From 47f86b88fd7970cd2c3277a3d11542f41f763f9b Mon Sep 17 00:00:00 2001 From: Sherkhan Azimov Date: Wed, 2 Aug 2023 06:43:35 +0300 Subject: [PATCH] fix(): update example to aframe 1.4.2 --- dist/aframe-gui.js | 6624 +--------------- dist/aframe-gui.min.js | 2 +- examples/all_components_colors.html | 3 +- examples/all_components_mouse_quest.html | 5 +- examples/casestudy_amper.html | 3 +- examples/casestudy_call.html | 3 +- examples/casestudy_dropdown.html | 3 +- examples/casestudy_eyetest.html | 3 +- examples/casestudy_keyboard.html | 3 +- examples/casestudy_movies.html | 3 +- examples/casestudy_vrremote.html | 3 +- examples/js/aframe-gui.js | 6627 +--------------- examples/js/aframe-gui.min.js | 2 +- src/index.js | 3 - src/third-party/aframe-troika-text.js | 6702 ----------------- src/third-party/aframe-troika-text.min.js | 2 - src/third-party/aframe-troika-text.min.js.map | 1 - 17 files changed, 23 insertions(+), 19969 deletions(-) delete mode 100644 src/third-party/aframe-troika-text.js delete mode 100644 src/third-party/aframe-troika-text.min.js delete mode 100644 src/third-party/aframe-troika-text.min.js.map diff --git a/dist/aframe-gui.js b/dist/aframe-gui.js index a7c7150..f13c59f 100644 --- a/dist/aframe-gui.js +++ b/dist/aframe-gui.js @@ -63,7 +63,7 @@ /******/ __webpack_require__.p = ""; /******/ /******/ // Load entry module and return exports -/******/ return __webpack_require__(__webpack_require__.s = 23); +/******/ return __webpack_require__(__webpack_require__.s = 21); /******/ }) /************************************************************************/ /******/ ([ @@ -3175,6625 +3175,6 @@ window.drawIcon = function (ctx, canvas, iconFontSize, icon, color) { /* 21 */ /***/ (function(module, exports, __webpack_require__) { -"use strict"; -/* WEBPACK VAR INJECTION */(function(process) { - -var _get = function get(object, property, receiver) { if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } }; - -var _createClass = function () { function defineProperties(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); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); - -var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }(); - -var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; - -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - -function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } - -function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } - -(function (THREE, aframe) { - 'use strict'; - - function _interopDefaultLegacy(e) { - return e && (typeof e === 'undefined' ? 'undefined' : _typeof(e)) === 'object' && 'default' in e ? e : { 'default': e }; - } - - function _interopNamespace(e) { - if (e && e.__esModule) { - return e; - } else { - var n = Object.create(null); - if (e) { - Object.keys(e).forEach(function (k) { - if (k !== 'default') { - var d = Object.getOwnPropertyDescriptor(e, k); - Object.defineProperty(n, k, d.get ? d : { - enumerable: true, - get: function get() { - return e[k]; - } - }); - } - }); - } - n['default'] = e; - return Object.freeze(n); - } - } - - var THREE__namespace = /*#__PURE__*/_interopNamespace(THREE); - var aframe__default = /*#__PURE__*/_interopDefaultLegacy(aframe); - - /** - * Lightweight thenable implementation that is entirely self-contained within a single - * function with no external dependencies so it can be easily shipped across to a WorkerModule. - * - * This implementation conforms fully to the Promises/A+ spec so it can safely interoperate - * with other thenable implementations. https://github.com/promises-aplus/promises-spec - * - * *However*, it is _not_ a full implementation of ES2015 Promises, e.g. it does not - * have the same constructor signature and does not expose a `catch` method or the static - * `resolve`/`reject`/`all`/`race` initializer methods. If you need to hand a Thenable - * instance off to consuming code that may expect a true Promise, you'll want to wrap it - * in a native-or-polyfilled Promise first. - * - * (Why yet another Promises/A+ implementation? Great question. We needed a polyfill-like - * thing that was (a) wrapped in a single function for easy serialization across to a Worker, - * and (b) was as small as possible -- at ~900B minified (~500B gzipped) this is the smallest - * implementation I've found. And also, exercises like this are challenging and fun.) - */ - function BespokeThenable() { - var state = 0; // 0=pending, 1=fulfilled, -1=rejected - var queue = []; - var value; - var scheduled = 0; - var completeCalled = 0; - - function then(onResolve, onReject) { - var nextThenable = BespokeThenable(); - - function handleNext() { - var cb = state > 0 ? onResolve : onReject; - if (isFn(cb)) { - try { - var result = cb(value); - if (result === nextThenable) { - recursiveError(); - } - var resultThen = getThenableThen(result); - if (resultThen) { - resultThen.call(result, nextThenable.resolve, nextThenable.reject); - } else { - nextThenable.resolve(result); - } - } catch (err) { - nextThenable.reject(err); - } - } else { - nextThenable[state > 0 ? 'resolve' : 'reject'](value); - } - } - - queue.push(handleNext); - if (state) { - scheduleQueueFlush(); - } - return nextThenable; - } - - var resolve = oneTime(function (val) { - if (!completeCalled) { - complete(1, val); - } - }); - - var reject = oneTime(function (reason) { - if (!completeCalled) { - complete(-1, reason); - } - }); - - function complete(st, val) { - completeCalled++; - var ignoreThrow = 0; - try { - if (val === thenableObj) { - recursiveError(); - } - var valThen = st > 0 && getThenableThen(val); - if (valThen) { - valThen.call(val, oneTime(function (v) { - ignoreThrow++; - complete(1, v); - }), oneTime(function (v) { - ignoreThrow++; - complete(-1, v); - })); - } else { - state = st; - value = val; - scheduleQueueFlush(); - } - } catch (e) { - if (!state && !ignoreThrow) { - complete(-1, e); - } - } - } - - function scheduleQueueFlush() { - if (!scheduled) { - setTimeout(flushQueue, 0); //TODO setImmediate or postMessage approach if available? - scheduled = 1; - } - } - - function flushQueue() { - var q = queue; - scheduled = 0; - queue = []; - q.forEach(callIt); - } - - function callIt(fn) { - fn(); - } - - function getThenableThen(val) { - var valThen = val && (isFn(val) || (typeof val === 'undefined' ? 'undefined' : _typeof(val)) === 'object') && val.then; - return isFn(valThen) && valThen; - } - - function oneTime(fn) { - var called = 0; - return function () { - var args = [], - len = arguments.length; - while (len--) { - args[len] = arguments[len]; - }if (!called++) { - fn.apply(this, args); - } - }; - } - - function recursiveError() { - throw new TypeError('Chaining cycle detected'); - } - - var isFn = function isFn(v) { - return typeof v === 'function'; - }; - - var thenableObj = { - then: then, - resolve: resolve, - reject: reject - }; - return thenableObj; - } - - /** - * Thenable implementation that uses a native Promise under the covers. This implementation - * is preferred if Promise is available, for better performance and dev tools integration. - * @constructor - */ - function NativePromiseThenable() { - var resolve, reject; - var promise = new Promise(function (res, rej) { - resolve = res; - reject = rej; - }); - return { - then: promise.then.bind(promise), - resolve: resolve, - reject: reject - }; - } - - /** - * Promise.all() impl: - */ - BespokeThenable.all = NativePromiseThenable.all = function (items) { - var resultCount = 0; - var results = []; - var out = DefaultThenable(); - if (items.length === 0) { - out.resolve([]); - } else { - items.forEach(function (item, i) { - var itemThenable = DefaultThenable(); - itemThenable.resolve(item); - itemThenable.then(function (res) { - resultCount++; - results[i] = res; - if (resultCount === items.length) { - out.resolve(results); - } - }, out.reject); - }); - } - return out; - }; - - /** - * Choose the best Thenable implementation and export it as the default. - */ - var DefaultThenable = typeof Promise === 'function' ? NativePromiseThenable : BespokeThenable; - - /** - * Main content for the worker that handles the loading and execution of - * modules within it. - */ - function workerBootstrap() { - var modules = Object.create(null); - - // Handle messages for registering a module - function registerModule(ref, callback) { - var id = ref.id; - var name = ref.name; - var dependencies = ref.dependencies;if (dependencies === void 0) dependencies = []; - var init = ref.init;if (init === void 0) init = function init() {}; - var getTransferables = ref.getTransferables;if (getTransferables === void 0) getTransferables = null; - - // Only register once - if (modules[id]) { - return; - } - - try { - // If any dependencies are modules, ensure they're registered and grab their value - dependencies = dependencies.map(function (dep) { - if (dep && dep.isWorkerModule) { - registerModule(dep, function (depResult) { - if (depResult instanceof Error) { - throw depResult; - } - }); - dep = modules[dep.id].value; - } - return dep; - }); - - // Rehydrate functions - init = rehydrate("<" + name + ">.init", init); - if (getTransferables) { - getTransferables = rehydrate("<" + name + ">.getTransferables", getTransferables); - } - - // Initialize the module and store its value - var value = null; - if (typeof init === 'function') { - value = init.apply(void 0, dependencies); - } else { - console.error('worker module init function failed to rehydrate'); - } - modules[id] = { - id: id, - value: value, - getTransferables: getTransferables - }; - callback(value); - } catch (err) { - if (!(err && err.noLog)) { - console.error(err); - } - callback(err); - } - } - - // Handle messages for calling a registered module's result function - function callModule(ref, callback) { - var ref$1; - - var id = ref.id; - var args = ref.args; - if (!modules[id] || typeof modules[id].value !== 'function') { - callback(new Error("Worker module " + id + ": not found or its 'init' did not return a function")); - } - try { - var result = (ref$1 = modules[id]).value.apply(ref$1, args); - if (result && typeof result.then === 'function') { - result.then(handleResult, function (rej) { - return callback(rej instanceof Error ? rej : new Error('' + rej)); - }); - } else { - handleResult(result); - } - } catch (err) { - callback(err); - } - function handleResult(result) { - try { - var tx = modules[id].getTransferables && modules[id].getTransferables(result); - if (!tx || !Array.isArray(tx) || !tx.length) { - tx = undefined; //postMessage is very picky about not passing null or empty transferables - } - callback(result, tx); - } catch (err) { - console.error(err); - callback(err); - } - } - } - - function rehydrate(name, str) { - var result = void 0; - self.troikaDefine = function (r) { - return result = r; - }; - var url = URL.createObjectURL(new Blob(["/** " + name.replace(/\*/g, '') + " **/\n\ntroikaDefine(\n" + str + "\n)"], { type: 'application/javascript' })); - try { - importScripts(url); - } catch (err) { - console.error(err); - } - URL.revokeObjectURL(url); - delete self.troikaDefine; - return result; - } - - // Handler for all messages within the worker - self.addEventListener('message', function (e) { - var ref = e.data; - var messageId = ref.messageId; - var action = ref.action; - var data = ref.data; - try { - // Module registration - if (action === 'registerModule') { - registerModule(data, function (result) { - if (result instanceof Error) { - postMessage({ - messageId: messageId, - success: false, - error: result.message - }); - } else { - postMessage({ - messageId: messageId, - success: true, - result: { isCallable: typeof result === 'function' } - }); - } - }); - } - // Invocation - if (action === 'callModule') { - callModule(data, function (result, transferables) { - if (result instanceof Error) { - postMessage({ - messageId: messageId, - success: false, - error: result.message - }); - } else { - postMessage({ - messageId: messageId, - success: true, - result: result - }, transferables || undefined); - } - }); - } - } catch (err) { - postMessage({ - messageId: messageId, - success: false, - error: err.stack - }); - } - }); - } - - /** - * Fallback for `defineWorkerModule` that behaves identically but runs in the main - * thread, for when the execution environment doesn't support web workers or they - * are disallowed due to e.g. CSP security restrictions. - */ - function defineMainThreadModule(options) { - var moduleFunc = function moduleFunc() { - var args = [], - len = arguments.length; - while (len--) { - args[len] = arguments[len]; - }return moduleFunc._getInitResult().then(function (initResult) { - if (typeof initResult === 'function') { - return initResult.apply(void 0, args); - } else { - throw new Error('Worker module function was called but `init` did not return a callable function'); - } - }); - }; - moduleFunc._getInitResult = function () { - // We can ignore getTransferables in main thread. TODO workerId? - var dependencies = options.dependencies; - var init = options.init; - - // Resolve dependencies - dependencies = Array.isArray(dependencies) ? dependencies.map(function (dep) { - return dep && dep._getInitResult ? dep._getInitResult() : dep; - }) : []; - - // Invoke init with the resolved dependencies - var initThenable = DefaultThenable.all(dependencies).then(function (deps) { - return init.apply(null, deps); - }); - - // Cache the resolved promise for subsequent calls - moduleFunc._getInitResult = function () { - return initThenable; - }; - - return initThenable; - }; - return moduleFunc; - } - - var _supportsWorkers = function supportsWorkers() { - var supported = false; - - // Only attempt worker initialization in browsers; elsewhere it would just be - // noise e.g. loading into a Node environment for SSR. - if (typeof window !== 'undefined' && typeof window.document !== 'undefined') { - try { - // TODO additional checks for things like importScripts within the worker? - // Would need to be an async check. - var worker = new Worker(URL.createObjectURL(new Blob([''], { type: 'application/javascript' }))); - worker.terminate(); - supported = true; - } catch (err) { - if (typeof process !== 'undefined' && process.env.NODE_ENV === 'test') ;else { - console.log("Troika createWorkerModule: web workers not allowed; falling back to main thread execution. Cause: [" + err.message + "]"); - } - } - } - - // Cached result - _supportsWorkers = function supportsWorkers() { - return supported; - }; - return supported; - }; - - var _workerModuleId = 0; - var _messageId = 0; - var _allowInitAsString = false; - var workers = Object.create(null); - var openRequests = /*#__PURE__*/function () { - var obj = Object.create(null); - obj._count = 0; - return obj; - }(); - - /** - * Define a module of code that will be executed with a web worker. This provides a simple - * interface for moving chunks of logic off the main thread, and managing their dependencies - * among one another. - * - * @param {object} options - * @param {function} options.init - The main function that initializes the module. This will be run - * within the worker, and will be passed the resolved dependencies as arguments. Its - * return value becomes the module's content, which can then be used by other modules - * that depend on it. This function can perform any logic using those dependencies, but - * must not depend on anything from its parent closures. - * @param {array} [options.dependencies] - Provides any dependencies required by the init function: - * - Primitives like strings, numbers, booleans - * - Raw functions; these will be stringified and rehydrated within the worker so they - * must not depend on anything from their parent closures - * - Other worker modules; these will be resolved within the worker, and therefore modules - * that provide functions can be called without having to cross the worker/main thread - * boundary. - * @param {function} [options.getTransferables] - An optional function that will be run in the worker - * just before posting the response value from a module call back to the main thread. - * It will be passed that response value, and if it returns an array then that will be - * used as the "transferables" parameter to `postMessage`. Use this if there are values - * in the response that can/should be transfered rather than cloned. - * @param {string} [options.name] - A descriptive name for this module; this can be useful for - * debugging but is not currently used for anything else. - * @param {string} [options.workerId] - By default all modules will run in the same dedicated worker, - * but if you want to use multiple workers you can pass a `workerId` to indicate a specific - * worker to spawn. Note that each worker is completely standalone and no data or state will - * be shared between them. If a worker module is used as a dependency by worker modules - * using different `workerId`s, then that dependency will be re-registered in each worker. - * @return {function(...[*]): {then}} - */ - function defineWorkerModule(options) { - if ((!options || typeof options.init !== 'function') && !_allowInitAsString) { - throw new Error('requires `options.init` function'); - } - var dependencies = options.dependencies; - var init = options.init; - var getTransferables = options.getTransferables; - var workerId = options.workerId; - - if (!_supportsWorkers()) { - return defineMainThreadModule(options); - } - - if (workerId == null) { - workerId = '#default'; - } - var id = "workerModule" + ++_workerModuleId; - var name = options.name || id; - var registrationThenable = null; - - dependencies = dependencies && dependencies.map(function (dep) { - // Wrap raw functions as worker modules with no dependencies - if (typeof dep === 'function' && !dep.workerModuleData) { - _allowInitAsString = true; - dep = defineWorkerModule({ - workerId: workerId, - name: "<" + name + "> function dependency: " + dep.name, - init: "function(){return (\n" + stringifyFunction(dep) + "\n)}" - }); - _allowInitAsString = false; - } - // Grab postable data for worker modules - if (dep && dep.workerModuleData) { - dep = dep.workerModuleData; - } - return dep; - }); - - function moduleFunc() { - var args = [], - len = arguments.length; - while (len--) { - args[len] = arguments[len]; - } // Register this module if needed - if (!registrationThenable) { - registrationThenable = callWorker(workerId, 'registerModule', moduleFunc.workerModuleData); - } - - // Invoke the module, returning a thenable - return registrationThenable.then(function (ref) { - var isCallable = ref.isCallable; - - if (isCallable) { - return callWorker(workerId, 'callModule', { id: id, args: args }); - } else { - throw new Error('Worker module function was called but `init` did not return a callable function'); - } - }); - } - moduleFunc.workerModuleData = { - isWorkerModule: true, - id: id, - name: name, - dependencies: dependencies, - init: stringifyFunction(init), - getTransferables: getTransferables && stringifyFunction(getTransferables) - }; - return moduleFunc; - } - - /** - * Stringifies a function into a form that can be deserialized in the worker - * @param fn - */ - function stringifyFunction(fn) { - var str = fn.toString(); - // If it was defined in object method/property format, it needs to be modified - if (!/^function/.test(str) && /^\w+\s*\(/.test(str)) { - str = 'function ' + str; - } - return str; - } - - function getWorker(workerId) { - var worker = workers[workerId]; - if (!worker) { - // Bootstrap the worker's content - var bootstrap = stringifyFunction(workerBootstrap); - - // Create the worker from the bootstrap function content - worker = workers[workerId] = new Worker(URL.createObjectURL(new Blob(["/** Worker Module Bootstrap: " + workerId.replace(/\*/g, '') + " **/\n\n;(" + bootstrap + ")()"], { type: 'application/javascript' }))); - - // Single handler for response messages from the worker - worker.onmessage = function (e) { - var response = e.data; - var msgId = response.messageId; - var callback = openRequests[msgId]; - if (!callback) { - throw new Error('WorkerModule response with empty or unknown messageId'); - } - delete openRequests[msgId]; - openRequests.count--; - callback(response); - }; - } - return worker; - } - - // Issue a call to the worker with a callback to handle the response - function callWorker(workerId, action, data) { - var thenable = DefaultThenable(); - var messageId = ++_messageId; - openRequests[messageId] = function (response) { - if (response.success) { - thenable.resolve(response.result); - } else { - thenable.reject(new Error("Error in worker " + action + " call: " + response.error)); - } - }; - openRequests._count++; - if (openRequests.count > 1000) { - //detect leaks - console.warn('Large number of open WorkerModule requests, some may not be returning'); - } - getWorker(workerId).postMessage({ - messageId: messageId, - action: action, - data: data - }); - return thenable; - } - - /** - * Just the {@link Thenable} function wrapped as a worker module. If another worker - * module needs Thenable as a dependency, it's better to pass this module rather than - * the raw function in its `dependencies` array so it only gets registered once. - */ - var ThenableWorkerModule = /*#__PURE__*/defineWorkerModule({ - name: 'Thenable', - dependencies: [DefaultThenable], - init: function init(Thenable) { - return Thenable; - } - }); - - /** - * Regular expression for matching the `void main() {` opener line in GLSL. - * @type {RegExp} - */ - var voidMainRegExp = /\bvoid\s+main\s*\(\s*\)\s*{/g; - - /** - * Recursively expands all `#include ` statements within string of shader code. - * Copied from three's WebGLProgram#parseIncludes for external use. - * - * @param {string} source - The GLSL source code to evaluate - * @return {string} The GLSL code with all includes expanded - */ - function expandShaderIncludes(source) { - var pattern = /^[ \t]*#include +<([\w\d./]+)>/gm; - function replace(match, include) { - var chunk = THREE.ShaderChunk[include]; - return chunk ? expandShaderIncludes(chunk) : match; - } - return source.replace(pattern, replace); - } - - // Local assign polyfill to avoid importing troika-core - var assign = Object.assign || function () /*target, ...sources*/{ - var target = arguments[0]; - for (var i = 1, len = arguments.length; i < len; i++) { - var source = arguments[i]; - if (source) { - for (var prop in source) { - if (source.hasOwnProperty(prop)) { - target[prop] = source[prop]; - } - } - } - } - return target; - }; - - var epoch = Date.now(); - var CONSTRUCTOR_CACHE = new WeakMap(); - var SHADER_UPGRADE_CACHE = new Map(); - - // Material ids must be integers, but we can't access the increment from Three's `Material` module, - // so let's choose a sufficiently large starting value that should theoretically never collide. - var materialInstanceId = 1e10; - - /** - * A utility for creating a custom shader material derived from another material's - * shaders. This allows you to inject custom shader logic and transforms into the - * builtin ThreeJS materials without having to recreate them from scratch. - * - * @param {THREE.Material} baseMaterial - the original material to derive from - * - * @param {Object} options - How the base material should be modified. - * @param {Object} options.defines - Custom `defines` for the material - * @param {Object} options.extensions - Custom `extensions` for the material, e.g. `{derivatives: true}` - * @param {Object} options.uniforms - Custom `uniforms` for use in the modified shader. These can - * be accessed and manipulated via the resulting material's `uniforms` property, just like - * in a ShaderMaterial. You do not need to repeat the base material's own uniforms here. - * @param {String} options.timeUniform - If specified, a uniform of this name will be injected into - * both shaders, and it will automatically be updated on each render frame with a number of - * elapsed milliseconds. The "zero" epoch time is not significant so don't rely on this as a - * true calendar time. - * @param {String} options.vertexDefs - Custom GLSL code to inject into the vertex shader's top-level - * definitions, above the `void main()` function. - * @param {String} options.vertexMainIntro - Custom GLSL code to inject at the top of the vertex - * shader's `void main` function. - * @param {String} options.vertexMainOutro - Custom GLSL code to inject at the end of the vertex - * shader's `void main` function. - * @param {String} options.vertexTransform - Custom GLSL code to manipulate the `position`, `normal`, - * and/or `uv` vertex attributes. This code will be wrapped within a standalone function with - * those attributes exposed by their normal names as read/write values. - * @param {String} options.fragmentDefs - Custom GLSL code to inject into the fragment shader's top-level - * definitions, above the `void main()` function. - * @param {String} options.fragmentMainIntro - Custom GLSL code to inject at the top of the fragment - * shader's `void main` function. - * @param {String} options.fragmentMainOutro - Custom GLSL code to inject at the end of the fragment - * shader's `void main` function. You can manipulate `gl_FragColor` here but keep in mind it goes - * after any of ThreeJS's color postprocessing shader chunks (tonemapping, fog, etc.), so if you - * want those to apply to your changes use `fragmentColorTransform` instead. - * @param {String} options.fragmentColorTransform - Custom GLSL code to manipulate the `gl_FragColor` - * output value. Will be injected near the end of the `void main` function, but before any - * of ThreeJS's color postprocessing shader chunks (tonemapping, fog, etc.), and before the - * `fragmentMainOutro`. - * @param {function<{vertexShader,fragmentShader}>:{vertexShader,fragmentShader}} options.customRewriter - A function - * for performing custom rewrites of the full shader code. Useful if you need to do something - * special that's not covered by the other builtin options. This function will be executed before - * any other transforms are applied. - * @param {boolean} options.chained - Set to `true` to prototype-chain the derived material to the base - * material, rather than the default behavior of copying it. This allows the derived material to - * automatically pick up changes made to the base material and its properties. This can be useful - * where the derived material is hidden from the user as an implementation detail, allowing them - * to work with the original material like normal. But it can result in unexpected behavior if not - * handled carefully. - * - * @return {THREE.Material} - * - * The returned material will also have two new methods, `getDepthMaterial()` and `getDistanceMaterial()`, - * which can be called to get a variant of the derived material for use in shadow casting. If the - * target mesh is expected to cast shadows, then you can assign these to the mesh's `customDepthMaterial` - * (for directional and spot lights) and/or `customDistanceMaterial` (for point lights) properties to - * allow the cast shadow to honor your derived shader's vertex transforms and discarded fragments. These - * will also set a custom `#define IS_DEPTH_MATERIAL` or `#define IS_DISTANCE_MATERIAL` that you can look - * for in your derived shaders with `#ifdef` to customize their behavior for the depth or distance - * scenarios, e.g. skipping antialiasing or expensive shader logic. - */ - function createDerivedMaterial(baseMaterial, options) { - // Generate a key that is unique to the content of these `options`. We'll use this - // throughout for caching and for generating the upgraded shader code. This increases - // the likelihood that the resulting shaders will line up across multiple calls so - // their GL programs can be shared and cached. - var optionsKey = getKeyForOptions(options); - - // First check to see if we've already derived from this baseMaterial using this - // unique set of options, and if so reuse the constructor to avoid some allocations. - var ctorsByDerivation = CONSTRUCTOR_CACHE.get(baseMaterial); - if (!ctorsByDerivation) { - CONSTRUCTOR_CACHE.set(baseMaterial, ctorsByDerivation = Object.create(null)); - } - if (ctorsByDerivation[optionsKey]) { - return new ctorsByDerivation[optionsKey](); - } - - var privateBeforeCompileProp = '_onBeforeCompile' + optionsKey; - - // Private onBeforeCompile handler that injects the modified shaders and uniforms when - // the renderer switches to this material's program - var onBeforeCompile = function onBeforeCompile(shaderInfo) { - baseMaterial.onBeforeCompile.call(this, shaderInfo); - - // Upgrade the shaders, caching the result by incoming source code - var cacheKey = optionsKey + '|||' + shaderInfo.vertexShader + '|||' + shaderInfo.fragmentShader; - var upgradedShaders = SHADER_UPGRADE_CACHE[cacheKey]; - if (!upgradedShaders) { - var upgraded = upgradeShaders(shaderInfo, options, optionsKey); - upgradedShaders = SHADER_UPGRADE_CACHE[cacheKey] = upgraded; - } - - // Inject upgraded shaders and uniforms into the program - shaderInfo.vertexShader = upgradedShaders.vertexShader; - shaderInfo.fragmentShader = upgradedShaders.fragmentShader; - assign(shaderInfo.uniforms, this.uniforms); - - // Inject auto-updating time uniform if requested - if (options.timeUniform) { - shaderInfo.uniforms[options.timeUniform] = { - get value() { - return Date.now() - epoch; - } - }; - } - - // Users can still add their own handlers on top of ours - if (this[privateBeforeCompileProp]) { - this[privateBeforeCompileProp](shaderInfo); - } - }; - - var DerivedMaterial = function DerivedMaterial() { - return derive(options.chained ? baseMaterial : baseMaterial.clone()); - }; - - var derive = function derive(base) { - // Prototype chain to the base material - var derived = Object.create(base, descriptor); - - // Store the baseMaterial for reference; this is always the original even when cloning - Object.defineProperty(derived, 'baseMaterial', { value: baseMaterial }); - - // Needs its own ids - Object.defineProperty(derived, 'id', { value: materialInstanceId++ }); - derived.uuid = THREE.MathUtils.generateUUID(); - - // Merge uniforms, defines, and extensions - derived.uniforms = assign({}, base.uniforms, options.uniforms); - derived.defines = assign({}, base.defines, options.defines); - derived.defines['TROIKA_DERIVED_MATERIAL_' + optionsKey] = ''; //force a program change from the base material - derived.extensions = assign({}, base.extensions, options.extensions); - - // Don't inherit EventDispatcher listeners - derived._listeners = undefined; - - return derived; - }; - - var descriptor = { - constructor: { value: DerivedMaterial }, - isDerivedMaterial: { value: true }, - - customProgramCacheKey: { - value: function value() { - return optionsKey; - } - }, - - onBeforeCompile: { - get: function get() { - return onBeforeCompile; - }, - set: function set(fn) { - this[privateBeforeCompileProp] = fn; - } - }, - - copy: { - writable: true, - configurable: true, - value: function value(source) { - baseMaterial.copy.call(this, source); - if (!baseMaterial.isShaderMaterial && !baseMaterial.isDerivedMaterial) { - assign(this.extensions, source.extensions); - assign(this.defines, source.defines); - assign(this.uniforms, THREE.UniformsUtils.clone(source.uniforms)); - } - return this; - } - }, - - clone: { - writable: true, - configurable: true, - value: function value() { - var newBase = new baseMaterial.constructor(); - return derive(newBase).copy(this); - } - }, - - /** - * Utility to get a MeshDepthMaterial that will honor this derived material's vertex - * transformations and discarded fragments. - */ - getDepthMaterial: { - writable: true, - configurable: true, - value: function value() { - var depthMaterial = this._depthMaterial; - if (!depthMaterial) { - depthMaterial = this._depthMaterial = createDerivedMaterial(baseMaterial.isDerivedMaterial ? baseMaterial.getDepthMaterial() : new THREE.MeshDepthMaterial({ depthPacking: THREE.RGBADepthPacking }), options); - depthMaterial.defines.IS_DEPTH_MATERIAL = ''; - depthMaterial.uniforms = this.uniforms; //automatically recieve same uniform values - } - return depthMaterial; - } - }, - - /** - * Utility to get a MeshDistanceMaterial that will honor this derived material's vertex - * transformations and discarded fragments. - */ - getDistanceMaterial: { - writable: true, - configurable: true, - value: function value() { - var distanceMaterial = this._distanceMaterial; - if (!distanceMaterial) { - distanceMaterial = this._distanceMaterial = createDerivedMaterial(baseMaterial.isDerivedMaterial ? baseMaterial.getDistanceMaterial() : new THREE.MeshDistanceMaterial(), options); - distanceMaterial.defines.IS_DISTANCE_MATERIAL = ''; - distanceMaterial.uniforms = this.uniforms; //automatically recieve same uniform values - } - return distanceMaterial; - } - }, - - dispose: { - writable: true, - configurable: true, - value: function value() { - var _depthMaterial = this._depthMaterial, - _distanceMaterial = this._distanceMaterial; - - if (_depthMaterial) _depthMaterial.dispose(); - if (_distanceMaterial) _distanceMaterial.dispose(); - baseMaterial.dispose.call(this); - } - } - }; - - ctorsByDerivation[optionsKey] = DerivedMaterial; - return new DerivedMaterial(); - } - - function upgradeShaders(_ref, options, key) { - var vertexShader = _ref.vertexShader, - fragmentShader = _ref.fragmentShader; - var vertexDefs = options.vertexDefs, - vertexMainIntro = options.vertexMainIntro, - vertexMainOutro = options.vertexMainOutro, - vertexTransform = options.vertexTransform, - fragmentDefs = options.fragmentDefs, - fragmentMainIntro = options.fragmentMainIntro, - fragmentMainOutro = options.fragmentMainOutro, - fragmentColorTransform = options.fragmentColorTransform, - customRewriter = options.customRewriter, - timeUniform = options.timeUniform; - - - vertexDefs = vertexDefs || ''; - vertexMainIntro = vertexMainIntro || ''; - vertexMainOutro = vertexMainOutro || ''; - fragmentDefs = fragmentDefs || ''; - fragmentMainIntro = fragmentMainIntro || ''; - fragmentMainOutro = fragmentMainOutro || ''; - - // Expand includes if needed - if (vertexTransform || customRewriter) { - vertexShader = expandShaderIncludes(vertexShader); - } - if (fragmentColorTransform || customRewriter) { - // We need to be able to find postprocessing chunks after include expansion in order to - // put them after the fragmentColorTransform, so mark them with comments first. Even if - // this particular derivation doesn't have a fragmentColorTransform, other derivations may, - // so we still mark them. - fragmentShader = fragmentShader.replace(/^[ \t]*#include <((?:tonemapping|encodings|fog|premultiplied_alpha|dithering)_fragment)>/gm, '\n//!BEGIN_POST_CHUNK $1\n$&\n//!END_POST_CHUNK\n'); - fragmentShader = expandShaderIncludes(fragmentShader); - } - - // Apply custom rewriter function - if (customRewriter) { - var res = customRewriter({ vertexShader: vertexShader, fragmentShader: fragmentShader }); - vertexShader = res.vertexShader; - fragmentShader = res.fragmentShader; - } - - // The fragmentColorTransform needs to go before any postprocessing chunks, so extract - // those and re-insert them into the outro in the correct place: - if (fragmentColorTransform) { - var postChunks = []; - fragmentShader = fragmentShader.replace(/^\/\/!BEGIN_POST_CHUNK[^]+?^\/\/!END_POST_CHUNK/gm, // [^]+? = non-greedy match of any chars including newlines - function (match) { - postChunks.push(match); - return ''; - }); - fragmentMainOutro = fragmentColorTransform + '\n' + postChunks.join('\n') + '\n' + fragmentMainOutro; - } - - // Inject auto-updating time uniform if requested - if (timeUniform) { - var code = '\nuniform float ' + timeUniform + ';\n'; - vertexDefs = code + vertexDefs; - fragmentDefs = code + fragmentDefs; - } - - // Inject a function for the vertexTransform and rename all usages of position/normal/uv - if (vertexTransform) { - vertexDefs = vertexDefs + '\nvec3 troika_position_' + key + ';\nvec3 troika_normal_' + key + ';\nvec2 troika_uv_' + key + ';\nvoid troikaVertexTransform' + key + '(inout vec3 position, inout vec3 normal, inout vec2 uv) {\n ' + vertexTransform + '\n}\n'; - vertexMainIntro = '\ntroika_position_' + key + ' = vec3(position);\ntroika_normal_' + key + ' = vec3(normal);\ntroika_uv_' + key + ' = vec2(uv);\ntroikaVertexTransform' + key + '(troika_position_' + key + ', troika_normal_' + key + ', troika_uv_' + key + ');\n' + vertexMainIntro + '\n'; - vertexShader = vertexShader.replace(/\b(position|normal|uv)\b/g, function (match, match1, index, fullStr) { - return (/\battribute\s+vec[23]\s+$/.test(fullStr.substr(0, index)) ? match1 : 'troika_' + match1 + '_' + key - ); - }); - } - - // Inject defs and intro/outro snippets - vertexShader = injectIntoShaderCode(vertexShader, key, vertexDefs, vertexMainIntro, vertexMainOutro); - fragmentShader = injectIntoShaderCode(fragmentShader, key, fragmentDefs, fragmentMainIntro, fragmentMainOutro); - - return { - vertexShader: vertexShader, - fragmentShader: fragmentShader - }; - } - - function injectIntoShaderCode(shaderCode, id, defs, intro, outro) { - if (intro || outro || defs) { - shaderCode = shaderCode.replace(voidMainRegExp, '\n' + defs + '\nvoid troikaOrigMain' + id + '() {'); - shaderCode += '\nvoid main() {\n ' + intro + '\n troikaOrigMain' + id + '();\n ' + outro + '\n}'; - } - return shaderCode; - } - - function optionsJsonReplacer(key, value) { - return key === 'uniforms' ? undefined : typeof value === 'function' ? value.toString() : value; - } - - var _idCtr = 0; - var optionsHashesToIds = new Map(); - function getKeyForOptions(options) { - var optionsHash = JSON.stringify(options, optionsJsonReplacer); - var id = optionsHashesToIds.get(optionsHash); - if (id == null) { - optionsHashesToIds.set(optionsHash, id = ++_idCtr); - } - return id; - } - - /** - * Initializes and returns a function to generate an SDF texture for a given glyph. - * @param {function} createGlyphSegmentsIndex - factory for a GlyphSegmentsIndex implementation. - * @param {number} config.sdfExponent - * @param {number} config.sdfMargin - * - * @return {function(Object): {renderingBounds: [minX, minY, maxX, maxY], textureData: Uint8Array}} - */ - function createSDFGenerator(createGlyphSegmentsIndex, config) { - var sdfExponent = config.sdfExponent, - sdfMargin = config.sdfMargin; - - /** - * How many straight line segments to use when approximating a glyph's quadratic/cubic bezier curves. - */ - - var CURVE_POINTS = 16; - - /** - * Find the point on a quadratic bezier curve at t where t is in the range [0, 1] - */ - function pointOnQuadraticBezier(x0, y0, x1, y1, x2, y2, t) { - var t2 = 1 - t; - return { - x: t2 * t2 * x0 + 2 * t2 * t * x1 + t * t * x2, - y: t2 * t2 * y0 + 2 * t2 * t * y1 + t * t * y2 - }; - } - - /** - * Find the point on a cubic bezier curve at t where t is in the range [0, 1] - */ - function pointOnCubicBezier(x0, y0, x1, y1, x2, y2, x3, y3, t) { - var t2 = 1 - t; - return { - x: t2 * t2 * t2 * x0 + 3 * t2 * t2 * t * x1 + 3 * t2 * t * t * x2 + t * t * t * x3, - y: t2 * t2 * t2 * y0 + 3 * t2 * t2 * t * y1 + 3 * t2 * t * t * y2 + t * t * t * y3 - }; - } - - /** - * Generate an SDF texture segment for a single glyph. - * @param {object} glyphObj - * @param {number} sdfSize - the length of one side of the SDF image. - * Larger images encode more details. Must be a power of 2. - * @return {{textureData: Uint8Array, renderingBounds: *[]}} - */ - function generateSDF(glyphObj, sdfSize) { - //console.time('glyphSDF') - - var textureData = new Uint8Array(sdfSize * sdfSize); - - // Determine mapping between glyph grid coords and sdf grid coords - var glyphW = glyphObj.xMax - glyphObj.xMin; - var glyphH = glyphObj.yMax - glyphObj.yMin; - - // Choose a maximum search distance radius in font units, based on the glyph's max dimensions - var fontUnitsMaxSearchDist = Math.max(glyphW, glyphH); - - // Margin - add an extra 0.5 over the configured value because the outer 0.5 doesn't contain - // useful interpolated values and will be ignored anyway. - var fontUnitsMargin = Math.max(glyphW, glyphH) / sdfSize * (sdfMargin * sdfSize + 0.5); - - // Metrics of the texture/quad in font units - var textureMinFontX = glyphObj.xMin - fontUnitsMargin; - var textureMinFontY = glyphObj.yMin - fontUnitsMargin; - var textureMaxFontX = glyphObj.xMax + fontUnitsMargin; - var textureMaxFontY = glyphObj.yMax + fontUnitsMargin; - var fontUnitsTextureWidth = textureMaxFontX - textureMinFontX; - var fontUnitsTextureHeight = textureMaxFontY - textureMinFontY; - var fontUnitsTextureMaxDim = Math.max(fontUnitsTextureWidth, fontUnitsTextureHeight); - - function textureXToFontX(x) { - return textureMinFontX + fontUnitsTextureWidth * x / sdfSize; - } - - function textureYToFontY(y) { - return textureMinFontY + fontUnitsTextureHeight * y / sdfSize; - } - - if (glyphObj.pathCommandCount) { - //whitespace chars will have no commands, so we can skip all this - // Decompose all paths into straight line segments and add them to a quadtree - var lineSegmentsIndex = createGlyphSegmentsIndex(glyphObj); - var firstX = void 0, - firstY = void 0, - prevX = void 0, - prevY = void 0; - glyphObj.forEachPathCommand(function (type, x0, y0, x1, y1, x2, y2) { - switch (type) { - case 'M': - prevX = firstX = x0; - prevY = firstY = y0; - break; - case 'L': - if (x0 !== prevX || y0 !== prevY) { - //yup, some fonts have zero-length line commands - lineSegmentsIndex.addLineSegment(prevX, prevY, prevX = x0, prevY = y0); - } - break; - case 'Q': - { - var prevPoint = { x: prevX, y: prevY }; - for (var i = 1; i < CURVE_POINTS; i++) { - var nextPoint = pointOnQuadraticBezier(prevX, prevY, x0, y0, x1, y1, i / (CURVE_POINTS - 1)); - lineSegmentsIndex.addLineSegment(prevPoint.x, prevPoint.y, nextPoint.x, nextPoint.y); - prevPoint = nextPoint; - } - prevX = x1; - prevY = y1; - break; - } - case 'C': - { - var _prevPoint = { x: prevX, y: prevY }; - for (var _i = 1; _i < CURVE_POINTS; _i++) { - var _nextPoint = pointOnCubicBezier(prevX, prevY, x0, y0, x1, y1, x2, y2, _i / (CURVE_POINTS - 1)); - lineSegmentsIndex.addLineSegment(_prevPoint.x, _prevPoint.y, _nextPoint.x, _nextPoint.y); - _prevPoint = _nextPoint; - } - prevX = x2; - prevY = y2; - break; - } - case 'Z': - if (prevX !== firstX || prevY !== firstY) { - lineSegmentsIndex.addLineSegment(prevX, prevY, firstX, firstY); - } - break; - } - }); - - // For each target SDF texel, find the distance from its center to its nearest line segment, - // map that distance to an alpha value, and write that alpha to the texel - for (var sdfX = 0; sdfX < sdfSize; sdfX++) { - for (var sdfY = 0; sdfY < sdfSize; sdfY++) { - var signedDist = lineSegmentsIndex.findNearestSignedDistance(textureXToFontX(sdfX + 0.5), textureYToFontY(sdfY + 0.5), fontUnitsMaxSearchDist); - - // Use an exponential scale to ensure the texels very near the glyph path have adequate - // precision, while allowing the distance field to cover the entire texture, given that - // there are only 8 bits available. Formula visualized: https://www.desmos.com/calculator/uiaq5aqiam - var alpha = Math.pow(1 - Math.abs(signedDist) / fontUnitsTextureMaxDim, sdfExponent) / 2; - if (signedDist < 0) { - alpha = 1 - alpha; - } - - alpha = Math.max(0, Math.min(255, Math.round(alpha * 255))); //clamp - textureData[sdfY * sdfSize + sdfX] = alpha; - } - } - } - - //console.timeEnd('glyphSDF') - - return { - textureData: textureData, - - renderingBounds: [textureMinFontX, textureMinFontY, textureMaxFontX, textureMaxFontY] - }; - } - - return generateSDF; - } - - /** - * Creates a self-contained environment for processing text rendering requests. - * - * It is important that this function has no closure dependencies, so that it can be easily injected - * into the source for a Worker without requiring a build step or complex dependency loading. All its - * dependencies must be passed in at initialization. - * - * @param {function} fontParser - a function that accepts an ArrayBuffer of the font data and returns - * a standardized structure giving access to the font and its glyphs: - * { - * unitsPerEm: number, - * ascender: number, - * descender: number, - * forEachGlyph(string, fontSize, letterSpacing, callback) { - * //invokes callback for each glyph to render, passing it an object: - * callback({ - * index: number, - * advanceWidth: number, - * xMin: number, - * yMin: number, - * xMax: number, - * yMax: number, - * pathCommandCount: number, - * forEachPathCommand(callback) { - * //invokes callback for each path command, with args: - * callback( - * type: 'M|L|C|Q|Z', - * ...args //0 to 6 args depending on the type - * ) - * } - * }) - * } - * } - * @param {function} sdfGenerator - a function that accepts a glyph object and generates an SDF texture - * from it. - * @param {Object} config - * @return {Object} - */ - function createFontProcessor(fontParser, sdfGenerator, config) { - var defaultFontURL = config.defaultFontURL; - - /** - * @private - * Holds data about font glyphs and how they relate to SDF atlases - * - * { - * 'fontUrl@sdfSize': { - * fontObj: {}, //result of the fontParser - * glyphs: { - * [glyphIndex]: { - * atlasIndex: 0, - * glyphObj: {}, //glyph object from the fontParser - * renderingBounds: [x0, y0, x1, y1] - * }, - * ... - * }, - * glyphCount: 123 - * } - * } - */ - - var fontAtlases = Object.create(null); - - /** - * Holds parsed font objects by url - */ - var fonts = Object.create(null); - - var INF = Infinity; - - /** - * Load a given font url - */ - function doLoadFont(url, callback) { - function tryLoad() { - var onError = function onError(err) { - console.error('Failure loading font ' + url + (url === defaultFontURL ? '' : '; trying fallback'), err); - if (url !== defaultFontURL) { - url = defaultFontURL; - tryLoad(); - } - }; - try { - var request = new XMLHttpRequest(); - request.open('get', url, true); - request.responseType = 'arraybuffer'; - request.onload = function () { - if (request.status >= 400) { - onError(new Error(request.statusText)); - } else if (request.status > 0) { - try { - var fontObj = fontParser(request.response); - callback(fontObj); - } catch (e) { - onError(e); - } - } - }; - request.onerror = onError; - request.send(); - } catch (err) { - onError(err); - } - } - tryLoad(); - } - - /** - * Load a given font url if needed, invoking a callback when it's loaded. If already - * loaded, the callback will be called synchronously. - */ - function loadFont(fontUrl, callback) { - if (!fontUrl) fontUrl = defaultFontURL; - var font = fonts[fontUrl]; - if (font) { - // if currently loading font, add to callbacks, otherwise execute immediately - if (font.pending) { - font.pending.push(callback); - } else { - callback(font); - } - } else { - fonts[fontUrl] = { pending: [callback] }; - doLoadFont(fontUrl, function (fontObj) { - var callbacks = fonts[fontUrl].pending; - fonts[fontUrl] = fontObj; - callbacks.forEach(function (cb) { - return cb(fontObj); - }); - }); - } - } - - /** - * Get the atlas data for a given font url, loading it from the network and initializing - * its atlas data objects if necessary. - */ - function getSdfAtlas(fontUrl, sdfGlyphSize, callback) { - if (!fontUrl) fontUrl = defaultFontURL; - var atlasKey = fontUrl + '@' + sdfGlyphSize; - var atlas = fontAtlases[atlasKey]; - if (atlas) { - callback(atlas); - } else { - loadFont(fontUrl, function (fontObj) { - atlas = fontAtlases[atlasKey] || (fontAtlases[atlasKey] = { - fontObj: fontObj, - glyphs: {}, - glyphCount: 0 - }); - callback(atlas); - }); - } - } - - /** - * Main entry point. - * Process a text string with given font and formatting parameters, and return all info - * necessary to render all its glyphs. - */ - function process(_ref2, callback) { - var _ref2$text = _ref2.text, - text = _ref2$text === undefined ? '' : _ref2$text, - _ref2$font = _ref2.font, - font = _ref2$font === undefined ? defaultFontURL : _ref2$font, - _ref2$sdfGlyphSize = _ref2.sdfGlyphSize, - sdfGlyphSize = _ref2$sdfGlyphSize === undefined ? 64 : _ref2$sdfGlyphSize, - _ref2$fontSize = _ref2.fontSize, - fontSize = _ref2$fontSize === undefined ? 1 : _ref2$fontSize, - _ref2$letterSpacing = _ref2.letterSpacing, - letterSpacing = _ref2$letterSpacing === undefined ? 0 : _ref2$letterSpacing, - _ref2$lineHeight = _ref2.lineHeight, - lineHeight = _ref2$lineHeight === undefined ? 'normal' : _ref2$lineHeight, - _ref2$maxWidth = _ref2.maxWidth, - maxWidth = _ref2$maxWidth === undefined ? INF : _ref2$maxWidth, - _ref2$textAlign = _ref2.textAlign, - textAlign = _ref2$textAlign === undefined ? 'left' : _ref2$textAlign, - _ref2$textIndent = _ref2.textIndent, - textIndent = _ref2$textIndent === undefined ? 0 : _ref2$textIndent, - _ref2$whiteSpace = _ref2.whiteSpace, - whiteSpace = _ref2$whiteSpace === undefined ? 'normal' : _ref2$whiteSpace, - _ref2$overflowWrap = _ref2.overflowWrap, - overflowWrap = _ref2$overflowWrap === undefined ? 'normal' : _ref2$overflowWrap, - _ref2$anchorX = _ref2.anchorX, - anchorX = _ref2$anchorX === undefined ? 0 : _ref2$anchorX, - _ref2$anchorY = _ref2.anchorY, - anchorY = _ref2$anchorY === undefined ? 0 : _ref2$anchorY, - _ref2$includeCaretPos = _ref2.includeCaretPositions, - includeCaretPositions = _ref2$includeCaretPos === undefined ? false : _ref2$includeCaretPos, - _ref2$chunkedBoundsSi = _ref2.chunkedBoundsSize, - chunkedBoundsSize = _ref2$chunkedBoundsSi === undefined ? 8192 : _ref2$chunkedBoundsSi, - _ref2$colorRanges = _ref2.colorRanges, - colorRanges = _ref2$colorRanges === undefined ? null : _ref2$colorRanges; - var metricsOnly = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false; - - var mainStart = now(); - var timings = { total: 0, fontLoad: 0, layout: 0, sdf: {}, sdfTotal: 0 }; - - // Ensure newlines are normalized - if (text.indexOf('\r') > -1) { - console.warn('FontProcessor.process: got text with \\r chars; normalizing to \\n'); - text = text.replace(/\r\n/g, '\n').replace(/\r/g, '\n'); - } - - // Ensure we've got numbers not strings - fontSize = +fontSize; - letterSpacing = +letterSpacing; - maxWidth = +maxWidth; - lineHeight = lineHeight || 'normal'; - textIndent = +textIndent; - - getSdfAtlas(font, sdfGlyphSize, function (atlas) { - var fontObj = atlas.fontObj; - var hasMaxWidth = isFinite(maxWidth); - var newGlyphs = null; - var glyphBounds = null; - var glyphAtlasIndices = null; - var glyphColors = null; - var caretPositions = null; - var visibleBounds = null; - var chunkedBounds = null; - var maxLineWidth = 0; - var renderableGlyphCount = 0; - var canWrap = whiteSpace !== 'nowrap'; - var ascender = fontObj.ascender, - descender = fontObj.descender, - unitsPerEm = fontObj.unitsPerEm; - - timings.fontLoad = now() - mainStart; - var layoutStart = now(); - - // Find conversion between native font units and fontSize units; this will already be done - // for the gx/gy values below but everything else we'll need to convert - var fontSizeMult = fontSize / unitsPerEm; - - // Determine appropriate value for 'normal' line height based on the font's actual metrics - // TODO this does not guarantee individual glyphs won't exceed the line height, e.g. Roboto; should we use yMin/Max instead? - if (lineHeight === 'normal') { - lineHeight = (ascender - descender) / unitsPerEm; - } - - // Determine line height and leading adjustments - lineHeight = lineHeight * fontSize; - var halfLeading = (lineHeight - (ascender - descender) * fontSizeMult) / 2; - var topBaseline = -(ascender * fontSizeMult + halfLeading); - var caretHeight = Math.min(lineHeight, (ascender - descender) * fontSizeMult); - var caretBottomOffset = (ascender + descender) / 2 * fontSizeMult - caretHeight / 2; - - // Distribute glyphs into lines based on wrapping - var lineXOffset = textIndent; - var currentLine = new TextLine(); - var lines = [currentLine]; - fontObj.forEachGlyph(text, fontSize, letterSpacing, function (glyphObj, glyphX, charIndex) { - var char = text.charAt(charIndex); - var glyphWidth = glyphObj.advanceWidth * fontSizeMult; - var curLineCount = currentLine.count; - var nextLine = void 0; - - // Calc isWhitespace and isEmpty once per glyphObj - if (!('isEmpty' in glyphObj)) { - glyphObj.isWhitespace = !!char && /\s/.test(char); - glyphObj.isEmpty = glyphObj.xMin === glyphObj.xMax || glyphObj.yMin === glyphObj.yMax; - } - if (!glyphObj.isWhitespace && !glyphObj.isEmpty) { - renderableGlyphCount++; - } - - // If a non-whitespace character overflows the max width, we need to soft-wrap - if (canWrap && hasMaxWidth && !glyphObj.isWhitespace && glyphX + glyphWidth + lineXOffset > maxWidth && curLineCount) { - // If it's the first char after a whitespace, start a new line - if (currentLine.glyphAt(curLineCount - 1).glyphObj.isWhitespace) { - nextLine = new TextLine(); - lineXOffset = -glyphX; - } else { - // Back up looking for a whitespace character to wrap at - for (var i = curLineCount; i--;) { - // If we got the start of the line there's no soft break point; make hard break if overflowWrap='break-word' - if (i === 0 && overflowWrap === 'break-word') { - nextLine = new TextLine(); - lineXOffset = -glyphX; - break; - } - // Found a soft break point; move all chars since it to a new line - else if (currentLine.glyphAt(i).glyphObj.isWhitespace) { - nextLine = currentLine.splitAt(i + 1); - var adjustX = nextLine.glyphAt(0).x; - lineXOffset -= adjustX; - for (var j = nextLine.count; j--;) { - nextLine.glyphAt(j).x -= adjustX; - } - break; - } - } - } - if (nextLine) { - currentLine.isSoftWrapped = true; - currentLine = nextLine; - lines.push(currentLine); - maxLineWidth = maxWidth; //after soft wrapping use maxWidth as calculated width - } - } - - var fly = currentLine.glyphAt(currentLine.count); - fly.glyphObj = glyphObj; - fly.x = glyphX + lineXOffset; - fly.width = glyphWidth; - fly.charIndex = charIndex; - - // Handle hard line breaks - if (char === '\n') { - currentLine = new TextLine(); - lines.push(currentLine); - lineXOffset = -(glyphX + glyphWidth + letterSpacing * fontSize) + textIndent; - } - }); - - // Calculate width of each line (excluding trailing whitespace) and maximum block width - lines.forEach(function (line) { - for (var i = line.count; i--;) { - var _line$glyphAt = line.glyphAt(i), - glyphObj = _line$glyphAt.glyphObj, - x = _line$glyphAt.x, - width = _line$glyphAt.width; - - if (!glyphObj.isWhitespace) { - line.width = x + width; - if (line.width > maxLineWidth) { - maxLineWidth = line.width; - } - return; - } - } - }); - - // Find overall position adjustments for anchoring - var anchorXOffset = 0; - var anchorYOffset = 0; - if (anchorX) { - if (typeof anchorX === 'number') { - anchorXOffset = -anchorX; - } else if (typeof anchorX === 'string') { - anchorXOffset = -maxLineWidth * (anchorX === 'left' ? 0 : anchorX === 'center' ? 0.5 : anchorX === 'right' ? 1 : parsePercent(anchorX)); - } - } - if (anchorY) { - if (typeof anchorY === 'number') { - anchorYOffset = -anchorY; - } else if (typeof anchorY === 'string') { - var height = lines.length * lineHeight; - anchorYOffset = anchorY === 'top' ? 0 : anchorY === 'top-baseline' ? -topBaseline : anchorY === 'middle' ? height / 2 : anchorY === 'bottom' ? height : anchorY === 'bottom-baseline' ? height - halfLeading + descender * fontSizeMult : parsePercent(anchorY) * height; - } - } - - if (!metricsOnly) { - // Process each line, applying alignment offsets, adding each glyph to the atlas, and - // collecting all renderable glyphs into a single collection. - glyphBounds = new Float32Array(renderableGlyphCount * 4); - glyphAtlasIndices = new Float32Array(renderableGlyphCount); - visibleBounds = [INF, INF, -INF, -INF]; - chunkedBounds = []; - var lineYOffset = topBaseline; - if (includeCaretPositions) { - caretPositions = new Float32Array(text.length * 3); - } - if (colorRanges) { - glyphColors = new Uint8Array(renderableGlyphCount * 3); - } - var renderableGlyphIndex = 0; - var prevCharIndex = -1; - var colorCharIndex = -1; - var chunk = void 0; - var currentColor = void 0; - lines.forEach(function (line) { - var lineGlyphCount = line.count, - lineWidth = line.width; - - // Ignore empty lines - - if (lineGlyphCount > 0) { - // Find x offset for horizontal alignment - var _lineXOffset = 0; - var justifyAdjust = 0; - if (textAlign === 'center') { - _lineXOffset = (maxLineWidth - lineWidth) / 2; - } else if (textAlign === 'right') { - _lineXOffset = maxLineWidth - lineWidth; - } else if (textAlign === 'justify' && line.isSoftWrapped) { - // just count the non-trailing whitespace characters, and we'll adjust the offsets per - // character in the next loop - var whitespaceCount = 0; - for (var i = lineGlyphCount; i--;) { - if (!line.glyphAt(i).glyphObj.isWhitespace) { - while (i--) { - if (!line.glyphAt(i).glyphObj) { - debugger; - } - if (line.glyphAt(i).glyphObj.isWhitespace) { - whitespaceCount++; - } - } - break; - } - } - justifyAdjust = (maxLineWidth - lineWidth) / whitespaceCount; - } - - for (var _i2 = 0; _i2 < lineGlyphCount; _i2++) { - var glyphInfo = line.glyphAt(_i2); - var glyphObj = glyphInfo.glyphObj; - - // Apply position adjustments - if (_lineXOffset) glyphInfo.x += _lineXOffset; - - // Expand whitespaces for justify alignment - if (justifyAdjust !== 0 && glyphObj.isWhitespace) { - _lineXOffset += justifyAdjust; - glyphInfo.width += justifyAdjust; - } - - // Add caret positions - if (includeCaretPositions) { - var charIndex = glyphInfo.charIndex; - - caretPositions[charIndex * 3] = glyphInfo.x + anchorXOffset; //left edge x - caretPositions[charIndex * 3 + 1] = glyphInfo.x + glyphInfo.width + anchorXOffset; //right edge x - caretPositions[charIndex * 3 + 2] = lineYOffset + caretBottomOffset + anchorYOffset; //common bottom y - - // If we skipped any chars from the previous glyph (due to ligature subs), copy the - // previous glyph's info to those missing char indices. In the future we may try to - // use the font's LigatureCaretList table to get interior caret positions. - while (charIndex - prevCharIndex > 1) { - caretPositions[(prevCharIndex + 1) * 3] = caretPositions[prevCharIndex * 3 + 1]; - caretPositions[(prevCharIndex + 1) * 3 + 1] = caretPositions[prevCharIndex * 3 + 1]; - caretPositions[(prevCharIndex + 1) * 3 + 2] = caretPositions[prevCharIndex * 3 + 2]; - prevCharIndex++; - } - prevCharIndex = charIndex; - } - - // Track current color range - if (colorRanges) { - var _charIndex = glyphInfo.charIndex; - - while (_charIndex > colorCharIndex) { - colorCharIndex++; - if (colorRanges.hasOwnProperty(colorCharIndex)) { - currentColor = colorRanges[colorCharIndex]; - } - } - } - - // Get atlas data for renderable glyphs - if (!glyphObj.isWhitespace && !glyphObj.isEmpty) { - var idx = renderableGlyphIndex++; - - // If we haven't seen this glyph yet, generate its SDF - var glyphAtlasInfo = atlas.glyphs[glyphObj.index]; - if (!glyphAtlasInfo) { - var sdfStart = now(); - var glyphSDFData = sdfGenerator(glyphObj, sdfGlyphSize); - timings.sdf[text.charAt(glyphInfo.charIndex)] = now() - sdfStart; - - // Assign this glyph the next available atlas index - glyphSDFData.atlasIndex = atlas.glyphCount++; - - // Queue it up in the response's newGlyphs list - if (!newGlyphs) newGlyphs = []; - newGlyphs.push(glyphSDFData); - - // Store its metadata (not the texture) in our atlas info - glyphAtlasInfo = atlas.glyphs[glyphObj.index] = { - atlasIndex: glyphSDFData.atlasIndex, - glyphObj: glyphObj, - renderingBounds: glyphSDFData.renderingBounds - }; - } - - // Determine final glyph quad bounds and add them to the glyphBounds array - var bounds = glyphAtlasInfo.renderingBounds; - var startIdx = idx * 4; - var xStart = glyphInfo.x + anchorXOffset; - var yStart = lineYOffset + anchorYOffset; - glyphBounds[startIdx] = xStart + bounds[0] * fontSizeMult; - glyphBounds[startIdx + 1] = yStart + bounds[1] * fontSizeMult; - glyphBounds[startIdx + 2] = xStart + bounds[2] * fontSizeMult; - glyphBounds[startIdx + 3] = yStart + bounds[3] * fontSizeMult; - - // Track total visible bounds - var visX0 = xStart + glyphObj.xMin * fontSizeMult; - var visY0 = yStart + glyphObj.yMin * fontSizeMult; - var visX1 = xStart + glyphObj.xMax * fontSizeMult; - var visY1 = yStart + glyphObj.yMax * fontSizeMult; - if (visX0 < visibleBounds[0]) visibleBounds[0] = visX0; - if (visY0 < visibleBounds[1]) visibleBounds[1] = visY0; - if (visX1 > visibleBounds[2]) visibleBounds[2] = visX1; - if (visY1 > visibleBounds[3]) visibleBounds[3] = visY1; - - // Track bounding rects for each chunk of N glyphs - if (idx % chunkedBoundsSize === 0) { - chunk = { start: idx, end: idx, rect: [INF, INF, -INF, -INF] }; - chunkedBounds.push(chunk); - } - chunk.end++; - var chunkRect = chunk.rect; - if (visX0 < chunkRect[0]) chunkRect[0] = visX0; - if (visY0 < chunkRect[1]) chunkRect[1] = visY0; - if (visX1 > chunkRect[2]) chunkRect[2] = visX1; - if (visY1 > chunkRect[3]) chunkRect[3] = visY1; - - // Add to atlas indices array - glyphAtlasIndices[idx] = glyphAtlasInfo.atlasIndex; - - // Add colors - if (colorRanges) { - var start = idx * 3; - glyphColors[start] = currentColor >> 16 & 255; - glyphColors[start + 1] = currentColor >> 8 & 255; - glyphColors[start + 2] = currentColor & 255; - } - } - } - } - - // Increment y offset for next line - lineYOffset -= lineHeight; - }); - } - - // Timing stats - for (var ch in timings.sdf) { - timings.sdfTotal += timings.sdf[ch]; - } - timings.layout = now() - layoutStart - timings.sdfTotal; - timings.total = now() - mainStart; - - callback({ - glyphBounds: glyphBounds, //rendering quad bounds for each glyph [x1, y1, x2, y2] - glyphAtlasIndices: glyphAtlasIndices, //atlas indices for each glyph - caretPositions: caretPositions, //x,y of bottom of cursor position before each char, plus one after last char - caretHeight: caretHeight, //height of cursor from bottom to top - glyphColors: glyphColors, //color for each glyph, if color ranges supplied - chunkedBounds: chunkedBounds, //total rects per (n=chunkedBoundsSize) consecutive glyphs - ascender: ascender * fontSizeMult, //font ascender - descender: descender * fontSizeMult, //font descender - lineHeight: lineHeight, //computed line height - topBaseline: topBaseline, //y coordinate of the top line's baseline - blockBounds: [//bounds for the whole block of text, including vertical padding for lineHeight - anchorXOffset, anchorYOffset - lines.length * lineHeight, anchorXOffset + maxLineWidth, anchorYOffset], - visibleBounds: visibleBounds, //total bounds of visible text paths, may be larger or smaller than totalBounds - newGlyphSDFs: newGlyphs, //if this request included any new SDFs for the atlas, they'll be included here - timings: timings - }); - }); - } - - /** - * For a given text string and font parameters, determine the resulting block dimensions - * after wrapping for the given maxWidth. - * @param args - * @param callback - */ - function measure(args, callback) { - process(args, function (result) { - var _result$blockBounds = _slicedToArray(result.blockBounds, 4), - x0 = _result$blockBounds[0], - y0 = _result$blockBounds[1], - x1 = _result$blockBounds[2], - y1 = _result$blockBounds[3]; - - callback({ - width: x1 - x0, - height: y1 - y0 - }); - }, { metricsOnly: true }); - } - - function parsePercent(str) { - var match = str.match(/^([\d.]+)%$/); - var pct = match ? parseFloat(match[1]) : NaN; - return isNaN(pct) ? 0 : pct / 100; - } - - function now() { - return (self.performance || Date).now(); - } - - // Array-backed structure for a single line's glyphs data - function TextLine() { - this.data = []; - } - TextLine.prototype = { - width: 0, - isSoftWrapped: false, - get count() { - return Math.ceil(this.data.length / 4); - }, - glyphAt: function glyphAt(i) { - var fly = TextLine.flyweight; - fly.data = this.data; - fly.index = i; - return fly; - }, - splitAt: function splitAt(i) { - var newLine = new TextLine(); - newLine.data = this.data.splice(i * 4); - return newLine; - } - }; - TextLine.flyweight = ['glyphObj', 'x', 'width', 'charIndex'].reduce(function (obj, prop, i, all) { - Object.defineProperty(obj, prop, { - get: function get() { - return this.data[this.index * 4 + i]; - }, - set: function set(val) { - this.data[this.index * 4 + i] = val; - } - }); - return obj; - }, { data: null, index: 0 }); - - return { - process: process, - measure: measure, - loadFont: loadFont - }; - } - - /** - * Index for performing fast spatial searches of a glyph's line segments. - * @return {{addLineSegment:function, findNearestSignedDistance:function}} - */ - function createGlyphSegmentsIndex() { - var needsSort = false; - var segments = []; - - function sortSegments() { - if (needsSort) { - // sort by maxX, this will let us short-circuit some loops below - segments.sort(function (a, b) { - return a.maxX - b.maxX; - }); - needsSort = false; - } - } - - /** - * Add a line segment to the index. - * @param x0 - * @param y0 - * @param x1 - * @param y1 - */ - function addLineSegment(x0, y0, x1, y1) { - var segment = { - x0: x0, y0: y0, x1: x1, y1: y1, - minX: Math.min(x0, x1), - minY: Math.min(y0, y1), - maxX: Math.max(x0, x1), - maxY: Math.max(y0, y1) - }; - segments.push(segment); - needsSort = true; - } - - /** - * For a given x/y, search the index for the closest line segment and return - * its signed distance. Negative = inside, positive = outside, zero = on edge - * @param x - * @param y - * @returns {number} - */ - function findNearestSignedDistance(x, y) { - sortSegments(); - var closestDistSq = Infinity; - var closestDist = Infinity; - - for (var i = segments.length; i--;) { - var seg = segments[i]; - if (seg.maxX + closestDist <= x) break; //sorting by maxX means no more can be closer, so we can short-circuit - if (x + closestDist > seg.minX && y - closestDist < seg.maxY && y + closestDist > seg.minY) { - var distSq = absSquareDistanceToLineSegment(x, y, seg.x0, seg.y0, seg.x1, seg.y1); - if (distSq < closestDistSq) { - closestDistSq = distSq; - closestDist = Math.sqrt(closestDistSq); - } - } - } - - // Flip to negative distance if inside the poly - if (isPointInPoly(x, y)) { - closestDist = -closestDist; - } - return closestDist; - } - - // Determine whether the given point lies inside or outside the glyph. Uses a simple - // ray casting algorithm using a ray pointing east from the point. - function isPointInPoly(x, y) { - sortSegments(); - var inside = false; - for (var i = segments.length; i--;) { - var seg = segments[i]; - if (seg.maxX <= x) break; //sorting by maxX means no more can cross, so we can short-circuit - if (seg.minY < y && seg.maxY > y) { - var intersects = seg.y0 > y !== seg.y1 > y && x < (seg.x1 - seg.x0) * (y - seg.y0) / (seg.y1 - seg.y0) + seg.x0; - if (intersects) { - inside = !inside; - } - } - } - return inside; - } - - // Find the absolute distance from a point to a line segment at closest approach - function absSquareDistanceToLineSegment(x, y, lineX0, lineY0, lineX1, lineY1) { - var ldx = lineX1 - lineX0; - var ldy = lineY1 - lineY0; - var lengthSq = ldx * ldx + ldy * ldy; - var t = lengthSq ? Math.max(0, Math.min(1, ((x - lineX0) * ldx + (y - lineY0) * ldy) / lengthSq)) : 0; - var dx = x - (lineX0 + t * ldx); - var dy = y - (lineY0 + t * ldy); - return dx * dx + dy * dy; - } - - return { - addLineSegment: addLineSegment, - findNearestSignedDistance: findNearestSignedDistance - }; - } - - // Custom bundle of Typr.js (https://github.com/photopea/Typr.js) for use in troika-3d-text. - // Original MIT license applies: https://github.com/photopea/Typr.js/blob/gh-pages/LICENSE - - function typrFactory() { - - var window = self; - - // Begin Typr.js - - - var Typr = {}; - - Typr.parse = function (buff) { - var bin = Typr._bin; - var data = new Uint8Array(buff); - - var tag = bin.readASCII(data, 0, 4); - if (tag == "ttcf") { - var offset = 4; - var majV = bin.readUshort(data, offset);offset += 2; - var minV = bin.readUshort(data, offset);offset += 2; - var numF = bin.readUint(data, offset);offset += 4; - var fnts = []; - for (var i = 0; i < numF; i++) { - var foff = bin.readUint(data, offset);offset += 4; - fnts.push(Typr._readFont(data, foff)); - } - return fnts; - } else return [Typr._readFont(data, 0)]; - }; - - Typr._readFont = function (data, offset) { - var bin = Typr._bin; - var ooff = offset; - - var sfnt_version = bin.readFixed(data, offset); - offset += 4; - var numTables = bin.readUshort(data, offset); - offset += 2; - var searchRange = bin.readUshort(data, offset); - offset += 2; - var entrySelector = bin.readUshort(data, offset); - offset += 2; - var rangeShift = bin.readUshort(data, offset); - offset += 2; - - var tags = ["cmap", "head", "hhea", "maxp", "hmtx", "name", "OS/2", "post", - - //"cvt", - //"fpgm", - "loca", "glyf", "kern", - - //"prep" - //"gasp" - - "CFF ", "GPOS", "GSUB", "SVG " - //"VORG", - ]; - - var obj = { _data: data, _offset: ooff }; - //console.log(sfnt_version, numTables, searchRange, entrySelector, rangeShift); - - var tabs = {}; - - for (var i = 0; i < numTables; i++) { - var tag = bin.readASCII(data, offset, 4);offset += 4; - var checkSum = bin.readUint(data, offset);offset += 4; - var toffset = bin.readUint(data, offset);offset += 4; - var length = bin.readUint(data, offset);offset += 4; - tabs[tag] = { offset: toffset, length: length }; - - //if(tags.indexOf(tag)==-1) console.log("unknown tag", tag, length); - } - - for (var i = 0; i < tags.length; i++) { - var t = tags[i]; - //console.log(t); - //if(tabs[t]) console.log(t, tabs[t].offset, tabs[t].length); - if (tabs[t]) obj[t.trim()] = Typr[t.trim()].parse(data, tabs[t].offset, tabs[t].length, obj); - } - - return obj; - }; - - Typr._tabOffset = function (data, tab, foff) { - var bin = Typr._bin; - var numTables = bin.readUshort(data, foff + 4); - var offset = foff + 12; - for (var i = 0; i < numTables; i++) { - var tag = bin.readASCII(data, offset, 4);offset += 4; - var checkSum = bin.readUint(data, offset);offset += 4; - var toffset = bin.readUint(data, offset);offset += 4; - var length = bin.readUint(data, offset);offset += 4; - if (tag == tab) return toffset; - } - return 0; - }; - - Typr._bin = { - readFixed: function readFixed(data, o) { - return (data[o] << 8 | data[o + 1]) + (data[o + 2] << 8 | data[o + 3]) / (256 * 256 + 4); - }, - readF2dot14: function readF2dot14(data, o) { - var num = Typr._bin.readShort(data, o); - return num / 16384; - }, - readInt: function readInt(buff, p) { - //if(p>=buff.length) throw "error"; - var a = Typr._bin.t.uint8; - a[0] = buff[p + 3]; - a[1] = buff[p + 2]; - a[2] = buff[p + 1]; - a[3] = buff[p]; - return Typr._bin.t.int32[0]; - }, - - readInt8: function readInt8(buff, p) { - //if(p>=buff.length) throw "error"; - var a = Typr._bin.t.uint8; - a[0] = buff[p]; - return Typr._bin.t.int8[0]; - }, - readShort: function readShort(buff, p) { - //if(p>=buff.length) throw "error"; - var a = Typr._bin.t.uint8; - a[1] = buff[p];a[0] = buff[p + 1]; - return Typr._bin.t.int16[0]; - }, - readUshort: function readUshort(buff, p) { - //if(p>=buff.length) throw "error"; - return buff[p] << 8 | buff[p + 1]; - }, - readUshorts: function readUshorts(buff, p, len) { - var arr = []; - for (var i = 0; i < len; i++) { - arr.push(Typr._bin.readUshort(buff, p + i * 2)); - }return arr; - }, - readUint: function readUint(buff, p) { - //if(p>=buff.length) throw "error"; - var a = Typr._bin.t.uint8; - a[3] = buff[p];a[2] = buff[p + 1];a[1] = buff[p + 2];a[0] = buff[p + 3]; - return Typr._bin.t.uint32[0]; - }, - readUint64: function readUint64(buff, p) { - //if(p>=buff.length) throw "error"; - return Typr._bin.readUint(buff, p) * (0xffffffff + 1) + Typr._bin.readUint(buff, p + 4); - }, - readASCII: function readASCII(buff, p, l) // l : length in Characters (not Bytes) - { - //if(p>=buff.length) throw "error"; - var s = ""; - for (var i = 0; i < l; i++) { - s += String.fromCharCode(buff[p + i]); - }return s; - }, - readUnicode: function readUnicode(buff, p, l) { - //if(p>=buff.length) throw "error"; - var s = ""; - for (var i = 0; i < l; i++) { - var c = buff[p++] << 8 | buff[p++]; - s += String.fromCharCode(c); - } - return s; - }, - _tdec: window["TextDecoder"] ? new window["TextDecoder"]() : null, - readUTF8: function readUTF8(buff, p, l) { - var tdec = Typr._bin._tdec; - if (tdec && p == 0 && l == buff.length) return tdec["decode"](buff); - return Typr._bin.readASCII(buff, p, l); - }, - readBytes: function readBytes(buff, p, l) { - //if(p>=buff.length) throw "error"; - var arr = []; - for (var i = 0; i < l; i++) { - arr.push(buff[p + i]); - }return arr; - }, - readASCIIArray: function readASCIIArray(buff, p, l) // l : length in Characters (not Bytes) - { - //if(p>=buff.length) throw "error"; - var s = []; - for (var i = 0; i < l; i++) { - s.push(String.fromCharCode(buff[p + i])); - }return s; - } - }; - - Typr._bin.t = { - buff: new ArrayBuffer(8) - }; - Typr._bin.t.int8 = new Int8Array(Typr._bin.t.buff); - Typr._bin.t.uint8 = new Uint8Array(Typr._bin.t.buff); - Typr._bin.t.int16 = new Int16Array(Typr._bin.t.buff); - Typr._bin.t.uint16 = new Uint16Array(Typr._bin.t.buff); - Typr._bin.t.int32 = new Int32Array(Typr._bin.t.buff); - Typr._bin.t.uint32 = new Uint32Array(Typr._bin.t.buff); - - // OpenType Layout Common Table Formats - - Typr._lctf = {}; - - Typr._lctf.parse = function (data, offset, length, font, subt) { - var bin = Typr._bin; - var obj = {}; - var offset0 = offset; - var tableVersion = bin.readFixed(data, offset);offset += 4; - - var offScriptList = bin.readUshort(data, offset);offset += 2; - var offFeatureList = bin.readUshort(data, offset);offset += 2; - var offLookupList = bin.readUshort(data, offset);offset += 2; - - obj.scriptList = Typr._lctf.readScriptList(data, offset0 + offScriptList); - obj.featureList = Typr._lctf.readFeatureList(data, offset0 + offFeatureList); - obj.lookupList = Typr._lctf.readLookupList(data, offset0 + offLookupList, subt); - - return obj; - }; - - Typr._lctf.readLookupList = function (data, offset, subt) { - var bin = Typr._bin; - var offset0 = offset; - var obj = []; - var count = bin.readUshort(data, offset);offset += 2; - for (var i = 0; i < count; i++) { - var noff = bin.readUshort(data, offset);offset += 2; - var lut = Typr._lctf.readLookupTable(data, offset0 + noff, subt); - obj.push(lut); - } - return obj; - }; - - Typr._lctf.readLookupTable = function (data, offset, subt) { - //console.log("Parsing lookup table", offset); - var bin = Typr._bin; - var offset0 = offset; - var obj = { tabs: [] }; - - obj.ltype = bin.readUshort(data, offset);offset += 2; - obj.flag = bin.readUshort(data, offset);offset += 2; - var cnt = bin.readUshort(data, offset);offset += 2; - - for (var i = 0; i < cnt; i++) { - var noff = bin.readUshort(data, offset);offset += 2; - var tab = subt(data, obj.ltype, offset0 + noff); - //console.log(obj.type, tab); - obj.tabs.push(tab); - } - return obj; - }; - - Typr._lctf.numOfOnes = function (n) { - var num = 0; - for (var i = 0; i < 32; i++) { - if ((n >>> i & 1) != 0) num++; - }return num; - }; - - Typr._lctf.readClassDef = function (data, offset) { - var bin = Typr._bin; - var obj = []; - var format = bin.readUshort(data, offset);offset += 2; - if (format == 1) { - var startGlyph = bin.readUshort(data, offset);offset += 2; - var glyphCount = bin.readUshort(data, offset);offset += 2; - for (var i = 0; i < glyphCount; i++) { - obj.push(startGlyph + i); - obj.push(startGlyph + i); - obj.push(bin.readUshort(data, offset));offset += 2; - } - } - if (format == 2) { - var count = bin.readUshort(data, offset);offset += 2; - for (var i = 0; i < count; i++) { - obj.push(bin.readUshort(data, offset));offset += 2; - obj.push(bin.readUshort(data, offset));offset += 2; - obj.push(bin.readUshort(data, offset));offset += 2; - } - } - return obj; - }; - Typr._lctf.getInterval = function (tab, val) { - for (var i = 0; i < tab.length; i += 3) { - var start = tab[i], - end = tab[i + 1], - index = tab[i + 2]; - if (start <= val && val <= end) return i; - } - return -1; - }; - - Typr._lctf.readCoverage = function (data, offset) { - var bin = Typr._bin; - var cvg = {}; - cvg.fmt = bin.readUshort(data, offset);offset += 2; - var count = bin.readUshort(data, offset);offset += 2; - //console.log("parsing coverage", offset-4, format, count); - if (cvg.fmt == 1) cvg.tab = bin.readUshorts(data, offset, count); - if (cvg.fmt == 2) cvg.tab = bin.readUshorts(data, offset, count * 3); - return cvg; - }; - - Typr._lctf.coverageIndex = function (cvg, val) { - var tab = cvg.tab; - if (cvg.fmt == 1) return tab.indexOf(val); - if (cvg.fmt == 2) { - var ind = Typr._lctf.getInterval(tab, val); - if (ind != -1) return tab[ind + 2] + (val - tab[ind]); - } - return -1; - }; - - Typr._lctf.readFeatureList = function (data, offset) { - var bin = Typr._bin; - var offset0 = offset; - var obj = []; - - var count = bin.readUshort(data, offset);offset += 2; - - for (var i = 0; i < count; i++) { - var tag = bin.readASCII(data, offset, 4);offset += 4; - var noff = bin.readUshort(data, offset);offset += 2; - obj.push({ tag: tag.trim(), tab: Typr._lctf.readFeatureTable(data, offset0 + noff) }); - } - return obj; - }; - - Typr._lctf.readFeatureTable = function (data, offset) { - var bin = Typr._bin; - - var featureParams = bin.readUshort(data, offset);offset += 2; // = 0 - var lookupCount = bin.readUshort(data, offset);offset += 2; - - var indices = []; - for (var i = 0; i < lookupCount; i++) { - indices.push(bin.readUshort(data, offset + 2 * i)); - }return indices; - }; - - Typr._lctf.readScriptList = function (data, offset) { - var bin = Typr._bin; - var offset0 = offset; - var obj = {}; - - var count = bin.readUshort(data, offset);offset += 2; - - for (var i = 0; i < count; i++) { - var tag = bin.readASCII(data, offset, 4);offset += 4; - var noff = bin.readUshort(data, offset);offset += 2; - obj[tag.trim()] = Typr._lctf.readScriptTable(data, offset0 + noff); - } - return obj; - }; - - Typr._lctf.readScriptTable = function (data, offset) { - var bin = Typr._bin; - var offset0 = offset; - var obj = {}; - - var defLangSysOff = bin.readUshort(data, offset);offset += 2; - obj.default = Typr._lctf.readLangSysTable(data, offset0 + defLangSysOff); - - var langSysCount = bin.readUshort(data, offset);offset += 2; - - for (var i = 0; i < langSysCount; i++) { - var tag = bin.readASCII(data, offset, 4);offset += 4; - var langSysOff = bin.readUshort(data, offset);offset += 2; - obj[tag.trim()] = Typr._lctf.readLangSysTable(data, offset0 + langSysOff); - } - return obj; - }; - - Typr._lctf.readLangSysTable = function (data, offset) { - var bin = Typr._bin; - var obj = {}; - - var lookupOrder = bin.readUshort(data, offset);offset += 2; - //if(lookupOrder!=0) throw "lookupOrder not 0"; - obj.reqFeature = bin.readUshort(data, offset);offset += 2; - //if(obj.reqFeature != 0xffff) throw "reqFeatureIndex != 0xffff"; - - //console.log(lookupOrder, obj.reqFeature); - - var featureCount = bin.readUshort(data, offset);offset += 2; - obj.features = bin.readUshorts(data, offset, featureCount); - return obj; - }; - - Typr.CFF = {}; - Typr.CFF.parse = function (data, offset, length) { - var bin = Typr._bin; - - data = new Uint8Array(data.buffer, offset, length); - offset = 0; - - // Header - var major = data[offset];offset++; - var minor = data[offset];offset++; - var hdrSize = data[offset];offset++; - var offsize = data[offset];offset++; - //console.log(major, minor, hdrSize, offsize); - - // Name INDEX - var ninds = []; - offset = Typr.CFF.readIndex(data, offset, ninds); - var names = []; - - for (var i = 0; i < ninds.length - 1; i++) { - names.push(bin.readASCII(data, offset + ninds[i], ninds[i + 1] - ninds[i])); - }offset += ninds[ninds.length - 1]; - - // Top DICT INDEX - var tdinds = []; - offset = Typr.CFF.readIndex(data, offset, tdinds); //console.log(tdinds); - // Top DICT Data - var topDicts = []; - for (var i = 0; i < tdinds.length - 1; i++) { - topDicts.push(Typr.CFF.readDict(data, offset + tdinds[i], offset + tdinds[i + 1])); - }offset += tdinds[tdinds.length - 1]; - var topdict = topDicts[0]; - //console.log(topdict); - - // String INDEX - var sinds = []; - offset = Typr.CFF.readIndex(data, offset, sinds); - // String Data - var strings = []; - for (var i = 0; i < sinds.length - 1; i++) { - strings.push(bin.readASCII(data, offset + sinds[i], sinds[i + 1] - sinds[i])); - }offset += sinds[sinds.length - 1]; - - // Global Subr INDEX (subroutines) - Typr.CFF.readSubrs(data, offset, topdict); - - // charstrings - if (topdict.CharStrings) { - offset = topdict.CharStrings; - var sinds = []; - offset = Typr.CFF.readIndex(data, offset, sinds); - - var cstr = []; - for (var i = 0; i < sinds.length - 1; i++) { - cstr.push(bin.readBytes(data, offset + sinds[i], sinds[i + 1] - sinds[i])); - } //offset += sinds[sinds.length-1]; - topdict.CharStrings = cstr; - //console.log(topdict.CharStrings); - } - - // CID font - if (topdict.ROS) { - offset = topdict.FDArray; - var fdind = []; - offset = Typr.CFF.readIndex(data, offset, fdind); - - topdict.FDArray = []; - for (var i = 0; i < fdind.length - 1; i++) { - var dict = Typr.CFF.readDict(data, offset + fdind[i], offset + fdind[i + 1]); - Typr.CFF._readFDict(data, dict, strings); - topdict.FDArray.push(dict); - } - offset += fdind[fdind.length - 1]; - - offset = topdict.FDSelect; - topdict.FDSelect = []; - var fmt = data[offset];offset++; - if (fmt == 3) { - var rns = bin.readUshort(data, offset);offset += 2; - for (var i = 0; i < rns + 1; i++) { - topdict.FDSelect.push(bin.readUshort(data, offset), data[offset + 2]);offset += 3; - } - } else throw fmt; - } - - // Encoding - if (topdict.Encoding) topdict.Encoding = Typr.CFF.readEncoding(data, topdict.Encoding, topdict.CharStrings.length); - - // charset - if (topdict.charset) topdict.charset = Typr.CFF.readCharset(data, topdict.charset, topdict.CharStrings.length); - - Typr.CFF._readFDict(data, topdict, strings); - return topdict; - }; - Typr.CFF._readFDict = function (data, dict, ss) { - var offset; - if (dict.Private) { - offset = dict.Private[1]; - dict.Private = Typr.CFF.readDict(data, offset, offset + dict.Private[0]); - if (dict.Private.Subrs) Typr.CFF.readSubrs(data, offset + dict.Private.Subrs, dict.Private); - } - for (var p in dict) { - if (["FamilyName", "FontName", "FullName", "Notice", "version", "Copyright"].indexOf(p) != -1) dict[p] = ss[dict[p] - 426 + 35]; - } - }; - - Typr.CFF.readSubrs = function (data, offset, obj) { - var bin = Typr._bin; - var gsubinds = []; - offset = Typr.CFF.readIndex(data, offset, gsubinds); - - var bias, - nSubrs = gsubinds.length; - if (nSubrs < 1240) bias = 107;else if (nSubrs < 33900) bias = 1131;else bias = 32768; - obj.Bias = bias; - - obj.Subrs = []; - for (var i = 0; i < gsubinds.length - 1; i++) { - obj.Subrs.push(bin.readBytes(data, offset + gsubinds[i], gsubinds[i + 1] - gsubinds[i])); - } //offset += gsubinds[gsubinds.length-1]; - }; - - Typr.CFF.tableSE = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 0, 111, 112, 113, 114, 0, 115, 116, 117, 118, 119, 120, 121, 122, 0, 123, 0, 124, 125, 126, 127, 128, 129, 130, 131, 0, 132, 133, 0, 134, 135, 136, 137, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 138, 0, 139, 0, 0, 0, 0, 140, 141, 142, 143, 0, 0, 0, 0, 0, 144, 0, 0, 0, 145, 0, 0, 146, 147, 148, 149, 0, 0, 0, 0]; - - Typr.CFF.glyphByUnicode = function (cff, code) { - for (var i = 0; i < cff.charset.length; i++) { - if (cff.charset[i] == code) return i; - }return -1; - }; - - Typr.CFF.glyphBySE = function (cff, charcode) // glyph by standard encoding - { - if (charcode < 0 || charcode > 255) return -1; - return Typr.CFF.glyphByUnicode(cff, Typr.CFF.tableSE[charcode]); - }; - - Typr.CFF.readEncoding = function (data, offset, num) { - var bin = Typr._bin; - - var array = ['.notdef']; - var format = data[offset];offset++; - //console.log("Encoding"); - //console.log(format); - - if (format == 0) { - var nCodes = data[offset];offset++; - for (var i = 0; i < nCodes; i++) { - array.push(data[offset + i]); - } - } - /* - else if(format==1 || format==2) - { - while(charset.length> 4, - nib1 = b & 0xf; - if (nib0 != 0xf) nibs.push(nib0);if (nib1 != 0xf) nibs.push(nib1); - if (nib1 == 0xf) break; - } - var s = ""; - var chars = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, ".", "e", "e-", "reserved", "-", "endOfNumber"]; - for (var i = 0; i < nibs.length; i++) { - s += chars[nibs[i]]; - } //console.log(nibs); - val = parseFloat(s); - } - - if (b0 <= 21) // operator - { - var keys = ["version", "Notice", "FullName", "FamilyName", "Weight", "FontBBox", "BlueValues", "OtherBlues", "FamilyBlues", "FamilyOtherBlues", "StdHW", "StdVW", "escape", "UniqueID", "XUID", "charset", "Encoding", "CharStrings", "Private", "Subrs", "defaultWidthX", "nominalWidthX"]; - - key = keys[b0];vs = 1; - if (b0 == 12) { - var keys = ["Copyright", "isFixedPitch", "ItalicAngle", "UnderlinePosition", "UnderlineThickness", "PaintType", "CharstringType", "FontMatrix", "StrokeWidth", "BlueScale", "BlueShift", "BlueFuzz", "StemSnapH", "StemSnapV", "ForceBold", 0, 0, "LanguageGroup", "ExpansionFactor", "initialRandomSeed", "SyntheticBase", "PostScript", "BaseFontName", "BaseFontBlend", 0, 0, 0, 0, 0, 0, "ROS", "CIDFontVersion", "CIDFontRevision", "CIDFontType", "CIDCount", "UIDBase", "FDArray", "FDSelect", "FontName"]; - key = keys[b1];vs = 2; - } - } - - if (key != null) { - dict[key] = carr.length == 1 ? carr[0] : carr;carr = []; - } else carr.push(val); - - offset += vs; - } - return dict; - }; - - Typr.cmap = {}; - Typr.cmap.parse = function (data, offset, length) { - data = new Uint8Array(data.buffer, offset, length); - offset = 0; - var bin = Typr._bin; - var obj = {}; - var version = bin.readUshort(data, offset);offset += 2; - var numTables = bin.readUshort(data, offset);offset += 2; - - //console.log(version, numTables); - - var offs = []; - obj.tables = []; - - for (var i = 0; i < numTables; i++) { - var platformID = bin.readUshort(data, offset);offset += 2; - var encodingID = bin.readUshort(data, offset);offset += 2; - var noffset = bin.readUint(data, offset);offset += 4; - - var id = "p" + platformID + "e" + encodingID; - - //console.log("cmap subtable", platformID, encodingID, noffset); - - - var tind = offs.indexOf(noffset); - - if (tind == -1) { - tind = obj.tables.length; - var subt; - offs.push(noffset); - var format = bin.readUshort(data, noffset); - if (format == 0) subt = Typr.cmap.parse0(data, noffset);else if (format == 4) subt = Typr.cmap.parse4(data, noffset);else if (format == 6) subt = Typr.cmap.parse6(data, noffset);else if (format == 12) subt = Typr.cmap.parse12(data, noffset);else console.log("unknown format: " + format, platformID, encodingID, noffset); - obj.tables.push(subt); - } - - if (obj[id] != null) throw "multiple tables for one platform+encoding"; - obj[id] = tind; - } - return obj; - }; - - Typr.cmap.parse0 = function (data, offset) { - var bin = Typr._bin; - var obj = {}; - obj.format = bin.readUshort(data, offset);offset += 2; - var len = bin.readUshort(data, offset);offset += 2; - var lang = bin.readUshort(data, offset);offset += 2; - obj.map = []; - for (var i = 0; i < len - 6; i++) { - obj.map.push(data[offset + i]); - }return obj; - }; - - Typr.cmap.parse4 = function (data, offset) { - var bin = Typr._bin; - var offset0 = offset; - var obj = {}; - - obj.format = bin.readUshort(data, offset);offset += 2; - var length = bin.readUshort(data, offset);offset += 2; - var language = bin.readUshort(data, offset);offset += 2; - var segCountX2 = bin.readUshort(data, offset);offset += 2; - var segCount = segCountX2 / 2; - obj.searchRange = bin.readUshort(data, offset);offset += 2; - obj.entrySelector = bin.readUshort(data, offset);offset += 2; - obj.rangeShift = bin.readUshort(data, offset);offset += 2; - obj.endCount = bin.readUshorts(data, offset, segCount);offset += segCount * 2; - offset += 2; - obj.startCount = bin.readUshorts(data, offset, segCount);offset += segCount * 2; - obj.idDelta = []; - for (var i = 0; i < segCount; i++) { - obj.idDelta.push(bin.readShort(data, offset));offset += 2; - } - obj.idRangeOffset = bin.readUshorts(data, offset, segCount);offset += segCount * 2; - obj.glyphIdArray = []; - while (offset < offset0 + length) { - obj.glyphIdArray.push(bin.readUshort(data, offset));offset += 2; - } - return obj; - }; - - Typr.cmap.parse6 = function (data, offset) { - var bin = Typr._bin; - var obj = {}; - - obj.format = bin.readUshort(data, offset);offset += 2; - var length = bin.readUshort(data, offset);offset += 2; - var language = bin.readUshort(data, offset);offset += 2; - obj.firstCode = bin.readUshort(data, offset);offset += 2; - var entryCount = bin.readUshort(data, offset);offset += 2; - obj.glyphIdArray = []; - for (var i = 0; i < entryCount; i++) { - obj.glyphIdArray.push(bin.readUshort(data, offset));offset += 2; - } - - return obj; - }; - - Typr.cmap.parse12 = function (data, offset) { - var bin = Typr._bin; - var obj = {}; - - obj.format = bin.readUshort(data, offset);offset += 2; - offset += 2; - var length = bin.readUint(data, offset);offset += 4; - var lang = bin.readUint(data, offset);offset += 4; - var nGroups = bin.readUint(data, offset);offset += 4; - obj.groups = []; - - for (var i = 0; i < nGroups; i++) { - var off = offset + i * 12; - var startCharCode = bin.readUint(data, off + 0); - var endCharCode = bin.readUint(data, off + 4); - var startGlyphID = bin.readUint(data, off + 8); - obj.groups.push([startCharCode, endCharCode, startGlyphID]); - } - return obj; - }; - - Typr.glyf = {}; - Typr.glyf.parse = function (data, offset, length, font) { - var obj = []; - for (var g = 0; g < font.maxp.numGlyphs; g++) { - obj.push(null); - }return obj; - }; - - Typr.glyf._parseGlyf = function (font, g) { - var bin = Typr._bin; - var data = font._data; - - var offset = Typr._tabOffset(data, "glyf", font._offset) + font.loca[g]; - - if (font.loca[g] == font.loca[g + 1]) return null; - - var gl = {}; - - gl.noc = bin.readShort(data, offset);offset += 2; // number of contours - gl.xMin = bin.readShort(data, offset);offset += 2; - gl.yMin = bin.readShort(data, offset);offset += 2; - gl.xMax = bin.readShort(data, offset);offset += 2; - gl.yMax = bin.readShort(data, offset);offset += 2; - - if (gl.xMin >= gl.xMax || gl.yMin >= gl.yMax) return null; - - if (gl.noc > 0) { - gl.endPts = []; - for (var i = 0; i < gl.noc; i++) { - gl.endPts.push(bin.readUshort(data, offset));offset += 2; - } - - var instructionLength = bin.readUshort(data, offset);offset += 2; - if (data.length - offset < instructionLength) return null; - gl.instructions = bin.readBytes(data, offset, instructionLength);offset += instructionLength; - - var crdnum = gl.endPts[gl.noc - 1] + 1; - gl.flags = []; - for (var i = 0; i < crdnum; i++) { - var flag = data[offset];offset++; - gl.flags.push(flag); - if ((flag & 8) != 0) { - var rep = data[offset];offset++; - for (var j = 0; j < rep; j++) { - gl.flags.push(flag);i++; - } - } - } - gl.xs = []; - for (var i = 0; i < crdnum; i++) { - var i8 = (gl.flags[i] & 2) != 0, - same = (gl.flags[i] & 16) != 0; - if (i8) { - gl.xs.push(same ? data[offset] : -data[offset]);offset++; - } else { - if (same) gl.xs.push(0);else { - gl.xs.push(bin.readShort(data, offset));offset += 2; - } - } - } - gl.ys = []; - for (var i = 0; i < crdnum; i++) { - var i8 = (gl.flags[i] & 4) != 0, - same = (gl.flags[i] & 32) != 0; - if (i8) { - gl.ys.push(same ? data[offset] : -data[offset]);offset++; - } else { - if (same) gl.ys.push(0);else { - gl.ys.push(bin.readShort(data, offset));offset += 2; - } - } - } - var x = 0, - y = 0; - for (var i = 0; i < crdnum; i++) { - x += gl.xs[i];y += gl.ys[i];gl.xs[i] = x;gl.ys[i] = y; - } - //console.log(endPtsOfContours, instructionLength, instructions, flags, xCoordinates, yCoordinates); - } else { - var ARG_1_AND_2_ARE_WORDS = 1 << 0; - var ARGS_ARE_XY_VALUES = 1 << 1; - var WE_HAVE_A_SCALE = 1 << 3; - var MORE_COMPONENTS = 1 << 5; - var WE_HAVE_AN_X_AND_Y_SCALE = 1 << 6; - var WE_HAVE_A_TWO_BY_TWO = 1 << 7; - var WE_HAVE_INSTRUCTIONS = 1 << 8; - - gl.parts = []; - var flags; - do { - flags = bin.readUshort(data, offset);offset += 2; - var part = { m: { a: 1, b: 0, c: 0, d: 1, tx: 0, ty: 0 }, p1: -1, p2: -1 };gl.parts.push(part); - part.glyphIndex = bin.readUshort(data, offset);offset += 2; - if (flags & ARG_1_AND_2_ARE_WORDS) { - var arg1 = bin.readShort(data, offset);offset += 2; - var arg2 = bin.readShort(data, offset);offset += 2; - } else { - var arg1 = bin.readInt8(data, offset);offset++; - var arg2 = bin.readInt8(data, offset);offset++; - } - - if (flags & ARGS_ARE_XY_VALUES) { - part.m.tx = arg1;part.m.ty = arg2; - } else { - part.p1 = arg1;part.p2 = arg2; - } - //part.m.tx = arg1; part.m.ty = arg2; - //else { throw "params are not XY values"; } - - if (flags & WE_HAVE_A_SCALE) { - part.m.a = part.m.d = bin.readF2dot14(data, offset);offset += 2; - } else if (flags & WE_HAVE_AN_X_AND_Y_SCALE) { - part.m.a = bin.readF2dot14(data, offset);offset += 2; - part.m.d = bin.readF2dot14(data, offset);offset += 2; - } else if (flags & WE_HAVE_A_TWO_BY_TWO) { - part.m.a = bin.readF2dot14(data, offset);offset += 2; - part.m.b = bin.readF2dot14(data, offset);offset += 2; - part.m.c = bin.readF2dot14(data, offset);offset += 2; - part.m.d = bin.readF2dot14(data, offset);offset += 2; - } - } while (flags & MORE_COMPONENTS); - if (flags & WE_HAVE_INSTRUCTIONS) { - var numInstr = bin.readUshort(data, offset);offset += 2; - gl.instr = []; - for (var i = 0; i < numInstr; i++) { - gl.instr.push(data[offset]);offset++; - } - } - } - return gl; - }; - - Typr.GPOS = {}; - Typr.GPOS.parse = function (data, offset, length, font) { - return Typr._lctf.parse(data, offset, length, font, Typr.GPOS.subt); - }; - - Typr.GPOS.subt = function (data, ltype, offset) // lookup type - { - var bin = Typr._bin, - offset0 = offset, - tab = {}; - - tab.fmt = bin.readUshort(data, offset);offset += 2; - - //console.log(ltype, tab.fmt); - - if (ltype == 1 || ltype == 2 || ltype == 3 || ltype == 7 || ltype == 8 && tab.fmt <= 2) { - var covOff = bin.readUshort(data, offset);offset += 2; - tab.coverage = Typr._lctf.readCoverage(data, covOff + offset0); - } - if (ltype == 1 && tab.fmt == 1) { - var valFmt1 = bin.readUshort(data, offset);offset += 2; - var ones1 = Typr._lctf.numOfOnes(valFmt1); - if (valFmt1 != 0) tab.pos = Typr.GPOS.readValueRecord(data, offset, valFmt1); - } else if (ltype == 2) { - var valFmt1 = bin.readUshort(data, offset);offset += 2; - var valFmt2 = bin.readUshort(data, offset);offset += 2; - var ones1 = Typr._lctf.numOfOnes(valFmt1); - var ones2 = Typr._lctf.numOfOnes(valFmt2); - if (tab.fmt == 1) { - tab.pairsets = []; - var psc = bin.readUshort(data, offset);offset += 2; // PairSetCount - - for (var i = 0; i < psc; i++) { - var psoff = offset0 + bin.readUshort(data, offset);offset += 2; - - var pvc = bin.readUshort(data, psoff);psoff += 2; - var arr = []; - for (var j = 0; j < pvc; j++) { - var gid2 = bin.readUshort(data, psoff);psoff += 2; - var value1, value2; - if (valFmt1 != 0) { - value1 = Typr.GPOS.readValueRecord(data, psoff, valFmt1);psoff += ones1 * 2; - } - if (valFmt2 != 0) { - value2 = Typr.GPOS.readValueRecord(data, psoff, valFmt2);psoff += ones2 * 2; - } - //if(value1!=null) throw "e"; - arr.push({ gid2: gid2, val1: value1, val2: value2 }); - } - tab.pairsets.push(arr); - } - } - if (tab.fmt == 2) { - var classDef1 = bin.readUshort(data, offset);offset += 2; - var classDef2 = bin.readUshort(data, offset);offset += 2; - var class1Count = bin.readUshort(data, offset);offset += 2; - var class2Count = bin.readUshort(data, offset);offset += 2; - - tab.classDef1 = Typr._lctf.readClassDef(data, offset0 + classDef1); - tab.classDef2 = Typr._lctf.readClassDef(data, offset0 + classDef2); - - tab.matrix = []; - for (var i = 0; i < class1Count; i++) { - var row = []; - for (var j = 0; j < class2Count; j++) { - var value1 = null, - value2 = null; - if (tab.valFmt1 != 0) { - value1 = Typr.GPOS.readValueRecord(data, offset, tab.valFmt1);offset += ones1 * 2; - } - if (tab.valFmt2 != 0) { - value2 = Typr.GPOS.readValueRecord(data, offset, tab.valFmt2);offset += ones2 * 2; - } - row.push({ val1: value1, val2: value2 }); - } - tab.matrix.push(row); - } - } - } - return tab; - }; - - Typr.GPOS.readValueRecord = function (data, offset, valFmt) { - var bin = Typr._bin; - var arr = []; - arr.push(valFmt & 1 ? bin.readShort(data, offset) : 0);offset += valFmt & 1 ? 2 : 0; // X_PLACEMENT - arr.push(valFmt & 2 ? bin.readShort(data, offset) : 0);offset += valFmt & 2 ? 2 : 0; // Y_PLACEMENT - arr.push(valFmt & 4 ? bin.readShort(data, offset) : 0);offset += valFmt & 4 ? 2 : 0; // X_ADVANCE - arr.push(valFmt & 8 ? bin.readShort(data, offset) : 0);offset += valFmt & 8 ? 2 : 0; // Y_ADVANCE - return arr; - }; - - Typr.GSUB = {}; - Typr.GSUB.parse = function (data, offset, length, font) { - return Typr._lctf.parse(data, offset, length, font, Typr.GSUB.subt); - }; - - Typr.GSUB.subt = function (data, ltype, offset) // lookup type - { - var bin = Typr._bin, - offset0 = offset, - tab = {}; - - tab.fmt = bin.readUshort(data, offset);offset += 2; - - if (ltype != 1 && ltype != 4 && ltype != 5 && ltype != 6) return null; - - if (ltype == 1 || ltype == 4 || ltype == 5 && tab.fmt <= 2 || ltype == 6 && tab.fmt <= 2) { - var covOff = bin.readUshort(data, offset);offset += 2; - tab.coverage = Typr._lctf.readCoverage(data, offset0 + covOff); // not always is coverage here - } - - if (ltype == 1) { - if (tab.fmt == 1) { - tab.delta = bin.readShort(data, offset);offset += 2; - } else if (tab.fmt == 2) { - var cnt = bin.readUshort(data, offset);offset += 2; - tab.newg = bin.readUshorts(data, offset, cnt);offset += tab.newg.length * 2; - } - } - // Ligature Substitution Subtable - else if (ltype == 4) { - tab.vals = []; - var cnt = bin.readUshort(data, offset);offset += 2; - for (var i = 0; i < cnt; i++) { - var loff = bin.readUshort(data, offset);offset += 2; - tab.vals.push(Typr.GSUB.readLigatureSet(data, offset0 + loff)); - } - //console.log(tab.coverage); - //console.log(tab.vals); - } - // Contextual Substitution Subtable - else if (ltype == 5) { - if (tab.fmt == 2) { - var cDefOffset = bin.readUshort(data, offset);offset += 2; - tab.cDef = Typr._lctf.readClassDef(data, offset0 + cDefOffset); - tab.scset = []; - var subClassSetCount = bin.readUshort(data, offset);offset += 2; - for (var i = 0; i < subClassSetCount; i++) { - var scsOff = bin.readUshort(data, offset);offset += 2; - tab.scset.push(scsOff == 0 ? null : Typr.GSUB.readSubClassSet(data, offset0 + scsOff)); - } - } - //else console.log("unknown table format", tab.fmt); - } - //* - else if (ltype == 6) { - /* - if(tab.fmt==2) { - var btDef = bin.readUshort(data, offset); offset+=2; - var inDef = bin.readUshort(data, offset); offset+=2; - var laDef = bin.readUshort(data, offset); offset+=2; - - tab.btDef = Typr._lctf.readClassDef(data, offset0 + btDef); - tab.inDef = Typr._lctf.readClassDef(data, offset0 + inDef); - tab.laDef = Typr._lctf.readClassDef(data, offset0 + laDef); - - tab.scset = []; - var cnt = bin.readUshort(data, offset); offset+=2; - for(var i=0; i>> 8; - /* I have seen format 128 once, that's why I do */format &= 0xf; - if (format == 0) offset = Typr.kern.readFormat0(data, offset, map);else throw "unknown kern table format: " + format; - } - return map; - }; - - Typr.kern.parseV1 = function (data, offset, length, font) { - var bin = Typr._bin; - - var version = bin.readFixed(data, offset);offset += 4; - var nTables = bin.readUint(data, offset);offset += 4; - - var map = { glyph1: [], rval: [] }; - for (var i = 0; i < nTables; i++) { - var length = bin.readUint(data, offset);offset += 4; - var coverage = bin.readUshort(data, offset);offset += 2; - var tupleIndex = bin.readUshort(data, offset);offset += 2; - var format = coverage >>> 8; - /* I have seen format 128 once, that's why I do */format &= 0xf; - if (format == 0) offset = Typr.kern.readFormat0(data, offset, map);else throw "unknown kern table format: " + format; - } - return map; - }; - - Typr.kern.readFormat0 = function (data, offset, map) { - var bin = Typr._bin; - var pleft = -1; - var nPairs = bin.readUshort(data, offset);offset += 2; - var searchRange = bin.readUshort(data, offset);offset += 2; - var entrySelector = bin.readUshort(data, offset);offset += 2; - var rangeShift = bin.readUshort(data, offset);offset += 2; - for (var j = 0; j < nPairs; j++) { - var left = bin.readUshort(data, offset);offset += 2; - var right = bin.readUshort(data, offset);offset += 2; - var value = bin.readShort(data, offset);offset += 2; - if (left != pleft) { - map.glyph1.push(left);map.rval.push({ glyph2: [], vals: [] }); - } - var rval = map.rval[map.rval.length - 1]; - rval.glyph2.push(right);rval.vals.push(value); - pleft = left; - } - return offset; - }; - - Typr.loca = {}; - Typr.loca.parse = function (data, offset, length, font) { - var bin = Typr._bin; - var obj = []; - - var ver = font.head.indexToLocFormat; - //console.log("loca", ver, length, 4*font.maxp.numGlyphs); - var len = font.maxp.numGlyphs + 1; - - if (ver == 0) for (var i = 0; i < len; i++) { - obj.push(bin.readUshort(data, offset + (i << 1)) << 1); - }if (ver == 1) for (var i = 0; i < len; i++) { - obj.push(bin.readUint(data, offset + (i << 2))); - }return obj; - }; - - Typr.maxp = {}; - Typr.maxp.parse = function (data, offset, length) { - //console.log(data.length, offset, length); - - var bin = Typr._bin; - var obj = {}; - - // both versions 0.5 and 1.0 - var ver = bin.readUint(data, offset);offset += 4; - obj.numGlyphs = bin.readUshort(data, offset);offset += 2; - - // only 1.0 - if (ver == 0x00010000) { - obj.maxPoints = bin.readUshort(data, offset);offset += 2; - obj.maxContours = bin.readUshort(data, offset);offset += 2; - obj.maxCompositePoints = bin.readUshort(data, offset);offset += 2; - obj.maxCompositeContours = bin.readUshort(data, offset);offset += 2; - obj.maxZones = bin.readUshort(data, offset);offset += 2; - obj.maxTwilightPoints = bin.readUshort(data, offset);offset += 2; - obj.maxStorage = bin.readUshort(data, offset);offset += 2; - obj.maxFunctionDefs = bin.readUshort(data, offset);offset += 2; - obj.maxInstructionDefs = bin.readUshort(data, offset);offset += 2; - obj.maxStackElements = bin.readUshort(data, offset);offset += 2; - obj.maxSizeOfInstructions = bin.readUshort(data, offset);offset += 2; - obj.maxComponentElements = bin.readUshort(data, offset);offset += 2; - obj.maxComponentDepth = bin.readUshort(data, offset);offset += 2; - } - - return obj; - }; - - Typr.name = {}; - Typr.name.parse = function (data, offset, length) { - var bin = Typr._bin; - var obj = {}; - var format = bin.readUshort(data, offset);offset += 2; - var count = bin.readUshort(data, offset);offset += 2; - var stringOffset = bin.readUshort(data, offset);offset += 2; - - //console.log(format,count); - - var names = ["copyright", "fontFamily", "fontSubfamily", "ID", "fullName", "version", "postScriptName", "trademark", "manufacturer", "designer", "description", "urlVendor", "urlDesigner", "licence", "licenceURL", "---", "typoFamilyName", "typoSubfamilyName", "compatibleFull", "sampleText", "postScriptCID", "wwsFamilyName", "wwsSubfamilyName", "lightPalette", "darkPalette"]; - - var offset0 = offset; - - for (var i = 0; i < count; i++) { - var platformID = bin.readUshort(data, offset);offset += 2; - var encodingID = bin.readUshort(data, offset);offset += 2; - var languageID = bin.readUshort(data, offset);offset += 2; - var nameID = bin.readUshort(data, offset);offset += 2; - var slen = bin.readUshort(data, offset);offset += 2; - var noffset = bin.readUshort(data, offset);offset += 2; - //console.log(platformID, encodingID, languageID.toString(16), nameID, length, noffset); - - var cname = names[nameID]; - var soff = offset0 + count * 12 + noffset; - var str; - if (platformID == 0) str = bin.readUnicode(data, soff, slen / 2);else if (platformID == 3 && encodingID == 0) str = bin.readUnicode(data, soff, slen / 2);else if (encodingID == 0) str = bin.readASCII(data, soff, slen);else if (encodingID == 1) str = bin.readUnicode(data, soff, slen / 2);else if (encodingID == 3) str = bin.readUnicode(data, soff, slen / 2);else if (platformID == 1) { - str = bin.readASCII(data, soff, slen);console.log("reading unknown MAC encoding " + encodingID + " as ASCII"); - } else throw "unknown encoding " + encodingID + ", platformID: " + platformID; - - var tid = "p" + platformID + "," + languageID.toString(16); //Typr._platforms[platformID]; - if (obj[tid] == null) obj[tid] = {}; - obj[tid][cname] = str; - obj[tid]._lang = languageID; - //console.log(tid, obj[tid]); - } - /* - if(format == 1) - { - var langTagCount = bin.readUshort(data, offset); offset += 2; - for(var i=0; i= tab.map.length) return 0; - return tab.map[code]; - } else if (tab.format == 4) { - var sind = -1; - for (var i = 0; i < tab.endCount.length; i++) { - if (code <= tab.endCount[i]) { - sind = i;break; - } - }if (sind == -1) return 0; - if (tab.startCount[sind] > code) return 0; - - var gli = 0; - if (tab.idRangeOffset[sind] != 0) gli = tab.glyphIdArray[code - tab.startCount[sind] + (tab.idRangeOffset[sind] >> 1) - (tab.idRangeOffset.length - sind)];else gli = code + tab.idDelta[sind]; - return gli & 0xFFFF; - } else if (tab.format == 12) { - if (code > tab.groups[tab.groups.length - 1][1]) return 0; - for (var i = 0; i < tab.groups.length; i++) { - var grp = tab.groups[i]; - if (grp[0] <= code && code <= grp[1]) return grp[2] + (code - grp[0]); - } - return 0; - } else throw "unknown cmap table format " + tab.format; - }; - - Typr.U.glyphToPath = function (font, gid) { - var path = { cmds: [], crds: [] }; - if (font.SVG && font.SVG.entries[gid]) { - var p = font.SVG.entries[gid];if (p == null) return path; - if (typeof p == "string") { - p = Typr.SVG.toPath(p);font.SVG.entries[gid] = p; - } - return p; - } else if (font.CFF) { - var state = { x: 0, y: 0, stack: [], nStems: 0, haveWidth: false, width: font.CFF.Private ? font.CFF.Private.defaultWidthX : 0, open: false }; - var cff = font.CFF, - pdct = font.CFF.Private; - if (cff.ROS) { - var gi = 0; - while (cff.FDSelect[gi + 2] <= gid) { - gi += 2; - }pdct = cff.FDArray[cff.FDSelect[gi + 1]].Private; - } - Typr.U._drawCFF(font.CFF.CharStrings[gid], state, cff, pdct, path); - } else if (font.glyf) { - Typr.U._drawGlyf(gid, font, path); - } - return path; - }; - - Typr.U._drawGlyf = function (gid, font, path) { - var gl = font.glyf[gid]; - if (gl == null) gl = font.glyf[gid] = Typr.glyf._parseGlyf(font, gid); - if (gl != null) { - if (gl.noc > -1) Typr.U._simpleGlyph(gl, path);else Typr.U._compoGlyph(gl, font, path); - } - }; - Typr.U._simpleGlyph = function (gl, p) { - for (var c = 0; c < gl.noc; c++) { - var i0 = c == 0 ? 0 : gl.endPts[c - 1] + 1; - var il = gl.endPts[c]; - - for (var i = i0; i <= il; i++) { - var pr = i == i0 ? il : i - 1; - var nx = i == il ? i0 : i + 1; - var onCurve = gl.flags[i] & 1; - var prOnCurve = gl.flags[pr] & 1; - var nxOnCurve = gl.flags[nx] & 1; - - var x = gl.xs[i], - y = gl.ys[i]; - - if (i == i0) { - if (onCurve) { - if (prOnCurve) Typr.U.P.moveTo(p, gl.xs[pr], gl.ys[pr]);else { - Typr.U.P.moveTo(p, x, y);continue; /* will do curveTo at il */ - } - } else { - if (prOnCurve) Typr.U.P.moveTo(p, gl.xs[pr], gl.ys[pr]);else Typr.U.P.moveTo(p, (gl.xs[pr] + x) / 2, (gl.ys[pr] + y) / 2); - } - } - if (onCurve) { - if (prOnCurve) Typr.U.P.lineTo(p, x, y); - } else { - if (nxOnCurve) Typr.U.P.qcurveTo(p, x, y, gl.xs[nx], gl.ys[nx]);else Typr.U.P.qcurveTo(p, x, y, (x + gl.xs[nx]) / 2, (y + gl.ys[nx]) / 2); - } - } - Typr.U.P.closePath(p); - } - }; - Typr.U._compoGlyph = function (gl, font, p) { - for (var j = 0; j < gl.parts.length; j++) { - var path = { cmds: [], crds: [] }; - var prt = gl.parts[j]; - Typr.U._drawGlyf(prt.glyphIndex, font, path); - - var m = prt.m; - for (var i = 0; i < path.crds.length; i += 2) { - var x = path.crds[i], - y = path.crds[i + 1]; - p.crds.push(x * m.a + y * m.b + m.tx); - p.crds.push(x * m.c + y * m.d + m.ty); - } - for (var i = 0; i < path.cmds.length; i++) { - p.cmds.push(path.cmds[i]); - } - } - }; - - Typr.U._getGlyphClass = function (g, cd) { - var intr = Typr._lctf.getInterval(cd, g); - return intr == -1 ? 0 : cd[intr + 2]; - //for(var i=0; i=g) return cd.class[i]; - //return 0; - }; - - Typr.U.getPairAdjustment = function (font, g1, g2) { - //return 0; - if (font.GPOS) { - var gpos = font["GPOS"]; - var llist = gpos.lookupList, - flist = gpos.featureList; - var tused = []; - for (var i = 0; i < flist.length; i++) { - var fl = flist[i]; //console.log(fl); - if (fl.tag != "kern") continue; - for (var ti = 0; ti < fl.tab.length; ti++) { - if (tused[fl.tab[ti]]) continue;tused[fl.tab[ti]] = true; - var tab = llist[fl.tab[ti]]; - //console.log(tab); - - for (var j = 0; j < tab.tabs.length; j++) { - if (tab.tabs[i] == null) continue; - var ltab = tab.tabs[j], - ind; - if (ltab.coverage) { - ind = Typr._lctf.coverageIndex(ltab.coverage, g1);if (ind == -1) continue; - } - - if (tab.ltype == 1) ;else if (tab.ltype == 2) { - var adj; - if (ltab.fmt == 1) { - var right = ltab.pairsets[ind]; - for (var i = 0; i < right.length; i++) { - if (right[i].gid2 == g2) adj = right[i]; - } - } else if (ltab.fmt == 2) { - var c1 = Typr.U._getGlyphClass(g1, ltab.classDef1); - var c2 = Typr.U._getGlyphClass(g2, ltab.classDef2); - adj = ltab.matrix[c1][c2]; - } - //if(adj) console.log(ltab, adj); - if (adj && adj.val2) return adj.val2[2]; - } - } - } - } - } - if (font.kern) { - var ind1 = font.kern.glyph1.indexOf(g1); - if (ind1 != -1) { - var ind2 = font.kern.rval[ind1].glyph2.indexOf(g2); - if (ind2 != -1) return font.kern.rval[ind1].vals[ind2]; - } - } - - return 0; - }; - - Typr.U.stringToGlyphs = function (font, str) { - var gls = []; - for (var i = 0; i < str.length; i++) { - var cc = str.codePointAt(i);if (cc > 0xffff) i++; - gls.push(Typr.U.codeToGlyph(font, cc)); - } - for (var i = 0; i < str.length; i++) { - var cc = str.codePointAt(i); // - if (cc == 2367) { - var t = gls[i - 1];gls[i - 1] = gls[i];gls[i] = t; - } - //if(cc==2381) { var t=gls[i+1]; gls[i+1]=gls[i]; gls[i]=t; } - if (cc > 0xffff) i++; - } - //console.log(gls.slice(0)); - - //console.log(gls); return gls; - - var gsub = font["GSUB"];if (gsub == null) return gls; - var llist = gsub.lookupList, - flist = gsub.featureList; - - var cligs = ["rlig", "liga", "mset", "isol", "init", "fina", "medi", "half", "pres", "blws" /* Tibetan fonts like Himalaya.ttf */]; - - //console.log(gls.slice(0)); - var tused = []; - for (var fi = 0; fi < flist.length; fi++) { - var fl = flist[fi];if (cligs.indexOf(fl.tag) == -1) continue; - //if(fl.tag=="blwf") continue; - //console.log(fl); - //console.log(fl.tag); - for (var ti = 0; ti < fl.tab.length; ti++) { - if (tused[fl.tab[ti]]) continue;tused[fl.tab[ti]] = true; - var tab = llist[fl.tab[ti]]; - //console.log(fl.tab[ti], tab.ltype); - //console.log(fl.tag, tab); - for (var ci = 0; ci < gls.length; ci++) { - var feat = Typr.U._getWPfeature(str, ci); - if ("isol,init,fina,medi".indexOf(fl.tag) != -1 && fl.tag != feat) continue; - - Typr.U._applySubs(gls, ci, tab, llist); - } - } - } - - return gls; - }; - Typr.U._getWPfeature = function (str, ci) { - // get Word Position feature - var wsep = "\n\t\" ,.:;!?() ،"; - var R = "آأؤإاةدذرزوٱٲٳٵٶٷڈډڊڋڌڍڎڏڐڑڒړڔڕږڗژڙۀۃۄۅۆۇۈۉۊۋۍۏےۓەۮۯܐܕܖܗܘܙܞܨܪܬܯݍݙݚݛݫݬݱݳݴݸݹࡀࡆࡇࡉࡔࡧࡩࡪࢪࢫࢬࢮࢱࢲࢹૅેૉ૊૎૏ૐ૑૒૝ૡ૤૯஁ஃ஄அஉ஌எஏ஑னப஫஬"; - var L = "ꡲ્૗"; - - var slft = ci == 0 || wsep.indexOf(str[ci - 1]) != -1; - var srgt = ci == str.length - 1 || wsep.indexOf(str[ci + 1]) != -1; - - if (!slft && R.indexOf(str[ci - 1]) != -1) slft = true; - if (!srgt && R.indexOf(str[ci]) != -1) srgt = true; - - if (!srgt && L.indexOf(str[ci + 1]) != -1) srgt = true; - if (!slft && L.indexOf(str[ci]) != -1) slft = true; - - var feat = null; - if (slft) feat = srgt ? "isol" : "init";else feat = srgt ? "fina" : "medi"; - - return feat; - }; - Typr.U._applySubs = function (gls, ci, tab, llist) { - var rlim = gls.length - ci - 1; - //if(ci==0) console.log("++++ ", tab.ltype); - for (var j = 0; j < tab.tabs.length; j++) { - if (tab.tabs[j] == null) continue; - var ltab = tab.tabs[j], - ind; - if (ltab.coverage) { - ind = Typr._lctf.coverageIndex(ltab.coverage, gls[ci]);if (ind == -1) continue; - } - //if(ci==0) console.log(ind, ltab); - //* - if (tab.ltype == 1) { - var gl = gls[ci]; - if (ltab.fmt == 1) gls[ci] = gls[ci] + ltab.delta;else gls[ci] = ltab.newg[ind]; - //console.log("applying ... 1", ci, gl, gls[ci]); - } //* - else if (tab.ltype == 4) { - var vals = ltab.vals[ind]; - - for (var k = 0; k < vals.length; k++) { - var lig = vals[k], - rl = lig.chain.length;if (rl > rlim) continue; - var good = true, - em1 = 0; - for (var l = 0; l < rl; l++) { - while (gls[ci + em1 + (1 + l)] == -1) { - em1++; - }if (lig.chain[l] != gls[ci + em1 + (1 + l)]) good = false; - } - if (!good) continue; - gls[ci] = lig.nglyph; - for (var l = 0; l < rl + em1; l++) { - gls[ci + l + 1] = -1; - }break; // first character changed, other ligatures do not apply anymore - //console.log("lig", ci, lig.chain, lig.nglyph); - //console.log("applying ..."); - } - } else if (tab.ltype == 5 && ltab.fmt == 2) { - var cind = Typr._lctf.getInterval(ltab.cDef, gls[ci]); - var cls = ltab.cDef[cind + 2], - scs = ltab.scset[cls]; - for (var i = 0; i < scs.length; i++) { - var sc = scs[i], - inp = sc.input; - if (inp.length > rlim) continue; - var good = true; - for (var l = 0; l < inp.length; l++) { - var cind2 = Typr._lctf.getInterval(ltab.cDef, gls[ci + 1 + l]); - if (cind == -1 && ltab.cDef[cind2 + 2] != inp[l]) { - good = false;break; - } - } - if (!good) continue; - //console.log(ci, gl); - var lrs = sc.substLookupRecords; - for (var k = 0; k < lrs.length; k += 2) { - var gi = lrs[k], - tabi = lrs[k + 1]; - //Typr.U._applyType1(gls, ci+gi, llist[tabi]); - //console.log(tabi, gls[ci+gi], llist[tabi]); - } - } - } else if (tab.ltype == 6 && ltab.fmt == 3) { - //if(ltab.backCvg.length==0) return; - if (!Typr.U._glsCovered(gls, ltab.backCvg, ci - ltab.backCvg.length)) continue; - if (!Typr.U._glsCovered(gls, ltab.inptCvg, ci)) continue; - if (!Typr.U._glsCovered(gls, ltab.ahedCvg, ci + ltab.inptCvg.length)) continue; - //console.log(ci, ltab); - var lr = ltab.lookupRec; //console.log(ci, gl, lr); - for (var i = 0; i < lr.length; i += 2) { - var cind = lr[i], - tab2 = llist[lr[i + 1]]; - //console.log("-", lr[i+1], tab2); - Typr.U._applySubs(gls, ci + cind, tab2, llist); - } - } - //else console.log("Unknown table", tab.ltype, ltab.fmt); - //*/ - } - }; - - Typr.U._glsCovered = function (gls, cvgs, ci) { - for (var i = 0; i < cvgs.length; i++) { - var ind = Typr._lctf.coverageIndex(cvgs[i], gls[ci + i]);if (ind == -1) return false; - } - return true; - }; - - Typr.U.glyphsToPath = function (font, gls, clr) { - //gls = gls.reverse();//gls.slice(0,12).concat(gls.slice(12).reverse()); - - var tpath = { cmds: [], crds: [] }; - var x = 0; - - for (var i = 0; i < gls.length; i++) { - var gid = gls[i];if (gid == -1) continue; - var gid2 = i < gls.length - 1 && gls[i + 1] != -1 ? gls[i + 1] : 0; - var path = Typr.U.glyphToPath(font, gid); - for (var j = 0; j < path.crds.length; j += 2) { - tpath.crds.push(path.crds[j] + x); - tpath.crds.push(path.crds[j + 1]); - } - if (clr) tpath.cmds.push(clr); - for (var j = 0; j < path.cmds.length; j++) { - tpath.cmds.push(path.cmds[j]); - }if (clr) tpath.cmds.push("X"); - x += font.hmtx.aWidth[gid]; // - font.hmtx.lsBearing[gid]; - if (i < gls.length - 1) x += Typr.U.getPairAdjustment(font, gid, gid2); - } - return tpath; - }; - - Typr.U.pathToSVG = function (path, prec) { - if (prec == null) prec = 5; - var out = [], - co = 0, - lmap = { "M": 2, "L": 2, "Q": 4, "C": 6 }; - for (var i = 0; i < path.cmds.length; i++) { - var cmd = path.cmds[i], - cn = co + (lmap[cmd] ? lmap[cmd] : 0); - out.push(cmd); - while (co < cn) { - var c = path.crds[co++];out.push(parseFloat(c.toFixed(prec)) + (co == cn ? "" : " ")); - } - } - return out.join(""); - }; - - Typr.U.pathToContext = function (path, ctx) { - var c = 0, - crds = path.crds; - - for (var j = 0; j < path.cmds.length; j++) { - var cmd = path.cmds[j]; - if (cmd == "M") { - ctx.moveTo(crds[c], crds[c + 1]); - c += 2; - } else if (cmd == "L") { - ctx.lineTo(crds[c], crds[c + 1]); - c += 2; - } else if (cmd == "C") { - ctx.bezierCurveTo(crds[c], crds[c + 1], crds[c + 2], crds[c + 3], crds[c + 4], crds[c + 5]); - c += 6; - } else if (cmd == "Q") { - ctx.quadraticCurveTo(crds[c], crds[c + 1], crds[c + 2], crds[c + 3]); - c += 4; - } else if (cmd.charAt(0) == "#") { - ctx.beginPath(); - ctx.fillStyle = cmd; - } else if (cmd == "Z") { - ctx.closePath(); - } else if (cmd == "X") { - ctx.fill(); - } - } - }; - - Typr.U.P = {}; - Typr.U.P.moveTo = function (p, x, y) { - p.cmds.push("M");p.crds.push(x, y); - }; - Typr.U.P.lineTo = function (p, x, y) { - p.cmds.push("L");p.crds.push(x, y); - }; - Typr.U.P.curveTo = function (p, a, b, c, d, e, f) { - p.cmds.push("C");p.crds.push(a, b, c, d, e, f); - }; - Typr.U.P.qcurveTo = function (p, a, b, c, d) { - p.cmds.push("Q");p.crds.push(a, b, c, d); - }; - Typr.U.P.closePath = function (p) { - p.cmds.push("Z"); - }; - - Typr.U._drawCFF = function (cmds, state, font, pdct, p) { - var stack = state.stack; - var nStems = state.nStems, - haveWidth = state.haveWidth, - width = state.width, - open = state.open; - var i = 0; - var x = state.x, - y = state.y, - c1x = 0, - c1y = 0, - c2x = 0, - c2y = 0, - c3x = 0, - c3y = 0, - c4x = 0, - c4y = 0, - jpx = 0, - jpy = 0; - - var o = { val: 0, size: 0 }; - //console.log(cmds); - while (i < cmds.length) { - Typr.CFF.getCharString(cmds, i, o); - var v = o.val; - i += o.size; - - if (v == "o1" || v == "o18") // hstem || hstemhm - { - var hasWidthArg; - - // The number of stem operators on the stack is always even. - // If the value is uneven, that means a width is specified. - hasWidthArg = stack.length % 2 !== 0; - if (hasWidthArg && !haveWidth) { - width = stack.shift() + pdct.nominalWidthX; - } - - nStems += stack.length >> 1; - stack.length = 0; - haveWidth = true; - } else if (v == "o3" || v == "o23") // vstem || vstemhm - { - var hasWidthArg; - - // The number of stem operators on the stack is always even. - // If the value is uneven, that means a width is specified. - hasWidthArg = stack.length % 2 !== 0; - if (hasWidthArg && !haveWidth) { - width = stack.shift() + pdct.nominalWidthX; - } - - nStems += stack.length >> 1; - stack.length = 0; - haveWidth = true; - } else if (v == "o4") { - if (stack.length > 1 && !haveWidth) { - width = stack.shift() + pdct.nominalWidthX; - haveWidth = true; - } - if (open) Typr.U.P.closePath(p); - - y += stack.pop(); - Typr.U.P.moveTo(p, x, y);open = true; - } else if (v == "o5") { - while (stack.length > 0) { - x += stack.shift(); - y += stack.shift(); - Typr.U.P.lineTo(p, x, y); - } - } else if (v == "o6" || v == "o7") // hlineto || vlineto - { - var count = stack.length; - var isX = v == "o6"; - - for (var j = 0; j < count; j++) { - var sval = stack.shift(); - - if (isX) x += sval;else y += sval; - isX = !isX; - Typr.U.P.lineTo(p, x, y); - } - } else if (v == "o8" || v == "o24") // rrcurveto || rcurveline - { - var count = stack.length; - var index = 0; - while (index + 6 <= count) { - c1x = x + stack.shift(); - c1y = y + stack.shift(); - c2x = c1x + stack.shift(); - c2y = c1y + stack.shift(); - x = c2x + stack.shift(); - y = c2y + stack.shift(); - Typr.U.P.curveTo(p, c1x, c1y, c2x, c2y, x, y); - index += 6; - } - if (v == "o24") { - x += stack.shift(); - y += stack.shift(); - Typr.U.P.lineTo(p, x, y); - } - } else if (v == "o11") break;else if (v == "o1234" || v == "o1235" || v == "o1236" || v == "o1237") //if((v+"").slice(0,3)=="o12") - { - if (v == "o1234") { - c1x = x + stack.shift(); // dx1 - c1y = y; // dy1 - c2x = c1x + stack.shift(); // dx2 - c2y = c1y + stack.shift(); // dy2 - jpx = c2x + stack.shift(); // dx3 - jpy = c2y; // dy3 - c3x = jpx + stack.shift(); // dx4 - c3y = c2y; // dy4 - c4x = c3x + stack.shift(); // dx5 - c4y = y; // dy5 - x = c4x + stack.shift(); // dx6 - Typr.U.P.curveTo(p, c1x, c1y, c2x, c2y, jpx, jpy); - Typr.U.P.curveTo(p, c3x, c3y, c4x, c4y, x, y); - } - if (v == "o1235") { - c1x = x + stack.shift(); // dx1 - c1y = y + stack.shift(); // dy1 - c2x = c1x + stack.shift(); // dx2 - c2y = c1y + stack.shift(); // dy2 - jpx = c2x + stack.shift(); // dx3 - jpy = c2y + stack.shift(); // dy3 - c3x = jpx + stack.shift(); // dx4 - c3y = jpy + stack.shift(); // dy4 - c4x = c3x + stack.shift(); // dx5 - c4y = c3y + stack.shift(); // dy5 - x = c4x + stack.shift(); // dx6 - y = c4y + stack.shift(); // dy6 - stack.shift(); // flex depth - Typr.U.P.curveTo(p, c1x, c1y, c2x, c2y, jpx, jpy); - Typr.U.P.curveTo(p, c3x, c3y, c4x, c4y, x, y); - } - if (v == "o1236") { - c1x = x + stack.shift(); // dx1 - c1y = y + stack.shift(); // dy1 - c2x = c1x + stack.shift(); // dx2 - c2y = c1y + stack.shift(); // dy2 - jpx = c2x + stack.shift(); // dx3 - jpy = c2y; // dy3 - c3x = jpx + stack.shift(); // dx4 - c3y = c2y; // dy4 - c4x = c3x + stack.shift(); // dx5 - c4y = c3y + stack.shift(); // dy5 - x = c4x + stack.shift(); // dx6 - Typr.U.P.curveTo(p, c1x, c1y, c2x, c2y, jpx, jpy); - Typr.U.P.curveTo(p, c3x, c3y, c4x, c4y, x, y); - } - if (v == "o1237") { - c1x = x + stack.shift(); // dx1 - c1y = y + stack.shift(); // dy1 - c2x = c1x + stack.shift(); // dx2 - c2y = c1y + stack.shift(); // dy2 - jpx = c2x + stack.shift(); // dx3 - jpy = c2y + stack.shift(); // dy3 - c3x = jpx + stack.shift(); // dx4 - c3y = jpy + stack.shift(); // dy4 - c4x = c3x + stack.shift(); // dx5 - c4y = c3y + stack.shift(); // dy5 - if (Math.abs(c4x - x) > Math.abs(c4y - y)) { - x = c4x + stack.shift(); - } else { - y = c4y + stack.shift(); - } - Typr.U.P.curveTo(p, c1x, c1y, c2x, c2y, jpx, jpy); - Typr.U.P.curveTo(p, c3x, c3y, c4x, c4y, x, y); - } - } else if (v == "o14") { - if (stack.length > 0 && !haveWidth) { - width = stack.shift() + font.nominalWidthX; - haveWidth = true; - } - if (stack.length == 4) // seac = standard encoding accented character - { - var adx = stack.shift(); - var ady = stack.shift(); - var bchar = stack.shift(); - var achar = stack.shift(); - - var bind = Typr.CFF.glyphBySE(font, bchar); - var aind = Typr.CFF.glyphBySE(font, achar); - - //console.log(bchar, bind); - //console.log(achar, aind); - //state.x=x; state.y=y; state.nStems=nStems; state.haveWidth=haveWidth; state.width=width; state.open=open; - - Typr.U._drawCFF(font.CharStrings[bind], state, font, pdct, p); - state.x = adx;state.y = ady; - Typr.U._drawCFF(font.CharStrings[aind], state, font, pdct, p); - - //x=state.x; y=state.y; nStems=state.nStems; haveWidth=state.haveWidth; width=state.width; open=state.open; - } - if (open) { - Typr.U.P.closePath(p);open = false; - } - } else if (v == "o19" || v == "o20") { - var hasWidthArg; - - // The number of stem operators on the stack is always even. - // If the value is uneven, that means a width is specified. - hasWidthArg = stack.length % 2 !== 0; - if (hasWidthArg && !haveWidth) { - width = stack.shift() + pdct.nominalWidthX; - } - - nStems += stack.length >> 1; - stack.length = 0; - haveWidth = true; - - i += nStems + 7 >> 3; - } else if (v == "o21") { - if (stack.length > 2 && !haveWidth) { - width = stack.shift() + pdct.nominalWidthX; - haveWidth = true; - } - - y += stack.pop(); - x += stack.pop(); - - if (open) Typr.U.P.closePath(p); - Typr.U.P.moveTo(p, x, y);open = true; - } else if (v == "o22") { - if (stack.length > 1 && !haveWidth) { - width = stack.shift() + pdct.nominalWidthX; - haveWidth = true; - } - - x += stack.pop(); - - if (open) Typr.U.P.closePath(p); - Typr.U.P.moveTo(p, x, y);open = true; - } else if (v == "o25") { - while (stack.length > 6) { - x += stack.shift(); - y += stack.shift(); - Typr.U.P.lineTo(p, x, y); - } - - c1x = x + stack.shift(); - c1y = y + stack.shift(); - c2x = c1x + stack.shift(); - c2y = c1y + stack.shift(); - x = c2x + stack.shift(); - y = c2y + stack.shift(); - Typr.U.P.curveTo(p, c1x, c1y, c2x, c2y, x, y); - } else if (v == "o26") { - if (stack.length % 2) { - x += stack.shift(); - } - - while (stack.length > 0) { - c1x = x; - c1y = y + stack.shift(); - c2x = c1x + stack.shift(); - c2y = c1y + stack.shift(); - x = c2x; - y = c2y + stack.shift(); - Typr.U.P.curveTo(p, c1x, c1y, c2x, c2y, x, y); - } - } else if (v == "o27") { - if (stack.length % 2) { - y += stack.shift(); - } - - while (stack.length > 0) { - c1x = x + stack.shift(); - c1y = y; - c2x = c1x + stack.shift(); - c2y = c1y + stack.shift(); - x = c2x + stack.shift(); - y = c2y; - Typr.U.P.curveTo(p, c1x, c1y, c2x, c2y, x, y); - } - } else if (v == "o10" || v == "o29") // callsubr || callgsubr - { - var obj = v == "o10" ? pdct : font; - if (stack.length == 0) { - console.log("error: empty stack"); - } else { - var ind = stack.pop(); - var subr = obj.Subrs[ind + obj.Bias]; - state.x = x;state.y = y;state.nStems = nStems;state.haveWidth = haveWidth;state.width = width;state.open = open; - Typr.U._drawCFF(subr, state, font, pdct, p); - x = state.x;y = state.y;nStems = state.nStems;haveWidth = state.haveWidth;width = state.width;open = state.open; - } - } else if (v == "o30" || v == "o31") // vhcurveto || hvcurveto - { - var count, - count1 = stack.length; - var index = 0; - var alternate = v == "o31"; - - count = count1 & ~2; - index += count1 - count; - - while (index < count) { - if (alternate) { - c1x = x + stack.shift(); - c1y = y; - c2x = c1x + stack.shift(); - c2y = c1y + stack.shift(); - y = c2y + stack.shift(); - if (count - index == 5) { - x = c2x + stack.shift();index++; - } else x = c2x; - alternate = false; - } else { - c1x = x; - c1y = y + stack.shift(); - c2x = c1x + stack.shift(); - c2y = c1y + stack.shift(); - x = c2x + stack.shift(); - if (count - index == 5) { - y = c2y + stack.shift();index++; - } else y = c2y; - alternate = true; - } - Typr.U.P.curveTo(p, c1x, c1y, c2x, c2y, x, y); - index += 4; - } - } else if ((v + "").charAt(0) == "o") { - console.log("Unknown operation: " + v, cmds);throw v; - } else stack.push(v); - } - //console.log(cmds); - state.x = x;state.y = y;state.nStems = nStems;state.haveWidth = haveWidth;state.width = width;state.open = open; - }; - - // End Typr.U.js - - return Typr; - } - - // Custom bundle of woff2otf (https://github.com/arty-name/woff2otf) with tiny-inflate - // (https://github.com/foliojs/tiny-inflate) for use in troika-3d-text. - // Original licenses apply: - // - tiny-inflate: https://github.com/foliojs/tiny-inflate/blob/master/LICENSE (MIT) - // - woff2otf.js: https://github.com/arty-name/woff2otf/blob/master/woff2otf.js (Apache2) - - function woff2otfFactory() { - - // Begin tinyInflate - var tinyInflate = function () { - var module = {}; - var TINF_OK = 0; - var TINF_DATA_ERROR = -3; - - function Tree() { - this.table = new Uint16Array(16); /* table of code length counts */ - this.trans = new Uint16Array(288); /* code -> symbol translation table */ - } - - function Data(source, dest) { - this.source = source; - this.sourceIndex = 0; - this.tag = 0; - this.bitcount = 0; - - this.dest = dest; - this.destLen = 0; - - this.ltree = new Tree(); /* dynamic length/symbol tree */ - this.dtree = new Tree(); /* dynamic distance tree */ - } - - /* --------------------------------------------------- * - * -- uninitialized global data (static structures) -- * - * --------------------------------------------------- */ - - var sltree = new Tree(); - var sdtree = new Tree(); - - /* extra bits and base tables for length codes */ - var length_bits = new Uint8Array(30); - var length_base = new Uint16Array(30); - - /* extra bits and base tables for distance codes */ - var dist_bits = new Uint8Array(30); - var dist_base = new Uint16Array(30); - - /* special ordering of code length codes */ - var clcidx = new Uint8Array([16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]); - - /* used by tinf_decode_trees, avoids allocations every call */ - var code_tree = new Tree(); - var lengths = new Uint8Array(288 + 32); - - /* ----------------------- * - * -- utility functions -- * - * ----------------------- */ - - /* build extra bits and base tables */ - function tinf_build_bits_base(bits, base, delta, first) { - var i, sum; - - /* build bits table */ - for (i = 0; i < delta; ++i) { - bits[i] = 0; - }for (i = 0; i < 30 - delta; ++i) { - bits[i + delta] = i / delta | 0; - } /* build base table */ - for (sum = first, i = 0; i < 30; ++i) { - base[i] = sum; - sum += 1 << bits[i]; - } - } - - /* build the fixed huffman trees */ - function tinf_build_fixed_trees(lt, dt) { - var i; - - /* build fixed length tree */ - for (i = 0; i < 7; ++i) { - lt.table[i] = 0; - }lt.table[7] = 24; - lt.table[8] = 152; - lt.table[9] = 112; - - for (i = 0; i < 24; ++i) { - lt.trans[i] = 256 + i; - }for (i = 0; i < 144; ++i) { - lt.trans[24 + i] = i; - }for (i = 0; i < 8; ++i) { - lt.trans[24 + 144 + i] = 280 + i; - }for (i = 0; i < 112; ++i) { - lt.trans[24 + 144 + 8 + i] = 144 + i; - } /* build fixed distance tree */ - for (i = 0; i < 5; ++i) { - dt.table[i] = 0; - }dt.table[5] = 32; - - for (i = 0; i < 32; ++i) { - dt.trans[i] = i; - } - } - - /* given an array of code lengths, build a tree */ - var offs = new Uint16Array(16); - - function tinf_build_tree(t, lengths, off, num) { - var i, sum; - - /* clear code length count table */ - for (i = 0; i < 16; ++i) { - t.table[i] = 0; - } /* scan symbol lengths, and sum code length counts */ - for (i = 0; i < num; ++i) { - t.table[lengths[off + i]]++; - }t.table[0] = 0; - - /* compute offset table for distribution sort */ - for (sum = 0, i = 0; i < 16; ++i) { - offs[i] = sum; - sum += t.table[i]; - } - - /* create code->symbol translation table (symbols sorted by code) */ - for (i = 0; i < num; ++i) { - if (lengths[off + i]) t.trans[offs[lengths[off + i]]++] = i; - } - } - - /* ---------------------- * - * -- decode functions -- * - * ---------------------- */ - - /* get one bit from source stream */ - function tinf_getbit(d) { - /* check if tag is empty */ - if (!d.bitcount--) { - /* load next tag */ - d.tag = d.source[d.sourceIndex++]; - d.bitcount = 7; - } - - /* shift bit out of tag */ - var bit = d.tag & 1; - d.tag >>>= 1; - - return bit; - } - - /* read a num bit value from a stream and add base */ - function tinf_read_bits(d, num, base) { - if (!num) return base; - - while (d.bitcount < 24) { - d.tag |= d.source[d.sourceIndex++] << d.bitcount; - d.bitcount += 8; - } - - var val = d.tag & 0xffff >>> 16 - num; - d.tag >>>= num; - d.bitcount -= num; - return val + base; - } - - /* given a data stream and a tree, decode a symbol */ - function tinf_decode_symbol(d, t) { - while (d.bitcount < 24) { - d.tag |= d.source[d.sourceIndex++] << d.bitcount; - d.bitcount += 8; - } - - var sum = 0, - cur = 0, - len = 0; - var tag = d.tag; - - /* get more bits while code value is above sum */ - do { - cur = 2 * cur + (tag & 1); - tag >>>= 1; - ++len; - - sum += t.table[len]; - cur -= t.table[len]; - } while (cur >= 0); - - d.tag = tag; - d.bitcount -= len; - - return t.trans[sum + cur]; - } - - /* given a data stream, decode dynamic trees from it */ - function tinf_decode_trees(d, lt, dt) { - var hlit, hdist, hclen; - var i, num, length; - - /* get 5 bits HLIT (257-286) */ - hlit = tinf_read_bits(d, 5, 257); - - /* get 5 bits HDIST (1-32) */ - hdist = tinf_read_bits(d, 5, 1); - - /* get 4 bits HCLEN (4-19) */ - hclen = tinf_read_bits(d, 4, 4); - - for (i = 0; i < 19; ++i) { - lengths[i] = 0; - } /* read code lengths for code length alphabet */ - for (i = 0; i < hclen; ++i) { - /* get 3 bits code length (0-7) */ - var clen = tinf_read_bits(d, 3, 0); - lengths[clcidx[i]] = clen; - } - - /* build code length tree */ - tinf_build_tree(code_tree, lengths, 0, 19); - - /* decode code lengths for the dynamic trees */ - for (num = 0; num < hlit + hdist;) { - var sym = tinf_decode_symbol(d, code_tree); - - switch (sym) { - case 16: - /* copy previous code length 3-6 times (read 2 bits) */ - var prev = lengths[num - 1]; - for (length = tinf_read_bits(d, 2, 3); length; --length) { - lengths[num++] = prev; - } - break; - case 17: - /* repeat code length 0 for 3-10 times (read 3 bits) */ - for (length = tinf_read_bits(d, 3, 3); length; --length) { - lengths[num++] = 0; - } - break; - case 18: - /* repeat code length 0 for 11-138 times (read 7 bits) */ - for (length = tinf_read_bits(d, 7, 11); length; --length) { - lengths[num++] = 0; - } - break; - default: - /* values 0-15 represent the actual code lengths */ - lengths[num++] = sym; - break; - } - } - - /* build dynamic trees */ - tinf_build_tree(lt, lengths, 0, hlit); - tinf_build_tree(dt, lengths, hlit, hdist); - } - - /* ----------------------------- * - * -- block inflate functions -- * - * ----------------------------- */ - - /* given a stream and two trees, inflate a block of data */ - function tinf_inflate_block_data(d, lt, dt) { - while (1) { - var sym = tinf_decode_symbol(d, lt); - - /* check for end of block */ - if (sym === 256) { - return TINF_OK; - } - - if (sym < 256) { - d.dest[d.destLen++] = sym; - } else { - var length, dist, offs; - var i; - - sym -= 257; - - /* possibly get more bits from length code */ - length = tinf_read_bits(d, length_bits[sym], length_base[sym]); - - dist = tinf_decode_symbol(d, dt); - - /* possibly get more bits from distance code */ - offs = d.destLen - tinf_read_bits(d, dist_bits[dist], dist_base[dist]); - - /* copy match */ - for (i = offs; i < offs + length; ++i) { - d.dest[d.destLen++] = d.dest[i]; - } - } - } - } - - /* inflate an uncompressed block of data */ - function tinf_inflate_uncompressed_block(d) { - var length, invlength; - var i; - - /* unread from bitbuffer */ - while (d.bitcount > 8) { - d.sourceIndex--; - d.bitcount -= 8; - } - - /* get length */ - length = d.source[d.sourceIndex + 1]; - length = 256 * length + d.source[d.sourceIndex]; - - /* get one's complement of length */ - invlength = d.source[d.sourceIndex + 3]; - invlength = 256 * invlength + d.source[d.sourceIndex + 2]; - - /* check length */ - if (length !== (~invlength & 0x0000ffff)) return TINF_DATA_ERROR; - - d.sourceIndex += 4; - - /* copy block */ - for (i = length; i; --i) { - d.dest[d.destLen++] = d.source[d.sourceIndex++]; - } /* make sure we start next block on a byte boundary */ - d.bitcount = 0; - - return TINF_OK; - } - - /* inflate stream from source to dest */ - function tinf_uncompress(source, dest) { - var d = new Data(source, dest); - var bfinal, btype, res; - - do { - /* read final block flag */ - bfinal = tinf_getbit(d); - - /* read block type (2 bits) */ - btype = tinf_read_bits(d, 2, 0); - - /* decompress block */ - switch (btype) { - case 0: - /* decompress uncompressed block */ - res = tinf_inflate_uncompressed_block(d); - break; - case 1: - /* decompress block with fixed huffman trees */ - res = tinf_inflate_block_data(d, sltree, sdtree); - break; - case 2: - /* decompress block with dynamic huffman trees */ - tinf_decode_trees(d, d.ltree, d.dtree); - res = tinf_inflate_block_data(d, d.ltree, d.dtree); - break; - default: - res = TINF_DATA_ERROR; - } - - if (res !== TINF_OK) throw new Error('Data error'); - } while (!bfinal); - - if (d.destLen < d.dest.length) { - if (typeof d.dest.slice === 'function') return d.dest.slice(0, d.destLen);else return d.dest.subarray(0, d.destLen); - } - - return d.dest; - } - - /* -------------------- * - * -- initialization -- * - * -------------------- */ - - /* build fixed huffman trees */ - tinf_build_fixed_trees(sltree, sdtree); - - /* build extra bits and base tables */ - tinf_build_bits_base(length_bits, length_base, 4, 3); - tinf_build_bits_base(dist_bits, dist_base, 2, 1); - - /* fix a special case */ - length_bits[28] = 0; - length_base[28] = 258; - - module.exports = tinf_uncompress; - - return module.exports; - }(); - // End tinyInflate - - // Begin woff2otf.js - /* - Copyright 2012, Steffen Hanikel (https://github.com/hanikesn) - Modified by Artemy Tregubenko, 2014 (https://github.com/arty-name/woff2otf) - Modified by Jason Johnston, 2019 (pako --> tiny-inflate) - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - A tool to convert a WOFF back to a TTF/OTF font file, in pure Javascript - */ - - function convert_streams(bufferIn, tinyInflate) { - var dataViewIn = new DataView(bufferIn); - var offsetIn = 0; - - function read2() { - var uint16 = dataViewIn.getUint16(offsetIn); - offsetIn += 2; - return uint16; - } - - function read4() { - var uint32 = dataViewIn.getUint32(offsetIn); - offsetIn += 4; - return uint32; - } - - function write2(uint16) { - dataViewOut.setUint16(offsetOut, uint16); - offsetOut += 2; - } - - function write4(uint32) { - dataViewOut.setUint32(offsetOut, uint32); - offsetOut += 4; - } - - var WOFFHeader = { - signature: read4(), - flavor: read4(), - length: read4(), - numTables: read2(), - reserved: read2(), - totalSfntSize: read4(), - majorVersion: read2(), - minorVersion: read2(), - metaOffset: read4(), - metaLength: read4(), - metaOrigLength: read4(), - privOffset: read4(), - privLength: read4() - }; - - var entrySelector = 0; - while (Math.pow(2, entrySelector) <= WOFFHeader.numTables) { - entrySelector++; - } - entrySelector--; - - var searchRange = Math.pow(2, entrySelector) * 16; - var rangeShift = WOFFHeader.numTables * 16 - searchRange; - - var offset = 4 + 2 + 2 + 2 + 2; - var TableDirectoryEntries = []; - for (var i = 0; i < WOFFHeader.numTables; i++) { - TableDirectoryEntries.push({ - tag: read4(), - offset: read4(), - compLength: read4(), - origLength: read4(), - origChecksum: read4() - }); - offset += 4 * 4; - } - - var arrayOut = new Uint8Array(4 + 2 + 2 + 2 + 2 + TableDirectoryEntries.length * (4 + 4 + 4 + 4) + TableDirectoryEntries.reduce(function (acc, entry) { - return acc + entry.origLength + 4; - }, 0)); - var bufferOut = arrayOut.buffer; - var dataViewOut = new DataView(bufferOut); - var offsetOut = 0; - - write4(WOFFHeader.flavor); - write2(WOFFHeader.numTables); - write2(searchRange); - write2(entrySelector); - write2(rangeShift); - - TableDirectoryEntries.forEach(function (TableDirectoryEntry) { - write4(TableDirectoryEntry.tag); - write4(TableDirectoryEntry.origChecksum); - write4(offset); - write4(TableDirectoryEntry.origLength); - - TableDirectoryEntry.outOffset = offset; - offset += TableDirectoryEntry.origLength; - if (offset % 4 != 0) { - offset += 4 - offset % 4; - } - }); - - var size; - - TableDirectoryEntries.forEach(function (TableDirectoryEntry) { - var compressedData = bufferIn.slice(TableDirectoryEntry.offset, TableDirectoryEntry.offset + TableDirectoryEntry.compLength); - - if (TableDirectoryEntry.compLength != TableDirectoryEntry.origLength) { - var uncompressedData = new Uint8Array(TableDirectoryEntry.origLength); - tinyInflate(new Uint8Array(compressedData, 2), //skip deflate header - uncompressedData); - } else { - uncompressedData = new Uint8Array(compressedData); - } - - arrayOut.set(uncompressedData, TableDirectoryEntry.outOffset); - offset = TableDirectoryEntry.outOffset + TableDirectoryEntry.origLength; - - var padding = 0; - if (offset % 4 != 0) { - padding = 4 - offset % 4; - } - arrayOut.set(new Uint8Array(padding).buffer, TableDirectoryEntry.outOffset + TableDirectoryEntry.origLength); - - size = offset + padding; - }); - - return bufferOut.slice(0, size); - } - - // End woff2otf.js - - return function (buffer) { - return convert_streams(buffer, tinyInflate); - }; - } - - /** - * An adapter that allows Typr.js to be used as if it were (a subset of) the OpenType.js API. - * Also adds support for WOFF files (not WOFF2). - */ - - function parserFactory(Typr, woff2otf) { - var cmdArgLengths = { - M: 2, - L: 2, - Q: 4, - C: 6, - Z: 0 - }; - - function wrapFontObj(typrFont) { - var glyphMap = Object.create(null); - - var fontObj = { - unitsPerEm: typrFont.head.unitsPerEm, - ascender: typrFont.hhea.ascender, - descender: typrFont.hhea.descender, - forEachGlyph: function forEachGlyph(text, fontSize, letterSpacing, callback) { - var glyphX = 0; - var fontScale = 1 / fontObj.unitsPerEm * fontSize; - - var glyphIndices = Typr.U.stringToGlyphs(typrFont, text); - var charIndex = 0; - glyphIndices.forEach(function (glyphIndex) { - // Typr returns a glyph index per string codepoint, with -1s in place of those that - // were omitted due to ligature substitution. So we can track original index in the - // string via simple increment, and skip everything else when seeing a -1. - if (glyphIndex !== -1) { - var glyphObj = glyphMap[glyphIndex]; - if (!glyphObj) { - var _Typr$U$glyphToPath = Typr.U.glyphToPath(typrFont, glyphIndex), - cmds = _Typr$U$glyphToPath.cmds, - crds = _Typr$U$glyphToPath.crds; - - // Find extents - Glyf gives this in metadata but not CFF, and Typr doesn't - // normalize the two, so it's simplest just to iterate ourselves. - - - var xMin = void 0, - yMin = void 0, - xMax = void 0, - yMax = void 0; - if (crds.length) { - xMin = yMin = Infinity; - xMax = yMax = -Infinity; - for (var i = 0, len = crds.length; i < len; i += 2) { - var x = crds[i]; - var y = crds[i + 1]; - if (x < xMin) xMin = x; - if (y < yMin) yMin = y; - if (x > xMax) xMax = x; - if (y > yMax) yMax = y; - } - } else { - xMin = xMax = yMin = yMax = 0; - } - - glyphObj = glyphMap[glyphIndex] = { - index: glyphIndex, - advanceWidth: typrFont.hmtx.aWidth[glyphIndex], - xMin: xMin, - yMin: yMin, - xMax: xMax, - yMax: yMax, - pathCommandCount: cmds.length, - forEachPathCommand: function forEachPathCommand(callback) { - var argsIndex = 0; - var argsArray = []; - for (var _i3 = 0, _len = cmds.length; _i3 < _len; _i3++) { - var numArgs = cmdArgLengths[cmds[_i3]]; - argsArray.length = 1 + numArgs; - argsArray[0] = cmds[_i3]; - for (var j = 1; j <= numArgs; j++) { - argsArray[j] = crds[argsIndex++]; - } - callback.apply(null, argsArray); - } - } - }; - } - - callback.call(null, glyphObj, glyphX, charIndex); - - if (glyphObj.advanceWidth) { - glyphX += glyphObj.advanceWidth * fontScale; - } - if (letterSpacing) { - glyphX += letterSpacing * fontSize; - } - } - charIndex += text.codePointAt(charIndex) > 0xffff ? 2 : 1; - }); - return glyphX; - } - }; - - return fontObj; - } - - return function parse(buffer) { - // Look to see if we have a WOFF file and convert it if so: - var peek = new Uint8Array(buffer, 0, 4); - var tag = Typr._bin.readASCII(peek, 0, 4); - if (tag === 'wOFF') { - buffer = woff2otf(buffer); - } else if (tag === 'wOF2') { - throw new Error('woff2 fonts not supported'); - } - return wrapFontObj(Typr.parse(buffer)[0]); - }; - } - - var workerModule = /*#__PURE__*/defineWorkerModule({ - name: 'Typr Font Parser', - dependencies: [typrFactory, woff2otfFactory, parserFactory], - init: function init(typrFactory, woff2otfFactory, parserFactory) { - var Typr = typrFactory(); - var woff2otf = woff2otfFactory(); - return parserFactory(Typr, woff2otf); - } - }); - - //import fontParser from './FontParser_OpenType.js' - - - var CONFIG = { - defaultFontURL: 'https://fonts.gstatic.com/s/roboto/v18/KFOmCnqEu92Fr1Mu4mxM.woff', //Roboto Regular - sdfGlyphSize: 64, - sdfMargin: 1 / 16, - sdfExponent: 9, - textureWidth: 2048 - }; - var tempColor = /*#__PURE__*/new THREE.Color(); - - /** - * Repository for all font SDF atlas textures - * - * { - * [font]: { - * sdfTexture: DataTexture - * } - * } - */ - var atlases = Object.create(null); - - /** - * @typedef {object} TroikaTextRenderInfo - Format of the result from `getTextRenderInfo`. - * @property {object} parameters - The normalized input arguments to the render call. - * @property {DataTexture} sdfTexture - The SDF atlas texture. - * @property {number} sdfGlyphSize - The size of each glyph's SDF; see `configureTextBuilder`. - * @property {number} sdfExponent - The exponent used in encoding the SDF's values; see `configureTextBuilder`. - * @property {Float32Array} glyphBounds - List of [minX, minY, maxX, maxY] quad bounds for each glyph. - * @property {Float32Array} glyphAtlasIndices - List holding each glyph's index in the SDF atlas. - * @property {Uint8Array} [glyphColors] - List holding each glyph's [r, g, b] color, if `colorRanges` was supplied. - * @property {Float32Array} [caretPositions] - A list of caret positions for all glyphs; this is - * the bottom [x,y] of the cursor position before each char, plus one after the last char. - * @property {number} [caretHeight] - An appropriate height for all selection carets. - * @property {number} ascender - The font's ascender metric. - * @property {number} descender - The font's descender metric. - * @property {number} lineHeight - The final computed lineHeight measurement. - * @property {number} topBaseline - The y position of the top line's baseline. - * @property {Array} blockBounds - The total [minX, minY, maxX, maxY] rect of the whole text block; - * this can include extra vertical space beyond the visible glyphs due to lineHeight, and is - * equivalent to the dimensions of a block-level text element in CSS. - * @property {Array} visibleBounds - - * @property {Array} totalBounds - DEPRECATED; use blockBounds instead. - * @property {Array} totalBlockSize - DEPRECATED; use blockBounds instead - * @property {Array} chunkedBounds - List of bounding rects for each consecutive set of N glyphs, - * in the format `{start:N, end:N, rect:[minX, minY, maxX, maxY]}`. - * @property {object} timings - Timing info for various parts of the rendering logic including SDF - * generation, layout, etc. - * @frozen - */ - - /** - * @callback getTextRenderInfo~callback - * @param {TroikaTextRenderInfo} textRenderInfo - */ - - /** - * Main entry point for requesting the data needed to render a text string with given font parameters. - * This is an asynchronous call, performing most of the logic in a web worker thread. - * @param {object} args - * @param {getTextRenderInfo~callback} callback - */ - function getTextRenderInfo(args, callback) { - args = assign$1({}, args); - - // Apply default font here to avoid a 'null' atlas, and convert relative - // URLs to absolute so they can be resolved in the worker - args.font = toAbsoluteURL(args.font || CONFIG.defaultFontURL); - - // Normalize text to a string - args.text = '' + args.text; - - args.sdfGlyphSize = args.sdfGlyphSize || CONFIG.sdfGlyphSize; - - // Normalize colors - if (args.colorRanges != null) { - var colors = {}; - for (var key in args.colorRanges) { - if (args.colorRanges.hasOwnProperty(key)) { - var val = args.colorRanges[key]; - if (typeof val !== 'number') { - val = tempColor.set(val).getHex(); - } - colors[key] = val; - } - } - args.colorRanges = colors; - } - - Object.freeze(args); - - // Init the atlas for this font if needed - var textureWidth = CONFIG.textureWidth, - sdfExponent = CONFIG.sdfExponent; - var _args = args, - sdfGlyphSize = _args.sdfGlyphSize; - - var atlasKey = args.font + '@' + sdfGlyphSize; - var atlas = atlases[atlasKey]; - if (!atlas) { - atlas = atlases[atlasKey] = { - sdfTexture: new THREE.DataTexture(new Uint8Array(sdfGlyphSize * textureWidth), textureWidth, sdfGlyphSize, THREE.LuminanceFormat, undefined, undefined, undefined, undefined, THREE.LinearFilter, THREE.LinearFilter) - }; - atlas.sdfTexture.font = args.font; - } - - // Issue request to the FontProcessor in the worker - processInWorker(args).then(function (result) { - // If the response has newGlyphs, copy them into the atlas texture at the specified indices - if (result.newGlyphSDFs) { - result.newGlyphSDFs.forEach(function (_ref3) { - var textureData = _ref3.textureData, - atlasIndex = _ref3.atlasIndex; - - var texImg = atlas.sdfTexture.image; - - // Grow the texture by power of 2 if needed - while (texImg.data.length < (atlasIndex + 1) * sdfGlyphSize * sdfGlyphSize) { - var biggerArray = new Uint8Array(texImg.data.length * 2); - biggerArray.set(texImg.data); - texImg.data = biggerArray; - texImg.height *= 2; - } - - // Insert the new glyph's data into the full texture image at the correct offsets - var cols = texImg.width / sdfGlyphSize; - var baseStartIndex = texImg.width * sdfGlyphSize * Math.floor(atlasIndex / cols) //full rows - + atlasIndex % cols * sdfGlyphSize; //partial row - for (var y = 0; y < sdfGlyphSize; y++) { - var srcStartIndex = y * sdfGlyphSize; - var rowStartIndex = baseStartIndex + y * texImg.width; - for (var x = 0; x < sdfGlyphSize; x++) { - texImg.data[rowStartIndex + x] = textureData[srcStartIndex + x]; - } - } - }); - atlas.sdfTexture.needsUpdate = true; - } - - // Invoke callback with the text layout arrays and updated texture - callback(Object.freeze({ - parameters: args, - sdfTexture: atlas.sdfTexture, - sdfGlyphSize: sdfGlyphSize, - sdfExponent: sdfExponent, - glyphBounds: result.glyphBounds, - glyphAtlasIndices: result.glyphAtlasIndices, - glyphColors: result.glyphColors, - caretPositions: result.caretPositions, - caretHeight: result.caretHeight, - chunkedBounds: result.chunkedBounds, - ascender: result.ascender, - descender: result.descender, - lineHeight: result.lineHeight, - topBaseline: result.topBaseline, - blockBounds: result.blockBounds, - visibleBounds: result.visibleBounds, - timings: result.timings, - get totalBounds() { - console.log('totalBounds deprecated, use blockBounds instead'); - return result.blockBounds; - }, - get totalBlockSize() { - console.log('totalBlockSize deprecated, use blockBounds instead'); - - var _result$blockBounds2 = _slicedToArray(result.blockBounds, 4), - x0 = _result$blockBounds2[0], - y0 = _result$blockBounds2[1], - x1 = _result$blockBounds2[2], - y1 = _result$blockBounds2[3]; - - return [x1 - x0, y1 - y0]; - } - })); - }); - } - - // Local assign impl so we don't have to import troika-core - function assign$1(toObj, fromObj) { - for (var key in fromObj) { - if (fromObj.hasOwnProperty(key)) { - toObj[key] = fromObj[key]; - } - } - return toObj; - } - - // Utility for making URLs absolute - var linkEl = void 0; - function toAbsoluteURL(path) { - if (!linkEl) { - linkEl = typeof document === 'undefined' ? {} : document.createElement('a'); - } - linkEl.href = path; - return linkEl.href; - } - - var fontProcessorWorkerModule = /*#__PURE__*/defineWorkerModule({ - name: 'FontProcessor', - dependencies: [CONFIG, workerModule, createGlyphSegmentsIndex, createSDFGenerator, createFontProcessor], - init: function init(config, fontParser, createGlyphSegmentsIndex, createSDFGenerator, createFontProcessor) { - var sdfExponent = config.sdfExponent, - sdfMargin = config.sdfMargin, - defaultFontURL = config.defaultFontURL; - - var sdfGenerator = createSDFGenerator(createGlyphSegmentsIndex, { sdfExponent: sdfExponent, sdfMargin: sdfMargin }); - return createFontProcessor(fontParser, sdfGenerator, { defaultFontURL: defaultFontURL }); - } - }); - - var processInWorker = /*#__PURE__*/defineWorkerModule({ - name: 'TextBuilder', - dependencies: [fontProcessorWorkerModule, ThenableWorkerModule], - init: function init(fontProcessor, Thenable) { - return function (args) { - var thenable = new Thenable(); - fontProcessor.process(args, thenable.resolve); - return thenable; - }; - }, - getTransferables: function getTransferables(result) { - // Mark array buffers as transferable to avoid cloning during postMessage - var transferables = [result.glyphBounds.buffer, result.glyphAtlasIndices.buffer]; - if (result.caretPositions) { - transferables.push(result.caretPositions.buffer); - } - if (result.newGlyphSDFs) { - result.newGlyphSDFs.forEach(function (d) { - transferables.push(d.textureData.buffer); - }); - } - return transferables; - } - }); - - var GlyphsGeometry = /*#__PURE__*/function () { - - var templateGeometries = {}; - function getTemplateGeometry(detail) { - var geom = templateGeometries[detail]; - if (!geom) { - geom = templateGeometries[detail] = new THREE.PlaneBufferGeometry(1, 1, detail, detail).translate(0.5, 0.5, 0); - } - return geom; - } - var tempVec3 = new THREE.Vector3(); - - var glyphBoundsAttrName = 'aTroikaGlyphBounds'; - var glyphIndexAttrName = 'aTroikaGlyphIndex'; - var glyphColorAttrName = 'aTroikaGlyphColor'; - - /** - @class GlyphsGeometry - A specialized Geometry for rendering a set of text glyphs. Uses InstancedBufferGeometry to - render the glyphs using GPU instancing of a single quad, rather than constructing a whole - geometry with vertices, for much smaller attribute arraybuffers according to this math: - Where N = number of glyphs... - Instanced: - - position: 4 * 3 - - index: 2 * 3 - - normal: 4 * 3 - - uv: 4 * 2 - - glyph x/y bounds: N * 4 - - glyph indices: N * 1 - = 5N + 38 - Non-instanced: - - position: N * 4 * 3 - - index: N * 2 * 3 - - normal: N * 4 * 3 - - uv: N * 4 * 2 - - glyph indices: N * 1 - = 39N - A downside of this is the rare-but-possible lack of the instanced arrays extension, - which we could potentially work around with a fallback non-instanced implementation. - */ - - var GlyphsGeometry = function (_THREE$InstancedBuffe) { - _inherits(GlyphsGeometry, _THREE$InstancedBuffe); - - function GlyphsGeometry() { - _classCallCheck(this, GlyphsGeometry); - - var _this = _possibleConstructorReturn(this, (GlyphsGeometry.__proto__ || Object.getPrototypeOf(GlyphsGeometry)).call(this)); - - _this.detail = 1; - - // Define groups for rendering text outline as a separate pass; these will only - // be used when the `material` getter returns an array, i.e. outlineWidth > 0. - _this.groups = [{ start: 0, count: Infinity, materialIndex: 0 }, { start: 0, count: Infinity, materialIndex: 1 }]; - - // Preallocate zero-radius bounding sphere - _this.boundingSphere = new THREE.Sphere(); - _this.boundingBox = new THREE.Box3(); - return _this; - } - - _createClass(GlyphsGeometry, [{ - key: 'computeBoundingSphere', - value: function computeBoundingSphere() { - // No-op; we'll sync the boundingSphere proactively in `updateGlyphs`. - } - }, { - key: 'computeBoundingBox', - value: function computeBoundingBox() { - // No-op; we'll sync the boundingBox proactively in `updateGlyphs`. - } - }, { - key: 'updateGlyphs', - - - /** - * Update the geometry for a new set of glyphs. - * @param {Float32Array} glyphBounds - An array holding the planar bounds for all glyphs - * to be rendered, 4 entries for each glyph: x1,x2,y1,y1 - * @param {Float32Array} glyphAtlasIndices - An array holding the index of each glyph within - * the SDF atlas texture. - * @param {Array} blockBounds - An array holding the [minX, minY, maxX, maxY] across all glyphs - * @param {Array} [chunkedBounds] - An array of objects describing bounds for each chunk of N - * consecutive glyphs: `{start:N, end:N, rect:[minX, minY, maxX, maxY]}`. This can be - * used with `applyClipRect` to choose an optimized `instanceCount`. - * @param {Uint8Array} [glyphColors] - An array holding r,g,b values for each glyph. - */ - value: function updateGlyphs(glyphBounds, glyphAtlasIndices, blockBounds, chunkedBounds, glyphColors) { - // Update the instance attributes - updateBufferAttr(this, glyphBoundsAttrName, glyphBounds, 4); - updateBufferAttr(this, glyphIndexAttrName, glyphAtlasIndices, 1); - updateBufferAttr(this, glyphColorAttrName, glyphColors, 3); - this._chunkedBounds = chunkedBounds; - setInstanceCount(this, glyphAtlasIndices.length); - - // Update the boundingSphere based on the total bounds - var sphere = this.boundingSphere; - sphere.center.set((blockBounds[0] + blockBounds[2]) / 2, (blockBounds[1] + blockBounds[3]) / 2, 0); - sphere.radius = sphere.center.distanceTo(tempVec3.set(blockBounds[0], blockBounds[1], 0)); - - // Update the boundingBox based on the total bounds - var box = this.boundingBox; - box.min.set(blockBounds[0], blockBounds[1], 0); - box.max.set(blockBounds[2], blockBounds[3], 0); - } - - /** - * Given a clipping rect, and the chunkedBounds from the last updateGlyphs call, choose the lowest - * `instanceCount` that will show all glyphs within the clipped view. This is an optimization - * for long blocks of text that are clipped, to skip vertex shader evaluation for glyphs that would - * be clipped anyway. - * - * Note that since `drawElementsInstanced[ANGLE]` only accepts an instance count and not a starting - * offset, this optimization becomes less effective as the clipRect moves closer to the end of the - * text block. We could fix that by switching from instancing to a full geometry with a drawRange, - * but at the expense of much larger attribute buffers (see classdoc above.) - * - * @param {Vector4} clipRect - */ - - }, { - key: 'applyClipRect', - value: function applyClipRect(clipRect) { - var count = this.getAttribute(glyphIndexAttrName).count; - var chunks = this._chunkedBounds; - if (chunks) { - for (var i = chunks.length; i--;) { - count = chunks[i].end; - var rect = chunks[i].rect; - // note: both rects are l-b-r-t - if (rect[1] < clipRect.w && rect[3] > clipRect.y && rect[0] < clipRect.z && rect[2] > clipRect.x) { - break; - } - } - } - setInstanceCount(this, count); - } - }, { - key: 'detail', - set: function set(detail) { - var _this2 = this; - - if (detail !== this._detail) { - this._detail = detail; - if (typeof detail !== 'number' || detail < 1) { - detail = 1; - } - var tpl = getTemplateGeometry(detail);['position', 'normal', 'uv'].forEach(function (attr) { - _this2.attributes[attr] = tpl.attributes[attr].clone(); - }); - this.setIndex(tpl.getIndex().clone()); - } - }, - get: function get() { - return this._detail; - } - }]); - - return GlyphsGeometry; - }(THREE.InstancedBufferGeometry); - - // Compat for pre r109: - - - if (!GlyphsGeometry.prototype.setAttribute) { - GlyphsGeometry.prototype.setAttribute = function (name, attribute) { - this.attributes[name] = attribute; - return this; - }; - } - - function updateBufferAttr(geom, attrName, newArray, itemSize) { - var attr = geom.getAttribute(attrName); - if (newArray) { - // If length isn't changing, just update the attribute's array data - if (attr && attr.array.length === newArray.length) { - attr.array.set(newArray); - attr.needsUpdate = true; - } else { - geom.setAttribute(attrName, new THREE.InstancedBufferAttribute(newArray, itemSize)); - // If the new attribute has a different size, we also have to (as of r117) manually clear the - // internal cached max instance count. See https://github.com/mrdoob/three.js/issues/19706 - // It's unclear if this is a threejs bug or a truly unsupported scenario; discussion in - // that ticket is ambiguous as to whether replacing a BufferAttribute with one of a - // different size is supported, but https://github.com/mrdoob/three.js/pull/17418 strongly - // implies it should be supported. It's possible we need to - delete geom._maxInstanceCount; //for r117+, could be fragile - geom.dispose(); //for r118+, more robust feeling, but more heavy-handed than I'd like - } - } else if (attr) { - geom.deleteAttribute(attrName); - } - } - - // Handle maxInstancedCount -> instanceCount rename that happened in three r117 - function setInstanceCount(geom, count) { - geom[geom.hasOwnProperty('instanceCount') ? 'instanceCount' : 'maxInstancedCount'] = count; - } - - return GlyphsGeometry; - }(); - - // language=GLSL - var VERTEX_DEFS = '\nuniform vec2 uTroikaSDFTextureSize;\nuniform float uTroikaSDFGlyphSize;\nuniform vec4 uTroikaTotalBounds;\nuniform vec4 uTroikaClipRect;\nuniform mat3 uTroikaOrient;\nuniform bool uTroikaUseGlyphColors;\nuniform float uTroikaDistanceOffset;\nattribute vec4 aTroikaGlyphBounds;\nattribute float aTroikaGlyphIndex;\nattribute vec3 aTroikaGlyphColor;\nvarying vec2 vTroikaGlyphUV;\nvarying vec4 vTroikaTextureUVBounds;\nvarying vec3 vTroikaGlyphColor;\nvarying vec2 vTroikaGlyphDimensions;\n'; - - // language=GLSL prefix="void main() {" suffix="}" - var VERTEX_TRANSFORM = '\nvec4 bounds = aTroikaGlyphBounds;\nvec4 outlineBounds = vec4(bounds.xy - uTroikaDistanceOffset, bounds.zw + uTroikaDistanceOffset);\nvec4 clippedBounds = vec4(\n clamp(outlineBounds.xy, uTroikaClipRect.xy, uTroikaClipRect.zw),\n clamp(outlineBounds.zw, uTroikaClipRect.xy, uTroikaClipRect.zw)\n);\nvec2 clippedXY = (mix(clippedBounds.xy, clippedBounds.zw, position.xy) - bounds.xy) / (bounds.zw - bounds.xy);\n\nposition.xy = mix(bounds.xy, bounds.zw, clippedXY);\n\nuv = (position.xy - uTroikaTotalBounds.xy) / (uTroikaTotalBounds.zw - uTroikaTotalBounds.xy);\n\nposition = uTroikaOrient * position;\nnormal = uTroikaOrient * normal;\n\nvTroikaGlyphUV = clippedXY.xy;\nvTroikaGlyphDimensions = vec2(bounds[2] - bounds[0], bounds[3] - bounds[1]);\n\n' + '\nfloat txCols = uTroikaSDFTextureSize.x / uTroikaSDFGlyphSize;\nvec2 txUvPerGlyph = uTroikaSDFGlyphSize / uTroikaSDFTextureSize;\nvec2 txStartUV = txUvPerGlyph * vec2(\n mod(aTroikaGlyphIndex, txCols),\n floor(aTroikaGlyphIndex / txCols)\n);\nvTroikaTextureUVBounds = vec4(txStartUV, vec2(txStartUV) + txUvPerGlyph);\n'; - - // language=GLSL - var FRAGMENT_DEFS = '\nuniform sampler2D uTroikaSDFTexture;\nuniform vec2 uTroikaSDFTextureSize;\nuniform float uTroikaSDFGlyphSize;\nuniform float uTroikaSDFExponent;\nuniform float uTroikaDistanceOffset;\nuniform bool uTroikaSDFDebug;\nvarying vec2 vTroikaGlyphUV;\nvarying vec4 vTroikaTextureUVBounds;\nvarying vec2 vTroikaGlyphDimensions;\n\nfloat troikaSdfValueToSignedDistance(float alpha) {\n // Inverse of encoding in SDFGenerator.js\n ' + '\n float maxDimension = max(vTroikaGlyphDimensions.x, vTroikaGlyphDimensions.y);\n float absDist = (1.0 - pow(2.0 * (alpha > 0.5 ? 1.0 - alpha : alpha), 1.0 / uTroikaSDFExponent)) * maxDimension;\n float signedDist = absDist * (alpha > 0.5 ? -1.0 : 1.0);\n return signedDist;\n}\n\nfloat troikaGlyphUvToSdfValue(vec2 glyphUV) {\n vec2 textureUV = mix(vTroikaTextureUVBounds.xy, vTroikaTextureUVBounds.zw, glyphUV);\n return texture2D(uTroikaSDFTexture, textureUV).r;\n}\n\nfloat troikaGlyphUvToDistance(vec2 uv) {\n return troikaSdfValueToSignedDistance(troikaGlyphUvToSdfValue(uv));\n}\n\nfloat troikaGetTextAlpha(float distanceOffset) {\n vec2 clampedGlyphUV = clamp(vTroikaGlyphUV, 0.5 / uTroikaSDFGlyphSize, 1.0 - 0.5 / uTroikaSDFGlyphSize);\n float distance = troikaGlyphUvToDistance(clampedGlyphUV);\n \n // Extrapolate distance when outside bounds:\n distance += clampedGlyphUV == vTroikaGlyphUV ? 0.0 : \n length((vTroikaGlyphUV - clampedGlyphUV) * vTroikaGlyphDimensions);\n\n ' + '\n \n #if defined(IS_DEPTH_MATERIAL) || defined(IS_DISTANCE_MATERIAL)\n float alpha = step(-distanceOffset, -distance);\n #else\n ' + '\n #if defined(GL_OES_standard_derivatives) || __VERSION__ >= 300\n float aaDist = length(fwidth(vTroikaGlyphUV * vTroikaGlyphDimensions)) * 0.5;\n #else\n float aaDist = vTroikaGlyphDimensions.x / 64.0;\n #endif\n \n float alpha = smoothstep(\n distanceOffset + aaDist,\n distanceOffset - aaDist,\n distance\n );\n #endif\n \n return alpha;\n}\n'; - - // language=GLSL prefix="void main() {" suffix="}" - var FRAGMENT_TRANSFORM = '\nfloat alpha = uTroikaSDFDebug ?\n troikaGlyphUvToSdfValue(vTroikaGlyphUV) :\n troikaGetTextAlpha(uTroikaDistanceOffset);\n\n#if !defined(IS_DEPTH_MATERIAL) && !defined(IS_DISTANCE_MATERIAL)\ngl_FragColor.a *= alpha;\n#endif\n \nif (alpha == 0.0) {\n discard;\n}\n'; - - /** - * Create a material for rendering text, derived from a baseMaterial - */ - function createTextDerivedMaterial(baseMaterial) { - var textMaterial = createDerivedMaterial(baseMaterial, { - chained: true, - extensions: { - derivatives: true - }, - uniforms: { - uTroikaSDFTexture: { value: null }, - uTroikaSDFTextureSize: { value: new THREE.Vector2() }, - uTroikaSDFGlyphSize: { value: 0 }, - uTroikaSDFExponent: { value: 0 }, - uTroikaTotalBounds: { value: new THREE.Vector4(0, 0, 0, 0) }, - uTroikaClipRect: { value: new THREE.Vector4(0, 0, 0, 0) }, - uTroikaDistanceOffset: { value: 0 }, - uTroikaOrient: { value: new THREE.Matrix3() }, - uTroikaUseGlyphColors: { value: true }, - uTroikaSDFDebug: { value: false } - }, - vertexDefs: VERTEX_DEFS, - vertexTransform: VERTEX_TRANSFORM, - fragmentDefs: FRAGMENT_DEFS, - fragmentColorTransform: FRAGMENT_TRANSFORM, - customRewriter: function customRewriter(_ref4) { - var vertexShader = _ref4.vertexShader, - fragmentShader = _ref4.fragmentShader; - - var uDiffuseRE = /\buniform\s+vec3\s+diffuse\b/; - if (uDiffuseRE.test(fragmentShader)) { - // Replace all instances of `diffuse` with our varying - fragmentShader = fragmentShader.replace(uDiffuseRE, 'varying vec3 vTroikaGlyphColor').replace(/\bdiffuse\b/g, 'vTroikaGlyphColor'); - // Make sure the vertex shader declares the uniform so we can grab it as a fallback - if (!uDiffuseRE.test(vertexShader)) { - vertexShader = vertexShader.replace(voidMainRegExp, 'uniform vec3 diffuse;\n$&\nvTroikaGlyphColor = uTroikaUseGlyphColors ? aTroikaGlyphColor / 255.0 : diffuse;\n'); - } - } - return { vertexShader: vertexShader, fragmentShader: fragmentShader }; - } - }); - - // Force transparency - TODO is this reasonable? - textMaterial.transparent = true; - - Object.defineProperties(textMaterial, { - isTroikaTextMaterial: { value: true }, - - // WebGLShadowMap reverses the side of the shadow material by default, which fails - // for planes, so here we force the `shadowSide` to always match the main side. - shadowSide: { - get: function get() { - return this.side; - }, - set: function set() { - //no-op - } - } - }); - - return textMaterial; - } - - var Text = /*#__PURE__*/function () { - - var defaultMaterial = new THREE.MeshBasicMaterial({ - color: 0xffffff, - side: THREE.DoubleSide, - transparent: true - }); - - var tempMat4 = new THREE.Matrix4(); - var tempVec3a = new THREE.Vector3(); - var tempVec3b = new THREE.Vector3(); - var tempArray = []; - var origin = new THREE.Vector3(); - var defaultOrient = '+x+y'; - - function first(o) { - return Array.isArray(o) ? o[0] : o; - } - - var raycastMesh = new THREE.Mesh(new THREE.PlaneBufferGeometry(1, 1).translate(0.5, 0.5, 0), defaultMaterial); - - var syncStartEvent = { type: 'syncstart' }; - var syncCompleteEvent = { type: 'synccomplete' }; - - var SYNCABLE_PROPS = ['font', 'fontSize', 'letterSpacing', 'lineHeight', 'maxWidth', 'overflowWrap', 'text', 'textAlign', 'textIndent', 'whiteSpace', 'anchorX', 'anchorY', 'colorRanges', 'sdfGlyphSize']; - - var COPYABLE_PROPS = SYNCABLE_PROPS.concat('material', 'color', 'depthOffset', 'clipRect', 'orientation', 'glyphGeometryDetail'); - - /** - * @class Text - * - * A ThreeJS Mesh that renders a string of text on a plane in 3D space using signed distance - * fields (SDF). - */ - - var Text = function (_THREE$Mesh) { - _inherits(Text, _THREE$Mesh); - - function Text() { - _classCallCheck(this, Text); - - var geometry = new GlyphsGeometry(); - - // === Text layout properties: === // - - /** - * @member {string} text - * The string of text to be rendered. - */ - var _this3 = _possibleConstructorReturn(this, (Text.__proto__ || Object.getPrototypeOf(Text)).call(this, geometry, null)); - - _this3.text = ''; - - /** - * @deprecated Use `anchorX` and `anchorY` instead - * @member {Array} anchor - * Defines where in the text block should correspond to the mesh's local position, as a set - * of horizontal and vertical percentages from 0 to 1. A value of `[0, 0]` (the default) - * anchors at the top-left, `[1, 1]` at the bottom-right, and `[0.5, 0.5]` centers the - * block at the mesh's position. - */ - //this.anchor = null - - /** - * @member {number|string} anchorX - * Defines the horizontal position in the text block that should line up with the local origin. - * Can be specified as a numeric x position in local units, a string percentage of the total - * text block width e.g. `'25%'`, or one of the following keyword strings: 'left', 'center', - * or 'right'. - */ - _this3.anchorX = 0; - - /** - * @member {number|string} anchorX - * Defines the vertical position in the text block that should line up with the local origin. - * Can be specified as a numeric y position in local units (note: down is negative y), a string - * percentage of the total text block height e.g. `'25%'`, or one of the following keyword strings: - * 'top', 'top-baseline', 'middle', 'bottom-baseline', or 'bottom'. - */ - _this3.anchorY = 0; - - /** - * @member {string} font - * URL of a custom font to be used. Font files can be any of the formats supported by - * OpenType (see https://github.com/opentypejs/opentype.js). - * Defaults to the Roboto font loaded from Google Fonts. - */ - _this3.font = null; //will use default from TextBuilder - - /** - * @member {number} fontSize - * The size at which to render the font in local units; corresponds to the em-box height - * of the chosen `font`. - */ - _this3.fontSize = 0.1; - - /** - * @member {number} letterSpacing - * Sets a uniform adjustment to spacing between letters after kerning is applied. Positive - * numbers increase spacing and negative numbers decrease it. - */ - _this3.letterSpacing = 0; - - /** - * @member {number|string} lineHeight - * Sets the height of each line of text, as a multiple of the `fontSize`. Defaults to 'normal' - * which chooses a reasonable height based on the chosen font's ascender/descender metrics. - */ - _this3.lineHeight = 'normal'; - - /** - * @member {number} maxWidth - * The maximum width of the text block, above which text may start wrapping according to the - * `whiteSpace` and `overflowWrap` properties. - */ - _this3.maxWidth = Infinity; - - /** - * @member {string} overflowWrap - * Defines how text wraps if the `whiteSpace` property is `normal`. Can be either `'normal'` - * to break at whitespace characters, or `'break-word'` to allow breaking within words. - * Defaults to `'normal'`. - */ - _this3.overflowWrap = 'normal'; - - /** - * @member {string} textAlign - * The horizontal alignment of each line of text within the overall text bounding box. - */ - _this3.textAlign = 'left'; - - /** - * @member {number} textIndent - * Indentation for the first character of a line; see CSS `text-indent`. - */ - _this3.textIndent = 0; - - /** - * @member {string} whiteSpace - * Defines whether text should wrap when a line reaches the `maxWidth`. Can - * be either `'normal'` (the default), to allow wrapping according to the `overflowWrap` property, - * or `'nowrap'` to prevent wrapping. Note that `'normal'` here honors newline characters to - * manually break lines, making it behave more like `'pre-wrap'` does in CSS. - */ - _this3.whiteSpace = 'normal'; - - // === Presentation properties: === // - - /** - * @member {THREE.Material} material - * Defines a _base_ material to be used when rendering the text. This material will be - * automatically replaced with a material derived from it, that adds shader code to - * decrease the alpha for each fragment (pixel) outside the text glyphs, with antialiasing. - * By default it will derive from a simple white MeshBasicMaterial, but you can use any - * of the other mesh materials to gain other features like lighting, texture maps, etc. - * - * Also see the `color` shortcut property. - */ - _this3.material = null; - - /** - * @member {string|number|THREE.Color} color - * This is a shortcut for setting the `color` of the text's material. You can use this - * if you don't want to specify a whole custom `material`. Also, if you do use a custom - * `material`, this color will only be used for this particuar Text instance, even if - * that same material instance is shared across multiple Text objects. - */ - _this3.color = null; - - /** - * @member {object|null} colorRanges - * WARNING: This API is experimental and may change. - * This allows more fine-grained control of colors for individual or ranges of characters, - * taking precedence over the material's `color`. Its format is an Object whose keys each - * define a starting character index for a range, and whose values are the color for each - * range. The color value can be a numeric hex color value, a `THREE.Color` object, or - * any of the strings accepted by `THREE.Color`. - */ - _this3.colorRanges = null; - - /** - * @member {number|string} outlineWidth - * WARNING: This API is experimental and may change. - * The width of an outline drawn around each text glyph using the `outlineColor`. Can be - * specified as either an absolute number in local units, or as a percentage string e.g. - * `"12%"` which is treated as a percentage of the `fontSize`. Defaults to `0`. - */ - _this3.outlineWidth = 0; - - /** - * @member {string|number|THREE.Color} outlineColor - * WARNING: This API is experimental and may change. - * The color of the text outline, if `outlineWidth` is greater than zero. Defaults to black. - */ - _this3.outlineColor = 0; - - /** - * @member {number} depthOffset - * This is a shortcut for setting the material's `polygonOffset` and related properties, - * which can be useful in preventing z-fighting when this text is laid on top of another - * plane in the scene. Positive numbers are further from the camera, negatives closer. - */ - _this3.depthOffset = 0; - - /** - * @member {Array} clipRect - * If specified, defines a `[minX, minY, maxX, maxY]` of a rectangle outside of which all - * pixels will be discarded. This can be used for example to clip overflowing text when - * `whiteSpace='nowrap'`. - */ - _this3.clipRect = null; - - /** - * @member {string} orientation - * Defines the axis plane on which the text should be laid out when the mesh has no extra - * rotation transform. It is specified as a string with two axes: the horizontal axis with - * positive pointing right, and the vertical axis with positive pointing up. By default this - * is '+x+y', meaning the text sits on the xy plane with the text's top toward positive y - * and facing positive z. A value of '+x-z' would place it on the xz plane with the text's - * top toward negative z and facing positive y. - */ - _this3.orientation = defaultOrient; - - /** - * @member {number} glyphGeometryDetail - * Controls number of vertical/horizontal segments that make up each glyph's rectangular - * plane. Defaults to 1. This can be increased to provide more geometrical detail for custom - * vertex shader effects, for example. - */ - _this3.glyphGeometryDetail = 1; - - /** - * @member {number|null} sdfGlyphSize - * The size of each glyph's SDF (signed distance field) used for rendering. This must be a - * power-of-two number. Defaults to 64 which is generally a good balance of size and quality - * for most fonts. Larger sizes can improve the quality of glyph rendering by increasing - * the sharpness of corners and preventing loss of very thin lines, at the expense of - * increased memory footprint and longer SDF generation time. - */ - _this3.sdfGlyphSize = null; - - _this3.debugSDF = false; - return _this3; - } - - /** - * Updates the text rendering according to the current text-related configuration properties. - * This is an async process, so you can pass in a callback function to be executed when it - * finishes. - * @param {function} [callback] - */ - - - _createClass(Text, [{ - key: 'sync', - value: function sync(callback) { - var _this4 = this; - - if (this._needsSync) { - this._needsSync = false; - - // If there's another sync still in progress, queue - if (this._isSyncing) { - (this._queuedSyncs || (this._queuedSyncs = [])).push(callback); - } else { - this._isSyncing = true; - this.dispatchEvent(syncStartEvent); - - getTextRenderInfo({ - text: this.text, - font: this.font, - fontSize: this.fontSize || 0.1, - letterSpacing: this.letterSpacing || 0, - lineHeight: this.lineHeight || 'normal', - maxWidth: this.maxWidth, - textAlign: this.textAlign, - textIndent: this.textIndent, - whiteSpace: this.whiteSpace, - overflowWrap: this.overflowWrap, - anchorX: this.anchorX, - anchorY: this.anchorY, - colorRanges: this.colorRanges, - includeCaretPositions: true, //TODO parameterize - sdfGlyphSize: this.sdfGlyphSize - }, function (textRenderInfo) { - _this4._isSyncing = false; - - // Save result for later use in onBeforeRender - _this4._textRenderInfo = textRenderInfo; - - // Update the geometry attributes - _this4.geometry.updateGlyphs(textRenderInfo.glyphBounds, textRenderInfo.glyphAtlasIndices, textRenderInfo.blockBounds, textRenderInfo.chunkedBounds, textRenderInfo.glyphColors); - - // If we had extra sync requests queued up, kick it off - var queued = _this4._queuedSyncs; - if (queued) { - _this4._queuedSyncs = null; - _this4._needsSync = true; - _this4.sync(function () { - queued.forEach(function (fn) { - return fn && fn(); - }); - }); - } - - _this4.dispatchEvent(syncCompleteEvent); - if (callback) { - callback(); - } - }); - } - } - } - - /** - * Initiate a sync if needed - note it won't complete until next frame at the - * earliest so if possible it's a good idea to call sync() manually as soon as - * all the properties have been set. - * @override - */ - - }, { - key: 'onBeforeRender', - value: function onBeforeRender(renderer, scene, camera, geometry, material, group) { - this.sync(); - - // This may not always be a text material, e.g. if there's a scene.overrideMaterial present - if (material.isTroikaTextMaterial) { - this._prepareForRender(material); - } - } - - /** - * Shortcut to dispose the geometry specific to this instance. - * Note: we don't also dispose the derived material here because if anything else is - * sharing the same base material it will result in a pause next frame as the program - * is recompiled. Instead users can dispose the base material manually, like normal, - * and we'll also dispose the derived material at that time. - */ - - }, { - key: 'dispose', - value: function dispose() { - this.geometry.dispose(); - } - - /** - * @property {TroikaTextRenderInfo|null} textRenderInfo - * @readonly - * The current processed rendering data for this TextMesh, returned by the TextBuilder after - * a `sync()` call. This will be `null` initially, and may be stale for a short period until - * the asynchrous `sync()` process completes. - */ - - }, { - key: '_prepareForRender', - value: function _prepareForRender(material) { - var isOutline = material.isTextOutlineMaterial; - var uniforms = material.uniforms; - var textInfo = this.textRenderInfo; - if (textInfo) { - var sdfTexture = textInfo.sdfTexture, - blockBounds = textInfo.blockBounds; - - uniforms.uTroikaSDFTexture.value = sdfTexture; - uniforms.uTroikaSDFTextureSize.value.set(sdfTexture.image.width, sdfTexture.image.height); - uniforms.uTroikaSDFGlyphSize.value = textInfo.sdfGlyphSize; - uniforms.uTroikaSDFExponent.value = textInfo.sdfExponent; - uniforms.uTroikaTotalBounds.value.fromArray(blockBounds); - uniforms.uTroikaUseGlyphColors.value = !!textInfo.glyphColors; - - var distanceOffset = 0; - if (isOutline) { - var outlineWidth = this.outlineWidth; - - if (typeof outlineWidth === 'string') { - var match = outlineWidth.match(/^([\d.]+)%$/); - var pct = match ? parseFloat(match[1]) : NaN; - outlineWidth = (isNaN(pct) ? 0 : pct / 100) * this.fontSize; - } - distanceOffset = outlineWidth; - } - uniforms.uTroikaDistanceOffset.value = distanceOffset; - - var clipRect = this.clipRect; - if (clipRect && Array.isArray(clipRect) && clipRect.length === 4) { - uniforms.uTroikaClipRect.value.fromArray(clipRect); - } else { - // no clipping - choose a finite rect that shouldn't ever be reached by overflowing glyphs or outlines - var pad = (this.fontSize || 0.1) * 100; - uniforms.uTroikaClipRect.value.set(blockBounds[0] - pad, blockBounds[1] - pad, blockBounds[2] + pad, blockBounds[3] + pad); - } - this.geometry.applyClipRect(uniforms.uTroikaClipRect.value); - } - uniforms.uTroikaSDFDebug.value = !!this.debugSDF; - material.polygonOffset = !!this.depthOffset; - material.polygonOffsetFactor = material.polygonOffsetUnits = this.depthOffset || 0; - - // Shortcut for setting material color via `color` prop on the mesh; this is - // applied only to the derived material to avoid mutating a shared base material. - var color = isOutline ? this.outlineColor || 0 : this.color; - if (color == null) { - delete material.color; //inherit from base - } else { - var colorObj = material.hasOwnProperty('color') ? material.color : material.color = new THREE.Color(); - if (color !== colorObj._input || (typeof color === 'undefined' ? 'undefined' : _typeof(color)) === 'object') { - colorObj.set(colorObj._input = color); - } - } - - // base orientation - var orient = this.orientation || defaultOrient; - if (orient !== material._orientation) { - var rotMat = uniforms.uTroikaOrient.value; - orient = orient.replace(/[^-+xyz]/g, ''); - var _match = orient !== defaultOrient && orient.match(/^([-+])([xyz])([-+])([xyz])$/); - if (_match) { - var _match2 = _slicedToArray(_match, 5), - hSign = _match2[1], - hAxis = _match2[2], - vSign = _match2[3], - vAxis = _match2[4]; - - tempVec3a.set(0, 0, 0)[hAxis] = hSign === '-' ? 1 : -1; - tempVec3b.set(0, 0, 0)[vAxis] = vSign === '-' ? -1 : 1; - tempMat4.lookAt(origin, tempVec3a.cross(tempVec3b), tempVec3b); - rotMat.setFromMatrix4(tempMat4); - } else { - rotMat.identity(); - } - material._orientation = orient; - } - } - - /** - * @override Custom raycasting to test against the whole text block's max rectangular bounds - * TODO is there any reason to make this more granular, like within individual line or glyph rects? - */ - - }, { - key: 'raycast', - value: function raycast(raycaster, intersects) { - var textInfo = this.textRenderInfo; - if (textInfo) { - var bounds = textInfo.blockBounds; - raycastMesh.matrixWorld.multiplyMatrices(this.matrixWorld, tempMat4.set(bounds[2] - bounds[0], 0, 0, bounds[0], 0, bounds[3] - bounds[1], 0, bounds[1], 0, 0, 1, 0, 0, 0, 0, 1)); - tempArray.length = 0; - raycastMesh.raycast(raycaster, tempArray); - for (var i = 0; i < tempArray.length; i++) { - tempArray[i].object = this; - intersects.push(tempArray[i]); - } - } - } - }, { - key: 'copy', - value: function copy(source) { - var _this5 = this; - - _get(Text.prototype.__proto__ || Object.getPrototypeOf(Text.prototype), 'copy', this).call(this, source); - COPYABLE_PROPS.forEach(function (prop) { - _this5[prop] = source[prop]; - }); - return this; - } - }, { - key: 'clone', - value: function clone() { - return new this.constructor().copy(this); - } - }, { - key: 'textRenderInfo', - get: function get() { - return this._textRenderInfo || null; - } - - // Handler for automatically wrapping the base material with our upgrades. We do the wrapping - // lazily on _read_ rather than write to avoid unnecessary wrapping on transient values. - - }, { - key: 'material', - get: function get() { - var derivedMaterial = this._derivedMaterial; - var baseMaterial = this._baseMaterial || this._defaultMaterial || (this._defaultMaterial = defaultMaterial.clone()); - if (!derivedMaterial || derivedMaterial.baseMaterial !== baseMaterial) { - derivedMaterial = this._derivedMaterial = createTextDerivedMaterial(baseMaterial); - // dispose the derived material when its base material is disposed: - baseMaterial.addEventListener('dispose', function onDispose() { - baseMaterial.removeEventListener('dispose', onDispose); - derivedMaterial.dispose(); - }); - } - // If text outline is present, render it as a preliminary draw using Three's multi-material - // feature (see GlyphsGeometry which sets up `groups` for this purpose) Doing it with multi - // materials ensures the layers are always rendered consecutively in a consistent order. - // Each layer will trigger onBeforeRender with the appropriate material. - if (this.outlineWidth) { - var outlineMaterial = derivedMaterial._outlineMtl; - if (!outlineMaterial) { - outlineMaterial = derivedMaterial._outlineMtl = Object.create(derivedMaterial, { - id: { value: derivedMaterial.id + 0.1 } - }); - outlineMaterial.isTextOutlineMaterial = true; - outlineMaterial.depthWrite = false; - outlineMaterial.map = null; //??? - } - derivedMaterial = [outlineMaterial, derivedMaterial]; - } - return derivedMaterial; - }, - set: function set(baseMaterial) { - if (baseMaterial && baseMaterial.isTroikaTextMaterial) { - //prevent double-derivation - this._derivedMaterial = baseMaterial; - this._baseMaterial = baseMaterial.baseMaterial; - } else { - this._baseMaterial = baseMaterial; - } - } - }, { - key: 'glyphGeometryDetail', - get: function get() { - return this.geometry.detail; - }, - set: function set(detail) { - this.geometry.detail = detail; - } - - // Create and update material for shadows upon request: - - }, { - key: 'customDepthMaterial', - get: function get() { - return first(this.material).getDepthMaterial(); - } - }, { - key: 'customDistanceMaterial', - get: function get() { - return first(this.material).getDistanceMaterial(); - } - }]); - - return Text; - }(THREE.Mesh); - - // Create setters for properties that affect text layout: - - - SYNCABLE_PROPS.forEach(function (prop) { - var privateKey = '_private_' + prop; - Object.defineProperty(Text.prototype, prop, { - get: function get() { - return this[privateKey]; - }, - set: function set(value) { - if (value !== this[privateKey]) { - this[privateKey] = value; - this._needsSync = true; - } - } - }); - }); - - // Deprecation handler for `anchor` array: - var deprMsgShown = false; - Object.defineProperty(Text.prototype, 'anchor', { - get: function get() { - return this._deprecated_anchor; - }, - set: function set(val) { - this._deprecated_anchor = val; - if (!deprMsgShown) { - console.warn('TextMesh: `anchor` has been deprecated; use `anchorX` and `anchorY` instead.'); - deprMsgShown = true; - } - if (Array.isArray(val)) { - this.anchorX = (+val[0] || 0) * 100 + '%'; - this.anchorY = (+val[1] || 0) * 100 + '%'; - } else { - this.anchorX = this.anchorY = 0; - } - } - }); - - return Text; - }(); - - var COMPONENT_NAME = 'troika-text'; - - aframe__default['default'].registerComponent(COMPONENT_NAME, { - schema: { - align: { type: 'string', default: 'left', oneOf: ['left', 'right', 'center', 'justify'] }, - anchor: { default: 'center', oneOf: ['left', 'right', 'center', 'align'] }, - baseline: { default: 'center', oneOf: ['top', 'center', 'bottom'] }, - clipRect: { - type: 'string', - default: '', - parse: function parse(value) { - if (value) { - value = value.split(/[\s,]+/).reduce(function (out, val) { - val = +val; - if (!isNaN(val)) { - out.push(val); - } - return out; - }, []); - } - return value && value.length === 4 ? value : null; - }, - stringify: function stringify(value) { - return value ? value.join(' ') : ''; - } - }, - color: { type: 'color', default: '#FFF' }, - depthOffset: { type: 'number', default: 0 }, - font: { type: 'string' }, - fontSize: { type: 'number', default: 0.2 }, - letterSpacing: { type: 'number', default: 0 }, - lineHeight: { type: 'number' }, - maxWidth: { type: 'number', default: Infinity }, - outlineColor: { type: 'color', default: '#000' }, - outlineWidth: { - default: 0, - parse: function parse(value) { - if (typeof value === 'string' && value.indexOf('%') > 0) { - return value; - } - value = +value; - return isNaN(value) ? 0 : value; - }, - stringify: function stringify(value) { - return '' + value; - } - }, - overflowWrap: { type: 'string', default: 'normal', oneOf: ['normal', 'break-word'] }, - textIndent: { type: 'number', default: 0 }, - value: { type: 'string' }, - whiteSpace: { default: 'normal', oneOf: ['normal', 'nowrap'] - - // attrs that can be configured via troika-text-material: - // opacity: {type: 'number', default: 1.0}, - // transparent: {default: true}, - // side: {default: 'front', oneOf: ['front', 'back', 'double']}, - } }, - - /** - * Called once when component is attached. Generally for initial setup. - */ - init: function init() { - // If we're being applied as a component attached to a generic a-entity, create an - // anonymous sub-entity that we can use to isolate the text mesh and the material - // component that should apply to it. If we're a primitive, no isolation is needed. - var textEntity; - var isPrimitive = this.el.tagName.toLowerCase() === 'a-troika-text'; - if (isPrimitive) { - textEntity = this.el; - } else { - textEntity = document.createElement('a-entity'); - this.el.appendChild(textEntity); - } - this.troikaTextEntity = textEntity; - - // Create Text mesh and add it to the entity as the 'mesh' object - var textMesh = this.troikaTextMesh = new Text(); - textEntity.setObject3D('mesh', textMesh); - }, - - /** - * Called when component is attached and when component data changes. - * Generally modifies the entity based on the data. - */ - update: function update() { - var data = this.data; - var mesh = this.troikaTextMesh; - var entity = this.troikaTextEntity; - - // Update the text mesh - mesh.text = (data.value || '').replace(/\\n/g, '\n').replace(/\\t/g, '\t'); - mesh.textAlign = data.align; - - mesh.anchorX = anchorMapping[data.anchor === 'align' ? data.align : data.anchor] || 'center'; - mesh.anchorY = baselineMapping[data.baseline] || 'middle'; - mesh.color = data.color; - mesh.clipRect = data.clipRect; - mesh.depthOffset = data.depthOffset || 0; - mesh.font = data.font; //TODO allow aframe stock font names - mesh.fontSize = data.fontSize; - mesh.letterSpacing = data.letterSpacing || 0; - mesh.lineHeight = data.lineHeight || 'normal'; - mesh.outlineColor = data.outlineColor; - mesh.outlineWidth = data.outlineWidth; - mesh.overflowWrap = data.overflowWrap; - mesh.textIndent = data.textIndent; - mesh.whiteSpace = data.whiteSpace; - mesh.maxWidth = data.maxWidth; - mesh.sync(); - - // Pass material config down to child entity - if (entity !== this.el) { - var materialAttr = this.el.getAttribute('troika-text-material'); - if (materialAttr) { - entity.setAttribute('material', materialAttr); - } else { - entity.removeAttribute('material'); - } - } - }, - - /** - * Called when a component is removed (e.g., via removeAttribute). - * Generally undoes all modifications to the entity. - */ - remove: function remove() { - // Free memory - this.troikaTextMesh.dispose(); - - // If using sub-entity, remove it - if (this.troikaTextEntity !== this.el) { - this.el.removeChild(this.troikaTextEntity); - } - } - - }); - - var anchorMapping = { - 'left': 'left', - 'center': 'center', - 'right': 'right' - }; - var baselineMapping = { - 'top': 'top', - 'center': 'middle', - 'bottom': 'bottom' - }; - - var mappings = {}; - - // From aframe's primitives.js utilities... - var schema = aframe__default['default'].components[COMPONENT_NAME].schema; - Object.keys(schema).map(function (prop) { - // Hyphenate where there is camelCase. - var attrName = prop.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase(); - mappings[attrName] = COMPONENT_NAME + '.' + prop; - }); - - aframe__default['default'].registerPrimitive('a-troika-text', { - defaultComponents: { - 'troika-text': {} - }, - mappings: mappings - }); - - // Polyfill Three's rename of Math->MathUtils after the super-three fork - (function (ThreedleDum) { - if (!ThreedleDum.MathUtils) { - ThreedleDum.MathUtils = ThreedleDum.Math; - } - })(THREE__namespace); -})(THREE, AFRAME); -/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(22))) - -/***/ }), -/* 22 */ -/***/ (function(module, exports) { - -// shim for using process in browser -var process = module.exports = {}; - -// cached from whatever global is present so that test runners that stub it -// don't break things. But we need to wrap it in a try catch in case it is -// wrapped in strict mode code which doesn't define any globals. It's inside a -// function because try/catches deoptimize in certain engines. - -var cachedSetTimeout; -var cachedClearTimeout; - -function defaultSetTimout() { - throw new Error('setTimeout has not been defined'); -} -function defaultClearTimeout () { - throw new Error('clearTimeout has not been defined'); -} -(function () { - try { - if (typeof setTimeout === 'function') { - cachedSetTimeout = setTimeout; - } else { - cachedSetTimeout = defaultSetTimout; - } - } catch (e) { - cachedSetTimeout = defaultSetTimout; - } - try { - if (typeof clearTimeout === 'function') { - cachedClearTimeout = clearTimeout; - } else { - cachedClearTimeout = defaultClearTimeout; - } - } catch (e) { - cachedClearTimeout = defaultClearTimeout; - } -} ()) -function runTimeout(fun) { - if (cachedSetTimeout === setTimeout) { - //normal enviroments in sane situations - return setTimeout(fun, 0); - } - // if setTimeout wasn't available but was latter defined - if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) { - cachedSetTimeout = setTimeout; - return setTimeout(fun, 0); - } - try { - // when when somebody has screwed with setTimeout but no I.E. maddness - return cachedSetTimeout(fun, 0); - } catch(e){ - try { - // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally - return cachedSetTimeout.call(null, fun, 0); - } catch(e){ - // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error - return cachedSetTimeout.call(this, fun, 0); - } - } - - -} -function runClearTimeout(marker) { - if (cachedClearTimeout === clearTimeout) { - //normal enviroments in sane situations - return clearTimeout(marker); - } - // if clearTimeout wasn't available but was latter defined - if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) { - cachedClearTimeout = clearTimeout; - return clearTimeout(marker); - } - try { - // when when somebody has screwed with setTimeout but no I.E. maddness - return cachedClearTimeout(marker); - } catch (e){ - try { - // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally - return cachedClearTimeout.call(null, marker); - } catch (e){ - // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error. - // Some versions of I.E. have different rules for clearTimeout vs setTimeout - return cachedClearTimeout.call(this, marker); - } - } - - - -} -var queue = []; -var draining = false; -var currentQueue; -var queueIndex = -1; - -function cleanUpNextTick() { - if (!draining || !currentQueue) { - return; - } - draining = false; - if (currentQueue.length) { - queue = currentQueue.concat(queue); - } else { - queueIndex = -1; - } - if (queue.length) { - drainQueue(); - } -} - -function drainQueue() { - if (draining) { - return; - } - var timeout = runTimeout(cleanUpNextTick); - draining = true; - - var len = queue.length; - while(len) { - currentQueue = queue; - queue = []; - while (++queueIndex < len) { - if (currentQueue) { - currentQueue[queueIndex].run(); - } - } - queueIndex = -1; - len = queue.length; - } - currentQueue = null; - draining = false; - runClearTimeout(timeout); -} - -process.nextTick = function (fun) { - var args = new Array(arguments.length - 1); - if (arguments.length > 1) { - for (var i = 1; i < arguments.length; i++) { - args[i - 1] = arguments[i]; - } - } - queue.push(new Item(fun, args)); - if (queue.length === 1 && !draining) { - runTimeout(drainQueue); - } -}; - -// v8 likes predictible objects -function Item(fun, array) { - this.fun = fun; - this.array = array; -} -Item.prototype.run = function () { - this.fun.apply(null, this.array); -}; -process.title = 'browser'; -process.browser = true; -process.env = {}; -process.argv = []; -process.version = ''; // empty string to avoid regexp issues -process.versions = {}; - -function noop() {} - -process.on = noop; -process.addListener = noop; -process.once = noop; -process.off = noop; -process.removeListener = noop; -process.removeAllListeners = noop; -process.emit = noop; -process.prependListener = noop; -process.prependOnceListener = noop; - -process.listeners = function (name) { return [] } - -process.binding = function (name) { - throw new Error('process.binding is not supported'); -}; - -process.cwd = function () { return '/' }; -process.chdir = function (dir) { - throw new Error('process.chdir is not supported'); -}; -process.umask = function() { return 0; }; - - -/***/ }), -/* 23 */ -/***/ (function(module, exports, __webpack_require__) { - "use strict"; @@ -9801,9 +3182,6 @@ if (typeof AFRAME === 'undefined') { throw new Error('Component attempted to register before AFRAME was available.'); } -// third-party -__webpack_require__(21); - // Components __webpack_require__(20); __webpack_require__(19); diff --git a/dist/aframe-gui.min.js b/dist/aframe-gui.min.js index 226b8b9..3acfaf5 100644 --- a/dist/aframe-gui.min.js +++ b/dist/aframe-gui.min.js @@ -1 +1 @@ -!function(t){function e(r){if(i[r])return i[r].exports;var o=i[r]={i:r,l:!1,exports:{}};return t[r].call(o.exports,o,o.exports,e),o.l=!0,o.exports}var i={};e.m=t,e.c=i,e.i=function(t){return t},e.d=function(t,i,r){e.o(t,i)||Object.defineProperty(t,i,{configurable:!1,enumerable:!0,get:r})},e.n=function(t){var i=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(i,"a",i),i},e.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},e.p="",e(e.s=23)}([function(t,e,i){"use strict";if("undefined"==typeof AFRAME)throw new Error("Component attempted to register before AFRAME was available.");AFRAME.registerComponent("bevelbox",{schema:{width:{type:"number",default:1},height:{type:"number",default:1},depth:{type:"number",default:1},topLeftRadius:{type:"number",default:1e-5},topRightRadius:{type:"number",default:1e-5},bottomLeftRadius:{type:"number",default:1e-5},bottomRightRadius:{type:"number",default:1e-5},bevelEnabled:{type:"boolean",default:!0},bevelSegments:{type:"number",default:2},steps:{type:"number",default:1},bevelSize:{type:"number",default:.1},bevelOffset:{type:"number",default:0},bevelThickness:{type:"number",default:.1}},multiple:!1,init:function(){var t=this.el,e=this.data,i=e.width,r=e.height,o=-e.width/2,n=-e.height/2,a=new THREE.Shape;a.moveTo(o,n+e.topLeftRadius),a.lineTo(o,n+r-e.topLeftRadius),a.quadraticCurveTo(o,n+r,o+e.topLeftRadius,n+r),a.lineTo(o+i-e.topRightRadius,n+r),a.quadraticCurveTo(o+i,n+r,o+i,n+r-e.topRightRadius),a.lineTo(o+i,n+e.bottomRightRadius),a.quadraticCurveTo(o+i,n,o+i-e.bottomRightRadius,n),a.lineTo(o+e.bottomLeftRadius,n),a.quadraticCurveTo(o,n,o,n+e.bottomLeftRadius);var s=this.extrude(a);t.setObject3D("mesh",s)},extrude:function(t){var e=(this.el,this.data),i={steps:e.steps,depth:e.depth,bevelEnabled:e.bevelEnabled,bevelThickness:e.bevelThickness,bevelSize:e.bevelSize,bevelOffset:e.bevelOffset,bevelSegments:e.bevelSegments},r=new THREE.ExtrudeGeometry(t,i);return new THREE.Mesh(r,new THREE.MeshStandardMaterial({side:THREE.DoubleSide}))},update:function(t){},remove:function(){},pause:function(){},play:function(){}})},function(t,e,i){"use strict";AFRAME.registerComponent("gui-button",{schema:{on:{default:"click"},value:{type:"string",default:""},fontSize:{type:"number",default:.2},fontFamily:{type:"string",default:""},fontColor:{type:"string",default:key_offwhite},borderColor:{type:"string",default:key_offwhite},focusColor:{type:"string",default:key_orange_light},backgroundColor:{type:"string",default:key_grey},hoverColor:{type:"string",default:key_grey_dark},activeColor:{type:"string",default:key_orange},toggle:{type:"boolean",default:!1},toggleState:{type:"boolean",default:!1}},dependencies:["aframe-troika-text"],init:function(){var t=this.data,e=this.el,i=e.getAttribute("gui-item");if(this.guiItem=i,t.fontSize>20){var r=t.fontSize/750;t.fontSize=r}var o=e.getAttribute("gui-interactable");this.guiInteractable=o,e.setAttribute("geometry","primitive: plane; \n height: "+i.height+"; \n width: "+i.width+";\n "),e.setAttribute("material","shader: flat; \n transparent: true; \n opacity: 0.5; \n side:double; \n color:"+t.backgroundColor+";\n ");var n=document.createElement("a-entity");if(i.bevel){var a=1*i.bevelSize,s=i.bevelThickness;n.setAttribute("bevelbox","width: "+(i.width-i.width*a)+"; \n height: "+(i.height-i.height*a)+"; \n depth: "+(i.baseDepth-i.baseDepth*s)+";\n bevelThickness: 0;\n bevelSize: "+i.bevelSize+";\n "),n.setAttribute("position","0 0 0")}else n.setAttribute("geometry","primitive: box; \n width: "+i.width+"; \n height: "+i.height+"; \n depth: "+i.baseDepth+";\n "),n.setAttribute("position","0 0 "+i.baseDepth/2);n.setAttribute("rotation","0 0 0"),n.setAttribute("material","shader: flat; \n opacity: 1; \n side:double; \n color: "+t.borderColor+"\n "),e.appendChild(n),this.buttonContainer=n;var l=document.createElement("a-entity");if(i.bevel){var a=1*i.bevelSize,s=i.bevelThickness;l.setAttribute("bevelbox","width: "+(i.width-i.gap-(i.width-i.gap)*a)+"; \n height: "+(i.height-i.gap-(i.height-i.gap)*a)+"; \n depth: "+(i.depth-i.depth*s)+";\n bevelThickness: "+i.bevelThickness+";\n bevelSize: "+i.bevelSize+";\n "),l.setAttribute("position","0 0 0")}else l.setAttribute("geometry","primitive: box; \n width: "+(i.width-i.gap)+"; \n height: "+(i.height-i.gap)+"; \n depth: "+i.depth+";"),l.setAttribute("position","0 0 "+i.depth/2);l.setAttribute("material","shader: flat; \n opacity: 1; \n side:double; \n color: "+(t.toggleState?t.activeColor:t.backgroundColor)+"\n "),l.setAttribute("rotation","0 0 0"),e.appendChild(l),this.buttonEntity=l,this.setText(t.value),e.addEventListener("mouseenter",function(e){l.removeAttribute("animation__leave"),t.toggle||l.setAttribute("animation__enter","property: material.color; from: "+t.backgroundColor+"; to:"+t.hoverColor+"; dur:200;")}),e.addEventListener("mouseleave",function(e){t.toggle||(l.removeAttribute("animation__click"),l.setAttribute("animation__leave","property: material.color; from: "+t.hoverColor+"; to:"+t.backgroundColor+"; dur:200; easing: easeOutQuad;")),l.removeAttribute("animation__enter")}),e.addEventListener("focus",function(e){n.setAttribute("material","color",""+t.focusColor)}),e.addEventListener("blur",function(e){n.setAttribute("material","color",""+t.borderColor),t.toggle||(l.removeAttribute("animation__click"),l.setAttribute("animation__leave","property: material.color; from: "+t.hoverColor+"; to:"+t.backgroundColor+"; dur:200; easing: easeOutQuad;")),l.removeAttribute("animation__enter")}),e.addEventListener(t.on,function(i){if(t.toggle){var r=e.components["gui-button"];r.setActiveState(!r.data.toggleState)}else l.setAttribute("animation__click","property: material.color; from: "+t.activeColor+"; to:"+t.backgroundColor+"; dur:400; easing: easeOutQuad;");var n=o.clickAction,a=window[n];"function"==typeof a&&a(i)}),e.addEventListener("keyup",function(i){i.isComposing||229===i.keyCode||(13!=i.keyCode&&32!=i.keyCode||e.emit(t.on),i.preventDefault())}),e.setAttribute("role","button"),e.setAttribute("tabindex","0"),e.setAttribute("aria-label",t.value)},play:function(){},update:function(t){var e=this.data,i=this.el,r=i.getAttribute("gui-item");if(this.guiItem=r,i.setAttribute("geometry","primitive: plane; \n height: "+r.height+"; \n width: "+r.width+";\n "),i.setAttribute("material","shader: flat; \n transparent: true; \n opacity: 0.5; \n side:double; \n color:"+e.backgroundColor+";\n "),r.bevel){var o=1*r.bevelSize,n=r.bevelThickness;this.buttonContainer.setAttribute("bevelbox","width: "+(r.width-r.width*o)+"; \n height: "+(r.height-r.height*o)+"; \n depth: "+(r.baseDepth-r.baseDepth*n)+";\n bevelThickness: 0;\n bevelSize: "+r.bevelSize+";\n "),this.buttonContainer.setAttribute("position","0 0 0")}else this.buttonContainer.setAttribute("geometry","primitive: box; \n width: "+r.width+"; \n height: "+r.height+"; \n depth: "+r.baseDepth+";\n "),this.buttonContainer.setAttribute("position","0 0 "+r.baseDepth/2);if(this.buttonContainer.setAttribute("material","shader: flat; \n opacity: 1; \n side:double; \n color: "+e.borderColor+"\n "),r.bevel){var o=1*r.bevelSize,n=r.bevelThickness;this.buttonEntity.setAttribute("bevelbox","width: "+(r.width-r.gap-(r.width-r.gap)*o)+"; \n height: "+(r.height-r.gap-(r.height-r.gap)*o)+"; \n depth: "+(r.depth-r.depth*n)+";\n bevelThickness: "+r.bevelThickness+";\n bevelSize: "+r.bevelSize+";\n "),this.buttonEntity.setAttribute("position","0 0 0")}else this.buttonEntity.setAttribute("geometry","primitive: box; \n width: "+(r.width-r.gap)+"; \n height: "+(r.height-r.gap)+"; \n depth: "+r.depth+";\n "),this.buttonEntity.setAttribute("position","0 0 "+r.depth/2);if(this.buttonEntity.setAttribute("material","shader: flat; \n opacity: 1; \n side:double; \n color: "+(e.toggleState?e.activeColor:e.backgroundColor)+"\n "),this.textEntity){console.log("has textEntity: "+this.textEntity);var a=this.textEntity;a.parentNode.removeChild(a),this.setText(this.data.value)}else console.log("no textEntity!")},setActiveState:function(t){this.data.toggleState=t,t?(console.log("active, about to set active color"),this.buttonEntity.setAttribute("material","color",this.data.activeColor)):(console.log("not active, about to set background color"),this.buttonEntity.setAttribute("material","color",this.data.backgroundColor))},setText:function(t){var e=this.data,i=this.el,r=i.getAttribute("gui-item"),o=document.createElement("a-entity");this.textEntity=o,o.setAttribute("troika-text","value: "+t+"; \n align:center; \n anchor:center; \n baseline:center;\n letterSpacing:0;\n color:"+e.fontColor+"; \n font:"+e.fontFamily+";\n fontSize:"+e.fontSize+";\n depthOffset:1;\n maxWidth:"+r.width/1.05+";\n "),o.setAttribute("troika-text-material","shader: flat;"),r.bevel?o.setAttribute("position","0 0 "+(r.depth+r.bevelThickness/2+.05)):o.setAttribute("position","0 0 "+(r.depth/2+.05)),this.buttonEntity.appendChild(o)}}),AFRAME.registerPrimitive("a-gui-button",{defaultComponents:{"gui-interactable":{},"gui-item":{type:"button"},"gui-button":{}},mappings:{onclick:"gui-interactable.clickAction",onhover:"gui-interactable.hoverAction","key-code":"gui-interactable.keyCode",width:"gui-item.width",height:"gui-item.height",depth:"gui-item.depth","base-depth":"gui-item.baseDepth",gap:"gui-item.gap",radius:"gui-item.radius",margin:"gui-item.margin",bevel:"gui-item.bevel","bevel-segments":"gui-item.bevelSegments",steps:"gui-item.steps","bevel-size":"gui-item.bevelSize","bevel-offset":"gui-item.bevelOffset","bevel-thickness":"gui-item.bevelThickness",on:"gui-button.on",value:"gui-button.value","font-size":"gui-button.fontSize","font-family":"gui-button.fontFamily","font-color":"gui-button.fontColor","border-color":"gui-button.borderColor","focus-color":"gui-button.focusColor","background-color":"gui-button.backgroundColor","hover-color":"gui-button.hoverColor","active-color":"gui-button.activeColor",toggle:"gui-button.toggle","toggle-state":"gui-button.toggleState"}})},function(t,e,i){"use strict";AFRAME.registerComponent("gui-circle-loader",{schema:{loaded:{type:"number",default:.5},fontSize:{type:"number",default:.2},fontFamily:{type:"string",default:""},fontColor:{type:"string",default:key_grey},backgroundColor:{type:"string",default:key_offwhite},activeColor:{type:"string",default:key_orange}},init:function(){var t=this.data,e=this.el,i=e.getAttribute("gui-item");if(this.guiItem=i,t.fontSize>20){var r=t.fontSize/750;t.fontSize=r}e.setAttribute("geometry","primitive: plane; height: "+i.height+"; width: "+i.height+";"),e.setAttribute("material","shader: flat; transparent: true; opacity: 1; side:back; color:"+t.backgroundColor+";");var o=document.createElement("a-entity");o.setAttribute("geometry","primitive: cylinder; radius: "+i.height/2+"; height: 0.02;"),o.setAttribute("material","shader: flat; opacity: 1; side:double; color: "+t.backgroundColor),o.setAttribute("rotation","90 0 0"),o.setAttribute("position","0 0 0.01"),e.appendChild(o);var n=document.createElement("a-ring");n.setAttribute("material","shader: flat; opacity: 1; side:double; color: "+t.activeColor),n.setAttribute("radius-inner",""+i.height/3),n.setAttribute("radius-outer",""+i.height/2),n.setAttribute("theta-start","90"),n.setAttribute("theta-length",""+-360*t.loaded),n.setAttribute("rotation","0 0 0"),n.setAttribute("position","0 0 0.04"),n.id="loader_ring",e.appendChild(n),this.setText(t.loaded)},play:function(){},update:function(t){this.data,this.el;if(this.textEntity){console.log("has textEntity: "+this.textEntity);var e=this.textEntity;e.parentNode.removeChild(e),this.setText(this.data.loaded)}else console.log("no textEntity!")},setText:function(t){var e=document.createElement("a-entity");this.textEntity=e,e.setAttribute("troika-text","value: "+Math.round(100*t)+"; \n align:center; \n anchor:center; \n baseline:center;\n letterSpacing:0;\n color:"+this.data.fontColor+";\n font:"+this.data.fontFamily+";\n fontSize:"+this.data.fontSize+";\n depthOffset:1;\n maxWidth:"+this.guiItem.width/1.05+";\n "),e.setAttribute("position","0 0 0.05"),this.el.appendChild(e)}}),AFRAME.registerPrimitive("a-gui-circle-loader",{defaultComponents:{"gui-item":{type:"circle-loader"},"gui-circle-loader":{}},mappings:{width:"gui-item.width",height:"gui-item.height",margin:"gui-item.margin",loaded:"gui-circle-loader.loaded","font-size":"gui-circle-loader.fontSize","font-family":"gui-circle-loader.fontFamily","font-color":"gui-circle-loader.fontColor","background-color":"gui-circle-loader.backgroundColor","active-color":"gui-circle-loader.activeColor"}})},function(t,e,i){"use strict";AFRAME.registerComponent("gui-circle-timer",{schema:{countDown:{type:"number",default:10},fontSize:{type:"number",default:.2},fontFamily:{type:"string",default:""},fontColor:{type:"string",default:key_grey},borderColor:{type:"string",default:key_grey},backgroundColor:{type:"string",default:key_offwhite},activeColor:{type:"string",default:key_orange}},init:function(){var t=this.data,e=this.el,i=e.getAttribute("gui-item");this.guiItem=i;var r=e.getAttribute("gui-interactable");if(console.log("in timer callback, guiInteractable: "+JSON.stringify(r)),t.fontSize>20){var o=t.fontSize/750;t.fontSize=o}e.setAttribute("geometry","primitive: plane; height: "+i.height+"; width: "+i.height+";"),e.setAttribute("material","shader: flat; transparent: true; opacity: 1; side:back; color:"+t.backgroundColor+";");var n=document.createElement("a-entity");n.setAttribute("geometry","primitive: cylinder; radius: "+i.height/2+"; height: 0.02;"),n.setAttribute("material","shader: flat; opacity: 1; side:double; color: "+t.backgroundColor),n.setAttribute("rotation","90 0 0"),n.setAttribute("position","0 0 0.01"),e.appendChild(n);var a=document.createElement("a-ring");a.setAttribute("material","shader: flat; opacity: 1; side:double; color: "+t.borderColor),a.setAttribute("radius-inner",""+i.height/3),a.setAttribute("radius-outer",""+i.height/2),a.setAttribute("theta-start","-1"),a.setAttribute("theta-length","3"),a.setAttribute("position","0 0 0.04"),e.appendChild(a);var s=document.createElement("a-ring");s.setAttribute("material","shader: flat; opacity: 1; side:double; color: "+t.borderColor),s.setAttribute("radius-inner",""+i.height/3),s.setAttribute("radius-outer",""+i.height/2),s.setAttribute("theta-start","89"),s.setAttribute("theta-length","3"),s.setAttribute("position","0 0 0.04"),e.appendChild(s);var l=document.createElement("a-ring");l.setAttribute("material","shader: flat; opacity: 1; side:double; color: "+t.borderColor),l.setAttribute("radius-inner",""+i.height/3),l.setAttribute("radius-outer",""+i.height/2),l.setAttribute("theta-start","179"),l.setAttribute("theta-length","3"),l.setAttribute("position","0 0 0.04"),e.appendChild(l);var u=document.createElement("a-ring");u.setAttribute("material","shader: flat; opacity: 1; side:double; color: "+t.borderColor),u.setAttribute("radius-inner",""+i.height/3),u.setAttribute("radius-outer",""+i.height/2),u.setAttribute("theta-start","269"),u.setAttribute("theta-length","3"),u.setAttribute("position","0 0 0.04"),e.appendChild(u);var d=document.createElement("a-ring");d.setAttribute("material","shader: flat; opacity: 1; side:double; color: "+t.activeColor),d.setAttribute("radius-inner",""+i.height/3),d.setAttribute("radius-outer",""+i.height/2),d.setAttribute("theta-start","0"),d.setAttribute("theta-length","0"),d.setAttribute("rotation","0 180 90"),d.setAttribute("position","0 0 0.03"),e.appendChild(d),this.timerRing=d;this.initCount=t.countDown;this.setText(t.countDown)},update:function(t){var e=this.data,i=this.el;if(0!==Object.keys(t).length&&e.countDown!==t.countDown){i.getObject3D("mesh").material.color=e.color;var r=e.countDown,o=this.initCount,n=Math.round(100*(o-r)/o)/100*360;this.timerRing.setAttribute("theta-length",n),this.textEntity.setAttribute("troika-text","value: "+e.countDown+";"),1==r&&console.log("fire callback on the last second")}},setText:function(t){var e=document.createElement("a-entity");this.textEntity=e,e.setAttribute("troika-text","value: "+t+"; \n align:center; \n anchor:center; \n baseline:center;\n letterSpacing:0;\n color:"+this.data.fontColor+";\n font:"+this.data.fontFamily+";\n fontSize:"+this.data.fontSize+";\n depthOffset:1;\n maxWidth:"+this.guiItem.width/1.05+";\n "),e.setAttribute("position","0 0 0.05"),this.el.appendChild(e)},callback:function(){var t=this.el.getAttribute("gui-interactable"),e=t.clickAction;console.log("in timer callback, guiInteractable: "+JSON.stringify(t)),console.log("in button, clickActionFunctionName: "+e);var i=window[e];"function"==typeof i&&i()}}),AFRAME.registerPrimitive("a-gui-circle-timer",{defaultComponents:{"gui-item":{type:"circle-timer"},"gui-circle-timer":{}},mappings:{width:"gui-item.width",height:"gui-item.height",margin:"gui-item.margin","count-down":"gui-circle-timer.countDown","font-size":"gui-circle-timer.fontSize","font-family":"gui-circle-timer.fontFamily","font-color":"gui-circle-timer.fontColor","border-color":"gui-circle-timer.borderColor","background-color":"gui-circle-timer.backgroundColor","active-color":"gui-circle-timer.activeColor",callback:"gui-interactable.clickAction"}})},function(t,e,i){"use strict";AFRAME.registerComponent("gui-cursor",{schema:{color:{type:"string",default:key_white},hoverColor:{type:"string",default:key_white},activeColor:{type:"string",default:key_orange},distance:{type:"number",default:-1},design:{type:"string",default:"dot"}},init:function(){var t=this.cursor=this.el.getAttribute("cursor"),e=this.fuse=t.fuse,i=t.fuseTimeout,r=this.el,o=this.data,n=200,a=i-n;if(AFRAME.utils.entity.setComponentProperty(r,"raycaster.interval","500"),console.log("fuse: "+e+", fuseTimeout: "+i),"dot"==o.design){r.setAttribute("geometry","primitive: ring; radiusInner:0.000001; radiusOuter:0.025"),r.setAttribute("material","color: "+o.color+"; shader: flat; opacity:1;"),r.setAttribute("position","0 0 "+o.distance),r.setAttribute("animation__radiusInnerIn","property: geometry.radiusInner; from: 0.000001; to:0.0225; dur:"+n+"; easing:linear; startEvents: hovergui"),r.setAttribute("animation__radiusOuterIn","property: geometry.radiusOuter; from: 0.025; to:0.0275; dur:"+n+"; easing:linear; startEvents: hovergui"),r.setAttribute("animation__colorIn","property: material.color; from: "+o.color+"; to:"+o.hoverColor+"; dur:"+n+"; easing:linear; startEvents: hovergui"),r.setAttribute("animation__radiusInnerOut","property: geometry.radiusInner; from: 0.0225; to:0.000001; dur:"+n+"; easing:linear; startEvents: leavegui"),r.setAttribute("animation__radiusOuterOut","property: geometry.radiusOuter; from: 0.0275; to:0.025; dur:"+n+"; easing:linear; startEvents: leavegui"),r.setAttribute("animation__colorOut","property: material.color; from: "+o.hoverColor+"; to:"+o.color+"; dur:"+n+"; easing:linear; startEvents: leavegui"),r.setAttribute("animation__scale","property: scale; from: 1 1 1; to:1.25 1.25 1.25; dur:200; easing:easeInQuad; startEvents: click");var s=document.createElement("a-entity");if(s.setAttribute("geometry","primitive: ring; radiusInner:0.0275; radiusOuter:0.03; thetaLength:360"),s.setAttribute("material","color: #000000; shader: flat; opacity:0.25;"),s.setAttribute("position","0 0 0"),s.setAttribute("animation__radiusInnerIn","property: geometry.radiusInner; from: 0.0275; to:0.03; dur:"+n+"; easing:linear; startEvents: hovergui"),s.setAttribute("animation__radiusOuterIn","property: geometry.radiusOuter; from: 0.03; to:0.0325; dur:"+n+"; easing:linear; startEvents: hovergui"),s.setAttribute("animation__radiusInnerOut","property: geometry.radiusInner; from: 0.03; to:0.0275; dur:"+n+"; easing:linear; startEvents: leavegui"),s.setAttribute("animation__radiusOuterOut","property: geometry.radiusOuter; from: 0.0325; to:0.03; dur:"+n+"; easing:linear; startEvents: leavegui"),r.appendChild(s),this.cursorShadow=s,e){var l=document.createElement("a-entity");l.setAttribute("geometry","primitive: ring; radiusInner:0.03; radiusOuter:0.0375; thetaLength:0"),l.setAttribute("material","color: "+o.activeColor+"; shader: flat; opacity:1;"),l.setAttribute("position","0 0 0"),l.setAttribute("animation","property: geometry.thetaLength; from: 0; to:360; dur:"+a+"; delay: "+n+"; easing:linear; autoplay:false;"),r.appendChild(l),this.fuseLoader=l}}else if("ring"==o.design){r.setAttribute("geometry","primitive: ring; radiusInner:0.0225; radiusOuter:0.0275"),r.setAttribute("material","color: "+o.color+"; shader: flat; opacity:1;"),r.setAttribute("position","0 0 "+o.distance),r.setAttribute("animation__radiusInnerIn","property: geometry.radiusInner; from: 0.0225; to:0.025; dur:"+n+"; easing:linear; startEvents: hovergui"),r.setAttribute("animation__radiusOuterIn","property: geometry.radiusOuter; from: 0.0275; to:0.0325; dur:"+n+"; easing:linear; startEvents: hovergui"),r.setAttribute("animation__colorIn","property: material.color; from: "+o.color+"; to:"+o.hoverColor+"; dur:"+n+"; easing:linear; startEvents: hovergui"),r.setAttribute("animation__radiusInnerOut","property: geometry.radiusInner; from: 0.025; to:0.0225; dur:"+n+"; easing:linear; startEvents: leavegui"),r.setAttribute("animation__radiusOuterOut","property: geometry.radiusOuter; from: 0.0325; to:0.0275; dur:"+n+"; easing:linear; startEvents: leavegui"),r.setAttribute("animation__colorOut","property: material.color; from: "+o.hoverColor+"; to:"+o.color+"; dur:"+n+"; easing:linear; startEvents: leavegui"),r.setAttribute("animation__scale","property: scale; from: 1 1 1; to:1.25 1.25 1.25; dur:200; easing:easeInQuad; startEvents: click");var s=document.createElement("a-entity");if(s.setAttribute("geometry","primitive: ring; radiusInner:0.03; radiusOuter:0.0325; thetaLength:360"),s.setAttribute("material","color: #000000; shader: flat; opacity:0.25;"),s.setAttribute("position","0 0 0"),s.setAttribute("animation__radiusInnerIn","property: geometry.radiusInner; from: 0.03; to:0.0325; dur:"+n+"; easing:linear; startEvents: hovergui"),s.setAttribute("animation__radiusOuterIn","property: geometry.radiusOuter; from: 0.0325; to:0.0375; dur:"+n+"; easing:linear; startEvents: hovergui"),s.setAttribute("animation__radiusInnerOut","property: geometry.radiusInner; from: 0.0325; to:0.03; dur:"+n+"; easing:linear; startEvents: leavegui"),s.setAttribute("animation__radiusOuterOut","property: geometry.radiusOuter; from: 0.0375; to:0.0325; dur:"+n+"; easing:linear; startEvents: leavegui"),r.appendChild(s),this.cursorShadow=s,e){var l=document.createElement("a-entity");l.setAttribute("geometry","primitive: ring; radiusInner:0.035; radiusOuter:0.0425; thetaLength:0"),l.setAttribute("material","color: "+o.activeColor+"; shader: flat; opacity:1;"),l.setAttribute("position","0 0 0"),l.setAttribute("animation","property: geometry.thetaLength; from: 0; to:360; dur:"+a+"; delay: "+n+"; easing:linear; autoplay:false;"),r.appendChild(l),this.fuseLoader=l}}else if("reticle"==o.design){r.setAttribute("geometry","primitive: ring; radiusInner:0.000001; radiusOuter:0.0125; thetaLength:180;"),r.setAttribute("material","color: "+o.color+"; shader: flat; opacity:1;"),r.setAttribute("position","0 0 "+o.distance),r.setAttribute("animation__opacityIn","property: material.opacity; from: 1; to: 0; dur:"+n+"; easing:linear; startEvents: hovergui"),r.setAttribute("animation__opacityOut","property: material.opacity; from: 0; to: 1; dur:"+n+"; easing:linear; startEvents: leavegui");var u=document.createElement("a-entity");u.setAttribute("geometry","primitive: ring; radiusInner:0.000001; radiusOuter:0.0125; thetaLength:180; thetaStart:180;"),u.setAttribute("material","color: #000000; shader: flat; opacity:0.25;"),u.setAttribute("position","0 0 0"),u.setAttribute("animation__opacityIn","property: material.opacity; from: 0.25; to: 0; dur:"+n+"; easing:linear; startEvents: hovergui"),u.setAttribute("animation__opacityOut","property: material.opacity; from: 0; to: 0.25; dur:"+n+"; easing:linear; startEvents: leavegui"),r.appendChild(u),this.cursorCenter=u;var s=document.createElement("a-entity");s.setAttribute("geometry","primitive: ring; radiusInner:0.0125; radiusOuter:0.0145"),s.setAttribute("material","color: #000000; shader: flat; opacity:0.25;"),s.setAttribute("position","0 0 0"),s.setAttribute("animation__colorIn","property: material.color; from: #000000; to: "+o.color+"; dur:"+n+"; easing:linear; startEvents: hovergui"),s.setAttribute("animation__opacityIn","property: material.opacity; from: 0.25; to: 1; dur:"+n+"; easing:linear; startEvents: hovergui"),s.setAttribute("animation__colorOut","property: material.color; from: "+o.color+"; to: #000000; dur:"+n+"; easing:linear; startEvents: leavegui"),s.setAttribute("animation__opacityOut","property: material.opacity; from: 1; to: 0.25; dur:"+n+"; easing:linear; startEvents: leavegui"),r.appendChild(s),this.cursorShadow=s;var d=document.createElement("a-entity");d.setAttribute("geometry","primitive: plane; width:0.005; height:0.005;"),d.setAttribute("material","color: #000000; shader: flat; opacity:0.25;"),d.setAttribute("position","-0.0325 0.0325 0"),r.appendChild(d),this.cursorShadowTL=d;var c=document.createElement("a-entity");c.setAttribute("geometry","primitive: plane; width:0.005; height:0.005;"),c.setAttribute("material","color: #000000; shader: flat; opacity:0.25;"),c.setAttribute("position","-0.0325 -0.0325 0"),r.appendChild(c),this.cursorShadowBL=c;var h=document.createElement("a-entity");h.setAttribute("geometry","primitive: plane; width:0.005; height:0.005;"),h.setAttribute("material","color: #000000; shader: flat; opacity:0.25;"),h.setAttribute("position","0.0325 0.0325 0"),r.appendChild(h),this.cursorShadowTR=h;var f=document.createElement("a-entity");f.setAttribute("geometry","primitive: plane; width:0.005; height:0.005;"),f.setAttribute("material","color: #000000; shader: flat; opacity:0.25;"),f.setAttribute("position","0.0325 -0.0325 0"),r.appendChild(f),this.cursorShadowBR=f;var p=document.createElement("a-entity");p.setAttribute("geometry","primitive: plane; width:0.015; height:0.0035;"),p.setAttribute("material","color: "+o.color+"; shader: flat; opacity:1;"),p.setAttribute("position","-0.03 0.0375 0"),r.appendChild(p),this.cursorBoundTL=p;var g=document.createElement("a-entity");g.setAttribute("geometry","primitive: plane; width:0.0035; height:0.015;"),g.setAttribute("material","color: "+o.color+"; shader: flat; opacity:1;"),g.setAttribute("position","-0.0375 0.03 0"),r.appendChild(g),this.cursorBoundTL2=g;var m=document.createElement("a-entity");m.setAttribute("geometry","primitive: plane; width:0.015; height:0.0035;"),m.setAttribute("material","color: "+o.color+"; shader: flat; opacity:1;"),m.setAttribute("position","0.03 0.0375 0"),r.appendChild(m),this.cursorBoundTR=m;var v=document.createElement("a-entity");v.setAttribute("geometry","primitive: plane; width:0.0035; height:0.015;"),v.setAttribute("material","color: "+o.color+"; shader: flat; opacity:1;"),v.setAttribute("position","0.0375 0.03 0"),r.appendChild(v),this.cursorBoundTR2=v;var b=document.createElement("a-entity");b.setAttribute("geometry","primitive: plane; width:0.015; height:0.0035;"),b.setAttribute("material","color: "+o.color+"; shader: flat; opacity:1;"),b.setAttribute("position","-0.03 -0.0375 0"),r.appendChild(b),this.cursorBoundBL=b;var y=document.createElement("a-entity");y.setAttribute("geometry","primitive: plane; width:0.0035; height:0.015;"),y.setAttribute("material","color: "+o.color+"; shader: flat; opacity:1;"),y.setAttribute("position","-0.0375 -0.03 0"),r.appendChild(y),this.cursorBoundBL2=y;var A=document.createElement("a-entity");A.setAttribute("geometry","primitive: plane; width:0.015; height:0.0035;"),A.setAttribute("material","color: "+o.color+"; shader: flat; opacity:1;"),A.setAttribute("position","0.03 -0.0375 0"),r.appendChild(A),this.cursorBoundBR=A;var w=document.createElement("a-entity");if(w.setAttribute("geometry","primitive: plane; width:0.0035; height:0.015;"),w.setAttribute("material","color: "+o.color+"; shader: flat; opacity:1;"),w.setAttribute("position","0.0375 -0.03 0"),r.appendChild(w),this.cursorBoundBR2=w,e){var l=document.createElement("a-entity");l.setAttribute("geometry","primitive: plane; width:0.000001; height:0.01;"),l.setAttribute("material","color: "+o.activeColor+"; shader: flat; opacity:1;"),l.setAttribute("position","0 -0.05 0"),l.setAttribute("animation","property: geometry.width; from: 0; to: 0.075; dur:"+a+"; delay:"+n+"; easing:linear; autoplay:false;"),r.appendChild(l),this.fuseLoader=l}}else if("cross"==o.design){r.setAttribute("geometry","primitive: ring; radiusInner:0.035; radiusOuter:0.0375"),r.setAttribute("material","color: "+o.color+"; shader: flat; opacity:1;"),r.setAttribute("position","0 0 "+o.distance),r.setAttribute("animation__radiusInnerIn","property: geometry.radiusInner; from: 0.035; to: 0.0315; dur:"+n+"; easing:linear; startEvents: hovergui"),r.setAttribute("animation__radiusInnerOut","property: geometry.radiusInner; from: 0.0315; to: 0.035; dur:"+n+"; easing:linear; startEvents: leavegui");var s=document.createElement("a-entity");s.setAttribute("geometry","primitive: ring; radiusInner:0.0375; radiusOuter:0.04; thetaLength:360"),s.setAttribute("material","color: #000000; shader: flat; opacity:0.25;"),s.setAttribute("position","0 0 0"),r.appendChild(s),this.cursorShadow=s;var k=document.createElement("a-entity");k.setAttribute("geometry","primitive: plane; width:0.0035; height:0.01875"),k.setAttribute("material","color: "+o.color+"; shader: flat; opacity:1;"),k.setAttribute("position","0 0.028125 0"),k.setAttribute("animation__widthIn","property: geometry.width; from: 0.0035; to: 0.007; dur:"+a+"; easing:linear; startEvents: hovergui"),k.setAttribute("animation__widthOut","property: geometry.width; from: 0.007; to: 0.0035; dur:"+a+"; easing:linear; startEvents: leavegui"),r.appendChild(k),this.cursorVerticalTop=k;var C=document.createElement("a-entity");C.setAttribute("geometry","primitive: plane; width:0.0035; height:0.01875"),C.setAttribute("material","color: "+o.color+"; shader: flat; opacity:1;"),C.setAttribute("position","0 -0.028125 0"),C.setAttribute("animation__widthIn","property: geometry.width; from: 0.0035; to: 0.007; dur:"+a+"; easing:linear; startEvents: hovergui"),C.setAttribute("animation__widthOut","property: geometry.width; from: 0.007; to: 0.0035; dur:"+a+"; easing:linear; startEvents: leavegui"),r.appendChild(C),this.cursorVerticalBottom=C;var x=document.createElement("a-entity");x.setAttribute("geometry","primitive: plane; width:0.01875; height:0.0035"),x.setAttribute("material","color: "+o.color+"; shader: flat; opacity:1;"),x.setAttribute("position","-0.028125 0 0"),x.setAttribute("animation__heightIn","property: geometry.height; from: 0.0035; to: 0.007; dur:"+a+"; easing:linear; startEvents: hovergui"),x.setAttribute("animation__heightOut","property: geometry.height; from: 0.007; to: 0.0035; dur:"+a+"; easing:linear; startEvents: leavegui"),r.appendChild(x),this.cursorHorizontalLeft=x;var S=document.createElement("a-entity");if(S.setAttribute("geometry","primitive: plane; width:0.01875; height:0.0035"),S.setAttribute("material","color: "+o.color+"; shader: flat; opacity:1;"),S.setAttribute("position","0.028125 0 0"),S.setAttribute("animation__heightIn","property: geometry.height; from: 0.0035; to: 0.007; dur:"+a+"; easing:linear; startEvents: hovergui"),S.setAttribute("animation__heightOut","property: geometry.height; from: 0.007; to: 0.0035; dur:"+a+"; easing:linear; startEvents: leavegui"),r.appendChild(S),this.cursorHorizontalRight=S,e){var l=document.createElement("a-entity");l.setAttribute("geometry","primitive: ring; radiusInner:0.0415; radiusOuter:0.0485; thetaLength:0"),l.setAttribute("material","color: "+o.activeColor+"; shader: flat; opacity:1;"),l.setAttribute("position","0 0 0"),l.setAttribute("animation","property: geometry.thetaLength; from: 0; to: 360; dur:"+a+"; delay:"+n+"; easing:linear; autoplay:false;"),r.appendChild(l),this.fuseLoader=l}}r.addEventListener("mouseenter",function(){console.log("in gui-cursor mousenter, el: "+r),r.emit("hovergui"),"dot"==o.design||"ring"==o.design?s.emit("hovergui"):"cross"==o.design?(s.emit("hovergui"),k.emit("hovergui"),C.emit("hovergui"),x.emit("hovergui"),S.emit("hovergui")):"reticle"==o.design&&(centerHoverAniOpacity.emit("hovergui"),cursorHoverAniColor.emit("hovergui"),cursorHoverAniOpacity.emit("hovergui"))}),r.addEventListener("mouseleave",function(){console.log("in gui-cursor mouseleave, el: "+r),r.emit("leavegui"),"dot"==o.design||"ring"==o.design?s.emit("leavegui"):"cross"==o.design?(k.emit("leavegui"),C.emit("leavegui"),x.emit("leavegui"),S.emit("leavegui")):"reticle"==o.design&&(centerHoverAniOpacity.emit("leavegui"),cursorHoverAniColor.emit("leavegui"),cursorHoverAniOpacity.emit("leavegui")),e&&(l.object3D.el.components.animation.animation.pause(),l.object3D.el.components.animation.animation.seek(0)),r.setAttribute("scale","1 1 1")}),e&&r.addEventListener("fusing",function(){l.object3D.el.components.animation.animation.play()}),r.addEventListener("stateremoved",function(t){console.log("evt.detail "+t.detail),"cursor-fusing"===t.detail.state||"cursor-fusing"===t.detail?"dot"==o.design||"ring"==o.design||"cross"==o.design?e&&(l.object3D.el.components.animation.animation.pause(),l.object3D.el.components.animation.animation.seek(0),AFRAME.utils.entity.setComponentProperty(l,"geometry.thetaLength","0")):"reticle"==o.design&&e&&(l.object3D.el.components.animation.animation.pause(),l.object3D.el.components.animation.animation.seek(0),AFRAME.utils.entity.setComponentProperty(l,"geometry.width","0.000001")):"cursor-hovering"!==t.detail.state&&"cursor-hovering"!==t.detail||("dot"==o.design||"ring"==o.design?(AFRAME.utils.entity.setComponentProperty(this,"scale","1 1 1"),e&&AFRAME.utils.entity.setComponentProperty(l,"geometry.thetaLength","0")):"cross"==o.design?e&&AFRAME.utils.entity.setComponentProperty(l,"geometry.thetaLength","0"):"reticle"==o.design&&e&&AFRAME.utils.entity.setComponentProperty(l,"geometry.width","0.000001"))})},update:function(){},tick:function(){},remove:function(){},pause:function(){},play:function(){}}),AFRAME.registerPrimitive("a-gui-cursor",{defaultComponents:{cursor:{},"gui-cursor":{}},mappings:{fuse:"cursor.fuse","fuse-timeout":"cursor.fuseTimeout",color:"gui-cursor.color","hover-color":"gui-cursor.hoverColor","active-color":"gui-cursor.activeColor",distance:"gui-cursor.distance",design:"gui-cursor.design"}})},function(t,e,i){"use strict";var r=function(t,e){new MutationObserver(function(t,i){t.forEach(function(t){console.log(t),t.addedNodes.length&&e(t.target,t.addedNodes)})}).observe(t,{childList:!0})};AFRAME.registerComponent("gui-flex-container",{schema:{flexDirection:{type:"string",default:"row"},justifyContent:{type:"string",default:"flexStart"},alignItems:{type:"string",default:"flexStart"},itemPadding:{type:"number",default:0},opacity:{type:"number",default:0},isTopContainer:{type:"boolean",default:!1},panelColor:{type:"string",default:key_grey},panelRounded:{type:"number",default:.05},styles:{fontFamily:{type:"string",default:"Helvetica"},fontColor:{type:"string",default:key_offwhite},borderColor:{type:"string",default:key_offwhite},backgroundColor:{type:"string",default:key_grey},hoverColor:{type:"string",default:key_grey_dark},activeColor:{type:"string",default:key_orange},handleColor:{type:"string",default:key_offwhite}}},init:function(){console.log("in aframe-gui-component init for: "+this.el.getAttribute("id"));var t=this.el.getAttribute("gui-item");this.data.isTopContainer?this.setBackground():this.el.setAttribute("rounded","height: "+t.height+"; width: "+t.width+"; opacity: "+this.data.opacity+"; color: "+this.data.panelColor+"; radius:"+this.data.panelRounded+"; depthWrite:false; polygonOffset:true; polygonOffsetFactor: 1;"),this.children=this.el.getChildEntities();var e=0,i=0;if("row"==this.data.flexDirection){if("flexStart"==this.data.justifyContent)e=0;else if("center"==this.data.justifyContent||"flexEnd"==this.data.justifyContent){for(var o=0,n=0;n0){console.log("panel position: "+JSON.stringify(this.el.getAttribute("position")));var t=this.el.getAttribute("gui-item"),e=document.createElement("a-entity");e.setAttribute("rounded","height: "+t.height+"; width: "+t.width+"; opacity: "+this.data.opacity+"; color: "+this.data.panelColor+"; radius:"+this.data.panelRounded+"; depthWrite:false; polygonOffset:true; polygonOffsetFactor: 2;"),console.log("about to set panel background color to: : "+this.data.panelColor),e.setAttribute("position",this.el.getAttribute("position").x+" "+this.el.getAttribute("position").y+" "+(this.el.getAttribute("position").z-.0125)),e.setAttribute("rotation",this.el.getAttribute("rotation").x+" "+this.el.getAttribute("rotation").y+" "+this.el.getAttribute("rotation").z),this.el.parentNode.insertBefore(e,this.el)}}}),AFRAME.registerPrimitive("a-gui-flex-container",{defaultComponents:{"gui-item":{type:"flex-container"},"gui-flex-container":{}},mappings:{width:"gui-item.width",height:"gui-item.height",margin:"gui-item.margin","flex-direction":"gui-flex-container.flexDirection","justify-content":"gui-flex-container.justifyContent","align-items":"gui-flex-container.alignItems","item-padding":"gui-flex-container.itemPadding",opacity:"gui-flex-container.opacity","is-top-container":"gui-flex-container.isTopContainer","panel-color":"gui-flex-container.panelColor","panel-rounded":"gui-flex-container.panelRounded","font-family":"gui-flex-container.styles.fontFamily","font-color":"gui-flex-container.styles.fontColor","border-color":"gui-flex-container.styles.borderColor","background-color":"gui-flex-container.styles.backgroundColor","hover-color":"gui-flex-container.styles.hoverColor","active-color":"gui-flex-container.styles.activeColor","handle-color":"gui-flex-container.styles.handleColor"}})},function(t,e,i){"use strict";AFRAME.registerComponent("gui-icon-button",{schema:{on:{default:"click"},toggle:{type:"boolean",default:!1},toggleState:{type:"boolean",default:!1},icon:{type:"string",default:"f0f3"},iconActive:{type:"string",default:""},iconFontSize:{type:"number",default:.4},iconFont:{type:"string",default:"assets/fonts/fa-regular-400.ttf"},fontColor:{type:"string",default:key_offwhite},borderColor:{type:"string",default:key_offwhite},backgroundColor:{type:"string",default:key_grey},hoverColor:{type:"string",default:key_grey_dark},activeColor:{type:"string",default:key_orange}},init:function(){var t=this.data,e=this.el,i=e.getAttribute("gui-item");this.guiItem=i;var r=(this.toggleState=t.toggle,e.getAttribute("gui-interactable"));if(this.guiInteractable=r,t.iconFontSize>20){var o=t.iconFontSize/750;t.iconFontSize=o}e.setAttribute("geometry","primitive: plane; height: "+i.height+"; width: "+i.width+";"),e.setAttribute("material","shader: flat; transparent: true; opacity: 0.0; alphaTest: 0.5; side:double; color:"+t.backgroundColor+";");var n=document.createElement("a-entity");n.setAttribute("geometry","primitive: cylinder; radius: "+i.height/2+"; height: 0.02;"),n.setAttribute("material","shader: flat; opacity: 1; side:double; color: "+t.borderColor),n.setAttribute("rotation","90 0 0"),n.setAttribute("position","0 0 0.01"),e.appendChild(n);var a=document.createElement("a-entity");a.setAttribute("geometry","primitive: cylinder; radius: "+i.height/2.05+"; height: 0.04;"),a.setAttribute("material","shader: flat; opacity: 1; side:double; color: "+t.backgroundColor),a.setAttribute("rotation","90 0 0"),a.setAttribute("position","0 0 0.02"),e.appendChild(a),this.buttonEntity=a,this.setIcon(t.icon),e.addEventListener("mouseenter",function(e){a.removeAttribute("animation__leave"),t.toggle||a.setAttribute("animation__enter","property: material.color; from: "+t.backgroundColor+"; to:"+t.hoverColor+"; dur:200;")}),e.addEventListener("mouseleave",function(e){t.toggle||(a.removeAttribute("animation__click"),a.setAttribute("animation__leave","property: material.color; from: "+t.hoverColor+"; to:"+t.backgroundColor+"; dur:200; easing: easeOutQuad;")),a.removeAttribute("animation__enter")}),e.addEventListener(t.on,function(i){if(t.toggle){var o=e.components["gui-button"];o.setActiveState(!o.data.toggleState)}else a.setAttribute("animation__click","property: material.color; from: "+t.activeColor+"; to:"+t.backgroundColor+"; dur:400; easing: easeOutQuad;");var n=r.clickAction,s=window[n];"function"==typeof s&&s(i)}),e.setAttribute("role","button")},play:function(){},update:function(t){console.log("In button update, toggle: "+this.toggleState);this.data,this.el;if(this.iconEntity){console.log("has iconEntity: "+this.iconEntity);var e=this.iconEntity;e.parentNode.removeChild(e),this.setIcon(this.data.icon)}else console.log("no iconEntity!")},setActiveState:function(t){this.data.toggleState=t,t?(console.log("active, about to set active color"),this.buttonEntity.setAttribute("material","color",this.data.activeColor)):(console.log("not active, about to set background color"),this.buttonEntity.setAttribute("material","color",this.data.backgroundColor))},setIcon:function(t){var e=parseInt(t,16),i=String.fromCharCode(e),r=document.createElement("a-entity");this.iconEntity=r,r.setAttribute("troika-text","value:"+i+"; \n align:center; \n anchor:center; \n baseline:center;\n lineHeight:"+this.guiItem.height+";\n maxWidth:"+this.guiItem.width+";\n color:"+this.data.fontColor+";\n font:"+this.data.iconFont+";\n fontSize:"+this.data.iconFontSize+";\n depthOffset:1;\n "),r.setAttribute("position","0 0 0.05"),this.el.appendChild(r)}}),AFRAME.registerPrimitive("a-gui-icon-button",{defaultComponents:{"gui-interactable":{},"gui-item":{type:"icon-button"},"gui-icon-button":{}},mappings:{onclick:"gui-interactable.clickAction",onhover:"gui-interactable.hoverAction","key-code":"gui-interactable.keyCode",width:"gui-item.width",height:"gui-item.height",margin:"gui-item.margin",on:"gui-icon-button.on","font-color":"gui-icon-button.fontColor","font-family":"gui-icon-button.fontFamily","border-color":"gui-icon-button.borderColor","background-color":"gui-icon-button.backgroundColor","hover-color":"gui-icon-button.hoverColor","active-color":"gui-icon-button.activeColor",icon:"gui-icon-button.icon","icon-active":"gui-icon-button.iconActive","icon-font":"gui-icon-button.iconFont","icon-font-size":"gui-icon-button.iconFontSize",toggle:"gui-icon-button.toggle","toggle-state":"gui-icon-button.toggleState"}})},function(t,e,i){"use strict";AFRAME.registerComponent("gui-icon-label-button",{schema:{on:{default:"click"},toggle:{type:"boolean",default:!1},toggleState:{type:"boolean",default:!1},icon:{type:"string",default:"f0f3"},iconActive:{type:"string",default:""},iconFontSize:{type:"number",default:.35},iconFont:{type:"string",default:"assets/fonts/fa-regular-400.ttf"},value:{type:"string",default:""},fontSize:{type:"number",default:.2},fontFamily:{type:"string",default:""},fontColor:{type:"string",default:key_offwhite},borderColor:{type:"string",default:key_offwhite},backgroundColor:{type:"string",default:key_grey},hoverColor:{type:"string",default:key_grey_dark},activeColor:{type:"string",default:key_orange}},init:function(){var t=this.data,e=this.el,i=e.getAttribute("gui-item");this.guiItem=i;var r=(this.toggleState=t.toggle,e.getAttribute("gui-interactable"));if(this.guiInteractable=r,t.iconFontSize>20){var o=t.iconFontSize/750;t.iconFontSize=o}if(t.fontSize>20){var o=t.fontSize/750;t.fontSize=o}e.setAttribute("geometry","primitive: plane; height: "+i.height+"; width: "+i.width+";"),e.setAttribute("material","shader: flat; side:front; color:"+t.backgroundColor+";");var n=document.createElement("a-entity");n.setAttribute("geometry","primitive: box; width: "+i.width+"; height: "+i.height+"; depth: 0.02;"),n.setAttribute("material","shader: flat; opacity: 1; side:double; color: "+t.borderColor),n.setAttribute("rotation","0 0 0"),n.setAttribute("position","0 0 0.01"),e.appendChild(n);var a=document.createElement("a-entity");a.setAttribute("geometry","primitive: box; width: "+(i.width-.025)+"; height: "+(i.height-.025)+"; depth: 0.04;"),a.setAttribute("material","shader: flat; opacity: 1; side:double; color: "+(t.toggleState?t.activeColor:t.backgroundColor)),a.setAttribute("rotation","0 0 0"),a.setAttribute("position","0 0 0.02"),e.appendChild(a),this.buttonEntity=a,this.setIcon(t.icon),""!=t.value&&this.setText(t.value),e.addEventListener("mouseenter",function(e){a.removeAttribute("animation__leave"),t.toggle||a.setAttribute("animation__enter","property: material.color; from: "+t.backgroundColor+"; to:"+t.hoverColor+"; dur:200;")}),e.addEventListener("mouseleave",function(e){t.toggle||(a.removeAttribute("animation__click"),a.setAttribute("animation__leave","property: material.color; from: "+t.hoverColor+"; to:"+t.backgroundColor+"; dur:200; easing: easeOutQuad;")),a.removeAttribute("animation__enter")}),e.addEventListener(t.on,function(i){if(t.toggle){var o=e.components["gui-button"];o.setActiveState(!o.data.toggleState)}else a.setAttribute("animation__click","property: material.color; from: "+t.activeColor+"; to:"+t.backgroundColor+"; dur:400; easing: easeOutQuad;");var n=r.clickAction,s=window[n];"function"==typeof s&&s(i)}),e.setAttribute("role","button")},play:function(){},update:function(t){console.log("In button update, toggle: "+this.toggleState);this.data,this.el;if(this.iconEntity){console.log("has iconEntity: "+this.iconEntity);var e=this.iconEntity;e.parentNode.removeChild(e),this.setIcon(this.data.icon)}else console.log("no iconEntity!");if(this.textEntity){console.log("has textEntity: "+this.textEntity);var e=this.textEntity;e.parentNode.removeChild(e),this.setText(this.data.value)}else console.log("no textEntity!")},setActiveState:function(t){this.data.toggleState=t,t?(console.log("active, about to set active color"),this.buttonEntity.setAttribute("material","color",this.data.activeColor)):(console.log("not active, about to set background color"),this.buttonEntity.setAttribute("material","color",this.data.backgroundColor))},setIcon:function(t){var e=parseInt(t,16),i=String.fromCharCode(e),r=document.createElement("a-entity"),o=0;""!=this.data.value&&(o=.5*-this.guiItem.width+.5*this.guiItem.height),this.iconEntity=r,r.setAttribute("troika-text","value:"+i+"; \n align:center; \n anchor:center; \n baseline:center;\n color:"+this.data.fontColor+";\n font:"+this.data.iconFont+";\n fontSize:"+this.data.iconFontSize+";\n depthOffset:1;\n "),r.setAttribute("position",o+" 0 0.05"),this.el.appendChild(r)},setText:function(t){var e=this.guiItem.height-.5*this.guiItem.width,i=document.createElement("a-entity");this.textEntity=i,i.setAttribute("troika-text","value: "+t+"; \n align:left; \n anchor:left; \n baseline:center;\n letterSpacing:0;\n color:"+this.data.fontColor+";\n font:"+this.data.fontFamily+";\n fontSize:"+this.data.fontSize+";\n depthOffset:1;\n maxWidth:"+this.guiItem.width/1.05+";\n "),i.setAttribute("position",e+" 0 0.05"),this.el.appendChild(i)}}),AFRAME.registerPrimitive("a-gui-icon-label-button",{defaultComponents:{"gui-interactable":{},"gui-item":{type:"icon-label-button"},"gui-icon-label-button":{}},mappings:{onclick:"gui-interactable.clickAction",onhover:"gui-interactable.hoverAction","key-code":"gui-interactable.keyCode",width:"gui-item.width",height:"gui-item.height",margin:"gui-item.margin",on:"gui-icon-label-button.on","font-color":"gui-icon-label-button.fontColor","font-family":"gui-icon-label-button.fontFamily","font-size":"gui-icon-label-button.fontSize","border-color":"gui-icon-label-button.borderColor","background-color":"gui-icon-label-button.backgroundColor","hover-color":"gui-icon-label-button.hoverColor","active-color":"gui-icon-label-button.activeColor",icon:"gui-icon-label-button.icon","icon-active":"gui-icon-label-button.iconActive","icon-font":"gui-icon-label-button.iconFont","icon-font-size":"gui-icon-label-button.iconFontSize",value:"gui-icon-label-button.value",toggle:"gui-icon-label-button.toggle","toggle-state":"gui-icon-label-button.toggleState"}})},function(t,e,i){"use strict";AFRAME.registerComponent("gui-input",{schema:{align:{type:"string",default:"left"},on:{default:"click"},value:{type:"string",default:""},toggle:{type:"boolean",default:!1},toggleState:{type:"boolean",default:!1},fontSize:{type:"number",default:.2},fontFamily:{type:"string",default:""},fontColor:{type:"string",default:key_grey_dark},borderColor:{type:"string",default:key_grey_dark},borderHoverColor:{type:"string",default:key_grey},backgroundColor:{type:"string",default:key_offwhite},hoverColor:{type:"string",default:key_white},activeColor:{type:"string",default:key_orange}},init:function(){var t=this.data,e=this.el,i=e.getAttribute("gui-item");this.guiItem=i;var r=(this.toggleState=t.toggle,e.getAttribute("gui-interactable"));if(this.guiInteractable=r,t.fontSize>20){var o=t.fontSize/750;t.fontSize=o}e.setAttribute("geometry","primitive: plane; height: "+i.height+"; width: "+i.width+";"),e.setAttribute("material","shader: flat; transparent: false; side:front; color:"+t.backgroundColor+";");var n=document.createElement("a-entity");n.setAttribute("geometry","primitive: box; width: "+i.width+"; height: 0.05; depth: 0.02;"),n.setAttribute("material","shader: flat; opacity: 1; side:double; color: "+t.borderColor),n.setAttribute("position","0 -"+(i.height/2-.025)+" 0.01"),e.appendChild(n);var a=document.createElement("a-entity");a.setAttribute("geometry","primitive: box; width: "+i.width+"; height: 0.05; depth: 0.02;"),a.setAttribute("material","shader: flat; opacity: 1; side:double; color: "+t.borderColor),a.setAttribute("position","0 "+(i.height/2-.025)+" 0.01"),e.appendChild(a);var s=document.createElement("a-entity");s.setAttribute("geometry","primitive: box; width: 0.05; height: "+i.height+"; depth: 0.02;"),s.setAttribute("material","shader: flat; opacity: 1; side:double; color: "+t.borderColor),s.setAttribute("position","-"+(i.width/2-.025)+" 0 0.01"),e.appendChild(s);var l=document.createElement("a-entity");l.setAttribute("geometry","primitive: box; width: 0.05; height: "+i.height+"; depth: 0.02;"),l.setAttribute("material","shader: flat; opacity: 1; side:double; color: "+t.borderColor),l.setAttribute("position",i.width/2-.025+" 0 0.01"),e.appendChild(l),this.setText(t.value),e.setAttribute("role","input"),e.addEventListener("mouseenter",function(i){e.setAttribute("material","color",t.hoverColor),n.setAttribute("material","color",t.borderHoverColor),a.setAttribute("material","color",t.borderHoverColor),s.setAttribute("material","color",t.borderHoverColor),l.setAttribute("material","color",t.borderHoverColor)}),e.addEventListener("mouseleave",function(i){e.setAttribute("material","color",t.backgroundColor),n.setAttribute("material","color",t.borderColor),a.setAttribute("material","color",t.borderColor),s.setAttribute("material","color",t.borderColor),l.setAttribute("material","color",t.borderColor)}),e.addEventListener(t.on,function(t){console.log("I was clicked at: ",t.detail.intersection.point);var i=e.getAttribute("gui-interactable");console.log("guiInteractable: "+i);var r=i.clickAction;console.log("clickActionFunctionName: "+r);var o=window[r];"function"==typeof o&&o(t)})},setText:function(t){var e=.25*this.guiItem.height-.5*this.guiItem.width,i=document.createElement("a-entity");this.textEntity=i,i.setAttribute("troika-text","value: "+t+"; \n align:left; \n anchor:left; \n baseline:center;\n letterSpacing:0;\n color:"+this.data.fontColor+";\n font:"+this.data.fontFamily+";\n fontSize:"+this.data.fontSize+";\n depthOffset:1;\n maxWidth:"+this.guiItem.width/1.05+";\n "),i.setAttribute("position",e+" 0 0.05"),this.el.appendChild(i)},play:function(){},update:function(t){var e=this.data;this.el;this.textEntity.setAttribute("troika-text","value: "+e.value+";")},appendText:function(t){var e=this.data.value+t;this.el.setAttribute("gui-input","text",e)},delete:function(){if(this.data.value&&this.data.value.length>0){var t=this.data.value.slice(0,-1);this.el.setAttribute("gui-input","text",t)}}}),AFRAME.registerPrimitive("a-gui-input",{defaultComponents:{"gui-interactable":{},"gui-item":{type:"input"},"gui-input":{}},mappings:{onclick:"gui-interactable.clickAction",onhover:"gui-interactable.hoverAction",width:"gui-item.width",height:"gui-item.height",margin:"gui-item.margin",value:"gui-input.value","font-size":"gui-input.fontSize","font-family":"gui-input.fontFamily","font-color":"gui-input.fontColor","background-color":"gui-input.backgroundColor","hover-color":"gui-input.hoverColor","border-color":"gui-input.borderColor","border-hover-color":"gui-input.borderHoverColor"}})},function(t,e,i){"use strict";AFRAME.registerComponent("gui-interactable",{schema:{clickAction:{type:"string"},hoverAction:{type:"string"},keyCode:{type:"number",default:-1},key:{type:"string"}},init:function(){var t=this.data,e=this.el;t.keyCode>0&&window.addEventListener("keydown",function(i){i.key==t.key?e.emit("click"):i.keyCode==t.keyCode&&e.emit("click"),i.preventDefault()},!0)},update:function(){},tick:function(){},remove:function(){},pause:function(){},play:function(){},setClickAction:function(t){this.data.clickAction=t}})},function(t,e,i){"use strict";AFRAME.registerComponent("gui-item",{schema:{type:{type:"string"},width:{type:"number",default:1},height:{type:"number",default:1},baseDepth:{type:"number",default:.01},depth:{type:"number",default:.02},gap:{type:"number",default:.025},radius:{type:"number",default:0},margin:{type:"vec4",default:{x:0,y:0,z:0,w:0}},bevel:{type:"boolean",default:!1},bevelSegments:{type:"number",default:5},steps:{type:"number",default:2},bevelSize:{type:"number",default:.1},bevelOffset:{type:"number",default:0},bevelThickness:{type:"number",default:.1}},init:function(){},update:function(){},tick:function(){},remove:function(){},pause:function(){},play:function(){}})},function(t,e,i){"use strict";AFRAME.registerComponent("gui-label",{schema:{value:{type:"string",default:""},align:{type:"string",default:"center"},anchor:{type:"string",default:"center"},fontSize:{type:"number",default:.2},lineHeight:{type:"number",default:.2},letterSpacing:{type:"number",default:0},fontFamily:{type:"string",default:""},fontColor:{type:"string",default:key_grey_dark},backgroundColor:{type:"string",default:key_offwhite},opacity:{type:"number",default:1},textDepth:{type:"number",default:.01}},init:function(){var t=this.data,e=this.el,i=e.getAttribute("gui-item");if(this.guiItem=i,e.setAttribute("geometry","primitive: plane; height: "+i.height+"; width: "+i.width+";"),e.setAttribute("material","shader: flat; side:front; color:"+t.backgroundColor+"; transparent: true; opacity: "+t.opacity+"; alphaTest: 0.5;"),t.fontSize>20){var r=t.fontSize/750;t.fontSize=r}this.setText(t.value)},update:function(t){this.data,this.el;if(this.textEntity){console.log("has textEntity: "+this.textEntity);var e=this.textEntity;e.parentNode.removeChild(e),this.setText(this.data.value)}else console.log("no textEntity!")},setText:function(t){var e=document.createElement("a-entity");this.textEntity=e,e.setAttribute("troika-text","value: "+t+"; \n align: "+this.data.align+"; \n anchor: "+this.data.anchor+"; \n baseline:center;\n letterSpacing:0;\n lineHeight: "+this.data.lineHeight+";\n color:"+this.data.fontColor+";\n font:"+this.data.fontFamily+";\n fontSize:"+this.data.fontSize+";\n depthOffset:1;\n maxWidth:"+this.guiItem.width/1.05+";\n "),e.setAttribute("position","0 0 "+this.data.textDepth),this.el.appendChild(e)}}),AFRAME.registerPrimitive("a-gui-label",{defaultComponents:{"gui-item":{type:"label"},"gui-label":{}},mappings:{width:"gui-item.width",height:"gui-item.height",margin:"gui-item.margin",align:"gui-label.align",anchor:"gui-label.anchor",value:"gui-label.value","font-size":"gui-label.fontSize","line-height":"gui-label.lineHeight","letter-spacing":"gui-label.letterSpacing","font-color":"gui-label.fontColor","font-family":"gui-label.fontFamily","background-color":"gui-label.backgroundColor",opacity:"gui-label.opacity","text-depth":"gui-label.textDepth"}})},function(t,e,i){"use strict";AFRAME.registerComponent("gui-progressbar",{schema:{backgroundColor:{type:"string",default:key_grey},activeColor:{type:"string",default:key_orange}},init:function(){var t=this.data,e=this.el,i=e.getAttribute("gui-item");e.setAttribute("geometry","primitive: plane; height: "+i.height+"; width: "+i.width+";"),e.setAttribute("material","shader: flat; opacity: 1; color: "+t.backgroundColor+"; side:front;");var r=document.createElement("a-entity");r.setAttribute("geometry","primitive: box; width: 0.04; height: "+i.height+"; depth: 0.02;"),r.setAttribute("material","shader: flat; opacity: 1; side:double; color: "+t.activeColor),r.setAttribute("position",-i.width/2+" 0 0.01"),r.id="progress_meter",e.appendChild(r)},update:function(){},tick:function(){},remove:function(){},pause:function(){},play:function(){}}),AFRAME.registerPrimitive("a-gui-progressbar",{defaultComponents:{"gui-item":{type:"progressbar"},"gui-progressbar":{}},mappings:{width:"gui-item.width",height:"gui-item.height",margin:"gui-item.margin","background-color":"gui-progressbar.backgroundColor","active-color":"gui-progressbar.activeColor"}})},function(t,e,i){"use strict";AFRAME.registerComponent("gui-radio",{schema:{on:{default:"click"},value:{type:"string",default:""},active:{type:"boolean",default:!0},toggle:{type:"boolean",default:!1},toggleState:{type:"boolean",default:!1},checked:{type:"boolean",default:!1},radiosizecoef:{type:"number",default:1},fontSize:{type:"number",default:.2},fontFamily:{type:"string",default:""},fontColor:{type:"string",default:key_grey_dark},borderColor:{type:"string",default:key_white},backgroundColor:{type:"string",default:key_offwhite},hoverColor:{type:"string",default:key_grey_light},activeColor:{type:"string",default:key_orange},handleColor:{type:"string",default:key_grey}},init:function(){var t=this.data,e=this.el,i=e.getAttribute("gui-item");this.guiItem=i;var r=(this.toggleState=t.toggle,e.getAttribute("gui-interactable"));if(this.guiInteractable=r,t.fontSize>20){var o=t.fontSize/750;t.fontSize=o}e.setAttribute("material","shader: flat; depthTest:true;transparent: false; opacity: 1; color: "+this.data.backgroundColor+"; side:front;"),e.setAttribute("geometry","primitive: plane; height: "+i.height+"; width: "+i.height+";");var n=.5*-i.width+.5*i.height,a=document.createElement("a-cylinder");a.setAttribute("radius",.2*i.height*t.radiosizecoef),a.setAttribute("height","0.01"),a.setAttribute("rotation","90 0 0"),a.setAttribute("material","color:"+t.handleColor+"; shader: flat;"),a.setAttribute("position",n+" 0 0"),e.appendChild(a);var s=document.createElement("a-torus");s.setAttribute("radius",.19*i.height*t.radiosizecoef),s.setAttribute("radius-tubular","0.01"),s.setAttribute("rotation","90 0 0"),s.setAttribute("material","color:"+t.borderColor+"; shader: flat;"),a.appendChild(s);var l=document.createElement("a-cylinder");l.setAttribute("radius",.18*i.height*t.radiosizecoef),l.setAttribute("height","0.02"),l.setAttribute("rotation","0 0 0"),l.setAttribute("material","color:"+t.handleColor+"; shader: flat;"),a.appendChild(l),this.setText(t.value),this.updateToggle(t.active),e.setAttribute("checked",t.active),e.addEventListener("mouseenter",function(e){s.removeAttribute("animation__leave"),s.setAttribute("animation__enter","property: material.color; from: "+t.borderColor+"; to:"+t.hoverColor+"; dur:200;")}),e.addEventListener("mouseleave",function(e){s.removeAttribute("animation__enter"),s.setAttribute("animation__leave","property: material.color; from: "+t.hoverColor+"; to:"+t.borderColor+"; dur:200; easing: easeOutQuad;")}),e.addEventListener(t.on,function(i){t.checked=!t.checked,t.checked?(l.removeAttribute("animation__colorOut"),l.removeAttribute("animation__rotationOut"),l.removeAttribute("animation__position1Out"),l.removeAttribute("animation__position2Out"),l.setAttribute("animation__colorIn","property: material.color; from: "+t.handleColor+"; to:"+t.activeColor+"; dur:500; easing:easeInOutCubic;"),l.setAttribute("animation__rotationIn","property: rotation; from: 0 0 0; to:-180 0 0; dur:500; easing:easeInOutCubic;"),l.setAttribute("animation__position1In","property: position; from: 0 0 0; to:0 0.3 0; dur:200; easing:easeInOutCubic;"),l.setAttribute("animation__position2In","property: position; from: 0 0.3 0; to:0 0 0; dur:200; easing:easeInOutCubic; delay:300;")):(l.removeAttribute("animation__colorIn"),l.removeAttribute("animation__rotationIn"),l.removeAttribute("animation__position1In"),l.removeAttribute("animation__position2In"),l.setAttribute("animation__colorOut","property: material.color; from: "+t.activeColor+"; to:"+t.handleColor+"; dur:500; easing:easeInOutCubic;"),l.setAttribute("animation__rotationOut","property: rotation; from: -180 0 0; to:0 0 0; dur:500; easing:easeInOutCubic;"),l.setAttribute("animation__position1Out","property: position; from: 0 0 0; to:0 0.3 0; dur:200; easing:easeInOutCubic; "),l.setAttribute("animation__position2Out","property: position; from: 0 0.3 0; to:0 0 0; dur:200; easing:easeInOutCubic; delay:300;"));var r=e.getAttribute("gui-interactable"),o=r.clickAction,n=window[o];"function"==typeof n&&n(i)}),e.setAttribute("role","radio")},update:function(){var t=this.data;this.el;if(this.updateToggle(t.active),this.textEntity){console.log("has textEntity: "+this.textEntity);var e=this.textEntity;e.parentNode.removeChild(e),this.setText(this.data.value)}else console.log("no textEntity!")},updateToggle:function(t){},setText:function(t){var e=this.guiItem.height-.5*this.guiItem.width,i=document.createElement("a-entity");this.textEntity=i,i.setAttribute("troika-text","value: "+t+"; \n align:left; \n anchor:left; \n baseline:center;\n letterSpacing:0;\n color:"+this.data.fontColor+";\n font:"+this.data.fontFamily+";\n fontSize:"+this.data.fontSize+";\n depthOffset:1;\n maxWidth:"+this.guiItem.width/1.05+";\n "),i.setAttribute("position",e+" 0 0.05"),this.el.appendChild(i)}}),AFRAME.registerPrimitive("a-gui-radio",{defaultComponents:{"gui-interactable":{},"gui-item":{type:"radio"},"gui-radio":{}},mappings:{onclick:"gui-interactable.clickAction",onhover:"gui-interactable.hoverAction","key-code":"gui-interactable.keyCode",width:"gui-item.width",height:"gui-item.height",margin:"gui-item.margin",on:"gui-radio.on",value:"gui-radio.value",active:"gui-radio.active",checked:"gui-radio.checked","font-color":"gui-radio.fontColor","font-size":"gui-radio.fontSize","font-family":"gui-radio.fontFamily","border-color":"gui-radio.borderColor","background-color":"gui-radio.backgroundColor","hover-color":"gui-radio.hoverColor","active-color":"gui-radio.activeColor","handle-color":"gui-radio.handleColor",radiosizecoef:"gui-radio.radiosizecoef"}})},function(t,e,i){"use strict";AFRAME.registerComponent("rounded",{schema:{enabled:{default:!0},width:{type:"number",default:1},height:{type:"number",default:1},radius:{type:"number",default:.3},topLeftRadius:{type:"number",default:-1},topRightRadius:{type:"number",default:-1},bottomLeftRadius:{type:"number",default:-1},bottomRightRadius:{type:"number",default:-1},depthWrite:{default:!0},polygonOffset:{default:!1},polygonOffsetFactor:{type:"number",default:0},color:{type:"color",default:"#F0F0F0"},opacity:{type:"number",default:1}},init:function(){this.rounded=new THREE.Mesh(this.draw(),new THREE.MeshStandardMaterial({color:new THREE.Color(this.data.color)})),this.updateOpacity(),this.el.setObject3D("mesh",this.rounded)},update:function(){this.data.enabled?this.rounded&&(this.rounded.visible=!0,this.rounded.geometry=this.draw(),this.rounded.material.color=new THREE.Color(this.data.color),this.updateOpacity()):this.rounded.visible=!1},updateOpacity:function(){this.data.opacity<0&&(this.data.opacity=0),this.data.opacity>1&&(this.data.opacity=1),this.data.opacity<1?(this.rounded.material.transparent=!0,this.rounded.material.opacity=this.data.opacity,this.rounded.material.alphaTest=0):this.rounded.material.transparent=!1},tick:function(){},remove:function(){this.rounded&&(this.el.object3D.remove(this.rounded),this.rounded=null)},draw:function(){function t(t,e,i,r,o,n,a,s,l){n||(n=1e-5),a||(a=1e-5),s||(s=1e-5),l||(l=1e-5),t.moveTo(e,i+n),t.lineTo(e,i+o-n),t.quadraticCurveTo(e,i+o,e+n,i+o),t.lineTo(e+r-a,i+o),t.quadraticCurveTo(e+r,i+o,e+r,i+o-a),t.lineTo(e+r,i+l),t.quadraticCurveTo(e+r,i,e+r-l,i),t.lineTo(e+s,i),t.quadraticCurveTo(e,i,e,i+s)}var e=new THREE.Shape,i=[this.data.radius,this.data.radius,this.data.radius,this.data.radius];return-1!=this.data.topLeftRadius&&(i[0]=this.data.topLeftRadius),-1!=this.data.topRightRadius&&(i[1]=this.data.topRightRadius),-1!=this.data.bottomLeftRadius&&(i[2]=this.data.bottomLeftRadius),-1!=this.data.bottomRightRadius&&(i[3]=this.data.bottomRightRadius),t(e,-this.data.width/2,-this.data.height/2,this.data.width,this.data.height,i[0],i[1],i[2],i[3]),new THREE.ShapeBufferGeometry(e)},pause:function(){},play:function(){}}),AFRAME.registerPrimitive("a-rounded",{defaultComponents:{rounded:{}},mappings:{enabled:"rounded.enabled",width:"rounded.width",height:"rounded.height",radius:"rounded.radius","depth-write":"rounded.depthWrite","polygon-offset":"rounded.polygonOffset","polygon-offset-factor":"rounded.polygonOffsetFactor","top-left-radius":"rounded.topLeftRadius","top-right-radius":"rounded.topRightRadius","bottom-left-radius":"rounded.bottomLeftRadius","bottom-right-radius":"rounded.bottomRightRadius",color:"rounded.color",opacity:"rounded.opacity"}})},function(t,e,i){"use strict";AFRAME.registerComponent("gui-slider",{schema:{activeColor:{type:"string",default:key_orange},backgroundColor:{type:"string",default:key_offwhite},borderColor:{type:"string",default:key_grey},handleColor:{type:"string",default:key_white},handleInnerDepth:{type:"number",default:.02},handleInnerRadius:{type:"number",default:.13},handleOuterDepth:{type:"number",default:.04},handleOuterRadius:{type:"number",default:.17},hoverColor:{type:"string",default:key_grey_light},leftRightPadding:{type:"number",default:.25},percent:{type:"number",default:.5},sliderBarHeight:{type:"number",default:.05},sliderBarDepth:{type:"number",default:.03},topBottomPadding:{type:"number",default:.125}},init:function(){var t=this.data,e=this.el,i=e.getAttribute("gui-item"),r=i.width-2*t.leftRightPadding;i.height,t.topBottomPadding;e.setAttribute("geometry","primitive: plane; height: "+i.height+"; width: "+i.height+";"),e.setAttribute("material","shader: flat; opacity: 1; color: "+t.backgroundColor+"; side:front;");var o=document.createElement("a-entity");o.setAttribute("geometry","primitive: box; width: "+t.percent*r+"; height: "+t.sliderBarHeight+"; depth: "+t.sliderBarDepth+";"),o.setAttribute("material","shader: flat; opacity: 1; side:double; color: "+t.activeColor+";"),o.setAttribute("position",t.percent-.5*r+" 0 "+(t.sliderBarDepth-.01)),e.appendChild(o);var n=document.createElement("a-entity");n.setAttribute("geometry","primitive: box; width: "+(r-t.percent*r)+"; height: "+t.sliderBarHeight+"; depth: "+t.sliderBarDepth+";"),n.setAttribute("material","shader: flat; opacity: 1; side:double; color: "+t.borderColor+";"),n.setAttribute("position",t.percent*r*.5+" 0 "+(t.sliderBarDepth-.01)),e.appendChild(n);var a=document.createElement("a-entity");a.setAttribute("geometry","primitive: cylinder; radius: "+t.handleOuterRadius+"; height: "+t.handleOuterDepth+";"),a.setAttribute("material","shader: flat; opacity: 1; side:double; color: "+t.borderColor+";"),a.setAttribute("rotation","90 0 0"),a.setAttribute("position",t.percent*r-.5*r+" 0 "+(t.handleOuterDepth-.01)),e.appendChild(a);var s=document.createElement("a-entity");s.setAttribute("geometry","primitive: cylinder; radius: "+t.handleInnerRadius+"; height: "+t.handleInnerDepth+";"),s.setAttribute("material","shader: flat; opacity: 1; side:double; color: "+t.handleColor+";"),s.setAttribute("position","0 "+t.handleInnerDepth+" 0"),a.appendChild(s),e.addEventListener("mouseenter",function(){s.setAttribute("material","color",t.hoverColor)}),e.addEventListener("mouseleave",function(){s.setAttribute("material","color",t.handleColor)}),e.addEventListener("click",function(i){console.log("I was clicked at: ",i.detail.intersection.point);var r=e.object3D.worldToLocal(i.detail.intersection.point);console.log("local coordinates: ",r),console.log("current percent: "+t.percent);var s=2;r.x<=-s/2?t.percent=0:r.x>=s/2?t.percent=1:t.percent=(r.x+s/2)/s,console.log("handle container: "+a),o.setAttribute("geometry","primitive: box; width: "+2*t.percent+"; height: 0.05; depth: 0.03;"),o.setAttribute("position",t.percent-1+" 0 0.02"),n.setAttribute("geometry","primitive: box; width: "+(2-2*t.percent)+"; height: 0.05; depth: 0.03;"),n.setAttribute("position",1*t.percent+" 0 0.02"),a.setAttribute("position",2*t.percent-1+" 0 0.03");var l=e.getAttribute("gui-interactable");console.log("guiInteractable: "+l);var u=l.clickAction;console.log("clickActionFunctionName: "+u);var d=window[u];"function"==typeof d&&d(i,t.percent)})},update:function(){},tick:function(){},remove:function(){},pause:function(){},play:function(){}}),AFRAME.registerPrimitive("a-gui-slider",{defaultComponents:{"gui-interactable":{},"gui-item":{type:"slider"},"gui-slider":{}},mappings:{"active-color":"gui-slider.activeColor","background-color":"gui-slider.backgroundColor","border-color":"gui-slider.borderColor","handle-color":"gui-slider.handleColor","handle-inner-depth":"gui-slider.handleInnerDepth","handle-inner-radius":"gui-slider.handleInnerRadius","handle-outer-depth":"gui-slider.handleOuterDepth","handle-outer-radius":"gui-slider.handleOuterRadius",height:"gui-item.height","hover-color":"gui-slider.hoverColor","key-code":"gui-interactable.keyCode","left-right-padding":"gui-slider.leftRightPadding",margin:"gui-item.margin",onclick:"gui-interactable.clickAction",onhover:"gui-interactable.hoverAction",percent:"gui-slider.percent","slider-bar-depth":"gui-slider.sliderBarDepth","slider-bar-height":"gui-slider.sliderBarHeight","top-bottom-padding":"gui-slider.topBottomPadding",width:"gui-item.width"}})},function(t,e,i){"use strict";AFRAME.registerComponent("gui-toggle",{schema:{on:{default:"click"},value:{type:"string",default:""},toggle:{type:"boolean",default:!1},toggleState:{type:"boolean",default:!1},active:{type:"boolean",default:!0},checked:{type:"boolean",default:!1},borderWidth:{type:"number",default:1},fontSize:{type:"number",default:.2},fontFamily:{type:"string",default:""},fontColor:{type:"string",default:key_grey_dark},borderColor:{type:"string",default:key_grey},backgroundColor:{type:"string",default:key_offwhite},hoverColor:{type:"string",default:key_grey_light},activeColor:{type:"string",default:key_orange},handleColor:{type:"string",default:key_offwhite}},init:function(){var t=this.data,e=this.el,i=e.getAttribute("gui-item");this.guiItem=i;var r=(this.toggleState=t.toggle,e.getAttribute("gui-interactable"));if(this.guiInteractable=r,t.fontSize>20){var o=t.fontSize/750;t.fontSize=o}e.setAttribute("material","shader: flat; depthTest:true;transparent: false; opacity: 1; color: "+this.data.backgroundColor+"; side:front;"),e.setAttribute("geometry","primitive: plane; height: "+i.height+"; width: "+i.height+";");var n=i.height/1.75,a=.5*-i.width+i.height/2,s=document.createElement("a-box");s.setAttribute("width",n),s.setAttribute("height",.5*i.height),s.setAttribute("depth","0.01"),s.setAttribute("material","color:"+t.borderColor+"; shader: flat;"),s.setAttribute("position",a+" 0 0"),e.appendChild(s);var l=i.height/5,u=.5*-i.height+2*l,d=.5*i.height-2*l,c=document.createElement("a-box");c.setAttribute("width",""+l),c.setAttribute("height",.4*i.height),c.setAttribute("depth","0.02"),c.setAttribute("material","color:"+t.handleColor),c.setAttribute("position",u+" 0 0.02"),s.appendChild(c),this.setText(t.value),this.updateToggle(t.active),e.addEventListener("mouseenter",function(e){c.removeAttribute("animation__leave"),c.setAttribute("animation__enter","property: material.color; from: "+t.handleColor+"; to:"+t.hoverColor+"; dur:200;")}),e.addEventListener("mouseleave",function(e){c.removeAttribute("animation__enter"),c.setAttribute("animation__leave","property: material.color; from: "+t.hoverColor+"; to:"+t.handleColor+"; dur:200; easing: easeOutQuad;")}),e.addEventListener("check",function(e){t.checked||(t.checked=!0)}),e.addEventListener("uncheck",function(e){t.checked&&(t.checked=!1)}),e.addEventListener(t.on,function(i){console.log("I was clicked at: ",i.detail.intersection.point),t.checked=!t.checked,t.checked?(s.removeAttribute("animation__colorOut"),c.removeAttribute("animation__positionOut"),s.setAttribute("animation__colorIn","property: material.color; from: "+t.borderColor+"; to:"+t.activeColor+"; dur:200; easing:easeInOutCubic;"),c.setAttribute("animation__positionIn","property: position; from: "+u+" 0 0.02; to:"+d+" 0 0.02; dur:200; easing:easeInOutCubic;")):(s.removeAttribute("animation__colorIn"),c.removeAttribute("animation__positionIn"),s.setAttribute("animation__colorOut","property: material.color; from: "+t.activeColor+"; to:"+t.borderColor+"; dur:200; easing:easeInOutCubic;"),c.setAttribute("animation__positionOut","property: position; from: "+d+" 0 0.02; to:"+u+" 0 0.02; dur:200; easing:easeInOutCubic;"));var r=e.getAttribute("gui-interactable");console.log("guiInteractable: "+r);var o=r.clickAction;console.log("clickActionFunctionName: "+o);var n=window[o];"function"==typeof n&&n(i)})},update:function(){var t=this.data;this.el;if(this.updateToggle(t.active),this.textEntity){console.log("has textEntity: "+this.textEntity);var e=this.textEntity;e.parentNode.removeChild(e),this.setText(this.data.value)}else console.log("no textEntity!")},updateToggle:function(t){},setText:function(t){var e=this.guiItem.height-.5*this.guiItem.width,i=document.createElement("a-entity");this.textEntity=i,i.setAttribute("troika-text","value: "+t+"; \n align:left; \n anchor:left; \n baseline:center;\n letterSpacing:0;\n color:"+this.data.fontColor+";\n font:"+this.data.fontFamily+";\n fontSize:"+this.data.fontSize+";\n depthOffset:1;\n maxWidth:"+this.guiItem.width/1.05+";\n "),i.setAttribute("position",e+" 0 0.05"),this.el.appendChild(i)}}),AFRAME.registerPrimitive("a-gui-toggle",{defaultComponents:{"gui-interactable":{},"gui-item":{type:"toggle"},"gui-toggle":{}},mappings:{onclick:"gui-interactable.clickAction",onhover:"gui-interactable.hoverAction","key-code":"gui-interactable.keyCode",width:"gui-item.width",height:"gui-item.height",margin:"gui-item.margin",on:"gui-toggle.on",active:"gui-toggle.active",checked:"gui-toggle.checked",value:"gui-toggle.value","font-color":"gui-toggle.fontColor","font-family":"gui-toggle.fontFamily","font-size":"gui-toggle.fontSize","border-width":"gui-toggle.borderWidth","border-color":"gui-toggle.borderColor","background-color":"gui-toggle.backgroundColor","hover-color":"gui-toggle.hoverColor","active-color":"gui-toggle.activeColor","handle-color":"gui-toggle.handleColor"}})},function(t,e,i){"use strict";AFRAME.registerComponent("gui-vertical-slider",{schema:{activeColor:{type:"string",default:key_orange},backgroundColor:{type:"string",default:key_offwhite},borderColor:{type:"string",default:key_grey},handleColor:{type:"string",default:key_white},handleInnerDepth:{type:"number",default:.02},handleInnerRadius:{type:"number",default:.13},handleOuterDepth:{type:"number",default:.04},handleOuterRadius:{type:"number",default:.17},hoverColor:{type:"string",default:key_grey_light},hoverFontSize:{type:"number",default:100},hoverHeight:{type:"number",default:.35},hoverPercent:{type:"number"},hoverWidth:{type:"number",default:.7},hoverMargin:{type:"vec4",default:{x:0,y:0,z:0,w:0}},leftRightPadding:{type:"number",default:.125},percent:{type:"number",default:.5},opacity:{type:"number",default:1},outputFontSize:{type:"string",default:"0.2"},outputFunction:{type:"string"},outputHeight:{type:"number",default:1},outputMargin:{type:"vec4",default:{x:0,y:0,z:0,w:0}},outputTextDepth:{type:"number",default:.25},outputWidth:{type:"number",default:1},sliderBarDepth:{type:"number",default:.03},sliderBarWidth:{type:"number",default:.08},topBottomPadding:{type:"number",default:.25}},init:function(){var t=this,e=this.data,i=this.el,r=i.getAttribute("gui-item"),o=(r.width,e.leftRightPadding,r.height-2*e.topBottomPadding);this.sliderHeight=o,i.setAttribute("geometry","primitive: plane; height: "+r.height+"; width: "+r.width+";"),i.setAttribute("material","shader: flat; opacity: "+e.opacity+"; alphaTest: 0.5; color: "+e.backgroundColor+"; side:front;"),console.log("**** in vertical slider init, percent: "+e.percent+", sliderHeight: "+o);var n=document.createElement("a-entity");n.setAttribute("geometry","primitive: box; height: "+e.percent*o+"; width: "+e.sliderBarWidth+"; depth: "+e.sliderBarDepth+";"),n.setAttribute("material","shader: flat; opacity: 1; side:double; color: "+e.activeColor+";"),n.setAttribute("position","0 "+(e.percent*o-.5*o-e.percent*o*.5)+" "+(e.sliderBarDepth-.01)),this.sliderActiveBar=n,i.appendChild(n);var a=document.createElement("a-entity");a.setAttribute("geometry","primitive: box; height: "+(o-e.percent*o)+"; width: "+e.sliderBarWidth+"; depth: "+e.sliderBarDepth+";"),a.setAttribute("material","shader: flat; opacity: 1; alphaTest: 0.5; side:double; color:"+e.borderColor+";"),a.setAttribute("position","0 "+e.percent*o*.5+" "+(e.sliderBarDepth-.01)),this.sliderBar=a,i.appendChild(a);var s=document.createElement("a-entity");s.setAttribute("geometry","primitive: cylinder; radius: "+e.handleOuterRadius+"; height: "+e.handleOuterDepth+";"),s.setAttribute("material","shader: flat; opacity: 1; side:double; color: "+e.activeColor+";"),s.setAttribute("rotation","90 0 0"),s.setAttribute("position","0 "+(e.percent*o-.5*o)+" "+(e.handleOuterDepth-.01)),this.handleContainer=s,i.appendChild(s);var l=document.createElement("a-entity");l.setAttribute("geometry","primitive: cylinder; radius: "+e.handleInnerRadius+"; height: "+e.handleInnerDepth+";"),l.setAttribute("material","shader: flat; opacity: 1; side:double; color: "+e.handleColor+";"),l.setAttribute("position","0 "+e.handleInnerDepth+" 0"),s.appendChild(l);var u=document.createElement("a-gui-label");u.setAttribute("width",""+1.4*r.width*e.outputWidth),u.setAttribute("height",""+.7*r.width),u.setAttribute("value","0.0"),u.setAttribute("opacity","1.0"),u.setAttribute("position",1.4*r.width+" 0 "+e.sliderBarDepth),u.setAttribute("rotation","-90 0 0"),u.setAttribute("font-color",e.activeColor),u.setAttribute("font-size",240*r.width+"px"),u.setAttribute("font-weight","bold"),u.setAttribute("text-depth",e.outputTextDepth),this.valueLabel=u,s.appendChild(u);var d=document.createElement("a-entity");d.setAttribute("geometry","primitive: box; height: 0.02; width: "+.5*r.width+"; depth: "+e.sliderBarDepth+";"),d.setAttribute("material","shader: flat; opacity: 1; side:double; color: "+e.activeColor+";"),d.setAttribute("position",.5*-r.width+" 0 "+(e.sliderBarDepth-.01)),d.setAttribute("visible","false"),this.hoverIndicator=d,i.appendChild(d);var c=document.createElement("a-gui-label");c.setAttribute("width",""+r.width*e.hoverWidth),c.setAttribute("height",""+r.width*e.hoverHeight),c.setAttribute("value",""),c.setAttribute("opacity","0.5"),c.setAttribute("position",-r.width*e.hoverWidth+" 0 "+e.sliderBarDepth),c.setAttribute("font-color",e.borderColor),c.setAttribute("font-size",r.width*e.hoverFontSize+"px"),c.setAttribute("text-depth",e.outputTextDepth),this.hoverLabel=c,d.appendChild(c),i.addEventListener("mouseenter",function(){l.setAttribute("material","color",e.hoverColor)}),i.addEventListener("mouseleave",function(){l.setAttribute("material","color",e.handleColor)}),i.addEventListener("click",function(t){var r=i.object3D.worldToLocal(t.detail.intersection.point);console.log("click local coordinates: ",r),console.log("current percent: "+e.percent);var n=null;n=r.y<=-o/2?0:r.y>=o/2?1:(r.y+o/2)/o,console.log("new percent: "+n),i.setAttribute("gui-vertical-slider","percent",String(n)),i.setAttribute("gui-vertical-slider","hoverPercent",String(n)),console.log("handle container: "+s);var a=i.getAttribute("gui-interactable");console.log("guiInteractable: "+a);var l=a.clickAction;console.log("clickActionFunctionName: "+l);var u=window[l];"function"==typeof u&&u(e.percent)}),this.el.addEventListener("raycaster-intersected",function(e){t.raycaster=e.detail.el}),this.el.addEventListener("raycaster-intersected-cleared",function(e){t.raycaster=null,t.hoverIndicator.setAttribute("visible",!1),t.hoverLabel.setAttribute("visible",!1)})},update:function(t){var e=this.data,i=this.el,r=i.getAttribute("gui-item"),o=(r.width,e.leftRightPadding,r.height-2*e.topBottomPadding);if(e.percent!=t.percent&&this.sliderActiveBar&&this.sliderBar&&this.handleContainer){var o=r.height-2*e.topBottomPadding;this.sliderActiveBar.setAttribute("geometry","primitive: box; height: "+e.percent*o+"; width: "+e.sliderBarWidth+"; depth: "+e.sliderBarDepth+";"),this.sliderActiveBar.setAttribute("position","0 "+(e.percent*o-.5*o-e.percent*o*.5)+" "+(e.sliderBarDepth-.01)),this.sliderBar.setAttribute("geometry","primitive: box; width: "+e.sliderBarWidth+"; height: "+(o-e.percent*o)+"; depth: "+e.sliderBarDepth+";"),this.sliderBar.setAttribute("position","0 "+e.percent*o*.5+" "+(e.sliderBarDepth-.01)),this.handleContainer.setAttribute("position","0 "+(e.percent*o-.5*o)+" "+(e.handleOuterDepth-.01));var n=this.getOutputValue(!1);n&&this.valueLabel.setAttribute("value",n),this.hoverIndicator.setAttribute("visible",!1),this.hoverLabel.setAttribute("visible",!1)}else if(e.hoverPercent!=t.hoverPercent&&e.hoverPercent!=e.percent&&this.hoverIndicator){var a=this.getOutputValue(!0);a&&this.hoverLabel.setAttribute("value",a),this.hoverIndicator.setAttribute("position","0 "+(e.hoverPercent*o-.5*o)+" "+(e.sliderBarDepth-.01)),this.hoverIndicator.setAttribute("visible",!0),this.hoverLabel.setAttribute("visible",!0)}},tick:function(){if(this.raycaster){var t=this.el,e=(this.data,this.sliderHeight),i=(this.handleContainer,this.raycaster.components.raycaster.getIntersection(t));if(i){if(this.previousLocalY&&this.previousLocalY==i.point.y)return this.hoverIndicator.setAttribute("visible",!1),void this.hoverLabel.setAttribute("visible",!1);var r=this.el.object3D;r.updateMatrixWorld();var o=new THREE.Vector3,n=new THREE.Quaternion,a=new THREE.Vector3;r.matrixWorld.decompose(o,n,a);var s=new THREE.Vector3;s.x=i.point.x-o.x,s.y=i.point.y-o.y,s.z=i.point.z-o.z,this.previousLocalY=s.y;var l=null;(l=s.y<=-e/2?0:s.y>=e/2?1:(s.y+e/2)/e)!=this.data.hoverPercent&&t.setAttribute("gui-vertical-slider","hoverPercent",String(l));var u=t.getAttribute("gui-interactable"),d=u.hoverAction,c=window[d];"function"==typeof c&&c(l)}}},remove:function(){},pause:function(){},play:function(){},getOutputValue:function(t){var e=window[this.data.outputFunction];if("function"==typeof e){return e(t?this.data.hoverPercent:this.data.percent)}return null}}),AFRAME.registerPrimitive("a-gui-vertical-slider",{defaultComponents:{"gui-interactable":{},"gui-item":{type:"slider"},"gui-vertical-slider":{}},mappings:{"active-color":"gui-vertical-slider.activeColor","background-color":"gui-vertical-slider.backgroundColor","border-color":"gui-vertical-slider.borderColor","handle-color":"gui-vertical-slider.handleColor","handle-inner-depth":"gui-vertical-slider.handleInnerDepth","handle-inner-radius":"gui-vertical-slider.handleInnerRadius","handle-outer-depth":"gui-vertical-slider.handleOuterDepth","handle-outer-radius":"gui-vertical-slider.handleOuterRadius",height:"gui-item.height","hover-color":"gui-vertical-slider.hoverColor","hover-font-size":"gui-vertical-slider.hoverFontSize","hover-height":"gui-vertical-slider.hoverHeight","hover-margin":"gui-vertical-slider.hoverMargin","hover-percent":"gui-vertical-slider.hoverPercent","hover-width":"gui-vertical-slider.hoverWidth","key-code":"gui-interactable.keyCode","left-right-padding":"gui-vertical-slider.leftRightPadding",margin:"gui-item.margin",onclick:"gui-interactable.clickAction",onhover:"gui-interactable.hoverAction",opacity:"gui-vertical-slider.opacity","output-font-size":"gui-vertical-slider.outputFontSize","output-function":"gui-vertical-slider.outputFunction","output-height":"gui-vertical-slider.outputHeight","output-margin":"gui-vertical-slider.outputMargin","output-text-depth":"gui-vertical-slider.outputTextDepth","output-width":"gui-vertical-slider.outputWidth",percent:"gui-vertical-slider.percent","slider-bar-depth":"gui-vertical-slider.sliderBarDepth","slider-bar-width":"gui-vertical-slider.sliderBarWidth","top-bottom-padding":"gui-vertical-slider.topBottomPadding",width:"gui-item.width"}})},function(t,e,i){"use strict";var r=document.querySelector("#cursor");r&&r.addEventListener("stateremoved",function(t){"cursor-fusing"===t.detail.state&&(AFRAME.utils.entity.setComponentProperty(this,"geometry.thetaLength",360),AFRAME.utils.entity.setComponentProperty(this,"material.color",key_white),AFRAME.utils.entity.setComponentProperty(this,"scale","1 1 1"))})},function(t,e,i){"use strict";window.nearestPow2=function(t){Math.pow(2,Math.round(Math.log(t)/Math.log(2)))}},function(t,e,i){"use strict";window.normalYPosition=1.5,window.hiddenYPosition=1e3,window.key_orange="#ed5b21",window.key_orange_light="#ef8c60",window.key_grey="#22252a",window.key_grey_dark="#2c3037",window.key_grey_light="#606876",window.key_offwhite="#d3d3d4",window.key_white="#fff",window.icon_font={alert:"","alert-circled":"","android-add":"","android-add-circle":"","android-alarm-clock":"","android-alert":"","android-apps":"","android-archive":"","android-arrow-back":"","android-arrow-down":"","android-arrow-dropdown":"","android-arrow-dropdown-circle":"","android-arrow-dropleft":"","android-arrow-dropleft-circle":"","android-arrow-dropright":"","android-arrow-dropright-circle":"","android-arrow-dropup":"","android-arrow-dropup-circle":"","android-arrow-forward":"","android-arrow-up":"","android-attach":"","android-bar":"","android-bicycle":"","android-boat":"","android-bookmark":"","android-bulb":"","android-bus":"","android-calendar":"","android-call":"","android-camera":"","android-cancel":"","android-car":"","android-cart":"","android-chat":"","android-checkbox":"","android-checkbox-blank":"","android-checkbox-outline":"","android-checkbox-outline-blank":"","android-checkmark-circle":"","android-clipboard":"","android-close":"","android-cloud":"","android-cloud-circle":"","android-cloud-done":"","android-cloud-outline":"","android-color-palette":"","android-compass":"","android-contact":"","android-contacts":"","android-contract":"","android-create":"","android-delete":"","android-desktop":"","android-document":"","android-done":"","android-done-all":"","android-download":"","android-drafts":"","android-exit":"","android-expand":"","android-favorite":"","android-favorite-outline":"","android-film":"","android-folder":"","android-folder-open":"","android-funnel":"","android-globe":"","android-hand":"","android-hangout":"","android-happy":"","android-home":"","android-image":"","android-laptop":"","android-list":"","android-locate":"","android-lock":"","android-mail":"","android-map":"","android-menu":"","android-microphone":"","android-microphone-off":"","android-more-horizontal":"","android-more-vertical":"","android-navigate":"","android-notifications":"","android-notifications-none":"","android-notifications-off":"","android-open":"","android-options":"","android-people":"","android-person":"","android-person-add":"","android-phone-landscape":"","android-phone-portrait":"","android-pin":"","android-plane":"","android-playstore":"","android-print":"","android-radio-button-off":"","android-radio-button-on":"","android-refresh":"","android-remove":"","android-remove-circle":"","android-restaurant":"","android-sad":"","android-search":"","android-send":"","android-settings":"","android-share":"","android-share-alt":"","android-star":"","android-star-half":"","android-star-outline":"","android-stopwatch":"","android-subway":"","android-sunny":"","android-sync":"","android-textsms":"","android-time":"","android-train":"","android-unlock":"","android-upload":"","android-volume-down":"","android-volume-mute":"","android-volume-off":"","android-volume-up":"","android-walk":"","android-warning":"","android-watch":"","android-wifi":"",aperture:"",archive:"","arrow-down-a":"","arrow-down-b":"","arrow-down-c":"","arrow-expand":"","arrow-graph-down-left":"","arrow-graph-down-right":"","arrow-graph-up-left":"","arrow-graph-up-right":"","arrow-left-a":"","arrow-left-b":"","arrow-left-c":"","arrow-move":"","arrow-resize":"","arrow-return-left":"","arrow-return-right":"","arrow-right-a":"","arrow-right-b":"","arrow-right-c":"","arrow-shrink":"","arrow-swap":"","arrow-up-a":"","arrow-up-b":"","arrow-up-c":"",asterisk:"",at:"",backspace:"","backspace-outline":"",bag:"","battery-charging":"","battery-empty":"","battery-full":"","battery-half":"","battery-low":"",beaker:"",beer:"",bluetooth:"",bonfire:"",bookmark:"",bowtie:"",briefcase:"",bug:"",calculator:"",calendar:"",camera:"",card:"",cash:"",chatbox:"","chatbox-working":"",chatboxes:"",chatbubble:"","chatbubble-working":"",chatbubbles:"",checkmark:"","checkmark-circled":"","checkmark-round":"","chevron-down":"","chevron-left":"","chevron-right":"","chevron-up":"",clipboard:"",clock:"",close:"","close-circled":"","close-round":"","closed-captioning":"",cloud:"",code:"","code-download":"","code-working":"",coffee:"",compass:"",compose:"","connection-bars":"",contrast:"",crop:"",cube:"",disc:"",document:"","document-text":"",drag:"",earth:"",easel:"",edit:"",egg:"",eject:"",email:"","email-unread":"","erlenmeyer-flask":"","erlenmeyer-flask-bubbles":"",eye:"","eye-disabled":"",female:"",filing:"","film-marker":"",fireball:"",flag:"",flame:"",flash:"","flash-off":"",folder:"",fork:"","fork-repo":"",forward:"",funnel:"","gear-a":"","gear-b":"",grid:"",hammer:"",happy:"","happy-outline":"",headphone:"",heart:"","heart-broken":"",help:"","help-buoy":"","help-circled":"",home:"",icecream:"",image:"",images:"",information:"","information-circled":"",ionic:"","ios-alarm":"","ios-alarm-outline":"","ios-albums":"","ios-albums-outline":"","ios-americanfootball":"","ios-americanfootball-outline":"","ios-analytics":"","ios-analytics-outline":"","ios-arrow-back":"","ios-arrow-down":"","ios-arrow-forward":"","ios-arrow-left":"","ios-arrow-right":"","ios-arrow-thin-down":"","ios-arrow-thin-left":"","ios-arrow-thin-right":"","ios-arrow-thin-up":"","ios-arrow-up":"","ios-at":"","ios-at-outline":"","ios-barcode":"","ios-barcode-outline":"","ios-baseball":"","ios-baseball-outline":"","ios-basketball":"","ios-basketball-outline":"","ios-bell":"","ios-bell-outline":"","ios-body":"","ios-body-outline":"","ios-bolt":"","ios-bolt-outline":"","ios-book":"","ios-book-outline":"","ios-bookmarks":"","ios-bookmarks-outline":"","ios-box":"","ios-box-outline":"","ios-briefcase":"","ios-briefcase-outline":"","ios-browsers":"","ios-browsers-outline":"","ios-calculator":"","ios-calculator-outline":"","ios-calendar":"","ios-calendar-outline":"","ios-camera":"","ios-camera-outline":"","ios-cart":"","ios-cart-outline":"","ios-chatboxes":"","ios-chatboxes-outline":"","ios-chatbubble":"","ios-chatbubble-outline":"","ios-checkmark":"","ios-checkmark-empty":"","ios-checkmark-outline":"","ios-circle-filled":"","ios-circle-outline":"","ios-clock":"","ios-clock-outline":"","ios-close":"","ios-close-empty":"","ios-close-outline":"","ios-cloud":"","ios-cloud-download":"","ios-cloud-download-outline":"","ios-cloud-outline":"","ios-cloud-upload":"","ios-cloud-upload-outline":"","ios-cloudy":"","ios-cloudy-night":"","ios-cloudy-night-outline":"","ios-cloudy-outline":"","ios-cog":"","ios-cog-outline":"","ios-color-filter":"","ios-color-filter-outline":"","ios-color-wand":"","ios-color-wand-outline":"","ios-compose":"","ios-compose-outline":"","ios-contact":"","ios-contact-outline":"","ios-copy":"","ios-copy-outline":"","ios-crop":"","ios-crop-strong":"","ios-download":"","ios-download-outline":"","ios-drag":"","ios-email":"","ios-email-outline":"","ios-eye":"","ios-eye-outline":"","ios-fastforward":"","ios-fastforward-outline":"","ios-filing":"","ios-filing-outline":"","ios-film":"","ios-film-outline":"","ios-flag":"","ios-flag-outline":"","ios-flame":"","ios-flame-outline":"","ios-flask":"","ios-flask-outline":"","ios-flower":"","ios-flower-outline":"","ios-folder":"","ios-folder-outline":"","ios-football":"","ios-football-outline":"","ios-game-controller-a":"","ios-game-controller-a-outline":"","ios-game-controller-b":"","ios-game-controller-b-outline":"","ios-gear":"","ios-gear-outline":"","ios-glasses":"","ios-glasses-outline":"","ios-grid-view":"","ios-grid-view-outline":"","ios-heart":"","ios-heart-outline":"","ios-help":"","ios-help-empty":"","ios-help-outline":"","ios-home":"","ios-home-outline":"","ios-infinite":"","ios-infinite-outline":"","ios-information":"","ios-information-empty":"","ios-information-outline":"","ios-ionic-outline":"","ios-keypad":"","ios-keypad-outline":"","ios-lightbulb":"","ios-lightbulb-outline":"","ios-list":"","ios-list-outline":"","ios-location":"","ios-location-outline":"","ios-locked":"","ios-locked-outline":"","ios-loop":"","ios-loop-strong":"","ios-medical":"","ios-medical-outline":"","ios-medkit":"","ios-medkit-outline":"","ios-mic":"","ios-mic-off":"","ios-mic-outline":"","ios-minus":"","ios-minus-empty":"","ios-minus-outline":"","ios-monitor":"","ios-monitor-outline":"","ios-moon":"","ios-moon-outline":"","ios-more":"","ios-more-outline":"","ios-musical-note":"","ios-musical-notes":"","ios-navigate":"","ios-navigate-outline":"","ios-nutrition":"","ios-nutrition-outline":"","ios-paper":"","ios-paper-outline":"","ios-paperplane":"","ios-paperplane-outline":"","ios-partlysunny":"","ios-partlysunny-outline":"","ios-pause":"","ios-pause-outline":"","ios-paw":"","ios-paw-outline":"","ios-people":"","ios-people-outline":"","ios-person":"","ios-person-outline":"","ios-personadd":"","ios-personadd-outline":"","ios-photos":"","ios-photos-outline":"","ios-pie":"","ios-pie-outline":"","ios-pint":"","ios-pint-outline":"","ios-play":"","ios-play-outline":"","ios-plus":"","ios-plus-empty":"","ios-plus-outline":"","ios-pricetag":"","ios-pricetag-outline":"","ios-pricetags":"","ios-pricetags-outline":"","ios-printer":"","ios-printer-outline":"","ios-pulse":"","ios-pulse-strong":"","ios-rainy":"","ios-rainy-outline":"","ios-recording":"","ios-recording-outline":"","ios-redo":"","ios-redo-outline":"","ios-refresh":"","ios-refresh-empty":"","ios-refresh-outline":"","ios-reload":"","ios-reverse-camera":"","ios-reverse-camera-outline":"","ios-rewind":"","ios-rewind-outline":"","ios-rose":"","ios-rose-outline":"","ios-search":"","ios-search-strong":"","ios-settings":"","ios-settings-strong":"","ios-shuffle":"","ios-shuffle-strong":"","ios-skipbackward":"","ios-skipbackward-outline":"","ios-skipforward":"","ios-skipforward-outline":"","ios-snowy":"","ios-speedometer":"","ios-speedometer-outline":"","ios-star":"","ios-star-half":"","ios-star-outline":"","ios-stopwatch":"","ios-stopwatch-outline":"","ios-sunny":"","ios-sunny-outline":"","ios-telephone":"","ios-telephone-outline":"","ios-tennisball":"","ios-tennisball-outline":"","ios-thunderstorm":"","ios-thunderstorm-outline":"","ios-time":"","ios-time-outline":"","ios-timer":"","ios-timer-outline":"","ios-toggle":"","ios-toggle-outline":"","ios-trash":"","ios-trash-outline":"","ios-undo":"","ios-undo-outline":"","ios-unlocked":"","ios-unlocked-outline":"","ios-upload":"","ios-upload-outline":"","ios-videocam":"","ios-videocam-outline":"","ios-volume-high":"","ios-volume-low":"","ios-wineglass":"","ios-wineglass-outline":"","ios-world":"","ios-world-outline":"",ipad:"",iphone:"",ipod:"",jet:"",key:"",knife:"",laptop:"",leaf:"",levels:"",lightbulb:"",link:"","load-a":"","load-b":"","load-c":"","load-d":"",location:"","lock-combination":"",locked:"","log-in":"","log-out":"",loop:"",magnet:"",male:"",man:"",map:"",medkit:"",merge:"","mic-a":"","mic-b":"","mic-c":"",minus:"","minus-circled":"","minus-round":"","model-s":"",monitor:"",more:"",mouse:"","music-note":"",navicon:"","navicon-round":"",navigate:"",network:"","no-smoking":"",nuclear:"",outlet:"",paintbrush:"",paintbucket:"","paper-airplane":"",paperclip:"",pause:"",person:"","person-add":"","person-stalker":"","pie-graph":"",pin:"",pinpoint:"",pizza:"",plane:"",planet:"",play:"",playstation:"",plus:"","plus-circled":"","plus-round":"",podium:"",pound:"",power:"",pricetag:"",pricetags:"",printer:"","pull-request":"","qr-scanner":"",quote:"","radio-waves":"",record:"",refresh:"",reply:"","reply-all":"","ribbon-a":"","ribbon-b":"",sad:"","sad-outline":"",scissors:"",search:"",settings:"",share:"",shuffle:"","skip-backward":"","skip-forward":"","social-android":"","social-android-outline":"","social-angular":"","social-angular-outline":"","social-apple":"","social-apple-outline":"","social-bitcoin":"","social-bitcoin-outline":"","social-buffer":"","social-buffer-outline":"","social-chrome":"","social-chrome-outline":"","social-codepen":"","social-codepen-outline":"","social-css3":"","social-css3-outline":"","social-designernews":"","social-designernews-outline":"","social-dribbble":"","social-dribbble-outline":"","social-dropbox":"","social-dropbox-outline":"","social-euro":"","social-euro-outline":"","social-facebook":"","social-facebook-outline":"","social-foursquare":"","social-foursquare-outline":"","social-freebsd-devil":"","social-github":"","social-github-outline":"","social-google":"","social-google-outline":"","social-googleplus":"","social-googleplus-outline":"","social-hackernews":"","social-hackernews-outline":"","social-html5":"","social-html5-outline":"","social-instagram":"","social-instagram-outline":"","social-javascript":"","social-javascript-outline":"","social-linkedin":"","social-linkedin-outline":"","social-markdown":"","social-nodejs":"","social-octocat":"","social-pinterest":"","social-pinterest-outline":"","social-python":"","social-reddit":"","social-reddit-outline":"","social-rss":"","social-rss-outline":"","social-sass":"","social-skype":"","social-skype-outline":"","social-snapchat":"","social-snapchat-outline":"","social-tumblr":"","social-tumblr-outline":"","social-tux":"","social-twitch":"","social-twitch-outline":"","social-twitter":"","social-twitter-outline":"","social-usd":"","social-usd-outline":"","social-vimeo":"","social-vimeo-outline":"","social-whatsapp":"","social-whatsapp-outline":"","social-windows":"","social-windows-outline":"","social-wordpress":"","social-wordpress-outline":"","social-yahoo":"","social-yahoo-outline":"","social-yen":"","social-yen-outline":"","social-youtube":"","social-youtube-outline":"","soup-can":"","soup-can-outline":"",speakerphone:"",speedometer:"",spoon:"",star:"","stats-bars":"",steam:"",stop:"",thermometer:"",thumbsdown:"",thumbsup:"",toggle:"","toggle-filled":"",transgender:"","trash-a":"","trash-b":"",trophy:"",tshirt:"","tshirt-outline":"",umbrella:"",university:"",unlocked:"",upload:"",usb:"",videocamera:"","volume-high":"","volume-low":"","volume-medium":"","volume-mute":"",wand:"",waterdrop:"",wifi:"",wineglass:"",woman:"",wrench:"",xbox:""},window.getUniqueId=function(t){return t+"_"+(new Date).getTime().toString()+Math.random().toString().replace(".","")},window.getTextWidth=function(t,e){var i=getTextWidth.canvas||(getTextWidth.canvas=document.createElement("canvas")),r=i.getContext("2d");return r.font=e,r.measureText(t).width},window.drawText=function(t,e,i,r,o,n){var a=arguments.length>6&&void 0!==arguments[6]?arguments[6]:1,s=arguments.length>7&&void 0!==arguments[7]?arguments[7]:"center",l=arguments.length>8&&void 0!==arguments[8]?arguments[8]:"middle",u=arguments.length>9&&void 0!==arguments[9]?arguments[9]:"normal";t.font=u+" "+r+" "+o,t.fillStyle=n,t.textAlign=s,t.textBaseline=l,t.scale(a,a),t.clearRect(0,0,e.width,e.height);var d=i+"";if(d.match("char#")){var c=d.substring(d.indexOf("#")+1);"left"==s?t.fillText(String.fromCharCode(c),e.height/8,e.height/2):t.fillText(String.fromCharCode(c),e.width/2,e.height/2)}else"left"==s?t.fillText(d,e.height/8,e.height/2):t.fillText(d,e.width/2,e.height/2)},window.drawIcon=function(t,e,i,r,o){var n=arguments.length>5&&void 0!==arguments[5]?arguments[5]:1;t.font=i+" Ionicons",t.fillStyle=o,t.textAlign="center",t.textBaseline="middle",t.clearRect(0,0,e.width,e.height),t.scale(n,n),icon_font[r]?t.fillText(icon_font[r],e.width/2,e.height/2):t.fillText("?",e.width/2,e.height/2)}},function(t,e,i){"use strict";(function(t){function e(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function i(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}function r(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}var o=function t(e,i,r){null===e&&(e=Function.prototype);var o=Object.getOwnPropertyDescriptor(e,i);if(void 0===o){var n=Object.getPrototypeOf(e);return null===n?void 0:t(n,i,r)}if("value"in o)return o.value;var a=o.get;if(void 0!==a)return a.call(r)},n=function(){function t(t,e){for(var i=0;i0?t:e;if(v(i))try{var r=i(u);r===o&&l();var a=n(r);a?a.call(r,o.resolve,o.reject):o.resolve(r)}catch(t){o.reject(t)}else o[d>0?"resolve":"reject"](u)}var o=c();return h.push(r),d&&i(),o}function e(t,r){p++;var o=0;try{r===b&&l();var s=t>0&&n(r);s?s.call(r,a(function(t){o++,e(1,t)}),a(function(t){o++,e(-1,t)})):(d=t,u=r,i())}catch(t){d||o||e(-1,t)}}function i(){f||(setTimeout(r,0),f=1)}function r(){var t=h;f=0,h=[],t.forEach(o)}function o(t){t()}function n(t){var e=t&&(v(t)||"object"===(void 0===t?"undefined":s(t)))&&t.then;return v(e)&&e}function a(t){var e=0;return function(){for(var i=[],r=arguments.length;r--;)i[r]=arguments[r];e++||t.apply(this,i)}}function l(){throw new TypeError("Chaining cycle detected")}var u,d=0,h=[],f=0,p=0,g=a(function(t){p||e(1,t)}),m=a(function(t){p||e(-1,t)}),v=function(t){return"function"==typeof t},b={then:t,resolve:g,reject:m};return b}function h(){var t,e,i=new Promise(function(i,r){t=i,e=r});return{then:i.then.bind(i),resolve:t,reject:e}}function f(){function t(e,o){var n=e.id,a=e.name,s=e.dependencies;void 0===s&&(s=[]);var l=e.init;void 0===l&&(l=function(){});var u=e.getTransferables;if(void 0===u&&(u=null),!r[n])try{s=s.map(function(e){return e&&e.isWorkerModule&&(t(e,function(t){if(t instanceof Error)throw t}),e=r[e.id].value),e}),l=i("<"+a+">.init",l),u&&(u=i("<"+a+">.getTransferables",u));var d=null;"function"==typeof l?d=l.apply(void 0,s):console.error("worker module init function failed to rehydrate"),r[n]={id:n,value:d,getTransferables:u},o(d)}catch(t){t&&t.noLog||console.error(t),o(t)}}function e(t,e){function i(t){try{var i=r[n].getTransferables&&r[n].getTransferables(t);i&&Array.isArray(i)&&i.length||(i=void 0),e(t,i)}catch(t){console.error(t),e(t)}}var o,n=t.id,a=t.args;r[n]&&"function"==typeof r[n].value||e(new Error("Worker module "+n+": not found or its 'init' did not return a function"));try{var s=(o=r[n]).value.apply(o,a);s&&"function"==typeof s.then?s.then(i,function(t){return e(t instanceof Error?t:new Error(""+t))}):i(s)}catch(t){e(t)}}function i(t,e){var i=void 0;self.troikaDefine=function(t){return i=t};var r=URL.createObjectURL(new Blob(["/** "+t.replace(/\*/g,"")+" **/\n\ntroikaDefine(\n"+e+"\n)"],{type:"application/javascript"}));try{importScripts(r)}catch(t){console.error(t)}return URL.revokeObjectURL(r),delete self.troikaDefine,i}var r=Object.create(null);self.addEventListener("message",function(i){var r=i.data,o=r.messageId,n=r.action,a=r.data;try{"registerModule"===n&&t(a,function(t){t instanceof Error?postMessage({messageId:o,success:!1,error:t.message}):postMessage({messageId:o,success:!0,result:{isCallable:"function"==typeof t}})}),"callModule"===n&&e(a,function(t,e){t instanceof Error?postMessage({messageId:o,success:!1,error:t.message}):postMessage({messageId:o,success:!0,result:t},e||void 0)})}catch(t){postMessage({messageId:o,success:!1,error:t.stack})}})}function p(t){var e=function t(){for(var e=[],i=arguments.length;i--;)e[i]=arguments[i];return t._getInitResult().then(function(t){if("function"==typeof t)return t.apply(void 0,e);throw new Error("Worker module function was called but `init` did not return a callable function")})};return e._getInitResult=function(){var i=t.dependencies,r=t.init;i=Array.isArray(i)?i.map(function(t){return t&&t._getInitResult?t._getInitResult():t}):[];var o=L.all(i).then(function(t){return r.apply(null,t)});return e._getInitResult=function(){return o},o},e}function g(t){function e(){for(var t=[],i=arguments.length;i--;)t[i]=arguments[i];return l||(l=b(n,"registerModule",e.workerModuleData)),l.then(function(e){if(e.isCallable)return b(n,"callModule",{id:a,args:t});throw new Error("Worker module function was called but `init` did not return a callable function")})}if(!(t&&"function"==typeof t.init||W))throw new Error("requires `options.init` function");var i=t.dependencies,r=t.init,o=t.getTransferables,n=t.workerId;if(!z())return p(t);null==n&&(n="#default");var a="workerModule"+ ++B,s=t.name||a,l=null;return i=i&&i.map(function(t){return"function"!=typeof t||t.workerModuleData||(W=!0,t=g({workerId:n,name:"<"+s+"> function dependency: "+t.name,init:"function(){return (\n"+m(t)+"\n)}"}),W=!1),t&&t.workerModuleData&&(t=t.workerModuleData),t}),e.workerModuleData={isWorkerModule:!0,id:a,name:s,dependencies:i,init:m(r),getTransferables:o&&m(o)},e}function m(t){var e=t.toString();return!/^function/.test(e)&&/^\w+\s*\(/.test(e)&&(e="function "+e),e}function v(t){var e=j[t];if(!e){var i=m(f);e=j[t]=new Worker(URL.createObjectURL(new Blob(["/** Worker Module Bootstrap: "+t.replace(/\*/g,"")+" **/\n\n;("+i+")()"],{type:"application/javascript"}))),e.onmessage=function(t){var e=t.data,i=e.messageId,r=V[i];if(!r)throw new Error("WorkerModule response with empty or unknown messageId");delete V[i],V.count--,r(e)}}return e}function b(t,e,i){var r=L(),o=++G;return V[o]=function(t){t.success?r.resolve(t.result):r.reject(new Error("Error in worker "+e+" call: "+t.error))},V._count++,V.count>1e3&&console.warn("Large number of open WorkerModule requests, some may not be returning"),v(t).postMessage({messageId:o,action:e,data:i}),r}function y(e){function i(e,i){var r=t.ShaderChunk[i];return r?y(r):e}var r=/^[ \t]*#include +<([\w\d.\/]+)>/gm;return e.replace(r,i)}function A(e,i){var r=x(i),o=Y.get(e);if(o||Y.set(e,o=Object.create(null)),o[r])return new o[r];var n="_onBeforeCompile"+r,a=function(t){e.onBeforeCompile.call(this,t);var o=r+"|||"+t.vertexShader+"|||"+t.fragmentShader,a=Q[o];if(!a){var s=w(t,i,r);a=Q[o]=s}t.vertexShader=a.vertexShader,t.fragmentShader=a.fragmentShader,X(t.uniforms,this.uniforms),i.timeUniform&&(t.uniforms[i.timeUniform]={get value(){return Date.now()-q}}),this[n]&&this[n](t)},s=function(){return l(i.chained?e:e.clone())},l=function(o){var n=Object.create(o,u);return Object.defineProperty(n,"baseMaterial",{value:e}),Object.defineProperty(n,"id",{value:$++}),n.uuid=t.MathUtils.generateUUID(),n.uniforms=X({},o.uniforms,i.uniforms),n.defines=X({},o.defines,i.defines),n.defines["TROIKA_DERIVED_MATERIAL_"+r]="",n.extensions=X({},o.extensions,i.extensions),n._listeners=void 0,n},u={constructor:{value:s},isDerivedMaterial:{value:!0},customProgramCacheKey:{value:function(){return r}},onBeforeCompile:{get:function(){return a},set:function(t){this[n]=t}},copy:{writable:!0,configurable:!0,value:function(i){return e.copy.call(this,i),e.isShaderMaterial||e.isDerivedMaterial||(X(this.extensions,i.extensions),X(this.defines,i.defines),X(this.uniforms,t.UniformsUtils.clone(i.uniforms))),this}},clone:{writable:!0,configurable:!0,value:function(){var t=new e.constructor;return l(t).copy(this)}},getDepthMaterial:{writable:!0,configurable:!0,value:function(){var r=this._depthMaterial;return r||(r=this._depthMaterial=A(e.isDerivedMaterial?e.getDepthMaterial():new t.MeshDepthMaterial({depthPacking:t.RGBADepthPacking}),i),r.defines.IS_DEPTH_MATERIAL="",r.uniforms=this.uniforms),r}},getDistanceMaterial:{writable:!0,configurable:!0,value:function(){var r=this._distanceMaterial;return r||(r=this._distanceMaterial=A(e.isDerivedMaterial?e.getDistanceMaterial():new t.MeshDistanceMaterial,i),r.defines.IS_DISTANCE_MATERIAL="",r.uniforms=this.uniforms),r}},dispose:{writable:!0,configurable:!0,value:function(){var t=this._depthMaterial,i=this._distanceMaterial;t&&t.dispose(),i&&i.dispose(),e.dispose.call(this)}}};return o[r]=s,new s}function w(t,e,i){var r=t.vertexShader,o=t.fragmentShader,n=e.vertexDefs,a=e.vertexMainIntro,s=e.vertexMainOutro,l=e.vertexTransform,u=e.fragmentDefs,d=e.fragmentMainIntro,c=e.fragmentMainOutro,h=e.fragmentColorTransform,f=e.customRewriter,p=e.timeUniform;if(n=n||"",a=a||"",s=s||"",u=u||"",d=d||"",c=c||"",(l||f)&&(r=y(r)),(h||f)&&(o=o.replace(/^[ \t]*#include <((?:tonemapping|encodings|fog|premultiplied_alpha|dithering)_fragment)>/gm,"\n//!BEGIN_POST_CHUNK $1\n$&\n//!END_POST_CHUNK\n"),o=y(o)),f){var g=f({vertexShader:r,fragmentShader:o});r=g.vertexShader,o=g.fragmentShader}if(h){var m=[];o=o.replace(/^\/\/!BEGIN_POST_CHUNK[^]+?^\/\/!END_POST_CHUNK/gm,function(t){return m.push(t),""}),c=h+"\n"+m.join("\n")+"\n"+c}if(p){var v="\nuniform float "+p+";\n";n=v+n,u=v+u}return l&&(n=n+"\nvec3 troika_position_"+i+";\nvec3 troika_normal_"+i+";\nvec2 troika_uv_"+i+";\nvoid troikaVertexTransform"+i+"(inout vec3 position, inout vec3 normal, inout vec2 uv) {\n "+l+"\n}\n",a="\ntroika_position_"+i+" = vec3(position);\ntroika_normal_"+i+" = vec3(normal);\ntroika_uv_"+i+" = vec2(uv);\ntroikaVertexTransform"+i+"(troika_position_"+i+", troika_normal_"+i+", troika_uv_"+i+");\n"+a+"\n",r=r.replace(/\b(position|normal|uv)\b/g,function(t,e,r,o){return/\battribute\s+vec[23]\s+$/.test(o.substr(0,r))?e:"troika_"+e+"_"+i})),r=k(r,i,n,a,s),o=k(o,i,u,d,c),{vertexShader:r,fragmentShader:o}}function k(t,e,i,r,o){return(r||o||i)&&(t=t.replace(N,"\n"+i+"\nvoid troikaOrigMain"+e+"() {"),t+="\nvoid main() {\n "+r+"\n troikaOrigMain"+e+"();\n "+o+"\n}"),t}function C(t,e){return"uniforms"===t?void 0:"function"==typeof e?e.toString():e}function x(t){var e=JSON.stringify(t,C),i=Z.get(e);return null==i&&Z.set(e,i=++K),i}function S(t,e){function i(t,e,i,r,o,n,a){var s=1-a;return{x:s*s*t+2*s*a*i+a*a*o,y:s*s*e+2*s*a*r+a*a*n}}function r(t,e,i,r,o,n,a,s,l){var u=1-l;return{x:u*u*u*t+3*u*u*l*i+3*u*l*l*o+l*l*l*a,y:u*u*u*e+3*u*u*l*r+3*u*l*l*n+l*l*l*s}}function o(e,o){function l(t){return g+y*t/o}function u(t){return m+A*t/o}var d=new Uint8Array(o*o),c=e.xMax-e.xMin,h=e.yMax-e.yMin,f=Math.max(c,h),p=Math.max(c,h)/o*(a*o+.5),g=e.xMin-p,m=e.yMin-p,v=e.xMax+p,b=e.yMax+p,y=v-g,A=b-m,w=Math.max(y,A);if(e.pathCommandCount){var k=t(e),C=void 0,x=void 0,S=void 0,_=void 0;e.forEachPathCommand(function(t,e,o,n,a,l,u){switch(t){case"M":S=C=e,_=x=o;break;case"L":e===S&&o===_||k.addLineSegment(S,_,S=e,_=o);break;case"Q":for(var d={x:S,y:_},c=1;c=400)o(new Error(n.statusText));else if(n.status>0)try{var e=t(n.response);i(e)}catch(t){o(t)}},n.onerror=o,n.send()}catch(t){o(t)}}r()}function o(t,e){t||(t=h);var i=p[t];i?i.pending?i.pending.push(e):e(i):(p[t]={pending:[e]},r(t,function(e){var i=p[t].pending;p[t]=e,i.forEach(function(t){return t(e)})}))}function n(t,e,i){t||(t=h);var r=t+"@"+e,n=f[r];n?i(n):o(t,function(t){n=f[r]||(f[r]={fontObj:t,glyphs:{},glyphCount:0}),i(n)})}function s(t,i){var r=t.text,o=void 0===r?"":r,a=t.font,s=void 0===a?h:a,l=t.sdfGlyphSize,f=void 0===l?64:l,p=t.fontSize,m=void 0===p?1:p,v=t.letterSpacing,b=void 0===v?0:v,y=t.lineHeight,A=void 0===y?"normal":y,w=t.maxWidth,k=void 0===w?g:w,C=t.textAlign,x=void 0===C?"left":C,S=t.textIndent,_=void 0===S?0:S,U=t.whiteSpace,E=void 0===U?"normal":U,T=t.overflowWrap,F=void 0===T?"normal":T,I=t.anchorX,O=void 0===I?0:I,D=t.anchorY,R=void 0===D?0:D,M=t.includeCaretPositions,P=void 0!==M&&M,L=t.chunkedBoundsSize,z=void 0===L?8192:L,B=t.colorRanges,G=void 0===B?null:B,W=arguments.length>2&&void 0!==arguments[2]&&arguments[2],j=d(),V={total:0,fontLoad:0,layout:0,sdf:{},sdfTotal:0};o.indexOf("\r")>-1&&(console.warn("FontProcessor.process: got text with \\r chars; normalizing to \\n"),o=o.replace(/\r\n/g,"\n").replace(/\r/g,"\n")),m=+m,b=+b,k=+k,A=A||"normal",_=+_,n(s,f,function(t){var r=t.fontObj,n=isFinite(k),a=null,s=null,l=null,h=null,p=null,v=null,y=null,w=0,C=0,S="nowrap"!==E,U=r.ascender,T=r.descender,I=r.unitsPerEm;V.fontLoad=d()-j;var D=d(),M=m/I;"normal"===A&&(A=(U-T)/I),A*=m;var L=(A-(U-T)*M)/2,B=-(U*M+L),H=Math.min(A,(U-T)*M),N=(U+T)/2*M-H/2,X=_,q=new c,Y=[q];r.forEachGlyph(o,m,b,function(t,e,i){var r=o.charAt(i),a=t.advanceWidth*M,s=q.count,l=void 0;if("isEmpty"in t||(t.isWhitespace=!!r&&/\s/.test(r),t.isEmpty=t.xMin===t.xMax||t.yMin===t.yMax),t.isWhitespace||t.isEmpty||C++,S&&n&&!t.isWhitespace&&e+a+X>k&&s){if(q.glyphAt(s-1).glyphObj.isWhitespace)l=new c,X=-e;else for(var u=s;u--;){if(0===u&&"break-word"===F){l=new c,X=-e;break}if(q.glyphAt(u).glyphObj.isWhitespace){l=q.splitAt(u+1);var d=l.glyphAt(0).x;X-=d;for(var h=l.count;h--;)l.glyphAt(h).x-=d;break}}l&&(q.isSoftWrapped=!0,q=l,Y.push(q),w=k)}var f=q.glyphAt(q.count);f.glyphObj=t,f.x=e+X,f.width=a,f.charIndex=i,"\n"===r&&(q=new c,Y.push(q),X=-(e+a+b*m)+_)}),Y.forEach(function(t){for(var e=t.count;e--;){var i=t.glyphAt(e),r=i.glyphObj,o=i.x,n=i.width;if(!r.isWhitespace)return t.width=o+n,void(t.width>w&&(w=t.width))}});var Q=0,$=0;if(O&&("number"==typeof O?Q=-O:"string"==typeof O&&(Q=-w*("left"===O?0:"center"===O?.5:"right"===O?1:u(O)))),R)if("number"==typeof R)$=-R;else if("string"==typeof R){var K=Y.length*A;$="top"===R?0:"top-baseline"===R?-B:"middle"===R?K/2:"bottom"===R?K:"bottom-baseline"===R?K-L+T*M:u(R)*K}if(!W){s=new Float32Array(4*C),l=new Float32Array(C),v=[g,g,-g,-g],y=[];var Z=B;P&&(p=new Float32Array(3*o.length)),G&&(h=new Uint8Array(3*C));var J=0,tt=-1,et=-1,it=void 0,rt=void 0;Y.forEach(function(i){var r=i.count,n=i.width;if(r>0){var u=0,c=0;if("center"===x)u=(w-n)/2;else if("right"===x)u=w-n;else if("justify"===x&&i.isSoftWrapped){for(var m=0,b=r;b--;)if(!i.glyphAt(b).glyphObj.isWhitespace){for(;b--;)i.glyphAt(b).glyphObj,i.glyphAt(b).glyphObj.isWhitespace&&m++;break}c=(w-n)/m}for(var k=0;k1;)p[3*(tt+1)]=p[3*tt+1],p[3*(tt+1)+1]=p[3*tt+1],p[3*(tt+1)+2]=p[3*tt+2],tt++;tt=_}if(G)for(var U=C.charIndex;U>et;)et++,G.hasOwnProperty(et)&&(rt=G[et]);if(!S.isWhitespace&&!S.isEmpty){var E=J++,T=t.glyphs[S.index];if(!T){var F=d(),I=e(S,f);V.sdf[o.charAt(C.charIndex)]=d()-F,I.atlasIndex=t.glyphCount++,a||(a=[]),a.push(I),T=t.glyphs[S.index]={atlasIndex:I.atlasIndex,glyphObj:S,renderingBounds:I.renderingBounds}}var O=T.renderingBounds,D=4*E,R=C.x+Q,L=Z+$;s[D]=R+O[0]*M,s[D+1]=L+O[1]*M,s[D+2]=R+O[2]*M,s[D+3]=L+O[3]*M;var B=R+S.xMin*M,W=L+S.yMin*M,j=R+S.xMax*M,H=L+S.yMax*M;Bv[2]&&(v[2]=j),H>v[3]&&(v[3]=H),E%z==0&&(it={start:E,end:E,rect:[g,g,-g,-g]},y.push(it)),it.end++;var X=it.rect;if(BX[2]&&(X[2]=j),H>X[3]&&(X[3]=H),l[E]=T.atlasIndex,G){var q=3*E;h[q]=rt>>16&255,h[q+1]=rt>>8&255,h[q+2]=255&rt}}}}Z-=A})}for(var ot in V.sdf)V.sdfTotal+=V.sdf[ot];V.layout=d()-D-V.sdfTotal,V.total=d()-j,i({glyphBounds:s,glyphAtlasIndices:l,caretPositions:p,caretHeight:H,glyphColors:h,chunkedBounds:y,ascender:U*M,descender:T*M,lineHeight:A,topBaseline:B,blockBounds:[Q,$-Y.length*A,Q+w,$],visibleBounds:v,newGlyphSDFs:a,timings:V})})}function l(t,e){s(t,function(t){var i=a(t.blockBounds,4),r=i[0],o=i[1],n=i[2],s=i[3];e({width:n-r,height:s-o})},{metricsOnly:!0})}function u(t){var e=t.match(/^([\d.]+)%$/),i=e?parseFloat(e[1]):NaN;return isNaN(i)?0:i/100}function d(){return(self.performance||Date).now()}function c(){this.data=[]}var h=i.defaultFontURL,f=Object.create(null),p=Object.create(null),g=1/0;return c.prototype={width:0,isSoftWrapped:!1,get count(){return Math.ceil(this.data.length/4)},glyphAt:function(t){var e=c.flyweight;return e.data=this.data,e.index=t,e},splitAt:function(t){var e=new c;return e.data=this.data.splice(4*t),e}},c.flyweight=["glyphObj","x","width","charIndex"].reduce(function(t,e,i,r){return Object.defineProperty(t,e,{get:function(){return this.data[4*this.index+i]},set:function(t){this.data[4*this.index+i]=t}}),t},{data:null,index:0}),{process:s,measure:l,loadFont:o}}function U(){function t(){n&&(a.sort(function(t,e){return t.maxX-e.maxX}),n=!1)}function e(t,e,i,r){var o={x0:t,y0:e,x1:i,y1:r,minX:Math.min(t,i),minY:Math.min(e,r),maxX:Math.max(t,i),maxY:Math.max(e,r)};a.push(o),n=!0}function i(e,i){t();for(var n=1/0,s=1/0,l=a.length;l--;){var u=a[l];if(u.maxX+s<=e)break;if(e+s>u.minX&&i-su.minY){var d=o(e,i,u.x0,u.y0,u.x1,u.y1);di){n.y0>i!=n.y1>i&&e<(n.x1-n.x0)*(i-n.y0)/(n.y1-n.y0)+n.x0&&(r=!r)}}return r}function o(t,e,i,r,o,n){var a=o-i,s=n-r,l=a*a+s*s,u=l?Math.max(0,Math.min(1,((t-i)*a+(e-r)*s)/l)):0,d=t-(i+u*a),c=e-(r+u*s);return d*d+c*c}var n=!1,a=[];return{addLineSegment:e,findNearestSignedDistance:i}}function E(){var t=self,e={};return e.parse=function(t){var i=e._bin,r=new Uint8Array(t);if("ttcf"==i.readASCII(r,0,4)){var o=4;i.readUshort(r,o),o+=2,i.readUshort(r,o),o+=2;var n=i.readUint(r,o);o+=4;for(var a=[],s=0;s>>i&1)&&e++;return e},e._lctf.readClassDef=function(t,i){var r=e._bin,o=[],n=r.readUshort(t,i);if(i+=2,1==n){var a=r.readUshort(t,i);i+=2;var s=r.readUshort(t,i);i+=2;for(var l=0;l255?-1:e.CFF.glyphByUnicode(t,e.CFF.tableSE[i])},e.CFF.readEncoding=function(t,i,r){var o=(e._bin,[".notdef"]),n=t[i];if(i++,0!=n)throw"error: unknown encoding format: "+n;var a=t[i];i++;for(var s=0;s>4,g=15&f;if(15!=p&&h.push(p),15!=g&&h.push(g),15==g)break}for(var m="",v=[0,1,2,3,4,5,6,7,8,9,".","e","e-","reserved","-","endOfNumber"],b=0;b=a.xMax||a.yMin>=a.yMax)return null;if(a.noc>0){a.endPts=[];for(var s=0;s>>8;if(0!=(c&=15))throw"unknown kern table format: "+c;i=e.kern.readFormat0(t,i,l)}return l},e.kern.parseV1=function(t,i,r,o){var n=e._bin;n.readFixed(t,i);i+=4;var a=n.readUint(t,i);i+=4;for(var s={glyph1:[],rval:[]},l=0;l>>8;if(0!=(d&=15))throw"unknown kern table format: "+d;i=e.kern.readFormat0(t,i,s)}return s},e.kern.readFormat0=function(t,i,r){var o=e._bin,n=-1,a=o.readUshort(t,i);i+=2;o.readUshort(t,i);i+=2;o.readUshort(t,i);i+=2;o.readUshort(t,i);i+=2;for(var s=0;s=o.map.length?0:o.map[e];if(4==o.format){for(var n=-1,a=0;ae)return 0;return 65535&(0!=o.idRangeOffset[n]?o.glyphIdArray[e-o.startCount[n]+(o.idRangeOffset[n]>>1)-(o.idRangeOffset.length-n)]:e+o.idDelta[n])}if(12==o.format){if(e>o.groups[o.groups.length-1][1])return 0;for(var a=0;a-1?e.U._simpleGlyph(o,r):e.U._compoGlyph(o,i,r))},e.U._simpleGlyph=function(t,i){for(var r=0;r65535&&o++,r.push(e.U.codeToGlyph(t,n))}for(var o=0;o65535&&o++}var s=t.GSUB;if(null==s)return r;for(var l=s.lookupList,u=s.featureList,d=["rlig","liga","mset","isol","init","fina","medi","half","pres","blws"],c=[],h=0;hn)){for(var f=!0,p=0,g=0;gn)){for(var f=!0,g=0;g>1,a.length=0,l=!0}else if("o3"==S||"o23"==S){var _;_=a.length%2!=0,_&&!l&&(u=a.shift()+o.nominalWidthX),s+=a.length>>1,a.length=0,l=!0}else if("o4"==S)a.length>1&&!l&&(u=a.shift()+o.nominalWidthX,l=!0),d&&e.U.P.closePath(n),f+=a.pop(),e.U.P.moveTo(n,h,f),d=!0;else if("o5"==S)for(;a.length>0;)h+=a.shift(),f+=a.shift(),e.U.P.lineTo(n,h,f);else if("o6"==S||"o7"==S)for(var U=a.length,E="o6"==S,T=0;TMath.abs(w-f)?h=A+a.shift():f=w+a.shift(),e.U.P.curveTo(n,p,g,m,v,k,C),e.U.P.curveTo(n,b,y,A,w,h,f));else if("o14"==S){if(a.length>0&&!l&&(u=a.shift()+r.nominalWidthX,l=!0),4==a.length){var O=a.shift(),D=a.shift(),R=a.shift(),M=a.shift(),P=e.CFF.glyphBySE(r,R),L=e.CFF.glyphBySE(r,M);e.U._drawCFF(r.CharStrings[P],i,r,o,n),i.x=O,i.y=D,e.U._drawCFF(r.CharStrings[L],i,r,o,n)}d&&(e.U.P.closePath(n),d=!1)}else if("o19"==S||"o20"==S){var _;_=a.length%2!=0,_&&!l&&(u=a.shift()+o.nominalWidthX),s+=a.length>>1,a.length=0,l=!0,c+=s+7>>3}else if("o21"==S)a.length>2&&!l&&(u=a.shift()+o.nominalWidthX,l=!0),f+=a.pop(),h+=a.pop(),d&&e.U.P.closePath(n),e.U.P.moveTo(n,h,f),d=!0;else if("o22"==S)a.length>1&&!l&&(u=a.shift()+o.nominalWidthX,l=!0),h+=a.pop(),d&&e.U.P.closePath(n),e.U.P.moveTo(n,h,f),d=!0;else if("o25"==S){for(;a.length>6;)h+=a.shift(),f+=a.shift(),e.U.P.lineTo(n,h,f);p=h+a.shift(),g=f+a.shift(),m=p+a.shift(),v=g+a.shift(),h=m+a.shift(),f=v+a.shift(),e.U.P.curveTo(n,p,g,m,v,h,f)}else if("o26"==S)for(a.length%2&&(h+=a.shift());a.length>0;)p=h,g=f+a.shift(),m=p+a.shift(),v=g+a.shift(),h=m,f=v+a.shift(),e.U.P.curveTo(n,p,g,m,v,h,f);else if("o27"==S)for(a.length%2&&(f+=a.shift());a.length>0;)p=h+a.shift(),g=f,m=p+a.shift(),v=g+a.shift(),h=m+a.shift(),f=v,e.U.P.curveTo(n,p,g,m,v,h,f);else if("o10"==S||"o29"==S){var z="o10"==S?o:r;if(0==a.length)console.log("error: empty stack");else{var B=a.pop(),G=z.Subrs[B+z.Bias];i.x=h,i.y=f,i.nStems=s,i.haveWidth=l,i.width=u,i.open=d,e.U._drawCFF(G,i,r,o,n),h=i.x,f=i.y,s=i.nStems,l=i.haveWidth,u=i.width,d=i.open}}else if("o30"==S||"o31"==S){var U,W=a.length,I=0,j="o31"==S;for(U=-3&W,I+=W-U;I>>=1,e}function a(t,e,i){if(!e)return i;for(;t.bitcount<24;)t.tag|=t.source[t.sourceIndex++]<>>16-e;return t.tag>>>=e,t.bitcount-=e,r+i}function s(t,e){for(;t.bitcount<24;)t.tag|=t.source[t.sourceIndex++]<>>=1,++o,i+=e.table[o],r-=e.table[o]}while(r>=0);return t.tag=n,t.bitcount-=o,e.trans[i+r]}function l(t,e,i){var r,n,l,u,d,c;for(r=a(t,5,257),n=a(t,5,1),l=a(t,4,4),u=0;u<19;++u)C[u]=0;for(u=0;u8;)t.sourceIndex--,t.bitcount-=8;if(e=t.source[t.sourceIndex+1],e=256*e+t.source[t.sourceIndex],i=t.source[t.sourceIndex+3],i=256*i+t.source[t.sourceIndex+2],e!==(65535&~i))return p;for(t.sourceIndex+=4,r=e;r;--r)t.dest[t.destLen++]=t.source[t.sourceIndex++];return t.bitcount=0,f}function c(t,i){var r,o,s=new e(t,i);do{switch(r=n(s),a(s,2,0)){case 0:o=d(s);break;case 1:o=u(s,g,m);break;case 2:l(s,s.ltree,s.dtree),o=u(s,s.ltree,s.dtree);break;default:o=p}if(o!==f)throw new Error("Data error")}while(!r);return s.destLenb&&(b=k),C>y&&(y=C)}}else m=b=v=y=0;c=i[o]={index:o,advanceWidth:e.hmtx.aWidth[o],xMin:m,yMin:v,xMax:b,yMax:y,pathCommandCount:p.length,forEachPathCommand:function(t){for(var e=0,i=[],o=0,n=p.length;o65535?2:1}),u}};return o}var r={M:2,L:2,Q:4,C:6,Z:0};return function(r){var o=new Uint8Array(r,0,4),n=t._bin.readASCII(o,0,4);if("wOFF"===n)r=e(r);else if("wOF2"===n)throw new Error("woff2 fonts not supported");return i(t.parse(r)[0])}}function I(e,i){if(e=O({},e),e.font=D(e.font||tt.defaultFontURL),e.text=""+e.text,e.sdfGlyphSize=e.sdfGlyphSize||tt.sdfGlyphSize,null!=e.colorRanges){var r={};for(var o in e.colorRanges)if(e.colorRanges.hasOwnProperty(o)){var n=e.colorRanges[o];"number"!=typeof n&&(n=et.set(n).getHex()),r[o]=n}e.colorRanges=r}Object.freeze(e);var s=tt.textureWidth,l=tt.sdfExponent,u=e,d=u.sdfGlyphSize,c=e.font+"@"+d,h=it[c];h||(h=it[c]={sdfTexture:new t.DataTexture(new Uint8Array(d*s),s,d,t.LuminanceFormat,void 0,void 0,void 0,void 0,t.LinearFilter,t.LinearFilter)},h.sdfTexture.font=e.font),nt(e).then(function(t){t.newGlyphSDFs&&(t.newGlyphSDFs.forEach(function(t){for(var e=t.textureData,i=t.atlasIndex,r=h.sdfTexture.image;r.data.length<(i+1)*d*d;){var o=new Uint8Array(2*r.data.length);o.set(r.data),r.data=o,r.height*=2}for(var n=r.width/d,a=r.width*d*Math.floor(i/n)+i%n*d,s=0;st.y&&o[0]t.x)break}s(this,e)}},{key:"detail",set:function(t){var e=this;if(t!==this._detail){this._detail=t,("number"!=typeof t||t<1)&&(t=1);var i=o(t);["position","normal","uv"].forEach(function(t){e.attributes[t]=i.attributes[t].clone()}),this.setIndex(i.getIndex().clone())}},get:function(){return this._detail}}]),f}(t.InstancedBufferGeometry);return f.prototype.setAttribute||(f.prototype.setAttribute=function(t,e){return this.attributes[t]=e,this}),f}(),st="\nuniform vec2 uTroikaSDFTextureSize;\nuniform float uTroikaSDFGlyphSize;\nuniform vec4 uTroikaTotalBounds;\nuniform vec4 uTroikaClipRect;\nuniform mat3 uTroikaOrient;\nuniform bool uTroikaUseGlyphColors;\nuniform float uTroikaDistanceOffset;\nattribute vec4 aTroikaGlyphBounds;\nattribute float aTroikaGlyphIndex;\nattribute vec3 aTroikaGlyphColor;\nvarying vec2 vTroikaGlyphUV;\nvarying vec4 vTroikaTextureUVBounds;\nvarying vec3 vTroikaGlyphColor;\nvarying vec2 vTroikaGlyphDimensions;\n",lt="\nvec4 bounds = aTroikaGlyphBounds;\nvec4 outlineBounds = vec4(bounds.xy - uTroikaDistanceOffset, bounds.zw + uTroikaDistanceOffset);\nvec4 clippedBounds = vec4(\n clamp(outlineBounds.xy, uTroikaClipRect.xy, uTroikaClipRect.zw),\n clamp(outlineBounds.zw, uTroikaClipRect.xy, uTroikaClipRect.zw)\n);\nvec2 clippedXY = (mix(clippedBounds.xy, clippedBounds.zw, position.xy) - bounds.xy) / (bounds.zw - bounds.xy);\n\nposition.xy = mix(bounds.xy, bounds.zw, clippedXY);\n\nuv = (position.xy - uTroikaTotalBounds.xy) / (uTroikaTotalBounds.zw - uTroikaTotalBounds.xy);\n\nposition = uTroikaOrient * position;\nnormal = uTroikaOrient * normal;\n\nvTroikaGlyphUV = clippedXY.xy;\nvTroikaGlyphDimensions = vec2(bounds[2] - bounds[0], bounds[3] - bounds[1]);\n\n\nfloat txCols = uTroikaSDFTextureSize.x / uTroikaSDFGlyphSize;\nvec2 txUvPerGlyph = uTroikaSDFGlyphSize / uTroikaSDFTextureSize;\nvec2 txStartUV = txUvPerGlyph * vec2(\n mod(aTroikaGlyphIndex, txCols),\n floor(aTroikaGlyphIndex / txCols)\n);\nvTroikaTextureUVBounds = vec4(txStartUV, vec2(txStartUV) + txUvPerGlyph);\n",ut="\nuniform sampler2D uTroikaSDFTexture;\nuniform vec2 uTroikaSDFTextureSize;\nuniform float uTroikaSDFGlyphSize;\nuniform float uTroikaSDFExponent;\nuniform float uTroikaDistanceOffset;\nuniform bool uTroikaSDFDebug;\nvarying vec2 vTroikaGlyphUV;\nvarying vec4 vTroikaTextureUVBounds;\nvarying vec2 vTroikaGlyphDimensions;\n\nfloat troikaSdfValueToSignedDistance(float alpha) {\n // Inverse of encoding in SDFGenerator.js\n \n float maxDimension = max(vTroikaGlyphDimensions.x, vTroikaGlyphDimensions.y);\n float absDist = (1.0 - pow(2.0 * (alpha > 0.5 ? 1.0 - alpha : alpha), 1.0 / uTroikaSDFExponent)) * maxDimension;\n float signedDist = absDist * (alpha > 0.5 ? -1.0 : 1.0);\n return signedDist;\n}\n\nfloat troikaGlyphUvToSdfValue(vec2 glyphUV) {\n vec2 textureUV = mix(vTroikaTextureUVBounds.xy, vTroikaTextureUVBounds.zw, glyphUV);\n return texture2D(uTroikaSDFTexture, textureUV).r;\n}\n\nfloat troikaGlyphUvToDistance(vec2 uv) {\n return troikaSdfValueToSignedDistance(troikaGlyphUvToSdfValue(uv));\n}\n\nfloat troikaGetTextAlpha(float distanceOffset) {\n vec2 clampedGlyphUV = clamp(vTroikaGlyphUV, 0.5 / uTroikaSDFGlyphSize, 1.0 - 0.5 / uTroikaSDFGlyphSize);\n float distance = troikaGlyphUvToDistance(clampedGlyphUV);\n \n // Extrapolate distance when outside bounds:\n distance += clampedGlyphUV == vTroikaGlyphUV ? 0.0 : \n length((vTroikaGlyphUV - clampedGlyphUV) * vTroikaGlyphDimensions);\n\n \n \n #if defined(IS_DEPTH_MATERIAL) || defined(IS_DISTANCE_MATERIAL)\n float alpha = step(-distanceOffset, -distance);\n #else\n \n #if defined(GL_OES_standard_derivatives) || __VERSION__ >= 300\n float aaDist = length(fwidth(vTroikaGlyphUV * vTroikaGlyphDimensions)) * 0.5;\n #else\n float aaDist = vTroikaGlyphDimensions.x / 64.0;\n #endif\n \n float alpha = smoothstep(\n distanceOffset + aaDist,\n distanceOffset - aaDist,\n distance\n );\n #endif\n \n return alpha;\n}\n",dt="\nfloat alpha = uTroikaSDFDebug ?\n troikaGlyphUvToSdfValue(vTroikaGlyphUV) :\n troikaGetTextAlpha(uTroikaDistanceOffset);\n\n#if !defined(IS_DEPTH_MATERIAL) && !defined(IS_DISTANCE_MATERIAL)\ngl_FragColor.a *= alpha;\n#endif\n \nif (alpha == 0.0) {\n discard;\n}\n",ct=function(){function l(t){return Array.isArray(t)?t[0]:t}var u=new t.MeshBasicMaterial({color:16777215,side:t.DoubleSide,transparent:!0}),d=new t.Matrix4,c=new t.Vector3,h=new t.Vector3,f=[],p=new t.Vector3,g="+x+y",m=new t.Mesh(new t.PlaneBufferGeometry(1,1).translate(.5,.5,0),u),v={type:"syncstart"},b={type:"synccomplete"},y=["font","fontSize","letterSpacing","lineHeight","maxWidth","overflowWrap","text","textAlign","textIndent","whiteSpace","anchorX","anchorY","colorRanges","sdfGlyphSize"],A=y.concat("material","color","depthOffset","clipRect","orientation","glyphGeometryDetail"),w=function(y){function w(){e(this,w);var t=new at,r=i(this,(w.__proto__||Object.getPrototypeOf(w)).call(this,t,null));return r.text="",r.anchorX=0,r.anchorY=0,r.font=null,r.fontSize=.1,r.letterSpacing=0,r.lineHeight="normal",r.maxWidth=1/0,r.overflowWrap="normal",r.textAlign="left",r.textIndent=0,r.whiteSpace="normal",r.material=null,r.color=null,r.colorRanges=null,r.outlineWidth=0,r.outlineColor=0,r.depthOffset=0,r.clipRect=null,r.orientation=g,r.glyphGeometryDetail=1,r.sdfGlyphSize=null,r.debugSDF=!1,r}return r(w,y),n(w,[{key:"sync",value:function(t){var e=this;this._needsSync&&(this._needsSync=!1,this._isSyncing?(this._queuedSyncs||(this._queuedSyncs=[])).push(t):(this._isSyncing=!0,this.dispatchEvent(v),I({text:this.text,font:this.font,fontSize:this.fontSize||.1,letterSpacing:this.letterSpacing||0,lineHeight:this.lineHeight||"normal",maxWidth:this.maxWidth,textAlign:this.textAlign,textIndent:this.textIndent,whiteSpace:this.whiteSpace,overflowWrap:this.overflowWrap,anchorX:this.anchorX,anchorY:this.anchorY,colorRanges:this.colorRanges,includeCaretPositions:!0,sdfGlyphSize:this.sdfGlyphSize},function(i){e._isSyncing=!1,e._textRenderInfo=i,e.geometry.updateGlyphs(i.glyphBounds,i.glyphAtlasIndices,i.blockBounds,i.chunkedBounds,i.glyphColors);var r=e._queuedSyncs;r&&(e._queuedSyncs=null,e._needsSync=!0,e.sync(function(){r.forEach(function(t){return t&&t()})})),e.dispatchEvent(b),t&&t()})))}},{key:"onBeforeRender",value:function(t,e,i,r,o,n){this.sync(),o.isTroikaTextMaterial&&this._prepareForRender(o)}},{key:"dispose",value:function(){this.geometry.dispose()}},{key:"_prepareForRender",value:function(e){var i=e.isTextOutlineMaterial,r=e.uniforms,o=this.textRenderInfo;if(o){var n=o.sdfTexture,l=o.blockBounds;r.uTroikaSDFTexture.value=n,r.uTroikaSDFTextureSize.value.set(n.image.width,n.image.height),r.uTroikaSDFGlyphSize.value=o.sdfGlyphSize,r.uTroikaSDFExponent.value=o.sdfExponent,r.uTroikaTotalBounds.value.fromArray(l),r.uTroikaUseGlyphColors.value=!!o.glyphColors;var u=0;if(i){var f=this.outlineWidth;if("string"==typeof f){var m=f.match(/^([\d.]+)%$/),v=m?parseFloat(m[1]):NaN;f=(isNaN(v)?0:v/100)*this.fontSize}u=f}r.uTroikaDistanceOffset.value=u;var b=this.clipRect;if(b&&Array.isArray(b)&&4===b.length)r.uTroikaClipRect.value.fromArray(b);else{var y=100*(this.fontSize||.1);r.uTroikaClipRect.value.set(l[0]-y,l[1]-y,l[2]+y,l[3]+y)}this.geometry.applyClipRect(r.uTroikaClipRect.value)}r.uTroikaSDFDebug.value=!!this.debugSDF,e.polygonOffset=!!this.depthOffset,e.polygonOffsetFactor=e.polygonOffsetUnits=this.depthOffset||0;var A=i?this.outlineColor||0:this.color;if(null==A)delete e.color;else{var w=e.hasOwnProperty("color")?e.color:e.color=new t.Color;A===w._input&&"object"!==(void 0===A?"undefined":s(A))||w.set(w._input=A)}var k=this.orientation||g;if(k!==e._orientation){var C=r.uTroikaOrient.value;k=k.replace(/[^-+xyz]/g,"");var x=k!==g&&k.match(/^([-+])([xyz])([-+])([xyz])$/);if(x){var S=a(x,5),_=S[1],U=S[2],E=S[3],T=S[4];c.set(0,0,0)[U]="-"===_?1:-1,h.set(0,0,0)[T]="-"===E?-1:1,d.lookAt(p,c.cross(h),h),C.setFromMatrix4(d)}else C.identity();e._orientation=k}}},{key:"raycast",value:function(t,e){var i=this.textRenderInfo;if(i){var r=i.blockBounds;m.matrixWorld.multiplyMatrices(this.matrixWorld,d.set(r[2]-r[0],0,0,r[0],0,r[3]-r[1],0,r[1],0,0,1,0,0,0,0,1)),f.length=0,m.raycast(t,f);for(var o=0;o0?t:(t=+t,isNaN(t)?0:t)},stringify:function(t){return""+t}},overflowWrap:{type:"string",default:"normal",oneOf:["normal","break-word"]},textIndent:{type:"number",default:0},value:{type:"string"},whiteSpace:{default:"normal",oneOf:["normal","nowrap"]}},init:function(){var t;"a-troika-text"===this.el.tagName.toLowerCase()?t=this.el:(t=document.createElement("a-entity"),this.el.appendChild(t)),this.troikaTextEntity=t;var e=this.troikaTextMesh=new ct;t.setObject3D("mesh",e)},update:function(){var t=this.data,e=this.troikaTextMesh,i=this.troikaTextEntity;if(e.text=(t.value||"").replace(/\\n/g,"\n").replace(/\\t/g,"\t"),e.textAlign=t.align,e.anchorX=ft["align"===t.anchor?t.align:t.anchor]||"center",e.anchorY=pt[t.baseline]||"middle",e.color=t.color,e.clipRect=t.clipRect,e.depthOffset=t.depthOffset||0,e.font=t.font,e.fontSize=t.fontSize,e.letterSpacing=t.letterSpacing||0,e.lineHeight=t.lineHeight||"normal",e.outlineColor=t.outlineColor,e.outlineWidth=t.outlineWidth,e.overflowWrap=t.overflowWrap,e.textIndent=t.textIndent,e.whiteSpace=t.whiteSpace,e.maxWidth=t.maxWidth,e.sync(),i!==this.el){var r=this.el.getAttribute("troika-text-material");r?i.setAttribute("material",r):i.removeAttribute("material")}},remove:function(){this.troikaTextMesh.dispose(),this.troikaTextEntity!==this.el&&this.el.removeChild(this.troikaTextEntity)}});var ft={left:"left",center:"center",right:"right"},pt={top:"top",center:"middle",bottom:"bottom"},gt={},mt=P.default.components[ht].schema;Object.keys(mt).map(function(t){var e=t.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase();gt[e]=ht+"."+t}),P.default.registerPrimitive("a-troika-text",{defaultComponents:{"troika-text":{}},mappings:gt}),function(t){t.MathUtils||(t.MathUtils=t.Math)}(M)}(THREE,AFRAME)}).call(e,i(22))},function(t,e,i){"use strict";function r(){throw new Error("setTimeout has not been defined")}function o(){throw new Error("clearTimeout has not been defined")}function n(t){if(c===setTimeout)return setTimeout(t,0);if((c===r||!c)&&setTimeout)return c=setTimeout,setTimeout(t,0);try{return c(t,0)}catch(e){try{return c.call(null,t,0)}catch(e){return c.call(this,t,0)}}}function a(t){if(h===clearTimeout)return clearTimeout(t);if((h===o||!h)&&clearTimeout)return h=clearTimeout,clearTimeout(t);try{return h(t)}catch(e){try{return h.call(null,t)}catch(e){return h.call(this,t)}}}function s(){m&&p&&(m=!1,p.length?g=p.concat(g):v=-1,g.length&&l())}function l(){if(!m){var t=n(s);m=!0;for(var e=g.length;e;){for(p=g,g=[];++v1)for(var i=1;i20){var o=t.fontSize/750;t.fontSize=o}var r=e.getAttribute("gui-interactable");this.guiInteractable=r,e.setAttribute("geometry","primitive: plane; \n height: "+i.height+"; \n width: "+i.width+";\n "),e.setAttribute("material","shader: flat; \n transparent: true; \n opacity: 0.5; \n side:double; \n color:"+t.backgroundColor+";\n ");var a=document.createElement("a-entity");if(i.bevel){var n=1*i.bevelSize,l=i.bevelThickness;a.setAttribute("bevelbox","width: "+(i.width-i.width*n)+"; \n height: "+(i.height-i.height*n)+"; \n depth: "+(i.baseDepth-i.baseDepth*l)+";\n bevelThickness: 0;\n bevelSize: "+i.bevelSize+";\n "),a.setAttribute("position","0 0 0")}else a.setAttribute("geometry","primitive: box; \n width: "+i.width+"; \n height: "+i.height+"; \n depth: "+i.baseDepth+";\n "),a.setAttribute("position","0 0 "+i.baseDepth/2);a.setAttribute("rotation","0 0 0"),a.setAttribute("material","shader: flat; \n opacity: 1; \n side:double; \n color: "+t.borderColor+"\n "),e.appendChild(a),this.buttonContainer=a;var s=document.createElement("a-entity");if(i.bevel){var n=1*i.bevelSize,l=i.bevelThickness;s.setAttribute("bevelbox","width: "+(i.width-i.gap-(i.width-i.gap)*n)+"; \n height: "+(i.height-i.gap-(i.height-i.gap)*n)+"; \n depth: "+(i.depth-i.depth*l)+";\n bevelThickness: "+i.bevelThickness+";\n bevelSize: "+i.bevelSize+";\n "),s.setAttribute("position","0 0 0")}else s.setAttribute("geometry","primitive: box; \n width: "+(i.width-i.gap)+"; \n height: "+(i.height-i.gap)+"; \n depth: "+i.depth+";"),s.setAttribute("position","0 0 "+i.depth/2);s.setAttribute("material","shader: flat; \n opacity: 1; \n side:double; \n color: "+(t.toggleState?t.activeColor:t.backgroundColor)+"\n "),s.setAttribute("rotation","0 0 0"),e.appendChild(s),this.buttonEntity=s,this.setText(t.value),e.addEventListener("mouseenter",function(e){s.removeAttribute("animation__leave"),t.toggle||s.setAttribute("animation__enter","property: material.color; from: "+t.backgroundColor+"; to:"+t.hoverColor+"; dur:200;")}),e.addEventListener("mouseleave",function(e){t.toggle||(s.removeAttribute("animation__click"),s.setAttribute("animation__leave","property: material.color; from: "+t.hoverColor+"; to:"+t.backgroundColor+"; dur:200; easing: easeOutQuad;")),s.removeAttribute("animation__enter")}),e.addEventListener("focus",function(e){a.setAttribute("material","color",""+t.focusColor)}),e.addEventListener("blur",function(e){a.setAttribute("material","color",""+t.borderColor),t.toggle||(s.removeAttribute("animation__click"),s.setAttribute("animation__leave","property: material.color; from: "+t.hoverColor+"; to:"+t.backgroundColor+"; dur:200; easing: easeOutQuad;")),s.removeAttribute("animation__enter")}),e.addEventListener(t.on,function(i){if(t.toggle){var o=e.components["gui-button"];o.setActiveState(!o.data.toggleState)}else s.setAttribute("animation__click","property: material.color; from: "+t.activeColor+"; to:"+t.backgroundColor+"; dur:400; easing: easeOutQuad;");var a=r.clickAction,n=window[a];"function"==typeof n&&n(i)}),e.addEventListener("keyup",function(i){i.isComposing||229===i.keyCode||(13!=i.keyCode&&32!=i.keyCode||e.emit(t.on),i.preventDefault())}),e.setAttribute("role","button"),e.setAttribute("tabindex","0"),e.setAttribute("aria-label",t.value)},play:function(){},update:function(t){var e=this.data,i=this.el,o=i.getAttribute("gui-item");if(this.guiItem=o,i.setAttribute("geometry","primitive: plane; \n height: "+o.height+"; \n width: "+o.width+";\n "),i.setAttribute("material","shader: flat; \n transparent: true; \n opacity: 0.5; \n side:double; \n color:"+e.backgroundColor+";\n "),o.bevel){var r=1*o.bevelSize,a=o.bevelThickness;this.buttonContainer.setAttribute("bevelbox","width: "+(o.width-o.width*r)+"; \n height: "+(o.height-o.height*r)+"; \n depth: "+(o.baseDepth-o.baseDepth*a)+";\n bevelThickness: 0;\n bevelSize: "+o.bevelSize+";\n "),this.buttonContainer.setAttribute("position","0 0 0")}else this.buttonContainer.setAttribute("geometry","primitive: box; \n width: "+o.width+"; \n height: "+o.height+"; \n depth: "+o.baseDepth+";\n "),this.buttonContainer.setAttribute("position","0 0 "+o.baseDepth/2);if(this.buttonContainer.setAttribute("material","shader: flat; \n opacity: 1; \n side:double; \n color: "+e.borderColor+"\n "),o.bevel){var r=1*o.bevelSize,a=o.bevelThickness;this.buttonEntity.setAttribute("bevelbox","width: "+(o.width-o.gap-(o.width-o.gap)*r)+"; \n height: "+(o.height-o.gap-(o.height-o.gap)*r)+"; \n depth: "+(o.depth-o.depth*a)+";\n bevelThickness: "+o.bevelThickness+";\n bevelSize: "+o.bevelSize+";\n "),this.buttonEntity.setAttribute("position","0 0 0")}else this.buttonEntity.setAttribute("geometry","primitive: box; \n width: "+(o.width-o.gap)+"; \n height: "+(o.height-o.gap)+"; \n depth: "+o.depth+";\n "),this.buttonEntity.setAttribute("position","0 0 "+o.depth/2);if(this.buttonEntity.setAttribute("material","shader: flat; \n opacity: 1; \n side:double; \n color: "+(e.toggleState?e.activeColor:e.backgroundColor)+"\n "),this.textEntity){console.log("has textEntity: "+this.textEntity);var n=this.textEntity;n.parentNode.removeChild(n),this.setText(this.data.value)}else console.log("no textEntity!")},setActiveState:function(t){this.data.toggleState=t,t?(console.log("active, about to set active color"),this.buttonEntity.setAttribute("material","color",this.data.activeColor)):(console.log("not active, about to set background color"),this.buttonEntity.setAttribute("material","color",this.data.backgroundColor))},setText:function(t){var e=this.data,i=this.el,o=i.getAttribute("gui-item"),r=document.createElement("a-entity");this.textEntity=r,r.setAttribute("troika-text","value: "+t+"; \n align:center; \n anchor:center; \n baseline:center;\n letterSpacing:0;\n color:"+e.fontColor+"; \n font:"+e.fontFamily+";\n fontSize:"+e.fontSize+";\n depthOffset:1;\n maxWidth:"+o.width/1.05+";\n "),r.setAttribute("troika-text-material","shader: flat;"),o.bevel?r.setAttribute("position","0 0 "+(o.depth+o.bevelThickness/2+.05)):r.setAttribute("position","0 0 "+(o.depth/2+.05)),this.buttonEntity.appendChild(r)}}),AFRAME.registerPrimitive("a-gui-button",{defaultComponents:{"gui-interactable":{},"gui-item":{type:"button"},"gui-button":{}},mappings:{onclick:"gui-interactable.clickAction",onhover:"gui-interactable.hoverAction","key-code":"gui-interactable.keyCode",width:"gui-item.width",height:"gui-item.height",depth:"gui-item.depth","base-depth":"gui-item.baseDepth",gap:"gui-item.gap",radius:"gui-item.radius",margin:"gui-item.margin",bevel:"gui-item.bevel","bevel-segments":"gui-item.bevelSegments",steps:"gui-item.steps","bevel-size":"gui-item.bevelSize","bevel-offset":"gui-item.bevelOffset","bevel-thickness":"gui-item.bevelThickness",on:"gui-button.on",value:"gui-button.value","font-size":"gui-button.fontSize","font-family":"gui-button.fontFamily","font-color":"gui-button.fontColor","border-color":"gui-button.borderColor","focus-color":"gui-button.focusColor","background-color":"gui-button.backgroundColor","hover-color":"gui-button.hoverColor","active-color":"gui-button.activeColor",toggle:"gui-button.toggle","toggle-state":"gui-button.toggleState"}})},function(t,e,i){"use strict";AFRAME.registerComponent("gui-circle-loader",{schema:{loaded:{type:"number",default:.5},fontSize:{type:"number",default:.2},fontFamily:{type:"string",default:""},fontColor:{type:"string",default:key_grey},backgroundColor:{type:"string",default:key_offwhite},activeColor:{type:"string",default:key_orange}},init:function(){var t=this.data,e=this.el,i=e.getAttribute("gui-item");if(this.guiItem=i,t.fontSize>20){var o=t.fontSize/750;t.fontSize=o}e.setAttribute("geometry","primitive: plane; height: "+i.height+"; width: "+i.height+";"),e.setAttribute("material","shader: flat; transparent: true; opacity: 1; side:back; color:"+t.backgroundColor+";");var r=document.createElement("a-entity");r.setAttribute("geometry","primitive: cylinder; radius: "+i.height/2+"; height: 0.02;"),r.setAttribute("material","shader: flat; opacity: 1; side:double; color: "+t.backgroundColor),r.setAttribute("rotation","90 0 0"),r.setAttribute("position","0 0 0.01"),e.appendChild(r);var a=document.createElement("a-ring");a.setAttribute("material","shader: flat; opacity: 1; side:double; color: "+t.activeColor),a.setAttribute("radius-inner",""+i.height/3),a.setAttribute("radius-outer",""+i.height/2),a.setAttribute("theta-start","90"),a.setAttribute("theta-length",""+-360*t.loaded),a.setAttribute("rotation","0 0 0"),a.setAttribute("position","0 0 0.04"),a.id="loader_ring",e.appendChild(a),this.setText(t.loaded)},play:function(){},update:function(t){this.data,this.el;if(this.textEntity){console.log("has textEntity: "+this.textEntity);var e=this.textEntity;e.parentNode.removeChild(e),this.setText(this.data.loaded)}else console.log("no textEntity!")},setText:function(t){var e=document.createElement("a-entity");this.textEntity=e,e.setAttribute("troika-text","value: "+Math.round(100*t)+"; \n align:center; \n anchor:center; \n baseline:center;\n letterSpacing:0;\n color:"+this.data.fontColor+";\n font:"+this.data.fontFamily+";\n fontSize:"+this.data.fontSize+";\n depthOffset:1;\n maxWidth:"+this.guiItem.width/1.05+";\n "),e.setAttribute("position","0 0 0.05"),this.el.appendChild(e)}}),AFRAME.registerPrimitive("a-gui-circle-loader",{defaultComponents:{"gui-item":{type:"circle-loader"},"gui-circle-loader":{}},mappings:{width:"gui-item.width",height:"gui-item.height",margin:"gui-item.margin",loaded:"gui-circle-loader.loaded","font-size":"gui-circle-loader.fontSize","font-family":"gui-circle-loader.fontFamily","font-color":"gui-circle-loader.fontColor","background-color":"gui-circle-loader.backgroundColor","active-color":"gui-circle-loader.activeColor"}})},function(t,e,i){"use strict";AFRAME.registerComponent("gui-circle-timer",{schema:{countDown:{type:"number",default:10},fontSize:{type:"number",default:.2},fontFamily:{type:"string",default:""},fontColor:{type:"string",default:key_grey},borderColor:{type:"string",default:key_grey},backgroundColor:{type:"string",default:key_offwhite},activeColor:{type:"string",default:key_orange}},init:function(){var t=this.data,e=this.el,i=e.getAttribute("gui-item");this.guiItem=i;var o=e.getAttribute("gui-interactable");if(console.log("in timer callback, guiInteractable: "+JSON.stringify(o)),t.fontSize>20){var r=t.fontSize/750;t.fontSize=r}e.setAttribute("geometry","primitive: plane; height: "+i.height+"; width: "+i.height+";"),e.setAttribute("material","shader: flat; transparent: true; opacity: 1; side:back; color:"+t.backgroundColor+";");var a=document.createElement("a-entity");a.setAttribute("geometry","primitive: cylinder; radius: "+i.height/2+"; height: 0.02;"),a.setAttribute("material","shader: flat; opacity: 1; side:double; color: "+t.backgroundColor),a.setAttribute("rotation","90 0 0"),a.setAttribute("position","0 0 0.01"),e.appendChild(a);var n=document.createElement("a-ring");n.setAttribute("material","shader: flat; opacity: 1; side:double; color: "+t.borderColor),n.setAttribute("radius-inner",""+i.height/3),n.setAttribute("radius-outer",""+i.height/2),n.setAttribute("theta-start","-1"),n.setAttribute("theta-length","3"),n.setAttribute("position","0 0 0.04"),e.appendChild(n);var l=document.createElement("a-ring");l.setAttribute("material","shader: flat; opacity: 1; side:double; color: "+t.borderColor),l.setAttribute("radius-inner",""+i.height/3),l.setAttribute("radius-outer",""+i.height/2),l.setAttribute("theta-start","89"),l.setAttribute("theta-length","3"),l.setAttribute("position","0 0 0.04"),e.appendChild(l);var s=document.createElement("a-ring");s.setAttribute("material","shader: flat; opacity: 1; side:double; color: "+t.borderColor),s.setAttribute("radius-inner",""+i.height/3),s.setAttribute("radius-outer",""+i.height/2),s.setAttribute("theta-start","179"),s.setAttribute("theta-length","3"),s.setAttribute("position","0 0 0.04"),e.appendChild(s);var u=document.createElement("a-ring");u.setAttribute("material","shader: flat; opacity: 1; side:double; color: "+t.borderColor),u.setAttribute("radius-inner",""+i.height/3),u.setAttribute("radius-outer",""+i.height/2),u.setAttribute("theta-start","269"),u.setAttribute("theta-length","3"),u.setAttribute("position","0 0 0.04"),e.appendChild(u);var d=document.createElement("a-ring");d.setAttribute("material","shader: flat; opacity: 1; side:double; color: "+t.activeColor),d.setAttribute("radius-inner",""+i.height/3),d.setAttribute("radius-outer",""+i.height/2),d.setAttribute("theta-start","0"),d.setAttribute("theta-length","0"),d.setAttribute("rotation","0 180 90"),d.setAttribute("position","0 0 0.03"),e.appendChild(d),this.timerRing=d;this.initCount=t.countDown;this.setText(t.countDown)},update:function(t){var e=this.data,i=this.el;if(0!==Object.keys(t).length&&e.countDown!==t.countDown){i.getObject3D("mesh").material.color=e.color;var o=e.countDown,r=this.initCount,a=Math.round(100*(r-o)/r)/100*360;this.timerRing.setAttribute("theta-length",a),this.textEntity.setAttribute("troika-text","value: "+e.countDown+";"),1==o&&console.log("fire callback on the last second")}},setText:function(t){var e=document.createElement("a-entity");this.textEntity=e,e.setAttribute("troika-text","value: "+t+"; \n align:center; \n anchor:center; \n baseline:center;\n letterSpacing:0;\n color:"+this.data.fontColor+";\n font:"+this.data.fontFamily+";\n fontSize:"+this.data.fontSize+";\n depthOffset:1;\n maxWidth:"+this.guiItem.width/1.05+";\n "),e.setAttribute("position","0 0 0.05"),this.el.appendChild(e)},callback:function(){var t=this.el.getAttribute("gui-interactable"),e=t.clickAction;console.log("in timer callback, guiInteractable: "+JSON.stringify(t)),console.log("in button, clickActionFunctionName: "+e);var i=window[e];"function"==typeof i&&i()}}),AFRAME.registerPrimitive("a-gui-circle-timer",{defaultComponents:{"gui-item":{type:"circle-timer"},"gui-circle-timer":{}},mappings:{width:"gui-item.width",height:"gui-item.height",margin:"gui-item.margin","count-down":"gui-circle-timer.countDown","font-size":"gui-circle-timer.fontSize","font-family":"gui-circle-timer.fontFamily","font-color":"gui-circle-timer.fontColor","border-color":"gui-circle-timer.borderColor","background-color":"gui-circle-timer.backgroundColor","active-color":"gui-circle-timer.activeColor",callback:"gui-interactable.clickAction"}})},function(t,e,i){"use strict";AFRAME.registerComponent("gui-cursor",{schema:{color:{type:"string",default:key_white},hoverColor:{type:"string",default:key_white},activeColor:{type:"string",default:key_orange},distance:{type:"number",default:-1},design:{type:"string",default:"dot"}},init:function(){var t=this.cursor=this.el.getAttribute("cursor"),e=this.fuse=t.fuse,i=t.fuseTimeout,o=this.el,r=this.data,a=200,n=i-a;if(AFRAME.utils.entity.setComponentProperty(o,"raycaster.interval","500"),console.log("fuse: "+e+", fuseTimeout: "+i),"dot"==r.design){o.setAttribute("geometry","primitive: ring; radiusInner:0.000001; radiusOuter:0.025"),o.setAttribute("material","color: "+r.color+"; shader: flat; opacity:1;"),o.setAttribute("position","0 0 "+r.distance),o.setAttribute("animation__radiusInnerIn","property: geometry.radiusInner; from: 0.000001; to:0.0225; dur:"+a+"; easing:linear; startEvents: hovergui"),o.setAttribute("animation__radiusOuterIn","property: geometry.radiusOuter; from: 0.025; to:0.0275; dur:"+a+"; easing:linear; startEvents: hovergui"),o.setAttribute("animation__colorIn","property: material.color; from: "+r.color+"; to:"+r.hoverColor+"; dur:"+a+"; easing:linear; startEvents: hovergui"),o.setAttribute("animation__radiusInnerOut","property: geometry.radiusInner; from: 0.0225; to:0.000001; dur:"+a+"; easing:linear; startEvents: leavegui"),o.setAttribute("animation__radiusOuterOut","property: geometry.radiusOuter; from: 0.0275; to:0.025; dur:"+a+"; easing:linear; startEvents: leavegui"),o.setAttribute("animation__colorOut","property: material.color; from: "+r.hoverColor+"; to:"+r.color+"; dur:"+a+"; easing:linear; startEvents: leavegui"),o.setAttribute("animation__scale","property: scale; from: 1 1 1; to:1.25 1.25 1.25; dur:200; easing:easeInQuad; startEvents: click");var l=document.createElement("a-entity");if(l.setAttribute("geometry","primitive: ring; radiusInner:0.0275; radiusOuter:0.03; thetaLength:360"),l.setAttribute("material","color: #000000; shader: flat; opacity:0.25;"),l.setAttribute("position","0 0 0"),l.setAttribute("animation__radiusInnerIn","property: geometry.radiusInner; from: 0.0275; to:0.03; dur:"+a+"; easing:linear; startEvents: hovergui"),l.setAttribute("animation__radiusOuterIn","property: geometry.radiusOuter; from: 0.03; to:0.0325; dur:"+a+"; easing:linear; startEvents: hovergui"),l.setAttribute("animation__radiusInnerOut","property: geometry.radiusInner; from: 0.03; to:0.0275; dur:"+a+"; easing:linear; startEvents: leavegui"),l.setAttribute("animation__radiusOuterOut","property: geometry.radiusOuter; from: 0.0325; to:0.03; dur:"+a+"; easing:linear; startEvents: leavegui"),o.appendChild(l),this.cursorShadow=l,e){var s=document.createElement("a-entity");s.setAttribute("geometry","primitive: ring; radiusInner:0.03; radiusOuter:0.0375; thetaLength:0"),s.setAttribute("material","color: "+r.activeColor+"; shader: flat; opacity:1;"),s.setAttribute("position","0 0 0"),s.setAttribute("animation","property: geometry.thetaLength; from: 0; to:360; dur:"+n+"; delay: "+a+"; easing:linear; autoplay:false;"),o.appendChild(s),this.fuseLoader=s}}else if("ring"==r.design){o.setAttribute("geometry","primitive: ring; radiusInner:0.0225; radiusOuter:0.0275"),o.setAttribute("material","color: "+r.color+"; shader: flat; opacity:1;"),o.setAttribute("position","0 0 "+r.distance),o.setAttribute("animation__radiusInnerIn","property: geometry.radiusInner; from: 0.0225; to:0.025; dur:"+a+"; easing:linear; startEvents: hovergui"),o.setAttribute("animation__radiusOuterIn","property: geometry.radiusOuter; from: 0.0275; to:0.0325; dur:"+a+"; easing:linear; startEvents: hovergui"),o.setAttribute("animation__colorIn","property: material.color; from: "+r.color+"; to:"+r.hoverColor+"; dur:"+a+"; easing:linear; startEvents: hovergui"),o.setAttribute("animation__radiusInnerOut","property: geometry.radiusInner; from: 0.025; to:0.0225; dur:"+a+"; easing:linear; startEvents: leavegui"),o.setAttribute("animation__radiusOuterOut","property: geometry.radiusOuter; from: 0.0325; to:0.0275; dur:"+a+"; easing:linear; startEvents: leavegui"),o.setAttribute("animation__colorOut","property: material.color; from: "+r.hoverColor+"; to:"+r.color+"; dur:"+a+"; easing:linear; startEvents: leavegui"),o.setAttribute("animation__scale","property: scale; from: 1 1 1; to:1.25 1.25 1.25; dur:200; easing:easeInQuad; startEvents: click");var l=document.createElement("a-entity");if(l.setAttribute("geometry","primitive: ring; radiusInner:0.03; radiusOuter:0.0325; thetaLength:360"),l.setAttribute("material","color: #000000; shader: flat; opacity:0.25;"),l.setAttribute("position","0 0 0"),l.setAttribute("animation__radiusInnerIn","property: geometry.radiusInner; from: 0.03; to:0.0325; dur:"+a+"; easing:linear; startEvents: hovergui"),l.setAttribute("animation__radiusOuterIn","property: geometry.radiusOuter; from: 0.0325; to:0.0375; dur:"+a+"; easing:linear; startEvents: hovergui"),l.setAttribute("animation__radiusInnerOut","property: geometry.radiusInner; from: 0.0325; to:0.03; dur:"+a+"; easing:linear; startEvents: leavegui"),l.setAttribute("animation__radiusOuterOut","property: geometry.radiusOuter; from: 0.0375; to:0.0325; dur:"+a+"; easing:linear; startEvents: leavegui"),o.appendChild(l),this.cursorShadow=l,e){var s=document.createElement("a-entity");s.setAttribute("geometry","primitive: ring; radiusInner:0.035; radiusOuter:0.0425; thetaLength:0"),s.setAttribute("material","color: "+r.activeColor+"; shader: flat; opacity:1;"),s.setAttribute("position","0 0 0"),s.setAttribute("animation","property: geometry.thetaLength; from: 0; to:360; dur:"+n+"; delay: "+a+"; easing:linear; autoplay:false;"),o.appendChild(s),this.fuseLoader=s}}else if("reticle"==r.design){o.setAttribute("geometry","primitive: ring; radiusInner:0.000001; radiusOuter:0.0125; thetaLength:180;"),o.setAttribute("material","color: "+r.color+"; shader: flat; opacity:1;"),o.setAttribute("position","0 0 "+r.distance),o.setAttribute("animation__opacityIn","property: material.opacity; from: 1; to: 0; dur:"+a+"; easing:linear; startEvents: hovergui"),o.setAttribute("animation__opacityOut","property: material.opacity; from: 0; to: 1; dur:"+a+"; easing:linear; startEvents: leavegui");var u=document.createElement("a-entity");u.setAttribute("geometry","primitive: ring; radiusInner:0.000001; radiusOuter:0.0125; thetaLength:180; thetaStart:180;"),u.setAttribute("material","color: #000000; shader: flat; opacity:0.25;"),u.setAttribute("position","0 0 0"),u.setAttribute("animation__opacityIn","property: material.opacity; from: 0.25; to: 0; dur:"+a+"; easing:linear; startEvents: hovergui"),u.setAttribute("animation__opacityOut","property: material.opacity; from: 0; to: 0.25; dur:"+a+"; easing:linear; startEvents: leavegui"),o.appendChild(u),this.cursorCenter=u;var l=document.createElement("a-entity");l.setAttribute("geometry","primitive: ring; radiusInner:0.0125; radiusOuter:0.0145"),l.setAttribute("material","color: #000000; shader: flat; opacity:0.25;"),l.setAttribute("position","0 0 0"),l.setAttribute("animation__colorIn","property: material.color; from: #000000; to: "+r.color+"; dur:"+a+"; easing:linear; startEvents: hovergui"),l.setAttribute("animation__opacityIn","property: material.opacity; from: 0.25; to: 1; dur:"+a+"; easing:linear; startEvents: hovergui"),l.setAttribute("animation__colorOut","property: material.color; from: "+r.color+"; to: #000000; dur:"+a+"; easing:linear; startEvents: leavegui"),l.setAttribute("animation__opacityOut","property: material.opacity; from: 1; to: 0.25; dur:"+a+"; easing:linear; startEvents: leavegui"),o.appendChild(l),this.cursorShadow=l;var d=document.createElement("a-entity");d.setAttribute("geometry","primitive: plane; width:0.005; height:0.005;"),d.setAttribute("material","color: #000000; shader: flat; opacity:0.25;"),d.setAttribute("position","-0.0325 0.0325 0"),o.appendChild(d),this.cursorShadowTL=d;var c=document.createElement("a-entity");c.setAttribute("geometry","primitive: plane; width:0.005; height:0.005;"),c.setAttribute("material","color: #000000; shader: flat; opacity:0.25;"),c.setAttribute("position","-0.0325 -0.0325 0"),o.appendChild(c),this.cursorShadowBL=c;var h=document.createElement("a-entity");h.setAttribute("geometry","primitive: plane; width:0.005; height:0.005;"),h.setAttribute("material","color: #000000; shader: flat; opacity:0.25;"),h.setAttribute("position","0.0325 0.0325 0"),o.appendChild(h),this.cursorShadowTR=h;var g=document.createElement("a-entity");g.setAttribute("geometry","primitive: plane; width:0.005; height:0.005;"),g.setAttribute("material","color: #000000; shader: flat; opacity:0.25;"),g.setAttribute("position","0.0325 -0.0325 0"),o.appendChild(g),this.cursorShadowBR=g;var p=document.createElement("a-entity");p.setAttribute("geometry","primitive: plane; width:0.015; height:0.0035;"),p.setAttribute("material","color: "+r.color+"; shader: flat; opacity:1;"),p.setAttribute("position","-0.03 0.0375 0"),o.appendChild(p),this.cursorBoundTL=p;var m=document.createElement("a-entity");m.setAttribute("geometry","primitive: plane; width:0.0035; height:0.015;"),m.setAttribute("material","color: "+r.color+"; shader: flat; opacity:1;"),m.setAttribute("position","-0.0375 0.03 0"),o.appendChild(m),this.cursorBoundTL2=m;var b=document.createElement("a-entity");b.setAttribute("geometry","primitive: plane; width:0.015; height:0.0035;"),b.setAttribute("material","color: "+r.color+"; shader: flat; opacity:1;"),b.setAttribute("position","0.03 0.0375 0"),o.appendChild(b),this.cursorBoundTR=b;var f=document.createElement("a-entity");f.setAttribute("geometry","primitive: plane; width:0.0035; height:0.015;"),f.setAttribute("material","color: "+r.color+"; shader: flat; opacity:1;"),f.setAttribute("position","0.0375 0.03 0"),o.appendChild(f),this.cursorBoundTR2=f;var y=document.createElement("a-entity");y.setAttribute("geometry","primitive: plane; width:0.015; height:0.0035;"),y.setAttribute("material","color: "+r.color+"; shader: flat; opacity:1;"),y.setAttribute("position","-0.03 -0.0375 0"),o.appendChild(y),this.cursorBoundBL=y;var v=document.createElement("a-entity");v.setAttribute("geometry","primitive: plane; width:0.0035; height:0.015;"),v.setAttribute("material","color: "+r.color+"; shader: flat; opacity:1;"),v.setAttribute("position","-0.0375 -0.03 0"),o.appendChild(v),this.cursorBoundBL2=v;var A=document.createElement("a-entity");A.setAttribute("geometry","primitive: plane; width:0.015; height:0.0035;"),A.setAttribute("material","color: "+r.color+"; shader: flat; opacity:1;"),A.setAttribute("position","0.03 -0.0375 0"),o.appendChild(A),this.cursorBoundBR=A;var w=document.createElement("a-entity");if(w.setAttribute("geometry","primitive: plane; width:0.0035; height:0.015;"),w.setAttribute("material","color: "+r.color+"; shader: flat; opacity:1;"),w.setAttribute("position","0.0375 -0.03 0"),o.appendChild(w),this.cursorBoundBR2=w,e){var s=document.createElement("a-entity");s.setAttribute("geometry","primitive: plane; width:0.000001; height:0.01;"),s.setAttribute("material","color: "+r.activeColor+"; shader: flat; opacity:1;"),s.setAttribute("position","0 -0.05 0"),s.setAttribute("animation","property: geometry.width; from: 0; to: 0.075; dur:"+n+"; delay:"+a+"; easing:linear; autoplay:false;"),o.appendChild(s),this.fuseLoader=s}}else if("cross"==r.design){o.setAttribute("geometry","primitive: ring; radiusInner:0.035; radiusOuter:0.0375"),o.setAttribute("material","color: "+r.color+"; shader: flat; opacity:1;"),o.setAttribute("position","0 0 "+r.distance),o.setAttribute("animation__radiusInnerIn","property: geometry.radiusInner; from: 0.035; to: 0.0315; dur:"+a+"; easing:linear; startEvents: hovergui"),o.setAttribute("animation__radiusInnerOut","property: geometry.radiusInner; from: 0.0315; to: 0.035; dur:"+a+"; easing:linear; startEvents: leavegui");var l=document.createElement("a-entity");l.setAttribute("geometry","primitive: ring; radiusInner:0.0375; radiusOuter:0.04; thetaLength:360"),l.setAttribute("material","color: #000000; shader: flat; opacity:0.25;"),l.setAttribute("position","0 0 0"),o.appendChild(l),this.cursorShadow=l;var C=document.createElement("a-entity");C.setAttribute("geometry","primitive: plane; width:0.0035; height:0.01875"),C.setAttribute("material","color: "+r.color+"; shader: flat; opacity:1;"),C.setAttribute("position","0 0.028125 0"),C.setAttribute("animation__widthIn","property: geometry.width; from: 0.0035; to: 0.007; dur:"+n+"; easing:linear; startEvents: hovergui"),C.setAttribute("animation__widthOut","property: geometry.width; from: 0.007; to: 0.0035; dur:"+n+"; easing:linear; startEvents: leavegui"),o.appendChild(C),this.cursorVerticalTop=C;var k=document.createElement("a-entity");k.setAttribute("geometry","primitive: plane; width:0.0035; height:0.01875"),k.setAttribute("material","color: "+r.color+"; shader: flat; opacity:1;"),k.setAttribute("position","0 -0.028125 0"),k.setAttribute("animation__widthIn","property: geometry.width; from: 0.0035; to: 0.007; dur:"+n+"; easing:linear; startEvents: hovergui"),k.setAttribute("animation__widthOut","property: geometry.width; from: 0.007; to: 0.0035; dur:"+n+"; easing:linear; startEvents: leavegui"),o.appendChild(k),this.cursorVerticalBottom=k;var E=document.createElement("a-entity");E.setAttribute("geometry","primitive: plane; width:0.01875; height:0.0035"),E.setAttribute("material","color: "+r.color+"; shader: flat; opacity:1;"),E.setAttribute("position","-0.028125 0 0"),E.setAttribute("animation__heightIn","property: geometry.height; from: 0.0035; to: 0.007; dur:"+n+"; easing:linear; startEvents: hovergui"),E.setAttribute("animation__heightOut","property: geometry.height; from: 0.007; to: 0.0035; dur:"+n+"; easing:linear; startEvents: leavegui"),o.appendChild(E),this.cursorHorizontalLeft=E;var _=document.createElement("a-entity");if(_.setAttribute("geometry","primitive: plane; width:0.01875; height:0.0035"),_.setAttribute("material","color: "+r.color+"; shader: flat; opacity:1;"),_.setAttribute("position","0.028125 0 0"),_.setAttribute("animation__heightIn","property: geometry.height; from: 0.0035; to: 0.007; dur:"+n+"; easing:linear; startEvents: hovergui"),_.setAttribute("animation__heightOut","property: geometry.height; from: 0.007; to: 0.0035; dur:"+n+"; easing:linear; startEvents: leavegui"),o.appendChild(_),this.cursorHorizontalRight=_,e){var s=document.createElement("a-entity");s.setAttribute("geometry","primitive: ring; radiusInner:0.0415; radiusOuter:0.0485; thetaLength:0"),s.setAttribute("material","color: "+r.activeColor+"; shader: flat; opacity:1;"),s.setAttribute("position","0 0 0"),s.setAttribute("animation","property: geometry.thetaLength; from: 0; to: 360; dur:"+n+"; delay:"+a+"; easing:linear; autoplay:false;"),o.appendChild(s),this.fuseLoader=s}}o.addEventListener("mouseenter",function(){console.log("in gui-cursor mousenter, el: "+o),o.emit("hovergui"),"dot"==r.design||"ring"==r.design?l.emit("hovergui"):"cross"==r.design?(l.emit("hovergui"),C.emit("hovergui"),k.emit("hovergui"),E.emit("hovergui"),_.emit("hovergui")):"reticle"==r.design&&(centerHoverAniOpacity.emit("hovergui"),cursorHoverAniColor.emit("hovergui"),cursorHoverAniOpacity.emit("hovergui"))}),o.addEventListener("mouseleave",function(){console.log("in gui-cursor mouseleave, el: "+o),o.emit("leavegui"),"dot"==r.design||"ring"==r.design?l.emit("leavegui"):"cross"==r.design?(C.emit("leavegui"),k.emit("leavegui"),E.emit("leavegui"),_.emit("leavegui")):"reticle"==r.design&&(centerHoverAniOpacity.emit("leavegui"),cursorHoverAniColor.emit("leavegui"),cursorHoverAniOpacity.emit("leavegui")),e&&(s.object3D.el.components.animation.animation.pause(),s.object3D.el.components.animation.animation.seek(0)),o.setAttribute("scale","1 1 1")}),e&&o.addEventListener("fusing",function(){s.object3D.el.components.animation.animation.play()}),o.addEventListener("stateremoved",function(t){console.log("evt.detail "+t.detail),"cursor-fusing"===t.detail.state||"cursor-fusing"===t.detail?"dot"==r.design||"ring"==r.design||"cross"==r.design?e&&(s.object3D.el.components.animation.animation.pause(),s.object3D.el.components.animation.animation.seek(0),AFRAME.utils.entity.setComponentProperty(s,"geometry.thetaLength","0")):"reticle"==r.design&&e&&(s.object3D.el.components.animation.animation.pause(),s.object3D.el.components.animation.animation.seek(0),AFRAME.utils.entity.setComponentProperty(s,"geometry.width","0.000001")):"cursor-hovering"!==t.detail.state&&"cursor-hovering"!==t.detail||("dot"==r.design||"ring"==r.design?(AFRAME.utils.entity.setComponentProperty(this,"scale","1 1 1"),e&&AFRAME.utils.entity.setComponentProperty(s,"geometry.thetaLength","0")):"cross"==r.design?e&&AFRAME.utils.entity.setComponentProperty(s,"geometry.thetaLength","0"):"reticle"==r.design&&e&&AFRAME.utils.entity.setComponentProperty(s,"geometry.width","0.000001"))})},update:function(){},tick:function(){},remove:function(){},pause:function(){},play:function(){}}),AFRAME.registerPrimitive("a-gui-cursor",{defaultComponents:{cursor:{},"gui-cursor":{}},mappings:{fuse:"cursor.fuse","fuse-timeout":"cursor.fuseTimeout",color:"gui-cursor.color","hover-color":"gui-cursor.hoverColor","active-color":"gui-cursor.activeColor",distance:"gui-cursor.distance",design:"gui-cursor.design"}})},function(t,e,i){"use strict";var o=function(t,e){new MutationObserver(function(t,i){t.forEach(function(t){console.log(t),t.addedNodes.length&&e(t.target,t.addedNodes)})}).observe(t,{childList:!0})};AFRAME.registerComponent("gui-flex-container",{schema:{flexDirection:{type:"string",default:"row"},justifyContent:{type:"string",default:"flexStart"},alignItems:{type:"string",default:"flexStart"},itemPadding:{type:"number",default:0},opacity:{type:"number",default:0},isTopContainer:{type:"boolean",default:!1},panelColor:{type:"string",default:key_grey},panelRounded:{type:"number",default:.05},styles:{fontFamily:{type:"string",default:"Helvetica"},fontColor:{type:"string",default:key_offwhite},borderColor:{type:"string",default:key_offwhite},backgroundColor:{type:"string",default:key_grey},hoverColor:{type:"string",default:key_grey_dark},activeColor:{type:"string",default:key_orange},handleColor:{type:"string",default:key_offwhite}}},init:function(){console.log("in aframe-gui-component init for: "+this.el.getAttribute("id"));var t=this.el.getAttribute("gui-item");this.data.isTopContainer?this.setBackground():this.el.setAttribute("rounded","height: "+t.height+"; width: "+t.width+"; opacity: "+this.data.opacity+"; color: "+this.data.panelColor+"; radius:"+this.data.panelRounded+"; depthWrite:false; polygonOffset:true; polygonOffsetFactor: 1;"),this.children=this.el.getChildEntities();var e=0,i=0;if("row"==this.data.flexDirection){if("flexStart"==this.data.justifyContent)e=0;else if("center"==this.data.justifyContent||"flexEnd"==this.data.justifyContent){for(var r=0,a=0;a0){console.log("panel position: "+JSON.stringify(this.el.getAttribute("position")));var t=this.el.getAttribute("gui-item"),e=document.createElement("a-entity");e.setAttribute("rounded","height: "+t.height+"; width: "+t.width+"; opacity: "+this.data.opacity+"; color: "+this.data.panelColor+"; radius:"+this.data.panelRounded+"; depthWrite:false; polygonOffset:true; polygonOffsetFactor: 2;"),console.log("about to set panel background color to: : "+this.data.panelColor),e.setAttribute("position",this.el.getAttribute("position").x+" "+this.el.getAttribute("position").y+" "+(this.el.getAttribute("position").z-.0125)),e.setAttribute("rotation",this.el.getAttribute("rotation").x+" "+this.el.getAttribute("rotation").y+" "+this.el.getAttribute("rotation").z),this.el.parentNode.insertBefore(e,this.el)}}}),AFRAME.registerPrimitive("a-gui-flex-container",{defaultComponents:{"gui-item":{type:"flex-container"},"gui-flex-container":{}},mappings:{width:"gui-item.width",height:"gui-item.height",margin:"gui-item.margin","flex-direction":"gui-flex-container.flexDirection","justify-content":"gui-flex-container.justifyContent","align-items":"gui-flex-container.alignItems","item-padding":"gui-flex-container.itemPadding",opacity:"gui-flex-container.opacity","is-top-container":"gui-flex-container.isTopContainer","panel-color":"gui-flex-container.panelColor","panel-rounded":"gui-flex-container.panelRounded","font-family":"gui-flex-container.styles.fontFamily","font-color":"gui-flex-container.styles.fontColor","border-color":"gui-flex-container.styles.borderColor","background-color":"gui-flex-container.styles.backgroundColor","hover-color":"gui-flex-container.styles.hoverColor","active-color":"gui-flex-container.styles.activeColor","handle-color":"gui-flex-container.styles.handleColor"}})},function(t,e,i){"use strict";AFRAME.registerComponent("gui-icon-button",{schema:{on:{default:"click"},toggle:{type:"boolean",default:!1},toggleState:{type:"boolean",default:!1},icon:{type:"string",default:"f0f3"},iconActive:{type:"string",default:""},iconFontSize:{type:"number",default:.4},iconFont:{type:"string",default:"assets/fonts/fa-regular-400.ttf"},fontColor:{type:"string",default:key_offwhite},borderColor:{type:"string",default:key_offwhite},backgroundColor:{type:"string",default:key_grey},hoverColor:{type:"string",default:key_grey_dark},activeColor:{type:"string",default:key_orange}},init:function(){var t=this.data,e=this.el,i=e.getAttribute("gui-item");this.guiItem=i;var o=(this.toggleState=t.toggle,e.getAttribute("gui-interactable"));if(this.guiInteractable=o,t.iconFontSize>20){var r=t.iconFontSize/750;t.iconFontSize=r}e.setAttribute("geometry","primitive: plane; height: "+i.height+"; width: "+i.width+";"),e.setAttribute("material","shader: flat; transparent: true; opacity: 0.0; alphaTest: 0.5; side:double; color:"+t.backgroundColor+";");var a=document.createElement("a-entity");a.setAttribute("geometry","primitive: cylinder; radius: "+i.height/2+"; height: 0.02;"),a.setAttribute("material","shader: flat; opacity: 1; side:double; color: "+t.borderColor),a.setAttribute("rotation","90 0 0"),a.setAttribute("position","0 0 0.01"),e.appendChild(a);var n=document.createElement("a-entity");n.setAttribute("geometry","primitive: cylinder; radius: "+i.height/2.05+"; height: 0.04;"),n.setAttribute("material","shader: flat; opacity: 1; side:double; color: "+t.backgroundColor),n.setAttribute("rotation","90 0 0"),n.setAttribute("position","0 0 0.02"),e.appendChild(n),this.buttonEntity=n,this.setIcon(t.icon),e.addEventListener("mouseenter",function(e){n.removeAttribute("animation__leave"),t.toggle||n.setAttribute("animation__enter","property: material.color; from: "+t.backgroundColor+"; to:"+t.hoverColor+"; dur:200;")}),e.addEventListener("mouseleave",function(e){t.toggle||(n.removeAttribute("animation__click"),n.setAttribute("animation__leave","property: material.color; from: "+t.hoverColor+"; to:"+t.backgroundColor+"; dur:200; easing: easeOutQuad;")),n.removeAttribute("animation__enter")}),e.addEventListener(t.on,function(i){if(t.toggle){var r=e.components["gui-button"];r.setActiveState(!r.data.toggleState)}else n.setAttribute("animation__click","property: material.color; from: "+t.activeColor+"; to:"+t.backgroundColor+"; dur:400; easing: easeOutQuad;");var a=o.clickAction,l=window[a];"function"==typeof l&&l(i)}),e.setAttribute("role","button")},play:function(){},update:function(t){console.log("In button update, toggle: "+this.toggleState);this.data,this.el;if(this.iconEntity){console.log("has iconEntity: "+this.iconEntity);var e=this.iconEntity;e.parentNode.removeChild(e),this.setIcon(this.data.icon)}else console.log("no iconEntity!")},setActiveState:function(t){this.data.toggleState=t,t?(console.log("active, about to set active color"),this.buttonEntity.setAttribute("material","color",this.data.activeColor)):(console.log("not active, about to set background color"),this.buttonEntity.setAttribute("material","color",this.data.backgroundColor))},setIcon:function(t){var e=parseInt(t,16),i=String.fromCharCode(e),o=document.createElement("a-entity");this.iconEntity=o,o.setAttribute("troika-text","value:"+i+"; \n align:center; \n anchor:center; \n baseline:center;\n lineHeight:"+this.guiItem.height+";\n maxWidth:"+this.guiItem.width+";\n color:"+this.data.fontColor+";\n font:"+this.data.iconFont+";\n fontSize:"+this.data.iconFontSize+";\n depthOffset:1;\n "),o.setAttribute("position","0 0 0.05"),this.el.appendChild(o)}}),AFRAME.registerPrimitive("a-gui-icon-button",{defaultComponents:{"gui-interactable":{},"gui-item":{type:"icon-button"},"gui-icon-button":{}},mappings:{onclick:"gui-interactable.clickAction",onhover:"gui-interactable.hoverAction","key-code":"gui-interactable.keyCode",width:"gui-item.width",height:"gui-item.height",margin:"gui-item.margin",on:"gui-icon-button.on","font-color":"gui-icon-button.fontColor","font-family":"gui-icon-button.fontFamily","border-color":"gui-icon-button.borderColor","background-color":"gui-icon-button.backgroundColor","hover-color":"gui-icon-button.hoverColor","active-color":"gui-icon-button.activeColor",icon:"gui-icon-button.icon","icon-active":"gui-icon-button.iconActive","icon-font":"gui-icon-button.iconFont","icon-font-size":"gui-icon-button.iconFontSize",toggle:"gui-icon-button.toggle","toggle-state":"gui-icon-button.toggleState"}})},function(t,e,i){"use strict";AFRAME.registerComponent("gui-icon-label-button",{schema:{on:{default:"click"},toggle:{type:"boolean",default:!1},toggleState:{type:"boolean",default:!1},icon:{type:"string",default:"f0f3"},iconActive:{type:"string",default:""},iconFontSize:{type:"number",default:.35},iconFont:{type:"string",default:"assets/fonts/fa-regular-400.ttf"},value:{type:"string",default:""},fontSize:{type:"number",default:.2},fontFamily:{type:"string",default:""},fontColor:{type:"string",default:key_offwhite},borderColor:{type:"string",default:key_offwhite},backgroundColor:{type:"string",default:key_grey},hoverColor:{type:"string",default:key_grey_dark},activeColor:{type:"string",default:key_orange}},init:function(){var t=this.data,e=this.el,i=e.getAttribute("gui-item");this.guiItem=i;var o=(this.toggleState=t.toggle,e.getAttribute("gui-interactable"));if(this.guiInteractable=o,t.iconFontSize>20){var r=t.iconFontSize/750;t.iconFontSize=r}if(t.fontSize>20){var r=t.fontSize/750;t.fontSize=r}e.setAttribute("geometry","primitive: plane; height: "+i.height+"; width: "+i.width+";"),e.setAttribute("material","shader: flat; side:front; color:"+t.backgroundColor+";");var a=document.createElement("a-entity");a.setAttribute("geometry","primitive: box; width: "+i.width+"; height: "+i.height+"; depth: 0.02;"),a.setAttribute("material","shader: flat; opacity: 1; side:double; color: "+t.borderColor),a.setAttribute("rotation","0 0 0"),a.setAttribute("position","0 0 0.01"),e.appendChild(a);var n=document.createElement("a-entity");n.setAttribute("geometry","primitive: box; width: "+(i.width-.025)+"; height: "+(i.height-.025)+"; depth: 0.04;"),n.setAttribute("material","shader: flat; opacity: 1; side:double; color: "+(t.toggleState?t.activeColor:t.backgroundColor)),n.setAttribute("rotation","0 0 0"),n.setAttribute("position","0 0 0.02"),e.appendChild(n),this.buttonEntity=n,this.setIcon(t.icon),""!=t.value&&this.setText(t.value),e.addEventListener("mouseenter",function(e){n.removeAttribute("animation__leave"),t.toggle||n.setAttribute("animation__enter","property: material.color; from: "+t.backgroundColor+"; to:"+t.hoverColor+"; dur:200;")}),e.addEventListener("mouseleave",function(e){t.toggle||(n.removeAttribute("animation__click"),n.setAttribute("animation__leave","property: material.color; from: "+t.hoverColor+"; to:"+t.backgroundColor+"; dur:200; easing: easeOutQuad;")),n.removeAttribute("animation__enter")}),e.addEventListener(t.on,function(i){if(t.toggle){var r=e.components["gui-button"];r.setActiveState(!r.data.toggleState)}else n.setAttribute("animation__click","property: material.color; from: "+t.activeColor+"; to:"+t.backgroundColor+"; dur:400; easing: easeOutQuad;");var a=o.clickAction,l=window[a];"function"==typeof l&&l(i)}),e.setAttribute("role","button")},play:function(){},update:function(t){console.log("In button update, toggle: "+this.toggleState);this.data,this.el;if(this.iconEntity){console.log("has iconEntity: "+this.iconEntity);var e=this.iconEntity;e.parentNode.removeChild(e),this.setIcon(this.data.icon)}else console.log("no iconEntity!");if(this.textEntity){console.log("has textEntity: "+this.textEntity);var e=this.textEntity;e.parentNode.removeChild(e),this.setText(this.data.value)}else console.log("no textEntity!")},setActiveState:function(t){this.data.toggleState=t,t?(console.log("active, about to set active color"),this.buttonEntity.setAttribute("material","color",this.data.activeColor)):(console.log("not active, about to set background color"),this.buttonEntity.setAttribute("material","color",this.data.backgroundColor))},setIcon:function(t){var e=parseInt(t,16),i=String.fromCharCode(e),o=document.createElement("a-entity"),r=0;""!=this.data.value&&(r=.5*-this.guiItem.width+.5*this.guiItem.height),this.iconEntity=o,o.setAttribute("troika-text","value:"+i+"; \n align:center; \n anchor:center; \n baseline:center;\n color:"+this.data.fontColor+";\n font:"+this.data.iconFont+";\n fontSize:"+this.data.iconFontSize+";\n depthOffset:1;\n "),o.setAttribute("position",r+" 0 0.05"),this.el.appendChild(o)},setText:function(t){var e=this.guiItem.height-.5*this.guiItem.width,i=document.createElement("a-entity");this.textEntity=i,i.setAttribute("troika-text","value: "+t+"; \n align:left; \n anchor:left; \n baseline:center;\n letterSpacing:0;\n color:"+this.data.fontColor+";\n font:"+this.data.fontFamily+";\n fontSize:"+this.data.fontSize+";\n depthOffset:1;\n maxWidth:"+this.guiItem.width/1.05+";\n "),i.setAttribute("position",e+" 0 0.05"),this.el.appendChild(i)}}),AFRAME.registerPrimitive("a-gui-icon-label-button",{defaultComponents:{"gui-interactable":{},"gui-item":{type:"icon-label-button"},"gui-icon-label-button":{}},mappings:{onclick:"gui-interactable.clickAction",onhover:"gui-interactable.hoverAction","key-code":"gui-interactable.keyCode",width:"gui-item.width",height:"gui-item.height",margin:"gui-item.margin",on:"gui-icon-label-button.on","font-color":"gui-icon-label-button.fontColor","font-family":"gui-icon-label-button.fontFamily","font-size":"gui-icon-label-button.fontSize","border-color":"gui-icon-label-button.borderColor","background-color":"gui-icon-label-button.backgroundColor","hover-color":"gui-icon-label-button.hoverColor","active-color":"gui-icon-label-button.activeColor",icon:"gui-icon-label-button.icon","icon-active":"gui-icon-label-button.iconActive","icon-font":"gui-icon-label-button.iconFont","icon-font-size":"gui-icon-label-button.iconFontSize",value:"gui-icon-label-button.value",toggle:"gui-icon-label-button.toggle","toggle-state":"gui-icon-label-button.toggleState"}})},function(t,e,i){"use strict";AFRAME.registerComponent("gui-input",{schema:{align:{type:"string",default:"left"},on:{default:"click"},value:{type:"string",default:""},toggle:{type:"boolean",default:!1},toggleState:{type:"boolean",default:!1},fontSize:{type:"number",default:.2},fontFamily:{type:"string",default:""},fontColor:{type:"string",default:key_grey_dark},borderColor:{type:"string",default:key_grey_dark},borderHoverColor:{type:"string",default:key_grey},backgroundColor:{type:"string",default:key_offwhite},hoverColor:{type:"string",default:key_white},activeColor:{type:"string",default:key_orange}},init:function(){var t=this.data,e=this.el,i=e.getAttribute("gui-item");this.guiItem=i;var o=(this.toggleState=t.toggle,e.getAttribute("gui-interactable"));if(this.guiInteractable=o,t.fontSize>20){var r=t.fontSize/750;t.fontSize=r}e.setAttribute("geometry","primitive: plane; height: "+i.height+"; width: "+i.width+";"),e.setAttribute("material","shader: flat; transparent: false; side:front; color:"+t.backgroundColor+";");var a=document.createElement("a-entity");a.setAttribute("geometry","primitive: box; width: "+i.width+"; height: 0.05; depth: 0.02;"),a.setAttribute("material","shader: flat; opacity: 1; side:double; color: "+t.borderColor),a.setAttribute("position","0 -"+(i.height/2-.025)+" 0.01"),e.appendChild(a);var n=document.createElement("a-entity");n.setAttribute("geometry","primitive: box; width: "+i.width+"; height: 0.05; depth: 0.02;"),n.setAttribute("material","shader: flat; opacity: 1; side:double; color: "+t.borderColor),n.setAttribute("position","0 "+(i.height/2-.025)+" 0.01"),e.appendChild(n);var l=document.createElement("a-entity");l.setAttribute("geometry","primitive: box; width: 0.05; height: "+i.height+"; depth: 0.02;"),l.setAttribute("material","shader: flat; opacity: 1; side:double; color: "+t.borderColor),l.setAttribute("position","-"+(i.width/2-.025)+" 0 0.01"),e.appendChild(l);var s=document.createElement("a-entity");s.setAttribute("geometry","primitive: box; width: 0.05; height: "+i.height+"; depth: 0.02;"),s.setAttribute("material","shader: flat; opacity: 1; side:double; color: "+t.borderColor),s.setAttribute("position",i.width/2-.025+" 0 0.01"),e.appendChild(s),this.setText(t.value),e.setAttribute("role","input"),e.addEventListener("mouseenter",function(i){e.setAttribute("material","color",t.hoverColor),a.setAttribute("material","color",t.borderHoverColor),n.setAttribute("material","color",t.borderHoverColor),l.setAttribute("material","color",t.borderHoverColor),s.setAttribute("material","color",t.borderHoverColor)}),e.addEventListener("mouseleave",function(i){e.setAttribute("material","color",t.backgroundColor),a.setAttribute("material","color",t.borderColor),n.setAttribute("material","color",t.borderColor),l.setAttribute("material","color",t.borderColor),s.setAttribute("material","color",t.borderColor)}),e.addEventListener(t.on,function(t){console.log("I was clicked at: ",t.detail.intersection.point);var i=e.getAttribute("gui-interactable");console.log("guiInteractable: "+i);var o=i.clickAction;console.log("clickActionFunctionName: "+o);var r=window[o];"function"==typeof r&&r(t)})},setText:function(t){var e=.25*this.guiItem.height-.5*this.guiItem.width,i=document.createElement("a-entity");this.textEntity=i,i.setAttribute("troika-text","value: "+t+"; \n align:left; \n anchor:left; \n baseline:center;\n letterSpacing:0;\n color:"+this.data.fontColor+";\n font:"+this.data.fontFamily+";\n fontSize:"+this.data.fontSize+";\n depthOffset:1;\n maxWidth:"+this.guiItem.width/1.05+";\n "),i.setAttribute("position",e+" 0 0.05"),this.el.appendChild(i)},play:function(){},update:function(t){var e=this.data;this.el;this.textEntity.setAttribute("troika-text","value: "+e.value+";")},appendText:function(t){var e=this.data.value+t;this.el.setAttribute("gui-input","text",e)},delete:function(){if(this.data.value&&this.data.value.length>0){var t=this.data.value.slice(0,-1);this.el.setAttribute("gui-input","text",t)}}}),AFRAME.registerPrimitive("a-gui-input",{defaultComponents:{"gui-interactable":{},"gui-item":{type:"input"},"gui-input":{}},mappings:{onclick:"gui-interactable.clickAction",onhover:"gui-interactable.hoverAction",width:"gui-item.width",height:"gui-item.height",margin:"gui-item.margin",value:"gui-input.value","font-size":"gui-input.fontSize","font-family":"gui-input.fontFamily","font-color":"gui-input.fontColor","background-color":"gui-input.backgroundColor","hover-color":"gui-input.hoverColor","border-color":"gui-input.borderColor","border-hover-color":"gui-input.borderHoverColor"}})},function(t,e,i){"use strict";AFRAME.registerComponent("gui-interactable",{schema:{clickAction:{type:"string"},hoverAction:{type:"string"},keyCode:{type:"number",default:-1},key:{type:"string"}},init:function(){var t=this.data,e=this.el;t.keyCode>0&&window.addEventListener("keydown",function(i){i.key==t.key?e.emit("click"):i.keyCode==t.keyCode&&e.emit("click"),i.preventDefault()},!0)},update:function(){},tick:function(){},remove:function(){},pause:function(){},play:function(){},setClickAction:function(t){this.data.clickAction=t}})},function(t,e,i){"use strict";AFRAME.registerComponent("gui-item",{schema:{type:{type:"string"},width:{type:"number",default:1},height:{type:"number",default:1},baseDepth:{type:"number",default:.01},depth:{type:"number",default:.02},gap:{type:"number",default:.025},radius:{type:"number",default:0},margin:{type:"vec4",default:{x:0,y:0,z:0,w:0}},bevel:{type:"boolean",default:!1},bevelSegments:{type:"number",default:5},steps:{type:"number",default:2},bevelSize:{type:"number",default:.1},bevelOffset:{type:"number",default:0},bevelThickness:{type:"number",default:.1}},init:function(){},update:function(){},tick:function(){},remove:function(){},pause:function(){},play:function(){}})},function(t,e,i){"use strict";AFRAME.registerComponent("gui-label",{schema:{value:{type:"string",default:""},align:{type:"string",default:"center"},anchor:{type:"string",default:"center"},fontSize:{type:"number",default:.2},lineHeight:{type:"number",default:.2},letterSpacing:{type:"number",default:0},fontFamily:{type:"string",default:""},fontColor:{type:"string",default:key_grey_dark},backgroundColor:{type:"string",default:key_offwhite},opacity:{type:"number",default:1},textDepth:{type:"number",default:.01}},init:function(){var t=this.data,e=this.el,i=e.getAttribute("gui-item");if(this.guiItem=i,e.setAttribute("geometry","primitive: plane; height: "+i.height+"; width: "+i.width+";"),e.setAttribute("material","shader: flat; side:front; color:"+t.backgroundColor+"; transparent: true; opacity: "+t.opacity+"; alphaTest: 0.5;"),t.fontSize>20){var o=t.fontSize/750;t.fontSize=o}this.setText(t.value)},update:function(t){this.data,this.el;if(this.textEntity){console.log("has textEntity: "+this.textEntity);var e=this.textEntity;e.parentNode.removeChild(e),this.setText(this.data.value)}else console.log("no textEntity!")},setText:function(t){var e=document.createElement("a-entity");this.textEntity=e,e.setAttribute("troika-text","value: "+t+"; \n align: "+this.data.align+"; \n anchor: "+this.data.anchor+"; \n baseline:center;\n letterSpacing:0;\n lineHeight: "+this.data.lineHeight+";\n color:"+this.data.fontColor+";\n font:"+this.data.fontFamily+";\n fontSize:"+this.data.fontSize+";\n depthOffset:1;\n maxWidth:"+this.guiItem.width/1.05+";\n "),e.setAttribute("position","0 0 "+this.data.textDepth),this.el.appendChild(e)}}),AFRAME.registerPrimitive("a-gui-label",{defaultComponents:{"gui-item":{type:"label"},"gui-label":{}},mappings:{width:"gui-item.width",height:"gui-item.height",margin:"gui-item.margin",align:"gui-label.align",anchor:"gui-label.anchor",value:"gui-label.value","font-size":"gui-label.fontSize","line-height":"gui-label.lineHeight","letter-spacing":"gui-label.letterSpacing","font-color":"gui-label.fontColor","font-family":"gui-label.fontFamily","background-color":"gui-label.backgroundColor",opacity:"gui-label.opacity","text-depth":"gui-label.textDepth"}})},function(t,e,i){"use strict";AFRAME.registerComponent("gui-progressbar",{schema:{backgroundColor:{type:"string",default:key_grey},activeColor:{type:"string",default:key_orange}},init:function(){var t=this.data,e=this.el,i=e.getAttribute("gui-item");e.setAttribute("geometry","primitive: plane; height: "+i.height+"; width: "+i.width+";"),e.setAttribute("material","shader: flat; opacity: 1; color: "+t.backgroundColor+"; side:front;");var o=document.createElement("a-entity");o.setAttribute("geometry","primitive: box; width: 0.04; height: "+i.height+"; depth: 0.02;"),o.setAttribute("material","shader: flat; opacity: 1; side:double; color: "+t.activeColor),o.setAttribute("position",-i.width/2+" 0 0.01"),o.id="progress_meter",e.appendChild(o)},update:function(){},tick:function(){},remove:function(){},pause:function(){},play:function(){}}),AFRAME.registerPrimitive("a-gui-progressbar",{defaultComponents:{"gui-item":{type:"progressbar"},"gui-progressbar":{}},mappings:{width:"gui-item.width",height:"gui-item.height",margin:"gui-item.margin","background-color":"gui-progressbar.backgroundColor","active-color":"gui-progressbar.activeColor"}})},function(t,e,i){"use strict";AFRAME.registerComponent("gui-radio",{schema:{on:{default:"click"},value:{type:"string",default:""},active:{type:"boolean",default:!0},toggle:{type:"boolean",default:!1},toggleState:{type:"boolean",default:!1},checked:{type:"boolean",default:!1},radiosizecoef:{type:"number",default:1},fontSize:{type:"number",default:.2},fontFamily:{type:"string",default:""},fontColor:{type:"string",default:key_grey_dark},borderColor:{type:"string",default:key_white},backgroundColor:{type:"string",default:key_offwhite},hoverColor:{type:"string",default:key_grey_light},activeColor:{type:"string",default:key_orange},handleColor:{type:"string",default:key_grey}},init:function(){var t=this.data,e=this.el,i=e.getAttribute("gui-item");this.guiItem=i;var o=(this.toggleState=t.toggle,e.getAttribute("gui-interactable"));if(this.guiInteractable=o,t.fontSize>20){var r=t.fontSize/750;t.fontSize=r}e.setAttribute("material","shader: flat; depthTest:true;transparent: false; opacity: 1; color: "+this.data.backgroundColor+"; side:front;"),e.setAttribute("geometry","primitive: plane; height: "+i.height+"; width: "+i.height+";");var a=.5*-i.width+.5*i.height,n=document.createElement("a-cylinder");n.setAttribute("radius",.2*i.height*t.radiosizecoef),n.setAttribute("height","0.01"),n.setAttribute("rotation","90 0 0"),n.setAttribute("material","color:"+t.handleColor+"; shader: flat;"),n.setAttribute("position",a+" 0 0"),e.appendChild(n);var l=document.createElement("a-torus");l.setAttribute("radius",.19*i.height*t.radiosizecoef),l.setAttribute("radius-tubular","0.01"),l.setAttribute("rotation","90 0 0"),l.setAttribute("material","color:"+t.borderColor+"; shader: flat;"),n.appendChild(l);var s=document.createElement("a-cylinder");s.setAttribute("radius",.18*i.height*t.radiosizecoef),s.setAttribute("height","0.02"),s.setAttribute("rotation","0 0 0"),s.setAttribute("material","color:"+t.handleColor+"; shader: flat;"),n.appendChild(s),this.setText(t.value),this.updateToggle(t.active),e.setAttribute("checked",t.active),e.addEventListener("mouseenter",function(e){l.removeAttribute("animation__leave"),l.setAttribute("animation__enter","property: material.color; from: "+t.borderColor+"; to:"+t.hoverColor+"; dur:200;")}),e.addEventListener("mouseleave",function(e){l.removeAttribute("animation__enter"),l.setAttribute("animation__leave","property: material.color; from: "+t.hoverColor+"; to:"+t.borderColor+"; dur:200; easing: easeOutQuad;")}),e.addEventListener(t.on,function(i){t.checked=!t.checked,t.checked?(s.removeAttribute("animation__colorOut"),s.removeAttribute("animation__rotationOut"),s.removeAttribute("animation__position1Out"),s.removeAttribute("animation__position2Out"),s.setAttribute("animation__colorIn","property: material.color; from: "+t.handleColor+"; to:"+t.activeColor+"; dur:500; easing:easeInOutCubic;"),s.setAttribute("animation__rotationIn","property: rotation; from: 0 0 0; to:-180 0 0; dur:500; easing:easeInOutCubic;"),s.setAttribute("animation__position1In","property: position; from: 0 0 0; to:0 0.3 0; dur:200; easing:easeInOutCubic;"),s.setAttribute("animation__position2In","property: position; from: 0 0.3 0; to:0 0 0; dur:200; easing:easeInOutCubic; delay:300;")):(s.removeAttribute("animation__colorIn"),s.removeAttribute("animation__rotationIn"),s.removeAttribute("animation__position1In"),s.removeAttribute("animation__position2In"),s.setAttribute("animation__colorOut","property: material.color; from: "+t.activeColor+"; to:"+t.handleColor+"; dur:500; easing:easeInOutCubic;"),s.setAttribute("animation__rotationOut","property: rotation; from: -180 0 0; to:0 0 0; dur:500; easing:easeInOutCubic;"),s.setAttribute("animation__position1Out","property: position; from: 0 0 0; to:0 0.3 0; dur:200; easing:easeInOutCubic; "),s.setAttribute("animation__position2Out","property: position; from: 0 0.3 0; to:0 0 0; dur:200; easing:easeInOutCubic; delay:300;"));var o=e.getAttribute("gui-interactable"),r=o.clickAction,a=window[r];"function"==typeof a&&a(i)}),e.setAttribute("role","radio")},update:function(){var t=this.data;this.el;if(this.updateToggle(t.active),this.textEntity){console.log("has textEntity: "+this.textEntity);var e=this.textEntity;e.parentNode.removeChild(e),this.setText(this.data.value)}else console.log("no textEntity!")},updateToggle:function(t){},setText:function(t){var e=this.guiItem.height-.5*this.guiItem.width,i=document.createElement("a-entity");this.textEntity=i,i.setAttribute("troika-text","value: "+t+"; \n align:left; \n anchor:left; \n baseline:center;\n letterSpacing:0;\n color:"+this.data.fontColor+";\n font:"+this.data.fontFamily+";\n fontSize:"+this.data.fontSize+";\n depthOffset:1;\n maxWidth:"+this.guiItem.width/1.05+";\n "),i.setAttribute("position",e+" 0 0.05"),this.el.appendChild(i)}}),AFRAME.registerPrimitive("a-gui-radio",{defaultComponents:{"gui-interactable":{},"gui-item":{type:"radio"},"gui-radio":{}},mappings:{onclick:"gui-interactable.clickAction",onhover:"gui-interactable.hoverAction","key-code":"gui-interactable.keyCode",width:"gui-item.width",height:"gui-item.height",margin:"gui-item.margin",on:"gui-radio.on",value:"gui-radio.value",active:"gui-radio.active",checked:"gui-radio.checked","font-color":"gui-radio.fontColor","font-size":"gui-radio.fontSize","font-family":"gui-radio.fontFamily","border-color":"gui-radio.borderColor","background-color":"gui-radio.backgroundColor","hover-color":"gui-radio.hoverColor","active-color":"gui-radio.activeColor","handle-color":"gui-radio.handleColor",radiosizecoef:"gui-radio.radiosizecoef"}})},function(t,e,i){"use strict";AFRAME.registerComponent("rounded",{schema:{enabled:{default:!0},width:{type:"number",default:1},height:{type:"number",default:1},radius:{type:"number",default:.3},topLeftRadius:{type:"number",default:-1},topRightRadius:{type:"number",default:-1},bottomLeftRadius:{type:"number",default:-1},bottomRightRadius:{type:"number",default:-1},depthWrite:{default:!0},polygonOffset:{default:!1},polygonOffsetFactor:{type:"number",default:0},color:{type:"color",default:"#F0F0F0"},opacity:{type:"number",default:1}},init:function(){this.rounded=new THREE.Mesh(this.draw(),new THREE.MeshStandardMaterial({color:new THREE.Color(this.data.color)})),this.updateOpacity(),this.el.setObject3D("mesh",this.rounded)},update:function(){this.data.enabled?this.rounded&&(this.rounded.visible=!0,this.rounded.geometry=this.draw(),this.rounded.material.color=new THREE.Color(this.data.color),this.updateOpacity()):this.rounded.visible=!1},updateOpacity:function(){this.data.opacity<0&&(this.data.opacity=0),this.data.opacity>1&&(this.data.opacity=1),this.data.opacity<1?(this.rounded.material.transparent=!0,this.rounded.material.opacity=this.data.opacity,this.rounded.material.alphaTest=0):this.rounded.material.transparent=!1},tick:function(){},remove:function(){this.rounded&&(this.el.object3D.remove(this.rounded),this.rounded=null)},draw:function(){function t(t,e,i,o,r,a,n,l,s){a||(a=1e-5),n||(n=1e-5),l||(l=1e-5),s||(s=1e-5),t.moveTo(e,i+a),t.lineTo(e,i+r-a),t.quadraticCurveTo(e,i+r,e+a,i+r),t.lineTo(e+o-n,i+r),t.quadraticCurveTo(e+o,i+r,e+o,i+r-n),t.lineTo(e+o,i+s),t.quadraticCurveTo(e+o,i,e+o-s,i),t.lineTo(e+l,i),t.quadraticCurveTo(e,i,e,i+l)}var e=new THREE.Shape,i=[this.data.radius,this.data.radius,this.data.radius,this.data.radius];return-1!=this.data.topLeftRadius&&(i[0]=this.data.topLeftRadius),-1!=this.data.topRightRadius&&(i[1]=this.data.topRightRadius),-1!=this.data.bottomLeftRadius&&(i[2]=this.data.bottomLeftRadius),-1!=this.data.bottomRightRadius&&(i[3]=this.data.bottomRightRadius),t(e,-this.data.width/2,-this.data.height/2,this.data.width,this.data.height,i[0],i[1],i[2],i[3]),new THREE.ShapeBufferGeometry(e)},pause:function(){},play:function(){}}),AFRAME.registerPrimitive("a-rounded",{defaultComponents:{rounded:{}},mappings:{enabled:"rounded.enabled",width:"rounded.width",height:"rounded.height",radius:"rounded.radius","depth-write":"rounded.depthWrite","polygon-offset":"rounded.polygonOffset","polygon-offset-factor":"rounded.polygonOffsetFactor","top-left-radius":"rounded.topLeftRadius","top-right-radius":"rounded.topRightRadius","bottom-left-radius":"rounded.bottomLeftRadius","bottom-right-radius":"rounded.bottomRightRadius",color:"rounded.color",opacity:"rounded.opacity"}})},function(t,e,i){"use strict";AFRAME.registerComponent("gui-slider",{schema:{activeColor:{type:"string",default:key_orange},backgroundColor:{type:"string",default:key_offwhite},borderColor:{type:"string",default:key_grey},handleColor:{type:"string",default:key_white},handleInnerDepth:{type:"number",default:.02},handleInnerRadius:{type:"number",default:.13},handleOuterDepth:{type:"number",default:.04},handleOuterRadius:{type:"number",default:.17},hoverColor:{type:"string",default:key_grey_light},leftRightPadding:{type:"number",default:.25},percent:{type:"number",default:.5},sliderBarHeight:{type:"number",default:.05},sliderBarDepth:{type:"number",default:.03},topBottomPadding:{type:"number",default:.125}},init:function(){var t=this.data,e=this.el,i=e.getAttribute("gui-item"),o=i.width-2*t.leftRightPadding;i.height,t.topBottomPadding;e.setAttribute("geometry","primitive: plane; height: "+i.height+"; width: "+i.height+";"),e.setAttribute("material","shader: flat; opacity: 1; color: "+t.backgroundColor+"; side:front;");var r=document.createElement("a-entity");r.setAttribute("geometry","primitive: box; width: "+t.percent*o+"; height: "+t.sliderBarHeight+"; depth: "+t.sliderBarDepth+";"),r.setAttribute("material","shader: flat; opacity: 1; side:double; color: "+t.activeColor+";"),r.setAttribute("position",t.percent-.5*o+" 0 "+(t.sliderBarDepth-.01)),e.appendChild(r);var a=document.createElement("a-entity");a.setAttribute("geometry","primitive: box; width: "+(o-t.percent*o)+"; height: "+t.sliderBarHeight+"; depth: "+t.sliderBarDepth+";"),a.setAttribute("material","shader: flat; opacity: 1; side:double; color: "+t.borderColor+";"),a.setAttribute("position",t.percent*o*.5+" 0 "+(t.sliderBarDepth-.01)),e.appendChild(a);var n=document.createElement("a-entity");n.setAttribute("geometry","primitive: cylinder; radius: "+t.handleOuterRadius+"; height: "+t.handleOuterDepth+";"),n.setAttribute("material","shader: flat; opacity: 1; side:double; color: "+t.borderColor+";"),n.setAttribute("rotation","90 0 0"),n.setAttribute("position",t.percent*o-.5*o+" 0 "+(t.handleOuterDepth-.01)),e.appendChild(n);var l=document.createElement("a-entity");l.setAttribute("geometry","primitive: cylinder; radius: "+t.handleInnerRadius+"; height: "+t.handleInnerDepth+";"),l.setAttribute("material","shader: flat; opacity: 1; side:double; color: "+t.handleColor+";"),l.setAttribute("position","0 "+t.handleInnerDepth+" 0"),n.appendChild(l),e.addEventListener("mouseenter",function(){l.setAttribute("material","color",t.hoverColor)}),e.addEventListener("mouseleave",function(){l.setAttribute("material","color",t.handleColor)}),e.addEventListener("click",function(i){console.log("I was clicked at: ",i.detail.intersection.point);var o=e.object3D.worldToLocal(i.detail.intersection.point);console.log("local coordinates: ",o),console.log("current percent: "+t.percent);var l=2;o.x<=-l/2?t.percent=0:o.x>=l/2?t.percent=1:t.percent=(o.x+l/2)/l,console.log("handle container: "+n),r.setAttribute("geometry","primitive: box; width: "+2*t.percent+"; height: 0.05; depth: 0.03;"),r.setAttribute("position",t.percent-1+" 0 0.02"),a.setAttribute("geometry","primitive: box; width: "+(2-2*t.percent)+"; height: 0.05; depth: 0.03;"),a.setAttribute("position",1*t.percent+" 0 0.02"),n.setAttribute("position",2*t.percent-1+" 0 0.03");var s=e.getAttribute("gui-interactable");console.log("guiInteractable: "+s);var u=s.clickAction;console.log("clickActionFunctionName: "+u);var d=window[u];"function"==typeof d&&d(i,t.percent)})},update:function(){},tick:function(){},remove:function(){},pause:function(){},play:function(){}}),AFRAME.registerPrimitive("a-gui-slider",{defaultComponents:{"gui-interactable":{},"gui-item":{type:"slider"},"gui-slider":{}},mappings:{"active-color":"gui-slider.activeColor","background-color":"gui-slider.backgroundColor","border-color":"gui-slider.borderColor","handle-color":"gui-slider.handleColor","handle-inner-depth":"gui-slider.handleInnerDepth","handle-inner-radius":"gui-slider.handleInnerRadius","handle-outer-depth":"gui-slider.handleOuterDepth","handle-outer-radius":"gui-slider.handleOuterRadius",height:"gui-item.height","hover-color":"gui-slider.hoverColor","key-code":"gui-interactable.keyCode","left-right-padding":"gui-slider.leftRightPadding",margin:"gui-item.margin",onclick:"gui-interactable.clickAction",onhover:"gui-interactable.hoverAction",percent:"gui-slider.percent","slider-bar-depth":"gui-slider.sliderBarDepth","slider-bar-height":"gui-slider.sliderBarHeight","top-bottom-padding":"gui-slider.topBottomPadding",width:"gui-item.width"}})},function(t,e,i){"use strict";AFRAME.registerComponent("gui-toggle",{schema:{on:{default:"click"},value:{type:"string",default:""},toggle:{type:"boolean",default:!1},toggleState:{type:"boolean",default:!1},active:{type:"boolean",default:!0},checked:{type:"boolean",default:!1},borderWidth:{type:"number",default:1},fontSize:{type:"number",default:.2},fontFamily:{type:"string",default:""},fontColor:{type:"string",default:key_grey_dark},borderColor:{type:"string",default:key_grey},backgroundColor:{type:"string",default:key_offwhite},hoverColor:{type:"string",default:key_grey_light},activeColor:{type:"string",default:key_orange},handleColor:{type:"string",default:key_offwhite}},init:function(){var t=this.data,e=this.el,i=e.getAttribute("gui-item");this.guiItem=i;var o=(this.toggleState=t.toggle,e.getAttribute("gui-interactable"));if(this.guiInteractable=o,t.fontSize>20){var r=t.fontSize/750;t.fontSize=r}e.setAttribute("material","shader: flat; depthTest:true;transparent: false; opacity: 1; color: "+this.data.backgroundColor+"; side:front;"),e.setAttribute("geometry","primitive: plane; height: "+i.height+"; width: "+i.height+";");var a=i.height/1.75,n=.5*-i.width+i.height/2,l=document.createElement("a-box");l.setAttribute("width",a),l.setAttribute("height",.5*i.height),l.setAttribute("depth","0.01"),l.setAttribute("material","color:"+t.borderColor+"; shader: flat;"),l.setAttribute("position",n+" 0 0"),e.appendChild(l);var s=i.height/5,u=.5*-i.height+2*s,d=.5*i.height-2*s,c=document.createElement("a-box");c.setAttribute("width",""+s),c.setAttribute("height",.4*i.height),c.setAttribute("depth","0.02"),c.setAttribute("material","color:"+t.handleColor),c.setAttribute("position",u+" 0 0.02"),l.appendChild(c),this.setText(t.value),this.updateToggle(t.active),e.addEventListener("mouseenter",function(e){c.removeAttribute("animation__leave"),c.setAttribute("animation__enter","property: material.color; from: "+t.handleColor+"; to:"+t.hoverColor+"; dur:200;")}),e.addEventListener("mouseleave",function(e){c.removeAttribute("animation__enter"),c.setAttribute("animation__leave","property: material.color; from: "+t.hoverColor+"; to:"+t.handleColor+"; dur:200; easing: easeOutQuad;")}),e.addEventListener("check",function(e){t.checked||(t.checked=!0)}),e.addEventListener("uncheck",function(e){t.checked&&(t.checked=!1)}),e.addEventListener(t.on,function(i){console.log("I was clicked at: ",i.detail.intersection.point),t.checked=!t.checked,t.checked?(l.removeAttribute("animation__colorOut"),c.removeAttribute("animation__positionOut"),l.setAttribute("animation__colorIn","property: material.color; from: "+t.borderColor+"; to:"+t.activeColor+"; dur:200; easing:easeInOutCubic;"),c.setAttribute("animation__positionIn","property: position; from: "+u+" 0 0.02; to:"+d+" 0 0.02; dur:200; easing:easeInOutCubic;")):(l.removeAttribute("animation__colorIn"),c.removeAttribute("animation__positionIn"),l.setAttribute("animation__colorOut","property: material.color; from: "+t.activeColor+"; to:"+t.borderColor+"; dur:200; easing:easeInOutCubic;"),c.setAttribute("animation__positionOut","property: position; from: "+d+" 0 0.02; to:"+u+" 0 0.02; dur:200; easing:easeInOutCubic;"));var o=e.getAttribute("gui-interactable");console.log("guiInteractable: "+o);var r=o.clickAction;console.log("clickActionFunctionName: "+r);var a=window[r];"function"==typeof a&&a(i)})},update:function(){var t=this.data;this.el;if(this.updateToggle(t.active),this.textEntity){console.log("has textEntity: "+this.textEntity);var e=this.textEntity;e.parentNode.removeChild(e),this.setText(this.data.value)}else console.log("no textEntity!")},updateToggle:function(t){},setText:function(t){var e=this.guiItem.height-.5*this.guiItem.width,i=document.createElement("a-entity");this.textEntity=i,i.setAttribute("troika-text","value: "+t+"; \n align:left; \n anchor:left; \n baseline:center;\n letterSpacing:0;\n color:"+this.data.fontColor+";\n font:"+this.data.fontFamily+";\n fontSize:"+this.data.fontSize+";\n depthOffset:1;\n maxWidth:"+this.guiItem.width/1.05+";\n "),i.setAttribute("position",e+" 0 0.05"),this.el.appendChild(i)}}),AFRAME.registerPrimitive("a-gui-toggle",{defaultComponents:{"gui-interactable":{},"gui-item":{type:"toggle"},"gui-toggle":{}},mappings:{onclick:"gui-interactable.clickAction",onhover:"gui-interactable.hoverAction","key-code":"gui-interactable.keyCode",width:"gui-item.width",height:"gui-item.height",margin:"gui-item.margin",on:"gui-toggle.on",active:"gui-toggle.active",checked:"gui-toggle.checked",value:"gui-toggle.value","font-color":"gui-toggle.fontColor","font-family":"gui-toggle.fontFamily","font-size":"gui-toggle.fontSize","border-width":"gui-toggle.borderWidth","border-color":"gui-toggle.borderColor","background-color":"gui-toggle.backgroundColor","hover-color":"gui-toggle.hoverColor","active-color":"gui-toggle.activeColor","handle-color":"gui-toggle.handleColor"}})},function(t,e,i){"use strict";AFRAME.registerComponent("gui-vertical-slider",{schema:{activeColor:{type:"string",default:key_orange},backgroundColor:{type:"string",default:key_offwhite},borderColor:{type:"string",default:key_grey},handleColor:{type:"string",default:key_white},handleInnerDepth:{type:"number",default:.02},handleInnerRadius:{type:"number",default:.13},handleOuterDepth:{type:"number",default:.04},handleOuterRadius:{type:"number",default:.17},hoverColor:{type:"string",default:key_grey_light},hoverFontSize:{type:"number",default:100},hoverHeight:{type:"number",default:.35},hoverPercent:{type:"number"},hoverWidth:{type:"number",default:.7},hoverMargin:{type:"vec4",default:{x:0,y:0,z:0,w:0}},leftRightPadding:{type:"number",default:.125},percent:{type:"number",default:.5},opacity:{type:"number",default:1},outputFontSize:{type:"string",default:"0.2"},outputFunction:{type:"string"},outputHeight:{type:"number",default:1},outputMargin:{type:"vec4",default:{x:0,y:0,z:0,w:0}},outputTextDepth:{type:"number",default:.25},outputWidth:{type:"number",default:1},sliderBarDepth:{type:"number",default:.03},sliderBarWidth:{type:"number",default:.08},topBottomPadding:{type:"number",default:.25}},init:function(){var t=this,e=this.data,i=this.el,o=i.getAttribute("gui-item"),r=(o.width,e.leftRightPadding,o.height-2*e.topBottomPadding);this.sliderHeight=r,i.setAttribute("geometry","primitive: plane; height: "+o.height+"; width: "+o.width+";"),i.setAttribute("material","shader: flat; opacity: "+e.opacity+"; alphaTest: 0.5; color: "+e.backgroundColor+"; side:front;"),console.log("**** in vertical slider init, percent: "+e.percent+", sliderHeight: "+r);var a=document.createElement("a-entity");a.setAttribute("geometry","primitive: box; height: "+e.percent*r+"; width: "+e.sliderBarWidth+"; depth: "+e.sliderBarDepth+";"),a.setAttribute("material","shader: flat; opacity: 1; side:double; color: "+e.activeColor+";"),a.setAttribute("position","0 "+(e.percent*r-.5*r-e.percent*r*.5)+" "+(e.sliderBarDepth-.01)),this.sliderActiveBar=a,i.appendChild(a);var n=document.createElement("a-entity");n.setAttribute("geometry","primitive: box; height: "+(r-e.percent*r)+"; width: "+e.sliderBarWidth+"; depth: "+e.sliderBarDepth+";"),n.setAttribute("material","shader: flat; opacity: 1; alphaTest: 0.5; side:double; color:"+e.borderColor+";"),n.setAttribute("position","0 "+e.percent*r*.5+" "+(e.sliderBarDepth-.01)),this.sliderBar=n,i.appendChild(n);var l=document.createElement("a-entity");l.setAttribute("geometry","primitive: cylinder; radius: "+e.handleOuterRadius+"; height: "+e.handleOuterDepth+";"),l.setAttribute("material","shader: flat; opacity: 1; side:double; color: "+e.activeColor+";"),l.setAttribute("rotation","90 0 0"),l.setAttribute("position","0 "+(e.percent*r-.5*r)+" "+(e.handleOuterDepth-.01)),this.handleContainer=l,i.appendChild(l);var s=document.createElement("a-entity");s.setAttribute("geometry","primitive: cylinder; radius: "+e.handleInnerRadius+"; height: "+e.handleInnerDepth+";"),s.setAttribute("material","shader: flat; opacity: 1; side:double; color: "+e.handleColor+";"),s.setAttribute("position","0 "+e.handleInnerDepth+" 0"),l.appendChild(s);var u=document.createElement("a-gui-label");u.setAttribute("width",""+1.4*o.width*e.outputWidth),u.setAttribute("height",""+.7*o.width),u.setAttribute("value","0.0"),u.setAttribute("opacity","1.0"),u.setAttribute("position",1.4*o.width+" 0 "+e.sliderBarDepth),u.setAttribute("rotation","-90 0 0"),u.setAttribute("font-color",e.activeColor),u.setAttribute("font-size",240*o.width+"px"),u.setAttribute("font-weight","bold"),u.setAttribute("text-depth",e.outputTextDepth),this.valueLabel=u,l.appendChild(u);var d=document.createElement("a-entity");d.setAttribute("geometry","primitive: box; height: 0.02; width: "+.5*o.width+"; depth: "+e.sliderBarDepth+";"),d.setAttribute("material","shader: flat; opacity: 1; side:double; color: "+e.activeColor+";"),d.setAttribute("position",.5*-o.width+" 0 "+(e.sliderBarDepth-.01)),d.setAttribute("visible","false"),this.hoverIndicator=d,i.appendChild(d);var c=document.createElement("a-gui-label");c.setAttribute("width",""+o.width*e.hoverWidth),c.setAttribute("height",""+o.width*e.hoverHeight),c.setAttribute("value",""),c.setAttribute("opacity","0.5"),c.setAttribute("position",-o.width*e.hoverWidth+" 0 "+e.sliderBarDepth),c.setAttribute("font-color",e.borderColor),c.setAttribute("font-size",o.width*e.hoverFontSize+"px"),c.setAttribute("text-depth",e.outputTextDepth),this.hoverLabel=c,d.appendChild(c),i.addEventListener("mouseenter",function(){s.setAttribute("material","color",e.hoverColor)}),i.addEventListener("mouseleave",function(){s.setAttribute("material","color",e.handleColor)}),i.addEventListener("click",function(t){var o=i.object3D.worldToLocal(t.detail.intersection.point);console.log("click local coordinates: ",o),console.log("current percent: "+e.percent);var a=null;a=o.y<=-r/2?0:o.y>=r/2?1:(o.y+r/2)/r,console.log("new percent: "+a),i.setAttribute("gui-vertical-slider","percent",String(a)),i.setAttribute("gui-vertical-slider","hoverPercent",String(a)),console.log("handle container: "+l);var n=i.getAttribute("gui-interactable");console.log("guiInteractable: "+n);var s=n.clickAction;console.log("clickActionFunctionName: "+s);var u=window[s];"function"==typeof u&&u(e.percent)}),this.el.addEventListener("raycaster-intersected",function(e){t.raycaster=e.detail.el}),this.el.addEventListener("raycaster-intersected-cleared",function(e){t.raycaster=null,t.hoverIndicator.setAttribute("visible",!1),t.hoverLabel.setAttribute("visible",!1)})},update:function(t){var e=this.data,i=this.el,o=i.getAttribute("gui-item"),r=(o.width,e.leftRightPadding,o.height-2*e.topBottomPadding);if(e.percent!=t.percent&&this.sliderActiveBar&&this.sliderBar&&this.handleContainer){var r=o.height-2*e.topBottomPadding;this.sliderActiveBar.setAttribute("geometry","primitive: box; height: "+e.percent*r+"; width: "+e.sliderBarWidth+"; depth: "+e.sliderBarDepth+";"),this.sliderActiveBar.setAttribute("position","0 "+(e.percent*r-.5*r-e.percent*r*.5)+" "+(e.sliderBarDepth-.01)),this.sliderBar.setAttribute("geometry","primitive: box; width: "+e.sliderBarWidth+"; height: "+(r-e.percent*r)+"; depth: "+e.sliderBarDepth+";"),this.sliderBar.setAttribute("position","0 "+e.percent*r*.5+" "+(e.sliderBarDepth-.01)),this.handleContainer.setAttribute("position","0 "+(e.percent*r-.5*r)+" "+(e.handleOuterDepth-.01));var a=this.getOutputValue(!1);a&&this.valueLabel.setAttribute("value",a),this.hoverIndicator.setAttribute("visible",!1),this.hoverLabel.setAttribute("visible",!1)}else if(e.hoverPercent!=t.hoverPercent&&e.hoverPercent!=e.percent&&this.hoverIndicator){var n=this.getOutputValue(!0);n&&this.hoverLabel.setAttribute("value",n),this.hoverIndicator.setAttribute("position","0 "+(e.hoverPercent*r-.5*r)+" "+(e.sliderBarDepth-.01)),this.hoverIndicator.setAttribute("visible",!0),this.hoverLabel.setAttribute("visible",!0)}},tick:function(){if(this.raycaster){var t=this.el,e=(this.data,this.sliderHeight),i=(this.handleContainer,this.raycaster.components.raycaster.getIntersection(t));if(i){if(this.previousLocalY&&this.previousLocalY==i.point.y)return this.hoverIndicator.setAttribute("visible",!1),void this.hoverLabel.setAttribute("visible",!1);var o=this.el.object3D;o.updateMatrixWorld();var r=new THREE.Vector3,a=new THREE.Quaternion,n=new THREE.Vector3;o.matrixWorld.decompose(r,a,n);var l=new THREE.Vector3;l.x=i.point.x-r.x,l.y=i.point.y-r.y,l.z=i.point.z-r.z,this.previousLocalY=l.y;var s=null;(s=l.y<=-e/2?0:l.y>=e/2?1:(l.y+e/2)/e)!=this.data.hoverPercent&&t.setAttribute("gui-vertical-slider","hoverPercent",String(s));var u=t.getAttribute("gui-interactable"),d=u.hoverAction,c=window[d];"function"==typeof c&&c(s)}}},remove:function(){},pause:function(){},play:function(){},getOutputValue:function(t){var e=window[this.data.outputFunction];if("function"==typeof e){return e(t?this.data.hoverPercent:this.data.percent)}return null}}),AFRAME.registerPrimitive("a-gui-vertical-slider",{defaultComponents:{"gui-interactable":{},"gui-item":{type:"slider"},"gui-vertical-slider":{}},mappings:{"active-color":"gui-vertical-slider.activeColor","background-color":"gui-vertical-slider.backgroundColor","border-color":"gui-vertical-slider.borderColor","handle-color":"gui-vertical-slider.handleColor","handle-inner-depth":"gui-vertical-slider.handleInnerDepth","handle-inner-radius":"gui-vertical-slider.handleInnerRadius","handle-outer-depth":"gui-vertical-slider.handleOuterDepth","handle-outer-radius":"gui-vertical-slider.handleOuterRadius",height:"gui-item.height","hover-color":"gui-vertical-slider.hoverColor","hover-font-size":"gui-vertical-slider.hoverFontSize","hover-height":"gui-vertical-slider.hoverHeight","hover-margin":"gui-vertical-slider.hoverMargin","hover-percent":"gui-vertical-slider.hoverPercent","hover-width":"gui-vertical-slider.hoverWidth","key-code":"gui-interactable.keyCode","left-right-padding":"gui-vertical-slider.leftRightPadding",margin:"gui-item.margin",onclick:"gui-interactable.clickAction",onhover:"gui-interactable.hoverAction",opacity:"gui-vertical-slider.opacity","output-font-size":"gui-vertical-slider.outputFontSize","output-function":"gui-vertical-slider.outputFunction","output-height":"gui-vertical-slider.outputHeight","output-margin":"gui-vertical-slider.outputMargin","output-text-depth":"gui-vertical-slider.outputTextDepth","output-width":"gui-vertical-slider.outputWidth",percent:"gui-vertical-slider.percent","slider-bar-depth":"gui-vertical-slider.sliderBarDepth","slider-bar-width":"gui-vertical-slider.sliderBarWidth","top-bottom-padding":"gui-vertical-slider.topBottomPadding",width:"gui-item.width"}})},function(t,e,i){"use strict";var o=document.querySelector("#cursor");o&&o.addEventListener("stateremoved",function(t){"cursor-fusing"===t.detail.state&&(AFRAME.utils.entity.setComponentProperty(this,"geometry.thetaLength",360),AFRAME.utils.entity.setComponentProperty(this,"material.color",key_white),AFRAME.utils.entity.setComponentProperty(this,"scale","1 1 1"))})},function(t,e,i){"use strict";window.nearestPow2=function(t){Math.pow(2,Math.round(Math.log(t)/Math.log(2)))}},function(t,e,i){"use strict";window.normalYPosition=1.5,window.hiddenYPosition=1e3,window.key_orange="#ed5b21",window.key_orange_light="#ef8c60",window.key_grey="#22252a",window.key_grey_dark="#2c3037",window.key_grey_light="#606876",window.key_offwhite="#d3d3d4",window.key_white="#fff",window.icon_font={alert:"","alert-circled":"","android-add":"","android-add-circle":"","android-alarm-clock":"","android-alert":"","android-apps":"","android-archive":"","android-arrow-back":"","android-arrow-down":"","android-arrow-dropdown":"","android-arrow-dropdown-circle":"","android-arrow-dropleft":"","android-arrow-dropleft-circle":"","android-arrow-dropright":"","android-arrow-dropright-circle":"","android-arrow-dropup":"","android-arrow-dropup-circle":"","android-arrow-forward":"","android-arrow-up":"","android-attach":"","android-bar":"","android-bicycle":"","android-boat":"","android-bookmark":"","android-bulb":"","android-bus":"","android-calendar":"","android-call":"","android-camera":"","android-cancel":"","android-car":"","android-cart":"","android-chat":"","android-checkbox":"","android-checkbox-blank":"","android-checkbox-outline":"","android-checkbox-outline-blank":"","android-checkmark-circle":"","android-clipboard":"","android-close":"","android-cloud":"","android-cloud-circle":"","android-cloud-done":"","android-cloud-outline":"","android-color-palette":"","android-compass":"","android-contact":"","android-contacts":"","android-contract":"","android-create":"","android-delete":"","android-desktop":"","android-document":"","android-done":"","android-done-all":"","android-download":"","android-drafts":"","android-exit":"","android-expand":"","android-favorite":"","android-favorite-outline":"","android-film":"","android-folder":"","android-folder-open":"","android-funnel":"","android-globe":"","android-hand":"","android-hangout":"","android-happy":"","android-home":"","android-image":"","android-laptop":"","android-list":"","android-locate":"","android-lock":"","android-mail":"","android-map":"","android-menu":"","android-microphone":"","android-microphone-off":"","android-more-horizontal":"","android-more-vertical":"","android-navigate":"","android-notifications":"","android-notifications-none":"","android-notifications-off":"","android-open":"","android-options":"","android-people":"","android-person":"","android-person-add":"","android-phone-landscape":"","android-phone-portrait":"","android-pin":"","android-plane":"","android-playstore":"","android-print":"","android-radio-button-off":"","android-radio-button-on":"","android-refresh":"","android-remove":"","android-remove-circle":"","android-restaurant":"","android-sad":"","android-search":"","android-send":"","android-settings":"","android-share":"","android-share-alt":"","android-star":"","android-star-half":"","android-star-outline":"","android-stopwatch":"","android-subway":"","android-sunny":"","android-sync":"","android-textsms":"","android-time":"","android-train":"","android-unlock":"","android-upload":"","android-volume-down":"","android-volume-mute":"","android-volume-off":"","android-volume-up":"","android-walk":"","android-warning":"","android-watch":"","android-wifi":"",aperture:"",archive:"","arrow-down-a":"","arrow-down-b":"","arrow-down-c":"","arrow-expand":"","arrow-graph-down-left":"","arrow-graph-down-right":"","arrow-graph-up-left":"","arrow-graph-up-right":"","arrow-left-a":"","arrow-left-b":"","arrow-left-c":"","arrow-move":"","arrow-resize":"","arrow-return-left":"","arrow-return-right":"","arrow-right-a":"","arrow-right-b":"","arrow-right-c":"","arrow-shrink":"","arrow-swap":"","arrow-up-a":"","arrow-up-b":"","arrow-up-c":"",asterisk:"",at:"",backspace:"","backspace-outline":"",bag:"","battery-charging":"","battery-empty":"","battery-full":"","battery-half":"","battery-low":"",beaker:"",beer:"",bluetooth:"",bonfire:"",bookmark:"",bowtie:"",briefcase:"",bug:"",calculator:"",calendar:"",camera:"",card:"",cash:"",chatbox:"","chatbox-working":"",chatboxes:"",chatbubble:"","chatbubble-working":"",chatbubbles:"",checkmark:"","checkmark-circled":"","checkmark-round":"","chevron-down":"","chevron-left":"","chevron-right":"","chevron-up":"",clipboard:"",clock:"",close:"","close-circled":"","close-round":"","closed-captioning":"",cloud:"",code:"","code-download":"","code-working":"",coffee:"",compass:"",compose:"","connection-bars":"",contrast:"",crop:"",cube:"",disc:"",document:"","document-text":"",drag:"",earth:"",easel:"",edit:"",egg:"",eject:"",email:"","email-unread":"","erlenmeyer-flask":"","erlenmeyer-flask-bubbles":"",eye:"","eye-disabled":"",female:"",filing:"","film-marker":"",fireball:"",flag:"",flame:"",flash:"","flash-off":"",folder:"",fork:"","fork-repo":"",forward:"",funnel:"","gear-a":"","gear-b":"",grid:"",hammer:"",happy:"","happy-outline":"",headphone:"",heart:"","heart-broken":"",help:"","help-buoy":"","help-circled":"",home:"",icecream:"",image:"",images:"",information:"","information-circled":"",ionic:"","ios-alarm":"","ios-alarm-outline":"","ios-albums":"","ios-albums-outline":"","ios-americanfootball":"","ios-americanfootball-outline":"","ios-analytics":"","ios-analytics-outline":"","ios-arrow-back":"","ios-arrow-down":"","ios-arrow-forward":"","ios-arrow-left":"","ios-arrow-right":"","ios-arrow-thin-down":"","ios-arrow-thin-left":"","ios-arrow-thin-right":"","ios-arrow-thin-up":"","ios-arrow-up":"","ios-at":"","ios-at-outline":"","ios-barcode":"","ios-barcode-outline":"","ios-baseball":"","ios-baseball-outline":"","ios-basketball":"","ios-basketball-outline":"","ios-bell":"","ios-bell-outline":"","ios-body":"","ios-body-outline":"","ios-bolt":"","ios-bolt-outline":"","ios-book":"","ios-book-outline":"","ios-bookmarks":"","ios-bookmarks-outline":"","ios-box":"","ios-box-outline":"","ios-briefcase":"","ios-briefcase-outline":"","ios-browsers":"","ios-browsers-outline":"","ios-calculator":"","ios-calculator-outline":"","ios-calendar":"","ios-calendar-outline":"","ios-camera":"","ios-camera-outline":"","ios-cart":"","ios-cart-outline":"","ios-chatboxes":"","ios-chatboxes-outline":"","ios-chatbubble":"","ios-chatbubble-outline":"","ios-checkmark":"","ios-checkmark-empty":"","ios-checkmark-outline":"","ios-circle-filled":"","ios-circle-outline":"","ios-clock":"","ios-clock-outline":"","ios-close":"","ios-close-empty":"","ios-close-outline":"","ios-cloud":"","ios-cloud-download":"","ios-cloud-download-outline":"","ios-cloud-outline":"","ios-cloud-upload":"","ios-cloud-upload-outline":"","ios-cloudy":"","ios-cloudy-night":"","ios-cloudy-night-outline":"","ios-cloudy-outline":"","ios-cog":"","ios-cog-outline":"","ios-color-filter":"","ios-color-filter-outline":"","ios-color-wand":"","ios-color-wand-outline":"","ios-compose":"","ios-compose-outline":"","ios-contact":"","ios-contact-outline":"","ios-copy":"","ios-copy-outline":"","ios-crop":"","ios-crop-strong":"","ios-download":"","ios-download-outline":"","ios-drag":"","ios-email":"","ios-email-outline":"","ios-eye":"","ios-eye-outline":"","ios-fastforward":"","ios-fastforward-outline":"","ios-filing":"","ios-filing-outline":"","ios-film":"","ios-film-outline":"","ios-flag":"","ios-flag-outline":"","ios-flame":"","ios-flame-outline":"","ios-flask":"","ios-flask-outline":"","ios-flower":"","ios-flower-outline":"","ios-folder":"","ios-folder-outline":"","ios-football":"","ios-football-outline":"","ios-game-controller-a":"","ios-game-controller-a-outline":"","ios-game-controller-b":"","ios-game-controller-b-outline":"","ios-gear":"","ios-gear-outline":"","ios-glasses":"","ios-glasses-outline":"","ios-grid-view":"","ios-grid-view-outline":"","ios-heart":"","ios-heart-outline":"","ios-help":"","ios-help-empty":"","ios-help-outline":"","ios-home":"","ios-home-outline":"","ios-infinite":"","ios-infinite-outline":"","ios-information":"","ios-information-empty":"","ios-information-outline":"","ios-ionic-outline":"","ios-keypad":"","ios-keypad-outline":"","ios-lightbulb":"","ios-lightbulb-outline":"","ios-list":"","ios-list-outline":"","ios-location":"","ios-location-outline":"","ios-locked":"","ios-locked-outline":"","ios-loop":"","ios-loop-strong":"","ios-medical":"","ios-medical-outline":"","ios-medkit":"","ios-medkit-outline":"","ios-mic":"","ios-mic-off":"","ios-mic-outline":"","ios-minus":"","ios-minus-empty":"","ios-minus-outline":"","ios-monitor":"","ios-monitor-outline":"","ios-moon":"","ios-moon-outline":"","ios-more":"","ios-more-outline":"","ios-musical-note":"","ios-musical-notes":"","ios-navigate":"","ios-navigate-outline":"","ios-nutrition":"","ios-nutrition-outline":"","ios-paper":"","ios-paper-outline":"","ios-paperplane":"","ios-paperplane-outline":"","ios-partlysunny":"","ios-partlysunny-outline":"","ios-pause":"","ios-pause-outline":"","ios-paw":"","ios-paw-outline":"","ios-people":"","ios-people-outline":"","ios-person":"","ios-person-outline":"","ios-personadd":"","ios-personadd-outline":"","ios-photos":"","ios-photos-outline":"","ios-pie":"","ios-pie-outline":"","ios-pint":"","ios-pint-outline":"","ios-play":"","ios-play-outline":"","ios-plus":"","ios-plus-empty":"","ios-plus-outline":"","ios-pricetag":"","ios-pricetag-outline":"","ios-pricetags":"","ios-pricetags-outline":"","ios-printer":"","ios-printer-outline":"","ios-pulse":"","ios-pulse-strong":"","ios-rainy":"","ios-rainy-outline":"","ios-recording":"","ios-recording-outline":"","ios-redo":"","ios-redo-outline":"","ios-refresh":"","ios-refresh-empty":"","ios-refresh-outline":"","ios-reload":"","ios-reverse-camera":"","ios-reverse-camera-outline":"","ios-rewind":"","ios-rewind-outline":"","ios-rose":"","ios-rose-outline":"","ios-search":"","ios-search-strong":"","ios-settings":"","ios-settings-strong":"","ios-shuffle":"","ios-shuffle-strong":"","ios-skipbackward":"","ios-skipbackward-outline":"","ios-skipforward":"","ios-skipforward-outline":"","ios-snowy":"","ios-speedometer":"","ios-speedometer-outline":"","ios-star":"","ios-star-half":"","ios-star-outline":"","ios-stopwatch":"","ios-stopwatch-outline":"","ios-sunny":"","ios-sunny-outline":"","ios-telephone":"","ios-telephone-outline":"","ios-tennisball":"","ios-tennisball-outline":"","ios-thunderstorm":"","ios-thunderstorm-outline":"","ios-time":"","ios-time-outline":"","ios-timer":"","ios-timer-outline":"","ios-toggle":"","ios-toggle-outline":"","ios-trash":"","ios-trash-outline":"","ios-undo":"","ios-undo-outline":"","ios-unlocked":"","ios-unlocked-outline":"","ios-upload":"","ios-upload-outline":"","ios-videocam":"","ios-videocam-outline":"","ios-volume-high":"","ios-volume-low":"","ios-wineglass":"","ios-wineglass-outline":"","ios-world":"","ios-world-outline":"",ipad:"",iphone:"",ipod:"",jet:"",key:"",knife:"",laptop:"",leaf:"",levels:"",lightbulb:"",link:"","load-a":"","load-b":"","load-c":"","load-d":"",location:"","lock-combination":"",locked:"","log-in":"","log-out":"",loop:"",magnet:"",male:"",man:"",map:"",medkit:"",merge:"","mic-a":"","mic-b":"","mic-c":"",minus:"","minus-circled":"","minus-round":"","model-s":"",monitor:"",more:"",mouse:"","music-note":"",navicon:"","navicon-round":"",navigate:"",network:"","no-smoking":"",nuclear:"",outlet:"",paintbrush:"",paintbucket:"","paper-airplane":"",paperclip:"",pause:"",person:"","person-add":"","person-stalker":"","pie-graph":"",pin:"",pinpoint:"",pizza:"",plane:"",planet:"",play:"",playstation:"",plus:"","plus-circled":"","plus-round":"",podium:"",pound:"",power:"",pricetag:"",pricetags:"",printer:"","pull-request":"","qr-scanner":"",quote:"","radio-waves":"",record:"",refresh:"",reply:"","reply-all":"","ribbon-a":"","ribbon-b":"",sad:"","sad-outline":"",scissors:"",search:"",settings:"",share:"",shuffle:"","skip-backward":"","skip-forward":"","social-android":"","social-android-outline":"","social-angular":"","social-angular-outline":"","social-apple":"","social-apple-outline":"","social-bitcoin":"","social-bitcoin-outline":"","social-buffer":"","social-buffer-outline":"","social-chrome":"","social-chrome-outline":"","social-codepen":"","social-codepen-outline":"","social-css3":"","social-css3-outline":"","social-designernews":"","social-designernews-outline":"","social-dribbble":"","social-dribbble-outline":"","social-dropbox":"","social-dropbox-outline":"","social-euro":"","social-euro-outline":"","social-facebook":"","social-facebook-outline":"","social-foursquare":"","social-foursquare-outline":"","social-freebsd-devil":"","social-github":"","social-github-outline":"","social-google":"","social-google-outline":"","social-googleplus":"","social-googleplus-outline":"","social-hackernews":"","social-hackernews-outline":"","social-html5":"","social-html5-outline":"","social-instagram":"","social-instagram-outline":"","social-javascript":"","social-javascript-outline":"","social-linkedin":"","social-linkedin-outline":"","social-markdown":"","social-nodejs":"","social-octocat":"","social-pinterest":"","social-pinterest-outline":"","social-python":"","social-reddit":"","social-reddit-outline":"","social-rss":"","social-rss-outline":"","social-sass":"","social-skype":"","social-skype-outline":"","social-snapchat":"","social-snapchat-outline":"","social-tumblr":"","social-tumblr-outline":"","social-tux":"","social-twitch":"","social-twitch-outline":"","social-twitter":"","social-twitter-outline":"","social-usd":"","social-usd-outline":"","social-vimeo":"","social-vimeo-outline":"","social-whatsapp":"","social-whatsapp-outline":"","social-windows":"","social-windows-outline":"","social-wordpress":"","social-wordpress-outline":"","social-yahoo":"","social-yahoo-outline":"","social-yen":"","social-yen-outline":"","social-youtube":"","social-youtube-outline":"","soup-can":"","soup-can-outline":"",speakerphone:"",speedometer:"",spoon:"",star:"","stats-bars":"",steam:"",stop:"",thermometer:"",thumbsdown:"",thumbsup:"",toggle:"","toggle-filled":"",transgender:"","trash-a":"","trash-b":"",trophy:"",tshirt:"","tshirt-outline":"",umbrella:"",university:"",unlocked:"",upload:"",usb:"",videocamera:"","volume-high":"","volume-low":"","volume-medium":"","volume-mute":"",wand:"",waterdrop:"",wifi:"",wineglass:"",woman:"",wrench:"",xbox:""},window.getUniqueId=function(t){return t+"_"+(new Date).getTime().toString()+Math.random().toString().replace(".","")},window.getTextWidth=function(t,e){var i=getTextWidth.canvas||(getTextWidth.canvas=document.createElement("canvas")),o=i.getContext("2d");return o.font=e,o.measureText(t).width},window.drawText=function(t,e,i,o,r,a){var n=arguments.length>6&&void 0!==arguments[6]?arguments[6]:1,l=arguments.length>7&&void 0!==arguments[7]?arguments[7]:"center",s=arguments.length>8&&void 0!==arguments[8]?arguments[8]:"middle",u=arguments.length>9&&void 0!==arguments[9]?arguments[9]:"normal";t.font=u+" "+o+" "+r,t.fillStyle=a,t.textAlign=l,t.textBaseline=s,t.scale(n,n),t.clearRect(0,0,e.width,e.height);var d=i+"";if(d.match("char#")){var c=d.substring(d.indexOf("#")+1);"left"==l?t.fillText(String.fromCharCode(c),e.height/8,e.height/2):t.fillText(String.fromCharCode(c),e.width/2,e.height/2)}else"left"==l?t.fillText(d,e.height/8,e.height/2):t.fillText(d,e.width/2,e.height/2)},window.drawIcon=function(t,e,i,o,r){var a=arguments.length>5&&void 0!==arguments[5]?arguments[5]:1;t.font=i+" Ionicons",t.fillStyle=r,t.textAlign="center",t.textBaseline="middle",t.clearRect(0,0,e.width,e.height),t.scale(a,a),icon_font[o]?t.fillText(icon_font[o],e.width/2,e.height/2):t.fillText("?",e.width/2,e.height/2)}},function(t,e,i){"use strict";if("undefined"==typeof AFRAME)throw new Error("Component attempted to register before AFRAME was available.");i(20),i(19),i(10),i(0),i(9),i(5),i(11),i(1),i(6),i(7),i(16),i(13),i(2),i(12),i(3),i(15),i(17),i(8),i(4),i(14),i(18)}]); \ No newline at end of file diff --git a/examples/all_components_colors.html b/examples/all_components_colors.html index ea3acba..3dd2771 100644 --- a/examples/all_components_colors.html +++ b/examples/all_components_colors.html @@ -3,8 +3,9 @@ A-Frame GUI Colors - + + diff --git a/examples/all_components_mouse_quest.html b/examples/all_components_mouse_quest.html index 7a94817..c325be9 100644 --- a/examples/all_components_mouse_quest.html +++ b/examples/all_components_mouse_quest.html @@ -3,8 +3,9 @@ A-Frame GUI All Components - - + + + diff --git a/examples/casestudy_amper.html b/examples/casestudy_amper.html index c054208..312adb4 100644 --- a/examples/casestudy_amper.html +++ b/examples/casestudy_amper.html @@ -3,7 +3,8 @@ A-Frame GUI - + +