@diagrammo/dgmo 0.21.1 → 0.22.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 (73) hide show
  1. package/README.md +16 -6
  2. package/dist/advanced.cjs +2003 -466
  3. package/dist/advanced.d.cts +5714 -0
  4. package/dist/advanced.d.ts +5714 -0
  5. package/dist/advanced.js +1999 -466
  6. package/dist/auto.cjs +2048 -449
  7. package/dist/auto.d.cts +39 -0
  8. package/dist/auto.d.ts +39 -0
  9. package/dist/auto.js +121 -121
  10. package/dist/auto.mjs +2050 -450
  11. package/dist/cli.cjs +170 -170
  12. package/dist/editor.cjs +13 -16
  13. package/dist/editor.js +13 -16
  14. package/dist/highlight.cjs +15 -13
  15. package/dist/highlight.js +15 -13
  16. package/dist/index.cjs +2032 -435
  17. package/dist/index.d.cts +339 -0
  18. package/dist/index.d.ts +339 -0
  19. package/dist/index.js +2034 -436
  20. package/dist/internal.cjs +2003 -466
  21. package/dist/internal.d.cts +5714 -0
  22. package/dist/internal.d.ts +5714 -0
  23. package/dist/internal.js +1999 -466
  24. package/dist/map-data/water-bodies.json +1 -0
  25. package/docs/language-reference.md +20 -9
  26. package/gallery/fixtures/map-categorical-world.dgmo +16 -0
  27. package/gallery/fixtures/map-categorical.dgmo +0 -1
  28. package/gallery/fixtures/map-choropleth.dgmo +0 -1
  29. package/gallery/fixtures/map-coastline.dgmo +7 -0
  30. package/gallery/fixtures/map-colorize.dgmo +11 -0
  31. package/gallery/fixtures/map-direct-color.dgmo +0 -1
  32. package/gallery/fixtures/map-reference-world.dgmo +11 -0
  33. package/gallery/fixtures/map-region-scope.dgmo +0 -3
  34. package/gallery/fixtures/map-route.dgmo +0 -1
  35. package/package.json +1 -1
  36. package/src/advanced.ts +12 -1
  37. package/src/boxes-and-lines/renderer.ts +39 -12
  38. package/src/cli.ts +1 -1
  39. package/src/completion.ts +32 -25
  40. package/src/cycle/renderer.ts +14 -1
  41. package/src/d3.ts +8 -2
  42. package/src/editor/highlight-api.ts +4 -0
  43. package/src/editor/keywords.ts +13 -16
  44. package/src/infra/renderer.ts +35 -7
  45. package/src/map/colorize.ts +54 -0
  46. package/src/map/context-labels.ts +429 -0
  47. package/src/map/data/types.ts +34 -0
  48. package/src/map/data/water-bodies.json +1 -0
  49. package/src/map/dimensions.ts +117 -0
  50. package/src/map/geo-query.ts +21 -3
  51. package/src/map/geo.ts +47 -1
  52. package/src/map/layout.ts +1300 -251
  53. package/src/map/load-data.ts +10 -2
  54. package/src/map/parser.ts +42 -116
  55. package/src/map/renderer.ts +512 -13
  56. package/src/map/resolved-types.ts +16 -2
  57. package/src/map/resolver.ts +208 -59
  58. package/src/map/types.ts +30 -32
  59. package/src/mindmap/renderer.ts +10 -1
  60. package/src/palettes/atlas.ts +77 -0
  61. package/src/palettes/blueprint.ts +73 -0
  62. package/src/palettes/color-utils.ts +58 -1
  63. package/src/palettes/index.ts +12 -3
  64. package/src/palettes/slate.ts +73 -0
  65. package/src/palettes/tidewater.ts +73 -0
  66. package/src/render.ts +8 -1
  67. package/src/tech-radar/renderer.ts +3 -0
  68. package/src/tech-radar/types.ts +3 -0
  69. package/src/utils/d3-types.ts +5 -0
  70. package/src/utils/legend-layout.ts +21 -4
  71. package/src/utils/legend-types.ts +7 -0
  72. package/src/utils/reserved-key-registry.ts +3 -0
  73. package/src/palettes/bold.ts +0 -67
@@ -21,14 +21,19 @@ import type { DecodedFeature } from './geo';
21
21
  import { pixelToLonLat, lonLatToPixel } from './invert';
22
22
  import type { MapData, GeoExtent } from './resolved-types';
23
23
  import type { Gazetteer } from './data/types';
24
+ import type { DgmoError } from '../diagnostics';
24
25
 
25
26
  /** Nearest gazetteer city to a point: the real haversine distance, plus the
26
- * canonical name + ISO + (US-only) subdivision for token shaping. */
27
+ * canonical name + ISO + (US-only) subdivision for token shaping. `lon`/`lat`
28
+ * are the city's own gazetteer coordinates (so callers can mark it on the map,
29
+ * distinct from the inspected point). */
27
30
  export interface NearestCity {
28
31
  readonly name: string;
29
32
  readonly iso: string;
30
33
  readonly sub?: string;
31
34
  readonly distanceKm: number;
35
+ readonly lon: number;
36
+ readonly lat: number;
32
37
  }
33
38
 
34
39
  /** A region declaration with its canonical/primary form plus bare alternates
@@ -85,6 +90,10 @@ export interface MapGeoQuery {
85
90
  locate(px: number, py: number): ResultCard | null;
86
91
  /** Culled + projected cities for the all-cities layer (population-primary). */
87
92
  cities(extent?: GeoExtent): ProjectedCity[];
93
+ /** Layout-time, dimension-dependent diagnostics. They live on the geo-query
94
+ * (bound to the rendered layout) rather than the resolver. Callers merge them
95
+ * with `resolved.diagnostics`. (No producers currently — always empty.) */
96
+ readonly diagnostics: readonly DgmoError[];
88
97
  }
