PhilSad commited on
Commit
4978bd9
·
verified ·
1 Parent(s): 823ef2f

Upload 14 files

Browse files
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ index.pck filter=lfs diff=lfs merge=lfs -text
index.144x144.png ADDED
index.180x180.png ADDED
index.512x512.png ADDED
index.apple-touch-icon.png ADDED
index.audio.worklet.js ADDED
@@ -0,0 +1,213 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**************************************************************************/
2
+ /* audio.worklet.js */
3
+ /**************************************************************************/
4
+ /* This file is part of: */
5
+ /* GODOT ENGINE */
6
+ /* https://godotengine.org */
7
+ /**************************************************************************/
8
+ /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9
+ /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10
+ /* */
11
+ /* Permission is hereby granted, free of charge, to any person obtaining */
12
+ /* a copy of this software and associated documentation files (the */
13
+ /* "Software"), to deal in the Software without restriction, including */
14
+ /* without limitation the rights to use, copy, modify, merge, publish, */
15
+ /* distribute, sublicense, and/or sell copies of the Software, and to */
16
+ /* permit persons to whom the Software is furnished to do so, subject to */
17
+ /* the following conditions: */
18
+ /* */
19
+ /* The above copyright notice and this permission notice shall be */
20
+ /* included in all copies or substantial portions of the Software. */
21
+ /* */
22
+ /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23
+ /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24
+ /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25
+ /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26
+ /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27
+ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28
+ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29
+ /**************************************************************************/
30
+
31
+ class RingBuffer {
32
+ constructor(p_buffer, p_state, p_threads) {
33
+ this.buffer = p_buffer;
34
+ this.avail = p_state;
35
+ this.threads = p_threads;
36
+ this.rpos = 0;
37
+ this.wpos = 0;
38
+ }
39
+
40
+ data_left() {
41
+ return this.threads ? Atomics.load(this.avail, 0) : this.avail;
42
+ }
43
+
44
+ space_left() {
45
+ return this.buffer.length - this.data_left();
46
+ }
47
+
48
+ read(output) {
49
+ const size = this.buffer.length;
50
+ let from = 0;
51
+ let to_write = output.length;
52
+ if (this.rpos + to_write > size) {
53
+ const high = size - this.rpos;
54
+ output.set(this.buffer.subarray(this.rpos, size));
55
+ from = high;
56
+ to_write -= high;
57
+ this.rpos = 0;
58
+ }
59
+ if (to_write) {
60
+ output.set(this.buffer.subarray(this.rpos, this.rpos + to_write), from);
61
+ }
62
+ this.rpos += to_write;
63
+ if (this.threads) {
64
+ Atomics.add(this.avail, 0, -output.length);
65
+ Atomics.notify(this.avail, 0);
66
+ } else {
67
+ this.avail -= output.length;
68
+ }
69
+ }
70
+
71
+ write(p_buffer) {
72
+ const to_write = p_buffer.length;
73
+ const mw = this.buffer.length - this.wpos;
74
+ if (mw >= to_write) {
75
+ this.buffer.set(p_buffer, this.wpos);
76
+ this.wpos += to_write;
77
+ if (mw === to_write) {
78
+ this.wpos = 0;
79
+ }
80
+ } else {
81
+ const high = p_buffer.subarray(0, mw);
82
+ const low = p_buffer.subarray(mw);
83
+ this.buffer.set(high, this.wpos);
84
+ this.buffer.set(low);
85
+ this.wpos = low.length;
86
+ }
87
+ if (this.threads) {
88
+ Atomics.add(this.avail, 0, to_write);
89
+ Atomics.notify(this.avail, 0);
90
+ } else {
91
+ this.avail += to_write;
92
+ }
93
+ }
94
+ }
95
+
96
+ class GodotProcessor extends AudioWorkletProcessor {
97
+ constructor() {
98
+ super();
99
+ this.threads = false;
100
+ this.running = true;
101
+ this.lock = null;
102
+ this.notifier = null;
103
+ this.output = null;
104
+ this.output_buffer = new Float32Array();
105
+ this.input = null;
106
+ this.input_buffer = new Float32Array();
107
+ this.port.onmessage = (event) => {
108
+ const cmd = event.data['cmd'];
109
+ const data = event.data['data'];
110
+ this.parse_message(cmd, data);
111
+ };
112
+ }
113
+
114
+ process_notify() {
115
+ if (this.notifier) {
116
+ Atomics.add(this.notifier, 0, 1);
117
+ Atomics.notify(this.notifier, 0);
118
+ }
119
+ }
120
+
121
+ parse_message(p_cmd, p_data) {
122
+ if (p_cmd === 'start' && p_data) {
123
+ const state = p_data[0];
124
+ let idx = 0;
125
+ this.threads = true;
126
+ this.lock = state.subarray(idx, ++idx);
127
+ this.notifier = state.subarray(idx, ++idx);
128
+ const avail_in = state.subarray(idx, ++idx);
129
+ const avail_out = state.subarray(idx, ++idx);
130
+ this.input = new RingBuffer(p_data[1], avail_in, true);
131
+ this.output = new RingBuffer(p_data[2], avail_out, true);
132
+ } else if (p_cmd === 'stop') {
133
+ this.running = false;
134
+ this.output = null;
135
+ this.input = null;
136
+ this.lock = null;
137
+ this.notifier = null;
138
+ } else if (p_cmd === 'start_nothreads') {
139
+ this.output = new RingBuffer(p_data[0], p_data[0].length, false);
140
+ } else if (p_cmd === 'chunk') {
141
+ this.output.write(p_data);
142
+ }
143
+ }
144
+
145
+ static array_has_data(arr) {
146
+ return arr.length && arr[0].length && arr[0][0].length;
147
+ }
148
+
149
+ process(inputs, outputs, parameters) {
150
+ if (!this.running) {
151
+ return false; // Stop processing.
152
+ }
153
+ if (this.output === null) {
154
+ return true; // Not ready yet, keep processing.
155
+ }
156
+ const process_input = GodotProcessor.array_has_data(inputs);
157
+ if (process_input) {
158
+ const input = inputs[0];
159
+ const chunk = input[0].length * input.length;
160
+ if (this.input_buffer.length !== chunk) {
161
+ this.input_buffer = new Float32Array(chunk);
162
+ }
163
+ if (!this.threads) {
164
+ GodotProcessor.write_input(this.input_buffer, input);
165
+ this.port.postMessage({ 'cmd': 'input', 'data': this.input_buffer });
166
+ } else if (this.input.space_left() >= chunk) {
167
+ GodotProcessor.write_input(this.input_buffer, input);
168
+ this.input.write(this.input_buffer);
169
+ } else {
170
+ // this.port.postMessage('Input buffer is full! Skipping input frame.'); // Uncomment this line to debug input buffer.
171
+ }
172
+ }
173
+ const process_output = GodotProcessor.array_has_data(outputs);
174
+ if (process_output) {
175
+ const output = outputs[0];
176
+ const chunk = output[0].length * output.length;
177
+ if (this.output_buffer.length !== chunk) {
178
+ this.output_buffer = new Float32Array(chunk);
179
+ }
180
+ if (this.output.data_left() >= chunk) {
181
+ this.output.read(this.output_buffer);
182
+ GodotProcessor.write_output(output, this.output_buffer);
183
+ if (!this.threads) {
184
+ this.port.postMessage({ 'cmd': 'read', 'data': chunk });
185
+ }
186
+ } else {
187
+ // this.port.postMessage('Output buffer has not enough frames! Skipping output frame.'); // Uncomment this line to debug output buffer.
188
+ }
189
+ }
190
+ this.process_notify();
191
+ return true;
192
+ }
193
+
194
+ static write_output(dest, source) {
195
+ const channels = dest.length;
196
+ for (let ch = 0; ch < channels; ch++) {
197
+ for (let sample = 0; sample < dest[ch].length; sample++) {
198
+ dest[ch][sample] = source[sample * channels + ch];
199
+ }
200
+ }
201
+ }
202
+
203
+ static write_input(dest, source) {
204
+ const channels = source.length;
205
+ for (let ch = 0; ch < channels; ch++) {
206
+ for (let sample = 0; sample < source[ch].length; sample++) {
207
+ dest[sample * channels + ch] = source[ch][sample];
208
+ }
209
+ }
210
+ }
211
+ }
212
+
213
+ registerProcessor('godot-processor', GodotProcessor);
index.html CHANGED
@@ -1,19 +1,200 @@
1
- <!doctype html>
2
- <html>
3
  <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width" />
