diff --git a/dist/amd/can-list.js b/dist/amd/can-list.js new file mode 100644 index 0000000..e449e33 --- /dev/null +++ b/dist/amd/can-list.js @@ -0,0 +1,350 @@ +/*can-list@3.2.0#can-list*/ +define(function (require, exports, module) { + require('can-event'); + var namespace = require('can-namespace'); + var Map = require('can-map'); + var bubble = require('can-map/bubble'); + var mapHelpers = require('can-map/map-helpers'); + var canBatch = require('can-event/batch'); + var canEvent = require('can-event'); + var Observation = require('can-observation'); + var CID = require('can-cid'); + var isPromise = require('can-util/js/is-promise'); + var makeArray = require('can-util/js/make-array'); + var assign = require('can-util/js/assign'); + var types = require('can-types'); + var each = require('can-util/js/each'); + var canReflect = require('can-reflect'); + var canSymbol = require('can-symbol'); + var CIDMap = require('can-util/js/cid-map'); + var splice = [].splice, spliceRemovesProps = function () { + var obj = { + 0: 'a', + length: 1 + }; + splice.call(obj, 0, 1); + return !obj[0]; + }(); + var serializeNonTypes = function (MapType, arg, args) { + if (arg && arg.serialize && !(arg instanceof MapType)) { + args.push(new MapType(arg.serialize())); + } else { + args.push(arg); + } + }; + var List = Map.extend({ Map: Map }, { + setup: function (instances, options) { + this.length = 0; + CID(this, '.map'); + this._setupComputedProperties(); + instances = instances || []; + var teardownMapping; + if (isPromise(instances)) { + this.replace(instances); + } else { + teardownMapping = instances.length && mapHelpers.addToMap(instances, this); + this.push.apply(this, makeArray(instances || [])); + } + if (teardownMapping) { + teardownMapping(); + } + assign(this, options); + }, + _triggerChange: function (attr, how, newVal, oldVal) { + Map.prototype._triggerChange.apply(this, arguments); + var index = +attr; + if (!~('' + attr).indexOf('.') && !isNaN(index)) { + if (how === 'add') { + canEvent.dispatch.call(this, how, [ + newVal, + index + ]); + canEvent.dispatch.call(this, 'length', [this.length]); + } else if (how === 'remove') { + canEvent.dispatch.call(this, how, [ + oldVal, + index + ]); + canEvent.dispatch.call(this, 'length', [this.length]); + } else { + canEvent.dispatch.call(this, how, [ + newVal, + index + ]); + } + } + }, + ___get: function (attr) { + if (attr) { + var computedAttr = this._computedAttrs[attr]; + if (computedAttr && computedAttr.compute) { + return canReflect.getValue(computedAttr.compute); + } + if (this[attr] && this[attr].isComputed && typeof this.constructor.prototype[attr] === 'function') { + return canReflect.getValue(this[attr]); + } else { + return this[attr]; + } + } else { + return this; + } + }, + __set: function (prop, value, current) { + prop = isNaN(+prop) || prop % 1 ? prop : +prop; + if (typeof prop === 'number') { + if (prop > this.length - 1) { + var newArr = new Array(prop + 1 - this.length); + newArr[newArr.length - 1] = value; + this.push.apply(this, newArr); + return newArr; + } else { + this.splice(prop, 1, value); + return this; + } + } + return Map.prototype.__set.call(this, '' + prop, value, current); + }, + ___set: function (attr, val) { + this[attr] = val; + if (+attr >= this.length) { + this.length = +attr + 1; + } + }, + __remove: function (prop, current) { + if (isNaN(+prop)) { + delete this[prop]; + this._triggerChange(prop, 'remove', undefined, current); + } else { + this.splice(prop, 1); + } + }, + _each: function (callback) { + var data = this.___get(); + for (var i = 0; i < data.length; i++) { + callback(data[i], i); + } + }, + serialize: function () { + return canReflect.serialize(this, CIDMap); + }, + splice: function (index, howMany) { + var args = makeArray(arguments), added = [], i, len, listIndex, allSame = args.length > 2; + index = index || 0; + for (i = 0, len = args.length - 2; i < len; i++) { + listIndex = i + 2; + args[listIndex] = this.__type(args[listIndex], listIndex); + added.push(args[listIndex]); + if (this[i + index] !== args[listIndex]) { + allSame = false; + } + } + if (allSame && this.length <= added.length) { + return added; + } + if (howMany === undefined) { + howMany = args[1] = this.length - index; + } + var removed = splice.apply(this, args); + if (!spliceRemovesProps) { + for (i = this.length; i < removed.length + this.length; i++) { + delete this[i]; + } + } + canBatch.start(); + if (howMany > 0) { + bubble.removeMany(this, removed); + this._triggerChange('' + index, 'remove', undefined, removed); + } + if (args.length > 2) { + bubble.addMany(this, added); + this._triggerChange('' + index, 'add', added, removed); + } + canBatch.stop(); + return removed; + } + }), getArgs = function (args) { + return args[0] && Array.isArray(args[0]) ? args[0] : makeArray(args); + }; + each({ + push: 'length', + unshift: 0 + }, function (where, name) { + var orig = [][name]; + List.prototype[name] = function () { + var args = [], len = where ? this.length : 0, i = arguments.length, res, val; + while (i--) { + val = arguments[i]; + args[i] = bubble.set(this, i, this.__type(val, i)); + } + res = orig.apply(this, args); + if (!this.comparator || args.length) { + this._triggerChange('' + len, 'add', args, undefined); + } + return res; + }; + }); + each({ + pop: 'length', + shift: 0 + }, function (where, name) { + List.prototype[name] = function () { + if (!this.length) { + return undefined; + } + var args = getArgs(arguments), len = where && this.length ? this.length - 1 : 0; + var res = [][name].apply(this, args); + this._triggerChange('' + len, 'remove', undefined, [res]); + if (res && res.removeEventListener) { + bubble.remove(this, res); + } + return res; + }; + }); + assign(List.prototype, { + indexOf: function (item, fromIndex) { + Observation.add(this, 'length'); + for (var i = fromIndex || 0, len = this.length; i < len; i++) { + if (this.attr(i) === item) { + return i; + } + } + return -1; + }, + join: function () { + Observation.add(this, 'length'); + return [].join.apply(this, arguments); + }, + reverse: function () { + var list = [].reverse.call(makeArray(this)); + return this.replace(list); + }, + slice: function () { + Observation.add(this, 'length'); + var temp = Array.prototype.slice.apply(this, arguments); + return new this.constructor(temp); + }, + concat: function () { + var args = [], MapType = this.constructor.Map; + each(arguments, function (arg) { + if (canReflect.isObservableLike(arg) && canReflect.isListLike(arg) || Array.isArray(arg)) { + var arr = canReflect.isObservableLike(arg) && canReflect.isListLike(arg) ? makeArray(arg) : arg; + each(arr, function (innerArg) { + serializeNonTypes(MapType, innerArg, args); + }); + } else { + serializeNonTypes(MapType, arg, args); + } + }); + return new this.constructor(Array.prototype.concat.apply(makeArray(this), args)); + }, + forEach: function (cb, thisarg) { + var item; + for (var i = 0, len = this.attr('length'); i < len; i++) { + item = this.attr(i); + if (item !== undefined && cb.call(thisarg || item, item, i, this) === false) { + break; + } + } + return this; + }, + replace: function (newList) { + if (isPromise(newList)) { + if (this._promise) { + this._promise.__isCurrentPromise = false; + } + var promise = this._promise = newList; + promise.__isCurrentPromise = true; + var self = this; + newList.then(function (newList) { + if (promise.__isCurrentPromise) { + self.replace(newList); + } + }); + } else { + this.splice.apply(this, [ + 0, + this.length + ].concat(makeArray(newList || []))); + } + return this; + }, + filter: function (callback, thisArg) { + var filteredList = new this.constructor(), self = this, filtered; + this.each(function (item, index, list) { + filtered = callback.call(thisArg || self, item, index, self); + if (filtered) { + filteredList.push(item); + } + }); + return filteredList; + }, + map: function (callback, thisArg) { + var filteredList = new List(), self = this; + this.each(function (item, index, list) { + var mapped = callback.call(thisArg || self, item, index, self); + filteredList.push(mapped); + }); + return filteredList; + } + }); + var oldType = Map.prototype.__type; + Map.prototype.__type = function (value, prop) { + if (typeof value === 'object' && Array.isArray(value)) { + var cached = mapHelpers.getMapFromObject(value); + if (cached) { + return cached; + } + return new List(value); + } + return oldType.apply(this, arguments); + }; + var oldSetup = Map.setup; + Map.setup = function () { + oldSetup.apply(this, arguments); + if (!(this.prototype instanceof List)) { + this.List = Map.List.extend({ Map: this }, {}); + } + }; + if (!types.DefaultList) { + types.DefaultList = List; + } + canReflect.assignSymbols(List.prototype, { + 'can.isMoreListLikeThanMapLike': true, + 'can.isListLike': true, + 'can.getKeyValue': List.prototype._get, + 'can.setKeyValue': List.prototype._set, + 'can.deleteKeyValue': List.prototype._remove, + 'can.getOwnEnumerableKeys': function () { + return Object.keys(this._data || {}).concat(this.map(function (val, index) { + return index; + })); + }, + 'can.assignDeep': function (source) { + canBatch.start(); + canReflect.assignDeepList(this, source); + canBatch.stop(); + }, + 'can.updateDeep': function (source) { + canBatch.start(); + canReflect.updateDeepList(this, source); + canBatch.stop(); + }, + 'can.unwrap': mapHelpers.reflectUnwrap, + 'can.serialize': mapHelpers.reflectSerialize, + 'can.onKeysAdded': function (handler) { + this[canSymbol.for('can.onKeyValue')]('add', handler); + }, + 'can.onKeysRemoved': function (handler) { + this[canSymbol.for('can.onKeyValue')]('remove', handler); + }, + 'can.splice': function (index, deleteCount, insert) { + this.splice.apply(this, [ + index, + deleteCount + ].concat(insert)); + } + }); + List.prototype.each = List.prototype.forEach; + Map.List = List; + module.exports = namespace.List = List; +}); \ No newline at end of file diff --git a/dist/global/can-list.js b/dist/global/can-list.js new file mode 100644 index 0000000..a111989 --- /dev/null +++ b/dist/global/can-list.js @@ -0,0 +1,4823 @@ +/*[global-shim-start]*/ +(function(exports, global, doEval){ // jshint ignore:line + var origDefine = global.define; + + var get = function(name){ + var parts = name.split("."), + cur = global, + i; + for(i = 0 ; i < parts.length; i++){ + if(!cur) { + break; + } + cur = cur[parts[i]]; + } + return cur; + }; + var set = function(name, val){ + var parts = name.split("."), + cur = global, + i, part, next; + for(i = 0; i < parts.length - 1; i++) { + part = parts[i]; + next = cur[part]; + if(!next) { + next = cur[part] = {}; + } + cur = next; + } + part = parts[parts.length - 1]; + cur[part] = val; + }; + var useDefault = function(mod){ + if(!mod || !mod.__esModule) return false; + var esProps = { __esModule: true, "default": true }; + for(var p in mod) { + if(!esProps[p]) return false; + } + return true; + }; + var modules = (global.define && global.define.modules) || + (global._define && global._define.modules) || {}; + var ourDefine = global.define = function(moduleName, deps, callback){ + var module; + if(typeof deps === "function") { + callback = deps; + deps = []; + } + var args = [], + i; + for(i =0; i < deps.length; i++) { + args.push( exports[deps[i]] ? get(exports[deps[i]]) : ( modules[deps[i]] || get(deps[i]) ) ); + } + // CJS has no dependencies but 3 callback arguments + if(!deps.length && callback.length) { + module = { exports: {} }; + var require = function(name) { + return exports[name] ? get(exports[name]) : modules[name]; + }; + args.push(require, module.exports, module); + } + // Babel uses the exports and module object. + else if(!args[0] && deps[0] === "exports") { + module = { exports: {} }; + args[0] = module.exports; + if(deps[1] === "module") { + args[1] = module; + } + } else if(!args[0] && deps[0] === "module") { + args[0] = { id: moduleName }; + } + + global.define = origDefine; + var result = callback ? callback.apply(null, args) : undefined; + global.define = ourDefine; + + // Favor CJS module.exports over the return value + result = module && module.exports ? module.exports : result; + modules[moduleName] = result; + + // Set global exports + var globalExport = exports[moduleName]; + if(globalExport && !get(globalExport)) { + if(useDefault(result)) { + result = result["default"]; + } + set(globalExport, result); + } + }; + global.define.orig = origDefine; + global.define.modules = modules; + global.define.amd = true; + ourDefine("@loader", [], function(){ + // shim for @@global-helpers + var noop = function(){}; + return { + get: function(){ + return { prepareGlobal: noop, retrieveGlobal: noop }; + }, + global: global, + __exec: function(__load){ + doEval(__load.source, global); + } + }; + }); +} +)({"can-namespace":"can"},window,function(__$source__, __$global__) { // jshint ignore:line + eval("(function() { " + __$source__ + " \n }).call(__$global__);"); +} +) +/*can-util@3.9.9#js/global/global*/ +define('can-util/js/global/global', function (require, exports, module) { + (function (global) { + 'use strict'; + var GLOBAL; + module.exports = function (setGlobal) { + if (setGlobal !== undefined) { + GLOBAL = setGlobal; + } + if (GLOBAL) { + return GLOBAL; + } else { + return GLOBAL = typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope ? self : typeof process === 'object' && {}.toString.call(process) === '[object process]' ? global : window; + } + }; + }(function () { + return this; + }())); +}); +/*can-util@3.9.9#dom/document/document*/ +define('can-util/dom/document/document', function (require, exports, module) { + (function (global) { + 'use strict'; + var global = require('can-util/js/global/global'); + var setDocument; + module.exports = function (setDoc) { + if (setDoc) { + setDocument = setDoc; + } + return setDocument || global().document; + }; + }(function () { + return this; + }())); +}); +/*can-util@3.9.9#js/is-browser-window/is-browser-window*/ +define('can-util/js/is-browser-window/is-browser-window', function (require, exports, module) { + (function (global) { + 'use strict'; + module.exports = function () { + return typeof window !== 'undefined' && typeof document !== 'undefined' && typeof SimpleDOM === 'undefined'; + }; + }(function () { + return this; + }())); +}); +/*can-util@3.9.9#js/is-plain-object/is-plain-object*/ +define('can-util/js/is-plain-object/is-plain-object', function (require, exports, module) { + 'use strict'; + var core_hasOwn = Object.prototype.hasOwnProperty; + function isWindow(obj) { + return obj !== null && obj == obj.window; + } + function isPlainObject(obj) { + if (!obj || typeof obj !== 'object' || obj.nodeType || isWindow(obj) || obj.constructor && obj.constructor.shortName) { + return false; + } + try { + if (obj.constructor && !core_hasOwn.call(obj, 'constructor') && !core_hasOwn.call(obj.constructor.prototype, 'isPrototypeOf')) { + return false; + } + } catch (e) { + return false; + } + var key; + for (key in obj) { + } + return key === undefined || core_hasOwn.call(obj, key); + } + module.exports = isPlainObject; +}); +/*can-util@3.9.9#js/log/log*/ +define('can-util/js/log/log', function (require, exports, module) { + 'use strict'; + exports.warnTimeout = 5000; + exports.logLevel = 0; + exports.warn = function (out) { + var ll = this.logLevel; + if (ll < 2) { + Array.prototype.unshift.call(arguments, 'WARN:'); + if (typeof console !== 'undefined' && console.warn) { + this._logger('warn', Array.prototype.slice.call(arguments)); + } else if (typeof console !== 'undefined' && console.log) { + this._logger('log', Array.prototype.slice.call(arguments)); + } else if (window && window.opera && window.opera.postError) { + window.opera.postError('CanJS WARNING: ' + out); + } + } + }; + exports.log = function (out) { + var ll = this.logLevel; + if (ll < 1) { + if (typeof console !== 'undefined' && console.log) { + Array.prototype.unshift.call(arguments, 'INFO:'); + this._logger('log', Array.prototype.slice.call(arguments)); + } else if (window && window.opera && window.opera.postError) { + window.opera.postError('CanJS INFO: ' + out); + } + } + }; + exports.error = function (out) { + var ll = this.logLevel; + if (ll < 1) { + if (typeof console !== 'undefined' && console.error) { + Array.prototype.unshift.call(arguments, 'ERROR:'); + this._logger('error', Array.prototype.slice.call(arguments)); + } else if (window && window.opera && window.opera.postError) { + window.opera.postError('ERROR: ' + out); + } + } + }; + exports._logger = function (type, arr) { + try { + console[type].apply(console, arr); + } catch (e) { + console[type](arr); + } + }; +}); +/*can-util@3.9.9#js/dev/dev*/ +define('can-util/js/dev/dev', function (require, exports, module) { + 'use strict'; + var canLog = require('can-util/js/log/log'); + module.exports = { + warnTimeout: 5000, + logLevel: 0, + stringify: function (value) { + var flagUndefined = function flagUndefined(key, value) { + return value === undefined ? '/* void(undefined) */' : value; + }; + return JSON.stringify(value, flagUndefined, ' ').replace(/"\/\* void\(undefined\) \*\/"/g, 'undefined'); + }, + warn: function () { + }, + log: function () { + }, + error: function () { + }, + _logger: canLog._logger + }; +}); +/*can-util@3.9.9#dom/events/events*/ +define('can-util/dom/events/events', function (require, exports, module) { + 'use strict'; + var _document = require('can-util/dom/document/document'); + var isBrowserWindow = require('can-util/js/is-browser-window/is-browser-window'); + var isPlainObject = require('can-util/js/is-plain-object/is-plain-object'); + var fixSyntheticEventsOnDisabled = false; + var dev = require('can-util/js/dev/dev'); + function isDispatchingOnDisabled(element, ev) { + var isInsertedOrRemoved = isPlainObject(ev) ? ev.type === 'inserted' || ev.type === 'removed' : ev === 'inserted' || ev === 'removed'; + var isDisabled = !!element.disabled; + return isInsertedOrRemoved && isDisabled; + } + module.exports = { + addEventListener: function () { + this.addEventListener.apply(this, arguments); + }, + removeEventListener: function () { + this.removeEventListener.apply(this, arguments); + }, + canAddEventListener: function () { + return this.nodeName && (this.nodeType === 1 || this.nodeType === 9) || this === window; + }, + dispatch: function (event, args, bubbles) { + var ret; + var dispatchingOnDisabled = fixSyntheticEventsOnDisabled && isDispatchingOnDisabled(this, event); + var doc = this.ownerDocument || _document(); + var ev = doc.createEvent('HTMLEvents'); + var isString = typeof event === 'string'; + ev.initEvent(isString ? event : event.type, bubbles === undefined ? true : bubbles, false); + if (!isString) { + for (var prop in event) { + if (ev[prop] === undefined) { + ev[prop] = event[prop]; + } + } + } + if (this.disabled === true && ev.type !== 'fix_synthetic_events_on_disabled_test') { + } + ev.args = args; + if (dispatchingOnDisabled) { + this.disabled = false; + } + ret = this.dispatchEvent(ev); + if (dispatchingOnDisabled) { + this.disabled = true; + } + return ret; + } + }; + (function () { + if (!isBrowserWindow()) { + return; + } + var testEventName = 'fix_synthetic_events_on_disabled_test'; + var input = document.createElement('input'); + input.disabled = true; + var timer = setTimeout(function () { + fixSyntheticEventsOnDisabled = true; + }, 50); + var onTest = function onTest() { + clearTimeout(timer); + module.exports.removeEventListener.call(input, testEventName, onTest); + }; + module.exports.addEventListener.call(input, testEventName, onTest); + try { + module.exports.dispatch.call(input, testEventName, [], false); + } catch (e) { + onTest(); + fixSyntheticEventsOnDisabled = true; + } + }()); +}); +/*can-namespace@1.0.0#can-namespace*/ +define('can-namespace', function (require, exports, module) { + module.exports = {}; +}); +/*can-cid@1.0.3#can-cid*/ +define('can-cid', function (require, exports, module) { + var namespace = require('can-namespace'); + var _cid = 0; + var cid = function (object, name) { + if (!object._cid) { + _cid++; + object._cid = (name || '') + _cid; + } + return object._cid; + }; + if (namespace.cid) { + throw new Error('You can\'t have two versions of can-cid, check your dependencies'); + } else { + module.exports = namespace.cid = cid; + } +}); +/*can-util@3.9.9#js/is-empty-object/is-empty-object*/ +define('can-util/js/is-empty-object/is-empty-object', function (require, exports, module) { + 'use strict'; + module.exports = function (obj) { + for (var prop in obj) { + return false; + } + return true; + }; +}); +/*can-util@3.9.9#dom/dispatch/dispatch*/ +define('can-util/dom/dispatch/dispatch', function (require, exports, module) { + 'use strict'; + var domEvents = require('can-util/dom/events/events'); + module.exports = function () { + return domEvents.dispatch.apply(this, arguments); + }; +}); +/*can-util@3.9.9#dom/data/core*/ +define('can-util/dom/data/core', function (require, exports, module) { + 'use strict'; + var isEmptyObject = require('can-util/js/is-empty-object/is-empty-object'); + var data = {}; + var expando = 'can' + new Date(); + var uuid = 0; + var setData = function (name, value) { + var id = this[expando] || (this[expando] = ++uuid), store = data[id], newStore = false; + if (!data[id]) { + newStore = true; + store = data[id] = {}; + } + if (name !== undefined) { + store[name] = value; + } + return newStore; + }; + var deleteNode = function () { + var id = this[expando]; + var nodeDeleted = false; + if (id && data[id]) { + nodeDeleted = true; + delete data[id]; + } + return nodeDeleted; + }; + module.exports = { + _data: data, + getCid: function () { + return this[expando]; + }, + cid: function () { + return this[expando] || (this[expando] = ++uuid); + }, + expando: expando, + get: function (key) { + var id = this[expando], store = id && data[id]; + return key === undefined ? store || setData(this) : store && store[key]; + }, + set: setData, + clean: function (prop) { + var id = this[expando]; + var itemData = data[id]; + if (itemData && itemData[prop]) { + delete itemData[prop]; + } + if (isEmptyObject(itemData)) { + deleteNode.call(this); + } + }, + delete: deleteNode + }; +}); +/*can-util@3.9.9#dom/mutation-observer/mutation-observer*/ +define('can-util/dom/mutation-observer/mutation-observer', function (require, exports, module) { + (function (global) { + 'use strict'; + var global = require('can-util/js/global/global')(); + var setMutationObserver; + module.exports = function (setMO) { + if (setMO !== undefined) { + setMutationObserver = setMO; + } + return setMutationObserver !== undefined ? setMutationObserver : global.MutationObserver || global.WebKitMutationObserver || global.MozMutationObserver; + }; + }(function () { + return this; + }())); +}); +/*can-util@3.9.9#js/is-array-like/is-array-like*/ +define('can-util/js/is-array-like/is-array-like', function (require, exports, module) { + 'use strict'; + function isArrayLike(obj) { + var type = typeof obj; + if (type === 'string') { + return true; + } else if (type === 'number') { + return false; + } + var length = obj && type !== 'boolean' && typeof obj !== 'number' && 'length' in obj && obj.length; + return typeof obj !== 'function' && (length === 0 || typeof length === 'number' && length > 0 && length - 1 in obj); + } + module.exports = isArrayLike; +}); +/*can-symbol@1.0.0#can-symbol*/ +define('can-symbol', function (require, exports, module) { + (function (global) { + var namespace = require('can-namespace'); + var CanSymbol; + if (typeof Symbol !== 'undefined' && typeof Symbol.for === 'function') { + CanSymbol = Symbol; + } else { + var symbolNum = 0; + CanSymbol = function CanSymbolPolyfill(description) { + var symbolValue = '@@symbol' + symbolNum++ + description; + var symbol = {}; + Object.defineProperties(symbol, { + toString: { + value: function () { + return symbolValue; + } + } + }); + return symbol; + }; + var descriptionToSymbol = {}; + var symbolToDescription = {}; + CanSymbol.for = function (description) { + var symbol = descriptionToSymbol[description]; + if (!symbol) { + symbol = descriptionToSymbol[description] = CanSymbol(description); + symbolToDescription[symbol] = description; + } + return symbol; + }; + CanSymbol.keyFor = function (symbol) { + return symbolToDescription[symbol]; + }; + [ + 'hasInstance', + 'isConcatSpreadable', + 'iterator', + 'match', + 'prototype', + 'replace', + 'search', + 'species', + 'split', + 'toPrimitive', + 'toStringTag', + 'unscopables' + ].forEach(function (name) { + CanSymbol[name] = CanSymbol.for(name); + }); + } + [ + 'isMapLike', + 'isListLike', + 'isValueLike', + 'isFunctionLike', + 'getOwnKeys', + 'getOwnKeyDescriptor', + 'proto', + 'getOwnEnumerableKeys', + 'hasOwnKey', + 'getValue', + 'setValue', + 'getKeyValue', + 'setKeyValue', + 'apply', + 'new', + 'onValue', + 'offValue', + 'onKeyValue', + 'offKeyValue', + 'getKeyDependencies', + 'getValueDependencies', + 'keyHasDependencies', + 'valueHasDependencies', + 'onKeys', + 'onKeysAdded', + 'onKeysRemoved' + ].forEach(function (name) { + CanSymbol.for('can.' + name); + }); + module.exports = namespace.Symbol = CanSymbol; + }(function () { + return this; + }())); +}); +/*can-util@3.9.9#js/is-iterable/is-iterable*/ +define('can-util/js/is-iterable/is-iterable', function (require, exports, module) { + 'use strict'; + var canSymbol = require('can-symbol'); + module.exports = function (obj) { + return obj && !!obj[canSymbol.iterator || canSymbol.for('iterator')]; + }; +}); +/*can-util@3.9.9#js/each/each*/ +define('can-util/js/each/each', function (require, exports, module) { + 'use strict'; + var isArrayLike = require('can-util/js/is-array-like/is-array-like'); + var has = Object.prototype.hasOwnProperty; + var isIterable = require('can-util/js/is-iterable/is-iterable'); + var canSymbol = require('can-symbol'); + function each(elements, callback, context) { + var i = 0, key, len, item; + if (elements) { + if (isArrayLike(elements)) { + for (len = elements.length; i < len; i++) { + item = elements[i]; + if (callback.call(context || item, item, i, elements) === false) { + break; + } + } + } else if (isIterable(elements)) { + var iter = elements[canSymbol.iterator || canSymbol.for('iterator')](); + var res, value; + while (!(res = iter.next()).done) { + value = res.value; + callback.call(context || elements, Array.isArray(value) ? value[1] : value, value[0]); + } + } else if (typeof elements === 'object') { + for (key in elements) { + if (has.call(elements, key) && callback.call(context || elements[key], elements[key], key, elements) === false) { + break; + } + } + } + } + return elements; + } + module.exports = each; +}); +/*can-util@3.9.9#js/cid/get-cid*/ +define('can-util/js/cid/get-cid', function (require, exports, module) { + 'use strict'; + var CID = require('can-cid'); + var domDataCore = require('can-util/dom/data/core'); + module.exports = function (obj) { + if (typeof obj.nodeType === 'number') { + return domDataCore.cid.call(obj); + } else { + var type = typeof obj; + var isObject = type !== null && (type === 'object' || type === 'function'); + return type + ':' + (isObject ? CID(obj) : obj); + } + }; +}); +/*can-util@3.9.9#js/cid-set/cid-set*/ +define('can-util/js/cid-set/cid-set', function (require, exports, module) { + (function (global) { + 'use strict'; + var GLOBAL = require('can-util/js/global/global'); + var each = require('can-util/js/each/each'); + var getCID = require('can-util/js/cid/get-cid'); + var CIDSet; + if (GLOBAL().Set) { + CIDSet = GLOBAL().Set; + } else { + var CIDSet = function () { + this.values = {}; + }; + CIDSet.prototype.add = function (value) { + this.values[getCID(value)] = value; + }; + CIDSet.prototype['delete'] = function (key) { + var has = getCID(key) in this.values; + if (has) { + delete this.values[getCID(key)]; + } + return has; + }; + CIDSet.prototype.forEach = function (cb, thisArg) { + each(this.values, cb, thisArg); + }; + CIDSet.prototype.has = function (value) { + return getCID(value) in this.values; + }; + CIDSet.prototype.clear = function (key) { + return this.values = {}; + }; + Object.defineProperty(CIDSet.prototype, 'size', { + get: function () { + var size = 0; + each(this.values, function () { + size++; + }); + return size; + } + }); + } + module.exports = CIDSet; + }(function () { + return this; + }())); +}); +/*can-util@3.9.9#js/make-array/make-array*/ +define('can-util/js/make-array/make-array', function (require, exports, module) { + 'use strict'; + var each = require('can-util/js/each/each'); + var isArrayLike = require('can-util/js/is-array-like/is-array-like'); + function makeArray(element) { + var ret = []; + if (isArrayLike(element)) { + each(element, function (a, i) { + ret[i] = a; + }); + } else if (element === 0 || element) { + ret.push(element); + } + return ret; + } + module.exports = makeArray; +}); +/*can-util@3.9.9#js/is-container/is-container*/ +define('can-util/js/is-container/is-container', function (require, exports, module) { + 'use strict'; + module.exports = function (current) { + return /^f|^o/.test(typeof current); + }; +}); +/*can-util@3.9.9#js/get/get*/ +define('can-util/js/get/get', function (require, exports, module) { + 'use strict'; + var isContainer = require('can-util/js/is-container/is-container'); + function get(obj, name) { + var parts = typeof name !== 'undefined' ? (name + '').replace(/\[/g, '.').replace(/]/g, '').split('.') : [], length = parts.length, current, i, container; + if (!length) { + return obj; + } + current = obj; + for (i = 0; i < length && isContainer(current); i++) { + container = current; + current = container[parts[i]]; + } + return current; + } + module.exports = get; +}); +/*can-util@3.9.9#js/is-array/is-array*/ +define('can-util/js/is-array/is-array', function (require, exports, module) { + 'use strict'; + var dev = require('can-util/js/dev/dev'); + var hasWarned = false; + module.exports = function (arr) { + return Array.isArray(arr); + }; +}); +/*can-util@3.9.9#js/string/string*/ +define('can-util/js/string/string', function (require, exports, module) { + 'use strict'; + var get = require('can-util/js/get/get'); + var isContainer = require('can-util/js/is-container/is-container'); + var canDev = require('can-util/js/dev/dev'); + var isArray = require('can-util/js/is-array/is-array'); + var strUndHash = /_|-/, strColons = /\=\=/, strWords = /([A-Z]+)([A-Z][a-z])/g, strLowUp = /([a-z\d])([A-Z])/g, strDash = /([a-z\d])([A-Z])/g, strReplacer = /\{([^\}]+)\}/g, strQuote = /"/g, strSingleQuote = /'/g, strHyphenMatch = /-+(.)?/g, strCamelMatch = /[a-z][A-Z]/g, convertBadValues = function (content) { + var isInvalid = content === null || content === undefined || isNaN(content) && '' + content === 'NaN'; + return '' + (isInvalid ? '' : content); + }, deleteAtPath = function (data, path) { + var parts = path ? path.replace(/\[/g, '.').replace(/]/g, '').split('.') : []; + var current = data; + for (var i = 0; i < parts.length - 1; i++) { + if (current) { + current = current[parts[i]]; + } + } + if (current) { + delete current[parts[parts.length - 1]]; + } + }; + var string = { + esc: function (content) { + return convertBadValues(content).replace(/&/g, '&').replace(//g, '>').replace(strQuote, '"').replace(strSingleQuote, '''); + }, + getObject: function (name, roots) { + roots = isArray(roots) ? roots : [roots || window]; + var result, l = roots.length; + for (var i = 0; i < l; i++) { + result = get(roots[i], name); + if (result) { + return result; + } + } + }, + capitalize: function (s, cache) { + return s.charAt(0).toUpperCase() + s.slice(1); + }, + camelize: function (str) { + return convertBadValues(str).replace(strHyphenMatch, function (match, chr) { + return chr ? chr.toUpperCase() : ''; + }); + }, + hyphenate: function (str) { + return convertBadValues(str).replace(strCamelMatch, function (str, offset) { + return str.charAt(0) + '-' + str.charAt(1).toLowerCase(); + }); + }, + underscore: function (s) { + return s.replace(strColons, '/').replace(strWords, '$1_$2').replace(strLowUp, '$1_$2').replace(strDash, '_').toLowerCase(); + }, + sub: function (str, data, remove) { + var obs = []; + str = str || ''; + obs.push(str.replace(strReplacer, function (whole, inside) { + var ob = get(data, inside); + if (remove === true) { + deleteAtPath(data, inside); + } + if (ob === undefined || ob === null) { + obs = null; + return ''; + } + if (isContainer(ob) && obs) { + obs.push(ob); + return ''; + } + return '' + ob; + })); + return obs === null ? obs : obs.length <= 1 ? obs[0] : obs; + }, + replacer: strReplacer, + undHash: strUndHash + }; + module.exports = string; +}); +/*can-util@3.9.9#dom/mutation-observer/document/document*/ +define('can-util/dom/mutation-observer/document/document', function (require, exports, module) { + (function (global) { + 'use strict'; + var getDocument = require('can-util/dom/document/document'); + var domDataCore = require('can-util/dom/data/core'); + var MUTATION_OBSERVER = require('can-util/dom/mutation-observer/mutation-observer'); + var each = require('can-util/js/each/each'); + var CIDStore = require('can-util/js/cid-set/cid-set'); + var makeArray = require('can-util/js/make-array/make-array'); + var string = require('can-util/js/string/string'); + var dispatchIfListening = function (mutatedNode, nodes, dispatched) { + if (dispatched.has(mutatedNode)) { + return true; + } + dispatched.add(mutatedNode); + if (nodes.name === 'removedNodes') { + var documentElement = getDocument().documentElement; + if (documentElement.contains(mutatedNode)) { + return; + } + } + nodes.handlers.forEach(function (handler) { + handler(mutatedNode); + }); + nodes.afterHandlers.forEach(function (handler) { + handler(mutatedNode); + }); + }; + var mutationObserverDocument = { + add: function (handler) { + var MO = MUTATION_OBSERVER(); + if (MO) { + var documentElement = getDocument().documentElement; + var globalObserverData = domDataCore.get.call(documentElement, 'globalObserverData'); + if (!globalObserverData) { + var observer = new MO(function (mutations) { + globalObserverData.handlers.forEach(function (handler) { + handler(mutations); + }); + }); + observer.observe(documentElement, { + childList: true, + subtree: true + }); + globalObserverData = { + observer: observer, + handlers: [] + }; + domDataCore.set.call(documentElement, 'globalObserverData', globalObserverData); + } + globalObserverData.handlers.push(handler); + } + }, + remove: function (handler) { + var documentElement = getDocument().documentElement; + var globalObserverData = domDataCore.get.call(documentElement, 'globalObserverData'); + if (globalObserverData) { + var index = globalObserverData.handlers.indexOf(handler); + if (index >= 0) { + globalObserverData.handlers.splice(index, 1); + } + if (globalObserverData.handlers.length === 0) { + globalObserverData.observer.disconnect(); + domDataCore.clean.call(documentElement, 'globalObserverData'); + } + } + } + }; + var makeMutationMethods = function (name) { + var mutationName = name.toLowerCase() + 'Nodes'; + var getMutationData = function () { + var documentElement = getDocument().documentElement; + var mutationData = domDataCore.get.call(documentElement, mutationName + 'MutationData'); + if (!mutationData) { + mutationData = { + name: mutationName, + handlers: [], + afterHandlers: [], + hander: null + }; + if (MUTATION_OBSERVER()) { + domDataCore.set.call(documentElement, mutationName + 'MutationData', mutationData); + } + } + return mutationData; + }; + var setup = function () { + var mutationData = getMutationData(); + if (mutationData.handlers.length === 0 || mutationData.afterHandlers.length === 0) { + mutationData.handler = function (mutations) { + var dispatched = new CIDStore(); + mutations.forEach(function (mutation) { + each(mutation[mutationName], function (mutatedNode) { + var children = mutatedNode.getElementsByTagName && makeArray(mutatedNode.getElementsByTagName('*')); + var alreadyChecked = dispatchIfListening(mutatedNode, mutationData, dispatched); + if (children && !alreadyChecked) { + for (var j = 0, child; (child = children[j]) !== undefined; j++) { + dispatchIfListening(child, mutationData, dispatched); + } + } + }); + }); + }; + this.add(mutationData.handler); + } + return mutationData; + }; + var teardown = function () { + var documentElement = getDocument().documentElement; + var mutationData = getMutationData(); + if (mutationData.handlers.length === 0 && mutationData.afterHandlers.length === 0) { + this.remove(mutationData.handler); + domDataCore.clean.call(documentElement, mutationName + 'MutationData'); + } + }; + var createOnOffHandlers = function (name, handlerList) { + mutationObserverDocument['on' + name] = function (handler) { + var mutationData = setup.call(this); + mutationData[handlerList].push(handler); + }; + mutationObserverDocument['off' + name] = function (handler) { + var mutationData = getMutationData(); + var index = mutationData[handlerList].indexOf(handler); + if (index >= 0) { + mutationData[handlerList].splice(index, 1); + } + teardown.call(this); + }; + }; + var createHandlers = function (name) { + createOnOffHandlers(name, 'handlers'); + createOnOffHandlers('After' + name, 'afterHandlers'); + }; + createHandlers(string.capitalize(mutationName)); + }; + makeMutationMethods('added'); + makeMutationMethods('removed'); + module.exports = mutationObserverDocument; + }(function () { + return this; + }())); +}); +/*can-util@3.9.9#dom/data/data*/ +define('can-util/dom/data/data', function (require, exports, module) { + 'use strict'; + var domDataCore = require('can-util/dom/data/core'); + var mutationDocument = require('can-util/dom/mutation-observer/document/document'); + var deleteNode = function () { + return domDataCore.delete.call(this); + }; + var elementSetCount = 0; + var cleanupDomData = function (node) { + elementSetCount -= deleteNode.call(node) ? 1 : 0; + if (elementSetCount === 0) { + mutationDocument.offAfterRemovedNodes(cleanupDomData); + } + }; + module.exports = { + getCid: domDataCore.getCid, + cid: domDataCore.cid, + expando: domDataCore.expando, + clean: domDataCore.clean, + get: domDataCore.get, + set: function (name, value) { + if (elementSetCount === 0) { + mutationDocument.onAfterRemovedNodes(cleanupDomData); + } + elementSetCount += domDataCore.set.call(this, name, value) ? 1 : 0; + }, + delete: deleteNode + }; +}); +/*can-util@3.9.9#dom/matches/matches*/ +define('can-util/dom/matches/matches', function (require, exports, module) { + 'use strict'; + var matchesMethod = function (element) { + return element.matches || element.webkitMatchesSelector || element.webkitMatchesSelector || element.mozMatchesSelector || element.msMatchesSelector || element.oMatchesSelector; + }; + module.exports = function () { + var method = matchesMethod(this); + return method ? method.apply(this, arguments) : false; + }; +}); +/*can-util@3.9.9#dom/events/delegate/delegate*/ +define('can-util/dom/events/delegate/delegate', function (require, exports, module) { + 'use strict'; + var domEvents = require('can-util/dom/events/events'); + var domData = require('can-util/dom/data/data'); + var domMatches = require('can-util/dom/matches/matches'); + var each = require('can-util/js/each/each'); + var isEmptyObject = require('can-util/js/is-empty-object/is-empty-object'); + var dataName = 'delegateEvents'; + var useCapture = function (eventType) { + return eventType === 'focus' || eventType === 'blur'; + }; + var handleEvent = function (ev) { + var events = domData.get.call(this, dataName); + var eventTypeEvents = events[ev.type]; + var matches = []; + if (eventTypeEvents) { + var selectorDelegates = []; + each(eventTypeEvents, function (delegates) { + selectorDelegates.push(delegates); + }); + var cur = ev.target; + do { + selectorDelegates.forEach(function (delegates) { + if (domMatches.call(cur, delegates[0].selector)) { + matches.push({ + target: cur, + delegates: delegates + }); + } + }); + cur = cur.parentNode; + } while (cur && cur !== ev.currentTarget); + } + var oldStopProp = ev.stopPropagation; + ev.stopPropagation = function () { + oldStopProp.apply(this, arguments); + this.cancelBubble = true; + }; + for (var i = 0; i < matches.length; i++) { + var match = matches[i]; + var delegates = match.delegates; + for (var d = 0, dLen = delegates.length; d < dLen; d++) { + if (delegates[d].handler.call(match.target, ev) === false) { + return false; + } + if (ev.cancelBubble) { + return; + } + } + } + }; + domEvents.addDelegateListener = function (eventType, selector, handler) { + var events = domData.get.call(this, dataName), eventTypeEvents; + if (!events) { + domData.set.call(this, dataName, events = {}); + } + if (!(eventTypeEvents = events[eventType])) { + eventTypeEvents = events[eventType] = {}; + domEvents.addEventListener.call(this, eventType, handleEvent, useCapture(eventType)); + } + if (!eventTypeEvents[selector]) { + eventTypeEvents[selector] = []; + } + eventTypeEvents[selector].push({ + handler: handler, + selector: selector + }); + }; + domEvents.removeDelegateListener = function (eventType, selector, handler) { + var events = domData.get.call(this, dataName); + if (events[eventType] && events[eventType][selector]) { + var eventTypeEvents = events[eventType], delegates = eventTypeEvents[selector], i = 0; + while (i < delegates.length) { + if (delegates[i].handler === handler) { + delegates.splice(i, 1); + } else { + i++; + } + } + if (delegates.length === 0) { + delete eventTypeEvents[selector]; + if (isEmptyObject(eventTypeEvents)) { + domEvents.removeEventListener.call(this, eventType, handleEvent, useCapture(eventType)); + delete events[eventType]; + if (isEmptyObject(events)) { + domData.clean.call(this, dataName); + } + } + } + } + }; +}); +/*can-util@3.9.9#js/single-reference/single-reference*/ +define('can-util/js/single-reference/single-reference', function (require, exports, module) { + (function (global) { + var CID = require('can-cid'); + var singleReference; + function getKeyName(key, extraKey) { + var keyName = extraKey ? CID(key) + ':' + extraKey : CID(key); + return keyName || key; + } + singleReference = { + set: function (obj, key, value, extraKey) { + obj[getKeyName(key, extraKey)] = value; + }, + getAndDelete: function (obj, key, extraKey) { + var keyName = getKeyName(key, extraKey); + var value = obj[keyName]; + delete obj[keyName]; + return value; + } + }; + module.exports = singleReference; + }(function () { + return this; + }())); +}); +/*can-util@3.9.9#dom/events/delegate/enter-leave*/ +define('can-util/dom/events/delegate/enter-leave', function (require, exports, module) { + 'use strict'; + var domEvents = require('can-util/dom/events/events'), singleRef = require('can-util/js/single-reference/single-reference'), cid = require('can-util/js/cid/get-cid'); + var eventMap = { + mouseenter: 'mouseover', + mouseleave: 'mouseout', + pointerenter: 'pointerover', + pointerleave: 'pointerout' + }, classMap = { + mouseenter: 'MouseEvent', + mouseleave: 'MouseEvent', + pointerenter: 'PointerEvent', + pointerleave: 'PointerEvent' + }, _addDelegateListener = domEvents.addDelegateListener, _removeDelegateListener = domEvents.removeDelegateListener; + domEvents.addDelegateListener = function (eventType, selector, handler) { + if (eventMap[eventType] !== undefined) { + var origHandler = handler, origType = eventType; + eventType = eventMap[eventType]; + handler = function (event) { + var target = this, related = event.relatedTarget; + if (!related || related !== target && !target.contains(related)) { + var eventClass = classMap[origType]; + if (eventClass === 'MouseEvent') { + var newEv = document.createEvent(eventClass); + newEv.initMouseEvent(origType, false, false, event.view, event.detail, event.screenX, event.screenY, event.clientX, event.clientY, event.ctrlKey, event.altKey, event.shiftKey, event.metaKey, event.button, event.relatedTarget); + event = newEv; + } else if (eventClass === 'PointerEvent') { + event = new PointerEvent(origType, event); + } + return origHandler.call(this, event); + } + }; + singleRef.set(origHandler, cid(this) + eventType, handler); + } + _addDelegateListener.call(this, eventType, selector, handler); + }; + domEvents.removeDelegateListener = function (eventType, selector, handler) { + if (eventMap[eventType] !== undefined) { + eventType = eventMap[eventType]; + handler = singleRef.getAndDelete(handler, cid(this) + eventType); + } + _removeDelegateListener.call(this, eventType, selector, handler); + }; +}); +/*can-event@3.7.1#can-event*/ +define('can-event', function (require, exports, module) { + var domEvents = require('can-util/dom/events/events'); + var CID = require('can-cid'); + var isEmptyObject = require('can-util/js/is-empty-object/is-empty-object'); + var domDispatch = require('can-util/dom/dispatch/dispatch'); + var namespace = require('can-namespace'); + require('can-util/dom/events/delegate/delegate'); + require('can-util/dom/events/delegate/enter-leave'); + function makeHandlerArgs(event, args) { + if (typeof event === 'string') { + event = { type: event }; + } + var handlerArgs = [event]; + if (args) { + handlerArgs.push.apply(handlerArgs, args); + } + return handlerArgs; + } + function getHandlers(eventName) { + var events = this.__bindEvents; + if (!events) { + return; + } + return events[eventName]; + } + var canEvent = { + addEventListener: function (event, handler) { + var allEvents = this.__bindEvents || (this.__bindEvents = {}), eventList = allEvents[event] || (allEvents[event] = []); + eventList.push(handler); + return this; + }, + removeEventListener: function (event, fn) { + if (!this.__bindEvents) { + return this; + } + if (!arguments.length) { + for (var bindEvent in this.__bindEvents) { + if (bindEvent === '_lifecycleBindings') { + this.__bindEvents._lifecycleBindings = null; + } else if (this.__bindEvents.hasOwnProperty(bindEvent)) { + canEvent.removeEventListener.call(this, bindEvent); + } + } + return this; + } + var handlers = this.__bindEvents[event] || [], i = 0, handler, isFunction = typeof fn === 'function'; + while (i < handlers.length) { + handler = handlers[i]; + if (isFunction && handler === fn || !isFunction && (handler.cid === fn || !fn)) { + handlers.splice(i, 1); + } else { + i++; + } + } + return this; + }, + dispatchSync: function (event, args) { + var handlerArgs = makeHandlerArgs(event, args); + var handlers = getHandlers.call(this, handlerArgs[0].type); + if (!handlers) { + return; + } + handlers = handlers.slice(0); + for (var i = 0, len = handlers.length; i < len; i++) { + handlers[i].apply(this, handlerArgs); + } + return handlerArgs[0]; + }, + on: function (eventName, selector, handler) { + var method = typeof selector === 'string' ? 'addDelegateListener' : 'addEventListener'; + var listenWithDOM = domEvents.canAddEventListener.call(this); + var eventBinder = listenWithDOM ? domEvents[method] : this[method] || canEvent[method]; + return eventBinder.apply(this, arguments); + }, + off: function (eventName, selector, handler) { + var method = typeof selector === 'string' ? 'removeDelegateListener' : 'removeEventListener'; + var listenWithDOM = domEvents.canAddEventListener.call(this); + var eventBinder = listenWithDOM ? domEvents[method] : this[method] || canEvent[method]; + return eventBinder.apply(this, arguments); + }, + trigger: function () { + var listenWithDOM = domEvents.canAddEventListener.call(this); + var dispatch = listenWithDOM ? domDispatch : canEvent.dispatch; + return dispatch.apply(this, arguments); + }, + one: function (event, handler) { + var one = function () { + canEvent.off.call(this, event, one); + return handler.apply(this, arguments); + }; + canEvent.on.call(this, event, one); + return this; + }, + listenTo: function (other, event, handler) { + var idedEvents = this.__listenToEvents; + if (!idedEvents) { + idedEvents = this.__listenToEvents = {}; + } + var otherId = CID(other); + var othersEvents = idedEvents[otherId]; + if (!othersEvents) { + othersEvents = idedEvents[otherId] = { + obj: other, + events: {} + }; + } + var eventsEvents = othersEvents.events[event]; + if (!eventsEvents) { + eventsEvents = othersEvents.events[event] = []; + } + eventsEvents.push(handler); + canEvent.on.call(other, event, handler); + }, + stopListening: function (other, event, handler) { + var idedEvents = this.__listenToEvents, iterIdedEvents = idedEvents, i = 0; + if (!idedEvents) { + return this; + } + if (other) { + var othercid = CID(other); + (iterIdedEvents = {})[othercid] = idedEvents[othercid]; + if (!idedEvents[othercid]) { + return this; + } + } + for (var cid in iterIdedEvents) { + var othersEvents = iterIdedEvents[cid], eventsEvents; + other = idedEvents[cid].obj; + if (!event) { + eventsEvents = othersEvents.events; + } else { + (eventsEvents = {})[event] = othersEvents.events[event]; + } + for (var eventName in eventsEvents) { + var handlers = eventsEvents[eventName] || []; + i = 0; + while (i < handlers.length) { + if (handler && handler === handlers[i] || !handler) { + canEvent.off.call(other, eventName, handlers[i]); + handlers.splice(i, 1); + } else { + i++; + } + } + if (!handlers.length) { + delete othersEvents.events[eventName]; + } + } + if (isEmptyObject(othersEvents.events)) { + delete idedEvents[cid]; + } + } + return this; + } + }; + canEvent.addEvent = canEvent.bind = function () { + return canEvent.addEventListener.apply(this, arguments); + }; + canEvent.unbind = canEvent.removeEvent = function () { + return canEvent.removeEventListener.apply(this, arguments); + }; + canEvent.delegate = canEvent.on; + canEvent.undelegate = canEvent.off; + canEvent.dispatch = canEvent.dispatchSync; + Object.defineProperty(canEvent, 'makeHandlerArgs', { + enumerable: false, + value: makeHandlerArgs + }); + Object.defineProperty(canEvent, 'handlers', { + enumerable: false, + value: getHandlers + }); + Object.defineProperty(canEvent, 'flush', { + enumerable: false, + writable: true, + value: function () { + } + }); + module.exports = namespace.event = canEvent; +}); +/*can-reflect@1.2.6#reflections/helpers*/ +define('can-reflect/reflections/helpers', function (require, exports, module) { + var canSymbol = require('can-symbol'); + module.exports = { + makeGetFirstSymbolValue: function (symbolNames) { + var symbols = symbolNames.map(function (name) { + return canSymbol.for(name); + }); + var length = symbols.length; + return function getFirstSymbol(obj) { + var index = -1; + while (++index < length) { + if (obj[symbols[index]] !== undefined) { + return obj[symbols[index]]; + } + } + }; + } + }; +}); +/*can-reflect@1.2.6#reflections/type/type*/ +define('can-reflect/reflections/type/type', function (require, exports, module) { + var canSymbol = require('can-symbol'); + var helpers = require('can-reflect/reflections/helpers'); + var plainFunctionPrototypePropertyNames = Object.getOwnPropertyNames(function () { + }.prototype); + var plainFunctionPrototypeProto = Object.getPrototypeOf(function () { + }.prototype); + function isConstructorLike(func) { + var value = func[canSymbol.for('can.new')]; + if (value !== undefined) { + return value; + } + if (typeof func !== 'function') { + return false; + } + var prototype = func.prototype; + if (!prototype) { + return false; + } + if (plainFunctionPrototypeProto !== Object.getPrototypeOf(prototype)) { + return true; + } + var propertyNames = Object.getOwnPropertyNames(prototype); + if (propertyNames.length === plainFunctionPrototypePropertyNames.length) { + for (var i = 0, len = propertyNames.length; i < len; i++) { + if (propertyNames[i] !== plainFunctionPrototypePropertyNames[i]) { + return true; + } + } + return false; + } else { + return true; + } + } + var getNewOrApply = helpers.makeGetFirstSymbolValue([ + 'can.new', + 'can.apply' + ]); + function isFunctionLike(obj) { + var result, symbolValue = obj[canSymbol.for('can.isFunctionLike')]; + if (symbolValue !== undefined) { + return symbolValue; + } + result = getNewOrApply(obj); + if (result !== undefined) { + return !!result; + } + return typeof obj === 'function'; + } + function isPrimitive(obj) { + var type = typeof obj; + if (obj == null || type !== 'function' && type !== 'object') { + return true; + } else { + return false; + } + } + function isBuiltIn(obj) { + if (isPrimitive(obj) || Array.isArray(obj) || isPlainObject(obj) || Object.prototype.toString.call(obj) !== '[object Object]' && Object.prototype.toString.call(obj).indexOf('[object ') !== -1) { + return true; + } else { + return false; + } + } + function isValueLike(obj) { + var symbolValue; + if (isPrimitive(obj)) { + return true; + } + symbolValue = obj[canSymbol.for('can.isValueLike')]; + if (typeof symbolValue !== 'undefined') { + return symbolValue; + } + var value = obj[canSymbol.for('can.getValue')]; + if (value !== undefined) { + return !!value; + } + } + function isMapLike(obj) { + if (isPrimitive(obj)) { + return false; + } + var isMapLike = obj[canSymbol.for('can.isMapLike')]; + if (typeof isMapLike !== 'undefined') { + return !!isMapLike; + } + var value = obj[canSymbol.for('can.getKeyValue')]; + if (value !== undefined) { + return !!value; + } + return true; + } + var getObservableLikeSymbol = helpers.makeGetFirstSymbolValue([ + 'can.onValue', + 'can.onKeyValue', + 'can.onKeys', + 'can.onKeysAdded' + ]); + function isObservableLike(obj) { + if (isPrimitive(obj)) { + return false; + } + var result = getObservableLikeSymbol(obj); + if (result !== undefined) { + return !!result; + } + } + function isListLike(list) { + var symbolValue, type = typeof list; + if (type === 'string') { + return true; + } + if (isPrimitive(list)) { + return false; + } + symbolValue = list[canSymbol.for('can.isListLike')]; + if (typeof symbolValue !== 'undefined') { + return symbolValue; + } + var value = list[canSymbol.iterator]; + if (value !== undefined) { + return !!value; + } + if (Array.isArray(list)) { + return true; + } + var length = list && type !== 'boolean' && typeof list !== 'number' && 'length' in list && list.length; + return typeof list !== 'function' && (length === 0 || typeof length === 'number' && length > 0 && length - 1 in list); + } + var supportsSymbols = typeof Symbol !== 'undefined' && typeof Symbol.for === 'function'; + var isSymbolLike; + if (supportsSymbols) { + isSymbolLike = function (symbol) { + return typeof symbol === 'symbol'; + }; + } else { + var symbolStart = '@@symbol'; + isSymbolLike = function (symbol) { + if (typeof symbol === 'object' && !Array.isArray(symbol)) { + return symbol.toString().substr(0, symbolStart.length) === symbolStart; + } else { + return false; + } + }; + } + var coreHasOwn = Object.prototype.hasOwnProperty; + var funcToString = Function.prototype.toString; + var objectCtorString = funcToString.call(Object); + function isPlainObject(obj) { + if (!obj || typeof obj !== 'object') { + return false; + } + var proto = Object.getPrototypeOf(obj); + if (proto === Object.prototype || proto === null) { + return true; + } + var Constructor = coreHasOwn.call(proto, 'constructor') && proto.constructor; + return typeof Constructor === 'function' && Constructor instanceof Constructor && funcToString.call(Constructor) === objectCtorString; + } + module.exports = { + isConstructorLike: isConstructorLike, + isFunctionLike: isFunctionLike, + isListLike: isListLike, + isMapLike: isMapLike, + isObservableLike: isObservableLike, + isPrimitive: isPrimitive, + isBuiltIn: isBuiltIn, + isValueLike: isValueLike, + isSymbolLike: isSymbolLike, + isMoreListLikeThanMapLike: function (obj) { + if (Array.isArray(obj)) { + return true; + } + var value = obj[canSymbol.for('can.isMoreListLikeThanMapLike')]; + if (value !== undefined) { + return value; + } + var isListLike = this.isListLike(obj), isMapLike = this.isMapLike(obj); + if (isListLike && !isMapLike) { + return true; + } else if (!isListLike && isMapLike) { + return false; + } + }, + isIteratorLike: function (obj) { + return obj && typeof obj === 'object' && typeof obj.next === 'function' && obj.next.length === 0; + }, + isPromise: function (obj) { + return obj instanceof Promise || Object.prototype.toString.call(obj) === '[object Promise]'; + }, + isPlainObject: isPlainObject + }; +}); +/*can-reflect@1.2.6#reflections/call/call*/ +define('can-reflect/reflections/call/call', function (require, exports, module) { + var canSymbol = require('can-symbol'); + var typeReflections = require('can-reflect/reflections/type/type'); + module.exports = { + call: function (func, context) { + var args = [].slice.call(arguments, 2); + var apply = func[canSymbol.for('can.apply')]; + if (apply) { + return apply.call(func, context, args); + } else { + return func.apply(context, args); + } + }, + apply: function (func, context, args) { + var apply = func[canSymbol.for('can.apply')]; + if (apply) { + return apply.call(func, context, args); + } else { + return func.apply(context, args); + } + }, + 'new': function (func) { + var args = [].slice.call(arguments, 1); + var makeNew = func[canSymbol.for('can.new')]; + if (makeNew) { + return makeNew.apply(func, args); + } else { + var context = Object.create(func.prototype); + var ret = func.apply(context, args); + if (typeReflections.isPrimitive(ret)) { + return context; + } else { + return ret; + } + } + } + }; +}); +/*can-reflect@1.2.6#reflections/get-set/get-set*/ +define('can-reflect/reflections/get-set/get-set', function (require, exports, module) { + var canSymbol = require('can-symbol'); + var typeReflections = require('can-reflect/reflections/type/type'); + var setKeyValueSymbol = canSymbol.for('can.setKeyValue'), getKeyValueSymbol = canSymbol.for('can.getKeyValue'), getValueSymbol = canSymbol.for('can.getValue'), setValueSymbol = canSymbol.for('can.setValue'); + var reflections = { + setKeyValue: function (obj, key, value) { + if (typeReflections.isSymbolLike(key)) { + if (typeof key === 'symbol') { + obj[key] = value; + } else { + Object.defineProperty(obj, key, { + enumerable: false, + configurable: true, + value: value, + writable: true + }); + } + return; + } + var setKeyValue = obj[setKeyValueSymbol]; + if (setKeyValue !== undefined) { + return setKeyValue.call(obj, key, value); + } else { + obj[key] = value; + } + }, + getKeyValue: function (obj, key) { + var getKeyValue = obj[getKeyValueSymbol]; + if (getKeyValue) { + return getKeyValue.call(obj, key); + } + return obj[key]; + }, + deleteKeyValue: function (obj, key) { + var deleteKeyValue = obj[canSymbol.for('can.deleteKeyValue')]; + if (deleteKeyValue) { + return deleteKeyValue.call(obj, key); + } + delete obj[key]; + }, + getValue: function (value) { + if (typeReflections.isPrimitive(value)) { + return value; + } + var getValue = value[getValueSymbol]; + if (getValue) { + return getValue.call(value); + } + return value; + }, + setValue: function (item, value) { + var setValue = item && item[setValueSymbol]; + if (setValue) { + return setValue.call(item, value); + } else { + throw new Error('can-reflect.setValue - Can not set value.'); + } + }, + splice: function (obj, index, howMany, values) { + var splice = obj[canSymbol.for('can.splice')]; + if (splice) { + return splice.call(obj, index, howMany, values); + } + return [].splice.apply(obj, [ + index, + howMany + ].concat(values)); + } + }; + reflections.get = reflections.getKeyValue; + reflections.set = reflections.setKeyValue; + reflections['delete'] = reflections.deleteKeyValue; + module.exports = reflections; +}); +/*can-reflect@1.2.6#reflections/observe/observe*/ +define('can-reflect/reflections/observe/observe', function (require, exports, module) { + var canSymbol = require('can-symbol'); + var slice = [].slice; + function makeFallback(symbolName, fallbackName) { + return function (obj, event, handler) { + var method = obj[canSymbol.for(symbolName)]; + if (method !== undefined) { + return method.call(obj, event, handler); + } + return this[fallbackName].apply(this, arguments); + }; + } + function makeErrorIfMissing(symbolName, errorMessage) { + return function (obj, arg1, arg2) { + var method = obj[canSymbol.for(symbolName)]; + if (method !== undefined) { + return method.call(obj, arg1, arg2); + } + throw new Error(errorMessage); + }; + } + module.exports = { + onKeyValue: makeFallback('can.onKeyValue', 'onEvent'), + offKeyValue: makeFallback('can.offKeyValue', 'offEvent'), + onKeys: makeErrorIfMissing('can.onKeys', 'can-reflect: can not observe an onKeys event'), + onKeysAdded: makeErrorIfMissing('can.onKeysAdded', 'can-reflect: can not observe an onKeysAdded event'), + onKeysRemoved: makeErrorIfMissing('can.onKeysRemoved', 'can-reflect: can not unobserve an onKeysRemoved event'), + getKeyDependencies: makeErrorIfMissing('can.getKeyDependencies', 'can-reflect: can not determine dependencies'), + keyHasDependencies: makeErrorIfMissing('can.keyHasDependencies', 'can-reflect: can not determine if this has key dependencies'), + onValue: makeErrorIfMissing('can.onValue', 'can-reflect: can not observe value change'), + offValue: makeErrorIfMissing('can.offValue', 'can-reflect: can not unobserve value change'), + getValueDependencies: makeErrorIfMissing('can.getValueDependencies', 'can-reflect: can not determine dependencies'), + valueHasDependencies: makeErrorIfMissing('can.valueHasDependencies', 'can-reflect: can not determine if value has dependencies'), + onEvent: function (obj, eventName, callback) { + if (obj) { + var onEvent = obj[canSymbol.for('can.onEvent')]; + if (onEvent !== undefined) { + return onEvent.call(obj, eventName, callback); + } else if (obj.addEventListener) { + obj.addEventListener(eventName, callback); + } + } + }, + offEvent: function (obj, eventName, callback) { + if (obj) { + var offEvent = obj[canSymbol.for('can.offEvent')]; + if (offEvent !== undefined) { + return offEvent.call(obj, eventName, callback); + } else if (obj.removeEventListener) { + obj.removeEventListener(eventName, callback); + } + } + } + }; +}); +/*can-reflect@1.2.6#reflections/shape/shape*/ +define('can-reflect/reflections/shape/shape', function (require, exports, module) { + var canSymbol = require('can-symbol'); + var getSetReflections = require('can-reflect/reflections/get-set/get-set'); + var typeReflections = require('can-reflect/reflections/type/type'); + var helpers = require('can-reflect/reflections/helpers'); + var shiftFirstArgumentToThis = function (func) { + return function () { + var args = [this]; + args.push.apply(args, arguments); + return func.apply(null, args); + }; + }; + var getKeyValueSymbol = canSymbol.for('can.getKeyValue'); + var shiftedGetKeyValue = shiftFirstArgumentToThis(getSetReflections.getKeyValue); + var setKeyValueSymbol = canSymbol.for('can.setKeyValue'); + var shiftedSetKeyValue = shiftFirstArgumentToThis(getSetReflections.setKeyValue); + var serializeMap = null; + var hasUpdateSymbol = helpers.makeGetFirstSymbolValue([ + 'can.updateDeep', + 'can.assignDeep', + 'can.setKeyValue' + ]); + var shouldUpdateOrAssign = function (obj) { + return typeReflections.isPlainObject(obj) || Array.isArray(obj) || !!hasUpdateSymbol(obj); + }; + function isSerializable(obj) { + if (typeReflections.isPrimitive(obj)) { + return true; + } + if (hasUpdateSymbol(obj)) { + return false; + } + return typeReflections.isBuiltIn(obj) && !typeReflections.isPlainObject(obj); + } + var Object_Keys; + try { + Object.keys(1); + Object_Keys = Object.keys; + } catch (e) { + Object_Keys = function (obj) { + if (typeReflections.isPrimitive(obj)) { + return []; + } else { + return Object.keys(obj); + } + }; + } + function makeSerializer(methodName, symbolsToCheck) { + return function serializer(value, MapType) { + if (isSerializable(value)) { + return value; + } + var firstSerialize; + if (MapType && !serializeMap) { + serializeMap = { + unwrap: new MapType(), + serialize: new MapType() + }; + firstSerialize = true; + } + var serialized; + if (typeReflections.isValueLike(value)) { + serialized = this[methodName](getSetReflections.getValue(value)); + } else { + var isListLike = typeReflections.isIteratorLike(value) || typeReflections.isMoreListLikeThanMapLike(value); + serialized = isListLike ? [] : {}; + if (serializeMap) { + if (serializeMap[methodName].has(value)) { + return serializeMap[methodName].get(value); + } else { + serializeMap[methodName].set(value, serialized); + } + } + for (var i = 0, len = symbolsToCheck.length; i < len; i++) { + var serializer = value[symbolsToCheck[i]]; + if (serializer) { + var result = serializer.call(value, serialized); + if (firstSerialize) { + serializeMap = null; + } + return result; + } + } + if (typeof obj === 'function') { + if (serializeMap) { + serializeMap[methodName].set(value, value); + } + serialized = value; + } else if (isListLike) { + this.eachIndex(value, function (childValue, index) { + serialized[index] = this[methodName](childValue); + }, this); + } else { + this.eachKey(value, function (childValue, prop) { + serialized[prop] = this[methodName](childValue); + }, this); + } + } + if (firstSerialize) { + serializeMap = null; + } + return serialized; + }; + } + function makeMap(keys) { + var map = {}; + keys.forEach(function (key) { + map[key] = true; + }); + return map; + } + function addPatch(patches, patch) { + var lastPatch = patches[patches.length - 1]; + if (lastPatch) { + if (lastPatch.deleteCount === lastPatch.insert.length && patch.index - lastPatch.index === lastPatch.deleteCount) { + lastPatch.insert.push.apply(lastPatch.insert, patch.insert); + lastPatch.deleteCount += patch.deleteCount; + return; + } + } + patches.push(patch); + } + function updateDeepList(target, source, isAssign) { + var sourceArray = this.toArray(source); + var patches = [], lastIndex = -1; + this.eachIndex(target, function (curVal, index) { + lastIndex = index; + if (index >= sourceArray.length) { + if (!isAssign) { + addPatch(patches, { + index: index, + deleteCount: sourceArray.length - index + 1, + insert: [] + }); + } + return false; + } + var newVal = sourceArray[index]; + if (typeReflections.isPrimitive(curVal) || typeReflections.isPrimitive(newVal) || shouldUpdateOrAssign(curVal) === false) { + addPatch(patches, { + index: index, + deleteCount: 1, + insert: [newVal] + }); + } else { + this.updateDeep(curVal, newVal); + } + }, this); + if (sourceArray.length > lastIndex) { + addPatch(patches, { + index: lastIndex + 1, + deleteCount: 0, + insert: sourceArray.slice(lastIndex + 1) + }); + } + for (var i = 0, patchLen = patches.length; i < patchLen; i++) { + var patch = patches[i]; + getSetReflections.splice(target, patch.index, patch.deleteCount, patch.insert); + } + return target; + } + var shapeReflections = { + each: function (obj, callback, context) { + if (typeReflections.isIteratorLike(obj) || typeReflections.isMoreListLikeThanMapLike(obj)) { + return this.eachIndex(obj, callback, context); + } else { + return this.eachKey(obj, callback, context); + } + }, + eachIndex: function (list, callback, context) { + if (Array.isArray(list)) { + return this.eachListLike(list, callback, context); + } else { + var iter, iterator = list[canSymbol.iterator]; + if (typeReflections.isIteratorLike(list)) { + iter = list; + } else if (iterator) { + iter = iterator.call(list); + } + if (iter) { + var res, index = 0; + while (!(res = iter.next()).done) { + if (callback.call(context || list, res.value, index++, list) === false) { + break; + } + } + } else { + this.eachListLike(list, callback, context); + } + } + return list; + }, + eachListLike: function (list, callback, context) { + var index = -1; + var length = list.length; + while (++index < length) { + var item = list[index]; + if (callback.call(context || item, item, index, list) === false) { + break; + } + } + return list; + }, + toArray: function (obj) { + var arr = []; + this.each(obj, function (value) { + arr.push(value); + }); + return arr; + }, + eachKey: function (obj, callback, context) { + if (obj) { + var enumerableKeys = this.getOwnEnumerableKeys(obj); + var getKeyValue = obj[getKeyValueSymbol] || shiftedGetKeyValue; + return this.eachIndex(enumerableKeys, function (key) { + var value = getKeyValue.call(obj, key); + return callback.call(context || obj, value, key, obj); + }); + } + return obj; + }, + 'hasOwnKey': function (obj, key) { + var hasOwnKey = obj[canSymbol.for('can.hasOwnKey')]; + if (hasOwnKey) { + return hasOwnKey.call(obj, key); + } + var getOwnKeys = obj[canSymbol.for('can.getOwnKeys')]; + if (getOwnKeys) { + var found = false; + this.eachIndex(getOwnKeys.call(obj), function (objKey) { + if (objKey === key) { + found = true; + return false; + } + }); + return found; + } + return obj.hasOwnProperty(key); + }, + getOwnEnumerableKeys: function (obj) { + var getOwnEnumerableKeys = obj[canSymbol.for('can.getOwnEnumerableKeys')]; + if (getOwnEnumerableKeys) { + return getOwnEnumerableKeys.call(obj); + } + if (obj[canSymbol.for('can.getOwnKeys')] && obj[canSymbol.for('can.getOwnKeyDescriptor')]) { + var keys = []; + this.eachIndex(this.getOwnKeys(obj), function (key) { + var descriptor = this.getOwnKeyDescriptor(obj, key); + if (descriptor.enumerable) { + keys.push(key); + } + }, this); + return keys; + } else { + return Object_Keys(obj); + } + }, + getOwnKeys: function (obj) { + var getOwnKeys = obj[canSymbol.for('can.getOwnKeys')]; + if (getOwnKeys) { + return getOwnKeys.call(obj); + } else { + return Object.getOwnPropertyNames(obj); + } + }, + getOwnKeyDescriptor: function (obj, key) { + var getOwnKeyDescriptor = obj[canSymbol.for('can.getOwnKeyDescriptor')]; + if (getOwnKeyDescriptor) { + return getOwnKeyDescriptor.call(obj, key); + } else { + return Object.getOwnPropertyDescriptor(obj, key); + } + }, + unwrap: makeSerializer('unwrap', [canSymbol.for('can.unwrap')]), + serialize: makeSerializer('serialize', [ + canSymbol.for('can.serialize'), + canSymbol.for('can.unwrap') + ]), + assignMap: function (target, source) { + var targetKeyMap = makeMap(this.getOwnEnumerableKeys(target)); + var getKeyValue = target[getKeyValueSymbol] || shiftedGetKeyValue; + var setKeyValue = target[setKeyValueSymbol] || shiftedSetKeyValue; + this.eachKey(source, function (value, key) { + if (!targetKeyMap[key] || getKeyValue.call(target, key) !== value) { + setKeyValue.call(target, key, value); + } + }); + return target; + }, + assignList: function (target, source) { + var inserting = this.toArray(source); + getSetReflections.splice(target, 0, inserting.length, inserting); + return target; + }, + assign: function (target, source) { + if (typeReflections.isIteratorLike(source) || typeReflections.isMoreListLikeThanMapLike(source)) { + this.assignList(target, source); + } else { + this.assignMap(target, source); + } + return target; + }, + assignDeepMap: function (target, source) { + var targetKeyMap = makeMap(this.getOwnEnumerableKeys(target)); + var getKeyValue = target[getKeyValueSymbol] || shiftedGetKeyValue; + var setKeyValue = target[setKeyValueSymbol] || shiftedSetKeyValue; + this.eachKey(source, function (newVal, key) { + if (!targetKeyMap[key]) { + getSetReflections.setKeyValue(target, key, newVal); + } else { + var curVal = getKeyValue.call(target, key); + if (newVal === curVal) { + } else if (typeReflections.isPrimitive(curVal) || typeReflections.isPrimitive(newVal) || shouldUpdateOrAssign(curVal) === false) { + setKeyValue.call(target, key, newVal); + } else { + this.assignDeep(curVal, newVal); + } + } + }, this); + return target; + }, + assignDeepList: function (target, source) { + return updateDeepList.call(this, target, source, true); + }, + assignDeep: function (target, source) { + var assignDeep = target[canSymbol.for('can.assignDeep')]; + if (assignDeep) { + assignDeep.call(target, source); + } else if (typeReflections.isMoreListLikeThanMapLike(source)) { + this.assignDeepList(target, source); + } else { + this.assignDeepMap(target, source); + } + return target; + }, + updateMap: function (target, source) { + var sourceKeyMap = makeMap(this.getOwnEnumerableKeys(source)); + var sourceGetKeyValue = source[getKeyValueSymbol] || shiftedGetKeyValue; + var targetSetKeyValue = target[setKeyValueSymbol] || shiftedSetKeyValue; + this.eachKey(target, function (curVal, key) { + if (!sourceKeyMap[key]) { + getSetReflections.deleteKeyValue(target, key); + return; + } + sourceKeyMap[key] = false; + var newVal = sourceGetKeyValue.call(source, key); + if (newVal !== curVal) { + targetSetKeyValue.call(target, key, newVal); + } + }, this); + for (var key in sourceKeyMap) { + if (sourceKeyMap[key]) { + targetSetKeyValue.call(target, key, sourceGetKeyValue.call(source, key)); + } + } + return target; + }, + updateList: function (target, source) { + var inserting = this.toArray(source); + getSetReflections.splice(target, 0, target.length, inserting); + return target; + }, + update: function (target, source) { + if (typeReflections.isIteratorLike(source) || typeReflections.isMoreListLikeThanMapLike(source)) { + this.updateList(target, source); + } else { + this.updateMap(target, source); + } + return target; + }, + updateDeepMap: function (target, source) { + var sourceKeyMap = makeMap(this.getOwnEnumerableKeys(source)); + var sourceGetKeyValue = source[getKeyValueSymbol] || shiftedGetKeyValue; + var targetSetKeyValue = target[setKeyValueSymbol] || shiftedSetKeyValue; + this.eachKey(target, function (curVal, key) { + if (!sourceKeyMap[key]) { + getSetReflections.deleteKeyValue(target, key); + return; + } + sourceKeyMap[key] = false; + var newVal = sourceGetKeyValue.call(source, key); + if (typeReflections.isPrimitive(curVal) || typeReflections.isPrimitive(newVal) || shouldUpdateOrAssign(curVal) === false) { + targetSetKeyValue.call(target, key, newVal); + } else { + this.updateDeep(curVal, newVal); + } + }, this); + for (var key in sourceKeyMap) { + if (sourceKeyMap[key]) { + targetSetKeyValue.call(target, key, sourceGetKeyValue.call(source, key)); + } + } + return target; + }, + updateDeepList: function (target, source) { + return updateDeepList.call(this, target, source); + }, + updateDeep: function (target, source) { + var updateDeep = target[canSymbol.for('can.updateDeep')]; + if (updateDeep) { + updateDeep.call(target, source); + } else if (typeReflections.isMoreListLikeThanMapLike(source)) { + this.updateDeepList(target, source); + } else { + this.updateDeepMap(target, source); + } + return target; + }, + 'in': function () { + }, + getAllEnumerableKeys: function () { + }, + getAllKeys: function () { + }, + assignSymbols: function (target, source) { + this.eachKey(source, function (value, key) { + getSetReflections.setKeyValue(target, canSymbol.for(key), value); + }); + return target; + }, + isSerializable: isSerializable + }; + shapeReflections.keys = shapeReflections.getOwnEnumerableKeys; + module.exports = shapeReflections; +}); +/*can-reflect@1.2.6#can-reflect*/ +define('can-reflect', function (require, exports, module) { + var functionReflections = require('can-reflect/reflections/call/call'); + var getSet = require('can-reflect/reflections/get-set/get-set'); + var observe = require('can-reflect/reflections/observe/observe'); + var shape = require('can-reflect/reflections/shape/shape'); + var type = require('can-reflect/reflections/type/type'); + var namespace = require('can-namespace'); + var reflect = {}; + [ + functionReflections, + getSet, + observe, + shape, + type + ].forEach(function (reflections) { + for (var prop in reflections) { + reflect[prop] = reflections[prop]; + } + }); + module.exports = namespace.Reflect = reflect; +}); +/*can-map@3.3.3#bubble*/ +define('can-map/bubble', function (require, exports, module) { + var canEvent = require('can-event'); + var makeArray = require('can-util/js/make-array/make-array'); + var canReflect = require('can-reflect'); + var isEmptyObject = require('can-util/js/is-empty-object/is-empty-object'); + var bubble = { + bind: function (parent, eventName) { + if (!parent.__inSetup) { + var bubbleEvents = bubble.events(parent, eventName), len = bubbleEvents.length, bubbleEvent; + if (!parent._bubbleBindings) { + parent._bubbleBindings = {}; + } + for (var i = 0; i < len; i++) { + bubbleEvent = bubbleEvents[i]; + if (!parent._bubbleBindings[bubbleEvent]) { + parent._bubbleBindings[bubbleEvent] = 1; + bubble.childrenOf(parent, bubbleEvent); + } else { + parent._bubbleBindings[bubbleEvent]++; + } + } + } + }, + unbind: function (parent, eventName) { + var bubbleEvents = bubble.events(parent, eventName), len = bubbleEvents.length, bubbleEvent; + for (var i = 0; i < len; i++) { + bubbleEvent = bubbleEvents[i]; + if (parent._bubbleBindings) { + parent._bubbleBindings[bubbleEvent]--; + } + if (parent._bubbleBindings && !parent._bubbleBindings[bubbleEvent]) { + delete parent._bubbleBindings[bubbleEvent]; + bubble.teardownChildrenFrom(parent, bubbleEvent); + if (isEmptyObject(parent._bubbleBindings)) { + delete parent._bubbleBindings; + } + } + } + }, + add: function (parent, child, prop) { + if (canReflect.isObservableLike(child) && canReflect.isMapLike(child) && parent._bubbleBindings) { + for (var eventName in parent._bubbleBindings) { + if (parent._bubbleBindings[eventName]) { + bubble.teardownFromParent(parent, child, eventName); + bubble.toParent(child, parent, prop, eventName); + } + } + } + }, + addMany: function (parent, children) { + for (var i = 0, len = children.length; i < len; i++) { + bubble.add(parent, children[i], i); + } + }, + remove: function (parent, child) { + if (canReflect.isObservableLike(child) && canReflect.isMapLike(child) && parent._bubbleBindings) { + for (var eventName in parent._bubbleBindings) { + if (parent._bubbleBindings[eventName]) { + bubble.teardownFromParent(parent, child, eventName); + } + } + } + }, + removeMany: function (parent, children) { + for (var i = 0, len = children.length; i < len; i++) { + bubble.remove(parent, children[i]); + } + }, + set: function (parent, prop, value, current) { + if (canReflect.isObservableLike(value) && canReflect.isMapLike(value)) { + bubble.add(parent, value, prop); + } + if (canReflect.isObservableLike(current) && canReflect.isMapLike(current)) { + bubble.remove(parent, current); + } + return value; + }, + events: function (map, boundEventName) { + return map.constructor._bubbleRule(boundEventName, map); + }, + toParent: function (child, parent, prop, eventName) { + canEvent.listenTo.call(parent, child, eventName, function () { + var args = makeArray(arguments), ev = args.shift(); + args[0] = (canReflect.isObservableLike(parent) && canReflect.isListLike(parent) ? parent.indexOf(child) : prop) + (args[0] ? '.' + args[0] : ''); + ev.triggeredNS = ev.triggeredNS || {}; + if (ev.triggeredNS[parent._cid]) { + return; + } + ev.triggeredNS[parent._cid] = true; + canEvent.dispatch.call(parent, ev, args); + if (eventName === 'change') { + canEvent.dispatch.call(parent, args[0], [ + args[2], + args[3] + ]); + } + }); + }, + childrenOf: function (parent, eventName) { + parent._each(function (child, prop) { + if (child && child.bind) { + bubble.toParent(child, parent, prop, eventName); + } + }); + }, + teardownFromParent: function (parent, child, eventName) { + if (child && child.unbind) { + canEvent.stopListening.call(parent, child, eventName); + } + }, + teardownChildrenFrom: function (parent, eventName) { + parent._each(function (child) { + bubble.teardownFromParent(parent, child, eventName); + }); + }, + isBubbling: function (parent, eventName) { + return parent._bubbleBindings && parent._bubbleBindings[eventName]; + } + }; + module.exports = bubble; +}); +/*can-util@3.9.9#js/is-promise/is-promise*/ +define('can-util/js/is-promise/is-promise', function (require, exports, module) { + 'use strict'; + var canReflect = require('can-reflect'); + module.exports = function (obj) { + return canReflect.isPromise(obj); + }; +}); +/*can-util@3.9.9#js/assign/assign*/ +define('can-util/js/assign/assign', function (require, exports, module) { + module.exports = function (d, s) { + for (var prop in s) { + d[prop] = s[prop]; + } + return d; + }; +}); +/*can-map@3.3.3#map-helpers*/ +define('can-map/map-helpers', function (require, exports, module) { + var isPlainObject = require('can-util/js/is-plain-object/is-plain-object'); + var isPromise = require('can-util/js/is-promise/is-promise'); + var CID = require('can-cid'); + var assign = require('can-util/js/assign/assign'); + var canReflect = require('can-reflect'); + var madeMap = null; + var teardownMap = function () { + for (var cid in madeMap) { + if (madeMap[cid].added) { + delete madeMap[cid].obj._cid; + } + } + madeMap = null; + }; + var mapHelpers = { + attrParts: function (attr, keepKey) { + if (keepKey) { + return [attr]; + } + return typeof attr === 'object' ? attr : ('' + attr).split('.'); + }, + canMakeObserve: function (obj) { + return obj && !isPromise(obj) && (Array.isArray(obj) || isPlainObject(obj)); + }, + reflectSerialize: function (unwrapped) { + this.each(function (val, name) { + if (this.___serialize) { + val = this.___serialize(name, val); + } else { + val = canReflect.serialize(val); + } + if (val !== undefined) { + unwrapped[name] = val; + } + }, this); + return unwrapped; + }, + reflectUnwrap: function (unwrapped) { + this.each(function (value, key) { + if (value !== undefined) { + unwrapped[key] = canReflect.unwrap(value); + } + }); + return unwrapped; + }, + removeSpecialKeys: function (map) { + if (map) { + [ + '_data', + 'constructor', + '_cid', + '__bindEvents' + ].forEach(function (key) { + delete map[key]; + }); + } + return map; + }, + define: null, + addComputedAttr: function (map, attrName, compute) { + map._computedAttrs[attrName] = { + compute: compute, + count: 0, + handler: function (newVal, oldVal) { + map._triggerChange(attrName, 'set', newVal, oldVal); + } + }; + }, + addToMap: function addToMap(obj, instance) { + var teardown; + if (!madeMap) { + teardown = teardownMap; + madeMap = {}; + } + var hasCid = obj._cid; + var cid = CID(obj); + if (!madeMap[cid]) { + madeMap[cid] = { + obj: obj, + instance: instance, + added: !hasCid + }; + } + return teardown; + }, + getMapFromObject: function (obj) { + return madeMap && madeMap[obj._cid] && madeMap[obj._cid].instance; + }, + twoLevelDeepExtend: function (destination, source) { + for (var prop in source) { + destination[prop] = destination[prop] || {}; + assign(destination[prop], source[prop]); + } + } + }; + module.exports = exports = mapHelpers; +}); +/*can-util@3.9.9#js/last/last*/ +define('can-util/js/last/last', function (require, exports, module) { + 'use strict'; + module.exports = function (arr) { + return arr && arr[arr.length - 1]; + }; +}); +/*can-types@1.1.1#can-types*/ +define('can-types', function (require, exports, module) { + var namespace = require('can-namespace'); + var canReflect = require('can-reflect'); + var canSymbol = require('can-symbol'); + var dev = require('can-util/js/dev/dev'); + var types = { + isMapLike: function (obj) { + return canReflect.isObservableLike(obj) && canReflect.isMapLike(obj); + }, + isListLike: function (obj) { + return canReflect.isObservableLike(obj) && canReflect.isListLike(obj); + }, + isPromise: function (obj) { + return canReflect.isPromise(obj); + }, + isConstructor: function (func) { + return canReflect.isConstructorLike(func); + }, + isCallableForValue: function (obj) { + return obj && canReflect.isFunctionLike(obj) && !canReflect.isConstructorLike(obj); + }, + isCompute: function (obj) { + return obj && obj.isComputed; + }, + get iterator() { + return canSymbol.iterator || canSymbol.for('iterator'); + }, + DefaultMap: null, + DefaultList: null, + queueTask: function (task) { + var args = task[2] || []; + task[0].apply(task[1], args); + }, + wrapElement: function (element) { + return element; + }, + unwrapElement: function (element) { + return element; + } + }; + if (namespace.types) { + throw new Error('You can\'t have two versions of can-types, check your dependencies'); + } else { + module.exports = namespace.types = types; + } +}); +/*can-event@3.7.1#batch/batch*/ +define('can-event/batch/batch', function (require, exports, module) { + 'use strict'; + var canEvent = require('can-event'); + var last = require('can-util/js/last/last'); + var namespace = require('can-namespace'); + var canTypes = require('can-types'); + var canDev = require('can-util/js/dev/dev'); + var canLog = require('can-util/js/log/log'); + var batchNum = 1, collectionQueue = null, queues = [], dispatchingQueues = false, makeHandlerArgs = canEvent.makeHandlerArgs, getHandlers = canEvent.handlers; + function addToCollectionQueue(item, event, args, handlers) { + var handlerArgs = makeHandlerArgs(event, args); + var tasks = []; + for (var i = 0, len = handlers.length; i < len; i++) { + tasks[i] = [ + handlers[i], + item, + handlerArgs + ]; + } + [].push.apply(collectionQueue.tasks, tasks); + } + var canBatch = { + transactions: 0, + start: function (batchStopHandler) { + canBatch.transactions++; + if (canBatch.transactions === 1) { + var queue = { + number: batchNum++, + index: 0, + tasks: [], + batchEnded: false, + callbacksIndex: 0, + callbacks: [], + complete: false + }; + if (batchStopHandler) { + queue.callbacks.push(batchStopHandler); + } + collectionQueue = queue; + } + }, + collecting: function () { + return collectionQueue; + }, + dispatching: function () { + return queues[0]; + }, + stop: function (force, callStart) { + if (force) { + canBatch.transactions = 0; + } else { + canBatch.transactions--; + } + if (canBatch.transactions === 0) { + queues.push(collectionQueue); + collectionQueue = null; + if (!dispatchingQueues) { + canEvent.flush(); + } + } + }, + flush: function () { + dispatchingQueues = true; + while (queues.length) { + var queue = queues[0]; + var tasks = queue.tasks, callbacks = queue.callbacks; + canBatch.batchNum = queue.number; + var len = tasks.length; + while (queue.index < len) { + var task = tasks[queue.index++]; + task[0].apply(task[1], task[2]); + } + if (!queue.batchEnded) { + queue.batchEnded = true; + canEvent.dispatchSync.call(canBatch, 'batchEnd', [queue.number]); + } + while (queue.callbacksIndex < callbacks.length) { + callbacks[queue.callbacksIndex++](); + } + if (!queue.complete) { + queue.complete = true; + canBatch.batchNum = undefined; + queues.shift(); + } + } + dispatchingQueues = false; + }, + dispatch: function (event, args) { + var item = this, handlers; + if (!item.__inSetup) { + event = typeof event === 'string' ? { type: event } : event; + if (event.batchNum) { + canBatch.batchNum = event.batchNum; + canEvent.dispatchSync.call(item, event, args); + } else if (collectionQueue) { + handlers = getHandlers.call(this, event.type); + if (handlers) { + event.batchNum = collectionQueue.number; + addToCollectionQueue(item, event, args, handlers); + } + } else if (queues.length) { + handlers = getHandlers.call(this, event.type); + if (handlers) { + canBatch.start(); + event.batchNum = collectionQueue.number; + addToCollectionQueue(item, event, args, handlers); + last(queues).callbacks.push(canBatch.stop); + } + } else { + handlers = getHandlers.call(this, event.type); + if (handlers) { + canBatch.start(); + event.batchNum = collectionQueue.number; + addToCollectionQueue(item, event, args, handlers); + canBatch.stop(); + } + } + } + }, + queue: function (task, inCurrentBatch) { + if (collectionQueue) { + collectionQueue.tasks.push(task); + } else if (queues.length) { + if (inCurrentBatch && queues[0].index < queues.tasks.length) { + queues[0].tasks.push(task); + } else { + canBatch.start(); + collectionQueue.tasks.push(task); + last(queues).callbacks.push(canBatch.stop); + } + } else { + canBatch.start(); + collectionQueue.tasks.push(task); + canBatch.stop(); + } + }, + queues: function () { + return queues; + }, + afterPreviousEvents: function (handler) { + this.queue([handler]); + }, + after: function (handler) { + var queue = collectionQueue || queues[0]; + if (queue) { + queue.callbacks.push(handler); + } else { + handler({}); + } + } + }; + Object.defineProperty(canBatch, 'debounce', { + enumerable: false, + value: function (handler) { + var that = null; + var args = null; + return function () { + if (!that) { + canEvent.addEventListener.call(canBatch, 'batchEnd', function listener() { + canEvent.removeEventListener.call(canBatch, 'batchEnd', listener); + handler.apply(that, args); + that = null; + args = null; + }); + } + that = this; + args = arguments; + }; + } + }); + canEvent.flush = canBatch.flush; + canEvent.dispatch = canBatch.dispatch; + canBatch.trigger = function () { + canLog.warn('use canEvent.dispatch instead'); + return canEvent.dispatch.apply(this, arguments); + }; + canTypes.queueTask = canBatch.queue; + if (namespace.batch) { + throw new Error('You can\'t have two versions of can-event/batch/batch, check your dependencies'); + } else { + module.exports = namespace.batch = canBatch; + } +}); +/*can-event@3.7.1#lifecycle/lifecycle*/ +define('can-event/lifecycle/lifecycle', function (require, exports, module) { + var canEvent = require('can-event'); + var lifecycle = function (prototype) { + var baseAddEventListener = prototype.addEventListener; + var baseRemoveEventListener = prototype.removeEventListener; + prototype.addEventListener = function () { + var ret = baseAddEventListener.apply(this, arguments); + if (!this.__inSetup) { + this.__bindEvents = this.__bindEvents || {}; + if (!this.__bindEvents._lifecycleBindings) { + this.__bindEvents._lifecycleBindings = 1; + if (this._eventSetup) { + this._eventSetup(); + } + } else { + this.__bindEvents._lifecycleBindings++; + } + } + return ret; + }; + prototype.removeEventListener = function (event, handler) { + if (!this.__bindEvents) { + return this; + } + var handlers = this.__bindEvents[event] || []; + var handlerCount = handlers.length; + var ret = baseRemoveEventListener.apply(this, arguments); + if (this.__bindEvents._lifecycleBindings === null) { + this.__bindEvents._lifecycleBindings = 0; + } else { + this.__bindEvents._lifecycleBindings -= handlerCount - handlers.length; + } + if (!this.__bindEvents._lifecycleBindings && this._eventTeardown) { + this._eventTeardown(); + } + return ret; + }; + return prototype; + }; + var baseEvents = lifecycle({ + addEventListener: canEvent.addEventListener, + removeEventListener: canEvent.removeEventListener + }); + lifecycle.addAndSetup = baseEvents.addEventListener; + lifecycle.removeAndTeardown = baseEvents.removeEventListener; + module.exports = lifecycle; +}); +/*can-util@3.9.9#js/is-function/is-function*/ +define('can-util/js/is-function/is-function', function (require, exports, module) { + 'use strict'; + var isFunction = function () { + if (typeof document !== 'undefined' && typeof document.getElementsByTagName('body') === 'function') { + return function (value) { + return Object.prototype.toString.call(value) === '[object Function]'; + }; + } + return function (value) { + return typeof value === 'function'; + }; + }(); + module.exports = isFunction; +}); +/*can-util@3.9.9#js/deep-assign/deep-assign*/ +define('can-util/js/deep-assign/deep-assign', function (require, exports, module) { + 'use strict'; + var isFunction = require('can-util/js/is-function/is-function'); + var isPlainObject = require('can-util/js/is-plain-object/is-plain-object'); + function deepAssign() { + var options, name, src, copy, copyIsArray, clone, target = arguments[0] || {}, i = 1, length = arguments.length; + if (typeof target !== 'object' && !isFunction(target)) { + target = {}; + } + if (length === i) { + target = this; + --i; + } + for (; i < length; i++) { + if ((options = arguments[i]) != null) { + for (name in options) { + src = target[name]; + copy = options[name]; + if (target === copy) { + continue; + } + if (copy && (isPlainObject(copy) || (copyIsArray = Array.isArray(copy)))) { + if (copyIsArray) { + copyIsArray = false; + clone = src && Array.isArray(src) ? src : []; + } else { + clone = src && isPlainObject(src) ? src : {}; + } + target[name] = deepAssign(clone, copy); + } else if (copy !== undefined) { + target[name] = copy; + } + } + } + } + return target; + } + module.exports = deepAssign; +}); +/*can-construct@3.2.0#can-construct*/ +define('can-construct', function (require, exports, module) { + 'use strict'; + var assign = require('can-util/js/assign/assign'); + var deepAssign = require('can-util/js/deep-assign/deep-assign'); + var dev = require('can-util/js/dev/dev'); + var makeArray = require('can-util/js/make-array/make-array'); + var namespace = require('can-namespace'); + var initializing = 0; + var Construct = function () { + if (arguments.length) { + return Construct.extend.apply(Construct, arguments); + } + }; + var canGetDescriptor; + try { + Object.getOwnPropertyDescriptor({}); + canGetDescriptor = true; + } catch (e) { + canGetDescriptor = false; + } + var getDescriptor = function (newProps, name) { + var descriptor = Object.getOwnPropertyDescriptor(newProps, name); + if (descriptor && (descriptor.get || descriptor.set)) { + return descriptor; + } + return null; + }, inheritGetterSetter = function (newProps, oldProps, addTo) { + addTo = addTo || newProps; + var descriptor; + for (var name in newProps) { + if (descriptor = getDescriptor(newProps, name)) { + this._defineProperty(addTo, oldProps, name, descriptor); + } else { + Construct._overwrite(addTo, oldProps, name, newProps[name]); + } + } + }, simpleInherit = function (newProps, oldProps, addTo) { + addTo = addTo || newProps; + for (var name in newProps) { + Construct._overwrite(addTo, oldProps, name, newProps[name]); + } + }; + assign(Construct, { + constructorExtends: true, + newInstance: function () { + var inst = this.instance(), args; + if (inst.setup) { + Object.defineProperty(inst, '__inSetup', { + configurable: true, + enumerable: false, + value: true, + writable: true + }); + args = inst.setup.apply(inst, arguments); + if (args instanceof Construct.ReturnValue) { + return args.value; + } + inst.__inSetup = false; + } + if (inst.init) { + inst.init.apply(inst, args || arguments); + } + return inst; + }, + _inherit: canGetDescriptor ? inheritGetterSetter : simpleInherit, + _defineProperty: function (what, oldProps, propName, descriptor) { + Object.defineProperty(what, propName, descriptor); + }, + _overwrite: function (what, oldProps, propName, val) { + Object.defineProperty(what, propName, { + value: val, + configurable: true, + enumerable: true, + writable: true + }); + }, + setup: function (base) { + this.defaults = deepAssign(true, {}, base.defaults, this.defaults); + }, + instance: function () { + initializing = 1; + var inst = new this(); + initializing = 0; + return inst; + }, + extend: function (name, staticProperties, instanceProperties) { + var shortName = name, klass = staticProperties, proto = instanceProperties; + if (typeof shortName !== 'string') { + proto = klass; + klass = shortName; + shortName = null; + } + if (!proto) { + proto = klass; + klass = null; + } + proto = proto || {}; + var _super_class = this, _super = this.prototype, Constructor, prototype; + prototype = this.instance(); + Construct._inherit(proto, _super, prototype); + if (shortName) { + } else if (klass && klass.shortName) { + shortName = klass.shortName; + } else if (this.shortName) { + shortName = this.shortName; + } + function init() { + if (!initializing) { + return (!this || this.constructor !== Constructor) && arguments.length && Constructor.constructorExtends ? Constructor.extend.apply(Constructor, arguments) : Constructor.newInstance.apply(Constructor, arguments); + } + } + Constructor = typeof namedCtor === 'function' ? namedCtor(constructorName, init) : function () { + return init.apply(this, arguments); + }; + for (var propName in _super_class) { + if (_super_class.hasOwnProperty(propName)) { + Constructor[propName] = _super_class[propName]; + } + } + Construct._inherit(klass, _super_class, Constructor); + assign(Constructor, { + constructor: Constructor, + prototype: prototype + }); + if (shortName !== undefined) { + Constructor.shortName = shortName; + } + Constructor.prototype.constructor = Constructor; + var t = [_super_class].concat(makeArray(arguments)), args = Constructor.setup.apply(Constructor, t); + if (Constructor.init) { + Constructor.init.apply(Constructor, args || t); + } + return Constructor; + }, + ReturnValue: function (value) { + this.value = value; + } + }); + Construct.prototype.setup = function () { + }; + Construct.prototype.init = function () { + }; + module.exports = namespace.Construct = Construct; +}); +/*can-util@3.9.9#js/cid-map/cid-map*/ +define('can-util/js/cid-map/cid-map', function (require, exports, module) { + (function (global) { + 'use strict'; + var GLOBAL = require('can-util/js/global/global'); + var each = require('can-util/js/each/each'); + var getCID = require('can-util/js/cid/get-cid'); + var CIDMap; + if (GLOBAL().Map) { + CIDMap = GLOBAL().Map; + } else { + var CIDMap = function () { + this.values = {}; + }; + CIDMap.prototype.set = function (key, value) { + this.values[getCID(key)] = { + key: key, + value: value + }; + }; + CIDMap.prototype['delete'] = function (key) { + var has = getCID(key) in this.values; + if (has) { + delete this.values[getCID(key)]; + } + return has; + }; + CIDMap.prototype.forEach = function (cb, thisArg) { + each(this.values, function (pair) { + return cb.call(thisArg || this, pair.value, pair.key, this); + }, this); + }; + CIDMap.prototype.has = function (key) { + return getCID(key) in this.values; + }; + CIDMap.prototype.get = function (key) { + var obj = this.values[getCID(key)]; + return obj && obj.value; + }; + CIDMap.prototype.clear = function (key) { + return this.values = {}; + }; + Object.defineProperty(CIDMap.prototype, 'size', { + get: function () { + var size = 0; + each(this.values, function () { + size++; + }); + return size; + } + }); + } + module.exports = CIDMap; + }(function () { + return this; + }())); +}); +/*can-observation@3.3.5#can-observation*/ +define('can-observation', function (require, exports, module) { + (function (global) { + require('can-event'); + var canEvent = require('can-event'); + var canBatch = require('can-event/batch/batch'); + var assign = require('can-util/js/assign/assign'); + var isEmptyObject = require('can-util/js/is-empty-object/is-empty-object'); + var namespace = require('can-namespace'); + var canLog = require('can-util/js/log/log'); + var canReflect = require('can-reflect'); + var canSymbol = require('can-symbol'); + var CID = require('can-cid'); + var CIDMap = require('can-util/js/cid-map/cid-map'); + var CIDSet = require('can-util/js/cid-set/cid-set'); + function Observation(func, context, compute) { + this.newObserved = {}; + this.oldObserved = null; + this.func = func; + this.context = context; + this.compute = compute && (compute.updater || 'isObservable' in compute) ? compute : { updater: compute }; + this.isObservable = typeof compute === 'object' ? compute.isObservable : true; + var observation = this; + this.onDependencyChange = function (value, legacyValue) { + observation.dependencyChange(this, value, legacyValue); + }; + this.ignore = 0; + this.needsUpdate = false; + this.handlers = null; + CID(this); + } + var observationStack = []; + Observation.observationStack = observationStack; + var remaining = { + updates: 0, + notifications: 0 + }; + Observation.remaining = remaining; + assign(Observation.prototype, { + get: function () { + if (this.isObservable && Observation.isRecording()) { + Observation.add(this); + if (!this.bound) { + Observation.temporarilyBind(this); + } + } + if (this.bound === true) { + canEvent.flush(); + if (remaining.updates > 0) { + Observation.updateChildrenAndSelf(this); + } + return this.value; + } else { + return this.func.call(this.context); + } + }, + getPrimaryDepth: function () { + return this.compute._primaryDepth || 0; + }, + addEdge: function (objEv) { + if (objEv.event === 'undefined') { + canReflect.onValue(objEv.obj, this.onDependencyChange); + } else { + canReflect.onKeyValue(objEv.obj, objEv.event, this.onDependencyChange); + } + }, + removeEdge: function (objEv) { + if (objEv.event === 'undefined') { + canReflect.offValue(objEv.obj, this.onDependencyChange); + } else { + canReflect.offKeyValue(objEv.obj, objEv.event, this.onDependencyChange); + } + }, + dependencyChange: function () { + if (this.bound === true) { + if (canBatch.batchNum === undefined || canBatch.batchNum !== this.batchNum) { + Observation.registerUpdate(this, canBatch.batchNum); + this.batchNum = canBatch.batchNum; + } + } + }, + onDependencyChange: function (value) { + this.dependencyChange(value); + }, + update: function (batchNum) { + if (this.needsUpdate === true) { + remaining.updates--; + } + this.needsUpdate = false; + if (this.bound === true) { + var oldValue = this.value; + this.oldValue = null; + this.start(); + if (oldValue !== this.value) { + this.compute.updater(this.value, oldValue, batchNum); + return true; + } + } + }, + getValueAndBind: function () { + canLog.warn('can-observation: call start instead of getValueAndBind'); + return this.start(); + }, + start: function () { + this.bound = true; + this.oldObserved = this.newObserved || {}; + this.ignore = 0; + this.newObserved = {}; + observationStack.push(this); + this.value = this.func.call(this.context); + observationStack.pop(); + this.updateBindings(); + }, + updateBindings: function () { + var newObserved = this.newObserved, oldObserved = this.oldObserved, name, obEv; + for (name in newObserved) { + obEv = newObserved[name]; + if (!oldObserved[name]) { + this.addEdge(obEv); + } else { + oldObserved[name] = undefined; + } + } + for (name in oldObserved) { + obEv = oldObserved[name]; + if (obEv !== undefined) { + this.removeEdge(obEv); + } + } + }, + teardown: function () { + canLog.warn('can-observation: call stop instead of teardown'); + return this.stop(); + }, + stop: function () { + this.bound = false; + for (var name in this.newObserved) { + var ob = this.newObserved[name]; + this.removeEdge(ob); + } + this.newObserved = {}; + } + }); + var updateOrder = [], curPrimaryDepth = Infinity, maxPrimaryDepth = 0, currentBatchNum, isUpdating = false; + var updateUpdateOrder = function (observation) { + var primaryDepth = observation.getPrimaryDepth(); + if (primaryDepth < curPrimaryDepth) { + curPrimaryDepth = primaryDepth; + } + if (primaryDepth > maxPrimaryDepth) { + maxPrimaryDepth = primaryDepth; + } + var primary = updateOrder[primaryDepth] || (updateOrder[primaryDepth] = []); + return primary; + }; + Observation.registerUpdate = function (observation, batchNum) { + if (observation.needsUpdate === true) { + return; + } + remaining.updates++; + observation.needsUpdate = true; + var objs = updateUpdateOrder(observation); + objs.push(observation); + }; + var afterCallbacks = []; + Observation.updateAndNotify = function (ev, batchNum) { + currentBatchNum = batchNum; + if (isUpdating === true) { + return; + } + isUpdating = true; + while (true) { + if (curPrimaryDepth <= maxPrimaryDepth) { + var primary = updateOrder[curPrimaryDepth]; + var lastUpdate = primary && primary.pop(); + if (lastUpdate !== undefined) { + lastUpdate.update(currentBatchNum); + } else { + curPrimaryDepth++; + } + } else { + updateOrder = []; + curPrimaryDepth = Infinity; + maxPrimaryDepth = 0; + isUpdating = false; + var afterCB = afterCallbacks; + afterCallbacks = []; + afterCB.forEach(function (cb) { + cb(); + }); + return; + } + } + }; + canEvent.addEventListener.call(canBatch, 'batchEnd', Observation.updateAndNotify); + Observation.afterUpdateAndNotify = function (callback) { + canBatch.after(function () { + if (isUpdating === true) { + afterCallbacks.push(callback); + } else { + callback(); + } + }); + }; + Observation.updateChildrenAndSelf = function (observation) { + if (observation.needsUpdate === true) { + return Observation.unregisterAndUpdate(observation); + } + var childHasChanged = false; + for (var prop in observation.newObserved) { + if (observation.newObserved[prop].obj.observation) { + if (Observation.updateChildrenAndSelf(observation.newObserved[prop].obj.observation)) { + childHasChanged = true; + } + } + } + if (childHasChanged === true) { + return observation.update(currentBatchNum); + } + }; + Observation.unregisterAndUpdate = function (observation) { + var primaryDepth = observation.getPrimaryDepth(); + var primary = updateOrder[primaryDepth]; + if (primary !== undefined) { + var index = primary.indexOf(observation); + if (index !== -1) { + primary.splice(index, 1); + } + } + return observation.update(currentBatchNum); + }; + Observation.add = function (obj, event) { + var top = observationStack[observationStack.length - 1]; + if (top !== undefined && !top.ignore) { + var evStr = event + '', name = obj._cid + '|' + evStr; + if (top.traps !== undefined) { + top.traps.push({ + obj: obj, + event: evStr, + name: name + }); + } else { + top.newObserved[name] = { + obj: obj, + event: evStr + }; + } + } + }; + Observation.addAll = function (observes) { + var top = observationStack[observationStack.length - 1]; + if (top !== undefined) { + if (top.traps !== undefined) { + top.traps.push.apply(top.traps, observes); + } else { + for (var i = 0, len = observes.length; i < len; i++) { + var trap = observes[i], name = trap.name; + if (top.newObserved[name] === undefined) { + top.newObserved[name] = trap; + } + } + } + } + }; + Observation.ignore = function (fn) { + return function () { + if (observationStack.length > 0) { + var top = observationStack[observationStack.length - 1]; + top.ignore++; + var res = fn.apply(this, arguments); + top.ignore--; + return res; + } else { + return fn.apply(this, arguments); + } + }; + }; + Observation.trap = function () { + if (observationStack.length > 0) { + var top = observationStack[observationStack.length - 1]; + var oldTraps = top.traps; + var traps = top.traps = []; + return function () { + top.traps = oldTraps; + return traps; + }; + } else { + return function () { + return []; + }; + } + }; + Observation.trapsCount = function () { + if (observationStack.length > 0) { + var top = observationStack[observationStack.length - 1]; + return top.traps.length; + } else { + return 0; + } + }; + Observation.isRecording = function () { + var len = observationStack.length; + var last = len > 0 && observationStack[len - 1]; + return last && last.ignore === 0; + }; + var noop = function () { + }; + var observables; + var unbindComputes = function () { + for (var i = 0, len = observables.length; i < len; i++) { + canReflect.offValue(observables[i], noop); + } + observables = null; + }; + Observation.temporarilyBind = function (compute) { + var computeInstance = compute.computeInstance || compute; + canReflect.onValue(computeInstance, noop); + if (!observables) { + observables = []; + setTimeout(unbindComputes, 10); + } + observables.push(computeInstance); + }; + var callHandlers = function (newValue) { + this.handlers.forEach(function (handler) { + handler.call(this.compute, newValue); + }, this); + }; + canReflect.set(Observation.prototype, canSymbol.for('can.onValue'), function (handler) { + if (!this.handlers) { + this.handlers = []; + this.compute.updater = callHandlers.bind(this); + } + if (!this.handlers.length) { + this.start(); + } + this.handlers.push(handler); + }); + canReflect.set(Observation.prototype, canSymbol.for('can.offValue'), function (handler) { + if (this.handlers) { + var index = this.handlers.indexOf(handler); + this.handlers.splice(index, 1); + if (this.handlers.length === 0) { + this.stop(); + } + } + }); + canReflect.set(Observation.prototype, canSymbol.for('can.getValue'), Observation.prototype.get); + Observation.prototype.hasDependencies = function () { + return this.bound ? !isEmptyObject(this.newObserved) : undefined; + }; + canReflect.set(Observation.prototype, canSymbol.for('can.isValueLike'), true); + canReflect.set(Observation.prototype, canSymbol.for('can.isMapLike'), false); + canReflect.set(Observation.prototype, canSymbol.for('can.isListLike'), false); + canReflect.set(Observation.prototype, canSymbol.for('can.valueHasDependencies'), Observation.prototype.hasDependencies); + canReflect.set(Observation.prototype, canSymbol.for('can.getValueDependencies'), function () { + var rets; + if (this.bound === true) { + rets = {}; + canReflect.eachKey(this.newObserved || {}, function (dep) { + if (canReflect.isValueLike(dep.obj)) { + rets.valueDependencies = rets.valueDependencies || new CIDSet(); + rets.valueDependencies.add(dep.obj); + } else { + rets.keyDependencies = rets.keyDependencies || new CIDMap(); + if (rets.keyDependencies.get(dep.obj)) { + rets.keyDependencies.get(dep.obj).push(dep.event); + } else { + rets.keyDependencies.set(dep.obj, [dep.event]); + } + } + }); + } + return rets; + }); + if (namespace.Observation) { + throw new Error('You can\'t have two versions of can-observation, check your dependencies'); + } else { + module.exports = namespace.Observation = Observation; + } + }(function () { + return this; + }())); +}); +/*can-util@3.9.9#js/is-promise-like/is-promise-like*/ +define('can-util/js/is-promise-like/is-promise-like', function (require, exports, module) { + 'use strict'; + module.exports = function (obj) { + return !!obj && (typeof obj === 'object' || typeof obj === 'function') && typeof obj.then === 'function'; + }; +}); +/*can-reflect-promise@1.1.0#can-reflect-promise*/ +define('can-reflect-promise', function (require, exports, module) { + var canReflect = require('can-reflect'); + var canSymbol = require('can-symbol'); + var dev = require('can-util/js/dev/dev'); + var Observation = require('can-observation'); + var CID = require('can-cid'); + var assign = require('can-util/js/assign/assign'); + var canEvent = require('can-event'); + var singleReference = require('can-util/js/single-reference/single-reference'); + var getValueSymbol = canSymbol.for('can.getValue'), getKeyValueSymbol = canSymbol.for('can.getKeyValue'), onValueSymbol = canSymbol.for('can.onValue'), onKeyValueSymbol = canSymbol.for('can.onKeyValue'), offKeyValueSymbol = canSymbol.for('can.offKeyValue'), observeDataSymbol = canSymbol.for('can.observeData'); + var promiseDataPrototype = { + isPending: true, + state: 'pending', + isResolved: false, + isRejected: false, + value: undefined, + reason: undefined + }; + assign(promiseDataPrototype, canEvent); + canReflect.set(promiseDataPrototype, onKeyValueSymbol, function (key, handler) { + var observeData = this; + var translated = function () { + handler(observeData[key]); + }; + singleReference.set(handler, this, translated, key); + canEvent.on.call(this, 'state', translated); + }); + canReflect.set(promiseDataPrototype, offKeyValueSymbol, function (key, handler) { + var translated = singleReference.getAndDelete(handler, this, key); + canEvent.off.call(this, 'state', translated); + }); + function initPromise(promise) { + var observeData = promise[observeDataSymbol]; + if (!observeData) { + Object.defineProperty(promise, observeDataSymbol, { + enumerable: false, + configurable: false, + writable: false, + value: Object.create(promiseDataPrototype) + }); + observeData = promise[observeDataSymbol]; + CID(observeData); + } + promise.then(function (value) { + observeData.isPending = false; + observeData.isResolved = true; + observeData.value = value; + observeData.state = 'resolved'; + observeData.dispatch('state', [ + 'resolved', + 'pending' + ]); + }, function (reason) { + observeData.isPending = false; + observeData.isRejected = true; + observeData.reason = reason; + observeData.state = 'rejected'; + observeData.dispatch('state', [ + 'rejected', + 'pending' + ]); + }); + } + function setupPromise(value) { + var oldPromiseFn; + var proto = 'getPrototypeOf' in Object ? Object.getPrototypeOf(value) : value.__proto__; + if (value[getKeyValueSymbol] && value[observeDataSymbol]) { + return; + } + if (proto === null || proto === Object.prototype) { + proto = value; + if (typeof proto.promise === 'function') { + oldPromiseFn = proto.promise; + proto.promise = function () { + var result = oldPromiseFn.call(proto); + setupPromise(result); + return result; + }; + } + } + [ + getKeyValueSymbol, + function (key) { + if (!this[observeDataSymbol]) { + initPromise(this); + } + Observation.add(this[observeDataSymbol], 'state'); + switch (key) { + case 'state': + case 'isPending': + case 'isResolved': + case 'isRejected': + case 'value': + case 'reason': + return this[observeDataSymbol][key]; + default: + return this[key]; + } + }, + getValueSymbol, + function () { + return this[getKeyValueSymbol]('value'); + }, + canSymbol.for('can.isValueLike'), + false, + onValueSymbol, + function (handler) { + return this[onKeyValueSymbol]('value', handler); + }, + onKeyValueSymbol, + function (key, handler) { + if (!this[observeDataSymbol]) { + initPromise(this); + } + var promise = this; + var translated = function () { + handler(promise[getKeyValueSymbol](key)); + }; + singleReference.set(handler, this, translated, key); + canEvent.on.call(this[observeDataSymbol], 'state', translated); + }, + canSymbol.for('can.offValue'), + function (handler) { + return this[offKeyValueSymbol]('value', handler); + }, + offKeyValueSymbol, + function (key, handler) { + var translated = singleReference.getAndDelete(handler, this, key); + if (translated) { + canEvent.off.call(this[observeDataSymbol], 'state', translated); + } + } + ].forEach(function (symbol, index, list) { + if (index % 2 === 0) { + canReflect.set(proto, symbol, list[index + 1]); + } + }); + } + module.exports = setupPromise; +}); +/*can-stache-key@0.1.0#can-stache-key*/ +define('can-stache-key', function (require, exports, module) { + var Observation = require('can-observation'); + var dev = require('can-util/js/dev/dev'); + var each = require('can-util/js/each/each'); + var canSymbol = require('can-symbol'); + var canReflect = require('can-reflect'); + var isPromiseLike = require('can-util/js/is-promise-like/is-promise-like'); + var canReflectPromise = require('can-reflect-promise'); + var getValueSymbol = canSymbol.for('can.getValue'); + var setValueSymbol = canSymbol.for('can.setValue'); + var isValueLikeSymbol = canSymbol.for('can.isValueLike'); + var observeReader; + var isAt = function (index, reads) { + var prevRead = reads[index - 1]; + return prevRead && prevRead.at; + }; + var readValue = function (value, index, reads, options, state, prev) { + var usedValueReader; + do { + usedValueReader = false; + for (var i = 0, len = observeReader.valueReaders.length; i < len; i++) { + if (observeReader.valueReaders[i].test(value, index, reads, options)) { + value = observeReader.valueReaders[i].read(value, index, reads, options, state, prev); + } + } + } while (usedValueReader); + return value; + }; + var specialRead = { + index: true, + key: true, + event: true, + element: true, + viewModel: true + }; + var checkForObservableAndNotify = function (options, state, getObserves, value, index) { + if (options.foundObservable && !state.foundObservable) { + if (Observation.trapsCount()) { + Observation.addAll(getObserves()); + options.foundObservable(value, index); + state.foundObservable = true; + } + } + }; + observeReader = { + read: function (parent, reads, options) { + options = options || {}; + var state = { foundObservable: false }; + var getObserves; + if (options.foundObservable) { + getObserves = Observation.trap(); + } + var cur = readValue(parent, 0, reads, options, state), type, prev, readLength = reads.length, i = 0, last; + checkForObservableAndNotify(options, state, getObserves, parent, 0); + while (i < readLength) { + prev = cur; + for (var r = 0, readersLength = observeReader.propertyReaders.length; r < readersLength; r++) { + var reader = observeReader.propertyReaders[r]; + if (reader.test(cur)) { + cur = reader.read(cur, reads[i], i, options, state); + break; + } + } + checkForObservableAndNotify(options, state, getObserves, prev, i); + last = cur; + i = i + 1; + cur = readValue(cur, i, reads, options, state, prev); + checkForObservableAndNotify(options, state, getObserves, prev, i - 1); + type = typeof cur; + if (i < reads.length && (cur === null || cur === undefined)) { + if (options.earlyExit) { + options.earlyExit(prev, i - 1, cur); + } + return { + value: undefined, + parent: prev + }; + } + } + if (cur === undefined) { + if (options.earlyExit) { + options.earlyExit(prev, i - 1); + } + } + return { + value: cur, + parent: prev + }; + }, + get: function (parent, reads, options) { + return observeReader.read(parent, observeReader.reads(reads), options || {}).value; + }, + valueReadersMap: {}, + valueReaders: [ + { + name: 'function', + test: function (value) { + return value && canReflect.isFunctionLike(value) && !canReflect.isConstructorLike(value); + }, + read: function (value, i, reads, options, state, prev) { + if (isAt(i, reads)) { + return i === reads.length ? value.bind(prev) : value; + } else if (options.callMethodsOnObservables && canReflect.isObservableLike(prev) && canReflect.isMapLike(prev)) { + return value.apply(prev, options.args || []); + } else if (options.isArgument && i === reads.length) { + return options.proxyMethods !== false ? value.bind(prev) : value; + } + return value.apply(prev, options.args || []); + } + }, + { + name: 'isValueLike', + test: function (value, i, reads, options) { + return value && value[getValueSymbol] && value[isValueLikeSymbol] !== false && (options.foundAt || !isAt(i, reads)); + }, + read: function (value, i, reads, options) { + if (options.readCompute === false && i === reads.length) { + return value; + } + return canReflect.getValue(value); + }, + write: function (base, newVal) { + if (base[setValueSymbol]) { + base[setValueSymbol](newVal); + } else if (base.set) { + base.set(newVal); + } else { + base(newVal); + } + } + } + ], + propertyReadersMap: {}, + propertyReaders: [ + { + name: 'map', + test: function (value) { + if (isPromiseLike(value) || typeof value === 'object' && value && typeof value.then === 'function') { + canReflectPromise(value); + } + return canReflect.isObservableLike(value) && canReflect.isMapLike(value); + }, + read: function (value, prop) { + var res = canReflect.getKeyValue(value, prop.key); + if (res !== undefined) { + return res; + } else { + return value[prop.key]; + } + }, + write: canReflect.setKeyValue + }, + { + name: 'object', + test: function () { + return true; + }, + read: function (value, prop, i, options) { + if (value == null) { + return undefined; + } else { + if (typeof value === 'object') { + if (prop.key in value) { + return value[prop.key]; + } else if (prop.at && specialRead[prop.key] && '@' + prop.key in value) { + options.foundAt = true; + return value['@' + prop.key]; + } + } else { + return value[prop.key]; + } + } + }, + write: function (base, prop, newVal) { + base[prop] = newVal; + } + } + ], + reads: function (keyArg) { + var key = '' + keyArg; + var keys = []; + var last = 0; + var at = false; + if (key.charAt(0) === '@') { + last = 1; + at = true; + } + var keyToAdd = ''; + for (var i = last; i < key.length; i++) { + var character = key.charAt(i); + if (character === '.' || character === '@') { + if (key.charAt(i - 1) !== '\\') { + keys.push({ + key: keyToAdd, + at: at + }); + at = character === '@'; + keyToAdd = ''; + } else { + keyToAdd = keyToAdd.substr(0, keyToAdd.length - 1) + '.'; + } + } else { + keyToAdd += character; + } + } + keys.push({ + key: keyToAdd, + at: at + }); + return keys; + }, + write: function (parent, key, value, options) { + var keys = typeof key === 'string' ? observeReader.reads(key) : key; + var last; + options = options || {}; + if (keys.length > 1) { + last = keys.pop(); + parent = observeReader.read(parent, keys, options).value; + keys.push(last); + } else { + last = keys[0]; + } + if (observeReader.valueReadersMap.isValueLike.test(parent[last.key], keys.length - 1, keys, options)) { + observeReader.valueReadersMap.isValueLike.write(parent[last.key], value, options); + } else { + if (observeReader.valueReadersMap.isValueLike.test(parent, keys.length - 1, keys, options)) { + parent = parent[getValueSymbol](); + } + if (observeReader.propertyReadersMap.map.test(parent)) { + observeReader.propertyReadersMap.map.write(parent, last.key, value, options); + } else if (observeReader.propertyReadersMap.object.test(parent)) { + observeReader.propertyReadersMap.object.write(parent, last.key, value, options); + if (options.observation) { + options.observation.update(); + } + } + } + } + }; + each(observeReader.propertyReaders, function (reader) { + observeReader.propertyReadersMap[reader.name] = reader; + }); + each(observeReader.valueReaders, function (reader) { + observeReader.valueReadersMap[reader.name] = reader; + }); + observeReader.set = observeReader.write; + module.exports = observeReader; +}); +/*can-compute@3.3.3#proto-compute*/ +define('can-compute/proto-compute', function (require, exports, module) { + var Observation = require('can-observation'); + var canEvent = require('can-event'); + var eventLifecycle = require('can-event/lifecycle/lifecycle'); + require('can-event/batch/batch'); + var observeReader = require('can-stache-key'); + var getObject = require('can-util/js/get/get'); + var CID = require('can-cid'); + var assign = require('can-util/js/assign/assign'); + var canLog = require('can-util/js/log/log'); + var canReflect = require('can-reflect'); + var canSymbol = require('can-symbol'); + var CIDSet = require('can-util/js/cid-set/cid-set'); + var singleReference = require('can-util/js/single-reference/single-reference'); + var Compute = function (getterSetter, context, eventName, bindOnce) { + CID(this, 'compute'); + var args = []; + for (var i = 0, arglen = arguments.length; i < arglen; i++) { + args[i] = arguments[i]; + } + var contextType = typeof args[1]; + if (typeof args[0] === 'function') { + this._setupGetterSetterFn(args[0], args[1], args[2], args[3]); + } else if (args[1] !== undefined) { + if (contextType === 'string' || contextType === 'number') { + var isListLike = canReflect.isObservableLike(args[0]) && canReflect.isListLike(args[0]); + var isMapLike = canReflect.isObservableLike(args[0]) && canReflect.isMapLike(args[0]); + if (isMapLike || isListLike) { + var map = args[0]; + var propertyName = args[1]; + var mapGetterSetter = function (newValue) { + if (arguments.length) { + observeReader.set(map, propertyName, newValue); + } else { + if (isListLike) { + observeReader.get(map, 'length'); + } + return observeReader.get(map, '' + propertyName); + } + }; + this._setupGetterSetterFn(mapGetterSetter, args[1], args[2], args[3]); + } else { + this._setupProperty(args[0], args[1], args[2]); + } + } else if (contextType === 'function') { + this._setupSetter(args[0], args[1], args[2]); + } else { + if (args[1] && args[1].fn) { + this._setupAsyncCompute(args[0], args[1]); + } else { + this._setupSettings(args[0], args[1]); + } + } + } else { + this._setupSimpleValue(args[0]); + } + this._args = args; + this._primaryDepth = 0; + this.isComputed = true; + }; + var updateOnChange = function (compute, newValue, oldValue, batchNum) { + var valueChanged = newValue !== oldValue && !(newValue !== newValue && oldValue !== oldValue); + if (valueChanged) { + canEvent.dispatch.call(compute, { + type: 'change', + batchNum: batchNum + }, [ + newValue, + oldValue + ]); + } + }; + var setupComputeHandlers = function (compute, func, context) { + var observation = new Observation(func, context, compute); + compute.observation = observation; + return { + _on: function () { + observation.start(); + compute.value = observation.value; + }, + _off: function () { + observation.stop(); + }, + getDepth: function () { + return observation.getDepth(); + } + }; + }; + assign(Compute.prototype, { + setPrimaryDepth: function (depth) { + this._primaryDepth = depth; + }, + _setupGetterSetterFn: function (getterSetter, context, eventName) { + this._set = context ? getterSetter.bind(context) : getterSetter; + this._get = context ? getterSetter.bind(context) : getterSetter; + this._canObserve = eventName === false ? false : true; + var handlers = setupComputeHandlers(this, getterSetter, context || this); + assign(this, handlers); + }, + _setupProperty: function (target, propertyName, eventName) { + var self = this, handler; + handler = function () { + self.updater(self._get(), self.value); + }; + this._get = function () { + return getObject(target, propertyName); + }; + this._set = function (value) { + var properties = propertyName.split('.'), leafPropertyName = properties.pop(); + if (properties.length) { + var targetProperty = getObject(target, properties.join('.')); + targetProperty[leafPropertyName] = value; + } else { + target[propertyName] = value; + } + }; + this._on = function (update) { + canEvent.on.call(target, eventName || propertyName, handler); + this.value = this._get(); + }; + this._off = function () { + return canEvent.off.call(target, eventName || propertyName, handler); + }; + }, + _setupSetter: function (initialValue, setter, eventName) { + this.value = initialValue; + this._set = setter; + assign(this, eventName); + }, + _setupSettings: function (initialValue, settings) { + this.value = initialValue; + this._set = settings.set || this._set; + this._get = settings.get || this._get; + if (!settings.__selfUpdater) { + var self = this, oldUpdater = this.updater; + this.updater = function () { + oldUpdater.call(self, self._get(), self.value); + }; + } + this._on = settings.on ? settings.on : this._on; + this._off = settings.off ? settings.off : this._off; + }, + _setupAsyncCompute: function (initialValue, settings) { + var self = this; + var getter = settings.fn; + var bindings; + this.value = initialValue; + this._setUpdates = true; + this.lastSetValue = new Compute(initialValue); + this._set = function (newVal) { + if (newVal === self.lastSetValue.get()) { + return this.value; + } + return self.lastSetValue.set(newVal); + }; + this._get = function () { + return getter.call(settings.context, self.lastSetValue.get()); + }; + if (getter.length === 0) { + bindings = setupComputeHandlers(this, getter, settings.context); + } else if (getter.length === 1) { + bindings = setupComputeHandlers(this, function () { + return getter.call(settings.context, self.lastSetValue.get()); + }, settings); + } else { + var oldUpdater = this.updater, resolve = Observation.ignore(function (newVal) { + oldUpdater.call(self, newVal, self.value); + }); + this.updater = function (newVal) { + oldUpdater.call(self, newVal, self.value); + }; + bindings = setupComputeHandlers(this, function () { + var res = getter.call(settings.context, self.lastSetValue.get(), resolve); + return res !== undefined ? res : this.value; + }, this); + } + assign(this, bindings); + }, + _setupSimpleValue: function (initialValue) { + this.value = initialValue; + }, + _eventSetup: Observation.ignore(function () { + this.bound = true; + this._on(this.updater); + }), + _eventTeardown: function () { + this._off(this.updater); + this.bound = false; + }, + addEventListener: eventLifecycle.addAndSetup, + removeEventListener: eventLifecycle.removeAndTeardown, + clone: function (context) { + if (context && typeof this._args[0] === 'function') { + this._args[1] = context; + } else if (context) { + this._args[2] = context; + } + return new Compute(this._args[0], this._args[1], this._args[2], this._args[3]); + }, + _on: function () { + }, + _off: function () { + }, + get: function () { + var recordingObservation = Observation.isRecording(); + if (recordingObservation && this._canObserve !== false) { + Observation.add(this, 'change'); + if (!this.bound) { + Compute.temporarilyBind(this); + } + } + if (this.bound) { + if (this.observation) { + return this.observation.get(); + } else { + return this.value; + } + } else { + return this._get(); + } + }, + _get: function () { + return this.value; + }, + set: function (newVal) { + var old = this.value; + var setVal = this._set(newVal, old); + if (this._setUpdates) { + return this.value; + } + if (this.hasDependencies) { + return this._get(); + } + this.updater(setVal === undefined ? this._get() : setVal, old); + return this.value; + }, + _set: function (newVal) { + return this.value = newVal; + }, + updater: function (newVal, oldVal, batchNum) { + this.value = newVal; + if (this.observation) { + this.observation.value = newVal; + } + updateOnChange(this, newVal, oldVal, batchNum); + }, + toFunction: function () { + return this._computeFn.bind(this); + }, + _computeFn: function (newVal) { + if (arguments.length) { + return this.set(newVal); + } + return this.get(); + } + }); + var hasDependencies = function () { + return this.observation && this.observation.hasDependencies(); + }; + Object.defineProperty(Compute.prototype, 'hasDependencies', { get: hasDependencies }); + canReflect.set(Compute.prototype, canSymbol.for('can.valueHasDependencies'), hasDependencies); + Compute.prototype.on = Compute.prototype.bind = Compute.prototype.addEventListener; + Compute.prototype.off = Compute.prototype.unbind = Compute.prototype.removeEventListener; + canReflect.set(Compute.prototype, canSymbol.for('can.onValue'), function (handler) { + var translationHandler = function (ev, newValue) { + handler(newValue); + }; + singleReference.set(handler, this, translationHandler); + this.addEventListener('change', translationHandler); + }); + canReflect.set(Compute.prototype, canSymbol.for('can.offValue'), function (handler) { + this.removeEventListener('change', singleReference.getAndDelete(handler, this)); + }); + canReflect.set(Compute.prototype, canSymbol.for('can.getValue'), Compute.prototype.get); + canReflect.set(Compute.prototype, canSymbol.for('can.setValue'), Compute.prototype.set); + Compute.temporarilyBind = Observation.temporarilyBind; + Compute.async = function (initialValue, asyncComputer, context) { + return new Compute(initialValue, { + fn: asyncComputer, + context: context + }); + }; + Compute.truthy = function (compute) { + return new Compute(function () { + var res = compute.get(); + if (typeof res === 'function') { + res = res.get(); + } + return !!res; + }); + }; + canReflect.set(Compute.prototype, canSymbol.for('can.setValue'), Compute.prototype.set); + canReflect.set(Compute.prototype, canSymbol.for('can.isValueLike'), true); + canReflect.set(Compute.prototype, canSymbol.for('can.isMapLike'), false); + canReflect.set(Compute.prototype, canSymbol.for('can.isListLike'), false); + canReflect.set(Compute.prototype, canSymbol.for('can.valueHasDependencies'), function () { + return !!this.observation; + }); + canReflect.set(Compute.prototype, canSymbol.for('can.getValueDependencies'), function () { + var ret; + if (this.observation) { + ret = { valueDependencies: new CIDSet() }; + ret.valueDependencies.add(this.observation); + } + return ret; + }); + module.exports = exports = Compute; +}); +/*can-compute@3.3.3#can-compute*/ +define('can-compute', function (require, exports, module) { + require('can-event'); + require('can-event/batch/batch'); + var Compute = require('can-compute/proto-compute'); + var CID = require('can-cid'); + var namespace = require('can-namespace'); + var singleReference = require('can-util/js/single-reference/single-reference'); + var canReflect = require('can-reflect/reflections/get-set/get-set'); + var canSymbol = require('can-symbol'); + var canOnValueSymbol = canSymbol.for('can.onValue'), canOffValueSymbol = canSymbol.for('can.offValue'), canGetValue = canSymbol.for('can.getValue'), canSetValue = canSymbol.for('can.setValue'), isValueLike = canSymbol.for('can.isValueLike'), isMapLike = canSymbol.for('can.isMapLike'), isListLike = canSymbol.for('can.isListLike'), isFunctionLike = canSymbol.for('can.isFunctionLike'), canValueHasDependencies = canSymbol.for('can.valueHasDependencies'), canGetValueDependencies = canSymbol.for('can.getValueDependencies'); + var addEventListener = function (ev, handler) { + var compute = this; + var translationHandler; + if (handler) { + translationHandler = function () { + handler.apply(compute, arguments); + }; + singleReference.set(handler, this, translationHandler); + } + return compute.computeInstance.addEventListener(ev, translationHandler); + }; + var removeEventListener = function (ev, handler) { + return this.computeInstance.removeEventListener(ev, handler && singleReference.getAndDelete(handler, this)); + }; + var onValue = function (handler) { + return this.computeInstance[canOnValueSymbol](handler); + }, offValue = function (handler) { + return this.computeInstance[canOffValueSymbol](handler); + }, getValue = function () { + return this.computeInstance.get(); + }, setValue = function (value) { + return this.computeInstance.set(value); + }, hasDependencies = function () { + return this.computeInstance.hasDependencies; + }, getDependencies = function () { + return this.computeInstance[canGetValueDependencies](); + }; + var COMPUTE = function (getterSetter, context, eventName, bindOnce) { + function compute(val) { + if (arguments.length) { + return compute.computeInstance.set(val); + } + return compute.computeInstance.get(); + } + var cid = CID(compute, 'compute'); + compute.computeInstance = new Compute(getterSetter, context, eventName, bindOnce); + compute.handlerKey = '__handler' + cid; + compute.on = compute.bind = compute.addEventListener = addEventListener; + compute.off = compute.unbind = compute.removeEventListener = removeEventListener; + compute.isComputed = compute.computeInstance.isComputed; + compute.clone = function (ctx) { + if (typeof getterSetter === 'function') { + context = ctx; + } + return COMPUTE(getterSetter, context, ctx, bindOnce); + }; + canReflect.set(compute, canOnValueSymbol, onValue); + canReflect.set(compute, canOffValueSymbol, offValue); + canReflect.set(compute, canGetValue, getValue); + canReflect.set(compute, canSetValue, setValue); + canReflect.set(compute, isValueLike, true); + canReflect.set(compute, isMapLike, false); + canReflect.set(compute, isListLike, false); + canReflect.set(compute, isFunctionLike, false); + canReflect.set(compute, canValueHasDependencies, hasDependencies); + canReflect.set(compute, canGetValueDependencies, getDependencies); + return compute; + }; + COMPUTE.truthy = function (compute) { + return COMPUTE(function () { + var res = compute(); + return !!res; + }); + }; + COMPUTE.async = function (initialValue, asyncComputer, context) { + return COMPUTE(initialValue, { + fn: asyncComputer, + context: context + }); + }; + COMPUTE.temporarilyBind = Compute.temporarilyBind; + module.exports = namespace.compute = COMPUTE; +}); +/*can-map@3.3.3#can-map*/ +define('can-map', function (require, exports, module) { + var bubble = require('can-map/bubble'); + var mapHelpers = require('can-map/map-helpers'); + var canEvent = require('can-event'); + var canBatch = require('can-event/batch/batch'); + var eventLifecycle = require('can-event/lifecycle/lifecycle'); + var Construct = require('can-construct'); + var Observation = require('can-observation'); + var ObserveReader = require('can-stache-key'); + var canCompute = require('can-compute'); + var singleReference = require('can-util/js/single-reference/single-reference'); + var namespace = require('can-namespace'); + var dev = require('can-util/js/dev/dev'); + var CID = require('can-cid'); + var deepAssign = require('can-util/js/deep-assign/deep-assign'); + var isFunction = require('can-util/js/is-function/is-function'); + var assign = require('can-util/js/assign/assign'); + var types = require('can-types'); + var canReflect = require('can-reflect'); + var canSymbol = require('can-symbol'); + var CIDSet = require('can-util/js/cid-set/cid-set'); + var CIDMap = require('can-util/js/cid-map/cid-map'); + var unobservable = { 'constructor': true }; + var hasOwnProperty = {}.hasOwnProperty; + var Map = Construct.extend({ + setup: function (baseMap) { + Construct.setup.apply(this, arguments); + this._computedPropertyNames = []; + if (Map) { + if (!this.defaults) { + this.defaults = {}; + } + for (var prop in this.prototype) { + if (prop !== 'define' && prop !== 'constructor' && (typeof this.prototype[prop] !== 'function' || this.prototype[prop].prototype instanceof Construct)) { + this.defaults[prop] = this.prototype[prop]; + } else if (this.prototype[prop].isComputed) { + this._computedPropertyNames.push(prop); + } + } + if (mapHelpers.define) { + mapHelpers.define(this, baseMap.prototype.define); + } + } + }, + shortName: 'Map', + _bubbleRule: function (eventName) { + return eventName === 'change' || eventName.indexOf('.') >= 0 ? ['change'] : []; + }, + addEventListener: eventLifecycle.addAndSetup, + removeEventListener: eventLifecycle.removeAndTeardown, + keys: function (map) { + Observation.add(map, '__keys'); + return canReflect.getOwnEnumerableKeys(map._data); + } + }, { + setup: function (obj) { + if (canReflect.isObservableLike(obj) && typeof obj.serialize === 'function') { + obj = obj.serialize(); + } + this._data = Object.create(null); + CID(this, '.map'); + this._setupComputedProperties(); + var teardownMapping = obj && mapHelpers.addToMap(obj, this); + var defaultValues = this._setupDefaults(obj); + var data = assign(deepAssign(true, {}, defaultValues), obj); + this.attr(data); + if (teardownMapping) { + teardownMapping(); + } + }, + _setupComputedProperties: function () { + this._computedAttrs = Object.create(null); + var computes = this.constructor._computedPropertyNames; + for (var i = 0, len = computes.length; i < len; i++) { + var attrName = computes[i]; + mapHelpers.addComputedAttr(this, attrName, this[attrName].clone(this)); + } + }, + _setupDefaults: function () { + return this.constructor.defaults || {}; + }, + attr: function (attr, val) { + var type = typeof attr; + if (attr === undefined) { + return this._getAttrs(); + } else if (type !== 'string' && type !== 'number') { + return this._setAttrs(attr, val); + } else if (arguments.length === 1) { + return this._get(attr + ''); + } else { + this._set(attr + '', val); + return this; + } + }, + _get: function (attr) { + var dotIndex = attr.indexOf('.'); + if (dotIndex >= 0) { + var value = this.___get(attr); + if (value !== undefined) { + Observation.add(this, attr); + return value; + } + var first = attr.substr(0, dotIndex), second = attr.substr(dotIndex + 1); + var current = this.__get(first); + return current && canReflect.getKeyValue(current, second); + } else { + return this.__get(attr); + } + }, + __get: function (attr) { + if (!unobservable[attr] && !this._computedAttrs[attr]) { + Observation.add(this, attr); + } + return this.___get(attr); + }, + ___get: function (attr) { + if (attr !== undefined) { + var computedAttr = this._computedAttrs[attr]; + if (computedAttr && computedAttr.compute) { + return computedAttr.compute(); + } else { + return hasOwnProperty.call(this._data, attr) ? this._data[attr] : undefined; + } + } else { + return this._data; + } + }, + _set: function (attr, value, keepKey) { + var dotIndex = attr.indexOf('.'), current; + if (dotIndex >= 0 && !keepKey) { + var first = attr.substr(0, dotIndex), second = attr.substr(dotIndex + 1); + current = this.__inSetup ? undefined : this.___get(first); + if (canReflect.isMapLike(current)) { + canReflect.setKeyValue(current, second, value); + } else { + current = this.__inSetup ? undefined : this.___get(attr); + if (this.__convert) { + value = this.__convert(attr, value); + } + this.__set(attr, this.__type(value, attr), current); + } + } else { + current = this.__inSetup ? undefined : this.___get(attr); + if (this.__convert) { + value = this.__convert(attr, value); + } + this.__set(attr, this.__type(value, attr), current); + } + }, + __type: function (value, prop) { + if (typeof value === 'object' && !canReflect.isObservableLike(value) && mapHelpers.canMakeObserve(value) && !canReflect.isListLike(value)) { + var cached = mapHelpers.getMapFromObject(value); + if (cached) { + return cached; + } + var MapConstructor = this.constructor.Map || Map; + return new MapConstructor(value); + } + return value; + }, + __set: function (prop, value, current) { + if (value !== current) { + var computedAttr = this._computedAttrs[prop]; + var changeType = computedAttr || current !== undefined || hasOwnProperty.call(this.___get(), prop) ? 'set' : 'add'; + this.___set(prop, typeof value === 'object' ? bubble.set(this, prop, value, current) : value); + if (!computedAttr || !computedAttr.count) { + this._triggerChange(prop, changeType, value, current); + } + if (typeof current === 'object') { + bubble.teardownFromParent(this, current); + } + } + }, + ___set: function (prop, val) { + var computedAttr = this._computedAttrs[prop]; + if (computedAttr) { + computedAttr.compute(val); + } else { + this._data[prop] = val; + } + if (typeof this.constructor.prototype[prop] !== 'function' && !computedAttr) { + this[prop] = val; + } + }, + removeAttr: function (attr) { + return this._remove(attr); + }, + _remove: function (attr) { + var parts = mapHelpers.attrParts(attr), prop = parts.shift(), current = this.___get(prop); + if (parts.length && current) { + return canReflect.deleteKeyValue(current, parts.join('.')); + } else { + if (typeof attr === 'string' && !!~attr.indexOf('.')) { + prop = attr; + } + this.__remove(prop, current); + return current; + } + }, + __remove: function (prop, current) { + if (prop in this._data) { + this.___remove(prop); + this._triggerChange(prop, 'remove', undefined, current); + } + }, + ___remove: function (prop) { + delete this._data[prop]; + if (!(prop in this.constructor.prototype)) { + delete this[prop]; + } + }, + ___serialize: function (name, val) { + return canReflect.serialize(val, CIDMap); + }, + _getAttrs: function () { + return canReflect.unwrap(this, CIDMap); + }, + _setAttrs: function (props, remove) { + if (remove === true) { + this[canSymbol.for('can.updateDeep')](props); + } else { + this[canSymbol.for('can.assignDeep')](props); + } + return this; + }, + serialize: function () { + return canReflect.serialize(this, CIDMap); + }, + _triggerChange: function (attr, how, newVal, oldVal, batchNum) { + if (bubble.isBubbling(this, 'change')) { + canEvent.dispatch.call(this, { + type: 'change', + target: this, + batchNum: batchNum + }, [ + attr, + how, + newVal, + oldVal + ]); + } + canEvent.dispatch.call(this, { + type: attr, + target: this, + batchNum: batchNum + }, [ + newVal, + oldVal + ]); + if (how === 'remove' || how === 'add') { + canEvent.dispatch.call(this, { + type: '__keys', + target: this, + batchNum: batchNum + }); + } + }, + _eventSetup: function () { + }, + _eventTeardown: function () { + }, + one: canEvent.one, + addEventListener: function (eventName, handler) { + var computedBinding = this._computedAttrs && this._computedAttrs[eventName]; + if (computedBinding && computedBinding.compute) { + if (!computedBinding.count) { + computedBinding.count = 1; + computedBinding.compute.addEventListener('change', function (ev, newVal, oldVal) { + computedBinding.handler(newVal, oldVal); + }); + } else { + computedBinding.count++; + } + } + bubble.bind(this, eventName); + return eventLifecycle.addAndSetup.apply(this, arguments); + }, + removeEventListener: function (eventName, handler) { + var computedBinding = this._computedAttrs && this._computedAttrs[eventName]; + if (computedBinding) { + if (computedBinding.count === 1) { + computedBinding.count = 0; + canReflect.offValue(computedBinding.compute, computedBinding.handler); + } else { + computedBinding.count--; + } + } + bubble.unbind(this, eventName); + return eventLifecycle.removeAndTeardown.apply(this, arguments); + }, + compute: function (prop) { + if (isFunction(this.constructor.prototype[prop])) { + return canCompute(this[prop], this); + } else { + var reads = ObserveReader.reads(prop); + var last = reads.length - 1; + return canCompute(function (newVal) { + if (arguments.length) { + ObserveReader.write(this, reads[last].key, newVal, {}); + } else { + return ObserveReader.get(this, prop); + } + }, this); + } + }, + each: function (callback, context) { + var key, item; + var keys = Map.keys(this); + for (var i = 0, len = keys.length; i < len; i++) { + key = keys[i]; + item = this.attr(key); + if (callback.call(context || item, item, key, this) === false) { + break; + } + } + return this; + }, + _each: function (callback) { + var data = this.___get(); + for (var prop in data) { + if (hasOwnProperty.call(data, prop)) { + callback(data[prop], prop); + } + } + }, + dispatch: canEvent.dispatch + }); + Map.prototype.on = Map.prototype.bind = Map.prototype.addEventListener; + Map.prototype.off = Map.prototype.unbind = Map.prototype.removeEventListener; + Map.on = Map.bind = Map.addEventListener; + Map.off = Map.unbind = Map.removeEventListener; + canReflect.assignSymbols(Map.prototype, { + 'can.isMapLike': true, + 'can.isListLike': false, + 'can.isValueLike': false, + 'can.getKeyValue': Map.prototype._get, + 'can.setKeyValue': Map.prototype._set, + 'can.deleteKeyValue': Map.prototype._remove, + 'can.getOwnEnumerableKeys': function () { + Observation.add(this, '__keys'); + return Object.keys(this._data); + }, + 'can.assignDeep': function (source) { + canBatch.start(); + canReflect.assignDeepMap(this, mapHelpers.removeSpecialKeys(canReflect.assignMap({}, source))); + canBatch.stop(); + }, + 'can.updateDeep': function (source) { + canBatch.start(); + canReflect.updateDeepMap(this, mapHelpers.removeSpecialKeys(canReflect.assignMap({}, source))); + canBatch.stop(); + }, + 'can.unwrap': mapHelpers.reflectUnwrap, + 'can.serialize': mapHelpers.reflectSerialize, + 'can.onKeyValue': function (key, handler) { + var translationHandler = function (ev, newValue, oldValue) { + handler.call(this, newValue, oldValue); + }; + singleReference.set(handler, this, translationHandler, key); + this.addEventListener(key, translationHandler); + }, + 'can.offKeyValue': function (key, handler) { + this.removeEventListener(key, singleReference.getAndDelete(handler, this, key)); + }, + 'can.keyHasDependencies': function (key) { + return !!(this._computedAttrs && this._computedAttrs[key] && this._computedAttrs[key].compute); + }, + 'can.getKeyDependencies': function (key) { + var ret; + if (this._computedAttrs && this._computedAttrs[key] && this._computedAttrs[key].compute) { + ret = {}; + ret.valueDependencies = new CIDSet(); + ret.valueDependencies.add(this._computedAttrs[key].compute); + } + return ret; + } + }); + if (!types.DefaultMap) { + types.DefaultMap = Map; + } + module.exports = namespace.Map = Map; +}); +/*can-list@3.2.0#can-list*/ +define('can-list', function (require, exports, module) { + require('can-event'); + var namespace = require('can-namespace'); + var Map = require('can-map'); + var bubble = require('can-map/bubble'); + var mapHelpers = require('can-map/map-helpers'); + var canBatch = require('can-event/batch/batch'); + var canEvent = require('can-event'); + var Observation = require('can-observation'); + var CID = require('can-cid'); + var isPromise = require('can-util/js/is-promise/is-promise'); + var makeArray = require('can-util/js/make-array/make-array'); + var assign = require('can-util/js/assign/assign'); + var types = require('can-types'); + var each = require('can-util/js/each/each'); + var canReflect = require('can-reflect'); + var canSymbol = require('can-symbol'); + var CIDMap = require('can-util/js/cid-map/cid-map'); + var splice = [].splice, spliceRemovesProps = function () { + var obj = { + 0: 'a', + length: 1 + }; + splice.call(obj, 0, 1); + return !obj[0]; + }(); + var serializeNonTypes = function (MapType, arg, args) { + if (arg && arg.serialize && !(arg instanceof MapType)) { + args.push(new MapType(arg.serialize())); + } else { + args.push(arg); + } + }; + var List = Map.extend({ Map: Map }, { + setup: function (instances, options) { + this.length = 0; + CID(this, '.map'); + this._setupComputedProperties(); + instances = instances || []; + var teardownMapping; + if (isPromise(instances)) { + this.replace(instances); + } else { + teardownMapping = instances.length && mapHelpers.addToMap(instances, this); + this.push.apply(this, makeArray(instances || [])); + } + if (teardownMapping) { + teardownMapping(); + } + assign(this, options); + }, + _triggerChange: function (attr, how, newVal, oldVal) { + Map.prototype._triggerChange.apply(this, arguments); + var index = +attr; + if (!~('' + attr).indexOf('.') && !isNaN(index)) { + if (how === 'add') { + canEvent.dispatch.call(this, how, [ + newVal, + index + ]); + canEvent.dispatch.call(this, 'length', [this.length]); + } else if (how === 'remove') { + canEvent.dispatch.call(this, how, [ + oldVal, + index + ]); + canEvent.dispatch.call(this, 'length', [this.length]); + } else { + canEvent.dispatch.call(this, how, [ + newVal, + index + ]); + } + } + }, + ___get: function (attr) { + if (attr) { + var computedAttr = this._computedAttrs[attr]; + if (computedAttr && computedAttr.compute) { + return canReflect.getValue(computedAttr.compute); + } + if (this[attr] && this[attr].isComputed && typeof this.constructor.prototype[attr] === 'function') { + return canReflect.getValue(this[attr]); + } else { + return this[attr]; + } + } else { + return this; + } + }, + __set: function (prop, value, current) { + prop = isNaN(+prop) || prop % 1 ? prop : +prop; + if (typeof prop === 'number') { + if (prop > this.length - 1) { + var newArr = new Array(prop + 1 - this.length); + newArr[newArr.length - 1] = value; + this.push.apply(this, newArr); + return newArr; + } else { + this.splice(prop, 1, value); + return this; + } + } + return Map.prototype.__set.call(this, '' + prop, value, current); + }, + ___set: function (attr, val) { + this[attr] = val; + if (+attr >= this.length) { + this.length = +attr + 1; + } + }, + __remove: function (prop, current) { + if (isNaN(+prop)) { + delete this[prop]; + this._triggerChange(prop, 'remove', undefined, current); + } else { + this.splice(prop, 1); + } + }, + _each: function (callback) { + var data = this.___get(); + for (var i = 0; i < data.length; i++) { + callback(data[i], i); + } + }, + serialize: function () { + return canReflect.serialize(this, CIDMap); + }, + splice: function (index, howMany) { + var args = makeArray(arguments), added = [], i, len, listIndex, allSame = args.length > 2; + index = index || 0; + for (i = 0, len = args.length - 2; i < len; i++) { + listIndex = i + 2; + args[listIndex] = this.__type(args[listIndex], listIndex); + added.push(args[listIndex]); + if (this[i + index] !== args[listIndex]) { + allSame = false; + } + } + if (allSame && this.length <= added.length) { + return added; + } + if (howMany === undefined) { + howMany = args[1] = this.length - index; + } + var removed = splice.apply(this, args); + if (!spliceRemovesProps) { + for (i = this.length; i < removed.length + this.length; i++) { + delete this[i]; + } + } + canBatch.start(); + if (howMany > 0) { + bubble.removeMany(this, removed); + this._triggerChange('' + index, 'remove', undefined, removed); + } + if (args.length > 2) { + bubble.addMany(this, added); + this._triggerChange('' + index, 'add', added, removed); + } + canBatch.stop(); + return removed; + } + }), getArgs = function (args) { + return args[0] && Array.isArray(args[0]) ? args[0] : makeArray(args); + }; + each({ + push: 'length', + unshift: 0 + }, function (where, name) { + var orig = [][name]; + List.prototype[name] = function () { + var args = [], len = where ? this.length : 0, i = arguments.length, res, val; + while (i--) { + val = arguments[i]; + args[i] = bubble.set(this, i, this.__type(val, i)); + } + res = orig.apply(this, args); + if (!this.comparator || args.length) { + this._triggerChange('' + len, 'add', args, undefined); + } + return res; + }; + }); + each({ + pop: 'length', + shift: 0 + }, function (where, name) { + List.prototype[name] = function () { + if (!this.length) { + return undefined; + } + var args = getArgs(arguments), len = where && this.length ? this.length - 1 : 0; + var res = [][name].apply(this, args); + this._triggerChange('' + len, 'remove', undefined, [res]); + if (res && res.removeEventListener) { + bubble.remove(this, res); + } + return res; + }; + }); + assign(List.prototype, { + indexOf: function (item, fromIndex) { + Observation.add(this, 'length'); + for (var i = fromIndex || 0, len = this.length; i < len; i++) { + if (this.attr(i) === item) { + return i; + } + } + return -1; + }, + join: function () { + Observation.add(this, 'length'); + return [].join.apply(this, arguments); + }, + reverse: function () { + var list = [].reverse.call(makeArray(this)); + return this.replace(list); + }, + slice: function () { + Observation.add(this, 'length'); + var temp = Array.prototype.slice.apply(this, arguments); + return new this.constructor(temp); + }, + concat: function () { + var args = [], MapType = this.constructor.Map; + each(arguments, function (arg) { + if (canReflect.isObservableLike(arg) && canReflect.isListLike(arg) || Array.isArray(arg)) { + var arr = canReflect.isObservableLike(arg) && canReflect.isListLike(arg) ? makeArray(arg) : arg; + each(arr, function (innerArg) { + serializeNonTypes(MapType, innerArg, args); + }); + } else { + serializeNonTypes(MapType, arg, args); + } + }); + return new this.constructor(Array.prototype.concat.apply(makeArray(this), args)); + }, + forEach: function (cb, thisarg) { + var item; + for (var i = 0, len = this.attr('length'); i < len; i++) { + item = this.attr(i); + if (item !== undefined && cb.call(thisarg || item, item, i, this) === false) { + break; + } + } + return this; + }, + replace: function (newList) { + if (isPromise(newList)) { + if (this._promise) { + this._promise.__isCurrentPromise = false; + } + var promise = this._promise = newList; + promise.__isCurrentPromise = true; + var self = this; + newList.then(function (newList) { + if (promise.__isCurrentPromise) { + self.replace(newList); + } + }); + } else { + this.splice.apply(this, [ + 0, + this.length + ].concat(makeArray(newList || []))); + } + return this; + }, + filter: function (callback, thisArg) { + var filteredList = new this.constructor(), self = this, filtered; + this.each(function (item, index, list) { + filtered = callback.call(thisArg || self, item, index, self); + if (filtered) { + filteredList.push(item); + } + }); + return filteredList; + }, + map: function (callback, thisArg) { + var filteredList = new List(), self = this; + this.each(function (item, index, list) { + var mapped = callback.call(thisArg || self, item, index, self); + filteredList.push(mapped); + }); + return filteredList; + } + }); + var oldType = Map.prototype.__type; + Map.prototype.__type = function (value, prop) { + if (typeof value === 'object' && Array.isArray(value)) { + var cached = mapHelpers.getMapFromObject(value); + if (cached) { + return cached; + } + return new List(value); + } + return oldType.apply(this, arguments); + }; + var oldSetup = Map.setup; + Map.setup = function () { + oldSetup.apply(this, arguments); + if (!(this.prototype instanceof List)) { + this.List = Map.List.extend({ Map: this }, {}); + } + }; + if (!types.DefaultList) { + types.DefaultList = List; + } + canReflect.assignSymbols(List.prototype, { + 'can.isMoreListLikeThanMapLike': true, + 'can.isListLike': true, + 'can.getKeyValue': List.prototype._get, + 'can.setKeyValue': List.prototype._set, + 'can.deleteKeyValue': List.prototype._remove, + 'can.getOwnEnumerableKeys': function () { + return Object.keys(this._data || {}).concat(this.map(function (val, index) { + return index; + })); + }, + 'can.assignDeep': function (source) { + canBatch.start(); + canReflect.assignDeepList(this, source); + canBatch.stop(); + }, + 'can.updateDeep': function (source) { + canBatch.start(); + canReflect.updateDeepList(this, source); + canBatch.stop(); + }, + 'can.unwrap': mapHelpers.reflectUnwrap, + 'can.serialize': mapHelpers.reflectSerialize, + 'can.onKeysAdded': function (handler) { + this[canSymbol.for('can.onKeyValue')]('add', handler); + }, + 'can.onKeysRemoved': function (handler) { + this[canSymbol.for('can.onKeyValue')]('remove', handler); + }, + 'can.splice': function (index, deleteCount, insert) { + this.splice.apply(this, [ + index, + deleteCount + ].concat(insert)); + } + }); + List.prototype.each = List.prototype.forEach; + Map.List = List; + module.exports = namespace.List = List; +}); +/*[global-shim-end]*/ +(function(){ // jshint ignore:line + window._define = window.define; + window.define = window.define.orig; +} +)(); \ No newline at end of file