UNPKG

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