@canvas-harness/core 0.0.5 → 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.
package/dist/index.cjs CHANGED
@@ -3244,8 +3244,15 @@ var createCanvasStore = (opts = {}) => {
3244
3244
  };
3245
3245
  const incidentEdges = /* @__PURE__ */ new Map();
3246
3246
  let topZ = 0;
3247
- for (const n of Object.values(initial.nodes)) if (n.z > topZ) topZ = n.z;
3248
- for (const e of Object.values(initial.edges)) if (e.z > topZ) topZ = e.z;
3247
+ let bottomZ = 0;
3248
+ for (const n of Object.values(initial.nodes)) {
3249
+ if (n.z > topZ) topZ = n.z;
3250
+ if (n.z < bottomZ) bottomZ = n.z;
3251
+ }
3252
+ for (const e of Object.values(initial.edges)) {
3253
+ if (e.z > topZ) topZ = e.z;
3254
+ if (e.z < bottomZ) bottomZ = e.z;
3255
+ }
3249
3256
  const getNodeForGeo = (id) => nodeAtoms.get(id)?.value;
3250
3257
  let currentBatchOps = null;
3251
3258
  let batchDepth = 0;
@@ -3334,6 +3341,8 @@ var createCanvasStore = (opts = {}) => {
3334
3341
  nodeAtoms.set(op.node.id, a);
3335
3342
  nodeIdsAtom.update((ids) => [...ids, op.node.id]);
3336
3343
  reindexNode(op.node);
3344
+ if (op.node.z > topZ) topZ = op.node.z;
3345
+ if (op.node.z < bottomZ) bottomZ = op.node.z;
3337
3346
  if (op.node.type === "frame") {
3338
3347
  frameOrderAtom.update((ids) => ids.includes(op.node.id) ? ids : [...ids, op.node.id]);
3339
3348
  }
@@ -3345,6 +3354,10 @@ var createCanvasStore = (opts = {}) => {
3345
3354
  const next = { ...a.value, ...op.patch };
3346
3355
  a.set(next);
3347
3356
  reindexNode(next);
3357
+ if (op.patch.z !== void 0) {
3358
+ if (op.patch.z > topZ) topZ = op.patch.z;
3359
+ if (op.patch.z < bottomZ) bottomZ = op.patch.z;
3360
+ }
3348
3361
  const incident = incidentEdges.get(op.id);
3349
3362
  if (incident) {
3350
3363
  for (const eid of incident) {
@@ -3373,6 +3386,8 @@ var createCanvasStore = (opts = {}) => {
3373
3386
  trackIncidence(op.edge);
3374
3387
  bumpEdgeVersion(op.edge.id);
3375
3388
  reindexEdge(op.edge);
3389
+ if (op.edge.z > topZ) topZ = op.edge.z;
3390
+ if (op.edge.z < bottomZ) bottomZ = op.edge.z;
3376
3391
  break;
3377
3392
  }
3378
3393
  case "edge.update": {
@@ -3385,6 +3400,10 @@ var createCanvasStore = (opts = {}) => {
3385
3400
  a.set(next);
3386
3401
  bumpEdgeVersion(op.id);
3387
3402
  reindexEdge(next);
3403
+ if (op.patch.z !== void 0) {
3404
+ if (op.patch.z > topZ) topZ = op.patch.z;
3405
+ if (op.patch.z < bottomZ) bottomZ = op.patch.z;
3406
+ }
3388
3407
  break;
3389
3408
  }
3390
3409
  case "edge.remove": {
@@ -3472,9 +3491,8 @@ var createCanvasStore = (opts = {}) => {
3472
3491
  clientId,
3473
3492
  generateId: () => idGenerator(),
3474
3493
  addNode(node) {
3475
- const withZ = node.z === 0 ? { ...node, z: ++topZ } : node;
3476
- if (withZ.z > topZ) topZ = withZ.z;
3477
- const fitted = withAutoFitHeight(withZ);
3494
+ const z = node.z ?? ++topZ;
3495
+ const fitted = withAutoFitHeight({ ...node, z });
3478
3496
  enqueueOp({ type: "node.add", node: fitted });
3479
3497
  return fitted.id;
3480
3498
  },
@@ -3537,7 +3555,6 @@ var createCanvasStore = (opts = {}) => {
3537
3555
  w,
3538
3556
  h,
3539
3557
  angle: 0,
3540
- z: 0,
3541
3558
  groups: [],
3542
3559
  style: opts2.style,
3543
3560
  data: { src, naturalW, naturalH, alt: opts2.alt }
@@ -3560,7 +3577,6 @@ var createCanvasStore = (opts = {}) => {
3560
3577
  w,
3561
3578
  h,
3562
3579
  angle: 0,
3563
- z: 0,
3564
3580
  groups: [],
3565
3581
  ...mergedStyle ? { style: mergedStyle } : {},
3566
3582
  data: { src: sanitized, alt: opts2.alt }
@@ -3568,8 +3584,8 @@ var createCanvasStore = (opts = {}) => {
3568
3584
  return id;
3569
3585
  },
3570
3586
  addEdge(edge) {
3571
- const withZ = edge.z === 0 ? { ...edge, z: ++topZ } : edge;
3572
- if (withZ.z > topZ) topZ = withZ.z;
3587
+ const z = edge.z ?? ++topZ;
3588
+ const withZ = { ...edge, z };
3573
3589
  enqueueOp({ type: "edge.add", edge: withZ });
3574
3590
  return withZ.id;
3575
3591
  },
@@ -3592,29 +3608,10 @@ var createCanvasStore = (opts = {}) => {
3592
3608
  });
3593
3609
  },
3594
3610
  sendToBack(ids) {
3595
- const targets = new Set(ids);
3596
- let minZ = 0;
3597
- let initialized = false;
3598
- for (const a of nodeAtoms.values()) {
3599
- if (targets.has(a.value.id)) continue;
3600
- if (!initialized || a.value.z < minZ) {
3601
- minZ = a.value.z;
3602
- initialized = true;
3603
- }
3604
- }
3605
- for (const a of edgeAtoms.values()) {
3606
- if (targets.has(a.value.id)) continue;
3607
- if (!initialized || a.value.z < minZ) {
3608
- minZ = a.value.z;
3609
- initialized = true;
3610
- }
3611
- }
3612
3611
  this.batch(() => {
3613
- let next = (initialized ? minZ : 0) - 1;
3614
3612
  for (const id of ids) {
3615
- if (nodeAtoms.has(id)) this.updateNode(id, { z: next });
3616
- else if (edgeAtoms.has(id)) this.updateEdge(id, { z: next });
3617
- next -= 1;
3613
+ if (nodeAtoms.has(id)) this.updateNode(id, { z: --bottomZ });
3614
+ else if (edgeAtoms.has(id)) this.updateEdge(id, { z: --bottomZ });
3618
3615
  }
3619
3616
  });
3620
3617
  },
@@ -3632,7 +3629,6 @@ var createCanvasStore = (opts = {}) => {
3632
3629
  if (currentZ === void 0) continue;
3633
3630
  const idx = binaryFirstGreater(allZ, currentZ);
3634
3631
  const nextZ = idx >= 0 ? allZ[idx] + 1 : currentZ + 1;
3635
- if (nextZ > topZ) topZ = nextZ;
3636
3632
  if (node) this.updateNode(id, { z: nextZ });
3637
3633
  else this.updateEdge(id, { z: nextZ });
3638
3634
  }
@@ -4293,7 +4289,7 @@ var paintBackground = (ctx, opts) => {
4293
4289
  }
4294
4290
  };
4295
4291
  var paintDots = (ctx, minX, minY, maxX, maxY, gap, color, zoom) => {
4296
- const sizeWorld = Math.max(1, 2.4 / zoom);
4292
+ const sizeWorld = Math.max(1, 1.6 / zoom);
4297
4293
  const half = sizeWorld / 2;
4298
4294
  ctx.save();
4299
4295
  ctx.fillStyle = color;