@cardenelabs/cdl 0.78.0 → 0.80.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/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 points = extractPathPoints(e.d);
1383
- if (points.length === 0) continue;
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
- const tokens = d.replace(/[A-Za-z]/g, " ").trim().split(/[\s,]+/).filter(Boolean);
1404
- for (let i = 0; i + 1 < tokens.length; i += 2) {
1405
- const x = parseFloat(tokens[i]);
1406
- const y = parseFloat(tokens[i + 1]);
1407
- if (Number.isFinite(x) && Number.isFinite(y)) {
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 m;
1418
- while ((m = commandRegex.exec(d)) !== null) {
1419
- const cmd = m[1];
1420
- const argsStr = (m[2] ?? "").trim();
1421
- if (argsStr === "" || cmd === "Z" || cmd === "z") {
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 args = argsStr.split(/[\s,]+/).filter(Boolean).map(parseFloat);
1426
- const translated = [];
1427
- for (let i = 0; i + 1 < args.length; i += 2) {
1428
- const [nx, ny] = map(args[i], args[i + 1], idx);
1429
- translated.push(nx, ny);
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 + " " + translated.join(" ") + " ";
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
- let m;
1442
- while ((m = commandRegex.exec(d)) !== null) {
1443
- const cmd = m[1];
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
  }
@@ -19471,6 +19568,10 @@ function CdlNodeView({
19471
19568
  const offsetX = node.renderOffsetX !== void 0 ? resolveNumericAttr(node.renderOffsetX, stateValues, 0) : 0;
19472
19569
  const offsetY = node.renderOffsetY !== void 0 ? resolveNumericAttr(node.renderOffsetY, stateValues, 0) : 0;
19473
19570
  const hasOffset = offsetX !== 0 || offsetY !== 0;
19571
+ const \u7BB1\u306Estyle = {
19572
+ transition: "opacity 120ms ease-out, transform 200ms ease-out",
19573
+ ...\u95A2\u4FC2\u306E\u53D7\u3051\u53E3 === void 0 ? {} : { cursor: "pointer" }
19574
+ };
19474
19575
  return /* @__PURE__ */ jsxs(
19475
19576
  "g",
19476
19577
  {
@@ -19492,7 +19593,6 @@ function CdlNodeView({
19492
19593
  role: "button",
19493
19594
  tabIndex: 0,
19494
19595
  "aria-pressed": \u95A2\u4FC2\u306E\u53D7\u3051\u53E3.\u7126\u70B9 === node.id,
19495
- style: { cursor: "pointer" },
19496
19596
  onPointerEnter: () => \u95A2\u4FC2\u306E\u53D7\u3051\u53E3.\u89E6\u308C\u305F(node.id),
19497
19597
  onPointerLeave: () => \u95A2\u4FC2\u306E\u53D7\u3051\u53E3.\u96E2\u308C\u305F(),
19498
19598
  onFocus: () => \u95A2\u4FC2\u306E\u53D7\u3051\u53E3.\u89E6\u308C\u305F(node.id),
@@ -19507,7 +19607,7 @@ function CdlNodeView({
19507
19607
  transform: hasOffset ? `translate(${offsetX}, ${offsetY})` : void 0,
19508
19608
  opacity: boundOpacity,
19509
19609
  "data-cdl-tone": node.tone,
19510
- style: { transition: "opacity 120ms ease-out, transform 200ms ease-out" },
19610
+ style: \u7BB1\u306Estyle,
19511
19611
  children: [
19512
19612
  /* @__PURE__ */ jsx(
19513
19613
  "rect",