1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 | import { __extends, __decorate, __param, __metadata, __read, __spread } from 'tslib';
|
8 | import { ViewEncapsulation, Injectable, Inject, RendererFactory2, NgZone, InjectionToken, NgModule } from '@angular/core';
|
9 | import { ɵDomRendererFactory2, BrowserModule } from '@angular/platform-browser';
|
10 | import { sequence, AnimationBuilder, AnimationFactory } from '@angular/animations';
|
11 | import { ɵAnimationEngine, AnimationDriver, ɵAnimationStyleNormalizer, ɵsupportsWebAnimations, ɵWebAnimationsDriver, ɵCssKeyframesDriver, ɵWebAnimationsStyleNormalizer, ɵNoopAnimationDriver } from '@angular/animations/browser';
|
12 | import { DOCUMENT } from '@angular/common';
|
13 |
|
14 | var BrowserAnimationBuilder = (function (_super) {
|
15 | __extends(BrowserAnimationBuilder, _super);
|
16 | function BrowserAnimationBuilder(rootRenderer, doc) {
|
17 | var _this = _super.call(this) || this;
|
18 | _this._nextAnimationId = 0;
|
19 | var typeData = { id: '0', encapsulation: ViewEncapsulation.None, styles: [], data: { animation: [] } };
|
20 | _this._renderer = rootRenderer.createRenderer(doc.body, typeData);
|
21 | return _this;
|
22 | }
|
23 | BrowserAnimationBuilder.prototype.build = function (animation) {
|
24 | var id = this._nextAnimationId.toString();
|
25 | this._nextAnimationId++;
|
26 | var entry = Array.isArray(animation) ? sequence(animation) : animation;
|
27 | issueAnimationCommand(this._renderer, null, id, 'register', [entry]);
|
28 | return new BrowserAnimationFactory(id, this._renderer);
|
29 | };
|
30 | BrowserAnimationBuilder = __decorate([
|
31 | Injectable(),
|
32 | __param(1, Inject(DOCUMENT)),
|
33 | __metadata("design:paramtypes", [RendererFactory2, Object])
|
34 | ], BrowserAnimationBuilder);
|
35 | return BrowserAnimationBuilder;
|
36 | }(AnimationBuilder));
|
37 | var BrowserAnimationFactory = (function (_super) {
|
38 | __extends(BrowserAnimationFactory, _super);
|
39 | function BrowserAnimationFactory(_id, _renderer) {
|
40 | var _this = _super.call(this) || this;
|
41 | _this._id = _id;
|
42 | _this._renderer = _renderer;
|
43 | return _this;
|
44 | }
|
45 | BrowserAnimationFactory.prototype.create = function (element, options) {
|
46 | return new RendererAnimationPlayer(this._id, element, options || {}, this._renderer);
|
47 | };
|
48 | return BrowserAnimationFactory;
|
49 | }(AnimationFactory));
|
50 | var RendererAnimationPlayer = (function () {
|
51 | function RendererAnimationPlayer(id, element, options, _renderer) {
|
52 | this.id = id;
|
53 | this.element = element;
|
54 | this._renderer = _renderer;
|
55 | this.parentPlayer = null;
|
56 | this._started = false;
|
57 | this.totalTime = 0;
|
58 | this._command('create', options);
|
59 | }
|
60 | RendererAnimationPlayer.prototype._listen = function (eventName, callback) {
|
61 | return this._renderer.listen(this.element, "@@" + this.id + ":" + eventName, callback);
|
62 | };
|
63 | RendererAnimationPlayer.prototype._command = function (command) {
|
64 | var args = [];
|
65 | for (var _i = 1; _i < arguments.length; _i++) {
|
66 | args[_i - 1] = arguments[_i];
|
67 | }
|
68 | return issueAnimationCommand(this._renderer, this.element, this.id, command, args);
|
69 | };
|
70 | RendererAnimationPlayer.prototype.onDone = function (fn) {
|
71 | this._listen('done', fn);
|
72 | };
|
73 | RendererAnimationPlayer.prototype.onStart = function (fn) {
|
74 | this._listen('start', fn);
|
75 | };
|
76 | RendererAnimationPlayer.prototype.onDestroy = function (fn) {
|
77 | this._listen('destroy', fn);
|
78 | };
|
79 | RendererAnimationPlayer.prototype.init = function () {
|
80 | this._command('init');
|
81 | };
|
82 | RendererAnimationPlayer.prototype.hasStarted = function () {
|
83 | return this._started;
|
84 | };
|
85 | RendererAnimationPlayer.prototype.play = function () {
|
86 | this._command('play');
|
87 | this._started = true;
|
88 | };
|
89 | RendererAnimationPlayer.prototype.pause = function () {
|
90 | this._command('pause');
|
91 | };
|
92 | RendererAnimationPlayer.prototype.restart = function () {
|
93 | this._command('restart');
|
94 | };
|
95 | RendererAnimationPlayer.prototype.finish = function () {
|
96 | this._command('finish');
|
97 | };
|
98 | RendererAnimationPlayer.prototype.destroy = function () {
|
99 | this._command('destroy');
|
100 | };
|
101 | RendererAnimationPlayer.prototype.reset = function () {
|
102 | this._command('reset');
|
103 | };
|
104 | RendererAnimationPlayer.prototype.setPosition = function (p) {
|
105 | this._command('setPosition', p);
|
106 | };
|
107 | RendererAnimationPlayer.prototype.getPosition = function () {
|
108 | return 0;
|
109 | };
|
110 | return RendererAnimationPlayer;
|
111 | }());
|
112 | function issueAnimationCommand(renderer, element, id, command, args) {
|
113 | return renderer.setProperty(element, "@@" + id + ":" + command, args);
|
114 | }
|
115 |
|
116 | var ANIMATION_PREFIX = '@';
|
117 | var DISABLE_ANIMATIONS_FLAG = '@.disabled';
|
118 | var AnimationRendererFactory = (function () {
|
119 | function AnimationRendererFactory(delegate, engine, _zone) {
|
120 | this.delegate = delegate;
|
121 | this.engine = engine;
|
122 | this._zone = _zone;
|
123 | this._currentId = 0;
|
124 | this._microtaskId = 1;
|
125 | this._animationCallbacksBuffer = [];
|
126 | this._rendererCache = new Map();
|
127 | this._cdRecurDepth = 0;
|
128 | this.promise = Promise.resolve(0);
|
129 | engine.onRemovalComplete = function (element, delegate) {
|
130 |
|
131 |
|
132 |
|
133 |
|
134 | if (delegate && delegate.parentNode(element)) {
|
135 | delegate.removeChild(element.parentNode, element);
|
136 | }
|
137 | };
|
138 | }
|
139 | AnimationRendererFactory.prototype.createRenderer = function (hostElement, type) {
|
140 | var _this = this;
|
141 | var EMPTY_NAMESPACE_ID = '';
|
142 |
|
143 |
|
144 | var delegate = this.delegate.createRenderer(hostElement, type);
|
145 | if (!hostElement || !type || !type.data || !type.data['animation']) {
|
146 | var renderer = this._rendererCache.get(delegate);
|
147 | if (!renderer) {
|
148 | renderer = new BaseAnimationRenderer(EMPTY_NAMESPACE_ID, delegate, this.engine);
|
149 |
|
150 | this._rendererCache.set(delegate, renderer);
|
151 | }
|
152 | return renderer;
|
153 | }
|
154 | var componentId = type.id;
|
155 | var namespaceId = type.id + '-' + this._currentId;
|
156 | this._currentId++;
|
157 | this.engine.register(namespaceId, hostElement);
|
158 | var registerTrigger = function (trigger) {
|
159 | if (Array.isArray(trigger)) {
|
160 | trigger.forEach(registerTrigger);
|
161 | }
|
162 | else {
|
163 | _this.engine.registerTrigger(componentId, namespaceId, hostElement, trigger.name, trigger);
|
164 | }
|
165 | };
|
166 | var animationTriggers = type.data['animation'];
|
167 | animationTriggers.forEach(registerTrigger);
|
168 | return new AnimationRenderer(this, namespaceId, delegate, this.engine);
|
169 | };
|
170 | AnimationRendererFactory.prototype.begin = function () {
|
171 | this._cdRecurDepth++;
|
172 | if (this.delegate.begin) {
|
173 | this.delegate.begin();
|
174 | }
|
175 | };
|
176 | AnimationRendererFactory.prototype._scheduleCountTask = function () {
|
177 | var _this = this;
|
178 |
|
179 | this.promise.then(function () {
|
180 | _this._microtaskId++;
|
181 | });
|
182 | };
|
183 |
|
184 | AnimationRendererFactory.prototype.scheduleListenerCallback = function (count, fn, data) {
|
185 | var _this = this;
|
186 | if (count >= 0 && count < this._microtaskId) {
|
187 | this._zone.run(function () { return fn(data); });
|
188 | return;
|
189 | }
|
190 | if (this._animationCallbacksBuffer.length == 0) {
|
191 | Promise.resolve(null).then(function () {
|
192 | _this._zone.run(function () {
|
193 | _this._animationCallbacksBuffer.forEach(function (tuple) {
|
194 | var _a = __read(tuple, 2), fn = _a[0], data = _a[1];
|
195 | fn(data);
|
196 | });
|
197 | _this._animationCallbacksBuffer = [];
|
198 | });
|
199 | });
|
200 | }
|
201 | this._animationCallbacksBuffer.push([fn, data]);
|
202 | };
|
203 | AnimationRendererFactory.prototype.end = function () {
|
204 | var _this = this;
|
205 | this._cdRecurDepth--;
|
206 |
|
207 |
|
208 | if (this._cdRecurDepth == 0) {
|
209 | this._zone.runOutsideAngular(function () {
|
210 | _this._scheduleCountTask();
|
211 | _this.engine.flush(_this._microtaskId);
|
212 | });
|
213 | }
|
214 | if (this.delegate.end) {
|
215 | this.delegate.end();
|
216 | }
|
217 | };
|
218 | AnimationRendererFactory.prototype.whenRenderingDone = function () {
|
219 | return this.engine.whenRenderingDone();
|
220 | };
|
221 | AnimationRendererFactory = __decorate([
|
222 | Injectable(),
|
223 | __metadata("design:paramtypes", [RendererFactory2, ɵAnimationEngine, NgZone])
|
224 | ], AnimationRendererFactory);
|
225 | return AnimationRendererFactory;
|
226 | }());
|
227 | var BaseAnimationRenderer = (function () {
|
228 | function BaseAnimationRenderer(namespaceId, delegate, engine) {
|
229 | this.namespaceId = namespaceId;
|
230 | this.delegate = delegate;
|
231 | this.engine = engine;
|
232 | this.destroyNode = this.delegate.destroyNode ? function (n) { return delegate.destroyNode(n); } : null;
|
233 | }
|
234 | Object.defineProperty(BaseAnimationRenderer.prototype, "data", {
|
235 | get: function () {
|
236 | return this.delegate.data;
|
237 | },
|
238 | enumerable: true,
|
239 | configurable: true
|
240 | });
|
241 | BaseAnimationRenderer.prototype.destroy = function () {
|
242 | this.engine.destroy(this.namespaceId, this.delegate);
|
243 | this.delegate.destroy();
|
244 | };
|
245 | BaseAnimationRenderer.prototype.createElement = function (name, namespace) {
|
246 | return this.delegate.createElement(name, namespace);
|
247 | };
|
248 | BaseAnimationRenderer.prototype.createComment = function (value) {
|
249 | return this.delegate.createComment(value);
|
250 | };
|
251 | BaseAnimationRenderer.prototype.createText = function (value) {
|
252 | return this.delegate.createText(value);
|
253 | };
|
254 | BaseAnimationRenderer.prototype.appendChild = function (parent, newChild) {
|
255 | this.delegate.appendChild(parent, newChild);
|
256 | this.engine.onInsert(this.namespaceId, newChild, parent, false);
|
257 | };
|
258 | BaseAnimationRenderer.prototype.insertBefore = function (parent, newChild, refChild) {
|
259 | this.delegate.insertBefore(parent, newChild, refChild);
|
260 | this.engine.onInsert(this.namespaceId, newChild, parent, true);
|
261 | };
|
262 | BaseAnimationRenderer.prototype.removeChild = function (parent, oldChild, isHostElement) {
|
263 | this.engine.onRemove(this.namespaceId, oldChild, this.delegate, isHostElement);
|
264 | };
|
265 | BaseAnimationRenderer.prototype.selectRootElement = function (selectorOrNode, preserveContent) {
|
266 | return this.delegate.selectRootElement(selectorOrNode, preserveContent);
|
267 | };
|
268 | BaseAnimationRenderer.prototype.parentNode = function (node) {
|
269 | return this.delegate.parentNode(node);
|
270 | };
|
271 | BaseAnimationRenderer.prototype.nextSibling = function (node) {
|
272 | return this.delegate.nextSibling(node);
|
273 | };
|
274 | BaseAnimationRenderer.prototype.setAttribute = function (el, name, value, namespace) {
|
275 | this.delegate.setAttribute(el, name, value, namespace);
|
276 | };
|
277 | BaseAnimationRenderer.prototype.removeAttribute = function (el, name, namespace) {
|
278 | this.delegate.removeAttribute(el, name, namespace);
|
279 | };
|
280 | BaseAnimationRenderer.prototype.addClass = function (el, name) {
|
281 | this.delegate.addClass(el, name);
|
282 | };
|
283 | BaseAnimationRenderer.prototype.removeClass = function (el, name) {
|
284 | this.delegate.removeClass(el, name);
|
285 | };
|
286 | BaseAnimationRenderer.prototype.setStyle = function (el, style, value, flags) {
|
287 | this.delegate.setStyle(el, style, value, flags);
|
288 | };
|
289 | BaseAnimationRenderer.prototype.removeStyle = function (el, style, flags) {
|
290 | this.delegate.removeStyle(el, style, flags);
|
291 | };
|
292 | BaseAnimationRenderer.prototype.setProperty = function (el, name, value) {
|
293 | if (name.charAt(0) == ANIMATION_PREFIX && name == DISABLE_ANIMATIONS_FLAG) {
|
294 | this.disableAnimations(el, !!value);
|
295 | }
|
296 | else {
|
297 | this.delegate.setProperty(el, name, value);
|
298 | }
|
299 | };
|
300 | BaseAnimationRenderer.prototype.setValue = function (node, value) {
|
301 | this.delegate.setValue(node, value);
|
302 | };
|
303 | BaseAnimationRenderer.prototype.listen = function (target, eventName, callback) {
|
304 | return this.delegate.listen(target, eventName, callback);
|
305 | };
|
306 | BaseAnimationRenderer.prototype.disableAnimations = function (element, value) {
|
307 | this.engine.disableAnimations(element, value);
|
308 | };
|
309 | return BaseAnimationRenderer;
|
310 | }());
|
311 | var AnimationRenderer = (function (_super) {
|
312 | __extends(AnimationRenderer, _super);
|
313 | function AnimationRenderer(factory, namespaceId, delegate, engine) {
|
314 | var _this = _super.call(this, namespaceId, delegate, engine) || this;
|
315 | _this.factory = factory;
|
316 | _this.namespaceId = namespaceId;
|
317 | return _this;
|
318 | }
|
319 | AnimationRenderer.prototype.setProperty = function (el, name, value) {
|
320 | if (name.charAt(0) == ANIMATION_PREFIX) {
|
321 | if (name.charAt(1) == '.' && name == DISABLE_ANIMATIONS_FLAG) {
|
322 | value = value === undefined ? true : !!value;
|
323 | this.disableAnimations(el, value);
|
324 | }
|
325 | else {
|
326 | this.engine.process(this.namespaceId, el, name.substr(1), value);
|
327 | }
|
328 | }
|
329 | else {
|
330 | this.delegate.setProperty(el, name, value);
|
331 | }
|
332 | };
|
333 | AnimationRenderer.prototype.listen = function (target, eventName, callback) {
|
334 | var _a;
|
335 | var _this = this;
|
336 | if (eventName.charAt(0) == ANIMATION_PREFIX) {
|
337 | var element = resolveElementFromTarget(target);
|
338 | var name_1 = eventName.substr(1);
|
339 | var phase = '';
|
340 |
|
341 |
|
342 | if (name_1.charAt(0) != ANIMATION_PREFIX) {
|
343 | _a = __read(parseTriggerCallbackName(name_1), 2), name_1 = _a[0], phase = _a[1];
|
344 | }
|
345 | return this.engine.listen(this.namespaceId, element, name_1, phase, function (event) {
|
346 | var countId = event['_data'] || -1;
|
347 | _this.factory.scheduleListenerCallback(countId, callback, event);
|
348 | });
|
349 | }
|
350 | return this.delegate.listen(target, eventName, callback);
|
351 | };
|
352 | return AnimationRenderer;
|
353 | }(BaseAnimationRenderer));
|
354 | function resolveElementFromTarget(target) {
|
355 | switch (target) {
|
356 | case 'body':
|
357 | return document.body;
|
358 | case 'document':
|
359 | return document;
|
360 | case 'window':
|
361 | return window;
|
362 | default:
|
363 | return target;
|
364 | }
|
365 | }
|
366 | function parseTriggerCallbackName(triggerName) {
|
367 | var dotIndex = triggerName.indexOf('.');
|
368 | var trigger = triggerName.substring(0, dotIndex);
|
369 | var phase = triggerName.substr(dotIndex + 1);
|
370 | return [trigger, phase];
|
371 | }
|
372 |
|
373 |
|
374 |
|
375 |
|
376 |
|
377 |
|
378 |
|
379 |
|
380 | var InjectableAnimationEngine = (function (_super) {
|
381 | __extends(InjectableAnimationEngine, _super);
|
382 | function InjectableAnimationEngine(doc, driver, normalizer) {
|
383 | return _super.call(this, doc.body, driver, normalizer) || this;
|
384 | }
|
385 | InjectableAnimationEngine = __decorate([
|
386 | Injectable(),
|
387 | __param(0, Inject(DOCUMENT)),
|
388 | __metadata("design:paramtypes", [Object, AnimationDriver, ɵAnimationStyleNormalizer])
|
389 | ], InjectableAnimationEngine);
|
390 | return InjectableAnimationEngine;
|
391 | }(ɵAnimationEngine));
|
392 | function instantiateSupportedAnimationDriver() {
|
393 | return ɵsupportsWebAnimations() ? new ɵWebAnimationsDriver() : new ɵCssKeyframesDriver();
|
394 | }
|
395 | function instantiateDefaultStyleNormalizer() {
|
396 | return new ɵWebAnimationsStyleNormalizer();
|
397 | }
|
398 | function instantiateRendererFactory(renderer, engine, zone) {
|
399 | return new AnimationRendererFactory(renderer, engine, zone);
|
400 | }
|
401 |
|
402 |
|
403 |
|
404 | var ANIMATION_MODULE_TYPE = new InjectionToken('AnimationModuleType');
|
405 | var SHARED_ANIMATION_PROVIDERS = [
|
406 | { provide: AnimationBuilder, useClass: BrowserAnimationBuilder },
|
407 | { provide: ɵAnimationStyleNormalizer, useFactory: instantiateDefaultStyleNormalizer },
|
408 | { provide: ɵAnimationEngine, useClass: InjectableAnimationEngine }, {
|
409 | provide: RendererFactory2,
|
410 | useFactory: instantiateRendererFactory,
|
411 | deps: [ɵDomRendererFactory2, ɵAnimationEngine, NgZone]
|
412 | }
|
413 | ];
|
414 |
|
415 |
|
416 |
|
417 |
|
418 | var BROWSER_ANIMATIONS_PROVIDERS = __spread([
|
419 | { provide: AnimationDriver, useFactory: instantiateSupportedAnimationDriver },
|
420 | { provide: ANIMATION_MODULE_TYPE, useValue: 'BrowserAnimations' }
|
421 | ], SHARED_ANIMATION_PROVIDERS);
|
422 |
|
423 |
|
424 |
|
425 |
|
426 | var BROWSER_NOOP_ANIMATIONS_PROVIDERS = __spread([
|
427 | { provide: AnimationDriver, useClass: ɵNoopAnimationDriver },
|
428 | { provide: ANIMATION_MODULE_TYPE, useValue: 'NoopAnimations' }
|
429 | ], SHARED_ANIMATION_PROVIDERS);
|
430 |
|
431 |
|
432 |
|
433 |
|
434 |
|
435 |
|
436 | var BrowserAnimationsModule = (function () {
|
437 | function BrowserAnimationsModule() {
|
438 | }
|
439 | BrowserAnimationsModule = __decorate([
|
440 | NgModule({
|
441 | exports: [BrowserModule],
|
442 | providers: BROWSER_ANIMATIONS_PROVIDERS,
|
443 | })
|
444 | ], BrowserAnimationsModule);
|
445 | return BrowserAnimationsModule;
|
446 | }());
|
447 |
|
448 |
|
449 |
|
450 |
|
451 | var NoopAnimationsModule = (function () {
|
452 | function NoopAnimationsModule() {
|
453 | }
|
454 | NoopAnimationsModule = __decorate([
|
455 | NgModule({
|
456 | exports: [BrowserModule],
|
457 | providers: BROWSER_NOOP_ANIMATIONS_PROVIDERS,
|
458 | })
|
459 | ], NoopAnimationsModule);
|
460 | return NoopAnimationsModule;
|
461 | }());
|
462 |
|
463 |
|
464 |
|
465 |
|
466 |
|
467 |
|
468 |
|
469 |
|
470 |
|
471 |
|
472 |
|
473 |
|
474 |
|
475 |
|
476 |
|
477 |
|
478 |
|
479 |
|
480 |
|
481 |
|
482 |
|
483 |
|
484 |
|
485 |
|
486 |
|
487 |
|
488 |
|
489 |
|
490 |
|
491 |
|
492 |
|
493 |
|
494 |
|
495 |
|
496 |
|
497 |
|
498 |
|
499 | export { ANIMATION_MODULE_TYPE, BrowserAnimationsModule, NoopAnimationsModule, AnimationRenderer as ɵAnimationRenderer, AnimationRendererFactory as ɵAnimationRendererFactory, BrowserAnimationBuilder as ɵBrowserAnimationBuilder, BrowserAnimationFactory as ɵBrowserAnimationFactory, InjectableAnimationEngine as ɵInjectableAnimationEngine, instantiateSupportedAnimationDriver as ɵangular_packages_platform_browser_animations_animations_a, instantiateDefaultStyleNormalizer as ɵangular_packages_platform_browser_animations_animations_b, instantiateRendererFactory as ɵangular_packages_platform_browser_animations_animations_c, BROWSER_ANIMATIONS_PROVIDERS as ɵangular_packages_platform_browser_animations_animations_d, BROWSER_NOOP_ANIMATIONS_PROVIDERS as ɵangular_packages_platform_browser_animations_animations_e, BaseAnimationRenderer as ɵangular_packages_platform_browser_animations_animations_f };
|
500 |
|