2020-11-23 13:27:13 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								const Utils = { // eslint-disable-line no-unused-vars
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-19 11:44:19 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2020-11-23 13:27:13 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									createLocateRewrite: function (execName) {
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-19 11:44:19 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
										function rw(path) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
											if (path.endsWith('.worker.js')) {
							 | 
						
					
						
							
								
									
										
										
										
											2020-11-23 13:27:13 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
												return `${execName}.worker.js`;
							 | 
						
					
						
							
								
									
										
										
										
											2020-11-03 17:18:02 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											} else if (path.endsWith('.audio.worklet.js')) {
							 | 
						
					
						
							
								
									
										
										
										
											2020-11-23 13:27:13 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
												return `${execName}.audio.worklet.js`;
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-19 11:44:19 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
											} else if (path.endsWith('.js')) {
							 | 
						
					
						
							
								
									
										
										
										
											2020-11-23 13:27:13 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
												return `${execName}.js`;
							 | 
						
					
						
							
								
									
										
										
										
											2020-10-24 16:02:09 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											} else if (path.endsWith('.side.wasm')) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
												return `${execName}.side.wasm`;
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-19 11:44:19 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
											} else if (path.endsWith('.wasm')) {
							 | 
						
					
						
							
								
									
										
										
										
											2020-11-23 13:27:13 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
												return `${execName}.wasm`;
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-19 11:44:19 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
											}
							 | 
						
					
						
							
								
									
										
										
										
											2020-11-19 16:54:07 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											return path;
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-19 11:44:19 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
										}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										return rw;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									},
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2020-11-23 13:27:13 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									createInstantiatePromise: function (wasmLoader) {
							 | 
						
					
						
							
								
									
										
										
										
											2020-11-19 16:54:07 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										let loader = wasmLoader;
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-19 11:44:19 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
										function instantiateWasm(imports, onSuccess) {
							 | 
						
					
						
							
								
									
										
										
										
											2020-11-23 13:27:13 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											loader.then(function (xhr) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
												WebAssembly.instantiate(xhr.response, imports).then(function (result) {
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-19 11:44:19 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
													onSuccess(result['instance'], result['module']);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
												});
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
											});
							 | 
						
					
						
							
								
									
										
										
										
											2020-11-19 16:54:07 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											loader = null;
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-19 11:44:19 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
											return {};
							 | 
						
					
						
							
								
									
										
										
										
											2020-11-23 13:27:13 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										}
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-19 11:44:19 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										return instantiateWasm;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									},
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2020-11-23 13:27:13 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									findCanvas: function () {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										const nodes = document.getElementsByTagName('canvas');
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-19 11:44:19 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
										if (nodes.length && nodes[0] instanceof HTMLCanvasElement) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
											return nodes[0];
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										}
							 | 
						
					
						
							
								
									
										
										
										
											2020-11-19 16:54:07 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										return null;
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-19 11:44:19 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
									},
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2020-11-23 13:27:13 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									isWebGLAvailable: function (majorVersion = 1) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										let testContext = false;
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-19 11:44:19 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
										try {
							 | 
						
					
						
							
								
									
										
										
										
											2020-11-23 13:27:13 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											const testCanvas = document.createElement('canvas');
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-19 11:44:19 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
											if (majorVersion === 1) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
												testContext = testCanvas.getContext('webgl') || testCanvas.getContext('experimental-webgl');
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
											} else if (majorVersion === 2) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
												testContext = testCanvas.getContext('webgl2') || testCanvas.getContext('experimental-webgl2');
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
											}
							 | 
						
					
						
							
								
									
										
										
										
											2020-11-19 16:54:07 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										} catch (e) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
											// Not available
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										}
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-19 11:44:19 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
										return !!testContext;
							 | 
						
					
						
							
								
									
										
										
										
											2020-11-23 13:27:13 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									},
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-19 11:44:19 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								};
							 |