@cardenelabs/cdl 0.50.0 → 0.51.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,73 @@ 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 \u6700\u5F8C\u306E\u5411\u304D(d) {
10425
+ const segs = extractPathSegments(d);
10426
+ const last = segs[segs.length - 1];
10427
+ if (!last) return null;
10428
+ const end = { x: last.x2, y: last.y2 };
10429
+ for (let i = segs.length - 1; i >= 0; i--) {
10430
+ const s = segs[i];
10431
+ const \u5236\u5FA1\u70B9 = s.cmd === "Q" ? s.ctrl?.[0] : s.cmd === "C" ? s.ctrl?.[1] : void 0;
10432
+ for (const p of [\u5236\u5FA1\u70B9, { x: s.x1, y: s.y1 }]) {
10433
+ if (!p) continue;
10434
+ const dx = end.x - p.x;
10435
+ const dy = end.y - p.y;
10436
+ const len = Math.hypot(dx, dy);
10437
+ if (len > 1e-6) return { end, ux: dx / len, uy: dy / len };
10438
+ }
10439
+ }
10440
+ return null;
10441
+ }
10442
+ function \u7AEF\u306E\u5B57\u3092\u7F6E\u304F(edge) {
10443
+ const text = edge.headLabel?.trim();
10444
+ if (!text) return null;
10445
+ const \u5411\u304D = \u6700\u5F8C\u306E\u5411\u304D(edge.d);
10446
+ if (!\u5411\u304D) return null;
10447
+ const { end, ux, uy } = \u5411\u304D;
10448
+ const bx = end.x - ux * \u7AEF\u306E\u5B57\u3092\u623B\u3059\u8DDD\u96E2;
10449
+ const by = end.y - uy * \u7AEF\u306E\u5B57\u3092\u623B\u3059\u8DDD\u96E2;
10450
+ const w = measureTextWidth(text, {
10451
+ fontSize: \u7AEF\u306E\u5B57\u306E\u5927\u304D\u3055,
10452
+ fontWeight: EDGE_LABEL_TEXT.sub.fontWeight,
10453
+ fontFamily: "mono"
10454
+ });
10455
+ const h = \u7BB1\u306E\u9AD8\u30552;
10456
+ const \u672D = hasRenderedLabel(edge) && edge.labelX !== void 0 && edge.labelY !== void 0 ? { x: edge.labelX, y: edge.labelY } : null;
10457
+ let anchor;
10458
+ let box;
10459
+ if (Math.abs(ux) >= Math.abs(uy)) {
10460
+ const \u53F3\u3078\u9032\u3080 = ux > 0;
10461
+ const \u4E0A\u306B\u7F6E\u304F = \u672D !== null && \u672D.y > by;
10462
+ anchor = \u53F3\u3078\u9032\u3080 ? "end" : "start";
10463
+ box = {
10464
+ x: \u53F3\u3078\u9032\u3080 ? bx - w : bx,
10465
+ y: \u4E0A\u306B\u7F6E\u304F ? by - \u7AEF\u306E\u5B57\u3068\u7DDA\u306E\u9699\u9593 - h : by + \u7AEF\u306E\u5B57\u3068\u7DDA\u306E\u9699\u9593,
10466
+ w,
10467
+ h
10468
+ };
10469
+ } else {
10470
+ const \u4E0B\u3078\u9032\u3080 = uy > 0;
10471
+ const \u53F3\u306B\u7F6E\u304F = \u672D !== null && \u672D.x < bx;
10472
+ anchor = \u53F3\u306B\u7F6E\u304F ? "start" : "end";
10473
+ box = {
10474
+ x: \u53F3\u306B\u7F6E\u304F ? bx + \u7AEF\u306E\u5B57\u3068\u7DDA\u306E\u9699\u9593 : bx - \u7AEF\u306E\u5B57\u3068\u7DDA\u306E\u9699\u9593 - w,
10475
+ y: \u4E0B\u3078\u9032\u3080 ? by - h : by,
10476
+ w,
10477
+ h
10478
+ };
10479
+ }
10480
+ const x = anchor === "start" ? box.x : box.x + box.w;
10481
+ const y = box.y + (h - \u7AEF\u306E\u5B57\u306E\u5927\u304D\u3055) / 2 + \u7AEF\u306E\u5B57\u306E\u5927\u304D\u3055 * BASELINE_RATIO;
10482
+ return { x, y, anchor, box };
10483
+ }
10417
10484
  function defaultEdgeWidth(active) {
10418
10485
  return active ? 2.5 : 1.25;
10419
10486
  }
@@ -10676,6 +10743,33 @@ function CdlEdgeLabelView({
10676
10743
  }
10677
10744
  );
10678
10745
  }
10746
+ function CdlEdgeHeadLabelView({
10747
+ edge,
10748
+ active
10749
+ }) {
10750
+ const \u7F6E\u304D\u5834\u6240 = \u7AEF\u306E\u5B57\u3092\u7F6E\u304F(edge);
10751
+ if (!\u7F6E\u304D\u5834\u6240) return null;
10752
+ const color = edgeColor(edge);
10753
+ return /* @__PURE__ */ jsxRuntime.jsx(
10754
+ "text",
10755
+ {
10756
+ "data-cdl-role": "edge-end-label",
10757
+ "data-cdl-edge-end-label-for": edge.id,
10758
+ x: \u7F6E\u304D\u5834\u6240.x,
10759
+ y: \u7F6E\u304D\u5834\u6240.y,
10760
+ fontSize: \u7AEF\u306E\u5B57\u306E\u5927\u304D\u3055,
10761
+ fontWeight: EDGE_LABEL_TEXT.sub.fontWeight,
10762
+ textAnchor: \u7F6E\u304D\u5834\u6240.anchor,
10763
+ fill: active ? color : "var(--cdl-text-dim, #5a6270)",
10764
+ stroke: "var(--cdl-label-bg, #ffffff)",
10765
+ strokeWidth: 4,
10766
+ strokeLinejoin: "round",
10767
+ paintOrder: "stroke",
10768
+ style: { fontFamily: fontFamilyAttr("sub") },
10769
+ children: \u7B49\u5E45\u306E\u5B57(edge.headLabel, \u7AEF\u306E\u5B57\u306E\u5927\u304D\u3055)
10770
+ }
10771
+ );
10772
+ }
10679
10773
 
10680
10774
  // src/kinds/node-tone.ts
10681
10775
  function nodeAccent(node, fallback) {
@@ -18957,6 +19051,14 @@ function CdlStage({
18957
19051
  },
18958
19052
  `label-${edge.id}`
18959
19053
  )),
19054
+ laid.edges.filter((edge) => edge.headLabel && \u77E2\u5370\u306E\u51FA\u756A.\u51FA\u308B\u304B(edge.id)).map((edge) => /* @__PURE__ */ jsxRuntime.jsx(
19055
+ CdlEdgeHeadLabelView,
19056
+ {
19057
+ edge,
19058
+ active: activeSet.has(edge.id)
19059
+ },
19060
+ `head-label-${edge.id}`
19061
+ )),
18960
19062
  debug && /* @__PURE__ */ jsxRuntime.jsxs("g", { pointerEvents: "none", children: [
18961
19063
  laid.bboxes.map((bbox, idx) => {
18962
19064
  const color = bbox.kind === "node" ? "#3b82f6" : bbox.kind === "lane-label" ? "#a855f7" : bbox.kind === "edge-label" ? "#10b981" : "#f59e0b";