@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.
- package/dist/sil-data.cjs +73 -0
- package/dist/sil-data.cjs.map +1 -1
- package/dist/sil-data.js +73 -0
- package/dist/sil-data.js.map +1 -1
- package/dist/types/__tests__/countryMaps.test.d.ts +1 -0
- package/dist/types/data/countryMaps.d.ts +104 -0
- package/dist/types/index.d.ts +2 -1
- package/dist/types/types/index.d.ts +29 -0
- package/package.json +1 -1
package/dist/sil-data.cjs
CHANGED
|
@@ -4931,6 +4931,76 @@ function _renderPaths(country, fill, stroke, strokeWidth, label) {
|
|
|
4931
4931
|
return `<path${attrs} d="${d}" fill="${fill}" stroke="${stroke}" stroke-width="${strokeWidth}">${i === 0 ? title : ""}</path>`;
|
|
4932
4932
|
}).join("");
|
|
4933
4933
|
}
|
|
4934
|
+
const WORLD_MAP_WIDTH = 2e3;
|
|
4935
|
+
const WORLD_MAP_HEIGHT = 857;
|
|
4936
|
+
const COUNTRY_MAP_DEFAULTS = {
|
|
4937
|
+
fill: "#d0d0d0",
|
|
4938
|
+
stroke: "#ffffff",
|
|
4939
|
+
strokeWidth: 0.5,
|
|
4940
|
+
width: "100%",
|
|
4941
|
+
height: "auto",
|
|
4942
|
+
className: "",
|
|
4943
|
+
showCities: true,
|
|
4944
|
+
cityColor: "#555555",
|
|
4945
|
+
capitalColor: "#cc2222",
|
|
4946
|
+
cityRadius: 3,
|
|
4947
|
+
capitalRadius: 5,
|
|
4948
|
+
padding: 5
|
|
4949
|
+
};
|
|
4950
|
+
function latLonToMapPoint(lat, lon) {
|
|
4951
|
+
return {
|
|
4952
|
+
x: (lon + 180) * (WORLD_MAP_WIDTH / 360),
|
|
4953
|
+
y: (90 - lat) * (WORLD_MAP_HEIGHT / 180)
|
|
4954
|
+
};
|
|
4955
|
+
}
|
|
4956
|
+
function getCountrySubdivisionMapUrl(alpha3) {
|
|
4957
|
+
const code = alpha3.toUpperCase();
|
|
4958
|
+
return `https://upload.wikimedia.org/wikipedia/commons/thumb/maps/${code}.svg/800px-${code}.svg.png`;
|
|
4959
|
+
}
|
|
4960
|
+
function getCountrySvg(alpha2, options = {}) {
|
|
4961
|
+
const opts = { ...COUNTRY_MAP_DEFAULTS, ...options };
|
|
4962
|
+
const code = alpha2.toUpperCase();
|
|
4963
|
+
const countryData = getCountryMapData(code);
|
|
4964
|
+
if (!countryData || countryData.paths.length === 0) return null;
|
|
4965
|
+
const geo = getCountryGeography(code);
|
|
4966
|
+
if (!geo) return null;
|
|
4967
|
+
const { x: x1, y: y1 } = latLonToMapPoint(geo.bounds.north, geo.bounds.west);
|
|
4968
|
+
const { x: x2, y: y2 } = latLonToMapPoint(geo.bounds.south, geo.bounds.east);
|
|
4969
|
+
const minX = Math.min(x1, x2) - opts.padding;
|
|
4970
|
+
const minY = Math.min(y1, y2) - opts.padding;
|
|
4971
|
+
const boxW = Math.abs(x2 - x1) + opts.padding * 2;
|
|
4972
|
+
const boxH = Math.abs(y2 - y1) + opts.padding * 2;
|
|
4973
|
+
const viewBox = `${minX.toFixed(1)} ${minY.toFixed(1)} ${boxW.toFixed(1)} ${boxH.toFixed(1)}`;
|
|
4974
|
+
const pathsHtml = countryData.paths.map((d, i) => {
|
|
4975
|
+
const attrs = i === 0 ? ` id="${code}" data-code="${code}" data-name="${countryData.name}"` : ` data-code="${code}"`;
|
|
4976
|
+
return `<path${attrs} d="${d}" fill="${opts.fill}" stroke="${opts.stroke}" stroke-width="${opts.strokeWidth}"/>`;
|
|
4977
|
+
}).join("\n ");
|
|
4978
|
+
let cityMarkersHtml = "";
|
|
4979
|
+
if (opts.showCities) {
|
|
4980
|
+
const citiesForCountry = getCitiesByCountry(code);
|
|
4981
|
+
cityMarkersHtml = citiesForCountry.map((city) => {
|
|
4982
|
+
const { x, y } = latLonToMapPoint(city.lat, city.lon);
|
|
4983
|
+
const isCapital = city.capital === true;
|
|
4984
|
+
const r = isCapital ? opts.capitalRadius : opts.cityRadius;
|
|
4985
|
+
const color = isCapital ? opts.capitalColor : opts.cityColor;
|
|
4986
|
+
const capitalAttr = isCapital ? ' data-capital="true"' : "";
|
|
4987
|
+
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>`;
|
|
4988
|
+
}).join("\n ");
|
|
4989
|
+
}
|
|
4990
|
+
const svgClass = opts.className ? ` class="${opts.className}"` : "";
|
|
4991
|
+
const body = cityMarkersHtml ? ` ${pathsHtml}
|
|
4992
|
+
${cityMarkersHtml}` : ` ${pathsHtml}`;
|
|
4993
|
+
return `<svg
|
|
4994
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
4995
|
+
viewBox="${viewBox}"
|
|
4996
|
+
width="${opts.width}"
|
|
4997
|
+
height="${opts.height}"${svgClass}
|
|
4998
|
+
role="img"
|
|
4999
|
+
aria-label="${countryData.name} map">
|
|
5000
|
+
${body}
|
|
5001
|
+
</svg>`;
|
|
5002
|
+
}
|
|
5003
|
+
exports.COUNTRY_MAP_DEFAULTS = COUNTRY_MAP_DEFAULTS;
|
|
4934
5004
|
exports.WORLD_MAP_DEFAULTS = WORLD_MAP_DEFAULTS;
|
|
4935
5005
|
exports.WORLD_MAP_VIEWBOX = WORLD_MAP_VIEWBOX;
|
|
4936
5006
|
exports.bearing = bearing;
|
|
@@ -4956,6 +5026,8 @@ exports.getCountryFlag = getCountryFlag;
|
|
|
4956
5026
|
exports.getCountryGeography = getCountryGeography;
|
|
4957
5027
|
exports.getCountryMapData = getCountryMapData;
|
|
4958
5028
|
exports.getCountryMapSvgUrl = getCountryMapSvgUrl;
|
|
5029
|
+
exports.getCountrySubdivisionMapUrl = getCountrySubdivisionMapUrl;
|
|
5030
|
+
exports.getCountrySvg = getCountrySvg;
|
|
4959
5031
|
exports.getCurrencyByCode = getCurrencyByCode;
|
|
4960
5032
|
exports.getCurrencyByCountry = getCurrencyByCountry;
|
|
4961
5033
|
exports.getDirectionBetweenCountries = getDirectionBetweenCountries;
|
|
@@ -4976,6 +5048,7 @@ exports.getStatesByType = getStatesByType;
|
|
|
4976
5048
|
exports.getWorldMapSvg = getWorldMapSvg;
|
|
4977
5049
|
exports.haversineDistance = haversineDistance;
|
|
4978
5050
|
exports.highlightCountries = highlightCountries;
|
|
5051
|
+
exports.latLonToMapPoint = latLonToMapPoint;
|
|
4979
5052
|
exports.phoneCountryCodes = phoneCountryCodes;
|
|
4980
5053
|
exports.searchCities = searchCities;
|
|
4981
5054
|
exports.searchWorldMapCountries = searchWorldMapCountries;
|