6
- <title>My static Space</title>
7
- <link rel="stylesheet" href="style.css" />
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  </head>
9
  <body>
10
- <div class="card">
11
- <h1>Welcome to your static Space!</h1>
12
- <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
13
- <p>
14
- Also don't forget to check the
15
- <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
16
- </p>
 
 
 
 
 
17
  </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
  </body>
19
  </html>
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
  <head>
4
+ <meta charset="utf-8">
5
+ <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0">
6
+ <title>GodotProject</title>
7
+ <style>
8
+ html, body, #canvas {
9
+ margin: 0;
10
+ padding: 0;
11
+ border: 0;
12
+ }
13
+
14
+ body {
15
+ color: white;
16
+ background-color: black;
17
+ overflow: hidden;
18
+ touch-action: none;
19
+ }
20
+
21
+ #canvas {
22
+ display: block;
23
+ }
24
+
25
+ #canvas:focus {
26
+ outline: none;
27
+ }
28
+
29
+ #status, #status-splash, #status-progress {
30
+ position: absolute;
31
+ left: 0;
32
+ right: 0;
33
+ }
34
+
35
+ #status, #status-splash {
36
+ top: 0;
37
+ bottom: 0;
38
+ }
39
+
40
+ #status {
41
+ background-color: #242424;
42
+ display: flex;
43
+ flex-direction: column;
44
+ justify-content: center;
45
+ align-items: center;
46
+ visibility: hidden;
47
+ }
48
+
49
+ #status-splash {
50
+ max-height: 100%;
51
+ max-width: 100%;
52
+ margin: auto;
53
+ }
54
+
55
+ #status-progress, #status-notice {
56
+ display: none;
57
+ }
58
+
59
+ #status-progress {
60
+ bottom: 10%;
61
+ width: 50%;
62
+ margin: 0 auto;
63
+ }
64
+
65
+ #status-notice {
66
+ background-color: #5b3943;
67
+ border-radius: 0.5rem;
68
+ border: 1px solid #9b3943;
69
+ color: #e0e0e0;
70
+ font-family: 'Noto Sans', 'Droid Sans', Arial, sans-serif;
71
+ line-height: 1.3;
72
+ margin: 0 2rem;
73
+ overflow: hidden;
74
+ padding: 1rem;
75
+ text-align: center;
76
+ z-index: 1;
77
+ }
78
+ </style>
79
+ <link id="-gd-engine-icon" rel="icon" type="image/png" href="index.icon.png" />
80
+ <link rel="apple-touch-icon" href="index.apple-touch-icon.png"/>
81
+ <link rel="manifest" href="index.manifest.json">
82
+
83
  </head>
