three
Version:
JavaScript 3D library
1,297 lines (1,295 loc) • 1.5 MB
JavaScript
var __defProp = Object.defineProperty;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues = (a, b) => {
for (var prop in b || (b = {}))
if (__hasOwnProp.call(b, prop))
__defNormalProp(a, prop, b[prop]);
if (__getOwnPropSymbols)
for (var prop of __getOwnPropSymbols(b)) {
if (__propIsEnum.call(b, prop))
__defNormalProp(a, prop, b[prop]);
}
return a;
};
var __require = (x) => {
if (typeof require !== "undefined")
return require(x);
throw new Error('Dynamic require of "' + x + '" is not supported');
};
var __commonJS = (cb, mod) => function __require2() {
return mod || (0, cb[Object.keys(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
};
var __async = (__this, __arguments, generator) => {
return new Promise((resolve, reject) => {
var fulfilled = (value) => {
try {
step(generator.next(value));
} catch (e) {
reject(e);
}
};
var rejected = (value) => {
try {
step(generator.throw(value));
} catch (e) {
reject(e);
}
};
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
step((generator = generator.apply(__this, __arguments)).next());
});
};
// (disabled):crypto
var require_crypto = __commonJS({
"(disabled):crypto"() {
}
});
// dist/web-ifc.js
var require_web_ifc = __commonJS({
"dist/web-ifc.js"(exports, module) {
var WebIFCWasm2 = function() {
var _scriptDir = typeof document !== "undefined" && document.currentScript ? document.currentScript.src : void 0;
if (typeof __filename !== "undefined")
_scriptDir = _scriptDir || __filename;
return function(WebIFCWasm3) {
WebIFCWasm3 = WebIFCWasm3 || {};
var Module = typeof WebIFCWasm3 !== "undefined" ? WebIFCWasm3 : {};
var readyPromiseResolve, readyPromiseReject;
Module["ready"] = new Promise(function(resolve, reject) {
readyPromiseResolve = resolve;
readyPromiseReject = reject;
});
var moduleOverrides = {};
var key;
for (key in Module) {
if (Module.hasOwnProperty(key)) {
moduleOverrides[key] = Module[key];
}
}
var arguments_ = [];
var thisProgram = "./this.program";
var quit_ = function(status, toThrow) {
throw toThrow;
};
var ENVIRONMENT_IS_WEB = false;
var ENVIRONMENT_IS_WORKER = false;
var ENVIRONMENT_IS_NODE = false;
var ENVIRONMENT_IS_SHELL = false;
ENVIRONMENT_IS_WEB = typeof window === "object";
ENVIRONMENT_IS_WORKER = typeof importScripts === "function";
ENVIRONMENT_IS_NODE = typeof process === "object" && typeof process.versions === "object" && typeof process.versions.node === "string";
ENVIRONMENT_IS_SHELL = !ENVIRONMENT_IS_WEB && !ENVIRONMENT_IS_NODE && !ENVIRONMENT_IS_WORKER;
var scriptDirectory = "";
function locateFile(path) {
if (Module["locateFile"]) {
return Module["locateFile"](path, scriptDirectory);
}
return scriptDirectory + path;
}
var read_, readAsync, readBinary, setWindowTitle;
var nodeFS;
var nodePath;
if (ENVIRONMENT_IS_NODE) {
if (ENVIRONMENT_IS_WORKER) {
scriptDirectory = __require("path").dirname(scriptDirectory) + "/";
} else {
scriptDirectory = __dirname + "/";
}
read_ = function shell_read(filename, binary) {
if (!nodeFS)
nodeFS = __require("fs");
if (!nodePath)
nodePath = __require("path");
filename = nodePath["normalize"](filename);
return nodeFS["readFileSync"](filename, binary ? null : "utf8");
};
readBinary = function readBinary2(filename) {
var ret = read_(filename, true);
if (!ret.buffer) {
ret = new Uint8Array(ret);
}
assert(ret.buffer);
return ret;
};
if (process["argv"].length > 1) {
thisProgram = process["argv"][1].replace(/\\/g, "/");
}
arguments_ = process["argv"].slice(2);
process["on"]("uncaughtException", function(ex) {
if (!(ex instanceof ExitStatus)) {
throw ex;
}
});
process["on"]("unhandledRejection", abort);
quit_ = function(status) {
process["exit"](status);
};
Module["inspect"] = function() {
return "[Emscripten Module object]";
};
} else if (ENVIRONMENT_IS_SHELL) {
if (typeof read != "undefined") {
read_ = function shell_read(f) {
return read(f);
};
}
readBinary = function readBinary2(f) {
var data;
if (typeof readbuffer === "function") {
return new Uint8Array(readbuffer(f));
}
data = read(f, "binary");
assert(typeof data === "object");
return data;
};
if (typeof scriptArgs != "undefined") {
arguments_ = scriptArgs;
} else if (typeof arguments != "undefined") {
arguments_ = arguments;
}
if (typeof quit === "function") {
quit_ = function(status) {
quit(status);
};
}
if (typeof print !== "undefined") {
if (typeof console === "undefined")
console = {};
console.log = print;
console.warn = console.error = typeof printErr !== "undefined" ? printErr : print;
}
} else if (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER) {
if (ENVIRONMENT_IS_WORKER) {
scriptDirectory = self.location.href;
} else if (typeof document !== "undefined" && document.currentScript) {
scriptDirectory = document.currentScript.src;
}
if (_scriptDir) {
scriptDirectory = _scriptDir;
}
if (scriptDirectory.indexOf("blob:") !== 0) {
scriptDirectory = scriptDirectory.slice(0, scriptDirectory.lastIndexOf("/") + 1);
} else {
scriptDirectory = "";
}
{
read_ = function shell_read(url) {
var xhr = new XMLHttpRequest();
xhr.open("GET", url, false);
xhr.send(null);
return xhr.responseText;
};
if (ENVIRONMENT_IS_WORKER) {
readBinary = function readBinary2(url) {
var xhr = new XMLHttpRequest();
xhr.open("GET", url, false);
xhr.responseType = "arraybuffer";
xhr.send(null);
return new Uint8Array(xhr.response);
};
}
readAsync = function readAsync2(url, onload, onerror) {
var xhr = new XMLHttpRequest();
xhr.open("GET", url, true);
xhr.responseType = "arraybuffer";
xhr.onload = function xhr_onload() {
if (xhr.status == 200 || xhr.status == 0 && xhr.response) {
onload(xhr.response);
return;
}
onerror();
};
xhr.onerror = onerror;
xhr.send(null);
};
}
setWindowTitle = function(title) {
document.title = title;
};
} else {
}
var out = Module["print"] || console.log.bind(console);
var err = Module["printErr"] || console.warn.bind(console);
for (key in moduleOverrides) {
if (moduleOverrides.hasOwnProperty(key)) {
Module[key] = moduleOverrides[key];
}
}
moduleOverrides = null;
if (Module["arguments"])
arguments_ = Module["arguments"];
if (Module["thisProgram"])
thisProgram = Module["thisProgram"];
if (Module["quit"])
quit_ = Module["quit"];
var STACK_ALIGN = 16;
function alignMemory(size, factor) {
if (!factor)
factor = STACK_ALIGN;
return Math.ceil(size / factor) * factor;
}
var tempRet0 = 0;
var setTempRet0 = function(value) {
tempRet0 = value;
};
var wasmBinary;
if (Module["wasmBinary"])
wasmBinary = Module["wasmBinary"];
var noExitRuntime;
if (Module["noExitRuntime"])
noExitRuntime = Module["noExitRuntime"];
if (typeof WebAssembly !== "object") {
abort("no native wasm support detected");
}
var wasmMemory;
var ABORT = false;
var EXITSTATUS = 0;
function assert(condition, text) {
if (!condition) {
abort("Assertion failed: " + text);
}
}
var UTF8Decoder = typeof TextDecoder !== "undefined" ? new TextDecoder("utf8") : void 0;
function UTF8ArrayToString(heap, idx, maxBytesToRead) {
idx >>>= 0;
var endIdx = idx + maxBytesToRead;
var endPtr = idx;
while (heap[endPtr >>> 0] && !(endPtr >= endIdx))
++endPtr;
if (endPtr - idx > 16 && heap.subarray && UTF8Decoder) {
return UTF8Decoder.decode(heap.subarray(idx >>> 0, endPtr >>> 0));
} else {
var str = "";
while (idx < endPtr) {
var u0 = heap[idx++ >>> 0];
if (!(u0 & 128)) {
str += String.fromCharCode(u0);
continue;
}
var u1 = heap[idx++ >>> 0] & 63;
if ((u0 & 224) == 192) {
str += String.fromCharCode((u0 & 31) << 6 | u1);
continue;
}
var u2 = heap[idx++ >>> 0] & 63;
if ((u0 & 240) == 224) {
u0 = (u0 & 15) << 12 | u1 << 6 | u2;
} else {
u0 = (u0 & 7) << 18 | u1 << 12 | u2 << 6 | heap[idx++ >>> 0] & 63;
}
if (u0 < 65536) {
str += String.fromCharCode(u0);
} else {
var ch = u0 - 65536;
str += String.fromCharCode(55296 | ch >> 10, 56320 | ch & 1023);
}
}
}
return str;
}
function UTF8ToString(ptr, maxBytesToRead) {
ptr >>>= 0;
return ptr ? UTF8ArrayToString(HEAPU8, ptr, maxBytesToRead) : "";
}
function stringToUTF8Array(str, heap, outIdx, maxBytesToWrite) {
outIdx >>>= 0;
if (!(maxBytesToWrite > 0))
return 0;
var startIdx = outIdx;
var endIdx = outIdx + maxBytesToWrite - 1;
for (var i = 0; i < str.length; ++i) {
var u = str.charCodeAt(i);
if (u >= 55296 && u <= 57343) {
var u1 = str.charCodeAt(++i);
u = 65536 + ((u & 1023) << 10) | u1 & 1023;
}
if (u <= 127) {
if (outIdx >= endIdx)
break;
heap[outIdx++ >>> 0] = u;
} else if (u <= 2047) {
if (outIdx + 1 >= endIdx)
break;
heap[outIdx++ >>> 0] = 192 | u >> 6;
heap[outIdx++ >>> 0] = 128 | u & 63;
} else if (u <= 65535) {
if (outIdx + 2 >= endIdx)
break;
heap[outIdx++ >>> 0] = 224 | u >> 12;
heap[outIdx++ >>> 0] = 128 | u >> 6 & 63;
heap[outIdx++ >>> 0] = 128 | u & 63;
} else {
if (outIdx + 3 >= endIdx)
break;
heap[outIdx++ >>> 0] = 240 | u >> 18;
heap[outIdx++ >>> 0] = 128 | u >> 12 & 63;
heap[outIdx++ >>> 0] = 128 | u >> 6 & 63;
heap[outIdx++ >>> 0] = 128 | u & 63;
}
}
heap[outIdx >>> 0] = 0;
return outIdx - startIdx;
}
function stringToUTF8(str, outPtr, maxBytesToWrite) {
return stringToUTF8Array(str, HEAPU8, outPtr, maxBytesToWrite);
}
function lengthBytesUTF8(str) {
var len = 0;
for (var i = 0; i < str.length; ++i) {
var u = str.charCodeAt(i);
if (u >= 55296 && u <= 57343)
u = 65536 + ((u & 1023) << 10) | str.charCodeAt(++i) & 1023;
if (u <= 127)
++len;
else if (u <= 2047)
len += 2;
else if (u <= 65535)
len += 3;
else
len += 4;
}
return len;
}
var UTF16Decoder = typeof TextDecoder !== "undefined" ? new TextDecoder("utf-16le") : void 0;
function UTF16ToString(ptr, maxBytesToRead) {
var endPtr = ptr;
var idx = endPtr >> 1;
var maxIdx = idx + maxBytesToRead / 2;
while (!(idx >= maxIdx) && HEAPU16[idx >>> 0])
++idx;
endPtr = idx << 1;
if (endPtr - ptr > 32 && UTF16Decoder) {
return UTF16Decoder.decode(HEAPU8.subarray(ptr >>> 0, endPtr >>> 0));
} else {
var str = "";
for (var i = 0; !(i >= maxBytesToRead / 2); ++i) {
var codeUnit = HEAP16[ptr + i * 2 >>> 1];
if (codeUnit == 0)
break;
str += String.fromCharCode(codeUnit);
}
return str;
}
}
function stringToUTF16(str, outPtr, maxBytesToWrite) {
if (maxBytesToWrite === void 0) {
maxBytesToWrite = 2147483647;
}
if (maxBytesToWrite < 2)
return 0;
maxBytesToWrite -= 2;
var startPtr = outPtr;
var numCharsToWrite = maxBytesToWrite < str.length * 2 ? maxBytesToWrite / 2 : str.length;
for (var i = 0; i < numCharsToWrite; ++i) {
var codeUnit = str.charCodeAt(i);
HEAP16[outPtr >>> 1] = codeUnit;
outPtr += 2;
}
HEAP16[outPtr >>> 1] = 0;
return outPtr - startPtr;
}
function lengthBytesUTF16(str) {
return str.length * 2;
}
function UTF32ToString(ptr, maxBytesToRead) {
var i = 0;
var str = "";
while (!(i >= maxBytesToRead / 4)) {
var utf32 = HEAP32[ptr + i * 4 >>> 2];
if (utf32 == 0)
break;
++i;
if (utf32 >= 65536) {
var ch = utf32 - 65536;
str += String.fromCharCode(55296 | ch >> 10, 56320 | ch & 1023);
} else {
str += String.fromCharCode(utf32);
}
}
return str;
}
function stringToUTF32(str, outPtr, maxBytesToWrite) {
outPtr >>>= 0;
if (maxBytesToWrite === void 0) {
maxBytesToWrite = 2147483647;
}
if (maxBytesToWrite < 4)
return 0;
var startPtr = outPtr;
var endPtr = startPtr + maxBytesToWrite - 4;
for (var i = 0; i < str.length; ++i) {
var codeUnit = str.charCodeAt(i);
if (codeUnit >= 55296 && codeUnit <= 57343) {
var trailSurrogate = str.charCodeAt(++i);
codeUnit = 65536 + ((codeUnit & 1023) << 10) | trailSurrogate & 1023;
}
HEAP32[outPtr >>> 2] = codeUnit;
outPtr += 4;
if (outPtr + 4 > endPtr)
break;
}
HEAP32[outPtr >>> 2] = 0;
return outPtr - startPtr;
}
function lengthBytesUTF32(str) {
var len = 0;
for (var i = 0; i < str.length; ++i) {
var codeUnit = str.charCodeAt(i);
if (codeUnit >= 55296 && codeUnit <= 57343)
++i;
len += 4;
}
return len;
}
function writeArrayToMemory(array, buffer2) {
HEAP8.set(array, buffer2 >>> 0);
}
function writeAsciiToMemory(str, buffer2, dontAddNull) {
for (var i = 0; i < str.length; ++i) {
HEAP8[buffer2++ >>> 0] = str.charCodeAt(i);
}
if (!dontAddNull)
HEAP8[buffer2 >>> 0] = 0;
}
function alignUp(x, multiple) {
if (x % multiple > 0) {
x += multiple - x % multiple;
}
return x;
}
var buffer, HEAP8, HEAPU8, HEAP16, HEAPU16, HEAP32, HEAPU32, HEAPF32, HEAPF64;
function updateGlobalBufferAndViews(buf) {
buffer = buf;
Module["HEAP8"] = HEAP8 = new Int8Array(buf);
Module["HEAP16"] = HEAP16 = new Int16Array(buf);
Module["HEAP32"] = HEAP32 = new Int32Array(buf);
Module["HEAPU8"] = HEAPU8 = new Uint8Array(buf);
Module["HEAPU16"] = HEAPU16 = new Uint16Array(buf);
Module["HEAPU32"] = HEAPU32 = new Uint32Array(buf);
Module["HEAPF32"] = HEAPF32 = new Float32Array(buf);
Module["HEAPF64"] = HEAPF64 = new Float64Array(buf);
}
var INITIAL_MEMORY = Module["INITIAL_MEMORY"] || 16777216;
if (Module["wasmMemory"]) {
wasmMemory = Module["wasmMemory"];
} else {
wasmMemory = new WebAssembly.Memory({ "initial": INITIAL_MEMORY / 65536, "maximum": 4294967296 / 65536 });
}
if (wasmMemory) {
buffer = wasmMemory.buffer;
}
INITIAL_MEMORY = buffer.byteLength;
updateGlobalBufferAndViews(buffer);
var wasmTable;
var __ATPRERUN__ = [];
var __ATINIT__ = [];
var __ATMAIN__ = [];
var __ATPOSTRUN__ = [];
var runtimeInitialized = false;
var runtimeExited = false;
function preRun() {
if (Module["preRun"]) {
if (typeof Module["preRun"] == "function")
Module["preRun"] = [Module["preRun"]];
while (Module["preRun"].length) {
addOnPreRun(Module["preRun"].shift());
}
}
callRuntimeCallbacks(__ATPRERUN__);
}
function initRuntime() {
runtimeInitialized = true;
if (!Module["noFSInit"] && !FS.init.initialized)
FS.init();
TTY.init();
callRuntimeCallbacks(__ATINIT__);
}
function preMain() {
FS.ignorePermissions = false;
callRuntimeCallbacks(__ATMAIN__);
}
function exitRuntime() {
runtimeExited = true;
}
function postRun() {
if (Module["postRun"]) {
if (typeof Module["postRun"] == "function")
Module["postRun"] = [Module["postRun"]];
while (Module["postRun"].length) {
addOnPostRun(Module["postRun"].shift());
}
}
callRuntimeCallbacks(__ATPOSTRUN__);
}
function addOnPreRun(cb) {
__ATPRERUN__.unshift(cb);
}
function addOnPostRun(cb) {
__ATPOSTRUN__.unshift(cb);
}
var runDependencies = 0;
var runDependencyWatcher = null;
var dependenciesFulfilled = null;
function getUniqueRunDependency(id) {
return id;
}
function addRunDependency(id) {
runDependencies++;
if (Module["monitorRunDependencies"]) {
Module["monitorRunDependencies"](runDependencies);
}
}
function removeRunDependency(id) {
runDependencies--;
if (Module["monitorRunDependencies"]) {
Module["monitorRunDependencies"](runDependencies);
}
if (runDependencies == 0) {
if (runDependencyWatcher !== null) {
clearInterval(runDependencyWatcher);
runDependencyWatcher = null;
}
if (dependenciesFulfilled) {
var callback = dependenciesFulfilled;
dependenciesFulfilled = null;
callback();
}
}
}
Module["preloadedImages"] = {};
Module["preloadedAudios"] = {};
function abort(what) {
if (Module["onAbort"]) {
Module["onAbort"](what);
}
what += "";
err(what);
ABORT = true;
EXITSTATUS = 1;
what = "abort(" + what + "). Build with -s ASSERTIONS=1 for more info.";
var e = new WebAssembly.RuntimeError(what);
readyPromiseReject(e);
throw e;
}
function hasPrefix(str, prefix) {
return String.prototype.startsWith ? str.startsWith(prefix) : str.indexOf(prefix) === 0;
}
var dataURIPrefix = "data:application/octet-stream;base64,";
function isDataURI(filename) {
return hasPrefix(filename, dataURIPrefix);
}
var fileURIPrefix = "file://";
function isFileURI(filename) {
return hasPrefix(filename, fileURIPrefix);
}
var wasmBinaryFile = WasmPath + "web-ifc.wasm";
if (!isDataURI(wasmBinaryFile)) {
wasmBinaryFile = locateFile(wasmBinaryFile);
}
function getBinary() {
try {
if (wasmBinary) {
return new Uint8Array(wasmBinary);
}
if (readBinary) {
return readBinary(wasmBinaryFile);
} else {
throw "both async and sync fetching of the wasm failed";
}
} catch (err2) {
abort(err2);
}
}
function getBinaryPromise() {
if (!wasmBinary && (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER) && typeof fetch === "function" && !isFileURI(wasmBinaryFile)) {
return fetch(wasmBinaryFile, { credentials: "same-origin" }).then(function(response) {
if (!response["ok"]) {
throw "failed to load wasm binary file at '" + wasmBinaryFile + "'";
}
return response["arrayBuffer"]();
}).catch(function() {
return getBinary();
});
}
return Promise.resolve().then(getBinary);
}
function createWasm() {
var info = { "a": asmLibraryArg };
function receiveInstance(instance, module2) {
var exports3 = instance.exports;
Module["asm"] = exports3;
wasmTable = Module["asm"]["X"];
removeRunDependency("wasm-instantiate");
}
addRunDependency("wasm-instantiate");
function receiveInstantiatedSource(output) {
receiveInstance(output["instance"]);
}
function instantiateArrayBuffer(receiver) {
return getBinaryPromise().then(function(binary) {
return WebAssembly.instantiate(binary, info);
}).then(receiver, function(reason) {
err("failed to asynchronously prepare wasm: " + reason);
abort(reason);
});
}
function instantiateAsync() {
if (!wasmBinary && typeof WebAssembly.instantiateStreaming === "function" && !isDataURI(wasmBinaryFile) && !isFileURI(wasmBinaryFile) && typeof fetch === "function") {
return fetch(wasmBinaryFile, { credentials: "same-origin" }).then(function(response) {
var result = WebAssembly.instantiateStreaming(response, info);
return result.then(receiveInstantiatedSource, function(reason) {
err("wasm streaming compile failed: " + reason);
err("falling back to ArrayBuffer instantiation");
return instantiateArrayBuffer(receiveInstantiatedSource);
});
});
} else {
return instantiateArrayBuffer(receiveInstantiatedSource);
}
}
if (Module["instantiateWasm"]) {
try {
var exports2 = Module["instantiateWasm"](info, receiveInstance);
return exports2;
} catch (e) {
err("Module.instantiateWasm callback failed with error: " + e);
return false;
}
}
instantiateAsync().catch(readyPromiseReject);
return {};
}
var tempDouble;
var tempI64;
function callRuntimeCallbacks(callbacks) {
while (callbacks.length > 0) {
var callback = callbacks.shift();
if (typeof callback == "function") {
callback(Module);
continue;
}
var func = callback.func;
if (typeof func === "number") {
if (callback.arg === void 0) {
wasmTable.get(func)();
} else {
wasmTable.get(func)(callback.arg);
}
} else {
func(callback.arg === void 0 ? null : callback.arg);
}
}
}
function dynCallLegacy(sig, ptr, args) {
if (args && args.length) {
return Module["dynCall_" + sig].apply(null, [ptr].concat(args));
}
return Module["dynCall_" + sig].call(null, ptr);
}
function dynCall(sig, ptr, args) {
if (sig.indexOf("j") != -1) {
return dynCallLegacy(sig, ptr, args);
}
return wasmTable.get(ptr).apply(null, args);
}
function ___assert_fail(condition, filename, line, func) {
abort("Assertion failed: " + UTF8ToString(condition) + ", at: " + [filename ? UTF8ToString(filename) : "unknown filename", line, func ? UTF8ToString(func) : "unknown function"]);
}
function setErrNo(value) {
HEAP32[___errno_location() >>> 2] = value;
return value;
}
var PATH = { splitPath: function(filename) {
var splitPathRe = /^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/;
return splitPathRe.exec(filename).slice(1);
}, normalizeArray: function(parts, allowAboveRoot) {
var up = 0;
for (var i = parts.length - 1; i >= 0; i--) {
var last = parts[i];
if (last === ".") {
parts.splice(i, 1);
} else if (last === "..") {
parts.splice(i, 1);
up++;
} else if (up) {
parts.splice(i, 1);
up--;
}
}
if (allowAboveRoot) {
for (; up; up--) {
parts.unshift("..");
}
}
return parts;
}, normalize: function(path) {
var isAbsolute = path.charAt(0) === "/", trailingSlash = path.slice(-1) === "/";
path = PATH.normalizeArray(path.split("/").filter(function(p) {
return !!p;
}), !isAbsolute).join("/");
if (!path && !isAbsolute) {
path = ".";
}
if (path && trailingSlash) {
path += "/";
}
return (isAbsolute ? "/" : "") + path;
}, dirname: function(path) {
var result = PATH.splitPath(path), root = result[0], dir = result[1];
if (!root && !dir) {
return ".";
}
if (dir) {
dir = dir.slice(0, dir.length - 1);
}
return root + dir;
}, basename: function(path) {
if (path === "/")
return "/";
path = PATH.normalize(path);
path = path.replace(/\/$/, "");
var lastSlash = path.lastIndexOf("/");
if (lastSlash === -1)
return path;
return path.slice(lastSlash + 1);
}, extname: function(path) {
return PATH.splitPath(path)[3];
}, join: function() {
var paths = Array.prototype.slice.call(arguments, 0);
return PATH.normalize(paths.join("/"));
}, join2: function(l, r) {
return PATH.normalize(l + "/" + r);
} };
function getRandomDevice() {
if (typeof crypto === "object" && typeof crypto["getRandomValues"] === "function") {
var randomBuffer = new Uint8Array(1);
return function() {
crypto.getRandomValues(randomBuffer);
return randomBuffer[0];
};
} else if (ENVIRONMENT_IS_NODE) {
try {
var crypto_module = require_crypto();
return function() {
return crypto_module["randomBytes"](1)[0];
};
} catch (e) {
}
}
return function() {
abort("randomDevice");
};
}
var PATH_FS = { resolve: function() {
var resolvedPath = "", resolvedAbsolute = false;
for (var i = arguments.length - 1; i >= -1 && !resolvedAbsolute; i--) {
var path = i >= 0 ? arguments[i] : FS.cwd();
if (typeof path !== "string") {
throw new TypeError("Arguments to path.resolve must be strings");
} else if (!path) {
return "";
}
resolvedPath = path + "/" + resolvedPath;
resolvedAbsolute = path.charAt(0) === "/";
}
resolvedPath = PATH.normalizeArray(resolvedPath.split("/").filter(function(p) {
return !!p;
}), !resolvedAbsolute).join("/");
return (resolvedAbsolute ? "/" : "") + resolvedPath || ".";
}, relative: function(from, to) {
from = PATH_FS.resolve(from).slice(1);
to = PATH_FS.resolve(to).slice(1);
function trim(arr) {
var start = 0;
for (; start < arr.length; start++) {
if (arr[start] !== "")
break;
}
var end = arr.length - 1;
for (; end >= 0; end--) {
if (arr[end] !== "")
break;
}
if (start > end)
return [];
return arr.slice(start, end - start + 1);
}
var fromParts = trim(from.split("/"));
var toParts = trim(to.split("/"));
var length = Math.min(fromParts.length, toParts.length);
var samePartsLength = length;
for (var i = 0; i < length; i++) {
if (fromParts[i] !== toParts[i]) {
samePartsLength = i;
break;
}
}
var outputParts = [];
for (var i = samePartsLength; i < fromParts.length; i++) {
outputParts.push("..");
}
outputParts = outputParts.concat(toParts.slice(samePartsLength));
return outputParts.join("/");
} };
var TTY = { ttys: [], init: function() {
}, shutdown: function() {
}, register: function(dev, ops) {
TTY.ttys[dev] = { input: [], output: [], ops };
FS.registerDevice(dev, TTY.stream_ops);
}, stream_ops: { open: function(stream) {
var tty = TTY.ttys[stream.node.rdev];
if (!tty) {
throw new FS.ErrnoError(43);
}
stream.tty = tty;
stream.seekable = false;
}, close: function(stream) {
stream.tty.ops.flush(stream.tty);
}, flush: function(stream) {
stream.tty.ops.flush(stream.tty);
}, read: function(stream, buffer2, offset, length, pos) {
if (!stream.tty || !stream.tty.ops.get_char) {
throw new FS.ErrnoError(60);
}
var bytesRead = 0;
for (var i = 0; i < length; i++) {
var result;
try {
result = stream.tty.ops.get_char(stream.tty);
} catch (e) {
throw new FS.ErrnoError(29);
}
if (result === void 0 && bytesRead === 0) {
throw new FS.ErrnoError(6);
}
if (result === null || result === void 0)
break;
bytesRead++;
buffer2[offset + i] = result;
}
if (bytesRead) {
stream.node.timestamp = Date.now();
}
return bytesRead;
}, write: function(stream, buffer2, offset, length, pos) {
if (!stream.tty || !stream.tty.ops.put_char) {
throw new FS.ErrnoError(60);
}
try {
for (var i = 0; i < length; i++) {
stream.tty.ops.put_char(stream.tty, buffer2[offset + i]);
}
} catch (e) {
throw new FS.ErrnoError(29);
}
if (length) {
stream.node.timestamp = Date.now();
}
return i;
} }, default_tty_ops: { get_char: function(tty) {
if (!tty.input.length) {
var result = null;
if (ENVIRONMENT_IS_NODE) {
var BUFSIZE = 256;
var buf = Buffer.alloc ? Buffer.alloc(BUFSIZE) : new Buffer(BUFSIZE);
var bytesRead = 0;
try {
bytesRead = nodeFS.readSync(process.stdin.fd, buf, 0, BUFSIZE, null);
} catch (e) {
if (e.toString().indexOf("EOF") != -1)
bytesRead = 0;
else
throw e;
}
if (bytesRead > 0) {
result = buf.slice(0, bytesRead).toString("utf-8");
} else {
result = null;
}
} else if (typeof window != "undefined" && typeof window.prompt == "function") {
result = window.prompt("Input: ");
if (result !== null) {
result += "\n";
}
} else if (typeof readline == "function") {
result = readline();
if (result !== null) {
result += "\n";
}
}
if (!result) {
return null;
}
tty.input = intArrayFromString(result, true);
}
return tty.input.shift();
}, put_char: function(tty, val) {
if (val === null || val === 10) {
out(UTF8ArrayToString(tty.output, 0));
tty.output = [];
} else {
if (val != 0)
tty.output.push(val);
}
}, flush: function(tty) {
if (tty.output && tty.output.length > 0) {
out(UTF8ArrayToString(tty.output, 0));
tty.output = [];
}
} }, default_tty1_ops: { put_char: function(tty, val) {
if (val === null || val === 10) {
err(UTF8ArrayToString(tty.output, 0));
tty.output = [];
} else {
if (val != 0)
tty.output.push(val);
}
}, flush: function(tty) {
if (tty.output && tty.output.length > 0) {
err(UTF8ArrayToString(tty.output, 0));
tty.output = [];
}
} } };
function mmapAlloc(size) {
var alignedSize = alignMemory(size, 16384);
var ptr = _malloc(alignedSize);
while (size < alignedSize)
HEAP8[ptr + size++ >>> 0] = 0;
return ptr;
}
var MEMFS = { ops_table: null, mount: function(mount) {
return MEMFS.createNode(null, "/", 16384 | 511, 0);
}, createNode: function(parent, name2, mode, dev) {
if (FS.isBlkdev(mode) || FS.isFIFO(mode)) {
throw new FS.ErrnoError(63);
}
if (!MEMFS.ops_table) {
MEMFS.ops_table = { dir: { node: { getattr: MEMFS.node_ops.getattr, setattr: MEMFS.node_ops.setattr, lookup: MEMFS.node_ops.lookup, mknod: MEMFS.node_ops.mknod, rename: MEMFS.node_ops.rename, unlink: MEMFS.node_ops.unlink, rmdir: MEMFS.node_ops.rmdir, readdir: MEMFS.node_ops.readdir, symlink: MEMFS.node_ops.symlink }, stream: { llseek: MEMFS.stream_ops.llseek } }, file: { node: { getattr: MEMFS.node_ops.getattr, setattr: MEMFS.node_ops.setattr }, stream: { llseek: MEMFS.stream_ops.llseek, read: MEMFS.stream_ops.read, write: MEMFS.stream_ops.write, allocate: MEMFS.stream_ops.allocate, mmap: MEMFS.stream_ops.mmap, msync: MEMFS.stream_ops.msync } }, link: { node: { getattr: MEMFS.node_ops.getattr, setattr: MEMFS.node_ops.setattr, readlink: MEMFS.node_ops.readlink }, stream: {} }, chrdev: { node: { getattr: MEMFS.node_ops.getattr, setattr: MEMFS.node_ops.setattr }, stream: FS.chrdev_stream_ops } };
}
var node = FS.createNode(parent, name2, mode, dev);
if (FS.isDir(node.mode)) {
node.node_ops = MEMFS.ops_table.dir.node;
node.stream_ops = MEMFS.ops_table.dir.stream;
node.contents = {};
} else if (FS.isFile(node.mode)) {
node.node_ops = MEMFS.ops_table.file.node;
node.stream_ops = MEMFS.ops_table.file.stream;
node.usedBytes = 0;
node.contents = null;
} else if (FS.isLink(node.mode)) {
node.node_ops = MEMFS.ops_table.link.node;
node.stream_ops = MEMFS.ops_table.link.stream;
} else if (FS.isChrdev(node.mode)) {
node.node_ops = MEMFS.ops_table.chrdev.node;
node.stream_ops = MEMFS.ops_table.chrdev.stream;
}
node.timestamp = Date.now();
if (parent) {
parent.contents[name2] = node;
}
return node;
}, getFileDataAsRegularArray: function(node) {
if (node.contents && node.contents.subarray) {
var arr = [];
for (var i = 0; i < node.usedBytes; ++i)
arr.push(node.contents[i]);
return arr;
}
return node.contents;
}, getFileDataAsTypedArray: function(node) {
if (!node.contents)
return new Uint8Array(0);
if (node.contents.subarray)
return node.contents.subarray(0, node.usedBytes);
return new Uint8Array(node.contents);
}, expandFileStorage: function(node, newCapacity) {
newCapacity >>>= 0;
var prevCapacity = node.contents ? node.contents.length : 0;
if (prevCapacity >= newCapacity)
return;
var CAPACITY_DOUBLING_MAX = 1024 * 1024;
newCapacity = Math.max(newCapacity, prevCapacity * (prevCapacity < CAPACITY_DOUBLING_MAX ? 2 : 1.125) >>> 0);
if (prevCapacity != 0)
newCapacity = Math.max(newCapacity, 256);
var oldContents = node.contents;
node.contents = new Uint8Array(newCapacity);
if (node.usedBytes > 0)
node.contents.set(oldContents.subarray(0, node.usedBytes), 0);
return;
}, resizeFileStorage: function(node, newSize) {
newSize >>>= 0;
if (node.usedBytes == newSize)
return;
if (newSize == 0) {
node.contents = null;
node.usedBytes = 0;
return;
}
if (!node.contents || node.contents.subarray) {
var oldContents = node.contents;
node.contents = new Uint8Array(newSize);
if (oldContents) {
node.contents.set(oldContents.subarray(0, Math.min(newSize, node.usedBytes)));
}
node.usedBytes = newSize;
return;
}
if (!node.contents)
node.contents = [];
if (node.contents.length > newSize)
node.contents.length = newSize;
else
while (node.contents.length < newSize)
node.contents.push(0);
node.usedBytes = newSize;
}, node_ops: { getattr: function(node) {
var attr = {};
attr.dev = FS.isChrdev(node.mode) ? node.id : 1;
attr.ino = node.id;
attr.mode = node.mode;
attr.nlink = 1;
attr.uid = 0;
attr.gid = 0;
attr.rdev = node.rdev;
if (FS.isDir(node.mode)) {
attr.size = 4096;
} else if (FS.isFile(node.mode)) {
attr.size = node.usedBytes;
} else if (FS.isLink(node.mode)) {
attr.size = node.link.length;
} else {
attr.size = 0;
}
attr.atime = new Date(node.timestamp);
attr.mtime = new Date(node.timestamp);
attr.ctime = new Date(node.timestamp);
attr.blksize = 4096;
attr.blocks = Math.ceil(attr.size / attr.blksize);
return attr;
}, setattr: function(node, attr) {
if (attr.mode !== void 0) {
node.mode = attr.mode;
}
if (attr.timestamp !== void 0) {
node.timestamp = attr.timestamp;
}
if (attr.size !== void 0) {
MEMFS.resizeFileStorage(node, attr.size);
}
}, lookup: function(parent, name2) {
throw FS.genericErrors[44];
}, mknod: function(parent, name2, mode, dev) {
return MEMFS.createNode(parent, name2, mode, dev);
}, rename: function(old_node, new_dir, new_name) {
if (FS.isDir(old_node.mode)) {
var new_node;
try {
new_node = FS.lookupNode(new_dir, new_name);
} catch (e) {
}
if (new_node) {
for (var i in new_node.contents) {
throw new FS.ErrnoError(55);
}
}
}
delete old_node.parent.contents[old_node.name];
old_node.name = new_name;
new_dir.contents[new_name] = old_node;
old_node.parent = new_dir;
}, unlink: function(parent, name2) {
delete parent.contents[name2];
}, rmdir: function(parent, name2) {
var node = FS.lookupNode(parent, name2);
for (var i in node.contents) {
throw new FS.ErrnoError(55);
}
delete parent.contents[name2];
}, readdir: function(node) {
var entries = [".", ".."];
for (var key2 in node.contents) {
if (!node.contents.hasOwnProperty(key2)) {
continue;
}
entries.push(key2);
}
return entries;
}, symlink: function(parent, newname, oldpath) {
var node = MEMFS.createNode(parent, newname, 511 | 40960, 0);
node.link = oldpath;
return node;
}, readlink: function(node) {
if (!FS.isLink(node.mode)) {
throw new FS.ErrnoError(28);
}
return node.link;
} }, stream_ops: { read: function(stream, buffer2, offset, length, position) {
var contents = stream.node.contents;
if (position >= stream.node.usedBytes)
return 0;
var size = Math.min(stream.node.usedBytes - position, length);
if (size > 8 && contents.subarray) {
buffer2.set(contents.subarray(position, position + size), offset);
} else {
for (var i = 0; i < size; i++)
buffer2[offset + i] = contents[position + i];
}
return size;
}, write: function(stream, buffer2, offset, length, position, canOwn) {
if (buffer2.buffer === HEAP8.buffer) {
canOwn = false;
}
if (!length)
return 0;
var node = stream.node;
node.timestamp = Date.now();
if (buffer2.subarray && (!node.contents || node.contents.subarray)) {
if (canOwn) {
node.contents = buffer2.subarray(offset, offset + length);
node.usedBytes = length;
return length;
} else if (node.usedBytes === 0 && position === 0) {
node.contents = buffer2.slice(offset, offset + length);
node.usedBytes = length;
return length;
} else if (position + length <= node.usedBytes) {
node.contents.set(buffer2.subarray(offset, offset + length), position);
return length;
}
}
MEMFS.expandFileStorage(node, position + length);
if (node.contents.subarray && buffer2.subarray) {
node.contents.set(buffer2.subarray(offset, offset + length), position);
} else {
for (var i = 0; i < length; i++) {
node.contents[position + i] = buffer2[offset + i];
}
}
node.usedBytes = Math.max(node.usedBytes, position + length);
return length;
}, llseek: function(stream, offset, whence) {
var position = offset;
if (whence === 1) {
position += stream.position;
} else if (whence === 2) {
if (FS.isFile(stream.node.mode)) {
position += stream.node.usedBytes;
}
}
if (position < 0) {
throw new FS.ErrnoError(28);
}
return position;
}, allocate: function(stream, offset, length) {
MEMFS.expandFileStorage(stream.node, offset + length);
stream.node.usedBytes = Math.max(stream.node.usedBytes, offset + length);
}, mmap: function(stream, address, length, position, prot, flags) {
assert(address === 0);
if (!FS.isFile(stream.node.mode)) {
throw new FS.ErrnoError(43);
}
var ptr;
var allocated;
var contents = stream.node.contents;
if (!(flags & 2) && contents.buffer === buffer) {
allocated = false;
ptr = contents.byteOffset;
} else {
if (position > 0 || position + length < contents.length) {
if (contents.subarray) {
contents = contents.subarray(position, position + length);
} else {
contents = Array.prototype.slice.call(contents, position, position + length);
}
}
allocated = true;
ptr = mmapAlloc(length);
if (!ptr) {
throw new FS.ErrnoError(48);
}
ptr >>>= 0;
HEAP8.set(contents, ptr >>> 0);
}
return { ptr, allocated };
}, msync: function(stream, buffer2, offset, length, mmapFlags) {
if (!FS.isFile(stream.node.mode)) {
throw new FS.ErrnoError(43);
}
if (mmapFlags & 2) {
return 0;
}
var bytesWritten = MEMFS.stream_ops.write(stream, buffer2, 0, length, offset, false);
return 0;
} } };
var FS = { root: null, mounts: [], devices: {}, streams: [], nextInode: 1, nameTable: null, currentPath: "/", initialized: false, ignorePermissions: true, trackingDelegate: {}, tracking: { openFlags: { READ: 1, WRITE: 2 } }, ErrnoError: null, genericErrors: {}, filesystems: null, syncFSRequests: 0, lookupPath: function(path, opts) {
path = PATH_FS.resolve(FS.cwd(), path);
opts = opts || {};
if (!path)
return { path: "", node: null };
var defaults = { follow_mount: true, recurse_count: 0 };
for (var key2 in defaults) {
if (opts[key2] === void 0) {
opts[key2] = defaults[key2];
}
}
if (opts.recurse_count > 8) {
throw new FS.ErrnoError(32);
}
var parts = PATH.normalizeArray(path.split("/").filter(function(p) {
return !!p;
}), false);
var current = FS.root;
var current_path = "/";
for (var i = 0; i < parts.length; i++) {
var islast = i === parts.length - 1;
if (islast && opts.parent) {
break;
}
current = FS.lookupNode(current, parts[i]);
current_path = PATH.join2(current_path, parts[i]);
if (FS.isMountpoint(current)) {
if (!islast || islast && opts.follow_mount) {
current = current.mounted.root;
}
}
if (!islast || opts.follow) {
var count = 0;
while (FS.isLink(current.mode)) {
var link = FS.readlink(current_path);
current_path = PATH_FS.resolve(PATH.dirname(current_path), link);
var lookup = FS.lookupPath(current_path, { recurse_count: opts.recurse_count });
current = lookup.node;
if (count++ > 40) {
throw new FS.ErrnoError(32);
}
}
}
}
return { path: current_path, node: current };
}, getPath: function(node) {
var path;
while (true) {
if (FS.isRoot(node)) {
var mount = node.mount.mountpoint;
if (!path)
return mount;
return mount[mount.length - 1] !== "/" ? mount + "/" + path : mount + path;
}
path = path ? node.name + "/" + path : node.name;
node = node.parent;
}
}, hashName: function(parentid, name2) {
var hash = 0;
for (var i = 0; i < name2.length; i++) {
hash = (hash << 5) - hash + name2.charCodeAt(i) | 0;
}
return (parentid + hash >>> 0) % FS.nameTable.length;
}, hashAddNode: function(node) {
var hash = FS.hashName(node.parent.id, node.name);
node.name_next = FS.nameTable[hash];
FS.nameTable[hash] = node;
}, hashRemoveNode: function(node) {
var hash = FS.hashName(node.pa