@avodado/render 0.2.5 → 0.2.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.
package/dist/index.js CHANGED
@@ -2110,6 +2110,7 @@ function renderErd(data) {
2110
2110
  at2.set(b.name, { x: n.x - b.w / 2, y: n.y - b.h / 2 });
2111
2111
  }
2112
2112
  let s = `<svg viewBox="0 0 ${W2} ${H2}" role="img"><title>Entity-relationship diagram</title>`;
2113
+ const labels = [];
2113
2114
  validRels.forEach((r) => {
2114
2115
  const src = byName.get(r.from);
2115
2116
  const tgt = byName.get(r.to);
@@ -2129,7 +2130,9 @@ function renderErd(data) {
2129
2130
  if (r.label !== void 0 && r.label !== "") {
2130
2131
  const w2 = Math.max(30, r.label.length * 6.4);
2131
2132
  const cy = (fkY + pkY) / 2;
2132
- s += `<rect x="${round(midX - w2 / 2)}" y="${round(cy - 9)}" width="${round(w2)}" height="18" rx="9" fill="var(--white)" stroke="var(--rule)"/><text x="${round(midX)}" y="${round(cy + 3)}" class="edge-label">${escapeHtml(r.label)}</text>`;
2133
+ labels.push(
2134
+ `<rect x="${round(midX - w2 / 2)}" y="${round(cy - 9)}" width="${round(w2)}" height="18" rx="9" fill="var(--white)" stroke="var(--rule)"/><text x="${round(midX)}" y="${round(cy + 3)}" class="edge-label">${escapeHtml(r.label)}</text>`
2135
+ );
2133
2136
  }
2134
2137
  });
2135
2138
  for (const b of boxes) {
@@ -2156,6 +2159,7 @@ function renderErd(data) {
2156
2159
  s += `<line x1="${round(x2)}" y1="${round(rowTop)}" x2="${round(x2 + b.w)}" y2="${round(rowTop)}" class="er-rowline"/><text x="${round(x2 + b.w / 2)}" y="${round(rowTop + 16)}" class="er-col dim" text-anchor="middle">\u2026 +${b.hidden} more</text>`;
2157
2160
  }
2158
2161
  }
2162
+ s += labels.join("");
2159
2163
  s += `</svg>`;
2160
2164
  const opts = {
2161
2165
  tag: "ER",
@@ -3124,6 +3128,7 @@ function renderGraph(data) {
3124
3128
  const width = padX * 2 + cols * cellW + (cols - 1) * gapX;
3125
3129
  const height = padTop + rows * cellH + (rows - 1) * gapY + padBot;
3126
3130
  let s = `<svg viewBox="0 0 ${width} ${height}" role="img"><title>Graph</title>`;
3131
+ const labels = [];
3127
3132
  for (const e of edges) {
3128
3133
  const A2 = byId.get(e.from);
3129
3134
  const B2 = byId.get(e.to);
@@ -3131,13 +3136,15 @@ function renderGraph(data) {
3131
3136
  const p2 = ortho(rectFor2(A2), rectFor2(B2));
3132
3137
  const directed = (e.dir ?? "directed") !== "undirected";
3133
3138
  const markerAttr = directed ? ` marker-end="url(#gArrow)"` : "";
3134
- s += `<g><path d="${p2.d}" fill="none" stroke="#6b7280" stroke-width="1.4"${markerAttr}/>` + edgePill(p2, e.label) + `</g>`;
3139
+ s += `<path d="${p2.d}" fill="none" stroke="#6b7280" stroke-width="1.4"${markerAttr}/>`;
3140
+ labels.push(edgePill(p2, e.label));
3135
3141
  }
3136
3142
  for (const n of nodes) {
3137
3143
  const r = rectFor2(n);
3138
3144
  const c = CHART_COLORS3[(n.group ?? 0) % CHART_COLORS3.length] ?? "#0e54a1";
3139
3145
  s += `<g filter="url(#gshadow)"><rect x="${r.x}" y="${r.y}" width="${r.w}" height="${r.h}" rx="20" fill="#fff" stroke="${c}" stroke-width="1.6"/><text x="${r.cx}" y="${r.cy + 4}" class="blk-name" fill="${c}" text-anchor="middle" style="font-size:12px">${escapeHtml(n.label)}</text></g>`;
3140
3146
  }
3147
+ s += labels.join("");
3141
3148
  s += `</svg>`;
3142
3149
  return diagramFrame(
3143
3150
  {
@@ -3254,12 +3261,14 @@ function renderSwimlane(data) {
3254
3261
  if (L2 === void 0) continue;
3255
3262
  s += `<g><rect x="${padX}" y="${yLane(i)}" width="${width - padX * 2}" height="${laneH}" fill="${i % 2 ? "#fafafa" : "#fff"}" stroke="#e5e7eb"/><rect x="${padX}" y="${yLane(i)}" width="${labelW}" height="${laneH}" fill="#0e54a1"/><text x="${padX + 14}" y="${yLane(i) + laneH / 2 + 4}" class="sl-lane-label">${escapeHtml(L2.label)}</text></g>`;
3256
3263
  }
3264
+ const labels = [];
3257
3265
  for (const lk of links) {
3258
3266
  const A2 = byId.get(lk.from);
3259
3267
  const B2 = byId.get(lk.to);
3260
3268
  if (!A2 || !B2) continue;
3261
3269
  const p2 = ortho(rectFor2(A2), rectFor2(B2));
3262
- s += `<g><path d="${p2.d}" fill="none" stroke="#1a1a2e" stroke-width="1.4" marker-end="url(#gArrow)"/>` + edgePill(p2, lk.label) + `</g>`;
3270
+ s += `<path d="${p2.d}" fill="none" stroke="#1a1a2e" stroke-width="1.4" marker-end="url(#gArrow)"/>`;
3271
+ labels.push(edgePill(p2, lk.label));
3263
3272
  }
3264
3273
  for (const st2 of steps) {
3265
3274
  const r = rectFor2(st2);
@@ -3270,6 +3279,7 @@ function renderSwimlane(data) {
3270
3279
  ).join("");
3271
3280
  s += `<g filter="url(#gshadow)"><rect x="${r.x}" y="${r.y}" width="${r.w}" height="${r.h}" rx="7" fill="${c.fill}" stroke="${c.stroke}" stroke-width="1.3"/>` + texts + `</g>`;
3272
3281
  }
3282
+ s += labels.join("");
3273
3283
  s += `</svg>`;
3274
3284
  return diagramFrame(
3275
3285
  {
@@ -3948,6 +3958,7 @@ function renderCluster(data) {
3948
3958
  const kindLabel = cb.c.kind !== void 0 ? `<text x="${cb.x + cb.w - 14}" y="${cb.y + 21}" class="cl-kind">${escapeHtml(cb.c.kind)}</text>` : "";
3949
3959
  s += `<g><rect x="${cb.x}" y="${cb.y}" width="${cb.w}" height="${cb.h}" rx="12" fill="var(--navy)" fill-opacity="0.035" stroke="var(--navy)" stroke-width="1.4" stroke-dasharray="8 5"/><rect x="${cb.x}" y="${cb.y}" width="${cb.w}" height="${cHeader}" rx="12" fill="var(--navy)"/><rect x="${cb.x}" y="${cb.y + cHeader - 12}" width="${cb.w}" height="12" fill="#0e54a1"/><text x="${cb.x + 16}" y="${cb.y + 21}" class="cl-head">${escapeHtml(cb.c.label)}</text>` + kindLabel + `</g>`;
3950
3960
  }
3961
+ const labels = [];
3951
3962
  for (const e of edges) {
3952
3963
  const A2 = rects.get(e.from);
3953
3964
  const B2 = rects.get(e.to);
@@ -3960,7 +3971,8 @@ function renderCluster(data) {
3960
3971
  marker: "gArrow",
3961
3972
  err: false
3962
3973
  };
3963
- s += `<g><path d="${p2.d}" fill="none" stroke="${st2.stroke}" stroke-width="${st2.sw}" stroke-dasharray="${st2.dash}" marker-end="url(#${st2.marker})"/>` + edgePill(p2, e.label, st2.err) + `</g>`;
3974
+ s += `<path d="${p2.d}" fill="none" stroke="${st2.stroke}" stroke-width="${st2.sw}" stroke-dasharray="${st2.dash}" marker-end="url(#${st2.marker})"/>`;
3975
+ labels.push(edgePill(p2, e.label, st2.err));
3964
3976
  }
3965
3977
  for (const sv of services) {
3966
3978
  const r = rects.get(sv.id);
@@ -3980,6 +3992,7 @@ function renderCluster(data) {
3980
3992
  })() : "";
3981
3993
  s += `<g filter="url(#gshadow)"><path d="${rectRoundRight(r.x, r.y, r.w, r.h, 8)}" fill="${st2.fill}" stroke="${st2.accent}" stroke-width="1.2"/><rect x="${r.x}" y="${r.y}" width="5" height="${r.h}" fill="${st2.accent}"/>` + gl + `<text x="${nx}" y="${r.y + (sv.tech !== void 0 ? 26 : 30)}" class="blk-name" fill="${st2.text}" style="font-size:12px">${escapeHtml(sv.label)}</text>` + techLine + repIndicator + `</g>`;
3982
3994
  }
3995
+ s += labels.join("");
3983
3996
  s += `</svg>`;
3984
3997
  return diagramFrame(
3985
3998
  {
@@ -4006,11 +4019,11 @@ function renderGrid(data) {
4006
4019
  const edges = data.edges ?? [];
4007
4020
  const cellW = 178;
4008
4021
  const cellH = 80;
4009
- const gapX = 54;
4010
- const gapY = 60;
4011
- const padX = 32;
4012
- const padTop = 46;
4013
- const padBot = 28;
4022
+ const gapX = 64;
4023
+ const gapY = 68;
4024
+ const padX = 38;
4025
+ const padTop = 52;
4026
+ const padBot = 36;
4014
4027
  const cols = Math.max(
4015
4028
  1,
4016
4029
  ...nodes.map((n) => (n.col ?? 1) + ((n.w ?? 1) - 1)),
@@ -4030,10 +4043,10 @@ function renderGrid(data) {
4030
4043
  h: cellH
4031
4044
  });
4032
4045
  const groupRect = (g) => ({
4033
- x: xOf(g.col) - 22,
4034
- y: yOf(g.row) - 30,
4035
- w: (g.cols ?? 1) * cellW + ((g.cols ?? 1) - 1) * gapX + 44,
4036
- h: (g.rows ?? 1) * cellH + ((g.rows ?? 1) - 1) * gapY + 54
4046
+ x: xOf(g.col) - 28,
4047
+ y: yOf(g.row) - 38,
4048
+ w: (g.cols ?? 1) * cellW + ((g.cols ?? 1) - 1) * gapX + 56,
4049
+ h: (g.rows ?? 1) * cellH + ((g.rows ?? 1) - 1) * gapY + 66
4037
4050
  });
4038
4051
  const byId = new Map(nodes.map((n) => [n.id, n]));
4039
4052
  const width = padX * 2 + cols * cellW + (cols - 1) * gapX;
@@ -4044,12 +4057,8 @@ function renderGrid(data) {
4044
4057
  let s = `<svg viewBox="0 0 ${width} ${height}" role="img"><title>Block diagram</title>`;
4045
4058
  for (const g of sortedGroups) {
4046
4059
  const r = groupRect(g);
4047
- const col = safeColor(g.color, "#0e54a1");
4048
- const badgeW = 16 + g.label.length * 6.4;
4049
- const isContainer = (g.cols ?? 1) >= 2 && (g.rows ?? 1) >= 2;
4050
- const zone = `<rect x="${r.x}" y="${r.y}" width="${r.w}" height="${r.h}" rx="10" fill="${col}" fill-opacity="0.06" stroke="${col}" stroke-opacity="0.55" stroke-width="1.3" stroke-dasharray="7 5"/>`;
4051
- const label = isContainer ? `<rect x="${r.x + (r.w - badgeW) / 2}" y="${r.y - 1}" width="${badgeW}" height="20" rx="10" fill="${col}"/><text x="${r.x + r.w / 2}" y="${r.y + 13}" class="grp-label" fill="#fff" text-anchor="middle">${escapeHtml(g.label)}</text>` : `<path d="M${r.x} ${r.y + 20} L${r.x} ${r.y + 10} a10 10 0 0 1 10 -10 h${badgeW - 10} v20 z" fill="${col}"/><text x="${r.x + badgeW / 2}" y="${r.y + 14}" class="grp-label" fill="#fff" text-anchor="middle">${escapeHtml(g.label)}</text>`;
4052
- s += `<g>${zone}${label}</g>`;
4060
+ const col = safeColor(g.color, "#475569");
4061
+ s += `<g><rect x="${r.x}" y="${r.y}" width="${r.w}" height="${r.h}" rx="12" fill="none" stroke="${col}" stroke-opacity="0.6" stroke-width="1.3" stroke-dasharray="7 5"/><text x="${r.x + 16}" y="${r.y + 19}" class="grp-label" fill="${col}">${escapeHtml(g.label)}</text></g>`;
4053
4062
  }
4054
4063
  const labels = [];
4055
4064
  for (const e of edges) {
@@ -4318,13 +4327,15 @@ function renderFelogicGraph(data, frame) {
4318
4327
  const col = safeColor(g.color, "#0e54a1");
4319
4328
  s += `<g><rect x="${r.x}" y="${r.y}" width="${r.w}" height="${r.h}" rx="10" fill="${col}" fill-opacity="0.05" stroke="${col}" stroke-opacity="0.5" stroke-width="1.2" stroke-dasharray="7 5"/><text x="${r.x + 14}" y="${r.y + 15}" class="grp-label" fill="${col}">${escapeHtml(g.label)}</text></g>`;
4320
4329
  }
4330
+ const labels = [];
4321
4331
  for (const e of edges) {
4322
4332
  const A2 = byId.get(e.from);
4323
4333
  const B2 = byId.get(e.to);
4324
4334
  if (!A2 || !B2) continue;
4325
4335
  const p2 = ortho(rectFor2(A2), rectFor2(B2));
4326
4336
  const st2 = feEdge(e.kind);
4327
- s += `<g><path d="${p2.d}" fill="none" stroke="${st2.stroke}" stroke-width="${st2.sw}" stroke-dasharray="${st2.dash}" marker-end="url(#${st2.marker})"/>` + edgePill(p2, e.label) + `</g>`;
4337
+ s += `<path d="${p2.d}" fill="none" stroke="${st2.stroke}" stroke-width="${st2.sw}" stroke-dasharray="${st2.dash}" marker-end="url(#${st2.marker})"/>`;
4338
+ labels.push(edgePill(p2, e.label));
4328
4339
  }
4329
4340
  for (const n of nodes) {
4330
4341
  const r = rectFor2(n);
@@ -4343,6 +4354,7 @@ function renderFelogicGraph(data, frame) {
4343
4354
  const note = n.note !== void 0 ? `<text x="${nx}" y="${noteY}" class="blk-tech" fill="${st2.solid === true ? "#cfe0f3" : st2.accent}" text-anchor="${anchor}">${escapeHtml(n.note)}</text>` : "";
4344
4355
  s += `<g filter="url(#gshadow)">` + card + stripe + gl + stereo + `<text x="${nx}" y="${nameY}" class="blk-name" fill="${st2.text}" text-anchor="${anchor}">${escapeHtml(n.name)}</text>` + note + `</g>`;
4345
4356
  }
4357
+ s += labels.join("");
4346
4358
  s += `</svg>`;
4347
4359
  return diagramFrame(
4348
4360
  {