@angular-wave/angular.ts 0.0.1

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.
Files changed (231) hide show
  1. package/.eslintignore +1 -0
  2. package/.eslintrc.cjs +29 -0
  3. package/.github/workflows/playwright.yml +27 -0
  4. package/CHANGELOG.md +17974 -0
  5. package/CODE_OF_CONDUCT.md +3 -0
  6. package/CONTRIBUTING.md +246 -0
  7. package/DEVELOPERS.md +488 -0
  8. package/LICENSE +22 -0
  9. package/Makefile +31 -0
  10. package/README.md +115 -0
  11. package/RELEASE.md +98 -0
  12. package/SECURITY.md +16 -0
  13. package/TRIAGING.md +135 -0
  14. package/css/angular.css +22 -0
  15. package/dist/angular-ts.cjs.js +36843 -0
  16. package/dist/angular-ts.esm.js +36841 -0
  17. package/dist/angular-ts.umd.js +36848 -0
  18. package/dist/build/angular-animate.js +4272 -0
  19. package/dist/build/angular-aria.js +426 -0
  20. package/dist/build/angular-message-format.js +1072 -0
  21. package/dist/build/angular-messages.js +829 -0
  22. package/dist/build/angular-mocks.js +3757 -0
  23. package/dist/build/angular-parse-ext.js +1275 -0
  24. package/dist/build/angular-resource.js +911 -0
  25. package/dist/build/angular-route.js +1266 -0
  26. package/dist/build/angular-sanitize.js +891 -0
  27. package/dist/build/angular-touch.js +368 -0
  28. package/dist/build/angular.js +36600 -0
  29. package/e2e/unit.spec.ts +15 -0
  30. package/images/android-chrome-192x192.png +0 -0
  31. package/images/android-chrome-512x512.png +0 -0
  32. package/images/apple-touch-icon.png +0 -0
  33. package/images/favicon-16x16.png +0 -0
  34. package/images/favicon-32x32.png +0 -0
  35. package/images/favicon.ico +0 -0
  36. package/images/site.webmanifest +1 -0
  37. package/index.html +104 -0
  38. package/package.json +47 -0
  39. package/playwright.config.ts +78 -0
  40. package/public/circle.html +1 -0
  41. package/public/my_child_directive.html +1 -0
  42. package/public/my_directive.html +1 -0
  43. package/public/my_other_directive.html +1 -0
  44. package/public/test.html +1 -0
  45. package/rollup.config.js +31 -0
  46. package/src/animations/animateCache.js +55 -0
  47. package/src/animations/animateChildrenDirective.js +105 -0
  48. package/src/animations/animateCss.js +1139 -0
  49. package/src/animations/animateCssDriver.js +291 -0
  50. package/src/animations/animateJs.js +367 -0
  51. package/src/animations/animateJsDriver.js +67 -0
  52. package/src/animations/animateQueue.js +851 -0
  53. package/src/animations/animation.js +506 -0
  54. package/src/animations/module.js +779 -0
  55. package/src/animations/ngAnimateSwap.js +119 -0
  56. package/src/animations/rafScheduler.js +50 -0
  57. package/src/animations/shared.js +378 -0
  58. package/src/constants.js +20 -0
  59. package/src/core/animate.js +845 -0
  60. package/src/core/animateCss.js +73 -0
  61. package/src/core/animateRunner.js +195 -0
  62. package/src/core/attributes.js +199 -0
  63. package/src/core/cache.js +45 -0
  64. package/src/core/compile.js +4727 -0
  65. package/src/core/controller.js +225 -0
  66. package/src/core/exceptionHandler.js +63 -0
  67. package/src/core/filter.js +146 -0
  68. package/src/core/interpolate.js +442 -0
  69. package/src/core/interval.js +188 -0
  70. package/src/core/intervalFactory.js +57 -0
  71. package/src/core/location.js +1086 -0
  72. package/src/core/parser/parse.js +2562 -0
  73. package/src/core/parser/parse.md +13 -0
  74. package/src/core/q.js +746 -0
  75. package/src/core/rootScope.js +1596 -0
  76. package/src/core/sanitizeUri.js +85 -0
  77. package/src/core/sce.js +1161 -0
  78. package/src/core/taskTrackerFactory.js +125 -0
  79. package/src/core/timeout.js +121 -0
  80. package/src/core/urlUtils.js +187 -0
  81. package/src/core/utils.js +1349 -0
  82. package/src/directive/a.js +37 -0
  83. package/src/directive/attrs.js +283 -0
  84. package/src/directive/bind.js +51 -0
  85. package/src/directive/bind.md +142 -0
  86. package/src/directive/change.js +12 -0
  87. package/src/directive/change.md +25 -0
  88. package/src/directive/cloak.js +12 -0
  89. package/src/directive/cloak.md +24 -0
  90. package/src/directive/events.js +75 -0
  91. package/src/directive/events.md +166 -0
  92. package/src/directive/form.js +725 -0
  93. package/src/directive/init.js +15 -0
  94. package/src/directive/init.md +41 -0
  95. package/src/directive/input.js +1783 -0
  96. package/src/directive/list.js +46 -0
  97. package/src/directive/list.md +22 -0
  98. package/src/directive/ngClass.js +249 -0
  99. package/src/directive/ngController.js +64 -0
  100. package/src/directive/ngCsp.js +82 -0
  101. package/src/directive/ngIf.js +134 -0
  102. package/src/directive/ngInclude.js +217 -0
  103. package/src/directive/ngModel.js +1356 -0
  104. package/src/directive/ngModelOptions.js +509 -0
  105. package/src/directive/ngOptions.js +670 -0
  106. package/src/directive/ngRef.js +90 -0
  107. package/src/directive/ngRepeat.js +650 -0
  108. package/src/directive/ngShowHide.js +255 -0
  109. package/src/directive/ngSwitch.js +178 -0
  110. package/src/directive/ngTransclude.js +98 -0
  111. package/src/directive/non-bindable.js +11 -0
  112. package/src/directive/non-bindable.md +17 -0
  113. package/src/directive/script.js +30 -0
  114. package/src/directive/select.js +624 -0
  115. package/src/directive/style.js +25 -0
  116. package/src/directive/style.md +23 -0
  117. package/src/directive/validators.js +329 -0
  118. package/src/exts/aria.js +544 -0
  119. package/src/exts/messages.js +852 -0
  120. package/src/filters/filter.js +207 -0
  121. package/src/filters/filter.md +69 -0
  122. package/src/filters/filters.js +239 -0
  123. package/src/filters/json.md +16 -0
  124. package/src/filters/limit-to.js +43 -0
  125. package/src/filters/limit-to.md +19 -0
  126. package/src/filters/order-by.js +183 -0
  127. package/src/filters/order-by.md +83 -0
  128. package/src/index.js +13 -0
  129. package/src/injector.js +1034 -0
  130. package/src/jqLite.js +1117 -0
  131. package/src/loader.js +1320 -0
  132. package/src/public.js +215 -0
  133. package/src/routeToRegExp.js +41 -0
  134. package/src/services/anchorScroll.js +135 -0
  135. package/src/services/browser.js +321 -0
  136. package/src/services/cacheFactory.js +398 -0
  137. package/src/services/cookieReader.js +72 -0
  138. package/src/services/document.js +64 -0
  139. package/src/services/http.js +1537 -0
  140. package/src/services/httpBackend.js +206 -0
  141. package/src/services/log.js +160 -0
  142. package/src/services/templateRequest.js +139 -0
  143. package/test/angular.spec.js +2153 -0
  144. package/test/aria/aria.spec.js +1245 -0
  145. package/test/binding.spec.js +504 -0
  146. package/test/build-test.html +14 -0
  147. package/test/injector.spec.js +2327 -0
  148. package/test/jasmine/jasmine-5.1.2/boot0.js +65 -0
  149. package/test/jasmine/jasmine-5.1.2/boot1.js +133 -0
  150. package/test/jasmine/jasmine-5.1.2/jasmine-html.js +963 -0
  151. package/test/jasmine/jasmine-5.1.2/jasmine.css +320 -0
  152. package/test/jasmine/jasmine-5.1.2/jasmine.js +10824 -0
  153. package/test/jasmine/jasmine-5.1.2/jasmine_favicon.png +0 -0
  154. package/test/jasmine/jasmine-browser.json +17 -0
  155. package/test/jasmine/jasmine.json +9 -0
  156. package/test/jqlite.spec.js +2133 -0
  157. package/test/loader.spec.js +219 -0
  158. package/test/messages/messages.spec.js +1146 -0
  159. package/test/min-err.spec.js +174 -0
  160. package/test/mock-test.html +13 -0
  161. package/test/module-test.html +15 -0
  162. package/test/ng/anomate.spec.js +606 -0
  163. package/test/ng/cache-factor.spec.js +334 -0
  164. package/test/ng/compile.spec.js +17956 -0
  165. package/test/ng/controller-provider.spec.js +227 -0
  166. package/test/ng/cookie-reader.spec.js +98 -0
  167. package/test/ng/directive/a.spec.js +192 -0
  168. package/test/ng/directive/bind.spec.js +334 -0
  169. package/test/ng/directive/boolean.spec.js +136 -0
  170. package/test/ng/directive/change.spec.js +71 -0
  171. package/test/ng/directive/class.spec.js +858 -0
  172. package/test/ng/directive/click.spec.js +38 -0
  173. package/test/ng/directive/cloak.spec.js +44 -0
  174. package/test/ng/directive/constoller.spec.js +194 -0
  175. package/test/ng/directive/element-style.spec.js +92 -0
  176. package/test/ng/directive/event.spec.js +282 -0
  177. package/test/ng/directive/form.spec.js +1518 -0
  178. package/test/ng/directive/href.spec.js +143 -0
  179. package/test/ng/directive/if.spec.js +402 -0
  180. package/test/ng/directive/include.spec.js +828 -0
  181. package/test/ng/directive/init.spec.js +68 -0
  182. package/test/ng/directive/input.spec.js +3810 -0
  183. package/test/ng/directive/list.spec.js +170 -0
  184. package/test/ng/directive/model-options.spec.js +1008 -0
  185. package/test/ng/directive/model.spec.js +1905 -0
  186. package/test/ng/directive/non-bindable.spec.js +55 -0
  187. package/test/ng/directive/options.spec.js +3583 -0
  188. package/test/ng/directive/ref.spec.js +575 -0
  189. package/test/ng/directive/repeat.spec.js +1675 -0
  190. package/test/ng/directive/script.spec.js +52 -0
  191. package/test/ng/directive/scrset.spec.js +67 -0
  192. package/test/ng/directive/select.spec.js +2541 -0
  193. package/test/ng/directive/show-hide.spec.js +253 -0
  194. package/test/ng/directive/src.spec.js +157 -0
  195. package/test/ng/directive/style.spec.js +178 -0
  196. package/test/ng/directive/switch.spec.js +647 -0
  197. package/test/ng/directive/validators.spec.js +717 -0
  198. package/test/ng/document.spec.js +52 -0
  199. package/test/ng/filter/filter.spec.js +714 -0
  200. package/test/ng/filter/filters.spec.js +35 -0
  201. package/test/ng/filter/limit-to.spec.js +251 -0
  202. package/test/ng/filter/order-by.spec.js +891 -0
  203. package/test/ng/filter.spec.js +149 -0
  204. package/test/ng/http-backend.spec.js +398 -0
  205. package/test/ng/http.spec.js +4071 -0
  206. package/test/ng/interpolate.spec.js +642 -0
  207. package/test/ng/interval.spec.js +343 -0
  208. package/test/ng/location.spec.js +3488 -0
  209. package/test/ng/on.spec.js +229 -0
  210. package/test/ng/parse.spec.js +4655 -0
  211. package/test/ng/prop.spec.js +805 -0
  212. package/test/ng/q.spec.js +2904 -0
  213. package/test/ng/root-element.spec.js +16 -0
  214. package/test/ng/sanitize-uri.spec.js +249 -0
  215. package/test/ng/sce.spec.js +660 -0
  216. package/test/ng/scope.spec.js +3442 -0
  217. package/test/ng/template-request.spec.js +236 -0
  218. package/test/ng/timeout.spec.js +351 -0
  219. package/test/ng/url-utils.spec.js +156 -0
  220. package/test/ng/utils.spec.js +144 -0
  221. package/test/original-test.html +21 -0
  222. package/test/public.spec.js +34 -0
  223. package/test/sanitize/bing-html.spec.js +36 -0
  224. package/test/server/express.js +158 -0
  225. package/test/test-utils.js +11 -0
  226. package/tsconfig.json +17 -0
  227. package/types/angular.d.ts +138 -0
  228. package/types/global.d.ts +9 -0
  229. package/types/index.d.ts +2357 -0
  230. package/types/jqlite.d.ts +558 -0
  231. package/vite.config.js +14 -0
