@cardenelabs/cdl 0.62.0 → 0.64.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.
@@ -1086,7 +1086,10 @@ type CdlReadout = {
1086
1086
  id: string;
1087
1087
  kind: "badge";
1088
1088
  source: string;
1089
- /** color source (default source と同じ)、 別 signal で色を切替可能 */
1089
+ /**
1090
+ * 色を引く状態 (#861)。 書くと `map` をこの状態の値で引き、札の字は `source` の値のまま。
1091
+ * 書かなければ `source` の値で引く。 書いた状態が無い時は色を付けない (`source` に戻さない)
1092
+ */
1090
1093
  colorSource?: string;
1091
1094
  /** 値と色 mapping (例: [{value: 'ok', color: 'green'}])、 未指定なら brand 色 */
1092
1095
  map?: readonly {
@@ -1086,7 +1086,10 @@ type CdlReadout = {
1086
1086
  id: string;
1087
1087
  kind: "badge";
1088
1088
  source: string;
1089
- /** color source (default source と同じ)、 別 signal で色を切替可能 */
1089
+ /**
1090
+ * 色を引く状態 (#861)。 書くと `map` をこの状態の値で引き、札の字は `source` の値のまま。
1091
+ * 書かなければ `source` の値で引く。 書いた状態が無い時は色を付けない (`source` に戻さない)
1092
+ */
1090
1093
  colorSource?: string;
1091
1094
  /** 値と色 mapping (例: [{value: 'ok', color: 'green'}])、 未指定なら brand 色 */
1092
1095
  map?: readonly {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cardenelabs/cdl",
3
- "version": "0.62.0",
3
+ "version": "0.64.0",
4
4
  "description": "CDL (Chainome Diagram Language). Mermaid-like declarative DSL that compiles to animated SVG diagrams. Built for blockchain / Solidity flows, generic enough for sequence / flow / state / ER / topology diagrams.",
5
5
  "license": "MIT",
6
6
  "author": "cardene777",
@@ -57,6 +57,16 @@
57
57
  "node": ">=18"
58
58
  },
59
59
  "sideEffects": false,
60
+ "scripts": {
61
+ "build": "tsup",
62
+ "dev": "tsup --watch",
63
+ "typecheck": "tsc --noEmit",
64
+ "test": "cd ../.. && vitest run packages/cdl",
65
+ "lint": "tsc --noEmit",
66
+ "prepublishOnly": "pnpm run typecheck && pnpm run build",
67
+ "prepack": "node scripts/prepack-check.mjs",
68
+ "postpack": "node scripts/prepack-check.mjs"
69
+ },
60
70
  "peerDependencies": {
61
71
  "react": "^19.0.0",
62
72
  "react-dom": "^19.0.0"
@@ -68,12 +78,5 @@
68
78
  "typedoc": "^0.28.19",
69
79
  "typedoc-plugin-markdown": "^4.12.0",
70
80
  "typescript": "^5.8.0"
71
- },
72
- "scripts": {
73
- "build": "tsup",
74
- "dev": "tsup --watch",
75
- "typecheck": "tsc --noEmit",
76
- "test": "cd ../.. && vitest run packages/cdl",
77
- "lint": "tsc --noEmit"
78
81
  }
79
- }
82
+ }
package/src/presets.ts CHANGED
@@ -1030,7 +1030,9 @@ export type StateMachineBuilder = {
1030
1030
  export function stateMachine(preset: StateMachinePreset): StateMachineBuilder {
1031
1031
  const stateW = resolveStateW(preset.stateWidth, "stateMachine");
1032
1032
  const tone: Tone = preset.defaultTone ?? "accent";
1033
- const b = diagram(preset.id, { topic: preset.topic, type: "state" });
1033
+ // 図の型と最後の段の札は同じ綴り (#859)。 札を別の字にすると、消費側が型の一覧で引けない
1034
+ const diagramType = "state";
1035
+ const b = diagram(preset.id, { topic: preset.topic, type: diagramType });
1034
1036
 
1035
1037
  const phaseActivate: string[] = [];
1036
1038
  const stateOrder = new Map<string, number>();
@@ -1159,7 +1161,7 @@ export function stateMachine(preset: StateMachinePreset): StateMachineBuilder {
1159
1161
  b.phase(
1160
1162
  "fsm",
1161
1163
  { duration: 2400, title: preset.topic, body: "すべての状態と遷移を並べた姿。" },
1162
- (p) => p.activate(...phaseActivate).badge("fsm"),
1164
+ (p) => p.activate(...phaseActivate).badge(diagramType),
1163
1165
  );
1164
1166
  return b.build();
1165
1167
  },
@@ -1810,7 +1812,10 @@ export type MindMapBuilder = {
1810
1812
  export function mindMap(preset: MindMapPreset): MindMapBuilder {
1811
1813
  const canvasW = preset.branchWidth ? preset.branchWidth * 2 : 720;
1812
1814
  const canvasH = 480;
1813
- const b = diagram(preset.id, { topic: preset.topic, type: "mindmap" });
1815
+ // 型は他の組み立て関数と同じく短い名前 (`state` / `class` / `journey` と並ぶ `mind`)。
1816
+ // 最後の段の札も同じ綴り (#859)
1817
+ const diagramType = "mind";
1818
+ const b = diagram(preset.id, { topic: preset.topic, type: diagramType });
1814
1819
  const branches: MindBranch[] = [];
1815
1820
 
1816
1821
  const api: MindMapBuilder = {
@@ -1845,7 +1850,7 @@ export function mindMap(preset: MindMapPreset): MindMapBuilder {
1845
1850
  b.phase(
1846
1851
  "mindmap",
1847
1852
  { duration: 2400, title: preset.topic, body: "中心の主題から、すべての枝を放射状に広げた姿。" },
1848
- (p) => p.activate(nodeId).badge("mindmap"),
1853
+ (p) => p.activate(nodeId).badge(diagramType),
1849
1854
  );
1850
1855
  return b.build();
1851
1856
  },
@@ -2581,7 +2586,9 @@ export function stateMachine2(preset: StateMachine2Preset): StateMachine2Builder
2581
2586
  const stateW = resolveStateW(preset.stateWidth, "stateMachine2");
2582
2587
  const laneW = boxLaneW(stateW);
2583
2588
  const tone: Tone = preset.defaultTone ?? "accent";
2584
- const b = diagram(preset.id, { topic: preset.topic, type: "state" });
2589
+ // 入れ子を持つ状態の図も型は `state`。 最後の段の札も同じ綴りで、1 つ目の図との見分けは題が持つ (#859)
2590
+ const diagramType = "state";
2591
+ const b = diagram(preset.id, { topic: preset.topic, type: diagramType });
2585
2592
 
2586
2593
  const stateOrder = new Map<string, number>();
2587
2594
  const phaseActivate: string[] = [];
@@ -2645,7 +2652,7 @@ export function stateMachine2(preset: StateMachine2Preset): StateMachine2Builder
2645
2652
  title: preset.topic,
2646
2653
  body: "入れ子の状態と、入る時・出る時の処理を含めた、すべての状態と遷移。",
2647
2654
  },
2648
- (p) => p.activate(...phaseActivate).badge("statemachine2"),
2655
+ (p) => p.activate(...phaseActivate).badge(diagramType),
2649
2656
  );
2650
2657
  const d = b.build();
2651
2658
  // 入れ子の札に親の題を足す。 識別子 (`active`) を出すと、図のどこにも無い字になる
@@ -1280,15 +1280,15 @@ function ReadoutWidget({
1280
1280
  colors={readout.colors ?? ["#e0e6ef", "#2d6a8f"]}
1281
1281
  />
1282
1282
  );
1283
- case "badge":
1284
- return (
1285
- <BadgeReadout
1286
- id={readout.id}
1287
- label={label}
1288
- value={typeof rawValue === "string" ? rawValue : String(rawValue ?? "")}
1289
- map={readout.map}
1290
- />
1291
- );
1283
+ case "badge": {
1284
+ const value = typeof rawValue === "string" ? rawValue : String(rawValue ?? "");
1285
+ // 色を引く鍵は `colorSource` を書けばその状態の値、書かなければ札の字と同じ値 (#861)。
1286
+ // 書いた状態が無い時は `source` の値に戻さない = 書き間違いが効いているように見えない
1287
+ const colorRaw = readout.colorSource === undefined ? undefined : stateOverrides[readout.colorSource];
1288
+ const colorKey =
1289
+ readout.colorSource === undefined ? value : colorRaw === undefined ? undefined : String(colorRaw);
1290
+ return <BadgeReadout id={readout.id} label={label} value={value} colorKey={colorKey} map={readout.map} />;
1291
+ }
1292
1292
  case "status-dot":
1293
1293
  return (
1294
1294
  <StatusDotReadout
@@ -3041,14 +3041,18 @@ function BadgeReadout({
3041
3041
  id,
3042
3042
  label,
3043
3043
  value,
3044
+ colorKey,
3044
3045
  map,
3045
3046
  }: {
3046
3047
  id: string;
3047
3048
  label: string;
3049
+ /** 札に出す字 */
3048
3050
  value: string;
3051
+ /** `map` を引く鍵。 無ければどの色にも当てない */
3052
+ colorKey: string | undefined;
3049
3053
  map?: readonly { value: string; color: string }[];
3050
3054
  }): JSX.Element {
3051
- const entry = map?.find((m) => m.value === value);
3055
+ const entry = colorKey === undefined ? undefined : map?.find((m) => m.value === colorKey);
3052
3056
  const color = entry?.color;
3053
3057
  return (
3054
3058
  <div className="cdl-ip-item cdl-ip-readout-badge" data-cdl-readout={id}>
package/src/types.ts CHANGED
@@ -1150,7 +1150,10 @@ export type CdlReadout =
1150
1150
  id: string;
1151
1151
  kind: "badge";
1152
1152
  source: string;
1153
- /** color source (default source と同じ)、 別 signal で色を切替可能 */
1153
+ /**
1154
+ * 色を引く状態 (#861)。 書くと `map` をこの状態の値で引き、札の字は `source` の値のまま。
1155
+ * 書かなければ `source` の値で引く。 書いた状態が無い時は色を付けない (`source` に戻さない)
1156
+ */
1154
1157
  colorSource?: string;
1155
1158
  /** 値と色 mapping (例: [{value: 'ok', color: 'green'}])、 未指定なら brand 色 */
1156
1159
  map?: readonly { value: string; color: string }[];