UNPKG

@danielkalen/simplybind

Version:

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

1,493 lines (1,141 loc) 170 kB
'use strict'; System.register(['aurelia-logging', 'aurelia-metadata', 'aurelia-pal', 'aurelia-path', 'aurelia-loader', 'aurelia-dependency-injection', 'aurelia-binding', 'aurelia-task-queue'], function (_export, _context) { "use strict"; var LogManager, metadata, Origin, protocol, DOM, PLATFORM, FEATURE, relativeToFile, TemplateRegistryEntry, Loader, inject, Container, resolver, Binding, createOverrideContext, ValueConverterResource, BindingBehaviorResource, subscriberCollection, bindingMode, ObserverLocator, EventManager, TaskQueue, _createClass, _class4, _temp, _dec, _class5, _dec2, _class6, _dec3, _class7, _dec4, _class8, _dec5, _class9, _class10, _temp2, _dec6, _class11, _class12, _temp3, _class15, _dec7, _class17, _dec8, _class18, _class19, _temp4, _dec9, _class21, _dec10, _class22, _dec11, _class23, _typeof, animationEvent, Animator, CompositionTransactionNotifier, CompositionTransactionOwnershipToken, CompositionTransaction, capitalMatcher, ViewEngineHooksResource, ElementEvents, ResourceLoadContext, ViewCompileInstruction, BehaviorInstruction, TargetInstruction, viewStrategy, RelativeViewStrategy, ConventionalViewStrategy, NoViewStrategy, TemplateRegistryViewStrategy, InlineViewStrategy, ViewLocator, BindingLanguage, noNodes, SlotCustomAttribute, PassThroughSlot, ShadowSlot, ShadowDOM, ViewResources, View, ViewSlot, ProviderResolver, providerResolverInstance, BoundViewFactory, ViewFactory, nextInjectorId, lastAUTargetID, ViewCompiler, ResourceModule, ResourceDescription, ModuleAnalyzer, logger, ProxyViewFactory, ViewEngine, Controller, BehaviorPropertyObserver, BindableProperty, lastProviderId, HtmlBehaviorResource, ChildObserver, noMutations, ChildObserverBinder, CompositionEngine, ElementConfigResource, defaultShadowDOMOptions, TemplatingEngine; function addHyphenAndLower(char) { return '-' + char.toLowerCase(); } function _hyphenate(name) { return (name.charAt(0).toLowerCase() + name.slice(1)).replace(capitalMatcher, addHyphenAndLower); } _export('_hyphenate', _hyphenate); function _isAllWhitespace(node) { return !(node.auInterpolationTarget || /[^\t\n\r ]/.test(node.textContent)); } _export('_isAllWhitespace', _isAllWhitespace); function viewEngineHooks(target) { var deco = function deco(t) { metadata.define(metadata.resource, new ViewEngineHooksResource(), t); }; return target ? deco(target) : deco; } _export('viewEngineHooks', viewEngineHooks); function mi(name) { throw new Error('BindingLanguage must implement ' + name + '().'); } function register(lookup, name, resource, type) { if (!name) { return; } var existing = lookup[name]; if (existing) { if (existing !== resource) { throw new Error('Attempted to register ' + type + ' when one with the same name already exists. Name: ' + name + '.'); } return; } lookup[name] = resource; } function getAnimatableElement(view) { if (view.animatableElement !== undefined) { return view.animatableElement; } var current = view.firstChild; while (current && current.nodeType !== 1) { current = current.nextSibling; } if (current && current.nodeType === 1) { return view.animatableElement = current.classList.contains('au-animate') ? current : null; } return view.animatableElement = null; } function elementContainerGet(key) { if (key === DOM.Element) { return this.element; } if (key === BoundViewFactory) { if (this.boundViewFactory) { return this.boundViewFactory; } var factory = this.instruction.viewFactory; var _partReplacements = this.partReplacements; if (_partReplacements) { factory = _partReplacements[factory.part] || factory; } this.boundViewFactory = new BoundViewFactory(this, factory, _partReplacements); return this.boundViewFactory; } if (key === ViewSlot) { if (this.viewSlot === undefined) { this.viewSlot = new ViewSlot(this.element, this.instruction.anchorIsContainer); this.element.isContentProjectionSource = this.instruction.lifting; this.children.push(this.viewSlot); } return this.viewSlot; } if (key === ElementEvents) { return this.elementEvents || (this.elementEvents = new ElementEvents(this.element)); } if (key === CompositionTransaction) { return this.compositionTransaction || (this.compositionTransaction = this.parent.get(key)); } if (key === ViewResources) { return this.viewResources; } if (key === TargetInstruction) { return this.instruction; } return this.superGet(key); } function createElementContainer(parent, element, instruction, children, partReplacements, resources) { var container = parent.createChild(); var providers = void 0; var i = void 0; container.element = element; container.instruction = instruction; container.children = children; container.viewResources = resources; container.partReplacements = partReplacements; providers = instruction.providers; i = providers.length; while (i--) { container._resolvers.set(providers[i], providerResolverInstance); } container.superGet = container.get; container.get = elementContainerGet; return container; } function makeElementIntoAnchor(element, elementInstruction) { var anchor = DOM.createComment('anchor'); if (elementInstruction) { var firstChild = element.firstChild; if (firstChild && firstChild.tagName === 'AU-CONTENT') { anchor.contentElement = firstChild; } anchor.hasAttribute = function (name) { return element.hasAttribute(name); }; anchor.getAttribute = function (name) { return element.getAttribute(name); }; anchor.setAttribute = function (name, value) { element.setAttribute(name, value); }; } DOM.replaceNode(anchor, element); return anchor; } function applyInstructions(containers, element, instruction, controllers, bindings, children, shadowSlots, partReplacements, resources) { var behaviorInstructions = instruction.behaviorInstructions; var expressions = instruction.expressions; var elementContainer = void 0; var i = void 0; var ii = void 0; var current = void 0; var instance = void 0; if (instruction.contentExpression) { bindings.push(instruction.contentExpression.createBinding(element.nextSibling)); element.nextSibling.auInterpolationTarget = true; element.parentNode.removeChild(element); return; } if (instruction.shadowSlot) { var commentAnchor = DOM.createComment('slot'); var slot = void 0; if (instruction.slotDestination) { slot = new PassThroughSlot(commentAnchor, instruction.slotName, instruction.slotDestination, instruction.slotFallbackFactory); } else { slot = new ShadowSlot(commentAnchor, instruction.slotName, instruction.slotFallbackFactory); } DOM.replaceNode(commentAnchor, element); shadowSlots[instruction.slotName] = slot; controllers.push(slot); return; } if (behaviorInstructions.length) { if (!instruction.anchorIsContainer) { element = makeElementIntoAnchor(element, instruction.elementInstruction); } containers[instruction.injectorId] = elementContainer = createElementContainer(containers[instruction.parentInjectorId], element, instruction, children, partReplacements, resources); for (i = 0, ii = behaviorInstructions.length; i < ii; ++i) { current = behaviorInstructions[i]; instance = current.type.create(elementContainer, current, element, bindings); controllers.push(instance); } } for (i = 0, ii = expressions.length; i < ii; ++i) { bindings.push(expressions[i].createBinding(element)); } } function styleStringToObject(style, target) { var attributes = style.split(';'); var firstIndexOfColon = void 0; var i = void 0; var current = void 0; var key = void 0; var value = void 0; target = target || {}; for (i = 0; i < attributes.length; i++) { current = attributes[i]; firstIndexOfColon = current.indexOf(':'); key = current.substring(0, firstIndexOfColon).trim(); value = current.substring(firstIndexOfColon + 1).trim(); target[key] = value; } return target; } function styleObjectToString(obj) { var result = ''; for (var key in obj) { result += key + ':' + obj[key] + ';'; } return result; } function applySurrogateInstruction(container, element, instruction, controllers, bindings, children) { var behaviorInstructions = instruction.behaviorInstructions; var expressions = instruction.expressions; var providers = instruction.providers; var values = instruction.values; var i = void 0; var ii = void 0; var current = void 0; var instance = void 0; var currentAttributeValue = void 0; i = providers.length; while (i--) { container._resolvers.set(providers[i], providerResolverInstance); } for (var key in values) { currentAttributeValue = element.getAttribute(key); if (currentAttributeValue) { if (key === 'class') { element.setAttribute('class', currentAttributeValue + ' ' + values[key]); } else if (key === 'style') { var styleObject = styleStringToObject(values[key]); styleStringToObject(currentAttributeValue, styleObject); element.setAttribute('style', styleObjectToString(styleObject)); } } else { element.setAttribute(key, values[key]); } } if (behaviorInstructions.length) { for (i = 0, ii = behaviorInstructions.length; i < ii; ++i) { current = behaviorInstructions[i]; instance = current.type.create(container, current, element, bindings); if (instance.contentView) { children.push(instance.contentView); } controllers.push(instance); } } for (i = 0, ii = expressions.length; i < ii; ++i) { bindings.push(expressions[i].createBinding(element)); } } function getNextInjectorId() { return ++nextInjectorId; } function configureProperties(instruction, resources) { var type = instruction.type; var attrName = instruction.attrName; var attributes = instruction.attributes; var property = void 0; var key = void 0; var value = void 0; var knownAttribute = resources.mapAttribute(attrName); if (knownAttribute && attrName in attributes && knownAttribute !== attrName) { attributes[knownAttribute] = attributes[attrName]; delete attributes[attrName]; } for (key in attributes) { value = attributes[key]; if (value !== null && (typeof value === 'undefined' ? 'undefined' : _typeof(value)) === 'object') { property = type.attributes[key]; if (property !== undefined) { value.targetProperty = property.name; } else { value.targetProperty = key; } } } } function getNextAUTargetID() { return (++lastAUTargetID).toString(); } function makeIntoInstructionTarget(element) { var value = element.getAttribute('class'); var auTargetID = getNextAUTargetID(); element.setAttribute('class', value ? value += ' au-target' : 'au-target'); element.setAttribute('au-target-id', auTargetID); return auTargetID; } function makeShadowSlot(compiler, resources, node, instructions, parentInjectorId) { var auShadowSlot = DOM.createElement('au-shadow-slot'); DOM.replaceNode(auShadowSlot, node); var auTargetID = makeIntoInstructionTarget(auShadowSlot); var instruction = TargetInstruction.shadowSlot(parentInjectorId); instruction.slotName = node.getAttribute('name') || ShadowDOM.defaultSlotKey; instruction.slotDestination = node.getAttribute('slot'); if (node.innerHTML.trim()) { var fragment = DOM.createDocumentFragment(); var _child3 = void 0; while (_child3 = node.firstChild) { fragment.appendChild(_child3); } instruction.slotFallbackFactory = compiler.compile(fragment, resources); } instructions[auTargetID] = instruction; return auShadowSlot; } function ensureRegistryEntry(loader, urlOrRegistryEntry) { if (urlOrRegistryEntry instanceof TemplateRegistryEntry) { return Promise.resolve(urlOrRegistryEntry); } return loader.loadTemplate(urlOrRegistryEntry); } function getObserver(behavior, instance, name) { var lookup = instance.__observers__; if (lookup === undefined) { if (!behavior.isInitialized) { behavior.initialize(Container.instance || new Container(), instance.constructor); } lookup = behavior.observerLocator.getOrCreateObserversLookup(instance); behavior._ensurePropertiesDefined(instance, lookup); } return lookup[name]; } function nextProviderId() { return ++lastProviderId; } function doProcessContent() { return true; } function doProcessAttributes() {} function createChildObserverDecorator(selectorOrConfig, all) { return function (target, key, descriptor) { var actualTarget = typeof key === 'string' ? target.constructor : target; var r = metadata.getOrCreateOwn(metadata.resource, HtmlBehaviorResource, actualTarget); if (typeof selectorOrConfig === 'string') { selectorOrConfig = { selector: selectorOrConfig, name: key }; } if (descriptor) { descriptor.writable = true; } selectorOrConfig.all = all; r.addChildBinding(new ChildObserver(selectorOrConfig)); }; } function children(selectorOrConfig) { return createChildObserverDecorator(selectorOrConfig, true); } _export('children', children); function child(selectorOrConfig) { return createChildObserverDecorator(selectorOrConfig, false); } _export('child', child); function trackMutation(groupedMutations, binder, record) { var mutations = groupedMutations.get(binder); if (!mutations) { mutations = []; groupedMutations.set(binder, mutations); } mutations.push(record); } function onChildChange(mutations, observer) { var binders = observer.binders; var bindersLength = binders.length; var groupedMutations = new Map(); for (var i = 0, ii = mutations.length; i < ii; ++i) { var record = mutations[i]; var added = record.addedNodes; var removed = record.removedNodes; for (var j = 0, jj = removed.length; j < jj; ++j) { var node = removed[j]; if (node.nodeType === 1) { for (var k = 0; k < bindersLength; ++k) { var binder = binders[k]; if (binder.onRemove(node)) { trackMutation(groupedMutations, binder, record); } } } } for (var _j = 0, _jj = added.length; _j < _jj; ++_j) { var _node = added[_j]; if (_node.nodeType === 1) { for (var _k = 0; _k < bindersLength; ++_k) { var _binder = binders[_k]; if (_binder.onAdd(_node)) { trackMutation(groupedMutations, _binder, record); } } } } } groupedMutations.forEach(function (value, key) { if (key.changeHandler !== null) { key.viewModel[key.changeHandler](value); } }); } function tryActivateViewModel(context) { if (context.skipActivation || typeof context.viewModel.activate !== 'function') { return Promise.resolve(); } return context.viewModel.activate(context.model) || Promise.resolve(); } function validateBehaviorName(name, type) { if (/[A-Z]/.test(name)) { var newName = _hyphenate(name); LogManager.getLogger('templating').warn('\'' + name + '\' is not a valid ' + type + ' name and has been converted to \'' + newName + '\'. Upper-case letters are not allowed because the DOM is not case-sensitive.'); return newName; } return name; } function resource(instance) { return function (target) { metadata.define(metadata.resource, instance, target); }; } _export('resource', resource); function behavior(override) { return function (target) { if (override instanceof HtmlBehaviorResource) { metadata.define(metadata.resource, override, target); } else { var r = metadata.getOrCreateOwn(metadata.resource, HtmlBehaviorResource, target); Object.assign(r, override); } }; } _export('behavior', behavior); function customElement(name) { return function (target) { var r = metadata.getOrCreateOwn(metadata.resource, HtmlBehaviorResource, target); r.elementName = validateBehaviorName(name, 'custom element'); }; } _export('customElement', customElement); function customAttribute(name, defaultBindingMode) { return function (target) { var r = metadata.getOrCreateOwn(metadata.resource, HtmlBehaviorResource, target); r.attributeName = validateBehaviorName(name, 'custom attribute'); r.attributeDefaultBindingMode = defaultBindingMode; }; } _export('customAttribute', customAttribute); function templateController(target) { var deco = function deco(t) { var r = metadata.getOrCreateOwn(metadata.resource, HtmlBehaviorResource, t); r.liftsContent = true; }; return target ? deco(target) : deco; } _export('templateController', templateController); function bindable(nameOrConfigOrTarget, key, descriptor) { var deco = function deco(target, key2, descriptor2) { var actualTarget = key2 ? target.constructor : target; var r = metadata.getOrCreateOwn(metadata.resource, HtmlBehaviorResource, actualTarget); var prop = void 0; if (key2) { nameOrConfigOrTarget = nameOrConfigOrTarget || {}; nameOrConfigOrTarget.name = key2; } prop = new BindableProperty(nameOrConfigOrTarget); return prop.registerWith(actualTarget, r, descriptor2); }; if (!nameOrConfigOrTarget) { return deco; } if (key) { var _target = nameOrConfigOrTarget; nameOrConfigOrTarget = null; return deco(_target, key, descriptor); } return deco; } _export('bindable', bindable); function dynamicOptions(target) { var deco = function deco(t) { var r = metadata.getOrCreateOwn(metadata.resource, HtmlBehaviorResource, t); r.hasDynamicOptions = true; }; return target ? deco(target) : deco; } _export('dynamicOptions', dynamicOptions); function useShadowDOM(targetOrOptions) { var options = typeof targetOrOptions === 'function' || !targetOrOptions ? defaultShadowDOMOptions : targetOrOptions; var deco = function deco(t) { var r = metadata.getOrCreateOwn(metadata.resource, HtmlBehaviorResource, t); r.targetShadowDOM = true; r.shadowDOMOptions = options; }; return typeof targetOrOptions === 'function' ? deco(targetOrOptions) : deco; } _export('useShadowDOM', useShadowDOM); function processAttributes(processor) { return function (t) { var r = metadata.getOrCreateOwn(metadata.resource, HtmlBehaviorResource, t); r.processAttributes = function (compiler, resources, node, attributes, elementInstruction) { try { processor(compiler, resources, node, attributes, elementInstruction); } catch (error) { LogManager.getLogger('templating').error(error); } }; }; } _export('processAttributes', processAttributes); function doNotProcessContent() { return false; } function processContent(processor) { return function (t) { var r = metadata.getOrCreateOwn(metadata.resource, HtmlBehaviorResource, t); r.processContent = processor ? function (compiler, resources, node, instruction) { try { return processor(compiler, resources, node, instruction); } catch (error) { LogManager.getLogger('templating').error(error); return false; } } : doNotProcessContent; }; } _export('processContent', processContent); function containerless(target) { var deco = function deco(t) { var r = metadata.getOrCreateOwn(metadata.resource, HtmlBehaviorResource, t); r.containerless = true; }; return target ? deco(target) : deco; } _export('containerless', containerless); function useViewStrategy(strategy) { return function (target) { metadata.define(ViewLocator.viewStrategyMetadataKey, strategy, target); }; } _export('useViewStrategy', useViewStrategy); function useView(path) { return useViewStrategy(new RelativeViewStrategy(path)); } _export('useView', useView); function inlineView(markup, dependencies, dependencyBaseUrl) { return useViewStrategy(new InlineViewStrategy(markup, dependencies, dependencyBaseUrl)); } _export('inlineView', inlineView); function noView(targetOrDependencies, dependencyBaseUrl) { var target = void 0; var dependencies = void 0; if (typeof targetOrDependencies === 'function') { target = targetOrDependencies; } else { dependencies = targetOrDependencies; target = undefined; } var deco = function deco(t) { metadata.define(ViewLocator.viewStrategyMetadataKey, new NoViewStrategy(dependencies, dependencyBaseUrl), t); }; return target ? deco(target) : deco; } _export('noView', noView); function elementConfig(target) { var deco = function deco(t) { metadata.define(metadata.resource, new ElementConfigResource(), t); }; return target ? deco(target) : deco; } _export('elementConfig', elementConfig); function viewResources() { return function (target) { metadata.define(ViewEngine.viewModelRequireMetadataKey, resources, target); }; } _export('viewResources', viewResources); return { setters: [function (_aureliaLogging) { LogManager = _aureliaLogging; }, function (_aureliaMetadata) { metadata = _aureliaMetadata.metadata; Origin = _aureliaMetadata.Origin; protocol = _aureliaMetadata.protocol; }, function (_aureliaPal) { DOM = _aureliaPal.DOM; PLATFORM = _aureliaPal.PLATFORM; FEATURE = _aureliaPal.FEATURE; }, function (_aureliaPath) { relativeToFile = _aureliaPath.relativeToFile; }, function (_aureliaLoader) { TemplateRegistryEntry = _aureliaLoader.TemplateRegistryEntry; Loader = _aureliaLoader.Loader; }, function (_aureliaDependencyInjection) { inject = _aureliaDependencyInjection.inject; Container = _aureliaDependencyInjection.Container; resolver = _aureliaDependencyInjection.resolver; }, function (_aureliaBinding) { Binding = _aureliaBinding.Binding; createOverrideContext = _aureliaBinding.createOverrideContext; ValueConverterResource = _aureliaBinding.ValueConverterResource; BindingBehaviorResource = _aureliaBinding.BindingBehaviorResource; subscriberCollection = _aureliaBinding.subscriberCollection; bindingMode = _aureliaBinding.bindingMode; ObserverLocator = _aureliaBinding.ObserverLocator; EventManager = _aureliaBinding.EventManager; }, function (_aureliaTaskQueue) { TaskQueue = _aureliaTaskQueue.TaskQueue; }], execute: function () { _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; }; }(); _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; }; _export('animationEvent', animationEvent = { enterBegin: 'animation:enter:begin', enterActive: 'animation:enter:active', enterDone: 'animation:enter:done', enterTimeout: 'animation:enter:timeout', leaveBegin: 'animation:leave:begin', leaveActive: 'animation:leave:active', leaveDone: 'animation:leave:done', leaveTimeout: 'animation:leave:timeout', staggerNext: 'animation:stagger:next', removeClassBegin: 'animation:remove-class:begin', removeClassActive: 'animation:remove-class:active', removeClassDone: 'animation:remove-class:done', removeClassTimeout: 'animation:remove-class:timeout', addClassBegin: 'animation:add-class:begin', addClassActive: 'animation:add-class:active', addClassDone: 'animation:add-class:done', addClassTimeout: 'animation:add-class:timeout', animateBegin: 'animation:animate:begin', animateActive: 'animation:animate:active', animateDone: 'animation:animate:done', animateTimeout: 'animation:animate:timeout', sequenceBegin: 'animation:sequence:begin', sequenceDone: 'animation:sequence:done' }); _export('animationEvent', animationEvent); _export('Animator', Animator = function () { function Animator() { } Animator.prototype.enter = function enter(element) { return Promise.resolve(false); }; Animator.prototype.leave = function leave(element) { return Promise.resolve(false); }; Animator.prototype.removeClass = function removeClass(element, className) { element.classList.remove(className); return Promise.resolve(false); }; Animator.prototype.addClass = function addClass(element, className) { element.classList.add(className); return Promise.resolve(false); }; Animator.prototype.animate = function animate(element, className) { return Promise.resolve(false); }; Animator.prototype.runSequence = function runSequence(animations) {}; Animator.prototype.registerEffect = function registerEffect(effectName, properties) {}; Animator.prototype.unregisterEffect = function unregisterEffect(effectName) {}; return Animator; }()); _export('Animator', Animator); _export('CompositionTransactionNotifier', CompositionTransactionNotifier = function () { function CompositionTransactionNotifier(owner) { this.owner = owner; this.owner._compositionCount++; } CompositionTransactionNotifier.prototype.done = function done() { this.owner._compositionCount--; this.owner._tryCompleteTransaction(); }; return CompositionTransactionNotifier; }()); _export('CompositionTransactionNotifier', CompositionTransactionNotifier); _export('CompositionTransactionOwnershipToken', CompositionTransactionOwnershipToken = function () { function CompositionTransactionOwnershipToken(owner) { this.owner = owner; this.owner._ownershipToken = this; this.thenable = this._createThenable(); } CompositionTransactionOwnershipToken.prototype.waitForCompositionComplete = function waitForCompositionComplete() { this.owner._tryCompleteTransaction(); return this.thenable; }; CompositionTransactionOwnershipToken.prototype.resolve = function resolve() { this._resolveCallback(); }; CompositionTransactionOwnershipToken.prototype._createThenable = function _createThenable() { var _this = this; return new Promise(function (resolve, reject) { _this._resolveCallback = resolve; }); }; return CompositionTransactionOwnershipToken; }()); _export('CompositionTransactionOwnershipToken', CompositionTransactionOwnershipToken); _export('CompositionTransaction', CompositionTransaction = function () { function CompositionTransaction() { this._ownershipToken = null; this._compositionCount = 0; } CompositionTransaction.prototype.tryCapture = function tryCapture() { return this._ownershipToken === null ? new CompositionTransactionOwnershipToken(this) : null; }; CompositionTransaction.prototype.enlist = function enlist() { return new CompositionTransactionNotifier(this); }; CompositionTransaction.prototype._tryCompleteTransaction = function _tryCompleteTransaction() { if (this._compositionCount <= 0) { this._compositionCount = 0; if (this._ownershipToken !== null) { var token = this._ownershipToken; this._ownershipToken = null; token.resolve(); } } }; return CompositionTransaction; }()); _export('CompositionTransaction', CompositionTransaction); capitalMatcher = /([A-Z])/g; _export('ViewEngineHooksResource', ViewEngineHooksResource = function () { function ViewEngineHooksResource() { } ViewEngineHooksResource.prototype.initialize = function initialize(container, target) { this.instance = container.get(target); }; ViewEngineHooksResource.prototype.register = function register(registry, name) { registry.registerViewEngineHooks(this.instance); }; ViewEngineHooksResource.prototype.load = function load(container, target) {}; ViewEngineHooksResource.convention = function convention(name) { if (name.endsWith('ViewEngineHooks')) { return new ViewEngineHooksResource(); } }; return ViewEngineHooksResource; }()); _export('ViewEngineHooksResource', ViewEngineHooksResource); _export('ElementEvents', ElementEvents = function () { function ElementEvents(element) { this.element = element; this.subscriptions = {}; } ElementEvents.prototype._enqueueHandler = function _enqueueHandler(handler) { this.subscriptions[handler.eventName] = this.subscriptions[handler.eventName] || []; this.subscriptions[handler.eventName].push(handler); }; ElementEvents.prototype._dequeueHandler = function _dequeueHandler(handler) { var index = void 0; var subscriptions = this.subscriptions[handler.eventName]; if (subscriptions) { index = subscriptions.indexOf(handler); if (index > -1) { subscriptions.splice(index, 1); } } return handler; }; ElementEvents.prototype.publish = function publish(eventName) { var detail = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1]; var bubbles = arguments.length <= 2 || arguments[2] === undefined ? true : arguments[2]; var cancelable = arguments.length <= 3 || arguments[3] === undefined ? true : arguments[3]; var event = DOM.createCustomEvent(eventName, { cancelable: cancelable, bubbles: bubbles, detail: detail }); this.element.dispatchEvent(event); }; ElementEvents.prototype.subscribe = function subscribe(eventName, handler) { var _this2 = this; var bubbles = arguments.length <= 2 || arguments[2] === undefined ? true : arguments[2]; if (handler && typeof handler === 'function') { handler.eventName = eventName; handler.handler = handler; handler.bubbles = bubbles; handler.dispose = function () { _this2.element.removeEventListener(eventName, handler, bubbles); _this2._dequeueHandler(handler); }; this.element.addEventListener(eventName, handler, bubbles); this._enqueueHandler(handler); return handler; } return undefined; }; ElementEvents.prototype.subscribeOnce = function subscribeOnce(eventName, handler) { var _this3 = this; var bubbles = arguments.length <= 2 || arguments[2] === undefined ? true : arguments[2]; if (handler && typeof handler === 'function') { var _ret = function () { var _handler = function _handler(event) { handler(event); _handler.dispose(); }; return { v: _this3.subscribe(eventName, _handler, bubbles) }; }(); if ((typeof _ret === 'undefined' ? 'undefined' : _typeof(_ret)) === "object") return _ret.v; } return undefined; }; ElementEvents.prototype.dispose = function dispose(eventName) { if (eventName && typeof eventName === 'string') { var subscriptions = this.subscriptions[eventName]; if (subscriptions) { while (subscriptions.length) { var subscription = subscriptions.pop(); if (subscription) { subscription.dispose(); } } } } else { this.disposeAll(); } }; ElementEvents.prototype.disposeAll = function disposeAll() { for (var key in this.subscriptions) { this.dispose(key); } }; return ElementEvents; }()); _export('ElementEvents', ElementEvents); _export('ResourceLoadContext', ResourceLoadContext = function () { function ResourceLoadContext() { this.dependencies = {}; } ResourceLoadContext.prototype.addDependency = function addDependency(url) { this.dependencies[url] = true; }; ResourceLoadContext.prototype.hasDependency = function hasDependency(url) { return url in this.dependencies; }; return ResourceLoadContext; }()); _export('ResourceLoadContext', ResourceLoadContext); _export('ViewCompileInstruction', ViewCompileInstruction = function ViewCompileInstruction() { var targetShadowDOM = arguments.length <= 0 || arguments[0] === undefined ? false : arguments[0]; var compileSurrogate = arguments.length <= 1 || arguments[1] === undefined ? false : arguments[1]; this.targetShadowDOM = targetShadowDOM; this.compileSurrogate = compileSurrogate; this.associatedModuleId = null; }); _export('ViewCompileInstruction', ViewCompileInstruction); ViewCompileInstruction.normal = new ViewCompileInstruction(); _export('BehaviorInstruction', BehaviorInstruction = function () { BehaviorInstruction.enhance = function enhance() { var instruction = new BehaviorInstruction(); instruction.enhance = true; return instruction; }; BehaviorInstruction.unitTest = function unitTest(type, attributes) { var instruction = new BehaviorInstruction(); instruction.type = type; instruction.attributes = attributes || {}; return instruction; }; BehaviorInstruction.element = function element(node, type) { var instruction = new BehaviorInstruction(); instruction.type = type; instruction.attributes = {}; instruction.anchorIsContainer = !(node.hasAttribute('containerless') || type.containerless); instruction.initiatedByBehavior = true; return instruction; }; BehaviorInstruction.attribute = function attribute(attrName, type) { var instruction = new BehaviorInstruction(); instruction.attrName = attrName; instruction.type = type || null; instruction.attributes = {}; return instruction; }; BehaviorInstruction.dynamic = function dynamic(host, viewModel, viewFactory) { var instruction = new BehaviorInstruction(); instruction.host = host; instruction.viewModel = viewModel; instruction.viewFactory = viewFactory; instruction.inheritBindingContext = true; return instruction; }; function BehaviorInstruction() { this.initiatedByBehavior = false; this.enhance = false; this.partReplacements = null; this.viewFactory = null; this.originalAttrName = null; this.skipContentProcessing = false; this.contentFactory = null; this.viewModel = null; this.anchorIsContainer = false; this.host = null; this.attributes = null; this.type = null; this.attrName = null; this.inheritBindingContext = false; } return BehaviorInstruction; }()); _export('BehaviorInstruction', BehaviorInstruction); BehaviorInstruction.normal = new BehaviorInstruction(); _export('TargetInstruction', TargetInstruction = (_temp = _class4 = function () { TargetInstruction.shadowSlot = function shadowSlot(parentInjectorId) { var instruction = new TargetInstruction(); instruction.parentInjectorId = parentInjectorId; instruction.shadowSlot = true; return instruction; }; TargetInstruction.contentExpression = function contentExpression(expression) { var instruction = new TargetInstruction(); instruction.contentExpression = expression; return instruction; }; TargetInstruction.lifting = function lifting(parentInjectorId, liftingInstruction) { var instruction = new TargetInstruction(); instruction.parentInjectorId = parentInjectorId; instruction.expressions = TargetInstruction.noExpressions; instruction.behaviorInstructions = [liftingInstruction]; instruction.viewFactory = liftingInstruction.viewFactory; instruction.providers = [liftingInstruction.type.target]; instruction.lifting = true; return instruction; }; TargetInstruction.normal = function normal(injectorId, parentInjectorId, providers, behaviorInstructions, expressions, elementInstruction) { var instruction = new TargetInstruction(); instruction.injectorId = injectorId; instruction.parentInjectorId = parentInjectorId; instruction.providers = providers; instruction.behaviorInstructions = behaviorInstructions; instruction.expressions = expressions; instruction.anchorIsContainer = elementInstruction ? elementInstruction.anchorIsContainer : true; instruction.elementInstruction = elementInstruction; return instruction; }; TargetInstruction.surrogate = function surrogate(providers, behaviorInstructions, expressions, values) { var instruction = new TargetInstruction(); instruction.expressions = expressions; instruction.behaviorInstructions = behaviorInstructions; instruction.providers = providers; instruction.values = values; return instruction; }; function TargetInstruction() { this.injectorId = null; this.parentInjectorId = null; this.shadowSlot = false; this.slotName = null; this.slotFallbackFactory = null; this.contentExpression = null; this.expressions = null; this.behaviorInstructions = null; this.providers = null; this.viewFactory = null; this.anchorIsContainer = false; this.elementInstruction = null; this.lifting = false; this.values = null; } return TargetInstruction; }(), _class4.noExpressions = Object.freeze([]), _temp)); _export('TargetInstruction', TargetInstruction); _export('viewStrategy', viewStrategy = protocol.create('aurelia:view-strategy', { validate: function validate(target) { if (!(typeof target.loadViewFactory === 'function')) { return 'View strategies must implement: loadViewFactory(viewEngine: ViewEngine, compileInstruction: ViewCompileInstruction, loadContext?: ResourceLoadContext): Promise<ViewFactory>'; } return true; }, compose: function compose(target) { if (!(typeof target.makeRelativeTo === 'function')) { target.makeRelativeTo = PLATFORM.noop; } } })); _export('viewStrategy', viewStrategy); _export('RelativeViewStrategy', RelativeViewStrategy = (_dec = viewStrategy(), _dec(_class5 = function () { function RelativeViewStrategy(path) { this.path = path; this.absolutePath = null; } RelativeViewStrategy.prototype.loadViewFactory = function loadViewFactory(viewEngine, compileInstruction, loadContext, target) { if (this.absolutePath === null && this.moduleId) { this.absolutePath = relativeToFile(this.path, this.moduleId); } compileInstruction.associatedModuleId = this.moduleId; return viewEngine.loadViewFactory(this.absolutePath || this.path, compileInstruction, loadContext, target); }; RelativeViewStrategy.prototype.makeRelativeTo = function makeRelativeTo(file) { if (this.absolutePath === null) { this.absolutePath = relativeToFile(this.path, file); } }; return RelativeViewStrategy; }()) || _class5)); _export('RelativeViewStrategy', RelativeViewStrategy); _export('ConventionalViewStrategy', ConventionalViewStrategy = (_dec2 = viewStrategy(), _dec2(_class6 = function () { function ConventionalViewStrategy(viewLocator, origin) { this.moduleId = origin.moduleId; this.viewUrl = viewLocator.convertOriginToViewUrl(origin); } ConventionalViewStrategy.prototype.loadViewFactory = function loadViewFactory(viewEngine, compileInstruction, loadContext, target) { compileInstruction.associatedModuleId = this.moduleId; return viewEngine.loadViewFactory(this.viewUrl, compileInstruction, loadContext, target); }; return ConventionalViewStrategy; }()) || _class6)); _export('ConventionalViewStrategy', ConventionalViewStrategy); _export('NoViewStrategy', NoViewStrategy = (_dec3 = viewStrategy(), _dec3(_class7 = function () { function NoViewStrategy(dependencies, dependencyBaseUrl) { this.dependencies = dependencies || null; this.dependencyBaseUrl = dependencyBaseUrl || ''; } NoViewStrategy.prototype.loadViewFactory = function loadViewFactory(viewEngine, compileInstruction, loadContext, target) { var entry = this.entry; var dependencies = this.dependencies; if (entry && entry.factoryIsReady) { return Promise.resolve(null); } this.entry = entry = new TemplateRegistryEntry(this.moduleId || this.dependencyBaseUrl); entry.dependencies = []; entry.templateIsLoaded = true; if (dependencies !== null) { for (var i = 0, ii = dependencies.length; i < ii; ++i) { var current = dependencies[i]; if (typeof current === 'string' || typeof current === 'function') { entry.addDependency(current); } else { entry.addDependency(current.from, current.as); } } } compileInstruction.associatedModuleId = this.moduleId; return viewEngine.loadViewFactory(entry, compileInstruction, loadContext, target); }; return NoViewStrategy; }()) || _class7)); _export('NoViewStrategy', NoViewStrategy); _export('TemplateRegistryViewStrategy', TemplateRegistryViewStrategy = (_dec4 = viewStrategy(), _dec4(_class8 = function () { function TemplateRegistryViewStrategy(moduleId, entry) { this.moduleId = moduleId; this.entry = entry; } TemplateRegistryViewStrategy.prototype.loadViewFactory = function loadViewFactory(viewEngine, compileInstruction, loadContext, target) { var entry = this.entry; if (entry.factoryIsReady) { return Promise.resolve(entry.factory); } compileInstruction.associatedModuleId = this.moduleId; return viewEngine.loadViewFactory(entry, compileInstruction, loadContext, target); }; return TemplateRegistryViewStrategy; }()) || _class8)); _export('TemplateRegistryViewStrategy', TemplateRegistryViewStrategy); _export('InlineViewStrategy', InlineViewStrategy = (_dec5 = viewStrategy(), _dec5(_class9 = function () { function InlineViewStrategy(markup, dependencies, dependencyBaseUrl) { this.markup = markup; this.dependencies = dependencies || null; this.dependencyBaseUrl = dependencyBaseUrl || ''; } InlineViewStrategy.prototype.loadViewFactory = function loadViewFactory(viewEngine, compileInstruction, loadContext, target) { var entry = this.entry; var dependencies = this.dependencies; if (entry && entry.factoryIsReady) { return Promise.resolve(entry.factory); } this.entry = entry = new TemplateRegistryEntry(this.moduleId || this.dependencyBaseUrl); entry.template = DOM.createTemplateFromMarkup(this.markup); if (dependencies !== null) { for (var i = 0, ii = dependencies.length; i < ii; ++i) { var current = dependencies[i]; if (typeof current === 'string' || typeof current === 'function') { entry.addDependency(current); } else { entry.addDependency(current.from, current.as); } } } compileInstruction.associatedModuleId = this.moduleId; return viewEngine.loadViewFactory(entry, compileInstruction, loadContext, target); }; return InlineViewStrategy; }()) || _class9)); _export('InlineViewStrategy', InlineViewStrategy); _export('ViewLocator', ViewLocator = (_temp2 = _class10 = function () { function ViewLocator() { } ViewLocator.prototype.getViewStrategy = function getViewStrategy(value) { if (!value) { return null; } if ((typeof value === 'undefined' ? 'undefined' : _typeof(value)) === 'object' && 'getViewStrategy' in value) { var _origin = Origin.get(value.constructor); value = value.getViewStrategy(); if (typeof value === 'string') { value = new RelativeViewStrategy(value); } viewStrategy.assert(value); if (_origin.moduleId) { value.makeRelativeTo(_origin.moduleId); } return value; } if (typeof value === 'string') { value = new RelativeViewStrategy(value); } if (viewStrategy.validate(value)) { return value; } if (typeof value !== 'function') { value = value.constructor; } var origin = Origin.get(value); var strategy = metadata.get(ViewLocator.viewStrategyMetadataKey, value); if (!strategy) { if (!origin.moduleId) { throw new Error('Cannot determine default view strategy for object.', value); } strategy = this.createFallbackViewStrategy(origin); } else if (origin.moduleId) { strategy.moduleId = origin.moduleId; } return strategy; }; ViewLocator.prototype.createFallbackViewStrategy = function createFallbackViewStrategy(origin) { return new ConventionalViewStrategy(this, origin); }; ViewLocator.prototype.convertOriginToViewUrl = function convertOriginToViewUrl(origin) { var moduleId = origin.moduleId; var id = moduleId.endsWith('.js') || moduleId.endsWith('.ts') ? moduleId.substring(0, moduleId.length - 3) : moduleId; return id + '.html'; }; return ViewLocator; }(), _class10.viewStrategyMetadataKey = 'aurelia:view-strategy', _temp2)); _export('ViewLocator', ViewLocator); _export('BindingLanguage', BindingLanguage = function () { function BindingLanguage() { } BindingLanguage.prototype.inspectAttribute = function inspectAttribute(resources, elementName, attrName, attrValue) { mi('inspectAttribute');