@cardenelabs/cdl 0.50.0 → 0.52.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.cjs CHANGED
@@ -2776,10 +2776,10 @@ function \u66F8\u8A18\u7D20\u306B\u5206\u3051\u308B(text) {
2776
2776
  if (typeof \u533A\u5207\u308A !== "function") return [...text];
2777
2777
  return [...new \u533A\u5207\u308A(void 0, { granularity: "grapheme" }).segment(text)].map((g) => g.segment);
2778
2778
  }
2779
- function \u7BB1\u306B\u7A4D\u3080(\u884C, \u7BB1\u306E\u5E45, \u7BB1\u306E\u9AD8\u30552) {
2779
+ function \u7BB1\u306B\u7A4D\u3080(\u884C, \u7BB1\u306E\u5E45, \u7BB1\u306E\u9AD8\u30553) {
2780
2780
  const \u5019\u88DC = \u884C.filter((r, i) => i === 0 || r.text.trim() !== "");
2781
2781
  if (\u5019\u88DC.length === 0) return [];
2782
- const \u4F7F\u3048\u308B\u9AD8\u3055 = \u7BB1\u306E\u9AD8\u30552 - \u4E0A\u4E0B\u306E\u4F59\u767D * 2;
2782
+ const \u4F7F\u3048\u308B\u9AD8\u3055 = \u7BB1\u306E\u9AD8\u30553 - \u4E0A\u4E0B\u306E\u4F59\u767D * 2;
2783
2783
  const \u9AD8\u3055 = (rs) => rs.reduce((a, r) => a + r.fontSize * \u884C\u9001\u308A\u306E\u6BD4, 0);
2784
2784
  const \u6B8B\u3059 = [...\u5019\u88DC];
2785
2785
  while (\u6B8B\u3059.length > 1 && \u9AD8\u3055(\u6B8B\u3059) > \u4F7F\u3048\u308B\u9AD8\u3055) \u6B8B\u3059.pop();
@@ -3834,7 +3834,7 @@ function \u30D9\u30B8\u30A8\u306E\u7D2F\u7A4D\u5272\u5408(\u70B9, \u5236\u5FA1\u
3834
3834
  function \u7BB1\u306E\u6587\u5B57({
3835
3835
  \u884C,
3836
3836
  x,
3837
- \u7BB1\u306E\u9AD8\u3055: \u7BB1\u306E\u9AD8\u30552,
3837
+ \u7BB1\u306E\u9AD8\u3055: \u7BB1\u306E\u9AD8\u30553,
3838
3838
  fill,
3839
3839
  \u540D\u524D\u306E\u592A\u3055
3840
3840
  }) {
@@ -3843,7 +3843,7 @@ function \u7BB1\u306E\u6587\u5B57({
3843
3843
  {
3844
3844
  "data-cdl-role": r.\u5F79\u5272 === "subtitle" ? "tree-node-subtitle" : void 0,
3845
3845
  x,
3846
- y: \u7BB1\u306E\u9AD8\u30552 / 2 + r.dy,
3846
+ y: \u7BB1\u306E\u9AD8\u30553 / 2 + r.dy,
3847
3847
  fontSize: r.fontSize,
3848
3848
  fontWeight: r.\u5F79\u5272 === "title" ? \u540D\u524D\u306E\u592A\u3055 : 500,
3849
3849
  textAnchor: "middle",
@@ -10414,6 +10414,79 @@ function \u7B49\u5E45\u306E\u5B57(text, fontSize) {
10414
10414
  });
10415
10415
  return out;
10416
10416
  }
10417
+
10418
+ // src/layout/head-label.ts
10419
+ var \u7AEF\u306E\u5B57\u3092\u623B\u3059\u8DDD\u96E2 = 22;
10420
+ var \u7AEF\u306E\u5B57\u3068\u7DDA\u306E\u9699\u9593 = 8;
10421
+ var \u7AEF\u306E\u5B57\u306E\u5927\u304D\u3055 = EDGE_LABEL_TEXT.sub.fontSize;
10422
+ var \u7BB1\u306E\u9AD8\u30552 = Math.round(\u7AEF\u306E\u5B57\u306E\u5927\u304D\u3055 * 1.2);
10423
+ var BASELINE_RATIO = 0.8;
10424
+ function \u5411\u304D\u3092\u53D6\u308B(end, \u5019\u88DC) {
10425
+ for (const p of \u5019\u88DC) {
10426
+ if (!p) continue;
10427
+ const dx = end.x - p.x;
10428
+ const dy = end.y - p.y;
10429
+ const len = Math.hypot(dx, dy);
10430
+ if (len > 1e-6) return { end, ux: dx / len, uy: dy / len };
10431
+ }
10432
+ return null;
10433
+ }
10434
+ function \u7AEF\u3067\u306E\u5411\u304D(d, \u7AEF) {
10435
+ const segs = extractPathSegments(d);
10436
+ if (segs.length === 0) return null;
10437
+ if (\u7AEF === "head") {
10438
+ const last = segs[segs.length - 1];
10439
+ const end2 = { x: last.x2, y: last.y2 };
10440
+ const \u5019\u88DC2 = segs.slice().reverse().flatMap((s) => [s.cmd === "Q" ? s.ctrl?.[0] : s.cmd === "C" ? s.ctrl?.[1] : void 0, { x: s.x1, y: s.y1 }]);
10441
+ return \u5411\u304D\u3092\u53D6\u308B(end2, \u5019\u88DC2);
10442
+ }
10443
+ const first = segs[0];
10444
+ const end = { x: first.x1, y: first.y1 };
10445
+ const \u5019\u88DC = segs.flatMap((s) => [...s.ctrl ?? [], { x: s.x2, y: s.y2 }]);
10446
+ return \u5411\u304D\u3092\u53D6\u308B(end, \u5019\u88DC);
10447
+ }
10448
+ function \u7AEF\u306E\u5B57\u3092\u7F6E\u304F(edge, \u7AEF = "head") {
10449
+ const text = (\u7AEF === "head" ? edge.headLabel : edge.tailLabel)?.trim();
10450
+ if (!text) return null;
10451
+ const \u5411\u304D = \u7AEF\u3067\u306E\u5411\u304D(edge.d, \u7AEF);
10452
+ if (!\u5411\u304D) return null;
10453
+ const { end, ux, uy } = \u5411\u304D;
10454
+ const bx = end.x - ux * \u7AEF\u306E\u5B57\u3092\u623B\u3059\u8DDD\u96E2;
10455
+ const by = end.y - uy * \u7AEF\u306E\u5B57\u3092\u623B\u3059\u8DDD\u96E2;
10456
+ const w = measureTextWidth(text, {
10457
+ fontSize: \u7AEF\u306E\u5B57\u306E\u5927\u304D\u3055,
10458
+ fontWeight: EDGE_LABEL_TEXT.sub.fontWeight,
10459
+ fontFamily: "mono"
10460
+ });
10461
+ const h = \u7BB1\u306E\u9AD8\u30552;
10462
+ const \u672D = hasRenderedLabel(edge) && edge.labelX !== void 0 && edge.labelY !== void 0 ? { x: edge.labelX, y: edge.labelY } : null;
10463
+ let anchor;
10464
+ let box;
10465
+ if (Math.abs(ux) >= Math.abs(uy)) {
10466
+ const \u53F3\u3078\u9032\u3080 = ux > 0;
10467
+ const \u4E0A\u306B\u7F6E\u304F = \u672D !== null && \u672D.y > by;
10468
+ anchor = \u53F3\u3078\u9032\u3080 ? "end" : "start";
10469
+ box = {
10470
+ x: \u53F3\u3078\u9032\u3080 ? bx - w : bx,
10471
+ y: \u4E0A\u306B\u7F6E\u304F ? by - \u7AEF\u306E\u5B57\u3068\u7DDA\u306E\u9699\u9593 - h : by + \u7AEF\u306E\u5B57\u3068\u7DDA\u306E\u9699\u9593,
10472
+ w,
10473
+ h
10474
+ };
10475
+ } else {
10476
+ const \u4E0B\u3078\u9032\u3080 = uy > 0;
10477
+ const \u53F3\u306B\u7F6E\u304F = \u672D !== null && \u672D.x < bx;
10478
+ anchor = \u53F3\u306B\u7F6E\u304F ? "start" : "end";
10479
+ box = {
10480
+ x: \u53F3\u306B\u7F6E\u304F ? bx + \u7AEF\u306E\u5B57\u3068\u7DDA\u306E\u9699\u9593 : bx - \u7AEF\u306E\u5B57\u3068\u7DDA\u306E\u9699\u9593 - w,
10481
+ y: \u4E0B\u3078\u9032\u3080 ? by - h : by,
10482
+ w,
10483
+ h
10484
+ };
10485
+ }
10486
+ const x = anchor === "start" ? box.x : box.x + box.w;
10487
+ const y = box.y + (h - \u7AEF\u306E\u5B57\u306E\u5927\u304D\u3055) / 2 + \u7AEF\u306E\u5B57\u306E\u5927\u304D\u3055 * BASELINE_RATIO;
10488
+ return { x, y, anchor, box };
10489
+ }
10417
10490
  function defaultEdgeWidth(active) {
10418
10491
  return active ? 2.5 : 1.25;
10419
10492
  }
@@ -10676,6 +10749,35 @@ function CdlEdgeLabelView({
10676
10749
  }
10677
10750
  );
10678
10751
  }
10752
+ function CdlEdgeEndLabelView({
10753
+ edge,
10754
+ active,
10755
+ \u7AEF
10756
+ }) {
10757
+ const \u7F6E\u304D\u5834\u6240 = \u7AEF\u306E\u5B57\u3092\u7F6E\u304F(edge, \u7AEF);
10758
+ if (!\u7F6E\u304D\u5834\u6240) return null;
10759
+ const color = edgeColor(edge);
10760
+ return /* @__PURE__ */ jsxRuntime.jsx(
10761
+ "text",
10762
+ {
10763
+ "data-cdl-role": "edge-end-label",
10764
+ "data-cdl-edge-end-label-for": edge.id,
10765
+ "data-cdl-edge-end": \u7AEF,
10766
+ x: \u7F6E\u304D\u5834\u6240.x,
10767
+ y: \u7F6E\u304D\u5834\u6240.y,
10768
+ fontSize: \u7AEF\u306E\u5B57\u306E\u5927\u304D\u3055,
10769
+ fontWeight: EDGE_LABEL_TEXT.sub.fontWeight,
10770
+ textAnchor: \u7F6E\u304D\u5834\u6240.anchor,
10771
+ fill: active ? color : "var(--cdl-text-dim, #5a6270)",
10772
+ stroke: "var(--cdl-label-bg, #ffffff)",
10773
+ strokeWidth: 4,
10774
+ strokeLinejoin: "round",
10775
+ paintOrder: "stroke",
10776
+ style: { fontFamily: fontFamilyAttr("sub") },
10777
+ children: \u7B49\u5E45\u306E\u5B57(\u7AEF === "head" ? edge.headLabel : edge.tailLabel, \u7AEF\u306E\u5B57\u306E\u5927\u304D\u3055)
10778
+ }
10779
+ );
10780
+ }
10679
10781
 
10680
10782
  // src/kinds/node-tone.ts
10681
10783
  function nodeAccent(node, fallback) {
@@ -18957,6 +19059,17 @@ function CdlStage({
18957
19059
  },
18958
19060
  `label-${edge.id}`
18959
19061
  )),
19062
+ laid.edges.filter((edge) => (edge.headLabel || edge.tailLabel) && \u77E2\u5370\u306E\u51FA\u756A.\u51FA\u308B\u304B(edge.id)).flatMap(
19063
+ (edge) => ["head", "tail"].map((\u7AEF) => /* @__PURE__ */ jsxRuntime.jsx(
19064
+ CdlEdgeEndLabelView,
19065
+ {
19066
+ edge,
19067
+ active: activeSet.has(edge.id),
19068
+ \u7AEF
19069
+ },
19070
+ `${\u7AEF}-label-${edge.id}`
19071
+ ))
19072
+ ),
18960
19073
  debug && /* @__PURE__ */ jsxRuntime.jsxs("g", { pointerEvents: "none", children: [
18961
19074
  laid.bboxes.map((bbox, idx) => {
18962
19075
  const color = bbox.kind === "node" ? "#3b82f6" : bbox.kind === "lane-label" ? "#a855f7" : bbox.kind === "edge-label" ? "#10b981" : "#f59e0b";