UNPKG

20.7 kBJavaScriptView Raw
1/**
2 * @license Angular v9.0.5
3 * (c) 2010-2020 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 registerTrigger = function (trigger) {
140 if (Array.isArray(trigger)) {
141 trigger.forEach(registerTrigger);
142 }
143 else {
144 _this.engine.registerTrigger(componentId, namespaceId, hostElement, trigger.name, trigger);
145 }
146 };
147 var animationTriggers = type.data['animation'];
148 animationTriggers.forEach(registerTrigger);
149 return new AnimationRenderer(this, namespaceId, delegate, this.engine);
150 };
151 AnimationRendererFactory.prototype.begin = function () {
152 this._cdRecurDepth++;
153 if (this.delegate.begin) {
154 this.delegate.begin();
155 }
156 };
157 AnimationRendererFactory.prototype._scheduleCountTask = function () {
158 var _this = this;
159 // always use promise to schedule microtask instead of use Zone
160 this.promise.then(function () { _this._microtaskId++; });
161 };
162 /** @internal */
163 AnimationRendererFactory.prototype.scheduleListenerCallback = function (count, fn, data) {
164 var _this = this;
165 if (count >= 0 && count < this._microtaskId) {
166 this._zone.run(function () { return fn(data); });
167 return;
168 }
169 if (this._animationCallbacksBuffer.length == 0) {
170 Promise.resolve(null).then(function () {
171 _this._zone.run(function () {
172 _this._animationCallbacksBuffer.forEach(function (tuple) {
173 var _a = __read(tuple, 2), fn = _a[0], data = _a[1];
174 fn(data);
175 });
176 _this._animationCallbacksBuffer = [];
177 });
178 });
179 }
180 this._animationCallbacksBuffer.push([fn, data]);
181 };
182 AnimationRendererFactory.prototype.end = function () {
183 var _this = this;
184 this._cdRecurDepth--;
185 // this is to prevent animations from running twice when an inner
186 // component does CD when a parent component instead has inserted it
187 if (this._cdRecurDepth == 0) {
188 this._zone.runOutsideAngular(function () {
189 _this._scheduleCountTask();
190 _this.engine.flush(_this._microtaskId);
191 });
192 }
193 if (this.delegate.end) {
194 this.delegate.end();
195 }
196 };
197 AnimationRendererFactory.prototype.whenRenderingDone = function () { return this.engine.whenRenderingDone(); };
198 AnimationRendererFactory = __decorate([
199 Injectable(),
200 __metadata("design:paramtypes", [RendererFactory2, ɵAnimationEngine, NgZone])
201 ], AnimationRendererFactory);
202 return AnimationRendererFactory;
203}());
204var BaseAnimationRenderer = /** @class */ (function () {
205 function BaseAnimationRenderer(namespaceId, delegate, engine) {
206 this.namespaceId = namespaceId;
207 this.delegate = delegate;
208 this.engine = engine;
209 this.destroyNode = this.delegate.destroyNode ? function (n) { return delegate.destroyNode(n); } : null;
210 }
211 Object.defineProperty(BaseAnimationRenderer.prototype, "data", {
212 get: function () { return this.delegate.data; },
213 enumerable: true,
214 configurable: true
215 });
216 BaseAnimationRenderer.prototype.destroy = function () {
217 this.engine.destroy(this.namespaceId, this.delegate);
218 this.delegate.destroy();
219 };
220 BaseAnimationRenderer.prototype.createElement = function (name, namespace) {
221 return this.delegate.createElement(name, namespace);
222 };
223 BaseAnimationRenderer.prototype.createComment = function (value) { return this.delegate.createComment(value); };
224 BaseAnimationRenderer.prototype.createText = function (value) { return this.delegate.createText(value); };
225 BaseAnimationRenderer.prototype.appendChild = function (parent, newChild) {
226 this.delegate.appendChild(parent, newChild);
227 this.engine.onInsert(this.namespaceId, newChild, parent, false);
228 };
229 BaseAnimationRenderer.prototype.insertBefore = function (parent, newChild, refChild) {
230 this.delegate.insertBefore(parent, newChild, refChild);
231 this.engine.onInsert(this.namespaceId, newChild, parent, true);
232 };
233 BaseAnimationRenderer.prototype.removeChild = function (parent, oldChild, isHostElement) {
234 this.engine.onRemove(this.namespaceId, oldChild, this.delegate, isHostElement);
235 };
236 BaseAnimationRenderer.prototype.selectRootElement = function (selectorOrNode, preserveContent) {
237 return this.delegate.selectRootElement(selectorOrNode, preserveContent);
238 };
239 BaseAnimationRenderer.prototype.parentNode = function (node) { return this.delegate.parentNode(node); };
240 BaseAnimationRenderer.prototype.nextSibling = function (node) { return this.delegate.nextSibling(node); };
241 BaseAnimationRenderer.prototype.setAttribute = function (el, name, value, namespace) {
242 this.delegate.setAttribute(el, name, value, namespace);
243 };
244 BaseAnimationRenderer.prototype.removeAttribute = function (el, name, namespace) {
245 this.delegate.removeAttribute(el, name, namespace);
246 };
247 BaseAnimationRenderer.prototype.addClass = function (el, name) { this.delegate.addClass(el, name); };
248 BaseAnimationRenderer.prototype.removeClass = function (el, name) { this.delegate.removeClass(el, name); };
249 BaseAnimationRenderer.prototype.setStyle = function (el, style, value, flags) {
250 this.delegate.setStyle(el, style, value, flags);
251 };
252 BaseAnimationRenderer.prototype.removeStyle = function (el, style, flags) {
253 this.delegate.removeStyle(el, style, flags);
254 };
255 BaseAnimationRenderer.prototype.setProperty = function (el, name, value) {
256 if (name.charAt(0) == ANIMATION_PREFIX && name == DISABLE_ANIMATIONS_FLAG) {
257 this.disableAnimations(el, !!value);
258 }
259 else {
260 this.delegate.setProperty(el, name, value);
261 }
262 };
263 BaseAnimationRenderer.prototype.setValue = function (node, value) { this.delegate.setValue(node, value); };
264 BaseAnimationRenderer.prototype.listen = function (target, eventName, callback) {
265 return this.delegate.listen(target, eventName, callback);
266 };
267 BaseAnimationRenderer.prototype.disableAnimations = function (element, value) {
268 this.engine.disableAnimations(element, value);
269 };
270 return BaseAnimationRenderer;
271}());
272var AnimationRenderer = /** @class */ (function (_super) {
273 __extends(AnimationRenderer, _super);
274 function AnimationRenderer(factory, namespaceId, delegate, engine) {
275 var _this = _super.call(this, namespaceId, delegate, engine) || this;
276 _this.factory = factory;
277 _this.namespaceId = namespaceId;
278 return _this;
279 }
280 AnimationRenderer.prototype.setProperty = function (el, name, value) {
281 if (name.charAt(0) == ANIMATION_PREFIX) {
282 if (name.charAt(1) == '.' && name == DISABLE_ANIMATIONS_FLAG) {
283 value = value === undefined ? true : !!value;
284 this.disableAnimations(el, value);
285 }
286 else {
287 this.engine.process(this.namespaceId, el, name.substr(1), value);
288 }
289 }
290 else {
291 this.delegate.setProperty(el, name, value);
292 }
293 };
294 AnimationRenderer.prototype.listen = function (target, eventName, callback) {
295 var _a;
296 var _this = this;
297 if (eventName.charAt(0) == ANIMATION_PREFIX) {
298 var element = resolveElementFromTarget(target);
299 var name_1 = eventName.substr(1);
300 var phase = '';
301 // @listener.phase is for trigger animation callbacks
302 // @@listener is for animation builder callbacks
303 if (name_1.charAt(0) != ANIMATION_PREFIX) {
304 _a = __read(parseTriggerCallbackName(name_1), 2), name_1 = _a[0], phase = _a[1];
305 }
306 return this.engine.listen(this.namespaceId, element, name_1, phase, function (event) {
307 var countId = event['_data'] || -1;
308 _this.factory.scheduleListenerCallback(countId, callback, event);
309 });
310 }
311 return this.delegate.listen(target, eventName, callback);
312 };
313 return AnimationRenderer;
314}(BaseAnimationRenderer));
315function resolveElementFromTarget(target) {
316 switch (target) {
317 case 'body':
318 return document.body;
319 case 'document':
320 return document;
321 case 'window':
322 return window;
323 default:
324 return target;
325 }
326}
327function parseTriggerCallbackName(triggerName) {
328 var dotIndex = triggerName.indexOf('.');
329 var trigger = triggerName.substring(0, dotIndex);
330 var phase = triggerName.substr(dotIndex + 1);
331 return [trigger, phase];
332}
333
334/**
335 * @license
336 * Copyright Google Inc. All Rights Reserved.
337 *
338 * Use of this source code is governed by an MIT-style license that can be
339 * found in the LICENSE file at https://angular.io/license
340 */
341var InjectableAnimationEngine = /** @class */ (function (_super) {
342 __extends(InjectableAnimationEngine, _super);
343 function InjectableAnimationEngine(doc, driver, normalizer) {
344 return _super.call(this, doc.body, driver, normalizer) || this;
345 }
346 InjectableAnimationEngine = __decorate([
347 Injectable(),
348 __param(0, Inject(DOCUMENT)),
349 __metadata("design:paramtypes", [Object, AnimationDriver, ɵAnimationStyleNormalizer])
350 ], InjectableAnimationEngine);
351 return InjectableAnimationEngine;
352}(ɵAnimationEngine));
353function instantiateSupportedAnimationDriver() {
354 return ɵsupportsWebAnimations() ? new ɵWebAnimationsDriver() : new ɵCssKeyframesDriver();
355}
356function instantiateDefaultStyleNormalizer() {
357 return new ɵWebAnimationsStyleNormalizer();
358}
359function instantiateRendererFactory(renderer, engine, zone) {
360 return new AnimationRendererFactory(renderer, engine, zone);
361}
362/**
363 * @publicApi
364 */
365var ANIMATION_MODULE_TYPE = new InjectionToken('AnimationModuleType');
366var SHARED_ANIMATION_PROVIDERS = [
367 { provide: AnimationBuilder, useClass: BrowserAnimationBuilder },
368 { provide: ɵAnimationStyleNormalizer, useFactory: instantiateDefaultStyleNormalizer },
369 { provide: ɵAnimationEngine, useClass: InjectableAnimationEngine }, {
370 provide: RendererFactory2,
371 useFactory: instantiateRendererFactory,
372 deps: [ɵDomRendererFactory2, ɵAnimationEngine, NgZone]
373 }
374];
375/**
376 * Separate providers from the actual module so that we can do a local modification in Google3 to
377 * include them in the BrowserModule.
378 */
379var BROWSER_ANIMATIONS_PROVIDERS = __spread([
380 { provide: AnimationDriver, useFactory: instantiateSupportedAnimationDriver },
381 { provide: ANIMATION_MODULE_TYPE, useValue: 'BrowserAnimations' }
382], SHARED_ANIMATION_PROVIDERS);
383/**
384 * Separate providers from the actual module so that we can do a local modification in Google3 to
385 * include them in the BrowserTestingModule.
386 */
387var BROWSER_NOOP_ANIMATIONS_PROVIDERS = __spread([
388 { provide: AnimationDriver, useClass: ɵNoopAnimationDriver },
389 { provide: ANIMATION_MODULE_TYPE, useValue: 'NoopAnimations' }
390], SHARED_ANIMATION_PROVIDERS);
391
392/**
393 * Exports `BrowserModule` with additional [dependency-injection providers](guide/glossary#provider)
394 * for use with animations. See [Animations](guide/animations).
395 * @publicApi
396 */
397var BrowserAnimationsModule = /** @class */ (function () {
398 function BrowserAnimationsModule() {
399 }
400 BrowserAnimationsModule = __decorate([
401 NgModule({
402 exports: [BrowserModule],
403 providers: BROWSER_ANIMATIONS_PROVIDERS,
404 })
405 ], BrowserAnimationsModule);
406 return BrowserAnimationsModule;
407}());
408/**
409 * A null player that must be imported to allow disabling of animations.
410 * @publicApi
411 */
412var NoopAnimationsModule = /** @class */ (function () {
413 function NoopAnimationsModule() {
414 }
415 NoopAnimationsModule = __decorate([
416 NgModule({
417 exports: [BrowserModule],
418 providers: BROWSER_NOOP_ANIMATIONS_PROVIDERS,
419 })
420 ], NoopAnimationsModule);
421 return NoopAnimationsModule;
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 * @license
450 * Copyright Google Inc. All Rights Reserved.
451 *
452 * Use of this source code is governed by an MIT-style license that can be
453 * found in the LICENSE file at https://angular.io/license
454 */
455
456/**
457 * Generated bundle index. Do not edit.
458 */
459
460export { 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 };
461//# sourceMappingURL=animations.js.map