@cardenelabs/dragon 0.46.4 → 0.47.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.
Files changed (87) hide show
  1. package/README.ja.md +4 -2
  2. package/README.md +4 -2
  3. package/dist/cli.cjs +71 -70
  4. package/dist/cli.cjs.map +1 -1
  5. package/dist/cli.js +71 -70
  6. package/dist/cli.js.map +1 -1
  7. package/dist/export.cjs +13 -10
  8. package/dist/export.cjs.map +1 -1
  9. package/dist/export.d.cts +2 -2
  10. package/dist/export.d.ts +2 -2
  11. package/dist/export.js +13 -10
  12. package/dist/export.js.map +1 -1
  13. package/dist/index.cjs +10 -9
  14. package/dist/index.cjs.map +1 -1
  15. package/dist/index.d.cts +5 -5
  16. package/dist/index.d.ts +5 -5
  17. package/dist/index.js +10 -9
  18. package/dist/index.js.map +1 -1
  19. package/dist/{ink-DeDtzaTL.d.cts → ink-Sz5_zWte.d.cts} +1 -1
  20. package/dist/{ink-DeDtzaTL.d.ts → ink-Sz5_zWte.d.ts} +1 -1
  21. package/dist/light/{chunk-YO3UBEC3.js → chunk-AHUJ37R3.js} +4 -3
  22. package/dist/light/chunk-AHUJ37R3.js.map +1 -0
  23. package/dist/light/{chunk-SUL4AJLI.cjs → chunk-KNA5HH2H.cjs} +85 -2
  24. package/dist/light/chunk-KNA5HH2H.cjs.map +1 -0
  25. package/dist/light/{chunk-V34DCH34.cjs → chunk-O7RQ6R54.cjs} +84 -83
  26. package/dist/light/chunk-O7RQ6R54.cjs.map +1 -0
  27. package/dist/light/{chunk-DVGDEPCV.js → chunk-VUVRSYH6.js} +84 -1
  28. package/dist/light/chunk-VUVRSYH6.js.map +1 -0
  29. package/dist/light/{git-WBGFDRBD.cjs → git-M63KYUUK.cjs} +66 -68
  30. package/dist/light/git-M63KYUUK.cjs.map +1 -0
  31. package/dist/light/{git-WEJL6VAY.js → git-NMPPSCRM.js} +4 -6
  32. package/dist/light/{git-WEJL6VAY.js.map → git-NMPPSCRM.js.map} +1 -1
  33. package/dist/light/index.cjs +292 -293
  34. package/dist/light/index.cjs.map +1 -1
  35. package/dist/light/index.d.cts +4 -4
  36. package/dist/light/index.d.ts +4 -4
  37. package/dist/light/index.js +41 -42
  38. package/dist/light/index.js.map +1 -1
  39. package/dist/light/{lineup-WLGNGTFX.cjs → lineup-2VWQ74CU.cjs} +42 -44
  40. package/dist/light/lineup-2VWQ74CU.cjs.map +1 -0
  41. package/dist/light/{lineup-6LN6Z5T2.js → lineup-HZ5YTQ36.js} +4 -6
  42. package/dist/light/{lineup-6LN6Z5T2.js.map → lineup-HZ5YTQ36.js.map} +1 -1
  43. package/dist/light/{state-JVAH4TSM.cjs → state-MFCHMESP.cjs} +42 -44
  44. package/dist/light/state-MFCHMESP.cjs.map +1 -0
  45. package/dist/light/{state-DFYTMQI7.js → state-RRAJPRO3.js} +3 -5
  46. package/dist/light/{state-DFYTMQI7.js.map → state-RRAJPRO3.js.map} +1 -1
  47. package/dist/light/{time-M3EGEFDU.js → time-7V7RUEYS.js} +5 -4
  48. package/dist/light/time-7V7RUEYS.js.map +1 -0
  49. package/dist/light/{time-EXRPI34B.cjs → time-RISQEAB7.cjs} +86 -85
  50. package/dist/light/time-RISQEAB7.cjs.map +1 -0
  51. package/dist/light/{tree-MFU54QKY.js → tree-PWSU7R6R.js} +3 -3
  52. package/dist/light/{tree-DECHTXFU.cjs → tree-S23P2PW7.cjs} +62 -62
  53. package/dist/light/tree-S23P2PW7.cjs.map +1 -0
  54. package/dist/node.cjs +5 -2
  55. package/dist/node.cjs.map +1 -1
  56. package/dist/node.js +5 -2
  57. package/dist/node.js.map +1 -1
  58. package/dist/player.global.js +3 -3
  59. package/package.json +1 -1
  60. package/src/cli.ts +10 -10
  61. package/src/export/index.ts +3 -3
  62. package/src/figure-text.ts +2 -2
  63. package/src/kinds/registry.ts +2 -2
  64. package/src/layout/time.ts +2 -2
  65. package/src/messages.ts +1 -1
  66. package/src/parser.ts +3 -2
  67. package/src/player.ts +3 -2
  68. package/src/render/draw.ts +4 -4
  69. package/src/render/ink.ts +2 -2
  70. package/src/schema.ts +4 -4
  71. package/src/version.ts +3 -3
  72. package/src/words.ts +6 -0
  73. package/dist/light/chunk-CLS6JVKK.cjs +0 -84
  74. package/dist/light/chunk-CLS6JVKK.cjs.map +0 -1
  75. package/dist/light/chunk-DVGDEPCV.js.map +0 -1
  76. package/dist/light/chunk-SUL4AJLI.cjs.map +0 -1
  77. package/dist/light/chunk-V34DCH34.cjs.map +0 -1
  78. package/dist/light/chunk-YDKPEKGZ.js +0 -84
  79. package/dist/light/chunk-YDKPEKGZ.js.map +0 -1
  80. package/dist/light/chunk-YO3UBEC3.js.map +0 -1
  81. package/dist/light/git-WBGFDRBD.cjs.map +0 -1
  82. package/dist/light/lineup-WLGNGTFX.cjs.map +0 -1
  83. package/dist/light/state-JVAH4TSM.cjs.map +0 -1
  84. package/dist/light/time-EXRPI34B.cjs.map +0 -1
  85. package/dist/light/time-M3EGEFDU.js.map +0 -1
  86. package/dist/light/tree-DECHTXFU.cjs.map +0 -1
  87. /package/dist/light/{tree-MFU54QKY.js.map → tree-PWSU7R6R.js.map} +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cardenelabs/dragon",
