@cardenelabs/cdl 0.59.1 → 0.61.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.cjs CHANGED
@@ -3362,7 +3362,7 @@ function tokenize(src) {
3362
3362
  `invalid name "{${name}}" at position ${start} (\u7A7A\u767D / { } / . / [ ] \u306F\u540D\u524D\u306B\u4F7F\u3048\u306A\u3044)`
3363
3363
  );
3364
3364
  }
3365
- tokens.push({ kind: "id", name, pos: start });
3365
+ tokens.push({ kind: "id", name, pos: start, end: close + 1 });
3366
3366
  i = close + 1;
3367
3367
  continue;
3368
3368
  }
@@ -3411,7 +3411,7 @@ function tokenize(src) {
3411
3411
  `property access "${name}.${src[i + 1] ?? ""}..." at position ${start} is not allowed (only Math.* namespace is accessible)`
3412
3412
  );
3413
3413
  }
3414
- tokens.push({ kind: "id", name, pos: start });
3414
+ tokens.push({ kind: "id", name, pos: start, end: i });
3415
3415
  continue;
3416
3416
  }
3417
3417
  if (c === "+") {
@@ -3636,6 +3636,24 @@ function parseFormula(expression) {
3636
3636
  }
3637
3637
  return new Parser(tokens).parse();
3638
3638
  }
3639
+ function \u5F0F\u3092\u540D\u672D\u3067\u8AAD\u3080(expression, \u540D\u672D) {
3640
+ let tokens;
3641
+ try {
3642
+ tokens = tokenize(expression);
3643
+ } catch {
3644
+ return expression;
3645
+ }
3646
+ let \u8AAD\u307F = "";
3647
+ let \u524D = 0;
3648
+ for (const t of tokens) {
3649
+ if (t.kind !== "id") continue;
3650
+ const \u672D = \u540D\u672D.get(t.name);
3651
+ if (\u672D === void 0 || \u672D === "") continue;
3652
+ \u8AAD\u307F += expression.slice(\u524D, t.pos) + \u672D;
3653
+ \u524D = t.end;
3654
+ }
3655
+ return \u8AAD\u307F + expression.slice(\u524D);
3656
+ }
3639
3657
  function extractIdentifiers(ast, out = /* @__PURE__ */ new Set()) {
3640
3658
  switch (ast.type) {
3641
3659
  case "number":
@@ -3800,6 +3818,34 @@ function evaluateOne(entry, values) {
3800
3818
  }
3801
3819
  }
3802
3820
 
3821
+ // src/input-option.ts
3822
+ function \u9078\u629E\u80A2\u306E\u5024(option) {
3823
+ return typeof option === "string" ? option : option.value;
3824
+ }
3825
+ function \u9078\u629E\u80A2\u306E\u540D\u524D(option) {
3826
+ return typeof option === "string" || option.label === "" ? \u9078\u629E\u80A2\u306E\u5024(option) : option.label;
3827
+ }
3828
+ function \u5024\u306E\u540D\u524D\u306E\u8868\u3092\u4F5C\u308B(inputs) {
3829
+ const \u8868 = /* @__PURE__ */ new Map();
3830
+ for (const input of inputs ?? []) {
3831
+ const \u540D\u524D = /* @__PURE__ */ new Map();
3832
+ if (input.kind === "dropdown" || input.kind === "radio" || input.kind === "tabs" || input.kind === "multi-select") {
3833
+ for (const option of input.options) {
3834
+ if (typeof option !== "string" && option.label !== "") \u540D\u524D.set(option.value, option.label);
3835
+ }
3836
+ } else if (input.kind === "toggle") {
3837
+ if (input.onLabel) \u540D\u524D.set("true", input.onLabel);
3838
+ if (input.offLabel) \u540D\u524D.set("false", input.offLabel);
3839
+ }
3840
+ if (\u540D\u524D.size > 0) \u8868.set(input.id, { \u540D\u524D, \u8907\u6570: input.kind === "multi-select" });
3841
+ }
3842
+ return \u8868;
3843
+ }
3844
+ function \u5024\u3092\u540D\u524D\u3067\u8AAD\u3080(\u5165\u529B\u6B04, \u5024) {
3845
+ if (!\u5165\u529B\u6B04.\u8907\u6570) return \u5165\u529B\u6B04.\u540D\u524D.get(\u5024) ?? \u5024;
3846
+ return \u5024.split(",").map((v) => \u5165\u529B\u6B04.\u540D\u524D.get(v) ?? v).join(",");
3847
+ }
3848
+
3803
3849
  // src/render/utils.ts
3804
3850
  var TEMPLATE_REF_RE = new RegExp(TEMPLATE_REF_SRC, "g");
3805
3851
  var TEMPLATE_LEFTOVER_TEST_RE = new RegExp(TEMPLATE_LEFTOVER_SRC);
@@ -3848,11 +3894,14 @@ function mergeStateValues(base, overrides) {
3848
3894
  }
3849
3895
  return merged;
3850
3896
  }
