@angular/animations 17.0.0-next.8 → 17.0.0-rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,66 +1,12 @@
1
1
  /**
2
- * @license Angular v17.0.0-next.8
2
+ * @license Angular v17.0.0-rc.0
3
3
  * (c) 2010-2022 Google LLC. https://angular.io/
4
4
  * License: MIT
5
5
  */
6
6
 
7
- /**
8
- * An injectable service that produces an animation sequence programmatically within an
9
- * Angular component or directive.
10
- * Provided by the `BrowserAnimationsModule` or `NoopAnimationsModule`.
11
- *
12
- * @usageNotes
13
- *
14
- * To use this service, add it to your component or directive as a dependency.
15
- * The service is instantiated along with your component.
16
- *
17
- * Apps do not typically need to create their own animation players, but if you
18
- * do need to, follow these steps:
19
- *
20
- * 1. Use the <code>[AnimationBuilder.build](api/animations/AnimationBuilder#build)()</code> method
21
- * to create a programmatic animation. The method returns an `AnimationFactory` instance.
22
- *
23
- * 2. Use the factory object to create an `AnimationPlayer` and attach it to a DOM element.
24
- *
25
- * 3. Use the player object to control the animation programmatically.
26
- *
27
- * For example:
28
- *
29
- * ```ts
30
- * // import the service from BrowserAnimationsModule
31
- * import {AnimationBuilder} from '@angular/animations';
32
- * // require the service as a dependency
33
- * class MyCmp {
34
- * constructor(private _builder: AnimationBuilder) {}
35
- *
36
- * makeAnimation(element: any) {
37
- * // first define a reusable animation
38
- * const myAnimation = this._builder.build([
39
- * style({ width: 0 }),
40
- * animate(1000, style({ width: '100px' }))
41
- * ]);
42
- *
43
- * // use the returned factory object to create a player
44
- * const player = myAnimation.create(element);
45
- *
46
- * player.play();
47
- * }
48
- * }
49
- * ```
50
- *
51
- * @publicApi
52
- */
53
- class AnimationBuilder {
54
- }
55
- /**
56
- * A factory object returned from the
57
- * <code>[AnimationBuilder.build](api/animations/AnimationBuilder#build)()</code>
58
- * method.
59
- *
60
- * @publicApi
61
- */
62
- class AnimationFactory {
63
- }
7
+ import { DOCUMENT } from '@angular/common';
8
+ import * as i0 from '@angular/core';
9
+ import { inject, Injectable, ANIMATION_MODULE_TYPE, ViewEncapsulation, ɵRuntimeError, Inject } from '@angular/core';
64
10
 
65
11
  /**
66
12
  * Specifies automatic styling.
@@ -913,6 +859,195 @@ function stagger(timings, animation) {
913
859
  return { type: 12 /* AnimationMetadataType.Stagger */, timings, animation };
914
860
  }
915
861
 
