UNPKG

aurelia-templating

Version:

An extensible HTML templating engine supporting databinding, custom elements, attached behaviors and more.

1,482 lines (1,135 loc) 189 kB
'use strict'; System.register(['aurelia-logging', 'aurelia-metadata', 'aurelia-pal', 'aurelia-loader', 'aurelia-path', 'aurelia-binding', 'aurelia-dependency-injection', 'aurelia-task-queue'], function (_export, _context) { "use strict"; var LogManager, metadata, Origin, protocol, DOM, PLATFORM, FEATURE, TemplateRegistryEntry, Loader, relativeToFile, Scope, Expression, ValueConverterResource, BindingBehaviorResource, camelCase, Binding, createOverrideContext, subscriberCollection, bindingMode, ObserverLocator, EventManager, Container, resolver, inject, TaskQueue, _createClass, _typeof, _class, _temp, _dec, _class2, _dec2, _class3, _dec3, _class4, _dec4, _class5, _dec5, _class6, _dec6, _class7, _class8, _temp2, _class9, _temp3, _class11, _dec7, _class13, _dec8, _class14, _class15, _temp4, _dec9, _class16, _dec10, _class17, _dec11, _class18, animationEvent, Animator, CompositionTransactionNotifier, CompositionTransactionOwnershipToken, CompositionTransaction, capitalMatcher, ViewEngineHooksResource, ElementEvents, EventHandlerImpl, ResourceLoadContext, ViewCompileInstruction, BehaviorInstruction, biProto, TargetInstruction, tiProto, viewStrategy, RelativeViewStrategy, ConventionalViewStrategy, NoViewStrategy, TemplateRegistryViewStrategy, InlineViewStrategy, StaticViewStrategy, ViewLocator, BindingLanguage, noNodes, SlotCustomAttribute, PassThroughSlot, ShadowSlot, ShadowDOM, conventionMark, ViewResources, View, ViewSlot, ProviderResolver, providerResolverInstance, BoundViewFactory, ViewFactory, nextInjectorId, lastAUTargetID, defaultLetHandler, ViewCompiler, ResourceModule, ResourceDescription, ModuleAnalyzer, logger, ProxyViewFactory, auSlotBehavior, ViewEngine, Controller, BehaviorPropertyObserver, BindableProperty, lastProviderId, HtmlBehaviorResource, ChildObserver, noMutations, ChildObserverBinder, SwapStrategies, 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 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; } _export('validateBehaviorName', validateBehaviorName); 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 hasAttribute(name) { return this._element.hasAttribute(name); } function getAttribute(name) { return this._element.getAttribute(name); } function setAttribute(name, value) { this._element.setAttribute(name, value); } 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._element = element; anchor.hasAttribute = hasAttribute; anchor.getAttribute = getAttribute; anchor.setAttribute = setAttribute; } 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 (instruction.letElement) { for (i = 0, ii = expressions.length; i < ii; ++i) { bindings.push(expressions[i].createBinding()); } element.parentNode.removeChild(element); 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 _key4 in obj) { result += _key4 + ':' + obj[_key4] + ';'; } 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 _key5 in values) { currentAttributeValue = element.getAttribute(_key5); if (currentAttributeValue) { if (_key5 === 'class') { element.setAttribute('class', currentAttributeValue + ' ' + values[_key5]); } else if (_key5 === 'style') { var styleObject = styleStringToObject(values[_key5]); styleStringToObject(currentAttributeValue, styleObject); element.setAttribute('style', styleObjectToString(styleObject)); } } else { element.setAttribute(_key5, values[_key5]); } } 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 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 _child4 = void 0; while (_child4 = node.firstChild) { fragment.appendChild(_child4); } 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(instance, name) { var lookup = instance.__observers__; if (lookup === undefined) { var ctor = Object.getPrototypeOf(instance).constructor; var _behavior = metadata.get(metadata.resource, ctor); 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; descriptor.configurable = 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 _i10 = 0, _ii9 = mutations.length; _i10 < _ii9; ++_i10) { var record = mutations[_i10]; 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 _node2 = added[_j]; if (_node2.nodeType === 1) { for (var _k = 0; _k < bindersLength; ++_k) { var _binder = binders[_k]; if (_binder.onAdd(_node2)) { trackMutation(groupedMutations, _binder, record); } } } } } groupedMutations.forEach(function (value, key) { if (key.changeHandler !== null) { key.viewModel[key.changeHandler](value); } }); } function remove(viewSlot, previous) { return Array.isArray(previous) ? viewSlot.removeMany(previous, true) : viewSlot.remove(previous, true); } function tryActivateViewModel(context) { if (context.skipActivation || typeof context.viewModel.activate !== 'function') { return Promise.resolve(); } return context.viewModel.activate(context.model) || Promise.resolve(); } function resource(instanceOrConfig) { return function (target) { var isConfig = typeof instanceOrConfig === 'string' || Object.getPrototypeOf(instanceOrConfig) === Object.prototype; if (isConfig) { target.$resource = instanceOrConfig; } else { metadata.define(metadata.resource, instanceOrConfig, 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, aliases) { return function (target) { var r = metadata.getOrCreateOwn(metadata.resource, HtmlBehaviorResource, target); r.attributeName = validateBehaviorName(name, 'custom attribute'); r.attributeDefaultBindingMode = defaultBindingMode; r.aliases = aliases; }; } _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 view(templateOrConfig) { return function (target) { target.$view = templateOrConfig; }; } _export('view', view); 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() { for (var _len = arguments.length, resources = Array(_len), _key7 = 0; _key7 < _len; _key7++) { resources[_key7] = arguments[_key7]; } 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 (_aureliaLoader) { TemplateRegistryEntry = _aureliaLoader.TemplateRegistryEntry; Loader = _aureliaLoader.Loader; }, function (_aureliaPath) { relativeToFile = _aureliaPath.relativeToFile; }, function (_aureliaBinding) { Scope = _aureliaBinding.Scope; Expression = _aureliaBinding.Expression; ValueConverterResource = _aureliaBinding.ValueConverterResource; BindingBehaviorResource = _aureliaBinding.BindingBehaviorResource; camelCase = _aureliaBinding.camelCase; Binding = _aureliaBinding.Binding; createOverrideContext = _aureliaBinding.createOverrideContext; subscriberCollection = _aureliaBinding.subscriberCollection; bindingMode = _aureliaBinding.bindingMode; ObserverLocator = _aureliaBinding.ObserverLocator; EventManager = _aureliaBinding.EventManager; }, function (_aureliaDependencyInjection) { Container = _aureliaDependencyInjection.Container; resolver = _aureliaDependencyInjection.resolver; inject = _aureliaDependencyInjection.inject; }, 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 && obj !== Symbol.prototype ? "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 ? arguments[2] : true; var cancelable = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true; var event = DOM.createCustomEvent(eventName, { cancelable: cancelable, bubbles: bubbles, detail: detail }); this.element.dispatchEvent(event); }; ElementEvents.prototype.subscribe = function subscribe(eventName, handler) { var captureOrOptions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true; if (typeof handler === 'function') { var eventHandler = new EventHandlerImpl(this, eventName, handler, captureOrOptions, false); return eventHandler; } return undefined; }; ElementEvents.prototype.subscribeOnce = function subscribeOnce(eventName, handler) { var captureOrOptions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true; if (typeof handler === 'function') { var eventHandler = new EventHandlerImpl(this, eventName, handler, captureOrOptions, true); return eventHandler; } 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); EventHandlerImpl = function () { function EventHandlerImpl(owner, eventName, handler, captureOrOptions, once) { this.owner = owner; this.eventName = eventName; this.handler = handler; this.capture = typeof captureOrOptions === 'boolean' ? captureOrOptions : captureOrOptions.capture; this.bubbles = !this.capture; this.captureOrOptions = captureOrOptions; this.once = once; owner.element.addEventListener(eventName, this, captureOrOptions); owner._enqueueHandler(this); } EventHandlerImpl.prototype.handleEvent = function handleEvent(e) { var fn = this.handler; fn(e); if (this.once) { this.dispose(); } }; EventHandlerImpl.prototype.dispose = function dispose() { this.owner.element.removeEventListener(this.eventName, this, this.captureOrOptions); this.owner._dequeueHandler(this); this.owner = this.handler = null; }; return EventHandlerImpl; }(); _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 ? arguments[0] : false; var compileSurrogate = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; this.targetShadowDOM = targetShadowDOM; this.compileSurrogate = compileSurrogate; this.associatedModuleId = null; }); _export('ViewCompileInstruction', ViewCompileInstruction); ViewCompileInstruction.normal = new ViewCompileInstruction(); _export('BehaviorInstruction', BehaviorInstruction = function () { function BehaviorInstruction() { } 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; }; return BehaviorInstruction; }()); _export('BehaviorInstruction', BehaviorInstruction); biProto = BehaviorInstruction.prototype; biProto.initiatedByBehavior = false; biProto.enhance = false; biProto.partReplacements = null; biProto.viewFactory = null; biProto.originalAttrName = null; biProto.skipContentProcessing = false; biProto.contentFactory = null; biProto.viewModel = null; biProto.anchorIsContainer = false; biProto.host = null; biProto.attributes = null; biProto.type = null; biProto.attrName = null; biProto.inheritBindingContext = false; BehaviorInstruction.normal = new BehaviorInstruction(); _export('TargetInstruction', TargetInstruction = (_temp = _class = function () { function TargetInstruction() { } 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.letElement = function letElement(expressions) { var instruction = new TargetInstruction(); instruction.expressions = expressions; instruction.letElement = true; 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; }; return TargetInstruction; }(), _class.noExpressions = Object.freeze([]), _temp)); _export('TargetInstruction', TargetInstruction); tiProto = TargetInstruction.prototype; tiProto.injectorId = null; tiProto.parentInjectorId = null; tiProto.shadowSlot = false; tiProto.slotName = null; tiProto.slotFallbackFactory = null; tiProto.contentExpression = null; tiProto.letElement = false; tiProto.expressions = null; tiProto.expressions = null; tiProto.providers = null; tiProto.viewFactory = null; tiProto.anchorIsContainer = false; tiProto.elementInstruction = null; tiProto.lifting = false; tiProto.values = null; _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(_class2 = 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; }()) || _class2)); _export('RelativeViewStrategy', RelativeViewStrategy); _export('ConventionalViewStrategy', ConventionalViewStrategy = (_dec2 = viewStrategy(), _dec2(_class3 = 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; }()) || _class3)); _export('ConventionalViewStrategy', ConventionalViewStrategy); _export('NoViewStrategy', NoViewStrategy = (_dec3 = viewStrategy(), _dec3(_class4 = 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; }()) || _class4)); _export('NoViewStrategy', NoViewStrategy); _export('TemplateRegistryViewStrategy', TemplateRegistryViewStrategy = (_dec4 = viewStrategy(), _dec4(_class5 = 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; }()) || _class5)); _export('TemplateRegistryViewStrategy', TemplateRegistryViewStrategy); _export('InlineViewStrategy', InlineViewStrategy = (_dec5 = viewStrategy(), _dec5(_class6 = 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; }()) || _class6)); _export('InlineViewStrategy', InlineViewStrategy); _export('StaticViewStrategy', StaticViewStrategy = (_dec6 = viewStrategy(), _dec6(_class7 = function () { function StaticViewStrategy(config) { if (typeof config === 'string' || config instanceof DOM.Element && config.tagName === 'TEMPLATE') { config = { template: config }; } this.template = config.template; this.dependencies = config.dependencies || []; this.factoryIsReady = false; this.onReady = null; this.moduleId = 'undefined'; } StaticViewStrategy.prototype.loadViewFactory = function loadViewFactory(viewEngine, compileInstruction, loadContext, target) { var _this2 = this; if (this.factoryIsReady) { return Promise.resolve(this.factory); } var deps = this.dependencies; deps = typeof deps === 'function' ? deps() : deps; deps = deps ? deps : [];