UNPKG

@danielkalen/simplybind

Version:

Magically simple, framework-less one-way/two-way data binding for frontend/backend in ~5kb.

1,610 lines (1,314 loc) 192 kB
'use strict'; System.register(['aurelia-logging', 'aurelia-pal', 'aurelia-task-queue', 'aurelia-metadata'], function (_export, _context) { "use strict"; var LogManager, PLATFORM, DOM, TaskQueue, metadata, _typeof, _createClass, _dec, _dec2, _class, _dec3, _class2, _dec4, _class3, _dec5, _class5, _dec6, _class7, _dec7, _class8, _dec8, _class9, _dec9, _class10, _class11, _temp, _dec10, _class12, _class13, _temp2, map, sourceContext, slotNames, versionSlotNames, i, bindings, minimumImmediate, frameBudget, isFlushRequested, immediate, arrayPool1, arrayPool2, poolUtilization, ExpressionObserver, EDIT_LEAVE, EDIT_UPDATE, EDIT_ADD, EDIT_DELETE, arraySplice, ModifyCollectionObserver, CollectionLengthObserver, pop, push, reverse, shift, sort, splice, unshift, ModifyArrayObserver, Expression, Chain, BindingBehavior, ValueConverter, Assign, Conditional, AccessThis, AccessScope, AccessMember, AccessKeyed, CallScope, CallMember, CallFunction, Binary, PrefixNot, LiteralPrimitive, LiteralString, LiteralArray, LiteralObject, evalListCache, Unparser, ExpressionCloner, bindingMode, Token, Lexer, Scanner, OPERATORS, $EOF, $TAB, $LF, $VTAB, $FF, $CR, $SPACE, $BANG, $DQ, $$, $PERCENT, $AMPERSAND, $SQ, $LPAREN, $RPAREN, $STAR, $PLUS, $COMMA, $MINUS, $PERIOD, $SLASH, $COLON, $SEMICOLON, $LT, $EQ, $GT, $QUESTION, $0, $9, $A, $E, $Z, $LBRACKET, $BACKSLASH, $RBRACKET, $CARET, $_, $a, $e, $f, $n, $r, $t, $u, $v, $z, $LBRACE, $BAR, $RBRACE, $NBSP, EOF, Parser, ParserImplementation, mapProto, ModifyMapObserver, DelegateHandlerEntry, DefaultEventStrategy, EventManager, DirtyChecker, DirtyCheckProperty, logger, propertyAccessor, PrimitiveObserver, SetterObserver, XLinkAttributeObserver, dataAttributeAccessor, DataAttributeObserver, StyleObserver, ValueAttributeObserver, checkedArrayContext, checkedValueContext, CheckedObserver, selectArrayContext, SelectValueObserver, ClassObserver, ComputedExpression, elements, presentationElements, presentationAttributes, SVGAnalyzer, ObserverLocator, ObjectObservationAdapter, BindingExpression, targetContext, Binding, CallExpression, Call, ValueConverterResource, BindingBehaviorResource, ListenerExpression, Listener, NameExpression, NameBinder, LookupFunctions, BindingEngine, setProto, ModifySetObserver; function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } function camelCase(name) { if (name in map) { return map[name]; } var result = name.charAt(0).toLowerCase() + name.slice(1).replace(/[_.-](\w|$)/g, function (_, x) { return x.toUpperCase(); }); map[name] = result; return result; } _export('camelCase', camelCase); function createOverrideContext(bindingContext, parentOverrideContext) { return { bindingContext: bindingContext, parentOverrideContext: parentOverrideContext || null }; } _export('createOverrideContext', createOverrideContext); function getContextFor(name, scope, ancestor) { var oc = scope.overrideContext; if (ancestor) { while (ancestor && oc) { ancestor--; oc = oc.parentOverrideContext; } if (ancestor || !oc) { return undefined; } return name in oc ? oc : oc.bindingContext; } while (oc && !(name in oc) && !(oc.bindingContext && name in oc.bindingContext)) { oc = oc.parentOverrideContext; } if (oc) { return name in oc ? oc : oc.bindingContext; } return scope.bindingContext || scope.overrideContext; } _export('getContextFor', getContextFor); function createScopeForTest(bindingContext, parentBindingContext) { if (parentBindingContext) { return { bindingContext: bindingContext, overrideContext: createOverrideContext(bindingContext, createOverrideContext(parentBindingContext)) }; } return { bindingContext: bindingContext, overrideContext: createOverrideContext(bindingContext) }; } _export('createScopeForTest', createScopeForTest); function addObserver(observer) { var observerSlots = this._observerSlots === undefined ? 0 : this._observerSlots; var i = observerSlots; while (i-- && this[slotNames[i]] !== observer) {} if (i === -1) { i = 0; while (this[slotNames[i]]) { i++; } this[slotNames[i]] = observer; observer.subscribe(sourceContext, this); if (i === observerSlots) { this._observerSlots = i + 1; } } if (this._version === undefined) { this._version = 0; } this[versionSlotNames[i]] = this._version; } function observeProperty(obj, propertyName) { var observer = this.observerLocator.getObserver(obj, propertyName); addObserver.call(this, observer); } function observeArray(array) { var observer = this.observerLocator.getArrayObserver(array); addObserver.call(this, observer); } function unobserve(all) { var i = this._observerSlots; while (i--) { if (all || this[versionSlotNames[i]] !== this._version) { var observer = this[slotNames[i]]; this[slotNames[i]] = null; if (observer) { observer.unsubscribe(sourceContext, this); } } } } function connectable() { return function (target) { target.prototype.observeProperty = observeProperty; target.prototype.observeArray = observeArray; target.prototype.unobserve = unobserve; target.prototype.addObserver = addObserver; }; } _export('connectable', connectable); function flush(animationFrameStart) { var i = 0; var keys = bindings.keys(); var item = void 0; while (item = keys.next()) { if (item.done) { break; } var binding = item.value; bindings.delete(binding); binding.connect(true); i++; if (i % 100 === 0 && PLATFORM.performance.now() - animationFrameStart > frameBudget) { break; } } if (bindings.size) { PLATFORM.requestAnimationFrame(flush); } else { isFlushRequested = false; immediate = 0; } } function enqueueBindingConnect(binding) { if (immediate < minimumImmediate) { immediate++; binding.connect(false); } else { bindings.set(binding); } if (!isFlushRequested) { isFlushRequested = true; PLATFORM.requestAnimationFrame(flush); } } _export('enqueueBindingConnect', enqueueBindingConnect); function addSubscriber(context, callable) { if (this.hasSubscriber(context, callable)) { return false; } if (!this._context0) { this._context0 = context; this._callable0 = callable; return true; } if (!this._context1) { this._context1 = context; this._callable1 = callable; return true; } if (!this._context2) { this._context2 = context; this._callable2 = callable; return true; } if (!this._contextsRest) { this._contextsRest = [context]; this._callablesRest = [callable]; return true; } this._contextsRest.push(context); this._callablesRest.push(callable); return true; } function removeSubscriber(context, callable) { if (this._context0 === context && this._callable0 === callable) { this._context0 = null; this._callable0 = null; return true; } if (this._context1 === context && this._callable1 === callable) { this._context1 = null; this._callable1 = null; return true; } if (this._context2 === context && this._callable2 === callable) { this._context2 = null; this._callable2 = null; return true; } var rest = this._contextsRest; var index = void 0; if (!rest || !rest.length || (index = rest.indexOf(context)) === -1 || this._callablesRest[index] !== callable) { return false; } rest.splice(index, 1); this._callablesRest.splice(index, 1); return true; } function callSubscribers(newValue, oldValue) { var context0 = this._context0; var callable0 = this._callable0; var context1 = this._context1; var callable1 = this._callable1; var context2 = this._context2; var callable2 = this._callable2; var length = this._contextsRest ? this._contextsRest.length : 0; var contextsRest = void 0; var callablesRest = void 0; var poolIndex = void 0; var i = void 0; if (length) { poolIndex = poolUtilization.length; while (poolIndex-- && poolUtilization[poolIndex]) {} if (poolIndex < 0) { poolIndex = poolUtilization.length; contextsRest = []; callablesRest = []; poolUtilization.push(true); arrayPool1.push(contextsRest); arrayPool2.push(callablesRest); } else { poolUtilization[poolIndex] = true; contextsRest = arrayPool1[poolIndex]; callablesRest = arrayPool2[poolIndex]; } i = length; while (i--) { contextsRest[i] = this._contextsRest[i]; callablesRest[i] = this._callablesRest[i]; } } if (context0) { if (callable0) { callable0.call(context0, newValue, oldValue); } else { context0(newValue, oldValue); } } if (context1) { if (callable1) { callable1.call(context1, newValue, oldValue); } else { context1(newValue, oldValue); } } if (context2) { if (callable2) { callable2.call(context2, newValue, oldValue); } else { context2(newValue, oldValue); } } if (length) { for (i = 0; i < length; i++) { var callable = callablesRest[i]; var context = contextsRest[i]; if (callable) { callable.call(context, newValue, oldValue); } else { context(newValue, oldValue); } contextsRest[i] = null; callablesRest[i] = null; } poolUtilization[poolIndex] = false; } } function hasSubscribers() { return !!(this._context0 || this._context1 || this._context2 || this._contextsRest && this._contextsRest.length); } function hasSubscriber(context, callable) { var has = this._context0 === context && this._callable0 === callable || this._context1 === context && this._callable1 === callable || this._context2 === context && this._callable2 === callable; if (has) { return true; } var index = void 0; var contexts = this._contextsRest; if (!contexts || (index = contexts.length) === 0) { return false; } var callables = this._callablesRest; while (index--) { if (contexts[index] === context && callables[index] === callable) { return true; } } return false; } function subscriberCollection() { return function (target) { target.prototype.addSubscriber = addSubscriber; target.prototype.removeSubscriber = removeSubscriber; target.prototype.callSubscribers = callSubscribers; target.prototype.hasSubscribers = hasSubscribers; target.prototype.hasSubscriber = hasSubscriber; }; } _export('subscriberCollection', subscriberCollection); function isIndex(s) { return +s === s >>> 0; } function toNumber(s) { return +s; } function newSplice(index, removed, addedCount) { return { index: index, removed: removed, addedCount: addedCount }; } function ArraySplice() {} function calcSplices(current, currentStart, currentEnd, old, oldStart, oldEnd) { return arraySplice.calcSplices(current, currentStart, currentEnd, old, oldStart, oldEnd); } _export('calcSplices', calcSplices); function intersect(start1, end1, start2, end2) { if (end1 < start2 || end2 < start1) { return -1; } if (end1 === start2 || end2 === start1) { return 0; } if (start1 < start2) { if (end1 < end2) { return end1 - start2; } return end2 - start2; } if (end2 < end1) { return end2 - start1; } return end1 - start1; } function mergeSplice(splices, index, removed, addedCount) { var splice = newSplice(index, removed, addedCount); var inserted = false; var insertionOffset = 0; for (var _i5 = 0; _i5 < splices.length; _i5++) { var current = splices[_i5]; current.index += insertionOffset; if (inserted) { continue; } var intersectCount = intersect(splice.index, splice.index + splice.removed.length, current.index, current.index + current.addedCount); if (intersectCount >= 0) { splices.splice(_i5, 1); _i5--; insertionOffset -= current.addedCount - current.removed.length; splice.addedCount += current.addedCount - intersectCount; var deleteCount = splice.removed.length + current.removed.length - intersectCount; if (!splice.addedCount && !deleteCount) { inserted = true; } else { var currentRemoved = current.removed; if (splice.index < current.index) { var prepend = splice.removed.slice(0, current.index - splice.index); Array.prototype.push.apply(prepend, currentRemoved); currentRemoved = prepend; } if (splice.index + splice.removed.length > current.index + current.addedCount) { var append = splice.removed.slice(current.index + current.addedCount - splice.index); Array.prototype.push.apply(currentRemoved, append); } splice.removed = currentRemoved; if (current.index < splice.index) { splice.index = current.index; } } } else if (splice.index < current.index) { inserted = true; splices.splice(_i5, 0, splice); _i5++; var offset = splice.addedCount - splice.removed.length; current.index += offset; insertionOffset += offset; } } if (!inserted) { splices.push(splice); } } _export('mergeSplice', mergeSplice); function createInitialSplices(array, changeRecords) { var splices = []; for (var _i6 = 0; _i6 < changeRecords.length; _i6++) { var record = changeRecords[_i6]; switch (record.type) { case 'splice': mergeSplice(splices, record.index, record.removed.slice(), record.addedCount); break; case 'add': case 'update': case 'delete': if (!isIndex(record.name)) { continue; } var index = toNumber(record.name); if (index < 0) { continue; } mergeSplice(splices, index, [record.oldValue], record.type === 'delete' ? 0 : 1); break; default: console.error('Unexpected record type: ' + JSON.stringify(record)); break; } } return splices; } function projectArraySplices(array, changeRecords) { var splices = []; createInitialSplices(array, changeRecords).forEach(function (splice) { if (splice.addedCount === 1 && splice.removed.length === 1) { if (splice.removed[0] !== array[splice.index]) { splices.push(splice); } return; } splices = splices.concat(calcSplices(array, splice.index, splice.index + splice.addedCount, splice.removed, 0, splice.removed.length)); }); return splices; } _export('projectArraySplices', projectArraySplices); function newRecord(type, object, key, oldValue) { return { type: type, object: object, key: key, oldValue: oldValue }; } function getChangeRecords(map) { var entries = new Array(map.size); var keys = map.keys(); var i = 0; var item = void 0; while (item = keys.next()) { if (item.done) { break; } entries[i] = newRecord('added', map, item.value); i++; } return entries; } _export('getChangeRecords', getChangeRecords); function _getArrayObserver(taskQueue, array) { return ModifyArrayObserver.for(taskQueue, array); } function evalList(scope, list, lookupFunctions) { var length = list.length; for (var cacheLength = evalListCache.length; cacheLength <= length; ++cacheLength) { evalListCache.push([]); } var result = evalListCache[length]; for (var _i14 = 0; _i14 < length; ++_i14) { result[_i14] = list[_i14].evaluate(scope, lookupFunctions); } return result; } function autoConvertAdd(a, b) { if (a !== null && b !== null) { if (typeof a === 'string' && typeof b !== 'string') { return a + b.toString(); } if (typeof a !== 'string' && typeof b === 'string') { return a.toString() + b; } return a + b; } if (a !== null) { return a; } if (b !== null) { return b; } return 0; } function getFunction(obj, name, mustExist) { var func = obj === null || obj === undefined ? null : obj[name]; if (typeof func === 'function') { return func; } if (!mustExist && (func === null || func === undefined)) { return null; } throw new Error(name + ' is not a function'); } function getKeyed(obj, key) { if (Array.isArray(obj)) { return obj[parseInt(key, 10)]; } else if (obj) { return obj[key]; } else if (obj === null || obj === undefined) { return undefined; } return obj[key]; } function setKeyed(obj, key, value) { if (Array.isArray(obj)) { var index = parseInt(key, 10); if (obj.length <= index) { obj.length = index + 1; } obj[index] = value; } else { obj[key] = value; } return value; } function cloneExpression(expression) { var visitor = new ExpressionCloner(); return expression.accept(visitor); } _export('cloneExpression', cloneExpression); function isWhitespace(code) { return code >= $TAB && code <= $SPACE || code === $NBSP; } function isIdentifierStart(code) { return $a <= code && code <= $z || $A <= code && code <= $Z || code === $_ || code === $$; } function isIdentifierPart(code) { return $a <= code && code <= $z || $A <= code && code <= $Z || $0 <= code && code <= $9 || code === $_ || code === $$; } function isDigit(code) { return $0 <= code && code <= $9; } function isExponentStart(code) { return code === $e || code === $E; } function isExponentSign(code) { return code === $MINUS || code === $PLUS; } function unescape(code) { switch (code) { case $n: return $LF; case $f: return $FF; case $r: return $CR; case $t: return $TAB; case $v: return $VTAB; default: return code; } } function assert(condition, message) { if (!condition) { throw message || 'Assertion failed'; } } function _getMapObserver(taskQueue, map) { return ModifyMapObserver.for(taskQueue, map); } function findOriginalEventTarget(event) { return event.path && event.path[0] || event.deepPath && event.deepPath[0] || event.target; } function interceptStopPropagation(event) { event.standardStopPropagation = event.stopPropagation; event.stopPropagation = function () { this.propagationStopped = true; this.standardStopPropagation(); }; } function handleDelegatedEvent(event) { var interceptInstalled = false; event.propagationStopped = false; var target = findOriginalEventTarget(event); while (target && !event.propagationStopped) { if (target.delegatedCallbacks) { var callback = target.delegatedCallbacks[event.type]; if (callback) { if (!interceptInstalled) { interceptStopPropagation(event); interceptInstalled = true; } callback(event); } } target = target.parentNode; } } function hasDeclaredDependencies(descriptor) { return !!(descriptor && descriptor.get && descriptor.get.dependencies); } _export('hasDeclaredDependencies', hasDeclaredDependencies); function declarePropertyDependencies(ctor, propertyName, dependencies) { var descriptor = Object.getOwnPropertyDescriptor(ctor.prototype, propertyName); descriptor.get.dependencies = dependencies; } _export('declarePropertyDependencies', declarePropertyDependencies); function computedFrom() { for (var _len = arguments.length, rest = Array(_len), _key = 0; _key < _len; _key++) { rest[_key] = arguments[_key]; } return function (target, key, descriptor) { descriptor.get.dependencies = rest; return descriptor; }; } _export('computedFrom', computedFrom); function createComputedObserver(obj, propertyName, descriptor, observerLocator) { var dependencies = descriptor.get.dependencies; if (!(dependencies instanceof ComputedExpression)) { var _i24 = dependencies.length; while (_i24--) { dependencies[_i24] = observerLocator.parser.parse(dependencies[_i24]); } dependencies = descriptor.get.dependencies = new ComputedExpression(propertyName, dependencies); } var scope = { bindingContext: obj, overrideContext: createOverrideContext(obj) }; return new ExpressionObserver(scope, dependencies, observerLocator); } _export('createComputedObserver', createComputedObserver); function createElement(html) { var div = DOM.createElement('div'); div.innerHTML = html; return div.firstChild; } function valueConverter(nameOrTarget) { if (nameOrTarget === undefined || typeof nameOrTarget === 'string') { return function (target) { metadata.define(metadata.resource, new ValueConverterResource(nameOrTarget), target); }; } metadata.define(metadata.resource, new ValueConverterResource(), nameOrTarget); } _export('valueConverter', valueConverter); function bindingBehavior(nameOrTarget) { if (nameOrTarget === undefined || typeof nameOrTarget === 'string') { return function (target) { metadata.define(metadata.resource, new BindingBehaviorResource(nameOrTarget), target); }; } metadata.define(metadata.resource, new BindingBehaviorResource(), nameOrTarget); } _export('bindingBehavior', bindingBehavior); function getAU(element) { var au = element.au; if (au === undefined) { throw new Error('No Aurelia APIs are defined for the element: "' + element.tagName + '".'); } return au; } function _getSetObserver(taskQueue, set) { return ModifySetObserver.for(taskQueue, set); } function observable(targetOrConfig, key, descriptor) { function deco(target, key, descriptor, config) { if (key === undefined) { target = target.prototype; key = typeof config === 'string' ? config : config.name; } var innerPropertyName = '_' + key; var callbackName = config && config.changeHandler || key + 'Changed'; if (descriptor) { if (typeof descriptor.initializer === 'function') { target[innerPropertyName] = descriptor.initializer(); } } else { descriptor = {}; } delete descriptor.writable; delete descriptor.initializer; descriptor.get = function () { return this[innerPropertyName]; }; descriptor.set = function (newValue) { var oldValue = this[innerPropertyName]; this[innerPropertyName] = newValue; if (this[callbackName]) { this[callbackName](newValue, oldValue, key); } }; descriptor.get.dependencies = [innerPropertyName]; Reflect.defineProperty(target, key, descriptor); } if (key === undefined) { return function (t, k, d) { return deco(t, k, d, targetOrConfig); }; } return deco(targetOrConfig, key, descriptor); } _export('observable', observable); return { setters: [function (_aureliaLogging) { LogManager = _aureliaLogging; }, function (_aureliaPal) { PLATFORM = _aureliaPal.PLATFORM; DOM = _aureliaPal.DOM; }, function (_aureliaTaskQueue) { TaskQueue = _aureliaTaskQueue.TaskQueue; }, function (_aureliaMetadata) { metadata = _aureliaMetadata.metadata; }], execute: function () { _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; }; _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); map = Object.create(null); _export('sourceContext', sourceContext = 'Binding:source'); _export('sourceContext', sourceContext); slotNames = []; versionSlotNames = []; for (i = 0; i < 100; i++) { slotNames.push('_observer' + i); versionSlotNames.push('_observerVersion' + i); }bindings = new Map(); minimumImmediate = 100; frameBudget = 15; isFlushRequested = false; immediate = 0; arrayPool1 = []; arrayPool2 = []; poolUtilization = []; _export('ExpressionObserver', ExpressionObserver = (_dec = connectable(), _dec2 = subscriberCollection(), _dec(_class = _dec2(_class = function () { function ExpressionObserver(scope, expression, observerLocator, lookupFunctions) { this.scope = scope; this.expression = expression; this.observerLocator = observerLocator; this.lookupFunctions = lookupFunctions; } ExpressionObserver.prototype.getValue = function getValue() { return this.expression.evaluate(this.scope, this.lookupFunctions); }; ExpressionObserver.prototype.setValue = function setValue(newValue) { this.expression.assign(this.scope, newValue); }; ExpressionObserver.prototype.subscribe = function subscribe(context, callable) { var _this = this; if (!this.hasSubscribers()) { this.oldValue = this.expression.evaluate(this.scope, this.lookupFunctions); this.expression.connect(this, this.scope); } this.addSubscriber(context, callable); if (arguments.length === 1 && context instanceof Function) { return { dispose: function dispose() { _this.unsubscribe(context, callable); } }; } }; ExpressionObserver.prototype.unsubscribe = function unsubscribe(context, callable) { if (this.removeSubscriber(context, callable) && !this.hasSubscribers()) { this.unobserve(true); this.oldValue = undefined; } }; ExpressionObserver.prototype.call = function call() { var newValue = this.expression.evaluate(this.scope, this.lookupFunctions); var oldValue = this.oldValue; if (newValue !== oldValue) { this.oldValue = newValue; this.callSubscribers(newValue, oldValue); } this._version++; this.expression.connect(this, this.scope); this.unobserve(false); }; return ExpressionObserver; }()) || _class) || _class)); _export('ExpressionObserver', ExpressionObserver); EDIT_LEAVE = 0; EDIT_UPDATE = 1; EDIT_ADD = 2; EDIT_DELETE = 3; ArraySplice.prototype = { calcEditDistances: function calcEditDistances(current, currentStart, currentEnd, old, oldStart, oldEnd) { var rowCount = oldEnd - oldStart + 1; var columnCount = currentEnd - currentStart + 1; var distances = new Array(rowCount); var north = void 0; var west = void 0; for (var _i = 0; _i < rowCount; ++_i) { distances[_i] = new Array(columnCount); distances[_i][0] = _i; } for (var j = 0; j < columnCount; ++j) { distances[0][j] = j; } for (var _i2 = 1; _i2 < rowCount; ++_i2) { for (var _j = 1; _j < columnCount; ++_j) { if (this.equals(current[currentStart + _j - 1], old[oldStart + _i2 - 1])) { distances[_i2][_j] = distances[_i2 - 1][_j - 1]; } else { north = distances[_i2 - 1][_j] + 1; west = distances[_i2][_j - 1] + 1; distances[_i2][_j] = north < west ? north : west; } } } return distances; }, spliceOperationsFromEditDistances: function spliceOperationsFromEditDistances(distances) { var i = distances.length - 1; var j = distances[0].length - 1; var current = distances[i][j]; var edits = []; while (i > 0 || j > 0) { if (i === 0) { edits.push(EDIT_ADD); j--; continue; } if (j === 0) { edits.push(EDIT_DELETE); i--; continue; } var northWest = distances[i - 1][j - 1]; var west = distances[i - 1][j]; var north = distances[i][j - 1]; var min = void 0; if (west < north) { min = west < northWest ? west : northWest; } else { min = north < northWest ? north : northWest; } if (min === northWest) { if (northWest === current) { edits.push(EDIT_LEAVE); } else { edits.push(EDIT_UPDATE); current = northWest; } i--; j--; } else if (min === west) { edits.push(EDIT_DELETE); i--; current = west; } else { edits.push(EDIT_ADD); j--; current = north; } } edits.reverse(); return edits; }, calcSplices: function calcSplices(current, currentStart, currentEnd, old, oldStart, oldEnd) { var prefixCount = 0; var suffixCount = 0; var minLength = Math.min(currentEnd - currentStart, oldEnd - oldStart); if (currentStart === 0 && oldStart === 0) { prefixCount = this.sharedPrefix(current, old, minLength); } if (currentEnd === current.length && oldEnd === old.length) { suffixCount = this.sharedSuffix(current, old, minLength - prefixCount); } currentStart += prefixCount; oldStart += prefixCount; currentEnd -= suffixCount; oldEnd -= suffixCount; if (currentEnd - currentStart === 0 && oldEnd - oldStart === 0) { return []; } if (currentStart === currentEnd) { var _splice = newSplice(currentStart, [], 0); while (oldStart < oldEnd) { _splice.removed.push(old[oldStart++]); } return [_splice]; } else if (oldStart === oldEnd) { return [newSplice(currentStart, [], currentEnd - currentStart)]; } var ops = this.spliceOperationsFromEditDistances(this.calcEditDistances(current, currentStart, currentEnd, old, oldStart, oldEnd)); var splice = undefined; var splices = []; var index = currentStart; var oldIndex = oldStart; for (var _i3 = 0; _i3 < ops.length; ++_i3) { switch (ops[_i3]) { case EDIT_LEAVE: if (splice) { splices.push(splice); splice = undefined; } index++; oldIndex++; break; case EDIT_UPDATE: if (!splice) { splice = newSplice(index, [], 0); } splice.addedCount++; index++; splice.removed.push(old[oldIndex]); oldIndex++; break; case EDIT_ADD: if (!splice) { splice = newSplice(index, [], 0); } splice.addedCount++; index++; break; case EDIT_DELETE: if (!splice) { splice = newSplice(index, [], 0); } splice.removed.push(old[oldIndex]); oldIndex++; break; } } if (splice) { splices.push(splice); } return splices; }, sharedPrefix: function sharedPrefix(current, old, searchLength) { for (var _i4 = 0; _i4 < searchLength; ++_i4) { if (!this.equals(current[_i4], old[_i4])) { return _i4; } } return searchLength; }, sharedSuffix: function sharedSuffix(current, old, searchLength) { var index1 = current.length; var index2 = old.length; var count = 0; while (count < searchLength && this.equals(current[--index1], old[--index2])) { count++; } return count; }, calculateSplices: function calculateSplices(current, previous) { return this.calcSplices(current, 0, current.length, previous, 0, previous.length); }, equals: function equals(currentValue, previousValue) { return currentValue === previousValue; } }; arraySplice = new ArraySplice(); _export('ModifyCollectionObserver', ModifyCollectionObserver = (_dec3 = subscriberCollection(), _dec3(_class2 = function () { function ModifyCollectionObserver(taskQueue, collection) { this.taskQueue = taskQueue; this.queued = false; this.changeRecords = null; this.oldCollection = null; this.collection = collection; this.lengthPropertyName = collection instanceof Map || collection instanceof Set ? 'size' : 'length'; } ModifyCollectionObserver.prototype.subscribe = function subscribe(context, callable) { this.addSubscriber(context, callable); }; ModifyCollectionObserver.prototype.unsubscribe = function unsubscribe(context, callable) { this.removeSubscriber(context, callable); }; ModifyCollectionObserver.prototype.addChangeRecord = function addChangeRecord(changeRecord) { if (!this.hasSubscribers() && !this.lengthObserver) { return; } if (changeRecord.type === 'splice') { var index = changeRecord.index; var arrayLength = changeRecord.object.length; if (index > arrayLength) { index = arrayLength - changeRecord.addedCount; } else if (index < 0) { index = arrayLength + changeRecord.removed.length + index - changeRecord.addedCount; } if (index < 0) { index = 0; } changeRecord.index = index; } if (this.changeRecords === null) { this.changeRecords = [changeRecord]; } else { this.changeRecords.push(changeRecord); } if (!this.queued) { this.queued = true; this.taskQueue.queueMicroTask(this); } }; ModifyCollectionObserver.prototype.flushChangeRecords = function flushChangeRecords() { if (this.changeRecords && this.changeRecords.length || this.oldCollection) { this.call(); } }; ModifyCollectionObserver.prototype.reset = function reset(oldCollection) { this.oldCollection = oldCollection; if (this.hasSubscribers() && !this.queued) { this.queued = true; this.taskQueue.queueMicroTask(this); } }; ModifyCollectionObserver.prototype.getLengthObserver = function getLengthObserver() { return this.lengthObserver || (this.lengthObserver = new CollectionLengthObserver(this.collection)); }; ModifyCollectionObserver.prototype.call = function call() { var changeRecords = this.changeRecords; var oldCollection = this.oldCollection; var records = void 0; this.queued = false; this.changeRecords = []; this.oldCollection = null; if (this.hasSubscribers()) { if (oldCollection) { if (this.collection instanceof Map || this.collection instanceof Set) { records = getChangeRecords(oldCollection); } else { records = calcSplices(this.collection, 0, this.collection.length, oldCollection, 0, oldCollection.length); } } else { if (this.collection instanceof Map || this.collection instanceof Set) { records = changeRecords; } else { records = projectArraySplices(this.collection, changeRecords); } } this.callSubscribers(records); } if (this.lengthObserver) { this.lengthObserver.call(this.collection[this.lengthPropertyName]); } }; return ModifyCollectionObserver; }()) || _class2)); _export('ModifyCollectionObserver', ModifyCollectionObserver); _export('CollectionLengthObserver', CollectionLengthObserver = (_dec4 = subscriberCollection(), _dec4(_class3 = function () { function CollectionLengthObserver(collection) { this.collection = collection; this.lengthPropertyName = collection instanceof Map || collection instanceof Set ? 'size' : 'length'; this.currentValue = collection[this.lengthPropertyName]; } CollectionLengthObserver.prototype.getValue = function getValue() { return this.collection[this.lengthPropertyName]; }; CollectionLengthObserver.prototype.setValue = function setValue(newValue) { this.collection[this.lengthPropertyName] = newValue; }; CollectionLengthObserver.prototype.subscribe = function subscribe(context, callable) { this.addSubscriber(context, callable); }; CollectionLengthObserver.prototype.unsubscribe = function unsubscribe(context, callable) { this.removeSubscriber(context, callable); }; CollectionLengthObserver.prototype.call = function call(newValue) { var oldValue = this.currentValue; this.callSubscribers(newValue, oldValue); this.currentValue = newValue; }; return CollectionLengthObserver; }()) || _class3)); _export('CollectionLengthObserver', CollectionLengthObserver); pop = Array.prototype.pop; push = Array.prototype.push; reverse = Array.prototype.reverse; shift = Array.prototype.shift; sort = Array.prototype.sort; splice = Array.prototype.splice; unshift = Array.prototype.unshift; Array.prototype.pop = function () { var notEmpty = this.length > 0; var methodCallResult = pop.apply(this, arguments); if (notEmpty && this.__array_observer__ !== undefined) { this.__array_observer__.addChangeRecord({ type: 'delete', object: this, name: this.length, oldValue: methodCallResult }); } return methodCallResult; }; Array.prototype.push = function () { var methodCallResult = push.apply(this, arguments); if (this.__array_observer__ !== undefined) { this.__array_observer__.addChangeRecord({ type: 'splice', object: this, index: this.length - arguments.length, removed: [], addedCount: arguments.length }); } return methodCallResult; }; Array.prototype.reverse = function () { var oldArray = void 0; if (this.__array_observer__ !== undefined) { this.__array_observer__.flushChangeRecords(); oldArray = this.slice(); } var methodCallResult = reverse.apply(this, arguments); if (this.__array_observer__ !== undefined) { this.__array_observer__.reset(oldArray); } return methodCallResult; }; Array.prototype.shift = function () { var notEmpty = this.length > 0; var methodCallResult = shift.apply(this, arguments); if (notEmpty && this.__array_observer__ !== undefined) { this.__array_observer__.addChangeRecord({ type: 'delete', object: this, name: 0, oldValue: methodCallResult }); } return methodCallResult; }; Array.prototype.sort = function () { var oldArray = void 0; if (this.__array_observer__ !== undefined) { this.__array_observer__.flushChangeRecords(); oldArray = this.slice(); } var methodCallResult = sort.apply(this, arguments); if (this.__array_observer__ !== undefined) { this.__array_observer__.reset(oldArray); } return methodCallResult; }; Array.prototype.splice = function () { var methodCallResult = splice.apply(this, arguments); if (this.__array_observer__ !== undefined) { this.__array_observer__.addChangeRecord({ type: 'splice', object: this, index: arguments[0], removed: methodCallResult, addedCount: arguments.length > 2 ? arguments.length - 2 : 0 }); } return methodCallResult; }; Array.prototype.unshift = function () { var methodCallResult = unshift.apply(this, arguments); if (this.__array_observer__ !== undefined) { this.__array_observer__.addChangeRecord({ type: 'splice', object: this, index: 0, removed: [], addedCount: arguments.length }); } return methodCallResult; }; _export('getArrayObserver', _getArrayObserver); ModifyArrayObserver = function (_ModifyCollectionObse) { _inherits(ModifyArrayObserver, _ModifyCollectionObse); function ModifyArrayObserver(taskQueue, array) { return _possibleConstructorReturn(this, _ModifyCollectionObse.call(this, taskQueue, array)); } ModifyArrayObserver.for = function _for(taskQueue, array) { if (!('__array_observer__' in array)) { Reflect.defineProperty(array, '__array_observer__', { value: ModifyArrayObserver.create(taskQueue, array), enumerable: false, configurable: false }); } return array.__array_observer__; }; ModifyArrayObserver.create = function create(taskQueue, array) { return new ModifyArrayObserver(taskQueue, array); }; return ModifyArrayObserver; }(ModifyCollectionObserver); _export('Expression', Expression = function () { function Expression() { this.isChain = false; this.isAssignable = false; } Expression.prototype.evaluate = function evaluate(scope, lookupFunctions, args) { throw new Error('Binding expression "' + this + '" cannot be evaluated.'); }; Expression.prototype.assign = function assign(scope, value, lookupFunctions) { throw new Error('Binding expression "' + this + '" cannot be assigned to.'); }; Expression.prototype.toString = function toString() { return Unparser.unparse(this); }; return Expression; }()); _export('Expression', Expression); _export('Chain', Chain = function (_Expression) { _inherits(Chain, _Expression); function Chain(expressions) { var _this3 = _possibleConstructorReturn(this, _Expression.call(this)); _this3.expressions = expressions; _this3.isChain = true; return _this3; } Chain.prototype.evaluate = function evaluate(scope, lookupFunctions) { var result = void 0; var expressions = this.expressions; var last = void 0; for (var _i7 = 0, length = expressions.length; _i7 < length; ++_i7) { last = expressions[_i7].evaluate(scope, lookupFunctions); if (last !== null) { result = last; } } return result; }; Chain.prototype.accept = function accept(visitor) { return visitor.visitChain(this); }; return Chain; }(Expression)); _export('Chain', Chain); _export('BindingBehavior', BindingBehavior = function (_Expression2) { _inherits(BindingBehavior, _Expression2); function BindingBehavior(expression, name, args) { var _this4 = _possibleConstructorReturn(this, _Expression2.call(this)); _this4.expression = expression; _this4.name = name; _this4.args = args; return _this4; } BindingBehavior.prototype.evaluate = function evaluate(scope, lookupFunctions) { return this.expression.evaluate(scope, lookupFunctions); }; BindingBehavior.prototype.assign = function assign(scope, value, lookupFunctions) { return this.expression.assign(scope, value, lookupFunctions); }; BindingBehavior.prototype.accept = function accept(visitor) { return visitor.visitBindingBehavior(this); }; BindingBehavior.prototype.connect = function connect(binding, scope) { this.expression.connect(binding, scope); }; BindingBehavior.prototype.bind = function bind(binding, scope, lookupFunctions) { if (this.expression.expression && this.expression.bind) { this.expression.bind(binding, scope, lookupFunctions); } var behavior = lookupFunctions.bindingBehaviors(this.name); if (!behavior) { throw new Error('No BindingBehavior named "' + this.name + '" was found!'); } var behaviorKey = 'behavior-' + this.name; if (binding[behaviorKey]) { throw new Error('A binding behavior named "' + this.name + '" has already been applied to "' + this.expression + '"'); } binding[behaviorKey] = behavior; behavior.bind.apply(behavior, [binding, scope].concat(evalList(scope, this.args, binding.lookupFunctions))); }; BindingBehavior.prototype.unbind = function unbind(binding, scope) { var behaviorKey = 'behavior-' + this.name; binding[behaviorKey].unbind(binding, scope); binding[behaviorKey] = null; if (this.expression.expression && this.expression.unbind) { this.expression.unbind(binding, scope); } }; return BindingBehavior; }(Expression)); _export('BindingBehavior', BindingBehavior); _export('ValueConverter', ValueConverter = function (_Expression3) { _inherits(ValueConverter, _Expression3); function ValueConverter(expression, name, args, allArgs) { var _this5 = _possibleConstructorReturn(this, _Expression3.call(this)); _this5.expression = expression; _this5.name = name; _this5.args = args; _this5.allArgs = allArgs; return _this5; } ValueConverter.prototype.evaluate = function evaluate(scope, lookupFunctions) { var converter = lookupFunctions.valueConverters(this.name); if (!converter) { throw new Error('No ValueConverter named "' + this.name + '" was found!'); } if ('toView' in converter) { return converter.toView.apply(converter, evalList(scope, this.allArgs, lookupFunctions)); } return t