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

View file

@ -0,0 +1,60 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Storage</title>
</head>
<body>
<div class="container-fluid py-md-3">
<main id="app">
<h1>List files in storage</h1>
<div class="form-row">
<div class="form-group col-md-6">
<label for="selectlayer">Select layer:</label>
<select class="form-control" id="selectlayer"></select>
</div>
</div>
<p>
Total <span id="storage"></span>
<button class="btn btn-danger" id="remove_tiles">
<i
class="fa fa-trash"
aria-hidden="true"
title="Remove all tiles from all layers"
></i>
All
</button>
<button class="btn btn-warning" id="remove_old_tiles">
<i
class="fa fa-archive"
aria-hidden="true"
title="Remove old osm tiles"
></i>
Old
</button>
</p>
<table class="table table-striped table-sm table-fixed">
<colgroup>
<col style="width: 50px" />
<col />
<col />
<col style="width: 100px" />
</colgroup>
<thead>
<tr>
<th></th>
<th>Source url</th>
<th>Storage key</th>
<th>Bytes</th>
</tr>
</thead>
<tbody id="tileinforows"></tbody>
</table>
</main>
</div>
<script type="module" src="/src/main.ts"></script>
</body>
</html>

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,22 @@
{
"name": "list-storage",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
"preview": "vite preview"
},
"devDependencies": {
"idb": "^8.0.0",
"leaflet": "^1.9.4",
"leaflet.offline": "^3.1.0",
"prettier": "^3.3.3",
"typescript": "~5.6.2",
"vite": "^6.3.5"
},
"dependencies": {
"@fortawesome/fontawesome-free": "^7.1.0"
}
}

View file

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>

After

Width:  |  Height:  |  Size: 1.5 KiB

View file

@ -0,0 +1,70 @@
import './style.css';
import { getStorageInfo, removeTile, truncate } from 'leaflet.offline';
export const urlTemplate = 'https://tile.openstreetmap.org/{z}/{x}/{y}.png';
export const wmtsUrlTemplate =
'https://service.pdok.nl/brt/achtergrondkaart/wmts/v2_0?service=WMTS&request=GetTile&version=1.0.0&tilematrixset=EPSG:3857&layer={layer}&tilematrix={z}&tilerow={y}&tilecol={x}&format=image%2Fpng';
const layerSelector = document.getElementById(
'selectlayer',
) as HTMLSelectElement;
function createLayerOpts() {
const xyzOpt = document.createElement('option');
xyzOpt.value = urlTemplate;
xyzOpt.text = 'osm';
const wmtsOpt = document.createElement('option');
wmtsOpt.value = wmtsUrlTemplate;
wmtsOpt.text = 'wmts api layer';
layerSelector.add(xyzOpt);
layerSelector.add(wmtsOpt);
layerSelector.value = urlTemplate;
}
const createTable = (url: string) =>
getStorageInfo(url).then((r) => {
document.getElementById('storage')!.innerHTML = r.length.toString();
const list = document.getElementById(
'tileinforows',
) as HTMLTableSectionElement;
list.innerHTML = '';
for (let i = 0; i < r.length; i += 1) {
const tileInfo = r[i];
list.insertAdjacentHTML(
'beforeend',
`<tr>
<td>${i}</td>
<td class="text-truncate">${tileInfo.url}</td>
<td class="text-truncate">${r[i].key}</td>
<td>${tileInfo.blob.size}</td>
</tr>`,
);
}
});
createLayerOpts();
createTable(layerSelector.value);
const rmButton = document.getElementById('remove_tiles') as HTMLButtonElement;
rmButton.addEventListener('click', () =>
truncate().then(() => createTable(layerSelector.value)),
);
const rmOldButton = document.getElementById(
'remove_old_tiles',
) as HTMLButtonElement;
rmOldButton.addEventListener('click', async () => {
const tiles = await getStorageInfo(urlTemplate);
const minCreatedAt = new Date().setDate(-30);
await Promise.all(
tiles.map((tile) =>
tile.createdAt < minCreatedAt ? removeTile(tile.key) : Promise.resolve(),
),
);
createTable(layerSelector.value);
});
layerSelector.addEventListener('change', (e) => {
// @ts-ignore
createTable(e.target.value);
});

View file

@ -0,0 +1,40 @@
@import 'leaflet/dist/leaflet.css';
@import '/node_modules/@fortawesome/fontawesome-free/css/all.min.css';
body {
margin: 0;
font-family: sans-serif;
}
#app {
height: 100vh;
max-width: 1200px;
margin: 0 auto;
}
.btn-danger {
--background-color: red;
--foreground-color: white;
}
.btn-warning {
--background-color: orange;
--foreground-color: white;
}
.btn {
border: var(--background-color) 1px solid;
background-color: var(--background-color);
color: var(--foreground-color);
padding: 0.5em;
}
.table-striped {
td {
padding: 0.5em;
}
tr:nth-child(even) {
background-color: #f2f2f2;
}
}

View file

@ -0,0 +1 @@
/// <reference types="vite/client" />

View file

@ -0,0 +1,24 @@
{
"compilerOptions": {
"target": "ES2020",
"useDefineForClassFields": true,
"module": "ESNext",
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"skipLibCheck": true,
/* Bundler mode */
"moduleResolution": "Bundler",
"allowImportingTsExtensions": true,
"isolatedModules": true,
"moduleDetection": "force",
"noEmit": true,
/* Linting */
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true,
"noUncheckedSideEffectImports": true
},
"include": ["src"]
}