@ogabrielluiz/patchflow 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -4127,7 +4127,7 @@ function findPortPosition(block, portId, direction) {
4127
4127
  }
4128
4128
  function layout(graph, options = {}) {
4129
4129
  const direction = options.direction ?? "LR";
4130
- const rankSep = options.rankSep ?? 160;
4130
+ const rankSep = options.rankSep ?? 200;
4131
4131
  const nodeSep = options.nodeSep ?? 40;
4132
4132
  const allBlocks = [...graph.declaredBlocks, ...graph.stubBlocks];
4133
4133
  const allConnections = [...graph.connections, ...graph.feedbackEdges];
@@ -4420,40 +4420,47 @@ function buildLabels(theme, blocks) {
4420
4420
  return parts.join("");
4421
4421
  }
4422
4422
  function buildAnnotations(theme, connections) {
4423
+ const annotated = connections.filter((c) => c.annotation);
4424
+ if (annotated.length === 0) return "";
4423
4425
  const parts = [];
4424
4426
  const fontFamily = sanitizeForSvg(theme.annotation.fontFamily);
4425
- const fontSize = theme.annotation.fontSize;
4426
- const charWidth = fontSize * 0.55;
4427
- for (const conn of connections) {
4428
- if (!conn.annotation) continue;
4427
+ const noteFontSize = theme.annotation.fontSize + 1;
4428
+ const markerFontFamily = fontFamily;
4429
+ annotated.forEach((conn, i) => {
4430
+ const num = i + 1;
4429
4431
  const sx = conn.sourcePoint.x;
4430
4432
  const sy = conn.sourcePoint.y;
4431
4433
  const tx = conn.targetPoint.x;
4432
4434
  const ty = conn.targetPoint.y;
4433
- let x;
4434
- let y;
4435
+ let mx;
4436
+ let my;
4435
4437
  if (conn.isFeedback) {
4436
- x = (sx + tx) / 2;
4437
- y = Math.max(sy, ty) + 30;
4438
+ mx = (sx + tx) / 2;
4439
+ const match = conn.path.match(/L\s+\S+\s+\S+\s+L\s+\S+\s+(\S+)/);
4440
+ my = match ? parseFloat(match[1]) : Math.max(sy, ty) + 30;
4438
4441
  } else {
4439
- x = (sx + tx) / 2;
4440
- y = (sy + ty) / 2 - 14;
4441
- }
4442
- const prefix = conn.isFeedback ? "\u21BB " : "";
4443
- let raw = conn.annotation;
4444
- if (!conn.isFeedback) {
4445
- const available = Math.abs(tx - sx);
4446
- const prefixWidth = prefix.length * charWidth;
4447
- const maxChars = Math.max(0, Math.floor((available - prefixWidth) / charWidth));
4448
- if (maxChars > 0 && raw.length > maxChars) {
4449
- raw = maxChars > 1 ? raw.slice(0, maxChars - 1) + "\u2026" : raw.slice(0, maxChars);
4450
- }
4442
+ mx = (sx + tx) / 2;
4443
+ my = (sy + ty) / 2;
4451
4444
  }
4452
- const text = prefix + sanitizeForSvg(raw);
4445
+ const markerStroke = conn.isFeedback ? theme.cable.colors[conn.signalType].stroke : theme.label.color;
4453
4446
  parts.push(
4454
- `<text x="${x}" y="${y}" text-anchor="middle" font-family="${fontFamily}" font-size="${fontSize}" fill="${theme.annotation.color}" paint-order="stroke fill" stroke="${theme.annotation.haloColor}" stroke-width="3" stroke-linejoin="round">${text}</text>`
4447
+ `<circle cx="${mx}" cy="${my}" r="8" fill="${theme.panel.highlight}" stroke="${markerStroke}" stroke-width="0.5" data-annotation-marker="${num}"/>`
4455
4448
  );
4456
- }
4449
+ parts.push(
4450
+ `<text x="${mx}" y="${my + 3}" text-anchor="middle" font-family="${markerFontFamily}" font-size="9" fill="${theme.label.color}">${num}</text>`
4451
+ );
4452
+ });
4453
+ const panelX = -120;
4454
+ let panelY = 20;
4455
+ const lineGap = 14;
4456
+ annotated.forEach((conn, i) => {
4457
+ const num = i + 1;
4458
+ const noteText = `${num}. ${sanitizeForSvg(conn.annotation)}`;
4459
+ parts.push(
4460
+ `<text x="${panelX}" y="${panelY}" font-family="${fontFamily}" font-size="${noteFontSize}" fill="${theme.annotation.color}">${noteText}</text>`
4461
+ );
4462
+ panelY += lineGap;
4463
+ });
4457
4464
  return parts.join("");
4458
4465
  }
4459
4466
  function buildLegend(theme, layoutResult) {