UNPKG

@angular/platform-server

Version:

Angular - library for using Angular in Node.js

1,316 lines (1,304 loc) 343 kB
/** * @license Angular v5.0.0-rc.8 * (c) 2010-2017 Google, Inc. https://angular.io/ * License: MIT */ (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/platform-browser'), require('@angular/animations'), require('@angular/common'), require('rxjs/observable/of'), require('rxjs/operator/concatMap'), require('rxjs/operator/filter'), require('rxjs/operator/map'), require('rxjs/Observable'), require('@angular/http'), require('@angular/platform-browser-dynamic'), require('@angular/platform-browser/animations'), require('rxjs/Subject'), require('url'), require('@angular/compiler'), require('rxjs/operator/first'), require('rxjs/operator/toPromise')) : typeof define === 'function' && define.amd ? define('@angular/platform-server', ['exports', '@angular/core', '@angular/platform-browser', '@angular/animations', '@angular/common', 'rxjs/observable/of', 'rxjs/operator/concatMap', 'rxjs/operator/filter', 'rxjs/operator/map', 'rxjs/Observable', '@angular/http', '@angular/platform-browser-dynamic', '@angular/platform-browser/animations', 'rxjs/Subject', 'url', '@angular/compiler', 'rxjs/operator/first', 'rxjs/operator/toPromise'], factory) : (factory((global.ng = global.ng || {}, global.ng.platformServer = {}),global.ng.core,global.ng.platformBrowser,global.ng.animations,global.ng.common,global.rxjs_observable_of,global.rxjs_operator_concatMap,global.Rx.Observable.prototype,global.rxjs_operator_map,global.Rx,global.ng.http,global.ng.platformBrowserDynamic,global._angular_platformBrowser_animations,global.Rx,global.url,global.ng.compiler,global.Rx.Observable.prototype,global.Rx.Observable.prototype)); }(this, (function (exports,_angular_core,_angular_platformBrowser,_angular_animations,_angular_common,rxjs_observable_of,rxjs_operator_concatMap,rxjs_operator_filter,rxjs_operator_map,rxjs_Observable,_angular_http,_angular_platformBrowserDynamic,_angular_platformBrowser_animations,rxjs_Subject,url,_angular_compiler,rxjs_operator_first,rxjs_operator_toPromise) { 'use strict'; /*! ***************************************************************************** Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT. See the Apache Version 2.0 License for specific language governing permissions and limitations under the License. ***************************************************************************** */ /* global Reflect, Promise */ var extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; function __extends(d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); } /*! ***************************************************************************** Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT. See the Apache Version 2.0 License for specific language governing permissions and limitations under the License. ***************************************************************************** */ /* global Reflect, Promise */ var extendStatics$1 = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; function __extends$1(d, b) { extendStatics$1(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); } /** * @license Angular v4.3.6 * (c) 2010-2017 Google, Inc. https://angular.io/ * License: MIT */ /** * @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 */ function optimizeGroupPlayer(players) { switch (players.length) { case 0: return new _angular_animations.NoopAnimationPlayer(); case 1: return players[0]; default: return new _angular_animations.ɵAnimationGroupPlayer(players); } } function normalizeKeyframes(driver, normalizer, element, keyframes, preStyles, postStyles) { if (preStyles === void 0) { preStyles = {}; } if (postStyles === void 0) { postStyles = {}; } var errors = []; var normalizedKeyframes = []; var previousOffset = -1; var previousKeyframe = null; keyframes.forEach(function (kf) { var offset = kf['offset']; var isSameOffset = offset == previousOffset; var normalizedKeyframe = (isSameOffset && previousKeyframe) || {}; Object.keys(kf).forEach(function (prop) { var normalizedProp = prop; var normalizedValue = kf[prop]; if (prop !== 'offset') { normalizedProp = normalizer.normalizePropertyName(normalizedProp, errors); switch (normalizedValue) { case _angular_animations.ɵPRE_STYLE: normalizedValue = preStyles[prop]; break; case _angular_animations.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) { var LINE_START = '\n - '; throw new Error("Unable to animate due to the following errors:" + LINE_START + errors.join(LINE_START)); } return normalizedKeyframes; } function listenOnPlayer(player, eventName, event, callback) { switch (eventName) { case 'start': player.onStart(function () { return callback(event && copyAnimationEvent(event, 'start', player.totalTime)); }); break; case 'done': player.onDone(function () { return callback(event && copyAnimationEvent(event, 'done', player.totalTime)); }); break; case 'destroy': player.onDestroy(function () { return callback(event && copyAnimationEvent(event, 'destroy', player.totalTime)); }); break; } } function copyAnimationEvent(e, phaseName, totalTime) { var event = makeAnimationEvent(e.element, e.triggerName, e.fromState, e.toState, phaseName || e.phaseName, totalTime == undefined ? e.totalTime : totalTime); var data = e['_data']; if (data != null) { event['_data'] = data; } return event; } function makeAnimationEvent(element, triggerName, fromState, toState, phaseName, totalTime) { if (phaseName === void 0) { phaseName = ''; } if (totalTime === void 0) { totalTime = 0; } return { element: element, triggerName: triggerName, fromState: fromState, toState: toState, phaseName: phaseName, totalTime: totalTime }; } function getOrSetAsInMap(map$$1, key, defaultValue) { var value; if (map$$1 instanceof Map) { value = map$$1.get(key); if (!value) { map$$1.set(key, value = defaultValue); } } else { value = map$$1[key]; if (!value) { value = map$$1[key] = defaultValue; } } return value; } function parseTimelineCommand(command) { var separatorPos = command.indexOf(':'); var id = command.substring(1, separatorPos); var action = command.substr(separatorPos + 1); return [id, action]; } var _contains = function (elm1, elm2) { return false; }; var _matches = function (element, selector) { return false; }; var _query = function (element, selector, multi) { return []; }; if (typeof Element != 'undefined') { // this is well supported in all browsers _contains = function (elm1, elm2) { return elm1.contains(elm2); }; if (Element.prototype.matches) { _matches = function (element, selector) { return element.matches(selector); }; } else { var proto = Element.prototype; var fn_1 = proto.matchesSelector || proto.mozMatchesSelector || proto.msMatchesSelector || proto.oMatchesSelector || proto.webkitMatchesSelector; if (fn_1) { _matches = function (element, selector) { return fn_1.apply(element, [selector]); }; } } _query = function (element, selector, multi) { var results = []; if (multi) { results.push.apply(results, element.querySelectorAll(selector)); } else { var elm = element.querySelector(selector); if (elm) { results.push(elm); } } return results; }; } var matchesElement = _matches; var containsElement = _contains; var invokeQuery = _query; /** * @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 */ /** * @experimental */ var NoopAnimationDriver = (function () { function NoopAnimationDriver() { } NoopAnimationDriver.prototype.matchesElement = function (element, selector) { return matchesElement(element, selector); }; NoopAnimationDriver.prototype.containsElement = function (elm1, elm2) { return containsElement(elm1, elm2); }; NoopAnimationDriver.prototype.query = function (element, selector, multi) { return invokeQuery(element, selector, multi); }; NoopAnimationDriver.prototype.computeStyle = function (element, prop, defaultValue) { return defaultValue || ''; }; NoopAnimationDriver.prototype.animate = function (element, keyframes, duration, delay, easing, previousPlayers) { if (previousPlayers === void 0) { previousPlayers = []; } return new _angular_animations.NoopAnimationPlayer(); }; return NoopAnimationDriver; }()); /** * @experimental */ var AnimationDriver = (function () { function AnimationDriver() { } return AnimationDriver; }()); AnimationDriver.NOOP = new NoopAnimationDriver(); /** * @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 */ var ONE_SECOND = 1000; var SUBSTITUTION_EXPR_START = '{{'; var SUBSTITUTION_EXPR_END = '}}'; var ENTER_CLASSNAME = 'ng-enter'; var LEAVE_CLASSNAME = 'ng-leave'; var ENTER_SELECTOR = '.ng-enter'; var LEAVE_SELECTOR = '.ng-leave'; var NG_TRIGGER_CLASSNAME = 'ng-trigger'; var NG_TRIGGER_SELECTOR = '.ng-trigger'; var NG_ANIMATING_CLASSNAME = 'ng-animating'; var NG_ANIMATING_SELECTOR = '.ng-animating'; function resolveTimingValue(value) { if (typeof value == 'number') return value; var matches = value.match(/^(-?[\.\d]+)(m?s)/); if (!matches || matches.length < 2) return 0; return _convertTimeValueToMS(parseFloat(matches[1]), matches[2]); } function _convertTimeValueToMS(value, unit) { switch (unit) { case 's': return value * ONE_SECOND; default: return value; } } function resolveTiming(timings, errors, allowNegativeValues) { return timings.hasOwnProperty('duration') ? timings : parseTimeExpression(timings, errors, allowNegativeValues); } function parseTimeExpression(exp, errors, allowNegativeValues) { var regex = /^(-?[\.\d]+)(m?s)(?:\s+(-?[\.\d]+)(m?s))?(?:\s+([-a-z]+(?:\(.+?\))?))?$/i; var duration; var delay = 0; var easing = ''; if (typeof exp === 'string') { var 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]); var delayMatch = matches[3]; if (delayMatch != null) { delay = _convertTimeValueToMS(Math.floor(parseFloat(delayMatch)), matches[4]); } var easingVal = matches[5]; if (easingVal) { easing = easingVal; } } else { duration = exp; } if (!allowNegativeValues) { var containsErrors = false; var 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: duration, delay: delay, easing: easing }; } function copyObj(obj, destination) { if (destination === void 0) { destination = {}; } Object.keys(obj).forEach(function (prop) { destination[prop] = obj[prop]; }); return destination; } function copyStyles(styles, readPrototype, destination) { if (destination === void 0) { destination = {}; } if (readPrototype) { // we make use of a for-in loop so that the // prototypically inherited properties are // revealed from the backFill map for (var prop in styles) { destination[prop] = styles[prop]; } } else { copyObj(styles, destination); } return destination; } function setStyles(element, styles) { if (element['style']) { Object.keys(styles).forEach(function (prop) { var camelProp = dashCaseToCamelCase(prop); element.style[camelProp] = styles[prop]; }); } } function eraseStyles(element, styles) { if (element['style']) { Object.keys(styles).forEach(function (prop) { var camelProp = dashCaseToCamelCase(prop); element.style[camelProp] = ''; }); } } function normalizeAnimationEntry(steps) { if (Array.isArray(steps)) { if (steps.length == 1) return steps[0]; return _angular_animations.sequence(steps); } return steps; } function validateStyleParams(value, options, errors) { var params = options.params || {}; var matches = extractStyleParams(value); if (matches.length) { matches.forEach(function (varName) { if (!params.hasOwnProperty(varName)) { errors.push("Unable to resolve the local animation param " + varName + " in the given list of values"); } }); } } var PARAM_REGEX = new RegExp(SUBSTITUTION_EXPR_START + "\\s*(.+?)\\s*" + SUBSTITUTION_EXPR_END, 'g'); function extractStyleParams(value) { var params = []; if (typeof value === 'string') { var val = value.toString(); var match = void 0; while (match = PARAM_REGEX.exec(val)) { params.push(match[1]); } PARAM_REGEX.lastIndex = 0; } return params; } function interpolateParams(value, params, errors) { var original = value.toString(); var str = original.replace(PARAM_REGEX, function (_, varName) { var localVal = params[varName]; // this means that the value was never overidden 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; } function iteratorToArray(iterator) { var arr = []; var item = iterator.next(); while (!item.done) { arr.push(item.value); item = iterator.next(); } return arr; } var DASH_CASE_REGEXP = /-+([a-z0-9])/g; function dashCaseToCamelCase(input) { return input.replace(DASH_CASE_REGEXP, function () { var m = []; for (var _i = 0; _i < arguments.length; _i++) { m[_i] = arguments[_i]; } return m[1].toUpperCase(); }); } function allowPreviousPlayerStylesMerge(duration, delay) { return duration === 0 || delay === 0; } /** * @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 */ var EMPTY_ANIMATION_OPTIONS = {}; /** * @abstract */ var Ast = (function () { function Ast() { this.options = EMPTY_ANIMATION_OPTIONS; } /** * @abstract * @param {?} ast * @param {?} context * @return {?} */ Ast.prototype.visit = function (ast, context) { }; Object.defineProperty(Ast.prototype, "params", { /** * @return {?} */ get: function () { return this.options['params'] || null; }, enumerable: true, configurable: true }); return Ast; }()); var TriggerAst = (function (_super) { __extends$1(TriggerAst, _super); /** * @param {?} name * @param {?} states * @param {?} transitions */ function TriggerAst(name, states, transitions) { var _this = _super.call(this) || this; _this.name = name; _this.states = states; _this.transitions = transitions; _this.queryCount = 0; _this.depCount = 0; return _this; } /** * @param {?} visitor * @param {?} context * @return {?} */ TriggerAst.prototype.visit = function (visitor, context) { return visitor.visitTrigger(this, context); }; return TriggerAst; }(Ast)); var StateAst = (function (_super) { __extends$1(StateAst, _super); /** * @param {?} name * @param {?} style */ function StateAst(name, style$$1) { var _this = _super.call(this) || this; _this.name = name; _this.style = style$$1; return _this; } /** * @param {?} visitor * @param {?} context * @return {?} */ StateAst.prototype.visit = function (visitor, context) { return visitor.visitState(this, context); }; return StateAst; }(Ast)); var TransitionAst = (function (_super) { __extends$1(TransitionAst, _super); /** * @param {?} matchers * @param {?} animation */ function TransitionAst(matchers, animation) { var _this = _super.call(this) || this; _this.matchers = matchers; _this.animation = animation; _this.queryCount = 0; _this.depCount = 0; return _this; } /** * @param {?} visitor * @param {?} context * @return {?} */ TransitionAst.prototype.visit = function (visitor, context) { return visitor.visitTransition(this, context); }; return TransitionAst; }(Ast)); var SequenceAst = (function (_super) { __extends$1(SequenceAst, _super); /** * @param {?} steps */ function SequenceAst(steps) { var _this = _super.call(this) || this; _this.steps = steps; return _this; } /** * @param {?} visitor * @param {?} context * @return {?} */ SequenceAst.prototype.visit = function (visitor, context) { return visitor.visitSequence(this, context); }; return SequenceAst; }(Ast)); var GroupAst = (function (_super) { __extends$1(GroupAst, _super); /** * @param {?} steps */ function GroupAst(steps) { var _this = _super.call(this) || this; _this.steps = steps; return _this; } /** * @param {?} visitor * @param {?} context * @return {?} */ GroupAst.prototype.visit = function (visitor, context) { return visitor.visitGroup(this, context); }; return GroupAst; }(Ast)); var AnimateAst = (function (_super) { __extends$1(AnimateAst, _super); /** * @param {?} timings * @param {?} style */ function AnimateAst(timings, style$$1) { var _this = _super.call(this) || this; _this.timings = timings; _this.style = style$$1; return _this; } /** * @param {?} visitor * @param {?} context * @return {?} */ AnimateAst.prototype.visit = function (visitor, context) { return visitor.visitAnimate(this, context); }; return AnimateAst; }(Ast)); var StyleAst = (function (_super) { __extends$1(StyleAst, _super); /** * @param {?} styles * @param {?} easing * @param {?} offset */ function StyleAst(styles, easing, offset) { var _this = _super.call(this) || this; _this.styles = styles; _this.easing = easing; _this.offset = offset; _this.isEmptyStep = false; _this.containsDynamicStyles = false; return _this; } /** * @param {?} visitor * @param {?} context * @return {?} */ StyleAst.prototype.visit = function (visitor, context) { return visitor.visitStyle(this, context); }; return StyleAst; }(Ast)); var KeyframesAst = (function (_super) { __extends$1(KeyframesAst, _super); /** * @param {?} styles */ function KeyframesAst(styles) { var _this = _super.call(this) || this; _this.styles = styles; return _this; } /** * @param {?} visitor * @param {?} context * @return {?} */ KeyframesAst.prototype.visit = function (visitor, context) { return visitor.visitKeyframes(this, context); }; return KeyframesAst; }(Ast)); var ReferenceAst = (function (_super) { __extends$1(ReferenceAst, _super); /** * @param {?} animation */ function ReferenceAst(animation) { var _this = _super.call(this) || this; _this.animation = animation; return _this; } /** * @param {?} visitor * @param {?} context * @return {?} */ ReferenceAst.prototype.visit = function (visitor, context) { return visitor.visitReference(this, context); }; return ReferenceAst; }(Ast)); var AnimateChildAst = (function (_super) { __extends$1(AnimateChildAst, _super); function AnimateChildAst() { return _super.call(this) || this; } /** * @param {?} visitor * @param {?} context * @return {?} */ AnimateChildAst.prototype.visit = function (visitor, context) { return visitor.visitAnimateChild(this, context); }; return AnimateChildAst; }(Ast)); var AnimateRefAst = (function (_super) { __extends$1(AnimateRefAst, _super); /** * @param {?} animation */ function AnimateRefAst(animation) { var _this = _super.call(this) || this; _this.animation = animation; return _this; } /** * @param {?} visitor * @param {?} context * @return {?} */ AnimateRefAst.prototype.visit = function (visitor, context) { return visitor.visitAnimateRef(this, context); }; return AnimateRefAst; }(Ast)); var QueryAst = (function (_super) { __extends$1(QueryAst, _super); /** * @param {?} selector * @param {?} limit * @param {?} optional * @param {?} includeSelf * @param {?} animation */ function QueryAst(selector, limit, optional, includeSelf, animation) { var _this = _super.call(this) || this; _this.selector = selector; _this.limit = limit; _this.optional = optional; _this.includeSelf = includeSelf; _this.animation = animation; return _this; } /** * @param {?} visitor * @param {?} context * @return {?} */ QueryAst.prototype.visit = function (visitor, context) { return visitor.visitQuery(this, context); }; return QueryAst; }(Ast)); var StaggerAst = (function (_super) { __extends$1(StaggerAst, _super); /** * @param {?} timings * @param {?} animation */ function StaggerAst(timings, animation) { var _this = _super.call(this) || this; _this.timings = timings; _this.animation = animation; return _this; } /** * @param {?} visitor * @param {?} context * @return {?} */ StaggerAst.prototype.visit = function (visitor, context) { return visitor.visitStagger(this, context); }; return StaggerAst; }(Ast)); var TimingAst = (function (_super) { __extends$1(TimingAst, _super); /** * @param {?} duration * @param {?=} delay * @param {?=} easing */ function TimingAst(duration, delay, easing) { if (delay === void 0) { delay = 0; } if (easing === void 0) { easing = null; } var _this = _super.call(this) || this; _this.duration = duration; _this.delay = delay; _this.easing = easing; return _this; } /** * @param {?} visitor * @param {?} context * @return {?} */ TimingAst.prototype.visit = function (visitor, context) { return visitor.visitTiming(this, context); }; return TimingAst; }(Ast)); var DynamicTimingAst = (function (_super) { __extends$1(DynamicTimingAst, _super); /** * @param {?} value */ function DynamicTimingAst(value) { var _this = _super.call(this, 0, 0, '') || this; _this.value = value; return _this; } /** * @param {?} visitor * @param {?} context * @return {?} */ DynamicTimingAst.prototype.visit = function (visitor, context) { return visitor.visitTiming(this, context); }; return DynamicTimingAst; }(TimingAst)); /** * @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 */ /** * @param {?} visitor * @param {?} node * @param {?} context * @return {?} */ function visitAnimationNode(visitor, node, context) { switch (node.type) { case 7 /* Trigger */: return visitor.visitTrigger(/** @type {?} */ (node), context); case 0 /* State */: return visitor.visitState(/** @type {?} */ (node), context); case 1 /* Transition */: return visitor.visitTransition(/** @type {?} */ (node), context); case 2 /* Sequence */: return visitor.visitSequence(/** @type {?} */ (node), context); case 3 /* Group */: return visitor.visitGroup(/** @type {?} */ (node), context); case 4 /* Animate */: return visitor.visitAnimate(/** @type {?} */ (node), context); case 5 /* Keyframes */: return visitor.visitKeyframes(/** @type {?} */ (node), context); case 6 /* Style */: return visitor.visitStyle(/** @type {?} */ (node), context); case 8 /* Reference */: return visitor.visitReference(/** @type {?} */ (node), context); case 9 /* AnimateChild */: return visitor.visitAnimateChild(/** @type {?} */ (node), context); case 10 /* AnimateRef */: return visitor.visitAnimateRef(/** @type {?} */ (node), context); case 11 /* Query */: return visitor.visitQuery(/** @type {?} */ (node), context); case 12 /* Stagger */: return visitor.visitStagger(/** @type {?} */ (node), context); default: throw new Error("Unable to resolve animation metadata node #" + node.type); } } /** * @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 */ var ANY_STATE = '*'; /** * @param {?} transitionValue * @param {?} errors * @return {?} */ function parseTransitionExpr(transitionValue, errors) { var /** @type {?} */ expressions = []; if (typeof transitionValue == 'string') { ((transitionValue)) .split(/\s*,\s*/) .forEach(function (str) { return 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] == ':') { eventStr = parseAnimationAlias(eventStr, errors); } var /** @type {?} */ 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; } var /** @type {?} */ fromState = match[1]; var /** @type {?} */ separator = match[2]; var /** @type {?} */ toState = match[3]; expressions.push(makeLambdaFromStates(fromState, toState)); var /** @type {?} */ 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'; default: errors.push("The transition alias value \"" + alias + "\" is not supported"); return '* => *'; } } /** * @param {?} lhs * @param {?} rhs * @return {?} */ function makeLambdaFromStates(lhs, rhs) { return function (fromState, toState) { var /** @type {?} */ lhsMatch = lhs == ANY_STATE || lhs == fromState; var /** @type {?} */ rhsMatch = rhs == ANY_STATE || rhs == toState; if (!lhsMatch && typeof fromState === 'boolean') { lhsMatch = fromState ? lhs === 'true' : lhs === 'false'; } if (!rhsMatch && typeof toState === 'boolean') { rhsMatch = toState ? rhs === 'true' : rhs === 'false'; } return lhsMatch && rhsMatch; }; } /** * @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 */ var SELF_TOKEN = ':self'; var SELF_TOKEN_REGEX = new RegExp("s*" + SELF_TOKEN + "s*,?", 'g'); /** * @param {?} metadata * @param {?} errors * @return {?} */ function buildAnimationAst(metadata, errors) { return new AnimationAstBuilderVisitor().build(metadata, errors); } var LEAVE_TOKEN = ':leave'; var LEAVE_TOKEN_REGEX = new RegExp(LEAVE_TOKEN, 'g'); var ENTER_TOKEN = ':enter'; var ENTER_TOKEN_REGEX = new RegExp(ENTER_TOKEN, 'g'); var ROOT_SELECTOR = ''; var AnimationAstBuilderVisitor = (function () { function AnimationAstBuilderVisitor() { } /** * @param {?} metadata * @param {?} errors * @return {?} */ AnimationAstBuilderVisitor.prototype.build = function (metadata, errors) { var /** @type {?} */ context = new AnimationAstBuilderContext(errors); this._resetContextStyleTimingState(context); return (visitAnimationNode(this, normalizeAnimationEntry(metadata), context)); }; /** * @param {?} context * @return {?} */ AnimationAstBuilderVisitor.prototype._resetContextStyleTimingState = function (context) { context.currentQuerySelector = ROOT_SELECTOR; context.collectedStyles = {}; context.collectedStyles[ROOT_SELECTOR] = {}; context.currentTime = 0; }; /** * @param {?} metadata * @param {?} context * @return {?} */ AnimationAstBuilderVisitor.prototype.visitTrigger = function (metadata, context) { var _this = this; var /** @type {?} */ queryCount = context.queryCount = 0; var /** @type {?} */ depCount = context.depCount = 0; var /** @type {?} */ states = []; var /** @type {?} */ transitions = []; metadata.definitions.forEach(function (def) { _this._resetContextStyleTimingState(context); if (def.type == 0 /* State */) { var /** @type {?} */ stateDef_1 = (def); var /** @type {?} */ name = stateDef_1.name; name.split(/\s*,\s*/).forEach(function (n) { stateDef_1.name = n; states.push(_this.visitState(stateDef_1, context)); }); stateDef_1.name = name; } else if (def.type == 1 /* Transition */) { var /** @type {?} */ 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()'); } }); var /** @type {?} */ ast = new TriggerAst(metadata.name, states, transitions); ast.options = normalizeAnimationOptions(metadata.options); ast.queryCount = queryCount; ast.depCount = depCount; return ast; }; /** * @param {?} metadata * @param {?} context * @return {?} */ AnimationAstBuilderVisitor.prototype.visitState = function (metadata, context) { var /** @type {?} */ styleAst = this.visitStyle(metadata.styles, context); var /** @type {?} */ astParams = (metadata.options && metadata.options.params) || null; if (styleAst.containsDynamicStyles) { var /** @type {?} */ missingSubs_1 = new Set(); var /** @type {?} */ params_1 = astParams || {}; styleAst.styles.forEach(function (value) { if (isObject(value)) { var /** @type {?} */ stylesObj_1 = (value); Object.keys(stylesObj_1).forEach(function (prop) { extractStyleParams(stylesObj_1[prop]).forEach(function (sub) { if (!params_1.hasOwnProperty(sub)) { missingSubs_1.add(sub); } }); }); } }); if (missingSubs_1.size) { var /** @type {?} */ missingSubsArr = iteratorToArray(missingSubs_1.values()); context.errors.push("state(\"" + metadata.name + "\", ...) must define default values for all the following style substitutions: " + missingSubsArr.join(', ')); } } var /** @type {?} */ stateAst = new StateAst(metadata.name, styleAst); if (astParams) { stateAst.options = { params: astParams }; } return stateAst; }; /** * @param {?} metadata * @param {?} context * @return {?} */ AnimationAstBuilderVisitor.prototype.visitTransition = function (metadata, context) { context.queryCount = 0; context.depCount = 0; var /** @type {?} */ entry = visitAnimationNode(this, normalizeAnimationEntry(metadata.animation), context); var /** @type {?} */ matchers = parseTransitionExpr(metadata.expr, context.errors); var /** @type {?} */ ast = new TransitionAst(matchers, entry); ast.options = normalizeAnimationOptions(metadata.options); ast.queryCount = context.queryCount; ast.depCount = context.depCount; return ast; }; /** * @param {?} metadata * @param {?} context * @return {?} */ AnimationAstBuilderVisitor.prototype.visitSequence = function (metadata, context) { var _this = this; var /** @type {?} */ ast = new SequenceAst(metadata.steps.map(function (s) { return visitAnimationNode(_this, s, context); })); ast.options = normalizeAnimationOptions(metadata.options); return ast; }; /** * @param {?} metadata * @param {?} context * @return {?} */ AnimationAstBuilderVisitor.prototype.visitGroup = function (metadata, context) { var _this = this; var /** @type {?} */ currentTime = context.currentTime; var /** @type {?} */ furthestTime = 0; var /** @type {?} */ steps = metadata.steps.map(function (step) { context.currentTime = currentTime; var /** @type {?} */ innerAst = visitAnimationNode(_this, step, context); furthestTime = Math.max(furthestTime, context.currentTime); return innerAst; }); context.currentTime = furthestTime; var /** @type {?} */ ast = new GroupAst(steps); ast.options = normalizeAnimationOptions(metadata.options); return ast; }; /** * @param {?} metadata * @param {?} context * @return {?} */ AnimationAstBuilderVisitor.prototype.visitAnimate = function (metadata, context) { var /** @type {?} */ timingAst = constructTimingAst(metadata.timings, context.errors); context.currentAnimateTimings = timingAst; var /** @type {?} */ styles; var /** @type {?} */ styleMetadata = metadata.styles ? metadata.styles : _angular_animations.style({}); if (styleMetadata.type == 5 /* Keyframes */) { styles = this.visitKeyframes(/** @type {?} */ (styleMetadata), context); } else { var /** @type {?} */ styleMetadata_1 = (metadata.styles); var /** @type {?} */ isEmpty = false; if (!styleMetadata_1) { isEmpty = true; var /** @type {?} */ newStyleData = {}; if (timingAst.easing) { newStyleData['easing'] = timingAst.easing; } styleMetadata_1 = _angular_animations.style(newStyleData); } context.currentTime += timingAst.duration + timingAst.delay; var /** @type {?} */ styleAst = this.visitStyle(styleMetadata_1, context); styleAst.isEmptyStep = isEmpty; styles = styleAst; } context.currentAnimateTimings = null; return new AnimateAst(timingAst, styles); }; /** * @param {?} metadata * @param {?} context * @return {?} */ AnimationAstBuilderVisitor.prototype.visitStyle = function (metadata, context) { var /** @type {?} */ ast = this._makeStyleAst(metadata, context); this._validateStyleAst(ast, context); return ast; }; /** * @param {?} metadata * @param {?} context * @return {?} */ AnimationAstBuilderVisitor.prototype._makeStyleAst = function (metadata, context) { var /** @type {?} */ styles = []; if (Array.isArray(metadata.styles)) { ((metadata.styles)).forEach(function (styleTuple) { if (typeof styleTuple == 'string') { if (styleTuple == _angular_animations.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); } var /** @type {?} */ containsDynamicStyles = false; var /** @type {?} */ collectedEasing = null; styles.forEach(function (styleData) { if (isObject(styleData)) { var /** @type {?} */ styleMap = (styleData); var /** @type {?} */ easing = styleMap['easing']; if (easing) { collectedEasing = (easing); delete styleMap['easing']; } if (!containsDynamicStyles) { for (var /** @type {?} */ prop in styleMap) { var /** @type {?} */ value = styleMap[prop]; if (value.toString().indexOf(SUBSTITUTION_EXPR_START) >= 0) { containsDynamicStyles = true; break; } } } } }); var /** @type {?} */ ast = new StyleAst(styles, collectedEasing, metadata.offset); ast.containsDynamicStyles = containsDynamicStyles; return ast; }; /** * @param {?} ast * @param {?} context * @return {?} */ AnimationAstBuilderVisitor.prototype._validateStyleAst = function (ast, context) { var /** @type {?} */ timings = context.currentAnimateTimings; var /** @type {?} */ endTime = context.currentTime; var /** @type {?} */ startTime = context.currentTime; if (timings && startTime > 0) { startTime -= timings.duration + timings.delay; } ast.styles.forEach(function (tuple) { if (typeof tuple == 'string') return; Object.keys(tuple).forEach(function (prop) { var /** @type {?} */ collectedStyles = context.collectedStyles[((context.currentQuerySelector))]; var /** @type {?} */ collectedEntry = collectedStyles[prop]; var /** @type {?} */ 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: startTime, endTime: endTime }; } if (context.options) { validateStyleParams(tuple[prop], context.options, context.errors); } }); }); }; /** * @param {?} metadata * @param {?} context * @return {?} */ AnimationAstBuilderVisitor.prototype.visitKeyframes = function (metadata, context) { var _this = this; if (!context.currentAnimateTimings) { context.errors.push("keyframes() must be placed inside of a call to animate()"); return new KeyframesAst([]); } var /** @type {?} */ MAX_KEYFRAME_OFFSET = 1; var /** @type {?} */ totalKeyframesWithOffsets = 0; var /** @type {?} */ offsets = []; var /** @type {?} */ offsetsOutOfOrder = false; var /** @type {?} */ keyframesOutOfRange = false; var /** @type {?} */ previousOffset = 0; var /** @type {?} */ keyframes = metadata.steps.map(function (styles) { var /** @type {?} */ style$$1 = _this._makeStyleAst(styles, context); var /** @type {?} */ offsetVal = style$$1.offset != null ? style$$1.offset : consumeOffset(style$$1.styles); var /** @type {?} */ offset = 0; if (offsetVal != null) { totalKeyframesWithOffsets++; offset = style$$1.offset = offsetVal; } keyframesOutOfRange = keyframesOutOfRange || offset < 0 || offset > 1; offsetsOutOfOrder = offsetsOutOfOrder || offset < previousOffset; previousOffset = offset; offsets.push(offset); return style$$1; }); 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"); } var /** @type {?} */ length = metadata.steps.length; var /** @type {?} */ 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); } var /** @type {?} */ limit = length - 1; var /** @type {?} */ currentTime = context.currentTime; var /** @type {?} */ currentAnimateTimings = ((context.currentAnimateTimings)); var /** @type {?} */ animateDuration = currentAnimateTimings.duration; keyframes.forEach(function (kf, i) { var /** @type {?} */ offset = generatedOffset > 0 ? (i == limit ? 1 : (generatedOffset * i)) : offsets[i]; var /** @type {?} */ durationUpToThisFrame = offset * animateDuration; context.currentTime = currentTime + currentAnimateTimings.delay + durationUpToThisFrame; currentAnimateTimings.duration = durationUpToThisFrame; _this._validateStyleAst(kf, context); kf.offset = offset; }); return new KeyframesAst(keyframes); }; /** * @param {?} metadata * @param {?} context * @return {?} */ AnimationAstBuilderVisitor.prototype.visitReference = function (metadata, context) { var /** @type {?} */ entry = visitAnimationNode(this, normalizeAnimationEntry(metadata.animation), context); var /** @type {?} */ ast = new ReferenceAst(entry); ast.options = normalizeAnimationOptions(metadata.options); return ast; }; /** * @param {?} metadata * @param {?} context * @return {?} */ AnimationAstBuilderVisitor.prototype.visitAnimateChild = function (metadata, context) { context.depCount++; var /** @type {?} */ ast = new AnimateChildAst(); ast.options = normalizeAnimationOptions(metadata.options); return ast; }; /** * @param {?} metadata * @param {?} context * @return {?} */ AnimationAstBuilderVisitor.prototype.visitAnimateRef = function (metadata, context) { var /** @type {?} */ animation = this.visitReference(metadata.animation, context); var /** @type {?} */ ast = new AnimateRefAst(animation); ast.options = normalizeAnimationOptions(metadata.options); return ast; }; /** * @param {?} metadata * @param {?} context * @return {?} */ AnimationAstBuilderVisitor.prototype.visitQuery = function (metadata, context) { var /** @type {?} */ parentSelector = ((context.currentQuerySelector)); var /** @type {?} */ options = ((metadata.options || {})); context.queryCount++; context.currentQuery = metadata; var _a = normalizeSelector(metadata.selector), selector = _a[0], includeSelf = _a[1]; context.currentQuerySelector = parentSelector.length ? (parentSelector + ' ' + selector) : selector; getOrSetAsInMap(context.collectedStyles, context.currentQuerySelector, {}); var /** @type {?} */ entry = visitAnimationNode(this, normalizeAnimationEntry(metadata.animation), context); context.currentQuery = null; context.currentQuerySelector = parentSelector; var /** @type {?} */ ast = new QueryAst(selector, options.limit || 0, !!options.optional, includeSelf, entry); ast.originalSelector = metadata.selector; ast.options = normalizeAnimationOptions(metadata.options); return ast; }; /** * @param {?} metadata * @param {?} context * @return {?} */ AnimationAstBuilderVisitor.prototype.visitStagger = function (metadata, context) { if (!context.currentQuery) { context.errors.push("stagger() can only be used inside of query()"); } var /** @type {?} */ timings = metadata.timings === 'full' ? { duration: 0, delay: 0, easing: 'full' } :