@cardenelabs/cdl 0.46.0 → 0.48.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 +64 -1
- package/dist/index.cjs +135 -23
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +29 -3
- package/dist/index.d.ts +29 -3
- package/dist/index.js +133 -24
- package/dist/index.js.map +1 -1
- package/dist/react.cjs +131 -23
- 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 +131 -23
- package/dist/react.js.map +1 -1
- package/dist/{render-UGswDfAh.d.cts → render-C53-PeJZ.d.cts} +25 -1
- package/dist/{render-UGswDfAh.d.ts → render-C53-PeJZ.d.ts} +25 -1
- package/package.json +1 -1
- package/src/index.ts +6 -0
- package/src/layout/edges.ts +95 -23
- package/src/layout.ts +1 -0
- package/src/render/edges.tsx +19 -0
- package/src/render/nodes.tsx +40 -1
- package/src/render/relation-focus.ts +40 -0
- package/src/render/stage.tsx +55 -2
- package/src/types.ts +27 -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-C53-PeJZ.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-C53-PeJZ.js';
|
package/dist/react.js
CHANGED
|
@@ -2421,6 +2421,7 @@ var EDGE_HEADS = [
|
|
|
2421
2421
|
];
|
|
2422
2422
|
var EDGE_HEAD_FILL_DEFAULT = "solid";
|
|
2423
2423
|
var EDGE_HEAD_FILLS = ["solid", "hollow"];
|
|
2424
|
+
var RELATION_FOCUS_DEFAULT = "off";
|
|
2424
2425
|
var EDGE_REVEAL_DEFAULT = "phase";
|
|
2425
2426
|
|
|
2426
2427
|
// src/kinds/text-width.ts
|
|
@@ -8279,33 +8280,73 @@ function placeAvoidingSiblingPaths(args) {
|
|
|
8279
8280
|
}
|
|
8280
8281
|
};
|
|
8281
8282
|
consider([...wants]);
|
|
8283
|
+
const \u62BC\u3059\u91CF = (idx, side, pos) => {
|
|
8284
|
+
let \u8981\u308B = 0;
|
|
8285
|
+
for (const i of idx) {
|
|
8286
|
+
const box = boxes[i];
|
|
8287
|
+
const rect = { x: box.x, y: pos[i] - box.h / 2, w: box.w, h: box.h };
|
|
8288
|
+
for (const probe of probeSegs[i]) {
|
|
8289
|
+
if (measurePathLabelGapSegs(probe.segs, rect) >= CLEARANCE_PATH_LABEL) continue;
|
|
8290
|
+
let lo = Infinity;
|
|
8291
|
+
let hi = -Infinity;
|
|
8292
|
+
for (const seg of probe.segs) {
|
|
8293
|
+
const c = clipY(seg, box.x, box.x + box.w);
|
|
8294
|
+
if (!c) continue;
|
|
8295
|
+
lo = Math.min(lo, c.lo);
|
|
8296
|
+
hi = Math.max(hi, c.hi);
|
|
8297
|
+
}
|
|
8298
|
+
if (lo > hi) continue;
|
|
8299
|
+
const \u884C\u304D\u5148 = side === "above" ? lo - box.h / 2 - CLEARANCE_PATH_LABEL : hi + box.h / 2 + CLEARANCE_PATH_LABEL;
|
|
8300
|
+
\u8981\u308B = Math.max(\u8981\u308B, side === "above" ? pos[i] - \u884C\u304D\u5148 : \u884C\u304D\u5148 - pos[i]);
|
|
8301
|
+
}
|
|
8302
|
+
}
|
|
8303
|
+
return Math.max(0, \u8981\u308B);
|
|
8304
|
+
};
|
|
8282
8305
|
if (bands.some((b) => b !== null)) {
|
|
8283
8306
|
for (let split = 0; split <= order.length; split++) {
|
|
8284
8307
|
const above = order.slice(0, split);
|
|
8285
8308
|
const below = order.slice(split);
|
|
8286
|
-
const
|
|
8287
|
-
|
|
8288
|
-
[above, "above"],
|
|
8289
|
-
[below, "below"]
|
|
8290
|
-
]) {
|
|
8291
|
-
if (idx.length === 0) continue;
|
|
8292
|
-
const ys = spread(idx);
|
|
8293
|
-
let shift = 0;
|
|
8294
|
-
for (let k = 0; k < idx.length; k++) {
|
|
8295
|
-
const band = bands[idx[k]];
|
|
8296
|
-
if (!band) continue;
|
|
8297
|
-
shift = side === "above" ? Math.min(shift, band.lo - ys[k]) : Math.max(shift, band.hi - ys[k]);
|
|
8298
|
-
}
|
|
8299
|
-
for (let k = 0; k < idx.length; k++) out[idx[k]] = ys[k] + shift;
|
|
8300
|
-
}
|
|
8301
|
-
if (above.length > 0 && below.length > 0) {
|
|
8309
|
+
const \u9593\u3092\u7A7A\u3051\u308B = (out) => {
|
|
8310
|
+
if (above.length === 0 || below.length === 0) return;
|
|
8302
8311
|
const lastIdx = above[above.length - 1];
|
|
8303
8312
|
const firstIdx = below[0];
|
|
8304
8313
|
const need = (sizes[lastIdx] + sizes[firstIdx]) / 2 + CLEARANCE_LABEL_LABEL;
|
|
8305
8314
|
const deficit = need - (out[firstIdx] - out[lastIdx]);
|
|
8306
|
-
if (deficit > 0) for (const i of below) out[i]
|
|
8307
|
-
}
|
|
8308
|
-
|
|
8315
|
+
if (deficit > 0) for (const i of below) out[i] = out[i] + deficit;
|
|
8316
|
+
};
|
|
8317
|
+
const \u5E2F\u3092\u8D8A\u3048\u308B = () => {
|
|
8318
|
+
const out = new Array(members.length);
|
|
8319
|
+
for (const [idx, side] of [
|
|
8320
|
+
[above, "above"],
|
|
8321
|
+
[below, "below"]
|
|
8322
|
+
]) {
|
|
8323
|
+
if (idx.length === 0) continue;
|
|
8324
|
+
const ys = spread(idx);
|
|
8325
|
+
let shift = 0;
|
|
8326
|
+
for (let k = 0; k < idx.length; k++) {
|
|
8327
|
+
const band = bands[idx[k]];
|
|
8328
|
+
if (!band) continue;
|
|
8329
|
+
shift = side === "above" ? Math.min(shift, band.lo - ys[k]) : Math.max(shift, band.hi - ys[k]);
|
|
8330
|
+
}
|
|
8331
|
+
for (let k = 0; k < idx.length; k++) out[idx[k]] = ys[k] + shift;
|
|
8332
|
+
}
|
|
8333
|
+
\u9593\u3092\u7A7A\u3051\u308B(out);
|
|
8334
|
+
return out;
|
|
8335
|
+
};
|
|
8336
|
+
const \u62BC\u3057\u3066\u8D8A\u3048\u308B = () => {
|
|
8337
|
+
const out = \u5E2F\u3092\u8D8A\u3048\u308B();
|
|
8338
|
+
for (let round = 0; round < 4; round += 1) {
|
|
8339
|
+
const a = \u62BC\u3059\u91CF(above, "above", out);
|
|
8340
|
+
const b = \u62BC\u3059\u91CF(below, "below", out);
|
|
8341
|
+
if (a === 0 && b === 0) return out;
|
|
8342
|
+
for (const i of above) out[i] = out[i] - a;
|
|
8343
|
+
for (const i of below) out[i] = out[i] + b;
|
|
8344
|
+
}
|
|
8345
|
+
return \u62BC\u3059\u91CF(above, "above", out) === 0 && \u62BC\u3059\u91CF(below, "below", out) === 0 ? out : null;
|
|
8346
|
+
};
|
|
8347
|
+
consider(\u5E2F\u3092\u8D8A\u3048\u308B());
|
|
8348
|
+
const \u62BC\u3057\u305F = \u62BC\u3057\u3066\u8D8A\u3048\u308B();
|
|
8349
|
+
if (\u62BC\u3057\u305F) consider(\u62BC\u3057\u305F);
|
|
8309
8350
|
}
|
|
8310
8351
|
}
|
|
8311
8352
|
const plain = spread(all);
|
|
@@ -9425,6 +9466,7 @@ function layout(diag) {
|
|
|
9425
9466
|
...diag.derived ? { derived: diag.derived } : {},
|
|
9426
9467
|
// 矢印をいつ出すか (#582)。 描き手が読む欄なので、そのまま持ち越す
|
|
9427
9468
|
...diag.edgeReveal ? { edgeReveal: diag.edgeReveal } : {},
|
|
9469
|
+
...diag.relationFocus ? { relationFocus: diag.relationFocus } : {},
|
|
9428
9470
|
// どの配色で描くか (#1553)。 空文字は書かなかった扱いにする = 空の目印を出すと、
|
|
9429
9471
|
// 消費側の `[data-cdl-palette]` が配色を書いていない図にも当たる。
|
|
9430
9472
|
//
|
|
@@ -10298,7 +10340,8 @@ function CdlEdgeView({
|
|
|
10298
10340
|
active,
|
|
10299
10341
|
drawing,
|
|
10300
10342
|
progress,
|
|
10301
|
-
stateValues
|
|
10343
|
+
stateValues,
|
|
10344
|
+
flowing = false
|
|
10302
10345
|
}) {
|
|
10303
10346
|
const color = edgeColor(edge);
|
|
10304
10347
|
const marker = edgeHeadMarkerName(edge.tone, edge.head, !active, edge.headFill);
|
|
@@ -10316,6 +10359,7 @@ function CdlEdgeView({
|
|
|
10316
10359
|
"data-cdl-from": edge.from,
|
|
10317
10360
|
"data-cdl-to": edge.to,
|
|
10318
10361
|
"data-cdl-active": active ? "true" : "false",
|
|
10362
|
+
"data-cdl-flowing": flowing ? "true" : "false",
|
|
10319
10363
|
"data-cdl-drawing": drawing ? "true" : "false",
|
|
10320
10364
|
"data-cdl-path-d": edge.d,
|
|
10321
10365
|
"data-cdl-label-x": edge.labelX,
|
|
@@ -10368,7 +10412,11 @@ function CdlEdgeView({
|
|
|
10368
10412
|
strokeWidth: 14,
|
|
10369
10413
|
strokeLinecap: "round"
|
|
10370
10414
|
}
|
|
10371
|
-
)
|
|
10415
|
+
),
|
|
10416
|
+
flowing && !isDotted && /* @__PURE__ */ jsxs("g", { "data-cdl-role": "edge-flow", children: [
|
|
10417
|
+
/* @__PURE__ */ jsx("path", { id: glowPathId, d: edge.d, fill: "none", stroke: "none" }),
|
|
10418
|
+
/* @__PURE__ */ jsx(EdgeGlowCircles, { color, edgeId: edge.id })
|
|
10419
|
+
] })
|
|
10372
10420
|
]
|
|
10373
10421
|
}
|
|
10374
10422
|
);
|
|
@@ -18141,7 +18189,8 @@ function CdlNodeView({
|
|
|
18141
18189
|
progress,
|
|
18142
18190
|
stateValues,
|
|
18143
18191
|
currentPhaseId,
|
|
18144
|
-
chartLineScale
|
|
18192
|
+
chartLineScale,
|
|
18193
|
+
\u95A2\u4FC2\u306E\u53D7\u3051\u53E3
|
|
18145
18194
|
}) {
|
|
18146
18195
|
const value = node.value ? interpolate(node.value, stateValues) : void 0;
|
|
18147
18196
|
const rows = (node.rows ?? []).map((r) => interpolate(r, stateValues));
|
|
@@ -18463,6 +18512,23 @@ function CdlNodeView({
|
|
|
18463
18512
|
"data-cdl-eyebrow": resolvedNode.eyebrow ?? "",
|
|
18464
18513
|
"data-cdl-offset-x": offsetX || void 0,
|
|
18465
18514
|
"data-cdl-offset-y": offsetY || void 0,
|
|
18515
|
+
...\u95A2\u4FC2\u306E\u53D7\u3051\u53E3 === void 0 ? {} : {
|
|
18516
|
+
// 読み上げに「押せる」 ことを伝え、 tab でも辿れるようにする。
|
|
18517
|
+
role: "button",
|
|
18518
|
+
tabIndex: 0,
|
|
18519
|
+
"aria-pressed": \u95A2\u4FC2\u306E\u53D7\u3051\u53E3.\u7126\u70B9 === node.id,
|
|
18520
|
+
style: { cursor: "pointer" },
|
|
18521
|
+
onPointerEnter: () => \u95A2\u4FC2\u306E\u53D7\u3051\u53E3.\u89E6\u308C\u305F(node.id),
|
|
18522
|
+
onPointerLeave: () => \u95A2\u4FC2\u306E\u53D7\u3051\u53E3.\u96E2\u308C\u305F(),
|
|
18523
|
+
onFocus: () => \u95A2\u4FC2\u306E\u53D7\u3051\u53E3.\u89E6\u308C\u305F(node.id),
|
|
18524
|
+
onBlur: () => \u95A2\u4FC2\u306E\u53D7\u3051\u53E3.\u96E2\u308C\u305F(),
|
|
18525
|
+
onClick: () => \u95A2\u4FC2\u306E\u53D7\u3051\u53E3.\u62BC\u3057\u305F(node.id),
|
|
18526
|
+
onKeyDown: (e) => {
|
|
18527
|
+
if (e.key !== "Enter" && e.key !== " ") return;
|
|
18528
|
+
e.preventDefault();
|
|
18529
|
+
\u95A2\u4FC2\u306E\u53D7\u3051\u53E3.\u62BC\u3057\u305F(node.id);
|
|
18530
|
+
}
|
|
18531
|
+
},
|
|
18466
18532
|
transform: hasOffset ? `translate(${offsetX}, ${offsetY})` : void 0,
|
|
18467
18533
|
opacity: boundOpacity,
|
|
18468
18534
|
"data-cdl-tone": node.tone,
|
|
@@ -18486,6 +18552,18 @@ function CdlNodeView({
|
|
|
18486
18552
|
}
|
|
18487
18553
|
);
|
|
18488
18554
|
}
|
|
18555
|
+
|
|
18556
|
+
// src/render/relation-focus.ts
|
|
18557
|
+
function relatedFocusSet(edges, nodeId) {
|
|
18558
|
+
const \u96C6\u5408 = /* @__PURE__ */ new Set([nodeId]);
|
|
18559
|
+
for (const e of edges) {
|
|
18560
|
+
if (e.from !== nodeId && e.to !== nodeId) continue;
|
|
18561
|
+
\u96C6\u5408.add(e.id);
|
|
18562
|
+
\u96C6\u5408.add(e.from);
|
|
18563
|
+
\u96C6\u5408.add(e.to);
|
|
18564
|
+
}
|
|
18565
|
+
return \u96C6\u5408;
|
|
18566
|
+
}
|
|
18489
18567
|
function CdlStage({
|
|
18490
18568
|
laid,
|
|
18491
18569
|
currentPhase,
|
|
@@ -18496,7 +18574,35 @@ function CdlStage({
|
|
|
18496
18574
|
compact = false,
|
|
18497
18575
|
svgRef
|
|
18498
18576
|
}) {
|
|
18499
|
-
const
|
|
18577
|
+
const [\u7126\u70B9, set\u7126\u70B9] = useState(null);
|
|
18578
|
+
const \u95A2\u4FC2\u3092\u5149\u3089\u305B\u308B = (laid.relationFocus ?? RELATION_FOCUS_DEFAULT) === "hover";
|
|
18579
|
+
const \u52D5\u304D\u3092\u63A7\u3048\u308B = useReducedMotion();
|
|
18580
|
+
useEffect(() => {
|
|
18581
|
+
if (!\u95A2\u4FC2\u3092\u5149\u3089\u305B\u308B) set\u7126\u70B9(null);
|
|
18582
|
+
}, [\u95A2\u4FC2\u3092\u5149\u3089\u305B\u308B]);
|
|
18583
|
+
useEffect(() => {
|
|
18584
|
+
if (!\u95A2\u4FC2\u3092\u5149\u3089\u305B\u308B || \u7126\u70B9?.\u7559\u3081\u305F !== true) return;
|
|
18585
|
+
const \u62BC\u3057\u305F2 = (e) => {
|
|
18586
|
+
if (e.key === "Escape") set\u7126\u70B9(null);
|
|
18587
|
+
};
|
|
18588
|
+
window.addEventListener("keydown", \u62BC\u3057\u305F2);
|
|
18589
|
+
return () => window.removeEventListener("keydown", \u62BC\u3057\u305F2);
|
|
18590
|
+
}, [\u95A2\u4FC2\u3092\u5149\u3089\u305B\u308B, \u7126\u70B9?.\u7559\u3081\u305F]);
|
|
18591
|
+
const \u89E6\u308C\u305F = useCallback((id) => {
|
|
18592
|
+
set\u7126\u70B9((\u524D) => \u524D?.\u7559\u3081\u305F === true ? \u524D : { id, \u7559\u3081\u305F: false });
|
|
18593
|
+
}, []);
|
|
18594
|
+
const \u96E2\u308C\u305F = useCallback(() => {
|
|
18595
|
+
set\u7126\u70B9((\u524D) => \u524D?.\u7559\u3081\u305F === true ? \u524D : null);
|
|
18596
|
+
}, []);
|
|
18597
|
+
const \u62BC\u3057\u305F = useCallback((id) => {
|
|
18598
|
+
set\u7126\u70B9((\u524D) => \u524D?.id === id && \u524D.\u7559\u3081\u305F ? null : { id, \u7559\u3081\u305F: true });
|
|
18599
|
+
}, []);
|
|
18600
|
+
const \u7126\u70B9\u306E\u96C6\u5408 = useMemo(
|
|
18601
|
+
() => \u95A2\u4FC2\u3092\u5149\u3089\u305B\u308B && \u7126\u70B9 !== null ? relatedFocusSet(laid.edges, \u7126\u70B9.id) : null,
|
|
18602
|
+
[\u95A2\u4FC2\u3092\u5149\u3089\u305B\u308B, \u7126\u70B9, laid.edges]
|
|
18603
|
+
);
|
|
18604
|
+
const activeSet = \u7126\u70B9\u306E\u96C6\u5408 ?? new Set(currentPhase?.activate ?? []);
|
|
18605
|
+
const \u7BB1\u306E\u53D7\u3051\u53E3 = \u95A2\u4FC2\u3092\u5149\u3089\u305B\u308B ? { \u89E6\u308C\u305F, \u96E2\u308C\u305F, \u62BC\u3057\u305F, \u7126\u70B9: \u7126\u70B9?.id ?? null } : void 0;
|
|
18500
18606
|
const \u77E2\u5370\u306E\u51FA\u756A = useMemo(() => {
|
|
18501
18607
|
const \u521D\u51FA = /* @__PURE__ */ new Map();
|
|
18502
18608
|
laid.phases.forEach((p, i) => {
|
|
@@ -18727,6 +18833,7 @@ function CdlStage({
|
|
|
18727
18833
|
{
|
|
18728
18834
|
edge,
|
|
18729
18835
|
active: activeSet.has(edge.id),
|
|
18836
|
+
flowing: \u7126\u70B9\u306E\u96C6\u5408?.has(edge.id) === true && !\u52D5\u304D\u3092\u63A7\u3048\u308B,
|
|
18730
18837
|
drawing: \u77E2\u5370\u306E\u51FA\u756A.\u4F38\u3070\u3059\u304B(edge.id),
|
|
18731
18838
|
progress: \u77E2\u5370\u306E\u51FA\u756A.\u4F38\u3070\u3059\u304B(edge.id) ? \u63CF\u304F\u9032\u307F : progress,
|
|
18732
18839
|
stateValues
|
|
@@ -18740,6 +18847,7 @@ function CdlStage({
|
|
|
18740
18847
|
{
|
|
18741
18848
|
node,
|
|
18742
18849
|
active: activeSet.has(node.id),
|
|
18850
|
+
\u95A2\u4FC2\u306E\u53D7\u3051\u53E3: \u7BB1\u306E\u53D7\u3051\u53E3,
|
|
18743
18851
|
drawing: \u63CF\u304F,
|
|
18744
18852
|
progress: \u63CF\u304F ? \u63CF\u304F\u9032\u307F : progress,
|
|
18745
18853
|
stateValues,
|