@markasso/mcp 0.7.6 → 0.7.7

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.
Files changed (2) hide show
  1. package/dist/markasso-mcp.js +298 -18
  2. package/package.json +1 -1
@@ -1395,6 +1395,31 @@ function zoom(viewport, factor, originX, originY) {
1395
1395
  };
1396
1396
  }
1397
1397
  //#endregion
1398
+ //#region ../src/design/tokens.ts
1399
+ /**
1400
+ * Default ink of a drawing in each theme. It is also element data: saved
1401
+ * drawings store these exact hex values and the renderer swaps one for the
1402
+ * other on a theme change, so they must never change.
1403
+ */
1404
+ var DEFAULT_INK = {
1405
+ dark: "#e2e2ef",
1406
+ light: "#000000"
1407
+ };
1408
+ /** Default canvas background of each theme, before the user picks one. */
1409
+ var CANVAS_BG = {
1410
+ dark: "#080808",
1411
+ light: "#ffffff"
1412
+ };
1413
+ CANVAS_BG.dark, DEFAULT_INK.dark;
1414
+ CANVAS_BG.light, DEFAULT_INK.light;
1415
+ ({ ...Object.fromEntries(Object.entries({
1416
+ sm: "40rem",
1417
+ md: "48rem",
1418
+ lg: "64rem",
1419
+ xl: "80rem",
1420
+ "2xl": "96rem"
1421
+ }).map(([k, v]) => [`breakpoint-${k}`, v])) });
1422
+ //#endregion
1398
1423
  //#region ../src/core/font_metrics.generated.ts
1399
1424
  /** Advance widths at 1px font size for code points 32..126, then 160..255. */
