@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 +27 -1
- package/dist/index.cjs +34 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +12 -4
- package/dist/index.d.ts +12 -4
- package/dist/index.js +34 -11
- package/dist/index.js.map +1 -1
- package/dist/react.cjs +29 -7
- 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 +29 -7
- package/dist/react.js.map +1 -1
- package/dist/{render-DpwY2hzM.d.cts → render-MbIjRWdX.d.cts} +7 -0
- package/dist/{render-DpwY2hzM.d.ts → render-MbIjRWdX.d.ts} +7 -0
- package/package.json +1 -1
- package/src/builder.ts +13 -5
- package/src/formula/parser.ts +32 -3
- package/src/render/interactive-panel.tsx +18 -5
- package/src/types.ts +7 -0
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { C as CdlDiagram, S as Signal, a as CdlInput, b as CdlLane, c as CdlNode, T as Tone, d as Side, E as EdgeStyle, e as EdgeRole, f as EdgeHead, g as EdgeHeadFill, h as CdlState, i as CdlEventTarget, j as CdlLang, k as Computed, l as CdlDerivedValue, m as CdlScrollTrigger, L as LaidDiagram, n as CdlDiagramViewProps, o as LaidEdge, p as LaidNode, q as CdlEdge, B as BBox, R as RowMark, N as NodeKind, J as JourneyEmotion, Q as QuadrantKey } from './render-
|
|
2
|
-
export { r as CdlDiagramView, s as CdlEventBinding, t as CdlEventKind, u as CdlFormula, v as CdlPhase, w as ChartPieForm, x as ChartSlopeForm, y as EDGE_HEADS, z as EDGE_HEAD_DEFAULT, A as EDGE_HEAD_FILLS, D as EDGE_HEAD_FILL_DEFAULT, F as EDGE_REVEALS, G as EDGE_REVEAL_DEFAULT, H as EDGE_STYLES, I as EdgeReveal, K as InteractiveHandlerMap, M as InteractiveSignalsAccessor, O as LaidLane, P as NODE_KINDS, U as RELATION_FOCUSES, V as RELATION_FOCUS_DEFAULT, W as RelationFocus, X as ScrollProgressHandle, Y as TONES, Z as computeEventBindingKey, _ as computeFormulaKey, $ as computeInputSignalKey, a0 as computeScrollTriggerKey, a1 as computed, a2 as createInteractiveSignalsAccessor, a3 as createScrollProgressHandle, a4 as createScrollProgressSignals, a5 as hasInteractivePrimitives, a6 as resolveLang, a7 as sequenceBoardMetrics, a8 as sequenceStepId, a9 as signal } from './render-
|
|
1
|
+
import { C as CdlDiagram, S as Signal, a as CdlInput, b as CdlLane, c as CdlNode, T as Tone, d as Side, E as EdgeStyle, e as EdgeRole, f as EdgeHead, g as EdgeHeadFill, h as CdlState, i as CdlEventTarget, j as CdlLang, k as Computed, l as CdlDerivedValue, m as CdlScrollTrigger, L as LaidDiagram, n as CdlDiagramViewProps, o as LaidEdge, p as LaidNode, q as CdlEdge, B as BBox, R as RowMark, N as NodeKind, J as JourneyEmotion, Q as QuadrantKey } from './render-MbIjRWdX.cjs';
|
|
2
|
+
export { r as CdlDiagramView, s as CdlEventBinding, t as CdlEventKind, u as CdlFormula, v as CdlPhase, w as ChartPieForm, x as ChartSlopeForm, y as EDGE_HEADS, z as EDGE_HEAD_DEFAULT, A as EDGE_HEAD_FILLS, D as EDGE_HEAD_FILL_DEFAULT, F as EDGE_REVEALS, G as EDGE_REVEAL_DEFAULT, H as EDGE_STYLES, I as EdgeReveal, K as InteractiveHandlerMap, M as InteractiveSignalsAccessor, O as LaidLane, P as NODE_KINDS, U as RELATION_FOCUSES, V as RELATION_FOCUS_DEFAULT, W as RelationFocus, X as ScrollProgressHandle, Y as TONES, Z as computeEventBindingKey, _ as computeFormulaKey, $ as computeInputSignalKey, a0 as computeScrollTriggerKey, a1 as computed, a2 as createInteractiveSignalsAccessor, a3 as createScrollProgressHandle, a4 as createScrollProgressSignals, a5 as hasInteractivePrimitives, a6 as resolveLang, a7 as sequenceBoardMetrics, a8 as sequenceStepId, a9 as signal } from './render-MbIjRWdX.cjs';
|
|
3
3
|
import { JSX } from 'react';
|
|
4
4
|
|
|
5
5
|
declare function effect(fn: () => void | (() => void)): () => void;
|
|
@@ -1170,8 +1170,12 @@ type DiagramBuilder = {
|
|
|
1170
1170
|
* consumer が createFormulaComputeds() で computed 化して signal と reactive bind する。
|
|
1171
1171
|
* expression syntax error は本 method 内で throw (fail-fast)。
|
|
1172
1172
|
* 例 `.formula("gasFee", "gasBase * (1 + delta/8)")`
|
|
1173
|
+
*
|
|
1174
|
+
* `opts.label` は操作部の式の行に描く名札 (#853)。 例 `.formula("total", "baseFee + tip", { label: "合計" })`
|
|
1173
1175
|
*/
|
|
1174
|
-
formula: (id: string, expression: string
|
|
1176
|
+
formula: (id: string, expression: string, opts?: {
|
|
1177
|
+
label?: string;
|
|
1178
|
+
}) => DiagramBuilder;
|
|
1175
1179
|
/**
|
|
1176
1180
|
* derive chain = 「連鎖形 formula」 を N 個宣言的に生成 (CAR: derive chain)。
|
|
1177
1181
|
* 各 iteration で `{i}` 置換と、 直前 iteration の id (`prev`) を参照可能。
|
|
@@ -1181,8 +1185,12 @@ type DiagramBuilder = {
|
|
|
1181
1185
|
*
|
|
1182
1186
|
* baseId は「gas1 / gas2 / gas3」 のように `gas${i+1}` として使われる、
|
|
1183
1187
|
* expr fn は index (0..count-1) と prev id (前 iteration の完全 id) を受け取る。
|
|
1188
|
+
*
|
|
1189
|
+
* `opts.label` は index を受け取り、その式の名札を返す (#853)。 例 `{ label: (i) => \`${i + 1} 回目\` }`
|
|
1184
1190
|
*/
|
|
1185
|
-
deriveChain: (baseId: string, count: number, exprFn: (i: number, prev: string | null) => string
|
|
1191
|
+
deriveChain: (baseId: string, count: number, exprFn: (i: number, prev: string | null) => string, opts?: {
|
|
1192
|
+
label?: (i: number) => string;
|
|
1193
|
+
}) => DiagramBuilder;
|
|
1186
1194
|
/**
|
|
1187
1195
|
* animation primitive (CAR #245)。 `.animation.scroll(id, opts)` で scroll-driven trigger を追加。
|
|
1188
1196
|
* 将来的に `.animation.time(...)` 等の time-based primitive を追加する余地を残す namespace。
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { C as CdlDiagram, S as Signal, a as CdlInput, b as CdlLane, c as CdlNode, T as Tone, d as Side, E as EdgeStyle, e as EdgeRole, f as EdgeHead, g as EdgeHeadFill, h as CdlState, i as CdlEventTarget, j as CdlLang, k as Computed, l as CdlDerivedValue, m as CdlScrollTrigger, L as LaidDiagram, n as CdlDiagramViewProps, o as LaidEdge, p as LaidNode, q as CdlEdge, B as BBox, R as RowMark, N as NodeKind, J as JourneyEmotion, Q as QuadrantKey } from './render-
|
|
2
|
-
export { r as CdlDiagramView, s as CdlEventBinding, t as CdlEventKind, u as CdlFormula, v as CdlPhase, w as ChartPieForm, x as ChartSlopeForm, y as EDGE_HEADS, z as EDGE_HEAD_DEFAULT, A as EDGE_HEAD_FILLS, D as EDGE_HEAD_FILL_DEFAULT, F as EDGE_REVEALS, G as EDGE_REVEAL_DEFAULT, H as EDGE_STYLES, I as EdgeReveal, K as InteractiveHandlerMap, M as InteractiveSignalsAccessor, O as LaidLane, P as NODE_KINDS, U as RELATION_FOCUSES, V as RELATION_FOCUS_DEFAULT, W as RelationFocus, X as ScrollProgressHandle, Y as TONES, Z as computeEventBindingKey, _ as computeFormulaKey, $ as computeInputSignalKey, a0 as computeScrollTriggerKey, a1 as computed, a2 as createInteractiveSignalsAccessor, a3 as createScrollProgressHandle, a4 as createScrollProgressSignals, a5 as hasInteractivePrimitives, a6 as resolveLang, a7 as sequenceBoardMetrics, a8 as sequenceStepId, a9 as signal } from './render-
|
|
1
|
+
import { C as CdlDiagram, S as Signal, a as CdlInput, b as CdlLane, c as CdlNode, T as Tone, d as Side, E as EdgeStyle, e as EdgeRole, f as EdgeHead, g as EdgeHeadFill, h as CdlState, i as CdlEventTarget, j as CdlLang, k as Computed, l as CdlDerivedValue, m as CdlScrollTrigger, L as LaidDiagram, n as CdlDiagramViewProps, o as LaidEdge, p as LaidNode, q as CdlEdge, B as BBox, R as RowMark, N as NodeKind, J as JourneyEmotion, Q as QuadrantKey } from './render-MbIjRWdX.js';
|
|
2
|
+
export { r as CdlDiagramView, s as CdlEventBinding, t as CdlEventKind, u as CdlFormula, v as CdlPhase, w as ChartPieForm, x as ChartSlopeForm, y as EDGE_HEADS, z as EDGE_HEAD_DEFAULT, A as EDGE_HEAD_FILLS, D as EDGE_HEAD_FILL_DEFAULT, F as EDGE_REVEALS, G as EDGE_REVEAL_DEFAULT, H as EDGE_STYLES, I as EdgeReveal, K as InteractiveHandlerMap, M as InteractiveSignalsAccessor, O as LaidLane, P as NODE_KINDS, U as RELATION_FOCUSES, V as RELATION_FOCUS_DEFAULT, W as RelationFocus, X as ScrollProgressHandle, Y as TONES, Z as computeEventBindingKey, _ as computeFormulaKey, $ as computeInputSignalKey, a0 as computeScrollTriggerKey, a1 as computed, a2 as createInteractiveSignalsAccessor, a3 as createScrollProgressHandle, a4 as createScrollProgressSignals, a5 as hasInteractivePrimitives, a6 as resolveLang, a7 as sequenceBoardMetrics, a8 as sequenceStepId, a9 as signal } from './render-MbIjRWdX.js';
|
|
3
3
|
import { JSX } from 'react';
|
|
4
4
|
|
|
5
5
|
declare function effect(fn: () => void | (() => void)): () => void;
|
|
@@ -1170,8 +1170,12 @@ type DiagramBuilder = {
|
|
|
1170
1170
|
* consumer が createFormulaComputeds() で computed 化して signal と reactive bind する。
|
|
1171
1171
|
* expression syntax error は本 method 内で throw (fail-fast)。
|
|
1172
1172
|
* 例 `.formula("gasFee", "gasBase * (1 + delta/8)")`
|
|
1173
|
+
*
|
|
1174
|
+
* `opts.label` は操作部の式の行に描く名札 (#853)。 例 `.formula("total", "baseFee + tip", { label: "合計" })`
|
|
1173
1175
|
*/
|
|
1174
|
-
formula: (id: string, expression: string
|
|
1176
|
+
formula: (id: string, expression: string, opts?: {
|
|
1177
|
+
label?: string;
|
|
1178
|
+
}) => DiagramBuilder;
|
|
1175
1179
|
/**
|
|
1176
1180
|
* derive chain = 「連鎖形 formula」 を N 個宣言的に生成 (CAR: derive chain)。
|
|
1177
1181
|
* 各 iteration で `{i}` 置換と、 直前 iteration の id (`prev`) を参照可能。
|
|
@@ -1181,8 +1185,12 @@ type DiagramBuilder = {
|
|
|
1181
1185
|
*
|
|
1182
1186
|
* baseId は「gas1 / gas2 / gas3」 のように `gas${i+1}` として使われる、
|
|
1183
1187
|
* expr fn は index (0..count-1) と prev id (前 iteration の完全 id) を受け取る。
|
|
1188
|
+
*
|
|
1189
|
+
* `opts.label` は index を受け取り、その式の名札を返す (#853)。 例 `{ label: (i) => \`${i + 1} 回目\` }`
|
|
1184
1190
|
*/
|
|
1185
|
-
deriveChain: (baseId: string, count: number, exprFn: (i: number, prev: string | null) => string
|
|
1191
|
+
deriveChain: (baseId: string, count: number, exprFn: (i: number, prev: string | null) => string, opts?: {
|
|
1192
|
+
label?: (i: number) => string;
|
|
1193
|
+
}) => DiagramBuilder;
|
|
1186
1194
|
/**
|
|
1187
1195
|
* animation primitive (CAR #245)。 `.animation.scroll(id, opts)` で scroll-driven trigger を追加。
|
|
1188
1196
|
* 将来的に `.animation.time(...)` 等の time-based primitive を追加する余地を残す namespace。
|
package/dist/index.js
CHANGED
|
@@ -753,7 +753,7 @@ function tokenize(src) {
|
|
|
753
753
|
`invalid name "{${name}}" at position ${start} (\u7A7A\u767D / { } / . / [ ] \u306F\u540D\u524D\u306B\u4F7F\u3048\u306A\u3044)`
|
|
754
754
|
);
|
|
755
755
|
}
|
|
756
|
-
tokens.push({ kind: "id", name, pos: start });
|
|
756
|
+
tokens.push({ kind: "id", name, pos: start, end: close + 1 });
|
|
757
757
|
i = close + 1;
|
|
758
758
|
continue;
|
|
759
759
|
}
|
|
@@ -802,7 +802,7 @@ function tokenize(src) {
|
|
|
802
802
|
`property access "${name}.${src[i + 1] ?? ""}..." at position ${start} is not allowed (only Math.* namespace is accessible)`
|
|
803
803
|
);
|
|
804
804
|
}
|
|
805
|
-
tokens.push({ kind: "id", name, pos: start });
|
|
805
|
+
tokens.push({ kind: "id", name, pos: start, end: i });
|
|
806
806
|
continue;
|
|
807
807
|
}
|
|
808
808
|
if (c === "+") {
|
|
@@ -1027,6 +1027,24 @@ function parseFormula(expression) {
|
|
|
1027
1027
|
}
|
|
1028
1028
|
return new Parser(tokens).parse();
|
|
1029
1029
|
}
|
|
1030
|
+
function \u5F0F\u3092\u540D\u672D\u3067\u8AAD\u3080(expression, \u540D\u672D) {
|
|
1031
|
+
let tokens;
|
|
1032
|
+
try {
|
|
1033
|
+
tokens = tokenize(expression);
|
|
1034
|
+
} catch {
|
|
1035
|
+
return expression;
|
|
1036
|
+
}
|
|
1037
|
+
let \u8AAD\u307F = "";
|
|
1038
|
+
let \u524D = 0;
|
|
1039
|
+
for (const t of tokens) {
|
|
1040
|
+
if (t.kind !== "id") continue;
|
|
1041
|
+
const \u672D = \u540D\u672D.get(t.name);
|
|
1042
|
+
if (\u672D === void 0 || \u672D === "") continue;
|
|
1043
|
+
\u8AAD\u307F += expression.slice(\u524D, t.pos) + \u672D;
|
|
1044
|
+
\u524D = t.end;
|
|
1045
|
+
}
|
|
1046
|
+
return \u8AAD\u307F + expression.slice(\u524D);
|
|
1047
|
+
}
|
|
1030
1048
|
function extractIdentifiers(ast, out = /* @__PURE__ */ new Set()) {
|
|
1031
1049
|
switch (ast.type) {
|
|
1032
1050
|
case "number":
|
|
@@ -1980,6 +1998,8 @@ function useInteractiveIntegration(diagram2, options = {}) {
|
|
|
1980
1998
|
const readouts = diagram2.readouts ?? [];
|
|
1981
1999
|
if (inputs.length === 0 && scrolls.length === 0 && formulasList.length === 0 && readouts.length === 0)
|
|
1982
2000
|
return null;
|
|
2001
|
+
const \u540D\u672D = /* @__PURE__ */ new Map();
|
|
2002
|
+
for (const x of [...inputs, ...formulasList]) if (x.label) \u540D\u672D.set(x.id, x.label);
|
|
1983
2003
|
return (
|
|
1984
2004
|
// 操作部の中の読み出しと入力欄へ、図の言語を届ける (#849)。 型の外の値は英語に落ちる
|
|
1985
2005
|
/* @__PURE__ */ jsx(\u64CD\u4F5C\u90E8\u306E\u8A00\u8A9E.Provider, { value: resolveLang(diagram2.lang), children: /* @__PURE__ */ jsxs("div", { className: "cdl-ip-root", "data-cdl-interactive-panel": "true", children: [
|
|
@@ -1988,12 +2008,13 @@ function useInteractiveIntegration(diagram2, options = {}) {
|
|
|
1988
2008
|
FormulaReadout,
|
|
1989
2009
|
{
|
|
1990
2010
|
id: f.id,
|
|
1991
|
-
|
|
2011
|
+
name: f.label || f.id,
|
|
2012
|
+
expression: f.label ? \u5F0F\u3092\u540D\u672D\u3067\u8AAD\u3080(f.expression, \u540D\u672D) : f.expression,
|
|
1992
2013
|
value: stateOverrides[f.id]
|
|
1993
2014
|
},
|
|
1994
2015
|
f.id
|
|
1995
2016
|
)) }),
|
|
1996
|
-
scrolls.length > 0 && /* @__PURE__ */ jsx("div", { className: "cdl-ip-group", children: scrolls.map((s) => /* @__PURE__ */ jsx(ScrollReadout, { id: s.id, progress: stateOverrides[s.id] }, s.id)) }),
|
|
2017
|
+
scrolls.length > 0 && /* @__PURE__ */ jsx("div", { className: "cdl-ip-group", children: scrolls.map((s) => /* @__PURE__ */ jsx(ScrollReadout, { id: s.id, name: s.label || s.id, progress: stateOverrides[s.id] }, s.id)) }),
|
|
1997
2018
|
readouts.length > 0 && /* @__PURE__ */ jsx("div", { className: "cdl-ip-group", children: readouts.map((r) => /* @__PURE__ */ jsx(ReadoutWidget, { readout: r, stateOverrides: mergedStateValues }, r.id)) })
|
|
1998
2019
|
] }) })
|
|
1999
2020
|
);
|
|
@@ -2250,11 +2271,12 @@ function NumberInputWidget({
|
|
|
2250
2271
|
}
|
|
2251
2272
|
function FormulaReadout({
|
|
2252
2273
|
id,
|
|
2274
|
+
name,
|
|
2253
2275
|
expression,
|
|
2254
2276
|
value
|
|
2255
2277
|
}) {
|
|
2256
2278
|
return /* @__PURE__ */ jsxs("div", { className: "cdl-ip-item cdl-ip-formula", "data-cdl-formula": id, children: [
|
|
2257
|
-
/* @__PURE__ */ jsx("span", { className: "cdl-ip-label", children:
|
|
2279
|
+
/* @__PURE__ */ jsx("span", { className: "cdl-ip-label", children: name }),
|
|
2258
2280
|
/* @__PURE__ */ jsxs("code", { className: "cdl-ip-formula-expr", children: [
|
|
2259
2281
|
"= ",
|
|
2260
2282
|
expression
|
|
@@ -2262,11 +2284,11 @@ function FormulaReadout({
|
|
|
2262
2284
|
/* @__PURE__ */ jsx("span", { className: "cdl-ip-formula-value", children: String(value ?? "") })
|
|
2263
2285
|
] });
|
|
2264
2286
|
}
|
|
2265
|
-
function ScrollReadout({ id, progress }) {
|
|
2287
|
+
function ScrollReadout({ id, name, progress }) {
|
|
2266
2288
|
const p = typeof progress === "number" ? progress : 0;
|
|
2267
2289
|
const pct = Math.round(p * 100);
|
|
2268
2290
|
return /* @__PURE__ */ jsxs("div", { className: "cdl-ip-item cdl-ip-scroll", "data-cdl-scroll": id, children: [
|
|
2269
|
-
/* @__PURE__ */ jsx("span", { className: "cdl-ip-label", children:
|
|
2291
|
+
/* @__PURE__ */ jsx("span", { className: "cdl-ip-label", children: name }),
|
|
2270
2292
|
/* @__PURE__ */ jsx("div", { className: "cdl-ip-scroll-track", children: /* @__PURE__ */ jsx("div", { className: "cdl-ip-scroll-fill", style: { width: `${pct}%` } }) }),
|
|
2271
2293
|
/* @__PURE__ */ jsxs("span", { className: "cdl-ip-scroll-value", children: [
|
|
2272
2294
|
pct,
|
|
@@ -10315,7 +10337,7 @@ function diagram(id, options) {
|
|
|
10315
10337
|
return api;
|
|
10316
10338
|
}
|
|
10317
10339
|
},
|
|
10318
|
-
formula(formulaId, expression) {
|
|
10340
|
+
formula(formulaId, expression, opts) {
|
|
10319
10341
|
assertUniqueFormulaId(formulaId);
|
|
10320
10342
|
try {
|
|
10321
10343
|
parseFormula(expression);
|
|
@@ -10323,10 +10345,10 @@ function diagram(id, options) {
|
|
|
10323
10345
|
const msg = e instanceof Error ? e.message : String(e);
|
|
10324
10346
|
throw new Error(`formula '${formulaId}' \u306E expression syntax error: ${msg}`);
|
|
10325
10347
|
}
|
|
10326
|
-
formulas.push({ id: formulaId, expression });
|
|
10348
|
+
formulas.push({ id: formulaId, expression, ...opts?.label ? { label: opts.label } : {} });
|
|
10327
10349
|
return api;
|
|
10328
10350
|
},
|
|
10329
|
-
deriveChain(baseId, count, exprFn) {
|
|
10351
|
+
deriveChain(baseId, count, exprFn, opts) {
|
|
10330
10352
|
if (!Number.isInteger(count) || count < 1 || count > 100) {
|
|
10331
10353
|
throw new Error(`deriveChain: count (${count}) \u306F 1..100 \u306E\u6574\u6570\u3067\u3042\u308B\u5FC5\u8981\u304C\u3042\u308A\u307E\u3059`);
|
|
10332
10354
|
}
|
|
@@ -10342,7 +10364,8 @@ function diagram(id, options) {
|
|
|
10342
10364
|
const msg = e instanceof Error ? e.message : String(e);
|
|
10343
10365
|
throw new Error(`deriveChain '${id2}' \u306E expression syntax error: ${msg}`);
|
|
10344
10366
|
}
|
|
10345
|
-
|
|
10367
|
+
const label = opts?.label?.(i);
|
|
10368
|
+
formulas.push({ id: id2, expression: expr, ...label ? { label } : {} });
|
|
10346
10369
|
prev = id2;
|
|
10347
10370
|
}
|
|
10348
10371
|
return api;
|