@cardenelabs/cdl 0.9.0 → 0.11.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.d.cts CHANGED
@@ -1,2 +1,2 @@
1
1
  import 'react';
2
- export { n as CdlDiagramView, j as CdlDiagramViewProps } from './render-hmFRAabt.cjs';
2
+ export { n as CdlDiagramView, j as CdlDiagramViewProps } from './render-DwH8v5Mb.cjs';
package/dist/react.d.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  import 'react';
2
- export { n as CdlDiagramView, j as CdlDiagramViewProps } from './render-hmFRAabt.js';
2
+ export { n as CdlDiagramView, j as CdlDiagramViewProps } from './render-DwH8v5Mb.js';
package/dist/react.js CHANGED
@@ -1,4 +1,4 @@
1
- import { useMemo, useEffect, useSyncExternalStore, useRef, useCallback, useState, useLayoutEffect } from 'react';
1
+ import { useMemo, useEffect, useSyncExternalStore, useRef, useCallback, useState, useLayoutEffect, useId } from 'react';
2
2
  import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
3
3
 
4
4
  // src/render.tsx
@@ -4884,6 +4884,7 @@ function nodeTemplateTexts(node) {
4884
4884
 
4885
4885
  // src/validate.ts
4886
4886
  var TONES2 = new Set(TONES);
4887
+ var DRAW_KINDS = /* @__PURE__ */ new Set(["chart-line", "chart-bar", "chart-pie"]);
4887
4888
  var KINDS = new Set(NODE_KINDS);
4888
4889
  var ENG_BANNED = /\b(FUNCTION|STORAGE|EVENT LOG|BALANCES MAPPING|READ|WRITE|EMIT|CALL)\b/;
4889
4890
  function validate(diag) {
@@ -4947,7 +4948,7 @@ function validate(diag) {
4947
4948
  ...(diag.formulas ?? []).map((f) => f.id),
4948
4949
  ...(diag.scrollTriggers ?? []).map((t) => t.id)
4949
4950
  ]);
4950
- const suggest = (target, candidates) => {
4951
+ const suggest = (target, candidates, candidateKind = "lane") => {
4951
4952
  const list = [...candidates];
4952
4953
  if (list.length === 0) return "";
4953
4954
  let best = "";
@@ -4959,7 +4960,7 @@ function validate(diag) {
4959
4960
  best = c;
4960
4961
  }
4961
4962
  }
4962
- return bestD <= 2 ? ` (\u3082\u3057\u304B\u3057\u3066 "${best}"?)` : ` (\u5B9A\u7FA9\u6E08 lane: ${list.slice(0, 5).join(", ")}${list.length > 5 ? "..." : ""})`;
4963
+ return bestD <= 2 ? ` (\u3082\u3057\u304B\u3057\u3066 "${best}"?)` : ` (\u5B9A\u7FA9\u6E08 ${candidateKind}: ${list.slice(0, 5).join(", ")}${list.length > 5 ? "..." : ""})`;
4963
4964
  };
4964
4965
  for (const n of diag.nodes) {
4965
4966
  if (!laneIds.has(n.lane)) {
@@ -4972,13 +4973,13 @@ function validate(diag) {
4972
4973
  for (const e of diag.edges) {
4973
4974
  if (!nodeIds.has(e.from)) {
4974
4975
  errors.push(
4975
- `[cdl] unknown-ref: edge "${e.id}" \u306E from "${e.from}" \u304C node \u306B\u5B58\u5728\u3057\u307E\u305B\u3093${suggest(e.from, nodeIds)}
4976
+ `[cdl] unknown-ref: edge "${e.id}" \u306E from "${e.from}" \u304C node \u306B\u5B58\u5728\u3057\u307E\u305B\u3093${suggest(e.from, nodeIds, "node")}
4976
4977
  \u2192 \u4FEE\u6B63\u4F8B: .node("${e.from}", { lane: "...", stack: 0, kind: "actor", title: "..." }) \u3092 edge \u5BA3\u8A00\u524D\u306B\u8FFD\u52A0`
4977
4978
  );
4978
4979
  }
4979
4980
  if (!nodeIds.has(e.to)) {
4980
4981
  errors.push(
4981
- `[cdl] unknown-ref: edge "${e.id}" \u306E to "${e.to}" \u304C node \u306B\u5B58\u5728\u3057\u307E\u305B\u3093${suggest(e.to, nodeIds)}
4982
+ `[cdl] unknown-ref: edge "${e.id}" \u306E to "${e.to}" \u304C node \u306B\u5B58\u5728\u3057\u307E\u305B\u3093${suggest(e.to, nodeIds, "node")}
4982
4983
  \u2192 \u4FEE\u6B63\u4F8B: .node("${e.to}", { lane: "...", stack: 0, kind: "...", title: "..." }) \u3092 edge \u5BA3\u8A00\u524D\u306B\u8FFD\u52A0`
4983
4984
  );
4984
4985
  }
@@ -4995,6 +4996,18 @@ function validate(diag) {
4995
4996
  errors.push(`[cdl] unknown-ref: phase "${p.id}" \u306E activate "${id}" \u306F node \u3067\u3082 edge \u3067\u3082\u306A\u3044 (typo \u306E\u53EF\u80FD\u6027)`);
4996
4997
  }
4997
4998
  }
4999
+ for (const id of p.draw ?? []) {
5000
+ if (!nodeIds.has(id)) {
5001
+ errors.push(`[cdl] unknown-ref: phase "${p.id}" \u306E draw "${id}" \u306F node \u3067\u306F\u306A\u3044 (typo \u306E\u53EF\u80FD\u6027)${suggest(id, nodeIds, "node")}`);
5002
+ continue;
5003
+ }
5004
+ const kind = diag.nodes.find((n) => n.id === id)?.kind;
5005
+ if (!DRAW_KINDS.has(String(kind))) {
5006
+ warnings.push(
5007
+ `phase "${p.id}" \u306E draw "${id}" \u306F kind "${kind}" \u3067\u3001 \u8D77\u70B9\u304B\u3089\u63CF\u304F\u52D5\u304D\u3092\u6301\u305F\u306A\u3044 (\u5BFE\u8C61\u306F ${[...DRAW_KINDS].join(" / ")})`
5008
+ );
5009
+ }
5010
+ }
4998
5011
  for (const t of p.tweens) {
4999
5012
  if (!stateIds.has(t.stateId)) {
5000
5013
  errors.push(`[cdl] unknown-ref: phase "${p.id}" tween \u5BFE\u8C61 state "${t.stateId}" \u672A\u5B9A\u7FA9`);
@@ -6572,7 +6585,9 @@ function resolveMindData(data, values) {
6572
6585
  function ChartLineNode({
6573
6586
  node,
6574
6587
  active,
6575
- stateValues = {}
6588
+ stateValues = {},
6589
+ drawing = false,
6590
+ progress = 1
6576
6591
  }) {
6577
6592
  const x0 = node.cx - node.w / 2;
6578
6593
  const y0 = node.cy - node.h / 2;
@@ -6593,6 +6608,24 @@ function ChartLineNode({
6593
6608
  const xAt = (idx) => PAD_LEFT + (data.length <= 1 ? canvasW / 2 : canvasW * idx / (data.length - 1));
6594
6609
  const yAt = (v) => plotTop + plotH - (v - vMin) / vRange * plotH;
6595
6610
  const points = data.map((d, idx) => `${xAt(idx)},${yAt(d.value)}`).join(" ");
6611
+ const \u70B9\u307E\u3067\u306E\u9577\u3055 = [];
6612
+ let \u7DDA\u306E\u5168\u9577 = 0;
6613
+ let \u524D\u306E\u70B9;
6614
+ for (const [idx, datum] of data.entries()) {
6615
+ const \u4ECA\u306E\u70B9 = { x: xAt(idx), y: yAt(datum.value) };
6616
+ if (\u524D\u306E\u70B9) {
6617
+ \u7DDA\u306E\u5168\u9577 += Math.hypot(\u4ECA\u306E\u70B9.x - \u524D\u306E\u70B9.x, \u4ECA\u306E\u70B9.y - \u524D\u306E\u70B9.y);
6618
+ }
6619
+ \u70B9\u307E\u3067\u306E\u9577\u3055.push(\u7DDA\u306E\u5168\u9577);
6620
+ \u524D\u306E\u70B9 = \u4ECA\u306E\u70B9;
6621
+ }
6622
+ const \u4F38\u3073 = drawing ? Math.min(1, Math.max(0, Number.isFinite(progress) ? progress : 1)) : 1;
6623
+ const \u7DDA\u306E\u5148\u304C\u5C4A\u3044\u305F = (idx) => {
6624
+ if (!drawing) return true;
6625
+ if (data.length <= 1) return true;
6626
+ if (\u7DDA\u306E\u5168\u9577 === 0) return true;
6627
+ return \u4F38\u3073 >= (\u70B9\u307E\u3067\u306E\u9577\u3055[idx] ?? 0) / \u7DDA\u306E\u5168\u9577;
6628
+ };
6596
6629
  const gridCount = 4;
6597
6630
  const gridTicks = Array.from({ length: gridCount + 1 }, (_, i) => {
6598
6631
  const v = vMin + vRange * i / gridCount;
@@ -6670,7 +6703,8 @@ function ChartLineNode({
6670
6703
  stroke: "var(--cdl-tone-accent, #2d6a8f)",
6671
6704
  strokeWidth: 2.5,
6672
6705
  strokeLinejoin: "round",
6673
- strokeLinecap: "round"
6706
+ strokeLinecap: "round",
6707
+ ...drawing ? { pathLength: 1, strokeDasharray: 1, strokeDashoffset: 1 - \u4F38\u3073 } : {}
6674
6708
  }
6675
6709
  ),
6676
6710
  data.map((d, idx) => {
@@ -6681,40 +6715,43 @@ function ChartLineNode({
6681
6715
  const isValley = (prev === void 0 || d.value <= prev) && (next === void 0 || d.value <= next);
6682
6716
  const labelAbove = !isValley;
6683
6717
  const labelY = labelAbove ? cy - 12 : cy + 18;
6718
+ const \u51FA\u3059 = \u7DDA\u306E\u5148\u304C\u5C4A\u3044\u305F(idx);
6684
6719
  return /* @__PURE__ */ jsxs("g", { "data-cdl-unresolved": d.unresolved ? "true" : void 0, children: [
6685
- /* @__PURE__ */ jsx(
6686
- "circle",
6687
- {
6688
- cx,
6689
- cy,
6690
- r: 5,
6691
- fill: "var(--cdl-node-fill, #ffffff)",
6692
- stroke: "var(--cdl-tone-accent, #2d6a8f)",
6693
- strokeWidth: 2.5
6694
- }
6695
- ),
6696
- /* @__PURE__ */ jsx(
6697
- "circle",
6698
- {
6699
- cx,
6700
- cy,
6701
- r: 2.5,
6702
- fill: "var(--cdl-tone-accent, #2d6a8f)"
6703
- }
6704
- ),
6705
- /* @__PURE__ */ jsx(
6706
- "text",
6707
- {
6708
- "data-cdl-role": "chart-line-value",
6709
- x: cx,
6710
- y: labelY,
6711
- fontSize: 11,
6712
- fontWeight: 600,
6713
- textAnchor: "middle",
6714
- fill: "var(--cdl-text, #1a1f2a)",
6715
- children: d.value.toLocaleString()
6716
- }
6717
- ),
6720
+ \u51FA\u3059 && /* @__PURE__ */ jsxs(Fragment, { children: [
6721
+ /* @__PURE__ */ jsx(
6722
+ "circle",
6723
+ {
6724
+ cx,
6725
+ cy,
6726
+ r: 5,
6727
+ fill: "var(--cdl-node-fill, #ffffff)",
6728
+ stroke: "var(--cdl-tone-accent, #2d6a8f)",
6729
+ strokeWidth: 2.5
6730
+ }
6731
+ ),
6732
+ /* @__PURE__ */ jsx(
6733
+ "circle",
6734
+ {
6735
+ cx,
6736
+ cy,
6737
+ r: 2.5,
6738
+ fill: "var(--cdl-tone-accent, #2d6a8f)"
6739
+ }
6740
+ ),
6741
+ /* @__PURE__ */ jsx(
6742
+ "text",
6743
+ {
6744
+ "data-cdl-role": "chart-line-value",
6745
+ x: cx,
6746
+ y: labelY,
6747
+ fontSize: 11,
6748
+ fontWeight: 600,
6749
+ textAnchor: "middle",
6750
+ fill: "var(--cdl-text, #1a1f2a)",
6751
+ children: d.value.toLocaleString()
6752
+ }
6753
+ )
6754
+ ] }),
6718
6755
  /* @__PURE__ */ jsx(
6719
6756
  "text",
6720
6757
  {
@@ -6733,8 +6770,11 @@ function ChartLineNode({
6733
6770
  function ChartPieNode({
6734
6771
  node,
6735
6772
  active,
6736
- stateValues = {}
6773
+ stateValues = {},
6774
+ drawing = false,
6775
+ progress = 1
6737
6776
  }) {
6777
+ const instanceId = useId().replace(/[^A-Za-z0-9_-]/g, "");
6738
6778
  const x0 = node.cx - node.w / 2;
6739
6779
  const y0 = node.cy - node.h / 2;
6740
6780
  const data = resolveChartData(node.chartData ?? [], stateValues);
@@ -6747,20 +6787,26 @@ function ChartPieNode({
6747
6787
  const cx = pieAreaW / 2;
6748
6788
  const cy = PAD_TOP + chartAreaH / 2;
6749
6789
  let cumAngle = -Math.PI / 2;
6790
+ let cumFrac = 0;
6750
6791
  const slices = data.map((d) => {
6751
6792
  const frac = d.value / total;
6752
6793
  const angle = frac * Math.PI * 2;
6753
6794
  const a0 = cumAngle;
6754
6795
  const a1 = cumAngle + angle;
6755
6796
  cumAngle = a1;
6797
+ const startFrac = cumFrac;
6798
+ cumFrac += frac;
6756
6799
  const x1 = cx + radius * Math.cos(a0);
6757
6800
  const y1 = cy + radius * Math.sin(a0);
6758
6801
  const x2 = cx + radius * Math.cos(a1);
6759
6802
  const y2 = cy + radius * Math.sin(a1);
6760
6803
  const large = angle > Math.PI ? 1 : 0;
6761
6804
  const path = `M ${cx} ${cy} L ${x1} ${y1} A ${radius} ${radius} 0 ${large} 1 ${x2} ${y2} Z`;
6762
- return { d, frac, path };
6805
+ return { d, frac, path, startFrac };
6763
6806
  });
6807
+ const \u958B\u304D = drawing ? Math.min(1, Math.max(0, Number.isFinite(progress) ? progress : 1)) : 1;
6808
+ const \u5207\u308A\u629C\u304Did = `cdl-pie-draw-${instanceId}`;
6809
+ const \u958B\u304D\u59CB\u3081\u305F = (startFrac) => !drawing || \u958B\u304D > startFrac;
6764
6810
  const legendX = pieAreaW + 8;
6765
6811
  const legendGap = Math.min(28, chartAreaH / Math.max(data.length, 1));
6766
6812
  const legendStartY = PAD_TOP + (chartAreaH - legendGap * data.length) / 2 + legendGap / 2;
@@ -6779,7 +6825,8 @@ function ChartPieNode({
6779
6825
  strokeWidth: active ? 3 : 1.25
6780
6826
  }
6781
6827
  ),
6782
- slices.map((s, idx) => /* @__PURE__ */ jsx(
6828
+ drawing && /* @__PURE__ */ jsx("defs", { children: /* @__PURE__ */ jsx("clipPath", { id: \u5207\u308A\u629C\u304Did, children: \u6247\u5F62\u306E\u5207\u308A\u629C\u304D(cx, cy, radius + 2, \u958B\u304D) }) }),
6829
+ /* @__PURE__ */ jsx("g", { ...drawing ? { clipPath: `url(#${\u5207\u308A\u629C\u304Did})` } : {}, children: slices.map((s, idx) => /* @__PURE__ */ jsx(
6783
6830
  "path",
6784
6831
  {
6785
6832
  "data-cdl-role": "chart-pie-slice",
@@ -6791,8 +6838,8 @@ function ChartPieNode({
6791
6838
  strokeWidth: 1.5
6792
6839
  },
6793
6840
  `slice-${idx}`
6794
- )),
6795
- slices.map((s, idx) => /* @__PURE__ */ jsxs("g", { transform: `translate(${legendX} ${legendStartY + idx * legendGap})`, children: [
6841
+ )) }),
6842
+ slices.map((s, idx) => !\u958B\u304D\u59CB\u3081\u305F(s.startFrac) ? null : /* @__PURE__ */ jsxs("g", { transform: `translate(${legendX} ${legendStartY + idx * legendGap})`, children: [
6796
6843
  /* @__PURE__ */ jsx(
6797
6844
  "rect",
6798
6845
  {
@@ -6830,6 +6877,15 @@ function ChartPieNode({
6830
6877
  ] }, `legend-${idx}`))
6831
6878
  ] });
6832
6879
  }
6880
+ function \u6247\u5F62\u306E\u5207\u308A\u629C\u304D(cx, cy, r, \u958B\u304D) {
6881
+ if (\u958B\u304D <= 0) return null;
6882
+ if (\u958B\u304D >= 1) return /* @__PURE__ */ jsx("circle", { cx, cy, r });
6883
+ const a0 = -Math.PI / 2;
6884
+ const a1 = a0 + \u958B\u304D * Math.PI * 2;
6885
+ const large = \u958B\u304D > 0.5 ? 1 : 0;
6886
+ const d = `M ${cx} ${cy} L ${cx + r * Math.cos(a0)} ${cy + r * Math.sin(a0)} A ${r} ${r} 0 ${large} 1 ${cx + r * Math.cos(a1)} ${cy + r * Math.sin(a1)} Z`;
6887
+ return /* @__PURE__ */ jsx("path", { d });
6888
+ }
6833
6889
  var FALLBACK_ORDER = ["accent", "teal", "warning", "success", "info", "error"];
6834
6890
  function sliceColor(tone, idx) {
6835
6891
  if (tone) return TONE[tone];
@@ -6838,7 +6894,9 @@ function sliceColor(tone, idx) {
6838
6894
  function ChartBarNode({
6839
6895
  node,
6840
6896
  active,
6841
- stateValues = {}
6897
+ stateValues = {},
6898
+ drawing = false,
6899
+ progress = 1
6842
6900
  }) {
6843
6901
  const x0 = node.cx - node.w / 2;
6844
6902
  const y0 = node.cy - node.h / 2;
@@ -6861,6 +6919,8 @@ function ChartBarNode({
6861
6919
  const v = vMax * i / gridCount;
6862
6920
  return { y: yAt(v), value: v };
6863
6921
  });
6922
+ const \u4F38\u3073 = drawing ? Math.min(1, Math.max(0, Number.isFinite(progress) ? progress : 1)) : 1;
6923
+ const \u6A2A\u8EF8\u306Ey = PAD_TOP + canvasH;
6864
6924
  return /* @__PURE__ */ jsxs("g", { transform: `translate(${x0} ${y0})`, children: [
6865
6925
  /* @__PURE__ */ jsx(
6866
6926
  "rect",
@@ -6917,26 +6977,28 @@ function ChartBarNode({
6917
6977
  const bx = xAt(idx);
6918
6978
  const by = yAt(d.value);
6919
6979
  const bh = PAD_TOP + canvasH - by;
6980
+ const \u898B\u3048\u3066\u3044\u308B\u982D = \u6A2A\u8EF8\u306Ey - (\u6A2A\u8EF8\u306Ey - by) * \u4F38\u3073;
6981
+ const \u68D2 = /* @__PURE__ */ jsx(
6982
+ "rect",
6983
+ {
6984
+ "data-cdl-role": "chart-bar",
6985
+ "data-cdl-unresolved": d.unresolved ? "true" : void 0,
6986
+ x: bx,
6987
+ y: by,
6988
+ width: barW,
6989
+ height: bh,
6990
+ rx: 2,
6991
+ fill: "var(--cdl-tone-accent, #2d6a8f)",
6992
+ fillOpacity: 0.9
6993
+ }
6994
+ );
6920
6995
  return /* @__PURE__ */ jsxs("g", { children: [
6921
- /* @__PURE__ */ jsx(
6922
- "rect",
6923
- {
6924
- "data-cdl-role": "chart-bar",
6925
- "data-cdl-unresolved": d.unresolved ? "true" : void 0,
6926
- x: bx,
6927
- y: by,
6928
- width: barW,
6929
- height: bh,
6930
- rx: 2,
6931
- fill: "var(--cdl-tone-accent, #2d6a8f)",
6932
- fillOpacity: 0.9
6933
- }
6934
- ),
6996
+ drawing ? /* @__PURE__ */ jsx("g", { transform: `translate(0 ${\u6A2A\u8EF8\u306Ey}) scale(1 ${\u4F38\u3073}) translate(0 ${-\u6A2A\u8EF8\u306Ey})`, children: \u68D2 }) : \u68D2,
6935
6997
  /* @__PURE__ */ jsx(
6936
6998
  "text",
6937
6999
  {
6938
7000
  x: bx + barW / 2,
6939
- y: by - 6,
7001
+ y: \u898B\u3048\u3066\u3044\u308B\u982D - 6,
6940
7002
  fontSize: 11,
6941
7003
  textAnchor: "middle",
6942
7004
  fill: "var(--cdl-text, #1a1f2a)",
@@ -12190,6 +12252,7 @@ function ShapeCustomerServiceNode({ node, active }) {
12190
12252
  function CdlNodeView({
12191
12253
  node,
12192
12254
  active,
12255
+ drawing = false,
12193
12256
  progress,
12194
12257
  stateValues,
12195
12258
  currentPhaseId
@@ -12239,11 +12302,38 @@ function CdlNodeView({
12239
12302
  // 数と語を取る 7 種に対し、mind-map / tree-hierarchy は **名前だけ** を取る (#467)。
12240
12303
  // 親子の繋がりと、描かれない欄 (補足) は解決しない。
12241
12304
  case "chart-line":
12242
- return /* @__PURE__ */ jsx(ChartLineNode, { node: resolvedNode, active, stateValues });
12305
+ return /* @__PURE__ */ jsx(
12306
+ ChartLineNode,
12307
+ {
12308
+ node: resolvedNode,
12309
+ active,
12310
+ stateValues,
12311
+ drawing,
12312
+ progress
12313
+ }
12314
+ );
12243
12315
  case "chart-pie":
12244
- return /* @__PURE__ */ jsx(ChartPieNode, { node: resolvedNode, active, stateValues });
12316
+ return /* @__PURE__ */ jsx(
12317
+ ChartPieNode,
12318
+ {
12319
+ node: resolvedNode,
12320
+ active,
12321
+ stateValues,
12322
+ drawing,
12323
+ progress
12324
+ }
12325
+ );
12245
12326
  case "chart-bar":
12246
- return /* @__PURE__ */ jsx(ChartBarNode, { node: resolvedNode, active, stateValues });
12327
+ return /* @__PURE__ */ jsx(
12328
+ ChartBarNode,
12329
+ {
12330
+ node: resolvedNode,
12331
+ active,
12332
+ stateValues,
12333
+ drawing,
12334
+ progress
12335
+ }
12336
+ );
12247
12337
  case "gantt-timeline":
12248
12338
  return /* @__PURE__ */ jsx(GanttNode, { node: resolvedNode, active, stateValues });
12249
12339
  case "mind-map":
@@ -12433,6 +12523,7 @@ function CdlStage({
12433
12523
  svgRef
12434
12524
  }) {
12435
12525
  const activeSet = new Set(currentPhase?.activate ?? []);
12526
+ const drawSet = new Set(currentPhase?.draw ?? []);
12436
12527
  const { lifelineStarts, uniformFooterTop } = useMemo(() => {
12437
12528
  const starts = lifelineStartYs(laid.nodes);
12438
12529
  return {
@@ -12569,6 +12660,7 @@ function CdlStage({
12569
12660
  {
12570
12661
  node,
12571
12662
  active: activeSet.has(node.id),
12663
+ drawing: drawSet.has(node.id),
12572
12664
  progress,
12573
12665
  stateValues,
12574
12666
  currentPhaseId: currentPhase?.id