/** * Minimal, zero-dependency TopoJSON feature extractor. * * TopoJSON (https://github.com/topojson/topojson-specification) encodes * geometries as indices into a shared arc table, optionally with an * integer quantisation grid that is dequantised via `transform`. Full * support (mesh, merge, presimplify…) belongs to a dedicated library; * this module implements only what the `regionMap` renderer needs: * * 1. Parse a {@link TopologyLike} object produced by any TopoJSON 1.x * emitter (d3, topojson-server, world-atlas bundles). * 2. Dequantise integer-encoded arcs back to absolute lon/lat pairs. * 3. Resolve a geometry (`Polygon` / `MultiPolygon` / `LineString` / * `MultiLineString` / `Point` / `MultiPoint`) into drawable rings. * * The shapes here mirror what the TopoJSON 1.x spec emits but keep * the types narrow — unknown fields (`bbox`, vendor extensions) are * ignored, not stripped. Users who need the full spec should use the * upstream `topojson-client` package; doing so does not conflict with * this module because both return `[lon, lat]` coordinate arrays in * the geometry output. */ /** Raw TopoJSON topology as produced by d3 / world-atlas. */ export interface TopologyLike { type: "Topology"; /** * Optional quantisation transform: each arc point's integer pair * `[qx, qy]` is decoded as * `[qx * scale[0] + translate[0], qy * scale[1] + translate[1]]` * after delta-undo. Absent → arcs already hold absolute coordinates. */ transform?: { scale: [number, number]; translate: [number, number]; }; /** Shared arc pool; each arc is a list of `[x, y]` integer or float pairs. */ arcs: Array>; /** Named geometry collections (e.g. `countries`, `states`). */ objects: Record; } export type TopoGeometry = { type: "Polygon"; arcs: number[][]; id?: string | number; properties?: Record; } | { type: "MultiPolygon"; arcs: number[][][]; id?: string | number; properties?: Record; } | { type: "LineString"; arcs: number[]; id?: string | number; properties?: Record; } | { type: "MultiLineString"; arcs: number[][]; id?: string | number; properties?: Record; } | { type: "Point"; coordinates: [number, number]; id?: string | number; properties?: Record; } | { type: "MultiPoint"; coordinates: Array<[number, number]>; id?: string | number; properties?: Record; }; export interface TopoGeometryCollection { type: "GeometryCollection"; geometries: TopoGeometry[]; } /** * A resolved polygon — an ordered ring of `[lon, lat]` pairs in * absolute coordinates. Holes (inner rings) are represented as * subsequent entries in the outer array. */ export type ResolvedRing = Array<[number, number]>; /** * Resolve a named object from a {@link TopologyLike} into a flat list * of `{ id, rings }` records. Each `rings[0]` is the outer ring and * the remainder are holes. For `LineString` / `MultiLineString`, * `rings` contains the open polylines; the caller is expected to * treat them as un-closed paths. * * Throws if the object is missing or not a recognised geometry type — * preferring a loud failure over silent "empty map" output, which is * almost always a wiring bug on the caller's side. */ export declare function resolveTopologyObject(topology: TopologyLike, objectName: string): Array<{ id: string | number | undefined; properties: Record | undefined; geometry: TopoGeometry; rings: ResolvedRing[]; }>;