@draftably/editor 0.0.0-stage → 0.1.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 (185) hide show
  1. package/README.md +26 -2
  2. package/dist/LICENSE +21 -0
  3. package/dist/assets/engine.worker-DmHew5f6.js +6813 -0
  4. package/dist/assets/import-d2.worker-CnXfFXoa.js +5395 -0
  5. package/dist/chunks/abnfDiagram-WEYOIA3C-llcpthp5.js +87 -0
  6. package/dist/chunks/arc-rJj0TtXf.js +83 -0
  7. package/dist/chunks/architectureDiagram-ZHVYKT53-CfiXg0Lk.js +4781 -0
  8. package/dist/chunks/blockDiagram-RJAE7QA3-CO-14jWz.js +1440 -0
  9. package/dist/chunks/browser-iNhbPsGc.js +40 -0
  10. package/dist/chunks/c4Diagram-XDPPPE54-DYKuxA4n.js +1524 -0
  11. package/dist/chunks/channel-qMvPU6eH.js +5 -0
  12. package/dist/chunks/chunk-2E7WHVMD-BEZwsFS3.js +670 -0
  13. package/dist/chunks/chunk-2Q5K7J3B-gqtzQ8ux.js +18 -0
  14. package/dist/chunks/chunk-4EMNKR2T-MC54CXVe.js +262 -0
  15. package/dist/chunks/chunk-55XCU76K-DkZUAaqC.js +68 -0
  16. package/dist/chunks/chunk-5VM5RSS4-CaKe4sjM.js +19 -0
  17. package/dist/chunks/chunk-JWPE2WC7-CnAFS2xF.js +8 -0
  18. package/dist/chunks/chunk-VQ5W62QI-CXRv7FiX.js +19 -0
  19. package/dist/chunks/chunk-XXDRQBXY-B-AMQgD2.js +8 -0
  20. package/dist/chunks/chunk-ZCHMQSOR-BALpdc3g.js +451 -0
  21. package/dist/chunks/classDiagram-v2-4MYWR3UA-wPjgJTg4.js +1570 -0
  22. package/dist/chunks/cose-bilkent-JH36ORCC-Bbh5ggBc.js +2608 -0
  23. package/dist/chunks/cynefin-EF2NZ3EQ-Bt6b88hY.js +22361 -0
  24. package/dist/chunks/cynefinDiagram-WF24UDRP-BHWZvxoF.js +299 -0
  25. package/dist/chunks/cytoscape.esm-CRsF_JA3.js +18791 -0
  26. package/dist/chunks/dagre-NK4GIZVX-Cz37yPrT.js +2157 -0
  27. package/dist/chunks/defaultLocale-BgPVtth8.js +171 -0
  28. package/dist/chunks/diagram-CBK3MWTC-Q2R6FJ0B.js +531 -0
  29. package/dist/chunks/diagram-I5XIIV2D-a2Kdu_wA.js +153 -0
  30. package/dist/chunks/diagram-ODIL2UCW-DTWXxcOn.js +346 -0
  31. package/dist/chunks/diagram-PFBEJUXE-DIAQQ5KX.js +480 -0
  32. package/dist/chunks/diagram-RJA3I4VV-BPD0GghS.js +219 -0
  33. package/dist/chunks/diagram-TYUNFSNR-BmdkONfG.js +2586 -0
  34. package/dist/chunks/dot-importer-B23jwEkx.js +1547 -0
  35. package/dist/chunks/ebnfDiagram-V4P3TTPT-C5IKvYlb.js +109 -0
  36. package/dist/chunks/elk-QONTBCTQ-CtdQFvh2.js +49229 -0
  37. package/dist/chunks/erDiagram-KYQIGQAA-5wguK9Dx.js +1064 -0
  38. package/dist/chunks/flowDiagram-IUGLLWBU-BijvFPku.js +1771 -0
  39. package/dist/chunks/ganttDiagram-R7GPNTJY-BaqGPz-O.js +2729 -0
  40. package/dist/chunks/gitGraphDiagram-PDYL7XHY-DZfMGyHE.js +815 -0
  41. package/dist/chunks/graph-CKJmgLki.js +1541 -0
  42. package/dist/chunks/import-core-C-I1wGfw.js +145 -0
  43. package/dist/chunks/infoDiagram-MVDRKAX5-C2vH_59e.js +24 -0
  44. package/dist/chunks/init-DjUOC4st.js +16 -0
  45. package/dist/chunks/ishikawaDiagram-HPEHV2GE-q149MFlV.js +624 -0
  46. package/dist/chunks/journeyDiagram-BOSHW7O7-D-2Z3VtR.js +834 -0
  47. package/dist/chunks/kanban-definition-FNSA4HC5-wvAjV5ub.js +724 -0
  48. package/dist/chunks/katex-BsrBVQKd.js +11314 -0
  49. package/dist/chunks/linear-4t7D_ros.js +259 -0
  50. package/dist/chunks/mermaid-facade-BoLWBerE.js +289 -0
  51. package/dist/chunks/mermaid-importer-Cgx1IhmR.js +478 -0
  52. package/dist/chunks/mermaid.core-DXv6D2Sm.js +19244 -0
  53. package/dist/chunks/mindmap-definition-6OY57UG3-r9wTKul_.js +837 -0
  54. package/dist/chunks/mount-C1Xk_GQz.js +22131 -0
  55. package/dist/chunks/ordinal-DfAQgscy.js +61 -0
  56. package/dist/chunks/pegDiagram-ECIUJNBX-CmKlFWiP.js +95 -0
  57. package/dist/chunks/pieDiagram-GNMPY74T-DNTw_qan.js +208 -0
  58. package/dist/chunks/quadrantDiagram-D57K4MC3-CT_tvVub.js +1029 -0
  59. package/dist/chunks/railroadDiagram-Y72NRBL7-C5TUvZBe.js +77 -0
  60. package/dist/chunks/requirementDiagram-EQYSW5RA-C_c65aCa.js +889 -0
  61. package/dist/chunks/sankeyDiagram-SY24JHO5-CKcbizM1.js +859 -0
  62. package/dist/chunks/sequenceDiagram-BLEHNHQU-GpVnHOjf.js +2972 -0
  63. package/dist/chunks/sizeCapture-INFHLROL-CToN3JSu.js +46 -0
  64. package/dist/chunks/stateDiagram-v2-A6IESKWZ-rJYd2FfM.js +1520 -0
  65. package/dist/chunks/swimlanes-B3ENRKFQ-C7w5pfxG.js +4991 -0
  66. package/dist/chunks/swimlanesDiagram-AYQRV4AK-BpGY_bvE.js +13 -0
  67. package/dist/chunks/timeline-definition-JXYKGLGB-ChKFPBKc.js +1058 -0
  68. package/dist/chunks/usecaseDiagram-WPOLBNNX-skXH8Dcu.js +7945 -0
  69. package/dist/chunks/vennDiagram-Q3Y3IDCW-C5KknmJf.js +1578 -0
  70. package/dist/chunks/wardleyDiagram-IVAIDKWA-DY4Lkfpu.js +678 -0
  71. package/dist/chunks/xychartDiagram-4URNHDU4-BHScsL7h.js +1536 -0
  72. package/dist/element.js +36 -0
  73. package/dist/index.js +4 -0
  74. package/dist/types/src/cli/links.d.ts +4 -0
  75. package/dist/types/src/cli/pdf.d.ts +29 -0
  76. package/dist/types/src/cli/png.d.ts +23 -0
  77. package/dist/types/src/cli/svg.d.ts +4 -0
  78. package/dist/types/src/components/Icon.d.ts +14 -0
  79. package/dist/types/src/components/LayoutPreviewBar.d.ts +2 -0
  80. package/dist/types/src/components/canvas/Canvas.d.ts +15 -0
  81. package/dist/types/src/components/canvas/Frame.d.ts +22 -0
  82. package/dist/types/src/components/canvas/InlineEditor.d.ts +2 -0
  83. package/dist/types/src/components/canvas/Notes.d.ts +5 -0
  84. package/dist/types/src/components/canvas/Overlay.d.ts +2 -0
  85. package/dist/types/src/components/canvas/StateBar.d.ts +5 -0
  86. package/dist/types/src/components/canvas/TextHits.d.ts +6 -0
  87. package/dist/types/src/components/canvas/ZoomControls.d.ts +1 -0
  88. package/dist/types/src/components/canvas/text-boxes.d.ts +24 -0
  89. package/dist/types/src/components/controls.d.ts +88 -0
  90. package/dist/types/src/components/scene/EdgeView.d.ts +22 -0
  91. package/dist/types/src/components/scene/GroupView.d.ts +22 -0
  92. package/dist/types/src/components/scene/Lifelines.d.ts +15 -0
  93. package/dist/types/src/components/scene/LinkMark.d.ts +11 -0
  94. package/dist/types/src/components/scene/NodeView.d.ts +18 -0
  95. package/dist/types/src/components/scene/parts.d.ts +50 -0
  96. package/dist/types/src/components/sculpt/BrushDock.d.ts +2 -0
  97. package/dist/types/src/components/sculpt/TimelineDeck.d.ts +2 -0
  98. package/dist/types/src/components/session-context.d.ts +486 -0
  99. package/dist/types/src/dsl/cells.d.ts +91 -0
  100. package/dist/types/src/dsl/channels.d.ts +53 -0
  101. package/dist/types/src/dsl/compile.d.ts +162 -0
  102. package/dist/types/src/dsl/frame.d.ts +38 -0
  103. package/dist/types/src/dsl/lanes.d.ts +23 -0
  104. package/dist/types/src/dsl/layout-edits.d.ts +58 -0
  105. package/dist/types/src/dsl/legend-notes.d.ts +3 -0
  106. package/dist/types/src/dsl/project.d.ts +39 -0
  107. package/dist/types/src/dsl/source-edits.d.ts +37 -0
  108. package/dist/types/src/dsl/syntax.d.ts +317 -0
  109. package/dist/types/src/dsl/translate.d.ts +69 -0
  110. package/dist/types/src/editor/Editor.d.ts +6 -0
  111. package/dist/types/src/editor/element.d.ts +15 -0
  112. package/dist/types/src/editor/mount.d.ts +23 -0
  113. package/dist/types/src/import/browser.d.ts +3 -0
  114. package/dist/types/src/import/detect.d.ts +31 -0
  115. package/dist/types/src/import/dot-importer.d.ts +3 -0
  116. package/dist/types/src/import/import-core.d.ts +105 -0
  117. package/dist/types/src/import/mermaid-facade.d.ts +120 -0
  118. package/dist/types/src/import/mermaid-importer.d.ts +4 -0
  119. package/dist/types/src/import/mermaid-sequence.d.ts +8 -0
  120. package/dist/types/src/import/scratch.d.ts +3 -0
  121. package/dist/types/src/lib/engine-tasks.d.ts +88 -0
  122. package/dist/types/src/lib/font-data.d.ts +9 -0
  123. package/dist/types/src/lib/saved-diagram.d.ts +4 -0
  124. package/dist/types/src/lib/scene-cache.d.ts +4 -0
  125. package/dist/types/src/lib/source-hash.d.ts +7 -0
  126. package/dist/types/src/lib/svg-export.d.ts +15 -0
  127. package/dist/types/src/model/appearance.d.ts +209 -0
  128. package/dist/types/src/model/bounds.d.ts +19 -0
  129. package/dist/types/src/model/camera.d.ts +21 -0
  130. package/dist/types/src/model/candidates.d.ts +53 -0
  131. package/dist/types/src/model/colors.d.ts +22 -0
  132. package/dist/types/src/model/document.d.ts +24 -0
  133. package/dist/types/src/model/edits.d.ts +133 -0
  134. package/dist/types/src/model/embed.d.ts +17 -0
  135. package/dist/types/src/model/examples.d.ts +15 -0
  136. package/dist/types/src/model/font-faces.d.ts +24 -0
  137. package/dist/types/src/model/fonts.d.ts +47 -0
  138. package/dist/types/src/model/footnote.d.ts +34 -0
  139. package/dist/types/src/model/frame.d.ts +71 -0
  140. package/dist/types/src/model/geometry.d.ts +29 -0
  141. package/dist/types/src/model/graph.d.ts +53 -0
  142. package/dist/types/src/model/heading.d.ts +38 -0
  143. package/dist/types/src/model/icons.d.ts +2 -0
  144. package/dist/types/src/model/label-hits.d.ts +27 -0
  145. package/dist/types/src/model/labels.d.ts +88 -0
  146. package/dist/types/src/model/legend.d.ts +25 -0
  147. package/dist/types/src/model/link.d.ts +63 -0
  148. package/dist/types/src/model/markers.d.ts +47 -0
  149. package/dist/types/src/model/note.d.ts +75 -0
  150. package/dist/types/src/model/panels.d.ts +11 -0
  151. package/dist/types/src/model/rich-text.d.ts +24 -0
  152. package/dist/types/src/model/routes.d.ts +170 -0
  153. package/dist/types/src/model/samples.d.ts +11 -0
  154. package/dist/types/src/model/stack.d.ts +8 -0
  155. package/dist/types/src/model/static-scene.d.ts +15 -0
  156. package/dist/types/src/model/status.d.ts +84 -0
  157. package/dist/types/src/model/styles.d.ts +13 -0
  158. package/dist/types/src/model/surface.d.ts +31 -0
  159. package/dist/types/src/model/types.d.ts +277 -0
  160. package/dist/types/src/runtime/svg-renderer.d.ts +38 -0
  161. package/dist/types/src/server/file-session.d.ts +19 -0
  162. package/dist/types/src/server/workspace.d.ts +21 -0
  163. package/dist/types/src/state/active-session.d.ts +479 -0
  164. package/dist/types/src/state/commands.d.ts +529 -0
  165. package/dist/types/src/state/comparison.d.ts +151 -0
  166. package/dist/types/src/state/files.d.ts +61 -0
  167. package/dist/types/src/state/keyboard.d.ts +6 -0
  168. package/dist/types/src/state/keys.d.ts +5 -0
  169. package/dist/types/src/state/launch.d.ts +61 -0
  170. package/dist/types/src/state/links.d.ts +11 -0
  171. package/dist/types/src/state/session/actions.d.ts +77 -0
  172. package/dist/types/src/state/session/canvas-text.d.ts +24 -0
  173. package/dist/types/src/state/session/document.d.ts +84 -0
  174. package/dist/types/src/state/session/editor.d.ts +81 -0
  175. package/dist/types/src/state/session/emphasis.d.ts +11 -0
  176. package/dist/types/src/state/session/file-session.d.ts +98 -0
  177. package/dist/types/src/state/session/index.d.ts +496 -0
  178. package/dist/types/src/state/session/layout.d.ts +79 -0
  179. package/dist/types/src/state/session/pointer.d.ts +19 -0
  180. package/dist/types/src/state/session/routing.d.ts +20 -0
  181. package/dist/types/src/state/session/scene.d.ts +144 -0
  182. package/dist/types/src/state/session/sculpt.d.ts +70 -0
  183. package/dist/types/src/state/toast.d.ts +14 -0
  184. package/dist/types/src/state/ui.d.ts +39 -0
  185. package/package.json +41 -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: ("text" | "diamond" | "circle" | "box" | "pill")[];
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,69 @@
1
+ /**
2
+ * Translate one committed editor edit into source statements.
3
+ *
4
+ * The editor works on a projected `Diagram`. When an edit is committed, the document before and
5
+ * after it are compared and the supported differences become targeted source changes: model edits
6
+ * become declarations, and moves become relative preferences. Geometry the translator does not
7
+ * write snaps back when the source is reprojected, so nothing unsaved looks saved. Changes the
8
+ * file cannot express are rejected outright.
9
+ */
10
+ import type { DiagramAppearance } from '../model/appearance';
11
+ import type { Diagram } from '../model/types';
12
+ import { type Scene } from './compile';
13
+ import { type SourceDoc } from './syntax';
14
+ export declare class UnsupportedEdit extends Error {
15
+ }
16
+ export interface EditInput {
17
+ source: SourceDoc;
18
+ scene: Scene;
19
+ before: Diagram;
20
+ after: Diagram;
21
+ label: string;
22
+ /** Selected ids when the edit was committed; moves and resizes apply to these. */
23
+ selection: string[];
24
+ }
25
+ export interface EditResult {
26
+ source: SourceDoc;
27
+ /** Editor ids of new objects and connections, mapped to their ids in the source. */
28
+ ids: Map<string, string>;
29
+ /** Short descriptions of saved refinements, for the status message. */
30
+ notes: string[];
31
+ /** Objects a move placed `near` a neighbour, with where they were dropped. */
32
+ drops: Drop[];
33
+ }
34
+ /** A dropped object: where it was let go in the drawing, and that point in its parent. */
35
+ export interface Drop {
36
+ id: string;
37
+ x: number;
38
+ y: number;
39
+ local: {
40
+ x: number;
41
+ y: number;
42
+ };
43
+ }
44
+ /** Replace the `near` of each dropped object with a `stay` at the exact point it was dropped. */
45
+ export declare function keepDropped(source: SourceDoc, drops: Drop[]): void;
46
+ export declare function translateEdit(input: EditInput): EditResult;
47
+ /**
48
+ * Write a diagram appearance as the file's `theme` line and `theme-color` statements. Statements
49
+ * for colors that are no longer defined are removed; the rest are updated in place, so comments
50
+ * next to them stay.
51
+ */
52
+ export declare function writeAppearance(source: SourceDoc, appearance: DiagramAppearance): void;
53
+ /**
54
+ * Write soft `stay` anchors at their current positions for objects around an accepted refinement:
55
+ * every top-level object, and the siblings of each edited object and of its containers. Later
56
+ * additions then move nearby objects instead of rearranging distant ones. Objects that already
57
+ * have a position refinement keep it. Returns the anchored ids.
58
+ */
59
+ export declare function anchorSurroundings(source: SourceDoc, drawn: Scene, edited: string[]): string[];
60
+ /**
61
+ * Let the automatic recipe rearrange a group again: remove soft refinements for everything inside
62
+ * it (pins and sizes stay), and anchor what is around it so the rest of the drawing holds.
63
+ */
64
+ export declare function reflowGroup(source: SourceDoc, scene: Scene, groupId: string): number;
65
+ /**
66
+ * Objects that moved between two compiled versions although no changed statement mentions them
67
+ * (or a container of theirs). Only the outermost moved object of a subtree is listed.
68
+ */
69
+ export declare function movedOutsideEdit(previous: Scene, next: Scene, previousSource: SourceDoc, nextSource: SourceDoc): string[];
@@ -0,0 +1,6 @@
1
+ import { type CanvasProps } from '../components/canvas/Canvas';
2
+ import type { DiagramSession } from '../state/session';
3
+ /** One live diagram: the canvas for `session`. A page can show any number of them. */
4
+ export declare function Editor(props: CanvasProps & {
5
+ session: DiagramSession;
6
+ }): import("solid-js").JSX.Element;
@@ -0,0 +1,15 @@
1
+ /**
2
+ * `<draft-editor>`: the editor as a custom element, for any framework or plain HTML. Its `source`
3
+ * attribute or property sets the text; every kept edit fires `draft-change` with the new text.
4
+ * It mounts when added to the page and stops its session when removed.
5
+ */
6
+ import { type MountedEditor } from './mount';
7
+ export interface DraftEditorElement extends HTMLElement {
8
+ source: string;
9
+ readonly editor?: MountedEditor;
10
+ }
11
+ declare global {
12
+ interface HTMLElementTagNameMap {
13
+ 'draft-editor': DraftEditorElement;
14
+ }
15
+ }
@@ -0,0 +1,23 @@
1
+ import { type DiagramSession, type SessionOptions } from '../state/session';
2
+ import '../styles/app.css';
3
+ export interface MountOptions extends SessionOptions {
4
+ /** The `.draft` text to edit. */
5
+ source: string;
6
+ /** Receives the new text after every kept edit, undo and redo. */
7
+ onChange?: (source: string) => void;
8
+ }
9
+ export interface MountedEditor {
10
+ session: DiagramSession;
11
+ /** The text as the editor holds it now. */
12
+ source(): string;
13
+ /** Show text the host changed. Resolves once it is drawn. */
14
+ update(source: string): Promise<void>;
15
+ /** Remove the editor and stop its session. */
16
+ destroy(): void;
17
+ }
18
+ /**
19
+ * Edit one diagram inside `host`: the canvas with selection, dragging, inline editing and its
20
+ * shortcuts. Each edit is written back to the source and reported through `onChange`. Give the
21
+ * host a size; the canvas fills it.
22
+ */
23
+ export declare function mountEditor(host: HTMLElement, options: MountOptions): MountedEditor;
@@ -0,0 +1,3 @@
1
+ import type { ImportResult } from './import-core';
2
+ /** Convert a supported text diagram without changing the current document. */
3
+ export declare function importBrowser(source: string, filename?: string): Promise<ImportResult>;
@@ -0,0 +1,31 @@
1
+ /** A bounded dispatcher, not a parser. Ambiguous plain text never becomes D2 by guess. */
2
+ export type KnownFormat = 'native' | 'mermaid' | 'dot' | 'd2' | 'plantuml' | 'dbml' | 'nomnoml';
3
+ export interface DetectedSource {
4
+ status: 'detected';
5
+ format: KnownFormat;
6
+ source: string;
7
+ via: 'explicit' | 'extension' | 'fence' | 'signature';
8
+ /** One-based source line where the extracted content begins. */
9
+ startLine: number;
10
+ }
11
+ export interface FencedSource {
12
+ format: KnownFormat;
13
+ source: string;
14
+ startLine: number;
15
+ }
16
+ export type Detection = DetectedSource | {
17
+ status: 'choose-fence';
18
+ blocks: FencedSource[];
19
+ } | {
20
+ status: 'unknown';
21
+ reason: string;
22
+ };
23
+ /** Focused conventional fences: <=3 leading spaces, backticks or tildes, closed.
24
+ * A Markdown document is never sent wholesale to a diagram parser.
25
+ * This intentionally does not implement every CommonMark container rule.
26
+ */
27
+ export declare function fencedSources(text: string): FencedSource[];
28
+ export declare function detectSource(source: string, options?: {
29
+ filename?: string;
30
+ format?: KnownFormat;
31
+ }): Detection;
@@ -0,0 +1,3 @@
1
+ import { type ImportResult } from './import-core';
2
+ /** Convert DOT and verify the generated source before exposing it to callers. */
3
+ export declare function importDot(source: string, title?: string): ImportResult;
@@ -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;