diff --git a/dist/global/can-define.js b/dist/global/can-define.js new file mode 100644 index 0000000..7bce43a --- /dev/null +++ b/dist/global/can-define.js @@ -0,0 +1,3472 @@ +/*[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.2.2#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-util@3.2.2#js/global/global*/ +define('can-util/js/global/global', function (require, exports, module) { + (function (global) { + 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.2.2#dom/document/document*/ +define('can-util/dom/document/document', function (require, exports, module) { + (function (global) { + 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.2.2#dom/events/events*/ +define('can-util/dom/events/events', function (require, exports, module) { + var assign = require('can-util/js/assign/assign'); + var _document = require('can-util/dom/document/document'); + 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 doc = _document(); + var ev = doc.createEvent('HTMLEvents'); + var isString = typeof event === 'string'; + ev.initEvent(isString ? event : event.type, bubbles === undefined ? true : bubbles, false); + if (!isString) { + assign(ev, event); + } + ev.args = args; + return this.dispatchEvent(ev); + } + }; +}); +/*can-namespace@1.0.0#can-namespace*/ +define('can-namespace', function (require, exports, module) { + module.exports = {}; +}); +/*can-cid@1.0.1#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.2.2#js/is-empty-object/is-empty-object*/ +define('can-util/js/is-empty-object/is-empty-object', function (require, exports, module) { + module.exports = function (obj) { + for (var prop in obj) { + return false; + } + return true; + }; +}); +/*can-util@3.2.2#dom/dispatch/dispatch*/ +define('can-util/dom/dispatch/dispatch', function (require, exports, module) { + var domEvents = require('can-util/dom/events/events'); + module.exports = function () { + return domEvents.dispatch.apply(this, arguments); + }; +}); +/*can-util@3.2.2#dom/data/data*/ +define('can-util/dom/data/data', function (require, exports, module) { + 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] || (data[id] = {}); + if (name !== undefined) { + store[name] = value; + } + return store; + }; + module.exports = { + getCid: function () { + return this[expando]; + }, + cid: function () { + return this[expando] || (this[expando] = ++uuid); + }, + expando: expando, + clean: function (prop) { + var id = this[expando]; + if (data[id] && data[id][prop]) { + delete data[id][prop]; + } + if (isEmptyObject(data[id])) { + delete data[id]; + } + }, + get: function (key) { + var id = this[expando], store = id && data[id]; + return key === undefined ? store || setData(this) : store && store[key]; + }, + set: setData + }; +}); +/*can-util@3.2.2#dom/matches/matches*/ +define('can-util/dom/matches/matches', function (require, exports, module) { + 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.2.2#js/is-array-like/is-array-like*/ +define('can-util/js/is-array-like/is-array-like', function (require, exports, module) { + function isArrayLike(obj) { + var type = typeof obj; + if (type === 'string') { + return true; + } + var length = obj && type !== 'boolean' && typeof obj !== 'number' && 'length' in obj && obj.length; + return typeof arr !== 'function' && (length === 0 || typeof length === 'number' && length > 0 && length - 1 in obj); + } + module.exports = isArrayLike; +}); +/*can-types@1.0.2#can-types*/ +define('can-types', function (require, exports, module) { + var namespace = require('can-namespace'); + var types = { + isMapLike: function () { + return false; + }, + isListLike: function () { + return false; + }, + isPromise: function (obj) { + return obj instanceof Promise || Object.prototype.toString.call(obj) === '[object Promise]'; + }, + isConstructor: function (func) { + if (typeof func !== 'function') { + return false; + } + for (var prop in func.prototype) { + return true; + } + return false; + }, + isCallableForValue: function (obj) { + return typeof obj === 'function' && !types.isConstructor(obj); + }, + isCompute: function (obj) { + return obj && obj.isComputed; + }, + iterator: typeof Symbol === 'function' && Symbol.iterator || '@@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-util@3.2.2#js/is-iterable/is-iterable*/ +define('can-util/js/is-iterable/is-iterable', function (require, exports, module) { + var types = require('can-types'); + module.exports = function (obj) { + return obj && !!obj[types.iterator]; + }; +}); +/*can-util@3.2.2#js/each/each*/ +define('can-util/js/each/each', function (require, exports, module) { + 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 types = require('can-types'); + 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[types.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.2.2#dom/events/delegate/delegate*/ +define('can-util/dom/events/delegate/delegate', function (require, exports, module) { + 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-event@3.0.2#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'); + 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; + } + var handlers = events[eventName]; + if (!handlers) { + return; + } else { + return handlers; + } + } + 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; + } + 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-event@3.0.2#lifecycle/lifecycle*/ +define('can-event/lifecycle/lifecycle', function (require, exports, module) { + var canEvent = require('can-event'); + module.exports = { + addAndSetup: function () { + canEvent.addEventListener.apply(this, arguments); + if (!this.__inSetup) { + if (!this._bindings) { + this._bindings = 1; + if (this._eventSetup) { + this._eventSetup(); + } + } else { + this._bindings++; + } + } + return this; + }, + removeAndTeardown: function (event, handler) { + if (!this.__bindEvents) { + return this; + } + var handlers = this.__bindEvents[event] || []; + var handlerCount = handlers.length; + canEvent.removeEventListener.apply(this, arguments); + if (this._bindings === null) { + this._bindings = 0; + } else { + this._bindings = this._bindings - (handlerCount - handlers.length); + } + if (!this._bindings && this._eventTeardown) { + this._eventTeardown(); + } + return this; + } + }; +}); +/*can-util@3.2.2#js/last/last*/ +define('can-util/js/last/last', function (require, exports, module) { + module.exports = function (arr) { + return arr && arr[arr.length - 1]; + }; +}); +/*can-util@3.2.2#js/log/log*/ +define('can-util/js/log/log', function (require, exports, module) { + 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.2.2#js/dev/dev*/ +define('can-util/js/dev/dev', function (require, exports, module) { + var canLog = require('can-util/js/log/log'); + module.exports = { + warnTimeout: 5000, + logLevel: 0, + warn: function () { + }, + log: function () { + }, + _logger: canLog._logger + }; +}); +/*can-event@3.0.2#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 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, index; + while (queue.index < len) { + index = queue.index++; + tasks[index][0].apply(tasks[index][1], tasks[index][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) { + 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({}); + } + } + }; + canEvent.flush = canBatch.flush; + canEvent.dispatch = canBatch.dispatch; + canBatch.trigger = function () { + console.warn('use canEvent.dispatch instead'); + return canEvent.dispatch.apply(this, arguments); + }; + canTypes.queueTask = canBatch.queue; + module.exports = namespace.batch = canBatch; +}); +/*can-observation@3.0.7#can-observation*/ +define('can-observation', function (require, exports, module) { + require('can-event'); + var canEvent = require('can-event'); + var canBatch = require('can-event/batch/batch'); + var assign = require('can-util/js/assign/assign'); + var namespace = require('can-namespace'); + var remaining = { + updates: 0, + notifications: 0 + }; + function Observation(func, context, compute) { + this.newObserved = {}; + this.oldObserved = null; + this.func = func; + this.context = context; + this.compute = compute.updater ? compute : { updater: compute }; + this.onDependencyChange = this.onDependencyChange.bind(this); + this.childDepths = {}; + this.ignore = 0; + this.needsUpdate = false; + } + var observationStack = []; + assign(Observation.prototype, { + get: function () { + if (this.bound) { + canEvent.flush(); + if (remaining.updates) { + Observation.updateChildrenAndSelf(this); + } + return this.value; + } else { + return this.func.call(this.context); + } + }, + getPrimaryDepth: function () { + return this.compute._primaryDepth || 0; + }, + addEdge: function (objEv) { + objEv.obj.addEventListener(objEv.event, this.onDependencyChange); + if (objEv.obj.observation) { + this.depth = null; + } + }, + removeEdge: function (objEv) { + objEv.obj.removeEventListener(objEv.event, this.onDependencyChange); + if (objEv.obj.observation) { + this.depth = null; + } + }, + dependencyChange: function (ev) { + if (this.bound) { + if (ev.batchNum !== this.batchNum) { + Observation.registerUpdate(this, ev.batchNum); + this.batchNum = ev.batchNum; + } + } + }, + onDependencyChange: function (ev, newVal, oldVal) { + this.dependencyChange(ev, newVal, oldVal); + }, + update: function (batchNum) { + if (this.needsUpdate) { + remaining.updates--; + } + this.needsUpdate = false; + if (this.bound) { + var oldValue = this.value; + this.oldValue = null; + this.start(); + if (oldValue !== this.value) { + this.compute.updater(this.value, oldValue, batchNum); + return true; + } + } + }, + getValueAndBind: function () { + console.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] = null; + } + } + for (name in oldObserved) { + obEv = oldObserved[name]; + if (obEv) { + this.removeEdge(obEv); + } + } + }, + teardown: function () { + console.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) { + return; + } + remaining.updates++; + observation.needsUpdate = true; + var objs = updateUpdateOrder(observation); + objs.push(observation); + }; + var afterCallbacks = []; + Observation.updateAndNotify = function (ev, batchNum) { + currentBatchNum = batchNum; + if (isUpdating) { + return; + } + isUpdating = true; + while (true) { + if (curPrimaryDepth <= maxPrimaryDepth) { + var primary = updateOrder[curPrimaryDepth]; + var lastUpdate = primary && primary.pop(); + if (lastUpdate) { + 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) { + afterCallbacks.push(callback); + } else { + callback(); + } + }); + }; + Observation.updateChildrenAndSelf = function (observation) { + if (observation.needsUpdate) { + return Observation.unregisterAndUpdate(observation); + } + var childHasChanged; + for (var prop in observation.newObserved) { + if (observation.newObserved[prop].obj.observation) { + if (Observation.updateChildrenAndSelf(observation.newObserved[prop].obj.observation)) { + childHasChanged = true; + } + } + } + if (childHasChanged) { + return observation.update(currentBatchNum); + } + }; + Observation.unregisterAndUpdate = function (observation) { + var primaryDepth = observation.getPrimaryDepth(); + var primary = updateOrder[primaryDepth]; + if (primary) { + 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 && !top.ignore) { + var evStr = event + '', name = obj._cid + '|' + evStr; + if (top.traps) { + 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) { + if (top.traps) { + 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]) { + top.newObserved[name] = trap; + } + } + } + } + }; + Observation.ignore = function (fn) { + return function () { + if (observationStack.length) { + 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) { + 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) { + var top = observationStack[observationStack.length - 1]; + return top.traps.length; + } else { + return 0; + } + }; + Observation.isRecording = function () { + var len = observationStack.length; + var last = len && observationStack[len - 1]; + return last && last.ignore === 0 && last; + }; + if (namespace.Observation) { + throw new Error('You can\'t have two versions of can-observation, check your dependencies'); + } else { + module.exports = namespace.Observation = Observation; + } +}); +/*can-observation@3.0.7#reader/reader*/ +define('can-observation/reader/reader', function (require, exports, module) { + var Observation = require('can-observation'); + var assign = require('can-util/js/assign/assign'); + var CID = require('can-cid'); + var types = require('can-types'); + var dev = require('can-util/js/dev/dev'); + var canEvent = require('can-event'); + var each = require('can-util/js/each/each'); + 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 || type !== 'function' && type !== 'object')) { + 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, i, reads, options) { + return types.isCallableForValue(value) && !types.isCompute(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 && types.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: 'compute', + test: function (value, i, reads, options) { + return types.isCompute(value) && !isAt(i, reads); + }, + read: function (value, i, reads, options, state) { + if (options.readCompute === false && i === reads.length) { + return value; + } + return value.get ? value.get() : value(); + }, + write: function (base, newVal) { + if (base.set) { + base.set(newVal); + } else { + base(newVal); + } + } + } + ], + propertyReadersMap: {}, + propertyReaders: [ + { + name: 'map', + test: function () { + return types.isMapLike.apply(this, arguments) || types.isListLike.apply(this, arguments); + }, + read: function (value, prop, index, options, state) { + var res = value.get ? value.get(prop.key) : value.attr(prop.key); + if (res !== undefined) { + return res; + } else { + return value[prop.key]; + } + }, + write: function (base, prop, newVal) { + if (typeof base.set === 'function') { + base.set(prop, newVal); + } else { + base.attr(prop, newVal); + } + } + }, + { + name: 'promise', + test: function (value) { + return types.isPromise(value); + }, + read: function (value, prop, index, options, state) { + var observeData = value.__observeData; + if (!value.__observeData) { + observeData = value.__observeData = { + isPending: true, + state: 'pending', + isResolved: false, + isRejected: false, + value: undefined, + reason: undefined + }; + CID(observeData); + assign(observeData, canEvent); + value.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' + ]); + }); + } + Observation.add(observeData, 'state'); + return prop.key in observeData ? observeData[prop.key] : value[prop.key]; + } + }, + { + name: 'object', + test: function () { + return true; + }, + read: function (value, prop) { + 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) { + return value['@' + prop.key]; + } + } else { + return value[prop.key]; + } + } + }, + write: function (base, prop, newVal) { + base[prop] = newVal; + } + } + ], + reads: function (key) { + 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; + if (keys.length > 1) { + last = keys.pop(); + parent = observeReader.read(parent, keys, options).value; + keys.push(last); + } else { + last = keys[0]; + } + if (observeReader.valueReadersMap.compute.test(parent[last.key], keys.length - 1, keys, options)) { + observeReader.valueReadersMap.compute.write(parent[last.key], value, options); + } else { + if (observeReader.valueReadersMap.compute.test(parent, keys.length - 1, keys, options)) { + parent = parent(); + } + 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); + } + } + } + }; + 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-util@3.2.2#js/is-container/is-container*/ +define('can-util/js/is-container/is-container', function (require, exports, module) { + module.exports = function (current) { + return /^f|^o/.test(typeof current); + }; +}); +/*can-util@3.2.2#js/get/get*/ +define('can-util/js/get/get', function (require, exports, module) { + 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-compute@3.0.5#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-observation/reader/reader'); + var getObject = require('can-util/js/get/get'); + var CID = require('can-cid'); + var assign = require('can-util/js/assign/assign'); + var types = require('can-types'); + var isEmptyObject = require('can-util/js/is-empty-object/is-empty-object'); + 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 = types.isListLike(args[0]); + if (types.isMapLike(args[0]) || 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; + compute.hasDependencies = !isEmptyObject(observation.newObserved); + }, + _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(), targetProperty = getObject(target, properties.join('.')); + targetProperty[leafPropertyName] = 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(); + } + }); + Compute.prototype.on = Compute.prototype.bind = Compute.prototype.addEventListener; + Compute.prototype.off = Compute.prototype.unbind = Compute.prototype.removeEventListener; + var k = function () { + }; + var computes; + var unbindComputes = function () { + for (var i = 0, len = computes.length; i < len; i++) { + computes[i].removeEventListener('change', k); + } + computes = null; + }; + Compute.temporarilyBind = function (compute) { + var computeInstance = compute.computeInstance || compute; + computeInstance.addEventListener('change', k); + if (!computes) { + computes = []; + setTimeout(unbindComputes, 10); + } + computes.push(computeInstance); + }; + 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; + }); + }; + module.exports = exports = Compute; +}); +/*can-compute@3.0.5#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 addEventListener = function (ev, handler) { + var compute = this; + var computeHandler = handler && handler[compute.handlerKey]; + if (handler && !computeHandler) { + computeHandler = handler[compute.handlerKey] = function () { + handler.apply(compute, arguments); + }; + } + return compute.computeInstance.addEventListener(ev, computeHandler); + }; + var removeEventListener = function (ev, handler) { + var compute = this; + var computeHandler = handler && handler[compute.handlerKey]; + if (computeHandler) { + delete handler[compute.handlerKey]; + return compute.computeInstance.removeEventListener(ev, computeHandler); + } + return compute.computeInstance.removeEventListener.apply(compute.computeInstance, arguments); + }; + 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); + }; + return compute; + }; + COMPUTE.truthy = function (compute) { + return COMPUTE(function () { + var res = compute(); + if (typeof res === 'function') { + res = res(); + } + 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-util@3.2.2#js/is-plain-object/is-plain-object*/ +define('can-util/js/is-plain-object/is-plain-object', function (require, exports, module) { + 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)) { + 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.2.2#js/is-array/is-array*/ +define('can-util/js/is-array/is-array', function (require, exports, module) { + module.exports = function (arr) { + return Array.isArray(arr); + }; +}); +/*can-util@3.2.2#js/defaults/defaults*/ +define('can-util/js/defaults/defaults', function (require, exports, module) { + module.exports = function (target) { + var length = arguments.length; + for (var i = 1; i < length; i++) { + for (var prop in arguments[i]) { + if (target[prop] === undefined) { + target[prop] = arguments[i][prop]; + } + } + } + return target; + }; +}); +/*can-define@1.0.15#can-define*/ +define('can-define', function (require, exports, module) { + 'use strict'; + 'format cjs'; + var event = require('can-event'); + var eventLifecycle = require('can-event/lifecycle/lifecycle'); + var canBatch = require('can-event/batch/batch'); + var canEvent = require('can-event'); + var compute = require('can-compute'); + var Observation = require('can-observation'); + var isEmptyObject = require('can-util/js/is-empty-object/is-empty-object'); + var assign = require('can-util/js/assign/assign'); + var dev = require('can-util/js/dev/dev'); + var CID = require('can-cid'); + var isPlainObject = require('can-util/js/is-plain-object/is-plain-object'); + var isArray = require('can-util/js/is-array/is-array'); + var types = require('can-types'); + var each = require('can-util/js/each/each'); + var defaults = require('can-util/js/defaults/defaults'); + var ns = require('can-namespace'); + var eventsProto, define, make, makeDefinition, replaceWith, getDefinitionsAndMethods, isDefineType, getDefinitionOrMethod; + var defineConfigurableAndNotEnumerable = function (obj, prop, value) { + Object.defineProperty(obj, prop, { + configurable: true, + enumerable: false, + writable: true, + value: value + }); + }; + var eachPropertyDescriptor = function (map, cb) { + for (var prop in map) { + if (map.hasOwnProperty(prop)) { + cb(prop, Object.getOwnPropertyDescriptor(map, prop)); + } + } + }; + module.exports = define = ns.define = function (objPrototype, defines, baseDefine) { + var dataInitializers = Object.create(baseDefine ? baseDefine.dataInitializers : null), computedInitializers = Object.create(baseDefine ? baseDefine.computedInitializers : null); + var result = getDefinitionsAndMethods(defines, baseDefine); + result.dataInitializers = dataInitializers; + result.computedInitializers = computedInitializers; + each(result.definitions, function (definition, property) { + define.property(objPrototype, property, definition, dataInitializers, computedInitializers); + }); + replaceWith(objPrototype, '_data', function () { + var map = this; + var data = {}; + for (var prop in dataInitializers) { + replaceWith(data, prop, dataInitializers[prop].bind(map), true); + } + return data; + }); + replaceWith(objPrototype, '_computed', function () { + var map = this; + var data = {}; + for (var prop in computedInitializers) { + replaceWith(data, prop, computedInitializers[prop].bind(map)); + } + return data; + }); + for (var prop in eventsProto) { + Object.defineProperty(objPrototype, prop, { + enumerable: false, + value: eventsProto[prop], + configurable: true, + writable: true + }); + } + Object.defineProperty(objPrototype, '_define', { + enumerable: false, + value: result, + configurable: true, + writable: true + }); + if (!objPrototype[types.iterator]) { + defineConfigurableAndNotEnumerable(objPrototype, types.iterator, function () { + return new define.Iterator(this); + }); + } + return result; + }; + define.extensions = function () { + }; + var onlyType = function (obj) { + for (var prop in obj) { + if (prop !== 'type') { + return false; + } + } + return true; + }; + define.property = function (objPrototype, prop, definition, dataInitializers, computedInitializers) { + var propertyDefinition = define.extensions.apply(this, arguments); + if (propertyDefinition) { + definition = propertyDefinition; + } + var type = definition.type; + if (type && onlyType(definition) && type === define.types['*']) { + Object.defineProperty(objPrototype, prop, { + get: make.get.data(prop), + set: make.set.events(prop, make.get.data(prop), make.set.data(prop), make.eventType.data(prop)), + enumerable: true + }); + return; + } + definition.type = type; + var dataProperty = definition.get ? 'computed' : 'data', reader = make.read[dataProperty](prop), getter = make.get[dataProperty](prop), setter = make.set[dataProperty](prop), getInitialValue; + var typeConvert = function (val) { + return val; + }; + if (definition.Type) { + typeConvert = make.set.Type(prop, definition.Type, typeConvert); + } + if (type) { + typeConvert = make.set.type(prop, type, typeConvert); + } + var eventsSetter = make.set.events(prop, reader, setter, make.eventType[dataProperty](prop)); + if (definition.value !== undefined || definition.Value !== undefined) { + getInitialValue = make.get.defaultValue(prop, definition, typeConvert, eventsSetter); + } + if (definition.get) { + computedInitializers[prop] = make.compute(prop, definition.get, getInitialValue); + } else if (getInitialValue) { + dataInitializers[prop] = getInitialValue; + } + if (definition.get && definition.set) { + setter = make.set.setter(prop, definition.set, make.read.lastSet(prop), setter, true); + } else if (definition.set) { + setter = make.set.setter(prop, definition.set, reader, eventsSetter, false); + } else if (!definition.get) { + setter = eventsSetter; + } + if (type) { + setter = make.set.type(prop, type, setter); + } + if (definition.Type) { + setter = make.set.Type(prop, definition.Type, setter); + } + Object.defineProperty(objPrototype, prop, { + get: getter, + set: setter, + enumerable: 'serialize' in definition ? !!definition.serialize : !definition.get + }); + }; + define.Constructor = function (defines) { + var constructor = function (props) { + define.setup.call(this, props); + }; + define(constructor.prototype, defines); + return constructor; + }; + make = { + compute: function (prop, get, defaultValueFn) { + return function () { + var map = this, defaultValue = defaultValueFn && defaultValueFn.call(this), computeFn; + if (defaultValue) { + computeFn = defaultValue.isComputed ? defaultValue : compute.async(defaultValue, get, map); + } else { + computeFn = compute.async(defaultValue, get, map); + } + return { + compute: computeFn, + count: 0, + handler: function (ev, newVal, oldVal) { + canEvent.dispatch.call(map, { + type: prop, + target: map + }, [ + newVal, + oldVal + ]); + } + }; + }; + }, + set: { + data: function (prop) { + return function (newVal) { + this._data[prop] = newVal; + }; + }, + computed: function (prop) { + return function (val) { + this._computed[prop].compute(val); + }; + }, + events: function (prop, getCurrent, setData, eventType) { + return function (newVal) { + var current = getCurrent.call(this); + if (newVal !== current) { + setData.call(this, newVal); + canEvent.dispatch.call(this, { + type: prop, + target: this + }, [ + newVal, + current + ]); + } + }; + }, + setter: function (prop, setter, getCurrent, setEvents, hasGetter) { + return function (value) { + var self = this; + canBatch.start(); + var setterCalled = false, current = getCurrent.call(this), setValue = setter.call(this, value, function (value) { + setEvents.call(self, value); + setterCalled = true; + }, current); + if (setterCalled) { + canBatch.stop(); + } else { + if (hasGetter) { + if (setValue !== undefined) { + if (current !== setValue) { + setEvents.call(this, setValue); + } + canBatch.stop(); + } else if (setter.length === 0) { + setEvents.call(this, value); + canBatch.stop(); + return; + } else if (setter.length === 1) { + canBatch.stop(); + } else { + canBatch.stop(); + return; + } + } else { + if (setValue !== undefined) { + setEvents.call(this, setValue); + canBatch.stop(); + } else if (setter.length === 0) { + setEvents.call(this, value); + canBatch.stop(); + return; + } else if (setter.length === 1) { + setEvents.call(this, undefined); + canBatch.stop(); + } else { + canBatch.stop(); + return; + } + } + } + }; + }, + type: function (prop, type, set) { + if (typeof type === 'object') { + return make.set.Type(prop, type, set); + } else { + return function (newValue) { + return set.call(this, type.call(this, newValue, prop)); + }; + } + }, + Type: function (prop, Type, set) { + if (isArray(Type) && types.DefineList) { + Type = types.DefineList.extend({ '#': Type[0] }); + } else if (typeof Type === 'object') { + if (types.DefineMap) { + Type = types.DefineMap.extend(Type); + } else { + Type = define.constructor(Type); + } + } + return function (newValue) { + if (newValue instanceof Type || newValue == null) { + return set.call(this, newValue); + } else { + return set.call(this, new Type(newValue)); + } + }; + } + }, + eventType: { + data: function (prop) { + return function (newVal, oldVal) { + return oldVal !== undefined || this._data.hasOwnProperty(prop) ? 'set' : 'add'; + }; + }, + computed: function () { + return function () { + return 'set'; + }; + } + }, + read: { + data: function (prop) { + return function () { + return this._data[prop]; + }; + }, + computed: function (prop) { + return function () { + return this._computed[prop].compute(); + }; + }, + lastSet: function (prop) { + return function () { + var lastSetValue = this._computed[prop].compute.computeInstance.lastSetValue; + return lastSetValue && lastSetValue.get(); + }; + } + }, + get: { + defaultValue: function (prop, definition, typeConvert, callSetter) { + return function () { + var value = definition.value; + if (value !== undefined) { + if (typeof value === 'function') { + value = value.call(this); + } + value = typeConvert(value); + } else { + var Value = definition.Value; + if (Value) { + value = typeConvert(new Value()); + } + } + if (definition.set) { + var VALUE; + var sync = true; + var setter = make.set.setter(prop, definition.set, function () { + }, function (value) { + if (sync) { + VALUE = value; + } else { + callSetter.call(this, value); + } + }, definition.get); + setter.call(this, value); + sync = false; + return VALUE; + } + return value; + }; + }, + data: function (prop) { + return function () { + Observation.add(this, prop); + return this._data[prop]; + }; + }, + computed: function (prop) { + return function () { + return this._computed[prop].compute(); + }; + } + } + }; + define.behaviors = [ + 'get', + 'set', + 'value', + 'Value', + 'type', + 'Type', + 'serialize' + ]; + var addDefinition = function (definition, behavior, value) { + if (behavior === 'type') { + var behaviorDef = value; + if (typeof behaviorDef === 'string') { + behaviorDef = define.types[behaviorDef]; + if (typeof behaviorDef === 'object') { + assign(definition, behaviorDef); + behaviorDef = behaviorDef[behavior]; + } + } + definition[behavior] = behaviorDef; + } else { + definition[behavior] = value; + } + }; + makeDefinition = function (prop, def, defaultDefinition) { + var definition = {}; + each(def, function (value, behavior) { + addDefinition(definition, behavior, value); + }); + each(defaultDefinition, function (value, prop) { + if (definition[prop] === undefined) { + if (prop !== 'type' && prop !== 'Type') { + definition[prop] = value; + } + } + }); + if (!definition.type && !definition.Type) { + defaults(definition, defaultDefinition); + } + if (isEmptyObject(definition)) { + definition.type = define.types['*']; + } + return definition; + }; + getDefinitionOrMethod = function (prop, value, defaultDefinition) { + var definition; + if (typeof value === 'string') { + definition = { type: value }; + } else if (typeof value === 'function') { + if (types.isConstructor(value)) { + definition = { Type: value }; + } else if (isDefineType(value)) { + definition = { type: value }; + } + } else if (isArray(value)) { + definition = { Type: value }; + } else if (isPlainObject(value)) { + definition = value; + } + if (definition) { + return makeDefinition(prop, definition, defaultDefinition); + } else { + return value; + } + }; + getDefinitionsAndMethods = function (defines, baseDefines) { + var definitions = Object.create(baseDefines ? baseDefines.definitions : null); + var methods = {}; + var defaults = defines['*'], defaultDefinition; + if (defaults) { + delete defines['*']; + defaultDefinition = getDefinitionOrMethod('*', defaults, {}); + } else { + defaultDefinition = {}; + } + eachPropertyDescriptor(defines, function (prop, propertyDescriptor) { + var value; + if (propertyDescriptor.get || propertyDescriptor.set) { + value = { + get: propertyDescriptor.get, + set: propertyDescriptor.set + }; + } else { + value = propertyDescriptor.value; + } + if (prop === 'constructor') { + methods[prop] = value; + return; + } else { + var result = getDefinitionOrMethod(prop, value, defaultDefinition); + if (result && typeof result === 'object') { + definitions[prop] = result; + } else { + methods[prop] = result; + } + } + }); + if (defaults) { + defines['*'] = defaults; + } + return { + definitions: definitions, + methods: methods, + defaultDefinition: defaultDefinition + }; + }; + replaceWith = function (obj, prop, cb, writable) { + Object.defineProperty(obj, prop, { + configurable: true, + get: function () { + Object.defineProperty(this, prop, { + value: undefined, + writable: true + }); + var value = cb.call(this, obj, prop); + Object.defineProperty(this, prop, { + value: value, + writable: !!writable + }); + return value; + } + }); + }; + eventsProto = assign({}, event); + assign(eventsProto, { + _eventSetup: function () { + }, + _eventTeardown: function () { + }, + addEventListener: function (eventName, handler) { + var computedBinding = this._computed && this._computed[eventName]; + if (computedBinding && computedBinding.compute) { + if (!computedBinding.count) { + computedBinding.count = 1; + computedBinding.compute.addEventListener('change', computedBinding.handler); + } else { + computedBinding.count++; + } + } + return eventLifecycle.addAndSetup.apply(this, arguments); + }, + removeEventListener: function (eventName, handler) { + var computedBinding = this._computed && this._computed[eventName]; + if (computedBinding) { + if (computedBinding.count === 1) { + computedBinding.count = 0; + computedBinding.compute.removeEventListener('change', computedBinding.handler); + } else { + computedBinding.count--; + } + } + return eventLifecycle.removeAndTeardown.apply(this, arguments); + } + }); + eventsProto.on = eventsProto.bind = eventsProto.addEventListener; + eventsProto.off = eventsProto.unbind = eventsProto.removeEventListener; + delete eventsProto.one; + define.setup = function (props, sealed) { + defineConfigurableAndNotEnumerable(this, '_cid'); + defineConfigurableAndNotEnumerable(this, '__bindEvents', {}); + defineConfigurableAndNotEnumerable(this, '_bindings', 0); + CID(this); + var definitions = this._define.definitions; + var instanceDefinitions = {}; + var map = this; + each(props, function (value, prop) { + if (definitions[prop]) { + map[prop] = value; + } else { + var def = define.makeSimpleGetterSetter(prop); + instanceDefinitions[prop] = {}; + Object.defineProperty(map, prop, def); + map[prop] = define.types.observable(value); + } + }); + if (!isEmptyObject(instanceDefinitions)) { + defineConfigurableAndNotEnumerable(this, '_instanceDefinitions', instanceDefinitions); + } + }; + define.replaceWith = replaceWith; + define.eventsProto = eventsProto; + define.defineConfigurableAndNotEnumerable = defineConfigurableAndNotEnumerable; + define.make = make; + define.getDefinitionOrMethod = getDefinitionOrMethod; + var simpleGetterSetters = {}; + define.makeSimpleGetterSetter = function (prop) { + if (!simpleGetterSetters[prop]) { + var setter = make.set.events(prop, make.get.data(prop), make.set.data(prop), make.eventType.data(prop)); + simpleGetterSetters[prop] = { + get: make.get.data(prop), + set: function (newVal) { + return setter.call(this, define.types.observable(newVal)); + }, + enumerable: true + }; + } + return simpleGetterSetters[prop]; + }; + define.Iterator = function (obj) { + this.obj = obj; + this.definitions = Object.keys(obj._define.definitions); + this.instanceDefinitions = obj._instanceDefinitions ? Object.keys(obj._instanceDefinitions) : Object.keys(obj); + this.hasGet = typeof obj.get === 'function'; + }; + define.Iterator.prototype.next = function () { + var key; + if (this.definitions.length) { + key = this.definitions.shift(); + var def = this.obj._define.definitions[key]; + if (def.get) { + return this.next(); + } + } else if (this.instanceDefinitions.length) { + key = this.instanceDefinitions.shift(); + } else { + return { + value: undefined, + done: true + }; + } + return { + value: [ + key, + this.hasGet ? this.obj.get(key) : this.obj[key] + ], + done: false + }; + }; + isDefineType = function (func) { + return func && func.canDefineType === true; + }; + define.types = { + 'date': function (str) { + var type = typeof str; + if (type === 'string') { + str = Date.parse(str); + return isNaN(str) ? null : new Date(str); + } else if (type === 'number') { + return new Date(str); + } else { + return str; + } + }, + 'number': function (val) { + if (val == null) { + return val; + } + return +val; + }, + 'boolean': function (val) { + if (val == null) { + return val; + } + if (val === 'false' || val === '0' || !val) { + return false; + } + return true; + }, + 'observable': function (newVal) { + if (isArray(newVal) && types.DefineList) { + newVal = new types.DefineList(newVal); + } else if (isPlainObject(newVal) && types.DefineMap) { + newVal = new types.DefineMap(newVal); + } + return newVal; + }, + 'stringOrObservable': function (newVal) { + if (isArray(newVal)) { + return new types.DefaultList(newVal); + } else if (isPlainObject(newVal)) { + return new types.DefaultMap(newVal); + } else { + return define.types.string(newVal); + } + }, + 'htmlbool': function (val) { + return typeof val === 'string' || !!val; + }, + '*': function (val) { + return val; + }, + 'any': function (val) { + return val; + }, + 'string': function (val) { + if (val == null) { + return val; + } + return '' + val; + }, + 'compute': { + set: function (newValue, setVal, setErr, oldValue) { + if (newValue && newValue.isComputed) { + return newValue; + } + if (oldValue && oldValue.isComputed) { + oldValue(newValue); + return oldValue; + } + return newValue; + }, + get: function (value) { + return value && value.isComputed ? value() : value; + } + } + }; +}); +/*can-util@3.2.2#js/is-function/is-function*/ +define('can-util/js/is-function/is-function', function (require, exports, module) { + 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.2.2#js/deep-assign/deep-assign*/ +define('can-util/js/deep-assign/deep-assign', function (require, exports, module) { + var isArray = require('can-util/js/is-array/is-array'); + 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 = isArray(copy)))) { + if (copyIsArray) { + copyIsArray = false; + clone = src && 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-util@3.2.2#js/make-array/make-array*/ +define('can-util/js/make-array/make-array', function (require, exports, module) { + var each = require('can-util/js/each/each'); + function makeArray(arr) { + var ret = []; + each(arr, function (a, i) { + ret[i] = a; + }); + return ret; + } + module.exports = makeArray; +}); +/*can-util@3.2.2#js/string/string*/ +define('can-util/js/string/string', function (require, exports, module) { + 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-construct@3.1.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 types = require('can-types'); + 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 () { + }; + var oldIsConstructor = types.isConstructor; + types.isConstructor = function (obj) { + return obj.prototype instanceof Construct || oldIsConstructor.call(null, obj); + }; + module.exports = namespace.Construct = Construct; +}); +/*can-define@1.0.15#define-helpers/define-helpers*/ +define('can-define/define-helpers/define-helpers', function (require, exports, module) { + var assign = require('can-util/js/assign/assign'); + var CID = require('can-cid'); + var define = require('can-define'); + var canBatch = require('can-event/batch/batch'); + var canEvent = require('can-event'); + var hasMethod = function (obj, method) { + return obj && typeof obj === 'object' && method in obj; + }; + var defineHelpers = { + extendedSetup: function (props) { + assign(this, props); + }, + toObject: function (map, props, where, Type) { + if (props instanceof Type) { + props.each(function (value, prop) { + where[prop] = value; + }); + return where; + } else { + return props; + } + }, + defineExpando: function (map, prop, value) { + var constructorDefines = map._define.definitions; + if (constructorDefines && constructorDefines[prop]) { + return; + } + var instanceDefines = map._instanceDefinitions; + if (!instanceDefines) { + instanceDefines = map._instanceDefinitions = {}; + } + if (!instanceDefines[prop]) { + var defaultDefinition = map._define.defaultDefinition || { type: define.types.observable }; + define.property(map, prop, defaultDefinition, {}, {}); + map._data[prop] = defaultDefinition.type ? defaultDefinition.type(value) : define.types.observable(value); + instanceDefines[prop] = defaultDefinition; + canBatch.start(); + canEvent.dispatch.call(map, { + type: '__keys', + target: map + }); + if (map._data[prop] !== undefined) { + canEvent.dispatch.call(map, { + type: prop, + target: map + }, [ + map._data[prop], + undefined + ]); + } + canBatch.stop(); + return true; + } + }, + getValue: function (map, name, val, how) { + if (how === 'serialize') { + var constructorDefinitions = map._define.definitions; + var propDef = constructorDefinitions[name]; + if (propDef && typeof propDef.serialize === 'function') { + return propDef.serialize.call(map, val, name); + } + var defaultDefinition = map._define.defaultDefinition; + if (defaultDefinition && typeof defaultDefinition.serialize === 'function') { + return defaultDefinition.serialize.call(map, val, name); + } + } + if (hasMethod(val, how)) { + return val[how](); + } else { + return val; + } + }, + serialize: function () { + var serializeMap = null; + return function (map, how, where) { + var cid = CID(map), firstSerialize = false; + if (!serializeMap) { + firstSerialize = true; + serializeMap = { + get: {}, + serialize: {} + }; + } + serializeMap[how][cid] = where; + map.each(function (val, name) { + var result, isObservable = hasMethod(val, how), serialized = isObservable && serializeMap[how][CID(val)]; + if (serialized) { + result = serialized; + } else { + result = defineHelpers.getValue(map, name, val, how); + } + if (result !== undefined) { + where[name] = result; + } + }); + if (firstSerialize) { + serializeMap = null; + } + return where; + }; + }() + }; + module.exports = defineHelpers; +}); +/*can-define@1.0.15#map/map*/ +define('can-define/map/map', function (require, exports, module) { + var Construct = require('can-construct'); + var define = require('can-define'); + var assign = require('can-util/js/assign/assign'); + var isArray = require('can-util/js/is-array/is-array'); + var isPlainObject = require('can-util/js/is-plain-object/is-plain-object'); + var defineHelpers = require('can-define/define-helpers/define-helpers'); + var Observation = require('can-observation'); + var types = require('can-types'); + var canBatch = require('can-event/batch/batch'); + var ns = require('can-namespace'); + var readWithoutObserve = Observation.ignore(function (map, prop) { + return map[prop]; + }); + var eachDefinition = function (map, cb, thisarg, definitions, observe) { + for (var prop in definitions) { + var definition = definitions[prop]; + if (typeof definition !== 'object' || ('serialize' in definition ? !!definition.serialize : !definition.get)) { + var item = observe === false ? readWithoutObserve(map, prop) : map[prop]; + if (cb.call(thisarg || item, item, prop, map) === false) { + return false; + } + } + } + }; + var setProps = function (props, remove) { + props = assign({}, props); + var prop, self = this, newVal; + canBatch.start(); + this.each(function (curVal, prop) { + if (prop === '_cid') { + return; + } + newVal = props[prop]; + if (newVal === undefined) { + if (remove) { + self[prop] = undefined; + } + return; + } + if (typeof curVal !== 'object' || curVal === null) { + self.set(prop, newVal); + } else if ('replace' in curVal && isArray(newVal)) { + curVal.replace(newVal); + } else if ('set' in curVal && (isPlainObject(newVal) || isArray(newVal))) { + curVal.set(newVal, remove); + } else if ('attr' in curVal && (isPlainObject(newVal) || isArray(newVal))) { + curVal.attr(newVal, remove); + } else if (curVal !== newVal) { + self.set(prop, newVal); + } + delete props[prop]; + }, this, false); + for (prop in props) { + if (prop !== '_cid') { + newVal = props[prop]; + this.set(prop, newVal); + } + } + canBatch.stop(); + return this; + }; + var DefineMap = Construct.extend('DefineMap', { + setup: function (base) { + if (DefineMap) { + var prototype = this.prototype; + define(prototype, prototype, base.prototype._define); + this.prototype.setup = function (props) { + define.setup.call(this, defineHelpers.toObject(this, props, {}, DefineMap), this.constructor.seal); + }; + } + } + }, { + setup: function (props, sealed) { + if (!this._define) { + Object.defineProperty(this, '_define', { + enumerable: false, + value: { definitions: {} } + }); + Object.defineProperty(this, '_data', { + enumerable: false, + value: {} + }); + } + define.setup.call(this, defineHelpers.toObject(this, props, {}, DefineMap), sealed === true); + }, + get: function (prop) { + if (prop) { + var value = this[prop]; + if (value !== undefined || prop in this || Object.isSealed(this)) { + return value; + } else { + Observation.add(this, prop); + return this[prop]; + } + } else { + return defineHelpers.serialize(this, 'get', {}); + } + }, + set: function (prop, value) { + if (typeof prop === 'object') { + return setProps.call(this, prop, value); + } + var defined = defineHelpers.defineExpando(this, prop, value); + if (!defined) { + this[prop] = value; + } + return this; + }, + serialize: function () { + return defineHelpers.serialize(this, 'serialize', {}); + }, + forEach: function (cb, thisarg, observe) { + if (observe !== false) { + Observation.add(this, '__keys'); + } + var res; + var constructorDefinitions = this._define.definitions; + if (constructorDefinitions) { + res = eachDefinition(this, cb, thisarg, constructorDefinitions, observe); + } + if (res === false) { + return this; + } + if (this._instanceDefinitions) { + eachDefinition(this, cb, thisarg, this._instanceDefinitions, observe); + } + return this; + }, + '*': { type: define.types.observable } + }); + for (var prop in define.eventsProto) { + DefineMap[prop] = define.eventsProto[prop]; + Object.defineProperty(DefineMap.prototype, prop, { + enumerable: false, + value: define.eventsProto[prop], + writable: true + }); + } + types.DefineMap = DefineMap; + types.DefaultMap = DefineMap; + DefineMap.prototype.toObject = function () { + console.warn('Use DefineMap::get instead of DefineMap::toObject'); + return this.get(); + }; + DefineMap.prototype.each = DefineMap.prototype.forEach; + var oldIsMapLike = types.isMapLike; + types.isMapLike = function (obj) { + return obj instanceof DefineMap || oldIsMapLike.apply(this, arguments); + }; + module.exports = ns.DefineMap = DefineMap; +}); +/*can-define@1.0.15#list/list*/ +define('can-define/list/list', function (require, exports, module) { + var Construct = require('can-construct'); + var define = require('can-define'); + var make = define.make; + var canEvent = require('can-event'); + var canBatch = require('can-event/batch/batch'); + var Observation = require('can-observation'); + var defineHelpers = require('can-define/define-helpers/define-helpers'); + var assign = require('can-util/js/assign/assign'); + var each = require('can-util/js/each/each'); + var isArray = require('can-util/js/is-array/is-array'); + var makeArray = require('can-util/js/make-array/make-array'); + var types = require('can-types'); + var ns = require('can-namespace'); + var splice = [].splice; + var identity = function (x) { + return x; + }; + var makeFilterCallback = function (props) { + return function (item) { + for (var prop in props) { + if (item[prop] !== props[prop]) { + return false; + } + } + return true; + }; + }; + var DefineList = Construct.extend('DefineList', { + setup: function (base) { + if (DefineList) { + var prototype = this.prototype; + var result = define(prototype, prototype, base.prototype._define); + var itemsDefinition = result.definitions['#'] || result.defaultDefinition; + if (itemsDefinition) { + if (itemsDefinition.Type) { + this.prototype.__type = make.set.Type('*', itemsDefinition.Type, identity); + } else if (itemsDefinition.type) { + this.prototype.__type = make.set.type('*', itemsDefinition.type, identity); + } + } + } + } + }, { + setup: function (items) { + if (!this._define) { + Object.defineProperty(this, '_define', { + enumerable: false, + value: { definitions: {} } + }); + Object.defineProperty(this, '_data', { + enumerable: false, + value: {} + }); + } + define.setup.call(this, {}, false); + this._length = 0; + if (items) { + this.splice.apply(this, [ + 0, + 0 + ].concat(defineHelpers.toObject(this, items, [], DefineList))); + } + }, + __type: define.types.observable, + _triggerChange: function (attr, how, newVal, oldVal) { + canBatch.start(); + var index = +attr; + if (!~('' + attr).indexOf('.') && !isNaN(index)) { + var itemsDefinition = this._define.definitions['#']; + if (how === 'add') { + if (itemsDefinition && typeof itemsDefinition.added === 'function') { + Observation.ignore(itemsDefinition.added).call(this, newVal, index); + } + canEvent.dispatch.call(this, how, [ + newVal, + index + ]); + canEvent.dispatch.call(this, 'length', [this._length]); + } else if (how === 'remove') { + if (itemsDefinition && typeof itemsDefinition.removed === 'function') { + Observation.ignore(itemsDefinition.removed).call(this, oldVal, index); + } + canEvent.dispatch.call(this, how, [ + oldVal, + index + ]); + canEvent.dispatch.call(this, 'length', [this._length]); + } else { + canEvent.dispatch.call(this, how, [ + newVal, + index + ]); + } + } else { + canEvent.dispatch.call(this, { + type: '' + attr, + target: this + }, [ + newVal, + oldVal + ]); + } + canBatch.stop(); + }, + get: function (index) { + if (arguments.length) { + Observation.add(this, '' + index); + return this[index]; + } else { + return defineHelpers.serialize(this, 'get', []); + } + }, + set: function (prop, value) { + if (typeof prop !== 'object') { + prop = isNaN(+prop) || prop % 1 ? prop : +prop; + if (typeof prop === 'number') { + if (typeof prop === 'number' && prop > this._length - 1) { + var newArr = new Array(prop + 1 - this._length); + newArr[newArr.length - 1] = value; + this.push.apply(this, newArr); + return newArr; + } + this.splice(prop, 1, value); + } else { + var defined = defineHelpers.defineExpando(this, prop, value); + if (!defined) { + this[prop] = value; + } + } + } else { + if (isArray(prop)) { + if (value) { + this.replace(prop); + } else { + this.splice.apply(this, [ + 0, + prop.length + ].concat(prop)); + } + } else { + each(prop, function (value, prop) { + this.set(prop, value); + }, this); + } + } + return this; + }, + _items: function () { + var arr = []; + this._each(function (item) { + arr.push(item); + }); + return arr; + }, + _each: function (callback) { + for (var i = 0, len = this._length; i < len; i++) { + callback(this[i], i); + } + }, + 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); + canBatch.start(); + if (howMany > 0) { + this._triggerChange('' + index, 'remove', undefined, removed); + } + if (args.length > 2) { + this._triggerChange('' + index, 'add', added, removed); + } + canBatch.stop(); + return removed; + }, + serialize: function () { + return defineHelpers.serialize(this, 'serialize', []); + } + }); + var 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]; + DefineList.prototype[name] = function () { + var args = [], len = where ? this._length : 0, i = arguments.length, res, val; + while (i--) { + val = arguments[i]; + args[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) { + DefineList.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]); + return res; + }; + }); + assign(DefineList.prototype, { + indexOf: function (item, fromIndex) { + for (var i = fromIndex || 0, len = this.length; i < len; i++) { + if (this.get(i) === item) { + return i; + } + } + return -1; + }, + join: function () { + Observation.add(this, 'length'); + return [].join.apply(this, arguments); + }, + reverse: function () { + var list = [].reverse.call(this._items()); + 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 = []; + each(arguments, function (arg) { + if (types.isListLike(arg) || Array.isArray(arg)) { + var arr = types.isListLike(arg) ? makeArray(arg) : arg; + each(arr, function (innerArg) { + args.push(this.__type(innerArg)); + }, this); + } else { + args.push(this.__type(arg)); + } + }, this); + return new this.constructor(Array.prototype.concat.apply(makeArray(this), args)); + }, + forEach: function (cb, thisarg) { + var item; + for (var i = 0, len = this.length; i < len; i++) { + item = this.get(i); + if (cb.call(thisarg || item, item, i, this) === false) { + break; + } + } + return this; + }, + replace: function (newList) { + this.splice.apply(this, [ + 0, + this._length + ].concat(makeArray(newList || []))); + return this; + }, + filter: function (callback, thisArg) { + var filteredList = [], self = this, filtered; + if (typeof callback === 'object') { + callback = makeFilterCallback(callback); + } + this.each(function (item, index, list) { + filtered = callback.call(thisArg | self, item, index, self); + if (filtered) { + filteredList.push(item); + } + }); + return new this.constructor(filteredList); + }, + map: function (callback, thisArg) { + var mappedList = [], self = this; + this.each(function (item, index, list) { + var mapped = callback.call(thisArg | self, item, index, self); + mappedList.push(mapped); + }); + return new this.constructor(mappedList); + }, + sort: function (compareFunction) { + var removed = Array.prototype.slice.call(this); + Array.prototype.sort.call(this, compareFunction); + var added = Array.prototype.slice.call(this); + canBatch.start(); + canEvent.dispatch.call(this, 'remove', [ + removed, + 0 + ]); + canEvent.dispatch.call(this, 'add', [ + added, + 0 + ]); + canEvent.dispatch.call(this, 'length', [ + this._length, + this._length + ]); + canBatch.stop(); + return this; + } + }); + for (var prop in define.eventsProto) { + DefineList[prop] = define.eventsProto[prop]; + Object.defineProperty(DefineList.prototype, prop, { + enumerable: false, + value: define.eventsProto[prop], + writable: true + }); + } + Object.defineProperty(DefineList.prototype, 'length', { + get: function () { + if (!this.__inSetup) { + Observation.add(this, 'length'); + } + return this._length; + }, + set: function (newVal) { + this._length = newVal; + }, + enumerable: true + }); + var oldIsListLike = types.isListLike; + types.isListLike = function (obj) { + return obj instanceof DefineList || oldIsListLike.apply(this, arguments); + }; + DefineList.prototype.each = DefineList.prototype.forEach; + DefineList.prototype.attr = function (prop, value) { + console.warn('DefineMap::attr shouldn\'t be called'); + if (arguments.length === 0) { + return this.get(); + } else if (prop && typeof prop === 'object') { + return this.set.apply(this, arguments); + } else if (arguments.length === 1) { + return this.get(prop); + } else { + return this.set(prop, value); + } + }; + DefineList.prototype.item = function (index, value) { + if (arguments.length === 1) { + return this.get(index); + } else { + return this.set(index, value); + } + }; + DefineList.prototype.items = function () { + console.warn('DefineList::get should should be used instead of DefineList::items'); + return this.get(); + }; + types.DefineList = DefineList; + types.DefaultList = DefineList; + module.exports = ns.DefineList = DefineList; +}); +/*[global-shim-end]*/ +(function(){ // jshint ignore:line + window._define = window.define; + window.define = window.define.orig; +} +)(); \ No newline at end of file