text: /**
   * @license Angular v8.2.10
   * (c) 2010-2019 Google LLC. https://angular.io/
   * License: MIT
   */
  
  import { NoopAnimationPlayer, ɵAnimationGroupPlayer, ɵPRE_STYLE, AUTO_STYLE, sequence, style } from '@angular/animations';
  import { Injectable } from '@angular/core';
  
  /**
   * @fileoverview added by tsickle
   * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
   */
  /**
   * @return {?}
   */
  function isBrowser() {
      return (typeof window !== 'undefined' && typeof window.document !== 'undefined');
  }
  /**
   * @return {?}
   */
  function isNode() {
      return (typeof process !== 'undefined');
  }
  /**
   * @param {?} players
   * @return {?}
   */
  function optimizeGroupPlayer(players) {
      switch (players.length) {
          case 0:
              return new NoopAnimationPlayer();
          case 1:
              return players[0];
          default:
              return new ɵAnimationGroupPlayer(players);
      }
  }
  /**
   * @param {?} driver
   * @param {?} normalizer
   * @param {?} element
   * @param {?} keyframes
   * @param {?=} preStyles
   * @param {?=} postStyles
   * @return {?}
   */
  function normalizeKeyframes(driver, normalizer, element, keyframes, preStyles = {}, postStyles = {}) {
      /** @type {?} */
      const errors = [];
      /** @type {?} */
      const normalizedKeyframes = [];
      /** @type {?} */
      let previousOffset = -1;
      /** @type {?} */
      let previousKeyframe = null;
      keyframes.forEach((/**
       * @param {?} kf
       * @return {?}
       */
      kf => {
          /** @type {?} */
          const offset = (/** @type {?} */ (kf['offset']));
          /** @type {?} */
          const isSameOffset = offset == previousOffset;
          /** @type {?} */
          const normalizedKeyframe = (isSameOffset && previousKeyframe) || {};
          Object.keys(kf).forEach((/**
           * @param {?} prop
           * @return {?}
           */
          prop => {
              /** @type {?} */
              let normalizedProp = prop;
              /** @type {?} */
              let normalizedValue = kf[prop];
              if (prop !== 'offset') {
                  normalizedProp = normalizer.normalizePropertyName(normalizedProp, errors);
                  switch (normalizedValue) {
                      case ɵPRE_STYLE:
                          normalizedValue = preStyles[prop];
                          break;
                      case AUTO_STYLE:
                          normalizedValue = postStyles[prop];
                          break;
                      default:
                          normalizedValue =
                              normalizer.normalizeStyleValue(prop, normalizedProp, normalizedValue, errors);
                          break;
                  }
              }
              normalizedKeyframe[normalizedProp] = normalizedValue;
          }));
          if (!isSameOffset) {
              normalizedKeyframes.push(normalizedKeyframe);
          }
          previousKeyframe = normalizedKeyframe;
          previousOffset = offset;
      }));
      if (errors.length) {
          /** @type {?} */
          const LINE_START = '\n - ';
          throw new Error(`Unable to animate due to the following errors:${LINE_START}${errors.join(LINE_START)}`);
      }
      return normalizedKeyframes;
  }
  /**
   * @param {?} player
   * @param {?} eventName
   * @param {?} event
   * @param {?} callback
   * @return {?}
   */
  function listenOnPlayer(player, eventName, event, callback) {
      switch (eventName) {
          case 'start':
              player.onStart((/**
               * @return {?}
               */
              () => callback(event && copyAnimationEvent(event, 'start', player))));
              break;
          case 'done':
              player.onDone((/**
               * @return {?}
               */
              () => callback(event && copyAnimationEvent(event, 'done', player))));
              break;
          case 'destroy':
              player.onDestroy((/**
               * @return {?}
               */
              () => callback(event && copyAnimationEvent(event, 'destroy', player))));
              break;
      }
  }
  /**
   * @param {?} e
   * @param {?} phaseName
   * @param {?} player
   * @return {?}
   */
  function copyAnimationEvent(e, phaseName, player) {
      /** @type {?} */
      const totalTime = player.totalTime;
      /** @type {?} */
      const disabled = ((/** @type {?} */ (player))).disabled ? true : false;
      /** @type {?} */
      const event = makeAnimationEvent(e.element, e.triggerName, e.fromState, e.toState, phaseName || e.phaseName, totalTime == undefined ? e.totalTime : totalTime, disabled);
      /** @type {?} */
      const data = ((/** @type {?} */ (e)))['_data'];
      if (data != null) {
          ((/** @type {?} */ (event)))['_data'] = data;
      }
      return event;
  }
  /**
   * @param {?} element
   * @param {?} triggerName
   * @param {?} fromState
   * @param {?} toState
   * @param {?=} phaseName
   * @param {?=} totalTime
   * @param {?=} disabled
   * @return {?}
   */
  function makeAnimationEvent(element, triggerName, fromState, toState, phaseName = '', totalTime = 0, disabled) {
      return { element, triggerName, fromState, toState, phaseName, totalTime, disabled: !!disabled };
  }
  /**
   * @param {?} map
   * @param {?} key
   * @param {?} defaultValue
   * @return {?}
   */
  function getOrSetAsInMap(map, key, defaultValue) {
      /** @type {?} */
      let value;
      if (map instanceof Map) {
          value = map.get(key);
          if (!value) {
              map.set(key, value = defaultValue);
          }
      }
      else {
          value = map[key];
          if (!value) {
              value = map[key] = defaultValue;
          }
      }
      return value;
  }
  /**
   * @param {?} command
   * @return {?}
   */
  function parseTimelineCommand(command) {
      /** @type {?} */
      const separatorPos = command.indexOf(':');
      /** @type {?} */
      const id = command.substring(1, separatorPos);
      /** @type {?} */
      const action = command.substr(separatorPos + 1);
      return [id, action];
  }
  /** @type {?} */
  let _contains = (/**
   * @param {?} elm1
   * @param {?} elm2
   * @return {?}
   */
  (elm1, elm2) => false);
  const ɵ0 = _contains;
  /** @type {?} */
  let _matches = (/**
   * @param {?} element
   * @param {?} selector
   * @return {?}
   */
  (element, selector) => false);
  const ɵ1 = _matches;
  /** @type {?} */
  let _query = (/**
   * @param {?} element
   * @param {?} selector
   * @param {?} multi
   * @return {?}
   */
  (element, selector, multi) => {
      return [];
  });
  const ɵ2 = _query;
  // Define utility methods for browsers and platform-server(domino) where Element
  // and utility methods exist.
  /** @type {?} */
  const _isNode = isNode();
  if (_isNode || typeof Element !== 'undefined') {
      // this is well supported in all browsers
      _contains = (/**
       * @param {?} elm1
       * @param {?} elm2
       * @return {?}
       */
      (elm1, elm2) => { return (/** @type {?} */ (elm1.contains(elm2))); });
      _matches = ((/**
       * @return {?}
       */
      () => {
          if (_isNode || Element.prototype.matches) {
              return (/**
               * @param {?} element
               * @param {?} selector
               * @return {?}
               */
              (element, selector) => element.matches(selector));
          }
          else {
              /** @type {?} */
              const proto = (/** @type {?} */ (Element.prototype));
              /** @type {?} */
              const fn = proto.matchesSelector || proto.mozMatchesSelector || proto.msMatchesSelector ||
                  proto.oMatchesSelector || proto.webkitMatchesSelector;
              if (fn) {
                  return (/**
                   * @param {?} element
                   * @param {?} selector
                   * @return {?}
                   */
                  (element, selector) => fn.apply(element, [selector]));
              }
              else {
                  return _matches;
              }
          }
      }))();
      _query = (/**
       * @param {?} element
       * @param {?} selector
       * @param {?} multi
       * @return {?}
       */
      (element, selector, multi) => {
          /** @type {?} */
          let results = [];
          if (multi) {
              results.push(...element.querySelectorAll(selector));
          }
          else {
              /** @type {?} */
              const elm = element.querySelector(selector);
              if (elm) {
                  results.push(elm);
              }
          }
          return results;
      });
  }
  /**
   * @param {?} prop
   * @return {?}
   */
  function containsVendorPrefix(prop) {
      // Webkit is the only real popular vendor prefix nowadays
      // cc: http://shouldiprefix.com/
      return prop.substring(1, 6) == 'ebkit'; // webkit or Webkit
  }
  /** @type {?} */
  let _CACHED_BODY = null;
  /** @type {?} */
  let _IS_WEBKIT = false;
  /**
   * @param {?} prop
   * @return {?}
   */
  function validateStyleProperty(prop) {
      if (!_CACHED_BODY) {
          _CACHED_BODY = getBodyNode() || {};
          _IS_WEBKIT = (/** @type {?} */ (_CACHED_BODY)).style ? ('WebkitAppearance' in (/** @type {?} */ (_CACHED_BODY)).style) : false;
      }
      /** @type {?} */
      let result = true;
      if ((/** @type {?} */ (_CACHED_BODY)).style && !containsVendorPrefix(prop)) {
          result = prop in (/** @type {?} */ (_CACHED_BODY)).style;
          if (!result && _IS_WEBKIT) {
              /** @type {?} */
              const camelProp = 'Webkit' + prop.charAt(0).toUpperCase() + prop.substr(1);
              result = camelProp in (/** @type {?} */ (_CACHED_BODY)).style;
          }
      }
      return result;
  }
  /**
   * @return {?}
   */
  function getBodyNode() {
      if (typeof document != 'undefined') {
          return document.body;
      }
      return null;
  }
  /** @type {?} */
  const matchesElement = _matches;
  /** @type {?} */
  const containsElement = _contains;
  /** @type {?} */
  const invokeQuery = _query;
  /**
   * @param {?} object
   * @return {?}
   */
  function hypenatePropsObject(object) {
      /** @type {?} */
      const newObj = {};
      Object.keys(object).forEach((/**
       * @param {?} prop
       * @return {?}
       */
      prop => {
          /** @type {?} */
          const newProp = prop.replace(/([a-z])([A-Z])/g, '$1-$2');
          newObj[newProp] = object[prop];
      }));
      return newObj;
  }
  
  /**
   * @fileoverview added by tsickle
   * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
   */
  /**
   * \@publicApi
   */
  class NoopAnimationDriver {
      /**
       * @param {?} prop
       * @return {?}
       */
      validateStyleProperty(prop) { return validateStyleProperty(prop); }
      /**
       * @param {?} element
       * @param {?} selector
       * @return {?}
       */
      matchesElement(element, selector) {
          return matchesElement(element, selector);
      }
      /**
       * @param {?} elm1
       * @param {?} elm2
       * @return {?}
       */
      containsElement(elm1, elm2) { return containsElement(elm1, elm2); }
      /**
       * @param {?} element
       * @param {?} selector
       * @param {?} multi
       * @return {?}
       */
      query(element, selector, multi) {
          return invokeQuery(element, selector, multi);
      }
      /**
       * @param {?} element
       * @param {?} prop
       * @param {?=} defaultValue
       * @return {?}
       */
      computeStyle(element, prop, defaultValue) {
          return defaultValue || '';
      }
      /**
       * @param {?} element
       * @param {?} keyframes
       * @param {?} duration
       * @param {?} delay
       * @param {?} easing
       * @param {?=} previousPlayers
       * @param {?=} scrubberAccessRequested
       * @return {?}
       */
      animate(element, keyframes, duration, delay, easing, previousPlayers = [], scrubberAccessRequested) {
          return new NoopAnimationPlayer(duration, delay);
      }
  }
  NoopAnimationDriver.decorators = [
      { type: Injectable }
  ];
  /**
   * \@publicApi
   * @abstract
   */
  class AnimationDriver {
  }
  AnimationDriver.NOOP = new NoopAnimationDriver();
  if (false) {
      /** @type {?} */
      AnimationDriver.NOOP;
      /**
       * @abstract
       * @param {?} prop
       * @return {?}
       */
      AnimationDriver.prototype.validateStyleProperty = function (prop) { };
      /**
       * @abstract
       * @param {?} element
       * @param {?} selector
       * @return {?}
       */
      AnimationDriver.prototype.matchesElement = function (element, selector) { };
      /**
       * @abstract
       * @param {?} elm1
       * @param {?} elm2
       * @return {?}
       */
      AnimationDriver.prototype.containsElement = function (elm1, elm2) { };
      /**
       * @abstract
       * @param {?} element
       * @param {?} selector
       * @param {?} multi
       * @return {?}
       */
      AnimationDriver.prototype.query = function (element, selector, multi) { };
      /**
       * @abstract
       * @param {?} element
       * @param {?} prop
       * @param {?=} defaultValue
       * @return {?}
       */
      AnimationDriver.prototype.computeStyle = function (element, prop, defaultValue) { };
      /**
       * @abstract
       * @param {?} element
       * @param {?} keyframes
       * @param {?} duration
       * @param {?} delay
       * @param {?=} easing
       * @param {?=} previousPlayers
       * @param {?=} scrubberAccessRequested
       * @return {?}
       */
      AnimationDriver.prototype.animate = function (element, keyframes, duration, delay, easing, previousPlayers, scrubberAccessRequested) { };
  }
  
  /**
   * @fileoverview added by tsickle
   * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
   */
  /** @type {?} */
  const ONE_SECOND = 1000;
  /** @type {?} */
  const SUBSTITUTION_EXPR_START = '{{';
  /** @type {?} */
  const SUBSTITUTION_EXPR_END = '}}';
  /** @type {?} */
  const ENTER_CLASSNAME = 'ng-enter';
  /** @type {?} */
  const LEAVE_CLASSNAME = 'ng-leave';
  /** @type {?} */
  const ENTER_SELECTOR = '.ng-enter';
  /** @type {?} */
  const LEAVE_SELECTOR = '.ng-leave';
  /** @type {?} */
  const NG_TRIGGER_CLASSNAME = 'ng-trigger';
  /** @type {?} */
  const NG_TRIGGER_SELECTOR = '.ng-trigger';
  /** @type {?} */
  const NG_ANIMATING_CLASSNAME = 'ng-animating';
  /** @type {?} */
  const NG_ANIMATING_SELECTOR = '.ng-animating';
  /**
   * @param {?} value
   * @return {?}
   */
  function resolveTimingValue(value) {
      if (typeof value == 'number')
          return value;
      /** @type {?} */
      const matches = ((/** @type {?} */ (value))).match(/^(-?[\.\d]+)(m?s)/);
      if (!matches || matches.length < 2)
          return 0;
      return _convertTimeValueToMS(parseFloat(matches[1]), matches[2]);
  }
  /**
   * @param {?} value
   * @param {?} unit
   * @return {?}
   */
  function _convertTimeValueToMS(value, unit) {
      switch (unit) {
          case 's':
              return value * ONE_SECOND;
          default: // ms or something else
              return value;
      }
  }
  /**
   * @param {?} timings
   * @param {?} errors
   * @param {?=} allowNegativeValues
   * @return {?}
   */
  function resolveTiming(timings, errors, allowNegativeValues) {
      return timings.hasOwnProperty('duration') ?
          (/** @type {?} */ (timings)) :
          parseTimeExpression((/** @type {?} */ (timings)), errors, allowNegativeValues);
  }
  /**
   * @param {?} exp
   * @param {?} errors
   * @param {?=} allowNegativeValues
   * @return {?}
   */
  function parseTimeExpression(exp, errors, allowNegativeValues) {
      /** @type {?} */
      const regex = /^(-?[\.\d]+)(m?s)(?:\s+(-?[\.\d]+)(m?s))?(?:\s+([-a-z]+(?:\(.+?\))?))?$/i;
      /** @type {?} */
      let duration;
      /** @type {?} */
      let delay = 0;
      /** @type {?} */
      let easing = '';
      if (typeof exp === 'string') {
          /** @type {?} */
          const matches = exp.match(regex);
          if (matches === null) {
              errors.push(`The provided timing value "${exp}" is invalid.`);
              return { duration: 0, delay: 0, easing: '' };
          }
          duration = _convertTimeValueToMS(parseFloat(matches[1]), matches[2]);
          /** @type {?} */
          const delayMatch = matches[3];
          if (delayMatch != null) {
              delay = _convertTimeValueToMS(parseFloat(delayMatch), matches[4]);
          }
          /** @type {?} */
          const easingVal = matches[5];
          if (easingVal) {
              easing = easingVal;
          }
      }
      else {
          duration = (/** @type {?} */ (exp));
      }
      if (!allowNegativeValues) {
          /** @type {?} */
          let containsErrors = false;
          /** @type {?} */
          let startIndex = errors.length;
          if (duration < 0) {
              errors.push(`Duration values below 0 are not allowed for this animation step.`);
              containsErrors = true;
          }
          if (delay < 0) {
              errors.push(`Delay values below 0 are not allowed for this animation step.`);
              containsErrors = true;
          }
          if (containsErrors) {
              errors.splice(startIndex, 0, `The provided timing value "${exp}" is invalid.`);
          }
      }
      return { duration, delay, easing };
  }
  /**
   * @param {?} obj
   * @param {?=} destination
   * @return {?}
   */
  function copyObj(obj, destination = {}) {
      Object.keys(obj).forEach((/**
       * @param {?} prop
       * @return {?}
       */
      prop => { destination[prop] = obj[prop]; }));
      return destination;
  }
  /**
   * @param {?} styles
   * @return {?}
   */
  function normalizeStyles(styles) {
      /** @type {?} */
      const normalizedStyles = {};
      if (Array.isArray(styles)) {
          styles.forEach((/**
           * @param {?} data
           * @return {?}
           */
          data => copyStyles(data, false, normalizedStyles)));
      }
      else {
          copyStyles(styles, false, normalizedStyles);
      }
      return normalizedStyles;
  }
  /**
   * @param {?} styles
   * @param {?} readPrototype
   * @param {?=} destination
   * @return {?}
   */
  function copyStyles(styles, readPrototype, destination = {}) {
      if (readPrototype) {
          // we make use of a for-in loop so that the
          // prototypically inherited properties are
          // revealed from the backFill map
          for (let prop in styles) {
              destination[prop] = styles[prop];
          }
      }
      else {
          copyObj(styles, destination);
      }
      return destination;
  }
  /**
   * @param {?} element
   * @param {?} key
   * @param {?} value
   * @return {?}
   */
  function getStyleAttributeString(element, key, value) {
      // Return the key-value pair string to be added to the style attribute for the
      // given CSS style key.
      if (value) {
          return key + ':' + value + ';';
      }
      else {
          return '';
      }
  }
  /**
   * @param {?} element
   * @return {?}
   */
  function writeStyleAttribute(element) {
      // Read the style property of the element and manually reflect it to the
      // style attribute. This is needed because Domino on platform-server doesn't
      // understand the full set of allowed CSS properties and doesn't reflect some
      // of them automatically.
      /** @type {?} */
      let styleAttrValue = '';
      for (let i = 0; i < element.style.length; i++) {
          /** @type {?} */
          const key = element.style.item(i);
          styleAttrValue += getStyleAttributeString(element, key, element.style.getPropertyValue(key));
      }
      for (const key in element.style) {
          // Skip internal Domino properties that don't need to be reflected.
          if (!element.style.hasOwnProperty(key) || key.startsWith('_')) {
              continue;
          }
          /** @type {?} */
          const dashKey = camelCaseToDashCase(key);
          styleAttrValue += getStyleAttributeString(element, dashKey, element.style[key]);
      }
      element.setAttribute('style', styleAttrValue);
  }
  /**
   * @param {?} element
   * @param {?} styles
   * @param {?=} formerStyles
   * @return {?}
   */
  function setStyles(element, styles, formerStyles) {
      if (element['style']) {
          Object.keys(styles).forEach((/**
           * @param {?} prop
           * @return {?}
           */
          prop => {
              /** @type {?} */
              const camelProp = dashCaseToCamelCase(prop);
              if (formerStyles && !formerStyles.hasOwnProperty(prop)) {
                  formerStyles[prop] = element.style[camelProp];
              }
              element.style[camelProp] = styles[prop];
          }));
          // On the server set the 'style' attribute since it's not automatically reflected.
          if (isNode()) {
              writeStyleAttribute(element);
          }
      }
  }
  /**
   * @param {?} element
   * @param {?} styles
   * @return {?}
   */
  function eraseStyles(element, styles) {
      if (element['style']) {
          Object.keys(styles).forEach((/**
           * @param {?} prop
           * @return {?}
           */
          prop => {
              /** @type {?} */
              const camelProp = dashCaseToCamelCase(prop);
              element.style[camelProp] = '';
          }));
          // On the server set the 'style' attribute since it's not automatically reflected.
          if (isNode()) {
              writeStyleAttribute(element);
          }
      }
  }
  /**
   * @param {?} steps
   * @return {?}
   */
  function normalizeAnimationEntry(steps) {
      if (Array.isArray(steps)) {
          if (steps.length == 1)
              return steps[0];
          return sequence(steps);
      }
      return (/** @type {?} */ (steps));
  }
  /**
   * @param {?} value
   * @param {?} options
   * @param {?} errors
   * @return {?}
   */
  function validateStyleParams(value, options, errors) {
      /** @type {?} */
      const params = options.params || {};
      /** @type {?} */
      const matches = extractStyleParams(value);
      if (matches.length) {
          matches.forEach((/**
           * @param {?} varName
           * @return {?}
           */
          varName => {
              if (!params.hasOwnProperty(varName)) {
                  errors.push(`Unable to resolve the local animation param ${varName} in the given list of values`);
              }
          }));
      }
  }
  /** @type {?} */
  const PARAM_REGEX = new RegExp(`${SUBSTITUTION_EXPR_START}\\s*(.+?)\\s*${SUBSTITUTION_EXPR_END}`, 'g');
  /**
   * @param {?} value
   * @return {?}
   */
  function extractStyleParams(value) {
      /** @type {?} */
      let params = [];
      if (typeof value === 'string') {
          /** @type {?} */
          const val = value.toString();
          /** @type {?} */
          let match;
          while (match = PARAM_REGEX.exec(val)) {
              params.push((/** @type {?} */ (match[1])));
          }
          PARAM_REGEX.lastIndex = 0;
      }
      return params;
  }
  /**
   * @param {?} value
   * @param {?} params
   * @param {?} errors
   * @return {?}
   */
  function interpolateParams(value, params, errors) {
      /** @type {?} */
      const original = value.toString();
      /** @type {?} */
      const str = original.replace(PARAM_REGEX, (/**
       * @param {?} _
       * @param {?} varName
       * @return {?}
       */
      (_, varName) => {
          /** @type {?} */
          let localVal = params[varName];
          // this means that the value was never overridden by the data passed in by the user
          if (!params.hasOwnProperty(varName)) {
              errors.push(`Please provide a value for the animation param ${varName}`);
              localVal = '';
          }
          return localVal.toString();
      }));
      // we do this to assert that numeric values stay as they are
      return str == original ? value : str;
  }
  /**
   * @param {?} iterator
   * @return {?}
   */
  function iteratorToArray(iterator) {
      /** @type {?} */
      const arr = [];
      /** @type {?} */
      let item = iterator.next();
      while (!item.done) {
          arr.push(item.value);
          item = iterator.next();
      }
      return arr;
  }
  /**
   * @param {?} source
   * @param {?} destination
   * @return {?}
   */
  function mergeAnimationOptions(source, destination) {
      if (source.params) {
          /** @type {?} */
          const p0 = source.params;
          if (!destination.params) {
              destination.params = {};
          }
          /** @type {?} */
          const p1 = destination.params;
          Object.keys(p0).forEach((/**
           * @param {?} param
           * @return {?}
           */
          param => {
              if (!p1.hasOwnProperty(param)) {
                  p1[param] = p0[param];
              }
          }));
      }
      return destination;
  }
  /** @type {?} */
  const DASH_CASE_REGEXP = /-+([a-z0-9])/g;
  /**
   * @param {?} input
   * @return {?}
   */
  function dashCaseToCamelCase(input) {
      return input.replace(DASH_CASE_REGEXP, (/**
       * @param {...?} m
       * @return {?}
       */
      (...m) => m[1].toUpperCase()));
  }
  /**
   * @param {?} input
   * @return {?}
   */
  function camelCaseToDashCase(input) {
      return input.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
  }
  /**
   * @param {?} duration
   * @param {?} delay
   * @return {?}
   */
  function allowPreviousPlayerStylesMerge(duration, delay) {
      return duration === 0 || delay === 0;
  }
  /**
   * @param {?} element
   * @param {?} keyframes
   * @param {?} previousStyles
   * @return {?}
   */
  function balancePreviousStylesIntoKeyframes(element, keyframes, previousStyles) {
      /** @type {?} */
      const previousStyleProps = Object.keys(previousStyles);
      if (previousStyleProps.length && keyframes.length) {
          /** @type {?} */
          let startingKeyframe = keyframes[0];
          /** @type {?} */
          let missingStyleProps = [];
          previousStyleProps.forEach((/**
           * @param {?} prop
           * @return {?}
           */
          prop => {
              if (!startingKeyframe.hasOwnProperty(prop)) {
                  missingStyleProps.push(prop);
              }
              startingKeyframe[prop] = previousStyles[prop];
          }));
          if (missingStyleProps.length) {
              // tslint:disable-next-line
              for (var i = 1; i < keyframes.length; i++) {
                  /** @type {?} */
                  let kf = keyframes[i];
                  missingStyleProps.forEach((/**
                   * @param {?} prop
                   * @return {?}
                   */
                  function (prop) { kf[prop] = computeStyle(element, prop); }));
              }
          }
      }
      return keyframes;
  }
  /**
   * @param {?} visitor
   * @param {?} node
   * @param {?} context
   * @return {?}
   */
  function visitDslNode(visitor, node, context) {
      switch (node.type) {
          case 7 /* Trigger */:
              return visitor.visitTrigger(node, context);
          case 0 /* State */:
              return visitor.visitState(node, context);
          case 1 /* Transition */:
              return visitor.visitTransition(node, context);
          case 2 /* Sequence */:
              return visitor.visitSequence(node, context);
          case 3 /* Group */:
              return visitor.visitGroup(node, context);
          case 4 /* Animate */:
              return visitor.visitAnimate(node, context);
          case 5 /* Keyframes */:
              return visitor.visitKeyframes(node, context);
          case 6 /* Style */:
              return visitor.visitStyle(node, context);
          case 8 /* Reference */:
              return visitor.visitReference(node, context);
          case 9 /* AnimateChild */:
              return visitor.visitAnimateChild(node, context);
          case 10 /* AnimateRef */:
              return visitor.visitAnimateRef(node, context);
          case 11 /* Query */:
              return visitor.visitQuery(node, context);
          case 12 /* Stagger */:
              return visitor.visitStagger(node, context);
          default:
              throw new Error(`Unable to resolve animation metadata node #${node.type}`);
      }
  }
  /**
   * @param {?} element
   * @param {?} prop
   * @return {?}
   */
  function computeStyle(element, prop) {
      return ((/** @type {?} */ (window.getComputedStyle(element))))[prop];
  }
  
  /**
   * @fileoverview added by tsickle
   * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
   */
  /**
   * @license
   * Copyright Google Inc. All Rights Reserved.
   *
   * Use of this source code is governed by an MIT-style license that can be
   * found in the LICENSE file at https://angular.io/license
   * @type {?}
   */
  const ANY_STATE = '*';
  /**
   * @param {?} transitionValue
   * @param {?} errors
   * @return {?}
   */
  function parseTransitionExpr(transitionValue, errors) {
      /** @type {?} */
      const expressions = [];
      if (typeof transitionValue == 'string') {
          ((/** @type {?} */ (transitionValue)))
              .split(/\s*,\s*/)
              .forEach((/**
           * @param {?} str
           * @return {?}
           */
          str => parseInnerTransitionStr(str, expressions, errors)));
      }
      else {
          expressions.push((/** @type {?} */ (transitionValue)));
      }
      return expressions;
  }
  /**
   * @param {?} eventStr
   * @param {?} expressions
   * @param {?} errors
   * @return {?}
   */
  function parseInnerTransitionStr(eventStr, expressions, errors) {
      if (eventStr[0] == ':') {
          /** @type {?} */
          const result = parseAnimationAlias(eventStr, errors);
          if (typeof result == 'function') {
              expressions.push(result);
              return;
          }
          eventStr = (/** @type {?} */ (result));
      }
      /** @type {?} */
      const match = eventStr.match(/^(\*|[-\w]+)\s*(<?[=-]>)\s*(\*|[-\w]+)$/);
      if (match == null || match.length < 4) {
          errors.push(`The provided transition expression "${eventStr}" is not supported`);
          return expressions;
      }
      /** @type {?} */
      const fromState = match[1];
      /** @type {?} */
      const separator = match[2];
      /** @type {?} */
      const toState = match[3];
      expressions.push(makeLambdaFromStates(fromState, toState));
      /** @type {?} */
      const isFullAnyStateExpr = fromState == ANY_STATE && toState == ANY_STATE;
      if (separator[0] == '<' && !isFullAnyStateExpr) {
          expressions.push(makeLambdaFromStates(toState, fromState));
      }
  }
  /**
   * @param {?} alias
   * @param {?} errors
   * @return {?}
   */
  function parseAnimationAlias(alias, errors) {
      switch (alias) {
          case ':enter':
              return 'void => *';
          case ':leave':
              return '* => void';
          case ':increment':
              return (/**
               * @param {?} fromState
               * @param {?} toState
               * @return {?}
               */
              (fromState, toState) => parseFloat(toState) > parseFloat(fromState));
          case ':decrement':
              return (/**
               * @param {?} fromState
               * @param {?} toState
               * @return {?}
               */
              (fromState, toState) => parseFloat(toState) < parseFloat(fromState));
          default:
              errors.push(`The transition alias value "${alias}" is not supported`);
              return '* => *';
      }
  }
  // DO NOT REFACTOR ... keep the follow set instantiations
  // with the values intact (closure compiler for some reason
  // removes follow-up lines that add the values outside of
  // the constructor...
  /** @type {?} */
  const TRUE_BOOLEAN_VALUES = new Set(['true', '1']);
  /** @type {?} */
  const FALSE_BOOLEAN_VALUES = new Set(['false', '0']);
  /**
   * @param {?} lhs
   * @param {?} rhs
   * @return {?}
   */
  function makeLambdaFromStates(lhs, rhs) {
      /** @type {?} */
      const LHS_MATCH_BOOLEAN = TRUE_BOOLEAN_VALUES.has(lhs) || FALSE_BOOLEAN_VALUES.has(lhs);
      /** @type {?} */
      const RHS_MATCH_BOOLEAN = TRUE_BOOLEAN_VALUES.has(rhs) || FALSE_BOOLEAN_VALUES.has(rhs);
      return (/**
       * @param {?} fromState
       * @param {?} toState
       * @return {?}
       */
      (fromState, toState) => {
          /** @type {?} */
          let lhsMatch = lhs == ANY_STATE || lhs == fromState;
          /** @type {?} */
          let rhsMatch = rhs == ANY_STATE || rhs == toState;
          if (!lhsMatch && LHS_MATCH_BOOLEAN && typeof fromState === 'boolean') {
              lhsMatch = fromState ? TRUE_BOOLEAN_VALUES.has(lhs) : FALSE_BOOLEAN_VALUES.has(lhs);
          }
          if (!rhsMatch && RHS_MATCH_BOOLEAN && typeof toState === 'boolean') {
              rhsMatch = toState ? TRUE_BOOLEAN_VALUES.has(rhs) : FALSE_BOOLEAN_VALUES.has(rhs);
          }
          return lhsMatch && rhsMatch;
      });
  }
  
  /**
   * @fileoverview added by tsickle
   * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
   */
  /** @type {?} */
  const SELF_TOKEN = ':self';
  /** @type {?} */
  const SELF_TOKEN_REGEX = new RegExp(`\s*${SELF_TOKEN}\s*,?`, 'g');
  /*
   * [Validation]
   * The visitor code below will traverse the animation AST generated by the animation verb functions
   * (the output is a tree of objects) and attempt to perform a series of validations on the data. The
   * following corner-cases will be validated:
   *
   * 1. Overlap of animations
   * Given that a CSS property cannot be animated in more than one place at the same time, it's
   * important that this behavior is detected and validated. The way in which this occurs is that
   * each time a style property is examined, a string-map containing the property will be updated with
   * the start and end times for when the property is used within an animation step.
   *
   * If there are two or more parallel animations that are currently running (these are invoked by the
   * group()) on the same element then the validator will throw an error. Since the start/end timing
   * values are collected for each property then if the current animation step is animating the same
   * property and its timing values fall anywhere into the window of time that the property is
   * currently being animated within then this is what causes an error.
   *
   * 2. Timing values
   * The validator will validate to see if a timing value of `duration delay easing` or
   * `durationNumber` is valid or not.
   *
   * (note that upon validation the code below will replace the timing data with an object containing
   * {duration,delay,easing}.
   *
   * 3. Offset Validation
   * Each of the style() calls are allowed to have an offset value when placed inside of keyframes().
   * Offsets within keyframes() are considered valid when:
   *
   *   - No offsets are used at all
   *   - Each style() entry contains an offset value
   *   - Each offset is between 0 and 1
   *   - Each offset is greater to or equal than the previous one
   *
   * Otherwise an error will be thrown.
   */
  /**
   * @param {?} driver
   * @param {?} metadata
   * @param {?} errors
   * @return {?}
   */
  function buildAnimationAst(driver, metadata, errors) {
      return new AnimationAstBuilderVisitor(driver).build(metadata, errors);
  }
  /** @type {?} */
  const ROOT_SELECTOR = '';
  class AnimationAstBuilderVisitor {
      /**
       * @param {?} _driver
       */
      constructor(_driver) {
          this._driver = _driver;
      }
      /**
       * @param {?} metadata
       * @param {?} errors
       * @return {?}
       */
      build(metadata, errors) {
          /** @type {?} */
          const context = new AnimationAstBuilderContext(errors);
          this._resetContextStyleTimingState(context);
          return (/** @type {?} */ (visitDslNode(this, normalizeAnimationEntry(metadata), context)));
      }
      /**
       * @private
       * @param {?} context
       * @return {?}
       */
      _resetContextStyleTimingState(context) {
          context.currentQuerySelector = ROOT_SELECTOR;
          context.collectedStyles = {};
          context.collectedStyles[ROOT_SELECTOR] = {};
          context.currentTime = 0;
      }
      /**
       * @param {?} metadata
       * @param {?} context
       * @return {?}
       */
      visitTrigger(metadata, context) {
          /** @type {?} */
          let queryCount = context.queryCount = 0;
          /** @type {?} */
          let depCount = context.depCount = 0;
          /** @type {?} */
          const states = [];
          /** @type {?} */
          const transitions = [];
          if (metadata.name.charAt(0) == '@') {
              context.errors.push('animation triggers cannot be prefixed with an `@` sign (e.g. trigger(\'@foo\', [...]))');
          }
          metadata.definitions.forEach((/**
           * @param {?} def
           * @return {?}
           */
          def => {
              this._resetContextStyleTimingState(context);
              if (def.type == 0 /* State */) {
                  /** @type {?} */
                  const stateDef = (/** @type {?} */ (def));
                  /** @type {?} */
                  const name = stateDef.name;
                  name.toString().split(/\s*,\s*/).forEach((/**
                   * @param {?} n
                   * @return {?}
                   */
                  n => {
                      stateDef.name = n;
                      states.push(this.visitState(stateDef, context));
                  }));
                  stateDef.name = name;
              }
              else if (def.type == 1 /* Transition */) {
                  /** @type {?} */
                  const transition = this.visitTransition((/** @type {?} */ (def)), context);
                  queryCount += transition.queryCount;
                  depCount += transition.depCount;
                  transitions.push(transition);
              }
              else {
                  context.errors.push('only state() and transition() definitions can sit inside of a trigger()');
              }
          }));
          return {
              type: 7 /* Trigger */,
              name: metadata.name, states, transitions, queryCount, depCount,
              options: null
          };
      }
      /**
       * @param {?} metadata
       * @param {?} context
       * @return {?}
       */
      visitState(metadata, context) {
          /** @type {?} */
          const styleAst = this.visitStyle(metadata.styles, context);
          /** @type {?} */
          const astParams = (metadata.options && metadata.options.params) || null;
          if (styleAst.containsDynamicStyles) {
              /** @type {?} */
              const missingSubs = new Set();
              /** @type {?} */
              const params = astParams || {};
              styleAst.styles.forEach((/**
               * @param {?} value
               * @return {?}
               */
              value => {
                  if (isObject(value)) {
                      /** @type {?} */
                      const stylesObj = (/** @type {?} */ (value));
                      Object.keys(stylesObj).forEach((/**
                       * @param {?} prop
                       * @return {?}
                       */
                      prop => {
                          extractStyleParams(stylesObj[prop]).forEach((/**
                           * @param {?} sub
                           * @return {?}
                           */
                          sub => {
                              if (!params.hasOwnProperty(sub)) {
                                  missingSubs.add(sub);
                              }
                          }));
                      }));
                  }
              }));
              if (missingSubs.size) {
                  /** @type {?} */
                  const missingSubsArr = iteratorToArray(missingSubs.values());
                  context.errors.push(`state("${metadata.name}", ...) must define default values for all the following style substitutions: ${missingSubsArr.join(', ')}`);
              }
          }
          return {
              type: 0 /* State */,
              name: metadata.name,
              style: styleAst,
              options: astParams ? { params: astParams } : null
          };
      }
      /**
       * @param {?} metadata
       * @param {?} context
       * @return {?}
       */
      visitTransition(metadata, context) {
          context.queryCount = 0;
          context.depCount = 0;
          /** @type {?} */
          const animation = visitDslNode(this, normalizeAnimationEntry(metadata.animation), context);
          /** @type {?} */
          const matchers = parseTransitionExpr(metadata.expr, context.errors);
          return {
              type: 1 /* Transition */,
              matchers,
              animation,
              queryCount: context.queryCount,
              depCount: context.depCount,
              options: normalizeAnimationOptions(metadata.options)
          };
      }
      /**
       * @param {?} metadata
       * @param {?} context
       * @return {?}
       */
      visitSequence(metadata, context) {
          return {
              type: 2 /* Sequence */,
              steps: metadata.steps.map((/**
               * @param {?} s
               * @return {?}
               */
              s => visitDslNode(this, s, context))),
              options: normalizeAnimationOptions(metadata.options)
          };
      }
      /**
       * @param {?} metadata
       * @param {?} context
       * @return {?}
       */
      visitGroup(metadata, context) {
          /** @type {?} */
          const currentTime = context.currentTime;
          /** @type {?} */
          let furthestTime = 0;
          /** @type {?} */
          const steps = metadata.steps.map((/**
           * @param {?} step
           * @return {?}
           */
          step => {
              context.currentTime = currentTime;
              /** @type {?} */
              const innerAst = visitDslNode(this, step, context);
              furthestTime = Math.max(furthestTime, context.currentTime);
              return innerAst;
          }));
          context.currentTime = furthestTime;
          return {
              type: 3 /* Group */,
              steps,
              options: normalizeAnimationOptions(metadata.options)
          };
      }
      /**
       * @param {?} metadata
       * @param {?} context
       * @return {?}
       */
      visitAnimate(metadata, context) {
          /** @type {?} */
          const timingAst = constructTimingAst(metadata.timings, context.errors);
          context.currentAnimateTimings = timingAst;
          /** @type {?} */
          let styleAst;
          /** @type {?} */
          let styleMetadata = metadata.styles ? metadata.styles : style({});
          if (styleMetadata.type == 5 /* Keyframes */) {
              styleAst = this.visitKeyframes((/** @type {?} */ (styleMetadata)), context);
          }
          else {
              /** @type {?} */
              let styleMetadata = (/** @type {?} */ (metadata.styles));
              /** @type {?} */
              let isEmpty = false;
              if (!styleMetadata) {
                  isEmpty = true;
                  /** @type {?} */
                  const newStyleData = {};
                  if (timingAst.easing) {
                      newStyleData['easing'] = timingAst.easing;
                  }
                  styleMetadata = style(newStyleData);
              }
              context.currentTime += timingAst.duration + timingAst.delay;
              /** @type {?} */
              const _styleAst = this.visitStyle(styleMetadata, context);
              _styleAst.isEmptyStep = isEmpty;
              styleAst = _styleAst;
          }
          context.currentAnimateTimings = null;
          return {
              type: 4 /* Animate */,
              timings: timingAst,
              style: styleAst,
              options: null
          };
      }
      /**
       * @param {?} metadata
       * @param {?} context
       * @return {?}
       */
      visitStyle(metadata, context) {
          /** @type {?} */
          const ast = this._makeStyleAst(metadata, context);
          this._validateStyleAst(ast, context);
          return ast;
      }
      /**
       * @private
       * @param {?} metadata
       * @param {?} context
       * @return {?}
       */
      _makeStyleAst(metadata, context) {
          /** @type {?} */
          const styles = [];
          if (Array.isArray(metadata.styles)) {
              ((/** @type {?} */ (metadata.styles))).forEach((/**
               * @param {?} styleTuple
               * @return {?}
               */
              styleTuple => {
                  if (typeof styleTuple == 'string') {
                      if (styleTuple == AUTO_STYLE) {
                          styles.push((/** @type {?} */ (styleTuple)));
                      }
                      else {
                          context.errors.push(`The provided style string value ${styleTuple} is not allowed.`);
                      }
                  }
                  else {
                      styles.push((/** @type {?} */ (styleTuple)));
                  }
              }));
          }
          else {
              styles.push(metadata.styles);
          }
          /** @type {?} */
          let containsDynamicStyles = false;
          /** @type {?} */
          let collectedEasing = null;
          styles.forEach((/**
           * @param {?} styleData
           * @return {?}
           */
          styleData => {
              if (isObject(styleData)) {
                  /** @type {?} */
                  const styleMap = (/** @type {?} */ (styleData));
                  /** @type {?} */
                  const easing = styleMap['easing'];
                  if (easing) {
                      collectedEasing = (/** @type {?} */ (easing));
                      delete styleMap['easing'];
                  }
                  if (!containsDynamicStyles) {
                      for (let prop in styleMap) {
                          /** @type {?} */
                          const value = styleMap[prop];
                          if (value.toString().indexOf(SUBSTITUTION_EXPR_START) >= 0) {
                              containsDynamicStyles = true;
                              break;
                          }
                      }
                  }
              }
          }));
          return {
              type: 6 /* Style */,
              styles,
              easing: collectedEasing,
              offset: metadata.offset, containsDynamicStyles,
              options: null
          };
      }
      /**
       * @private
       * @param {?} ast
       * @param {?} context
       * @return {?}
       */
      _validateStyleAst(ast, context) {
          /** @type {?} */
          const timings = context.currentAnimateTimings;
          /** @type {?} */
          let endTime = context.currentTime;
          /** @type {?} */
          let startTime = context.currentTime;
          if (timings && startTime > 0) {
              startTime -= timings.duration + timings.delay;
          }
          ast.styles.forEach((/**
           * @param {?} tuple
           * @return {?}
           */
          tuple => {
              if (typeof tuple == 'string')
                  return;
              Object.keys(tuple).forEach((/**
               * @param {?} prop
               * @return {?}
               */
              prop => {
                  if (!this._driver.validateStyleProperty(prop)) {
                      context.errors.push(`The provided animation property "${prop}" is not a supported CSS property for animations`);
                      return;
                  }
                  /** @type {?} */
                  const collectedStyles = context.collectedStyles[(/** @type {?} */ (context.currentQuerySelector))];
                  /** @type {?} */
                  const collectedEntry = collectedStyles[prop];
                  /** @type {?} */
                  let updateCollectedStyle = true;
                  if (collectedEntry) {
                      if (startTime != endTime && startTime >= collectedEntry.startTime &&
                          endTime <= collectedEntry.endTime) {
                          context.errors.push(`The CSS property "${prop}" that exists between the times of "${collectedEntry.startTime}ms" and "${collectedEntry.endTime}ms" is also being animated in a parallel animation between the times of "${startTime}ms" and "${endTime}ms"`);
                          updateCollectedStyle = false;
                      }
                      // we always choose the smaller start time value since we
                      // want to have a record of the entire animation window where
                      // the style property is being animated in between
                      startTime = collectedEntry.startTime;
                  }
                  if (updateCollectedStyle) {
                      collectedStyles[prop] = { startTime, endTime };
                  }
                  if (context.options) {
                      validateStyleParams(tuple[prop], context.options, context.errors);
                  }
              }));
          }));
      }
      /**
       * @param {?} metadata
       * @param {?} context
       * @return {?}
       */
      visitKeyframes(metadata, context) {
          /** @type {?} */
          const ast = { type: 5 /* Keyframes */, styles: [], options: null };
          if (!context.currentAnimateTimings) {
              context.errors.push(`keyframes() must be placed inside of a call to animate()`);
              return ast;
          }
          /** @type {?} */
          const MAX_KEYFRAME_OFFSET = 1;
          /** @type {?} */
          let totalKeyframesWithOffsets = 0;
          /** @type {?} */
          const offsets = [];
          /** @type {?} */
          let offsetsOutOfOrder = false;
          /** @type {?} */
          let keyframesOutOfRange = false;
          /** @type {?} */
          let previousOffset = 0;
          /** @type {?} */
          const keyframes = metadata.steps.map((/**
           * @param {?} styles
           * @return {?}
           */
          styles => {
              /** @type {?} */
              const style = this._makeStyleAst(styles, context);
              /** @type {?} */
              let offsetVal = style.offset != null ? style.offset : consumeOffset(style.styles);
              /** @type {?} */
              let offset = 0;
              if (offsetVal != null) {
                  totalKeyframesWithOffsets++;
                  offset = style.offset = offsetVal;
              }
              keyframesOutOfRange = keyframesOutOfRange || offset < 0 || offset > 1;
              offsetsOutOfOrder = offsetsOutOfOrder || offset < previousOffset;
              previousOffset = offset;
              offsets.push(offset);
              return style;
          }));
          if (keyframesOutOfRange) {
              context.errors.push(`Please ensure that all keyframe offsets are between 0 and 1`);
          }
          if (offsetsOutOfOrder) {
              context.errors.push(`Please ensure that all keyframe offsets are in order`);
          }
          /** @type {?} */
          const length = metadata.steps.length;
          /** @type {?} */
          let generatedOffset = 0;
          if (totalKeyframesWithOffsets > 0 && totalKeyframesWithOffsets < length) {
              context.errors.push(`Not all style() steps within the declared keyframes() contain offsets`);
          }
          else if (totalKeyframesWithOffsets == 0) {
              generatedOffset = MAX_KEYFRAME_OFFSET / (length - 1);
          }
          /** @type {?} */
          const limit = length - 1;
          /** @type {?} */
          const currentTime = context.currentTime;
          /** @type {?} */
          const currentAnimateTimings = (/** @type {?} */ (context.currentAnimateTimings));
          /** @type {?} */
          const animateDuration = currentAnimateTimings.duration;
          keyframes.forEach((/**
           * @param {?} kf
           * @param {?} i
           * @return {?}
           */
          (kf, i) => {
              /** @type {?} */
              const offset = generatedOffset > 0 ? (i == limit ? 1 : (generatedOffset * i)) : offsets[i];
              /** @type {?} */
              const durationUpToThisFrame = offset * animateDuration;
              context.currentTime = currentTime + currentAnimateTimings.delay + durationUpToThisFrame;
              currentAnimateTimings.duration = durationUpToThisFrame;
              this._validateStyleAst(kf, context);
              kf.offset = offset;
              ast.styles.push(kf);
          }));
          return ast;
      }
      /**
       * @param {?} metadata
       * @param {?} context
       * @return {?}
       */
      visitReference(metadata, context) {
          return {
              type: 8 /* Reference */,
              animation: visitDslNode(this, normalizeAnimationEntry(metadata.animation), context),
              options: normalizeAnimationOptions(metadata.options)
          };
      }
      /**
       * @param {?} metadata
       * @param {?} context
       * @return {?}
       */
      visitAnimateChild(metadata, context) {
          context.depCount++;
          return {
              type: 9 /* AnimateChild */,
              options: normalizeAnimationOptions(metadata.options)
          };
      }
      /**
       * @param {?} metadata
       * @param {?} context
       * @return {?}
       */
      visitAnimateRef(metadata, context) {
          return {
              type: 10 /* AnimateRef */,
              animation: this.visitReference(metadata.animation, context),
              options: normalizeAnimationOptions(metadata.options)
          };
      }
      /**
       * @param {?} metadata
       * @param {?} context
       * @return {?}
       */
      visitQuery(metadata, context) {
          /** @type {?} */
          const parentSelector = (/** @type {?} */ (context.currentQuerySelector));
          /** @type {?} */
          const options = (/** @type {?} */ ((metadata.options || {})));
          context.queryCount++;
          context.currentQuery = metadata;
          const [selector, includeSelf] = normalizeSelector(metadata.selector);
          context.currentQuerySelector =
              parentSelector.length ? (parentSelector + ' ' + selector) : selector;
          getOrSetAsInMap(context.collectedStyles, context.currentQuerySelector, {});
          /** @type {?} */
          const animation = visitDslNode(this, normalizeAnimationEntry(metadata.animation), context);
          context.currentQuery = null;
          context.currentQuerySelector = parentSelector;
          return {
              type: 11 /* Query */,
              selector,
              limit: options.limit || 0,
              optional: !!options.optional, includeSelf, animation,
              originalSelector: metadata.selector,
              options: normalizeAnimationOptions(metadata.options)
          };
      }
      /**
       * @param {?} metadata
       * @param {?} context
       * @return {?}
       */
      visitStagger(metadata, context) {
          if (!context.currentQuery) {
              context.errors.push(`stagger() can only be used inside of query()`);
          }
          /** @type {?} */
          const timings = metadata.timings === 'full' ?
              { duration: 0, delay: 0, easing: 'full' } :
              resolveTiming(metadata.timings, context.errors, true);
          return {
              type: 12 /* Stagger */,
              animation: visitDslNode(this, normalizeAnimationEntry(metadata.animation), context), timings,
              options: null
          };
      }
  }
  if (false) {
      /**
       * @type {?}
       * @private
       */
      AnimationAstBuilderVisitor.prototype._driver;
  }
  /**
   * @param {?} selector
   * @return {?}
   */
  function normalizeSelector(selector) {
      /** @type {?} */
      const hasAmpersand = selector.split(/\s*,\s*/).find((/**
       * @param {?} token
       * @return {?}
       */
      token => token == SELF_TOKEN)) ? true : false;
      if (hasAmpersand) {
          selector = selector.replace(SELF_TOKEN_REGEX, '');
      }
      // the :enter and :leave selectors are filled in at runtime during timeline building
      selector = selector.replace(/@\*/g, NG_TRIGGER_SELECTOR)
          .replace(/@\w+/g, (/**
       * @param {?} match
       * @return {?}
       */
      match => NG_TRIGGER_SELECTOR + '-' + match.substr(1)))
          .replace(/:animating/g, NG_ANIMATING_SELECTOR);
      return [selector, hasAmpersand];
  }
  /**
   * @param {?} obj
   * @return {?}
   */
  function normalizeParams(obj) {
      return obj ? copyObj(obj) : null;
  }
  class AnimationAstBuilderContext {
      /**
       * @param {?} errors
       */
      constructor(errors) {
          this.errors = errors;
          this.queryCount = 0;
          this.depCount = 0;
          this.currentTransition = null;
          this.currentQuery = null;
          this.currentQuerySelector = null;
          this.currentAnimateTimings = null;
          this.currentTime = 0;
          this.collectedStyles = {};
          this.options = null;
      }
  }
  if (false) {
      /** @type {?} */
      AnimationAstBuilderContext.prototype.queryCount;
      /** @type {?} */
      AnimationAstBuilderContext.prototype.depCount;
      /** @type {?} */
      AnimationAstBuilderContext.prototype.currentTransition;
      /** @type {?} */
      AnimationAstBuilderContext.prototype.currentQuery;
      /** @type {?} */
      AnimationAstBuilderContext.prototype.currentQuerySelector;
      /** @type {?} */
      AnimationAstBuilderContext.prototype.currentAnimateTimings;
      /** @type {?} */
      AnimationAstBuilderContext.prototype.currentTime;
      /** @type {?} */
      AnimationAstBuilderContext.prototype.collectedStyles;
      /** @type {?} */
      AnimationAstBuilderContext.prototype.options;
      /** @type {?} */
      AnimationAstBuilderContext.prototype.errors;
  }
  /**
   * @param {?} styles
   * @return {?}
   */
  function consumeOffset(styles) {
      if (typeof styles == 'string')
          return null;
      /** @type {?} */
      let offset = null;
      if (Array.isArray(styles)) {
          styles.forEach((/**
           * @param {?} styleTuple
           * @return {?}
           */
          styleTuple => {
              if (isObject(styleTuple) && styleTuple.hasOwnProperty('offset')) {
                  /** @type {?} */
                  const obj = (/** @type {?} */ (styleTuple));
                  offset = parseFloat((/** @type {?} */ (obj['offset'])));
                  delete obj['offset'];
              }
          }));
      }
      else if (isObject(styles) && styles.hasOwnProperty('offset')) {
          /** @type {?} */
          const obj = (/** @type {?} */ (styles));
          offset = parseFloat((/** @type {?} */ (obj['offset'])));
          delete obj['offset'];
      }
      return offset;
  }
  /**
   * @param {?} value
   * @return {?}
   */
  function isObject(value) {
      return !Array.isArray(value) && typeof value == 'object';
  }
  /**
   * @param {?} value
   * @param {?} errors
   * @return {?}
   */
  function constructTimingAst(value, errors) {
      /** @type {?} */
      let timings = null;
      if (value.hasOwnProperty('duration')) {
          timings = (/** @type {?} */ (value));
      }
      else if (typeof value == 'number') {
          /** @type {?} */
          const duration = resolveTiming((/** @type {?} */ (value)), errors).duration;
          return makeTimingAst((/** @type {?} */ (duration)), 0, '');
      }
      /** @type {?} */
      const strValue = (/** @type {?} */ (value));
      /** @type {?} */
      const isDynamic = strValue.split(/\s+/).some((/**
       * @param {?} v
       * @return {?}
       */
      v => v.charAt(0) == '{' && v.charAt(1) == '{'));
      if (isDynamic) {
          /** @type {?} */
          const ast = (/** @type {?} */ (makeTimingAst(0, 0, '')));
          ast.dynamic = true;
          ast.strValue = strValue;
          return (/** @type {?} */ (ast));
      }
      timings = timings || resolveTiming(strValue, errors);
      return makeTimingAst(timings.duration, timings.delay, timings.easing);
  }
  /**
   * @param {?} options
   * @return {?}
   */
  function normalizeAnimationOptions(options) {
      if (options) {
          options = copyObj(options);
          if (options['params']) {
              options['params'] = (/** @type {?} */ (normalizeParams(options['params'])));
          }
      }
      else {
          options = {};
      }
      return options;
  }
  /**
   * @param {?} duration
   * @param {?} delay
   * @param {?} easing
   * @return {?}
   */
  function makeTimingAst(duration, delay, easing) {
      return { duration, delay, easing };
  }
  
  /**
   * @fileoverview added by tsickle
   * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
   */
  /**
   * @record
   */
  function AnimationTimelineInstruction() { }
  if (false) {
      /** @type {?} */
      AnimationTimelineInstruction.prototype.element;
      /** @type {?} */
      AnimationTimelineInstruction.prototype.keyframes;
      /** @type {?} */
      AnimationTimelineInstruction.prototype.preStyleProps;
      /** @type {?} */
      AnimationTimelineInstruction.prototype.postStyleProps;
      /** @type {?} */
      AnimationTimelineInstruction.prototype.duration;
      /** @type {?} */
      AnimationTimelineInstruction.prototype.delay;
      /** @type {?} */
      AnimationTimelineInstruction.prototype.totalTime;
      /** @type {?} */
      AnimationTimelineInstruction.prototype.easing;
      /** @type {?|undefined} */
      AnimationTimelineInstruction.prototype.stretchStartingKeyframe;
      /** @type {?} */
      AnimationTimelineInstruction.prototype.subTimeline;
  }
  /**
   * @param {?} element
   * @param {?} keyframes
   * @param {?} preStyleProps
   * @param {?} postStyleProps
   * @param {?} duration
   * @param {?} delay
   * @param {?=} easing
   * @param {?=} subTimeline
   * @return {?}
   */
  function createTimelineInstruction(element, keyframes, preStyleProps, postStyleProps, duration, delay, easing = null, subTimeline = false) {
      return {
          type: 1 /* TimelineAnimation */,
          element,
          keyframes,
          preStyleProps,
          postStyleProps,
          duration,
          delay,
          totalTime: duration + delay, easing, subTimeline
      };
  }
  
  /**
   * @fileoverview added by tsickle
   * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
   */
  class ElementInstructionMap {
      constructor() {
          this._map = new Map();
      }
      /**
       * @param {?} element
       * @return {?}
       */
      consume(element) {
          /** @type {?} */
          let instructions = this._map.get(element);
          if (instructions) {
              this._map.delete(element);
          }
          else {
              instructions = [];
          }
          return instructions;
      }
      /**
       * @param {?} element
       * @param {?} instructions
       * @return {?}
       */
      append(element, instructions) {
          /** @type {?} */
          let existingInstructions = this._map.get(element);
          if (!existingInstructions) {
              this._map.set(element, existingInstructions = []);
          }
          existingInstructions.push(...instructions);
      }
      /**
       * @param {?} element
       * @return {?}
       */
      has(element) { return this._map.has(element); }
      /**
       * @return {?}
       */
      clear() { this._map.clear(); }
  }
  if (false) {
      /**
       * @type {?}
       * @private
       */
      ElementInstructionMap.prototype._map;
  }
  
  /**
   * @fileoverview added by tsickle
   * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
   */
  /** @type {?} */
  const ONE_FRAME_IN_MILLISECONDS = 1;
  /** @type {?} */
  const ENTER_TOKEN = ':enter';
  /** @type {?} */
  const ENTER_TOKEN_REGEX = new RegExp(ENTER_TOKEN, 'g');
  /** @type {?} */
  const LEAVE_TOKEN = ':leave';
  /** @type {?} */
  const LEAVE_TOKEN_REGEX = new RegExp(LEAVE_TOKEN, 'g');
  /*
   * The code within this file aims to generate web-animations-compatible keyframes from Angular's
   * animation DSL code.
   *
   * The code below will be converted from:
   *
   * ```
   * sequence([
   *   style({ opacity: 0 }),
   *   animate(1000, style({ opacity: 0 }))
   * ])
   * ```
   *
   * To:
   * ```
   * keyframes = [{ opacity: 0, offset: 0 }, { opacity: 1, offset: 1 }]
   * duration = 1000
   * delay = 0
   * easing = ''
   * ```
   *
   * For this operation to cover the combination of animation verbs (style, animate, group, etc...) a
   * combination of prototypical inheritance, AST traversal and merge-sort-like algorithms are used.
   *
   * [AST Traversal]
   * Each of the animation verbs, when executed, will return an string-map object representing what
   * type of action it is (style, animate, group, etc...) and the data associated with it. This means
   * that when functional composition mix of these functions is evaluated (like in the example above)
   * then it will end up producing a tree of objects representing the animation itself.
   *
   * When this animation object tree is processed by the visitor code below it will visit each of the
   * verb statements within the visitor. And during each visit it will build the context of the
   * animation keyframes by interacting with the `TimelineBuilder`.
   *
   * [TimelineBuilder]
   * This class is responsible for tracking the styles and building a series of keyframe objects for a
   * timeline between a start and end time. The builder starts off with an initial timeline and each
   * time the AST comes across a `group()`, `keyframes()` or a combination of the two wihtin a
   * `sequence()` then it will generate a sub timeline for each step as well as a new one after
   * they are complete.
   *
   * As the AST is traversed, the timing state on each of the timelines will be incremented. If a sub
   * timeline was created (based on one of the cases above) then the parent timeline will attempt to
   * merge the styles used within the sub timelines into itself (only with group() this will happen).
   * This happens with a merge operation (much like how the merge works in mergesort) and it will only
   * copy the most recently used styles from the sub timelines into the parent timeline. This ensures
   * that if the styles are used later on in another phase of the animation then they will be the most
   * up-to-date values.
   *
   * [How Missing Styles Are Updated]
   * Each timeline has a `backFill` property which is responsible for filling in new styles into
   * already processed keyframes if a new style shows up later within the animation sequence.
   *
   * ```
   * sequence([
   *   style({ width: 0 }),
   *   animate(1000, style({ width: 100 })),
   *   animate(1000, style({ width: 200 })),
   *   animate(1000, style({ width: 300 }))
   *   animate(1000, style({ width: 400, height: 400 })) // notice how `height` doesn't exist anywhere
   * else
   * ])
   * ```
   *
   * What is happening here is that the `height` value is added later in the sequence, but is missing
   * from all previous animation steps. Therefore when a keyframe is created it would also be missing
   * from all previous keyframes up until where it is first used. For the timeline keyframe generation
   * to properly fill in the style it will place the previous value (the value from the parent
   * timeline) or a default value of `*` into the backFill object. Given that each of the keyframe
   * styles are objects that prototypically inhert from the backFill object, this means that if a
   * value is added into the backFill then it will automatically propagate any missing values to all
   * keyframes. Therefore the missing `height` value will be properly filled into the already
   * processed keyframes.
   *
   * When a sub-timeline is created it will have its own backFill property. This is done so that
   * styles present within the sub-timeline do not accidentally seep into the previous/future timeline
   * keyframes
   *
   * (For prototypically-inherited contents to be detected a `for(i in obj)` loop must be used.)
   *
   * [Validation]
   * The code in this file is not responsible for validation. That functionality happens with within
   * the `AnimationValidatorVisitor` code.
   */
  /**
   * @param {?} driver
   * @param {?} rootElement
   * @param {?} ast
   * @param {?} enterClassName
   * @param {?} leaveClassName
   * @param {?=} startingStyles
   * @param {?=} finalStyles
   * @param {?=} options
   * @param {?=} subInstructions
   * @param {?=} errors
   * @return {?}
   */
  function buildAnimationTimelines(driver, rootElement, ast, enterClassName, leaveClassName, startingStyles = {}, finalStyles = {}, options, subInstructions, errors = []) {
      return new AnimationTimelineBuilderVisitor().buildKeyframes(driver, rootElement, ast, enterClassName, leaveClassName, startingStyles, finalStyles, options, subInstructions, errors);
  }
  class AnimationTimelineBuilderVisitor {
      /**
       * @param {?} driver
       * @param {?} rootElement
       * @param {?} ast
       * @param {?} enterClassName
       * @param {?} leaveClassName
       * @param {?} startingStyles
       * @param {?} finalStyles
       * @param {?} options
       * @param {?=} subInstructions
       * @param {?=} errors
       * @return {?}
       */
      buildKeyframes(driver, rootElement, ast, enterClassName, leaveClassName, startingStyles, finalStyles, options, subInstructions, errors = []) {
          subInstructions = subInstructions || new ElementInstructionMap();
          /** @type {?} */
          const context = new AnimationTimelineContext(driver, rootElement, subInstructions, enterClassName, leaveClassName, errors, []);
          context.options = options;
          context.currentTimeline.setStyles([startingStyles], null, context.errors, options);
          visitDslNode(this, ast, context);
          // this checks to see if an actual animation happened
          /** @type {?} */
          const timelines = context.timelines.filter((/**
           * @param {?} timeline
           * @return {?}
           */
          timeline => timeline.containsAnimation()));
          if (timelines.length && Object.keys(finalStyles).length) {
              /** @type {?} */
              const tl = timelines[timelines.length - 1];
              if (!tl.allowOnlyTimelineStyles()) {
                  tl.setStyles([finalStyles], null, context.errors, options);
              }
          }
          return timelines.length ? timelines.map((/**
           * @param {?} timeline
           * @return {?}
           */
          timeline => timeline.buildKeyframes())) :
              [createTimelineInstruction(rootElement, [], [], [], 0, 0, '', false)];
      }
      /**
       * @param {?} ast
       * @param {?} context
       * @return {?}
       */
      visitTrigger(ast, context) {
          // these values are not visited in this AST
      }
      /**
       * @param {?} ast
       * @param {?} context
       * @return {?}
       */
      visitState(ast, context) {
          // these values are not visited in this AST
      }
      /**
       * @param {?} ast
       * @param {?} context
       * @return {?}
       */
      visitTransition(ast, context) {
          // these values are not visited in this AST
      }
      /**
       * @param {?} ast
       * @param {?} context
       * @return {?}
       */
      visitAnimateChild(ast, context) {
          /** @type {?} */
          const elementInstructions = context.subInstructions.consume(context.element);
          if (elementInstructions) {
              /** @type {?} */
              const innerContext = context.createSubContext(ast.options);
              /** @type {?} */
              const startTime = context.currentTimeline.currentTime;
              /** @type {?} */
              const endTime = this._visitSubInstructions(elementInstructions, innerContext, (/** @type {?} */ (innerContext.options)));
              if (startTime != endTime) {
                  // we do this on the upper context because we created a sub context for
                  // the sub child animations
                  context.transformIntoNewTimeline(endTime);
              }
          }
          context.previousNode = ast;
      }
      /**
       * @param {?} ast
       * @param {?} context
       * @return {?}
       */
      visitAnimateRef(ast, context) {
          /** @type {?} */
          const innerContext = context.createSubContext(ast.options);
          innerContext.transformIntoNewTimeline();
          this.visitReference(ast.animation, innerContext);
          context.transformIntoNewTimeline(innerContext.currentTimeline.currentTime);
          context.previousNode = ast;
      }
      /**
       * @private
       * @param {?} instructions
       * @param {?} context
       * @param {?} options
       * @return {?}
       */
      _visitSubInstructions(instructions, context, options) {
          /** @type {?} */
          const startTime = context.currentTimeline.currentTime;
          /** @type {?} */
          let furthestTime = startTime;
          // this is a special-case for when a user wants to skip a sub
          // animation from being fired entirely.
          /** @type {?} */
          const duration = options.duration != null ? resolveTimingValue(options.duration) : null;
          /** @type {?} */
          const delay = options.delay != null ? resolveTimingValue(options.delay) : null;
          if (duration !== 0) {
              instructions.forEach((/**
               * @param {?} instruction
               * @return {?}
               */
              instruction => {
                  /** @type {?} */
                  const instructionTimings = context.appendInstructionToTimeline(instruction, duration, delay);
                  furthestTime =
                      Math.max(furthestTime, instructionTimings.duration + instructionTimings.delay);
              }));
          }
          return furthestTime;
      }
      /**
       * @param {?} ast
       * @param {?} context
       * @return {?}
       */
      visitReference(ast, context) {
          context.updateOptions(ast.options, true);
          visitDslNode(this, ast.animation, context);
          context.previousNode = ast;
      }
      /**
       * @param {?} ast
       * @param {?} context
       * @return {?}
       */
      visitSequence(ast, context) {
          /** @type {?} */
          const subContextCount = context.subContextCount;
          /** @type {?} */
          let ctx = context;
          /** @type {?} */
          const options = ast.options;
          if (options && (options.params || options.delay)) {
              ctx = context.createSubContext(options);
              ctx.transformIntoNewTimeline();
              if (options.delay != null) {
                  if (ctx.previousNode.type == 6 /* Style */) {
                      ctx.currentTimeline.snapshotCurrentStyles();
                      ctx.previousNode = DEFAULT_NOOP_PREVIOUS_NODE;
                  }
                  /** @type {?} */
                  const delay = resolveTimingValue(options.delay);
                  ctx.delayNextStep(delay);
              }
          }
          if (ast.steps.length) {
              ast.steps.forEach((/**
               * @param {?} s
               * @return {?}
               */
              s => visitDslNode(this, s, ctx)));
              // this is here just incase the inner steps only contain or end with a style() call
              ctx.currentTimeline.applyStylesToKeyframe();
              // this means that some animation function within the sequence
              // ended up creating a sub timeline (which means the current
              // timeline cannot overlap with the contents of the sequence)
              if (ctx.subContextCount > subContextCount) {
                  ctx.transformIntoNewTimeline();
              }
          }
          context.previousNode = ast;
      }
      /**
       * @param {?} ast
       * @param {?} context
       * @return {?}
       */
      visitGroup(ast, context) {
          /** @type {?} */
          const innerTimelines = [];
          /** @type {?} */
          let furthestTime = context.currentTimeline.currentTime;
          /** @type {?} */
          const delay = ast.options && ast.options.delay ? resolveTimingValue(ast.options.delay) : 0;
          ast.steps.forEach((/**
           * @param {?} s
           * @return {?}
           */
          s => {
              /** @type {?} */
              const innerContext = context.createSubContext(ast.options);
              if (delay) {
                  innerContext.delayNextStep(delay);
              }
              visitDslNode(this, s, innerContext);
              furthestTime = Math.max(furthestTime, innerContext.currentTimeline.currentTime);
              innerTimelines.push(innerContext.currentTimeline);
          }));
          // this operation is run after the AST loop because otherwise
          // if the parent timeline's collected styles were updated then
          // it would pass in invalid data into the new-to-be forked items
          innerTimelines.forEach((/**
           * @param {?} timeline
           * @return {?}
           */
          timeline => context.currentTimeline.mergeTimelineCollectedStyles(timeline)));
          context.transformIntoNewTimeline(furthestTime);
          context.previousNode = ast;
      }
      /**
       * @private
       * @param {?} ast
       * @param {?} context
       * @return {?}
       */
      _visitTiming(ast, context) {
          if (((/** @type {?} */ (ast))).dynamic) {
              /** @type {?} */
              const strValue = ((/** @type {?} */ (ast))).strValue;
              /** @type {?} */
              const timingValue = context.params ? interpolateParams(strValue, context.params, context.errors) : strValue;
              return resolveTiming(timingValue, context.errors);
          }
          else {
              return { duration: ast.duration, delay: ast.delay, easing: ast.easing };
          }
      }
      /**
       * @param {?} ast
       * @param {?} context
       * @return {?}
       */
      visitAnimate(ast, context) {
          /** @type {?} */
          const timings = context.currentAnimateTimings = this._visitTiming(ast.timings, context);
          /** @type {?} */
          const timeline = context.currentTimeline;
          if (timings.delay) {
              context.incrementTime(timings.delay);
              timeline.snapshotCurrentStyles();
          }
          /** @type {?} */
          const style = ast.style;
          if (style.type == 5 /* Keyframes */) {
              this.visitKeyframes(style, context);
          }
          else {
              context.incrementTime(timings.duration);
              this.visitStyle((/** @type {?} */ (style)), context);
              timeline.applyStylesToKeyframe();
          }
          context.currentAnimateTimings = null;
          context.previousNode = ast;
      }
      /**
       * @param {?} ast
       * @param {?} context
       * @return {?}
       */
      visitStyle(ast, context) {
          /** @type {?} */
          const timeline = context.currentTimeline;
          /** @type {?} */
          const timings = (/** @type {?} */ (context.currentAnimateTimings));
          // this is a special case for when a style() call
          // directly follows  an animate() call (but not inside of an animate() call)
          if (!timings && timeline.getCurrentStyleProperties().length) {
              timeline.forwardFrame();
          }
          /** @type {?} */
          const easing = (timings && timings.easing) || ast.easing;
          if (ast.isEmptyStep) {
              timeline.applyEmptyStep(easing);
          }
          else {
              timeline.setStyles(ast.styles, easing, context.errors, context.options);
          }
          context.previousNode = ast;
      }
      /**
       * @param {?} ast
       * @param {?} context
       * @return {?}
       */
      visitKeyframes(ast, context) {
          /** @type {?} */
          const currentAnimateTimings = (/** @type {?} */ (context.currentAnimateTimings));
          /** @type {?} */
          const startTime = ((/** @type {?} */ (context.currentTimeline))).duration;
          /** @type {?} */
          const duration = currentAnimateTimings.duration;
          /** @type {?} */
          const innerContext = context.createSubContext();
          /** @type {?} */
          const innerTimeline = innerContext.currentTimeline;
          innerTimeline.easing = currentAnimateTimings.easing;
          ast.styles.forEach((/**
           * @param {?} step
           * @return {?}
           */
          step => {
              /** @type {?} */
              const offset = step.offset || 0;
              innerTimeline.forwardTime(offset * duration);
              innerTimeline.setStyles(step.styles, step.easing, context.errors, context.options);
              innerTimeline.applyStylesToKeyframe();
          }));
          // this will ensure that the parent timeline gets all the styles from
          // the child even if the new timeline below is not used
          context.currentTimeline.mergeTimelineCollectedStyles(innerTimeline);
          // we do this because the window between this timeline and the sub timeline
          // should ensure that the styles within are exactly the same as they were before
          context.transformIntoNewTimeline(startTime + duration);
          context.previousNode = ast;
      }
      /**
       * @param {?} ast
       * @param {?} context
       * @return {?}
       */
      visitQuery(ast, context) {
          // in the event that the first step before this is a style step we need
          // to ensure the styles are applied before the children are animated
          /** @type {?} */
          const startTime = context.currentTimeline.currentTime;
          /** @type {?} */
          const options = (/** @type {?} */ ((ast.options || {})));
          /** @type {?} */
          const delay = options.delay ? resolveTimingValue(options.delay) : 0;
          if (delay && (context.previousNode.type === 6 /* Style */ ||
              (startTime == 0 && context.currentTimeline.getCurrentStyleProperties().length))) {
              context.currentTimeline.snapshotCurrentStyles();
              context.previousNode = DEFAULT_NOOP_PREVIOUS_NODE;
          }
          /** @type {?} */
          let furthestTime = startTime;
          /** @type {?} */
          const elms = context.invokeQuery(ast.selector, ast.originalSelector, ast.limit, ast.includeSelf, options.optional ? true : false, context.errors);
          context.currentQueryTotal = elms.length;
          /** @type {?} */
          let sameElementTimeline = null;
          elms.forEach((/**
           * @param {?} element
           * @param {?} i
           * @return {?}
           */
          (element, i) => {
              context.currentQueryIndex = i;
              /** @type {?} */
              const innerContext = context.createSubContext(ast.options, element);
              if (delay) {
                  innerContext.delayNextStep(delay);
              }
              if (element === context.element) {
                  sameElementTimeline = innerContext.currentTimeline;
              }
              visitDslNode(this, ast.animation, innerContext);
              // this is here just incase the inner steps only contain or end
              // with a style() call (which is here to signal that this is a preparatory
              // call to style an element before it is animated again)
              innerContext.currentTimeline.applyStylesToKeyframe();
              /** @type {?} */
              const endTime = innerContext.currentTimeline.currentTime;
              furthestTime = Math.max(furthestTime, endTime);
          }));
          context.currentQueryIndex = 0;
          context.currentQueryTotal = 0;
          context.transformIntoNewTimeline(furthestTime);
          if (sameElementTimeline) {
              context.currentTimeline.mergeTimelineCollectedStyles(sameElementTimeline);
              context.currentTimeline.snapshotCurrentStyles();
          }
          context.previousNode = ast;
      }
      /**
       * @param {?} ast
       * @param {?} context
       * @return {?}
       */
      visitStagger(ast, context) {
          /** @type {?} */
          const parentContext = (/** @type {?} */ (context.parentContext));
          /** @type {?} */
          const tl = context.currentTimeline;
          /** @type {?} */
          const timings = ast.timings;
          /** @type {?} */
          const duration = Math.abs(timings.duration);
          /** @type {?} */
          const maxTime = duration * (context.currentQueryTotal - 1);
          /** @type {?} */
          let delay = duration * context.currentQueryIndex;
          /** @type {?} */
          let staggerTransformer = timings.duration < 0 ? 'reverse' : timings.easing;
          switch (staggerTransformer) {
              case 'reverse':
                  delay = maxTime - delay;
                  break;
              case 'full':
                  delay = parentContext.currentStaggerTime;
                  break;
          }
          /** @type {?} */
          const timeline = context.currentTimeline;
          if (delay) {
              timeline.delayNextStep(delay);
          }
          /** @type {?} */
          const startingTime = timeline.currentTime;
          visitDslNode(this, ast.animation, context);
          context.previousNode = ast;
          // time = duration + delay
          // the reason why this computation is so complex is because
          // the inner timeline may either have a delay value or a stretched
          // keyframe depending on if a subtimeline is not used or is used.
          parentContext.currentStaggerTime =
              (tl.currentTime - startingTime) + (tl.startTime - parentContext.currentTimeline.startTime);
      }
  }
  /** @type {?} */
  const DEFAULT_NOOP_PREVIOUS_NODE = (/** @type {?} */ ({}));
  class AnimationTimelineContext {
      /**
       * @param {?} _driver
       * @param {?} element
       * @param {?} subInstructions
       * @param {?} _enterClassName
       * @param {?} _leaveClassName
       * @param {?} errors
       * @param {?} timelines
       * @param {?=} initialTimeline
       */
      constructor(_driver, element, subInstructions, _enterClassName, _leaveClassName, errors, timelines, initialTimeline) {
          this._driver = _driver;
          this.element = element;
          this.subInstructions = subInstructions;
          this._enterClassName = _enterClassName;
          this._leaveClassName = _leaveClassName;
          this.errors = errors;
          this.timelines = timelines;
          this.parentContext = null;
          this.currentAnimateTimings = null;
          this.previousNode = DEFAULT_NOOP_PREVIOUS_NODE;
          this.subContextCount = 0;
          this.options = {};
          this.currentQueryIndex = 0;
          this.currentQueryTotal = 0;
          this.currentStaggerTime = 0;
          this.currentTimeline = initialTimeline || new TimelineBuilder(this._driver, element, 0);
          timelines.push(this.currentTimeline);
      }
      /**
       * @return {?}
       */
      get params() { return this.options.params; }
      /**
       * @param {?} options
       * @param {?=} skipIfExists
       * @return {?}
       */
      updateOptions(options, skipIfExists) {
          if (!options)
              return;
          /** @type {?} */
          const newOptions = (/** @type {?} */ (options));
          /** @type {?} */
          let optionsToUpdate = this.options;
          // NOTE: this will get patched up when other animation methods support duration overrides
          if (newOptions.duration != null) {
              ((/** @type {?} */ (optionsToUpdate))).duration = resolveTimingValue(newOptions.duration);
          }
          if (newOptions.delay != null) {
              optionsToUpdate.delay = resolveTimingValue(newOptions.delay);
          }
          /** @type {?} */
          const newParams = newOptions.params;
          if (newParams) {
              /** @type {?} */
              let paramsToUpdate = (/** @type {?} */ (optionsToUpdate.params));
              if (!paramsToUpdate) {
                  paramsToUpdate = this.options.params = {};
              }
              Object.keys(newParams).forEach((/**
               * @param {?} name
               * @return {?}
               */
              name => {
                  if (!skipIfExists || !paramsToUpdate.hasOwnProperty(name)) {
                      paramsToUpdate[name] = interpolateParams(newParams[name], paramsToUpdate, this.errors);
                  }
              }));
          }
      }
      /**
       * @private
       * @return {?}
       */
      _copyOptions() {
          /** @type {?} */
          const options = {};
          if (this.options) {
              /** @type {?} */
              const oldParams = this.options.params;
              if (oldParams) {
                  /** @type {?} */
                  const params = options['params'] = {};
                  Object.keys(oldParams).forEach((/**
                   * @param {?} name
                   * @return {?}
                   */
                  name => { params[name] = oldParams[name]; }));
              }
          }
          return options;
      }
      /**
       * @param {?=} options
       * @param {?=} element
       * @param {?=} newTime
       * @return {?}
       */
      createSubContext(options = null, element, newTime) {
          /** @type {?} */
          const target = element || this.element;
          /** @type {?} */
          const context = new AnimationTimelineContext(this._driver, target, this.subInstructions, this._enterClassName, this._leaveClassName, this.errors, this.timelines, this.currentTimeline.fork(target, newTime || 0));
          context.previousNode = this.previousNode;
          context.currentAnimateTimings = this.currentAnimateTimings;
          context.options = this._copyOptions();
          context.updateOptions(options);
          context.currentQueryIndex = this.currentQueryIndex;
          context.currentQueryTotal = this.currentQueryTotal;
          context.parentContext = this;
          this.subContextCount++;
          return context;
      }
      /**
       * @param {?=} newTime
       * @return {?}
       */
      transformIntoNewTimeline(newTime) {
          this.previousNode = DEFAULT_NOOP_PREVIOUS_NODE;
          this.currentTimeline = this.currentTimeline.fork(this.element, newTime);
          this.timelines.push(this.currentTimeline);
          return this.currentTimeline;
      }
      /**
       * @param {?} instruction
       * @param {?} duration
       * @param {?} delay
       * @return {?}
       */
      appendInstructionToTimeline(instruction, duration, delay) {
          /** @type {?} */
          const updatedTimings = {
              duration: duration != null ? duration : instruction.duration,
              delay: this.currentTimeline.currentTime + (delay != null ? delay : 0) + instruction.delay,
              easing: ''
          };
          /** @type {?} */
          const builder = new SubTimelineBuilder(this._driver, instruction.element, instruction.keyframes, instruction.preStyleProps, instruction.postStyleProps, updatedTimings, instruction.stretchStartingKeyframe);
          this.timelines.push(builder);
          return updatedTimings;
      }
      /**
       * @param {?} time
       * @return {?}
       */
      incrementTime(time) {
          this.currentTimeline.forwardTime(this.currentTimeline.duration + time);
      }
      /**
       * @param {?} delay
       * @return {?}
       */
      delayNextStep(delay) {
          // negative delays are not yet supported
          if (delay > 0) {
              this.currentTimeline.delayNextStep(delay);
          }
      }
      /**
       * @param {?} selector
       * @param {?} originalSelector
       * @param {?} limit
       * @param {?} includeSelf
       * @param {?} optional
       * @param {?} errors
       * @return {?}
       */
      invokeQuery(selector, originalSelector, limit, includeSelf, optional, errors) {
          /** @type {?} */
          let results = [];
          if (includeSelf) {
              results.push(this.element);
          }
          if (selector.length > 0) { // if :self is only used then the selector is empty
              selector = selector.replace(ENTER_TOKEN_REGEX, '.' + this._enterClassName);
              selector = selector.replace(LEAVE_TOKEN_REGEX, '.' + this._leaveClassName);
              /** @type {?} */
              const multi = limit != 1;
              /** @type {?} */
              let elements = this._driver.query(this.element, selector, multi);
              if (limit !== 0) {
                  elements = limit < 0 ? elements.slice(elements.length + limit, elements.length) :
                      elements.slice(0, limit);
              }
              results.push(...elements);
          }
          if (!optional && results.length == 0) {
              errors.push(`\`query("${originalSelector}")\` returned zero elements. (Use \`query("${originalSelector}", { optional: true })\` if you wish to allow this.)`);
          }
          return results;
      }
  }
  if (false) {
      /** @type {?} */
      AnimationTimelineContext.prototype.parentContext;
      /** @type {?} */
      AnimationTimelineContext.prototype.currentTimeline;
      /** @type {?} */
      AnimationTimelineContext.prototype.currentAnimateTimings;
      /** @type {?} */
      AnimationTimelineContext.prototype.previousNode;
      /** @type {?} */
      AnimationTimelineContext.prototype.subContextCount;
      /** @type {?} */
      AnimationTimelineContext.prototype.options;
      /** @type {?} */
      AnimationTimelineContext.prototype.currentQueryIndex;
      /** @type {?} */
      AnimationTimelineContext.prototype.currentQueryTotal;
      /** @type {?} */
      AnimationTimelineContext.prototype.currentStaggerTime;
      /**
       * @type {?}
       * @private
       */
      AnimationTimelineContext.prototype._driver;
      /** @type {?} */
      AnimationTimelineContext.prototype.element;
      /** @type {?} */
      AnimationTimelineContext.prototype.subInstructions;
      /**
       * @type {?}
       * @private
       */
      AnimationTimelineContext.prototype._enterClassName;
      /**
       * @type {?}
       * @private
       */
      AnimationTimelineContext.prototype._leaveClassName;
      /** @type {?} */
      AnimationTimelineContext.prototype.errors;
      /** @type {?} */
      AnimationTimelineContext.prototype.timelines;
  }
  class TimelineBuilder {
      /**
       * @param {?} _driver
       * @param {?} element
       * @param {?} startTime
       * @param {?=} _elementTimelineStylesLookup
       */
      constructor(_driver, element, startTime, _elementTimelineStylesLookup) {
          this._driver = _driver;
          this.element = element;
          this.startTime = startTime;
          this._elementTimelineStylesLookup = _elementTimelineStylesLookup;
          this.duration = 0;
          this._previousKeyframe = {};
          this._currentKeyframe = {};
          this._keyframes = new Map();
          this._styleSummary = {};
          this._pendingStyles = {};
          this._backFill = {};
          this._currentEmptyStepKeyframe = null;
          if (!this._elementTimelineStylesLookup) {
              this._elementTimelineStylesLookup = new Map();
          }
          this._localTimelineStyles = Object.create(this._backFill, {});
          this._globalTimelineStyles = (/** @type {?} */ (this._elementTimelineStylesLookup.get(element)));
          if (!this._globalTimelineStyles) {
              this._globalTimelineStyles = this._localTimelineStyles;
              this._elementTimelineStylesLookup.set(element, this._localTimelineStyles);
          }
          this._loadKeyframe();
      }
      /**
       * @return {?}
       */
      containsAnimation() {
          switch (this._keyframes.size) {
              case 0:
                  return false;
              case 1:
                  return this.getCurrentStyleProperties().length > 0;
              default:
                  return true;
          }
      }
      /**
       * @return {?}
       */
      getCurrentStyleProperties() { return Object.keys(this._currentKeyframe); }
      /**
       * @return {?}
       */
      get currentTime() { return this.startTime + this.duration; }
      /**
       * @param {?} delay
       * @return {?}
       */
      delayNextStep(delay) {
          // in the event that a style() step is placed right before a stagger()
          // and that style() step is the very first style() value in the animation
          // then we need to make a copy of the keyframe [0, copy, 1] so that the delay
          // properly applies the style() values to work with the stagger...
          /** @type {?} */
          const hasPreStyleStep = this._keyframes.size == 1 && Object.keys(this._pendingStyles).length;
          if (this.duration || hasPreStyleStep) {
              this.forwardTime(this.currentTime + delay);
              if (hasPreStyleStep) {
                  this.snapshotCurrentStyles();
              }
          }
          else {
              this.startTime += delay;
          }
      }
      /**
       * @param {?} element
       * @param {?=} currentTime
       * @return {?}
       */
      fork(element, currentTime) {
          this.applyStylesToKeyframe();
          return new TimelineBuilder(this._driver, element, currentTime || this.currentTime, this._elementTimelineStylesLookup);
      }
      /**
       * @private
       * @return {?}
       */
      _loadKeyframe() {
          if (this._currentKeyframe) {
              this._previousKeyframe = this._currentKeyframe;
          }
          this._currentKeyframe = (/** @type {?} */ (this._keyframes.get(this.duration)));
          if (!this._currentKeyframe) {
              this._currentKeyframe = Object.create(this._backFill, {});
              this._keyframes.set(this.duration, this._currentKeyframe);
          }
      }
      /**
       * @return {?}
       */
      forwardFrame() {
          this.duration += ONE_FRAME_IN_MILLISECONDS;
          this._loadKeyframe();
      }
      /**
       * @param {?} time
       * @return {?}
       */
      forwardTime(time) {
          this.applyStylesToKeyframe();
          this.duration = time;
          this._loadKeyframe();
      }
      /**
       * @private
       * @param {?} prop
       * @param {?} value
       * @return {?}
       */
      _updateStyle(prop, value) {
          this._localTimelineStyles[prop] = value;
          this._globalTimelineStyles[prop] = value;
          this._styleSummary[prop] = { time: this.currentTime, value };
      }
      /**
       * @return {?}
       */
      allowOnlyTimelineStyles() { return this._currentEmptyStepKeyframe !== this._currentKeyframe; }
      /**
       * @param {?} easing
       * @return {?}
       */
      applyEmptyStep(easing) {
          if (easing) {
              this._previousKeyframe['easing'] = easing;
          }
          // special case for animate(duration):
          // all missing styles are filled with a `*` value then
          // if any destination styles are filled in later on the same
          // keyframe then they will override the overridden styles
          // We use `_globalTimelineStyles` here because there may be
          // styles in previous keyframes that are not present in this timeline
          Object.keys(this._globalTimelineStyles).forEach((/**
           * @param {?} prop
           * @return {?}
           */
          prop => {
              this._backFill[prop] = this._globalTimelineStyles[prop] || AUTO_STYLE;
              this._currentKeyframe[prop] = AUTO_STYLE;
          }));
          this._currentEmptyStepKeyframe = this._currentKeyframe;
      }
      /**
       * @param {?} input
       * @param {?} easing
       * @param {?} errors
       * @param {?=} options
       * @return {?}
       */
      setStyles(input, easing, errors, options) {
          if (easing) {
              this._previousKeyframe['easing'] = easing;
          }
          /** @type {?} */
          const params = (options && options.params) || {};
          /** @type {?} */
          const styles = flattenStyles(input, this._globalTimelineStyles);
          Object.keys(styles).forEach((/**
           * @param {?} prop
           * @return {?}
           */
          prop => {
              /** @type {?} */
              const val = interpolateParams(styles[prop], params, errors);
              this._pendingStyles[prop] = val;
              if (!this._localTimelineStyles.hasOwnProperty(prop)) {
                  this._backFill[prop] = this._globalTimelineStyles.hasOwnProperty(prop) ?
                      this._globalTimelineStyles[prop] :
                      AUTO_STYLE;
              }
              this._updateStyle(prop, val);
          }));
      }
      /**
       * @return {?}
       */
      applyStylesToKeyframe() {
          /** @type {?} */
          const styles = this._pendingStyles;
          /** @type {?} */
          const props = Object.keys(styles);
          if (props.length == 0)
              return;
          this._pendingStyles = {};
          props.forEach((/**
           * @param {?} prop
           * @return {?}
           */
          prop => {
              /** @type {?} */
              const val = styles[prop];
              this._currentKeyframe[prop] = val;
          }));
          Object.keys(this._localTimelineStyles).forEach((/**
           * @param {?} prop
           * @return {?}
           */
          prop => {
              if (!this._currentKeyframe.hasOwnProperty(prop)) {
                  this._currentKeyframe[prop] = this._localTimelineStyles[prop];
              }
          }));
      }
      /**
       * @return {?}
       */
      snapshotCurrentStyles() {
          Object.keys(this._localTimelineStyles).forEach((/**
           * @param {?} prop
           * @return {?}
           */
          prop => {
              /** @type {?} */
              const val = this._localTimelineStyles[prop];
              this._pendingStyles[prop] = val;
              this._updateStyle(prop, val);
          }));
      }
      /**
       * @return {?}
       */
      getFinalKeyframe() { return this._keyframes.get(this.duration); }
      /**
       * @return {?}
       */
      get properties() {
          /** @type {?} */
          const properties = [];
          for (let prop in this._currentKeyframe) {
              properties.push(prop);
          }
          return properties;
      }
      /**
       * @param {?} timeline
       * @return {?}
       */
      mergeTimelineCollectedStyles(timeline) {
          Object.keys(timeline._styleSummary).forEach((/**
           * @param {?} prop
           * @return {?}
           */
          prop => {
              /** @type {?} */
              const details0 = this._styleSummary[prop];
              /** @type {?} */
              const details1 = timeline._styleSummary[prop];
              if (!details0 || details1.time > details0.time) {
                  this._updateStyle(prop, details1.value);
              }
          }));
      }
      /**
       * @return {?}
       */
      buildKeyframes() {
          this.applyStylesToKeyframe();
          /** @type {?} */
          const preStyleProps = new Set();
          /** @type {?} */
          const postStyleProps = new Set();
          /** @type {?} */
          const isEmpty = this._keyframes.size === 1 && this.duration === 0;
          /** @type {?} */
          let finalKeyframes = [];
          this._keyframes.forEach((/**
           * @param {?} keyframe
           * @param {?} time
           * @return {?}
           */
          (keyframe, time) => {
              /** @type {?} */
              const finalKeyframe = copyStyles(keyframe, true);
              Object.keys(finalKeyframe).forEach((/**
               * @param {?} prop
               * @return {?}
               */
              prop => {
                  /** @type {?} */
                  const value = finalKeyframe[prop];
                  if (value == ɵPRE_STYLE) {
                      preStyleProps.add(prop);
                  }
                  else if (value == AUTO_STYLE) {
                      postStyleProps.add(prop);
                  }
              }));
              if (!isEmpty) {
                  finalKeyframe['offset'] = time / this.duration;
              }
              finalKeyframes.push(finalKeyframe);
          }));
          /** @type {?} */
          const preProps = preStyleProps.size ? iteratorToArray(preStyleProps.values()) : [];
          /** @type {?} */
          const postProps = postStyleProps.size ? iteratorToArray(postStyleProps.values()) : [];
          // special case for a 0-second animation (which is designed just to place styles onscreen)
          if (isEmpty) {
              /** @type {?} */
              const kf0 = finalKeyframes[0];
              /** @type {?} */
              const kf1 = copyObj(kf0);
              kf0['offset'] = 0;
              kf1['offset'] = 1;
              finalKeyframes = [kf0, kf1];
          }
          return createTimelineInstruction(this.element, finalKeyframes, preProps, postProps, this.duration, this.startTime, this.easing, false);
      }
  }
  if (false) {
      /** @type {?} */
      TimelineBuilder.prototype.duration;
      /** @type {?} */
      TimelineBuilder.prototype.easing;
      /**
       * @type {?}
       * @private
       */
      TimelineBuilder.prototype._previousKeyframe;
      /**
       * @type {?}
       * @private
       */
      TimelineBuilder.prototype._currentKeyframe;
      /**
       * @type {?}
       * @private
       */
      TimelineBuilder.prototype._keyframes;
      /**
       * @type {?}
       * @private
       */
      TimelineBuilder.prototype._styleSummary;
      /**
       * @type {?}
       * @private
       */
      TimelineBuilder.prototype._localTimelineStyles;
      /**
       * @type {?}
       * @private
       */
      TimelineBuilder.prototype._globalTimelineStyles;
      /**
       * @type {?}
       * @private
       */
      TimelineBuilder.prototype._pendingStyles;
      /**
       * @type {?}
       * @private
       */
      TimelineBuilder.prototype._backFill;
      /**
       * @type {?}
       * @private
       */
      TimelineBuilder.prototype._currentEmptyStepKeyframe;
      /**
       * @type {?}
       * @private
       */
      TimelineBuilder.prototype._driver;
      /** @type {?} */
      TimelineBuilder.prototype.element;
      /** @type {?} */
      TimelineBuilder.prototype.startTime;
      /**
       * @type {?}
       * @private
       */
      TimelineBuilder.prototype._elementTimelineStylesLookup;
  }
  class SubTimelineBuilder extends TimelineBuilder {
      /**
       * @param {?} driver
       * @param {?} element
       * @param {?} keyframes
       * @param {?} preStyleProps
       * @param {?} postStyleProps
       * @param {?} timings
       * @param {?=} _stretchStartingKeyframe
       */
      constructor(driver, element, keyframes, preStyleProps, postStyleProps, timings, _stretchStartingKeyframe = false) {
          super(driver, element, timings.delay);
          this.element = element;
          this.keyframes = keyframes;
          this.preStyleProps = preStyleProps;
          this.postStyleProps = postStyleProps;
          this._stretchStartingKeyframe = _stretchStartingKeyframe;
          this.timings = { duration: timings.duration, delay: timings.delay, easing: timings.easing };
      }
      /**
       * @return {?}
       */
      containsAnimation() { return this.keyframes.length > 1; }
      /**
       * @return {?}
       */
      buildKeyframes() {
          /** @type {?} */
          let keyframes = this.keyframes;
          let { delay, duration, easing } = this.timings;
          if (this._stretchStartingKeyframe && delay) {
              /** @type {?} */
              const newKeyframes = [];
              /** @type {?} */
              const totalTime = duration + delay;
              /** @type {?} */
              const startingGap = delay / totalTime;
              // the original starting keyframe now starts once the delay is done
              /** @type {?} */
              const newFirstKeyframe = copyStyles(keyframes[0], false);
              newFirstKeyframe['offset'] = 0;
              newKeyframes.push(newFirstKeyframe);
              /** @type {?} */
              const oldFirstKeyframe = copyStyles(keyframes[0], false);
              oldFirstKeyframe['offset'] = roundOffset(startingGap);
              newKeyframes.push(oldFirstKeyframe);
              /*
                      When the keyframe is stretched then it means that the delay before the animation
                      starts is gone. Instead the first keyframe is placed at the start of the animation
                      and it is then copied to where it starts when the original delay is over. This basically
                      means nothing animates during that delay, but the styles are still renderered. For this
                      to work the original offset values that exist in the original keyframes must be "warped"
                      so that they can take the new keyframe + delay into account.
              
                      delay=1000, duration=1000, keyframes = 0 .5 1
              
                      turns into
              
                      delay=0, duration=2000, keyframes = 0 .33 .66 1
                     */
              // offsets between 1 ... n -1 are all warped by the keyframe stretch
              /** @type {?} */
              const limit = keyframes.length - 1;
              for (let i = 1; i <= limit; i++) {
                  /** @type {?} */
                  let kf = copyStyles(keyframes[i], false);
                  /** @type {?} */
                  const oldOffset = (/** @type {?} */ (kf['offset']));
                  /** @type {?} */
                  const timeAtKeyframe = delay + oldOffset * duration;
                  kf['offset'] = roundOffset(timeAtKeyframe / totalTime);
                  newKeyframes.push(kf);
              }
              // the new starting keyframe should be added at the start
              duration = totalTime;
              delay = 0;
              easing = '';
              keyframes = newKeyframes;
          }
          return createTimelineInstruction(this.element, keyframes, this.preStyleProps, this.postStyleProps, duration, delay, easing, true);
      }
  }
  if (false) {
      /** @type {?} */
      SubTimelineBuilder.prototype.timings;
      /** @type {?} */
      SubTimelineBuilder.prototype.element;
      /** @type {?} */
      SubTimelineBuilder.prototype.keyframes;
      /** @type {?} */
      SubTimelineBuilder.prototype.preStyleProps;
      /** @type {?} */
      SubTimelineBuilder.prototype.postStyleProps;
      /**
       * @type {?}
       * @private
       */
      SubTimelineBuilder.prototype._stretchStartingKeyframe;
  }
  /**
   * @param {?} offset
   * @param {?=} decimalPoints
   * @return {?}
   */
  function roundOffset(offset, decimalPoints = 3) {
      /** @type {?} */
      const mult = Math.pow(10, decimalPoints - 1);
      return Math.round(offset * mult) / mult;
  }
  /**
   * @param {?} input
   * @param {?} allStyles
   * @return {?}
   */
  function flattenStyles(input, allStyles) {
      /** @type {?} */
      const styles = {};
      /** @type {?} */
      let allProperties;
      input.forEach((/**
       * @param {?} token
       * @return {?}
       */
      token => {
          if (token === '*') {
              allProperties = allProperties || Object.keys(allStyles);
              allProperties.forEach((/**
               * @param {?} prop
               * @return {?}
               */
              prop => { styles[prop] = AUTO_STYLE; }));
          }
          else {
              copyStyles((/** @type {?} */ (token)), false, styles);
          }
      }));
      return styles;
  }
  
  /**
   * @fileoverview added by tsickle
   * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
   */
  class Animation {
      /**
       * @param {?} _driver
       * @param {?} input
       */
      constructor(_driver, input) {
          this._driver = _driver;
          /** @type {?} */
          const errors = [];
          /** @type {?} */
          const ast = buildAnimationAst(_driver, input, errors);
          if (errors.length) {
              /** @type {?} */
              const errorMessage = `animation validation failed:\n${errors.join("\n")}`;
              throw new Error(errorMessage);
          }
          this._animationAst = ast;
      }
      /**
       * @param {?} element
       * @param {?} startingStyles
       * @param {?} destinationStyles
       * @param {?} options
       * @param {?=} subInstructions
       * @return {?}
       */
      buildTimelines(element, startingStyles, destinationStyles, options, subInstructions) {
          /** @type {?} */
          const start = Array.isArray(startingStyles) ? normalizeStyles(startingStyles) :
              (/** @type {?} */ (startingStyles));
          /** @type {?} */
          const dest = Array.isArray(destinationStyles) ? normalizeStyles(destinationStyles) :
              (/** @type {?} */ (destinationStyles));
          /** @type {?} */
          const errors = [];
          subInstructions = subInstructions || new ElementInstructionMap();
          /** @type {?} */
          const result = buildAnimationTimelines(this._driver, element, this._animationAst, ENTER_CLASSNAME, LEAVE_CLASSNAME, start, dest, options, subInstructions, errors);
          if (errors.length) {
              /** @type {?} */
              const errorMessage = `animation building failed:\n${errors.join("\n")}`;
              throw new Error(errorMessage);
          }
          return result;
      }
  }
  if (false) {
      /**
       * @type {?}
       * @private
       */
      Animation.prototype._animationAst;
      /**
       * @type {?}
       * @private
       */
      Animation.prototype._driver;
  }
  
  /**
   * @fileoverview added by tsickle
   * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
   */
  /**
   * @license
   * Copyright Google Inc. All Rights Reserved.
   *
   * Use of this source code is governed by an MIT-style license that can be
   * found in the LICENSE file at https://angular.io/license
   */
  /**
   * \@publicApi
   * @abstract
   */
  class AnimationStyleNormalizer {
  }
  if (false) {
      /**
       * @abstract
       * @param {?} propertyName
       * @param {?} errors
       * @return {?}
       */
      AnimationStyleNormalizer.prototype.normalizePropertyName = function (propertyName, errors) { };
      /**
       * @abstract
       * @param {?} userProvidedProperty
       * @param {?} normalizedProperty
       * @param {?} value
       * @param {?} errors
       * @return {?}
       */
      AnimationStyleNormalizer.prototype.normalizeStyleValue = function (userProvidedProperty, normalizedProperty, value, errors) { };
  }
  /**
   * \@publicApi
   */
  class NoopAnimationStyleNormalizer {
      /**
       * @param {?} propertyName
       * @param {?} errors
       * @return {?}
       */
      normalizePropertyName(propertyName, errors) { return propertyName; }
      /**
       * @param {?} userProvidedProperty
       * @param {?} normalizedProperty
       * @param {?} value
       * @param {?} errors
       * @return {?}
       */
      normalizeStyleValue(userProvidedProperty, normalizedProperty, value, errors) {
          return (/** @type {?} */ (value));
      }
  }
  
  /**
   * @fileoverview added by tsickle
   * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
   */
  class WebAnimationsStyleNormalizer extends AnimationStyleNormalizer {
      /**
       * @param {?} propertyName
       * @param {?} errors
       * @return {?}
       */
      normalizePropertyName(propertyName, errors) {
          return dashCaseToCamelCase(propertyName);
      }
      /**
       * @param {?} userProvidedProperty
       * @param {?} normalizedProperty
       * @param {?} value
       * @param {?} errors
       * @return {?}
       */
      normalizeStyleValue(userProvidedProperty, normalizedProperty, value, errors) {
          /** @type {?} */
          let unit = '';
          /** @type {?} */
          const strVal = value.toString().trim();
          if (DIMENSIONAL_PROP_MAP[normalizedProperty] && value !== 0 && value !== '0') {
              if (typeof value === 'number') {
                  unit = 'px';
              }
              else {
                  /** @type {?} */
                  const valAndSuffixMatch = value.match(/^[+-]?[\d\.]+([a-z]*)$/);
                  if (valAndSuffixMatch && valAndSuffixMatch[1].length == 0) {
                      errors.push(`Please provide a CSS unit value for ${userProvidedProperty}:${value}`);
                  }
              }
          }
          return strVal + unit;
      }
  }
  const ɵ0$1 = /**
   * @return {?}
   */
  () => makeBooleanMap('width,height,minWidth,minHeight,maxWidth,maxHeight,left,top,bottom,right,fontSize,outlineWidth,outlineOffset,paddingTop,paddingLeft,paddingBottom,paddingRight,marginTop,marginLeft,marginBottom,marginRight,borderRadius,borderWidth,borderTopWidth,borderLeftWidth,borderRightWidth,borderBottomWidth,textIndent,perspective'
      .split(','));
  /** @type {?} */
  const DIMENSIONAL_PROP_MAP = ((ɵ0$1))();
  /**
   * @param {?} keys
   * @return {?}
   */
  function makeBooleanMap(keys) {
      /** @type {?} */
      const map = {};
      keys.forEach((/**
       * @param {?} key
       * @return {?}
       */
      key => map[key] = true));
      return map;
  }
  
  /**
   * @fileoverview added by tsickle
   * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
   */
  /**
   * @record
   */
  function AnimationTransitionInstruction() { }
  if (false) {
      /** @type {?} */
      AnimationTransitionInstruction.prototype.element;
      /** @type {?} */
      AnimationTransitionInstruction.prototype.triggerName;
      /** @type {?} */
      AnimationTransitionInstruction.prototype.isRemovalTransition;
      /** @type {?} */
      AnimationTransitionInstruction.prototype.fromState;
      /** @type {?} */
      AnimationTransitionInstruction.prototype.fromStyles;
      /** @type {?} */
      AnimationTransitionInstruction.prototype.toState;
      /** @type {?} */
      AnimationTransitionInstruction.prototype.toStyles;
      /** @type {?} */
      AnimationTransitionInstruction.prototype.timelines;
      /** @type {?} */
      AnimationTransitionInstruction.prototype.queriedElements;
      /** @type {?} */
      AnimationTransitionInstruction.prototype.preStyleProps;
      /** @type {?} */
      AnimationTransitionInstruction.prototype.postStyleProps;
      /** @type {?} */
      AnimationTransitionInstruction.prototype.totalTime;
      /** @type {?|undefined} */
      AnimationTransitionInstruction.prototype.errors;
  }
  /**
   * @param {?} element
   * @param {?} triggerName
   * @param {?} fromState
   * @param {?} toState
   * @param {?} isRemovalTransition
   * @param {?} fromStyles
   * @param {?} toStyles
   * @param {?} timelines
   * @param {?} queriedElements
   * @param {?} preStyleProps
   * @param {?} postStyleProps
   * @param {?} totalTime
   * @param {?=} errors
   * @return {?}
   */
  function createTransitionInstruction(element, triggerName, fromState, toState, isRemovalTransition, fromStyles, toStyles, timelines, queriedElements, preStyleProps, postStyleProps, totalTime, errors) {
      return {
          type: 0 /* TransitionAnimation */,
          element,
          triggerName,
          isRemovalTransition,
          fromState,
          fromStyles,
          toState,
          toStyles,
          timelines,
          queriedElements,
          preStyleProps,
          postStyleProps,
          totalTime,
          errors
      };
  }
  
  /**
   * @fileoverview added by tsickle
   * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
   */
  /** @type {?} */
  const EMPTY_OBJECT = {};
  class AnimationTransitionFactory {
      /**
       * @param {?} _triggerName
       * @param {?} ast
       * @param {?} _stateStyles
       */
      constructor(_triggerName, ast, _stateStyles) {
          this._triggerName = _triggerName;
          this.ast = ast;
          this._stateStyles = _stateStyles;
      }
      /**
       * @param {?} currentState
       * @param {?} nextState
       * @param {?} element
       * @param {?} params
       * @return {?}
       */
      match(currentState, nextState, element, params) {
          return oneOrMoreTransitionsMatch(this.ast.matchers, currentState, nextState, element, params);
      }
      /**
       * @param {?} stateName
       * @param {?} params
       * @param {?} errors
       * @return {?}
       */
      buildStyles(stateName, params, errors) {
          /** @type {?} */
          const backupStateStyler = this._stateStyles['*'];
          /** @type {?} */
          const stateStyler = this._stateStyles[stateName];
          /** @type {?} */
          const backupStyles = backupStateStyler ? backupStateStyler.buildStyles(params, errors) : {};
          return stateStyler ? stateStyler.buildStyles(params, errors) : backupStyles;
      }
      /**
       * @param {?} driver
       * @param {?} element
       * @param {?} currentState
       * @param {?} nextState
       * @param {?} enterClassName
       * @param {?} leaveClassName
       * @param {?=} currentOptions
       * @param {?=} nextOptions
       * @param {?=} subInstructions
       * @param {?=} skipAstBuild
       * @return {?}
       */
      build(driver, element, currentState, nextState, enterClassName, leaveClassName, currentOptions, nextOptions, subInstructions, skipAstBuild) {
          /** @type {?} */
          const errors = [];
          /** @type {?} */
          const transitionAnimationParams = this.ast.options && this.ast.options.params || EMPTY_OBJECT;
          /** @type {?} */
          const currentAnimationParams = currentOptions && currentOptions.params || EMPTY_OBJECT;
          /** @type {?} */
          const currentStateStyles = this.buildStyles(currentState, currentAnimationParams, errors);
          /** @type {?} */
          const nextAnimationParams = nextOptions && nextOptions.params || EMPTY_OBJECT;
          /** @type {?} */
          const nextStateStyles = this.buildStyles(nextState, nextAnimationParams, errors);
          /** @type {?} */
          const queriedElements = new Set();
          /** @type {?} */
          const preStyleMap = new Map();
          /** @type {?} */
          const postStyleMap = new Map();
          /** @type {?} */
          const isRemoval = nextState === 'void';
          /** @type {?} */
          const animationOptions = { params: Object.assign({}, transitionAnimationParams, nextAnimationParams) };
          /** @type {?} */
          const timelines = skipAstBuild ? [] : buildAnimationTimelines(driver, element, this.ast.animation, enterClassName, leaveClassName, currentStateStyles, nextStateStyles, animationOptions, subInstructions, errors);
          /** @type {?} */
          let totalTime = 0;
          timelines.forEach((/**
           * @param {?} tl
           * @return {?}
           */
          tl => { totalTime = Math.max(tl.duration + tl.delay, totalTime); }));
          if (errors.length) {
              return createTransitionInstruction(element, this._triggerName, currentState, nextState, isRemoval, currentStateStyles, nextStateStyles, [], [], preStyleMap, postStyleMap, totalTime, errors);
          }
          timelines.forEach((/**
           * @param {?} tl
           * @return {?}
           */
          tl => {
              /** @type {?} */
              const elm = tl.element;
              /** @type {?} */
              const preProps = getOrSetAsInMap(preStyleMap, elm, {});
              tl.preStyleProps.forEach((/**
               * @param {?} prop
               * @return {?}
               */
              prop => preProps[prop] = true));
              /** @type {?} */
              const postProps = getOrSetAsInMap(postStyleMap, elm, {});
              tl.postStyleProps.forEach((/**
               * @param {?} prop
               * @return {?}
               */
              prop => postProps[prop] = true));
              if (elm !== element) {
                  queriedElements.add(elm);
              }
          }));
          /** @type {?} */
          const queriedElementsList = iteratorToArray(queriedElements.values());
          return createTransitionInstruction(element, this._triggerName, currentState, nextState, isRemoval, currentStateStyles, nextStateStyles, timelines, queriedElementsList, preStyleMap, postStyleMap, totalTime);
      }
  }
  if (false) {
      /**
       * @type {?}
       * @private
       */
      AnimationTransitionFactory.prototype._triggerName;
      /** @type {?} */
      AnimationTransitionFactory.prototype.ast;
      /**
       * @type {?}
       * @private
       */
      AnimationTransitionFactory.prototype._stateStyles;
  }
  /**
   * @param {?} matchFns
   * @param {?} currentState
   * @param {?} nextState
   * @param {?} element
   * @param {?} params
   * @return {?}
   */
  function oneOrMoreTransitionsMatch(matchFns, currentState, nextState, element, params) {
      return matchFns.some((/**
       * @param {?} fn
       * @return {?}
       */
      fn => fn(currentState, nextState, element, params)));
  }
  class AnimationStateStyles {
      /**
       * @param {?} styles
       * @param {?} defaultParams
       */
      constructor(styles, defaultParams) {
          this.styles = styles;
          this.defaultParams = defaultParams;
      }
      /**
       * @param {?} params
       * @param {?} errors
       * @return {?}
       */
      buildStyles(params, errors) {
          /** @type {?} */
          const finalStyles = {};
          /** @type {?} */
          const combinedParams = copyObj(this.defaultParams);
          Object.keys(params).forEach((/**
           * @param {?} key
           * @return {?}
           */
          key => {
              /** @type {?} */
              const value = params[key];
              if (value != null) {
                  combinedParams[key] = value;
              }
          }));
          this.styles.styles.forEach((/**
           * @param {?} value
           * @return {?}
           */
          value => {
              if (typeof value !== 'string') {
                  /** @type {?} */
                  const styleObj = (/** @type {?} */ (value));
                  Object.keys(styleObj).forEach((/**
                   * @param {?} prop
                   * @return {?}
                   */
                  prop => {
                      /** @type {?} */
                      let val = styleObj[prop];
                      if (val.length > 1) {
                          val = interpolateParams(val, combinedParams, errors);
                      }
                      finalStyles[prop] = val;
                  }));
              }
          }));
          return finalStyles;
      }
  }
  if (false) {
      /**
       * @type {?}
       * @private
       */
      AnimationStateStyles.prototype.styles;
      /**
       * @type {?}
       * @private
       */
      AnimationStateStyles.prototype.defaultParams;
  }
  
  /**
   * @fileoverview added by tsickle
   * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
   */
  /**
   * \@publicApi
   * @param {?} name
   * @param {?} ast
   * @return {?}
   */
  function buildTrigger(name, ast) {
      return new AnimationTrigger(name, ast);
  }
  /**
   * \@publicApi
   */
  class AnimationTrigger {
      /**
       * @param {?} name
       * @param {?} ast
       */
      constructor(name, ast) {
          this.name = name;
          this.ast = ast;
          this.transitionFactories = [];
          this.states = {};
          ast.states.forEach((/**
           * @param {?} ast
           * @return {?}
           */
          ast => {
              /** @type {?} */
              const defaultParams = (ast.options && ast.options.params) || {};
              this.states[ast.name] = new AnimationStateStyles(ast.style, defaultParams);
          }));
          balanceProperties(this.states, 'true', '1');
          balanceProperties(this.states, 'false', '0');
          ast.transitions.forEach((/**
           * @param {?} ast
           * @return {?}
           */
          ast => {
              this.transitionFactories.push(new AnimationTransitionFactory(name, ast, this.states));
          }));
          this.fallbackTransition = createFallbackTransition(name, this.states);
      }
      /**
       * @return {?}
       */
      get containsQueries() { return this.ast.queryCount > 0; }
      /**
       * @param {?} currentState
       * @param {?} nextState
       * @param {?} element
       * @param {?} params
       * @return {?}
       */
      matchTransition(currentState, nextState, element, params) {
          /** @type {?} */
          const entry = this.transitionFactories.find((/**
           * @param {?} f
           * @return {?}
           */
          f => f.match(currentState, nextState, element, params)));
          return entry || null;
      }
      /**
       * @param {?} currentState
       * @param {?} params
       * @param {?} errors
       * @return {?}
       */
      matchStyles(currentState, params, errors) {
          return this.fallbackTransition.buildStyles(currentState, params, errors);
      }
  }
  if (false) {
      /** @type {?} */
      AnimationTrigger.prototype.transitionFactories;
      /** @type {?} */
      AnimationTrigger.prototype.fallbackTransition;
      /** @type {?} */
      AnimationTrigger.prototype.states;
      /** @type {?} */
      AnimationTrigger.prototype.name;
      /** @type {?} */
      AnimationTrigger.prototype.ast;
  }
  /**
   * @param {?} triggerName
   * @param {?} states
   * @return {?}
   */
  function createFallbackTransition(triggerName, states) {
      /** @type {?} */
      const matchers = [(/**
           * @param {?} fromState
           * @param {?} toState
           * @return {?}
           */
          (fromState, toState) => true)];
      /** @type {?} */
      const animation = { type: 2 /* Sequence */, steps: [], options: null };
      /** @type {?} */
      const transition = {
          type: 1 /* Transition */,
          animation,
          matchers,
          options: null,
          queryCount: 0,
          depCount: 0
      };
      return new AnimationTransitionFactory(triggerName, transition, states);
  }
  /**
   * @param {?} obj
   * @param {?} key1
   * @param {?} key2
   * @return {?}
   */
  function balanceProperties(obj, key1, key2) {
      if (obj.hasOwnProperty(key1)) {
          if (!obj.hasOwnProperty(key2)) {
              obj[key2] = obj[key1];
          }
      }
      else if (obj.hasOwnProperty(key2)) {
          obj[key1] = obj[key2];
      }
  }
  
  /**
   * @fileoverview added by tsickle
   * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
   */
  /** @type {?} */
  const EMPTY_INSTRUCTION_MAP = new ElementInstructionMap();
  class TimelineAnimationEngine {
      /**
       * @param {?} bodyNode
       * @param {?} _driver
       * @param {?} _normalizer
       */
      constructor(bodyNode, _driver, _normalizer) {
          this.bodyNode = bodyNode;
          this._driver = _driver;
          this._normalizer = _normalizer;
          this._animations = {};
          this._playersById = {};
          this.players = [];
      }
      /**
       * @param {?} id
       * @param {?} metadata
       * @return {?}
       */
      register(id, metadata) {
          /** @type {?} */
          const errors = [];
          /** @type {?} */
          const ast = buildAnimationAst(this._driver, metadata, errors);
          if (errors.length) {
              throw new Error(`Unable to build the animation due to the following errors: ${errors.join("\n")}`);
          }
          else {
              this._animations[id] = ast;
          }
      }
      /**
       * @private
       * @param {?} i
       * @param {?} preStyles
       * @param {?=} postStyles
       * @return {?}
       */
      _buildPlayer(i, preStyles, postStyles) {
          /** @type {?} */
          const element = i.element;
          /** @type {?} */
          const keyframes = normalizeKeyframes(this._driver, this._normalizer, element, i.keyframes, preStyles, postStyles);
          return this._driver.animate(element, keyframes, i.duration, i.delay, i.easing, [], true);
      }
      /**
       * @param {?} id
       * @param {?} element
       * @param {?=} options
       * @return {?}
       */
      create(id, element, options = {}) {
          /** @type {?} */
          const errors = [];
          /** @type {?} */
          const ast = this._animations[id];
          /** @type {?} */
          let instructions;
          /** @type {?} */
          const autoStylesMap = new Map();
          if (ast) {
              instructions = buildAnimationTimelines(this._driver, element, ast, ENTER_CLASSNAME, LEAVE_CLASSNAME, {}, {}, options, EMPTY_INSTRUCTION_MAP, errors);
              instructions.forEach((/**
               * @param {?} inst
               * @return {?}
               */
              inst => {
                  /** @type {?} */
                  const styles = getOrSetAsInMap(autoStylesMap, inst.element, {});
                  inst.postStyleProps.forEach((/**
                   * @param {?} prop
                   * @return {?}
                   */
                  prop => styles[prop] = null));
              }));
          }
          else {
              errors.push('The requested animation doesn\'t exist or has already been destroyed');
              instructions = [];
          }
          if (errors.length) {
              throw new Error(`Unable to create the animation due to the following errors: ${errors.join("\n")}`);
          }
          autoStylesMap.forEach((/**
           * @param {?} styles
           * @param {?} element
           * @return {?}
           */
          (styles, element) => {
              Object.keys(styles).forEach((/**
               * @param {?} prop
               * @return {?}
               */
              prop => { styles[prop] = this._driver.computeStyle(element, prop, AUTO_STYLE); }));
          }));
          /** @type {?} */
          const players = instructions.map((/**
           * @param {?} i
           * @return {?}
           */
          i => {
              /** @type {?} */
              const styles = autoStylesMap.get(i.element);
              return this._buildPlayer(i, {}, styles);
          }));
          /** @type {?} */
          const player = optimizeGroupPlayer(players);
          this._playersById[id] = player;
          player.onDestroy((/**
           * @return {?}
           */
          () => this.destroy(id)));
          this.players.push(player);
          return player;
      }
      /**
       * @param {?} id
       * @return {?}
       */
      destroy(id) {
          /** @type {?} */
          const player = this._getPlayer(id);
          player.destroy();
          delete this._playersById[id];
          /** @type {?} */
          const index = this.players.indexOf(player);
          if (index >= 0) {
              this.players.splice(index, 1);
          }
      }
      /**
       * @private
       * @param {?} id
       * @return {?}
       */
      _getPlayer(id) {
          /** @type {?} */
          const player = this._playersById[id];
          if (!player) {
              throw new Error(`Unable to find the timeline player referenced by ${id}`);
          }
          return player;
      }
      /**
       * @param {?} id
       * @param {?} element
       * @param {?} eventName
       * @param {?} callback
       * @return {?}
       */
      listen(id, element, eventName, callback) {
          // triggerName, fromState, toState are all ignored for timeline animations
          /** @type {?} */
          const baseEvent = makeAnimationEvent(element, '', '', '');
          listenOnPlayer(this._getPlayer(id), eventName, baseEvent, callback);
          return (/**
           * @return {?}
           */
          () => { });
      }
      /**
       * @param {?} id
       * @param {?} element
       * @param {?} command
       * @param {?} args
       * @return {?}
       */
      command(id, element, command, args) {
          if (command == 'register') {
              this.register(id, (/** @type {?} */ (args[0])));
              return;
          }
          if (command == 'create') {
              /** @type {?} */
              const options = (/** @type {?} */ ((args[0] || {})));
              this.create(id, element, options);
              return;
          }
          /** @type {?} */
          const player = this._getPlayer(id);
          switch (command) {
              case 'play':
                  player.play();
                  break;
              case 'pause':
                  player.pause();
                  break;
              case 'reset':
                  player.reset();
                  break;
              case 'restart':
                  player.restart();
                  break;
              case 'finish':
                  player.finish();
                  break;
              case 'init':
                  player.init();
                  break;
              case 'setPosition':
                  player.setPosition(parseFloat((/** @type {?} */ (args[0]))));
                  break;
              case 'destroy':
                  this.destroy(id);
                  break;
          }
      }
  }
  if (false) {
      /**
       * @type {?}
       * @private
       */
      TimelineAnimationEngine.prototype._animations;
      /**
       * @type {?}
       * @private
       */
      TimelineAnimationEngine.prototype._playersById;
      /** @type {?} */
      TimelineAnimationEngine.prototype.players;
      /** @type {?} */
      TimelineAnimationEngine.prototype.bodyNode;
      /**
       * @type {?}
       * @private
       */
      TimelineAnimationEngine.prototype._driver;
      /**
       * @type {?}
       * @private
       */
      TimelineAnimationEngine.prototype._normalizer;
  }
  
  /**
   * @fileoverview added by tsickle
   * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
   */
  /** @type {?} */
  const QUEUED_CLASSNAME = 'ng-animate-queued';
  /** @type {?} */
  const QUEUED_SELECTOR = '.ng-animate-queued';
  /** @type {?} */
  const DISABLED_CLASSNAME = 'ng-animate-disabled';
  /** @type {?} */
  const DISABLED_SELECTOR = '.ng-animate-disabled';
  /** @type {?} */
  const STAR_CLASSNAME = 'ng-star-inserted';
  /** @type {?} */
  const STAR_SELECTOR = '.ng-star-inserted';
  /** @type {?} */
  const EMPTY_PLAYER_ARRAY = [];
  /** @type {?} */
  const NULL_REMOVAL_STATE = {
      namespaceId: '',
      setForRemoval: false,
      setForMove: false,
      hasAnimation: false,
      removedBeforeQueried: false
  };
  /** @type {?} */
  const NULL_REMOVED_QUERIED_STATE = {
      namespaceId: '',
      setForMove: false,
      setForRemoval: false,
      hasAnimation: false,
      removedBeforeQueried: true
  };
  /**
   * @record
   */
  function TriggerListener() { }
  if (false) {
      /** @type {?} */
      TriggerListener.prototype.name;
      /** @type {?} */
      TriggerListener.prototype.phase;
      /** @type {?} */
      TriggerListener.prototype.callback;
  }
  /**
   * @record
   */
  function QueueInstruction() { }
  if (false) {
      /** @type {?} */
      QueueInstruction.prototype.element;
      /** @type {?} */
      QueueInstruction.prototype.triggerName;
      /** @type {?} */
      QueueInstruction.prototype.fromState;
      /** @type {?} */
      QueueInstruction.prototype.toState;
      /** @type {?} */
      QueueInstruction.prototype.transition;
      /** @type {?} */
      QueueInstruction.prototype.player;
      /** @type {?} */
      QueueInstruction.prototype.isFallbackTransition;
  }
  /** @type {?} */
  const REMOVAL_FLAG = '__ng_removed';
  /**
   * @record
   */
  function ElementAnimationState() { }
  if (false) {
      /** @type {?} */
      ElementAnimationState.prototype.setForRemoval;
      /** @type {?} */
      ElementAnimationState.prototype.setForMove;
      /** @type {?} */
      ElementAnimationState.prototype.hasAnimation;
      /** @type {?} */
      ElementAnimationState.prototype.namespaceId;
      /** @type {?} */
      ElementAnimationState.prototype.removedBeforeQueried;
  }
  class StateValue {
      /**
       * @param {?} input
       * @param {?=} namespaceId
       */
      constructor(input, namespaceId = '') {
          this.namespaceId = namespaceId;
          /** @type {?} */
          const isObj = input && input.hasOwnProperty('value');
          /** @type {?} */
          const value = isObj ? input['value'] : input;
          this.value = normalizeTriggerValue(value);
          if (isObj) {
              /** @type {?} */
              const options = copyObj((/** @type {?} */ (input)));
              delete options['value'];
              this.options = (/** @type {?} */ (options));
          }
          else {
              this.options = {};
          }
          if (!this.options.params) {
              this.options.params = {};
          }
      }
      /**
       * @return {?}
       */
      get params() { return (/** @type {?} */ (this.options.params)); }
      /**
       * @param {?} options
       * @return {?}
       */
      absorbOptions(options) {
          /** @type {?} */
          const newParams = options.params;
          if (newParams) {
              /** @type {?} */
              const oldParams = (/** @type {?} */ (this.options.params));
              Object.keys(newParams).forEach((/**
               * @param {?} prop
               * @return {?}
               */
              prop => {
                  if (oldParams[prop] == null) {
                      oldParams[prop] = newParams[prop];
                  }
              }));
          }
      }
  }
  if (false) {
      /** @type {?} */
      StateValue.prototype.value;
      /** @type {?} */
      StateValue.prototype.options;
      /** @type {?} */
      StateValue.prototype.namespaceId;
  }
  /** @type {?} */
  const VOID_VALUE = 'void';
  /** @type {?} */
  const DEFAULT_STATE_VALUE = new StateValue(VOID_VALUE);
  class AnimationTransitionNamespace {
      /**
       * @param {?} id
       * @param {?} hostElement
       * @param {?} _engine
       */
      constructor(id, hostElement, _engine) {
          this.id = id;
          this.hostElement = hostElement;
          this._engine = _engine;
          this.players = [];
          this._triggers = {};
          this._queue = [];
          this._elementListeners = new Map();
          this._hostClassName = 'ng-tns-' + id;
          addClass(hostElement, this._hostClassName);
      }
      /**
       * @param {?} element
       * @param {?} name
       * @param {?} phase
       * @param {?} callback
       * @return {?}
       */
      listen(element, name, phase, callback) {
          if (!this._triggers.hasOwnProperty(name)) {
              throw new Error(`Unable to listen on the animation trigger event "${phase}" because the animation trigger "${name}" doesn\'t exist!`);
          }
          if (phase == null || phase.length == 0) {
              throw new Error(`Unable to listen on the animation trigger "${name}" because the provided event is undefined!`);
          }
          if (!isTriggerEventValid(phase)) {
              throw new Error(`The provided animation trigger event "${phase}" for the animation trigger "${name}" is not supported!`);
          }
          /** @type {?} */
          const listeners = getOrSetAsInMap(this._elementListeners, element, []);
          /** @type {?} */
          const data = { name, phase, callback };
          listeners.push(data);
          /** @type {?} */
          const triggersWithStates = getOrSetAsInMap(this._engine.statesByElement, element, {});
          if (!triggersWithStates.hasOwnProperty(name)) {
              addClass(element, NG_TRIGGER_CLASSNAME);
              addClass(element, NG_TRIGGER_CLASSNAME + '-' + name);
              triggersWithStates[name] = DEFAULT_STATE_VALUE;
          }
          return (/**
           * @return {?}
           */
          () => {
              // the event listener is removed AFTER the flush has occurred such
              // that leave animations callbacks can fire (otherwise if the node
              // is removed in between then the listeners would be deregistered)
              this._engine.afterFlush((/**
               * @return {?}
               */
              () => {
                  /** @type {?} */
                  const index = listeners.indexOf(data);
                  if (index >= 0) {
                      listeners.splice(index, 1);
                  }
                  if (!this._triggers[name]) {
                      delete triggersWithStates[name];
                  }
              }));
          });
      }
      /**
       * @param {?} name
       * @param {?} ast
       * @return {?}
       */
      register(name, ast) {
          if (this._triggers[name]) {
              // throw
              return false;
          }
          else {
              this._triggers[name] = ast;
              return true;
          }
      }
      /**
       * @private
       * @param {?} name
       * @return {?}
       */
      _getTrigger(name) {
          /** @type {?} */
          const trigger = this._triggers[name];
          if (!trigger) {
              throw new Error(`The provided animation trigger "${name}" has not been registered!`);
          }
          return trigger;
      }
      /**
       * @param {?} element
       * @param {?} triggerName
       * @param {?} value
       * @param {?=} defaultToFallback
       * @return {?}
       */
      trigger(element, triggerName, value, defaultToFallback = true) {
          /** @type {?} */
          const trigger = this._getTrigger(triggerName);
          /** @type {?} */
          const player = new TransitionAnimationPlayer(this.id, triggerName, element);
          /** @type {?} */
          let triggersWithStates = this._engine.statesByElement.get(element);
          if (!triggersWithStates) {
              addClass(element, NG_TRIGGER_CLASSNAME);
              addClass(element, NG_TRIGGER_CLASSNAME + '-' + triggerName);
              this._engine.statesByElement.set(element, triggersWithStates = {});
          }
          /** @type {?} */
          let fromState = triggersWithStates[triggerName];
          /** @type {?} */
          const toState = new StateValue(value, this.id);
          /** @type {?} */
          const isObj = value && value.hasOwnProperty('value');
          if (!isObj && fromState) {
              toState.absorbOptions(fromState.options);
          }
          triggersWithStates[triggerName] = toState;
          if (!fromState) {
              fromState = DEFAULT_STATE_VALUE;
          }
          /** @type {?} */
          const isRemoval = toState.value === VOID_VALUE;
          // normally this isn't reached by here, however, if an object expression
          // is passed in then it may be a new object each time. Comparing the value
          // is important since that will stay the same despite there being a new object.
          // The removal arc here is special cased because the same element is triggered
          // twice in the event that it contains animations on the outer/inner portions
          // of the host container
          if (!isRemoval && fromState.value === toState.value) {
              // this means that despite the value not changing, some inner params
              // have changed which means that the animation final styles need to be applied
              if (!objEquals(fromState.params, toState.params)) {
                  /** @type {?} */
                  const errors = [];
                  /** @type {?} */
                  const fromStyles = trigger.matchStyles(fromState.value, fromState.params, errors);
                  /** @type {?} */
                  const toStyles = trigger.matchStyles(toState.value, toState.params, errors);
                  if (errors.length) {
                      this._engine.reportError(errors);
                  }
                  else {
                      this._engine.afterFlush((/**
                       * @return {?}
                       */
                      () => {
                          eraseStyles(element, fromStyles);
                          setStyles(element, toStyles);
                      }));
                  }
              }
              return;
          }
          /** @type {?} */
          const playersOnElement = getOrSetAsInMap(this._engine.playersByElement, element, []);
          playersOnElement.forEach((/**
           * @param {?} player
           * @return {?}
           */
          player => {
              // only remove the player if it is queued on the EXACT same trigger/namespace
              // we only also deal with queued players here because if the animation has
              // started then we want to keep the player alive until the flush happens
              // (which is where the previousPlayers are passed into the new palyer)
              if (player.namespaceId == this.id && player.triggerName == triggerName && player.queued) {
                  player.destroy();
              }
          }));
          /** @type {?} */
          let transition = trigger.matchTransition(fromState.value, toState.value, element, toState.params);
          /** @type {?} */
          let isFallbackTransition = false;
          if (!transition) {
              if (!defaultToFallback)
                  return;
              transition = trigger.fallbackTransition;
              isFallbackTransition = true;
          }
          this._engine.totalQueuedPlayers++;
          this._queue.push({ element, triggerName, transition, fromState, toState, player, isFallbackTransition });
          if (!isFallbackTransition) {
              addClass(element, QUEUED_CLASSNAME);
              player.onStart((/**
               * @return {?}
               */
              () => { removeClass(element, QUEUED_CLASSNAME); }));
          }
          player.onDone((/**
           * @return {?}
           */
          () => {
              /** @type {?} */
              let index = this.players.indexOf(player);
              if (index >= 0) {
                  this.players.splice(index, 1);
              }
              /** @type {?} */
              const players = this._engine.playersByElement.get(element);
              if (players) {
                  /** @type {?} */
                  let index = players.indexOf(player);
                  if (index >= 0) {
                      players.splice(index, 1);
                  }
              }
          }));
          this.players.push(player);
          playersOnElement.push(player);
          return player;
      }
      /**
       * @param {?} name
       * @return {?}
       */
      deregister(name) {
          delete this._triggers[name];
          this._engine.statesByElement.forEach((/**
           * @param {?} stateMap
           * @param {?} element
           * @return {?}
           */
          (stateMap, element) => { delete stateMap[name]; }));
          this._elementListeners.forEach((/**
           * @param {?} listeners
           * @param {?} element
           * @return {?}
           */
          (listeners, element) => {
              this._elementListeners.set(element, listeners.filter((/**
               * @param {?} entry
               * @return {?}
               */
              entry => { return entry.name != name; })));
          }));
      }
      /**
       * @param {?} element
       * @return {?}
       */
      clearElementCache(element) {
          this._engine.statesByElement.delete(element);
          this._elementListeners.delete(element);
          /** @type {?} */
          const elementPlayers = this._engine.playersByElement.get(element);
          if (elementPlayers) {
              elementPlayers.forEach((/**
               * @param {?} player
               * @return {?}
               */
              player => player.destroy()));
              this._engine.playersByElement.delete(element);
          }
      }
      /**
       * @private
       * @param {?} rootElement
       * @param {?} context
       * @param {?=} animate
       * @return {?}
       */
      _signalRemovalForInnerTriggers(rootElement, context, animate = false) {
          // emulate a leave animation for all inner nodes within this node.
          // If there are no animations found for any of the nodes then clear the cache
          // for the element.
          this._engine.driver.query(rootElement, NG_TRIGGER_SELECTOR, true).forEach((/**
           * @param {?} elm
           * @return {?}
           */
          elm => {
              // this means that an inner remove() operation has already kicked off
              // the animation on this element...
              if (elm[REMOVAL_FLAG])
                  return;
              /** @type {?} */
              const namespaces = this._engine.fetchNamespacesByElement(elm);
              if (namespaces.size) {
                  namespaces.forEach((/**
                   * @param {?} ns
                   * @return {?}
                   */
                  ns => ns.triggerLeaveAnimation(elm, context, false, true)));
              }
              else {
                  this.clearElementCache(elm);
              }
          }));
      }
      /**
       * @param {?} element
       * @param {?} context
       * @param {?=} destroyAfterComplete
       * @param {?=} defaultToFallback
       * @return {?}
       */
      triggerLeaveAnimation(element, context, destroyAfterComplete, defaultToFallback) {
          /** @type {?} */
          const triggerStates = this._engine.statesByElement.get(element);
          if (triggerStates) {
              /** @type {?} */
              const players = [];
              Object.keys(triggerStates).forEach((/**
               * @param {?} triggerName
               * @return {?}
               */
              triggerName => {
                  // this check is here in the event that an element is removed
                  // twice (both on the host level and the component level)
                  if (this._triggers[triggerName]) {
                      /** @type {?} */
                      const player = this.trigger(element, triggerName, VOID_VALUE, defaultToFallback);
                      if (player) {
                          players.push(player);
                      }
                  }
              }));
              if (players.length) {
                  this._engine.markElementAsRemoved(this.id, element, true, context);
                  if (destroyAfterComplete) {
                      optimizeGroupPlayer(players).onDone((/**
                       * @return {?}
                       */
                      () => this._engine.processLeaveNode(element)));
                  }
                  return true;
              }
          }
          return false;
      }
      /**
       * @param {?} element
       * @return {?}
       */
      prepareLeaveAnimationListeners(element) {
          /** @type {?} */
          const listeners = this._elementListeners.get(element);
          if (listeners) {
              /** @type {?} */
              const visitedTriggers = new Set();
              listeners.forEach((/**
               * @param {?} listener
               * @return {?}
               */
              listener => {
                  /** @type {?} */
                  const triggerName = listener.name;
                  if (visitedTriggers.has(triggerName))
                      return;
                  visitedTriggers.add(triggerName);
                  /** @type {?} */
                  const trigger = this._triggers[triggerName];
                  /** @type {?} */
                  const transition = trigger.fallbackTransition;
                  /** @type {?} */
                  const elementStates = (/** @type {?} */ (this._engine.statesByElement.get(element)));
                  /** @type {?} */
                  const fromState = elementStates[triggerName] || DEFAULT_STATE_VALUE;
                  /** @type {?} */
                  const toState = new StateValue(VOID_VALUE);
                  /** @type {?} */
                  const player = new TransitionAnimationPlayer(this.id, triggerName, element);
                  this._engine.totalQueuedPlayers++;
                  this._queue.push({
                      element,
                      triggerName,
                      transition,
                      fromState,
                      toState,
                      player,
                      isFallbackTransition: true
                  });
              }));
          }
      }
      /**
       * @param {?} element
       * @param {?} context
       * @return {?}
       */
      removeNode(element, context) {
          /** @type {?} */
          const engine = this._engine;
          if (element.childElementCount) {
              this._signalRemovalForInnerTriggers(element, context, true);
          }
          // this means that a * => VOID animation was detected and kicked off
          if (this.triggerLeaveAnimation(element, context, true))
              return;
          // find the player that is animating and make sure that the
          // removal is delayed until that player has completed
          /** @type {?} */
          let containsPotentialParentTransition = false;
          if (engine.totalAnimations) {
              /** @type {?} */
              const currentPlayers = engine.players.length ? engine.playersByQueriedElement.get(element) : [];
              // when this `if statement` does not continue forward it means that
              // a previous animation query has selected the current element and
              // is animating it. In this situation want to continue forwards and
              // allow the element to be queued up for animation later.
              if (currentPlayers && currentPlayers.length) {
                  containsPotentialParentTransition = true;
              }
              else {
                  /** @type {?} */
                  let parent = element;
                  while (parent = parent.parentNode) {
                      /** @type {?} */
                      const triggers = engine.statesByElement.get(parent);
                      if (triggers) {
                          containsPotentialParentTransition = true;
                          break;
                      }
                  }
              }
          }
          // at this stage we know that the element will either get removed
          // during flush or will be picked up by a parent query. Either way
          // we need to fire the listeners for this element when it DOES get
          // removed (once the query parent animation is done or after flush)
          this.prepareLeaveAnimationListeners(element);
          // whether or not a parent has an animation we need to delay the deferral of the leave
          // operation until we have more information (which we do after flush() has been called)
          if (containsPotentialParentTransition) {
              engine.markElementAsRemoved(this.id, element, false, context);
          }
          else {
              // we do this after the flush has occurred such
              // that the callbacks can be fired
              engine.afterFlush((/**
               * @return {?}
               */
              () => this.clearElementCache(element)));
              engine.destroyInnerAnimations(element);
              engine._onRemovalComplete(element, context);
          }
      }
      /**
       * @param {?} element
       * @param {?} parent
       * @return {?}
       */
      insertNode(element, parent) { addClass(element, this._hostClassName); }
      /**
       * @param {?} microtaskId
       * @return {?}
       */
      drainQueuedTransitions(microtaskId) {
          /** @type {?} */
          const instructions = [];
          this._queue.forEach((/**
           * @param {?} entry
           * @return {?}
           */
          entry => {
              /** @type {?} */
              const player = entry.player;
              if (player.destroyed)
                  return;
              /** @type {?} */
              const element = entry.element;
              /** @type {?} */
              const listeners = this._elementListeners.get(element);
              if (listeners) {
                  listeners.forEach((/**
                   * @param {?} listener
                   * @return {?}
                   */
                  (listener) => {
                      if (listener.name == entry.triggerName) {
                          /** @type {?} */
                          const baseEvent = makeAnimationEvent(element, entry.triggerName, entry.fromState.value, entry.toState.value);
                          ((/** @type {?} */ (baseEvent)))['_data'] = microtaskId;
                          listenOnPlayer(entry.player, listener.phase, baseEvent, listener.callback);
                      }
                  }));
              }
              if (player.markedForDestroy) {
                  this._engine.afterFlush((/**
                   * @return {?}
                   */
                  () => {
                      // now we can destroy the element properly since the event listeners have
                      // been bound to the player
                      player.destroy();
                  }));
              }
              else {
                  instructions.push(entry);
              }
          }));
          this._queue = [];
          return instructions.sort((/**
           * @param {?} a
           * @param {?} b
           * @return {?}
           */
          (a, b) => {
              // if depCount == 0 them move to front
              // otherwise if a contains b then move back
              /** @type {?} */
              const d0 = a.transition.ast.depCount;
              /** @type {?} */
              const d1 = b.transition.ast.depCount;
              if (d0 == 0 || d1 == 0) {
                  return d0 - d1;
              }
              return this._engine.driver.containsElement(a.element, b.element) ? 1 : -1;
          }));
      }
      /**
       * @param {?} context
       * @return {?}
       */
      destroy(context) {
          this.players.forEach((/**
           * @param {?} p
           * @return {?}
           */
          p => p.destroy()));
          this._signalRemovalForInnerTriggers(this.hostElement, context);
      }
      /**
       * @param {?} element
       * @return {?}
       */
      elementContainsData(element) {
          /** @type {?} */
          let containsData = false;
          if (this._elementListeners.has(element))
              containsData = true;
          containsData =
              (this._queue.find((/**
               * @param {?} entry
               * @return {?}
               */
              entry => entry.element === element)) ? true : false) || containsData;
          return containsData;
      }
  }
  if (false) {
      /** @type {?} */
      AnimationTransitionNamespace.prototype.players;
      /**
       * @type {?}
       * @private
       */
      AnimationTransitionNamespace.prototype._triggers;
      /**
       * @type {?}
       * @private
       */
      AnimationTransitionNamespace.prototype._queue;
      /**
       * @type {?}
       * @private
       */
      AnimationTransitionNamespace.prototype._elementListeners;
      /**
       * @type {?}
       * @private
       */
      AnimationTransitionNamespace.prototype._hostClassName;
      /** @type {?} */
      AnimationTransitionNamespace.prototype.id;
      /** @type {?} */
      AnimationTransitionNamespace.prototype.hostElement;
      /**
       * @type {?}
       * @private
       */
      AnimationTransitionNamespace.prototype._engine;
  }
  /**
   * @record
   */
  function QueuedTransition() { }
  if (false) {
      /** @type {?} */
      QueuedTransition.prototype.element;
      /** @type {?} */
      QueuedTransition.prototype.instruction;
      /** @type {?} */
      QueuedTransition.prototype.player;
  }
  class TransitionAnimationEngine {
      /**
       * @param {?} bodyNode
       * @param {?} driver
       * @param {?} _normalizer
       */
      constructor(bodyNode, driver, _normalizer) {
          this.bodyNode = bodyNode;
          this.driver = driver;
          this._normalizer = _normalizer;
          this.players = [];
          this.newHostElements = new Map();
          this.playersByElement = new Map();
          this.playersByQueriedElement = new Map();
          this.statesByElement = new Map();
          this.disabledNodes = new Set();
          this.totalAnimations = 0;
          this.totalQueuedPlayers = 0;
          this._namespaceLookup = {};
          this._namespaceList = [];
          this._flushFns = [];
          this._whenQuietFns = [];
          this.namespacesByHostElement = new Map();
          this.collectedEnterElements = [];
          this.collectedLeaveElements = [];
          // this method is designed to be overridden by the code that uses this engine
          this.onRemovalComplete = (/**
           * @param {?} element
           * @param {?} context
           * @return {?}
           */
          (element, context) => { });
      }
      /**
       * \@internal
       * @param {?} element
       * @param {?} context
       * @return {?}
       */
      _onRemovalComplete(element, context) { this.onRemovalComplete(element, context); }
      /**
       * @return {?}
       */
      get queuedPlayers() {
          /** @type {?} */
          const players = [];
          this._namespaceList.forEach((/**
           * @param {?} ns
           * @return {?}
           */
          ns => {
              ns.players.forEach((/**
               * @param {?} player
               * @return {?}
               */
              player => {
                  if (player.queued) {
                      players.push(player);
                  }
              }));
          }));
          return players;
      }
      /**
       * @param {?} namespaceId
       * @param {?} hostElement
       * @return {?}
       */
      createNamespace(namespaceId, hostElement) {
          /** @type {?} */
          const ns = new AnimationTransitionNamespace(namespaceId, hostElement, this);
          if (hostElement.parentNode) {
              this._balanceNamespaceList(ns, hostElement);
          }
          else {
              // defer this later until flush during when the host element has
              // been inserted so that we know exactly where to place it in
              // the namespace list
              this.newHostElements.set(hostElement, ns);
              // given that this host element is apart of the animation code, it
              // may or may not be inserted by a parent node that is an of an
              // animation renderer type. If this happens then we can still have
              // access to this item when we query for :enter nodes. If the parent
              // is a renderer then the set data-structure will normalize the entry
              this.collectEnterElement(hostElement);
          }
          return this._namespaceLookup[namespaceId] = ns;
      }
      /**
       * @private
       * @param {?} ns
       * @param {?} hostElement
       * @return {?}
       */
      _balanceNamespaceList(ns, hostElement) {
          /** @type {?} */
          const limit = this._namespaceList.length - 1;
          if (limit >= 0) {
              /** @type {?} */
              let found = false;
              for (let i = limit; i >= 0; i--) {
                  /** @type {?} */
                  const nextNamespace = this._namespaceList[i];
                  if (this.driver.containsElement(nextNamespace.hostElement, hostElement)) {
                      this._namespaceList.splice(i + 1, 0, ns);
                      found = true;
                      break;
                  }
              }
              if (!found) {
                  this._namespaceList.splice(0, 0, ns);
              }
          }
          else {
              this._namespaceList.push(ns);
          }
          this.namespacesByHostElement.set(hostElement, ns);
          return ns;
      }
      /**
       * @param {?} namespaceId
       * @param {?} hostElement
       * @return {?}
       */
      register(namespaceId, hostElement) {
          /** @type {?} */
          let ns = this._namespaceLookup[namespaceId];
          if (!ns) {
              ns = this.createNamespace(namespaceId, hostElement);
          }
          return ns;
      }
      /**
       * @param {?} namespaceId
       * @param {?} name
       * @param {?} trigger
       * @return {?}
       */
      registerTrigger(namespaceId, name, trigger) {
          /** @type {?} */
          let ns = this._namespaceLookup[namespaceId];
          if (ns && ns.register(name, trigger)) {
              this.totalAnimations++;
          }
      }
      /**
       * @param {?} namespaceId
       * @param {?} context
       * @return {?}
       */
      destroy(namespaceId, context) {
          if (!namespaceId)
              return;
          /** @type {?} */
          const ns = this._fetchNamespace(namespaceId);
          this.afterFlush((/**
           * @return {?}
           */
          () => {
              this.namespacesByHostElement.delete(ns.hostElement);
              delete this._namespaceLookup[namespaceId];
              /** @type {?} */
              const index = this._namespaceList.indexOf(ns);
              if (index >= 0) {
                  this._namespaceList.splice(index, 1);
              }
          }));
          this.afterFlushAnimationsDone((/**
           * @return {?}
           */
          () => ns.destroy(context)));
      }
      /**
       * @private
       * @param {?} id
       * @return {?}
       */
      _fetchNamespace(id) { return this._namespaceLookup[id]; }
      /**
       * @param {?} element
       * @return {?}
       */
      fetchNamespacesByElement(element) {
          // normally there should only be one namespace per element, however
          // if @triggers are placed on both the component element and then
          // its host element (within the component code) then there will be
          // two namespaces returned. We use a set here to simply the dedupe
          // of namespaces incase there are multiple triggers both the elm and host
          /** @type {?} */
          const namespaces = new Set();
          /** @type {?} */
          const elementStates = this.statesByElement.get(element);
          if (elementStates) {
              /** @type {?} */
              const keys = Object.keys(elementStates);
              for (let i = 0; i < keys.length; i++) {
                  /** @type {?} */
                  const nsId = elementStates[keys[i]].namespaceId;
                  if (nsId) {
                      /** @type {?} */
                      const ns = this._fetchNamespace(nsId);
                      if (ns) {
                          namespaces.add(ns);
                      }
                  }
              }
          }
          return namespaces;
      }
      /**
       * @param {?} namespaceId
       * @param {?} element
       * @param {?} name
       * @param {?} value
       * @return {?}
       */
      trigger(namespaceId, element, name, value) {
          if (isElementNode(element)) {
              /** @type {?} */
              const ns = this._fetchNamespace(namespaceId);
              if (ns) {
                  ns.trigger(element, name, value);
                  return true;
              }
          }
          return false;
      }
      /**
       * @param {?} namespaceId
       * @param {?} element
       * @param {?} parent
       * @param {?} insertBefore
       * @return {?}
       */
      insertNode(namespaceId, element, parent, insertBefore) {
          if (!isElementNode(element))
              return;
          // special case for when an element is removed and reinserted (move operation)
          // when this occurs we do not want to use the element for deletion later
          /** @type {?} */
          const details = (/** @type {?} */ (element[REMOVAL_FLAG]));
          if (details && details.setForRemoval) {
              details.setForRemoval = false;
              details.setForMove = true;
              /** @type {?} */
              const index = this.collectedLeaveElements.indexOf(element);
              if (index >= 0) {
                  this.collectedLeaveElements.splice(index, 1);
              }
          }
          // in the event that the namespaceId is blank then the caller
          // code does not contain any animation code in it, but it is
          // just being called so that the node is marked as being inserted
          if (namespaceId) {
              /** @type {?} */
              const ns = this._fetchNamespace(namespaceId);
              // This if-statement is a workaround for router issue #21947.
              // The router sometimes hits a race condition where while a route
              // is being instantiated a new navigation arrives, triggering leave
              // animation of DOM that has not been fully initialized, until this
              // is resolved, we need to handle the scenario when DOM is not in a
              // consistent state during the animation.
              if (ns) {
                  ns.insertNode(element, parent);
              }
          }
          // only *directives and host elements are inserted before
          if (insertBefore) {
              this.collectEnterElement(element);
          }
      }
      /**
       * @param {?} element
       * @return {?}
       */
      collectEnterElement(element) { this.collectedEnterElements.push(element); }
      /**
       * @param {?} element
       * @param {?} value
       * @return {?}
       */
      markElementAsDisabled(element, value) {
          if (value) {
              if (!this.disabledNodes.has(element)) {
                  this.disabledNodes.add(element);
                  addClass(element, DISABLED_CLASSNAME);
              }
          }
          else if (this.disabledNodes.has(element)) {
              this.disabledNodes.delete(element);
              removeClass(element, DISABLED_CLASSNAME);
          }
      }
      /**
       * @param {?} namespaceId
       * @param {?} element
       * @param {?} isHostElement
       * @param {?} context
       * @return {?}
       */
      removeNode(namespaceId, element, isHostElement, context) {
          if (isElementNode(element)) {
              /** @type {?} */
              const ns = namespaceId ? this._fetchNamespace(namespaceId) : null;
              if (ns) {
                  ns.removeNode(element, context);
              }
              else {
                  this.markElementAsRemoved(namespaceId, element, false, context);
              }
              if (isHostElement) {
                  /** @type {?} */
                  const hostNS = this.namespacesByHostElement.get(element);
                  if (hostNS && hostNS.id !== namespaceId) {
                      hostNS.removeNode(element, context);
                  }
              }
          }
          else {
              this._onRemovalComplete(element, context);
          }
      }
      /**
       * @param {?} namespaceId
       * @param {?} element
       * @param {?=} hasAnimation
       * @param {?=} context
       * @return {?}
       */
      markElementAsRemoved(namespaceId, element, hasAnimation, context) {
          this.collectedLeaveElements.push(element);
          element[REMOVAL_FLAG] = {
              namespaceId,
              setForRemoval: context, hasAnimation,
              removedBeforeQueried: false
          };
      }
      /**
       * @param {?} namespaceId
       * @param {?} element
       * @param {?} name
       * @param {?} phase
       * @param {?} callback
       * @return {?}
       */
      listen(namespaceId, element, name, phase, callback) {
          if (isElementNode(element)) {
              return this._fetchNamespace(namespaceId).listen(element, name, phase, callback);
          }
          return (/**
           * @return {?}
           */
          () => { });
      }
      /**
       * @private
       * @param {?} entry
       * @param {?} subTimelines
       * @param {?} enterClassName
       * @param {?} leaveClassName
       * @param {?=} skipBuildAst
       * @return {?}
       */
      _buildInstruction(entry, subTimelines, enterClassName, leaveClassName, skipBuildAst) {
          return entry.transition.build(this.driver, entry.element, entry.fromState.value, entry.toState.value, enterClassName, leaveClassName, entry.fromState.options, entry.toState.options, subTimelines, skipBuildAst);
      }
      /**
       * @param {?} containerElement
       * @return {?}
       */
      destroyInnerAnimations(containerElement) {
          /** @type {?} */
          let elements = this.driver.query(containerElement, NG_TRIGGER_SELECTOR, true);
          elements.forEach((/**
           * @param {?} element
           * @return {?}
           */
          element => this.destroyActiveAnimationsForElement(element)));
          if (this.playersByQueriedElement.size == 0)
              return;
          elements = this.driver.query(containerElement, NG_ANIMATING_SELECTOR, true);
          elements.forEach((/**
           * @param {?} element
           * @return {?}
           */
          element => this.finishActiveQueriedAnimationOnElement(element)));
      }
      /**
       * @param {?} element
       * @return {?}
       */
      destroyActiveAnimationsForElement(element) {
          /** @type {?} */
          const players = this.playersByElement.get(element);
          if (players) {
              players.forEach((/**
               * @param {?} player
               * @return {?}
               */
              player => {
                  // special case for when an element is set for destruction, but hasn't started.
                  // in this situation we want to delay the destruction until the flush occurs
                  // so that any event listeners attached to the player are triggered.
                  if (player.queued) {
                      player.markedForDestroy = true;
                  }
                  else {
                      player.destroy();
                  }
              }));
          }
      }
      /**
       * @param {?} element
       * @return {?}
       */
      finishActiveQueriedAnimationOnElement(element) {
          /** @type {?} */
          const players = this.playersByQueriedElement.get(element);
          if (players) {
              players.forEach((/**
               * @param {?} player
               * @return {?}
               */
              player => player.finish()));
          }
      }
      /**
       * @return {?}
       */
      whenRenderingDone() {
          return new Promise((/**
           * @param {?} resolve
           * @return {?}
           */
          resolve => {
              if (this.players.length) {
                  return optimizeGroupPlayer(this.players).onDone((/**
                   * @return {?}
                   */
                  () => resolve()));
              }
              else {
                  resolve();
              }
          }));
      }
      /**
       * @param {?} element
       * @return {?}
       */
      processLeaveNode(element) {
          /** @type {?} */
          const details = (/** @type {?} */ (element[REMOVAL_FLAG]));
          if (details && details.setForRemoval) {
              // this will prevent it from removing it twice
              element[REMOVAL_FLAG] = NULL_REMOVAL_STATE;
              if (details.namespaceId) {
                  this.destroyInnerAnimations(element);
                  /** @type {?} */
                  const ns = this._fetchNamespace(details.namespaceId);
                  if (ns) {
                      ns.clearElementCache(element);
                  }
              }
              this._onRemovalComplete(element, details.setForRemoval);
          }
          if (this.driver.matchesElement(element, DISABLED_SELECTOR)) {
              this.markElementAsDisabled(element, false);
          }
          this.driver.query(element, DISABLED_SELECTOR, true).forEach((/**
           * @param {?} node
           * @return {?}
           */
          node => {
              this.markElementAsDisabled(node, false);
          }));
      }
      /**
       * @param {?=} microtaskId
       * @return {?}
       */
      flush(microtaskId = -1) {
          /** @type {?} */
          let players = [];
          if (this.newHostElements.size) {
              this.newHostElements.forEach((/**
               * @param {?} ns
               * @param {?} element
               * @return {?}
               */
              (ns, element) => this._balanceNamespaceList(ns, element)));
              this.newHostElements.clear();
          }
          if (this.totalAnimations && this.collectedEnterElements.length) {
              for (let i = 0; i < this.collectedEnterElements.length; i++) {
                  /** @type {?} */
                  const elm = this.collectedEnterElements[i];
                  addClass(elm, STAR_CLASSNAME);
              }
          }
          if (this._namespaceList.length &&
              (this.totalQueuedPlayers || this.collectedLeaveElements.length)) {
              /** @type {?} */
              const cleanupFns = [];
              try {
                  players = this._flushAnimations(cleanupFns, microtaskId);
              }
              finally {
                  for (let i = 0; i < cleanupFns.length; i++) {
                      cleanupFns[i]();
                  }
              }
          }
          else {
              for (let i = 0; i < this.collectedLeaveElements.length; i++) {
                  /** @type {?} */
                  const element = this.collectedLeaveElements[i];
                  this.processLeaveNode(element);
              }
          }
          this.totalQueuedPlayers = 0;
          this.collectedEnterElements.length = 0;
          this.collectedLeaveElements.length = 0;
          this._flushFns.forEach((/**
           * @param {?} fn
           * @return {?}
           */
          fn => fn()));
          this._flushFns = [];
          if (this._whenQuietFns.length) {
              // we move these over to a variable so that
              // if any new callbacks are registered in another
              // flush they do not populate the existing set
              /** @type {?} */
              const quietFns = this._whenQuietFns;
              this._whenQuietFns = [];
              if (players.length) {
                  optimizeGroupPlayer(players).onDone((/**
                   * @return {?}
                   */
                  () => { quietFns.forEach((/**
                   * @param {?} fn
                   * @return {?}
                   */
                  fn => fn())); }));
              }
              else {
                  quietFns.forEach((/**
                   * @param {?} fn
                   * @return {?}
                   */
                  fn => fn()));
              }
          }
      }
      /**
       * @param {?} errors
       * @return {?}
       */
      reportError(errors) {
          throw new Error(`Unable to process animations due to the following failed trigger transitions\n ${errors.join('\n')}`);
      }
      /**
       * @private
       * @param {?} cleanupFns
       * @param {?} microtaskId
       * @return {?}
       */
      _flushAnimations(cleanupFns, microtaskId) {
          /** @type {?} */
          const subTimelines = new ElementInstructionMap();
          /** @type {?} */
          const skippedPlayers = [];
          /** @type {?} */
          const skippedPlayersMap = new Map();
          /** @type {?} */
          const queuedInstructions = [];
          /** @type {?} */
          const queriedElements = new Map();
          /** @type {?} */
          const allPreStyleElements = new Map();
          /** @type {?} */
          const allPostStyleElements = new Map();
          /** @type {?} */
          const disabledElementsSet = new Set();
          this.disabledNodes.forEach((/**
           * @param {?} node
           * @return {?}
           */
          node => {
              disabledElementsSet.add(node);
              /** @type {?} */
              const nodesThatAreDisabled = this.driver.query(node, QUEUED_SELECTOR, true);
              for (let i = 0; i < nodesThatAreDisabled.length; i++) {
                  disabledElementsSet.add(nodesThatAreDisabled[i]);
              }
          }));
          /** @type {?} */
          const bodyNode = this.bodyNode;
          /** @type {?} */
          const allTriggerElements = Array.from(this.statesByElement.keys());
          /** @type {?} */
          const enterNodeMap = buildRootMap(allTriggerElements, this.collectedEnterElements);
          // this must occur before the instructions are built below such that
          // the :enter queries match the elements (since the timeline queries
          // are fired during instruction building).
          /** @type {?} */
          const enterNodeMapIds = new Map();
          /** @type {?} */
          let i = 0;
          enterNodeMap.forEach((/**
           * @param {?} nodes
           * @param {?} root
           * @return {?}
           */
          (nodes, root) => {
              /** @type {?} */
              const className = ENTER_CLASSNAME + i++;
              enterNodeMapIds.set(root, className);
              nodes.forEach((/**
               * @param {?} node
               * @return {?}
               */
              node => addClass(node, className)));
          }));
          /** @type {?} */
          const allLeaveNodes = [];
          /** @type {?} */
          const mergedLeaveNodes = new Set();
          /** @type {?} */
          const leaveNodesWithoutAnimations = new Set();
          for (let i = 0; i < this.collectedLeaveElements.length; i++) {
              /** @type {?} */
              const element = this.collectedLeaveElements[i];
              /** @type {?} */
              const details = (/** @type {?} */ (element[REMOVAL_FLAG]));
              if (details && details.setForRemoval) {
                  allLeaveNodes.push(element);
                  mergedLeaveNodes.add(element);
                  if (details.hasAnimation) {
                      this.driver.query(element, STAR_SELECTOR, true).forEach((/**
                       * @param {?} elm
                       * @return {?}
                       */
                      elm => mergedLeaveNodes.add(elm)));
                  }
                  else {
                      leaveNodesWithoutAnimations.add(element);
                  }
              }
          }
          /** @type {?} */
          const leaveNodeMapIds = new Map();
          /** @type {?} */
          const leaveNodeMap = buildRootMap(allTriggerElements, Array.from(mergedLeaveNodes));
          leaveNodeMap.forEach((/**
           * @param {?} nodes
           * @param {?} root
           * @return {?}
           */
          (nodes, root) => {
              /** @type {?} */
              const className = LEAVE_CLASSNAME + i++;
              leaveNodeMapIds.set(root, className);
              nodes.forEach((/**
               * @param {?} node
               * @return {?}
               */
              node => addClass(node, className)));
          }));
          cleanupFns.push((/**
           * @return {?}
           */
          () => {
              enterNodeMap.forEach((/**
               * @param {?} nodes
               * @param {?} root
               * @return {?}
               */
              (nodes, root) => {
                  /** @type {?} */
                  const className = (/** @type {?} */ (enterNodeMapIds.get(root)));
                  nodes.forEach((/**
                   * @param {?} node
                   * @return {?}
                   */
                  node => removeClass(node, className)));
              }));
              leaveNodeMap.forEach((/**
               * @param {?} nodes
               * @param {?} root
               * @return {?}
               */
              (nodes, root) => {
                  /** @type {?} */
                  const className = (/** @type {?} */ (leaveNodeMapIds.get(root)));
                  nodes.forEach((/**
                   * @param {?} node
                   * @return {?}
                   */
                  node => removeClass(node, className)));
              }));
              allLeaveNodes.forEach((/**
               * @param {?} element
               * @return {?}
               */
              element => { this.processLeaveNode(element); }));
          }));
          /** @type {?} */
          const allPlayers = [];
          /** @type {?} */
          const erroneousTransitions = [];
          for (let i = this._namespaceList.length - 1; i >= 0; i--) {
              /** @type {?} */
              const ns = this._namespaceList[i];
              ns.drainQueuedTransitions(microtaskId).forEach((/**
               * @param {?} entry
               * @return {?}
               */
              entry => {
                  /** @type {?} */
                  const player = entry.player;
                  /** @type {?} */
                  const element = entry.element;
                  allPlayers.push(player);
                  if (this.collectedEnterElements.length) {
                      /** @type {?} */
                      const details = (/** @type {?} */ (element[REMOVAL_FLAG]));
                      // move animations are currently not supported...
                      if (details && details.setForMove) {
                          player.destroy();
                          return;
                      }
                  }
                  /** @type {?} */
                  const nodeIsOrphaned = !bodyNode || !this.driver.containsElement(bodyNode, element);
                  /** @type {?} */
                  const leaveClassName = (/** @type {?} */ (leaveNodeMapIds.get(element)));
                  /** @type {?} */
                  const enterClassName = (/** @type {?} */ (enterNodeMapIds.get(element)));
                  /** @type {?} */
                  const instruction = (/** @type {?} */ (this._buildInstruction(entry, subTimelines, enterClassName, leaveClassName, nodeIsOrphaned)));
                  if (instruction.errors && instruction.errors.length) {
                      erroneousTransitions.push(instruction);
                      return;
                  }
                  // even though the element may not be apart of the DOM, it may
                  // still be added at a later point (due to the mechanics of content
                  // projection and/or dynamic component insertion) therefore it's
                  // important we still style the element.
                  if (nodeIsOrphaned) {
                      player.onStart((/**
                       * @return {?}
                       */
                      () => eraseStyles(element, instruction.fromStyles)));
                      player.onDestroy((/**
                       * @return {?}
                       */
                      () => setStyles(element, instruction.toStyles)));
                      skippedPlayers.push(player);
                      return;
                  }
                  // if a unmatched transition is queued to go then it SHOULD NOT render
                  // an animation and cancel the previously running animations.
                  if (entry.isFallbackTransition) {
                      player.onStart((/**
                       * @return {?}
                       */
                      () => eraseStyles(element, instruction.fromStyles)));
                      player.onDestroy((/**
                       * @return {?}
                       */
                      () => setStyles(element, instruction.toStyles)));
                      skippedPlayers.push(player);
                      return;
                  }
                  // this means that if a parent animation uses this animation as a sub trigger
                  // then it will instruct the timeline builder to not add a player delay, but
                  // instead stretch the first keyframe gap up until the animation starts. The
                  // reason this is important is to prevent extra initialization styles from being
                  // required by the user in the animation.
                  instruction.timelines.forEach((/**
                   * @param {?} tl
                   * @return {?}
                   */
                  tl => tl.stretchStartingKeyframe = true));
                  subTimelines.append(element, instruction.timelines);
                  /** @type {?} */
                  const tuple = { instruction, player, element };
                  queuedInstructions.push(tuple);
                  instruction.queriedElements.forEach((/**
                   * @param {?} element
                   * @return {?}
                   */
                  element => getOrSetAsInMap(queriedElements, element, []).push(player)));
                  instruction.preStyleProps.forEach((/**
                   * @param {?} stringMap
                   * @param {?} element
                   * @return {?}
                   */
                  (stringMap, element) => {
                      /** @type {?} */
                      const props = Object.keys(stringMap);
                      if (props.length) {
                          /** @type {?} */
                          let setVal = (/** @type {?} */ (allPreStyleElements.get(element)));
                          if (!setVal) {
                              allPreStyleElements.set(element, setVal = new Set());
                          }
                          props.forEach((/**
                           * @param {?} prop
                           * @return {?}
                           */
                          prop => setVal.add(prop)));
                      }
                  }));
                  instruction.postStyleProps.forEach((/**
                   * @param {?} stringMap
                   * @param {?} element
                   * @return {?}
                   */
                  (stringMap, element) => {
                      /** @type {?} */
                      const props = Object.keys(stringMap);
                      /** @type {?} */
                      let setVal = (/** @type {?} */ (allPostStyleElements.get(element)));
                      if (!setVal) {
                          allPostStyleElements.set(element, setVal = new Set());
                      }
                      props.forEach((/**
                       * @param {?} prop
                       * @return {?}
                       */
                      prop => setVal.add(prop)));
                  }));
              }));
          }
          if (erroneousTransitions.length) {
              /** @type {?} */
              const errors = [];
              erroneousTransitions.forEach((/**
               * @param {?} instruction
               * @return {?}
               */
              instruction => {
                  errors.push(`@${instruction.triggerName} has failed due to:\n`);
                  (/** @type {?} */ (instruction.errors)).forEach((/**
                   * @param {?} error
                   * @return {?}
                   */
                  error => errors.push(`- ${error}\n`)));
              }));
              allPlayers.forEach((/**
               * @param {?} player
               * @return {?}
               */
              player => player.destroy()));
              this.reportError(errors);
          }
          /** @type {?} */
          const allPreviousPlayersMap = new Map();
          // this map works to tell which element in the DOM tree is contained by
          // which animation. Further down below this map will get populated once
          // the players are built and in doing so it can efficiently figure out
          // if a sub player is skipped due to a parent player having priority.
          /** @type {?} */
          const animationElementMap = new Map();
          queuedInstructions.forEach((/**
           * @param {?} entry
           * @return {?}
           */
          entry => {
              /** @type {?} */
              const element = entry.element;
              if (subTimelines.has(element)) {
                  animationElementMap.set(element, element);
                  this._beforeAnimationBuild(entry.player.namespaceId, entry.instruction, allPreviousPlayersMap);
              }
          }));
          skippedPlayers.forEach((/**
           * @param {?} player
           * @return {?}
           */
          player => {
              /** @type {?} */
              const element = player.element;
              /** @type {?} */
              const previousPlayers = this._getPreviousPlayers(element, false, player.namespaceId, player.triggerName, null);
              previousPlayers.forEach((/**
               * @param {?} prevPlayer
               * @return {?}
               */
              prevPlayer => {
                  getOrSetAsInMap(allPreviousPlayersMap, element, []).push(prevPlayer);
                  prevPlayer.destroy();
              }));
          }));
          // this is a special case for nodes that will be removed (either by)
          // having their own leave animations or by being queried in a container
          // that will be removed once a parent animation is complete. The idea
          // here is that * styles must be identical to ! styles because of
          // backwards compatibility (* is also filled in by default in many places).
          // Otherwise * styles will return an empty value or auto since the element
          // that is being getComputedStyle'd will not be visible (since * = destination)
          /** @type {?} */
          const replaceNodes = allLeaveNodes.filter((/**
           * @param {?} node
           * @return {?}
           */
          node => {
              return replacePostStylesAsPre(node, allPreStyleElements, allPostStyleElements);
          }));
          // POST STAGE: fill the * styles
          /** @type {?} */
          const postStylesMap = new Map();
          /** @type {?} */
          const allLeaveQueriedNodes = cloakAndComputeStyles(postStylesMap, this.driver, leaveNodesWithoutAnimations, allPostStyleElements, AUTO_STYLE);
          allLeaveQueriedNodes.forEach((/**
           * @param {?} node
           * @return {?}
           */
          node => {
              if (replacePostStylesAsPre(node, allPreStyleElements, allPostStyleElements)) {
                  replaceNodes.push(node);
              }
          }));
          // PRE STAGE: fill the ! styles
          /** @type {?} */
          const preStylesMap = new Map();
          enterNodeMap.forEach((/**
           * @param {?} nodes
           * @param {?} root
           * @return {?}
           */
          (nodes, root) => {
              cloakAndComputeStyles(preStylesMap, this.driver, new Set(nodes), allPreStyleElements, ɵPRE_STYLE);
          }));
          replaceNodes.forEach((/**
           * @param {?} node
           * @return {?}
           */
          node => {
              /** @type {?} */
              const post = postStylesMap.get(node);
              /** @type {?} */
              const pre = preStylesMap.get(node);
              postStylesMap.set(node, (/** @type {?} */ (Object.assign({}, post, pre))));
          }));
          /** @type {?} */
          const rootPlayers = [];
          /** @type {?} */
          const subPlayers = [];
          /** @type {?} */
          const NO_PARENT_ANIMATION_ELEMENT_DETECTED = {};
          queuedInstructions.forEach((/**
           * @param {?} entry
           * @return {?}
           */
          entry => {
              const { element, player, instruction } = entry;
              // this means that it was never consumed by a parent animation which
              // means that it is independent and therefore should be set for animation
              if (subTimelines.has(element)) {
                  if (disabledElementsSet.has(element)) {
                      player.onDestroy((/**
                       * @return {?}
                       */
                      () => setStyles(element, instruction.toStyles)));
                      player.disabled = true;
                      player.overrideTotalTime(instruction.totalTime);
                      skippedPlayers.push(player);
                      return;
                  }
                  // this will flow up the DOM and query the map to figure out
                  // if a parent animation has priority over it. In the situation
                  // that a parent is detected then it will cancel the loop. If
                  // nothing is detected, or it takes a few hops to find a parent,
                  // then it will fill in the missing nodes and signal them as having
                  // a detected parent (or a NO_PARENT value via a special constant).
                  /** @type {?} */
                  let parentWithAnimation = NO_PARENT_ANIMATION_ELEMENT_DETECTED;
                  if (animationElementMap.size > 1) {
                      /** @type {?} */
                      let elm = element;
                      /** @type {?} */
                      const parentsToAdd = [];
                      while (elm = elm.parentNode) {
                          /** @type {?} */
                          const detectedParent = animationElementMap.get(elm);
                          if (detectedParent) {
                              parentWithAnimation = detectedParent;
                              break;
                          }
                          parentsToAdd.push(elm);
                      }
                      parentsToAdd.forEach((/**
                       * @param {?} parent
                       * @return {?}
                       */
                      parent => animationElementMap.set(parent, parentWithAnimation)));
                  }
                  /** @type {?} */
                  const innerPlayer = this._buildAnimation(player.namespaceId, instruction, allPreviousPlayersMap, skippedPlayersMap, preStylesMap, postStylesMap);
                  player.setRealPlayer(innerPlayer);
                  if (parentWithAnimation === NO_PARENT_ANIMATION_ELEMENT_DETECTED) {
                      rootPlayers.push(player);
                  }
                  else {
                      /** @type {?} */
                      const parentPlayers = this.playersByElement.get(parentWithAnimation);
                      if (parentPlayers && parentPlayers.length) {
                          player.parentPlayer = optimizeGroupPlayer(parentPlayers);
                      }
                      skippedPlayers.push(player);
                  }
              }
              else {
                  eraseStyles(element, instruction.fromStyles);
                  player.onDestroy((/**
                   * @return {?}
                   */
                  () => setStyles(element, instruction.toStyles)));
                  // there still might be a ancestor player animating this
                  // element therefore we will still add it as a sub player
                  // even if its animation may be disabled
                  subPlayers.push(player);
                  if (disabledElementsSet.has(element)) {
                      skippedPlayers.push(player);
                  }
              }
          }));
          // find all of the sub players' corresponding inner animation player
          subPlayers.forEach((/**
           * @param {?} player
           * @return {?}
           */
          player => {
              // even if any players are not found for a sub animation then it
              // will still complete itself after the next tick since it's Noop
              /** @type {?} */
              const playersForElement = skippedPlayersMap.get(player.element);
              if (playersForElement && playersForElement.length) {
                  /** @type {?} */
                  const innerPlayer = optimizeGroupPlayer(playersForElement);
                  player.setRealPlayer(innerPlayer);
              }
          }));
          // the reason why we don't actually play the animation is
          // because all that a skipped player is designed to do is to
          // fire the start/done transition callback events
          skippedPlayers.forEach((/**
           * @param {?} player
           * @return {?}
           */
          player => {
              if (player.parentPlayer) {
                  player.syncPlayerEvents(player.parentPlayer);
              }
              else {
                  player.destroy();
              }
          }));
          // run through all of the queued removals and see if they
          // were picked up by a query. If not then perform the removal
          // operation right away unless a parent animation is ongoing.
          for (let i = 0; i < allLeaveNodes.length; i++) {
              /** @type {?} */
              const element = allLeaveNodes[i];
              /** @type {?} */
              const details = (/** @type {?} */ (element[REMOVAL_FLAG]));
              removeClass(element, LEAVE_CLASSNAME);
              // this means the element has a removal animation that is being
              // taken care of and therefore the inner elements will hang around
              // until that animation is over (or the parent queried animation)
              if (details && details.hasAnimation)
                  continue;
              /** @type {?} */
              let players = [];
              // if this element is queried or if it contains queried children
              // then we want for the element not to be removed from the page
              // until the queried animations have finished
              if (queriedElements.size) {
                  /** @type {?} */
                  let queriedPlayerResults = queriedElements.get(element);
                  if (queriedPlayerResults && queriedPlayerResults.length) {
                      players.push(...queriedPlayerResults);
                  }
                  /** @type {?} */
                  let queriedInnerElements = this.driver.query(element, NG_ANIMATING_SELECTOR, true);
                  for (let j = 0; j < queriedInnerElements.length; j++) {
                      /** @type {?} */
                      let queriedPlayers = queriedElements.get(queriedInnerElements[j]);
                      if (queriedPlayers && queriedPlayers.length) {
                          players.push(...queriedPlayers);
                      }
                  }
              }
              /** @type {?} */
              const activePlayers = players.filter((/**
               * @param {?} p
               * @return {?}
               */
              p => !p.destroyed));
              if (activePlayers.length) {
                  removeNodesAfterAnimationDone(this, element, activePlayers);
              }
              else {
                  this.processLeaveNode(element);
              }
          }
          // this is required so the cleanup method doesn't remove them
          allLeaveNodes.length = 0;
          rootPlayers.forEach((/**
           * @param {?} player
           * @return {?}
           */
          player => {
              this.players.push(player);
              player.onDone((/**
               * @return {?}
               */
              () => {
                  player.destroy();
                  /** @type {?} */
                  const index = this.players.indexOf(player);
                  this.players.splice(index, 1);
              }));
              player.play();
          }));
          return rootPlayers;
      }
      /**
       * @param {?} namespaceId
       * @param {?} element
       * @return {?}
       */
      elementContainsData(namespaceId, element) {
          /** @type {?} */
          let containsData = false;
          /** @type {?} */
          const details = (/** @type {?} */ (element[REMOVAL_FLAG]));
          if (details && details.setForRemoval)
              containsData = true;
          if (this.playersByElement.has(element))
              containsData = true;
          if (this.playersByQueriedElement.has(element))
              containsData = true;
          if (this.statesByElement.has(element))
              containsData = true;
          return this._fetchNamespace(namespaceId).elementContainsData(element) || containsData;
      }
      /**
       * @param {?} callback
       * @return {?}
       */
      afterFlush(callback) { this._flushFns.push(callback); }
      /**
       * @param {?} callback
       * @return {?}
       */
      afterFlushAnimationsDone(callback) { this._whenQuietFns.push(callback); }
      /**
       * @private
       * @param {?} element
       * @param {?} isQueriedElement
       * @param {?=} namespaceId
       * @param {?=} triggerName
       * @param {?=} toStateValue
       * @return {?}
       */
      _getPreviousPlayers(element, isQueriedElement, namespaceId, triggerName, toStateValue) {
          /** @type {?} */
          let players = [];
          if (isQueriedElement) {
              /** @type {?} */
              const queriedElementPlayers = this.playersByQueriedElement.get(element);
              if (queriedElementPlayers) {
                  players = queriedElementPlayers;
              }
          }
          else {
              /** @type {?} */
              const elementPlayers = this.playersByElement.get(element);
              if (elementPlayers) {
                  /** @type {?} */
                  const isRemovalAnimation = !toStateValue || toStateValue == VOID_VALUE;
                  elementPlayers.forEach((/**
                   * @param {?} player
                   * @return {?}
                   */
                  player => {
                      if (player.queued)
                          return;
                      if (!isRemovalAnimation && player.triggerName != triggerName)
                          return;
                      players.push(player);
                  }));
              }
          }
          if (namespaceId || triggerName) {
              players = players.filter((/**
               * @param {?} player
               * @return {?}
               */
              player => {
                  if (namespaceId && namespaceId != player.namespaceId)
                      return false;
                  if (triggerName && triggerName != player.triggerName)
                      return false;
                  return true;
              }));
          }
          return players;
      }
      /**
       * @private
       * @param {?} namespaceId
       * @param {?} instruction
       * @param {?} allPreviousPlayersMap
       * @return {?}
       */
      _beforeAnimationBuild(namespaceId, instruction, allPreviousPlayersMap) {
          /** @type {?} */
          const triggerName = instruction.triggerName;
          /** @type {?} */
          const rootElement = instruction.element;
          // when a removal animation occurs, ALL previous players are collected
          // and destroyed (even if they are outside of the current namespace)
          /** @type {?} */
          const targetNameSpaceId = instruction.isRemovalTransition ? undefined : namespaceId;
          /** @type {?} */
          const targetTriggerName = instruction.isRemovalTransition ? undefined : triggerName;
          for (const timelineInstruction of instruction.timelines) {
              /** @type {?} */
              const element = timelineInstruction.element;
              /** @type {?} */
              const isQueriedElement = element !== rootElement;
              /** @type {?} */
              const players = getOrSetAsInMap(allPreviousPlayersMap, element, []);
              /** @type {?} */
              const previousPlayers = this._getPreviousPlayers(element, isQueriedElement, targetNameSpaceId, targetTriggerName, instruction.toState);
              previousPlayers.forEach((/**
               * @param {?} player
               * @return {?}
               */
              player => {
                  /** @type {?} */
                  const realPlayer = (/** @type {?} */ (player.getRealPlayer()));
                  if (realPlayer.beforeDestroy) {
                      realPlayer.beforeDestroy();
                  }
                  player.destroy();
                  players.push(player);
              }));
          }
          // this needs to be done so that the PRE/POST styles can be
          // computed properly without interfering with the previous animation
          eraseStyles(rootElement, instruction.fromStyles);
      }
      /**
       * @private
       * @param {?} namespaceId
       * @param {?} instruction
       * @param {?} allPreviousPlayersMap
       * @param {?} skippedPlayersMap
       * @param {?} preStylesMap
       * @param {?} postStylesMap
       * @return {?}
       */
      _buildAnimation(namespaceId, instruction, allPreviousPlayersMap, skippedPlayersMap, preStylesMap, postStylesMap) {
          /** @type {?} */
          const triggerName = instruction.triggerName;
          /** @type {?} */
          const rootElement = instruction.element;
          // we first run this so that the previous animation player
          // data can be passed into the successive animation players
          /** @type {?} */
          const allQueriedPlayers = [];
          /** @type {?} */
          const allConsumedElements = new Set();
          /** @type {?} */
          const allSubElements = new Set();
          /** @type {?} */
          const allNewPlayers = instruction.timelines.map((/**
           * @param {?} timelineInstruction
           * @return {?}
           */
          timelineInstruction => {
              /** @type {?} */
              const element = timelineInstruction.element;
              allConsumedElements.add(element);
              // FIXME (matsko): make sure to-be-removed animations are removed properly
              /** @type {?} */
              const details = element[REMOVAL_FLAG];
              if (details && details.removedBeforeQueried)
                  return new NoopAnimationPlayer(timelineInstruction.duration, timelineInstruction.delay);
              /** @type {?} */
              const isQueriedElement = element !== rootElement;
              /** @type {?} */
              const previousPlayers = flattenGroupPlayers((allPreviousPlayersMap.get(element) || EMPTY_PLAYER_ARRAY)
                  .map((/**
               * @param {?} p
               * @return {?}
               */
              p => p.getRealPlayer())))
                  .filter((/**
               * @param {?} p
               * @return {?}
               */
              p => {
                  // the `element` is not apart of the AnimationPlayer definition, but
                  // Mock/WebAnimations
                  // use the element within their implementation. This will be added in Angular5 to
                  // AnimationPlayer
                  /** @type {?} */
                  const pp = (/** @type {?} */ (p));
                  return pp.element ? pp.element === element : false;
              }));
              /** @type {?} */
              const preStyles = preStylesMap.get(element);
              /** @type {?} */
              const postStyles = postStylesMap.get(element);
              /** @type {?} */
              const keyframes = normalizeKeyframes(this.driver, this._normalizer, element, timelineInstruction.keyframes, preStyles, postStyles);
              /** @type {?} */
              const player = this._buildPlayer(timelineInstruction, keyframes, previousPlayers);
              // this means that this particular player belongs to a sub trigger. It is
              // important that we match this player up with the corresponding (@trigger.listener)
              if (timelineInstruction.subTimeline && skippedPlayersMap) {
                  allSubElements.add(element);
              }
              if (isQueriedElement) {
                  /** @type {?} */
                  const wrappedPlayer = new TransitionAnimationPlayer(namespaceId, triggerName, element);
                  wrappedPlayer.setRealPlayer(player);
                  allQueriedPlayers.push(wrappedPlayer);
              }
              return player;
          }));
          allQueriedPlayers.forEach((/**
           * @param {?} player
           * @return {?}
           */
          player => {
              getOrSetAsInMap(this.playersByQueriedElement, player.element, []).push(player);
              player.onDone((/**
               * @return {?}
               */
              () => deleteOrUnsetInMap(this.playersByQueriedElement, player.element, player)));
          }));
          allConsumedElements.forEach((/**
           * @param {?} element
           * @return {?}
           */
          element => addClass(element, NG_ANIMATING_CLASSNAME)));
          /** @type {?} */
          const player = optimizeGroupPlayer(allNewPlayers);
          player.onDestroy((/**
           * @return {?}
           */
          () => {
              allConsumedElements.forEach((/**
               * @param {?} element
               * @return {?}
               */
              element => removeClass(element, NG_ANIMATING_CLASSNAME)));
              setStyles(rootElement, instruction.toStyles);
          }));
          // this basically makes all of the callbacks for sub element animations
          // be dependent on the upper players for when they finish
          allSubElements.forEach((/**
           * @param {?} element
           * @return {?}
           */
          element => { getOrSetAsInMap(skippedPlayersMap, element, []).push(player); }));
          return player;
      }
      /**
       * @private
       * @param {?} instruction
       * @param {?} keyframes
       * @param {?} previousPlayers
       * @return {?}
       */
      _buildPlayer(instruction, keyframes, previousPlayers) {
          if (keyframes.length > 0) {
              return this.driver.animate(instruction.element, keyframes, instruction.duration, instruction.delay, instruction.easing, previousPlayers);
          }
          // special case for when an empty transition|definition is provided
          // ... there is no point in rendering an empty animation
          return new NoopAnimationPlayer(instruction.duration, instruction.delay);
      }
  }
  if (false) {
      /** @type {?} */
      TransitionAnimationEngine.prototype.players;
      /** @type {?} */
      TransitionAnimationEngine.prototype.newHostElements;
      /** @type {?} */
      TransitionAnimationEngine.prototype.playersByElement;
      /** @type {?} */
      TransitionAnimationEngine.prototype.playersByQueriedElement;
      /** @type {?} */
      TransitionAnimationEngine.prototype.statesByElement;
      /** @type {?} */
      TransitionAnimationEngine.prototype.disabledNodes;
      /** @type {?} */
      TransitionAnimationEngine.prototype.totalAnimations;
      /** @type {?} */
      TransitionAnimationEngine.prototype.totalQueuedPlayers;
      /**
       * @type {?}
       * @private
       */
      TransitionAnimationEngine.prototype._namespaceLookup;
      /**
       * @type {?}
       * @private
       */
      TransitionAnimationEngine.prototype._namespaceList;
      /**
       * @type {?}
       * @private
       */
      TransitionAnimationEngine.prototype._flushFns;
      /**
       * @type {?}
       * @private
       */
      TransitionAnimationEngine.prototype._whenQuietFns;
      /** @type {?} */
      TransitionAnimationEngine.prototype.namespacesByHostElement;
      /** @type {?} */
      TransitionAnimationEngine.prototype.collectedEnterElements;
      /** @type {?} */
      TransitionAnimationEngine.prototype.collectedLeaveElements;
      /** @type {?} */
      TransitionAnimationEngine.prototype.onRemovalComplete;
      /** @type {?} */
      TransitionAnimationEngine.prototype.bodyNode;
      /** @type {?} */
      TransitionAnimationEngine.prototype.driver;
      /**
       * @type {?}
       * @private
       */
      TransitionAnimationEngine.prototype._normalizer;
  }
  class TransitionAnimationPlayer {
      /**
       * @param {?} namespaceId
       * @param {?} triggerName
       * @param {?} element
       */
      constructor(namespaceId, triggerName, element) {
          this.namespaceId = namespaceId;
          this.triggerName = triggerName;
          this.element = element;
          this._player = new NoopAnimationPlayer();
          this._containsRealPlayer = false;
          this._queuedCallbacks = {};
          this.destroyed = false;
          this.markedForDestroy = false;
          this.disabled = false;
          this.queued = true;
          this.totalTime = 0;
      }
      /**
       * @param {?} player
       * @return {?}
       */
      setRealPlayer(player) {
          if (this._containsRealPlayer)
              return;
          this._player = player;
          Object.keys(this._queuedCallbacks).forEach((/**
           * @param {?} phase
           * @return {?}
           */
          phase => {
              this._queuedCallbacks[phase].forEach((/**
               * @param {?} callback
               * @return {?}
               */
              callback => listenOnPlayer(player, phase, undefined, callback)));
          }));
          this._queuedCallbacks = {};
          this._containsRealPlayer = true;
          this.overrideTotalTime(player.totalTime);
          ((/** @type {?} */ (this))).queued = false;
      }
      /**
       * @return {?}
       */
      getRealPlayer() { return this._player; }
      /**
       * @param {?} totalTime
       * @return {?}
       */
      overrideTotalTime(totalTime) { ((/** @type {?} */ (this))).totalTime = totalTime; }
      /**
       * @param {?} player
       * @return {?}
       */
      syncPlayerEvents(player) {
          /** @type {?} */
          const p = (/** @type {?} */ (this._player));
          if (p.triggerCallback) {
              player.onStart((/**
               * @return {?}
               */
              () => (/** @type {?} */ (p.triggerCallback))('start')));
          }
          player.onDone((/**
           * @return {?}
           */
          () => this.finish()));
          player.onDestroy((/**
           * @return {?}
           */
          () => this.destroy()));
      }
      /**
       * @private
       * @param {?} name
       * @param {?} callback
       * @return {?}
       */
      _queueEvent(name, callback) {
          getOrSetAsInMap(this._queuedCallbacks, name, []).push(callback);
      }
      /**
       * @param {?} fn
       * @return {?}
       */
      onDone(fn) {
          if (this.queued) {
              this._queueEvent('done', fn);
          }
          this._player.onDone(fn);
      }
      /**
       * @param {?} fn
       * @return {?}
       */
      onStart(fn) {
          if (this.queued) {
              this._queueEvent('start', fn);
          }
          this._player.onStart(fn);
      }
      /**
       * @param {?} fn
       * @return {?}
       */
      onDestroy(fn) {
          if (this.queued) {
              this._queueEvent('destroy', fn);
          }
          this._player.onDestroy(fn);
      }
      /**
       * @return {?}
       */
      init() { this._player.init(); }
      /**
       * @return {?}
       */
      hasStarted() { return this.queued ? false : this._player.hasStarted(); }
      /**
       * @return {?}
       */
      play() { !this.queued && this._player.play(); }
      /**
       * @return {?}
       */
      pause() { !this.queued && this._player.pause(); }
      /**
       * @return {?}
       */
      restart() { !this.queued && this._player.restart(); }
      /**
       * @return {?}
       */
      finish() { this._player.finish(); }
      /**
       * @return {?}
       */
      destroy() {
          ((/** @type {?} */ (this))).destroyed = true;
          this._player.destroy();
      }
      /**
       * @return {?}
       */
      reset() { !this.queued && this._player.reset(); }
      /**
       * @param {?} p
       * @return {?}
       */
      setPosition(p) {
          if (!this.queued) {
              this._player.setPosition(p);
          }
      }
      /**
       * @return {?}
       */
      getPosition() { return this.queued ? 0 : this._player.getPosition(); }
      /**
       * \@internal
       * @param {?} phaseName
       * @return {?}
       */
      triggerCallback(phaseName) {
          /** @type {?} */
          const p = (/** @type {?} */ (this._player));
          if (p.triggerCallback) {
              p.triggerCallback(phaseName);
          }
      }
  }
  if (false) {
      /**
       * @type {?}
       * @private
       */
      TransitionAnimationPlayer.prototype._player;
      /**
       * @type {?}
       * @private
       */
      TransitionAnimationPlayer.prototype._containsRealPlayer;
      /**
       * @type {?}
       * @private
       */
      TransitionAnimationPlayer.prototype._queuedCallbacks;
      /** @type {?} */
      TransitionAnimationPlayer.prototype.destroyed;
      /** @type {?} */
      TransitionAnimationPlayer.prototype.parentPlayer;
      /** @type {?} */
      TransitionAnimationPlayer.prototype.markedForDestroy;
      /** @type {?} */
      TransitionAnimationPlayer.prototype.disabled;
      /** @type {?} */
      TransitionAnimationPlayer.prototype.queued;
      /** @type {?} */
      TransitionAnimationPlayer.prototype.totalTime;
      /** @type {?} */
      TransitionAnimationPlayer.prototype.namespaceId;
      /** @type {?} */
      TransitionAnimationPlayer.prototype.triggerName;
      /** @type {?} */
      TransitionAnimationPlayer.prototype.element;
  }
  /**
   * @param {?} map
   * @param {?} key
   * @param {?} value
   * @return {?}
   */
  function deleteOrUnsetInMap(map, key, value) {
      /** @type {?} */
      let currentValues;
      if (map instanceof Map) {
          currentValues = map.get(key);
          if (currentValues) {
              if (currentValues.length) {
                  /** @type {?} */
                  const index = currentValues.indexOf(value);
                  currentValues.splice(index, 1);
              }
              if (currentValues.length == 0) {
                  map.delete(key);
              }
          }
      }
      else {
          currentValues = map[key];
          if (currentValues) {
              if (currentValues.length) {
                  /** @type {?} */
                  const index = currentValues.indexOf(value);
                  currentValues.splice(index, 1);
              }
              if (currentValues.length == 0) {
                  delete map[key];
              }
          }
      }
      return currentValues;
  }
  /**
   * @param {?} value
   * @return {?}
   */
  function normalizeTriggerValue(value) {
      // we use `!= null` here because it's the most simple
      // way to test against a "falsy" value without mixing
      // in empty strings or a zero value. DO NOT OPTIMIZE.
      return value != null ? value : null;
  }
  /**
   * @param {?} node
   * @return {?}
   */
  function isElementNode(node) {
      return node && node['nodeType'] === 1;
  }
  /**
   * @param {?} eventName
   * @return {?}
   */
  function isTriggerEventValid(eventName) {
      return eventName == 'start' || eventName == 'done';
  }
  /**
   * @param {?} element
   * @param {?=} value
   * @return {?}
   */
  function cloakElement(element, value) {
      /** @type {?} */
      const oldValue = element.style.display;
      element.style.display = value != null ? value : 'none';
      return oldValue;
  }
  /**
   * @param {?} valuesMap
   * @param {?} driver
   * @param {?} elements
   * @param {?} elementPropsMap
   * @param {?} defaultStyle
   * @return {?}
   */
  function cloakAndComputeStyles(valuesMap, driver, elements, elementPropsMap, defaultStyle) {
      /** @type {?} */
      const cloakVals = [];
      elements.forEach((/**
       * @param {?} element
       * @return {?}
       */
      element => cloakVals.push(cloakElement(element))));
      /** @type {?} */
      const failedElements = [];
      elementPropsMap.forEach((/**
       * @param {?} props
       * @param {?} element
       * @return {?}
       */
      (props, element) => {
          /** @type {?} */
          const styles = {};
          props.forEach((/**
           * @param {?} prop
           * @return {?}
           */
          prop => {
              /** @type {?} */
              const value = styles[prop] = driver.computeStyle(element, prop, defaultStyle);
              // there is no easy way to detect this because a sub element could be removed
              // by a parent animation element being detached.
              if (!value || value.length == 0) {
                  element[REMOVAL_FLAG] = NULL_REMOVED_QUERIED_STATE;
                  failedElements.push(element);
              }
          }));
          valuesMap.set(element, styles);
      }));
      // we use a index variable here since Set.forEach(a, i) does not return
      // an index value for the closure (but instead just the value)
      /** @type {?} */
      let i = 0;
      elements.forEach((/**
       * @param {?} element
       * @return {?}
       */
      element => cloakElement(element, cloakVals[i++])));
      return failedElements;
  }
  /*
  Since the Angular renderer code will return a collection of inserted
  nodes in all areas of a DOM tree, it's up to this algorithm to figure
  out which nodes are roots for each animation @trigger.
  
  By placing each inserted node into a Set and traversing upwards, it
  is possible to find the @trigger elements and well any direct *star
  insertion nodes, if a @trigger root is found then the enter element
  is placed into the Map[@trigger] spot.
   */
  /**
   * @param {?} roots
   * @param {?} nodes
   * @return {?}
   */
  function buildRootMap(roots, nodes) {
      /** @type {?} */
      const rootMap = new Map();
      roots.forEach((/**
       * @param {?} root
       * @return {?}
       */
      root => rootMap.set(root, [])));
      if (nodes.length == 0)
          return rootMap;
      /** @type {?} */
      const NULL_NODE = 1;
      /** @type {?} */
      const nodeSet = new Set(nodes);
      /** @type {?} */
      const localRootMap = new Map();
      /**
       * @param {?} node
       * @return {?}
       */
      function getRoot(node) {
          if (!node)
              return NULL_NODE;
          /** @type {?} */
          let root = localRootMap.get(node);
          if (root)
              return root;
          /** @type {?} */
          const parent = node.parentNode;
          if (rootMap.has(parent)) { // ngIf inside @trigger
              root = parent;
          }
          else if (nodeSet.has(parent)) { // ngIf inside ngIf
              root = NULL_NODE;
          }
          else { // recurse upwards
              root = getRoot(parent);
          }
          localRootMap.set(node, root);
          return root;
      }
      nodes.forEach((/**
       * @param {?} node
       * @return {?}
       */
      node => {
          /** @type {?} */
          const root = getRoot(node);
          if (root !== NULL_NODE) {
              (/** @type {?} */ (rootMap.get(root))).push(node);
          }
      }));
      return rootMap;
  }
  /** @type {?} */
  const CLASSES_CACHE_KEY = '$$classes';
  /**
   * @param {?} element
   * @param {?} className
   * @return {?}
   */
  function containsClass(element, className) {
      if (element.classList) {
          return element.classList.contains(className);
      }
      else {
          /** @type {?} */
          const classes = element[CLASSES_CACHE_KEY];
          return classes && classes[className];
      }
  }
  /**
   * @param {?} element
   * @param {?} className
   * @return {?}
   */
  function addClass(element, className) {
      if (element.classList) {
          element.classList.add(className);
      }
      else {
          /** @type {?} */
          let classes = element[CLASSES_CACHE_KEY];
          if (!classes) {
              classes = element[CLASSES_CACHE_KEY] = {};
          }
          classes[className] = true;
      }
  }
  /**
   * @param {?} element
   * @param {?} className
   * @return {?}
   */
  function removeClass(element, className) {
      if (element.classList) {
          element.classList.remove(className);
      }
      else {
          /** @type {?} */
          let classes = element[CLASSES_CACHE_KEY];
          if (classes) {
              delete classes[className];
          }
      }
  }
  /**
   * @param {?} engine
   * @param {?} element
   * @param {?} players
   * @return {?}
   */
  function removeNodesAfterAnimationDone(engine, element, players) {
      optimizeGroupPlayer(players).onDone((/**
       * @return {?}
       */
      () => engine.processLeaveNode(element)));
  }
  /**
   * @param {?} players
   * @return {?}
   */
  function flattenGroupPlayers(players) {
      /** @type {?} */
      const finalPlayers = [];
      _flattenGroupPlayersRecur(players, finalPlayers);
      return finalPlayers;
  }
  /**
   * @param {?} players
   * @param {?} finalPlayers
   * @return {?}
   */
  function _flattenGroupPlayersRecur(players, finalPlayers) {
      for (let i = 0; i < players.length; i++) {
          /** @type {?} */
          const player = players[i];
          if (player instanceof ɵAnimationGroupPlayer) {
              _flattenGroupPlayersRecur(player.players, finalPlayers);
          }
          else {
              finalPlayers.push((/** @type {?} */ (player)));
          }
      }
  }
  /**
   * @param {?} a
   * @param {?} b
   * @return {?}
   */
  function objEquals(a, b) {
      /** @type {?} */
      const k1 = Object.keys(a);
      /** @type {?} */
      const k2 = Object.keys(b);
      if (k1.length != k2.length)
          return false;
      for (let i = 0; i < k1.length; i++) {
          /** @type {?} */
          const prop = k1[i];
          if (!b.hasOwnProperty(prop) || a[prop] !== b[prop])
              return false;
      }
      return true;
  }
  /**
   * @param {?} element
   * @param {?} allPreStyleElements
   * @param {?} allPostStyleElements
   * @return {?}
   */
  function replacePostStylesAsPre(element, allPreStyleElements, allPostStyleElements) {
      /** @type {?} */
      const postEntry = allPostStyleElements.get(element);
      if (!postEntry)
          return false;
      /** @type {?} */
      let preEntry = allPreStyleElements.get(element);
      if (preEntry) {
          postEntry.forEach((/**
           * @param {?} data
           * @return {?}
           */
          data => (/** @type {?} */ (preEntry)).add(data)));
      }
      else {
          allPreStyleElements.set(element, postEntry);
      }
      allPostStyleElements.delete(element);
      return true;
  }
  
  /**
   * @fileoverview added by tsickle
   * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
   */
  class AnimationEngine {
      /**
       * @param {?} bodyNode
       * @param {?} _driver
       * @param {?} normalizer
       */
      constructor(bodyNode, _driver, normalizer) {
          this.bodyNode = bodyNode;
          this._driver = _driver;
          this._triggerCache = {};
          // this method is designed to be overridden by the code that uses this engine
          this.onRemovalComplete = (/**
           * @param {?} element
           * @param {?} context
           * @return {?}
           */
          (element, context) => { });
          this._transitionEngine = new TransitionAnimationEngine(bodyNode, _driver, normalizer);
          this._timelineEngine = new TimelineAnimationEngine(bodyNode, _driver, normalizer);
          this._transitionEngine.onRemovalComplete = (/**
           * @param {?} element
           * @param {?} context
           * @return {?}
           */
          (element, context) => this.onRemovalComplete(element, context));
      }
      /**
       * @param {?} componentId
       * @param {?} namespaceId
       * @param {?} hostElement
       * @param {?} name
       * @param {?} metadata
       * @return {?}
       */
      registerTrigger(componentId, namespaceId, hostElement, name, metadata) {
          /** @type {?} */
          const cacheKey = componentId + '-' + name;
          /** @type {?} */
          let trigger = this._triggerCache[cacheKey];
          if (!trigger) {
              /** @type {?} */
              const errors = [];
              /** @type {?} */
              const ast = (/** @type {?} */ (buildAnimationAst(this._driver, (/** @type {?} */ (metadata)), errors)));
              if (errors.length) {
                  throw new Error(`The animation trigger "${name}" has failed to build due to the following errors:\n - ${errors.join("\n - ")}`);
              }
              trigger = buildTrigger(name, ast);
              this._triggerCache[cacheKey] = trigger;
          }
          this._transitionEngine.registerTrigger(namespaceId, name, trigger);
      }
      /**
       * @param {?} namespaceId
       * @param {?} hostElement
       * @return {?}
       */
      register(namespaceId, hostElement) {
          this._transitionEngine.register(namespaceId, hostElement);
      }
      /**
       * @param {?} namespaceId
       * @param {?} context
       * @return {?}
       */
      destroy(namespaceId, context) {
          this._transitionEngine.destroy(namespaceId, context);
      }
      /**
       * @param {?} namespaceId
       * @param {?} element
       * @param {?} parent
       * @param {?} insertBefore
       * @return {?}
       */
      onInsert(namespaceId, element, parent, insertBefore) {
          this._transitionEngine.insertNode(namespaceId, element, parent, insertBefore);
      }
      /**
       * @param {?} namespaceId
       * @param {?} element
       * @param {?} context
       * @param {?=} isHostElement
       * @return {?}
       */
      onRemove(namespaceId, element, context, isHostElement) {
          this._transitionEngine.removeNode(namespaceId, element, isHostElement || false, context);
      }
      /**
       * @param {?} element
       * @param {?} disable
       * @return {?}
       */
      disableAnimations(element, disable) {
          this._transitionEngine.markElementAsDisabled(element, disable);
      }
      /**
       * @param {?} namespaceId
       * @param {?} element
       * @param {?} property
       * @param {?} value
       * @return {?}
       */
      process(namespaceId, element, property, value) {
          if (property.charAt(0) == '@') {
              const [id, action] = parseTimelineCommand(property);
              /** @type {?} */
              const args = (/** @type {?} */ (value));
              this._timelineEngine.command(id, element, action, args);
          }
          else {
              this._transitionEngine.trigger(namespaceId, element, property, value);
          }
      }
      /**
       * @param {?} namespaceId
       * @param {?} element
       * @param {?} eventName
       * @param {?} eventPhase
       * @param {?} callback
       * @return {?}
       */
      listen(namespaceId, element, eventName, eventPhase, callback) {
          // @@listen
          if (eventName.charAt(0) == '@') {
              const [id, action] = parseTimelineCommand(eventName);
              return this._timelineEngine.listen(id, element, action, callback);
          }
          return this._transitionEngine.listen(namespaceId, element, eventName, eventPhase, callback);
      }
      /**
       * @param {?=} microtaskId
       * @return {?}
       */
      flush(microtaskId = -1) { this._transitionEngine.flush(microtaskId); }
      /**
       * @return {?}
       */
      get players() {
          return ((/** @type {?} */ (this._transitionEngine.players)))
              .concat((/** @type {?} */ (this._timelineEngine.players)));
      }
      /**
       * @return {?}
       */
      whenRenderingDone() { return this._transitionEngine.whenRenderingDone(); }
  }
  if (false) {
      /**
       * @type {?}
       * @private
       */
      AnimationEngine.prototype._transitionEngine;
      /**
       * @type {?}
       * @private
       */
      AnimationEngine.prototype._timelineEngine;
      /**
       * @type {?}
       * @private
       */
      AnimationEngine.prototype._triggerCache;
      /** @type {?} */
      AnimationEngine.prototype.onRemovalComplete;
      /**
       * @type {?}
       * @private
       */
      AnimationEngine.prototype.bodyNode;
      /**
       * @type {?}
       * @private
       */
      AnimationEngine.prototype._driver;
  }
  
  /**
   * @fileoverview added by tsickle
   * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
   */
  /**
   * Returns an instance of `SpecialCasedStyles` if and when any special (non animateable) styles are
   * detected.
   *
   * In CSS there exist properties that cannot be animated within a keyframe animation
   * (whether it be via CSS keyframes or web-animations) and the animation implementation
   * will ignore them. This function is designed to detect those special cased styles and
   * return a container that will be executed at the start and end of the animation.
   *
   * @param {?} element
   * @param {?} styles
   * @return {?} an instance of `SpecialCasedStyles` if any special styles are detected otherwise `null`
   */
  function packageNonAnimatableStyles(element, styles) {
      /** @type {?} */
      let startStyles = null;
      /** @type {?} */
      let endStyles = null;
      if (Array.isArray(styles) && styles.length) {
          startStyles = filterNonAnimatableStyles(styles[0]);
          if (styles.length > 1) {
              endStyles = filterNonAnimatableStyles(styles[styles.length - 1]);
          }
      }
      else if (styles) {
          startStyles = filterNonAnimatableStyles(styles);
      }
      return (startStyles || endStyles) ? new SpecialCasedStyles(element, startStyles, endStyles) :
          null;
  }
  /**
   * Designed to be executed during a keyframe-based animation to apply any special-cased styles.
   *
   * When started (when the `start()` method is run) then the provided `startStyles`
   * will be applied. When finished (when the `finish()` method is called) the
   * `endStyles` will be applied as well any any starting styles. Finally when
   * `destroy()` is called then all styles will be removed.
   */
  class SpecialCasedStyles {
      /**
       * @param {?} _element
       * @param {?} _startStyles
       * @param {?} _endStyles
       */
      constructor(_element, _startStyles, _endStyles) {
          this._element = _element;
          this._startStyles = _startStyles;
          this._endStyles = _endStyles;
          this._state = 0 /* Pending */;
          /** @type {?} */
          let initialStyles = SpecialCasedStyles.initialStylesByElement.get(_element);
          if (!initialStyles) {
              SpecialCasedStyles.initialStylesByElement.set(_element, initialStyles = {});
          }
          this._initialStyles = initialStyles;
      }
      /**
       * @return {?}
       */
      start() {
          if (this._state < 1 /* Started */) {
              if (this._startStyles) {
                  setStyles(this._element, this._startStyles, this._initialStyles);
              }
              this._state = 1 /* Started */;
          }
      }
      /**
       * @return {?}
       */
      finish() {
          this.start();
          if (this._state < 2 /* Finished */) {
              setStyles(this._element, this._initialStyles);
              if (this._endStyles) {
                  setStyles(this._element, this._endStyles);
                  this._endStyles = null;
              }
              this._state = 1 /* Started */;
          }
      }
      /**
       * @return {?}
       */
      destroy() {
          this.finish();
          if (this._state < 3 /* Destroyed */) {
              SpecialCasedStyles.initialStylesByElement.delete(this._element);
              if (this._startStyles) {
                  eraseStyles(this._element, this._startStyles);
                  this._endStyles = null;
              }
              if (this._endStyles) {
                  eraseStyles(this._element, this._endStyles);
                  this._endStyles = null;
              }
              setStyles(this._element, this._initialStyles);
              this._state = 3 /* Destroyed */;
          }
      }
  }
  SpecialCasedStyles.initialStylesByElement = new WeakMap();
  if (false) {
      /** @type {?} */
      SpecialCasedStyles.initialStylesByElement;
      /**
       * @type {?}
       * @private
       */
      SpecialCasedStyles.prototype._state;
      /**
       * @type {?}
       * @private
       */
      SpecialCasedStyles.prototype._initialStyles;
      /**
       * @type {?}
       * @private
       */
      SpecialCasedStyles.prototype._element;
      /**
       * @type {?}
       * @private
       */
      SpecialCasedStyles.prototype._startStyles;
      /**
       * @type {?}
       * @private
       */
      SpecialCasedStyles.prototype._endStyles;
  }
  /** @enum {number} */
  const SpecialCasedStylesState = {
      Pending: 0,
      Started: 1,
      Finished: 2,
      Destroyed: 3,
  };
  /**
   * @param {?} styles
   * @return {?}
   */
  function filterNonAnimatableStyles(styles) {
      /** @type {?} */
      let result = null;
      /** @type {?} */
      const props = Object.keys(styles);
      for (let i = 0; i < props.length; i++) {
          /** @type {?} */
          const prop = props[i];
          if (isNonAnimatableStyle(prop)) {
              result = result || {};
              result[prop] = styles[prop];
          }
      }
      return result;
  }
  /**
   * @param {?} prop
   * @return {?}
   */
  function isNonAnimatableStyle(prop) {
      return prop === 'display' || prop === 'position';
  }
  
  /**
   * @fileoverview added by tsickle
   * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
   */
  /**
   * @license
   * Copyright Google Inc. All Rights Reserved.
   *
   * Use of this source code is governed by an MIT-style license that can be
   * found in the LICENSE file at https://angular.io/license
   * @type {?}
   */
  const ELAPSED_TIME_MAX_DECIMAL_PLACES = 3;
  /** @type {?} */
  const ANIMATION_PROP = 'animation';
  /** @type {?} */
  const ANIMATIONEND_EVENT = 'animationend';
  /** @type {?} */
  const ONE_SECOND$1 = 1000;
  class ElementAnimationStyleHandler {
      /**
       * @param {?} _element
       * @param {?} _name
       * @param {?} _duration
       * @param {?} _delay
       * @param {?} _easing
       * @param {?} _fillMode
       * @param {?} _onDoneFn
       */
      constructor(_element, _name, _duration, _delay, _easing, _fillMode, _onDoneFn) {
          this._element = _element;
          this._name = _name;
          this._duration = _duration;
          this._delay = _delay;
          this._easing = _easing;
          this._fillMode = _fillMode;
          this._onDoneFn = _onDoneFn;
          this._finished = false;
          this._destroyed = false;
          this._startTime = 0;
          this._position = 0;
          this._eventFn = (/**
           * @param {?} e
           * @return {?}
           */
          (e) => this._handleCallback(e));
      }
      /**
       * @return {?}
       */
      apply() {
          applyKeyframeAnimation(this._element, `${this._duration}ms ${this._easing} ${this._delay}ms 1 normal ${this._fillMode} ${this._name}`);
          addRemoveAnimationEvent(this._element, this._eventFn, false);
          this._startTime = Date.now();
      }
      /**
       * @return {?}
       */
      pause() { playPauseAnimation(this._element, this._name, 'paused'); }
      /**
       * @return {?}
       */
      resume() { playPauseAnimation(this._element, this._name, 'running'); }
      /**
       * @param {?} position
       * @return {?}
       */
      setPosition(position) {
          /** @type {?} */
          const index = findIndexForAnimation(this._element, this._name);
          this._position = position * this._duration;
          setAnimationStyle(this._element, 'Delay', `-${this._position}ms`, index);
      }
      /**
       * @return {?}
       */
      getPosition() { return this._position; }
      /**
       * @private
       * @param {?} event
       * @return {?}
       */
      _handleCallback(event) {
          /** @type {?} */
          const timestamp = event._ngTestManualTimestamp || Date.now();
          /** @type {?} */
          const elapsedTime = parseFloat(event.elapsedTime.toFixed(ELAPSED_TIME_MAX_DECIMAL_PLACES)) * ONE_SECOND$1;
          if (event.animationName == this._name &&
              Math.max(timestamp - this._startTime, 0) >= this._delay && elapsedTime >= this._duration) {
              this.finish();
          }
      }
      /**
       * @return {?}
       */
      finish() {
          if (this._finished)
              return;
          this._finished = true;
          this._onDoneFn();
          addRemoveAnimationEvent(this._element, this._eventFn, true);
      }
      /**
       * @return {?}
       */
      destroy() {
          if (this._destroyed)
              return;
          this._destroyed = true;
          this.finish();
          removeKeyframeAnimation(this._element, this._name);
      }
  }
  if (false) {
      /**
       * @type {?}
       * @private
       */
      ElementAnimationStyleHandler.prototype._eventFn;
      /**
       * @type {?}
       * @private
       */
      ElementAnimationStyleHandler.prototype._finished;
      /**
       * @type {?}
       * @private
       */
      ElementAnimationStyleHandler.prototype._destroyed;
      /**
       * @type {?}
       * @private
       */
      ElementAnimationStyleHandler.prototype._startTime;
      /**
       * @type {?}
       * @private
       */
      ElementAnimationStyleHandler.prototype._position;
      /**
       * @type {?}
       * @private
       */
      ElementAnimationStyleHandler.prototype._element;
      /**
       * @type {?}
       * @private
       */
      ElementAnimationStyleHandler.prototype._name;
      /**
       * @type {?}
       * @private
       */
      ElementAnimationStyleHandler.prototype._duration;
      /**
       * @type {?}
       * @private
       */
      ElementAnimationStyleHandler.prototype._delay;
      /**
       * @type {?}
       * @private
       */
      ElementAnimationStyleHandler.prototype._easing;
      /**
       * @type {?}
       * @private
       */
      ElementAnimationStyleHandler.prototype._fillMode;
      /**
       * @type {?}
       * @private
       */
      ElementAnimationStyleHandler.prototype._onDoneFn;
  }
  /**
   * @param {?} element
   * @param {?} name
   * @param {?} status
   * @return {?}
   */
  function playPauseAnimation(element, name, status) {
      /** @type {?} */
      const index = findIndexForAnimation(element, name);
      setAnimationStyle(element, 'PlayState', status, index);
  }
  /**
   * @param {?} element
   * @param {?} value
   * @return {?}
   */
  function applyKeyframeAnimation(element, value) {
      /** @type {?} */
      const anim = getAnimationStyle(element, '').trim();
      /** @type {?} */
      let index = 0;
      if (anim.length) {
          index = countChars(anim, ',') + 1;
          value = `${anim}, ${value}`;
      }
      setAnimationStyle(element, '', value);
      return index;
  }
  /**
   * @param {?} element
   * @param {?} name
   * @return {?}
   */
  function removeKeyframeAnimation(element, name) {
      /** @type {?} */
      const anim = getAnimationStyle(element, '');
      /** @type {?} */
      const tokens = anim.split(',');
      /** @type {?} */
      const index = findMatchingTokenIndex(tokens, name);
      if (index >= 0) {
          tokens.splice(index, 1);
          /** @type {?} */
          const newValue = tokens.join(',');
          setAnimationStyle(element, '', newValue);
      }
  }
  /**
   * @param {?} element
   * @param {?} value
   * @return {?}
   */
  function findIndexForAnimation(element, value) {
      /** @type {?} */
      const anim = getAnimationStyle(element, '');
      if (anim.indexOf(',') > 0) {
          /** @type {?} */
          const tokens = anim.split(',');
          return findMatchingTokenIndex(tokens, value);
      }
      return findMatchingTokenIndex([anim], value);
  }
  /**
   * @param {?} tokens
   * @param {?} searchToken
   * @return {?}
   */
  function findMatchingTokenIndex(tokens, searchToken) {
      for (let i = 0; i < tokens.length; i++) {
          if (tokens[i].indexOf(searchToken) >= 0) {
              return i;
          }
      }
      return -1;
  }
  /**
   * @param {?} element
   * @param {?} fn
   * @param {?} doRemove
   * @return {?}
   */
  function addRemoveAnimationEvent(element, fn, doRemove) {
      doRemove ? element.removeEventListener(ANIMATIONEND_EVENT, fn) :
          element.addEventListener(ANIMATIONEND_EVENT, fn);
  }
  /**
   * @param {?} element
   * @param {?} name
   * @param {?} value
   * @param {?=} index
   * @return {?}
   */
  function setAnimationStyle(element, name, value, index) {
      /** @type {?} */
      const prop = ANIMATION_PROP + name;
      if (index != null) {
          /** @type {?} */
          const oldValue = element.style[prop];
          if (oldValue.length) {
              /** @type {?} */
              const tokens = oldValue.split(',');
              tokens[index] = value;
              value = tokens.join(',');
          }
      }
      element.style[prop] = value;
  }
  /**
   * @param {?} element
   * @param {?} name
   * @return {?}
   */
  function getAnimationStyle(element, name) {
      return element.style[ANIMATION_PROP + name];
  }
  /**
   * @param {?} value
   * @param {?} char
   * @return {?}
   */
  function countChars(value, char) {
      /** @type {?} */
      let count = 0;
      for (let i = 0; i < value.length; i++) {
          /** @type {?} */
          const c = value.charAt(i);
          if (c === char)
              count++;
      }
      return count;
  }
  
  /**
   * @fileoverview added by tsickle
   * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
   */
  /** @type {?} */
  const DEFAULT_FILL_MODE = 'forwards';
  /** @type {?} */
  const DEFAULT_EASING = 'linear';
  /** @enum {number} */
  const AnimatorControlState = {
      INITIALIZED: 1, STARTED: 2, FINISHED: 3, DESTROYED: 4,
  };
  class CssKeyframesPlayer {
      /**
       * @param {?} element
       * @param {?} keyframes
       * @param {?} animationName
       * @param {?} _duration
       * @param {?} _delay
       * @param {?} easing
       * @param {?} _finalStyles
       * @param {?=} _specialStyles
       */
      constructor(element, keyframes, animationName, _duration, _delay, easing, _finalStyles, _specialStyles) {
          this.element = element;
          this.keyframes = keyframes;
          this.animationName = animationName;
          this._duration = _duration;
          this._delay = _delay;
          this._finalStyles = _finalStyles;
          this._specialStyles = _specialStyles;
          this._onDoneFns = [];
          this._onStartFns = [];
          this._onDestroyFns = [];
          this._started = false;
          this.currentSnapshot = {};
          this._state = 0;
          this.easing = easing || DEFAULT_EASING;
          this.totalTime = _duration + _delay;
          this._buildStyler();
      }
      /**
       * @param {?} fn
       * @return {?}
       */
      onStart(fn) { this._onStartFns.push(fn); }
      /**
       * @param {?} fn
       * @return {?}
       */
      onDone(fn) { this._onDoneFns.push(fn); }
      /**
       * @param {?} fn
       * @return {?}
       */
      onDestroy(fn) { this._onDestroyFns.push(fn); }
      /**
       * @return {?}
       */
      destroy() {
          this.init();
          if (this._state >= 4 /* DESTROYED */)
              return;
          this._state = 4 /* DESTROYED */;
          this._styler.destroy();
          this._flushStartFns();
          this._flushDoneFns();
          if (this._specialStyles) {
              this._specialStyles.destroy();
          }
          this._onDestroyFns.forEach((/**
           * @param {?} fn
           * @return {?}
           */
          fn => fn()));
          this._onDestroyFns = [];
      }
      /**
       * @private
       * @return {?}
       */
      _flushDoneFns() {
          this._onDoneFns.forEach((/**
           * @param {?} fn
           * @return {?}
           */
          fn => fn()));
          this._onDoneFns = [];
      }
      /**
       * @private
       * @return {?}
       */
      _flushStartFns() {
          this._onStartFns.forEach((/**
           * @param {?} fn
           * @return {?}
           */
          fn => fn()));
          this._onStartFns = [];
      }
      /**
       * @return {?}
       */
      finish() {
          this.init();
          if (this._state >= 3 /* FINISHED */)
              return;
          this._state = 3 /* FINISHED */;
          this._styler.finish();
          this._flushStartFns();
          if (this._specialStyles) {
              this._specialStyles.finish();
          }
          this._flushDoneFns();
      }
      /**
       * @param {?} value
       * @return {?}
       */
      setPosition(value) { this._styler.setPosition(value); }
      /**
       * @return {?}
       */
      getPosition() { return this._styler.getPosition(); }
      /**
       * @return {?}
       */
      hasStarted() { return this._state >= 2 /* STARTED */; }
      /**
       * @return {?}
       */
      init() {
          if (this._state >= 1 /* INITIALIZED */)
              return;
          this._state = 1 /* INITIALIZED */;
          /** @type {?} */
          const elm = this.element;
          this._styler.apply();
          if (this._delay) {
              this._styler.pause();
          }
      }
      /**
       * @return {?}
       */
      play() {
          this.init();
          if (!this.hasStarted()) {
              this._flushStartFns();
              this._state = 2 /* STARTED */;
              if (this._specialStyles) {
                  this._specialStyles.start();
              }
          }
          this._styler.resume();
      }
      /**
       * @return {?}
       */
      pause() {
          this.init();
          this._styler.pause();
      }
      /**
       * @return {?}
       */
      restart() {
          this.reset();
          this.play();
      }
      /**
       * @return {?}
       */
      reset() {
          this._styler.destroy();
          this._buildStyler();
          this._styler.apply();
      }
      /**
       * @private
       * @return {?}
       */
      _buildStyler() {
          this._styler = new ElementAnimationStyleHandler(this.element, this.animationName, this._duration, this._delay, this.easing, DEFAULT_FILL_MODE, (/**
           * @return {?}
           */
          () => this.finish()));
      }
      /**
       * \@internal
       * @param {?} phaseName
       * @return {?}
       */
      triggerCallback(phaseName) {
          /** @type {?} */
          const methods = phaseName == 'start' ? this._onStartFns : this._onDoneFns;
          methods.forEach((/**
           * @param {?} fn
           * @return {?}
           */
          fn => fn()));
          methods.length = 0;
      }
      /**
       * @return {?}
       */
      beforeDestroy() {
          this.init();
          /** @type {?} */
          const styles = {};
          if (this.hasStarted()) {
              /** @type {?} */
              const finished = this._state >= 3 /* FINISHED */;
              Object.keys(this._finalStyles).forEach((/**
               * @param {?} prop
               * @return {?}
               */
              prop => {
                  if (prop != 'offset') {
                      styles[prop] = finished ? this._finalStyles[prop] : computeStyle(this.element, prop);
                  }
              }));
          }
          this.currentSnapshot = styles;
      }
  }
  if (false) {
      /**
       * @type {?}
       * @private
       */
      CssKeyframesPlayer.prototype._onDoneFns;
      /**
       * @type {?}
       * @private
       */
      CssKeyframesPlayer.prototype._onStartFns;
      /**
       * @type {?}
       * @private
       */
      CssKeyframesPlayer.prototype._onDestroyFns;
      /**
       * @type {?}
       * @private
       */
      CssKeyframesPlayer.prototype._started;
      /**
       * @type {?}
       * @private
       */
      CssKeyframesPlayer.prototype._styler;
      /** @type {?} */
      CssKeyframesPlayer.prototype.parentPlayer;
      /** @type {?} */
      CssKeyframesPlayer.prototype.totalTime;
      /** @type {?} */
      CssKeyframesPlayer.prototype.easing;
      /** @type {?} */
      CssKeyframesPlayer.prototype.currentSnapshot;
      /**
       * @type {?}
       * @private
       */
      CssKeyframesPlayer.prototype._state;
      /** @type {?} */
      CssKeyframesPlayer.prototype.element;
      /** @type {?} */
      CssKeyframesPlayer.prototype.keyframes;
      /** @type {?} */
      CssKeyframesPlayer.prototype.animationName;
      /**
       * @type {?}
       * @private
       */
      CssKeyframesPlayer.prototype._duration;
      /**
       * @type {?}
       * @private
       */
      CssKeyframesPlayer.prototype._delay;
      /**
       * @type {?}
       * @private
       */
      CssKeyframesPlayer.prototype._finalStyles;
      /**
       * @type {?}
       * @private
       */
      CssKeyframesPlayer.prototype._specialStyles;
  }
  
  /**
   * @fileoverview added by tsickle
   * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
   */
  class DirectStylePlayer extends NoopAnimationPlayer {
      /**
       * @param {?} element
       * @param {?} styles
       */
      constructor(element, styles) {
          super();
          this.element = element;
          this._startingStyles = {};
          this.__initialized = false;
          this._styles = hypenatePropsObject(styles);
      }
      /**
       * @return {?}
       */
      init() {
          if (this.__initialized || !this._startingStyles)
              return;
          this.__initialized = true;
          Object.keys(this._styles).forEach((/**
           * @param {?} prop
           * @return {?}
           */
          prop => {
              (/** @type {?} */ (this._startingStyles))[prop] = this.element.style[prop];
          }));
          super.init();
      }
      /**
       * @return {?}
       */
      play() {
          if (!this._startingStyles)
              return;
          this.init();
          Object.keys(this._styles)
              .forEach((/**
           * @param {?} prop
           * @return {?}
           */
          prop => this.element.style.setProperty(prop, this._styles[prop])));
          super.play();
      }
      /**
       * @return {?}
       */
      destroy() {
          if (!this._startingStyles)
              return;
          Object.keys(this._startingStyles).forEach((/**
           * @param {?} prop
           * @return {?}
           */
          prop => {
              /** @type {?} */
              const value = (/** @type {?} */ (this._startingStyles))[prop];
              if (value) {
                  this.element.style.setProperty(prop, value);
              }
              else {
                  this.element.style.removeProperty(prop);
              }
          }));
          this._startingStyles = null;
          super.destroy();
      }
  }
  if (false) {
      /**
       * @type {?}
       * @private
       */
      DirectStylePlayer.prototype._startingStyles;
      /**
       * @type {?}
       * @private
       */
      DirectStylePlayer.prototype.__initialized;
      /**
       * @type {?}
       * @private
       */
      DirectStylePlayer.prototype._styles;
      /** @type {?} */
      DirectStylePlayer.prototype.element;
  }
  
  /**
   * @fileoverview added by tsickle
   * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
   */
  /** @type {?} */
  const KEYFRAMES_NAME_PREFIX = 'gen_css_kf_';
  /** @type {?} */
  const TAB_SPACE = ' ';
  class CssKeyframesDriver {
      constructor() {
          this._count = 0;
          this._head = document.querySelector('head');
          this._warningIssued = false;
      }
      /**
       * @param {?} prop
       * @return {?}
       */
      validateStyleProperty(prop) { return validateStyleProperty(prop); }
      /**
       * @param {?} element
       * @param {?} selector
       * @return {?}
       */
      matchesElement(element, selector) {
          return matchesElement(element, selector);
      }
      /**
       * @param {?} elm1
       * @param {?} elm2
       * @return {?}
       */
      containsElement(elm1, elm2) { return containsElement(elm1, elm2); }
      /**
       * @param {?} element
       * @param {?} selector
       * @param {?} multi
       * @return {?}
       */
      query(element, selector, multi) {
          return invokeQuery(element, selector, multi);
      }
      /**
       * @param {?} element
       * @param {?} prop
       * @param {?=} defaultValue
       * @return {?}
       */
      computeStyle(element, prop, defaultValue) {
          return (/** @type {?} */ (((/** @type {?} */ (window.getComputedStyle(element))))[prop]));
      }
      /**
       * @param {?} element
       * @param {?} name
       * @param {?} keyframes
       * @return {?}
       */
      buildKeyframeElement(element, name, keyframes) {
          keyframes = keyframes.map((/**
           * @param {?} kf
           * @return {?}
           */
          kf => hypenatePropsObject(kf)));
          /** @type {?} */
          let keyframeStr = `@keyframes ${name} {\n`;
          /** @type {?} */
          let tab = '';
          keyframes.forEach((/**
           * @param {?} kf
           * @return {?}
           */
          kf => {
              tab = TAB_SPACE;
              /** @type {?} */
              const offset = parseFloat(kf['offset']);
              keyframeStr += `${tab}${offset * 100}% {\n`;
              tab += TAB_SPACE;
              Object.keys(kf).forEach((/**
               * @param {?} prop
               * @return {?}
               */
              prop => {
                  /** @type {?} */
                  const value = kf[prop];
                  switch (prop) {
                      case 'offset':
                          return;
                      case 'easing':
                          if (value) {
                              keyframeStr += `${tab}animation-timing-function: ${value};\n`;
                          }
                          return;
                      default:
                          keyframeStr += `${tab}${prop}: ${value};\n`;
                          return;
                  }
              }));
              keyframeStr += `${tab}}\n`;
          }));
          keyframeStr += `}\n`;
          /** @type {?} */
          const kfElm = document.createElement('style');
          kfElm.innerHTML = keyframeStr;
          return kfElm;
      }
      /**
       * @param {?} element
       * @param {?} keyframes
       * @param {?} duration
       * @param {?} delay
       * @param {?} easing
       * @param {?=} previousPlayers
       * @param {?=} scrubberAccessRequested
       * @return {?}
       */
      animate(element, keyframes, duration, delay, easing, previousPlayers = [], scrubberAccessRequested) {
          if (scrubberAccessRequested) {
              this._notifyFaultyScrubber();
          }
          /** @type {?} */
          const previousCssKeyframePlayers = (/** @type {?} */ (previousPlayers.filter((/**
           * @param {?} player
           * @return {?}
           */
          player => player instanceof CssKeyframesPlayer))));
          /** @type {?} */
          const previousStyles = {};
          if (allowPreviousPlayerStylesMerge(duration, delay)) {
              previousCssKeyframePlayers.forEach((/**
               * @param {?} player
               * @return {?}
               */
              player => {
                  /** @type {?} */
                  let styles = player.currentSnapshot;
                  Object.keys(styles).forEach((/**
                   * @param {?} prop
                   * @return {?}
                   */
                  prop => previousStyles[prop] = styles[prop]));
              }));
          }
          keyframes = balancePreviousStylesIntoKeyframes(element, keyframes, previousStyles);
          /** @type {?} */
          const finalStyles = flattenKeyframesIntoStyles(keyframes);
          // if there is no animation then there is no point in applying
          // styles and waiting for an event to get fired. This causes lag.
          // It's better to just directly apply the styles to the element
          // via the direct styling animation player.
          if (duration == 0) {
              return new DirectStylePlayer(element, finalStyles);
          }
          /** @type {?} */
          const animationName = `${KEYFRAMES_NAME_PREFIX}${this._count++}`;
          /** @type {?} */
          const kfElm = this.buildKeyframeElement(element, animationName, keyframes);
          (/** @type {?} */ (document.querySelector('head'))).appendChild(kfElm);
          /** @type {?} */
          const specialStyles = packageNonAnimatableStyles(element, keyframes);
          /** @type {?} */
          const player = new CssKeyframesPlayer(element, keyframes, animationName, duration, delay, easing, finalStyles, specialStyles);
          player.onDestroy((/**
           * @return {?}
           */
          () => removeElement(kfElm)));
          return player;
      }
      /**
       * @private
       * @return {?}
       */
      _notifyFaultyScrubber() {
          if (!this._warningIssued) {
              console.warn('@angular/animations: please load the web-animations.js polyfill to allow programmatic access...\n', '  visit http://bit.ly/IWukam to learn more about using the web-animation-js polyfill.');
              this._warningIssued = true;
          }
      }
  }
  if (false) {
      /**
       * @type {?}
       * @private
       */
      CssKeyframesDriver.prototype._count;
      /**
       * @type {?}
       * @private
       */
      CssKeyframesDriver.prototype._head;
      /**
       * @type {?}
       * @private
       */
      CssKeyframesDriver.prototype._warningIssued;
  }
  /**
   * @param {?} keyframes
   * @return {?}
   */
  function flattenKeyframesIntoStyles(keyframes) {
      /** @type {?} */
      let flatKeyframes = {};
      if (keyframes) {
          /** @type {?} */
          const kfs = Array.isArray(keyframes) ? keyframes : [keyframes];
          kfs.forEach((/**
           * @param {?} kf
           * @return {?}
           */
          kf => {
              Object.keys(kf).forEach((/**
               * @param {?} prop
               * @return {?}
               */
              prop => {
                  if (prop == 'offset' || prop == 'easing')
                      return;
                  flatKeyframes[prop] = kf[prop];
              }));
          }));
      }
      return flatKeyframes;
  }
  /**
   * @param {?} node
   * @return {?}
   */
  function removeElement(node) {
      node.parentNode.removeChild(node);
  }
  
  /**
   * @fileoverview added by tsickle
   * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
   */
  class WebAnimationsPlayer {
      /**
       * @param {?} element
       * @param {?} keyframes
       * @param {?} options
       * @param {?=} _specialStyles
       */
      constructor(element, keyframes, options, _specialStyles) {
          this.element = element;
          this.keyframes = keyframes;
          this.options = options;
          this._specialStyles = _specialStyles;
          this._onDoneFns = [];
          this._onStartFns = [];
          this._onDestroyFns = [];
          this._initialized = false;
          this._finished = false;
          this._started = false;
          this._destroyed = false;
          this.time = 0;
          this.parentPlayer = null;
          this.currentSnapshot = {};
          this._duration = (/** @type {?} */ (options['duration']));
          this._delay = (/** @type {?} */ (options['delay'])) || 0;
          this.time = this._duration + this._delay;
      }
      /**
       * @private
       * @return {?}
       */
      _onFinish() {
          if (!this._finished) {
              this._finished = true;
              this._onDoneFns.forEach((/**
               * @param {?} fn
               * @return {?}
               */
              fn => fn()));
              this._onDoneFns = [];
          }
      }
      /**
       * @return {?}
       */
      init() {
          this._buildPlayer();
          this._preparePlayerBeforeStart();
      }
      /**
       * @private
       * @return {?}
       */
      _buildPlayer() {
          if (this._initialized)
              return;
          this._initialized = true;
          /** @type {?} */
          const keyframes = this.keyframes;
          ((/** @type {?} */ (this))).domPlayer =
              this._triggerWebAnimation(this.element, keyframes, this.options);
          this._finalKeyframe = keyframes.length ? keyframes[keyframes.length - 1] : {};
          this.domPlayer.addEventListener('finish', (/**
           * @return {?}
           */
          () => this._onFinish()));
      }
      /**
       * @private
       * @return {?}
       */
      _preparePlayerBeforeStart() {
          // this is required so that the player doesn't start to animate right away
          if (this._delay) {
              this._resetDomPlayerState();
          }
          else {
              this.domPlayer.pause();
          }
      }
      /**
       * \@internal
       * @param {?} element
       * @param {?} keyframes
       * @param {?} options
       * @return {?}
       */
      _triggerWebAnimation(element, keyframes, options) {
          // jscompiler doesn't seem to know animate is a native property because it's not fully
          // supported yet across common browsers (we polyfill it for Edge/Safari) [CL #143630929]
          return (/** @type {?} */ (element['animate'](keyframes, options)));
      }
      /**
       * @param {?} fn
       * @return {?}
       */
      onStart(fn) { this._onStartFns.push(fn); }
      /**
       * @param {?} fn
       * @return {?}
       */
      onDone(fn) { this._onDoneFns.push(fn); }
      /**
       * @param {?} fn
       * @return {?}
       */
      onDestroy(fn) { this._onDestroyFns.push(fn); }
      /**
       * @return {?}
       */
      play() {
          this._buildPlayer();
          if (!this.hasStarted()) {
              this._onStartFns.forEach((/**
               * @param {?} fn
               * @return {?}
               */
              fn => fn()));
              this._onStartFns = [];
              this._started = true;
              if (this._specialStyles) {
                  this._specialStyles.start();
              }
          }
          this.domPlayer.play();
      }
      /**
       * @return {?}
       */
      pause() {
          this.init();
          this.domPlayer.pause();
      }
      /**
       * @return {?}
       */
      finish() {
          this.init();
          if (this._specialStyles) {
              this._specialStyles.finish();
          }
          this._onFinish();
          this.domPlayer.finish();
      }
      /**
       * @return {?}
       */
      reset() {
          this._resetDomPlayerState();
          this._destroyed = false;
          this._finished = false;
          this._started = false;
      }
      /**
       * @private
       * @return {?}
       */
      _resetDomPlayerState() {
          if (this.domPlayer) {
              this.domPlayer.cancel();
          }
      }
      /**
       * @return {?}
       */
      restart() {
          this.reset();
          this.play();
      }
      /**
       * @return {?}
       */
      hasStarted() { return this._started; }
      /**
       * @return {?}
       */
      destroy() {
          if (!this._destroyed) {
              this._destroyed = true;
              this._resetDomPlayerState();
              this._onFinish();
              if (this._specialStyles) {
                  this._specialStyles.destroy();
              }
              this._onDestroyFns.forEach((/**
               * @param {?} fn
               * @return {?}
               */
              fn => fn()));
              this._onDestroyFns = [];
          }
      }
      /**
       * @param {?} p
       * @return {?}
       */
      setPosition(p) { this.domPlayer.currentTime = p * this.time; }
      /**
       * @return {?}
       */
      getPosition() { return this.domPlayer.currentTime / this.time; }
      /**
       * @return {?}
       */
      get totalTime() { return this._delay + this._duration; }
      /**
       * @return {?}
       */
      beforeDestroy() {
          /** @type {?} */
          const styles = {};
          if (this.hasStarted()) {
              Object.keys(this._finalKeyframe).forEach((/**
               * @param {?} prop
               * @return {?}
               */
              prop => {
                  if (prop != 'offset') {
                      styles[prop] =
                          this._finished ? this._finalKeyframe[prop] : computeStyle(this.element, prop);
                  }
              }));
          }
          this.currentSnapshot = styles;
      }
      /**
       * \@internal
       * @param {?} phaseName
       * @return {?}
       */
      triggerCallback(phaseName) {
          /** @type {?} */
          const methods = phaseName == 'start' ? this._onStartFns : this._onDoneFns;
          methods.forEach((/**
           * @param {?} fn
           * @return {?}
           */
          fn => fn()));
          methods.length = 0;
      }
  }
  if (false) {
      /**
       * @type {?}
       * @private
       */
      WebAnimationsPlayer.prototype._onDoneFns;
      /**
       * @type {?}
       * @private
       */
      WebAnimationsPlayer.prototype._onStartFns;
      /**
       * @type {?}
       * @private
       */
      WebAnimationsPlayer.prototype._onDestroyFns;
      /**
       * @type {?}
       * @private
       */
      WebAnimationsPlayer.prototype._duration;
      /**
       * @type {?}
       * @private
       */
      WebAnimationsPlayer.prototype._delay;
      /**
       * @type {?}
       * @private
       */
      WebAnimationsPlayer.prototype._initialized;
      /**
       * @type {?}
       * @private
       */
      WebAnimationsPlayer.prototype._finished;
      /**
       * @type {?}
       * @private
       */
      WebAnimationsPlayer.prototype._started;
      /**
       * @type {?}
       * @private
       */
      WebAnimationsPlayer.prototype._destroyed;
      /**
       * @type {?}
       * @private
       */
      WebAnimationsPlayer.prototype._finalKeyframe;
      /** @type {?} */
      WebAnimationsPlayer.prototype.domPlayer;
      /** @type {?} */
      WebAnimationsPlayer.prototype.time;
      /** @type {?} */
      WebAnimationsPlayer.prototype.parentPlayer;
      /** @type {?} */
      WebAnimationsPlayer.prototype.currentSnapshot;
      /** @type {?} */
      WebAnimationsPlayer.prototype.element;
      /** @type {?} */
      WebAnimationsPlayer.prototype.keyframes;
      /** @type {?} */
      WebAnimationsPlayer.prototype.options;
      /**
       * @type {?}
       * @private
       */
      WebAnimationsPlayer.prototype._specialStyles;
  }
  
  /**
   * @fileoverview added by tsickle
   * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
   */
  class WebAnimationsDriver {
      constructor() {
          this._isNativeImpl = /\{\s*\[native\s+code\]\s*\}/.test(getElementAnimateFn().toString());
          this._cssKeyframesDriver = new CssKeyframesDriver();
      }
      /**
       * @param {?} prop
       * @return {?}
       */
      validateStyleProperty(prop) { return validateStyleProperty(prop); }
      /**
       * @param {?} element
       * @param {?} selector
       * @return {?}
       */
      matchesElement(element, selector) {
          return matchesElement(element, selector);
      }
      /**
       * @param {?} elm1
       * @param {?} elm2
       * @return {?}
       */
      containsElement(elm1, elm2) { return containsElement(elm1, elm2); }
      /**
       * @param {?} element
       * @param {?} selector
       * @param {?} multi
       * @return {?}
       */
      query(element, selector, multi) {
          return invokeQuery(element, selector, multi);
      }
      /**
       * @param {?} element
       * @param {?} prop
       * @param {?=} defaultValue
       * @return {?}
       */
      computeStyle(element, prop, defaultValue) {
          return (/** @type {?} */ (((/** @type {?} */ (window.getComputedStyle(element))))[prop]));
      }
      /**
       * @param {?} supported
       * @return {?}
       */
      overrideWebAnimationsSupport(supported) { this._isNativeImpl = supported; }
      /**
       * @param {?} element
       * @param {?} keyframes
       * @param {?} duration
       * @param {?} delay
       * @param {?} easing
       * @param {?=} previousPlayers
       * @param {?=} scrubberAccessRequested
       * @return {?}
       */
      animate(element, keyframes, duration, delay, easing, previousPlayers = [], scrubberAccessRequested) {
          /** @type {?} */
          const useKeyframes = !scrubberAccessRequested && !this._isNativeImpl;
          if (useKeyframes) {
              return this._cssKeyframesDriver.animate(element, keyframes, duration, delay, easing, previousPlayers);
          }
          /** @type {?} */
          const fill = delay == 0 ? 'both' : 'forwards';
          /** @type {?} */
          const playerOptions = { duration, delay, fill };
          // we check for this to avoid having a null|undefined value be present
          // for the easing (which results in an error for certain browsers #9752)
          if (easing) {
              playerOptions['easing'] = easing;
          }
          /** @type {?} */
          const previousStyles = {};
          /** @type {?} */
          const previousWebAnimationPlayers = (/** @type {?} */ (previousPlayers.filter((/**
           * @param {?} player
           * @return {?}
           */
          player => player instanceof WebAnimationsPlayer))));
          if (allowPreviousPlayerStylesMerge(duration, delay)) {
              previousWebAnimationPlayers.forEach((/**
               * @param {?} player
               * @return {?}
               */
              player => {
                  /** @type {?} */
                  let styles = player.currentSnapshot;
                  Object.keys(styles).forEach((/**
                   * @param {?} prop
                   * @return {?}
                   */
                  prop => previousStyles[prop] = styles[prop]));
              }));
          }
          keyframes = keyframes.map((/**
           * @param {?} styles
           * @return {?}
           */
          styles => copyStyles(styles, false)));
          keyframes = balancePreviousStylesIntoKeyframes(element, keyframes, previousStyles);
          /** @type {?} */
          const specialStyles = packageNonAnimatableStyles(element, keyframes);
          return new WebAnimationsPlayer(element, keyframes, playerOptions, specialStyles);
      }
  }
  if (false) {
      /**
       * @type {?}
       * @private
       */
      WebAnimationsDriver.prototype._isNativeImpl;
      /**
       * @type {?}
       * @private
       */
      WebAnimationsDriver.prototype._cssKeyframesDriver;
  }
  /**
   * @return {?}
   */
  function supportsWebAnimations() {
      return typeof getElementAnimateFn() === 'function';
  }
  /**
   * @return {?}
   */
  function getElementAnimateFn() {
      return (isBrowser() && ((/** @type {?} */ (Element))).prototype['animate']) || {};
  }
  
  /**
   * @fileoverview added by tsickle
   * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
   */
  
  /**
   * @fileoverview added by tsickle
   * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
   */
  
  /**
   * @fileoverview added by tsickle
   * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
   */
  
  /**
   * @fileoverview added by tsickle
   * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
   */
  
  /**
   * Generated bundle index. Do not edit.
   */
  
  export { SpecialCasedStyles as ɵangular_packages_animations_browser_browser_a, AnimationDriver, AnimationDriver as ɵAnimationDriver, Animation as ɵAnimation, AnimationStyleNormalizer as ɵAnimationStyleNormalizer, NoopAnimationStyleNormalizer as ɵNoopAnimationStyleNormalizer, WebAnimationsStyleNormalizer as ɵWebAnimationsStyleNormalizer, NoopAnimationDriver as ɵNoopAnimationDriver, AnimationEngine as ɵAnimationEngine, CssKeyframesDriver as ɵCssKeyframesDriver, CssKeyframesPlayer as ɵCssKeyframesPlayer, containsElement as ɵcontainsElement, invokeQuery as ɵinvokeQuery, matchesElement as ɵmatchesElement, validateStyleProperty as ɵvalidateStyleProperty, WebAnimationsDriver as ɵWebAnimationsDriver, supportsWebAnimations as ɵsupportsWebAnimations, WebAnimationsPlayer as ɵWebAnimationsPlayer, allowPreviousPlayerStylesMerge as ɵallowPreviousPlayerStylesMerge };
  //# sourceMappingURL=browser.js.map
  