@diagrammo/dgmo 0.20.3 → 0.21.1

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 (48) hide show
  1. package/dist/advanced.cjs +867 -286
  2. package/dist/advanced.js +866 -286
  3. package/dist/auto.cjs +635 -284
  4. package/dist/auto.js +113 -113
  5. package/dist/auto.mjs +635 -284
  6. package/dist/cli.cjs +156 -156
  7. package/dist/editor.cjs +6 -2
  8. package/dist/editor.js +6 -2
  9. package/dist/highlight.cjs +6 -2
  10. package/dist/highlight.js +6 -2
  11. package/dist/index.cjs +628 -281
  12. package/dist/index.js +628 -281
  13. package/dist/internal.cjs +867 -286
  14. package/dist/internal.js +866 -286
  15. package/dist/map-data/PROVENANCE.json +1 -1
  16. package/dist/map-data/mountain-ranges.json +1 -0
  17. package/docs/language-reference.md +27 -25
  18. package/gallery/fixtures/map-choropleth.dgmo +7 -7
  19. package/gallery/fixtures/map-direct-color.dgmo +10 -0
  20. package/gallery/fixtures/map-pois.dgmo +4 -4
  21. package/gallery/fixtures/map-region-scope.dgmo +8 -8
  22. package/gallery/fixtures/map-route.dgmo +5 -6
  23. package/package.json +1 -1
  24. package/src/advanced.ts +14 -0
  25. package/src/completion.ts +10 -4
  26. package/src/d3.ts +15 -9
  27. package/src/editor/keywords.ts +6 -2
  28. package/src/map/data/PROVENANCE.json +1 -1
  29. package/src/map/data/mountain-ranges.json +1 -0
  30. package/src/map/geo-query.ts +277 -0
  31. package/src/map/geo.ts +258 -1
  32. package/src/map/invert.ts +111 -0
  33. package/src/map/layout.ts +333 -139
  34. package/src/map/load-data.ts +7 -1
  35. package/src/map/parser.ts +142 -33
  36. package/src/map/renderer.ts +57 -6
  37. package/src/map/resolved-types.ts +21 -2
  38. package/src/map/resolver.ts +219 -53
  39. package/src/map/types.ts +57 -14
  40. package/src/utils/reserved-key-registry.ts +7 -7
  41. package/dist/advanced.d.cts +0 -5290
  42. package/dist/advanced.d.ts +0 -5290
  43. package/dist/auto.d.cts +0 -39
  44. package/dist/auto.d.ts +0 -39
  45. package/dist/index.d.cts +0 -336
  46. package/dist/index.d.ts +0 -336
  47. package/dist/internal.d.cts +0 -5290
  48. package/dist/internal.d.ts +0 -5290
