@diagrammo/dgmo 0.25.2 → 0.25.4

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 (51) hide show
  1. package/README.md +69 -884
  2. package/package.json +1 -1
  3. package/src/cli.ts +0 -9
  4. package/src/d3.ts +180 -46
  5. package/src/render.ts +80 -39
  6. package/src/utils/svg-embed.ts +12 -3
  7. package/dist/advanced.cjs +0 -62454
  8. package/dist/advanced.d.cts +0 -5684
  9. package/dist/advanced.d.ts +0 -5684
  10. package/dist/advanced.js +0 -62207
  11. package/dist/auto.cjs +0 -59764
  12. package/dist/auto.css +0 -214
  13. package/dist/auto.d.cts +0 -39
  14. package/dist/auto.d.ts +0 -39
  15. package/dist/auto.js +0 -437
  16. package/dist/auto.mjs +0 -59774
  17. package/dist/cli.cjs +0 -465
  18. package/dist/editor.cjs +0 -432
  19. package/dist/editor.d.cts +0 -26
  20. package/dist/editor.d.ts +0 -26
  21. package/dist/editor.js +0 -401
  22. package/dist/highlight.cjs +0 -720
  23. package/dist/highlight.d.cts +0 -32
  24. package/dist/highlight.d.ts +0 -32
  25. package/dist/highlight.js +0 -690
  26. package/dist/index.cjs +0 -58947
  27. package/dist/index.d.cts +0 -375
  28. package/dist/index.d.ts +0 -375
  29. package/dist/index.js +0 -58951
  30. package/dist/internal.cjs +0 -62456
  31. package/dist/internal.d.cts +0 -5684
  32. package/dist/internal.d.ts +0 -5684
  33. package/dist/internal.js +0 -62207
  34. package/dist/map-data/PROVENANCE.json +0 -1
  35. package/dist/map-data/gazetteer.json +0 -1
  36. package/dist/map-data/lakes.json +0 -1
  37. package/dist/map-data/mountain-ranges.json +0 -1
  38. package/dist/map-data/na-lakes.json +0 -1
  39. package/dist/map-data/na-land.json +0 -1
  40. package/dist/map-data/region-names.json +0 -1
  41. package/dist/map-data/rivers.json +0 -1
  42. package/dist/map-data/us-states.json +0 -1
  43. package/dist/map-data/water-bodies.json +0 -1
  44. package/dist/map-data/world-coarse.json +0 -1
  45. package/dist/map-data/world-detail.json +0 -1
  46. package/dist/pert.cjs +0 -325
  47. package/dist/pert.d.cts +0 -554
  48. package/dist/pert.d.ts +0 -554
  49. package/dist/pert.js +0 -294
  50. package/src/editor/dgmo.grammar.js +0 -18
  51. package/src/editor/dgmo.grammar.terms.js +0 -35
