@sil/data 0.1.5 → 0.1.7
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.
- package/dist/sil-data.cjs +82 -0
- package/dist/sil-data.cjs.map +1 -1
- package/dist/sil-data.js +82 -0
- package/dist/sil-data.js.map +1 -1
- package/dist/types/__tests__/countryMaps.test.d.ts +1 -0
- package/dist/types/__tests__/geography.test.d.ts +1 -0
- package/dist/types/data/countryMaps.d.ts +104 -0
- package/dist/types/data/geography.d.ts +15 -0
- package/dist/types/index.d.ts +3 -2
- package/dist/types/types/index.d.ts +29 -0
- package/package.json +1 -1
package/dist/sil-data.js
CHANGED
|
@@ -4160,6 +4160,14 @@ function getNeighbors(alpha2) {
|
|
|
4160
4160
|
if (!geo) return [];
|
|
4161
4161
|
return geo.neighbors.map((code) => getCountryGeography(code)).filter((g) => g !== void 0);
|
|
4162
4162
|
}
|
|
4163
|
+
function doCountriesBorder(alpha2A, alpha2B) {
|
|
4164
|
+
const geoA = getCountryGeography(alpha2A);
|
|
4165
|
+
if (!geoA) return false;
|
|
4166
|
+
const geoB = getCountryGeography(alpha2B);
|
|
4167
|
+
if (!geoB) return false;
|
|
4168
|
+
const upper = geoB.alpha2.toUpperCase();
|
|
4169
|
+
return geoA.neighbors.some((n) => n.toUpperCase() === upper);
|
|
4170
|
+
}
|
|
4163
4171
|
function getFlagSvgUrl(alpha2) {
|
|
4164
4172
|
return `https://flagcdn.com/${alpha2.toLowerCase()}.svg`;
|
|
4165
4173
|
}
|
|
@@ -4929,7 +4937,77 @@ function _renderPaths(country, fill, stroke, strokeWidth, label) {
|
|
|
4929
4937
|
return `<path${attrs} d="${d}" fill="${fill}" stroke="${stroke}" stroke-width="${strokeWidth}">${i === 0 ? title : ""}</path>`;
|
|
4930
4938
|
}).join("");
|
|
4931
4939
|
}
|
|
4940
|
+
const WORLD_MAP_WIDTH = 2e3;
|
|
4941
|
+
const WORLD_MAP_HEIGHT = 857;
|
|
4942
|
+
const COUNTRY_MAP_DEFAULTS = {
|
|
4943
|
+
fill: "#d0d0d0",
|
|
4944
|
+
stroke: "#ffffff",
|
|
4945
|
+
strokeWidth: 0.5,
|
|
4946
|
+
width: "100%",
|
|
4947
|
+
height: "auto",
|
|
4948
|
+
className: "",
|
|
4949
|
+
showCities: true,
|
|
4950
|
+
cityColor: "#555555",
|
|
4951
|
+
capitalColor: "#cc2222",
|
|
4952
|
+
cityRadius: 3,
|
|
4953
|
+
capitalRadius: 5,
|
|
4954
|
+
padding: 5
|
|
4955
|
+
};
|
|
4956
|
+
function latLonToMapPoint(lat, lon) {
|
|
4957
|
+
return {
|
|
4958
|
+
x: (lon + 180) * (WORLD_MAP_WIDTH / 360),
|
|
4959
|
+
y: (90 - lat) * (WORLD_MAP_HEIGHT / 180)
|
|
4960
|
+
};
|
|
4961
|
+
}
|
|
4962
|
+
function getCountrySubdivisionMapUrl(alpha3) {
|
|
4963
|
+
const code = alpha3.toUpperCase();
|
|
4964
|
+
return `https://upload.wikimedia.org/wikipedia/commons/thumb/maps/${code}.svg/800px-${code}.svg.png`;
|
|
4965
|
+
}
|
|
4966
|
+
function getCountrySvg(alpha2, options = {}) {
|
|
4967
|
+
const opts = { ...COUNTRY_MAP_DEFAULTS, ...options };
|
|
4968
|
+
const code = alpha2.toUpperCase();
|
|
4969
|
+
const countryData = getCountryMapData(code);
|
|
4970
|
+
if (!countryData || countryData.paths.length === 0) return null;
|
|
4971
|
+
const geo = getCountryGeography(code);
|
|
4972
|
+
if (!geo) return null;
|
|
4973
|
+
const { x: x1, y: y1 } = latLonToMapPoint(geo.bounds.north, geo.bounds.west);
|
|
4974
|
+
const { x: x2, y: y2 } = latLonToMapPoint(geo.bounds.south, geo.bounds.east);
|
|
4975
|
+
const minX = Math.min(x1, x2) - opts.padding;
|
|
4976
|
+
const minY = Math.min(y1, y2) - opts.padding;
|
|
4977
|
+
const boxW = Math.abs(x2 - x1) + opts.padding * 2;
|
|
4978
|
+
const boxH = Math.abs(y2 - y1) + opts.padding * 2;
|
|
4979
|
+
const viewBox = `${minX.toFixed(1)} ${minY.toFixed(1)} ${boxW.toFixed(1)} ${boxH.toFixed(1)}`;
|
|
4980
|
+
const pathsHtml = countryData.paths.map((d, i) => {
|
|
4981
|
+
const attrs = i === 0 ? ` id="${code}" data-code="${code}" data-name="${countryData.name}"` : ` data-code="${code}"`;
|
|
4982
|
+
return `<path${attrs} d="${d}" fill="${opts.fill}" stroke="${opts.stroke}" stroke-width="${opts.strokeWidth}"/>`;
|
|
4983
|
+
}).join("\n ");
|
|
4984
|
+
let cityMarkersHtml = "";
|
|
4985
|
+
if (opts.showCities) {
|
|
4986
|
+
const citiesForCountry = getCitiesByCountry(code);
|
|
4987
|
+
cityMarkersHtml = citiesForCountry.map((city) => {
|
|
4988
|
+
const { x, y } = latLonToMapPoint(city.lat, city.lon);
|
|
4989
|
+
const isCapital = city.capital === true;
|
|
4990
|
+
const r = isCapital ? opts.capitalRadius : opts.cityRadius;
|
|
4991
|
+
const color = isCapital ? opts.capitalColor : opts.cityColor;
|
|
4992
|
+
const capitalAttr = isCapital ? ' data-capital="true"' : "";
|
|
4993
|
+
return `<circle cx="${x.toFixed(1)}" cy="${y.toFixed(1)}" r="${r}" fill="${color}" data-city="${city.name}"${capitalAttr}><title>${city.name}${isCapital ? " (capital)" : ""}</title></circle>`;
|
|
4994
|
+
}).join("\n ");
|
|
4995
|
+
}
|
|
4996
|
+
const svgClass = opts.className ? ` class="${opts.className}"` : "";
|
|
4997
|
+
const body = cityMarkersHtml ? ` ${pathsHtml}
|
|
4998
|
+
${cityMarkersHtml}` : ` ${pathsHtml}`;
|
|
4999
|
+
return `<svg
|
|
5000
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
5001
|
+
viewBox="${viewBox}"
|
|
5002
|
+
width="${opts.width}"
|
|
5003
|
+
height="${opts.height}"${svgClass}
|
|
5004
|
+
role="img"
|
|
5005
|
+
aria-label="${countryData.name} map">
|
|
5006
|
+
${body}
|
|
5007
|
+
</svg>`;
|
|
5008
|
+
}
|
|
4932
5009
|
export {
|
|
5010
|
+
COUNTRY_MAP_DEFAULTS,
|
|
4933
5011
|
WORLD_MAP_DEFAULTS,
|
|
4934
5012
|
WORLD_MAP_VIEWBOX,
|
|
4935
5013
|
bearing,
|
|
@@ -4942,6 +5020,7 @@ export {
|
|
|
4942
5020
|
countries,
|
|
4943
5021
|
countryGeography,
|
|
4944
5022
|
currencies,
|
|
5023
|
+
doCountriesBorder,
|
|
4945
5024
|
flagData,
|
|
4946
5025
|
getCapitalCity,
|
|
4947
5026
|
getCitiesByCountry,
|
|
@@ -4955,6 +5034,8 @@ export {
|
|
|
4955
5034
|
getCountryGeography,
|
|
4956
5035
|
getCountryMapData,
|
|
4957
5036
|
getCountryMapSvgUrl,
|
|
5037
|
+
getCountrySubdivisionMapUrl,
|
|
5038
|
+
getCountrySvg,
|
|
4958
5039
|
getCurrencyByCode,
|
|
4959
5040
|
getCurrencyByCountry,
|
|
4960
5041
|
getDirectionBetweenCountries,
|
|
@@ -4975,6 +5056,7 @@ export {
|
|
|
4975
5056
|
getWorldMapSvg,
|
|
4976
5057
|
haversineDistance,
|
|
4977
5058
|
highlightCountries,
|
|
5059
|
+
latLonToMapPoint,
|
|
4978
5060
|
phoneCountryCodes,
|
|
4979
5061
|
searchCities,
|
|
4980
5062
|
searchWorldMapCountries,
|