@markdy/core 1.5.9 → 1.6.0
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 +239 -31
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -900,9 +900,9 @@ function computeNodeDimensions(decl, baseW = 180, baseH = 76) {
|
|
|
900
900
|
const numLines2 = Math.max(words.length > 0 ? 1 : 0, measureLabelLines(rawLabel, words, charsPerLine2));
|
|
901
901
|
const labelH2 = numLines2 * 16;
|
|
902
902
|
const techH2 = techLen > 0 ? 20 : 0;
|
|
903
|
-
const diamondContentH =
|
|
904
|
-
const neededH2 = Math.max(effectiveBaseH, Math.ceil(diamondContentH / 0.
|
|
905
|
-
const neededW = Math.max(effectiveBaseW, Math.ceil((targetTextW2 +
|
|
903
|
+
const diamondContentH = 28 + labelH2 + techH2;
|
|
904
|
+
const neededH2 = Math.max(effectiveBaseH, Math.ceil(diamondContentH / 0.52 / 8) * 8);
|
|
905
|
+
const neededW = Math.max(effectiveBaseW, Math.ceil((targetTextW2 + 44) / 0.5 / 8) * 8);
|
|
906
906
|
return {
|
|
907
907
|
width: typeof decl.props?.width === "number" ? Math.max(decl.props.width, neededW) : neededW,
|
|
908
908
|
height: typeof decl.props?.height === "number" ? Math.max(decl.props.height, neededH2) : neededH2
|
|
@@ -977,10 +977,8 @@ function nodeShape(kind, dtype, props) {
|
|
|
977
977
|
if (kind === "token_strip" || kind === "chips") return "pill";
|
|
978
978
|
if (kind === "surface" || kind === "stat" || kind === "matrix" || kind === "track" || kind === "glyph_card") return "rounded";
|
|
979
979
|
if (dtype === "constellation") return "rounded";
|
|
980
|
-
if (
|
|
981
|
-
|
|
982
|
-
if (kind === "decision" || kind === "condition") return "diamond";
|
|
983
|
-
}
|
|
980
|
+
if (kind === "start" || kind === "end") return "pill";
|
|
981
|
+
if (kind === "decision" || kind === "condition") return "diamond";
|
|
984
982
|
if (dtype === "state" && kind === "state") return "rounded";
|
|
985
983
|
if (kind === "user" || kind === "client") return "rounded";
|
|
986
984
|
return "card";
|
|
@@ -1047,11 +1045,22 @@ function assignRanks(nodeIds, edges, direction) {
|
|
|
1047
1045
|
const queue = nodeIds.filter((id) => indegree.get(id) === 0);
|
|
1048
1046
|
const processed = /* @__PURE__ */ new Set();
|
|
1049
1047
|
let cursor = 0;
|
|
1050
|
-
let cycleRoot = 0;
|
|
1051
1048
|
while (processed.size < nodeIds.length) {
|
|
1052
1049
|
if (cursor === queue.length) {
|
|
1053
|
-
|
|
1054
|
-
|
|
1050
|
+
let bestId = "";
|
|
1051
|
+
let bestRank = -1;
|
|
1052
|
+
let bestIndegree = Number.POSITIVE_INFINITY;
|
|
1053
|
+
for (const candidate of nodeIds) {
|
|
1054
|
+
if (processed.has(candidate)) continue;
|
|
1055
|
+
const r = ranks.get(candidate) ?? 0;
|
|
1056
|
+
const deg = indegree.get(candidate) ?? 0;
|
|
1057
|
+
if (r > bestRank || r === bestRank && deg < bestIndegree) {
|
|
1058
|
+
bestId = candidate;
|
|
1059
|
+
bestRank = r;
|
|
1060
|
+
bestIndegree = deg;
|
|
1061
|
+
}
|
|
1062
|
+
}
|
|
1063
|
+
if (bestId) queue.push(bestId);
|
|
1055
1064
|
}
|
|
1056
1065
|
const id = queue[cursor++];
|
|
1057
1066
|
if (processed.has(id)) continue;
|
|
@@ -1157,7 +1166,7 @@ function layoutRanked(ast, edges, opts) {
|
|
|
1157
1166
|
const isVertical = direction === "TB" || direction === "BT";
|
|
1158
1167
|
const hasTitle = Boolean(ast.meta.title && ast.meta.title.trim().length > 0);
|
|
1159
1168
|
const hasBeatCaptions = ast.beats.some((b) => b.label && b.label.trim().length > 0);
|
|
1160
|
-
const titleBand =
|
|
1169
|
+
const titleBand = effectiveTitleBand(ast);
|
|
1161
1170
|
const bottomBand = hasBeatCaptions ? 44 : 0;
|
|
1162
1171
|
const contentW = ast.meta.width - SAFE * 2;
|
|
1163
1172
|
const maxRank = Math.max(...byRank.keys(), 0);
|
|
@@ -1199,32 +1208,184 @@ function layoutRanked(ast, edges, opts) {
|
|
|
1199
1208
|
});
|
|
1200
1209
|
return nodes;
|
|
1201
1210
|
}
|
|
1211
|
+
function alignRankItems(items, minPos, maxPos, preferredStep, minGap) {
|
|
1212
|
+
const n = items.length;
|
|
1213
|
+
if (n === 0) return [];
|
|
1214
|
+
const anchors = items.map((item) => item.parentCenter ?? item.defaultCenter);
|
|
1215
|
+
const desiredCenters = new Array(n);
|
|
1216
|
+
let i = 0;
|
|
1217
|
+
while (i < n) {
|
|
1218
|
+
let j = i + 1;
|
|
1219
|
+
while (j < n && items[j].parentCenter !== null && items[i].parentCenter !== null && Math.abs(anchors[j] - anchors[i]) < 1) {
|
|
1220
|
+
j++;
|
|
1221
|
+
}
|
|
1222
|
+
const count = j - i;
|
|
1223
|
+
if (count === 1) {
|
|
1224
|
+
desiredCenters[i] = anchors[i];
|
|
1225
|
+
} else {
|
|
1226
|
+
const center = anchors[i];
|
|
1227
|
+
for (let k = 0; k < count; k++) {
|
|
1228
|
+
desiredCenters[i + k] = center + (k - (count - 1) / 2) * preferredStep;
|
|
1229
|
+
}
|
|
1230
|
+
}
|
|
1231
|
+
i = j;
|
|
1232
|
+
}
|
|
1233
|
+
const pairGap = (idxA, idxB) => {
|
|
1234
|
+
const gA = items[idxA].groupIdx;
|
|
1235
|
+
const gB = items[idxB].groupIdx;
|
|
1236
|
+
if (gA === gB) return minGap;
|
|
1237
|
+
return gA >= 0 && gB >= 0 ? minGap + GROUP_PAD * 2 + 12 : minGap + GROUP_PAD + 8;
|
|
1238
|
+
};
|
|
1239
|
+
const starts = desiredCenters.map((c, idx) => Math.max(minPos, Math.min(maxPos - items[idx].size, c - items[idx].size / 2)));
|
|
1240
|
+
for (let k = 1; k < n; k++) {
|
|
1241
|
+
const minNext = starts[k - 1] + items[k - 1].size + pairGap(k - 1, k);
|
|
1242
|
+
if (starts[k] < minNext) starts[k] = minNext;
|
|
1243
|
+
}
|
|
1244
|
+
const lastEnd = starts[n - 1] + items[n - 1].size;
|
|
1245
|
+
if (lastEnd > maxPos) {
|
|
1246
|
+
starts[n - 1] = Math.max(minPos, maxPos - items[n - 1].size);
|
|
1247
|
+
for (let k = n - 2; k >= 0; k--) {
|
|
1248
|
+
const maxPrev = starts[k + 1] - items[k].size - pairGap(k, k + 1);
|
|
1249
|
+
if (starts[k] > maxPrev) starts[k] = maxPrev;
|
|
1250
|
+
}
|
|
1251
|
+
}
|
|
1252
|
+
if (starts[0] < minPos) {
|
|
1253
|
+
const totalSizes = items.reduce((sum, item) => sum + item.size, 0);
|
|
1254
|
+
const availSpan = Math.max(totalSizes, maxPos - minPos);
|
|
1255
|
+
const actualGap = n > 1 ? Math.max(4, (availSpan - totalSizes) / (n - 1)) : 0;
|
|
1256
|
+
let cur = minPos;
|
|
1257
|
+
for (let k = 0; k < n; k++) {
|
|
1258
|
+
starts[k] = cur;
|
|
1259
|
+
cur += items[k].size + actualGap;
|
|
1260
|
+
}
|
|
1261
|
+
}
|
|
1262
|
+
return starts;
|
|
1263
|
+
}
|
|
1264
|
+
const placedCenter = /* @__PURE__ */ new Map();
|
|
1265
|
+
const separateGroupCollisions = (positioned) => {
|
|
1266
|
+
const groupList = Object.values(ast.groups);
|
|
1267
|
+
if (groupList.length < 2) return;
|
|
1268
|
+
const byId = new Map(positioned.map((n) => [n.id, n]));
|
|
1269
|
+
const boundsOf = (members) => {
|
|
1270
|
+
const rects = members.map((id) => byId.get(id)).filter((n) => Boolean(n));
|
|
1271
|
+
if (rects.length === 0) return null;
|
|
1272
|
+
return {
|
|
1273
|
+
x1: Math.min(...rects.map((n) => n.x)) - GROUP_PAD,
|
|
1274
|
+
y1: Math.min(...rects.map((n) => n.y)) - GROUP_PAD - 12,
|
|
1275
|
+
x2: Math.max(...rects.map((n) => n.x + n.width)) + GROUP_PAD,
|
|
1276
|
+
y2: Math.max(...rects.map((n) => n.y + n.height)) + GROUP_PAD,
|
|
1277
|
+
avgRank: rects.reduce((s, n) => s + (ranks.get(n.id) ?? 0), 0) / rects.length,
|
|
1278
|
+
nodes: rects
|
|
1279
|
+
};
|
|
1280
|
+
};
|
|
1281
|
+
for (let pass = 0; pass < groupList.length; pass++) {
|
|
1282
|
+
let moved = false;
|
|
1283
|
+
for (let aIdx = 0; aIdx < groupList.length; aIdx++) {
|
|
1284
|
+
for (let bIdx = aIdx + 1; bIdx < groupList.length; bIdx++) {
|
|
1285
|
+
const bA = boundsOf(groupList[aIdx].members);
|
|
1286
|
+
const bB = boundsOf(groupList[bIdx].members);
|
|
1287
|
+
if (!bA || !bB) continue;
|
|
1288
|
+
const overlapX = Math.min(bA.x2, bB.x2) - Math.max(bA.x1, bB.x1);
|
|
1289
|
+
const overlapY = Math.min(bA.y2, bB.y2) - Math.max(bA.y1, bB.y1);
|
|
1290
|
+
if (overlapX <= -12 || overlapY <= -12) continue;
|
|
1291
|
+
if (isVertical) {
|
|
1292
|
+
const [first, second] = bA.avgRank <= bB.avgRank ? [bA, bB] : [bB, bA];
|
|
1293
|
+
if (Math.abs(first.avgRank - second.avgRank) < 0.75) {
|
|
1294
|
+
const [leftG, rightG] = first.x1 + first.x2 <= second.x1 + second.x2 ? [first, second] : [second, first];
|
|
1295
|
+
const shift = Math.ceil(leftG.x2 - rightG.x1 + 20);
|
|
1296
|
+
if (shift > 0) {
|
|
1297
|
+
for (const n of rightG.nodes) n.x = snapGrid(n.x + shift);
|
|
1298
|
+
moved = true;
|
|
1299
|
+
}
|
|
1300
|
+
} else {
|
|
1301
|
+
const shift = Math.ceil(first.y2 - second.y1 + 20);
|
|
1302
|
+
if (shift > 0) {
|
|
1303
|
+
const minMoveRank = Math.min(...second.nodes.map((n) => ranks.get(n.id) ?? 0));
|
|
1304
|
+
for (const n of positioned) {
|
|
1305
|
+
if ((ranks.get(n.id) ?? 0) >= minMoveRank && !first.nodes.includes(n)) {
|
|
1306
|
+
n.y = snapGrid(n.y + shift);
|
|
1307
|
+
}
|
|
1308
|
+
}
|
|
1309
|
+
moved = true;
|
|
1310
|
+
}
|
|
1311
|
+
}
|
|
1312
|
+
} else {
|
|
1313
|
+
const [first, second] = bA.avgRank <= bB.avgRank ? [bA, bB] : [bB, bA];
|
|
1314
|
+
if (Math.abs(first.avgRank - second.avgRank) < 0.75) {
|
|
1315
|
+
const [topG, botG] = first.y1 + first.y2 <= second.y1 + second.y2 ? [first, second] : [second, first];
|
|
1316
|
+
const shift = Math.ceil(topG.y2 - botG.y1 + 20);
|
|
1317
|
+
if (shift > 0) {
|
|
1318
|
+
for (const n of botG.nodes) n.y = snapGrid(n.y + shift);
|
|
1319
|
+
moved = true;
|
|
1320
|
+
}
|
|
1321
|
+
} else {
|
|
1322
|
+
const shift = Math.ceil(first.x2 - second.x1 + 20);
|
|
1323
|
+
if (shift > 0) {
|
|
1324
|
+
const minMoveRank = Math.min(...second.nodes.map((n) => ranks.get(n.id) ?? 0));
|
|
1325
|
+
for (const n of positioned) {
|
|
1326
|
+
if ((ranks.get(n.id) ?? 0) >= minMoveRank && !first.nodes.includes(n)) {
|
|
1327
|
+
n.x = snapGrid(n.x + shift);
|
|
1328
|
+
}
|
|
1329
|
+
}
|
|
1330
|
+
moved = true;
|
|
1331
|
+
}
|
|
1332
|
+
}
|
|
1333
|
+
}
|
|
1334
|
+
}
|
|
1335
|
+
}
|
|
1336
|
+
if (!moved) break;
|
|
1337
|
+
}
|
|
1338
|
+
};
|
|
1202
1339
|
if (isVertical) {
|
|
1203
|
-
const
|
|
1340
|
+
const firstRankIds = byRank.get(sortedRanks[0] ?? 0) ?? [];
|
|
1341
|
+
const topGroupMargin2 = firstRankIds.some((id) => nodeGroupIndex.has(id)) ? GROUP_PAD + 14 : 0;
|
|
1342
|
+
const baseTopY = (hasTitle ? titleBand : SAFE) + topGroupMargin2;
|
|
1343
|
+
const contentH = Math.max(NODE_H, ast.meta.height - baseTopY - bottomBand - SAFE);
|
|
1204
1344
|
const maxNodeH = Math.max(...nodeIds.map((id) => nodeDims.get(id)?.height ?? NODE_H));
|
|
1205
1345
|
const rowGap = Math.max(maxNodeH + 40, Math.min(200, contentH / Math.max(rankCount, 1)));
|
|
1206
1346
|
const totalH = (rankCount - 1) * rowGap + maxNodeH;
|
|
1207
|
-
const startY =
|
|
1208
|
-
for (const
|
|
1347
|
+
const startY = baseTopY + Math.max(0, (contentH - totalH) / 2);
|
|
1348
|
+
for (const rank of sortedRanks) {
|
|
1349
|
+
const ids = byRank.get(rank) ?? [];
|
|
1209
1350
|
const rowCount = ids.length;
|
|
1210
1351
|
const maxRowW = Math.max(...ids.map((id) => nodeDims.get(id)?.width ?? NODE_W));
|
|
1211
1352
|
const colSpacing = Math.max(maxRowW + 36, Math.min(320, contentW / Math.max(rowCount, 1)));
|
|
1212
1353
|
const rankW = (rowCount - 1) * colSpacing + maxRowW;
|
|
1213
1354
|
const rankStartX = SAFE + Math.max(0, (contentW - rankW) / 2);
|
|
1214
1355
|
const y = startY + rank * rowGap;
|
|
1356
|
+
const xs = alignRankItems(
|
|
1357
|
+
ids.map((id, idx) => {
|
|
1358
|
+
const dims = nodeDims.get(id) ?? { width: NODE_W, height: NODE_H };
|
|
1359
|
+
const parents = (incomingParents.get(id) ?? []).filter((p) => placedCenter.has(p));
|
|
1360
|
+
const parentCenter = parents.length > 0 ? parents.reduce((sum, p) => sum + placedCenter.get(p).x, 0) / parents.length : null;
|
|
1361
|
+
return {
|
|
1362
|
+
id,
|
|
1363
|
+
size: dims.width,
|
|
1364
|
+
parentCenter,
|
|
1365
|
+
defaultCenter: rankStartX + idx * colSpacing + dims.width / 2,
|
|
1366
|
+
groupIdx: nodeGroupIndex.get(id) ?? -1
|
|
1367
|
+
};
|
|
1368
|
+
}),
|
|
1369
|
+
SAFE,
|
|
1370
|
+
SAFE + contentW,
|
|
1371
|
+
colSpacing,
|
|
1372
|
+
36
|
|
1373
|
+
);
|
|
1215
1374
|
ids.forEach((id, idx) => {
|
|
1216
1375
|
const decl = ast.nodes[id];
|
|
1217
1376
|
const role = nodeRole(decl.kind);
|
|
1218
1377
|
const dims = nodeDims.get(id) ?? { width: NODE_W, height: NODE_H };
|
|
1219
|
-
const x =
|
|
1378
|
+
const x = snapGrid(xs[idx]);
|
|
1379
|
+
const sy = snapGrid(y);
|
|
1220
1380
|
const focal = decl.props.focal === true || decl.props.accent === true;
|
|
1381
|
+
placedCenter.set(id, { x: x + dims.width / 2, y: sy + dims.height / 2 });
|
|
1221
1382
|
nodes.push({
|
|
1222
1383
|
id,
|
|
1223
1384
|
kind: decl.kind,
|
|
1224
1385
|
role,
|
|
1225
1386
|
label: decl.label,
|
|
1226
|
-
x
|
|
1227
|
-
y:
|
|
1387
|
+
x,
|
|
1388
|
+
y: sy,
|
|
1228
1389
|
width: dims.width,
|
|
1229
1390
|
height: dims.height,
|
|
1230
1391
|
style: resolveNodeStyle(decl, ast),
|
|
@@ -1235,6 +1396,7 @@ function layoutRanked(ast, edges, opts) {
|
|
|
1235
1396
|
});
|
|
1236
1397
|
});
|
|
1237
1398
|
}
|
|
1399
|
+
separateGroupCollisions(nodes);
|
|
1238
1400
|
return nodes;
|
|
1239
1401
|
}
|
|
1240
1402
|
const rankWidths = /* @__PURE__ */ new Map();
|
|
@@ -1243,35 +1405,65 @@ function layoutRanked(ast, edges, opts) {
|
|
|
1243
1405
|
rankWidths.set(rank, maxW);
|
|
1244
1406
|
}
|
|
1245
1407
|
const totalRankWidths = [...rankWidths.values()].reduce((a, b) => a + b, 0);
|
|
1246
|
-
const
|
|
1408
|
+
const hasHorizLabels = edges.some((e) => !e.selfLoop && e.label && e.label.trim().length > 0);
|
|
1409
|
+
const maxHorizLabelLen = hasHorizLabels ? Math.max(...edges.filter((e) => !e.selfLoop && e.label).map((e) => e.label.trim().length), 0) : 0;
|
|
1410
|
+
const minColGap = rankCount >= 3 && maxHorizLabelLen > 0 ? Math.max(88, Math.min(176, Math.ceil(maxHorizLabelLen * 6.8 + 54))) : 56;
|
|
1247
1411
|
const availableGapW = Math.max(0, contentW - totalRankWidths);
|
|
1248
1412
|
const colGap = rankCount > 1 ? Math.max(minColGap, Math.min(160, availableGapW / (rankCount - 1))) : 0;
|
|
1249
1413
|
const totalW = totalRankWidths + (rankCount - 1) * colGap;
|
|
1250
1414
|
const startX = SAFE + Math.max(0, (contentW - totalW) / 2);
|
|
1251
|
-
const
|
|
1415
|
+
const anyGrouped = Object.keys(ast.groups).length > 0;
|
|
1416
|
+
const topGroupMargin = hasTitle && anyGrouped ? GROUP_PAD + 10 : 0;
|
|
1417
|
+
const topBandH = titleBand + topGroupMargin;
|
|
1418
|
+
const availableH = Math.max(NODE_H, ast.meta.height - topBandH - bottomBand);
|
|
1419
|
+
const rankXMap = /* @__PURE__ */ new Map();
|
|
1252
1420
|
let currentRankX = startX;
|
|
1253
1421
|
for (let rank = 0; rank < rankCount; rank++) {
|
|
1422
|
+
rankXMap.set(rank, currentRankX);
|
|
1423
|
+
currentRankX += (rankWidths.get(rank) ?? NODE_W) + colGap;
|
|
1424
|
+
}
|
|
1425
|
+
for (const rank of sortedRanks) {
|
|
1254
1426
|
const ids = byRank.get(rank) ?? [];
|
|
1255
|
-
const
|
|
1427
|
+
const rankX = rankXMap.get(rank) ?? startX;
|
|
1256
1428
|
const rowCount = ids.length;
|
|
1257
1429
|
const maxH = Math.max(...ids.map((id) => nodeDims.get(id)?.height ?? NODE_H), NODE_H);
|
|
1258
1430
|
const maxPossibleRowStep = rowCount > 1 ? (availableH - maxH) / (rowCount - 1) : 0;
|
|
1259
1431
|
const rowSpacing = rowCount > 1 ? Math.min(180, Math.max(maxH + 28, maxPossibleRowStep)) : 0;
|
|
1260
1432
|
const colH = (rowCount - 1) * rowSpacing + maxH;
|
|
1261
|
-
const colStartY =
|
|
1433
|
+
const colStartY = topBandH + Math.max(0, (availableH - colH) / 2);
|
|
1434
|
+
const ys = alignRankItems(
|
|
1435
|
+
ids.map((id, idx) => {
|
|
1436
|
+
const dims = nodeDims.get(id) ?? { width: NODE_W, height: NODE_H };
|
|
1437
|
+
const parents = (incomingParents.get(id) ?? []).filter((p) => placedCenter.has(p));
|
|
1438
|
+
const parentCenter = parents.length > 0 ? parents.reduce((sum, p) => sum + placedCenter.get(p).y, 0) / parents.length : null;
|
|
1439
|
+
return {
|
|
1440
|
+
id,
|
|
1441
|
+
size: dims.height,
|
|
1442
|
+
parentCenter,
|
|
1443
|
+
defaultCenter: colStartY + idx * rowSpacing + dims.height / 2,
|
|
1444
|
+
groupIdx: nodeGroupIndex.get(id) ?? -1
|
|
1445
|
+
};
|
|
1446
|
+
}),
|
|
1447
|
+
topBandH,
|
|
1448
|
+
topBandH + availableH,
|
|
1449
|
+
rowSpacing > 0 ? rowSpacing : maxH + 28,
|
|
1450
|
+
28
|
|
1451
|
+
);
|
|
1262
1452
|
ids.forEach((id, idx) => {
|
|
1263
1453
|
const decl = ast.nodes[id];
|
|
1264
1454
|
const role = nodeRole(decl.kind);
|
|
1265
1455
|
const dims = nodeDims.get(id) ?? { width: NODE_W, height: NODE_H };
|
|
1266
|
-
const
|
|
1456
|
+
const sx = snapGrid(rankX);
|
|
1457
|
+
const y = snapGrid(ys[idx]);
|
|
1267
1458
|
const focal = decl.props.focal === true || decl.props.accent === true;
|
|
1459
|
+
placedCenter.set(id, { x: sx + dims.width / 2, y: y + dims.height / 2 });
|
|
1268
1460
|
nodes.push({
|
|
1269
1461
|
id,
|
|
1270
1462
|
kind: decl.kind,
|
|
1271
1463
|
role,
|
|
1272
1464
|
label: decl.label,
|
|
1273
|
-
x:
|
|
1274
|
-
y
|
|
1465
|
+
x: sx,
|
|
1466
|
+
y,
|
|
1275
1467
|
width: dims.width,
|
|
1276
1468
|
height: dims.height,
|
|
1277
1469
|
style: resolveNodeStyle(decl, ast),
|
|
@@ -1281,8 +1473,8 @@ function layoutRanked(ast, edges, opts) {
|
|
|
1281
1473
|
focal
|
|
1282
1474
|
});
|
|
1283
1475
|
});
|
|
1284
|
-
currentRankX += rankW + colGap;
|
|
1285
1476
|
}
|
|
1477
|
+
separateGroupCollisions(nodes);
|
|
1286
1478
|
return nodes;
|
|
1287
1479
|
}
|
|
1288
1480
|
function layoutTree(ast, edges) {
|
|
@@ -2811,24 +3003,30 @@ function computeAdaptiveDimensions(ast, edges) {
|
|
|
2811
3003
|
}
|
|
2812
3004
|
const rankCount = Math.max(...byRank.keys(), 0) + 1;
|
|
2813
3005
|
const maxInRank = Math.max(...[...byRank.values()].map((v) => v.length), 1);
|
|
2814
|
-
const groupPaddingBonus = groupCount > 0 ? GROUP_PAD * 2 : 0;
|
|
3006
|
+
const groupPaddingBonus = groupCount > 0 ? GROUP_PAD * Math.max(2, groupCount) : 0;
|
|
2815
3007
|
const maxRankW = maxNodeW;
|
|
2816
3008
|
const maxRankH = maxNodeH;
|
|
3009
|
+
const maxLabelLen = effectiveEdges.reduce(
|
|
3010
|
+
(max, e) => !e.selfLoop && e.label ? Math.max(max, e.label.trim().length) : max,
|
|
3011
|
+
0
|
|
3012
|
+
);
|
|
2817
3013
|
if (forceVertical) {
|
|
2818
|
-
const colSpacing = 44;
|
|
2819
|
-
const rowGap = 56;
|
|
3014
|
+
const colSpacing = groupCount >= 2 ? 72 : 44;
|
|
3015
|
+
const rowGap = maxLabelLen > 0 ? 68 : 56;
|
|
3016
|
+
const topGroupClearance = hasTitle && groupCount > 0 ? GROUP_PAD + 14 : 0;
|
|
2820
3017
|
const contentNeededW = maxInRank * maxRankW + Math.max(0, maxInRank - 1) * colSpacing + groupPaddingBonus;
|
|
2821
3018
|
const requiredW = SAFE * 2 + contentNeededW;
|
|
2822
3019
|
autoW = Math.max(480, Math.min(2400, Math.max(requiredW, titleW)));
|
|
2823
|
-
const contentNeededH = rankCount * maxRankH + Math.max(0, rankCount - 1) * rowGap + groupPaddingBonus;
|
|
3020
|
+
const contentNeededH = rankCount * maxRankH + Math.max(0, rankCount - 1) * rowGap + groupPaddingBonus + topGroupClearance;
|
|
2824
3021
|
const requiredH = SAFE * 2 + titleBand + bottomBand + contentNeededH;
|
|
2825
3022
|
autoH = Math.max(360, Math.min(3200, requiredH));
|
|
2826
3023
|
} else {
|
|
2827
|
-
const colGap = 56;
|
|
3024
|
+
const colGap = rankCount >= 3 && maxLabelLen > 0 ? Math.max(88, Math.min(176, Math.ceil(maxLabelLen * 6.8 + 54))) : 56;
|
|
2828
3025
|
const rowGap = 44;
|
|
2829
3026
|
const contentNeededW = rankCount * maxRankW + Math.max(0, rankCount - 1) * colGap + groupPaddingBonus;
|
|
2830
3027
|
const requiredW = SAFE * 2 + contentNeededW;
|
|
2831
|
-
const
|
|
3028
|
+
const topGroupClearance = hasTitle && groupCount > 0 ? GROUP_PAD + 10 : 0;
|
|
3029
|
+
const contentNeededH = maxInRank * maxRankH + Math.max(0, maxInRank - 1) * rowGap + groupPaddingBonus + topGroupClearance;
|
|
2832
3030
|
const requiredH = SAFE * 2 + titleBand + bottomBand + contentNeededH;
|
|
2833
3031
|
autoW = Math.max(480, Math.min(2560, Math.max(requiredW, titleW)));
|
|
2834
3032
|
autoH = Math.max(240, Math.min(1800, requiredH));
|
|
@@ -2848,6 +3046,16 @@ function compilePlan(ast, theme) {
|
|
|
2848
3046
|
}
|
|
2849
3047
|
const nodes = layoutNodes(ast, structuralEdges);
|
|
2850
3048
|
const groupBoundaries = computeGroupBoundaries(ast, nodes);
|
|
3049
|
+
if (nodes.length > 0) {
|
|
3050
|
+
const maxNodeRight = Math.max(...nodes.map((n) => n.x + n.width), ...groupBoundaries.map((g) => g.x + g.width));
|
|
3051
|
+
const maxNodeBottom = Math.max(...nodes.map((n) => n.y + n.height), ...groupBoundaries.map((g) => g.y + g.height));
|
|
3052
|
+
if (!ast.meta.explicitWidth && maxNodeRight + SAFE > ast.meta.width) {
|
|
3053
|
+
ast.meta.width = snapGrid(maxNodeRight + SAFE, 16);
|
|
3054
|
+
}
|
|
3055
|
+
if (!ast.meta.explicitHeight && maxNodeBottom + SAFE > ast.meta.height) {
|
|
3056
|
+
ast.meta.height = snapGrid(maxNodeBottom + SAFE, 16);
|
|
3057
|
+
}
|
|
3058
|
+
}
|
|
2851
3059
|
const treeEdges = structuralEdges.some((edge) => edge.structural) ? structuralEdges.filter((edge) => edge.structural) : structuralEdges;
|
|
2852
3060
|
const treeBuses = computeTreeBuses(ast, nodes, treeEdges);
|
|
2853
3061
|
const { cues, beats } = scheduleBeats(ast, structuralEdges);
|
package/package.json
CHANGED