@drupflare/spool 0.4.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +206 -1756
- package/dist/angular/index.d.ts +13 -0
- package/dist/angular/index.js +25 -0
- package/dist/angular/pages.d.ts +28 -0
- package/dist/angular/pages.js +85 -0
- package/dist/cdn/client.js +1 -1
- package/dist/cdn/location.d.ts +6 -0
- package/dist/cdn/location.js +8 -0
- package/dist/cdn/manifest.json +7 -7
- package/dist/cdn/spool-sw.js +1 -1
- package/dist/client/bootstrap.d.ts +57 -0
- package/dist/client/bootstrap.js +307 -0
- package/dist/client/contact.d.ts +24 -0
- package/dist/client/contact.js +66 -0
- package/dist/client/declared.d.ts +23 -0
- package/dist/client/declared.js +68 -0
- package/dist/client/entry.js +91 -2
- package/dist/client/gate.d.ts +1 -0
- package/dist/client/gate.js +148 -0
- package/dist/client/index.d.ts +25 -0
- package/dist/client/index.js +1 -0
- package/dist/client/live.d.ts +66 -0
- package/dist/client/live.js +225 -0
- package/dist/client/navigate-entry.d.ts +1 -0
- package/dist/client/navigate-entry.js +4 -0
- package/dist/client/navigate.d.ts +54 -0
- package/dist/client/navigate.js +272 -0
- package/dist/client/persist.d.ts +2 -0
- package/dist/client/persist.js +9 -0
- package/dist/client/register.d.ts +11 -1
- package/dist/client/register.js +19 -8
- package/dist/express/index.d.ts +11 -0
- package/dist/express/index.js +209 -0
- package/dist/hono/index.d.ts +19 -0
- package/dist/hono/index.js +49 -0
- package/dist/next/index.d.ts +33 -0
- package/dist/next/index.js +41 -0
- package/dist/next/pages.d.ts +22 -0
- package/dist/next/pages.js +39 -0
- package/dist/node/listener.d.ts +3 -0
- package/dist/node/listener.js +57 -2
- package/dist/nuxt/index.d.ts +22 -0
- package/dist/nuxt/index.js +104 -0
- package/dist/nuxt/pages.d.ts +26 -0
- package/dist/nuxt/pages.js +48 -0
- package/dist/nuxt/runtime/index.d.ts +24 -0
- package/dist/nuxt/runtime/index.js +58 -0
- package/dist/plugins/coverage.d.ts +14 -0
- package/dist/plugins/coverage.js +27 -0
- package/dist/plugins/mode.d.ts +19 -0
- package/dist/plugins/mode.js +20 -0
- package/dist/plugins/path.d.ts +16 -0
- package/dist/plugins/path.js +139 -0
- package/dist/plugins/report.d.ts +22 -0
- package/dist/plugins/report.js +18 -0
- package/dist/plugins/routes.d.ts +38 -0
- package/dist/plugins/routes.js +52 -0
- package/dist/plugins/static.d.ts +42 -0
- package/dist/plugins/static.js +97 -0
- package/dist/protocol/bundle.d.ts +111 -0
- package/dist/protocol/bundle.js +428 -0
- package/dist/protocol/config.d.ts +65 -1
- package/dist/protocol/config.js +28 -0
- package/dist/protocol/dataset.d.ts +6 -0
- package/dist/protocol/dataset.js +6 -0
- package/dist/protocol/envelope.d.ts +33 -1
- package/dist/protocol/envelope.js +15 -1
- package/dist/protocol/errors.d.ts +1 -1
- package/dist/protocol/index-rows.d.ts +22 -0
- package/dist/protocol/index-rows.js +53 -0
- package/dist/protocol/index.d.ts +2 -0
- package/dist/protocol/index.js +2 -0
- package/dist/protocol/normalise.d.ts +4 -4
- package/dist/protocol/normalise.js +9 -5
- package/dist/protocol/ring.d.ts +58 -0
- package/dist/protocol/ring.js +6 -0
- package/dist/protocol/route.d.ts +57 -11
- package/dist/protocol/route.js +95 -3
- package/dist/protocol/tag.d.ts +22 -2
- package/dist/protocol/tag.js +25 -4
- package/dist/protocol/view.d.ts +2 -0
- package/dist/protocol/view.js +8 -2
- package/dist/protocol/views.d.ts +6 -0
- package/dist/protocol/views.js +15 -0
- package/dist/protocol/write.d.ts +92 -4
- package/dist/protocol/write.js +251 -9
- package/dist/proxy/eligible.d.ts +22 -1
- package/dist/proxy/eligible.js +62 -15
- package/dist/proxy/proxy.js +28 -18
- package/dist/react-router/index.d.ts +20 -0
- package/dist/react-router/index.js +60 -0
- package/dist/react-router/pages.d.ts +34 -0
- package/dist/react-router/pages.js +83 -0
- package/dist/report/demand.d.ts +49 -0
- package/dist/report/demand.js +60 -0
- package/dist/report/economics.d.ts +55 -0
- package/dist/report/economics.js +189 -0
- package/dist/report/headline.d.ts +158 -0
- package/dist/report/headline.js +473 -0
- package/dist/report/index.d.ts +2 -0
- package/dist/report/index.js +2 -0
- package/dist/report/inputs.d.ts +79 -0
- package/dist/report/inputs.js +115 -0
- package/dist/report/measurement.d.ts +1 -1
- package/dist/report/measurement.js +5 -1
- package/dist/report/traffic.d.ts +8 -0
- package/dist/report/traffic.js +7 -0
- package/dist/server/bundle.d.ts +55 -0
- package/dist/server/bundle.js +172 -0
- package/dist/server/dataset.d.ts +8 -2
- package/dist/server/dataset.js +51 -4
- package/dist/server/embedded.d.ts +7 -3
- package/dist/server/embedded.js +7 -3
- package/dist/server/index.d.ts +5 -1
- package/dist/server/index.js +5 -1
- package/dist/server/live-sockets.d.ts +54 -0
- package/dist/server/live-sockets.js +131 -0
- package/dist/server/live.d.ts +146 -0
- package/dist/server/live.js +228 -0
- package/dist/server/ring.d.ts +77 -0
- package/dist/server/ring.js +311 -0
- package/dist/server/spool.d.ts +139 -4
- package/dist/server/spool.js +457 -28
- package/dist/server/static.d.ts +42 -0
- package/dist/server/static.js +29 -0
- package/dist/server/stub.d.ts +43 -5
- package/dist/server/stub.js +126 -8
- package/dist/server/write.d.ts +23 -1
- package/dist/server/write.js +96 -0
- package/dist/stores/durable-object.d.ts +46 -0
- package/dist/stores/durable-object.js +114 -0
- package/dist/sw/analytics.d.ts +1 -1
- package/dist/sw/analytics.js +2 -2
- package/dist/sw/coverage.d.ts +6 -0
- package/dist/sw/coverage.js +34 -0
- package/dist/sw/family.d.ts +15 -0
- package/dist/sw/family.js +48 -0
- package/dist/sw/idb.d.ts +2 -0
- package/dist/sw/idb.js +2 -2
- package/dist/sw/index.d.ts +2 -0
- package/dist/sw/index.js +1 -0
- package/dist/sw/pack/store.d.ts +128 -0
- package/dist/sw/pack/store.js +737 -0
- package/dist/sw/policy.d.ts +2 -0
- package/dist/sw/policy.js +11 -0
- package/dist/sw/probe.d.ts +16 -0
- package/dist/sw/probe.js +25 -0
- package/dist/sw/router.d.ts +3 -2
- package/dist/sw/router.js +15 -2
- package/dist/sw/runtime.d.ts +48 -1
- package/dist/sw/runtime.js +548 -68
- package/dist/sw/scheduler.d.ts +6 -1
- package/dist/sw/scheduler.js +22 -5
- package/dist/sw/write.d.ts +41 -1
- package/dist/sw/write.js +188 -5
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -2
- package/dist/vite/index.d.ts +26 -0
- package/dist/vite/index.js +66 -0
- package/dist/vue/index.d.ts +36 -0
- package/dist/vue/index.js +53 -0
- package/package.json +64 -4
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
/** the service worker core, generated by `bun run build:sw`; never edit by hand */
|
|
2
|
-
export declare const SW_CORE = "(()=>{class D extends Error{code;constructor(e,t){super(t);this.name=\"ProtocolError\",this.code=e}}async function Ae(e){let t=new Uint8Array(await crypto.subtle.digest(\"SHA-256\",new TextEncoder().encode(e))),n=\"\";for(let r of t)n+=String.fromCharCode(r);return btoa(n).replace(/\\+/g,\"-\").replace(/\\//g,\"_\").replace(/=+$/,\"\")}var Bt=\"dataset proof does not match its items\",be=(e)=>typeof e===\"object\"&&e!==null&&!Array.isArray(e),fe=(e,t)=>Object.hasOwn(e,t)?e[t]:void 0;function rt(e){let t=e?.toJSON;if(typeof e===\"object\"&&typeof t===\"function\")return rt(t.call(e));if(Array.isArray(e))return`[${e.map((n)=>rt(n)??\"null\").join(\",\")}]`;if(be(e)){let n=[];for(let r of Object.keys(e).sort()){let s=rt(e[r]);if(s!==void 0)n.push(`${JSON.stringify(r)}:${s}`)}return`{${n.join(\",\")}}`}return JSON.stringify(e)}function nr(e){return rt(e)??\"null\"}var $t=1n<<256n,We=\"0\".repeat(64),rr=/^[0-9a-f]{64}$/;function Nt(e,t){return Ae(`${e}\\x00${nr(t)}`)}function _t(e){if(!/^[A-Za-z0-9_-]{43}$/.test(e))throw RangeError(\"not a row hash\");let t=atob(e.replace(/-/g,\"+\").replace(/_/g,\"/\")+\"=\"),n=\"\";for(let r=0;r<t.length;r++)n+=t.charCodeAt(r).toString(16).padStart(2,\"0\");return BigInt(`0x${n}`)}function sr(e){if(!rr.test(e))throw RangeError(\"not a set digest\");return BigInt(`0x${e}`)}var Wt=(e)=>((e%$t+$t)%$t).toString(16).padStart(64,\"0\");function st(e,t){return Wt(sr(e)+_t(t))}function or(e,t){return Wt(sr(e)-_t(t))}async function qt(e){let t=await Promise.all([...e].map(([r,s])=>Nt(r,s))),n=0n;for(let r of t)n+=_t(r);return{kind:\"set\",count:e.size,digest:Wt(n)}}function Lt(e){return be(e)&&e.kind===\"set\"&&typeof e.count===\"number\"&&Number.isSafeInteger(e.count)&&e.count>=0&&typeof e.digest===\"string\"&&rr.test(e.digest)}function ir(e){let t=e.key;if(t===void 0)return;return(n)=>{let r=fe(n,t);if(typeof r!==\"string\")throw TypeError(`${t} is not a string key`);return r}}async function Oo(e,t,n){if(t.count!==e.length)return!1;let r=new Map;for(let s of e){if(!be(s))return!1;let o;try{o=n(s)}catch{return!1}if(typeof o!==\"string\"||r.has(o))return!1;r.set(o,s)}return(await qt(r)).digest===t.digest}async function Do(e,t,n){if(!be(t))return!1;let r=fe(t,e.list),s=fe(t,\"proof\");if(!Array.isArray(r)||!be(s))return!1;let o=s.kind;if(o===\"set\")return n!==void 0&&Lt(s)&&await Oo(r,s,n);if(o!==void 0&&o!==\"ordered\")return!1;if(s.count!==r.length||typeof s.digest!==\"string\")return!1;return await Ae(nr(r))===s.digest}var jo=(e)=>e.trim()!==\"\"&&Number.isFinite(Number(e))?Number(e):null,tr=(e)=>typeof e===\"number\"?0:typeof e===\"string\"?1:2;function Co(e,t){let[n,r]=[tr(e),tr(t)];if(n!==r)return n-r;if(n===2)return 0;return e<t?-1:e>t?1:0}function Mo(e,t,n){let r=be(t)?fe(t,e.list):void 0;if(!Array.isArray(r)||!r.every(be))return null;let s=new URLSearchParams(n),o=e.filter??{};for(let y of new Set(s.keys()))if(y!==\"sort\"&&y!==\"page\"&&!Object.hasOwn(o,y))return null;let i=r;for(let[y,S]of Object.entries(o)){let x=s.getAll(y);if(x.length===0)continue;if(S===\"number\"){let T=x.map(jo);if(T.includes(null))return null;i=i.filter((N)=>{let C=fe(N,y);return typeof C===\"number\"&&T.includes(C)})}else i=i.filter((T)=>{let N=fe(T,y),C=typeof N===\"string\"||typeof N===\"number\"||typeof N===\"boolean\"?String(N):void 0;return C!==void 0&&x.includes(C)})}let a=s.getAll(\"sort\");if(a.length>1)return null;if(i=[...i],a.length===1){let y=a[0],S=e.sort??[],x=!S.includes(y)&&y.startsWith(\"-\"),T=x?y.slice(1):y;if(!S.includes(T))return null;i.sort((N,C)=>{let q=Co(fe(N,T),fe(C,T));return x?-q:q})}let c=s.getAll(\"page\");if(c.length>1)return null;let l=1;if(c.length===1){if(!/^[1-9]\\d{0,14}$/.test(c[0]))return null;l=Number(c[0])}let d=i.length,p=e.pageSize,h=p===void 0?1:Math.max(1,Math.ceil(d/p));if(l>h)return null;return{items:p===void 0?i:i.slice((l-1)*p,l*p),total:d,page:l,pages:h}}async function ar(e,t,n,r){if(!await Do(e,t,r))return{ok:!1,reason:Bt};return Ft(e,t,n)}function Ft(e,t,n){let r=Mo(e,t,n);if(!r)return{ok:!1,reason:\"query is not one the route declares\"};let{items:s,total:o,page:i,pages:a}=r,c={total:o,page:i,pages:a};return{ok:!0,data:{...t,[e.list]:s,query:c}}}function Vt(e){let t=e.indexOf(\"/\");if(t<1||t===e.length-1)return null;return{dataset:e.slice(0,t),key:e.slice(t+1)}}function qe(e){return typeof e===\"object\"&&e!==null&&!Array.isArray(e)}function ot(e){if(!qe(e))return!1;let t=Object.keys(e);if(t.length!==1)return!1;let n=t[0];return(n===\"$record\"||n===\"$projection\"||n===\"$row\")&&typeof e[n]===\"string\"}function ge(e){let t=new Set,n=new Set,r=new Set,s=(o)=>{if(Array.isArray(o))return o.forEach(s);if(!qe(o))return;if(ot(o)){if(\"$record\"in o)t.add(o.$record);else if(\"$row\"in o)r.add(o.$row);else n.add(o.$projection);return}Object.values(o).forEach(s)};return s(e),{records:[...t].sort(),projections:[...n].sort(),...r.size>0?{rows:[...r].sort()}:{}}}function Ut(e,t){let n=(r,s)=>{if(Array.isArray(r))return r.map((o)=>n(o,s));if(!qe(r))return r;if(ot(r)){if(\"$record\"in r){let a=t.record(r.$record);if(!a)throw Error(`record ${r.$record} is not stored`);return a.data}if(\"$row\"in r){let a=Vt(r.$row),c=a?t.row?.(a.dataset,a.key):void 0;if(c===void 0)throw Error(`row ${r.$row} is not held`);return c}let o=r.$projection;if(s.includes(o))throw Error(`projection ${o} reaches itself`);let i=t.projection(o);if(!i)throw Error(`projection ${o} is not stored`);return n(i.data,[...s,o])}return Object.fromEntries(Object.entries(r).map(([o,i])=>[o,n(i,s)]))};try{return{ok:!0,value:n(e,[])}}catch(r){return{ok:!1,reason:r instanceof Error?r.message:\"unresolved reference\"}}}function pe(e){throw new D(\"bad-artifact\",e)}function cr(e,t){if(typeof e!==\"number\"||!Number.isSafeInteger(e)||e<0)return pe(`${t} version must be a non-negative integer`);return e}function ur(e){if(!qe(e))return pe(\"record must be an object\");if(typeof e.id!==\"string\"||e.id===\"\")return pe(\"record id\");if(!(\"data\"in e))return pe(`record ${e.id} needs data`);return{id:e.id,version:cr(e.version,\"record\"),data:e.data}}function lr(e){if(!qe(e))return pe(\"projection must be an object\");let{id:t,deps:n}=e;if(typeof t!==\"string\"||t===\"\")return pe(\"projection id\");if(!Array.isArray(n)||n.some((r)=>typeof r!==\"string\"))return pe(`projection ${t} deps must be a list of strings`);if(!(\"data\"in e))return pe(`projection ${t} needs data`);return{id:t,version:cr(e.version,\"projection\"),deps:n,data:e.data}}var j=1;function J(e){throw new D(\"bad-artifact\",e)}function zt(e){return typeof e===\"object\"&&e!==null&&!Array.isArray(e)}function dr(e,t){if(e===void 0)return;if(!zt(e))return J(`${t} must be an object`);for(let n of Object.values(e))if(typeof n!==\"string\"&&!ot(n))return J(`${t} values must be strings or references`);return e}function fr(e,t,n){if(e===void 0)return;if(!Array.isArray(e))return J(`${t} must be a list`);return e.map(n)}function Le(e){if(!zt(e))return J(\"artifact must be an object\");if(e.protocol!==j)return J(\"unsupported protocol version\");let{id:t,scope:n,deps:r,vector:s,strategy:o,body:i}=e;if(typeof t!==\"string\"||!t.startsWith(\"/\"))return J(\"id must be a path\");if(n!==\"public\"&&n!==\"principal\")return J(\"scope must be public or principal\");if(!Array.isArray(r)||r.some((d)=>typeof d!==\"string\"))return J(\"deps must be a list of strings\");if(typeof s!==\"number\"||!Number.isSafeInteger(s)||s<0)return J(\"vector must be a non-negative integer\");if(!zt(i))return J(\"body must be an object\");let a={protocol:j,id:t,scope:n,deps:r,vector:s},c=fr(e.records,\"records\",ur),l=fr(e.projections,\"projections\",lr);if(c)a.records=c;if(l)a.projections=l;if(o===\"template\"||o===\"projection\"||o===\"data\"){if(!(\"data\"in i))return J(`${o} body needs data`);return{...a,strategy:o,body:{data:i.data}}}if(o===\"assembly\"){if(typeof i.shell!==\"string\")return J(\"assembly body needs a shell string\");let d={shell:i.shell},p=dr(i.fragments,\"fragments\"),h=dr(i.slots,\"slots\");if(p)d.fragments=p;if(h)d.slots=h;return{...a,strategy:o,body:d}}return J(`unknown strategy ${String(o)}`)}function I(e){return new Promise((t,n)=>{e.onsuccess=()=>t(e.result),e.onerror=()=>n(e.error)})}function Gt(e){return new Promise((t,n)=>{e.oncomplete=()=>t(),e.onerror=()=>n(e.error),e.onabort=()=>n(e.error)})}function it(e=indexedDB,t=\"spool\"){let n,r,s=()=>n??=new Promise((a,c)=>{let l=e.open(t,2);l.onupgradeneeded=()=>{let d=l.result,p=(h)=>!d.objectStoreNames.contains(h);if(p(\"artifacts\"))d.createObjectStore(\"artifacts\",{keyPath:\"artifact.id\"});if(p(\"meta\"))d.createObjectStore(\"meta\");if(p(\"beacons\"))d.createObjectStore(\"beacons\",{autoIncrement:!0});if(p(\"records\"))d.createObjectStore(\"records\",{keyPath:\"id\"});if(p(\"projections\"))d.createObjectStore(\"projections\",{keyPath:\"id\"})},l.onsuccess=()=>{let d=l.result;d.onversionchange=()=>{d.close(),n=void 0},a(d)},l.onerror=()=>c(l.error)}),o=()=>r??=new Promise((a,c)=>{let l=e.open(`${t}-datasets`,1);l.onupgradeneeded=()=>{let d=l.result;d.createObjectStore(\"datasetRows\",{keyPath:[\"name\",\"key\"]}),d.createObjectStore(\"datasetMeta\",{keyPath:\"name\"})},l.onsuccess=()=>{let d=l.result;d.onversionchange=()=>{d.close(),r=void 0},a(d)},l.onerror=()=>c(l.error)});async function i(a,c,l,d=s){let h=(await d()).transaction(a,c),y=Gt(h),S=await l(h.objectStore(a));return await y,S}return{destroy:async()=>{let a=await Promise.all([n,r].map((c)=>c?.catch(()=>{return})));for(let c of a)c?.close();n=void 0,r=void 0;for(let c of[t,`${t}-datasets`])await new Promise((l)=>{let d=e.deleteDatabase(c);d.onsuccess=()=>l(),d.onerror=()=>l()})},getArtifact:(a)=>i(\"artifacts\",\"readonly\",(c)=>I(c.get(a))),putArtifact:(a)=>i(\"artifacts\",\"readwrite\",async(c)=>void await I(c.put(a))),deleteArtifacts:(a)=>i(\"artifacts\",\"readwrite\",async(c)=>{await Promise.all(a.map((l)=>I(c.delete(l))))}),allArtifacts:()=>i(\"artifacts\",\"readonly\",(a)=>I(a.getAll())),clearArtifacts:()=>i(\"artifacts\",\"readwrite\",async(a)=>void await I(a.clear())),getMeta:()=>i(\"meta\",\"readonly\",(a)=>I(a.get(\"replica\"))),setMeta:(a)=>i(\"meta\",\"readwrite\",async(c)=>void await I(c.put(a,\"replica\"))),addBeacon:(a)=>i(\"beacons\",\"readwrite\",async(c)=>void await I(c.add(a))),readBeacons:()=>i(\"beacons\",\"readonly\",async(a)=>{let[c,l]=await Promise.all([I(a.getAllKeys()),I(a.getAll())]);return c.map((d,p)=>({key:d,event:l[p]}))}),removeBeacons:(a)=>i(\"beacons\",\"readwrite\",async(c)=>{await Promise.all(a.map((l)=>I(c.delete(l))))}),getFlush:()=>i(\"meta\",\"readonly\",(a)=>I(a.get(\"flush\"))),setFlush:(a)=>i(\"meta\",\"readwrite\",async(c)=>void await I(c.put(a,\"flush\"))),putRecords:(a)=>i(\"records\",\"readwrite\",async(c)=>{await Promise.all(a.map((l)=>I(c.put(l))))}),allRecords:()=>i(\"records\",\"readonly\",(a)=>I(a.getAll())),deleteRecords:(a)=>i(\"records\",\"readwrite\",async(c)=>{await Promise.all(a.map((l)=>I(c.delete(l))))}),putProjections:(a)=>i(\"projections\",\"readwrite\",async(c)=>{await Promise.all(a.map((l)=>I(c.put(l))))}),allProjections:()=>i(\"projections\",\"readonly\",(a)=>I(a.getAll())),deleteProjections:(a)=>i(\"projections\",\"readwrite\",async(c)=>{await Promise.all(a.map((l)=>I(c.delete(l))))}),clearGraph:async()=>{await i(\"records\",\"readwrite\",async(a)=>void await I(a.clear())),await i(\"projections\",\"readwrite\",async(a)=>void await I(a.clear()))},getDatasets:()=>i(\"datasetMeta\",\"readonly\",(a)=>I(a.getAll()),o),readDataset:(a)=>i(\"datasetRows\",\"readonly\",(c)=>I(c.getAll(IDBKeyRange.bound([a],[a,[]]))),o),commitDataset:async(a)=>{let l=(await o()).transaction([\"datasetRows\",\"datasetMeta\"],\"readwrite\",{durability:\"strict\"}),d=Gt(l);d.catch(()=>{return});try{let p=l.objectStore(\"datasetRows\"),h=l.objectStore(\"datasetMeta\");if(a.clear)p.delete(IDBKeyRange.bound([a.name],[a.name,[]]));for(let y of a.deletes)p.delete([a.name,y]);for(let y of a.puts)p.put(y);if(a.meta)h.put(a.meta);else h.delete(a.name)}catch(p){try{l.abort()}catch{}throw p}await d},clearDatasets:async()=>{let c=(await o()).transaction([\"datasetRows\",\"datasetMeta\"],\"readwrite\"),l=Gt(c);c.objectStore(\"datasetRows\").clear(),c.objectStore(\"datasetMeta\").clear(),await l}}}var Qt=new TextEncoder,Io=new TextDecoder;async function Fe(e,t,n,r){let s=crypto.getRandomValues(new Uint8Array(12)),o=await crypto.subtle.encrypt({name:\"AES-GCM\",iv:s,additionalData:Qt.encode(t)},e,Qt.encode(JSON.stringify(n)));return{sealed:{iv:s,data:o,at:r}}}async function Ee(e,t,n,r){let s=r?.sealed;if(!s)return;let o=await e.get(t,s.at,!1);if(!o)return;try{let i=await crypto.subtle.decrypt({name:\"AES-GCM\",iv:s.iv,additionalData:Qt.encode(n)},o,s.data);return JSON.parse(Io.decode(i))}catch{return}}function pr(e,t){let{partition:n,vault:r}=t,s=!1,o=(c,l)=>`${n}\\x00${c}\\x00${l}`;async function i(c,l,d,p){let h=await r.get(n,c,!0);if(!h)throw Error(\"no key\");return Fe(h,o(l,d),p,c)}let a=(c,l,d)=>Ee(r,n,o(c,l),d);return{kill:()=>{s=!0,t.datasets?.kill()},async getArtifact(c){if(s)return;let l=await e.getArtifact(c);if(!l)return;let d=await a(\"artifact\",c,l);if(!d)await e.deleteArtifacts([c]);return d},async putArtifact(c){if(s)return;let l=c.artifact.id,d=await i(t.retentionOf(l),\"artifact\",l,c);if(s)return;await e.putArtifact({artifact:{id:l},...d})},deleteArtifacts:(c)=>s?Promise.resolve():e.deleteArtifacts(c),async allArtifacts(){if(s)return[];let c=[],l=[];for(let d of await e.allArtifacts()){let p=d.artifact.id,h=await a(\"artifact\",p,d);if(h)c.push(h);else l.push(p)}if(l.length>0)await e.deleteArtifacts(l);return c},clearArtifacts:()=>s?Promise.resolve():e.clearArtifacts(),async getMeta(){if(s)return;return a(\"meta\",\"replica\",await e.getMeta())},async setMeta(c){if(s)return;let l=await i(t.shared,\"meta\",\"replica\",c);if(!s)await e.setMeta(l)},addBeacon:(c)=>e.addBeacon(c),readBeacons:()=>e.readBeacons(),removeBeacons:(c)=>e.removeBeacons(c),getFlush:()=>e.getFlush(),setFlush:(c)=>e.setFlush(c),async putRecords(c){if(s)return;let l=await Promise.all(c.map(async(d)=>({id:d.id,version:d.version,...await i(t.shared,\"record\",d.id,d)})));if(!s)await e.putRecords(l)},async allRecords(){if(s)return[];let c=[];for(let l of await e.allRecords()){let d=await a(\"record\",l.id,l);if(d)c.push(d)}return c},deleteRecords:(c)=>s?Promise.resolve():e.deleteRecords(c),async putProjections(c){if(s)return;let l=await Promise.all(c.map(async(d)=>({id:d.id,version:d.version,...await i(t.shared,\"projection\",d.id,d)})));if(!s)await e.putProjections(l)},async allProjections(){if(s)return[];let c=[];for(let l of await e.allProjections()){let d=await a(\"projection\",l.id,l);if(d)c.push(d)}return c},deleteProjections:(c)=>s?Promise.resolve():e.deleteProjections(c),clearGraph:()=>s?Promise.resolve():e.clearGraph(),getDatasets:t.datasets?.getDatasets??(async()=>[]),readDataset:t.datasets?.readDataset??(async()=>[]),commitDataset:t.datasets?.commitDataset??(()=>Promise.reject(Error(\"a principal partition holds no dataset\"))),clearDatasets:t.datasets?.clearDatasets??(async()=>{return})}}var yr=\"spool-principal-datasets\",ue=\"rows\",oe=\"meta\",$o=new TextEncoder;function Bo(e){return new Promise((t,n)=>{e.onsuccess=()=>t(e.result),e.onerror=()=>n(e.error)})}function at(e){return new Promise((t,n)=>{e.oncomplete=()=>t(),e.onerror=()=>n(e.error),e.onabort=()=>n(e.error)})}var He=(e)=>IDBKeyRange.bound([e],[e,[]]),gr=(e,t)=>IDBKeyRange.bound([e,t],[e,t,[]]);function hr(e,t){let n,r=()=>n??=new Promise((i,a)=>{let c=e.open(yr,1);c.onupgradeneeded=()=>{let l=c.result;l.createObjectStore(ue,{keyPath:[\"partition\",\"name\",\"slot\"]}),l.createObjectStore(oe,{keyPath:[\"partition\",\"name\"]})},c.onsuccess=()=>{let l=c.result;l.onversionchange=()=>{l.close(),n=void 0},i(l)},c.onerror=()=>a(c.error)}),s=(i)=>{let{partition:a,...c}=i;return c};async function o(i,a){let l=(await r()).transaction(i,\"readonly\"),d=at(l),p=await Bo(a(l.objectStore(i)));return await d,p}return{metas:async()=>(await o(oe,(i)=>i.getAll(He(t)))).map((i)=>s(i)),meta:async(i)=>{let a=await o(oe,(c)=>c.get([t,i]));return a?s(a):void 0},rows:async(i)=>(await o(ue,(a)=>a.getAll(gr(t,i)))).map((a)=>s(a)),commit:async(i)=>{let c=(await r()).transaction([ue,oe],\"readwrite\",{durability:\"strict\"}),l=at(c);l.catch(()=>{return});try{let d=c.objectStore(ue),p=c.objectStore(oe);if(i.clear)d.delete(gr(t,i.name));for(let h of i.deletes)d.delete([t,i.name,h]);for(let h of i.puts)d.put({partition:t,...h});if(i.meta)p.put({partition:t,...i.meta});else p.delete([t,i.name])}catch(d){try{c.abort()}catch{}throw d}await l},clear:async()=>{let a=(await r()).transaction([ue,oe],\"readwrite\"),c=at(a);a.objectStore(ue).delete(He(t)),a.objectStore(oe).delete(He(t)),await c}}}async function wr(e,t){let n=await new Promise((r)=>{let s=e.open(yr);s.onupgradeneeded=()=>{try{s.transaction?.abort()}catch{}},s.onsuccess=()=>r(s.result),s.onerror=()=>r(null),s.onblocked=()=>r(null)});if(!n)return;try{if(!n.objectStoreNames.contains(ue)||!n.objectStoreNames.contains(oe))return;let r=n.transaction([ue,oe],\"readwrite\"),s=at(r);r.objectStore(ue).delete(He(t)),r.objectStore(oe).delete(He(t)),await s}catch{}finally{n.close()}}function mr(e){let t=\"\";for(let n of e)t+=String.fromCharCode(n);return btoa(t).replace(/\\+/g,\"-\").replace(/\\//g,\"_\").replace(/=+$/,\"\")}function br(e,t){let{partition:n,vault:r,retention:s}=t,o=!1,i=new Map,a=(y)=>`${n}\\x00dataset-meta\\x00${y}`,c=(y,S)=>`${n}\\x00dataset-row\\x00${y}\\x00${S}`;async function l(y,S){let x=await r.get(n,s,!0);if(!x)throw Error(\"no key\");return Fe(x,y,S,s)}async function d(y,S,x){let T=$o.encode(`${x}\\x00${y}\\x00${S}`);return mr(new Uint8Array(await crypto.subtle.digest(\"SHA-256\",T)))}async function p(y){let S=await Ee(r,n,a(y.name),y);if(S)return i.set(y.name,S.salt),S;i.delete(y.name),await e.commit({name:y.name,meta:null,clear:!0,puts:[],deletes:[]});return}async function h(y){let S=i.get(y);if(S!==void 0)return S;let x=await e.meta(y);return x?(await p(x))?.salt:void 0}return{kill:()=>void(o=!0),async getDatasets(){if(o)return[];let y=[];for(let S of await e.metas()){let x=await p(S);if(x)y.push(x.meta)}return y},async readDataset(y){if(o||await h(y)===void 0)return[];let S=[];for(let x of await e.rows(y)){let T=await Ee(r,n,c(y,x.slot),x);if(T&&T.name===y)S.push(T)}return S.sort((x,T)=>x.key<T.key?-1:x.key>T.key?1:0)},async commitDataset(y){if(o)return;let{name:S}=y;if(y.meta===null){await e.commit({name:S,meta:null,clear:!0,puts:[],deletes:[]}),i.delete(S);return}let x=y.clear?void 0:await h(S),T=x===void 0;x??=mr(crypto.getRandomValues(new Uint8Array(16)));let N=[];for(let H of y.puts){let ae=await d(S,H.key,x);N.push({name:S,slot:ae,...await l(c(S,ae),H)})}let C=await Promise.all(y.deletes.map((H)=>d(S,H,x))),q=await l(a(S),{meta:y.meta,salt:x});if(o)return;await e.commit({name:S,meta:{name:S,...q},clear:y.clear||T,puts:N,deletes:C}),i.set(S,x)},async clearDatasets(){if(o)return;await e.clear(),i.clear()}}}var No=/^[A-Za-z_][A-Za-z0-9_]*$/;function Jt(e){let t=e.length>1&&e.endsWith(\"/\")?e.slice(0,-1):e;return t===\"/\"?[]:t.slice(1).split(\"/\")}function ct(e){if(!e.startsWith(\"/\"))throw new D(\"bad-pattern\",`pattern must start with \"/\": ${e}`);let t=new Set,n=Jt(e);for(let[r,s]of n.entries()){if(s===\"\")throw new D(\"bad-pattern\",`empty segment in ${e}`);if(s===\"**\"){if(r!==n.length-1)throw new D(\"bad-pattern\",`\"**\" must be the last segment in ${e}`);continue}if(!s.startsWith(\":\"))continue;let o=s.slice(1);if(!No.test(o))throw new D(\"bad-pattern\",`bad parameter name \"${o}\" in ${e}`);if(t.has(o))throw new D(\"bad-pattern\",`duplicate parameter \"${o}\" in ${e}`);t.add(o)}}function ut(e,t){let n=Jt(e),r=Jt(t),s=n[n.length-1]===\"**\";if(s)n.pop();if(s?r.length<n.length:n.length!==r.length)return null;let o={};for(let i=0;i<n.length;i++){let a=n[i],c=r[i];if(a.startsWith(\":\")){if(c===\"\")return null;try{o[a.slice(1)]=decodeURIComponent(c)}catch{return null}}else if(a!==c)return null}return o}var Rr={id:\"spool-write-id\"};var _o=/^[A-Za-z0-9._:~-]{1,128}$/;var Wo=256;var Sr={\"writes-off\":403,\"unknown-write\":404,\"bad-method\":405,\"bad-key\":400,\"missing-version\":428,\"bad-version\":400,\"bad-id\":400,\"bad-body\":400,\"too-large\":413,\"too-many\":429,\"id-reused\":422,forbidden:403,\"sign-in\":401,\"no-partition\":409,\"no-record\":404,\"not-conflicted\":409,unavailable:503};function Pr(e){return typeof e===\"string\"&&e.length>0&&e.length<=Wo&&!e.includes(\"\\x00\")}var lt=(e)=>typeof e===\"string\"&&_o.test(e);var vr=(e)=>`\"${e}\"`;function dt(){let e=crypto.getRandomValues(new Uint8Array(16)),t=\"\";for(let n of e)t+=String.fromCharCode(n);return btoa(t).replace(/\\+/g,\"-\").replace(/\\//g,\"_\").replace(/=+$/,\"\")}var xr=\"spool-writes\",Te=\"queue\",qo=new TextEncoder;function Ve(e){return new Promise((t,n)=>{e.onsuccess=()=>t(e.result),e.onerror=()=>n(e.error)})}function kr(e){return new Promise((t,n)=>{e.oncomplete=()=>t(),e.onerror=()=>n(e.error),e.onabort=()=>n(e.error)})}var Ar=(e)=>IDBKeyRange.bound([e],[e,[]]);function Er(e,t,n){let r,s=()=>r??=new Promise((c,l)=>{let d=e.open(xr,1);d.onupgradeneeded=()=>{d.result.createObjectStore(Te,{keyPath:[\"partition\",\"name\",\"key\"]})},d.onsuccess=()=>{let p=d.result;p.onversionchange=()=>{p.close(),r=void 0},c(p)},d.onerror=()=>l(d.error)}),o=(c,l)=>`${t}\\x00write\\x00${c}\\x00${l}`;async function i(c,l){let p=(await s()).transaction(Te,c),h=kr(p),y=await l(p.objectStore(Te));return await h,y}let a=async(c)=>c&&await Ee(n,t,o(c.name,c.key),c);return{get:async(c,l)=>a(await i(\"readonly\",(d)=>Ve(d.get([t,c,l])))),put:async(c)=>{let l=await n.get(t,\"persistent\",!0);if(!l)throw Error(\"no key\");let d=await Fe(l,o(c.name,c.key),c,\"persistent\");await i(\"readwrite\",async(p)=>{await Ve(p.put({partition:t,name:c.name,key:c.key,...d}))})},delete:(c,l)=>i(\"readwrite\",async(d)=>void await Ve(d.delete([t,c,l]))),all:async()=>{let c=await i(\"readonly\",(d)=>Ve(d.getAll(Ar(t)))),l=[];for(let d of c){let p=await a(d);if(p)l.push(p);else await i(\"readwrite\",async(h)=>void await Ve(h.delete([t,d.name,d.key])))}return l}}}async function Tr(e,t){let n=await new Promise((r)=>{let s=e.open(xr);s.onupgradeneeded=()=>{try{s.transaction?.abort()}catch{}},s.onsuccess=()=>r(s.result),s.onerror=()=>r(null),s.onblocked=()=>r(null)});if(!n)return;try{if(!n.objectStoreNames.contains(Te))return;let r=n.transaction(Te,\"readwrite\"),s=kr(r);r.objectStore(Te).delete(Ar(t)),await s}catch{}finally{n.close()}}var G=(e,t)=>({ok:!1,code:e,message:t}),Lo=new Set(Object.keys(Sr)),Fo=(e)=>{let t=e?.code;return typeof t===\"string\"&&Lo.has(t)?t:void 0};function Ho(e){let t=e?.conflict;if(!t||!lt(t.version))return;return\"value\"in t?{version:t.version,value:t.value}:{version:t.version}}class Re{#e;#t=Promise.resolve();#n=null;#r=!1;constructor(e){this.#e=e}kill(){this.#r=!0}#s(e){let t=this.#t.then(e,e);return this.#t=t.catch(()=>{return}),t}write(e,t,n,r){if(this.#r)return Promise.resolve(G(\"no-partition\",\"the queue was wiped\"));let s=this.#e.classes().find((i)=>i.name===e);if(!s)return Promise.resolve(G(\"unknown-write\",`no write class \"${e}\"`));if(!Pr(t))return Promise.resolve(G(\"bad-key\",\"the key is malformed\"));if(r===void 0||r===null)return Promise.resolve(G(\"missing-version\",\"say which version the edit started from\"));if(!lt(r))return Promise.resolve(G(\"bad-version\",\"the version is malformed\"));let o;try{let i=JSON.stringify({value:n});if(n===void 0)throw Error(\"no value\");o=qo.encode(i).length}catch{return Promise.resolve(G(\"bad-body\",\"the value is not JSON\"))}if(o>s.maxBytes)return Promise.resolve(G(\"too-large\",`the value is over ${s.maxBytes} bytes`));return this.#s(async()=>{if(this.#r)return G(\"no-partition\",\"the queue was wiped\");let i=this.#e.now(),a=await this.#e.store.get(e,t);if(!a){if((await this.#e.store.all()).filter((h)=>h.name===e).length>=s.maxPending)return G(\"too-many\",`${s.maxPending} keys of \"${e}\" are already queued`);let p={name:e,key:t,value:n,base:r,id:dt(),state:\"pending\",queuedAt:i,updatedAt:i,bytes:o,edits:1,attempts:0};return await this.#e.store.put(p),{ok:!0,state:p.state,edits:1}}let c=a.state===\"flushing\"||a.attempts>0,l={...a,updatedAt:i,edits:a.edits+1,...c&&a.state!==\"conflicted\"?{next:{value:n,bytes:o}}:{value:n,bytes:o}};return await this.#e.store.put(l),{ok:!0,state:l.state,edits:l.edits}})}list(){return this.#s(async()=>{if(this.#r)return[];return(await this.#e.store.all()).sort((t,n)=>t.queuedAt-n.queuedAt||(t.key<n.key?-1:1)).map((t)=>({name:t.name,key:t.key,state:t.state,base:t.base,queuedAt:t.queuedAt,updatedAt:t.updatedAt,bytes:t.bytes,attempts:t.attempts,...t.conflict?{conflict:t.conflict}:{},...t.refusal?{refusal:t.refusal}:{}}))})}flush(e){if(this.#n&&!e)return this.#n;let t=this.#o(e);if(!e)return this.#n=t.finally(()=>{this.#n=null}),this.#n;return t}async#o(e){let t={queued:0,flushed:0,conflicted:0};if(this.#r)return t;let n=await this.#s(async()=>this.#r?[]:(await this.#e.store.all()).filter((r)=>r.state!==\"conflicted\"));for(let r of n){if(e&&(r.name!==e.name||r.key!==e.key))continue;let s=await this.#s(async()=>{if(this.#r)return;let a=await this.#e.store.get(r.name,r.key);if(!a||a.state===\"conflicted\")return;let c={...a,state:\"flushing\"};return await this.#e.store.put(c),c});if(!s)continue;t.queued+=1;let o;try{o=await this.#e.send(s)}catch{o=void 0}if(await this.#s(()=>this.#i(s,o,t)).catch(()=>!0))break}if(t.queued>0&&!this.#r)this.#e.onFlush?.(t);return t}async#i(e,t,n){if(this.#r)return!0;let{store:r}=this.#e,s=this.#e.now(),o=await r.get(e.name,e.key);if(!o)return!1;let i=async(d)=>(await r.put({...o,state:\"pending\",updatedAt:s,attempts:o.attempts+(d?1:0)}),!0);if(!t)return i(!0);let{status:a,body:c}=t;if(a===200){let d=c?.version;if(!lt(d))return i(!0);if(n.flushed+=1,!o.next)return await r.delete(o.name,o.key),!1;let{value:p,bytes:h}=o.next;return await r.put({name:o.name,key:o.key,value:p,bytes:h,base:d,id:dt(),state:\"pending\",queuedAt:o.queuedAt,updatedAt:s,edits:1,attempts:0}),!1}let l=Fo(c);if(a===412){let d=Ho(c);if(d)return n.conflicted+=1,await r.put(this.#a(o,s,{conflict:d})),!1;return n.conflicted+=1,await r.put(this.#a(o,s,{refusal:\"unavailable\"})),!1}if(a===401||a===429||l===\"writes-off\"||l===\"sign-in\")return i(!1);if(a>=500||a===408)return i(!0);return n.conflicted+=1,await r.put(this.#a(o,s,{refusal:l??\"unavailable\"})),!1}#a(e,t,n){let{next:r,conflict:s,refusal:o,...i}=e;return{...i,...r?{value:r.value,bytes:r.bytes}:{},state:\"conflicted\",updatedAt:t,...n}}async resolve(e,t,n){if(this.#r)return G(\"no-partition\",\"the queue was wiped\");if(n!==\"local\"&&n!==\"server\")return G(\"bad-body\",'resolve with \"local\" or \"server\"');let r=await this.#s(async()=>{if(this.#r)return G(\"no-partition\",\"the queue was wiped\");let s=await this.#e.store.get(e,t);if(!s)return G(\"no-record\",\"nothing is queued for that key\");if(s.state!==\"conflicted\")return G(\"not-conflicted\",\"that record has no conflict to resolve\");if(n===\"server\")return await this.#e.store.delete(e,t),{ok:!0,...s.conflict?{server:s.conflict}:{}};let{conflict:o,refusal:i,...a}=s;return await this.#e.store.put({...a,base:o?.version??s.base,id:dt(),state:\"pending\",updatedAt:this.#e.now(),edits:1,attempts:0}),{ok:!0}});if(!r.ok||n===\"server\")return r;return{ok:!0,flush:await this.flush({name:e,key:t})}}}var Vo=\"spool-keys\",Xt=\"keys\",Yt=\"meta\",Kt=\"partition\";function Oe(e){return new Promise((t,n)=>{e.onsuccess=()=>t(e.result),e.onerror=()=>n(e.error)})}function Or(e){return new Promise((t,n)=>{let r=e.open(Vo,1);r.onupgradeneeded=()=>{r.result.createObjectStore(Xt),r.result.createObjectStore(Yt)},r.onsuccess=()=>{let s=r.result;s.onversionchange=()=>s.close(),t(s)},r.onerror=()=>n(r.error)})}function Uo(e=indexedDB){let t=new Map,n=Promise.resolve(),r=(i)=>{let a=n.then(i,i);return n=a.catch(()=>{return}),a},s=()=>crypto.subtle.generateKey({name:\"AES-GCM\",length:256},!1,[\"encrypt\",\"decrypt\"]);async function o(i,a){let c=await Or(e);try{let l=c.transaction(Xt,i),d=new Promise((h,y)=>{l.oncomplete=()=>h(),l.onerror=()=>y(l.error),l.onabort=()=>y(l.error)}),p=await a(l.objectStore(Xt));return await d,p}finally{c.close()}}return{get:(i,a,c)=>r(async()=>{if(a===\"session\"){let p=t.get(i);if(!p&&c)p=await s(),t.set(i,p);return p}let l=await o(\"readonly\",(p)=>Oe(p.get(i)));if(l||!c)return l;let d=await s();return await o(\"readwrite\",async(p)=>void await Oe(p.put(d,i))),d}),shred:(i)=>r(async()=>{t.delete(i),await o(\"readwrite\",async(a)=>void await Oe(a.delete(i)))})}}function Dr(e=indexedDB,t=Uo(e)){let n=new Map,r=(o)=>`spool-p-${o}`;async function s(o,i){let a=await Or(e);try{let c=a.transaction(Yt,o),l=new Promise((p,h)=>{c.oncomplete=()=>p(),c.onerror=()=>h(c.error),c.onabort=()=>h(c.error)}),d=await i(c.objectStore(Yt));return await l,d}finally{a.close()}}return{current:async()=>await s(\"readonly\",(o)=>Oe(o.get(Kt)))??null,setCurrent:(o)=>s(\"readwrite\",async(i)=>{if(o===null)await Oe(i.delete(Kt));else await Oe(i.put(o,Kt))}),open(o,i,a,c=!1){let l=n.get(o);if(l)return l.sealed;let d=it(e,r(o)),p=pr(d,{partition:o,vault:t,retentionOf:i,shared:a,...c?{datasets:br(hr(e,o),{partition:o,vault:t,retention:a})}:{}});return n.set(o,{sealed:p,destroy:d.destroy}),p},openWrites:(o)=>Er(e,o,t),async destroy(o){let i=n.get(o);if(i?.sealed.kill(),n.delete(o),await t.shred(o),await Tr(e,o),await wr(e,o),i)await i.destroy();else await new Promise((a)=>{let c=e.deleteDatabase(r(o));c.onsuccess=()=>a(),c.onerror=()=>a()})}}}var Zt=\"/.spool/dropped\",jr=\"/.spool/\",Cr=65536;var Mr=8;var Ir=3600000,Ma=48*Ir,Ia=72*Ir;function $r(e,t){if(!e||e.length===0)return;let n;try{n=new URL(t)}catch{return}return e.find((r)=>{let s=new URL(r.match);return n.origin===s.origin&&n.pathname.startsWith(s.pathname)})}function zo(e,t,n){if(e===\"age-ms\")return String(Math.max(0,Math.round(n-t)));if(e===\"epoch-ms\")return String(Math.round(t));if(e===\"epoch-s\")return String(Math.floor(t/1000));return new Date(t).toISOString().slice(0,19).replace(\"T\",\" \")}function Br(e,t,n,r){let s=new URLSearchParams(e);s.set(t.param,zo(t.kind,n,r));let o=s.toString();return o===\"\"?\"\":`?${o}`}var Se={sync:\"/.spool/sync\",artifact:\"/.spool/artifact\",dataset:\"/.spool/dataset\",beacon:\"/.spool/beacon\",write:\"/.spool/write\",worker:\"/spool-sw.js\"};var W={protocol:\"spool-protocol\",artifact:\"spool-artifact\",invalidate:\"spool-invalidate\",clear:\"spool-clear\",vector:\"spool-vector\",partition:\"spool-partition\",vectorSeen:\"spool-vector-seen\",provision:\"spool-provision\",provisionReason:\"spool-provision-reason\"},en=\"*\",Go=/^[A-Za-z0-9_-]{1,128}$/,Qo=/^[A-Za-z0-9_-]{43}$/;function Pe(e){throw new D(\"bad-header\",e)}function Ue(e,t){if(!/^\\d{1,15}$/.test(e.trim()))return Pe(`${t} must be a non-negative integer`);return Number(e)}function ze(e,t){try{return decodeURIComponent(e)}catch{return Pe(`${t} has a bad escape`)}}function ft(e){return e.split(\",\").map((t)=>t.trim()).filter((t)=>t!==\"\")}function pt(e){try{return tn(e)}catch{let t=e.get(W.protocol)?.trim();if(t&&/^\\d{1,15}$/.test(t)&&Number(t)!==j)return;let n=e.get(W.clear);if(n===null)return;try{return{protocol:j,clear:ft(n).map((r)=>ze(r,\"Spool-Clear\"))}}catch{return{protocol:j,clear:[en]}}}}function tn(e){let t={},n=e.get(W.protocol);if(n!==null)t.protocol=Ue(n,\"Spool-Protocol\");let r=e.get(W.artifact);if(r!==null){let l=new Map;for(let S of r.split(\";\")){let x=S.indexOf(\"=\");if(x<1)return Pe(\"Spool-Artifact has a field without a name\");l.set(S.slice(0,x).trim(),S.slice(x+1).trim())}let d=l.get(\"id\"),p=l.get(\"scope\"),h=l.get(\"v\");if(d===void 0||h===void 0)return Pe(\"Spool-Artifact needs id and v\");if(p!==\"public\"&&p!==\"principal\")return Pe(\"Spool-Artifact scope is unknown\");t.artifact={id:ze(d,\"Spool-Artifact id\"),scope:p,deps:ft(l.get(\"deps\")??\"\").map((S)=>ze(S,\"Spool-Artifact deps\")),version:Ue(h,\"Spool-Artifact v\")};let y=l.get(\"h\");if(y!==void 0&&Qo.test(y))t.artifact.hash=y}let s=e.get(W.invalidate);if(s!==null)t.invalidate=Object.fromEntries(ft(s).map((l)=>{let d=l.lastIndexOf(\"=\");if(d<1)return Pe(\"Spool-Invalidate entries are tag=version\");return[ze(l.slice(0,d),\"Spool-Invalidate tag\"),Ue(l.slice(d+1),\"Spool-Invalidate version\")]}));let o=e.get(W.clear);if(o!==null)t.clear=ft(o).map((l)=>ze(l,\"Spool-Clear\"));let i=e.get(W.vector);if(i!==null)t.vector=Ue(i,\"Spool-Vector\");let a=e.get(W.vectorSeen);if(a!==null)t.seen=Ue(a,\"Spool-Vector-Seen\");let c=e.get(W.partition);if(c!==null){if(!Go.test(c))return Pe(\"Spool-Partition must be a base64url token\");t.partition=c}return t}var qa=new RegExp(`[<>&${String.fromCharCode(8232,8233)}]`,\"g\");function Nr(e){let t=e.lastIndexOf('<script type=\"application/spool+json\" data-spool-artifact>');if(t<0)return null;let n=t+58,r=e.indexOf(\"</script>\",n);return r<0?null:e.slice(n,r)}function _r(e){let t=\"\",n=0;for(;;){let r=e.indexOf('<script type=\"application/spool+json\" data-spool-artifact>',n),s=r<0?-1:e.indexOf(\"</script>\",r+58);if(s<0)return t+e.slice(n);t+=e.slice(n,r),n=s+9}}var qr=200,Jo=/^[1-9]\\d{0,14}$/,Ko=/^[+-]?(\\d+\\.?\\d*|\\.\\d+)(e[+-]?\\d+)?$/i,Xo=/[\\uD800-\\uDBFF](?![\\uDC00-\\uDFFF])|(?<![\\uD800-\\uDBFF])[\\uDC00-\\uDFFF]/;class gt extends Error{}var ie=(e,t)=>Object.hasOwn(e,t)?e[t]??null:null,Yo=(e)=>typeof e===\"object\"&&e!==null&&!Array.isArray(e),F=(e)=>typeof e===\"number\"?1:typeof e===\"string\"?2:0,mt=(e)=>e.replace(/[A-Z]+/g,(t)=>t.toLowerCase());function Lr(e){if(e===null||e===void 0)return!0;if(typeof e===\"number\")return Number.isFinite(e);if(typeof e===\"string\")return!Xo.test(e)&&!e.includes(\"\\x00\");return!1}function Qe(e,t){let n=Math.min(e.length,t.length);for(let r=0;r<n;r++){let s=e.charCodeAt(r),o=t.charCodeAt(r);if(s===o)continue;let i=s>=55296&&s<=57343,a=o>=55296&&o<=57343;if(i!==a)return i?1:-1;return s-o}return e.length-t.length}function me(e,t){let n=F(e),r=F(t);if(n!==r)return n-r;if(n===0)return 0;if(n===1)return e<t?-1:e>t?1:0;return Qe(e,t)}function Zo(e,t){for(let n=0;n<e.length;n++){let r=me(e[n],t[n]);if(r!==0)return r}return 0}var Fr=(e,t)=>F(e)!==0&&F(e)===F(t)&&e===t,nn=(e)=>e.sort(Qe);function Ge(e,t){let n=0,r=e.length;while(n<r){let s=n+r>>>1;if(t(e[s]))r=s;else n=s+1}return n}class sn{#e;#t;#n=new Map;#r=new Map;#s=new Map;#o=0;#i=0;constructor(e,t){this.#e=e,this.#t=t}get built(){return this.#o}get entries(){return this.#i}clean(e){let t=this.#n.get(e);if(t===void 0)t=this.#e.every((n)=>Lr(ie(this.#t.get(n),e))),this.#n.set(e,t);return t}equal(e,t){let n=this.#a(e),r=t.length===1?n.get(`${F(t[0])}${String(t[0])}`):void 0;if(r)return[...r];let s=new Set;for(let o of t)for(let i of n.get(`${F(o)}${String(o)}`)??[])s.add(i);return nn([...s])}range(e,t,n){let r=this.#c(`r\\x00${e}`,e,(l)=>F(l)===0?void 0:l),s=F(n),o=Ge(r,(l)=>F(l[0])>=s),i=Ge(r,(l)=>F(l[0])>s),[a,c]=t===\"gte\"?[Ge(r,(l)=>me(l[0],n)>=0),i]:[o,Ge(r,(l)=>me(l[0],n)>0)];return nn(r.slice(Math.max(a,o),c).map((l)=>l[1]))}prefix(e,t,n){let r=this.#c(`p\\x00${t??\"\"}\\x00${e}`,e,(i)=>typeof i===\"string\"?t===\"ascii\"?mt(i):i:void 0),s=t===\"ascii\"?mt(n):n,o=[];for(let i=Ge(r,(a)=>me(a[0],s)>=0);i<r.length;i++){let[a,c]=r[i];if(!a.startsWith(s))break;o.push(c)}return nn(o)}#a(e){let t=this.#r.get(e);if(!t){t=new Map;for(let n of this.#e){let r=ie(this.#t.get(n),e);if(F(r)===0)continue;let s=`${F(r)}${String(r)}`,o=t.get(s);if(o)o.push(n);else t.set(s,[n]);this.#i+=1}this.#r.set(e,t),this.#o+=1}return t}#c(e,t,n){let r=this.#s.get(e);if(!r){r=[];for(let s of this.#e){let o=n(ie(this.#t.get(s),t));if(o!==void 0)r.push([o,s])}r.sort((s,o)=>me(s[0],o[0])||Qe(s[1],o[1])),this.#s.set(e,r),this.#o+=1,this.#i+=r.length}return r}}function Wr(e,t){if(e.index)return e.index.clean(t);return e.keys.every((n)=>Lr(ie(e.rows.get(n),t)))}function yt(e,t){if(e.from.includes(t))return{join:-1,field:t};let n=t.indexOf(\".\");if(n<0)return;let r=t.slice(0,n),s=t.slice(n+1),o=(e.join??[]).findIndex((i)=>i.as===r);if(o<0||!(e.join?.[o]?.fields??[]).includes(s))return;return{join:o,field:s}}function ht(e,t){if(t.join<0)return ie(e.base,t.field);let n=e.joined[t.join];return n?ie(n,t.field):null}function ei(e,t){if(e.op!==\"in\"&&t.length!==1)return null;let n=[];for(let r of t)if(e.type===\"number\"){if(!Ko.test(r))return null;let s=Number(r);if(!Number.isFinite(s))return null;n.push(s)}else{if(r.includes(\"\\x00\"))return null;n.push(r)}return n}function ti(e,t){let{cond:n,values:r}=e;if(n.op===\"eq\"||n.op===\"in\")return r.some((o)=>Fr(t,o));if(n.op===\"gte\"||n.op===\"lte\"){let o=r[0];if(F(t)===0||F(t)!==F(o))return!1;let i=me(t,o);return n.op===\"gte\"?i>=0:i<=0}if(typeof t!==\"string\")return!1;let s=r[0];return n.fold===\"ascii\"?mt(t).startsWith(mt(s)):t.startsWith(s)}function ni(e,t,n){let r=ie(n,e.on[0]);if(e.on[1]===null)return typeof r===\"string\"&&t.rows.has(r)?[r]:[];if(F(r)===0)return[];let s=e.on[1];if(t.index&&t.keys.length>=qr)return t.index.equal(s,[r]);return t.keys.filter((o)=>Fr(ie(t.rows.get(o),s),r))}function rn(e,t,n,r,s){if(r===e.length){s.push(n);return}let o=e[r],i=t[r],a=ni(o,i,n.base);if(a.length===0){if(o.type===\"left\")rn(e,t,{...n,keys:[...n.keys,null],joined:[...n.joined,null]},r+1,s);return}for(let c of a){let l=i.rows.get(c);rn(e,t,{base:n.base,keys:[...n.keys,c],joined:[...n.joined,l]},r+1,s)}}function ri(e,t,n){if(t===\"count\")return n.length;let[r,s]=Object.entries(t)[0],o=yt(e,s),i=n.map((c)=>ht(c,o)).filter((c)=>c!==null);if(r===\"count\")return i.length;if(r===\"min\"||r===\"max\"){if(i.length===0)return null;return i.reduce((c,l)=>{let d=me(l,c);return r===\"min\"?d<0?l:c:d>0?l:c})}if(i.length===0)return null;let a=0;for(let c of i){if(typeof c!==\"number\"||!Number.isSafeInteger(c))throw new gt;if(a+=c,!Number.isSafeInteger(a))throw new gt}return r===\"sum\"?a:a/i.length}function si(e,t){let n=e.from.map((s)=>[s,ie(t.base,s)]),r=(e.join??[]).map((s,o)=>{let i=t.joined[o],a=s.fields.map((c)=>[c,i?ie(i,c):null]);return[s.as,Object.fromEntries(a)]});return Object.fromEntries([...n,...r])}function oi(e,t,n,r){let s=t.by.map((a)=>yt(e,a)),o=new Map;if(t.by.length===0)o.set(\"[]\",{by:[],members:[]});for(let a of n){let c=s.map((p)=>ht(a,p)),l=JSON.stringify(c.map((p)=>p===null?\"0\":`${F(p)}${String(p)}`)),d=o.get(l)??{by:c,members:[]};d.members.push(a),o.set(l,d)}let i=Object.entries(t.aggregates);return[...o.values()].map(({by:a,members:c})=>{let l=Object.fromEntries([...t.by.map((d,p)=>[d,a[p]??null]),...i.map(([d,p])=>[d,ri(e,p,c)])]);return{row:l,sort:r.map((d)=>l[d]),tie:a}})}function ii(e,t,n){let r=new URLSearchParams(t),s=e.where??[],o=e.join??[];for(let k of new Set(r.keys()))if(k!==\"sort\"&&k!==\"page\"&&!s.some((E)=>E.param===k))return null;let i=[];for(let k of s){let E=r.getAll(k.param);if(E.length===0)continue;let M=ei(k,E);if(!M)return null;i.push({cond:k,ref:yt(e,k.field),values:M})}let a=r.getAll(\"sort\");if(a.length>1)return null;let c=[];if(a.length===1){let k=a[0],E=k.startsWith(\"-\"),M=E?k.slice(1):k;if(!(e.sort??[]).includes(M))return null;c.push({name:M,desc:E})}let l=r.getAll(\"page\");if(l.length>1)return null;let d=1;if(l.length===1){if(!Jo.test(l[0]))return null;d=Number(l[0])}let p=n.base,h=[];for(let k of o){let E=n.joined(k.dataset);if(!E)return null;h.push(E)}for(let k of e.from)if(!Wr(p,k))return null;for(let k=0;k<o.length;k++){let E=o[k],M=E.on[1]===null?E.fields:[...E.fields,E.on[1]];for(let he of M)if(!Wr(h[k],he))return null}let y=p.keys,S=i.find((k)=>k.ref.join<0);if(S&&p.index&&p.keys.length>=qr){let{cond:k,ref:E,values:M}=S;y=k.op===\"gte\"||k.op===\"lte\"?p.index.range(E.field,k.op,M[0]):k.op===\"prefix\"?p.index.prefix(E.field,k.fold,M[0]):p.index.equal(E.field,M)}let x=[];for(let k of y){let E=p.rows.get(k);rn(o,h,{base:E,keys:[k],joined:[]},0,x)}let T=x.filter((k)=>i.every((E)=>ti(E,ht(k,E.ref)))),N=e.group,C=c.map((k)=>k.name),q;if(N)q=oi(e,N,T,C);else{if(T.length>e.limit)return null;let k=C.map((E)=>yt(e,E));q=T.map((E)=>({row:si(e,E),sort:k.map((M)=>ht(E,M)),tie:E.keys}))}if(q.length>e.limit)return null;q.sort((k,E)=>{for(let M=0;M<c.length;M++){let he=me(k.sort[M],E.sort[M]);if(he!==0)return c[M]?.desc?-he:he}return Zo(k.tie,E.tie)});let H=q.length,ae=e.pageSize,Ye=Math.max(1,Math.ceil(H/ae));if(d>Ye)return null;return{items:q.slice((d-1)*ae,d*ae).map((k)=>k.row),total:H,page:d,pages:Ye}}function ai(e,t,n){try{return ii(e,t,n)}catch(r){if(r instanceof gt)return null;throw r}}function Hr(e,t,n,r,s){if(!s)return{ok:!1,reason:\"plan needs its datasets\"};let o=ai(t,r,s);if(!o)return{ok:!1,reason:\"query is not one the route declares\"};let{items:i,total:a,page:c,pages:l}=o;return{ok:!0,data:{...Yo(n)?n:{},[e]:i,query:{total:a,page:c,pages:l}}}}var Vr={public:{maxStale:900,mode:\"soft\"},principal:{maxStale:300,mode:\"hard\"}};function ne(e,t){for(let n of e){let r=ut(n.pattern,t);if(r)return{route:n,params:r}}return null}var Ur=1,zr=256;function Q(e){throw new D(\"bad-manifest\",e)}function on(e){return typeof e===\"object\"&&e!==null&&!Array.isArray(e)}function ci(e,t){let n=`routes[${t}]`;if(!on(e))return Q(`${n} must be an object`);let{pattern:r,strategy:s,version:o,freshness:i,offline:a,sync:c}=e;if(typeof r!==\"string\")return Q(`${n}.pattern must be a string`);try{ct(r)}catch(d){return Q(`${n}: ${d instanceof Error?d.message:\"bad pattern\"}`)}if(s!==\"static\")return Q(`${r}: strategy must be \"static\"`);if(typeof o!==\"string\"||o===\"\"||o.length>zr)return Q(`${r}: version must be a string of 1 to ${zr} characters`);let l={pattern:r,strategy:s,version:o};if(i!==void 0){if(!on(i))return Q(`${r}: freshness must be an object`);let{maxStale:d,mode:p}=i;if(d!==void 0){if(typeof d!==\"number\"||!Number.isFinite(d)||d<=0)return Q(`${r}: freshness.maxStale must be a positive number of seconds`)}if(p!==void 0&&p!==\"hard\"&&p!==\"soft\")return Q(`${r}: freshness.mode must be \"hard\" or \"soft\"`);l.freshness={...d===void 0?{}:{maxStale:d},...p===void 0?{}:{mode:p}}}if(a!==void 0){if(a!==\"serve\"&&a!==\"refuse\")return Q(`${r}: offline must be \"serve\" or \"refuse\"`);l.offline=a}if(c!==void 0){if(c!==\"background\"&&c!==\"deferred\")return Q(`${r}: sync must be \"background\" or \"deferred\"`);l.sync=c}return l}function an(e){if(!on(e))return Q(\"manifest must be an object\");if(e.schema!==Ur)return Q(\"unsupported manifest schema\");let{routes:t}=e;if(!Array.isArray(t))return Q(\"routes must be a list\");let n=t.map(ci),r=new Set;for(let s of n){if(r.has(s.pattern))return Q(`${s.pattern}: declared twice`);r.add(s.pattern)}return{schema:Ur,routes:n}}function cn(e){return e.routes.map((t)=>({pattern:t.pattern,strategy:\"static\",scope:\"public\",freshness:{...Vr.public,...t.freshness},persist:!0,offline:t.offline??\"serve\",sync:t.sync??\"background\",version:t.version}))}var Je=\"spool:artifact:\",un=64,Gr=256;function ln(e){return`${Je}${e}`}function ye(e){throw new D(\"bad-sync\",e)}function dn(e){return Object.entries(e).map(([t,n])=>`${encodeURIComponent(t)}@${n}`).join(\",\")}function Qr(e){if(typeof e!==\"object\"||e===null)return ye(\"sync response must be an object\");let t=e;if(t.protocol!==j)return ye(\"unsupported protocol version\");let{cursor:n,changed:r,dropped:s,reset:o,partial:i}=t;if(typeof n!==\"number\"||!Number.isSafeInteger(n)||n<0)return ye(\"cursor must be a non-negative integer\");if(typeof r!==\"object\"||r===null||Array.isArray(r))return ye(\"changed must be an object\");for(let c of Object.values(r))if(typeof c!==\"number\"||!Number.isSafeInteger(c))return ye(\"changed versions must be integers\");if(!Array.isArray(s)||s.some((c)=>typeof c!==\"string\"))return ye(\"dropped must be a list of strings\");if(typeof o!==\"boolean\")return ye(\"reset must be a boolean\");if(i!==void 0&&typeof i!==\"boolean\")return ye(\"partial must be a boolean\");let a={protocol:j,cursor:n,changed:r,dropped:s,reset:o};if(i)a.partial=!0;return a}var fn={cold:\"network\",principal:\"network\",fresh:\"local\",catalogue:\"local\",\"soft-deferred\":\"local\",\"soft-sync\":\"local-revalidate\",\"hard-sync\":\"local-revalidate\",\"offline-stale\":\"local-revalidate\",invalidated:\"fallback\",\"stale-after-sync\":\"fallback\",\"hard-refused\":\"fallback\",refused:\"fallback\"};var Jr=\"external\",pn=\"/.spool/view\",Kr=\"/.spool/loads\";function Xr(e,t,n,r){return{path:\"/.spool/loads\",body:JSON.stringify(r&&Object.keys(r).length>0?{view:e,count:t,origins:r}:{view:e,count:t}),contentType:\"application/json\",at:n}}function Yr(e,t){return{path:\"/.spool/view\",body:JSON.stringify(e),contentType:\"application/json\",at:t}}function Zr(e){if(/\\b(?:CriOS|FxiOS|EdgiOS|OPiOS)\\//.test(e))return\"webkit\";if(/\\bFirefox\\//.test(e))return\"firefox\";if(/\\b(?:Chrome|Chromium)\\//.test(e))return\"chromium\";if(/\\bSafari\\//.test(e))return\"webkit\";return\"other\"}var es=86400000,ui=3600000,li=20,di=3600000,fi=86400000,pi=256,ts=100,rs=3000,ns=\"same-origin\";function gi(e,t){let n,r=new Promise((s,o)=>{n=setTimeout(()=>o(Error(\"timed out\")),t)});return Promise.race([e,r]).finally(()=>clearTimeout(n))}var mi=new TextEncoder,wt=(e)=>e.path.startsWith(jr)||e.deliver===\"sink\";class gn{#e;#t=null;#n;dropped=new Map;constructor(e){this.#e=e}async record(e){await this.#e.storage.addBeacon(e)}async enqueue(e,t){let n=e.method===\"GET\",r=n?\"\":e.headers.get(\"content-type\")??\"text/plain\";if(/octet-stream|multipart|image\\//i.test(r))return!1;let s=n?\"\":await e.clone().text();if(mi.encode(s).length>Cr)return!1;let o=new URL(e.url),i=this.#e.now(),a={path:o.pathname,body:s,contentType:r,at:i};if(o.search!==\"\")a.search=o.search;if(n)a.method=\"GET\";if(t){if(a.origin=o.origin,a.vendor=t.vendor,a.until=i+t.maxAgeMs,t.delivery===\"sink\")a.deliver=\"sink\"}return await this.#e.storage.addBeacon(a),!0}flush(){return this.#t??=this.#a().finally(()=>{this.#t=null}),this.#t}async flushAtMoment(){await this.#o();let e=await this.#e.storage.readBeacons();if(e.length===0)return!1;let t=(c)=>c===pn||c===Kr||c===Zt,n=e.some((c)=>!t(c.event.path)),r=e.filter((c)=>c.event.path===pn).length,s=(await this.#e.want?.()??[]).length>0,o=await this.#c(this.#e.catalogue?.())!==void 0,i=Math.min(...e.map((c)=>c.event.at)),a=this.#e.now()-i>=di;if(n||s||o||a||r>=li)return this.flush();return!1}async flushIfDue(){let e=this.#e.now(),t=await this.#r(),n=t.checkedAt>e?-1/0:t.checkedAt;if(e-n<ui)return!1;t.checkedAt=e,await this.#s(t),await this.#o();let r=await this.#e.storage.readBeacons(),s=Math.min(...r.map((i)=>i.event.at));if(r.length===0||e-s<es)return!1;let o=t.lastStandalone>e?-1/0:t.lastStandalone;if(e-o<es)return!1;return t.lastStandalone=e,await this.#s(t),this.flush()}async#r(){return this.#n??=await this.#e.storage.getFlush()??{lastStandalone:-1/0,checkedAt:-1/0},this.#n}async#s(e){await this.#e.storage.setFlush(e)}async#o(){let{storage:e,now:t}=this.#e,n=t(),s=(await e.readBeacons()).filter((o)=>o.event.until!==void 0&&o.event.until<n);if(s.length===0)return;await e.removeBeacons(s.map((o)=>o.key)),await this.#i(s.map(({event:o})=>o.vendor??\"unknown\"))}async#i(e){let t=new Map;for(let n of e)t.set(n,(t.get(n)??0)+1);for(let[n,r]of t)this.dropped.set(n,(this.dropped.get(n)??0)+r),await this.#e.storage.addBeacon({path:Zt,body:JSON.stringify({vendor:n,count:r}),contentType:\"application/json\",at:this.#e.now()})}async sendSameOrigin(e){if(this.#t)await this.#t.catch(()=>!1);let{storage:t,replay:n}=this.#e,r=(await t.readBeacons()).filter(({event:i})=>!wt(i)&&i.origin===void 0);if(r.length===0)return;await t.removeBeacons(r.map((i)=>i.key));let s=!1,o=[];for(let{event:i}of r){let a=!1;if(!s)try{a=await gi(n(i),e)}catch{s=!0}if(!a)o.push(ns)}await this.#i(o)}async dropSameOrigin(){if(this.#t)await this.#t.catch(()=>!1);let e=(await this.#e.storage.readBeacons()).filter(({event:t})=>!wt(t)&&t.origin===void 0);if(e.length===0)return;await this.#e.storage.removeBeacons(e.map((t)=>t.key)),await this.#i(e.map(()=>ns))}async#a(){let{storage:e,send:t,replay:n,want:r,catalogue:s}=this.#e;await this.#o();let o=await e.readBeacons();if(o.length===0)return!1;let i=!0;for(let p of o.filter((h)=>!wt(h.event))){let h;try{h=await n(p.event)}catch{h=!1}if(h)await e.removeBeacons([p.key]);else i=!1}let a=o.filter((p)=>wt(p.event)),c=await r?.()??[],l=await this.#c(s?.());if(a.length===0&&c.length===0)return i;let d=!0;for(let p=0;p<Math.max(a.length,1);p+=ts){let h=a.slice(p,p+ts),y={protocol:j,events:h.map(({event:{until:S,...x}})=>x)};if(c.length>0)y.want=c;if(l)y.catalogue=l;c=[],l=void 0;try{d=await t(y)}catch{d=!1}if(!d)return!1;if(await e.removeBeacons(h.map((S)=>S.key)),y.catalogue)await this.#u(y.catalogue.path)}return i&&d}async#c(e){if(!e)return;let t=(await this.#r()).catalogue?.[e.path],n=this.#e.now();return t===void 0||t>n||n-t>=fi?e:void 0}async#u(e){let t=await this.#r(),n={...t.catalogue};delete n[e],n[e]=this.#e.now();let r=Object.keys(n);for(let s of r.slice(0,r.length-pi))delete n[s];t.catalogue=n,await this.#s(t)}}function yi(e){try{return new URL(e).origin}catch{return null}}var hi=Uint8Array.from(atob(\"R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7\"),(e)=>e.charCodeAt(0));function ss(e){let t=new Headers;if(e.mode===\"cors\"){let n=e.headers.get(\"origin\")??yi(e.referrer);if(e.credentials===\"include\"&&n)t.set(\"access-control-allow-origin\",n),t.set(\"access-control-allow-credentials\",\"true\");else t.set(\"access-control-allow-origin\",\"*\")}if(e.method===\"GET\")return t.set(\"content-type\",\"image/gif\"),t.set(\"cache-control\",\"no-store\"),new Response(hi,{status:200,headers:t});return new Response(null,{status:204,headers:t})}function K(e){throw new D(\"bad-dataset\",e)}function is(e){let t=new URLSearchParams({name:e.name});if(e.since!==void 0)t.set(\"since\",String(e.since));if(e.schema!==void 0)t.set(\"schema\",e.schema);if(e.after!==void 0)t.set(\"after\",e.after);if(e.limit!==void 0)t.set(\"limit\",String(e.limit));return t.toString()}var bt=(e)=>typeof e===\"object\"&&e!==null&&!Array.isArray(e),os=(e)=>typeof e===\"number\"&&Number.isSafeInteger(e)&&e>=0;function as(e){if(!bt(e))return K(\"dataset response must be an object\");if(e.protocol!==j)return K(\"unsupported protocol version\");let{name:t,schema:n,cursor:r,reset:s,puts:o,deletes:i,after:a,next:c,proof:l}=e;if(typeof t!==\"string\"||typeof n!==\"string\")return K(\"name and schema must be strings\");if(!os(r))return K(\"cursor must be a non-negative integer\");if(typeof s!==\"boolean\")return K(\"reset must be a boolean\");if(!Array.isArray(o))return K(\"puts must be a list\");let d=o.map((y)=>{if(!bt(y)||typeof y.key!==\"string\"||!bt(y.row))return K(\"a put is { key, row }\");return{key:y.key,row:y.row}});if(!Array.isArray(i))return K(\"deletes must be a list\");let p=i.map((y)=>{if(!bt(y)||typeof y.key!==\"string\"||!os(y.cursor))return K(\"a delete is { key, cursor }\");return{key:y.key,cursor:y.cursor}}),h={protocol:j,name:t,schema:n,cursor:r,reset:s,puts:d,deletes:p};if(a!==void 0){if(typeof a!==\"string\")return K(\"after must be a string\");h.after=a}if(c!==void 0){if(typeof c!==\"string\")return K(\"next must be a string\");h.next=c}if(l!==void 0){if(!Lt(l))return K(\"proof must be a set proof\");h.proof={kind:\"set\",count:l.count,digest:l.digest}}if(h.next===void 0&&h.proof===void 0)return K(\"a response without next carries a proof\");return h}async function cs(e,t,n,r={}){let s=r.hash??Nt,o=t.reset&&t.after===void 0,i=new Map(o?[]:e),a=r.hashes?new Map(o?[]:r.hashes):void 0,c=o?We:n??(await qt(e)).digest,l=async(p)=>{let h=i.get(p);if(h===void 0)return;c=or(c,a?.get(p)??await s(p,h)),i.delete(p),a?.delete(p)};for(let{key:p}of t.deletes)await l(p);for(let{key:p,row:h}of t.puts){await l(p),i.set(p,h);let y=await s(p,h);a?.set(p,y),c=st(c,y)}let d=t.proof;return{rows:i,digest:c,matches:d===void 0?null:d.count===i.size&&d.digest===c,...a?{hashes:a}:{}}}function us(e){return(t)=>{if(t.status===401)return\"ended\";if(t.status===403)return\"revoked\";if(t.ok&&t.headers.get(W.partition)!==e)return\"partition\";return\"ok\"}}var wi=1000;class z extends Error{reason;by;constructor(e,t){super(e);this.reason=e;this.by=t}}async function ls(e,t){let{store:n,origin:r}=e,s=e.epoch(),o=0,i=async(l)=>{o+=1;let d=await e.fetch(`${r}${Se.dataset}?${is(l)}`,{cache:\"no-store\",credentials:\"same-origin\"}),p=e.guard?.(d)??\"ok\";if(p!==\"ok\")throw new z(p);if(d.status===409)throw new z(\"declined\",d.headers.get(W.provisionReason));if(d.status===400||d.status===404)throw new z(\"unavailable\");if(!d.ok)throw TypeError(`dataset answered ${d.status}`);let h=as(await d.json());if(h.name!==t)throw new z(\"bad-response\");return h},a=async(l,d,p)=>{try{if(e.epoch()!==s)throw new z(\"epoch\");if(!await n.commit(l,d,s))throw new z(\"epoch\")}catch(h){if(h instanceof z)throw h;throw new z(\"storage\")}return{name:t,requests:o,status:p,cursor:d.cursor,rows:l.rows.size}},c=async(l,d,p)=>{let h=l??await i({name:t}),{cursor:y,schema:S}=h,x=await e.budget(),T=n.stage(t),N,C;for(let H=1;;H+=1){if(e.epoch()!==s)throw new z(\"epoch\");if(N=await T.add(h),x!==void 0&&T.bytes>x)throw new z(\"budget\");if(h.next===void 0)break;if(H>=wi||C!==void 0&&h.next<=C)throw new z(\"bad-response\");C=h.next,h=await i({name:t,after:C})}if(N===!0)return a(T,{cursor:y,schema:S},d);let q=await i({name:t,since:y,schema:S});if(!q.reset&&await T.add(q)===!0)return a(T,{cursor:q.cursor,schema:S},d);if(p)return c(void 0,\"reseeded\",!1);throw new z(\"proof\")};try{let l=await n.get(t);if(!l)return await c(void 0,\"seeded\",!0);let{cursor:d,schema:p,digest:h,count:y}=l.meta,S=await i({name:t,since:d,schema:p});if(S.reset)return await c(S,\"reseeded\",!0);if(S.cursor<d)return{name:t,requests:o,status:\"current\",cursor:d,rows:y};let x=S.proof;if(S.cursor===d){if(x&&(x.count!==y||x.digest!==h))return await n.drop(t),await c(void 0,\"reseeded\",!1);if(!await n.touch(t,s))throw new z(\"epoch\");return{name:t,requests:o,status:\"current\",cursor:d,rows:y}}let T=n.stage(t,l);if(await T.add(S)===!0)return await a(T,{cursor:S.cursor,schema:p},\"patched\");return await n.drop(t),await c(void 0,\"reseeded\",!1)}catch(l){if(l instanceof z){if(l.reason===\"revoked\"&&e.epoch()===s)await n.drop(t).catch(()=>{return});return{name:t,requests:o,status:\"refused\",reason:l.reason,by:l.by}}if(l instanceof D)return{name:t,requests:o,status:\"refused\",reason:\"bad-response\"};return{name:t,requests:o,status:\"offline\"}}}function ds(e,t,n){if((n>=t?(n-t)/1000:1/0)<=e.maxStale)return\"serve\";return e.mode===\"hard\"?\"sync-first\":\"serve-then-sync\"}function fs(e,t){return Math.max(e,t)}function ps(e,t){return e.deps.every((n)=>t(n)<=e.vector)}var bi=[\"content-security-policy\",\"content-security-policy-report-only\",\"x-frame-options\",\"x-content-type-options\",\"referrer-policy\",\"permissions-policy\",\"cross-origin-opener-policy\",\"cross-origin-embedder-policy\",\"cross-origin-resource-policy\"],gs=128;function ms(e){let t=[];for(let n of bi){let r=e.get(n);if(r!==null)t.push([n,r])}return t}var ve={reuse:0.5,futureViews:2,requestBytes:2000,artifactBytes:20000,avoidedBytes:17054,changesPerDay:1};function hs(e){let{hot:t,...n}=e??{};return{...ve,...n}}function Ri(e,t){return e.bytes+e.requests*t}var Si={bytes:0,requests:0};function Pi(e,t=ve){let n=e.reuse??t.reuse,r=e.futureViews??t.futureViews,s=(o)=>Ri(o,t.requestBytes);return n*r*s(e.avoided)-s(e.provision)-s(e.maintain??Si)}var ys={layout:0,template:0,asset:0,route:1,expansion:2};function ws(e,t=ve){return e.map((n)=>({...n,benefit:Pi(n,t)})).filter((n)=>n.benefit>0).sort((n,r)=>ys[n.kind]-ys[r.kind]||r.benefit-n.benefit||(n.id<r.id?-1:n.id>r.id?1:0))}class mn{#e=new Map;#t(e){let t=this.#e.get(e)??{id:e,bytes:0,requests:0,views:0,catalogueBytes:0,catalogueViews:0};return this.#e.set(e,t),t}spend(e,t,n=!1){let r=this.#t(e);if(r.bytes+=t.bytes,r.requests+=t.requests,n)r.catalogueBytes+=t.bytes}serve(e,t=!1){let n=this.#t(e);if(n.views+=1,t)n.catalogueViews+=1}entries(){return[...this.#e.values()].map((e)=>({...e})).sort((e,t)=>e.id<t.id?-1:1)}totals(){let e=[...this.#e.values()],t=(s)=>e.reduce((o,i)=>o+s(i),0),n=t((s)=>s.views),r=t((s)=>s.bytes);return{bytes:r,requests:t((s)=>s.requests),views:n,bytesPerView:n===0?null:r/n,catalogueBytes:t((s)=>s.catalogueBytes),catalogueViews:t((s)=>s.catalogueViews)}}meanFetchBytes(){let e=[...this.#e.values()].filter((t)=>t.bytes>t.catalogueBytes);return e.length===0?null:e.reduce((t,n)=>t+n.bytes-n.catalogueBytes,0)/e.length}}var vi=/<span data-spool-placeholder=\"([^\"]*)\"><\\/span>/g,xi=/\\{\\{spool-slot:([A-Za-z0-9_.-]+)\\}\\}/g;function bs(e,t,n){let r=[],s=[],o=new Set,i=e.replace(t,(c,l)=>{o.add(l);let d=Object.hasOwn(n,l)?n[l]:void 0;if(d===void 0)return s.push(l),c;return r.push(l),d}),a=Object.keys(n).filter((c)=>!o.has(c));return{html:i,filled:r,unfilled:s,unmatched:a}}function ki(e,t){return bs(e,vi,t)}function Ai(e,t){return bs(e,xi,t)}function Rs(e){let t=(i)=>{let a={};for(let[c,l]of Object.entries(i??{})){if(typeof l!==\"string\")return null;a[c]=l}return a},n=t(e.fragments),r=t(e.slots);if(!n||!r)return{ok:!1,reason:\"unresolved reference\"};let s=ki(e.shell,n);if(s.unfilled.length>0)return{ok:!1,reason:`unfilled placeholders: ${s.unfilled.join(\", \")}`};let o=Ai(s.html,r);if(o.unfilled.length>0)return{ok:!1,reason:`unfilled slots: ${o.unfilled.join(\", \")}`};return{ok:!0,html:o.html}}function Ss(e,t){if(e.includes(\"data-spool-client\"))return e;for(let n of[/<\\/head\\s*>/i,/<\\/body\\s*>/i]){let r=e.search(n);if(r>=0)return e.slice(0,r)+t+e.slice(r)}return e+t}var Ei={\"&\":\"&\",\"<\":\"<\",\">\":\">\",'\"':\""\",\"'\":\"'\"};function Ti(e){return e.replace(/[&<>\"']/g,(t)=>Ei[t])}function Ps(e,t){if(e===null||typeof e!==\"object\")return;return Object.hasOwn(e,t)?e[t]:void 0}function yn(e,t){let n=t[t.length-1];if(e.length===0)return n.value;if(e[0]===\"@index\")return n.index;for(let r=t.length-1;r>=0;r--){let s=t[r];if(Ps(s.value,e[0])===void 0)continue;return e.reduce((o,i)=>Ps(o,i),s.value)}return}function Oi(e){if(Array.isArray(e))return e.length>0;return!(e===void 0||e===null||e===!1||e===\"\"||e===0)}function Di(e){return typeof e===\"string\"||typeof e===\"number\"?String(e):\"\"}function hn(e,t,n){let r=\"\";for(let s of e)if(s.t===\"text\")r+=s.v;else if(s.t===\"var\"){let o=Di(yn(s.p,t));if(!s.raw)r+=Ti(o);else if(n.has(s.p.join(\".\")))r+=o;else throw new D(\"bad-template\",`{{{${s.p.join(\".\")}}}} is not trusted`)}else if(s.t===\"if\")r+=hn(Oi(yn(s.p,t))?s.then:s.else,t,n);else{let o=yn(s.p,t);if(!Array.isArray(o))continue;o.forEach((i,a)=>{r+=hn(s.body,[...t,{value:i,index:a}],n)})}return r}function vs(e,t){if(e.v!==1)throw new D(\"bad-template\",`unknown template version ${String(e.v)}`);return hn(e.nodes,[{value:t,index:0}],new Set(e.trusted))}var ji=(e)=>typeof e===\"object\"&&e!==null&&!Array.isArray(e);async function xs(e,t,n,r={},s,o,i){try{let a=n,c=t.query;if(c&&(c.plan!==void 0||o!==void 0||s!==void 0&&s!==\"\")){if(n.strategy===\"assembly\"||n.strategy===\"static\")return{ok:!1,reason:`${n.strategy} artifact cannot answer a query`};let p=n.body.data,h=c.plan?Hr(c.list,c.plan,p,s??\"\",i):o===void 0?await ar(c,p,s??\"\",ir(c)):Ft(c,{...ji(p)?p:{},[c.list]:o},s??\"\");if(!h.ok)return h;a={...n,body:{data:h.data}}}let l=Object.hasOwn(r,t.pattern)?r[t.pattern]:void 0,d;if(l)d=await l(a);else if(a.strategy===\"data\"&&t.strategy===\"data\")return{ok:!0,html:JSON.stringify(a.body.data)};else if(a.strategy===\"projection\"&&t.strategy===\"projection\")return{ok:!1,reason:`no renderer for ${t.pattern}`};else if(a.strategy===\"static\"||a.strategy!==t.strategy)return{ok:!1,reason:`artifact is ${a.strategy}, route is ${t.strategy}`};else if(a.strategy===\"assembly\"){let p=Rs(a.body);if(!p.ok)return p;d=p.html}else if(a.strategy!==\"template\")return{ok:!1,reason:`${a.strategy} has no built-in render`};else{let p=Object.hasOwn(e.templates,t.pattern)?e.templates[t.pattern]:void 0;if(!p)return{ok:!1,reason:`no template for ${t.pattern}`};d=vs(p,a.body.data)}if(t.strategy===\"data\")return{ok:!0,html:d};return{ok:!0,html:Ss(d,e.clientTag)}}catch(a){return{ok:!1,reason:a instanceof Error?a.message:\"render failed\"}}}var Ci=new TextEncoder,wn=(e)=>Ci.encode(JSON.stringify(e)).length;class ks{name;clear;rows;hashes;digest;bytes;#e;#t=new Set;#n=new Set;constructor(e,t,n){this.#e=e,this.name=t,this.clear=n===void 0,this.rows=n?.rows??new Map,this.hashes=n?.hashes??new Map,this.digest=n?.meta.digest??We,this.bytes=n?.meta.bytes??0}async add(e){let t=e.reset&&e.after===void 0;if(t)this.clear=!0,this.bytes=0,this.#t.clear(),this.#n.clear();let n=new Map,r=(i)=>n.has(i)?n.get(i):t?void 0:this.rows.get(i);for(let{key:i}of e.deletes){let a=r(i);if(a!==void 0)this.bytes-=wn(a);n.set(i,void 0)}for(let{key:i,row:a}of e.puts){let c=r(i);if(c!==void 0)this.bytes-=wn(c);this.bytes+=wn(a),n.set(i,a)}let s={hashes:this.hashes,...this.#e.hash?{hash:this.#e.hash}:{}},o=await cs(this.rows,e,this.digest,s);this.rows=o.rows,this.hashes=o.hashes,this.digest=o.digest;for(let{key:i}of e.deletes)this.#n.add(i),this.#t.delete(i);for(let{key:i}of e.puts)this.#t.add(i),this.#n.delete(i);return o.matches}writes(){return{puts:(this.clear?[...this.rows.keys()]:[...this.#t]).map((t)=>({name:this.name,key:t,row:this.rows.get(t),hash:this.hashes.get(t)})),deletes:this.clear?[]:[...this.#n]}}}class bn{#e;#t=new Map;#n=new Map;#r;#s=Promise.resolve();#o=new Map;#i=new Map;evicted=0;constructor(e){this.#e=e}#a(e){let t=this.#s.then(e,e);return this.#s=t.catch(()=>{return}),t}#c(){return this.#r??=this.#e.storage.getDatasets().then((e)=>new Map(e.map((t)=>[t.name,t]))),this.#r}async list(){return[...(await this.#c()).values()].sort((e,t)=>e.name<t.name?-1:1)}get(e){let t=this.#t.get(e);if(!t)t=this.#u(e),this.#t.set(e,t);return t}async#u(e){let t=(await this.#c()).get(e);if(!t)return;let n=await this.#e.storage.readDataset(e),r=We,s=n.length===t.count;try{for(let i of n)r=st(r,i.hash)}catch{s=!1}if(!s||r!==t.digest){this.evicted+=1,await this.drop(e);return}let o={meta:t,rows:new Map(n.map((i)=>[i.key,i.row])),hashes:new Map(n.map((i)=>[i.key,i.hash]))};return this.#n.set(e,o),o}async rows(e){let t=await this.get(e);if(!t)return;let n=this.#o.get(e);if(!n)n=[...t.rows.keys()].sort().map((r)=>t.rows.get(r)),this.#o.set(e,n);return n}async tables(e,t){let n=await this.#f(e);if(!n)return;let r=new Map;for(let s of t){let o=await this.#f(s);if(!o)return;r.set(s,o)}return{base:n,joined:(s)=>r.get(s)}}async#f(e){let t=await this.get(e);if(!t)return;let n=this.#i.get(e);if(!n){let r=[...t.rows.keys()].sort(Qe);n={keys:r,rows:t.rows,index:new sn(r,t.rows)},this.#i.set(e,n)}return n}loaded(e){return this.#n.has(e)}row(e,t){return this.#n.get(e)?.rows.get(t)}stage(e,t){return new ks(this.#e,e,t)}commit(e,t,n){return this.#a(async()=>{if(this.#e.epoch()!==n)return!1;let r=this.#n.get(e.name),s={name:e.name,schema:t.schema,cursor:t.cursor,count:e.rows.size,digest:e.digest,bytes:e.bytes,appliedAt:this.#e.now()},{puts:o,deletes:i}=e.writes();await this.#e.storage.commitDataset({name:e.name,meta:s,clear:e.clear,puts:o,deletes:i});let a={meta:s,rows:e.rows,hashes:e.hashes};return this.#i.delete(e.name),await this.#l(e.name,a),await this.#e.onChange?.(e.name,...Mi(r,a)),!0})}touch(e,t){return this.#a(async()=>{let n=this.#n.get(e);if(!n||this.#e.epoch()!==t)return!1;let r={...n.meta,appliedAt:this.#e.now()};return await this.#e.storage.commitDataset({name:e,meta:r,clear:!1,puts:[],deletes:[]}),await this.#l(e,{...n,meta:r}),!0})}drop(e){return this.#a(async()=>{let t=this.#n.get(e);if(await this.#e.storage.commitDataset({name:e,meta:null,clear:!0,puts:[],deletes:[]}),this.#i.delete(e),await this.#l(e,void 0),t)await this.#e.onChange?.(e,[],[...t.rows.keys()])})}clear(){return this.#a(async()=>{await this.#e.storage.clearDatasets(),this.#t.clear(),this.#n.clear(),this.#o.clear(),this.#i.clear(),this.#r=Promise.resolve(new Map)})}async#l(e,t){let n=await this.#c();if(this.#o.delete(e),t)n.set(e,t.meta),this.#n.set(e,t),this.#t.set(e,Promise.resolve(t));else n.delete(e),this.#n.delete(e),this.#t.delete(e)}}function Mi(e,t){let n=[];for(let[s,o]of t.hashes)if(e?.hashes.get(s)!==o)n.push(s);let r=[...e?.hashes.keys()??[]].filter((s)=>!t.hashes.has(s));return[n,r]}function De(e,t,n){let r=e.get(t)??new Set;r.add(n),e.set(t,r)}function je(e,t,n){let r=e.get(t);if(!r)return;if(r.delete(n),r.size===0)e.delete(t)}class Rt{#e=new Map;#t=new Map;#n=new Map;#r=new Map;#s=new Map;#o=new Map;#i=new Map;#a=new Map;addProjection(e,t,n,r=[]){this.removeProjections([e]),this.#a.set(e,{deps:[...t],children:[...n],rows:[...r]});for(let s of t)De(this.#e,s,e);for(let s of n)De(this.#t,s,e);for(let s of r)De(this.#s,s,e)}removeProjections(e){for(let t of e){let n=this.#a.get(t);if(!n)continue;for(let r of n.deps)je(this.#e,r,t);for(let r of n.children)je(this.#t,r,t);for(let r of n.rows)je(this.#s,r,t);this.#a.delete(t)}}addArtifact(e,t){this.removeArtifacts([e]),this.#i.set(e,t);for(let n of t.records)De(this.#n,n,e);for(let n of t.projections)De(this.#r,n,e);for(let n of t.rows??[])De(this.#o,n,e)}removeArtifacts(e){for(let t of e){let n=this.#i.get(t);if(!n)continue;for(let r of n.records)je(this.#n,r,t);for(let r of n.projections)je(this.#r,r,t);for(let r of n.rows??[])je(this.#o,r,t);this.#i.delete(t)}}clear(){this.#e.clear(),this.#t.clear(),this.#n.clear(),this.#r.clear(),this.#s.clear(),this.#o.clear(),this.#i.clear(),this.#a.clear()}rowsReaching(e){let t=new Set,n=new Set;for(let s of e){for(let o of this.#s.get(s)??[])t.add(o);for(let o of this.#o.get(s)??[])n.add(o)}let r=this.withParents(t);for(let s of this.artifactsUsing([],r))n.add(s);return{projections:r,artifacts:[...n].sort()}}projectionsReading(e){let t=new Set;for(let n of e)for(let r of this.#e.get(n)??[])t.add(r);return[...t].sort()}withParents(e){let t=new Set,n=[...e];for(let r=n.pop();r!==void 0;r=n.pop()){if(t.has(r))continue;t.add(r),n.push(...this.#t.get(r)??[])}return[...t].sort()}artifactsUsing(e,t){let n=new Set;for(let r of e)for(let s of this.#n.get(r)??[])n.add(s);for(let r of t)for(let s of this.#r.get(r)??[])n.add(s);return[...n].sort()}}class Ce{#e;#t=new Map;constructor(e){this.#e=e}async load(){for(let e of await this.#e.all())this.#t.set(e.id,e)}get(e){return this.#t.get(e)}all(){return[...this.#t.values()]}ids(){return[...this.#t.keys()].sort()}async put(e,t){let n=e.filter((r)=>(this.#t.get(r.id)?.version??-1)<r.version);for(let r of n)this.#t.set(r.id,r);if(n.length>0)if(t)await this.#e.put(n);else await this.#e.delete(n.map((r)=>r.id));return n.map((r)=>r.id)}async drop(e){let t=e.filter((n)=>this.#t.delete(n));if(t.length>0)await this.#e.delete(t)}forget(){this.#t.clear()}}function Rn(e){return new Ce({all:()=>e.allProjections(),put:(t)=>e.putProjections(t),delete:(t)=>e.deleteProjections(t)})}function Sn(e){return new Ce({all:()=>e.allRecords(),put:(t)=>e.putRecords(t),delete:(t)=>e.deleteRecords(t)})}function Ke(e){return e.records!==void 0||e.projections!==void 0||St(ge(e.body))}var St=(e)=>e.records.length+e.projections.length+(e.rows?.length??0)>0;function As(e){return ge(e.data).projections}var Es=(e)=>ge(e.data).rows??[];class Pn{records;projections;index=new Rt;#e;#t;constructor(e){this.#e=e,this.records=Sn(e.storage),this.projections=Rn(e.storage)}get loaded(){return this.#t!==void 0}ensure(){let e=this.#t===void 0;return this.#t??=this.#n(),e?this.#t:this.#t.then(()=>[])}async#n(){await Promise.all([this.records.load(),this.projections.load()]);for(let t of this.projections.all())this.index.addProjection(t.id,t.deps,As(t),Es(t));for(let{artifact:t}of await this.#e.artifacts()){let n=ge(t.body);if(St(n))this.index.addArtifact(t.id,n)}let e={};for(let t of this.records.all()){let n=this.#e.tagVersion(t.id);if(n>t.version)e[t.id]=n}for(let t of this.projections.all())for(let n of t.deps){let r=this.#e.tagVersion(n);if(r>t.version)e[n]=r}return(await this.invalidate(e)).artifacts}async put(e,t){await this.records.put(e.records??[],t);let n=await this.projections.put(e.projections??[],t);for(let s of n){let o=this.projections.get(s);this.index.addProjection(s,o.deps,As(o),Es(o))}let r=ge(e.body);if(St(r))this.index.addArtifact(e.id,r)}forgetArtifacts(e){this.index.removeArtifacts(e)}held(e){let t={};for(let n of[...this.records.all(),...this.projections.all()].slice(0,e))t[n.id]=n.version;return t}async invalidate(e){let t=Object.keys(e),n=(a,c)=>(e[a]??0)>c,r=t.filter((a)=>{let c=this.records.get(a);return c!==void 0&&n(a,c.version)}),s=this.index.projectionsReading(t).filter((a)=>{let c=this.projections.get(a);return c!==void 0&&c.deps.some((l)=>n(l,c.version))}),o=this.index.withParents(s).filter((a)=>this.projections.get(a)),i=this.index.artifactsUsing(r,o);return await this.records.drop(r),await this.projections.drop(o),this.index.removeProjections(o),{records:r.sort(),projections:o,artifacts:i}}async rowsChanged(e,t,n){let r=(i)=>`${e}/${i}`,s=this.index.rowsReaching([...t,...n].map(r)),o=this.index.rowsReaching(n.map(r));return await this.projections.drop(o.projections),this.index.removeProjections(o.projections),{touched:s,dropped:{records:[],projections:o.projections,artifacts:o.artifacts}}}async clear(){this.records.forget(),this.projections.forget(),this.index.clear(),await this.#e.storage.clearGraph()}datasetsOf(e){let t=new Set,n=new Set,r=[e.body];for(let s=r.pop();s!==void 0;s=r.pop()){let o=ge(s);for(let i of o.rows??[])t.add(Vt(i)?.dataset??i);for(let i of o.projections){if(n.has(i))continue;n.add(i);let a=this.projections.get(i);if(a)r.push(a.data)}}return[...t]}async materialize(e){if(e.strategy===\"static\"||!St(ge(e.body)))return{ok:!0,artifact:e};await this.ensure();let t=this.datasetsOf(e);if(t.length>0){await this.#e.loadDatasets?.(t);let a=t.filter((c)=>!this.#e.held?.(c));if(a.length>0)return{ok:!1,reason:`dataset ${a[0]} is not held`,datasets:a}}let n={record:(a)=>this.records.get(a),projection:(a)=>this.projections.get(a),...this.#e.row?{row:this.#e.row}:{}};if(e.strategy!==\"assembly\"){let a=Ut(e.body.data,n);if(!a.ok)return a;return{ok:!0,artifact:{...e,body:{data:a.value}}}}let r=(a)=>{let c={};for(let[l,d]of Object.entries(a??{})){let p=Ut(d,n);if(!p.ok)return p;if(typeof p.value!==\"string\")return{ok:!1,reason:`${l} did not resolve to text`};c[l]=p.value}return{ok:!0,value:c}},s=r(e.body.fragments);if(!s.ok)return s;let o=r(e.body.slots);if(!o.ok)return o;let i={shell:e.body.shell};if(e.body.fragments)i.fragments=s.value;if(e.body.slots)i.slots=o.value;return{ok:!0,artifact:{...e,body:i}}}}class Pt{#e;#t;#n;#r=new Map;#s=new Map;#o=null;#i=0;#a=0;#c;#u=new Map;graph;datasets;constructor(e,t,n=Date.now,r){this.#e=e,this.#t=t,this.#n=n,this.datasets=new bn({storage:e,now:n,epoch:()=>this.#a,...r?{hash:r}:{},onChange:(s,o,i)=>this.#f(s,o,i)}),this.graph=new Pn({storage:e,tagVersion:(s)=>this.#s.get(s)??0,artifacts:()=>this.#p(),row:(s,o)=>this.datasets.row(s,o),held:(s)=>this.datasets.loaded(s),loadDatasets:async(s)=>void await Promise.all(s.map((o)=>this.datasets.get(o)))})}async#f(e,t,n){if(!this.graph.loaded)return;let r=await this.graph.rowsChanged(e,t,n);if(r.dropped.artifacts.length>0)await this.drop(r.dropped.artifacts)}async load(){let e=await this.#e.getMeta();if(e&&e.version===this.#t){this.#o=e.cursor,this.#i=e.syncedAt,this.#s=new Map(e.tags),this.#c=e.policy?.site,this.#u=new Map(e.policy?.paths);return}await this.#e.clearArtifacts(),await this.graph.clear(),await this.datasets.clear(),await this.#d()}get cursor(){return this.#o}get syncedAt(){return this.#i}get sitePolicy(){return this.#c}policyOf(e){return this.#u.get(e)}async keepPolicy(e,t){let n=(r)=>JSON.stringify(r)===JSON.stringify(t);if(e===null){if(n(this.#c))return;this.#c=t}else{if(n(this.#u.get(e)))return;if(this.#u.delete(e),this.#u.set(e,t),this.#u.size>gs)this.#u.delete(this.#u.keys().next().value)}await this.#d()}async get(e){return this.#r.get(e)??await this.#e.getArtifact(e)}async ids(){return(await this.#p()).map((e)=>e.artifact.id)}get epoch(){return this.#a}isCurrent(e){return ps(e,(t)=>this.#s.get(t)??0)}validatedAt(e){return Math.max(fs(e.fetchedAt,this.#i),e.validatedAt??0)}async validate(e){let t=await this.get(e);if(!t||!this.isCurrent(t.artifact))return;let n={...t,validatedAt:this.#n()};if(this.#r.has(e))this.#r.set(e,n);else await this.#e.putArtifact(n)}needFor(e,t=!1){if(!t&&!Ke(e))return null;let n=[...new Set([...e.deps,ln(e.id)])];if(n.length>un)return null;return Object.fromEntries(n.map((r)=>[r,e.vector]))}async held(){return await this.#l(),this.graph.held(Gr)}async datasetsOf(e){if(!Ke(e))return[];return await this.#l(),this.graph.datasetsOf(e)}async materialize(e){if(Ke(e))await this.#l();return this.graph.materialize(e)}async#l(){let e=await this.graph.ensure();if(e.length>0)await this.drop(e)}async put(e,t,n=!1){if(!this.isCurrent(e))return!1;if(Ke(e))await this.#l(),await this.graph.put(e,t);let{records:r,projections:s,...o}=e,i={artifact:o,fetchedAt:this.#n(),...n?{catalogue:!0}:{}};if(t)this.#r.delete(e.id),await this.#e.putArtifact(i);else await this.#e.deleteArtifacts([e.id]),this.#r.set(e.id,i);if(this.#o===null)this.#o=e.vector,await this.#d();return!0}async open(e){let t=await this.get(e);if(!t?.catalogue)return;let{catalogue:n,...r}=t;if(this.#r.has(e))this.#r.set(e,r);else await this.#e.putArtifact(r)}async sweep(e){let t={...e};for(let{artifact:n,catalogue:r}of await this.#p()){if(!r)continue;for(let s of[...n.deps,ln(n.id)])t[s]=Math.min(t[s]??1/0,n.vector)}return Object.keys(t).length>un?null:t}async drop(e){for(let t of e)this.#r.delete(t);if(await this.#e.deleteArtifacts(e),this.graph.loaded)this.graph.forgetArtifacts(e)}async wipe(e=null,t=!1){if(this.#a+=1,this.#r.clear(),await this.#e.clearArtifacts(),await this.graph.clear(),!t)await this.datasets.clear();this.#s=new Map,this.#c=void 0,this.#u=new Map,this.#o=e,await this.#d()}async applySync(e){if(e.reset){let n=await this.ids();return await this.wipe(e.cursor,!0),this.#i=this.#n(),await this.#d(),n}let t=await this.#g(e.changed);if(await this.drop(e.dropped),!e.partial)this.#o=Math.max(this.#o??0,e.cursor),this.#i=this.#n();return await this.#d(),[...new Set([...t,...e.dropped])]}async applyEnvelope(e,t,n){let r=[];if(e.clear?.includes(en))r=await this.ids(),await this.wipe(e.vector??this.#o);else if(e.invalidate)r=await this.#g(e.invalidate);if(t!==null&&e.seen===t&&e.vector!==void 0&&!n)this.#o=Math.max(this.#o??0,e.vector),this.#i=this.#n();return await this.#d(),r}async#p(){return[...this.#r.values(),...await this.#e.allArtifacts()]}async#g(e){let t=new Map;for(let[s,o]of Object.entries(e))if(s.startsWith(Je))t.set(s.slice(Je.length),o);else if(o>(this.#s.get(s)??0))this.#s.set(s,o);let n=this.graph.loaded?(await this.graph.invalidate(Object.fromEntries(this.#m(e)))).artifacts:[],r=(await this.#p()).filter(({artifact:s})=>{let o=t.get(s.id);return o!==void 0&&s.vector<o||!this.isCurrent(s)||n.includes(s.id)}).map(({artifact:s})=>s.id);return await this.drop(r),r}#m(e){return Object.entries(e).filter(([t])=>!t.startsWith(Je))}async#d(){await this.#e.setMeta({version:this.#t,cursor:this.#o,tags:[...this.#s],syncedAt:this.#i,policy:{...this.#c?{site:this.#c}:{},paths:[...this.#u]}})}}function Ii(e,t){return e.thirdParty?.allow.includes(t.origin)===!0}function vn(e,t,n){let r=new URL(t.url);if(r.origin!==n){let i=$r(e.collectors,t.url);if(i&&(t.method===\"POST\"||t.method===\"GET\"))return{kind:\"collector\",collector:i};if(t.method===\"GET\"&&Ii(e,r))return{kind:\"thirdparty\"};return{kind:\"ignore\"}}if(e.logout?.some((i)=>ut(i,r.pathname)))return{kind:\"logout\"};if(t.method===\"POST\"&&e.beacons.includes(r.pathname))return{kind:\"beacon\"};if(t.method!==\"GET\")return{kind:\"pass\"};let s=ne(e.routes,r.pathname),o=r.search!==\"\"&&!s?.route.query;if(t.mode!==\"navigate\"){if(s?.route.strategy===\"static\"&&!t.headers.has(\"range\"))return{kind:\"static\",route:s.route,path:r.pathname+r.search};if(s?.route.strategy===\"data\"&&!t.headers.has(\"range\")&&!o)return{kind:\"data\",route:s.route,path:r.pathname};return{kind:\"asset\"}}if(!s||s.route.strategy===\"data\"||o)return{kind:\"pass\"};return{kind:\"navigation\",route:s.route,params:s.params,path:r.pathname}}function $i(e,t){let n=(s)=>`${t}${s}`,r=[{condition:{requestMode:\"navigate\"},source:\"fetch-event\"}];for(let s of e.beacons)r.push({condition:{urlPattern:n(s),requestMethod:\"POST\"},source:\"fetch-event\"});for(let s of e.logout??[])r.push({condition:{urlPattern:n(s)},source:\"fetch-event\"});for(let s of e.routes)if(s.strategy===\"static\"||s.strategy===\"data\")r.push({condition:{urlPattern:n(s.pattern)},source:\"fetch-event\"});if((e.collectors?.length??0)>0||e.thirdParty)r.push({condition:{not:{urlPattern:n(\"/*\")}},source:\"fetch-event\"});return r.push({condition:{urlPattern:n(\"/*\")},source:\"network\"}),r}async function Ts(e,t,n){if(typeof e.addRoutes!==\"function\")return!1;try{return await e.addRoutes($i(t,n)),!0}catch{return!1}}var Bi=86400,Ni={changesPerDay:ve.changesPerDay,staleBytes:ve.avoidedBytes,syncBytes:ve.requestBytes};class Os{#e;#t;constructor(e){this.#e=1,this.#t=Bi/e}observe(e,t,n){this.#e+=n,this.#t+=e*t}perSecond(){return this.#e/this.#t}}function _i(e){return(1-Math.exp(-e.perSecond*e.tags*Math.max(0,e.ageSec)))*e.policy.staleBytes-e.policy.syncBytes}var Wi=(e)=>e?Object.entries(e).sort().join(\"|\"):\"*\";class xn{#e;#t=new Map;#n;#r={};#s=0;rate;constructor(e){this.#e=e,this.#n=e.policy??Ni,this.rate=new Os(this.#n.changesPerDay)}sync(e,t){let n=this.#t.get(\"*\");if(n)return n;let r=Wi(e),s=this.#t.get(r);if(s)return s;let o=[...this.#t.values()],i=Promise.allSettled(o).then(()=>this.#o(e,t)).finally(()=>{if(this.#t.get(r)===i)this.#t.delete(r)});return this.#t.set(r,i),i}background(e,t){return this.sync(e,t).then(()=>{return},()=>{return})}defer(e,t){let n=Object.keys(e).length;if(n===0)return!1;if(_i({ageSec:t,perSecond:this.rate.perSecond(),tags:n,policy:this.#n})<=0)return!1;for(let[s,o]of Object.entries(e))this.#r[s]=Math.min(o,this.#r[s]??1/0);return this.#s=Math.max(this.#s,t),!0}get pending(){return Object.keys(this.#r).sort()}drain(){let e=this.#r;if(Object.keys(e).length===0)return Promise.resolve(!0);let t=this.#s;return this.#r={},this.#s=0,this.sync(e,t)}async#o(e,t){let{replica:n,fetchSync:r,onNetwork:s}=this.#e,o=n.cursor;if(o===null&&!e)return!0;try{let i=await r(o??0,e);if(e&&t!==void 0&&!i.reset){let a=Object.keys(e),c=a.filter((l)=>Object.hasOwn(i.changed,l)).length;this.rate.observe(a.length,t,c)}return await n.applySync(i),!0}catch{return!1}finally{s?.()}}}var qi=\"\\x00\";function Ds(e,t={}){let n=_r(e).replace(/<!--[\\s\\S]*?-->/g,\"\");for(let r of t.ignore??[]){let s=r.flags.includes(\"g\")?r.flags:`${r.flags}g`;n=n.replace(new RegExp(r.source,s),qi)}return n.replace(/\\s+/g,\" \").replace(/>\\s+</g,\"><\").trim()}function js(e,t,n={}){let r=Ds(e,n),s=Ds(t,n);if(r===s)return{equal:!0};let o=0;while(o<r.length&&r[o]===s[o])o++;return{at:o,equal:!1,reason:`diverges at ${o}: ${JSON.stringify(r.slice(o,o+80))} vs ${JSON.stringify(s.slice(o,o+80))}`}}function vt(e,t){return t.mode??e.mode??\"serve\"}function Cs(e,t,n){if(t.strategy===\"static\")return!1;if(vt(e,t)===\"shadow\")return!0;let r=e.shadowSample??0;return r>0&&n()<r}async function Ms(e,t){if(t.status!==200)return!0;return!js(e,await t.text()).equal}var kn=\"spool-static-\",An=4194304,Li=[\"content-encoding\",\"content-length\",\"transfer-encoding\",\"connection\",\"keep-alive\",\"set-cookie\",\"age\",\"date\",\"vary\"];function $s(e){let t=new Headers(e);for(let n of Li)t.delete(n);return t}async function En(e,t){if(Number(e.headers.get(\"content-length\"))>t)return e.body?.cancel().catch(()=>{return}),null;let n=e.body?.getReader();if(!n)return new Uint8Array;let r=[],s=0;for(;;){let{done:a,value:c}=await n.read();if(a)break;if(s+=c.byteLength,s>t)return n.cancel().catch(()=>{return}),null;r.push(c)}let o=new Uint8Array(s),i=0;for(let a of r)o.set(a,i),i+=a.byteLength;return o}function Fi(e){let t=e.getReader(),n=[],r=null,s=()=>{},o=!0,i,a=new ReadableStream({start(d){i=d},cancel(){o=!1}}),c=(d)=>{r=d,s()};return(async()=>{for(;;){let d;try{d=await t.read()}catch(p){if(o)i.error(p);return c({failed:!0,reason:p})}if(d.done){if(o)i.close();return c({failed:!1})}if(n.push(d.value),s(),o)i.enqueue(d.value)}})(),{visitor:new ReadableStream({async pull(d){for(;;){let p=n.shift();if(p)return d.enqueue(p);if(r?.failed)return d.error(r.reason);if(r)return d.close();await new Promise((h)=>s=h)}},cancel:(d)=>t.cancel(d)},{highWaterMark:0}),capture:a}}function Bs(e){if(e.redirected||!e.body)return{visitor:e,copy:e.clone()};let{visitor:t,capture:n}=Fi(e.body),r={status:e.status,statusText:e.statusText,headers:e.headers};return{visitor:new Response(t,r),copy:new Response(n,r)}}var Hi=/^sha(256|384|512)-([A-Za-z0-9+/]+={0,2})$/,Vi=/^(?:W\\/)?\"/;function Ui(e){let t=\"\";for(let n of e)t+=String.fromCharCode(n);return btoa(t)}var Is=(e)=>e.replace(/^W\\//,\"\");async function Ns(e,t,n){let r=Hi.exec(e);if(r){let s=await crypto.subtle.digest(`SHA-${r[1]}`,t);return Ui(new Uint8Array(s))===r[2]}if(Vi.test(e)){let s=n.get(\"etag\");return s!==null&&Is(s)===Is(e)}return!0}var Xe=\"spool-third\",Me={class:\"x-spool-class\",fetched:\"x-spool-fetched\"};var zi=[/[._-][0-9a-f]{8,}(?=[._-]|$)/i,/[@/_-]v?\\d+\\.\\d+\\.\\d+/,/\\/v\\d+(?:\\/|$)/],Gi=/[?&](?:v|ver|version|hash|h|rev)=[^&]+/i;function _s(e,t,n=[]){if(zi.some((o)=>o.test(e.pathname)))return\"immutable\";let r=t.get(\"cache-control\")??\"\";if(/(?:^|,)\\s*immutable\\b/i.test(r))return\"immutable\";let s=/max-age=(\\d+)/i.exec(r);if(s!==null&&Number(s[1])>=31536000)return\"immutable\";if(Gi.test(e.search))return\"revalidate\";for(let o of n)try{if(new RegExp(o).test(e.href))return\"revalidate\"}catch{continue}return null}var Qi=[\"template\",\"projection\",\"data\"],qs=\"spool-assets-\",Ji=[qs,kn],Ki=31536000,Xi=86400000,xt=new TextEncoder,Ws=(e)=>e.split(\"?\",1)[0];function Yi(e){let t=e.headers.get(\"cache-control\")??\"\";if(/(?:^|,)\\s*immutable\\b/i.test(t))return!0;let n=/max-age=(\\d+)/i.exec(t);return n!==null&&Number(n[1])>=Ki}function Ls(e){let{config:t,storage:n,origin:r,renderers:s}=e,o=e.partitions,i=e.now??Date.now,a=e.random??Math.random,c=Zr(e.userAgent??(typeof navigator>\"u\"?\"\":navigator.userAgent)),l=hs(t.provision),d=new Pt(n,t.version,i),p=new mn,h=new Set,y=new Map,S=new Map,x=new Set,T=new Set,N=null,C=new Map,q=`${qs}${t.version}`,H=`${kn}${t.version}`,ae=(u)=>new Request(`${r}${u}`),Ye=i(),k=t.assets??\"cache\",E=!1,M=null,he,Tn,Us,_=null,On=Promise.resolve(),zs=t.mode===\"shadow\",Dn=()=>t.manifest!==void 0&&t.routes.length===0,kt=new Map,ce=(u)=>{let f=kt.get(u);if(!f)f=e.caches.open(u),kt.set(u,f),f.catch(()=>kt.delete(u));return f},X=async()=>{if(await(he??=d.load()),Dn())await(Tn??=vo());if(o)await(Us??=co())},re=(u)=>{let f=u.then(()=>{return},()=>{return});h.add(f),f.then(()=>h.delete(f))},Gs=async(u)=>{let f=()=>[...h].filter((g)=>!u.has(g));while(f().length>0)await Promise.allSettled(f())},jn=(u)=>{let f=On.then(u,u);return On=f.catch(()=>{return}),f};async function Qs(u,f){if(t.manifest)return Un();let g=f?`need=${encodeURIComponent(dn(f))}`:`from=${u}`,m=await e.fetch(`${r}${Se.sync}?${g}`,{cache:\"no-store\",credentials:\"same-origin\"});if(!m.ok)throw Error(`sync answered ${m.status}`);return await Ot(pt(m.headers),!0),Qr(await m.json())}let Js={changesPerDay:l.changesPerDay,staleBytes:l.avoidedBytes,syncBytes:l.requestBytes};async function Ks(){let u=[];for(let g of x)if(!await d.get(g))u.push(g);let f=[];for(let g of t.provision?.hot??[]){if(T.has(g)||u.includes(g)||await d.get(g))continue;let m=ne(t.routes,g);if(!m||m.route.scope!==\"public\"||m.route.strategy===\"static\")continue;f.push({id:g,kind:\"route\",provision:{bytes:p.meanFetchBytes()??l.artifactBytes,requests:0},avoided:{bytes:l.avoidedBytes,requests:1}})}return[...u,...ws(f,l).map((g)=>g.id)].slice(0,Mr)}async function Xs(u,f,g){let m=ne(t.routes,u.id);if(!m||u.scope!==\"public\"||u.strategy!==m.route.strategy)return;if(await d.put(u,m.route.persist))p.spend(u.id,{bytes:f,requests:g})}let Ys=()=>N!==null?{path:N,sweep:!0}:void 0;async function Zs(u,f){if(!Array.isArray(u))return;for(let g of u){let m;try{m=Le(g)}catch{continue}p.spend(m.id,{bytes:xt.encode(JSON.stringify(g)).length,requests:0},!0);let w=ne(t.routes,m.id);if(!w||!Qi.includes(m.strategy))continue;if(m.strategy!==w.route.strategy||m.scope!==w.route.scope)continue;let b=Z;if(m.scope===\"principal\"){if(b=await we(),!b||b.id!==f)continue}if(await b.replica.get(m.id))continue;await b.replica.put(m,w.route.persist,!0)}}async function eo(u){let f=t.collectors?.find((R)=>R.vendor===u.vendor),g=u.search??\"\";if(f?.stamp)g=Br(g,f.stamp,u.at,i());let m=u.method??\"POST\",w={method:m,credentials:u.origin?\"omit\":\"same-origin\"};if(m===\"POST\"){if(w.body=u.body,u.contentType)w.headers={\"content-type\":u.contentType}}if(u.origin){let R=u.contentType.split(\";\")[0]?.trim().toLowerCase()??\"\",v=[\"\",\"text/plain\",\"application/x-www-form-urlencoded\"].includes(R);w.mode=v?\"no-cors\":\"cors\"}let b=await e.fetch(`${u.origin??r}${u.path}${g}`,w);return b.type===\"opaque\"||b.ok||b.status>=400&&b.status<500}let Y=new gn({storage:n,now:i,want:Ks,catalogue:Ys,replay:eo,async send(u){let f=await e.fetch(`${r}${Se.beacon}`,{method:\"POST\",headers:{\"content-type\":\"application/json\"},body:JSON.stringify(u),credentials:\"same-origin\"});if(f.status===200&&(u.want||u.catalogue)){let g=await f.json();if(u.want){let m=Array.isArray(g.artifacts)?g.artifacts:[];for(let w of m){let b=Le(w);await Xs(b,xt.encode(JSON.stringify(w)).length,0)}for(let w of u.want)x.delete(w),T.add(w)}if(u.catalogue)await Zs(g.catalogue,f.headers.get(W.partition))}return f.ok||f.status>=400&&f.status<500}}),Cn=(u)=>new xn({replica:u,fetchSync:Qs,onNetwork:()=>re(Y.flushAtMoment()),policy:Js}),Z={id:null,replica:d,scheduler:Cn(d),deferred:new Set,loaded:Promise.resolve(),dead:!1},ta=Z.scheduler,Ze=new Map,At={},Ie=new Map,Et=new Set,$e=new Set,Mn=!1,In=null,to=async()=>{if(e.estimate)return e.estimate();return(typeof navigator>\"u\"?void 0:await navigator.storage?.estimate?.())??{}},no=async()=>{try{let{quota:u,usage:f}=await to();if(u===void 0||f===void 0)return;return Math.max(0,(u-f)*(t.datasetShare??1))}catch{return}},ro=(u)=>{let f=u.status===\"refused\"?`${u.name}:refused:${u.reason}`:`${u.name}:${u.status}`;if(At[f]=(At[f]??0)+1,u.status===\"refused\"){if(Ie.set(u.name,u.reason),u.reason===\"declined\")S.set(u.name,u.by??null)}else if(u.status!==\"offline\")Ie.delete(u.name);if(u.status!==\"offline\"&&u.status!==\"refused\"&&!Mn)Mn=!0,e.broadcast?.({type:\"spool:persist\"})},Tt=()=>new Map((t.principalDatasets??[]).map((u)=>[u.name,u.maxStaleMs]));async function so(u,f,g){let m=await e.fetch(f,g);if(u.dead||_!==u)return m;if(m.status===401)await Ne(\"session-ended\");else if(m.ok)if(m.headers.has(W.partition))await Ot(pt(m.headers),!0);else await Ne(\"session-ended\");return m}function Be(u,f=Z){let g=`${f.id??\"\"}\\x00${u}`,m=Ze.get(g);if(m)return m;let w=f.id,b=ls({store:f.replica.datasets,fetch:w===null?(R,v)=>e.fetch(R,v):(R,v)=>so(f,R,v),origin:r,epoch:()=>f.dead?-1:f.replica.epoch,budget:no,...w===null?{}:{guard:us(w)}},u).then((R)=>(ro(R),R)).finally(()=>Ze.delete(g));return Ze.set(g,b),b}let oo=(u)=>u.status!==\"offline\"&&u.status!==\"refused\";function $n(u,f=Z){if(f!==Z&&!Tt().has(u))return;let g=`${f.id??\"\"}\\x00${u}`;if(!Ie.has(u)&&!Ze.has(g))re(Be(u,f))}let io=(u)=>ne(t.routes,u)?.route.retention??\"session\",ao=()=>t.routes.some((u)=>u.scope===\"principal\"&&u.retention===\"persistent\")?\"persistent\":\"session\";function Bn(u){let f=o.open(u,io,ao(),t.principalDatasets!==void 0),g=new Pt(f,t.version,i);return{id:u,replica:g,scheduler:Cn(g),deferred:new Set,loaded:g.load(),dead:!1}}async function co(){let u=await o.current();if(u&&!_)_=Bn(u)}async function we(){await X();let u=_;if(!u)return null;return await u.loaded,u}function Nn(u){u.dead=!0,$e.clear();for(let f of Tt().keys())Ie.delete(f)}function Ne(u){return jn(async()=>{await X();let f=_;if(_=null,f?.writes?.kill(),f)Nn(f);if(!f||!o)return!1;return await o.setCurrent(null),await o.destroy(f.id),e.broadcast?.({type:\"spool:cleared\",reason:u}),!0})}function uo(u){return jn(async()=>{await X();let f=_;if(f?.id===u)return;if(_=Bn(u),f?.writes?.kill(),f)Nn(f);if(await o.setCurrent(u),f)await o.destroy(f.id),e.broadcast?.({type:\"spool:cleared\",reason:\"partition\"})})}async function Ot(u,f,g=!1){if(!o||!u||u.protocol!==j)return;await X();let m=u.clear??[];if(m.includes(\"*\")||_&&m.includes(_.id)){await Y.dropSameOrigin(),await Ne(\"clear\");return}if(g)return;if(u.partition!==void 0){if(_?.id!==u.partition)await Y.dropSameOrigin(),await uo(u.partition)}else if(f&&_)await Y.dropSameOrigin(),await Ne(\"session-ended\")}let _n=()=>t.writes!==void 0&&t.mode!==\"shadow\",Dt=(u,f)=>({ok:!1,code:u,message:f});async function lo(u){let f=`name=${encodeURIComponent(u.name)}&key=${encodeURIComponent(u.key)}`,g=await e.fetch(`${r}${Se.write}?${f}`,{method:\"PUT\",headers:{\"content-type\":\"application/json\",\"if-match\":vr(u.base),[Rr.id]:u.id},body:JSON.stringify({value:u.value}),cache:\"no-store\",credentials:\"same-origin\"}),m=await g.json().catch(()=>{return});return{status:g.status,body:m}}function Wn(u){if(!_n()||!o?.openWrites)return null;return u.writes??=new Re({store:o.openWrites(u.id),classes:()=>t.writes??[],now:i,send:lo,onFlush:(f)=>e.broadcast?.({type:\"spool:written\",...f})}),u.writes}async function et(){if(!_n())return Dt(\"writes-off\",\"declared writes are off\");let u=await we();if(!u)return Dt(\"no-partition\",\"no signed-in principal is held\");return Wn(u)??Dt(\"unavailable\",\"this worker has no partition storage\")}async function fo(){let u=_?Wn(_):null;if(u)await u.flush()}async function po(u,f,g){let m=f.scope===\"principal\"?await we():Z;if(!m||f.scope===\"principal\"&&m.id!==g)return;let w=await m.replica.held(),b=Object.keys(w).length>0?`&have=${encodeURIComponent(dn(w))}`:\"\",R=await e.fetch(`${r}${Se.artifact}?path=${encodeURIComponent(u)}${b}`,{cache:\"no-store\",credentials:\"same-origin\"});if(R.status===204&&R.headers.get(W.provision)===\"declined\"){S.set(u,R.headers.get(W.provisionReason));return}if(!R.ok){if(f.scope===\"principal\"&&[401,403,404].includes(R.status))await m.replica.drop([u]);return}let v=await R.text(),P=Le(JSON.parse(v));if(P.scope!==f.scope||P.id!==u)return;if(P.strategy!==f.strategy)return;if(f.scope===\"principal\"){if(R.headers.get(W.partition)!==g)return;if(_!==m)return}if(await m.replica.put(P,f.persist))p.spend(u,{bytes:xt.encode(v).length,requests:1})}async function qn(u){let f=[...u.deferred];if(u.deferred.clear(),await u.scheduler.drain())for(let g of f)await u.replica.validate(g)}async function go(u,f,g,m,w,b,R){if(await R(),f&&f.protocol===j){await d.applyEnvelope(f,g,u.has(\"age\"));let v=_;if(v)await v.loaded,await v.replica.applyEnvelope(f,null,!0);let P=f.artifact;if(b&&P){let O=ne(t.routes,P.id),L=P.scope===\"principal\"?await we():Z,V=O&&O.route.strategy!==\"static\"&&O.route.scope===P.scope&&!S.has(P.id)&&L&&(P.scope===\"public\"||L.id===f.partition);if(O&&L&&V&&!await L.replica.get(P.id))if(P.scope===\"public\"&&vt(t,O.route)===\"shadow\")x.add(P.id);else{let B=`${P.scope}:${P.id}`,ee=y.get(B)??po(P.id,O.route,f.partition);y.set(B,ee);try{await ee}catch{}finally{y.delete(B)}}}}if(w){if(await qn(Z),_)await qn(_);let v=[...Et];Et.clear();for(let L of v)await Be(L);let P=[...$e];$e.clear();let O=_;if(O)for(let L of P)await Be(L,O);await Y.flushAtMoment(),await fo(),await Ao()}}async function mo(u,f,g,m,w){if(u.method!==\"GET\"||f.status!==200||f.redirected)return;if(w?.signedOut)return;if(m&&!/text\\/html/i.test(f.headers.get(\"content-type\")??\"\"))return;let b=ms(f.headers);if(m)await d.keepPolicy(null,b);let R=w?.route,v=new URL(u.url);if(!R||R.strategy===\"static\"||v.search!==\"\")return;let P=R.scope===\"principal\"?_?.id===g?.partition?_:null:Z;if(!P)return;await P.loaded,await P.replica.keepPolicy(v.pathname,b)}async function le(u,f,g){let m=u,w=null;if(!t.manifest&&!f&&u.method===\"GET\"&&d.cursor!==null)try{let B=new Headers(u.headers);B.set(W.vectorSeen,String(d.cursor)),m=new Request(u,{headers:B}),w=d.cursor}catch{m=u}let b=await e.fetch(m),R=pt(b.headers);await Ot(R,f,g?.signedOut);let v=f||u.method!==\"GET\",P=g?.clone,O=typeof P===\"function\"?P(b,R):P,{visitor:L,copy:V}=O?Bs(b):{visitor:b,copy:null};return re((async()=>{try{await g?.run(V,R)}catch{}await go(b.headers,R,w,f,v,g?.provision??f,()=>mo(u,b,R,f,g))})()),L}async function jt(u,f,g,m=\"\"){let w=Z;if(f.scope===\"principal\"){if(!o)return{reason:\"principal\",staleSec:null};let A=await we();if(!A)return{reason:\"cold\",staleSec:null};w=A}let{replica:b,scheduler:R}=w,v=await b.get(u);if(!v)return{reason:\"cold\",staleSec:null};let P=()=>v?Math.max(0,Math.floor((i()-b.validatedAt(v))/1000)):null;if(!b.isCurrent(v.artifact)){let A=P();return await b.drop([u]),{reason:\"invalidated\",staleSec:A}}if(f.version!==void 0&&v.artifact.strategy===\"static\"&&v.artifact.body.version!==f.version){let A=P();return await b.drop([u]),{reason:\"invalidated\",staleSec:A}}let O=f.query?.dataset,L=(f.query?.plan?.join??[]).map((A)=>A.dataset),V=[...new Set([...O?[O]:[],...L,...await b.datasetsOf(v.artifact)])],B=w===Z?void 0:Tt();if(B&&V.some((A)=>!B.has(A)))return{reason:\"refused\",staleSec:P()};let ee=async()=>Promise.all(V.map(async(A)=>(await b.datasets.get(A))?.meta.appliedAt)),te=await ee(),xe=V.filter((A,se)=>te[se]===void 0);if(xe.length>0){if(!g)for(let A of xe)$n(A,w);return{reason:\"refused\",staleSec:P()}}if(B){let A=V.filter((se,It)=>{let er=i()-te[It];return!(er>=0&&er<B.get(se))});if(A.length>0){if(!g)for(let se of A)$e.add(se);return{reason:\"refused\",staleSec:P()}}}let Jn=(A)=>A.filter((se)=>se!==void 0),To=v.catalogue===!0,Kn=ds(f.freshness,Math.min(b.validatedAt(v),...Jn(te)),i()),U=Math.max(P(),...Jn(te).map((A)=>Math.floor((i()-A)/1000))),Ct=b.needFor(v.artifact,f.sync===\"deferred\"||f.scope===\"principal\"),ke=(f.scope===\"principal\"&&Ct?await b.sweep(Ct):Ct)??void 0,de=\"fresh\";if(Kn===\"sync-first\"){if(de=\"hard-sync\",!g){let A=await R.sync(ke,U),se=(await Promise.all(V.map((It)=>Be(It,w)))).every(oo);if(!(A&&se)&&f.offline===\"refuse\")return{reason:\"hard-refused\",staleSec:U};if(V.length>0){if(te=await ee(),te.includes(void 0))return{reason:\"refused\",staleSec:U}}if(A){if(ke)await b.validate(u);if(v=await b.get(u),!v||!b.isCurrent(v.artifact))return{reason:\"stale-after-sync\",staleSec:U}}if(!(A&&se))de=\"offline-stale\"}}else if(Kn===\"serve-then-sync\"){if(f.sync===\"deferred\"){if(de=\"soft-deferred\",!g&&ke&&R.defer(ke,U))w.deferred.add(u);if(!g)for(let A of V)(w===Z?Et:$e).add(A)}else if(de=\"soft-sync\",!g){re(R.sync(ke,U).then(async(A)=>{if(A&&ke)await b.validate(u)}));for(let A of V)re(Be(A,w))}}if(f.strategy===\"static\"){let A=await bo(u);if(!A)return await b.drop([u]),{reason:\"refused\",staleSec:U};return{reason:de,response:A,staleSec:U}}let Xn=b.policyOf(u)??d.sitePolicy;if(!Xn&&!g)return{reason:\"refused\",staleSec:U};let tt=await b.materialize(v.artifact);if(!tt.ok){if(tt.datasets){if(!g)for(let A of tt.datasets)$n(A,w);return{reason:\"refused\",staleSec:U}}return await b.drop([u]),{reason:\"refused\",staleSec:U}}let nt=f.query?.plan!==void 0,Yn=O===void 0||nt?void 0:await b.datasets.rows(O);if(O!==void 0&&!nt&&!Yn)return{reason:\"refused\",staleSec:U};let Zn=O!==void 0&&nt?await b.datasets.tables(O,L):void 0;if(O!==void 0&&nt&&!Zn)return{reason:\"refused\",staleSec:U};let Mt=await xs(t,f,tt.artifact,s,m,Yn,Zn);if(!Mt.ok){if(Mt.reason===Bt)await b.drop([u]);return{reason:\"refused\",staleSec:U}}if(To){if(await b.open(u),fn[de]===\"local\")de=\"catalogue\"}return{reason:de,html:Mt.html,headers:Xn,staleSec:U}}function yo(u){let f;try{f=new URL(u)}catch{return}if(f.protocol!==\"http:\"&&f.protocol!==\"https:\")return;if(f.origin!==r)return Jr;return ne(t.routes,f.pathname)?.route.pattern}async function ho(u,f,g){let m=Cs(t,f,a),w=i(),b=M===null?null:w-M;M=w,N=f.catalogue?u:null;let R=await jt(u,f,m,new URL(g.url).search),v=yo(g.referrer),P=crypto.randomUUID();if(C.delete(u),C.set(u,P),C.size>64)C.delete(C.keys().next().value);let O=(B)=>({id:P,crossOriginLoads:null,tier:m?\"shadow\":fn[R.reason],reason:R.reason,staleSec:R.staleSec,engine:c,scope:f.scope,strategy:f.strategy,route:f.pattern,mismatch:B,swAgeMs:w-Ye,gapMs:b,...v?{from:v}:{}}),L=async(B)=>{if(t.views!==!1)await Y.record(Yr(O(B),w))};if(m){let B=R.html;return le(g,!0,{clone:B!==void 0,route:f,run:async(ee)=>{await L(B===void 0||!ee?null:await Ms(B,ee))}})}if(R.response)return p.serve(u),re(L(null)),R.response;if(R.html===void 0){let B=f.strategy===\"static\",ee=await le(g,!0,{clone:B||((te,xe)=>Vn(u,f,te,xe)),route:f,run:async(te,xe)=>{if(B)await Hn(u,f,te);else await So(u,f,te,xe);await L(null)}});if(f.scope===\"principal\"&&Ln(ee))await Fn(u);return ee}p.serve(u,R.reason===\"catalogue\"),re(L(null));let V=new Headers(R.headers);return V.set(\"content-type\",\"text/html; charset=utf-8\"),new Response(R.html,{headers:V})}function Ln(u){return u.status===401||u.status===403||u.type===\"opaqueredirect\"||u.status>=300&&u.status<400}async function Fn(u){let f=await we();if(f)await f.replica.drop([u])}async function wo(u,f,g){let m=await jt(f,g,!1,new URL(u.url).search);if(m.html!==void 0){p.serve(f,m.reason===\"catalogue\");let b=new Headers(m.headers);return b.set(\"content-type\",g.type??\"application/json\"),new Response(m.html,{headers:b})}let w=await le(u,!1,{provision:!0,route:g,run:async()=>{return}});if(g.scope===\"principal\"&&Ln(w))await Fn(f);return w}async function bo(u){return(await ce(H)).match(ae(u))}async function Hn(u,f,g){if(!g||g.status!==200||g.redirected){g?.body?.cancel().catch(()=>{return});return}let m=t.manifest?ne(t.routes,Ws(u))?.route:f;if(m?.strategy!==\"static\")return;let w=await En(g,An);if(!w)return;let b=g.headers.get(\"content-type\")??\"application/octet-stream\",R;if(t.manifest){let P=m.version;if(P===void 0||!await Ns(P,w,g.headers))return;R={protocol:j,id:u,scope:\"public\",strategy:\"static\",deps:[],vector:0,body:{type:b,bytes:w.byteLength,version:P}}}else{let P;try{P=tn(g.headers)}catch{return}let O=P.artifact;if(P.protocol!==j||!O)return;if(O.id!==u||O.scope!==\"public\")return;R={protocol:j,id:u,scope:\"public\",strategy:\"static\",deps:O.deps,vector:O.version,body:{type:b,bytes:w.byteLength}}}if(await(await ce(H)).put(ae(u),new Response(w,{headers:$s(g.headers)})),await d.put(R,!0))p.spend(u,{bytes:w.byteLength,requests:0})}function Vn(u,f,g,m){let w=m?.artifact;return(f.strategy===\"assembly\"||f.strategy===\"template\")&&f.scope===\"public\"&&m?.protocol===j&&w?.hash!==void 0&&w.id===u&&w.scope===\"public\"&&vt(t,f)!==\"shadow\"&&!S.has(u)&&g.status===200&&!g.redirected&&/text\\/html/i.test(g.headers.get(\"content-type\")??\"\")}async function Ro(u,f,g,m){if(f.strategy===\"template\"){let R=Nr(g);if(R===null||await Ae(R)!==m.hash)return null;let v=Le(JSON.parse(R));if(v.id!==u||v.scope!==\"public\")return null;if(v.strategy!==\"template\")return null;return{artifact:v,bytes:xt.encode(R).length}}let w=g.indexOf(t.clientTag),b=w<0?[g]:[g.slice(0,w)+g.slice(w+t.clientTag.length),g];for(let R of b){if(await Ae(R)!==m.hash)continue;return{artifact:{protocol:j,id:u,scope:\"public\",strategy:\"assembly\",deps:[...new Set(m.deps)],vector:m.version,body:{shell:R}},bytes:0}}return null}async function So(u,f,g,m){let w=m?.artifact;if(!g||!w?.hash||!Vn(u,f,g,m))return;let b=d.epoch;try{let R=await En(g,An);if(!R)return;let v=new TextDecoder(\"utf-8\",{fatal:!0}).decode(R),P=await Ro(u,f,v,{...w,hash:w.hash});if(!P||await d.get(u)||d.epoch!==b)return;if(await d.put(P.artifact,f.persist))p.spend(u,{bytes:P.bytes,requests:0})}catch{}}async function Po(u,f,g){let m=await jt(f,g,!1);if(m.response)return p.serve(f),m.response;return le(u,!1,{clone:!0,run:(w)=>Hn(f,g,w)})}async function vo(){try{let f=await(await ce(H)).match(new Request(t.manifest));if(f){t.routes=cn(an(JSON.parse(await f.text())));return}await Un()}catch{Tn=void 0}}async function Un(){let u=t.manifest,f=await e.fetch(u,{cache:\"no-store\",credentials:\"same-origin\"});if(!f.ok)throw Error(`manifest answered ${f.status}`);let g=await f.text(),m=cn(an(JSON.parse(g)));t.routes=m,await(await ce(H)).put(new Request(u),new Response(g,{headers:{\"content-type\":\"application/json\"}}));let b=[];for(let R of await d.ids()){let v=await d.get(R);if(v?.artifact.strategy!==\"static\")continue;let P=ne(m,Ws(R));if(!P||v.artifact.body.version!==P.route.version)b.push(R)}return{protocol:j,cursor:d.cursor??0,changed:{},dropped:b,reset:!1}}async function zn(u){let f=await ce(q),g=!u.headers.has(\"range\");if(g){let w=await f.match(u);if(w)return w}await X();let m=await le(u,!1);if(g&&m.status===200&&Yi(m))re(f.put(u,m.clone()));return m}async function xo(u,f){if(await X(),!await Y.enqueue(u,f))return e.fetch(u);return ss(u)}let _e=t.thirdParty,Gn=(u)=>new Request(u.url);async function ko(u){let g=await(await ce(Xe)).match(Gn(u));if(g)return g;let m=await e.fetch(u);if(m.status===200&&(m.type!==\"opaque\"||_e?.allowOpaque)){let w=m.type===\"opaque\"?\"immutable\":_s(new URL(u.url),m.headers,_e?.versioned);if(w)re(Qn(u,m.clone(),w))}return m}async function Qn(u,f,g){let m=await ce(Xe),w=f;if(f.type!==\"opaque\"){let P=new Headers(f.headers);P.set(Me.class,g),P.set(Me.fetched,String(i())),w=new Response(await f.arrayBuffer(),{status:200,headers:P})}await m.put(Gn(u),w);let b=await m.keys(),R=_e?.maxEntries??64;if(b.length<=R)return;let v=[];for(let P of b){let O=await m.match(P);v.push({key:P,at:Number(O?.headers.get(Me.fetched)??0)})}v.sort((P,O)=>P.at-O.at);for(let{key:P}of v.slice(0,b.length-R))await m.delete(P)}async function Ao(){if(!_e)return;let u=await ce(Xe),f=_e.revalidateAfterMs??Xi;for(let g of await u.keys()){let m=await u.match(g);if(!m||m.headers.get(Me.class)!==\"revalidate\")continue;let w=Number(m.headers.get(Me.fetched)??0);if(i()-w<f)continue;try{let b=await e.fetch(new Request(g.url,{cache:\"no-cache\",mode:\"cors\",credentials:\"omit\"}));if(b.status===200&&b.type!==\"opaque\")await Qn(g,b,\"revalidate\")}catch{}}}async function Eo(u){await X();let f=vn(t,u,r);if(re(Y.flushIfDue()),f.kind===\"logout\")return await Y.sendSameOrigin(rs).catch(()=>{return}),await Ne(\"logout\"),le(u,u.mode===\"navigate\",{signedOut:!0,run:async()=>{return}});if(f.kind===\"collector\")return xo(u,f.collector);if(f.kind===\"thirdparty\")return ko(u);if(f.kind===\"beacon\"){if(await Y.enqueue(u))return new Response(null,{status:204});return le(u,!1)}if(f.kind===\"navigation\")return ho(f.path,f.route,u);if(f.kind===\"static\")return Po(u,f.path,f.route);if(f.kind===\"data\")return wo(u,f.path,f.route);if(f.kind===\"asset\")return zn(u);return le(u,u.mode===\"navigate\")}return{replica:d,ledger:p,handle(u,f){let g=vn(t,u,r).kind;if(g===\"ignore\")return;if(g===\"asset\"&&k!==\"cache\")return;if(zs&&g!==\"navigation\"&&g!==\"static\"&&u.mode!==\"navigate\")return;let m=new Set(h);return(g===\"asset\"&&!Dn()?zn(u):Eo(u)).catch(()=>e.fetch(u)).finally(()=>f(Gs(m)))},async install(u){if(k===\"static-routing\")E=await Ts(u,t,r)},async activate(){await X();for(let u of await e.caches.keys())if(Ji.some((g)=>u.startsWith(g))&&u!==q&&u!==H)await e.caches.delete(u)},async message(u){let f=u??{};if(f.type===\"spool:hello\")return{type:\"spool:hello\",protocol:j,version:t.version,compatible:f.protocol===j};if(f.type===\"spool:status\")return await X(),{type:\"spool:status\",cursor:d.cursor,syncedAt:d.syncedAt,artifacts:await d.ids(),beacons:(await n.readBeacons()).length};if(f.type===\"spool:view\"){let g=f.path;return{type:\"spool:view\",id:typeof g===\"string\"&&C.get(g)||null}}if(f.type===\"spool:loads\"){let{view:g,count:m,origins:w}=f;if(typeof g===\"string\"&&typeof m===\"number\"&&t.views!==!1){await X();let b=typeof w===\"object\"&&w!==null&&!Array.isArray(w)?w:void 0;await Y.record(Xr(g,m,i(),b))}return}if(f.type===\"spool:graph\")return await X(),await d.held(),{type:\"spool:graph\",records:d.graph.records.ids(),projections:d.graph.projections.ids()};if(f.type===\"spool:ledger\")return{type:\"spool:ledger\",entries:p.entries(),totals:p.totals()};if(f.type===\"spool:partition\"){let g=await we();if(!g)return{type:\"spool:partition\",partition:null,artifacts:[],records:[],projections:[],datasets:[]};return await g.replica.held(),{type:\"spool:partition\",partition:g.id,artifacts:await g.replica.ids(),records:g.replica.graph.records.ids(),projections:g.replica.graph.projections.ids(),datasets:await g.replica.datasets.list()}}if(f.type===\"spool:assets\")return{type:\"spool:assets\",mode:k,routed:E};if(f.type===\"spool:datasets\")return await X(),{type:\"spool:datasets\",datasets:await d.datasets.list(),outcomes:{...At},refused:Object.fromEntries(Ie),declined:Object.fromEntries(S),evicted:d.datasets.evicted,persisted:In};if(f.type===\"spool:persisted\"){In=f.granted===!0;return}if(f.type===\"spool:write\"){let{name:g,key:m,value:w,version:b}=f,R=await et();return{type:\"spool:write\",result:R instanceof Re?await R.write(typeof g===\"string\"?g:\"\",typeof m===\"string\"?m:\"\",w,b):R}}if(f.type===\"spool:flush\"){let g=await et();return{type:\"spool:flush\",result:g instanceof Re?{ok:!0,...await g.flush()}:g}}if(f.type===\"spool:writes\"){let g=await et();return{type:\"spool:writes\",result:g instanceof Re?{ok:!0,writes:await g.list()}:g}}if(f.type===\"spool:resolve\"){let{name:g,key:m,use:w}=f,b=await et();return{type:\"spool:resolve\",result:b instanceof Re?await b.resolve(typeof g===\"string\"?g:\"\",typeof m===\"string\"?m:\"\",w):b}}if(f.type===\"spool:held\"){let g=await ce(Xe);return{type:\"spool:held\",dropped:Object.fromEntries(Y.dropped),third:(await g.keys()).map((m)=>m.url).sort()}}return}}}var Zi=\"static-1\",ea=\"spool.json\";function Fs(e){return{protocol:j,version:Zi,routes:[],templates:{},beacons:[],clientTag:\"\",views:!1,manifest:new URL(ea,e).href}}function Hs(e,t){let n=self,r=Ls({config:e,storage:it(),fetch:(s,o)=>fetch(s,o),caches,origin:n.location.origin,renderers:t,partitions:typeof indexedDB>\"u\"?void 0:Dr(),broadcast:(s)=>void n.clients.matchAll({type:\"window\",includeUncontrolled:!0}).then((o)=>o.forEach((i)=>i.postMessage(s)))});n.addEventListener(\"install\",(s)=>s.waitUntil(Promise.all([n.skipWaiting(),r.install(s)]))),n.addEventListener(\"activate\",(s)=>s.waitUntil(Promise.all([r.activate(),n.clients.claim()]))),n.addEventListener(\"fetch\",(s)=>{let o=r.handle(s.request,(i)=>s.waitUntil(i));if(o)s.respondWith(o)}),n.addEventListener(\"message\",(s)=>{s.waitUntil(r.message(s.data).then((o)=>{if(!o)return;let i=s.ports[0];if(i)i.postMessage(o);else s.source?.postMessage(o)}))})}var Vs=self;Hs(Vs.__SPOOL_CONFIG__??Fs(Vs.location.href));})();\n";
|
|
2
|
+
export declare const SW_CORE = "(()=>{class L extends Error{code;constructor(e,t){super(t);this.name=\"ProtocolError\",this.code=e}}async function et(e){let t=new Uint8Array(await crypto.subtle.digest(\"SHA-256\",new TextEncoder().encode(e))),n=\"\";for(let r of t)n+=String.fromCharCode(r);return btoa(n).replace(/\\+/g,\"-\").replace(/\\//g,\"_\").replace(/=+$/,\"\")}var Wn=\"dataset proof does not match its items\",ze=(e)=>typeof e===\"object\"&&e!==null&&!Array.isArray(e),Me=(e,t)=>Object.hasOwn(e,t)?e[t]:void 0;function Jt(e){let t=e?.toJSON;if(typeof e===\"object\"&&typeof t===\"function\")return Jt(t.call(e));if(Array.isArray(e))return`[${e.map((n)=>Jt(n)??\"null\").join(\",\")}]`;if(ze(e)){let n=[];for(let r of Object.keys(e).sort()){let s=Jt(e[r]);if(s!==void 0)n.push(`${JSON.stringify(r)}:${s}`)}return`{${n.join(\",\")}}`}return JSON.stringify(e)}function Ge(e){return Jt(e)??\"null\"}var Nn=1n<<256n,De=\"0\".repeat(64),cs=/^[0-9a-f]{64}$/;function Oe(e,t){return et(`${e}\\x00${Ge(t)}`)}function Ln(e){if(!/^[A-Za-z0-9_-]{43}$/.test(e))throw RangeError(\"not a row hash\");let t=atob(e.replace(/-/g,\"+\").replace(/_/g,\"/\")+\"=\"),n=\"\";for(let r=0;r<t.length;r++)n+=t.charCodeAt(r).toString(16).padStart(2,\"0\");return BigInt(`0x${n}`)}function us(e){if(!cs.test(e))throw RangeError(\"not a set digest\");return BigInt(`0x${e}`)}var qn=(e)=>((e%Nn+Nn)%Nn).toString(16).padStart(64,\"0\");function je(e,t){return qn(us(e)+Ln(t))}function Kt(e,t){return qn(us(e)-Ln(t))}async function Fn(e){let t=await Promise.all([...e].map(([r,s])=>Oe(r,s))),n=0n;for(let r of t)n+=Ln(r);return{kind:\"set\",count:e.size,digest:qn(n)}}function Hn(e){return ze(e)&&e.kind===\"set\"&&typeof e.count===\"number\"&&Number.isSafeInteger(e.count)&&e.count>=0&&typeof e.digest===\"string\"&&cs.test(e.digest)}function ls(e){let t=e.key;if(t===void 0)return;return(n)=>{let r=Me(n,t);if(typeof r!==\"string\")throw TypeError(`${t} is not a string key`);return r}}async function da(e,t,n){if(t.count!==e.length)return!1;let r=new Map;for(let s of e){if(!ze(s))return!1;let o;try{o=n(s)}catch{return!1}if(typeof o!==\"string\"||r.has(o))return!1;r.set(o,s)}return(await Fn(r)).digest===t.digest}async function fa(e,t,n){if(!ze(t))return!1;let r=Me(t,e.list),s=Me(t,\"proof\");if(!Array.isArray(r)||!ze(s))return!1;let o=s.kind;if(o===\"set\")return n!==void 0&&Hn(s)&&await da(r,s,n);if(o!==void 0&&o!==\"ordered\")return!1;if(s.count!==r.length||typeof s.digest!==\"string\")return!1;return await et(Ge(r))===s.digest}var pa=(e)=>e.trim()!==\"\"&&Number.isFinite(Number(e))?Number(e):null,as=(e)=>typeof e===\"number\"?0:typeof e===\"string\"?1:2;function ga(e,t){let[n,r]=[as(e),as(t)];if(n!==r)return n-r;if(n===2)return 0;return e<t?-1:e>t?1:0}function ya(e,t,n){let r=ze(t)?Me(t,e.list):void 0;if(!Array.isArray(r)||!r.every(ze))return null;let s=new URLSearchParams(n),o=e.filter??{};for(let w of new Set(s.keys()))if(w!==\"sort\"&&w!==\"page\"&&!Object.hasOwn(o,w))return null;let i=r;for(let[w,E]of Object.entries(o)){let O=s.getAll(w);if(O.length===0)continue;if(E===\"number\"){let M=O.map(pa);if(M.includes(null))return null;i=i.filter((z)=>{let Q=Me(z,w);return typeof Q===\"number\"&&M.includes(Q)})}else i=i.filter((M)=>{let z=Me(M,w),Q=typeof z===\"string\"||typeof z===\"number\"||typeof z===\"boolean\"?String(z):void 0;return Q!==void 0&&O.includes(Q)})}let a=s.getAll(\"sort\");if(a.length>1)return null;if(i=[...i],a.length===1){let w=a[0],E=e.sort??[],O=!E.includes(w)&&w.startsWith(\"-\"),M=O?w.slice(1):w;if(!E.includes(M))return null;i.sort((z,Q)=>{let te=ga(Me(z,M),Me(Q,M));return O?-te:te})}let u=s.getAll(\"page\");if(u.length>1)return null;let l=1;if(u.length===1){if(!/^[1-9]\\d{0,14}$/.test(u[0]))return null;l=Number(u[0])}let f=i.length,y=e.pageSize,m=y===void 0?1:Math.max(1,Math.ceil(f/y));if(l>m)return null;return{items:y===void 0?i:i.slice((l-1)*y,l*y),total:f,page:l,pages:m}}async function ds(e,t,n,r){if(!await fa(e,t,r))return{ok:!1,reason:Wn};return Un(e,t,n)}function Un(e,t,n){let r=ya(e,t,n);if(!r)return{ok:!1,reason:\"query is not one the route declares\"};let{items:s,total:o,page:i,pages:a}=r,u={total:o,page:i,pages:a};return{ok:!0,data:{...t,[e.list]:s,query:u}}}function zn(e){let t=e.indexOf(\"/\");if(t<1||t===e.length-1)return null;return{dataset:e.slice(0,t),key:e.slice(t+1)}}function ht(e){return typeof e===\"object\"&&e!==null&&!Array.isArray(e)}function Qt(e){if(!ht(e))return!1;let t=Object.keys(e);if(t.length!==1)return!1;let n=t[0];return(n===\"$record\"||n===\"$projection\"||n===\"$row\")&&typeof e[n]===\"string\"}function _e(e){let t=new Set,n=new Set,r=new Set,s=(o)=>{if(Array.isArray(o))return o.forEach(s);if(!ht(o))return;if(Qt(o)){if(\"$record\"in o)t.add(o.$record);else if(\"$row\"in o)r.add(o.$row);else n.add(o.$projection);return}Object.values(o).forEach(s)};return s(e),{records:[...t].sort(),projections:[...n].sort(),...r.size>0?{rows:[...r].sort()}:{}}}function Gn(e,t){let n=(r,s)=>{if(Array.isArray(r))return r.map((o)=>n(o,s));if(!ht(r))return r;if(Qt(r)){if(\"$record\"in r){let a=t.record(r.$record);if(!a)throw Error(`record ${r.$record} is not stored`);return a.data}if(\"$row\"in r){let a=zn(r.$row),u=a?t.row?.(a.dataset,a.key):void 0;if(u===void 0)throw Error(`row ${r.$row} is not held`);return u}let o=r.$projection;if(s.includes(o))throw Error(`projection ${o} reaches itself`);let i=t.projection(o);if(!i)throw Error(`projection ${o} is not stored`);return n(i.data,[...s,o])}return Object.fromEntries(Object.entries(r).map(([o,i])=>[o,n(i,s)]))};try{return{ok:!0,value:n(e,[])}}catch(r){return{ok:!1,reason:r instanceof Error?r.message:\"unresolved reference\"}}}function $e(e){throw new L(\"bad-artifact\",e)}function fs(e,t){if(typeof e!==\"number\"||!Number.isSafeInteger(e)||e<0)return $e(`${t} version must be a non-negative integer`);return e}function ps(e){if(!ht(e))return $e(\"record must be an object\");if(typeof e.id!==\"string\"||e.id===\"\")return $e(\"record id\");if(!(\"data\"in e))return $e(`record ${e.id} needs data`);return{id:e.id,version:fs(e.version,\"record\"),data:e.data}}function gs(e){if(!ht(e))return $e(\"projection must be an object\");let{id:t,deps:n}=e;if(typeof t!==\"string\"||t===\"\")return $e(\"projection id\");if(!Array.isArray(n)||n.some((r)=>typeof r!==\"string\"))return $e(`projection ${t} deps must be a list of strings`);if(!(\"data\"in e))return $e(`projection ${t} needs data`);return{id:t,version:fs(e.version,\"projection\"),deps:n,data:e.data}}var F=1;function me(e){throw new L(\"bad-artifact\",e)}function Jn(e){return typeof e===\"object\"&&e!==null&&!Array.isArray(e)}function ys(e,t){if(e===void 0)return;if(!Jn(e))return me(`${t} must be an object`);for(let n of Object.values(e))if(typeof n!==\"string\"&&!Qt(n))return me(`${t} values must be strings or references`);return e}function ms(e,t,n){if(e===void 0)return;if(!Array.isArray(e))return me(`${t} must be a list`);return e.map(n)}function wt(e){if(!Jn(e))return me(\"artifact must be an object\");if(e.protocol!==F)return me(\"unsupported protocol version\");let{id:t,scope:n,deps:r,vector:s,strategy:o,body:i}=e;if(typeof t!==\"string\"||!t.startsWith(\"/\"))return me(\"id must be a path\");if(n!==\"public\"&&n!==\"principal\")return me(\"scope must be public or principal\");if(!Array.isArray(r)||r.some((f)=>typeof f!==\"string\"))return me(\"deps must be a list of strings\");if(typeof s!==\"number\"||!Number.isSafeInteger(s)||s<0)return me(\"vector must be a non-negative integer\");if(!Jn(i))return me(\"body must be an object\");let a={protocol:F,id:t,scope:n,deps:r,vector:s},u=ms(e.records,\"records\",ps),l=ms(e.projections,\"projections\",gs);if(u)a.records=u;if(l)a.projections=l;if(o===\"template\"||o===\"projection\"||o===\"data\"){if(!(\"data\"in i))return me(`${o} body needs data`);return{...a,strategy:o,body:{data:i.data}}}if(o===\"assembly\"){if(typeof i.shell!==\"string\")return me(\"assembly body needs a shell string\");let f={shell:i.shell},y=ys(i.fragments,\"fragments\"),m=ys(i.slots,\"slots\");if(y)f.fragments=y;if(m)f.slots=m;return{...a,strategy:o,body:f}}return me(`unknown strategy ${String(o)}`)}function B(e){return new Promise((t,n)=>{e.onsuccess=()=>t(e.result),e.onerror=()=>n(e.error)})}function bt(e){return new Promise((t,n)=>{e.oncomplete=()=>t(),e.onerror=()=>n(e.error),e.onabort=()=>n(e.error)})}function Xt(e=indexedDB,t=\"spool\"){let n,r,s=()=>n??=new Promise((a,u)=>{let l=e.open(t,2);l.onupgradeneeded=()=>{let f=l.result,y=(m)=>!f.objectStoreNames.contains(m);if(y(\"artifacts\"))f.createObjectStore(\"artifacts\",{keyPath:\"artifact.id\"});if(y(\"meta\"))f.createObjectStore(\"meta\");if(y(\"beacons\"))f.createObjectStore(\"beacons\",{autoIncrement:!0});if(y(\"records\"))f.createObjectStore(\"records\",{keyPath:\"id\"});if(y(\"projections\"))f.createObjectStore(\"projections\",{keyPath:\"id\"})},l.onsuccess=()=>{let f=l.result;f.onversionchange=()=>{f.close(),n=void 0},a(f)},l.onerror=()=>u(l.error)}),o=()=>r??=new Promise((a,u)=>{let l=e.open(`${t}-datasets`,1);l.onupgradeneeded=()=>{let f=l.result;f.createObjectStore(\"datasetRows\",{keyPath:[\"name\",\"key\"]}),f.createObjectStore(\"datasetMeta\",{keyPath:\"name\"})},l.onsuccess=()=>{let f=l.result;f.onversionchange=()=>{f.close(),r=void 0},a(f)},l.onerror=()=>u(l.error)});async function i(a,u,l,f=s){let m=(await f()).transaction(a,u),w=bt(m),E=await l(m.objectStore(a));return await w,E}return{destroy:async()=>{let a=await Promise.all([n,r].map((u)=>u?.catch(()=>{return})));for(let u of a)u?.close();n=void 0,r=void 0;for(let u of[t,`${t}-datasets`])await new Promise((l)=>{let f=e.deleteDatabase(u);f.onsuccess=()=>l(),f.onerror=()=>l()})},getArtifact:(a)=>i(\"artifacts\",\"readonly\",(u)=>B(u.get(a))),putArtifact:(a)=>i(\"artifacts\",\"readwrite\",async(u)=>void await B(u.put(a))),deleteArtifacts:(a)=>i(\"artifacts\",\"readwrite\",async(u)=>{await Promise.all(a.map((l)=>B(u.delete(l))))}),allArtifacts:()=>i(\"artifacts\",\"readonly\",(a)=>B(a.getAll())),clearArtifacts:()=>i(\"artifacts\",\"readwrite\",async(a)=>void await B(a.clear())),getMeta:()=>i(\"meta\",\"readonly\",(a)=>B(a.get(\"replica\"))),setMeta:(a)=>i(\"meta\",\"readwrite\",async(u)=>void await B(u.put(a,\"replica\"))),addBeacon:(a)=>i(\"beacons\",\"readwrite\",async(u)=>void await B(u.add(a))),readBeacons:()=>i(\"beacons\",\"readonly\",async(a)=>{let[u,l]=await Promise.all([B(a.getAllKeys()),B(a.getAll())]);return u.map((f,y)=>({key:f,event:l[y]}))}),removeBeacons:(a)=>i(\"beacons\",\"readwrite\",async(u)=>{await Promise.all(a.map((l)=>B(u.delete(l))))}),getFlush:()=>i(\"meta\",\"readonly\",(a)=>B(a.get(\"flush\"))),setFlush:(a)=>i(\"meta\",\"readwrite\",async(u)=>void await B(u.put(a,\"flush\"))),putRecords:(a)=>i(\"records\",\"readwrite\",async(u)=>{await Promise.all(a.map((l)=>B(u.put(l))))}),allRecords:()=>i(\"records\",\"readonly\",(a)=>B(a.getAll())),deleteRecords:(a)=>i(\"records\",\"readwrite\",async(u)=>{await Promise.all(a.map((l)=>B(u.delete(l))))}),putProjections:(a)=>i(\"projections\",\"readwrite\",async(u)=>{await Promise.all(a.map((l)=>B(u.put(l))))}),allProjections:()=>i(\"projections\",\"readonly\",(a)=>B(a.getAll())),deleteProjections:(a)=>i(\"projections\",\"readwrite\",async(u)=>{await Promise.all(a.map((l)=>B(u.delete(l))))}),clearGraph:async()=>{await i(\"records\",\"readwrite\",async(a)=>void await B(a.clear())),await i(\"projections\",\"readwrite\",async(a)=>void await B(a.clear()))},getDatasets:()=>i(\"datasetMeta\",\"readonly\",(a)=>B(a.getAll()),o),readDataset:(a)=>i(\"datasetRows\",\"readonly\",(u)=>B(u.getAll(IDBKeyRange.bound([a],[a,[]]))),o),commitDataset:async(a)=>{let l=(await o()).transaction([\"datasetRows\",\"datasetMeta\"],\"readwrite\",{durability:\"strict\"}),f=bt(l);f.catch(()=>{return});try{let y=l.objectStore(\"datasetRows\"),m=l.objectStore(\"datasetMeta\");if(a.clear)y.delete(IDBKeyRange.bound([a.name],[a.name,[]]));for(let w of a.deletes)y.delete([a.name,w]);for(let w of a.puts)y.put(w);if(a.meta)m.put(a.meta);else m.delete(a.name)}catch(y){try{l.abort()}catch{}throw y}await f},clearDatasets:async()=>{let u=(await o()).transaction([\"datasetRows\",\"datasetMeta\"],\"readwrite\"),l=bt(u);u.objectStore(\"datasetRows\").clear(),u.objectStore(\"datasetMeta\").clear(),await l}}}var Kn=new TextEncoder,ma=new TextDecoder;async function Rt(e,t,n,r){let s=crypto.getRandomValues(new Uint8Array(12)),o=await crypto.subtle.encrypt({name:\"AES-GCM\",iv:s,additionalData:Kn.encode(t)},e,Kn.encode(JSON.stringify(n)));return{sealed:{iv:s,data:o,at:r}}}async function tt(e,t,n,r){let s=r?.sealed;if(!s)return;let o=await e.get(t,s.at,!1);if(!o)return;try{let i=await crypto.subtle.decrypt({name:\"AES-GCM\",iv:s.iv,additionalData:Kn.encode(n)},o,s.data);return JSON.parse(ma.decode(i))}catch{return}}function hs(e,t){let{partition:n,vault:r}=t,s=!1,o=(u,l)=>`${n}\\x00${u}\\x00${l}`;async function i(u,l,f,y){let m=await r.get(n,u,!0);if(!m)throw Error(\"no key\");return Rt(m,o(l,f),y,u)}let a=(u,l,f)=>tt(r,n,o(u,l),f);return{kill:()=>{s=!0,t.datasets?.kill()},async getArtifact(u){if(s)return;let l=await e.getArtifact(u);if(!l)return;let f=await a(\"artifact\",u,l);if(!f)await e.deleteArtifacts([u]);return f},async putArtifact(u){if(s)return;let l=u.artifact.id,f=await i(t.retentionOf(l),\"artifact\",l,u);if(s)return;await e.putArtifact({artifact:{id:l},...f})},deleteArtifacts:(u)=>s?Promise.resolve():e.deleteArtifacts(u),async allArtifacts(){if(s)return[];let u=[],l=[];for(let f of await e.allArtifacts()){let y=f.artifact.id,m=await a(\"artifact\",y,f);if(m)u.push(m);else l.push(y)}if(l.length>0)await e.deleteArtifacts(l);return u},clearArtifacts:()=>s?Promise.resolve():e.clearArtifacts(),async getMeta(){if(s)return;return a(\"meta\",\"replica\",await e.getMeta())},async setMeta(u){if(s)return;let l=await i(t.shared,\"meta\",\"replica\",u);if(!s)await e.setMeta(l)},addBeacon:(u)=>e.addBeacon(u),readBeacons:()=>e.readBeacons(),removeBeacons:(u)=>e.removeBeacons(u),getFlush:()=>e.getFlush(),setFlush:(u)=>e.setFlush(u),async putRecords(u){if(s)return;let l=await Promise.all(u.map(async(f)=>({id:f.id,version:f.version,...await i(t.shared,\"record\",f.id,f)})));if(!s)await e.putRecords(l)},async allRecords(){if(s)return[];let u=[];for(let l of await e.allRecords()){let f=await a(\"record\",l.id,l);if(f)u.push(f)}return u},deleteRecords:(u)=>s?Promise.resolve():e.deleteRecords(u),async putProjections(u){if(s)return;let l=await Promise.all(u.map(async(f)=>({id:f.id,version:f.version,...await i(t.shared,\"projection\",f.id,f)})));if(!s)await e.putProjections(l)},async allProjections(){if(s)return[];let u=[];for(let l of await e.allProjections()){let f=await a(\"projection\",l.id,l);if(f)u.push(f)}return u},deleteProjections:(u)=>s?Promise.resolve():e.deleteProjections(u),clearGraph:()=>s?Promise.resolve():e.clearGraph(),getDatasets:t.datasets?.getDatasets??(async()=>[]),readDataset:t.datasets?.readDataset??(async()=>[]),commitDataset:t.datasets?.commitDataset??(()=>Promise.reject(Error(\"a principal partition holds no dataset\"))),clearDatasets:t.datasets?.clearDatasets??(async()=>{return})}}var Rs=\"spool-principal-datasets\",Ce=\"rows\",ke=\"meta\",ha=new TextEncoder;function wa(e){return new Promise((t,n)=>{e.onsuccess=()=>t(e.result),e.onerror=()=>n(e.error)})}function Yt(e){return new Promise((t,n)=>{e.oncomplete=()=>t(),e.onerror=()=>n(e.error),e.onabort=()=>n(e.error)})}var St=(e)=>IDBKeyRange.bound([e],[e,[]]),ws=(e,t)=>IDBKeyRange.bound([e,t],[e,t,[]]);function Ss(e,t){let n,r=()=>n??=new Promise((i,a)=>{let u=e.open(Rs,1);u.onupgradeneeded=()=>{let l=u.result;l.createObjectStore(Ce,{keyPath:[\"partition\",\"name\",\"slot\"]}),l.createObjectStore(ke,{keyPath:[\"partition\",\"name\"]})},u.onsuccess=()=>{let l=u.result;l.onversionchange=()=>{l.close(),n=void 0},i(l)},u.onerror=()=>a(u.error)}),s=(i)=>{let{partition:a,...u}=i;return u};async function o(i,a){let l=(await r()).transaction(i,\"readonly\"),f=Yt(l),y=await wa(a(l.objectStore(i)));return await f,y}return{metas:async()=>(await o(ke,(i)=>i.getAll(St(t)))).map((i)=>s(i)),meta:async(i)=>{let a=await o(ke,(u)=>u.get([t,i]));return a?s(a):void 0},rows:async(i)=>(await o(Ce,(a)=>a.getAll(ws(t,i)))).map((a)=>s(a)),commit:async(i)=>{let u=(await r()).transaction([Ce,ke],\"readwrite\",{durability:\"strict\"}),l=Yt(u);l.catch(()=>{return});try{let f=u.objectStore(Ce),y=u.objectStore(ke);if(i.clear)f.delete(ws(t,i.name));for(let m of i.deletes)f.delete([t,i.name,m]);for(let m of i.puts)f.put({partition:t,...m});if(i.meta)y.put({partition:t,...i.meta});else y.delete([t,i.name])}catch(f){try{u.abort()}catch{}throw f}await l},clear:async()=>{let a=(await r()).transaction([Ce,ke],\"readwrite\"),u=Yt(a);a.objectStore(Ce).delete(St(t)),a.objectStore(ke).delete(St(t)),await u}}}async function vs(e,t){let n=await new Promise((r)=>{let s=e.open(Rs);s.onupgradeneeded=()=>{try{s.transaction?.abort()}catch{}},s.onsuccess=()=>r(s.result),s.onerror=()=>r(null),s.onblocked=()=>r(null)});if(!n)return;try{if(!n.objectStoreNames.contains(Ce)||!n.objectStoreNames.contains(ke))return;let r=n.transaction([Ce,ke],\"readwrite\"),s=Yt(r);r.objectStore(Ce).delete(St(t)),r.objectStore(ke).delete(St(t)),await s}catch{}finally{n.close()}}function bs(e){let t=\"\";for(let n of e)t+=String.fromCharCode(n);return btoa(t).replace(/\\+/g,\"-\").replace(/\\//g,\"_\").replace(/=+$/,\"\")}function ks(e,t){let{partition:n,vault:r,retention:s}=t,o=!1,i=new Map,a=(w)=>`${n}\\x00dataset-meta\\x00${w}`,u=(w,E)=>`${n}\\x00dataset-row\\x00${w}\\x00${E}`;async function l(w,E){let O=await r.get(n,s,!0);if(!O)throw Error(\"no key\");return Rt(O,w,E,s)}async function f(w,E,O){let M=ha.encode(`${O}\\x00${w}\\x00${E}`);return bs(new Uint8Array(await crypto.subtle.digest(\"SHA-256\",M)))}async function y(w){let E=await tt(r,n,a(w.name),w);if(E)return i.set(w.name,E.salt),E;i.delete(w.name),await e.commit({name:w.name,meta:null,clear:!0,puts:[],deletes:[]});return}async function m(w){let E=i.get(w);if(E!==void 0)return E;let O=await e.meta(w);return O?(await y(O))?.salt:void 0}return{kill:()=>void(o=!0),async getDatasets(){if(o)return[];let w=[];for(let E of await e.metas()){let O=await y(E);if(O)w.push(O.meta)}return w},async readDataset(w){if(o||await m(w)===void 0)return[];let E=[];for(let O of await e.rows(w)){let M=await tt(r,n,u(w,O.slot),O);if(M&&M.name===w)E.push(M)}return E.sort((O,M)=>O.key<M.key?-1:O.key>M.key?1:0)},async commitDataset(w){if(o)return;let{name:E}=w;if(w.meta===null){await e.commit({name:E,meta:null,clear:!0,puts:[],deletes:[]}),i.delete(E);return}let O=w.clear?void 0:await m(E),M=O===void 0;O??=bs(crypto.getRandomValues(new Uint8Array(16)));let z=[];for(let re of w.puts){let ce=await f(E,re.key,O);z.push({name:E,slot:ce,...await l(u(E,ce),re)})}let Q=await Promise.all(w.deletes.map((re)=>f(E,re,O))),te=await l(a(E),{meta:w.meta,salt:O});if(o)return;await e.commit({name:E,meta:{name:E,...te},clear:w.clear||M,puts:z,deletes:Q}),i.set(E,O)},async clearDatasets(){if(o)return;await e.clear(),i.clear()}}}var vt=\"spool:artifact:\",Qn=64,Ps=256;function Xn(e){return`${vt}${e}`}function Ne(e){throw new L(\"bad-sync\",e)}function Yn(e){return Object.entries(e).map(([t,n])=>`${encodeURIComponent(t)}@${n}`).join(\",\")}function Zt(e){if(typeof e!==\"object\"||e===null)return Ne(\"sync response must be an object\");let t=e;if(t.protocol!==F)return Ne(\"unsupported protocol version\");let{cursor:n,changed:r,dropped:s,reset:o,partial:i}=t;if(typeof n!==\"number\"||!Number.isSafeInteger(n)||n<0)return Ne(\"cursor must be a non-negative integer\");if(typeof r!==\"object\"||r===null||Array.isArray(r))return Ne(\"changed must be an object\");for(let u of Object.values(r))if(typeof u!==\"number\"||!Number.isSafeInteger(u))return Ne(\"changed versions must be integers\");if(!Array.isArray(s)||s.some((u)=>typeof u!==\"string\"))return Ne(\"dropped must be a list of strings\");if(typeof o!==\"boolean\")return Ne(\"reset must be a boolean\");if(i!==void 0&&typeof i!==\"boolean\")return Ne(\"partial must be a boolean\");let a={protocol:F,cursor:n,changed:r,dropped:s,reset:o};if(i)a.partial=!0;return a}var K={protocol:\"spool-protocol\",artifact:\"spool-artifact\",invalidate:\"spool-invalidate\",clear:\"spool-clear\",vector:\"spool-vector\",partition:\"spool-partition\",vectorSeen:\"spool-vector-seen\",provision:\"spool-provision\",provisionReason:\"spool-provision-reason\",delta:\"spool-delta\",have:\"spool-have\"},Zn=\"*\",ba=/^[A-Za-z0-9_-]{1,128}$/,Ra=/^[A-Za-z0-9_-]{43}$/;function We(e){throw new L(\"bad-header\",e)}function kt(e,t){if(!/^\\d{1,15}$/.test(e.trim()))return We(`${t} must be a non-negative integer`);return Number(e)}function Pt(e,t){try{return decodeURIComponent(e)}catch{return We(`${t} has a bad escape`)}}function en(e){return e.split(\",\").map((t)=>t.trim()).filter((t)=>t!==\"\")}function xt(e){try{return er(e)}catch{let t=e.get(K.protocol)?.trim();if(t&&/^\\d{1,15}$/.test(t)&&Number(t)!==F)return;let n=e.get(K.clear);if(n===null)return;try{return{protocol:F,clear:en(n).map((r)=>Pt(r,\"Spool-Clear\"))}}catch{return{protocol:F,clear:[Zn]}}}}function er(e){let t={},n=e.get(K.protocol);if(n!==null)t.protocol=kt(n,\"Spool-Protocol\");let r=e.get(K.artifact);if(r!==null){let l=new Map;for(let E of r.split(\";\")){let O=E.indexOf(\"=\");if(O<1)return We(\"Spool-Artifact has a field without a name\");l.set(E.slice(0,O).trim(),E.slice(O+1).trim())}let f=l.get(\"id\"),y=l.get(\"scope\"),m=l.get(\"v\");if(f===void 0||m===void 0)return We(\"Spool-Artifact needs id and v\");if(y!==\"public\"&&y!==\"principal\")return We(\"Spool-Artifact scope is unknown\");t.artifact={id:Pt(f,\"Spool-Artifact id\"),scope:y,deps:en(l.get(\"deps\")??\"\").map((E)=>Pt(E,\"Spool-Artifact deps\")),version:kt(m,\"Spool-Artifact v\")};let w=l.get(\"h\");if(w!==void 0&&Ra.test(w))t.artifact.hash=w}let s=e.get(K.invalidate);if(s!==null)t.invalidate=Object.fromEntries(en(s).map((l)=>{let f=l.lastIndexOf(\"=\");if(f<1)return We(\"Spool-Invalidate entries are tag=version\");return[Pt(l.slice(0,f),\"Spool-Invalidate tag\"),kt(l.slice(f+1),\"Spool-Invalidate version\")]}));let o=e.get(K.clear);if(o!==null)t.clear=en(o).map((l)=>Pt(l,\"Spool-Clear\"));let i=e.get(K.vector);if(i!==null)t.vector=kt(i,\"Spool-Vector\");let a=e.get(K.vectorSeen);if(a!==null)t.seen=kt(a,\"Spool-Vector-Seen\");let u=e.get(K.partition);if(u!==null){if(!ba.test(u))return We(\"Spool-Partition must be a base64url token\");t.partition=u}return t}function xs(e){let t=Zt(e),n=e.from;if(typeof n!==\"number\"||!Number.isSafeInteger(n)||n<0)return We(\"from must be a non-negative integer\");return{...t,from:n}}var Sa=/^[A-Za-z_][A-Za-z0-9_]*$/;function tn(e){let t=e.length>1&&e.endsWith(\"/\")?e.slice(0,-1):e;return t===\"/\"?[]:t.slice(1).split(\"/\")}function nn(e){if(!e.startsWith(\"/\"))throw new L(\"bad-pattern\",`pattern must start with \"/\": ${e}`);let t=new Set,n=tn(e);for(let[r,s]of n.entries()){if(s===\"\")throw new L(\"bad-pattern\",`empty segment in ${e}`);if(s===\"**\"){if(r!==n.length-1)throw new L(\"bad-pattern\",`\"**\" must be the last segment in ${e}`);continue}if(!s.startsWith(\":\"))continue;let o=s.slice(1);if(!Sa.test(o))throw new L(\"bad-pattern\",`bad parameter name \"${o}\" in ${e}`);if(t.has(o))throw new L(\"bad-pattern\",`duplicate parameter \"${o}\" in ${e}`);t.add(o)}}function Pe(e,t){let n=tn(e),r=tn(t),s=n[n.length-1]===\"**\";if(s)n.pop();if(s?r.length<n.length:n.length!==r.length)return null;let o={};for(let i=0;i<n.length;i++){let a=n[i],u=r[i];if(a.startsWith(\":\")){if(u===\"\")return null;try{o[a.slice(1)]=decodeURIComponent(u)}catch{return null}}else if(a!==u)return null}return o}function As(e,t){return`/${tn(e).map((r)=>{if(r===\"**\")throw new L(\"bad-pattern\",`${e} has no single path to fill`);if(!r.startsWith(\":\"))return r;let s=t[r.slice(1)];if(s===void 0)throw new L(\"bad-pattern\",`missing parameter \"${r.slice(1)}\" for ${e}`);return encodeURIComponent(s)}).join(\"/\")}`}function va(e,t){let n=e.split(\"/\");return!n.includes(\"**\")&&n.every((r)=>!r.startsWith(\":\")||r===`:${t}`)}function Es(e){let t=[],n=new Map;for(let r of e){if(r.scope!==\"public\")continue;if(r.family&&va(r.pattern,r.family.key))t.push({dataset:r.family.dataset,pattern:r.pattern,key:r.family.key});let s=r.query;if(s?.dataset!==void 0&&s.plan===void 0){let o=n.get(s.dataset)??new Set;n.set(s.dataset,o);for(let i of[...Object.keys(s.filter??{}),...s.sort??[]])o.add(i)}}return{paths:t,fields:new Map([...n].map(([r,s])=>[r,[...s]]))}}function Ts(e,t,n,r){let s=[];for(let i of e.paths){if(i.dataset!==t)continue;let a=As(i.pattern,{[i.key]:n});s.push([`path:${t}`,a,r===void 0?null:{key:n}])}let o=e.fields.get(t);if(o!==void 0)s.push([`query:${t}`,n,r===void 0?null:ka(r,o)]);return s}function ka(e,t){return Object.fromEntries(t.filter((n)=>Object.hasOwn(e,n)).map((n)=>[n,e[n]]))}var Os=200,Pa=/^[1-9]\\d{0,14}$/,xa=/^[+-]?(\\d+\\.?\\d*|\\.\\d+)(e[+-]?\\d+)?$/i,Aa=/[\\uD800-\\uDBFF](?![\\uDC00-\\uDFFF])|(?<![\\uD800-\\uDBFF])[\\uDC00-\\uDFFF]/;class rn extends Error{}var xe=(e,t)=>Object.hasOwn(e,t)?e[t]??null:null,Ea=(e)=>typeof e===\"object\"&&e!==null&&!Array.isArray(e),ae=(e)=>typeof e===\"number\"?1:typeof e===\"string\"?2:0,sn=(e)=>e.replace(/[A-Z]+/g,(t)=>t.toLowerCase());function js(e){if(e===null||e===void 0)return!0;if(typeof e===\"number\")return Number.isFinite(e);if(typeof e===\"string\")return!Aa.test(e)&&!e.includes(\"\\x00\");return!1}function Et(e,t){let n=Math.min(e.length,t.length);for(let r=0;r<n;r++){let s=e.charCodeAt(r),o=t.charCodeAt(r);if(s===o)continue;let i=s>=55296&&s<=57343,a=o>=55296&&o<=57343;if(i!==a)return i?1:-1;return s-o}return e.length-t.length}function Le(e,t){let n=ae(e),r=ae(t);if(n!==r)return n-r;if(n===0)return 0;if(n===1)return e<t?-1:e>t?1:0;return Et(e,t)}function Ta(e,t){for(let n=0;n<e.length;n++){let r=Le(e[n],t[n]);if(r!==0)return r}return 0}var Cs=(e,t)=>ae(e)!==0&&ae(e)===ae(t)&&e===t,tr=(e)=>e.sort(Et);function At(e,t){let n=0,r=e.length;while(n<r){let s=n+r>>>1;if(t(e[s]))r=s;else n=s+1}return n}class rr{#e;#t;#r=new Map;#o=new Map;#s=new Map;#n=0;#i=0;constructor(e,t){this.#e=e,this.#t=t}get built(){return this.#n}get entries(){return this.#i}clean(e){let t=this.#r.get(e);if(t===void 0)t=this.#e.every((n)=>js(xe(this.#t.get(n),e))),this.#r.set(e,t);return t}equal(e,t){let n=this.#a(e),r=t.length===1?n.get(`${ae(t[0])}${String(t[0])}`):void 0;if(r)return[...r];let s=new Set;for(let o of t)for(let i of n.get(`${ae(o)}${String(o)}`)??[])s.add(i);return tr([...s])}range(e,t,n){let r=this.#c(`r\\x00${e}`,e,(l)=>ae(l)===0?void 0:l),s=ae(n),o=At(r,(l)=>ae(l[0])>=s),i=At(r,(l)=>ae(l[0])>s),[a,u]=t===\"gte\"?[At(r,(l)=>Le(l[0],n)>=0),i]:[o,At(r,(l)=>Le(l[0],n)>0)];return tr(r.slice(Math.max(a,o),u).map((l)=>l[1]))}prefix(e,t,n){let r=this.#c(`p\\x00${t??\"\"}\\x00${e}`,e,(i)=>typeof i===\"string\"?t===\"ascii\"?sn(i):i:void 0),s=t===\"ascii\"?sn(n):n,o=[];for(let i=At(r,(a)=>Le(a[0],s)>=0);i<r.length;i++){let[a,u]=r[i];if(!a.startsWith(s))break;o.push(u)}return tr(o)}#a(e){let t=this.#o.get(e);if(!t){t=new Map;for(let n of this.#e){let r=xe(this.#t.get(n),e);if(ae(r)===0)continue;let s=`${ae(r)}${String(r)}`,o=t.get(s);if(o)o.push(n);else t.set(s,[n]);this.#i+=1}this.#o.set(e,t),this.#n+=1}return t}#c(e,t,n){let r=this.#s.get(e);if(!r){r=[];for(let s of this.#e){let o=n(xe(this.#t.get(s),t));if(o!==void 0)r.push([o,s])}r.sort((s,o)=>Le(s[0],o[0])||Et(s[1],o[1])),this.#s.set(e,r),this.#n+=1,this.#i+=r.length}return r}}function Ds(e,t){if(e.index)return e.index.clean(t);return e.keys.every((n)=>js(xe(e.rows.get(n),t)))}function on(e,t){if(e.from.includes(t))return{join:-1,field:t};let n=t.indexOf(\".\");if(n<0)return;let r=t.slice(0,n),s=t.slice(n+1),o=(e.join??[]).findIndex((i)=>i.as===r);if(o<0||!(e.join?.[o]?.fields??[]).includes(s))return;return{join:o,field:s}}function an(e,t){if(t.join<0)return xe(e.base,t.field);let n=e.joined[t.join];return n?xe(n,t.field):null}function Da(e,t){if(e.op!==\"in\"&&t.length!==1)return null;let n=[];for(let r of t)if(e.type===\"number\"){if(!xa.test(r))return null;let s=Number(r);if(!Number.isFinite(s))return null;n.push(s)}else{if(r.includes(\"\\x00\"))return null;n.push(r)}return n}function Oa(e,t){let{cond:n,values:r}=e;if(n.op===\"eq\"||n.op===\"in\")return r.some((o)=>Cs(t,o));if(n.op===\"gte\"||n.op===\"lte\"){let o=r[0];if(ae(t)===0||ae(t)!==ae(o))return!1;let i=Le(t,o);return n.op===\"gte\"?i>=0:i<=0}if(typeof t!==\"string\")return!1;let s=r[0];return n.fold===\"ascii\"?sn(t).startsWith(sn(s)):t.startsWith(s)}function ja(e,t,n){let r=xe(n,e.on[0]);if(e.on[1]===null)return typeof r===\"string\"&&t.rows.has(r)?[r]:[];if(ae(r)===0)return[];let s=e.on[1];if(t.index&&t.keys.length>=Os)return t.index.equal(s,[r]);return t.keys.filter((o)=>Cs(xe(t.rows.get(o),s),r))}function nr(e,t,n,r,s){if(r===e.length){s.push(n);return}let o=e[r],i=t[r],a=ja(o,i,n.base);if(a.length===0){if(o.type===\"left\")nr(e,t,{...n,keys:[...n.keys,null],joined:[...n.joined,null]},r+1,s);return}for(let u of a){let l=i.rows.get(u);nr(e,t,{base:n.base,keys:[...n.keys,u],joined:[...n.joined,l]},r+1,s)}}function Ca(e,t,n){if(t===\"count\")return n.length;let[r,s]=Object.entries(t)[0],o=on(e,s),i=n.map((u)=>an(u,o)).filter((u)=>u!==null);if(r===\"count\")return i.length;if(r===\"min\"||r===\"max\"){if(i.length===0)return null;return i.reduce((u,l)=>{let f=Le(l,u);return r===\"min\"?f<0?l:u:f>0?l:u})}if(i.length===0)return null;let a=0;for(let u of i){if(typeof u!==\"number\"||!Number.isSafeInteger(u))throw new rn;if(a+=u,!Number.isSafeInteger(a))throw new rn}return r===\"sum\"?a:a/i.length}function Ba(e,t){let n=e.from.map((s)=>[s,xe(t.base,s)]),r=(e.join??[]).map((s,o)=>{let i=t.joined[o],a=s.fields.map((u)=>[u,i?xe(i,u):null]);return[s.as,Object.fromEntries(a)]});return Object.fromEntries([...n,...r])}function Ia(e,t,n,r){let s=t.by.map((a)=>on(e,a)),o=new Map;if(t.by.length===0)o.set(\"[]\",{by:[],members:[]});for(let a of n){let u=s.map((y)=>an(a,y)),l=JSON.stringify(u.map((y)=>y===null?\"0\":`${ae(y)}${String(y)}`)),f=o.get(l)??{by:u,members:[]};f.members.push(a),o.set(l,f)}let i=Object.entries(t.aggregates);return[...o.values()].map(({by:a,members:u})=>{let l=Object.fromEntries([...t.by.map((f,y)=>[f,a[y]??null]),...i.map(([f,y])=>[f,Ca(e,y,u)])]);return{row:l,sort:r.map((f)=>l[f]),tie:a}})}function Ma(e,t,n){let r=new URLSearchParams(t),s=e.where??[],o=e.join??[];for(let C of new Set(r.keys()))if(C!==\"sort\"&&C!==\"page\"&&!s.some((N)=>N.param===C))return null;let i=[];for(let C of s){let N=r.getAll(C.param);if(N.length===0)continue;let X=Da(C,N);if(!X)return null;i.push({cond:C,ref:on(e,C.field),values:X})}let a=r.getAll(\"sort\");if(a.length>1)return null;let u=[];if(a.length===1){let C=a[0],N=C.startsWith(\"-\"),X=N?C.slice(1):C;if(!(e.sort??[]).includes(X))return null;u.push({name:X,desc:N})}let l=r.getAll(\"page\");if(l.length>1)return null;let f=1;if(l.length===1){if(!Pa.test(l[0]))return null;f=Number(l[0])}let y=n.base,m=[];for(let C of o){let N=n.joined(C.dataset);if(!N)return null;m.push(N)}for(let C of e.from)if(!Ds(y,C))return null;for(let C=0;C<o.length;C++){let N=o[C],X=N.on[1]===null?N.fields:[...N.fields,N.on[1]];for(let we of X)if(!Ds(m[C],we))return null}let w=y.keys,E=i.find((C)=>C.ref.join<0);if(E&&y.index&&y.keys.length>=Os){let{cond:C,ref:N,values:X}=E;w=C.op===\"gte\"||C.op===\"lte\"?y.index.range(N.field,C.op,X[0]):C.op===\"prefix\"?y.index.prefix(N.field,C.fold,X[0]):y.index.equal(N.field,X)}let O=[];for(let C of w){let N=y.rows.get(C);nr(o,m,{base:N,keys:[C],joined:[]},0,O)}let M=O.filter((C)=>i.every((N)=>Oa(N,an(C,N.ref)))),z=e.group,Q=u.map((C)=>C.name),te;if(z)te=Ia(e,z,M,Q);else{if(M.length>e.limit)return null;let C=Q.map((N)=>on(e,N));te=M.map((N)=>({row:Ba(e,N),sort:C.map((X)=>an(N,X)),tie:N.keys}))}if(te.length>e.limit)return null;te.sort((C,N)=>{for(let X=0;X<u.length;X++){let we=Le(C.sort[X],N.sort[X]);if(we!==0)return u[X]?.desc?-we:we}return Ta(C.tie,N.tie)});let re=te.length,ce=e.pageSize,qe=Math.max(1,Math.ceil(re/ce));if(f>qe)return null;return{items:te.slice((f-1)*ce,f*ce).map((C)=>C.row),total:re,page:f,pages:qe}}function $a(e,t,n){try{return Ma(e,t,n)}catch(r){if(r instanceof rn)return null;throw r}}function Bs(e,t,n,r,s){if(!s)return{ok:!1,reason:\"plan needs its datasets\"};let o=$a(t,r,s);if(!o)return{ok:!1,reason:\"query is not one the route declares\"};let{items:i,total:a,page:u,pages:l}=o;return{ok:!0,data:{...Ea(n)?n:{},[e]:i,query:{total:a,page:u,pages:l}}}}var Is={public:{maxStale:900,mode:\"soft\"},principal:{maxStale:300,mode:\"hard\"}};function Se(e,t){for(let n of e){let r=Pe(n.pattern,t);if(r)return{route:n,params:r}}return null}var cn={id:\"spool-write-id\",digest:\"spool-write-digest\"};var _a=/^[A-Za-z0-9._:~-]{1,128}$/;var Na=256;var Ms={\"writes-off\":403,\"unknown-write\":404,\"bad-method\":405,\"bad-key\":400,\"missing-version\":428,\"bad-version\":400,\"bad-id\":400,\"bad-body\":400,\"too-large\":413,\"too-many\":429,\"id-reused\":422,forbidden:403,\"sign-in\":401,\"no-partition\":409,\"no-record\":404,\"not-conflicted\":409,unavailable:503};function $s(e){return typeof e===\"string\"&&e.length>0&&e.length<=Na&&!e.includes(\"\\x00\")}var un=(e)=>typeof e===\"string\"&&_a.test(e);var _s=(e)=>`\"${e}\"`;function ln(){let e=crypto.getRandomValues(new Uint8Array(16)),t=\"\";for(let n of e)t+=String.fromCharCode(n);return btoa(t).replace(/\\+/g,\"-\").replace(/\\//g,\"_\").replace(/=+$/,\"\")}var Ns=(e)=>typeof e===\"object\"&&e!==null&&!Array.isArray(e),Wa=(e)=>Ns(e)&&Object.keys(e).length===1&&typeof e.body===\"string\";function La(e,t){let n=e;for(let r of t.split(\".\")){if(!Ns(n)||!Object.prototype.hasOwnProperty.call(n,r))return;n=n[r]}return n}function Ws(e,t,n){let r={...e};for(let[s,o]of Object.entries(n.set??{})){if(!Wa(o)){r[s]=structuredClone(o);continue}let i=La(t,o.body);if(i===void 0)return;r[s]=i}for(let[s,o]of Object.entries(n.inc??{})){let i=r[s]===void 0?0:r[s];if(typeof i!==\"number\")return;r[s]=i+o}for(let s of n.unset??[])delete r[s];return r}function Ls(e,t,n,r){return e.find((s)=>s.method===t&&Pe(s.pattern,n.pathname)!==null&&n.origin===(s.origin??r))}var Hs=\"spool-writes\",nt=\"queue\",qa=new TextEncoder;function Tt(e){return new Promise((t,n)=>{e.onsuccess=()=>t(e.result),e.onerror=()=>n(e.error)})}function Us(e){return new Promise((t,n)=>{e.oncomplete=()=>t(),e.onerror=()=>n(e.error),e.onabort=()=>n(e.error)})}var Vs=(e)=>IDBKeyRange.bound([e],[e,[]]);function zs(e,t,n){let r,s=()=>r??=new Promise((u,l)=>{let f=e.open(Hs,1);f.onupgradeneeded=()=>{f.result.createObjectStore(nt,{keyPath:[\"partition\",\"name\",\"key\"]})},f.onsuccess=()=>{let y=f.result;y.onversionchange=()=>{y.close(),r=void 0},u(y)},f.onerror=()=>l(f.error)}),o=(u,l)=>`${t}\\x00write\\x00${u}\\x00${l}`;async function i(u,l){let y=(await s()).transaction(nt,u),m=Us(y),w=await l(y.objectStore(nt));return await m,w}let a=async(u)=>u&&await tt(n,t,o(u.name,u.key),u);return{get:async(u,l)=>a(await i(\"readonly\",(f)=>Tt(f.get([t,u,l])))),put:async(u)=>{let l=await n.get(t,\"persistent\",!0);if(!l)throw Error(\"no key\");let f=await Rt(l,o(u.name,u.key),u,\"persistent\");await i(\"readwrite\",async(y)=>{await Tt(y.put({partition:t,name:u.name,key:u.key,...f}))})},delete:(u,l)=>i(\"readwrite\",async(f)=>void await Tt(f.delete([t,u,l]))),all:async()=>{let u=await i(\"readonly\",(f)=>Tt(f.getAll(Vs(t)))),l=[];for(let f of u){let y=await a(f);if(y)l.push(y);else await i(\"readwrite\",async(m)=>void await Tt(m.delete([t,f.name,f.key])))}return l}}}async function Gs(e,t){let n=await new Promise((r)=>{let s=e.open(Hs);s.onupgradeneeded=()=>{try{s.transaction?.abort()}catch{}},s.onsuccess=()=>r(s.result),s.onerror=()=>r(null),s.onblocked=()=>r(null)});if(!n)return;try{if(!n.objectStoreNames.contains(nt))return;let r=n.transaction(nt,\"readwrite\"),s=Us(r);r.objectStore(nt).delete(Vs(t)),await s}catch{}finally{n.close()}}var Fa={set:(e,t)=>setTimeout(e,t),clear:(e)=>clearTimeout(e)},fe=(e,t)=>({ok:!1,code:e,message:t}),Ha=new Set(Object.keys(Ms)),Ua=(e)=>{let t=e?.code;return typeof t===\"string\"&&Ha.has(t)?t:void 0};function Va(e){let t=e?.conflict;if(!t||!un(t.version))return;return\"value\"in t?{version:t.version,value:t.value}:{version:t.version}}class Je{#e;#t;#r=Promise.resolve();#o=null;#s=!1;#n;constructor(e){this.#e=e,this.#t=e.timers??Fa}kill(){this.#s=!0,this.#c()}#i(e,t){let n=this.#e.classes().find((r)=>r.name===e)?.maxDelayMs;return n===void 0?void 0:t+n}#a(e){if(this.#s||this.#n!==void 0&&this.#n.at<=e)return;this.#c();let t=this.#t.set(()=>this.#u(),Math.max(0,e-this.#e.now()));this.#n={at:e,handle:t}}#c(){if(this.#n!==void 0)this.#t.clear(this.#n.handle);this.#n=void 0}#u(){return this.#n=void 0,this.flushDue().catch(()=>({queued:0,flushed:0,conflicted:0}))}async#p(e=-1/0){let t=(await this.#e.store.all()).filter((n)=>n.state!==\"conflicted\"&&n.due!==void 0).map((n)=>n.due).filter((n)=>n>e);return t.length>0?Math.min(...t):void 0}async#f(){let e=await this.#p(this.#e.now());if(this.#c(),e!==void 0)this.#a(e)}async flushDue(){let e=await this.#l(async()=>this.#s?void 0:this.#p());if(e===void 0)return{queued:0,flushed:0,conflicted:0};if(e>this.#e.now())return this.#a(e),{queued:0,flushed:0,conflicted:0};return this.flush()}#l(e){let t=this.#r.then(e,e);return this.#r=t.catch(()=>{return}),t}write(e,t,n,r){if(this.#s)return Promise.resolve(fe(\"no-partition\",\"the queue was wiped\"));let s=this.#e.classes().find((i)=>i.name===e);if(!s)return Promise.resolve(fe(\"unknown-write\",`no write class \"${e}\"`));if(!$s(t))return Promise.resolve(fe(\"bad-key\",\"the key is malformed\"));if(r===void 0||r===null)return Promise.resolve(fe(\"missing-version\",\"say which version the edit started from\"));if(!un(r))return Promise.resolve(fe(\"bad-version\",\"the version is malformed\"));let o;try{let i=JSON.stringify({value:n});if(n===void 0)throw Error(\"no value\");o=qa.encode(i).length}catch{return Promise.resolve(fe(\"bad-body\",\"the value is not JSON\"))}if(o>s.maxBytes)return Promise.resolve(fe(\"too-large\",`the value is over ${s.maxBytes} bytes`));return this.#l(async()=>{if(this.#s)return fe(\"no-partition\",\"the queue was wiped\");let i=this.#e.now(),a=await this.#e.store.get(e,t);if(!a){if((await this.#e.store.all()).filter((E)=>E.name===e).length>=s.maxPending)return fe(\"too-many\",`${s.maxPending} keys of \"${e}\" are already queued`);let m=this.#i(e,i),w={name:e,key:t,value:n,base:r,id:ln(),state:\"pending\",queuedAt:i,updatedAt:i,bytes:o,edits:1,attempts:0,...m===void 0?{}:{due:m}};if(await this.#e.store.put(w),m!==void 0)this.#a(m);return{ok:!0,state:w.state,edits:1}}let u=a.state===\"flushing\"||a.attempts>0,l=a.due??(a.state===\"conflicted\"?void 0:this.#i(e,i)),f={...a,updatedAt:i,edits:a.edits+1,...l===void 0?{}:{due:l},...u&&a.state!==\"conflicted\"?{next:{value:n,bytes:o}}:{value:n,bytes:o}};if(await this.#e.store.put(f),l!==void 0)this.#a(l);return{ok:!0,state:f.state,edits:f.edits}})}list(){return this.#l(async()=>{if(this.#s)return[];return(await this.#e.store.all()).sort((t,n)=>t.queuedAt-n.queuedAt||(t.key<n.key?-1:1)).map((t)=>({name:t.name,key:t.key,state:t.state,base:t.base,queuedAt:t.queuedAt,updatedAt:t.updatedAt,bytes:t.bytes,attempts:t.attempts,...t.conflict?{conflict:t.conflict}:{},...t.refusal?{refusal:t.refusal}:{}}))})}flush(e){if(this.#o&&!e)return this.#o;let t=this.#g(e);if(!e)return this.#o=t.finally(()=>{this.#o=null}),this.#o;return t}async#g(e){let t={queued:0,flushed:0,conflicted:0};if(this.#s)return t;let n=await this.#l(async()=>this.#s?[]:(await this.#e.store.all()).filter((r)=>r.state!==\"conflicted\"));for(let r of n){if(e&&(r.name!==e.name||r.key!==e.key))continue;let s=await this.#l(async()=>{if(this.#s)return;let a=await this.#e.store.get(r.name,r.key);if(!a||a.state===\"conflicted\")return;let u={...a,state:\"flushing\"};return await this.#e.store.put(u),u});if(!s)continue;t.queued+=1;let o;try{o=await this.#e.send(s)}catch{o=void 0}if(await this.#l(()=>this.#y(s,o,t)).catch(()=>!0))break}if(t.queued>0&&!this.#s)this.#e.onFlush?.(t);if(!this.#s)await this.#l(()=>this.#f());return t}async#y(e,t,n){if(this.#s)return!0;let{store:r}=this.#e,s=this.#e.now(),o=await r.get(e.name,e.key);if(!o)return!1;let i=async(f)=>{let{due:y,...m}=o;return await r.put({...m,state:\"pending\",updatedAt:s,attempts:o.attempts+(f?1:0)}),!0};if(!t)return i(!0);let{status:a,body:u}=t;if(a===200){let f=u?.version;if(!un(f))return i(!0);if(n.flushed+=1,!o.next)return await r.delete(o.name,o.key),!1;let{value:y,bytes:m}=o.next,w=this.#i(o.name,s);return await r.put({name:o.name,key:o.key,value:y,bytes:m,base:f,id:ln(),state:\"pending\",queuedAt:o.queuedAt,updatedAt:s,edits:1,attempts:0,...w===void 0?{}:{due:w}}),!1}let l=Ua(u);if(a===412){let f=Va(u);if(f)return n.conflicted+=1,await r.put(this.#d(o,s,{conflict:f})),!1;return n.conflicted+=1,await r.put(this.#d(o,s,{refusal:\"unavailable\"})),!1}if(a===401||a===429||l===\"writes-off\"||l===\"sign-in\")return i(!1);if(a>=500||a===408)return i(!0);return n.conflicted+=1,await r.put(this.#d(o,s,{refusal:l??\"unavailable\"})),!1}#d(e,t,n){let{next:r,conflict:s,refusal:o,due:i,...a}=e;return{...a,...r?{value:r.value,bytes:r.bytes}:{},state:\"conflicted\",updatedAt:t,...n}}async resolve(e,t,n){if(this.#s)return fe(\"no-partition\",\"the queue was wiped\");if(n!==\"local\"&&n!==\"server\")return fe(\"bad-body\",'resolve with \"local\" or \"server\"');let r=await this.#l(async()=>{if(this.#s)return fe(\"no-partition\",\"the queue was wiped\");let s=await this.#e.store.get(e,t);if(!s)return fe(\"no-record\",\"nothing is queued for that key\");if(s.state!==\"conflicted\")return fe(\"not-conflicted\",\"that record has no conflict to resolve\");if(n===\"server\")return await this.#e.store.delete(e,t),{ok:!0,...s.conflict?{server:s.conflict}:{}};let{conflict:o,refusal:i,...a}=s;return await this.#e.store.put({...a,base:o?.version??s.base,id:ln(),state:\"pending\",updatedAt:this.#e.now(),edits:1,attempts:0}),{ok:!0}});if(!r.ok||n===\"server\")return r;return{ok:!0,flush:await this.flush({name:e,key:t})}}}var qs=(e)=>typeof e===\"object\"&&e!==null&&!Array.isArray(e);function sr(e,t,n,r){let s=[[t,n,r??null],...Ts(e,t,n,r)];return{puts:s.flatMap(([o,i,a])=>a===null?[]:[[o,i,a]]),deletes:s.flatMap(([o,i,a])=>a===null?[[o,i]]:[])}}async function Fs(e,t,{write:n,url:r,body:s,routes:o}){let i=Es(o),a=Pe(n.pattern,r.pathname)?.[n.key],{dataset:u}=n;if(n.apply===\"invalidate\")return;if(n.apply===\"delete\"){if(a!==void 0)await t.applyPredicted(sr(i,u,a));return}if(n.apply===\"response\"){let y=await e.clone().json().catch(()=>{return});if(!qs(y))return;let m=y[n.key];if(typeof m!==\"string\"&&typeof m!==\"number\")return;let w=String(m);if(a!==void 0&&a!==w)return;await t.applyPredicted(sr(i,u,w,y));return}if(a===void 0)return;let l=await t.getRow(u,a);if(!l)return;let f=n.apply===\"merge\"?qs(s)?{...l,...s}:void 0:Ws(l,s,n.apply);if(f)await t.applyPredicted(sr(i,u,a,f))}async function Js(e,t,n,r,s){if(!e.url||new URL(e.url).origin!==r)return;let o=await t.head();if(!o)return;let i=e.headers.get(K.delta),a=i===null?void 0:JSON.parse(i);if(a?.from===o.version)try{await t.applyDelta(a);return}catch{}let u=e.headers.get(K.vector),l=a?.to??(u===null?void 0:Number(u));if(l===void 0){if(s)await Fs(e,t,s);return}if(!Number.isSafeInteger(l)||l<=o.version)return;let f=e.headers.get(cn.digest);if(a===void 0&&s&&f!==null){await Fs(e,t,s);try{await t.confirmPredicted(l,f);return}catch{await t.dropPredicted()}}await t.applyDelta(await n(o.version,l))}var za=\"spool-keys\",ir=\"keys\",ar=\"meta\",or=\"partition\";function rt(e){return new Promise((t,n)=>{e.onsuccess=()=>t(e.result),e.onerror=()=>n(e.error)})}function Ks(e){return new Promise((t,n)=>{let r=e.open(za,1);r.onupgradeneeded=()=>{r.result.createObjectStore(ir),r.result.createObjectStore(ar)},r.onsuccess=()=>{let s=r.result;s.onversionchange=()=>s.close(),t(s)},r.onerror=()=>n(r.error)})}function Ga(e=indexedDB){let t=new Map,n=Promise.resolve(),r=(i)=>{let a=n.then(i,i);return n=a.catch(()=>{return}),a},s=()=>crypto.subtle.generateKey({name:\"AES-GCM\",length:256},!1,[\"encrypt\",\"decrypt\"]);async function o(i,a){let u=await Ks(e);try{let l=u.transaction(ir,i),f=new Promise((m,w)=>{l.oncomplete=()=>m(),l.onerror=()=>w(l.error),l.onabort=()=>w(l.error)}),y=await a(l.objectStore(ir));return await f,y}finally{u.close()}}return{get:(i,a,u)=>r(async()=>{if(a===\"session\"){let y=t.get(i);if(!y&&u)y=await s(),t.set(i,y);return y}let l=await o(\"readonly\",(y)=>rt(y.get(i)));if(l||!u)return l;let f=await s();return await o(\"readwrite\",async(y)=>void await rt(y.put(f,i))),f}),shred:(i)=>r(async()=>{t.delete(i),await o(\"readwrite\",async(a)=>void await rt(a.delete(i)))})}}function Qs(e=indexedDB,t=Ga(e)){let n=new Map,r=(o)=>`spool-p-${o}`;async function s(o,i){let a=await Ks(e);try{let u=a.transaction(ar,o),l=new Promise((y,m)=>{u.oncomplete=()=>y(),u.onerror=()=>m(u.error),u.onabort=()=>m(u.error)}),f=await i(u.objectStore(ar));return await l,f}finally{a.close()}}return{current:async()=>await s(\"readonly\",(o)=>rt(o.get(or)))??null,setCurrent:(o)=>s(\"readwrite\",async(i)=>{if(o===null)await rt(i.delete(or));else await rt(i.put(o,or))}),open(o,i,a,u=!1){let l=n.get(o);if(l)return l.sealed;let f=Xt(e,r(o)),y=hs(f,{partition:o,vault:t,retentionOf:i,shared:a,...u?{datasets:ks(Ss(e,o),{partition:o,vault:t,retention:a})}:{}});return n.set(o,{sealed:y,destroy:f.destroy}),y},openWrites:(o)=>zs(e,o,t),async destroy(o){let i=n.get(o);if(i?.sealed.kill(),n.delete(o),await t.shred(o),await Gs(e,o),await vs(e,o),i)await i.destroy();else await new Promise((a)=>{let u=e.deleteDatabase(r(o));u.onsuccess=()=>a(),u.onerror=()=>a()})}}}var cr=\"/.spool/dropped\",Xs=\"/.spool/\",Ys=65536;var Zs=8;var eo=3600000,yl=48*eo,ml=72*eo;function to(e,t){if(!e||e.length===0)return;let n;try{n=new URL(t)}catch{return}return e.find((r)=>{let s=new URL(r.match);return n.origin===s.origin&&n.pathname.startsWith(s.pathname)})}function Ja(e,t,n){if(e===\"age-ms\")return String(Math.max(0,Math.round(n-t)));if(e===\"epoch-ms\")return String(Math.round(t));if(e===\"epoch-s\")return String(Math.floor(t/1000));return new Date(t).toISOString().slice(0,19).replace(\"T\",\" \")}function no(e,t,n,r){let s=new URLSearchParams(e);s.set(t.param,Ja(t.kind,n,r));let o=s.toString();return o===\"\"?\"\":`?${o}`}var ro=\"/.spool/bundle/delta/\",Ke={sync:\"/.spool/sync\",artifact:\"/.spool/artifact\",dataset:\"/.spool/dataset\",beacon:\"/.spool/beacon\",write:\"/.spool/write\",worker:\"/spool-sw.js\"},so=\"/.spool/live\";function oo(e){return`/.spool/${encodeURIComponent(e)}/client.js`}var bl=new RegExp(`[<>&${String.fromCharCode(8232,8233)}]`,\"g\");function io(e){let t=e.lastIndexOf('<script type=\"application/spool+json\" data-spool-artifact>');if(t<0)return null;let n=t+58,r=e.indexOf(\"</script>\",n);return r<0?null:e.slice(n,r)}function ao(e){let t=\"\",n=0;for(;;){let r=e.indexOf('<script type=\"application/spool+json\" data-spool-artifact>',n),s=r<0?-1:e.indexOf(\"</script>\",r+58);if(s<0)return t+e.slice(n);t+=e.slice(n,r),n=s+9}}var co=1,uo=256;function pe(e){throw new L(\"bad-manifest\",e)}function ur(e){return typeof e===\"object\"&&e!==null&&!Array.isArray(e)}function Ka(e,t){let n=`routes[${t}]`;if(!ur(e))return pe(`${n} must be an object`);let{pattern:r,strategy:s,version:o,freshness:i,offline:a,sync:u}=e;if(typeof r!==\"string\")return pe(`${n}.pattern must be a string`);try{nn(r)}catch(f){return pe(`${n}: ${f instanceof Error?f.message:\"bad pattern\"}`)}if(s!==\"static\")return pe(`${r}: strategy must be \"static\"`);if(typeof o!==\"string\"||o===\"\"||o.length>uo)return pe(`${r}: version must be a string of 1 to ${uo} characters`);let l={pattern:r,strategy:s,version:o};if(i!==void 0){if(!ur(i))return pe(`${r}: freshness must be an object`);let{maxStale:f,mode:y}=i;if(f!==void 0){if(typeof f!==\"number\"||!Number.isFinite(f)||f<=0)return pe(`${r}: freshness.maxStale must be a positive number of seconds`)}if(y!==void 0&&y!==\"hard\"&&y!==\"soft\")return pe(`${r}: freshness.mode must be \"hard\" or \"soft\"`);l.freshness={...f===void 0?{}:{maxStale:f},...y===void 0?{}:{mode:y}}}if(a!==void 0){if(a!==\"serve\"&&a!==\"refuse\")return pe(`${r}: offline must be \"serve\" or \"refuse\"`);l.offline=a}if(u!==void 0){if(u!==\"background\"&&u!==\"deferred\")return pe(`${r}: sync must be \"background\" or \"deferred\"`);l.sync=u}return l}function lr(e){if(!ur(e))return pe(\"manifest must be an object\");if(e.schema!==co)return pe(\"unsupported manifest schema\");let{routes:t}=e;if(!Array.isArray(t))return pe(\"routes must be a list\");let n=t.map(Ka),r=new Set;for(let s of n){if(r.has(s.pattern))return pe(`${s.pattern}: declared twice`);r.add(s.pattern)}return{schema:co,routes:n}}function dr(e){return e.routes.map((t)=>({pattern:t.pattern,strategy:\"static\",scope:\"public\",freshness:{...Is.public,...t.freshness},persist:!0,offline:t.offline??\"serve\",sync:t.sync??\"background\",version:t.version}))}var fr={cold:\"network\",principal:\"network\",fresh:\"local\",catalogue:\"local\",\"soft-deferred\":\"local\",\"soft-sync\":\"local-revalidate\",\"hard-sync\":\"local-revalidate\",\"offline-stale\":\"local-revalidate\",invalidated:\"fallback\",\"stale-after-sync\":\"fallback\",\"hard-refused\":\"fallback\",refused:\"fallback\"};var lo=\"external\",pr=\"/.spool/view\",fo=\"/.spool/loads\";function po(e,t,n,r){return{path:\"/.spool/loads\",body:JSON.stringify(r&&Object.keys(r).length>0?{view:e,count:t,origins:r}:{view:e,count:t}),contentType:\"application/json\",at:n}}function go(e,t){return{path:\"/.spool/view\",body:JSON.stringify(e),contentType:\"application/json\",at:t}}function yo(e){if(/\\b(?:CriOS|FxiOS|EdgiOS|OPiOS)\\//.test(e))return\"webkit\";if(/\\bFirefox\\//.test(e))return\"firefox\";if(/(?:Chrome|Chromium)\\//.test(e))return\"chromium\";if(/\\bSafari\\//.test(e))return\"webkit\";return\"other\"}var mo=86400000,Qa=3600000,Xa=20,Ya=3600000,Za=86400000,ec=256,ho=100,bo=3000,wo=\"same-origin\";function tc(e,t){let n,r=new Promise((s,o)=>{n=setTimeout(()=>o(Error(\"timed out\")),t)});return Promise.race([e,r]).finally(()=>clearTimeout(n))}var nc=new TextEncoder,dn=(e)=>e.path.startsWith(Xs)||e.deliver===\"sink\";class gr{#e;#t=null;#r;dropped=new Map;constructor(e){this.#e=e}async record(e){await this.#e.storage.addBeacon(e)}async enqueue(e,t){let n=e.method===\"GET\",r=n?\"\":e.headers.get(\"content-type\")??\"text/plain\";if(/octet-stream|multipart|image\\//i.test(r))return!1;let s=n?\"\":await e.clone().text();if(nc.encode(s).length>Ys)return!1;let o=new URL(e.url),i=this.#e.now(),a={path:o.pathname,body:s,contentType:r,at:i};if(o.search!==\"\")a.search=o.search;if(n)a.method=\"GET\";if(t){if(a.origin=o.origin,a.vendor=t.vendor,a.until=i+t.maxAgeMs,t.delivery===\"sink\")a.deliver=\"sink\"}return await this.#e.storage.addBeacon(a),!0}flush(){return this.#t??=this.#a().finally(()=>{this.#t=null}),this.#t}async flushAtMoment(){await this.#n();let e=await this.#e.storage.readBeacons();if(e.length===0)return!1;let t=(u)=>u===pr||u===fo||u===cr,n=e.some((u)=>!t(u.event.path)),r=e.filter((u)=>u.event.path===pr).length,s=(await this.#e.want?.()??[]).length>0,o=await this.#c(await this.#e.catalogue?.())!==void 0,i=Math.min(...e.map((u)=>u.event.at)),a=this.#e.now()-i>=Ya;if(n||s||o||a||r>=Xa)return this.flush();return!1}async flushIfDue(){let e=this.#e.now(),t=await this.#o(),n=t.checkedAt>e?-1/0:t.checkedAt;if(e-n<Qa)return!1;t.checkedAt=e,await this.#s(t),await this.#n();let r=await this.#e.storage.readBeacons(),s=Math.min(...r.map((i)=>i.event.at));if(r.length===0||e-s<mo)return!1;let o=t.lastStandalone>e?-1/0:t.lastStandalone;if(e-o<mo)return!1;return t.lastStandalone=e,await this.#s(t),this.flush()}async#o(){return this.#r??=await this.#e.storage.getFlush()??{lastStandalone:-1/0,checkedAt:-1/0},this.#r}async#s(e){await this.#e.storage.setFlush(e)}async#n(){let{storage:e,now:t}=this.#e,n=t(),s=(await e.readBeacons()).filter((o)=>o.event.until!==void 0&&o.event.until<n);if(s.length===0)return;await e.removeBeacons(s.map((o)=>o.key)),await this.#i(s.map(({event:o})=>o.vendor??\"unknown\"))}async#i(e){let t=new Map;for(let n of e)t.set(n,(t.get(n)??0)+1);for(let[n,r]of t)this.dropped.set(n,(this.dropped.get(n)??0)+r),await this.#e.storage.addBeacon({path:cr,body:JSON.stringify({vendor:n,count:r}),contentType:\"application/json\",at:this.#e.now()})}async sendSameOrigin(e){if(this.#t)await this.#t.catch(()=>!1);let{storage:t,replay:n}=this.#e,r=(await t.readBeacons()).filter(({event:i})=>!dn(i)&&i.origin===void 0);if(r.length===0)return;await t.removeBeacons(r.map((i)=>i.key));let s=!1,o=[];for(let{event:i}of r){let a=!1;if(!s)try{a=await tc(n(i),e)}catch{s=!0}if(!a)o.push(wo)}await this.#i(o)}async dropSameOrigin(){if(this.#t)await this.#t.catch(()=>!1);let e=(await this.#e.storage.readBeacons()).filter(({event:t})=>!dn(t)&&t.origin===void 0);if(e.length===0)return;await this.#e.storage.removeBeacons(e.map((t)=>t.key)),await this.#i(e.map(()=>wo))}async#a(){let{storage:e,send:t,replay:n,want:r,catalogue:s}=this.#e;await this.#n();let o=await e.readBeacons();if(o.length===0)return!1;let i=!0;for(let y of o.filter((m)=>!dn(m.event))){let m;try{m=await n(y.event)}catch{m=!1}if(m)await e.removeBeacons([y.key]);else i=!1}let a=o.filter((y)=>dn(y.event)),u=await r?.()??[],l=await this.#c(await s?.());if(a.length===0&&u.length===0)return i;let f=!0;for(let y=0;y<Math.max(a.length,1);y+=ho){let m=a.slice(y,y+ho),w={protocol:F,events:m.map(({event:{until:E,...O}})=>O)};if(u.length>0)w.want=u;if(l)w.catalogue=l;u=[],l=void 0;try{f=await t(w)}catch{f=!1}if(!f)return!1;if(await e.removeBeacons(m.map((E)=>E.key)),w.catalogue)await this.#u(w.catalogue.path)}return i&&f}async#c(e){if(!e)return;let t=(await this.#o()).catalogue?.[e.path],n=this.#e.now();return t===void 0||t>n||n-t>=Za?e:void 0}async#u(e){let t=await this.#o(),n={...t.catalogue};delete n[e],n[e]=this.#e.now();let r=Object.keys(n);for(let s of r.slice(0,r.length-ec))delete n[s];t.catalogue=n,await this.#s(t)}}function rc(e){try{return new URL(e).origin}catch{return null}}var sc=Uint8Array.from(atob(\"R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7\"),(e)=>e.charCodeAt(0));function Ro(e){let t=new Headers;if(e.mode===\"cors\"){let n=e.headers.get(\"origin\")??rc(e.referrer);if(e.credentials===\"include\"&&n)t.set(\"access-control-allow-origin\",n),t.set(\"access-control-allow-credentials\",\"true\");else t.set(\"access-control-allow-origin\",\"*\")}if(e.method===\"GET\")return t.set(\"content-type\",\"image/gif\"),t.set(\"cache-control\",\"no-store\"),new Response(sc,{status:200,headers:t});return new Response(null,{status:204,headers:t})}function he(e){throw new L(\"bad-dataset\",e)}function vo(e){let t=new URLSearchParams({name:e.name});if(e.since!==void 0)t.set(\"since\",String(e.since));if(e.schema!==void 0)t.set(\"schema\",e.schema);if(e.after!==void 0)t.set(\"after\",e.after);if(e.limit!==void 0)t.set(\"limit\",String(e.limit));return t.toString()}var fn=(e)=>typeof e===\"object\"&&e!==null&&!Array.isArray(e),So=(e)=>typeof e===\"number\"&&Number.isSafeInteger(e)&&e>=0;function ko(e){if(!fn(e))return he(\"dataset response must be an object\");if(e.protocol!==F)return he(\"unsupported protocol version\");let{name:t,schema:n,cursor:r,reset:s,puts:o,deletes:i,after:a,next:u,proof:l}=e;if(typeof t!==\"string\"||typeof n!==\"string\")return he(\"name and schema must be strings\");if(!So(r))return he(\"cursor must be a non-negative integer\");if(typeof s!==\"boolean\")return he(\"reset must be a boolean\");if(!Array.isArray(o))return he(\"puts must be a list\");let f=o.map((w)=>{if(!fn(w)||typeof w.key!==\"string\"||!fn(w.row))return he(\"a put is { key, row }\");return{key:w.key,row:w.row}});if(!Array.isArray(i))return he(\"deletes must be a list\");let y=i.map((w)=>{if(!fn(w)||typeof w.key!==\"string\"||!So(w.cursor))return he(\"a delete is { key, cursor }\");return{key:w.key,cursor:w.cursor}}),m={protocol:F,name:t,schema:n,cursor:r,reset:s,puts:f,deletes:y};if(a!==void 0){if(typeof a!==\"string\")return he(\"after must be a string\");m.after=a}if(u!==void 0){if(typeof u!==\"string\")return he(\"next must be a string\");m.next=u}if(l!==void 0){if(!Hn(l))return he(\"proof must be a set proof\");m.proof={kind:\"set\",count:l.count,digest:l.digest}}if(m.next===void 0&&m.proof===void 0)return he(\"a response without next carries a proof\");return m}async function Po(e,t,n,r={}){let s=r.hash??Oe,o=t.reset&&t.after===void 0,i=new Map(o?[]:e),a=r.hashes?new Map(o?[]:r.hashes):void 0,u=o?De:n??(await Fn(e)).digest,l=async(y)=>{let m=i.get(y);if(m===void 0)return;u=Kt(u,a?.get(y)??await s(y,m)),i.delete(y),a?.delete(y)};for(let{key:y}of t.deletes)await l(y);for(let{key:y,row:m}of t.puts){await l(y),i.set(y,m);let w=await s(y,m);a?.set(y,w),u=je(u,w)}let f=t.proof;return{rows:i,digest:u,matches:f===void 0?null:f.count===i.size&&f.digest===u,...a?{hashes:a}:{}}}function xo(e){return(t)=>{if(t.status===401)return\"ended\";if(t.status===403)return\"revoked\";if(t.ok&&t.headers.get(K.partition)!==e)return\"partition\";return\"ok\"}}var oc=1000;class le extends Error{reason;by;constructor(e,t){super(e);this.reason=e;this.by=t}}async function Ao(e,t){let{store:n,origin:r}=e,s=e.epoch(),o=0,i=async(l)=>{o+=1;let f=await e.fetch(`${r}${Ke.dataset}?${vo(l)}`,{cache:\"no-store\",credentials:\"same-origin\"}),y=e.guard?.(f)??\"ok\";if(y!==\"ok\")throw new le(y);if(f.status===409)throw new le(\"declined\",f.headers.get(K.provisionReason));if(f.status===400||f.status===404)throw new le(\"unavailable\");if(!f.ok)throw TypeError(`dataset answered ${f.status}`);let m=ko(await f.json());if(m.name!==t)throw new le(\"bad-response\");return m},a=async(l,f,y)=>{try{if(e.epoch()!==s)throw new le(\"epoch\");if(!await n.commit(l,f,s))throw new le(\"epoch\")}catch(m){if(m instanceof le)throw m;throw new le(\"storage\")}return{name:t,requests:o,status:y,cursor:f.cursor,rows:l.rows.size}},u=async(l,f,y)=>{let m=l??await i({name:t}),{cursor:w,schema:E}=m,O=await e.budget(),M=n.stage(t),z,Q;for(let re=1;;re+=1){if(e.epoch()!==s)throw new le(\"epoch\");if(z=await M.add(m),O!==void 0&&M.bytes>O)throw new le(\"budget\");if(m.next===void 0)break;if(re>=oc||Q!==void 0&&m.next<=Q)throw new le(\"bad-response\");Q=m.next,m=await i({name:t,after:Q})}if(z===!0)return a(M,{cursor:w,schema:E},f);let te=await i({name:t,since:w,schema:E});if(!te.reset&&await M.add(te)===!0)return a(M,{cursor:te.cursor,schema:E},f);if(y)return u(void 0,\"reseeded\",!1);throw new le(\"proof\")};try{let l=await n.get(t);if(!l)return await u(void 0,\"seeded\",!0);let{cursor:f,schema:y,digest:m,count:w}=l.meta,E=await i({name:t,since:f,schema:y});if(E.reset)return await u(E,\"reseeded\",!0);if(E.cursor<f)return{name:t,requests:o,status:\"current\",cursor:f,rows:w};let O=E.proof;if(E.cursor===f){if(O&&(O.count!==w||O.digest!==m))return await n.drop(t),await u(void 0,\"reseeded\",!1);if(!await n.touch(t,s))throw new le(\"epoch\");return{name:t,requests:o,status:\"current\",cursor:f,rows:w}}let M=n.stage(t,l);if(await M.add(E)===!0)return await a(M,{cursor:E.cursor,schema:y},\"patched\");return await n.drop(t),await u(void 0,\"reseeded\",!1)}catch(l){if(l instanceof le){if(l.reason===\"revoked\"&&e.epoch()===s)await n.drop(t).catch(()=>{return});return{name:t,requests:o,status:\"refused\",reason:l.reason,by:l.by}}if(l instanceof L)return{name:t,requests:o,status:\"refused\",reason:\"bad-response\"};return{name:t,requests:o,status:\"offline\"}}}async function yr(e,t,n,r){let s=t.family;if(s===void 0)return;if(![\"template\",\"projection\",\"data\"].includes(t.strategy))return;let o=Pe(t.pattern,n),i=o?.[s.key];if(o===null||i===void 0)return;let a=await e(i);if(a===void 0)return;return{artifact:{protocol:F,id:n,scope:t.scope,strategy:t.strategy,deps:[],vector:0,body:{data:t.strategy===\"data\"?a:{params:o,row:a}}},fetchedAt:r}}function mr(e,t){return{artifact:{protocol:F,id:e,scope:\"public\",strategy:\"data\",deps:[],vector:0,body:{data:{}}},fetchedAt:t}}function Eo(e,t,n){if((n>=t?(n-t)/1000:1/0)<=e.maxStale)return\"serve\";return e.mode===\"hard\"?\"sync-first\":\"serve-then-sync\"}function To(e,t){return Math.max(e,t)}function Do(e,t){return e.deps.every((n)=>t(n)<=e.vector)}var br=128,ic=1000,ac=65536,Co=8388608,hr=1048576,Bo=-1,cc=256;var Io=new TextEncoder,Mo=new TextDecoder,wr=(e)=>new Uint8Array(Io.encode(e));function ne(e){throw new L(\"bad-bundle\",e)}var Oo=(e)=>typeof e===\"number\"&&Number.isSafeInteger(e)&&e>=0,$o=(e)=>typeof e===\"object\"&&e!==null&&!Array.isArray(e);function Rr(e){let t=new Uint8Array(e.reduce((r,s)=>r+s.length,0)),n=0;for(let r of e)t.set(r,n),n+=r.length;return t}async function _o(e){let t=new Uint8Array(await crypto.subtle.digest(\"SHA-256\",e)),n=\"\";for(let r of t)n+=String.fromCharCode(r);return btoa(n).replace(/\\+/g,\"-\").replace(/\\//g,\"_\").replace(/=+$/,\"\")}async function uc(e,t){let n=new Response(e).body?.pipeThrough(t);if(!n)ne(\"no body to transform\");return new Uint8Array(await new Response(n).arrayBuffer())}var lc=(e)=>uc(e,new CompressionStream(\"gzip\"));async function dc(e,t){let n=e.length-4;if(n>=0){let a=new DataView(e.buffer,e.byteOffset+n,4).getUint32(0,!0);if(a>hr)ne(`${t} declares ${a} bytes, over the block cap`)}let r=new Response(e).body?.pipeThrough(new DecompressionStream(\"gzip\"));if(!r)ne(\"no body to transform\");let s=r.getReader(),o=[],i=0;for(;;){let a=await s.read().catch(()=>ne(`${t} does not decode`));if(a.done)break;if(i+=a.value.byteLength,i>hr)await s.cancel().catch(()=>{return}),ne(`${t} is over the block cap`);o.push(new Uint8Array(a.value))}return new Uint8Array(await new Blob(o).arrayBuffer())}function No(e,t){return e<t?-1:e>t?1:0}function fc(e,t){let n=[...t].sort(([r],[s])=>No(r,s));for(let r=1;r<n.length;r++)if(n[r-1]?.[0]===n[r]?.[0])ne(`${e}: key ${n[r]?.[0]} repeats`);return n}function jo(e,t,n){let r=wr(JSON.stringify({table:e,ordinal:t,bytes:n.length})),s=new Uint8Array(4);return new DataView(s.buffer).setUint32(0,r.length),Rr([s,r,n])}async function Sr(e){let t=De;for(let n of Object.keys(e))for(let[r,s]of e[n]??[])t=je(t,await Oe(JSON.stringify([n,r]),s));return t}async function Wo(e,t=br,n=Co){if(!Number.isSafeInteger(t)||t<1)ne(\"blockRows must be 1 or more\");let r=[],s=[],o=Object.keys(e.tables).filter((u)=>(e.tables[u]?.length??0)>0).sort(No);for(let[u,l]of o.entries()){let f=fc(l,e.tables[l]??[]),y=[];for(let m=0;m*t<f.length;m++){let w=f.slice(m*t,(m+1)*t),E=wr(Ge(w));if(E.length>hr)ne(`block ${l}/${m} is over the block cap`);let O=await lc(E);if(O.length>n)ne(`block ${l}/${m} is over the frame cap`);y.push(await _o(O)),r.push(jo(u,m,O))}s.push({name:l,rows:f.length,first:f[0]?.[0]??null,blocks:y})}let i={version:e.version,codec:\"gzip\",blockRows:t,digest:await Sr(e.tables),tables:s},a=jo(Bo,0,wr(Ge(i)));return{index:i,bytes:Rr([a,...r])}}async function*Lo(e,t=Co){let n=e[Symbol.asyncIterator](),r=new Uint8Array(0),s=async(i)=>{while(r.length<i){let a=await n.next();if(a.done)return!1;r=Rr([r,a.value])}return!0},o=(i)=>{let a=r.slice(0,i);return r=r.subarray(i),a};while(await s(1)){if(!await s(4))ne(\"a frame is cut short\");let i=new DataView(r.buffer,r.byteOffset,4).getUint32(0);if(i===0||i>cc)ne(\"a frame header has a bad size\");if(!await s(4+i))ne(\"a frame is cut short\");let a=JSON.parse(Mo.decode(r.subarray(4,4+i)));if(o(4+i),!$o(a)||typeof a.table!==\"number\"||!Number.isSafeInteger(a.table)||a.table<Bo||!Oo(a.ordinal)||!Oo(a.bytes))ne(\"a frame header is not { table, ordinal, bytes }\");let{table:u,ordinal:l,bytes:f}=a;if(f>t)ne(\"a frame is over the frame cap\");if(!await s(f))ne(\"a frame is cut short\");yield{table:u,ordinal:l,payload:o(f)}}}async function vr(e,t){let r=e.tables[t.table]?.blocks[t.ordinal];if(r===void 0)ne(`no block ${t.table}/${t.ordinal} in the index`);if(await _o(t.payload)!==r)ne(`block ${t.table}/${t.ordinal} does not match its hash`);let s=await dc(t.payload,`block ${t.table}/${t.ordinal}`),o;try{o=JSON.parse(Mo.decode(s))}catch{ne(`block ${t.table}/${t.ordinal} does not decode`)}if(!Array.isArray(o))ne(`block ${t.table}/${t.ordinal} is not a row list`);for(let i of o)if(!Array.isArray(i)||typeof i[0]!==\"string\"||!$o(i[1]))ne(`block ${t.table}/${t.ordinal} has a row that is not [key, row]`);return o}function qo(e){let t=0;for(let n of Object.values(e.tables))t+=n.puts.length+n.deletes.length;return t>ic||Io.encode(JSON.stringify(e)).length>ac}var pc=[\"blocks\",\"index\",\"overlay\",\"head\",\"templates\",\"predicted\"],Ae=\"active\",gc=-1,yc=/^[0-9a-f]{64}$/,mc=8388608,hc=new TextEncoder,wc=new TextDecoder;function U(e){throw new L(\"bad-sync\",e)}var kr=(e)=>typeof e===\"number\"&&Number.isSafeInteger(e)&&e>=0;function bc(e){let t;try{t=JSON.parse(wc.decode(e))}catch{U(\"the index is not JSON\")}if(typeof t!==\"object\"||t===null)U(\"the index is not an object\");let n=t;if(!kr(n.version)||n.codec!==\"gzip\"||!kr(n.blockRows)||n.blockRows<1||typeof n.digest!==\"string\"||!yc.test(n.digest)||!Array.isArray(n.tables))U(\"the index has a bad version, codec, block size or digest\");let r=new Set;for(let s of n.tables){if(typeof s.name!==\"string\"||r.has(s.name)||!kr(s.rows)||s.rows<1||typeof s.first!==\"string\"||!Array.isArray(s.blocks)||s.blocks.length!==Math.ceil(s.rows/n.blockRows)||!s.blocks.every((o)=>typeof o===\"string\"))U(\"an index table does not match its rows and blocks\");r.add(s.name)}return n}function Rc(e,t){let n=0,r=e.first.length-1,s=-1;while(n<=r){let o=n+r>>1;if((e.first[o]??\"\")<=t)s=o,n=o+1;else r=o-1}return s>=0&&t<=(e.last[s]??\"\")?s:-1}function Fo(e,t){let n=0,r=e.length-1;while(n<=r){let s=n+r>>1,o=e[s];if(o?.[0]===t)return o[1];if((o?.[0]??\"\")<t)n=s+1;else r=s-1}return}async function Sc(e){let t=new Uint8Array(await crypto.subtle.digest(\"SHA-256\",e)),n=\"\";for(let r of t)n+=String.fromCharCode(r);return btoa(n).replace(/\\+/g,\"-\").replace(/\\//g,\"_\").replace(/=+$/,\"\")}async function vc(e){let t=new Response(e).body?.pipeThrough(new CompressionStream(\"gzip\"));if(!t)U(\"no body to compress\");return new Uint8Array(await new Response(t).arrayBuffer())}async function*kc(e){yield e}function pn(e){let t=new Map;for(let[n,r,s]of e){let o=t.get(n)??[];o.push([r,s]),t.set(n,o)}return t}function Pc(e,t){let n=new Map(e);for(let[r,s]of t)n.set(r,s);return[...n].sort(([r],[s])=>r<s?-1:1)}function Ho(e){let t={};for(let[n,r]of e)t[n]={puts:r.flatMap(([s,o])=>o===null?[]:[[s,o]]),deletes:r.flatMap(([s,o])=>o===null?[s]:[])};return t}async function xc(){return globalThis.navigator?.storage?.estimate()}function Uo(e=indexedDB,t={}){let n=t.name??\"spool-bundle\",r=t.estimate??xc,s={blockReads:0,blockInflates:0,overlayReads:0},o=new Map,i,a=Promise.resolve(),u=()=>i??=new Promise((h,S)=>{let x=e.open(n,2);x.onupgradeneeded=()=>{for(let P of pc)if(!x.result.objectStoreNames.contains(P))x.result.createObjectStore(P)},x.onsuccess=()=>{let P=x.result;P.onversionchange=()=>{P.close(),i=void 0},h(P)},x.onerror=()=>S(x.error)});async function l(h,S,x){let v=(await u()).transaction(h,S),T=bt(v);T.catch(()=>{return});try{let A=await x(v);return await T,A}catch(A){try{v.abort()}catch{}throw A}}let f=(h)=>{let S=a.then(h);return a=S.catch(()=>{return}),S},y=()=>l([\"head\",\"predicted\"],\"readonly\",async(h)=>{let S=await B(h.objectStore(\"head\").get(Ae));if(!S)return;return{...S,unconfirmed:await B(h.objectStore(\"predicted\").count())}}),m=(h,S)=>l([\"index\"],\"readonly\",(x)=>B(x.objectStore(\"index\").get([h,S])));async function w(h,S,x=\"overlay\"){let P=h.objectStore(x),[v,T]=await Promise.all([B(P.getAllKeys(S)),B(P.getAll(S))]);if(x===\"overlay\")s.overlayReads+=v.length;return v.map((A,_)=>{let[q,V]=A;return[q,V,T[_]]})}function E(h,S,x,P,v){return s.blockInflates++,vr({version:h.version,codec:\"gzip\",blockRows:h.blockRows,digest:h.digest,tables:[{name:S,rows:x.rows,first:x.first[0]??null,blocks:x.hashes}]},{table:0,ordinal:P,payload:v})}async function O(h,S,x,P){let v=await l([\"head\",\"blocks\"],\"readonly\",async(T)=>{if((await B(T.objectStore(\"head\").get(Ae)))?.generation!==h.generation)U(\"the pack changed during a read\");return s.blockReads++,B(T.objectStore(\"blocks\").get([h.generation,S,P]))});if(!v)U(`block ${S}/${P} is missing`);return E(h,S,x,P,v)}async function*M(h,S,x,P){let v=S?.hashes.length??0,T=0;for(let A=0;A<=v;A++){let _=S&&A<v,q=_?await O(h,x,S,A):[],V=_?S.last[A]:void 0,Y=0;for(;;){let se=P[T],ge=q[Y];if(se&&(V===void 0||se[0]<=V)&&(!ge||se[0]<=ge[0])){if(T++,ge&&ge[0]===se[0])Y++;if(se[1]!==null)yield[se[0],se[1]]}else if(ge)Y++,yield ge;else break}}}async function z(h,S,x){return l([\"head\",\"index\",\"overlay\",\"predicted\",\"blocks\"],\"readonly\",async(P)=>{let v=await B(P.objectStore(\"head\").get(Ae));if(!v)return;if(x){let se=await B(P.objectStore(\"predicted\").get([h,S]));if(se!==void 0)return se??void 0}s.overlayReads++;let T=await B(P.objectStore(\"overlay\").get([h,S]));if(T!==void 0)return T??void 0;if(!v.tables.includes(h))return;let A=await B(P.objectStore(\"index\").get([v.generation,h])),_=A?Rc(A,S):-1;if(!A||_<0)return;let q=o.get(h);if(q?.generation===v.generation&&q.ordinal===_)return Fo(q.rows,S);let V=await B(P.objectStore(\"blocks\").get([v.generation,h,_]));if(s.blockReads++,!V)U(`block ${h}/${_} is missing`);let Y=await E(v,h,A,_,V);return o.set(h,{generation:v.generation,ordinal:_,rows:Y}),Fo(Y,S)})}let Q=(h,S)=>z(h,S,!0);async function te(h){let S=await l([\"head\",\"index\",\"overlay\",\"predicted\"],\"readonly\",async(P)=>{let v=await B(P.objectStore(\"head\").get(Ae));if(!v)return;let T=v.tables.includes(h)?await B(P.objectStore(\"index\").get([v.generation,h])):void 0,A=IDBKeyRange.bound([h],[h,[]]),_=await w(P,A),q=await w(P,A,\"predicted\"),V=Pc(pn(_).get(h)??[],pn(q).get(h)??[]);return{head:v,record:T,changes:V}});if(!S)return[];let x=[];for await(let P of M(S.head,S.record,h,S.changes))x.push(P);return x}function re(h){return l([\"blocks\",\"index\"],\"readwrite\",(S)=>{let x=IDBKeyRange.lowerBound([h]);S.objectStore(\"blocks\").delete(x),S.objectStore(\"index\").delete(x)})}function ce(h,S){return o.clear(),l([\"head\",\"blocks\",\"index\",\"overlay\",\"predicted\"],\"readwrite\",async(x)=>{if((await B(x.objectStore(\"head\").get(Ae)))?.generation!==h?.generation)U(\"the head moved during a swap\");if(h){let v=IDBKeyRange.bound([h.generation],[h.generation,[]]);x.objectStore(\"blocks\").delete(v),x.objectStore(\"index\").delete(v)}x.objectStore(\"overlay\").clear(),x.objectStore(\"predicted\").clear(),x.objectStore(\"head\").put(S,Ae)})}async function qe(h,S,x){let P,v=[],T=0,A=0,_=0,q=0,V=0,Y,se=De;for await(let ye of Lo(h)){if(!P){if(ye.table!==gc)U(\"the pack does not start with its index\");if(P=bc(ye.payload),x&&P.version<x.version)U(`the pack is version ${P.version}, the head holds ${x.version}`);for(let ve of P.tables)v.push({rows:ve.rows,first:[],last:[],hashes:[]});continue}let oe=P.tables[T];if(!oe||ye.table!==T||ye.ordinal!==A)U(`expected block ${T}/${A}, got ${ye.table}/${ye.ordinal}`);let be=await vr(P,ye),Sn=Math.min(P.blockRows,oe.rows-A*P.blockRows);if(be.length!==Sn)U(`block ${T}/${A} holds ${be.length} rows`);if(A===0)Y=void 0;for(let[ve,vn]of be){if(Y!==void 0&&Y>=ve)U(`${oe.name}: key ${ve} is out of order`);Y=ve,se=je(se,await Oe(JSON.stringify([oe.name,ve]),vn))}let Mt=be[0]?.[0]??\"\";if(A===0&&Mt!==oe.first)U(`${oe.name}: wrong first key`);if(v[T]?.first.push(Mt),v[T]?.last.push(be[be.length-1]?.[0]??\"\"),v[T]?.hashes.push(oe.blocks[A]??\"\"),await l([\"blocks\"],\"readwrite\",(ve)=>B(ve.objectStore(\"blocks\").put(ye.payload,[S,oe.name,A]))),_+=be.length,q+=be.length,V++,A+1<oe.blocks.length){A++;continue}if(_!==oe.rows)U(`${oe.name}: ${_} rows, the index says ${oe.rows}`);T++,A=0,_=0}if(!P)U(\"the pack is empty\");if(T!==P.tables.length)U(\"the pack ends before its last block\");if(se!==P.digest)U(\"the set digest does not match\");let ge=P;return await l([\"index\"],\"readwrite\",(ye)=>{ge.tables.forEach((oe,be)=>ye.objectStore(\"index\").put(v[be],[S,oe.name]))}),{index:ge,rows:q,blocks:V}}async function C(h){let S=await r();if(S?.quota===void 0)return{checked:!1,fits:!0};let x=S.usage??0;if(x+h+mc<=S.quota)return{checked:!0,fits:!0};return{checked:!0,fits:!1,bytes:h,usage:x,quota:S.quota}}async function N(h){let S=await y(),x=(S?.generation??0)+1;await re(x);try{let{index:P,rows:v,blocks:T}=await qe(h,x,S);return await ce(S,{version:P.version,digest:P.digest,generation:x,blockRows:P.blockRows,codec:\"gzip\",tables:P.tables.map((A)=>A.name)}),{installed:!0,version:P.version,tables:P.tables.length,rows:v,blocks:T}}catch(P){throw await re(x),P}}function X(h,S={}){return f(async()=>{if(S.bytes!==void 0){let x=await C(S.bytes);if(!x.fits)return{installed:!1,fit:x}}return N(h)})}function we(h){return f(async()=>{let S=await y();if(S&&h.version<S.version)return{installed:!1,reason:\"older\"};if(S&&!S.partial&&h.version===S.version)return{installed:!1,reason:\"held\"};let x=Object.values(h.tables).reduce((v,T)=>v+T.length,0);if(h.complete){if(await Sr(h.tables)!==h.digest)U(\"the ring digest does not match its rows\");let{bytes:v}=await Wo({version:h.version,tables:h.tables});if(h.routes)await H(h.routes,h.templates);let{version:T,rows:A}=await N(kc(v));return{installed:!0,version:T,rows:A,complete:!0}}if(h.routes)await H(h.routes,h.templates);let P=(S?.generation??0)+1;return await l([\"head\",\"blocks\",\"index\",\"overlay\",\"predicted\"],\"readwrite\",async(v)=>{if((await B(v.objectStore(\"head\").get(Ae)))?.generation!==S?.generation)U(\"the head moved during a ring\");if(S){let A=IDBKeyRange.bound([S.generation],[S.generation,[]]);v.objectStore(\"blocks\").delete(A),v.objectStore(\"index\").delete(A)}v.objectStore(\"overlay\").clear(),v.objectStore(\"predicted\").clear();for(let[A,_]of Object.entries(h.tables))for(let[q,V]of _)v.objectStore(\"overlay\").put(V,[A,q]);v.objectStore(\"head\").put({version:h.version,digest:h.digest,generation:P,blockRows:br,codec:\"gzip\",tables:Object.keys(h.tables),partial:!0},Ae)}),o.clear(),{installed:!0,version:h.version,rows:x,complete:!1}})}function jt(h){return f(()=>Xe(h))}async function Xe(h){let S=await y();if(!S)U(\"no pack is installed\");if(S.partial)U(\"the held pack is partial; install the pack first\");if(S.version!==h.from)U(`the delta starts at ${h.from}, the store holds ${S.version}`);if(h.to<h.from)U(`the delta ends at ${h.to}, before it starts at ${h.from}`);let x=async(v,T,A)=>{let _=await z(T,A,!1);if(_===void 0)return v;return Kt(v,await Oe(JSON.stringify([T,A]),_))},P=S.digest;for(let[v,T]of Object.entries(h.tables)){for(let A of T.deletes)P=await x(P,v,A);for(let[A,_]of T.puts)P=je(await x(P,v,A),await Oe(JSON.stringify([v,A]),_))}if(P!==h.digest)U(\"the candidate digest does not match the delta\");await l([\"head\",\"overlay\",\"predicted\"],\"readwrite\",async(v)=>{let T=v.objectStore(\"predicted\");for(let[_,q]of Object.entries(h.tables)){for(let V of q.deletes)T.delete([_,V]);for(let[V]of q.puts)T.delete([_,V])}if(h.to!==h.from)T.clear();let A=await B(v.objectStore(\"head\").get(Ae));if(!A||A.version!==S.version||A.digest!==S.digest)U(\"the base moved during a delta\");for(let[_,q]of Object.entries(h.tables)){for(let V of q.deletes)v.objectStore(\"overlay\").put(null,[_,V]);for(let[V,Y]of q.puts)v.objectStore(\"overlay\").put(Y,[_,V])}v.objectStore(\"head\").put({...A,version:h.to,digest:h.digest},Ae)})}function ct(h){return f(async()=>{if(!await y())return;await l([\"predicted\"],\"readwrite\",(S)=>{let x=S.objectStore(\"predicted\");for(let[P,v,T]of h.puts)x.put(T,[P,v]);for(let[P,v]of h.deletes)x.put(null,[P,v])})})}function bn(h,S){return f(async()=>{let x=await y();if(!x)U(\"no pack is installed\");let P=await l([\"predicted\"],\"readonly\",(v)=>w(v,IDBKeyRange.lowerBound([\"\"]),\"predicted\"));await Xe({from:x.version,to:h,digest:S,tables:Ho(pn(P))})})}function Ct(){return f(()=>l([\"predicted\"],\"readwrite\",(h)=>{h.objectStore(\"predicted\").clear()}))}function Rn(){return f(async()=>{let h=await y();if(!h||h.partial||h.unconfirmed>0)return!1;let S=pn(await l([\"overlay\"],\"readonly\",(v)=>w(v,IDBKeyRange.lowerBound([\"\"])))),x={from:h.version,to:h.version,digest:h.digest,tables:Ho(S)};if(!qo(x))return!1;let P=h.generation+1;await re(P);try{let v=[];for(let T of[...new Set([...h.tables,...S.keys()])].sort()){let A=h.tables.includes(T)?await m(h.generation,T):void 0,_={rows:0,first:[],last:[],hashes:[]},q=[],V=async()=>{let Y=await vc(new Uint8Array(hc.encode(Ge(q)))),se=_.hashes.length;_.first.push(q[0]?.[0]??\"\"),_.last.push(q[q.length-1]?.[0]??\"\"),_.hashes.push(await Sc(Y)),_.rows+=q.length,await l([\"blocks\"],\"readwrite\",(ge)=>B(ge.objectStore(\"blocks\").put(Y,[P,T,se]))),q=[]};for await(let Y of M(h,A,T,S.get(T)??[]))if(q.push(Y),q.length===h.blockRows)await V();if(q.length>0)await V();if(_.rows>0)v.push(T),await l([\"index\"],\"readwrite\",(Y)=>B(Y.objectStore(\"index\").put(_,[P,T])))}return await ce(h,{version:h.version,digest:h.digest,generation:P,blockRows:h.blockRows,codec:\"gzip\",tables:v}),!0}catch(v){throw await re(P),v}})}function H(h,S={}){return l([\"templates\"],\"readwrite\",(x)=>{let P=x.objectStore(\"templates\");P.clear(),h.forEach((v,T)=>{let A=S[v.pattern];P.put(A?{order:T,route:v,template:A}:{order:T,route:v},v.pattern)})})}async function ut(){return(await l([\"templates\"],\"readonly\",(S)=>B(S.objectStore(\"templates\").getAll()))).sort((S,x)=>S.order-x.order)}async function Bt(){return(await ut()).map((h)=>h.route)}async function It(){let h={};for(let{route:S,template:x}of await ut())if(x)h[S.pattern]=x;return h}return{counters:s,head:y,recordCounts:()=>l([\"blocks\",\"index\",\"overlay\",\"head\"],\"readonly\",async(h)=>{let S=(A)=>B(h.objectStore(A).count()),[x,P,v,T]=await Promise.all([S(\"blocks\"),S(\"index\"),S(\"overlay\"),S(\"head\")]);return{blocks:x,index:P,overlay:v,head:T}}),installPack:X,installRing:we,estimateBeforeInstall:C,applyDelta:jt,applyPredicted:ct,confirmPredicted:bn,dropPredicted:Ct,getRow:Q,scanTable:te,compact:Rn,putRoutes:H,getRoutes:Bt,getTemplates:It}}var Vo=[\"content-security-policy\",\"content-security-policy-report-only\",\"x-frame-options\",\"x-content-type-options\",\"referrer-policy\",\"permissions-policy\",\"cross-origin-opener-policy\",\"cross-origin-embedder-policy\",\"cross-origin-resource-policy\"],zo=128;function Go(e){if(!Array.isArray(e))return;let t=Vo;return e.filter((n)=>Array.isArray(n)&&n.length===2&&typeof n[0]===\"string\"&&typeof n[1]===\"string\"&&t.includes(n[0]))}function Jo(e){let t=[];for(let n of Vo){let r=e.get(n);if(r!==null)t.push([n,r])}return t}function Ac(e){return e!==void 0&&e.encodedBodySize===0?\"hit\":\"miss\"}function Ko(e){return e===\"hit\"}function Qo(e){return performance.getEntriesByName(e).at(-1)}async function Xo(e,t,n){try{let r=await t(e,{cache:\"only-if-cached\",mode:\"same-origin\"});if(await r.arrayBuffer(),!r.ok)return\"miss\";return Ac(n(e))}catch{return\"miss\"}}var Qe={reuse:0.5,futureViews:2,requestBytes:2000,artifactBytes:20000,avoidedBytes:17054,changesPerDay:1};function Zo(e){let{hot:t,...n}=e??{};return{...Qe,...n}}function Ec(e,t){return e.bytes+e.requests*t}var Tc={bytes:0,requests:0};function Dc(e,t=Qe){let n=e.reuse??t.reuse,r=e.futureViews??t.futureViews,s=(o)=>Ec(o,t.requestBytes);return n*r*s(e.avoided)-s(e.provision)-s(e.maintain??Tc)}var Yo={layout:0,template:0,asset:0,route:1,expansion:2};function ei(e,t=Qe){return e.map((n)=>({...n,benefit:Dc(n,t)})).filter((n)=>n.benefit>0).sort((n,r)=>Yo[n.kind]-Yo[r.kind]||r.benefit-n.benefit||(n.id<r.id?-1:n.id>r.id?1:0))}class Pr{#e=new Map;#t(e){let t=this.#e.get(e)??{id:e,bytes:0,requests:0,views:0,catalogueBytes:0,catalogueViews:0};return this.#e.set(e,t),t}spend(e,t,n=!1){let r=this.#t(e);if(r.bytes+=t.bytes,r.requests+=t.requests,n)r.catalogueBytes+=t.bytes}serve(e,t=!1){let n=this.#t(e);if(n.views+=1,t)n.catalogueViews+=1}entries(){return[...this.#e.values()].map((e)=>({...e})).sort((e,t)=>e.id<t.id?-1:1)}totals(){let e=[...this.#e.values()],t=(s)=>e.reduce((o,i)=>o+s(i),0),n=t((s)=>s.views),r=t((s)=>s.bytes);return{bytes:r,requests:t((s)=>s.requests),views:n,bytesPerView:n===0?null:r/n,catalogueBytes:t((s)=>s.catalogueBytes),catalogueViews:t((s)=>s.catalogueViews)}}meanFetchBytes(){let e=[...this.#e.values()].filter((t)=>t.bytes>t.catalogueBytes);return e.length===0?null:e.reduce((t,n)=>t+n.bytes-n.catalogueBytes,0)/e.length}}var Oc=/<span data-spool-placeholder=\"([^\"]*)\"><\\/span>/g,jc=/\\{\\{spool-slot:([A-Za-z0-9_.-]+)\\}\\}/g;function ti(e,t,n){let r=[],s=[],o=new Set,i=e.replace(t,(u,l)=>{o.add(l);let f=Object.hasOwn(n,l)?n[l]:void 0;if(f===void 0)return s.push(l),u;return r.push(l),f}),a=Object.keys(n).filter((u)=>!o.has(u));return{html:i,filled:r,unfilled:s,unmatched:a}}function Cc(e,t){return ti(e,Oc,t)}function Bc(e,t){return ti(e,jc,t)}function ni(e){let t=(i)=>{let a={};for(let[u,l]of Object.entries(i??{})){if(typeof l!==\"string\")return null;a[u]=l}return a},n=t(e.fragments),r=t(e.slots);if(!n||!r)return{ok:!1,reason:\"unresolved reference\"};let s=Cc(e.shell,n);if(s.unfilled.length>0)return{ok:!1,reason:`unfilled placeholders: ${s.unfilled.join(\", \")}`};let o=Bc(s.html,r);if(o.unfilled.length>0)return{ok:!1,reason:`unfilled slots: ${o.unfilled.join(\", \")}`};return{ok:!0,html:o.html}}var Ic=\"data-spool-gate\";function ri(e,t){if(e.includes(\"data-spool-client\")||e.includes(Ic))return e;for(let n of[/<\\/head\\s*>/i,/<\\/body\\s*>/i]){let r=e.search(n);if(r>=0)return e.slice(0,r)+t+e.slice(r)}return e+t}var Mc={\"&\":\"&\",\"<\":\"<\",\">\":\">\",'\"':\""\",\"'\":\"'\"};function $c(e){return e.replace(/[&<>\"']/g,(t)=>Mc[t])}function si(e,t){if(e===null||typeof e!==\"object\")return;return Object.hasOwn(e,t)?e[t]:void 0}function xr(e,t){let n=t[t.length-1];if(e.length===0)return n.value;if(e[0]===\"@index\")return n.index;for(let r=t.length-1;r>=0;r--){let s=t[r];if(si(s.value,e[0])===void 0)continue;return e.reduce((o,i)=>si(o,i),s.value)}return}function _c(e){if(Array.isArray(e))return e.length>0;return!(e===void 0||e===null||e===!1||e===\"\"||e===0)}function Nc(e){return typeof e===\"string\"||typeof e===\"number\"?String(e):\"\"}function Ar(e,t,n){let r=\"\";for(let s of e)if(s.t===\"text\")r+=s.v;else if(s.t===\"var\"){let o=Nc(xr(s.p,t));if(!s.raw)r+=$c(o);else if(n.has(s.p.join(\".\")))r+=o;else throw new L(\"bad-template\",`{{{${s.p.join(\".\")}}}} is not trusted`)}else if(s.t===\"if\")r+=Ar(_c(xr(s.p,t))?s.then:s.else,t,n);else{let o=xr(s.p,t);if(!Array.isArray(o))continue;o.forEach((i,a)=>{r+=Ar(s.body,[...t,{value:i,index:a}],n)})}return r}function oi(e,t){if(e.v!==1)throw new L(\"bad-template\",`unknown template version ${String(e.v)}`);return Ar(e.nodes,[{value:t,index:0}],new Set(e.trusted))}var Wc=(e)=>typeof e===\"object\"&&e!==null&&!Array.isArray(e);async function Er(e,t,n,r={},s,o,i){try{let a=n,u=t.query;if(u&&(u.plan!==void 0||o!==void 0||s!==void 0&&s!==\"\")){if(n.strategy===\"assembly\"||n.strategy===\"static\")return{ok:!1,reason:`${n.strategy} artifact cannot answer a query`};let y=n.body.data,m=u.plan?Bs(u.list,u.plan,y,s??\"\",i):o===void 0?await ds(u,y,s??\"\",ls(u)):Un(u,{...Wc(y)?y:{},[u.list]:o},s??\"\");if(!m.ok)return m;a={...n,body:{data:m.data}}}let l=Object.hasOwn(r,t.pattern)?r[t.pattern]:void 0,f;if(l)f=await l(a);else if(a.strategy===\"data\"&&t.strategy===\"data\")return{ok:!0,html:JSON.stringify(a.body.data)};else if(a.strategy===\"projection\"&&t.strategy===\"projection\")return{ok:!1,reason:`no renderer for ${t.pattern}`};else if(a.strategy===\"static\"||a.strategy!==t.strategy)return{ok:!1,reason:`artifact is ${a.strategy}, route is ${t.strategy}`};else if(a.strategy===\"assembly\"){let y=ni(a.body);if(!y.ok)return y;f=y.html}else if(a.strategy!==\"template\")return{ok:!1,reason:`${a.strategy} has no built-in render`};else{let y=Object.hasOwn(e.templates,t.pattern)?e.templates[t.pattern]:void 0;if(!y)return{ok:!1,reason:`no template for ${t.pattern}`};f=oi(y,a.body.data)}if(t.strategy===\"data\")return{ok:!0,html:f};return{ok:!0,html:ri(f,e.clientTag)}}catch(a){return{ok:!1,reason:a instanceof Error?a.message:\"render failed\"}}}var Lc=new TextEncoder,Tr=(e)=>Lc.encode(JSON.stringify(e)).length;class ii{name;clear;rows;hashes;digest;bytes;#e;#t=new Set;#r=new Set;constructor(e,t,n){this.#e=e,this.name=t,this.clear=n===void 0,this.rows=n?.rows??new Map,this.hashes=n?.hashes??new Map,this.digest=n?.meta.digest??De,this.bytes=n?.meta.bytes??0}async add(e){let t=e.reset&&e.after===void 0;if(t)this.clear=!0,this.bytes=0,this.#t.clear(),this.#r.clear();let n=new Map,r=(i)=>n.has(i)?n.get(i):t?void 0:this.rows.get(i);for(let{key:i}of e.deletes){let a=r(i);if(a!==void 0)this.bytes-=Tr(a);n.set(i,void 0)}for(let{key:i,row:a}of e.puts){let u=r(i);if(u!==void 0)this.bytes-=Tr(u);this.bytes+=Tr(a),n.set(i,a)}let s={hashes:this.hashes,...this.#e.hash?{hash:this.#e.hash}:{}},o=await Po(this.rows,e,this.digest,s);this.rows=o.rows,this.hashes=o.hashes,this.digest=o.digest;for(let{key:i}of e.deletes)this.#r.add(i),this.#t.delete(i);for(let{key:i}of e.puts)this.#t.add(i),this.#r.delete(i);return o.matches}writes(){return{puts:(this.clear?[...this.rows.keys()]:[...this.#t]).map((t)=>({name:this.name,key:t,row:this.rows.get(t),hash:this.hashes.get(t)})),deletes:this.clear?[]:[...this.#r]}}}class Dr{#e;#t=new Map;#r=new Map;#o;#s=Promise.resolve();#n=new Map;#i=new Map;evicted=0;constructor(e){this.#e=e}#a(e){let t=this.#s.then(e,e);return this.#s=t.catch(()=>{return}),t}#c(){return this.#o??=this.#e.storage.getDatasets().then((e)=>new Map(e.map((t)=>[t.name,t]))),this.#o}async list(){return[...(await this.#c()).values()].sort((e,t)=>e.name<t.name?-1:1)}get(e){let t=this.#t.get(e);if(!t)t=this.#u(e),this.#t.set(e,t);return t}async#u(e){let t=(await this.#c()).get(e);if(!t)return;let n=await this.#e.storage.readDataset(e),r=De,s=n.length===t.count;try{for(let i of n)r=je(r,i.hash)}catch{s=!1}if(!s||r!==t.digest){this.evicted+=1,await this.drop(e);return}let o={meta:t,rows:new Map(n.map((i)=>[i.key,i.row])),hashes:new Map(n.map((i)=>[i.key,i.hash]))};return this.#r.set(e,o),o}async rows(e){let t=await this.get(e);if(!t)return;let n=this.#n.get(e);if(!n)n=[...t.rows.keys()].sort().map((r)=>t.rows.get(r)),this.#n.set(e,n);return n}async tables(e,t){let n=await this.#p(e);if(!n)return;let r=new Map;for(let s of t){let o=await this.#p(s);if(!o)return;r.set(s,o)}return{base:n,joined:(s)=>r.get(s)}}async#p(e){let t=await this.get(e);if(!t)return;let n=this.#i.get(e);if(!n){let r=[...t.rows.keys()].sort(Et);n={keys:r,rows:t.rows,index:new rr(r,t.rows)},this.#i.set(e,n)}return n}loaded(e){return this.#r.has(e)}row(e,t){return this.#r.get(e)?.rows.get(t)}stage(e,t){return new ii(this.#e,e,t)}commit(e,t,n){return this.#a(async()=>{if(this.#e.epoch()!==n)return!1;let r=this.#r.get(e.name),s={name:e.name,schema:t.schema,cursor:t.cursor,count:e.rows.size,digest:e.digest,bytes:e.bytes,appliedAt:this.#e.now()},{puts:o,deletes:i}=e.writes();await this.#e.storage.commitDataset({name:e.name,meta:s,clear:e.clear,puts:o,deletes:i});let a={meta:s,rows:e.rows,hashes:e.hashes};return this.#i.delete(e.name),await this.#f(e.name,a),await this.#e.onChange?.(e.name,...qc(r,a)),!0})}touch(e,t){return this.#a(async()=>{let n=this.#r.get(e);if(!n||this.#e.epoch()!==t)return!1;let r={...n.meta,appliedAt:this.#e.now()};return await this.#e.storage.commitDataset({name:e,meta:r,clear:!1,puts:[],deletes:[]}),await this.#f(e,{...n,meta:r}),!0})}drop(e){return this.#a(async()=>{let t=this.#r.get(e);if(await this.#e.storage.commitDataset({name:e,meta:null,clear:!0,puts:[],deletes:[]}),this.#i.delete(e),await this.#f(e,void 0),t)await this.#e.onChange?.(e,[],[...t.rows.keys()])})}clear(){return this.#a(async()=>{await this.#e.storage.clearDatasets(),this.#t.clear(),this.#r.clear(),this.#n.clear(),this.#i.clear(),this.#o=Promise.resolve(new Map)})}async#f(e,t){let n=await this.#c();if(this.#n.delete(e),t)n.set(e,t.meta),this.#r.set(e,t),this.#t.set(e,Promise.resolve(t));else n.delete(e),this.#r.delete(e),this.#t.delete(e)}}function qc(e,t){let n=[];for(let[s,o]of t.hashes)if(e?.hashes.get(s)!==o)n.push(s);let r=[...e?.hashes.keys()??[]].filter((s)=>!t.hashes.has(s));return[n,r]}function st(e,t,n){let r=e.get(t)??new Set;r.add(n),e.set(t,r)}function ot(e,t,n){let r=e.get(t);if(!r)return;if(r.delete(n),r.size===0)e.delete(t)}class gn{#e=new Map;#t=new Map;#r=new Map;#o=new Map;#s=new Map;#n=new Map;#i=new Map;#a=new Map;addProjection(e,t,n,r=[]){this.removeProjections([e]),this.#a.set(e,{deps:[...t],children:[...n],rows:[...r]});for(let s of t)st(this.#e,s,e);for(let s of n)st(this.#t,s,e);for(let s of r)st(this.#s,s,e)}removeProjections(e){for(let t of e){let n=this.#a.get(t);if(!n)continue;for(let r of n.deps)ot(this.#e,r,t);for(let r of n.children)ot(this.#t,r,t);for(let r of n.rows)ot(this.#s,r,t);this.#a.delete(t)}}addArtifact(e,t){this.removeArtifacts([e]),this.#i.set(e,t);for(let n of t.records)st(this.#r,n,e);for(let n of t.projections)st(this.#o,n,e);for(let n of t.rows??[])st(this.#n,n,e)}removeArtifacts(e){for(let t of e){let n=this.#i.get(t);if(!n)continue;for(let r of n.records)ot(this.#r,r,t);for(let r of n.projections)ot(this.#o,r,t);for(let r of n.rows??[])ot(this.#n,r,t);this.#i.delete(t)}}clear(){this.#e.clear(),this.#t.clear(),this.#r.clear(),this.#o.clear(),this.#s.clear(),this.#n.clear(),this.#i.clear(),this.#a.clear()}rowsReaching(e){let t=new Set,n=new Set;for(let s of e){for(let o of this.#s.get(s)??[])t.add(o);for(let o of this.#n.get(s)??[])n.add(o)}let r=this.withParents(t);for(let s of this.artifactsUsing([],r))n.add(s);return{projections:r,artifacts:[...n].sort()}}projectionsReading(e){let t=new Set;for(let n of e)for(let r of this.#e.get(n)??[])t.add(r);return[...t].sort()}withParents(e){let t=new Set,n=[...e];for(let r=n.pop();r!==void 0;r=n.pop()){if(t.has(r))continue;t.add(r),n.push(...this.#t.get(r)??[])}return[...t].sort()}artifactsUsing(e,t){let n=new Set;for(let r of e)for(let s of this.#r.get(r)??[])n.add(s);for(let r of t)for(let s of this.#o.get(r)??[])n.add(s);return[...n].sort()}}class it{#e;#t=new Map;constructor(e){this.#e=e}async load(){for(let e of await this.#e.all())this.#t.set(e.id,e)}get(e){return this.#t.get(e)}all(){return[...this.#t.values()]}ids(){return[...this.#t.keys()].sort()}async put(e,t){let n=e.filter((r)=>(this.#t.get(r.id)?.version??-1)<r.version);for(let r of n)this.#t.set(r.id,r);if(n.length>0)if(t)await this.#e.put(n);else await this.#e.delete(n.map((r)=>r.id));return n.map((r)=>r.id)}async drop(e){let t=e.filter((n)=>this.#t.delete(n));if(t.length>0)await this.#e.delete(t)}forget(){this.#t.clear()}}function Or(e){return new it({all:()=>e.allProjections(),put:(t)=>e.putProjections(t),delete:(t)=>e.deleteProjections(t)})}function jr(e){return new it({all:()=>e.allRecords(),put:(t)=>e.putRecords(t),delete:(t)=>e.deleteRecords(t)})}function Dt(e){return e.records!==void 0||e.projections!==void 0||yn(_e(e.body))}var yn=(e)=>e.records.length+e.projections.length+(e.rows?.length??0)>0;function ai(e){return _e(e.data).projections}var ci=(e)=>_e(e.data).rows??[];class Cr{records;projections;index=new gn;#e;#t;constructor(e){this.#e=e,this.records=jr(e.storage),this.projections=Or(e.storage)}get loaded(){return this.#t!==void 0}ensure(){let e=this.#t===void 0;return this.#t??=this.#r(),e?this.#t:this.#t.then(()=>[])}async#r(){await Promise.all([this.records.load(),this.projections.load()]);for(let t of this.projections.all())this.index.addProjection(t.id,t.deps,ai(t),ci(t));for(let{artifact:t}of await this.#e.artifacts()){let n=_e(t.body);if(yn(n))this.index.addArtifact(t.id,n)}let e={};for(let t of this.records.all()){let n=this.#e.tagVersion(t.id);if(n>t.version)e[t.id]=n}for(let t of this.projections.all())for(let n of t.deps){let r=this.#e.tagVersion(n);if(r>t.version)e[n]=r}return(await this.invalidate(e)).artifacts}async put(e,t){await this.records.put(e.records??[],t);let n=await this.projections.put(e.projections??[],t);for(let s of n){let o=this.projections.get(s);this.index.addProjection(s,o.deps,ai(o),ci(o))}let r=_e(e.body);if(yn(r))this.index.addArtifact(e.id,r)}forgetArtifacts(e){this.index.removeArtifacts(e)}held(e){let t={};for(let n of[...this.records.all(),...this.projections.all()].slice(0,e))t[n.id]=n.version;return t}async invalidate(e){let t=Object.keys(e),n=(a,u)=>(e[a]??0)>u,r=t.filter((a)=>{let u=this.records.get(a);return u!==void 0&&n(a,u.version)}),s=this.index.projectionsReading(t).filter((a)=>{let u=this.projections.get(a);return u!==void 0&&u.deps.some((l)=>n(l,u.version))}),o=this.index.withParents(s).filter((a)=>this.projections.get(a)),i=this.index.artifactsUsing(r,o);return await this.records.drop(r),await this.projections.drop(o),this.index.removeProjections(o),{records:r.sort(),projections:o,artifacts:i}}async rowsChanged(e,t,n){let r=(i)=>`${e}/${i}`,s=this.index.rowsReaching([...t,...n].map(r)),o=this.index.rowsReaching(n.map(r));return await this.projections.drop(o.projections),this.index.removeProjections(o.projections),{touched:s,dropped:{records:[],projections:o.projections,artifacts:o.artifacts}}}async clear(){this.records.forget(),this.projections.forget(),this.index.clear(),await this.#e.storage.clearGraph()}datasetsOf(e){let t=new Set,n=new Set,r=[e.body];for(let s=r.pop();s!==void 0;s=r.pop()){let o=_e(s);for(let i of o.rows??[])t.add(zn(i)?.dataset??i);for(let i of o.projections){if(n.has(i))continue;n.add(i);let a=this.projections.get(i);if(a)r.push(a.data)}}return[...t]}async materialize(e){if(e.strategy===\"static\"||!yn(_e(e.body)))return{ok:!0,artifact:e};await this.ensure();let t=this.datasetsOf(e);if(t.length>0){await this.#e.loadDatasets?.(t);let a=t.filter((u)=>!this.#e.held?.(u));if(a.length>0)return{ok:!1,reason:`dataset ${a[0]} is not held`,datasets:a}}let n={record:(a)=>this.records.get(a),projection:(a)=>this.projections.get(a),...this.#e.row?{row:this.#e.row}:{}};if(e.strategy!==\"assembly\"){let a=Gn(e.body.data,n);if(!a.ok)return a;return{ok:!0,artifact:{...e,body:{data:a.value}}}}let r=(a)=>{let u={};for(let[l,f]of Object.entries(a??{})){let y=Gn(f,n);if(!y.ok)return y;if(typeof y.value!==\"string\")return{ok:!1,reason:`${l} did not resolve to text`};u[l]=y.value}return{ok:!0,value:u}},s=r(e.body.fragments);if(!s.ok)return s;let o=r(e.body.slots);if(!o.ok)return o;let i={shell:e.body.shell};if(e.body.fragments)i.fragments=s.value;if(e.body.slots)i.slots=o.value;return{ok:!0,artifact:{...e,body:i}}}}class mn{#e;#t;#r;#o=new Map;#s=new Map;#n=null;#i=0;#a=0;#c;#u=new Map;graph;datasets;constructor(e,t,n=Date.now,r){this.#e=e,this.#t=t,this.#r=n,this.datasets=new Dr({storage:e,now:n,epoch:()=>this.#a,...r?{hash:r}:{},onChange:(s,o,i)=>this.#p(s,o,i)}),this.graph=new Cr({storage:e,tagVersion:(s)=>this.#s.get(s)??0,artifacts:()=>this.#l(),row:(s,o)=>this.datasets.row(s,o),held:(s)=>this.datasets.loaded(s),loadDatasets:async(s)=>void await Promise.all(s.map((o)=>this.datasets.get(o)))})}async#p(e,t,n){if(!this.graph.loaded)return;let r=await this.graph.rowsChanged(e,t,n);if(r.dropped.artifacts.length>0)await this.drop(r.dropped.artifacts)}async load(){let e=await this.#e.getMeta();if(e&&e.version===this.#t){this.#n=e.cursor,this.#i=e.syncedAt,this.#s=new Map(e.tags),this.#c=e.policy?.site,this.#u=new Map(e.policy?.paths);return}await this.#e.clearArtifacts(),await this.graph.clear(),await this.datasets.clear(),await this.#d()}get cursor(){return this.#n}get syncedAt(){return this.#i}get sitePolicy(){return this.#c}policyOf(e){return this.#u.get(e)}async keepPolicy(e,t){let n=(r)=>JSON.stringify(r)===JSON.stringify(t);if(e===null){if(n(this.#c))return;this.#c=t}else{if(n(this.#u.get(e)))return;if(this.#u.delete(e),this.#u.set(e,t),this.#u.size>zo)this.#u.delete(this.#u.keys().next().value)}await this.#d()}async get(e){return this.#o.get(e)??await this.#e.getArtifact(e)}async ids(){return(await this.#l()).map((e)=>e.artifact.id)}get epoch(){return this.#a}isCurrent(e){return Do(e,(t)=>this.#s.get(t)??0)}validatedAt(e){return Math.max(To(e.fetchedAt,this.#i),e.validatedAt??0)}async validate(e){let t=await this.get(e);if(!t||!this.isCurrent(t.artifact))return;let n={...t,validatedAt:this.#r()};if(this.#o.has(e))this.#o.set(e,n);else await this.#e.putArtifact(n)}needFor(e,t=!1){if(!t&&!Dt(e))return null;let n=[...new Set([...e.deps,Xn(e.id)])];if(n.length>Qn)return null;return Object.fromEntries(n.map((r)=>[r,e.vector]))}async held(){return await this.#f(),this.graph.held(Ps)}async datasetsOf(e){if(!Dt(e))return[];return await this.#f(),this.graph.datasetsOf(e)}async materialize(e){if(Dt(e))await this.#f();return this.graph.materialize(e)}async#f(){let e=await this.graph.ensure();if(e.length>0)await this.drop(e)}async put(e,t,n=!1){if(!this.isCurrent(e))return!1;if(Dt(e))await this.#f(),await this.graph.put(e,t);let{records:r,projections:s,...o}=e,i={artifact:o,fetchedAt:this.#r(),...n?{catalogue:!0}:{}};if(t)this.#o.delete(e.id),await this.#e.putArtifact(i);else await this.#e.deleteArtifacts([e.id]),this.#o.set(e.id,i);if(this.#n===null)this.#n=e.vector,await this.#d();return!0}async open(e){let t=await this.get(e);if(!t?.catalogue)return;let{catalogue:n,...r}=t;if(this.#o.has(e))this.#o.set(e,r);else await this.#e.putArtifact(r)}async sweep(e){let t={...e};for(let{artifact:n,catalogue:r}of await this.#l()){if(!r)continue;for(let s of[...n.deps,Xn(n.id)])t[s]=Math.min(t[s]??1/0,n.vector)}return Object.keys(t).length>Qn?null:t}async drop(e){for(let t of e)this.#o.delete(t);if(await this.#e.deleteArtifacts(e),this.graph.loaded)this.graph.forgetArtifacts(e)}async wipe(e=null,t=!1){if(this.#a+=1,this.#o.clear(),await this.#e.clearArtifacts(),await this.graph.clear(),!t)await this.datasets.clear();this.#s=new Map,this.#c=void 0,this.#u=new Map,this.#n=e,await this.#d()}async applySync(e){if(e.reset){let n=await this.ids();return await this.wipe(e.cursor,!0),this.#i=this.#r(),await this.#d(),n}let t=await this.#g(e.changed);if(await this.drop(e.dropped),!e.partial)this.#n=Math.max(this.#n??0,e.cursor),this.#i=this.#r();return await this.#d(),[...new Set([...t,...e.dropped])]}async applyEnvelope(e,t,n){let r=[];if(e.clear?.includes(Zn))r=await this.ids(),await this.wipe(e.vector??this.#n);else if(e.invalidate)r=await this.#g(e.invalidate);if(t!==null&&e.seen===t&&e.vector!==void 0&&!n)this.#n=Math.max(this.#n??0,e.vector),this.#i=this.#r();return await this.#d(),r}async#l(){return[...this.#o.values(),...await this.#e.allArtifacts()]}async#g(e){let t=new Map;for(let[s,o]of Object.entries(e))if(s.startsWith(vt))t.set(s.slice(vt.length),o);else if(o>(this.#s.get(s)??0))this.#s.set(s,o);let n=this.graph.loaded?(await this.graph.invalidate(Object.fromEntries(this.#y(e)))).artifacts:[],r=(await this.#l()).filter(({artifact:s})=>{let o=t.get(s.id);return o!==void 0&&s.vector<o||!this.isCurrent(s)||n.includes(s.id)}).map(({artifact:s})=>s.id);return await this.drop(r),r}#y(e){return Object.entries(e).filter(([t])=>!t.startsWith(vt))}async#d(){await this.#e.setMeta({version:this.#t,cursor:this.#n,tags:[...this.#s],syncedAt:this.#i,policy:{...this.#c?{site:this.#c}:{},paths:[...this.#u]}})}}function Fc(e,t){return e.thirdParty?.allow.includes(t.origin)===!0}function Br(e,t,n){let r=new URL(t.url);if(r.origin!==n){let i=to(e.collectors,t.url);if(i&&(t.method===\"POST\"||t.method===\"GET\"))return{kind:\"collector\",collector:i};if(t.method===\"GET\"&&!t.headers.has(\"range\")){let a=e.routes.filter((l)=>l.origin===r.origin),u=Se(a,r.pathname);if(u?.route.strategy===\"data\"&&(r.search===\"\"||u.route.query))return{kind:\"data\",route:u.route,path:r.pathname}}if(t.method===\"GET\"&&Fc(e,r))return{kind:\"thirdparty\"};return{kind:\"ignore\"}}if(r.pathname===so)return{kind:\"ignore\"};if(e.logout?.some((i)=>Pe(i,r.pathname)))return{kind:\"logout\"};if(t.method===\"POST\"&&e.beacons.includes(r.pathname))return{kind:\"beacon\"};if(t.method!==\"GET\")return{kind:\"pass\"};let s=Se(e.routes.filter((i)=>i.origin===void 0),r.pathname),o=r.search!==\"\"&&!s?.route.query;if(t.mode!==\"navigate\"){if(s?.route.strategy===\"static\"&&!t.headers.has(\"range\"))return{kind:\"static\",route:s.route,path:r.pathname+r.search};if(s?.route.strategy===\"data\"&&!t.headers.has(\"range\")&&!o)return{kind:\"data\",route:s.route,path:r.pathname};return{kind:\"asset\"}}if(!s||s.route.strategy===\"data\"||o)return{kind:\"pass\"};return{kind:\"navigation\",route:s.route,params:s.params,path:r.pathname}}function Hc(e,t){let n=(s)=>`${t}${s}`,r=[{condition:{requestMode:\"navigate\"},source:\"fetch-event\"}];for(let s of e.beacons)r.push({condition:{urlPattern:n(s),requestMethod:\"POST\"},source:\"fetch-event\"});for(let s of e.logout??[])r.push({condition:{urlPattern:n(s)},source:\"fetch-event\"});for(let s of e.routes)if(s.strategy===\"static\"||s.strategy===\"data\")r.push({condition:{urlPattern:n(s.pattern)},source:\"fetch-event\"});if((e.collectors?.length??0)>0||e.thirdParty)r.push({condition:{not:{urlPattern:n(\"/*\")}},source:\"fetch-event\"});return r.push({condition:{urlPattern:n(\"/*\")},source:\"network\"}),r}async function ui(e,t,n){if(typeof e.addRoutes!==\"function\")return!1;try{return await e.addRoutes(Hc(t,n)),!0}catch{return!1}}var Uc=86400,Vc={changesPerDay:Qe.changesPerDay,staleBytes:Qe.avoidedBytes,syncBytes:Qe.requestBytes};class li{#e;#t;constructor(e){this.#e=1,this.#t=Uc/e}observe(e,t,n){this.#e+=n,this.#t+=e*t}perSecond(){return this.#e/this.#t}}function zc(e){return(1-Math.exp(-e.perSecond*e.tags*Math.max(0,e.ageSec)))*e.policy.staleBytes-e.policy.syncBytes}var Gc=(e)=>e?Object.entries(e).sort().join(\"|\"):\"*\";class Ir{#e;#t=new Map;#r;#o={};#s=!1;#n=0;rate;constructor(e){this.#e=e,this.#r=e.policy??Vc,this.rate=new li(this.#r.changesPerDay)}sync(e,t){let n=this.#t.get(\"*\");if(n)return n;let r=Gc(e),s=this.#t.get(r);if(s)return s;let o=[...this.#t.values()],i=Promise.allSettled(o).then(()=>this.#i(e,t)).finally(()=>{if(this.#t.get(r)===i)this.#t.delete(r)});return this.#t.set(r,i),i}background(e,t){return this.sync(e,t).then(()=>{return},()=>{return})}defer(e,t){let n=Object.keys(e).length;if(n===0)return!1;if(zc({ageSec:t,perSecond:this.rate.perSecond(),tags:n,policy:this.#r})<=0)return!1;return this.queue(e,t)}queue(e,t){if(e===void 0)this.#s=!0;else{if(Object.keys(e).length===0)return!1;for(let[n,r]of Object.entries(e))this.#o[n]=Math.min(r,this.#o[n]??1/0)}return this.#n=Math.max(this.#n,t),!0}get pending(){return Object.keys(this.#o).sort()}drain(){let e=this.#o,t=this.#s;if(!t&&Object.keys(e).length===0)return Promise.resolve(!0);let n=this.#n;return this.#o={},this.#n=0,this.#s=!1,this.sync(t?void 0:e,n)}async#i(e,t){let{replica:n,fetchSync:r,onNetwork:s}=this.#e,o=n.cursor;if(o===null&&!e)return!0;try{let i=await r(o??0,e);if(e&&t!==void 0&&!i.reset){let a=Object.keys(e),u=a.filter((l)=>Object.hasOwn(i.changed,l)).length;this.rate.observe(a.length,t,u)}return await n.applySync(i),!0}catch{return!1}finally{s?.()}}}var di=\"spool-ring\",fi=\"spool-writes\",pi=\"spool-delta\";var Jc=\"\\x00\",Kc=new RegExp(`<script type=\"application/json\" id=\"(?:${di}|${fi}|${pi})\">[\\\\s\\\\S]*?</script>`,\"g\");function gi(e,t={}){let n=ao(e).replace(/<!--[\\s\\S]*?-->/g,\"\").replace(Kc,\"\");for(let r of t.ignore??[]){let s=r.flags.includes(\"g\")?r.flags:`${r.flags}g`;n=n.replace(new RegExp(r.source,s),Jc)}return n.replace(/\\s+/g,\" \").replace(/>\\s+</g,\"><\").trim()}function yi(e,t,n={}){let r=gi(e,n),s=gi(t,n);if(r===s)return{equal:!0};let o=0;while(o<r.length&&r[o]===s[o])o++;return{at:o,equal:!1,reason:`diverges at ${o}: ${JSON.stringify(r.slice(o,o+80))} vs ${JSON.stringify(s.slice(o,o+80))}`}}function hn(e,t){return t.mode??e.mode??\"serve\"}function mi(e,t,n){if(t.strategy===\"static\")return!1;if(hn(e,t)===\"shadow\")return!0;let r=e.shadowSample??0;return r>0&&n()<r}async function hi(e,t){if(t.status!==200)return!0;return!yi(e,await t.text()).equal}var Mr=\"spool-static-\",$r=4194304,Qc=[\"content-encoding\",\"content-length\",\"transfer-encoding\",\"connection\",\"keep-alive\",\"set-cookie\",\"age\",\"date\",\"vary\"];function bi(e){let t=new Headers(e);for(let n of Qc)t.delete(n);return t}async function _r(e,t){if(Number(e.headers.get(\"content-length\"))>t)return e.body?.cancel().catch(()=>{return}),null;let n=e.body?.getReader();if(!n)return new Uint8Array;let r=[],s=0;for(;;){let{done:a,value:u}=await n.read();if(a)break;if(s+=u.byteLength,s>t)return n.cancel().catch(()=>{return}),null;r.push(u)}let o=new Uint8Array(s),i=0;for(let a of r)o.set(a,i),i+=a.byteLength;return o}function Xc(e){let t=e.getReader(),n=[],r=null,s=()=>{},o=!0,i,a=new ReadableStream({start(f){i=f},cancel(){o=!1}}),u=(f)=>{r=f,s()};return(async()=>{for(;;){let f;try{f=await t.read()}catch(y){if(o)i.error(y);return u({failed:!0,reason:y})}if(f.done){if(o)i.close();return u({failed:!1})}if(n.push(f.value),s(),o)i.enqueue(f.value)}})(),{visitor:new ReadableStream({async pull(f){for(;;){let y=n.shift();if(y)return f.enqueue(y);if(r?.failed)return f.error(r.reason);if(r)return f.close();await new Promise((m)=>s=m)}},cancel:(f)=>t.cancel(f)},{highWaterMark:0}),capture:a}}function Ri(e){if(e.redirected||!e.body)return{visitor:e,copy:e.clone()};let{visitor:t,capture:n}=Xc(e.body),r={status:e.status,statusText:e.statusText,headers:e.headers};return{visitor:new Response(t,r),copy:new Response(n,r)}}var Yc=/^sha(256|384|512)-([A-Za-z0-9+/]+={0,2})$/,Zc=/^(?:W\\/)?\"/;function eu(e){let t=\"\";for(let n of e)t+=String.fromCharCode(n);return btoa(t)}var wi=(e)=>e.replace(/^W\\//,\"\");async function Si(e,t,n){let r=Yc.exec(e);if(r){let s=await crypto.subtle.digest(`SHA-${r[1]}`,t);return eu(new Uint8Array(s))===r[2]}if(Zc.test(e)){let s=n.get(\"etag\");return s!==null&&wi(s)===wi(e)}return!0}var Ot=\"spool-third\",at={class:\"x-spool-class\",fetched:\"x-spool-fetched\"};var tu=[/[._-][0-9a-f]{8,}(?=[._-]|$)/i,/[@/_-]v?\\d+\\.\\d+\\.\\d+/,/\\/v\\d+(?:\\/|$)/],nu=/[?&](?:v|ver|version|hash|h|rev)=[^&]+/i;function vi(e,t,n=[]){if(tu.some((o)=>o.test(e.pathname)))return\"immutable\";let r=t.get(\"cache-control\")??\"\";if(/(?:^|,)\\s*immutable\\b/i.test(r))return\"immutable\";let s=/max-age=(\\d+)/i.exec(r);if(s!==null&&Number(s[1])>=31536000)return\"immutable\";if(nu.test(e.search))return\"revalidate\";for(let o of n)try{if(new RegExp(o).test(e.href))return\"revalidate\"}catch{continue}return null}var ru=[\"template\",\"projection\",\"data\"],xi=\"spool-assets-\",su=[xi,Mr],ou=31536000,iu=86400000,wn=new TextEncoder,ki=(e)=>e.split(\"?\",1)[0],Pi=(e)=>e.strategy===\"data\"&&(e.family!==void 0||e.origin!==void 0);function au(e){let t=e.headers.get(\"cache-control\")??\"\";if(/(?:^|,)\\s*immutable\\b/i.test(t))return!0;let n=/max-age=(\\d+)/i.exec(t);return n!==null&&Number(n[1])>=ou}function Ai(e){let{config:t,storage:n,origin:r,renderers:s}=e,o=e.partitions,i=e.now??Date.now,a=e.random??Math.random,u=yo(e.userAgent??(typeof navigator>\"u\"?\"\":navigator.userAgent)),l=Zo(t.provision),f=e.pack??(typeof indexedDB>\"u\"?void 0:Uo()),y=t.runtime??t.version,m=new mn(n,y,i),w=new Pr,E=new Set,O=new Map,M=new Map,z=new Map,Q=new Set,te=new Set,re=null,ce=new Map,qe=`${xi}${y}`,C=`${Mr}${y}`,N=(c)=>new Request(`${r}${c}`),X=i(),we=t.assets??\"cache\",jt=!1,Xe=null,ct,bn,Ct,Rn,H=null,ut=Promise.resolve(),Bt=t.mode===\"shadow\",It=we!==\"cache\"&&!Bt,h,S=!1,x=()=>t.manifest!==void 0&&t.routes.length===0,P=new Map,v=(c)=>{let d=P.get(c);if(!d)d=e.caches.open(c),P.set(c,d),d.catch(()=>P.delete(c));return d},T=async()=>{if(await(bn??=m.load()),x())await(Ct??=ra());if(o)await(Rn??=Wi())},A=(c)=>{let d=c.then(()=>{return},()=>{return});E.add(d),d.then(()=>E.delete(d))},_=async(c)=>{let d=()=>[...E].filter((p)=>!c.has(p));while(d().length>0)await Promise.allSettled(d())},q=(c)=>{let d=ut.then(c,c);return ut=d.catch(()=>{return}),d};async function V(c,d){if(t.manifest)return Kr();let p=d?`need=${encodeURIComponent(Yn(d))}`:`from=${c}`,g=await e.fetch(`${r}${Ke.sync}?${p}`,{cache:\"no-store\",credentials:\"same-origin\"});if(!g.ok)throw Error(`sync answered ${g.status}`);return await Ft(xt(g.headers),!0),Zt(await g.json())}async function Y(c,d){let p=await c.clone().json().catch(()=>{return}),g=await e.fetch(await oe(c)),b=xt(g.headers);await Ft(b,!1);let k=d.origin??r;if(g.ok&&f)await Js(g,f,se,k,{write:d,url:new URL(c.url),body:p,routes:t.routes}).catch(()=>{return});return A(Ur(g.headers,b,null,!1,!0,!1,async()=>{return})),g}async function se(c,d){let p=await e.fetch(`${r}${ro}${c}/${d}`,{credentials:\"same-origin\"});if(!p.ok)throw Error(`delta answered ${p.status}`);return await p.json()}async function ge(c,d){await T();let p=await c.head();if(!p||p.version>=d.version)return;let g=d.deltas.find((b)=>b.from===p.version);await ye(c,g??await se(p.version,d.version))}async function ye(c,d){await c.applyDelta(d);let p=Object.keys(d.tables).map((g)=>[g,d.to]);await m.applyEnvelope({invalidate:Object.fromEntries(p)},null,!1)}async function oe(c){if(!f||new URL(c.url).origin!==r)return c;let d;try{d=(await f.head())?.version}catch{return c}if(d===void 0)return c;try{let p=new Headers(c.headers);return p.set(K.have,String(d)),new Request(c,{headers:p})}catch{return c}}async function be(c){let d=c.headers.get(K.delta);if(d===null||!f||!c.url)return;if(new URL(c.url).origin!==r)return;try{await ye(f,JSON.parse(d))}catch{}}let Sn={changesPerDay:l.changesPerDay,staleBytes:l.avoidedBytes,syncBytes:l.requestBytes};async function Mt(){let c=[];for(let p of Q)if(!await m.get(p))c.push(p);let d=[];for(let p of t.provision?.hot??[]){if(te.has(p)||c.includes(p)||await m.get(p))continue;let g=Se(t.routes,p);if(!g||g.route.scope!==\"public\"||g.route.strategy===\"static\")continue;if(g.route.family||g.route.origin!==void 0)continue;d.push({id:p,kind:\"route\",provision:{bytes:w.meanFetchBytes()??l.artifactBytes,requests:0},avoided:{bytes:l.avoidedBytes,requests:1}})}return[...c,...ei(d,l).map((p)=>p.id)].slice(0,Zs)}async function ve(c,d,p){let g=Se(t.routes,c.id);if(!g||c.scope!==\"public\"||c.strategy!==g.route.strategy)return;if(await m.put(c,g.route.persist))w.spend(c.id,{bytes:d,requests:p})}let vn=async()=>{if(re===null)return;let c=await f?.head().catch(()=>{return});if(c&&!c.partial)return;return{path:re,sweep:!0}};async function Oi(c,d){if(!Array.isArray(c))return;for(let p of c){let g;try{g=wt(p)}catch{continue}w.spend(g.id,{bytes:wn.encode(JSON.stringify(p)).length,requests:0},!0);let b=Se(t.routes,g.id);if(!b||!ru.includes(g.strategy))continue;if(g.strategy!==b.route.strategy||g.scope!==b.route.scope)continue;let k=ue;if(g.scope===\"principal\"){if(k=await Ee(),!k||k.id!==d)continue}if(await k.replica.get(g.id))continue;await k.replica.put(g,b.route.persist,!0)}}async function ji(c){let d=t.collectors?.find((R)=>R.vendor===c.vendor),p=c.search??\"\";if(d?.stamp)p=no(p,d.stamp,c.at,i());let g=c.method??\"POST\",b={method:g,credentials:c.origin?\"omit\":\"same-origin\"};if(g===\"POST\"){if(b.body=c.body,c.contentType)b.headers={\"content-type\":c.contentType}}if(c.origin){let R=c.contentType.split(\";\")[0]?.trim().toLowerCase()??\"\",j=[\"\",\"text/plain\",\"application/x-www-form-urlencoded\"].includes(R);b.mode=j?\"no-cors\":\"cors\"}let k=await e.fetch(`${c.origin??r}${c.path}${p}`,b);return k.type===\"opaque\"||k.ok||k.status>=400&&k.status<500}let Re=new gr({storage:n,now:i,want:Mt,catalogue:vn,replay:ji,async send(c){let d=await e.fetch(`${r}${Ke.beacon}`,{method:\"POST\",headers:{\"content-type\":\"application/json\"},body:JSON.stringify(c),credentials:\"same-origin\"});if(d.status===200&&(c.want||c.catalogue)){let p=await d.json();if(c.want){let g=Array.isArray(p.artifacts)?p.artifacts:[];for(let b of g){let k=wt(b);await ve(k,wn.encode(JSON.stringify(b)).length,0)}for(let b of c.want)Q.delete(b),te.add(b)}if(c.catalogue)await Oi(p.catalogue,d.headers.get(K.partition))}return d.ok||d.status>=400&&d.status<500}}),Nr=(c)=>new Ir({replica:c,fetchSync:V,onNetwork:()=>A(Re.flushAtMoment()),policy:Sn}),ue={id:null,replica:m,scheduler:Nr(m),deferred:new Set,loaded:Promise.resolve(),dead:!1,covered:!1,leaseUntil:0},lu=ue.scheduler,$t=new Map,kn={},lt=new Map,dt=new Set,_t=new Set,Wr=!1,Lr=null,Ci=async()=>{if(e.estimate)return e.estimate();return(typeof navigator>\"u\"?void 0:await navigator.storage?.estimate?.())??{}},Bi=async()=>{try{let{quota:c,usage:d}=await Ci();if(c===void 0||d===void 0)return;return Math.max(0,(c-d)*(t.datasetShare??1))}catch{return}},Ii=(c)=>{let d=c.status===\"refused\"?`${c.name}:refused:${c.reason}`:`${c.name}:${c.status}`;if(kn[d]=(kn[d]??0)+1,c.status===\"refused\"){if(lt.set(c.name,c.reason),c.reason===\"declined\")M.set(c.name,c.by??null)}else if(c.status!==\"offline\")lt.delete(c.name);if(c.status!==\"offline\"&&c.status!==\"refused\"&&!Wr)Wr=!0,e.broadcast?.({type:\"spool:persist\"})},Pn=()=>new Map((t.principalDatasets??[]).map((c)=>[c.name,c.maxStaleMs]));async function Mi(c,d,p){let g=await e.fetch(d,p);if(c.dead||H!==c)return g;if(g.status===401)await Ye(\"session-ended\");else if(g.ok)if(g.headers.has(K.partition))await Ft(xt(g.headers),!0);else await Ye(\"session-ended\");return g}function ft(c,d=ue){let p=`${d.id??\"\"}\\x00${c}`,g=$t.get(p);if(g)return g;let b=d.id,k=Ao({store:d.replica.datasets,fetch:b===null?(R,j)=>e.fetch(R,j):(R,j)=>Mi(d,R,j),origin:r,epoch:()=>d.dead?-1:d.replica.epoch,budget:Bi,...b===null?{}:{guard:xo(b)}},c).then((R)=>(Ii(R),R)).finally(()=>$t.delete(p));return $t.set(p,k),k}let $i=(c)=>c.status!==\"offline\"&&c.status!==\"refused\";function Nt(c,d=ue){if(d!==ue&&!Pn().has(c))return;let p=`${d.id??\"\"}\\x00${c}`;if(!lt.has(c)&&!$t.has(p))A(ft(c,d))}let _i=(c)=>Se(t.routes,c)?.route.retention??\"session\",Ni=()=>t.routes.some((c)=>c.scope===\"principal\"&&c.retention===\"persistent\")?\"persistent\":\"session\";function qr(c){let d=o.open(c,_i,Ni(),t.principalDatasets!==void 0),p=new mn(d,y,i);return{id:c,replica:p,scheduler:Nr(p),deferred:new Set,loaded:p.load(),dead:!1,covered:!1,leaseUntil:0}}async function Wi(){let c=await o.current();if(c&&!H)H=qr(c)}async function Ee(){await T();let c=H;if(!c)return null;return await c.loaded,c}function Fr(c){c.dead=!0,_t.clear();for(let d of Pn().keys())lt.delete(d)}function Ye(c,d){return q(async()=>{if(await T(),d!==void 0&&H?.id!==d)return!1;let p=H;if(H=null,p?.writes?.kill(),p)Fr(p);if(!p||!o)return!1;return await o.setCurrent(null),await o.destroy(p.id),e.broadcast?.({type:\"spool:cleared\",reason:c}),!0})}function Li(c){return q(async()=>{await T();let d=H;if(d?.id===c)return;if(H=qr(c),Dn=!1,d?.writes?.kill(),d)Fr(d);if(await o.setCurrent(c),d)await o.destroy(d.id),e.broadcast?.({type:\"spool:cleared\",reason:\"partition\"})})}async function qi(){let c=await Ee(),d=[m.cursor,c?.replica.cursor??null].filter((p)=>p!==null);return{type:\"spool:live-state\",live:t.live??null,partition:c?.id??null,have:d.length>0?Math.min(...d):null}}let xn=0,Wt=new Set;function Fi(){if(!e.broadcast)return Promise.resolve(!1);return new Promise((c)=>{let d=()=>{clearTimeout(p),c(!0)},p=setTimeout(()=>{Wt.delete(d),c(!1)},e.liveWaitMs??3000);Wt.add(d),e.broadcast?.({type:\"spool:want-live\"})})}async function Lt(c){if(c.event===\"session\")return xn=0,{type:\"spool:live\",ok:!0};if(c.event===\"revoked\"){if(c.partition!==null)await Ye(\"revoked\",c.partition);return{type:\"spool:live\",ok:!0}}return q(async()=>{await T();let d=H&&H.id===c.partition?H:null,p=t.live?.public===!0,g=[...d?[d]:[],...p?[ue]:[]];if(c.event===\"lease\"){let k=i()+c.leaseMs;for(let R of g)if(R.covered)R.leaseUntil=k;if(d?.covered){for(let R of[...Wt])R();Wt.clear()}return{type:\"spool:live\",ok:!0}}let b=!0;for(let k of g){if(k.dead)continue;let R=k.replica.cursor;if(R===null)continue;if(R<c.delta.from){k.covered=!1,k.leaseUntil=0,b=!1;continue}await k.replica.applySync(c.delta),k.covered=!0}return{type:\"spool:live\",ok:b}})}let qt=0;function An(){qt=i(),e.broadcast?.({type:\"spool:contact\",at:qt})}async function Ft(c,d,p=!1){if(c?.protocol===F)An();if(!o||!c||c.protocol!==F)return;await T();let g=c.clear??[];if(g.includes(\"*\")||H&&g.includes(H.id)){await Re.dropSameOrigin(),await Ye(\"clear\");return}if(p)return;if(c.partition!==void 0){if(H?.id!==c.partition)await Re.dropSameOrigin(),await Li(c.partition)}else if(d&&H)await Re.dropSameOrigin(),await Ye(\"session-ended\")}let Hr=()=>t.writes!==void 0&&t.mode!==\"shadow\",En=(c,d)=>({ok:!1,code:c,message:d});async function Hi(c){let d=`name=${encodeURIComponent(c.name)}&key=${encodeURIComponent(c.key)}`,p=await oe(new Request(`${r}${Ke.write}?${d}`,{method:\"PUT\",headers:{\"content-type\":\"application/json\",\"if-match\":_s(c.base),[cn.id]:c.id},body:JSON.stringify({value:c.value}),cache:\"no-store\",credentials:\"same-origin\"})),g=await e.fetch(p);An();let b=await g.json().catch(()=>{return});return{status:g.status,body:b}}function Tn(c){if(!Hr()||!o?.openWrites)return null;return c.writes??=new Je({store:o.openWrites(c.id),classes:()=>t.writes??[],now:i,send:Hi,onFlush:(d)=>e.broadcast?.({type:\"spool:written\",...d}),timers:e.timers}),c.writes}async function Ht(){if(!Hr())return En(\"writes-off\",\"declared writes are off\");let c=await Ee();if(!c)return En(\"no-partition\",\"no signed-in principal is held\");return Tn(c)??En(\"unavailable\",\"this worker has no partition storage\")}async function Ui(){let c=H?Tn(H):null;if(c)await c.flush()}let Dn=!1;function On(){if(Dn)return;return Dn=!0,Ee().then((c)=>c?Tn(c)?.flushDue():void 0).then(()=>{return},()=>{return})}async function Vi(c,d){if(d.family===void 0||d.scope!==\"public\")return!1;let p=d.family.dataset;return await yr(async(b)=>f?f.getRow(p,b):void 0,d,c,i())!==void 0}async function zi(c,d,p,g){let b=d.scope===\"principal\"?await Ee():ue;if(!b||d.scope===\"principal\"&&b.id!==g)return;let k=await b.replica.held(),R=Object.keys(k).length>0?`&have=${encodeURIComponent(Yn(k))}`:\"\",j=await e.fetch(`${r}${Ke.artifact}?path=${encodeURIComponent(c)}${R}`,{cache:\"no-store\",credentials:\"same-origin\"});if(j.status===204&&j.headers.get(K.provision)===\"declined\"){M.set(c,j.headers.get(K.provisionReason)),z.set(c,p);return}if(!j.ok){if(j.status===404)z.set(c,p);if(d.scope===\"principal\"&&[401,403,404].includes(j.status))await b.replica.drop([c]);return}let D=await j.text(),W=wt(JSON.parse(D));if(W.scope!==d.scope||W.id!==c)return;if(W.strategy!==d.strategy)return;if(d.scope===\"principal\"){if(j.headers.get(K.partition)!==g)return;if(H!==b)return}if(await b.replica.put(W,d.persist)){if(w.spend(c,{bytes:wn.encode(D).length,requests:1}),d.scope===\"principal\"&&d.retention===\"persistent\")await Gi(b,d).catch(()=>{return})}}async function Gi(c,d){let p=new Set([...d.family?[d.family.dataset]:[],...d.query?.dataset?[d.query.dataset]:[],...(d.query?.plan?.join??[]).map((g)=>g.dataset)]);for(let g of p)if(!await c.replica.datasets.get(g))Nt(g,c)}async function jn(c){let d=[...c.deferred];if(c.deferred.clear(),await c.scheduler.drain())for(let p of d)await c.replica.validate(p)}let Ut;function Ji(){if(Ut)return;Ut=(async()=>{await jn(ue);let c=[...dt];dt.clear();for(let d of c)await ft(d)})().catch(()=>{return}).finally(()=>{Ut=void 0}),A(Ut)}async function Ur(c,d,p,g,b,k,R){if(await R(),d&&d.protocol===F){await m.applyEnvelope(d,p,c.has(\"age\"));let j=H;if(j)await j.loaded,await j.replica.applyEnvelope(d,null,!0);let D=d.artifact;if(k&&D){let W=Se(t.routes,D.id),G=D.scope===\"principal\"?await Ee():ue,Z=W&&W.route.strategy!==\"static\"&&W.route.provisionable!==!1&&W.route.scope===D.scope&&!M.has(D.id)&&z.get(D.id)!==D.version&&G&&(D.scope===\"public\"||G.id===d.partition);if(W&&G&&Z&&!await Vi(D.id,W.route)&&!await G.replica.get(D.id))if(D.scope===\"public\"&&hn(t,W.route)===\"shadow\")Q.add(D.id);else{let J=`${D.scope}:${D.id}`,ee=O.get(J)??zi(D.id,W.route,D.version,d.partition);O.set(J,ee);try{await ee}catch{}finally{O.delete(J)}}}}if(b){if(await jn(ue),H)await jn(H);let j=[...dt];dt.clear();for(let G of j)await ft(G);let D=[..._t];_t.clear();let W=H;if(W)for(let G of D)await ft(G,W);await Re.flushAtMoment(),await Ui(),await ia()}}async function Ki(c,d,p,g,b){if(c.method!==\"GET\"||d.status!==200||d.redirected)return;if(b?.signedOut)return;if(g&&!/text\\/html/i.test(d.headers.get(\"content-type\")??\"\"))return;let k=Jo(d.headers);if(g)await m.keepPolicy(null,k);let R=b?.route,j=new URL(c.url);if(!R||R.strategy===\"static\"||j.search!==\"\")return;let D=R.scope===\"principal\"?H?.id===p?.partition?H:null:ue;if(!D)return;await D.loaded,await D.replica.keepPolicy(j.pathname,k)}async function Be(c,d,p){let g=c,b=null;if(!t.manifest&&!d&&c.method===\"GET\"&&m.cursor!==null)try{let J=new Headers(c.headers);J.set(K.vectorSeen,String(m.cursor)),g=new Request(c,{headers:J}),b=m.cursor}catch{g=c}g=await oe(g);let k=await e.fetch(g),R=xt(k.headers);await Ft(R,d,p?.signedOut);let j=d||c.method!==\"GET\",D=p?.clone,W=typeof D===\"function\"?D(k,R):D,{visitor:G,copy:Z}=W?Ri(k):{visitor:k,copy:null};return A((async()=>{await be(k);try{await p?.run(Z,R)}catch{}await Ur(k.headers,R,b,d,j,p?.provision??d,()=>Ki(c,k,R,d,p))})()),G}async function Cn(c,d,p,g=\"\"){let b=d.scope===\"principal\",k=ue;if(b){if(!o)return{reason:\"principal\",staleSec:null};let I=await Ee();if(!I)return{reason:\"cold\",staleSec:null};k=I}let{replica:R,scheduler:j}=k,D=(I)=>async(de)=>b?(await R.datasets.get(I))?.rows.get(de):await f?.getRow(I,de),W=()=>{if(d.family&&d.family.key!==\"viewer.id\")return yr(D(d.family.dataset),d,c,i());if(d.origin!==void 0)return mr(c,i());return R.get(c)},G=d.query?.dataset;if(G!==void 0&&!b&&f&&d.strategy===\"data\"&&d.family===void 0&&d.origin===void 0&&d.query?.plan===void 0){let I=await f.head();if(I&&!I.partial&&I.tables.includes(G)){let de=(await f.scanTable(G)).map(([,mt])=>mt),Te=await Er(t,d,mr(c,i()).artifact,s,g,de),yt=R.policyOf(c)??m.sitePolicy;if(!Te.ok||!yt&&!p&&!Pi(d))return{reason:\"refused\",staleSec:null};return{reason:\"fresh\",html:Te.html,headers:yt,staleSec:0}}}let Z=await W();if(!Z){if(b&&d.family&&!p&&!await R.datasets.get(d.family.dataset))Nt(d.family.dataset,k);return{reason:\"cold\",staleSec:null}}let J=()=>Z?Math.max(0,Math.floor((i()-R.validatedAt(Z))/1000)):null;if(!R.isCurrent(Z.artifact)){let I=J();return await R.drop([c]),{reason:\"invalidated\",staleSec:I}}if(d.version!==void 0&&Z.artifact.strategy===\"static\"&&Z.artifact.body.version!==d.version){let I=J();return await R.drop([c]),{reason:\"invalidated\",staleSec:I}}let ee=d.query?.dataset,Fe=(d.query?.plan?.join??[]).map((I)=>I.dataset),He=ee!==void 0&&g!==\"\"&&!b&&d.scope===\"public\"&&d.query?.plan===void 0&&f?await f.head():void 0,Zr=ee!==void 0&&He&&!He.partial&&He.tables.includes(ee)&&f?(await f.scanTable(ee)).map(([,I])=>I):void 0,Ie=[...new Set([...ee&&Zr===void 0?[ee]:[],...Fe,...b&&d.family?[d.family.dataset]:[],...await R.datasetsOf(Z.artifact)])],Vt=k===ue?void 0:Pn();if(Vt&&Ie.some((I)=>!Vt.has(I)))return{reason:\"refused\",staleSec:J()};let es=async()=>Promise.all(Ie.map(async(I)=>(await R.datasets.get(I))?.meta.appliedAt)),Ue=await es(),ts=Ie.filter((I,de)=>Ue[de]===void 0);if(ts.length>0){if(!p)for(let I of ts)Nt(I,k);return{reason:\"refused\",staleSec:J()}}let Bn=()=>Vt?Ie.filter((I,de)=>{let Te=i()-Ue[de];return!(Te>=0&&Te<Vt.get(I))}):[],In=Bn().length>0;if(In&&p)return{reason:\"refused\",staleSec:J()};let ns=(I)=>I.filter((de)=>de!==void 0),ua=Z.catalogue===!0,zt=In?\"sync-first\":k.covered&&i()<k.leaseUntil?\"serve\":Eo(d.freshness,Math.min(R.validatedAt(Z),...ns(Ue)),i());if(zt===\"sync-first\"&&!In&&!p&&k!==ue&&t.live?.mode===\"adaptive\"&&(xn+=1)===2&&await Fi())zt=\"serve\";let ie=Math.max(J(),...ns(Ue).map((I)=>Math.floor((i()-I)/1000))),Mn=R.needFor(Z.artifact,d.sync===\"deferred\"||d.scope===\"principal\"),Ze=(d.scope===\"principal\"&&Mn?await R.sweep(Mn):Mn)??void 0,Ve=\"fresh\";if(zt===\"sync-first\"){if(Ve=\"hard-sync\",!p){let I=await j.sync(Ze,ie);if(k.dead)return{reason:\"refused\",staleSec:ie};let de=new Set(Bn()),Te=Ie.filter((mt,la)=>{let is=i()-Ue[la];return de.has(mt)||!(is>=0&&is<=d.freshness.maxStale*1000)}),yt=(await Promise.all(Te.map((mt)=>ft(mt,k)))).every($i);if(!(I&&yt)&&d.offline===\"refuse\")return{reason:\"hard-refused\",staleSec:ie};if(Ie.length>0){if(Ue=await es(),Ue.includes(void 0)||Bn().length>0)return{reason:\"refused\",staleSec:ie}}if(I){if(Ze)await R.validate(c);if(Z=await W(),!Z||!R.isCurrent(Z.artifact))return{reason:\"stale-after-sync\",staleSec:ie}}if(!(I&&yt))Ve=\"offline-stale\"}}else if(zt===\"serve-then-sync\"){if(Ve=d.sync===\"deferred\"?\"soft-deferred\":\"soft-sync\",!p){let I=d.sync===\"deferred\"?Ze!==void 0&&j.defer(Ze,ie):j.queue(Ze,ie);if(I&&Ze)k.deferred.add(c);for(let Te of Ie)(k===ue?dt:_t).add(Te);let de=t.lease!==void 0&&ie>=t.lease;if(k===ue&&de&&(I||Ie.length>0))Ji()}}if(d.strategy===\"static\"){let I=await Zi(c);if(!I)return await R.drop([c]),{reason:\"refused\",staleSec:ie};return{reason:Ve,response:I,staleSec:ie}}let rs=R.policyOf(c)??m.sitePolicy;if(!rs&&!p&&!Pi(d))return{reason:\"refused\",staleSec:ie};let Gt=await R.materialize(Z.artifact);if(!Gt.ok){if(Gt.datasets){if(!p)for(let I of Gt.datasets)Nt(I,k);return{reason:\"refused\",staleSec:ie}}return await R.drop([c]),{reason:\"refused\",staleSec:ie}}let gt=d.query?.plan!==void 0,$n=g===\"\"&&d.strategy!==\"data\"&&d.scope===\"public\";if(gt&&$n)return{reason:\"refused\",staleSec:ie};let ss=ee===void 0||gt||$n?void 0:Zr??await R.datasets.rows(ee);if(ee!==void 0&&!gt&&!$n&&!ss)return{reason:\"refused\",staleSec:ie};let os=ee!==void 0&>?await R.datasets.tables(ee,Fe):void 0;if(ee!==void 0&>&&!os)return{reason:\"refused\",staleSec:ie};let _n=await Er(t,d,Gt.artifact,s,g,ss,os);if(!_n.ok){if(_n.reason===Wn)await R.drop([c]);return{reason:\"refused\",staleSec:ie}}if(ua){if(await R.open(c),fr[Ve]===\"local\")Ve=\"catalogue\"}return{reason:Ve,html:_n.html,headers:rs,staleSec:ie}}function Qi(c){let d;try{d=new URL(c)}catch{return}if(d.protocol!==\"http:\"&&d.protocol!==\"https:\")return;if(d.origin!==r)return lo;return Se(t.routes,d.pathname)?.route.pattern}async function Xi(c,d,p){let g=mi(t,d,a);if(p.destination===\"\"||p.destination===\"document\")xn=0;let b=i(),k=Xe===null?null:b-Xe;Xe=b,re=d.catalogue?c:null;let R=await Cn(c,d,g,new URL(p.url).search),j=Qi(p.referrer),D=crypto.randomUUID();if(ce.delete(c),ce.set(c,D),ce.size>64)ce.delete(ce.keys().next().value);let W=(J)=>({id:D,crossOriginLoads:null,tier:g?\"shadow\":fr[R.reason],reason:R.reason,staleSec:R.staleSec,engine:u,scope:d.scope,strategy:d.strategy,route:d.pattern,mismatch:J,swAgeMs:b-X,gapMs:k,...j?{from:j}:{},...ct===void 0?{}:{lifetimes:ct}}),G=async(J)=>{if(t.views!==!1)await Re.record(go(W(J),b))};if(g){let J=R.html;return Be(p,!0,{clone:J!==void 0,route:d,run:async(ee)=>{await G(J===void 0||!ee?null:await hi(J,ee))}})}if(R.response)return w.serve(c),A(G(null)),R.response;if(R.html===void 0){let J=d.strategy===\"static\",ee=await Be(p,!0,{clone:J||((Fe,He)=>Jr(c,d,Fe,He)),route:d,run:async(Fe,He)=>{if(J)await Gr(c,d,Fe);else await ta(c,d,Fe,He);await G(null)}});if(d.scope===\"principal\"&&Vr(ee))await zr(c);return ee}w.serve(c,R.reason===\"catalogue\"),A(G(null));let Z=new Headers(R.headers);return Z.set(\"content-type\",\"text/html; charset=utf-8\"),new Response(R.html,{headers:Z})}function Vr(c){return c.status===401||c.status===403||c.type===\"opaqueredirect\"||c.status>=300&&c.status<400}async function zr(c){let d=await Ee();if(d)await d.replica.drop([c])}async function Yi(c,d,p){let g=new URL(c.url),b=g.origin!==r,k=c.headers.has(\"authorization\"),R=k&&p.scope===\"public\",j=b&&p.scope===\"principal\"&&!k,D=R||j?{reason:\"refused\",staleSec:null}:await Cn(d,p,!1,g.search);if(D.html!==void 0){w.serve(d,D.reason===\"catalogue\");let G=new Headers(D.headers);if(G.set(\"content-type\",p.type??\"application/json\"),b)G.set(\"access-control-allow-origin\",r),G.set(\"vary\",\"origin\");return new Response(D.html,{headers:G})}if(b||R)return e.fetch(c);let W=await Be(c,!1,{provision:!0,route:p,run:async()=>{return}});if(p.scope===\"principal\"&&Vr(W))await zr(d);return W}async function Zi(c){return(await v(C)).match(N(c))}async function Gr(c,d,p){if(!p||p.status!==200||p.redirected){p?.body?.cancel().catch(()=>{return});return}let g=t.manifest?Se(t.routes,ki(c))?.route:d;if(g?.strategy!==\"static\")return;let b=await _r(p,$r);if(!b)return;let k=p.headers.get(\"content-type\")??\"application/octet-stream\",R;if(t.manifest){let D=g.version;if(D===void 0||!await Si(D,b,p.headers))return;R={protocol:F,id:c,scope:\"public\",strategy:\"static\",deps:[],vector:0,body:{type:k,bytes:b.byteLength,version:D}}}else{let D;try{D=er(p.headers)}catch{return}let W=D.artifact;if(D.protocol!==F||!W)return;if(W.id!==c||W.scope!==\"public\")return;R={protocol:F,id:c,scope:\"public\",strategy:\"static\",deps:W.deps,vector:W.version,body:{type:k,bytes:b.byteLength}}}if(await(await v(C)).put(N(c),new Response(b,{headers:bi(p.headers)})),await m.put(R,!0))w.spend(c,{bytes:b.byteLength,requests:0})}function Jr(c,d,p,g){let b=g?.artifact;return(d.strategy===\"assembly\"||d.strategy===\"template\")&&d.family===void 0&&d.scope===\"public\"&&g?.protocol===F&&b?.hash!==void 0&&b.id===c&&b.scope===\"public\"&&hn(t,d)!==\"shadow\"&&!M.has(c)&&p.status===200&&!p.redirected&&/text\\/html/i.test(p.headers.get(\"content-type\")??\"\")}async function ea(c,d,p,g){if(d.strategy===\"template\"){let R=io(p);if(R===null||await et(R)!==g.hash)return null;let j=wt(JSON.parse(R));if(j.id!==c||j.scope!==\"public\")return null;if(j.strategy!==\"template\")return null;return{artifact:j,bytes:wn.encode(R).length}}let b=p.indexOf(t.clientTag),k=b<0?[p]:[p.slice(0,b)+p.slice(b+t.clientTag.length),p];for(let R of k){if(await et(R)!==g.hash)continue;return{artifact:{protocol:F,id:c,scope:\"public\",strategy:\"assembly\",deps:[...new Set(g.deps)],vector:g.version,body:{shell:R}},bytes:0}}return null}async function ta(c,d,p,g){let b=g?.artifact;if(!p||!b?.hash||!Jr(c,d,p,g))return;let k=m.epoch;try{let R=await _r(p,$r);if(!R)return;let j=new TextDecoder(\"utf-8\",{fatal:!0}).decode(R),D=await ea(c,d,j,{...b,hash:b.hash});if(!D||await m.get(c)||m.epoch!==k)return;if(await m.put(D.artifact,d.persist))w.spend(c,{bytes:D.bytes,requests:0})}catch{}}async function na(c,d,p){let g=await Cn(d,p,!1);if(g.response)return w.serve(d),g.response;return Be(c,!1,{clone:!0,run:(b)=>Gr(d,p,b)})}async function ra(){try{let d=await(await v(C)).match(new Request(t.manifest));if(d){t.routes=dr(lr(JSON.parse(await d.text())));return}await Kr()}catch{Ct=void 0}}async function Kr(){let c=t.manifest,d=await e.fetch(c,{cache:\"no-store\",credentials:\"same-origin\"});if(!d.ok)throw Error(`manifest answered ${d.status}`);let p=await d.text(),g=dr(lr(JSON.parse(p)));t.routes=g,await(await v(C)).put(new Request(c),new Response(p,{headers:{\"content-type\":\"application/json\"}}));let k=[];for(let R of await m.ids()){let j=await m.get(R);if(j?.artifact.strategy!==\"static\")continue;let D=Se(g,ki(R));if(!D||j.artifact.body.version!==D.route.version)k.push(R)}return{protocol:F,cursor:m.cursor??0,changed:{},dropped:k,reset:!1}}async function Qr(c){let d=await v(qe),p=!c.headers.has(\"range\");if(p){let b=await d.match(c);if(b)return b}await T();let g=await Be(c,!1);if(p&&g.status===200&&au(g))A(d.put(c,g.clone()));return g}async function sa(c,d){if(await T(),!await Re.enqueue(c,d))return e.fetch(c);return Ro(c)}let pt=t.thirdParty,Xr=(c)=>new Request(c.url);async function oa(c){let p=await(await v(Ot)).match(Xr(c));if(p)return p;let g=await e.fetch(c);if(g.status===200&&(g.type!==\"opaque\"||pt?.allowOpaque)){let b=g.type===\"opaque\"?\"immutable\":vi(new URL(c.url),g.headers,pt?.versioned);if(b)A(Yr(c,g.clone(),b))}return g}async function Yr(c,d,p){let g=await v(Ot),b=d;if(d.type!==\"opaque\"){let D=new Headers(d.headers);D.set(at.class,p),D.set(at.fetched,String(i())),b=new Response(await d.arrayBuffer(),{status:200,headers:D})}await g.put(Xr(c),b);let k=await g.keys(),R=pt?.maxEntries??64;if(k.length<=R)return;let j=[];for(let D of k){let W=await g.match(D);j.push({key:D,at:Number(W?.headers.get(at.fetched)??0)})}j.sort((D,W)=>D.at-W.at);for(let{key:D}of j.slice(0,k.length-R))await g.delete(D)}async function ia(){if(!pt)return;let c=await v(Ot),d=pt.revalidateAfterMs??iu;for(let p of await c.keys()){let g=await c.match(p);if(!g||g.headers.get(at.class)!==\"revalidate\")continue;let b=Number(g.headers.get(at.fetched)??0);if(i()-b<d)continue;try{let k=await e.fetch(new Request(p.url,{cache:\"no-cache\",mode:\"cors\",credentials:\"omit\"}));if(k.status===200&&k.type!==\"opaque\")await Yr(p,k,\"revalidate\")}catch{}}}async function aa(c){await T();let d=Ls(t.resourceWrites??[],c.method,new URL(c.url),r);if(d)return Y(c,d);let p=Br(t,c,r);if(A(Re.flushIfDue()),p.kind===\"logout\")return await Re.sendSameOrigin(bo).catch(()=>{return}),await Ye(\"logout\"),Be(c,c.mode===\"navigate\",{signedOut:!0,run:async()=>{return}});if(p.kind===\"collector\")return sa(c,p.collector);if(p.kind===\"thirdparty\")return oa(c);if(p.kind===\"beacon\"){if(await Re.enqueue(c))return new Response(null,{status:204});return Be(c,!1)}if(p.kind===\"navigation\")return Xi(p.path,p.route,c);if(p.kind===\"static\")return na(c,p.path,p.route);if(p.kind===\"data\")return Yi(c,p.path,p.route);if(p.kind===\"asset\")return Qr(c);return Be(c,c.mode===\"navigate\")}async function ca(c){if(typeof c.addRoutes!==\"function\")return;try{await c.addRoutes([{condition:{requestMode:\"navigate\"},source:\"fetch-event\"}])}catch{}}return{replica:m,ledger:w,handle(c,d){let p=On();if(p)d(p);let g=Br(t,c,r).kind;if(g===\"ignore\")return;if(g===\"asset\"&&we!==\"cache\")return It&&Ko(h)?e.fetch(c):void 0;if(Bt&&g!==\"navigation\"&&g!==\"static\"&&c.mode!==\"navigate\")return;let b=new Set(E);if(It&&c.mode===\"navigate\"&&!S){S=!0;let R=new URL(oo(t.version),r).href,j=Xo(R,(D,W)=>e.fetch(D,W),Qo);A(j.then((D)=>{h=D}))}return(g===\"asset\"&&!x()?Qr(c):aa(c)).catch(()=>e.fetch(c)).finally(()=>d(_(b)))},async install(c){if(we===\"static-routing\")jt=await ui(c,t,r);else await ca(c);if(t.pack&&f)await ge(f,t.pack);if(t.stamp!==void 0||t.pack!==void 0)An()},async activate(){let c=On();if(c)A(c);if(await T(),t.policy!==void 0&&m.sitePolicy===void 0){let d=Go(t.policy);if(d)await m.keepPolicy(null,d)}for(let d of await e.caches.keys())if(su.some((g)=>d.startsWith(g))&&d!==qe&&d!==C)await e.caches.delete(d)},async message(c){let d=On();if(d)A(d);let p=c??{};if(p.type===\"spool:hello\")return{type:\"spool:hello\",protocol:F,version:t.version,compatible:p.protocol===F,...t.lease===void 0?{}:{lease:t.lease},...qt===0?{}:{contact:qt}};if(p.type===\"spool:status\")return await T(),{type:\"spool:status\",cursor:m.cursor,syncedAt:m.syncedAt,artifacts:await m.ids(),beacons:(await n.readBeacons()).length};if(p.type===\"spool:view\"){let g=p.path;return{type:\"spool:view\",id:typeof g===\"string\"&&ce.get(g)||null}}if(p.type===\"spool:loads\"){let{view:g,count:b,origins:k}=p;if(typeof g===\"string\"&&typeof b===\"number\"&&t.views!==!1){await T();let R=typeof k===\"object\"&&k!==null&&!Array.isArray(k)?k:void 0;await Re.record(po(g,b,i(),R))}return}if(p.type===\"spool:lifetimes\"){let g=p.count;if(typeof g===\"number\"&&Number.isSafeInteger(g)&&g>=0)ct=g;return}if(p.type===\"spool:graph\")return await T(),await m.held(),{type:\"spool:graph\",records:m.graph.records.ids(),projections:m.graph.projections.ids()};if(p.type===\"spool:ledger\")return{type:\"spool:ledger\",entries:w.entries(),totals:w.totals()};if(p.type===\"spool:partition\"){let g=await Ee();if(!g)return{type:\"spool:partition\",partition:null,artifacts:[],records:[],projections:[],datasets:[]};return await g.replica.held(),{type:\"spool:partition\",partition:g.id,artifacts:await g.replica.ids(),records:g.replica.graph.records.ids(),projections:g.replica.graph.projections.ids(),datasets:await g.replica.datasets.list()}}if(p.type===\"spool:live-state\")return qi();if(p.type===\"spool:live\"){let{partition:g,event:b,delta:k,leaseMs:R}=p;if(g!==null&&typeof g!==\"string\")return;if(b===\"revoked\")return Lt({partition:g,event:b});if(b===\"session\")return Lt({partition:null,event:b});if(b===\"lease\"&&typeof R===\"number\"&&R>0)return Lt({partition:g,event:b,leaseMs:R});if(b===\"delta\")try{return Lt({partition:g,event:b,delta:xs(k)})}catch{return}return}if(p.type===\"spool:assets\")return{type:\"spool:assets\",mode:we,routed:jt};if(p.type===\"spool:datasets\")return await T(),{type:\"spool:datasets\",datasets:await m.datasets.list(),outcomes:{...kn},refused:Object.fromEntries(lt),declined:Object.fromEntries(M),evicted:m.datasets.evicted,persisted:Lr};if(p.type===\"spool:persisted\"){Lr=p.granted===!0;return}if(p.type===\"spool:write\"){let{name:g,key:b,value:k,version:R}=p,j=await Ht();return{type:\"spool:write\",result:j instanceof Je?await j.write(typeof g===\"string\"?g:\"\",typeof b===\"string\"?b:\"\",k,R):j}}if(p.type===\"spool:flush\"){let g=await Ht();return{type:\"spool:flush\",result:g instanceof Je?{ok:!0,...await g.flush()}:g}}if(p.type===\"spool:writes\"){let g=await Ht();return{type:\"spool:writes\",result:g instanceof Je?{ok:!0,writes:await g.list()}:g}}if(p.type===\"spool:resolve\"){let{name:g,key:b,use:k}=p,R=await Ht();return{type:\"spool:resolve\",result:R instanceof Je?await R.resolve(typeof g===\"string\"?g:\"\",typeof b===\"string\"?b:\"\",k):R}}if(p.type===\"spool:held\"){let g=await v(Ot);return{type:\"spool:held\",dropped:Object.fromEntries(Re.dropped),third:(await g.keys()).map((b)=>b.url).sort()}}return}}}var cu=\"static-1\",uu=\"spool.json\";function Ei(e){return{protocol:F,version:cu,routes:[],templates:{},beacons:[],clientTag:\"\",views:!1,manifest:new URL(uu,e).href}}function Ti(e,t){let n=self,r=Ai({config:e,storage:Xt(),fetch:(s,o)=>fetch(s,o),caches,origin:n.location.origin,renderers:t,partitions:typeof indexedDB>\"u\"?void 0:Qs(),broadcast:(s)=>void n.clients.matchAll({type:\"window\",includeUncontrolled:!0}).then((o)=>o.forEach((i)=>i.postMessage(s)))});n.addEventListener(\"install\",(s)=>s.waitUntil(Promise.all([n.skipWaiting(),r.install(s)]))),n.addEventListener(\"activate\",(s)=>s.waitUntil(Promise.all([r.activate(),n.clients.claim()]))),n.addEventListener(\"fetch\",(s)=>{let o=r.handle(s.request,(i)=>s.waitUntil(i));if(o)s.respondWith(o)}),n.addEventListener(\"message\",(s)=>{s.waitUntil(r.message(s.data).then((o)=>{if(!o)return;let i=s.ports[0];if(i)i.postMessage(o);else s.source?.postMessage(o)}))})}var Di=self;Ti(Di.__SPOOL_CONFIG__??Ei(Di.location.href));})();\n";
|
|
3
3
|
/** the page runtime, generated by `bun run build:sw`; never edit by hand */
|
|
4
|
-
export declare const CLIENT_CORE = "(()=>{var R=\"data-spool-client\";function v(e=k()){return{register(t,r={}){let i=r.hiddenAfterMs??1e4,n=!0,o=!1,a=!1,u=!1,d=!1,p=null,f=(g)=>{try{t[g]()}catch(L){if(!d)d=!0,console.warn(\"spool.activity\",L)}},s=()=>{if(u)return;let g=!n||o;if(g===a)return;a=g,f(g?\"pause\":\"resume\")},c=()=>{if(p===null)return;e.clearTimeout(p),p=null},l=()=>{if(u)return;if(!e.hidden()){c(),o=!1,s();return}if(o||p!==null)return;if(i<=0){o=!0,s();return}p=e.setTimeout(()=>{if(p=null,e.hidden())o=!0,s()},i)},m=e.onVisibilityChange(l),h=r.target?e.observe(r.target,(g)=>{n=g,s()}):()=>{return};return l(),()=>{if(u)return;if(u=!0,c(),m(),h(),a)a=!1,f(\"resume\")}}}}function k(){return{hidden:()=>document.hidden,onVisibilityChange(e){return document.addEventListener(\"visibilitychange\",e),()=>document.removeEventListener(\"visibilitychange\",e)},observe(e,t){if(typeof IntersectionObserver>\"u\")return t(!0),()=>{return};let r=new IntersectionObserver((i)=>{let n=i.at(-1);if(n)t(n.isIntersecting||n.intersectionRatio>0)},{threshold:0});return r.observe(e),()=>r.disconnect()},setTimeout:(e,t)=>setTimeout(e,t),clearTimeout:(e)=>clearTimeout(e)}}function x(e,t,r=[]){let i=0;for(let{name:n}of e){if(r.includes(n))continue;try{if(new URL(n).origin!==t)i+=1}catch{continue}}return i}function S(e,t,r=[],i=32){let n=new Map;for(let{name:o}of e){if(r.includes(o))continue;try{let a=new URL(o).origin;if(a!==t&&a!==\"null\")n.set(a,(n.get(a)??0)+1)}catch{continue}}return Object.fromEntries([...n].sort((o,a)=>a[1]-o[1]||(o[0]<a[0]?-1:1)).slice(0,i))}var F=1n<<256n,D=\"0\".repeat(64);var P=1;var j={sync:\"/.spool/sync\",artifact:\"/.spool/artifact\",dataset:\"/.spool/dataset\",beacon:\"/.spool/beacon\",write:\"/.spool/write\",worker:\"/spool-sw.js\"};function E(e,t=window){let r=()=>e.close();return t.addEventListener(\"pagehide\",r),()=>t.removeEventListener(\"pagehide\",r)}var A=30000;function w(e,t,r){return new Promise((i,n)=>{let o=new MessageChannel,a=setTimeout(()=>{o.port1.close(),n(Error(\"the worker did not answer\"))},r);o.port1.onmessage=(u)=>{clearTimeout(a),o.port1.close(),i(u.data)},e.postMessage(t,[o.port2])})}async function T(e={}){let t=e.container??navigator.serviceWorker;if(!t)return null;let r=e.helloTimeoutMs??5000,i=null,n=!1,o,a=async()=>{if(n)return;n=!0;let s=e.storage??navigator.storage;try{i=await s?.persisted?.()===!0||await s?.persist?.()===!0}catch{i=!1}(e.target??window).dispatchEvent(new CustomEvent(\"spool:persisted\",{detail:{granted:i}})),(o??t.controller)?.postMessage({type:\"spool:persisted\",granted:i})};t.addEventListener?.(\"message\",(s)=>{let c=s.data;if(c?.type===\"spool:persist\")a();if(c?.type===\"spool:written\"){let{queued:l,flushed:m,conflicted:h}=c;(e.target??window).dispatchEvent(new CustomEvent(\"spool:written\",{detail:{queued:l,flushed:m,conflicted:h}}))}if(c?.type!==\"spool:cleared\")return;(e.target??window).dispatchEvent(new CustomEvent(\"spool:cleared\",{detail:{reason:c.reason}}))}),await t.register(e.workerUrl??j.worker,{scope:e.scope,updateViaCache:\"all\"});let u=await t.ready,d=u.active;if(!d)throw Error(\"the worker is not active\");o=d;let p=await w(d,{type:\"spool:hello\",protocol:P},r),f=async(s,c=r)=>{try{let l=await w(u.active??d,s,c);if(l?.type===s.type)return l.result}catch{}return{ok:!1,code:\"unavailable\",message:\"the worker did not answer\"}};return{registration:u,hello:p,status:()=>w(u.active??d,{type:\"spool:status\"},r),view:async(s=location.pathname)=>(await w(u.active??d,{type:\"spool:view\",path:s},r)).id,reportLoads:(s,c,l)=>(u.active??d).postMessage({type:\"spool:loads\",view:s,count:c,origins:l}),persisted:()=>i,track:(s)=>E(s),write:(s,c,l,m)=>f({type:\"spool:write\",name:s,key:c,value:l,version:m}),flush:()=>f({type:\"spool:flush\"},Math.max(r,A)),writes:()=>f({type:\"spool:writes\"}),resolve:(s,c,l)=>f({type:\"spool:resolve\",name:s,key:c,use:l},Math.max(r,A))}}var y=T().catch(()=>null),b={ok:!1,code:\"unavailable\",message:\"there is no worker on this page\"},C=!1,M={write:async(...e)=>{let t=await y.then((r)=>r?.write(...e)??b);if(t.ok)C=!0;return t},flush:()=>y.then((e)=>e?.flush()??b),writes:()=>y.then((e)=>e?.writes()??b),resolve:(...e)=>y.then((t)=>t?.resolve(...e)??b)};globalThis.spool={ready:y,activity:v(k()),...M};var O=()=>{if(C)M.flush()};y.then((e)=>{if(!e)return;addEventListener(\"pagehide\",O),document.addEventListener(\"visibilitychange\",()=>{if(document.visibilityState===\"hidden\")O()})});y.then(async(e)=>{let t=await e?.view().catch(()=>null);if(!e||!t)return;let r=-1,i=()=>{let n=document.querySelector(`script[${R}]`)?.src,o=performance.getEntriesByType(\"resource\"),a=x(o,location.origin,n?[n]:[]);if(a===r)return;r=a,e.reportLoads(t,a,S(o,location.origin,n?[n]:[]))};addEventListener(\"pagehide\",i),document.addEventListener(\"visibilitychange\",()=>{if(document.visibilityState===\"hidden\")i()})});})();\n";
|
|
4
|
+
export declare const CLIENT_CORE = "(()=>{var re=\"/.spool/bundle/delta/\",De={sync:\"/.spool/sync\",artifact:\"/.spool/artifact\",dataset:\"/.spool/dataset\",beacon:\"/.spool/beacon\",write:\"/.spool/write\",worker:\"/spool-sw.js\"},Ce=\"/.spool/live\",We=\"ping\",Me={held:\"spool-held\"};function Ne(e){return`/.spool/${encodeURIComponent(e)}/navigate.js`}var oe=\"spool-ring\",_e=\"spool-writes\",Le=\"spool-delta\";var ge=\"data-spool-client\";class j extends Error{code;constructor(e,t){super(t);this.name=\"ProtocolError\",this.code=e}}async function qe(e){let t=new Uint8Array(await crypto.subtle.digest(\"SHA-256\",new TextEncoder().encode(e))),n=\"\";for(let r of t)n+=String.fromCharCode(r);return btoa(n).replace(/\\+/g,\"-\").replace(/\\//g,\"_\").replace(/=+$/,\"\")}var sn=(e)=>typeof e===\"object\"&&e!==null&&!Array.isArray(e);function se(e){let t=e?.toJSON;if(typeof e===\"object\"&&typeof t===\"function\")return se(t.call(e));if(Array.isArray(e))return`[${e.map((n)=>se(n)??\"null\").join(\",\")}]`;if(sn(e)){let n=[];for(let r of Object.keys(e).sort()){let o=se(e[r]);if(o!==void 0)n.push(`${JSON.stringify(r)}:${o}`)}return`{${n.join(\",\")}}`}return JSON.stringify(e)}function z(e){return se(e)??\"null\"}var me=1n<<256n,ie=\"0\".repeat(64),an=/^[0-9a-f]{64}$/;function Q(e,t){return qe(`${e}\\x00${z(t)}`)}function Fe(e){if(!/^[A-Za-z0-9_-]{43}$/.test(e))throw RangeError(\"not a row hash\");let t=atob(e.replace(/-/g,\"+\").replace(/_/g,\"/\")+\"=\"),n=\"\";for(let r=0;r<t.length;r++)n+=t.charCodeAt(r).toString(16).padStart(2,\"0\");return BigInt(`0x${n}`)}function Ue(e){if(!an.test(e))throw RangeError(\"not a set digest\");return BigInt(`0x${e}`)}var He=(e)=>((e%me+me)%me).toString(16).padStart(64,\"0\");function ee(e,t){return He(Ue(e)+Fe(t))}function Ve(e,t){return He(Ue(e)-Fe(t))}var we=128,cn=1000,un=65536,Je=8388608,ye=1048576,Ke=-1,ln=256;var Ge=new TextEncoder,Ye=new TextDecoder,be=(e)=>new Uint8Array(Ge.encode(e));function O(e){throw new j(\"bad-bundle\",e)}var ze=(e)=>typeof e===\"number\"&&Number.isSafeInteger(e)&&e>=0,Xe=(e)=>typeof e===\"object\"&&e!==null&&!Array.isArray(e);function he(e){let t=new Uint8Array(e.reduce((r,o)=>r+o.length,0)),n=0;for(let r of e)t.set(r,n),n+=r.length;return t}async function Ze(e){let t=new Uint8Array(await crypto.subtle.digest(\"SHA-256\",e)),n=\"\";for(let r of t)n+=String.fromCharCode(r);return btoa(n).replace(/\\+/g,\"-\").replace(/\\//g,\"_\").replace(/=+$/,\"\")}async function dn(e,t){let n=new Response(e).body?.pipeThrough(t);if(!n)O(\"no body to transform\");return new Uint8Array(await new Response(n).arrayBuffer())}var fn=(e)=>dn(e,new CompressionStream(\"gzip\"));async function pn(e,t){let n=e.length-4;if(n>=0){let u=new DataView(e.buffer,e.byteOffset+n,4).getUint32(0,!0);if(u>ye)O(`${t} declares ${u} bytes, over the block cap`)}let r=new Response(e).body?.pipeThrough(new DecompressionStream(\"gzip\"));if(!r)O(\"no body to transform\");let o=r.getReader(),s=[],a=0;for(;;){let u=await o.read().catch(()=>O(`${t} does not decode`));if(u.done)break;if(a+=u.value.byteLength,a>ye)await o.cancel().catch(()=>{return}),O(`${t} is over the block cap`);s.push(new Uint8Array(u.value))}return new Uint8Array(await new Blob(s).arrayBuffer())}function et(e,t){return e<t?-1:e>t?1:0}function gn(e,t){let n=[...t].sort(([r],[o])=>et(r,o));for(let r=1;r<n.length;r++)if(n[r-1]?.[0]===n[r]?.[0])O(`${e}: key ${n[r]?.[0]} repeats`);return n}function Qe(e,t,n){let r=be(JSON.stringify({table:e,ordinal:t,bytes:n.length})),o=new Uint8Array(4);return new DataView(o.buffer).setUint32(0,r.length),he([o,r,n])}async function ke(e){let t=ie;for(let n of Object.keys(e))for(let[r,o]of e[n]??[])t=ee(t,await Q(JSON.stringify([n,r]),o));return t}async function tt(e,t=we,n=Je){if(!Number.isSafeInteger(t)||t<1)O(\"blockRows must be 1 or more\");let r=[],o=[],s=Object.keys(e.tables).filter((m)=>(e.tables[m]?.length??0)>0).sort(et);for(let[m,p]of s.entries()){let y=gn(p,e.tables[p]??[]),w=[];for(let h=0;h*t<y.length;h++){let R=y.slice(h*t,(h+1)*t),S=be(z(R));if(S.length>ye)O(`block ${p}/${h} is over the block cap`);let A=await fn(S);if(A.length>n)O(`block ${p}/${h} is over the frame cap`);w.push(await Ze(A)),r.push(Qe(m,h,A))}o.push({name:p,rows:y.length,first:y[0]?.[0]??null,blocks:w})}let a={version:e.version,codec:\"gzip\",blockRows:t,digest:await ke(e.tables),tables:o},u=Qe(Ke,0,be(z(a)));return{index:a,bytes:he([u,...r])}}async function*nt(e,t=Je){let n=e[Symbol.asyncIterator](),r=new Uint8Array(0),o=async(a)=>{while(r.length<a){let u=await n.next();if(u.done)return!1;r=he([r,u.value])}return!0},s=(a)=>{let u=r.slice(0,a);return r=r.subarray(a),u};while(await o(1)){if(!await o(4))O(\"a frame is cut short\");let a=new DataView(r.buffer,r.byteOffset,4).getUint32(0);if(a===0||a>ln)O(\"a frame header has a bad size\");if(!await o(4+a))O(\"a frame is cut short\");let u=JSON.parse(Ye.decode(r.subarray(4,4+a)));if(s(4+a),!Xe(u)||typeof u.table!==\"number\"||!Number.isSafeInteger(u.table)||u.table<Ke||!ze(u.ordinal)||!ze(u.bytes))O(\"a frame header is not { table, ordinal, bytes }\");let{table:m,ordinal:p,bytes:y}=u;if(y>t)O(\"a frame is over the frame cap\");if(!await o(y))O(\"a frame is cut short\");yield{table:m,ordinal:p,payload:s(y)}}}async function Re(e,t){let r=e.tables[t.table]?.blocks[t.ordinal];if(r===void 0)O(`no block ${t.table}/${t.ordinal} in the index`);if(await Ze(t.payload)!==r)O(`block ${t.table}/${t.ordinal} does not match its hash`);let o=await pn(t.payload,`block ${t.table}/${t.ordinal}`),s;try{s=JSON.parse(Ye.decode(o))}catch{O(`block ${t.table}/${t.ordinal} does not decode`)}if(!Array.isArray(s))O(`block ${t.table}/${t.ordinal} is not a row list`);for(let a of s)if(!Array.isArray(a)||typeof a[0]!==\"string\"||!Xe(a[1]))O(`block ${t.table}/${t.ordinal} has a row that is not [key, row]`);return s}function rt(e){let t=0;for(let n of Object.values(e.tables))t+=n.puts.length+n.deletes.length;return t>cn||Ge.encode(JSON.stringify(e)).length>un}function E(e){return new Promise((t,n)=>{e.onsuccess=()=>t(e.result),e.onerror=()=>n(e.error)})}function ot(e){return new Promise((t,n)=>{e.oncomplete=()=>t(),e.onerror=()=>n(e.error),e.onabort=()=>n(e.error)})}var mn=[\"blocks\",\"index\",\"overlay\",\"head\",\"templates\",\"predicted\"],L=\"active\",yn=-1,bn=/^[0-9a-f]{64}$/,wn=8388608,hn=new TextEncoder,kn=new TextDecoder;function x(e){throw new j(\"bad-sync\",e)}var ve=(e)=>typeof e===\"number\"&&Number.isSafeInteger(e)&&e>=0;function Rn(e){let t;try{t=JSON.parse(kn.decode(e))}catch{x(\"the index is not JSON\")}if(typeof t!==\"object\"||t===null)x(\"the index is not an object\");let n=t;if(!ve(n.version)||n.codec!==\"gzip\"||!ve(n.blockRows)||n.blockRows<1||typeof n.digest!==\"string\"||!bn.test(n.digest)||!Array.isArray(n.tables))x(\"the index has a bad version, codec, block size or digest\");let r=new Set;for(let o of n.tables){if(typeof o.name!==\"string\"||r.has(o.name)||!ve(o.rows)||o.rows<1||typeof o.first!==\"string\"||!Array.isArray(o.blocks)||o.blocks.length!==Math.ceil(o.rows/n.blockRows)||!o.blocks.every((s)=>typeof s===\"string\"))x(\"an index table does not match its rows and blocks\");r.add(o.name)}return n}function vn(e,t){let n=0,r=e.first.length-1,o=-1;while(n<=r){let s=n+r>>1;if((e.first[s]??\"\")<=t)o=s,n=s+1;else r=s-1}return o>=0&&t<=(e.last[o]??\"\")?o:-1}function st(e,t){let n=0,r=e.length-1;while(n<=r){let o=n+r>>1,s=e[o];if(s?.[0]===t)return s[1];if((s?.[0]??\"\")<t)n=o+1;else r=o-1}return}async function Sn(e){let t=new Uint8Array(await crypto.subtle.digest(\"SHA-256\",e)),n=\"\";for(let r of t)n+=String.fromCharCode(r);return btoa(n).replace(/\\+/g,\"-\").replace(/\\//g,\"_\").replace(/=+$/,\"\")}async function xn(e){let t=new Response(e).body?.pipeThrough(new CompressionStream(\"gzip\"));if(!t)x(\"no body to compress\");return new Uint8Array(await new Response(t).arrayBuffer())}async function*Pn(e){yield e}function ae(e){let t=new Map;for(let[n,r,o]of e){let s=t.get(n)??[];s.push([r,o]),t.set(n,s)}return t}function An(e,t){let n=new Map(e);for(let[r,o]of t)n.set(r,o);return[...n].sort(([r],[o])=>r<o?-1:1)}function it(e){let t={};for(let[n,r]of e)t[n]={puts:r.flatMap(([o,s])=>s===null?[]:[[o,s]]),deletes:r.flatMap(([o,s])=>s===null?[o]:[])};return t}async function En(){return globalThis.navigator?.storage?.estimate()}function at(e=indexedDB,t={}){let n=t.name??\"spool-bundle\",r=t.estimate??En,o={blockReads:0,blockInflates:0,overlayReads:0},s=new Map,a,u=Promise.resolve(),m=()=>a??=new Promise((i,c)=>{let f=e.open(n,2);f.onupgradeneeded=()=>{for(let d of mn)if(!f.result.objectStoreNames.contains(d))f.result.createObjectStore(d)},f.onsuccess=()=>{let d=f.result;d.onversionchange=()=>{d.close(),a=void 0},i(d)},f.onerror=()=>c(f.error)});async function p(i,c,f){let l=(await m()).transaction(i,c),b=ot(l);b.catch(()=>{return});try{let g=await f(l);return await b,g}catch(g){try{l.abort()}catch{}throw g}}let y=(i)=>{let c=u.then(i);return u=c.catch(()=>{return}),c},w=()=>p([\"head\",\"predicted\"],\"readonly\",async(i)=>{let c=await E(i.objectStore(\"head\").get(L));if(!c)return;return{...c,unconfirmed:await E(i.objectStore(\"predicted\").count())}}),h=(i,c)=>p([\"index\"],\"readonly\",(f)=>E(f.objectStore(\"index\").get([i,c])));async function R(i,c,f=\"overlay\"){let d=i.objectStore(f),[l,b]=await Promise.all([E(d.getAllKeys(c)),E(d.getAll(c))]);if(f===\"overlay\")o.overlayReads+=l.length;return l.map((g,k)=>{let[v,P]=g;return[v,P,b[k]]})}function S(i,c,f,d,l){return o.blockInflates++,Re({version:i.version,codec:\"gzip\",blockRows:i.blockRows,digest:i.digest,tables:[{name:c,rows:f.rows,first:f.first[0]??null,blocks:f.hashes}]},{table:0,ordinal:d,payload:l})}async function A(i,c,f,d){let l=await p([\"head\",\"blocks\"],\"readonly\",async(b)=>{if((await E(b.objectStore(\"head\").get(L)))?.generation!==i.generation)x(\"the pack changed during a read\");return o.blockReads++,E(b.objectStore(\"blocks\").get([i.generation,c,d]))});if(!l)x(`block ${c}/${d} is missing`);return S(i,c,f,d,l)}async function*I(i,c,f,d){let l=c?.hashes.length??0,b=0;for(let g=0;g<=l;g++){let k=c&&g<l,v=k?await A(i,f,c,g):[],P=k?c.last[g]:void 0,T=0;for(;;){let B=d[b],W=v[T];if(B&&(P===void 0||B[0]<=P)&&(!W||B[0]<=W[0])){if(b++,W&&W[0]===B[0])T++;if(B[1]!==null)yield[B[0],B[1]]}else if(W)T++,yield W;else break}}}async function C(i,c,f){return p([\"head\",\"index\",\"overlay\",\"predicted\",\"blocks\"],\"readonly\",async(d)=>{let l=await E(d.objectStore(\"head\").get(L));if(!l)return;if(f){let B=await E(d.objectStore(\"predicted\").get([i,c]));if(B!==void 0)return B??void 0}o.overlayReads++;let b=await E(d.objectStore(\"overlay\").get([i,c]));if(b!==void 0)return b??void 0;if(!l.tables.includes(i))return;let g=await E(d.objectStore(\"index\").get([l.generation,i])),k=g?vn(g,c):-1;if(!g||k<0)return;let v=s.get(i);if(v?.generation===l.generation&&v.ordinal===k)return st(v.rows,c);let P=await E(d.objectStore(\"blocks\").get([l.generation,i,k]));if(o.blockReads++,!P)x(`block ${i}/${k} is missing`);let T=await S(l,i,g,k,P);return s.set(i,{generation:l.generation,ordinal:k,rows:T}),st(T,c)})}let X=(i,c)=>C(i,c,!0);async function Z(i){let c=await p([\"head\",\"index\",\"overlay\",\"predicted\"],\"readonly\",async(d)=>{let l=await E(d.objectStore(\"head\").get(L));if(!l)return;let b=l.tables.includes(i)?await E(d.objectStore(\"index\").get([l.generation,i])):void 0,g=IDBKeyRange.bound([i],[i,[]]),k=await R(d,g),v=await R(d,g,\"predicted\"),P=An(ae(k).get(i)??[],ae(v).get(i)??[]);return{head:l,record:b,changes:P}});if(!c)return[];let f=[];for await(let d of I(c.head,c.record,i,c.changes))f.push(d);return f}function M(i){return p([\"blocks\",\"index\"],\"readwrite\",(c)=>{let f=IDBKeyRange.lowerBound([i]);c.objectStore(\"blocks\").delete(f),c.objectStore(\"index\").delete(f)})}function V(i,c){return s.clear(),p([\"head\",\"blocks\",\"index\",\"overlay\",\"predicted\"],\"readwrite\",async(f)=>{if((await E(f.objectStore(\"head\").get(L)))?.generation!==i?.generation)x(\"the head moved during a swap\");if(i){let l=IDBKeyRange.bound([i.generation],[i.generation,[]]);f.objectStore(\"blocks\").delete(l),f.objectStore(\"index\").delete(l)}f.objectStore(\"overlay\").clear(),f.objectStore(\"predicted\").clear(),f.objectStore(\"head\").put(c,L)})}async function Qt(i,c,f){let d,l=[],b=0,g=0,k=0,v=0,P=0,T,B=ie;for await(let N of nt(i)){if(!d){if(N.table!==yn)x(\"the pack does not start with its index\");if(d=Rn(N.payload),f&&d.version<f.version)x(`the pack is version ${d.version}, the head holds ${f.version}`);for(let F of d.tables)l.push({rows:F.rows,first:[],last:[],hashes:[]});continue}let D=d.tables[b];if(!D||N.table!==b||N.ordinal!==g)x(`expected block ${b}/${g}, got ${N.table}/${N.ordinal}`);let _=await Re(d,N),rn=Math.min(d.blockRows,D.rows-g*d.blockRows);if(_.length!==rn)x(`block ${b}/${g} holds ${_.length} rows`);if(g===0)T=void 0;for(let[F,on]of _){if(T!==void 0&&T>=F)x(`${D.name}: key ${F} is out of order`);T=F,B=ee(B,await Q(JSON.stringify([D.name,F]),on))}let $e=_[0]?.[0]??\"\";if(g===0&&$e!==D.first)x(`${D.name}: wrong first key`);if(l[b]?.first.push($e),l[b]?.last.push(_[_.length-1]?.[0]??\"\"),l[b]?.hashes.push(D.blocks[g]??\"\"),await p([\"blocks\"],\"readwrite\",(F)=>E(F.objectStore(\"blocks\").put(N.payload,[c,D.name,g]))),k+=_.length,v+=_.length,P++,g+1<D.blocks.length){g++;continue}if(k!==D.rows)x(`${D.name}: ${k} rows, the index says ${D.rows}`);b++,g=0,k=0}if(!d)x(\"the pack is empty\");if(b!==d.tables.length)x(\"the pack ends before its last block\");if(B!==d.digest)x(\"the set digest does not match\");let W=d;return await p([\"index\"],\"readwrite\",(N)=>{W.tables.forEach((D,_)=>N.objectStore(\"index\").put(l[_],[c,D.name]))}),{index:W,rows:v,blocks:P}}async function Oe(i){let c=await r();if(c?.quota===void 0)return{checked:!1,fits:!0};let f=c.usage??0;if(f+i+wn<=c.quota)return{checked:!0,fits:!0};return{checked:!0,fits:!1,bytes:i,usage:f,quota:c.quota}}async function je(i){let c=await w(),f=(c?.generation??0)+1;await M(f);try{let{index:d,rows:l,blocks:b}=await Qt(i,f,c);return await V(c,{version:d.version,digest:d.digest,generation:f,blockRows:d.blockRows,codec:\"gzip\",tables:d.tables.map((g)=>g.name)}),{installed:!0,version:d.version,tables:d.tables.length,rows:l,blocks:b}}catch(d){throw await M(f),d}}function Jt(i,c={}){return y(async()=>{if(c.bytes!==void 0){let f=await Oe(c.bytes);if(!f.fits)return{installed:!1,fit:f}}return je(i)})}function Kt(i){return y(async()=>{let c=await w();if(c&&i.version<c.version)return{installed:!1,reason:\"older\"};if(c&&!c.partial&&i.version===c.version)return{installed:!1,reason:\"held\"};let f=Object.values(i.tables).reduce((l,b)=>l+b.length,0);if(i.complete){if(await ke(i.tables)!==i.digest)x(\"the ring digest does not match its rows\");let{bytes:l}=await tt({version:i.version,tables:i.tables});if(i.routes)await pe(i.routes,i.templates);let{version:b,rows:g}=await je(Pn(l));return{installed:!0,version:b,rows:g,complete:!0}}if(i.routes)await pe(i.routes,i.templates);let d=(c?.generation??0)+1;return await p([\"head\",\"blocks\",\"index\",\"overlay\",\"predicted\"],\"readwrite\",async(l)=>{if((await E(l.objectStore(\"head\").get(L)))?.generation!==c?.generation)x(\"the head moved during a ring\");if(c){let g=IDBKeyRange.bound([c.generation],[c.generation,[]]);l.objectStore(\"blocks\").delete(g),l.objectStore(\"index\").delete(g)}l.objectStore(\"overlay\").clear(),l.objectStore(\"predicted\").clear();for(let[g,k]of Object.entries(i.tables))for(let[v,P]of k)l.objectStore(\"overlay\").put(P,[g,v]);l.objectStore(\"head\").put({version:i.version,digest:i.digest,generation:d,blockRows:we,codec:\"gzip\",tables:Object.keys(i.tables),partial:!0},L)}),s.clear(),{installed:!0,version:i.version,rows:f,complete:!1}})}function Gt(i){return y(()=>Ie(i))}async function Ie(i){let c=await w();if(!c)x(\"no pack is installed\");if(c.partial)x(\"the held pack is partial; install the pack first\");if(c.version!==i.from)x(`the delta starts at ${i.from}, the store holds ${c.version}`);if(i.to<i.from)x(`the delta ends at ${i.to}, before it starts at ${i.from}`);let f=async(l,b,g)=>{let k=await C(b,g,!1);if(k===void 0)return l;return Ve(l,await Q(JSON.stringify([b,g]),k))},d=c.digest;for(let[l,b]of Object.entries(i.tables)){for(let g of b.deletes)d=await f(d,l,g);for(let[g,k]of b.puts)d=ee(await f(d,l,g),await Q(JSON.stringify([l,g]),k))}if(d!==i.digest)x(\"the candidate digest does not match the delta\");await p([\"head\",\"overlay\",\"predicted\"],\"readwrite\",async(l)=>{let b=l.objectStore(\"predicted\");for(let[k,v]of Object.entries(i.tables)){for(let P of v.deletes)b.delete([k,P]);for(let[P]of v.puts)b.delete([k,P])}if(i.to!==i.from)b.clear();let g=await E(l.objectStore(\"head\").get(L));if(!g||g.version!==c.version||g.digest!==c.digest)x(\"the base moved during a delta\");for(let[k,v]of Object.entries(i.tables)){for(let P of v.deletes)l.objectStore(\"overlay\").put(null,[k,P]);for(let[P,T]of v.puts)l.objectStore(\"overlay\").put(T,[k,P])}l.objectStore(\"head\").put({...g,version:i.to,digest:i.digest},L)})}function Yt(i){return y(async()=>{if(!await w())return;await p([\"predicted\"],\"readwrite\",(c)=>{let f=c.objectStore(\"predicted\");for(let[d,l,b]of i.puts)f.put(b,[d,l]);for(let[d,l]of i.deletes)f.put(null,[d,l])})})}function Xt(i,c){return y(async()=>{let f=await w();if(!f)x(\"no pack is installed\");let d=await p([\"predicted\"],\"readonly\",(l)=>R(l,IDBKeyRange.lowerBound([\"\"]),\"predicted\"));await Ie({from:f.version,to:i,digest:c,tables:it(ae(d))})})}function Zt(){return y(()=>p([\"predicted\"],\"readwrite\",(i)=>{i.objectStore(\"predicted\").clear()}))}function en(){return y(async()=>{let i=await w();if(!i||i.partial||i.unconfirmed>0)return!1;let c=ae(await p([\"overlay\"],\"readonly\",(l)=>R(l,IDBKeyRange.lowerBound([\"\"])))),f={from:i.version,to:i.version,digest:i.digest,tables:it(c)};if(!rt(f))return!1;let d=i.generation+1;await M(d);try{let l=[];for(let b of[...new Set([...i.tables,...c.keys()])].sort()){let g=i.tables.includes(b)?await h(i.generation,b):void 0,k={rows:0,first:[],last:[],hashes:[]},v=[],P=async()=>{let T=await xn(new Uint8Array(hn.encode(z(v)))),B=k.hashes.length;k.first.push(v[0]?.[0]??\"\"),k.last.push(v[v.length-1]?.[0]??\"\"),k.hashes.push(await Sn(T)),k.rows+=v.length,await p([\"blocks\"],\"readwrite\",(W)=>E(W.objectStore(\"blocks\").put(T,[d,b,B]))),v=[]};for await(let T of I(i,g,b,c.get(b)??[]))if(v.push(T),v.length===i.blockRows)await P();if(v.length>0)await P();if(k.rows>0)l.push(b),await p([\"index\"],\"readwrite\",(T)=>E(T.objectStore(\"index\").put(k,[d,b])))}return await V(i,{version:i.version,digest:i.digest,generation:d,blockRows:i.blockRows,codec:\"gzip\",tables:l}),!0}catch(l){throw await M(d),l}})}function pe(i,c={}){return p([\"templates\"],\"readwrite\",(f)=>{let d=f.objectStore(\"templates\");d.clear(),i.forEach((l,b)=>{let g=c[l.pattern];d.put(g?{order:b,route:l,template:g}:{order:b,route:l},l.pattern)})})}async function Be(){return(await p([\"templates\"],\"readonly\",(c)=>E(c.objectStore(\"templates\").getAll()))).sort((c,f)=>c.order-f.order)}async function tn(){return(await Be()).map((i)=>i.route)}async function nn(){let i={};for(let{route:c,template:f}of await Be())if(f)i[c.pattern]=f;return i}return{counters:o,head:w,recordCounts:()=>p([\"blocks\",\"index\",\"overlay\",\"head\"],\"readonly\",async(i)=>{let c=(g)=>E(i.objectStore(g).count()),[f,d,l,b]=await Promise.all([c(\"blocks\"),c(\"index\"),c(\"overlay\"),c(\"head\")]);return{blocks:f,index:d,overlay:l,head:b}}),installPack:Jt,installRing:Kt,estimateBeforeInstall:Oe,applyDelta:Gt,applyPredicted:Yt,confirmPredicted:Xt,dropPredicted:Zt,getRow:X,scanTable:Z,compact:en,putRoutes:pe,getRoutes:tn,getTemplates:nn}}var ct=\"1.0.0\";function ut(e=Se()){return{register(t,n={}){let r=n.hiddenAfterMs??1e4,o=!0,s=!1,a=!1,u=!1,m=!1,p=null,y=(I)=>{try{t[I]()}catch(C){if(!m)m=!0,console.warn(\"spool.activity\",C)}},w=()=>{if(u)return;let I=!o||s;if(I===a)return;a=I,y(I?\"pause\":\"resume\")},h=()=>{if(p===null)return;e.clearTimeout(p),p=null},R=()=>{if(u)return;if(!e.hidden()){h(),s=!1,w();return}if(s||p!==null)return;if(r<=0){s=!0,w();return}p=e.setTimeout(()=>{if(p=null,e.hidden())s=!0,w()},r)},S=e.onVisibilityChange(R),A=n.target?e.observe(n.target,(I)=>{o=I,w()}):()=>{return};return R(),()=>{if(u)return;if(u=!0,h(),S(),A(),a)a=!1,y(\"resume\")}}}}function Se(){return{hidden:()=>document.hidden,onVisibilityChange(e){return document.addEventListener(\"visibilitychange\",e),()=>document.removeEventListener(\"visibilitychange\",e)},observe(e,t){if(typeof IntersectionObserver>\"u\")return t(!0),()=>{return};let n=new IntersectionObserver((r)=>{let o=r.at(-1);if(o)t(o.isIntersecting||o.intersectionRatio>0)},{threshold:0});return n.observe(e),()=>n.disconnect()},setTimeout:(e,t)=>setTimeout(e,t),clearTimeout:(e)=>clearTimeout(e)}}function xe(e){if(/\\b(?:CriOS|FxiOS|EdgiOS|OPiOS)\\//.test(e))return\"webkit\";if(/\\bFirefox\\//.test(e))return\"firefox\";if(/(?:Chrome|Chromium)\\//.test(e))return\"chromium\";if(/\\bSafari\\//.test(e))return\"webkit\";return\"other\"}function lt(e,t,n){return[...e.split(\",\").filter(Boolean).map(Number).filter((r)=>r>=0&&r<=t&&t-r<n),t].slice(-3)}async function ce(e){try{return await e?.persisted?.()===!0||await e?.persist?.()===!0}catch{return!1}}var Tn=\"spool:views\",dt=\"spool:stamps\",ft=\"spool:lifetimes\",On=\"spool:boot\",jn=604800;function In(e){let t=e;return typeof t===\"object\"&&t!==null&&typeof t.url===\"string\"&&Number.isSafeInteger(t.bytes)}function Pe(e){if(!e)return null;let t;try{t=JSON.parse(e)}catch{return null}if(typeof t!==\"object\"||t===null||Array.isArray(t))return null;let n=t;return n.protocol===1&&Number.isSafeInteger(n.version)&&typeof n.digest===\"string\"&&(n.routes===void 0||Array.isArray(n.routes))&&(n.templates===void 0||typeof n.templates===\"object\"&&n.templates!==null&&!Array.isArray(n.templates))&&typeof n.tables===\"object\"&&n.tables!==null&&!Array.isArray(n.tables)&&typeof n.complete===\"boolean\"&&(n.bootstrap===\"first-view\"||n.bootstrap===\"second-view\")&&(n.worker===\"auto\"||n.worker===\"never\")&&(n.pack===void 0?n.complete===!0:In(n.pack))&&(n.writes===void 0||Array.isArray(n.writes))&&(n.lease===void 0||Number.isSafeInteger(n.lease))?t:null}function pt(e,t){try{let n=Number(e?.getItem(t)??0),r=(Number.isSafeInteger(n)&&n>=0?n:0)+1;return e?.setItem(t,String(r)),r}catch{return 1}}function Bn(e,t,n){if(!((n??0)>0))return t;try{let r=lt(e?.getItem(dt)??\"\",Date.now(),(n??0)*1000);return e?.setItem(dt,r.join()),r.length}catch{return 1}}function $n(e){try{return(e??document).getElementById(oe)?.textContent}catch{return null}}function Dn(e){try{let t=(e??document).getElementById(Le);if(!t)return;let n=Number(t.getAttribute(\"data-from\")),r=Number(t.getAttribute(\"data-to\"));if(!Number.isSafeInteger(n)||!Number.isSafeInteger(r)||r<=n)return;return{from:n,to:r,text:t.textContent??\"\"}}catch{return}}function Cn(e,t,n){if(t)return t.worker===\"never\"||t.webkitWorker!==!0&&xe(n)===\"webkit\";try{return(e??document).querySelector?.('script[data-spool-worker=\"never\"]')!=null}catch{return!1}}function Wn(){try{return localStorage}catch{return null}}function Mn(e){try{let t=Number(e?.getItem(ft)??0);if(Number.isSafeInteger(t)&&t>0)navigator.serviceWorker?.controller?.postMessage({type:\"spool:lifetimes\",count:t})}catch{}}function Nn(e,t,n,r,o){if(!e)return{pack:!1,worker:!n};let s=e.bootstrap===\"second-view\";return{pack:!e.complete&&(r||t>=(s?2:1)),worker:!n&&(o||t>=(s?3:1))}}async function*_n(e){let t=e.getReader();for(;;){let{done:n,value:r}=await t.read();if(n)return;yield r}}async function*Ln(e){let t=atob(e),n=new Uint8Array(t.length);for(let r=0;r<t.length;r++)n[r]=t.charCodeAt(r);yield n}async function qn(e,t,n,r){let{store:o}=e;try{let s=await o.head();if(s&&s.partial!==!0&&s.version>=n.version){if(s.version===n.version&&n.routes)await o.putRoutes(n.routes,n.templates);return s.version}let a=await o.installRing(n);if(n.complete)return a?.installed?n.version:void 0;if(!r||!n.pack)return;if(!(await o.estimateBeforeInstall(n.pack.bytes)).fits)return;let m;if(e.pack?.version===n.version)m=Ln(e.pack.data);else{let y=await(e.fetch??fetch)(n.pack.url);if(!y.ok||!y.body)return;m=_n(y.body)}if(!(await o.installPack(m,{bytes:n.pack.bytes})).installed)return;if(n.routes)await o.putRoutes(n.routes,n.templates);if(pt(t,ft),xe(e.userAgent??navigator.userAgent)===\"chromium\")await ce(e.manager??navigator.storage);return n.version}catch{return}}function Fn(e,t){if(e.routes&&e.templates)return e;let n=/[?&]r=([0-9a-f]+)/.exec(e.boot??\"\")?.[1];if(!t||n===void 0||t.id!==n)return;return{...e,routes:t.routes,templates:t.templates}}async function Un(e,t){let{store:n}=e,r=await n.head();if(!r||r.partial===!0||r.version!==t.from)return;let o=t.text?JSON.parse(t.text):void 0;if(!o){let s=await(e.fetch??fetch)(`${re}${t.from}/${t.to}`);if(!s.ok)return;o=await s.json()}return await n.applyDelta(o),t.to}function Ae(e,t){let n=`${Me.held}=${t}; path=/; max-age=${jn}; samesite=lax`;try{if(e.cookie)e.cookie(n);else document.cookie=n}catch{}}async function Hn(e,t,n,r,o){let s;try{let a=Dn(e.doc);if(a)s=await Un(e,a);if(n)s=await qn(e,t,n,r)??s;if(s===void 0){let u=await e.store.head();if(u&&u.partial!==!0)s=u.version}if(o&&s!==void 0)Ae(e,s)}catch{}}function gt(e){let t=e.storage===void 0?Wn():e.storage,n=pt(t,Tn);Mn(t);let r=Pe($n(e.doc)),o=r&&Fn(r,e.shape),s=r===null||o!==void 0;if(!s)try{t?.setItem(On,\"\")}catch{}let a=Cn(e.doc,r,e.userAgent??(typeof navigator>\"u\"?\"\":navigator.userAgent)),u=Nn(r,Bn(t,n,r?.lease),a,r!==null&&e.pack?.version===r.version,e.router===!0),m=Hn(e,t,o??null,u.pack,a);return{worker:u.worker,installed:m,current:s}}var J=1;function U(e){throw new j(\"bad-sync\",e)}function yt(e){if(typeof e!==\"object\"||e===null)return U(\"sync response must be an object\");let t=e;if(t.protocol!==J)return U(\"unsupported protocol version\");let{cursor:n,changed:r,dropped:o,reset:s,partial:a}=t;if(typeof n!==\"number\"||!Number.isSafeInteger(n)||n<0)return U(\"cursor must be a non-negative integer\");if(typeof r!==\"object\"||r===null||Array.isArray(r))return U(\"changed must be an object\");for(let m of Object.values(r))if(typeof m!==\"number\"||!Number.isSafeInteger(m))return U(\"changed versions must be integers\");if(!Array.isArray(o)||o.some((m)=>typeof m!==\"string\"))return U(\"dropped must be a list of strings\");if(typeof s!==\"boolean\")return U(\"reset must be a boolean\");if(a!==void 0&&typeof a!==\"boolean\")return U(\"partial must be a boolean\");let u={protocol:J,cursor:n,changed:r,dropped:o,reset:s};if(a)u.partial=!0;return u}var te={protocol:\"spool-protocol\",artifact:\"spool-artifact\",invalidate:\"spool-invalidate\",clear:\"spool-clear\",vector:\"spool-vector\",partition:\"spool-partition\",vectorSeen:\"spool-vector-seen\",provision:\"spool-provision\",provisionReason:\"spool-provision-reason\",delta:\"spool-delta\",have:\"spool-have\"};function Vn(e){throw new j(\"bad-header\",e)}function bt(e){let t=yt(e),n=e.from;if(typeof n!==\"number\"||!Number.isSafeInteger(n)||n<0)return Vn(\"from must be a non-negative integer\");return{...t,from:n}}function Ee(e){let t=e.length>1&&e.endsWith(\"/\")?e.slice(0,-1):e;return t===\"/\"?[]:t.slice(1).split(\"/\")}function ne(e,t){let n=Ee(e),r=Ee(t),o=n[n.length-1]===\"**\";if(o)n.pop();if(o?r.length<n.length:n.length!==r.length)return null;let s={};for(let a=0;a<n.length;a++){let u=n[a],m=r[a];if(u.startsWith(\":\")){if(m===\"\")return null;try{s[u.slice(1)]=decodeURIComponent(m)}catch{return null}}else if(u!==m)return null}return s}function wt(e,t){return`/${Ee(e).map((r)=>{if(r===\"**\")throw new j(\"bad-pattern\",`${e} has no single path to fill`);if(!r.startsWith(\":\"))return r;let o=t[r.slice(1)];if(o===void 0)throw new j(\"bad-pattern\",`missing parameter \"${r.slice(1)}\" for ${e}`);return encodeURIComponent(o)}).join(\"/\")}`}var ht={id:\"spool-write-id\",digest:\"spool-write-digest\"};var kt={\"writes-off\":403,\"unknown-write\":404,\"bad-method\":405,\"bad-key\":400,\"missing-version\":428,\"bad-version\":400,\"bad-id\":400,\"bad-body\":400,\"too-large\":413,\"too-many\":429,\"id-reused\":422,forbidden:403,\"sign-in\":401,\"no-partition\":409,\"no-record\":404,\"not-conflicted\":409,unavailable:503};var Rt=(e)=>typeof e===\"object\"&&e!==null&&!Array.isArray(e),Qn=(e)=>Rt(e)&&Object.keys(e).length===1&&typeof e.body===\"string\";function Jn(e,t){let n=e;for(let r of t.split(\".\")){if(!Rt(n)||!Object.prototype.hasOwnProperty.call(n,r))return;n=n[r]}return n}function vt(e,t,n){let r={...e};for(let[o,s]of Object.entries(n.set??{})){if(!Qn(s)){r[o]=structuredClone(s);continue}let a=Jn(t,s.body);if(a===void 0)return;r[o]=a}for(let[o,s]of Object.entries(n.inc??{})){let a=r[o]===void 0?0:r[o];if(typeof a!==\"number\")return;r[o]=a+s}for(let o of n.unset??[])delete r[o];return r}function St(e,t,n,r){return e.find((o)=>o.method===t&&ne(o.pattern,n.pathname)!==null&&n.origin===(o.origin??r))}function Kn(e,t){let n=e.split(\"/\");return!n.includes(\"**\")&&n.every((r)=>!r.startsWith(\":\")||r===`:${t}`)}function xt(e){let t=[],n=new Map;for(let r of e){if(r.scope!==\"public\")continue;if(r.family&&Kn(r.pattern,r.family.key))t.push({dataset:r.family.dataset,pattern:r.pattern,key:r.family.key});let o=r.query;if(o?.dataset!==void 0&&o.plan===void 0){let s=n.get(o.dataset)??new Set;n.set(o.dataset,s);for(let a of[...Object.keys(o.filter??{}),...o.sort??[]])s.add(a)}}return{paths:t,fields:new Map([...n].map(([r,o])=>[r,[...o]]))}}function Pt(e,t,n,r){let o=[];for(let a of e.paths){if(a.dataset!==t)continue;let u=wt(a.pattern,{[a.key]:n});o.push([`path:${t}`,u,r===void 0?null:{key:n}])}let s=e.fields.get(t);if(s!==void 0)o.push([`query:${t}`,n,r===void 0?null:Gn(r,s)]);return o}function Gn(e,t){return Object.fromEntries(t.filter((n)=>Object.hasOwn(e,n)).map((n)=>[n,e[n]]))}var jo=new Set(Object.keys(kt));var At=(e)=>typeof e===\"object\"&&e!==null&&!Array.isArray(e);function Te(e,t,n,r){let o=[[t,n,r??null],...Pt(e,t,n,r)];return{puts:o.flatMap(([s,a,u])=>u===null?[]:[[s,a,u]]),deletes:o.flatMap(([s,a,u])=>u===null?[[s,a]]:[])}}async function Et(e,t,{write:n,url:r,body:o,routes:s}){let a=xt(s),u=ne(n.pattern,r.pathname)?.[n.key],{dataset:m}=n;if(n.apply===\"invalidate\")return;if(n.apply===\"delete\"){if(u!==void 0)await t.applyPredicted(Te(a,m,u));return}if(n.apply===\"response\"){let w=await e.clone().json().catch(()=>{return});if(!At(w))return;let h=w[n.key];if(typeof h!==\"string\"&&typeof h!==\"number\")return;let R=String(h);if(u!==void 0&&u!==R)return;await t.applyPredicted(Te(a,m,R,w));return}if(u===void 0)return;let p=await t.getRow(m,u);if(!p)return;let y=n.apply===\"merge\"?At(o)?{...p,...o}:void 0:vt(p,o,n.apply);if(y)await t.applyPredicted(Te(a,m,u,y))}async function Tt(e,t,n,r,o){if(!e.url||new URL(e.url).origin!==r)return;let s=await t.head();if(!s)return;let a=e.headers.get(te.delta),u=a===null?void 0:JSON.parse(a);if(u?.from===s.version)try{await t.applyDelta(u);return}catch{}let m=e.headers.get(te.vector),p=u?.to??(m===null?void 0:Number(m));if(p===void 0){if(o)await Et(e,t,o);return}if(!Number.isSafeInteger(p)||p<=s.version)return;let y=e.headers.get(ht.digest);if(u===void 0&&o&&y!==null){await Et(e,t,o);try{await t.confirmPredicted(p,y);return}catch{await t.dropPredicted()}}await t.applyDelta(await n(s.version,p))}function Ot(e){if(!e)return[];try{let t=JSON.parse(e);return Array.isArray(t)?t:[]}catch{return[]}}function jt(e){let t=e.fetch??fetch,{store:n,writes:r,origin:o}=e,s=async(a,u)=>{let m=await t(`${o}${re}${a}/${u}`,{credentials:\"same-origin\"});if(!m.ok)throw Error(`delta answered ${m.status}`);return await m.json()};return async(a,u)=>{let m=new URL(a instanceof Request?a.url:String(a),o),p=a instanceof Request?a:void 0,y=(u?.method??p?.method??\"GET\").toUpperCase(),w=St(r,y,m,o);if(!w)return t(a,u);let h=await n.head(),R=new Headers(u?.headers??p?.headers);if(h&&h.partial!==!0)R.set(te.have,String(h.version));let S=typeof u?.body===\"string\"?u.body:void 0,A=await t(m.href,{...u,method:y,headers:R,body:S,cache:\"no-store\",credentials:\"same-origin\"});if(A.ok){let I=S===void 0?void 0:JSON.parse(S);await Tt(A,n,s,w.origin??o,{write:w,url:m,body:I,routes:await n.getRoutes()}).catch(()=>{return});let C=await n.head();if(C&&C.partial!==!0)Ae(e,C.version)}return A}}var Yn=\"spool-live\",Bt=2;function It(e,t){try{return t(JSON.parse(e))}catch{return}}function $t(e){let t,n=!1,r,o=null;function s(){r?.abort(),r=void 0,t?.release()}function a(){if(t||r||!e.visible()||!e.locks)return;let p=new AbortController;r=p,e.locks.request(Yn,{signal:p.signal},()=>u(p)).catch(()=>{return}).finally(()=>{if(r===p)r=void 0})}async function u(p){if(r===p)r=void 0;if(p.signal.aborted)return;let y=await e.state().catch(()=>{return});if(!y?.live||!e.visible())return;if(y.live.mode===\"adaptive\"&&!n){e.send({partition:null,event:\"session\"});return}let{partition:w,have:h}=y;if(w!==o)o=null;if(w===null?!y.live.public:w===o)return;await new Promise((R)=>{let S=[...w===null?[]:[`partition=${encodeURIComponent(w)}`],...h===null?[]:[`have=${h}`]].join(\"&\"),A=e.open(`${Ce}${S?`?${S}`:\"\"}`,y.live?.socket===!0),I=!1,C=()=>{if(A.close(),t=void 0,R(),I)a()},X=()=>{I=!0,C()};t={release:C,reopen:X},A.addEventListener(\"delta\",(Z)=>{let M=It(Z.data,bt);if(!M)return;e.send({partition:w,event:\"delta\",delta:M}).then((V)=>{if(V&&!V.ok)X()})}),A.addEventListener(\"lease\",(Z)=>{let M=It(Z.data,(V)=>V.leaseMs);if(typeof M===\"number\")e.send({partition:w,event:\"lease\",leaseMs:M})}),A.addEventListener(\"revoked\",()=>{o=w,e.send({partition:w,event:\"revoked\"}).finally(X)}),A.addEventListener(\"error\",()=>{if(A.readyState===Bt)C()})})}function m(){n=!1,s()}return e.onVisibility(()=>e.visible()?a():m()),e.onPageHide(m),a(),{reconcile:()=>t?t.reopen():a(),arm(){n=!0,a()}}}var Xn=25000,Zn=3000;function er(e,t){let n=new Map,r,o,s,a,u=!1;function m(){let y=t.socket(e);r=y;let w=!1;y.addEventListener(\"open\",()=>{w=!0,a=setInterval(()=>y.send(We),Xn)}),y.addEventListener(\"message\",(h)=>{if(typeof h.data!==\"string\")return;let R=/^event: (.*)$/m.exec(h.data)?.[1],S=/^data: (.*)$/m.exec(h.data)?.[1];if(R===void 0||S===void 0)return;for(let A of n.get(R)??[])A({data:S})}),y.addEventListener(\"close\",()=>{if(clearInterval(a),u||r!==y)return;if(!w)return p();s=setTimeout(m,Zn)})}function p(){r=void 0,o=t.events(e);for(let[y,w]of n)for(let h of w)o.addEventListener(y,h)}return m(),{get readyState(){if(o)return o.readyState;if(u)return Bt;return r?.readyState===1?1:0},addEventListener(y,w){n.set(y,[...n.get(y)??[],w]),o?.addEventListener(y,w)},close(){u=!0,clearTimeout(s),clearInterval(a),r?.close(),o?.close()}}}function Dt(e){if(typeof EventSource>\"u\")return null;return{state:()=>e.liveState(),send:(t)=>e.liveEvent(t),visible:()=>document.visibilityState===\"visible\",onVisibility:(t)=>{document.addEventListener(\"visibilitychange\",t),addEventListener(\"pageshow\",t)},onPageHide:(t)=>addEventListener(\"pagehide\",t),locks:navigator.locks,open:(t,n)=>n&&typeof WebSocket<\"u\"?er(t,{socket:(r)=>{let o=new URL(r,location.href);return o.protocol=o.protocol===\"https:\"?\"wss:\":\"ws:\",new WebSocket(o)},events:(r)=>new EventSource(r)}):new EventSource(t)}}function Ct(e,t,n=[]){let r=0;for(let{name:o}of e){if(n.includes(o))continue;try{if(new URL(o).origin!==t)r+=1}catch{continue}}return r}function Wt(e,t,n=[],r=32){let o=new Map;for(let{name:s}of e){if(n.includes(s))continue;try{let a=new URL(s).origin;if(a!==t&&a!==\"null\")o.set(a,(o.get(a)??0)+1)}catch{continue}}return Object.fromEntries([...o].sort((s,a)=>a[1]-s[1]||(s[0]<a[0]?-1:1)).slice(0,r))}function tr(){try{return globalThis.localStorage}catch{return}}function nr(e,t=tr(),n=Date.now){let r=0,o=()=>{let s=0;try{s=Number(t?.getItem(\"spool:contact\"))}catch{}let a=Math.max(Number.isFinite(s)?s:0,r);return a>0?a:void 0};return{due(){let s=o();if(s===void 0)return!0;let a=n()-s;return!(a>=0&&a<e*1000)},mark(s){r=Math.max(r,s);try{t?.setItem(\"spool:contact\",String(r))}catch{}}}}var K;function Mt(e,t){K={clock:nr(t),registration:e}}function ue(e){K?.clock.mark(e)}function Nt(){if(!K||!K.clock.due())return;K.clock.mark(Date.now()),K.registration.update().catch(()=>{return})}function _t(e,t=window){let n=()=>e.close();return t.addEventListener(\"pagehide\",n),()=>t.removeEventListener(\"pagehide\",n)}var Lt=30000;function G(e,t,n){return new Promise((r,o)=>{let s=new MessageChannel,a=setTimeout(()=>{s.port1.close(),o(Error(\"the worker did not answer\"))},n);s.port1.onmessage=(u)=>{clearTimeout(a),s.port1.close(),r(u.data)},e.postMessage(t,[s.port2])})}async function qt(e={}){let t=e.container??navigator.serviceWorker;if(!t)return null;let n=e.helloTimeoutMs??5000,r=null,o=!1,s,a=async()=>{if(o)return;o=!0,r=await ce(e.storage??navigator.storage),(e.target??window).dispatchEvent(new CustomEvent(\"spool:persisted\",{detail:{granted:r}})),(s??t.controller)?.postMessage({type:\"spool:persisted\",granted:r})};t.addEventListener?.(\"message\",(h)=>{let R=h.data;if(R?.type===\"spool:persist\")a();if(R?.type===\"spool:contact\"&&typeof R.at===\"number\")ue(R.at);if(R?.type===\"spool:written\"){let{queued:S,flushed:A,conflicted:I}=R;(e.target??window).dispatchEvent(new CustomEvent(\"spool:written\",{detail:{queued:S,flushed:A,conflicted:I}}))}if(R?.type===\"spool:want-live\")(e.target??window).dispatchEvent(new CustomEvent(\"spool:want-live\"));if(R?.type!==\"spool:cleared\")return;(e.target??window).dispatchEvent(new CustomEvent(\"spool:cleared\",{detail:{reason:R.reason}}))});let u=Date.now();await t.register(e.workerUrl??De.worker,{scope:e.scope,updateViaCache:\"all\"});let m=await t.ready,p=m.active;if(!p)throw Error(\"the worker is not active\");s=p;let y=await G(p,{type:\"spool:hello\",protocol:J},n);if(y.lease!==void 0){if(Mt(m,y.lease),ue(u),y.contact!==void 0)ue(y.contact);Nt()}let w=async(h,R=n)=>{try{let S=await G(m.active??p,h,R);if(S?.type===h.type)return S.result}catch{}return{ok:!1,code:\"unavailable\",message:\"the worker did not answer\"}};return{registration:m,hello:y,status:()=>G(m.active??p,{type:\"spool:status\"},n),view:async(h=location.pathname)=>(await G(m.active??p,{type:\"spool:view\",path:h},n)).id,reportLoads:(h,R,S)=>(m.active??p).postMessage({type:\"spool:loads\",view:h,count:R,origins:S}),persisted:()=>r,liveState:()=>G(m.active??p,{type:\"spool:live-state\"},n),liveEvent:(h)=>G(m.active??p,{type:\"spool:live\",...h},n).catch(()=>{return}),track:(h)=>_t(h),write:(h,R,S,A)=>w({type:\"spool:write\",name:h,key:R,value:S,version:A}),flush:()=>w({type:\"spool:flush\"},Math.max(n,Lt)),writes:()=>w({type:\"spool:writes\"}),resolve:(h,R,S)=>w({type:\"spool:resolve\",name:h,key:R,use:S},Math.max(n,Lt))}}function rr(){try{return at()}catch{return null}}function or(){let e=()=>globalThis.spoolNavigate,t=e();if(t)return Promise.resolve(t.enableNavigation);return new Promise((n,r)=>{let o=document.createElement(\"script\");o.src=Ne(ct),o.onload=()=>{let s=e();if(s)n(s.enableNavigation);else r(Error(\"navigation script did not register\"))},o.onerror=()=>r(Error(\"navigation script failed to load\")),document.head.append(o)})}var Y=globalThis.__SPOOL_BOOT__,de=Y?.to,Ft=()=>de?location.assign(de):void 0,q=rr(),fe=q?gt({store:q,...Y?.pack?{pack:Y.pack}:{},...Y?.shape?{shape:Y.shape}:{},router:Y?.router===!0}):{worker:!0,installed:Promise.resolve(),current:!0},H=(fe.worker?qt():Promise.resolve(null)).catch(()=>null);fe.installed.then(async()=>{if(!q||!fe.current||!await q.head())return Ft();let e=await or(),t=await q.getTemplates(),n=document.querySelector(`script[${ge}]`),r=e({store:q,clientTag:n?.outerHTML??\"\",templates:t});if(de)r.go(new URL(de))}).catch(Ft);var le={ok:!1,code:\"unavailable\",message:\"there is no worker on this page\"},Vt=!1,zt={write:async(...e)=>{let t=await H.then((n)=>n?.write(...e)??le);if(t.ok)Vt=!0;return t},flush:()=>H.then((e)=>e?.flush()??le),writes:()=>H.then((e)=>e?.writes()??le),resolve:(...e)=>H.then((t)=>t?.resolve(...e)??le)};function sr(){let e=Pe(document.getElementById(oe)?.textContent);if(e)return e.writes??[];return Ot(document.getElementById(_e)?.textContent)}var Ut=q&&!fe.worker?sr():[],ir=q&&Ut.length>0?jt({store:q,writes:Ut,origin:location.origin}):(e,t)=>fetch(e,t);globalThis.spool={ready:H,activity:ut(Se()),fetch:ir,...zt};var Ht=()=>{if(Vt)zt.flush()};H.then((e)=>{if(!e)return;addEventListener(\"pagehide\",Ht),document.addEventListener(\"visibilitychange\",()=>{if(document.visibilityState===\"hidden\")Ht()})});H.then(async(e)=>{let t=await e?.view().catch(()=>null);if(!e||!t)return;let n=-1,r=()=>{let o=document.querySelector(`script[${ge}]`)?.src,s=performance.getEntriesByType(\"resource\"),a=Ct(s,location.origin,o?[o]:[]);if(a===n)return;n=a,e.reportLoads(t,a,Wt(s,location.origin,o?[o]:[]))};addEventListener(\"pagehide\",r),document.addEventListener(\"visibilitychange\",()=>{if(document.visibilityState===\"hidden\")r()})});H.then((e)=>{let t=e&&Dt(e);if(!t)return;let n=$t(t);addEventListener(\"spool:cleared\",n.reconcile),addEventListener(\"spool:want-live\",n.arm)});})();\n";
|
|
5
|
+
/** the in-page navigation script, generated by `bun run build:sw`; never edit by hand */
|
|
6
|
+
export declare const NAVIGATE_CORE = "(()=>{class R extends Error{code;constructor(e,t){super(t);this.name=\"ProtocolError\",this.code=e}}async function _(e){let t=new Uint8Array(await crypto.subtle.digest(\"SHA-256\",new TextEncoder().encode(e))),n=\"\";for(let r of t)n+=String.fromCharCode(r);return btoa(n).replace(/\\+/g,\"-\").replace(/\\//g,\"_\").replace(/=+$/,\"\")}var he=\"dataset proof does not match its items\",E=(e)=>typeof e===\"object\"&&e!==null&&!Array.isArray(e),j=(e,t)=>Object.hasOwn(e,t)?e[t]:void 0;function O(e){let t=e?.toJSON;if(typeof e===\"object\"&&typeof t===\"function\")return O(t.call(e));if(Array.isArray(e))return`[${e.map((n)=>O(n)??\"null\").join(\",\")}]`;if(E(e)){let n=[];for(let r of Object.keys(e).sort()){let o=O(e[r]);if(o!==void 0)n.push(`${JSON.stringify(r)}:${o}`)}return`{${n.join(\",\")}}`}return JSON.stringify(e)}function G(e){return O(e)??\"null\"}var M=1n<<256n,dt=\"0\".repeat(64),be=/^[0-9a-f]{64}$/;function we(e,t){return _(`${e}\\x00${G(t)}`)}function ke(e){if(!/^[A-Za-z0-9_-]{43}$/.test(e))throw RangeError(\"not a row hash\");let t=atob(e.replace(/-/g,\"+\").replace(/_/g,\"/\")+\"=\"),n=\"\";for(let r=0;r<t.length;r++)n+=t.charCodeAt(r).toString(16).padStart(2,\"0\");return BigInt(`0x${n}`)}var xe=(e)=>((e%M+M)%M).toString(16).padStart(64,\"0\");async function Re(e){let t=await Promise.all([...e].map(([r,o])=>we(r,o))),n=0n;for(let r of t)n+=ke(r);return{kind:\"set\",count:e.size,digest:xe(n)}}function Se(e){return E(e)&&e.kind===\"set\"&&typeof e.count===\"number\"&&Number.isSafeInteger(e.count)&&e.count>=0&&typeof e.digest===\"string\"&&be.test(e.digest)}function K(e){let t=e.key;if(t===void 0)return;return(n)=>{let r=j(n,t);if(typeof r!==\"string\")throw TypeError(`${t} is not a string key`);return r}}async function Pe(e,t,n){if(t.count!==e.length)return!1;let r=new Map;for(let o of e){if(!E(o))return!1;let s;try{s=n(o)}catch{return!1}if(typeof s!==\"string\"||r.has(s))return!1;r.set(s,o)}return(await Re(r)).digest===t.digest}async function je(e,t,n){if(!E(t))return!1;let r=j(t,e.list),o=j(t,\"proof\");if(!Array.isArray(r)||!E(o))return!1;let s=o.kind;if(s===\"set\")return n!==void 0&&Se(o)&&await Pe(r,o,n);if(s!==void 0&&s!==\"ordered\")return!1;if(o.count!==r.length||typeof o.digest!==\"string\")return!1;return await _(G(r))===o.digest}var Ee=(e)=>e.trim()!==\"\"&&Number.isFinite(Number(e))?Number(e):null,J=(e)=>typeof e===\"number\"?0:typeof e===\"string\"?1:2;function $e(e,t){let[n,r]=[J(e),J(t)];if(n!==r)return n-r;if(n===2)return 0;return e<t?-1:e>t?1:0}function Ae(e,t,n){let r=E(t)?j(t,e.list):void 0;if(!Array.isArray(r)||!r.every(E))return null;let o=new URLSearchParams(n),s=e.filter??{};for(let g of new Set(o.keys()))if(g!==\"sort\"&&g!==\"page\"&&!Object.hasOwn(s,g))return null;let l=r;for(let[g,S]of Object.entries(s)){let k=o.getAll(g);if(k.length===0)continue;if(S===\"number\"){let b=k.map(Ee);if(b.includes(null))return null;l=l.filter((w)=>{let h=j(w,g);return typeof h===\"number\"&&b.includes(h)})}else l=l.filter((b)=>{let w=j(b,g),h=typeof w===\"string\"||typeof w===\"number\"||typeof w===\"boolean\"?String(w):void 0;return h!==void 0&&k.includes(h)})}let a=o.getAll(\"sort\");if(a.length>1)return null;if(l=[...l],a.length===1){let g=a[0],S=e.sort??[],k=!S.includes(g)&&g.startsWith(\"-\"),b=k?g.slice(1):g;if(!S.includes(b))return null;l.sort((w,h)=>{let x=$e(j(w,b),j(h,b));return k?-x:x})}let i=o.getAll(\"page\");if(i.length>1)return null;let u=1;if(i.length===1){if(!/^[1-9]\\d{0,14}$/.test(i[0]))return null;u=Number(i[0])}let c=l.length,f=e.pageSize,y=f===void 0?1:Math.max(1,Math.ceil(c/f));if(u>y)return null;return{items:f===void 0?l:l.slice((u-1)*f,u*f),total:c,page:u,pages:y}}async function V(e,t,n,r){if(!await je(e,t,r))return{ok:!1,reason:he};return F(e,t,n)}function F(e,t,n){let r=Ae(e,t,n);if(!r)return{ok:!1,reason:\"query is not one the route declares\"};let{items:o,total:s,page:l,pages:a}=r,i={total:s,page:l,pages:a};return{ok:!0,data:{...t,[e.list]:o,query:i}}}var Y=1;var St=new RegExp(`[<>&${String.fromCharCode(8232,8233)}]`,\"g\");var Z=\"spool-ring\",X=\"spool-writes\",ee=\"spool-delta\";var Tt=new RegExp(`<script type=\"application/json\" id=\"(?:${Z}|${X}|${ee})\">[\\\\s\\\\S]*?</script>`,\"g\");function te(e){let t=e.length>1&&e.endsWith(\"/\")?e.slice(0,-1):e;return t===\"/\"?[]:t.slice(1).split(\"/\")}function ne(e,t){let n=te(e),r=te(t),o=n[n.length-1]===\"**\";if(o)n.pop();if(o?r.length<n.length:n.length!==r.length)return null;let s={};for(let l=0;l<n.length;l++){let a=n[l],i=r[l];if(a.startsWith(\":\")){if(i===\"\")return null;try{s[a.slice(1)]=decodeURIComponent(i)}catch{return null}}else if(a!==i)return null}return s}var se=200,Te=/^[1-9]\\d{0,14}$/,Oe=/^[+-]?(\\d+\\.?\\d*|\\.\\d+)(e[+-]?\\d+)?$/i,Ne=/[\\uD800-\\uDBFF](?![\\uDC00-\\uDFFF])|(?<![\\uD800-\\uDBFF])[\\uDC00-\\uDFFF]/;class N extends Error{}var A=(e,t)=>Object.hasOwn(e,t)?e[t]??null:null,qe=(e)=>typeof e===\"object\"&&e!==null&&!Array.isArray(e),P=(e)=>typeof e===\"number\"?1:typeof e===\"string\"?2:0,re=(e)=>e.replace(/[A-Z]+/g,(t)=>t.toLowerCase());function Ce(e){if(e===null||e===void 0)return!0;if(typeof e===\"number\")return Number.isFinite(e);if(typeof e===\"string\")return!Ne.test(e)&&!e.includes(\"\\x00\");return!1}function Ie(e,t){let n=Math.min(e.length,t.length);for(let r=0;r<n;r++){let o=e.charCodeAt(r),s=t.charCodeAt(r);if(o===s)continue;let l=o>=55296&&o<=57343,a=s>=55296&&s<=57343;if(l!==a)return l?1:-1;return o-s}return e.length-t.length}function I(e,t){let n=P(e),r=P(t);if(n!==r)return n-r;if(n===0)return 0;if(n===1)return e<t?-1:e>t?1:0;return Ie(e,t)}function ve(e,t){for(let n=0;n<e.length;n++){let r=I(e[n],t[n]);if(r!==0)return r}return 0}var ie=(e,t)=>P(e)!==0&&P(e)===P(t)&&e===t;function oe(e,t){if(e.index)return e.index.clean(t);return e.keys.every((n)=>Ce(A(e.rows.get(n),t)))}function q(e,t){if(e.from.includes(t))return{join:-1,field:t};let n=t.indexOf(\".\");if(n<0)return;let r=t.slice(0,n),o=t.slice(n+1),s=(e.join??[]).findIndex((l)=>l.as===r);if(s<0||!(e.join?.[s]?.fields??[]).includes(o))return;return{join:s,field:o}}function C(e,t){if(t.join<0)return A(e.base,t.field);let n=e.joined[t.join];return n?A(n,t.field):null}function Le(e,t){if(e.op!==\"in\"&&t.length!==1)return null;let n=[];for(let r of t)if(e.type===\"number\"){if(!Oe.test(r))return null;let o=Number(r);if(!Number.isFinite(o))return null;n.push(o)}else{if(r.includes(\"\\x00\"))return null;n.push(r)}return n}function _e(e,t){let{cond:n,values:r}=e;if(n.op===\"eq\"||n.op===\"in\")return r.some((s)=>ie(t,s));if(n.op===\"gte\"||n.op===\"lte\"){let s=r[0];if(P(t)===0||P(t)!==P(s))return!1;let l=I(t,s);return n.op===\"gte\"?l>=0:l<=0}if(typeof t!==\"string\")return!1;let o=r[0];return n.fold===\"ascii\"?re(t).startsWith(re(o)):t.startsWith(o)}function Me(e,t,n){let r=A(n,e.on[0]);if(e.on[1]===null)return typeof r===\"string\"&&t.rows.has(r)?[r]:[];if(P(r)===0)return[];let o=e.on[1];if(t.index&&t.keys.length>=se)return t.index.equal(o,[r]);return t.keys.filter((s)=>ie(A(t.rows.get(s),o),r))}function D(e,t,n,r,o){if(r===e.length){o.push(n);return}let s=e[r],l=t[r],a=Me(s,l,n.base);if(a.length===0){if(s.type===\"left\")D(e,t,{...n,keys:[...n.keys,null],joined:[...n.joined,null]},r+1,o);return}for(let i of a){let u=l.rows.get(i);D(e,t,{base:n.base,keys:[...n.keys,i],joined:[...n.joined,u]},r+1,o)}}function Fe(e,t,n){if(t===\"count\")return n.length;let[r,o]=Object.entries(t)[0],s=q(e,o),l=n.map((i)=>C(i,s)).filter((i)=>i!==null);if(r===\"count\")return l.length;if(r===\"min\"||r===\"max\"){if(l.length===0)return null;return l.reduce((i,u)=>{let c=I(u,i);return r===\"min\"?c<0?u:i:c>0?u:i})}if(l.length===0)return null;let a=0;for(let i of l){if(typeof i!==\"number\"||!Number.isSafeInteger(i))throw new N;if(a+=i,!Number.isSafeInteger(a))throw new N}return r===\"sum\"?a:a/l.length}function De(e,t){let n=e.from.map((o)=>[o,A(t.base,o)]),r=(e.join??[]).map((o,s)=>{let l=t.joined[s],a=o.fields.map((i)=>[i,l?A(l,i):null]);return[o.as,Object.fromEntries(a)]});return Object.fromEntries([...n,...r])}function Qe(e,t,n,r){let o=t.by.map((a)=>q(e,a)),s=new Map;if(t.by.length===0)s.set(\"[]\",{by:[],members:[]});for(let a of n){let i=o.map((f)=>C(a,f)),u=JSON.stringify(i.map((f)=>f===null?\"0\":`${P(f)}${String(f)}`)),c=s.get(u)??{by:i,members:[]};c.members.push(a),s.set(u,c)}let l=Object.entries(t.aggregates);return[...s.values()].map(({by:a,members:i})=>{let u=Object.fromEntries([...t.by.map((c,f)=>[c,a[f]??null]),...l.map(([c,f])=>[c,Fe(e,f,i)])]);return{row:u,sort:r.map((c)=>u[c]),tie:a}})}function ze(e,t,n){let r=new URLSearchParams(t),o=e.where??[],s=e.join??[];for(let d of new Set(r.keys()))if(d!==\"sort\"&&d!==\"page\"&&!o.some((p)=>p.param===d))return null;let l=[];for(let d of o){let p=r.getAll(d.param);if(p.length===0)continue;let m=Le(d,p);if(!m)return null;l.push({cond:d,ref:q(e,d.field),values:m})}let a=r.getAll(\"sort\");if(a.length>1)return null;let i=[];if(a.length===1){let d=a[0],p=d.startsWith(\"-\"),m=p?d.slice(1):d;if(!(e.sort??[]).includes(m))return null;i.push({name:m,desc:p})}let u=r.getAll(\"page\");if(u.length>1)return null;let c=1;if(u.length===1){if(!Te.test(u[0]))return null;c=Number(u[0])}let f=n.base,y=[];for(let d of s){let p=n.joined(d.dataset);if(!p)return null;y.push(p)}for(let d of e.from)if(!oe(f,d))return null;for(let d=0;d<s.length;d++){let p=s[d],m=p.on[1]===null?p.fields:[...p.fields,p.on[1]];for(let T of m)if(!oe(y[d],T))return null}let g=f.keys,S=l.find((d)=>d.ref.join<0);if(S&&f.index&&f.keys.length>=se){let{cond:d,ref:p,values:m}=S;g=d.op===\"gte\"||d.op===\"lte\"?f.index.range(p.field,d.op,m[0]):d.op===\"prefix\"?f.index.prefix(p.field,d.fold,m[0]):f.index.equal(p.field,m)}let k=[];for(let d of g){let p=f.rows.get(d);D(s,y,{base:p,keys:[d],joined:[]},0,k)}let b=k.filter((d)=>l.every((p)=>_e(p,C(d,p.ref)))),w=e.group,h=i.map((d)=>d.name),x;if(w)x=Qe(e,w,b,h);else{if(b.length>e.limit)return null;let d=h.map((p)=>q(e,p));x=b.map((p)=>({row:De(e,p),sort:d.map((m)=>C(p,m)),tie:p.keys}))}if(x.length>e.limit)return null;x.sort((d,p)=>{for(let m=0;m<i.length;m++){let T=I(d.sort[m],p.sort[m]);if(T!==0)return i[m]?.desc?-T:T}return ve(d.tie,p.tie)});let U=x.length,L=e.pageSize,W=Math.max(1,Math.ceil(U/L));if(c>W)return null;return{items:x.slice((c-1)*L,c*L).map((d)=>d.row),total:U,page:c,pages:W}}function Be(e,t,n){try{return ze(e,t,n)}catch(r){if(r instanceof N)return null;throw r}}function ae(e,t,n,r,o){if(!o)return{ok:!1,reason:\"plan needs its datasets\"};let s=Be(t,r,o);if(!s)return{ok:!1,reason:\"query is not one the route declares\"};let{items:l,total:a,page:i,pages:u}=s;return{ok:!0,data:{...qe(n)?n:{},[e]:l,query:{total:a,page:i,pages:u}}}}function Q(e,t){for(let n of e){let r=ne(n.pattern,t);if(r)return{route:n,params:r}}return null}var Ue=/<span data-spool-placeholder=\"([^\"]*)\"><\\/span>/g,We=/\\{\\{spool-slot:([A-Za-z0-9_.-]+)\\}\\}/g;function ue(e,t,n){let r=[],o=[],s=new Set,l=e.replace(t,(i,u)=>{s.add(u);let c=Object.hasOwn(n,u)?n[u]:void 0;if(c===void 0)return o.push(u),i;return r.push(u),c}),a=Object.keys(n).filter((i)=>!s.has(i));return{html:l,filled:r,unfilled:o,unmatched:a}}function Je(e,t){return ue(e,Ue,t)}function Ge(e,t){return ue(e,We,t)}function le(e){let t=(l)=>{let a={};for(let[i,u]of Object.entries(l??{})){if(typeof u!==\"string\")return null;a[i]=u}return a},n=t(e.fragments),r=t(e.slots);if(!n||!r)return{ok:!1,reason:\"unresolved reference\"};let o=Je(e.shell,n);if(o.unfilled.length>0)return{ok:!1,reason:`unfilled placeholders: ${o.unfilled.join(\", \")}`};let s=Ge(o.html,r);if(s.unfilled.length>0)return{ok:!1,reason:`unfilled slots: ${s.unfilled.join(\", \")}`};return{ok:!0,html:s.html}}var Ke=\"data-spool-gate\";function ce(e,t){if(e.includes(\"data-spool-client\")||e.includes(Ke))return e;for(let n of[/<\\/head\\s*>/i,/<\\/body\\s*>/i]){let r=e.search(n);if(r>=0)return e.slice(0,r)+t+e.slice(r)}return e+t}var Ve={\"&\":\"&\",\"<\":\"<\",\">\":\">\",'\"':\""\",\"'\":\"'\"};function He(e){return e.replace(/[&<>\"']/g,(t)=>Ve[t])}function fe(e,t){if(e===null||typeof e!==\"object\")return;return Object.hasOwn(e,t)?e[t]:void 0}function z(e,t){let n=t[t.length-1];if(e.length===0)return n.value;if(e[0]===\"@index\")return n.index;for(let r=t.length-1;r>=0;r--){let o=t[r];if(fe(o.value,e[0])===void 0)continue;return e.reduce((s,l)=>fe(s,l),o.value)}return}function Ye(e){if(Array.isArray(e))return e.length>0;return!(e===void 0||e===null||e===!1||e===\"\"||e===0)}function Ze(e){return typeof e===\"string\"||typeof e===\"number\"?String(e):\"\"}function B(e,t,n){let r=\"\";for(let o of e)if(o.t===\"text\")r+=o.v;else if(o.t===\"var\"){let s=Ze(z(o.p,t));if(!o.raw)r+=He(s);else if(n.has(o.p.join(\".\")))r+=s;else throw new R(\"bad-template\",`{{{${o.p.join(\".\")}}}} is not trusted`)}else if(o.t===\"if\")r+=B(Ye(z(o.p,t))?o.then:o.else,t,n);else{let s=z(o.p,t);if(!Array.isArray(s))continue;s.forEach((l,a)=>{r+=B(o.body,[...t,{value:l,index:a}],n)})}return r}function de(e,t){if(e.v!==1)throw new R(\"bad-template\",`unknown template version ${String(e.v)}`);return B(e.nodes,[{value:t,index:0}],new Set(e.trusted))}var Xe=(e)=>typeof e===\"object\"&&e!==null&&!Array.isArray(e);async function pe(e,t,n,r={},o,s,l){try{let a=n,i=t.query;if(i&&(i.plan!==void 0||s!==void 0||o!==void 0&&o!==\"\")){if(n.strategy===\"assembly\"||n.strategy===\"static\")return{ok:!1,reason:`${n.strategy} artifact cannot answer a query`};let f=n.body.data,y=i.plan?ae(i.list,i.plan,f,o??\"\",l):s===void 0?await V(i,f,o??\"\",K(i)):F(i,{...Xe(f)?f:{},[i.list]:s},o??\"\");if(!y.ok)return y;a={...n,body:{data:y.data}}}let u=Object.hasOwn(r,t.pattern)?r[t.pattern]:void 0,c;if(u)c=await u(a);else if(a.strategy===\"data\"&&t.strategy===\"data\")return{ok:!0,html:JSON.stringify(a.body.data)};else if(a.strategy===\"projection\"&&t.strategy===\"projection\")return{ok:!1,reason:`no renderer for ${t.pattern}`};else if(a.strategy===\"static\"||a.strategy!==t.strategy)return{ok:!1,reason:`artifact is ${a.strategy}, route is ${t.strategy}`};else if(a.strategy===\"assembly\"){let f=le(a.body);if(!f.ok)return f;c=f.html}else if(a.strategy!==\"template\")return{ok:!1,reason:`${a.strategy} has no built-in render`};else{let f=Object.hasOwn(e.templates,t.pattern)?e.templates[t.pattern]:void 0;if(!f)return{ok:!1,reason:`no template for ${t.pattern}`};c=de(f,a.body.data)}if(t.strategy===\"data\")return{ok:!0,html:c};return{ok:!0,html:ce(c,e.clientTag)}}catch(a){return{ok:!1,reason:a instanceof Error?a.message:\"render failed\"}}}var v;function ge(){if(!v||!v.clock.due())return;v.clock.mark(Date.now()),v.registration.update().catch(()=>{return})}var et=90,tt=1e4,nt=[\"template\",\"projection\"];function ye(e,t,n){if(e.navigation===\"document\")return!1;if(!nt.includes(e.strategy))return!1;let r=Object.hasOwn(n.renderers??{},e.pattern),o=e.strategy===\"template\"&&Object.hasOwn(n.templates??{},e.pattern);if(!r&&!o)return!1;if(e.family)return t.search===\"\";return e.query?.dataset!==void 0&&e.query.plan===void 0&&t.search!==\"\"}async function rt(e,t){try{return await e.scanTable(t)}catch(n){if(n instanceof R&&n.code===\"bad-sync\")return e.scanTable(t);throw n}}function ot(e){let{store:t}=e,n=e.renderers??{},r={templates:e.templates??{},clientTag:e.clientTag??\"\"},o=[],s=!1,l=!1,a=Promise.all([t.getRoutes(),t.head()]).then(([i,u])=>{o=i,l=u?.partial===!0,s=!0}).catch(()=>{return});return{ready:a,offers(i){if(!s)return!1;let u=Q(o,i.pathname);return u!==null&&!(l&&!u.route.family)&&ye(u.route,i,e)},async render(i){await a;let u=Q(o,i.pathname);if(!u||!ye(u.route,i,e))return null;let{route:c,params:f}=u,y=c.family?.dataset??c.query?.dataset;if(y===void 0)return null;let g=await t.head();if(!g?.tables.includes(y))return null;if(g.partial&&!c.family)return null;let S={},k;if(c.family){let h=f[c.family.key],x=h===void 0?void 0:await t.getRow(y,h);if(x===void 0)return null;S={params:f,row:x}}else k=(await rt(t,y)).map(([,h])=>h);let b={protocol:Y,id:i.pathname,scope:c.scope,strategy:c.strategy,deps:[],vector:0,body:{data:S}},w=await pe(r,c,b,n,i.search.slice(1),k);return w.ok?w.html:null}}}function st(e,t=Date.now){let n=[];return{take(){let r=t();while(n.length>0&&r-n[0]>=tt)n.shift();if(n.length>=et)return!1;return n.push(r),!0},push(r){e.pushState(null,\"\",r)}}}function it(e){if(e.defaultPrevented||e.button!==0)return null;if(e.metaKey||e.ctrlKey||e.shiftKey||e.altKey)return null;let t=e.target?.closest?.(\"a[href]\");if(!t||t.hasAttribute(\"target\")||t.hasAttribute(\"download\"))return null;let n=new URL(t.getAttribute(\"href\")??\"\",location.href);if(n.origin!==location.origin)return null;if(n.hash!==\"\"&&n.pathname===location.pathname&&n.search===location.search)return null;return n}function at(e){let t=e.target;if(!t||e.defaultPrevented||t.hasAttribute(\"target\"))return null;if((t.getAttribute(\"method\")??\"get\").toLowerCase()!==\"get\")return null;let n=new URL(t.getAttribute(\"action\")??location.href,location.href);if(n.origin!==location.origin)return null;let r=new URLSearchParams;for(let[o,s]of new FormData(t))if(typeof s===\"string\")r.append(o,s);return n.search=r.toString(),n}function ut(e){let t=new DOMParser().parseFromString(e,\"text/html\"),n=(a)=>a.querySelector(\"[data-spool-swap]\")??a.querySelector(\"main\"),r=n(document),o=n(t);if(!r||!o)throw Error(\"the page has no swap element\");r.replaceWith(document.importNode(o,!0));let s=document.querySelector(\"[data-spool-swap-sidebar]\"),l=t.querySelector(\"[data-spool-swap-sidebar]\");if(s&&l)s.replaceWith(document.importNode(l,!0));document.title=t.title}function me(e){let t=ot(e),n=st(history),r=new URL(location.href);async function o(u,c){ge();let f=await t.render(u);if(f===null)return!1;if(ut(f),c){n.push(u.href);let y=u.hash.slice(1),g=y?document.getElementById(decodeURIComponent(y)):null;if(g)g.scrollIntoView();else window.scrollTo(0,0)}return r=u,window.dispatchEvent(new CustomEvent(\"spool:navigated\",{detail:{url:u.href,local:!0}})),!0}function s(u,c){let f=()=>c?location.assign(u.href):location.reload();o(u,c).then((y)=>{if(!y)f()},f)}let l=(u)=>{let c=it(u);if(!c||!t.offers(c)||!n.take())return;u.preventDefault(),s(c,!0)},a=(u)=>{let c=at(u);if(!c||!t.offers(c)||!n.take())return;u.preventDefault(),s(c,!0)},i=()=>{let u=new URL(location.href);if(u.pathname===r.pathname&&u.search===r.search)return;s(u,!1)};return document.addEventListener(\"click\",l),document.addEventListener(\"submit\",a),window.addEventListener(\"popstate\",i),{ready:t.ready,go:(u)=>s(u,!0),stop(){document.removeEventListener(\"click\",l),document.removeEventListener(\"submit\",a),window.removeEventListener(\"popstate\",i)}}}globalThis.spoolNavigate={enableNavigation:me};})();\n";
|
|
7
|
+
/** the inline gate that loads the page runtime from the second view, generated by `bun run build:sw`; never edit by hand */
|
|
8
|
+
export declare const GATE_CORE = "(()=>{function p(e){if(/\\b(?:CriOS|FxiOS|EdgiOS|OPiOS)\\//.test(e))return\"webkit\";if(/\\bFirefox\\//.test(e))return\"firefox\";if(/(?:Chrome|Chromium)\\//.test(e))return\"chromium\";if(/\\bSafari\\//.test(e))return\"webkit\";return\"other\"}function b(e,t,n){return[...e.split(\",\").filter(Boolean).map(Number).filter((o)=>o>=0&&o<=t&&t-o<n),t].slice(-3)}var{dataset:r}=document.currentScript,d=\"spool:views\",m=\"spool:stamps\",h=\"spool:boot\",k=(r.held??\"\").split(\" \").filter(Boolean),y=Number(r.lease)*1000,a=1,c=1,g=\"\",u=!1,l=r.src??\"\";try{let e=Number(localStorage.getItem(d));if(a=(e>=0&&e<1e9?e:0)+1,localStorage.setItem(d,String(a)),c=a,y>0){g=localStorage.getItem(m)??\"\";let n=b(g,Date.now(),y);localStorage.setItem(m,n.join()),c=n.length}let t=localStorage.getItem(h);if(t?.startsWith(l.slice(0,l.lastIndexOf(\"/\")+1)))l=t,u=!0}catch{}function i(e,t){let n=document.createElement(\"script\");if(n.src=e,r.integrity)n.integrity=r.integrity,n.crossOrigin=\"anonymous\";if(n.dataset.spoolClient=\"\",r.spoolWorker)n.dataset.spoolWorker=r.spoolWorker;if(t)n.onerror=()=>location.assign(t);try{localStorage.setItem(d,String(a-1)),localStorage.setItem(m,g)}catch{}document.head.append(n)}function O(){try{return JSON.parse(document.getElementById(\"spool-ring\")?.textContent??\"\").boot}catch{return}}function S(e){u=!0,document.removeEventListener(\"click\",E),document.removeEventListener(\"submit\",_);try{localStorage.setItem(h,e)}catch{}}function w(e,t){let{pathname:n,search:o}=t;if(t.origin!==location.origin)return;if(t.hash&&n===location.pathname&&o===location.search)return;let T=(f)=>f[0]===\"?\"?o&&n===f.slice(1):!o&&n.startsWith(f),s=k.some(T)?O():void 0;if(!s)return;if(S(s),e.defaultPrevented)return globalThis.__SPOOL_BOOT__={router:!0},i(s);e.preventDefault(),globalThis.__SPOOL_BOOT__={to:t.href},i(s,t.href)}function E(e){let t=e.target?.closest?.(\"a[href]\");if(!t||e.button||t.target)return;if(e.metaKey||e.ctrlKey||e.shiftKey||e.altKey)return;if(t.hasAttribute(\"download\"))return;w(e,new URL(t.href))}function _(e){let t=e.target;if(t.target)return;if((t.getAttribute(\"method\")??\"get\").toLowerCase()!==\"get\")return;let n=new URL(t.getAttribute(\"action\")??\"\",location.href);n.search=new URLSearchParams(new FormData(t)).toString(),w(e,n)}if(u)i(l);else if(document.addEventListener(\"click\",E),document.addEventListener(\"submit\",_),c>1)addEventListener(\"DOMContentLoaded\",()=>{if(u)return;let e=O();if(!e)return i(r.src??\"\");if(c<3||r.spoolWorker===\"never\")return;if(r.spoolWorker!==\"always\"&&p(navigator.userAgent)===\"webkit\")return;if(navigator.serviceWorker?.controller)return;S(e),i(e)});})();\n";
|
|
5
9
|
/** hash of the sources both bundles were built from; a test fails when it drifts */
|
|
6
|
-
export declare const SOURCE_HASH = "
|
|
10
|
+
export declare const SOURCE_HASH = "bfe75917890de19ada473c09f79126e46a7e0b07d7d263f1c1ede497ea9bbec6";
|