@cardenelabs/cdl 0.78.0 → 0.79.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/CHANGELOG.md +30 -1
- package/dist/index.cjs +134 -37
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +134 -37
- package/dist/index.js.map +1 -1
- package/dist/react.cjs +134 -37
- package/dist/react.cjs.map +1 -1
- package/dist/react.js +134 -37
- package/dist/react.js.map +1 -1
- package/package.json +1 -1
- package/src/layout/collisions.ts +185 -41
package/dist/react.js
CHANGED
|
@@ -1379,72 +1379,169 @@ function collectBBoxes(lanes, nodes, edges) {
|
|
|
1379
1379
|
});
|
|
1380
1380
|
}
|
|
1381
1381
|
for (const e of edges) {
|
|
1382
|
-
const
|
|
1383
|
-
if (
|
|
1384
|
-
const xs = points.map((p) => p.x);
|
|
1385
|
-
const ys = points.map((p) => p.y);
|
|
1386
|
-
const minX = Math.min(...xs);
|
|
1387
|
-
const maxX = Math.max(...xs);
|
|
1388
|
-
const minY = Math.min(...ys);
|
|
1389
|
-
const maxY = Math.max(...ys);
|
|
1382
|
+
const box = pathBBox(e.d);
|
|
1383
|
+
if (!box) continue;
|
|
1390
1384
|
out.push({
|
|
1391
1385
|
kind: "edge-path",
|
|
1392
1386
|
id: e.id,
|
|
1393
|
-
x: minX - 2,
|
|
1394
|
-
y: minY - 2,
|
|
1395
|
-
w: maxX - minX + 4,
|
|
1396
|
-
h: maxY - minY + 4
|
|
1387
|
+
x: box.minX - 2,
|
|
1388
|
+
y: box.minY - 2,
|
|
1389
|
+
w: box.maxX - box.minX + 4,
|
|
1390
|
+
h: box.maxY - box.minY + 4
|
|
1397
1391
|
});
|
|
1398
1392
|
}
|
|
1399
1393
|
return out;
|
|
1400
1394
|
}
|
|
1395
|
+
var PATH_ARITY = {
|
|
1396
|
+
M: 2,
|
|
1397
|
+
L: 2,
|
|
1398
|
+
H: 1,
|
|
1399
|
+
V: 1,
|
|
1400
|
+
C: 6,
|
|
1401
|
+
S: 4,
|
|
1402
|
+
Q: 4,
|
|
1403
|
+
T: 2,
|
|
1404
|
+
A: 7,
|
|
1405
|
+
Z: 0
|
|
1406
|
+
};
|
|
1407
|
+
function isRelative(cmd) {
|
|
1408
|
+
return cmd >= "a" && cmd <= "z";
|
|
1409
|
+
}
|
|
1410
|
+
function coordSlots(cmd) {
|
|
1411
|
+
switch (cmd.toUpperCase()) {
|
|
1412
|
+
case "M":
|
|
1413
|
+
case "L":
|
|
1414
|
+
case "T":
|
|
1415
|
+
return [[0, 1]];
|
|
1416
|
+
case "H":
|
|
1417
|
+
return [[0, -1]];
|
|
1418
|
+
case "V":
|
|
1419
|
+
return [[-1, 0]];
|
|
1420
|
+
case "Q":
|
|
1421
|
+
case "S":
|
|
1422
|
+
return [[0, 1], [2, 3]];
|
|
1423
|
+
case "C":
|
|
1424
|
+
return [[0, 1], [2, 3], [4, 5]];
|
|
1425
|
+
case "A":
|
|
1426
|
+
return [[5, 6]];
|
|
1427
|
+
default:
|
|
1428
|
+
return [];
|
|
1429
|
+
}
|
|
1430
|
+
}
|
|
1431
|
+
function parsePathCommands(d) {
|
|
1432
|
+
const out = [];
|
|
1433
|
+
const commandRegex = /([MmLlHhVvCcSsQqTtAaZz])([^MmLlHhVvCcSsQqTtAaZz]*)/g;
|
|
1434
|
+
let m;
|
|
1435
|
+
while ((m = commandRegex.exec(d)) !== null) {
|
|
1436
|
+
const cmd = m[1];
|
|
1437
|
+
const arity = PATH_ARITY[cmd.toUpperCase()] ?? 0;
|
|
1438
|
+
if (arity === 0) {
|
|
1439
|
+
out.push({ cmd, args: [] });
|
|
1440
|
+
continue;
|
|
1441
|
+
}
|
|
1442
|
+
const nums = (m[2] ?? "").trim().split(/[\s,]+/).filter(Boolean).map(parseFloat);
|
|
1443
|
+
for (let i = 0; i + arity <= nums.length; i += arity) {
|
|
1444
|
+
const args = nums.slice(i, i + arity);
|
|
1445
|
+
if (!args.every(Number.isFinite)) break;
|
|
1446
|
+
const \u7E70\u308A\u8FD4\u3057 = i > 0;
|
|
1447
|
+
const c = \u7E70\u308A\u8FD4\u3057 && cmd === "M" ? "L" : \u7E70\u308A\u8FD4\u3057 && cmd === "m" ? "l" : cmd;
|
|
1448
|
+
out.push({ cmd: c, args });
|
|
1449
|
+
}
|
|
1450
|
+
}
|
|
1451
|
+
return out;
|
|
1452
|
+
}
|
|
1401
1453
|
function extractPathPoints(d) {
|
|
1402
1454
|
const out = [];
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
const
|
|
1407
|
-
|
|
1455
|
+
let cur = { x: 0, y: 0 };
|
|
1456
|
+
let started = false;
|
|
1457
|
+
for (const { cmd, args } of parsePathCommands(d)) {
|
|
1458
|
+
const \u76F8\u5BFE = started && isRelative(cmd);
|
|
1459
|
+
const \u57FA\u70B9 = cur;
|
|
1460
|
+
for (const [xi, yi] of coordSlots(cmd)) {
|
|
1461
|
+
const x = xi >= 0 ? \u76F8\u5BFE ? \u57FA\u70B9.x + args[xi] : args[xi] : \u57FA\u70B9.x;
|
|
1462
|
+
const y = yi >= 0 ? \u76F8\u5BFE ? \u57FA\u70B9.y + args[yi] : args[yi] : \u57FA\u70B9.y;
|
|
1408
1463
|
out.push({ x, y });
|
|
1464
|
+
cur = { x, y };
|
|
1409
1465
|
}
|
|
1466
|
+
started = true;
|
|
1410
1467
|
}
|
|
1411
1468
|
return out;
|
|
1412
1469
|
}
|
|
1470
|
+
function pathBBox(d) {
|
|
1471
|
+
let minX = Infinity;
|
|
1472
|
+
let minY = Infinity;
|
|
1473
|
+
let maxX = -Infinity;
|
|
1474
|
+
let maxY = -Infinity;
|
|
1475
|
+
let \u70B9\u3042\u308A = false;
|
|
1476
|
+
const \u53D6\u308B = (x, y) => {
|
|
1477
|
+
minX = Math.min(minX, x);
|
|
1478
|
+
minY = Math.min(minY, y);
|
|
1479
|
+
maxX = Math.max(maxX, x);
|
|
1480
|
+
maxY = Math.max(maxY, y);
|
|
1481
|
+
\u70B9\u3042\u308A = true;
|
|
1482
|
+
};
|
|
1483
|
+
let cur = { x: 0, y: 0 };
|
|
1484
|
+
let started = false;
|
|
1485
|
+
for (const { cmd, args } of parsePathCommands(d)) {
|
|
1486
|
+
const \u76F8\u5BFE = started && isRelative(cmd);
|
|
1487
|
+
const \u57FA\u70B9 = cur;
|
|
1488
|
+
for (const [xi, yi] of coordSlots(cmd)) {
|
|
1489
|
+
const x = xi >= 0 ? \u76F8\u5BFE ? \u57FA\u70B9.x + args[xi] : args[xi] : \u57FA\u70B9.x;
|
|
1490
|
+
const y = yi >= 0 ? \u76F8\u5BFE ? \u57FA\u70B9.y + args[yi] : args[yi] : \u57FA\u70B9.y;
|
|
1491
|
+
\u53D6\u308B(x, y);
|
|
1492
|
+
cur = { x, y };
|
|
1493
|
+
}
|
|
1494
|
+
if (cmd.toUpperCase() === "A") {
|
|
1495
|
+
const r = Math.max(Math.abs(args[0]), Math.abs(args[1]));
|
|
1496
|
+
const \u5F26 = Math.hypot(cur.x - \u57FA\u70B9.x, cur.y - \u57FA\u70B9.y);
|
|
1497
|
+
const \u534A\u5F26 = Math.min(\u5F26 / 2, r);
|
|
1498
|
+
const \u4F59 = Math.sqrt(Math.max(0, r * r - \u534A\u5F26 * \u534A\u5F26));
|
|
1499
|
+
const \u81A8\u3089\u307F = args[3] !== 0 ? r + \u4F59 : r - \u4F59;
|
|
1500
|
+
\u53D6\u308B(Math.min(\u57FA\u70B9.x, cur.x) - \u81A8\u3089\u307F, Math.min(\u57FA\u70B9.y, cur.y) - \u81A8\u3089\u307F);
|
|
1501
|
+
\u53D6\u308B(Math.max(\u57FA\u70B9.x, cur.x) + \u81A8\u3089\u307F, Math.max(\u57FA\u70B9.y, cur.y) + \u81A8\u3089\u307F);
|
|
1502
|
+
}
|
|
1503
|
+
started = true;
|
|
1504
|
+
}
|
|
1505
|
+
return \u70B9\u3042\u308A ? { minX, minY, maxX, maxY } : null;
|
|
1506
|
+
}
|
|
1413
1507
|
function rebuildPathD(d, map) {
|
|
1414
|
-
const commandRegex = /([MLCQZmlcqz])([^MLCQZmlcqz]*)/g;
|
|
1415
1508
|
let out = "";
|
|
1416
1509
|
let idx = 0;
|
|
1417
|
-
let
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
const
|
|
1421
|
-
if (
|
|
1510
|
+
let cur = { x: 0, y: 0 };
|
|
1511
|
+
let started = false;
|
|
1512
|
+
for (const { cmd, args } of parsePathCommands(d)) {
|
|
1513
|
+
const slots = coordSlots(cmd);
|
|
1514
|
+
if (slots.length === 0) {
|
|
1422
1515
|
out += cmd + " ";
|
|
1516
|
+
started = true;
|
|
1423
1517
|
continue;
|
|
1424
1518
|
}
|
|
1425
|
-
const
|
|
1426
|
-
const
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1519
|
+
const \u76F8\u5BFE = started && isRelative(cmd);
|
|
1520
|
+
const \u57FA\u70B9 = cur;
|
|
1521
|
+
const \u6B21\u306E\u5F15\u6570 = args.slice();
|
|
1522
|
+
for (const [xi, yi] of slots) {
|
|
1523
|
+
const x = xi >= 0 ? \u76F8\u5BFE ? \u57FA\u70B9.x + args[xi] : args[xi] : \u57FA\u70B9.x;
|
|
1524
|
+
const y = yi >= 0 ? \u76F8\u5BFE ? \u57FA\u70B9.y + args[yi] : args[yi] : \u57FA\u70B9.y;
|
|
1525
|
+
const [nx, ny] = map(x, y, idx);
|
|
1526
|
+
if (!\u76F8\u5BFE) {
|
|
1527
|
+
if (xi >= 0) \u6B21\u306E\u5F15\u6570[xi] = nx;
|
|
1528
|
+
if (yi >= 0) \u6B21\u306E\u5F15\u6570[yi] = ny;
|
|
1529
|
+
}
|
|
1430
1530
|
idx += 1;
|
|
1531
|
+
cur = { x, y };
|
|
1431
1532
|
}
|
|
1432
|
-
out += cmd + " " +
|
|
1533
|
+
out += cmd + " " + \u6B21\u306E\u5F15\u6570.join(" ") + " ";
|
|
1534
|
+
started = true;
|
|
1433
1535
|
}
|
|
1434
1536
|
return out.trim();
|
|
1435
1537
|
}
|
|
1436
1538
|
function cornerBoundaryIndices(d) {
|
|
1437
|
-
const commandRegex = /([MLCQZmlcqz])([^MLCQZmlcqz]*)/g;
|
|
1438
1539
|
let idx = 0;
|
|
1439
1540
|
let firstCornerEnd = -1;
|
|
1440
1541
|
let lastCornerStart = -1;
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
const argsStr = (m[2] ?? "").trim();
|
|
1445
|
-
if (argsStr === "" || cmd === "Z" || cmd === "z") continue;
|
|
1446
|
-
const pairs = argsStr.split(/[\s,]+/).filter(Boolean).length >> 1;
|
|
1447
|
-
if ((cmd === "Q" || cmd === "q") && pairs >= 2) {
|
|
1542
|
+
for (const { cmd } of parsePathCommands(d)) {
|
|
1543
|
+
const pairs = coordSlots(cmd).length;
|
|
1544
|
+
if (cmd.toUpperCase() === "Q" && pairs >= 2) {
|
|
1448
1545
|
if (firstCornerEnd < 0) firstCornerEnd = idx + 1;
|
|
1449
1546
|
lastCornerStart = idx;
|
|
1450
1547
|
}
|