@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 +13 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +13 -4
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -4042,7 +4042,7 @@ function selfLoopArcPath(source, target, blockBottom, arcOffset) {
|
|
|
4042
4042
|
var MIN_WIDTH = 140;
|
|
4043
4043
|
var MIN_HEIGHT = 90;
|
|
4044
4044
|
function getBlockDimensions(block, portCount) {
|
|
4045
|
-
const labelWidth = block.label.length *
|
|
4045
|
+
const labelWidth = block.label.length * 11;
|
|
4046
4046
|
const subLabelWidth = block.subLabel ? block.subLabel.length * 7 : 0;
|
|
4047
4047
|
const paramWidths = block.params.map((p) => `${p.key}: ${p.value}`.length * 7);
|
|
4048
4048
|
const longestParam = paramWidths.length > 0 ? Math.max(...paramWidths) : 0;
|
|
@@ -4316,6 +4316,14 @@ function checkHeightInvariant(args) {
|
|
|
4316
4316
|
function genId() {
|
|
4317
4317
|
return "pf-" + Math.random().toString(16).slice(2, 8);
|
|
4318
4318
|
}
|
|
4319
|
+
function fitLabel(label, maxWidth, charWidth) {
|
|
4320
|
+
if (maxWidth <= 0 || charWidth <= 0) return label;
|
|
4321
|
+
const maxChars = Math.floor(maxWidth / charWidth);
|
|
4322
|
+
if (maxChars <= 0) return label;
|
|
4323
|
+
if (label.length <= maxChars) return label;
|
|
4324
|
+
if (maxChars === 1) return "\u2026";
|
|
4325
|
+
return label.slice(0, maxChars - 1) + "\u2026";
|
|
4326
|
+
}
|
|
4319
4327
|
function buildDesc(layoutResult) {
|
|
4320
4328
|
const blockCount = layoutResult.blocks.length;
|
|
4321
4329
|
const connCount = layoutResult.connections.length;
|
|
@@ -4361,11 +4369,11 @@ function buildPanels(theme, idPrefix, blocks) {
|
|
|
4361
4369
|
const parts = [];
|
|
4362
4370
|
for (const block of blocks) {
|
|
4363
4371
|
const moduleName = sanitizeForSvg(block.parentModule || block.label);
|
|
4364
|
-
const label = sanitizeForSvg(block.label);
|
|
4365
4372
|
const fontFamily = sanitizeForSvg(theme.label.fontFamily);
|
|
4366
4373
|
const insetX = block.x + 12;
|
|
4367
4374
|
const insetY = block.y + 8;
|
|
4368
4375
|
const insetW = block.width - 24;
|
|
4376
|
+
const label = sanitizeForSvg(fitLabel(block.label, insetW, 11));
|
|
4369
4377
|
let group = `<g data-module="${moduleName}" filter="url(#${idPrefix}-panel-shadow)">`;
|
|
4370
4378
|
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}"/>`;
|
|
4371
4379
|
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}"/>`;
|
|
@@ -4373,7 +4381,7 @@ function buildPanels(theme, idPrefix, blocks) {
|
|
|
4373
4381
|
group += `<rect x="${insetX}" y="${insetY}" width="${insetW}" height="28" fill="${theme.label.plateFill}" stroke="${theme.label.plateStroke}" stroke-width="0.5"/>`;
|
|
4374
4382
|
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>`;
|
|
4375
4383
|
if (block.subLabel) {
|
|
4376
|
-
const subLabel = sanitizeForSvg(block.subLabel);
|
|
4384
|
+
const subLabel = sanitizeForSvg(fitLabel(block.subLabel, insetW - 8, 7));
|
|
4377
4385
|
const barX = insetX;
|
|
4378
4386
|
const barY = insetY + 28;
|
|
4379
4387
|
const barW = insetW;
|
|
@@ -4399,7 +4407,8 @@ function buildParams(blocks, theme) {
|
|
|
4399
4407
|
`<rect x="${px}" y="${py}" width="${pw}" height="20" fill="${theme.param.plateFill}" stroke="${theme.param.plateStroke}" stroke-width="0.5"/>`
|
|
4400
4408
|
);
|
|
4401
4409
|
const keyNorm = param.key.trim().toLowerCase();
|
|
4402
|
-
const
|
|
4410
|
+
const rawText = keyNorm === blockLabelNorm ? param.value : `${param.key}: ${param.value}`;
|
|
4411
|
+
const text = sanitizeForSvg(fitLabel(rawText, pw - 8, 7));
|
|
4403
4412
|
parts.push(
|
|
4404
4413
|
`<text x="${px + pw / 2}" y="${py + 14}" text-anchor="middle" font-family="${monoFont}" font-size="10" fill="${theme.param.textColor}">${text}</text>`
|
|
4405
4414
|
);
|