@ogabrielluiz/patchflow 0.1.4 → 0.1.5

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.cjs CHANGED
@@ -4091,7 +4091,7 @@ function selfLoopArcPath(source, target, blockBottom, arcOffset) {
4091
4091
  var MIN_WIDTH = 140;
4092
4092
  var MIN_HEIGHT = 90;
4093
4093
  function getBlockDimensions(block, portCount) {
4094
- const labelWidth = block.label.length * 8;
4094
+ const labelWidth = block.label.length * 11;
4095
4095
  const subLabelWidth = block.subLabel ? block.subLabel.length * 7 : 0;
4096
4096
  const paramWidths = block.params.map((p) => `${p.key}: ${p.value}`.length * 7);
4097
4097
  const longestParam = paramWidths.length > 0 ? Math.max(...paramWidths) : 0;
@@ -4365,6 +4365,14 @@ function checkHeightInvariant(args) {
4365
4365
  function genId() {
4366
4366
  return "pf-" + Math.random().toString(16).slice(2, 8);
4367
4367
  }
4368
+ function fitLabel(label, maxWidth, charWidth) {
4369
+ if (maxWidth <= 0 || charWidth <= 0) return label;
4370
+ const maxChars = Math.floor(maxWidth / charWidth);
4371
+ if (maxChars <= 0) return label;
4372
+ if (label.length <= maxChars) return label;
4373
+ if (maxChars === 1) return "\u2026";
4374
+ return label.slice(0, maxChars - 1) + "\u2026";
4375
+ }
4368
4376
  function buildDesc(layoutResult) {
4369
4377
  const blockCount = layoutResult.blocks.length;
4370
4378
  const connCount = layoutResult.connections.length;
@@ -4410,11 +4418,11 @@ function buildPanels(theme, idPrefix, blocks) {
4410
4418
  const parts = [];
4411
4419
  for (const block of blocks) {
4412
4420
  const moduleName = sanitizeForSvg(block.parentModule || block.label);
4413
- const label = sanitizeForSvg(block.label);
4414
4421
  const fontFamily = sanitizeForSvg(theme.label.fontFamily);
4415
4422
  const insetX = block.x + 12;
4416
4423
  const insetY = block.y + 8;
4417
4424
  const insetW = block.width - 24;
4425
+ const label = sanitizeForSvg(fitLabel(block.label, insetW, 11));
4418
4426
  let group = `<g data-module="${moduleName}" filter="url(#${idPrefix}-panel-shadow)">`;
4419
4427
  group += `<rect x="${block.x}" y="${block.y}" width="${block.width}" height="${block.height}" fill="${theme.panel.fill}" stroke="${theme.panel.stroke}" stroke-width="0.75" rx="${theme.panel.cornerRadius}"/>`;
4420
4428
  group += `<line x1="${block.x}" y1="${block.y + 0.5}" x2="${block.x + block.width}" y2="${block.y + 0.5}" stroke="${theme.panel.highlight}" stroke-width="${theme.panel.bevelWidth}"/>`;
@@ -4422,7 +4430,7 @@ function buildPanels(theme, idPrefix, blocks) {
4422
4430
  group += `<rect x="${insetX}" y="${insetY}" width="${insetW}" height="28" fill="${theme.label.plateFill}" stroke="${theme.label.plateStroke}" stroke-width="0.5"/>`;
4423
4431
  group += `<text x="${block.x + block.width / 2}" y="${block.y + 22}" text-anchor="middle" font-family="${fontFamily}" font-size="14" font-weight="700" fill="${theme.label.color}" letter-spacing="3">${label}</text>`;
4424
4432
  if (block.subLabel) {
4425
- const subLabel = sanitizeForSvg(block.subLabel);
4433
+ const subLabel = sanitizeForSvg(fitLabel(block.subLabel, insetW - 8, 7));
4426
4434
  const barX = insetX;
4427
4435
  const barY = insetY + 28;
4428
4436
  const barW = insetW;
@@ -4448,7 +4456,8 @@ function buildParams(blocks, theme) {
4448
4456
  `<rect x="${px}" y="${py}" width="${pw}" height="20" fill="${theme.param.plateFill}" stroke="${theme.param.plateStroke}" stroke-width="0.5"/>`
4449
4457
  );
4450
4458
  const keyNorm = param.key.trim().toLowerCase();
4451
- const text = keyNorm === blockLabelNorm ? sanitizeForSvg(param.value) : `${sanitizeForSvg(param.key)}: ${sanitizeForSvg(param.value)}`;
4459
+ const rawText = keyNorm === blockLabelNorm ? param.value : `${param.key}: ${param.value}`;
4460
+ const text = sanitizeForSvg(fitLabel(rawText, pw - 8, 7));
4452
4461
  parts.push(
4453
4462
  `<text x="${px + pw / 2}" y="${py + 14}" text-anchor="middle" font-family="${monoFont}" font-size="10" fill="${theme.param.textColor}">${text}</text>`
4454
4463
  );