@diagrammo/dgmo 0.22.0 → 0.24.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 (51) hide show
  1. package/dist/advanced.cjs +372 -103
  2. package/dist/advanced.d.cts +52 -19
  3. package/dist/advanced.d.ts +52 -19
  4. package/dist/advanced.js +372 -103
  5. package/dist/auto.cjs +370 -97
  6. package/dist/auto.js +117 -117
  7. package/dist/auto.mjs +370 -97
  8. package/dist/cli.cjs +151 -151
  9. package/dist/editor.cjs +3 -0
  10. package/dist/editor.js +3 -0
  11. package/dist/highlight.cjs +3 -0
  12. package/dist/highlight.js +3 -0
  13. package/dist/index.cjs +498 -96
  14. package/dist/index.d.cts +37 -1
  15. package/dist/index.d.ts +37 -1
  16. package/dist/index.js +496 -96
  17. package/dist/internal.cjs +372 -103
  18. package/dist/internal.d.cts +52 -19
  19. package/dist/internal.d.ts +52 -19
  20. package/dist/internal.js +372 -103
  21. package/dist/map-data/PROVENANCE.json +1 -1
  22. package/dist/map-data/gazetteer.json +1 -1
  23. package/dist/map-data/mountain-ranges.json +1 -1
  24. package/dist/map-data/water-bodies.json +1 -1
  25. package/dist/map-data/world-coarse.json +1 -1
  26. package/dist/map-data/world-detail.json +1 -1
  27. package/docs/language-reference.md +38 -2
  28. package/gallery/fixtures/boxes-and-lines.dgmo +6 -4
  29. package/package.json +1 -1
  30. package/src/boxes-and-lines/parser.ts +39 -0
  31. package/src/boxes-and-lines/renderer.ts +219 -14
  32. package/src/boxes-and-lines/types.ts +9 -0
  33. package/src/completion.ts +4 -5
  34. package/src/d3.ts +26 -6
  35. package/src/editor/keywords.ts +3 -0
  36. package/src/index.ts +8 -0
  37. package/src/map/data/PROVENANCE.json +1 -1
  38. package/src/map/data/README.md +6 -0
  39. package/src/map/data/gazetteer.json +1 -1
  40. package/src/map/data/mountain-ranges.json +1 -1
  41. package/src/map/data/water-bodies.json +1 -1
  42. package/src/map/data/world-coarse.json +1 -1
  43. package/src/map/data/world-detail.json +1 -1
  44. package/src/map/dimensions.ts +21 -5
  45. package/src/map/layout.ts +167 -63
  46. package/src/map/legend-band.ts +99 -0
  47. package/src/map/renderer.ts +105 -32
  48. package/src/map/resolver.ts +43 -1
  49. package/src/map/types.ts +20 -0
  50. package/src/utils/reserved-key-registry.ts +5 -3
  51. package/src/utils/svg-embed.ts +193 -0
package/dist/index.d.cts CHANGED
@@ -182,6 +182,42 @@ declare function getMinDimensions(content: string): {
182
182
  height: number;
183
183
  };
184
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
+
185
221
  /**
186
222
  * A gazetteer city entry: `[lat, lon, iso, pop, name, sub?]`.
187
223
  * - `lat`/`lon` — rounded to 3 decimals.
@@ -336,4 +372,4 @@ interface DecodedDiagramUrl {
336
372
  */
337
373
  declare function decodeDiagramUrl(url: string): DecodedDiagramUrl | null;
338
374
 
339
- 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 };
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 };
package/dist/index.d.ts CHANGED
@@ -182,6 +182,42 @@ declare function getMinDimensions(content: string): {
182
182
  height: number;
183
183
  };
184
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
+
185
221
  /**
186
222
  * A gazetteer city entry: `[lat, lon, iso, pop, name, sub?]`.
187
223
  * - `lat`/`lon` — rounded to 3 decimals.
@@ -336,4 +372,4 @@ interface DecodedDiagramUrl {
336
372
  */
337
373
  declare function decodeDiagramUrl(url: string): DecodedDiagramUrl | null;
338
374
 
339
- 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 };
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 };