84
  <body>
85
+ <canvas id="canvas">
86
+ Your browser does not support the canvas tag.
87
+ </canvas>
88
+
89
+ <noscript>
90
+ Your browser does not support JavaScript.
91
+ </noscript>
92
+
93
+ <div id="status">
94
+ <img id="status-splash" src="index.png" alt="">
95
+ <progress id="status-progress"></progress>
96
+ <div id="status-notice"></div>
97
  </div>
98
+
99
+ <script src="index.js"></script>
100
+ <script>
101
+ const GODOT_CONFIG = {"args":[],"canvasResizePolicy":2,"ensureCrossOriginIsolationHeaders":false,"executable":"index","experimentalVK":false,"fileSizes":{"index.pck":130110016,"index.wasm":43016933},"focusCanvas":true,"gdextensionLibs":[],"serviceWorker":"index.service.worker.js"};
102
+ const GODOT_THREADS_ENABLED = false;
103
+ const engine = new Engine(GODOT_CONFIG);
104
+
105
+ (function () {
106
+ const statusOverlay = document.getElementById('status');
107
+ const statusProgress = document.getElementById('status-progress');
108
+ const statusNotice = document.getElementById('status-notice');
109
+
110
+ let initializing = true;
111
+ let statusMode = '';
112
+
113
+ function setStatusMode(mode) {
114
+ if (statusMode === mode || !initializing) {
115
+ return;
116
+ }
117
+ if (mode === 'hidden') {
118
+ statusOverlay.remove();
119
+ initializing = false;
120
+ return;
121
+ }
122
+ statusOverlay.style.visibility = 'visible';
123
+ statusProgress.style.display = mode === 'progress' ? 'block' : 'none';
124
+ statusNotice.style.display = mode === 'notice' ? 'block' : 'none';
125
+ statusMode = mode;
126
+ }
127
+
128
+ function setStatusNotice(text) {
129
+ while (statusNotice.lastChild) {
130
+ statusNotice.removeChild(statusNotice.lastChild);
131
+ }
132
+ const lines = text.split('\n');
133
+ lines.forEach((line) => {
134
+ statusNotice.appendChild(document.createTextNode(line));
135
+ statusNotice.appendChild(document.createElement('br'));
136
+ });
137
+ }
138
+
139
+ function displayFailureNotice(err) {
140
+ console.error(err);
141
+ if (err instanceof Error) {
142
+ setStatusNotice(err.message);
143
+ } else if (typeof err === 'string') {
144
+ setStatusNotice(err);
145
+ } else {
146
+ setStatusNotice('An unknown error occured');
147
+ }
148
+ setStatusMode('notice');
149
+ initializing = false;
150
+ }
151
+
152
+ const missing = Engine.getMissingFeatures({
153
+ threads: GODOT_THREADS_ENABLED,
154
+ });
155
+
156
+ if (missing.length !== 0) {
157
+ if (GODOT_CONFIG['serviceWorker'] && GODOT_CONFIG['ensureCrossOriginIsolationHeaders'] && 'serviceWorker' in navigator) {
158
+ // There's a chance that installing the service worker would fix the issue
159
+ Promise.race([
160
+ navigator.serviceWorker.getRegistration().then((registration) => {
161
+ if (registration != null) {
162
+ return Promise.reject(new Error('Service worker already exists.'));
163
+ }
164
+ return registration;
165
+ }).then(() => engine.installServiceWorker()),
166
+ // For some reason, `getRegistration()` can stall
167
+ new Promise((resolve) => {
168
+ setTimeout(() => resolve(), 2000);
169
+ }),
170
+ ]).catch((err) => {
171
+ console.error('Error while registering service worker:', err);
172
+ }).then(() => {
173
+ window.location.reload();
174
+ });
175
+ } else {
176
+ // Display the message as usual
177
+ const missingMsg = 'Error\nThe following features required to run Godot projects on the Web are missing:\n';
178
+ displayFailureNotice(missingMsg + missing.join('\n'));
179
+ }
180
+ } else {
181
+ setStatusMode('progress');
182
+ engine.startGame({
183
+ 'onProgress': function (current, total) {
184
+ if (current > 0 && total > 0) {
185
+ statusProgress.value = current;
186
+ statusProgress.max = total;
187
+ } else {
188
+ statusProgress.removeAttribute('value');
189
+ statusProgress.removeAttribute('max');
190
+ }
191
+ },
192
+ }).then(() => {
193
+ setStatusMode('hidden');
194
+ }, displayFailureNotice);
195
+ }
196
+ }());
197
+ </script>
198
  </body>