862
+ /**
863
+ * An injectable service that produces an animation sequence programmatically within an
864
+ * Angular component or directive.
865
+ * Provided by the `BrowserAnimationsModule` or `NoopAnimationsModule`.
866
+ *
867
+ * @usageNotes
868
+ *
869
+ * To use this service, add it to your component or directive as a dependency.
870
+ * The service is instantiated along with your component.
871
+ *
872
+ * Apps do not typically need to create their own animation players, but if you
873
+ * do need to, follow these steps:
874
+ *
875
+ * 1. Use the <code>[AnimationBuilder.build](api/animations/AnimationBuilder#build)()</code> method
876
+ * to create a programmatic animation. The method returns an `AnimationFactory` instance.
877
+ *
878
+ * 2. Use the factory object to create an `AnimationPlayer` and attach it to a DOM element.
879
+ *
880
+ * 3. Use the player object to control the animation programmatically.
881
+ *
882
+ * For example:
883
+ *
884
+ * ```ts
885
+ * // import the service from BrowserAnimationsModule
886
+ * import {AnimationBuilder} from '@angular/animations';
887
+ * // require the service as a dependency
888
+ * class MyCmp {
889
+ * constructor(private _builder: AnimationBuilder) {}
890
+ *
891
+ * makeAnimation(element: any) {
892
+ * // first define a reusable animation
893
+ * const myAnimation = this._builder.build([
894
+ * style({ width: 0 }),
895
+ * animate(1000, style({ width: '100px' }))
896
+ * ]);
897
+ *
898
+ * // use the returned factory object to create a player
899
+ * const player = myAnimation.create(element);
900
+ *
901
+ * player.play();
902
+ * }
903
+ * }
904
+ * ```
905
+ *
906
+ * @publicApi
907
+ */
908
+ class AnimationBuilder {
909
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.0-rc.0", ngImport: i0, type: AnimationBuilder, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
910
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.0-rc.0", ngImport: i0, type: AnimationBuilder, providedIn: 'root', useFactory: () => inject(BrowserAnimationBuilder) }); }
911
+ }
912
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.0-rc.0", ngImport: i0, type: AnimationBuilder, decorators: [{
913
+ type: Injectable,
914
+ args: [{ providedIn: 'root', useFactory: () => inject(BrowserAnimationBuilder) }]
915
+ }] });
916
+ /**
917
+ * A factory object returned from the
918
+ * <code>[AnimationBuilder.build](api/animations/AnimationBuilder#build)()</code>
919
+ * method.
920
+ *
921
+ * @publicApi
922
+ */
923
+ class AnimationFactory {
924
+ }
925
+ class BrowserAnimationBuilder extends AnimationBuilder {
926
+ constructor(rootRenderer, doc) {
927
+ super();
928
+ this.animationModuleType = inject(ANIMATION_MODULE_TYPE, { optional: true });
929
+ this._nextAnimationId = 0;
930
+ const typeData = {
931
+ id: '0',
932
+ encapsulation: ViewEncapsulation.None,
933
+ styles: [],
934
+ data: { animation: [] },
935
+ };
936
+ this._renderer = rootRenderer.createRenderer(doc.body, typeData);
937
+ if (this.animationModuleType === null && !isAnimationRenderer(this._renderer)) {
938
+ // We only support AnimationRenderer & DynamicDelegationRenderer for this AnimationBuilder
939
+ throw new ɵRuntimeError(3600 /* RuntimeErrorCode.BROWSER_ANIMATION_BUILDER_INJECTED_WITHOUT_ANIMATIONS */, (typeof ngDevMode === 'undefined' || ngDevMode) &&
940
+ 'Angular detected that the `AnimationBuilder` was injected, but animation support was not enabled. ' +
941
+ 'Please make sure that you enable animations in your application by calling `provideAnimations()` or `provideAnimationsAsync()` function.');
942
+ }
943
+ }
944
+ build(animation) {
945
+ const id = this._nextAnimationId;
946
+ this._nextAnimationId++;
947
+ const entry = Array.isArray(animation) ? sequence(animation) : animation;
948
+ issueAnimationCommand(this._renderer, null, id, 'register', [entry]);
949
+ return new BrowserAnimationFactory(id, this._renderer);
950
+ }
951
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.0-rc.0", ngImport: i0, type: BrowserAnimationBuilder, deps: [{ token: i0.RendererFactory2 }, { token: DOCUMENT }], target: i0.ɵɵFactoryTarget.Injectable }); }
952
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.0-rc.0", ngImport: i0, type: BrowserAnimationBuilder, providedIn: 'root' }); }
953
+ }
954
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.0-rc.0", ngImport: i0, type: BrowserAnimationBuilder, decorators: [{
955
+ type: Injectable,
956
+ args: [{ providedIn: 'root' }]
957
+ }], ctorParameters: () => [{ type: i0.RendererFactory2 }, { type: Document, decorators: [{
958
+ type: Inject,
959
+ args: [DOCUMENT]
960
+ }] }] });
961
+ class BrowserAnimationFactory extends AnimationFactory {
962
+ constructor(_id, _renderer) {
963
+ super();
964
+ this._id = _id;
965
+ this._renderer = _renderer;
966
+ }
967
+ create(element, options) {
968
+ return new RendererAnimationPlayer(this._id, element, options || {}, this._renderer);
969
+ }
970
+ }
971
+ class RendererAnimationPlayer {
972
+ constructor(id, element, options, _renderer) {
973
+ this.id = id;
974
+ this.element = element;
975
+ this._renderer = _renderer;
976
+ this.parentPlayer = null;
977
+ this._started = false;
978
+ this.totalTime = 0;
979
+ this._command('create', options);
980
+ }
981
+ _listen(eventName, callback) {
982
+ return this._renderer.listen(this.element, `@@${this.id}:${eventName}`, callback);
983
+ }
984
+ _command(command, ...args) {
985
+ issueAnimationCommand(this._renderer, this.element, this.id, command, args);
986
+ }
987
+ onDone(fn) {
988
+ this._listen('done', fn);
989
+ }
990
+ onStart(fn) {
991
+ this._listen('start', fn);
992
+ }
993
+ onDestroy(fn) {
994
+ this._listen('destroy', fn);
995
+ }
996
+ init() {
997
+ this._command('init');
998
+ }
999
+ hasStarted() {
1000
+ return this._started;
1001
+ }
1002
+ play() {
1003
+ this._command('play');
1004
+ this._started = true;
1005
+ }
1006
+ pause() {
1007
+ this._command('pause');
1008
+ }
1009
+ restart() {
1010
+ this._command('restart');
1011
+ }
1012
+ finish() {
1013
+ this._command('finish');
1014
+ }
1015
+ destroy() {
1016
+ this._command('destroy');
1017
+ }
1018
+ reset() {
1019
+ this._command('reset');
1020
+ this._started = false;
1021
+ }
1022
+ setPosition(p) {
1023
+ this._command('setPosition', p);
1024
+ }
1025
+ getPosition() {
1026
+ return unwrapAnimationRenderer(this._renderer)?.engine?.players[this.id]?.getPosition() ?? 0;
1027
+ }
1028
+ }
1029
+ function issueAnimationCommand(renderer, element, id, command, args) {
1030
+ renderer.setProperty(element, `@@${id}:${command}`, args);
1031
+ }
1032
+ /**
1033
+ * The following 2 methods cannot reference their correct types (AnimationRenderer &
1034
+ * DynamicDelegationRenderer) since this would introduce a import cycle.
1035
+ */
1036
+ function unwrapAnimationRenderer(renderer) {
1037
+ const type = renderer.ɵtype;
1038
+ if (type === 0 /* AnimationRendererType.Regular */) {
1039
+ return renderer;
1040
+ }
1041
+ else if (type === 1 /* AnimationRendererType.Delegated */) {
1042
+ return renderer.animationRenderer;
1043
+ }
1044
+ return null;
1045
+ }
1046
+ function isAnimationRenderer(renderer) {
1047
+ const type = renderer.ɵtype;
1048
+ return type === 0 /* AnimationRendererType.Regular */ || type === 1 /* AnimationRendererType.Delegated */;
1049
+ }
1050
+
916
1051
  /**
917
1052
  * An empty programmatic controller for reusable animations.
918
1053
  * Used internally when animations are disabled, to avoid
@@ -1171,5 +1306,5 @@ const ɵPRE_STYLE = '!';
1171
1306
  * Generated bundle index. Do not edit.
1172
1307
  */
1173
1308
 
1174
- export { AUTO_STYLE, AnimationBuilder, AnimationFactory, NoopAnimationPlayer, animate, animateChild, animation, group, keyframes, query, sequence, stagger, state, style, transition, trigger, useAnimation, AnimationGroupPlayer as ɵAnimationGroupPlayer, ɵPRE_STYLE };
1309
+ export { AUTO_STYLE, AnimationBuilder, AnimationFactory, NoopAnimationPlayer, animate, animateChild, animation, group, keyframes, query, sequence, stagger, state, style, transition, trigger, useAnimation, AnimationGroupPlayer as ɵAnimationGroupPlayer, BrowserAnimationBuilder as ɵBrowserAnimationBuilder, ɵPRE_STYLE };
1175
1310
  //# sourceMappingURL=animations.mjs.map