docblocks-react-ui 0.31.1 → 0.32.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.
@@ -14394,6 +14394,129 @@ const PORT_NORMAL = {
14394
14394
  /** The route-avoidance's boundary tolerance (canvas px — a route 0.5px
14395
14395
  * off a figure's edge stands clear of it). */
14396
14396
  const ROUTE_EPS = .5;
14397
+ // src/canvas/connector-segment.ts
14398
+ /** The run's movable axis: a vertical run moves in x, a horizontal one in y
14399
+ * (null over a diagonal / a zero-length run — the route is orthogonal, so
14400
+ * only a degenerate data stand bears one). */
14401
+ function segmentAxisOf(from, to) {
14402
+ if (from.x === to.x && from.y !== to.y) return "x";
14403
+ if (from.y === to.y && from.x !== to.x) return "y";
14404
+ return null;
14405
+ }
14406
+ /** The point's distance to the segment (the press's pick's measure). */
14407
+ function distanceToSegment(point, from, to) {
14408
+ const dx = to.x - from.x;
14409
+ const dy = to.y - from.y;
14410
+ const lengthSq = dx * dx + dy * dy;
14411
+ if (lengthSq === 0) return Math.hypot(point.x - from.x, point.y - from.y);
14412
+ const t = Math.max(0, Math.min(1, ((point.x - from.x) * dx + (point.y - from.y) * dy) / lengthSq));
14413
+ return Math.hypot(point.x - (from.x + t * dx), point.y - (from.y + t * dy));
14414
+ }
14415
+ /**
14416
+ * The route's segment nearest the point (the index over the vertices — the
14417
+ * segment `i` stands between `points[i]` and `points[i + 1]`): the port
14418
+ * attachment runs stand off the pick (a press on them selects the line), so
14419
+ * only the runs between the endpoints are returned.
14420
+ */
14421
+ function nearestSegmentOf(points, point, reach) {
14422
+ let best = null;
14423
+ let bestDistance = reach;
14424
+ for (let i = 1; i < points.length - 2; i += 1) {
14425
+ const from = points[i];
14426
+ const to = points[i + 1];
14427
+ if (from === void 0 || to === void 0) continue;
14428
+ if (segmentAxisOf(from, to) === null) continue;
14429
+ const distance = distanceToSegment(point, from, to);
14430
+ if (distance <= bestDistance) {
14431
+ best = i;
14432
+ bestDistance = distance;
14433
+ }
14434
+ }
14435
+ return best;
14436
+ }
14437
+ /** The point moved by `delta` along the run's movable axis. */
14438
+ function shifted(point, axis, delta) {
14439
+ return axis === "x" ? {
14440
+ x: point.x + delta,
14441
+ y: point.y
14442
+ } : {
14443
+ x: point.x,
14444
+ y: point.y + delta
14445
+ };
14446
+ }
14447
+ /**
14448
+ * The route with the segment moved parallel by `delta`: the run's own
14449
+ * vertices take the new coordinate; a stub point (the run touches the port's
14450
+ * attachment) keeps its place and a JOG vertex lands beside it, so the line
14451
+ * still leaves / enters the port along its normal. The port points and the
14452
+ * attachment runs themselves stand unchanged.
14453
+ */
14454
+ function moveSegmentRoute(points, index, delta, stubEnds) {
14455
+ const from = points[index];
14456
+ const to = points[index + 1];
14457
+ if (from === void 0 || to === void 0 || delta === 0) return [...points];
14458
+ const axis = segmentAxisOf(from, to);
14459
+ if (axis === null) return [...points];
14460
+ if (index <= 0 || index >= points.length - 2) return [...points];
14461
+ const startStub = index === 1 && stubEnds.first;
14462
+ const endStub = index + 1 === points.length - 2 && stubEnds.last;
14463
+ const next = [];
14464
+ for (let i = 0; i < points.length; i += 1) {
14465
+ const point = { ...points[i] };
14466
+ if (i === index && !startStub) point[axis] += delta;
14467
+ if (i === index + 1 && !endStub) point[axis] += delta;
14468
+ if (startStub && i === 2) next.push(shifted(points[1], axis, delta));
14469
+ next.push(point);
14470
+ }
14471
+ if (endStub) next.splice(next.length - 2, 0, shifted(points[points.length - 2], axis, delta));
14472
+ return next;
14473
+ }
14474
+ /**
14475
+ * The route without its redundant vertices: duplicates, zero-length runs and
14476
+ * the collinear middles drop — two parallel runs aligned into one line become
14477
+ * one piece (the merge the release stands).
14478
+ */
14479
+ function simplifyRoute(points) {
14480
+ const deduped = [];
14481
+ for (const point of points) {
14482
+ const last = deduped[deduped.length - 1];
14483
+ if (last !== void 0 && last.x === point.x && last.y === point.y) continue;
14484
+ deduped.push({
14485
+ x: point.x,
14486
+ y: point.y
14487
+ });
14488
+ }
14489
+ const simplified = [];
14490
+ for (const point of deduped) {
14491
+ const before = simplified[simplified.length - 2];
14492
+ const last = simplified[simplified.length - 1];
14493
+ if (before !== void 0 && last !== void 0 && (before.x === last.x && last.x === point.x || before.y === last.y && last.y === point.y)) simplified.pop();
14494
+ simplified.push(point);
14495
+ }
14496
+ return simplified;
14497
+ }
14498
+ /** The route's stored bends (the vertices between the stub ends). */
14499
+ function routeBendsOf(points, stubEnds) {
14500
+ const from = stubEnds.first ? 2 : 1;
14501
+ const to = stubEnds.last ? points.length - 2 : points.length - 1;
14502
+ return points.slice(from, Math.max(from, to)).map((point) => [point.x, point.y]);
14503
+ }
14504
+ /**
14505
+ * The route the reader adjusted, materialized at the gesture: the stored
14506
+ * bends stand between the endpoints' stub points, so the drawn route keeps
14507
+ * the ports' normal attachment and the custom bends hold the middle.
14508
+ */
14509
+ function customRouteOf(a, b, aOut, bIn, bends, stubEnds) {
14510
+ const points = [a];
14511
+ if (stubEnds.first) points.push(aOut);
14512
+ for (const [x, y] of bends) points.push({
14513
+ x,
14514
+ y
14515
+ });
14516
+ if (stubEnds.last) points.push(bIn);
14517
+ points.push(b);
14518
+ return simplifyRoute(points);
14519
+ }
14397
14520
  // src/canvas/geometry/utils/obstacles.ts
14398
14521
  /**
14399
14522
  * The connector route-avoidance's obstacle index: the uniform spatial grid
@@ -14593,7 +14716,8 @@ function connectorPath(start, end, variant) {
14593
14716
  x: b.x,
14594
14717
  y: b.y
14595
14718
  },
14596
- mid
14719
+ mid,
14720
+ points: []
14597
14721
  };
14598
14722
  if (variant === "orthogonal") {
14599
14723
  const dx = end.x - start.x;
@@ -14604,14 +14728,33 @@ function connectorPath(start, end, variant) {
14604
14728
  x: b.x,
14605
14729
  y: b.y
14606
14730
  },
14607
- mid
14731
+ mid,
14732
+ points: []
14608
14733
  };
14609
14734
  if (Math.abs(dx) >= Math.abs(dy)) {
14610
14735
  const sx = start.x + (dx > 0 ? start.w / 2 : -start.w / 2);
14611
14736
  const ex = end.x - (dx > 0 ? end.w / 2 : -end.w / 2);
14612
14737
  const bendX = (sx + ex) / 2;
14738
+ const points = [
14739
+ {
14740
+ x: sx,
14741
+ y: start.y
14742
+ },
14743
+ {
14744
+ x: bendX,
14745
+ y: start.y
14746
+ },
14747
+ {
14748
+ x: bendX,
14749
+ y: end.y
14750
+ },
14751
+ {
14752
+ x: ex,
14753
+ y: end.y
14754
+ }
14755
+ ];
14613
14756
  return {
14614
- d: `M ${sx} ${start.y} L ${bendX} ${start.y} L ${bendX} ${end.y} L ${ex} ${end.y}`,
14757
+ d: points.map((point, i) => `${i === 0 ? "M" : "L"} ${point.x} ${point.y}`).join(" "),
14615
14758
  end: {
14616
14759
  x: ex,
14617
14760
  y: end.y
@@ -14619,14 +14762,33 @@ function connectorPath(start, end, variant) {
14619
14762
  mid: {
14620
14763
  x: bendX,
14621
14764
  y: (start.y + end.y) / 2
14622
- }
14765
+ },
14766
+ points
14623
14767
  };
14624
14768
  }
14625
14769
  const sy = start.y + (dy > 0 ? start.h / 2 : -start.h / 2);
14626
14770
  const ey = end.y - (dy > 0 ? end.h / 2 : -end.h / 2);
14627
14771
  const bendY = (sy + ey) / 2;
14772
+ const points = [
14773
+ {
14774
+ x: start.x,
14775
+ y: sy
14776
+ },
14777
+ {
14778
+ x: start.x,
14779
+ y: bendY
14780
+ },
14781
+ {
14782
+ x: end.x,
14783
+ y: bendY
14784
+ },
14785
+ {
14786
+ x: end.x,
14787
+ y: ey
14788
+ }
14789
+ ];
14628
14790
  return {
14629
- d: `M ${start.x} ${sy} L ${start.x} ${bendY} L ${end.x} ${bendY} L ${end.x} ${ey}`,
14791
+ d: points.map((point, i) => `${i === 0 ? "M" : "L"} ${point.x} ${point.y}`).join(" "),
14630
14792
  end: {
14631
14793
  x: end.x,
14632
14794
  y: ey
@@ -14634,7 +14796,8 @@ function connectorPath(start, end, variant) {
14634
14796
  mid: {
14635
14797
  x: (start.x + end.x) / 2,
14636
14798
  y: bendY
14637
- }
14799
+ },
14800
+ points
14638
14801
  };
14639
14802
  }
14640
14803
  const reach = Math.hypot(b.x - a.x, b.y - a.y) / 3;
@@ -14652,7 +14815,8 @@ function connectorPath(start, end, variant) {
14652
14815
  x: b.x,
14653
14816
  y: b.y
14654
14817
  },
14655
- mid: cubicMid(a, c1, c2, b)
14818
+ mid: cubicMid(a, c1, c2, b),
14819
+ points: []
14656
14820
  };
14657
14821
  }
14658
14822
  /** Whether the route (the axis-aligned consecutive segments) crosses any
@@ -14736,223 +14900,226 @@ function cubicMid(a, c1, c2, b) {
14736
14900
  y: .125 * a.y + .375 * c1.y + .375 * c2.y + .125 * b.y
14737
14901
  };
14738
14902
  }
14903
+ // src/canvas/geometry/utils/ortho-route.ts
14904
+ /**
14905
+ * The orthogonal connector's route: the port stubs (the anchored endpoint
14906
+ * leaves / enters along its outward normal), the reader's stored bends (the
14907
+ * custom route — the automatic avoidance off), the automatic avoidance's
14908
+ * candidate selection (the shortest clear route over the single-bend pool +
14909
+ * the two-bend-line U's; the obstacle-free scene stands the default elbow
14910
+ * byte-for-byte), and the live segment drag's parallel move. The returned
14911
+ * vertices are the drawn polyline (the route's own order).
14912
+ */
14913
+ /** The ortho route's vertices (the stub points + the bends). */
14914
+ function orthoRouteOf(a, b, options) {
14915
+ const { obstacles, custom, segment, noStub = false } = options;
14916
+ const dx = b.x - a.x;
14917
+ const dy = b.y - a.y;
14918
+ if (dx === 0 && dy === 0) return [a, b];
14919
+ const aAnchored = !noStub && (a.nx !== 0 || a.ny !== 0);
14920
+ const bAnchored = !noStub && (b.nx !== 0 || b.ny !== 0);
14921
+ const aOut = aAnchored ? {
14922
+ x: a.x + a.nx * 18,
14923
+ y: a.y + a.ny * 18
14924
+ } : a;
14925
+ const bIn = bAnchored ? {
14926
+ x: b.x + b.nx * 18,
14927
+ y: b.y + b.ny * 18
14928
+ } : b;
14929
+ const stubEnds = {
14930
+ first: aAnchored,
14931
+ last: bAnchored
14932
+ };
14933
+ const customRoute = (bends) => customRouteOf(a, b, aOut, bIn, bends, stubEnds);
14934
+ if (custom !== void 0 && custom.length > 0) {
14935
+ const route = customRoute(custom);
14936
+ return simplifyRoute(segment !== void 0 && segment !== null ? moveSegmentRoute(route, segment.index, segment.delta, stubEnds) : route);
14937
+ }
14938
+ const horizontal = Math.abs(dx) >= Math.abs(dy);
14939
+ const structures = [horizontal ? (t) => [{
14940
+ x: t,
14941
+ y: aOut.y
14942
+ }, {
14943
+ x: t,
14944
+ y: bIn.y
14945
+ }] : (t) => [{
14946
+ x: aOut.x,
14947
+ y: t
14948
+ }, {
14949
+ x: bIn.x,
14950
+ y: t
14951
+ }], horizontal ? (t) => [{
14952
+ x: aOut.x,
14953
+ y: t
14954
+ }, {
14955
+ x: bIn.x,
14956
+ y: t
14957
+ }] : (t) => [{
14958
+ x: t,
14959
+ y: aOut.y
14960
+ }, {
14961
+ x: t,
14962
+ y: bIn.y
14963
+ }]];
14964
+ const avoid = obstacles !== void 0 && obstacles.length > 0;
14965
+ const obs = obstacles ?? [];
14966
+ const grid = avoid && obs.length >= 48 ? buildObstacleGrid(obs) : null;
14967
+ const hits = (points) => grid !== null ? routeHitsGrid(points, grid) : routeHitsObstacles(points, obs);
14968
+ const xEdges = [];
14969
+ const yEdges = [];
14970
+ if (avoid) for (const r of obs) {
14971
+ xEdges.push(r.x - r.w / 2 - 12, r.x + r.w / 2 + 12);
14972
+ yEdges.push(r.y - r.h / 2 - 12, r.y + r.h / 2 + 12);
14973
+ }
14974
+ const tsOf = (c1, c2, structureHorizontal) => {
14975
+ const ts_ = [
14976
+ (c1 + c2) / 2,
14977
+ c2,
14978
+ c1,
14979
+ Math.min(c1, c2) - 24,
14980
+ Math.max(c1, c2) + 24
14981
+ ];
14982
+ if (avoid) ts_.push(...topKSpanEdges(structureHorizontal ? xEdges : yEdges, c1, c2, 8));
14983
+ return ts_;
14984
+ };
14985
+ const tsList = [horizontal ? tsOf(aOut.x, bIn.x, true) : tsOf(aOut.y, bIn.y, false), horizontal ? tsOf(aOut.y, bIn.y, false) : tsOf(aOut.x, bIn.x, true)];
14986
+ const routeOf = (bend) => {
14987
+ const points = [a];
14988
+ if (aAnchored) points.push(aOut);
14989
+ points.push(...bend);
14990
+ if (bAnchored) points.push(bIn);
14991
+ points.push(b);
14992
+ return points;
14993
+ };
14994
+ const pool = [];
14995
+ for (let i = 0; i < structures.length; i++) {
14996
+ const structure = structures[i];
14997
+ const ts = tsList[i];
14998
+ if (structure === void 0 || ts === void 0) continue;
14999
+ for (const t of ts) {
15000
+ const candidate = routeOf(structure(t));
15001
+ if (avoid && hits(candidate)) continue;
15002
+ pool.push({
15003
+ points: candidate,
15004
+ length: avoid ? routeLength(candidate) : 0,
15005
+ bends: routeBends(candidate)
15006
+ });
15007
+ }
15008
+ }
15009
+ if (avoid) {
15010
+ const xs = [
15011
+ Math.min(aOut.x, bIn.x) - 24,
15012
+ Math.max(aOut.x, bIn.x) + 24,
15013
+ ...topKSpanEdges(xEdges, aOut.x, bIn.x, 6)
15014
+ ];
15015
+ const ys = [
15016
+ Math.min(aOut.y, bIn.y) - 24,
15017
+ Math.max(aOut.y, bIn.y) + 24,
15018
+ ...topKSpanEdges(yEdges, aOut.y, bIn.y, 6)
15019
+ ];
15020
+ for (const y1 of ys) for (const x1 of xs) {
15021
+ const f1 = routeOf([
15022
+ {
15023
+ x: x1,
15024
+ y: aOut.y
15025
+ },
15026
+ {
15027
+ x: x1,
15028
+ y: y1
15029
+ },
15030
+ {
15031
+ x: bIn.x,
15032
+ y: y1
15033
+ }
15034
+ ]);
15035
+ if (!hits(f1)) pool.push({
15036
+ points: f1,
15037
+ length: routeLength(f1),
15038
+ bends: routeBends(f1)
15039
+ });
15040
+ const f2 = routeOf([
15041
+ {
15042
+ x: aOut.x,
15043
+ y: y1
15044
+ },
15045
+ {
15046
+ x: x1,
15047
+ y: y1
15048
+ },
15049
+ {
15050
+ x: x1,
15051
+ y: bIn.y
15052
+ }
15053
+ ]);
15054
+ if (!hits(f2)) pool.push({
15055
+ points: f2,
15056
+ length: routeLength(f2),
15057
+ bends: routeBends(f2)
15058
+ });
15059
+ }
15060
+ }
15061
+ let points = null;
15062
+ if (pool.length > 0) {
15063
+ let best = 0;
15064
+ for (let i = 1; i < pool.length; i++) {
15065
+ const candidate = pool[i];
15066
+ const current = pool[best];
15067
+ const fewerBends = avoid && candidate.length === current.length && candidate.bends < current.bends;
15068
+ if (candidate.length < current.length || fewerBends) best = i;
15069
+ }
15070
+ points = pool[best].points;
15071
+ }
15072
+ const midCoord = horizontal ? (aOut.x + bIn.x) / 2 : (aOut.y + bIn.y) / 2;
15073
+ const final = points ?? routeOf(structures[0](midCoord));
15074
+ const deduped = final.filter((p, i) => i === 0 || p.x !== final[i - 1].x || p.y !== final[i - 1].y);
15075
+ return segment !== void 0 && segment !== null ? simplifyRoute(moveSegmentRoute(deduped, segment.index, segment.delta, stubEnds)) : deduped;
15076
+ }
14739
15077
  // src/canvas/geometry/utils/connector.ts
14740
15078
  /**
14741
- * The connector's resolved-endpoint path (the free-port generalization of
14742
- * the box-to-box's connectorPath): the variant's shape over the resolved
14743
- * points (the orthogonal's right-angle stubs) + the orthogonal's obstacle
14744
- * AVOIDANCE's candidate selection (the shortest clear route over the
14745
- * single-bend's candidates + the two-bend-line U's; the pool stands
14746
- * bounded over the sibling count — the candidate's obstacle coords are
14747
- * the NEAREST cap of the edges within the route's span (topKSpanEdges)).
14748
- */
14749
- /**
14750
- * The connector's path between the RESOLVED endpoint points (the variant's
14751
- * shape): the free-port generalization of connectorPath — straight is the
14752
- * segment, orthogonal the right-angled elbow (the port endpoints stand a
14753
- * STUB along their normal — the line leaves / enters the edge at a right
14754
- * angle, the 12-px minimum offset from the block), curved the cubic bow (a zero normal — the free point —
14755
- * bows out along the segment's own direction, so the line leaves the
14756
- * point the way it arrived). The orthogonal's AVOIDANCE: when
14757
- * `obstacles` stand (the surface's sibling
14758
- * boxes), the bend line runs the first CLEAR candidate (the default
14759
- * elbow, then the alternatives, then the outer detours) — the line never
14760
- * crosses a figure when a clear route stands; when the single-bend
14761
- * candidates stand no route (the endpoint boxes nearly touch — the
14762
- * corridor is sealed), the two-bend-line (U) candidates stand — the
14763
- * shortest clear U; the fallback is the default elbow (the crossing
14764
- * stands when no candidate is clear — the best effort). The candidate's
14765
- * SELECTION is the shortest CLEAR route over the whole pool (the
14766
- * single-bend's candidates + the U's); the equal length prefers the
14767
- * FEWER bends (the straighter route), and the list order breaks only the
14768
- * full tie, so an unrelated obstacle's far edge cannot beat a near
14769
- * detour (an obstacle-free scene stands the default elbow byte-for-byte
14770
- * — it is the shortest and straightest). The pool is BOUNDED over the
14771
- * sibling count: the candidate's obstacle coords stand the NEAREST edges
14772
- * over the route's span (the per-axis cap — a far edge's detour is longer
14773
- * than the near one's, so the cap drops only the candidates the
14774
- * selection cannot pick), and the hit test runs the spatial grid over
14775
- * the dense sets (the segment's local stand, not the whole set).
14776
- */
14777
- function connectorPathPoints(a, b, variant, obstacles) {
15079
+ * The connector's path over the RESOLVED endpoint points — the free-port
15080
+ * generalization of the box-to-box `connectorPath`: the straight segment (the
15081
+ * stored bends stand the polyline through them), the orthogonal route
15082
+ * (`./ortho-route`: the port stubs, the reader's bends, the automatic
15083
+ * avoidance), and the cubic bow (the control points ride the endpoints'
15084
+ * outward normals — a free point's zero normal bows perpendicular to the
15085
+ * segment).
15086
+ */
15087
+ function connectorPathPoints(a, b, variant, options = {}) {
15088
+ const { custom } = options;
14778
15089
  const mid = {
14779
15090
  x: (a.x + b.x) / 2,
14780
15091
  y: (a.y + b.y) / 2
14781
15092
  };
14782
- if (variant === "straight") return {
14783
- d: `M ${a.x} ${a.y} L ${b.x} ${b.y}`,
14784
- end: {
14785
- x: b.x,
14786
- y: b.y
14787
- },
14788
- mid
14789
- };
14790
- if (variant === "orthogonal") {
14791
- const dx = b.x - a.x;
14792
- const dy = b.y - a.y;
14793
- if (dx === 0 && dy === 0) return {
14794
- d: `M ${a.x} ${a.y} L ${b.x} ${b.y}`,
15093
+ if (variant === "straight") {
15094
+ const polyline = custom !== void 0 && custom.length > 0 ? [
15095
+ a,
15096
+ ...custom.map(([x, y]) => ({
15097
+ x,
15098
+ y
15099
+ })),
15100
+ b
15101
+ ] : [a, b];
15102
+ return {
15103
+ d: polyline.map((point, i) => `${i === 0 ? "M" : "L"} ${point.x} ${point.y}`).join(" "),
14795
15104
  end: {
14796
15105
  x: b.x,
14797
15106
  y: b.y
14798
15107
  },
14799
- mid
15108
+ mid: longestSegmentMid(polyline),
15109
+ points: []
14800
15110
  };
14801
- const aAnchored = a.nx !== 0 || a.ny !== 0;
14802
- const bAnchored = b.nx !== 0 || b.ny !== 0;
14803
- const aOut = aAnchored ? {
14804
- x: a.x + a.nx * 18,
14805
- y: a.y + a.ny * 18
14806
- } : a;
14807
- const bIn = bAnchored ? {
14808
- x: b.x + b.nx * 18,
14809
- y: b.y + b.ny * 18
14810
- } : b;
14811
- const horizontal = Math.abs(dx) >= Math.abs(dy);
14812
- const structures = [horizontal ? (t) => [{
14813
- x: t,
14814
- y: aOut.y
14815
- }, {
14816
- x: t,
14817
- y: bIn.y
14818
- }] : (t) => [{
14819
- x: aOut.x,
14820
- y: t
14821
- }, {
14822
- x: bIn.x,
14823
- y: t
14824
- }], horizontal ? (t) => [{
14825
- x: aOut.x,
14826
- y: t
14827
- }, {
14828
- x: bIn.x,
14829
- y: t
14830
- }] : (t) => [{
14831
- x: t,
14832
- y: aOut.y
14833
- }, {
14834
- x: t,
14835
- y: bIn.y
14836
- }]];
14837
- const avoid = obstacles !== void 0 && obstacles.length > 0;
14838
- const obs = obstacles ?? [];
14839
- const grid = avoid && obs.length >= 48 ? buildObstacleGrid(obs) : null;
14840
- const hits = (points) => grid !== null ? routeHitsGrid(points, grid) : routeHitsObstacles(points, obs);
14841
- const xEdges = [];
14842
- const yEdges = [];
14843
- if (avoid) for (const r of obs) {
14844
- xEdges.push(r.x - r.w / 2 - 12, r.x + r.w / 2 + 12);
14845
- yEdges.push(r.y - r.h / 2 - 12, r.y + r.h / 2 + 12);
14846
- }
14847
- const tsOf = (c1, c2, structureHorizontal) => {
14848
- const ts_ = [
14849
- (c1 + c2) / 2,
14850
- c2,
14851
- c1,
14852
- Math.min(c1, c2) - 24,
14853
- Math.max(c1, c2) + 24
14854
- ];
14855
- if (avoid) ts_.push(...topKSpanEdges(structureHorizontal ? xEdges : yEdges, c1, c2, 8));
14856
- return ts_;
14857
- };
14858
- const tsList = [horizontal ? tsOf(aOut.x, bIn.x, true) : tsOf(aOut.y, bIn.y, false), horizontal ? tsOf(aOut.y, bIn.y, false) : tsOf(aOut.x, bIn.x, true)];
14859
- const routeOf = (bend) => {
14860
- const points = [a];
14861
- if (aAnchored) points.push(aOut);
14862
- points.push(...bend);
14863
- if (bAnchored) points.push(bIn);
14864
- points.push(b);
14865
- return points;
14866
- };
14867
- const pool = [];
14868
- for (let i = 0; i < structures.length; i++) {
14869
- const structure = structures[i];
14870
- const ts = tsList[i];
14871
- if (structure === void 0 || ts === void 0) continue;
14872
- for (const t of ts) {
14873
- const candidate = routeOf(structure(t));
14874
- if (avoid && hits(candidate)) continue;
14875
- pool.push({
14876
- points: candidate,
14877
- length: avoid ? routeLength(candidate) : 0,
14878
- bends: routeBends(candidate)
14879
- });
14880
- }
14881
- }
14882
- if (avoid) {
14883
- const xs = [
14884
- Math.min(aOut.x, bIn.x) - 24,
14885
- Math.max(aOut.x, bIn.x) + 24,
14886
- ...topKSpanEdges(xEdges, aOut.x, bIn.x, 6)
14887
- ];
14888
- const ys = [
14889
- Math.min(aOut.y, bIn.y) - 24,
14890
- Math.max(aOut.y, bIn.y) + 24,
14891
- ...topKSpanEdges(yEdges, aOut.y, bIn.y, 6)
14892
- ];
14893
- for (const y1 of ys) for (const x1 of xs) {
14894
- const f1 = routeOf([
14895
- {
14896
- x: x1,
14897
- y: aOut.y
14898
- },
14899
- {
14900
- x: x1,
14901
- y: y1
14902
- },
14903
- {
14904
- x: bIn.x,
14905
- y: y1
14906
- }
14907
- ]);
14908
- if (!hits(f1)) pool.push({
14909
- points: f1,
14910
- length: routeLength(f1),
14911
- bends: routeBends(f1)
14912
- });
14913
- const f2 = routeOf([
14914
- {
14915
- x: aOut.x,
14916
- y: y1
14917
- },
14918
- {
14919
- x: x1,
14920
- y: y1
14921
- },
14922
- {
14923
- x: x1,
14924
- y: bIn.y
14925
- }
14926
- ]);
14927
- if (!hits(f2)) pool.push({
14928
- points: f2,
14929
- length: routeLength(f2),
14930
- bends: routeBends(f2)
14931
- });
14932
- }
14933
- }
14934
- let points = null;
14935
- if (pool.length > 0) {
14936
- let best = 0;
14937
- for (let i = 1; i < pool.length; i++) {
14938
- const candidate = pool[i];
14939
- const current = pool[best];
14940
- const fewerBends = avoid && candidate.length === current.length && candidate.bends < current.bends;
14941
- if (candidate.length < current.length || fewerBends) best = i;
14942
- }
14943
- points = pool[best].points;
14944
- }
14945
- const midCoord = horizontal ? (aOut.x + bIn.x) / 2 : (aOut.y + bIn.y) / 2;
14946
- const final = points ?? routeOf(structures[0](midCoord));
14947
- const deduped = final.filter((p, i) => i === 0 || p.x !== final[i - 1].x || p.y !== final[i - 1].y);
14948
- return {
14949
- d: deduped.map((p, i) => `${i === 0 ? "M" : "L"} ${p.x} ${p.y}`).join(" "),
15111
+ }
15112
+ if (variant === "orthogonal") {
15113
+ if (b.x - a.x === 0 && b.y - a.y === 0) return {
15114
+ d: `M ${a.x} ${a.y} L ${b.x} ${b.y}`,
14950
15115
  end: {
14951
15116
  x: b.x,
14952
15117
  y: b.y
14953
15118
  },
14954
- mid: longestSegmentMid(deduped)
15119
+ mid,
15120
+ points: []
14955
15121
  };
15122
+ return routePathOf(orthoRouteOf(a, b, options), b);
14956
15123
  }
14957
15124
  const dist = Math.hypot(b.x - a.x, b.y - a.y);
14958
15125
  const reach = dist / 3;
@@ -14985,7 +15152,23 @@ function connectorPathPoints(a, b, variant, obstacles) {
14985
15152
  x: b.x,
14986
15153
  y: b.y
14987
15154
  },
14988
- mid: cubicMid(a, c1, c2, b)
15155
+ mid: cubicMid(a, c1, c2, b),
15156
+ points: []
15157
+ };
15158
+ }
15159
+ /** The route's path stand over its vertices (the `d` + the label's seat). */
15160
+ function routePathOf(points, end) {
15161
+ return {
15162
+ d: points.map((point, i) => `${i === 0 ? "M" : "L"} ${point.x} ${point.y}`).join(" "),
15163
+ end: {
15164
+ x: end.x,
15165
+ y: end.y
15166
+ },
15167
+ mid: longestSegmentMid(points),
15168
+ points: points.map((point) => ({
15169
+ x: point.x,
15170
+ y: point.y
15171
+ }))
14989
15172
  };
14990
15173
  }
14991
15174
  // src/canvas/geometry/utils/geometry.ts
@@ -15454,7 +15637,7 @@ function connectorMidpoint(connectorId, childIds, blocks, previews) {
15454
15637
  if (item === void 0 || item.type === "connector" || item.type === "group") continue;
15455
15638
  obstacleBoxes.push(effectiveGeometry(item));
15456
15639
  }
15457
- return connectorPathPoints(startDraw, endDraw, attrs.variant ?? "straight", obstacleBoxes).mid;
15640
+ return connectorPathPoints(startDraw, endDraw, attrs.variant ?? "straight", { obstacles: obstacleBoxes }).mid;
15458
15641
  }
15459
15642
  /**
15460
15643
  * The connector's STORED waypoints (the bend dots' stand): the attrs'
@@ -16400,6 +16583,276 @@ function createPlaceCommands(store, doc) {
16400
16583
  onPen
16401
16584
  };
16402
16585
  }
16586
+ // src/canvas/connector-line-geometry.ts
16587
+ function connectorLineGeometryOf(connectorId, block, childIds, blocks, session) {
16588
+ const attrs = block.attrs;
16589
+ if (attrs === void 0) return null;
16590
+ const { movePreview, resizePreview, endpointDrag, endpointPreview, segmentDrag } = session;
16591
+ const segment = segmentDrag !== null && segmentDrag.connectorId === connectorId ? {
16592
+ index: segmentDrag.index,
16593
+ delta: segmentDrag.delta
16594
+ } : null;
16595
+ const previewBlocks = (() => {
16596
+ if (movePreview === null && resizePreview === null) return blocks;
16597
+ const next = { ...blocks };
16598
+ for (const childId of childIds) {
16599
+ const item = next[childId];
16600
+ if (item === void 0 || item.type === "connector") continue;
16601
+ if (resizePreview !== null && resizePreview.id === childId) next[childId] = {
16602
+ ...item,
16603
+ geometry: {
16604
+ ...item.geometry,
16605
+ ...resizePreview.box
16606
+ }
16607
+ };
16608
+ else if (movePreview !== null && movePreview.idSet.has(childId)) {
16609
+ const g = effectiveGeometry(item);
16610
+ next[childId] = {
16611
+ ...item,
16612
+ geometry: {
16613
+ x: g.x + movePreview.dx,
16614
+ y: g.y + movePreview.dy,
16615
+ w: g.w,
16616
+ h: g.h
16617
+ }
16618
+ };
16619
+ }
16620
+ }
16621
+ return next;
16622
+ })();
16623
+ const obstacleBoxes = [];
16624
+ for (const childId of childIds) {
16625
+ const item = previewBlocks[childId];
16626
+ if (item === void 0 || item.type === "connector" || item.type === "group") continue;
16627
+ obstacleBoxes.push(effectiveGeometry(item));
16628
+ }
16629
+ const startBox = endpointBoxOf(attrs.start, childIds, previewBlocks);
16630
+ const endBox = endpointBoxOf(attrs.end, childIds, previewBlocks);
16631
+ const startFree = attrs.start.x !== void 0 && attrs.start.y !== void 0 ? {
16632
+ x: attrs.start.x,
16633
+ y: attrs.start.y
16634
+ } : null;
16635
+ const endFree = attrs.end.x !== void 0 && attrs.end.y !== void 0 ? {
16636
+ x: attrs.end.x,
16637
+ y: attrs.end.y
16638
+ } : null;
16639
+ const startToward = endBox !== null ? {
16640
+ x: endBox.x,
16641
+ y: endBox.y
16642
+ } : endFree ?? {
16643
+ x: 0,
16644
+ y: 0
16645
+ };
16646
+ const endToward = startBox !== null ? {
16647
+ x: startBox.x,
16648
+ y: startBox.y
16649
+ } : startFree ?? {
16650
+ x: 0,
16651
+ y: 0
16652
+ };
16653
+ const startPoint = endpointPointOf(attrs.start, childIds, previewBlocks, startToward);
16654
+ const endPoint = endpointPointOf(attrs.end, childIds, previewBlocks, endToward);
16655
+ if (startPoint === null || endPoint === null) return null;
16656
+ const dragging = endpointDrag !== null && endpointDrag.connectorId === connectorId;
16657
+ const snapPoint = (which) => {
16658
+ if (!dragging || endpointDrag === null || endpointDrag.which !== which || endpointPreview === null) return null;
16659
+ const snap = endpointPreview.snap;
16660
+ const point = {
16661
+ x: endpointPreview.point.x,
16662
+ y: endpointPreview.point.y
16663
+ };
16664
+ if (snap === null) {
16665
+ const stored = which === "start" ? startPoint : endPoint;
16666
+ return {
16667
+ ...point,
16668
+ nx: stored.nx,
16669
+ ny: stored.ny
16670
+ };
16671
+ }
16672
+ const sibling = previewBlocks[snap.blockId];
16673
+ if (sibling === void 0) return {
16674
+ ...point,
16675
+ nx: 0,
16676
+ ny: 0
16677
+ };
16678
+ const p = edgePointOf(effectiveGeometry(sibling), snap.port, snap.t);
16679
+ const normal = PORT_NORMAL[snap.port];
16680
+ return {
16681
+ x: p.x,
16682
+ y: p.y,
16683
+ nx: normal.nx,
16684
+ ny: normal.ny
16685
+ };
16686
+ };
16687
+ const startDraw = dragging && endpointDrag !== null && endpointDrag.which === "start" ? snapPoint("start") ?? startPoint : startPoint;
16688
+ const endDraw = dragging && endpointDrag !== null && endpointDrag.which === "end" ? snapPoint("end") ?? endPoint : endPoint;
16689
+ const legacy = startBox !== null && endBox !== null && startFree === null && endFree === null && attrs.start.port === void 0 && attrs.end.port === void 0 && !dragging;
16690
+ const polyPoint = (ref, resolved, box, key) => {
16691
+ const dragged = dragging && endpointDrag !== null && endpointDrag.which === key;
16692
+ return ref.x !== void 0 && ref.y !== void 0 ? {
16693
+ x: ref.x,
16694
+ y: ref.y
16695
+ } : ref.port !== void 0 || box === null || dragged ? {
16696
+ x: resolved.x,
16697
+ y: resolved.y
16698
+ } : {
16699
+ x: box.x,
16700
+ y: box.y
16701
+ };
16702
+ };
16703
+ const startPoly = polyPoint(attrs.start, startDraw, startBox, "start");
16704
+ const endPoly = polyPoint(attrs.end, endDraw, endBox, "end");
16705
+ const points = (attrs.points ?? []).map(([x, y], index) => {
16706
+ if (!dragging || endpointDrag === null || endpointDrag.which !== "waypoint") return [x, y];
16707
+ if (endpointDrag.index !== index || endpointPreview === null) return [x, y];
16708
+ return [endpointPreview.point.x, endpointPreview.point.y];
16709
+ });
16710
+ const variant = attrs.variant ?? "straight";
16711
+ const custom = variant === "curved" ? [] : points;
16712
+ const resolved = (() => {
16713
+ if (custom.length > 0) return variant === "straight" ? connectorPathPoints({
16714
+ ...startPoly,
16715
+ nx: 0,
16716
+ ny: 0
16717
+ }, {
16718
+ ...endPoly,
16719
+ nx: 0,
16720
+ ny: 0
16721
+ }, "straight", { custom }) : connectorPathPoints(startDraw, endDraw, variant, {
16722
+ custom,
16723
+ segment,
16724
+ noStub: legacy
16725
+ });
16726
+ if (legacy) {
16727
+ const base = connectorPath(startBox, endBox, variant);
16728
+ return segment === null ? base : routePathOf(moveSegmentRoute(base.points, segment.index, segment.delta, {
16729
+ first: false,
16730
+ last: false
16731
+ }), base.end);
16732
+ }
16733
+ return connectorPathPoints(startDraw, endDraw, variant, {
16734
+ obstacles: obstacleBoxes,
16735
+ segment
16736
+ });
16737
+ })();
16738
+ return {
16739
+ path: resolved.d,
16740
+ startDraw,
16741
+ endDraw,
16742
+ dragging,
16743
+ points: resolved.points
16744
+ };
16745
+ }
16746
+ // src/canvas/viewport/session-segment.ts
16747
+ /** The connector's surface siblings + their snapshots (the route's inputs). */
16748
+ function surfaceOf(doc, connectorId) {
16749
+ const surfaceId = findParentSurface(doc, connectorId);
16750
+ if (surfaceId === null) return null;
16751
+ const children = doc.getChildren(surfaceId);
16752
+ const blocks = {};
16753
+ for (const childId of children) {
16754
+ const child = doc.getBlock(childId);
16755
+ if (child !== null) blocks[childId] = child;
16756
+ }
16757
+ return {
16758
+ children,
16759
+ blocks
16760
+ };
16761
+ }
16762
+ /** The connector's segment-drag commands. */
16763
+ function createSegmentSessions(store, doc) {
16764
+ const ref = { current: null };
16765
+ /** The line's route vertices over the live stand (the stored bends or the
16766
+ * auto route, the dragged run moved). */
16767
+ const routeOf = (session) => {
16768
+ const block = doc.getBlock(session.connectorId);
16769
+ if (block === null || block.type !== "connector") return null;
16770
+ const surface = surfaceOf(doc, session.connectorId);
16771
+ if (surface === null) return null;
16772
+ const live = {
16773
+ movePreview: null,
16774
+ resizePreview: null,
16775
+ endpointDrag: null,
16776
+ endpointPreview: null,
16777
+ segmentDrag: {
16778
+ connectorId: session.connectorId,
16779
+ index: session.index,
16780
+ delta: session.delta
16781
+ }
16782
+ };
16783
+ return connectorLineGeometryOf(session.connectorId, block, surface.children, surface.blocks, live)?.points ?? null;
16784
+ };
16785
+ /** The gesture's stepping: the pointer's movement along the run's movable
16786
+ * axis (canvas px) over the step grid. */
16787
+ const deltaOf = (session, pointer, zoom) => {
16788
+ const from = session.axis === "x" ? session.pointer.x : session.pointer.y;
16789
+ const to = session.axis === "x" ? pointer.x : pointer.y;
16790
+ return Math.round((to - from) / zoom / 10) * 10;
16791
+ };
16792
+ /** An anchored endpoint (the route's own stub vertex): a free point
16793
+ * without a port stands none. */
16794
+ const anchored = (ref) => ref.x === void 0 || ref.port !== void 0;
16795
+ const beginConnectorSegment = (connectorId, index, axis, pointer) => {
16796
+ ref.current = {
16797
+ connectorId,
16798
+ index,
16799
+ axis,
16800
+ pointer,
16801
+ delta: 0
16802
+ };
16803
+ store.getState().setConnectorSegment({
16804
+ connectorId,
16805
+ index,
16806
+ delta: 0
16807
+ });
16808
+ };
16809
+ const moveConnectorSegment = (pointer) => {
16810
+ const session = ref.current;
16811
+ if (session === null) return;
16812
+ const state = store.getState();
16813
+ const delta = deltaOf(session, pointer, state.zoom);
16814
+ if (delta === session.delta) return;
16815
+ session.delta = delta;
16816
+ state.setConnectorSegment({
16817
+ connectorId: session.connectorId,
16818
+ index: session.index,
16819
+ delta
16820
+ });
16821
+ };
16822
+ const cancelConnectorSegment = () => {
16823
+ ref.current = null;
16824
+ store.getState().setConnectorSegment(null);
16825
+ };
16826
+ const endConnectorSegment = () => {
16827
+ const session = ref.current;
16828
+ ref.current = null;
16829
+ store.getState().setConnectorSegment(null);
16830
+ if (session === null || session.delta === 0) return;
16831
+ const block = doc.getBlock(session.connectorId);
16832
+ if (block === null || block.type !== "connector") return;
16833
+ const route = routeOf(session);
16834
+ if (route === null) return;
16835
+ const bends = simplifyRoute(routeBendsOf(route, {
16836
+ first: anchored(block.attrs?.start ?? {}),
16837
+ last: anchored(block.attrs?.end ?? {})
16838
+ }).map(([x, y]) => ({
16839
+ x,
16840
+ y
16841
+ }))).map((point) => [Number(point.x.toFixed(2)), Number(point.y.toFixed(2))]);
16842
+ try {
16843
+ doc.transact(() => {
16844
+ if (bends.length === 0) doc.removeBlockAttr(session.connectorId, "points");
16845
+ else doc.updateBlock(session.connectorId, { points: bends });
16846
+ });
16847
+ } catch {}
16848
+ };
16849
+ return {
16850
+ beginConnectorSegment,
16851
+ moveConnectorSegment,
16852
+ endConnectorSegment,
16853
+ cancelConnectorSegment
16854
+ };
16855
+ }
16403
16856
  // src/canvas/viewport/session-shape-drop.ts
16404
16857
  /** The containers (the groups) of every surface, with their live box and
16405
16858
  * the stored members (the shared canvas space) — the drop's stand and the
@@ -16920,6 +17373,7 @@ function createCanvasViewportCommands(store, doc) {
16920
17373
  ...createShapeSessions(store, doc),
16921
17374
  ...createConnectorSessions(store, doc, standPoint),
16922
17375
  ...createWaypointSessions(store, doc),
17376
+ ...createSegmentSessions(store, doc),
16923
17377
  ...createPlaceCommands(store, doc),
16924
17378
  stepZoom: step,
16925
17379
  zoomAt,
@@ -17048,6 +17502,7 @@ function createViewportStore(initial) {
17048
17502
  connectorHoverSnap: null,
17049
17503
  connectorEndpoint: null,
17050
17504
  connectorEndpointPreview: null,
17505
+ connectorSegment: null,
17051
17506
  shapeTextEditing: null,
17052
17507
  canvasTextEditing: null,
17053
17508
  connectorLabelEditing: null,
@@ -17085,6 +17540,7 @@ function createViewportStore(initial) {
17085
17540
  setConnectorHoverSnap: (connectorHoverSnap) => set({ connectorHoverSnap }),
17086
17541
  setConnectorEndpoint: (connectorEndpoint) => set({ connectorEndpoint }),
17087
17542
  setConnectorEndpointPreview: (connectorEndpointPreview) => set({ connectorEndpointPreview }),
17543
+ setConnectorSegment: (connectorSegment) => set({ connectorSegment }),
17088
17544
  setShapeTextEditing: (shapeTextEditing) => set({ shapeTextEditing }),
17089
17545
  setCanvasTextEditing: (canvasTextEditing) => set({ canvasTextEditing }),
17090
17546
  setConnectorLabelEditing: (connectorLabelEditing) => set({ connectorLabelEditing }),
@@ -17200,7 +17656,8 @@ const EMPTY_LINE_SESSION = {
17200
17656
  movePreview: null,
17201
17657
  resizePreview: null,
17202
17658
  endpointDrag: null,
17203
- endpointPreview: null
17659
+ endpointPreview: null,
17660
+ segmentDrag: null
17204
17661
  };
17205
17662
  /** The preview's no-op stand (the stable object: the label chips'
17206
17663
  * midpoint's cache bails over the untouched lines). */
@@ -17264,22 +17721,26 @@ function useLineSession(id, startBlockId, endBlockId) {
17264
17721
  const rp = s.resizePreview;
17265
17722
  const ed = s.connectorEndpoint;
17266
17723
  const ep = s.connectorEndpointPreview;
17724
+ const sd = s.connectorSegment;
17267
17725
  const cache = cacheRef.current;
17268
- if (cache !== null && cache.mv === mv && cache.rp === rp && cache.ed === ed && cache.ep === ep) return cache.value;
17726
+ if (cache !== null && cache.mv === mv && cache.rp === rp && cache.ed === ed && cache.ep === ep && cache.sd === sd) return cache.value;
17269
17727
  const mvTouches = mv !== null && (startBlockId !== null && mv.idSet.has(startBlockId) || endBlockId !== null && mv.idSet.has(endBlockId));
17270
17728
  const rpTouches = rp !== null && (rp.id === startBlockId || rp.id === endBlockId);
17271
17729
  const edTouches = ed !== null && ed.connectorId === id;
17272
- const value = !mvTouches && !rpTouches && !edTouches ? EMPTY_LINE_SESSION : {
17730
+ const sdTouches = sd !== null && sd.connectorId === id;
17731
+ const value = !mvTouches && !rpTouches && !edTouches && !sdTouches ? EMPTY_LINE_SESSION : {
17273
17732
  movePreview: mvTouches ? mv : null,
17274
17733
  resizePreview: rpTouches ? rp : null,
17275
17734
  endpointDrag: edTouches ? ed : null,
17276
- endpointPreview: edTouches ? ep : null
17735
+ endpointPreview: edTouches ? ep : null,
17736
+ segmentDrag: sdTouches ? sd : null
17277
17737
  };
17278
17738
  cacheRef.current = {
17279
17739
  mv,
17280
17740
  rp,
17281
17741
  ed,
17282
17742
  ep,
17743
+ sd,
17283
17744
  value
17284
17745
  };
17285
17746
  return value;
@@ -17297,19 +17758,22 @@ function useChipsPreviews() {
17297
17758
  const rp = s.resizePreview;
17298
17759
  const ed = s.connectorEndpoint;
17299
17760
  const ep = s.connectorEndpointPreview;
17761
+ const sd = s.connectorSegment;
17300
17762
  const cache = cacheRef.current;
17301
- if (cache !== null && cache.mv === mv && cache.rp === rp && cache.ed === ed && cache.ep === ep) return cache.value;
17302
- const value = mv === null && rp === null && ed === null ? EMPTY_PREVIEWS : {
17763
+ if (cache !== null && cache.mv === mv && cache.rp === rp && cache.ed === ed && cache.ep === ep && cache.sd === sd) return cache.value;
17764
+ const value = mv === null && rp === null && ed === null && sd === null ? EMPTY_PREVIEWS : {
17303
17765
  movePreview: mv,
17304
17766
  resizePreview: rp,
17305
17767
  endpointDrag: ed,
17306
- endpointPreview: ep
17768
+ endpointPreview: ep,
17769
+ segmentDrag: sd
17307
17770
  };
17308
17771
  cacheRef.current = {
17309
17772
  mv,
17310
17773
  rp,
17311
17774
  ed,
17312
17775
  ep,
17776
+ sd,
17313
17777
  value
17314
17778
  };
17315
17779
  return value;
@@ -27339,133 +27803,6 @@ const PLACE_TOOLS = [
27339
27803
  "container",
27340
27804
  "frame"
27341
27805
  ];
27342
- // src/canvas/connector-line-geometry.ts
27343
- function connectorLineGeometryOf(connectorId, block, childIds, blocks, session) {
27344
- const attrs = block.attrs;
27345
- if (attrs === void 0) return null;
27346
- const { movePreview, resizePreview, endpointDrag, endpointPreview } = session;
27347
- const previewBlocks = (() => {
27348
- if (movePreview === null && resizePreview === null) return blocks;
27349
- const next = { ...blocks };
27350
- for (const childId of childIds) {
27351
- const item = next[childId];
27352
- if (item === void 0 || item.type === "connector") continue;
27353
- if (resizePreview !== null && resizePreview.id === childId) next[childId] = {
27354
- ...item,
27355
- geometry: {
27356
- ...item.geometry,
27357
- ...resizePreview.box
27358
- }
27359
- };
27360
- else if (movePreview !== null && movePreview.idSet.has(childId)) {
27361
- const g = effectiveGeometry(item);
27362
- next[childId] = {
27363
- ...item,
27364
- geometry: {
27365
- x: g.x + movePreview.dx,
27366
- y: g.y + movePreview.dy,
27367
- w: g.w,
27368
- h: g.h
27369
- }
27370
- };
27371
- }
27372
- }
27373
- return next;
27374
- })();
27375
- const obstacleBoxes = [];
27376
- for (const childId of childIds) {
27377
- const item = previewBlocks[childId];
27378
- if (item === void 0 || item.type === "connector" || item.type === "group") continue;
27379
- obstacleBoxes.push(effectiveGeometry(item));
27380
- }
27381
- const startBox = endpointBoxOf(attrs.start, childIds, previewBlocks);
27382
- const endBox = endpointBoxOf(attrs.end, childIds, previewBlocks);
27383
- const startFree = attrs.start.x !== void 0 && attrs.start.y !== void 0 ? {
27384
- x: attrs.start.x,
27385
- y: attrs.start.y
27386
- } : null;
27387
- const endFree = attrs.end.x !== void 0 && attrs.end.y !== void 0 ? {
27388
- x: attrs.end.x,
27389
- y: attrs.end.y
27390
- } : null;
27391
- const startToward = endBox !== null ? {
27392
- x: endBox.x,
27393
- y: endBox.y
27394
- } : endFree ?? {
27395
- x: 0,
27396
- y: 0
27397
- };
27398
- const endToward = startBox !== null ? {
27399
- x: startBox.x,
27400
- y: startBox.y
27401
- } : startFree ?? {
27402
- x: 0,
27403
- y: 0
27404
- };
27405
- const startPoint = endpointPointOf(attrs.start, childIds, previewBlocks, startToward);
27406
- const endPoint = endpointPointOf(attrs.end, childIds, previewBlocks, endToward);
27407
- if (startPoint === null || endPoint === null) return null;
27408
- const dragging = endpointDrag !== null && endpointDrag.connectorId === connectorId;
27409
- const snapPoint = (which) => {
27410
- if (!dragging || endpointDrag === null || endpointDrag.which !== which || endpointPreview === null) return null;
27411
- const snap = endpointPreview.snap;
27412
- const point = {
27413
- x: endpointPreview.point.x,
27414
- y: endpointPreview.point.y
27415
- };
27416
- if (snap === null) {
27417
- const stored = which === "start" ? startPoint : endPoint;
27418
- return {
27419
- ...point,
27420
- nx: stored.nx,
27421
- ny: stored.ny
27422
- };
27423
- }
27424
- const sibling = previewBlocks[snap.blockId];
27425
- if (sibling === void 0) return {
27426
- ...point,
27427
- nx: 0,
27428
- ny: 0
27429
- };
27430
- const p = edgePointOf(effectiveGeometry(sibling), snap.port, snap.t);
27431
- const normal = PORT_NORMAL[snap.port];
27432
- return {
27433
- x: p.x,
27434
- y: p.y,
27435
- nx: normal.nx,
27436
- ny: normal.ny
27437
- };
27438
- };
27439
- const startDraw = dragging && endpointDrag !== null && endpointDrag.which === "start" ? snapPoint("start") ?? startPoint : startPoint;
27440
- const endDraw = dragging && endpointDrag !== null && endpointDrag.which === "end" ? snapPoint("end") ?? endPoint : endPoint;
27441
- const legacy = startBox !== null && endBox !== null && startFree === null && endFree === null && attrs.start.port === void 0 && attrs.end.port === void 0 && !dragging;
27442
- const polyPoint = (ref, resolved, box, key) => {
27443
- const dragged = dragging && endpointDrag !== null && endpointDrag.which === key;
27444
- return ref.x !== void 0 && ref.y !== void 0 ? {
27445
- x: ref.x,
27446
- y: ref.y
27447
- } : ref.port !== void 0 || box === null || dragged ? {
27448
- x: resolved.x,
27449
- y: resolved.y
27450
- } : {
27451
- x: box.x,
27452
- y: box.y
27453
- };
27454
- };
27455
- const startPoly = polyPoint(attrs.start, startDraw, startBox, "start");
27456
- const endPoly = polyPoint(attrs.end, endDraw, endBox, "end");
27457
- const points = (attrs.points ?? []).map(([x, y], index) => {
27458
- if (!dragging || endpointDrag === null || endpointDrag.which !== "waypoint") return [x, y];
27459
- if (endpointDrag.index !== index || endpointPreview === null) return [x, y];
27460
- return [endpointPreview.point.x, endpointPreview.point.y];
27461
- });
27462
- return {
27463
- path: points.length > 0 ? `M ${startPoly.x} ${startPoly.y} L ${points.map(([x, y]) => `${x} ${y}`).join(" L ")} L ${endPoly.x} ${endPoly.y}` : legacy ? connectorPath(startBox, endBox, attrs.variant ?? "straight").d : connectorPathPoints(startDraw, endDraw, attrs.variant ?? "straight", obstacleBoxes).d,
27464
- startDraw,
27465
- endDraw,
27466
- dragging
27467
- };
27468
- }
27469
27806
  // src/canvas/connector-line.tsx
27470
27807
  function connectorLineOf(surfaceId, connectorId, block, childIds, blocks, selected, interactive, session, isDark) {
27471
27808
  const attrs = block.attrs;
@@ -28765,6 +29102,17 @@ function ZOrderMenu({ targetId, position, count, label }) {
28765
29102
  ]
28766
29103
  })] });
28767
29104
  }
29105
+ // src/canvas/connector-variant.ts
29106
+ function setConnectorVariant(doc, id, next) {
29107
+ const block = doc.getBlock(id);
29108
+ if (block === null || block.type !== "connector" || block.attrs === void 0) return;
29109
+ if ((block.attrs.variant ?? "straight") === next) return;
29110
+ const drops = next !== "straight" && block.attrs.points !== void 0;
29111
+ doc.transact(() => {
29112
+ doc.updateBlock(id, { variant: next });
29113
+ if (drops) doc.removeBlockAttr(id, "points");
29114
+ });
29115
+ }
28768
29116
  // src/canvas/shape-toolbar/constants.ts
28769
29117
  /** The shape toolbar's constants (the border width dots, the shape variant
28770
29118
  * picker list, the hex input's form). */
@@ -28989,7 +29337,7 @@ function ConnectorToolbar({ id, variant, strokeColor, strokeWidth, strokeStyle,
28989
29337
  };
28990
29338
  const applyVariant = (next) => {
28991
29339
  if (next === variant) return;
28992
- apply({ variant: next });
29340
+ setConnectorVariant(doc, id, next);
28993
29341
  };
28994
29342
  const applyWidth = (index) => {
28995
29343
  const value = WIDTH_POINTS[index];
@@ -29075,7 +29423,7 @@ function ConnectorToolbar({ id, variant, strokeColor, strokeWidth, strokeStyle,
29075
29423
  option("straight", "connector.straight", /* @__PURE__ */ jsx(Diagonal, { className: "size-4" })),
29076
29424
  option("orthogonal", "connector.orthogonal", /* @__PURE__ */ jsx(Elbow, { className: "size-4" })),
29077
29425
  option("curved", "connector.curved", /* @__PURE__ */ jsx(Curve, { className: "size-4" })),
29078
- onAddWaypoint !== void 0 && /* @__PURE__ */ jsx(ConnectorBendButton, { onPress: onAddWaypoint }),
29426
+ onAddWaypoint !== void 0 && (variant ?? "straight") === "straight" && /* @__PURE__ */ jsx(ConnectorBendButton, { onPress: onAddWaypoint }),
29079
29427
  /* @__PURE__ */ jsx(Separator, {
29080
29428
  orientation: "vertical",
29081
29429
  className: "h-5"
@@ -34281,12 +34629,13 @@ function CanvasWaypointHandles({ connectorId, points, screenOf, onPress }) {
34281
34629
  // src/canvas/canvas-view/CanvasConnectorChrome.tsx
34282
34630
  function CanvasConnectorChrome({ viewport, blocks, target, handles, onEndpointPress, onWaypointPress, onAddWaypoint }) {
34283
34631
  const mid = canvasToScreen(target.mid, viewport.zoom, viewport.pan);
34284
- const waypointPoints = connectorWaypointPoints(blocks[target.id], {
34632
+ const line = blocks[target.id];
34633
+ const waypointPoints = line?.type !== "connector" || (line.attrs?.variant ?? "straight") === "straight" ? connectorWaypointPoints(line, {
34285
34634
  movePreview: viewport.movePreview,
34286
34635
  resizePreview: viewport.resizePreview,
34287
34636
  endpointDrag: viewport.connectorEndpoint,
34288
34637
  endpointPreview: viewport.connectorEndpointPreview
34289
- });
34638
+ }) : [];
34290
34639
  const screenOf = (point) => canvasToScreen(point, viewport.zoom, viewport.pan);
34291
34640
  return /* @__PURE__ */ jsxs(Fragment$1, { children: [
34292
34641
  /* @__PURE__ */ jsx(ConnectorToolbar, {
@@ -35284,6 +35633,10 @@ function handleCanvasEscape({ viewport, selection, doc, sessionRef }) {
35284
35633
  viewport.cancelMove();
35285
35634
  return "stop";
35286
35635
  }
35636
+ if (viewport.connectorSegment !== null) {
35637
+ viewport.cancelConnectorSegment();
35638
+ return "stop";
35639
+ }
35287
35640
  if (viewport.connectorEndpoint !== null) {
35288
35641
  if (viewport.connectorEndpoint.which === "waypoint") viewport.cancelConnectorWaypoint();
35289
35642
  else viewport.cancelConnectorEndpoint();
@@ -35774,7 +36127,8 @@ const EMPTY_SESSION = {
35774
36127
  movePreview: null,
35775
36128
  resizePreview: null,
35776
36129
  endpointDrag: null,
35777
- endpointPreview: null
36130
+ endpointPreview: null,
36131
+ segmentDrag: null
35778
36132
  };
35779
36133
  /** Whether the point stands inside the box (the optional tolerance widens
35780
36134
  * the box's edges). */
@@ -35987,6 +36341,29 @@ const TITLE_CHIP_SELECTOR = "[data-slot='docblocks/group-title'], [data-slot='do
35987
36341
  function pointElementOf(event) {
35988
36342
  return (typeof document.elementFromPoint === "function" ? document.elementFromPoint(event.clientX, event.clientY) : null) ?? (event.target instanceof Element ? event.target : null);
35989
36343
  }
36344
+ /** The shape's text target under the point (the dblclick's shape's text
36345
+ * entry's resolution — the connector's label's entry's guard's shared
36346
+ * read): the event's target's closest first (the retargeted event's stand),
36347
+ * the point's element STACK (the line's hit path — the wide transparent
36348
+ * stroke, the pointer-events' stand — is DOM-top over a shape it paints
36349
+ * over, so the single element's hit test resolves the line's element and
36350
+ * never the shape's target), the single elementFromPoint's fallback (the
36351
+ * jsdom's stack's absence). */
36352
+ function shapeTextTargetAt(event) {
36353
+ if (event.target instanceof Element) {
36354
+ const fromTarget = event.target.closest("[data-slot='docblocks/shape-text-target']");
36355
+ if (fromTarget !== null) return fromTarget;
36356
+ }
36357
+ if (typeof document.elementsFromPoint === "function") {
36358
+ for (const element of document.elementsFromPoint(event.clientX, event.clientY)) {
36359
+ const target = element.closest("[data-slot='docblocks/shape-text-target']");
36360
+ if (target !== null) return target;
36361
+ }
36362
+ return null;
36363
+ }
36364
+ const element = typeof document.elementFromPoint === "function" ? document.elementFromPoint(event.clientX, event.clientY) : null;
36365
+ return element instanceof Element ? element.closest("[data-slot='docblocks/shape-text-target']") ?? null : null;
36366
+ }
35990
36367
  /** The title chip's double-click: the title's inline edit (the chip's own
35991
36368
  * target — the chip stands in the screen layer outside the box, so the
35992
36369
  * container's double-click handler never sees it). Only the chip itself
@@ -36064,9 +36441,10 @@ function createContentDoubleClick(ctx) {
36064
36441
  if (inner !== null) focusCaretInElement(inner, offset);
36065
36442
  return;
36066
36443
  }
36444
+ const shapeTextTarget = shapeTextTargetAt(event);
36067
36445
  const labelWorld = screenToCanvas(ctx.centerRelativePoint(event), ctx.viewport.zoom, ctx.viewport.pan);
36068
36446
  const labelCandidate = pressHitAt(ctx.doc, labelWorld, ctx.viewport.zoom);
36069
- if (labelCandidate !== null && labelCandidate.type === "connector") {
36447
+ if (labelCandidate !== null && labelCandidate.type === "connector" && shapeTextTarget === null) {
36070
36448
  ctx.viewport.setConnectorLabelEditing(labelCandidate.id);
36071
36449
  return;
36072
36450
  }
@@ -36087,14 +36465,47 @@ function createContentDoubleClick(ctx) {
36087
36465
  return;
36088
36466
  }
36089
36467
  }
36090
- const fromTarget = event.target instanceof Element ? event.target.closest("[data-slot='docblocks/shape-text-target']") : null;
36091
- const element = fromTarget !== null ? fromTarget : document.elementFromPoint(event.clientX, event.clientY);
36092
- const target = element instanceof Element ? element.closest("[data-slot='docblocks/shape-text-target']") : null;
36468
+ const target = shapeTextTarget;
36093
36469
  if (target === null) return;
36094
36470
  const id = target.closest("[data-slot='docblocks/canvas-item']")?.getAttribute("data-block-id") ?? null;
36095
36471
  if (id !== null) ctx.viewport.setShapeTextEditing(id);
36096
36472
  };
36097
36473
  }
36474
+ // src/canvas/canvas-view/canvas-segment-press.ts
36475
+ /** The empty session (the press reads the committed route, no preview). */
36476
+ const NO_SESSION = {
36477
+ movePreview: null,
36478
+ resizePreview: null,
36479
+ endpointDrag: null,
36480
+ endpointPreview: null,
36481
+ segmentDrag: null
36482
+ };
36483
+ /**
36484
+ * Opens the segment drag over the pressed connector: true when the press
36485
+ * stood on a movable run (the caller keeps the pointer capture and the
36486
+ * session's release), false otherwise.
36487
+ */
36488
+ function beginSegmentPress(ctx, event, id, world) {
36489
+ if (ctx.viewMode) return false;
36490
+ const block = ctx.doc.getBlock(id);
36491
+ if (block === null || block.type !== "connector") return false;
36492
+ if ((block.attrs?.variant ?? "straight") !== "orthogonal") return false;
36493
+ const surface = ctx.surfaces.find((entry) => entry.children.includes(id));
36494
+ if (surface === void 0) return false;
36495
+ const geometry = connectorLineGeometryOf(id, block, surface.children, ctx.blocks, NO_SESSION);
36496
+ if (geometry === null || geometry.points.length < 3) return false;
36497
+ const reach = 6 / ctx.viewport.zoom + (block.attrs?.strokeWidth ?? 1) / 2;
36498
+ const index = nearestSegmentOf(geometry.points, world, reach);
36499
+ if (index === null) return false;
36500
+ const from = geometry.points[index];
36501
+ const to = geometry.points[index + 1];
36502
+ if (from === void 0 || to === void 0) return false;
36503
+ const axis = segmentAxisOf(from, to);
36504
+ if (axis === null) return false;
36505
+ ctx.containerRef.current?.setPointerCapture?.(event.pointerId);
36506
+ ctx.viewport.beginConnectorSegment(id, index, axis, ctx.centerRelativePoint(event));
36507
+ return true;
36508
+ }
36098
36509
  // src/canvas/canvas-view/canvas-session-press-hit.ts
36099
36510
  /** The inline-editable target (the double-click's own entry): the
36100
36511
  * canvas-text and the shape that carries the inline text. */
@@ -36213,6 +36624,7 @@ function surfacePress(ctx, event) {
36213
36624
  panY: ctx.viewport.pan.y,
36214
36625
  pointerType: event.pointerType
36215
36626
  });
36627
+ if (candidate.type === "connector" && beginSegmentPress(ctx, event, id, world)) return true;
36216
36628
  beginItemPress(ctx, event, ids, candidate.type);
36217
36629
  return true;
36218
36630
  }
@@ -36519,11 +36931,17 @@ function createReleaseHandlers(ctx) {
36519
36931
  ctx.viewport.cancelResize();
36520
36932
  ctx.viewport.cancelConnectorEndpoint();
36521
36933
  ctx.viewport.cancelConnectorWaypoint();
36934
+ ctx.viewport.cancelConnectorSegment();
36522
36935
  ctx.viewport.setMarquee(null);
36523
36936
  ctx.viewport.setPenPoints([]);
36524
36937
  };
36525
36938
  const onPointerUp = (event) => {
36526
36939
  ctx.cardPressRef.current = false;
36940
+ if (ctx.viewport.connectorSegment !== null) {
36941
+ ctx.cycleStepRef.current = null;
36942
+ ctx.viewport.endConnectorSegment();
36943
+ return;
36944
+ }
36527
36945
  if (ctx.viewport.connectorEndpoint !== null) {
36528
36946
  ctx.cycleStepRef.current = null;
36529
36947
  if (ctx.viewport.connectorEndpoint.which === "waypoint") ctx.viewport.endConnectorWaypoint(event.clientX, event.clientY);
@@ -36685,6 +37103,7 @@ function useCanvasSessions(deps) {
36685
37103
  }
36686
37104
  ctx.viewport.moveDrag(event.clientX, event.clientY);
36687
37105
  ctx.viewport.resizeDrag(event.clientX, event.clientY, event.shiftKey);
37106
+ if (ctx.viewport.connectorSegment !== null) ctx.viewport.moveConnectorSegment(ctx.centerRelativePoint(event));
36688
37107
  if (ctx.viewport.connectorEndpoint !== null) {
36689
37108
  if (ctx.viewport.connectorEndpoint.which === "waypoint") ctx.viewport.moveConnectorWaypoint(ctx.centerRelativePoint(event));
36690
37109
  else ctx.viewport.moveConnectorEndpoint(ctx.centerRelativePoint(event));