199
  </html>
200
+
index.icon.png ADDED
index.js ADDED
The diff for this file is too large to render. See raw diff
 
index.manifest.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"background_color":"#000000","display":"standalone","icons":[{"sizes":"144x144","src":"index.144x144.png","type":"image/png"},{"sizes":"180x180","src":"index.180x180.png","type":"image/png"},{"sizes":"512x512","src":"index.512x512.png","type":"image/png"}],"name":"GodotProject","orientation":"any","start_url":"./index.html"}
index.offline.html ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta http-equiv="X-UA-Compatible" content="IE=edge">
6
+ <meta name="viewport" content="width=device-width, initial-scale=1">
7
+ <title>You are offline</title>
8
+ <style>
9
+ html {
10
+ background-color: #000000;
11
+ color: #ffffff;
12
+ }
13
+
14
+ body {
15
+ font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
16
+ margin: 2rem;
17
+ }
18
+
19
+ p {
20
+ margin-block: 1rem;
21
+ }
22
+
23
+ button {
24
+ display: block;
25
+ padding: 1rem 2rem;
26
+ margin: 3rem auto 0;
27
+ }
28
+ </style>
29
+ </head>
30
+ <body>
31
+ <h1>You are offline</h1>
32
+ <p>This application requires an Internet connection to run for the first time.</p>
33
+ <p>Press the button below to try reloading:</p>
34
+ <button type="button">Reload</button>
35
+ <script>
36
+ document.querySelector('button').addEventListener('click', () => {
37
+ window.location.reload();
38
+ });
39
+ </script>
40
+ </body>
41
+ </html>
index.pck ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f1eb2a0cad078a177145d5047133ff94ad7e6ebf737bcaa3d6d9ef31d75e7c6e
3
+ size 130110016
index.png ADDED
index.service.worker.js ADDED
@@ -0,0 +1,166 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // This service worker is required to expose an exported Godot project as a
2
+ // Progressive Web App. It provides an offline fallback page telling the user
3
+ // that they need an Internet connection to run the project if desired.
4
+ // Incrementing CACHE_VERSION will kick off the install event and force
5
+ // previously cached resources to be updated from the network.
6
+ /** @type {string} */
7
+ const CACHE_VERSION = '1737867270|4024896531';
8
+ /** @type {string} */
9
+ const CACHE_PREFIX = 'GodotProject-sw-cache-';
10
+ const CACHE_NAME = CACHE_PREFIX + CACHE_VERSION;
11
+ /** @type {string} */
12
+ const OFFLINE_URL = 'index.offline.html';
13
+ /** @type {boolean} */
14
+ const ENSURE_CROSSORIGIN_ISOLATION_HEADERS = false;
15
+ // Files that will be cached on load.
16
+ /** @type {string[]} */
17
+ const CACHED_FILES = ["index.html","index.js","index.offline.html","index.icon.png","index.apple-touch-icon.png","index.worker.js","index.audio.worklet.js"];
18
+ // Files that we might not want the user to preload, and will only be cached on first load.
19
+ /** @type {string[]} */
20
+ const CACHABLE_FILES = ["index.wasm","index.pck"];
21
+ const FULL_CACHE = CACHED_FILES.concat(CACHABLE_FILES);
22
+
23
+ self.addEventListener('install', (event) => {
24
+ event.waitUntil(caches.open(CACHE_NAME).then((cache) => cache.addAll(CACHED_FILES)));
25
+ });
26
+
27
+ self.addEventListener('activate', (event) => {
28
+ event.waitUntil(caches.keys().then(
29
+ function (keys) {
30
+ // Remove old caches.
31
+ return Promise.all(keys.filter((key) => key.startsWith(CACHE_PREFIX) && key !== CACHE_NAME).map((key) => caches.delete(key)));
32
+ }
33
+ ).then(function () {
34
+ // Enable navigation preload if available.
35
+ return ('navigationPreload' in self.registration) ? self.registration.navigationPreload.enable() : Promise.resolve();
36
+ }));
37
+ });
38
+
39
+ /**
40
+ * Ensures that the response has the correct COEP/COOP headers
41
+ * @param {Response} response
42
+ * @returns {Response}
43
+ */
44
+ function ensureCrossOriginIsolationHeaders(response) {
45
+ if (response.headers.get('Cross-Origin-Embedder-Policy') === 'require-corp'
46
+ && response.headers.get('Cross-Origin-Opener-Policy') === 'same-origin') {
47
+ return response;
48
+ }
49
+
50
+ const crossOriginIsolatedHeaders = new Headers(response.headers);
51
+ crossOriginIsolatedHeaders.set('Cross-Origin-Embedder-Policy', 'require-corp');
52
+ crossOriginIsolatedHeaders.set('Cross-Origin-Opener-Policy', 'same-origin');
53
+ const newResponse = new Response(response.body, {
54
+ status: response.status,
55
+ statusText: response.statusText,
56
+ headers: crossOriginIsolatedHeaders,
57
+ });
58
+
59
+ return newResponse;
60
+ }
61
+
62
+ /**
63
+ * Calls fetch and cache the result if it is cacheable
64
+ * @param {FetchEvent} event
65
+ * @param {Cache} cache
66
+ * @param {boolean} isCacheable
67
+ * @returns {Response}
68
+ */
69
+ async function fetchAndCache(event, cache, isCacheable) {
70
+ // Use the preloaded response, if it's there
71
+ /** @type { Response } */
72
+ let response = await event.preloadResponse;
73
+ if (response == null) {
74
+ // Or, go over network.
75
+ response = await self.fetch(event.request);
76
+ }
77
+
78
+ if (ENSURE_CROSSORIGIN_ISOLATION_HEADERS) {
79
+ response = ensureCrossOriginIsolationHeaders(response);
80
+ }
81
+
82
+ if (isCacheable) {
83
+ // And update the cache
84
+ cache.put(event.request, response.clone());
85
+ }
86
+
87
+ return response;
88
+ }
89
+
90
+ self.addEventListener(
91
+ 'fetch',
92
+ /**
93
+ * Triggered on fetch
94
+ * @param {FetchEvent} event
95
+ */
96
+ (event) => {
97
+ const isNavigate = event.request.mode === 'navigate';
98
+ const url = event.request.url || '';
99
+ const referrer = event.request.referrer || '';
100
+ const base = referrer.slice(0, referrer.lastIndexOf('/') + 1);
101
+ const local = url.startsWith(base) ? url.replace(base, '') : '';
102
+ const isCachable = FULL_CACHE.some((v) => v === local) || (base === referrer && base.endsWith(CACHED_FILES[0]));
103
+ if (isNavigate || isCachable) {
104
+ event.respondWith((async () => {
105
+ // Try to use cache first
106
+ const cache = await caches.open(CACHE_NAME);
107
+ if (isNavigate) {
108
+ // Check if we have full cache during HTML page request.
109
+ /** @type {Response[]} */
110
+ const fullCache = await Promise.all(FULL_CACHE.map((name) => cache.match(name)));
111
+ const missing = fullCache.some((v) => v === undefined);
112
+ if (missing) {
113
+ try {
114
+ // Try network if some cached file is missing (so we can display offline page in case).
115
+ const response = await fetchAndCache(event, cache, isCachable);
116
+ return response;
117
+ } catch (e) {
118
+ // And return the hopefully always cached offline page in case of network failure.
119
+ console.error('Network error: ', e); // eslint-disable-line no-console
120
+ return caches.match(OFFLINE_URL);
121
+ }
122
+ }
123
+ }
124
+ let cached = await cache.match(event.request);
125
+ if (cached != null) {
126
+ if (ENSURE_CROSSORIGIN_ISOLATION_HEADERS) {
127
+ cached = ensureCrossOriginIsolationHeaders(cached);
128
+ }
129
+ return cached;
130
+ }
131
+ // Try network if don't have it in cache.
132
+ const response = await fetchAndCache(event, cache, isCachable);
133
+ return response;
134
+ })());
135
+ } else if (ENSURE_CROSSORIGIN_ISOLATION_HEADERS) {
136
+ event.respondWith((async () => {
137
+ let response = await fetch(event.request);
138
+ response = ensureCrossOriginIsolationHeaders(response);
139
+ return response;
140
+ })());
141
+ }
142
+ }
143
+ );
144
+
145
+ self.addEventListener('message', (event) => {
146
+ // No cross origin
147
+ if (event.origin !== self.origin) {
148
+ return;
149
+ }
150
+ const id = event.source.id || '';
151
+ const msg = event.data || '';
152
+ // Ensure it's one of our clients.
153
+ self.clients.get(id).then(function (client) {
154
+ if (!client) {
155
+ return; // Not a valid client.
156
+ }
157
+ if (msg === 'claim') {
158
+ self.skipWaiting().then(() => self.clients.claim());
159
+ } else if (msg === 'clear') {
160
+ caches.delete(CACHE_NAME);
161
+ } else if (msg === 'update') {
162
+ self.skipWaiting().then(() => self.clients.claim()).then(() => self.clients.matchAll()).then((all) => all.forEach((c) => c.navigate(c.url)));
163
+ }
164
+ });
165
+ });
166
+
index.wasm ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:20bbe3d6bd8f1197b59335c4263b126ac435e8c8c74fa063227121e27210723a
3
+ size 43016933