@canvas-harness/core 0.0.4 → 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 +56 -34
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +18 -6
- package/dist/index.d.ts +18 -6
- package/dist/index.js +56 -34
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1055,7 +1055,8 @@ var COMPOSITE = /* @__PURE__ */ new Set([
|
|
|
1055
1055
|
"capsule",
|
|
1056
1056
|
"layered-rect",
|
|
1057
1057
|
"layered-ellipse",
|
|
1058
|
-
"layered-diamond"
|
|
1058
|
+
"layered-diamond",
|
|
1059
|
+
"soft-diamond"
|
|
1059
1060
|
]);
|
|
1060
1061
|
var isCompositePrimitive = (type) => COMPOSITE.has(type);
|
|
1061
1062
|
var isDrawablePrimitive = (type) => ATOMIC.has(type) || COMPOSITE.has(type);
|
|
@@ -1161,6 +1162,30 @@ var compositeLayout = (node) => {
|
|
|
1161
1162
|
const front = { atomic, x: 0, y: 0, w, h };
|
|
1162
1163
|
return [back, front];
|
|
1163
1164
|
}
|
|
1165
|
+
case "soft-diamond": {
|
|
1166
|
+
const backScale = 1.08;
|
|
1167
|
+
const frontScale = 0.96;
|
|
1168
|
+
const bw = w * backScale;
|
|
1169
|
+
const bh = h * backScale;
|
|
1170
|
+
const fw = w * frontScale;
|
|
1171
|
+
const fh = h * frontScale;
|
|
1172
|
+
const back = {
|
|
1173
|
+
atomic: "diamond",
|
|
1174
|
+
x: (w - bw) / 2,
|
|
1175
|
+
y: (h - bh) / 2,
|
|
1176
|
+
w: bw,
|
|
1177
|
+
h: bh,
|
|
1178
|
+
style: darkenedStyle(node.style)
|
|
1179
|
+
};
|
|
1180
|
+
const front = {
|
|
1181
|
+
atomic: "diamond",
|
|
1182
|
+
x: (w - fw) / 2,
|
|
1183
|
+
y: (h - fh) / 2,
|
|
1184
|
+
w: fw,
|
|
1185
|
+
h: fh
|
|
1186
|
+
};
|
|
1187
|
+
return [back, front];
|
|
1188
|
+
}
|
|
1164
1189
|
}
|
|
1165
1190
|
return [];
|
|
1166
1191
|
};
|
|
@@ -3219,8 +3244,15 @@ var createCanvasStore = (opts = {}) => {
|
|
|
3219
3244
|
};
|
|
3220
3245
|
const incidentEdges = /* @__PURE__ */ new Map();
|
|
3221
3246
|
let topZ = 0;
|
|
3222
|
-
|
|
3223
|
-
for (const
|
|
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
|
+
}
|
|
3224
3256
|
const getNodeForGeo = (id) => nodeAtoms.get(id)?.value;
|
|
3225
3257
|
let currentBatchOps = null;
|
|
3226
3258
|
let batchDepth = 0;
|
|
@@ -3309,6 +3341,8 @@ var createCanvasStore = (opts = {}) => {
|
|
|
3309
3341
|
nodeAtoms.set(op.node.id, a);
|
|
3310
3342
|
nodeIdsAtom.update((ids) => [...ids, op.node.id]);
|
|
3311
3343
|
reindexNode(op.node);
|
|
3344
|
+
if (op.node.z > topZ) topZ = op.node.z;
|
|
3345
|
+
if (op.node.z < bottomZ) bottomZ = op.node.z;
|
|
3312
3346
|
if (op.node.type === "frame") {
|
|
3313
3347
|
frameOrderAtom.update((ids) => ids.includes(op.node.id) ? ids : [...ids, op.node.id]);
|
|
3314
3348
|
}
|
|
@@ -3320,6 +3354,10 @@ var createCanvasStore = (opts = {}) => {
|
|
|
3320
3354
|
const next = { ...a.value, ...op.patch };
|
|
3321
3355
|
a.set(next);
|
|
3322
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
|
+
}
|
|
3323
3361
|
const incident = incidentEdges.get(op.id);
|
|
3324
3362
|
if (incident) {
|
|
3325
3363
|
for (const eid of incident) {
|
|
@@ -3348,6 +3386,8 @@ var createCanvasStore = (opts = {}) => {
|
|
|
3348
3386
|
trackIncidence(op.edge);
|
|
3349
3387
|
bumpEdgeVersion(op.edge.id);
|
|
3350
3388
|
reindexEdge(op.edge);
|
|
3389
|
+
if (op.edge.z > topZ) topZ = op.edge.z;
|
|
3390
|
+
if (op.edge.z < bottomZ) bottomZ = op.edge.z;
|
|
3351
3391
|
break;
|
|
3352
3392
|
}
|
|
3353
3393
|
case "edge.update": {
|
|
@@ -3360,6 +3400,10 @@ var createCanvasStore = (opts = {}) => {
|
|
|
3360
3400
|
a.set(next);
|
|
3361
3401
|
bumpEdgeVersion(op.id);
|
|
3362
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
|
+
}
|
|
3363
3407
|
break;
|
|
3364
3408
|
}
|
|
3365
3409
|
case "edge.remove": {
|
|
@@ -3447,9 +3491,8 @@ var createCanvasStore = (opts = {}) => {
|
|
|
3447
3491
|
clientId,
|
|
3448
3492
|
generateId: () => idGenerator(),
|
|
3449
3493
|
addNode(node) {
|
|
3450
|
-
const
|
|
3451
|
-
|
|
3452
|
-
const fitted = withAutoFitHeight(withZ);
|
|
3494
|
+
const z = node.z ?? ++topZ;
|
|
3495
|
+
const fitted = withAutoFitHeight({ ...node, z });
|
|
3453
3496
|
enqueueOp({ type: "node.add", node: fitted });
|
|
3454
3497
|
return fitted.id;
|
|
3455
3498
|
},
|
|
@@ -3512,7 +3555,6 @@ var createCanvasStore = (opts = {}) => {
|
|
|
3512
3555
|
w,
|
|
3513
3556
|
h,
|
|
3514
3557
|
angle: 0,
|
|
3515
|
-
z: 0,
|
|
3516
3558
|
groups: [],
|
|
3517
3559
|
style: opts2.style,
|
|
3518
3560
|
data: { src, naturalW, naturalH, alt: opts2.alt }
|
|
@@ -3535,7 +3577,6 @@ var createCanvasStore = (opts = {}) => {
|
|
|
3535
3577
|
w,
|
|
3536
3578
|
h,
|
|
3537
3579
|
angle: 0,
|
|
3538
|
-
z: 0,
|
|
3539
3580
|
groups: [],
|
|
3540
3581
|
...mergedStyle ? { style: mergedStyle } : {},
|
|
3541
3582
|
data: { src: sanitized, alt: opts2.alt }
|
|
@@ -3543,8 +3584,8 @@ var createCanvasStore = (opts = {}) => {
|
|
|
3543
3584
|
return id;
|
|
3544
3585
|
},
|
|
3545
3586
|
addEdge(edge) {
|
|
3546
|
-
const
|
|
3547
|
-
|
|
3587
|
+
const z = edge.z ?? ++topZ;
|
|
3588
|
+
const withZ = { ...edge, z };
|
|
3548
3589
|
enqueueOp({ type: "edge.add", edge: withZ });
|
|
3549
3590
|
return withZ.id;
|
|
3550
3591
|
},
|
|
@@ -3567,29 +3608,10 @@ var createCanvasStore = (opts = {}) => {
|
|
|
3567
3608
|
});
|
|
3568
3609
|
},
|
|
3569
3610
|
sendToBack(ids) {
|
|
3570
|
-
const targets = new Set(ids);
|
|
3571
|
-
let minZ = 0;
|
|
3572
|
-
let initialized = false;
|
|
3573
|
-
for (const a of nodeAtoms.values()) {
|
|
3574
|
-
if (targets.has(a.value.id)) continue;
|
|
3575
|
-
if (!initialized || a.value.z < minZ) {
|
|
3576
|
-
minZ = a.value.z;
|
|
3577
|
-
initialized = true;
|
|
3578
|
-
}
|
|
3579
|
-
}
|
|
3580
|
-
for (const a of edgeAtoms.values()) {
|
|
3581
|
-
if (targets.has(a.value.id)) continue;
|
|
3582
|
-
if (!initialized || a.value.z < minZ) {
|
|
3583
|
-
minZ = a.value.z;
|
|
3584
|
-
initialized = true;
|
|
3585
|
-
}
|
|
3586
|
-
}
|
|
3587
3611
|
this.batch(() => {
|
|
3588
|
-
let next = (initialized ? minZ : 0) - 1;
|
|
3589
3612
|
for (const id of ids) {
|
|
3590
|
-
if (nodeAtoms.has(id)) this.updateNode(id, { z:
|
|
3591
|
-
else if (edgeAtoms.has(id)) this.updateEdge(id, { z:
|
|
3592
|
-
next -= 1;
|
|
3613
|
+
if (nodeAtoms.has(id)) this.updateNode(id, { z: --bottomZ });
|
|
3614
|
+
else if (edgeAtoms.has(id)) this.updateEdge(id, { z: --bottomZ });
|
|
3593
3615
|
}
|
|
3594
3616
|
});
|
|
3595
3617
|
},
|
|
@@ -3607,7 +3629,6 @@ var createCanvasStore = (opts = {}) => {
|
|
|
3607
3629
|
if (currentZ === void 0) continue;
|
|
3608
3630
|
const idx = binaryFirstGreater(allZ, currentZ);
|
|
3609
3631
|
const nextZ = idx >= 0 ? allZ[idx] + 1 : currentZ + 1;
|
|
3610
|
-
if (nextZ > topZ) topZ = nextZ;
|
|
3611
3632
|
if (node) this.updateNode(id, { z: nextZ });
|
|
3612
3633
|
else this.updateEdge(id, { z: nextZ });
|
|
3613
3634
|
}
|
|
@@ -4268,7 +4289,7 @@ var paintBackground = (ctx, opts) => {
|
|
|
4268
4289
|
}
|
|
4269
4290
|
};
|
|
4270
4291
|
var paintDots = (ctx, minX, minY, maxX, maxY, gap, color, zoom) => {
|
|
4271
|
-
const sizeWorld = Math.max(1,
|
|
4292
|
+
const sizeWorld = Math.max(1, 1.6 / zoom);
|
|
4272
4293
|
const half = sizeWorld / 2;
|
|
4273
4294
|
ctx.save();
|
|
4274
4295
|
ctx.fillStyle = color;
|
|
@@ -4549,7 +4570,8 @@ var contentBounds = (node) => {
|
|
|
4549
4570
|
return { x: rectX, y: 0, w: Math.max(0, w - rectX), h };
|
|
4550
4571
|
}
|
|
4551
4572
|
case "diamond":
|
|
4552
|
-
case "layered-diamond":
|
|
4573
|
+
case "layered-diamond":
|
|
4574
|
+
case "soft-diamond": {
|
|
4553
4575
|
const cw = w * SQRT2_INV;
|
|
4554
4576
|
const ch = h * SQRT2_INV;
|
|
4555
4577
|
return { x: (w - cw) / 2, y: (h - ch) / 2, w: cw, h: ch };
|