Add progressive web app companion for cross-platform access

Vite + TypeScript PWA that mirrors the Android app's core features:
- Pre-processed shelter data (build-time UTM33N→WGS84 conversion)
- Leaflet map with shelter markers, user location, and offline tiles
- Canvas compass arrow (ported from DirectionArrowView.kt)
- IndexedDB shelter cache with 7-day staleness check
- Service worker with CacheFirst tiles and precached app shell
- i18n for en, nb, nn (ported from Android strings.xml)
- iOS/Android compass handling with low-pass filter
- Respects user map interaction (no auto-snap on pan/zoom)
- Build revision cache-breaker for reliable SW updates

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Ole-Morten Duesund 2026-03-08 17:41:38 +01:00
commit e8428de775
12051 changed files with 1799735 additions and 0 deletions

49
pwa/src/i18n/en.ts Normal file
View file

@ -0,0 +1,49 @@
/** English strings — default locale. Ported from res/values/strings.xml. */
export const en: Record<string, string> = {
app_name: 'Tilfluktsrom',
// Status
status_ready: 'Ready',
status_loading: 'Loading shelter data\u2026',
status_updating: 'Updating\u2026',
status_offline: 'Offline mode',
status_shelters_loaded: '%d shelters loaded',
status_no_location: 'Waiting for GPS\u2026',
status_caching_map: 'Caching map for offline use\u2026',
// Loading
loading_shelters: 'Downloading shelter data\u2026',
loading_map: 'Caching map tiles\u2026',
loading_map_explanation:
'Preparing offline map.\nThe map will scroll briefly to cache your surroundings.',
loading_first_time: 'Setting up for first use\u2026',
// Shelter info
shelter_capacity: '%d places',
shelter_room_nr: 'Room %d',
nearest_shelter: 'Nearest shelter',
no_shelters: 'No shelter data available',
// Actions
action_refresh: 'Refresh data',
action_toggle_view: 'Toggle map/compass view',
action_skip: 'Skip',
action_cache_ok: 'Cache map',
action_cache_now: 'Cache now',
warning_no_map_cache: 'No offline map cached. Map requires internet.',
// Permissions
permission_location_title: 'Location permission required',
permission_location_message:
'This app needs your location to find the nearest shelter. Please grant location access.',
permission_denied:
'Location permission denied. The app cannot find nearby shelters without it.',
// Errors
error_download_failed:
'Could not download shelter data. Check your internet connection.',
error_no_data_offline:
'No cached data available. Connect to the internet to download shelter data.',
update_success: 'Shelter data updated',
update_failed: 'Update failed \u2014 using cached data',
};

49
pwa/src/i18n/i18n.ts Normal file
View file

@ -0,0 +1,49 @@
/**
* Minimal i18n system: detects locale from navigator.languages,
* provides t(key, ...args) for string lookup with %d/%s substitution.
*/
import { en } from './en';
import { nb } from './nb';
import { nn } from './nn';
const locales: Record<string, Record<string, string>> = { en, nb, nn };
let currentLocale = 'en';
/** Detect and set locale from browser preferences. */
export function initLocale(): void {
const langs = navigator.languages ?? [navigator.language];
for (const lang of langs) {
const code = lang.toLowerCase().split('-')[0];
if (code in locales) {
currentLocale = code;
return;
}
// nb and nn both start with "n" — also match "no" as Bokmål
if (code === 'no') {
currentLocale = 'nb';
return;
}
}
}
/** Get current locale code. */
export function getLocale(): string {
return currentLocale;
}
/**
* Translate a string key, substituting %d and %s with provided arguments.
* Falls back to English, then to the raw key.
*/
export function t(key: string, ...args: (string | number)[]): string {
let str = locales[currentLocale]?.[key] ?? locales.en[key] ?? key;
// Replace %d and %s placeholders sequentially
for (const arg of args) {
str = str.replace(/%[ds]/, String(arg));
}
return str;
}

44
pwa/src/i18n/nb.ts Normal file
View file

