From 21767ceeac0fd4f90b39033a7cda0277088dc70c Mon Sep 17 00:00:00 2001 From: haydenjameslee Date: Sun, 19 Jan 2020 16:34:44 -0500 Subject: [PATCH] Update babel and 0.7 dist --- dist/networked-aframe.js | 2941 +++----------------------------- dist/networked-aframe.min.js | 10 +- package-lock.json | 3103 +++++++++++++++++++++------------- package.json | 12 +- webpack.config.js | 12 +- webpack.prod.config.js | 12 +- 6 files changed, 2122 insertions(+), 3968 deletions(-) diff --git a/dist/networked-aframe.js b/dist/networked-aframe.js index fd05a9ac..5ff114fe 100644 --- a/dist/networked-aframe.js +++ b/dist/networked-aframe.js @@ -1,2832 +1,293 @@ /******/ (function(modules) { // webpackBootstrap /******/ // The module cache /******/ var installedModules = {}; - +/******/ /******/ // The require function /******/ function __webpack_require__(moduleId) { - +/******/ /******/ // Check if module is in cache -/******/ if(installedModules[moduleId]) +/******/ if(installedModules[moduleId]) { /******/ return installedModules[moduleId].exports; - +/******/ } /******/ // Create a new module (and put it into the cache) /******/ var module = installedModules[moduleId] = { -/******/ exports: {}, -/******/ id: moduleId, -/******/ loaded: false +/******/ i: moduleId, +/******/ l: false, +/******/ exports: {} /******/ }; - +/******/ /******/ // Execute the module function /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); - +/******/ /******/ // Flag the module as loaded -/******/ module.loaded = true; - +/******/ module.l = true; +/******/ /******/ // Return the exports of the module /******/ return module.exports; /******/ } - - +/******/ +/******/ /******/ // expose the modules object (__webpack_modules__) /******/ __webpack_require__.m = modules; - +/******/ /******/ // expose the module cache /******/ __webpack_require__.c = installedModules; - +/******/ +/******/ // define getter function for harmony exports +/******/ __webpack_require__.d = function(exports, name, getter) { +/******/ if(!__webpack_require__.o(exports, name)) { +/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter }); +/******/ } +/******/ }; +/******/ +/******/ // define __esModule on exports +/******/ __webpack_require__.r = function(exports) { +/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { +/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); +/******/ } +/******/ Object.defineProperty(exports, '__esModule', { value: true }); +/******/ }; +/******/ +/******/ // create a fake namespace object +/******/ // mode & 1: value is a module id, require it +/******/ // mode & 2: merge all properties of value into the ns +/******/ // mode & 4: return value when already ns object +/******/ // mode & 8|1: behave like require +/******/ __webpack_require__.t = function(value, mode) { +/******/ if(mode & 1) value = __webpack_require__(value); +/******/ if(mode & 8) return value; +/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value; +/******/ var ns = Object.create(null); +/******/ __webpack_require__.r(ns); +/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value }); +/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key)); +/******/ return ns; +/******/ }; +/******/ +/******/ // getDefaultExport function for compatibility with non-harmony modules +/******/ __webpack_require__.n = function(module) { +/******/ var getter = module && module.__esModule ? +/******/ function getDefault() { return module['default']; } : +/******/ function getModuleExports() { return module; }; +/******/ __webpack_require__.d(getter, 'a', getter); +/******/ return getter; +/******/ }; +/******/ +/******/ // Object.prototype.hasOwnProperty.call +/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; +/******/ /******/ // __webpack_public_path__ /******/ __webpack_require__.p = ""; - +/******/ +/******/ /******/ // Load entry module and return exports -/******/ return __webpack_require__(0); +/******/ return __webpack_require__(__webpack_require__.s = "./src/index.js"); /******/ }) /************************************************************************/ -/******/ ([ -/* 0 */ -/***/ (function(module, exports, __webpack_require__) { - - 'use strict'; +/******/ ({ - // Global vars and functions - __webpack_require__(1); - - // Network components - __webpack_require__(11); - __webpack_require__(12); - __webpack_require__(15); - -/***/ }), -/* 1 */ +/***/ "./node_modules/buffered-interpolation/dist/buffered-interpolation.js": +/*!****************************************************************************!*\ + !*** ./node_modules/buffered-interpolation/dist/buffered-interpolation.js ***! + \****************************************************************************/ +/*! no static exports found */ /***/ (function(module, exports, __webpack_require__) { - 'use strict'; - - var options = __webpack_require__(2); - var utils = __webpack_require__(3); - var NafLogger = __webpack_require__(4); - var Schemas = __webpack_require__(5); - var NetworkEntities = __webpack_require__(6); - var NetworkConnection = __webpack_require__(8); - var AdapterFactory = __webpack_require__(9); - - var naf = {}; - naf.app = ''; - naf.room = ''; - naf.clientId = ''; - naf.options = options; - naf.utils = utils; - naf.log = new NafLogger(); - naf.schemas = new Schemas(); - naf.version = "0.6.1"; - - naf.adapters = new AdapterFactory(); - var entities = new NetworkEntities(); - var connection = new NetworkConnection(entities); - naf.connection = connection; - naf.entities = entities; - - module.exports = window.NAF = naf; +"use strict"; +eval("\n\nvar _createClass = function () {\n function defineProperties(target, props) {\n for (var i = 0; i < props.length; i++) {\n var descriptor = props[i];\n descriptor.enumerable = descriptor.enumerable || false;\n descriptor.configurable = true;\n if (\"value\" in descriptor) descriptor.writable = true;\n Object.defineProperty(target, descriptor.key, descriptor);\n }\n }\n\n return function (Constructor, protoProps, staticProps) {\n if (protoProps) defineProperties(Constructor.prototype, protoProps);\n if (staticProps) defineProperties(Constructor, staticProps);\n return Constructor;\n };\n}();\n\nfunction _classCallCheck(instance, Constructor) {\n if (!(instance instanceof Constructor)) {\n throw new TypeError(\"Cannot call a class as a function\");\n }\n}\n/* global THREE */\n\n\nvar INITIALIZING = 0;\nvar BUFFERING = 1;\nvar PLAYING = 2;\nvar MODE_LERP = 0;\nvar MODE_HERMITE = 1;\nvar vectorPool = [];\nvar quatPool = [];\nvar framePool = [];\n\nvar getPooledVector = function getPooledVector() {\n return vectorPool.shift() || new THREE.Vector3();\n};\n\nvar getPooledQuaternion = function getPooledQuaternion() {\n return quatPool.shift() || new THREE.Quaternion();\n};\n\nvar getPooledFrame = function getPooledFrame() {\n var frame = framePool.pop();\n\n if (!frame) {\n frame = {\n position: new THREE.Vector3(),\n velocity: new THREE.Vector3(),\n scale: new THREE.Vector3(),\n quaternion: new THREE.Quaternion(),\n time: 0\n };\n }\n\n return frame;\n};\n\nvar freeFrame = function freeFrame(f) {\n return framePool.push(f);\n};\n\nvar InterpolationBuffer = function () {\n function InterpolationBuffer() {\n var mode = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : MODE_LERP;\n var bufferTime = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0.15;\n\n _classCallCheck(this, InterpolationBuffer);\n\n this.state = INITIALIZING;\n this.buffer = [];\n this.bufferTime = bufferTime * 1000;\n this.time = 0;\n this.mode = mode;\n this.originFrame = getPooledFrame();\n this.position = new THREE.Vector3();\n this.quaternion = new THREE.Quaternion();\n this.scale = new THREE.Vector3(1, 1, 1);\n }\n\n _createClass(InterpolationBuffer, [{\n key: \"hermite\",\n value: function hermite(target, t, p1, p2, v1, v2) {\n var t2 = t * t;\n var t3 = t * t * t;\n var a = 2 * t3 - 3 * t2 + 1;\n var b = -2 * t3 + 3 * t2;\n var c = t3 - 2 * t2 + t;\n var d = t3 - t2;\n target.copy(p1.multiplyScalar(a));\n target.add(p2.multiplyScalar(b));\n target.add(v1.multiplyScalar(c));\n target.add(v2.multiplyScalar(d));\n }\n }, {\n key: \"lerp\",\n value: function lerp(target, v1, v2, alpha) {\n target.lerpVectors(v1, v2, alpha);\n }\n }, {\n key: \"slerp\",\n value: function slerp(target, r1, r2, alpha) {\n THREE.Quaternion.slerp(r1, r2, target, alpha);\n }\n }, {\n key: \"updateOriginFrameToBufferTail\",\n value: function updateOriginFrameToBufferTail() {\n freeFrame(this.originFrame);\n this.originFrame = this.buffer.shift();\n }\n }, {\n key: \"appendBuffer\",\n value: function appendBuffer(position, velocity, quaternion, scale) {\n var tail = this.buffer.length > 0 ? this.buffer[this.buffer.length - 1] : null; // update the last entry in the buffer if this is the same frame\n\n if (tail && tail.time === this.time) {\n if (position) {\n tail.position.copy(position);\n }\n\n if (velocity) {\n tail.velocity.copy(velocity);\n }\n\n if (quaternion) {\n tail.quaternion.copy(quaternion);\n }\n\n if (scale) {\n tail.scale.copy(scale);\n }\n } else {\n var priorFrame = tail || this.originFrame;\n var newFrame = getPooledFrame();\n newFrame.position.copy(position || priorFrame.position);\n newFrame.velocity.copy(velocity || priorFrame.velocity);\n newFrame.quaternion.copy(quaternion || priorFrame.quaternion);\n newFrame.scale.copy(scale || priorFrame.scale);\n newFrame.time = this.time;\n this.buffer.push(newFrame);\n }\n }\n }, {\n key: \"setTarget\",\n value: function setTarget(position, velocity, quaternion, scale) {\n this.appendBuffer(position, velocity, quaternion, scale);\n }\n }, {\n key: \"setPosition\",\n value: function setPosition(position, velocity) {\n this.appendBuffer(position, velocity, null, null);\n }\n }, {\n key: \"setQuaternion\",\n value: function setQuaternion(quaternion) {\n this.appendBuffer(null, null, quaternion, null);\n }\n }, {\n key: \"setScale\",\n value: function setScale(scale) {\n this.appendBuffer(null, null, null, scale);\n }\n }, {\n key: \"update\",\n value: function update(delta) {\n if (this.state === INITIALIZING) {\n if (this.buffer.length > 0) {\n this.updateOriginFrameToBufferTail();\n this.position.copy(this.originFrame.position);\n this.quaternion.copy(this.originFrame.quaternion);\n this.scale.copy(this.originFrame.scale);\n this.state = BUFFERING;\n }\n }\n\n if (this.state === BUFFERING) {\n if (this.buffer.length > 0 && this.time > this.bufferTime) {\n this.state = PLAYING;\n }\n }\n\n if (this.state === PLAYING) {\n var mark = this.time - this.bufferTime; //Purge this.buffer of expired frames\n\n while (this.buffer.length > 0 && mark > this.buffer[0].time) {\n //if this is the last frame in the buffer, just update the time and reuse it\n if (this.buffer.length > 1) {\n this.updateOriginFrameToBufferTail();\n } else {\n this.originFrame.position.copy(this.buffer[0].position);\n this.originFrame.velocity.copy(this.buffer[0].velocity);\n this.originFrame.quaternion.copy(this.buffer[0].quaternion);\n this.originFrame.scale.copy(this.buffer[0].scale);\n this.originFrame.time = this.buffer[0].time;\n this.buffer[0].time = this.time + delta;\n }\n }\n\n if (this.buffer.length > 0 && this.buffer[0].time > 0) {\n var targetFrame = this.buffer[0];\n var delta_time = targetFrame.time - this.originFrame.time;\n var alpha = (mark - this.originFrame.time) / delta_time;\n\n if (this.mode === MODE_LERP) {\n this.lerp(this.position, this.originFrame.position, targetFrame.position, alpha);\n } else if (this.mode === MODE_HERMITE) {\n this.hermite(this.position, alpha, this.originFrame.position, targetFrame.position, this.originFrame.velocity.multiplyScalar(delta_time), targetFrame.velocity.multiplyScalar(delta_time));\n }\n\n this.slerp(this.quaternion, this.originFrame.quaternion, targetFrame.quaternion, alpha);\n this.lerp(this.scale, this.originFrame.scale, targetFrame.scale, alpha);\n }\n }\n\n if (this.state !== INITIALIZING) {\n this.time += delta;\n }\n }\n }, {\n key: \"getPosition\",\n value: function getPosition() {\n return this.position;\n }\n }, {\n key: \"getQuaternion\",\n value: function getQuaternion() {\n return this.quaternion;\n }\n }, {\n key: \"getScale\",\n value: function getScale() {\n return this.scale;\n }\n }]);\n\n return InterpolationBuffer;\n}();\n\nmodule.exports = InterpolationBuffer;\n\n//# sourceURL=webpack:///./node_modules/buffered-interpolation/dist/buffered-interpolation.js?"); /***/ }), -/* 2 */ -/***/ (function(module, exports) { - "use strict"; +/***/ "./src/ChildEntityCache.js": +/*!*********************************!*\ + !*** ./src/ChildEntityCache.js ***! + \*********************************/ +/*! no static exports found */ +/***/ (function(module, exports, __webpack_require__) { - var options = { - debug: false, - updateRate: 15, // How often network components call `sync` - useLerp: true, // lerp position, rotation, and scale components on networked entities. - firstSyncSource: null, // If specified, only allow first syncs from this source. - syncSource: null // If specified, only allow syncs from this source. - }; - module.exports = options; +"use strict"; +eval("\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nfunction _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); } }\n\nfunction _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }\n\nvar ChildEntityCache =\n/*#__PURE__*/\nfunction () {\n function ChildEntityCache() {\n _classCallCheck(this, ChildEntityCache);\n\n this.dict = {};\n }\n\n _createClass(ChildEntityCache, [{\n key: \"addChild\",\n value: function addChild(parentNetworkId, childData) {\n if (!this.hasParent(parentNetworkId)) {\n this.dict[parentNetworkId] = [];\n }\n\n this.dict[parentNetworkId].push(childData);\n }\n }, {\n key: \"getChildren\",\n value: function getChildren(parentNetworkId) {\n if (!this.hasParent(parentNetworkId)) {\n return [];\n }\n\n var children = this.dict[parentNetworkId];\n delete this.dict[parentNetworkId];\n return children;\n }\n /* Private */\n\n }, {\n key: \"hasParent\",\n value: function hasParent(parentId) {\n return !!this.dict[parentId];\n }\n }]);\n\n return ChildEntityCache;\n}();\n\nmodule.exports = ChildEntityCache;\n\n//# sourceURL=webpack:///./src/ChildEntityCache.js?"); /***/ }), -/* 3 */ -/***/ (function(module, exports) { - - 'use strict'; - - /* global NAF */ - - module.exports.whenEntityLoaded = function (entity, callback) { - if (entity.hasLoaded) { - callback(); - } - entity.addEventListener('loaded', function () { - callback(); - }); - }; - - module.exports.createHtmlNodeFromString = function (str) { - var div = document.createElement('div'); - div.innerHTML = str; - var child = div.firstChild; - return child; - }; - module.exports.getCreator = function (el) { - var components = el.components; - if (components['networked']) { - return components['networked'].data.creator; - } - return null; - }; - - module.exports.getNetworkOwner = function (el) { - var components = el.components; - if (components['networked']) { - return components['networked'].data.owner; - } - return null; - }; - - module.exports.getNetworkId = function (el) { - var components = el.components; - if (components['networked']) { - return components['networked'].data.networkId; - } - return null; - }; - - module.exports.now = function () { - return Date.now(); - }; - - module.exports.createNetworkId = function () { - return Math.random().toString(36).substring(2, 9); - }; - - /** - * Find the closest ancestor (including the passed in entity) that has a `networked` component - * @param {ANode} entity - Entity to begin the search on - * @returns {Promise} An promise that resolves to an entity with a `networked` component - */ - function getNetworkedEntity(entity) { - return new Promise(function (resolve, reject) { - var curEntity = entity; - - while (curEntity && curEntity.components && !curEntity.components.networked) { - curEntity = curEntity.parentNode; - } - - if (!curEntity || !curEntity.components || !curEntity.components.networked) { - return reject("Entity does not have and is not a child of an entity with the [networked] component "); - } - - if (curEntity.hasLoaded) { - resolve(curEntity); - } else { - curEntity.addEventListener("instantiated", function () { - resolve(curEntity); - }, { once: true }); - } - }); - } - - module.exports.getNetworkedEntity = getNetworkedEntity; - - module.exports.takeOwnership = function (entity) { - var curEntity = entity; - - while (curEntity && curEntity.components && !curEntity.components.networked) { - curEntity = curEntity.parentNode; - } - - if (!curEntity || !curEntity.components || !curEntity.components.networked) { - throw new Error("Entity does not have and is not a child of an entity with the [networked] component "); - } - - return curEntity.components.networked.takeOwnership(); - }; - - module.exports.isMine = function (entity) { - var curEntity = entity; - - while (curEntity && curEntity.components && !curEntity.components.networked) { - curEntity = curEntity.parentNode; - } - - if (!curEntity || !curEntity.components || !curEntity.components.networked) { - throw new Error("Entity does not have and is not a child of an entity with the [networked] component "); - } - - return curEntity.components.networked.data.owner === NAF.clientId; - }; +/***/ "./src/DeepEquals.js": +/*!***************************!*\ + !*** ./src/DeepEquals.js ***! + \***************************/ +/*! no static exports found */ +/***/ (function(module, exports, __webpack_require__) { - module.exports.almostEqualVec3 = function (u, v, epsilon) { - return Math.abs(u.x - v.x) < epsilon && Math.abs(u.y - v.y) < epsilon && Math.abs(u.z - v.z) < epsilon; - }; +"use strict"; +eval("// Patched version of fast-deep-equal which does not\n// allocate memory via calling Object.keys\n//\n// https://github.com/epoberezkin/fast-deep-equal/blob/master/index.js\n\n\nfunction _typeof(obj) { if (typeof Symbol === \"function\" && typeof Symbol.iterator === \"symbol\") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === \"function\" && obj.constructor === Symbol && obj !== Symbol.prototype ? \"symbol\" : typeof obj; }; } return _typeof(obj); }\n\nvar isArray = Array.isArray;\nvar keyList = Object.keys;\nvar hasProp = Object.prototype.hasOwnProperty;\n\nmodule.exports = function equal(a, b) {\n if (a === b) return true;\n\n if (a && b && _typeof(a) == 'object' && _typeof(b) == 'object') {\n var arrA = isArray(a),\n arrB = isArray(b),\n i,\n length,\n key;\n\n if (arrA && arrB) {\n length = a.length;\n if (length != b.length) return false;\n\n for (i = length; i-- !== 0;) {\n if (!equal(a[i], b[i])) return false;\n }\n\n return true;\n }\n\n if (arrA != arrB) return false;\n var dateA = a instanceof Date,\n dateB = b instanceof Date;\n if (dateA != dateB) return false;\n if (dateA && dateB) return a.getTime() == b.getTime();\n var regexpA = a instanceof RegExp,\n regexpB = b instanceof RegExp;\n if (regexpA != regexpB) return false;\n if (regexpA && regexpB) return a.toString() == b.toString();\n var keys = keyList(a);\n length = keys.length;\n if (length !== keyList(b).length) return false;\n\n for (i = length; i-- !== 0;) {\n if (!hasProp.call(b, keys[i])) return false;\n }\n\n for (i = length; i-- !== 0;) {\n key = keys[i];\n if (!equal(a[key], b[key])) return false;\n }\n\n return true;\n }\n\n return a !== a && b !== b;\n};\n\n//# sourceURL=webpack:///./src/DeepEquals.js?"); /***/ }), -/* 4 */ -/***/ (function(module, exports) { - - "use strict"; - - 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; }; }(); - - function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - - /*eslint no-console: "off" */ - - var NafLogger = function () { - function NafLogger() { - _classCallCheck(this, NafLogger); - - this.debug = false; - } - _createClass(NafLogger, [{ - key: "setDebug", - value: function setDebug(debug) { - this.debug = debug; - } - }, { - key: "write", - value: function write() { - if (this.debug) { - console.log.apply(this, arguments); - } - } - }, { - key: "warn", - value: function warn() { - console.warn.apply(this, arguments); - } - }, { - key: "error", - value: function error() { - console.error.apply(this, arguments); - } - }]); - - return NafLogger; - }(); +/***/ "./src/NafIndex.js": +/*!*************************!*\ + !*** ./src/NafIndex.js ***! + \*************************/ +/*! no static exports found */ +/***/ (function(module, exports, __webpack_require__) { - module.exports = NafLogger; +"use strict"; +eval("\n\nvar options = __webpack_require__(/*! ./options */ \"./src/options.js\");\n\nvar utils = __webpack_require__(/*! ./utils */ \"./src/utils.js\");\n\nvar NafLogger = __webpack_require__(/*! ./NafLogger */ \"./src/NafLogger.js\");\n\nvar Schemas = __webpack_require__(/*! ./Schemas */ \"./src/Schemas.js\");\n\nvar NetworkEntities = __webpack_require__(/*! ./NetworkEntities */ \"./src/NetworkEntities.js\");\n\nvar NetworkConnection = __webpack_require__(/*! ./NetworkConnection */ \"./src/NetworkConnection.js\");\n\nvar AdapterFactory = __webpack_require__(/*! ./adapters/AdapterFactory */ \"./src/adapters/AdapterFactory.js\");\n\nvar naf = {};\nnaf.app = '';\nnaf.room = '';\nnaf.clientId = '';\nnaf.options = options;\nnaf.utils = utils;\nnaf.log = new NafLogger();\nnaf.schemas = new Schemas();\nnaf.version = \"0.6.1\";\nnaf.adapters = new AdapterFactory();\nvar entities = new NetworkEntities();\nvar connection = new NetworkConnection(entities);\nnaf.connection = connection;\nnaf.entities = entities;\nmodule.exports = window.NAF = naf;\n\n//# sourceURL=webpack:///./src/NafIndex.js?"); /***/ }), -/* 5 */ -/***/ (function(module, exports) { - - 'use strict'; - - 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; }; }(); - - function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - - /* global NAF */ - - var Schemas = function () { - function Schemas() { - _classCallCheck(this, Schemas); - this.schemaDict = {}; - this.templateCache = {}; - } - - _createClass(Schemas, [{ - key: 'createDefaultSchema', - value: function createDefaultSchema(name) { - return { - template: name, - components: ['position', 'rotation'] - }; - } - }, { - key: 'add', - value: function add(schema) { - if (this.validateSchema(schema)) { - this.schemaDict[schema.template] = schema; - var templateEl = document.querySelector(schema.template); - if (!templateEl) { - NAF.log.error('Template el not found for ' + schema.template + ', make sure NAF.schemas.add is called after is defined.'); - return; - } - if (!this.validateTemplate(schema, templateEl)) { - return; - } - this.templateCache[schema.template] = document.importNode(templateEl.content, true); - } else { - NAF.log.error('Schema not valid: ', schema); - NAF.log.error('See https://github.com/haydenjameslee/networked-aframe#syncing-custom-components'); - } - } - }, { - key: 'getCachedTemplate', - value: function getCachedTemplate(template) { - if (!this.templateIsCached(template)) { - if (this.templateExistsInScene(template)) { - this.add(this.createDefaultSchema(template)); - } else { - NAF.log.error('Template el for ' + template + ' is not in the scene, add the template to and register with NAF.schemas.add.'); - } - } - return this.templateCache[template].firstElementChild.cloneNode(true); - } - }, { - key: 'templateIsCached', - value: function templateIsCached(template) { - return !!this.templateCache[template]; - } - }, { - key: 'getComponents', - value: function getComponents(template) { - var components = ['position', 'rotation']; - if (this.hasTemplate(template)) { - components = this.schemaDict[template].components; - } - return components; - } - }, { - key: 'hasTemplate', - value: function hasTemplate(template) { - return !!this.schemaDict[template]; - } - }, { - key: 'templateExistsInScene', - value: function templateExistsInScene(templateSelector) { - var el = document.querySelector(templateSelector); - return el && this.isTemplateTag(el); - } - }, { - key: 'validateSchema', - value: function validateSchema(schema) { - return !!(schema['template'] && schema['components']); - } - }, { - key: 'validateTemplate', - value: function validateTemplate(schema, el) { - if (!this.isTemplateTag(el)) { - NAF.log.error('Template for ' + schema.template + ' is not a