package/dist/index.d.cts DELETED
@@ -1,375 +0,0 @@
1
- /**
2
- * Compact view state schema (ADR-6).
3
- * All fields optional. Only non-default values are encoded.
4
- * `tag: null` means "user chose none"; absent `tag` means "use DSL default" (ADR-5).
5
- */
6
- interface CompactViewState {
7
- tag?: string | null;
8
- cs?: number[];
9
- cg?: string[];
10
- swim?: string | null;
11
- cl?: string[];
12
- cc?: string[];
13
- rm?: string;
14
- htv?: Record<string, string[]>;
15
- ha?: string[];
16
- sem?: boolean;
17
- cm?: boolean;
18
- c4l?: string;
19
- c4s?: string;
20
- c4c?: string;
21
- rps?: number;
22
- spd?: number;
23
- io?: Record<string, number>;
24
- hd?: boolean;
25
- cbd?: boolean;
26
- rq?: string;
27
- an?: boolean;
28
- fl?: boolean;
29
- }
30
-
31
- type DgmoSeverity = 'error' | 'warning';
32
- interface DgmoError {
33
- line: number;
34
- column?: number;
35
- message: string;
36
- severity: DgmoSeverity;
37
- /**
38
- * Optional stable diagnostic code (e.g. 'E_ARROW_SUBSTRING_IN_LABEL').
39
- * Additive; pre-existing diagnostics omit this field and existing
40
- * substring-on-`.message` assertions keep working unchanged.
41
- */
42
- code?: string;
43
- }
44
- declare function formatDgmoError(err: DgmoError): string;
45
-
46
- /**
47
- * Parse DGMO content and return diagnostics without rendering.
48
- * Useful for the CLI and editor to surface all errors before attempting render.
49
- */
50
- declare function parseDgmo(content: string): {
51
- diagnostics: DgmoError[];
52
- chartType: string | null;
53
- };
54
-
55
- /**
56
- * Color definitions for a single mode (light or dark).
57
- * 10 semantic UI colors + 9 named accent colors = 19 total.
58
- *
59
- * `readonly` on every field (and the nested `colors` map) by design —
60
- * palettes flow from the registry into every renderer; nothing in the
61
- * pipeline should ever mutate a palette in place.
62
- */
63
- interface PaletteColors {
64
- /** Main background (#eceff4 light / #2e3440 dark for Nord) */
65
- readonly bg: string;
66
- /** Cards, panels (#e5e9f0 / #3b4252) */
67
- readonly surface: string;
68
- /** Popovers, dropdowns (#e5e9f0 / #434c5e) */
69
- readonly overlay: string;
70
- /** Borders, dividers, muted (#d8dee9 / #4c566a) */
71
- readonly border: string;
72
- /** Primary text (#2e3440 / #eceff4) */
73
- readonly text: string;
74
- /** Secondary/diminished text (#4c566a / #d8dee9) */
75
- readonly textMuted: string;
76
- /**
77
- * Light-mode arg for `contrastText()` when text is rendered on a
78
- * tinted shape fill (e.g. `shapeFill()` output). Must guarantee
79
- * ≥ 4.5:1 WCAG AA against any `shapeFill()` the palette can produce.
80
- * Distinct from `colors.white` because palette-aesthetic anchors don't
81
- * always meet contrast requirements (TD-5).
82
- */
83
- readonly textOnFillLight: string;
84
- /** Dark-mode counterpart to `textOnFillLight`. */
85
- readonly textOnFillDark: string;
86
- /** Primary accent — buttons, links */
87
- readonly primary: string;
88
- /** Secondary accent */
89
- readonly secondary: string;
90
- /** Tertiary accent */
91
- readonly accent: string;
92
- /** Error/danger */
93
- readonly destructive: string;
94
- /**
95
- * Used for: inline annotations (red), pie charts, cScale,
96
- * series rotation, journey actors, Gantt tasks.
97
- */
98
- readonly colors: {
99
- readonly red: string;
100
- readonly orange: string;
101
- readonly yellow: string;
102
- readonly green: string;
103
- readonly blue: string;
104
- readonly purple: string;
105
- readonly teal: string;
106
- readonly cyan: string;
107
- readonly gray: string;
108
- readonly black: string;
109
- readonly white: string;
110
- };
111
- }
112
- /**
113
- * Complete palette definition. One object per color scheme.
114
- * This is what palette authors create — the single artifact for NFR1.
115
- *
116
- * Palettes are immutable from the consumer's perspective; the registry
117
- * hands out the same frozen-shape object on every `getPalette(id)`.
118
- */
119
- interface PaletteConfig {
120
- /** Registry key: 'nord', 'solarized', 'catppuccin' */
121
- readonly id: string;
122
- /** Display name: 'Nord', 'Solarized', 'Catppuccin' */
123
- readonly name: string;
124
- /** Light mode color definitions */
125
- readonly light: PaletteColors;
126
- /** Dark mode color definitions */
127
- readonly dark: PaletteColors;
128
- }
129
-
130
- /**
131
- * Theme — render mode flag. Selects which palette variant the renderer uses
132
- * for background and text:
133
- * - 'light' → palette.light colors
134
- * - 'dark' → palette.dark colors
135
- * - 'transparent' → no background fill (for embedding in colored containers)
136
- */
137
- type Theme = 'light' | 'dark' | 'transparent';
138
- /**
139
- * `themes` namespace — use with render() options for a typed handle:
140
- *
141
- * await render(text, { theme: themes.dark });
142
- *
143
- * Passing the raw string `'dark'` also works (the underlying type is the
144
- * string-literal union); the namespace is the conventional path.
145
- */
146
- declare const themes: {
147
- readonly light: "light";
148
- readonly dark: "dark";
149
- readonly transparent: "transparent";
150
- };
151
-
152
- /** Get palette by id. Returns Nord if id is unrecognized (FR10). */
153
- declare function getPalette(id: string): PaletteConfig;
154
-
155
- /**
156
- * All built-in palettes, keyed by camelCase id. Use directly with render():
157
- *
158
- * await render(text, { palette: palettes.catppuccin });
159
- *
160
- * For preference/settings storage, the `.id` field of each entry is the
161
- * canonical string (e.g. `'tokyo-night'`, `'nord'`) — that's the wire format
162
- * used by share URLs and the CLI `--palette` flag.
163
- */
164
- declare const palettes: {
165
- readonly atlas: PaletteConfig;
166
- readonly blueprint: PaletteConfig;
167
- readonly slate: PaletteConfig;
168
- readonly tidewater: PaletteConfig;
169
- readonly nord: PaletteConfig;
170
- readonly catppuccin: PaletteConfig;
171
- readonly solarized: PaletteConfig;
172
- readonly gruvbox: PaletteConfig;
173
- readonly tokyoNight: PaletteConfig;
174
- readonly oneDark: PaletteConfig;
175
- readonly rosePine: PaletteConfig;
176
- readonly dracula: PaletteConfig;
177
- readonly monokai: PaletteConfig;
178
- };
179
-
180
- declare function getMinDimensions(content: string): {
181
- width: number;
182
- height: number;
183
- };
184
-
185
- /**
186
- * Make an SVG produced by `@diagrammo/dgmo`'s static `render()` suitable for
187
- * responsive inline embedding in any host (Obsidian, remark/markdown, web
188
- * pages):
189
- *
190
- * - dgmo renders diagrams inside a fixed export canvas (e.g.
191
- * `viewBox="0 0 1200 800"`), with content often occupying only a fraction
192
- * of it. We compute a tight content bounding box from element coordinates
193
- * and set the root `viewBox` to bbox+padding, so the diagram's intrinsic
194
- * aspect ratio matches its CONTENT — no dead space above/below or beside it.
195
- * - Ensure the root `<svg>` has a `viewBox` so it scales responsively.
196
- * - Strip fixed `width="N"` / `height="N"` so CSS (e.g. `width:100%;
197
- * height:auto`, or an aspect-ratio derived from the tight viewBox) controls
198
- * sizing.
199
- * - Remove any inline `background:` from the root style so the page
200
- * background shows through.
201
- *
202
- * This is intentionally a string transform, not a DOM `getBBox()` step: dgmo
203
- * can dual-render light/dark SVGs where one is hidden by color-mode CSS, and
204
- * `getBBox()` returns 0 for the hidden copy. Parsing coordinates from the
205
- * markup measures both copies reliably and works server-side (Node).
206
- */
207
- declare function normalizeSvgForEmbed(input: string): string;
208
- /**
209
- * Parse the content bounding box of a normalized embed SVG, if one can be
210
- * derived. Returns `null` when no usable coordinates are found (e.g. an empty
211
- * diagram). Useful for hosts that want to set an explicit `aspect-ratio` from
212
- * the tight viewBox.
213
- */
214
- declare function getEmbedSvgViewBox(svg: string): {
215
- x: number;
216
- y: number;
217
- width: number;
218
- height: number;
219
- } | null;
220
-
221
- /**
222
- * A gazetteer city entry: `[lat, lon, iso, pop, name, sub?]`.
223
- * - `lat`/`lon` — rounded to 3 decimals.
224
- * - `iso` — ISO 3166-1 alpha-2 country code.
225
- * - `pop` — population.
226
- * - `name` — canonical display name (case/accents preserved).
227
- * - `sub` — ISO 3166-2 subdivision (US cities only in v1, e.g. `US-OR`); absent otherwise.
228
- */
229
- type GazetteerEntry = [
230
- lat: number,
231
- lon: number,
232
- iso: string,
233
- pop: number,
234
- name: string,
235
- sub?: string
236
- ];
237
- interface Gazetteer {
238
- /** Every city, stored once. `byName`/`alt` reference cities by array index
239
- * (normalized — no tuple duplication; geonameid is a build-time-only linker). */
240
- cities: GazetteerEntry[];
241
- /** Folded (NFD, diacritic-stripped, lowercased) name → indices into `cities`.
242
- * Always an array; length > 1 for same-named cities (Portland US-OR / US-ME). */
243
- byName: Record<string, number[]>;
244
- /** Folded alias → index into `cities`. Never collides with a `byName` key. */
245
- alt: Record<string, number>;
246
- }
247
- /** A fill-able region (country or US state) — the display name + its ISO id +
248
- * layer. Powers region-name autocomplete (completion-only; the renderer derives
249
- * names from the topology directly). Extracted from the topologies by
250
- * scripts/build-map-data.mjs into `region-names.json`. */
251
- interface RegionName {
252
- /** Display name (original casing), e.g. `California` / `Germany`. */
253
- readonly name: string;
254
- /** ISO 3166-1 alpha-2 (country) or 3166-2 `US-XX` (state). */
255
- readonly iso: string;
256
- readonly layer: 'country' | 'us-state';
257
- }
258
- interface RegionNames {
259
- /** Deterministically ordered (layer, then name). */
260
- readonly regions: readonly RegionName[];
261
- }
262
-
263
- interface MapPlaceCompletion {
264
- /** Canonical display name (original casing), e.g. `Portland`. */
265
- readonly name: string;
266
- /** Text to insert. ISO-qualified (`Portland US-OR`) iff the name is
267
- * ambiguous in the gazetteer; bare otherwise (disambiguate-once, §24B.8). */
268
- readonly insert: string;
269
- /** Menu label (`Portland — US-OR` when ambiguous, else `Portland`). */
270
- readonly label: string;
271
- /** Secondary detail, e.g. `US-OR · 652,503`. */
272
- readonly detail: string;
273
- readonly iso: string;
274
- readonly sub?: string;
275
- readonly pop: number;
276
- }
277
- interface MapCompletionOptions {
278
- /** Max results (default 12). */
279
- readonly limit?: number;
280
- }
281
- /**
282
- * Prefix-match city names + alternate-name aliases against the gazetteer,
283
- * rank by population (desc; stable tie-break by gazetteer index), and emit
284
- * ISO-qualified insert text only for ambiguous (same-named) places.
285
- *
286
- * Pure + deterministic. Empty/blank query → `[]` (the caller gates min length).
287
- */
288
- declare function completeMapPlaces(query: string, gazetteer: Gazetteer, opts?: MapCompletionOptions): MapPlaceCompletion[];
289
- interface MapRegionCompletion {
290
- /** Display name = insert text (the resolver disambiguates cross-layer
291
- * collisions like Georgia by map scope, §24B.8). */
292
- readonly name: string;
293
- /** ISO 3166-1/3166-2 id. */
294
- readonly iso: string;
295
- readonly layer: 'country' | 'us-state';
296
- /** Secondary detail, e.g. `US state · US-CA` or `Country · DE`. */
297
- readonly detail: string;
298
- }
299
- /**
300
- * Prefix-match fill-able region names (countries + US states) for region-fill
301
- * lines. Matches the folded display name OR the ISO code; deterministic
302
- * (alphabetical by name, then layer). Pure. Empty query → `[]`.
303
- *
304
- * `regions` is injected (the `region-names.json` asset, shipped in dist/map-data
305
- * alongside the gazetteer). Cross-layer same-name (Georgia: country GE + state
306
- * US-GA) yields both entries, distinguished by `detail`.
307
- */
308
- declare function completeMapRegions(query: string, regions: readonly RegionName[], opts?: MapCompletionOptions): MapRegionCompletion[];
309
-
310
- interface RenderOptions {
311
- theme?: Theme;
312
- palette?: PaletteConfig;
313
- /**
314
- * How to handle parse errors:
315
- * 'svg' — render an inline error SVG (default)
316
- * 'silent' — return empty svg + diagnostics; caller handles UI
317
- * 'throw' — throw an Error with the diagnostics
318
- */
319
- onError?: 'svg' | 'silent' | 'throw';
320
- /**
321
- * Pre-applied interactive view state — collapsed sections/columns,
322
- * active swimlane tag-group, etc. Used to render a specific view
323
- * non-interactively (server-side render, share-link decode).
324
- */
325
- viewState?: CompactViewState;
326
- }
327
- interface RenderResult {
328
- svg: string;
329
- diagnostics: DgmoError[];
330
- }
331
- /**
332
- * Render DGMO source to an SVG string.
333
- *
334
- * @example
335
- * ```ts
336
- * import { render, palettes, themes } from '@diagrammo/dgmo';
337
- *
338
- * const { svg } = await render(text, {
339
- * palette: palettes.catppuccin,
340
- * theme: themes.dark,
341
- * });
342
- * document.getElementById('chart').innerHTML = svg;
343
- * ```
344
- */
345
- declare function render(text: string, options?: RenderOptions): Promise<RenderResult>;
346
-
347
- interface EncodeDiagramUrlOptions {
348
- baseUrl?: string;
349
- palette?: PaletteConfig;
350
- theme?: Theme;
351
- filename?: string;
352
- /**
353
- * Initial view state to embed in the URL — re-applied when the link is
354
- * decoded so recipients open the diagram in the same configuration.
355
- */
356
- viewState?: CompactViewState;
357
- }
358
- /**
359
- * Encode DGMO text into a shareable URL. Returns null if the compressed
360
- * payload exceeds the 8 KB URL limit.
361
- */
362
- declare function encodeDiagramUrl(text: string, options?: EncodeDiagramUrlOptions): string | null;
363
- interface DecodedDiagramUrl {
364
- text: string;
365
- palette?: PaletteConfig;
366
- theme?: Theme;
367
- filename?: string;
368
- }
369
- /**
370
- * Decode a share URL back into DGMO text plus optional palette/theme/filename.
371
- * Returns null if the URL contains no valid DGMO payload.
372
- */
373
- declare function decodeDiagramUrl(url: string): DecodedDiagramUrl | null;
374
-
375
- export { type CompactViewState, type DecodedDiagramUrl, type DgmoError, type DgmoSeverity, type EncodeDiagramUrlOptions, type Gazetteer, type GazetteerEntry, type MapCompletionOptions, type MapPlaceCompletion, type MapRegionCompletion, type PaletteColors, type PaletteConfig, type RegionName, type RegionNames, type RenderOptions, type RenderResult, type Theme, completeMapPlaces, completeMapRegions, decodeDiagramUrl, encodeDiagramUrl, formatDgmoError, getEmbedSvgViewBox, getMinDimensions, getPalette, normalizeSvgForEmbed, palettes, render, themes, parseDgmo as validate };