1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 | import * as i0 from '@angular/core';
|
8 | import { ViewEncapsulation, Injectable, Inject, InjectionToken, RendererFactory2, NgZone, NgModule } from '@angular/core';
|
9 | import { ɵDomRendererFactory2, BrowserModule } from '@angular/platform-browser';
|
10 | import { AnimationBuilder, sequence, AnimationFactory } from '@angular/animations';
|
11 | import * as i1 from '@angular/animations/browser';
|
12 | import { ɵAnimationEngine, ɵsupportsWebAnimations, ɵWebAnimationsDriver, ɵCssKeyframesDriver, ɵWebAnimationsStyleNormalizer, ɵAnimationStyleNormalizer, AnimationDriver, ɵNoopAnimationDriver } from '@angular/animations/browser';
|
13 | import { DOCUMENT } from '@angular/common';
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 | class 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 | }
|
37 | BrowserAnimationBuilder.ɵ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 });
|
38 | BrowserAnimationBuilder.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.0.3", ngImport: i0, type: BrowserAnimationBuilder });
|
39 | i0.ɵɵ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 | }] }]; } });
|
45 | class 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 | }
|
55 | class 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 | }
|
113 | function issueAnimationCommand(renderer, element, id, command, args) {
|
114 | return renderer.setProperty(element, `@@${id}:${command}`, args);
|
115 | }
|
116 |
|
117 | const ANIMATION_PREFIX = '@';
|
118 | const DISABLE_ANIMATIONS_FLAG = '@.disabled';
|
119 | class 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 |
|
132 |
|
133 |
|
134 |
|
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 |
|
144 |
|
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 |
|
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 |
|
179 | this.promise.then(() => {
|
180 | this._microtaskId++;
|
181 | });
|
182 | }
|
183 |
|
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 |
|
205 |
|
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 | }
|
220 | AnimationRendererFactory.ɵ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 });
|
221 | AnimationRendererFactory.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.0.3", ngImport: i0, type: AnimationRendererFactory });
|
222 | i0.ɵɵ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 }]; } });
|
225 | class 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 |
|
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 | }
|
305 | class 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 |
|
331 |
|
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 | }
|
343 | function 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 | }
|
355 | function 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 |
|
364 |
|
365 |
|
366 |
|
367 |
|
368 |
|
369 | class InjectableAnimationEngine extends ɵAnimationEngine {
|
370 | constructor(doc, driver, normalizer) {
|
371 | super(doc.body, driver, normalizer);
|
372 | }
|
373 | ngOnDestroy() {
|
374 | this.flush();
|
375 | }
|
376 | }
|
377 | InjectableAnimationEngine.ɵ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 });
|
378 | InjectableAnimationEngine.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.0.3", ngImport: i0, type: InjectableAnimationEngine });
|
379 | i0.ɵɵ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 }]; } });
|
385 | function instantiateSupportedAnimationDriver() {
|
386 | return ɵsupportsWebAnimations() ? new ɵWebAnimationsDriver() : new ɵCssKeyframesDriver();
|
387 | }
|
388 | function instantiateDefaultStyleNormalizer() {
|
389 | return new ɵWebAnimationsStyleNormalizer();
|
390 | }
|
391 | function instantiateRendererFactory(renderer, engine, zone) {
|
392 | return new AnimationRendererFactory(renderer, engine, zone);
|
393 | }
|
394 |
|
395 |
|
396 |
|
397 | const ANIMATION_MODULE_TYPE = new InjectionToken('AnimationModuleType');
|
398 | const 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 |
|
409 |
|
410 |
|
411 | const BROWSER_ANIMATIONS_PROVIDERS = [
|
412 | { provide: AnimationDriver, useFactory: instantiateSupportedAnimationDriver },
|
413 | { provide: ANIMATION_MODULE_TYPE, useValue: 'BrowserAnimations' }, ...SHARED_ANIMATION_PROVIDERS
|
414 | ];
|
415 |
|
416 |
|
417 |
|
418 |
|
419 | const BROWSER_NOOP_ANIMATIONS_PROVIDERS = [
|
420 | { provide: AnimationDriver, useClass: ɵNoopAnimationDriver },
|
421 | { provide: ANIMATION_MODULE_TYPE, useValue: 'NoopAnimations' }, ...SHARED_ANIMATION_PROVIDERS
|
422 | ];
|
423 |
|
424 |
|
425 |
|
426 |
|
427 |
|
428 |
|
429 |
|
430 |
|
431 |
|
432 |
|
433 |
|
434 |
|
435 |
|
436 | class BrowserAnimationsModule {
|
437 | |
438 |
|
439 |
|
440 |
|
441 |
|
442 |
|
443 |
|
444 |
|
445 |
|
446 |
|
447 |
|
448 |
|
449 |
|
450 |
|
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 | }
|
461 | BrowserAnimationsModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.0.3", ngImport: i0, type: BrowserAnimationsModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
462 | BrowserAnimationsModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "13.0.3", ngImport: i0, type: BrowserAnimationsModule, exports: [BrowserModule] });
|
463 | BrowserAnimationsModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "13.0.3", ngImport: i0, type: BrowserAnimationsModule, providers: BROWSER_ANIMATIONS_PROVIDERS, imports: [BrowserModule] });
|
464 | i0.ɵɵ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 |
|
473 |
|
474 |
|
475 | class NoopAnimationsModule {
|
476 | }
|
477 | NoopAnimationsModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.0.3", ngImport: i0, type: NoopAnimationsModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
478 | NoopAnimationsModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "13.0.3", ngImport: i0, type: NoopAnimationsModule, exports: [BrowserModule] });
|
479 | NoopAnimationsModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "13.0.3", ngImport: i0, type: NoopAnimationsModule, providers: BROWSER_NOOP_ANIMATIONS_PROVIDERS, imports: [BrowserModule] });
|
480 | i0.ɵɵ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 |
|
490 |
|
491 |
|
492 |
|
493 |
|
494 |
|
495 |
|
496 |
|
497 |
|
498 |
|
499 |
|
500 |
|
501 |
|
502 |
|
503 |
|
504 |
|
505 |
|
506 |
|
507 |
|
508 |
|
509 |
|
510 |
|
511 |
|
512 |
|
513 |
|
514 |
|
515 |
|
516 |
|
517 |
|
518 |
|
519 |
|
520 |
|
521 |
|
522 |
|
523 |
|
524 | export { ANIMATION_MODULE_TYPE, BrowserAnimationsModule, NoopAnimationsModule, AnimationRenderer as ɵAnimationRenderer, AnimationRendererFactory as ɵAnimationRendererFactory, BrowserAnimationBuilder as ɵBrowserAnimationBuilder, BrowserAnimationFactory as ɵBrowserAnimationFactory, InjectableAnimationEngine as ɵInjectableAnimationEngine };
|
525 |
|