3851
- function interpolate(template, values) {
3897
+ function interpolate(template, values, \u540D\u524D\u306E\u8868) {
3852
3898
  return template.replace(TEMPLATE_REF_RE, (_, id, accessor) => {
3853
3899
  const raw = Object.hasOwn(values, id) ? values[id] : void 0;
3854
3900
  if (raw === void 0) return `{${id}${accessor ?? ""}}`;
3855
- if (!accessor) return raw;
3901
+ if (!accessor) {
3902
+ const \u5165\u529B\u6B04 = \u540D\u524D\u306E\u8868?.get(id);
3903
+ return \u5165\u529B\u6B04 ? \u5024\u3092\u540D\u524D\u3067\u8AAD\u3080(\u5165\u529B\u6B04, raw) : raw;
3904
+ }
3856
3905
  const arr = parseArraySignal(raw);
3857
3906
  if (!arr) return `{${id}${accessor}}`;
3858
3907
  if (accessor === ".length") return String(arr.length);
@@ -12037,7 +12086,8 @@ function GenericNode({
12037
12086
  node,
12038
12087
  active,
12039
12088
  value,
12040
- stateValues
12089
+ stateValues,
12090
+ \u5024\u306E\u540D\u524D
12041
12091
  }) {
12042
12092
  const base = STYLES[node.kind] ?? FALLBACK;
12043
12093
  const toned = toneColor3(node.tone);
@@ -12123,7 +12173,7 @@ function GenericNode({
12123
12173
  style.look === "ledger" && /* @__PURE__ */ jsxRuntime.jsx("line", { x1: 1, y1: h - 7, x2: w - 1, y2: h - 7, stroke: paint.stroke, strokeWidth: 1 })
12124
12174
  ] });
12125
12175
  })();
12126
- const resolvedValue = value !== void 0 ? interpolate(value, stateValues) : void 0;
12176
+ const resolvedValue = value !== void 0 ? interpolate(value, stateValues, \u5024\u306E\u540D\u524D) : void 0;
12127
12177
  const hasRows = (node.rows?.length ?? 0) > 0;
12128
12178
  const centered = genericTextCentered(node.kind, hasRows);
12129
12179
  const textAnchor = centered ? "middle" : "start";
@@ -12173,7 +12223,7 @@ function GenericNode({
12173
12223
  }
12174
12224
  ),
12175
12225
  node.rows && node.rows.length > 0 && (() => {
12176
- const resolved = node.rows.map((row) => interpolate(row, stateValues));
12226
+ const resolved = node.rows.map((row) => interpolate(row, stateValues, \u5024\u306E\u540D\u524D));
12177
12227
  const splits = resolved.map(splitRow);
12178
12228
  const leftMaxWidth = splits.reduce(
12179
12229
  (m, s) => Math.max(m, rowColumnWidth(s.left, GENERIC_ROW_LEFT_SIZE_PX, false)),
@@ -18838,10 +18888,11 @@ function CdlNodeView({
18838
18888
  currentPhaseId,
18839
18889
  chartLineScale,
18840
18890
  \u95A2\u4FC2\u306E\u53D7\u3051\u53E3,
18841
- lang
18891
+ lang,
18892
+ \u5024\u306E\u540D\u524D
18842
18893
  }) {
18843
- const value = node.value ? interpolate(node.value, stateValues) : void 0;
18844
- const rows = (node.rows ?? []).map((r) => interpolate(r, stateValues));
18894
+ const value = node.value ? interpolate(node.value, stateValues, \u5024\u306E\u540D\u524D) : void 0;
18895
+ const rows = (node.rows ?? []).map((r) => interpolate(r, stateValues, \u5024\u306E\u540D\u524D));
18845
18896
  const boundW = node.wBind ? resolveNumericAttr(node.wBind, stateValues, node.w) : node.w;
18846
18897
  const boundH = node.hBind ? resolveNumericAttr(node.hBind, stateValues, node.h) : node.h;
18847
18898
  const boundOpacity = node.opacity !== void 0 ? Math.min(1, Math.max(0, resolveNumericAttr(node.opacity, stateValues, 1))) : void 0;
@@ -18855,9 +18906,9 @@ function CdlNodeView({
18855
18906
  }
18856
18907
  const resolvedNode = {
18857
18908
  ...node,
18858
- title: interpolate(node.title, stateValues),
18859
- subtitle: node.subtitle ? interpolate(node.subtitle, stateValues) : node.subtitle,
18860
- eyebrow: node.eyebrow ? interpolate(node.eyebrow, stateValues) : node.eyebrow,
18909
+ title: interpolate(node.title, stateValues, \u5024\u306E\u540D\u524D),
18910
+ subtitle: node.subtitle ? interpolate(node.subtitle, stateValues, \u5024\u306E\u540D\u524D) : node.subtitle,
18911
+ eyebrow: node.eyebrow ? interpolate(node.eyebrow, stateValues, \u5024\u306E\u540D\u524D) : node.eyebrow,
18861
18912
  w: boundW,
18862
18913
  h: boundH
18863
18914
  };
@@ -19138,7 +19189,7 @@ function CdlNodeView({
19138
19189
  case "mark-end":
19139
19190
  return /* @__PURE__ */ jsxRuntime.jsx(MarkEndNode, { node: resolvedNode, active });
19140
19191
  default:
19141
- return /* @__PURE__ */ jsxRuntime.jsx(GenericNode, { node: resolvedNode, active, value: node.value, stateValues });
19192
+ return /* @__PURE__ */ jsxRuntime.jsx(GenericNode, { node: resolvedNode, active, value: node.value, stateValues, \u5024\u306E\u540D\u524D });
19142
19193
  }
19143
19194
  })();
19144
19195
  const offsetX = node.renderOffsetX !== void 0 ? resolveNumericAttr(node.renderOffsetX, stateValues, 0) : 0;
@@ -19220,7 +19271,8 @@ function CdlStage({
19220
19271
  stateValues,
19221
19272
  debug,
19222
19273
  compact = false,
19223
- svgRef
19274
+ svgRef,
19275
+ \u5024\u306E\u540D\u524D
19224
19276
  }) {
19225
19277
  const [\u7126\u70B9, set\u7126\u70B9] = react.useState(null);
19226
19278
  const \u95A2\u4FC2\u3092\u5149\u3089\u305B\u308B = (laid.relationFocus ?? RELATION_FOCUS_DEFAULT) === "hover";
@@ -19500,6 +19552,7 @@ function CdlStage({
19500
19552
  drawing: \u63CF\u304F,
19501
19553
  progress: \u63CF\u304F ? \u63CF\u304F\u9032\u307F : progress,
19502
19554
  stateValues,
19555
+ \u5024\u306E\u540D\u524D,
19503
19556
  currentPhaseId: currentPhase?.id,
19504
19557
  chartLineScale: chartLineScales.get(node.id)
19505
19558
  }
@@ -20569,6 +20622,8 @@ function useInteractiveIntegration(diagram, options = {}) {
20569
20622
  const readouts = diagram.readouts ?? [];
20570
20623
  if (inputs.length === 0 && scrolls.length === 0 && formulasList.length === 0 && readouts.length === 0)
20571
20624
  return null;
20625
+ const \u540D\u672D = /* @__PURE__ */ new Map();
20626
+ for (const x of [...inputs, ...formulasList]) if (x.label) \u540D\u672D.set(x.id, x.label);
20572
20627
  return (
20573
20628
  // 操作部の中の読み出しと入力欄へ、図の言語を届ける (#849)。 型の外の値は英語に落ちる
20574
20629
  /* @__PURE__ */ jsxRuntime.jsx(\u64CD\u4F5C\u90E8\u306E\u8A00\u8A9E.Provider, { value: resolveLang(diagram.lang), children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "cdl-ip-root", "data-cdl-interactive-panel": "true", children: [
@@ -20577,12 +20632,13 @@ function useInteractiveIntegration(diagram, options = {}) {
20577
20632
  FormulaReadout,
20578
20633
  {
20579
20634
  id: f.id,
20580
- expression: f.expression,
20635
+ name: f.label || f.id,
20636
+ expression: f.label ? \u5F0F\u3092\u540D\u672D\u3067\u8AAD\u3080(f.expression, \u540D\u672D) : f.expression,
20581
20637
  value: stateOverrides[f.id]
20582
20638
  },
20583
20639
  f.id
20584
20640
  )) }),
20585
- 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)) }),
20641
+ 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)) }),
20586
20642
  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)) })
