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