feat: Initial prototype

This commit is contained in:
abdus committed 2026-10-10 12:51:33 +02:00
commit 819f6a61cd
327 files changed
+252446

No files matched your search

+48
View File
@@ -0,0 +1,48 @@
// Bump VERSION whenever a shell file changes. New versions wait for approval.
const VERSION = 'v6';
const BASE = self.registration.scope;
const PREFIX = `ascii-pwa-${encodeURIComponent(BASE)}-`;
const CACHE = `${PREFIX}${VERSION}`;
const SHELL = [
'./', './index.html', './style.css', './appearance.js', './app.js',
'./renderer.js', './bitmap.js', './font-catalog.js', './vendor/figlet.js',
'./translations.js', './pwa.js', './manifest.webmanifest',
'./fonts/IBMPlexMono-Regular.subset.woff2',
'./fonts/IBMPlexMono-Bold.subset.woff2',
'./icons/ascii.svg', './icons/icon-192.png', './icons/icon-512.png',
'./icons/apple-touch-icon.png', './icons/maskable.svg',
'./icons/maskable-192.png', './icons/maskable-512.png',
].map(path => new URL(path, BASE).href);
const HOME = new URL('./', BASE).href;
const ROUTES = new Set([new URL(HOME).pathname, new URL('./index.html', BASE).pathname]);
self.addEventListener('install', event => {
event.waitUntil(caches.open(CACHE).then(cache => cache.addAll(SHELL)));
});
self.addEventListener('message', event => {
if (event.data === 'ACTIVATE_UPDATE') self.skipWaiting();
});
self.addEventListener('activate', event => {
event.waitUntil((async () => {
const names = await caches.keys();
await Promise.all(names.filter(name => name.startsWith(PREFIX) && name !== CACHE)
.map(name => caches.delete(name)));
await self.clients.claim();
})());
});
self.addEventListener('fetch', event => {
const {request} = event;
const url = new URL(request.url);
if (request.method !== 'GET' || url.origin !== self.location.origin) return;
if (request.mode === 'navigate') {
if (!ROUTES.has(url.pathname)) return;
event.respondWith(caches.open(CACHE).then(async cache =>
(await cache.match(HOME)) || fetch(request)));
} else {
url.search = '';
url.hash = '';
if (!SHELL.includes(url.href)) return;
event.respondWith(caches.open(CACHE).then(async cache =>
(await cache.match(url.href)) || fetch(request)));
}
});