dotted-map 2.2.2 → 3.0.0

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,70 @@
1
+ //#region src/types.d.ts
2
+ interface Region {
3
+ lat: {
4
+ min: number;
5
+ max: number;
6
+ };
7
+ lng: {
8
+ min: number;
9
+ max: number;
10
+ };
11
+ }
12
+ interface MapSettings {
13
+ height?: number;
14
+ width?: number;
15
+ countries?: string[];
16
+ region?: Region;
17
+ grid?: 'vertical' | 'diagonal';
18
+ }
19
+ interface DottedMapSettings extends MapSettings {
20
+ avoidOuterPins?: boolean;
21
+ }
22
+ interface DottedMapWithoutCountriesSettings {
23
+ map: MapData;
24
+ avoidOuterPins?: boolean;
25
+ }
26
+ interface SvgOptions {
27
+ color?: string;
28
+ radius?: number;
29
+ }
30
+ interface PinInput {
31
+ lat: number;
32
+ lng: number;
33
+ data?: unknown;
34
+ svgOptions?: SvgOptions;
35
+ }
36
+ interface SvgSettings {
37
+ shape?: 'circle' | 'hexagon';
38
+ color?: string;
39
+ backgroundColor?: string;
40
+ radius?: number;
41
+ }
42
+ interface Point {
43
+ x: number;
44
+ y: number;
45
+ lat?: number;
46
+ lng?: number;
47
+ data?: unknown;
48
+ svgOptions?: SvgOptions;
49
+ }
50
+ interface MapData {
51
+ points: Record<string, Point>;
52
+ X_MIN: number;
53
+ Y_MIN: number;
54
+ X_MAX: number;
55
+ Y_MAX: number;
56
+ X_RANGE: number;
57
+ Y_RANGE: number;
58
+ region: Region;
59
+ grid: 'vertical' | 'diagonal';
60
+ height: number;
61
+ width: number;
62
+ ystep: number;
63
+ }
64
+ interface ImageInfo {
65
+ region: Region;
66
+ width: number;
67
+ height: number;
68
+ }
69
+ //#endregion
70
+ export { MapSettings as a, Region as c, MapData as i, SvgSettings as l, DottedMapWithoutCountriesSettings as n, PinInput as o, ImageInfo as r, Point as s, DottedMapSettings as t };
@@ -0,0 +1,70 @@
1
+ //#region src/types.d.ts
2
+ interface Region {
3
+ lat: {
4
+ min: number;
5
+ max: number;
6
+ };
7
+ lng: {
8
+ min: number;
9
+ max: number;
10
+ };
11
+ }
12
+ interface MapSettings {
13
+ height?: number;
14
+ width?: number;
15
+ countries?: string[];
16
+ region?: Region;
17
+ grid?: 'vertical' | 'diagonal';
18
+ }
19
+ interface DottedMapSettings extends MapSettings {
20
+ avoidOuterPins?: boolean;
21
+ }
22
+ interface DottedMapWithoutCountriesSettings {
23
+ map: MapData;
24
+ avoidOuterPins?: boolean;
25
+ }
26
+ interface SvgOptions {
27
+ color?: string;
28
+ radius?: number;
29
+ }
30
+ interface PinInput {
31
+ lat: number;
32
+ lng: number;
33
+ data?: unknown;
34
+ svgOptions?: SvgOptions;
35
+ }
36
+ interface SvgSettings {
37
+ shape?: 'circle' | 'hexagon';
38
+ color?: string;
39
+ backgroundColor?: string;
40
+ radius?: number;
41
+ }
42
+ interface Point {
43
+ x: number;
44
+ y: number;
45
+ lat?: number;
46
+ lng?: number;
47
+ data?: unknown;
48
+ svgOptions?: SvgOptions;
49
+ }
50
+ interface MapData {
51
+ points: Record<string, Point>;
52
+ X_MIN: number;
53
+ Y_MIN: number;
54
+ X_MAX: number;
55
+ Y_MAX: number;
56
+ X_RANGE: number;
57
+ Y_RANGE: number;
58
+ region: Region;
59
+ grid: 'vertical' | 'diagonal';
60
+ height: number;
61
+ width: number;
62
+ ystep: number;
63
+ }
64
+ interface ImageInfo {
65
+ region: Region;
66
+ width: number;
67
+ height: number;
68
+ }
69
+ //#endregion
70
+ export { MapSettings as a, Region as c, MapData as i, SvgSettings as l, DottedMapWithoutCountriesSettings as n, PinInput as o, ImageInfo as r, Point as s, DottedMapSettings as t };
@@ -0,0 +1,85 @@
1
+ const require_chunk = require('./chunk-C0xms8kb.cjs');
2
+ let proj4 = require("proj4");
3
+ proj4 = require_chunk.__toESM(proj4);
4
+
5
+ //#region src/without-countries.ts
6
+ var DottedMapWithoutCountries = class {
7
+ constructor({ map, avoidOuterPins = false }) {
8
+ this.points = map.points;
9
+ this.pins = [];
10
+ this.X_MIN = map.X_MIN;
11
+ this.Y_MAX = map.Y_MAX;
12
+ this.X_RANGE = map.X_RANGE;
13
+ this.Y_RANGE = map.Y_RANGE;
14
+ this.grid = map.grid;
15
+ this.width = map.width;
16
+ this.height = map.height;
17
+ this.ystep = map.ystep;
18
+ this.avoidOuterPins = avoidOuterPins;
19
+ this.image = {
20
+ region: map.region,
21
+ width: map.width,
22
+ height: map.height
23
+ };
24
+ }
25
+ addPin({ lat, lng, data, svgOptions }) {
26
+ const pin = this.getPin({
27
+ lat,
28
+ lng
29
+ });
30
+ if (!pin) return void 0;
31
+ const point = {
32
+ ...pin,
33
+ data,
34
+ svgOptions
35
+ };
36
+ this.pins.push(point);
37
+ return point;
38
+ }
39
+ getPin({ lat, lng }) {
40
+ const [googleX, googleY] = (0, proj4.default)("GOOGLE", [lng, lat]);
41
+ if (this.avoidOuterPins) return;
42
+ let rawX = this.width * (googleX - this.X_MIN) / this.X_RANGE;
43
+ const rawY = this.height * (this.Y_MAX - googleY) / this.Y_RANGE;
44
+ const y = Math.round(rawY / this.ystep);
45
+ if (y % 2 === 0 && this.grid === "diagonal") rawX -= .5;
46
+ let localx = Math.round(rawX);
47
+ const localy = Math.round(y) * this.ystep;
48
+ if (y % 2 === 0 && this.grid === "diagonal") localx += .5;
49
+ const [localLng, localLat] = (0, proj4.default)("GOOGLE", "WGS84", [localx * this.X_RANGE / this.width + this.X_MIN, this.Y_MAX - localy * this.Y_RANGE / this.height]);
50
+ return {
51
+ x: localx,
52
+ y: localy,
53
+ lat: localLat,
54
+ lng: localLng
55
+ };
56
+ }
57
+ getPoints() {
58
+ return [...Object.values(this.points), ...this.pins];
59
+ }
60
+ getSVG({ shape = "circle", color = "current", backgroundColor = "transparent", radius = .5 } = {}) {
61
+ const getPoint = ({ x, y, svgOptions = {} }) => {
62
+ const pointRadius = svgOptions.radius || radius;
63
+ if (shape === "circle") return `<circle cx="${x}" cy="${y}" r="${pointRadius}" fill="${svgOptions.color || color}" />`;
64
+ else if (shape === "hexagon") {
65
+ const sqrt3radius = Math.sqrt(3) * pointRadius;
66
+ return `<polyline points="${[
67
+ [x + sqrt3radius, y - pointRadius],
68
+ [x + sqrt3radius, y + pointRadius],
69
+ [x, y + 2 * pointRadius],
70
+ [x - sqrt3radius, y + pointRadius],
71
+ [x - sqrt3radius, y - pointRadius],
72
+ [x, y - 2 * pointRadius]
73
+ ].map((point) => point.join(",")).join(" ")}" fill="${svgOptions.color || color}" />`;
74
+ }
75
+ return "";
76
+ };
77
+ return `<svg viewBox="0 0 ${this.width} ${this.height}" xmlns="http://www.w3.org/2000/svg" style="background-color: ${backgroundColor}">
78
+ ${Object.values(this.points).map(getPoint).join("\n")}
79
+ ${this.pins.map(getPoint).join("\n")}
80
+ </svg>`;
81
+ }
82
+ };
83
+
84
+ //#endregion
85
+ module.exports = DottedMapWithoutCountries;
@@ -0,0 +1,43 @@
1
+ import { c as Region, i as MapData, l as SvgSettings, n as DottedMapWithoutCountriesSettings, o as PinInput, r as ImageInfo, s as Point } from "./types-ByIhMtjO.cjs";
2
+
3
+ //#region src/without-countries.d.ts
4
+ declare class DottedMapWithoutCountries {
5
+ private points;
6
+ private X_MIN;
7
+ private Y_MAX;
8
+ private X_RANGE;
9
+ private Y_RANGE;
10
+ private grid;
11
+ private width;
12
+ private height;
13
+ private ystep;
14
+ private avoidOuterPins;
15
+ private pins;
16
+ image: ImageInfo;
17
+ constructor({
18
+ map,
19
+ avoidOuterPins
20
+ }: DottedMapWithoutCountriesSettings);
21
+ addPin({
22
+ lat,
23
+ lng,
24
+ data,
25
+ svgOptions
26
+ }: PinInput): Point;
27
+ getPin({
28
+ lat,
29
+ lng
30
+ }: {
31
+ lat: number;
32
+ lng: number;
33
+ }): Point | undefined;
34
+ getPoints(): Point[];
35
+ getSVG({
36
+ shape,
37
+ color,
38
+ backgroundColor,
39
+ radius
40
+ }?: SvgSettings): string;
41
+ }
42
+ //#endregion
43
+ export { type DottedMapWithoutCountriesSettings, type ImageInfo, type MapData, type PinInput, type Point, type Region, type SvgSettings, DottedMapWithoutCountries as default };
@@ -0,0 +1,43 @@
1
+ import { c as Region, i as MapData, l as SvgSettings, n as DottedMapWithoutCountriesSettings, o as PinInput, r as ImageInfo, s as Point } from "./types-UL1f7mia.mjs";
2
+
3
+ //#region src/without-countries.d.ts
4
+ declare class DottedMapWithoutCountries {
5
+ private points;
6
+ private X_MIN;
7
+ private Y_MAX;
8
+ private X_RANGE;
9
+ private Y_RANGE;
10
+ private grid;
11
+ private width;
12
+ private height;
13
+ private ystep;
14
+ private avoidOuterPins;
15
+ private pins;
16
+ image: ImageInfo;
17
+ constructor({
18
+ map,
19
+ avoidOuterPins
20
+ }: DottedMapWithoutCountriesSettings);
21
+ addPin({
22
+ lat,
23
+ lng,
24
+ data,
25
+ svgOptions
26
+ }: PinInput): Point;
27
+ getPin({
28
+ lat,
29
+ lng
30
+ }: {
31
+ lat: number;
32
+ lng: number;
33
+ }): Point | undefined;
34
+ getPoints(): Point[];
35
+ getSVG({
36
+ shape,
37
+ color,
38
+ backgroundColor,
39
+ radius
40
+ }?: SvgSettings): string;
41
+ }
42
+ //#endregion
43
+ export { type DottedMapWithoutCountriesSettings, type ImageInfo, type MapData, type PinInput, type Point, type Region, type SvgSettings, DottedMapWithoutCountries as default };
@@ -0,0 +1,83 @@
1
+ import proj4 from "proj4";
2
+
3
+ //#region src/without-countries.ts
4
+ var DottedMapWithoutCountries = class {
5
+ constructor({ map, avoidOuterPins = false }) {
6
+ this.points = map.points;
7
+ this.pins = [];
8
+ this.X_MIN = map.X_MIN;
9
+ this.Y_MAX = map.Y_MAX;
10
+ this.X_RANGE = map.X_RANGE;
11
+ this.Y_RANGE = map.Y_RANGE;
12
+ this.grid = map.grid;
13
+ this.width = map.width;
14
+ this.height = map.height;
15
+ this.ystep = map.ystep;
16
+ this.avoidOuterPins = avoidOuterPins;
17
+ this.image = {
18
+ region: map.region,
19
+ width: map.width,
20
+ height: map.height
21
+ };
22
+ }
23
+ addPin({ lat, lng, data, svgOptions }) {
24
+ const pin = this.getPin({
25
+ lat,
26
+ lng
27
+ });
28
+ if (!pin) return void 0;
29
+ const point = {
30
+ ...pin,
31
+ data,
32
+ svgOptions
33
+ };
34
+ this.pins.push(point);
35
+ return point;
36
+ }
37
+ getPin({ lat, lng }) {
38
+ const [googleX, googleY] = proj4("GOOGLE", [lng, lat]);
39
+ if (this.avoidOuterPins) return;
40
+ let rawX = this.width * (googleX - this.X_MIN) / this.X_RANGE;
41
+ const rawY = this.height * (this.Y_MAX - googleY) / this.Y_RANGE;
42
+ const y = Math.round(rawY / this.ystep);
43
+ if (y % 2 === 0 && this.grid === "diagonal") rawX -= .5;
44
+ let localx = Math.round(rawX);
45
+ const localy = Math.round(y) * this.ystep;
46
+ if (y % 2 === 0 && this.grid === "diagonal") localx += .5;
47
+ const [localLng, localLat] = proj4("GOOGLE", "WGS84", [localx * this.X_RANGE / this.width + this.X_MIN, this.Y_MAX - localy * this.Y_RANGE / this.height]);
48
+ return {
49
+ x: localx,
50
+ y: localy,
51
+ lat: localLat,
52
+ lng: localLng
53
+ };
54
+ }
55
+ getPoints() {
56
+ return [...Object.values(this.points), ...this.pins];
57
+ }
58
+ getSVG({ shape = "circle", color = "current", backgroundColor = "transparent", radius = .5 } = {}) {
59
+ const getPoint = ({ x, y, svgOptions = {} }) => {
60
+ const pointRadius = svgOptions.radius || radius;
61
+ if (shape === "circle") return `<circle cx="${x}" cy="${y}" r="${pointRadius}" fill="${svgOptions.color || color}" />`;
62
+ else if (shape === "hexagon") {
63
+ const sqrt3radius = Math.sqrt(3) * pointRadius;
64
+ return `<polyline points="${[
65
+ [x + sqrt3radius, y - pointRadius],
66
+ [x + sqrt3radius, y + pointRadius],
67
+ [x, y + 2 * pointRadius],
68
+ [x - sqrt3radius, y + pointRadius],
69
+ [x - sqrt3radius, y - pointRadius],
70
+ [x, y - 2 * pointRadius]
71
+ ].map((point) => point.join(",")).join(" ")}" fill="${svgOptions.color || color}" />`;
72
+ }
73
+ return "";
74
+ };
75
+ return `<svg viewBox="0 0 ${this.width} ${this.height}" xmlns="http://www.w3.org/2000/svg" style="background-color: ${backgroundColor}">
76
+ ${Object.values(this.points).map(getPoint).join("\n")}
77
+ ${this.pins.map(getPoint).join("\n")}
78
+ </svg>`;
79
+ }
80
+ };
81
+
82
+ //#endregion
83
+ export { DottedMapWithoutCountries as default };
package/package.json CHANGED
@@ -1,15 +1,43 @@
1
1
  {
2
2
  "name": "dotted-map",
3
- "version": "2.2.2",
3
+ "version": "3.0.0",
4
4
  "description": "Create a SVG map filled with dots for the world or countries",
5
- "main": "./index.js",
5
+ "type": "module",
6
+ "main": "./dist/index.cjs",
7
+ "module": "./dist/index.mjs",
8
+ "types": "./dist/index.d.mts",
6
9
  "exports": {
7
- ".": "./index.js",
8
- "./without-countries": "./without-countries.js"
10
+ ".": {
11
+ "import": {
12
+ "types": "./dist/index.d.mts",
13
+ "default": "./dist/index.mjs"
14
+ },
15
+ "require": {
16
+ "types": "./dist/index.d.cts",
17
+ "default": "./dist/index.cjs"
18
+ }
19
+ },
20
+ "./without-countries": {
21
+ "import": {
22
+ "types": "./dist/without-countries.d.mts",
23
+ "default": "./dist/without-countries.mjs"
24
+ },
25
+ "require": {
26
+ "types": "./dist/without-countries.d.cts",
27
+ "default": "./dist/without-countries.cjs"
28
+ }
29
+ }
30
+ },
31
+ "files": [
32
+ "dist"
33
+ ],
34
+ "engines": {
35
+ "node": ">=18"
9
36
  },
10
- "module": "./src/with-countries.js",
11
37
  "scripts": {
12
- "build": "webpack"
38
+ "build": "tsdown",
39
+ "typecheck": "tsc --noEmit",
40
+ "test": "node test.js"
13
41
  },
14
42
  "keywords": [
15
43
  "map",
@@ -20,16 +48,24 @@
20
48
  "countries",
21
49
  "country"
22
50
  ],
51
+ "repository": {
52
+ "type": "git",
53
+ "url": "git+https://github.com/NTag/dotted-map.git"
54
+ },
23
55
  "author": "Basile Bruneau <basile@bruneau.email>",
24
56
  "license": "MIT",
57
+ "bugs": {
58
+ "url": "https://github.com/NTag/dotted-map/issues"
59
+ },
60
+ "homepage": "https://github.com/NTag/dotted-map",
25
61
  "dependencies": {
26
- "@turf/boolean-point-in-polygon": "^6.0.1",
27
- "proj4": "^2.6.1"
62
+ "@turf/boolean-point-in-polygon": "^7.3.4",
63
+ "proj4": "^2.20.2"
28
64
  },
29
65
  "devDependencies": {
30
- "prettier": "^2.0.5",
31
- "webpack": "^5.33.2",
32
- "webpack-cli": "^4.6.0"
66
+ "prettier": "^3.8.1",
67
+ "tsdown": "^0.20.3",
68
+ "typescript": "^5.9.3"
33
69
  },
34
70
  "sideEffects": false
35
71
  }