20587
20643
  ] }) })
20588
20644
  );
@@ -20665,7 +20721,7 @@ function InputWidget({
20665
20721
  },
20666
20722
  "data-cdl-input": input.id,
20667
20723
  className: "cdl-ip-dropdown-select",
20668
- children: input.options.map((opt) => /* @__PURE__ */ jsxRuntime.jsx("option", { value: opt, children: opt }, opt))
20724
+ children: input.options.map((opt) => /* @__PURE__ */ jsxRuntime.jsx("option", { value: \u9078\u629E\u80A2\u306E\u5024(opt), children: \u9078\u629E\u80A2\u306E\u540D\u524D(opt) }, \u9078\u629E\u80A2\u306E\u5024(opt)))
20669
20725
  }
20670
20726
  )
20671
20727
  ] });
@@ -20682,17 +20738,17 @@ function InputWidget({
20682
20738
  {
20683
20739
  type: "radio",
20684
20740
  name: input.id,
20685
- value: opt,
20686
- checked: value === opt,
20741
+ value: \u9078\u629E\u80A2\u306E\u5024(opt),
20742
+ checked: value === \u9078\u629E\u80A2\u306E\u5024(opt),
20687
20743
  onChange: () => {
20688
- signal2.value = opt;
20744
+ signal2.value = \u9078\u629E\u80A2\u306E\u5024(opt);
20689
20745
  },
20690
20746
  "data-cdl-input": input.id,
20691
20747
  className: "cdl-ip-radio-input"
20692
20748
  }
20693
20749
  ),
20694
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "cdl-ip-radio-label", children: opt })
20695
- ] }, opt)) })
20750
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "cdl-ip-radio-label", children: \u9078\u629E\u80A2\u306E\u540D\u524D(opt) })
20751
+ ] }, \u9078\u629E\u80A2\u306E\u5024(opt))) })
20696
20752
  ] });
