UNPKG

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