@cardenelabs/cdl 0.59.1 → 0.60.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 CHANGED
@@ -5,6 +5,31 @@ CDL (Chainome Diagram Language) の主要変更履歴。
5
5
 
6
6
  ## [Unreleased]
7
7
 
8
+ ## [0.60.0] - 2026-09-13
9
+
10
+ ### Added
11
+
12
+ - **操作部の式の行を、書き手が付けた名札で描けるようにした** (#853)
13
+
14
+ 操作部は図の式を 1 行ずつ並べ、名前に式の id、中身に式の文字列をそのまま描いていた (`total1` /
15
+ `= baseFee + priority`)。 式には名札を書く口が無く、日本語の図に置くとそこだけ英字の識別子が残っていた。
16
+
17
+ `.formula(id, expression, { label })` と `.deriveChain(baseId, count, exprFn, { label: (i) => 名札 })` で
18
+ 名札を付けられるようにした。 名札を持つ式の行は、名前に名札を描き、中身の名前のうち名札を持つ入力欄と式の
19
+ id を名札に置き換えて描く (`= baseFee + priority` → `= 基準手数料 (gwei) + 優先手数料`)。
20
+ 置き換えは式の字句の位置で行い、`Math.min` などの関数の名前と数には当てない。 表示だけの置き換えで、
21
+ 計算は書いた式を読む。
22
+
23
+ 名札を持たない式は、入力欄に名札があっても、名前も中身も変更前と同じ字で描く。 目印 (`data-cdl-formula`)
24
+ は名札の有無によらず id のまま。
25
+
26
+ ### Fixed
27
+
28
+ - **巻き取りの進みの行が、`label` を渡しても id を描いていたのを直した** (#853)
29
+
30
+ `.animation.scroll(id, { label })` の名札は図に残っていたが、操作部の行は読んでいなかった。
31
+ 名札があれば名札を描く。 目印 (`data-cdl-scroll`) は id のまま。
32
+
8
33
  ## [0.59.1] - 2026-09-13
9
34
 
10
35
  ### Fixed
@@ -2600,7 +2625,8 @@ Initial OSS release.
2600
2625
  使わない = annotated tag を push しても GitHub Release は作られず、 Release を作っていない版で
2601
2626
  行き止まりになる。
2602
2627
 
2603
- [Unreleased]: https://github.com/cardene777/cdl/compare/v0.59.1...HEAD
2628
+ [Unreleased]: https://github.com/cardene777/cdl/compare/v0.60.0...HEAD
2629
+ [0.60.0]: https://github.com/cardene777/cdl/compare/v0.59.1...v0.60.0
2604
2630
  [0.59.1]: https://github.com/cardene777/cdl/compare/v0.59.0...v0.59.1
2605
2631
  [0.59.0]: https://github.com/cardene777/cdl/compare/v0.58.0...v0.59.0
2606
2632
  [0.58.0]: https://github.com/cardene777/cdl/compare/v0.57.1...v0.58.0
package/dist/index.cjs CHANGED
@@ -755,7 +755,7 @@ function tokenize(src) {
755
755
  `invalid name "{${name}}" at position ${start} (\u7A7A\u767D / { } / . / [ ] \u306F\u540D\u524D\u306B\u4F7F\u3048\u306A\u3044)`
756
756
  );
757
757
  }
758
- tokens.push({ kind: "id", name, pos: start });
758
+ tokens.push({ kind: "id", name, pos: start, end: close + 1 });
759
759
  i = close + 1;
760
760
  continue;
761
761
  }
@@ -804,7 +804,7 @@ function tokenize(src) {
804
804
  `property access "${name}.${src[i + 1] ?? ""}..." at position ${start} is not allowed (only Math.* namespace is accessible)`
805
805
  );
806
806
  }
807
- tokens.push({ kind: "id", name, pos: start });
807
+ tokens.push({ kind: "id", name, pos: start, end: i });
808
808
  continue;
809
809
  }
810
810
  if (c === "+") {
@@ -1029,6 +1029,24 @@ function parseFormula(expression) {
1029
1029
  }
1030
1030
  return new Parser(tokens).parse();
1031
1031
  }
