@sil/data 0.1.5 → 0.1.6

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.
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,104 @@
1
+ /**
2
+ * Individual country SVG map utilities.
3
+ *
4
+ * Provides functions to render a standalone SVG for a single country, using
5
+ * the bundled world-map path data for the country outline and the bundled
6
+ * cities dataset for optional city markers. The viewBox is automatically
7
+ * derived from the country's geographic bounding box stored in the geography
8
+ * dataset.
9
+ *
10
+ * For maps that also show administrative subdivision (province / state)
11
+ * boundaries, use {@link getCountrySubdivisionMapUrl} to obtain a reference
12
+ * URL pointing to an external source – those boundaries are not bundled in
13
+ * this package.
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * import { getCountrySvg } from "@sil/data";
18
+ *
19
+ * // Render Germany with city markers
20
+ * document.getElementById("map").innerHTML = getCountrySvg("DE", {
21
+ * fill: "#4a90e2",
22
+ * stroke: "#ffffff",
23
+ * });
24
+ *
25
+ * // Render France without city markers
26
+ * document.getElementById("map").innerHTML = getCountrySvg("FR", {
27
+ * showCities: false,
28
+ * });
29
+ * ```
30
+ */
31
+ import type { CountryMapOptions } from "../types/index.js";
32
+ /**
33
+ * Default styling and display options for single-country SVG maps.
34
+ */
35
+ export declare const COUNTRY_MAP_DEFAULTS: Required<CountryMapOptions>;
36
+ /**
37
+ * Convert geographic coordinates (latitude / longitude) to the SVG coordinate
38
+ * system used by the bundled world-map path data.
39
+ *
40
+ * The world map uses a simple equirectangular projection scaled to a
41
+ * 2000 × 857 canvas (matching `WORLD_MAP_VIEWBOX`).
42
+ *
43
+ * @param lat Latitude in decimal degrees (−90 … +90)
44
+ * @param lon Longitude in decimal degrees (−180 … +180)
45
+ * @returns `{ x, y }` in world-map SVG units.
46
+ *
47
+ * @example
48
+ * const { x, y } = latLonToMapPoint(52.52, 13.41); // Berlin, Germany
49
+ */
50
+ export declare function latLonToMapPoint(lat: number, lon: number): {
51
+ x: number;
52
+ y: number;
53
+ };
54
+ /**
55
+ * Return an external URL for a country's administrative-subdivision map.
56
+ *
57
+ * The URL points to a Wikimedia Commons PNG rendering (800 px wide) of the
58
+ * corresponding SVG map file. These maps typically include province, state,
59
+ * or region boundaries. The image is **not bundled** in this package – it is
60
+ * fetched at runtime from Wikimedia servers.
61
+ *
62
+ * **Note:** Wikimedia Commons SVG thumbnails require a hash-based path for
63
+ * most files. This helper uses the same simplified URL convention that is
64
+ * already in use in the `flags` module (`getCountryMapSvgUrl`). If a
65
+ * particular country's map file is not served at this path, the URL may
66
+ * return a 404; in that case, use the Wikimedia Commons search page for
67
+ * `"administrative divisions map of {country name}"` to find the correct file.
68
+ *
69
+ * @param alpha3 ISO 3166-1 alpha-3 code (case-insensitive, e.g. `"DEU"`, `"usa"`)
70
+ * @returns A reference URL string – not guaranteed to resolve for every country.
71
+ *
72
+ * @example
73
+ * getCountrySubdivisionMapUrl("DEU");
74
+ * // → "https://upload.wikimedia.org/wikipedia/commons/thumb/maps/DEU.svg/800px-DEU.svg.png"
75
+ */
76
+ export declare function getCountrySubdivisionMapUrl(alpha3: string): string;
77
+ /**
78
+ * Render a standalone SVG string for a single country.
79
+ *
80
+ * The SVG shows:
81
+ * - The country's outline, drawn from the bundled world-map vector paths.
82
+ * - Optional city markers (dots) for every city in the bundled cities dataset
83
+ * that belongs to this country. Capital cities use a distinct colour and a
84
+ * slightly larger dot.
85
+ *
86
+ * Each country `<path>` element receives:
87
+ * - `id` — ISO alpha-2 code, e.g. `id="DE"`
88
+ * - `data-code` — same code
89
+ * - `data-name` — human-readable country name
90
+ *
91
+ * Each city `<circle>` element receives:
92
+ * - `data-city` — city name
93
+ * - `data-capital="true"` — only present for the capital city
94
+ *
95
+ * @param alpha2 ISO 3166-1 alpha-2 code (case-insensitive, e.g. `"DE"`, `"us"`)
96
+ * @param options Optional styling / display overrides.
97
+ * @returns A complete `<svg>…</svg>` string, or `null` if the country code is
98
+ * unknown or has no drawable path data.
99
+ *
100
+ * @example
101
+ * const svg = getCountrySvg("JP", { fill: "#e8f4f8", capitalColor: "#e24a4a" });
102
+ * document.getElementById("map")!.innerHTML = svg ?? "";
103
+ */
104
+ export declare function getCountrySvg(alpha2: string, options?: CountryMapOptions): string | null;
@@ -15,7 +15,7 @@
15
15
  * }));