1400
1425
  var FONT_WIDTHS = {
@@ -2817,6 +2842,77 @@ function simplifyRoute(points) {
2817
2842
  return out;
2818
2843
  }
2819
2844
  /**
2845
+ * Rounds the inner vertices of a polyline route. Each turn is a quadratic
2846
+ * curve whose control point is the original vertex, so it is tangent to both
2847
+ * legs and maps one to one onto the SVG `Q` command (the canvas and the SVG
2848
+ * export draw the same curve). The radius is clamped to half of each adjacent
2849
+ * leg, so two close turns never overlap, and only a straight vertex or one
2850
+ * with a zero-length leg stays sharp. The two ends are never rounded: arrowheads keep reading their
2851
+ * direction from the unrounded first and last legs.
2852
+ *
2853
+ * Only the drawn stroke and hit testing (distToRoundedRoute) follow the
2854
+ * turns. Label placement and bounds keep the polyline: the curve stays
2855
+ * inside its corner, at most `radius / 4` off each leg (2 units at the
2856
+ * default radius).
2857
+ */
2858
+ function roundRouteCorners(route, radius = 8) {
2859
+ const out = [];
2860
+ if (route.length < 2) return out;
2861
+ let at = route[0];
2862
+ for (let i = 1; i < route.length - 1; i++) {
2863
+ const a = route[i - 1];
2864
+ const b = route[i];
2865
+ const c = route[i + 1];
2866
+ const inLen = Math.hypot(b[0] - a[0], b[1] - a[1]);
2867
+ const outLen = Math.hypot(c[0] - b[0], c[1] - b[1]);
2868
+ const cross = (b[0] - a[0]) * (c[1] - b[1]) - (b[1] - a[1]) * (c[0] - b[0]);
2869
+ const r = Math.min(radius, inLen / 2, outLen / 2);
2870
+ if (r < .001 || Math.abs(cross) < 1e-6) {
2871
+ out.push({
2872
+ kind: "line",
2873
+ to: b
2874
+ });
2875
+ at = b;
2876
+ continue;
2877
+ }
2878
+ const enter = [b[0] + (a[0] - b[0]) * r / inLen, b[1] + (a[1] - b[1]) * r / inLen];
2879
+ const leave = [b[0] + (c[0] - b[0]) * r / outLen, b[1] + (c[1] - b[1]) * r / outLen];
2880
+ if (Math.hypot(enter[0] - at[0], enter[1] - at[1]) > .01) out.push({
2881
+ kind: "line",
2882
+ to: enter
2883
+ });
2884
+ out.push({
2885
+ kind: "turn",
2886
+ corner: b,
2887
+ to: leave
2888
+ });
2889
+ at = leave;
2890
+ }
2891
+ out.push({
2892
+ kind: "line",
2893
+ to: route[route.length - 1]
2894
+ });
2895
+ return out;
2896
+ }
2897
+ /**
2898
+ * Adds a route with rounded turns to the current path of `path` (no
2899
+ * beginPath or stroke). `map` turns world points into the sink's space, e.g.
2900
+ * screen coordinates for a selection outline.
2901
+ */
2902
+ function traceRoundedRoute(path, route, map = (x, y) => [x, y]) {
2903
+ if (route.length < 2) return;
2904
+ const [sx, sy] = map(route[0][0], route[0][1]);
2905
+ path.moveTo(sx, sy);
2906
+ for (const seg of roundRouteCorners(route)) {
2907
+ const [x, y] = map(seg.to[0], seg.to[1]);
2908
+ if (seg.kind === "line") path.lineTo(x, y);
2909
+ else {
2910
+ const [cx, cy] = map(seg.corner[0], seg.corner[1]);
2911
+ path.quadraticCurveTo(cx, cy, x, y);
2912
+ }
2913
+ }
2914
+ }
2915
+ /**
2820
2916
  * Orthogonal route from `start` to `end`. `startDir` is the direction the
2821
2917
  * connector leaves its start shape, `endDir` the outward normal of the side
2822
2918
  * it enters the end shape by; null means the end is free (not attached).
@@ -3496,15 +3592,14 @@ function elbowEnd(el, anchor, pinned, target, targetBox) {
3496
3592
  };
3497
3593
  }
3498
3594
  /**
3499
- * Polyline a connector is drawn along: its two resolved ends, or the full
3500
- * orthogonal route for `routing: 'elbow'`. Curved lines (cx/cy) are not
3501
- * covered here; callers keep their quadratic path for those.
3595
+ * Plans the two ends of an elbow connector from its own data and the
3596
+ * elements it is attached to: the side each end leaves by, the port it
3597
+ * starts from, and a shared coordinate when two flat sides face each other.
3502
3598
  */
3503
- function resolveConnectorRoute(el, allElements) {
3599
+ function planElbowEnds(el, allElements) {
3504
3600
  const pts = resolveArrowEndpoints(el, allElements);
3505
3601
  const start = [pts.x, pts.y];
3506
3602
  const end = [pts.x2, pts.y2];
3507
- if (el.routing !== "elbow") return [start, end];
3508
3603
  const startEl = el.startElementId ? allElements.find((e) => e.id === el.startElementId) : void 0;
3509
3604
  const endEl = el.endElementId ? allElements.find((e) => e.id === el.endElementId) : void 0;
3510
3605
  const targetOf = (other, otherAnchor, otherPoint) => {
@@ -3515,15 +3610,183 @@ function resolveConnectorRoute(el, allElements) {
3515
3610
  const boxOf = (other, otherAnchor) => other && !otherAnchor && !other.rotation ? getConnectorBox(other) : void 0;
3516
3611
  const s = startEl ? elbowEnd(startEl, el.startAnchor, start, targetOf(endEl, el.endAnchor, end), boxOf(endEl, el.endAnchor)) : null;
3517
3612
  const e = endEl ? elbowEnd(endEl, el.endAnchor, end, targetOf(startEl, el.startAnchor, start), boxOf(startEl, el.startAnchor)) : null;
3613
+ let aligned = false;
3518
3614
  if (s && e && startEl && endEl && !el.startAnchor && !el.endAnchor) {
3519
3615
  const shared = sharedOffset(startEl, s.dir, endEl, e.dir);
3520
3616
  if (shared !== null) {
3521
3617
  const vertical = s.dir.dx === 0;
3522
3618
  s.point = vertical ? [shared, s.point[1]] : [s.point[0], shared];
3523
3619
  e.point = vertical ? [shared, e.point[1]] : [e.point[0], shared];
3620
+ aligned = true;
3621
+ }
3622
+ }
3623
+ return {
3624
+ start,
3625
+ end,
3626
+ startEl,
3627
+ endEl,
3628
+ s,
3629
+ e,
3630
+ aligned
3631
+ };
3632
+ }
3633
+ /** Key of one connector end in the port slot map. */
3634
+ var slotKey = (id, which) => `${id}:${which}`;
3635
+ var portSlotCache = /* @__PURE__ */ new WeakMap();
3636
+ /** Space between two connector ends that share a side. */
3637
+ var PORT_GAP = 20;
3638
+ /** Clearance between a spread end and the end of its side (less on short sides). */
3639
+ var PORT_MARGIN = 8;
3640
+ /**
3641
+ * Moves ordered points along a segment as little as possible so that
3642
+ * consecutive ones are at least `PORT_GAP` apart: points that would come too
3643
+ * close are merged into a cluster, spaced evenly and centered on their mean,
3644
+ * then kept inside [lo + PORT_MARGIN, hi - PORT_MARGIN]. A point no other
3645
+ * point crowds keeps its place, so a connector that already runs straight
3646
+ * is not bent. When the side is too short for the full gap, the gap shrinks.
3647
+ */
3648
+ function spreadAlongSide(preferred, lo, hi) {
3649
+ const n = preferred.length;
3650
+ const margin = Math.min(PORT_MARGIN, (hi - lo) / 4);
3651
+ const min = lo + margin;
3652
+ const max = hi - margin;
3653
+ if (n < 2 || max <= min) return [...preferred];
3654
+ const gap = Math.min(PORT_GAP, (max - min) / (n - 1));
3655
+ const make = (first, count, sum) => {
3656
+ const width = (count - 1) * gap;
3657
+ const center = sum / count;
3658
+ return {
3659
+ first,
3660
+ count,
3661
+ sum,
3662
+ start: count === 1 ? center : Math.min(Math.max(center - width / 2, min), max - width)
3663
+ };
3664
+ };
3665
+ const clusters = [];
3666
+ preferred.forEach((p, i) => {
3667
+ let cur = make(i, 1, p);
3668
+ for (;;) {
3669
+ const prev = clusters[clusters.length - 1];
3670
+ if (!prev || prev.start + prev.count * gap <= cur.start + .001) break;
3671
+ clusters.pop();
3672
+ cur = make(prev.first, prev.count + cur.count, prev.sum + cur.sum);
3524
3673
  }
3674
+ clusters.push(cur);
3675
+ });
3676
+ const out = [];
3677
+ for (const c of clusters) for (let k = 0; k < c.count; k++) out.push(c.start + k * gap);
3678
+ return out;
3679
+ }
3680
+ /**
3681
+ * Separates the floating elbow ends that leave the same flat side of a node
3682
+ * and would sit on top of each other (typically all on its middle port):
3683
+ * see spreadAlongSide. Ends on a side are ordered by where their other end
3684
+ * sits along the side's axis (then by connector id), so fanned-out
3685
+ * connectors do not cross each other. Returns the ends it moved, with their
3686
+ * new coordinate along the side (x for top/bottom, y for left/right).
3687
+ *
3688
+ * Pinned ends, hidden connectors, self-loops and sides that are not flat
3689
+ * (see flatSideRange) keep their planned point, and a side with a single
3690
+ * end is left alone. The result depends only on the scene, so every live
3691
+ * peer computes the same routes; it is cached per elements array, which is
3692
+ * immutable, so a frame resolving N connectors plans each of them once
3693
+ * more, not N times.
3694
+ */
3695
+ function elbowPortSlots(allElements) {
3696
+ const cached = portSlotCache.get(allElements);
3697
+ if (cached) return cached;
3698
+ const groups = /* @__PURE__ */ new Map();
3699
+ /** Connectors whose ends sharedOffset put on one coordinate. */
3700
+ const aligned = [];
3701
+ for (const el of allElements) {
3702
+ if (el.type !== "line" && el.type !== "arrow") continue;
3703
+ if (el.routing !== "elbow" || el.visible === false) continue;
3704
+ if (el.startElementId && el.startElementId === el.endElementId) continue;
3705
+ const plan = planElbowEnds(el, allElements);
3706
+ const ends = [[
3707
+ plan.s,
3708
+ plan.startEl,
3709
+ el.startAnchor,
3710
+ plan.e?.point ?? plan.end,
3711
+ "start"
3712
+ ], [
3713
+ plan.e,
3714
+ plan.endEl,
3715
+ el.endAnchor,
3716
+ plan.s?.point ?? plan.start,
3717
+ "end"
3718
+ ]];
3719
+ const added = [];
3720
+ for (const [end, node, anchor, other, which] of ends) {
3721
+ if (!end || !node || anchor || !flatSideRange(node, end.dir)) continue;
3722
+ const axis = end.dir.dx === 0 ? 0 : 1;
3723
+ const depth = (other[0] - end.point[0]) * end.dir.dx + (other[1] - end.point[1]) * end.dir.dy;
3724
+ const member = {
3725
+ key: slotKey(el.id, which),
3726
+ group: `${node.id}:${end.dir.dx},${end.dir.dy}`,
3727
+ node,
3728
+ dir: end.dir,
3729
+ at: end.point[axis],
3730
+ angle: Math.atan2(other[axis] - end.point[axis], depth),
3731
+ id: el.id
3732
+ };
3733
+ const members = groups.get(member.group) ?? [];
3734
+ members.push(member);
3735
+ groups.set(member.group, members);
3736
+ added.push(member);
3737
+ }
3738
+ if (plan.aligned && added.length === 2) aligned.push([added[0], added[1]]);
3739
+ }
3740
+ const partnerOf = /* @__PURE__ */ new Map();
3741
+ for (const [a, b] of aligned) {
3742
+ partnerOf.set(a.key, b.key);
3743
+ partnerOf.set(b.key, a.key);
3744
+ }
3745
+ const placedAt = /* @__PURE__ */ new Map();
3746
+ const slots = /* @__PURE__ */ new Map();
3747
+ const order = [...groups.entries()].sort(([ka, a], [kb, b]) => b.length - a.length || (ka < kb ? -1 : ka > kb ? 1 : 0));
3748
+ for (const [, members] of order) {
3749
+ const { node, dir } = members[0];
3750
+ const [lo, hi] = flatSideRange(node, dir);
3751
+ const preferred = /* @__PURE__ */ new Map();
3752
+ for (const m of members) {
3753
+ const partner = partnerOf.get(m.key);
3754
+ const there = partner === void 0 ? void 0 : placedAt.get(partner);
3755
+ preferred.set(m, there !== void 0 && there >= lo && there <= hi ? there : m.at);
3756
+ }
3757
+ const pref = (m) => preferred.get(m);
3758
+ members.sort((a, b) => (Math.abs(pref(a) - pref(b)) > .01 ? pref(a) - pref(b) : 0) || a.angle - b.angle || (a.id < b.id ? -1 : a.id > b.id ? 1 : 0));
3759
+ const placed = spreadAlongSide(members.map(pref), lo, hi);
3760
+ members.forEach((m, i) => {
3761
+ placedAt.set(m.key, placed[i]);
3762
+ if (Math.abs(placed[i] - m.at) > .01) slots.set(m.key, placed[i]);
3763
+ });
3525
3764
  }
3526
- return computeElbowRoute(s?.point ?? start, s?.dir ?? null, e?.point ?? end, e?.dir ?? null, s?.stub, e?.stub);
3765
+ portSlotCache.set(allElements, slots);
3766
+ return slots;
3767
+ }
3768
+ /** Moves an end's point to `along` on its side's axis. */
3769
+ function placeAlong(end, along) {
3770
+ end.point = end.dir.dx === 0 ? [along, end.point[1]] : [end.point[0], along];
3771
+ }
3772
+ /**
3773
+ * Polyline a connector is drawn along: its two resolved ends, or the full
3774
+ * orthogonal route for `routing: 'elbow'`. Curved lines (cx/cy) are not
3775
+ * covered here; callers keep their quadratic path for those.
3776
+ */
3777
+ function resolveConnectorRoute(el, allElements) {
3778
+ if (el.routing !== "elbow") {
3779
+ const pts = resolveArrowEndpoints(el, allElements);
3780
+ return [[pts.x, pts.y], [pts.x2, pts.y2]];
3781
+ }
3782
+ const plan = planElbowEnds(el, allElements);
3783
+ const { s, e } = plan;
3784
+ const slots = elbowPortSlots(allElements);
3785
+ const startSlot = slots.get(slotKey(el.id, "start"));
3786
+ const endSlot = slots.get(slotKey(el.id, "end"));
3787
+ if (s && startSlot !== void 0) placeAlong(s, startSlot);
3788
+ if (e && endSlot !== void 0) placeAlong(e, endSlot);
3789
+ return computeElbowRoute(s?.point ?? plan.start, s?.dir ?? null, e?.point ?? plan.end, e?.dir ?? null, s?.stub, e?.stub);
3527
3790
  }
3528
3791
  /**
3529
3792
  * Extent of the flat side a connector leaves `el` by, along that side (x for
@@ -3872,8 +4135,8 @@ function contrastColor(fill, fallback) {
3872
4135
  if (Number.isNaN(r) || Number.isNaN(g) || Number.isNaN(b)) return fallback;
3873
4136
  return (.299 * r + .587 * g + .114 * b) / 255 > .55 ? "#111111" : "#ffffff";
3874
4137
  }
3875
- var DARK_DEFAULT_STROKE = "#e2e2ef";
3876
- var LIGHT_DEFAULT_STROKE = "#000000";
4138
+ var DARK_DEFAULT_STROKE = DEFAULT_INK.dark;
4139
+ var LIGHT_DEFAULT_STROKE = DEFAULT_INK.light;
3877
4140
  /**
3878
4141
  * The rule behind resolveStrokeColorForTheme for a given theme, without the
3879
4142
  * DOM: the SVG export applies it for the theme it exports in.
@@ -4223,10 +4486,16 @@ function lineToSVG(el, ox, oy, allElements) {
4223
4486
  function elbowToSVG(el, route, ox, oy) {
4224
4487
  if (route.length < 2) return "";
4225
4488
  const sp = `stroke="${escapeXml(el.strokeColor)}" stroke-width="${el.strokeWidth}" ${capJoinAttrs(el)} fill="none" opacity="${el.opacity}"${strokeDashAttr(el)}`;
4226
- const points = route.map(([x, y]) => `${round(x + ox)},${round(y + oy)}`).join(" ");
4489
+ const d = [];
4490
+ const pt = (x, y) => `${round(x + ox)} ${round(y + oy)}`;
4491
+ traceRoundedRoute({
4492
+ moveTo: (x, y) => d.push(`M${pt(x, y)}`),
4493
+ lineTo: (x, y) => d.push(`L${pt(x, y)}`),
4494
+ quadraticCurveTo: (cx, cy, x, y) => d.push(`Q${pt(cx, cy)} ${pt(x, y)}`)
4495
+ }, route);
4227
4496
  const heads = getConnectorHeads(el, (placement) => offsetVector(getRouteHeadVector(route, placement), ox, oy));
4228
4497
  const rot = rotateAttr(el, ox, oy);
4229
- return [connectorToSVG(el, `<polyline points="${points}" ${sp}${rot}/>`, heads, rot)].join("\n");
4498
+ return [connectorToSVG(el, `<path d="${d.join(" ")}" ${sp}${rot}/>`, heads, rot)].join("\n");
4230
4499
  }
4231
4500
  function arrowToSVG(el, ox, oy, allElements) {
4232
4501
  const pts = resolveArrowEndpoints(el, allElements);
@@ -4326,7 +4595,7 @@ function escapeXml(str) {
4326
4595
  }
4327
4596
  //#endregion
4328
4597
  //#region package.json
4329
- var version = "0.7.6";
4598
+ var version = "0.7.7";
4330
4599
  //#endregion
4331
4600
  //#region ../src/core/layout.ts
4332
4601
  /** Orders vertices without recursion, preserving input order when unconstrained. */
@@ -4468,7 +4737,7 @@ function createAppState() {
4468
4737
  const { document: doc, window: win } = globalThis;
4469
4738
  return {
4470
4739
  activeTool: "select",
4471
- strokeColor: doc?.documentElement.getAttribute("data-theme") === "light" ? "#000000" : "#e2e2ef",
4740
+ strokeColor: doc?.documentElement.getAttribute("data-theme") === "light" ? DEFAULT_INK.light : DEFAULT_INK.dark,
4472
4741
  fillColor: "transparent",
4473
4742
  strokeWidth: win?.matchMedia("(pointer: coarse)").matches ?? false ? 4 : 1,
4474
4743
  fontSize: 20,
@@ -4834,10 +5103,19 @@ function reducer(scene, command, isRemote = false) {
4834
5103
  },
4835
5104
  elements: (() => {
4836
5105
  const targets = targetIds(scene, command.ids);
4837
- return scene.elements.map((el) => targets.has(el.id) && el.type === "text" ? {
4838
- ...el,
4839
- fontFamily: command.family
4840
- } : el);
5106
+ const measured = new Map((command.bounds ?? []).map((b) => [b.id, b]));
5107
+ return scene.elements.map((el) => {
5108
+ if (!targets.has(el.id) || el.type !== "text") return el;
5109
+ const box = measured.get(el.id);
5110
+ return {
5111
+ ...el,
5112
+ fontFamily: command.family,
5113
+ ...box && {
5114
+ width: box.width,
5115
+ height: box.height
5116
+ }
5117
+ };
5118
+ });
4841
5119
  })()
4842
5120
  };
4843
5121
  case "SET_FONT_SIZE": return {
@@ -6579,6 +6857,8 @@ var RESIZE_NUMBERS = [
6579
6857
  "fontSize"
6580
6858
  ];
6581
6859
  /** One check per relayed command type; a type missing here is refused. */
6860
+ /** Per-text boxes measured by the sender (font size and family changes). */
6861
+ var optionalTextBounds = optional((bounds) => isListOf(bounds, (box) => isId(box.id) && isNumber(box.width) && isNumber(box.height)));
6582
6862
  var CHECKS = {
6583
6863
  CREATE_ELEMENT: (c) => isValidElement(c.element) && optionalBoolean(c.select),
6584
6864
  CREATE_ELEMENTS: (c) => isElementList(c.elements),
@@ -6590,8 +6870,8 @@ var CHECKS = {
6590
6870
  PATCH_ELEMENTS: (c) => optional((create) => isListOf(create, (item) => isValidElement(item.element) && Number.isInteger(item.index) && item.index >= 0))(c.create) && optional((update) => isListOf(update, (item) => isId(item.id) && isElementPatch(item.set) && optional((unset) => Array.isArray(unset) && unset.every(isString))(item.unset)))(c.update) && optionalIdList(c.delete) && optionalIdList(c.order),
6591
6871
  EDIT_TEXT: (c) => isId(c.id) && isString(c.content),
6592
6872
  SET_SHAPE_LABEL: (c) => isId(c.id) && isString(c.label) && optionalNumber(c.labelFontSize) && optionalString(c.labelFontFamily),
6593
- SET_FONT_FAMILY: (c) => isString(c.family) && optionalIdList(c.ids),
6594
- SET_FONT_SIZE: (c) => isNumber(c.size) && optionalIdList(c.ids) && optional((bounds) => isListOf(bounds, (box) => isId(box.id) && isNumber(box.width) && isNumber(box.height)))(c.bounds) && optionalNumber(c.width) && optionalNumber(c.height),
6873
+ SET_FONT_FAMILY: (c) => isString(c.family) && optionalIdList(c.ids) && optionalTextBounds(c.bounds),
6874
+ SET_FONT_SIZE: (c) => isNumber(c.size) && optionalIdList(c.ids) && optionalTextBounds(c.bounds) && optionalNumber(c.width) && optionalNumber(c.height),
6595
6875
  SET_ROTATION: (c) => isId(c.id) && isNumber(c.rotation),
6596
6876
  REORDER_ELEMENTS: (c) => isIdList(c.ids) && isNumber(c.targetIndex),
6597
6877
  LOAD_SCENE: (c) => isElementList(c.elements) && validateViewport(c.viewport) !== null,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@markasso/mcp",
3
- "version": "0.7.6",
3
+ "version": "0.7.7",
4
4
  "mcpName": "io.github.AlbertoBarrago/markasso",
5
5
  "description": "MCP server that lets AI agents create, read and edit Markasso diagrams, offline or live on a shared board",
6
6
  "type": "module",