animations.js 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191
  1. /**
  2. * @license Angular v8.1.0
  3. * (c) 2010-2019 Google LLC. https://angular.io/
  4. * License: MIT
  5. */
  6. /**
  7. * An injectable service that produces an animation sequence programmatically within an
  8. * Angular component or directive.
  9. * Provided by the `BrowserAnimationsModule` or `NoopAnimationsModule`.
  10. *
  11. * @usageNotes
  12. *
  13. * To use this service, add it to your component or directive as a dependency.
  14. * The service is instantiated along with your component.
  15. *
  16. * Apps do not typically need to create their own animation players, but if you
  17. * do need to, follow these steps:
  18. *
  19. * 1. Use the `build()` method to create a programmatic animation using the
  20. * `animate()` function. The method returns an `AnimationFactory` instance.
  21. *
  22. * 2. Use the factory object to create an `AnimationPlayer` and attach it to a DOM element.
  23. *
  24. * 3. Use the player object to control the animation programmatically.
  25. *
  26. * For example:
  27. *
  28. * ```ts
  29. * // import the service from BrowserAnimationsModule
  30. * import {AnimationBuilder} from '@angular/animations';
  31. * // require the service as a dependency
  32. * class MyCmp {
  33. * constructor(private _builder: AnimationBuilder) {}
  34. *
  35. * makeAnimation(element: any) {
  36. * // first define a reusable animation
  37. * const myAnimation = this._builder.build([
  38. * style({ width: 0 }),
  39. * animate(1000, style({ width: '100px' }))
  40. * ]);
  41. *
  42. * // use the returned factory object to create a player
  43. * const player = myAnimation.create(element);
  44. *
  45. * player.play();
  46. * }
  47. * }
  48. * ```
  49. *
  50. * @publicApi
  51. */
  52. var AnimationBuilder = /** @class */ (function () {
  53. function AnimationBuilder() {
  54. }
  55. return AnimationBuilder;
  56. }());
  57. /**
  58. * A factory object returned from the `AnimationBuilder`.`build()` method.
  59. *
  60. * @publicApi
  61. */
  62. var AnimationFactory = /** @class */ (function () {
  63. function AnimationFactory() {
  64. }
  65. return AnimationFactory;
  66. }());
  67. /**
  68. * @license
  69. * Copyright Google Inc. All Rights Reserved.
  70. *
  71. * Use of this source code is governed by an MIT-style license that can be
  72. * found in the LICENSE file at https://angular.io/license
  73. */
  74. /**
  75. * Specifies automatic styling.
  76. *
  77. * @publicApi
  78. */
  79. var AUTO_STYLE = '*';
  80. /**
  81. * Creates a named animation trigger, containing a list of `state()`
  82. * and `transition()` entries to be evaluated when the expression
  83. * bound to the trigger changes.
  84. *
  85. * @param name An identifying string.
  86. * @param definitions An animation definition object, containing an array of `state()`
  87. * and `transition()` declarations.
  88. *
  89. * @return An object that encapsulates the trigger data.
  90. *
  91. * @usageNotes
  92. * Define an animation trigger in the `animations` section of `@Component` metadata.
  93. * In the template, reference the trigger by name and bind it to a trigger expression that
  94. * evaluates to a defined animation state, using the following format:
  95. *
  96. * `[@triggerName]="expression"`
  97. *
  98. * Animation trigger bindings convert all values to strings, and then match the
  99. * previous and current values against any linked transitions.
  100. * Booleans can be specified as `1` or `true` and `0` or `false`.
  101. *
  102. * ### Usage Example
  103. *
  104. * The following example creates an animation trigger reference based on the provided
  105. * name value.
  106. * The provided animation value is expected to be an array consisting of state and
  107. * transition declarations.
  108. *
  109. * ```typescript
  110. * @Component({
  111. * selector: "my-component",
  112. * templateUrl: "my-component-tpl.html",
  113. * animations: [
  114. * trigger("myAnimationTrigger", [
  115. * state(...),
  116. * state(...),
  117. * transition(...),
  118. * transition(...)
  119. * ])
  120. * ]
  121. * })
  122. * class MyComponent {
  123. * myStatusExp = "something";
  124. * }
  125. * ```
  126. *
  127. * The template associated with this component makes use of the defined trigger
  128. * by binding to an element within its template code.
  129. *
  130. * ```html
  131. * <!-- somewhere inside of my-component-tpl.html -->
  132. * <div [@myAnimationTrigger]="myStatusExp">...</div>
  133. * ```
  134. *
  135. * ### Using an inline function
  136. * The `transition` animation method also supports reading an inline function which can decide
  137. * if its associated animation should be run.
  138. *
  139. * ```typescript
  140. * // this method is run each time the `myAnimationTrigger` trigger value changes.
  141. * function myInlineMatcherFn(fromState: string, toState: string, element: any, params: {[key:
  142. string]: any}): boolean {
  143. * // notice that `element` and `params` are also available here
  144. * return toState == 'yes-please-animate';
  145. * }
  146. *
  147. * @Component({
  148. * selector: 'my-component',
  149. * templateUrl: 'my-component-tpl.html',
  150. * animations: [
  151. * trigger('myAnimationTrigger', [
  152. * transition(myInlineMatcherFn, [
  153. * // the animation sequence code
  154. * ]),
  155. * ])
  156. * ]
  157. * })
  158. * class MyComponent {
  159. * myStatusExp = "yes-please-animate";
  160. * }
  161. * ```
  162. *
  163. * ### Disabling Animations
  164. * When true, the special animation control binding `@.disabled` binding prevents
  165. * all animations from rendering.
  166. * Place the `@.disabled` binding on an element to disable
  167. * animations on the element itself, as well as any inner animation triggers
  168. * within the element.
  169. *
  170. * The following example shows how to use this feature:
  171. *
  172. * ```typescript
  173. * @Component({
  174. * selector: 'my-component',
  175. * template: `
  176. * <div [@.disabled]="isDisabled">
  177. * <div [@childAnimation]="exp"></div>
  178. * </div>
  179. * `,
  180. * animations: [
  181. * trigger("childAnimation", [
  182. * // ...
  183. * ])
  184. * ]
  185. * })
  186. * class MyComponent {
  187. * isDisabled = true;
  188. * exp = '...';
  189. * }
  190. * ```
  191. *
  192. * When `@.disabled` is true, it prevents the `@childAnimation` trigger from animating,
  193. * along with any inner animations.
  194. *
  195. * ### Disable animations application-wide
  196. * When an area of the template is set to have animations disabled,
  197. * **all** inner components have their animations disabled as well.
  198. * This means that you can disable all animations for an app
  199. * by placing a host binding set on `@.disabled` on the topmost Angular component.
  200. *
  201. * ```typescript
  202. * import {Component, HostBinding} from '@angular/core';
  203. *
  204. * @Component({
  205. * selector: 'app-component',
  206. * templateUrl: 'app.component.html',
  207. * })
  208. * class AppComponent {
  209. * @HostBinding('@.disabled')
  210. * public animationsDisabled = true;
  211. * }
  212. * ```
  213. *
  214. * ### Overriding disablement of inner animations
  215. * Despite inner animations being disabled, a parent animation can `query()`
  216. * for inner elements located in disabled areas of the template and still animate
  217. * them if needed. This is also the case for when a sub animation is
  218. * queried by a parent and then later animated using `animateChild()`.
  219. *
  220. * ### Detecting when an animation is disabled
  221. * If a region of the DOM (or the entire application) has its animations disabled, the animation
  222. * trigger callbacks still fire, but for zero seconds. When the callback fires, it provides
  223. * an instance of an `AnimationEvent`. If animations are disabled,
  224. * the `.disabled` flag on the event is true.
  225. *
  226. * @publicApi
  227. */
  228. function trigger(name, definitions) {
  229. return { type: 7 /* Trigger */, name: name, definitions: definitions, options: {} };
  230. }
  231. /**
  232. * Defines an animation step that combines styling information with timing information.
  233. *
  234. * @param timings Sets `AnimateTimings` for the parent animation.
  235. * A string in the format "duration [delay] [easing]".
  236. * - Duration and delay are expressed as a number and optional time unit,
  237. * such as "1s" or "10ms" for one second and 10 milliseconds, respectively.
  238. * The default unit is milliseconds.
  239. * - The easing value controls how the animation accelerates and decelerates
  240. * during its runtime. Value is one of `ease`, `ease-in`, `ease-out`,
  241. * `ease-in-out`, or a `cubic-bezier()` function call.
  242. * If not supplied, no easing is applied.
  243. *
  244. * For example, the string "1s 100ms ease-out" specifies a duration of
  245. * 1000 milliseconds, and delay of 100 ms, and the "ease-out" easing style,
  246. * which decelerates near the end of the duration.
  247. * @param styles Sets AnimationStyles for the parent animation.
  248. * A function call to either `style()` or `keyframes()`
  249. * that returns a collection of CSS style entries to be applied to the parent animation.
  250. * When null, uses the styles from the destination state.
  251. * This is useful when describing an animation step that will complete an animation;
  252. * see "Animating to the final state" in `transitions()`.
  253. * @returns An object that encapsulates the animation step.
  254. *
  255. * @usageNotes
  256. * Call within an animation `sequence()`, `{@link animations/group group()}`, or
  257. * `transition()` call to specify an animation step
  258. * that applies given style data to the parent animation for a given amount of time.
  259. *
  260. * ### Syntax Examples
  261. * **Timing examples**
  262. *
  263. * The following examples show various `timings` specifications.
  264. * - `animate(500)` : Duration is 500 milliseconds.
  265. * - `animate("1s")` : Duration is 1000 milliseconds.
  266. * - `animate("100ms 0.5s")` : Duration is 100 milliseconds, delay is 500 milliseconds.
  267. * - `animate("5s ease-in")` : Duration is 5000 milliseconds, easing in.
  268. * - `animate("5s 10ms cubic-bezier(.17,.67,.88,.1)")` : Duration is 5000 milliseconds, delay is 10
  269. * milliseconds, easing according to a bezier curve.
  270. *
  271. * **Style examples**
  272. *
  273. * The following example calls `style()` to set a single CSS style.
  274. * ```typescript
  275. * animate(500, style({ background: "red" }))
  276. * ```
  277. * The following example calls `keyframes()` to set a CSS style
  278. * to different values for successive keyframes.
  279. * ```typescript
  280. * animate(500, keyframes(
  281. * [
  282. * style({ background: "blue" })),
  283. * style({ background: "red" }))
  284. * ])
  285. * ```
  286. *
  287. * @publicApi
  288. */
  289. function animate(timings, styles) {
  290. if (styles === void 0) { styles = null; }
  291. return { type: 4 /* Animate */, styles: styles, timings: timings };
  292. }
  293. /**
  294. * @description Defines a list of animation steps to be run in parallel.
  295. *
  296. * @param steps An array of animation step objects.
  297. * - When steps are defined by `style()` or `animate()`
  298. * function calls, each call within the group is executed instantly.
  299. * - To specify offset styles to be applied at a later time, define steps with
  300. * `keyframes()`, or use `animate()` calls with a delay value.
  301. * For example:
  302. *
  303. * ```typescript
  304. * group([
  305. * animate("1s", style({ background: "black" })),
  306. * animate("2s", style({ color: "white" }))
  307. * ])
  308. * ```
  309. *
  310. * @param options An options object containing a delay and
  311. * developer-defined parameters that provide styling defaults and
  312. * can be overridden on invocation.
  313. *
  314. * @return An object that encapsulates the group data.
  315. *
  316. * @usageNotes
  317. * Grouped animations are useful when a series of styles must be
  318. * animated at different starting times and closed off at different ending times.
  319. *
  320. * When called within a `sequence()` or a
  321. * `transition()` call, does not continue to the next
  322. * instruction until all of the inner animation steps have completed.
  323. *
  324. * @publicApi
  325. */
  326. function group(steps, options) {
  327. if (options === void 0) { options = null; }
  328. return { type: 3 /* Group */, steps: steps, options: options };
  329. }
  330. /**
  331. * Defines a list of animation steps to be run sequentially, one by one.
  332. *
  333. * @param steps An array of animation step objects.
  334. * - Steps defined by `style()` calls apply the styling data immediately.
  335. * - Steps defined by `animate()` calls apply the styling data over time
  336. * as specified by the timing data.
  337. *
  338. * ```typescript
  339. * sequence([
  340. * style({ opacity: 0 })),
  341. * animate("1s", style({ opacity: 1 }))
  342. * ])
  343. * ```
  344. *
  345. * @param options An options object containing a delay and
  346. * developer-defined parameters that provide styling defaults and
  347. * can be overridden on invocation.
  348. *
  349. * @return An object that encapsulates the sequence data.
  350. *
  351. * @usageNotes
  352. * When you pass an array of steps to a
  353. * `transition()` call, the steps run sequentially by default.
  354. * Compare this to the `{@link animations/group group()}` call, which runs animation steps in parallel.
  355. *
  356. * When a sequence is used within a `{@link animations/group group()}` or a `transition()` call,
  357. * execution continues to the next instruction only after each of the inner animation
  358. * steps have completed.
  359. *
  360. * @publicApi
  361. **/
  362. function sequence(steps, options) {
  363. if (options === void 0) { options = null; }
  364. return { type: 2 /* Sequence */, steps: steps, options: options };
  365. }
  366. /**
  367. * Declares a key/value object containing CSS properties/styles that
  368. * can then be used for an animation `state`, within an animation `sequence`,
  369. * or as styling data for calls to `animate()` and `keyframes()`.
  370. *
  371. * @param tokens A set of CSS styles or HTML styles associated with an animation state.
  372. * The value can be any of the following:
  373. * - A key-value style pair associating a CSS property with a value.
  374. * - An array of key-value style pairs.
  375. * - An asterisk (*), to use auto-styling, where styles are derived from the element
  376. * being animated and applied to the animation when it starts.
  377. *
  378. * Auto-styling can be used to define a state that depends on layout or other
  379. * environmental factors.
  380. *
  381. * @return An object that encapsulates the style data.
  382. *
  383. * @usageNotes
  384. * The following examples create animation styles that collect a set of
  385. * CSS property values:
  386. *
  387. * ```typescript
  388. * // string values for CSS properties
  389. * style({ background: "red", color: "blue" })
  390. *
  391. * // numerical pixel values
  392. * style({ width: 100, height: 0 })
  393. * ```
  394. *
  395. * The following example uses auto-styling to allow a component to animate from
  396. * a height of 0 up to the height of the parent element:
  397. *
  398. * ```
  399. * style({ height: 0 }),
  400. * animate("1s", style({ height: "*" }))
  401. * ```
  402. *
  403. * @publicApi
  404. **/
  405. function style(tokens) {
  406. return { type: 6 /* Style */, styles: tokens, offset: null };
  407. }
  408. /**
  409. * Declares an animation state within a trigger attached to an element.
  410. *
  411. * @param name One or more names for the defined state in a comma-separated string.
  412. * The following reserved state names can be supplied to define a style for specific use
  413. * cases:
  414. *
  415. * - `void` You can associate styles with this name to be used when
  416. * the element is detached from the application. For example, when an `ngIf` evaluates
  417. * to false, the state of the associated element is void.
  418. * - `*` (asterisk) Indicates the default state. You can associate styles with this name
  419. * to be used as the fallback when the state that is being animated is not declared
  420. * within the trigger.
  421. *
  422. * @param styles A set of CSS styles associated with this state, created using the
  423. * `style()` function.
  424. * This set of styles persists on the element once the state has been reached.
  425. * @param options Parameters that can be passed to the state when it is invoked.
  426. * 0 or more key-value pairs.
  427. * @return An object that encapsulates the new state data.
  428. *
  429. * @usageNotes
  430. * Use the `trigger()` function to register states to an animation trigger.
  431. * Use the `transition()` function to animate between states.
  432. * When a state is active within a component, its associated styles persist on the element,
  433. * even when the animation ends.
  434. *
  435. * @publicApi
  436. **/
  437. function state(name, styles, options) {
  438. return { type: 0 /* State */, name: name, styles: styles, options: options };
  439. }
  440. /**
  441. * Defines a set of animation styles, associating each style with an optional `offset` value.
  442. *
  443. * @param steps A set of animation styles with optional offset data.
  444. * The optional `offset` value for a style specifies a percentage of the total animation
  445. * time at which that style is applied.
  446. * @returns An object that encapsulates the keyframes data.
  447. *
  448. * @usageNotes
  449. * Use with the `animate()` call. Instead of applying animations
  450. * from the current state
  451. * to the destination state, keyframes describe how each style entry is applied and at what point
  452. * within the animation arc.
  453. * Compare [CSS Keyframe Animations](https://www.w3schools.com/css/css3_animations.asp).
  454. *
  455. * ### Usage
  456. *
  457. * In the following example, the offset values describe
  458. * when each `backgroundColor` value is applied. The color is red at the start, and changes to
  459. * blue when 20% of the total time has elapsed.
  460. *
  461. * ```typescript
  462. * // the provided offset values
  463. * animate("5s", keyframes([
  464. * style({ backgroundColor: "red", offset: 0 }),
  465. * style({ backgroundColor: "blue", offset: 0.2 }),
  466. * style({ backgroundColor: "orange", offset: 0.3 }),
  467. * style({ backgroundColor: "black", offset: 1 })
  468. * ]))
  469. * ```
  470. *
  471. * If there are no `offset` values specified in the style entries, the offsets
  472. * are calculated automatically.
  473. *
  474. * ```typescript
  475. * animate("5s", keyframes([
  476. * style({ backgroundColor: "red" }) // offset = 0
  477. * style({ backgroundColor: "blue" }) // offset = 0.33
  478. * style({ backgroundColor: "orange" }) // offset = 0.66
  479. * style({ backgroundColor: "black" }) // offset = 1
  480. * ]))
  481. *```
  482. * @publicApi
  483. */
  484. function keyframes(steps) {
  485. return { type: 5 /* Keyframes */, steps: steps };
  486. }
  487. /**
  488. * Declares an animation transition as a sequence of animation steps to run when a given
  489. * condition is satisfied. The condition is a Boolean expression or function that compares
  490. * the previous and current animation states, and returns true if this transition should occur.
  491. * When the state criteria of a defined transition are met, the associated animation is
  492. * triggered.
  493. *
  494. * @param stateChangeExpr A Boolean expression or function that compares the previous and current
  495. * animation states, and returns true if this transition should occur. Note that "true" and "false"
  496. * match 1 and 0, respectively. An expression is evaluated each time a state change occurs in the
  497. * animation trigger element.
  498. * The animation steps run when the expression evaluates to true.
  499. *
  500. * - A state-change string takes the form "state1 => state2", where each side is a defined animation
  501. * state, or an asterix (*) to refer to a dynamic start or end state.
  502. * - The expression string can contain multiple comma-separated statements;
  503. * for example "state1 => state2, state3 => state4".
  504. * - Special values `:enter` and `:leave` initiate a transition on the entry and exit states,
  505. * equivalent to "void => *" and "* => void".
  506. * - Special values `:increment` and `:decrement` initiate a transition when a numeric value has
  507. * increased or decreased in value.
  508. * - A function is executed each time a state change occurs in the animation trigger element.
  509. * The animation steps run when the function returns true.
  510. *
  511. * @param steps One or more animation objects, as returned by the `animate()` or
  512. * `sequence()` function, that form a transformation from one state to another.
  513. * A sequence is used by default when you pass an array.
  514. * @param options An options object that can contain a delay value for the start of the animation,
  515. * and additional developer-defined parameters. Provided values for additional parameters are used
  516. * as defaults, and override values can be passed to the caller on invocation.
  517. * @returns An object that encapsulates the transition data.
  518. *
  519. * @usageNotes
  520. * The template associated with a component binds an animation trigger to an element.
  521. *
  522. * ```HTML
  523. * <!-- somewhere inside of my-component-tpl.html -->
  524. * <div [@myAnimationTrigger]="myStatusExp">...</div>
  525. * ```
  526. *
  527. * All transitions are defined within an animation trigger,
  528. * along with named states that the transitions change to and from.
  529. *
  530. * ```typescript
  531. * trigger("myAnimationTrigger", [
  532. * // define states
  533. * state("on", style({ background: "green" })),
  534. * state("off", style({ background: "grey" })),
  535. * ...]
  536. * ```
  537. *
  538. * Note that when you call the `sequence()` function within a `{@link animations/group group()}`
  539. * or a `transition()` call, execution does not continue to the next instruction
  540. * until each of the inner animation steps have completed.
  541. *
  542. * ### Syntax examples
  543. *
  544. * The following examples define transitions between the two defined states (and default states),
  545. * using various options:
  546. *
  547. * ```typescript
  548. * // Transition occurs when the state value
  549. * // bound to "myAnimationTrigger" changes from "on" to "off"
  550. * transition("on => off", animate(500))
  551. * // Run the same animation for both directions
  552. * transition("on <=> off", animate(500))
  553. * // Define multiple state-change pairs separated by commas
  554. * transition("on => off, off => void", animate(500))
  555. * ```
  556. *
  557. * ### Special values for state-change expressions
  558. *
  559. * - Catch-all state change for when an element is inserted into the page and the
  560. * destination state is unknown:
  561. *
  562. * ```typescript
  563. * transition("void => *", [
  564. * style({ opacity: 0 }),
  565. * animate(500)
  566. * ])
  567. * ```
  568. *
  569. * - Capture a state change between any states:
  570. *
  571. * `transition("* => *", animate("1s 0s"))`
  572. *
  573. * - Entry and exit transitions:
  574. *
  575. * ```typescript
  576. * transition(":enter", [
  577. * style({ opacity: 0 }),
  578. * animate(500, style({ opacity: 1 }))
  579. * ]),
  580. * transition(":leave", [
  581. * animate(500, style({ opacity: 0 }))
  582. * ])
  583. * ```
  584. *
  585. * - Use `:increment` and `:decrement` to initiate transitions:
  586. *
  587. * ```typescript
  588. * transition(":increment", group([
  589. * query(':enter', [
  590. * style({ left: '100%' }),
  591. * animate('0.5s ease-out', style('*'))
  592. * ]),
  593. * query(':leave', [
  594. * animate('0.5s ease-out', style({ left: '-100%' }))
  595. * ])
  596. * ]))
  597. *
  598. * transition(":decrement", group([
  599. * query(':enter', [
  600. * style({ left: '100%' }),
  601. * animate('0.5s ease-out', style('*'))
  602. * ]),
  603. * query(':leave', [
  604. * animate('0.5s ease-out', style({ left: '-100%' }))
  605. * ])
  606. * ]))
  607. * ```
  608. *
  609. * ### State-change functions
  610. *
  611. * Here is an example of a `fromState` specified as a state-change function that invokes an
  612. * animation when true:
  613. *
  614. * ```typescript
  615. * transition((fromState, toState) =>
  616. * {
  617. * return fromState == "off" && toState == "on";
  618. * },
  619. * animate("1s 0s"))
  620. * ```
  621. *
  622. * ### Animating to the final state
  623. *
  624. * If the final step in a transition is a call to `animate()` that uses a timing value
  625. * with no style data, that step is automatically considered the final animation arc,
  626. * for the element to reach the final state. Angular automatically adds or removes
  627. * CSS styles to ensure that the element is in the correct final state.
  628. *
  629. * The following example defines a transition that starts by hiding the element,
  630. * then makes sure that it animates properly to whatever state is currently active for trigger:
  631. *
  632. * ```typescript
  633. * transition("void => *", [
  634. * style({ opacity: 0 }),
  635. * animate(500)
  636. * ])
  637. * ```
  638. * ### Boolean value matching
  639. * If a trigger binding value is a Boolean, it can be matched using a transition expression
  640. * that compares true and false or 1 and 0. For example:
  641. *
  642. * ```
  643. * // in the template
  644. * <div [@openClose]="open ? true : false">...</div>
  645. * // in the component metadata
  646. * trigger('openClose', [
  647. * state('true', style({ height: '*' })),
  648. * state('false', style({ height: '0px' })),
  649. * transition('false <=> true', animate(500))
  650. * ])
  651. * ```
  652. *
  653. * @publicApi
  654. **/
  655. function transition(stateChangeExpr, steps, options) {
  656. if (options === void 0) { options = null; }
  657. return { type: 1 /* Transition */, expr: stateChangeExpr, animation: steps, options: options };
  658. }
  659. /**
  660. * Produces a reusable animation that can be invoked in another animation or sequence,
  661. * by calling the `useAnimation()` function.
  662. *
  663. * @param steps One or more animation objects, as returned by the `animate()`
  664. * or `sequence()` function, that form a transformation from one state to another.
  665. * A sequence is used by default when you pass an array.
  666. * @param options An options object that can contain a delay value for the start of the
  667. * animation, and additional developer-defined parameters.
  668. * Provided values for additional parameters are used as defaults,
  669. * and override values can be passed to the caller on invocation.
  670. * @returns An object that encapsulates the animation data.
  671. *
  672. * @usageNotes
  673. * The following example defines a reusable animation, providing some default parameter
  674. * values.
  675. *
  676. * ```typescript
  677. * var fadeAnimation = animation([
  678. * style({ opacity: '{{ start }}' }),
  679. * animate('{{ time }}',
  680. * style({ opacity: '{{ end }}'}))
  681. * ],
  682. * { params: { time: '1000ms', start: 0, end: 1 }});
  683. * ```
  684. *
  685. * The following invokes the defined animation with a call to `useAnimation()`,
  686. * passing in override parameter values.
  687. *
  688. * ```js
  689. * useAnimation(fadeAnimation, {
  690. * params: {
  691. * time: '2s',
  692. * start: 1,
  693. * end: 0
  694. * }
  695. * })
  696. * ```
  697. *
  698. * If any of the passed-in parameter values are missing from this call,
  699. * the default values are used. If one or more parameter values are missing before a step is
  700. * animated, `useAnimation()` throws an error.
  701. *
  702. * @publicApi
  703. */
  704. function animation(steps, options) {
  705. if (options === void 0) { options = null; }
  706. return { type: 8 /* Reference */, animation: steps, options: options };
  707. }
  708. /**
  709. * Executes a queried inner animation element within an animation sequence.
  710. *
  711. * @param options An options object that can contain a delay value for the start of the
  712. * animation, and additional override values for developer-defined parameters.
  713. * @return An object that encapsulates the child animation data.
  714. *
  715. * @usageNotes
  716. * Each time an animation is triggered in Angular, the parent animation
  717. * has priority and any child animations are blocked. In order
  718. * for a child animation to run, the parent animation must query each of the elements
  719. * containing child animations, and run them using this function.
  720. *
  721. * Note that this feature is designed to be used with `query()` and it will only work
  722. * with animations that are assigned using the Angular animation library. CSS keyframes
  723. * and transitions are not handled by this API.
  724. *
  725. * @publicApi
  726. */
  727. function animateChild(options) {
  728. if (options === void 0) { options = null; }
  729. return { type: 9 /* AnimateChild */, options: options };
  730. }
  731. /**
  732. * Starts a reusable animation that is created using the `animation()` function.
  733. *
  734. * @param animation The reusable animation to start.
  735. * @param options An options object that can contain a delay value for the start of
  736. * the animation, and additional override values for developer-defined parameters.
  737. * @return An object that contains the animation parameters.
  738. *
  739. * @publicApi
  740. */
  741. function useAnimation(animation, options) {
  742. if (options === void 0) { options = null; }
  743. return { type: 10 /* AnimateRef */, animation: animation, options: options };
  744. }
  745. /**
  746. * Finds one or more inner elements within the current element that is
  747. * being animated within a sequence. Use with `animate()`.
  748. *
  749. * @param selector The element to query, or a set of elements that contain Angular-specific
  750. * characteristics, specified with one or more of the following tokens.
  751. * - `query(":enter")` or `query(":leave")` : Query for newly inserted/removed elements.
  752. * - `query(":animating")` : Query all currently animating elements.
  753. * - `query("@triggerName")` : Query elements that contain an animation trigger.
  754. * - `query("@*")` : Query all elements that contain an animation triggers.
  755. * - `query(":self")` : Include the current element into the animation sequence.
  756. *
  757. * @param animation One or more animation steps to apply to the queried element or elements.
  758. * An array is treated as an animation sequence.
  759. * @param options An options object. Use the 'limit' field to limit the total number of
  760. * items to collect.
  761. * @return An object that encapsulates the query data.
  762. *
  763. * @usageNotes
  764. * Tokens can be merged into a combined query selector string. For example:
  765. *
  766. * ```typescript
  767. * query(':self, .record:enter, .record:leave, @subTrigger', [...])
  768. * ```
  769. *
  770. * The `query()` function collects multiple elements and works internally by using
  771. * `element.querySelectorAll`. Use the `limit` field of an options object to limit
  772. * the total number of items to be collected. For example:
  773. *
  774. * ```js
  775. * query('div', [
  776. * animate(...),
  777. * animate(...)
  778. * ], { limit: 1 })
  779. * ```
  780. *
  781. * By default, throws an error when zero items are found. Set the
  782. * `optional` flag to ignore this error. For example:
  783. *
  784. * ```js
  785. * query('.some-element-that-may-not-be-there', [
  786. * animate(...),
  787. * animate(...)
  788. * ], { optional: true })
  789. * ```
  790. *
  791. * ### Usage Example
  792. *
  793. * The following example queries for inner elements and animates them
  794. * individually using `animate()`.
  795. *
  796. * ```typescript
  797. * @Component({
  798. * selector: 'inner',
  799. * template: `
  800. * <div [@queryAnimation]="exp">
  801. * <h1>Title</h1>
  802. * <div class="content">
  803. * Blah blah blah
  804. * </div>
  805. * </div>
  806. * `,
  807. * animations: [
  808. * trigger('queryAnimation', [
  809. * transition('* => goAnimate', [
  810. * // hide the inner elements
  811. * query('h1', style({ opacity: 0 })),
  812. * query('.content', style({ opacity: 0 })),
  813. *
  814. * // animate the inner elements in, one by one
  815. * query('h1', animate(1000, style({ opacity: 1 }))),
  816. * query('.content', animate(1000, style({ opacity: 1 }))),
  817. * ])
  818. * ])
  819. * ]
  820. * })
  821. * class Cmp {
  822. * exp = '';
  823. *
  824. * goAnimate() {
  825. * this.exp = 'goAnimate';
  826. * }
  827. * }
  828. * ```
  829. *
  830. * @publicApi
  831. */
  832. function query(selector, animation, options) {
  833. if (options === void 0) { options = null; }
  834. return { type: 11 /* Query */, selector: selector, animation: animation, options: options };
  835. }
  836. /**
  837. * Use within an animation `query()` call to issue a timing gap after
  838. * each queried item is animated.
  839. *
  840. * @param timings A delay value.
  841. * @param animation One ore more animation steps.
  842. * @returns An object that encapsulates the stagger data.
  843. *
  844. * @usageNotes
  845. * In the following example, a container element wraps a list of items stamped out
  846. * by an `ngFor`. The container element contains an animation trigger that will later be set
  847. * to query for each of the inner items.
  848. *
  849. * Each time items are added, the opacity fade-in animation runs,
  850. * and each removed item is faded out.
  851. * When either of these animations occur, the stagger effect is
  852. * applied after each item's animation is started.
  853. *
  854. * ```html
  855. * <!-- list.component.html -->
  856. * <button (click)="toggle()">Show / Hide Items</button>
  857. * <hr />
  858. * <div [@listAnimation]="items.length">
  859. * <div *ngFor="let item of items">
  860. * {{ item }}
  861. * </div>
  862. * </div>
  863. * ```
  864. *
  865. * Here is the component code:
  866. *
  867. * ```typescript
  868. * import {trigger, transition, style, animate, query, stagger} from '@angular/animations';
  869. * @Component({
  870. * templateUrl: 'list.component.html',
  871. * animations: [
  872. * trigger('listAnimation', [
  873. * ...
  874. * ])
  875. * ]
  876. * })
  877. * class ListComponent {
  878. * items = [];
  879. *
  880. * showItems() {
  881. * this.items = [0,1,2,3,4];
  882. * }
  883. *
  884. * hideItems() {
  885. * this.items = [];
  886. * }
  887. *
  888. * toggle() {
  889. * this.items.length ? this.hideItems() : this.showItems();
  890. * }
  891. * }
  892. * ```
  893. *
  894. * Here is the animation trigger code:
  895. *
  896. * ```typescript
  897. * trigger('listAnimation', [
  898. * transition('* => *', [ // each time the binding value changes
  899. * query(':leave', [
  900. * stagger(100, [
  901. * animate('0.5s', style({ opacity: 0 }))
  902. * ])
  903. * ]),
  904. * query(':enter', [
  905. * style({ opacity: 0 }),
  906. * stagger(100, [
  907. * animate('0.5s', style({ opacity: 1 }))
  908. * ])
  909. * ])
  910. * ])
  911. * ])
  912. * ```
  913. *
  914. * @publicApi
  915. */
  916. function stagger(timings, animation) {
  917. return { type: 12 /* Stagger */, timings: timings, animation: animation };
  918. }
  919. /**
  920. * @license
  921. * Copyright Google Inc. All Rights Reserved.
  922. *
  923. * Use of this source code is governed by an MIT-style license that can be
  924. * found in the LICENSE file at https://angular.io/license
  925. */
  926. function scheduleMicroTask(cb) {
  927. Promise.resolve(null).then(cb);
  928. }
  929. /**
  930. * @license
  931. * Copyright Google Inc. All Rights Reserved.
  932. *
  933. * Use of this source code is governed by an MIT-style license that can be
  934. * found in the LICENSE file at https://angular.io/license
  935. */
  936. /**
  937. * An empty programmatic controller for reusable animations.
  938. * Used internally when animations are disabled, to avoid
  939. * checking for the null case when an animation player is expected.
  940. *
  941. * @see `animate()`
  942. * @see `AnimationPlayer`
  943. * @see `GroupPlayer`
  944. *
  945. * @publicApi
  946. */
  947. var NoopAnimationPlayer = /** @class */ (function () {
  948. function NoopAnimationPlayer(duration, delay) {
  949. if (duration === void 0) { duration = 0; }
  950. if (delay === void 0) { delay = 0; }
  951. this._onDoneFns = [];
  952. this._onStartFns = [];
  953. this._onDestroyFns = [];
  954. this._started = false;
  955. this._destroyed = false;
  956. this._finished = false;
  957. this.parentPlayer = null;
  958. this.totalTime = duration + delay;
  959. }
  960. NoopAnimationPlayer.prototype._onFinish = function () {
  961. if (!this._finished) {
  962. this._finished = true;
  963. this._onDoneFns.forEach(function (fn) { return fn(); });
  964. this._onDoneFns = [];
  965. }
  966. };
  967. NoopAnimationPlayer.prototype.onStart = function (fn) { this._onStartFns.push(fn); };
  968. NoopAnimationPlayer.prototype.onDone = function (fn) { this._onDoneFns.push(fn); };
  969. NoopAnimationPlayer.prototype.onDestroy = function (fn) { this._onDestroyFns.push(fn); };
  970. NoopAnimationPlayer.prototype.hasStarted = function () { return this._started; };
  971. NoopAnimationPlayer.prototype.init = function () { };
  972. NoopAnimationPlayer.prototype.play = function () {
  973. if (!this.hasStarted()) {
  974. this._onStart();
  975. this.triggerMicrotask();
  976. }
  977. this._started = true;
  978. };
  979. /** @internal */
  980. NoopAnimationPlayer.prototype.triggerMicrotask = function () {
  981. var _this = this;
  982. scheduleMicroTask(function () { return _this._onFinish(); });
  983. };
  984. NoopAnimationPlayer.prototype._onStart = function () {
  985. this._onStartFns.forEach(function (fn) { return fn(); });
  986. this._onStartFns = [];
  987. };
  988. NoopAnimationPlayer.prototype.pause = function () { };
  989. NoopAnimationPlayer.prototype.restart = function () { };
  990. NoopAnimationPlayer.prototype.finish = function () { this._onFinish(); };
  991. NoopAnimationPlayer.prototype.destroy = function () {
  992. if (!this._destroyed) {
  993. this._destroyed = true;
  994. if (!this.hasStarted()) {
  995. this._onStart();
  996. }
  997. this.finish();
  998. this._onDestroyFns.forEach(function (fn) { return fn(); });
  999. this._onDestroyFns = [];
  1000. }
  1001. };
  1002. NoopAnimationPlayer.prototype.reset = function () { };
  1003. NoopAnimationPlayer.prototype.setPosition = function (position) { };
  1004. NoopAnimationPlayer.prototype.getPosition = function () { return 0; };
  1005. /** @internal */
  1006. NoopAnimationPlayer.prototype.triggerCallback = function (phaseName) {
  1007. var methods = phaseName == 'start' ? this._onStartFns : this._onDoneFns;
  1008. methods.forEach(function (fn) { return fn(); });
  1009. methods.length = 0;
  1010. };
  1011. return NoopAnimationPlayer;
  1012. }());
  1013. /**
  1014. * @license
  1015. * Copyright Google Inc. All Rights Reserved.
  1016. *
  1017. * Use of this source code is governed by an MIT-style license that can be
  1018. * found in the LICENSE file at https://angular.io/license
  1019. */
  1020. /**
  1021. * A programmatic controller for a group of reusable animations.
  1022. * Used internally to control animations.
  1023. *
  1024. * @see `AnimationPlayer`
  1025. * @see `{@link animations/group group()}`
  1026. *
  1027. */
  1028. var AnimationGroupPlayer = /** @class */ (function () {
  1029. function AnimationGroupPlayer(_players) {
  1030. var _this = this;
  1031. this._onDoneFns = [];
  1032. this._onStartFns = [];
  1033. this._finished = false;
  1034. this._started = false;
  1035. this._destroyed = false;
  1036. this._onDestroyFns = [];
  1037. this.parentPlayer = null;
  1038. this.totalTime = 0;
  1039. this.players = _players;
  1040. var doneCount = 0;
  1041. var destroyCount = 0;
  1042. var startCount = 0;
  1043. var total = this.players.length;
  1044. if (total == 0) {
  1045. scheduleMicroTask(function () { return _this._onFinish(); });
  1046. }
  1047. else {
  1048. this.players.forEach(function (player) {
  1049. player.onDone(function () {
  1050. if (++doneCount == total) {
  1051. _this._onFinish();
  1052. }
  1053. });
  1054. player.onDestroy(function () {
  1055. if (++destroyCount == total) {
  1056. _this._onDestroy();
  1057. }
  1058. });
  1059. player.onStart(function () {
  1060. if (++startCount == total) {
  1061. _this._onStart();
  1062. }
  1063. });
  1064. });
  1065. }
  1066. this.totalTime = this.players.reduce(function (time, player) { return Math.max(time, player.totalTime); }, 0);
  1067. }
  1068. AnimationGroupPlayer.prototype._onFinish = function () {
  1069. if (!this._finished) {
  1070. this._finished = true;
  1071. this._onDoneFns.forEach(function (fn) { return fn(); });
  1072. this._onDoneFns = [];
  1073. }
  1074. };
  1075. AnimationGroupPlayer.prototype.init = function () { this.players.forEach(function (player) { return player.init(); }); };
  1076. AnimationGroupPlayer.prototype.onStart = function (fn) { this._onStartFns.push(fn); };
  1077. AnimationGroupPlayer.prototype._onStart = function () {
  1078. if (!this.hasStarted()) {
  1079. this._started = true;
  1080. this._onStartFns.forEach(function (fn) { return fn(); });
  1081. this._onStartFns = [];
  1082. }
  1083. };
  1084. AnimationGroupPlayer.prototype.onDone = function (fn) { this._onDoneFns.push(fn); };
  1085. AnimationGroupPlayer.prototype.onDestroy = function (fn) { this._onDestroyFns.push(fn); };
  1086. AnimationGroupPlayer.prototype.hasStarted = function () { return this._started; };
  1087. AnimationGroupPlayer.prototype.play = function () {
  1088. if (!this.parentPlayer) {
  1089. this.init();
  1090. }
  1091. this._onStart();
  1092. this.players.forEach(function (player) { return player.play(); });
  1093. };
  1094. AnimationGroupPlayer.prototype.pause = function () { this.players.forEach(function (player) { return player.pause(); }); };
  1095. AnimationGroupPlayer.prototype.restart = function () { this.players.forEach(function (player) { return player.restart(); }); };
  1096. AnimationGroupPlayer.prototype.finish = function () {
  1097. this._onFinish();
  1098. this.players.forEach(function (player) { return player.finish(); });
  1099. };
  1100. AnimationGroupPlayer.prototype.destroy = function () { this._onDestroy(); };
  1101. AnimationGroupPlayer.prototype._onDestroy = function () {
  1102. if (!this._destroyed) {
  1103. this._destroyed = true;
  1104. this._onFinish();
  1105. this.players.forEach(function (player) { return player.destroy(); });
  1106. this._onDestroyFns.forEach(function (fn) { return fn(); });
  1107. this._onDestroyFns = [];
  1108. }
  1109. };
  1110. AnimationGroupPlayer.prototype.reset = function () {
  1111. this.players.forEach(function (player) { return player.reset(); });
  1112. this._destroyed = false;
  1113. this._finished = false;
  1114. this._started = false;
  1115. };
  1116. AnimationGroupPlayer.prototype.setPosition = function (p) {
  1117. var timeAtPosition = p * this.totalTime;
  1118. this.players.forEach(function (player) {
  1119. var position = player.totalTime ? Math.min(1, timeAtPosition / player.totalTime) : 1;
  1120. player.setPosition(position);
  1121. });
  1122. };
  1123. AnimationGroupPlayer.prototype.getPosition = function () {
  1124. var min = 0;
  1125. this.players.forEach(function (player) {
  1126. var p = player.getPosition();
  1127. min = Math.min(p, min);
  1128. });
  1129. return min;
  1130. };
  1131. AnimationGroupPlayer.prototype.beforeDestroy = function () {
  1132. this.players.forEach(function (player) {
  1133. if (player.beforeDestroy) {
  1134. player.beforeDestroy();
  1135. }
  1136. });
  1137. };
  1138. /** @internal */
  1139. AnimationGroupPlayer.prototype.triggerCallback = function (phaseName) {
  1140. var methods = phaseName == 'start' ? this._onStartFns : this._onDoneFns;
  1141. methods.forEach(function (fn) { return fn(); });
  1142. methods.length = 0;
  1143. };
  1144. return AnimationGroupPlayer;
  1145. }());
  1146. /**
  1147. * @license
  1148. * Copyright Google Inc. All Rights Reserved.
  1149. *
  1150. * Use of this source code is governed by an MIT-style license that can be
  1151. * found in the LICENSE file at https://angular.io/license
  1152. */
  1153. var ɵPRE_STYLE = '!';
  1154. /**
  1155. * @license
  1156. * Copyright Google Inc. All Rights Reserved.
  1157. *
  1158. * Use of this source code is governed by an MIT-style license that can be
  1159. * found in the LICENSE file at https://angular.io/license
  1160. */
  1161. /**
  1162. * @license
  1163. * Copyright Google Inc. All Rights Reserved.
  1164. *
  1165. * Use of this source code is governed by an MIT-style license that can be
  1166. * found in the LICENSE file at https://angular.io/license
  1167. */
  1168. /**
  1169. * @license
  1170. * Copyright Google Inc. All Rights Reserved.
  1171. *
  1172. * Use of this source code is governed by an MIT-style license that can be
  1173. * found in the LICENSE file at https://angular.io/license
  1174. */
  1175. /**
  1176. * Generated bundle index. Do not edit.
  1177. */
  1178. export { AnimationBuilder, AnimationFactory, AUTO_STYLE, animate, animateChild, animation, group, keyframes, query, sequence, stagger, state, style, transition, trigger, useAnimation, NoopAnimationPlayer, ɵPRE_STYLE, AnimationGroupPlayer as ɵAnimationGroupPlayer };
  1179. //# sourceMappingURL=animations.js.map