UNPKG

20.5 kBJavaScriptView Raw
1/**
2 * @license Angular v8.2.12
3 * (c) 2010-2019 Google LLC. https://angular.io/
4 * License: MIT
5 */
6
7import { __extends, __decorate, __param, __metadata, __read, __spread } from 'tslib';
8import { ViewEncapsulation, Injectable, Inject, RendererFactory2, NgZone, InjectionToken, NgModule } from '@angular/core';
9import { ɵDomRendererFactory2, BrowserModule } from '@angular/platform-browser';
10import { sequence, AnimationBuilder, AnimationFactory } from '@angular/animations';
11import { ɵAnimationEngine, AnimationDriver, ɵAnimationStyleNormalizer, ɵsupportsWebAnimations, ɵWebAnimationsDriver, ɵCssKeyframesDriver, ɵWebAnimationsStyleNormalizer, ɵNoopAnimationDriver } from '@angular/animations/browser';
12import { DOCUMENT } from '@angular/common';
13
14var BrowserAnimationBuilder = /** @class */ (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 = {
20 id: '0',
21 encapsulation: ViewEncapsulation.None,
22 styles: [],
23 data: { animation: [] }
24 };
25 _this._renderer = rootRenderer.createRenderer(doc.body, typeData);
26 return _this;
27 }
28 BrowserAnimationBuilder.prototype.build = function (animation) {
29 var id = this._nextAnimationId.toString();
30 this._nextAnimationId++;
31 var entry = Array.isArray(animation) ? sequence(animation) : animation;
32 issueAnimationCommand(this._renderer, null, id, 'register', [entry]);
33 return new BrowserAnimationFactory(id, this._renderer);
34 };
35 BrowserAnimationBuilder = __decorate([
36 Injectable(),
37 __param(1, Inject(DOCUMENT)),
38 __metadata("design:paramtypes", [RendererFactory2, Object])
39 ], BrowserAnimationBuilder);
40 return BrowserAnimationBuilder;
41}(AnimationBuilder));
42var BrowserAnimationFactory = /** @class */ (function (_super) {
43 __extends(BrowserAnimationFactory, _super);
44 function BrowserAnimationFactory(_id, _renderer) {
45 var _this = _super.call(this) || this;
46 _this._id = _id;
47 _this._renderer = _renderer;
48 return _this;
49 }
50 BrowserAnimationFactory.prototype.create = function (element, options) {
51 return new RendererAnimationPlayer(this._id, element, options || {}, this._renderer);
52 };
53 return BrowserAnimationFactory;
54}(AnimationFactory));
55var RendererAnimationPlayer = /** @class */ (function () {
56 function RendererAnimationPlayer(id, element, options, _renderer) {
57 this.id = id;
58 this.element = element;
59 this._renderer = _renderer;
60 this.parentPlayer = null;
61 this._started = false;
62 this.totalTime = 0;
63 this._command('create', options);
64 }
65 RendererAnimationPlayer.prototype._listen = function (eventName, callback) {
66 return this._renderer.listen(this.element, "@@" + this.id + ":" + eventName, callback);
67 };
68 RendererAnimationPlayer.prototype._command = function (command) {
69 var args = [];
70 for (var _i = 1; _i < arguments.length; _i++) {
71 args[_i - 1] = arguments[_i];
72 }
73 return issueAnimationCommand(this._renderer, this.element, this.id, command, args);
74 };
75 RendererAnimationPlayer.prototype.onDone = function (fn) { this._listen('done', fn); };
76 RendererAnimationPlayer.prototype.onStart = function (fn) { this._listen('start', fn); };
77 RendererAnimationPlayer.prototype.onDestroy = function (fn) { this._listen('destroy', fn); };
78 RendererAnimationPlayer.prototype.init = function () { this._command('init'); };
79 RendererAnimationPlayer.prototype.hasStarted = function () { return this._started; };
80 RendererAnimationPlayer.prototype.play = function () {
81 this._command('play');
82 this._started = true;
83 };
84 RendererAnimationPlayer.prototype.pause = function () { this._command('pause'); };
85 RendererAnimationPlayer.prototype.restart = function () { this._command('restart'); };
86 RendererAnimationPlayer.prototype.finish = function () { this._command('finish'); };
87 RendererAnimationPlayer.prototype.destroy = function () { this._command('destroy'); };
88 RendererAnimationPlayer.prototype.reset = function () { this._command('reset'); };
89 RendererAnimationPlayer.prototype.setPosition = function (p) { this._command('setPosition', p); };
90 RendererAnimationPlayer.prototype.getPosition = function () { return 0; };
91 return RendererAnimationPlayer;
92}());
93function issueAnimationCommand(renderer, element, id, command, args) {
94 return renderer.setProperty(element, "@@" + id + ":" + command, args);
95}
96
97var ANIMATION_PREFIX = '@';
98var DISABLE_ANIMATIONS_FLAG = '@.disabled';
99var AnimationRendererFactory = /** @class */ (function () {
100 function AnimationRendererFactory(delegate, engine, _zone) {
101 this.delegate = delegate;
102 this.engine = engine;
103 this._zone = _zone;
104 this._currentId = 0;
105 this._microtaskId = 1;
106 this._animationCallbacksBuffer = [];
107 this._rendererCache = new Map();
108 this._cdRecurDepth = 0;
109 this.promise = Promise.resolve(0);
110 engine.onRemovalComplete = function (element, delegate) {
111 // Note: if an component element has a leave animation, and the component
112 // a host leave animation, the view engine will call `removeChild` for the parent
113 // component renderer as well as for the child component renderer.
114 // Therefore, we need to check if we already removed the element.
115 if (delegate && delegate.parentNode(element)) {
116 delegate.removeChild(element.parentNode, element);
117 }
118 };
119 }
120 AnimationRendererFactory.prototype.createRenderer = function (hostElement, type) {
121 var _this = this;
122 var EMPTY_NAMESPACE_ID = '';
123 // cache the delegates to find out which cached delegate can
124 // be used by which cached renderer
125 var delegate = this.delegate.createRenderer(hostElement, type);
126 if (!hostElement || !type || !type.data || !type.data['animation']) {
127 var renderer = this._rendererCache.get(delegate);
128 if (!renderer) {
129 renderer = new BaseAnimationRenderer(EMPTY_NAMESPACE_ID, delegate, this.engine);
130 // only cache this result when the base renderer is used
131 this._rendererCache.set(delegate, renderer);
132 }
133 return renderer;
134 }
135 var componentId = type.id;
136 var namespaceId = type.id + '-' + this._currentId;
137 this._currentId++;
138 this.engine.register(namespaceId, hostElement);
139 var animationTriggers = type.data['animation'];
140 animationTriggers.forEach(function (trigger) { return _this.engine.registerTrigger(componentId, namespaceId, hostElement, trigger.name, trigger); });
141 return new AnimationRenderer(this, namespaceId, delegate, this.engine);
142 };
143 AnimationRendererFactory.prototype.begin = function () {
144 this._cdRecurDepth++;
145 if (this.delegate.begin) {
146 this.delegate.begin();
147 }
148 };
149 AnimationRendererFactory.prototype._scheduleCountTask = function () {
150 var _this = this;
151 // always use promise to schedule microtask instead of use Zone
152 this.promise.then(function () { _this._microtaskId++; });
153 };
154 /** @internal */
155 AnimationRendererFactory.prototype.scheduleListenerCallback = function (count, fn, data) {
156 var _this = this;
157 if (count >= 0 && count < this._microtaskId) {
158 this._zone.run(function () { return fn(data); });
159 return;
160 }
161 if (this._animationCallbacksBuffer.length == 0) {
162 Promise.resolve(null).then(function () {
163 _this._zone.run(function () {
164 _this._animationCallbacksBuffer.forEach(function (tuple) {
165 var _a = __read(tuple, 2), fn = _a[0], data = _a[1];
166 fn(data);
167 });
168 _this._animationCallbacksBuffer = [];
169 });
170 });
171 }
172 this._animationCallbacksBuffer.push([fn, data]);
173 };
174 AnimationRendererFactory.prototype.end = function () {
175 var _this = this;
176 this._cdRecurDepth--;
177 // this is to prevent animations from running twice when an inner
178 // component does CD when a parent component instead has inserted it
179 if (this._cdRecurDepth == 0) {
180 this._zone.runOutsideAngular(function () {
181 _this._scheduleCountTask();
182 _this.engine.flush(_this._microtaskId);
183 });
184 }
185 if (this.delegate.end) {
186 this.delegate.end();
187 }
188 };
189 AnimationRendererFactory.prototype.whenRenderingDone = function () { return this.engine.whenRenderingDone(); };
190 AnimationRendererFactory = __decorate([
191 Injectable(),
192 __metadata("design:paramtypes", [RendererFactory2, ɵAnimationEngine, NgZone])
193 ], AnimationRendererFactory);
194 return AnimationRendererFactory;
195}());
196var BaseAnimationRenderer = /** @class */ (function () {
197 function BaseAnimationRenderer(namespaceId, delegate, engine) {
198 this.namespaceId = namespaceId;
199 this.delegate = delegate;
200 this.engine = engine;
201 this.destroyNode = this.delegate.destroyNode ? function (n) { return delegate.destroyNode(n); } : null;
202 }
203 Object.defineProperty(BaseAnimationRenderer.prototype, "data", {
204 get: function () { return this.delegate.data; },
205 enumerable: true,
206 configurable: true
207 });
208 BaseAnimationRenderer.prototype.destroy = function () {
209 this.engine.destroy(this.namespaceId, this.delegate);
210 this.delegate.destroy();
211 };
212 BaseAnimationRenderer.prototype.createElement = function (name, namespace) {
213 return this.delegate.createElement(name, namespace);
214 };
215 BaseAnimationRenderer.prototype.createComment = function (value) { return this.delegate.createComment(value); };
216 BaseAnimationRenderer.prototype.createText = function (value) { return this.delegate.createText(value); };
217 BaseAnimationRenderer.prototype.appendChild = function (parent, newChild) {
218 this.delegate.appendChild(parent, newChild);
219 this.engine.onInsert(this.namespaceId, newChild, parent, false);
220 };
221 BaseAnimationRenderer.prototype.insertBefore = function (parent, newChild, refChild) {
222 this.delegate.insertBefore(parent, newChild, refChild);
223 this.engine.onInsert(this.namespaceId, newChild, parent, true);
224 };
225 BaseAnimationRenderer.prototype.removeChild = function (parent, oldChild, isHostElement) {
226 this.engine.onRemove(this.namespaceId, oldChild, this.delegate, isHostElement);
227 };
228 BaseAnimationRenderer.prototype.selectRootElement = function (selectorOrNode, preserveContent) {
229 return this.delegate.selectRootElement(selectorOrNode, preserveContent);
230 };
231 BaseAnimationRenderer.prototype.parentNode = function (node) { return this.delegate.parentNode(node); };
232 BaseAnimationRenderer.prototype.nextSibling = function (node) { return this.delegate.nextSibling(node); };
233 BaseAnimationRenderer.prototype.setAttribute = function (el, name, value, namespace) {
234 this.delegate.setAttribute(el, name, value, namespace);
235 };
236 BaseAnimationRenderer.prototype.removeAttribute = function (el, name, namespace) {
237 this.delegate.removeAttribute(el, name, namespace);
238 };
239 BaseAnimationRenderer.prototype.addClass = function (el, name) { this.delegate.addClass(el, name); };
240 BaseAnimationRenderer.prototype.removeClass = function (el, name) { this.delegate.removeClass(el, name); };
241 BaseAnimationRenderer.prototype.setStyle = function (el, style, value, flags) {
242 this.delegate.setStyle(el, style, value, flags);
243 };
244 BaseAnimationRenderer.prototype.removeStyle = function (el, style, flags) {
245 this.delegate.removeStyle(el, style, flags);
246 };
247 BaseAnimationRenderer.prototype.setProperty = function (el, name, value) {
248 if (name.charAt(0) == ANIMATION_PREFIX && name == DISABLE_ANIMATIONS_FLAG) {
249 this.disableAnimations(el, !!value);
250 }
251 else {
252 this.delegate.setProperty(el, name, value);
253 }
254 };
255 BaseAnimationRenderer.prototype.setValue = function (node, value) { this.delegate.setValue(node, value); };
256 BaseAnimationRenderer.prototype.listen = function (target, eventName, callback) {
257 return this.delegate.listen(target, eventName, callback);
258 };
259 BaseAnimationRenderer.prototype.disableAnimations = function (element, value) {
260 this.engine.disableAnimations(element, value);
261 };
262 return BaseAnimationRenderer;
263}());
264var AnimationRenderer = /** @class */ (function (_super) {
265 __extends(AnimationRenderer, _super);
266 function AnimationRenderer(factory, namespaceId, delegate, engine) {
267 var _this = _super.call(this, namespaceId, delegate, engine) || this;
268 _this.factory = factory;
269 _this.namespaceId = namespaceId;
270 return _this;
271 }
272 AnimationRenderer.prototype.setProperty = function (el, name, value) {
273 if (name.charAt(0) == ANIMATION_PREFIX) {
274 if (name.charAt(1) == '.' && name == DISABLE_ANIMATIONS_FLAG) {
275 value = value === undefined ? true : !!value;
276 this.disableAnimations(el, value);
277 }
278 else {
279 this.engine.process(this.namespaceId, el, name.substr(1), value);
280 }
281 }
282 else {
283 this.delegate.setProperty(el, name, value);
284 }
285 };
286 AnimationRenderer.prototype.listen = function (target, eventName, callback) {
287 var _a;
288 var _this = this;
289 if (eventName.charAt(0) == ANIMATION_PREFIX) {
290 var element = resolveElementFromTarget(target);
291 var name_1 = eventName.substr(1);
292 var phase = '';
293 // @listener.phase is for trigger animation callbacks
294 // @@listener is for animation builder callbacks
295 if (name_1.charAt(0) != ANIMATION_PREFIX) {
296 _a = __read(parseTriggerCallbackName(name_1), 2), name_1 = _a[0], phase = _a[1];
297 }
298 return this.engine.listen(this.namespaceId, element, name_1, phase, function (event) {
299 var countId = event['_data'] || -1;
300 _this.factory.scheduleListenerCallback(countId, callback, event);
301 });
302 }
303 return this.delegate.listen(target, eventName, callback);
304 };
305 return AnimationRenderer;
306}(BaseAnimationRenderer));
307function resolveElementFromTarget(target) {
308 switch (target) {
309 case 'body':
310 return document.body;
311 case 'document':
312 return document;
313 case 'window':
314 return window;
315 default:
316 return target;
317 }
318}
319function parseTriggerCallbackName(triggerName) {
320 var dotIndex = triggerName.indexOf('.');
321 var trigger = triggerName.substring(0, dotIndex);
322 var phase = triggerName.substr(dotIndex + 1);
323 return [trigger, phase];
324}
325
326/**
327 * @license
328 * Copyright Google Inc. All Rights Reserved.
329 *
330 * Use of this source code is governed by an MIT-style license that can be
331 * found in the LICENSE file at https://angular.io/license
332 */
333var InjectableAnimationEngine = /** @class */ (function (_super) {
334 __extends(InjectableAnimationEngine, _super);
335 function InjectableAnimationEngine(doc, driver, normalizer) {
336 return _super.call(this, doc.body, driver, normalizer) || this;
337 }
338 InjectableAnimationEngine = __decorate([
339 Injectable(),
340 __param(0, Inject(DOCUMENT)),
341 __metadata("design:paramtypes", [Object, AnimationDriver, ɵAnimationStyleNormalizer])
342 ], InjectableAnimationEngine);
343 return InjectableAnimationEngine;
344}(ɵAnimationEngine));
345function instantiateSupportedAnimationDriver() {
346 return ɵsupportsWebAnimations() ? new ɵWebAnimationsDriver() : new ɵCssKeyframesDriver();
347}
348function instantiateDefaultStyleNormalizer() {
349 return new ɵWebAnimationsStyleNormalizer();
350}
351function instantiateRendererFactory(renderer, engine, zone) {
352 return new AnimationRendererFactory(renderer, engine, zone);
353}
354/**
355 * @publicApi
356 */
357var ANIMATION_MODULE_TYPE = new InjectionToken('AnimationModuleType');
358var SHARED_ANIMATION_PROVIDERS = [
359 { provide: AnimationBuilder, useClass: BrowserAnimationBuilder },
360 { provide: ɵAnimationStyleNormalizer, useFactory: instantiateDefaultStyleNormalizer },
361 { provide: ɵAnimationEngine, useClass: InjectableAnimationEngine }, {
362 provide: RendererFactory2,
363 useFactory: instantiateRendererFactory,
364 deps: [ɵDomRendererFactory2, ɵAnimationEngine, NgZone]
365 }
366];
367/**
368 * Separate providers from the actual module so that we can do a local modification in Google3 to
369 * include them in the BrowserModule.
370 */
371var BROWSER_ANIMATIONS_PROVIDERS = __spread([
372 { provide: AnimationDriver, useFactory: instantiateSupportedAnimationDriver },
373 { provide: ANIMATION_MODULE_TYPE, useValue: 'BrowserAnimations' }
374], SHARED_ANIMATION_PROVIDERS);
375/**
376 * Separate providers from the actual module so that we can do a local modification in Google3 to
377 * include them in the BrowserTestingModule.
378 */
379var BROWSER_NOOP_ANIMATIONS_PROVIDERS = __spread([
380 { provide: AnimationDriver, useClass: ɵNoopAnimationDriver },
381 { provide: ANIMATION_MODULE_TYPE, useValue: 'NoopAnimations' }
382], SHARED_ANIMATION_PROVIDERS);
383
384/**
385 * Exports `BrowserModule` with additional [dependency-injection providers](guide/glossary#provider)
386 * for use with animations. See [Animations](guide/animations).
387 * @publicApi
388 */
389var BrowserAnimationsModule = /** @class */ (function () {
390 function BrowserAnimationsModule() {
391 }
392 BrowserAnimationsModule = __decorate([
393 NgModule({
394 exports: [BrowserModule],
395 providers: BROWSER_ANIMATIONS_PROVIDERS,
396 })
397 ], BrowserAnimationsModule);
398 return BrowserAnimationsModule;
399}());
400/**
401 * A null player that must be imported to allow disabling of animations.
402 * @publicApi
403 */
404var NoopAnimationsModule = /** @class */ (function () {
405 function NoopAnimationsModule() {
406 }
407 NoopAnimationsModule = __decorate([
408 NgModule({
409 exports: [BrowserModule],
410 providers: BROWSER_NOOP_ANIMATIONS_PROVIDERS,
411 })
412 ], NoopAnimationsModule);
413 return NoopAnimationsModule;
414}());
415
416/**
417 * @license
418 * Copyright Google Inc. All Rights Reserved.
419 *
420 * Use of this source code is governed by an MIT-style license that can be
421 * found in the LICENSE file at https://angular.io/license
422 */
423
424/**
425 * @license
426 * Copyright Google Inc. All Rights Reserved.
427 *
428 * Use of this source code is governed by an MIT-style license that can be
429 * found in the LICENSE file at https://angular.io/license
430 */
431
432/**
433 * @license
434 * Copyright Google Inc. All Rights Reserved.
435 *
436 * Use of this source code is governed by an MIT-style license that can be
437 * found in the LICENSE file at https://angular.io/license
438 */
439
440/**
441 * @license
442 * Copyright Google Inc. All Rights Reserved.
443 *
444 * Use of this source code is governed by an MIT-style license that can be
445 * found in the LICENSE file at https://angular.io/license
446 */
447
448/**
449 * Generated bundle index. Do not edit.
450 */
451
452export { BaseAnimationRenderer as ɵangular_packages_platform_browser_animations_animations_f, BROWSER_ANIMATIONS_PROVIDERS as ɵangular_packages_platform_browser_animations_animations_d, BROWSER_NOOP_ANIMATIONS_PROVIDERS as ɵangular_packages_platform_browser_animations_animations_e, instantiateDefaultStyleNormalizer as ɵangular_packages_platform_browser_animations_animations_b, instantiateRendererFactory as ɵangular_packages_platform_browser_animations_animations_c, instantiateSupportedAnimationDriver as ɵangular_packages_platform_browser_animations_animations_a, BrowserAnimationsModule, NoopAnimationsModule, ANIMATION_MODULE_TYPE, BrowserAnimationBuilder as ɵBrowserAnimationBuilder, BrowserAnimationFactory as ɵBrowserAnimationFactory, AnimationRenderer as ɵAnimationRenderer, AnimationRendererFactory as ɵAnimationRendererFactory, InjectableAnimationEngine as ɵInjectableAnimationEngine };
453//# sourceMappingURL=animations.js.map