16
16
  * ```
17
17
  */
18
- export type { Country, PhoneCountryCode, City, State, StateType, Continent, ContinentName, Currency, CountryGeography, CountryBounds, ClimateZone, FlagInfo, FlagColor, CardinalDirection, WorldMapCountry, WorldMapOptions, WorldMapHighlight, } from "./types/index.js";
18
+ export type { Country, PhoneCountryCode, City, State, StateType, Continent, ContinentName, Currency, CountryGeography, CountryBounds, ClimateZone, FlagInfo, FlagColor, CardinalDirection, WorldMapCountry, WorldMapOptions, WorldMapHighlight, CountryMapOptions, } from "./types/index.js";
19
19
  export { countries, getCountryByCode, getCountriesByContinent, getCountryFlag, } from "./data/countries.js";
20
20
  export { phoneCountryCodes, getPhoneCodeByCountry, getCountriesByPhoneCode, } from "./data/phoneCodes.js";
21
21
  export { cities, getCitiesByCountry, getCapitalCity, getCitiesByPopulation, searchCities, } from "./data/cities.js";
@@ -27,3 +27,4 @@ export { flagData, getFlagData, getFlagsByColor, getSimilarFlags, getFlagSvgUrl,
27
27
  export { haversineDistance, bearing, bearingToCardinal, getDistanceBetweenCountries, getDirectionBetweenCountries, compareTemperature, compareSize, getHemisphere, getGeoHints, } from "./utils/geo.js";
28
28
  export type { GeoHint, Hemisphere } from "./utils/geo.js";
29
29
  export { WORLD_MAP_VIEWBOX, WORLD_MAP_DEFAULTS, worldMapCountries, getCountryMapData, searchWorldMapCountries, getWorldMapSvg, highlightCountries, colorizeWorldMap, } from "./data/worldMap.js";
30
+ export { COUNTRY_MAP_DEFAULTS, latLonToMapPoint, getCountrySvg, getCountrySubdivisionMapUrl, } from "./data/countryMaps.js";
@@ -218,3 +218,32 @@ export interface WorldMapHighlight {
218
218
  /** Optional accessible label (written as a `<title>` element). */
219
219
  label?: string;
220
220
  }
221
+ /**
222
+ * Styling and display options for rendering a single-country SVG map.
223
+ */
224
+ export interface CountryMapOptions {
225
+ /** Fill color for the country shape. Default: "#d0d0d0" */
226
+ fill?: string;
227
+ /** Stroke (border) color for the country outline. Default: "#ffffff" */
228
+ stroke?: string;
229
+ /** Stroke width in SVG units. Default: 0.5 */
230
+ strokeWidth?: number;
231
+ /** SVG element width attribute (e.g. "100%", 800). Default: "100%" */
232
+ width?: string | number;
233
+ /** SVG element height attribute (e.g. "auto", 400). Default: "auto" */
234
+ height?: string | number;
235
+ /** Optional CSS class added to the `<svg>` element. */
236
+ className?: string;
237
+ /** Whether to show city marker dots. Default: true */
238
+ showCities?: boolean;
239
+ /** Fill color for regular city markers. Default: "#555555" */
240
+ cityColor?: string;
241
+ /** Fill color for the capital city marker. Default: "#cc2222" */
242
+ capitalColor?: string;
243
+ /** Radius of regular city markers in SVG units. Default: 3 */
244
+ cityRadius?: number;
245
+ /** Radius of the capital city marker in SVG units. Default: 5 */
246
+ capitalRadius?: number;
247
+ /** Extra space (in SVG units) added around the country outline. Default: 5 */
248
+ padding?: number;
249
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sil/data",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "description": "A comprehensive collection of reusable world data: countries, phone codes, flags, cities, states, provinces and more",
5
5
  "type": "module",
6
6
  "main": "./dist/sil-data.cjs",