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