3
- "version": "0.46.4",
3
+ "version": "0.47.0",
4
4
  "description": "Animated diagrams that people write in a plain notation and AI writes as JSON. Plays on a page and exports MP4, GIF, HTML, and PNG.",
5
5
  "license": "MIT",
6
6
  "author": "cardene777",
package/src/cli.ts CHANGED
@@ -5,7 +5,7 @@
5
5
  * 図に字の重なりがある時は、書き出したうえで重なりを段と文で 1 件 1 行ずつ標準エラーに出し、終わり方は 0 のままにする (#3178)。
6
6
  * 重なりは描けない誤りではなく、止めると避けられない重なりを持つ図を書き出せなくなるため。
7
7
  *
8
- * 使い方の文と誤りの文は、図の中の字と同じ言葉で出す (#3003)。`--lang` を渡せばその言葉、無ければ日本語。
8
+ * 使い方の文と誤りの文は、図の中の字と同じ言葉で出す (#3003)。`--lang` を渡せばその言葉、無ければ英語 (#3338)。
9
9
  * dragon記法の語は英語だけで file から言葉が決まらないため、記法の file も JSON の原本と同じに扱う (#3137)。
10
10
  */
11
11
  import { readFileSync } from "node:fs";
@@ -15,7 +15,7 @@ import { type ExportFormat, exportDiagram, FORMATS } from "./export/index";
15
15
  import { PALETTES, type Theme } from "./look/values";
16
16
  import { parseNotation } from "./parser";
17
17
  import { describeOverlap } from "./render/ink";
18
- import type { NotationLang } from "./words";
18
+ import { DEFAULT_LANG, type NotationLang } from "./words";
19
19
 
20
20
  const OPTIONS = {
21
21
  out: { type: "string" },
@@ -59,7 +59,7 @@ const CLI_TEXT: Record<NotationLang, CliText> = {
59
59
  " --width <px> 枠の幅。見せ方を選び、寄って見せる窓の幅になる",
60
60
  ` --palette <名前> 色味 (${PALETTE_NAMES})`,
61
61
  " --theme <明暗> light か dark",
62
- " --lang <言葉> 図の中の字と命令の文の言葉 (ja か en)。既定は ja",
62
+ " --lang <言葉> 図の中の字と命令の文の言葉 (ja か en)。既定は en",
63
63
  " --fps <数> mp4 の 1 秒のコマの数 (既定 30)",
64
64
  " --gif-fps <数> GIF の 1 秒のコマの数 (既定 10)",
65
65
  " --format <形> 書き出す形を , で区切る (既定 mp4,gif,html,png)",
@@ -82,7 +82,7 @@ const CLI_TEXT: Record<NotationLang, CliText> = {
82
82
  " --width <px> Frame width. Picks the view and sets the window width when following",
83
83
  ` --palette <name> Colors (${PALETTE_NAMES})`,
84
84
  " --theme <mode> light or dark",
85
- " --lang <lang> Language of the diagram text and command messages (ja or en). Defaults to ja",
85
+ " --lang <lang> Language of the diagram text and command messages (ja or en). Defaults to en",
86
86
  " --fps <n> Frames per second of the mp4 (default 30)",
87
87
  " --gif-fps <n> Frames per second of the GIF (default 10)",
88
88
  " --format <list> Formats to write, separated by , (default mp4,gif,html,png)",
@@ -178,8 +178,8 @@ function read(file: string, text: CliText, lang: NotationLang): unknown {
178
178
  async function main(argv: string[]): Promise<number> {
179
179
  const [command, ...rest] = argv;
180
180
  const chosen = langOf(argv);
181
- // file を読む前の文は、渡した言葉か日本語で出す。知らない言葉は日本語の使い方で断る
182
- const early = CLI_TEXT[isLang(chosen) ? chosen : "ja"];
181
+ // file を読む前の文は、渡した言葉か既定の英語で出す。知らない言葉は英語の使い方で断る
182
+ const early = CLI_TEXT[isLang(chosen) ? chosen : DEFAULT_LANG];
183
183
  if (command !== "export") {
184
184
  console.error(early.usage);
185
185
  return 2;
@@ -208,9 +208,9 @@ async function main(argv: string[]): Promise<number> {
208
208
  const width = number(values.width);
209
209
  const fps = number(values.fps);
210
210
  const gifFps = number(values["gif-fps"]);
211
- // 言葉は渡した物だけで決める。渡さなければ、書き出しの既定 (日本語) になる
211
+ // 言葉は渡した物だけで決める。渡さなければ、書き出しの既定 (英語) になる
212
212
  const lang = isLang(chosen) ? chosen : undefined;
213
- const diagram = read(file, early, lang ?? "ja");
213
+ const diagram = read(file, early, lang ?? DEFAULT_LANG);
214
214
  let result: Awaited<ReturnType<typeof exportDiagram>>;
215
215
  try {
216
216
  result = await exportDiagram(diagram, {
@@ -227,11 +227,11 @@ async function main(argv: string[]): Promise<number> {
227
227
  } catch (error) {
228
228
  // 書き出し先に書けない時だけ命令の言葉で書き直す。描けない時と道具が無い時の断りは、書き出しが言葉に合わせて出す (#3009)
229
229
  const path = failedPath(error);
230
- if (path !== undefined) throw new Error(CLI_TEXT[lang ?? "ja"].cannotWrite(path, detail(error)));
230
+ if (path !== undefined) throw new Error(CLI_TEXT[lang ?? DEFAULT_LANG].cannotWrite(path, detail(error)));
231
231
  throw error instanceof Error ? error : new Error(String(error));
232
232
  }
233
233
  for (const path of Object.values(result.files)) console.log(path);
234
- const said = lang ?? "ja";
234
+ const said = lang ?? DEFAULT_LANG;
235
235
  for (const overlap of result.overlaps) console.error(CLI_TEXT[said].overlap(overlap.step + 1, describeOverlap(overlap, said)));
236
236
  return 0;
237
237
  }
@@ -14,7 +14,7 @@ import type { Overlap } from "../render/ink";
14
14
  import { drawSvg, type Rendered, renderDiagram } from "../render/svg";
15
15
  import type { ViewMode } from "../schema";
16
16
  import { chooseView } from "../view";
17
- import type { NotationLang } from "../words";
17
+ import { DEFAULT_LANG, type NotationLang } from "../words";
18
18
  import { film, launch, sizeOf, stage, still } from "./capture";
19
19
  import { charsOf, fontFaces } from "./fonts";
20
20
  import { pageHtml } from "./html";
@@ -36,7 +36,7 @@ export interface ExportOptions {
36
36
  fps?: number;
37
37
  /** GIF の 1 秒のコマの数 */
38
38
  gifFps?: number;
39
- /** 図の中の字 (全体図の札、HTML の読み上げの名前、描けない時の断りの文) の言葉。書かなければ日本語 (#3001) */
39
+ /** 図の中の字 (全体図の札、HTML の読み上げの名前、描けない時の断りの文) の言葉。書かなければ英語 (#3001、#3338) */
40
40
  lang?: NotationLang;
41
41
  }
42
42
 
@@ -72,7 +72,7 @@ function drawnTexts(rendered: Rendered, followSvg: string | undefined): string[]
72
72
 
73
73
  export async function exportDiagram(input: unknown, options: ExportOptions): Promise<ExportResult> {
74
74
  const formats = options.formats ?? FORMATS;
75
- const lang = options.lang ?? "ja";
75
+ const lang = options.lang ?? DEFAULT_LANG;
76
76
  const rendered = renderDiagram(input, {
77
77
  ...(options.palette ? { palette: options.palette } : {}),
78
78
  ...(options.theme ? { theme: options.theme } : {}),
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * 描く部品が出す字 (#3001)。
3
3
  *
4
- * 図の原本は語を持たないので、呼ぶ側が言葉を渡す。渡さなければ日本語で出す。
5
- * 頁は頁の言葉を、`dragon export` は `--lang` の言葉 (渡さなければ日本語) を渡す。
4
+ * 図の原本は語を持たないので、呼ぶ側が言葉を渡す。渡さなければ英語で出す (#3338)。
5
+ * 頁は頁の言葉を、`dragon export` は `--lang` の言葉 (渡さなければ英語) を渡す。
6
6
  */
7
7
  import type { NotationLang } from "./words";
8
8
 
@@ -6,7 +6,7 @@
6
6
  * 時系列図と構成図の部品は登録せず、描く所が直に読む。
7
7
  */
8
8
  import { FIGURE_TEXT } from "../figure-text";
9
- import type { NotationLang } from "../words";
9
+ import { DEFAULT_LANG, type NotationLang } from "../words";
10
10
  import type * as git from "./git";
11
11
  import type * as lineup from "./lineup";
12
12
  import type * as state from "./state";
@@ -39,7 +39,7 @@ export function kindLoaded(kind: string | undefined): boolean {
39
39
  }
40
40
 
41
41
  /** 種類の部品。読んでいない時は、種類の名前を含む誤りで止まる */
42
- export function kindParts<K extends LaterKind>(kind: K, lang: NotationLang = "ja"): LaterKinds[K] {
42
+ export function kindParts<K extends LaterKind>(kind: K, lang: NotationLang = DEFAULT_LANG): LaterKinds[K] {
43
43
  const parts = registered[kind];
44
44
  if (parts === undefined) throw new Error(FIGURE_TEXT[lang].kindNotLoaded(kind));
45
45
  return parts;
@@ -11,7 +11,7 @@
11
11
  import { FIGURE_TEXT } from "../figure-text";
12
12
  import { COLOR_ORDER, type ColorKey, LOOK, TYPE } from "../look/values";
13
13
  import type { Diagram, DiagramEvent } from "../schema";
14
- import type { NotationLang } from "../words";
14
+ import { DEFAULT_LANG, type NotationLang } from "../words";
15
15
  import { textBox, textWidth } from "./measure";
16
16
  import {
17
17
  badgeOnPath,
@@ -219,7 +219,7 @@ function needleSteps(diagram: Diagram): [number, number][] {
219
219
  });
220
220
  }
221
221
 
222
- export function layoutTime(diagram: Diagram, lang: NotationLang = "ja"): TimeLayout {
222
+ export function layoutTime(diagram: Diagram, lang: NotationLang = DEFAULT_LANG): TimeLayout {
223
223
  const T = LOOK.time;
224
224
  const { margin, gap } = LOOK;
225
225
  const R = LOOK.region;
package/src/messages.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  * dragon記法の誤りの文 (#2997、#3137)。
3
3
  *
4
4
  * 記法の語は英語だけで file から言葉が決まらないため、誤りの文は呼ぶ側が渡した言葉
5
- * (渡さなければ日本語) で出す。文の中の記法の語は語の表から引き、表と文で語が食い違わないようにする。
5
+ * (渡さなければ英語) で出す。文の中の記法の語は語の表から引き、表と文で語が食い違わないようにする。
6
6
  */
7
7
  import { nearest } from "./nearest";
8
8
  import { COLORS, ICON_NAMES } from "./schema";
package/src/parser.ts CHANGED
@@ -95,6 +95,7 @@ import {
95
95
  ATTRS,
96
96
  CARRIES,
97
97
  COPY,
98
+ DEFAULT_LANG,
98
99
  FROM,
99
100
  HEAD,
100
101
  HEADS,
@@ -127,7 +128,7 @@ export interface LineError {
127
128
  export type Parsed = { ok: true; diagram: Diagram } | { ok: false; errors: LineError[] };
128
129
 
129
130
  export interface ParseOptions {
130
- /** 誤りの文の言葉。既定は日本語 */
131
+ /** 誤りの文の言葉。既定は英語 (#3338) */
131
132
  lang?: NotationLang;
132
133
  }
133
134
 
@@ -1334,7 +1335,7 @@ function parseLines(lines: SourceLine[], m: Messages): Diagram {
1334
1335
 
1335
1336
  export function parseNotation(notation: string, options: ParseOptions = {}): Parsed {
1336
1337
  try {
1337
- return { ok: true, diagram: parseLines(tokenize(notation), messagesFor(options.lang ?? "ja")) };
1338
+ return { ok: true, diagram: parseLines(tokenize(notation), messagesFor(options.lang ?? DEFAULT_LANG)) };
1338
1339
  } catch (error) {
1339
1340
  if (!(error instanceof NotationError)) throw error;
1340
1341
  return { ok: false, errors: [{ line: error.line, column: error.column, message: error.message }] };
package/src/player.ts CHANGED
@@ -5,7 +5,7 @@
5
5
  * 段ごとの止め絵を釦で送る。各段の題と本文と出典は、読み上げの道具が段の順に読める番号付きの一覧として置き、
6
6
  * 図そのものは読み上げから隠して同じ中身を 2 度読ませない。
7
7
  * 見せ方は枠の幅で選び (`view.ts`)、寄って追う時は窓と全体図で描き直す。
8
- * 釦と段の一覧の読み上げの名前と全体図の札は、渡した言葉 (`options.lang`、書かなければ日本語) で出す (#3001)。
8
+ * 釦と段の一覧の読み上げの名前と全体図の札は、渡した言葉 (`options.lang`、書かなければ英語) で出す (#3001)。
9
9
  * 色は `options.palette` の名前の色味に `options.colors` の色の値を重ね、図と全体図と釦と段の帯を同じ色で塗る (#3198)。
10
10
  * 段が替わるたびに `options.onStep` で今の段を知らせ、頁の側が段の札や進み具合を出せるようにする (#3031)。
11
11
  * 置いた時に流さず決めた段で止めて置く (`options.pausedAt`) ことと、1 度だけ流して最後の段で止める (`options.playOnce`) ことを選べる。
@@ -21,6 +21,7 @@ import { FONT_VARS, LOOK, paletteVars, type TextStyle, TYPE } from "./look/value
21
21
  import { drawSvg, paletteOf, type RenderOptions, renderDiagram } from "./render/draw";
22
22
  import type { Span } from "./timeline";
23
23
  import { chooseView } from "./view";
24
+ import { DEFAULT_LANG } from "./words";
24
25
 
25
26
  export interface PlayerOptions extends RenderOptions {
26
27
  /** 段が替わるたびに今の段 (0 から) を受け取る。置いた時にも最初の段で 1 度呼ぶ。頁の側で段の札や進み具合を出す時に使う (#3031) */
@@ -120,7 +121,7 @@ export function mountDiagram(host: HTMLElement, diagram: unknown, options: Playe
120
121
  // 描く前に読む。描いた後に読むと、動きを嫌う人にも一瞬だけ流れてしまう
121
122
  const reduce = Boolean(win?.matchMedia?.("(prefers-reduced-motion: reduce)").matches);
122
123
  const rendered = renderDiagram(diagram, options);
123
- const lang = options.lang ?? "ja";
124
+ const lang = options.lang ?? DEFAULT_LANG;
124
125
  const words = FIGURE_TEXT[lang];
125
126
  const palette = paletteOf(options, rendered.theme);
126
127
  const { timeline } = rendered;
@@ -22,7 +22,7 @@ import { type ColorKey, type Colors, EASE, FONT_VARS, isColorName, isColorValue,
22
22
  import { readDiagram } from "../version";
23
23
  import type { Diagram, ViewMode } from "../schema";
24
24
  import { buildTimeline, type LabelTime, type Span, type Timeline } from "../timeline";
25
- import type { NotationLang } from "../words";
25
+ import { DEFAULT_LANG, type NotationLang } from "../words";
26
26
  import {
27
27
  action,
28
28
  badge,
@@ -65,7 +65,7 @@ export interface RenderOptions {
65
65
  */
66
66
  colors?: Colors;
67
67
  theme?: Theme;
68
- /** 描く部品が出す字 (断りの文、全体図の札、読み上げの名前) の言葉。書かなければ日本語 (#3001) */
68
+ /** 描く部品が出す字 (断りの文、全体図の札、読み上げの名前) の言葉。書かなければ英語 (#3001、#3338) */
69
69
  lang?: NotationLang;
70
70
  /**
71
71
  * 最後の段の止め絵に、全ての段の線の名前と箱の中の処理を最後の段と同じ濃さで出す (#3200)。途中の段の止め絵は今の段の名前だけを出す。
@@ -701,7 +701,7 @@ function followView(layout: Layout, timeline: Timeline, diagram: Diagram, m: Mot
701
701
  export function paletteOf(options: RenderOptions, theme: Theme): Palette {
702
702
  const palette = resolvePalette(options.palette);
703
703
  if (!options.colors) return palette;
704
- const words = FIGURE_TEXT[options.lang ?? "ja"];
704
+ const words = FIGURE_TEXT[options.lang ?? DEFAULT_LANG];
705
705
  const errors = Object.entries(options.colors).flatMap(([name, value]) => (!isColorName(name) ? [words.unknownColor(name)] : isColorValue(value) ? [] : [words.unreadableColor(name)]));
706
706
  if (errors.length > 0) throw new Error(words.cannotDraw(errors.join(" / ")));
707
707
  return { ...palette, [theme]: { ...palette[theme], ...options.colors } };
@@ -709,7 +709,7 @@ export function paletteOf(options: RenderOptions, theme: Theme): Palette {
709
709
 
710
710
  /** 原本の JSON から図を描く。原本が形に合わない時は、誤りの場所を添えて断る。 */
711
711
  export function renderDiagram(input: unknown, options: RenderOptions = {}): Rendered {
712
- const lang = options.lang ?? "ja";
712
+ const lang = options.lang ?? DEFAULT_LANG;
713
713
  const read = readDiagram(input, { lang });
714
714
  if (!read.ok) throw new Error(FIGURE_TEXT[lang].cannotDraw(read.errors.map((e) => `${e.pointer} ${e.message}`).join(" / ")));
715
715
  const diagram = read.diagram;
package/src/render/ink.ts CHANGED
@@ -14,7 +14,7 @@
14
14
  */
15
15
  import { FIGURE_TEXT } from "../figure-text";
16
16
  import { crossesRect, type Point, type Rect } from "../layout/scene";
17
- import type { NotationLang } from "../words";
17
+ import { DEFAULT_LANG, type NotationLang } from "../words";
18
18
 
19
19
  /** 見えている間。`[出る時刻, 消える時刻)` */
20
20
  export type Shown = [number, number];
@@ -95,7 +95,7 @@ export function findOverlaps(inks: Ink[], stills: number[], traces: Trace[] = []
95
95
  * 重なりを知らせる文 (#3178)。段の番号は「段の番号 N」と呼び、図の部品は言葉ごとの呼び方で呼び (#3184)、ほかの字は鉤括弧か引用符で囲む。
96
96
  * 段の番号は文に含めない
97
97
  */
98
- export function describeOverlap(overlap: Overlap, lang: NotationLang = "ja"): string {
98
+ export function describeOverlap(overlap: Overlap, lang: NotationLang = DEFAULT_LANG): string {
99
99
  const t = FIGURE_TEXT[lang];
100
100
  const partName = (part: InkPart): string => (part.kind === "icon" ? t.iconOf(part.box) : part.kind === "coin" ? t.coin : t.envelope);
101
101
  const name = (spot: OverlapSpot): string => (spot.badge ? t.badgeName(spot.text) : spot.part ? partName(spot.part) : t.quoted(spot.text));
package/src/schema.ts CHANGED
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * 形の正は `schemas/diagram.schema.json` の 1 本で、下の型はその写し。
5
5
  * 誤りは JSON Pointer で場所を示す。欄が足りない時と知らない欄がある時は、その欄の場所まで示す。
6
- * 誤りの文は呼ぶ側が渡した言葉 (渡さなければ日本語) で出す。文の表は `field-messages.ts` が持つ (#2999)。
6
+ * 誤りの文は呼ぶ側が渡した言葉 (渡さなければ英語) で出す。文の表は `field-messages.ts` が持つ (#2999)。
7
7
  *
8
8
  * 検査の関数は schema から前もって書き出した物 (`schemas/validate-diagram.js`) を使う。
9
9
  * ajv に schema をその場で組み立てさせると `new Function` を使い、`eval` を許さない頁の CSP で止まる。
@@ -14,7 +14,7 @@ import { type Allowed, FIELD_MESSAGES, type FieldMessages, type Forbidden } from
14
14
  import { nearest } from "./nearest";
15
15
  import { ICONS } from "./render/icons";
16
16
  import validate from "./schemas/validate-diagram.js";
17
- import { type NotationLang, STATE_ENDS } from "./words";
17
+ import { DEFAULT_LANG, type NotationLang, STATE_ENDS } from "./words";
18
18
 
19
19
  export type Color = "blue" | "amber" | "green" | "violet" | "rose" | "slate" | "coin";
20
20
  /** 色の役の一覧。記法の `color:` に書ける値と、誤りの文に並べる値 */
@@ -236,7 +236,7 @@ export interface FieldError {
236
236
  export type Checked = { ok: true } | { ok: false; errors: FieldError[] };
237
237
 
238
238
  export interface CheckOptions {
239
- /** 誤りの文の言葉。渡さなければ日本語 */
239
+ /** 誤りの文の言葉。渡さなければ英語 (#3338) */
240
240
  lang?: NotationLang;
241
241
  }
242
242
 
@@ -407,7 +407,7 @@ export function validateDiagram(input: unknown, options: CheckOptions = {}): Che
407
407
  if (validate(input)) return { ok: true };
408
408
  const all = validate.errors ?? [];
409
409
  const inBranch = new Set(all.filter((error) => error.keyword === "anyOf").flatMap((anyOf) => branchesOf(anyOf, all)));
410
- const m = FIELD_MESSAGES[options.lang ?? "ja"];
410
+ const m = FIELD_MESSAGES[options.lang ?? DEFAULT_LANG];
411
411
  // 条件付きの決まり (if / then) は中で落ちた決まりの誤りを別に出すので、包む側の if の誤りは出さない
412
412
  const errors = all.filter((error) => error.keyword !== "if" && !inBranch.has(error)).map((error) => toFieldError(error, all, m, input));
413
413
  return { ok: false, errors };
package/src/version.ts CHANGED
@@ -8,7 +8,7 @@
8
8
  */
9
9
  import { FIELD_MESSAGES } from "./field-messages";
10
10
  import { type CheckOptions, type Diagram, type FieldError, validateDiagram } from "./schema";
11
- import type { NotationLang } from "./words";
11
+ import { DEFAULT_LANG, type NotationLang } from "./words";
12
12
 
13
13
  /** この道具が読める原本の版 */
14
14
  export const FORMAT_VERSION = 1;
@@ -26,10 +26,10 @@ const newerError = (version: number, lang: NotationLang): FieldError => ({
26
26
  message: FIELD_MESSAGES[lang].newer(version, FORMAT_VERSION),
27
27
  });
28
28
 
29
- /** 原本を読む。道具より新しい版は描かずに断り、形の誤りは検査の誤りとして返す。誤りの文は `options.lang` (渡さなければ日本語) で出す。 */
29
+ /** 原本を読む。道具より新しい版は描かずに断り、形の誤りは検査の誤りとして返す。誤りの文は `options.lang` (渡さなければ英語) で出す。 */
30
30
  export function readDiagram(input: unknown, options: CheckOptions = {}): Read {
31
31
  const newer = newerThanTool(input);
32
- if (newer !== undefined) return { ok: false, errors: [newerError(newer, options.lang ?? "ja")] };
32
+ if (newer !== undefined) return { ok: false, errors: [newerError(newer, options.lang ?? DEFAULT_LANG)] };
33
33
  const checked = validateDiagram(input, options);
34
34
  if (!checked.ok) return checked;
35
35
  return { ok: true, diagram: input as Diagram, warnings: [] };
package/src/words.ts CHANGED
@@ -13,6 +13,12 @@ import type { Carry, Diagram, LabelSide, ViewMode } from "./schema";
13
13
 
14
14
  export type NotationLang = "ja" | "en";
15
15
 
16
+ /**
17
+ * `lang` を渡さない時の言葉 (#3338)。外の人が例のまま使っても読める文が出るように英語にする。
18
+ * 日本語の文が要る時は `lang: "ja"` (命令は `--lang ja`) を渡す
19
+ */
20
+ export const DEFAULT_LANG: NotationLang = "en";
21
+
16
22
  const keys = <K extends string>(table: Record<K, true>): K[] => Object.keys(table) as K[];
17
23
 
18
24
  /** 図の種類。最初の行の頭の語 */
@@ -1,84 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/words.ts
2
- var keys = (table) => Object.keys(table);
3
- var KINDS = keys({ sequence: true, architecture: true, state: true, git: true, time: true, tree: true, lineup: true });
4
- var STATE_ENDS = ["start", "finish"];
5
- var TIME_HEADS = ["scale", "period", "row", "point", "zoom", "mark", "span"];
6
- var NOW = "now";
7
- var TREE_HEADS = ["leaf", "node"];
8
- var LINEUP_HEADS = ["item", "line", "seal", "open", "pick", "stamp"];
9
- var LANE_MOST = 12;
10
- var LABEL_MOST = 4;
11
- var LANE_ATTRS = ["note", "color"];
12
- var HEADS = ["group", "end", "box", "strip", "step", "say", "code", "source", "act", "note", "set", "branch", "commit", ...TIME_HEADS, ...TREE_HEADS, ...LINEUP_HEADS];
13
- var AS = "as";
14
- var ON = "on";
15
- var COPY = "copy";
16
- var MERGE = "merge";
17
- var FROM = "from";
18
- var HEAD = "HEAD";
19
- var AT = "at";
20
- var OF = "of";
21
- var ATTRS = {
22
- diagram: ["view"],
23
- group: ["note", "color", "icon"],
24
- box: ["note", "color", "icon", "link"],
25
- source: ["url"],
26
- edge: ["carry", "tag", "side", "at", "into"],
27
- note: ["color"],
28
- set: ["tag"],
29
- strip: ["meter"],
30
- branch: ["note"],
31
- commit: ["hash", "note"],
32
- leaf: ["hash"],
33
- node: ["hash"],
34
- item: ["color", "label"],
35
- scale: ["from"],
36
- period: ["from"],
37
- row: ["color", "empty"],
38
- mark: ["color"],
39
- span: ["shape", "color"]
40
- };
41
- var TIME_EDGE_ATTRS = ["at", "into"];
42
- var SPAN_SHAPES = ["box"];
43
- var DURATION_UNITS = ["ms", "s", "min", "h", "d"];
44
- var CARRIES = keys({ coin: true, none: true });
45
- var VIEWS = keys({ fixed: true, follow: true });
46
- var SIDES = keys({ above: true, below: true, left: true, right: true });
47
- var OLD_HEADS = {
48
- \u6642\u7CFB\u5217\u56F3: "sequence",
49
- \u69CB\u6210\u56F3: "architecture",
50
- \u533A\u753B: "group",
51
- \u898B\u305B\u65B9: "view",
52
- region: "group",
53
- view: "view"
54
- };
55
-
56
-
57
-
58
-
59
-
60
-
61
-
62
-
63
-
64
-
65
-
66
-
67
-
68
-
69
-
70
-
71
-
72
-
73
-
74
-
75
-
76
-
77
-
78
-
79
-
80
-
81
-
82
-
83
- exports.KINDS = KINDS; exports.STATE_ENDS = STATE_ENDS; exports.TIME_HEADS = TIME_HEADS; exports.NOW = NOW; exports.TREE_HEADS = TREE_HEADS; exports.LINEUP_HEADS = LINEUP_HEADS; exports.LANE_MOST = LANE_MOST; exports.LABEL_MOST = LABEL_MOST; exports.LANE_ATTRS = LANE_ATTRS; exports.HEADS = HEADS; exports.AS = AS; exports.ON = ON; exports.COPY = COPY; exports.MERGE = MERGE; exports.FROM = FROM; exports.HEAD = HEAD; exports.AT = AT; exports.OF = OF; exports.ATTRS = ATTRS; exports.TIME_EDGE_ATTRS = TIME_EDGE_ATTRS; exports.SPAN_SHAPES = SPAN_SHAPES; exports.DURATION_UNITS = DURATION_UNITS; exports.CARRIES = CARRIES; exports.VIEWS = VIEWS; exports.SIDES = SIDES; exports.OLD_H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AA;AAErC,IAAM,YAAA,EAAc,CAAC,KAAK,CAAA;AAE1B,IAAM,eAAA,EAAiB,CAAC,IAAA,EAAM,GAAA,EAAK,KAAA,EAAO,GAAA,EAAK,GAAG,CAAA;AAGlD,IAAM,QAAA,EAAU,IAAA,CAAiD,EAAE,IAAA,EAAM,IAAA,EAAM,IAAA,EAAM,KAAK,CAAC,CAAA;AAC3F,IAAM,MAAA,EAAQ,IAAA,CAAe,EAAE,KAAA,EAAO,IAAA,EAAM,MAAA,EAAQ,KAAK,CAAC,CAAA;AAC1D,IAAM,MAAA,EAAQ,IAAA,CAAgB,EAAE,KAAA,EAAO,IAAA,EAAM,KAAA,EAAO,IAAA,EAAM,IAAA,EAAM,IAAA,EAAM,KAAA,EAAO,KAAK,CAAC,CAAA;AAMnF,IAAM,UAAA,EAAY;AAAA,EACvB,wBAAA,EAAM,UAAA;AAAA,EACN,kBAAA,EAAK,cAAA;AAAA,EACL,YAAA,EAAI,OAAA;AAAA,EACJ,kBAAA,EAAK,MAAA;AAAA,EACL,MAAA,EAAQ,OAAA;AAAA,EACR,IAAA,EAAM;AACR,CAAA;AD7EA;AACA;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,yrBAAC","file":"/Users/cardene/Desktop/projects/dragon/packages/dragon/dist/light/chunk-CLS6JVKK.cjs","sourcesContent":[null,"/**\n * dragon記法の語 (#3137)。\n *\n * 行の種類は行の頭の英語の語で決まり、属性は `[<鍵>: <値>]` で書く。\n * 語は英語だけで、原本の JSON が使う名前に揃え、記法と JSON で覚える語を 1 組にする。\n *\n * 言葉の型 (`NotationLang`) は、誤りの文と図の中の字の言葉を選ぶために持つ。\n * 語が英語だけなので、記法の file から言葉は決めず、呼ぶ側が渡す。\n *\n * 型が欠けを止める。原本の JSON の値 (図の種類、運ぶ物、見せ方、名前の側) に語が無い時は、型の検査が落ちる。\n */\nimport type { Carry, Diagram, LabelSide, ViewMode } from \"./schema\";\n\nexport type NotationLang = \"ja\" | \"en\";\n\nconst keys = <K extends string>(table: Record<K, true>): K[] => Object.keys(table) as K[];\n\n/** 図の種類。最初の行の頭の語 */\nexport const KINDS = keys<Diagram[\"kind\"]>({ sequence: true, architecture: true, state: true, git: true, time: true, tree: true, lineup: true });\n\n/**\n * 状態遷移図の始まりと終わりの印の名前 (#3163)。線の送る側に `start`、受ける側に `finish` を書き、\n * 状態遷移図では箱の名札に使えない。時系列図と構成図では、宣言して使う普通の名札\n */\nexport const STATE_ENDS = [\"start\", \"finish\"] as const;\nexport type StateEnd = (typeof STATE_ENDS)[number];\n\n/**\n * 時間軸の図 (`time`、#3165) だけが書ける行の頭の語。目盛り、区切り、印の列、節目、拡大の範囲を最初の段より前に宣言し、\n * 段の中で印の色を変え (`mark`)、範囲に括弧か囲みを出す (`span`)\n */\nexport const TIME_HEADS = [\"scale\", \"period\", \"row\", \"point\", \"zoom\", \"mark\", \"span\"] as const;\n/**\n * 時間軸の図で針を進める行 (`now -> <目盛り>`) の送る側の名前。線の行と同じ形なので行の頭の語に入れない。\n * 時間軸の図では名札に使えず、ほかの図では普通の名札のまま\n */\nexport const NOW = \"now\";\n\n/**\n * 木の図 (`tree`、#3233) だけが書ける行の頭の語。段の中で葉を出し (`leaf`)、1 つ以上の子から親を組む (`node`)\n */\nexport const TREE_HEADS = [\"leaf\", \"node\"] as const;\n\n/**\n * 列の図 (`lineup`、#3239) だけが書ける行の頭の語。最初の段より前にチップを宣言し (`item`)、\n * 段の中で列の並びを書き (`line`)、封をして開け (`seal` と `open`)、列を選び (`pick`)、札を押す (`stamp`)\n */\nexport const LINEUP_HEADS = [\"item\", \"line\", \"seal\", \"open\", \"pick\", \"stamp\"] as const;\n/** 1 列に並べられるチップの上限。図の幅はこの枚数の列の幅で決まる */\nexport const LANE_MOST = 12;\n/** チップの字の上限 */\nexport const LABEL_MOST = 4;\n/** 列の図の `box` の行に書ける属性の鍵。列は絵柄と飛び先を持たない */\nexport const LANE_ATTRS = [\"note\", \"color\"] as const;\n\n/**\n * 最初の行より後の行の頭の語。線の行だけは箱の名札から始まる。\n * `branch` と `commit` は枝分かれの図 (`git`) だけが書ける (#3164)。`source` は段の出典 (#3199)\n */\nexport const HEADS = [\"group\", \"end\", \"box\", \"strip\", \"step\", \"say\", \"code\", \"source\", \"act\", \"note\", \"set\", \"branch\", \"commit\", ...TIME_HEADS, ...TREE_HEADS, ...LINEUP_HEADS] as const;\ntype Head = (typeof HEADS)[number];\n\n/** 箱と区画の名札の後ろに、見せる名前を続ける語 (`box <名札> as <名前>`) */\nexport const AS = \"as\";\n\n/** 枝分かれの図 (#3164) の `commit` の行で、積む枝、当て直しの元、取り込む枝を続ける語 (`commit <名札> on <枝> copy <commit>`) */\nexport const ON = \"on\";\nexport const COPY = \"copy\";\nexport const MERGE = \"merge\";\n/** 枝分かれの図で枝を切る行の、枝の後ろに切る commit を続ける語 (`<枝> from <commit>`) */\nexport const FROM = \"from\";\n/** 枝分かれの図で今いる場所を指す札の名前。枝と commit と箱の名札に使えない */\nexport const HEAD = \"HEAD\";\n/** 枝分かれの図の行の中の語のうち、行の頭の語でも属性でもない語。見本帳の部品が受け持つ語に数える (`on` は commit の行に必ず書くので数えない) */\nexport const GIT_WORDS = [FROM, COPY, MERGE] as const;\n\n/** 時間軸の図の節目の行で、節目を置く目盛りを続ける語 (`point <名札> at <目盛り>`)。必ず書くので部品の語に数えない */\nexport const AT = \"at\";\n\n/** 木の図の `node` の行で、親の名札の後ろに子を続ける語 (`node <名札> of <子>, <子>`)。必ず書くので部品の語に数えない */\nexport const OF = \"of\";\n\n/**\n * 行ごとに書ける属性の鍵。線の `at` と `into`、`note` の `color`、中身の帯の欄の `meter` は時間軸の図だけが書ける (#3165)。\n * `meter` は `strip` の行の欄ごとに、欄の名前の後ろに書く (`strip <題>: <欄> [meter: <割合>]`)\n * 箱の `link` は飛び先、段の出典の `url` は出典の在り処 (#3199)\n */\nexport const ATTRS = {\n diagram: [\"view\"],\n group: [\"note\", \"color\", \"icon\"],\n box: [\"note\", \"color\", \"icon\", \"link\"],\n source: [\"url\"],\n edge: [\"carry\", \"tag\", \"side\", \"at\", \"into\"],\n note: [\"color\"],\n set: [\"tag\"],\n strip: [\"meter\"],\n branch: [\"note\"],\n commit: [\"hash\", \"note\"],\n leaf: [\"hash\"],\n node: [\"hash\"],\n item: [\"color\", \"label\"],\n scale: [\"from\"],\n period: [\"from\"],\n row: [\"color\", \"empty\"],\n mark: [\"color\"],\n span: [\"shape\", \"color\"],\n} as const;\n\n/** 線の属性のうち、時間軸の図だけが書ける鍵 */\nexport const TIME_EDGE_ATTRS = [\"at\", \"into\"] as const;\n/** `span` の行の `shape` に書ける形。書かなければ括弧 */\nexport const SPAN_SHAPES = [\"box\"] as const;\n/** 時間軸の図の目盛りの長さに書ける単位 */\nexport const DURATION_UNITS = [\"ms\", \"s\", \"min\", \"h\", \"d\"] as const;\n\n/** `carry` に書ける運ぶ物。封筒は書かない時、札は `tag` で書く */\nexport const CARRIES = keys<Exclude<Carry[\"kind\"], \"envelope\" | \"tag\">>({ coin: true, none: true });\nexport const VIEWS = keys<ViewMode>({ fixed: true, follow: true });\nexport const SIDES = keys<LabelSide>({ above: true, below: true, left: true, right: true });\n\n/**\n * 前の形の行 (#2997 まで) が、新しい形のどの行に当たるか。誤りの文で新しい行の形を示すために引く。\n * 鍵は前の形の行の頭の語で、記号 (`#` など) で始まる行と、名札の後ろに `=` や「」が来る行は読む側が見分ける。\n */\nexport const OLD_HEADS = {\n 時系列図: \"sequence\",\n 構成図: \"architecture\",\n 区画: \"group\",\n 見せ方: \"view\",\n region: \"group\",\n view: \"view\",\n} as const satisfies Record<string, Diagram[\"kind\"] | Head | \"view\">;\n"]}