sketchmark 1.3.7 → 1.4.1
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 +21 -8
- 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/export/index.d.ts.map +1 -1
- package/dist/export/state.d.ts +8 -0
- package/dist/export/state.d.ts.map +1 -0
- package/dist/index.cjs +366 -48
- 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 +366 -48
- 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/render.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 +366 -48
- package/package.json +1 -1
package/dist/sketchmark.iife.js
CHANGED
|
@@ -360,6 +360,39 @@ var AIDiagram = (function (exports) {
|
|
|
360
360
|
function isPropKeyToken(t) {
|
|
361
361
|
return !!t && (t.type === "IDENT" || t.type === "KEYWORD");
|
|
362
362
|
}
|
|
363
|
+
const NUMBER_RE = /[-+]?(?:\d*\.\d+|\d+)(?:[eE][-+]?\d+)?/g;
|
|
364
|
+
function parseEdgeWaypoints(value, token) {
|
|
365
|
+
if (!value)
|
|
366
|
+
return undefined;
|
|
367
|
+
const numbers = (value.match(NUMBER_RE) ?? []).map((part) => Number(part));
|
|
368
|
+
if (!numbers.length)
|
|
369
|
+
return undefined;
|
|
370
|
+
if (numbers.length % 2 !== 0) {
|
|
371
|
+
throw new ParseError(`Edge via must contain x,y coordinate pairs`, token.line, token.col);
|
|
372
|
+
}
|
|
373
|
+
const points = [];
|
|
374
|
+
for (let index = 0; index < numbers.length; index += 2) {
|
|
375
|
+
const x = numbers[index];
|
|
376
|
+
const y = numbers[index + 1];
|
|
377
|
+
if (!Number.isFinite(x) || !Number.isFinite(y)) {
|
|
378
|
+
throw new ParseError(`Edge via contains a non-numeric coordinate`, token.line, token.col);
|
|
379
|
+
}
|
|
380
|
+
points.push([x, y]);
|
|
381
|
+
}
|
|
382
|
+
return points.length ? points : undefined;
|
|
383
|
+
}
|
|
384
|
+
function normalizeEdgeRoute(value, token) {
|
|
385
|
+
if (!value)
|
|
386
|
+
return undefined;
|
|
387
|
+
const normalized = value.toLowerCase();
|
|
388
|
+
if (normalized === "straight" || normalized === "polyline" || normalized === "orthogonal") {
|
|
389
|
+
return normalized;
|
|
390
|
+
}
|
|
391
|
+
if (normalized === "ortho" || normalized === "elbow") {
|
|
392
|
+
return "orthogonal";
|
|
393
|
+
}
|
|
394
|
+
throw new ParseError(`Unsupported edge route "${value}"; use straight, orthogonal, or polyline`, token.line, token.col);
|
|
395
|
+
}
|
|
363
396
|
function parse(src, options = {}) {
|
|
364
397
|
resetUid();
|
|
365
398
|
const preparedSource = applyPluginPreprocessors(src, options.plugins);
|
|
@@ -718,28 +751,63 @@ var AIDiagram = (function (exports) {
|
|
|
718
751
|
height: props.height !== undefined ? parseFloat(props.height) : undefined,
|
|
719
752
|
};
|
|
720
753
|
}
|
|
721
|
-
function
|
|
722
|
-
const toTok = rest.shift();
|
|
723
|
-
if (!toTok)
|
|
724
|
-
throw new ParseError("Expected edge target", 0, 0);
|
|
754
|
+
function parseEdgeProps(toks) {
|
|
725
755
|
const props = {};
|
|
726
756
|
let j = 0;
|
|
727
|
-
while (j <
|
|
728
|
-
const
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
j += 3;
|
|
757
|
+
while (j < toks.length) {
|
|
758
|
+
const key = toks[j];
|
|
759
|
+
const eq = toks[j + 1];
|
|
760
|
+
if (!isPropKeyToken(key) || eq?.type !== "EQUALS") {
|
|
761
|
+
j++;
|
|
762
|
+
continue;
|
|
734
763
|
}
|
|
735
|
-
|
|
764
|
+
const value = toks[j + 2];
|
|
765
|
+
if (!value) {
|
|
736
766
|
j++;
|
|
767
|
+
continue;
|
|
737
768
|
}
|
|
769
|
+
if (value.type === "LBRACKET") {
|
|
770
|
+
const parts = [];
|
|
771
|
+
let depth = 1;
|
|
772
|
+
j += 3;
|
|
773
|
+
while (j < toks.length && depth > 0) {
|
|
774
|
+
const tok = toks[j];
|
|
775
|
+
if (tok.type === "LBRACKET") {
|
|
776
|
+
depth++;
|
|
777
|
+
}
|
|
778
|
+
else if (tok.type === "RBRACKET") {
|
|
779
|
+
depth--;
|
|
780
|
+
if (depth === 0) {
|
|
781
|
+
j++;
|
|
782
|
+
break;
|
|
783
|
+
}
|
|
784
|
+
}
|
|
785
|
+
if (depth > 0)
|
|
786
|
+
parts.push(tok.value);
|
|
787
|
+
j++;
|
|
788
|
+
}
|
|
789
|
+
if (depth > 0) {
|
|
790
|
+
throw new ParseError(`Unterminated edge property list; expected ']'`, key.line, key.col);
|
|
791
|
+
}
|
|
792
|
+
props[key.value] = parts.join(" ");
|
|
793
|
+
continue;
|
|
794
|
+
}
|
|
795
|
+
props[key.value] = value.value;
|
|
796
|
+
j += 3;
|
|
738
797
|
}
|
|
798
|
+
return props;
|
|
799
|
+
}
|
|
800
|
+
function parseEdge(fromId, connector, rest) {
|
|
801
|
+
const toTok = rest.shift();
|
|
802
|
+
if (!toTok)
|
|
803
|
+
throw new ParseError("Expected edge target", 0, 0);
|
|
804
|
+
const props = parseEdgeProps(rest);
|
|
739
805
|
const dashed = connector.includes("--") ||
|
|
740
806
|
connector.includes(".-") ||
|
|
741
807
|
connector.includes("-.");
|
|
742
808
|
const bidirectional = connector.includes("<") && connector.includes(">");
|
|
809
|
+
const via = parseEdgeWaypoints(props.via, toTok);
|
|
810
|
+
const route = normalizeEdgeRoute(props.route, toTok) ?? (via?.length ? "polyline" : undefined);
|
|
743
811
|
return {
|
|
744
812
|
kind: "edge",
|
|
745
813
|
id: uid("edge"),
|
|
@@ -751,6 +819,8 @@ var AIDiagram = (function (exports) {
|
|
|
751
819
|
labelDy: props["label-dy"] !== undefined ? parseFloat(props["label-dy"]) : undefined,
|
|
752
820
|
fromAnchor: props["anchor-from"],
|
|
753
821
|
toAnchor: props["anchor-to"],
|
|
822
|
+
route,
|
|
823
|
+
via,
|
|
754
824
|
dashed,
|
|
755
825
|
bidirectional,
|
|
756
826
|
style: propsToStyle(props),
|
|
@@ -3684,6 +3754,8 @@ var AIDiagram = (function (exports) {
|
|
|
3684
3754
|
labelDy: e.labelDy,
|
|
3685
3755
|
fromAnchor: e.fromAnchor,
|
|
3686
3756
|
toAnchor: e.toAnchor,
|
|
3757
|
+
route: e.route,
|
|
3758
|
+
via: e.via,
|
|
3687
3759
|
dashed: e.dashed ?? false,
|
|
3688
3760
|
bidirectional: e.bidirectional ?? false,
|
|
3689
3761
|
style: e.style ?? {},
|
|
@@ -4285,6 +4357,151 @@ var AIDiagram = (function (exports) {
|
|
|
4285
4357
|
return anchoredConnPoint(src, anchor, dstCX, dstCY);
|
|
4286
4358
|
}
|
|
4287
4359
|
// ── Group depth (for paint order) ────────────────────────────────────────
|
|
4360
|
+
function segmentLength(a, b) {
|
|
4361
|
+
return Math.hypot(b[0] - a[0], b[1] - a[1]);
|
|
4362
|
+
}
|
|
4363
|
+
function compactPolylinePoints(points) {
|
|
4364
|
+
const compacted = [];
|
|
4365
|
+
for (const point of points) {
|
|
4366
|
+
const previous = compacted[compacted.length - 1];
|
|
4367
|
+
if (!previous || segmentLength(previous, point) > 0.01) {
|
|
4368
|
+
compacted.push(point);
|
|
4369
|
+
}
|
|
4370
|
+
}
|
|
4371
|
+
return compacted;
|
|
4372
|
+
}
|
|
4373
|
+
function polylinePathData(points) {
|
|
4374
|
+
return points
|
|
4375
|
+
.map(([x, y], index) => `${index === 0 ? "M" : "L"} ${x} ${y}`)
|
|
4376
|
+
.join(" ");
|
|
4377
|
+
}
|
|
4378
|
+
function polylineEndpointDirection(points, end) {
|
|
4379
|
+
const step = end === "start" ? 1 : -1;
|
|
4380
|
+
let index = end === "start" ? 0 : points.length - 1;
|
|
4381
|
+
while (index + step >= 0 && index + step < points.length) {
|
|
4382
|
+
const from = points[index];
|
|
4383
|
+
const to = points[index + step];
|
|
4384
|
+
const dx = to[0] - from[0];
|
|
4385
|
+
const dy = to[1] - from[1];
|
|
4386
|
+
const len = Math.hypot(dx, dy);
|
|
4387
|
+
if (len > 0.01) {
|
|
4388
|
+
return end === "start" ? [dx / len, dy / len] : [-dx / len, -dy / len];
|
|
4389
|
+
}
|
|
4390
|
+
index += step;
|
|
4391
|
+
}
|
|
4392
|
+
return [1, 0];
|
|
4393
|
+
}
|
|
4394
|
+
function insetPolylineEndpoints(points, arrowAt, inset) {
|
|
4395
|
+
const next = points.map((point) => [point[0], point[1]]);
|
|
4396
|
+
if (next.length < 2)
|
|
4397
|
+
return next;
|
|
4398
|
+
if (arrowAt === "start" || arrowAt === "both") {
|
|
4399
|
+
const [dx, dy] = polylineEndpointDirection(next, "start");
|
|
4400
|
+
next[0] = [next[0][0] + dx * inset, next[0][1] + dy * inset];
|
|
4401
|
+
}
|
|
4402
|
+
if (arrowAt === "end" || arrowAt === "both") {
|
|
4403
|
+
const [dx, dy] = polylineEndpointDirection(next, "end");
|
|
4404
|
+
const last = next.length - 1;
|
|
4405
|
+
next[last] = [next[last][0] - dx * inset, next[last][1] - dy * inset];
|
|
4406
|
+
}
|
|
4407
|
+
return compactPolylinePoints(next);
|
|
4408
|
+
}
|
|
4409
|
+
function polylineLabelPosition(points, offset, dx = 0, dy = 0) {
|
|
4410
|
+
if (points.length < 2) {
|
|
4411
|
+
const [x, y] = points[0] ?? [0, 0];
|
|
4412
|
+
return { x: x + dx, y: y + dy };
|
|
4413
|
+
}
|
|
4414
|
+
const lengths = points.slice(1).map((point, index) => segmentLength(points[index], point));
|
|
4415
|
+
const total = lengths.reduce((sum, value) => sum + value, 0);
|
|
4416
|
+
if (total <= 0.01) {
|
|
4417
|
+
const [x, y] = points[0];
|
|
4418
|
+
return { x: x + dx, y: y + dy };
|
|
4419
|
+
}
|
|
4420
|
+
let travelled = 0;
|
|
4421
|
+
const target = total / 2;
|
|
4422
|
+
for (let index = 0; index < lengths.length; index += 1) {
|
|
4423
|
+
const length = lengths[index];
|
|
4424
|
+
if (travelled + length >= target) {
|
|
4425
|
+
const from = points[index];
|
|
4426
|
+
const to = points[index + 1];
|
|
4427
|
+
const t = length > 0 ? (target - travelled) / length : 0;
|
|
4428
|
+
const ux = (to[0] - from[0]) / length;
|
|
4429
|
+
const uy = (to[1] - from[1]) / length;
|
|
4430
|
+
return {
|
|
4431
|
+
x: from[0] + (to[0] - from[0]) * t - uy * offset + dx,
|
|
4432
|
+
y: from[1] + (to[1] - from[1]) * t + ux * offset + dy,
|
|
4433
|
+
};
|
|
4434
|
+
}
|
|
4435
|
+
travelled += length;
|
|
4436
|
+
}
|
|
4437
|
+
const [x, y] = points[points.length - 1];
|
|
4438
|
+
return { x: x + dx, y: y + dy };
|
|
4439
|
+
}
|
|
4440
|
+
function rectBoundaryPoint(entity, point, direction) {
|
|
4441
|
+
const [px, py] = point;
|
|
4442
|
+
const [dx, dy] = direction;
|
|
4443
|
+
const candidates = [];
|
|
4444
|
+
const minX = entity.x;
|
|
4445
|
+
const maxX = entity.x + entity.w;
|
|
4446
|
+
const minY = entity.y;
|
|
4447
|
+
const maxY = entity.y + entity.h;
|
|
4448
|
+
const epsilon = 0.01;
|
|
4449
|
+
if (Math.abs(dx) > epsilon) {
|
|
4450
|
+
candidates.push((minX - px) / dx, (maxX - px) / dx);
|
|
4451
|
+
}
|
|
4452
|
+
if (Math.abs(dy) > epsilon) {
|
|
4453
|
+
candidates.push((minY - py) / dy, (maxY - py) / dy);
|
|
4454
|
+
}
|
|
4455
|
+
const valid = candidates
|
|
4456
|
+
.filter((t) => t >= -epsilon)
|
|
4457
|
+
.map((t) => ({
|
|
4458
|
+
t: Math.max(0, t),
|
|
4459
|
+
x: px + dx * t,
|
|
4460
|
+
y: py + dy * t,
|
|
4461
|
+
}))
|
|
4462
|
+
.filter(({ x, y }) => x >= minX - epsilon &&
|
|
4463
|
+
x <= maxX + epsilon &&
|
|
4464
|
+
y >= minY - epsilon &&
|
|
4465
|
+
y <= maxY + epsilon)
|
|
4466
|
+
.sort((a, b) => a.t - b.t);
|
|
4467
|
+
const hit = valid[0];
|
|
4468
|
+
return hit ? [hit.x, hit.y] : point;
|
|
4469
|
+
}
|
|
4470
|
+
function ellipseBoundaryPoint(entity, point, direction) {
|
|
4471
|
+
const [px, py] = point;
|
|
4472
|
+
const [dx, dy] = direction;
|
|
4473
|
+
const cx = entity.x + entity.w / 2;
|
|
4474
|
+
const cy = entity.y + entity.h / 2;
|
|
4475
|
+
const rx = Math.max(1, entity.w * 0.44);
|
|
4476
|
+
const ry = Math.max(1, entity.h * 0.44);
|
|
4477
|
+
const x0 = px - cx;
|
|
4478
|
+
const y0 = py - cy;
|
|
4479
|
+
const a = (dx * dx) / (rx * rx) + (dy * dy) / (ry * ry);
|
|
4480
|
+
const b = 2 * ((x0 * dx) / (rx * rx) + (y0 * dy) / (ry * ry));
|
|
4481
|
+
const c = (x0 * x0) / (rx * rx) + (y0 * y0) / (ry * ry) - 1;
|
|
4482
|
+
const disc = b * b - 4 * a * c;
|
|
4483
|
+
if (a <= 0 || disc < 0)
|
|
4484
|
+
return point;
|
|
4485
|
+
const sqrt = Math.sqrt(disc);
|
|
4486
|
+
const hits = [(-b - sqrt) / (2 * a), (-b + sqrt) / (2 * a)]
|
|
4487
|
+
.filter((t) => t >= -0.01)
|
|
4488
|
+
.sort((left, right) => left - right);
|
|
4489
|
+
const t = Math.max(0, hits[0] ?? 0);
|
|
4490
|
+
return [px + dx * t, py + dy * t];
|
|
4491
|
+
}
|
|
4492
|
+
function polylineArrowTipPoint(entity, points, end) {
|
|
4493
|
+
const point = end === "start" ? points[0] : points[points.length - 1];
|
|
4494
|
+
if (!point)
|
|
4495
|
+
return [0, 0];
|
|
4496
|
+
const [dx, dy] = polylineEndpointDirection(points, end);
|
|
4497
|
+
const outward = end === "start" ? [dx, dy] : [-dx, -dy];
|
|
4498
|
+
if (Math.hypot(outward[0], outward[1]) <= 0.01)
|
|
4499
|
+
return point;
|
|
4500
|
+
if (entity.shape === "circle") {
|
|
4501
|
+
return ellipseBoundaryPoint(entity, point, outward);
|
|
4502
|
+
}
|
|
4503
|
+
return rectBoundaryPoint(entity, point, outward);
|
|
4504
|
+
}
|
|
4288
4505
|
function groupDepth(g, gm) {
|
|
4289
4506
|
let d = 0;
|
|
4290
4507
|
let cur = g;
|
|
@@ -5245,6 +5462,31 @@ var AIDiagram = (function (exports) {
|
|
|
5245
5462
|
const t = Math.min(tx, ty);
|
|
5246
5463
|
return [cx + t * dx, cy + t * dy];
|
|
5247
5464
|
}
|
|
5465
|
+
function distance$1(a, b) {
|
|
5466
|
+
return Math.hypot(b[0] - a[0], b[1] - a[1]);
|
|
5467
|
+
}
|
|
5468
|
+
function compactEdgePoints(points) {
|
|
5469
|
+
const compacted = [];
|
|
5470
|
+
for (const point of points) {
|
|
5471
|
+
const previous = compacted[compacted.length - 1];
|
|
5472
|
+
if (!previous || distance$1(previous, point) > 0.01) {
|
|
5473
|
+
compacted.push(point);
|
|
5474
|
+
}
|
|
5475
|
+
}
|
|
5476
|
+
return compacted;
|
|
5477
|
+
}
|
|
5478
|
+
function orthogonalEdgePoints(start, end) {
|
|
5479
|
+
if (Math.abs(start[0] - end[0]) < 0.01 || Math.abs(start[1] - end[1]) < 0.01) {
|
|
5480
|
+
return [start, end];
|
|
5481
|
+
}
|
|
5482
|
+
const midX = (start[0] + end[0]) / 2;
|
|
5483
|
+
return compactEdgePoints([
|
|
5484
|
+
start,
|
|
5485
|
+
[midX, start[1]],
|
|
5486
|
+
[midX, end[1]],
|
|
5487
|
+
end,
|
|
5488
|
+
]);
|
|
5489
|
+
}
|
|
5248
5490
|
function routeEdges(sg) {
|
|
5249
5491
|
const nm = nodeMap(sg);
|
|
5250
5492
|
const tm = tableMap(sg);
|
|
@@ -5274,10 +5516,17 @@ var AIDiagram = (function (exports) {
|
|
|
5274
5516
|
}
|
|
5275
5517
|
const dstCX = dst.x + dst.w / 2, dstCY = dst.y + dst.h / 2;
|
|
5276
5518
|
const srcCX = src.x + src.w / 2, srcCY = src.y + src.h / 2;
|
|
5277
|
-
e.
|
|
5278
|
-
|
|
5279
|
-
|
|
5280
|
-
|
|
5519
|
+
const start = anchoredConnPoint(src, e.fromAnchor, dstCX, dstCY);
|
|
5520
|
+
const end = anchoredConnPoint(dst, e.toAnchor, srcCX, srcCY);
|
|
5521
|
+
if (e.via?.length) {
|
|
5522
|
+
e.points = compactEdgePoints([start, ...e.via, end]);
|
|
5523
|
+
}
|
|
5524
|
+
else if (e.route === "orthogonal") {
|
|
5525
|
+
e.points = orthogonalEdgePoints(start, end);
|
|
5526
|
+
}
|
|
5527
|
+
else {
|
|
5528
|
+
e.points = [start, end];
|
|
5529
|
+
}
|
|
5281
5530
|
}
|
|
5282
5531
|
}
|
|
5283
5532
|
function computeBounds(sg, margin) {
|
|
@@ -5287,6 +5536,7 @@ var AIDiagram = (function (exports) {
|
|
|
5287
5536
|
...sg.tables.map((t) => t.x + t.w),
|
|
5288
5537
|
...sg.charts.map((c) => c.x + c.w),
|
|
5289
5538
|
...sg.markdowns.map((m) => m.x + m.w),
|
|
5539
|
+
...sg.edges.flatMap((e) => (e.points ?? []).map(([x]) => x)),
|
|
5290
5540
|
];
|
|
5291
5541
|
const allY = [
|
|
5292
5542
|
...sg.nodes.map((n) => n.y + n.h),
|
|
@@ -5294,6 +5544,7 @@ var AIDiagram = (function (exports) {
|
|
|
5294
5544
|
...sg.tables.map((t) => t.y + t.h),
|
|
5295
5545
|
...sg.charts.map((c) => c.y + c.h),
|
|
5296
5546
|
...sg.markdowns.map((m) => m.y + m.h),
|
|
5547
|
+
...sg.edges.flatMap((e) => (e.points ?? []).map(([, y]) => y)),
|
|
5297
5548
|
];
|
|
5298
5549
|
const autoWidth = (allX.length ? Math.max(...allX) : 400) + margin;
|
|
5299
5550
|
const autoHeight = (allY.length ? Math.max(...allY) : 300) + margin;
|
|
@@ -8467,20 +8718,16 @@ var AIDiagram = (function (exports) {
|
|
|
8467
8718
|
const srcCX = src.x + src.w / 2, srcCY = src.y + src.h / 2;
|
|
8468
8719
|
const [x1, y1] = getConnPoint(src, dstCX, dstCY, e.fromAnchor);
|
|
8469
8720
|
const [x2, y2] = getConnPoint(dst, srcCX, srcCY, e.toAnchor);
|
|
8721
|
+
const points = compactPolylinePoints(e.points?.length && e.points.length >= 2 ? e.points : [[x1, y1], [x2, y2]]);
|
|
8470
8722
|
const eg = mkGroup(`edge-${e.from}-${e.to}`, "eg");
|
|
8471
8723
|
setParentGroupData(eg, resolveEdgeParentGroupId(e.from, e.to, nm, tm, gmMap, cm, parentGroups));
|
|
8472
8724
|
if (e.style?.opacity != null)
|
|
8473
8725
|
eg.setAttribute("opacity", String(e.style.opacity));
|
|
8474
|
-
const len = Math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2) || 1;
|
|
8475
|
-
const nx = (x2 - x1) / len, ny = (y2 - y1) / len;
|
|
8476
8726
|
const ecol = String(e.style?.stroke ?? palette.edgeStroke);
|
|
8477
8727
|
const { arrowAt, dashed } = connMeta(e.connector);
|
|
8478
8728
|
const HEAD = EDGE.headInset;
|
|
8479
|
-
const
|
|
8480
|
-
const
|
|
8481
|
-
const sx2 = arrowAt === "end" || arrowAt === "both" ? x2 - nx * HEAD : x2;
|
|
8482
|
-
const sy2 = arrowAt === "end" || arrowAt === "both" ? y2 - ny * HEAD : y2;
|
|
8483
|
-
const shaft = rc.line(sx1, sy1, sx2, sy2, {
|
|
8729
|
+
const shaftPoints = insetPolylineEndpoints(points, arrowAt, HEAD);
|
|
8730
|
+
const shaft = rc.path(polylinePathData(shaftPoints), {
|
|
8484
8731
|
...BASE_ROUGH,
|
|
8485
8732
|
roughness: 0.9,
|
|
8486
8733
|
seed: hashStr$3(e.from + e.to),
|
|
@@ -8491,18 +8738,21 @@ var AIDiagram = (function (exports) {
|
|
|
8491
8738
|
shaft.setAttribute("data-edge-role", "shaft");
|
|
8492
8739
|
eg.appendChild(shaft);
|
|
8493
8740
|
if (arrowAt === "end" || arrowAt === "both") {
|
|
8494
|
-
const
|
|
8741
|
+
const [endDx, endDy] = polylineEndpointDirection(points, "end");
|
|
8742
|
+
const [endX, endY] = polylineArrowTipPoint(dst, points, "end");
|
|
8743
|
+
const endHead = arrowHead(rc, endX, endY, Math.atan2(endDy, endDx), ecol, hashStr$3(e.to));
|
|
8495
8744
|
endHead.setAttribute("data-edge-role", "head");
|
|
8496
8745
|
eg.appendChild(endHead);
|
|
8497
8746
|
}
|
|
8498
8747
|
if (arrowAt === "start" || arrowAt === "both") {
|
|
8499
|
-
const
|
|
8748
|
+
const [startDx, startDy] = polylineEndpointDirection(points, "start");
|
|
8749
|
+
const [startX, startY] = polylineArrowTipPoint(src, points, "start");
|
|
8750
|
+
const startHead = arrowHead(rc, startX, startY, Math.atan2(-startDy, -startDx), ecol, hashStr$3(e.from + "back"));
|
|
8500
8751
|
startHead.setAttribute("data-edge-role", "head");
|
|
8501
8752
|
eg.appendChild(startHead);
|
|
8502
8753
|
}
|
|
8503
8754
|
if (e.label) {
|
|
8504
|
-
const
|
|
8505
|
-
const my = (y1 + y2) / 2 + nx * EDGE.labelOffset + (e.labelDy ?? 0);
|
|
8755
|
+
const { x: mx, y: my } = polylineLabelPosition(points, EDGE.labelOffset, e.labelDx ?? 0, e.labelDy ?? 0);
|
|
8506
8756
|
const tw = Math.max(e.label.length * 7 + 12, 36);
|
|
8507
8757
|
const bg = se("rect");
|
|
8508
8758
|
bg.setAttribute("x", String(mx - tw / 2));
|
|
@@ -9214,31 +9464,31 @@ var AIDiagram = (function (exports) {
|
|
|
9214
9464
|
const srcCX = src.x + src.w / 2, srcCY = src.y + src.h / 2;
|
|
9215
9465
|
const [x1, y1] = getConnPoint(src, dstCX, dstCY, e.fromAnchor);
|
|
9216
9466
|
const [x2, y2] = getConnPoint(dst, srcCX, srcCY, e.toAnchor);
|
|
9467
|
+
const points = compactPolylinePoints(e.points?.length && e.points.length >= 2 ? e.points : [[x1, y1], [x2, y2]]);
|
|
9217
9468
|
if (e.style?.opacity != null)
|
|
9218
9469
|
ctx.globalAlpha = Number(e.style.opacity);
|
|
9219
9470
|
const ecol = String(e.style?.stroke ?? palette.edgeStroke);
|
|
9220
9471
|
const { arrowAt, dashed } = connMeta(e.connector);
|
|
9221
|
-
const len = Math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2) || 1;
|
|
9222
|
-
const nx = (x2 - x1) / len, ny = (y2 - y1) / len;
|
|
9223
9472
|
const HEAD = EDGE.headInset;
|
|
9224
|
-
const
|
|
9225
|
-
|
|
9226
|
-
const sx2 = arrowAt === 'end' || arrowAt === 'both' ? x2 - nx * HEAD : x2;
|
|
9227
|
-
const sy2 = arrowAt === 'end' || arrowAt === 'both' ? y2 - ny * HEAD : y2;
|
|
9228
|
-
rc.line(sx1, sy1, sx2, sy2, {
|
|
9473
|
+
const shaftPoints = insetPolylineEndpoints(points, arrowAt, HEAD);
|
|
9474
|
+
rc.path(polylinePathData(shaftPoints), {
|
|
9229
9475
|
...R, roughness: 0.9, seed: hashStr$3(e.from + e.to),
|
|
9230
9476
|
stroke: ecol,
|
|
9231
9477
|
strokeWidth: Number(e.style?.strokeWidth ?? 1.6),
|
|
9232
9478
|
...(dashed ? { strokeLineDash: EDGE.dashPattern } : {}),
|
|
9233
9479
|
});
|
|
9234
|
-
|
|
9235
|
-
|
|
9236
|
-
|
|
9237
|
-
|
|
9238
|
-
|
|
9480
|
+
if (arrowAt === 'end' || arrowAt === 'both') {
|
|
9481
|
+
const [endDx, endDy] = polylineEndpointDirection(points, 'end');
|
|
9482
|
+
const [endX, endY] = polylineArrowTipPoint(dst, points, 'end');
|
|
9483
|
+
drawArrowHead(rc, endX, endY, Math.atan2(endDy, endDx), ecol, hashStr$3(e.to));
|
|
9484
|
+
}
|
|
9485
|
+
if (arrowAt === 'start' || arrowAt === 'both') {
|
|
9486
|
+
const [startDx, startDy] = polylineEndpointDirection(points, 'start');
|
|
9487
|
+
const [startX, startY] = polylineArrowTipPoint(src, points, 'start');
|
|
9488
|
+
drawArrowHead(rc, startX, startY, Math.atan2(-startDy, -startDx), ecol, hashStr$3(e.from + 'back'));
|
|
9489
|
+
}
|
|
9239
9490
|
if (e.label) {
|
|
9240
|
-
const
|
|
9241
|
-
const my = (y1 + y2) / 2 + nx * EDGE.labelOffset + (e.labelDy ?? 0);
|
|
9491
|
+
const { x: mx, y: my } = polylineLabelPosition(points, EDGE.labelOffset, e.labelDx ?? 0, e.labelDy ?? 0);
|
|
9242
9492
|
// ── Edge label: font, font-size, letter-spacing ──
|
|
9243
9493
|
// always center-anchored (single line)
|
|
9244
9494
|
const eFontSize = Number(e.style?.fontSize ?? EDGE.labelFontSize);
|
|
@@ -9935,7 +10185,7 @@ var AIDiagram = (function (exports) {
|
|
|
9935
10185
|
}));
|
|
9936
10186
|
}
|
|
9937
10187
|
// ── Edge draw helpers ─────────────────────────────────────
|
|
9938
|
-
const EDGE_SHAFT_SELECTOR = '[data-edge-role="shaft"] path';
|
|
10188
|
+
const EDGE_SHAFT_SELECTOR = '[data-edge-role="shaft"] path, path[data-edge-role="shaft"]';
|
|
9939
10189
|
const EDGE_DECOR_SELECTOR = '[data-edge-role="head"], [data-edge-role="label"], [data-edge-role="label-bg"]';
|
|
9940
10190
|
function edgeShaftPaths(el) {
|
|
9941
10191
|
return Array.from(el.querySelectorAll(EDGE_SHAFT_SELECTOR));
|
|
@@ -11152,8 +11402,11 @@ var AIDiagram = (function (exports) {
|
|
|
11152
11402
|
* 4. After guide finishes → fade in rough.js element, remove guide
|
|
11153
11403
|
*/
|
|
11154
11404
|
_animateAnnotation(roughEl, guideD, silent) {
|
|
11155
|
-
if (silent)
|
|
11405
|
+
if (silent) {
|
|
11406
|
+
roughEl.style.opacity = "1";
|
|
11407
|
+
roughEl.style.transition = "none";
|
|
11156
11408
|
return;
|
|
11409
|
+
}
|
|
11157
11410
|
// Hide rough.js element — will be revealed after guide draws
|
|
11158
11411
|
roughEl.style.opacity = "0";
|
|
11159
11412
|
roughEl.style.transition = "none";
|
|
@@ -11443,10 +11696,74 @@ var AIDiagram = (function (exports) {
|
|
|
11443
11696
|
.skm-caption { pointer-events: none; user-select: none; }
|
|
11444
11697
|
`;
|
|
11445
11698
|
|
|
11699
|
+
const exportAnimationState = new WeakMap();
|
|
11700
|
+
function bindExportAnimationState(svg, state) {
|
|
11701
|
+
exportAnimationState.set(svg, state);
|
|
11702
|
+
}
|
|
11703
|
+
function getExportAnimationState(svg) {
|
|
11704
|
+
return exportAnimationState.get(svg);
|
|
11705
|
+
}
|
|
11706
|
+
|
|
11446
11707
|
// ============================================================
|
|
11447
11708
|
// sketchmark — Export System
|
|
11448
11709
|
// SVG, PNG, Canvas, GIF (stub), MP4 (stub)
|
|
11449
11710
|
// ============================================================
|
|
11711
|
+
const EXPORT_SVG_STYLE_ID = "sketchmark-export-state";
|
|
11712
|
+
const EXPORT_SVG_STATE_CSS = `
|
|
11713
|
+
.ng, .gg, .tg, .ntg, .cg, .eg, .mdg {
|
|
11714
|
+
animation: none !important;
|
|
11715
|
+
transition: none !important;
|
|
11716
|
+
}
|
|
11717
|
+
|
|
11718
|
+
.ng.hidden { opacity: 0 !important; pointer-events: none !important; }
|
|
11719
|
+
.gg.gg-hidden,
|
|
11720
|
+
.tg.gg-hidden,
|
|
11721
|
+
.ntg.gg-hidden,
|
|
11722
|
+
.cg.gg-hidden,
|
|
11723
|
+
.eg.gg-hidden,
|
|
11724
|
+
.mdg.gg-hidden { opacity: 0 !important; }
|
|
11725
|
+
|
|
11726
|
+
.ng.faded,
|
|
11727
|
+
.gg.faded,
|
|
11728
|
+
.tg.faded,
|
|
11729
|
+
.ntg.faded,
|
|
11730
|
+
.cg.faded,
|
|
11731
|
+
.eg.faded,
|
|
11732
|
+
.mdg.faded { opacity: 0.22 !important; }
|
|
11733
|
+
|
|
11734
|
+
.ng.hl path, .ng.hl rect, .ng.hl ellipse, .ng.hl polygon,
|
|
11735
|
+
.tg.hl path, .tg.hl rect,
|
|
11736
|
+
.ntg.hl path, .ntg.hl polygon,
|
|
11737
|
+
.cg.hl path, .cg.hl rect,
|
|
11738
|
+
.mdg.hl text,
|
|
11739
|
+
.eg.hl path, .eg.hl line, .eg.hl polygon { stroke-width: 2.8 !important; }
|
|
11740
|
+
`;
|
|
11741
|
+
function buildExportSnapshot(svg) {
|
|
11742
|
+
const snapshot = svg.cloneNode(true);
|
|
11743
|
+
const animationState = getExportAnimationState(svg);
|
|
11744
|
+
if (animationState?.steps.length) {
|
|
11745
|
+
snapshot.querySelector("#annotation-layer")?.remove();
|
|
11746
|
+
let rc = null;
|
|
11747
|
+
try {
|
|
11748
|
+
rc = rough.svg(snapshot);
|
|
11749
|
+
}
|
|
11750
|
+
catch {
|
|
11751
|
+
rc = null;
|
|
11752
|
+
}
|
|
11753
|
+
const anim = new AnimationController(snapshot, animationState.steps, undefined, rc, animationState.config);
|
|
11754
|
+
anim.goTo(animationState.steps.length - 1);
|
|
11755
|
+
}
|
|
11756
|
+
injectExportStyles(snapshot);
|
|
11757
|
+
return snapshot;
|
|
11758
|
+
}
|
|
11759
|
+
function injectExportStyles(svg) {
|
|
11760
|
+
if (svg.querySelector(`#${EXPORT_SVG_STYLE_ID}`))
|
|
11761
|
+
return;
|
|
11762
|
+
const style = document.createElementNS(SVG_NS$1, "style");
|
|
11763
|
+
style.setAttribute("id", EXPORT_SVG_STYLE_ID);
|
|
11764
|
+
style.textContent = EXPORT_SVG_STATE_CSS;
|
|
11765
|
+
svg.insertBefore(style, svg.firstChild);
|
|
11766
|
+
}
|
|
11450
11767
|
// ── Trigger browser download ──────────────────────────────
|
|
11451
11768
|
function download(blob, filename) {
|
|
11452
11769
|
const url = URL.createObjectURL(blob);
|
|
@@ -11460,15 +11777,15 @@ var AIDiagram = (function (exports) {
|
|
|
11460
11777
|
}
|
|
11461
11778
|
// ── SVG export ────────────────────────────────────────────
|
|
11462
11779
|
function exportSVG(svg, opts = {}) {
|
|
11463
|
-
const str = svgToString(svg);
|
|
11780
|
+
const str = svgToString(buildExportSnapshot(svg));
|
|
11464
11781
|
const blob = new Blob([str], { type: 'image/svg+xml;charset=utf-8' });
|
|
11465
11782
|
download(blob, opts.filename ?? 'diagram.svg');
|
|
11466
11783
|
}
|
|
11467
11784
|
function getSVGString(svg) {
|
|
11468
|
-
return svgToString(svg);
|
|
11785
|
+
return svgToString(buildExportSnapshot(svg));
|
|
11469
11786
|
}
|
|
11470
11787
|
function getSVGBlob(svg) {
|
|
11471
|
-
return new Blob([svgToString(svg)], { type: 'image/svg+xml;charset=utf-8' });
|
|
11788
|
+
return new Blob([svgToString(buildExportSnapshot(svg))], { type: 'image/svg+xml;charset=utf-8' });
|
|
11472
11789
|
}
|
|
11473
11790
|
// ── PNG export (from SVG via Canvas) ─────────────────────
|
|
11474
11791
|
async function exportPNG(svg, opts = {}) {
|
|
@@ -11494,7 +11811,7 @@ var AIDiagram = (function (exports) {
|
|
|
11494
11811
|
ctx.fillStyle = EXPORT.fallbackBg;
|
|
11495
11812
|
ctx.fillRect(0, 0, w, h);
|
|
11496
11813
|
}
|
|
11497
|
-
const svgStr = svgToString(svg);
|
|
11814
|
+
const svgStr = svgToString(buildExportSnapshot(svg));
|
|
11498
11815
|
const blob = new Blob([svgStr], { type: 'image/svg+xml;charset=utf-8' });
|
|
11499
11816
|
const url = URL.createObjectURL(blob);
|
|
11500
11817
|
await new Promise((resolve, reject) => {
|
|
@@ -11512,7 +11829,7 @@ var AIDiagram = (function (exports) {
|
|
|
11512
11829
|
}
|
|
11513
11830
|
// ── HTML export (self-contained) ──────────────────────────
|
|
11514
11831
|
function exportHTML(svg, dslSource, opts = {}) {
|
|
11515
|
-
const svgStr = svgToString(svg);
|
|
11832
|
+
const svgStr = svgToString(buildExportSnapshot(svg));
|
|
11516
11833
|
const html = `<!DOCTYPE html>
|
|
11517
11834
|
<html lang="en">
|
|
11518
11835
|
<head>
|
|
@@ -11693,6 +12010,7 @@ var AIDiagram = (function (exports) {
|
|
|
11693
12010
|
}
|
|
11694
12011
|
const containerEl = el instanceof SVGSVGElement ? undefined : el;
|
|
11695
12012
|
anim = new AnimationController(svg, ast.steps, containerEl, rc, ast.config);
|
|
12013
|
+
bindExportAnimationState(svg, { steps: ast.steps, config: ast.config });
|
|
11696
12014
|
}
|
|
11697
12015
|
if (typeof tts === "boolean") {
|
|
11698
12016
|
anim.tts = tts;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sketchmark",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.1",
|
|
4
4
|
"description": "A plain-text DSL for hand-drawn diagrams. Write boxes, edges, and groups as code — renders sketchy SVG/Canvas via rough.js with a built-in step-by-step animation system.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"diagram",
|