diff --git a/build/ros3d.cjs.js b/build/ros3d.cjs.js index 8d89cddb..eda80f82 100644 --- a/build/ros3d.cjs.js +++ b/build/ros3d.cjs.js @@ -53263,1633 +53263,1640 @@ var eventemitter2 = {exports: {}}; */ eventemitter2.exports; -(function (module, exports) { +var hasRequiredEventemitter2; + +function requireEventemitter2 () { + if (hasRequiredEventemitter2) { return eventemitter2.exports; } + hasRequiredEventemitter2 = 1; + (function (module, exports) { !function(undefined$1) { - var hasOwnProperty= Object.hasOwnProperty; - var isArray = Array.isArray ? Array.isArray : function _isArray(obj) { - return Object.prototype.toString.call(obj) === "[object Array]"; - }; - var defaultMaxListeners = 10; - var nextTickSupported= typeof process=='object' && typeof process.nextTick=='function'; - var symbolsSupported= typeof Symbol==='function'; - var reflectSupported= typeof Reflect === 'object'; - var setImmediateSupported= typeof setImmediate === 'function'; - var _setImmediate= setImmediateSupported ? setImmediate : setTimeout; - var ownKeys= symbolsSupported? (reflectSupported && typeof Reflect.ownKeys==='function'? Reflect.ownKeys : function(obj){ - var arr= Object.getOwnPropertyNames(obj); - arr.push.apply(arr, Object.getOwnPropertySymbols(obj)); - return arr; - }) : Object.keys; - - function init() { - this._events = {}; - if (this._conf) { - configure.call(this, this._conf); - } - } - - function configure(conf) { - if (conf) { - this._conf = conf; - - conf.delimiter && (this.delimiter = conf.delimiter); - - if(conf.maxListeners!==undefined$1){ - this._maxListeners= conf.maxListeners; - } - - conf.wildcard && (this.wildcard = conf.wildcard); - conf.newListener && (this._newListener = conf.newListener); - conf.removeListener && (this._removeListener = conf.removeListener); - conf.verboseMemoryLeak && (this.verboseMemoryLeak = conf.verboseMemoryLeak); - conf.ignoreErrors && (this.ignoreErrors = conf.ignoreErrors); - - if (this.wildcard) { - this.listenerTree = {}; - } - } - } - - function logPossibleMemoryLeak(count, eventName) { - var errorMsg = '(node) warning: possible EventEmitter memory ' + - 'leak detected. ' + count + ' listeners added. ' + - 'Use emitter.setMaxListeners() to increase limit.'; - - if(this.verboseMemoryLeak){ - errorMsg += ' Event name: ' + eventName + '.'; - } - - if(typeof process !== 'undefined' && process.emitWarning){ - var e = new Error(errorMsg); - e.name = 'MaxListenersExceededWarning'; - e.emitter = this; - e.count = count; - process.emitWarning(e); - } else { - console.error(errorMsg); - - if (console.trace){ - console.trace(); - } - } - } - - var toArray = function (a, b, c) { - var arguments$1 = arguments; - - var n = arguments.length; - switch (n) { - case 0: - return []; - case 1: - return [a]; - case 2: - return [a, b]; - case 3: - return [a, b, c]; - default: - var arr = new Array(n); - while (n--) { - arr[n] = arguments$1[n]; - } - return arr; - } - }; - - function toObject(keys, values) { - var obj = {}; - var key; - var len = keys.length; - var valuesCount = values ? value.length : 0; - for (var i = 0; i < len; i++) { - key = keys[i]; - obj[key] = i < valuesCount ? values[i] : undefined$1; - } - return obj; - } - - function TargetObserver(emitter, target, options) { - this._emitter = emitter; - this._target = target; - this._listeners = {}; - this._listenersCount = 0; - - var on, off; - - if (options.on || options.off) { - on = options.on; - off = options.off; - } - - if (target.addEventListener) { - on = target.addEventListener; - off = target.removeEventListener; - } else if (target.addListener) { - on = target.addListener; - off = target.removeListener; - } else if (target.on) { - on = target.on; - off = target.off; - } - - if (!on && !off) { - throw Error('target does not implement any known event API'); - } - - if (typeof on !== 'function') { - throw TypeError('on method must be a function'); - } - - if (typeof off !== 'function') { - throw TypeError('off method must be a function'); - } - - this._on = on; - this._off = off; - - var _observers= emitter._observers; - if(_observers){ - _observers.push(this); - }else { - emitter._observers= [this]; - } - } - - Object.assign(TargetObserver.prototype, { - subscribe: function(event, localEvent, reducer){ - var observer= this; - var target= this._target; - var emitter= this._emitter; - var listeners= this._listeners; - var handler= function(){ - var args= toArray.apply(null, arguments); - var eventObj= { - data: args, - name: localEvent, - original: event - }; - if(reducer){ - var result= reducer.call(target, eventObj); - if(result!==false){ - emitter.emit.apply(emitter, [eventObj.name].concat(args)); - } - return; - } - emitter.emit.apply(emitter, [localEvent].concat(args)); - }; - - - if(listeners[event]){ - throw Error('Event \'' + event + '\' is already listening'); - } - - this._listenersCount++; - - if(emitter._newListener && emitter._removeListener && !observer._onNewListener){ - - this._onNewListener = function (_event) { - if (_event === localEvent && listeners[event] === null) { - listeners[event] = handler; - observer._on.call(target, event, handler); - } - }; - - emitter.on('newListener', this._onNewListener); - - this._onRemoveListener= function(_event){ - if(_event === localEvent && !emitter.hasListeners(_event) && listeners[event]){ - listeners[event]= null; - observer._off.call(target, event, handler); - } - }; - - listeners[event]= null; - - emitter.on('removeListener', this._onRemoveListener); - }else { - listeners[event]= handler; - observer._on.call(target, event, handler); - } - }, - - unsubscribe: function(event){ - var observer= this; - var listeners= this._listeners; - var emitter= this._emitter; - var handler; - var events; - var off= this._off; - var target= this._target; - var i; - - if(event && typeof event!=='string'){ - throw TypeError('event must be a string'); - } - - function clearRefs(){ - if(observer._onNewListener){ - emitter.off('newListener', observer._onNewListener); - emitter.off('removeListener', observer._onRemoveListener); - observer._onNewListener= null; - observer._onRemoveListener= null; - } - var index= findTargetIndex.call(emitter, observer); - emitter._observers.splice(index, 1); - } - - if(event){ - handler= listeners[event]; - if(!handler) { return; } - off.call(target, event, handler); - delete listeners[event]; - if(!--this._listenersCount){ - clearRefs(); - } - }else { - events= ownKeys(listeners); - i= events.length; - while(i-->0){ - event= events[i]; - off.call(target, event, listeners[event]); - } - this._listeners= {}; - this._listenersCount= 0; - clearRefs(); - } - } - }); - - function resolveOptions(options, schema, reducers, allowUnknown) { - var computedOptions = Object.assign({}, schema); - - if (!options) { return computedOptions; } - - if (typeof options !== 'object') { - throw TypeError('options must be an object') - } - - var keys = Object.keys(options); - var length = keys.length; - var option, value; - var reducer; - - function reject(reason) { - throw Error('Invalid "' + option + '" option value' + (reason ? '. Reason: ' + reason : '')) - } - - for (var i = 0; i < length; i++) { - option = keys[i]; - if (!allowUnknown && !hasOwnProperty.call(schema, option)) { - throw Error('Unknown "' + option + '" option'); - } - value = options[option]; - if (value !== undefined$1) { - reducer = reducers[option]; - computedOptions[option] = reducer ? reducer(value, reject) : value; - } - } - return computedOptions; - } - - function constructorReducer(value, reject) { - if (typeof value !== 'function' || !value.hasOwnProperty('prototype')) { - reject('value must be a constructor'); - } - return value; - } - - function makeTypeReducer(types) { - var message= 'value must be type of ' + types.join('|'); - var len= types.length; - var firstType= types[0]; - var secondType= types[1]; - - if (len === 1) { - return function (v, reject) { - if (typeof v === firstType) { - return v; - } - reject(message); - } - } - - if (len === 2) { - return function (v, reject) { - var kind= typeof v; - if (kind === firstType || kind === secondType) { return v; } - reject(message); - } - } - - return function (v, reject) { - var kind = typeof v; - var i = len; - while (i-- > 0) { - if (kind === types[i]) { return v; } - } - reject(message); - } - } - - var functionReducer= makeTypeReducer(['function']); - - var objectFunctionReducer= makeTypeReducer(['object', 'function']); - - function makeCancelablePromise(Promise, executor, options) { - var isCancelable; - var callbacks; - var timer= 0; - var subscriptionClosed; - - var promise = new Promise(function (resolve, reject, onCancel) { - options= resolveOptions(options, { - timeout: 0, - overload: false - }, { - timeout: function(value, reject){ - value*= 1; - if (typeof value !== 'number' || value < 0 || !Number.isFinite(value)) { - reject('timeout must be a positive number'); - } - return value; - } - }); - - isCancelable = !options.overload && typeof Promise.prototype.cancel === 'function' && typeof onCancel === 'function'; - - function cleanup() { - if (callbacks) { - callbacks = null; - } - if (timer) { - clearTimeout(timer); - timer = 0; - } - } - - var _resolve= function(value){ - cleanup(); - resolve(value); - }; - - var _reject= function(err){ - cleanup(); - reject(err); - }; - - if (isCancelable) { - executor(_resolve, _reject, onCancel); - } else { - callbacks = [function(reason){ - _reject(reason || Error('canceled')); - }]; - executor(_resolve, _reject, function (cb) { - if (subscriptionClosed) { - throw Error('Unable to subscribe on cancel event asynchronously') - } - if (typeof cb !== 'function') { - throw TypeError('onCancel callback must be a function'); - } - callbacks.push(cb); - }); - subscriptionClosed= true; - } - - if (options.timeout > 0) { - timer= setTimeout(function(){ - var reason= Error('timeout'); - reason.code = 'ETIMEDOUT'; - timer= 0; - promise.cancel(reason); - reject(reason); - }, options.timeout); - } - }); - - if (!isCancelable) { - promise.cancel = function (reason) { - if (!callbacks) { - return; - } - var length = callbacks.length; - for (var i = 1; i < length; i++) { - callbacks[i](reason); - } - // internal callback to reject the promise - callbacks[0](reason); - callbacks = null; - }; - } - - return promise; - } - - function findTargetIndex(observer) { - var observers = this._observers; - if(!observers){ - return -1; - } - var len = observers.length; - for (var i = 0; i < len; i++) { - if (observers[i]._target === observer) { return i; } - } - return -1; - } - - // Attention, function return type now is array, always ! - // It has zero elements if no any matches found and one or more - // elements (leafs) if there are matches - // - function searchListenerTree(handlers, type, tree, i, typeLength) { - if (!tree) { - return null; - } - - if (i === 0) { - var kind = typeof type; - if (kind === 'string') { - var ns, n, l = 0, j = 0, delimiter = this.delimiter, dl = delimiter.length; - if ((n = type.indexOf(delimiter)) !== -1) { - ns = new Array(5); - do { - ns[l++] = type.slice(j, n); - j = n + dl; - } while ((n = type.indexOf(delimiter, j)) !== -1); - - ns[l++] = type.slice(j); - type = ns; - typeLength = l; - } else { - type = [type]; - typeLength = 1; - } - } else if (kind === 'object') { - typeLength = type.length; - } else { - type = [type]; - typeLength = 1; - } - } - - var listeners= null, branch, xTree, xxTree, isolatedBranch, endReached, currentType = type[i], - nextType = type[i + 1], branches, _listeners; - - if (i === typeLength) { - // - // If at the end of the event(s) list and the tree has listeners - // invoke those listeners. - // - - if(tree._listeners) { - if (typeof tree._listeners === 'function') { - handlers && handlers.push(tree._listeners); - listeners = [tree]; - } else { - handlers && handlers.push.apply(handlers, tree._listeners); - listeners = [tree]; - } - } - } else { - - if (currentType === '*') { - // - // If the event emitted is '*' at this part - // or there is a concrete match at this patch - // - branches = ownKeys(tree); - n = branches.length; - while (n-- > 0) { - branch = branches[n]; - if (branch !== '_listeners') { - _listeners = searchListenerTree(handlers, type, tree[branch], i + 1, typeLength); - if (_listeners) { - if (listeners) { - listeners.push.apply(listeners, _listeners); - } else { - listeners = _listeners; - } - } - } - } - return listeners; - } else if (currentType === '**') { - endReached = (i + 1 === typeLength || (i + 2 === typeLength && nextType === '*')); - if (endReached && tree._listeners) { - // The next element has a _listeners, add it to the handlers. - listeners = searchListenerTree(handlers, type, tree, typeLength, typeLength); - } - - branches = ownKeys(tree); - n = branches.length; - while (n-- > 0) { - branch = branches[n]; - if (branch !== '_listeners') { - if (branch === '*' || branch === '**') { - if (tree[branch]._listeners && !endReached) { - _listeners = searchListenerTree(handlers, type, tree[branch], typeLength, typeLength); - if (_listeners) { - if (listeners) { - listeners.push.apply(listeners, _listeners); - } else { - listeners = _listeners; - } - } - } - _listeners = searchListenerTree(handlers, type, tree[branch], i, typeLength); - } else if (branch === nextType) { - _listeners = searchListenerTree(handlers, type, tree[branch], i + 2, typeLength); - } else { - // No match on this one, shift into the tree but not in the type array. - _listeners = searchListenerTree(handlers, type, tree[branch], i, typeLength); - } - if (_listeners) { - if (listeners) { - listeners.push.apply(listeners, _listeners); - } else { - listeners = _listeners; - } - } - } - } - return listeners; - } else if (tree[currentType]) { - listeners = searchListenerTree(handlers, type, tree[currentType], i + 1, typeLength); - } - } - - xTree = tree['*']; - if (xTree) { - // - // If the listener tree will allow any match for this part, - // then recursively explore all branches of the tree - // - searchListenerTree(handlers, type, xTree, i + 1, typeLength); - } - - xxTree = tree['**']; - if (xxTree) { - if (i < typeLength) { - if (xxTree._listeners) { - // If we have a listener on a '**', it will catch all, so add its handler. - searchListenerTree(handlers, type, xxTree, typeLength, typeLength); - } - - // Build arrays of matching next branches and others. - branches= ownKeys(xxTree); - n= branches.length; - while(n-->0){ - branch= branches[n]; - if (branch !== '_listeners') { - if (branch === nextType) { - // We know the next element will match, so jump twice. - searchListenerTree(handlers, type, xxTree[branch], i + 2, typeLength); - } else if (branch === currentType) { - // Current node matches, move into the tree. - searchListenerTree(handlers, type, xxTree[branch], i + 1, typeLength); - } else { - isolatedBranch = {}; - isolatedBranch[branch] = xxTree[branch]; - searchListenerTree(handlers, type, {'**': isolatedBranch}, i + 1, typeLength); - } - } - } - } else if (xxTree._listeners) { - // We have reached the end and still on a '**' - searchListenerTree(handlers, type, xxTree, typeLength, typeLength); - } else if (xxTree['*'] && xxTree['*']._listeners) { - searchListenerTree(handlers, type, xxTree['*'], typeLength, typeLength); - } - } - - return listeners; - } - - function growListenerTree(type, listener, prepend) { - var len = 0, j = 0, i, delimiter = this.delimiter, dl= delimiter.length, ns; - - if(typeof type==='string') { - if ((i = type.indexOf(delimiter)) !== -1) { - ns = new Array(5); - do { - ns[len++] = type.slice(j, i); - j = i + dl; - } while ((i = type.indexOf(delimiter, j)) !== -1); - - ns[len++] = type.slice(j); - }else { - ns= [type]; - len= 1; - } - }else { - ns= type; - len= type.length; - } - - // - // Looks for two consecutive '**', if so, don't add the event at all. - // - if (len > 1) { - for (i = 0; i + 1 < len; i++) { - if (ns[i] === '**' && ns[i + 1] === '**') { - return; - } - } - } - - - - var tree = this.listenerTree, name; - - for (i = 0; i < len; i++) { - name = ns[i]; - - tree = tree[name] || (tree[name] = {}); - - if (i === len - 1) { - if (!tree._listeners) { - tree._listeners = listener; - } else { - if (typeof tree._listeners === 'function') { - tree._listeners = [tree._listeners]; - } - - if (prepend) { - tree._listeners.unshift(listener); - } else { - tree._listeners.push(listener); - } - - if ( - !tree._listeners.warned && - this._maxListeners > 0 && - tree._listeners.length > this._maxListeners - ) { - tree._listeners.warned = true; - logPossibleMemoryLeak.call(this, tree._listeners.length, name); - } - } - return true; - } - } - - return true; - } - - function collectTreeEvents(tree, events, root, asArray){ - var branches= ownKeys(tree); - var i= branches.length; - var branch, branchName, path; - var hasListeners= tree['_listeners']; - var isArrayPath; - - while(i-->0){ - branchName= branches[i]; - - branch= tree[branchName]; - - if(branchName==='_listeners'){ - path= root; - }else { - path = root ? root.concat(branchName) : [branchName]; - } - - isArrayPath= asArray || typeof branchName==='symbol'; - - hasListeners && events.push(isArrayPath? path : path.join(this.delimiter)); - - if(typeof branch==='object'){ - collectTreeEvents.call(this, branch, events, path, isArrayPath); - } - } - - return events; - } - - function recursivelyGarbageCollect(root) { - var keys = ownKeys(root); - var i= keys.length; - var obj, key, flag; - while(i-->0){ - key = keys[i]; - obj = root[key]; - - if(obj){ - flag= true; - if(key !== '_listeners' && !recursivelyGarbageCollect(obj)){ - delete root[key]; - } - } - } - - return flag; - } - - function Listener(emitter, event, listener){ - this.emitter= emitter; - this.event= event; - this.listener= listener; - } - - Listener.prototype.off= function(){ - this.emitter.off(this.event, this.listener); - return this; - }; - - function setupListener(event, listener, options){ - if (options === true) { - promisify = true; - } else if (options === false) { - async = true; - } else { - if (!options || typeof options !== 'object') { - throw TypeError('options should be an object or true'); - } - var async = options.async; - var promisify = options.promisify; - var nextTick = options.nextTick; - var objectify = options.objectify; - } - - if (async || nextTick || promisify) { - var _listener = listener; - var _origin = listener._origin || listener; - - if (nextTick && !nextTickSupported) { - throw Error('process.nextTick is not supported'); - } - - if (promisify === undefined$1) { - promisify = listener.constructor.name === 'AsyncFunction'; - } - - listener = function () { - var args = arguments; - var context = this; - var event = this.event; - - return promisify ? (nextTick ? Promise.resolve() : new Promise(function (resolve) { - _setImmediate(resolve); - }).then(function () { - context.event = event; - return _listener.apply(context, args) - })) : (nextTick ? process.nextTick : _setImmediate)(function () { - context.event = event; - _listener.apply(context, args); - }); - }; - - listener._async = true; - listener._origin = _origin; - } - - return [listener, objectify? new Listener(this, event, listener): this]; - } - - function EventEmitter(conf) { - this._events = {}; - this._newListener = false; - this._removeListener = false; - this.verboseMemoryLeak = false; - configure.call(this, conf); - } - - EventEmitter.EventEmitter2 = EventEmitter; // backwards compatibility for exporting EventEmitter property - - EventEmitter.prototype.listenTo= function(target, events, options){ - if(typeof target!=='object'){ - throw TypeError('target musts be an object'); - } - - var emitter= this; - - options = resolveOptions(options, { - on: undefined$1, - off: undefined$1, - reducers: undefined$1 - }, { - on: functionReducer, - off: functionReducer, - reducers: objectFunctionReducer - }); - - function listen(events){ - if(typeof events!=='object'){ - throw TypeError('events must be an object'); - } - - var reducers= options.reducers; - var index= findTargetIndex.call(emitter, target); - var observer; - - if(index===-1){ - observer= new TargetObserver(emitter, target, options); - }else { - observer= emitter._observers[index]; - } - - var keys= ownKeys(events); - var len= keys.length; - var event; - var isSingleReducer= typeof reducers==='function'; - - for(var i=0; i 0) { - observer = observers[i]; - if (!target || observer._target === target) { - observer.unsubscribe(event); - matched= true; - } - } - - return matched; - }; - - // By default EventEmitters will print a warning if more than - // 10 listeners are added to it. This is a useful default which - // helps finding memory leaks. - // - // Obviously not all Emitters should be limited to 10. This function allows - // that to be increased. Set to zero for unlimited. - - EventEmitter.prototype.delimiter = '.'; - - EventEmitter.prototype.setMaxListeners = function(n) { - if (n !== undefined$1) { - this._maxListeners = n; - if (!this._conf) { this._conf = {}; } - this._conf.maxListeners = n; - } - }; - - EventEmitter.prototype.getMaxListeners = function() { - return this._maxListeners; - }; - - EventEmitter.prototype.event = ''; - - EventEmitter.prototype.once = function(event, fn, options) { - return this._once(event, fn, false, options); - }; - - EventEmitter.prototype.prependOnceListener = function(event, fn, options) { - return this._once(event, fn, true, options); - }; - - EventEmitter.prototype._once = function(event, fn, prepend, options) { - return this._many(event, 1, fn, prepend, options); - }; - - EventEmitter.prototype.many = function(event, ttl, fn, options) { - return this._many(event, ttl, fn, false, options); - }; - - EventEmitter.prototype.prependMany = function(event, ttl, fn, options) { - return this._many(event, ttl, fn, true, options); - }; - - EventEmitter.prototype._many = function(event, ttl, fn, prepend, options) { - var self = this; - - if (typeof fn !== 'function') { - throw new Error('many only accepts instances of Function'); - } - - function listener() { - if (--ttl === 0) { - self.off(event, listener); - } - return fn.apply(this, arguments); - } - - listener._origin = fn; - - return this._on(event, listener, prepend, options); - }; - - EventEmitter.prototype.emit = function() { - var arguments$1 = arguments; - - if (!this._events && !this._all) { - return false; - } - - this._events || init.call(this); - - var type = arguments[0], ns, wildcard= this.wildcard; - var args,l,i,j, containsSymbol; - - if (type === 'newListener' && !this._newListener) { - if (!this._events.newListener) { - return false; - } - } - - if (wildcard) { - ns= type; - if(type!=='newListener' && type!=='removeListener'){ - if (typeof type === 'object') { - l = type.length; - if (symbolsSupported) { - for (i = 0; i < l; i++) { - if (typeof type[i] === 'symbol') { - containsSymbol = true; - break; - } - } - } - if (!containsSymbol) { - type = type.join(this.delimiter); - } - } - } - } - - var al = arguments.length; - var handler; - - if (this._all && this._all.length) { - handler = this._all.slice(); - - for (i = 0, l = handler.length; i < l; i++) { - this.event = type; - switch (al) { - case 1: - handler[i].call(this, type); - break; - case 2: - handler[i].call(this, type, arguments$1[1]); - break; - case 3: - handler[i].call(this, type, arguments$1[1], arguments$1[2]); - break; - default: - handler[i].apply(this, arguments$1); - } - } - } - - if (wildcard) { - handler = []; - searchListenerTree.call(this, handler, ns, this.listenerTree, 0, l); - } else { - handler = this._events[type]; - if (typeof handler === 'function') { - this.event = type; - switch (al) { - case 1: - handler.call(this); - break; - case 2: - handler.call(this, arguments[1]); - break; - case 3: - handler.call(this, arguments[1], arguments[2]); - break; - default: - args = new Array(al - 1); - for (j = 1; j < al; j++) { args[j - 1] = arguments$1[j]; } - handler.apply(this, args); - } - return true; - } else if (handler) { - // need to make copy of handlers because list can change in the middle - // of emit call - handler = handler.slice(); - } - } - - if (handler && handler.length) { - if (al > 3) { - args = new Array(al - 1); - for (j = 1; j < al; j++) { args[j - 1] = arguments$1[j]; } - } - for (i = 0, l = handler.length; i < l; i++) { - this.event = type; - switch (al) { - case 1: - handler[i].call(this); - break; - case 2: - handler[i].call(this, arguments$1[1]); - break; - case 3: - handler[i].call(this, arguments$1[1], arguments$1[2]); - break; - default: - handler[i].apply(this, args); - } - } - return true; - } else if (!this.ignoreErrors && !this._all && type === 'error') { - if (arguments[1] instanceof Error) { - throw arguments[1]; // Unhandled 'error' event - } else { - throw new Error("Uncaught, unspecified 'error' event."); - } - } - - return !!this._all; - }; - - EventEmitter.prototype.emitAsync = function() { - var arguments$1 = arguments; - - if (!this._events && !this._all) { - return false; - } - - this._events || init.call(this); - - var type = arguments[0], wildcard= this.wildcard, ns, containsSymbol; - var args,l,i,j; - - if (type === 'newListener' && !this._newListener) { - if (!this._events.newListener) { return Promise.resolve([false]); } - } - - if (wildcard) { - ns= type; - if(type!=='newListener' && type!=='removeListener'){ - if (typeof type === 'object') { - l = type.length; - if (symbolsSupported) { - for (i = 0; i < l; i++) { - if (typeof type[i] === 'symbol') { - containsSymbol = true; - break; - } - } - } - if (!containsSymbol) { - type = type.join(this.delimiter); - } - } - } - } - - var promises= []; - - var al = arguments.length; - var handler; - - if (this._all) { - for (i = 0, l = this._all.length; i < l; i++) { - this.event = type; - switch (al) { - case 1: - promises.push(this._all[i].call(this, type)); - break; - case 2: - promises.push(this._all[i].call(this, type, arguments$1[1])); - break; - case 3: - promises.push(this._all[i].call(this, type, arguments$1[1], arguments$1[2])); - break; - default: - promises.push(this._all[i].apply(this, arguments$1)); - } - } - } - - if (wildcard) { - handler = []; - searchListenerTree.call(this, handler, ns, this.listenerTree, 0); - } else { - handler = this._events[type]; - } - - if (typeof handler === 'function') { - this.event = type; - switch (al) { - case 1: - promises.push(handler.call(this)); - break; - case 2: - promises.push(handler.call(this, arguments[1])); - break; - case 3: - promises.push(handler.call(this, arguments[1], arguments[2])); - break; - default: - args = new Array(al - 1); - for (j = 1; j < al; j++) { args[j - 1] = arguments$1[j]; } - promises.push(handler.apply(this, args)); - } - } else if (handler && handler.length) { - handler = handler.slice(); - if (al > 3) { - args = new Array(al - 1); - for (j = 1; j < al; j++) { args[j - 1] = arguments$1[j]; } - } - for (i = 0, l = handler.length; i < l; i++) { - this.event = type; - switch (al) { - case 1: - promises.push(handler[i].call(this)); - break; - case 2: - promises.push(handler[i].call(this, arguments$1[1])); - break; - case 3: - promises.push(handler[i].call(this, arguments$1[1], arguments$1[2])); - break; - default: - promises.push(handler[i].apply(this, args)); - } - } - } else if (!this.ignoreErrors && !this._all && type === 'error') { - if (arguments[1] instanceof Error) { - return Promise.reject(arguments[1]); // Unhandled 'error' event - } else { - return Promise.reject("Uncaught, unspecified 'error' event."); - } - } - - return Promise.all(promises); - }; - - EventEmitter.prototype.on = function(type, listener, options) { - return this._on(type, listener, false, options); - }; - - EventEmitter.prototype.prependListener = function(type, listener, options) { - return this._on(type, listener, true, options); - }; - - EventEmitter.prototype.onAny = function(fn) { - return this._onAny(fn, false); - }; - - EventEmitter.prototype.prependAny = function(fn) { - return this._onAny(fn, true); - }; - - EventEmitter.prototype.addListener = EventEmitter.prototype.on; - - EventEmitter.prototype._onAny = function(fn, prepend){ - if (typeof fn !== 'function') { - throw new Error('onAny only accepts instances of Function'); - } - - if (!this._all) { - this._all = []; - } - - // Add the function to the event listener collection. - if(prepend){ - this._all.unshift(fn); - }else { - this._all.push(fn); - } - - return this; - }; - - EventEmitter.prototype._on = function(type, listener, prepend, options) { - if (typeof type === 'function') { - this._onAny(type, listener); - return this; - } - - if (typeof listener !== 'function') { - throw new Error('on only accepts instances of Function'); - } - this._events || init.call(this); - - var returnValue= this, temp; - - if (options !== undefined$1) { - temp = setupListener.call(this, type, listener, options); - listener = temp[0]; - returnValue = temp[1]; - } - - // To avoid recursion in the case that type == "newListeners"! Before - // adding it to the listeners, first emit "newListeners". - if (this._newListener) { - this.emit('newListener', type, listener); - } - - if (this.wildcard) { - growListenerTree.call(this, type, listener, prepend); - return returnValue; - } - - if (!this._events[type]) { - // Optimize the case of one listener. Don't need the extra array object. - this._events[type] = listener; - } else { - if (typeof this._events[type] === 'function') { - // Change to array. - this._events[type] = [this._events[type]]; - } - - // If we've already got an array, just add - if(prepend){ - this._events[type].unshift(listener); - }else { - this._events[type].push(listener); - } - - // Check for listener leak - if ( - !this._events[type].warned && - this._maxListeners > 0 && - this._events[type].length > this._maxListeners - ) { - this._events[type].warned = true; - logPossibleMemoryLeak.call(this, this._events[type].length, type); - } - } - - return returnValue; - }; - - EventEmitter.prototype.off = function(type, listener) { - if (typeof listener !== 'function') { - throw new Error('removeListener only takes instances of Function'); - } - - var handlers,leafs=[]; - - if(this.wildcard) { - var ns = typeof type === 'string' ? type.split(this.delimiter) : type.slice(); - leafs = searchListenerTree.call(this, null, ns, this.listenerTree, 0); - if(!leafs) { return this; } - } else { - // does not use listeners(), so no side effect of creating _events[type] - if (!this._events[type]) { return this; } - handlers = this._events[type]; - leafs.push({_listeners:handlers}); - } - - for (var iLeaf=0; iLeaf 0) { - fns = this._all; - for(i = 0, l = fns.length; i < l; i++) { - if(fn === fns[i]) { - fns.splice(i, 1); - if (this._removeListener) - { this.emit("removeListenerAny", fn); } - return this; - } - } - } else { - fns = this._all; - if (this._removeListener) { - for(i = 0, l = fns.length; i < l; i++) - { this.emit("removeListenerAny", fns[i]); } - } - this._all = []; - } - return this; - }; - - EventEmitter.prototype.removeListener = EventEmitter.prototype.off; - - EventEmitter.prototype.removeAllListeners = function (type) { - if (type === undefined$1) { - !this._events || init.call(this); - return this; - } - - if (this.wildcard) { - var leafs = searchListenerTree.call(this, null, type, this.listenerTree, 0), leaf, i; - if (!leafs) { return this; } - for (i = 0; i < leafs.length; i++) { - leaf = leafs[i]; - leaf._listeners = null; - } - this.listenerTree && recursivelyGarbageCollect(this.listenerTree); - } else if (this._events) { - this._events[type] = null; - } - return this; - }; - - EventEmitter.prototype.listeners = function (type) { - var _events = this._events; - var keys, listeners, allListeners; - var i; - var listenerTree; - - if (type === undefined$1) { - if (this.wildcard) { - throw Error('event name required for wildcard emitter'); - } - - if (!_events) { - return []; - } - - keys = ownKeys(_events); - i = keys.length; - allListeners = []; - while (i-- > 0) { - listeners = _events[keys[i]]; - if (typeof listeners === 'function') { - allListeners.push(listeners); - } else { - allListeners.push.apply(allListeners, listeners); - } - } - return allListeners; - } else { - if (this.wildcard) { - listenerTree= this.listenerTree; - if(!listenerTree) { return []; } - var handlers = []; - var ns = typeof type === 'string' ? type.split(this.delimiter) : type.slice(); - searchListenerTree.call(this, handlers, ns, listenerTree, 0); - return handlers; - } - - if (!_events) { - return []; - } - - listeners = _events[type]; - - if (!listeners) { - return []; - } - return typeof listeners === 'function' ? [listeners] : listeners; - } - }; - - EventEmitter.prototype.eventNames = function(nsAsArray){ - var _events= this._events; - return this.wildcard? collectTreeEvents.call(this, this.listenerTree, [], null, nsAsArray) : (_events? ownKeys(_events) : []); - }; - - EventEmitter.prototype.listenerCount = function(type) { - return this.listeners(type).length; - }; - - EventEmitter.prototype.hasListeners = function (type) { - if (this.wildcard) { - var handlers = []; - var ns = typeof type === 'string' ? type.split(this.delimiter) : type.slice(); - searchListenerTree.call(this, handlers, ns, this.listenerTree, 0); - return handlers.length > 0; - } - - var _events = this._events; - var _all = this._all; - - return !!(_all && _all.length || _events && (type === undefined$1 ? ownKeys(_events).length : _events[type])); - }; - - EventEmitter.prototype.listenersAny = function() { - - if(this._all) { - return this._all; - } - else { - return []; - } - - }; - - EventEmitter.prototype.waitFor = function (event, options) { - var self = this; - var type = typeof options; - if (type === 'number') { - options = {timeout: options}; - } else if (type === 'function') { - options = {filter: options}; - } - - options= resolveOptions(options, { - timeout: 0, - filter: undefined$1, - handleError: false, - Promise: Promise, - overload: false - }, { - filter: functionReducer, - Promise: constructorReducer - }); - - return makeCancelablePromise(options.Promise, function (resolve, reject, onCancel) { - function listener() { - var filter= options.filter; - if (filter && !filter.apply(self, arguments)) { - return; - } - self.off(event, listener); - if (options.handleError) { - var err = arguments[0]; - err ? reject(err) : resolve(toArray.apply(null, arguments).slice(1)); - } else { - resolve(toArray.apply(null, arguments)); - } - } - - onCancel(function(){ - self.off(event, listener); - }); - - self._on(event, listener, false); - }, { - timeout: options.timeout, - overload: options.overload - }) - }; - - function once(emitter, name, options) { - options= resolveOptions(options, { - Promise: Promise, - timeout: 0, - overload: false - }, { - Promise: constructorReducer - }); - - var _Promise= options.Promise; - - return makeCancelablePromise(_Promise, function(resolve, reject, onCancel){ - var handler; - if (typeof emitter.addEventListener === 'function') { - handler= function () { - resolve(toArray.apply(null, arguments)); - }; - - onCancel(function(){ - emitter.removeEventListener(name, handler); - }); - - emitter.addEventListener( - name, - handler, - {once: true} - ); - return; - } - - var eventListener = function(){ - errorListener && emitter.removeListener('error', errorListener); - resolve(toArray.apply(null, arguments)); - }; - - var errorListener; - - if (name !== 'error') { - errorListener = function (err){ - emitter.removeListener(name, eventListener); - reject(err); - }; - - emitter.once('error', errorListener); - } - - onCancel(function(){ - errorListener && emitter.removeListener('error', errorListener); - emitter.removeListener(name, eventListener); - }); - - emitter.once(name, eventListener); - }, { - timeout: options.timeout, - overload: options.overload - }); - } - - var prototype= EventEmitter.prototype; - - Object.defineProperties(EventEmitter, { - defaultMaxListeners: { - get: function () { - return prototype._maxListeners; - }, - set: function (n) { - if (typeof n !== 'number' || n < 0 || Number.isNaN(n)) { - throw TypeError('n must be a non-negative number') - } - prototype._maxListeners = n; - }, - enumerable: true - }, - once: { - value: once, - writable: true, - configurable: true - } - }); - - Object.defineProperties(prototype, { - _maxListeners: { - value: defaultMaxListeners, - writable: true, - configurable: true - }, - _observers: {value: null, writable: true, configurable: true} - }); - - if (typeof undefined$1 === 'function' && undefined$1.amd) { - // AMD. Register as an anonymous module. - undefined$1(function() { - return EventEmitter; - }); - } else { - // CommonJS - module.exports = EventEmitter; - } - }(); -} (eventemitter2, eventemitter2.exports)); - -var eventemitter2Exports = eventemitter2.exports; + var hasOwnProperty= Object.hasOwnProperty; + var isArray = Array.isArray ? Array.isArray : function _isArray(obj) { + return Object.prototype.toString.call(obj) === "[object Array]"; + }; + var defaultMaxListeners = 10; + var nextTickSupported= typeof process=='object' && typeof process.nextTick=='function'; + var symbolsSupported= typeof Symbol==='function'; + var reflectSupported= typeof Reflect === 'object'; + var setImmediateSupported= typeof setImmediate === 'function'; + var _setImmediate= setImmediateSupported ? setImmediate : setTimeout; + var ownKeys= symbolsSupported? (reflectSupported && typeof Reflect.ownKeys==='function'? Reflect.ownKeys : function(obj){ + var arr= Object.getOwnPropertyNames(obj); + arr.push.apply(arr, Object.getOwnPropertySymbols(obj)); + return arr; + }) : Object.keys; + + function init() { + this._events = {}; + if (this._conf) { + configure.call(this, this._conf); + } + } + + function configure(conf) { + if (conf) { + this._conf = conf; + + conf.delimiter && (this.delimiter = conf.delimiter); + + if(conf.maxListeners!==undefined$1){ + this._maxListeners= conf.maxListeners; + } + + conf.wildcard && (this.wildcard = conf.wildcard); + conf.newListener && (this._newListener = conf.newListener); + conf.removeListener && (this._removeListener = conf.removeListener); + conf.verboseMemoryLeak && (this.verboseMemoryLeak = conf.verboseMemoryLeak); + conf.ignoreErrors && (this.ignoreErrors = conf.ignoreErrors); + + if (this.wildcard) { + this.listenerTree = {}; + } + } + } + + function logPossibleMemoryLeak(count, eventName) { + var errorMsg = '(node) warning: possible EventEmitter memory ' + + 'leak detected. ' + count + ' listeners added. ' + + 'Use emitter.setMaxListeners() to increase limit.'; + + if(this.verboseMemoryLeak){ + errorMsg += ' Event name: ' + eventName + '.'; + } + + if(typeof process !== 'undefined' && process.emitWarning){ + var e = new Error(errorMsg); + e.name = 'MaxListenersExceededWarning'; + e.emitter = this; + e.count = count; + process.emitWarning(e); + } else { + console.error(errorMsg); + + if (console.trace){ + console.trace(); + } + } + } + + var toArray = function (a, b, c) { + var arguments$1 = arguments; + + var n = arguments.length; + switch (n) { + case 0: + return []; + case 1: + return [a]; + case 2: + return [a, b]; + case 3: + return [a, b, c]; + default: + var arr = new Array(n); + while (n--) { + arr[n] = arguments$1[n]; + } + return arr; + } + }; + + function toObject(keys, values) { + var obj = {}; + var key; + var len = keys.length; + var valuesCount = values ? value.length : 0; + for (var i = 0; i < len; i++) { + key = keys[i]; + obj[key] = i < valuesCount ? values[i] : undefined$1; + } + return obj; + } + + function TargetObserver(emitter, target, options) { + this._emitter = emitter; + this._target = target; + this._listeners = {}; + this._listenersCount = 0; + + var on, off; + + if (options.on || options.off) { + on = options.on; + off = options.off; + } + + if (target.addEventListener) { + on = target.addEventListener; + off = target.removeEventListener; + } else if (target.addListener) { + on = target.addListener; + off = target.removeListener; + } else if (target.on) { + on = target.on; + off = target.off; + } + + if (!on && !off) { + throw Error('target does not implement any known event API'); + } + + if (typeof on !== 'function') { + throw TypeError('on method must be a function'); + } + + if (typeof off !== 'function') { + throw TypeError('off method must be a function'); + } + + this._on = on; + this._off = off; + + var _observers= emitter._observers; + if(_observers){ + _observers.push(this); + }else { + emitter._observers= [this]; + } + } + + Object.assign(TargetObserver.prototype, { + subscribe: function(event, localEvent, reducer){ + var observer= this; + var target= this._target; + var emitter= this._emitter; + var listeners= this._listeners; + var handler= function(){ + var args= toArray.apply(null, arguments); + var eventObj= { + data: args, + name: localEvent, + original: event + }; + if(reducer){ + var result= reducer.call(target, eventObj); + if(result!==false){ + emitter.emit.apply(emitter, [eventObj.name].concat(args)); + } + return; + } + emitter.emit.apply(emitter, [localEvent].concat(args)); + }; + + + if(listeners[event]){ + throw Error('Event \'' + event + '\' is already listening'); + } + + this._listenersCount++; + + if(emitter._newListener && emitter._removeListener && !observer._onNewListener){ + + this._onNewListener = function (_event) { + if (_event === localEvent && listeners[event] === null) { + listeners[event] = handler; + observer._on.call(target, event, handler); + } + }; + + emitter.on('newListener', this._onNewListener); + + this._onRemoveListener= function(_event){ + if(_event === localEvent && !emitter.hasListeners(_event) && listeners[event]){ + listeners[event]= null; + observer._off.call(target, event, handler); + } + }; + + listeners[event]= null; + + emitter.on('removeListener', this._onRemoveListener); + }else { + listeners[event]= handler; + observer._on.call(target, event, handler); + } + }, + + unsubscribe: function(event){ + var observer= this; + var listeners= this._listeners; + var emitter= this._emitter; + var handler; + var events; + var off= this._off; + var target= this._target; + var i; + + if(event && typeof event!=='string'){ + throw TypeError('event must be a string'); + } + + function clearRefs(){ + if(observer._onNewListener){ + emitter.off('newListener', observer._onNewListener); + emitter.off('removeListener', observer._onRemoveListener); + observer._onNewListener= null; + observer._onRemoveListener= null; + } + var index= findTargetIndex.call(emitter, observer); + emitter._observers.splice(index, 1); + } + + if(event){ + handler= listeners[event]; + if(!handler) { return; } + off.call(target, event, handler); + delete listeners[event]; + if(!--this._listenersCount){ + clearRefs(); + } + }else { + events= ownKeys(listeners); + i= events.length; + while(i-->0){ + event= events[i]; + off.call(target, event, listeners[event]); + } + this._listeners= {}; + this._listenersCount= 0; + clearRefs(); + } + } + }); + + function resolveOptions(options, schema, reducers, allowUnknown) { + var computedOptions = Object.assign({}, schema); + + if (!options) { return computedOptions; } + + if (typeof options !== 'object') { + throw TypeError('options must be an object') + } + + var keys = Object.keys(options); + var length = keys.length; + var option, value; + var reducer; + + function reject(reason) { + throw Error('Invalid "' + option + '" option value' + (reason ? '. Reason: ' + reason : '')) + } + + for (var i = 0; i < length; i++) { + option = keys[i]; + if (!allowUnknown && !hasOwnProperty.call(schema, option)) { + throw Error('Unknown "' + option + '" option'); + } + value = options[option]; + if (value !== undefined$1) { + reducer = reducers[option]; + computedOptions[option] = reducer ? reducer(value, reject) : value; + } + } + return computedOptions; + } + + function constructorReducer(value, reject) { + if (typeof value !== 'function' || !value.hasOwnProperty('prototype')) { + reject('value must be a constructor'); + } + return value; + } + + function makeTypeReducer(types) { + var message= 'value must be type of ' + types.join('|'); + var len= types.length; + var firstType= types[0]; + var secondType= types[1]; + + if (len === 1) { + return function (v, reject) { + if (typeof v === firstType) { + return v; + } + reject(message); + } + } + + if (len === 2) { + return function (v, reject) { + var kind= typeof v; + if (kind === firstType || kind === secondType) { return v; } + reject(message); + } + } + + return function (v, reject) { + var kind = typeof v; + var i = len; + while (i-- > 0) { + if (kind === types[i]) { return v; } + } + reject(message); + } + } + + var functionReducer= makeTypeReducer(['function']); + + var objectFunctionReducer= makeTypeReducer(['object', 'function']); + + function makeCancelablePromise(Promise, executor, options) { + var isCancelable; + var callbacks; + var timer= 0; + var subscriptionClosed; + + var promise = new Promise(function (resolve, reject, onCancel) { + options= resolveOptions(options, { + timeout: 0, + overload: false + }, { + timeout: function(value, reject){ + value*= 1; + if (typeof value !== 'number' || value < 0 || !Number.isFinite(value)) { + reject('timeout must be a positive number'); + } + return value; + } + }); + + isCancelable = !options.overload && typeof Promise.prototype.cancel === 'function' && typeof onCancel === 'function'; + + function cleanup() { + if (callbacks) { + callbacks = null; + } + if (timer) { + clearTimeout(timer); + timer = 0; + } + } + + var _resolve= function(value){ + cleanup(); + resolve(value); + }; + + var _reject= function(err){ + cleanup(); + reject(err); + }; + + if (isCancelable) { + executor(_resolve, _reject, onCancel); + } else { + callbacks = [function(reason){ + _reject(reason || Error('canceled')); + }]; + executor(_resolve, _reject, function (cb) { + if (subscriptionClosed) { + throw Error('Unable to subscribe on cancel event asynchronously') + } + if (typeof cb !== 'function') { + throw TypeError('onCancel callback must be a function'); + } + callbacks.push(cb); + }); + subscriptionClosed= true; + } + + if (options.timeout > 0) { + timer= setTimeout(function(){ + var reason= Error('timeout'); + reason.code = 'ETIMEDOUT'; + timer= 0; + promise.cancel(reason); + reject(reason); + }, options.timeout); + } + }); + + if (!isCancelable) { + promise.cancel = function (reason) { + if (!callbacks) { + return; + } + var length = callbacks.length; + for (var i = 1; i < length; i++) { + callbacks[i](reason); + } + // internal callback to reject the promise + callbacks[0](reason); + callbacks = null; + }; + } + + return promise; + } + + function findTargetIndex(observer) { + var observers = this._observers; + if(!observers){ + return -1; + } + var len = observers.length; + for (var i = 0; i < len; i++) { + if (observers[i]._target === observer) { return i; } + } + return -1; + } + + // Attention, function return type now is array, always ! + // It has zero elements if no any matches found and one or more + // elements (leafs) if there are matches + // + function searchListenerTree(handlers, type, tree, i, typeLength) { + if (!tree) { + return null; + } + + if (i === 0) { + var kind = typeof type; + if (kind === 'string') { + var ns, n, l = 0, j = 0, delimiter = this.delimiter, dl = delimiter.length; + if ((n = type.indexOf(delimiter)) !== -1) { + ns = new Array(5); + do { + ns[l++] = type.slice(j, n); + j = n + dl; + } while ((n = type.indexOf(delimiter, j)) !== -1); + + ns[l++] = type.slice(j); + type = ns; + typeLength = l; + } else { + type = [type]; + typeLength = 1; + } + } else if (kind === 'object') { + typeLength = type.length; + } else { + type = [type]; + typeLength = 1; + } + } + + var listeners= null, branch, xTree, xxTree, isolatedBranch, endReached, currentType = type[i], + nextType = type[i + 1], branches, _listeners; + + if (i === typeLength) { + // + // If at the end of the event(s) list and the tree has listeners + // invoke those listeners. + // + + if(tree._listeners) { + if (typeof tree._listeners === 'function') { + handlers && handlers.push(tree._listeners); + listeners = [tree]; + } else { + handlers && handlers.push.apply(handlers, tree._listeners); + listeners = [tree]; + } + } + } else { + + if (currentType === '*') { + // + // If the event emitted is '*' at this part + // or there is a concrete match at this patch + // + branches = ownKeys(tree); + n = branches.length; + while (n-- > 0) { + branch = branches[n]; + if (branch !== '_listeners') { + _listeners = searchListenerTree(handlers, type, tree[branch], i + 1, typeLength); + if (_listeners) { + if (listeners) { + listeners.push.apply(listeners, _listeners); + } else { + listeners = _listeners; + } + } + } + } + return listeners; + } else if (currentType === '**') { + endReached = (i + 1 === typeLength || (i + 2 === typeLength && nextType === '*')); + if (endReached && tree._listeners) { + // The next element has a _listeners, add it to the handlers. + listeners = searchListenerTree(handlers, type, tree, typeLength, typeLength); + } + + branches = ownKeys(tree); + n = branches.length; + while (n-- > 0) { + branch = branches[n]; + if (branch !== '_listeners') { + if (branch === '*' || branch === '**') { + if (tree[branch]._listeners && !endReached) { + _listeners = searchListenerTree(handlers, type, tree[branch], typeLength, typeLength); + if (_listeners) { + if (listeners) { + listeners.push.apply(listeners, _listeners); + } else { + listeners = _listeners; + } + } + } + _listeners = searchListenerTree(handlers, type, tree[branch], i, typeLength); + } else if (branch === nextType) { + _listeners = searchListenerTree(handlers, type, tree[branch], i + 2, typeLength); + } else { + // No match on this one, shift into the tree but not in the type array. + _listeners = searchListenerTree(handlers, type, tree[branch], i, typeLength); + } + if (_listeners) { + if (listeners) { + listeners.push.apply(listeners, _listeners); + } else { + listeners = _listeners; + } + } + } + } + return listeners; + } else if (tree[currentType]) { + listeners = searchListenerTree(handlers, type, tree[currentType], i + 1, typeLength); + } + } + + xTree = tree['*']; + if (xTree) { + // + // If the listener tree will allow any match for this part, + // then recursively explore all branches of the tree + // + searchListenerTree(handlers, type, xTree, i + 1, typeLength); + } + + xxTree = tree['**']; + if (xxTree) { + if (i < typeLength) { + if (xxTree._listeners) { + // If we have a listener on a '**', it will catch all, so add its handler. + searchListenerTree(handlers, type, xxTree, typeLength, typeLength); + } + + // Build arrays of matching next branches and others. + branches= ownKeys(xxTree); + n= branches.length; + while(n-->0){ + branch= branches[n]; + if (branch !== '_listeners') { + if (branch === nextType) { + // We know the next element will match, so jump twice. + searchListenerTree(handlers, type, xxTree[branch], i + 2, typeLength); + } else if (branch === currentType) { + // Current node matches, move into the tree. + searchListenerTree(handlers, type, xxTree[branch], i + 1, typeLength); + } else { + isolatedBranch = {}; + isolatedBranch[branch] = xxTree[branch]; + searchListenerTree(handlers, type, {'**': isolatedBranch}, i + 1, typeLength); + } + } + } + } else if (xxTree._listeners) { + // We have reached the end and still on a '**' + searchListenerTree(handlers, type, xxTree, typeLength, typeLength); + } else if (xxTree['*'] && xxTree['*']._listeners) { + searchListenerTree(handlers, type, xxTree['*'], typeLength, typeLength); + } + } + + return listeners; + } + + function growListenerTree(type, listener, prepend) { + var len = 0, j = 0, i, delimiter = this.delimiter, dl= delimiter.length, ns; + + if(typeof type==='string') { + if ((i = type.indexOf(delimiter)) !== -1) { + ns = new Array(5); + do { + ns[len++] = type.slice(j, i); + j = i + dl; + } while ((i = type.indexOf(delimiter, j)) !== -1); + + ns[len++] = type.slice(j); + }else { + ns= [type]; + len= 1; + } + }else { + ns= type; + len= type.length; + } + + // + // Looks for two consecutive '**', if so, don't add the event at all. + // + if (len > 1) { + for (i = 0; i + 1 < len; i++) { + if (ns[i] === '**' && ns[i + 1] === '**') { + return; + } + } + } + + + + var tree = this.listenerTree, name; + + for (i = 0; i < len; i++) { + name = ns[i]; + + tree = tree[name] || (tree[name] = {}); + + if (i === len - 1) { + if (!tree._listeners) { + tree._listeners = listener; + } else { + if (typeof tree._listeners === 'function') { + tree._listeners = [tree._listeners]; + } + + if (prepend) { + tree._listeners.unshift(listener); + } else { + tree._listeners.push(listener); + } + + if ( + !tree._listeners.warned && + this._maxListeners > 0 && + tree._listeners.length > this._maxListeners + ) { + tree._listeners.warned = true; + logPossibleMemoryLeak.call(this, tree._listeners.length, name); + } + } + return true; + } + } + + return true; + } + + function collectTreeEvents(tree, events, root, asArray){ + var branches= ownKeys(tree); + var i= branches.length; + var branch, branchName, path; + var hasListeners= tree['_listeners']; + var isArrayPath; + + while(i-->0){ + branchName= branches[i]; + + branch= tree[branchName]; + + if(branchName==='_listeners'){ + path= root; + }else { + path = root ? root.concat(branchName) : [branchName]; + } + + isArrayPath= asArray || typeof branchName==='symbol'; + + hasListeners && events.push(isArrayPath? path : path.join(this.delimiter)); + + if(typeof branch==='object'){ + collectTreeEvents.call(this, branch, events, path, isArrayPath); + } + } + + return events; + } + + function recursivelyGarbageCollect(root) { + var keys = ownKeys(root); + var i= keys.length; + var obj, key, flag; + while(i-->0){ + key = keys[i]; + obj = root[key]; + + if(obj){ + flag= true; + if(key !== '_listeners' && !recursivelyGarbageCollect(obj)){ + delete root[key]; + } + } + } + + return flag; + } + + function Listener(emitter, event, listener){ + this.emitter= emitter; + this.event= event; + this.listener= listener; + } + + Listener.prototype.off= function(){ + this.emitter.off(this.event, this.listener); + return this; + }; + + function setupListener(event, listener, options){ + if (options === true) { + promisify = true; + } else if (options === false) { + async = true; + } else { + if (!options || typeof options !== 'object') { + throw TypeError('options should be an object or true'); + } + var async = options.async; + var promisify = options.promisify; + var nextTick = options.nextTick; + var objectify = options.objectify; + } + + if (async || nextTick || promisify) { + var _listener = listener; + var _origin = listener._origin || listener; + + if (nextTick && !nextTickSupported) { + throw Error('process.nextTick is not supported'); + } + + if (promisify === undefined$1) { + promisify = listener.constructor.name === 'AsyncFunction'; + } + + listener = function () { + var args = arguments; + var context = this; + var event = this.event; + + return promisify ? (nextTick ? Promise.resolve() : new Promise(function (resolve) { + _setImmediate(resolve); + }).then(function () { + context.event = event; + return _listener.apply(context, args) + })) : (nextTick ? process.nextTick : _setImmediate)(function () { + context.event = event; + _listener.apply(context, args); + }); + }; + + listener._async = true; + listener._origin = _origin; + } + + return [listener, objectify? new Listener(this, event, listener): this]; + } + + function EventEmitter(conf) { + this._events = {}; + this._newListener = false; + this._removeListener = false; + this.verboseMemoryLeak = false; + configure.call(this, conf); + } + + EventEmitter.EventEmitter2 = EventEmitter; // backwards compatibility for exporting EventEmitter property + + EventEmitter.prototype.listenTo= function(target, events, options){ + if(typeof target!=='object'){ + throw TypeError('target musts be an object'); + } + + var emitter= this; + + options = resolveOptions(options, { + on: undefined$1, + off: undefined$1, + reducers: undefined$1 + }, { + on: functionReducer, + off: functionReducer, + reducers: objectFunctionReducer + }); + + function listen(events){ + if(typeof events!=='object'){ + throw TypeError('events must be an object'); + } + + var reducers= options.reducers; + var index= findTargetIndex.call(emitter, target); + var observer; + + if(index===-1){ + observer= new TargetObserver(emitter, target, options); + }else { + observer= emitter._observers[index]; + } + + var keys= ownKeys(events); + var len= keys.length; + var event; + var isSingleReducer= typeof reducers==='function'; + + for(var i=0; i 0) { + observer = observers[i]; + if (!target || observer._target === target) { + observer.unsubscribe(event); + matched= true; + } + } + + return matched; + }; + + // By default EventEmitters will print a warning if more than + // 10 listeners are added to it. This is a useful default which + // helps finding memory leaks. + // + // Obviously not all Emitters should be limited to 10. This function allows + // that to be increased. Set to zero for unlimited. + + EventEmitter.prototype.delimiter = '.'; + + EventEmitter.prototype.setMaxListeners = function(n) { + if (n !== undefined$1) { + this._maxListeners = n; + if (!this._conf) { this._conf = {}; } + this._conf.maxListeners = n; + } + }; + + EventEmitter.prototype.getMaxListeners = function() { + return this._maxListeners; + }; + + EventEmitter.prototype.event = ''; + + EventEmitter.prototype.once = function(event, fn, options) { + return this._once(event, fn, false, options); + }; + + EventEmitter.prototype.prependOnceListener = function(event, fn, options) { + return this._once(event, fn, true, options); + }; + + EventEmitter.prototype._once = function(event, fn, prepend, options) { + return this._many(event, 1, fn, prepend, options); + }; + + EventEmitter.prototype.many = function(event, ttl, fn, options) { + return this._many(event, ttl, fn, false, options); + }; + + EventEmitter.prototype.prependMany = function(event, ttl, fn, options) { + return this._many(event, ttl, fn, true, options); + }; + + EventEmitter.prototype._many = function(event, ttl, fn, prepend, options) { + var self = this; + + if (typeof fn !== 'function') { + throw new Error('many only accepts instances of Function'); + } + + function listener() { + if (--ttl === 0) { + self.off(event, listener); + } + return fn.apply(this, arguments); + } + + listener._origin = fn; + + return this._on(event, listener, prepend, options); + }; + + EventEmitter.prototype.emit = function() { + var arguments$1 = arguments; + + if (!this._events && !this._all) { + return false; + } + + this._events || init.call(this); + + var type = arguments[0], ns, wildcard= this.wildcard; + var args,l,i,j, containsSymbol; + + if (type === 'newListener' && !this._newListener) { + if (!this._events.newListener) { + return false; + } + } + + if (wildcard) { + ns= type; + if(type!=='newListener' && type!=='removeListener'){ + if (typeof type === 'object') { + l = type.length; + if (symbolsSupported) { + for (i = 0; i < l; i++) { + if (typeof type[i] === 'symbol') { + containsSymbol = true; + break; + } + } + } + if (!containsSymbol) { + type = type.join(this.delimiter); + } + } + } + } + + var al = arguments.length; + var handler; + + if (this._all && this._all.length) { + handler = this._all.slice(); + + for (i = 0, l = handler.length; i < l; i++) { + this.event = type; + switch (al) { + case 1: + handler[i].call(this, type); + break; + case 2: + handler[i].call(this, type, arguments$1[1]); + break; + case 3: + handler[i].call(this, type, arguments$1[1], arguments$1[2]); + break; + default: + handler[i].apply(this, arguments$1); + } + } + } + + if (wildcard) { + handler = []; + searchListenerTree.call(this, handler, ns, this.listenerTree, 0, l); + } else { + handler = this._events[type]; + if (typeof handler === 'function') { + this.event = type; + switch (al) { + case 1: + handler.call(this); + break; + case 2: + handler.call(this, arguments[1]); + break; + case 3: + handler.call(this, arguments[1], arguments[2]); + break; + default: + args = new Array(al - 1); + for (j = 1; j < al; j++) { args[j - 1] = arguments$1[j]; } + handler.apply(this, args); + } + return true; + } else if (handler) { + // need to make copy of handlers because list can change in the middle + // of emit call + handler = handler.slice(); + } + } + + if (handler && handler.length) { + if (al > 3) { + args = new Array(al - 1); + for (j = 1; j < al; j++) { args[j - 1] = arguments$1[j]; } + } + for (i = 0, l = handler.length; i < l; i++) { + this.event = type; + switch (al) { + case 1: + handler[i].call(this); + break; + case 2: + handler[i].call(this, arguments$1[1]); + break; + case 3: + handler[i].call(this, arguments$1[1], arguments$1[2]); + break; + default: + handler[i].apply(this, args); + } + } + return true; + } else if (!this.ignoreErrors && !this._all && type === 'error') { + if (arguments[1] instanceof Error) { + throw arguments[1]; // Unhandled 'error' event + } else { + throw new Error("Uncaught, unspecified 'error' event."); + } + } + + return !!this._all; + }; + + EventEmitter.prototype.emitAsync = function() { + var arguments$1 = arguments; + + if (!this._events && !this._all) { + return false; + } + + this._events || init.call(this); + + var type = arguments[0], wildcard= this.wildcard, ns, containsSymbol; + var args,l,i,j; + + if (type === 'newListener' && !this._newListener) { + if (!this._events.newListener) { return Promise.resolve([false]); } + } + + if (wildcard) { + ns= type; + if(type!=='newListener' && type!=='removeListener'){ + if (typeof type === 'object') { + l = type.length; + if (symbolsSupported) { + for (i = 0; i < l; i++) { + if (typeof type[i] === 'symbol') { + containsSymbol = true; + break; + } + } + } + if (!containsSymbol) { + type = type.join(this.delimiter); + } + } + } + } + + var promises= []; + + var al = arguments.length; + var handler; + + if (this._all) { + for (i = 0, l = this._all.length; i < l; i++) { + this.event = type; + switch (al) { + case 1: + promises.push(this._all[i].call(this, type)); + break; + case 2: + promises.push(this._all[i].call(this, type, arguments$1[1])); + break; + case 3: + promises.push(this._all[i].call(this, type, arguments$1[1], arguments$1[2])); + break; + default: + promises.push(this._all[i].apply(this, arguments$1)); + } + } + } + + if (wildcard) { + handler = []; + searchListenerTree.call(this, handler, ns, this.listenerTree, 0); + } else { + handler = this._events[type]; + } + + if (typeof handler === 'function') { + this.event = type; + switch (al) { + case 1: + promises.push(handler.call(this)); + break; + case 2: + promises.push(handler.call(this, arguments[1])); + break; + case 3: + promises.push(handler.call(this, arguments[1], arguments[2])); + break; + default: + args = new Array(al - 1); + for (j = 1; j < al; j++) { args[j - 1] = arguments$1[j]; } + promises.push(handler.apply(this, args)); + } + } else if (handler && handler.length) { + handler = handler.slice(); + if (al > 3) { + args = new Array(al - 1); + for (j = 1; j < al; j++) { args[j - 1] = arguments$1[j]; } + } + for (i = 0, l = handler.length; i < l; i++) { + this.event = type; + switch (al) { + case 1: + promises.push(handler[i].call(this)); + break; + case 2: + promises.push(handler[i].call(this, arguments$1[1])); + break; + case 3: + promises.push(handler[i].call(this, arguments$1[1], arguments$1[2])); + break; + default: + promises.push(handler[i].apply(this, args)); + } + } + } else if (!this.ignoreErrors && !this._all && type === 'error') { + if (arguments[1] instanceof Error) { + return Promise.reject(arguments[1]); // Unhandled 'error' event + } else { + return Promise.reject("Uncaught, unspecified 'error' event."); + } + } + + return Promise.all(promises); + }; + + EventEmitter.prototype.on = function(type, listener, options) { + return this._on(type, listener, false, options); + }; + + EventEmitter.prototype.prependListener = function(type, listener, options) { + return this._on(type, listener, true, options); + }; + + EventEmitter.prototype.onAny = function(fn) { + return this._onAny(fn, false); + }; + + EventEmitter.prototype.prependAny = function(fn) { + return this._onAny(fn, true); + }; + + EventEmitter.prototype.addListener = EventEmitter.prototype.on; + + EventEmitter.prototype._onAny = function(fn, prepend){ + if (typeof fn !== 'function') { + throw new Error('onAny only accepts instances of Function'); + } + + if (!this._all) { + this._all = []; + } + + // Add the function to the event listener collection. + if(prepend){ + this._all.unshift(fn); + }else { + this._all.push(fn); + } + + return this; + }; + + EventEmitter.prototype._on = function(type, listener, prepend, options) { + if (typeof type === 'function') { + this._onAny(type, listener); + return this; + } + + if (typeof listener !== 'function') { + throw new Error('on only accepts instances of Function'); + } + this._events || init.call(this); + + var returnValue= this, temp; + + if (options !== undefined$1) { + temp = setupListener.call(this, type, listener, options); + listener = temp[0]; + returnValue = temp[1]; + } + + // To avoid recursion in the case that type == "newListeners"! Before + // adding it to the listeners, first emit "newListeners". + if (this._newListener) { + this.emit('newListener', type, listener); + } + + if (this.wildcard) { + growListenerTree.call(this, type, listener, prepend); + return returnValue; + } + + if (!this._events[type]) { + // Optimize the case of one listener. Don't need the extra array object. + this._events[type] = listener; + } else { + if (typeof this._events[type] === 'function') { + // Change to array. + this._events[type] = [this._events[type]]; + } + + // If we've already got an array, just add + if(prepend){ + this._events[type].unshift(listener); + }else { + this._events[type].push(listener); + } + + // Check for listener leak + if ( + !this._events[type].warned && + this._maxListeners > 0 && + this._events[type].length > this._maxListeners + ) { + this._events[type].warned = true; + logPossibleMemoryLeak.call(this, this._events[type].length, type); + } + } + + return returnValue; + }; + + EventEmitter.prototype.off = function(type, listener) { + if (typeof listener !== 'function') { + throw new Error('removeListener only takes instances of Function'); + } + + var handlers,leafs=[]; + + if(this.wildcard) { + var ns = typeof type === 'string' ? type.split(this.delimiter) : type.slice(); + leafs = searchListenerTree.call(this, null, ns, this.listenerTree, 0); + if(!leafs) { return this; } + } else { + // does not use listeners(), so no side effect of creating _events[type] + if (!this._events[type]) { return this; } + handlers = this._events[type]; + leafs.push({_listeners:handlers}); + } + + for (var iLeaf=0; iLeaf 0) { + fns = this._all; + for(i = 0, l = fns.length; i < l; i++) { + if(fn === fns[i]) { + fns.splice(i, 1); + if (this._removeListener) + { this.emit("removeListenerAny", fn); } + return this; + } + } + } else { + fns = this._all; + if (this._removeListener) { + for(i = 0, l = fns.length; i < l; i++) + { this.emit("removeListenerAny", fns[i]); } + } + this._all = []; + } + return this; + }; + + EventEmitter.prototype.removeListener = EventEmitter.prototype.off; + + EventEmitter.prototype.removeAllListeners = function (type) { + if (type === undefined$1) { + !this._events || init.call(this); + return this; + } + + if (this.wildcard) { + var leafs = searchListenerTree.call(this, null, type, this.listenerTree, 0), leaf, i; + if (!leafs) { return this; } + for (i = 0; i < leafs.length; i++) { + leaf = leafs[i]; + leaf._listeners = null; + } + this.listenerTree && recursivelyGarbageCollect(this.listenerTree); + } else if (this._events) { + this._events[type] = null; + } + return this; + }; + + EventEmitter.prototype.listeners = function (type) { + var _events = this._events; + var keys, listeners, allListeners; + var i; + var listenerTree; + + if (type === undefined$1) { + if (this.wildcard) { + throw Error('event name required for wildcard emitter'); + } + + if (!_events) { + return []; + } + + keys = ownKeys(_events); + i = keys.length; + allListeners = []; + while (i-- > 0) { + listeners = _events[keys[i]]; + if (typeof listeners === 'function') { + allListeners.push(listeners); + } else { + allListeners.push.apply(allListeners, listeners); + } + } + return allListeners; + } else { + if (this.wildcard) { + listenerTree= this.listenerTree; + if(!listenerTree) { return []; } + var handlers = []; + var ns = typeof type === 'string' ? type.split(this.delimiter) : type.slice(); + searchListenerTree.call(this, handlers, ns, listenerTree, 0); + return handlers; + } + + if (!_events) { + return []; + } + + listeners = _events[type]; + + if (!listeners) { + return []; + } + return typeof listeners === 'function' ? [listeners] : listeners; + } + }; + + EventEmitter.prototype.eventNames = function(nsAsArray){ + var _events= this._events; + return this.wildcard? collectTreeEvents.call(this, this.listenerTree, [], null, nsAsArray) : (_events? ownKeys(_events) : []); + }; + + EventEmitter.prototype.listenerCount = function(type) { + return this.listeners(type).length; + }; + + EventEmitter.prototype.hasListeners = function (type) { + if (this.wildcard) { + var handlers = []; + var ns = typeof type === 'string' ? type.split(this.delimiter) : type.slice(); + searchListenerTree.call(this, handlers, ns, this.listenerTree, 0); + return handlers.length > 0; + } + + var _events = this._events; + var _all = this._all; + + return !!(_all && _all.length || _events && (type === undefined$1 ? ownKeys(_events).length : _events[type])); + }; + + EventEmitter.prototype.listenersAny = function() { + + if(this._all) { + return this._all; + } + else { + return []; + } + + }; + + EventEmitter.prototype.waitFor = function (event, options) { + var self = this; + var type = typeof options; + if (type === 'number') { + options = {timeout: options}; + } else if (type === 'function') { + options = {filter: options}; + } + + options= resolveOptions(options, { + timeout: 0, + filter: undefined$1, + handleError: false, + Promise: Promise, + overload: false + }, { + filter: functionReducer, + Promise: constructorReducer + }); + + return makeCancelablePromise(options.Promise, function (resolve, reject, onCancel) { + function listener() { + var filter= options.filter; + if (filter && !filter.apply(self, arguments)) { + return; + } + self.off(event, listener); + if (options.handleError) { + var err = arguments[0]; + err ? reject(err) : resolve(toArray.apply(null, arguments).slice(1)); + } else { + resolve(toArray.apply(null, arguments)); + } + } + + onCancel(function(){ + self.off(event, listener); + }); + + self._on(event, listener, false); + }, { + timeout: options.timeout, + overload: options.overload + }) + }; + + function once(emitter, name, options) { + options= resolveOptions(options, { + Promise: Promise, + timeout: 0, + overload: false + }, { + Promise: constructorReducer + }); + + var _Promise= options.Promise; + + return makeCancelablePromise(_Promise, function(resolve, reject, onCancel){ + var handler; + if (typeof emitter.addEventListener === 'function') { + handler= function () { + resolve(toArray.apply(null, arguments)); + }; + + onCancel(function(){ + emitter.removeEventListener(name, handler); + }); + + emitter.addEventListener( + name, + handler, + {once: true} + ); + return; + } + + var eventListener = function(){ + errorListener && emitter.removeListener('error', errorListener); + resolve(toArray.apply(null, arguments)); + }; + + var errorListener; + + if (name !== 'error') { + errorListener = function (err){ + emitter.removeListener(name, eventListener); + reject(err); + }; + + emitter.once('error', errorListener); + } + + onCancel(function(){ + errorListener && emitter.removeListener('error', errorListener); + emitter.removeListener(name, eventListener); + }); + + emitter.once(name, eventListener); + }, { + timeout: options.timeout, + overload: options.overload + }); + } + + var prototype= EventEmitter.prototype; + + Object.defineProperties(EventEmitter, { + defaultMaxListeners: { + get: function () { + return prototype._maxListeners; + }, + set: function (n) { + if (typeof n !== 'number' || n < 0 || Number.isNaN(n)) { + throw TypeError('n must be a non-negative number') + } + prototype._maxListeners = n; + }, + enumerable: true + }, + once: { + value: once, + writable: true, + configurable: true + } + }); + + Object.defineProperties(prototype, { + _maxListeners: { + value: defaultMaxListeners, + writable: true, + configurable: true + }, + _observers: {value: null, writable: true, configurable: true} + }); + + if (typeof undefined$1 === 'function' && undefined$1.amd) { + // AMD. Register as an anonymous module. + undefined$1(function() { + return EventEmitter; + }); + } else { + // CommonJS + module.exports = EventEmitter; + } + }(); + } (eventemitter2, eventemitter2.exports)); + return eventemitter2.exports; +} + +var eventemitter2Exports = requireEventemitter2(); var EventEmitter2 = /*@__PURE__*/getDefaultExportFromCjs(eventemitter2Exports); /** diff --git a/build/ros3d.esm.js b/build/ros3d.esm.js index 23e4c21c..af7025c1 100644 --- a/build/ros3d.esm.js +++ b/build/ros3d.esm.js @@ -53239,1633 +53239,1640 @@ var eventemitter2 = {exports: {}}; */ eventemitter2.exports; -(function (module, exports) { +var hasRequiredEventemitter2; + +function requireEventemitter2 () { + if (hasRequiredEventemitter2) { return eventemitter2.exports; } + hasRequiredEventemitter2 = 1; + (function (module, exports) { !function(undefined$1) { - var hasOwnProperty= Object.hasOwnProperty; - var isArray = Array.isArray ? Array.isArray : function _isArray(obj) { - return Object.prototype.toString.call(obj) === "[object Array]"; - }; - var defaultMaxListeners = 10; - var nextTickSupported= typeof process=='object' && typeof process.nextTick=='function'; - var symbolsSupported= typeof Symbol==='function'; - var reflectSupported= typeof Reflect === 'object'; - var setImmediateSupported= typeof setImmediate === 'function'; - var _setImmediate= setImmediateSupported ? setImmediate : setTimeout; - var ownKeys= symbolsSupported? (reflectSupported && typeof Reflect.ownKeys==='function'? Reflect.ownKeys : function(obj){ - var arr= Object.getOwnPropertyNames(obj); - arr.push.apply(arr, Object.getOwnPropertySymbols(obj)); - return arr; - }) : Object.keys; - - function init() { - this._events = {}; - if (this._conf) { - configure.call(this, this._conf); - } - } - - function configure(conf) { - if (conf) { - this._conf = conf; - - conf.delimiter && (this.delimiter = conf.delimiter); - - if(conf.maxListeners!==undefined$1){ - this._maxListeners= conf.maxListeners; - } - - conf.wildcard && (this.wildcard = conf.wildcard); - conf.newListener && (this._newListener = conf.newListener); - conf.removeListener && (this._removeListener = conf.removeListener); - conf.verboseMemoryLeak && (this.verboseMemoryLeak = conf.verboseMemoryLeak); - conf.ignoreErrors && (this.ignoreErrors = conf.ignoreErrors); - - if (this.wildcard) { - this.listenerTree = {}; - } - } - } - - function logPossibleMemoryLeak(count, eventName) { - var errorMsg = '(node) warning: possible EventEmitter memory ' + - 'leak detected. ' + count + ' listeners added. ' + - 'Use emitter.setMaxListeners() to increase limit.'; - - if(this.verboseMemoryLeak){ - errorMsg += ' Event name: ' + eventName + '.'; - } - - if(typeof process !== 'undefined' && process.emitWarning){ - var e = new Error(errorMsg); - e.name = 'MaxListenersExceededWarning'; - e.emitter = this; - e.count = count; - process.emitWarning(e); - } else { - console.error(errorMsg); - - if (console.trace){ - console.trace(); - } - } - } - - var toArray = function (a, b, c) { - var arguments$1 = arguments; - - var n = arguments.length; - switch (n) { - case 0: - return []; - case 1: - return [a]; - case 2: - return [a, b]; - case 3: - return [a, b, c]; - default: - var arr = new Array(n); - while (n--) { - arr[n] = arguments$1[n]; - } - return arr; - } - }; - - function toObject(keys, values) { - var obj = {}; - var key; - var len = keys.length; - var valuesCount = values ? value.length : 0; - for (var i = 0; i < len; i++) { - key = keys[i]; - obj[key] = i < valuesCount ? values[i] : undefined$1; - } - return obj; - } - - function TargetObserver(emitter, target, options) { - this._emitter = emitter; - this._target = target; - this._listeners = {}; - this._listenersCount = 0; - - var on, off; - - if (options.on || options.off) { - on = options.on; - off = options.off; - } - - if (target.addEventListener) { - on = target.addEventListener; - off = target.removeEventListener; - } else if (target.addListener) { - on = target.addListener; - off = target.removeListener; - } else if (target.on) { - on = target.on; - off = target.off; - } - - if (!on && !off) { - throw Error('target does not implement any known event API'); - } - - if (typeof on !== 'function') { - throw TypeError('on method must be a function'); - } - - if (typeof off !== 'function') { - throw TypeError('off method must be a function'); - } - - this._on = on; - this._off = off; - - var _observers= emitter._observers; - if(_observers){ - _observers.push(this); - }else { - emitter._observers= [this]; - } - } - - Object.assign(TargetObserver.prototype, { - subscribe: function(event, localEvent, reducer){ - var observer= this; - var target= this._target; - var emitter= this._emitter; - var listeners= this._listeners; - var handler= function(){ - var args= toArray.apply(null, arguments); - var eventObj= { - data: args, - name: localEvent, - original: event - }; - if(reducer){ - var result= reducer.call(target, eventObj); - if(result!==false){ - emitter.emit.apply(emitter, [eventObj.name].concat(args)); - } - return; - } - emitter.emit.apply(emitter, [localEvent].concat(args)); - }; - - - if(listeners[event]){ - throw Error('Event \'' + event + '\' is already listening'); - } - - this._listenersCount++; - - if(emitter._newListener && emitter._removeListener && !observer._onNewListener){ - - this._onNewListener = function (_event) { - if (_event === localEvent && listeners[event] === null) { - listeners[event] = handler; - observer._on.call(target, event, handler); - } - }; - - emitter.on('newListener', this._onNewListener); - - this._onRemoveListener= function(_event){ - if(_event === localEvent && !emitter.hasListeners(_event) && listeners[event]){ - listeners[event]= null; - observer._off.call(target, event, handler); - } - }; - - listeners[event]= null; - - emitter.on('removeListener', this._onRemoveListener); - }else { - listeners[event]= handler; - observer._on.call(target, event, handler); - } - }, - - unsubscribe: function(event){ - var observer= this; - var listeners= this._listeners; - var emitter= this._emitter; - var handler; - var events; - var off= this._off; - var target= this._target; - var i; - - if(event && typeof event!=='string'){ - throw TypeError('event must be a string'); - } - - function clearRefs(){ - if(observer._onNewListener){ - emitter.off('newListener', observer._onNewListener); - emitter.off('removeListener', observer._onRemoveListener); - observer._onNewListener= null; - observer._onRemoveListener= null; - } - var index= findTargetIndex.call(emitter, observer); - emitter._observers.splice(index, 1); - } - - if(event){ - handler= listeners[event]; - if(!handler) { return; } - off.call(target, event, handler); - delete listeners[event]; - if(!--this._listenersCount){ - clearRefs(); - } - }else { - events= ownKeys(listeners); - i= events.length; - while(i-->0){ - event= events[i]; - off.call(target, event, listeners[event]); - } - this._listeners= {}; - this._listenersCount= 0; - clearRefs(); - } - } - }); - - function resolveOptions(options, schema, reducers, allowUnknown) { - var computedOptions = Object.assign({}, schema); - - if (!options) { return computedOptions; } - - if (typeof options !== 'object') { - throw TypeError('options must be an object') - } - - var keys = Object.keys(options); - var length = keys.length; - var option, value; - var reducer; - - function reject(reason) { - throw Error('Invalid "' + option + '" option value' + (reason ? '. Reason: ' + reason : '')) - } - - for (var i = 0; i < length; i++) { - option = keys[i]; - if (!allowUnknown && !hasOwnProperty.call(schema, option)) { - throw Error('Unknown "' + option + '" option'); - } - value = options[option]; - if (value !== undefined$1) { - reducer = reducers[option]; - computedOptions[option] = reducer ? reducer(value, reject) : value; - } - } - return computedOptions; - } - - function constructorReducer(value, reject) { - if (typeof value !== 'function' || !value.hasOwnProperty('prototype')) { - reject('value must be a constructor'); - } - return value; - } - - function makeTypeReducer(types) { - var message= 'value must be type of ' + types.join('|'); - var len= types.length; - var firstType= types[0]; - var secondType= types[1]; - - if (len === 1) { - return function (v, reject) { - if (typeof v === firstType) { - return v; - } - reject(message); - } - } - - if (len === 2) { - return function (v, reject) { - var kind= typeof v; - if (kind === firstType || kind === secondType) { return v; } - reject(message); - } - } - - return function (v, reject) { - var kind = typeof v; - var i = len; - while (i-- > 0) { - if (kind === types[i]) { return v; } - } - reject(message); - } - } - - var functionReducer= makeTypeReducer(['function']); - - var objectFunctionReducer= makeTypeReducer(['object', 'function']); - - function makeCancelablePromise(Promise, executor, options) { - var isCancelable; - var callbacks; - var timer= 0; - var subscriptionClosed; - - var promise = new Promise(function (resolve, reject, onCancel) { - options= resolveOptions(options, { - timeout: 0, - overload: false - }, { - timeout: function(value, reject){ - value*= 1; - if (typeof value !== 'number' || value < 0 || !Number.isFinite(value)) { - reject('timeout must be a positive number'); - } - return value; - } - }); - - isCancelable = !options.overload && typeof Promise.prototype.cancel === 'function' && typeof onCancel === 'function'; - - function cleanup() { - if (callbacks) { - callbacks = null; - } - if (timer) { - clearTimeout(timer); - timer = 0; - } - } - - var _resolve= function(value){ - cleanup(); - resolve(value); - }; - - var _reject= function(err){ - cleanup(); - reject(err); - }; - - if (isCancelable) { - executor(_resolve, _reject, onCancel); - } else { - callbacks = [function(reason){ - _reject(reason || Error('canceled')); - }]; - executor(_resolve, _reject, function (cb) { - if (subscriptionClosed) { - throw Error('Unable to subscribe on cancel event asynchronously') - } - if (typeof cb !== 'function') { - throw TypeError('onCancel callback must be a function'); - } - callbacks.push(cb); - }); - subscriptionClosed= true; - } - - if (options.timeout > 0) { - timer= setTimeout(function(){ - var reason= Error('timeout'); - reason.code = 'ETIMEDOUT'; - timer= 0; - promise.cancel(reason); - reject(reason); - }, options.timeout); - } - }); - - if (!isCancelable) { - promise.cancel = function (reason) { - if (!callbacks) { - return; - } - var length = callbacks.length; - for (var i = 1; i < length; i++) { - callbacks[i](reason); - } - // internal callback to reject the promise - callbacks[0](reason); - callbacks = null; - }; - } - - return promise; - } - - function findTargetIndex(observer) { - var observers = this._observers; - if(!observers){ - return -1; - } - var len = observers.length; - for (var i = 0; i < len; i++) { - if (observers[i]._target === observer) { return i; } - } - return -1; - } - - // Attention, function return type now is array, always ! - // It has zero elements if no any matches found and one or more - // elements (leafs) if there are matches - // - function searchListenerTree(handlers, type, tree, i, typeLength) { - if (!tree) { - return null; - } - - if (i === 0) { - var kind = typeof type; - if (kind === 'string') { - var ns, n, l = 0, j = 0, delimiter = this.delimiter, dl = delimiter.length; - if ((n = type.indexOf(delimiter)) !== -1) { - ns = new Array(5); - do { - ns[l++] = type.slice(j, n); - j = n + dl; - } while ((n = type.indexOf(delimiter, j)) !== -1); - - ns[l++] = type.slice(j); - type = ns; - typeLength = l; - } else { - type = [type]; - typeLength = 1; - } - } else if (kind === 'object') { - typeLength = type.length; - } else { - type = [type]; - typeLength = 1; - } - } - - var listeners= null, branch, xTree, xxTree, isolatedBranch, endReached, currentType = type[i], - nextType = type[i + 1], branches, _listeners; - - if (i === typeLength) { - // - // If at the end of the event(s) list and the tree has listeners - // invoke those listeners. - // - - if(tree._listeners) { - if (typeof tree._listeners === 'function') { - handlers && handlers.push(tree._listeners); - listeners = [tree]; - } else { - handlers && handlers.push.apply(handlers, tree._listeners); - listeners = [tree]; - } - } - } else { - - if (currentType === '*') { - // - // If the event emitted is '*' at this part - // or there is a concrete match at this patch - // - branches = ownKeys(tree); - n = branches.length; - while (n-- > 0) { - branch = branches[n]; - if (branch !== '_listeners') { - _listeners = searchListenerTree(handlers, type, tree[branch], i + 1, typeLength); - if (_listeners) { - if (listeners) { - listeners.push.apply(listeners, _listeners); - } else { - listeners = _listeners; - } - } - } - } - return listeners; - } else if (currentType === '**') { - endReached = (i + 1 === typeLength || (i + 2 === typeLength && nextType === '*')); - if (endReached && tree._listeners) { - // The next element has a _listeners, add it to the handlers. - listeners = searchListenerTree(handlers, type, tree, typeLength, typeLength); - } - - branches = ownKeys(tree); - n = branches.length; - while (n-- > 0) { - branch = branches[n]; - if (branch !== '_listeners') { - if (branch === '*' || branch === '**') { - if (tree[branch]._listeners && !endReached) { - _listeners = searchListenerTree(handlers, type, tree[branch], typeLength, typeLength); - if (_listeners) { - if (listeners) { - listeners.push.apply(listeners, _listeners); - } else { - listeners = _listeners; - } - } - } - _listeners = searchListenerTree(handlers, type, tree[branch], i, typeLength); - } else if (branch === nextType) { - _listeners = searchListenerTree(handlers, type, tree[branch], i + 2, typeLength); - } else { - // No match on this one, shift into the tree but not in the type array. - _listeners = searchListenerTree(handlers, type, tree[branch], i, typeLength); - } - if (_listeners) { - if (listeners) { - listeners.push.apply(listeners, _listeners); - } else { - listeners = _listeners; - } - } - } - } - return listeners; - } else if (tree[currentType]) { - listeners = searchListenerTree(handlers, type, tree[currentType], i + 1, typeLength); - } - } - - xTree = tree['*']; - if (xTree) { - // - // If the listener tree will allow any match for this part, - // then recursively explore all branches of the tree - // - searchListenerTree(handlers, type, xTree, i + 1, typeLength); - } - - xxTree = tree['**']; - if (xxTree) { - if (i < typeLength) { - if (xxTree._listeners) { - // If we have a listener on a '**', it will catch all, so add its handler. - searchListenerTree(handlers, type, xxTree, typeLength, typeLength); - } - - // Build arrays of matching next branches and others. - branches= ownKeys(xxTree); - n= branches.length; - while(n-->0){ - branch= branches[n]; - if (branch !== '_listeners') { - if (branch === nextType) { - // We know the next element will match, so jump twice. - searchListenerTree(handlers, type, xxTree[branch], i + 2, typeLength); - } else if (branch === currentType) { - // Current node matches, move into the tree. - searchListenerTree(handlers, type, xxTree[branch], i + 1, typeLength); - } else { - isolatedBranch = {}; - isolatedBranch[branch] = xxTree[branch]; - searchListenerTree(handlers, type, {'**': isolatedBranch}, i + 1, typeLength); - } - } - } - } else if (xxTree._listeners) { - // We have reached the end and still on a '**' - searchListenerTree(handlers, type, xxTree, typeLength, typeLength); - } else if (xxTree['*'] && xxTree['*']._listeners) { - searchListenerTree(handlers, type, xxTree['*'], typeLength, typeLength); - } - } - - return listeners; - } - - function growListenerTree(type, listener, prepend) { - var len = 0, j = 0, i, delimiter = this.delimiter, dl= delimiter.length, ns; - - if(typeof type==='string') { - if ((i = type.indexOf(delimiter)) !== -1) { - ns = new Array(5); - do { - ns[len++] = type.slice(j, i); - j = i + dl; - } while ((i = type.indexOf(delimiter, j)) !== -1); - - ns[len++] = type.slice(j); - }else { - ns= [type]; - len= 1; - } - }else { - ns= type; - len= type.length; - } - - // - // Looks for two consecutive '**', if so, don't add the event at all. - // - if (len > 1) { - for (i = 0; i + 1 < len; i++) { - if (ns[i] === '**' && ns[i + 1] === '**') { - return; - } - } - } - - - - var tree = this.listenerTree, name; - - for (i = 0; i < len; i++) { - name = ns[i]; - - tree = tree[name] || (tree[name] = {}); - - if (i === len - 1) { - if (!tree._listeners) { - tree._listeners = listener; - } else { - if (typeof tree._listeners === 'function') { - tree._listeners = [tree._listeners]; - } - - if (prepend) { - tree._listeners.unshift(listener); - } else { - tree._listeners.push(listener); - } - - if ( - !tree._listeners.warned && - this._maxListeners > 0 && - tree._listeners.length > this._maxListeners - ) { - tree._listeners.warned = true; - logPossibleMemoryLeak.call(this, tree._listeners.length, name); - } - } - return true; - } - } - - return true; - } - - function collectTreeEvents(tree, events, root, asArray){ - var branches= ownKeys(tree); - var i= branches.length; - var branch, branchName, path; - var hasListeners= tree['_listeners']; - var isArrayPath; - - while(i-->0){ - branchName= branches[i]; - - branch= tree[branchName]; - - if(branchName==='_listeners'){ - path= root; - }else { - path = root ? root.concat(branchName) : [branchName]; - } - - isArrayPath= asArray || typeof branchName==='symbol'; - - hasListeners && events.push(isArrayPath? path : path.join(this.delimiter)); - - if(typeof branch==='object'){ - collectTreeEvents.call(this, branch, events, path, isArrayPath); - } - } - - return events; - } - - function recursivelyGarbageCollect(root) { - var keys = ownKeys(root); - var i= keys.length; - var obj, key, flag; - while(i-->0){ - key = keys[i]; - obj = root[key]; - - if(obj){ - flag= true; - if(key !== '_listeners' && !recursivelyGarbageCollect(obj)){ - delete root[key]; - } - } - } - - return flag; - } - - function Listener(emitter, event, listener){ - this.emitter= emitter; - this.event= event; - this.listener= listener; - } - - Listener.prototype.off= function(){ - this.emitter.off(this.event, this.listener); - return this; - }; - - function setupListener(event, listener, options){ - if (options === true) { - promisify = true; - } else if (options === false) { - async = true; - } else { - if (!options || typeof options !== 'object') { - throw TypeError('options should be an object or true'); - } - var async = options.async; - var promisify = options.promisify; - var nextTick = options.nextTick; - var objectify = options.objectify; - } - - if (async || nextTick || promisify) { - var _listener = listener; - var _origin = listener._origin || listener; - - if (nextTick && !nextTickSupported) { - throw Error('process.nextTick is not supported'); - } - - if (promisify === undefined$1) { - promisify = listener.constructor.name === 'AsyncFunction'; - } - - listener = function () { - var args = arguments; - var context = this; - var event = this.event; - - return promisify ? (nextTick ? Promise.resolve() : new Promise(function (resolve) { - _setImmediate(resolve); - }).then(function () { - context.event = event; - return _listener.apply(context, args) - })) : (nextTick ? process.nextTick : _setImmediate)(function () { - context.event = event; - _listener.apply(context, args); - }); - }; - - listener._async = true; - listener._origin = _origin; - } - - return [listener, objectify? new Listener(this, event, listener): this]; - } - - function EventEmitter(conf) { - this._events = {}; - this._newListener = false; - this._removeListener = false; - this.verboseMemoryLeak = false; - configure.call(this, conf); - } - - EventEmitter.EventEmitter2 = EventEmitter; // backwards compatibility for exporting EventEmitter property - - EventEmitter.prototype.listenTo= function(target, events, options){ - if(typeof target!=='object'){ - throw TypeError('target musts be an object'); - } - - var emitter= this; - - options = resolveOptions(options, { - on: undefined$1, - off: undefined$1, - reducers: undefined$1 - }, { - on: functionReducer, - off: functionReducer, - reducers: objectFunctionReducer - }); - - function listen(events){ - if(typeof events!=='object'){ - throw TypeError('events must be an object'); - } - - var reducers= options.reducers; - var index= findTargetIndex.call(emitter, target); - var observer; - - if(index===-1){ - observer= new TargetObserver(emitter, target, options); - }else { - observer= emitter._observers[index]; - } - - var keys= ownKeys(events); - var len= keys.length; - var event; - var isSingleReducer= typeof reducers==='function'; - - for(var i=0; i 0) { - observer = observers[i]; - if (!target || observer._target === target) { - observer.unsubscribe(event); - matched= true; - } - } - - return matched; - }; - - // By default EventEmitters will print a warning if more than - // 10 listeners are added to it. This is a useful default which - // helps finding memory leaks. - // - // Obviously not all Emitters should be limited to 10. This function allows - // that to be increased. Set to zero for unlimited. - - EventEmitter.prototype.delimiter = '.'; - - EventEmitter.prototype.setMaxListeners = function(n) { - if (n !== undefined$1) { - this._maxListeners = n; - if (!this._conf) { this._conf = {}; } - this._conf.maxListeners = n; - } - }; - - EventEmitter.prototype.getMaxListeners = function() { - return this._maxListeners; - }; - - EventEmitter.prototype.event = ''; - - EventEmitter.prototype.once = function(event, fn, options) { - return this._once(event, fn, false, options); - }; - - EventEmitter.prototype.prependOnceListener = function(event, fn, options) { - return this._once(event, fn, true, options); - }; - - EventEmitter.prototype._once = function(event, fn, prepend, options) { - return this._many(event, 1, fn, prepend, options); - }; - - EventEmitter.prototype.many = function(event, ttl, fn, options) { - return this._many(event, ttl, fn, false, options); - }; - - EventEmitter.prototype.prependMany = function(event, ttl, fn, options) { - return this._many(event, ttl, fn, true, options); - }; - - EventEmitter.prototype._many = function(event, ttl, fn, prepend, options) { - var self = this; - - if (typeof fn !== 'function') { - throw new Error('many only accepts instances of Function'); - } - - function listener() { - if (--ttl === 0) { - self.off(event, listener); - } - return fn.apply(this, arguments); - } - - listener._origin = fn; - - return this._on(event, listener, prepend, options); - }; - - EventEmitter.prototype.emit = function() { - var arguments$1 = arguments; - - if (!this._events && !this._all) { - return false; - } - - this._events || init.call(this); - - var type = arguments[0], ns, wildcard= this.wildcard; - var args,l,i,j, containsSymbol; - - if (type === 'newListener' && !this._newListener) { - if (!this._events.newListener) { - return false; - } - } - - if (wildcard) { - ns= type; - if(type!=='newListener' && type!=='removeListener'){ - if (typeof type === 'object') { - l = type.length; - if (symbolsSupported) { - for (i = 0; i < l; i++) { - if (typeof type[i] === 'symbol') { - containsSymbol = true; - break; - } - } - } - if (!containsSymbol) { - type = type.join(this.delimiter); - } - } - } - } - - var al = arguments.length; - var handler; - - if (this._all && this._all.length) { - handler = this._all.slice(); - - for (i = 0, l = handler.length; i < l; i++) { - this.event = type; - switch (al) { - case 1: - handler[i].call(this, type); - break; - case 2: - handler[i].call(this, type, arguments$1[1]); - break; - case 3: - handler[i].call(this, type, arguments$1[1], arguments$1[2]); - break; - default: - handler[i].apply(this, arguments$1); - } - } - } - - if (wildcard) { - handler = []; - searchListenerTree.call(this, handler, ns, this.listenerTree, 0, l); - } else { - handler = this._events[type]; - if (typeof handler === 'function') { - this.event = type; - switch (al) { - case 1: - handler.call(this); - break; - case 2: - handler.call(this, arguments[1]); - break; - case 3: - handler.call(this, arguments[1], arguments[2]); - break; - default: - args = new Array(al - 1); - for (j = 1; j < al; j++) { args[j - 1] = arguments$1[j]; } - handler.apply(this, args); - } - return true; - } else if (handler) { - // need to make copy of handlers because list can change in the middle - // of emit call - handler = handler.slice(); - } - } - - if (handler && handler.length) { - if (al > 3) { - args = new Array(al - 1); - for (j = 1; j < al; j++) { args[j - 1] = arguments$1[j]; } - } - for (i = 0, l = handler.length; i < l; i++) { - this.event = type; - switch (al) { - case 1: - handler[i].call(this); - break; - case 2: - handler[i].call(this, arguments$1[1]); - break; - case 3: - handler[i].call(this, arguments$1[1], arguments$1[2]); - break; - default: - handler[i].apply(this, args); - } - } - return true; - } else if (!this.ignoreErrors && !this._all && type === 'error') { - if (arguments[1] instanceof Error) { - throw arguments[1]; // Unhandled 'error' event - } else { - throw new Error("Uncaught, unspecified 'error' event."); - } - } - - return !!this._all; - }; - - EventEmitter.prototype.emitAsync = function() { - var arguments$1 = arguments; - - if (!this._events && !this._all) { - return false; - } - - this._events || init.call(this); - - var type = arguments[0], wildcard= this.wildcard, ns, containsSymbol; - var args,l,i,j; - - if (type === 'newListener' && !this._newListener) { - if (!this._events.newListener) { return Promise.resolve([false]); } - } - - if (wildcard) { - ns= type; - if(type!=='newListener' && type!=='removeListener'){ - if (typeof type === 'object') { - l = type.length; - if (symbolsSupported) { - for (i = 0; i < l; i++) { - if (typeof type[i] === 'symbol') { - containsSymbol = true; - break; - } - } - } - if (!containsSymbol) { - type = type.join(this.delimiter); - } - } - } - } - - var promises= []; - - var al = arguments.length; - var handler; - - if (this._all) { - for (i = 0, l = this._all.length; i < l; i++) { - this.event = type; - switch (al) { - case 1: - promises.push(this._all[i].call(this, type)); - break; - case 2: - promises.push(this._all[i].call(this, type, arguments$1[1])); - break; - case 3: - promises.push(this._all[i].call(this, type, arguments$1[1], arguments$1[2])); - break; - default: - promises.push(this._all[i].apply(this, arguments$1)); - } - } - } - - if (wildcard) { - handler = []; - searchListenerTree.call(this, handler, ns, this.listenerTree, 0); - } else { - handler = this._events[type]; - } - - if (typeof handler === 'function') { - this.event = type; - switch (al) { - case 1: - promises.push(handler.call(this)); - break; - case 2: - promises.push(handler.call(this, arguments[1])); - break; - case 3: - promises.push(handler.call(this, arguments[1], arguments[2])); - break; - default: - args = new Array(al - 1); - for (j = 1; j < al; j++) { args[j - 1] = arguments$1[j]; } - promises.push(handler.apply(this, args)); - } - } else if (handler && handler.length) { - handler = handler.slice(); - if (al > 3) { - args = new Array(al - 1); - for (j = 1; j < al; j++) { args[j - 1] = arguments$1[j]; } - } - for (i = 0, l = handler.length; i < l; i++) { - this.event = type; - switch (al) { - case 1: - promises.push(handler[i].call(this)); - break; - case 2: - promises.push(handler[i].call(this, arguments$1[1])); - break; - case 3: - promises.push(handler[i].call(this, arguments$1[1], arguments$1[2])); - break; - default: - promises.push(handler[i].apply(this, args)); - } - } - } else if (!this.ignoreErrors && !this._all && type === 'error') { - if (arguments[1] instanceof Error) { - return Promise.reject(arguments[1]); // Unhandled 'error' event - } else { - return Promise.reject("Uncaught, unspecified 'error' event."); - } - } - - return Promise.all(promises); - }; - - EventEmitter.prototype.on = function(type, listener, options) { - return this._on(type, listener, false, options); - }; - - EventEmitter.prototype.prependListener = function(type, listener, options) { - return this._on(type, listener, true, options); - }; - - EventEmitter.prototype.onAny = function(fn) { - return this._onAny(fn, false); - }; - - EventEmitter.prototype.prependAny = function(fn) { - return this._onAny(fn, true); - }; - - EventEmitter.prototype.addListener = EventEmitter.prototype.on; - - EventEmitter.prototype._onAny = function(fn, prepend){ - if (typeof fn !== 'function') { - throw new Error('onAny only accepts instances of Function'); - } - - if (!this._all) { - this._all = []; - } - - // Add the function to the event listener collection. - if(prepend){ - this._all.unshift(fn); - }else { - this._all.push(fn); - } - - return this; - }; - - EventEmitter.prototype._on = function(type, listener, prepend, options) { - if (typeof type === 'function') { - this._onAny(type, listener); - return this; - } - - if (typeof listener !== 'function') { - throw new Error('on only accepts instances of Function'); - } - this._events || init.call(this); - - var returnValue= this, temp; - - if (options !== undefined$1) { - temp = setupListener.call(this, type, listener, options); - listener = temp[0]; - returnValue = temp[1]; - } - - // To avoid recursion in the case that type == "newListeners"! Before - // adding it to the listeners, first emit "newListeners". - if (this._newListener) { - this.emit('newListener', type, listener); - } - - if (this.wildcard) { - growListenerTree.call(this, type, listener, prepend); - return returnValue; - } - - if (!this._events[type]) { - // Optimize the case of one listener. Don't need the extra array object. - this._events[type] = listener; - } else { - if (typeof this._events[type] === 'function') { - // Change to array. - this._events[type] = [this._events[type]]; - } - - // If we've already got an array, just add - if(prepend){ - this._events[type].unshift(listener); - }else { - this._events[type].push(listener); - } - - // Check for listener leak - if ( - !this._events[type].warned && - this._maxListeners > 0 && - this._events[type].length > this._maxListeners - ) { - this._events[type].warned = true; - logPossibleMemoryLeak.call(this, this._events[type].length, type); - } - } - - return returnValue; - }; - - EventEmitter.prototype.off = function(type, listener) { - if (typeof listener !== 'function') { - throw new Error('removeListener only takes instances of Function'); - } - - var handlers,leafs=[]; - - if(this.wildcard) { - var ns = typeof type === 'string' ? type.split(this.delimiter) : type.slice(); - leafs = searchListenerTree.call(this, null, ns, this.listenerTree, 0); - if(!leafs) { return this; } - } else { - // does not use listeners(), so no side effect of creating _events[type] - if (!this._events[type]) { return this; } - handlers = this._events[type]; - leafs.push({_listeners:handlers}); - } - - for (var iLeaf=0; iLeaf 0) { - fns = this._all; - for(i = 0, l = fns.length; i < l; i++) { - if(fn === fns[i]) { - fns.splice(i, 1); - if (this._removeListener) - { this.emit("removeListenerAny", fn); } - return this; - } - } - } else { - fns = this._all; - if (this._removeListener) { - for(i = 0, l = fns.length; i < l; i++) - { this.emit("removeListenerAny", fns[i]); } - } - this._all = []; - } - return this; - }; - - EventEmitter.prototype.removeListener = EventEmitter.prototype.off; - - EventEmitter.prototype.removeAllListeners = function (type) { - if (type === undefined$1) { - !this._events || init.call(this); - return this; - } - - if (this.wildcard) { - var leafs = searchListenerTree.call(this, null, type, this.listenerTree, 0), leaf, i; - if (!leafs) { return this; } - for (i = 0; i < leafs.length; i++) { - leaf = leafs[i]; - leaf._listeners = null; - } - this.listenerTree && recursivelyGarbageCollect(this.listenerTree); - } else if (this._events) { - this._events[type] = null; - } - return this; - }; - - EventEmitter.prototype.listeners = function (type) { - var _events = this._events; - var keys, listeners, allListeners; - var i; - var listenerTree; - - if (type === undefined$1) { - if (this.wildcard) { - throw Error('event name required for wildcard emitter'); - } - - if (!_events) { - return []; - } - - keys = ownKeys(_events); - i = keys.length; - allListeners = []; - while (i-- > 0) { - listeners = _events[keys[i]]; - if (typeof listeners === 'function') { - allListeners.push(listeners); - } else { - allListeners.push.apply(allListeners, listeners); - } - } - return allListeners; - } else { - if (this.wildcard) { - listenerTree= this.listenerTree; - if(!listenerTree) { return []; } - var handlers = []; - var ns = typeof type === 'string' ? type.split(this.delimiter) : type.slice(); - searchListenerTree.call(this, handlers, ns, listenerTree, 0); - return handlers; - } - - if (!_events) { - return []; - } - - listeners = _events[type]; - - if (!listeners) { - return []; - } - return typeof listeners === 'function' ? [listeners] : listeners; - } - }; - - EventEmitter.prototype.eventNames = function(nsAsArray){ - var _events= this._events; - return this.wildcard? collectTreeEvents.call(this, this.listenerTree, [], null, nsAsArray) : (_events? ownKeys(_events) : []); - }; - - EventEmitter.prototype.listenerCount = function(type) { - return this.listeners(type).length; - }; - - EventEmitter.prototype.hasListeners = function (type) { - if (this.wildcard) { - var handlers = []; - var ns = typeof type === 'string' ? type.split(this.delimiter) : type.slice(); - searchListenerTree.call(this, handlers, ns, this.listenerTree, 0); - return handlers.length > 0; - } - - var _events = this._events; - var _all = this._all; - - return !!(_all && _all.length || _events && (type === undefined$1 ? ownKeys(_events).length : _events[type])); - }; - - EventEmitter.prototype.listenersAny = function() { - - if(this._all) { - return this._all; - } - else { - return []; - } - - }; - - EventEmitter.prototype.waitFor = function (event, options) { - var self = this; - var type = typeof options; - if (type === 'number') { - options = {timeout: options}; - } else if (type === 'function') { - options = {filter: options}; - } - - options= resolveOptions(options, { - timeout: 0, - filter: undefined$1, - handleError: false, - Promise: Promise, - overload: false - }, { - filter: functionReducer, - Promise: constructorReducer - }); - - return makeCancelablePromise(options.Promise, function (resolve, reject, onCancel) { - function listener() { - var filter= options.filter; - if (filter && !filter.apply(self, arguments)) { - return; - } - self.off(event, listener); - if (options.handleError) { - var err = arguments[0]; - err ? reject(err) : resolve(toArray.apply(null, arguments).slice(1)); - } else { - resolve(toArray.apply(null, arguments)); - } - } - - onCancel(function(){ - self.off(event, listener); - }); - - self._on(event, listener, false); - }, { - timeout: options.timeout, - overload: options.overload - }) - }; - - function once(emitter, name, options) { - options= resolveOptions(options, { - Promise: Promise, - timeout: 0, - overload: false - }, { - Promise: constructorReducer - }); - - var _Promise= options.Promise; - - return makeCancelablePromise(_Promise, function(resolve, reject, onCancel){ - var handler; - if (typeof emitter.addEventListener === 'function') { - handler= function () { - resolve(toArray.apply(null, arguments)); - }; - - onCancel(function(){ - emitter.removeEventListener(name, handler); - }); - - emitter.addEventListener( - name, - handler, - {once: true} - ); - return; - } - - var eventListener = function(){ - errorListener && emitter.removeListener('error', errorListener); - resolve(toArray.apply(null, arguments)); - }; - - var errorListener; - - if (name !== 'error') { - errorListener = function (err){ - emitter.removeListener(name, eventListener); - reject(err); - }; - - emitter.once('error', errorListener); - } - - onCancel(function(){ - errorListener && emitter.removeListener('error', errorListener); - emitter.removeListener(name, eventListener); - }); - - emitter.once(name, eventListener); - }, { - timeout: options.timeout, - overload: options.overload - }); - } - - var prototype= EventEmitter.prototype; - - Object.defineProperties(EventEmitter, { - defaultMaxListeners: { - get: function () { - return prototype._maxListeners; - }, - set: function (n) { - if (typeof n !== 'number' || n < 0 || Number.isNaN(n)) { - throw TypeError('n must be a non-negative number') - } - prototype._maxListeners = n; - }, - enumerable: true - }, - once: { - value: once, - writable: true, - configurable: true - } - }); - - Object.defineProperties(prototype, { - _maxListeners: { - value: defaultMaxListeners, - writable: true, - configurable: true - }, - _observers: {value: null, writable: true, configurable: true} - }); - - if (typeof undefined$1 === 'function' && undefined$1.amd) { - // AMD. Register as an anonymous module. - undefined$1(function() { - return EventEmitter; - }); - } else { - // CommonJS - module.exports = EventEmitter; - } - }(); -} (eventemitter2, eventemitter2.exports)); - -var eventemitter2Exports = eventemitter2.exports; + var hasOwnProperty= Object.hasOwnProperty; + var isArray = Array.isArray ? Array.isArray : function _isArray(obj) { + return Object.prototype.toString.call(obj) === "[object Array]"; + }; + var defaultMaxListeners = 10; + var nextTickSupported= typeof process=='object' && typeof process.nextTick=='function'; + var symbolsSupported= typeof Symbol==='function'; + var reflectSupported= typeof Reflect === 'object'; + var setImmediateSupported= typeof setImmediate === 'function'; + var _setImmediate= setImmediateSupported ? setImmediate : setTimeout; + var ownKeys= symbolsSupported? (reflectSupported && typeof Reflect.ownKeys==='function'? Reflect.ownKeys : function(obj){ + var arr= Object.getOwnPropertyNames(obj); + arr.push.apply(arr, Object.getOwnPropertySymbols(obj)); + return arr; + }) : Object.keys; + + function init() { + this._events = {}; + if (this._conf) { + configure.call(this, this._conf); + } + } + + function configure(conf) { + if (conf) { + this._conf = conf; + + conf.delimiter && (this.delimiter = conf.delimiter); + + if(conf.maxListeners!==undefined$1){ + this._maxListeners= conf.maxListeners; + } + + conf.wildcard && (this.wildcard = conf.wildcard); + conf.newListener && (this._newListener = conf.newListener); + conf.removeListener && (this._removeListener = conf.removeListener); + conf.verboseMemoryLeak && (this.verboseMemoryLeak = conf.verboseMemoryLeak); + conf.ignoreErrors && (this.ignoreErrors = conf.ignoreErrors); + + if (this.wildcard) { + this.listenerTree = {}; + } + } + } + + function logPossibleMemoryLeak(count, eventName) { + var errorMsg = '(node) warning: possible EventEmitter memory ' + + 'leak detected. ' + count + ' listeners added. ' + + 'Use emitter.setMaxListeners() to increase limit.'; + + if(this.verboseMemoryLeak){ + errorMsg += ' Event name: ' + eventName + '.'; + } + + if(typeof process !== 'undefined' && process.emitWarning){ + var e = new Error(errorMsg); + e.name = 'MaxListenersExceededWarning'; + e.emitter = this; + e.count = count; + process.emitWarning(e); + } else { + console.error(errorMsg); + + if (console.trace){ + console.trace(); + } + } + } + + var toArray = function (a, b, c) { + var arguments$1 = arguments; + + var n = arguments.length; + switch (n) { + case 0: + return []; + case 1: + return [a]; + case 2: + return [a, b]; + case 3: + return [a, b, c]; + default: + var arr = new Array(n); + while (n--) { + arr[n] = arguments$1[n]; + } + return arr; + } + }; + + function toObject(keys, values) { + var obj = {}; + var key; + var len = keys.length; + var valuesCount = values ? value.length : 0; + for (var i = 0; i < len; i++) { + key = keys[i]; + obj[key] = i < valuesCount ? values[i] : undefined$1; + } + return obj; + } + + function TargetObserver(emitter, target, options) { + this._emitter = emitter; + this._target = target; + this._listeners = {}; + this._listenersCount = 0; + + var on, off; + + if (options.on || options.off) { + on = options.on; + off = options.off; + } + + if (target.addEventListener) { + on = target.addEventListener; + off = target.removeEventListener; + } else if (target.addListener) { + on = target.addListener; + off = target.removeListener; + } else if (target.on) { + on = target.on; + off = target.off; + } + + if (!on && !off) { + throw Error('target does not implement any known event API'); + } + + if (typeof on !== 'function') { + throw TypeError('on method must be a function'); + } + + if (typeof off !== 'function') { + throw TypeError('off method must be a function'); + } + + this._on = on; + this._off = off; + + var _observers= emitter._observers; + if(_observers){ + _observers.push(this); + }else { + emitter._observers= [this]; + } + } + + Object.assign(TargetObserver.prototype, { + subscribe: function(event, localEvent, reducer){ + var observer= this; + var target= this._target; + var emitter= this._emitter; + var listeners= this._listeners; + var handler= function(){ + var args= toArray.apply(null, arguments); + var eventObj= { + data: args, + name: localEvent, + original: event + }; + if(reducer){ + var result= reducer.call(target, eventObj); + if(result!==false){ + emitter.emit.apply(emitter, [eventObj.name].concat(args)); + } + return; + } + emitter.emit.apply(emitter, [localEvent].concat(args)); + }; + + + if(listeners[event]){ + throw Error('Event \'' + event + '\' is already listening'); + } + + this._listenersCount++; + + if(emitter._newListener && emitter._removeListener && !observer._onNewListener){ + + this._onNewListener = function (_event) { + if (_event === localEvent && listeners[event] === null) { + listeners[event] = handler; + observer._on.call(target, event, handler); + } + }; + + emitter.on('newListener', this._onNewListener); + + this._onRemoveListener= function(_event){ + if(_event === localEvent && !emitter.hasListeners(_event) && listeners[event]){ + listeners[event]= null; + observer._off.call(target, event, handler); + } + }; + + listeners[event]= null; + + emitter.on('removeListener', this._onRemoveListener); + }else { + listeners[event]= handler; + observer._on.call(target, event, handler); + } + }, + + unsubscribe: function(event){ + var observer= this; + var listeners= this._listeners; + var emitter= this._emitter; + var handler; + var events; + var off= this._off; + var target= this._target; + var i; + + if(event && typeof event!=='string'){ + throw TypeError('event must be a string'); + } + + function clearRefs(){ + if(observer._onNewListener){ + emitter.off('newListener', observer._onNewListener); + emitter.off('removeListener', observer._onRemoveListener); + observer._onNewListener= null; + observer._onRemoveListener= null; + } + var index= findTargetIndex.call(emitter, observer); + emitter._observers.splice(index, 1); + } + + if(event){ + handler= listeners[event]; + if(!handler) { return; } + off.call(target, event, handler); + delete listeners[event]; + if(!--this._listenersCount){ + clearRefs(); + } + }else { + events= ownKeys(listeners); + i= events.length; + while(i-->0){ + event= events[i]; + off.call(target, event, listeners[event]); + } + this._listeners= {}; + this._listenersCount= 0; + clearRefs(); + } + } + }); + + function resolveOptions(options, schema, reducers, allowUnknown) { + var computedOptions = Object.assign({}, schema); + + if (!options) { return computedOptions; } + + if (typeof options !== 'object') { + throw TypeError('options must be an object') + } + + var keys = Object.keys(options); + var length = keys.length; + var option, value; + var reducer; + + function reject(reason) { + throw Error('Invalid "' + option + '" option value' + (reason ? '. Reason: ' + reason : '')) + } + + for (var i = 0; i < length; i++) { + option = keys[i]; + if (!allowUnknown && !hasOwnProperty.call(schema, option)) { + throw Error('Unknown "' + option + '" option'); + } + value = options[option]; + if (value !== undefined$1) { + reducer = reducers[option]; + computedOptions[option] = reducer ? reducer(value, reject) : value; + } + } + return computedOptions; + } + + function constructorReducer(value, reject) { + if (typeof value !== 'function' || !value.hasOwnProperty('prototype')) { + reject('value must be a constructor'); + } + return value; + } + + function makeTypeReducer(types) { + var message= 'value must be type of ' + types.join('|'); + var len= types.length; + var firstType= types[0]; + var secondType= types[1]; + + if (len === 1) { + return function (v, reject) { + if (typeof v === firstType) { + return v; + } + reject(message); + } + } + + if (len === 2) { + return function (v, reject) { + var kind= typeof v; + if (kind === firstType || kind === secondType) { return v; } + reject(message); + } + } + + return function (v, reject) { + var kind = typeof v; + var i = len; + while (i-- > 0) { + if (kind === types[i]) { return v; } + } + reject(message); + } + } + + var functionReducer= makeTypeReducer(['function']); + + var objectFunctionReducer= makeTypeReducer(['object', 'function']); + + function makeCancelablePromise(Promise, executor, options) { + var isCancelable; + var callbacks; + var timer= 0; + var subscriptionClosed; + + var promise = new Promise(function (resolve, reject, onCancel) { + options= resolveOptions(options, { + timeout: 0, + overload: false + }, { + timeout: function(value, reject){ + value*= 1; + if (typeof value !== 'number' || value < 0 || !Number.isFinite(value)) { + reject('timeout must be a positive number'); + } + return value; + } + }); + + isCancelable = !options.overload && typeof Promise.prototype.cancel === 'function' && typeof onCancel === 'function'; + + function cleanup() { + if (callbacks) { + callbacks = null; + } + if (timer) { + clearTimeout(timer); + timer = 0; + } + } + + var _resolve= function(value){ + cleanup(); + resolve(value); + }; + + var _reject= function(err){ + cleanup(); + reject(err); + }; + + if (isCancelable) { + executor(_resolve, _reject, onCancel); + } else { + callbacks = [function(reason){ + _reject(reason || Error('canceled')); + }]; + executor(_resolve, _reject, function (cb) { + if (subscriptionClosed) { + throw Error('Unable to subscribe on cancel event asynchronously') + } + if (typeof cb !== 'function') { + throw TypeError('onCancel callback must be a function'); + } + callbacks.push(cb); + }); + subscriptionClosed= true; + } + + if (options.timeout > 0) { + timer= setTimeout(function(){ + var reason= Error('timeout'); + reason.code = 'ETIMEDOUT'; + timer= 0; + promise.cancel(reason); + reject(reason); + }, options.timeout); + } + }); + + if (!isCancelable) { + promise.cancel = function (reason) { + if (!callbacks) { + return; + } + var length = callbacks.length; + for (var i = 1; i < length; i++) { + callbacks[i](reason); + } + // internal callback to reject the promise + callbacks[0](reason); + callbacks = null; + }; + } + + return promise; + } + + function findTargetIndex(observer) { + var observers = this._observers; + if(!observers){ + return -1; + } + var len = observers.length; + for (var i = 0; i < len; i++) { + if (observers[i]._target === observer) { return i; } + } + return -1; + } + + // Attention, function return type now is array, always ! + // It has zero elements if no any matches found and one or more + // elements (leafs) if there are matches + // + function searchListenerTree(handlers, type, tree, i, typeLength) { + if (!tree) { + return null; + } + + if (i === 0) { + var kind = typeof type; + if (kind === 'string') { + var ns, n, l = 0, j = 0, delimiter = this.delimiter, dl = delimiter.length; + if ((n = type.indexOf(delimiter)) !== -1) { + ns = new Array(5); + do { + ns[l++] = type.slice(j, n); + j = n + dl; + } while ((n = type.indexOf(delimiter, j)) !== -1); + + ns[l++] = type.slice(j); + type = ns; + typeLength = l; + } else { + type = [type]; + typeLength = 1; + } + } else if (kind === 'object') { + typeLength = type.length; + } else { + type = [type]; + typeLength = 1; + } + } + + var listeners= null, branch, xTree, xxTree, isolatedBranch, endReached, currentType = type[i], + nextType = type[i + 1], branches, _listeners; + + if (i === typeLength) { + // + // If at the end of the event(s) list and the tree has listeners + // invoke those listeners. + // + + if(tree._listeners) { + if (typeof tree._listeners === 'function') { + handlers && handlers.push(tree._listeners); + listeners = [tree]; + } else { + handlers && handlers.push.apply(handlers, tree._listeners); + listeners = [tree]; + } + } + } else { + + if (currentType === '*') { + // + // If the event emitted is '*' at this part + // or there is a concrete match at this patch + // + branches = ownKeys(tree); + n = branches.length; + while (n-- > 0) { + branch = branches[n]; + if (branch !== '_listeners') { + _listeners = searchListenerTree(handlers, type, tree[branch], i + 1, typeLength); + if (_listeners) { + if (listeners) { + listeners.push.apply(listeners, _listeners); + } else { + listeners = _listeners; + } + } + } + } + return listeners; + } else if (currentType === '**') { + endReached = (i + 1 === typeLength || (i + 2 === typeLength && nextType === '*')); + if (endReached && tree._listeners) { + // The next element has a _listeners, add it to the handlers. + listeners = searchListenerTree(handlers, type, tree, typeLength, typeLength); + } + + branches = ownKeys(tree); + n = branches.length; + while (n-- > 0) { + branch = branches[n]; + if (branch !== '_listeners') { + if (branch === '*' || branch === '**') { + if (tree[branch]._listeners && !endReached) { + _listeners = searchListenerTree(handlers, type, tree[branch], typeLength, typeLength); + if (_listeners) { + if (listeners) { + listeners.push.apply(listeners, _listeners); + } else { + listeners = _listeners; + } + } + } + _listeners = searchListenerTree(handlers, type, tree[branch], i, typeLength); + } else if (branch === nextType) { + _listeners = searchListenerTree(handlers, type, tree[branch], i + 2, typeLength); + } else { + // No match on this one, shift into the tree but not in the type array. + _listeners = searchListenerTree(handlers, type, tree[branch], i, typeLength); + } + if (_listeners) { + if (listeners) { + listeners.push.apply(listeners, _listeners); + } else { + listeners = _listeners; + } + } + } + } + return listeners; + } else if (tree[currentType]) { + listeners = searchListenerTree(handlers, type, tree[currentType], i + 1, typeLength); + } + } + + xTree = tree['*']; + if (xTree) { + // + // If the listener tree will allow any match for this part, + // then recursively explore all branches of the tree + // + searchListenerTree(handlers, type, xTree, i + 1, typeLength); + } + + xxTree = tree['**']; + if (xxTree) { + if (i < typeLength) { + if (xxTree._listeners) { + // If we have a listener on a '**', it will catch all, so add its handler. + searchListenerTree(handlers, type, xxTree, typeLength, typeLength); + } + + // Build arrays of matching next branches and others. + branches= ownKeys(xxTree); + n= branches.length; + while(n-->0){ + branch= branches[n]; + if (branch !== '_listeners') { + if (branch === nextType) { + // We know the next element will match, so jump twice. + searchListenerTree(handlers, type, xxTree[branch], i + 2, typeLength); + } else if (branch === currentType) { + // Current node matches, move into the tree. + searchListenerTree(handlers, type, xxTree[branch], i + 1, typeLength); + } else { + isolatedBranch = {}; + isolatedBranch[branch] = xxTree[branch]; + searchListenerTree(handlers, type, {'**': isolatedBranch}, i + 1, typeLength); + } + } + } + } else if (xxTree._listeners) { + // We have reached the end and still on a '**' + searchListenerTree(handlers, type, xxTree, typeLength, typeLength); + } else if (xxTree['*'] && xxTree['*']._listeners) { + searchListenerTree(handlers, type, xxTree['*'], typeLength, typeLength); + } + } + + return listeners; + } + + function growListenerTree(type, listener, prepend) { + var len = 0, j = 0, i, delimiter = this.delimiter, dl= delimiter.length, ns; + + if(typeof type==='string') { + if ((i = type.indexOf(delimiter)) !== -1) { + ns = new Array(5); + do { + ns[len++] = type.slice(j, i); + j = i + dl; + } while ((i = type.indexOf(delimiter, j)) !== -1); + + ns[len++] = type.slice(j); + }else { + ns= [type]; + len= 1; + } + }else { + ns= type; + len= type.length; + } + + // + // Looks for two consecutive '**', if so, don't add the event at all. + // + if (len > 1) { + for (i = 0; i + 1 < len; i++) { + if (ns[i] === '**' && ns[i + 1] === '**') { + return; + } + } + } + + + + var tree = this.listenerTree, name; + + for (i = 0; i < len; i++) { + name = ns[i]; + + tree = tree[name] || (tree[name] = {}); + + if (i === len - 1) { + if (!tree._listeners) { + tree._listeners = listener; + } else { + if (typeof tree._listeners === 'function') { + tree._listeners = [tree._listeners]; + } + + if (prepend) { + tree._listeners.unshift(listener); + } else { + tree._listeners.push(listener); + } + + if ( + !tree._listeners.warned && + this._maxListeners > 0 && + tree._listeners.length > this._maxListeners + ) { + tree._listeners.warned = true; + logPossibleMemoryLeak.call(this, tree._listeners.length, name); + } + } + return true; + } + } + + return true; + } + + function collectTreeEvents(tree, events, root, asArray){ + var branches= ownKeys(tree); + var i= branches.length; + var branch, branchName, path; + var hasListeners= tree['_listeners']; + var isArrayPath; + + while(i-->0){ + branchName= branches[i]; + + branch= tree[branchName]; + + if(branchName==='_listeners'){ + path= root; + }else { + path = root ? root.concat(branchName) : [branchName]; + } + + isArrayPath= asArray || typeof branchName==='symbol'; + + hasListeners && events.push(isArrayPath? path : path.join(this.delimiter)); + + if(typeof branch==='object'){ + collectTreeEvents.call(this, branch, events, path, isArrayPath); + } + } + + return events; + } + + function recursivelyGarbageCollect(root) { + var keys = ownKeys(root); + var i= keys.length; + var obj, key, flag; + while(i-->0){ + key = keys[i]; + obj = root[key]; + + if(obj){ + flag= true; + if(key !== '_listeners' && !recursivelyGarbageCollect(obj)){ + delete root[key]; + } + } + } + + return flag; + } + + function Listener(emitter, event, listener){ + this.emitter= emitter; + this.event= event; + this.listener= listener; + } + + Listener.prototype.off= function(){ + this.emitter.off(this.event, this.listener); + return this; + }; + + function setupListener(event, listener, options){ + if (options === true) { + promisify = true; + } else if (options === false) { + async = true; + } else { + if (!options || typeof options !== 'object') { + throw TypeError('options should be an object or true'); + } + var async = options.async; + var promisify = options.promisify; + var nextTick = options.nextTick; + var objectify = options.objectify; + } + + if (async || nextTick || promisify) { + var _listener = listener; + var _origin = listener._origin || listener; + + if (nextTick && !nextTickSupported) { + throw Error('process.nextTick is not supported'); + } + + if (promisify === undefined$1) { + promisify = listener.constructor.name === 'AsyncFunction'; + } + + listener = function () { + var args = arguments; + var context = this; + var event = this.event; + + return promisify ? (nextTick ? Promise.resolve() : new Promise(function (resolve) { + _setImmediate(resolve); + }).then(function () { + context.event = event; + return _listener.apply(context, args) + })) : (nextTick ? process.nextTick : _setImmediate)(function () { + context.event = event; + _listener.apply(context, args); + }); + }; + + listener._async = true; + listener._origin = _origin; + } + + return [listener, objectify? new Listener(this, event, listener): this]; + } + + function EventEmitter(conf) { + this._events = {}; + this._newListener = false; + this._removeListener = false; + this.verboseMemoryLeak = false; + configure.call(this, conf); + } + + EventEmitter.EventEmitter2 = EventEmitter; // backwards compatibility for exporting EventEmitter property + + EventEmitter.prototype.listenTo= function(target, events, options){ + if(typeof target!=='object'){ + throw TypeError('target musts be an object'); + } + + var emitter= this; + + options = resolveOptions(options, { + on: undefined$1, + off: undefined$1, + reducers: undefined$1 + }, { + on: functionReducer, + off: functionReducer, + reducers: objectFunctionReducer + }); + + function listen(events){ + if(typeof events!=='object'){ + throw TypeError('events must be an object'); + } + + var reducers= options.reducers; + var index= findTargetIndex.call(emitter, target); + var observer; + + if(index===-1){ + observer= new TargetObserver(emitter, target, options); + }else { + observer= emitter._observers[index]; + } + + var keys= ownKeys(events); + var len= keys.length; + var event; + var isSingleReducer= typeof reducers==='function'; + + for(var i=0; i 0) { + observer = observers[i]; + if (!target || observer._target === target) { + observer.unsubscribe(event); + matched= true; + } + } + + return matched; + }; + + // By default EventEmitters will print a warning if more than + // 10 listeners are added to it. This is a useful default which + // helps finding memory leaks. + // + // Obviously not all Emitters should be limited to 10. This function allows + // that to be increased. Set to zero for unlimited. + + EventEmitter.prototype.delimiter = '.'; + + EventEmitter.prototype.setMaxListeners = function(n) { + if (n !== undefined$1) { + this._maxListeners = n; + if (!this._conf) { this._conf = {}; } + this._conf.maxListeners = n; + } + }; + + EventEmitter.prototype.getMaxListeners = function() { + return this._maxListeners; + }; + + EventEmitter.prototype.event = ''; + + EventEmitter.prototype.once = function(event, fn, options) { + return this._once(event, fn, false, options); + }; + + EventEmitter.prototype.prependOnceListener = function(event, fn, options) { + return this._once(event, fn, true, options); + }; + + EventEmitter.prototype._once = function(event, fn, prepend, options) { + return this._many(event, 1, fn, prepend, options); + }; + + EventEmitter.prototype.many = function(event, ttl, fn, options) { + return this._many(event, ttl, fn, false, options); + }; + + EventEmitter.prototype.prependMany = function(event, ttl, fn, options) { + return this._many(event, ttl, fn, true, options); + }; + + EventEmitter.prototype._many = function(event, ttl, fn, prepend, options) { + var self = this; + + if (typeof fn !== 'function') { + throw new Error('many only accepts instances of Function'); + } + + function listener() { + if (--ttl === 0) { + self.off(event, listener); + } + return fn.apply(this, arguments); + } + + listener._origin = fn; + + return this._on(event, listener, prepend, options); + }; + + EventEmitter.prototype.emit = function() { + var arguments$1 = arguments; + + if (!this._events && !this._all) { + return false; + } + + this._events || init.call(this); + + var type = arguments[0], ns, wildcard= this.wildcard; + var args,l,i,j, containsSymbol; + + if (type === 'newListener' && !this._newListener) { + if (!this._events.newListener) { + return false; + } + } + + if (wildcard) { + ns= type; + if(type!=='newListener' && type!=='removeListener'){ + if (typeof type === 'object') { + l = type.length; + if (symbolsSupported) { + for (i = 0; i < l; i++) { + if (typeof type[i] === 'symbol') { + containsSymbol = true; + break; + } + } + } + if (!containsSymbol) { + type = type.join(this.delimiter); + } + } + } + } + + var al = arguments.length; + var handler; + + if (this._all && this._all.length) { + handler = this._all.slice(); + + for (i = 0, l = handler.length; i < l; i++) { + this.event = type; + switch (al) { + case 1: + handler[i].call(this, type); + break; + case 2: + handler[i].call(this, type, arguments$1[1]); + break; + case 3: + handler[i].call(this, type, arguments$1[1], arguments$1[2]); + break; + default: + handler[i].apply(this, arguments$1); + } + } + } + + if (wildcard) { + handler = []; + searchListenerTree.call(this, handler, ns, this.listenerTree, 0, l); + } else { + handler = this._events[type]; + if (typeof handler === 'function') { + this.event = type; + switch (al) { + case 1: + handler.call(this); + break; + case 2: + handler.call(this, arguments[1]); + break; + case 3: + handler.call(this, arguments[1], arguments[2]); + break; + default: + args = new Array(al - 1); + for (j = 1; j < al; j++) { args[j - 1] = arguments$1[j]; } + handler.apply(this, args); + } + return true; + } else if (handler) { + // need to make copy of handlers because list can change in the middle + // of emit call + handler = handler.slice(); + } + } + + if (handler && handler.length) { + if (al > 3) { + args = new Array(al - 1); + for (j = 1; j < al; j++) { args[j - 1] = arguments$1[j]; } + } + for (i = 0, l = handler.length; i < l; i++) { + this.event = type; + switch (al) { + case 1: + handler[i].call(this); + break; + case 2: + handler[i].call(this, arguments$1[1]); + break; + case 3: + handler[i].call(this, arguments$1[1], arguments$1[2]); + break; + default: + handler[i].apply(this, args); + } + } + return true; + } else if (!this.ignoreErrors && !this._all && type === 'error') { + if (arguments[1] instanceof Error) { + throw arguments[1]; // Unhandled 'error' event + } else { + throw new Error("Uncaught, unspecified 'error' event."); + } + } + + return !!this._all; + }; + + EventEmitter.prototype.emitAsync = function() { + var arguments$1 = arguments; + + if (!this._events && !this._all) { + return false; + } + + this._events || init.call(this); + + var type = arguments[0], wildcard= this.wildcard, ns, containsSymbol; + var args,l,i,j; + + if (type === 'newListener' && !this._newListener) { + if (!this._events.newListener) { return Promise.resolve([false]); } + } + + if (wildcard) { + ns= type; + if(type!=='newListener' && type!=='removeListener'){ + if (typeof type === 'object') { + l = type.length; + if (symbolsSupported) { + for (i = 0; i < l; i++) { + if (typeof type[i] === 'symbol') { + containsSymbol = true; + break; + } + } + } + if (!containsSymbol) { + type = type.join(this.delimiter); + } + } + } + } + + var promises= []; + + var al = arguments.length; + var handler; + + if (this._all) { + for (i = 0, l = this._all.length; i < l; i++) { + this.event = type; + switch (al) { + case 1: + promises.push(this._all[i].call(this, type)); + break; + case 2: + promises.push(this._all[i].call(this, type, arguments$1[1])); + break; + case 3: + promises.push(this._all[i].call(this, type, arguments$1[1], arguments$1[2])); + break; + default: + promises.push(this._all[i].apply(this, arguments$1)); + } + } + } + + if (wildcard) { + handler = []; + searchListenerTree.call(this, handler, ns, this.listenerTree, 0); + } else { + handler = this._events[type]; + } + + if (typeof handler === 'function') { + this.event = type; + switch (al) { + case 1: + promises.push(handler.call(this)); + break; + case 2: + promises.push(handler.call(this, arguments[1])); + break; + case 3: + promises.push(handler.call(this, arguments[1], arguments[2])); + break; + default: + args = new Array(al - 1); + for (j = 1; j < al; j++) { args[j - 1] = arguments$1[j]; } + promises.push(handler.apply(this, args)); + } + } else if (handler && handler.length) { + handler = handler.slice(); + if (al > 3) { + args = new Array(al - 1); + for (j = 1; j < al; j++) { args[j - 1] = arguments$1[j]; } + } + for (i = 0, l = handler.length; i < l; i++) { + this.event = type; + switch (al) { + case 1: + promises.push(handler[i].call(this)); + break; + case 2: + promises.push(handler[i].call(this, arguments$1[1])); + break; + case 3: + promises.push(handler[i].call(this, arguments$1[1], arguments$1[2])); + break; + default: + promises.push(handler[i].apply(this, args)); + } + } + } else if (!this.ignoreErrors && !this._all && type === 'error') { + if (arguments[1] instanceof Error) { + return Promise.reject(arguments[1]); // Unhandled 'error' event + } else { + return Promise.reject("Uncaught, unspecified 'error' event."); + } + } + + return Promise.all(promises); + }; + + EventEmitter.prototype.on = function(type, listener, options) { + return this._on(type, listener, false, options); + }; + + EventEmitter.prototype.prependListener = function(type, listener, options) { + return this._on(type, listener, true, options); + }; + + EventEmitter.prototype.onAny = function(fn) { + return this._onAny(fn, false); + }; + + EventEmitter.prototype.prependAny = function(fn) { + return this._onAny(fn, true); + }; + + EventEmitter.prototype.addListener = EventEmitter.prototype.on; + + EventEmitter.prototype._onAny = function(fn, prepend){ + if (typeof fn !== 'function') { + throw new Error('onAny only accepts instances of Function'); + } + + if (!this._all) { + this._all = []; + } + + // Add the function to the event listener collection. + if(prepend){ + this._all.unshift(fn); + }else { + this._all.push(fn); + } + + return this; + }; + + EventEmitter.prototype._on = function(type, listener, prepend, options) { + if (typeof type === 'function') { + this._onAny(type, listener); + return this; + } + + if (typeof listener !== 'function') { + throw new Error('on only accepts instances of Function'); + } + this._events || init.call(this); + + var returnValue= this, temp; + + if (options !== undefined$1) { + temp = setupListener.call(this, type, listener, options); + listener = temp[0]; + returnValue = temp[1]; + } + + // To avoid recursion in the case that type == "newListeners"! Before + // adding it to the listeners, first emit "newListeners". + if (this._newListener) { + this.emit('newListener', type, listener); + } + + if (this.wildcard) { + growListenerTree.call(this, type, listener, prepend); + return returnValue; + } + + if (!this._events[type]) { + // Optimize the case of one listener. Don't need the extra array object. + this._events[type] = listener; + } else { + if (typeof this._events[type] === 'function') { + // Change to array. + this._events[type] = [this._events[type]]; + } + + // If we've already got an array, just add + if(prepend){ + this._events[type].unshift(listener); + }else { + this._events[type].push(listener); + } + + // Check for listener leak + if ( + !this._events[type].warned && + this._maxListeners > 0 && + this._events[type].length > this._maxListeners + ) { + this._events[type].warned = true; + logPossibleMemoryLeak.call(this, this._events[type].length, type); + } + } + + return returnValue; + }; + + EventEmitter.prototype.off = function(type, listener) { + if (typeof listener !== 'function') { + throw new Error('removeListener only takes instances of Function'); + } + + var handlers,leafs=[]; + + if(this.wildcard) { + var ns = typeof type === 'string' ? type.split(this.delimiter) : type.slice(); + leafs = searchListenerTree.call(this, null, ns, this.listenerTree, 0); + if(!leafs) { return this; } + } else { + // does not use listeners(), so no side effect of creating _events[type] + if (!this._events[type]) { return this; } + handlers = this._events[type]; + leafs.push({_listeners:handlers}); + } + + for (var iLeaf=0; iLeaf 0) { + fns = this._all; + for(i = 0, l = fns.length; i < l; i++) { + if(fn === fns[i]) { + fns.splice(i, 1); + if (this._removeListener) + { this.emit("removeListenerAny", fn); } + return this; + } + } + } else { + fns = this._all; + if (this._removeListener) { + for(i = 0, l = fns.length; i < l; i++) + { this.emit("removeListenerAny", fns[i]); } + } + this._all = []; + } + return this; + }; + + EventEmitter.prototype.removeListener = EventEmitter.prototype.off; + + EventEmitter.prototype.removeAllListeners = function (type) { + if (type === undefined$1) { + !this._events || init.call(this); + return this; + } + + if (this.wildcard) { + var leafs = searchListenerTree.call(this, null, type, this.listenerTree, 0), leaf, i; + if (!leafs) { return this; } + for (i = 0; i < leafs.length; i++) { + leaf = leafs[i]; + leaf._listeners = null; + } + this.listenerTree && recursivelyGarbageCollect(this.listenerTree); + } else if (this._events) { + this._events[type] = null; + } + return this; + }; + + EventEmitter.prototype.listeners = function (type) { + var _events = this._events; + var keys, listeners, allListeners; + var i; + var listenerTree; + + if (type === undefined$1) { + if (this.wildcard) { + throw Error('event name required for wildcard emitter'); + } + + if (!_events) { + return []; + } + + keys = ownKeys(_events); + i = keys.length; + allListeners = []; + while (i-- > 0) { + listeners = _events[keys[i]]; + if (typeof listeners === 'function') { + allListeners.push(listeners); + } else { + allListeners.push.apply(allListeners, listeners); + } + } + return allListeners; + } else { + if (this.wildcard) { + listenerTree= this.listenerTree; + if(!listenerTree) { return []; } + var handlers = []; + var ns = typeof type === 'string' ? type.split(this.delimiter) : type.slice(); + searchListenerTree.call(this, handlers, ns, listenerTree, 0); + return handlers; + } + + if (!_events) { + return []; + } + + listeners = _events[type]; + + if (!listeners) { + return []; + } + return typeof listeners === 'function' ? [listeners] : listeners; + } + }; + + EventEmitter.prototype.eventNames = function(nsAsArray){ + var _events= this._events; + return this.wildcard? collectTreeEvents.call(this, this.listenerTree, [], null, nsAsArray) : (_events? ownKeys(_events) : []); + }; + + EventEmitter.prototype.listenerCount = function(type) { + return this.listeners(type).length; + }; + + EventEmitter.prototype.hasListeners = function (type) { + if (this.wildcard) { + var handlers = []; + var ns = typeof type === 'string' ? type.split(this.delimiter) : type.slice(); + searchListenerTree.call(this, handlers, ns, this.listenerTree, 0); + return handlers.length > 0; + } + + var _events = this._events; + var _all = this._all; + + return !!(_all && _all.length || _events && (type === undefined$1 ? ownKeys(_events).length : _events[type])); + }; + + EventEmitter.prototype.listenersAny = function() { + + if(this._all) { + return this._all; + } + else { + return []; + } + + }; + + EventEmitter.prototype.waitFor = function (event, options) { + var self = this; + var type = typeof options; + if (type === 'number') { + options = {timeout: options}; + } else if (type === 'function') { + options = {filter: options}; + } + + options= resolveOptions(options, { + timeout: 0, + filter: undefined$1, + handleError: false, + Promise: Promise, + overload: false + }, { + filter: functionReducer, + Promise: constructorReducer + }); + + return makeCancelablePromise(options.Promise, function (resolve, reject, onCancel) { + function listener() { + var filter= options.filter; + if (filter && !filter.apply(self, arguments)) { + return; + } + self.off(event, listener); + if (options.handleError) { + var err = arguments[0]; + err ? reject(err) : resolve(toArray.apply(null, arguments).slice(1)); + } else { + resolve(toArray.apply(null, arguments)); + } + } + + onCancel(function(){ + self.off(event, listener); + }); + + self._on(event, listener, false); + }, { + timeout: options.timeout, + overload: options.overload + }) + }; + + function once(emitter, name, options) { + options= resolveOptions(options, { + Promise: Promise, + timeout: 0, + overload: false + }, { + Promise: constructorReducer + }); + + var _Promise= options.Promise; + + return makeCancelablePromise(_Promise, function(resolve, reject, onCancel){ + var handler; + if (typeof emitter.addEventListener === 'function') { + handler= function () { + resolve(toArray.apply(null, arguments)); + }; + + onCancel(function(){ + emitter.removeEventListener(name, handler); + }); + + emitter.addEventListener( + name, + handler, + {once: true} + ); + return; + } + + var eventListener = function(){ + errorListener && emitter.removeListener('error', errorListener); + resolve(toArray.apply(null, arguments)); + }; + + var errorListener; + + if (name !== 'error') { + errorListener = function (err){ + emitter.removeListener(name, eventListener); + reject(err); + }; + + emitter.once('error', errorListener); + } + + onCancel(function(){ + errorListener && emitter.removeListener('error', errorListener); + emitter.removeListener(name, eventListener); + }); + + emitter.once(name, eventListener); + }, { + timeout: options.timeout, + overload: options.overload + }); + } + + var prototype= EventEmitter.prototype; + + Object.defineProperties(EventEmitter, { + defaultMaxListeners: { + get: function () { + return prototype._maxListeners; + }, + set: function (n) { + if (typeof n !== 'number' || n < 0 || Number.isNaN(n)) { + throw TypeError('n must be a non-negative number') + } + prototype._maxListeners = n; + }, + enumerable: true + }, + once: { + value: once, + writable: true, + configurable: true + } + }); + + Object.defineProperties(prototype, { + _maxListeners: { + value: defaultMaxListeners, + writable: true, + configurable: true + }, + _observers: {value: null, writable: true, configurable: true} + }); + + if (typeof undefined$1 === 'function' && undefined$1.amd) { + // AMD. Register as an anonymous module. + undefined$1(function() { + return EventEmitter; + }); + } else { + // CommonJS + module.exports = EventEmitter; + } + }(); + } (eventemitter2, eventemitter2.exports)); + return eventemitter2.exports; +} + +var eventemitter2Exports = requireEventemitter2(); var EventEmitter2 = /*@__PURE__*/getDefaultExportFromCjs(eventemitter2Exports); /** diff --git a/build/ros3d.js b/build/ros3d.js index 33229259..81e8c5bf 100644 --- a/build/ros3d.js +++ b/build/ros3d.js @@ -53329,1627 +53329,1634 @@ var ROS3D = (function (exports, ROSLIB) { */ eventemitter2.exports; - (function (module, exports) { + var hasRequiredEventemitter2; + + function requireEventemitter2 () { + if (hasRequiredEventemitter2) return eventemitter2.exports; + hasRequiredEventemitter2 = 1; + (function (module, exports) { !function(undefined$1) { - var hasOwnProperty= Object.hasOwnProperty; - var isArray = Array.isArray ? Array.isArray : function _isArray(obj) { - return Object.prototype.toString.call(obj) === "[object Array]"; - }; - var defaultMaxListeners = 10; - var nextTickSupported= typeof process=='object' && typeof process.nextTick=='function'; - var symbolsSupported= typeof Symbol==='function'; - var reflectSupported= typeof Reflect === 'object'; - var setImmediateSupported= typeof setImmediate === 'function'; - var _setImmediate= setImmediateSupported ? setImmediate : setTimeout; - var ownKeys= symbolsSupported? (reflectSupported && typeof Reflect.ownKeys==='function'? Reflect.ownKeys : function(obj){ - var arr= Object.getOwnPropertyNames(obj); - arr.push.apply(arr, Object.getOwnPropertySymbols(obj)); - return arr; - }) : Object.keys; - - function init() { - this._events = {}; - if (this._conf) { - configure.call(this, this._conf); - } - } - - function configure(conf) { - if (conf) { - this._conf = conf; - - conf.delimiter && (this.delimiter = conf.delimiter); - - if(conf.maxListeners!==undefined$1){ - this._maxListeners= conf.maxListeners; - } - - conf.wildcard && (this.wildcard = conf.wildcard); - conf.newListener && (this._newListener = conf.newListener); - conf.removeListener && (this._removeListener = conf.removeListener); - conf.verboseMemoryLeak && (this.verboseMemoryLeak = conf.verboseMemoryLeak); - conf.ignoreErrors && (this.ignoreErrors = conf.ignoreErrors); - - if (this.wildcard) { - this.listenerTree = {}; - } - } - } - - function logPossibleMemoryLeak(count, eventName) { - var errorMsg = '(node) warning: possible EventEmitter memory ' + - 'leak detected. ' + count + ' listeners added. ' + - 'Use emitter.setMaxListeners() to increase limit.'; - - if(this.verboseMemoryLeak){ - errorMsg += ' Event name: ' + eventName + '.'; - } - - if(typeof process !== 'undefined' && process.emitWarning){ - var e = new Error(errorMsg); - e.name = 'MaxListenersExceededWarning'; - e.emitter = this; - e.count = count; - process.emitWarning(e); - } else { - console.error(errorMsg); - - if (console.trace){ - console.trace(); - } - } - } - - var toArray = function (a, b, c) { - var n = arguments.length; - switch (n) { - case 0: - return []; - case 1: - return [a]; - case 2: - return [a, b]; - case 3: - return [a, b, c]; - default: - var arr = new Array(n); - while (n--) { - arr[n] = arguments[n]; - } - return arr; - } - }; - - function toObject(keys, values) { - var obj = {}; - var key; - var len = keys.length; - var valuesCount = values ? value.length : 0; - for (var i = 0; i < len; i++) { - key = keys[i]; - obj[key] = i < valuesCount ? values[i] : undefined$1; - } - return obj; - } - - function TargetObserver(emitter, target, options) { - this._emitter = emitter; - this._target = target; - this._listeners = {}; - this._listenersCount = 0; - - var on, off; - - if (options.on || options.off) { - on = options.on; - off = options.off; - } - - if (target.addEventListener) { - on = target.addEventListener; - off = target.removeEventListener; - } else if (target.addListener) { - on = target.addListener; - off = target.removeListener; - } else if (target.on) { - on = target.on; - off = target.off; - } - - if (!on && !off) { - throw Error('target does not implement any known event API'); - } - - if (typeof on !== 'function') { - throw TypeError('on method must be a function'); - } - - if (typeof off !== 'function') { - throw TypeError('off method must be a function'); - } - - this._on = on; - this._off = off; - - var _observers= emitter._observers; - if(_observers){ - _observers.push(this); - }else { - emitter._observers= [this]; - } - } - - Object.assign(TargetObserver.prototype, { - subscribe: function(event, localEvent, reducer){ - var observer= this; - var target= this._target; - var emitter= this._emitter; - var listeners= this._listeners; - var handler= function(){ - var args= toArray.apply(null, arguments); - var eventObj= { - data: args, - name: localEvent, - original: event - }; - if(reducer){ - var result= reducer.call(target, eventObj); - if(result!==false){ - emitter.emit.apply(emitter, [eventObj.name].concat(args)); - } - return; - } - emitter.emit.apply(emitter, [localEvent].concat(args)); - }; - - - if(listeners[event]){ - throw Error('Event \'' + event + '\' is already listening'); - } - - this._listenersCount++; - - if(emitter._newListener && emitter._removeListener && !observer._onNewListener){ - - this._onNewListener = function (_event) { - if (_event === localEvent && listeners[event] === null) { - listeners[event] = handler; - observer._on.call(target, event, handler); - } - }; - - emitter.on('newListener', this._onNewListener); - - this._onRemoveListener= function(_event){ - if(_event === localEvent && !emitter.hasListeners(_event) && listeners[event]){ - listeners[event]= null; - observer._off.call(target, event, handler); - } - }; - - listeners[event]= null; - - emitter.on('removeListener', this._onRemoveListener); - }else { - listeners[event]= handler; - observer._on.call(target, event, handler); - } - }, - - unsubscribe: function(event){ - var observer= this; - var listeners= this._listeners; - var emitter= this._emitter; - var handler; - var events; - var off= this._off; - var target= this._target; - var i; - - if(event && typeof event!=='string'){ - throw TypeError('event must be a string'); - } - - function clearRefs(){ - if(observer._onNewListener){ - emitter.off('newListener', observer._onNewListener); - emitter.off('removeListener', observer._onRemoveListener); - observer._onNewListener= null; - observer._onRemoveListener= null; - } - var index= findTargetIndex.call(emitter, observer); - emitter._observers.splice(index, 1); - } - - if(event){ - handler= listeners[event]; - if(!handler) return; - off.call(target, event, handler); - delete listeners[event]; - if(!--this._listenersCount){ - clearRefs(); - } - }else { - events= ownKeys(listeners); - i= events.length; - while(i-->0){ - event= events[i]; - off.call(target, event, listeners[event]); - } - this._listeners= {}; - this._listenersCount= 0; - clearRefs(); - } - } - }); - - function resolveOptions(options, schema, reducers, allowUnknown) { - var computedOptions = Object.assign({}, schema); - - if (!options) return computedOptions; - - if (typeof options !== 'object') { - throw TypeError('options must be an object') - } - - var keys = Object.keys(options); - var length = keys.length; - var option, value; - var reducer; - - function reject(reason) { - throw Error('Invalid "' + option + '" option value' + (reason ? '. Reason: ' + reason : '')) - } - - for (var i = 0; i < length; i++) { - option = keys[i]; - if (!allowUnknown && !hasOwnProperty.call(schema, option)) { - throw Error('Unknown "' + option + '" option'); - } - value = options[option]; - if (value !== undefined$1) { - reducer = reducers[option]; - computedOptions[option] = reducer ? reducer(value, reject) : value; - } - } - return computedOptions; - } - - function constructorReducer(value, reject) { - if (typeof value !== 'function' || !value.hasOwnProperty('prototype')) { - reject('value must be a constructor'); - } - return value; - } - - function makeTypeReducer(types) { - var message= 'value must be type of ' + types.join('|'); - var len= types.length; - var firstType= types[0]; - var secondType= types[1]; - - if (len === 1) { - return function (v, reject) { - if (typeof v === firstType) { - return v; - } - reject(message); - } - } - - if (len === 2) { - return function (v, reject) { - var kind= typeof v; - if (kind === firstType || kind === secondType) return v; - reject(message); - } - } - - return function (v, reject) { - var kind = typeof v; - var i = len; - while (i-- > 0) { - if (kind === types[i]) return v; - } - reject(message); - } - } - - var functionReducer= makeTypeReducer(['function']); - - var objectFunctionReducer= makeTypeReducer(['object', 'function']); - - function makeCancelablePromise(Promise, executor, options) { - var isCancelable; - var callbacks; - var timer= 0; - var subscriptionClosed; - - var promise = new Promise(function (resolve, reject, onCancel) { - options= resolveOptions(options, { - timeout: 0, - overload: false - }, { - timeout: function(value, reject){ - value*= 1; - if (typeof value !== 'number' || value < 0 || !Number.isFinite(value)) { - reject('timeout must be a positive number'); - } - return value; - } - }); - - isCancelable = !options.overload && typeof Promise.prototype.cancel === 'function' && typeof onCancel === 'function'; - - function cleanup() { - if (callbacks) { - callbacks = null; - } - if (timer) { - clearTimeout(timer); - timer = 0; - } - } - - var _resolve= function(value){ - cleanup(); - resolve(value); - }; - - var _reject= function(err){ - cleanup(); - reject(err); - }; - - if (isCancelable) { - executor(_resolve, _reject, onCancel); - } else { - callbacks = [function(reason){ - _reject(reason || Error('canceled')); - }]; - executor(_resolve, _reject, function (cb) { - if (subscriptionClosed) { - throw Error('Unable to subscribe on cancel event asynchronously') - } - if (typeof cb !== 'function') { - throw TypeError('onCancel callback must be a function'); - } - callbacks.push(cb); - }); - subscriptionClosed= true; - } - - if (options.timeout > 0) { - timer= setTimeout(function(){ - var reason= Error('timeout'); - reason.code = 'ETIMEDOUT'; - timer= 0; - promise.cancel(reason); - reject(reason); - }, options.timeout); - } - }); - - if (!isCancelable) { - promise.cancel = function (reason) { - if (!callbacks) { - return; - } - var length = callbacks.length; - for (var i = 1; i < length; i++) { - callbacks[i](reason); - } - // internal callback to reject the promise - callbacks[0](reason); - callbacks = null; - }; - } - - return promise; - } - - function findTargetIndex(observer) { - var observers = this._observers; - if(!observers){ - return -1; - } - var len = observers.length; - for (var i = 0; i < len; i++) { - if (observers[i]._target === observer) return i; - } - return -1; - } - - // Attention, function return type now is array, always ! - // It has zero elements if no any matches found and one or more - // elements (leafs) if there are matches - // - function searchListenerTree(handlers, type, tree, i, typeLength) { - if (!tree) { - return null; - } - - if (i === 0) { - var kind = typeof type; - if (kind === 'string') { - var ns, n, l = 0, j = 0, delimiter = this.delimiter, dl = delimiter.length; - if ((n = type.indexOf(delimiter)) !== -1) { - ns = new Array(5); - do { - ns[l++] = type.slice(j, n); - j = n + dl; - } while ((n = type.indexOf(delimiter, j)) !== -1); - - ns[l++] = type.slice(j); - type = ns; - typeLength = l; - } else { - type = [type]; - typeLength = 1; - } - } else if (kind === 'object') { - typeLength = type.length; - } else { - type = [type]; - typeLength = 1; - } - } - - var listeners= null, branch, xTree, xxTree, isolatedBranch, endReached, currentType = type[i], - nextType = type[i + 1], branches, _listeners; - - if (i === typeLength) { - // - // If at the end of the event(s) list and the tree has listeners - // invoke those listeners. - // - - if(tree._listeners) { - if (typeof tree._listeners === 'function') { - handlers && handlers.push(tree._listeners); - listeners = [tree]; - } else { - handlers && handlers.push.apply(handlers, tree._listeners); - listeners = [tree]; - } - } - } else { - - if (currentType === '*') { - // - // If the event emitted is '*' at this part - // or there is a concrete match at this patch - // - branches = ownKeys(tree); - n = branches.length; - while (n-- > 0) { - branch = branches[n]; - if (branch !== '_listeners') { - _listeners = searchListenerTree(handlers, type, tree[branch], i + 1, typeLength); - if (_listeners) { - if (listeners) { - listeners.push.apply(listeners, _listeners); - } else { - listeners = _listeners; - } - } - } - } - return listeners; - } else if (currentType === '**') { - endReached = (i + 1 === typeLength || (i + 2 === typeLength && nextType === '*')); - if (endReached && tree._listeners) { - // The next element has a _listeners, add it to the handlers. - listeners = searchListenerTree(handlers, type, tree, typeLength, typeLength); - } - - branches = ownKeys(tree); - n = branches.length; - while (n-- > 0) { - branch = branches[n]; - if (branch !== '_listeners') { - if (branch === '*' || branch === '**') { - if (tree[branch]._listeners && !endReached) { - _listeners = searchListenerTree(handlers, type, tree[branch], typeLength, typeLength); - if (_listeners) { - if (listeners) { - listeners.push.apply(listeners, _listeners); - } else { - listeners = _listeners; - } - } - } - _listeners = searchListenerTree(handlers, type, tree[branch], i, typeLength); - } else if (branch === nextType) { - _listeners = searchListenerTree(handlers, type, tree[branch], i + 2, typeLength); - } else { - // No match on this one, shift into the tree but not in the type array. - _listeners = searchListenerTree(handlers, type, tree[branch], i, typeLength); - } - if (_listeners) { - if (listeners) { - listeners.push.apply(listeners, _listeners); - } else { - listeners = _listeners; - } - } - } - } - return listeners; - } else if (tree[currentType]) { - listeners = searchListenerTree(handlers, type, tree[currentType], i + 1, typeLength); - } - } - - xTree = tree['*']; - if (xTree) { - // - // If the listener tree will allow any match for this part, - // then recursively explore all branches of the tree - // - searchListenerTree(handlers, type, xTree, i + 1, typeLength); - } - - xxTree = tree['**']; - if (xxTree) { - if (i < typeLength) { - if (xxTree._listeners) { - // If we have a listener on a '**', it will catch all, so add its handler. - searchListenerTree(handlers, type, xxTree, typeLength, typeLength); - } - - // Build arrays of matching next branches and others. - branches= ownKeys(xxTree); - n= branches.length; - while(n-->0){ - branch= branches[n]; - if (branch !== '_listeners') { - if (branch === nextType) { - // We know the next element will match, so jump twice. - searchListenerTree(handlers, type, xxTree[branch], i + 2, typeLength); - } else if (branch === currentType) { - // Current node matches, move into the tree. - searchListenerTree(handlers, type, xxTree[branch], i + 1, typeLength); - } else { - isolatedBranch = {}; - isolatedBranch[branch] = xxTree[branch]; - searchListenerTree(handlers, type, {'**': isolatedBranch}, i + 1, typeLength); - } - } - } - } else if (xxTree._listeners) { - // We have reached the end and still on a '**' - searchListenerTree(handlers, type, xxTree, typeLength, typeLength); - } else if (xxTree['*'] && xxTree['*']._listeners) { - searchListenerTree(handlers, type, xxTree['*'], typeLength, typeLength); - } - } - - return listeners; - } - - function growListenerTree(type, listener, prepend) { - var len = 0, j = 0, i, delimiter = this.delimiter, dl= delimiter.length, ns; - - if(typeof type==='string') { - if ((i = type.indexOf(delimiter)) !== -1) { - ns = new Array(5); - do { - ns[len++] = type.slice(j, i); - j = i + dl; - } while ((i = type.indexOf(delimiter, j)) !== -1); - - ns[len++] = type.slice(j); - }else { - ns= [type]; - len= 1; - } - }else { - ns= type; - len= type.length; - } - - // - // Looks for two consecutive '**', if so, don't add the event at all. - // - if (len > 1) { - for (i = 0; i + 1 < len; i++) { - if (ns[i] === '**' && ns[i + 1] === '**') { - return; - } - } - } - - - - var tree = this.listenerTree, name; - - for (i = 0; i < len; i++) { - name = ns[i]; - - tree = tree[name] || (tree[name] = {}); - - if (i === len - 1) { - if (!tree._listeners) { - tree._listeners = listener; - } else { - if (typeof tree._listeners === 'function') { - tree._listeners = [tree._listeners]; - } - - if (prepend) { - tree._listeners.unshift(listener); - } else { - tree._listeners.push(listener); - } - - if ( - !tree._listeners.warned && - this._maxListeners > 0 && - tree._listeners.length > this._maxListeners - ) { - tree._listeners.warned = true; - logPossibleMemoryLeak.call(this, tree._listeners.length, name); - } - } - return true; - } - } - - return true; - } - - function collectTreeEvents(tree, events, root, asArray){ - var branches= ownKeys(tree); - var i= branches.length; - var branch, branchName, path; - var hasListeners= tree['_listeners']; - var isArrayPath; - - while(i-->0){ - branchName= branches[i]; - - branch= tree[branchName]; - - if(branchName==='_listeners'){ - path= root; - }else { - path = root ? root.concat(branchName) : [branchName]; - } - - isArrayPath= asArray || typeof branchName==='symbol'; - - hasListeners && events.push(isArrayPath? path : path.join(this.delimiter)); - - if(typeof branch==='object'){ - collectTreeEvents.call(this, branch, events, path, isArrayPath); - } - } - - return events; - } - - function recursivelyGarbageCollect(root) { - var keys = ownKeys(root); - var i= keys.length; - var obj, key, flag; - while(i-->0){ - key = keys[i]; - obj = root[key]; - - if(obj){ - flag= true; - if(key !== '_listeners' && !recursivelyGarbageCollect(obj)){ - delete root[key]; - } - } - } - - return flag; - } - - function Listener(emitter, event, listener){ - this.emitter= emitter; - this.event= event; - this.listener= listener; - } - - Listener.prototype.off= function(){ - this.emitter.off(this.event, this.listener); - return this; - }; - - function setupListener(event, listener, options){ - if (options === true) { - promisify = true; - } else if (options === false) { - async = true; - } else { - if (!options || typeof options !== 'object') { - throw TypeError('options should be an object or true'); - } - var async = options.async; - var promisify = options.promisify; - var nextTick = options.nextTick; - var objectify = options.objectify; - } - - if (async || nextTick || promisify) { - var _listener = listener; - var _origin = listener._origin || listener; - - if (nextTick && !nextTickSupported) { - throw Error('process.nextTick is not supported'); - } - - if (promisify === undefined$1) { - promisify = listener.constructor.name === 'AsyncFunction'; - } - - listener = function () { - var args = arguments; - var context = this; - var event = this.event; - - return promisify ? (nextTick ? Promise.resolve() : new Promise(function (resolve) { - _setImmediate(resolve); - }).then(function () { - context.event = event; - return _listener.apply(context, args) - })) : (nextTick ? process.nextTick : _setImmediate)(function () { - context.event = event; - _listener.apply(context, args); - }); - }; - - listener._async = true; - listener._origin = _origin; - } - - return [listener, objectify? new Listener(this, event, listener): this]; - } - - function EventEmitter(conf) { - this._events = {}; - this._newListener = false; - this._removeListener = false; - this.verboseMemoryLeak = false; - configure.call(this, conf); - } - - EventEmitter.EventEmitter2 = EventEmitter; // backwards compatibility for exporting EventEmitter property - - EventEmitter.prototype.listenTo= function(target, events, options){ - if(typeof target!=='object'){ - throw TypeError('target musts be an object'); - } - - var emitter= this; - - options = resolveOptions(options, { - on: undefined$1, - off: undefined$1, - reducers: undefined$1 - }, { - on: functionReducer, - off: functionReducer, - reducers: objectFunctionReducer - }); - - function listen(events){ - if(typeof events!=='object'){ - throw TypeError('events must be an object'); - } - - var reducers= options.reducers; - var index= findTargetIndex.call(emitter, target); - var observer; - - if(index===-1){ - observer= new TargetObserver(emitter, target, options); - }else { - observer= emitter._observers[index]; - } - - var keys= ownKeys(events); - var len= keys.length; - var event; - var isSingleReducer= typeof reducers==='function'; - - for(var i=0; i 0) { - observer = observers[i]; - if (!target || observer._target === target) { - observer.unsubscribe(event); - matched= true; - } - } - - return matched; - }; - - // By default EventEmitters will print a warning if more than - // 10 listeners are added to it. This is a useful default which - // helps finding memory leaks. - // - // Obviously not all Emitters should be limited to 10. This function allows - // that to be increased. Set to zero for unlimited. - - EventEmitter.prototype.delimiter = '.'; - - EventEmitter.prototype.setMaxListeners = function(n) { - if (n !== undefined$1) { - this._maxListeners = n; - if (!this._conf) this._conf = {}; - this._conf.maxListeners = n; - } - }; - - EventEmitter.prototype.getMaxListeners = function() { - return this._maxListeners; - }; - - EventEmitter.prototype.event = ''; - - EventEmitter.prototype.once = function(event, fn, options) { - return this._once(event, fn, false, options); - }; - - EventEmitter.prototype.prependOnceListener = function(event, fn, options) { - return this._once(event, fn, true, options); - }; - - EventEmitter.prototype._once = function(event, fn, prepend, options) { - return this._many(event, 1, fn, prepend, options); - }; - - EventEmitter.prototype.many = function(event, ttl, fn, options) { - return this._many(event, ttl, fn, false, options); - }; - - EventEmitter.prototype.prependMany = function(event, ttl, fn, options) { - return this._many(event, ttl, fn, true, options); - }; - - EventEmitter.prototype._many = function(event, ttl, fn, prepend, options) { - var self = this; - - if (typeof fn !== 'function') { - throw new Error('many only accepts instances of Function'); - } - - function listener() { - if (--ttl === 0) { - self.off(event, listener); - } - return fn.apply(this, arguments); - } - - listener._origin = fn; - - return this._on(event, listener, prepend, options); - }; - - EventEmitter.prototype.emit = function() { - if (!this._events && !this._all) { - return false; - } - - this._events || init.call(this); - - var type = arguments[0], ns, wildcard= this.wildcard; - var args,l,i,j, containsSymbol; - - if (type === 'newListener' && !this._newListener) { - if (!this._events.newListener) { - return false; - } - } - - if (wildcard) { - ns= type; - if(type!=='newListener' && type!=='removeListener'){ - if (typeof type === 'object') { - l = type.length; - if (symbolsSupported) { - for (i = 0; i < l; i++) { - if (typeof type[i] === 'symbol') { - containsSymbol = true; - break; - } - } - } - if (!containsSymbol) { - type = type.join(this.delimiter); - } - } - } - } - - var al = arguments.length; - var handler; - - if (this._all && this._all.length) { - handler = this._all.slice(); - - for (i = 0, l = handler.length; i < l; i++) { - this.event = type; - switch (al) { - case 1: - handler[i].call(this, type); - break; - case 2: - handler[i].call(this, type, arguments[1]); - break; - case 3: - handler[i].call(this, type, arguments[1], arguments[2]); - break; - default: - handler[i].apply(this, arguments); - } - } - } - - if (wildcard) { - handler = []; - searchListenerTree.call(this, handler, ns, this.listenerTree, 0, l); - } else { - handler = this._events[type]; - if (typeof handler === 'function') { - this.event = type; - switch (al) { - case 1: - handler.call(this); - break; - case 2: - handler.call(this, arguments[1]); - break; - case 3: - handler.call(this, arguments[1], arguments[2]); - break; - default: - args = new Array(al - 1); - for (j = 1; j < al; j++) args[j - 1] = arguments[j]; - handler.apply(this, args); - } - return true; - } else if (handler) { - // need to make copy of handlers because list can change in the middle - // of emit call - handler = handler.slice(); - } - } - - if (handler && handler.length) { - if (al > 3) { - args = new Array(al - 1); - for (j = 1; j < al; j++) args[j - 1] = arguments[j]; - } - for (i = 0, l = handler.length; i < l; i++) { - this.event = type; - switch (al) { - case 1: - handler[i].call(this); - break; - case 2: - handler[i].call(this, arguments[1]); - break; - case 3: - handler[i].call(this, arguments[1], arguments[2]); - break; - default: - handler[i].apply(this, args); - } - } - return true; - } else if (!this.ignoreErrors && !this._all && type === 'error') { - if (arguments[1] instanceof Error) { - throw arguments[1]; // Unhandled 'error' event - } else { - throw new Error("Uncaught, unspecified 'error' event."); - } - } - - return !!this._all; - }; - - EventEmitter.prototype.emitAsync = function() { - if (!this._events && !this._all) { - return false; - } - - this._events || init.call(this); - - var type = arguments[0], wildcard= this.wildcard, ns, containsSymbol; - var args,l,i,j; - - if (type === 'newListener' && !this._newListener) { - if (!this._events.newListener) { return Promise.resolve([false]); } - } - - if (wildcard) { - ns= type; - if(type!=='newListener' && type!=='removeListener'){ - if (typeof type === 'object') { - l = type.length; - if (symbolsSupported) { - for (i = 0; i < l; i++) { - if (typeof type[i] === 'symbol') { - containsSymbol = true; - break; - } - } - } - if (!containsSymbol) { - type = type.join(this.delimiter); - } - } - } - } - - var promises= []; - - var al = arguments.length; - var handler; - - if (this._all) { - for (i = 0, l = this._all.length; i < l; i++) { - this.event = type; - switch (al) { - case 1: - promises.push(this._all[i].call(this, type)); - break; - case 2: - promises.push(this._all[i].call(this, type, arguments[1])); - break; - case 3: - promises.push(this._all[i].call(this, type, arguments[1], arguments[2])); - break; - default: - promises.push(this._all[i].apply(this, arguments)); - } - } - } - - if (wildcard) { - handler = []; - searchListenerTree.call(this, handler, ns, this.listenerTree, 0); - } else { - handler = this._events[type]; - } - - if (typeof handler === 'function') { - this.event = type; - switch (al) { - case 1: - promises.push(handler.call(this)); - break; - case 2: - promises.push(handler.call(this, arguments[1])); - break; - case 3: - promises.push(handler.call(this, arguments[1], arguments[2])); - break; - default: - args = new Array(al - 1); - for (j = 1; j < al; j++) args[j - 1] = arguments[j]; - promises.push(handler.apply(this, args)); - } - } else if (handler && handler.length) { - handler = handler.slice(); - if (al > 3) { - args = new Array(al - 1); - for (j = 1; j < al; j++) args[j - 1] = arguments[j]; - } - for (i = 0, l = handler.length; i < l; i++) { - this.event = type; - switch (al) { - case 1: - promises.push(handler[i].call(this)); - break; - case 2: - promises.push(handler[i].call(this, arguments[1])); - break; - case 3: - promises.push(handler[i].call(this, arguments[1], arguments[2])); - break; - default: - promises.push(handler[i].apply(this, args)); - } - } - } else if (!this.ignoreErrors && !this._all && type === 'error') { - if (arguments[1] instanceof Error) { - return Promise.reject(arguments[1]); // Unhandled 'error' event - } else { - return Promise.reject("Uncaught, unspecified 'error' event."); - } - } - - return Promise.all(promises); - }; - - EventEmitter.prototype.on = function(type, listener, options) { - return this._on(type, listener, false, options); - }; - - EventEmitter.prototype.prependListener = function(type, listener, options) { - return this._on(type, listener, true, options); - }; - - EventEmitter.prototype.onAny = function(fn) { - return this._onAny(fn, false); - }; - - EventEmitter.prototype.prependAny = function(fn) { - return this._onAny(fn, true); - }; - - EventEmitter.prototype.addListener = EventEmitter.prototype.on; - - EventEmitter.prototype._onAny = function(fn, prepend){ - if (typeof fn !== 'function') { - throw new Error('onAny only accepts instances of Function'); - } - - if (!this._all) { - this._all = []; - } - - // Add the function to the event listener collection. - if(prepend){ - this._all.unshift(fn); - }else { - this._all.push(fn); - } - - return this; - }; - - EventEmitter.prototype._on = function(type, listener, prepend, options) { - if (typeof type === 'function') { - this._onAny(type, listener); - return this; - } - - if (typeof listener !== 'function') { - throw new Error('on only accepts instances of Function'); - } - this._events || init.call(this); - - var returnValue= this, temp; - - if (options !== undefined$1) { - temp = setupListener.call(this, type, listener, options); - listener = temp[0]; - returnValue = temp[1]; - } - - // To avoid recursion in the case that type == "newListeners"! Before - // adding it to the listeners, first emit "newListeners". - if (this._newListener) { - this.emit('newListener', type, listener); - } - - if (this.wildcard) { - growListenerTree.call(this, type, listener, prepend); - return returnValue; - } - - if (!this._events[type]) { - // Optimize the case of one listener. Don't need the extra array object. - this._events[type] = listener; - } else { - if (typeof this._events[type] === 'function') { - // Change to array. - this._events[type] = [this._events[type]]; - } - - // If we've already got an array, just add - if(prepend){ - this._events[type].unshift(listener); - }else { - this._events[type].push(listener); - } - - // Check for listener leak - if ( - !this._events[type].warned && - this._maxListeners > 0 && - this._events[type].length > this._maxListeners - ) { - this._events[type].warned = true; - logPossibleMemoryLeak.call(this, this._events[type].length, type); - } - } - - return returnValue; - }; - - EventEmitter.prototype.off = function(type, listener) { - if (typeof listener !== 'function') { - throw new Error('removeListener only takes instances of Function'); - } - - var handlers,leafs=[]; - - if(this.wildcard) { - var ns = typeof type === 'string' ? type.split(this.delimiter) : type.slice(); - leafs = searchListenerTree.call(this, null, ns, this.listenerTree, 0); - if(!leafs) return this; - } else { - // does not use listeners(), so no side effect of creating _events[type] - if (!this._events[type]) return this; - handlers = this._events[type]; - leafs.push({_listeners:handlers}); - } - - for (var iLeaf=0; iLeaf 0) { - fns = this._all; - for(i = 0, l = fns.length; i < l; i++) { - if(fn === fns[i]) { - fns.splice(i, 1); - if (this._removeListener) - this.emit("removeListenerAny", fn); - return this; - } - } - } else { - fns = this._all; - if (this._removeListener) { - for(i = 0, l = fns.length; i < l; i++) - this.emit("removeListenerAny", fns[i]); - } - this._all = []; - } - return this; - }; - - EventEmitter.prototype.removeListener = EventEmitter.prototype.off; - - EventEmitter.prototype.removeAllListeners = function (type) { - if (type === undefined$1) { - !this._events || init.call(this); - return this; - } - - if (this.wildcard) { - var leafs = searchListenerTree.call(this, null, type, this.listenerTree, 0), leaf, i; - if (!leafs) return this; - for (i = 0; i < leafs.length; i++) { - leaf = leafs[i]; - leaf._listeners = null; - } - this.listenerTree && recursivelyGarbageCollect(this.listenerTree); - } else if (this._events) { - this._events[type] = null; - } - return this; - }; - - EventEmitter.prototype.listeners = function (type) { - var _events = this._events; - var keys, listeners, allListeners; - var i; - var listenerTree; - - if (type === undefined$1) { - if (this.wildcard) { - throw Error('event name required for wildcard emitter'); - } - - if (!_events) { - return []; - } - - keys = ownKeys(_events); - i = keys.length; - allListeners = []; - while (i-- > 0) { - listeners = _events[keys[i]]; - if (typeof listeners === 'function') { - allListeners.push(listeners); - } else { - allListeners.push.apply(allListeners, listeners); - } - } - return allListeners; - } else { - if (this.wildcard) { - listenerTree= this.listenerTree; - if(!listenerTree) return []; - var handlers = []; - var ns = typeof type === 'string' ? type.split(this.delimiter) : type.slice(); - searchListenerTree.call(this, handlers, ns, listenerTree, 0); - return handlers; - } - - if (!_events) { - return []; - } - - listeners = _events[type]; - - if (!listeners) { - return []; - } - return typeof listeners === 'function' ? [listeners] : listeners; - } - }; - - EventEmitter.prototype.eventNames = function(nsAsArray){ - var _events= this._events; - return this.wildcard? collectTreeEvents.call(this, this.listenerTree, [], null, nsAsArray) : (_events? ownKeys(_events) : []); - }; - - EventEmitter.prototype.listenerCount = function(type) { - return this.listeners(type).length; - }; - - EventEmitter.prototype.hasListeners = function (type) { - if (this.wildcard) { - var handlers = []; - var ns = typeof type === 'string' ? type.split(this.delimiter) : type.slice(); - searchListenerTree.call(this, handlers, ns, this.listenerTree, 0); - return handlers.length > 0; - } - - var _events = this._events; - var _all = this._all; - - return !!(_all && _all.length || _events && (type === undefined$1 ? ownKeys(_events).length : _events[type])); - }; - - EventEmitter.prototype.listenersAny = function() { - - if(this._all) { - return this._all; - } - else { - return []; - } - - }; - - EventEmitter.prototype.waitFor = function (event, options) { - var self = this; - var type = typeof options; - if (type === 'number') { - options = {timeout: options}; - } else if (type === 'function') { - options = {filter: options}; - } - - options= resolveOptions(options, { - timeout: 0, - filter: undefined$1, - handleError: false, - Promise: Promise, - overload: false - }, { - filter: functionReducer, - Promise: constructorReducer - }); - - return makeCancelablePromise(options.Promise, function (resolve, reject, onCancel) { - function listener() { - var filter= options.filter; - if (filter && !filter.apply(self, arguments)) { - return; - } - self.off(event, listener); - if (options.handleError) { - var err = arguments[0]; - err ? reject(err) : resolve(toArray.apply(null, arguments).slice(1)); - } else { - resolve(toArray.apply(null, arguments)); - } - } - - onCancel(function(){ - self.off(event, listener); - }); - - self._on(event, listener, false); - }, { - timeout: options.timeout, - overload: options.overload - }) - }; - - function once(emitter, name, options) { - options= resolveOptions(options, { - Promise: Promise, - timeout: 0, - overload: false - }, { - Promise: constructorReducer - }); - - var _Promise= options.Promise; - - return makeCancelablePromise(_Promise, function(resolve, reject, onCancel){ - var handler; - if (typeof emitter.addEventListener === 'function') { - handler= function () { - resolve(toArray.apply(null, arguments)); - }; - - onCancel(function(){ - emitter.removeEventListener(name, handler); - }); - - emitter.addEventListener( - name, - handler, - {once: true} - ); - return; - } - - var eventListener = function(){ - errorListener && emitter.removeListener('error', errorListener); - resolve(toArray.apply(null, arguments)); - }; - - var errorListener; - - if (name !== 'error') { - errorListener = function (err){ - emitter.removeListener(name, eventListener); - reject(err); - }; - - emitter.once('error', errorListener); - } - - onCancel(function(){ - errorListener && emitter.removeListener('error', errorListener); - emitter.removeListener(name, eventListener); - }); - - emitter.once(name, eventListener); - }, { - timeout: options.timeout, - overload: options.overload - }); - } - - var prototype= EventEmitter.prototype; - - Object.defineProperties(EventEmitter, { - defaultMaxListeners: { - get: function () { - return prototype._maxListeners; - }, - set: function (n) { - if (typeof n !== 'number' || n < 0 || Number.isNaN(n)) { - throw TypeError('n must be a non-negative number') - } - prototype._maxListeners = n; - }, - enumerable: true - }, - once: { - value: once, - writable: true, - configurable: true - } - }); - - Object.defineProperties(prototype, { - _maxListeners: { - value: defaultMaxListeners, - writable: true, - configurable: true - }, - _observers: {value: null, writable: true, configurable: true} - }); - - if (typeof undefined$1 === 'function' && undefined$1.amd) { - // AMD. Register as an anonymous module. - undefined$1(function() { - return EventEmitter; - }); - } else { - // CommonJS - module.exports = EventEmitter; - } - }(); - } (eventemitter2, eventemitter2.exports)); - - var eventemitter2Exports = eventemitter2.exports; + var hasOwnProperty= Object.hasOwnProperty; + var isArray = Array.isArray ? Array.isArray : function _isArray(obj) { + return Object.prototype.toString.call(obj) === "[object Array]"; + }; + var defaultMaxListeners = 10; + var nextTickSupported= typeof process=='object' && typeof process.nextTick=='function'; + var symbolsSupported= typeof Symbol==='function'; + var reflectSupported= typeof Reflect === 'object'; + var setImmediateSupported= typeof setImmediate === 'function'; + var _setImmediate= setImmediateSupported ? setImmediate : setTimeout; + var ownKeys= symbolsSupported? (reflectSupported && typeof Reflect.ownKeys==='function'? Reflect.ownKeys : function(obj){ + var arr= Object.getOwnPropertyNames(obj); + arr.push.apply(arr, Object.getOwnPropertySymbols(obj)); + return arr; + }) : Object.keys; + + function init() { + this._events = {}; + if (this._conf) { + configure.call(this, this._conf); + } + } + + function configure(conf) { + if (conf) { + this._conf = conf; + + conf.delimiter && (this.delimiter = conf.delimiter); + + if(conf.maxListeners!==undefined$1){ + this._maxListeners= conf.maxListeners; + } + + conf.wildcard && (this.wildcard = conf.wildcard); + conf.newListener && (this._newListener = conf.newListener); + conf.removeListener && (this._removeListener = conf.removeListener); + conf.verboseMemoryLeak && (this.verboseMemoryLeak = conf.verboseMemoryLeak); + conf.ignoreErrors && (this.ignoreErrors = conf.ignoreErrors); + + if (this.wildcard) { + this.listenerTree = {}; + } + } + } + + function logPossibleMemoryLeak(count, eventName) { + var errorMsg = '(node) warning: possible EventEmitter memory ' + + 'leak detected. ' + count + ' listeners added. ' + + 'Use emitter.setMaxListeners() to increase limit.'; + + if(this.verboseMemoryLeak){ + errorMsg += ' Event name: ' + eventName + '.'; + } + + if(typeof process !== 'undefined' && process.emitWarning){ + var e = new Error(errorMsg); + e.name = 'MaxListenersExceededWarning'; + e.emitter = this; + e.count = count; + process.emitWarning(e); + } else { + console.error(errorMsg); + + if (console.trace){ + console.trace(); + } + } + } + + var toArray = function (a, b, c) { + var n = arguments.length; + switch (n) { + case 0: + return []; + case 1: + return [a]; + case 2: + return [a, b]; + case 3: + return [a, b, c]; + default: + var arr = new Array(n); + while (n--) { + arr[n] = arguments[n]; + } + return arr; + } + }; + + function toObject(keys, values) { + var obj = {}; + var key; + var len = keys.length; + var valuesCount = values ? value.length : 0; + for (var i = 0; i < len; i++) { + key = keys[i]; + obj[key] = i < valuesCount ? values[i] : undefined$1; + } + return obj; + } + + function TargetObserver(emitter, target, options) { + this._emitter = emitter; + this._target = target; + this._listeners = {}; + this._listenersCount = 0; + + var on, off; + + if (options.on || options.off) { + on = options.on; + off = options.off; + } + + if (target.addEventListener) { + on = target.addEventListener; + off = target.removeEventListener; + } else if (target.addListener) { + on = target.addListener; + off = target.removeListener; + } else if (target.on) { + on = target.on; + off = target.off; + } + + if (!on && !off) { + throw Error('target does not implement any known event API'); + } + + if (typeof on !== 'function') { + throw TypeError('on method must be a function'); + } + + if (typeof off !== 'function') { + throw TypeError('off method must be a function'); + } + + this._on = on; + this._off = off; + + var _observers= emitter._observers; + if(_observers){ + _observers.push(this); + }else { + emitter._observers= [this]; + } + } + + Object.assign(TargetObserver.prototype, { + subscribe: function(event, localEvent, reducer){ + var observer= this; + var target= this._target; + var emitter= this._emitter; + var listeners= this._listeners; + var handler= function(){ + var args= toArray.apply(null, arguments); + var eventObj= { + data: args, + name: localEvent, + original: event + }; + if(reducer){ + var result= reducer.call(target, eventObj); + if(result!==false){ + emitter.emit.apply(emitter, [eventObj.name].concat(args)); + } + return; + } + emitter.emit.apply(emitter, [localEvent].concat(args)); + }; + + + if(listeners[event]){ + throw Error('Event \'' + event + '\' is already listening'); + } + + this._listenersCount++; + + if(emitter._newListener && emitter._removeListener && !observer._onNewListener){ + + this._onNewListener = function (_event) { + if (_event === localEvent && listeners[event] === null) { + listeners[event] = handler; + observer._on.call(target, event, handler); + } + }; + + emitter.on('newListener', this._onNewListener); + + this._onRemoveListener= function(_event){ + if(_event === localEvent && !emitter.hasListeners(_event) && listeners[event]){ + listeners[event]= null; + observer._off.call(target, event, handler); + } + }; + + listeners[event]= null; + + emitter.on('removeListener', this._onRemoveListener); + }else { + listeners[event]= handler; + observer._on.call(target, event, handler); + } + }, + + unsubscribe: function(event){ + var observer= this; + var listeners= this._listeners; + var emitter= this._emitter; + var handler; + var events; + var off= this._off; + var target= this._target; + var i; + + if(event && typeof event!=='string'){ + throw TypeError('event must be a string'); + } + + function clearRefs(){ + if(observer._onNewListener){ + emitter.off('newListener', observer._onNewListener); + emitter.off('removeListener', observer._onRemoveListener); + observer._onNewListener= null; + observer._onRemoveListener= null; + } + var index= findTargetIndex.call(emitter, observer); + emitter._observers.splice(index, 1); + } + + if(event){ + handler= listeners[event]; + if(!handler) return; + off.call(target, event, handler); + delete listeners[event]; + if(!--this._listenersCount){ + clearRefs(); + } + }else { + events= ownKeys(listeners); + i= events.length; + while(i-->0){ + event= events[i]; + off.call(target, event, listeners[event]); + } + this._listeners= {}; + this._listenersCount= 0; + clearRefs(); + } + } + }); + + function resolveOptions(options, schema, reducers, allowUnknown) { + var computedOptions = Object.assign({}, schema); + + if (!options) return computedOptions; + + if (typeof options !== 'object') { + throw TypeError('options must be an object') + } + + var keys = Object.keys(options); + var length = keys.length; + var option, value; + var reducer; + + function reject(reason) { + throw Error('Invalid "' + option + '" option value' + (reason ? '. Reason: ' + reason : '')) + } + + for (var i = 0; i < length; i++) { + option = keys[i]; + if (!allowUnknown && !hasOwnProperty.call(schema, option)) { + throw Error('Unknown "' + option + '" option'); + } + value = options[option]; + if (value !== undefined$1) { + reducer = reducers[option]; + computedOptions[option] = reducer ? reducer(value, reject) : value; + } + } + return computedOptions; + } + + function constructorReducer(value, reject) { + if (typeof value !== 'function' || !value.hasOwnProperty('prototype')) { + reject('value must be a constructor'); + } + return value; + } + + function makeTypeReducer(types) { + var message= 'value must be type of ' + types.join('|'); + var len= types.length; + var firstType= types[0]; + var secondType= types[1]; + + if (len === 1) { + return function (v, reject) { + if (typeof v === firstType) { + return v; + } + reject(message); + } + } + + if (len === 2) { + return function (v, reject) { + var kind= typeof v; + if (kind === firstType || kind === secondType) return v; + reject(message); + } + } + + return function (v, reject) { + var kind = typeof v; + var i = len; + while (i-- > 0) { + if (kind === types[i]) return v; + } + reject(message); + } + } + + var functionReducer= makeTypeReducer(['function']); + + var objectFunctionReducer= makeTypeReducer(['object', 'function']); + + function makeCancelablePromise(Promise, executor, options) { + var isCancelable; + var callbacks; + var timer= 0; + var subscriptionClosed; + + var promise = new Promise(function (resolve, reject, onCancel) { + options= resolveOptions(options, { + timeout: 0, + overload: false + }, { + timeout: function(value, reject){ + value*= 1; + if (typeof value !== 'number' || value < 0 || !Number.isFinite(value)) { + reject('timeout must be a positive number'); + } + return value; + } + }); + + isCancelable = !options.overload && typeof Promise.prototype.cancel === 'function' && typeof onCancel === 'function'; + + function cleanup() { + if (callbacks) { + callbacks = null; + } + if (timer) { + clearTimeout(timer); + timer = 0; + } + } + + var _resolve= function(value){ + cleanup(); + resolve(value); + }; + + var _reject= function(err){ + cleanup(); + reject(err); + }; + + if (isCancelable) { + executor(_resolve, _reject, onCancel); + } else { + callbacks = [function(reason){ + _reject(reason || Error('canceled')); + }]; + executor(_resolve, _reject, function (cb) { + if (subscriptionClosed) { + throw Error('Unable to subscribe on cancel event asynchronously') + } + if (typeof cb !== 'function') { + throw TypeError('onCancel callback must be a function'); + } + callbacks.push(cb); + }); + subscriptionClosed= true; + } + + if (options.timeout > 0) { + timer= setTimeout(function(){ + var reason= Error('timeout'); + reason.code = 'ETIMEDOUT'; + timer= 0; + promise.cancel(reason); + reject(reason); + }, options.timeout); + } + }); + + if (!isCancelable) { + promise.cancel = function (reason) { + if (!callbacks) { + return; + } + var length = callbacks.length; + for (var i = 1; i < length; i++) { + callbacks[i](reason); + } + // internal callback to reject the promise + callbacks[0](reason); + callbacks = null; + }; + } + + return promise; + } + + function findTargetIndex(observer) { + var observers = this._observers; + if(!observers){ + return -1; + } + var len = observers.length; + for (var i = 0; i < len; i++) { + if (observers[i]._target === observer) return i; + } + return -1; + } + + // Attention, function return type now is array, always ! + // It has zero elements if no any matches found and one or more + // elements (leafs) if there are matches + // + function searchListenerTree(handlers, type, tree, i, typeLength) { + if (!tree) { + return null; + } + + if (i === 0) { + var kind = typeof type; + if (kind === 'string') { + var ns, n, l = 0, j = 0, delimiter = this.delimiter, dl = delimiter.length; + if ((n = type.indexOf(delimiter)) !== -1) { + ns = new Array(5); + do { + ns[l++] = type.slice(j, n); + j = n + dl; + } while ((n = type.indexOf(delimiter, j)) !== -1); + + ns[l++] = type.slice(j); + type = ns; + typeLength = l; + } else { + type = [type]; + typeLength = 1; + } + } else if (kind === 'object') { + typeLength = type.length; + } else { + type = [type]; + typeLength = 1; + } + } + + var listeners= null, branch, xTree, xxTree, isolatedBranch, endReached, currentType = type[i], + nextType = type[i + 1], branches, _listeners; + + if (i === typeLength) { + // + // If at the end of the event(s) list and the tree has listeners + // invoke those listeners. + // + + if(tree._listeners) { + if (typeof tree._listeners === 'function') { + handlers && handlers.push(tree._listeners); + listeners = [tree]; + } else { + handlers && handlers.push.apply(handlers, tree._listeners); + listeners = [tree]; + } + } + } else { + + if (currentType === '*') { + // + // If the event emitted is '*' at this part + // or there is a concrete match at this patch + // + branches = ownKeys(tree); + n = branches.length; + while (n-- > 0) { + branch = branches[n]; + if (branch !== '_listeners') { + _listeners = searchListenerTree(handlers, type, tree[branch], i + 1, typeLength); + if (_listeners) { + if (listeners) { + listeners.push.apply(listeners, _listeners); + } else { + listeners = _listeners; + } + } + } + } + return listeners; + } else if (currentType === '**') { + endReached = (i + 1 === typeLength || (i + 2 === typeLength && nextType === '*')); + if (endReached && tree._listeners) { + // The next element has a _listeners, add it to the handlers. + listeners = searchListenerTree(handlers, type, tree, typeLength, typeLength); + } + + branches = ownKeys(tree); + n = branches.length; + while (n-- > 0) { + branch = branches[n]; + if (branch !== '_listeners') { + if (branch === '*' || branch === '**') { + if (tree[branch]._listeners && !endReached) { + _listeners = searchListenerTree(handlers, type, tree[branch], typeLength, typeLength); + if (_listeners) { + if (listeners) { + listeners.push.apply(listeners, _listeners); + } else { + listeners = _listeners; + } + } + } + _listeners = searchListenerTree(handlers, type, tree[branch], i, typeLength); + } else if (branch === nextType) { + _listeners = searchListenerTree(handlers, type, tree[branch], i + 2, typeLength); + } else { + // No match on this one, shift into the tree but not in the type array. + _listeners = searchListenerTree(handlers, type, tree[branch], i, typeLength); + } + if (_listeners) { + if (listeners) { + listeners.push.apply(listeners, _listeners); + } else { + listeners = _listeners; + } + } + } + } + return listeners; + } else if (tree[currentType]) { + listeners = searchListenerTree(handlers, type, tree[currentType], i + 1, typeLength); + } + } + + xTree = tree['*']; + if (xTree) { + // + // If the listener tree will allow any match for this part, + // then recursively explore all branches of the tree + // + searchListenerTree(handlers, type, xTree, i + 1, typeLength); + } + + xxTree = tree['**']; + if (xxTree) { + if (i < typeLength) { + if (xxTree._listeners) { + // If we have a listener on a '**', it will catch all, so add its handler. + searchListenerTree(handlers, type, xxTree, typeLength, typeLength); + } + + // Build arrays of matching next branches and others. + branches= ownKeys(xxTree); + n= branches.length; + while(n-->0){ + branch= branches[n]; + if (branch !== '_listeners') { + if (branch === nextType) { + // We know the next element will match, so jump twice. + searchListenerTree(handlers, type, xxTree[branch], i + 2, typeLength); + } else if (branch === currentType) { + // Current node matches, move into the tree. + searchListenerTree(handlers, type, xxTree[branch], i + 1, typeLength); + } else { + isolatedBranch = {}; + isolatedBranch[branch] = xxTree[branch]; + searchListenerTree(handlers, type, {'**': isolatedBranch}, i + 1, typeLength); + } + } + } + } else if (xxTree._listeners) { + // We have reached the end and still on a '**' + searchListenerTree(handlers, type, xxTree, typeLength, typeLength); + } else if (xxTree['*'] && xxTree['*']._listeners) { + searchListenerTree(handlers, type, xxTree['*'], typeLength, typeLength); + } + } + + return listeners; + } + + function growListenerTree(type, listener, prepend) { + var len = 0, j = 0, i, delimiter = this.delimiter, dl= delimiter.length, ns; + + if(typeof type==='string') { + if ((i = type.indexOf(delimiter)) !== -1) { + ns = new Array(5); + do { + ns[len++] = type.slice(j, i); + j = i + dl; + } while ((i = type.indexOf(delimiter, j)) !== -1); + + ns[len++] = type.slice(j); + }else { + ns= [type]; + len= 1; + } + }else { + ns= type; + len= type.length; + } + + // + // Looks for two consecutive '**', if so, don't add the event at all. + // + if (len > 1) { + for (i = 0; i + 1 < len; i++) { + if (ns[i] === '**' && ns[i + 1] === '**') { + return; + } + } + } + + + + var tree = this.listenerTree, name; + + for (i = 0; i < len; i++) { + name = ns[i]; + + tree = tree[name] || (tree[name] = {}); + + if (i === len - 1) { + if (!tree._listeners) { + tree._listeners = listener; + } else { + if (typeof tree._listeners === 'function') { + tree._listeners = [tree._listeners]; + } + + if (prepend) { + tree._listeners.unshift(listener); + } else { + tree._listeners.push(listener); + } + + if ( + !tree._listeners.warned && + this._maxListeners > 0 && + tree._listeners.length > this._maxListeners + ) { + tree._listeners.warned = true; + logPossibleMemoryLeak.call(this, tree._listeners.length, name); + } + } + return true; + } + } + + return true; + } + + function collectTreeEvents(tree, events, root, asArray){ + var branches= ownKeys(tree); + var i= branches.length; + var branch, branchName, path; + var hasListeners= tree['_listeners']; + var isArrayPath; + + while(i-->0){ + branchName= branches[i]; + + branch= tree[branchName]; + + if(branchName==='_listeners'){ + path= root; + }else { + path = root ? root.concat(branchName) : [branchName]; + } + + isArrayPath= asArray || typeof branchName==='symbol'; + + hasListeners && events.push(isArrayPath? path : path.join(this.delimiter)); + + if(typeof branch==='object'){ + collectTreeEvents.call(this, branch, events, path, isArrayPath); + } + } + + return events; + } + + function recursivelyGarbageCollect(root) { + var keys = ownKeys(root); + var i= keys.length; + var obj, key, flag; + while(i-->0){ + key = keys[i]; + obj = root[key]; + + if(obj){ + flag= true; + if(key !== '_listeners' && !recursivelyGarbageCollect(obj)){ + delete root[key]; + } + } + } + + return flag; + } + + function Listener(emitter, event, listener){ + this.emitter= emitter; + this.event= event; + this.listener= listener; + } + + Listener.prototype.off= function(){ + this.emitter.off(this.event, this.listener); + return this; + }; + + function setupListener(event, listener, options){ + if (options === true) { + promisify = true; + } else if (options === false) { + async = true; + } else { + if (!options || typeof options !== 'object') { + throw TypeError('options should be an object or true'); + } + var async = options.async; + var promisify = options.promisify; + var nextTick = options.nextTick; + var objectify = options.objectify; + } + + if (async || nextTick || promisify) { + var _listener = listener; + var _origin = listener._origin || listener; + + if (nextTick && !nextTickSupported) { + throw Error('process.nextTick is not supported'); + } + + if (promisify === undefined$1) { + promisify = listener.constructor.name === 'AsyncFunction'; + } + + listener = function () { + var args = arguments; + var context = this; + var event = this.event; + + return promisify ? (nextTick ? Promise.resolve() : new Promise(function (resolve) { + _setImmediate(resolve); + }).then(function () { + context.event = event; + return _listener.apply(context, args) + })) : (nextTick ? process.nextTick : _setImmediate)(function () { + context.event = event; + _listener.apply(context, args); + }); + }; + + listener._async = true; + listener._origin = _origin; + } + + return [listener, objectify? new Listener(this, event, listener): this]; + } + + function EventEmitter(conf) { + this._events = {}; + this._newListener = false; + this._removeListener = false; + this.verboseMemoryLeak = false; + configure.call(this, conf); + } + + EventEmitter.EventEmitter2 = EventEmitter; // backwards compatibility for exporting EventEmitter property + + EventEmitter.prototype.listenTo= function(target, events, options){ + if(typeof target!=='object'){ + throw TypeError('target musts be an object'); + } + + var emitter= this; + + options = resolveOptions(options, { + on: undefined$1, + off: undefined$1, + reducers: undefined$1 + }, { + on: functionReducer, + off: functionReducer, + reducers: objectFunctionReducer + }); + + function listen(events){ + if(typeof events!=='object'){ + throw TypeError('events must be an object'); + } + + var reducers= options.reducers; + var index= findTargetIndex.call(emitter, target); + var observer; + + if(index===-1){ + observer= new TargetObserver(emitter, target, options); + }else { + observer= emitter._observers[index]; + } + + var keys= ownKeys(events); + var len= keys.length; + var event; + var isSingleReducer= typeof reducers==='function'; + + for(var i=0; i 0) { + observer = observers[i]; + if (!target || observer._target === target) { + observer.unsubscribe(event); + matched= true; + } + } + + return matched; + }; + + // By default EventEmitters will print a warning if more than + // 10 listeners are added to it. This is a useful default which + // helps finding memory leaks. + // + // Obviously not all Emitters should be limited to 10. This function allows + // that to be increased. Set to zero for unlimited. + + EventEmitter.prototype.delimiter = '.'; + + EventEmitter.prototype.setMaxListeners = function(n) { + if (n !== undefined$1) { + this._maxListeners = n; + if (!this._conf) this._conf = {}; + this._conf.maxListeners = n; + } + }; + + EventEmitter.prototype.getMaxListeners = function() { + return this._maxListeners; + }; + + EventEmitter.prototype.event = ''; + + EventEmitter.prototype.once = function(event, fn, options) { + return this._once(event, fn, false, options); + }; + + EventEmitter.prototype.prependOnceListener = function(event, fn, options) { + return this._once(event, fn, true, options); + }; + + EventEmitter.prototype._once = function(event, fn, prepend, options) { + return this._many(event, 1, fn, prepend, options); + }; + + EventEmitter.prototype.many = function(event, ttl, fn, options) { + return this._many(event, ttl, fn, false, options); + }; + + EventEmitter.prototype.prependMany = function(event, ttl, fn, options) { + return this._many(event, ttl, fn, true, options); + }; + + EventEmitter.prototype._many = function(event, ttl, fn, prepend, options) { + var self = this; + + if (typeof fn !== 'function') { + throw new Error('many only accepts instances of Function'); + } + + function listener() { + if (--ttl === 0) { + self.off(event, listener); + } + return fn.apply(this, arguments); + } + + listener._origin = fn; + + return this._on(event, listener, prepend, options); + }; + + EventEmitter.prototype.emit = function() { + if (!this._events && !this._all) { + return false; + } + + this._events || init.call(this); + + var type = arguments[0], ns, wildcard= this.wildcard; + var args,l,i,j, containsSymbol; + + if (type === 'newListener' && !this._newListener) { + if (!this._events.newListener) { + return false; + } + } + + if (wildcard) { + ns= type; + if(type!=='newListener' && type!=='removeListener'){ + if (typeof type === 'object') { + l = type.length; + if (symbolsSupported) { + for (i = 0; i < l; i++) { + if (typeof type[i] === 'symbol') { + containsSymbol = true; + break; + } + } + } + if (!containsSymbol) { + type = type.join(this.delimiter); + } + } + } + } + + var al = arguments.length; + var handler; + + if (this._all && this._all.length) { + handler = this._all.slice(); + + for (i = 0, l = handler.length; i < l; i++) { + this.event = type; + switch (al) { + case 1: + handler[i].call(this, type); + break; + case 2: + handler[i].call(this, type, arguments[1]); + break; + case 3: + handler[i].call(this, type, arguments[1], arguments[2]); + break; + default: + handler[i].apply(this, arguments); + } + } + } + + if (wildcard) { + handler = []; + searchListenerTree.call(this, handler, ns, this.listenerTree, 0, l); + } else { + handler = this._events[type]; + if (typeof handler === 'function') { + this.event = type; + switch (al) { + case 1: + handler.call(this); + break; + case 2: + handler.call(this, arguments[1]); + break; + case 3: + handler.call(this, arguments[1], arguments[2]); + break; + default: + args = new Array(al - 1); + for (j = 1; j < al; j++) args[j - 1] = arguments[j]; + handler.apply(this, args); + } + return true; + } else if (handler) { + // need to make copy of handlers because list can change in the middle + // of emit call + handler = handler.slice(); + } + } + + if (handler && handler.length) { + if (al > 3) { + args = new Array(al - 1); + for (j = 1; j < al; j++) args[j - 1] = arguments[j]; + } + for (i = 0, l = handler.length; i < l; i++) { + this.event = type; + switch (al) { + case 1: + handler[i].call(this); + break; + case 2: + handler[i].call(this, arguments[1]); + break; + case 3: + handler[i].call(this, arguments[1], arguments[2]); + break; + default: + handler[i].apply(this, args); + } + } + return true; + } else if (!this.ignoreErrors && !this._all && type === 'error') { + if (arguments[1] instanceof Error) { + throw arguments[1]; // Unhandled 'error' event + } else { + throw new Error("Uncaught, unspecified 'error' event."); + } + } + + return !!this._all; + }; + + EventEmitter.prototype.emitAsync = function() { + if (!this._events && !this._all) { + return false; + } + + this._events || init.call(this); + + var type = arguments[0], wildcard= this.wildcard, ns, containsSymbol; + var args,l,i,j; + + if (type === 'newListener' && !this._newListener) { + if (!this._events.newListener) { return Promise.resolve([false]); } + } + + if (wildcard) { + ns= type; + if(type!=='newListener' && type!=='removeListener'){ + if (typeof type === 'object') { + l = type.length; + if (symbolsSupported) { + for (i = 0; i < l; i++) { + if (typeof type[i] === 'symbol') { + containsSymbol = true; + break; + } + } + } + if (!containsSymbol) { + type = type.join(this.delimiter); + } + } + } + } + + var promises= []; + + var al = arguments.length; + var handler; + + if (this._all) { + for (i = 0, l = this._all.length; i < l; i++) { + this.event = type; + switch (al) { + case 1: + promises.push(this._all[i].call(this, type)); + break; + case 2: + promises.push(this._all[i].call(this, type, arguments[1])); + break; + case 3: + promises.push(this._all[i].call(this, type, arguments[1], arguments[2])); + break; + default: + promises.push(this._all[i].apply(this, arguments)); + } + } + } + + if (wildcard) { + handler = []; + searchListenerTree.call(this, handler, ns, this.listenerTree, 0); + } else { + handler = this._events[type]; + } + + if (typeof handler === 'function') { + this.event = type; + switch (al) { + case 1: + promises.push(handler.call(this)); + break; + case 2: + promises.push(handler.call(this, arguments[1])); + break; + case 3: + promises.push(handler.call(this, arguments[1], arguments[2])); + break; + default: + args = new Array(al - 1); + for (j = 1; j < al; j++) args[j - 1] = arguments[j]; + promises.push(handler.apply(this, args)); + } + } else if (handler && handler.length) { + handler = handler.slice(); + if (al > 3) { + args = new Array(al - 1); + for (j = 1; j < al; j++) args[j - 1] = arguments[j]; + } + for (i = 0, l = handler.length; i < l; i++) { + this.event = type; + switch (al) { + case 1: + promises.push(handler[i].call(this)); + break; + case 2: + promises.push(handler[i].call(this, arguments[1])); + break; + case 3: + promises.push(handler[i].call(this, arguments[1], arguments[2])); + break; + default: + promises.push(handler[i].apply(this, args)); + } + } + } else if (!this.ignoreErrors && !this._all && type === 'error') { + if (arguments[1] instanceof Error) { + return Promise.reject(arguments[1]); // Unhandled 'error' event + } else { + return Promise.reject("Uncaught, unspecified 'error' event."); + } + } + + return Promise.all(promises); + }; + + EventEmitter.prototype.on = function(type, listener, options) { + return this._on(type, listener, false, options); + }; + + EventEmitter.prototype.prependListener = function(type, listener, options) { + return this._on(type, listener, true, options); + }; + + EventEmitter.prototype.onAny = function(fn) { + return this._onAny(fn, false); + }; + + EventEmitter.prototype.prependAny = function(fn) { + return this._onAny(fn, true); + }; + + EventEmitter.prototype.addListener = EventEmitter.prototype.on; + + EventEmitter.prototype._onAny = function(fn, prepend){ + if (typeof fn !== 'function') { + throw new Error('onAny only accepts instances of Function'); + } + + if (!this._all) { + this._all = []; + } + + // Add the function to the event listener collection. + if(prepend){ + this._all.unshift(fn); + }else { + this._all.push(fn); + } + + return this; + }; + + EventEmitter.prototype._on = function(type, listener, prepend, options) { + if (typeof type === 'function') { + this._onAny(type, listener); + return this; + } + + if (typeof listener !== 'function') { + throw new Error('on only accepts instances of Function'); + } + this._events || init.call(this); + + var returnValue= this, temp; + + if (options !== undefined$1) { + temp = setupListener.call(this, type, listener, options); + listener = temp[0]; + returnValue = temp[1]; + } + + // To avoid recursion in the case that type == "newListeners"! Before + // adding it to the listeners, first emit "newListeners". + if (this._newListener) { + this.emit('newListener', type, listener); + } + + if (this.wildcard) { + growListenerTree.call(this, type, listener, prepend); + return returnValue; + } + + if (!this._events[type]) { + // Optimize the case of one listener. Don't need the extra array object. + this._events[type] = listener; + } else { + if (typeof this._events[type] === 'function') { + // Change to array. + this._events[type] = [this._events[type]]; + } + + // If we've already got an array, just add + if(prepend){ + this._events[type].unshift(listener); + }else { + this._events[type].push(listener); + } + + // Check for listener leak + if ( + !this._events[type].warned && + this._maxListeners > 0 && + this._events[type].length > this._maxListeners + ) { + this._events[type].warned = true; + logPossibleMemoryLeak.call(this, this._events[type].length, type); + } + } + + return returnValue; + }; + + EventEmitter.prototype.off = function(type, listener) { + if (typeof listener !== 'function') { + throw new Error('removeListener only takes instances of Function'); + } + + var handlers,leafs=[]; + + if(this.wildcard) { + var ns = typeof type === 'string' ? type.split(this.delimiter) : type.slice(); + leafs = searchListenerTree.call(this, null, ns, this.listenerTree, 0); + if(!leafs) return this; + } else { + // does not use listeners(), so no side effect of creating _events[type] + if (!this._events[type]) return this; + handlers = this._events[type]; + leafs.push({_listeners:handlers}); + } + + for (var iLeaf=0; iLeaf 0) { + fns = this._all; + for(i = 0, l = fns.length; i < l; i++) { + if(fn === fns[i]) { + fns.splice(i, 1); + if (this._removeListener) + this.emit("removeListenerAny", fn); + return this; + } + } + } else { + fns = this._all; + if (this._removeListener) { + for(i = 0, l = fns.length; i < l; i++) + this.emit("removeListenerAny", fns[i]); + } + this._all = []; + } + return this; + }; + + EventEmitter.prototype.removeListener = EventEmitter.prototype.off; + + EventEmitter.prototype.removeAllListeners = function (type) { + if (type === undefined$1) { + !this._events || init.call(this); + return this; + } + + if (this.wildcard) { + var leafs = searchListenerTree.call(this, null, type, this.listenerTree, 0), leaf, i; + if (!leafs) return this; + for (i = 0; i < leafs.length; i++) { + leaf = leafs[i]; + leaf._listeners = null; + } + this.listenerTree && recursivelyGarbageCollect(this.listenerTree); + } else if (this._events) { + this._events[type] = null; + } + return this; + }; + + EventEmitter.prototype.listeners = function (type) { + var _events = this._events; + var keys, listeners, allListeners; + var i; + var listenerTree; + + if (type === undefined$1) { + if (this.wildcard) { + throw Error('event name required for wildcard emitter'); + } + + if (!_events) { + return []; + } + + keys = ownKeys(_events); + i = keys.length; + allListeners = []; + while (i-- > 0) { + listeners = _events[keys[i]]; + if (typeof listeners === 'function') { + allListeners.push(listeners); + } else { + allListeners.push.apply(allListeners, listeners); + } + } + return allListeners; + } else { + if (this.wildcard) { + listenerTree= this.listenerTree; + if(!listenerTree) return []; + var handlers = []; + var ns = typeof type === 'string' ? type.split(this.delimiter) : type.slice(); + searchListenerTree.call(this, handlers, ns, listenerTree, 0); + return handlers; + } + + if (!_events) { + return []; + } + + listeners = _events[type]; + + if (!listeners) { + return []; + } + return typeof listeners === 'function' ? [listeners] : listeners; + } + }; + + EventEmitter.prototype.eventNames = function(nsAsArray){ + var _events= this._events; + return this.wildcard? collectTreeEvents.call(this, this.listenerTree, [], null, nsAsArray) : (_events? ownKeys(_events) : []); + }; + + EventEmitter.prototype.listenerCount = function(type) { + return this.listeners(type).length; + }; + + EventEmitter.prototype.hasListeners = function (type) { + if (this.wildcard) { + var handlers = []; + var ns = typeof type === 'string' ? type.split(this.delimiter) : type.slice(); + searchListenerTree.call(this, handlers, ns, this.listenerTree, 0); + return handlers.length > 0; + } + + var _events = this._events; + var _all = this._all; + + return !!(_all && _all.length || _events && (type === undefined$1 ? ownKeys(_events).length : _events[type])); + }; + + EventEmitter.prototype.listenersAny = function() { + + if(this._all) { + return this._all; + } + else { + return []; + } + + }; + + EventEmitter.prototype.waitFor = function (event, options) { + var self = this; + var type = typeof options; + if (type === 'number') { + options = {timeout: options}; + } else if (type === 'function') { + options = {filter: options}; + } + + options= resolveOptions(options, { + timeout: 0, + filter: undefined$1, + handleError: false, + Promise: Promise, + overload: false + }, { + filter: functionReducer, + Promise: constructorReducer + }); + + return makeCancelablePromise(options.Promise, function (resolve, reject, onCancel) { + function listener() { + var filter= options.filter; + if (filter && !filter.apply(self, arguments)) { + return; + } + self.off(event, listener); + if (options.handleError) { + var err = arguments[0]; + err ? reject(err) : resolve(toArray.apply(null, arguments).slice(1)); + } else { + resolve(toArray.apply(null, arguments)); + } + } + + onCancel(function(){ + self.off(event, listener); + }); + + self._on(event, listener, false); + }, { + timeout: options.timeout, + overload: options.overload + }) + }; + + function once(emitter, name, options) { + options= resolveOptions(options, { + Promise: Promise, + timeout: 0, + overload: false + }, { + Promise: constructorReducer + }); + + var _Promise= options.Promise; + + return makeCancelablePromise(_Promise, function(resolve, reject, onCancel){ + var handler; + if (typeof emitter.addEventListener === 'function') { + handler= function () { + resolve(toArray.apply(null, arguments)); + }; + + onCancel(function(){ + emitter.removeEventListener(name, handler); + }); + + emitter.addEventListener( + name, + handler, + {once: true} + ); + return; + } + + var eventListener = function(){ + errorListener && emitter.removeListener('error', errorListener); + resolve(toArray.apply(null, arguments)); + }; + + var errorListener; + + if (name !== 'error') { + errorListener = function (err){ + emitter.removeListener(name, eventListener); + reject(err); + }; + + emitter.once('error', errorListener); + } + + onCancel(function(){ + errorListener && emitter.removeListener('error', errorListener); + emitter.removeListener(name, eventListener); + }); + + emitter.once(name, eventListener); + }, { + timeout: options.timeout, + overload: options.overload + }); + } + + var prototype= EventEmitter.prototype; + + Object.defineProperties(EventEmitter, { + defaultMaxListeners: { + get: function () { + return prototype._maxListeners; + }, + set: function (n) { + if (typeof n !== 'number' || n < 0 || Number.isNaN(n)) { + throw TypeError('n must be a non-negative number') + } + prototype._maxListeners = n; + }, + enumerable: true + }, + once: { + value: once, + writable: true, + configurable: true + } + }); + + Object.defineProperties(prototype, { + _maxListeners: { + value: defaultMaxListeners, + writable: true, + configurable: true + }, + _observers: {value: null, writable: true, configurable: true} + }); + + if (typeof undefined$1 === 'function' && undefined$1.amd) { + // AMD. Register as an anonymous module. + undefined$1(function() { + return EventEmitter; + }); + } else { + // CommonJS + module.exports = EventEmitter; + } + }(); + } (eventemitter2, eventemitter2.exports)); + return eventemitter2.exports; + } + + var eventemitter2Exports = requireEventemitter2(); var EventEmitter2 = /*@__PURE__*/getDefaultExportFromCjs(eventemitter2Exports); /** diff --git a/build/ros3d.min.js b/build/ros3d.min.js index d3b63366..5a34d276 100644 --- a/build/ros3d.min.js +++ b/build/ros3d.min.js @@ -9,4 +9,4 @@ Object.assign(za.prototype,{_getValue_unbound:za.prototype.getValue,_setValue_un * * Copyright (c) 2013 hij1nx * Licensed under the MIT license. - */Ws=Xs,function(e){var t=Object.hasOwnProperty,i=Array.isArray?Array.isArray:function(e){return"[object Array]"===Object.prototype.toString.call(e)},r="object"==typeof process&&"function"==typeof process.nextTick,n="function"==typeof Symbol,o="object"==typeof Reflect,a="function"==typeof setImmediate?setImmediate:setTimeout,s=n?o&&"function"==typeof Reflect.ownKeys?Reflect.ownKeys:function(e){var t=Object.getOwnPropertyNames(e);return t.push.apply(t,Object.getOwnPropertySymbols(e)),t}:Object.keys;function c(){this._events={},this._conf&&h.call(this,this._conf)}function h(t){t&&(this._conf=t,t.delimiter&&(this.delimiter=t.delimiter),t.maxListeners!==e&&(this._maxListeners=t.maxListeners),t.wildcard&&(this.wildcard=t.wildcard),t.newListener&&(this._newListener=t.newListener),t.removeListener&&(this._removeListener=t.removeListener),t.verboseMemoryLeak&&(this.verboseMemoryLeak=t.verboseMemoryLeak),t.ignoreErrors&&(this.ignoreErrors=t.ignoreErrors),this.wildcard&&(this.listenerTree={}))}function l(e,t){var i="(node) warning: possible EventEmitter memory leak detected. "+e+" listeners added. Use emitter.setMaxListeners() to increase limit.";if(this.verboseMemoryLeak&&(i+=" Event name: "+t+"."),"undefined"!=typeof process&&process.emitWarning){var r=new Error(i);r.name="MaxListenersExceededWarning",r.emitter=this,r.count=e,process.emitWarning(r)}else console.error(i),console.trace&&console.trace()}var u=function(e,t,i){var r=arguments.length;switch(r){case 0:return[];case 1:return[e];case 2:return[e,t];case 3:return[e,t,i];default:for(var n=new Array(r);r--;)n[r]=arguments[r];return n}};function p(t,i){for(var r={},n=t.length,o=i?value.length:0,a=0;a0;)if(o===e[a])return r;n(t)}}Object.assign(d.prototype,{subscribe:function(e,t,i){var r=this,n=this._target,o=this._emitter,a=this._listeners,s=function(){var r=u.apply(null,arguments),a={data:r,name:t,original:e};if(i){var s=i.call(n,a);!1!==s&&o.emit.apply(o,[a.name].concat(r))}else o.emit.apply(o,[t].concat(r))};if(a[e])throw Error("Event '"+e+"' is already listening");this._listenersCount++,o._newListener&&o._removeListener&&!r._onNewListener?(this._onNewListener=function(i){i===t&&null===a[e]&&(a[e]=s,r._on.call(n,e,s))},o.on("newListener",this._onNewListener),this._onRemoveListener=function(i){i===t&&!o.hasListeners(i)&&a[e]&&(a[e]=null,r._off.call(n,e,s))},a[e]=null,o.on("removeListener",this._onRemoveListener)):(a[e]=s,r._on.call(n,e,s))},unsubscribe:function(e){var t,i,r,n=this,o=this._listeners,a=this._emitter,c=this._off,h=this._target;if(e&&"string"!=typeof e)throw TypeError("event must be a string");function l(){n._onNewListener&&(a.off("newListener",n._onNewListener),a.off("removeListener",n._onRemoveListener),n._onNewListener=null,n._onRemoveListener=null);var e=b.call(a,n);a._observers.splice(e,1)}if(e){if(!(t=o[e]))return;c.call(h,e,t),delete o[e],--this._listenersCount||l()}else{for(r=(i=s(o)).length;r-- >0;)e=i[r],c.call(h,e,o[e]);this._listeners={},this._listenersCount=0,l()}}});var g=v(["function"]),y=v(["object","function"]);function x(e,t,i){var r,n,o,a=0,s=new e((function(c,h,l){function u(){n&&(n=null),a&&(clearTimeout(a),a=0)}i=f(i,{timeout:0,overload:!1},{timeout:function(e,t){return("number"!=typeof(e*=1)||e<0||!Number.isFinite(e))&&t("timeout must be a positive number"),e}}),r=!i.overload&&"function"==typeof e.prototype.cancel&&"function"==typeof l;var p=function(e){u(),c(e)},d=function(e){u(),h(e)};r?t(p,d,l):(n=[function(e){d(e||Error("canceled"))}],t(p,d,(function(e){if(o)throw Error("Unable to subscribe on cancel event asynchronously");if("function"!=typeof e)throw TypeError("onCancel callback must be a function");n.push(e)})),o=!0),i.timeout>0&&(a=setTimeout((function(){var e=Error("timeout");e.code="ETIMEDOUT",a=0,s.cancel(e),h(e)}),i.timeout))}));return r||(s.cancel=function(e){if(n){for(var t=n.length,i=1;i0;)"_listeners"!==(d=y[c])&&(x=w(e,t,i[d],r+1,n))&&(b?b.push.apply(b,x):b=x);return b}if("**"===_){for((g=r+1===n||r+2===n&&"*"===M)&&i._listeners&&(b=w(e,t,i,n,n)),c=(y=s(i)).length;c-- >0;)"_listeners"!==(d=y[c])&&("*"===d||"**"===d?(i[d]._listeners&&!g&&(x=w(e,t,i[d],n,n))&&(b?b.push.apply(b,x):b=x),x=w(e,t,i[d],r,n)):x=w(e,t,i[d],d===M?r+2:r,n),x&&(b?b.push.apply(b,x):b=x));return b}i[_]&&(b=w(e,t,i[_],r+1,n))}if((f=i["*"])&&w(e,t,f,r+1,n),m=i["**"])if(r0;)"_listeners"!==(d=y[c])&&(d===M?w(e,t,m[d],r+2,n):d===_?w(e,t,m[d],r+1,n):((v={})[d]=m[d],w(e,t,{"**":v},r+1,n)));else m._listeners?w(e,t,m,n,n):m["*"]&&m["*"]._listeners&&w(e,t,m["*"],n,n);return b}function _(e,t,i){var r,n,o=0,a=0,s=this.delimiter,c=s.length;if("string"==typeof e)if(-1!==(r=e.indexOf(s))){n=new Array(5);do{n[o++]=e.slice(a,r),a=r+c}while(-1!==(r=e.indexOf(s,a)));n[o++]=e.slice(a)}else n=[e],o=1;else n=e,o=e.length;if(o>1)for(r=0;r+10&&u._listeners.length>this._maxListeners&&(u._listeners.warned=!0,l.call(this,u._listeners.length,h))):u._listeners=t,!0;return!0}function M(e,t,i,r){for(var n,o,a,c,h=s(e),l=h.length,u=e._listeners;l-- >0;)n=e[o=h[l]],a="_listeners"===o?i:i?i.concat(o):[o],c=r||"symbol"==typeof o,u&&t.push(c?a:a.join(this.delimiter)),"object"==typeof n&&M.call(this,n,t,a,c);return t}function E(e){for(var t,i,r,n=s(e),o=n.length;o-- >0;)(t=e[i=n[o]])&&(r=!0,"_listeners"===i||E(t)||delete e[i]);return r}function T(e,t,i){this.emitter=e,this.event=t,this.listener=i}function S(t,i,n){if(!0===n)s=!0;else if(!1===n)o=!0;else{if(!n||"object"!=typeof n)throw TypeError("options should be an object or true");var o=n.async,s=n.promisify,c=n.nextTick,h=n.objectify}if(o||c||s){var l=i,u=i._origin||i;if(c&&!r)throw Error("process.nextTick is not supported");s===e&&(s="AsyncFunction"===i.constructor.name),i=function(){var e=arguments,t=this,i=this.event;return s?c?Promise.resolve():new Promise((function(e){a(e)})).then((function(){return t.event=i,l.apply(t,e)})):(c?process.nextTick:a)((function(){t.event=i,l.apply(t,e)}))},i._async=!0,i._origin=u}return[i,h?new T(this,t,i):this]}function A(e){this._events={},this._newListener=!1,this._removeListener=!1,this.verboseMemoryLeak=!1,h.call(this,e)}T.prototype.off=function(){return this.emitter.off(this.event,this.listener),this},A.EventEmitter2=A,A.prototype.listenTo=function(t,r,n){if("object"!=typeof t)throw TypeError("target musts be an object");var o=this;function a(e){if("object"!=typeof e)throw TypeError("events must be an object");var i,r=n.reducers,a=b.call(o,t);i=-1===a?new d(o,t,n):o._observers[a];for(var c,h=s(e),l=h.length,u="function"==typeof r,p=0;p0;)r=i[n],e&&r._target!==e||(r.unsubscribe(t),o=!0);return o},A.prototype.delimiter=".",A.prototype.setMaxListeners=function(t){t!==e&&(this._maxListeners=t,this._conf||(this._conf={}),this._conf.maxListeners=t)},A.prototype.getMaxListeners=function(){return this._maxListeners},A.prototype.event="",A.prototype.once=function(e,t,i){return this._once(e,t,!1,i)},A.prototype.prependOnceListener=function(e,t,i){return this._once(e,t,!0,i)},A.prototype._once=function(e,t,i,r){return this._many(e,1,t,i,r)},A.prototype.many=function(e,t,i,r){return this._many(e,t,i,!1,r)},A.prototype.prependMany=function(e,t,i,r){return this._many(e,t,i,!0,r)},A.prototype._many=function(e,t,i,r,n){var o=this;if("function"!=typeof i)throw new Error("many only accepts instances of Function");function a(){return 0==--t&&o.off(e,a),i.apply(this,arguments)}return a._origin=i,this._on(e,a,r,n)},A.prototype.emit=function(){if(!this._events&&!this._all)return!1;this._events||c.call(this);var e,t,i,r,o,a,s=arguments[0],h=this.wildcard;if("newListener"===s&&!this._newListener&&!this._events.newListener)return!1;if(h&&(e=s,"newListener"!==s&&"removeListener"!==s&&"object"==typeof s)){if(i=s.length,n)for(r=0;r3)for(t=new Array(u-1),o=1;o3)for(i=new Array(p-1),a=1;a0&&this._events[t].length>this._maxListeners&&(this._events[t].warned=!0,l.call(this,this._events[t].length,t))):this._events[t]=i,a)},A.prototype.off=function(e,t){if("function"!=typeof t)throw new Error("removeListener only takes instances of Function");var r,n=[];if(this.wildcard){var o="string"==typeof e?e.split(this.delimiter):e.slice();if(!(n=w.call(this,null,o,this.listenerTree,0)))return this}else{if(!this._events[e])return this;r=this._events[e],n.push({_listeners:r})}for(var a=0;a0){for(i=0,r=(t=this._all).length;i0;)"function"==typeof(r=c[i[o]])?n.push(r):n.push.apply(n,r);return n}if(this.wildcard){if(!(a=this.listenerTree))return[];var h=[],l="string"==typeof t?t.split(this.delimiter):t.slice();return w.call(this,h,l,a,0),h}return c&&(r=c[t])?"function"==typeof r?[r]:r:[]},A.prototype.eventNames=function(e){var t=this._events;return this.wildcard?M.call(this,this.listenerTree,[],null,e):t?s(t):[]},A.prototype.listenerCount=function(e){return this.listeners(e).length},A.prototype.hasListeners=function(t){if(this.wildcard){var i=[],r="string"==typeof t?t.split(this.delimiter):t.slice();return w.call(this,i,r,this.listenerTree,0),i.length>0}var n=this._events,o=this._all;return!!(o&&o.length||n&&(t===e?s(n).length:n[t]))},A.prototype.listenersAny=function(){return this._all?this._all:[]},A.prototype.waitFor=function(t,i){var r=this,n=typeof i;return"number"===n?i={timeout:i}:"function"===n&&(i={filter:i}),x((i=f(i,{timeout:0,filter:e,handleError:!1,Promise:Promise,overload:!1},{filter:g,Promise:m})).Promise,(function(e,n,o){function a(){var o=i.filter;if(!o||o.apply(r,arguments))if(r.off(t,a),i.handleError){var s=arguments[0];s?n(s):e(u.apply(null,arguments).slice(1))}else e(u.apply(null,arguments))}o((function(){r.off(t,a)})),r._on(t,a,!1)}),{timeout:i.timeout,overload:i.overload})};var L=A.prototype;Object.defineProperties(A,{defaultMaxListeners:{get:function(){return L._maxListeners},set:function(e){if("number"!=typeof e||e<0||Number.isNaN(e))throw TypeError("n must be a non-negative number");L._maxListeners=e},enumerable:!0},once:{value:function(e,t,i){return x((i=f(i,{Promise:Promise,timeout:0,overload:!1},{Promise:m})).Promise,(function(i,r,n){var o;if("function"==typeof e.addEventListener)return o=function(){i(u.apply(null,arguments))},n((function(){e.removeEventListener(t,o)})),void e.addEventListener(t,o,{once:!0});var a,s=function(){a&&e.removeListener("error",a),i(u.apply(null,arguments))};"error"!==t&&(a=function(i){e.removeListener(t,s),r(i)},e.once("error",a)),n((function(){a&&e.removeListener("error",a),e.removeListener(t,s)})),e.once(t,s)}),{timeout:i.timeout,overload:i.overload})},writable:!0,configurable:!0}}),Object.defineProperties(L,{_maxListeners:{value:10,writable:!0,configurable:!0},_observers:{value:null,writable:!0,configurable:!0}}),Ws.exports=A}();var qs=Hs(Xs.exports);class Ys extends qs{constructor(e){super(),e=e||{},this.message=e.message,this.feedbackTopic=e.feedbackTopic,this.tfClient=e.tfClient,this.menuFontSize=e.menuFontSize||"0.8em",this.name=this.message.name,this.header=this.message.header,this.controls=this.message.controls,this.menuEntries=this.message.menu_entries,this.dragging=!1,this.timeoutHandle=null,this.tfTransform=new r.Transform,this.pose=new r.Pose,this.setPoseFromClientBound=this.setPoseFromClient.bind(this),this.onMouseDownBound=this.onMouseDown.bind(this),this.onMouseUpBound=this.onMouseUp.bind(this),this.onButtonClickBound=this.onButtonClick.bind(this),this.onMenuSelectBound=this.onMenuSelect.bind(this),this.setPoseFromServer(this.message.pose),this.tfUpdateBound=this.tfUpdate.bind(this)}subscribeTf(){0===this.message.header.stamp.secs&&0===this.message.header.stamp.nsecs&&this.tfClient.subscribe(this.message.header.frame_id,this.tfUpdateBound)}unsubscribeTf(){this.tfClient.unsubscribe(this.message.header.frame_id,this.tfUpdateBound)}emitServerPoseUpdate(){var e=new r.Pose(this.pose);e.applyTransform(this.tfTransform),this.emit("pose",e)}setPoseFromServer(e){this.pose=new r.Pose(e),this.emitServerPoseUpdate()}tfUpdate(e){this.tfTransform=new r.Transform(e),this.emitServerPoseUpdate()}setPoseFromClient(e){this.pose=new r.Pose(e);var t=this.tfTransform.clone();t.rotation.invert(),t.translation.multiplyQuaternion(t.rotation),t.translation.x*=-1,t.translation.y*=-1,t.translation.z*=-1,this.pose.applyTransform(t),this.sendFeedback(1,void 0,0,e.controlName),this.dragging&&(this.timeoutHandle&&clearTimeout(this.timeoutHandle),this.timeoutHandle=setTimeout(this.setPoseFromClient.bind(this,e),250))}onButtonClick(e){this.sendFeedback(3,e.clickPosition,0,e.controlName)}onMouseDown(e){this.sendFeedback(4,e.clickPosition,0,e.controlName),this.dragging=!0}onMouseUp(e){this.sendFeedback(5,e.clickPosition,0,e.controlName),this.dragging=!1,this.timeoutHandle&&clearTimeout(this.timeoutHandle)}onMenuSelect(e){this.sendFeedback(2,void 0,e.id,e.controlName)}sendFeedback(e,t,i,r){var n=void 0!==t;t=t||{x:0,y:0,z:0};var o={header:this.header,client_id:this.clientID,marker_name:this.name,control_name:r,event_type:e,pose:this.pose,mouse_point:t,mouse_point_valid:n,menu_entry_id:i};this.feedbackTopic.publish(o)}}class Zs extends Ss.Object3D{constructor(e){super(),e=e||{},this.tfClient=e.tfClient,this.frameID=e.frameID;var t=e.object;this.pose=e.pose||new r.Pose,this.visible=!1,this.add(t),this.updatePose(this.pose),this.tfUpdate=function(e){var t=new r.Transform(e),i=new r.Pose(this.pose);i.applyTransform(t),this.updatePose(i),this.visible=!0},this.tfUpdateBound=this.tfUpdate.bind(this),this.tfClient.subscribe(this.frameID,this.tfUpdateBound)}updatePose(e){this.position.set(e.position.x,e.position.y,e.position.z),this.quaternion.set(e.orientation.x,e.orientation.y,e.orientation.z,e.orientation.w),this.updateMatrixWorld(!0)}unsubscribeTf(){this.tfClient.unsubscribe(this.frameID,this.tfUpdateBound)}}class Js extends Ss.ArrowHelper{constructor(e){var t=(e=e||{}).origin||new Ss.Vector3(0,0,0),i=e.direction||new Ss.Vector3(1,0,0),r=e.length||1;e.headLength,e.shaftDiameter,e.headDiameter,e.material||new Ss.MeshBasicMaterial,super(i,t,r,16711680)}dispose(){void 0!==this.line&&(this.line.material.dispose(),this.line.geometry.dispose()),void 0!==this.cone&&(this.cone.material.dispose(),this.cone.geometry.dispose())}}class Ks extends Ss.Object3D{constructor(e){super();var t=this,i=(e=e||{}).shaftRadius||.008,r=e.headRadius||.023,n=e.headLength||.1,o=e.scale||1,a=e.lineType||"full",s=e.lineDashLength||.1;function c(e){var r=new Ss.Color;r.setRGB(e.x,e.y,e.z);var n=new Ss.MeshBasicMaterial({color:r.getHex()}),o=new Ss.Vector3;o.crossVectors(e,new Ss.Vector3(0,-1,0));var c=new Ss.Quaternion;c.setFromAxisAngle(o,.5*Math.PI);var h,l=new Ss.Mesh(t.headGeom,n);if(l.position.copy(e),l.position.multiplyScalar(.95),l.quaternion.copy(c),l.updateMatrix(),t.add(l),"dashed"===a)for(var u=s,p=0;u/2+3*u*p+u/2<=1;++p){var d=new Ss.CylinderGeometry(i,i,u);(h=new Ss.Mesh(d,n)).position.copy(e),h.position.multiplyScalar(u/2+3*u*p),h.quaternion.copy(c),h.updateMatrix(),t.add(h)}else"full"===a?((h=new Ss.Mesh(t.lineGeom,n)).position.copy(e),h.position.multiplyScalar(.45),h.quaternion.copy(c),h.updateMatrix(),t.add(h)):console.warn("[Axes]: Unsupported line type. Not drawing any axes.")}this.scale.set(o,o,o),this.lineGeom=new Ss.CylinderGeometry(i,i,1-n),this.headGeom=new Ss.CylinderGeometry(0,r,n),c(new Ss.Vector3(1,0,0)),c(new Ss.Vector3(0,1,0)),c(new Ss.Vector3(0,0,1))}}class Qs extends Ss.Object3D{constructor(e){var t=(e=e||{}).num_cells||10,i=e.color||"#cccccc",r=e.lineWidth||1,n=e.cellSize||1;super();for(var o=new Ss.LineBasicMaterial({color:i,linewidth:r}),a=0;a<=t;++a){var s=n*t/2,c=s-a*n,h=new Ss.Geometry;h.vertices.push(new Ss.Vector3(-s,c,0),new Ss.Vector3(s,c,0));var l=new Ss.Geometry;l.vertices.push(new Ss.Vector3(c,-s,0),new Ss.Vector3(c,s,0)),this.add(new Ss.Line(h,o)),this.add(new Ss.Line(l,o))}}}class $s extends Ss.Mesh{constructor(e){var t=(e=e||{}).message,i=e.opacity||1,r=e.color||{r:255,g:255,b:255,a:255},n=t.info,o=n.origin,a=n.width,s=n.height,c=new Ss.PlaneBufferGeometry(a,s),h=new Uint8Array(a*s*4),l=new Ss.DataTexture(h,a,s,Ss.RGBAFormat);l.flipY=!0,l.minFilter=Ss.NearestFilter,l.magFilter=Ss.NearestFilter,l.needsUpdate=!0;var u=new Ss.MeshBasicMaterial({map:l,transparent:i<1,opacity:i});u.side=Ss.DoubleSide,super(c,u),Object.assign(this,e),this.quaternion.copy(new Ss.Quaternion(o.orientation.x,o.orientation.y,o.orientation.z,o.orientation.w)),this.position.x=a*n.resolution/2+o.position.x,this.position.y=s*n.resolution/2+o.position.y,this.position.z=o.position.z,this.scale.x=n.resolution,this.scale.y=n.resolution;var p=t.data;this.color=r,this.material=u,this.texture=l;for(var d=0;d{const t="read"+e.kind,i="get"+e.kind;this[t]=()=>{if(this._cursor+e.width>this.length)throw new Error("Cannot read data stream. Overflow. Len="+this.length+" crsr="+this._cursor);const t=this._dataView[i](this._cursor,this.isLittleEndian);return this._cursor+=e.width,t}})),Object.defineProperty(this,"isEnd",{get:()=>this.cursor>=this.data.length}),this}class ac{constructor(e){this.resolution=void 0!==e.resolution?e.resolution:1,this.color=new Ss.Color(void 0!==e.color?e.color:"green"),this.opacity=void 0!==e.opacity?e.opacity:1,this.voxelRenderMode=void 0!==e.voxelRenderMode?e.voxelRenderMode:tc,this._rootNode=null,this._treeDepth=16,this._treeMaxKeyVal=32768,this._BINARY_UNALLOCATED=0,this._BINARY_LEAF_FREE=1,this._BINARY_LEAF_OCCUPIED=2,this._BINARY_HAS_CHILDREN=3,this._BINARY_CHILD_BUILD_TABLE={},this._BINARY_CHILD_BUILD_TABLE[this._BINARY_LEAF_FREE]=function(e){e.value=this._defaultFreeValue},this._BINARY_CHILD_BUILD_TABLE[this._BINARY_LEAF_OCCUPIED]=function(e){e.value=this._defaultOccupiedValue},this._BINARY_CHILD_BUILD_TABLE[this._BINARY_HAS_CHILDREN]=function(e){e.value=null},this._FACES=[{normal:[-1,0,0],vertices:[[0,1,0],[0,0,0],[0,1,1],[0,0,1]],childIndex:[1,3,5,7]},{normal:[1,0,0],vertices:[[1,1,1],[1,0,1],[1,1,0],[1,0,0]],childIndex:[0,2,4,6]},{normal:[0,-1,0],vertices:[[1,0,1],[0,0,1],[1,0,0],[0,0,0]],childIndex:[2,3,6,7]},{normal:[0,1,0],vertices:[[0,1,1],[1,1,1],[0,1,0],[1,1,0]],childIndex:[0,1,4,5]},{normal:[0,0,-1],vertices:[[1,0,0],[0,0,0],[1,1,0],[0,1,0]],childIndex:[4,5,6,7]},{normal:[0,0,1],vertices:[[0,0,1],[1,0,1],[0,1,1],[1,1,1]],childIndex:[0,1,2,3]}],this.nodeSizeTable=new Array(this._treeDepth);let t=this.resolution;for(let e=this._treeDepth-1;e>=0;--e)this.nodeSizeTable[e]=t,t*=2;this._defaultOccupiedValue=!0,this._defaultFreeValue=!1,this.object=null}searchAtDepth(e,t){t=void 0!==t&&t>0?t:this._treeDepth;const i=this._adjustKeyAtDepth(e,t),r=this._treeDepth-t;let n=this._rootNode;for(let e=this._treeDepth-1;e>=r;--e){const t=this._computeChildIdx(i,e);if(!n.hasChildAt(t))return n.hasChildren()?null:n;n=n.getChildAt(t)}return n}_computeCoordFromKey(e){return e.map((e=>this.resolution*(e-this._treeMaxKeyVal)))}_computeChildIdx(e,t){let i=0;return e[0]&1<(e-this._treeMaxKeyVal>>i<0;){let e=i.pop();const r=t.readUint16();let n=8;for(;0!==n;){--n;const t=(r&3<<2*n)>>2*n;if(t!==this._BINARY_UNALLOCATED){let r=this._newNode();this._BINARY_CHILD_BUILD_TABLE[t].bind(this)(r),e.createChildNodeAt(r,n),t===this._BINARY_HAS_CHILDREN&&i.push(r)}}}}read(e){null!==this._rootNode&&delete this._rootNode,this._rootNode=this._newNode();let t=new oc(e,!0),i=new Array;for(i.push(this._rootNode);i.length>0;){let e=i.pop();this._readNodeData(t,e);const r=t.readUint8();let n=8;for(;0!==n;){--n;if(r&1<0;){let i=t.pop();if(i.node.isLeafNode())e(i.node,i.key,i.depth-1);else for(let e=0;e<8;++e)if(i.node.hasChildAt(e)){const r=this._computeKeyFromChildIdx(e,i.key,i.depth);t.push({node:i.node.getChildAt(e),depth:i.depth+1,key:r})}}}_obtainColor(e){return this.color}_checkOccupied(e){return!1!==e.value}_buildFaces(){let e={vertices:[],indices:[],normals:[],colors:[],_insertFace:function(e,t,i,r){const n=this.vertices.length/3;e.vertices.forEach((function(e){this.vertices.push(t[0]+e[0]*i,t[1]+e[1]*i,t[2]+e[2]*i)}));const o=[r.r,r.g,r.b];this.colors.push(...o,...o,...o,...o),this.normals.push(...e.normal,...e.normal,...e.normal,...e.normal),this.indices.push(n,n+1,n+2,n+2,n+1,n+3)},_checkNeighborsTouchingFace:function(e,t,i){let r=new Array;for(r.push(t);0!==r.length;){const t=r.pop();t.hasChildren()&&e.childIndex.forEach((function(e){if(!t.hasChildAt(e))return!0;{const n=t.getChildAt(e),o=this._checkOccupied(t);(o&&i===ROS3D.OcTreeVoxelRenderMode.OCCUPIED||!o&&i===ic)&&r.push(n)}}))}return!1}};return this._traverseLeaves(((t,i,r)=>{const n=this._computeCoordFromKey(i),o=this.nodeSizeTable[r],a=this._treeDepth-r,s=this._checkOccupied(t);(s||this.voxelRenderMode!==tc)&&(s&&this.voxelRenderMode===ic||this._FACES.forEach((function(s){const c=[i[0]+s.normal[0]*a*a,i[1]+s.normal[1]*a*a,i[2]+s.normal[2]*a*a],h=this.searchAtDepth(c);null===h?e._insertFace(s,n,o,this._obtainColor(t)):rnew Ss.Color(e))):[{r:0,g:0,b:128},{r:0,g:255,b:0},{r:255,g:255,b:0},{r:255,g:128,b:0},{r:255,g:0,b:0}],this.paletteScale=void 0!==e.paletteScale?e.paletteScale:1}_readNodeData(e,t){t.value=e.readFloat32()}_obtainColor(e){if(this.useFlatColoring)return this.color;const t=1/(1+Math.exp(-e.value*this.paletteScale))*this.palette.length,i=Math.trunc(t),r=t-i;return i<0?this.palette[0]:i>=this.palette.length-1?this.palette[this.palette.length-1]:{r:r*this.palette[i].r+(1-r)*this.palette[i+1].r,g:r*this.palette[i].g+(1-r)*this.palette[i+1].g,b:r*this.palette[i].b+(1-r)*this.palette[i+1].b}}_checkOccupied(e){return e.value>=this.occupancyThreshold}}class cc extends sc{constructor(e){super(e),this.useOwnColor=void 0!==e.palette&&e.colorMode===nc}_readNodeData(e,t){t.value=e.readFloat32(),t.color={r:e.readUint8(),g:e.readUint8(),b:e.readUint8()}}_obtainColor(e){return this.useOwnColor?e.color:sc.prototype._obtainColor.call(this,e)}}class hc extends Ss.Object3D{constructor(e){super(),this.options=e||{},this.ros=e.ros,this.topicName=e.topic||"/particlecloud",this.tfClient=e.tfClient,this.color=e.color||13369599,this.length=e.length||1,this.rootObject=e.rootObject||new Ss.Object3D,this.keep=e.keep||1,this.sns=[],this.rosTopic=void 0,this.processMessageBound=this.processMessage.bind(this),this.subscribe()}unsubscribe(){this.rosTopic&&this.rosTopic.unsubscribe(this.processMessageBound)}subscribe(){this.unsubscribe(),this.rosTopic=new r.Topic({ros:this.ros,name:this.topicName,queue_length:1,messageType:"nav_msgs/Odometry"}),this.rosTopic.subscribe(this.processMessageBound)}processMessage(e){this.sns.length>=this.keep&&(this.sns[0].unsubscribeTf(),this.rootObject.remove(this.sns[0]),this.sns.shift()),this.options.origin=new Ss.Vector3(e.pose.pose.position.x,e.pose.pose.position.y,e.pose.pose.position.z);var t=new Ss.Quaternion(e.pose.pose.orientation.x,e.pose.pose.orientation.y,e.pose.pose.orientation.z,e.pose.pose.orientation.w);this.options.direction=new Ss.Vector3(1,0,0),this.options.direction.applyQuaternion(t),this.options.material=new Ss.MeshBasicMaterial({color:this.color});var i=new Ns(this.options);this.sns.push(new Zs({frameID:e.header.frame_id,tfClient:this.tfClient,object:i})),this.rootObject.add(this.sns[this.sns.length-1])}}class lc extends Ss.Object3D{constructor(e){super(),e=e||{},this.ros=e.ros,this.topicName=e.topic||"/path",this.tfClient=e.tfClient,this.color=e.color||13369599,this.rootObject=e.rootObject||new Ss.Object3D,this.sn=null,this.line=null,this.rosTopic=void 0,this.processMessageBound=this.processMessage.bind(this),this.subscribe()}unsubscribe(){this.rosTopic&&this.rosTopic.unsubscribe(this.processMessageBound)}subscribe(){this.unsubscribe(),this.rosTopic=new r.Topic({ros:this.ros,name:this.topicName,queue_length:1,messageType:"nav_msgs/Path"}),this.rosTopic.subscribe(this.processMessageBound)}processMessage(e){null!==this.sn&&(this.sn.unsubscribeTf(),this.rootObject.remove(this.sn));for(var t=new Ss.Geometry,i=0;i=e.range_min&&n<=e.range_max){var o=e.angle_min+r*e.angle_increment;this.points.positions.array[i++]=n*Math.cos(o),this.points.positions.array[i++]=n*Math.sin(o),this.points.positions.array[i++]=0}}this.points.update(i/3)}}}class yc extends Ss.Object3D{constructor(e){super(),e=e||{},this.ros=e.ros,this.topicName=e.topic||"/gps/fix",this.rootObject=e.rootObject||new Ss.Object3D,this.object3d=e.object3d||new Ss.Object3D;var t=e.material||{};this.altitudeNaN=e.altitudeNaN||0,this.keep=e.keep||100,this.convert=e.convert||function(e,t,i){return new Ss.Vector3(e,t,i)},this.count=0,this.next1=0,this.next2=this.keep,this.geom=new Ss.BufferGeometry,this.vertices=new Ss.BufferAttribute(new Float32Array(6*this.keep),3),this.geom.addAttribute("position",this.vertices),this.material=t.isMaterial?t:new Ss.LineBasicMaterial(t),this.line=new Ss.Line(this.geom,this.material),this.rootObject.add(this.object3d),this.rootObject.add(this.line),this.rosTopic=void 0,this.processMessageBound=this.processMessage.bind(this),this.subscribe()}unsubscribe(){this.rosTopic&&this.rosTopic.unsubscribe(this.processMessageBound)}subscribe(){this.unsubscribe(),this.rosTopic=new r.Topic({ros:this.ros,name:this.topicName,queue_length:1,messageType:"sensor_msgs/NavSatFix"}),this.rosTopic.subscribe(this.processMessageBound)}processMessage(e){var t=isNaN(e.altitude)?this.altitudeNaN:e.altitude,i=this.convert(e.longitude,e.latitude,t);this.object3d.position.copy(i),this.object3d.updateMatrixWorld(!0),this.vertices.array[3*this.next1]=i.x,this.vertices.array[3*this.next1+1]=i.y,this.vertices.array[3*this.next1+2]=i.z,this.vertices.array[3*this.next2]=i.x,this.vertices.array[3*this.next2+1]=i.y,this.vertices.array[3*this.next2+2]=i.z,this.vertices.needsUpdate=!0,this.next1=(this.next1+1)%this.keep,this.next2=this.next1+this.keep,this.count=Math.min(this.count+1,this.keep),this.geom.setDrawRange(this.next2-this.count,this.count)}}function xc(e,t,i,r){var n,o=0,a=0,s=0,c=e.length,h=t.length,l=((r=r||1)-1)*(i=i||h)*8;for(n=0;n=8&&(a-=8,t[s++]=o>>>a&255,s%i==0&&(n+=Math.ceil((l-a)/6),(a%=8)>0&&(o=xc.e[e.charAt(n)])));return Math.floor(s/i)}xc.S="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",xc.e={};for(var bc=0;bc<64;bc++)xc.e[xc.S.charAt(bc)]=bc;class wc extends Ss.Object3D{constructor(e){super(),e=e||{},this.ros=e.ros,this.topicName=e.topic||"/points",this.throttle_rate=e.throttle_rate||null,this.compression=e.compression||"cbor",this.max_pts=e.max_pts||1e4,this.points=new vc(e),this.rosTopic=void 0,this.buffer=null,this.processMessageBound=this.processMessage.bind(this),this.subscribe()}unsubscribe(){this.rosTopic&&this.rosTopic.unsubscribe(this.processMessageBound)}subscribe(){this.unsubscribe(),this.rosTopic=new r.Topic({ros:this.ros,name:this.topicName,messageType:"sensor_msgs/PointCloud2",throttle_rate:this.throttle_rate,queue_length:1,compression:this.compression}),this.rosTopic.subscribe(this.processMessageBound)}processMessage(e){if(this.points.setup(e.header.frame_id,e.point_step,e.fields)){var t,i=this.points.pointRatio,r=this.max_pts*e.point_step;e.data.buffer?(this.buffer=e.data.slice(0,Math.min(e.data.byteLength,r)),t=Math.min(e.height*e.width/i,this.points.positions.array.length/3)):((!this.buffer||this.buffer.byteLength0?(r=d[0].object,p.intersection=this.lastIntersection=d[0]):r=this.fallbackTarget,r!==this.lastTarget&&e.type.match(/mouse/)){var f=this.notify(r,"mouseover",p);0===f?this.notify(this.lastTarget,"mouseout",p):1===f&&(r=this.fallbackTarget)!==this.lastTarget&&(this.notify(r,"mouseover",p),this.notify(this.lastTarget,"mouseout",p))}r!==this.lastTarget&&e.type.match(/touch/)&&(this.notify(r,e.type,p)?(this.notify(this.lastTarget,"touchleave",p),this.notify(this.lastTarget,"touchend",p)):(r=this.fallbackTarget)!==this.lastTarget&&(this.notify(this.lastTarget,"touchmove",p),this.notify(this.lastTarget,"touchend",p)));this.notify(r,e.type,p),"mousedown"!==e.type&&"touchstart"!==e.type&&"touchmove"!==e.type||(this.dragging=!0),this.lastTarget=r}notify(e,t,i){for(i.type=t,i.cancelBubble=!1,i.continueBubble=!1,i.stopPropagation=function(){i.cancelBubble=!0},i.continuePropagation=function(){i.continueBubble=!0},i.currentTarget=e;i.currentTarget;){if(i.currentTarget.dispatchEvent&&i.currentTarget.dispatchEvent instanceof Function){if(i.currentTarget.dispatchEvent(i),i.cancelBubble)return this.dispatchEvent(i),0;if(i.continueBubble)return 2}i.currentTarget=i.currentTarget.parent}return 1}}class Sc extends Ss.EventDispatcher{constructor(e){super();var t=this,i=(e=e||{}).scene;this.camera=e.camera,this.center=new Ss.Vector3,this.userZoom=!0,this.userZoomSpeed=e.userZoomSpeed||1,this.userRotate=!0,this.userRotateSpeed=e.userRotateSpeed||1,this.autoRotate=e.autoRotate,this.autoRotateSpeed=e.autoRotateSpeed||2,this.displayPanAndZoomFrame=void 0===e.displayPanAndZoomFrame||!!e.displayPanAndZoomFrame,this.lineTypePanAndZoomFrame=e.dashedPanAndZoomFrame||"full",this.camera.up=new Ss.Vector3(0,0,1);var r=1800,n=new Ss.Vector2,o=new Ss.Vector2,a=new Ss.Vector2,s=new Ss.Vector2,c=new Ss.Vector2,h=new Ss.Vector2,l=new Ss.Vector3,u=new Ss.Vector3,p=new Ss.Vector3,d=new Ss.Vector3,f=new Array(2),m=new Array(2);this.phiDelta=0,this.thetaDelta=0,this.scale=1,this.lastPosition=new Ss.Vector3;var v=-1,g=0,y=1,x=2,b=v;function w(e,t,i){var r=new Ss.Vector3;new Ss.Vector3;r.subVectors(t,e.origin);var n=e.direction.dot(i);if(Math.abs(n)0?t.zoomIn():t.zoomOut(),this.showAxes()}}this.axes=new Ks({shaftRadius:.025,headRadius:.07,headLength:.2,lineType:this.lineTypePanAndZoomFrame}),this.displayPanAndZoomFrame&&(i.add(this.axes),this.axes.traverse((function(e){e.visible=!1}))),this.addEventListener("mousedown",(function(e){var i=e.domEvent;switch(i.preventDefault(),i.button){case 0:b=g,n.set(i.clientX,i.clientY);break;case 1:b=x,u=new Ss.Vector3(0,0,1);var r=(new Ss.Matrix4).extractRotation(this.camera.matrix);u.applyMatrix4(r),l=t.center.clone(),p=t.camera.position.clone(),d=w(e.mouseRay,l,u);break;case 2:b=y,s.set(i.clientX,i.clientY)}this.showAxes()})),this.addEventListener("mouseup",(function(e){t.userRotate&&(b=v)})),this.addEventListener("mousemove",(function(e){var i=e.domEvent;if(b===g)o.set(i.clientX,i.clientY),a.subVectors(o,n),t.rotateLeft(2*Math.PI*a.x/r*t.userRotateSpeed),t.rotateUp(2*Math.PI*a.y/r*t.userRotateSpeed),n.copy(o),this.showAxes();else if(b===y)c.set(i.clientX,i.clientY),h.subVectors(c,s),h.y>0?t.zoomIn():t.zoomOut(),s.copy(c),this.showAxes();else if(b===x){var f=w(e.mouseRay,t.center,u);if(!f)return;var m=(new Ss.Vector3).subVectors(d.clone(),f.clone());t.center.addVectors(l.clone(),m.clone()),t.camera.position.addVectors(p.clone(),m.clone()),t.update(),t.camera.updateMatrixWorld(),this.showAxes()}})),this.addEventListener("touchstart",(function(e){var i=e.domEvent;switch(i.touches.length){case 1:b=g,n.set(i.touches[0].pageX-window.scrollX,i.touches[0].pageY-window.scrollY);break;case 2:b=v,u=new Ss.Vector3(0,0,1);var r=(new Ss.Matrix4).extractRotation(this.camera.matrix);u.applyMatrix4(r),l=t.center.clone(),p=t.camera.position.clone(),d=w(e.mouseRay,l,u),f[0]=new Ss.Vector2(i.touches[0].pageX,i.touches[0].pageY),f[1]=new Ss.Vector2(i.touches[1].pageX,i.touches[1].pageY),m[0]=new Ss.Vector2(0,0),m[1]=new Ss.Vector2(0,0)}this.showAxes(),i.preventDefault()})),this.addEventListener("touchmove",(function(e){var i=e.domEvent;if(b===g)o.set(i.touches[0].pageX-window.scrollX,i.touches[0].pageY-window.scrollY),a.subVectors(o,n),t.rotateLeft(2*Math.PI*a.x/r*t.userRotateSpeed),t.rotateUp(2*Math.PI*a.y/r*t.userRotateSpeed),n.copy(o),this.showAxes();else{if(m[0].set(f[0].x-i.touches[0].pageX,f[0].y-i.touches[0].pageY),m[1].set(f[1].x-i.touches[1].pageX,f[1].y-i.touches[1].pageY),m[0].lengthSq()>10&&m[1].lengthSq()>10&&(f[0].set(i.touches[0].pageX,i.touches[0].pageY),f[1].set(i.touches[1].pageX,i.touches[1].pageY),m[0].dot(m[1])>0&&b!==y?b=x:m[0].dot(m[1])<0&&b!==x&&(b=y),b===y)){var s=new Ss.Vector2;s.subVectors(f[0],f[1]),m[0].dot(s)<0&&m[1].dot(s)>0?t.zoomOut():m[0].dot(s)>0&&m[1].dot(s)<0&&t.zoomIn()}if(b===x){var c=w(e.mouseRay,t.center,u);if(!c)return;var h=(new Ss.Vector3).subVectors(d.clone(),c.clone());t.center.addVectors(l.clone(),h.clone()),t.camera.position.addVectors(p.clone(),h.clone()),t.update(),t.camera.updateMatrixWorld()}this.showAxes(),i.preventDefault()}})),this.addEventListener("touchend",(function(e){var t=e.domEvent;1===t.touches.length&&b!==g?(b=g,n.set(t.touches[0].pageX-window.scrollX,t.touches[0].pageY-window.scrollY)):b=v})),this.addEventListener("mousewheel",_),this.addEventListener("DOMMouseScroll",_)}showAxes(){var e=this;this.axes.traverse((function(e){e.visible=!0})),this.hideTimeout&&clearTimeout(this.hideTimeout),this.hideTimeout=setTimeout((function(){e.axes.traverse((function(e){e.visible=!1})),e.hideTimeout=!1}),1e3)}rotateLeft(e){void 0===e&&(e=2*Math.PI/60/60*this.autoRotateSpeed),this.thetaDelta-=e}rotateRight(e){void 0===e&&(e=2*Math.PI/60/60*this.autoRotateSpeed),this.thetaDelta+=e}rotateUp(e){void 0===e&&(e=2*Math.PI/60/60*this.autoRotateSpeed),this.phiDelta-=e}rotateDown(e){void 0===e&&(e=2*Math.PI/60/60*this.autoRotateSpeed),this.phiDelta+=e}zoomIn(e){void 0===e&&(e=Math.pow(.95,this.userZoomSpeed)),this.scale/=e}zoomOut(e){void 0===e&&(e=Math.pow(.95,this.userZoomSpeed)),this.scale*=e}update(){var e=this.camera.position,t=e.clone().sub(this.center),i=Math.atan2(t.y,t.x),r=Math.atan2(Math.sqrt(t.y*t.y+t.x*t.x),t.z);this.autoRotate&&this.rotateLeft(2*Math.PI/60/60*this.autoRotateSpeed),i+=this.thetaDelta,r+=this.phiDelta;var n=1e-6;r=Math.max(n,Math.min(Math.PI-n,r));var o=t.length();t.set(o*Math.sin(r)*Math.cos(i),o*Math.sin(r)*Math.sin(i),o*Math.cos(r)),t.multiplyScalar(this.scale),e.copy(this.center).add(t),this.camera.lookAt(this.center),o=t.length(),this.axes.position.copy(this.center),this.axes.scale.set(.05*o,.05*o,.05*o),this.axes.updateMatrixWorld(!0),this.thetaDelta=0,this.phiDelta=0,this.scale=1,this.lastPosition.distanceTo(this.camera.position)>0&&(this.dispatchEvent({type:"change"}),this.lastPosition.copy(this.camera.position))}}return e.Arrow=Ns,e.Arrow2=Js,e.Axes=Ks,e.ColorOcTree=cc,e.DepthCloud=Ps,e.Grid=Qs,e.Highlighter=Ec,e.INTERACTIVE_MARKER_BUTTON=2,e.INTERACTIVE_MARKER_BUTTON_CLICK=3,e.INTERACTIVE_MARKER_FIXED=1,e.INTERACTIVE_MARKER_INHERIT=0,e.INTERACTIVE_MARKER_KEEP_ALIVE=0,e.INTERACTIVE_MARKER_MENU=1,e.INTERACTIVE_MARKER_MENU_SELECT=2,e.INTERACTIVE_MARKER_MOUSE_DOWN=4,e.INTERACTIVE_MARKER_MOUSE_UP=5,e.INTERACTIVE_MARKER_MOVE_3D=7,e.INTERACTIVE_MARKER_MOVE_AXIS=3,e.INTERACTIVE_MARKER_MOVE_PLANE=4,e.INTERACTIVE_MARKER_MOVE_ROTATE=6,e.INTERACTIVE_MARKER_MOVE_ROTATE_3D=9,e.INTERACTIVE_MARKER_NONE=0,e.INTERACTIVE_MARKER_POSE_UPDATE=1,e.INTERACTIVE_MARKER_ROTATE_3D=8,e.INTERACTIVE_MARKER_ROTATE_AXIS=5,e.INTERACTIVE_MARKER_VIEW_FACING=2,e.InteractiveMarker=js,e.InteractiveMarkerClient=class{constructor(e){e=e||{},this.ros=e.ros,this.tfClient=e.tfClient,this.topicName=e.topic,this.path=e.path||"/",this.camera=e.camera,this.rootObject=e.rootObject||new Ss.Object3D,this.loader=e.loader,this.menuFontSize=e.menuFontSize||"0.8em",this.interactiveMarkers={},this.updateTopic=null,this.feedbackTopic=null,this.processUpdateBound=this.processUpdate.bind(this),this.topicName&&this.subscribe(this.topicName)}subscribe(e){this.unsubscribe(),this.updateTopic=new r.Topic({ros:this.ros,name:e+"/tunneled/update",messageType:"visualization_msgs/InteractiveMarkerUpdate",compression:"png"}),this.updateTopic.subscribe(this.processUpdateBound),this.feedbackTopic=new r.Topic({ros:this.ros,name:e+"/feedback",messageType:"visualization_msgs/InteractiveMarkerFeedback",compression:"png"}),this.feedbackTopic.advertise(),this.initService=new r.Service({ros:this.ros,name:e+"/tunneled/get_init",serviceType:"demo_interactive_markers/GetInit"});var t=new r.ServiceRequest({});this.initService.callService(t,this.processInit.bind(this))}unsubscribe(){for(var e in this.updateTopic&&this.updateTopic.unsubscribe(this.processUpdateBound),this.feedbackTopic&&this.feedbackTopic.unadvertise(),this.interactiveMarkers)this.eraseIntMarker(e);this.interactiveMarkers={}}processInit(e){var t=e.msg;for(var i in t.erases=[],this.interactiveMarkers)t.erases.push(i);t.poses=[],this.processUpdate(t)}processUpdate(e){e.erases.forEach((function(e){this.eraseIntMarker(e)})),e.poses.forEach((function(e){var t=this.interactiveMarkers[e.name];t&&t.setPoseFromServer(e.pose)})),e.markers.forEach((function(e){var t=this.interactiveMarkers[e.name];t&&this.eraseIntMarker(t.name);var i=new Ys({message:e,feedbackTopic:this.feedbackTopic,tfClient:this.tfClient,menuFontSize:this.menuFontSize});this.interactiveMarkers[e.name]=i;var r=new js({handle:i,camera:this.camera,path:this.path,loader:this.loader});r.name=e.name,this.rootObject.add(r),i.on("pose",(function(e){r.onServerSetPose({pose:e})})),r.addEventListener("user-pose-change",i.setPoseFromClientBound),r.addEventListener("user-mousedown",i.onMouseDownBound),r.addEventListener("user-mouseup",i.onMouseUpBound),r.addEventListener("user-button-click",i.onButtonClickBound),r.addEventListener("menu-select",i.onMenuSelectBound),i.subscribeTf()}))}eraseIntMarker(e){if(this.interactiveMarkers[e]){var t=this.rootObject.getObjectByName(e);this.rootObject.remove(t);var i=this.interactiveMarkers[e];i.unsubscribeTf(),t.removeEventListener("user-pose-change",i.setPoseFromClientBound),t.removeEventListener("user-mousedown",i.onMouseDownBound),t.removeEventListener("user-mouseup",i.onMouseUpBound),t.removeEventListener("user-button-click",i.onButtonClickBound),t.removeEventListener("menu-select",i.onMenuSelectBound),delete this.interactiveMarkers[e],t.dispose()}}},e.InteractiveMarkerControl=Gs,e.InteractiveMarkerHandle=Ys,e.InteractiveMarkerMenu=Vs,e.LaserScan=gc,e.MARKER_ARROW=0,e.MARKER_CUBE=1,e.MARKER_CUBE_LIST=6,e.MARKER_CYLINDER=3,e.MARKER_LINE_LIST=5,e.MARKER_LINE_STRIP=4,e.MARKER_MESH_RESOURCE=10,e.MARKER_POINTS=8,e.MARKER_SPHERE=2,e.MARKER_SPHERE_LIST=7,e.MARKER_TEXT_VIEW_FACING=9,e.MARKER_TRIANGLE_LIST=11,e.Marker=ks,e.MarkerArrayClient=class extends qs{constructor(e){super(),e=e||{},this.ros=e.ros,this.topicName=e.topic,this.tfClient=e.tfClient,this.rootObject=e.rootObject||new Ss.Object3D,this.path=e.path||"/",this.markers={},this.rosTopic=void 0,this.processMessageBound=this.processMessage.bind(this),this.subscribe()}subscribe(){this.unsubscribe(),this.rosTopic=new r.Topic({ros:this.ros,name:this.topicName,messageType:"visualization_msgs/MarkerArray",compression:"png"}),this.rosTopic.subscribe(this.processMessageBound)}processMessage(e){e.markers.forEach(function(e){var t=e.ns+e.id;if(0===e.action){var i=!1;if(t in this.markers&&((i=this.markers[t].children[0].update(e))||this.removeMarker(t)),!i){var r=new ks({message:e,path:this.path});this.markers[t]=new Zs({frameID:e.header.frame_id,tfClient:this.tfClient,object:r}),this.rootObject.add(this.markers[t])}}else if(1===e.action)console.warn('Received marker message with deprecated action identifier "1"');else if(2===e.action)this.removeMarker(t);else if(3===e.action){for(var n in this.markers)this.removeMarker(n);this.markers={}}else console.warn('Received marker message with unknown action identifier "'+e.action+'"')}.bind(this)),this.emit("change")}unsubscribe(){this.rosTopic&&this.rosTopic.unsubscribe(this.processMessageBound)}removeMarker(e){var t=this.markers[e];t&&(t.unsubscribeTf(),this.rootObject.remove(t),t.children.forEach((e=>{e.dispose()})),delete this.markers[e])}},e.MarkerClient=class extends qs{constructor(e){super(),e=e||{},this.ros=e.ros,this.topicName=e.topic,this.tfClient=e.tfClient,this.rootObject=e.rootObject||new Ss.Object3D,this.path=e.path||"/",this.lifetime=e.lifetime||0,this.markers={},this.rosTopic=void 0,this.updatedTime={},this.processMessageBound=this.processMessage.bind(this),this.subscribe()}unsubscribe(){this.rosTopic&&this.rosTopic.unsubscribe(this.processMessageBound)}checkTime(e){if((new Date).getTime()-this.updatedTime[e]>this.lifetime)this.removeMarker(e),this.emit("change");else{var t=this;setTimeout((function(){t.checkTime(e)}),100)}}subscribe(){this.unsubscribe(),this.rosTopic=new r.Topic({ros:this.ros,name:this.topicName,messageType:"visualization_msgs/Marker",compression:"png"}),this.rosTopic.subscribe(this.processMessageBound)}processMessage(e){var t=e.ns+e.id,i=this.markers[t];if(this.updatedTime[t]=(new Date).getTime(),i?this.removeMarker(t):this.lifetime&&this.checkTime(e.ns+e.id),0===e.action){var r=new ks({message:e,path:this.path});this.markers[t]=new Zs({frameID:e.header.frame_id,tfClient:this.tfClient,object:r}),this.rootObject.add(this.markers[t])}this.emit("change")}removeMarker(e){var t=this.markers[e];t&&(t.unsubscribeTf(),this.rootObject.remove(t),t.children.forEach((e=>{e.dispose()})),delete this.markers[e])}},e.MeshLoader=Bs,e.MeshResource=Fs,e.MouseHandler=Tc,e.NavSatFix=yc,e.OcTree=sc,e.OcTreeClient=class extends qs{constructor(e){super(),e=e||{},this.ros=e.ros,this.topicName=e.topic||"/octomap",this.compression=e.compression||"cbor",this.continuous=e.continuous,this.tfClient=e.tfClient,this.rootObject=e.rootObject||new Ss.Object3D,this.offsetPose=e.offsetPose||new r.Pose,this.options={},void 0!==e.color&&(this.options.color=e.color),void 0!==e.opacity&&(this.options.opacity=e.opacity),void 0!==e.colorMode&&(this.options.colorMode=e.colorMode),void 0!==e.palette&&(this.options.palette=e.palette),void 0!==e.paletteScale&&(this.options.paletteScale=e.palette),void 0!==e.voxelRenderMode&&(this.options.voxelRenderMode=e.voxelRenderMode),this.currentMap=null,this.rosTopic=void 0,this.processMessageBound=this.processMessage.bind(this),this.subscribe()}unsubscribe(){this.rosTopic&&this.rosTopic.unsubscribe(this.processMessageBound)}subscribe(){this.unsubscribe(),this.rosTopic=new r.Topic({ros:this.ros,name:this.topicName,messageType:"octomap_msgs/Octomap",queue_length:1,compression:this.compression}),this.rosTopic.subscribe(this.processMessageBound)}processMessage(e){this.currentMap&&this.currentMap.tfClient&&this.currentMap.unsubscribeTf(),this._processMessagePrivate(e),this.continuous||this.rosTopic.unsubscribe(this.processMessageBound)}_loadOcTree(e){return new Promise(function(t,i){const r=Object.assign({resolution:e.resolution},this.options);let n=null;if(e.binary)n=new ac(r),n.readBinary(e.data);else{const t={OcTree:sc,ColorOcTree:cc};e.id in t&&(console.log(e.id,t),n=new t[e.id](r),n.read(e.data))}n.buildGeometry(),t(n)}.bind(this))}_processMessagePrivate(e){this._loadOcTree(e).then(function(t){const i=this.sceneNode;this.tfClient?(this.currentMap=t,this.sceneNode=new Zs({frameID:e.header.frame_id,tfClient:this.tfClient,object:t.object,pose:this.offsetPose})):(this.sceneNode=t.object,this.currentMap=t),this.rootObject.remove(i),this.rootObject.add(this.sceneNode),this.emit("change")}.bind(this))}},e.OccupancyGrid=$s,e.OccupancyGridClient=class extends qs{constructor(e){super(),e=e||{},this.ros=e.ros,this.topicName=e.topic||"/map",this.compression=e.compression||"cbor",this.continuous=e.continuous,this.tfClient=e.tfClient,this.rootObject=e.rootObject||new Ss.Object3D,this.offsetPose=e.offsetPose||new r.Pose,this.color=e.color||{r:255,g:255,b:255},this.opacity=e.opacity||1,this.currentGrid=null,this.rosTopic=void 0,this.processMessageBound=this.processMessage.bind(this),this.subscribe()}unsubscribe(){this.rosTopic&&this.rosTopic.unsubscribe(this.processMessageBound)}subscribe(){this.unsubscribe(),this.rosTopic=new r.Topic({ros:this.ros,name:this.topicName,messageType:"nav_msgs/OccupancyGrid",queue_length:1,compression:this.compression}),this.sceneNode=null,this.rosTopic.subscribe(this.processMessageBound)}processMessage(e){this.currentGrid&&(this.tfClient?(this.sceneNode.unsubscribeTf(),this.sceneNode.remove(this.currentGrid)):this.rootObject.remove(this.currentGrid),this.currentGrid.dispose());var t=new $s({message:e,color:this.color,opacity:this.opacity});this.tfClient?(this.currentGrid=t,null===this.sceneNode?(this.sceneNode=new Zs({frameID:e.header.frame_id,tfClient:this.tfClient,object:t,pose:this.offsetPose}),this.rootObject.add(this.sceneNode)):this.sceneNode.add(this.currentGrid)):(this.sceneNode=this.currentGrid=t,this.rootObject.add(this.currentGrid)),this.emit("change"),this.continuous||this.rosTopic.unsubscribe(this.processMessageBound)}},e.Odometry=hc,e.OrbitControls=Sc,e.Path=lc,e.Point=uc,e.PointCloud2=wc,e.Points=vc,e.Polygon=pc,e.Pose=dc,e.PoseArray=fc,e.PoseWithCovariance=mc,e.SceneNode=Zs,e.TFAxes=_c,e.TriangleList=zs,e.Urdf=Mc,e.UrdfClient=class{constructor(e){var t=(e=e||{}).ros;this.param=e.param||"robot_description",this.path=e.path||"/",this.tfClient=e.tfClient,this.rootObject=e.rootObject||new Ss.Object3D,this.tfPrefix=e.tfPrefix||"",this.loader=e.loader,new r.Param({ros:t,name:this.param}).get(function(e){var t=new r.UrdfModel({string:e});this.urdf=new Mc({urdfModel:t,path:this.path,tfClient:this.tfClient,tfPrefix:this.tfPrefix,loader:this.loader}),this.rootObject.add(this.urdf)}.bind(this))}},e.Viewer=class{constructor(e){var t=(e=e||{}).divID,i=e.elem,r=e.width,n=e.height,o=e.background||"#111111",a=e.antialias,s=e.intensity||.66,c=e.near||.01,h=e.far||1e3,l=e.alpha||1,u=e.cameraPose||{x:3,y:3,z:3},p=e.cameraZoomSpeed||.5,d=void 0===e.displayPanAndZoomFrame||!!e.displayPanAndZoomFrame,f=e.lineTypePanAndZoomFrame||"full";this.renderer=new Ss.WebGLRenderer({antialias:a,alpha:!0}),this.renderer.setClearColor(parseInt(o.replace("#","0x"),16),l),this.renderer.sortObjects=!1,this.renderer.setSize(r,n),this.renderer.shadowMap.enabled=!1,this.renderer.autoClear=!1,this.scene=new Ss.Scene,this.camera=new Ss.PerspectiveCamera(40,r/n,c,h),this.camera.position.x=u.x,this.camera.position.y=u.y,this.camera.position.z=u.z,this.cameraControls=new Sc({scene:this.scene,camera:this.camera,displayPanAndZoomFrame:d,lineTypePanAndZoomFrame:f}),this.cameraControls.userZoomSpeed=p,this.scene.add(new Ss.AmbientLight(5592405)),this.directionalLight=new Ss.DirectionalLight(16777215,s),this.scene.add(this.directionalLight),this.selectableObjects=new Ss.Group,this.scene.add(this.selectableObjects);var m=new Tc({renderer:this.renderer,camera:this.camera,rootObject:this.selectableObjects,fallbackTarget:this.cameraControls});this.highlighter=new Ec({mouseHandler:m}),this.stopped=!0,this.animationRequestId=void 0,(i||document.getElementById(t)).appendChild(this.renderer.domElement),this.start()}start(){this.stopped=!1,this.draw()}draw(){this.stopped||(this.cameraControls.update(),this.directionalLight.position.normalize(),this.renderer.clear(!0,!0,!0),this.renderer.render(this.scene,this.camera),this.highlighter.renderHighlights(this.scene,this.renderer,this.camera),this.animationRequestId=requestAnimationFrame(this.draw.bind(this)))}stop(){this.stopped||cancelAnimationFrame(this.animationRequestId),this.stopped=!0}addObject(e,t){t?this.selectableObjects.add(e):this.scene.add(e)}resize(e,t){this.camera.aspect=e/t,this.camera.updateProjectionMatrix(),this.renderer.setSize(e,t)}},e.closestAxisPoint=Cs,e.findClosestPoint=Rs,e.intersectPlane=Ls,e.makeColorMaterial=As,Object.defineProperty(e,"__esModule",{value:!0}),e}({},ROSLIB); + */var qs,Ys=(Ws||(Ws=1,qs=Xs,function(e){var t=Object.hasOwnProperty,i=Array.isArray?Array.isArray:function(e){return"[object Array]"===Object.prototype.toString.call(e)},r="object"==typeof process&&"function"==typeof process.nextTick,n="function"==typeof Symbol,o="object"==typeof Reflect,a="function"==typeof setImmediate?setImmediate:setTimeout,s=n?o&&"function"==typeof Reflect.ownKeys?Reflect.ownKeys:function(e){var t=Object.getOwnPropertyNames(e);return t.push.apply(t,Object.getOwnPropertySymbols(e)),t}:Object.keys;function c(){this._events={},this._conf&&h.call(this,this._conf)}function h(t){t&&(this._conf=t,t.delimiter&&(this.delimiter=t.delimiter),t.maxListeners!==e&&(this._maxListeners=t.maxListeners),t.wildcard&&(this.wildcard=t.wildcard),t.newListener&&(this._newListener=t.newListener),t.removeListener&&(this._removeListener=t.removeListener),t.verboseMemoryLeak&&(this.verboseMemoryLeak=t.verboseMemoryLeak),t.ignoreErrors&&(this.ignoreErrors=t.ignoreErrors),this.wildcard&&(this.listenerTree={}))}function l(e,t){var i="(node) warning: possible EventEmitter memory leak detected. "+e+" listeners added. Use emitter.setMaxListeners() to increase limit.";if(this.verboseMemoryLeak&&(i+=" Event name: "+t+"."),"undefined"!=typeof process&&process.emitWarning){var r=new Error(i);r.name="MaxListenersExceededWarning",r.emitter=this,r.count=e,process.emitWarning(r)}else console.error(i),console.trace&&console.trace()}var u=function(e,t,i){var r=arguments.length;switch(r){case 0:return[];case 1:return[e];case 2:return[e,t];case 3:return[e,t,i];default:for(var n=new Array(r);r--;)n[r]=arguments[r];return n}};function p(t,i){for(var r={},n=t.length,o=i?value.length:0,a=0;a0;)if(o===e[a])return r;n(t)}}Object.assign(d.prototype,{subscribe:function(e,t,i){var r=this,n=this._target,o=this._emitter,a=this._listeners,s=function(){var r=u.apply(null,arguments),a={data:r,name:t,original:e};if(i){var s=i.call(n,a);!1!==s&&o.emit.apply(o,[a.name].concat(r))}else o.emit.apply(o,[t].concat(r))};if(a[e])throw Error("Event '"+e+"' is already listening");this._listenersCount++,o._newListener&&o._removeListener&&!r._onNewListener?(this._onNewListener=function(i){i===t&&null===a[e]&&(a[e]=s,r._on.call(n,e,s))},o.on("newListener",this._onNewListener),this._onRemoveListener=function(i){i===t&&!o.hasListeners(i)&&a[e]&&(a[e]=null,r._off.call(n,e,s))},a[e]=null,o.on("removeListener",this._onRemoveListener)):(a[e]=s,r._on.call(n,e,s))},unsubscribe:function(e){var t,i,r,n=this,o=this._listeners,a=this._emitter,c=this._off,h=this._target;if(e&&"string"!=typeof e)throw TypeError("event must be a string");function l(){n._onNewListener&&(a.off("newListener",n._onNewListener),a.off("removeListener",n._onRemoveListener),n._onNewListener=null,n._onRemoveListener=null);var e=b.call(a,n);a._observers.splice(e,1)}if(e){if(!(t=o[e]))return;c.call(h,e,t),delete o[e],--this._listenersCount||l()}else{for(r=(i=s(o)).length;r-- >0;)e=i[r],c.call(h,e,o[e]);this._listeners={},this._listenersCount=0,l()}}});var g=v(["function"]),y=v(["object","function"]);function x(e,t,i){var r,n,o,a=0,s=new e((function(c,h,l){function u(){n&&(n=null),a&&(clearTimeout(a),a=0)}i=f(i,{timeout:0,overload:!1},{timeout:function(e,t){return("number"!=typeof(e*=1)||e<0||!Number.isFinite(e))&&t("timeout must be a positive number"),e}}),r=!i.overload&&"function"==typeof e.prototype.cancel&&"function"==typeof l;var p=function(e){u(),c(e)},d=function(e){u(),h(e)};r?t(p,d,l):(n=[function(e){d(e||Error("canceled"))}],t(p,d,(function(e){if(o)throw Error("Unable to subscribe on cancel event asynchronously");if("function"!=typeof e)throw TypeError("onCancel callback must be a function");n.push(e)})),o=!0),i.timeout>0&&(a=setTimeout((function(){var e=Error("timeout");e.code="ETIMEDOUT",a=0,s.cancel(e),h(e)}),i.timeout))}));return r||(s.cancel=function(e){if(n){for(var t=n.length,i=1;i0;)"_listeners"!==(d=y[c])&&(x=w(e,t,i[d],r+1,n))&&(b?b.push.apply(b,x):b=x);return b}if("**"===_){for((g=r+1===n||r+2===n&&"*"===M)&&i._listeners&&(b=w(e,t,i,n,n)),c=(y=s(i)).length;c-- >0;)"_listeners"!==(d=y[c])&&("*"===d||"**"===d?(i[d]._listeners&&!g&&(x=w(e,t,i[d],n,n))&&(b?b.push.apply(b,x):b=x),x=w(e,t,i[d],r,n)):x=w(e,t,i[d],d===M?r+2:r,n),x&&(b?b.push.apply(b,x):b=x));return b}i[_]&&(b=w(e,t,i[_],r+1,n))}if((f=i["*"])&&w(e,t,f,r+1,n),m=i["**"])if(r0;)"_listeners"!==(d=y[c])&&(d===M?w(e,t,m[d],r+2,n):d===_?w(e,t,m[d],r+1,n):((v={})[d]=m[d],w(e,t,{"**":v},r+1,n)));else m._listeners?w(e,t,m,n,n):m["*"]&&m["*"]._listeners&&w(e,t,m["*"],n,n);return b}function _(e,t,i){var r,n,o=0,a=0,s=this.delimiter,c=s.length;if("string"==typeof e)if(-1!==(r=e.indexOf(s))){n=new Array(5);do{n[o++]=e.slice(a,r),a=r+c}while(-1!==(r=e.indexOf(s,a)));n[o++]=e.slice(a)}else n=[e],o=1;else n=e,o=e.length;if(o>1)for(r=0;r+10&&u._listeners.length>this._maxListeners&&(u._listeners.warned=!0,l.call(this,u._listeners.length,h))):u._listeners=t,!0;return!0}function M(e,t,i,r){for(var n,o,a,c,h=s(e),l=h.length,u=e._listeners;l-- >0;)n=e[o=h[l]],a="_listeners"===o?i:i?i.concat(o):[o],c=r||"symbol"==typeof o,u&&t.push(c?a:a.join(this.delimiter)),"object"==typeof n&&M.call(this,n,t,a,c);return t}function E(e){for(var t,i,r,n=s(e),o=n.length;o-- >0;)(t=e[i=n[o]])&&(r=!0,"_listeners"===i||E(t)||delete e[i]);return r}function T(e,t,i){this.emitter=e,this.event=t,this.listener=i}function S(t,i,n){if(!0===n)s=!0;else if(!1===n)o=!0;else{if(!n||"object"!=typeof n)throw TypeError("options should be an object or true");var o=n.async,s=n.promisify,c=n.nextTick,h=n.objectify}if(o||c||s){var l=i,u=i._origin||i;if(c&&!r)throw Error("process.nextTick is not supported");s===e&&(s="AsyncFunction"===i.constructor.name),i=function(){var e=arguments,t=this,i=this.event;return s?c?Promise.resolve():new Promise((function(e){a(e)})).then((function(){return t.event=i,l.apply(t,e)})):(c?process.nextTick:a)((function(){t.event=i,l.apply(t,e)}))},i._async=!0,i._origin=u}return[i,h?new T(this,t,i):this]}function A(e){this._events={},this._newListener=!1,this._removeListener=!1,this.verboseMemoryLeak=!1,h.call(this,e)}T.prototype.off=function(){return this.emitter.off(this.event,this.listener),this},A.EventEmitter2=A,A.prototype.listenTo=function(t,r,n){if("object"!=typeof t)throw TypeError("target musts be an object");var o=this;function a(e){if("object"!=typeof e)throw TypeError("events must be an object");var i,r=n.reducers,a=b.call(o,t);i=-1===a?new d(o,t,n):o._observers[a];for(var c,h=s(e),l=h.length,u="function"==typeof r,p=0;p0;)r=i[n],e&&r._target!==e||(r.unsubscribe(t),o=!0);return o},A.prototype.delimiter=".",A.prototype.setMaxListeners=function(t){t!==e&&(this._maxListeners=t,this._conf||(this._conf={}),this._conf.maxListeners=t)},A.prototype.getMaxListeners=function(){return this._maxListeners},A.prototype.event="",A.prototype.once=function(e,t,i){return this._once(e,t,!1,i)},A.prototype.prependOnceListener=function(e,t,i){return this._once(e,t,!0,i)},A.prototype._once=function(e,t,i,r){return this._many(e,1,t,i,r)},A.prototype.many=function(e,t,i,r){return this._many(e,t,i,!1,r)},A.prototype.prependMany=function(e,t,i,r){return this._many(e,t,i,!0,r)},A.prototype._many=function(e,t,i,r,n){var o=this;if("function"!=typeof i)throw new Error("many only accepts instances of Function");function a(){return 0==--t&&o.off(e,a),i.apply(this,arguments)}return a._origin=i,this._on(e,a,r,n)},A.prototype.emit=function(){if(!this._events&&!this._all)return!1;this._events||c.call(this);var e,t,i,r,o,a,s=arguments[0],h=this.wildcard;if("newListener"===s&&!this._newListener&&!this._events.newListener)return!1;if(h&&(e=s,"newListener"!==s&&"removeListener"!==s&&"object"==typeof s)){if(i=s.length,n)for(r=0;r3)for(t=new Array(u-1),o=1;o3)for(i=new Array(p-1),a=1;a0&&this._events[t].length>this._maxListeners&&(this._events[t].warned=!0,l.call(this,this._events[t].length,t))):this._events[t]=i,a)},A.prototype.off=function(e,t){if("function"!=typeof t)throw new Error("removeListener only takes instances of Function");var r,n=[];if(this.wildcard){var o="string"==typeof e?e.split(this.delimiter):e.slice();if(!(n=w.call(this,null,o,this.listenerTree,0)))return this}else{if(!this._events[e])return this;r=this._events[e],n.push({_listeners:r})}for(var a=0;a0){for(i=0,r=(t=this._all).length;i0;)"function"==typeof(r=c[i[o]])?n.push(r):n.push.apply(n,r);return n}if(this.wildcard){if(!(a=this.listenerTree))return[];var h=[],l="string"==typeof t?t.split(this.delimiter):t.slice();return w.call(this,h,l,a,0),h}return c&&(r=c[t])?"function"==typeof r?[r]:r:[]},A.prototype.eventNames=function(e){var t=this._events;return this.wildcard?M.call(this,this.listenerTree,[],null,e):t?s(t):[]},A.prototype.listenerCount=function(e){return this.listeners(e).length},A.prototype.hasListeners=function(t){if(this.wildcard){var i=[],r="string"==typeof t?t.split(this.delimiter):t.slice();return w.call(this,i,r,this.listenerTree,0),i.length>0}var n=this._events,o=this._all;return!!(o&&o.length||n&&(t===e?s(n).length:n[t]))},A.prototype.listenersAny=function(){return this._all?this._all:[]},A.prototype.waitFor=function(t,i){var r=this,n=typeof i;return"number"===n?i={timeout:i}:"function"===n&&(i={filter:i}),x((i=f(i,{timeout:0,filter:e,handleError:!1,Promise:Promise,overload:!1},{filter:g,Promise:m})).Promise,(function(e,n,o){function a(){var o=i.filter;if(!o||o.apply(r,arguments))if(r.off(t,a),i.handleError){var s=arguments[0];s?n(s):e(u.apply(null,arguments).slice(1))}else e(u.apply(null,arguments))}o((function(){r.off(t,a)})),r._on(t,a,!1)}),{timeout:i.timeout,overload:i.overload})};var L=A.prototype;Object.defineProperties(A,{defaultMaxListeners:{get:function(){return L._maxListeners},set:function(e){if("number"!=typeof e||e<0||Number.isNaN(e))throw TypeError("n must be a non-negative number");L._maxListeners=e},enumerable:!0},once:{value:function(e,t,i){return x((i=f(i,{Promise:Promise,timeout:0,overload:!1},{Promise:m})).Promise,(function(i,r,n){var o;if("function"==typeof e.addEventListener)return o=function(){i(u.apply(null,arguments))},n((function(){e.removeEventListener(t,o)})),void e.addEventListener(t,o,{once:!0});var a,s=function(){a&&e.removeListener("error",a),i(u.apply(null,arguments))};"error"!==t&&(a=function(i){e.removeListener(t,s),r(i)},e.once("error",a)),n((function(){a&&e.removeListener("error",a),e.removeListener(t,s)})),e.once(t,s)}),{timeout:i.timeout,overload:i.overload})},writable:!0,configurable:!0}}),Object.defineProperties(L,{_maxListeners:{value:10,writable:!0,configurable:!0},_observers:{value:null,writable:!0,configurable:!0}}),qs.exports=A}()),Xs.exports),Zs=Hs(Ys);class Js extends Zs{constructor(e){super(),e=e||{},this.message=e.message,this.feedbackTopic=e.feedbackTopic,this.tfClient=e.tfClient,this.menuFontSize=e.menuFontSize||"0.8em",this.name=this.message.name,this.header=this.message.header,this.controls=this.message.controls,this.menuEntries=this.message.menu_entries,this.dragging=!1,this.timeoutHandle=null,this.tfTransform=new r.Transform,this.pose=new r.Pose,this.setPoseFromClientBound=this.setPoseFromClient.bind(this),this.onMouseDownBound=this.onMouseDown.bind(this),this.onMouseUpBound=this.onMouseUp.bind(this),this.onButtonClickBound=this.onButtonClick.bind(this),this.onMenuSelectBound=this.onMenuSelect.bind(this),this.setPoseFromServer(this.message.pose),this.tfUpdateBound=this.tfUpdate.bind(this)}subscribeTf(){0===this.message.header.stamp.secs&&0===this.message.header.stamp.nsecs&&this.tfClient.subscribe(this.message.header.frame_id,this.tfUpdateBound)}unsubscribeTf(){this.tfClient.unsubscribe(this.message.header.frame_id,this.tfUpdateBound)}emitServerPoseUpdate(){var e=new r.Pose(this.pose);e.applyTransform(this.tfTransform),this.emit("pose",e)}setPoseFromServer(e){this.pose=new r.Pose(e),this.emitServerPoseUpdate()}tfUpdate(e){this.tfTransform=new r.Transform(e),this.emitServerPoseUpdate()}setPoseFromClient(e){this.pose=new r.Pose(e);var t=this.tfTransform.clone();t.rotation.invert(),t.translation.multiplyQuaternion(t.rotation),t.translation.x*=-1,t.translation.y*=-1,t.translation.z*=-1,this.pose.applyTransform(t),this.sendFeedback(1,void 0,0,e.controlName),this.dragging&&(this.timeoutHandle&&clearTimeout(this.timeoutHandle),this.timeoutHandle=setTimeout(this.setPoseFromClient.bind(this,e),250))}onButtonClick(e){this.sendFeedback(3,e.clickPosition,0,e.controlName)}onMouseDown(e){this.sendFeedback(4,e.clickPosition,0,e.controlName),this.dragging=!0}onMouseUp(e){this.sendFeedback(5,e.clickPosition,0,e.controlName),this.dragging=!1,this.timeoutHandle&&clearTimeout(this.timeoutHandle)}onMenuSelect(e){this.sendFeedback(2,void 0,e.id,e.controlName)}sendFeedback(e,t,i,r){var n=void 0!==t;t=t||{x:0,y:0,z:0};var o={header:this.header,client_id:this.clientID,marker_name:this.name,control_name:r,event_type:e,pose:this.pose,mouse_point:t,mouse_point_valid:n,menu_entry_id:i};this.feedbackTopic.publish(o)}}class Ks extends Ss.Object3D{constructor(e){super(),e=e||{},this.tfClient=e.tfClient,this.frameID=e.frameID;var t=e.object;this.pose=e.pose||new r.Pose,this.visible=!1,this.add(t),this.updatePose(this.pose),this.tfUpdate=function(e){var t=new r.Transform(e),i=new r.Pose(this.pose);i.applyTransform(t),this.updatePose(i),this.visible=!0},this.tfUpdateBound=this.tfUpdate.bind(this),this.tfClient.subscribe(this.frameID,this.tfUpdateBound)}updatePose(e){this.position.set(e.position.x,e.position.y,e.position.z),this.quaternion.set(e.orientation.x,e.orientation.y,e.orientation.z,e.orientation.w),this.updateMatrixWorld(!0)}unsubscribeTf(){this.tfClient.unsubscribe(this.frameID,this.tfUpdateBound)}}class Qs extends Ss.ArrowHelper{constructor(e){var t=(e=e||{}).origin||new Ss.Vector3(0,0,0),i=e.direction||new Ss.Vector3(1,0,0),r=e.length||1;e.headLength,e.shaftDiameter,e.headDiameter,e.material||new Ss.MeshBasicMaterial,super(i,t,r,16711680)}dispose(){void 0!==this.line&&(this.line.material.dispose(),this.line.geometry.dispose()),void 0!==this.cone&&(this.cone.material.dispose(),this.cone.geometry.dispose())}}class $s extends Ss.Object3D{constructor(e){super();var t=this,i=(e=e||{}).shaftRadius||.008,r=e.headRadius||.023,n=e.headLength||.1,o=e.scale||1,a=e.lineType||"full",s=e.lineDashLength||.1;function c(e){var r=new Ss.Color;r.setRGB(e.x,e.y,e.z);var n=new Ss.MeshBasicMaterial({color:r.getHex()}),o=new Ss.Vector3;o.crossVectors(e,new Ss.Vector3(0,-1,0));var c=new Ss.Quaternion;c.setFromAxisAngle(o,.5*Math.PI);var h,l=new Ss.Mesh(t.headGeom,n);if(l.position.copy(e),l.position.multiplyScalar(.95),l.quaternion.copy(c),l.updateMatrix(),t.add(l),"dashed"===a)for(var u=s,p=0;u/2+3*u*p+u/2<=1;++p){var d=new Ss.CylinderGeometry(i,i,u);(h=new Ss.Mesh(d,n)).position.copy(e),h.position.multiplyScalar(u/2+3*u*p),h.quaternion.copy(c),h.updateMatrix(),t.add(h)}else"full"===a?((h=new Ss.Mesh(t.lineGeom,n)).position.copy(e),h.position.multiplyScalar(.45),h.quaternion.copy(c),h.updateMatrix(),t.add(h)):console.warn("[Axes]: Unsupported line type. Not drawing any axes.")}this.scale.set(o,o,o),this.lineGeom=new Ss.CylinderGeometry(i,i,1-n),this.headGeom=new Ss.CylinderGeometry(0,r,n),c(new Ss.Vector3(1,0,0)),c(new Ss.Vector3(0,1,0)),c(new Ss.Vector3(0,0,1))}}class ec extends Ss.Object3D{constructor(e){var t=(e=e||{}).num_cells||10,i=e.color||"#cccccc",r=e.lineWidth||1,n=e.cellSize||1;super();for(var o=new Ss.LineBasicMaterial({color:i,linewidth:r}),a=0;a<=t;++a){var s=n*t/2,c=s-a*n,h=new Ss.Geometry;h.vertices.push(new Ss.Vector3(-s,c,0),new Ss.Vector3(s,c,0));var l=new Ss.Geometry;l.vertices.push(new Ss.Vector3(c,-s,0),new Ss.Vector3(c,s,0)),this.add(new Ss.Line(h,o)),this.add(new Ss.Line(l,o))}}}class tc extends Ss.Mesh{constructor(e){var t=(e=e||{}).message,i=e.opacity||1,r=e.color||{r:255,g:255,b:255,a:255},n=t.info,o=n.origin,a=n.width,s=n.height,c=new Ss.PlaneBufferGeometry(a,s),h=new Uint8Array(a*s*4),l=new Ss.DataTexture(h,a,s,Ss.RGBAFormat);l.flipY=!0,l.minFilter=Ss.NearestFilter,l.magFilter=Ss.NearestFilter,l.needsUpdate=!0;var u=new Ss.MeshBasicMaterial({map:l,transparent:i<1,opacity:i});u.side=Ss.DoubleSide,super(c,u),Object.assign(this,e),this.quaternion.copy(new Ss.Quaternion(o.orientation.x,o.orientation.y,o.orientation.z,o.orientation.w)),this.position.x=a*n.resolution/2+o.position.x,this.position.y=s*n.resolution/2+o.position.y,this.position.z=o.position.z,this.scale.x=n.resolution,this.scale.y=n.resolution;var p=t.data;this.color=r,this.material=u,this.texture=l;for(var d=0;d{const t="read"+e.kind,i="get"+e.kind;this[t]=()=>{if(this._cursor+e.width>this.length)throw new Error("Cannot read data stream. Overflow. Len="+this.length+" crsr="+this._cursor);const t=this._dataView[i](this._cursor,this.isLittleEndian);return this._cursor+=e.width,t}})),Object.defineProperty(this,"isEnd",{get:()=>this.cursor>=this.data.length}),this}class cc{constructor(e){this.resolution=void 0!==e.resolution?e.resolution:1,this.color=new Ss.Color(void 0!==e.color?e.color:"green"),this.opacity=void 0!==e.opacity?e.opacity:1,this.voxelRenderMode=void 0!==e.voxelRenderMode?e.voxelRenderMode:rc,this._rootNode=null,this._treeDepth=16,this._treeMaxKeyVal=32768,this._BINARY_UNALLOCATED=0,this._BINARY_LEAF_FREE=1,this._BINARY_LEAF_OCCUPIED=2,this._BINARY_HAS_CHILDREN=3,this._BINARY_CHILD_BUILD_TABLE={},this._BINARY_CHILD_BUILD_TABLE[this._BINARY_LEAF_FREE]=function(e){e.value=this._defaultFreeValue},this._BINARY_CHILD_BUILD_TABLE[this._BINARY_LEAF_OCCUPIED]=function(e){e.value=this._defaultOccupiedValue},this._BINARY_CHILD_BUILD_TABLE[this._BINARY_HAS_CHILDREN]=function(e){e.value=null},this._FACES=[{normal:[-1,0,0],vertices:[[0,1,0],[0,0,0],[0,1,1],[0,0,1]],childIndex:[1,3,5,7]},{normal:[1,0,0],vertices:[[1,1,1],[1,0,1],[1,1,0],[1,0,0]],childIndex:[0,2,4,6]},{normal:[0,-1,0],vertices:[[1,0,1],[0,0,1],[1,0,0],[0,0,0]],childIndex:[2,3,6,7]},{normal:[0,1,0],vertices:[[0,1,1],[1,1,1],[0,1,0],[1,1,0]],childIndex:[0,1,4,5]},{normal:[0,0,-1],vertices:[[1,0,0],[0,0,0],[1,1,0],[0,1,0]],childIndex:[4,5,6,7]},{normal:[0,0,1],vertices:[[0,0,1],[1,0,1],[0,1,1],[1,1,1]],childIndex:[0,1,2,3]}],this.nodeSizeTable=new Array(this._treeDepth);let t=this.resolution;for(let e=this._treeDepth-1;e>=0;--e)this.nodeSizeTable[e]=t,t*=2;this._defaultOccupiedValue=!0,this._defaultFreeValue=!1,this.object=null}searchAtDepth(e,t){t=void 0!==t&&t>0?t:this._treeDepth;const i=this._adjustKeyAtDepth(e,t),r=this._treeDepth-t;let n=this._rootNode;for(let e=this._treeDepth-1;e>=r;--e){const t=this._computeChildIdx(i,e);if(!n.hasChildAt(t))return n.hasChildren()?null:n;n=n.getChildAt(t)}return n}_computeCoordFromKey(e){return e.map((e=>this.resolution*(e-this._treeMaxKeyVal)))}_computeChildIdx(e,t){let i=0;return e[0]&1<(e-this._treeMaxKeyVal>>i<0;){let e=i.pop();const r=t.readUint16();let n=8;for(;0!==n;){--n;const t=(r&3<<2*n)>>2*n;if(t!==this._BINARY_UNALLOCATED){let r=this._newNode();this._BINARY_CHILD_BUILD_TABLE[t].bind(this)(r),e.createChildNodeAt(r,n),t===this._BINARY_HAS_CHILDREN&&i.push(r)}}}}read(e){null!==this._rootNode&&delete this._rootNode,this._rootNode=this._newNode();let t=new sc(e,!0),i=new Array;for(i.push(this._rootNode);i.length>0;){let e=i.pop();this._readNodeData(t,e);const r=t.readUint8();let n=8;for(;0!==n;){--n;if(r&1<0;){let i=t.pop();if(i.node.isLeafNode())e(i.node,i.key,i.depth-1);else for(let e=0;e<8;++e)if(i.node.hasChildAt(e)){const r=this._computeKeyFromChildIdx(e,i.key,i.depth);t.push({node:i.node.getChildAt(e),depth:i.depth+1,key:r})}}}_obtainColor(e){return this.color}_checkOccupied(e){return!1!==e.value}_buildFaces(){let e={vertices:[],indices:[],normals:[],colors:[],_insertFace:function(e,t,i,r){const n=this.vertices.length/3;e.vertices.forEach((function(e){this.vertices.push(t[0]+e[0]*i,t[1]+e[1]*i,t[2]+e[2]*i)}));const o=[r.r,r.g,r.b];this.colors.push(...o,...o,...o,...o),this.normals.push(...e.normal,...e.normal,...e.normal,...e.normal),this.indices.push(n,n+1,n+2,n+2,n+1,n+3)},_checkNeighborsTouchingFace:function(e,t,i){let r=new Array;for(r.push(t);0!==r.length;){const t=r.pop();t.hasChildren()&&e.childIndex.forEach((function(e){if(!t.hasChildAt(e))return!0;{const n=t.getChildAt(e),o=this._checkOccupied(t);(o&&i===ROS3D.OcTreeVoxelRenderMode.OCCUPIED||!o&&i===nc)&&r.push(n)}}))}return!1}};return this._traverseLeaves(((t,i,r)=>{const n=this._computeCoordFromKey(i),o=this.nodeSizeTable[r],a=this._treeDepth-r,s=this._checkOccupied(t);(s||this.voxelRenderMode!==rc)&&(s&&this.voxelRenderMode===nc||this._FACES.forEach((function(s){const c=[i[0]+s.normal[0]*a*a,i[1]+s.normal[1]*a*a,i[2]+s.normal[2]*a*a],h=this.searchAtDepth(c);null===h?e._insertFace(s,n,o,this._obtainColor(t)):rnew Ss.Color(e))):[{r:0,g:0,b:128},{r:0,g:255,b:0},{r:255,g:255,b:0},{r:255,g:128,b:0},{r:255,g:0,b:0}],this.paletteScale=void 0!==e.paletteScale?e.paletteScale:1}_readNodeData(e,t){t.value=e.readFloat32()}_obtainColor(e){if(this.useFlatColoring)return this.color;const t=1/(1+Math.exp(-e.value*this.paletteScale))*this.palette.length,i=Math.trunc(t),r=t-i;return i<0?this.palette[0]:i>=this.palette.length-1?this.palette[this.palette.length-1]:{r:r*this.palette[i].r+(1-r)*this.palette[i+1].r,g:r*this.palette[i].g+(1-r)*this.palette[i+1].g,b:r*this.palette[i].b+(1-r)*this.palette[i+1].b}}_checkOccupied(e){return e.value>=this.occupancyThreshold}}class lc extends hc{constructor(e){super(e),this.useOwnColor=void 0!==e.palette&&e.colorMode===ac}_readNodeData(e,t){t.value=e.readFloat32(),t.color={r:e.readUint8(),g:e.readUint8(),b:e.readUint8()}}_obtainColor(e){return this.useOwnColor?e.color:hc.prototype._obtainColor.call(this,e)}}class uc extends Ss.Object3D{constructor(e){super(),this.options=e||{},this.ros=e.ros,this.topicName=e.topic||"/particlecloud",this.tfClient=e.tfClient,this.color=e.color||13369599,this.length=e.length||1,this.rootObject=e.rootObject||new Ss.Object3D,this.keep=e.keep||1,this.sns=[],this.rosTopic=void 0,this.processMessageBound=this.processMessage.bind(this),this.subscribe()}unsubscribe(){this.rosTopic&&this.rosTopic.unsubscribe(this.processMessageBound)}subscribe(){this.unsubscribe(),this.rosTopic=new r.Topic({ros:this.ros,name:this.topicName,queue_length:1,messageType:"nav_msgs/Odometry"}),this.rosTopic.subscribe(this.processMessageBound)}processMessage(e){this.sns.length>=this.keep&&(this.sns[0].unsubscribeTf(),this.rootObject.remove(this.sns[0]),this.sns.shift()),this.options.origin=new Ss.Vector3(e.pose.pose.position.x,e.pose.pose.position.y,e.pose.pose.position.z);var t=new Ss.Quaternion(e.pose.pose.orientation.x,e.pose.pose.orientation.y,e.pose.pose.orientation.z,e.pose.pose.orientation.w);this.options.direction=new Ss.Vector3(1,0,0),this.options.direction.applyQuaternion(t),this.options.material=new Ss.MeshBasicMaterial({color:this.color});var i=new Ns(this.options);this.sns.push(new Ks({frameID:e.header.frame_id,tfClient:this.tfClient,object:i})),this.rootObject.add(this.sns[this.sns.length-1])}}class pc extends Ss.Object3D{constructor(e){super(),e=e||{},this.ros=e.ros,this.topicName=e.topic||"/path",this.tfClient=e.tfClient,this.color=e.color||13369599,this.rootObject=e.rootObject||new Ss.Object3D,this.sn=null,this.line=null,this.rosTopic=void 0,this.processMessageBound=this.processMessage.bind(this),this.subscribe()}unsubscribe(){this.rosTopic&&this.rosTopic.unsubscribe(this.processMessageBound)}subscribe(){this.unsubscribe(),this.rosTopic=new r.Topic({ros:this.ros,name:this.topicName,queue_length:1,messageType:"nav_msgs/Path"}),this.rosTopic.subscribe(this.processMessageBound)}processMessage(e){null!==this.sn&&(this.sn.unsubscribeTf(),this.rootObject.remove(this.sn));for(var t=new Ss.Geometry,i=0;i=e.range_min&&n<=e.range_max){var o=e.angle_min+r*e.angle_increment;this.points.positions.array[i++]=n*Math.cos(o),this.points.positions.array[i++]=n*Math.sin(o),this.points.positions.array[i++]=0}}this.points.update(i/3)}}}class bc extends Ss.Object3D{constructor(e){super(),e=e||{},this.ros=e.ros,this.topicName=e.topic||"/gps/fix",this.rootObject=e.rootObject||new Ss.Object3D,this.object3d=e.object3d||new Ss.Object3D;var t=e.material||{};this.altitudeNaN=e.altitudeNaN||0,this.keep=e.keep||100,this.convert=e.convert||function(e,t,i){return new Ss.Vector3(e,t,i)},this.count=0,this.next1=0,this.next2=this.keep,this.geom=new Ss.BufferGeometry,this.vertices=new Ss.BufferAttribute(new Float32Array(6*this.keep),3),this.geom.addAttribute("position",this.vertices),this.material=t.isMaterial?t:new Ss.LineBasicMaterial(t),this.line=new Ss.Line(this.geom,this.material),this.rootObject.add(this.object3d),this.rootObject.add(this.line),this.rosTopic=void 0,this.processMessageBound=this.processMessage.bind(this),this.subscribe()}unsubscribe(){this.rosTopic&&this.rosTopic.unsubscribe(this.processMessageBound)}subscribe(){this.unsubscribe(),this.rosTopic=new r.Topic({ros:this.ros,name:this.topicName,queue_length:1,messageType:"sensor_msgs/NavSatFix"}),this.rosTopic.subscribe(this.processMessageBound)}processMessage(e){var t=isNaN(e.altitude)?this.altitudeNaN:e.altitude,i=this.convert(e.longitude,e.latitude,t);this.object3d.position.copy(i),this.object3d.updateMatrixWorld(!0),this.vertices.array[3*this.next1]=i.x,this.vertices.array[3*this.next1+1]=i.y,this.vertices.array[3*this.next1+2]=i.z,this.vertices.array[3*this.next2]=i.x,this.vertices.array[3*this.next2+1]=i.y,this.vertices.array[3*this.next2+2]=i.z,this.vertices.needsUpdate=!0,this.next1=(this.next1+1)%this.keep,this.next2=this.next1+this.keep,this.count=Math.min(this.count+1,this.keep),this.geom.setDrawRange(this.next2-this.count,this.count)}}function wc(e,t,i,r){var n,o=0,a=0,s=0,c=e.length,h=t.length,l=((r=r||1)-1)*(i=i||h)*8;for(n=0;n=8&&(a-=8,t[s++]=o>>>a&255,s%i==0&&(n+=Math.ceil((l-a)/6),(a%=8)>0&&(o=wc.e[e.charAt(n)])));return Math.floor(s/i)}wc.S="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",wc.e={};for(var _c=0;_c<64;_c++)wc.e[wc.S.charAt(_c)]=_c;class Mc extends Ss.Object3D{constructor(e){super(),e=e||{},this.ros=e.ros,this.topicName=e.topic||"/points",this.throttle_rate=e.throttle_rate||null,this.compression=e.compression||"cbor",this.max_pts=e.max_pts||1e4,this.points=new yc(e),this.rosTopic=void 0,this.buffer=null,this.processMessageBound=this.processMessage.bind(this),this.subscribe()}unsubscribe(){this.rosTopic&&this.rosTopic.unsubscribe(this.processMessageBound)}subscribe(){this.unsubscribe(),this.rosTopic=new r.Topic({ros:this.ros,name:this.topicName,messageType:"sensor_msgs/PointCloud2",throttle_rate:this.throttle_rate,queue_length:1,compression:this.compression}),this.rosTopic.subscribe(this.processMessageBound)}processMessage(e){if(this.points.setup(e.header.frame_id,e.point_step,e.fields)){var t,i=this.points.pointRatio,r=this.max_pts*e.point_step;e.data.buffer?(this.buffer=e.data.slice(0,Math.min(e.data.byteLength,r)),t=Math.min(e.height*e.width/i,this.points.positions.array.length/3)):((!this.buffer||this.buffer.byteLength0?(r=d[0].object,p.intersection=this.lastIntersection=d[0]):r=this.fallbackTarget,r!==this.lastTarget&&e.type.match(/mouse/)){var f=this.notify(r,"mouseover",p);0===f?this.notify(this.lastTarget,"mouseout",p):1===f&&(r=this.fallbackTarget)!==this.lastTarget&&(this.notify(r,"mouseover",p),this.notify(this.lastTarget,"mouseout",p))}r!==this.lastTarget&&e.type.match(/touch/)&&(this.notify(r,e.type,p)?(this.notify(this.lastTarget,"touchleave",p),this.notify(this.lastTarget,"touchend",p)):(r=this.fallbackTarget)!==this.lastTarget&&(this.notify(this.lastTarget,"touchmove",p),this.notify(this.lastTarget,"touchend",p)));this.notify(r,e.type,p),"mousedown"!==e.type&&"touchstart"!==e.type&&"touchmove"!==e.type||(this.dragging=!0),this.lastTarget=r}notify(e,t,i){for(i.type=t,i.cancelBubble=!1,i.continueBubble=!1,i.stopPropagation=function(){i.cancelBubble=!0},i.continuePropagation=function(){i.continueBubble=!0},i.currentTarget=e;i.currentTarget;){if(i.currentTarget.dispatchEvent&&i.currentTarget.dispatchEvent instanceof Function){if(i.currentTarget.dispatchEvent(i),i.cancelBubble)return this.dispatchEvent(i),0;if(i.continueBubble)return 2}i.currentTarget=i.currentTarget.parent}return 1}}class Lc extends Ss.EventDispatcher{constructor(e){super();var t=this,i=(e=e||{}).scene;this.camera=e.camera,this.center=new Ss.Vector3,this.userZoom=!0,this.userZoomSpeed=e.userZoomSpeed||1,this.userRotate=!0,this.userRotateSpeed=e.userRotateSpeed||1,this.autoRotate=e.autoRotate,this.autoRotateSpeed=e.autoRotateSpeed||2,this.displayPanAndZoomFrame=void 0===e.displayPanAndZoomFrame||!!e.displayPanAndZoomFrame,this.lineTypePanAndZoomFrame=e.dashedPanAndZoomFrame||"full",this.camera.up=new Ss.Vector3(0,0,1);var r=1800,n=new Ss.Vector2,o=new Ss.Vector2,a=new Ss.Vector2,s=new Ss.Vector2,c=new Ss.Vector2,h=new Ss.Vector2,l=new Ss.Vector3,u=new Ss.Vector3,p=new Ss.Vector3,d=new Ss.Vector3,f=new Array(2),m=new Array(2);this.phiDelta=0,this.thetaDelta=0,this.scale=1,this.lastPosition=new Ss.Vector3;var v=-1,g=0,y=1,x=2,b=v;function w(e,t,i){var r=new Ss.Vector3;new Ss.Vector3;r.subVectors(t,e.origin);var n=e.direction.dot(i);if(Math.abs(n)0?t.zoomIn():t.zoomOut(),this.showAxes()}}this.axes=new $s({shaftRadius:.025,headRadius:.07,headLength:.2,lineType:this.lineTypePanAndZoomFrame}),this.displayPanAndZoomFrame&&(i.add(this.axes),this.axes.traverse((function(e){e.visible=!1}))),this.addEventListener("mousedown",(function(e){var i=e.domEvent;switch(i.preventDefault(),i.button){case 0:b=g,n.set(i.clientX,i.clientY);break;case 1:b=x,u=new Ss.Vector3(0,0,1);var r=(new Ss.Matrix4).extractRotation(this.camera.matrix);u.applyMatrix4(r),l=t.center.clone(),p=t.camera.position.clone(),d=w(e.mouseRay,l,u);break;case 2:b=y,s.set(i.clientX,i.clientY)}this.showAxes()})),this.addEventListener("mouseup",(function(e){t.userRotate&&(b=v)})),this.addEventListener("mousemove",(function(e){var i=e.domEvent;if(b===g)o.set(i.clientX,i.clientY),a.subVectors(o,n),t.rotateLeft(2*Math.PI*a.x/r*t.userRotateSpeed),t.rotateUp(2*Math.PI*a.y/r*t.userRotateSpeed),n.copy(o),this.showAxes();else if(b===y)c.set(i.clientX,i.clientY),h.subVectors(c,s),h.y>0?t.zoomIn():t.zoomOut(),s.copy(c),this.showAxes();else if(b===x){var f=w(e.mouseRay,t.center,u);if(!f)return;var m=(new Ss.Vector3).subVectors(d.clone(),f.clone());t.center.addVectors(l.clone(),m.clone()),t.camera.position.addVectors(p.clone(),m.clone()),t.update(),t.camera.updateMatrixWorld(),this.showAxes()}})),this.addEventListener("touchstart",(function(e){var i=e.domEvent;switch(i.touches.length){case 1:b=g,n.set(i.touches[0].pageX-window.scrollX,i.touches[0].pageY-window.scrollY);break;case 2:b=v,u=new Ss.Vector3(0,0,1);var r=(new Ss.Matrix4).extractRotation(this.camera.matrix);u.applyMatrix4(r),l=t.center.clone(),p=t.camera.position.clone(),d=w(e.mouseRay,l,u),f[0]=new Ss.Vector2(i.touches[0].pageX,i.touches[0].pageY),f[1]=new Ss.Vector2(i.touches[1].pageX,i.touches[1].pageY),m[0]=new Ss.Vector2(0,0),m[1]=new Ss.Vector2(0,0)}this.showAxes(),i.preventDefault()})),this.addEventListener("touchmove",(function(e){var i=e.domEvent;if(b===g)o.set(i.touches[0].pageX-window.scrollX,i.touches[0].pageY-window.scrollY),a.subVectors(o,n),t.rotateLeft(2*Math.PI*a.x/r*t.userRotateSpeed),t.rotateUp(2*Math.PI*a.y/r*t.userRotateSpeed),n.copy(o),this.showAxes();else{if(m[0].set(f[0].x-i.touches[0].pageX,f[0].y-i.touches[0].pageY),m[1].set(f[1].x-i.touches[1].pageX,f[1].y-i.touches[1].pageY),m[0].lengthSq()>10&&m[1].lengthSq()>10&&(f[0].set(i.touches[0].pageX,i.touches[0].pageY),f[1].set(i.touches[1].pageX,i.touches[1].pageY),m[0].dot(m[1])>0&&b!==y?b=x:m[0].dot(m[1])<0&&b!==x&&(b=y),b===y)){var s=new Ss.Vector2;s.subVectors(f[0],f[1]),m[0].dot(s)<0&&m[1].dot(s)>0?t.zoomOut():m[0].dot(s)>0&&m[1].dot(s)<0&&t.zoomIn()}if(b===x){var c=w(e.mouseRay,t.center,u);if(!c)return;var h=(new Ss.Vector3).subVectors(d.clone(),c.clone());t.center.addVectors(l.clone(),h.clone()),t.camera.position.addVectors(p.clone(),h.clone()),t.update(),t.camera.updateMatrixWorld()}this.showAxes(),i.preventDefault()}})),this.addEventListener("touchend",(function(e){var t=e.domEvent;1===t.touches.length&&b!==g?(b=g,n.set(t.touches[0].pageX-window.scrollX,t.touches[0].pageY-window.scrollY)):b=v})),this.addEventListener("mousewheel",_),this.addEventListener("DOMMouseScroll",_)}showAxes(){var e=this;this.axes.traverse((function(e){e.visible=!0})),this.hideTimeout&&clearTimeout(this.hideTimeout),this.hideTimeout=setTimeout((function(){e.axes.traverse((function(e){e.visible=!1})),e.hideTimeout=!1}),1e3)}rotateLeft(e){void 0===e&&(e=2*Math.PI/60/60*this.autoRotateSpeed),this.thetaDelta-=e}rotateRight(e){void 0===e&&(e=2*Math.PI/60/60*this.autoRotateSpeed),this.thetaDelta+=e}rotateUp(e){void 0===e&&(e=2*Math.PI/60/60*this.autoRotateSpeed),this.phiDelta-=e}rotateDown(e){void 0===e&&(e=2*Math.PI/60/60*this.autoRotateSpeed),this.phiDelta+=e}zoomIn(e){void 0===e&&(e=Math.pow(.95,this.userZoomSpeed)),this.scale/=e}zoomOut(e){void 0===e&&(e=Math.pow(.95,this.userZoomSpeed)),this.scale*=e}update(){var e=this.camera.position,t=e.clone().sub(this.center),i=Math.atan2(t.y,t.x),r=Math.atan2(Math.sqrt(t.y*t.y+t.x*t.x),t.z);this.autoRotate&&this.rotateLeft(2*Math.PI/60/60*this.autoRotateSpeed),i+=this.thetaDelta,r+=this.phiDelta;var n=1e-6;r=Math.max(n,Math.min(Math.PI-n,r));var o=t.length();t.set(o*Math.sin(r)*Math.cos(i),o*Math.sin(r)*Math.sin(i),o*Math.cos(r)),t.multiplyScalar(this.scale),e.copy(this.center).add(t),this.camera.lookAt(this.center),o=t.length(),this.axes.position.copy(this.center),this.axes.scale.set(.05*o,.05*o,.05*o),this.axes.updateMatrixWorld(!0),this.thetaDelta=0,this.phiDelta=0,this.scale=1,this.lastPosition.distanceTo(this.camera.position)>0&&(this.dispatchEvent({type:"change"}),this.lastPosition.copy(this.camera.position))}}return e.Arrow=Ns,e.Arrow2=Qs,e.Axes=$s,e.ColorOcTree=lc,e.DepthCloud=Ps,e.Grid=ec,e.Highlighter=Sc,e.INTERACTIVE_MARKER_BUTTON=2,e.INTERACTIVE_MARKER_BUTTON_CLICK=3,e.INTERACTIVE_MARKER_FIXED=1,e.INTERACTIVE_MARKER_INHERIT=0,e.INTERACTIVE_MARKER_KEEP_ALIVE=0,e.INTERACTIVE_MARKER_MENU=1,e.INTERACTIVE_MARKER_MENU_SELECT=2,e.INTERACTIVE_MARKER_MOUSE_DOWN=4,e.INTERACTIVE_MARKER_MOUSE_UP=5,e.INTERACTIVE_MARKER_MOVE_3D=7,e.INTERACTIVE_MARKER_MOVE_AXIS=3,e.INTERACTIVE_MARKER_MOVE_PLANE=4,e.INTERACTIVE_MARKER_MOVE_ROTATE=6,e.INTERACTIVE_MARKER_MOVE_ROTATE_3D=9,e.INTERACTIVE_MARKER_NONE=0,e.INTERACTIVE_MARKER_POSE_UPDATE=1,e.INTERACTIVE_MARKER_ROTATE_3D=8,e.INTERACTIVE_MARKER_ROTATE_AXIS=5,e.INTERACTIVE_MARKER_VIEW_FACING=2,e.InteractiveMarker=js,e.InteractiveMarkerClient=class{constructor(e){e=e||{},this.ros=e.ros,this.tfClient=e.tfClient,this.topicName=e.topic,this.path=e.path||"/",this.camera=e.camera,this.rootObject=e.rootObject||new Ss.Object3D,this.loader=e.loader,this.menuFontSize=e.menuFontSize||"0.8em",this.interactiveMarkers={},this.updateTopic=null,this.feedbackTopic=null,this.processUpdateBound=this.processUpdate.bind(this),this.topicName&&this.subscribe(this.topicName)}subscribe(e){this.unsubscribe(),this.updateTopic=new r.Topic({ros:this.ros,name:e+"/tunneled/update",messageType:"visualization_msgs/InteractiveMarkerUpdate",compression:"png"}),this.updateTopic.subscribe(this.processUpdateBound),this.feedbackTopic=new r.Topic({ros:this.ros,name:e+"/feedback",messageType:"visualization_msgs/InteractiveMarkerFeedback",compression:"png"}),this.feedbackTopic.advertise(),this.initService=new r.Service({ros:this.ros,name:e+"/tunneled/get_init",serviceType:"demo_interactive_markers/GetInit"});var t=new r.ServiceRequest({});this.initService.callService(t,this.processInit.bind(this))}unsubscribe(){for(var e in this.updateTopic&&this.updateTopic.unsubscribe(this.processUpdateBound),this.feedbackTopic&&this.feedbackTopic.unadvertise(),this.interactiveMarkers)this.eraseIntMarker(e);this.interactiveMarkers={}}processInit(e){var t=e.msg;for(var i in t.erases=[],this.interactiveMarkers)t.erases.push(i);t.poses=[],this.processUpdate(t)}processUpdate(e){e.erases.forEach((function(e){this.eraseIntMarker(e)})),e.poses.forEach((function(e){var t=this.interactiveMarkers[e.name];t&&t.setPoseFromServer(e.pose)})),e.markers.forEach((function(e){var t=this.interactiveMarkers[e.name];t&&this.eraseIntMarker(t.name);var i=new Js({message:e,feedbackTopic:this.feedbackTopic,tfClient:this.tfClient,menuFontSize:this.menuFontSize});this.interactiveMarkers[e.name]=i;var r=new js({handle:i,camera:this.camera,path:this.path,loader:this.loader});r.name=e.name,this.rootObject.add(r),i.on("pose",(function(e){r.onServerSetPose({pose:e})})),r.addEventListener("user-pose-change",i.setPoseFromClientBound),r.addEventListener("user-mousedown",i.onMouseDownBound),r.addEventListener("user-mouseup",i.onMouseUpBound),r.addEventListener("user-button-click",i.onButtonClickBound),r.addEventListener("menu-select",i.onMenuSelectBound),i.subscribeTf()}))}eraseIntMarker(e){if(this.interactiveMarkers[e]){var t=this.rootObject.getObjectByName(e);this.rootObject.remove(t);var i=this.interactiveMarkers[e];i.unsubscribeTf(),t.removeEventListener("user-pose-change",i.setPoseFromClientBound),t.removeEventListener("user-mousedown",i.onMouseDownBound),t.removeEventListener("user-mouseup",i.onMouseUpBound),t.removeEventListener("user-button-click",i.onButtonClickBound),t.removeEventListener("menu-select",i.onMenuSelectBound),delete this.interactiveMarkers[e],t.dispose()}}},e.InteractiveMarkerControl=Gs,e.InteractiveMarkerHandle=Js,e.InteractiveMarkerMenu=Vs,e.LaserScan=xc,e.MARKER_ARROW=0,e.MARKER_CUBE=1,e.MARKER_CUBE_LIST=6,e.MARKER_CYLINDER=3,e.MARKER_LINE_LIST=5,e.MARKER_LINE_STRIP=4,e.MARKER_MESH_RESOURCE=10,e.MARKER_POINTS=8,e.MARKER_SPHERE=2,e.MARKER_SPHERE_LIST=7,e.MARKER_TEXT_VIEW_FACING=9,e.MARKER_TRIANGLE_LIST=11,e.Marker=ks,e.MarkerArrayClient=class extends Zs{constructor(e){super(),e=e||{},this.ros=e.ros,this.topicName=e.topic,this.tfClient=e.tfClient,this.rootObject=e.rootObject||new Ss.Object3D,this.path=e.path||"/",this.markers={},this.rosTopic=void 0,this.processMessageBound=this.processMessage.bind(this),this.subscribe()}subscribe(){this.unsubscribe(),this.rosTopic=new r.Topic({ros:this.ros,name:this.topicName,messageType:"visualization_msgs/MarkerArray",compression:"png"}),this.rosTopic.subscribe(this.processMessageBound)}processMessage(e){e.markers.forEach(function(e){var t=e.ns+e.id;if(0===e.action){var i=!1;if(t in this.markers&&((i=this.markers[t].children[0].update(e))||this.removeMarker(t)),!i){var r=new ks({message:e,path:this.path});this.markers[t]=new Ks({frameID:e.header.frame_id,tfClient:this.tfClient,object:r}),this.rootObject.add(this.markers[t])}}else if(1===e.action)console.warn('Received marker message with deprecated action identifier "1"');else if(2===e.action)this.removeMarker(t);else if(3===e.action){for(var n in this.markers)this.removeMarker(n);this.markers={}}else console.warn('Received marker message with unknown action identifier "'+e.action+'"')}.bind(this)),this.emit("change")}unsubscribe(){this.rosTopic&&this.rosTopic.unsubscribe(this.processMessageBound)}removeMarker(e){var t=this.markers[e];t&&(t.unsubscribeTf(),this.rootObject.remove(t),t.children.forEach((e=>{e.dispose()})),delete this.markers[e])}},e.MarkerClient=class extends Zs{constructor(e){super(),e=e||{},this.ros=e.ros,this.topicName=e.topic,this.tfClient=e.tfClient,this.rootObject=e.rootObject||new Ss.Object3D,this.path=e.path||"/",this.lifetime=e.lifetime||0,this.markers={},this.rosTopic=void 0,this.updatedTime={},this.processMessageBound=this.processMessage.bind(this),this.subscribe()}unsubscribe(){this.rosTopic&&this.rosTopic.unsubscribe(this.processMessageBound)}checkTime(e){if((new Date).getTime()-this.updatedTime[e]>this.lifetime)this.removeMarker(e),this.emit("change");else{var t=this;setTimeout((function(){t.checkTime(e)}),100)}}subscribe(){this.unsubscribe(),this.rosTopic=new r.Topic({ros:this.ros,name:this.topicName,messageType:"visualization_msgs/Marker",compression:"png"}),this.rosTopic.subscribe(this.processMessageBound)}processMessage(e){var t=e.ns+e.id,i=this.markers[t];if(this.updatedTime[t]=(new Date).getTime(),i?this.removeMarker(t):this.lifetime&&this.checkTime(e.ns+e.id),0===e.action){var r=new ks({message:e,path:this.path});this.markers[t]=new Ks({frameID:e.header.frame_id,tfClient:this.tfClient,object:r}),this.rootObject.add(this.markers[t])}this.emit("change")}removeMarker(e){var t=this.markers[e];t&&(t.unsubscribeTf(),this.rootObject.remove(t),t.children.forEach((e=>{e.dispose()})),delete this.markers[e])}},e.MeshLoader=Bs,e.MeshResource=Fs,e.MouseHandler=Ac,e.NavSatFix=bc,e.OcTree=hc,e.OcTreeClient=class extends Zs{constructor(e){super(),e=e||{},this.ros=e.ros,this.topicName=e.topic||"/octomap",this.compression=e.compression||"cbor",this.continuous=e.continuous,this.tfClient=e.tfClient,this.rootObject=e.rootObject||new Ss.Object3D,this.offsetPose=e.offsetPose||new r.Pose,this.options={},void 0!==e.color&&(this.options.color=e.color),void 0!==e.opacity&&(this.options.opacity=e.opacity),void 0!==e.colorMode&&(this.options.colorMode=e.colorMode),void 0!==e.palette&&(this.options.palette=e.palette),void 0!==e.paletteScale&&(this.options.paletteScale=e.palette),void 0!==e.voxelRenderMode&&(this.options.voxelRenderMode=e.voxelRenderMode),this.currentMap=null,this.rosTopic=void 0,this.processMessageBound=this.processMessage.bind(this),this.subscribe()}unsubscribe(){this.rosTopic&&this.rosTopic.unsubscribe(this.processMessageBound)}subscribe(){this.unsubscribe(),this.rosTopic=new r.Topic({ros:this.ros,name:this.topicName,messageType:"octomap_msgs/Octomap",queue_length:1,compression:this.compression}),this.rosTopic.subscribe(this.processMessageBound)}processMessage(e){this.currentMap&&this.currentMap.tfClient&&this.currentMap.unsubscribeTf(),this._processMessagePrivate(e),this.continuous||this.rosTopic.unsubscribe(this.processMessageBound)}_loadOcTree(e){return new Promise(function(t,i){const r=Object.assign({resolution:e.resolution},this.options);let n=null;if(e.binary)n=new cc(r),n.readBinary(e.data);else{const t={OcTree:hc,ColorOcTree:lc};e.id in t&&(console.log(e.id,t),n=new t[e.id](r),n.read(e.data))}n.buildGeometry(),t(n)}.bind(this))}_processMessagePrivate(e){this._loadOcTree(e).then(function(t){const i=this.sceneNode;this.tfClient?(this.currentMap=t,this.sceneNode=new Ks({frameID:e.header.frame_id,tfClient:this.tfClient,object:t.object,pose:this.offsetPose})):(this.sceneNode=t.object,this.currentMap=t),this.rootObject.remove(i),this.rootObject.add(this.sceneNode),this.emit("change")}.bind(this))}},e.OccupancyGrid=tc,e.OccupancyGridClient=class extends Zs{constructor(e){super(),e=e||{},this.ros=e.ros,this.topicName=e.topic||"/map",this.compression=e.compression||"cbor",this.continuous=e.continuous,this.tfClient=e.tfClient,this.rootObject=e.rootObject||new Ss.Object3D,this.offsetPose=e.offsetPose||new r.Pose,this.color=e.color||{r:255,g:255,b:255},this.opacity=e.opacity||1,this.currentGrid=null,this.rosTopic=void 0,this.processMessageBound=this.processMessage.bind(this),this.subscribe()}unsubscribe(){this.rosTopic&&this.rosTopic.unsubscribe(this.processMessageBound)}subscribe(){this.unsubscribe(),this.rosTopic=new r.Topic({ros:this.ros,name:this.topicName,messageType:"nav_msgs/OccupancyGrid",queue_length:1,compression:this.compression}),this.sceneNode=null,this.rosTopic.subscribe(this.processMessageBound)}processMessage(e){this.currentGrid&&(this.tfClient?(this.sceneNode.unsubscribeTf(),this.sceneNode.remove(this.currentGrid)):this.rootObject.remove(this.currentGrid),this.currentGrid.dispose());var t=new tc({message:e,color:this.color,opacity:this.opacity});this.tfClient?(this.currentGrid=t,null===this.sceneNode?(this.sceneNode=new Ks({frameID:e.header.frame_id,tfClient:this.tfClient,object:t,pose:this.offsetPose}),this.rootObject.add(this.sceneNode)):this.sceneNode.add(this.currentGrid)):(this.sceneNode=this.currentGrid=t,this.rootObject.add(this.currentGrid)),this.emit("change"),this.continuous||this.rosTopic.unsubscribe(this.processMessageBound)}},e.Odometry=uc,e.OrbitControls=Lc,e.Path=pc,e.Point=dc,e.PointCloud2=Mc,e.Points=yc,e.Polygon=fc,e.Pose=mc,e.PoseArray=vc,e.PoseWithCovariance=gc,e.SceneNode=Ks,e.TFAxes=Ec,e.TriangleList=zs,e.Urdf=Tc,e.UrdfClient=class{constructor(e){var t=(e=e||{}).ros;this.param=e.param||"robot_description",this.path=e.path||"/",this.tfClient=e.tfClient,this.rootObject=e.rootObject||new Ss.Object3D,this.tfPrefix=e.tfPrefix||"",this.loader=e.loader,new r.Param({ros:t,name:this.param}).get(function(e){var t=new r.UrdfModel({string:e});this.urdf=new Tc({urdfModel:t,path:this.path,tfClient:this.tfClient,tfPrefix:this.tfPrefix,loader:this.loader}),this.rootObject.add(this.urdf)}.bind(this))}},e.Viewer=class{constructor(e){var t=(e=e||{}).divID,i=e.elem,r=e.width,n=e.height,o=e.background||"#111111",a=e.antialias,s=e.intensity||.66,c=e.near||.01,h=e.far||1e3,l=e.alpha||1,u=e.cameraPose||{x:3,y:3,z:3},p=e.cameraZoomSpeed||.5,d=void 0===e.displayPanAndZoomFrame||!!e.displayPanAndZoomFrame,f=e.lineTypePanAndZoomFrame||"full";this.renderer=new Ss.WebGLRenderer({antialias:a,alpha:!0}),this.renderer.setClearColor(parseInt(o.replace("#","0x"),16),l),this.renderer.sortObjects=!1,this.renderer.setSize(r,n),this.renderer.shadowMap.enabled=!1,this.renderer.autoClear=!1,this.scene=new Ss.Scene,this.camera=new Ss.PerspectiveCamera(40,r/n,c,h),this.camera.position.x=u.x,this.camera.position.y=u.y,this.camera.position.z=u.z,this.cameraControls=new Lc({scene:this.scene,camera:this.camera,displayPanAndZoomFrame:d,lineTypePanAndZoomFrame:f}),this.cameraControls.userZoomSpeed=p,this.scene.add(new Ss.AmbientLight(5592405)),this.directionalLight=new Ss.DirectionalLight(16777215,s),this.scene.add(this.directionalLight),this.selectableObjects=new Ss.Group,this.scene.add(this.selectableObjects);var m=new Ac({renderer:this.renderer,camera:this.camera,rootObject:this.selectableObjects,fallbackTarget:this.cameraControls});this.highlighter=new Sc({mouseHandler:m}),this.stopped=!0,this.animationRequestId=void 0,(i||document.getElementById(t)).appendChild(this.renderer.domElement),this.start()}start(){this.stopped=!1,this.draw()}draw(){this.stopped||(this.cameraControls.update(),this.directionalLight.position.normalize(),this.renderer.clear(!0,!0,!0),this.renderer.render(this.scene,this.camera),this.highlighter.renderHighlights(this.scene,this.renderer,this.camera),this.animationRequestId=requestAnimationFrame(this.draw.bind(this)))}stop(){this.stopped||cancelAnimationFrame(this.animationRequestId),this.stopped=!0}addObject(e,t){t?this.selectableObjects.add(e):this.scene.add(e)}resize(e,t){this.camera.aspect=e/t,this.camera.updateProjectionMatrix(),this.renderer.setSize(e,t)}},e.closestAxisPoint=Cs,e.findClosestPoint=Rs,e.intersectPlane=Ls,e.makeColorMaterial=As,Object.defineProperty(e,"__esModule",{value:!0}),e}({},ROSLIB);