UNPKG

playcanvas

Version:

PlayCanvas WebGL game engine

1,577 lines (1,545 loc) 4.36 MB
/** * @license * PlayCanvas Engine v2.14.4 revision a8e9f39 (PROFILE) * Copyright 2011-2025 PlayCanvas Ltd. All rights reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : typeof define === 'function' && define.amd ? define(['exports'], factory) : (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.pc = {})); })(this, (function (exports) { 'use strict'; var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null; function defineProtoFunc(cls, name, func) { if (!cls.prototype[name]) { Object.defineProperty(cls.prototype, name, { value: func, configurable: true, enumerable: false, writable: true }); } } defineProtoFunc(Array, 'fill', function(value) { if (this == null) { throw new TypeError('this is null or not defined'); } var O = Object(this); var len = O.length >>> 0; var start = arguments[1]; var relativeStart = start >> 0; var k = relativeStart < 0 ? Math.max(len + relativeStart, 0) : Math.min(relativeStart, len); var end = arguments[2]; var relativeEnd = end === undefined ? len : end >> 0; var finalValue = relativeEnd < 0 ? Math.max(len + relativeEnd, 0) : Math.min(relativeEnd, len); while(k < finalValue){ O[k] = value; k++; } return O; }); defineProtoFunc(Array, 'find', function(predicate) { if (this == null) { throw TypeError('"this" is null or not defined'); } var o = Object(this); var len = o.length >>> 0; if (typeof predicate !== 'function') { throw TypeError('predicate must be a function'); } var thisArg = arguments[1]; var k = 0; while(k < len){ var kValue = o[k]; if (predicate.call(thisArg, kValue, k, o)) { return kValue; } k++; } return undefined; }); defineProtoFunc(Array, 'findIndex', function(predicate) { if (this == null) { throw new TypeError('"this" is null or not defined'); } var o = Object(this); var len = o.length >>> 0; if (typeof predicate !== 'function') { throw new TypeError('predicate must be a function'); } var thisArg = arguments[1]; var k = 0; while(k < len){ var kValue = o[k]; if (predicate.call(thisArg, kValue, k, o)) { return k; } k++; } return -1; }); Math.log2 = Math.log2 || function(x) { return Math.log(x) * Math.LOG2E; }; if (!Math.sign) { Math.sign = function(x) { return (x > 0) - (x < 0) || +x; }; } if (Number.isFinite === undefined) Number.isFinite = function(value) { return typeof value === 'number' && isFinite(value); }; if (typeof Object.assign != 'function') { Object.defineProperty(Object, "assign", { value: function assign(target, varArgs) { 'use strict'; if (target == null) { throw new TypeError('Cannot convert undefined or null to object'); } var to = Object(target); for(var index = 1; index < arguments.length; index++){ var nextSource = arguments[index]; if (nextSource != null) { for(var nextKey in nextSource){ if (Object.prototype.hasOwnProperty.call(nextSource, nextKey)) { to[nextKey] = nextSource[nextKey]; } } } } return to; }, writable: true, configurable: true }); } Object.fromEntries = Object.fromEntries || function fromEntries(entries) { if (!entries || !entries[Symbol.iterator]) { throw new Error('Object.fromEntries() requires a single iterable argument'); } var res = {}; for(var i = 0; i < entries.length; i++){ res[entries[i][0]] = entries[i][1]; } return res; }; Object.entries = Object.entries || function(obj) { var ownProps = Object.keys(obj), i = ownProps.length, resArray = new Array(i); while(i--)resArray[i] = [ ownProps[i], obj[ownProps[i]] ]; return resArray; }; Object.values = Object.values || function(object) { return Object.keys(object).map(function(key) { return object[key]; }); }; (function() { if (typeof navigator === 'undefined' || typeof document === 'undefined') { return; } navigator.pointer = navigator.pointer || navigator.webkitPointer || navigator.mozPointer; var pointerlockchange = function pointerlockchange() { var e = document.createEvent('CustomEvent'); e.initCustomEvent('pointerlockchange', true, false, null); document.dispatchEvent(e); }; var pointerlockerror = function pointerlockerror() { var e = document.createEvent('CustomEvent'); e.initCustomEvent('pointerlockerror', true, false, null); document.dispatchEvent(e); }; document.addEventListener('webkitpointerlockchange', pointerlockchange, false); document.addEventListener('webkitpointerlocklost', pointerlockchange, false); document.addEventListener('mozpointerlockchange', pointerlockchange, false); document.addEventListener('mozpointerlocklost', pointerlockchange, false); document.addEventListener('webkitpointerlockerror', pointerlockerror, false); document.addEventListener('mozpointerlockerror', pointerlockerror, false); if (Element.prototype.mozRequestPointerLock) { Element.prototype.requestPointerLock = function() { this.mozRequestPointerLock(); }; } else { Element.prototype.requestPointerLock = Element.prototype.requestPointerLock || Element.prototype.webkitRequestPointerLock || Element.prototype.mozRequestPointerLock; } if (!Element.prototype.requestPointerLock && navigator.pointer) { Element.prototype.requestPointerLock = function() { var el = this; document.pointerLockElement = el; navigator.pointer.lock(el, pointerlockchange, pointerlockerror); }; } document.exitPointerLock = document.exitPointerLock || document.webkitExitPointerLock || document.mozExitPointerLock; if (!document.exitPointerLock) { document.exitPointerLock = function() { if (navigator.pointer) { document.pointerLockElement = null; navigator.pointer.unlock(); } }; } })(); defineProtoFunc(String, 'endsWith', function(search, this_len) { if (this_len === undefined || this_len > this.length) { this_len = this.length; } return this.substring(this_len - search.length, this_len) === search; }); defineProtoFunc(String, 'includes', function(search, start) { 'use strict'; if (typeof start !== 'number') { start = 0; } if (start + search.length > this.length) { return false; } else { return this.indexOf(search, start) !== -1; } }); defineProtoFunc(String, 'startsWith', function(search, rawPos) { var pos = rawPos > 0 ? rawPos | 0 : 0; return this.substring(pos, pos + search.length) === search; }); defineProtoFunc(String, 'trimEnd', function() { return this.replace(new RegExp(/[\x09\x0A\x0B\x0C\x0D\x20\xA0\u1680\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028\u2029\uFEFF]+/.source + '$', 'g'), ''); }); function _array_like_to_array$I(arr, len) { if (len == null || len > arr.length) len = arr.length; for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i]; return arr2; } function _unsupported_iterable_to_array$I(o, minLen) { if (!o) return; if (typeof o === "string") return _array_like_to_array$I(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(n); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array$I(o, minLen); } function _create_for_of_iterator_helper_loose$I(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (it) return (it = it.call(o)).next.bind(it); if (Array.isArray(o) || (it = _unsupported_iterable_to_array$I(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; return function() { if (i >= o.length) { return { done: true }; } return { done: false, value: o[i++] }; }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var typedArrays = [ Int8Array, Uint8Array, Uint8ClampedArray, Int16Array, Uint16Array, Int32Array, Uint32Array, Float32Array ]; for(var _iterator = _create_for_of_iterator_helper_loose$I(typedArrays), _step; !(_step = _iterator()).done;){ var typedArray = _step.value; defineProtoFunc(typedArray, "fill", Array.prototype.fill); defineProtoFunc(typedArray, "join", Array.prototype.join); } var TRACEID_RENDER_FRAME = 'RenderFrame'; var TRACEID_RENDER_FRAME_TIME = 'RenderFrameTime'; var TRACEID_RENDER_PASS = 'RenderPass'; var TRACEID_RENDER_PASS_DETAIL = 'RenderPassDetail'; var TRACEID_RENDER_ACTION = 'RenderAction'; var TRACEID_RENDER_TARGET_ALLOC = 'RenderTargetAlloc'; var TRACEID_TEXTURE_ALLOC = 'TextureAlloc'; var TRACEID_SHADER_ALLOC = 'ShaderAlloc'; var TRACEID_SHADER_COMPILE = 'ShaderCompile'; var TRACEID_VRAM_TEXTURE = 'VRAM.Texture'; var TRACEID_VRAM_VB = 'VRAM.Vb'; var TRACEID_VRAM_IB = 'VRAM.Ib'; var TRACEID_VRAM_SB = 'VRAM.Sb'; var TRACEID_BINDGROUP_ALLOC = 'BindGroupAlloc'; var TRACEID_BINDGROUPFORMAT_ALLOC = 'BindGroupFormatAlloc'; var TRACEID_RENDERPIPELINE_ALLOC = 'RenderPipelineAlloc'; var TRACEID_COMPUTEPIPELINE_ALLOC = 'ComputePipelineAlloc'; var TRACEID_PIPELINELAYOUT_ALLOC = 'PipelineLayoutAlloc'; var TRACEID_ELEMENT = 'Element'; var TRACEID_TEXTURES = 'Textures'; var TRACEID_ASSETS = 'Assets'; var TRACEID_RENDER_QUEUE = 'RenderQueue'; var TRACEID_OCTREE_RESOURCES = 'OctreeResources'; var TRACEID_GPU_TIMINGS = 'GpuTimings'; var version = '2.14.4'; var revision = 'a8e9f39'; function extend(target, ex) { for(var prop in ex){ var copy = ex[prop]; if (Array.isArray(copy)) { target[prop] = extend([], copy); } else if (copy && typeof copy === 'object') { target[prop] = extend({}, copy); } else { target[prop] = copy; } } return target; } var guid = { create: function create() { return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { var r = Math.random() * 16 | 0; var v = c === 'x' ? r : r & 0x3 | 0x8; return v.toString(16); }); } }; var path = { delimiter: '/', join: function join() { for(var _len = arguments.length, sections = new Array(_len), _key = 0; _key < _len; _key++){ sections[_key] = arguments[_key]; } var result = sections[0]; for(var i = 0; i < sections.length - 1; i++){ var one = sections[i]; var two = sections[i + 1]; if (two[0] === path.delimiter) { result = two; continue; } if (one && two && one[one.length - 1] !== path.delimiter && two[0] !== path.delimiter) { result += path.delimiter + two; } else { result += two; } } return result; }, normalize: function normalize(pathname) { var lead = pathname.startsWith(path.delimiter); var trail = pathname.endsWith(path.delimiter); var parts = pathname.split('/'); var result = ''; var cleaned = []; for(var i = 0; i < parts.length; i++){ if (parts[i] === '') continue; if (parts[i] === '.') continue; if (parts[i] === '..' && cleaned.length > 0) { cleaned = cleaned.slice(0, cleaned.length - 2); continue; } if (i > 0) cleaned.push(path.delimiter); cleaned.push(parts[i]); } result = cleaned.join(''); if (!lead && result[0] === path.delimiter) { result = result.slice(1); } if (trail && result[result.length - 1] !== path.delimiter) { result += path.delimiter; } return result; }, split: function split(pathname) { var lastDelimiterIndex = pathname.lastIndexOf(path.delimiter); if (lastDelimiterIndex !== -1) { return [ pathname.substring(0, lastDelimiterIndex), pathname.substring(lastDelimiterIndex + 1) ]; } return [ '', pathname ]; }, getBasename: function getBasename(pathname) { return path.split(pathname)[1]; }, getDirectory: function getDirectory(pathname) { return path.split(pathname)[0]; }, getExtension: function getExtension(pathname) { var ext = pathname.split('?')[0].split('.').pop(); if (ext !== pathname) { return "." + ext; } return ''; }, isRelativePath: function isRelativePath(pathname) { return pathname.charAt(0) !== '/' && pathname.match(/:\/\//) === null; }, extractPath: function extractPath(pathname) { var result = ''; var parts = pathname.split('/'); var i = 0; if (parts.length > 1) { if (path.isRelativePath(pathname)) { if (parts[0] === '.') { for(i = 0; i < parts.length - 1; ++i){ result += i === 0 ? parts[i] : "/" + parts[i]; } } else if (parts[0] === '..') { for(i = 0; i < parts.length - 1; ++i){ result += i === 0 ? parts[i] : "/" + parts[i]; } } else { result = '.'; for(i = 0; i < parts.length - 1; ++i){ result += "/" + parts[i]; } } } else { for(i = 0; i < parts.length - 1; ++i){ result += i === 0 ? parts[i] : "/" + parts[i]; } } } return result; } }; var detectPassiveEvents = function() { var result = false; try { var opts = Object.defineProperty({}, 'passive', { get: function get() { result = true; return false; } }); window.addEventListener('testpassive', null, opts); window.removeEventListener('testpassive', null, opts); } catch (e) {} return result; }; var ua = typeof navigator !== 'undefined' ? navigator.userAgent : ''; var environment = typeof window !== 'undefined' ? 'browser' : typeof global !== 'undefined' ? 'node' : 'worker'; var platformName = /android/i.test(ua) ? 'android' : /ip(?:[ao]d|hone)/i.test(ua) ? 'ios' : /windows/i.test(ua) ? 'windows' : /mac os/i.test(ua) ? 'osx' : /linux/i.test(ua) ? 'linux' : /cros/i.test(ua) ? 'cros' : null; var browserName = environment !== 'browser' ? null : /Chrome\/|Chromium\/|Edg.*\//.test(ua) ? 'chrome' : /Safari\//.test(ua) ? 'safari' : /Firefox\//.test(ua) ? 'firefox' : 'other'; var xbox = /xbox/i.test(ua); var touch = environment === 'browser' && ('ontouchstart' in window || 'maxTouchPoints' in navigator && navigator.maxTouchPoints > 0); var gamepads = environment === 'browser' && (!!navigator.getGamepads || !!navigator.webkitGetGamepads); var workers = typeof Worker !== 'undefined'; var passiveEvents = detectPassiveEvents(); var _ref, _ref1, _ref2; var platform = { name: platformName, environment: environment, global: (_ref2 = (_ref1 = (_ref = typeof globalThis !== 'undefined' && globalThis) != null ? _ref : environment === 'browser' && window) != null ? _ref1 : environment === 'node' && global) != null ? _ref2 : environment === 'worker' && self, browser: environment === 'browser', worker: environment === 'worker', desktop: [ 'windows', 'osx', 'linux', 'cros' ].includes(platformName), mobile: [ 'android', 'ios' ].includes(platformName), ios: platformName === 'ios', android: platformName === 'android', xbox: xbox, gamepads: gamepads, touch: touch, workers: workers, passiveEvents: passiveEvents, browserName: browserName }; var ASCII_LOWERCASE = 'abcdefghijklmnopqrstuvwxyz'; var ASCII_UPPERCASE = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; var ASCII_LETTERS = ASCII_LOWERCASE + ASCII_UPPERCASE; var HIGH_SURROGATE_BEGIN = 0xD800; var HIGH_SURROGATE_END = 0xDBFF; var LOW_SURROGATE_BEGIN = 0xDC00; var LOW_SURROGATE_END = 0xDFFF; var ZERO_WIDTH_JOINER = 0x200D; var REGIONAL_INDICATOR_BEGIN = 0x1F1E6; var REGIONAL_INDICATOR_END = 0x1F1FF; var FITZPATRICK_MODIFIER_BEGIN = 0x1F3FB; var FITZPATRICK_MODIFIER_END = 0x1F3FF; var DIACRITICAL_MARKS_BEGIN = 0x20D0; var DIACRITICAL_MARKS_END = 0x20FF; var VARIATION_MODIFIER_BEGIN = 0xFE00; var VARIATION_MODIFIER_END = 0xFE0F; function getCodePointData(string, i) { if (i === void 0) i = 0; var size = string.length; if (i < 0 || i >= size) { return null; } var first = string.charCodeAt(i); if (size > 1 && first >= HIGH_SURROGATE_BEGIN && first <= HIGH_SURROGATE_END) { var second = string.charCodeAt(i + 1); if (second >= LOW_SURROGATE_BEGIN && second <= LOW_SURROGATE_END) { return { code: (first - HIGH_SURROGATE_BEGIN) * 0x400 + second - LOW_SURROGATE_BEGIN + 0x10000, long: true }; } } return { code: first, long: false }; } function isCodeBetween(string, begin, end) { if (!string) { return false; } var codeData = getCodePointData(string); if (codeData) { var code = codeData.code; return code >= begin && code <= end; } return false; } function numCharsToTakeForNextSymbol(string, index) { if (index === string.length - 1) { return 1; } if (isCodeBetween(string[index], HIGH_SURROGATE_BEGIN, HIGH_SURROGATE_END)) { var first = string.substring(index, index + 2); var second = string.substring(index + 2, index + 4); if (isCodeBetween(second, FITZPATRICK_MODIFIER_BEGIN, FITZPATRICK_MODIFIER_END) || isCodeBetween(first, REGIONAL_INDICATOR_BEGIN, REGIONAL_INDICATOR_END) && isCodeBetween(second, REGIONAL_INDICATOR_BEGIN, REGIONAL_INDICATOR_END)) { return 4; } if (isCodeBetween(second, VARIATION_MODIFIER_BEGIN, VARIATION_MODIFIER_END)) { return 3; } return 2; } if (isCodeBetween(string[index + 1], VARIATION_MODIFIER_BEGIN, VARIATION_MODIFIER_END)) { return 2; } return 1; } var string = { ASCII_LOWERCASE: ASCII_LOWERCASE, ASCII_UPPERCASE: ASCII_UPPERCASE, ASCII_LETTERS: ASCII_LETTERS, format: function format(s) { for(var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++){ args[_key - 1] = arguments[_key]; } for(var i = 0; i < args.length; i++){ s = s.replace("{" + i + "}", args[i]); } return s; }, getCodePoint: function getCodePoint(string, i) { var codePointData = getCodePointData(string, i); return codePointData && codePointData.code; }, getCodePoints: function getCodePoints(string) { if (typeof string !== 'string') { throw new TypeError('Not a string'); } var i = 0; var arr = []; var codePoint; while(!!(codePoint = getCodePointData(string, i))){ arr.push(codePoint.code); i += codePoint.long ? 2 : 1; } return arr; }, getSymbols: function getSymbols(string) { if (typeof string !== 'string') { throw new TypeError('Not a string'); } var index = 0; var length = string.length; var output = []; var take = 0; var ch; while(index < length){ take += numCharsToTakeForNextSymbol(string, index + take); ch = string[index + take]; if (isCodeBetween(ch, DIACRITICAL_MARKS_BEGIN, DIACRITICAL_MARKS_END)) { ch = string[index + take++]; } if (isCodeBetween(ch, VARIATION_MODIFIER_BEGIN, VARIATION_MODIFIER_END)) { ch = string[index + take++]; } if (ch && ch.charCodeAt(0) === ZERO_WIDTH_JOINER) { ch = string[index + take++]; continue; } var char = string.substring(index, index + take); output.push(char); index += take; take = 0; } return output; }, fromCodePoint: function fromCodePoint() { for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){ args[_key] = arguments[_key]; } return args.map(function(codePoint) { if (codePoint > 0xFFFF) { codePoint -= 0x10000; return String.fromCharCode((codePoint >> 10) + 0xD800, codePoint % 0x400 + 0xDC00); } return String.fromCharCode(codePoint); }).join(''); } }; function _defineProperties$30(target, props) { for(var i = 0; i < props.length; i++){ var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } function _create_class$30(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties$30(Constructor.prototype, protoProps); return Constructor; } var EventHandle = /*#__PURE__*/ function() { function EventHandle(handler, name, callback, scope, once) { if (once === void 0) once = false; this._removed = false; this.handler = handler; this.name = name; this.callback = callback; this.scope = scope; this._once = once; } var _proto = EventHandle.prototype; _proto.off = function off() { if (this._removed) return; this.handler.offByHandle(this); }; _proto.on = function on(name, callback, scope) { if (scope === void 0) scope = this; return this.handler._addCallback(name, callback, scope, false); }; _proto.once = function once(name, callback, scope) { if (scope === void 0) scope = this; return this.handler._addCallback(name, callback, scope, true); }; _proto.toJSON = function toJSON(key) { return undefined; }; _create_class$30(EventHandle, [ { key: "removed", get: function get() { return this._removed; }, set: function set(value) { if (!value) return; this._removed = true; } } ]); return EventHandle; }(); function _array_like_to_array$H(arr, len) { if (len == null || len > arr.length) len = arr.length; for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i]; return arr2; } function _unsupported_iterable_to_array$H(o, minLen) { if (!o) return; if (typeof o === "string") return _array_like_to_array$H(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(n); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array$H(o, minLen); } function _create_for_of_iterator_helper_loose$H(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (it) return (it = it.call(o)).next.bind(it); if (Array.isArray(o) || (it = _unsupported_iterable_to_array$H(o)) || allowArrayLike) { if (it) o = it; var i = 0; return function() { if (i >= o.length) { return { done: true }; } return { done: false, value: o[i++] }; }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var EventHandler = /*#__PURE__*/ function() { function EventHandler() { this._callbacks = new Map(); this._callbackActive = new Map(); } var _proto = EventHandler.prototype; _proto.initEventHandler = function initEventHandler() { this._callbacks = new Map(); this._callbackActive = new Map(); }; _proto._addCallback = function _addCallback(name, callback, scope, once) { if (!this._callbacks.has(name)) { this._callbacks.set(name, []); } if (this._callbackActive.has(name)) { var callbackActive = this._callbackActive.get(name); if (callbackActive && callbackActive === this._callbacks.get(name)) { this._callbackActive.set(name, callbackActive.slice()); } } var evt = new EventHandle(this, name, callback, scope, once); this._callbacks.get(name).push(evt); return evt; }; _proto.on = function on(name, callback, scope) { if (scope === void 0) scope = this; return this._addCallback(name, callback, scope, false); }; _proto.once = function once(name, callback, scope) { if (scope === void 0) scope = this; return this._addCallback(name, callback, scope, true); }; _proto.off = function off(name, callback, scope) { if (name) { if (this._callbackActive.has(name) && this._callbackActive.get(name) === this._callbacks.get(name)) { this._callbackActive.set(name, this._callbackActive.get(name).slice()); } } else { for(var _iterator = _create_for_of_iterator_helper_loose$H(this._callbackActive), _step; !(_step = _iterator()).done;){ var _step_value = _step.value, key = _step_value[0], callbacks = _step_value[1]; if (!this._callbacks.has(key)) { continue; } if (this._callbacks.get(key) !== callbacks) { continue; } this._callbackActive.set(key, callbacks.slice()); } } if (!name) { for(var _iterator1 = _create_for_of_iterator_helper_loose$H(this._callbacks.values()), _step1; !(_step1 = _iterator1()).done;){ var callbacks1 = _step1.value; for(var i = 0; i < callbacks1.length; i++){ callbacks1[i].removed = true; } } this._callbacks.clear(); } else if (!callback) { var callbacks2 = this._callbacks.get(name); if (callbacks2) { for(var i1 = 0; i1 < callbacks2.length; i1++){ callbacks2[i1].removed = true; } this._callbacks.delete(name); } } else { var callbacks3 = this._callbacks.get(name); if (!callbacks3) { return this; } for(var i2 = 0; i2 < callbacks3.length; i2++){ if (callbacks3[i2].callback !== callback) { continue; } if (scope && callbacks3[i2].scope !== scope) { continue; } callbacks3[i2].removed = true; callbacks3.splice(i2, 1); i2--; } if (callbacks3.length === 0) { this._callbacks.delete(name); } } return this; }; _proto.offByHandle = function offByHandle(handle) { var name = handle.name; handle.removed = true; if (this._callbackActive.has(name) && this._callbackActive.get(name) === this._callbacks.get(name)) { this._callbackActive.set(name, this._callbackActive.get(name).slice()); } var callbacks = this._callbacks.get(name); if (!callbacks) { return this; } var ind = callbacks.indexOf(handle); if (ind !== -1) { callbacks.splice(ind, 1); if (callbacks.length === 0) { this._callbacks.delete(name); } } return this; }; _proto.fire = function fire(name, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) { if (!name) { return this; } var callbacksInitial = this._callbacks.get(name); if (!callbacksInitial) { return this; } var callbacks; if (!this._callbackActive.has(name)) { this._callbackActive.set(name, callbacksInitial); } else if (this._callbackActive.get(name) !== callbacksInitial) { callbacks = callbacksInitial.slice(); } for(var i = 0; (callbacks || this._callbackActive.get(name)) && i < (callbacks || this._callbackActive.get(name)).length; i++){ var evt = (callbacks || this._callbackActive.get(name))[i]; if (!evt.callback) continue; evt.callback.call(evt.scope, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8); if (evt._once) { var existingCallback = this._callbacks.get(name); var ind = existingCallback ? existingCallback.indexOf(evt) : -1; if (ind !== -1) { if (this._callbackActive.get(name) === existingCallback) { this._callbackActive.set(name, this._callbackActive.get(name).slice()); } var callbacks1 = this._callbacks.get(name); if (!callbacks1) continue; callbacks1[ind].removed = true; callbacks1.splice(ind, 1); if (callbacks1.length === 0) { this._callbacks.delete(name); } } } } if (!callbacks) { this._callbackActive.delete(name); } return this; }; _proto.hasEvent = function hasEvent(name) { var _this__callbacks_get; return !!((_this__callbacks_get = this._callbacks.get(name)) == null ? void 0 : _this__callbacks_get.length); }; return EventHandler; }(); var IndexedList = /*#__PURE__*/ function() { function IndexedList() { this._list = []; this._index = {}; } var _proto = IndexedList.prototype; _proto.push = function push(key, item) { if (this._index[key]) { throw Error("Key already in index " + key); } var location = this._list.push(item) - 1; this._index[key] = location; }; _proto.has = function has(key) { return this._index[key] !== undefined; }; _proto.get = function get(key) { var location = this._index[key]; if (location !== undefined) { return this._list[location]; } return null; }; _proto.remove = function remove(key) { var location = this._index[key]; if (location !== undefined) { this._list.splice(location, 1); delete this._index[key]; for(key in this._index){ var idx = this._index[key]; if (idx > location) { this._index[key] = idx - 1; } } return true; } return false; }; _proto.list = function list() { return this._list; }; _proto.clear = function clear() { this._list.length = 0; for(var prop in this._index){ delete this._index[prop]; } }; return IndexedList; }(); function _instanceof$1g(left, right) { if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) { return !!right[Symbol.hasInstance](left); } else { return left instanceof right; } } var cachedResult = function(func) { var uninitToken = {}; var result = uninitToken; return function() { if (result === uninitToken) { result = func(); } return result; }; }; var Impl = /*#__PURE__*/ function() { function Impl() {} Impl.loadScript = function loadScript(url, callback) { var s = document.createElement("script"); s.setAttribute('src', url); s.onload = function() { callback(null); }; s.onerror = function() { callback("Failed to load script='" + url + "'"); }; document.body.appendChild(s); }; Impl.loadWasm = function loadWasm(moduleName, config, callback) { var loadUrl = Impl.wasmSupported() && config.glueUrl && config.wasmUrl ? config.glueUrl : config.fallbackUrl; if (loadUrl) { Impl.loadScript(loadUrl, function(err) { if (err) { callback(err, null); } else { var module = window[moduleName]; window[moduleName] = undefined; module({ locateFile: function() { return config.wasmUrl; }, onAbort: function() { callback('wasm module aborted.'); } }).then(function(instance) { callback(null, instance); }); } }); } else { callback('No supported wasm modules found.', null); } }; Impl.getModule = function getModule(name) { if (!Impl.modules.hasOwnProperty(name)) { Impl.modules[name] = { config: null, initializing: false, instance: null, callbacks: [] }; } return Impl.modules[name]; }; Impl.initialize = function initialize(moduleName, module) { if (module.initializing) { return; } var config = module.config; if (config.glueUrl || config.wasmUrl || config.fallbackUrl) { module.initializing = true; Impl.loadWasm(moduleName, config, function(err, instance) { if (err) { if (config.errorHandler) { config.errorHandler(err); } else { console.error("failed to initialize module=" + moduleName + " error=" + err); } } else { module.instance = instance; module.callbacks.forEach(function(callback) { callback(instance); }); } }); } }; return Impl; }(); Impl.modules = {}; Impl.wasmSupported = cachedResult(function() { try { if (typeof WebAssembly === 'object' && typeof WebAssembly.instantiate === 'function') { var module = new WebAssembly.Module(Uint8Array.of(0x0, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00)); if (_instanceof$1g(module, WebAssembly.Module)) { return _instanceof$1g(new WebAssembly.Instance(module), WebAssembly.Instance); } } } catch (e) {} return false; }); var WasmModule = /*#__PURE__*/ function() { function WasmModule() {} WasmModule.setConfig = function setConfig(moduleName, config) { var module = Impl.getModule(moduleName); module.config = config; if (module.callbacks.length > 0) { Impl.initialize(moduleName, module); } }; WasmModule.getConfig = function getConfig(moduleName) { var _Impl_modules_moduleName, _Impl_modules; return (_Impl_modules = Impl.modules) == null ? void 0 : (_Impl_modules_moduleName = _Impl_modules[moduleName]) == null ? void 0 : _Impl_modules_moduleName.config; }; WasmModule.getInstance = function getInstance(moduleName, callback) { var module = Impl.getModule(moduleName); if (module.instance) { callback(module.instance); } else { module.callbacks.push(callback); if (module.config) { Impl.initialize(moduleName, module); } } }; return WasmModule; }(); function _defineProperties$2$(target, props) { for(var i = 0; i < props.length; i++){ var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } function _create_class$2$(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties$2$(Constructor.prototype, protoProps); return Constructor; } var ReadStream = /*#__PURE__*/ function() { function ReadStream(arraybuffer) { this.offset = 0; this.arraybuffer = arraybuffer; this.dataView = new DataView(arraybuffer); } var _proto = ReadStream.prototype; _proto.reset = function reset(offset) { if (offset === void 0) offset = 0; this.offset = offset; }; _proto.skip = function skip(bytes) { this.offset += bytes; }; _proto.align = function align(bytes) { this.offset = this.offset + bytes - 1 & ~(bytes - 1); }; _proto._inc = function _inc(amount) { this.offset += amount; return this.offset - amount; }; _proto.readChar = function readChar() { return String.fromCharCode(this.dataView.getUint8(this.offset++)); }; _proto.readChars = function readChars(numChars) { var result = ''; for(var i = 0; i < numChars; ++i){ result += this.readChar(); } return result; }; _proto.readU8 = function readU8() { return this.dataView.getUint8(this.offset++); }; _proto.readU16 = function readU16() { return this.dataView.getUint16(this._inc(2), true); }; _proto.readU32 = function readU32() { return this.dataView.getUint32(this._inc(4), true); }; _proto.readU64 = function readU64() { return this.readU32() + Math.pow(2, 32) * this.readU32(); }; _proto.readU32be = function readU32be() { return this.dataView.getUint32(this._inc(4), false); }; _proto.readArray = function readArray(result) { for(var i = 0; i < result.length; ++i){ result[i] = this.readU8(); } }; _proto.readLine = function readLine() { var view = this.dataView; var result = ''; while(true){ if (this.offset >= view.byteLength) { break; } var c = String.fromCharCode(this.readU8()); if (c === '\n') { break; } result += c; } return result; }; _create_class$2$(ReadStream, [ { key: "remainingBytes", get: function get() { return this.dataView.byteLength - this.offset; } } ]); return ReadStream; }(); var SortedLoopArray = /*#__PURE__*/ function() { function SortedLoopArray(args) { this.items = []; this.length = 0; this.loopIndex = -1; this._sortBy = args.sortBy; this._sortHandler = this._doSort.bind(this); } var _proto = SortedLoopArray.prototype; _proto._binarySearch = function _binarySearch(item) { var left = 0; var right = this.items.length - 1; var search = item[this._sortBy]; var middle; var current; while(left <= right){ middle = Math.floor((left + right) / 2); current = this.items[middle][this._sortBy]; if (current <= search) { left = middle + 1; } else if (current > search) { right = middle - 1; } } return left; }; _proto._doSort = function _doSort(a, b) { var sortBy = this._sortBy; return a[sortBy] - b[sortBy]; }; _proto.insert = function insert(item) { var index = this._binarySearch(item); this.items.splice(index, 0, item); this.length++; if (this.loopIndex >= index) { this.loopIndex++; } }; _proto.append = function append(item) { this.items.push(item); this.length++; }; _proto.remove = function remove(item) { var idx = this.items.indexOf(item); if (idx < 0) return; this.items.splice(idx, 1); this.length--; if (this.loopIndex >= idx) { this.loopIndex--; } }; _proto.sort = function sort() { var current = this.loopIndex >= 0 ? this.items[this.loopIndex] : null; this.items.sort(this._sortHandler); if (current !== null) { this.loopIndex = this.items.indexOf(current); } }; return SortedLoopArray; }(); function _defineProperties$2_(target, props) { for(var i = 0; i < props.length; i++){ var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } function _create_class$2_(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties$2_(Constructor.prototype, protoProps); return Constructor; } function _inherits$3I(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _set_prototype_of$3I(subClass, superClass); } function _instanceof$1f(left, right) { if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) { return !!right[Symbol.hasInstance](left); } else { return left instanceof right; } } function _set_prototype_of$3I(o, p) { _set_prototype_of$3I = Object.setPrototypeOf || function setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _set_prototype_of$3I(o, p); } var Tags = /*#__PURE__*/ function(EventHandler) { _inherits$3I(Tags, EventHandler); function Tags(parent) { var _this; _this = EventHandler.call(this) || this, _this._index = {}, _this._list = []; _this._parent = parent; return _this; } var _proto = Tags.prototype; _proto.add = function add() { for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){ args[_key] = arguments[_key]; } var changed = false; var tags = this._processArguments(args, true); if (!tags.length) { return changed; } for(var i = 0; i < tags.length; i++){ if (this._index[tags[i]]) { continue; } changed = true; this._index[tags[i]] = true; this._list.push(tags[i]); this.fire('add', tags[i], this._parent); } if (changed) { this.fire('change', this._parent); } return changed; }; _proto.remove = function remove() { for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){ args[_key] = arguments[_key]; } var changed = false; if (!this._list.length) { return changed; } var tags = this._processArguments(args, true); if (!tags.length) { return changed; } for(var i = 0; i < tags.length; i++){ if (!this._index[tags[i]]) { continue; } changed = true; delete this._index[tags[i]]; this._list.splice(this._list.indexOf(tags[i]), 1); this.fire('remove', tags[i], this._parent); } if (changed) { this.fire('change', this._parent); } return changed; }; _proto.clear = function clear() { if (!this._list.length) { return; } var tags = this._list.slice(0); this._list = []; this._index = {}; for(var i = 0; i < tags.length; i++){ this.fire('remove', tags[i], this._parent); } this.fire('change', this._parent); }; _proto.has = function has() { for(var _len = arguments.length, query = new Array(_len), _key = 0; _key < _len; _key++){ query[_key] = arguments[_key]; } if (!this._list.length) { return false; } return this._has(this._processArguments(query)); }; _proto._has = function _has(tags) { if (!this._list.length || !tags.length) { return false; } for(var i = 0; i < tags.length; i++){ if (tags[i].length === 1) { if (this._index[tags[i][0]]) { return true; } } else { var multiple = true; for(var t = 0; t < tags[i].length; t++){ if (this._index[tags[i][t]]) { continue; } multiple = false; break; } if (multiple) { return true; } } } return false; }; _proto.list = function list() { return this._list.slice(0); }; _proto._processArguments = function _processArguments(args, flat) { var tags = []; var tmp = []; if (!args || !args.length) { return tags; } for(var i = 0; i < args.length; i++){ if (_instanceof$1f(args[i], Array)) { if (!flat) { tmp = []; } for(var t = 0; t < args[i].length; t++){ if (typeof args[i][t] !== 'string') { continue; } if (flat) { tags.push(args[i][t]); } else { tmp.push(args[i][t]); } } if (!flat && tmp.length) { tags.push(tmp); } } else if (typeof args[i] === 'string') { if (flat) { tags.push(args[i]); } else { tags.push([ args[i] ]); } } } return tags; }; _create_class$2_(Tags, [ { key: "size", get: function get() { return this._list.length; } } ]); return Tags; }(EventHandler); Tags.EVENT_ADD = 'add'; Tags.EVENT_REMOVE = 'remove'; Tags.EVENT_CHANGE = 'change'; var now = typeof window !== 'undefined' && window.performance && window.performance.now ? performance.now.bind(performance) : Date.now; function _array_like_to_array$G(arr, len) { if (len == null || len > arr.length) len = arr.length; for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i]; return arr2; } function _unsupported_iterable_to_array$G(o, minLen) { if (!o) return; if (typeof o === "string") return _array_like_to_array$G(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(n); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array$G(o, minLen); } function _create_for_of_iterator_helper_loose$G(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (it) return (it = it.call(o)).next.bind(it); if (Array.isArray(o) || (it = _unsupported_iterable_to_array$G(o)) || allowArrayLike) { if (it) o = it; var i = 0; return function() { if (i >= o.length) { return { done: true }; } return { done: false, value: o[i++] }; }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } function createURI(options) { var s = ''; if ((options.authority || options.scheme) && (options.host || options.hostpath)) { throw new Error('Can\'t have \'scheme\' or \'authority\' and \'host\' or \'hostpath\' option'); } if (options.host && options.hostpath) { throw new Error('Can\'t have \'host\' and \'hostpath\' option'); } if (options.path && options.hostpath) { throw new Error('Can\'t have \'path\' and \'hostpath\' option'); } if (options.scheme) { s += "" + options.scheme + ":"; } if (options.authority) { s += "//" + options.authority; } if (options.host) { s += options.host; } if (options.path) { s += options.path; } if (options.hostpath) { s += options.hostpath; } if (options.query) { s += "?" + options.query; } if (options.fragment) { s += "#" + options.fragment; } return s; } var re = /^(([^:/?#]+):)?(\/\/([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?/; var URI = /*#__PURE__*/ function() { function URI(uri) { var result = uri.match(re); this.scheme = result[2]; this.authority = result[4]; this.path = result[5]; this.query = result[7]; this.fragment = result[9]; } var _proto = URI.prototype; _proto.toString = function toString() { var s = ''; if (this.scheme) { s += "" + this.scheme + ":"; } if (this.authority) { s += "//" + this.authority; } s += this.path; if (this.query) { s += "?" + this.query; } if (this.fragment) { s += "#" + this.fragment; } return s; }; _proto.getQuery = function getQuery() { var result = {}; if (this.query) { var queryParams = decodeURIComponent(this.query).split('&'); for(var _iterator = _create_for_of_iterator_helper_loose$G(queryParams), _step; !(_step = _iterator()).done;){ var queryParam = _step.value; var pair = queryParam.split('='); result[pair[0]] = pair[1]; } } return result; }; _proto.setQuery = function setQuery(params) { var q = ''; for(var key in params){ if (params.hasOwnProperty(key)) { if (q !== '') { q += '&'; } q += encodeURIComponent(key) + "=" + encodeURIComponent(params[key]); } } this.query = q; }; return URI; }(); var Tracing = /*#__PURE__*/ function() { function Tracing() {} Tracing.set = function set(channel, enabled) { }; Tracing.get = function get(channel) { return Tracing._traceChannels.has(channel); }; return Tracing; }(); Tracing._traceChannels = new Set(); Tracing.stack = false; var CURVE_LINEAR = 0; var CURVE_SMOOTHSTEP = 1; var CURVE_SPLINE = 4; var CURVE_STEP = 5; var math = { DEG_TO_RAD: Math.PI / 180, RAD_TO_DEG: 180 / Math.PI, clamp: function clamp(value, min, max) { if (value >= max) return max; if (value <= min) return min; return value; }, intToBytes24: function intToBytes24(i) { var r = i >> 16 & 0xff; var g = i >> 8 & 0xff; var b = i & 0xff; return [ r, g, b ]; }, intToBytes32: function intToBytes32(i) { var r = i >> 24 & 0xff; var g = i >> 16 & 0xff; var b = i >> 8 & 0xff; var a = i & 0xff; return [ r, g, b, a ]; }, bytesToInt24: function bytesToInt24(r, g, b) { if (r.length) { b = r[2]; g = r[1]; r = r[0]; } return r << 16 | g << 8 | b; }, bytesToInt32: function bytesToInt32(r, g, b, a) { if (r.length) { a = r[3]; b = r[2]; g = r[1]; r = r[0]; } return (r << 24 | g << 16 | b << 8 | a) >>> 0; }, lerp: function lerp(a, b, alpha) {