piri 1.1.1 → 1.1.2

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.
Files changed (2) hide show
  1. package/README.md +40 -144
  2. package/package.json +3 -12
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # piri
2
2
 
3
- A lightweight utility to create beautiful, dotted SVG maps with a bring-your-own-styles mentality. Heavily based on the [Dotted Map](https://github.com/NTag/dotted-map/tree/main) library, with more customization.
3
+ A lightweight utility to create beautiful, stylized SVG maps with a bring-your-own-styles mentality. Heavily based on the [Dotted Map](https://github.com/NTag/dotted-map/tree/main) library, with more customization.
4
4
 
5
5
  ![a dotted map on an abstract background](https://raw.githubusercontent.com/thejessewinton/piri/refs/heads/main/image.jpeg "SVG Dotted Map")
6
6
 
@@ -12,7 +12,7 @@ A lightweight utility to create beautiful, dotted SVG maps with a bring-your-own
12
12
  pnpm install piri
13
13
  ```
14
14
 
15
- ## Quick Start
15
+ ## Usage
16
16
 
17
17
  ```tsx
18
18
  import { createMap } from "piri";
@@ -23,174 +23,70 @@ const { points, addMarkers } = createMap({
23
23
  });
24
24
  ```
25
25
 
26
- `createMap` returns:
26
+ It's that simple. `points` represents land mass, `addMarkers` projects your markers onto the same coordinate space.
27
27
 
28
- - **`points`** — an array of `{ x, y }` coordinates representing land masses, snapped to a dot grid
29
- - **`addMarkers`** — a function to convert lat/lng markers into the same coordinate space
30
-
31
- ## API Reference
32
-
33
- ### `createMap(options)`
34
-
35
- Creates a dot grid representing the world (or a subset of it) and returns the grid points along with a marker projection function.
36
-
37
- #### Options
28
+ ### Options
38
29
 
39
30
  | Option | Type | Default | Description |
40
31
  |---|---|---|---|
41
- | `width` | `number` | **required** | Width of the SVG viewBox in px. |
42
- | `height` | `number` | **required** | Height of the SVG viewBox in px. |
43
- | `mapSamples` | `number` | `6000` | Total number of grid cells sampled. Higher values produce denser, more detailed maps at the cost of more points to render. |
44
- | `radius` | `number` | `0.3` | The base dot radius in viewBox units. Controls the margin/padding around the edges of the map (`margin = radius * 1.25`). |
45
- | `countries` | `CountryCode[]` | `undefined` | ISO 3166-1 alpha-3 country codes to render (e.g. `["USA", "CAN"]`). When provided, only the specified countries are drawn and the region auto-fits to their bounding box. |
46
- | `region` | `Region` | auto | A custom lat/lng bounding box to control which part of the world is visible. Overrides the auto-fit behavior when `countries` is set. |
47
-
48
- #### Region
49
-
50
- ```typescript
51
- interface Region {
52
- lat: { min: number; max: number };
53
- lng: { min: number; max: number };
54
- }
55
- ```
56
-
57
- Latitudes are clamped to `[-85, 85]` internally (the limit of the Web Mercator projection).
32
+ | `width` | `number` | **required** | Width of the SVG viewBox. |
33
+ | `height` | `number` | **required** | Height of the SVG viewBox. |
34
+ | `mapSamples` | `number` | `6000` | Grid cells sampled. Higher = denser dots. |
35
+ | `radius` | `number` | `0.3` | Base dot radius in viewBox units. Controls edge margin (`radius * 1.25`). |
36
+ | `countries` | `CountryCode[]` | `undefined` | ISO 3166-1 alpha-3 codes (e.g. `["USA", "CAN"]`). Auto-fits the region to the bounding box. Fully typesafe you get autocomplete on all ~170 supported codes. |
37
+ | `region` | `Region` | auto | Custom lat/lng bounding box. Overrides the auto-fit from `countries`. Latitudes clamped to `[-85, 85]` (Web Mercator limit). |
58
38
 
59
- #### Return Value
39
+ ### Markers
60
40
 
61
- ```typescript
62
- {
63
- points: Point[]; // { x: number; y: number }[]
64
- addMarkers: <MarkerData>(markers: Marker<MarkerData>[]) => (Point & MarkerData)[];
65
- }
66
- ```
67
-
68
- ### `addMarkers<MarkerData>(markers)`
69
-
70
- Projects an array of lat/lng markers into the map's coordinate space. Each marker is snapped to the nearest grid position so it aligns with the dot grid.
71
-
72
- #### Marker
73
-
74
- ```typescript
75
- type Marker<MarkerData = void> = {
76
- lat: number;
77
- lng: number;
78
- size?: number;
79
- } & MarkerData;
80
- ```
41
+ By default `addMarkers` expects an array with, at minimum, the latitude and longitude of your markers, and an optional `size` parameter.
81
42
 
82
- - `lat` / `lng` — geographic coordinates
83
- - `size` **pass-through only**. Not used internally; it's returned as-is for your renderer to consume.
84
- - Any additional properties from `MarkerData` are preserved in the output.
85
-
86
- #### Generic Custom Data
87
-
88
- `addMarkers` accepts a generic type parameter, giving you full type safety on custom marker properties:
89
-
90
- ```typescript
91
- const markers = addMarkers<{ label: string; visited: boolean }>([
43
+ ```ts
44
+ const markers = addMarkers([
92
45
  {
93
46
  lat: 40.7128,
94
47
  lng: -74.006,
95
- label: "New York",
96
- visited: true
97
- },
48
+ size: 0.4
49
+ }, // New York
98
50
  { lat: 51.5074,
99
- lng: -0.1278,
100
- label: "London",
101
- visited: false
102
- },
51
+ lng: -0.1278
52
+ }, // London
103
53
  ]);
104
54
  ```
105
55
 
106
- ## Usage Examples
56
+ #### Expanding the output
107
57
 
108
- ### World Map
109
-
110
- ```tsx
111
- import { createMap } from "piri";
58
+ `addMarkers` is generic, and any extra properties you pass in are preserved and fully typed in the output.
112
59
 
113
- const { points, addMarkers } = createMap({
114
- width: 150,
115
- height: 75,
116
- mapSamples: 4500,
117
- });
118
-
119
- const markers = addMarkers([
120
- { lat: 40.7128, lng: -74.006, size: 0.5 }, // New York
121
- { lat: 34.0522, lng: -118.2437, size: 0.5 }, // Los Angeles
122
- { lat: 51.5074, lng: -0.1278, size: 0.5 }, // London
123
- { lat: -33.8688, lng: 151.2093, size: 0.5 }, // Sydney
60
+ ```ts
61
+ const markers = addMarkers<{ visited: boolean}>([
62
+ {
63
+ lat: 40.7128,
64
+ lng: -74.006,
65
+ size: 0.4
66
+ visited: true
67
+ }, // New York
68
+ { lat: 51.5074,
69
+ lng: -0.1278
70
+ visited: false
71
+ }, // London
124
72
  ]);
125
73
  ```
126
74
 
127
- ### Single Country
128
-
129
- When `countries` is provided, the map automatically zooms to fit those countries:
130
-
131
- ```typescript
132
- const { points, addMarkers } = createMap({
133
- width: 200,
134
- height: 100,
135
- countries: ["USA"],
136
- });
137
- ```
138
-
139
- ### Multiple Countries
140
-
141
- ```typescript
142
- const { points, addMarkers } = createMap({
143
- width: 200,
144
- height: 100,
145
- countries: ["USA", "CAN", "MEX"],
146
- });
147
- ```
148
-
149
- ### Custom Region
150
-
151
- Override the viewport with a specific lat/lng bounding box:
152
-
153
- ```typescript
154
- const { points } = createMap({
155
- width: 200,
156
- height: 100,
157
- region: {
158
- lat: { min: 35, max: 72 },
159
- lng: { min: -25, max: 45 },
160
- },
161
- });
162
- ```
163
-
164
- ### Controlling Density
165
-
166
- `mapSamples` controls the total grid cells tested. More samples = more dots = more detail:
167
-
168
- ```typescript
169
- // Sparse — fast, lightweight
170
- const sparse = createMap({ width: 200, height: 100, mapSamples: 500 });
171
-
172
- // Dense — detailed, more points to render
173
- const dense = createMap({ width: 200, height: 100, mapSamples: 10000 });
174
- ```
175
-
176
75
  ### Rendering
177
76
 
178
- After creating a map, render it as an SVG, with whatever customizations you'd like. This example uses React:
77
+ After these steps, render the map as an SVG, with whatever customizations you need. This example uses React:
179
78
 
180
79
  ```tsx
181
80
  export const DottedMap = () => {
182
- const { points, addMarkers } = createMap({
183
- width: 150,
184
- height: 75,
185
- });
81
+ const { points, addMarkers } = createMap({ width: 150, height: 75 })
186
82
 
187
83
  const markers = addMarkers<{ visited: boolean }>([
188
84
  { lat: 40.7128, lng: -74.006, size: 0.5, visited: true },
189
85
  { lat: 51.5074, lng: -0.1278, size: 0.5, visited: false },
190
- ]);
86
+ ])
191
87
 
192
88
  return (
193
- <svg viewBox="0 0 150 75" style={{ width: "100%", height: "100%" }}>
89
+ <svg viewBox="0 0 150 75" style={{ width: '100%', height: '100%' }}>
194
90
  {points.map((point) => (
195
91
  <circle
196
92
  cx={point.x}
@@ -205,15 +101,15 @@ export const DottedMap = () => {
205
101
  cx={marker.x}
206
102
  cy={marker.y}
207
103
  r={marker.size ?? 0.25}
208
- fill={marker.visited ? "#4A0404" : "#999"}
104
+ fill={marker.visited ? '#4A0404' : '#999'}
209
105
  key={`${marker.x}-${marker.y}`}
210
106
  />
211
107
  ))}
212
108
  </svg>
213
- );
214
- };
109
+ )
110
+ }
215
111
  ```
216
112
 
217
113
  ## Caching
218
114
 
219
- Point calculations are cached automatically. Calling `createMap` with identical options returns the same points without recalculating. The cache invalidates when any option changes (dimensions, countries, region, radius, or sample count).
115
+ Point calculations are cached automatically.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "piri",
3
- "version": "1.1.1",
3
+ "version": "1.1.2",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {
@@ -11,17 +11,8 @@
11
11
  },
12
12
  "main": "./dist/index.cjs",
13
13
  "types": "./dist/index.d.ts",
14
- "files": [
15
- "dist"
16
- ],
17
- "keywords": [
18
- "map",
19
- "dotted map",
20
- "svg map",
21
- "svg",
22
- "stylized map",
23
- "piri"
24
- ],
14
+ "files": ["dist"],
15
+ "keywords": ["map", "dotted map", "svg map", "svg", "stylized map", "piri"],
25
16
  "scripts": {
26
17
  "build": "tsup",
27
18
  "dev": "tsup --watch",