UNPKG

101 kBJavaScriptView Raw
1System.register(['aurelia-dependency-injection', 'aurelia-pal', 'aurelia-task-queue', 'aurelia-templating', 'aurelia-binding', 'aurelia-logging', 'aurelia-loader', 'aurelia-path', 'aurelia-metadata'], function (exports, module) {
2 'use strict';
3 var Container, inject, Optional, DOM, FEATURE, TaskQueue, CompositionEngine, ViewSlot, ViewResources, bindable, noView, customElement, customAttribute, templateController, BoundViewFactory, TargetInstruction, Animator, resource, useView, useShadowDOM, ViewEngine, createOverrideContext, bindingMode, BindingBehavior, ValueConverter, sourceContext, mergeSplice, ObserverLocator, valueConverter, DataAttributeObserver, bindingBehavior, targetContext, EventSubscriber, getLogger, Loader, relativeToFile, mixin;
4 return {
5 setters: [function (module) {
6 Container = module.Container;
7 inject = module.inject;
8 Optional = module.Optional;
9 }, function (module) {
10 DOM = module.DOM;
11 FEATURE = module.FEATURE;
12 }, function (module) {
13 TaskQueue = module.TaskQueue;
14 }, function (module) {
15 CompositionEngine = module.CompositionEngine;
16 ViewSlot = module.ViewSlot;
17 ViewResources = module.ViewResources;
18 bindable = module.bindable;
19 noView = module.noView;
20 customElement = module.customElement;
21 customAttribute = module.customAttribute;
22 templateController = module.templateController;
23 BoundViewFactory = module.BoundViewFactory;
24 TargetInstruction = module.TargetInstruction;
25 Animator = module.Animator;
26 resource = module.resource;
27 useView = module.useView;
28 useShadowDOM = module.useShadowDOM;
29 ViewEngine = module.ViewEngine;
30 }, function (module) {
31 createOverrideContext = module.createOverrideContext;
32 bindingMode = module.bindingMode;
33 BindingBehavior = module.BindingBehavior;
34 ValueConverter = module.ValueConverter;
35 sourceContext = module.sourceContext;
36 mergeSplice = module.mergeSplice;
37 ObserverLocator = module.ObserverLocator;
38 valueConverter = module.valueConverter;
39 DataAttributeObserver = module.DataAttributeObserver;
40 bindingBehavior = module.bindingBehavior;
41 targetContext = module.targetContext;
42 EventSubscriber = module.EventSubscriber;
43 }, function (module) {
44 getLogger = module.getLogger;
45 }, function (module) {
46 Loader = module.Loader;
47 }, function (module) {
48 relativeToFile = module.relativeToFile;
49 }, function (module) {
50 mixin = module.mixin;
51 }],
52 execute: function () {
53
54 exports({
55 configure: configure$1,
56 createFullOverrideContext: createFullOverrideContext,
57 getItemsSourceExpression: getItemsSourceExpression,
58 isOneTime: isOneTime,
59 unwrapExpression: unwrapExpression,
60 updateOneTimeBinding: updateOneTimeBinding,
61 updateOverrideContext: updateOverrideContext,
62 viewsRequireLifecycle: viewsRequireLifecycle
63 });
64
65 /*! *****************************************************************************
66 Copyright (c) Microsoft Corporation. All rights reserved.
67 Licensed under the Apache License, Version 2.0 (the "License"); you may not use
68 this file except in compliance with the License. You may obtain a copy of the
69 License at http://www.apache.org/licenses/LICENSE-2.0
70
71 THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
72 KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
73 WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
74 MERCHANTABLITY OR NON-INFRINGEMENT.
75
76 See the Apache Version 2.0 License for specific language governing permissions
77 and limitations under the License.
78 ***************************************************************************** */
79 /* global Reflect, Promise */
80
81 var extendStatics = function(d, b) {
82 extendStatics = Object.setPrototypeOf ||
83 ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
84 function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
85 return extendStatics(d, b);
86 };
87
88 function __extends(d, b) {
89 extendStatics(d, b);
90 function __() { this.constructor = d; }
91 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
92 }
93
94 function __decorate(decorators, target, key, desc) {
95 var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
96 if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
97 else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
98 return c > 3 && r && Object.defineProperty(target, key, r), r;
99 }
100
101 var ActivationStrategy;
102 (function (ActivationStrategy) {
103 ActivationStrategy["InvokeLifecycle"] = "invoke-lifecycle";
104 ActivationStrategy["Replace"] = "replace";
105 })(ActivationStrategy || (ActivationStrategy = {}));
106 var Compose = exports('Compose', (function () {
107 function Compose(element, container, compositionEngine, viewSlot, viewResources, taskQueue) {
108 this.activationStrategy = ActivationStrategy.InvokeLifecycle;
109 this.element = element;
110 this.container = container;
111 this.compositionEngine = compositionEngine;
112 this.viewSlot = viewSlot;
113 this.viewResources = viewResources;
114 this.taskQueue = taskQueue;
115 this.currentController = null;
116 this.currentViewModel = null;
117 this.changes = Object.create(null);
118 }
119 Compose.inject = function () {
120 return [DOM.Element, Container, CompositionEngine, ViewSlot, ViewResources, TaskQueue];
121 };
122 Compose.prototype.created = function (owningView) {
123 this.owningView = owningView;
124 };
125 Compose.prototype.bind = function (bindingContext, overrideContext) {
126 this.bindingContext = bindingContext;
127 this.overrideContext = overrideContext;
128 var changes = this.changes;
129 changes.view = this.view;
130 changes.viewModel = this.viewModel;
131 changes.model = this.model;
132 if (!this.pendingTask) {
133 processChanges(this);
134 }
135 };
136 Compose.prototype.unbind = function () {
137 this.changes = Object.create(null);
138 this.bindingContext = null;
139 this.overrideContext = null;
140 var returnToCache = true;
141 var skipAnimation = true;
142 this.viewSlot.removeAll(returnToCache, skipAnimation);
143 };
144 Compose.prototype.modelChanged = function (newValue, oldValue) {
145 this.changes.model = newValue;
146 requestUpdate(this);
147 };
148 Compose.prototype.viewChanged = function (newValue, oldValue) {
149 this.changes.view = newValue;
150 requestUpdate(this);
151 };
152 Compose.prototype.viewModelChanged = function (newValue, oldValue) {
153 this.changes.viewModel = newValue;
154 requestUpdate(this);
155 };
156 __decorate([
157 bindable
158 ], Compose.prototype, "model", void 0);
159 __decorate([
160 bindable
161 ], Compose.prototype, "view", void 0);
162 __decorate([
163 bindable
164 ], Compose.prototype, "viewModel", void 0);
165 __decorate([
166 bindable
167 ], Compose.prototype, "activationStrategy", void 0);
168 __decorate([
169 bindable
170 ], Compose.prototype, "swapOrder", void 0);
171 Compose = __decorate([
172 noView,
173 customElement('compose')
174 ], Compose);
175 return Compose;
176 }()));
177 function isEmpty(obj) {
178 for (var _ in obj) {
179 return false;
180 }
181 return true;
182 }
183 function tryActivateViewModel(vm, model) {
184 if (vm && typeof vm.activate === 'function') {
185 return Promise.resolve(vm.activate(model));
186 }
187 }
188 function createInstruction(composer, instruction) {
189 return Object.assign(instruction, {
190 bindingContext: composer.bindingContext,
191 overrideContext: composer.overrideContext,
192 owningView: composer.owningView,
193 container: composer.container,
194 viewSlot: composer.viewSlot,
195 viewResources: composer.viewResources,
196 currentController: composer.currentController,
197 host: composer.element,
198 swapOrder: composer.swapOrder
199 });
200 }
201 function processChanges(composer) {
202 var changes = composer.changes;
203 composer.changes = Object.create(null);
204 if (needsReInitialization(composer, changes)) {
205 var instruction = {
206 view: composer.view,
207 viewModel: composer.currentViewModel || composer.viewModel,
208 model: composer.model
209 };
210 instruction = Object.assign(instruction, changes);
211 instruction = createInstruction(composer, instruction);
212 composer.pendingTask = composer.compositionEngine.compose(instruction).then(function (controller) {
213 composer.currentController = controller;
214 composer.currentViewModel = controller ? controller.viewModel : null;
215 });
216 }
217 else {
218 composer.pendingTask = tryActivateViewModel(composer.currentViewModel, changes.model);
219 if (!composer.pendingTask) {
220 return;
221 }
222 }
223 composer.pendingTask = composer.pendingTask
224 .then(function () {
225 completeCompositionTask(composer);
226 }, function (reason) {
227 completeCompositionTask(composer);
228 throw reason;
229 });
230 }
231 function completeCompositionTask(composer) {
232 composer.pendingTask = null;
233 if (!isEmpty(composer.changes)) {
234 processChanges(composer);
235 }
236 }
237 function requestUpdate(composer) {
238 if (composer.pendingTask || composer.updateRequested) {
239 return;
240 }
241 composer.updateRequested = true;
242 composer.taskQueue.queueMicroTask(function () {
243 composer.updateRequested = false;
244 processChanges(composer);
245 });
246 }
247 function needsReInitialization(composer, changes) {
248 var activationStrategy = composer.activationStrategy;
249 var vm = composer.currentViewModel;
250 if (vm && typeof vm.determineActivationStrategy === 'function') {
251 activationStrategy = vm.determineActivationStrategy();
252 }
253 return 'view' in changes
254 || 'viewModel' in changes
255 || activationStrategy === ActivationStrategy.Replace;
256 }
257
258 var IfCore = (function () {
259 function IfCore(viewFactory, viewSlot) {
260 this.viewFactory = viewFactory;
261 this.viewSlot = viewSlot;
262 this.view = null;
263 this.bindingContext = null;
264 this.overrideContext = null;
265 this.showing = false;
266 this.cache = true;
267 }
268 IfCore.prototype.bind = function (bindingContext, overrideContext) {
269 this.bindingContext = bindingContext;
270 this.overrideContext = overrideContext;
271 };
272 IfCore.prototype.unbind = function () {
273 if (this.view === null) {
274 return;
275 }
276 this.view.unbind();
277 if (!this.viewFactory.isCaching) {
278 return;
279 }
280 if (this.showing) {
281 this.showing = false;
282 this.viewSlot.remove(this.view, true, true);
283 }
284 else {
285 this.view.returnToCache();
286 }
287 this.view = null;
288 };
289 IfCore.prototype._show = function () {
290 if (this.showing) {
291 if (!this.view.isBound) {
292 this.view.bind(this.bindingContext, this.overrideContext);
293 }
294 return;
295 }
296 if (this.view === null) {
297 this.view = this.viewFactory.create();
298 }
299 if (!this.view.isBound) {
300 this.view.bind(this.bindingContext, this.overrideContext);
301 }
302 this.showing = true;
303 return this.viewSlot.add(this.view);
304 };
305 IfCore.prototype._hide = function () {
306 var _this = this;
307 if (!this.showing) {
308 return;
309 }
310 this.showing = false;
311 var removed = this.viewSlot.remove(this.view);
312 if (removed instanceof Promise) {
313 return removed.then(function () {
314 _this._unbindView();
315 });
316 }
317 this._unbindView();
318 };
319 IfCore.prototype._unbindView = function () {
320 var cache = this.cache === 'false' ? false : !!this.cache;
321 this.view.unbind();
322 if (!cache) {
323 this.view = null;
324 }
325 };
326 return IfCore;
327 }());
328
329 var If = exports('If', (function (_super) {
330 __extends(If, _super);
331 function If() {
332 var _this = _super !== null && _super.apply(this, arguments) || this;
333 _this.cache = true;
334 return _this;
335 }
336 If.prototype.bind = function (bindingContext, overrideContext) {
337 _super.prototype.bind.call(this, bindingContext, overrideContext);
338 if (this.condition) {
339 this._show();
340 }
341 else {
342 this._hide();
343 }
344 };
345 If.prototype.conditionChanged = function (newValue) {
346 this._update(newValue);
347 };
348 If.prototype._update = function (show) {
349 var _this = this;
350 if (this.animating) {
351 return;
352 }
353 var promise;
354 if (this.elseVm) {
355 promise = show ? this._swap(this.elseVm, this) : this._swap(this, this.elseVm);
356 }
357 else {
358 promise = show ? this._show() : this._hide();
359 }
360 if (promise) {
361 this.animating = true;
362 promise.then(function () {
363 _this.animating = false;
364 if (_this.condition !== _this.showing) {
365 _this._update(_this.condition);
366 }
367 });
368 }
369 };
370 If.prototype._swap = function (remove, add) {
371 switch (this.swapOrder) {
372 case 'before':
373 return Promise.resolve(add._show()).then(function () { return remove._hide(); });
374 case 'with':
375 return Promise.all([remove._hide(), add._show()]);
376 default:
377 var promise = remove._hide();
378 return promise ? promise.then(function () { return add._show(); }) : add._show();
379 }
380 };
381 __decorate([
382 bindable({ primaryProperty: true })
383 ], If.prototype, "condition", void 0);
384 __decorate([
385 bindable
386 ], If.prototype, "swapOrder", void 0);
387 __decorate([
388 bindable
389 ], If.prototype, "cache", void 0);
390 If = __decorate([
391 customAttribute('if'),
392 templateController,
393 inject(BoundViewFactory, ViewSlot)
394 ], If);
395 return If;
396 }(IfCore)));
397
398 var Else = exports('Else', (function (_super) {
399 __extends(Else, _super);
400 function Else(viewFactory, viewSlot) {
401 var _this = _super.call(this, viewFactory, viewSlot) || this;
402 _this._registerInIf();
403 return _this;
404 }
405 Else.prototype.bind = function (bindingContext, overrideContext) {
406 _super.prototype.bind.call(this, bindingContext, overrideContext);
407 if (this.ifVm.condition) {
408 this._hide();
409 }
410 else {
411 this._show();
412 }
413 };
414 Else.prototype._registerInIf = function () {
415 var previous = this.viewSlot.anchor.previousSibling;
416 while (previous && !previous.au) {
417 previous = previous.previousSibling;
418 }
419 if (!previous || !previous.au.if) {
420 throw new Error("Can't find matching If for Else custom attribute.");
421 }
422 this.ifVm = previous.au.if.viewModel;
423 this.ifVm.elseVm = this;
424 };
425 Else = __decorate([
426 customAttribute('else'),
427 templateController,
428 inject(BoundViewFactory, ViewSlot)
429 ], Else);
430 return Else;
431 }(IfCore)));
432
433 var With = exports('With', (function () {
434 function With(viewFactory, viewSlot) {
435 this.viewFactory = viewFactory;
436 this.viewSlot = viewSlot;
437 this.parentOverrideContext = null;
438 this.view = null;
439 }
440 With.prototype.bind = function (bindingContext, overrideContext) {
441 this.parentOverrideContext = overrideContext;
442 this.valueChanged(this.value);
443 };
444 With.prototype.valueChanged = function (newValue) {
445 var overrideContext = createOverrideContext(newValue, this.parentOverrideContext);
446 var view = this.view;
447 if (!view) {
448 view = this.view = this.viewFactory.create();
449 view.bind(newValue, overrideContext);
450 this.viewSlot.add(view);
451 }
452 else {
453 view.bind(newValue, overrideContext);
454 }
455 };
456 With.prototype.unbind = function () {
457 var view = this.view;
458 this.parentOverrideContext = null;
459 if (view) {
460 view.unbind();
461 }
462 };
463 With = __decorate([
464 customAttribute('with'),
465 templateController,
466 inject(BoundViewFactory, ViewSlot)
467 ], With);
468 return With;
469 }()));
470
471 var oneTime = bindingMode.oneTime;
472 function updateOverrideContexts(views, startIndex) {
473 var length = views.length;
474 if (startIndex > 0) {
475 startIndex = startIndex - 1;
476 }
477 for (; startIndex < length; ++startIndex) {
478 updateOverrideContext(views[startIndex].overrideContext, startIndex, length);
479 }
480 }
481 function createFullOverrideContext(repeat, data, index, length, key) {
482 var bindingContext = {};
483 var overrideContext = createOverrideContext(bindingContext, repeat.scope.overrideContext);
484 if (typeof key !== 'undefined') {
485 bindingContext[repeat.key] = key;
486 bindingContext[repeat.value] = data;
487 }
488 else {
489 bindingContext[repeat.local] = data;
490 }
491 updateOverrideContext(overrideContext, index, length);
492 return overrideContext;
493 }
494 function updateOverrideContext(overrideContext, index, length) {
495 var first = (index === 0);
496 var last = (index === length - 1);
497 var even = index % 2 === 0;
498 overrideContext.$index = index;
499 overrideContext.$first = first;
500 overrideContext.$last = last;
501 overrideContext.$middle = !(first || last);
502 overrideContext.$odd = !even;
503 overrideContext.$even = even;
504 }
505 function getItemsSourceExpression(instruction, attrName) {
506 return instruction.behaviorInstructions
507 .filter(function (bi) { return bi.originalAttrName === attrName; })[0]
508 .attributes
509 .items
510 .sourceExpression;
511 }
512 function unwrapExpression(expression) {
513 var unwrapped = false;
514 while (expression instanceof BindingBehavior) {
515 expression = expression.expression;
516 }
517 while (expression instanceof ValueConverter) {
518 expression = expression.expression;
519 unwrapped = true;
520 }
521 return unwrapped ? expression : null;
522 }
523 function isOneTime(expression) {
524 while (expression instanceof BindingBehavior) {
525 if (expression.name === 'oneTime') {
526 return true;
527 }
528 expression = expression.expression;
529 }
530 return false;
531 }
532 function updateOneTimeBinding(binding) {
533 if (binding.call && binding.mode === oneTime) {
534 binding.call(sourceContext);
535 }
536 else if (binding.updateOneTimeBindings) {
537 binding.updateOneTimeBindings();
538 }
539 }
540 function indexOf(array, item, matcher, startIndex) {
541 if (!matcher) {
542 return array.indexOf(item);
543 }
544 var length = array.length;
545 for (var index = startIndex || 0; index < length; index++) {
546 if (matcher(array[index], item)) {
547 return index;
548 }
549 }
550 return -1;
551 }
552
553 var ArrayRepeatStrategy = exports('ArrayRepeatStrategy', (function () {
554 function ArrayRepeatStrategy() {
555 }
556 ArrayRepeatStrategy.prototype.getCollectionObserver = function (observerLocator, items) {
557 return observerLocator.getArrayObserver(items);
558 };
559 ArrayRepeatStrategy.prototype.instanceChanged = function (repeat, items) {
560 var _this = this;
561 var $repeat = repeat;
562 var itemsLength = items.length;
563 if (!items || itemsLength === 0) {
564 $repeat.removeAllViews(true, !$repeat.viewsRequireLifecycle);
565 return;
566 }
567 var children = $repeat.views();
568 var viewsLength = children.length;
569 if (viewsLength === 0) {
570 this._standardProcessInstanceChanged($repeat, items);
571 return;
572 }
573 if ($repeat.viewsRequireLifecycle) {
574 var childrenSnapshot = children.slice(0);
575 var itemNameInBindingContext = $repeat.local;
576 var matcher_1 = $repeat.matcher();
577 var itemsPreviouslyInViews_1 = [];
578 var viewsToRemove = [];
579 for (var index = 0; index < viewsLength; index++) {
580 var view = childrenSnapshot[index];
581 var oldItem = view.bindingContext[itemNameInBindingContext];
582 if (indexOf(items, oldItem, matcher_1) === -1) {
583 viewsToRemove.push(view);
584 }
585 else {
586 itemsPreviouslyInViews_1.push(oldItem);
587 }
588 }
589 var updateViews = void 0;
590 var removePromise = void 0;
591 if (itemsPreviouslyInViews_1.length > 0) {
592 removePromise = $repeat.removeViews(viewsToRemove, true, !$repeat.viewsRequireLifecycle);
593 updateViews = function () {
594 for (var index = 0; index < itemsLength; index++) {
595 var item = items[index];
596 var indexOfView = indexOf(itemsPreviouslyInViews_1, item, matcher_1, index);
597 var view = void 0;
598 if (indexOfView === -1) {
599 var overrideContext = createFullOverrideContext($repeat, items[index], index, itemsLength);
600 $repeat.insertView(index, overrideContext.bindingContext, overrideContext);
601 itemsPreviouslyInViews_1.splice(index, 0, undefined);
602 }
603 else if (indexOfView === index) {
604 view = children[indexOfView];
605 itemsPreviouslyInViews_1[indexOfView] = undefined;
606 }
607 else {
608 view = children[indexOfView];
609 $repeat.moveView(indexOfView, index);
610 itemsPreviouslyInViews_1.splice(indexOfView, 1);
611 itemsPreviouslyInViews_1.splice(index, 0, undefined);
612 }
613 if (view) {
614 updateOverrideContext(view.overrideContext, index, itemsLength);
615 }
616 }
617 _this._inPlaceProcessItems($repeat, items);
618 };
619 }
620 else {
621 removePromise = $repeat.removeAllViews(true, !$repeat.viewsRequireLifecycle);
622 updateViews = function () { return _this._standardProcessInstanceChanged($repeat, items); };
623 }
624 if (removePromise instanceof Promise) {
625 removePromise.then(updateViews);
626 }
627 else {
628 updateViews();
629 }
630 }
631 else {
632 this._inPlaceProcessItems($repeat, items);
633 }
634 };
635 ArrayRepeatStrategy.prototype._standardProcessInstanceChanged = function (repeat, items) {
636 for (var i = 0, ii = items.length; i < ii; i++) {
637 var overrideContext = createFullOverrideContext(repeat, items[i], i, ii);
638 repeat.addView(overrideContext.bindingContext, overrideContext);
639 }
640 };
641 ArrayRepeatStrategy.prototype._inPlaceProcessItems = function (repeat, items) {
642 var itemsLength = items.length;
643 var viewsLength = repeat.viewCount();
644 while (viewsLength > itemsLength) {
645 viewsLength--;
646 repeat.removeView(viewsLength, true, !repeat.viewsRequireLifecycle);
647 }
648 var local = repeat.local;
649 for (var i = 0; i < viewsLength; i++) {
650 var view = repeat.view(i);
651 var last = i === itemsLength - 1;
652 var middle = i !== 0 && !last;
653 var bindingContext = view.bindingContext;
654 var overrideContext = view.overrideContext;
655 if (bindingContext[local] === items[i]
656 && overrideContext.$middle === middle
657 && overrideContext.$last === last) {
658 continue;
659 }
660 bindingContext[local] = items[i];
661 overrideContext.$middle = middle;
662 overrideContext.$last = last;
663 repeat.updateBindings(view);
664 }
665 for (var i = viewsLength; i < itemsLength; i++) {
666 var overrideContext = createFullOverrideContext(repeat, items[i], i, itemsLength);
667 repeat.addView(overrideContext.bindingContext, overrideContext);
668 }
669 };
670 ArrayRepeatStrategy.prototype.instanceMutated = function (repeat, array, splices) {
671 var _this = this;
672 if (repeat.__queuedSplices) {
673 for (var i = 0, ii = splices.length; i < ii; ++i) {
674 var _a = splices[i], index = _a.index, removed = _a.removed, addedCount = _a.addedCount;
675 mergeSplice(repeat.__queuedSplices, index, removed, addedCount);
676 }
677 repeat.__array = array.slice(0);
678 return;
679 }
680 var maybePromise = this._runSplices(repeat, array.slice(0), splices);
681 if (maybePromise instanceof Promise) {
682 var queuedSplices_1 = repeat.__queuedSplices = [];
683 var runQueuedSplices_1 = function () {
684 if (!queuedSplices_1.length) {
685 repeat.__queuedSplices = undefined;
686 repeat.__array = undefined;
687 return;
688 }
689 var nextPromise = _this._runSplices(repeat, repeat.__array, queuedSplices_1) || Promise.resolve();
690 queuedSplices_1 = repeat.__queuedSplices = [];
691 nextPromise.then(runQueuedSplices_1);
692 };
693 maybePromise.then(runQueuedSplices_1);
694 }
695 };
696 ArrayRepeatStrategy.prototype._runSplices = function (repeat, array, splices) {
697 var _this = this;
698 var removeDelta = 0;
699 var rmPromises = [];
700 for (var i = 0, ii = splices.length; i < ii; ++i) {
701 var splice = splices[i];
702 var removed = splice.removed;
703 for (var j = 0, jj = removed.length; j < jj; ++j) {
704 var viewOrPromise = repeat.removeView(splice.index + removeDelta + rmPromises.length, true);
705 if (viewOrPromise instanceof Promise) {
706 rmPromises.push(viewOrPromise);
707 }
708 }
709 removeDelta -= splice.addedCount;
710 }
711 if (rmPromises.length > 0) {
712 return Promise.all(rmPromises).then(function () {
713 var spliceIndexLow = _this._handleAddedSplices(repeat, array, splices);
714 updateOverrideContexts(repeat.views(), spliceIndexLow);
715 });
716 }
717 var spliceIndexLow = this._handleAddedSplices(repeat, array, splices);
718 updateOverrideContexts(repeat.views(), spliceIndexLow);
719 return undefined;
720 };
721 ArrayRepeatStrategy.prototype._handleAddedSplices = function (repeat, array, splices) {
722 var spliceIndex;
723 var spliceIndexLow;
724 var arrayLength = array.length;
725 for (var i = 0, ii = splices.length; i < ii; ++i) {
726 var splice = splices[i];
727 var addIndex = spliceIndex = splice.index;
728 var end = splice.index + splice.addedCount;
729 if (typeof spliceIndexLow === 'undefined' || spliceIndexLow === null || spliceIndexLow > splice.index) {
730 spliceIndexLow = spliceIndex;
731 }
732 for (; addIndex < end; ++addIndex) {
733 var overrideContext = createFullOverrideContext(repeat, array[addIndex], addIndex, arrayLength);
734 repeat.insertView(addIndex, overrideContext.bindingContext, overrideContext);
735 }
736 }
737 return spliceIndexLow;
738 };
739 return ArrayRepeatStrategy;
740 }()));
741
742 var MapRepeatStrategy = exports('MapRepeatStrategy', (function () {
743 function MapRepeatStrategy() {
744 }
745 MapRepeatStrategy.prototype.getCollectionObserver = function (observerLocator, items) {
746 return observerLocator.getMapObserver(items);
747 };
748 MapRepeatStrategy.prototype.instanceChanged = function (repeat, items) {
749 var _this = this;
750 var removePromise = repeat.removeAllViews(true, !repeat.viewsRequireLifecycle);
751 if (removePromise instanceof Promise) {
752 removePromise.then(function () { return _this._standardProcessItems(repeat, items); });
753 return;
754 }
755 this._standardProcessItems(repeat, items);
756 };
757 MapRepeatStrategy.prototype._standardProcessItems = function (repeat, items) {
758 var index = 0;
759 var overrideContext;
760 items.forEach(function (value, key) {
761 overrideContext = createFullOverrideContext(repeat, value, index, items.size, key);
762 repeat.addView(overrideContext.bindingContext, overrideContext);
763 ++index;
764 });
765 };
766 MapRepeatStrategy.prototype.instanceMutated = function (repeat, map, records) {
767 var key;
768 var i;
769 var ii;
770 var overrideContext;
771 var removeIndex;
772 var addIndex;
773 var record;
774 var rmPromises = [];
775 var viewOrPromise;
776 for (i = 0, ii = records.length; i < ii; ++i) {
777 record = records[i];
778 key = record.key;
779 switch (record.type) {
780 case 'update':
781 removeIndex = this._getViewIndexByKey(repeat, key);
782 viewOrPromise = repeat.removeView(removeIndex, true, !repeat.viewsRequireLifecycle);
783 if (viewOrPromise instanceof Promise) {
784 rmPromises.push(viewOrPromise);
785 }
786 overrideContext = createFullOverrideContext(repeat, map.get(key), removeIndex, map.size, key);
787 repeat.insertView(removeIndex, overrideContext.bindingContext, overrideContext);
788 break;
789 case 'add':
790 addIndex = repeat.viewCount() <= map.size - 1 ? repeat.viewCount() : map.size - 1;
791 overrideContext = createFullOverrideContext(repeat, map.get(key), addIndex, map.size, key);
792 repeat.insertView(map.size - 1, overrideContext.bindingContext, overrideContext);
793 break;
794 case 'delete':
795 if (record.oldValue === undefined) {
796 return;
797 }
798 removeIndex = this._getViewIndexByKey(repeat, key);
799 viewOrPromise = repeat.removeView(removeIndex, true, !repeat.viewsRequireLifecycle);
800 if (viewOrPromise instanceof Promise) {
801 rmPromises.push(viewOrPromise);
802 }
803 break;
804 case 'clear':
805 repeat.removeAllViews(true, !repeat.viewsRequireLifecycle);
806 break;
807 default:
808 continue;
809 }
810 }
811 if (rmPromises.length > 0) {
812 Promise.all(rmPromises).then(function () {
813 updateOverrideContexts(repeat.views(), 0);
814 });
815 }
816 else {
817 updateOverrideContexts(repeat.views(), 0);
818 }
819 };
820 MapRepeatStrategy.prototype._getViewIndexByKey = function (repeat, key) {
821 var i;
822 var ii;
823 var child;
824 for (i = 0, ii = repeat.viewCount(); i < ii; ++i) {
825 child = repeat.view(i);
826 if (child.bindingContext[repeat.key] === key) {
827 return i;
828 }
829 }
830 return undefined;
831 };
832 return MapRepeatStrategy;
833 }()));
834
835 var NullRepeatStrategy = exports('NullRepeatStrategy', (function () {
836 function NullRepeatStrategy() {
837 }
838 NullRepeatStrategy.prototype.instanceChanged = function (repeat, items) {
839 repeat.removeAllViews(true);
840 };
841 NullRepeatStrategy.prototype.getCollectionObserver = function (observerLocator, items) {
842 };
843 return NullRepeatStrategy;
844 }()));
845
846 var NumberRepeatStrategy = exports('NumberRepeatStrategy', (function () {
847 function NumberRepeatStrategy() {
848 }
849 NumberRepeatStrategy.prototype.getCollectionObserver = function () {
850 return null;
851 };
852 NumberRepeatStrategy.prototype.instanceChanged = function (repeat, value) {
853 var _this = this;
854 var removePromise = repeat.removeAllViews(true, !repeat.viewsRequireLifecycle);
855 if (removePromise instanceof Promise) {
856 removePromise.then(function () { return _this._standardProcessItems(repeat, value); });
857 return;
858 }
859 this._standardProcessItems(repeat, value);
860 };
861 NumberRepeatStrategy.prototype._standardProcessItems = function (repeat, value) {
862 var childrenLength = repeat.viewCount();
863 var i;
864 var ii;
865 var overrideContext;
866 var viewsToRemove;
867 value = Math.floor(value);
868 viewsToRemove = childrenLength - value;
869 if (viewsToRemove > 0) {
870 if (viewsToRemove > childrenLength) {
871 viewsToRemove = childrenLength;
872 }
873 for (i = 0, ii = viewsToRemove; i < ii; ++i) {
874 repeat.removeView(childrenLength - (i + 1), true, !repeat.viewsRequireLifecycle);
875 }
876 return;
877 }
878 for (i = childrenLength, ii = value; i < ii; ++i) {
879 overrideContext = createFullOverrideContext(repeat, i, i, ii);
880 repeat.addView(overrideContext.bindingContext, overrideContext);
881 }
882 updateOverrideContexts(repeat.views(), 0);
883 };
884 return NumberRepeatStrategy;
885 }()));
886
887 var SetRepeatStrategy = exports('SetRepeatStrategy', (function () {
888 function SetRepeatStrategy() {
889 }
890 SetRepeatStrategy.prototype.getCollectionObserver = function (observerLocator, items) {
891 return observerLocator.getSetObserver(items);
892 };
893 SetRepeatStrategy.prototype.instanceChanged = function (repeat, items) {
894 var _this = this;
895 var removePromise = repeat.removeAllViews(true, !repeat.viewsRequireLifecycle);
896 if (removePromise instanceof Promise) {
897 removePromise.then(function () { return _this._standardProcessItems(repeat, items); });
898 return;
899 }
900 this._standardProcessItems(repeat, items);
901 };
902 SetRepeatStrategy.prototype._standardProcessItems = function (repeat, items) {
903 var index = 0;
904 var overrideContext;
905 items.forEach(function (value) {
906 overrideContext = createFullOverrideContext(repeat, value, index, items.size);
907 repeat.addView(overrideContext.bindingContext, overrideContext);
908 ++index;
909 });
910 };
911 SetRepeatStrategy.prototype.instanceMutated = function (repeat, set, records) {
912 var value;
913 var i;
914 var ii;
915 var overrideContext;
916 var removeIndex;
917 var record;
918 var rmPromises = [];
919 var viewOrPromise;
920 for (i = 0, ii = records.length; i < ii; ++i) {
921 record = records[i];
922 value = record.value;
923 switch (record.type) {
924 case 'add':
925 var size = Math.max(set.size - 1, 0);
926 overrideContext = createFullOverrideContext(repeat, value, size, set.size);
927 repeat.insertView(size, overrideContext.bindingContext, overrideContext);
928 break;
929 case 'delete':
930 removeIndex = this._getViewIndexByValue(repeat, value);
931 viewOrPromise = repeat.removeView(removeIndex, true, !repeat.viewsRequireLifecycle);
932 if (viewOrPromise instanceof Promise) {
933 rmPromises.push(viewOrPromise);
934 }
935 break;
936 case 'clear':
937 repeat.removeAllViews(true, !repeat.viewsRequireLifecycle);
938 break;
939 default:
940 continue;
941 }
942 }
943 if (rmPromises.length > 0) {
944 Promise.all(rmPromises).then(function () {
945 updateOverrideContexts(repeat.views(), 0);
946 });
947 }
948 else {
949 updateOverrideContexts(repeat.views(), 0);
950 }
951 };
952 SetRepeatStrategy.prototype._getViewIndexByValue = function (repeat, value) {
953 var i;
954 var ii;
955 var child;
956 for (i = 0, ii = repeat.viewCount(); i < ii; ++i) {
957 child = repeat.view(i);
958 if (child.bindingContext[repeat.local] === value) {
959 return i;
960 }
961 }
962 return undefined;
963 };
964 return SetRepeatStrategy;
965 }()));
966
967 var RepeatStrategyLocator = exports('RepeatStrategyLocator', (function () {
968 function RepeatStrategyLocator() {
969 this.matchers = [];
970 this.strategies = [];
971 this.addStrategy(function (items) { return items === null || items === undefined; }, new NullRepeatStrategy());
972 this.addStrategy(function (items) { return items instanceof Array; }, new ArrayRepeatStrategy());
973 this.addStrategy(function (items) { return items instanceof Map; }, new MapRepeatStrategy());
974 this.addStrategy(function (items) { return items instanceof Set; }, new SetRepeatStrategy());
975 this.addStrategy(function (items) { return typeof items === 'number'; }, new NumberRepeatStrategy());
976 }
977 RepeatStrategyLocator.prototype.addStrategy = function (matcher, strategy) {
978 this.matchers.push(matcher);
979 this.strategies.push(strategy);
980 };
981 RepeatStrategyLocator.prototype.getStrategy = function (items) {
982 var matchers = this.matchers;
983 for (var i = 0, ii = matchers.length; i < ii; ++i) {
984 if (matchers[i](items)) {
985 return this.strategies[i];
986 }
987 }
988 return null;
989 };
990 return RepeatStrategyLocator;
991 }()));
992
993 var lifecycleOptionalBehaviors = ['focus', 'if', 'else', 'repeat', 'show', 'hide', 'with'];
994 function behaviorRequiresLifecycle(instruction) {
995 var t = instruction.type;
996 var name = t.elementName !== null ? t.elementName : t.attributeName;
997 return lifecycleOptionalBehaviors.indexOf(name) === -1 && (t.handlesAttached || t.handlesBind || t.handlesCreated || t.handlesDetached || t.handlesUnbind)
998 || t.viewFactory && viewsRequireLifecycle(t.viewFactory)
999 || instruction.viewFactory && viewsRequireLifecycle(instruction.viewFactory);
1000 }
1001 function targetRequiresLifecycle(instruction) {
1002 var behaviors = instruction.behaviorInstructions;
1003 if (behaviors) {
1004 var i = behaviors.length;
1005 while (i--) {
1006 if (behaviorRequiresLifecycle(behaviors[i])) {
1007 return true;
1008 }
1009 }
1010 }
1011 return instruction.viewFactory && viewsRequireLifecycle(instruction.viewFactory);
1012 }
1013 function viewsRequireLifecycle(viewFactory) {
1014 if ('_viewsRequireLifecycle' in viewFactory) {
1015 return viewFactory._viewsRequireLifecycle;
1016 }
1017 viewFactory._viewsRequireLifecycle = false;
1018 if (viewFactory.viewFactory) {
1019 viewFactory._viewsRequireLifecycle = viewsRequireLifecycle(viewFactory.viewFactory);
1020 return viewFactory._viewsRequireLifecycle;
1021 }
1022 if (viewFactory.template.querySelector('.au-animate')) {
1023 viewFactory._viewsRequireLifecycle = true;
1024 return true;
1025 }
1026 for (var id in viewFactory.instructions) {
1027 if (targetRequiresLifecycle(viewFactory.instructions[id])) {
1028 viewFactory._viewsRequireLifecycle = true;
1029 return true;
1030 }
1031 }
1032 viewFactory._viewsRequireLifecycle = false;
1033 return false;
1034 }
1035
1036 var AbstractRepeater = exports('AbstractRepeater', (function () {
1037 function AbstractRepeater(options) {
1038 Object.assign(this, {
1039 local: 'items',
1040 viewsRequireLifecycle: true
1041 }, options);
1042 }
1043 AbstractRepeater.prototype.viewCount = function () {
1044 throw new Error('subclass must implement `viewCount`');
1045 };
1046 AbstractRepeater.prototype.views = function () {
1047 throw new Error('subclass must implement `views`');
1048 };
1049 AbstractRepeater.prototype.view = function (index) {
1050 throw new Error('subclass must implement `view`');
1051 };
1052 AbstractRepeater.prototype.matcher = function () {
1053 throw new Error('subclass must implement `matcher`');
1054 };
1055 AbstractRepeater.prototype.addView = function (bindingContext, overrideContext) {
1056 throw new Error('subclass must implement `addView`');
1057 };
1058 AbstractRepeater.prototype.insertView = function (index, bindingContext, overrideContext) {
1059 throw new Error('subclass must implement `insertView`');
1060 };
1061 AbstractRepeater.prototype.moveView = function (sourceIndex, targetIndex) {
1062 throw new Error('subclass must implement `moveView`');
1063 };
1064 AbstractRepeater.prototype.removeAllViews = function (returnToCache, skipAnimation) {
1065 throw new Error('subclass must implement `removeAllViews`');
1066 };
1067 AbstractRepeater.prototype.removeViews = function (viewsToRemove, returnToCache, skipAnimation) {
1068 throw new Error('subclass must implement `removeView`');
1069 };
1070 AbstractRepeater.prototype.removeView = function (index, returnToCache, skipAnimation) {
1071 throw new Error('subclass must implement `removeView`');
1072 };
1073 AbstractRepeater.prototype.updateBindings = function (view) {
1074 throw new Error('subclass must implement `updateBindings`');
1075 };
1076 return AbstractRepeater;
1077 }()));
1078
1079 var matcherExtractionMarker = '__marker_extracted__';
1080 var Repeat = exports('Repeat', (function (_super) {
1081 __extends(Repeat, _super);
1082 function Repeat(viewFactory, instruction, viewSlot, viewResources, observerLocator, strategyLocator) {
1083 var _this = _super.call(this, {
1084 local: 'item',
1085 viewsRequireLifecycle: viewsRequireLifecycle(viewFactory)
1086 }) || this;
1087 _this.viewFactory = viewFactory;
1088 _this.instruction = instruction;
1089 _this.viewSlot = viewSlot;
1090 _this.lookupFunctions = viewResources.lookupFunctions;
1091 _this.observerLocator = observerLocator;
1092 _this.key = 'key';
1093 _this.value = 'value';
1094 _this.strategyLocator = strategyLocator;
1095 _this.ignoreMutation = false;
1096 _this.sourceExpression = getItemsSourceExpression(_this.instruction, 'repeat.for');
1097 _this.isOneTime = isOneTime(_this.sourceExpression);
1098 _this.viewsRequireLifecycle = viewsRequireLifecycle(viewFactory);
1099 return _this;
1100 }
1101 Repeat_1 = Repeat;
1102 Repeat.prototype.call = function (context, changes) {
1103 this[context](this.items, changes);
1104 };
1105 Repeat.prototype.bind = function (bindingContext, overrideContext) {
1106 this.scope = { bindingContext: bindingContext, overrideContext: overrideContext };
1107 var instruction = this.instruction;
1108 if (!(matcherExtractionMarker in instruction)) {
1109 instruction[matcherExtractionMarker] = this._captureAndRemoveMatcherBinding();
1110 }
1111 this.matcherBinding = instruction[matcherExtractionMarker];
1112 this.itemsChanged();
1113 };
1114 Repeat.prototype.unbind = function () {
1115 this.scope = null;
1116 this.items = null;
1117 this.matcherBinding = null;
1118 this.viewSlot.removeAll(true, true);
1119 this._unsubscribeCollection();
1120 };
1121 Repeat.prototype._unsubscribeCollection = function () {
1122 if (this.collectionObserver) {
1123 this.collectionObserver.unsubscribe(this.callContext, this);
1124 this.collectionObserver = null;
1125 this.callContext = null;
1126 }
1127 };
1128 Repeat.prototype.itemsChanged = function () {
1129 var _this = this;
1130 this._unsubscribeCollection();
1131 if (!this.scope) {
1132 return;
1133 }
1134 var items = this.items;
1135 this.strategy = this.strategyLocator.getStrategy(items);
1136 if (!this.strategy) {
1137 throw new Error("Value for '" + this.sourceExpression + "' is non-repeatable");
1138 }
1139 if (!this.isOneTime && !this._observeInnerCollection()) {
1140 this._observeCollection();
1141 }
1142 this.ignoreMutation = true;
1143 this.strategy.instanceChanged(this, items);
1144 this.observerLocator.taskQueue.queueMicroTask(function () {
1145 _this.ignoreMutation = false;
1146 });
1147 };
1148 Repeat.prototype._getInnerCollection = function () {
1149 var expression = unwrapExpression(this.sourceExpression);
1150 if (!expression) {
1151 return null;
1152 }
1153 return expression.evaluate(this.scope, null);
1154 };
1155 Repeat.prototype.handleCollectionMutated = function (collection, changes) {
1156 if (!this.collectionObserver) {
1157 return;
1158 }
1159 if (this.ignoreMutation) {
1160 return;
1161 }
1162 this.strategy.instanceMutated(this, collection, changes);
1163 };
1164 Repeat.prototype.handleInnerCollectionMutated = function (collection, changes) {
1165 var _this = this;
1166 if (!this.collectionObserver) {
1167 return;
1168 }
1169 if (this.ignoreMutation) {
1170 return;
1171 }
1172 this.ignoreMutation = true;
1173 var newItems = this.sourceExpression.evaluate(this.scope, this.lookupFunctions);
1174 this.observerLocator.taskQueue.queueMicroTask(function () { return _this.ignoreMutation = false; });
1175 if (newItems === this.items) {
1176 this.itemsChanged();
1177 }
1178 else {
1179 this.items = newItems;
1180 }
1181 };
1182 Repeat.prototype._observeInnerCollection = function () {
1183 var items = this._getInnerCollection();
1184 var strategy = this.strategyLocator.getStrategy(items);
1185 if (!strategy) {
1186 return false;
1187 }
1188 this.collectionObserver = strategy.getCollectionObserver(this.observerLocator, items);
1189 if (!this.collectionObserver) {
1190 return false;
1191 }
1192 this.callContext = 'handleInnerCollectionMutated';
1193 this.collectionObserver.subscribe(this.callContext, this);
1194 return true;
1195 };
1196 Repeat.prototype._observeCollection = function () {
1197 var items = this.items;
1198 this.collectionObserver = this.strategy.getCollectionObserver(this.observerLocator, items);
1199 if (this.collectionObserver) {
1200 this.callContext = 'handleCollectionMutated';
1201 this.collectionObserver.subscribe(this.callContext, this);
1202 }
1203 };
1204 Repeat.prototype._captureAndRemoveMatcherBinding = function () {
1205 var viewFactory = this.viewFactory.viewFactory;
1206 if (viewFactory) {
1207 var template = viewFactory.template;
1208 var instructions = viewFactory.instructions;
1209 if (Repeat_1.useInnerMatcher) {
1210 return extractMatcherBindingExpression(instructions);
1211 }
1212 if (getChildrenCount(template) > 1) {
1213 return undefined;
1214 }
1215 var repeatedElement = getFirstElementChild(template);
1216 if (!repeatedElement.hasAttribute('au-target-id')) {
1217 return undefined;
1218 }
1219 var repeatedElementTargetId = repeatedElement.getAttribute('au-target-id');
1220 return extractMatcherBindingExpression(instructions, repeatedElementTargetId);
1221 }
1222 return undefined;
1223 };
1224 Repeat.prototype.viewCount = function () { return this.viewSlot.children.length; };
1225 Repeat.prototype.views = function () { return this.viewSlot.children; };
1226 Repeat.prototype.view = function (index) { return this.viewSlot.children[index]; };
1227 Repeat.prototype.matcher = function () {
1228 var matcherBinding = this.matcherBinding;
1229 return matcherBinding
1230 ? matcherBinding.sourceExpression.evaluate(this.scope, matcherBinding.lookupFunctions)
1231 : null;
1232 };
1233 Repeat.prototype.addView = function (bindingContext, overrideContext) {
1234 var view = this.viewFactory.create();
1235 view.bind(bindingContext, overrideContext);
1236 this.viewSlot.add(view);
1237 };
1238 Repeat.prototype.insertView = function (index, bindingContext, overrideContext) {
1239 var view = this.viewFactory.create();
1240 view.bind(bindingContext, overrideContext);
1241 this.viewSlot.insert(index, view);
1242 };
1243 Repeat.prototype.moveView = function (sourceIndex, targetIndex) {
1244 this.viewSlot.move(sourceIndex, targetIndex);
1245 };
1246 Repeat.prototype.removeAllViews = function (returnToCache, skipAnimation) {
1247 return this.viewSlot.removeAll(returnToCache, skipAnimation);
1248 };
1249 Repeat.prototype.removeViews = function (viewsToRemove, returnToCache, skipAnimation) {
1250 return this.viewSlot.removeMany(viewsToRemove, returnToCache, skipAnimation);
1251 };
1252 Repeat.prototype.removeView = function (index, returnToCache, skipAnimation) {
1253 return this.viewSlot.removeAt(index, returnToCache, skipAnimation);
1254 };
1255 Repeat.prototype.updateBindings = function (view) {
1256 var $view = view;
1257 var j = $view.bindings.length;
1258 while (j--) {
1259 updateOneTimeBinding($view.bindings[j]);
1260 }
1261 j = $view.controllers.length;
1262 while (j--) {
1263 var k = $view.controllers[j].boundProperties.length;
1264 while (k--) {
1265 var binding = $view.controllers[j].boundProperties[k].binding;
1266 updateOneTimeBinding(binding);
1267 }
1268 }
1269 };
1270 var Repeat_1;
1271 Repeat.useInnerMatcher = true;
1272 __decorate([
1273 bindable
1274 ], Repeat.prototype, "items", void 0);
1275 __decorate([
1276 bindable
1277 ], Repeat.prototype, "local", void 0);
1278 __decorate([
1279 bindable
1280 ], Repeat.prototype, "key", void 0);
1281 __decorate([
1282 bindable
1283 ], Repeat.prototype, "value", void 0);
1284 Repeat = Repeat_1 = __decorate([
1285 customAttribute('repeat'),
1286 templateController,
1287 inject(BoundViewFactory, TargetInstruction, ViewSlot, ViewResources, ObserverLocator, RepeatStrategyLocator)
1288 ], Repeat);
1289 return Repeat;
1290 }(AbstractRepeater)));
1291 var extractMatcherBindingExpression = function (instructions, targetedElementId) {
1292 var instructionIds = Object.keys(instructions);
1293 for (var i = 0; i < instructionIds.length; i++) {
1294 var instructionId = instructionIds[i];
1295 if (targetedElementId !== undefined && instructionId !== targetedElementId) {
1296 continue;
1297 }
1298 var expressions = instructions[instructionId].expressions;
1299 if (expressions) {
1300 for (var ii = 0; ii < expressions.length; ii++) {
1301 if (expressions[ii].targetProperty === 'matcher') {
1302 var matcherBindingExpression = expressions[ii];
1303 expressions.splice(ii, 1);
1304 return matcherBindingExpression;
1305 }
1306 }
1307 }
1308 }
1309 };
1310 var getChildrenCount = function (el) {
1311 var childNodes = el.childNodes;
1312 var count = 0;
1313 for (var i = 0, ii = childNodes.length; ii > i; ++i) {
1314 if (childNodes[i].nodeType === 1) {
1315 ++count;
1316 }
1317 }
1318 return count;
1319 };
1320 var getFirstElementChild = function (el) {
1321 var firstChild = el.firstChild;
1322 while (firstChild !== null) {
1323 if (firstChild.nodeType === 1) {
1324 return firstChild;
1325 }
1326 firstChild = firstChild.nextSibling;
1327 }
1328 return null;
1329 };
1330
1331 var aureliaHideClassName = 'aurelia-hide';
1332 var aureliaHideClass = "." + aureliaHideClassName + " { display:none !important; }";
1333 function injectAureliaHideStyleAtHead() {
1334 DOM.injectStyles(aureliaHideClass);
1335 }
1336 function injectAureliaHideStyleAtBoundary(domBoundary) {
1337 if (FEATURE.shadowDOM && domBoundary && !domBoundary.hasAureliaHideStyle) {
1338 domBoundary.hasAureliaHideStyle = true;
1339 DOM.injectStyles(aureliaHideClass, domBoundary);
1340 }
1341 }
1342
1343 var Show = exports('Show', (function () {
1344 function Show(element, animator, domBoundary) {
1345 this.element = element;
1346 this.animator = animator;
1347 this.domBoundary = domBoundary;
1348 }
1349 Show.inject = function () {
1350 return [DOM.Element, Animator, Optional.of(DOM.boundary, true)];
1351 };
1352 Show.prototype.created = function () {
1353 injectAureliaHideStyleAtBoundary(this.domBoundary);
1354 };
1355 Show.prototype.valueChanged = function (newValue) {
1356 var element = this.element;
1357 var animator = this.animator;
1358 if (newValue) {
1359 animator.removeClass(element, aureliaHideClassName);
1360 }
1361 else {
1362 animator.addClass(element, aureliaHideClassName);
1363 }
1364 };
1365 Show.prototype.bind = function (bindingContext) {
1366 this.valueChanged(this.value);
1367 };
1368 Show = __decorate([
1369 customAttribute('show')
1370 ], Show);
1371 return Show;
1372 }()));
1373
1374 var Hide = exports('Hide', (function () {
1375 function Hide(element, animator, domBoundary) {
1376 this.element = element;
1377 this.animator = animator;
1378 this.domBoundary = domBoundary;
1379 }
1380 Hide.inject = function () {
1381 return [DOM.Element, Animator, Optional.of(DOM.boundary, true)];
1382 };
1383 Hide.prototype.created = function () {
1384 injectAureliaHideStyleAtBoundary(this.domBoundary);
1385 };
1386 Hide.prototype.valueChanged = function (newValue) {
1387 if (newValue) {
1388 this.animator.addClass(this.element, aureliaHideClassName);
1389 }
1390 else {
1391 this.animator.removeClass(this.element, aureliaHideClassName);
1392 }
1393 };
1394 Hide.prototype.bind = function (bindingContext) {
1395 this.valueChanged(this.value);
1396 };
1397 Hide.prototype.value = function (value) {
1398 throw new Error('Method not implemented.');
1399 };
1400 Hide = __decorate([
1401 customAttribute('hide')
1402 ], Hide);
1403 return Hide;
1404 }()));
1405
1406 var SCRIPT_REGEX = /<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi;
1407 var needsToWarn = true;
1408 var HTMLSanitizer = exports('HTMLSanitizer', (function () {
1409 function HTMLSanitizer() {
1410 }
1411 HTMLSanitizer.prototype.sanitize = function (input) {
1412 if (needsToWarn) {
1413 needsToWarn = false;
1414 getLogger('html-sanitizer')
1415 .warn("CAUTION: The default HTMLSanitizer does NOT provide security against a wide variety of sophisticated XSS attacks,\nand should not be relied on for sanitizing input from unknown sources.\nPlease see https://aurelia.io/docs/binding/basics#element-content for instructions on how to use a secure solution like DOMPurify or sanitize-html.");
1416 }
1417 return input.replace(SCRIPT_REGEX, '');
1418 };
1419 return HTMLSanitizer;
1420 }()));
1421
1422 var SanitizeHTMLValueConverter = exports('SanitizeHTMLValueConverter', (function () {
1423 function SanitizeHTMLValueConverter(sanitizer) {
1424 this.sanitizer = sanitizer;
1425 }
1426 SanitizeHTMLValueConverter.prototype.toView = function (untrustedMarkup) {
1427 if (untrustedMarkup === null || untrustedMarkup === undefined) {
1428 return null;
1429 }
1430 return this.sanitizer.sanitize(untrustedMarkup);
1431 };
1432 SanitizeHTMLValueConverter = __decorate([
1433 valueConverter('sanitizeHTML'),
1434 inject(HTMLSanitizer)
1435 ], SanitizeHTMLValueConverter);
1436 return SanitizeHTMLValueConverter;
1437 }()));
1438
1439 var Replaceable = exports('Replaceable', (function () {
1440 function Replaceable(viewFactory, viewSlot) {
1441 this.viewFactory = viewFactory;
1442 this.viewSlot = viewSlot;
1443 this.view = null;
1444 }
1445 Replaceable.prototype.bind = function (bindingContext, overrideContext) {
1446 if (this.view === null) {
1447 this.view = this.viewFactory.create();
1448 this.viewSlot.add(this.view);
1449 }
1450 this.view.bind(bindingContext, overrideContext);
1451 };
1452 Replaceable.prototype.unbind = function () {
1453 this.view.unbind();
1454 };
1455 Replaceable = __decorate([
1456 customAttribute('replaceable'),
1457 templateController,
1458 inject(BoundViewFactory, ViewSlot)
1459 ], Replaceable);
1460 return Replaceable;
1461 }()));
1462
1463 var Focus = exports('Focus', (function () {
1464 function Focus(element, taskQueue) {
1465 this.element = element;
1466 this.taskQueue = taskQueue;
1467 this.isAttached = false;
1468 this.needsApply = false;
1469 }
1470 Focus.inject = function () {
1471 return [DOM.Element, TaskQueue];
1472 };
1473 Focus.prototype.valueChanged = function (newValue) {
1474 if (this.isAttached) {
1475 this._apply();
1476 }
1477 else {
1478 this.needsApply = true;
1479 }
1480 };
1481 Focus.prototype._apply = function () {
1482 var _this = this;
1483 if (this.value) {
1484 this.taskQueue.queueMicroTask(function () {
1485 if (_this.value) {
1486 _this.element.focus();
1487 }
1488 });
1489 }
1490 else {
1491 this.element.blur();
1492 }
1493 };
1494 Focus.prototype.attached = function () {
1495 this.isAttached = true;
1496 if (this.needsApply) {
1497 this.needsApply = false;
1498 this._apply();
1499 }
1500 this.element.addEventListener('focus', this);
1501 this.element.addEventListener('blur', this);
1502 };
1503 Focus.prototype.detached = function () {
1504 this.isAttached = false;
1505 this.element.removeEventListener('focus', this);
1506 this.element.removeEventListener('blur', this);
1507 };
1508 Focus.prototype.handleEvent = function (e) {
1509 if (e.type === 'focus') {
1510 this.value = true;
1511 }
1512 else if (DOM.activeElement !== this.element) {
1513 this.value = false;
1514 }
1515 };
1516 Focus = __decorate([
1517 customAttribute('focus', bindingMode.twoWay)
1518 ], Focus);
1519 return Focus;
1520 }()));
1521
1522 var cssUrlMatcher = /url\((?!['"]data)([^)]+)\)/gi;
1523 function fixupCSSUrls(address, css) {
1524 if (typeof css !== 'string') {
1525 throw new Error("Failed loading required CSS file: " + address);
1526 }
1527 return css.replace(cssUrlMatcher, function (match, p1) {
1528 var quote = p1.charAt(0);
1529 if (quote === '\'' || quote === '"') {
1530 p1 = p1.substr(1, p1.length - 2);
1531 }
1532 return 'url(\'' + relativeToFile(p1, address) + '\')';
1533 });
1534 }
1535 var CSSResource = (function () {
1536 function CSSResource(address) {
1537 this.address = address;
1538 this._scoped = null;
1539 this._global = false;
1540 this._alreadyGloballyInjected = false;
1541 }
1542 CSSResource.prototype.initialize = function (container, Target) {
1543 this._scoped = new Target(this);
1544 };
1545 CSSResource.prototype.register = function (registry, name) {
1546 if (name === 'scoped') {
1547 registry.registerViewEngineHooks(this._scoped);
1548 }
1549 else {
1550 this._global = true;
1551 }
1552 };
1553 CSSResource.prototype.load = function (container) {
1554 var _this = this;
1555 return container.get(Loader)
1556 .loadText(this.address)
1557 .catch(function (err) { return null; })
1558 .then(function (text) {
1559 text = fixupCSSUrls(_this.address, text);
1560 _this._scoped.css = text;
1561 if (_this._global) {
1562 _this._alreadyGloballyInjected = true;
1563 DOM.injectStyles(text);
1564 }
1565 });
1566 };
1567 return CSSResource;
1568 }());
1569 var CSSViewEngineHooks = (function () {
1570 function CSSViewEngineHooks(owner) {
1571 this.owner = owner;
1572 this.css = null;
1573 }
1574 CSSViewEngineHooks.prototype.beforeCompile = function (content, resources, instruction) {
1575 if (instruction.targetShadowDOM) {
1576 DOM.injectStyles(this.css, content, true);
1577 }
1578 else if (FEATURE.scopedCSS) {
1579 var styleNode = DOM.injectStyles(this.css, content, true);
1580 styleNode.setAttribute('scoped', 'scoped');
1581 }
1582 else if (this._global && !this.owner._alreadyGloballyInjected) {
1583 DOM.injectStyles(this.css);
1584 this.owner._alreadyGloballyInjected = true;
1585 }
1586 };
1587 return CSSViewEngineHooks;
1588 }());
1589 function _createCSSResource(address) {
1590 var ViewCSS = (function (_super) {
1591 __extends(ViewCSS, _super);
1592 function ViewCSS() {
1593 return _super !== null && _super.apply(this, arguments) || this;
1594 }
1595 ViewCSS = __decorate([
1596 resource(new CSSResource(address))
1597 ], ViewCSS);
1598 return ViewCSS;
1599 }(CSSViewEngineHooks));
1600 return ViewCSS;
1601 }
1602
1603 var AttrBindingBehavior = exports('AttrBindingBehavior', (function () {
1604 function AttrBindingBehavior() {
1605 }
1606 AttrBindingBehavior.prototype.bind = function (binding, source) {
1607 binding.targetObserver = new DataAttributeObserver(binding.target, binding.targetProperty);
1608 };
1609 AttrBindingBehavior.prototype.unbind = function (binding, source) {
1610 };
1611 AttrBindingBehavior = __decorate([
1612 bindingBehavior('attr')
1613 ], AttrBindingBehavior);
1614 return AttrBindingBehavior;
1615 }()));
1616
1617 var modeBindingBehavior = {
1618 bind: function (binding, source, lookupFunctions) {
1619 binding.originalMode = binding.mode;
1620 binding.mode = this.mode;
1621 },
1622 unbind: function (binding, source) {
1623 binding.mode = binding.originalMode;
1624 binding.originalMode = null;
1625 }
1626 };
1627 var OneTimeBindingBehavior = exports('OneTimeBindingBehavior', (function () {
1628 function OneTimeBindingBehavior() {
1629 this.mode = bindingMode.oneTime;
1630 }
1631 OneTimeBindingBehavior = __decorate([
1632 mixin(modeBindingBehavior),
1633 bindingBehavior('oneTime')
1634 ], OneTimeBindingBehavior);
1635 return OneTimeBindingBehavior;
1636 }()));
1637 var OneWayBindingBehavior = exports('OneWayBindingBehavior', (function () {
1638 function OneWayBindingBehavior() {
1639 this.mode = bindingMode.toView;
1640 }
1641 OneWayBindingBehavior = __decorate([
1642 mixin(modeBindingBehavior),
1643 bindingBehavior('oneWay')
1644 ], OneWayBindingBehavior);
1645 return OneWayBindingBehavior;
1646 }()));
1647 var ToViewBindingBehavior = exports('ToViewBindingBehavior', (function () {
1648 function ToViewBindingBehavior() {
1649 this.mode = bindingMode.toView;
1650 }
1651 ToViewBindingBehavior = __decorate([
1652 mixin(modeBindingBehavior),
1653 bindingBehavior('toView')
1654 ], ToViewBindingBehavior);
1655 return ToViewBindingBehavior;
1656 }()));
1657 var FromViewBindingBehavior = exports('FromViewBindingBehavior', (function () {
1658 function FromViewBindingBehavior() {
1659 this.mode = bindingMode.fromView;
1660 }
1661 FromViewBindingBehavior = __decorate([
1662 mixin(modeBindingBehavior),
1663 bindingBehavior('fromView')
1664 ], FromViewBindingBehavior);
1665 return FromViewBindingBehavior;
1666 }()));
1667 var TwoWayBindingBehavior = exports('TwoWayBindingBehavior', (function () {
1668 function TwoWayBindingBehavior() {
1669 this.mode = bindingMode.twoWay;
1670 }
1671 TwoWayBindingBehavior = __decorate([
1672 mixin(modeBindingBehavior),
1673 bindingBehavior('twoWay')
1674 ], TwoWayBindingBehavior);
1675 return TwoWayBindingBehavior;
1676 }()));
1677
1678 function throttle(newValue) {
1679 var _this = this;
1680 var state = this.throttleState;
1681 var elapsed = +new Date() - state.last;
1682 if (elapsed >= state.delay) {
1683 clearTimeout(state.timeoutId);
1684 state.timeoutId = null;
1685 state.last = +new Date();
1686 this.throttledMethod(newValue);
1687 return;
1688 }
1689 state.newValue = newValue;
1690 if (state.timeoutId === null) {
1691 state.timeoutId = setTimeout(function () {
1692 state.timeoutId = null;
1693 state.last = +new Date();
1694 _this.throttledMethod(state.newValue);
1695 }, state.delay - elapsed);
1696 }
1697 }
1698 var ThrottleBindingBehavior = exports('ThrottleBindingBehavior', (function () {
1699 function ThrottleBindingBehavior() {
1700 }
1701 ThrottleBindingBehavior.prototype.bind = function (binding, source, delay) {
1702 if (delay === void 0) { delay = 200; }
1703 var methodToThrottle = 'updateTarget';
1704 if (binding.callSource) {
1705 methodToThrottle = 'callSource';
1706 }
1707 else if (binding.updateSource && binding.mode === bindingMode.twoWay) {
1708 methodToThrottle = 'updateSource';
1709 }
1710 binding.throttledMethod = binding[methodToThrottle];
1711 binding.throttledMethod.originalName = methodToThrottle;
1712 binding[methodToThrottle] = throttle;
1713 binding.throttleState = {
1714 delay: delay,
1715 last: 0,
1716 timeoutId: null
1717 };
1718 };
1719 ThrottleBindingBehavior.prototype.unbind = function (binding, source) {
1720 var methodToRestore = binding.throttledMethod.originalName;
1721 binding[methodToRestore] = binding.throttledMethod;
1722 binding.throttledMethod = null;
1723 clearTimeout(binding.throttleState.timeoutId);
1724 binding.throttleState = null;
1725 };
1726 ThrottleBindingBehavior = __decorate([
1727 bindingBehavior('throttle')
1728 ], ThrottleBindingBehavior);
1729 return ThrottleBindingBehavior;
1730 }()));
1731
1732 var unset = {};
1733 function debounceCallSource(event) {
1734 var _this = this;
1735 var state = this.debounceState;
1736 clearTimeout(state.timeoutId);
1737 state.timeoutId = setTimeout(function () { return _this.debouncedMethod(event); }, state.delay);
1738 }
1739 function debounceCall(context, newValue, oldValue) {
1740 var _this = this;
1741 var state = this.debounceState;
1742 clearTimeout(state.timeoutId);
1743 if (context !== state.callContextToDebounce) {
1744 state.oldValue = unset;
1745 this.debouncedMethod(context, newValue, oldValue);
1746 return;
1747 }
1748 if (state.oldValue === unset) {
1749 state.oldValue = oldValue;
1750 }
1751 state.timeoutId = setTimeout(function () {
1752 var _oldValue = state.oldValue;
1753 state.oldValue = unset;
1754 _this.debouncedMethod(context, newValue, _oldValue);
1755 }, state.delay);
1756 }
1757 var DebounceBindingBehavior = exports('DebounceBindingBehavior', (function () {
1758 function DebounceBindingBehavior() {
1759 }
1760 DebounceBindingBehavior.prototype.bind = function (binding, source, delay) {
1761 if (delay === void 0) { delay = 200; }
1762 var isCallSource = binding.callSource !== undefined;
1763 var methodToDebounce = isCallSource ? 'callSource' : 'call';
1764 var debouncer = isCallSource ? debounceCallSource : debounceCall;
1765 var mode = binding.mode;
1766 var callContextToDebounce = mode === bindingMode.twoWay || mode === bindingMode.fromView ? targetContext : sourceContext;
1767 binding.debouncedMethod = binding[methodToDebounce];
1768 binding.debouncedMethod.originalName = methodToDebounce;
1769 binding[methodToDebounce] = debouncer;
1770 binding.debounceState = {
1771 callContextToDebounce: callContextToDebounce,
1772 delay: delay,
1773 timeoutId: 0,
1774 oldValue: unset
1775 };
1776 };
1777 DebounceBindingBehavior.prototype.unbind = function (binding, source) {
1778 var methodToRestore = binding.debouncedMethod.originalName;
1779 binding[methodToRestore] = binding.debouncedMethod;
1780 binding.debouncedMethod = null;
1781 clearTimeout(binding.debounceState.timeoutId);
1782 binding.debounceState = null;
1783 };
1784 DebounceBindingBehavior = __decorate([
1785 bindingBehavior('debounce')
1786 ], DebounceBindingBehavior);
1787 return DebounceBindingBehavior;
1788 }()));
1789
1790 function findOriginalEventTarget(event) {
1791 return (event.path && event.path[0]) || (event.deepPath && event.deepPath[0]) || event.target;
1792 }
1793 function handleSelfEvent(event) {
1794 var target = findOriginalEventTarget(event);
1795 if (this.target !== target) {
1796 return;
1797 }
1798 this.selfEventCallSource(event);
1799 }
1800 var SelfBindingBehavior = exports('SelfBindingBehavior', (function () {
1801 function SelfBindingBehavior() {
1802 }
1803 SelfBindingBehavior.prototype.bind = function (binding, source) {
1804 if (!binding.callSource || !binding.targetEvent) {
1805 throw new Error('Self binding behavior only supports event.');
1806 }
1807 binding.selfEventCallSource = binding.callSource;
1808 binding.callSource = handleSelfEvent;
1809 };
1810 SelfBindingBehavior.prototype.unbind = function (binding, source) {
1811 binding.callSource = binding.selfEventCallSource;
1812 binding.selfEventCallSource = null;
1813 };
1814 SelfBindingBehavior = __decorate([
1815 bindingBehavior('self')
1816 ], SelfBindingBehavior);
1817 return SelfBindingBehavior;
1818 }()));
1819
1820 var BindingSignaler = exports('BindingSignaler', (function () {
1821 function BindingSignaler() {
1822 this.signals = {};
1823 }
1824 BindingSignaler.prototype.signal = function (name) {
1825 var bindings = this.signals[name];
1826 if (!bindings) {
1827 return;
1828 }
1829 var i = bindings.length;
1830 while (i--) {
1831 bindings[i].call(sourceContext);
1832 }
1833 };
1834 return BindingSignaler;
1835 }()));
1836
1837 var SignalBindingBehavior = exports('SignalBindingBehavior', (function () {
1838 function SignalBindingBehavior(bindingSignaler) {
1839 this.signals = bindingSignaler.signals;
1840 }
1841 SignalBindingBehavior.inject = function () { return [BindingSignaler]; };
1842 SignalBindingBehavior.prototype.bind = function (binding, source) {
1843 var names = [];
1844 for (var _i = 2; _i < arguments.length; _i++) {
1845 names[_i - 2] = arguments[_i];
1846 }
1847 if (!binding.updateTarget) {
1848 throw new Error('Only property bindings and string interpolation bindings can be signaled. Trigger, delegate and call bindings cannot be signaled.');
1849 }
1850 var signals = this.signals;
1851 if (names.length === 1) {
1852 var name_1 = names[0];
1853 var bindings = signals[name_1] || (signals[name_1] = []);
1854 bindings.push(binding);
1855 binding.signalName = name_1;
1856 }
1857 else if (names.length > 1) {
1858 var i = names.length;
1859 while (i--) {
1860 var name_2 = names[i];
1861 var bindings = signals[name_2] || (signals[name_2] = []);
1862 bindings.push(binding);
1863 }
1864 binding.signalName = names;
1865 }
1866 else {
1867 throw new Error('Signal name is required.');
1868 }
1869 };
1870 SignalBindingBehavior.prototype.unbind = function (binding, source) {
1871 var signals = this.signals;
1872 var name = binding.signalName;
1873 binding.signalName = null;
1874 if (Array.isArray(name)) {
1875 var names = name;
1876 var i = names.length;
1877 while (i--) {
1878 var n = names[i];
1879 var bindings = signals[n];
1880 bindings.splice(bindings.indexOf(binding), 1);
1881 }
1882 }
1883 else {
1884 var bindings = signals[name];
1885 bindings.splice(bindings.indexOf(binding), 1);
1886 }
1887 };
1888 SignalBindingBehavior = __decorate([
1889 bindingBehavior('signal')
1890 ], SignalBindingBehavior);
1891 return SignalBindingBehavior;
1892 }()));
1893
1894 var eventNamesRequired = 'The updateTrigger binding behavior requires at least one event name argument: eg <input value.bind="firstName & updateTrigger:\'blur\'">';
1895 var notApplicableMessage = 'The updateTrigger binding behavior can only be applied to two-way/ from-view bindings on input/select elements.';
1896 var UpdateTriggerBindingBehavior = exports('UpdateTriggerBindingBehavior', (function () {
1897 function UpdateTriggerBindingBehavior() {
1898 }
1899 UpdateTriggerBindingBehavior.prototype.bind = function (binding, source) {
1900 var events = [];
1901 for (var _i = 2; _i < arguments.length; _i++) {
1902 events[_i - 2] = arguments[_i];
1903 }
1904 if (events.length === 0) {
1905 throw new Error(eventNamesRequired);
1906 }
1907 if (binding.mode !== bindingMode.twoWay && binding.mode !== bindingMode.fromView) {
1908 throw new Error(notApplicableMessage);
1909 }
1910 var targetObserver = binding.observerLocator.getObserver(binding.target, binding.targetProperty);
1911 if (!targetObserver.handler) {
1912 throw new Error(notApplicableMessage);
1913 }
1914 binding.targetObserver = targetObserver;
1915 targetObserver.originalHandler = binding.targetObserver.handler;
1916 var handler = new EventSubscriber(events);
1917 targetObserver.handler = handler;
1918 };
1919 UpdateTriggerBindingBehavior.prototype.unbind = function (binding, source) {
1920 var targetObserver = binding.targetObserver;
1921 targetObserver.handler.dispose();
1922 targetObserver.handler = targetObserver.originalHandler;
1923 targetObserver.originalHandler = null;
1924 };
1925 UpdateTriggerBindingBehavior = __decorate([
1926 bindingBehavior('updateTrigger')
1927 ], UpdateTriggerBindingBehavior);
1928 return UpdateTriggerBindingBehavior;
1929 }()));
1930
1931 function _createDynamicElement(_a) {
1932 var name = _a.name, viewUrl = _a.viewUrl, bindableNames = _a.bindableNames, useShadowDOMmode = _a.useShadowDOMmode;
1933 var DynamicElement = (function () {
1934 function DynamicElement() {
1935 }
1936 DynamicElement.prototype.bind = function (bindingContext) {
1937 this.$parent = bindingContext;
1938 };
1939 DynamicElement = __decorate([
1940 customElement(name),
1941 useView(viewUrl)
1942 ], DynamicElement);
1943 return DynamicElement;
1944 }());
1945 for (var i = 0, ii = bindableNames.length; i < ii; ++i) {
1946 bindable(bindableNames[i])(DynamicElement);
1947 }
1948 switch (useShadowDOMmode) {
1949 case 'open':
1950 useShadowDOM({ mode: 'open' })(DynamicElement);
1951 break;
1952 case 'closed':
1953 useShadowDOM({ mode: 'closed' })(DynamicElement);
1954 break;
1955 case '':
1956 useShadowDOM(DynamicElement);
1957 break;
1958 case null:
1959 break;
1960 default:
1961 getLogger('aurelia-html-only-element')
1962 .warn("Expected 'use-shadow-dom' value to be \"close\", \"open\" or \"\", received " + useShadowDOMmode);
1963 break;
1964 }
1965 return DynamicElement;
1966 }
1967
1968 function getElementName(address) {
1969 return /([^\/^\?]+)\.html/i.exec(address)[1].toLowerCase();
1970 }
1971 function configure(config) {
1972 var viewEngine = config.container.get(ViewEngine);
1973 var loader = config.aurelia.loader;
1974 viewEngine.addResourcePlugin('.html', {
1975 'fetch': function (viewUrl) {
1976 return loader.loadTemplate(viewUrl).then(function (registryEntry) {
1977 var _a;
1978 var bindableNames = registryEntry.template.getAttribute('bindable');
1979 var useShadowDOMmode = registryEntry.template.getAttribute('use-shadow-dom');
1980 var name = getElementName(viewUrl);
1981 if (bindableNames) {
1982 bindableNames = bindableNames.split(',').map(function (x) { return x.trim(); });
1983 registryEntry.template.removeAttribute('bindable');
1984 }
1985 else {
1986 bindableNames = [];
1987 }
1988 return _a = {}, _a[name] = _createDynamicElement({ name: name, viewUrl: viewUrl, bindableNames: bindableNames, useShadowDOMmode: useShadowDOMmode }), _a;
1989 });
1990 }
1991 });
1992 }
1993
1994 function configure$1(config) {
1995 injectAureliaHideStyleAtHead();
1996 config.globalResources(Compose, If, Else, With, Repeat, Show, Hide, Replaceable, Focus, SanitizeHTMLValueConverter, OneTimeBindingBehavior, OneWayBindingBehavior, ToViewBindingBehavior, FromViewBindingBehavior, TwoWayBindingBehavior, ThrottleBindingBehavior, DebounceBindingBehavior, SelfBindingBehavior, SignalBindingBehavior, UpdateTriggerBindingBehavior, AttrBindingBehavior);
1997 configure(config);
1998 var viewEngine = config.container.get(ViewEngine);
1999 var styleResourcePlugin = {
2000 fetch: function (address) {
2001 var _a;
2002 return _a = {}, _a[address] = _createCSSResource(address), _a;
2003 }
2004 };
2005 ['.css', '.less', '.sass', '.scss', '.styl'].forEach(function (ext) { return viewEngine.addResourcePlugin(ext, styleResourcePlugin); });
2006 }
2007
2008 }
2009 };
2010});
2011//# sourceMappingURL=aurelia-templating-resources.js.map