@cardenelabs/dragon 0.44.0 → 0.45.2
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/README.md +21 -0
- package/dist/cli.cjs +4166 -4063
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +4166 -4063
- package/dist/cli.js.map +1 -1
- package/dist/export.cjs +4066 -3963
- package/dist/export.cjs.map +1 -1
- package/dist/export.js +4065 -3964
- package/dist/export.js.map +1 -1
- package/dist/index.cjs +12297 -12194
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +12297 -12194
- package/dist/index.js.map +1 -1
- package/dist/light/chunk-5OQV42W3.cjs +1172 -0
- package/dist/light/chunk-5OQV42W3.cjs.map +1 -0
- package/dist/light/chunk-CLS6JVKK.cjs +84 -0
- package/dist/light/chunk-CLS6JVKK.cjs.map +1 -0
- package/dist/light/chunk-EHTQUCW4.js +1172 -0
- package/dist/light/chunk-EHTQUCW4.js.map +1 -0
- package/dist/light/chunk-JCEKXALJ.cjs +489 -0
- package/dist/light/chunk-JCEKXALJ.cjs.map +1 -0
- package/dist/light/chunk-YDKPEKGZ.js +84 -0
- package/dist/light/chunk-YDKPEKGZ.js.map +1 -0
- package/dist/light/chunk-YEQSLVIN.js +489 -0
- package/dist/light/chunk-YEQSLVIN.js.map +1 -0
- package/dist/light/git-GESUYKGR.js +637 -0
- package/dist/light/git-GESUYKGR.js.map +1 -0
- package/dist/light/git-K3KAAAWW.cjs +637 -0
- package/dist/light/git-K3KAAAWW.cjs.map +1 -0
- package/dist/light/index.cjs +9897 -0
- package/dist/light/index.cjs.map +1 -0
- package/dist/light/index.d.cts +976 -0
- package/dist/light/index.d.ts +976 -0
- package/dist/light/index.js +9897 -0
- package/dist/light/index.js.map +1 -0
- package/dist/light/lineup-2V2U7HZH.js +283 -0
- package/dist/light/lineup-2V2U7HZH.js.map +1 -0
- package/dist/light/lineup-623J25LU.cjs +283 -0
- package/dist/light/lineup-623J25LU.cjs.map +1 -0
- package/dist/light/state-OZVCHX7H.cjs +335 -0
- package/dist/light/state-OZVCHX7H.cjs.map +1 -0
- package/dist/light/state-T4OTVING.js +335 -0
- package/dist/light/state-T4OTVING.js.map +1 -0
- package/dist/light/time-6WEMD4FQ.js +719 -0
- package/dist/light/time-6WEMD4FQ.js.map +1 -0
- package/dist/light/time-PQCPVQOE.cjs +719 -0
- package/dist/light/time-PQCPVQOE.cjs.map +1 -0
- package/dist/light/tree-6D7KI57H.cjs +478 -0
- package/dist/light/tree-6D7KI57H.cjs.map +1 -0
- package/dist/light/tree-ZJZQI5QT.js +478 -0
- package/dist/light/tree-ZJZQI5QT.js.map +1 -0
- package/dist/player.global.js +3 -3
- package/package.json +14 -2
- package/src/api.ts +71 -0
- package/src/figure-text.ts +4 -0
- package/src/index.ts +6 -69
- package/src/kinds/all.ts +16 -0
- package/src/kinds/git.ts +3 -0
- package/src/kinds/lineup.ts +3 -0
- package/src/kinds/registry.ts +46 -0
- package/src/kinds/state.ts +2 -0
- package/src/kinds/time.ts +3 -0
- package/src/kinds/tree.ts +3 -0
- package/src/layout/git.ts +0 -1
- package/src/layout/lineup.ts +0 -1
- package/src/layout/scene.ts +58 -16
- package/src/layout/time.ts +0 -1
- package/src/layout/tree.ts +0 -1
- package/src/light.ts +31 -0
- package/src/look/values.ts +1 -1
- package/src/player-global.ts +3 -0
- package/src/player.ts +1 -1
- package/src/render/draw.ts +751 -0
- package/src/render/parts.ts +3 -0
- package/src/render/svg.ts +4 -725
- package/src/render/time.ts +1 -4
- package/src/view.ts +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cardenelabs/dragon",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.45.2",
|
|
4
4
|
"description": "Dragon — 動く図を、人は行ごとの記法で、AI は JSON で書く。時系列図と構成図を段ごとに動かし、mp4・GIF・HTML・PNG に書き出す。",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "cardene777",
|
|
@@ -39,6 +39,16 @@
|
|
|
39
39
|
"default": "./dist/index.cjs"
|
|
40
40
|
}
|
|
41
41
|
},
|
|
42
|
+
"./light": {
|
|
43
|
+
"import": {
|
|
44
|
+
"types": "./dist/light/index.d.ts",
|
|
45
|
+
"default": "./dist/light/index.js"
|
|
46
|
+
},
|
|
47
|
+
"require": {
|
|
48
|
+
"types": "./dist/light/index.d.cts",
|
|
49
|
+
"default": "./dist/light/index.cjs"
|
|
50
|
+
}
|
|
51
|
+
},
|
|
42
52
|
"./fonts": {
|
|
43
53
|
"import": "./dist/fonts.js",
|
|
44
54
|
"require": "./dist/fonts.cjs"
|
|
@@ -77,7 +87,9 @@
|
|
|
77
87
|
},
|
|
78
88
|
"sideEffects": [
|
|
79
89
|
"./dist/fonts.js",
|
|
80
|
-
"./dist/fonts.cjs"
|
|
90
|
+
"./dist/fonts.cjs",
|
|
91
|
+
"./src/kinds/all.ts",
|
|
92
|
+
"./src/render/svg.ts"
|
|
81
93
|
],
|
|
82
94
|
"scripts": {
|
|
83
95
|
"build": "tsup",
|
package/src/api.ts
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 既定の入口 (`index.ts`) と軽い入口 (`light.ts`) が共に出す部品 (#3248)。
|
|
3
|
+
* 図の種類の部品を読むかだけが 2 つの入口で違うので、ここでは種類の部品を読まない。
|
|
4
|
+
*/
|
|
5
|
+
export { extractDiagrams, type Fence } from "./markdown";
|
|
6
|
+
export { type LineError, type ParseOptions, type Parsed, parseNotation } from "./parser";
|
|
7
|
+
export { printNotation } from "./printer";
|
|
8
|
+
export type { NotationLang } from "./words";
|
|
9
|
+
export {
|
|
10
|
+
type Box,
|
|
11
|
+
type Carry,
|
|
12
|
+
type Checked,
|
|
13
|
+
type CheckOptions,
|
|
14
|
+
type Color,
|
|
15
|
+
type Diagram,
|
|
16
|
+
type DiagramEvent,
|
|
17
|
+
type FieldError,
|
|
18
|
+
type GitBranch,
|
|
19
|
+
type GitCommit,
|
|
20
|
+
type LabelSide,
|
|
21
|
+
type LineupItem,
|
|
22
|
+
type LineupOrder,
|
|
23
|
+
type LineupStamp,
|
|
24
|
+
type Region,
|
|
25
|
+
type StatePath,
|
|
26
|
+
type Step,
|
|
27
|
+
type StepSource,
|
|
28
|
+
type StripMeter,
|
|
29
|
+
type TimeMarkEvent,
|
|
30
|
+
type TimePeriod,
|
|
31
|
+
type TimePoint,
|
|
32
|
+
type TimeRow,
|
|
33
|
+
type TimeScale,
|
|
34
|
+
type TimeSpanEvent,
|
|
35
|
+
type TimeSpec,
|
|
36
|
+
type TreeLeaf,
|
|
37
|
+
type TreeNode,
|
|
38
|
+
validateDiagram,
|
|
39
|
+
type ViewMode,
|
|
40
|
+
} from "./schema";
|
|
41
|
+
export { FORMAT_VERSION, type Read, readDiagram } from "./version";
|
|
42
|
+
export type {
|
|
43
|
+
Layout,
|
|
44
|
+
Point,
|
|
45
|
+
Rect,
|
|
46
|
+
SceneAction,
|
|
47
|
+
SceneBadge,
|
|
48
|
+
SceneBox,
|
|
49
|
+
SceneEdge,
|
|
50
|
+
SceneEnd,
|
|
51
|
+
SceneField,
|
|
52
|
+
SceneLabel,
|
|
53
|
+
SceneLifeline,
|
|
54
|
+
ScenePath,
|
|
55
|
+
SceneRegion,
|
|
56
|
+
SceneSide,
|
|
57
|
+
SceneStrip,
|
|
58
|
+
SceneTrail,
|
|
59
|
+
} from "./layout/scene";
|
|
60
|
+
export type { TimeAxis, TimeBox, TimeColumn, TimeLayout, TimeMark, TimePeriodPlaced, TimePointPlaced, TimeRowPlaced, TimeSpanPlaced, TimeTick, TimeWire, TimeZoom } from "./layout/time";
|
|
61
|
+
export type { TreeLayout, TreeLink, TreePlaced, TreeRun } from "./layout/tree";
|
|
62
|
+
export type { LaneText, LineupAt, LineupLane, LineupLayout, LineupPick, LineupSeal, LineupSeat, LineupStamp as LineupStampPlaced } from "./layout/lineup";
|
|
63
|
+
export { type Family, FONTS } from "./look/fonts";
|
|
64
|
+
export { type ColorKey, type ColorName, type Colors, DEFAULT_PALETTE, type Palette, PALETTES, READABLE_PX, resolvePalette, type TextStyle, type Theme } from "./look/values";
|
|
65
|
+
export { mountDiagram, type Player, type PlayerOptions } from "./player";
|
|
66
|
+
export { ICONS } from "./render/icons";
|
|
67
|
+
export { describeOverlap, type InkPart, type Overlap, type OverlapSpot } from "./render/ink";
|
|
68
|
+
export { iconSvg } from "./render/parts";
|
|
69
|
+
export { type Rendered, type RenderOptions, renderDiagram } from "./render/draw";
|
|
70
|
+
export type { CarrierTime, EdgeTime, EventTime, LabelTime, Span, StateTime, Timeline } from "./timeline";
|
|
71
|
+
export { chooseView } from "./view";
|
package/src/figure-text.ts
CHANGED
|
@@ -9,6 +9,8 @@ import type { NotationLang } from "./words";
|
|
|
9
9
|
export interface FigureText {
|
|
10
10
|
/** 描けない時の断りの文。`detail` は誤りの場所と文を並べた物 */
|
|
11
11
|
cannotDraw: (detail: string) => string;
|
|
12
|
+
/** 軽い入口で読んでいない種類を描いた時の誤り (#3248) */
|
|
13
|
+
kindNotLoaded: (kind: string) => string;
|
|
12
14
|
/** 描く設定の `colors` (#3198) の誤り。色味に無い色の名前と、色の値として読めない値の色の名前 */
|
|
13
15
|
unknownColor: (name: string) => string;
|
|
14
16
|
unreadableColor: (name: string) => string;
|
|
@@ -58,6 +60,7 @@ const capital = (text: string): string => text.charAt(0).toUpperCase() + text.sl
|
|
|
58
60
|
export const FIGURE_TEXT: Record<NotationLang, FigureText> = {
|
|
59
61
|
ja: {
|
|
60
62
|
cannotDraw: (detail) => `図を描けない: ${detail}`,
|
|
63
|
+
kindNotLoaded: (kind) => `${kind} の図の部品を読んでいない。描く前に loadKind を待つ`,
|
|
61
64
|
unknownColor: (name) => `colors の ${name} は色味に無い色の名前`,
|
|
62
65
|
unreadableColor: (name) => `colors の ${name} の値を色として読めない`,
|
|
63
66
|
overview: "全体図",
|
|
@@ -87,6 +90,7 @@ export const FIGURE_TEXT: Record<NotationLang, FigureText> = {
|
|
|
87
90
|
},
|
|
88
91
|
en: {
|
|
89
92
|
cannotDraw: (detail) => `Cannot draw the diagram: ${detail}`,
|
|
93
|
+
kindNotLoaded: (kind) => `The ${kind} diagram parts are not loaded. Await loadKind before drawing`,
|
|
90
94
|
unknownColor: (name) => `colors.${name} is not a color name of the palette`,
|
|
91
95
|
unreadableColor: (name) => `colors.${name} cannot be read as a color`,
|
|
92
96
|
overview: "Overview",
|
package/src/index.ts
CHANGED
|
@@ -1,75 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* dragon
|
|
2
|
+
* dragon の入口。全ての図の種類の部品を持ち、待たずに描ける。
|
|
3
3
|
*
|
|
4
4
|
* 図の原本は JSON で、人は行の頭の英語の語で行の種類を決める dragon記法で書く。記法と JSON は行き来でき、
|
|
5
5
|
* JSON は JSON Schema 1 本で検査する。原本から図を描き、頁に置いて段ごとに動かす。
|
|
6
|
-
* 頁に字を読み込むのは別の入口 `@cardenelabs/dragon/fonts`、原本の file を移すのは Node でだけ動く入口 `@cardenelabs/dragon/node
|
|
6
|
+
* 頁に字を読み込むのは別の入口 `@cardenelabs/dragon/fonts`、原本の file を移すのは Node でだけ動く入口 `@cardenelabs/dragon/node`、
|
|
7
|
+
* 図の種類の部品を後から読むのは別の入口 `@cardenelabs/dragon/light`。
|
|
7
8
|
* この入口は頁を束ねる道具が読むため、Node の組み込みの module を読む部品を置かない (#3206)。
|
|
8
9
|
*/
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
export
|
|
12
|
-
export type { NotationLang } from "./words";
|
|
13
|
-
export {
|
|
14
|
-
type Box,
|
|
15
|
-
type Carry,
|
|
16
|
-
type Checked,
|
|
17
|
-
type CheckOptions,
|
|
18
|
-
type Color,
|
|
19
|
-
type Diagram,
|
|
20
|
-
type DiagramEvent,
|
|
21
|
-
type FieldError,
|
|
22
|
-
type GitBranch,
|
|
23
|
-
type GitCommit,
|
|
24
|
-
type LabelSide,
|
|
25
|
-
type LineupItem,
|
|
26
|
-
type LineupOrder,
|
|
27
|
-
type LineupStamp,
|
|
28
|
-
type Region,
|
|
29
|
-
type StatePath,
|
|
30
|
-
type Step,
|
|
31
|
-
type StepSource,
|
|
32
|
-
type StripMeter,
|
|
33
|
-
type TimeMarkEvent,
|
|
34
|
-
type TimePeriod,
|
|
35
|
-
type TimePoint,
|
|
36
|
-
type TimeRow,
|
|
37
|
-
type TimeScale,
|
|
38
|
-
type TimeSpanEvent,
|
|
39
|
-
type TimeSpec,
|
|
40
|
-
type TreeLeaf,
|
|
41
|
-
type TreeNode,
|
|
42
|
-
validateDiagram,
|
|
43
|
-
type ViewMode,
|
|
44
|
-
} from "./schema";
|
|
45
|
-
export { FORMAT_VERSION, type Read, readDiagram } from "./version";
|
|
46
|
-
export type {
|
|
47
|
-
Layout,
|
|
48
|
-
Point,
|
|
49
|
-
Rect,
|
|
50
|
-
SceneAction,
|
|
51
|
-
SceneBadge,
|
|
52
|
-
SceneBox,
|
|
53
|
-
SceneEdge,
|
|
54
|
-
SceneEnd,
|
|
55
|
-
SceneField,
|
|
56
|
-
SceneLabel,
|
|
57
|
-
SceneLifeline,
|
|
58
|
-
ScenePath,
|
|
59
|
-
SceneRegion,
|
|
60
|
-
SceneSide,
|
|
61
|
-
SceneStrip,
|
|
62
|
-
SceneTrail,
|
|
63
|
-
} from "./layout/scene";
|
|
64
|
-
export type { TimeAxis, TimeBox, TimeColumn, TimeLayout, TimeMark, TimePeriodPlaced, TimePointPlaced, TimeRowPlaced, TimeSpanPlaced, TimeTick, TimeWire, TimeZoom } from "./layout/time";
|
|
65
|
-
export type { TreeLayout, TreeLink, TreePlaced, TreeRun } from "./layout/tree";
|
|
66
|
-
export type { LaneText, LineupAt, LineupLane, LineupLayout, LineupPick, LineupSeal, LineupSeat, LineupStamp as LineupStampPlaced } from "./layout/lineup";
|
|
67
|
-
export { type Family, FONTS } from "./look/fonts";
|
|
68
|
-
export { type ColorKey, type ColorName, type Colors, DEFAULT_PALETTE, type Palette, PALETTES, READABLE_PX, resolvePalette, type TextStyle, type Theme } from "./look/values";
|
|
69
|
-
export { mountDiagram, type Player, type PlayerOptions } from "./player";
|
|
70
|
-
export { ICONS } from "./render/icons";
|
|
71
|
-
export { describeOverlap, type InkPart, type Overlap, type OverlapSpot } from "./render/ink";
|
|
72
|
-
export { iconSvg } from "./render/parts";
|
|
73
|
-
export { type Rendered, type RenderOptions, renderDiagram } from "./render/svg";
|
|
74
|
-
export type { CarrierTime, EdgeTime, EventTime, LabelTime, Span, StateTime, Timeline } from "./timeline";
|
|
75
|
-
export { chooseView } from "./view";
|
|
10
|
+
import "./kinds/all";
|
|
11
|
+
|
|
12
|
+
export * from "./api";
|
package/src/kinds/all.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 全ての種類の部品を読み込みの時に登録する (#3248)。全部入りの入口が読む。
|
|
3
|
+
* 読むだけで登録するので、`package.json` の `sideEffects` に載せて束ねる道具に消させない。
|
|
4
|
+
*/
|
|
5
|
+
import * as git from "./git";
|
|
6
|
+
import * as lineup from "./lineup";
|
|
7
|
+
import { registerKind } from "./registry";
|
|
8
|
+
import * as state from "./state";
|
|
9
|
+
import * as time from "./time";
|
|
10
|
+
import * as tree from "./tree";
|
|
11
|
+
|
|
12
|
+
registerKind("git", git);
|
|
13
|
+
registerKind("lineup", lineup);
|
|
14
|
+
registerKind("state", state);
|
|
15
|
+
registerKind("time", time);
|
|
16
|
+
registerKind("tree", tree);
|
package/src/kinds/git.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 図の種類ごとの描く部品の登録簿 (#3248)。
|
|
3
|
+
*
|
|
4
|
+
* 描く所 (`render/draw.ts`) は git、lineup、state、time、tree の部品をここから引く。
|
|
5
|
+
* 全部入りの入口は読み込みの時に全ての種類を登録し (`all.ts`)、軽い入口は `loadKind` が種類を読んだ時に登録する (`light.ts`)。
|
|
6
|
+
* 時系列図と構成図の部品は登録せず、描く所が直に読む。
|
|
7
|
+
*/
|
|
8
|
+
import { FIGURE_TEXT } from "../figure-text";
|
|
9
|
+
import type { NotationLang } from "../words";
|
|
10
|
+
import type * as git from "./git";
|
|
11
|
+
import type * as lineup from "./lineup";
|
|
12
|
+
import type * as state from "./state";
|
|
13
|
+
import type * as time from "./time";
|
|
14
|
+
import type * as tree from "./tree";
|
|
15
|
+
|
|
16
|
+
/** 後から読む種類の名前。部品の型から導くと、部品の型が軽い入口の型の file へ漏れるので字で書く */
|
|
17
|
+
export type LaterKind = "git" | "lineup" | "state" | "time" | "tree";
|
|
18
|
+
|
|
19
|
+
export interface LaterKinds {
|
|
20
|
+
git: typeof git;
|
|
21
|
+
lineup: typeof lineup;
|
|
22
|
+
state: typeof state;
|
|
23
|
+
time: typeof time;
|
|
24
|
+
tree: typeof tree;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** 後から読む種類 */
|
|
28
|
+
export const LATER_KINDS: readonly LaterKind[] = ["git", "lineup", "state", "time", "tree"];
|
|
29
|
+
|
|
30
|
+
const registered: Partial<LaterKinds> = {};
|
|
31
|
+
|
|
32
|
+
export function registerKind<K extends LaterKind>(kind: K, parts: LaterKinds[K]): void {
|
|
33
|
+
registered[kind] = parts;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** 種類の部品を今すぐ描ける形で持っているか。時系列図と構成図は常に持つ */
|
|
37
|
+
export function kindLoaded(kind: string | undefined): boolean {
|
|
38
|
+
return !(LATER_KINDS as readonly (string | undefined)[]).includes(kind) || registered[kind as LaterKind] !== undefined;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** 種類の部品。読んでいない時は、種類の名前を含む誤りで止まる */
|
|
42
|
+
export function kindParts<K extends LaterKind>(kind: K, lang: NotationLang = "ja"): LaterKinds[K] {
|
|
43
|
+
const parts = registered[kind];
|
|
44
|
+
if (parts === undefined) throw new Error(FIGURE_TEXT[lang].kindNotLoaded(kind));
|
|
45
|
+
return parts;
|
|
46
|
+
}
|
package/src/layout/git.ts
CHANGED
package/src/layout/lineup.ts
CHANGED
|
@@ -79,7 +79,6 @@ export interface LineupLayout extends Layout {
|
|
|
79
79
|
picks: LineupPick[];
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
-
export const isLineupLayout = (layout: Layout): layout is LineupLayout => layout.kind === "lineup";
|
|
83
82
|
|
|
84
83
|
/** 列の右上に出る字と、その字の形。段の中の `note` は太い字で描く */
|
|
85
84
|
function notesOf(diagram: Diagram, id: string, sub: string | undefined): number[] {
|
package/src/layout/scene.ts
CHANGED
|
@@ -618,28 +618,48 @@ const trailWidth = (trail: TrailSource): number => Math.max(textWidth(trail.titl
|
|
|
618
618
|
/** 1 行に並べた時に帯が要る幅。 */
|
|
619
619
|
export function stripNeed(diagram: Diagram, trail?: TrailSource): number {
|
|
620
620
|
if (!diagram.strip) return 0;
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
621
|
+
return rowNeed(diagram.strip.title, [...diagram.strip.fields.map((name) => fieldWidth(diagram, name)), ...(trail ? [trailWidth(trail)] : [])]);
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
/** 帯の題の右に、幅 `widths` の欄を 1 行に並べた時に帯が要る幅。 */
|
|
625
|
+
function rowNeed(title: string, widths: number[]): number {
|
|
626
|
+
const { fieldGap, pad } = LOOK.strip;
|
|
627
|
+
return stripStart(title) + widths.reduce((sum, w) => sum + w + fieldGap, 0) - fieldGap + pad;
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
/** 題の右の、欄を並べ始める所。 */
|
|
631
|
+
function stripStart(title: string): number {
|
|
632
|
+
return LOOK.strip.titleX + textWidth(title, TYPE.stripTitle) + LOOK.strip.fieldGap;
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
/** 欄を `start` から左へ詰めて並べ、幅 `width` に収まらない欄を次の行へ送る。`rows` は使った行の数から 1 を引いた値を返す */
|
|
636
|
+
function fieldPlacer(start: number, width: number): { place: (w: number) => { x: number; row: number }; rows: () => number } {
|
|
637
|
+
const { fieldGap, pad } = LOOK.strip;
|
|
638
|
+
let cx = start;
|
|
639
|
+
let row = 0;
|
|
640
|
+
return {
|
|
641
|
+
place(w) {
|
|
642
|
+
if (cx > start && cx + w > width - pad) {
|
|
643
|
+
cx = start;
|
|
644
|
+
row++;
|
|
645
|
+
}
|
|
646
|
+
const at = { x: cx, row };
|
|
647
|
+
cx += w + fieldGap;
|
|
648
|
+
return at;
|
|
649
|
+
},
|
|
650
|
+
rows: () => row,
|
|
651
|
+
};
|
|
625
652
|
}
|
|
626
653
|
|
|
627
654
|
/** 中身の帯。欄は左から並べ、幅に収まらない欄は次の行へ送る。通った状態の欄を渡すと、最後の欄の後に同じ決まりで置く。 */
|
|
628
655
|
export function layoutStrip(diagram: Diagram, x: number, y: number, width: number, trail?: TrailSource): SceneStrip | undefined {
|
|
629
656
|
if (!diagram.strip) return undefined;
|
|
630
|
-
const {
|
|
631
|
-
const start = titleX + textWidth(diagram.strip.title, TYPE.stripTitle) + fieldGap;
|
|
657
|
+
const { line, h } = LOOK.strip;
|
|
632
658
|
const fields: SceneField[] = [];
|
|
633
|
-
|
|
634
|
-
let row = 0;
|
|
659
|
+
const placer = fieldPlacer(stripStart(diagram.strip.title), width);
|
|
635
660
|
const place = (w: number): { x: number; y: number } => {
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
row++;
|
|
639
|
-
}
|
|
640
|
-
const at = { x: x + cx, y: y + row * line };
|
|
641
|
-
cx += w + fieldGap;
|
|
642
|
-
return at;
|
|
661
|
+
const at = placer.place(w);
|
|
662
|
+
return { x: x + at.x, y: y + at.row * line };
|
|
643
663
|
};
|
|
644
664
|
for (const name of diagram.strip.fields) {
|
|
645
665
|
const w = fieldWidth(diagram, name);
|
|
@@ -649,7 +669,29 @@ export function layoutStrip(diagram: Diagram, x: number, y: number, width: numbe
|
|
|
649
669
|
fields.push({ name, ...at, w, ...(meter && line !== undefined ? { meter: { line, text: meter.line, x: at.x, w: LOOK.time.meter.w } } : {}) });
|
|
650
670
|
}
|
|
651
671
|
const laidTrail = trail ? { ...trail, ...place(trailWidth(trail)), w: trailWidth(trail) } : undefined;
|
|
652
|
-
return { x, y, w: width, h: h +
|
|
672
|
+
return { x, y, w: width, h: h + placer.rows() * line, title: diagram.strip.title, fields, ...(laidTrail ? { trail: laidTrail } : {}) };
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
/**
|
|
676
|
+
* 帯を置き場所 (x, y) と幅 `width` で組み直す (#3270)。寄って追う図は帯を窓の下に置くので、図を組んだ時と幅が違う。
|
|
677
|
+
* 欄が題の右の 1 行に収まる幅では題の右に並べ、収まらない幅では題に 1 行を取って欄を左端から並べる。
|
|
678
|
+
* 題の右で折り返すと、携帯の幅では欄に残る幅が欄 1 つ分ほどになるため
|
|
679
|
+
*/
|
|
680
|
+
export function rewrapStrip(s: SceneStrip, x: number, y: number, width: number): SceneStrip {
|
|
681
|
+
const { line, h, pad, titleRow } = LOOK.strip;
|
|
682
|
+
const stacked = rowNeed(s.title, [...s.fields.map((f) => f.w), ...(s.trail ? [s.trail.w] : [])]) > width;
|
|
683
|
+
const top = stacked ? titleRow : 0;
|
|
684
|
+
const placer = fieldPlacer(stacked ? pad : stripStart(s.title), width);
|
|
685
|
+
const place = (w: number): { x: number; y: number } => {
|
|
686
|
+
const at = placer.place(w);
|
|
687
|
+
return { x: x + at.x, y: y + top + at.row * line };
|
|
688
|
+
};
|
|
689
|
+
const fields = s.fields.map((field) => {
|
|
690
|
+
const at = place(field.w);
|
|
691
|
+
return { ...field, ...at, ...(field.meter ? { meter: { ...field.meter, x: at.x } } : {}) };
|
|
692
|
+
});
|
|
693
|
+
const trail = s.trail ? { ...s.trail, ...place(s.trail.w) } : undefined;
|
|
694
|
+
return { ...s, x, y, w: width, h: h + placer.rows() * line + top, fields, ...(trail ? { trail } : {}) };
|
|
653
695
|
}
|
|
654
696
|
|
|
655
697
|
/** 場面の全ての物を (dx, dy) だけ動かす。区画と帯は動かさず、横いっぱいの形を保つ。 */
|
package/src/layout/time.ts
CHANGED
|
@@ -159,7 +159,6 @@ export interface TimeLayout extends Layout {
|
|
|
159
159
|
needle: { y1: number; y2: number };
|
|
160
160
|
}
|
|
161
161
|
|
|
162
|
-
export const isTimeLayout = (layout: Layout): layout is TimeLayout => layout.kind === "time";
|
|
163
162
|
|
|
164
163
|
const SECONDS = { d: 86400, h: 3600, min: 60, s: 1, ms: 0.001 } as const;
|
|
165
164
|
type TimeUnit = keyof typeof SECONDS;
|
package/src/layout/tree.ts
CHANGED
package/src/light.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* dragon の軽い入口 (`@cardenelabs/dragon/light`、#3248)。
|
|
3
|
+
*
|
|
4
|
+
* 既定の入口と同じ部品を出すが、git、lineup、state、time、tree の描く部品を持たず、`loadKind` を待った時に読む。
|
|
5
|
+
* 読んだ後は既定の入口と同じ関数で、待たずに同じ図を描く。読んでいない種類を描くと、その種類の名前を含む誤りで止まる。
|
|
6
|
+
* 最初に読む量を抑えたい頁を束ねる時に使い、この入口と既定の入口を 1 つの頁で混ぜない (混ぜると全ての部品が頁に入る)。
|
|
7
|
+
*/
|
|
8
|
+
import { kindLoaded, LATER_KINDS, type LaterKind, type LaterKinds, registerKind } from "./kinds/registry";
|
|
9
|
+
|
|
10
|
+
export * from "./api";
|
|
11
|
+
export { kindLoaded, LATER_KINDS, type LaterKind };
|
|
12
|
+
|
|
13
|
+
const LOADERS: { [K in LaterKind]: () => Promise<LaterKinds[K]> } = {
|
|
14
|
+
git: () => import("./kinds/git"),
|
|
15
|
+
lineup: () => import("./kinds/lineup"),
|
|
16
|
+
state: () => import("./kinds/state"),
|
|
17
|
+
time: () => import("./kinds/time"),
|
|
18
|
+
tree: () => import("./kinds/tree"),
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const isLater = (kind: string | undefined): kind is LaterKind => (LATER_KINDS as readonly (string | undefined)[]).includes(kind);
|
|
22
|
+
|
|
23
|
+
/** 種類の描く部品を読む。時系列図と構成図は初めから持つので何もしない。読み込みが落ちると拒否され、次に呼ぶと読み直す */
|
|
24
|
+
export async function loadKind(kind: string | undefined): Promise<void> {
|
|
25
|
+
if (!isLater(kind) || kindLoaded(kind)) return;
|
|
26
|
+
await register(kind);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
async function register<K extends LaterKind>(kind: K): Promise<void> {
|
|
30
|
+
registerKind(kind, await LOADERS[kind]());
|
|
31
|
+
}
|
package/src/look/values.ts
CHANGED
|
@@ -344,7 +344,7 @@ export const LOOK = {
|
|
|
344
344
|
/**
|
|
345
345
|
* `trail` は状態遷移図の帯の最後の、通った状態の点 (#3171)。`r` は点の半径、`step` は点の中心どうしの間、`now` は変わった値の欄の名前の横の点の半径と、名前からの離れ
|
|
346
346
|
*/
|
|
347
|
-
strip: { h: 72, line: 44, pad: 12, icon: 24, titleX: 44, fieldGap: 22, sepInset: 14, tagGap: 6, tagH: 15, tagPadX: 7, nameY: 22, valueY: 43, trail: { r: 5.4, step: 16 }, now: { r: 3, gap: 7 } },
|
|
347
|
+
strip: { h: 72, line: 44, titleRow: 40, pad: 12, icon: 24, titleX: 44, fieldGap: 22, sepInset: 14, tagGap: 6, tagH: 15, tagPadX: 7, nameY: 22, valueY: 43, trail: { r: 5.4, step: 16 }, now: { r: 3, gap: 7 } },
|
|
348
348
|
/** `time` から始まる値は時間軸の図 (#3165) の、目盛りの印の枠、拡大の枠、時刻の線、範囲の括弧と囲み、節目へ下ろす点線、節目の丸、針、物差しの線の印 */
|
|
349
349
|
stroke: {
|
|
350
350
|
git: 2.25,
|
package/src/player-global.ts
CHANGED
package/src/player.ts
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
import { FIGURE_TEXT } from "./figure-text";
|
|
19
19
|
import type { Rect } from "./layout/scene";
|
|
20
20
|
import { FONT_VARS, LOOK, paletteVars, type TextStyle, TYPE } from "./look/values";
|
|
21
|
-
import { drawSvg, paletteOf, type RenderOptions, renderDiagram } from "./render/
|
|
21
|
+
import { drawSvg, paletteOf, type RenderOptions, renderDiagram } from "./render/draw";
|
|
22
22
|
import type { Span } from "./timeline";
|
|
23
23
|
import { chooseView } from "./view";
|
|
24
24
|
|