1032
+ function \u5F0F\u3092\u540D\u672D\u3067\u8AAD\u3080(expression, \u540D\u672D) {
1033
+ let tokens;
1034
+ try {
1035
+ tokens = tokenize(expression);
1036
+ } catch {
1037
+ return expression;
1038
+ }
1039
+ let \u8AAD\u307F = "";
1040
+ let \u524D = 0;
1041
+ for (const t of tokens) {
1042
+ if (t.kind !== "id") continue;
1043
+ const \u672D = \u540D\u672D.get(t.name);
1044
+ if (\u672D === void 0 || \u672D === "") continue;
1045
+ \u8AAD\u307F += expression.slice(\u524D, t.pos) + \u672D;
1046
+ \u524D = t.end;
1047
+ }
1048
+ return \u8AAD\u307F + expression.slice(\u524D);
1049
+ }
1032
1050
  function extractIdentifiers(ast, out = /* @__PURE__ */ new Set()) {
1033
1051
  switch (ast.type) {
1034
1052
  case "number":
@@ -1982,6 +2000,8 @@ function useInteractiveIntegration(diagram2, options = {}) {
1982
2000
  const readouts = diagram2.readouts ?? [];
1983
2001
  if (inputs.length === 0 && scrolls.length === 0 && formulasList.length === 0 && readouts.length === 0)
1984
2002
  return null;
2003
+ const \u540D\u672D = /* @__PURE__ */ new Map();
2004
+ for (const x of [...inputs, ...formulasList]) if (x.label) \u540D\u672D.set(x.id, x.label);
1985
2005
  return (
1986
2006
  // 操作部の中の読み出しと入力欄へ、図の言語を届ける (#849)。 型の外の値は英語に落ちる
1987
2007
  /* @__PURE__ */ jsxRuntime.jsx(\u64CD\u4F5C\u90E8\u306E\u8A00\u8A9E.Provider, { value: resolveLang(diagram2.lang), children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "cdl-ip-root", "data-cdl-interactive-panel": "true", children: [
@@ -1990,12 +2010,13 @@ function useInteractiveIntegration(diagram2, options = {}) {
1990
2010
  FormulaReadout,
1991
2011
  {
1992
2012
  id: f.id,
1993
- expression: f.expression,
2013
+ name: f.label || f.id,
2014
+ expression: f.label ? \u5F0F\u3092\u540D\u672D\u3067\u8AAD\u3080(f.expression, \u540D\u672D) : f.expression,
1994
2015
  value: stateOverrides[f.id]
1995
2016
  },
1996
2017
  f.id
1997
2018
  )) }),
1998
- scrolls.length > 0 && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "cdl-ip-group", children: scrolls.map((s) => /* @__PURE__ */ jsxRuntime.jsx(ScrollReadout, { id: s.id, progress: stateOverrides[s.id] }, s.id)) }),
2019
+ scrolls.length > 0 && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "cdl-ip-group", children: scrolls.map((s) => /* @__PURE__ */ jsxRuntime.jsx(ScrollReadout, { id: s.id, name: s.label || s.id, progress: stateOverrides[s.id] }, s.id)) }),
1999
2020
  readouts.length > 0 && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "cdl-ip-group", children: readouts.map((r) => /* @__PURE__ */ jsxRuntime.jsx(ReadoutWidget, { readout: r, stateOverrides: mergedStateValues }, r.id)) })
2000
2021
  ] }) })
2001
2022
  );
@@ -2252,11 +2273,12 @@ function NumberInputWidget({
2252
2273
  }
2253
2274
  function FormulaReadout({
2254
2275
  id,
2276
+ name,
2255
2277
  expression,
2256
2278
  value
2257
2279
  }) {
2258
2280
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "cdl-ip-item cdl-ip-formula", "data-cdl-formula": id, children: [
2259
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "cdl-ip-label", children: id }),
2281
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "cdl-ip-label", children: name }),
2260
2282
  /* @__PURE__ */ jsxRuntime.jsxs("code", { className: "cdl-ip-formula-expr", children: [
2261
2283
  "= ",
2262
2284
  expression
@@ -2264,11 +2286,11 @@ function FormulaReadout({
2264
2286
  /* @__PURE__ */ jsxRuntime.jsx("span", { className: "cdl-ip-formula-value", children: String(value ?? "") })
2265
2287
  ] });
2266
2288
  }
2267
- function ScrollReadout({ id, progress }) {
2289
+ function ScrollReadout({ id, name, progress }) {
2268
2290
  const p = typeof progress === "number" ? progress : 0;
2269
2291
  const pct = Math.round(p * 100);
2270
2292
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "cdl-ip-item cdl-ip-scroll", "data-cdl-scroll": id, children: [
2271
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "cdl-ip-label", children: id }),
2293
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "cdl-ip-label", children: name }),
2272
2294
  /* @__PURE__ */ jsxRuntime.jsx("div", { className: "cdl-ip-scroll-track", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "cdl-ip-scroll-fill", style: { width: `${pct}%` } }) }),
2273
2295
  /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "cdl-ip-scroll-value", children: [
2274
2296
  pct,
@@ -10317,7 +10339,7 @@ function diagram(id, options) {
10317
10339
  return api;
10318
10340
  }
10319
10341
  },
10320
- formula(formulaId, expression) {
10342
+ formula(formulaId, expression, opts) {
10321
10343
  assertUniqueFormulaId(formulaId);
10322
10344
  try {
10323
10345
  parseFormula(expression);
@@ -10325,10 +10347,10 @@ function diagram(id, options) {
10325
10347
  const msg = e instanceof Error ? e.message : String(e);
10326
10348
  throw new Error(`formula '${formulaId}' \u306E expression syntax error: ${msg}`);
10327
10349
  }
10328
- formulas.push({ id: formulaId, expression });
10350
+ formulas.push({ id: formulaId, expression, ...opts?.label ? { label: opts.label } : {} });
10329
10351
  return api;
10330
10352
  },
10331
- deriveChain(baseId, count, exprFn) {
10353
+ deriveChain(baseId, count, exprFn, opts) {
10332
10354
  if (!Number.isInteger(count) || count < 1 || count > 100) {
10333
10355
  throw new Error(`deriveChain: count (${count}) \u306F 1..100 \u306E\u6574\u6570\u3067\u3042\u308B\u5FC5\u8981\u304C\u3042\u308A\u307E\u3059`);
10334
10356
  }
@@ -10344,7 +10366,8 @@ function diagram(id, options) {
10344
10366
  const msg = e instanceof Error ? e.message : String(e);
10345
10367
  throw new Error(`deriveChain '${id2}' \u306E expression syntax error: ${msg}`);
10346
10368
  }
10347
- formulas.push({ id: id2, expression: expr });
10369
+ const label = opts?.label?.(i);
10370
+ formulas.push({ id: id2, expression: expr, ...label ? { label } : {} });
10348
10371
  prev = id2;
10349
10372
  }
10350
10373
  return api;