wherever-dev 0.2.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/LICENSE +21 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1264 -0
- package/dist/index.js.map +1 -0
- package/dist/protocol.d.ts +157 -0
- package/dist/protocol.d.ts.map +1 -0
- package/dist/protocol.js +2 -0
- package/dist/protocol.js.map +1 -0
- package/dist/session-pool.d.ts +119 -0
- package/dist/session-pool.d.ts.map +1 -0
- package/dist/session-pool.js +909 -0
- package/dist/session-pool.js.map +1 -0
- package/dist/session-types.d.ts +44 -0
- package/dist/session-types.d.ts.map +1 -0
- package/dist/session-types.js +2 -0
- package/dist/session-types.js.map +1 -0
- package/package.json +42 -0
- package/public/_app/env.js +1 -0
- package/public/_app/immutable/assets/0.DvZxoQjW.css +2754 -0
- package/public/_app/immutable/chunks/B5WJGjcR.js +23 -0
- package/public/_app/immutable/chunks/B5WJGjcR.js.map +1 -0
- package/public/_app/immutable/chunks/BEWoN05F.js +110 -0
- package/public/_app/immutable/chunks/BEWoN05F.js.map +1 -0
- package/public/_app/immutable/chunks/BqMutrfe.js +2129 -0
- package/public/_app/immutable/chunks/BqMutrfe.js.map +1 -0
- package/public/_app/immutable/chunks/DFxBx2vA.js +897 -0
- package/public/_app/immutable/chunks/DFxBx2vA.js.map +1 -0
- package/public/_app/immutable/chunks/DiYtJzYU.js +396 -0
- package/public/_app/immutable/chunks/DiYtJzYU.js.map +1 -0
- package/public/_app/immutable/chunks/_lppinj8.js +879 -0
- package/public/_app/immutable/chunks/_lppinj8.js.map +1 -0
- package/public/_app/immutable/chunks/rMw82gDs.js +3048 -0
- package/public/_app/immutable/chunks/rMw82gDs.js.map +1 -0
- package/public/_app/immutable/entry/app.BFki2czn.js +309 -0
- package/public/_app/immutable/entry/app.BFki2czn.js.map +1 -0
- package/public/_app/immutable/entry/start.BceUuq27.js +6 -0
- package/public/_app/immutable/entry/start.BceUuq27.js.map +1 -0
- package/public/_app/immutable/nodes/0.BzvDOlXz.js +546 -0
- package/public/_app/immutable/nodes/0.BzvDOlXz.js.map +1 -0
- package/public/_app/immutable/nodes/1.DMtW3tA5.js +24 -0
- package/public/_app/immutable/nodes/1.DMtW3tA5.js.map +1 -0
- package/public/_app/immutable/nodes/2.CnZp8abw.js +5152 -0
- package/public/_app/immutable/nodes/2.CnZp8abw.js.map +1 -0
- package/public/_app/version.json +1 -0
- package/public/icon.png +0 -0
- package/public/index.html +84 -0
- package/public/logo.svg +52 -0
- package/public/pwa/apple-touch-icon.png +0 -0
- package/public/pwa/favicon-192.png +0 -0
- package/public/pwa/favicon-512.png +0 -0
- package/public/pwa/favicon.ico +0 -0
- package/public/pwa/favicon.png +0 -0
- package/public/pwa/manifest.webmanifest +27 -0
- package/public/service-worker.js +305 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":"5214502"}
|
package/public/icon.png
ADDED
|
Binary file
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en" class="h-full bg-brand-dark text-brand-text" data-mode="dark">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
6
|
+
<link rel="icon" href="./logo.svg" />
|
|
7
|
+
<meta name="description" content="Control your pi coding agent from anywhere with a beautiful remote dashboard." />
|
|
8
|
+
|
|
9
|
+
<!-- inject named-logs-console -->
|
|
10
|
+
<!-- prettier-ignore -->
|
|
11
|
+
<script>
|
|
12
|
+
"use strict";var noop=function(){},W="undefined"!=typeof window?window:globalThis,oldConsole=W.console,disabledRegexps=[],enabledRegexps=[];function bindCall(e,l,a,o,r){if(l.enabled&&(l.level>=o||factory.level>=o)){if(a>=o||factory.traceLevel>=o){if(factory.labelVisible){var t="string"==typeof factory.labelVisible?"".concat(factory.labelVisible).concat(l.namespace):l.namespace;return l.decoration?oldConsole.trace.bind(oldConsole,"%c".concat(t),l.decoration):oldConsole.trace.bind(oldConsole,t)}return oldConsole.trace.bind(oldConsole)}if(r&&factory.labelVisible){t="string"==typeof factory.labelVisible?"".concat(factory.labelVisible).concat(l.namespace):l.namespace;return l.decoration?e.bind(oldConsole,"%c".concat(t),l.decoration):e.bind(oldConsole,t)}return e.bind(oldConsole)}return noop}var loggers={};function write(e){process.stdout.write(e)}var factory=function(e,l){var a=loggers[e];if(a)return a;var o=factory.level,r=factory.traceLevel;return a=loggers[e]={namespace:e,decoration:null==l?void 0:l.decoration,get assert(){return bindCall(oldConsole.assert,a,r,1,!1)},get error(){return bindCall(oldConsole.error,a,r,1,!0)},get warn(){return bindCall(oldConsole.warn,a,r,2,!0)},get info(){return bindCall(oldConsole.info,a,r,3,!0)},get write(){return"undefined"!=typeof process?bindCall(write,a,r,3,!1):bindCall(oldConsole.info,a,r,3,!1)},get log(){return bindCall(oldConsole.log,a,r,4,!0)},get debug(){return bindCall(oldConsole.debug,a,r,5,!0)},get trace(){return bindCall(oldConsole.trace,a,r,6,!0)},get dir(){return bindCall(oldConsole.dir,a,r,5,!1)},get table(){return bindCall(oldConsole.table||oldConsole.debug,a,r,5,!1)},get time(){return bindCall(oldConsole.time||oldConsole.debug,a,r,5,!1)},get timeEnd(){return bindCall(oldConsole.timeEnd||oldConsole.debug,a,r,5,!1)},get timeLog(){return bindCall(oldConsole.timeLog||oldConsole.debug,a,r,5,!1)},get level(){return o},set level(e){o=e},get traceLevel(){return r},set traceLevel(e){r=e},enabled:enabled(e,{disabledRegexps:disabledRegexps,enabledRegexps:enabledRegexps})}},logLevels={error:1,warn:2,info:3,log:4,debug:5,trace:6};function enabled(e,l){var a,o,r=l.disabledRegexps,t=l.enabledRegexps;if("*"===e[e.length-1])return!0;for(a=0,o=r.length;a<o;a++)if(r[a].test(e))return!1;for(a=0,o=t.length;a<o;a++)if(t[a].test(e))return!0;return!1}function processNamespaces(e,l,a){for(var o=l.disabledRegexps,r=l.enabledRegexps,t=("string"==typeof e?e:"").split(/[\s,]+/),n=t.length,s=0;s<n;s++)t[s]&&("-"===(e=t[s].replace(/\*/g,".*?"))[0]?o.push(new RegExp("^"+e.substr(1)+"$")):r.push(new RegExp("^"+e+"$")));for(var i=0,d=Object.keys(loggers);i<d.length;i++){var c=d[i];a(c,enabled(c,{disabledRegexps:o,enabledRegexps:r}))}}if(factory.level=2,factory.traceLevel=0,factory.setTraceLevelFor=function(e,l){processNamespaces(e||"*",{disabledRegexps:[],enabledRegexps:[]},function(e,a){a&&(loggers[e].traceLevel=l)})},factory.disable=function(){disabledRegexps.splice(0,disabledRegexps.length),enabledRegexps.splice(0,enabledRegexps.length);for(var e=0,l=Object.keys(loggers);e<l.length;e++){var a=l[e];loggers[a].enabled=!1}try{localStorage.removeItem("debug")}catch(e){}},factory.enable=function(e){disabledRegexps.splice(0,disabledRegexps.length),enabledRegexps.splice(0,enabledRegexps.length),processNamespaces(e=""===e?"*":e||"*",{disabledRegexps:disabledRegexps,enabledRegexps:enabledRegexps},function(e,l){return loggers[e].enabled=l});try{localStorage.setItem("debug",e)}catch(e){}},"undefined"!=typeof localStorage)try{var str=localStorage.getItem("debug");str&&""!==str&&factory.enable(str)}catch(e){}else if("undefined"!=typeof process){(val=process.env.NAMED_LOGS)?factory.enable(val):factory.disable(),(val=process.env.NAMED_LOGS_LEVEL)&&(factory.level=logLevels[val]||parseInt(val)||factory.level),(val=process.env.NAMED_LOGS_TRACE_LEVEL)&&(factory.traceLevel=logLevels[val]||parseInt(val)||factory.level),(val=process.env.NAMED_LOGS_LABEL)&&(factory.labelVisible=!0)}for(var vars=W.location?W.location.search.slice(1).split("&"):[],_i=0,vars_1=vars;_i<vars_1.length;_i++){var variable=vars_1[_i];if(variable.startsWith("debug="))""===(val=variable.slice(6))?factory.disable():factory.enable(val);else if(variable.startsWith("debugLevel=")){var val=variable.slice(11);factory.level=logLevels[val]||parseInt(val)||factory.level}else if(variable.startsWith("traceLevel=")){val=variable.slice(11);factory.traceLevel=logLevels[val]||parseInt(val)||factory.level}else if(variable.startsWith("debugLabel")){val=variable.slice(11);factory.labelVisible=val||!0}}globalThis._logFactory=factory;
|
|
13
|
+
</script>
|
|
14
|
+
|
|
15
|
+
<!-- inject eruda loader (use ?eruda or even ?eruda=<plugin package name separated by ",">) -->
|
|
16
|
+
<!--prettier-ignore -->
|
|
17
|
+
<script>
|
|
18
|
+
(function () {
|
|
19
|
+
let params = new URLSearchParams(window.location.search);
|
|
20
|
+
const eruda_options = params.get('eruda');
|
|
21
|
+
if (eruda_options !== "" && !eruda_options && localStorage.getItem('active-eruda') != 'true') return;
|
|
22
|
+
const _ = '';
|
|
23
|
+
let add_plugins = '';
|
|
24
|
+
let load_plugins = '';
|
|
25
|
+
if (eruda_options.length > 0) {
|
|
26
|
+
for (const plugin of eruda_options.split(",")) {
|
|
27
|
+
let [pkg, v] = plugin.split(":");
|
|
28
|
+
v = v || pkg.split('-').map((split, i) => i > 0 ? split[0].toUpperCase() + split.slice(1): split).join('');
|
|
29
|
+
load_plugins += `document.write(\`<scr\${_}ipt src="//cdn.jsdelivr.net/npm/${pkg}"></scr\${_}ipt>\`);`;
|
|
30
|
+
add_plugins += `eruda.add(${v});`;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// you might want to load eruda from from .//debug/eruda.js
|
|
35
|
+
// document.write(`<scr${_}ipt src="./debug/eruda.js"></scr${_}ipt>`);
|
|
36
|
+
// and fallback on cdn.jsdelivr.net
|
|
37
|
+
document.write(`
|
|
38
|
+
<scr${_}ipt>
|
|
39
|
+
const _ = '';
|
|
40
|
+
if (typeof eruda === "undefined") {
|
|
41
|
+
document.write(\`<scr\${_}ipt src="//cdn.jsdelivr.net/npm/eruda"></scr\${_}ipt>\`);
|
|
42
|
+
};
|
|
43
|
+
${load_plugins}
|
|
44
|
+
document.write(\`<scr\${_}ipt>eruda.init();${add_plugins}</scr\${_}ipt>\`);
|
|
45
|
+
</scr${_}ipt>
|
|
46
|
+
`);
|
|
47
|
+
})();
|
|
48
|
+
</script>
|
|
49
|
+
|
|
50
|
+
<link href="./_app/immutable/entry/start.BceUuq27.js" rel="modulepreload">
|
|
51
|
+
<link href="./_app/immutable/chunks/BqMutrfe.js" rel="modulepreload">
|
|
52
|
+
<link href="./_app/immutable/chunks/rMw82gDs.js" rel="modulepreload">
|
|
53
|
+
<link href="./_app/immutable/entry/app.BFki2czn.js" rel="modulepreload">
|
|
54
|
+
<link href="./_app/immutable/chunks/BEWoN05F.js" rel="modulepreload">
|
|
55
|
+
<link href="./_app/immutable/chunks/DFxBx2vA.js" rel="modulepreload">
|
|
56
|
+
<link href="./_app/immutable/chunks/DiYtJzYU.js" rel="modulepreload">
|
|
57
|
+
<link href="./_app/immutable/nodes/0.BzvDOlXz.js" rel="modulepreload">
|
|
58
|
+
<link href="./_app/immutable/chunks/_lppinj8.js" rel="modulepreload">
|
|
59
|
+
<link href="./_app/immutable/chunks/B5WJGjcR.js" rel="modulepreload">
|
|
60
|
+
<link href="./_app/immutable/nodes/2.CnZp8abw.js" rel="modulepreload">
|
|
61
|
+
|
|
62
|
+
<link href="./_app/immutable/assets/0.DvZxoQjW.css" rel="stylesheet">
|
|
63
|
+
</head>
|
|
64
|
+
<body data-sveltekit-preload-data="hover">
|
|
65
|
+
<div style="display: contents">
|
|
66
|
+
<script>
|
|
67
|
+
{
|
|
68
|
+
__sveltekit_pphq34 = {
|
|
69
|
+
base: new URL(".", location).pathname.slice(0, -1)
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
const element = document.currentScript.parentElement;
|
|
73
|
+
|
|
74
|
+
Promise.all([
|
|
75
|
+
import("./_app/immutable/entry/start.BceUuq27.js"),
|
|
76
|
+
import("./_app/immutable/entry/app.BFki2czn.js")
|
|
77
|
+
]).then(([kit, app]) => {
|
|
78
|
+
kit.start(app, element);
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
</script>
|
|
82
|
+
</div>
|
|
83
|
+
</body>
|
|
84
|
+
</html>
|
package/public/logo.svg
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 120 120" width="120" height="120">
|
|
2
|
+
<defs>
|
|
3
|
+
<!-- Background glow linear gradient -->
|
|
4
|
+
<linearGradient id="grad" x1="0%" y1="0%" x2="100%" y2="100%">
|
|
5
|
+
<stop offset="0%" stop-color="#06b6d4"/>
|
|
6
|
+
<stop offset="50%" stop-color="#3b82f6"/>
|
|
7
|
+
<stop offset="100%" stop-color="#8b5cf6"/>
|
|
8
|
+
</linearGradient>
|
|
9
|
+
<linearGradient id="waveGrad" x1="0%" y1="0%" x2="100%" y2="100%">
|
|
10
|
+
<stop offset="0%" stop-color="#06b6d4" stop-opacity="0.5"/>
|
|
11
|
+
<stop offset="100%" stop-color="#8b5cf6" stop-opacity="0.5"/>
|
|
12
|
+
</linearGradient>
|
|
13
|
+
<filter id="glow">
|
|
14
|
+
<feGaussianBlur stdDeviation="3" result="coloredBlur"/>
|
|
15
|
+
<feMerge>
|
|
16
|
+
<feMergeNode in="coloredBlur"/>
|
|
17
|
+
<feMergeNode in="SourceGraphic"/>
|
|
18
|
+
</feMerge>
|
|
19
|
+
</filter>
|
|
20
|
+
</defs>
|
|
21
|
+
|
|
22
|
+
<!-- Glowing wireless waves in the background -->
|
|
23
|
+
<g opacity="0.3" filter="url(#glow)">
|
|
24
|
+
<circle cx="60" cy="60" r="48" stroke="url(#waveGrad)" stroke-width="1" fill="none" stroke-dasharray="4 8" />
|
|
25
|
+
<circle cx="60" cy="60" r="36" stroke="url(#waveGrad)" stroke-width="1.5" fill="none" stroke-dasharray="6 6" />
|
|
26
|
+
</g>
|
|
27
|
+
|
|
28
|
+
<!-- Modern, sleek, overlapping loop forming a 'W' -->
|
|
29
|
+
<g filter="url(#glow)">
|
|
30
|
+
<!-- Main W ribbon -->
|
|
31
|
+
<path d="M 28,38 C 28,38 35,82 46,82 C 55,82 54,44 60,44 C 66,44 65,82 74,82 C 85,82 92,38 92,38"
|
|
32
|
+
stroke="url(#grad)"
|
|
33
|
+
stroke-width="10"
|
|
34
|
+
fill="none"
|
|
35
|
+
stroke-linecap="round"
|
|
36
|
+
stroke-linejoin="round"/>
|
|
37
|
+
</g>
|
|
38
|
+
|
|
39
|
+
<!-- Connection / node endpoints -->
|
|
40
|
+
<g>
|
|
41
|
+
<!-- Left endpoint -->
|
|
42
|
+
<circle cx="28" cy="38" r="4" fill="#06b6d4" />
|
|
43
|
+
<circle cx="28" cy="38" r="1.5" fill="#fff" />
|
|
44
|
+
|
|
45
|
+
<!-- Right endpoint -->
|
|
46
|
+
<circle cx="92" cy="38" r="4" fill="#8b5cf6" />
|
|
47
|
+
<circle cx="92" cy="38" r="1.5" fill="#fff" />
|
|
48
|
+
|
|
49
|
+
<!-- Center peak node -->
|
|
50
|
+
<circle cx="60" cy="44" r="3" fill="#3b82f6" />
|
|
51
|
+
</g>
|
|
52
|
+
</svg>
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "Template Website",
|
|
3
|
+
"description": "A template to build website",
|
|
4
|
+
"display": "fullscreen",
|
|
5
|
+
"scope": "../",
|
|
6
|
+
"start_url": "../",
|
|
7
|
+
"background_color": "#000000",
|
|
8
|
+
"theme_color": "#000000",
|
|
9
|
+
"icons": [
|
|
10
|
+
{
|
|
11
|
+
"src": "favicon-192.png",
|
|
12
|
+
"type": "image/png",
|
|
13
|
+
"sizes": "192x192"
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
"src": "favicon-512.png",
|
|
17
|
+
"type": "image/png",
|
|
18
|
+
"sizes": "512x512"
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
"src": "../maskable_icon_512x512.png",
|
|
22
|
+
"type": "image/png",
|
|
23
|
+
"sizes": "512x512",
|
|
24
|
+
"purpose": "maskable"
|
|
25
|
+
}
|
|
26
|
+
]
|
|
27
|
+
}
|
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
const base = /* @__PURE__ */ location.pathname.split("/").slice(0, -1).join("/");
|
|
2
|
+
const build = [
|
|
3
|
+
base + "/_app/immutable/entry/start.BceUuq27.js",
|
|
4
|
+
base + "/_app/immutable/entry/app.BFki2czn.js",
|
|
5
|
+
base + "/_app/immutable/nodes/0.BzvDOlXz.js",
|
|
6
|
+
base + "/_app/immutable/assets/0.DvZxoQjW.css",
|
|
7
|
+
base + "/_app/immutable/nodes/1.DMtW3tA5.js",
|
|
8
|
+
base + "/_app/immutable/nodes/2.CnZp8abw.js",
|
|
9
|
+
base + "/_app/immutable/chunks/B5WJGjcR.js",
|
|
10
|
+
base + "/_app/immutable/chunks/BEWoN05F.js",
|
|
11
|
+
base + "/_app/immutable/chunks/BqMutrfe.js",
|
|
12
|
+
base + "/_app/immutable/chunks/DFxBx2vA.js",
|
|
13
|
+
base + "/_app/immutable/chunks/DiYtJzYU.js",
|
|
14
|
+
base + "/_app/immutable/chunks/_lppinj8.js",
|
|
15
|
+
base + "/_app/immutable/chunks/rMw82gDs.js"
|
|
16
|
+
];
|
|
17
|
+
const files = [
|
|
18
|
+
base + "/icon.png",
|
|
19
|
+
base + "/logo.svg",
|
|
20
|
+
base + "/pwa/apple-touch-icon.png",
|
|
21
|
+
base + "/pwa/favicon-192.png",
|
|
22
|
+
base + "/pwa/favicon-512.png",
|
|
23
|
+
base + "/pwa/favicon.ico",
|
|
24
|
+
base + "/pwa/favicon.png",
|
|
25
|
+
base + "/pwa/manifest.webmanifest"
|
|
26
|
+
];
|
|
27
|
+
const prerendered = [
|
|
28
|
+
base + "/"
|
|
29
|
+
];
|
|
30
|
+
const version = "5214502";
|
|
31
|
+
const ID = version;
|
|
32
|
+
const sw = self;
|
|
33
|
+
let ASSETS = [];
|
|
34
|
+
{
|
|
35
|
+
ASSETS = build.concat(prerendered).concat(files.filter((v) => v.indexOf("pwa/") === -1));
|
|
36
|
+
}
|
|
37
|
+
let _logEnabled = true;
|
|
38
|
+
function log(...args) {
|
|
39
|
+
if (_logEnabled) {
|
|
40
|
+
console.debug(`[Service Worker #${ID}] ${args[0]}`, ...args.slice(1));
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
const CACHE_NAME = `cache-${version}`;
|
|
44
|
+
const regexesOnlineFirst = [];
|
|
45
|
+
{
|
|
46
|
+
regexesOnlineFirst.push("localhost");
|
|
47
|
+
}
|
|
48
|
+
const regexesOnlineOnly = [];
|
|
49
|
+
const regexesCacheFirst = [
|
|
50
|
+
sw.location.origin,
|
|
51
|
+
// 'https://rsms.me/inter/', // TODO remove, used if using font from there
|
|
52
|
+
"cdn",
|
|
53
|
+
".*\\.png$",
|
|
54
|
+
".*\\.svg$"
|
|
55
|
+
];
|
|
56
|
+
const regexesCacheOnly = [];
|
|
57
|
+
log(`Origin: ${sw.location.origin}`);
|
|
58
|
+
sw.addEventListener("install", (event) => {
|
|
59
|
+
log("Install");
|
|
60
|
+
event.waitUntil(
|
|
61
|
+
caches.open(CACHE_NAME).then((cache) => {
|
|
62
|
+
log(`Creating cache: ${CACHE_NAME}`);
|
|
63
|
+
return cache.addAll(ASSETS);
|
|
64
|
+
}).then(() => {
|
|
65
|
+
log(`cache fully fetched!`);
|
|
66
|
+
})
|
|
67
|
+
);
|
|
68
|
+
});
|
|
69
|
+
sw.addEventListener("activate", (event) => {
|
|
70
|
+
log("Activate");
|
|
71
|
+
event.waitUntil(
|
|
72
|
+
caches.keys().then((cacheNames) => {
|
|
73
|
+
return Promise.all(
|
|
74
|
+
cacheNames.map((thisCacheName) => {
|
|
75
|
+
if (thisCacheName !== CACHE_NAME) {
|
|
76
|
+
log(`Deleting: ${thisCacheName}`);
|
|
77
|
+
return caches.delete(thisCacheName);
|
|
78
|
+
}
|
|
79
|
+
})
|
|
80
|
+
).then(() => sw.clients.claim());
|
|
81
|
+
})
|
|
82
|
+
);
|
|
83
|
+
});
|
|
84
|
+
async function fetchAndUpdateCache(request, cache) {
|
|
85
|
+
try {
|
|
86
|
+
const response = await fetch(request);
|
|
87
|
+
try {
|
|
88
|
+
const cache_1 = await caches.open(CACHE_NAME);
|
|
89
|
+
if (request.method === "GET" && request.url.startsWith("http")) {
|
|
90
|
+
cache_1.put(request, response.clone());
|
|
91
|
+
}
|
|
92
|
+
return response;
|
|
93
|
+
} catch (err) {
|
|
94
|
+
log(`error: ${err}`);
|
|
95
|
+
return response;
|
|
96
|
+
}
|
|
97
|
+
} catch (err_1) {
|
|
98
|
+
if (cache) {
|
|
99
|
+
return cache;
|
|
100
|
+
} else {
|
|
101
|
+
return new Response(`Could Not fetch ${request.url}`, {
|
|
102
|
+
status: 503,
|
|
103
|
+
headers: { "Content-Type": "text/plain" }
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
const cacheFirst = {
|
|
109
|
+
method: (request, cache) => {
|
|
110
|
+
log(`Cache first: ${request.url}`);
|
|
111
|
+
const fromNetwork = fetchAndUpdateCache(request, cache);
|
|
112
|
+
return cache || fromNetwork;
|
|
113
|
+
},
|
|
114
|
+
regexes: regexesCacheFirst
|
|
115
|
+
};
|
|
116
|
+
const cacheOnly = {
|
|
117
|
+
method: (request, cache) => {
|
|
118
|
+
log(`Cache only: ${request.url}`);
|
|
119
|
+
return cache || fetchAndUpdateCache(request, cache);
|
|
120
|
+
},
|
|
121
|
+
regexes: regexesCacheOnly
|
|
122
|
+
};
|
|
123
|
+
const onlineFirst = {
|
|
124
|
+
method: (request, cache) => {
|
|
125
|
+
log(`Online first: ${request.url}`);
|
|
126
|
+
return fetchAndUpdateCache(request, cache);
|
|
127
|
+
},
|
|
128
|
+
regexes: regexesOnlineFirst
|
|
129
|
+
};
|
|
130
|
+
const onlineOnly = {
|
|
131
|
+
method: (request) => {
|
|
132
|
+
log(`Online only: ${request.url}`);
|
|
133
|
+
return fetch(request);
|
|
134
|
+
},
|
|
135
|
+
regexes: regexesOnlineOnly
|
|
136
|
+
};
|
|
137
|
+
async function getResponse(event) {
|
|
138
|
+
const request = event.request;
|
|
139
|
+
const registration = sw.registration;
|
|
140
|
+
if (event.request.mode === "navigate" && event.request.method === "GET" && registration.waiting && // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
141
|
+
(await sw.clients.matchAll()).length < 2) {
|
|
142
|
+
log("only one client, skipWaiting as we navigate the page");
|
|
143
|
+
registration.waiting.postMessage("skipWaiting");
|
|
144
|
+
const response2 = new Response("", { headers: { Refresh: "0" } });
|
|
145
|
+
return response2;
|
|
146
|
+
}
|
|
147
|
+
const response = await caches.match(request).then((cache) => {
|
|
148
|
+
const patterns = [onlineFirst, onlineOnly, cacheFirst, cacheOnly];
|
|
149
|
+
for (const pattern of patterns) {
|
|
150
|
+
for (const regex of pattern.regexes) {
|
|
151
|
+
if (RegExp(regex).test(request.url)) {
|
|
152
|
+
return pattern.method(request, cache);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
return onlineFirst.method(request, cache);
|
|
157
|
+
});
|
|
158
|
+
return response;
|
|
159
|
+
}
|
|
160
|
+
sw.addEventListener("fetch", (event) => {
|
|
161
|
+
event.respondWith(getResponse(event));
|
|
162
|
+
});
|
|
163
|
+
sw.addEventListener("message", async function(event) {
|
|
164
|
+
if (event.data && event.data.type === "debug") {
|
|
165
|
+
_logEnabled = event.data.enabled && event.data.level >= 5;
|
|
166
|
+
if (_logEnabled) {
|
|
167
|
+
log(`log enabled ${event.data.level}`);
|
|
168
|
+
}
|
|
169
|
+
} else if (event.data && event.data.type === "ping") {
|
|
170
|
+
log("pong");
|
|
171
|
+
} else if (event.data === "skipWaiting") {
|
|
172
|
+
log(`skipWaiting received`);
|
|
173
|
+
event.waitUntil(sw.skipWaiting());
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
async function getClientsStatus() {
|
|
177
|
+
const windowClients = await sw.clients.matchAll({
|
|
178
|
+
type: "window",
|
|
179
|
+
includeUncontrolled: true
|
|
180
|
+
});
|
|
181
|
+
let atLeastOneVisible;
|
|
182
|
+
let atLeastOneFocused;
|
|
183
|
+
let atLeastOneVisibleAndFocused;
|
|
184
|
+
for (var i = 0; i < windowClients.length; i++) {
|
|
185
|
+
const windowClient = windowClients[i];
|
|
186
|
+
const visible = windowClient.visibilityState === "visible";
|
|
187
|
+
const hasFocus = windowClient.focused;
|
|
188
|
+
if (visible && !atLeastOneVisible) {
|
|
189
|
+
atLeastOneVisible = windowClient;
|
|
190
|
+
}
|
|
191
|
+
if (hasFocus && !atLeastOneFocused) {
|
|
192
|
+
atLeastOneFocused = windowClient;
|
|
193
|
+
}
|
|
194
|
+
if (hasFocus && visible) {
|
|
195
|
+
atLeastOneVisibleAndFocused = windowClient;
|
|
196
|
+
break;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
return {
|
|
200
|
+
atLeastOneFocused,
|
|
201
|
+
atLeastOneVisible,
|
|
202
|
+
atLeastOneVisibleAndFocused
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
async function handlePush(data) {
|
|
206
|
+
const appActive = await getClientsStatus();
|
|
207
|
+
const notificationTuple = {
|
|
208
|
+
title: "Notification",
|
|
209
|
+
options: {
|
|
210
|
+
body: "You have a new notification",
|
|
211
|
+
icon: "/favicon.png",
|
|
212
|
+
// TODO template it ?
|
|
213
|
+
badge: "/favicon.png"
|
|
214
|
+
// TODO template it ?
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
if (data) {
|
|
218
|
+
try {
|
|
219
|
+
const json = JSON.parse(data);
|
|
220
|
+
if (json.web_push === 8030) {
|
|
221
|
+
const notif = json.notification;
|
|
222
|
+
notificationTuple.options = {
|
|
223
|
+
badge: notif.badge,
|
|
224
|
+
body: notif.body,
|
|
225
|
+
data: notif.data,
|
|
226
|
+
dir: notif.dir,
|
|
227
|
+
icon: notif.icon,
|
|
228
|
+
lang: notif.lang,
|
|
229
|
+
requireInteraction: notif.requireInteraction,
|
|
230
|
+
silent: notif.silent,
|
|
231
|
+
tag: notif.tag
|
|
232
|
+
};
|
|
233
|
+
notificationTuple.title = notif.title;
|
|
234
|
+
if (!notificationTuple.options.icon) {
|
|
235
|
+
notificationTuple.options.icon = notif.image;
|
|
236
|
+
}
|
|
237
|
+
if (notif.navigate) {
|
|
238
|
+
if (!notificationTuple.options.data) {
|
|
239
|
+
notificationTuple.options.data = { navigate: notif.navigate };
|
|
240
|
+
} else {
|
|
241
|
+
if (typeof notificationTuple.options.data === "object" && !notificationTuple.options.data.navigate) {
|
|
242
|
+
notificationTuple.options.data = {
|
|
243
|
+
...notificationTuple.options.data,
|
|
244
|
+
navigate: notif.navigate
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
} else {
|
|
250
|
+
notificationTuple.title = json.notification?.title || json.title || "Notification";
|
|
251
|
+
notificationTuple.options = json.notification || json.options;
|
|
252
|
+
}
|
|
253
|
+
} catch {
|
|
254
|
+
notificationTuple.options.body = data;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
log(`handlePush`, data, notificationTuple);
|
|
258
|
+
if (appActive.atLeastOneVisibleAndFocused) {
|
|
259
|
+
log(`posting notification to active app`, notificationTuple);
|
|
260
|
+
appActive.atLeastOneVisibleAndFocused.postMessage({
|
|
261
|
+
type: "notification",
|
|
262
|
+
notification: {
|
|
263
|
+
title: notificationTuple.title,
|
|
264
|
+
options: notificationTuple.options
|
|
265
|
+
}
|
|
266
|
+
});
|
|
267
|
+
} else {
|
|
268
|
+
await sw.registration.showNotification(
|
|
269
|
+
notificationTuple.title,
|
|
270
|
+
notificationTuple.options
|
|
271
|
+
);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
sw.addEventListener("push", function(event) {
|
|
275
|
+
const data = event.data?.text();
|
|
276
|
+
event.waitUntil(handlePush(data));
|
|
277
|
+
});
|
|
278
|
+
async function handleNotificationClick(notification) {
|
|
279
|
+
const windowClients = await sw.clients.matchAll({
|
|
280
|
+
type: "window",
|
|
281
|
+
includeUncontrolled: true
|
|
282
|
+
});
|
|
283
|
+
const swPath = location.pathname;
|
|
284
|
+
const swFolder = swPath.substring(0, swPath.lastIndexOf("/") + 1);
|
|
285
|
+
let url = notification.data?.navigate;
|
|
286
|
+
if (url) {
|
|
287
|
+
if (!url.startsWith("/") && url.indexOf(":/") == -1) {
|
|
288
|
+
url = swFolder + url;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
for (const client of windowClients) {
|
|
292
|
+
log(`${"focus" in client ? "focus-available: " : ""}: ${client.url}`);
|
|
293
|
+
if ("focus" in client) {
|
|
294
|
+
if (url && "navigate" in client) {
|
|
295
|
+
return client.focus().then(() => client.navigate(url));
|
|
296
|
+
}
|
|
297
|
+
return client.focus();
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
if (sw.clients.openWindow) return sw.clients.openWindow(url || "/");
|
|
301
|
+
}
|
|
302
|
+
sw.addEventListener("notificationclick", function(event) {
|
|
303
|
+
event.notification.close();
|
|
304
|
+
event.waitUntil(handleNotificationClick(event.notification));
|
|
305
|
+
});
|