sketchmark 1.3.6 → 1.4.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/README.md +31 -18
- package/dist/animation/index.d.ts +1 -1
- package/dist/animation/index.d.ts.map +1 -1
- package/dist/ast/types.d.ts +4 -0
- package/dist/ast/types.d.ts.map +1 -1
- package/dist/index.cjs +340 -49
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +340 -49
- package/dist/index.js.map +1 -1
- package/dist/layout/index.d.ts.map +1 -1
- package/dist/parser/index.d.ts.map +1 -1
- package/dist/renderer/canvas/index.d.ts.map +1 -1
- package/dist/renderer/shared.d.ts +16 -0
- package/dist/renderer/shared.d.ts.map +1 -1
- package/dist/renderer/svg/index.d.ts.map +1 -1
- package/dist/scene/index.d.ts +4 -2
- package/dist/scene/index.d.ts.map +1 -1
- package/dist/sketchmark.iife.js +340 -49
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -359,6 +359,39 @@ function isValueToken(t) {
|
|
|
359
359
|
function isPropKeyToken(t) {
|
|
360
360
|
return !!t && (t.type === "IDENT" || t.type === "KEYWORD");
|
|
361
361
|
}
|
|
362
|
+
const NUMBER_RE = /[-+]?(?:\d*\.\d+|\d+)(?:[eE][-+]?\d+)?/g;
|
|
363
|
+
function parseEdgeWaypoints(value, token) {
|
|
364
|
+
if (!value)
|
|
365
|
+
return undefined;
|
|
366
|
+
const numbers = (value.match(NUMBER_RE) ?? []).map((part) => Number(part));
|
|
367
|
+
if (!numbers.length)
|
|
368
|
+
return undefined;
|
|
369
|
+
if (numbers.length % 2 !== 0) {
|
|
370
|
+
throw new ParseError(`Edge via must contain x,y coordinate pairs`, token.line, token.col);
|
|
371
|
+
}
|
|
372
|
+
const points = [];
|
|
373
|
+
for (let index = 0; index < numbers.length; index += 2) {
|
|
374
|
+
const x = numbers[index];
|
|
375
|
+
const y = numbers[index + 1];
|
|
376
|
+
if (!Number.isFinite(x) || !Number.isFinite(y)) {
|
|
377
|
+
throw new ParseError(`Edge via contains a non-numeric coordinate`, token.line, token.col);
|
|
378
|
+
}
|
|
379
|
+
points.push([x, y]);
|
|
380
|
+
}
|
|
381
|
+
return points.length ? points : undefined;
|
|
382
|
+
}
|
|
383
|
+
function normalizeEdgeRoute(value, token) {
|
|
384
|
+
if (!value)
|
|
385
|
+
return undefined;
|
|
386
|
+
const normalized = value.toLowerCase();
|
|
387
|
+
if (normalized === "straight" || normalized === "polyline" || normalized === "orthogonal") {
|
|
388
|
+
return normalized;
|
|
389
|
+
}
|
|
390
|
+
if (normalized === "ortho" || normalized === "elbow") {
|
|
391
|
+
return "orthogonal";
|
|
392
|
+
}
|
|
393
|
+
throw new ParseError(`Unsupported edge route "${value}"; use straight, orthogonal, or polyline`, token.line, token.col);
|
|
394
|
+
}
|
|
362
395
|
function parse(src, options = {}) {
|
|
363
396
|
resetUid();
|
|
364
397
|
const preparedSource = applyPluginPreprocessors(src, options.plugins);
|
|
@@ -717,28 +750,63 @@ function parse(src, options = {}) {
|
|
|
717
750
|
height: props.height !== undefined ? parseFloat(props.height) : undefined,
|
|
718
751
|
};
|
|
719
752
|
}
|
|
720
|
-
function
|
|
721
|
-
const toTok = rest.shift();
|
|
722
|
-
if (!toTok)
|
|
723
|
-
throw new ParseError("Expected edge target", 0, 0);
|
|
753
|
+
function parseEdgeProps(toks) {
|
|
724
754
|
const props = {};
|
|
725
755
|
let j = 0;
|
|
726
|
-
while (j <
|
|
727
|
-
const
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
j += 3;
|
|
756
|
+
while (j < toks.length) {
|
|
757
|
+
const key = toks[j];
|
|
758
|
+
const eq = toks[j + 1];
|
|
759
|
+
if (!isPropKeyToken(key) || eq?.type !== "EQUALS") {
|
|
760
|
+
j++;
|
|
761
|
+
continue;
|
|
733
762
|
}
|
|
734
|
-
|
|
763
|
+
const value = toks[j + 2];
|
|
764
|
+
if (!value) {
|
|
735
765
|
j++;
|
|
766
|
+
continue;
|
|
736
767
|
}
|
|
768
|
+
if (value.type === "LBRACKET") {
|
|
769
|
+
const parts = [];
|
|
770
|
+
let depth = 1;
|
|
771
|
+
j += 3;
|
|
772
|
+
while (j < toks.length && depth > 0) {
|
|
773
|
+
const tok = toks[j];
|
|
774
|
+
if (tok.type === "LBRACKET") {
|
|
775
|
+
depth++;
|
|
776
|
+
}
|
|
777
|
+
else if (tok.type === "RBRACKET") {
|
|
778
|
+
depth--;
|
|
779
|
+
if (depth === 0) {
|
|
780
|
+
j++;
|
|
781
|
+
break;
|
|
782
|
+
}
|
|
783
|
+
}
|
|
784
|
+
if (depth > 0)
|
|
785
|
+
parts.push(tok.value);
|
|
786
|
+
j++;
|
|
787
|
+
}
|
|
788
|
+
if (depth > 0) {
|
|
789
|
+
throw new ParseError(`Unterminated edge property list; expected ']'`, key.line, key.col);
|
|
790
|
+
}
|
|
791
|
+
props[key.value] = parts.join(" ");
|
|
792
|
+
continue;
|
|
793
|
+
}
|
|
794
|
+
props[key.value] = value.value;
|
|
795
|
+
j += 3;
|
|
737
796
|
}
|
|
797
|
+
return props;
|
|
798
|
+
}
|
|
799
|
+
function parseEdge(fromId, connector, rest) {
|
|
800
|
+
const toTok = rest.shift();
|
|
801
|
+
if (!toTok)
|
|
802
|
+
throw new ParseError("Expected edge target", 0, 0);
|
|
803
|
+
const props = parseEdgeProps(rest);
|
|
738
804
|
const dashed = connector.includes("--") ||
|
|
739
805
|
connector.includes(".-") ||
|
|
740
806
|
connector.includes("-.");
|
|
741
807
|
const bidirectional = connector.includes("<") && connector.includes(">");
|
|
808
|
+
const via = parseEdgeWaypoints(props.via, toTok);
|
|
809
|
+
const route = normalizeEdgeRoute(props.route, toTok) ?? (via?.length ? "polyline" : undefined);
|
|
742
810
|
return {
|
|
743
811
|
kind: "edge",
|
|
744
812
|
id: uid("edge"),
|
|
@@ -750,6 +818,8 @@ function parse(src, options = {}) {
|
|
|
750
818
|
labelDy: props["label-dy"] !== undefined ? parseFloat(props["label-dy"]) : undefined,
|
|
751
819
|
fromAnchor: props["anchor-from"],
|
|
752
820
|
toAnchor: props["anchor-to"],
|
|
821
|
+
route,
|
|
822
|
+
via,
|
|
753
823
|
dashed,
|
|
754
824
|
bidirectional,
|
|
755
825
|
style: propsToStyle(props),
|
|
@@ -3683,6 +3753,8 @@ function buildSceneGraph(ast) {
|
|
|
3683
3753
|
labelDy: e.labelDy,
|
|
3684
3754
|
fromAnchor: e.fromAnchor,
|
|
3685
3755
|
toAnchor: e.toAnchor,
|
|
3756
|
+
route: e.route,
|
|
3757
|
+
via: e.via,
|
|
3686
3758
|
dashed: e.dashed ?? false,
|
|
3687
3759
|
bidirectional: e.bidirectional ?? false,
|
|
3688
3760
|
style: e.style ?? {},
|
|
@@ -4284,6 +4356,151 @@ function getConnPoint(src, dstCX, dstCY, anchor) {
|
|
|
4284
4356
|
return anchoredConnPoint(src, anchor, dstCX, dstCY);
|
|
4285
4357
|
}
|
|
4286
4358
|
// ── Group depth (for paint order) ────────────────────────────────────────
|
|
4359
|
+
function segmentLength(a, b) {
|
|
4360
|
+
return Math.hypot(b[0] - a[0], b[1] - a[1]);
|
|
4361
|
+
}
|
|
4362
|
+
function compactPolylinePoints(points) {
|
|
4363
|
+
const compacted = [];
|
|
4364
|
+
for (const point of points) {
|
|
4365
|
+
const previous = compacted[compacted.length - 1];
|
|
4366
|
+
if (!previous || segmentLength(previous, point) > 0.01) {
|
|
4367
|
+
compacted.push(point);
|
|
4368
|
+
}
|
|
4369
|
+
}
|
|
4370
|
+
return compacted;
|
|
4371
|
+
}
|
|
4372
|
+
function polylinePathData(points) {
|
|
4373
|
+
return points
|
|
4374
|
+
.map(([x, y], index) => `${index === 0 ? "M" : "L"} ${x} ${y}`)
|
|
4375
|
+
.join(" ");
|
|
4376
|
+
}
|
|
4377
|
+
function polylineEndpointDirection(points, end) {
|
|
4378
|
+
const step = end === "start" ? 1 : -1;
|
|
4379
|
+
let index = end === "start" ? 0 : points.length - 1;
|
|
4380
|
+
while (index + step >= 0 && index + step < points.length) {
|
|
4381
|
+
const from = points[index];
|
|
4382
|
+
const to = points[index + step];
|
|
4383
|
+
const dx = to[0] - from[0];
|
|
4384
|
+
const dy = to[1] - from[1];
|
|
4385
|
+
const len = Math.hypot(dx, dy);
|
|
4386
|
+
if (len > 0.01) {
|
|
4387
|
+
return end === "start" ? [dx / len, dy / len] : [-dx / len, -dy / len];
|
|
4388
|
+
}
|
|
4389
|
+
index += step;
|
|
4390
|
+
}
|
|
4391
|
+
return [1, 0];
|
|
4392
|
+
}
|
|
4393
|
+
function insetPolylineEndpoints(points, arrowAt, inset) {
|
|
4394
|
+
const next = points.map((point) => [point[0], point[1]]);
|
|
4395
|
+
if (next.length < 2)
|
|
4396
|
+
return next;
|
|
4397
|
+
if (arrowAt === "start" || arrowAt === "both") {
|
|
4398
|
+
const [dx, dy] = polylineEndpointDirection(next, "start");
|
|
4399
|
+
next[0] = [next[0][0] + dx * inset, next[0][1] + dy * inset];
|
|
4400
|
+
}
|
|
4401
|
+
if (arrowAt === "end" || arrowAt === "both") {
|
|
4402
|
+
const [dx, dy] = polylineEndpointDirection(next, "end");
|
|
4403
|
+
const last = next.length - 1;
|
|
4404
|
+
next[last] = [next[last][0] - dx * inset, next[last][1] - dy * inset];
|
|
4405
|
+
}
|
|
4406
|
+
return compactPolylinePoints(next);
|
|
4407
|
+
}
|
|
4408
|
+
function polylineLabelPosition(points, offset, dx = 0, dy = 0) {
|
|
4409
|
+
if (points.length < 2) {
|
|
4410
|
+
const [x, y] = points[0] ?? [0, 0];
|
|
4411
|
+
return { x: x + dx, y: y + dy };
|
|
4412
|
+
}
|
|
4413
|
+
const lengths = points.slice(1).map((point, index) => segmentLength(points[index], point));
|
|
4414
|
+
const total = lengths.reduce((sum, value) => sum + value, 0);
|
|
4415
|
+
if (total <= 0.01) {
|
|
4416
|
+
const [x, y] = points[0];
|
|
4417
|
+
return { x: x + dx, y: y + dy };
|
|
4418
|
+
}
|
|
4419
|
+
let travelled = 0;
|
|
4420
|
+
const target = total / 2;
|
|
4421
|
+
for (let index = 0; index < lengths.length; index += 1) {
|
|
4422
|
+
const length = lengths[index];
|
|
4423
|
+
if (travelled + length >= target) {
|
|
4424
|
+
const from = points[index];
|
|
4425
|
+
const to = points[index + 1];
|
|
4426
|
+
const t = length > 0 ? (target - travelled) / length : 0;
|
|
4427
|
+
const ux = (to[0] - from[0]) / length;
|
|
4428
|
+
const uy = (to[1] - from[1]) / length;
|
|
4429
|
+
return {
|
|
4430
|
+
x: from[0] + (to[0] - from[0]) * t - uy * offset + dx,
|
|
4431
|
+
y: from[1] + (to[1] - from[1]) * t + ux * offset + dy,
|
|
4432
|
+
};
|
|
4433
|
+
}
|
|
4434
|
+
travelled += length;
|
|
4435
|
+
}
|
|
4436
|
+
const [x, y] = points[points.length - 1];
|
|
4437
|
+
return { x: x + dx, y: y + dy };
|
|
4438
|
+
}
|
|
4439
|
+
function rectBoundaryPoint(entity, point, direction) {
|
|
4440
|
+
const [px, py] = point;
|
|
4441
|
+
const [dx, dy] = direction;
|
|
4442
|
+
const candidates = [];
|
|
4443
|
+
const minX = entity.x;
|
|
4444
|
+
const maxX = entity.x + entity.w;
|
|
4445
|
+
const minY = entity.y;
|
|
4446
|
+
const maxY = entity.y + entity.h;
|
|
4447
|
+
const epsilon = 0.01;
|
|
4448
|
+
if (Math.abs(dx) > epsilon) {
|
|
4449
|
+
candidates.push((minX - px) / dx, (maxX - px) / dx);
|
|
4450
|
+
}
|
|
4451
|
+
if (Math.abs(dy) > epsilon) {
|
|
4452
|
+
candidates.push((minY - py) / dy, (maxY - py) / dy);
|
|
4453
|
+
}
|
|
4454
|
+
const valid = candidates
|
|
4455
|
+
.filter((t) => t >= -epsilon)
|
|
4456
|
+
.map((t) => ({
|
|
4457
|
+
t: Math.max(0, t),
|
|
4458
|
+
x: px + dx * t,
|
|
4459
|
+
y: py + dy * t,
|
|
4460
|
+
}))
|
|
4461
|
+
.filter(({ x, y }) => x >= minX - epsilon &&
|
|
4462
|
+
x <= maxX + epsilon &&
|
|
4463
|
+
y >= minY - epsilon &&
|
|
4464
|
+
y <= maxY + epsilon)
|
|
4465
|
+
.sort((a, b) => a.t - b.t);
|
|
4466
|
+
const hit = valid[0];
|
|
4467
|
+
return hit ? [hit.x, hit.y] : point;
|
|
4468
|
+
}
|
|
4469
|
+
function ellipseBoundaryPoint(entity, point, direction) {
|
|
4470
|
+
const [px, py] = point;
|
|
4471
|
+
const [dx, dy] = direction;
|
|
4472
|
+
const cx = entity.x + entity.w / 2;
|
|
4473
|
+
const cy = entity.y + entity.h / 2;
|
|
4474
|
+
const rx = Math.max(1, entity.w * 0.44);
|
|
4475
|
+
const ry = Math.max(1, entity.h * 0.44);
|
|
4476
|
+
const x0 = px - cx;
|
|
4477
|
+
const y0 = py - cy;
|
|
4478
|
+
const a = (dx * dx) / (rx * rx) + (dy * dy) / (ry * ry);
|
|
4479
|
+
const b = 2 * ((x0 * dx) / (rx * rx) + (y0 * dy) / (ry * ry));
|
|
4480
|
+
const c = (x0 * x0) / (rx * rx) + (y0 * y0) / (ry * ry) - 1;
|
|
4481
|
+
const disc = b * b - 4 * a * c;
|
|
4482
|
+
if (a <= 0 || disc < 0)
|
|
4483
|
+
return point;
|
|
4484
|
+
const sqrt = Math.sqrt(disc);
|
|
4485
|
+
const hits = [(-b - sqrt) / (2 * a), (-b + sqrt) / (2 * a)]
|
|
4486
|
+
.filter((t) => t >= -0.01)
|
|
4487
|
+
.sort((left, right) => left - right);
|
|
4488
|
+
const t = Math.max(0, hits[0] ?? 0);
|
|
4489
|
+
return [px + dx * t, py + dy * t];
|
|
4490
|
+
}
|
|
4491
|
+
function polylineArrowTipPoint(entity, points, end) {
|
|
4492
|
+
const point = end === "start" ? points[0] : points[points.length - 1];
|
|
4493
|
+
if (!point)
|
|
4494
|
+
return [0, 0];
|
|
4495
|
+
const [dx, dy] = polylineEndpointDirection(points, end);
|
|
4496
|
+
const outward = end === "start" ? [dx, dy] : [-dx, -dy];
|
|
4497
|
+
if (Math.hypot(outward[0], outward[1]) <= 0.01)
|
|
4498
|
+
return point;
|
|
4499
|
+
if (entity.shape === "circle") {
|
|
4500
|
+
return ellipseBoundaryPoint(entity, point, outward);
|
|
4501
|
+
}
|
|
4502
|
+
return rectBoundaryPoint(entity, point, outward);
|
|
4503
|
+
}
|
|
4287
4504
|
function groupDepth(g, gm) {
|
|
4288
4505
|
let d = 0;
|
|
4289
4506
|
let cur = g;
|
|
@@ -5244,6 +5461,31 @@ function rectConnPoint(rx, ry, rw, rh, ox, oy) {
|
|
|
5244
5461
|
const t = Math.min(tx, ty);
|
|
5245
5462
|
return [cx + t * dx, cy + t * dy];
|
|
5246
5463
|
}
|
|
5464
|
+
function distance$1(a, b) {
|
|
5465
|
+
return Math.hypot(b[0] - a[0], b[1] - a[1]);
|
|
5466
|
+
}
|
|
5467
|
+
function compactEdgePoints(points) {
|
|
5468
|
+
const compacted = [];
|
|
5469
|
+
for (const point of points) {
|
|
5470
|
+
const previous = compacted[compacted.length - 1];
|
|
5471
|
+
if (!previous || distance$1(previous, point) > 0.01) {
|
|
5472
|
+
compacted.push(point);
|
|
5473
|
+
}
|
|
5474
|
+
}
|
|
5475
|
+
return compacted;
|
|
5476
|
+
}
|
|
5477
|
+
function orthogonalEdgePoints(start, end) {
|
|
5478
|
+
if (Math.abs(start[0] - end[0]) < 0.01 || Math.abs(start[1] - end[1]) < 0.01) {
|
|
5479
|
+
return [start, end];
|
|
5480
|
+
}
|
|
5481
|
+
const midX = (start[0] + end[0]) / 2;
|
|
5482
|
+
return compactEdgePoints([
|
|
5483
|
+
start,
|
|
5484
|
+
[midX, start[1]],
|
|
5485
|
+
[midX, end[1]],
|
|
5486
|
+
end,
|
|
5487
|
+
]);
|
|
5488
|
+
}
|
|
5247
5489
|
function routeEdges(sg) {
|
|
5248
5490
|
const nm = nodeMap(sg);
|
|
5249
5491
|
const tm = tableMap(sg);
|
|
@@ -5273,10 +5515,17 @@ function routeEdges(sg) {
|
|
|
5273
5515
|
}
|
|
5274
5516
|
const dstCX = dst.x + dst.w / 2, dstCY = dst.y + dst.h / 2;
|
|
5275
5517
|
const srcCX = src.x + src.w / 2, srcCY = src.y + src.h / 2;
|
|
5276
|
-
e.
|
|
5277
|
-
|
|
5278
|
-
|
|
5279
|
-
|
|
5518
|
+
const start = anchoredConnPoint(src, e.fromAnchor, dstCX, dstCY);
|
|
5519
|
+
const end = anchoredConnPoint(dst, e.toAnchor, srcCX, srcCY);
|
|
5520
|
+
if (e.via?.length) {
|
|
5521
|
+
e.points = compactEdgePoints([start, ...e.via, end]);
|
|
5522
|
+
}
|
|
5523
|
+
else if (e.route === "orthogonal") {
|
|
5524
|
+
e.points = orthogonalEdgePoints(start, end);
|
|
5525
|
+
}
|
|
5526
|
+
else {
|
|
5527
|
+
e.points = [start, end];
|
|
5528
|
+
}
|
|
5280
5529
|
}
|
|
5281
5530
|
}
|
|
5282
5531
|
function computeBounds(sg, margin) {
|
|
@@ -5286,6 +5535,7 @@ function computeBounds(sg, margin) {
|
|
|
5286
5535
|
...sg.tables.map((t) => t.x + t.w),
|
|
5287
5536
|
...sg.charts.map((c) => c.x + c.w),
|
|
5288
5537
|
...sg.markdowns.map((m) => m.x + m.w),
|
|
5538
|
+
...sg.edges.flatMap((e) => (e.points ?? []).map(([x]) => x)),
|
|
5289
5539
|
];
|
|
5290
5540
|
const allY = [
|
|
5291
5541
|
...sg.nodes.map((n) => n.y + n.h),
|
|
@@ -5293,6 +5543,7 @@ function computeBounds(sg, margin) {
|
|
|
5293
5543
|
...sg.tables.map((t) => t.y + t.h),
|
|
5294
5544
|
...sg.charts.map((c) => c.y + c.h),
|
|
5295
5545
|
...sg.markdowns.map((m) => m.y + m.h),
|
|
5546
|
+
...sg.edges.flatMap((e) => (e.points ?? []).map(([, y]) => y)),
|
|
5296
5547
|
];
|
|
5297
5548
|
const autoWidth = (allX.length ? Math.max(...allX) : 400) + margin;
|
|
5298
5549
|
const autoHeight = (allY.length ? Math.max(...allY) : 300) + margin;
|
|
@@ -8280,6 +8531,36 @@ function setParentGroupData(el, groupId) {
|
|
|
8280
8531
|
if (groupId)
|
|
8281
8532
|
el.dataset.parentGroup = groupId;
|
|
8282
8533
|
}
|
|
8534
|
+
function resolveEdgeEndpointKind(id, nm, tm, gm, cm) {
|
|
8535
|
+
if (nm.has(id))
|
|
8536
|
+
return "node";
|
|
8537
|
+
if (gm.has(id))
|
|
8538
|
+
return "group";
|
|
8539
|
+
if (tm.has(id))
|
|
8540
|
+
return "table";
|
|
8541
|
+
if (cm.has(id))
|
|
8542
|
+
return "chart";
|
|
8543
|
+
return null;
|
|
8544
|
+
}
|
|
8545
|
+
function collectEdgeGroupLineage(endpointId, endpointKind, parentGroups) {
|
|
8546
|
+
const lineage = [];
|
|
8547
|
+
let groupId = endpointKind === "group"
|
|
8548
|
+
? endpointId
|
|
8549
|
+
: parentGroups.get(`${endpointKind}:${endpointId}`);
|
|
8550
|
+
while (groupId) {
|
|
8551
|
+
lineage.push(groupId);
|
|
8552
|
+
groupId = parentGroups.get(`group:${groupId}`);
|
|
8553
|
+
}
|
|
8554
|
+
return lineage;
|
|
8555
|
+
}
|
|
8556
|
+
function resolveEdgeParentGroupId(fromId, toId, nm, tm, gm, cm, parentGroups) {
|
|
8557
|
+
const fromKind = resolveEdgeEndpointKind(fromId, nm, tm, gm, cm);
|
|
8558
|
+
const toKind = resolveEdgeEndpointKind(toId, nm, tm, gm, cm);
|
|
8559
|
+
if (!fromKind || !toKind)
|
|
8560
|
+
return undefined;
|
|
8561
|
+
const toLineage = new Set(collectEdgeGroupLineage(toId, toKind, parentGroups));
|
|
8562
|
+
return collectEdgeGroupLineage(fromId, fromKind, parentGroups).find((groupId) => toLineage.has(groupId));
|
|
8563
|
+
}
|
|
8283
8564
|
// ── Node shapes ───────────────────────────────────────────────────────────
|
|
8284
8565
|
function renderShape$1(rc, n, palette) {
|
|
8285
8566
|
const s = n.style ?? {};
|
|
@@ -8436,19 +8717,16 @@ function renderToSVG(sg, container, options = {}) {
|
|
|
8436
8717
|
const srcCX = src.x + src.w / 2, srcCY = src.y + src.h / 2;
|
|
8437
8718
|
const [x1, y1] = getConnPoint(src, dstCX, dstCY, e.fromAnchor);
|
|
8438
8719
|
const [x2, y2] = getConnPoint(dst, srcCX, srcCY, e.toAnchor);
|
|
8720
|
+
const points = compactPolylinePoints(e.points?.length && e.points.length >= 2 ? e.points : [[x1, y1], [x2, y2]]);
|
|
8439
8721
|
const eg = mkGroup(`edge-${e.from}-${e.to}`, "eg");
|
|
8722
|
+
setParentGroupData(eg, resolveEdgeParentGroupId(e.from, e.to, nm, tm, gmMap, cm, parentGroups));
|
|
8440
8723
|
if (e.style?.opacity != null)
|
|
8441
8724
|
eg.setAttribute("opacity", String(e.style.opacity));
|
|
8442
|
-
const len = Math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2) || 1;
|
|
8443
|
-
const nx = (x2 - x1) / len, ny = (y2 - y1) / len;
|
|
8444
8725
|
const ecol = String(e.style?.stroke ?? palette.edgeStroke);
|
|
8445
8726
|
const { arrowAt, dashed } = connMeta(e.connector);
|
|
8446
8727
|
const HEAD = EDGE.headInset;
|
|
8447
|
-
const
|
|
8448
|
-
const
|
|
8449
|
-
const sx2 = arrowAt === "end" || arrowAt === "both" ? x2 - nx * HEAD : x2;
|
|
8450
|
-
const sy2 = arrowAt === "end" || arrowAt === "both" ? y2 - ny * HEAD : y2;
|
|
8451
|
-
const shaft = rc.line(sx1, sy1, sx2, sy2, {
|
|
8728
|
+
const shaftPoints = insetPolylineEndpoints(points, arrowAt, HEAD);
|
|
8729
|
+
const shaft = rc.path(polylinePathData(shaftPoints), {
|
|
8452
8730
|
...BASE_ROUGH,
|
|
8453
8731
|
roughness: 0.9,
|
|
8454
8732
|
seed: hashStr$3(e.from + e.to),
|
|
@@ -8459,18 +8737,21 @@ function renderToSVG(sg, container, options = {}) {
|
|
|
8459
8737
|
shaft.setAttribute("data-edge-role", "shaft");
|
|
8460
8738
|
eg.appendChild(shaft);
|
|
8461
8739
|
if (arrowAt === "end" || arrowAt === "both") {
|
|
8462
|
-
const
|
|
8740
|
+
const [endDx, endDy] = polylineEndpointDirection(points, "end");
|
|
8741
|
+
const [endX, endY] = polylineArrowTipPoint(dst, points, "end");
|
|
8742
|
+
const endHead = arrowHead(rc, endX, endY, Math.atan2(endDy, endDx), ecol, hashStr$3(e.to));
|
|
8463
8743
|
endHead.setAttribute("data-edge-role", "head");
|
|
8464
8744
|
eg.appendChild(endHead);
|
|
8465
8745
|
}
|
|
8466
8746
|
if (arrowAt === "start" || arrowAt === "both") {
|
|
8467
|
-
const
|
|
8747
|
+
const [startDx, startDy] = polylineEndpointDirection(points, "start");
|
|
8748
|
+
const [startX, startY] = polylineArrowTipPoint(src, points, "start");
|
|
8749
|
+
const startHead = arrowHead(rc, startX, startY, Math.atan2(-startDy, -startDx), ecol, hashStr$3(e.from + "back"));
|
|
8468
8750
|
startHead.setAttribute("data-edge-role", "head");
|
|
8469
8751
|
eg.appendChild(startHead);
|
|
8470
8752
|
}
|
|
8471
8753
|
if (e.label) {
|
|
8472
|
-
const
|
|
8473
|
-
const my = (y1 + y2) / 2 + nx * EDGE.labelOffset + (e.labelDy ?? 0);
|
|
8754
|
+
const { x: mx, y: my } = polylineLabelPosition(points, EDGE.labelOffset, e.labelDx ?? 0, e.labelDy ?? 0);
|
|
8474
8755
|
const tw = Math.max(e.label.length * 7 + 12, 36);
|
|
8475
8756
|
const bg = se("rect");
|
|
8476
8757
|
bg.setAttribute("x", String(mx - tw / 2));
|
|
@@ -9182,31 +9463,31 @@ function renderToCanvas(sg, canvas, options = {}) {
|
|
|
9182
9463
|
const srcCX = src.x + src.w / 2, srcCY = src.y + src.h / 2;
|
|
9183
9464
|
const [x1, y1] = getConnPoint(src, dstCX, dstCY, e.fromAnchor);
|
|
9184
9465
|
const [x2, y2] = getConnPoint(dst, srcCX, srcCY, e.toAnchor);
|
|
9466
|
+
const points = compactPolylinePoints(e.points?.length && e.points.length >= 2 ? e.points : [[x1, y1], [x2, y2]]);
|
|
9185
9467
|
if (e.style?.opacity != null)
|
|
9186
9468
|
ctx.globalAlpha = Number(e.style.opacity);
|
|
9187
9469
|
const ecol = String(e.style?.stroke ?? palette.edgeStroke);
|
|
9188
9470
|
const { arrowAt, dashed } = connMeta(e.connector);
|
|
9189
|
-
const len = Math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2) || 1;
|
|
9190
|
-
const nx = (x2 - x1) / len, ny = (y2 - y1) / len;
|
|
9191
9471
|
const HEAD = EDGE.headInset;
|
|
9192
|
-
const
|
|
9193
|
-
|
|
9194
|
-
const sx2 = arrowAt === 'end' || arrowAt === 'both' ? x2 - nx * HEAD : x2;
|
|
9195
|
-
const sy2 = arrowAt === 'end' || arrowAt === 'both' ? y2 - ny * HEAD : y2;
|
|
9196
|
-
rc.line(sx1, sy1, sx2, sy2, {
|
|
9472
|
+
const shaftPoints = insetPolylineEndpoints(points, arrowAt, HEAD);
|
|
9473
|
+
rc.path(polylinePathData(shaftPoints), {
|
|
9197
9474
|
...R, roughness: 0.9, seed: hashStr$3(e.from + e.to),
|
|
9198
9475
|
stroke: ecol,
|
|
9199
9476
|
strokeWidth: Number(e.style?.strokeWidth ?? 1.6),
|
|
9200
9477
|
...(dashed ? { strokeLineDash: EDGE.dashPattern } : {}),
|
|
9201
9478
|
});
|
|
9202
|
-
|
|
9203
|
-
|
|
9204
|
-
|
|
9205
|
-
|
|
9206
|
-
|
|
9479
|
+
if (arrowAt === 'end' || arrowAt === 'both') {
|
|
9480
|
+
const [endDx, endDy] = polylineEndpointDirection(points, 'end');
|
|
9481
|
+
const [endX, endY] = polylineArrowTipPoint(dst, points, 'end');
|
|
9482
|
+
drawArrowHead(rc, endX, endY, Math.atan2(endDy, endDx), ecol, hashStr$3(e.to));
|
|
9483
|
+
}
|
|
9484
|
+
if (arrowAt === 'start' || arrowAt === 'both') {
|
|
9485
|
+
const [startDx, startDy] = polylineEndpointDirection(points, 'start');
|
|
9486
|
+
const [startX, startY] = polylineArrowTipPoint(src, points, 'start');
|
|
9487
|
+
drawArrowHead(rc, startX, startY, Math.atan2(-startDy, -startDx), ecol, hashStr$3(e.from + 'back'));
|
|
9488
|
+
}
|
|
9207
9489
|
if (e.label) {
|
|
9208
|
-
const
|
|
9209
|
-
const my = (y1 + y2) / 2 + nx * EDGE.labelOffset + (e.labelDy ?? 0);
|
|
9490
|
+
const { x: mx, y: my } = polylineLabelPosition(points, EDGE.labelOffset, e.labelDx ?? 0, e.labelDy ?? 0);
|
|
9210
9491
|
// ── Edge label: font, font-size, letter-spacing ──
|
|
9211
9492
|
// always center-anchored (single line)
|
|
9212
9493
|
const eFontSize = Number(e.style?.fontSize ?? EDGE.labelFontSize);
|
|
@@ -9483,7 +9764,7 @@ const getTableEl = (svg, id) => getEl(svg, `table-${id}`);
|
|
|
9483
9764
|
const getNoteEl = (svg, id) => getEl(svg, `note-${id}`);
|
|
9484
9765
|
const getChartEl = (svg, id) => getEl(svg, `chart-${id}`);
|
|
9485
9766
|
const getMarkdownEl = (svg, id) => getEl(svg, `markdown-${id}`);
|
|
9486
|
-
const POSITIONABLE_SELECTOR = ".ng, .gg, .tg, .ntg, .cg, .mdg";
|
|
9767
|
+
const POSITIONABLE_SELECTOR = ".ng, .gg, .tg, .ntg, .cg, .eg, .mdg";
|
|
9487
9768
|
function resolveNonEdgeDrawEl(svg, target) {
|
|
9488
9769
|
return (getGroupEl(svg, target) ??
|
|
9489
9770
|
getTableEl(svg, target) ??
|
|
@@ -9903,7 +10184,7 @@ function animateShapeDraw(el, strokeDur = ANIMATION.nodeStrokeDur, stag = ANIMAT
|
|
|
9903
10184
|
}));
|
|
9904
10185
|
}
|
|
9905
10186
|
// ── Edge draw helpers ─────────────────────────────────────
|
|
9906
|
-
const EDGE_SHAFT_SELECTOR = '[data-edge-role="shaft"] path';
|
|
10187
|
+
const EDGE_SHAFT_SELECTOR = '[data-edge-role="shaft"] path, path[data-edge-role="shaft"]';
|
|
9907
10188
|
const EDGE_DECOR_SELECTOR = '[data-edge-role="head"], [data-edge-role="label"], [data-edge-role="label-bg"]';
|
|
9908
10189
|
function edgeShaftPaths(el) {
|
|
9909
10190
|
return Array.from(el.querySelectorAll(EDGE_SHAFT_SELECTOR));
|
|
@@ -10077,8 +10358,16 @@ class AnimationController {
|
|
|
10077
10358
|
_buildDrawStepIndex() {
|
|
10078
10359
|
const drawStepIndexByElementId = new Map();
|
|
10079
10360
|
forEachPlaybackStep(this.steps, (step, stepIndex) => {
|
|
10080
|
-
if (step.action !== "draw"
|
|
10361
|
+
if (step.action !== "draw")
|
|
10362
|
+
return;
|
|
10363
|
+
const edge = parseEdgeTarget(step.target);
|
|
10364
|
+
if (edge) {
|
|
10365
|
+
const edgeEl = getEdgeEl(this.svg, edge.from, edge.to);
|
|
10366
|
+
if (edgeEl && !drawStepIndexByElementId.has(edgeEl.id)) {
|
|
10367
|
+
drawStepIndexByElementId.set(edgeEl.id, stepIndex);
|
|
10368
|
+
}
|
|
10081
10369
|
return;
|
|
10370
|
+
}
|
|
10082
10371
|
const el = resolveNonEdgeDrawEl(this.svg, step.target);
|
|
10083
10372
|
if (el && !drawStepIndexByElementId.has(el.id)) {
|
|
10084
10373
|
drawStepIndexByElementId.set(el.id, stepIndex);
|
|
@@ -10778,6 +11067,7 @@ class AnimationController {
|
|
|
10778
11067
|
const el = getEdgeEl(this.svg, edge.from, edge.to);
|
|
10779
11068
|
if (!el)
|
|
10780
11069
|
return;
|
|
11070
|
+
showDrawEl(el);
|
|
10781
11071
|
if (silent) {
|
|
10782
11072
|
revealEdgeInstant(el);
|
|
10783
11073
|
requestAnimationFrame(() => requestAnimationFrame(() => {
|
|
@@ -11391,11 +11681,12 @@ const ANIMATION_CSS = `
|
|
|
11391
11681
|
.cg.faded, .eg.faded, .mdg.faded { opacity: 0.22; }
|
|
11392
11682
|
|
|
11393
11683
|
.ng.hidden { opacity: 0; pointer-events: none; }
|
|
11394
|
-
.gg.gg-hidden { opacity: 0; }
|
|
11395
|
-
.tg.gg-hidden { opacity: 0; }
|
|
11396
|
-
.ntg.gg-hidden { opacity: 0; }
|
|
11397
|
-
.cg.gg-hidden { opacity: 0; }
|
|
11398
|
-
.
|
|
11684
|
+
.gg.gg-hidden { opacity: 0; }
|
|
11685
|
+
.tg.gg-hidden { opacity: 0; }
|
|
11686
|
+
.ntg.gg-hidden { opacity: 0; }
|
|
11687
|
+
.cg.gg-hidden { opacity: 0; }
|
|
11688
|
+
.eg.gg-hidden { opacity: 0; }
|
|
11689
|
+
.mdg.gg-hidden { opacity: 0; }
|
|
11399
11690
|
|
|
11400
11691
|
/* narration caption */
|
|
11401
11692
|
.skm-caption { pointer-events: none; user-select: none; }
|