@canvas-harness/core 0.1.5 → 0.1.6
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 +39 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +24 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.js +39 -11
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1050,7 +1050,6 @@ var COMPOSITE = /* @__PURE__ */ new Set([
|
|
|
1050
1050
|
var isCompositePrimitive = (type) => COMPOSITE.has(type);
|
|
1051
1051
|
var isDrawablePrimitive = (type) => ATOMIC.has(type) || COMPOSITE.has(type);
|
|
1052
1052
|
var PLAIN_RECT_CORNER_THRESHOLD_PX = 1.5;
|
|
1053
|
-
var STROKE_VISIBILITY_THRESHOLD_PX = 0.5;
|
|
1054
1053
|
var LAYERED_OFFSET = 12;
|
|
1055
1054
|
var drawShape = (ctx, node, scale, theme, opts) => {
|
|
1056
1055
|
if (!isDrawablePrimitive(node.type)) return;
|
|
@@ -1069,7 +1068,7 @@ var drawAtomic = (ctx, type, w, h, style, scale, theme, opts) => {
|
|
|
1069
1068
|
const fill = resolveColor(style, "backgroundColor", DEFAULT_STYLE.backgroundColor, theme);
|
|
1070
1069
|
const stroke = resolveColor(style, "strokeColor", DEFAULT_STYLE.strokeColor, theme);
|
|
1071
1070
|
const fillVisible = !isFullyTransparent(fill);
|
|
1072
|
-
const strokeVisible = strokeWidth > 0 &&
|
|
1071
|
+
const strokeVisible = strokeWidth > 0 && !isFullyTransparent(stroke);
|
|
1073
1072
|
if (!fillVisible && !strokeVisible) return;
|
|
1074
1073
|
const cornerRadius = (style?.roundness ?? DEFAULT_STYLE.roundness) * 4;
|
|
1075
1074
|
switch (type) {
|
|
@@ -1106,7 +1105,7 @@ var drawAtomic = (ctx, type, w, h, style, scale, theme, opts) => {
|
|
|
1106
1105
|
}
|
|
1107
1106
|
if (strokeVisible && !opts?.skipStroke) {
|
|
1108
1107
|
ctx.strokeStyle = stroke;
|
|
1109
|
-
ctx.lineWidth = strokeWidth;
|
|
1108
|
+
ctx.lineWidth = Math.max(strokeWidth, 1 / scale);
|
|
1110
1109
|
ctx.setLineDash(dashPatternFor(style?.strokeStyle, strokeWidth));
|
|
1111
1110
|
ctx.stroke();
|
|
1112
1111
|
}
|
|
@@ -1482,13 +1481,16 @@ var paintAtomicRough = (rc, ctx, type, w, h, style, scale, theme, seed) => {
|
|
|
1482
1481
|
const isDark = theme?.("mode") === "dark";
|
|
1483
1482
|
const fill = resolveColor(style, "backgroundColor", DEFAULT_STYLE.backgroundColor, theme);
|
|
1484
1483
|
const strokeColor = deriveRoughStrokeColor(rawStroke, fill, isDark);
|
|
1485
|
-
const
|
|
1486
|
-
if (
|
|
1484
|
+
const rawStrokeWidth = resolveStrokeWidth(style, theme);
|
|
1485
|
+
if (rawStrokeWidth <= 0) return;
|
|
1487
1486
|
const roughness = style?.roughness ?? 0;
|
|
1488
1487
|
if (roughness <= 0) return;
|
|
1488
|
+
const isNoBorderIntent = isFullyTransparent(rawStroke);
|
|
1489
|
+
const effectiveStrokeStyle = isNoBorderIntent ? "solid" : style?.strokeStyle ?? "solid";
|
|
1490
|
+
const strokeWidth = isNoBorderIntent ? DEFAULT_STYLE.strokeWidth : rawStrokeWidth;
|
|
1489
1491
|
const cornerRadius = (style?.roundness ?? DEFAULT_STYLE.roundness) * 4;
|
|
1490
1492
|
const radius = Math.max(0, Math.min(cornerRadius, w / 2, h / 2));
|
|
1491
|
-
const dash = dashPatternFor(
|
|
1493
|
+
const dash = dashPatternFor(effectiveStrokeStyle, strokeWidth);
|
|
1492
1494
|
const detail = apparentDetail(Math.max(w, h), scale);
|
|
1493
1495
|
const cacheKey = [
|
|
1494
1496
|
type,
|
|
@@ -1497,7 +1499,7 @@ var paintAtomicRough = (rc, ctx, type, w, h, style, scale, theme, seed) => {
|
|
|
1497
1499
|
radius.toFixed(1),
|
|
1498
1500
|
strokeColor,
|
|
1499
1501
|
strokeWidth.toFixed(2),
|
|
1500
|
-
|
|
1502
|
+
effectiveStrokeStyle,
|
|
1501
1503
|
roughness.toFixed(2),
|
|
1502
1504
|
seed,
|
|
1503
1505
|
detail.curveStepCount,
|
|
@@ -2648,7 +2650,7 @@ var DEFAULT_EDGE_STYLE = {
|
|
|
2648
2650
|
sourceArrowhead: "none",
|
|
2649
2651
|
targetArrowhead: "arrow-filled"
|
|
2650
2652
|
};
|
|
2651
|
-
var
|
|
2653
|
+
var STROKE_VISIBILITY_THRESHOLD_PX = 0.5;
|
|
2652
2654
|
var ARROWHEAD_VISIBILITY_THRESHOLD_PX = 2;
|
|
2653
2655
|
var samplePaintStride = (scale) => {
|
|
2654
2656
|
if (scale < 0.15) return 8;
|
|
@@ -2662,7 +2664,7 @@ var drawEdge = (ctx, edge, geom, sourceNode, targetNode, scale, theme, opts) =>
|
|
|
2662
2664
|
if (samples.length < 2) return;
|
|
2663
2665
|
const style = edge.style;
|
|
2664
2666
|
const strokeWidth = typeof style?.strokeWidth === "number" ? style.strokeWidth : theme?.("strokeWidth") ?? DEFAULT_EDGE_STYLE.strokeWidth;
|
|
2665
|
-
if (strokeWidth * scale <
|
|
2667
|
+
if (strokeWidth * scale < STROKE_VISIBILITY_THRESHOLD_PX) return;
|
|
2666
2668
|
const strokeColor = typeof style?.strokeColor === "string" ? style.strokeColor : theme?.("edge.strokeColor") ?? DEFAULT_EDGE_STYLE.strokeColor;
|
|
2667
2669
|
const sourceArrowhead = style?.sourceArrowhead ?? DEFAULT_EDGE_STYLE.sourceArrowhead;
|
|
2668
2670
|
const targetArrowhead = style?.targetArrowhead ?? DEFAULT_EDGE_STYLE.targetArrowhead;
|
|
@@ -3378,6 +3380,8 @@ var idleInteractionState = () => ({
|
|
|
3378
3380
|
resizeHandle: null,
|
|
3379
3381
|
resizeLockAspect: false,
|
|
3380
3382
|
resizeFromCenter: false,
|
|
3383
|
+
resizeDraft: null,
|
|
3384
|
+
midpointDraft: null,
|
|
3381
3385
|
marqueeRect: null,
|
|
3382
3386
|
marqueeAdditive: false,
|
|
3383
3387
|
draftEdge: null,
|
|
@@ -4954,7 +4958,9 @@ var createRenderer = (opts) => {
|
|
|
4954
4958
|
const scale = camera.z * surface.dpr;
|
|
4955
4959
|
const interaction = store.getInteractionState();
|
|
4956
4960
|
const excludedNodes = interaction.mode === "dragging" || interaction.mode === "resizing" ? new Set(interaction.draggedIds) : null;
|
|
4957
|
-
const
|
|
4961
|
+
const baseExcludedEdges = excludedNodes ? incidentEdgeIds(excludedNodes) : null;
|
|
4962
|
+
const midpointEdgeId = interaction.midpointDraft?.edgeId ?? null;
|
|
4963
|
+
const excludedEdges = midpointEdgeId !== null ? /* @__PURE__ */ new Set([...baseExcludedEdges ?? [], midpointEdgeId]) : baseExcludedEdges;
|
|
4958
4964
|
paintBackground(surface.ctx, { viewport, zoom: camera.z, background });
|
|
4959
4965
|
const visible = visibleNodes(camera, viewport);
|
|
4960
4966
|
const isMoving2 = interaction.mode === "panning" || interaction.mode === "zooming" || interaction.mode === "dragging" || interaction.mode === "resizing" || interaction.mode === "rotating";
|
|
@@ -5366,6 +5372,23 @@ var createRenderer = (opts) => {
|
|
|
5366
5372
|
}
|
|
5367
5373
|
}
|
|
5368
5374
|
}
|
|
5375
|
+
if (interaction.midpointDraft) {
|
|
5376
|
+
const { edgeId, control } = interaction.midpointDraft;
|
|
5377
|
+
const edge = store.getEdge(edgeId);
|
|
5378
|
+
if (edge) {
|
|
5379
|
+
const draftEdge = { ...edge, control };
|
|
5380
|
+
const geom = computeEdgeGeometry(draftEdge, (id) => store.getNode(id));
|
|
5381
|
+
if (geom) {
|
|
5382
|
+
const sourceNode = geom.sourceNodeId ? store.getNode(geom.sourceNodeId) ?? null : null;
|
|
5383
|
+
const targetNode = geom.targetNodeId ? store.getNode(geom.targetNodeId) ?? null : null;
|
|
5384
|
+
drawEdge(ctx, draftEdge, geom, sourceNode, targetNode, scale, theme, {
|
|
5385
|
+
zoom: camera.z,
|
|
5386
|
+
dpr: interactiveSurface.dpr,
|
|
5387
|
+
isMoving: true
|
|
5388
|
+
});
|
|
5389
|
+
}
|
|
5390
|
+
}
|
|
5391
|
+
}
|
|
5369
5392
|
const selection = store.getSelection();
|
|
5370
5393
|
const selectedNodeIds = [];
|
|
5371
5394
|
const selectedEdgeIds = [];
|
|
@@ -5438,7 +5461,12 @@ var createRenderer = (opts) => {
|
|
|
5438
5461
|
y: orig.y + interaction.dragDelta.y
|
|
5439
5462
|
});
|
|
5440
5463
|
} else {
|
|
5441
|
-
|
|
5464
|
+
const d = interaction.resizeDraft;
|
|
5465
|
+
if (d) {
|
|
5466
|
+
m.set(orig.id, { ...live, x: d.x, y: d.y, w: d.w, h: d.h, angle: d.angle });
|
|
5467
|
+
} else {
|
|
5468
|
+
m.set(orig.id, live);
|
|
5469
|
+
}
|
|
5442
5470
|
}
|
|
5443
5471
|
}
|
|
5444
5472
|
return m;
|