20697
20753
  case "color":
20698
20754
  return /* @__PURE__ */ jsxRuntime.jsxs("label", { className: "cdl-ip-item cdl-ip-color", "data-cdl-input-kind": "color", children: [
@@ -20742,14 +20798,14 @@ function InputWidget({
20742
20798
  {
20743
20799
  type: "button",
20744
20800
  role: "tab",
20745
- className: `cdl-ip-tabs-btn ${value === opt ? "cdl-ip-tabs-active" : ""}`,
20801
+ className: `cdl-ip-tabs-btn ${value === \u9078\u629E\u80A2\u306E\u5024(opt) ? "cdl-ip-tabs-active" : ""}`,
20746
20802
  onClick: () => {
20747
- signal2.value = opt;
20803
+ signal2.value = \u9078\u629E\u80A2\u306E\u5024(opt);
20748
20804
  },
20749
20805
  "data-cdl-input": input.id,
20750
- children: opt
20806
+ children: \u9078\u629E\u80A2\u306E\u540D\u524D(opt)
20751
20807
  },
20752
- opt
20808
+ \u9078\u629E\u80A2\u306E\u5024(opt)
20753
20809
  )) })
20754
20810
  ] });
20755
20811
  case "datetime":
@@ -20839,11 +20895,12 @@ function NumberInputWidget({
20839
20895
  }
20840
20896
  function FormulaReadout({
20841
20897
  id,
20898
+ name,
20842
20899
  expression,
20843
20900
  value
20844
20901
  }) {
20845
20902
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "cdl-ip-item cdl-ip-formula", "data-cdl-formula": id, children: [
20846
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "cdl-ip-label", children: id }),
20903
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "cdl-ip-label", children: name }),
20847
20904
  /* @__PURE__ */ jsxRuntime.jsxs("code", { className: "cdl-ip-formula-expr", children: [
20848
20905
  "= ",
20849
20906
  expression
@@ -20851,11 +20908,11 @@ function FormulaReadout({
20851
20908
  /* @__PURE__ */ jsxRuntime.jsx("span", { className: "cdl-ip-formula-value", children: String(value ?? "") })
20852
20909
  ] });
20853
20910
  }
20854
- function ScrollReadout({ id, progress }) {
20911
+ function ScrollReadout({ id, name, progress }) {
20855
20912
  const p = typeof progress === "number" ? progress : 0;
20856
20913
  const pct = Math.round(p * 100);
20857
20914
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "cdl-ip-item cdl-ip-scroll", "data-cdl-scroll": id, children: [
20858
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "cdl-ip-label", children: id }),
20915
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "cdl-ip-label", children: name }),
20859
20916
  /* @__PURE__ */ jsxRuntime.jsx("div", { className: "cdl-ip-scroll-track", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "cdl-ip-scroll-fill", style: { width: `${pct}%` } }) }),
