feat(shared): keywords for MapLibre's template and theme styles

The maplibre_style slot gains two values that name no style document:
trek:template, which has MapLibre draw the user's map template the way
Leaflet does, and trek:ofm-auto, OpenFreeMap Liberty in the light theme
and OpenFreeMap Dark in the dark one. No stored row holds either, so no
saved setting changes its meaning, and a client that predates them reads
them as a foreign style and draws the default.

mapConnectHostAllows reads a host-source entry the way the browser reads
the policy (a wildcard never covers its apex, no port means the default
one), so the client can ask whether a GL map may fetch a tile before it
tries.
This commit is contained in:
Maurice
2026-11-30 15:00:09 +01:00
parent 06cd140bd3
commit dc008ad7a5
4 changed files with 70 additions and 2 deletions
+15
View File
@@ -66,6 +66,21 @@ export function parseMapConnectHosts(raw: string | undefined): { hosts: string[]
return { hosts: [...hosts], invalid };
}
/**
* Whether an https URL's host (`host` or `host:port`, as `URL.host` spells it)
* falls under one entry of the grammar above, read the way a CSP host-source
* reads it: a wildcard covers every subdomain but never the apex, and an entry
* without a port covers only the default one. Lets the client ask the same
* question of a tile URL that the browser will ask of the policy.
*/
export function mapConnectHostAllows(entry: string, urlHost: string): boolean {
const [entryHost = '', entryPort = ''] = entry.toLowerCase().split(':');
const [host = '', port = ''] = urlHost.toLowerCase().split(':');
if (entryPort !== (port === '443' ? '' : port)) return false;
if (entryHost.startsWith('*.')) return host.endsWith(entryHost.slice(1));
return host === entryHost;
}
/** One entry of the list, as the app config carries it. */
export const mapConnectHostSchema = z.string().refine(isMapConnectHost, {
message: 'Expected a host name such as tiles.example.com, *.tiles.example.com or tiles.example.com:8443',