@draftably/markdown 0.1.0 → 0.2.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/README.md +16 -64
- package/dist/chunks/{core-DPjuIyPG.js → core-D4HpamVq.js} +19 -13
- package/dist/chunks/mermaid-facade-BoLWBerE.js +289 -0
- package/dist/chunks/mermaid-importer-IVovOQE9.js +3753 -0
- package/dist/markdown-it.js +86 -85
- package/dist/mermaid.js +93 -0
- package/dist/remark.js +46 -46
- package/dist/types/{core.d.ts → packages/markdown/src/core.d.ts} +11 -0
- package/dist/types/packages/markdown/src/mermaid.d.ts +8 -0
- package/dist/types/{remark.d.ts → packages/markdown/src/remark.d.ts} +1 -1
- package/dist/types/src/dsl/cells.d.ts +91 -0
- package/dist/types/src/dsl/channels.d.ts +53 -0
- package/dist/types/src/dsl/compile.d.ts +162 -0
- package/dist/types/src/dsl/frame.d.ts +38 -0
- package/dist/types/src/dsl/lanes.d.ts +23 -0
- package/dist/types/src/dsl/legend-notes.d.ts +3 -0
- package/dist/types/src/dsl/project.d.ts +39 -0
- package/dist/types/src/dsl/syntax.d.ts +317 -0
- package/dist/types/src/import/import-core.d.ts +105 -0
- package/dist/types/src/import/mermaid-facade.d.ts +120 -0
- package/dist/types/src/import/mermaid-importer.d.ts +4 -0
- package/dist/types/src/import/mermaid-sequence.d.ts +8 -0
- package/dist/types/src/model/appearance.d.ts +209 -0
- package/dist/types/src/model/bounds.d.ts +19 -0
- package/dist/types/src/model/document.d.ts +24 -0
- package/dist/types/src/model/font-faces.d.ts +24 -0
- package/dist/types/src/model/fonts.d.ts +47 -0
- package/dist/types/src/model/footnote.d.ts +34 -0
- package/dist/types/src/model/geometry.d.ts +29 -0
- package/dist/types/src/model/graph.d.ts +53 -0
- package/dist/types/src/model/heading.d.ts +38 -0
- package/dist/types/src/model/icons.d.ts +2 -0
- package/dist/types/src/model/labels.d.ts +88 -0
- package/dist/types/src/model/link.d.ts +63 -0
- package/dist/types/src/model/markers.d.ts +47 -0
- package/dist/types/src/model/note.d.ts +75 -0
- package/dist/types/src/model/rich-text.d.ts +24 -0
- package/dist/types/src/model/routes.d.ts +170 -0
- package/dist/types/src/model/status.d.ts +84 -0
- package/dist/types/src/model/styles.d.ts +13 -0
- package/dist/types/src/model/types.d.ts +277 -0
- package/package.json +9 -7
- /package/dist/types/{client-validation.d.ts → packages/markdown/src/client-validation.d.ts} +0 -0
- /package/dist/types/{client.d.ts → packages/markdown/src/client.d.ts} +0 -0
- /package/dist/types/{files.d.ts → packages/markdown/src/files.d.ts} +0 -0
- /package/dist/types/{index.d.ts → packages/markdown/src/index.d.ts} +0 -0
- /package/dist/types/{markdown-it-helpers.d.ts → packages/markdown/src/markdown-it-helpers.d.ts} +0 -0
- /package/dist/types/{markdown-it.d.ts → packages/markdown/src/markdown-it.d.ts} +0 -0
- /package/dist/types/{metadata.d.ts → packages/markdown/src/metadata.d.ts} +0 -0
- /package/dist/types/{source.d.ts → packages/markdown/src/source.d.ts} +0 -0
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Routing channels inside groups.
|
|
3
|
+
*
|
|
4
|
+
* A group leaves `GROUP_INSET` between its members and its border. That is padding, not room for
|
|
5
|
+
* a line: a line routed through it runs beside a member and along the border at once. When a
|
|
6
|
+
* connection has to travel inside a group (a member boxed in by its neighbours, or a link between
|
|
7
|
+
* two of the group's children that can't go straight across), the group grows a channel on one
|
|
8
|
+
* side, wide enough for each such line to run a full standoff from the members,
|
|
9
|
+
* the border and each other. A link between children takes the side of them both ends lean
|
|
10
|
+
* toward, and a return (up or left) takes the left or top when they lean neither way, so a
|
|
11
|
+
* forward line and its return don't cross. The compiler lays the scene out once, plans channels
|
|
12
|
+
* from that geometry, and lays it out again with them.
|
|
13
|
+
*/
|
|
14
|
+
import type { ModelEdge } from './syntax';
|
|
15
|
+
/**
|
|
16
|
+
* Room a group leaves round its content: the inset on the left, right and bottom (at least
|
|
17
|
+
* `GROUP_INSET`), and extra room under the title band on top (0 without a channel there).
|
|
18
|
+
*/
|
|
19
|
+
export interface Channel {
|
|
20
|
+
left: number;
|
|
21
|
+
right: number;
|
|
22
|
+
top: number;
|
|
23
|
+
bottom: number;
|
|
24
|
+
/** How many lines each side's channel was planned for. */
|
|
25
|
+
lines: Record<Side, number>;
|
|
26
|
+
}
|
|
27
|
+
/** Channels may grow the drawing's area by this much at most. */
|
|
28
|
+
export declare const CHANNEL_BUDGET = 1.1;
|
|
29
|
+
/**
|
|
30
|
+
* Drop the channels that carry fewest lines until the drawing laid out with the rest (`measure`)
|
|
31
|
+
* is within `CHANNEL_BUDGET` of its area without any (`plain`).
|
|
32
|
+
*/
|
|
33
|
+
export declare function trimChannels(plan: Map<string, Channel>, plain: number, measure: (channels: Map<string, Channel>) => number): Map<string, Channel>;
|
|
34
|
+
interface Box {
|
|
35
|
+
id: string;
|
|
36
|
+
type: string;
|
|
37
|
+
parent: string;
|
|
38
|
+
x: number;
|
|
39
|
+
y: number;
|
|
40
|
+
w: number;
|
|
41
|
+
h: number;
|
|
42
|
+
}
|
|
43
|
+
export type Side = 'left' | 'right' | 'top' | 'bottom';
|
|
44
|
+
/**
|
|
45
|
+
* Channels for the scene laid out as `objects`. A group is keyed by id; groups with no traffic
|
|
46
|
+
* are left out.
|
|
47
|
+
*/
|
|
48
|
+
export declare function planChannels(objects: Box[], edges: ModelEdge[], routing?: {
|
|
49
|
+
edgeGap?: number;
|
|
50
|
+
portGap?: number;
|
|
51
|
+
standoff?: number;
|
|
52
|
+
}): Map<string, Channel>;
|
|
53
|
+
export {};
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { type ResolvedAppearance } from '../model/appearance';
|
|
2
|
+
import type { CellsChrome, Lane, SequenceLayout } from '../model/types';
|
|
3
|
+
import { GROUP_HEADER, GROUP_INSET, contentOrigin } from './frame';
|
|
4
|
+
import { type Model, type ModelEdge, type ModelLayout, type ModelObject } from './syntax';
|
|
5
|
+
/** The single render context. Browser window size changes the camera, never the layout. */
|
|
6
|
+
export declare const RENDER_CONTEXT: {
|
|
7
|
+
readonly width: 1100;
|
|
8
|
+
readonly height: 720;
|
|
9
|
+
};
|
|
10
|
+
export { GROUP_HEADER, GROUP_INSET, contentOrigin };
|
|
11
|
+
export interface SceneObject extends ModelObject {
|
|
12
|
+
/** World (diagram) coordinates. */
|
|
13
|
+
x: number;
|
|
14
|
+
y: number;
|
|
15
|
+
w: number;
|
|
16
|
+
h: number;
|
|
17
|
+
/** Position relative to the parent's content origin; `pin` and `stay` use these. */
|
|
18
|
+
localX: number;
|
|
19
|
+
localY: number;
|
|
20
|
+
/** Local position from the automatic recipe alone, before refinements; `nudge` offsets this. */
|
|
21
|
+
baseX: number;
|
|
22
|
+
baseY: number;
|
|
23
|
+
depth: number;
|
|
24
|
+
/** Sequence participants: how far the dashed lifeline runs below the box. */
|
|
25
|
+
lifeline?: number;
|
|
26
|
+
/** Soft groups: the tint's rectangles, relative to the group's top left; the first holds the label. */
|
|
27
|
+
hull?: Array<{
|
|
28
|
+
x: number;
|
|
29
|
+
y: number;
|
|
30
|
+
w: number;
|
|
31
|
+
h: number;
|
|
32
|
+
}>;
|
|
33
|
+
/** Groups: lines the title wraps to, when more than one. */
|
|
34
|
+
titleLines?: number;
|
|
35
|
+
}
|
|
36
|
+
export interface Diagnostic {
|
|
37
|
+
level: 'error' | 'warning' | 'info';
|
|
38
|
+
code: string;
|
|
39
|
+
message: string;
|
|
40
|
+
/** Source line of the rule involved, when there is one. */
|
|
41
|
+
line?: number;
|
|
42
|
+
ids: string[];
|
|
43
|
+
}
|
|
44
|
+
/** A connection as the file declares it, plus the lane a fold's wrap edge returns along. */
|
|
45
|
+
export interface SceneEdge extends ModelEdge {
|
|
46
|
+
lane?: Lane;
|
|
47
|
+
/** A sequence message: the height of its row; it is drawn straight between lifelines there. */
|
|
48
|
+
row?: number;
|
|
49
|
+
}
|
|
50
|
+
export interface Scene {
|
|
51
|
+
model: Model;
|
|
52
|
+
title: string;
|
|
53
|
+
objects: SceneObject[];
|
|
54
|
+
byId: Map<string, SceneObject>;
|
|
55
|
+
edges: SceneEdge[];
|
|
56
|
+
diagnostics: Diagnostic[];
|
|
57
|
+
/** The file's resolved appearance: the spacing and type every size above was computed with. */
|
|
58
|
+
look: ResolvedAppearance;
|
|
59
|
+
/** Rulers and run-on pieces of byte and bit layouts, by group. */
|
|
60
|
+
cells: Map<string, CellsChrome>;
|
|
61
|
+
/** Sequence diagrams: the panel they are drawn on and their phases' row bands. */
|
|
62
|
+
sequence?: SequenceLayout;
|
|
63
|
+
}
|
|
64
|
+
type Size = {
|
|
65
|
+
w: number;
|
|
66
|
+
h: number;
|
|
67
|
+
};
|
|
68
|
+
type Pos = {
|
|
69
|
+
x: number;
|
|
70
|
+
y: number;
|
|
71
|
+
};
|
|
72
|
+
export declare function compile(source: string): Promise<Scene>;
|
|
73
|
+
/**
|
|
74
|
+
* Check source synchronously: every error `compile` can report, without running layout engines
|
|
75
|
+
* (they never add errors). Engine-governed scopes keep their built-in recipe in the result.
|
|
76
|
+
*/
|
|
77
|
+
export declare function checkSource(source: string): Scene;
|
|
78
|
+
/**
|
|
79
|
+
* The scene as layout sees it, for edits that write positions: soft and frameless groups left
|
|
80
|
+
* out, and each object under the container that lays it out, which its local position is
|
|
81
|
+
* relative to.
|
|
82
|
+
*/
|
|
83
|
+
export declare function layoutView(scene: Scene): Scene;
|
|
84
|
+
/** How far a soft refinement may give way before `check` warns that it no longer holds. */
|
|
85
|
+
export declare const RELAXED_WARNING = 16;
|
|
86
|
+
/** Solver budget for engine recipes; the same budget Compare and the timeline use. */
|
|
87
|
+
export declare const ENGINE_ITERATIONS = 640;
|
|
88
|
+
/** A labelled edge between two siblings, with the room its label needs across and down a gap. */
|
|
89
|
+
interface LabelRoom {
|
|
90
|
+
a: string;
|
|
91
|
+
b: string;
|
|
92
|
+
w: number;
|
|
93
|
+
h: number;
|
|
94
|
+
}
|
|
95
|
+
export declare function layoutFor(m: Model, scope: string): ModelLayout;
|
|
96
|
+
/**
|
|
97
|
+
* Size of a node: its requested size, or the default width with a height that fits the title in
|
|
98
|
+
* the theme's type and padding. A requested size is kept exactly; `overflow` reports a title that
|
|
99
|
+
* no longer fits in it.
|
|
100
|
+
*/
|
|
101
|
+
export declare function leafSize(o: ModelObject, size: {
|
|
102
|
+
width: number;
|
|
103
|
+
height?: number;
|
|
104
|
+
} | undefined, look: ResolvedAppearance): {
|
|
105
|
+
w: number;
|
|
106
|
+
h: number;
|
|
107
|
+
overflow: boolean;
|
|
108
|
+
};
|
|
109
|
+
/**
|
|
110
|
+
* Longest-path ranks, in declaration order. Cycles are broken first: a depth-first walk from the
|
|
111
|
+
* sources (then any node not yet reached), in declaration order, sets aside each edge that returns
|
|
112
|
+
* to a node still on the walk. A loop therefore keeps its path along the reading direction and
|
|
113
|
+
* only its return edge runs backwards.
|
|
114
|
+
*/
|
|
115
|
+
export declare function rankLayers(ids: string[], pairs: Array<[string, string]>): string[][];
|
|
116
|
+
/** A folded run: each band's ids in reading order, and the axis the bands read along. */
|
|
117
|
+
export interface Fold {
|
|
118
|
+
bands: string[][];
|
|
119
|
+
axis: 'right' | 'down';
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Fold a long run of ranks into bands, like lines of text: each band starts again at the
|
|
123
|
+
* beginning of the reading direction, and the bands stack across it. A run that is longer than
|
|
124
|
+
* the render context and more than `FOLD_ASPECT` times its depth is cut only between ranks (where
|
|
125
|
+
* no box spans the cut), into the fewest bands that bring it within both. Within a quarter of an
|
|
126
|
+
* even share, a cut is chosen for the fewest edges across it, keeping each decision with its
|
|
127
|
+
* branches and each loop whole, before an exact balance. Other runs are returned unchanged.
|
|
128
|
+
*
|
|
129
|
+
* `plan` is the same run laid out without its edge labels. Whether to fold, how many bands and
|
|
130
|
+
* where to cut are decided on it, so relabelling an edge never adds a band or moves a cut: the
|
|
131
|
+
* labels only widen the gaps they need inside their own band.
|
|
132
|
+
*/
|
|
133
|
+
export declare function foldRanks(items: Array<{
|
|
134
|
+
id: string;
|
|
135
|
+
w: number;
|
|
136
|
+
h: number;
|
|
137
|
+
}>, positions: Map<string, Pos>, axis: 'right' | 'down', gap: number, pairs: Array<[string, string]>, rooms?: LabelRoom[], decisions?: Set<string>, plan?: Map<string, Pos>, { aspect, fewest, room, }?: {
|
|
138
|
+
aspect?: number;
|
|
139
|
+
fewest?: number;
|
|
140
|
+
room?: number;
|
|
141
|
+
}): {
|
|
142
|
+
positions: Map<string, Pos>;
|
|
143
|
+
fold?: Fold;
|
|
144
|
+
};
|
|
145
|
+
/** How many times orthogonal paths, given as points along and across, cross one another. */
|
|
146
|
+
export declare function crossings(paths: Array<Array<{
|
|
147
|
+
u: number;
|
|
148
|
+
v: number;
|
|
149
|
+
}>>): number;
|
|
150
|
+
/** The order of up to six items that scores fewest crossings; the first such, from `items`. */
|
|
151
|
+
export declare function fewestCrossings<T>(items: T[], score: (order: T[]) => number): T[];
|
|
152
|
+
/**
|
|
153
|
+
* Lay out a model. `arranged` holds world positions from layout engines; scopes that an engine
|
|
154
|
+
* governs take their children's relative placement from it instead of their built-in recipe.
|
|
155
|
+
*
|
|
156
|
+
* Nodes are laid out on slots: their size in the reference appearance (the default theme, with
|
|
157
|
+
* the file's own overrides), so a theme switch keeps rows, order and positions. Each node is drawn
|
|
158
|
+
* at its theme's size in its slot. A slot grows only where the theme's size is larger
|
|
159
|
+
* than the scope's gap can absorb (`SLOT_SPILL`), or where spilling would bring two boxes closer
|
|
160
|
+
* than `MIN_GAP`. With `slots`, objects come out at their slot size (the engines' input).
|
|
161
|
+
*/
|
|
162
|
+
export declare function layoutModel(m: Model, arranged?: Map<string, Pos & Size>, slots?: boolean): Scene;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/** Group frame metrics shared by the compiler, the projection and the translator. */
|
|
2
|
+
/** Space between a group's frame and its content, on the sides and bottom. */
|
|
3
|
+
export declare const GROUP_INSET = 24;
|
|
4
|
+
/**
|
|
5
|
+
* Space between a group's top edge and its content in the default theme; the title sits in it.
|
|
6
|
+
* Themes with taller titles reserve more (`ResolvedAppearance.groupHeader`).
|
|
7
|
+
*/
|
|
8
|
+
export declare const GROUP_HEADER = 48;
|
|
9
|
+
/**
|
|
10
|
+
* Horizontal room a group title needs besides its text: the icon and gap before it (33) and the
|
|
11
|
+
* frame controls after it (64), as `GroupView` and the SVG export truncate titles.
|
|
12
|
+
*/
|
|
13
|
+
export declare const GROUP_TITLE_CHROME: number;
|
|
14
|
+
/** Room a soft group's tint leaves round its members, and above them for its label. */
|
|
15
|
+
export declare const SOFT_PAD = 10;
|
|
16
|
+
export declare const SOFT_LABEL = 18;
|
|
17
|
+
/** Where a soft group's label sits in its tint: in the annotation face, at the top left. */
|
|
18
|
+
export declare const SOFT_TITLE: {
|
|
19
|
+
x: number;
|
|
20
|
+
y: number;
|
|
21
|
+
};
|
|
22
|
+
/** Corner radius of each rectangle of a tint; small, so joined rectangles read as one shape. */
|
|
23
|
+
export declare const SOFT_RADIUS = 6;
|
|
24
|
+
/** Dash of a sequence participant's lifeline; quieter than a message line. */
|
|
25
|
+
export declare const LIFELINE: {
|
|
26
|
+
dash: string;
|
|
27
|
+
width: number;
|
|
28
|
+
};
|
|
29
|
+
/** Top-left of a group's content area, which its children's local positions are relative to. */
|
|
30
|
+
export declare const contentOrigin: (group: {
|
|
31
|
+
x: number;
|
|
32
|
+
y: number;
|
|
33
|
+
}, header?: number) => {
|
|
34
|
+
x: number;
|
|
35
|
+
y: number;
|
|
36
|
+
};
|
|
37
|
+
/** Horizontal room a `cells` group's title needs besides its text: padding and the collapse control. */
|
|
38
|
+
export declare const CELLS_TITLE_CHROME: number;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Lane } from '../model/types';
|
|
2
|
+
import type { ModelEdge } from './syntax';
|
|
3
|
+
interface Box {
|
|
4
|
+
id: string;
|
|
5
|
+
type: string;
|
|
6
|
+
shape?: string;
|
|
7
|
+
parent: string;
|
|
8
|
+
x: number;
|
|
9
|
+
y: number;
|
|
10
|
+
w: number;
|
|
11
|
+
h: number;
|
|
12
|
+
}
|
|
13
|
+
/** A scope arranged along a reading axis, with its fold's bands when it folded. */
|
|
14
|
+
export interface FlowScope {
|
|
15
|
+
scope: string;
|
|
16
|
+
axis: 'right' | 'down';
|
|
17
|
+
bands?: string[][];
|
|
18
|
+
}
|
|
19
|
+
export declare function returnLanes(flows: FlowScope[], edges: ModelEdge[], byId: Map<string, Box>, taken: Set<string>, labelSize?: (label: string) => {
|
|
20
|
+
w: number;
|
|
21
|
+
h: number;
|
|
22
|
+
}): Map<string, Lane>;
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { Diagram, Rect } from '../model/types';
|
|
2
|
+
import type { Scene } from './compile';
|
|
3
|
+
/** Editor state that is not part of the source and survives a reprojection. */
|
|
4
|
+
export type ViewState = Partial<Pick<Diagram, 'settings' | 'camera' | 'theme' | 'collapsed'>>;
|
|
5
|
+
export declare function projectScene(scene: Scene, view?: ViewState): Diagram;
|
|
6
|
+
export interface CanonicalGeometry {
|
|
7
|
+
nodes: Array<{
|
|
8
|
+
id: string;
|
|
9
|
+
parent: string;
|
|
10
|
+
x: number;
|
|
11
|
+
y: number;
|
|
12
|
+
w: number;
|
|
13
|
+
h: number;
|
|
14
|
+
}>;
|
|
15
|
+
routes: Array<{
|
|
16
|
+
id: string;
|
|
17
|
+
points: Array<{
|
|
18
|
+
x: number;
|
|
19
|
+
y: number;
|
|
20
|
+
}>;
|
|
21
|
+
}>;
|
|
22
|
+
}
|
|
23
|
+
/** Rectangles for everything visible, as the canvas draws them. */
|
|
24
|
+
export declare function visibleRects(doc: Diagram): {
|
|
25
|
+
vg: import("../model/graph").VisibleGraph;
|
|
26
|
+
rects: Map<string, Rect>;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Node rectangles and route points for a projected document. Edge label positions are left out:
|
|
30
|
+
* the browser measures label text with real fonts, which Node cannot reproduce.
|
|
31
|
+
*/
|
|
32
|
+
export declare function canonicalGeometry(doc: Diagram): CanonicalGeometry;
|
|
33
|
+
export declare function measured(doc: Diagram, rects: Map<string, Rect>, routes: Array<{
|
|
34
|
+
id: string;
|
|
35
|
+
points: Array<{
|
|
36
|
+
x: number;
|
|
37
|
+
y: number;
|
|
38
|
+
}>;
|
|
39
|
+
}>): CanonicalGeometry;
|
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `.draft` diagram language: a line-based source format that keeps comments, plus a model
|
|
3
|
+
* parser and a formatter. Adapted from the Meld 0.1 prototype in `reference/meld/original`.
|
|
4
|
+
*
|
|
5
|
+
* Source is kept as a list of lines so that edits can change single statements and formatting
|
|
6
|
+
* keeps every comment and unrelated statement.
|
|
7
|
+
*/
|
|
8
|
+
import { type DiagramAppearance, type Shade } from '../model/appearance';
|
|
9
|
+
import { type EndMarker } from '../model/markers';
|
|
10
|
+
import type { Status } from '../model/status';
|
|
11
|
+
import type { ColorKey, LayoutAlgorithmId, LayoutSettings, PortSide, RoutingSettings, ShapeKind } from '../model/types';
|
|
12
|
+
export declare class DslError extends Error {
|
|
13
|
+
readonly line: number;
|
|
14
|
+
readonly column: number;
|
|
15
|
+
constructor(message: string, line?: number, column?: number);
|
|
16
|
+
}
|
|
17
|
+
/** Change marks before `node`, `group` and `edge`, read like a diff, and the status each sets. */
|
|
18
|
+
export declare const MARKS: {
|
|
19
|
+
readonly '+': "added";
|
|
20
|
+
readonly '-': "removed";
|
|
21
|
+
readonly '~': "changed";
|
|
22
|
+
readonly '.': "context";
|
|
23
|
+
};
|
|
24
|
+
export type Mark = keyof typeof MARKS;
|
|
25
|
+
/** A word in a statement. Quoted words are strings; bare words are identifiers and numbers. */
|
|
26
|
+
export interface Word {
|
|
27
|
+
value: string;
|
|
28
|
+
quoted: boolean;
|
|
29
|
+
}
|
|
30
|
+
export interface Statement {
|
|
31
|
+
kind: 'statement';
|
|
32
|
+
command: string;
|
|
33
|
+
/** Change mark written before the command, as in a diff: `+`, `-`, `~` or `.`. */
|
|
34
|
+
mark?: Mark;
|
|
35
|
+
args: Word[];
|
|
36
|
+
attrs: Array<[string, Word]>;
|
|
37
|
+
/** Inline comment including its `#` or `//` marker. */
|
|
38
|
+
comment?: string;
|
|
39
|
+
/** 1-based line in the source this statement was parsed from; 0 when added by an edit. */
|
|
40
|
+
line: number;
|
|
41
|
+
}
|
|
42
|
+
export type SourceLine = {
|
|
43
|
+
kind: 'blank';
|
|
44
|
+
} | {
|
|
45
|
+
kind: 'comment';
|
|
46
|
+
text: string;
|
|
47
|
+
} | Statement;
|
|
48
|
+
export interface SourceDoc {
|
|
49
|
+
lines: SourceLine[];
|
|
50
|
+
}
|
|
51
|
+
export declare const bare: (value: string | number) => Word;
|
|
52
|
+
export declare const quoted: (value: string) => Word;
|
|
53
|
+
/**
|
|
54
|
+
* Split one line into raw tokens, each with its 1-based start column, and a trailing comment.
|
|
55
|
+
* Quoted tokens keep their quotes.
|
|
56
|
+
*/
|
|
57
|
+
export declare function tokenize(text: string, line?: number): {
|
|
58
|
+
tokens: string[];
|
|
59
|
+
columns: number[];
|
|
60
|
+
comment?: string;
|
|
61
|
+
};
|
|
62
|
+
/** Read source text into lines. Only lexical errors are reported here. */
|
|
63
|
+
export declare function readSource(source: string): SourceDoc;
|
|
64
|
+
export declare function printStatement(s: Statement): string;
|
|
65
|
+
/**
|
|
66
|
+
* Print source consistently: one space between words, no indentation, at most one blank line in a
|
|
67
|
+
* row, and a final newline. Comments and statement order are kept.
|
|
68
|
+
*/
|
|
69
|
+
export declare function printSource(doc: SourceDoc): string;
|
|
70
|
+
/** Format source text. Throws `DslError` for lexical errors; semantics are not checked. */
|
|
71
|
+
export declare const formatSource: (source: string) => string;
|
|
72
|
+
export type DslColor = ColorKey | 'auto';
|
|
73
|
+
export type DslShape = Exclude<ShapeKind, 'icon' | 'image'>;
|
|
74
|
+
/** `cells` lays a group's members edge to edge as one object: a sequence, table or byte layout. */
|
|
75
|
+
export type Algorithm = 'flow' | 'row' | 'column' | 'lanes' | 'sequence' | 'cells';
|
|
76
|
+
export interface ModelObject {
|
|
77
|
+
id: string;
|
|
78
|
+
type: 'node' | 'group';
|
|
79
|
+
label: string;
|
|
80
|
+
parent: string;
|
|
81
|
+
color: DslColor;
|
|
82
|
+
/** Explicit shade; omitted means the default for the object type. */
|
|
83
|
+
shade?: Shade;
|
|
84
|
+
shape: DslShape;
|
|
85
|
+
/** From a change mark; unchanged when omitted. */
|
|
86
|
+
status?: Status;
|
|
87
|
+
/** With `~`: the label before the change. */
|
|
88
|
+
was?: string;
|
|
89
|
+
/** With `~`, nodes only: the shape before the change. */
|
|
90
|
+
wasShape?: DslShape;
|
|
91
|
+
/** With `~`, nodes only: the count before the change; 1 means a single box. */
|
|
92
|
+
wasCount?: number | string;
|
|
93
|
+
/** A link to open from exported drawings, such as a source file or URL. */
|
|
94
|
+
href?: string;
|
|
95
|
+
/**
|
|
96
|
+
* Nodes only: how many things this one box stands for, drawn as a stack with a badge. A short
|
|
97
|
+
* symbol such as `N` or `many` stands for an unknown number.
|
|
98
|
+
*/
|
|
99
|
+
count?: number | string;
|
|
100
|
+
/**
|
|
101
|
+
* Groups only: `soft` draws a tint behind the members and `none` draws nothing. Either way the
|
|
102
|
+
* group is not a layout scope: its members are laid out with the nearest framed container's.
|
|
103
|
+
*/
|
|
104
|
+
frame?: 'soft' | 'none';
|
|
105
|
+
/** Groups only: `fold=never` keeps the group's chain in one column even when it is much the tallest. */
|
|
106
|
+
fold?: 'never';
|
|
107
|
+
/** Set by the compiler: the soft groups this object sits in below its layout scope, outermost first. */
|
|
108
|
+
soft?: string[];
|
|
109
|
+
/** Cells only: how many columns (or units) of its group's grid the cell covers; `var` for a
|
|
110
|
+
* field of variable length in a byte or bit layout. */
|
|
111
|
+
span?: number | 'var';
|
|
112
|
+
line: number;
|
|
113
|
+
}
|
|
114
|
+
export interface ModelEdge {
|
|
115
|
+
id: string;
|
|
116
|
+
source: string;
|
|
117
|
+
target: string;
|
|
118
|
+
label: string;
|
|
119
|
+
dashed: boolean;
|
|
120
|
+
from: PortSide;
|
|
121
|
+
to: PortSide;
|
|
122
|
+
/** From a change mark; unchanged when omitted. */
|
|
123
|
+
status?: Status;
|
|
124
|
+
/** With `~`: the label before the change. */
|
|
125
|
+
was?: string;
|
|
126
|
+
/** `directed=false`: an undirected connection, drawn without an arrowhead. */
|
|
127
|
+
directed?: false;
|
|
128
|
+
/** `head=`: the mark at the target end, when it isn't the plain arrow. */
|
|
129
|
+
head?: EndMarker;
|
|
130
|
+
/** `tail=`: the mark at the source end, when it has one. */
|
|
131
|
+
tail?: EndMarker;
|
|
132
|
+
/** `constraint=false`: drawn and routed, but layout doesn't rank or order by it. */
|
|
133
|
+
constraint?: false;
|
|
134
|
+
line: number;
|
|
135
|
+
}
|
|
136
|
+
/** A layout engine run cold over a scope's subtree; see `src/engines/layout-engine.js`. */
|
|
137
|
+
export interface EngineRecipe {
|
|
138
|
+
algorithm: LayoutAlgorithmId;
|
|
139
|
+
params: Partial<LayoutSettings>;
|
|
140
|
+
}
|
|
141
|
+
/** Image shapes a drawing can aim for (`fit=`, `vary --fit`): width over height. */
|
|
142
|
+
export declare const FITS: {
|
|
143
|
+
readonly wide: 2;
|
|
144
|
+
readonly slide: 1.78;
|
|
145
|
+
readonly square: 1;
|
|
146
|
+
readonly page: 0.77;
|
|
147
|
+
readonly tall: 0.6;
|
|
148
|
+
};
|
|
149
|
+
export type Fit = keyof typeof FITS;
|
|
150
|
+
export interface ModelLayout {
|
|
151
|
+
scope: string;
|
|
152
|
+
algorithm: Algorithm;
|
|
153
|
+
/** Set when the scope is arranged by a layout engine instead of a built-in recipe. */
|
|
154
|
+
engine?: EngineRecipe;
|
|
155
|
+
direction: 'auto' | 'right' | 'down';
|
|
156
|
+
/** `cells` only: columns in each row of the grid; one row or column without it. */
|
|
157
|
+
columns?: number;
|
|
158
|
+
/** `cells` only: a byte or bit layout, where each column is one unit of the same width. */
|
|
159
|
+
unit?: 'bit' | 'byte';
|
|
160
|
+
/** With `unit`: the width of one unit, and whether unit numbers run above the first row. */
|
|
161
|
+
unitWidth?: number;
|
|
162
|
+
ruler?: boolean;
|
|
163
|
+
/** `flow` only: whether a long run of ranks folds into bands. Engines take `fold` as a param. */
|
|
164
|
+
fold: 'auto' | 'never';
|
|
165
|
+
/** Root only: the image shape to aim for; compile tries direction and folding to get closest. */
|
|
166
|
+
fit?: Fit;
|
|
167
|
+
gap: number;
|
|
168
|
+
minWidth: number;
|
|
169
|
+
minHeight: number;
|
|
170
|
+
line: number;
|
|
171
|
+
}
|
|
172
|
+
export type Hint = {
|
|
173
|
+
type: 'order';
|
|
174
|
+
scope: string;
|
|
175
|
+
ids: string[];
|
|
176
|
+
line: number;
|
|
177
|
+
} | {
|
|
178
|
+
type: 'align';
|
|
179
|
+
axis: 'x' | 'y';
|
|
180
|
+
ids: string[];
|
|
181
|
+
strength: Strength;
|
|
182
|
+
line: number;
|
|
183
|
+
} | {
|
|
184
|
+
type: 'near';
|
|
185
|
+
id: string;
|
|
186
|
+
ref: string;
|
|
187
|
+
side: NearSide;
|
|
188
|
+
gap: number;
|
|
189
|
+
offset: number;
|
|
190
|
+
strength: Strength;
|
|
191
|
+
line: number;
|
|
192
|
+
} | {
|
|
193
|
+
type: 'nudge';
|
|
194
|
+
id: string;
|
|
195
|
+
dx: number;
|
|
196
|
+
dy: number;
|
|
197
|
+
line: number;
|
|
198
|
+
} | {
|
|
199
|
+
type: 'stay';
|
|
200
|
+
id: string;
|
|
201
|
+
x: number;
|
|
202
|
+
y: number;
|
|
203
|
+
weight: number;
|
|
204
|
+
line: number;
|
|
205
|
+
} | {
|
|
206
|
+
type: 'pin';
|
|
207
|
+
id: string;
|
|
208
|
+
x: number;
|
|
209
|
+
y: number;
|
|
210
|
+
line: number;
|
|
211
|
+
}
|
|
212
|
+
/** `height` is unset for `height=auto`: the title's height at that width, as without a size. */
|
|
213
|
+
| {
|
|
214
|
+
type: 'size';
|
|
215
|
+
id: string;
|
|
216
|
+
width: number;
|
|
217
|
+
height?: number;
|
|
218
|
+
line: number;
|
|
219
|
+
};
|
|
220
|
+
export type Strength = 'prefer' | 'required';
|
|
221
|
+
/**
|
|
222
|
+
* What `near id ref` places against: `ref` itself when it is a sibling of `id`, else the group
|
|
223
|
+
* around `ref` that is `id`'s sibling. Undefined when `ref` is not inside one.
|
|
224
|
+
*/
|
|
225
|
+
export declare function nearAnchor(by: Map<string, ModelObject>, id: string, ref: string): string | undefined;
|
|
226
|
+
export type NearSide = 'right' | 'left' | 'above' | 'below';
|
|
227
|
+
export type HintType = Hint['type'];
|
|
228
|
+
export declare const POSITION_HINTS: HintType[];
|
|
229
|
+
export interface Model {
|
|
230
|
+
title: string;
|
|
231
|
+
objects: ModelObject[];
|
|
232
|
+
edges: ModelEdge[];
|
|
233
|
+
layouts: ModelLayout[];
|
|
234
|
+
hints: Hint[];
|
|
235
|
+
/** Router settings from a `routing` statement. */
|
|
236
|
+
routing: Partial<RoutingSettings>;
|
|
237
|
+
/** Theme, overrides and color definitions from `theme` and `theme-color` statements. */
|
|
238
|
+
appearance: DiagramAppearance;
|
|
239
|
+
/** Source line of the `theme` statement, and of each `theme-color` by `family:shade`. */
|
|
240
|
+
themeLine: number;
|
|
241
|
+
colorLines: Map<string, number>;
|
|
242
|
+
/** Source line of each `legend` entry, in order. */
|
|
243
|
+
legendLines: number[];
|
|
244
|
+
/** Source line of each `note`, in order. */
|
|
245
|
+
noteLines: number[];
|
|
246
|
+
/** Source line of each `footnote`, in order. */
|
|
247
|
+
footnoteLines: number[];
|
|
248
|
+
/** Source line of each ID an emphasis state lists, by `state:id`. */
|
|
249
|
+
stateLines: Map<string, number>;
|
|
250
|
+
/** Sequence diagrams: `phase` statements, each a run of messages drawn as a row band. */
|
|
251
|
+
phases: Array<{
|
|
252
|
+
id: string;
|
|
253
|
+
label: string;
|
|
254
|
+
ids: string[];
|
|
255
|
+
line: number;
|
|
256
|
+
}>;
|
|
257
|
+
/** Sequence diagrams: the `was-order` statement, the older version's message order. */
|
|
258
|
+
wasOrder?: {
|
|
259
|
+
ids: string[];
|
|
260
|
+
line: number;
|
|
261
|
+
};
|
|
262
|
+
/** Problems that do not stop the file from drawing, such as a `config` key set twice. */
|
|
263
|
+
warnings: {
|
|
264
|
+
code: string;
|
|
265
|
+
message: string;
|
|
266
|
+
line: number;
|
|
267
|
+
}[];
|
|
268
|
+
}
|
|
269
|
+
/** `config` keys and the setting each sets. */
|
|
270
|
+
export declare const CONFIG_KEYS: {
|
|
271
|
+
readonly 'link-base': "linkBase";
|
|
272
|
+
readonly editor: "editor";
|
|
273
|
+
readonly 'strike-removed': "strikeRemoved";
|
|
274
|
+
};
|
|
275
|
+
/** Theme attributes in the file and the override each sets. */
|
|
276
|
+
export declare const THEME_ATTRS: {
|
|
277
|
+
readonly 'padding-x': "paddingX";
|
|
278
|
+
readonly 'padding-y': "paddingY";
|
|
279
|
+
readonly radius: "radius";
|
|
280
|
+
readonly 'title-font': "titleFont";
|
|
281
|
+
readonly 'annotation-font': "annotationFont";
|
|
282
|
+
readonly canvas: "canvas";
|
|
283
|
+
readonly text: "text";
|
|
284
|
+
readonly connection: "connection";
|
|
285
|
+
};
|
|
286
|
+
type Param<K extends string> = {
|
|
287
|
+
key: K;
|
|
288
|
+
min: number;
|
|
289
|
+
max: number;
|
|
290
|
+
} | {
|
|
291
|
+
key: K;
|
|
292
|
+
choices: readonly string[];
|
|
293
|
+
};
|
|
294
|
+
/**
|
|
295
|
+
* Layout engines a file can name. `separate` is left out: it only repairs overlaps in the current
|
|
296
|
+
* drawing, so it cannot be recomputed from the source.
|
|
297
|
+
*/
|
|
298
|
+
export declare const ENGINES: readonly LayoutAlgorithmId[];
|
|
299
|
+
/** Engine settings by source attribute. Ranges match the engine's own limits. */
|
|
300
|
+
export declare const ENGINE_PARAMS: Record<string, Param<keyof LayoutSettings>>;
|
|
301
|
+
/** Router settings by source attribute. Ranges match the router's own limits. */
|
|
302
|
+
export declare const ROUTING_PARAMS: Record<string, Param<keyof RoutingSettings>>;
|
|
303
|
+
/** Source attribute for an engine or router setting. */
|
|
304
|
+
export declare const paramAttr: (table: Record<string, Param<string>>, key: string) => string | undefined;
|
|
305
|
+
export declare const isIdentifier: (s: string) => boolean;
|
|
306
|
+
export declare const COLORS: DslColor[];
|
|
307
|
+
export declare const DSL_SHAPES: DslShape[];
|
|
308
|
+
/** Shapes a node's box can draw as it was: a marker's box is a thin cut, so it has no other shape. */
|
|
309
|
+
export declare const PAST_SHAPES: ("box" | "text" | "pill" | "circle" | "diamond")[];
|
|
310
|
+
/** Parse and validate source. Throws `DslError` with a line number for the first problem. */
|
|
311
|
+
export declare function parseModel(source: string | SourceDoc): Model;
|
|
312
|
+
/**
|
|
313
|
+
* The container that lays an object out: its parent, or the nearest framed container above it
|
|
314
|
+
* when its parent is a soft or frameless group. Soft groups are never layout scopes.
|
|
315
|
+
*/
|
|
316
|
+
export declare function layoutParent(by: Map<string, ModelObject>, id: string): string;
|
|
317
|
+
export {};
|