package/index.d.ts DELETED
@@ -1,62 +0,0 @@
1
- namespace DottedMapLib {
2
- interface Region {
3
- lat: { min: number; max: number };
4
- lng: { min: number; max: number };
5
- }
6
-
7
- interface MapSettings {
8
- height?: number;
9
- width?: number;
10
- countries?: string[];
11
- region?: Region;
12
- grid?: 'vertical' | 'diagonal';
13
- }
14
-
15
- interface Settings extends MapSettings {
16
- avoidOuterPins?: false | true;
17
- }
18
-
19
- interface SvgOptions {
20
- color?: string;
21
- radius?: number;
22
- }
23
-
24
- interface Pin {
25
- lat: number;
26
- lng: number;
27
- data?: any;
28
- svgOptions?: SvgOptions;
29
- }
30
-
31
- interface SvgSettings {
32
- shape?: 'circle' | 'hexagon';
33
- color?: string;
34
- backgroundColor?: string;
35
- radius?: number;
36
- }
37
-
38
- type Point = {
39
- x: number;
40
- y: number;
41
- lat: number;
42
- lng: number;
43
- data?: any;
44
- svgOptions?: SvgOptions;
45
- };
46
- }
47
-
48
- export const getMapJSON: (settings: DottedMapLib.MapSettings) => string;
49
-
50
- export default class DottedMap {
51
- constructor(settings: DottedMapLib.Settings);
52
-
53
- addPin(pin: DottedMapLib.Pin): DottedMapLib.Point;
54
- getPin(pin: DottedMapLib.Pin): DottedMapLib.Point;
55
- getPoints(): DottedMapLib.Point[];
56
- getSVG(settings: DottedMapLib.SvgSettings): string;
57
- image: {
58
- region: DottedMap.Region;
59
- width: number;
60
- height: number;
61
- };
62
- }