@draftably/markdown 0.0.0-stage → 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 +24 -2
- package/dist/LICENSE +21 -0
- package/dist/chunks/core-D4HpamVq.js +323 -0
- package/dist/chunks/mermaid-facade-BoLWBerE.js +289 -0
- package/dist/chunks/mermaid-importer-IVovOQE9.js +3753 -0
- package/dist/chunks/metadata-Dx6T_2Zy.js +53 -0
- package/dist/client.js +153 -0
- package/dist/files.js +103 -0
- package/dist/index.js +8 -0
- package/dist/markdown-it.js +156 -0
- package/dist/mermaid.js +93 -0
- package/dist/remark.js +86 -0
- package/dist/types/packages/markdown/src/client-validation.d.ts +5 -0
- package/dist/types/packages/markdown/src/client.d.ts +12 -0
- package/dist/types/packages/markdown/src/core.d.ts +110 -0
- package/dist/types/packages/markdown/src/files.d.ts +12 -0
- package/dist/types/packages/markdown/src/index.d.ts +3 -0
- package/dist/types/packages/markdown/src/markdown-it-helpers.d.ts +9 -0
- package/dist/types/packages/markdown/src/markdown-it.d.ts +30 -0
- package/dist/types/packages/markdown/src/mermaid.d.ts +8 -0
- package/dist/types/packages/markdown/src/metadata.d.ts +9 -0
- package/dist/types/packages/markdown/src/remark.d.ts +21 -0
- package/dist/types/packages/markdown/src/source.d.ts +4 -0
- 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 +53 -3
|
@@ -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 {};
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/** Build native source from the facts retained by an importer. */
|
|
2
|
+
import type { EndMarker } from '../model/markers';
|
|
3
|
+
export type Format = 'dot' | 'mermaid' | 'd2';
|
|
4
|
+
export type Impact = 'syntax' | 'semantics' | 'appearance' | 'layout' | 'security' | 'limit';
|
|
5
|
+
export interface Diagnostic {
|
|
6
|
+
code: string;
|
|
7
|
+
severity: 'error' | 'warning' | 'info';
|
|
8
|
+
impact: Impact;
|
|
9
|
+
message: string;
|
|
10
|
+
line?: number;
|
|
11
|
+
column?: number;
|
|
12
|
+
foreignIds?: string[];
|
|
13
|
+
}
|
|
14
|
+
export interface NativeObject {
|
|
15
|
+
id: string;
|
|
16
|
+
kind: 'node' | 'group';
|
|
17
|
+
label: string;
|
|
18
|
+
parent?: string;
|
|
19
|
+
shape?: 'box' | 'pill' | 'circle' | 'diamond' | 'text';
|
|
20
|
+
color?: string;
|
|
21
|
+
shade?: number;
|
|
22
|
+
}
|
|
23
|
+
export interface NativeEdge {
|
|
24
|
+
id: string;
|
|
25
|
+
from: string;
|
|
26
|
+
to: string;
|
|
27
|
+
label: string;
|
|
28
|
+
directed: boolean;
|
|
29
|
+
head?: EndMarker;
|
|
30
|
+
tail?: EndMarker;
|
|
31
|
+
dashed?: boolean;
|
|
32
|
+
constraint?: false;
|
|
33
|
+
fromSide?: 'left' | 'right' | 'top' | 'bottom';
|
|
34
|
+
toSide?: 'left' | 'right' | 'top' | 'bottom';
|
|
35
|
+
}
|
|
36
|
+
export interface NativeLayout {
|
|
37
|
+
scope: string;
|
|
38
|
+
kind: 'flow' | 'column' | 'row' | 'sequence';
|
|
39
|
+
direction?: 'right' | 'down';
|
|
40
|
+
}
|
|
41
|
+
export interface NativeColor {
|
|
42
|
+
name: string;
|
|
43
|
+
fill: string;
|
|
44
|
+
stroke: string;
|
|
45
|
+
ink: string;
|
|
46
|
+
}
|
|
47
|
+
export interface NativePhase {
|
|
48
|
+
id: string;
|
|
49
|
+
label: string;
|
|
50
|
+
members: string[];
|
|
51
|
+
}
|
|
52
|
+
export interface NativeNote {
|
|
53
|
+
text: string;
|
|
54
|
+
near?: string;
|
|
55
|
+
side?: 'left' | 'right' | 'above' | 'below';
|
|
56
|
+
}
|
|
57
|
+
export interface NativePlan {
|
|
58
|
+
title: string;
|
|
59
|
+
objects: NativeObject[];
|
|
60
|
+
edges: NativeEdge[];
|
|
61
|
+
layouts: NativeLayout[];
|
|
62
|
+
colors: NativeColor[];
|
|
63
|
+
/** Sequence diagrams only. */
|
|
64
|
+
phases?: NativePhase[];
|
|
65
|
+
notes?: NativeNote[];
|
|
66
|
+
}
|
|
67
|
+
export interface IdMapping {
|
|
68
|
+
kind: string;
|
|
69
|
+
foreign: string;
|
|
70
|
+
native: string;
|
|
71
|
+
}
|
|
72
|
+
export interface ImportResult {
|
|
73
|
+
status: 'ready' | 'needs-review' | 'failed';
|
|
74
|
+
format: Format;
|
|
75
|
+
family: string;
|
|
76
|
+
diagnostics: Diagnostic[];
|
|
77
|
+
/** Absent on every fatal error; callers must not apply a partial graph. */
|
|
78
|
+
nativeSource?: string;
|
|
79
|
+
facts?: NativePlan;
|
|
80
|
+
ids: IdMapping[];
|
|
81
|
+
requires: string[];
|
|
82
|
+
}
|
|
83
|
+
export declare const LIMITS: Readonly<{
|
|
84
|
+
sourceBytes: number;
|
|
85
|
+
objects: 500;
|
|
86
|
+
edges: 1200;
|
|
87
|
+
depth: 12;
|
|
88
|
+
labelChars: number;
|
|
89
|
+
totalLabelBytes: number;
|
|
90
|
+
outputBytes: number;
|
|
91
|
+
nativeSourceChars: 300000;
|
|
92
|
+
}>;
|
|
93
|
+
export declare class Ids {
|
|
94
|
+
readonly entries: IdMapping[];
|
|
95
|
+
private readonly byForeign;
|
|
96
|
+
private readonly taken;
|
|
97
|
+
get(kind: string, foreign: string, preferred?: string): string;
|
|
98
|
+
}
|
|
99
|
+
export declare const quote: (value: string) => string;
|
|
100
|
+
export declare const blankPlan: (title: string) => NativePlan;
|
|
101
|
+
export declare function inputLimit(source: string): Diagnostic[];
|
|
102
|
+
export declare function finish(format: Format, family: string, plan: NativePlan, diagnostics: Diagnostic[], ids: Ids): ImportResult;
|
|
103
|
+
/** Only an explicit hex color is accepted. No CSS, URL, or Graphviz colorscheme interpretation. */
|
|
104
|
+
export declare function hex(value: string | undefined): string | undefined;
|
|
105
|
+
export declare function applyColor(plan: NativePlan, o: NativeObject, fill?: string, stroke?: string, ink?: string): void;
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tested against mermaid 12.2.0. Uses its internal DB behind a narrow, checked boundary.
|
|
3
|
+
* This file parses only; it neither renders Mermaid nor attaches interaction callbacks.
|
|
4
|
+
* Call in an isolated Node worker with a DOM, or in a dedicated browser Mermaid instance.
|
|
5
|
+
*/
|
|
6
|
+
export declare const MERMAID_VERSION: "12.2.0";
|
|
7
|
+
export type ParserDiagnostic = {
|
|
8
|
+
code: string;
|
|
9
|
+
severity: 'warning' | 'error';
|
|
10
|
+
message: string;
|
|
11
|
+
line?: number;
|
|
12
|
+
column?: number;
|
|
13
|
+
locationKind?: 'source' | 'parser-relative';
|
|
14
|
+
};
|
|
15
|
+
export type FlowVertex = {
|
|
16
|
+
id: string;
|
|
17
|
+
text: string;
|
|
18
|
+
type?: string;
|
|
19
|
+
labelType: string;
|
|
20
|
+
classes: string[];
|
|
21
|
+
styles: string[];
|
|
22
|
+
link?: string;
|
|
23
|
+
icon?: string;
|
|
24
|
+
img?: string;
|
|
25
|
+
props?: Record<string, unknown>;
|
|
26
|
+
};
|
|
27
|
+
export type FlowEdge = {
|
|
28
|
+
start: string;
|
|
29
|
+
end: string;
|
|
30
|
+
text: string;
|
|
31
|
+
type?: string;
|
|
32
|
+
stroke?: string;
|
|
33
|
+
id?: string;
|
|
34
|
+
isUserDefinedId: boolean;
|
|
35
|
+
labelType: string;
|
|
36
|
+
classes: string[];
|
|
37
|
+
style: string[];
|
|
38
|
+
length?: number;
|
|
39
|
+
interpolate?: string;
|
|
40
|
+
animate?: boolean;
|
|
41
|
+
animation?: string;
|
|
42
|
+
};
|
|
43
|
+
export type FlowGroup = {
|
|
44
|
+
id: string;
|
|
45
|
+
title: string;
|
|
46
|
+
nodes: string[];
|
|
47
|
+
dir?: string;
|
|
48
|
+
labelType: string;
|
|
49
|
+
classes: string[];
|
|
50
|
+
metadata?: Record<string, unknown>;
|
|
51
|
+
};
|
|
52
|
+
export type FlowClass = {
|
|
53
|
+
id: string;
|
|
54
|
+
styles: string[];
|
|
55
|
+
textStyles: string[];
|
|
56
|
+
};
|
|
57
|
+
export type FlowSnapshot = {
|
|
58
|
+
format: 'mermaid';
|
|
59
|
+
family: 'flowchart';
|
|
60
|
+
parserVersion: typeof MERMAID_VERSION;
|
|
61
|
+
direction: string;
|
|
62
|
+
vertices: FlowVertex[];
|
|
63
|
+
edges: FlowEdge[];
|
|
64
|
+
groups: FlowGroup[];
|
|
65
|
+
classes: FlowClass[];
|
|
66
|
+
defaultEdgeStyle: string[];
|
|
67
|
+
defaultEdgeInterpolate?: string;
|
|
68
|
+
};
|
|
69
|
+
/** One entry of Mermaid's ordered sequence log; `kind` is its LINETYPE name. */
|
|
70
|
+
export type SequenceEvent = {
|
|
71
|
+
kind: string;
|
|
72
|
+
from?: string;
|
|
73
|
+
to?: string;
|
|
74
|
+
text: string;
|
|
75
|
+
placement?: 'left' | 'right' | 'over';
|
|
76
|
+
central: boolean;
|
|
77
|
+
};
|
|
78
|
+
export type SequenceActor = {
|
|
79
|
+
id: string;
|
|
80
|
+
name: string;
|
|
81
|
+
type: string;
|
|
82
|
+
box?: number;
|
|
83
|
+
links: string[];
|
|
84
|
+
};
|
|
85
|
+
export type SequenceBox = {
|
|
86
|
+
name?: string;
|
|
87
|
+
fill?: string;
|
|
88
|
+
};
|
|
89
|
+
export type SequenceSnapshot = {
|
|
90
|
+
format: 'mermaid';
|
|
91
|
+
family: 'sequence';
|
|
92
|
+
parserVersion: typeof MERMAID_VERSION;
|
|
93
|
+
title?: string;
|
|
94
|
+
actors: SequenceActor[];
|
|
95
|
+
boxes: SequenceBox[];
|
|
96
|
+
events: SequenceEvent[];
|
|
97
|
+
created: string[];
|
|
98
|
+
destroyed: string[];
|
|
99
|
+
};
|
|
100
|
+
export type ParseFlowResult = {
|
|
101
|
+
ok: true;
|
|
102
|
+
snapshot: FlowSnapshot | SequenceSnapshot;
|
|
103
|
+
diagnostics: ParserDiagnostic[];
|
|
104
|
+
} | {
|
|
105
|
+
ok: false;
|
|
106
|
+
diagnostics: ParserDiagnostic[];
|
|
107
|
+
};
|
|
108
|
+
type MermaidApi = Pick<(typeof import('mermaid'))['default'], 'initialize' | 'mermaidAPI'>;
|
|
109
|
+
/** DB strings contain Mermaid entity sentinels; preserve entity spelling for text decoding. */
|
|
110
|
+
export declare function restoreEntitySpelling(value: string): string;
|
|
111
|
+
/**
|
|
112
|
+
* Use an unattached HTML template only. Its content is inert and is never adopted into the page.
|
|
113
|
+
* Caller supplies the browser document or the dedicated worker's JSDOM document.
|
|
114
|
+
* Markdown markers deliberately remain visible; native Markdown rendering is not assumed.
|
|
115
|
+
*/
|
|
116
|
+
export declare function makePlainLabel(document: Document): (value: string) => string;
|
|
117
|
+
export declare function preflightMermaidFlow(source: string): ParserDiagnostic[];
|
|
118
|
+
/** Each factory owns a serialized queue because Mermaid maintains parser/configuration state. */
|
|
119
|
+
export declare function createMermaidFlowParser(load: () => Promise<MermaidApi>): (source: string) => Promise<ParseFlowResult>;
|
|
120
|
+
export {};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type ImportResult } from './import-core';
|
|
2
|
+
import { type ParseFlowResult } from './mermaid-facade';
|
|
3
|
+
/** Convert a checked Mermaid snapshot into valid native source. */
|
|
4
|
+
export declare function importMermaidFlow(parsed: ParseFlowResult, plainText: (value: string) => string, title?: string): ImportResult;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mermaid `sequenceDiagram` -> native source. Participants become nodes and messages become edges
|
|
3
|
+
* in file order. Native sequences have no fragments, so each top-level branch of a block becomes
|
|
4
|
+
* a phase band, and the warning says that the branch logic is gone.
|
|
5
|
+
*/
|
|
6
|
+
import { type Diagnostic, type ImportResult } from './import-core';
|
|
7
|
+
import type { SequenceSnapshot } from './mermaid-facade';
|
|
8
|
+
export declare function mapMermaidSequence(snapshot: SequenceSnapshot, plainText: (value: string) => string, title: string, diagnostics: Diagnostic[]): ImportResult;
|