UNPKG

neft

Version:

Universal Platform

1,798 lines (1,646 loc) 672 kB
var Neft = (function(){ var __modules = [function(exports){ var module = {exports: exports}; var require = __require.bind(null, {}); var exports = module.exports; (function() { 'use strict'; var extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, hasProp = {}.hasOwnProperty; module.exports = function(utils) { var OptionsArray, get, isStringArray; get = utils.get = function(obj, path, target) { var elem, i, j, k, key, len, len1; if (path == null) { path = ''; } switch (typeof path) { case 'object': path = exports.clone(path); break; case 'string': path = path.split('.'); break; default: throw new TypeError; } for (i = j = 0, len = path.length; j < len; i = ++j) { key = path[i]; if (!key.length && i) { throw new ReferenceError('utils.get(): empty properties ' + 'are not supported'); } if (isStringArray(key)) { key = key.substring(0, key.indexOf('[]')); path = path.splice(i); path[0] = path[0].substring(key.length + 2); if (!path[0].length) { path.shift(); } if (target == null) { target = new OptionsArray(); } if (key.length) { obj = obj[key]; } if (typeof obj === 'undefined') { return void 0; } for (k = 0, len1 = obj.length; k < len1; k++) { elem = obj[k]; get(elem, path.join('.'), target); } if (!target.length) { return void 0; } return target; } if (key.length) { obj = obj[key]; } if (typeof obj !== 'object' && typeof obj !== 'function') { if (i !== path.length - 1) { obj = void 0; } break; } } if (target && typeof obj !== 'undefined') { target.push(obj); } return obj; }; get.OptionsArray = OptionsArray = (function(superClass) { extend(OptionsArray, superClass); function OptionsArray() { OptionsArray.__super__.constructor.apply(this, arguments); } return OptionsArray; })(Array); return isStringArray = utils.isStringArray = function(arg) { null; //<development>; if (typeof arg !== 'string') { throw new Error('utils.isStringArray value must be a string'); } //</development>; return /\[\]$/.test(arg); }; }; }).call(this); return module.exports; },function(exports){ var module = {exports: exports}; var require = __require.bind(null, {}); var exports = module.exports; (function() { 'use strict'; var isArray; isArray = Array.isArray; module.exports = function(utils) { utils.simplify = (function() { var nativeCtors, nativeProtos; nativeProtos = [Array.prototype, Object.prototype]; nativeCtors = [Array, Object]; return function(obj, opts) { var ctors, cyclic, i, ids, j, len1, objs, optsCtors, optsInsts, optsProps, optsProtos, parse, protos, references, value; if (opts == null) { opts = {}; } null; //<development>; if (!utils.isObject(obj)) { throw new Error('utils.simplify object must be an object'); } if (!utils.isPlainObject(opts)) { throw new Error('utils.simplify options must be a plain object'); } //</development>; optsProps = opts.properties != null ? opts.properties : opts.properties = false; optsProtos = opts.protos != null ? opts.protos : opts.protos = false; optsCtors = opts.constructors != null ? opts.constructors : opts.constructors = false; optsInsts = opts.instances = !optsProtos && optsCtors; objs = []; ids = []; references = {}; if (optsCtors) { ctors = {}; } if (optsProtos) { protos = {}; } cyclic = function(obj) { var i, key, len, objIds, proto, value; len = objs.push(obj); ids.push(objIds = []); for (key in obj) { value = obj[key]; if (!(obj.hasOwnProperty(key))) { continue; } if (!(value && typeof value === 'object')) { continue; } if (optsProps && exports.lookupGetter(obj, key)) { objIds.push(null); continue; } if (!~(i = objs.indexOf(value))) { i = cyclic(value); } objIds.push(i); } if (optsProtos && (proto = getPrototypeOf(obj))) { if (~(nativeProtos.indexOf(proto))) { i = null; } else if (!~(i = objs.indexOf(proto))) { i = cyclic(proto); } objIds.push(i); } return len - 1; }; parse = function(obj, index) { var ctor, desc, isReference, key, objId, objIds, objReferences, obji, protoObjId, r, value; r = isArray(obj) ? [] : {}; objIds = ids[index]; obji = 0; objReferences = null; for (key in obj) { value = obj[key]; if (!(obj.hasOwnProperty(key))) { continue; } r[key] = value; isReference = false; if (value && typeof value === 'object') { if (objReferences == null) { objReferences = []; } objId = value = objIds[obji++]; if (value !== null) { isReference = true; objReferences.push(key); } } if (optsProps) { desc = getObjOwnPropDesc(obj, key); if (isReference) { desc.value = value; } value = desc; } r[key] = value; } if (optsProtos && getPrototypeOf(obj)) { protoObjId = objIds[obji++]; if (protoObjId !== null) { protos[index] = protoObjId; } } if (optsCtors && (ctor = obj.constructor)) { if (optsInsts || obj.hasOwnProperty('constructor')) { if (!~(nativeCtors.indexOf(ctor))) { ctors[index] = ctor; } } } if (objReferences) { references[index] = objReferences; } return r; }; cyclic(obj); for (i = j = 0, len1 = objs.length; j < len1; i = ++j) { value = objs[i]; objs[i] = parse(value, i); } return { opts: opts, objects: objs, references: references, protos: protos, constructors: ctors }; }; })(); return utils.assemble = (function() { var ctorPropConfig; ctorPropConfig = { value: null }; return function(obj) { var constructors, func, j, k, key, l, len1, len2, len3, len4, m, objI, object, objects, opts, optsCtors, optsInsts, optsProps, optsProtos, protos, ref, refI, refId, references, refs, refsIds, value; null; //<development>; if (!utils.isPlainObject(obj)) { throw new Error('utils.assemble object must be a plain object'); } //</development>; opts = obj.opts, objects = obj.objects, references = obj.references, protos = obj.protos, constructors = obj.constructors; optsProps = opts.properties; optsProtos = opts.protos; optsCtors = opts.constructors; optsInsts = opts.instances; refsIds = []; if (optsProps) { for (objI in references) { refs = references[objI]; obj = objects[objI]; for (j = 0, len1 = refs.length; j < len1; j++) { ref = refs[j]; refsIds.push(obj[ref].value); obj[ref].value = objects[obj[ref].value]; } } } else { for (objI in references) { refs = references[objI]; obj = objects[objI]; for (k = 0, len2 = refs.length; k < len2; k++) { ref = refs[k]; refsIds.push(obj[ref]); obj[ref] = objects[obj[ref]]; } } } if (optsProps) { for (l = 0, len3 = objects.length; l < len3; l++) { obj = objects[l]; for (key in obj) { value = obj[key]; if (obj.hasOwnProperty(key)) { defObjProp(obj, key, value); } } } } for (objI in protos) { refI = protos[objI]; objects[objI] = utils.setPrototypeOf(objects[objI], objects[refI]); } if (optsInsts) { for (objI in constructors) { func = constructors[objI]; object = objects[objI] = utils.setPrototypeOf(objects[objI], func.prototype); if (typeof func.fromAssembled === "function") { func.fromAssembled(object); } } } else if (optsCtors) { for (objI in constructors) { func = constructors[objI]; ctorPropConfig.value = func; defObjProp(objects[objI], 'constructor', ctorPropConfig); } } refId = 0; for (objI in references) { refs = references[objI]; obj = objects[objI]; for (m = 0, len4 = refs.length; m < len4; m++) { ref = refs[m]; obj[ref] = objects[refsIds[refId++]]; } } return objects[0]; }; })(); }; }).call(this); return module.exports; },function(exports){ var module = {exports: exports}; var require = __require.bind(null, {}); var exports = module.exports; (function() { 'use strict'; var NOP, Stack, assert, exports, forEach, isArray, shift, utils, slice = [].slice; utils = null; assert = console.assert.bind(console); exports = module.exports; shift = Array.prototype.shift; isArray = Array.isArray; NOP = function() {}; forEach = (function() { var forArray, forObject; forArray = function(arr, callback, onEnd, thisArg) { var i, n, next; i = 0; n = arr.length; next = function() { if (i === n) { return onEnd.call(thisArg); } i++; return callback.call(thisArg, arr[i - 1], i - 1, arr, next); }; return next(); }; forObject = function(obj, callback, onEnd, thisArg) { var i, keys, n, next; keys = Object.keys(obj); i = 0; n = keys.length; next = function() { var key; if (i === n) { return onEnd.call(thisArg); } key = keys[i]; callback.call(thisArg, key, obj[key], obj, next); return i++; }; return next(); }; return function(list, callback, onEnd, thisArg) { var method; assert(!utils.isPrimitive(list)); assert(typeof callback === 'function'); if (onEnd != null) { assert(typeof onEnd === 'function'); } method = isArray(list) ? forArray : forObject; method(list, callback, onEnd, thisArg); return null; }; })(); Stack = (function() { function Stack() { this._arr = []; this.length = 0; this.pending = false; Object.preventExtensions(this); } Stack.prototype.add = function(func, context, args) { if (args != null) { assert(utils.isObject(args)); } this._arr.push(func, context, args); this.length++; return this; }; Stack.prototype.callNext = function(args, callback) { var arg, callbackWrapper, called, context, func, funcArgs, funcLength, i, j, len, syncError; if (typeof args === 'function' && (callback == null)) { callback = args; args = null; } assert(typeof callback === 'function'); if (!this._arr.length) { return callback(); } this.length--; func = this._arr.shift(); context = this._arr.shift(); funcArgs = this._arr.shift(); if (typeof func === 'string') { func = utils.get(context, func); } if (typeof func !== 'function') { throw new TypeError('ASync Stack::callNext(): ' + 'function to call is not a function'); } funcLength = func.length || Math.max((args != null ? args.length : void 0) || 0, (funcArgs != null ? funcArgs.length : void 0) || 0) + 1; syncError = null; called = false; callbackWrapper = function() { assert(!called || !syncError, "Callback can't be called if function throws an error;\n" + ("Function: `" + func + "`\nSynchronous error: `" + ((syncError != null ? syncError.stack : void 0) || syncError) + "`")); assert(!called, "Callback can't be called twice;\nFunction: `" + func + "`"); called = true; return callback.apply(this, arguments); }; funcArgs = Object.create(funcArgs || null); funcArgs[funcLength - 1] = callbackWrapper; if (funcArgs.length === void 0 || funcArgs.length < funcLength) { funcArgs.length = funcLength; } if (args) { for (i = j = 0, len = args.length; j < len; i = ++j) { arg = args[i]; if (i !== funcLength - 1 && funcArgs[i] === void 0) { funcArgs[i] = arg; } } } syncError = utils.catchError(func, context, funcArgs); if (syncError) { callbackWrapper(syncError); } return null; }; Stack.prototype.runAll = function(callback, ctx) { var callNext, onNextCalled; if (callback == null) { callback = NOP; } if (ctx == null) { ctx = null; } assert(this.pending === false); if (typeof callback !== 'function') { throw new TypeError('ASync runAll(): ' + 'passed callback is not a function'); } if (!this._arr.length) { return callback.call(ctx, null); } onNextCalled = (function(_this) { return function() { var args, err; err = arguments[0], args = 2 <= arguments.length ? slice.call(arguments, 1) : []; if (err != null) { _this.pending = false; return callback.call(ctx, err); } if (_this._arr.length) { return callNext(args); } _this.pending = false; return callback.apply(ctx, arguments); }; })(this); callNext = (function(_this) { return function(args) { return _this.callNext(args, onNextCalled); }; })(this); this.pending = true; callNext(); return null; }; Stack.prototype.runAllSimultaneously = function(callback, ctx) { var done, length, n, onDone; if (callback == null) { callback = NOP; } if (ctx == null) { ctx = null; } assert(this.pending === false); assert(typeof callback === 'function'); length = n = this._arr.length / 3; done = 0; if (!length) { return callback.call(ctx); } onDone = (function(_this) { return function(err) { ++done; if (done > length) { return; } if (err) { done = length; _this.pending = false; return callback.call(ctx, err); } if (done === length) { _this.pending = false; return callback.call(ctx); } }; })(this); this.pending = true; while (n--) { this.callNext(onDone); } return null; }; return Stack; })(); /* Exports */ module.exports = function() { utils = arguments[0]; return utils.async = { forEach: forEach, Stack: Stack }; }; }).call(this); return module.exports; },function(exports){ var module = {exports: exports}; var require = __require.bind(null, {"./namespace":0,"./stringifying":1,"./async":2}); var exports = module.exports; (function() { 'use strict'; var clone, cloneDeep, createObject, defObjProp, funcToString, getObjOwnPropDesc, getOwnPropertyNames, getPrototypeOf, has, hasOwnProp, isArray, isEqual, isObject, isPrimitive, merge, mergeDeep, objKeys, pop, random, ref, setPrototypeOf, shift, toString; toString = Object.prototype.toString; funcToString = Function.prototype.toString; isArray = Array.isArray; ref = Array.prototype, shift = ref.shift, pop = ref.pop; createObject = Object.create; getPrototypeOf = Object.getPrototypeOf, getOwnPropertyNames = Object.getOwnPropertyNames; objKeys = Object.keys; hasOwnProp = Object.hasOwnProperty; getObjOwnPropDesc = Object.getOwnPropertyDescriptor; defObjProp = Object.defineProperty; random = Math.random; /* Link subfiles */ require('./namespace')(exports); require('./stringifying')(exports); require('./async')(exports); exports.isNode = exports.isServer = exports.isClient = exports.isBrowser = exports.isQt = exports.isAndroid = exports.isIOS = false; switch (true) { case (typeof Qt !== "undefined" && Qt !== null ? Qt.include : void 0) != null: exports.isClient = exports.isQt = true; break; case typeof android !== "undefined" && android !== null: exports.isClient = exports.isAndroid = true; break; case typeof ios !== "undefined" && ios !== null: exports.isClient = exports.isIOS = true; break; case (typeof window !== "undefined" && window !== null ? window.document : void 0) != null: exports.isClient = exports.isBrowser = true; break; case (typeof process !== "undefined" && process !== null) && Object.prototype.toString.call(process) === '[object process]': exports.isNode = exports.isServer = true; } exports.NOP = function() {}; exports.is = Object.is || function(val1, val2) { if (val1 === 0 && val2 === 0) { return 1 / val1 === 1 / val2; } else if (val1 !== val1) { return val2 !== val2; } else { return val1 === val2; } }; exports.isFloat = function(val) { return typeof val === 'number' && isFinite(val); }; exports.isInteger = function(val) { return typeof val === 'number' && isFinite(val) && val > -9007199254740992 && val < 9007199254740992 && Math.floor(val) === val; }; isPrimitive = exports.isPrimitive = function(val) { return val === null || typeof val === 'string' || typeof val === 'number' || typeof val === 'boolean' || typeof val === 'undefined'; }; isObject = exports.isObject = function(param) { return param !== null && typeof param === 'object'; }; exports.isPlainObject = function(param) { var proto; if (!isObject(param)) { return false; } proto = getPrototypeOf(param); if (!proto) { return true; } if ((proto === Object.prototype) && !getPrototypeOf(proto)) { return true; } return false; }; exports.isArguments = function(param) { return toString.call(param) === '[object Arguments]'; }; merge = exports.merge = function(source, obj) { var key, value; null; //<development>; if (isPrimitive(source)) { throw new Error('utils.merge source cannot be primitive'); } if (isPrimitive(obj)) { throw new Error('utils.merge object cannot be primitive'); } if (source === obj) { throw new Error('utils.merge source and object are the same'); } if (arguments.length > 2) { throw new Error('utils.merge expects only two arguments; ' + 'use utils.mergeAll instead'); } //</development>; for (key in obj) { value = obj[key]; if (obj.hasOwnProperty(key)) { source[key] = value; } } return source; }; exports.mergeAll = function(source) { var i, j, key, obj, ref1, value; null; //<development>; if (isPrimitive(source)) { throw new Error('utils.merge source cannot be primitive'); } //</development>; for (i = j = 1, ref1 = arguments.length; j < ref1; i = j += 1) { if ((obj = arguments[i]) != null) { //<development>; if (isPrimitive(obj)) { throw new Error('utils.mergeAll object cannot be primitive'); } if (source === obj) { throw new Error('utils.mergeAll source and object are the same'); } //</development>; for (key in obj) { value = obj[key]; if (obj.hasOwnProperty(key)) { source[key] = value; } } } } return source; }; mergeDeep = exports.mergeDeep = function(source, obj) { var key, sourceValue, value; null; //<development>; if (isPrimitive(source)) { throw new Error('utils.mergeDeep source cannot be primitive'); } if (isPrimitive(obj)) { throw new Error('utils.mergeDeep object cannot be primitive'); } if (source === obj) { throw new Error('utils.mergeDeep source and object are the same'); } //</development>; for (key in obj) { value = obj[key]; if (!(hasOwnProp.call(obj, key))) { continue; } sourceValue = source[key]; if (value && typeof value === 'object' && !isArray(value) && sourceValue && typeof sourceValue === 'object' && !isArray(sourceValue)) { mergeDeep(sourceValue, value); continue; } source[key] = value; } return source; }; exports.fill = function(source, obj) { var key, value; null; //<development>; if (isPrimitive(source)) { throw new Error('utils.fill source cannot be primitive'); } if (isPrimitive(obj)) { throw new Error('utils.fill object cannot be primitive'); } if (source === obj) { throw new Error('utils.fill source and object are the same'); } //</development>; for (key in obj) { value = obj[key]; if (hasOwnProp.call(obj, key)) { if (key in source && !hasOwnProp.call(source, key)) { source[key] = value; } } } return source; }; exports.remove = function(obj, elem) { var index; null; //<development>; if (isPrimitive(obj)) { throw new Error('utils.remove object cannot be primitive'); } //</development>; if (isArray(obj)) { index = obj.indexOf(elem); if (index !== -1) { if (index === 0) { obj.shift(); } else if (index === obj.length - 1) { obj.pop(); } else { obj.splice(index, 1); } } } else { delete obj[elem]; } }; exports.removeFromUnorderedArray = function(arr, elem) { var index; null; //<development>; if (!Array.isArray(arr)) { throw new Error('utils.removeFromUnorderedArray array must be an Array'); } //</development>; index = arr.indexOf(elem); if (index !== -1) { arr[index] = arr[arr.length - 1]; arr.pop(); } }; exports.getPropertyDescriptor = function(obj, prop) { var desc; null; //<development>; if (isPrimitive(obj)) { throw new Error('utils.getPropertyDescriptor object cannot be primitive'); } if (typeof prop !== 'string') { throw new Error('utils.getPropertyDescriptor property must be a string'); } //</development>; while (obj && !desc) { desc = getObjOwnPropDesc(obj, prop); obj = getPrototypeOf(obj); } return desc; }; exports.lookupGetter = (function() { var lookupGetter; if (Object.prototype.__lookupGetter__) { lookupGetter = Object.prototype.lookupGetter; (function(obj, prop) { var getter; getter = lookupGetter.call(obj, prop); return (getter != null ? getter.trueGetter : void 0) || getter; }); } return function(obj, prop) { var desc, ref1; if (desc = exports.getPropertyDescriptor(obj, prop)) { return ((ref1 = desc.get) != null ? ref1.trueGetter : void 0) || desc.get; } }; })(); exports.lookupSetter = (function() { if (Object.prototype.__lookupSetter__) { return Function.call.bind(Object.prototype.__lookupSetter__); } return function(obj, prop) { var desc; desc = exports.getPropertyDescriptor(obj, prop); return desc != null ? desc.set : void 0; }; })(); defObjProp(exports, 'WRITABLE', { value: 1 << 0 }); defObjProp(exports, 'ENUMERABLE', { value: 1 << 1 }); defObjProp(exports, 'CONFIGURABLE', { value: 1 << 2 }); exports.defineProperty = (function() { var CONFIGURABLE, ENUMERABLE, WRITABLE, accessorsCfg, descCfg, isSafari, valueCfg; WRITABLE = exports.WRITABLE, ENUMERABLE = exports.ENUMERABLE, CONFIGURABLE = exports.CONFIGURABLE; descCfg = { enumerable: true, configurable: true }; valueCfg = exports.merge({ writable: true, value: null }, descCfg); accessorsCfg = exports.merge({ get: void 0, set: void 0 }, descCfg); isSafari = typeof navigator !== "undefined" && navigator !== null ? /^((?!chrome).)*safari/i.test(navigator.userAgent) : false; return function(obj, prop, desc, getter, setter) { var _getter, cfg; null; //<development>; if (isPrimitive(obj)) { throw new Error('utils.defineProperty object cannot be primitive'); } if (typeof prop !== 'string') { throw new Error('utils.defineProperty property must be a string'); } if ((desc != null) && (!exports.isInteger(desc) || desc < 0)) { throw new Error('utils.defineProperty descriptors bitmask ' + 'must be a positive integer'); } //</development>; if (setter === void 0) { cfg = valueCfg; valueCfg.value = getter; valueCfg.writable = desc & WRITABLE; } else { if (isSafari && getter) { _getter = getter; getter = function() { if (this !== obj && this.hasOwnProperty(prop)) { return this[prop]; } else { return _getter.call(this); } }; } cfg = accessorsCfg; accessorsCfg.get = typeof getter === 'function' ? getter : void 0; accessorsCfg.set = typeof setter === 'function' ? setter : void 0; } cfg.enumerable = desc & ENUMERABLE; cfg.configurable = desc & CONFIGURABLE; defObjProp(obj, prop, cfg); return obj; }; })(); exports.overrideProperty = function(obj, prop, getter, setter) { var desc, opts, ref1; if (!(desc = exports.getPropertyDescriptor(obj, prop))) { throw new Error('utils.overrideProperty object ' + 'must has the given property'); } if (!desc.configurable) { throw new Error('utils.overrideProperty the given property ' + 'is not configurable'); } opts = exports.CONFIGURABLE; if (desc.writable) { opts |= exports.WRITABLE; } if (desc.enumerable) { opts |= exports.ENUMERABLE; } if (getter !== void 0 && setter !== void 0) { if (desc.get != null) { if (typeof getter === 'function') { getter = getter(desc.get); } else { getter = desc.get; } } if (desc.set != null) { if (typeof setter === 'function') { setter = setter(desc.set); } else { setter = desc.set; } } } else if ((typeof getter === (ref1 = typeof desc.value) && ref1 === 'function')) { getter = getter(desc.value); } return exports.defineProperty(obj, prop, opts, getter, setter); }; clone = exports.clone = function(param) { var j, key, len, proto, ref1, result; if (isArray(param)) { return param.slice(); } if (isObject(param)) { proto = getPrototypeOf(param); if (proto === Object.prototype) { result = {}; } else { result = createObject(proto); } ref1 = objKeys(param); for (j = 0, len = ref1.length; j < len; j++) { key = ref1[j]; result[key] = param[key]; } return result; } return param; }; cloneDeep = exports.cloneDeep = function(param) { var j, key, len, ref1, result; result = clone(param); if (isObject(result)) { ref1 = objKeys(result); for (j = 0, len = ref1.length; j < len; j++) { key = ref1[j]; result[key] = cloneDeep(result[key]); } } return result; }; exports.isEmpty = function(object) { var key; if (typeof object === 'string') { return object === ''; } //<development>; if (isPrimitive(object)) { throw new Error('utils.isEmpty object must be a string or ' + 'not primitive'); } //</development>; if (isArray(object)) { return !object.length; } else { for (key in object) { return false; } return true; } }; exports.last = function(arg) { null; //<development>; if (isPrimitive(arg)) { throw new Error('utils.last array cannot be primitive'); } //</development>; return arg[arg.length - 1]; }; exports.clear = function(obj) { var _, j, k, key, len, ref1, ref2; null; //<development>; if (isPrimitive(obj)) { throw new Error('utils.clear object cannot be primitive'); } //</development>; if (isArray(obj)) { for (_ = j = 0, ref1 = obj.length; j < ref1; _ = j += 1) { obj.pop(); } } else { ref2 = objKeys(obj); for (k = 0, len = ref2.length; k < len; k++) { key = ref2[k]; delete obj[key]; } } return obj; }; setPrototypeOf = exports.setPrototypeOf = (function() { var tmp; if (typeof Object.setPrototypeOf === 'function') { return Object.setPrototypeOf; } tmp = {}; tmp.__proto__ = { a: 1 }; if (tmp.a === 1) { return function(obj, proto) { null; //<development>; if (isPrimitive(obj)) { throw new Error('utils.setPrototypeOf object ' + 'cannot be primitive'); } if ((proto != null) && isPrimitive(proto)) { throw new Error('utils.setPrototypeOf prototype ' + 'cannot be primitive'); } //</development>; obj.__proto__ = proto; return obj; }; } return function(obj, proto) { var newObj; null; //<development>; if (isPrimitive(obj)) { throw new Error('utils.setPrototypeOf object ' + 'cannot be primitive'); } if ((proto != null) && isPrimitive(proto)) { throw new Error('utils.setPrototypeOf prototype ' + 'cannot be primitive'); } //</development>; if (typeof obj === 'object') { newObj = createObject(proto); merge(newObj, obj); } else { merge(obj, proto); } return newObj; }; })(); has = exports.has = function(obj, val) { var key, value; if (typeof obj === 'string') { return !!~obj.indexOf(val); } else { //<development>; if (isPrimitive(obj)) { throw new Error('utils.has object must be a string or not primitive'); } //</development>; if (isArray(obj)) { return !!~Array.prototype.indexOf.call(obj, val); } else { for (key in obj) { value = obj[key]; if (hasOwnProp.call(obj, key)) { if (value === val) { return true; } } } return false; } } }; exports.objectToArray = function(obj, valueGen, target) { var i, j, key, keys, len, value; keys = objKeys(obj); if (target == null) { target = keys; } //<development>; if (!isObject(obj)) { throw new Error('utils.objectToArray object must be an object'); } if ((valueGen != null) && typeof valueGen !== 'function') { throw new Error('utils.objectToArray valueGen must be a function'); } if (!isArray(target)) { throw new Error('utils.objectToArray target must be an array'); } //</development>; for (i = j = 0, len = keys.length; j < len; i = ++j) { key = keys[i]; value = valueGen ? valueGen(key, obj[key], obj) : obj[key]; target[i] = value; } return target; }; exports.arrayToObject = function(arr, keyGen, valueGen, target) { var elem, i, j, key, len, value; if (target == null) { target = {}; } null; //<development>; if (!isArray(arr)) { throw new Error('utils.arrayToObject array must be an array'); } if ((keyGen != null) && typeof keyGen !== 'function') { throw new Error('utils.arrayToObject keyGen must be a function'); } if ((valueGen != null) && typeof valueGen !== 'function') { throw new Error('utils.arrayToObject valueGen must be a function'); } if (!isObject(target)) { throw new Error('utils.arrayToObject target must be an object'); } //</development>; for (i = j = 0, len = arr.length; j < len; i = ++j) { elem = arr[i]; key = keyGen ? keyGen(i, elem, arr) : i; value = valueGen ? valueGen(i, elem, arr) : elem; if (key != null) { target[key] = value; } } return target; }; exports.capitalize = function(str) { null; //<development>; if (typeof str !== 'string') { throw new Error('utils.capitalize string must be a string'); } //</development>; if (!str.length) { return ''; } return str[0].toUpperCase() + str.slice(1); }; exports.addSlashes = (function() { var NEW_SUB_STR, SLASHES_RE; SLASHES_RE = /'|"/g; NEW_SUB_STR = '\\$\&'; return function(str) { null; //<development>; if (typeof str !== 'string') { throw new Error('utils.addSlashes string must be a string'); } //</development>; if (!str.length) { return str; } return str.replace(SLASHES_RE, NEW_SUB_STR); }; })(); exports.uid = function(n) { var str; if (n == null) { n = 8; } null; //<development>; if (typeof n !== 'number' || n <= 0 || !isFinite(n)) { throw new Error('utils.uid length must be a positive finite number'); } //</development>; str = ''; while (true) { str += random().toString(16).slice(2); if (str.length >= n) { break; } } if (str.length !== n) { str = str.slice(0, n); } return str; }; exports.tryFunction = function(func, context, args, onFail) { var err, error1; null; //<development>; if (typeof func !== 'function') { throw new Error('utils.tryFunction function must be a function'); } if ((args != null) && !isObject(args)) { throw new Error('utils.tryFunction arguments must be an object'); } //</development>; try { return func.apply(context, args); } catch (error1) { err = error1; if (typeof onFail === 'function') { return onFail(err); } else if (onFail === void 0) { return err; } else { return onFail; } } }; exports.catchError = function(func, context, args) { var err, error1; null; //<development>; if (typeof func !== 'function') { throw new Error('utils.catchError function must be a function'); } if ((args != null) && !isObject(args)) { throw new Error('utils.catchError arguments must be an object'); } //</development>; try { func.apply(context, args); } catch (error1) { err = error1; return err; } }; exports.bindFunctionContext = function(func, ctx) { null; //<development>; if (typeof func !== 'function') { throw new Error('utils.bindFunctionContext function must be a function'); } //</development>; switch (func.length) { case 0: return function() { return func.call(ctx); }; case 1: return function(a1) { return func.call(ctx, a1); }; case 2: return function(a1, a2) { return func.call(ctx, a1, a2); }; case 3: return function(a1, a2, a3) { return func.call(ctx, a1, a2, a3); }; case 4: return function(a1, a2, a3, a4) { return func.call(ctx, a1, a2, a3, a4); }; case 5: return function(a1, a2, a3, a4, a5) { return func.call(ctx, a1, a2, a3, a4, a5); }; case 6: return function(a1, a2, a3, a4, a5, a6) { return func.call(ctx, a1, a2, a3, a4, a5, a6); }; case 7: return function(a1, a2, a3, a4, a5, a6, a7) { return func.call(ctx, a1, a2, a3, a4, a5, a6, a7); }; default: return function() { return func.apply(ctx, arguments); }; } }; exports.errorToObject = function(error) { var result; null; //<development>; if (!(error instanceof Error)) { throw new Error('utils.errorToObject error must be an Error instance'); } //</development>; result = { name: error.name, message: error.message }; exports.merge(result, error); return result; }; exports.getOwnProperties = function(obj) { var result; null; //<development>; if (!isObject(obj)) { throw new Error('utils.getOwnProperties object must be an object'); } //</development>; result = isArray(obj) ? [] : {}; merge(result, obj); return result; }; isEqual = exports.isEqual = (function() { var defaultComparison, forArrays, forObjects; defaultComparison = function(a, b) { return a === b; }; forArrays = function(a, b, compareFunc, maxDeep) { var aValue, bValue, index, j, len; if (getPrototypeOf(a) !== getPrototypeOf(b)) { return false; } if (a.length !== b.length) { return false; } if (maxDeep <= 0) { return true; } for (index = j = 0, len = a.length; j < len; index = ++j) { aValue = a[index]; bValue = b[index]; if (bValue && typeof bValue === 'object') { if (!isEqual(aValue, bValue, compareFunc, maxDeep - 1)) { return false; } continue; } if (!compareFunc(aValue, bValue)) { return false; } } return true; }; forObjects = function(a, b, compareFunc, maxDeep) { var key, value; if (getPrototypeOf(a) !== getPrototypeOf(b)) { return false; } for (key in a) { value = a[key]; if (a.hasOwnProperty(key)) { if (!b.hasOwnProperty(key)) { return false; } } } for (key in b) { value = b[key]; if (b.hasOwnProperty(key)) { if (!a.hasOwnProperty(key)) { return false; } } } if (maxDeep <= 0) { return true; } for (key in a) { value = a[key]; if (!(a.hasOwnProperty(key))) { continue; } if (value && typeof value === 'object') { if (!isEqual(value, b[key], compareFunc, maxDeep - 1)) { return false; } continue; } if (!compareFunc(value, b[key])) { return false; } } return true; }; return function(a, b, compareFunc, maxDeep) { if (compareFunc == null) { compareFunc = defaultComparison; } if (maxDeep == null) { maxDeep = Infinity; } if (typeof compareFunc === 'number') { maxDeep = compareFunc; compareFunc = defaultComparison; } //<development>; if (typeof compareFunc !== 'function') { throw new Error('utils.isEqual compareFunction must be a function'); } if (typeof maxDeep !== 'number') { throw new Error('utils.isEqual maxDeep must be a number'); } //</development>; if (maxDeep < 0) { return compareFunc(a, b); } if (isArray(a) && isArray(b)) { return forArrays(a, b, compareFunc, maxDeep); } else if (isObject(a) && isObject(b)) { return forObjects(a, b, compareFunc, maxDeep); } else { return compareFunc(a, b); } }; })(); }).call(this); return module.exports; },function(exports){ var module = {exports: exports}; var require = __require.bind(null, {"src/utils":3,"src/assert":7}); var exports = module.exports; (function() { 'use strict'; var Log, LogImpl, assert, bind, callOnce, exports, fromArgs, impl, isArray, linesPrefix, unshift, utils, slice = [].slice; utils = require('src/utils'); assert = require('src/assert'); bind = Function.bind; isArray = Array.isArray; unshift = Array.prototype.unshift; linesPrefix = ''; fromArgs = function(args) { var arg, j, k, len, len1, line, lines, str; str = ''; for (j = 0, len = args.length; j < len; j++) { arg = args[j]; str += arg + " → "; } str = str.substring(0, str.length - 3); lines = str.split('\n'); str = ''; for (k = 0, len1 = lines.length; k < len1; k++) { line = lines[k]; str += "" + linesPrefix + line + "\n"; } str = str.slice(0, -1); return str; }; callOnce = (function() { var usedMessages; usedMessages = Object.create(null); return function() { var msg; msg = fromArgs(arguments); if (usedMessages[msg]) { return -1; } usedMessages[msg] = true; return this.apply(null, arguments); }; })(); Log = (function() { var i, isEnabled; Log.LOGS_METHODS = ['log', 'info', 'warn', 'error', 'time', 'ok']; Log.MARKERS = { white: function(str) { return "LOG: " + str; }, green: function(str) { return "OK: " + str; }, gray: function(str) { return "" + str; }, blue: function(str) { return "INFO: " + str; }, yellow: function(str) { return "WARN: " + str; }, red: function(str) { return "ERROR: " + str; } }; Log.setGlobalLinesPrefix = function(prefix) { return linesPrefix = prefix; }; Log.time = Date.now; Log.timeDiff = function(since) { return Log.time() - since; }; function Log(prefixes, parentScope) { var args, func, j, key, len, name, ref, value; if (prefixes == null) { prefixes = []; } this.parentScope = parentScope; this.prefixes = prefixes; assert.isArray(prefixes); args = utils.clone(prefixes); args.unshift(this); ref = this.constructor.LOGS_METHODS; for (j = 0, len = ref.length; j < len; j++) { name = ref[j]; this[name] = bind.apply(this[name], args); this[name].once = callOnce; } for (key in this) { value = this[key]; this[key] = value; } if (typeof this['lo' + 'g'] === 'function') { func = (function(_this) { return function() { return _this.log.apply(func, arguments); }; })(this); func.once = callOnce; func.constructor = this.constructor; return utils.merge(func, this); } } Log.prototype._write = (typeof console !== "undefined" && console !== null ? console['lo' + 'g'].bind(console) : void 0) || (function() {}); Log.prototype._writeError = (typeof console !== "undefined" && console !== null ? console['erro' + 'r'].bind(console) : void 0) || (function() {}); i = 0; Log.prototype.LOG = 1 << i++; Log.prototype.INFO = 1 << i++; Log.prototype.OK = 1 << i++; Log.prototype.WARN = 1 << i++; Log.prototype.ERROR = 1 << i++; Log.prototype.TIME = 1 << i++; Log.prototype.ALL = (1 << i++) - 1; Log.prototype.enabled = Log.prototype.ALL; isEnabled = function(log, type) { if (!(log.enabled & type)) { return false; } else if (log.parentScope) { return isEnabled(log.parentScope, type); } else { return true; } }; Log.prototype['log'] = function() { if (isEnabled(this, this.LOG)) { this._write(this.constructor.MARKERS.white(fromArgs(arguments))); } }; Log.prototype.info = function() { if (isEnabled(this, this.INFO)) { this._write(this.constructor.MARKERS.blue(fromArgs(arguments))); } }; Log.prototype.ok = function() { if (isEnabled(this, this.OK)) { this._write(this.constructor.MARKERS.green(fromArgs(arguments))); } }; Log.prototype.warn = function() { if (isEnabled(this, this.WARN)) { this._write(this.constructor.MARKERS.yellow(fromArgs(arguments))); } }; Log.prototype.error = function() { if (isEnabled(this, this.ERROR)) { this._writeError(this.constructor.MARKERS.red(fromArgs(arguments))); } }; Log.prototype.time = function() { if (!isEnabled(this, this.TIME)) { return -1; } return [this.constructor.time(), fromArgs(arguments)]; }; Log.prototype.end = function(logTime) { var diff, str; diff = this.constructor.timeDiff(logTime[0]); diff = diff.toFixed(2); str = logTime[1] + ": " + diff + " ms"; this._write(this.constructor.MARKERS.gray(str)); logTime[0] = 0; }; Log.prototype.scope = function() { var args; args = 1 <= arguments.length ? slice.call(arguments, 0) : []; if (this.prefixes) { unshift.apply(args, this.prefixes); } return new this.constructor(args, this); }; return Log; })(); impl = (function() { switch (true) { case utils.isNode: return require('./impls/node/index.coffee'); case utils.isBrowser: return require('./impls/browser/index.coffee'); } })(); LogImpl = typeof impl === 'function' ? impl(Log) : Log; exports = module.exports = new LogImpl; exports.Log = Log; }).call(this); return module.exports; },function(exports){ var module = {exports: exports}; var require = __require.bind(null, {"src/utils":3,"src/assert":7,"./emitter":17}); var exports = module.exports; (function() { 'use strict'; var STOP_PROPAGATION, SignalPrototype, assert, callSignal, createSignalFunction, utils; utils = require('src/utils'); assert = require('src/assert'); STOP_PROPAGATION = exports.STOP_PROPAGATION = 1 << 30; exports.create = function(obj, name) { var signal; signal = createSignalFunction(obj); if (name === void 0) { return signal; } assert.isNotPrimitive(obj, 'signal object cannot be primitive'); assert.isString(name, 'signal name must be a string'); assert.notLengthOf(name, 0, 'signal name cannot be an empty string'); assert(!obj.hasOwnProperty(name), "signal object has already defined the '" + name + "' property"); return obj[name] = signal; }; exports.isEmpty = function(signal) { var func, j, len, ref; ref = signal.listeners; for (j = 0, len = ref.length; j < len; j += 2) { func = ref[j]; if (func !== null) { return false; } } return true; }; callSignal = function(obj, listeners, arg1, arg2) { var containsGaps, ctx, func, i, n, result, shift; i = 0; n = listeners.length; result = 0; containsGaps = false; while (i < n) { func = listeners[i]; if (func === null) { containsGaps = true; } else { ctx = listeners[i + 1]; if (result <= 0 && func.call(ctx || obj, arg1, arg2) === STOP_PROPAGATION) { result = STOP_PROPAGATION; if (containsGaps) { break; } } } i += 2; } if (containsGaps) { shift = 0; while (i < n) { func = listeners[i]; if (func === null) { shift -= 2; } else if (shift > 0) { assert.isNotDefined(listeners[i + shift]); assert.isNotDefined(listeners[i + shift + 1]); listeners[i + shift] = func; listeners[i + shift + 1] = listeners[i + 1]; listeners[i] = null; listeners[i + 1] = null; } i += 2; } } return result; }; createSignalFunction = function(obj) { var handler; handler = function(listener, ctx) { return handler.connect(listener, ctx); }; handler.obj = obj; handler.listeners = []; utils.setPrototypeOf(handler, SignalPrototype); return handler; }; SignalPrototype = { emit: function(arg1, arg2) { assert.isFunction(this, 'emit must be called on a signal function'); assert.isArray(this.listeners, 'emit must be called on a signal function'); assert.operator(arguments.length, '<', 3, 'signal accepts maximally two parameters; use object instead'); return callSignal(this.obj, this.listeners, arg1, arg2); }, connect: function(listener, ctx) { var i, listeners, n; if (ctx == null) { ctx = null; } assert.isFunction(this, 'connect must be called on a signal fu