package/dist/auto.d.cts DELETED
@@ -1,39 +0,0 @@
1
- /**
2
- * `@diagrammo/dgmo/auto` — IIFE-distributed auto-renderer for static HTML.
3
- *
4
- * Drop a `<script src="…/auto.js">` on any page; on `DOMContentLoaded`
5
- * this module scans for `.dgmo, .language-dgmo`, runs `render()`, and
6
- * replaces each match with `<div class="dgmo-rendered">` containing the
7
- * SVG plus an optional collapsible source panel with Copy and
8
- * "Open in editor" actions.
9
- *
10
- * Public API: frozen `window.dgmo` and alias `window.diagrammo` with
11
- * `{ initialize, run, version }`. Configuration is read from the
12
- * bundle's own `<script data-config='{…}'>` (JSON with strict
13
- * allowlist) or via `dgmo.initialize(opts)` for `data-auto="false"`
14
- * embedders.
15
- */
16
-
17
- interface AutoConfig {
18
- theme?: 'auto' | 'light' | 'dark' | 'transparent';
19
- palette?: string;
20
- showSource?: boolean;
21
- showEditorLink?: boolean;
22
- }
23
- interface RunOptions {
24
- nodes?: Element[] | NodeListOf<Element>;
25
- }
26
- declare const VERSION: string;
27
- declare function findScriptTag(): HTMLScriptElement | null;
28
- declare function parseConfig(raw: string | null | undefined): Partial<AutoConfig>;
29
- declare function selectTargets(root?: ParentNode): Element[];
30
- declare function resolveTheme(theme: AutoConfig['theme']): 'light' | 'dark' | 'transparent';
31
- declare function initialize(opts?: AutoConfig): void;
32
- declare function run(opts?: RunOptions): Promise<void>;
33
- declare const api: Readonly<{
34
- initialize: typeof initialize;
35
- run: typeof run;
36
- version: string;
37
- }>;
38
-
39
- export { type AutoConfig, type RunOptions, VERSION, api as default, findScriptTag, initialize, parseConfig, resolveTheme, run, selectTargets };
package/dist/auto.d.ts DELETED
@@ -1,39 +0,0 @@
1
- /**
2
- * `@diagrammo/dgmo/auto` — IIFE-distributed auto-renderer for static HTML.
3
- *
4
- * Drop a `<script src="…/auto.js">` on any page; on `DOMContentLoaded`
5
- * this module scans for `.dgmo, .language-dgmo`, runs `render()`, and
6
- * replaces each match with `<div class="dgmo-rendered">` containing the
7
- * SVG plus an optional collapsible source panel with Copy and
8
- * "Open in editor" actions.
9
- *
10
- * Public API: frozen `window.dgmo` and alias `window.diagrammo` with
11
- * `{ initialize, run, version }`. Configuration is read from the
12
- * bundle's own `<script data-config='{…}'>` (JSON with strict
13
- * allowlist) or via `dgmo.initialize(opts)` for `data-auto="false"`
14
- * embedders.
15
- */
16
-
17
- interface AutoConfig {
18
- theme?: 'auto' | 'light' | 'dark' | 'transparent';
19
- palette?: string;
20
- showSource?: boolean;
21
- showEditorLink?: boolean;
22
- }
23
- interface RunOptions {
24
- nodes?: Element[] | NodeListOf<Element>;
25
- }
26
- declare const VERSION: string;
27
- declare function findScriptTag(): HTMLScriptElement | null;
28
- declare function parseConfig(raw: string | null | undefined): Partial<AutoConfig>;
29
- declare function selectTargets(root?: ParentNode): Element[];
30
- declare function resolveTheme(theme: AutoConfig['theme']): 'light' | 'dark' | 'transparent';
31
- declare function initialize(opts?: AutoConfig): void;
32
- declare function run(opts?: RunOptions): Promise<void>;
33
- declare const api: Readonly<{
34
- initialize: typeof initialize;
35
- run: typeof run;
36
- version: string;
37
- }>;
38
-
39
- export { type AutoConfig, type RunOptions, VERSION, api as default, findScriptTag, initialize, parseConfig, resolveTheme, run, selectTargets };
package/dist/index.d.cts DELETED
@@ -1,336 +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 nord: PaletteConfig;
166
- readonly catppuccin: PaletteConfig;
167
- readonly solarized: PaletteConfig;
168
- readonly gruvbox: PaletteConfig;
169
- readonly tokyoNight: PaletteConfig;
170
- readonly oneDark: PaletteConfig;
171
- readonly rosePine: PaletteConfig;
172
- readonly dracula: PaletteConfig;
173
- readonly monokai: PaletteConfig;
174
- readonly bold: PaletteConfig;
175
- };
176
-
177
- declare function getMinDimensions(content: string): {
178
- width: number;
179
- height: number;
180
- };
181
-
182
- /**
183
- * A gazetteer city entry: `[lat, lon, iso, pop, name, sub?]`.
184
- * - `lat`/`lon` — rounded to 3 decimals.
185
- * - `iso` — ISO 3166-1 alpha-2 country code.
186
- * - `pop` — population.
187
- * - `name` — canonical display name (case/accents preserved).
188
- * - `sub` — ISO 3166-2 subdivision (US cities only in v1, e.g. `US-OR`); absent otherwise.
189
- */
190
- type GazetteerEntry = [
191
- lat: number,
192
- lon: number,
193
- iso: string,
194
- pop: number,
195
- name: string,
196
- sub?: string
197
- ];
198
- interface Gazetteer {
199
- /** Every city, stored once. `byName`/`alt` reference cities by array index
200
- * (normalized — no tuple duplication; geonameid is a build-time-only linker). */
201
- cities: GazetteerEntry[];
202
- /** Folded (NFD, diacritic-stripped, lowercased) name → indices into `cities`.
203
- * Always an array; length > 1 for same-named cities (Portland US-OR / US-ME). */
204
- byName: Record<string, number[]>;
205
- /** Folded alias → index into `cities`. Never collides with a `byName` key. */
206
- alt: Record<string, number>;
207
- }
208
- /** A fill-able region (country or US state) — the display name + its ISO id +
209
- * layer. Powers region-name autocomplete (completion-only; the renderer derives
210
- * names from the topology directly). Extracted from the topologies by
211
- * scripts/build-map-data.mjs into `region-names.json`. */
212
- interface RegionName {
213
- /** Display name (original casing), e.g. `California` / `Germany`. */
214
- readonly name: string;
215
- /** ISO 3166-1 alpha-2 (country) or 3166-2 `US-XX` (state). */
216
- readonly iso: string;
217
- readonly layer: 'country' | 'us-state';
218
- }
219
- interface RegionNames {
220
- /** Deterministically ordered (layer, then name). */
221
- readonly regions: readonly RegionName[];
222
- }
223
-
224
- interface MapPlaceCompletion {
225
- /** Canonical display name (original casing), e.g. `Portland`. */
226
- readonly name: string;
227
- /** Text to insert. ISO-qualified (`Portland US-OR`) iff the name is
228
- * ambiguous in the gazetteer; bare otherwise (disambiguate-once, §24B.8). */
229
- readonly insert: string;
230
- /** Menu label (`Portland — US-OR` when ambiguous, else `Portland`). */
231
- readonly label: string;
232
- /** Secondary detail, e.g. `US-OR · 652,503`. */
233
- readonly detail: string;
234
- readonly iso: string;
235
- readonly sub?: string;
236
- readonly pop: number;
237
- }
238
- interface MapCompletionOptions {
239
- /** Max results (default 12). */
240
- readonly limit?: number;
241
- }
242
- /**
243
- * Prefix-match city names + alternate-name aliases against the gazetteer,
244
- * rank by population (desc; stable tie-break by gazetteer index), and emit
245
- * ISO-qualified insert text only for ambiguous (same-named) places.
246
- *
247
- * Pure + deterministic. Empty/blank query → `[]` (the caller gates min length).
248
- */
249
- declare function completeMapPlaces(query: string, gazetteer: Gazetteer, opts?: MapCompletionOptions): MapPlaceCompletion[];
250
- interface MapRegionCompletion {
251
- /** Display name = insert text (the resolver disambiguates cross-layer
252
- * collisions like Georgia by map scope, §24B.8). */
253
- readonly name: string;
254
- /** ISO 3166-1/3166-2 id. */
255
- readonly iso: string;
256
- readonly layer: 'country' | 'us-state';
257
- /** Secondary detail, e.g. `US state · US-CA` or `Country · DE`. */
258
- readonly detail: string;
259
- }
260
- /**
261
- * Prefix-match fill-able region names (countries + US states) for region-fill
262
- * lines. Matches the folded display name OR the ISO code; deterministic
263
- * (alphabetical by name, then layer). Pure. Empty query → `[]`.
264
- *
265
- * `regions` is injected (the `region-names.json` asset, shipped in dist/map-data
266
- * alongside the gazetteer). Cross-layer same-name (Georgia: country GE + state
267
- * US-GA) yields both entries, distinguished by `detail`.
268
- */
269
- declare function completeMapRegions(query: string, regions: readonly RegionName[], opts?: MapCompletionOptions): MapRegionCompletion[];
270
-
271
- interface RenderOptions {
272
- theme?: Theme;
273
- palette?: PaletteConfig;
274
- /**
275
- * How to handle parse errors:
276
- * 'svg' — render an inline error SVG (default)
277
- * 'silent' — return empty svg + diagnostics; caller handles UI
278
- * 'throw' — throw an Error with the diagnostics
279
- */
280
- onError?: 'svg' | 'silent' | 'throw';
281
- /**
282
- * Pre-applied interactive view state — collapsed sections/columns,
283
- * active swimlane tag-group, etc. Used to render a specific view
284
- * non-interactively (server-side render, share-link decode).
285
- */
286
- viewState?: CompactViewState;
287
- }
288
- interface RenderResult {
289
- svg: string;
290
- diagnostics: DgmoError[];
291
- }
292
- /**
293
- * Render DGMO source to an SVG string.
294
- *
295
- * @example
296
- * ```ts
297
- * import { render, palettes, themes } from '@diagrammo/dgmo';
298
- *
299
- * const { svg } = await render(text, {
300
- * palette: palettes.catppuccin,
301
- * theme: themes.dark,
302
- * });
303
- * document.getElementById('chart').innerHTML = svg;
304
- * ```
305
- */
306
- declare function render(text: string, options?: RenderOptions): Promise<RenderResult>;
307
-
308
- interface EncodeDiagramUrlOptions {
309
- baseUrl?: string;
310
- palette?: PaletteConfig;
311
- theme?: Theme;
312
- filename?: string;
313
- /**
314
- * Initial view state to embed in the URL — re-applied when the link is
315
- * decoded so recipients open the diagram in the same configuration.
316
- */
317
- viewState?: CompactViewState;
318
- }
319
- /**
320
- * Encode DGMO text into a shareable URL. Returns null if the compressed
321
- * payload exceeds the 8 KB URL limit.
322
- */
323
- declare function encodeDiagramUrl(text: string, options?: EncodeDiagramUrlOptions): string | null;
324
- interface DecodedDiagramUrl {
325
- text: string;
326
- palette?: PaletteConfig;
327
- theme?: Theme;
328
- filename?: string;
329
- }
330
- /**
331
- * Decode a share URL back into DGMO text plus optional palette/theme/filename.
332
- * Returns null if the URL contains no valid DGMO payload.
333
- */
334
- declare function decodeDiagramUrl(url: string): DecodedDiagramUrl | null;
335
-
336
- 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, getMinDimensions, getPalette, palettes, render, themes, parseDgmo as validate };