@map-jr/styles 0.0.0-stage → 1.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.
package/CHANGELOG.md ADDED
@@ -0,0 +1,14 @@
1
+ # Changelog
2
+
3
+ Each version has one entry. The styles are served at `https://styles.map-jr.org/<major>/`, so a version that breaks a
4
+ map increases the first number, and its entry starts with a section "Breaking changes". Every other version
5
+ increases the second number. The third number is always 0. See [Release](README.md#release).
6
+
7
+ ## 1.0.0 (2026-11-18)
8
+
9
+ The first release at `https://styles.map-jr.org/1/`.
10
+
11
+ - The styles Elevation · color, Elevation · radar, and the five styles of OpenFreeMap, each as one JSON file without
12
+ white space, with its icons and road shields inside it.
13
+ - The two elevation styles draw their labels with the fonts of the system and load no glyph files. They need a
14
+ map-jr-gl with commit `bd4d4ea`. MapLibre GL JS does not load them.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Sam Margulies
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/NOTICE.md ADDED
@@ -0,0 +1,16 @@
1
+ # Third-party material
2
+
3
+ The MIT licence in `LICENSE` covers what is written for this repository: the build (`build.mjs`, `lib/`, `scripts/`,
4
+ `test/`), the style modules (`styles/*.mjs`) and the shield templates (`shields/*.svg`, `shields/shields.mjs`).
5
+ The material below comes from other projects and keeps its own terms. `dist/` is built from both.
6
+
7
+ | Material | From | Terms |
8
+ |---|---|---|
9
+ | `icons/upstream/*.svg` | [openfreemap-styles](https://github.com/hyperknot/openfreemap-styles), the liberty and bright icon sets | `icons/upstream/LICENSE-liberty.md`, `icons/upstream/LICENSE-bright.md` |
10
+ | `icons/extra/*.svg` | Glyphs of [Maki](https://github.com/mapbox/maki), on the disc of the sprite icons | CC0 1.0: `icons/extra/LICENSE-maki.txt` |
11
+ | `styles/src/openfreemap/*.json` | [openfreemap-styles](https://github.com/hyperknot/openfreemap-styles), at the commit in `styles/src/openfreemap/COMMIT` | BSD 3-Clause for the style code and CC-BY 4.0 for the design: `styles/src/openfreemap/LICENSE*.md` |
12
+ | `styles/src/elevation-color.json` | Based on [OSM Liberty](https://github.com/maputnik/osm-liberty), with the tiles and the sprite of OpenFreeMap | BSD 3-Clause for the style code and CC-BY 4.0 for the design, as `styles/src/openfreemap/LICENSE-liberty.md` |
13
+ | `styles/src/elevation-radar.json` | Based on a style of the OpenMapTiles family; the closest is [MapTiler Basic](https://github.com/openmaptiles/maptiler-basic-gl-style) | BSD 3-Clause for the style code and CC-BY 4.0 for the design |
14
+ | `shields/networks.json` | Made from the shield definitions of [OSM Americana](https://github.com/osm-americana/openstreetmap-americana) (`https://americanamap.org/shields.json`) | CC0 1.0 |
15
+
16
+ Map data shown with the styles: OpenFreeMap, © OpenMapTiles, data from OpenStreetMap; terrain © Mapterhorn.
package/README.md CHANGED
@@ -1,3 +1,242 @@
1
- # Temporary Holding Version
1
+ # map-jr-styles
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Map styles for [map-jr-gl](https://github.com/map-jr/map-jr-gl) that carry their own icons and road shields as SVG
4
+ templates, in place of a sprite sheet. Each style has a light and a dark branch, chosen by the global state
5
+ property `color-scheme`.
6
+
7
+ | Style | File | What it is |
8
+ |---|---|---|
9
+ | Elevation · color | `dist/styles/elevation-color.json` | A full-color terrain map. Dark is the same map under bright moonlight. |
10
+ | Elevation · radar | `dist/styles/elevation-radar.json` | A neutral base for an overlay (a choropleth, snowfall), with relief and peaks for context. |
11
+ | OpenFreeMap | `dist/styles/openfreemap-{bright,dark,fiord,liberty,positron}.json` | The styles of OpenFreeMap as they are, with the images of the sprite inside the style. |
12
+
13
+ Each style also has a `.min.json` without white space. The styles need a map-jr-gl build that reads
14
+ `metadata["map-jr:images"]` and `params` of the `image` expression. MapLibre GL JS draws them without icons.
15
+
16
+ The two elevation styles have no `glyphs`: map-jr-gl draws their labels with the fonts of the browser, and makes no
17
+ requests for fonts. Each `text-font` is a stack of the fonts of the system, such as
18
+ `["system-ui Semibold", "Segoe UI Semibold", "Roboto Medium", "sans-serif"]`: SF Pro on Apple systems, Segoe UI on
19
+ Windows, Roboto on Android. The first name gives the weight and the style (Regular, Semibold, Bold, Italic, Semibold
20
+ Italic). This needs a map-jr-gl with commit `bd4d4ea` (a `text-font` stack as a CSS family list, with `system-ui`
21
+ unquoted); an older one draws the labels in the `fontFamily` of the map. To give every reader the same font, pass the
22
+ font files in the `fonts` option of map-jr-gl. MapLibre GL JS does not load a style
23
+ with text and no `glyphs`: add a `glyphs` URL to use these two styles there. The OpenFreeMap styles keep the glyphs
24
+ of OpenFreeMap.
25
+
26
+ ## Use
27
+
28
+ The styles are at `https://styles.map-jr.org`, by major version:
29
+
30
+ ```js
31
+ createMap('map', {style: 'https://styles.map-jr.org/1/elevation-color.json'});
32
+ ```
33
+
34
+ | Path | What it gives | Cached |
35
+ |---|---|---|
36
+ | `/1/<name>.json` | The latest release of version 1, without white space. It takes each change that does not break a map. | A day in the browser, then up to a week more while it is fetched again in the background; 5 minutes at the edge |
37
+ | `/1/version.json` | `{version, commit}` of the folder | As its folder |
38
+
39
+ A new major version (`/2/`) breaks a map: a layer id is renamed or removed, a global state property changes, or the
40
+ styles need a newer map-jr-gl. Every other release is a new minor version (`1.1`), and `/1/` moves to it. To keep
41
+ one release as it is, host the zip of its GitHub release.
42
+
43
+ ### From npm
44
+
45
+ The package [`@map-jr/styles`](https://www.npmjs.com/package/@map-jr/styles) has the same styles, by the same names:
46
+
47
+ ```bash
48
+ pnpm add @map-jr/styles
49
+ ```
50
+
51
+ ```js
52
+ import style from '@map-jr/styles/elevation-color.json' with {type: 'json'};
53
+
54
+ createMap('map', {style});
55
+ ```
56
+
57
+ A bundler (Vite, webpack, esbuild) takes the import as it is; Node.js needs `with {type: 'json'}`. A range such as
58
+ `^1.0.0` takes each release that does not break a map, as `/1/` does. The CDNs of npm serve the package too:
59
+ `https://cdn.jsdelivr.net/npm/@map-jr/styles@1/elevation-color.json`. The package has only the styles without white
60
+ space (`dist/styles/*.min.json`), the changelog, and the licences of the material in `NOTICE.md`.
61
+
62
+ ## Release
63
+
64
+ A release is a pull request that changes `"version"` in `package.json` and adds the section of that version to
65
+ [CHANGELOG.md](CHANGELOG.md). Merging it releases the version: the workflow `Release` uploads the styles to
66
+ `/<major>/`, publishes `@map-jr/styles` to npm, pushes the tag `v<version>`, and makes the release on GitHub with the
67
+ section as its text and `dist/` as a zip. Nobody pushes a tag or makes a release by hand. A release replaces the styles of its major version: `1.3.0` writes
68
+ `/1/`, and `2.0.0` writes `/2/` and leaves `/1/` as it was.
69
+
70
+ 1. **Check `main`.** The workflow `build` is green for the commit to release.
71
+ 2. **Choose the version.** The third number is always 0.
72
+ - A change that does not break a map (a color, a new layer, a fix) increases the second number: `1.2.0` → `1.3.0`.
73
+ - A change that breaks a map (a layer id renamed or removed, a global state property changed, a newer map-jr-gl
74
+ needed) increases the first number: `1.3.0` → `2.0.0`. Its section in the changelog starts with "Breaking
75
+ changes", which says what stopped working and what to do instead.
76
+ 3. **Open the pull request of the release.** On a branch from `main`, set `"version"` in `package.json`, and add
77
+ `## 1.3.0 (2026-11-20)` at the top of `CHANGELOG.md`, with what changed since the last release. Then:
78
+
79
+ ```bash
80
+ pnpm run build && pnpm run check && pnpm test && pnpm run test:package
81
+ ```
82
+
83
+ 4. **Merge it** when CI passes, and follow the workflow `Release` in the Actions tab.
84
+ 5. **Check the release:**
85
+
86
+ ```bash
87
+ curl https://styles.map-jr.org/1/version.json
88
+ ```
89
+
90
+ ```bash
91
+ npm view @map-jr/styles@1.3.0 version
92
+ ```
93
+
94
+ The first gives `{"version":"1.3","commit":"…"}`, with the commit of the merge, and the second `1.3.0`. The edge has the new styles within 5
95
+ minutes; a browser that has the last release gets the new one within a day.
96
+
97
+ A section whose heading says `(unreleased)` is not released: the workflow does nothing for it. The workflow stops,
98
+ and uploads nothing, when the changelog has no section for the version, when `/<major>/` has the same release from
99
+ another commit or a newer release, or when npm has the version and the tag `v<version>` does not exist. A run that stopped after the upload can be run again from the Actions tab
100
+ (**Run workflow** on `main`): it does only what is left. To undo a release, release the earlier state as a newer
101
+ version. `node scripts/publish.mjs --dry-run` lists the files that a release uploads, without uploading them.
102
+
103
+ It needs, in the repository:
104
+
105
+ | Name | Kind | What it is |
106
+ |---|---|---|
107
+ | `CLOUDFLARE_ACCOUNT_ID` | Variable | The Cloudflare account of the bucket |
108
+ | `R2_BUCKET` | Variable | The name of the bucket |
109
+ | `R2_API_TOKEN` | Secret | The token value of an R2 API token with Object Read & Write on the bucket only |
110
+
111
+ The repository has no token of npm. npm trusts the workflow `Release` by its file name (`release.yml`), as a trusted
112
+ publisher in the settings of the package on npmjs.com, and adds a provenance statement to each version. Renaming the
113
+ file needs the same change there.
114
+
115
+ The script makes the S3 keys of R2 from the token, as Cloudflare documents them: the key ID is the id of the token,
116
+ and the secret is the SHA-256 of its value.
117
+
118
+ Cloudflare does not cache `.json` by default. A Cache Rule on the zone makes it: for the hostname
119
+ `styles.map-jr.org`, **Eligible for cache**, with the edge TTL from the `Cache-Control` header of the origin. With
120
+ the short edge TTL and `stale-while-revalidate`, a release reaches the edge in minutes with no purge, and a reader
121
+ does not wait while a file is fetched again.
122
+
123
+ ## Build
124
+
125
+ ```bash
126
+ pnpm install
127
+ ```
128
+
129
+ ```bash
130
+ pnpm run build
131
+ ```
132
+
133
+ `dist/` is committed, so that a style has a URL. `pnpm run check` fails when `dist/` is not what the sources give;
134
+ CI runs it, and `pnpm test`.
135
+
136
+ ## Editing a style with Maputnik
137
+
138
+ An edit in Maputnik reaches the repository as a change to the sources, because the build writes `dist/` from them
139
+ and overwrites an edit made there.
140
+
141
+ 1. Open the built style in the Maputnik of map-jr-gl:
142
+ `https://map-jr.github.io/maputnik/?style=https://styles.map-jr.org/@main/elevation-color.json`.
143
+ 2. Edit it, and save it with **Save** (a file such as `elevation-color.json`).
144
+ 3. Apply it to the sources, and build:
145
+
146
+ ```bash
147
+ ppnpm run apply-edit ~/Downloads/elevation-color.json
148
+ pnpm run build
149
+ ```
150
+
151
+ The command builds the style from the sources in memory and compares it with the saved style, layer by layer and
152
+ property by property. It finds the style by the file name, or by the layers when the name is not the name of a
153
+ style. A second argument gives the name: `ppnpm run apply-edit saved.json elevation-radar`. For each difference it
154
+ tries the places that the value can come from, builds again, and keeps a change only when it removes differences and
155
+ adds none.
156
+
157
+ | Edit | Where it goes |
158
+ |---|---|
159
+ | A value of a layer that the source style has: a light color, a number, a filter, a layout property | `styles/src/<name>.json` |
160
+ | A new layer, a removed layer, the order of the layers | `styles/src/<name>.json` |
161
+ | The dark value of a `case` on `color-scheme` | `PAIRS` in `styles/<name>.mjs`, by the `dark\|light` pair of the source. When other layers share the pair and keep their value, the dark value goes into the source. |
162
+ | The light value of such a `case` | The source, and the pair in `PAIRS` moves to the new light value |
163
+
164
+ The command does not map a value that a module makes: the images and their colors (`useIcons`, `ICON_DARK`), the
165
+ road shields, the peak and name labels, the layers that a module adds (`place_capital`), and a value that a module
166
+ sets (the hillshade colors, the light airport colors). It does not map an edit that changes the length of a filter to
167
+ which a module adds a clause. It lists each of these with its layer and property and writes nothing for it, so that
168
+ you can change the module by hand. At the end it builds from the files again, lists each property that still differs
169
+ from the saved style, and exits with 1 when there is one. It does not edit the OpenFreeMap styles, which are copies
170
+ of their sources.
171
+
172
+ ## How it is made
173
+
174
+ ```
175
+ icons/upstream/*.svg the SVG sources of the OpenFreeMap sprite (ofm_f384), one file for each icon
176
+ icons/extra.json POI classes the sprite has no icon for: new icons from Maki glyphs, and aliases
177
+ icons/extra/*.svg the new icons (pnpm run update-icons)
178
+ icons/custom/*.svg icons drawn for this repository
179
+ shields/*.svg road shield templates, written by hand
180
+ shields/shields.mjs how each shield stretches, and the networks whose look is set by hand
181
+ shields/networks.json the look of each road network, from OSM Americana (pnpm run update-shields)
182
+ styles/src/*.json the source styles, which use the sprite
183
+ styles/*.mjs one module for each style (or family): its dark palette and its fixes
184
+ styles/shared.mjs the dark icon colors and the neutral shield plate
185
+ lib/ the build steps
186
+ ```
187
+
188
+ **Icons.** `lib/icons.mjs` minifies each upstream SVG with SVGO and replaces each color by a slot named for its
189
+ role: `{{color}}` (the glyph), `{{background}}` (the plate behind it) and `{{border}}` (the outline or halo). The
190
+ build writes three files to `dist/icons/`: `icons.min.json` (`{"name": "<svg…>"}`), `icons.template.json` (the same
191
+ with slots) and `icons.defaults.json` (the colors of each icon). An icon whose colors fit no rule stops the build.
192
+
193
+ The tiles have POI classes that the sprite has no icon for. `icons/extra.json` gives 14 of them a new icon, drawn
194
+ from a [Maki](https://github.com/mapbox/maki) glyph in the look of the sprite, and gives 34 more the icon of a
195
+ class that has one (`atm` is `bank`, `yoga` is `sports_centre`). In the styles of this repository an alias costs no
196
+ image: the layer draws it from the image of its target.
197
+
198
+ **Styles.** A style module gets the source style and changes it: `useIcons` puts the templates that the layers use
199
+ into `metadata["map-jr:images"]`, turns each `icon-image` into an `image` expression with the colors as `params`,
200
+ and removes `sprite`. `retune` gives the dark branch of the source style new values, by its `dark|light` pair.
201
+
202
+ **Road shields.** `useShields` gives the shield layer one template for each shape, which stretches around the route
203
+ number with `icon-text-fit`. The shape and the colors come from `route_1_network` of the OpenMapTiles layer
204
+ `transportation_name`. To add a network, add its name to an entry of `NETWORKS` in `shields/shields.mjs`, or add an
205
+ entry. To add a shape, add an SVG with slots to `shields/` and its stretch columns to `SHAPES`.
206
+
207
+ | Shape | Networks |
208
+ |---|---|
209
+ | `us_interstate` | US Interstates |
210
+ | `us_highway` | US Highways |
211
+ | `pill` | US state routes, and the networks Americana draws as a pill or an ellipse |
212
+ | `hex` | German Autobahn, Italian autostrade, and the networks Americana draws as a horizontal hexagon |
213
+ | `rect` | The other networks, with the colors of their signs; a neutral plate for a network that is not listed |
214
+
215
+ The colors and shapes come from the shield definitions of OSM Americana: `pnpm run update-shields` downloads them
216
+ and writes `shields/networks.json`. It keeps the networks of a country, state or province (about 200) and leaves out
217
+ county and city networks. A shield that Americana draws from artwork (most US states, Mexico, Korea) gets the pill or
218
+ the neutral plate here, unless `MANUAL` in `shields/shields.mjs` gives it a look.
219
+
220
+ **Global state.** The two styles of this repository read three properties of the global state of the map:
221
+
222
+ | Property | Values | Effect |
223
+ |---|---|---|
224
+ | `color-scheme` | `light` (default), `dark` | The branch of the style. map-jr-gl sets it from `colorScheme`. |
225
+ | `elevation-unit` | `ft` (default), `m` | The unit of the elevation in peak labels. Set it with `globalState: {'elevation-unit': 'm'}`. |
226
+ | `language` | none (default), or a language code of the tiles such as `de`, `fr`, `ja` | The language of the names, for each feature that has a name in it. Without it, a place with a name in a script other than Latin shows its Latin name and that name, and other names are English. |
227
+
228
+ **OpenFreeMap styles.** `styles/openfreemap.mjs` builds the five styles of OpenFreeMap with `inlineSprite`: the
229
+ images that a layer can ask for go into the style as plain SVG, and the layers are not changed.
230
+
231
+ ## Preview
232
+
233
+ `pnpm run preview` draws each style in light and dark, side by side, at the views of `test/views.json` (a range of
234
+ zoom levels and kinds of place), into `test/shots/`. Set `STATE` to try a global state: `STATE='{"elevation-unit":"m"}' node test/preview.mjs elevation-color chamonix`. It needs Playwright with Chromium, and the `dist/` folder of a
235
+ map-jr-gl build in `test/lib/`. Pass a style and a view to draw one: `node test/preview.mjs elevation-radar rockies`.
236
+
237
+ ## Sources and licences
238
+
239
+ The code and the shield templates of this repository have the MIT licence (`LICENSE`). The icons, the source styles
240
+ and the network table come from OpenFreeMap, OSM Liberty, OpenMapTiles, Maki and OSM Americana and keep their own terms: see
241
+ `NOTICE.md`. The idea of a shape and colors for each route network follows
242
+ [Trailblazer](https://github.com/osm-americana/trailblazer).