@ -0,0 +1,44 @@
/** Norwegian Bokm\u00e5l strings. Ported from res/values-nb/strings.xml. */
export const nb: Record<string, string> = {
app_name: 'Tilfluktsrom',
status_ready: 'Klar',
status_loading: 'Laster tilfluktsromdata\u2026',
status_updating: 'Oppdaterer\u2026',
status_offline: 'Frakoblet modus',
status_shelters_loaded: '%d tilfluktsrom lastet',
status_no_location: 'Venter p\u00e5 GPS\u2026',
status_caching_map: 'Lagrer kart for frakoblet bruk\u2026',
loading_shelters: 'Laster ned tilfluktsromdata\u2026',
loading_map: 'Lagrer kartfliser\u2026',
loading_map_explanation:
'Forbereder frakoblet kart.\nKartet vil rulle kort for \u00e5 lagre omgivelsene dine.',
loading_first_time: 'Gj\u00f8r klar for f\u00f8rste gangs bruk\u2026',
shelter_capacity: '%d plasser',
shelter_room_nr: 'Rom %d',
nearest_shelter: 'N\u00e6rmeste tilfluktsrom',
no_shelters: 'Ingen tilfluktsromdata tilgjengelig',
action_refresh: 'Oppdater data',
action_toggle_view: 'Bytt mellom kart og kompassvisning',
action_skip: 'Hopp over',
action_cache_ok: 'Lagre kart',
action_cache_now: 'Lagre n\u00e5',
warning_no_map_cache:
'Ingen frakoblet kart lagret. Kartet krever internett.',
permission_location_title: 'Posisjonstillatelse kreves',
permission_location_message:
'Denne appen trenger din posisjon for \u00e5 finne n\u00e6rmeste tilfluktsrom. Vennligst gi tilgang til posisjon.',
permission_denied:
'Posisjonstillatelse avsl\u00e5tt. Appen kan ikke finne tilfluktsrom i n\u00e6rheten uten den.',
error_download_failed:
'Kunne ikke laste ned tilfluktsromdata. Sjekk internettforbindelsen.',
error_no_data_offline:
'Ingen lagrede data tilgjengelig. Koble til internett for \u00e5 laste ned tilfluktsromdata.',
update_success: 'Tilfluktsromdata oppdatert',
update_failed: 'Oppdatering mislyktes \u2014 bruker lagrede data',
};

44
pwa/src/i18n/nn.ts Normal file
View file

@ -0,0 +1,44 @@
/** Norwegian Nynorsk strings. Ported from res/values-nn/strings.xml. */
export const nn: Record<string, string> = {
app_name: 'Tilfluktsrom',
status_ready: 'Klar',
status_loading: 'Lastar tilfluktsromdata\u2026',
status_updating: 'Oppdaterer\u2026',
status_offline: 'Fr\u00e5kopla modus',
status_shelters_loaded: '%d tilfluktsrom lasta',
status_no_location: 'Ventar p\u00e5 GPS\u2026',
status_caching_map: 'Lagrar kart for fr\u00e5kopla bruk\u2026',
loading_shelters: 'Lastar ned tilfluktsromdata\u2026',
loading_map: 'Lagrar kartfliser\u2026',
loading_map_explanation:
'F\u00f8rebur fr\u00e5kopla kart.\nKartet vil rulle kort for \u00e5 lagre omgjevnadene dine.',
loading_first_time: 'Gjer klar for fyrste gongs bruk\u2026',
shelter_capacity: '%d plassar',
shelter_room_nr: 'Rom %d',
nearest_shelter: 'N\u00e6raste tilfluktsrom',
no_shelters: 'Ingen tilfluktsromdata tilgjengeleg',
action_refresh: 'Oppdater data',
action_toggle_view: 'Byt mellom kart og kompassvising',
action_skip: 'Hopp over',
action_cache_ok: 'Lagre kart',
action_cache_now: 'Lagre no',
warning_no_map_cache:
'Ingen fr\u00e5kopla kart lagra. Kartet krev internett.',
permission_location_title: 'Posisjonsløyve krevst',
permission_location_message:
'Denne appen treng posisjonen din for \u00e5 finne n\u00e6raste tilfluktsrom. Ver venleg og gje tilgang til posisjon.',
permission_denied:
'Posisjonsløyve avsl\u00e5tt. Appen kan ikkje finne tilfluktsrom i n\u00e6rleiken utan det.',
error_download_failed:
'Kunne ikkje laste ned tilfluktsromdata. Sjekk internettilkoplinga.',
error_no_data_offline:
'Ingen lagra data tilgjengeleg. Kopla til internett for \u00e5 laste ned tilfluktsromdata.',
update_success: 'Tilfluktsromdata oppdatert',
update_failed: 'Oppdatering mislukkast \u2014 brukar lagra data',
};