@@ -0,0 +1,1139 @@
1
+ import { jqLite } from "../jqLite";
2
+ import { forEach, isDefined, isArray } from "../core/utils";
3
+ import {
4
+ TRANSITION_DURATION_PROP,
5
+ TRANSITION_DELAY_PROP,
6
+ ANIMATION_DELAY_PROP,
7
+ TRANSITION_PROP,
8
+ PROPERTY_KEY,
9
+ ANIMATION_DURATION_PROP,
10
+ ANIMATION_ITERATION_COUNT_KEY,
11
+ ANIMATION_PROP,
12
+ DURATION_KEY,
13
+ applyAnimationClassesFactory,
14
+ pendClasses,
15
+ prepareAnimationOptions,
16
+ getDomNode,
17
+ packageStyles,
18
+ EVENT_CLASS_PREFIX,
19
+ ADD_CLASS_SUFFIX,
20
+ REMOVE_CLASS_SUFFIX,
21
+ applyInlineStyle,
22
+ SAFE_FAST_FORWARD_DURATION_VALUE,
23
+ ACTIVE_CLASS_SUFFIX,
24
+ applyAnimationFromStyles,
25
+ applyAnimationStyles,
26
+ blockKeyframeAnimations,
27
+ removeFromArray,
28
+ TIMING_KEY,
29
+ TRANSITIONEND_EVENT,
30
+ ANIMATIONEND_EVENT,
31
+ applyAnimationToStyles,
32
+ } from "./shared";
33
+
34
+ const ANIMATE_TIMER_KEY = "$$animateCss";
35
+
36
+ /**
37
+ * @ngdoc service
38
+ * @name $animateCss
39
+ * @kind object
40
+ *
41
+ * @description
42
+ * The `$animateCss` service is a useful utility to trigger customized CSS-based transitions/keyframes
43
+ * from a JavaScript-based animation or directly from a directive. The purpose of `$animateCss` is NOT
44
+ * to side-step how `$animate` and ngAnimate work, but the goal is to allow pre-existing animations or
45
+ * directives to create more complex animations that can be purely driven using CSS code.
46
+ *
47
+ * Note that only browsers that support CSS transitions and/or keyframe animations are capable of
48
+ * rendering animations triggered via `$animateCss` (bad news for IE9 and lower).
49
+ *
50
+ * ## General Use
51
+ * Once again, `$animateCss` is designed to be used inside of a registered JavaScript animation that
52
+ * is powered by ngAnimate. It is possible to use `$animateCss` directly inside of a directive, however,
53
+ * any automatic control over cancelling animations and/or preventing animations from being run on
54
+ * child elements will not be handled by AngularJS. For this to work as expected, please use `$animate` to
55
+ * trigger the animation and then setup a JavaScript animation that injects `$animateCss` to trigger
56
+ * the CSS animation.
57
+ *
58
+ * The example below shows how we can create a folding animation on an element using `ng-if`:
59
+ *
60
+ * ```html
61
+ * <!-- notice the `fold-animation` CSS class -->
62
+ * <div ng-if="onOff" class="fold-animation">
63
+ * This element will go BOOM
64
+ * </div>
65
+ * <button ng-click="onOff=true">Fold In</button>
66
+ * ```
67
+ *
68
+ * Now we create the **JavaScript animation** that will trigger the CSS transition:
69
+ *
70
+ * ```js
71
+ * ngModule.animation('.fold-animation', ['$animateCss', function($animateCss) {
72
+ * return {
73
+ * enter: function(element, doneFn) {
74
+ * let height = element[0].offsetHeight;
75
+ * return $animateCss(element, {
76
+ * from: { height:'0px' },
77
+ * to: { height:height + 'px' },
78
+ * duration: 1 // one second
79
+ * });
80
+ * }
81
+ * }
82
+ * }]);
83
+ * ```
84
+ *
85
+ * ## More Advanced Uses
86
+ *
87
+ * `$animateCss` is the underlying code that ngAnimate uses to power **CSS-based animations** behind the scenes. Therefore CSS hooks
88
+ * like `.ng-EVENT`, `.ng-EVENT-active`, `.ng-EVENT-stagger` are all features that can be triggered using `$animateCss` via JavaScript code.
89
+ *
90
+ * This also means that just about any combination of adding classes, removing classes, setting styles, dynamically setting a keyframe animation,
91
+ * applying a hardcoded duration or delay value, changing the animation easing or applying a stagger animation are all options that work with
92
+ * `$animateCss`. The service itself is smart enough to figure out the combination of options and examine the element styling properties in order
93
+ * to provide a working animation that will run in CSS.
94
+ *
95
+ * The example below showcases a more advanced version of the `.fold-animation` from the example above:
96
+ *
97
+ * ```js
98
+ * ngModule.animation('.fold-animation', ['$animateCss', function($animateCss) {
99
+ * return {
100
+ * enter: function(element, doneFn) {
101
+ * let height = element[0].offsetHeight;
102
+ * return $animateCss(element, {
103
+ * addClass: 'red large-text pulse-twice',
104
+ * easing: 'ease-out',
105
+ * from: { height:'0px' },
106
+ * to: { height:height + 'px' },
107
+ * duration: 1 // one second
108
+ * });
109
+ * }
110
+ * }
111
+ * }]);
112
+ * ```
113
+ *
114
+ * Since we're adding/removing CSS classes then the CSS transition will also pick those up:
115
+ *
116
+ * ```css
117
+ * /&#42; since a hardcoded duration value of 1 was provided in the JavaScript animation code,
118
+ * the CSS classes below will be transitioned despite them being defined as regular CSS classes &#42;/
119
+ * .red { background:red; }
120
+ * .large-text { font-size:20px; }
121
+ *
122
+ * /&#42; we can also use a keyframe animation and $animateCss will make it work alongside the transition &#42;/
123
+ * .pulse-twice {
124
+ * animation: 0.5s pulse linear 2;
125
+ * -webkit-animation: 0.5s pulse linear 2;
126
+ * }
127
+ *
128
+ * @keyframes pulse {
129
+ * from { transform: scale(0.5); }
130
+ * to { transform: scale(1.5); }
131
+ * }
132
+ *
133
+ * @-webkit-keyframes pulse {
134
+ * from { -webkit-transform: scale(0.5); }
135
+ * to { -webkit-transform: scale(1.5); }
136
+ * }
137
+ * ```
138
+ *
139
+ * Given this complex combination of CSS classes, styles and options, `$animateCss` will figure everything out and make the animation happen.
140
+ *
141
+ * ## How the Options are handled
142
+ *
143
+ * `$animateCss` is very versatile and intelligent when it comes to figuring out what configurations to apply to the element to ensure the animation
144
+ * works with the options provided. Say for example we were adding a class that contained a keyframe value and we wanted to also animate some inline
145
+ * styles using the `from` and `to` properties.
146
+ *
147
+ * ```js
148
+ * let animator = $animateCss(element, {
149
+ * from: { background:'red' },
150
+ * to: { background:'blue' }
151
+ * });
152
+ * animator.start();
153
+ * ```
154
+ *
155
+ * ```css
156
+ * .rotating-animation {
157
+ * animation:0.5s rotate linear;
158
+ * -webkit-animation:0.5s rotate linear;
159
+ * }
160
+ *
161
+ * @keyframes rotate {
162
+ * from { transform: rotate(0deg); }
163
+ * to { transform: rotate(360deg); }
164
+ * }
165
+ *
166
+ * @-webkit-keyframes rotate {
167
+ * from { -webkit-transform: rotate(0deg); }
168
+ * to { -webkit-transform: rotate(360deg); }
169
+ * }
170
+ * ```
171
+ *
172
+ * The missing pieces here are that we do not have a transition set (within the CSS code nor within the `$animateCss` options) and the duration of the animation is
173
+ * going to be detected from what the keyframe styles on the CSS class are. In this event, `$animateCss` will automatically create an inline transition
174
+ * style matching the duration detected from the keyframe style (which is present in the CSS class that is being added) and then prepare both the transition
175
+ * and keyframe animations to run in parallel on the element. Then when the animation is underway the provided `from` and `to` CSS styles will be applied
176
+ * and spread across the transition and keyframe animation.
177
+ *
178
+ * ## What is returned
179
+ *
180
+ * `$animateCss` works in two stages: a preparation phase and an animation phase. Therefore when `$animateCss` is first called it will NOT actually
181
+ * start the animation. All that is going on here is that the element is being prepared for the animation (which means that the generated CSS classes are
182
+ * added and removed on the element). Once `$animateCss` is called it will return an object with the following properties:
183
+ *
184
+ * ```js
185
+ * let animator = $animateCss(element, { ... });
186
+ * ```
187
+ *
188
+ * Now what do the contents of our `animator` variable look like:
189
+ *
190
+ * ```js
191
+ * {
192
+ * // starts the animation
193
+ * start: Function,
194
+ *
195
+ * // ends (aborts) the animation
196
+ * end: Function
197
+ * }
198
+ * ```
199
+ *
200
+ * To actually start the animation we need to run `animation.start()` which will then return a promise that we can hook into to detect when the animation ends.
201
+ * If we choose not to run the animation then we MUST run `animation.end()` to perform a cleanup on the element (since some CSS classes and styles may have been
202
+ * applied to the element during the preparation phase). Note that all other properties such as duration, delay, transitions and keyframes are just properties
203
+ * and that changing them will not reconfigure the parameters of the animation.
204
+ *
205
+ * ### runner.done() vs runner.then()
206
+ * It is documented that `animation.start()` will return a promise object and this is true, however, there is also an additional method available on the
207
+ * runner called `.done(callbackFn)`. The done method works the same as `.finally(callbackFn)`, however, it does **not trigger a digest to occur**.
208
+ * Therefore, for performance reasons, it's always best to use `runner.done(callback)` instead of `runner.then()`, `runner.catch()` or `runner.finally()`
209
+ * unless you really need a digest to kick off afterwards.
210
+ *
211
+ * Keep in mind that, to make this easier, ngAnimate has tweaked the JS animations API to recognize when a runner instance is returned from $animateCss
212
+ * (so there is no need to call `runner.done(doneFn)` inside of your JavaScript animation code).
213
+ * Check the {@link ngAnimate.$animateCss#usage animation code above} to see how this works.
214
+ *
215
+ * @param {Element} element the element that will be animated
216
+ * @param {object} options the animation-related options that will be applied during the animation
217
+ *
218
+ * * `event` - The DOM event (e.g. enter, leave, move). When used, a generated CSS class of `ng-EVENT` and `ng-EVENT-active` will be applied
219
+ * to the element during the animation. Multiple events can be provided when spaces are used as a separator. (Note that this will not perform any DOM operation.)
220
+ * * `structural` - Indicates that the `ng-` prefix will be added to the event class. Setting to `false` or omitting will turn `ng-EVENT` and
221
+ * `ng-EVENT-active` in `EVENT` and `EVENT-active`. Unused if `event` is omitted.
222
+ * * `easing` - The CSS easing value that will be applied to the transition or keyframe animation (or both).
223
+ * * `transitionStyle` - The raw CSS transition style that will be used (e.g. `1s linear all`).
224
+ * * `keyframeStyle` - The raw CSS keyframe animation style that will be used (e.g. `1s my_animation linear`).
225
+ * * `from` - The starting CSS styles (a key/value object) that will be applied at the start of the animation.
226
+ * * `to` - The ending CSS styles (a key/value object) that will be applied across the animation via a CSS transition.
227
+ * * `addClass` - A space separated list of CSS classes that will be added to the element and spread across the animation.
228
+ * * `removeClass` - A space separated list of CSS classes that will be removed from the element and spread across the animation.
229
+ * * `duration` - A number value representing the total duration of the transition and/or keyframe (note that a value of 1 is 1000ms). If a value of `0`
230
+ * is provided then the animation will be skipped entirely.
231
+ * * `delay` - A number value representing the total delay of the transition and/or keyframe (note that a value of 1 is 1000ms). If a value of `true` is
232
+ * used then whatever delay value is detected from the CSS classes will be mirrored on the elements styles (e.g. by setting delay true then the style value
233
+ * of the element will be `transition-delay: DETECTED_VALUE`). Using `true` is useful when you want the CSS classes and inline styles to all share the same
234
+ * CSS delay value.
235
+ * * `stagger` - A numeric time value representing the delay between successively animated elements
236
+ * ({@link ngAnimate#css-staggering-animations Click here to learn how CSS-based staggering works in ngAnimate.})
237
+ * * `staggerIndex` - The numeric index representing the stagger item (e.g. a value of 5 is equal to the sixth item in the stagger; therefore when a
238
+ * `stagger` option value of `0.1` is used then there will be a stagger delay of `600ms`)
239
+ * * `applyClassesEarly` - Whether or not the classes being added or removed will be used when detecting the animation. This is set by `$animate` when enter/leave/move animations are fired to ensure that the CSS classes are resolved in time. (Note that this will prevent any transitions from occurring on the classes being added and removed.)
240
+ * * `cleanupStyles` - Whether or not the provided `from` and `to` styles will be removed once
241
+ * the animation is closed. This is useful for when the styles are used purely for the sake of
242
+ * the animation and do not have a lasting visual effect on the element (e.g. a collapse and open animation).
243
+ * By default this value is set to `false`.
244
+ *
245
+ * @return {object} an object with start and end methods and details about the animation.
246
+ *
247
+ * * `start` - The method to start the animation. This will return a `Promise` when called.
248
+ * * `end` - This method will cancel the animation and remove all applied CSS classes and styles.
249
+ */
250
+ const ONE_SECOND = 1000;
251
+
252
+ const ELAPSED_TIME_MAX_DECIMAL_PLACES = 3;
253
+ const CLOSING_TIME_BUFFER = 1.5;
254
+
255
+ const DETECT_CSS_PROPERTIES = {
256
+ transitionDuration: TRANSITION_DURATION_PROP,
257
+ transitionDelay: TRANSITION_DELAY_PROP,
258
+ transitionProperty: TRANSITION_PROP + PROPERTY_KEY,
259
+ animationDuration: ANIMATION_DURATION_PROP,
260
+ animationDelay: ANIMATION_DELAY_PROP,
261
+ animationIterationCount: ANIMATION_PROP + ANIMATION_ITERATION_COUNT_KEY,
262
+ };
263
+
264
+ const DETECT_STAGGER_CSS_PROPERTIES = {
265
+ transitionDuration: TRANSITION_DURATION_PROP,
266
+ transitionDelay: TRANSITION_DELAY_PROP,
267
+ animationDuration: ANIMATION_DURATION_PROP,
268
+ animationDelay: ANIMATION_DELAY_PROP,
269
+ };
270
+
271
+ function getCssKeyframeDurationStyle(duration) {
272
+ return [ANIMATION_DURATION_PROP, `${duration}s`];
273
+ }
274
+
275
+ function getCssDelayStyle(delay, isKeyframeAnimation) {
276
+ const prop = isKeyframeAnimation
277
+ ? ANIMATION_DELAY_PROP
278
+ : TRANSITION_DELAY_PROP;
279
+ return [prop, `${delay}s`];
280
+ }
281
+
282
+ function computeCssStyles(element, properties) {
283
+ const styles = Object.create(null);
284
+ const detectedStyles = window.getComputedStyle(element) || {};
285
+ forEach(properties, (formalStyleName, actualStyleName) => {
286
+ let val = detectedStyles[formalStyleName];
287
+ if (val) {
288
+ const c = val.charAt(0);
289
+
290
+ // only numerical-based values have a negative sign or digit as the first value
291
+ if (c === "-" || c === "+" || c >= 0) {
292
+ val = parseMaxTime(val);
293
+ }
294
+
295
+ // by setting this to null in the event that the delay is not set or is set directly as 0
296
+ // then we can still allow for negative values to be used later on and not mistake this
297
+ // value for being greater than any other negative value.
298
+ if (val === 0) {
299
+ val = null;
300
+ }
301
+ styles[actualStyleName] = val;
302
+ }
303
+ });
304
+
305
+ return styles;
306
+ }
307
+
308
+ function parseMaxTime(str) {
309
+ let maxValue = 0;
310
+ const values = str.split(/\s*,\s*/);
311
+ forEach(values, (value) => {
312
+ // it's always safe to consider only second values and omit `ms` values since
313
+ // getComputedStyle will always handle the conversion for us
314
+ if (value.charAt(value.length - 1) === "s") {
315
+ value = value.substring(0, value.length - 1);
316
+ }
317
+ value = parseFloat(value) || 0;
318
+ maxValue = maxValue ? Math.max(value, maxValue) : value;
319
+ });
320
+ return maxValue;
321
+ }
322
+
323
+ function truthyTimingValue(val) {
324
+ return val === 0 || val != null;
325
+ }
326
+
327
+ function getCssTransitionDurationStyle(duration, applyOnlyDuration) {
328
+ let style = TRANSITION_PROP;
329
+ let value = `${duration}s`;
330
+ if (applyOnlyDuration) {
331
+ style += DURATION_KEY;
332
+ } else {
333
+ value += " linear all";
334
+ }
335
+ return [style, value];
336
+ }
337
+
338
+ // we do not reassign an already present style value since
339
+ // if we detect the style property value again we may be
340
+ // detecting styles that were added via the `from` styles.
341
+ // We make use of `isDefined` here since an empty string
342
+ // or null value (which is what getPropertyValue will return
343
+ // for a non-existing style) will still be marked as a valid
344
+ // value for the style (a falsy value implies that the style
345
+ // is to be removed at the end of the animation). If we had a simple
346
+ // "OR" statement then it would not be enough to catch that.
347
+ function registerRestorableStyles(backup, node, properties) {
348
+ forEach(properties, (prop) => {
349
+ backup[prop] = isDefined(backup[prop])
350
+ ? backup[prop]
351
+ : node.style.getPropertyValue(prop);
352
+ });
353
+ }
354
+
355
+ export const $AnimateCssProvider = [
356
+ function () {
357
+ this.$get = [
358
+ "$$AnimateRunner",
359
+ "$timeout",
360
+ "$$animateCache",
361
+ "$$rAFScheduler",
362
+ "$$animateQueue",
363
+ function (
364
+ $$AnimateRunner,
365
+ $timeout,
366
+ $$animateCache,
367
+ $$rAFScheduler,
368
+ $$animateQueue,
369
+ ) {
370
+ const applyAnimationClasses = applyAnimationClassesFactory();
371
+
372
+ function computeCachedCssStyles(
373
+ node,
374
+ className,
375
+ cacheKey,
376
+ allowNoDuration,
377
+ properties,
378
+ ) {
379
+ let timings = $$animateCache.get(cacheKey);
380
+
381
+ if (!timings) {
382
+ timings = computeCssStyles(window, node, properties);
383
+ if (timings.animationIterationCount === "infinite") {
384
+ timings.animationIterationCount = 1;
385
+ }
386
+ }
387
+
388
+ // if a css animation has no duration we
389
+ // should mark that so that repeated addClass/removeClass calls are skipped
390
+ const hasDuration =
391
+ allowNoDuration ||
392
+ timings.transitionDuration > 0 ||
393
+ timings.animationDuration > 0;
394
+
395
+ // we keep putting this in multiple times even though the value and the cacheKey are the same
396
+ // because we're keeping an internal tally of how many duplicate animations are detected.
397
+ $$animateCache.put(cacheKey, timings, hasDuration);
398
+
399
+ return timings;
400
+ }
401
+
402
+ function computeCachedCssStaggerStyles(
403
+ node,
404
+ className,
405
+ cacheKey,
406
+ properties,
407
+ ) {
408
+ let stagger;
409
+ const staggerCacheKey = `stagger-${cacheKey}`;
410
+
411
+ // if we have one or more existing matches of matching elements
412
+ // containing the same parent + CSS styles (which is how cacheKey works)
413
+ // then staggering is possible
414
+ if ($$animateCache.count(cacheKey) > 0) {
415
+ stagger = $$animateCache.get(staggerCacheKey);
416
+
417
+ if (!stagger) {
418
+ const staggerClassName = pendClasses(className, "-stagger");
419
+
420
+ node.className += ` ${staggerClassName}`;
421
+ stagger = computeCssStyles(window, node, properties);
422
+
423
+ // force the conversion of a null value to zero incase not set
424
+ stagger.animationDuration = Math.max(
425
+ stagger.animationDuration,
426
+ 0,
427
+ );
428
+ stagger.transitionDuration = Math.max(
429
+ stagger.transitionDuration,
430
+ 0,
431
+ );
432
+
433
+ node.classList.remove(staggerClassName);
434
+
435
+ $$animateCache.put(staggerCacheKey, stagger, true);
436
+ }
437
+ }
438
+
439
+ return stagger || {};
440
+ }
441
+
442
+ const rafWaitQueue = [];
443
+ function waitUntilQuiet(callback) {
444
+ rafWaitQueue.push(callback);
445
+ $$rAFScheduler.waitUntilQuiet(() => {
446
+ $$animateCache.flush();
447
+
448
+ // DO NOT REMOVE THIS LINE OR REFACTOR OUT THE `pageWidth` variable.
449
+ // the line below will force the browser to perform a repaint so
450
+ // that all the animated elements within the animation frame will
451
+ // be properly updated and drawn on screen. This is required to
452
+ // ensure that the preparation animation is properly flushed so that
453
+ // the active state picks up from there. DO NOT REMOVE THIS LINE.
454
+ // DO NOT OPTIMIZE THIS LINE. THE MINIFIER WILL REMOVE IT OTHERWISE WHICH
455
+ // WILL RESULT IN AN UNPREDICTABLE BUG THAT IS VERY HARD TO TRACK DOWN AND
456
+ // WILL TAKE YEARS AWAY FROM YOUR LIFE.
457
+
458
+ const pageWidth = document.body.offsetWidth + 1;
459
+
460
+ // we use a for loop to ensure that if the queue is changed
461
+ // during this looping then it will consider new requests
462
+ for (let i = 0; i < rafWaitQueue.length; i++) {
463
+ rafWaitQueue[i](pageWidth);
464
+ }
465
+ rafWaitQueue.length = 0;
466
+ });
467
+ }
468
+
469
+ function computeTimings(node, className, cacheKey, allowNoDuration) {
470
+ const timings = computeCachedCssStyles(
471
+ node,
472
+ className,
473
+ cacheKey,
474
+ allowNoDuration,
475
+ DETECT_CSS_PROPERTIES,
476
+ );
477
+ const aD = timings.animationDelay;
478
+ const tD = timings.transitionDelay;
479
+ timings.maxDelay = aD && tD ? Math.max(aD, tD) : aD || tD;
480
+ timings.maxDuration = Math.max(
481
+ timings.animationDuration * timings.animationIterationCount,
482
+ timings.transitionDuration,
483
+ );
484
+
485
+ return timings;
486
+ }
487
+
488
+ return function init(element, initialOptions) {
489
+ // all of the animation functions should create
490
+ // a copy of the options data, however, if a
491
+ // parent service has already created a copy then
492
+ // we should stick to using that
493
+ let options = initialOptions || {};
494
+ if (!options.$$prepared) {
495
+ options = prepareAnimationOptions(structuredClone(options));
496
+ }
497
+
498
+ const restoreStyles = {};
499
+ const node = getDomNode(element);
500
+ if (!node || !node.parentNode || !$$animateQueue.enabled()) {
501
+ return closeAndReturnNoopAnimator();
502
+ }
503
+
504
+ const temporaryStyles = [];
505
+ const classes = element.attr("class");
506
+ const styles = packageStyles(options);
507
+ let animationClosed;
508
+ let animationPaused;
509
+ let animationCompleted;
510
+ let runner;
511
+ let runnerHost;
512
+ let maxDelay;
513
+ let maxDelayTime;
514
+ let maxDuration;
515
+ let maxDurationTime;
516
+ let startTime;
517
+ const events = [];
518
+
519
+ if (options.duration === 0) {
520
+ return closeAndReturnNoopAnimator();
521
+ }
522
+
523
+ const method =
524
+ options.event && isArray(options.event)
525
+ ? options.event.join(" ")
526
+ : options.event;
527
+
528
+ const isStructural = method && options.structural;
529
+ let structuralClassName = "";
530
+ let addRemoveClassName = "";
531
+
532
+ if (isStructural) {
533
+ structuralClassName = pendClasses(method, EVENT_CLASS_PREFIX, true);
534
+ } else if (method) {
535
+ structuralClassName = method;
536
+ }
537
+
538
+ if (options.addClass) {
539
+ addRemoveClassName += pendClasses(
540
+ options.addClass,
541
+ ADD_CLASS_SUFFIX,
542
+ );
543
+ }
544
+
545
+ if (options.removeClass) {
546
+ if (addRemoveClassName.length) {
547
+ addRemoveClassName += " ";
548
+ }
549
+ addRemoveClassName += pendClasses(
550
+ options.removeClass,
551
+ REMOVE_CLASS_SUFFIX,
552
+ );
553
+ }
554
+
555
+ // there may be a situation where a structural animation is combined together
556
+ // with CSS classes that need to resolve before the animation is computed.
557
+ // However this means that there is no explicit CSS code to block the animation
558
+ // from happening (by setting 0s none in the class name). If this is the case
559
+ // we need to apply the classes before the first rAF so we know to continue if
560
+ // there actually is a detected transition or keyframe animation
561
+ if (options.applyClassesEarly && addRemoveClassName.length) {
562
+ applyAnimationClasses(element, options);
563
+ }
564
+
565
+ let preparationClasses = [structuralClassName, addRemoveClassName]
566
+ .join(" ")
567
+ .trim();
568
+ let fullClassName = `${classes} ${preparationClasses}`;
569
+ const hasToStyles = styles.to && Object.keys(styles.to).length > 0;
570
+ const containsKeyframeAnimation =
571
+ (options.keyframeStyle || "").length > 0;
572
+
573
+ // there is no way we can trigger an animation if no styles and
574
+ // no classes are being applied which would then trigger a transition,
575
+ // unless there a is raw keyframe value that is applied to the element.
576
+ if (
577
+ !containsKeyframeAnimation &&
578
+ !hasToStyles &&
579
+ !preparationClasses
580
+ ) {
581
+ return closeAndReturnNoopAnimator();
582
+ }
583
+
584
+ let stagger;
585
+ let cacheKey = $$animateCache.cacheKey(
586
+ node,
587
+ method,
588
+ options.addClass,
589
+ options.removeClass,
590
+ );
591
+ if ($$animateCache.containsCachedAnimationWithoutDuration(cacheKey)) {
592
+ preparationClasses = null;
593
+ return closeAndReturnNoopAnimator();
594
+ }
595
+
596
+ if (options.stagger > 0) {
597
+ const staggerVal = parseFloat(options.stagger);
598
+ stagger = {
599
+ transitionDelay: staggerVal,
600
+ animationDelay: staggerVal,
601
+ transitionDuration: 0,
602
+ animationDuration: 0,
603
+ };
604
+ } else {
605
+ stagger = computeCachedCssStaggerStyles(
606
+ node,
607
+ preparationClasses,
608
+ cacheKey,
609
+ DETECT_STAGGER_CSS_PROPERTIES,
610
+ );
611
+ }
612
+
613
+ if (!options.$$skipPreparationClasses) {
614
+ element[0].classList.add(preparationClasses);
615
+ }
616
+
617
+ let applyOnlyDuration;
618
+
619
+ if (options.transitionStyle) {
620
+ const transitionStyle = [TRANSITION_PROP, options.transitionStyle];
621
+ applyInlineStyle(node, transitionStyle);
622
+ temporaryStyles.push(transitionStyle);
623
+ }
624
+
625
+ if (options.duration >= 0) {
626
+ applyOnlyDuration = node.style[TRANSITION_PROP].length > 0;
627
+ const durationStyle = getCssTransitionDurationStyle(
628
+ options.duration,
629
+ applyOnlyDuration,
630
+ );
631
+
632
+ // we set the duration so that it will be picked up by getComputedStyle later
633
+ applyInlineStyle(node, durationStyle);
634
+ temporaryStyles.push(durationStyle);
635
+ }
636
+
637
+ if (options.keyframeStyle) {
638
+ const keyframeStyle = [ANIMATION_PROP, options.keyframeStyle];
639
+ applyInlineStyle(node, keyframeStyle);
640
+ temporaryStyles.push(keyframeStyle);
641
+ }
642
+
643
+ const itemIndex = stagger
644
+ ? options.staggerIndex >= 0
645
+ ? options.staggerIndex
646
+ : $$animateCache.count(cacheKey)
647
+ : 0;
648
+
649
+ const isFirst = itemIndex === 0;
650
+
651
+ // this is a pre-emptive way of forcing the setup classes to be added and applied INSTANTLY
652
+ // without causing any combination of transitions to kick in. By adding a negative delay value
653
+ // it forces the setup class' transition to end immediately. We later then remove the negative
654
+ // transition delay to allow for the transition to naturally do it's thing. The beauty here is
655
+ // that if there is no transition defined then nothing will happen and this will also allow
656
+ // other transitions to be stacked on top of each other without any chopping them out.
657
+ if (isFirst && !options.skipBlocking) {
658
+ helpers.blockTransitions(node, SAFE_FAST_FORWARD_DURATION_VALUE);
659
+ }
660
+
661
+ let timings = computeTimings(
662
+ node,
663
+ fullClassName,
664
+ cacheKey,
665
+ !isStructural,
666
+ );
667
+ let relativeDelay = timings.maxDelay;
668
+ maxDelay = Math.max(relativeDelay, 0);
669
+ maxDuration = timings.maxDuration;
670
+
671
+ const flags = {};
672
+ flags.hasTransitions = timings.transitionDuration > 0;
673
+ flags.hasAnimations = timings.animationDuration > 0;
674
+ flags.hasTransitionAll =
675
+ flags.hasTransitions && timings.transitionProperty === "all";
676
+ flags.applyTransitionDuration =
677
+ hasToStyles &&
678
+ ((flags.hasTransitions && !flags.hasTransitionAll) ||
679
+ (flags.hasAnimations && !flags.hasTransitions));
680
+ flags.applyAnimationDuration =
681
+ options.duration && flags.hasAnimations;
682
+ flags.applyTransitionDelay =
683
+ truthyTimingValue(options.delay) &&
684
+ (flags.applyTransitionDuration || flags.hasTransitions);
685
+ flags.applyAnimationDelay =
686
+ truthyTimingValue(options.delay) && flags.hasAnimations;
687
+ flags.recalculateTimingStyles = addRemoveClassName.length > 0;
688
+
689
+ if (flags.applyTransitionDuration || flags.applyAnimationDuration) {
690
+ maxDuration = options.duration
691
+ ? parseFloat(options.duration)
692
+ : maxDuration;
693
+
694
+ if (flags.applyTransitionDuration) {
695
+ flags.hasTransitions = true;
696
+ timings.transitionDuration = maxDuration;
697
+ applyOnlyDuration =
698
+ node.style[TRANSITION_PROP + PROPERTY_KEY].length > 0;
699
+ temporaryStyles.push(
700
+ getCssTransitionDurationStyle(maxDuration, applyOnlyDuration),
701
+ );
702
+ }
703
+
704
+ if (flags.applyAnimationDuration) {
705
+ flags.hasAnimations = true;
706
+ timings.animationDuration = maxDuration;
707
+ temporaryStyles.push(getCssKeyframeDurationStyle(maxDuration));
708
+ }
709
+ }
710
+
711
+ if (maxDuration === 0 && !flags.recalculateTimingStyles) {
712
+ return closeAndReturnNoopAnimator();
713
+ }
714
+
715
+ const activeClasses = pendClasses(
716
+ preparationClasses,
717
+ ACTIVE_CLASS_SUFFIX,
718
+ );
719
+
720
+ if (options.delay != null) {
721
+ var delayStyle;
722
+ if (typeof options.delay !== "boolean") {
723
+ delayStyle = parseFloat(options.delay);
724
+ // number in options.delay means we have to recalculate the delay for the closing timeout
725
+ maxDelay = Math.max(delayStyle, 0);
726
+ }
727
+
728
+ if (flags.applyTransitionDelay) {
729
+ temporaryStyles.push(getCssDelayStyle(delayStyle));
730
+ }
731
+
732
+ if (flags.applyAnimationDelay) {
733
+ temporaryStyles.push(getCssDelayStyle(delayStyle, true));
734
+ }
735
+ }
736
+
737
+ // we need to recalculate the delay value since we used a pre-emptive negative
738
+ // delay value and the delay value is required for the final event checking. This
739
+ // property will ensure that this will happen after the RAF phase has passed.
740
+ if (options.duration == null && timings.transitionDuration > 0) {
741
+ flags.recalculateTimingStyles =
742
+ flags.recalculateTimingStyles || isFirst;
743
+ }
744
+
745
+ maxDelayTime = maxDelay * ONE_SECOND;
746
+ maxDurationTime = maxDuration * ONE_SECOND;
747
+ if (!options.skipBlocking) {
748
+ flags.blockTransition = timings.transitionDuration > 0;
749
+ flags.blockKeyframeAnimation =
750
+ timings.animationDuration > 0 &&
751
+ stagger.animationDelay > 0 &&
752
+ stagger.animationDuration === 0;
753
+ }
754
+
755
+ if (options.from) {
756
+ if (options.cleanupStyles) {
757
+ registerRestorableStyles(
758
+ restoreStyles,
759
+ node,
760
+ Object.keys(options.from),
761
+ );
762
+ }
763
+ applyAnimationFromStyles(element, options);
764
+ }
765
+
766
+ if (flags.blockTransition || flags.blockKeyframeAnimation) {
767
+ applyBlocking(maxDuration);
768
+ } else if (!options.skipBlocking) {
769
+ helpers.blockTransitions(node, false);
770
+ }
771
+
772
+ // TODO(matsko): for 1.5 change this code to have an animator object for better debugging
773
+ return {
774
+ $$willAnimate: true,
775
+ end: endFn,
776
+ start() {
777
+ if (animationClosed) return;
778
+
779
+ runnerHost = {
780
+ end: endFn,
781
+ cancel: cancelFn,
782
+ resume: null, // this will be set during the start() phase
783
+ pause: null,
784
+ };
785
+
786
+ runner = new $$AnimateRunner(runnerHost);
787
+
788
+ waitUntilQuiet(start);
789
+
790
+ // we don't have access to pause/resume the animation
791
+ // since it hasn't run yet. AnimateRunner will therefore
792
+ // set noop functions for resume and pause and they will
793
+ // later be overridden once the animation is triggered
794
+ return runner;
795
+ },
796
+ };
797
+
798
+ function endFn() {
799
+ close();
800
+ }
801
+
802
+ function cancelFn() {
803
+ close(true);
804
+ }
805
+
806
+ function close(rejected) {
807
+ // if the promise has been called already then we shouldn't close
808
+ // the animation again
809
+ if (animationClosed || (animationCompleted && animationPaused))
810
+ return;
811
+ animationClosed = true;
812
+ animationPaused = false;
813
+
814
+ if (preparationClasses && !options.$$skipPreparationClasses) {
815
+ preparationClasses
816
+ .split(" ")
817
+ .forEach((cls) => element.classList.remove(cls));
818
+ }
819
+
820
+ if (activeClasses) {
821
+ activeClasses
822
+ .split(" ")
823
+ .forEach((cls) => element.classList.remove(cls));
824
+ }
825
+
826
+ blockKeyframeAnimations(node, false);
827
+ helpers.blockTransitions(node, false);
828
+
829
+ forEach(temporaryStyles, (entry) => {
830
+ // There is only one way to remove inline style properties entirely from elements.
831
+ // By using `removeProperty` this works, but we need to convert camel-cased CSS
832
+ // styles down to hyphenated values.
833
+ node.style[entry[0]] = "";
834
+ });
835
+
836
+ applyAnimationClasses(element, options);
837
+ applyAnimationStyles(element, options);
838
+
839
+ if (Object.keys(restoreStyles).length) {
840
+ forEach(restoreStyles, (value, prop) => {
841
+ if (value) {
842
+ node.style.setProperty(prop, value);
843
+ } else {
844
+ node.style.removeProperty(prop);
845
+ }
846
+ });
847
+ }
848
+
849
+ // the reason why we have this option is to allow a synchronous closing callback
850
+ // that is fired as SOON as the animation ends (when the CSS is removed) or if
851
+ // the animation never takes off at all. A good example is a leave animation since
852
+ // the element must be removed just after the animation is over or else the element
853
+ // will appear on screen for one animation frame causing an overbearing flicker.
854
+ if (options.onDone) {
855
+ options.onDone();
856
+ }
857
+
858
+ if (events && events.length) {
859
+ // Remove the transitionend / animationend listener(s)
860
+ element.off(events.join(" "), onAnimationProgress);
861
+ }
862
+
863
+ // Cancel the fallback closing timeout and remove the timer data
864
+ const animationTimerData = element.data(ANIMATE_TIMER_KEY);
865
+ if (animationTimerData) {
866
+ $timeout.cancel(animationTimerData[0].timer);
867
+ element.removeData(ANIMATE_TIMER_KEY);
868
+ }
869
+
870
+ // if the preparation function fails then the promise is not setup
871
+ if (runner) {
872
+ runner.complete(!rejected);
873
+ }
874
+ }
875
+
876
+ function applyBlocking(duration) {
877
+ if (flags.blockTransition) {
878
+ helpers.blockTransitions(node, duration);
879
+ }
880
+
881
+ if (flags.blockKeyframeAnimation) {
882
+ blockKeyframeAnimations(node, !!duration);
883
+ }
884
+ }
885
+
886
+ function closeAndReturnNoopAnimator() {
887
+ runner = new $$AnimateRunner({
888
+ end: endFn,
889
+ cancel: cancelFn,
890
+ });
891
+
892
+ // should flush the cache animation
893
+ waitUntilQuiet(() => {});
894
+ close();
895
+
896
+ return {
897
+ $$willAnimate: false,
898
+ start() {
899
+ return runner;
900
+ },
901
+ end: endFn,
902
+ };
903
+ }
904
+
905
+ function onAnimationProgress(event) {
906
+ event.stopPropagation();
907
+ const ev = event.originalEvent || event;
908
+
909
+ if (ev.target !== node) {
910
+ // Since TransitionEvent / AnimationEvent bubble up,
911
+ // we have to ignore events by finished child animations
912
+ return;
913
+ }
914
+
915
+ // we now always use `Date.now()` due to the recent changes with
916
+ // event.timeStamp in Firefox, Webkit and Chrome (see #13494 for more info)
917
+ const timeStamp = ev.$manualTimeStamp || Date.now();
918
+
919
+ /* Firefox (or possibly just Gecko) likes to not round values up
920
+ * when a ms measurement is used for the animation */
921
+ const elapsedTime = parseFloat(
922
+ ev.elapsedTime.toFixed(ELAPSED_TIME_MAX_DECIMAL_PLACES),
923
+ );
924
+
925
+ /* $manualTimeStamp is a mocked timeStamp value which is set
926
+ * within browserTrigger(). This is only here so that tests can
927
+ * mock animations properly. Real events fallback to event.timeStamp,
928
+ * or, if they don't, then a timeStamp is automatically created for them.
929
+ * We're checking to see if the timeStamp surpasses the expected delay,
930
+ * but we're using elapsedTime instead of the timeStamp on the 2nd
931
+ * pre-condition since animationPauseds sometimes close off early */
932
+ if (
933
+ Math.max(timeStamp - startTime, 0) >= maxDelayTime &&
934
+ elapsedTime >= maxDuration
935
+ ) {
936
+ // we set this flag to ensure that if the transition is paused then, when resumed,
937
+ // the animation will automatically close itself since transitions cannot be paused.
938
+ animationCompleted = true;
939
+ close();
940
+ }
941
+ }
942
+
943
+ function start() {
944
+ if (animationClosed) return;
945
+ if (!node.parentNode) {
946
+ close();
947
+ return;
948
+ }
949
+
950
+ // even though we only pause keyframe animations here the pause flag
951
+ // will still happen when transitions are used. Only the transition will
952
+ // not be paused since that is not possible. If the animation ends when
953
+ // paused then it will not complete until unpaused or cancelled.
954
+ const playPause = function (playAnimation) {
955
+ if (!animationCompleted) {
956
+ animationPaused = !playAnimation;
957
+ if (timings.animationDuration) {
958
+ const value = blockKeyframeAnimations(node, animationPaused);
959
+ if (animationPaused) {
960
+ temporaryStyles.push(value);
961
+ } else {
962
+ removeFromArray(temporaryStyles, value);
963
+ }
964
+ }
965
+ } else if (animationPaused && playAnimation) {
966
+ animationPaused = false;
967
+ close();
968
+ }
969
+ };
970
+
971
+ // checking the stagger duration prevents an accidentally cascade of the CSS delay style
972
+ // being inherited from the parent. If the transition duration is zero then we can safely
973
+ // rely that the delay value is an intentional stagger delay style.
974
+ const maxStagger =
975
+ itemIndex > 0 &&
976
+ ((timings.transitionDuration &&
977
+ stagger.transitionDuration === 0) ||
978
+ (timings.animationDuration &&
979
+ stagger.animationDuration === 0)) &&
980
+ Math.max(stagger.animationDelay, stagger.transitionDelay);
981
+ if (maxStagger) {
982
+ $timeout(
983
+ triggerAnimationStart,
984
+ Math.floor(maxStagger * itemIndex * ONE_SECOND),
985
+ false,
986
+ );
987
+ } else {
988
+ triggerAnimationStart();
989
+ }
990
+
991
+ // this will decorate the existing promise runner with pause/resume methods
992
+ runnerHost.resume = function () {
993
+ playPause(true);
994
+ };
995
+
996
+ runnerHost.pause = function () {
997
+ playPause(false);
998
+ };
999
+
1000
+ function triggerAnimationStart() {
1001
+ // just incase a stagger animation kicks in when the animation
1002
+ // itself was cancelled entirely
1003
+ if (animationClosed) return;
1004
+
1005
+ applyBlocking(false);
1006
+
1007
+ forEach(temporaryStyles, (entry) => {
1008
+ const key = entry[0];
1009
+ const value = entry[1];
1010
+ node.style[key] = value;
1011
+ });
1012
+
1013
+ applyAnimationClasses(element, options);
1014
+ element.className += ` ${activeClasses}`;
1015
+ if (flags.recalculateTimingStyles) {
1016
+ fullClassName = `${node.getAttribute("class")} ${preparationClasses}`;
1017
+ cacheKey = $$animateCache.cacheKey(
1018
+ node,
1019
+ method,
1020
+ options.addClass,
1021
+ options.removeClass,
1022
+ );
1023
+
1024
+ timings = computeTimings(node, fullClassName, cacheKey, false);
1025
+ relativeDelay = timings.maxDelay;
1026
+ maxDelay = Math.max(relativeDelay, 0);
1027
+ maxDuration = timings.maxDuration;
1028
+
1029
+ if (maxDuration === 0) {
1030
+ close();
1031
+ return;
1032
+ }
1033
+
1034
+ flags.hasTransitions = timings.transitionDuration > 0;
1035
+ flags.hasAnimations = timings.animationDuration > 0;
1036
+ }
1037
+
1038
+ if (flags.applyAnimationDelay) {
1039
+ relativeDelay =
1040
+ typeof options.delay !== "boolean" &&
1041
+ truthyTimingValue(options.delay)
1042
+ ? parseFloat(options.delay)
1043
+ : relativeDelay;
1044
+
1045
+ maxDelay = Math.max(relativeDelay, 0);
1046
+ timings.animationDelay = relativeDelay;
1047
+ delayStyle = getCssDelayStyle(relativeDelay, true);
1048
+ temporaryStyles.push(delayStyle);
1049
+ node.style[delayStyle[0]] = delayStyle[1];
1050
+ }
1051
+
1052
+ maxDelayTime = maxDelay * ONE_SECOND;
1053
+ maxDurationTime = maxDuration * ONE_SECOND;
1054
+
1055
+ if (options.easing) {
1056
+ let easeProp;
1057
+ const easeVal = options.easing;
1058
+ if (flags.hasTransitions) {
1059
+ easeProp = TRANSITION_PROP + TIMING_KEY;
1060
+ temporaryStyles.push([easeProp, easeVal]);
1061
+ node.style[easeProp] = easeVal;
1062
+ }
1063
+ if (flags.hasAnimations) {
1064
+ easeProp = ANIMATION_PROP + TIMING_KEY;
1065
+ temporaryStyles.push([easeProp, easeVal]);
1066
+ node.style[easeProp] = easeVal;
1067
+ }
1068
+ }
1069
+
1070
+ if (timings.transitionDuration) {
1071
+ events.push(TRANSITIONEND_EVENT);
1072
+ }
1073
+
1074
+ if (timings.animationDuration) {
1075
+ events.push(ANIMATIONEND_EVENT);
1076
+ }
1077
+
1078
+ startTime = Date.now();
1079
+ const timerTime =
1080
+ maxDelayTime + CLOSING_TIME_BUFFER * maxDurationTime;
1081
+ const endTime = startTime + timerTime;
1082
+
1083
+ const animationsData = element.data(ANIMATE_TIMER_KEY) || [];
1084
+ let setupFallbackTimer = true;
1085
+ if (animationsData.length) {
1086
+ const currentTimerData = animationsData[0];
1087
+ setupFallbackTimer = endTime > currentTimerData.expectedEndTime;
1088
+ if (setupFallbackTimer) {
1089
+ $timeout.cancel(currentTimerData.timer);
1090
+ } else {
1091
+ animationsData.push(close);
1092
+ }
1093
+ }
1094
+
1095
+ if (setupFallbackTimer) {
1096
+ const timer = $timeout(onAnimationExpired, timerTime, false);
1097
+ animationsData[0] = {
1098
+ timer,
1099
+ expectedEndTime: endTime,
1100
+ };
1101
+ animationsData.push(close);
1102
+ element.data(ANIMATE_TIMER_KEY, animationsData);
1103
+ }
1104
+
1105
+ if (events.length) {
1106
+ element.on(events.join(" "), onAnimationProgress);
1107
+ }
1108
+
1109
+ if (options.to) {
1110
+ if (options.cleanupStyles) {
1111
+ registerRestorableStyles(
1112
+ restoreStyles,
1113
+ node,
1114
+ Object.keys(options.to),
1115
+ );
1116
+ }
1117
+ applyAnimationToStyles(element, options);
1118
+ }
1119
+ }
1120
+
1121
+ function onAnimationExpired() {
1122
+ const animationsData = element.data(ANIMATE_TIMER_KEY);
1123
+
1124
+ // this will be false in the event that the element was
1125
+ // removed from the DOM (via a leave animation or something
1126
+ // similar)
1127
+ if (animationsData) {
1128
+ for (let i = 1; i < animationsData.length; i++) {
1129
+ animationsData[i]();
1130
+ }
1131
+ element.removeData(ANIMATE_TIMER_KEY);
1132
+ }
1133
+ }
1134
+ }
1135
+ };
1136
+ },
1137
+ ];
1138
+ },
1139
+ ];