20860
20917
  /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "cdl-ip-scroll-value", children: [
20861
20918
  pct,
@@ -22803,13 +22860,13 @@ function MultiSelectWidget({
22803
22860
  "button",
22804
22861
  {
22805
22862
  type: "button",
22806
- className: `cdl-ip-multi-select-chip ${selected.has(opt) ? "cdl-ip-multi-select-active" : ""}`,
22807
- onClick: () => toggle(opt),
22863
+ className: `cdl-ip-multi-select-chip ${selected.has(\u9078\u629E\u80A2\u306E\u5024(opt)) ? "cdl-ip-multi-select-active" : ""}`,
22864
+ onClick: () => toggle(\u9078\u629E\u80A2\u306E\u5024(opt)),
22808
22865
  "data-cdl-input": input.id,
22809
- "data-cdl-multi-value": opt,
22810
- children: opt
22866
+ "data-cdl-multi-value": \u9078\u629E\u80A2\u306E\u5024(opt),
22867
+ children: \u9078\u629E\u80A2\u306E\u540D\u524D(opt)
22811
22868
  },
22812
- opt
22869
+ \u9078\u629E\u80A2\u306E\u5024(opt)
22813
22870
  )) })
22814
22871
  ] });
22815
22872
  }
@@ -28341,6 +28398,7 @@ function CdlDiagramView({ diagram, laid: laidProp, hideHeader = false, hideMiniP
28341
28398
  if (!isInteractive) return baseStateValues;
28342
28399
  return mergeStateValues(baseStateValues, interactive.stateOverrides);
28343
28400
  }, [isInteractive, baseStateValues, interactive.stateOverrides]);
28401
+ const \u5024\u306E\u540D\u524D = react.useMemo(() => \u5024\u306E\u540D\u524D\u306E\u8868\u3092\u4F5C\u308B(diagram.inputs), [diagram.inputs]);
28344
28402
  return /* @__PURE__ */ jsxRuntime.jsxs(
28345
28403
  "div",
28346
28404
  {
@@ -28369,7 +28427,7 @@ function CdlDiagramView({ diagram, laid: laidProp, hideHeader = false, hideMiniP
28369
28427
  }
28370
28428
  ),
28371
28429
  isInteractive && interactive.panel,
28372
- /* @__PURE__ */ jsxRuntime.jsx(CdlStage, { laid, currentPhase, progress, drawProgress, stateValues, debug, compact: hideHeader, svgRef: isInteractive ? interactive.svgRef : void 0 }),
28430
+ /* @__PURE__ */ jsxRuntime.jsx(CdlStage, { laid, currentPhase, progress, drawProgress, stateValues, \u5024\u306E\u540D\u524D, debug, compact: hideHeader, svgRef: isInteractive ? interactive.svgRef : void 0 }),
28373
28431
  hideHeader && !hideMiniPhaseIndicator && currentPhase && laid.phases.length > 1 && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between gap-3 border-t border-[var(--cdl-divider,#d4d4d8)]/40 bg-[var(--cdl-stage-bg,#f1f5f9)]/50 px-3 py-2 text-xs", children: [
28374
28432
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1.5", children: [
28375
28433
  laid.phases.map((p, i) => /* @__PURE__ */ jsxRuntime.jsx(