@markasso/mcp 0.8.0 → 0.8.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.
Files changed (2) hide show
  1. package/dist/markasso-mcp.js +210 -24
  2. package/package.json +1 -1
@@ -63,6 +63,19 @@ function quarter(x0, y0, x1, y1, startAxis) {
63
63
  y1
64
64
  ];
65
65
  }
66
+ /** Middle half of `0..length`: the usable part of a cap or a point. */
67
+ function middleHalf(length) {
68
+ return [length * .25, length * .75];
69
+ }
70
+ /** Every side usable along its full length. */
71
+ function allSides(w, h) {
72
+ return {
73
+ top: [0, w],
74
+ right: [0, h],
75
+ bottom: [0, w],
76
+ left: [0, h]
77
+ };
78
+ }
66
79
  function rectCommands(w, h) {
67
80
  return [
68
81
  [
@@ -115,6 +128,16 @@ var SHAPE_DEFINITIONS = {
115
128
  ["Z"]
116
129
  ];
117
130
  },
131
+ sides(w, h) {
132
+ const r = Math.min(w / 2, h / 2);
133
+ const flat = w - 2 * r >= w * .5 ? [r, w - r] : middleHalf(w);
134
+ return {
135
+ top: flat,
136
+ right: middleHalf(h),
137
+ bottom: flat,
138
+ left: middleHalf(h)
139
+ };
140
+ },
118
141
  textBox(w, h) {
119
142
  const r = Math.min(w / 2, h / 2);
120
143
  return {
@@ -152,6 +175,15 @@ var SHAPE_DEFINITIONS = {
152
175
  ["Z"]
153
176
  ];
154
177
  },
178
+ sides(w, h) {
179
+ const s = Math.min(w * .2, h * .5);
180
+ return {
181
+ top: [s, w],
182
+ right: [0, h],
183
+ bottom: [0, w - s],
184
+ left: [0, h]
185
+ };
186
+ },
155
187
  textBox(w, h) {
156
188
  const s = Math.min(w * .2, h * .5);
157
189
  return {
@@ -194,6 +226,15 @@ var SHAPE_DEFINITIONS = {
194
226
  ["Z"]
195
227
  ];
196
228
  },
229
+ sides(w, h) {
230
+ const base = h - h * .1;
231
+ return {
232
+ top: [0, w],
233
+ right: [0, base],
234
+ bottom: [0, w],
235
+ left: [0, base]
236
+ };
237
+ },
197
238
  textBox(w, h) {
198
239
  return {
199
240
  x: 0,
@@ -224,6 +265,15 @@ var SHAPE_DEFINITIONS = {
224
265
  ["Z"]
225
266
  ];
226
267
  },
268
+ sides(w, h) {
269
+ const ry = Math.min(h * .15, w * .25);
270
+ return {
271
+ top: middleHalf(w),
272
+ right: [ry, h - ry],
273
+ bottom: middleHalf(w),
274
+ left: [ry, h - ry]
275
+ };
276
+ },
227
277
  details(w, h) {
228
278
  const ry = Math.min(h * .15, w * .25);
229
279
  return [
@@ -248,6 +298,7 @@ var SHAPE_DEFINITIONS = {
248
298
  },
249
299
  predefinedProcess: {
250
300
  outline: rectCommands,
301
+ sides: allSides,
251
302
  details(w, h) {
252
303
  const d = Math.min(w * .1, 16);
253
304
  return [
@@ -320,6 +371,15 @@ var SHAPE_DEFINITIONS = {
320
371
  ["Z"]
321
372
  ];
322
373
  },
374
+ sides(w, h) {
375
+ const s = Math.min(w * .2, h * .5);
376
+ return {
377
+ top: [s, w - s],
378
+ right: middleHalf(h),
379
+ bottom: [s, w - s],
380
+ left: middleHalf(h)
381
+ };
382
+ },
323
383
  textBox(w, h) {
324
384
  const s = Math.min(w * .2, h * .5);
325
385
  return {
@@ -356,6 +416,14 @@ var SHAPE_DEFINITIONS = {
356
416
  ["Z"]
357
417
  ];
358
418
  },
419
+ sides(w, h) {
420
+ return {
421
+ top: [0, w],
422
+ right: [0, h],
423
+ bottom: [0, w],
424
+ left: [h * .25, h]
425
+ };
426
+ },
359
427
  textBox(w, h) {
360
428
  const t = h * .25;
361
429
  return {
@@ -390,6 +458,15 @@ var SHAPE_DEFINITIONS = {
390
458
  ["Z"]
391
459
  ];
392
460
  },
461
+ sides(w, h) {
462
+ const r = Math.min(w / 2, h / 2);
463
+ return {
464
+ top: [0, w - r],
465
+ right: middleHalf(h),
466
+ bottom: [0, w - r],
467
+ left: [0, h]
468
+ };
469
+ },
393
470
  textBox(w, h) {
394
471
  const r = Math.min(w / 2, h / 2);
395
472
  return {
@@ -3132,6 +3209,82 @@ function flattenShapeCommands(commands) {
3132
3209
  function getShapeOutlinePolygon(kind, w, h) {
3133
3210
  return flattenShapeCommands(SHAPE_DEFINITIONS[kind].outline(w, h))[0] ?? [];
3134
3211
  }
3212
+ /** Samples per cubic when looking for crossings, before refining them. */
3213
+ var EDGE_SCAN_STEPS = 32;
3214
+ /** Bisection rounds per crossing: far below a pixel on any shape size. */
3215
+ var EDGE_REFINE_STEPS = 40;
3216
+ /**
3217
+ * Where a side's outline lies at `along` (x for top and bottom, y for left
3218
+ * and right), in box-local coordinates: the outline crossing of the line
3219
+ * through `along` perpendicular to the side, the outermost one toward that
3220
+ * side. Curves are intersected exactly (scanned, then refined by
3221
+ * bisection), not through the flattened polygon, so an end placed there
3222
+ * touches the drawn stroke on large shapes too. Null when the line misses
3223
+ * the outline.
3224
+ */
3225
+ function getShapeSideEdge(kind, w, h, side, along) {
3226
+ const vertical = side === "top" || side === "bottom";
3227
+ const outward = side === "bottom" || side === "right" ? 1 : -1;
3228
+ /** Along and across coordinates of a point. */
3229
+ const a = (p) => vertical ? p[0] : p[1];
3230
+ const c = (p) => vertical ? p[1] : p[0];
3231
+ let best = null;
3232
+ const consider = (at) => {
3233
+ if (best === null || at * outward > best * outward) best = at;
3234
+ };
3235
+ const line = (p, q) => {
3236
+ const lo = Math.min(a(p), a(q));
3237
+ const hi = Math.max(a(p), a(q));
3238
+ if (along < lo || along > hi) return;
3239
+ const span = a(q) - a(p);
3240
+ if (Math.abs(span) < 1e-9) {
3241
+ consider(c(p));
3242
+ consider(c(q));
3243
+ } else consider(c(p) + (along - a(p)) / span * (c(q) - c(p)));
3244
+ };
3245
+ const cubic = (p0, p1, p2, p3) => {
3246
+ const at = (t) => [cubicAt(p0[0], p1[0], p2[0], p3[0], t), cubicAt(p0[1], p1[1], p2[1], p3[1], t)];
3247
+ const offset = (t) => a(at(t)) - along;
3248
+ let t0 = 0;
3249
+ let f0 = offset(0);
3250
+ for (let i = 1; i <= EDGE_SCAN_STEPS; i++) {
3251
+ const t1 = i / EDGE_SCAN_STEPS;
3252
+ const f1 = offset(t1);
3253
+ if (f0 === 0) consider(c(at(t0)));
3254
+ else if (f0 * f1 < 0) {
3255
+ let lo = t0;
3256
+ let hi = t1;
3257
+ for (let k = 0; k < EDGE_REFINE_STEPS; k++) {
3258
+ const mid = (lo + hi) / 2;
3259
+ if (offset(lo) * offset(mid) <= 0) hi = mid;
3260
+ else lo = mid;
3261
+ }
3262
+ consider(c(at((lo + hi) / 2)));
3263
+ }
3264
+ t0 = t1;
3265
+ f0 = f1;
3266
+ }
3267
+ if (f0 === 0) consider(c(at(1)));
3268
+ };
3269
+ let start = null;
3270
+ let current = null;
3271
+ for (const cmd of SHAPE_DEFINITIONS[kind].outline(w, h)) if (cmd[0] === "M") {
3272
+ if (start) break;
3273
+ start = current = [cmd[1], cmd[2]];
3274
+ } else if (cmd[0] === "L" && current) {
3275
+ const next = [cmd[1], cmd[2]];
3276
+ line(current, next);
3277
+ current = next;
3278
+ } else if (cmd[0] === "C" && current) {
3279
+ const next = [cmd[5], cmd[6]];
3280
+ cubic(current, [cmd[1], cmd[2]], [cmd[3], cmd[4]], next);
3281
+ current = next;
3282
+ } else if (cmd[0] === "Z" && current && start) {
3283
+ line(current, start);
3284
+ current = start;
3285
+ }
3286
+ return best;
3287
+ }
3135
3288
  function getShapeTextBox(kind, w, h) {
3136
3289
  return SHAPE_DEFINITIONS[kind].textBox(w, h);
3137
3290
  }
@@ -3614,9 +3767,8 @@ function planElbowEnds(el, allElements) {
3614
3767
  if (s && e && startEl && endEl && !el.startAnchor && !el.endAnchor) {
3615
3768
  const shared = sharedOffset(startEl, s.dir, endEl, e.dir);
3616
3769
  if (shared !== null) {
3617
- const vertical = s.dir.dx === 0;
3618
- s.point = vertical ? [shared, s.point[1]] : [s.point[0], shared];
3619
- e.point = vertical ? [shared, e.point[1]] : [e.point[0], shared];
3770
+ placeAlong(s, startEl, shared);
3771
+ placeAlong(e, endEl, shared);
3620
3772
  aligned = true;
3621
3773
  }
3622
3774
  }
@@ -3685,8 +3837,8 @@ function spreadAlongSide(preferred, lo, hi) {
3685
3837
  * connectors do not cross each other. Returns the ends it moved, with their
3686
3838
  * new coordinate along the side (x for top/bottom, y for left/right).
3687
3839
  *
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
3840
+ * Pinned ends, hidden connectors, self-loops and sides with a single port
3841
+ * (see sideSpan) keep their planned point, and a side with a single
3690
3842
  * end is left alone. The result depends only on the scene, so every live
3691
3843
  * peer computes the same routes; it is cached per elements array, which is
3692
3844
  * immutable, so a frame resolving N connectors plans each of them once
@@ -3718,7 +3870,7 @@ function elbowPortSlots(allElements) {
3718
3870
  ]];
3719
3871
  const added = [];
3720
3872
  for (const [end, node, anchor, other, which] of ends) {
3721
- if (!end || !node || anchor || !flatSideRange(node, end.dir)) continue;
3873
+ if (!end || !node || anchor || !sideSpan(node, end.dir)) continue;
3722
3874
  const axis = end.dir.dx === 0 ? 0 : 1;
3723
3875
  const depth = (other[0] - end.point[0]) * end.dir.dx + (other[1] - end.point[1]) * end.dir.dy;
3724
3876
  const member = {
@@ -3747,7 +3899,7 @@ function elbowPortSlots(allElements) {
3747
3899
  const order = [...groups.entries()].sort(([ka, a], [kb, b]) => b.length - a.length || (ka < kb ? -1 : ka > kb ? 1 : 0));
3748
3900
  for (const [, members] of order) {
3749
3901
  const { node, dir } = members[0];
3750
- const [lo, hi] = flatSideRange(node, dir);
3902
+ const [lo, hi] = sideSpan(node, dir);
3751
3903
  const preferred = /* @__PURE__ */ new Map();
3752
3904
  for (const m of members) {
3753
3905
  const partner = partnerOf.get(m.key);
@@ -3755,7 +3907,8 @@ function elbowPortSlots(allElements) {
3755
3907
  preferred.set(m, there !== void 0 && there >= lo && there <= hi ? there : m.at);
3756
3908
  }
3757
3909
  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));
3910
+ const grid = (m) => Math.round(pref(m) * 100);
3911
+ members.sort((a, b) => grid(a) - grid(b) || a.angle - b.angle || (a.id < b.id ? -1 : a.id > b.id ? 1 : 0));
3759
3912
  const placed = spreadAlongSide(members.map(pref), lo, hi);
3760
3913
  members.forEach((m, i) => {
3761
3914
  placedAt.set(m.key, placed[i]);
@@ -3765,9 +3918,32 @@ function elbowPortSlots(allElements) {
3765
3918
  portSlotCache.set(allElements, slots);
3766
3919
  return slots;
3767
3920
  }
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];
3921
+ /**
3922
+ * Moves an end's point to `along` on its side's axis. On a flowchart symbol
3923
+ * the point also moves across, onto the outline, since that side may be
3924
+ * slanted or curved; flat sides keep their line.
3925
+ */
3926
+ function placeAlong(end, node, along) {
3927
+ const vertical = end.dir.dx === 0;
3928
+ let across = vertical ? end.point[1] : end.point[0];
3929
+ if (node.type === "shape" && !node.rotation) {
3930
+ const b = getElementBounds(node);
3931
+ const [start, length] = vertical ? [b.x, b.w] : [b.y, b.h];
3932
+ const local = Math.min(Math.max(along - start, 0), length);
3933
+ const edge = getShapeSideEdge(node.kind, b.w, b.h, sideOf(end.dir), local);
3934
+ if (edge !== null) {
3935
+ across = edge + (vertical ? b.y : b.x);
3936
+ const outer = vertical ? end.dir.dy === 1 ? b.y + b.h : b.y : end.dir.dx === 1 ? b.x + b.w : b.x;
3937
+ end.stub = 16 + Math.abs(outer - across);
3938
+ }
3939
+ }
3940
+ end.point = vertical ? [along, across] : [across, along];
3941
+ }
3942
+ /** The box side an outward axis direction leaves by. */
3943
+ function sideOf(dir) {
3944
+ if (dir.dy === -1) return "top";
3945
+ if (dir.dy === 1) return "bottom";
3946
+ return dir.dx === 1 ? "right" : "left";
3771
3947
  }
3772
3948
  /**
3773
3949
  * Polyline a connector is drawn along: its two resolved ends, or the full
@@ -3784,22 +3960,32 @@ function resolveConnectorRoute(el, allElements) {
3784
3960
  const slots = elbowPortSlots(allElements);
3785
3961
  const startSlot = slots.get(slotKey(el.id, "start"));
3786
3962
  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);
3963
+ if (s && plan.startEl && startSlot !== void 0) placeAlong(s, plan.startEl, startSlot);
3964
+ if (e && plan.endEl && endSlot !== void 0) placeAlong(e, plan.endEl, endSlot);
3789
3965
  return computeElbowRoute(s?.point ?? plan.start, s?.dir ?? null, e?.point ?? plan.end, e?.dir ?? null, s?.stub, e?.stub);
3790
3966
  }
3791
3967
  /**
3792
- * Extent of the flat side a connector leaves `el` by, along that side (x for
3793
- * top/bottom, y for left/right), inset from rounded corners; null for shapes
3794
- * whose sides aren't flat (ellipse, rhombus, flowchart symbols) or rotated.
3968
+ * Stretch of the side a connector leaves `el` by where several ends can
3969
+ * spread, along that side (x for top/bottom, y for left/right): a flat side
3970
+ * inset from rounded corners, or the stretch a flowchart symbol declares
3971
+ * (see ShapeSides), which may be slanted or curved. Null for sides with a
3972
+ * single port (ellipse, rhombus, round or pointed symbol ends) and for
3973
+ * rotated elements.
3795
3974
  */
3796
- function flatSideRange(el, dir) {
3975
+ function sideSpan(el, dir) {
3797
3976
  if (el.rotation) return null;
3798
- if (el.type !== "rectangle" && el.type !== "stencil" && el.type !== "text" && el.type !== "image") return null;
3799
3977
  const b = getElementBounds(el);
3978
+ const vertical = dir.dx === 0;
3979
+ if (el.type === "shape") {
3980
+ const span = SHAPE_DEFINITIONS[el.kind].sides(b.w, b.h)[sideOf(dir)];
3981
+ if (!span || span[1] - span[0] < 1) return null;
3982
+ const offset = vertical ? b.x : b.y;
3983
+ return [span[0] + offset, span[1] + offset];
3984
+ }
3985
+ if (el.type !== "rectangle" && el.type !== "stencil" && el.type !== "text" && el.type !== "image") return null;
3800
3986
  const side = el.type === "stencil" && dir.dy === 1 ? getStencilLabelBox(el) ?? b : b;
3801
3987
  const inset = el.type === "rectangle" ? el.cornerRadius ?? 0 : 0;
3802
- const [lo, hi] = dir.dx === 0 ? [side.x, side.x + side.w] : [side.y, side.y + side.h];
3988
+ const [lo, hi] = vertical ? [side.x, side.x + side.w] : [side.y, side.y + side.h];
3803
3989
  return hi - lo > inset * 2 ? [lo + inset, hi - inset] : null;
3804
3990
  }
3805
3991
  /**
@@ -3812,8 +3998,8 @@ function flatSideRange(el, dir) {
3812
3998
  */
3813
3999
  function sharedOffset(startEl, startDir, endEl, endDir) {
3814
4000
  if (startDir.dx !== -endDir.dx || startDir.dy !== -endDir.dy) return null;
3815
- const a = flatSideRange(startEl, startDir);
3816
- const b = flatSideRange(endEl, endDir);
4001
+ const a = sideSpan(startEl, startDir);
4002
+ const b = sideSpan(endEl, endDir);
3817
4003
  if (!a || !b) return null;
3818
4004
  const lo = Math.max(a[0], b[0]);
3819
4005
  const hi = Math.min(a[1], b[1]);
@@ -3976,7 +4162,7 @@ function getConnectorLabelSize(el) {
3976
4162
  };
3977
4163
  }
3978
4164
  function isCurved(el) {
3979
- return el.type === "line" && el.cx !== void 0 && el.cy !== void 0;
4165
+ return el.type === "line" && el.routing !== "elbow" && el.cx !== void 0 && el.cy !== void 0;
3980
4166
  }
3981
4167
  /** Polyline the connector is drawn along (curves sampled). */
3982
4168
  function polylineOf$1(el, elements) {
@@ -4595,7 +4781,7 @@ function escapeXml(str) {
4595
4781
  }
4596
4782
  //#endregion
4597
4783
  //#region package.json
4598
- var version = "0.8.0";
4784
+ var version = "0.8.1";
4599
4785
  //#endregion
4600
4786
  //#region ../src/core/layout.ts
4601
4787
  /** Space kept on both sides of a label between ranks. */
@@ -8471,7 +8657,7 @@ function isConnector(el) {
8471
8657
  /** Polyline the connector is drawn along (curves sampled). */
8472
8658
  function polylineOf(el, elements) {
8473
8659
  const route = resolveConnectorRoute(el, elements);
8474
- if (el.type !== "line" || el.cx === void 0 || el.cy === void 0 || route.length !== 2) return route;
8660
+ if (el.type !== "line" || el.routing === "elbow" || el.cx === void 0 || el.cy === void 0 || route.length !== 2) return route;
8475
8661
  const [[x1, y1], [x2, y2]] = route;
8476
8662
  const { cx, cy } = el;
8477
8663
  return Array.from({ length: 13 }, (_, i) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@markasso/mcp",
3
- "version": "0.8.0",
3
+ "version": "0.8.1",
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",