dsh-drawai 0.2.1 → 0.2.2

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 (2) hide show
  1. package/lib/index.js +10 -1
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -809,6 +809,9 @@ async function applyOps(doc, ops, out, opctx) {
809
809
  if (typeof op.label === 'string') synthetic.label = op.label
810
810
  if (has(op, 'x')) synthetic.x = op.x
811
811
  if (has(op, 'y')) synthetic.y = op.y
812
+ // 就地插一条 addNode 紧随其后(读像素是 async 的,所以这条 op 不能在解析参数时先展开)。
813
+ // 注意:这里改的必须是**我们自己那份** ops —— 调用方(execute)已经 slice 过,
814
+ // 因为宿主给的 arguments 是深冻结的,直接 splice 会抛 "object is not extensible"。
812
815
  ops.splice(i + 1, 0, synthetic)
813
816
  notes.push(
814
817
  '🖼 ' + rawImage + ' → 逐像素矢量化:' + metrics.palette.length + ' 色 / ' + metrics.paths + ' 条 path / ' +
@@ -2900,7 +2903,13 @@ export function apply(ctx) {
2900
2903
  const focused = focusedPathFor(sessionIdOf(exec))
2901
2904
  const path =
2902
2905
  typeof args.path === 'string' && args.path.length > 0 ? args.path : focused !== undefined && focused.length > 0 ? focused : DEFAULT_PATH
2903
- const ops = Array.isArray(args.ops) ? args.ops : []
2906
+ // **入参是宿主深冻结的**:dsh-tools 在 execute 之前把整份 arguments 深冻结
2907
+ // (`arguments: deepFreeze(snapshotJsonValue(exec.arguments))`,见 dsh-tools 的 tool 执行器),
2908
+ // 数组和里面的 op 对象都是 non-extensible。所以这里必须**复制成一份可扩展的数组**再用:
2909
+ // traceImage 会往 ops 里插一条合成的 addNode(见下面 applyOps 里的 `ops.splice`),
2910
+ // 就地改冻结数组会抛 `Cannot add property N, object is not extensible`。
2911
+ // op 落盘语义不受影响 —— 复制出来的数组里元素仍是原来那些(本文件只读它们,从不写回)。
2912
+ const ops = Array.isArray(args.ops) ? args.ops.slice() : []
2904
2913
  if (ops.length === 0) throw new Error('ops must contain at least one operation')
2905
2914
 
2906
2915
  const sessionId = sessionIdOf(exec)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-drawai",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "type": "module",
5
5
  "description": "DSH 右侧栏的可编辑画布 + AI 语义绘图工具(diagram_apply / diagram_read),直接读写原生 .drawio 文件",
6
6
  "license": "MIT",