Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,19 @@ the `social` shortcode of 1.7.0 with a callout. A patch release only fixes.
`lines` keeps its per-line prefix colours. Conflicting inputs and missing,
blank or non-string source warn and drop the visual. Print shows the source
as plain text. Custom shells get the dark syntax palette in the Landing stylesheet.
- **Protomaps basemaps for `map` fences.** `params.map.protomaps.url` takes an
https:// PMTiles archive (a path ending in `.pmtiles`) or a `{z}/{x}/{y}`
vector-tile template such as the Protomaps API, in place of raster `tiles`.
The vendored protomaps-leaflet `5.1.0` draws it on the existing Leaflet map,
so markers, popups, keyboard use and click-to-load stay as they are; it loads
after Leaflet and only on sites that configure it. `flavor` and
`dark_flavor` (light, dark, white, grayscale, black; default light and
dark) follow the color mode, `lang` picks label names and defaults to the
site language (Chinese as `zh-Hans` or `zh-Hant`), and `max_data_zoom`
(default 15) is the deepest zoom the tiles hold. `attribution` is still
required. A basemap whose first tiles all fail hides the canvas and keeps
the place list, as raster tiles do; setting both `tiles` and
`protomaps.url` warns and uses Protomaps.

## [1.8.0] — 2026-11-28

