// sw.js — GENERATED by build-sw.mjs. Do not edit by hand.
// flove service worker: full-offline precache (104 entries).
const VERSION = "flove-be8eb8ad05";
const BASE = self.registration.scope;
const PRECACHE = ["","../docs/index.html","../docs/paradigms.html",".well-known/assetlinks.json","apple-touch-icon.png","apps/apps-full.html","apps/apps-graph.html","apps/appy/appy-basic.html","apps/appy/appy-mini-full.html","apps/appy/appy-mini.html","apps/appy/appy-qr.js","apps/appy/flove-appy.js","apps/appy/flove-theme.js","apps/appy/flove.css","apps/appy/nety.html","apps/appy/profily.html","apps/appy/wizy.js","apps/bio/diesafe.html","apps/bio/index.html","apps/bio/pracsys.html","apps/bio/sensy.html","apps/bio/varyy.html","apps/blogy/blogy-advanced-css.html","apps/blogy/blogy-advanced-one.html","apps/blogy/blogy-advanced.html","apps/blogy/blogy-basic-css.html","apps/blogy/blogy-mini-css.html","apps/blogy/blogy-normal-css.html","apps/blogy/blogy-super.html","apps/blogy/flove.css","apps/blogy/flove.js","apps/blogy/index.html","apps/blogy/new/labeler/index.html","apps/blogy/new/language/index.html","apps/blogy/new/sound/index.html","apps/blogy/new/wizard/index.html","apps/bubbles.html","apps/economy/crafty.html","apps/economy/dealy/dealy-advanced.html","apps/economy/dealy/dealy-mini.html","apps/economy/dealy/freed.html","apps/economy/dealy/help.html","apps/economy/dealy/index.html","apps/economy/dealy/inventary.html","apps/economy/dealy/new-wizard-help.html","apps/economy/dealy/rewardy.html","apps/economy/dealy/shary.html","apps/economy/dealy/wanty.html","apps/economy/index.html","apps/economy/lowy.html","apps/economy/worthing.html","apps/index.html","apps/metas/goddy.html","apps/metas/index.html","apps/metas/moraly.html","apps/metas/souls.html","apps/metas/willy.html","apps/psicosocial/astry.html","apps/psicosocial/hacky.html","apps/psicosocial/index.html","apps/psicosocial/lovy.html","apps/psicosocial/realy.html","apps/psicosocial/socy.html","apps/puzzy/comby.html","apps/puzzy/confluenty.html","apps/puzzy/dev/sety.html","apps/puzzy/dev/triady.html","apps/puzzy/dev/vizy.html","apps/puzzy/dev/vizy2.html","apps/puzzy/favicon-comby.svg","apps/puzzy/favicon-confluenty.svg","apps/puzzy/favicon-fivy.svg","apps/puzzy/favicon-keys.svg","apps/puzzy/favicon-linky.svg","apps/puzzy/favicon-poly.svg","apps/puzzy/favicon-raty.svg","apps/puzzy/favicon-sety.svg","apps/puzzy/favicon-vizy.svg","apps/puzzy/favicon-vizy2.svg","apps/puzzy/favicon-wisy.svg","apps/puzzy/favicon.svg","apps/puzzy/fivy.html","apps/puzzy/index.html","apps/puzzy/keys/keys-advanced-raw.html","apps/puzzy/keys/keys-advanced.html","apps/puzzy/keys/keys-basic.html","apps/puzzy/keys/keys-mini-css.html","apps/puzzy/linky.html","apps/puzzy/poly.html","apps/puzzy/raty.html","apps/puzzy/wisy.html","apps/trusty/crumbly.html","apps/trusty/daty.html","apps/trusty/evily.html","apps/trusty/index.html","apps/trusty/maty.html","apps/trusty/myfamily.html","apps/trusty/parenty.html","apps/trusty/trusty.html","localhost-intro.html","manifest.webmanifest","routing.json","solo/apps/index.html","start.html"];

self.addEventListener('install', (e) => {
  e.waitUntil((async () => {
    const cache = await caches.open(VERSION);
    // Cache each entry independently so one odd file can't abort the whole install.
    await Promise.allSettled(PRECACHE.map((p) => cache.add(BASE + p)));
    await self.skipWaiting();
  })());
});

self.addEventListener('activate', (e) => {
  e.waitUntil((async () => {
    const keys = await caches.keys();
    await Promise.all(keys.filter((k) => k !== VERSION).map((k) => caches.delete(k)));
    await self.clients.claim();
  })());
});

self.addEventListener('fetch', (e) => {
  const req = e.request;
  if (req.method !== 'GET') return;
  if (new URL(req.url).origin !== location.origin) return;

  const isPage = req.mode === 'navigate' ||
    (req.headers.get('accept') || '').includes('text/html');

  if (isPage) {
    // Pages: NETWORK-FIRST so an online visit always shows the latest content;
    // fall back to cache (then the gate) only when offline. Prevents the
    // "I published but still see the old page" service-worker trap.
    e.respondWith((async () => {
      try {
        const res = await fetch(req);
        if (res && res.ok && res.type === 'basic') {
          const cache = await caches.open(VERSION);
          cache.put(req, res.clone());
        }
        return res;
      } catch (err) {
        const cached = await caches.match(req, { ignoreSearch: true });
        if (cached) return cached;
        const gate = await caches.match(BASE + 'start.html');
        if (gate) return gate;
        throw err;
      }
    })());
    return;
  }

  // Assets (css/js/img/…): CACHE-FIRST for speed; fill the cache on a miss.
  e.respondWith((async () => {
    const cached = await caches.match(req, { ignoreSearch: true });
    if (cached) return cached;
    try {
      const res = await fetch(req);
      if (res && res.ok && res.type === 'basic') {
        const cache = await caches.open(VERSION);
        cache.put(req, res.clone());
      }
      return res;
    } catch (err) {
      throw err;
    }
  })());
});
