@cardenelabs/dragon 0.10.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/index.cjs +25 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +9 -1
- package/dist/index.d.ts +9 -1
- package/dist/index.js +25 -6
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/compile.ts +23 -15
- package/src/index.ts +1 -1
- package/src/v05/parser.ts +25 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cardenelabs/dragon",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0",
|
|
4
4
|
"description": "Dragon — Mermaid 感覚で animated SVG を生成する Text DSL。 cdl engine を内部利用。",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "cardene777",
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
"prepublishOnly": "pnpm run typecheck && pnpm run test && pnpm run build"
|
|
57
57
|
},
|
|
58
58
|
"dependencies": {
|
|
59
|
-
"@cardenelabs/cdl": "^0.
|
|
59
|
+
"@cardenelabs/cdl": "^0.13.1"
|
|
60
60
|
},
|
|
61
61
|
"peerDependencies": {
|
|
62
62
|
"react": "^19.0.0",
|
package/src/compile.ts
CHANGED
|
@@ -4645,7 +4645,9 @@ function compileTree(doc: DslDocument, onNotice?: (n: CompileNotice) => void): C
|
|
|
4645
4645
|
const data: NonNullable<CdlDiagram["nodes"][number]["treeData"]> = doc.actors.map((a) => {
|
|
4646
4646
|
const id = slugify(a.name);
|
|
4647
4647
|
const p3 = 親.get(id);
|
|
4648
|
-
|
|
4648
|
+
// 木も放射と同じく名前と補足を分けて渡す (#1332)。 分けないと補足が捨てられ、
|
|
4649
|
+
// 書いた文字が図に出ない
|
|
4650
|
+
return { id, ...放射に出す文字(a), ...(p3 !== undefined ? { parent: p3 } : {}) };
|
|
4649
4651
|
});
|
|
4650
4652
|
b.node(`${slugify(doc.title) || "tree"}-chart`, {
|
|
4651
4653
|
lane: "chart", stack: 0, kind: "tree-hierarchy", title: doc.title, ...図の小見出し(doc), w: W, h: H, treeData: data,
|
|
@@ -4997,14 +4999,13 @@ type 放射で描ける欄 =
|
|
|
4997
4999
|
/** 中心の名前 / 枝の名前になる */
|
|
4998
5000
|
| "name"
|
|
4999
5001
|
/**
|
|
5000
|
-
*
|
|
5002
|
+
* 名前とは分けて補足に出す 2 欄。
|
|
5001
5003
|
*
|
|
5002
5004
|
* `- 描く量を減らす: "{draw} ms"` の形は副題として解析されるため、 値の欄だけを見ると
|
|
5003
5005
|
* 記法で最も普通な書き方が届かない (#1230 で実測)。 明示的に書いた値の欄も同じ場所へ出す。
|
|
5004
5006
|
*
|
|
5005
|
-
*
|
|
5006
|
-
*
|
|
5007
|
-
* (`resolveMindData`)。 届ける先が他に無いため名前と同じ欄へ載せる。
|
|
5007
|
+
* 描画側は枝の `subtitle` と中心の `rootSubtitle` を名前とは別の行に描く。 2 欄を
|
|
5008
|
+
* `放射に出す文字` で 1 つの補足にまとめ、 名前とは分けて渡す。
|
|
5008
5009
|
*/
|
|
5009
5010
|
| "subtitle"
|
|
5010
5011
|
| "value"
|
|
@@ -5115,18 +5116,17 @@ function 放射で描けない欄を書いたか(a: DslActor, 欄: 放射で描
|
|
|
5115
5116
|
}
|
|
5116
5117
|
|
|
5117
5118
|
/**
|
|
5118
|
-
*
|
|
5119
|
+
* 放射と木の箱に出す名前と補足 (#1332)。
|
|
5119
5120
|
*
|
|
5120
|
-
*
|
|
5121
|
-
*
|
|
5121
|
+
* **連結しない**。 描画側は名前と補足を別々に受け取れば箱の中で 2 行に積む。 1 つの文字列に
|
|
5122
|
+
* すると 1 行に全部入り、箱幅を超えて末尾が切られる (実測 = 箱 120px に対し文字 163px)。
|
|
5122
5123
|
*
|
|
5123
|
-
*
|
|
5124
|
-
*
|
|
5125
|
-
* `title` と `rootTitle` に限る (`resolveMindData`)。 値を別の欄へ渡しても絵に出ない。
|
|
5124
|
+
* `subtitle` と `value` の両方が書かれた場合は空白で繋いで 1 つの補足にする。 描画側の
|
|
5125
|
+
* 補足は 1 行なので、2 つを別々の行にはできない。
|
|
5126
5126
|
*/
|
|
5127
|
-
function 放射に出す文字(a: DslActor): string {
|
|
5127
|
+
function 放射に出す文字(a: DslActor): { title: string; subtitle?: string } {
|
|
5128
5128
|
const 続き = [a.subtitle, a.value].map((x) => x?.trim()).filter((x): x is string => !!x);
|
|
5129
|
-
return 続き.length > 0 ?
|
|
5129
|
+
return { title: a.name, ...(続き.length > 0 ? { subtitle: 続き.join(" ") } : {}) };
|
|
5130
5130
|
}
|
|
5131
5131
|
|
|
5132
5132
|
function compileMind(doc: DslDocument, onNotice?: (n: CompileNotice) => void): CdlDiagram {
|
|
@@ -5246,7 +5246,7 @@ function compileMind(doc: DslDocument, onNotice?: (n: CompileNotice) => void): C
|
|
|
5246
5246
|
// 枝は色を持てる (`MindBranchNode.tone`)
|
|
5247
5247
|
branches.push({
|
|
5248
5248
|
id,
|
|
5249
|
-
|
|
5249
|
+
...放射に出す文字(a),
|
|
5250
5250
|
parent: 親.get(id) ?? rootId,
|
|
5251
5251
|
...(a.tone ? { tone: a.tone } : {}),
|
|
5252
5252
|
});
|
|
@@ -5269,7 +5269,15 @@ function compileMind(doc: DslDocument, onNotice?: (n: CompileNotice) => void): C
|
|
|
5269
5269
|
...図の小見出し(doc),
|
|
5270
5270
|
w: W,
|
|
5271
5271
|
h: H,
|
|
5272
|
-
mindData:
|
|
5272
|
+
mindData: (() => {
|
|
5273
|
+
const 中心 = 放射に出す文字(root);
|
|
5274
|
+
return {
|
|
5275
|
+
rootId,
|
|
5276
|
+
rootTitle: 中心.title,
|
|
5277
|
+
...(中心.subtitle === undefined ? {} : { rootSubtitle: 中心.subtitle }),
|
|
5278
|
+
branches,
|
|
5279
|
+
};
|
|
5280
|
+
})(),
|
|
5273
5281
|
});
|
|
5274
5282
|
return b.build();
|
|
5275
5283
|
}
|
package/src/index.ts
CHANGED
|
@@ -13,7 +13,7 @@ export { compileToCdl } from "./compile";
|
|
|
13
13
|
export type { CompileNotice } from "./compile";
|
|
14
14
|
export { parseTextDslV05 } from "./v05";
|
|
15
15
|
// 記法一覧が「実際に受け付ける値」 を実装から引くための公開。 手書きすると説明と実装がずれる。
|
|
16
|
-
export { DRAW_TARGETS, DRAW_WORDS, PRESET_TYPES, TOP_LEVEL_KEYS } from "./v05/parser";
|
|
16
|
+
export { DRAW_TARGETS, DRAW_WORDS, PHASE_ITEM_WORDS, PRESET_TYPES, TOP_LEVEL_KEYS } from "./v05/parser";
|
|
17
17
|
export { TONE_ALIAS, NODE_KIND_ALIAS } from "./keywords";
|
|
18
18
|
export { lintDiagram, autoFix } from "./notation-lint";
|
|
19
19
|
export type { LintIssue, LintReport, LintSeverity } from "./notation-lint";
|
package/src/v05/parser.ts
CHANGED
|
@@ -2174,6 +2174,18 @@ function ensureAnimate(a: DslAnimate | undefined, lineNo: number): DslAnimate {
|
|
|
2174
2174
|
return { states: [], phases: [], pos: { line: lineNo } };
|
|
2175
2175
|
}
|
|
2176
2176
|
|
|
2177
|
+
/**
|
|
2178
|
+
* 段に書ける項目の英語名。 `parsePhase` が受け付ける名前の入口でも使う。
|
|
2179
|
+
*
|
|
2180
|
+
* 誤りの案内で使うほか、**見本が値の名前にこの語を使っていないか** を見るのにも使う
|
|
2181
|
+
* (#1330)。 段の項目と値は階層が違うので衝突しないが、同じ語が 2 つの意味で並ぶと
|
|
2182
|
+
* 見本を読む人が階層から意味を判断することになる。
|
|
2183
|
+
*/
|
|
2184
|
+
export const PHASE_ITEM_WORDS = ["focus", "badge", "body", "description", "tween", "set", "draw"] as const;
|
|
2185
|
+
|
|
2186
|
+
const 段の項目の英語 = PHASE_ITEM_WORDS;
|
|
2187
|
+
const 段の項目の集合: ReadonlySet<string> = new Set(PHASE_ITEM_WORDS);
|
|
2188
|
+
|
|
2177
2189
|
function parsePhase(block: Line[], errors: DslError[]): DslPhase | null {
|
|
2178
2190
|
// block[0]!: `step: "request" 1.5s`
|
|
2179
2191
|
const head = block[0]!;
|
|
@@ -2220,6 +2232,17 @@ function parsePhase(block: Line[], errors: DslError[]): DslPhase | null {
|
|
|
2220
2232
|
}
|
|
2221
2233
|
const key = (propMatch[1] ?? "").toLowerCase();
|
|
2222
2234
|
const value = (propMatch[2] ?? "").trim();
|
|
2235
|
+
// 一覧を parse の入口にも使う。 分岐だけを増やして一覧を更新し忘れると、見本の名前との
|
|
2236
|
+
// 重なり検査が新しい項目を見落とすため、一覧にない語は各分岐へ到達させない。
|
|
2237
|
+
if (!段の項目の集合.has(key)) {
|
|
2238
|
+
errors.push({
|
|
2239
|
+
line: ln.no,
|
|
2240
|
+
message: `段の項目名が読めません: "${propMatch[1] ?? ""}"`,
|
|
2241
|
+
hint: 段の項目のヒント(propMatch[1] ?? ""),
|
|
2242
|
+
});
|
|
2243
|
+
i += 1;
|
|
2244
|
+
continue;
|
|
2245
|
+
}
|
|
2223
2246
|
if (key === "focus") {
|
|
2224
2247
|
phase.highlight = parseFocusList(value);
|
|
2225
2248
|
i += 1;
|
|
@@ -2304,8 +2327,8 @@ function parsePhase(block: Line[], errors: DslError[]): DslPhase | null {
|
|
|
2304
2327
|
i = j;
|
|
2305
2328
|
continue;
|
|
2306
2329
|
}
|
|
2307
|
-
//
|
|
2308
|
-
//
|
|
2330
|
+
// ここに来るのは一覧へ語を足したのに処理分岐を足していない時だけ。 黙って捨てると
|
|
2331
|
+
// 「一覧にはあるのに段が変わらない」 が手掛かりなしで起きる。
|
|
2309
2332
|
errors.push({
|
|
2310
2333
|
line: ln.no,
|
|
2311
2334
|
message: `段の項目名が読めません: "${propMatch[1] ?? ""}"`,
|
|
@@ -2329,9 +2352,6 @@ function 段の項目のヒント(書いた名前: string): string {
|
|
|
2329
2352
|
: `使える項目 = ${段の項目の英語.join(", ")}`;
|
|
2330
2353
|
}
|
|
2331
2354
|
|
|
2332
|
-
/** 段に書ける項目の英語名。 `parsePhase` の分岐から導く一覧 */
|
|
2333
|
-
const 段の項目の英語 = ["focus", "badge", "body", "description", "tween", "set", "draw"] as const;
|
|
2334
|
-
|
|
2335
2355
|
/**
|
|
2336
2356
|
* `draw:` に書ける語と、その語が効く図種 (#1312 / #1314)。
|
|
2337
2357
|
*
|