sfn-diagram 1.0.0 → 1.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/cli.js +48 -2
- package/dist/index.cjs +48 -2
- package/dist/index.js +48 -2
- package/dist/png.cjs +48 -2
- package/dist/png.js +48 -2
- package/package.json +7 -5
package/dist/cli.js
CHANGED
|
@@ -1346,6 +1346,53 @@ var DagreLayout = class {
|
|
|
1346
1346
|
}
|
|
1347
1347
|
};
|
|
1348
1348
|
//#endregion
|
|
1349
|
+
//#region src/utils/textMeasure.ts
|
|
1350
|
+
/**
|
|
1351
|
+
* Per-character text width estimation for proportional fonts.
|
|
1352
|
+
*
|
|
1353
|
+
* Tuned for Arial / Helvetica / system sans-serif — the default font
|
|
1354
|
+
* family used by both built-in themes. Characters are bucketed into
|
|
1355
|
+
* width classes based on measured glyph advance widths in Arial.
|
|
1356
|
+
* Unknown characters fall through to the NORMAL class (0.55).
|
|
1357
|
+
*/
|
|
1358
|
+
/** Narrow glyphs: i, l, 1, punctuation */
|
|
1359
|
+
const NARROW = .3;
|
|
1360
|
+
/** Medium-narrow glyphs: f, j, t, r, brackets */
|
|
1361
|
+
const MEDIUM_NARROW = .4;
|
|
1362
|
+
/** Most lowercase letters and digits */
|
|
1363
|
+
const NORMAL = .55;
|
|
1364
|
+
/** Most uppercase letters */
|
|
1365
|
+
const WIDE = .65;
|
|
1366
|
+
/** Extra-wide glyphs: M, W, m, w, @ */
|
|
1367
|
+
const EXTRA_WIDE = .78;
|
|
1368
|
+
/** Space character */
|
|
1369
|
+
const SPACE = .28;
|
|
1370
|
+
/** Lookup table: character → width multiplier relative to fontSize. */
|
|
1371
|
+
const CHAR_WIDTHS = {};
|
|
1372
|
+
for (const ch of "iIl1|!.:;,'\"") CHAR_WIDTHS[ch] = NARROW;
|
|
1373
|
+
for (const ch of "fjtr()[]{}/-") CHAR_WIDTHS[ch] = MEDIUM_NARROW;
|
|
1374
|
+
for (const ch of "mwMW@%") CHAR_WIDTHS[ch] = EXTRA_WIDE;
|
|
1375
|
+
for (let code = 65; code <= 90; code++) {
|
|
1376
|
+
const ch = String.fromCharCode(code);
|
|
1377
|
+
if (!(ch in CHAR_WIDTHS)) CHAR_WIDTHS[ch] = WIDE;
|
|
1378
|
+
}
|
|
1379
|
+
CHAR_WIDTHS[" "] = SPACE;
|
|
1380
|
+
/**
|
|
1381
|
+
* Estimate the rendered width of a string using per-character width classes.
|
|
1382
|
+
* More accurate than a flat per-character average because it accounts for the
|
|
1383
|
+
* significant width variance between narrow (i, l) and wide (M, W) glyphs
|
|
1384
|
+
* in proportional fonts.
|
|
1385
|
+
*
|
|
1386
|
+
* @param text - The string to measure
|
|
1387
|
+
* @param fontSize - Font size in pixels
|
|
1388
|
+
* @returns Estimated width in pixels
|
|
1389
|
+
*/
|
|
1390
|
+
function estimateTextWidth(text, fontSize) {
|
|
1391
|
+
let width = 0;
|
|
1392
|
+
for (let i = 0; i < text.length; i++) width += (CHAR_WIDTHS[text[i]] ?? NORMAL) * fontSize;
|
|
1393
|
+
return width;
|
|
1394
|
+
}
|
|
1395
|
+
//#endregion
|
|
1349
1396
|
//#region src/renderers/svgBuilder.ts
|
|
1350
1397
|
/**
|
|
1351
1398
|
* Escape a string for use as a double-quoted HTML attribute value.
|
|
@@ -1734,10 +1781,9 @@ var SvgRenderer = class {
|
|
|
1734
1781
|
*/
|
|
1735
1782
|
calculateLabelDimensions(label) {
|
|
1736
1783
|
const fontSize = this.theme.fontSize - 2;
|
|
1737
|
-
const avgCharWidth = fontSize * .6;
|
|
1738
1784
|
const padding = 8;
|
|
1739
1785
|
const verticalPadding = 4;
|
|
1740
|
-
const width = label
|
|
1786
|
+
const width = estimateTextWidth(label, fontSize) + padding * 2;
|
|
1741
1787
|
return {
|
|
1742
1788
|
height: fontSize + verticalPadding * 2,
|
|
1743
1789
|
width
|
package/dist/index.cjs
CHANGED
|
@@ -1161,6 +1161,53 @@ var DagreLayout = class {
|
|
|
1161
1161
|
}
|
|
1162
1162
|
};
|
|
1163
1163
|
//#endregion
|
|
1164
|
+
//#region src/utils/textMeasure.ts
|
|
1165
|
+
/**
|
|
1166
|
+
* Per-character text width estimation for proportional fonts.
|
|
1167
|
+
*
|
|
1168
|
+
* Tuned for Arial / Helvetica / system sans-serif — the default font
|
|
1169
|
+
* family used by both built-in themes. Characters are bucketed into
|
|
1170
|
+
* width classes based on measured glyph advance widths in Arial.
|
|
1171
|
+
* Unknown characters fall through to the NORMAL class (0.55).
|
|
1172
|
+
*/
|
|
1173
|
+
/** Narrow glyphs: i, l, 1, punctuation */
|
|
1174
|
+
const NARROW = .3;
|
|
1175
|
+
/** Medium-narrow glyphs: f, j, t, r, brackets */
|
|
1176
|
+
const MEDIUM_NARROW = .4;
|
|
1177
|
+
/** Most lowercase letters and digits */
|
|
1178
|
+
const NORMAL = .55;
|
|
1179
|
+
/** Most uppercase letters */
|
|
1180
|
+
const WIDE = .65;
|
|
1181
|
+
/** Extra-wide glyphs: M, W, m, w, @ */
|
|
1182
|
+
const EXTRA_WIDE = .78;
|
|
1183
|
+
/** Space character */
|
|
1184
|
+
const SPACE = .28;
|
|
1185
|
+
/** Lookup table: character → width multiplier relative to fontSize. */
|
|
1186
|
+
const CHAR_WIDTHS = {};
|
|
1187
|
+
for (const ch of "iIl1|!.:;,'\"") CHAR_WIDTHS[ch] = NARROW;
|
|
1188
|
+
for (const ch of "fjtr()[]{}/-") CHAR_WIDTHS[ch] = MEDIUM_NARROW;
|
|
1189
|
+
for (const ch of "mwMW@%") CHAR_WIDTHS[ch] = EXTRA_WIDE;
|
|
1190
|
+
for (let code = 65; code <= 90; code++) {
|
|
1191
|
+
const ch = String.fromCharCode(code);
|
|
1192
|
+
if (!(ch in CHAR_WIDTHS)) CHAR_WIDTHS[ch] = WIDE;
|
|
1193
|
+
}
|
|
1194
|
+
CHAR_WIDTHS[" "] = SPACE;
|
|
1195
|
+
/**
|
|
1196
|
+
* Estimate the rendered width of a string using per-character width classes.
|
|
1197
|
+
* More accurate than a flat per-character average because it accounts for the
|
|
1198
|
+
* significant width variance between narrow (i, l) and wide (M, W) glyphs
|
|
1199
|
+
* in proportional fonts.
|
|
1200
|
+
*
|
|
1201
|
+
* @param text - The string to measure
|
|
1202
|
+
* @param fontSize - Font size in pixels
|
|
1203
|
+
* @returns Estimated width in pixels
|
|
1204
|
+
*/
|
|
1205
|
+
function estimateTextWidth(text, fontSize) {
|
|
1206
|
+
let width = 0;
|
|
1207
|
+
for (let i = 0; i < text.length; i++) width += (CHAR_WIDTHS[text[i]] ?? NORMAL) * fontSize;
|
|
1208
|
+
return width;
|
|
1209
|
+
}
|
|
1210
|
+
//#endregion
|
|
1164
1211
|
//#region src/renderers/svgBuilder.ts
|
|
1165
1212
|
/**
|
|
1166
1213
|
* Escape a string for use as a double-quoted HTML attribute value.
|
|
@@ -1549,10 +1596,9 @@ var SvgRenderer = class {
|
|
|
1549
1596
|
*/
|
|
1550
1597
|
calculateLabelDimensions(label) {
|
|
1551
1598
|
const fontSize = this.theme.fontSize - 2;
|
|
1552
|
-
const avgCharWidth = fontSize * .6;
|
|
1553
1599
|
const padding = 8;
|
|
1554
1600
|
const verticalPadding = 4;
|
|
1555
|
-
const width = label
|
|
1601
|
+
const width = estimateTextWidth(label, fontSize) + padding * 2;
|
|
1556
1602
|
return {
|
|
1557
1603
|
height: fontSize + verticalPadding * 2,
|
|
1558
1604
|
width
|
package/dist/index.js
CHANGED
|
@@ -1137,6 +1137,53 @@ var DagreLayout = class {
|
|
|
1137
1137
|
}
|
|
1138
1138
|
};
|
|
1139
1139
|
//#endregion
|
|
1140
|
+
//#region src/utils/textMeasure.ts
|
|
1141
|
+
/**
|
|
1142
|
+
* Per-character text width estimation for proportional fonts.
|
|
1143
|
+
*
|
|
1144
|
+
* Tuned for Arial / Helvetica / system sans-serif — the default font
|
|
1145
|
+
* family used by both built-in themes. Characters are bucketed into
|
|
1146
|
+
* width classes based on measured glyph advance widths in Arial.
|
|
1147
|
+
* Unknown characters fall through to the NORMAL class (0.55).
|
|
1148
|
+
*/
|
|
1149
|
+
/** Narrow glyphs: i, l, 1, punctuation */
|
|
1150
|
+
const NARROW = .3;
|
|
1151
|
+
/** Medium-narrow glyphs: f, j, t, r, brackets */
|
|
1152
|
+
const MEDIUM_NARROW = .4;
|
|
1153
|
+
/** Most lowercase letters and digits */
|
|
1154
|
+
const NORMAL = .55;
|
|
1155
|
+
/** Most uppercase letters */
|
|
1156
|
+
const WIDE = .65;
|
|
1157
|
+
/** Extra-wide glyphs: M, W, m, w, @ */
|
|
1158
|
+
const EXTRA_WIDE = .78;
|
|
1159
|
+
/** Space character */
|
|
1160
|
+
const SPACE = .28;
|
|
1161
|
+
/** Lookup table: character → width multiplier relative to fontSize. */
|
|
1162
|
+
const CHAR_WIDTHS = {};
|
|
1163
|
+
for (const ch of "iIl1|!.:;,'\"") CHAR_WIDTHS[ch] = NARROW;
|
|
1164
|
+
for (const ch of "fjtr()[]{}/-") CHAR_WIDTHS[ch] = MEDIUM_NARROW;
|
|
1165
|
+
for (const ch of "mwMW@%") CHAR_WIDTHS[ch] = EXTRA_WIDE;
|
|
1166
|
+
for (let code = 65; code <= 90; code++) {
|
|
1167
|
+
const ch = String.fromCharCode(code);
|
|
1168
|
+
if (!(ch in CHAR_WIDTHS)) CHAR_WIDTHS[ch] = WIDE;
|
|
1169
|
+
}
|
|
1170
|
+
CHAR_WIDTHS[" "] = SPACE;
|
|
1171
|
+
/**
|
|
1172
|
+
* Estimate the rendered width of a string using per-character width classes.
|
|
1173
|
+
* More accurate than a flat per-character average because it accounts for the
|
|
1174
|
+
* significant width variance between narrow (i, l) and wide (M, W) glyphs
|
|
1175
|
+
* in proportional fonts.
|
|
1176
|
+
*
|
|
1177
|
+
* @param text - The string to measure
|
|
1178
|
+
* @param fontSize - Font size in pixels
|
|
1179
|
+
* @returns Estimated width in pixels
|
|
1180
|
+
*/
|
|
1181
|
+
function estimateTextWidth(text, fontSize) {
|
|
1182
|
+
let width = 0;
|
|
1183
|
+
for (let i = 0; i < text.length; i++) width += (CHAR_WIDTHS[text[i]] ?? NORMAL) * fontSize;
|
|
1184
|
+
return width;
|
|
1185
|
+
}
|
|
1186
|
+
//#endregion
|
|
1140
1187
|
//#region src/renderers/svgBuilder.ts
|
|
1141
1188
|
/**
|
|
1142
1189
|
* Escape a string for use as a double-quoted HTML attribute value.
|
|
@@ -1525,10 +1572,9 @@ var SvgRenderer = class {
|
|
|
1525
1572
|
*/
|
|
1526
1573
|
calculateLabelDimensions(label) {
|
|
1527
1574
|
const fontSize = this.theme.fontSize - 2;
|
|
1528
|
-
const avgCharWidth = fontSize * .6;
|
|
1529
1575
|
const padding = 8;
|
|
1530
1576
|
const verticalPadding = 4;
|
|
1531
|
-
const width = label
|
|
1577
|
+
const width = estimateTextWidth(label, fontSize) + padding * 2;
|
|
1532
1578
|
return {
|
|
1533
1579
|
height: fontSize + verticalPadding * 2,
|
|
1534
1580
|
width
|
package/dist/png.cjs
CHANGED
|
@@ -1161,6 +1161,53 @@ var DagreLayout = class {
|
|
|
1161
1161
|
}
|
|
1162
1162
|
};
|
|
1163
1163
|
//#endregion
|
|
1164
|
+
//#region src/utils/textMeasure.ts
|
|
1165
|
+
/**
|
|
1166
|
+
* Per-character text width estimation for proportional fonts.
|
|
1167
|
+
*
|
|
1168
|
+
* Tuned for Arial / Helvetica / system sans-serif — the default font
|
|
1169
|
+
* family used by both built-in themes. Characters are bucketed into
|
|
1170
|
+
* width classes based on measured glyph advance widths in Arial.
|
|
1171
|
+
* Unknown characters fall through to the NORMAL class (0.55).
|
|
1172
|
+
*/
|
|
1173
|
+
/** Narrow glyphs: i, l, 1, punctuation */
|
|
1174
|
+
const NARROW = .3;
|
|
1175
|
+
/** Medium-narrow glyphs: f, j, t, r, brackets */
|
|
1176
|
+
const MEDIUM_NARROW = .4;
|
|
1177
|
+
/** Most lowercase letters and digits */
|
|
1178
|
+
const NORMAL = .55;
|
|
1179
|
+
/** Most uppercase letters */
|
|
1180
|
+
const WIDE = .65;
|
|
1181
|
+
/** Extra-wide glyphs: M, W, m, w, @ */
|
|
1182
|
+
const EXTRA_WIDE = .78;
|
|
1183
|
+
/** Space character */
|
|
1184
|
+
const SPACE = .28;
|
|
1185
|
+
/** Lookup table: character → width multiplier relative to fontSize. */
|
|
1186
|
+
const CHAR_WIDTHS = {};
|
|
1187
|
+
for (const ch of "iIl1|!.:;,'\"") CHAR_WIDTHS[ch] = NARROW;
|
|
1188
|
+
for (const ch of "fjtr()[]{}/-") CHAR_WIDTHS[ch] = MEDIUM_NARROW;
|
|
1189
|
+
for (const ch of "mwMW@%") CHAR_WIDTHS[ch] = EXTRA_WIDE;
|
|
1190
|
+
for (let code = 65; code <= 90; code++) {
|
|
1191
|
+
const ch = String.fromCharCode(code);
|
|
1192
|
+
if (!(ch in CHAR_WIDTHS)) CHAR_WIDTHS[ch] = WIDE;
|
|
1193
|
+
}
|
|
1194
|
+
CHAR_WIDTHS[" "] = SPACE;
|
|
1195
|
+
/**
|
|
1196
|
+
* Estimate the rendered width of a string using per-character width classes.
|
|
1197
|
+
* More accurate than a flat per-character average because it accounts for the
|
|
1198
|
+
* significant width variance between narrow (i, l) and wide (M, W) glyphs
|
|
1199
|
+
* in proportional fonts.
|
|
1200
|
+
*
|
|
1201
|
+
* @param text - The string to measure
|
|
1202
|
+
* @param fontSize - Font size in pixels
|
|
1203
|
+
* @returns Estimated width in pixels
|
|
1204
|
+
*/
|
|
1205
|
+
function estimateTextWidth(text, fontSize) {
|
|
1206
|
+
let width = 0;
|
|
1207
|
+
for (let i = 0; i < text.length; i++) width += (CHAR_WIDTHS[text[i]] ?? NORMAL) * fontSize;
|
|
1208
|
+
return width;
|
|
1209
|
+
}
|
|
1210
|
+
//#endregion
|
|
1164
1211
|
//#region src/renderers/svgBuilder.ts
|
|
1165
1212
|
/**
|
|
1166
1213
|
* Escape a string for use as a double-quoted HTML attribute value.
|
|
@@ -1549,10 +1596,9 @@ var SvgRenderer = class {
|
|
|
1549
1596
|
*/
|
|
1550
1597
|
calculateLabelDimensions(label) {
|
|
1551
1598
|
const fontSize = this.theme.fontSize - 2;
|
|
1552
|
-
const avgCharWidth = fontSize * .6;
|
|
1553
1599
|
const padding = 8;
|
|
1554
1600
|
const verticalPadding = 4;
|
|
1555
|
-
const width = label
|
|
1601
|
+
const width = estimateTextWidth(label, fontSize) + padding * 2;
|
|
1556
1602
|
return {
|
|
1557
1603
|
height: fontSize + verticalPadding * 2,
|
|
1558
1604
|
width
|
package/dist/png.js
CHANGED
|
@@ -1137,6 +1137,53 @@ var DagreLayout = class {
|
|
|
1137
1137
|
}
|
|
1138
1138
|
};
|
|
1139
1139
|
//#endregion
|
|
1140
|
+
//#region src/utils/textMeasure.ts
|
|
1141
|
+
/**
|
|
1142
|
+
* Per-character text width estimation for proportional fonts.
|
|
1143
|
+
*
|
|
1144
|
+
* Tuned for Arial / Helvetica / system sans-serif — the default font
|
|
1145
|
+
* family used by both built-in themes. Characters are bucketed into
|
|
1146
|
+
* width classes based on measured glyph advance widths in Arial.
|
|
1147
|
+
* Unknown characters fall through to the NORMAL class (0.55).
|
|
1148
|
+
*/
|
|
1149
|
+
/** Narrow glyphs: i, l, 1, punctuation */
|
|
1150
|
+
const NARROW = .3;
|
|
1151
|
+
/** Medium-narrow glyphs: f, j, t, r, brackets */
|
|
1152
|
+
const MEDIUM_NARROW = .4;
|
|
1153
|
+
/** Most lowercase letters and digits */
|
|
1154
|
+
const NORMAL = .55;
|
|
1155
|
+
/** Most uppercase letters */
|
|
1156
|
+
const WIDE = .65;
|
|
1157
|
+
/** Extra-wide glyphs: M, W, m, w, @ */
|
|
1158
|
+
const EXTRA_WIDE = .78;
|
|
1159
|
+
/** Space character */
|
|
1160
|
+
const SPACE = .28;
|
|
1161
|
+
/** Lookup table: character → width multiplier relative to fontSize. */
|
|
1162
|
+
const CHAR_WIDTHS = {};
|
|
1163
|
+
for (const ch of "iIl1|!.:;,'\"") CHAR_WIDTHS[ch] = NARROW;
|
|
1164
|
+
for (const ch of "fjtr()[]{}/-") CHAR_WIDTHS[ch] = MEDIUM_NARROW;
|
|
1165
|
+
for (const ch of "mwMW@%") CHAR_WIDTHS[ch] = EXTRA_WIDE;
|
|
1166
|
+
for (let code = 65; code <= 90; code++) {
|
|
1167
|
+
const ch = String.fromCharCode(code);
|
|
1168
|
+
if (!(ch in CHAR_WIDTHS)) CHAR_WIDTHS[ch] = WIDE;
|
|
1169
|
+
}
|
|
1170
|
+
CHAR_WIDTHS[" "] = SPACE;
|
|
1171
|
+
/**
|
|
1172
|
+
* Estimate the rendered width of a string using per-character width classes.
|
|
1173
|
+
* More accurate than a flat per-character average because it accounts for the
|
|
1174
|
+
* significant width variance between narrow (i, l) and wide (M, W) glyphs
|
|
1175
|
+
* in proportional fonts.
|
|
1176
|
+
*
|
|
1177
|
+
* @param text - The string to measure
|
|
1178
|
+
* @param fontSize - Font size in pixels
|
|
1179
|
+
* @returns Estimated width in pixels
|
|
1180
|
+
*/
|
|
1181
|
+
function estimateTextWidth(text, fontSize) {
|
|
1182
|
+
let width = 0;
|
|
1183
|
+
for (let i = 0; i < text.length; i++) width += (CHAR_WIDTHS[text[i]] ?? NORMAL) * fontSize;
|
|
1184
|
+
return width;
|
|
1185
|
+
}
|
|
1186
|
+
//#endregion
|
|
1140
1187
|
//#region src/renderers/svgBuilder.ts
|
|
1141
1188
|
/**
|
|
1142
1189
|
* Escape a string for use as a double-quoted HTML attribute value.
|
|
@@ -1525,10 +1572,9 @@ var SvgRenderer = class {
|
|
|
1525
1572
|
*/
|
|
1526
1573
|
calculateLabelDimensions(label) {
|
|
1527
1574
|
const fontSize = this.theme.fontSize - 2;
|
|
1528
|
-
const avgCharWidth = fontSize * .6;
|
|
1529
1575
|
const padding = 8;
|
|
1530
1576
|
const verticalPadding = 4;
|
|
1531
|
-
const width = label
|
|
1577
|
+
const width = estimateTextWidth(label, fontSize) + padding * 2;
|
|
1532
1578
|
return {
|
|
1533
1579
|
height: fontSize + verticalPadding * 2,
|
|
1534
1580
|
width
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sfn-diagram",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "Generate SVG, Mermaid, HTML, and PNG diagrams from AWS Step Functions ASL definitions, CloudFormation/CDK templates, or live AWS state machines",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"packageManager": "pnpm@9.15.9",
|
|
@@ -153,20 +153,22 @@
|
|
|
153
153
|
"pnpm": {
|
|
154
154
|
"overrides": {
|
|
155
155
|
"basic-ftp": ">=5.3.1",
|
|
156
|
-
"brace-expansion": ">=
|
|
156
|
+
"brace-expansion": ">=5.0.7",
|
|
157
157
|
"defu": ">=6.1.5",
|
|
158
|
-
"dompurify": ">=3.4.
|
|
158
|
+
"dompurify": ">=3.4.12",
|
|
159
159
|
"esbuild": ">=0.28.1",
|
|
160
|
+
"fast-uri": ">=3.1.3 <4.0.0",
|
|
160
161
|
"fast-xml-builder": ">=1.1.7",
|
|
161
162
|
"fast-xml-parser": ">=5.7.0",
|
|
162
163
|
"flatted": ">=3.4.2",
|
|
163
164
|
"handlebars": ">=4.7.9",
|
|
164
165
|
"ip-address": ">=10.1.1",
|
|
165
|
-
"js-yaml": ">=4.
|
|
166
|
+
"js-yaml": ">=4.3.0 <5.0.0",
|
|
167
|
+
"linkify-it": ">=5.0.2 <6.0.0",
|
|
166
168
|
"lodash-es": ">=4.18.0",
|
|
167
169
|
"minimatch": ">=9.0.7",
|
|
168
170
|
"picomatch": ">=4.0.4",
|
|
169
|
-
"postcss": ">=8.5.
|
|
171
|
+
"postcss": ">=8.5.18 <9.0.0",
|
|
170
172
|
"rollup": ">=4.59.0",
|
|
171
173
|
"undici": ">=6.27.0",
|
|
172
174
|
"vite": ">=8.0.16",
|