89
98
 
90
99
  export interface CreateMapGeoQueryOptions {
@@ -144,6 +153,8 @@ function nearestCity(
144
153
  iso: c[2],
145
154
  ...(c[5] !== undefined && { sub: c[5] }),
146
155
  distanceKm: best.dist,
156
+ lat: c[0],
157
+ lon: c[1],
147
158
  };
148
159
  }
149
160
 
@@ -206,7 +217,14 @@ const MAX_CITY_DOTS = 250;
206
217
 
207
218
  /** Construct a geo-query handle bound to the layout for `(content, width,
208
219
  * height, data, palette, isDark)`. Deterministic: identical inputs ⇒ the same
209
- * fitted projection the rendered SVG used, so inverted clicks align. */
220
+ * fitted projection the rendered SVG used, so inverted clicks align.
221
+ *
222
+ * INVARIANT: this is the PREVIEW path — it never passes `preferContain`, so its
223
+ * layout matches the in-app preview (stretch-fill), where geo-query is used. It is
224
+ * NOT valid against a content-aware EXPORT canvas (which may set `preferContain` →
225
+ * contain-fit): the inverted positions would not match that export's pixels. If
226
+ * geo-query is ever pointed at an export canvas, thread `preferContain` through
227
+ * `CreateMapGeoQueryOptions` to keep the projection in sync. */
210
228
  export function createMapGeoQuery(opts: CreateMapGeoQueryOptions): MapGeoQuery {
211
229
  const { content, width, height, data, palette, isDark } = opts;
212
230
  const resolved = resolveMap(parseMap(content), data);
@@ -273,5 +291,5 @@ export function createMapGeoQuery(opts: CreateMapGeoQueryOptions): MapGeoQuery {
273
291
  return out;
274
292
  };
275
293
 
276
- return { invert, project, locate, cities };
294
+ return { invert, project, locate, cities, diagnostics: layout.diagnostics };
277
295
  }
package/src/map/geo.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  // Geometry helpers for the resolver: topology indexing + antimeridian-correct
2
2
  // feature bounds (via d3-geo geoBounds — NOT naive min/max, which breaks on the
3
3
  // antimeridian and on multi-part features like US Alaska/Hawaii; R5/R6).
4
- import { feature } from 'topojson-client';
4
+ import { feature, neighbors } from 'topojson-client';
5
5
  import { geoBounds, geoArea } from 'd3-geo';
6
6
  import type { BoundaryTopology } from './data/types';
7
7
  import type { GeoExtent } from './resolved-types';
@@ -47,6 +47,52 @@ export function idSet(topo: BoundaryTopology): Set<string> {
47
47
  return new Set(geomObject(topo).geometries.map((g) => g.id));
48
48
  }
49
49
 
50
+ // Memoize adjacency on the RAW asset object (never the per-render-mutated
51
+ // `worldLayer`). Keyed by topology identity — the assets are stable singletons
52
+ // from load-data.ts, so one build per topology lasts the process (G13).
53
+ const adjacencyCache = new WeakMap<BoundaryTopology, Map<string, string[]>>();
54
+
55
+ /** Per-topology arc-adjacency: ISO → neighbour ISOs, from shared TopoJSON arcs
56
+ * (`topojson-client.neighbors()` on the RAW topology geometries — arcs live on
57
+ * the topology, independent of any `feature()` decode — F2/ADR-4). Computed
58
+ * per-topology (a country never neighbours a state) and memoized.
59
+ *
60
+ * DATA HYGIENE (G1): the raw geometry array can carry (a) `type: null`
61
+ * sovereignty stubs with no arcs (e.g. "Ashmore & Cartier Is." tagged `AU`) and
62
+ * (b) genuine duplicate ISO ids. Null stubs are skipped (no arcs → no
63
+ * adjacency), and every geometry sharing one ISO is UNIONED into a single ISO
64
+ * node — matching the merged layer `decodeLayer` actually draws. Without this
65
+ * the ISO-keyed graph corrupts and the AC9 no-collision guarantee degrades. */
66
+ export function buildAdjacency(topo: BoundaryTopology): Map<string, string[]> {
67
+ const cached = adjacencyCache.get(topo);
68
+ if (cached) return cached;
69
+ const geometries = geomObject(topo).geometries as Array<{
70
+ id: string;
71
+ type?: string;
72
+ }>;
73
+ // neighbors() returns, per geometry BY ARRAY POSITION, the indices of
74
+ // arc-sharing geometries. Null-geometry stubs share no arcs → empty lists.
75
+ const nb = neighbors(geometries as never);
76
+ const sets = new Map<string, Set<string>>();
77
+ geometries.forEach((g, i) => {
78
+ if (!g.type || g.type === 'null') return; // skip arc-less sovereignty stubs
79
+ let set = sets.get(g.id);
80
+ if (!set) {
81
+ set = new Set<string>();
82
+ sets.set(g.id, set);
83
+ }
84
+ for (const j of nb[i] ?? []) {
85
+ const nid = geometries[j]?.id;
86
+ if (nid && nid !== g.id) set.add(nid); // union; never self
87
+ }
88
+ });
89
+ const out = new Map<string, string[]>();
90
+ // Deterministic neighbour order (sorted) so downstream coloring is stable.
91
+ for (const [iso, set] of sets) out.set(iso, [...set].sort());
92
+ adjacencyCache.set(topo, out);
93
+ return out;
94
+ }
95
+
50
96
  /** A decoded boundary feature: the GeoJSON geometry plus its ISO id and display
51
97
  * name (carried straight from the topology's `properties.name`). Used for
52
98
  * point-in-polygon reverse-geocoding by the geo-query. */