Expand Down
24 changes: 21 additions & 3 deletions VENDOR.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"schema": 1,
"generated": "2026-11-28",
"generated": "2026-11-29",
"hash": "sha256",
"trees": [
{
"path": "assets/third_party",
"files": 131,
"sha256": "bebaa6c3d82905d89f831220cf967ec90477875a4b789faf2d42f56c9433bdc0"
"files": 133,
"sha256": "1cfb993689d3569a48d26cd0cd1b9584a9c9867ac47bd4de6c9431cee786c7d5"
},
{
"path": "static/webfonts",
Expand Down Expand Up @@ -615,6 +615,24 @@
}
],
"integrity": "sha512-nxS1ynzJOmOlHp+iL3FyWqK89GtNL8U8rvlMOsQdTTssxZwCXh8N2NB3GDQOL+YR3XnWyZAxwQixURb+FA74PA=="
},
{
"name": "protomaps-leaflet",
"version": "5.1.0",
"source": "https://registry.npmjs.org/protomaps-leaflet/-/protomaps-leaflet-5.1.0.tgz",
"integrity": "sha512-N0YY1Gbw5nZ9n8VUOvwHKm/w3zhTTuaZEeMZl8doHemeM4ujGPp2otI6t4Sgqrz8iM4svx2rpG1Q17rHkOWSaA==",
"license": "BSD-3-Clause AND ISC AND MIT",
"licenseFiles": [
"assets/third_party/protomaps-leaflet/LICENSES.txt"
],
"build": "bin/vendor/build.mjs",
"lockfile": "bin/vendor/package-lock.json",
"artifacts": [
{
"path": "assets/third_party/protomaps-leaflet/protomaps-leaflet.min.js",
"sha256": "bec647d021df05b448019e515fb823aad781898d1196777f4200add90955ec16"
}
]
}
]
}
110 changes: 87 additions & 23 deletions assets/js/content-components.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
if (!component || component.begun) return;
component.begun = true;
if (observer) observer.unobserve(root);
loadEngine(component.engine, component.ready).then(
(component.load ? component.load() : loadEngine(component.engine, component.ready)).then(
function () {
unmounted.delete(root);
component.mount(root);
Expand Down Expand Up @@ -395,10 +395,12 @@
}

// The hosts a click-to-load map may contact: light and dark tiles alike, with
// `{s}` shown as `*` because the request rotates through every subdomain.
// `{s}` shown as `*` because the request rotates through every subdomain,
// or the one host a Protomaps basemap reads its vector tiles from.
function tileHosts(site) {
var hosts = [];
[site && site.tiles, site && site.darkTiles].forEach(function (template) {
var protomaps = site && site.protomaps;
[site && site.tiles, site && site.darkTiles, protomaps && protomaps.url].forEach(function (template) {
if (!template) return;
try {
var host = new URL(template.replace(/\{s\}/g, '*')).host.replace(/%2a/gi, '*');
Expand Down Expand Up @@ -470,11 +472,16 @@
var data = configOf(root, '[data-td-map-source]');
var site = configOf(document, '[data-td-map-config]');
var canvas = root.querySelector('[data-td-map-canvas]');
if (!L || !data || !site || !site.tiles || !canvas) return;
// A Protomaps basemap is one vector source drawn in a light and a dark
// flavor; protomaps-leaflet renders it on Leaflet's canvas grid.
var vector = site && site.protomaps && site.protomaps.url ? site.protomaps : null;
if (vector && !(window.protomapsL && typeof window.protomapsL.leafletLayer === 'function')) return;
if (!L || !data || !site || !(site.tiles || vector) || !canvas) return;
var places = Array.isArray(data.places) ? data.places : [];
if (!places.length) return;
canvas.hidden = false;
if (!site.darkTiles && typeof canvas.setAttribute === 'function') {
var hasDark = vector ? !!vector.darkFlavor : !!site.darkTiles;
if (!hasDark && typeof canvas.setAttribute === 'function') {
canvas.setAttribute('data-td-map-light-tiles', '');
}
var reduced = !!(
Expand Down Expand Up @@ -543,34 +550,78 @@
if (typeof map.remove === 'function') map.remove();
}, 0);
}
// protomaps-leaflet logs a failed vector tile and still paints the
// flavor's background, so Leaflet sees no tile error. Count the source's
// answers instead; an aborted request (a zoom moved on) is neither.
function countVectorTiles(current, counts) {
var views = current && current.views;
if (!views || typeof views.forEach !== 'function') return;
views.forEach(function (view) {
var get = view && view.getDisplayTile;
if (typeof get !== 'function') return;
view.getDisplayTile = function () {
return get.apply(view, arguments).then(
function (value) {
counts.loaded += 1;
return value;
},
function (error) {
if (!error || error.name !== 'AbortError') counts.failed += 1;
throw error;
},
);
};
});
}
function tiles() {
if (hidden) return;
var dark = currentTheme() === 'dark' && !!site.darkTiles && !darkFailed;
var nextUrl = dark ? site.darkTiles : site.tiles;
var dark = currentTheme() === 'dark' && hasDark && !darkFailed;
var nextUrl = vector
? dark
? vector.darkFlavor
: vector.flavor || 'light'
: dark
? site.darkTiles
: site.tiles;
if (layer && nextUrl === currentUrl) return;
if (layer) map.removeLayer(layer);
currentUrl = nextUrl;
var tileOpts = { maxZoom: site.maxZoom || 19 };
if (site.subdomains) tileOpts.subdomains = site.subdomains;
var loaded = 0;
var failed = 0;
var current = L.tileLayer(nextUrl, tileOpts);
var counts = { loaded: 0, failed: 0 };
var current;
if (vector) {
current = window.protomapsL.leafletLayer({
url: vector.url,
flavor: nextUrl,
lang: vector.lang || 'en',
maxDataZoom: vector.maxDataZoom || 15,
maxZoom: site.maxZoom || 19,
// The map's own control carries the site's attribution.
attribution: '',
});
countVectorTiles(current, counts);
} else {
var tileOpts = { maxZoom: site.maxZoom || 19 };
if (site.subdomains) tileOpts.subdomains = site.subdomains;
current = L.tileLayer(nextUrl, tileOpts);
}
layer = current;
if (typeof current.on === 'function') {
current.on('tileload', function () {
loaded += 1;
});
current.on('tileerror', function () {
failed += 1;
});
if (!vector) {
current.on('tileload', function () {
counts.loaded += 1;
});
current.on('tileerror', function () {
counts.failed += 1;
});
}
current.on('load', function () {
if (!hidden && current === layer && loaded === 0 && failed > 0) layerFailed(dark);
if (!hidden && current === layer && counts.loaded === 0 && counts.failed > 0) layerFailed(dark);
});
}
current.addTo(map);
}
tiles();
if (site.darkTiles) watchTheme(tiles);
if (hasDark) watchTheme(tiles);
var points = [];
var markers = [];
places.forEach(function (place, index) {
Expand Down Expand Up @@ -766,14 +817,27 @@
var mapSite = configOf(document, '[data-td-map-config]');
var mapClickOnly = !!(mapSite && mapSite.loading === 'click');
var mapHost = mapClickOnly ? tileHosts(mapSite).join(', ') : '';
var mapVector = !!(mapSite && mapSite.protomaps && mapSite.protomaps.url);
function leafletReady() {
return !!window.L;
}
function protomapsReady() {
return !!window.protomapsL;
}
document.querySelectorAll('[data-td-map]').forEach(function (root) {
var component = {
engine: 'leaflet',
ready: function () {
return !!window.L;
},
ready: leafletReady,
mount: initMap,
};
// protomaps-leaflet extends Leaflet's grid layer, so it loads second.
if (mapVector) {
component.load = function () {
return loadEngine('leaflet', leafletReady).then(function () {
return loadEngine('protomaps', protomapsReady);
});
};
}
if (mapClickOnly) {
var canvas = root.querySelector('[data-td-map-canvas]');
if (!canvas || typeof root.insertBefore !== 'function') return;
Expand Down
Loading