style(lint): re-format modules/@angular
This commit is contained in:
@ -20,9 +20,9 @@ export interface AnimationAstVisitor {
|
||||
}
|
||||
|
||||
export class AnimationEntryAst extends AnimationAst {
|
||||
constructor(public name: string,
|
||||
public stateDeclarations: AnimationStateDeclarationAst[],
|
||||
public stateTransitions: AnimationStateTransitionAst[]) {
|
||||
constructor(
|
||||
public name: string, public stateDeclarations: AnimationStateDeclarationAst[],
|
||||
public stateTransitions: AnimationStateTransitionAst[]) {
|
||||
super();
|
||||
}
|
||||
visit(visitor: AnimationAstVisitor, context: any): any {
|
||||
@ -31,9 +31,7 @@ export class AnimationEntryAst extends AnimationAst {
|
||||
}
|
||||
|
||||
export class AnimationStateDeclarationAst extends AnimationStateAst {
|
||||
constructor(public stateName: string, public styles: AnimationStylesAst) {
|
||||
super();
|
||||
}
|
||||
constructor(public stateName: string, public styles: AnimationStylesAst) { super(); }
|
||||
visit(visitor: AnimationAstVisitor, context: any): any {
|
||||
return visitor.visitAnimationStateDeclaration(this, context);
|
||||
}
|
||||
@ -44,7 +42,9 @@ export class AnimationStateTransitionExpression {
|
||||
}
|
||||
|
||||
export class AnimationStateTransitionAst extends AnimationStateAst {
|
||||
constructor(public stateChanges: AnimationStateTransitionExpression[], public animation: AnimationSequenceAst) {
|
||||
constructor(
|
||||
public stateChanges: AnimationStateTransitionExpression[],
|
||||
public animation: AnimationSequenceAst) {
|
||||
super();
|
||||
}
|
||||
visit(visitor: AnimationAstVisitor, context: any): any {
|
||||
@ -53,11 +53,9 @@ export class AnimationStateTransitionAst extends AnimationStateAst {
|
||||
}
|
||||
|
||||
export class AnimationStepAst extends AnimationAst {
|
||||
constructor(public startingStyles: AnimationStylesAst,
|
||||
public keyframes: AnimationKeyframeAst[],
|
||||
public duration: number,
|
||||
public delay: number,
|
||||
public easing: string) {
|
||||
constructor(
|
||||
public startingStyles: AnimationStylesAst, public keyframes: AnimationKeyframeAst[],
|
||||
public duration: number, public delay: number, public easing: string) {
|
||||
super();
|
||||
}
|
||||
visit(visitor: AnimationAstVisitor, context: any): any {
|
||||
|
@ -1,41 +1,21 @@
|
||||
import {BaseException} from '../facade/exceptions';
|
||||
import {ListWrapper, Map, StringMapWrapper} from '../facade/collection';
|
||||
import {isPresent, isBlank, isArray} from '../facade/lang';
|
||||
import {AUTO_STYLE} from '@angular/core';
|
||||
|
||||
import {ANY_STATE, DEFAULT_STATE, EMPTY_STATE} from '../../core_private';
|
||||
import {CompileDirectiveMetadata} from '../compile_metadata';
|
||||
import {ListWrapper, Map, StringMapWrapper} from '../facade/collection';
|
||||
import {BaseException} from '../facade/exceptions';
|
||||
import {isArray, isBlank, isPresent} from '../facade/lang';
|
||||
import {Identifiers} from '../identifiers';
|
||||
import * as o from '../output/output_ast';
|
||||
|
||||
import {AUTO_STYLE} from '@angular/core';
|
||||
import {DEFAULT_STATE, ANY_STATE, EMPTY_STATE} from '../../core_private';
|
||||
|
||||
import {
|
||||
AnimationParseError,
|
||||
ParsedAnimationResult,
|
||||
parseAnimationEntry
|
||||
} from './animation_parser';
|
||||
|
||||
import {CompileDirectiveMetadata} from "../compile_metadata";
|
||||
|
||||
import {
|
||||
AnimationAst,
|
||||
AnimationEntryAst,
|
||||
AnimationStateAst,
|
||||
AnimationStateDeclarationAst,
|
||||
AnimationStateTransitionAst,
|
||||
AnimationKeyframeAst,
|
||||
AnimationStylesAst,
|
||||
AnimationSequenceAst,
|
||||
AnimationGroupAst,
|
||||
AnimationStepAst,
|
||||
AnimationAstVisitor
|
||||
} from './animation_ast';
|
||||
import {AnimationAst, AnimationAstVisitor, AnimationEntryAst, AnimationGroupAst, AnimationKeyframeAst, AnimationSequenceAst, AnimationStateAst, AnimationStateDeclarationAst, AnimationStateTransitionAst, AnimationStepAst, AnimationStylesAst} from './animation_ast';
|
||||
import {AnimationParseError, ParsedAnimationResult, parseAnimationEntry} from './animation_parser';
|
||||
|
||||
export class CompiledAnimation {
|
||||
constructor(public name: string,
|
||||
public statesMapStatement: o.Statement,
|
||||
public statesVariableName: string,
|
||||
public fnStatement: o.Statement,
|
||||
public fnVariable: o.Expression) {}
|
||||
constructor(
|
||||
public name: string, public statesMapStatement: o.Statement,
|
||||
public statesVariableName: string, public fnStatement: o.Statement,
|
||||
public fnVariable: o.Expression) {}
|
||||
}
|
||||
|
||||
export class AnimationCompiler {
|
||||
@ -46,11 +26,12 @@ export class AnimationCompiler {
|
||||
var result = parseAnimationEntry(entry);
|
||||
if (result.errors.length > 0) {
|
||||
var errorMessage = '';
|
||||
result.errors.forEach((error: AnimationParseError) => { errorMessage += "\n- " + error.msg; });
|
||||
result.errors.forEach(
|
||||
(error: AnimationParseError) => { errorMessage += '\n- ' + error.msg; });
|
||||
// todo (matsko): include the component name when throwing
|
||||
throw new BaseException(
|
||||
`Unable to parse the animation sequence for "${entry.name}" due to the following errors: ` +
|
||||
errorMessage);
|
||||
`Unable to parse the animation sequence for "${entry.name}" due to the following errors: ` +
|
||||
errorMessage);
|
||||
}
|
||||
|
||||
var factoryName = `${component.type.name}_${entry.name}_${index}`;
|
||||
@ -86,8 +67,7 @@ class _AnimationBuilder implements AnimationAstVisitor {
|
||||
this._statesMapVar = o.variable(this._statesMapVarName);
|
||||
}
|
||||
|
||||
visitAnimationStyles(ast: AnimationStylesAst,
|
||||
context: _AnimationBuilderContext): o.Expression {
|
||||
visitAnimationStyles(ast: AnimationStylesAst, context: _AnimationBuilderContext): o.Expression {
|
||||
var stylesArr: any[] /** TODO #9100 */ = [];
|
||||
if (context.isExpectingFirstStyleStep) {
|
||||
stylesArr.push(_ANIMATION_START_STATE_STYLES_VAR);
|
||||
@ -95,22 +75,21 @@ class _AnimationBuilder implements AnimationAstVisitor {
|
||||
}
|
||||
|
||||
ast.styles.forEach(entry => {
|
||||
stylesArr.push(o.literalMap(StringMapWrapper.keys(entry).map(key => [key, o.literal(entry[key])])));
|
||||
stylesArr.push(
|
||||
o.literalMap(StringMapWrapper.keys(entry).map(key => [key, o.literal(entry[key])])));
|
||||
});
|
||||
|
||||
return o.importExpr(Identifiers.AnimationStyles).instantiate([
|
||||
o.importExpr(Identifiers.collectAndResolveStyles).callFn([
|
||||
_ANIMATION_COLLECTED_STYLES,
|
||||
o.literalArr(stylesArr)
|
||||
_ANIMATION_COLLECTED_STYLES, o.literalArr(stylesArr)
|
||||
])
|
||||
]);
|
||||
}
|
||||
|
||||
visitAnimationKeyframe(ast: AnimationKeyframeAst,
|
||||
context: _AnimationBuilderContext): o.Expression {
|
||||
visitAnimationKeyframe(ast: AnimationKeyframeAst, context: _AnimationBuilderContext):
|
||||
o.Expression {
|
||||
return o.importExpr(Identifiers.AnimationKeyframe).instantiate([
|
||||
o.literal(ast.offset),
|
||||
ast.styles.visit(this, context)
|
||||
o.literal(ast.offset), ast.styles.visit(this, context)
|
||||
]);
|
||||
}
|
||||
|
||||
@ -120,18 +99,17 @@ class _AnimationBuilder implements AnimationAstVisitor {
|
||||
}
|
||||
|
||||
var startingStylesExpr = ast.startingStyles.visit(this, context);
|
||||
var keyframeExpressions = ast.keyframes.map(keyframeEntry => keyframeEntry.visit(this, context));
|
||||
var keyframeExpressions =
|
||||
ast.keyframes.map(keyframeEntry => keyframeEntry.visit(this, context));
|
||||
return this._callAnimateMethod(ast, startingStylesExpr, o.literalArr(keyframeExpressions));
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
_visitEndStateAnimation(ast: AnimationStepAst,
|
||||
context: _AnimationBuilderContext): o.Expression {
|
||||
_visitEndStateAnimation(ast: AnimationStepAst, context: _AnimationBuilderContext): o.Expression {
|
||||
var startingStylesExpr = ast.startingStyles.visit(this, context);
|
||||
var keyframeExpressions = ast.keyframes.map(keyframe => keyframe.visit(this, context));
|
||||
var keyframesExpr = o.importExpr(Identifiers.balanceAnimationKeyframes).callFn([
|
||||
_ANIMATION_COLLECTED_STYLES,
|
||||
_ANIMATION_END_STATE_STYLES_VAR,
|
||||
_ANIMATION_COLLECTED_STYLES, _ANIMATION_END_STATE_STYLES_VAR,
|
||||
o.literalArr(keyframeExpressions)
|
||||
]);
|
||||
|
||||
@ -139,41 +117,41 @@ class _AnimationBuilder implements AnimationAstVisitor {
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
_callAnimateMethod(ast: AnimationStepAst, startingStylesExpr: any /** TODO #9100 */, keyframesExpr: any /** TODO #9100 */) {
|
||||
_callAnimateMethod(
|
||||
ast: AnimationStepAst, startingStylesExpr: any /** TODO #9100 */,
|
||||
keyframesExpr: any /** TODO #9100 */) {
|
||||
return _ANIMATION_FACTORY_RENDERER_VAR.callMethod('animate', [
|
||||
_ANIMATION_FACTORY_ELEMENT_VAR,
|
||||
startingStylesExpr,
|
||||
keyframesExpr,
|
||||
o.literal(ast.duration),
|
||||
o.literal(ast.delay),
|
||||
o.literal(ast.easing)
|
||||
_ANIMATION_FACTORY_ELEMENT_VAR, startingStylesExpr, keyframesExpr, o.literal(ast.duration),
|
||||
o.literal(ast.delay), o.literal(ast.easing)
|
||||
]);
|
||||
}
|
||||
|
||||
visitAnimationSequence(ast: AnimationSequenceAst,
|
||||
context: _AnimationBuilderContext): o.Expression {
|
||||
visitAnimationSequence(ast: AnimationSequenceAst, context: _AnimationBuilderContext):
|
||||
o.Expression {
|
||||
var playerExprs = ast.steps.map(step => step.visit(this, context));
|
||||
return o.importExpr(Identifiers.AnimationSequencePlayer).instantiate([
|
||||
o.literalArr(playerExprs)]);
|
||||
return o.importExpr(Identifiers.AnimationSequencePlayer).instantiate([o.literalArr(
|
||||
playerExprs)]);
|
||||
}
|
||||
|
||||
visitAnimationGroup(ast: AnimationGroupAst, context: _AnimationBuilderContext): o.Expression {
|
||||
var playerExprs = ast.steps.map(step => step.visit(this, context));
|
||||
return o.importExpr(Identifiers.AnimationGroupPlayer).instantiate([
|
||||
o.literalArr(playerExprs)]);
|
||||
return o.importExpr(Identifiers.AnimationGroupPlayer).instantiate([o.literalArr(playerExprs)]);
|
||||
}
|
||||
|
||||
visitAnimationStateDeclaration(ast: AnimationStateDeclarationAst, context: _AnimationBuilderContext): void {
|
||||
var flatStyles: {[key: string]: string|number} = {};
|
||||
visitAnimationStateDeclaration(
|
||||
ast: AnimationStateDeclarationAst, context: _AnimationBuilderContext): void {
|
||||
var flatStyles: {[key: string]: string | number} = {};
|
||||
_getStylesArray(ast).forEach((entry: any /** TODO #9100 */) => {
|
||||
StringMapWrapper.forEach(entry, (value: any /** TODO #9100 */, key: any /** TODO #9100 */) => {
|
||||
flatStyles[key] = value;
|
||||
});
|
||||
StringMapWrapper.forEach(
|
||||
entry, (value: any /** TODO #9100 */, key: any /** TODO #9100 */) => {
|
||||
flatStyles[key] = value;
|
||||
});
|
||||
});
|
||||
context.stateMap.registerState(ast.stateName, flatStyles);
|
||||
}
|
||||
|
||||
visitAnimationStateTransition(ast: AnimationStateTransitionAst, context: _AnimationBuilderContext): any {
|
||||
visitAnimationStateTransition(
|
||||
ast: AnimationStateTransitionAst, context: _AnimationBuilderContext): any {
|
||||
var steps = ast.animation.steps;
|
||||
var lastStep = steps[steps.length - 1];
|
||||
if (_isEndStateAnimateStep(lastStep)) {
|
||||
@ -186,9 +164,8 @@ class _AnimationBuilder implements AnimationAstVisitor {
|
||||
|
||||
ast.stateChanges.forEach(stateChange => {
|
||||
stateChangePreconditions.push(
|
||||
_compareToAnimationStateExpr(_ANIMATION_CURRENT_STATE_VAR, stateChange.fromState)
|
||||
.and(_compareToAnimationStateExpr(_ANIMATION_NEXT_STATE_VAR, stateChange.toState))
|
||||
);
|
||||
_compareToAnimationStateExpr(_ANIMATION_CURRENT_STATE_VAR, stateChange.fromState)
|
||||
.and(_compareToAnimationStateExpr(_ANIMATION_NEXT_STATE_VAR, stateChange.toState)));
|
||||
|
||||
if (stateChange.fromState != ANY_STATE) {
|
||||
context.stateMap.registerState(stateChange.fromState);
|
||||
@ -201,56 +178,52 @@ class _AnimationBuilder implements AnimationAstVisitor {
|
||||
|
||||
var animationPlayerExpr = ast.animation.visit(this, context);
|
||||
|
||||
var reducedStateChangesPrecondition = stateChangePreconditions.reduce((a,b) => a.or(b));
|
||||
var precondition = _ANIMATION_PLAYER_VAR.equals(o.NULL_EXPR).and(reducedStateChangesPrecondition);
|
||||
var reducedStateChangesPrecondition = stateChangePreconditions.reduce((a, b) => a.or(b));
|
||||
var precondition =
|
||||
_ANIMATION_PLAYER_VAR.equals(o.NULL_EXPR).and(reducedStateChangesPrecondition);
|
||||
|
||||
return new o.IfStmt(precondition, [
|
||||
_ANIMATION_PLAYER_VAR.set(animationPlayerExpr).toStmt()
|
||||
]);
|
||||
return new o.IfStmt(precondition, [_ANIMATION_PLAYER_VAR.set(animationPlayerExpr).toStmt()]);
|
||||
}
|
||||
|
||||
visitAnimationEntry(ast: AnimationEntryAst, context: _AnimationBuilderContext): any {
|
||||
//visit each of the declarations first to build the context state map
|
||||
// visit each of the declarations first to build the context state map
|
||||
ast.stateDeclarations.forEach(def => def.visit(this, context));
|
||||
|
||||
//this should always be defined even if the user overrides it
|
||||
// this should always be defined even if the user overrides it
|
||||
context.stateMap.registerState(DEFAULT_STATE, {});
|
||||
|
||||
var statements: any[] /** TODO #9100 */ = [];
|
||||
statements.push(
|
||||
_ANIMATION_FACTORY_VIEW_VAR.callMethod('cancelActiveAnimation', [
|
||||
_ANIMATION_FACTORY_ELEMENT_VAR,
|
||||
o.literal(this.animationName),
|
||||
_ANIMATION_NEXT_STATE_VAR.equals(o.literal(EMPTY_STATE))
|
||||
]).toStmt());
|
||||
statements.push(_ANIMATION_FACTORY_VIEW_VAR
|
||||
.callMethod(
|
||||
'cancelActiveAnimation',
|
||||
[
|
||||
_ANIMATION_FACTORY_ELEMENT_VAR, o.literal(this.animationName),
|
||||
_ANIMATION_NEXT_STATE_VAR.equals(o.literal(EMPTY_STATE))
|
||||
])
|
||||
.toStmt());
|
||||
|
||||
statements.push(_ANIMATION_COLLECTED_STYLES.set(EMPTY_MAP).toDeclStmt());
|
||||
statements.push(_ANIMATION_PLAYER_VAR.set(o.NULL_EXPR).toDeclStmt());
|
||||
|
||||
statements.push(
|
||||
_ANIMATION_DEFAULT_STATE_VAR.set(
|
||||
this._statesMapVar.key(o.literal(DEFAULT_STATE))
|
||||
).toDeclStmt());
|
||||
_ANIMATION_DEFAULT_STATE_VAR.set(this._statesMapVar.key(o.literal(DEFAULT_STATE)))
|
||||
.toDeclStmt());
|
||||
|
||||
statements.push(
|
||||
_ANIMATION_START_STATE_STYLES_VAR.set(
|
||||
this._statesMapVar.key(_ANIMATION_CURRENT_STATE_VAR)
|
||||
).toDeclStmt());
|
||||
_ANIMATION_START_STATE_STYLES_VAR.set(this._statesMapVar.key(_ANIMATION_CURRENT_STATE_VAR))
|
||||
.toDeclStmt());
|
||||
|
||||
statements.push(new o.IfStmt(
|
||||
_ANIMATION_START_STATE_STYLES_VAR.equals(o.NULL_EXPR),
|
||||
[_ANIMATION_START_STATE_STYLES_VAR.set(_ANIMATION_DEFAULT_STATE_VAR).toStmt()]));
|
||||
|
||||
statements.push(
|
||||
new o.IfStmt(_ANIMATION_START_STATE_STYLES_VAR.equals(o.NULL_EXPR), [
|
||||
_ANIMATION_START_STATE_STYLES_VAR.set(_ANIMATION_DEFAULT_STATE_VAR).toStmt()
|
||||
]));
|
||||
_ANIMATION_END_STATE_STYLES_VAR.set(this._statesMapVar.key(_ANIMATION_NEXT_STATE_VAR))
|
||||
.toDeclStmt());
|
||||
|
||||
statements.push(
|
||||
_ANIMATION_END_STATE_STYLES_VAR.set(
|
||||
this._statesMapVar.key(_ANIMATION_NEXT_STATE_VAR)
|
||||
).toDeclStmt());
|
||||
|
||||
statements.push(
|
||||
new o.IfStmt(_ANIMATION_END_STATE_STYLES_VAR.equals(o.NULL_EXPR), [
|
||||
_ANIMATION_END_STATE_STYLES_VAR.set(_ANIMATION_DEFAULT_STATE_VAR).toStmt()
|
||||
]));
|
||||
statements.push(new o.IfStmt(
|
||||
_ANIMATION_END_STATE_STYLES_VAR.equals(o.NULL_EXPR),
|
||||
[_ANIMATION_END_STATE_STYLES_VAR.set(_ANIMATION_DEFAULT_STATE_VAR).toStmt()]));
|
||||
|
||||
|
||||
var RENDER_STYLES_FN = o.importExpr(Identifiers.renderStyles);
|
||||
@ -259,53 +232,59 @@ class _AnimationBuilder implements AnimationAstVisitor {
|
||||
// styles from the element's style property (since they were placed
|
||||
// there at the end of the last animation
|
||||
statements.push(
|
||||
RENDER_STYLES_FN.callFn([
|
||||
_ANIMATION_FACTORY_ELEMENT_VAR,
|
||||
_ANIMATION_FACTORY_RENDERER_VAR,
|
||||
o.importExpr(Identifiers.clearStyles).callFn([_ANIMATION_START_STATE_STYLES_VAR])
|
||||
]).toStmt());
|
||||
RENDER_STYLES_FN
|
||||
.callFn([
|
||||
_ANIMATION_FACTORY_ELEMENT_VAR, _ANIMATION_FACTORY_RENDERER_VAR,
|
||||
o.importExpr(Identifiers.clearStyles).callFn([_ANIMATION_START_STATE_STYLES_VAR])
|
||||
])
|
||||
.toStmt());
|
||||
|
||||
ast.stateTransitions.forEach(transAst => statements.push(transAst.visit(this, context)));
|
||||
|
||||
// this check ensures that the animation factory always returns a player
|
||||
// so that the onDone callback can be used for tracking
|
||||
statements.push(
|
||||
new o.IfStmt(_ANIMATION_PLAYER_VAR.equals(o.NULL_EXPR), [
|
||||
_ANIMATION_PLAYER_VAR.set(
|
||||
o.importExpr(Identifiers.NoOpAnimationPlayer).instantiate([])
|
||||
).toStmt()
|
||||
]));
|
||||
statements.push(new o.IfStmt(
|
||||
_ANIMATION_PLAYER_VAR.equals(o.NULL_EXPR),
|
||||
[_ANIMATION_PLAYER_VAR.set(o.importExpr(Identifiers.NoOpAnimationPlayer).instantiate([]))
|
||||
.toStmt()]));
|
||||
|
||||
// once complete we want to apply the styles on the element
|
||||
// since the destination state's values should persist once
|
||||
// the animation sequence has completed.
|
||||
statements.push(
|
||||
_ANIMATION_PLAYER_VAR.callMethod('onDone', [
|
||||
o.fn([], [
|
||||
RENDER_STYLES_FN.callFn([
|
||||
_ANIMATION_FACTORY_ELEMENT_VAR,
|
||||
_ANIMATION_FACTORY_RENDERER_VAR,
|
||||
o.importExpr(Identifiers.balanceAnimationStyles).callFn([
|
||||
_ANIMATION_START_STATE_STYLES_VAR,
|
||||
_ANIMATION_END_STATE_STYLES_VAR
|
||||
])
|
||||
]).toStmt()
|
||||
])
|
||||
]).toStmt());
|
||||
|
||||
statements.push(
|
||||
_ANIMATION_FACTORY_VIEW_VAR.callMethod('registerAndStartAnimation', [
|
||||
_ANIMATION_FACTORY_ELEMENT_VAR,
|
||||
o.literal(this.animationName),
|
||||
_ANIMATION_PLAYER_VAR
|
||||
]).toStmt());
|
||||
.callMethod(
|
||||
'onDone',
|
||||
[o.fn(
|
||||
[], [RENDER_STYLES_FN
|
||||
.callFn([
|
||||
_ANIMATION_FACTORY_ELEMENT_VAR, _ANIMATION_FACTORY_RENDERER_VAR,
|
||||
o.importExpr(Identifiers.balanceAnimationStyles).callFn([
|
||||
_ANIMATION_START_STATE_STYLES_VAR, _ANIMATION_END_STATE_STYLES_VAR
|
||||
])
|
||||
])
|
||||
.toStmt()])])
|
||||
.toStmt());
|
||||
|
||||
return o.fn([
|
||||
new o.FnParam(_ANIMATION_FACTORY_VIEW_VAR.name, o.importType(Identifiers.AppView, [o.DYNAMIC_TYPE])),
|
||||
new o.FnParam(_ANIMATION_FACTORY_ELEMENT_VAR.name, o.DYNAMIC_TYPE),
|
||||
new o.FnParam(_ANIMATION_CURRENT_STATE_VAR.name, o.DYNAMIC_TYPE),
|
||||
new o.FnParam(_ANIMATION_NEXT_STATE_VAR.name, o.DYNAMIC_TYPE)
|
||||
], statements);
|
||||
statements.push(_ANIMATION_FACTORY_VIEW_VAR
|
||||
.callMethod(
|
||||
'registerAndStartAnimation',
|
||||
[
|
||||
_ANIMATION_FACTORY_ELEMENT_VAR, o.literal(this.animationName),
|
||||
_ANIMATION_PLAYER_VAR
|
||||
])
|
||||
.toStmt());
|
||||
|
||||
return o.fn(
|
||||
[
|
||||
new o.FnParam(
|
||||
_ANIMATION_FACTORY_VIEW_VAR.name,
|
||||
o.importType(Identifiers.AppView, [o.DYNAMIC_TYPE])),
|
||||
new o.FnParam(_ANIMATION_FACTORY_ELEMENT_VAR.name, o.DYNAMIC_TYPE),
|
||||
new o.FnParam(_ANIMATION_CURRENT_STATE_VAR.name, o.DYNAMIC_TYPE),
|
||||
new o.FnParam(_ANIMATION_NEXT_STATE_VAR.name, o.DYNAMIC_TYPE)
|
||||
],
|
||||
statements);
|
||||
}
|
||||
|
||||
build(ast: AnimationAst): CompiledAnimation {
|
||||
@ -314,24 +293,24 @@ class _AnimationBuilder implements AnimationAstVisitor {
|
||||
var fnVariable = o.variable(this._fnVarName);
|
||||
|
||||
var lookupMap: any[] /** TODO #9100 */ = [];
|
||||
StringMapWrapper.forEach(context.stateMap.states, (value: any /** TODO #9100 */, stateName: any /** TODO #9100 */) => {
|
||||
var variableValue = EMPTY_MAP;
|
||||
if (isPresent(value)) {
|
||||
let styleMap: any[] /** TODO #9100 */ = [];
|
||||
StringMapWrapper.forEach(value, (value: any /** TODO #9100 */, key: any /** TODO #9100 */) => {
|
||||
styleMap.push([key, o.literal(value)]);
|
||||
StringMapWrapper.forEach(
|
||||
context.stateMap.states,
|
||||
(value: any /** TODO #9100 */, stateName: any /** TODO #9100 */) => {
|
||||
var variableValue = EMPTY_MAP;
|
||||
if (isPresent(value)) {
|
||||
let styleMap: any[] /** TODO #9100 */ = [];
|
||||
StringMapWrapper.forEach(
|
||||
value, (value: any /** TODO #9100 */, key: any /** TODO #9100 */) => {
|
||||
styleMap.push([key, o.literal(value)]);
|
||||
});
|
||||
variableValue = o.literalMap(styleMap);
|
||||
}
|
||||
lookupMap.push([stateName, variableValue]);
|
||||
});
|
||||
variableValue = o.literalMap(styleMap);
|
||||
}
|
||||
lookupMap.push([stateName, variableValue]);
|
||||
});
|
||||
|
||||
var compiledStatesMapExpr = this._statesMapVar.set(o.literalMap(lookupMap)).toDeclStmt();
|
||||
return new CompiledAnimation(this.animationName,
|
||||
compiledStatesMapExpr,
|
||||
this._statesMapVarName,
|
||||
fnStatement,
|
||||
fnVariable);
|
||||
return new CompiledAnimation(
|
||||
this.animationName, compiledStatesMapExpr, this._statesMapVarName, fnStatement, fnVariable);
|
||||
}
|
||||
}
|
||||
|
||||
@ -342,9 +321,9 @@ class _AnimationBuilderContext {
|
||||
}
|
||||
|
||||
class _AnimationBuilderStateMap {
|
||||
private _states: {[key: string]: {[prop: string]: string|number}} = {};
|
||||
private _states: {[key: string]: {[prop: string]: string | number}} = {};
|
||||
get states() { return this._states; }
|
||||
registerState(name: string, value: {[prop: string]: string|number} = null): void {
|
||||
registerState(name: string, value: {[prop: string]: string | number} = null): void {
|
||||
var existingEntry = this._states[name];
|
||||
if (isBlank(existingEntry)) {
|
||||
this._states[name] = value;
|
||||
@ -369,9 +348,7 @@ function _compareToAnimationStateExpr(value: o.Expression, animationState: strin
|
||||
function _isEndStateAnimateStep(step: AnimationAst): boolean {
|
||||
// the final animation step is characterized by having only TWO
|
||||
// keyframe values and it must have zero styles for both keyframes
|
||||
if (step instanceof AnimationStepAst
|
||||
&& step.duration > 0
|
||||
&& step.keyframes.length == 2) {
|
||||
if (step instanceof AnimationStepAst && step.duration > 0 && step.keyframes.length == 2) {
|
||||
var styles1 = _getStylesArray(step.keyframes[0])[0];
|
||||
var styles2 = _getStylesArray(step.keyframes[1])[0];
|
||||
return StringMapWrapper.isEmpty(styles1) && StringMapWrapper.isEmpty(styles2);
|
||||
|
@ -1,46 +1,13 @@
|
||||
import {ListWrapper, StringMapWrapper} from '../facade/collection';
|
||||
import {Math} from '../facade/math';
|
||||
import {ANY_STATE, FILL_STYLE_FLAG} from '../../core_private';
|
||||
import {
|
||||
RegExpWrapper,
|
||||
isArray,
|
||||
isPresent,
|
||||
isBlank,
|
||||
isString,
|
||||
isStringMap,
|
||||
NumberWrapper
|
||||
} from '../facade/lang';
|
||||
|
||||
import {
|
||||
CompileAnimationEntryMetadata,
|
||||
CompileAnimationStateDeclarationMetadata,
|
||||
CompileAnimationStateTransitionMetadata,
|
||||
CompileAnimationMetadata,
|
||||
CompileAnimationWithStepsMetadata,
|
||||
CompileAnimationStyleMetadata,
|
||||
CompileAnimationAnimateMetadata,
|
||||
CompileAnimationGroupMetadata,
|
||||
CompileAnimationSequenceMetadata,
|
||||
CompileAnimationKeyframesSequenceMetadata
|
||||
} from '../compile_metadata';
|
||||
|
||||
import {
|
||||
AnimationAst,
|
||||
AnimationEntryAst,
|
||||
AnimationStateTransitionAst,
|
||||
AnimationStateDeclarationAst,
|
||||
AnimationKeyframeAst,
|
||||
AnimationStylesAst,
|
||||
AnimationWithStepsAst,
|
||||
AnimationSequenceAst,
|
||||
AnimationGroupAst,
|
||||
AnimationStepAst,
|
||||
AnimationStateTransitionExpression
|
||||
} from './animation_ast';
|
||||
|
||||
import {StylesCollection} from './styles_collection';
|
||||
import {CompileAnimationAnimateMetadata, CompileAnimationEntryMetadata, CompileAnimationGroupMetadata, CompileAnimationKeyframesSequenceMetadata, CompileAnimationMetadata, CompileAnimationSequenceMetadata, CompileAnimationStateDeclarationMetadata, CompileAnimationStateTransitionMetadata, CompileAnimationStyleMetadata, CompileAnimationWithStepsMetadata} from '../compile_metadata';
|
||||
import {ListWrapper, StringMapWrapper} from '../facade/collection';
|
||||
import {NumberWrapper, RegExpWrapper, isArray, isBlank, isPresent, isString, isStringMap} from '../facade/lang';
|
||||
import {Math} from '../facade/math';
|
||||
import {ParseError} from '../parse_util';
|
||||
|
||||
import {AnimationAst, AnimationEntryAst, AnimationGroupAst, AnimationKeyframeAst, AnimationSequenceAst, AnimationStateDeclarationAst, AnimationStateTransitionAst, AnimationStateTransitionExpression, AnimationStepAst, AnimationStylesAst, AnimationWithStepsAst} from './animation_ast';
|
||||
import {StylesCollection} from './styles_collection';
|
||||
|
||||
const _INITIAL_KEYFRAME = 0;
|
||||
const _TERMINAL_KEYFRAME = 1;
|
||||
const _ONE_SECOND = 1000;
|
||||
@ -71,21 +38,24 @@ export function parseAnimationEntry(entry: CompileAnimationEntryMetadata): Parse
|
||||
}
|
||||
});
|
||||
|
||||
var stateTransitionAsts = transitions.map(transDef =>
|
||||
_parseAnimationStateTransition(transDef, stateStyles, errors));
|
||||
var stateTransitionAsts =
|
||||
transitions.map(transDef => _parseAnimationStateTransition(transDef, stateStyles, errors));
|
||||
|
||||
var ast = new AnimationEntryAst(entry.name, stateDeclarationAsts, stateTransitionAsts);
|
||||
return new ParsedAnimationResult(ast, errors);
|
||||
}
|
||||
|
||||
function _parseAnimationDeclarationStates(stateMetadata: CompileAnimationStateDeclarationMetadata, errors: AnimationParseError[]): AnimationStateDeclarationAst[] {
|
||||
var styleValues: {[key: string]: string|number}[] = [];
|
||||
function _parseAnimationDeclarationStates(
|
||||
stateMetadata: CompileAnimationStateDeclarationMetadata,
|
||||
errors: AnimationParseError[]): AnimationStateDeclarationAst[] {
|
||||
var styleValues: {[key: string]: string | number}[] = [];
|
||||
stateMetadata.styles.styles.forEach(stylesEntry => {
|
||||
// TODO (matsko): change this when we get CSS class integration support
|
||||
if (isStringMap(stylesEntry)) {
|
||||
styleValues.push(<{[key: string]: string|number}>stylesEntry);
|
||||
styleValues.push(<{[key: string]: string | number}>stylesEntry);
|
||||
} else {
|
||||
errors.push(new AnimationParseError(`State based animations cannot contain references to other states`));
|
||||
errors.push(new AnimationParseError(
|
||||
`State based animations cannot contain references to other states`));
|
||||
}
|
||||
});
|
||||
var defStyles = new AnimationStylesAst(styleValues);
|
||||
@ -94,9 +64,10 @@ function _parseAnimationDeclarationStates(stateMetadata: CompileAnimationStateDe
|
||||
return states.map(state => new AnimationStateDeclarationAst(state, defStyles));
|
||||
}
|
||||
|
||||
function _parseAnimationStateTransition(transitionStateMetadata: CompileAnimationStateTransitionMetadata,
|
||||
stateStyles: {[key: string]: AnimationStylesAst},
|
||||
errors: AnimationParseError[]): AnimationStateTransitionAst {
|
||||
function _parseAnimationStateTransition(
|
||||
transitionStateMetadata: CompileAnimationStateTransitionMetadata,
|
||||
stateStyles: {[key: string]: AnimationStylesAst},
|
||||
errors: AnimationParseError[]): AnimationStateTransitionAst {
|
||||
var styles = new StylesCollection();
|
||||
var transitionExprs: any[] /** TODO #9100 */ = [];
|
||||
var transitionStates = transitionStateMetadata.stateChangeExpr.split(/\s*,\s*/);
|
||||
@ -112,14 +83,15 @@ function _parseAnimationStateTransition(transitionStateMetadata: CompileAnimatio
|
||||
_fillAnimationAstStartingKeyframes(animationAst, styles, errors);
|
||||
}
|
||||
|
||||
var sequenceAst = (animationAst instanceof AnimationSequenceAst)
|
||||
? <AnimationSequenceAst>animationAst
|
||||
: new AnimationSequenceAst([animationAst]);
|
||||
var sequenceAst = (animationAst instanceof AnimationSequenceAst) ?
|
||||
<AnimationSequenceAst>animationAst :
|
||||
new AnimationSequenceAst([animationAst]);
|
||||
|
||||
return new AnimationStateTransitionAst(transitionExprs, sequenceAst);
|
||||
}
|
||||
|
||||
function _parseAnimationTransitionExpr(eventStr: string, errors: AnimationParseError[]): AnimationStateTransitionExpression[] {
|
||||
function _parseAnimationTransitionExpr(
|
||||
eventStr: string, errors: AnimationParseError[]): AnimationStateTransitionExpression[] {
|
||||
var expressions: any[] /** TODO #9100 */ = [];
|
||||
var match = eventStr.match(/^(\*|[-\w]+)\s*(<?[=-]>)\s*(\*|[-\w]+)$/);
|
||||
if (!isPresent(match) || match.length < 4) {
|
||||
@ -130,19 +102,17 @@ function _parseAnimationTransitionExpr(eventStr: string, errors: AnimationParseE
|
||||
var fromState = match[1];
|
||||
var separator = match[2];
|
||||
var toState = match[3];
|
||||
expressions.push(
|
||||
new AnimationStateTransitionExpression(fromState, toState));
|
||||
expressions.push(new AnimationStateTransitionExpression(fromState, toState));
|
||||
|
||||
var isFullAnyStateExpr = fromState == ANY_STATE && toState == ANY_STATE;
|
||||
if (separator[0] == '<' && !isFullAnyStateExpr) {
|
||||
expressions.push(
|
||||
new AnimationStateTransitionExpression(toState, fromState));
|
||||
expressions.push(new AnimationStateTransitionExpression(toState, fromState));
|
||||
}
|
||||
return expressions;
|
||||
}
|
||||
|
||||
function _fetchSylesFromState(stateName: string,
|
||||
stateStyles: {[key: string]: AnimationStylesAst}): CompileAnimationStyleMetadata {
|
||||
function _fetchSylesFromState(stateName: string, stateStyles: {[key: string]: AnimationStylesAst}):
|
||||
CompileAnimationStyleMetadata {
|
||||
var entry = stateStyles[stateName];
|
||||
if (isPresent(entry)) {
|
||||
var styles = <{[key: string]: string | number}[]>entry.styles;
|
||||
@ -151,20 +121,20 @@ function _fetchSylesFromState(stateName: string,
|
||||
return null;
|
||||
}
|
||||
|
||||
function _normalizeAnimationEntry(entry: CompileAnimationMetadata | CompileAnimationMetadata[])
|
||||
:CompileAnimationMetadata {
|
||||
return isArray(entry)
|
||||
? new CompileAnimationSequenceMetadata(<CompileAnimationMetadata[]>entry)
|
||||
: <CompileAnimationMetadata>entry;
|
||||
function _normalizeAnimationEntry(entry: CompileAnimationMetadata | CompileAnimationMetadata[]):
|
||||
CompileAnimationMetadata {
|
||||
return isArray(entry) ? new CompileAnimationSequenceMetadata(<CompileAnimationMetadata[]>entry) :
|
||||
<CompileAnimationMetadata>entry;
|
||||
}
|
||||
|
||||
function _normalizeStyleMetadata(entry: CompileAnimationStyleMetadata,
|
||||
stateStyles: {[key: string]: AnimationStylesAst},
|
||||
errors: AnimationParseError[]): Array<{[key: string]: string|number}> {
|
||||
function _normalizeStyleMetadata(
|
||||
entry: CompileAnimationStyleMetadata, stateStyles: {[key: string]: AnimationStylesAst},
|
||||
errors: AnimationParseError[]): Array<{[key: string]: string | number}> {
|
||||
var normalizedStyles: any[] /** TODO #9100 */ = [];
|
||||
entry.styles.forEach(styleEntry => {
|
||||
if (isString(styleEntry)) {
|
||||
ListWrapper.addAll(normalizedStyles, _resolveStylesFromState(<string>styleEntry, stateStyles, errors));
|
||||
ListWrapper.addAll(
|
||||
normalizedStyles, _resolveStylesFromState(<string>styleEntry, stateStyles, errors));
|
||||
} else {
|
||||
normalizedStyles.push(<{[key: string]: string | number}>styleEntry);
|
||||
}
|
||||
@ -172,31 +142,30 @@ function _normalizeStyleMetadata(entry: CompileAnimationStyleMetadata,
|
||||
return normalizedStyles;
|
||||
}
|
||||
|
||||
function _normalizeStyleSteps(entry: CompileAnimationMetadata,
|
||||
stateStyles: {[key: string]: AnimationStylesAst},
|
||||
errors: AnimationParseError[]): CompileAnimationMetadata {
|
||||
function _normalizeStyleSteps(
|
||||
entry: CompileAnimationMetadata, stateStyles: {[key: string]: AnimationStylesAst},
|
||||
errors: AnimationParseError[]): CompileAnimationMetadata {
|
||||
var steps = _normalizeStyleStepEntry(entry, stateStyles, errors);
|
||||
return new CompileAnimationSequenceMetadata(steps);
|
||||
}
|
||||
|
||||
function _mergeAnimationStyles(stylesList: any[], newItem: {[key: string]: string|number}|string) {
|
||||
function _mergeAnimationStyles(
|
||||
stylesList: any[], newItem: {[key: string]: string | number} | string) {
|
||||
if (isStringMap(newItem) && stylesList.length > 0) {
|
||||
var lastIndex = stylesList.length - 1;
|
||||
var lastItem = stylesList[lastIndex];
|
||||
if (isStringMap(lastItem)) {
|
||||
stylesList[lastIndex] = StringMapWrapper.merge(
|
||||
<{[key: string]: string|number}>lastItem,
|
||||
<{[key: string]: string|number}>newItem
|
||||
);
|
||||
<{[key: string]: string | number}>lastItem, <{[key: string]: string | number}>newItem);
|
||||
return;
|
||||
}
|
||||
}
|
||||
stylesList.push(newItem);
|
||||
}
|
||||
|
||||
function _normalizeStyleStepEntry(entry: CompileAnimationMetadata,
|
||||
stateStyles: {[key: string]: AnimationStylesAst},
|
||||
errors: AnimationParseError[]): CompileAnimationMetadata[] {
|
||||
function _normalizeStyleStepEntry(
|
||||
entry: CompileAnimationMetadata, stateStyles: {[key: string]: AnimationStylesAst},
|
||||
errors: AnimationParseError[]): CompileAnimationMetadata[] {
|
||||
var steps: CompileAnimationMetadata[];
|
||||
if (entry instanceof CompileAnimationWithStepsMetadata) {
|
||||
steps = entry.steps;
|
||||
@ -215,9 +184,8 @@ function _normalizeStyleStepEntry(entry: CompileAnimationMetadata,
|
||||
if (!isPresent(combinedStyles)) {
|
||||
combinedStyles = [];
|
||||
}
|
||||
_normalizeStyleMetadata(<CompileAnimationStyleMetadata>step, stateStyles, errors).forEach(entry => {
|
||||
_mergeAnimationStyles(combinedStyles, entry);
|
||||
});
|
||||
_normalizeStyleMetadata(<CompileAnimationStyleMetadata>step, stateStyles, errors)
|
||||
.forEach(entry => { _mergeAnimationStyles(combinedStyles, entry); });
|
||||
} else {
|
||||
// it is important that we create a metadata entry of the combined styles
|
||||
// before we go on an process the animate, sequence or group metadata steps.
|
||||
@ -233,17 +201,17 @@ function _normalizeStyleStepEntry(entry: CompileAnimationMetadata,
|
||||
// those style steps are not going to be squashed
|
||||
var animateStyleValue = (<CompileAnimationAnimateMetadata>step).styles;
|
||||
if (animateStyleValue instanceof CompileAnimationStyleMetadata) {
|
||||
animateStyleValue.styles = _normalizeStyleMetadata(animateStyleValue, stateStyles, errors);
|
||||
animateStyleValue.styles =
|
||||
_normalizeStyleMetadata(animateStyleValue, stateStyles, errors);
|
||||
} else if (animateStyleValue instanceof CompileAnimationKeyframesSequenceMetadata) {
|
||||
animateStyleValue.steps.forEach(step => {
|
||||
step.styles = _normalizeStyleMetadata(step, stateStyles, errors);
|
||||
});
|
||||
animateStyleValue.steps.forEach(
|
||||
step => { step.styles = _normalizeStyleMetadata(step, stateStyles, errors); });
|
||||
}
|
||||
} else if (step instanceof CompileAnimationWithStepsMetadata) {
|
||||
let innerSteps = _normalizeStyleStepEntry(step, stateStyles, errors);
|
||||
step = step instanceof CompileAnimationGroupMetadata
|
||||
? new CompileAnimationGroupMetadata(innerSteps)
|
||||
: new CompileAnimationSequenceMetadata(innerSteps);
|
||||
step = step instanceof CompileAnimationGroupMetadata ?
|
||||
new CompileAnimationGroupMetadata(innerSteps) :
|
||||
new CompileAnimationSequenceMetadata(innerSteps);
|
||||
}
|
||||
|
||||
newSteps.push(step);
|
||||
@ -259,15 +227,18 @@ function _normalizeStyleStepEntry(entry: CompileAnimationMetadata,
|
||||
}
|
||||
|
||||
|
||||
function _resolveStylesFromState(stateName: string, stateStyles: {[key: string]: AnimationStylesAst}, errors: AnimationParseError[]) {
|
||||
var styles: {[key: string]: string|number}[] = [];
|
||||
function _resolveStylesFromState(
|
||||
stateName: string, stateStyles: {[key: string]: AnimationStylesAst},
|
||||
errors: AnimationParseError[]) {
|
||||
var styles: {[key: string]: string | number}[] = [];
|
||||
if (stateName[0] != ':') {
|
||||
errors.push(new AnimationParseError(`Animation states via styles must be prefixed with a ":"`));
|
||||
} else {
|
||||
var normalizedStateName = stateName.substring(1);
|
||||
var value = stateStyles[normalizedStateName];
|
||||
if (!isPresent(value)) {
|
||||
errors.push(new AnimationParseError(`Unable to apply styles due to missing a state: "${normalizedStateName}"`));
|
||||
errors.push(new AnimationParseError(
|
||||
`Unable to apply styles due to missing a state: "${normalizedStateName}"`));
|
||||
} else {
|
||||
value.styles.forEach(stylesEntry => {
|
||||
if (isStringMap(stylesEntry)) {
|
||||
@ -283,17 +254,17 @@ class _AnimationTimings {
|
||||
constructor(public duration: number, public delay: number, public easing: string) {}
|
||||
}
|
||||
|
||||
function _parseAnimationKeyframes(keyframeSequence: CompileAnimationKeyframesSequenceMetadata,
|
||||
currentTime: number,
|
||||
collectedStyles: StylesCollection,
|
||||
stateStyles: {[key: string]: AnimationStylesAst},
|
||||
errors: AnimationParseError[]): AnimationKeyframeAst[] {
|
||||
function _parseAnimationKeyframes(
|
||||
keyframeSequence: CompileAnimationKeyframesSequenceMetadata, currentTime: number,
|
||||
collectedStyles: StylesCollection, stateStyles: {[key: string]: AnimationStylesAst},
|
||||
errors: AnimationParseError[]): AnimationKeyframeAst[] {
|
||||
var totalEntries = keyframeSequence.steps.length;
|
||||
var totalOffsets = 0;
|
||||
keyframeSequence.steps.forEach(step => totalOffsets += (isPresent(step.offset) ? 1 : 0));
|
||||
|
||||
if (totalOffsets > 0 && totalOffsets < totalEntries) {
|
||||
errors.push(new AnimationParseError(`Not all style() entries contain an offset for the provided keyframe()`));
|
||||
errors.push(new AnimationParseError(
|
||||
`Not all style() entries contain an offset for the provided keyframe()`));
|
||||
totalOffsets = totalEntries;
|
||||
}
|
||||
|
||||
@ -305,13 +276,15 @@ function _parseAnimationKeyframes(keyframeSequence: CompileAnimationKeyframesSeq
|
||||
var lastOffset = 0;
|
||||
keyframeSequence.steps.forEach(styleMetadata => {
|
||||
var offset = styleMetadata.offset;
|
||||
var keyframeStyles: {[key: string]: string|number} = {};
|
||||
var keyframeStyles: {[key: string]: string | number} = {};
|
||||
styleMetadata.styles.forEach(entry => {
|
||||
StringMapWrapper.forEach(<{[key: string]: string|number}>entry, (value: any /** TODO #9100 */, prop: any /** TODO #9100 */) => {
|
||||
if (prop != 'offset') {
|
||||
keyframeStyles[prop] = value;
|
||||
}
|
||||
});
|
||||
StringMapWrapper.forEach(
|
||||
<{[key: string]: string | number}>entry,
|
||||
(value: any /** TODO #9100 */, prop: any /** TODO #9100 */) => {
|
||||
if (prop != 'offset') {
|
||||
keyframeStyles[prop] = value;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
if (isPresent(offset)) {
|
||||
@ -326,7 +299,7 @@ function _parseAnimationKeyframes(keyframeSequence: CompileAnimationKeyframesSeq
|
||||
});
|
||||
|
||||
if (doSortKeyframes) {
|
||||
ListWrapper.sort(rawKeyframes, (a,b) => a[0] <= b[0] ? -1 : 1);
|
||||
ListWrapper.sort(rawKeyframes, (a, b) => a[0] <= b[0] ? -1 : 1);
|
||||
}
|
||||
|
||||
var i: any /** TODO #9100 */;
|
||||
@ -348,32 +321,33 @@ function _parseAnimationKeyframes(keyframeSequence: CompileAnimationKeyframesSeq
|
||||
let entry = rawKeyframes[i];
|
||||
let styles = entry[1];
|
||||
|
||||
StringMapWrapper.forEach(styles, (value: any /** TODO #9100 */, prop: any /** TODO #9100 */) => {
|
||||
if (!isPresent(firstKeyframeStyles[prop])) {
|
||||
firstKeyframeStyles[prop] = FILL_STYLE_FLAG;
|
||||
}
|
||||
});
|
||||
StringMapWrapper.forEach(
|
||||
styles, (value: any /** TODO #9100 */, prop: any /** TODO #9100 */) => {
|
||||
if (!isPresent(firstKeyframeStyles[prop])) {
|
||||
firstKeyframeStyles[prop] = FILL_STYLE_FLAG;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
for (i = limit - 1; i >= 0; i--) {
|
||||
let entry = rawKeyframes[i];
|
||||
let styles = entry[1];
|
||||
|
||||
StringMapWrapper.forEach(styles, (value: any /** TODO #9100 */, prop: any /** TODO #9100 */) => {
|
||||
if (!isPresent(lastKeyframeStyles[prop])) {
|
||||
lastKeyframeStyles[prop] = value;
|
||||
}
|
||||
});
|
||||
StringMapWrapper.forEach(
|
||||
styles, (value: any /** TODO #9100 */, prop: any /** TODO #9100 */) => {
|
||||
if (!isPresent(lastKeyframeStyles[prop])) {
|
||||
lastKeyframeStyles[prop] = value;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return rawKeyframes.map(entry => new AnimationKeyframeAst(entry[0], new AnimationStylesAst([entry[1]])));
|
||||
return rawKeyframes.map(
|
||||
entry => new AnimationKeyframeAst(entry[0], new AnimationStylesAst([entry[1]])));
|
||||
}
|
||||
|
||||
function _parseTransitionAnimation(entry: CompileAnimationMetadata,
|
||||
currentTime: number,
|
||||
collectedStyles: StylesCollection,
|
||||
stateStyles: {[key: string]: AnimationStylesAst},
|
||||
errors: AnimationParseError[]): AnimationAst {
|
||||
function _parseTransitionAnimation(
|
||||
entry: CompileAnimationMetadata, currentTime: number, collectedStyles: StylesCollection,
|
||||
stateStyles: {[key: string]: AnimationStylesAst}, errors: AnimationParseError[]): AnimationAst {
|
||||
var ast: any /** TODO #9100 */;
|
||||
var playTime = 0;
|
||||
var startingTime = currentTime;
|
||||
@ -388,10 +362,11 @@ function _parseTransitionAnimation(entry: CompileAnimationMetadata,
|
||||
if (entry instanceof CompileAnimationStyleMetadata) {
|
||||
entry.styles.forEach(stylesEntry => {
|
||||
// by this point we know that we only have stringmap values
|
||||
var map = <{[key: string]: string|number}>stylesEntry;
|
||||
StringMapWrapper.forEach(map, (value: any /** TODO #9100 */, prop: any /** TODO #9100 */) => {
|
||||
collectedStyles.insertAtTime(prop, time, value);
|
||||
});
|
||||
var map = <{[key: string]: string | number}>stylesEntry;
|
||||
StringMapWrapper.forEach(
|
||||
map, (value: any /** TODO #9100 */, prop: any /** TODO #9100 */) => {
|
||||
collectedStyles.insertAtTime(prop, time, value);
|
||||
});
|
||||
});
|
||||
previousStyles = entry.styles;
|
||||
return;
|
||||
@ -432,25 +407,26 @@ function _parseTransitionAnimation(entry: CompileAnimationMetadata,
|
||||
|
||||
var keyframes: any /** TODO #9100 */;
|
||||
if (styles instanceof CompileAnimationKeyframesSequenceMetadata) {
|
||||
keyframes = _parseAnimationKeyframes(styles, currentTime, collectedStyles, stateStyles, errors);
|
||||
keyframes =
|
||||
_parseAnimationKeyframes(styles, currentTime, collectedStyles, stateStyles, errors);
|
||||
} else {
|
||||
let styleData = <CompileAnimationStyleMetadata>styles;
|
||||
let offset = _TERMINAL_KEYFRAME;
|
||||
let styleAst = new AnimationStylesAst(<{[key: string]: string|number}[]>styleData.styles);
|
||||
let styleAst = new AnimationStylesAst(<{[key: string]: string | number}[]>styleData.styles);
|
||||
var keyframe = new AnimationKeyframeAst(offset, styleAst);
|
||||
keyframes = [keyframe];
|
||||
}
|
||||
|
||||
ast = new AnimationStepAst(new AnimationStylesAst([]), keyframes, timings.duration, timings.delay, timings.easing);
|
||||
ast = new AnimationStepAst(
|
||||
new AnimationStylesAst([]), keyframes, timings.duration, timings.delay, timings.easing);
|
||||
playTime = timings.duration + timings.delay;
|
||||
currentTime += playTime;
|
||||
|
||||
keyframes.forEach((keyframe: any /** TODO #9100 */) =>
|
||||
keyframe.styles.styles.forEach((entry: any /** TODO #9100 */) =>
|
||||
StringMapWrapper.forEach(entry, (value: any /** TODO #9100 */, prop: any /** TODO #9100 */) =>
|
||||
collectedStyles.insertAtTime(prop, currentTime, value))
|
||||
)
|
||||
);
|
||||
keyframes.forEach(
|
||||
(keyframe: any /** TODO #9100 */) => keyframe.styles.styles.forEach(
|
||||
(entry: any /** TODO #9100 */) => StringMapWrapper.forEach(
|
||||
entry, (value: any /** TODO #9100 */, prop: any /** TODO #9100 */) =>
|
||||
collectedStyles.insertAtTime(prop, currentTime, value))));
|
||||
} else {
|
||||
// if the code reaches this stage then an error
|
||||
// has already been populated within the _normalizeStyleSteps()
|
||||
@ -463,15 +439,15 @@ function _parseTransitionAnimation(entry: CompileAnimationMetadata,
|
||||
return ast;
|
||||
}
|
||||
|
||||
function _fillAnimationAstStartingKeyframes(ast: AnimationAst, collectedStyles: StylesCollection,
|
||||
errors: AnimationParseError[]): void {
|
||||
function _fillAnimationAstStartingKeyframes(
|
||||
ast: AnimationAst, collectedStyles: StylesCollection, errors: AnimationParseError[]): void {
|
||||
// steps that only contain style will not be filled
|
||||
if ((ast instanceof AnimationStepAst) && ast.keyframes.length > 0) {
|
||||
var keyframes = ast.keyframes;
|
||||
if (keyframes.length == 1) {
|
||||
var endKeyframe = keyframes[0];
|
||||
var startKeyframe = _createStartKeyframeFromEndKeyframe(endKeyframe, ast.startTime,
|
||||
ast.playTime, collectedStyles, errors);
|
||||
var startKeyframe = _createStartKeyframeFromEndKeyframe(
|
||||
endKeyframe, ast.startTime, ast.playTime, collectedStyles, errors);
|
||||
ast.keyframes = [startKeyframe, endKeyframe];
|
||||
}
|
||||
} else if (ast instanceof AnimationWithStepsAst) {
|
||||
@ -479,8 +455,8 @@ function _fillAnimationAstStartingKeyframes(ast: AnimationAst, collectedStyles:
|
||||
}
|
||||
}
|
||||
|
||||
function _parseTimeExpression(exp: string | number,
|
||||
errors: AnimationParseError[]): _AnimationTimings {
|
||||
function _parseTimeExpression(
|
||||
exp: string | number, errors: AnimationParseError[]): _AnimationTimings {
|
||||
var regex = /^([\.\d]+)(m?s)(?:\s+([\.\d]+)(m?s))?(?:\s+([-a-z]+(?:\(.+?\))?))?/gi;
|
||||
var duration: number;
|
||||
var delay: number = 0;
|
||||
@ -520,17 +496,18 @@ function _parseTimeExpression(exp: string | number,
|
||||
return new _AnimationTimings(duration, delay, easing);
|
||||
}
|
||||
|
||||
function _createStartKeyframeFromEndKeyframe(endKeyframe: AnimationKeyframeAst, startTime: number,
|
||||
duration: number, collectedStyles: StylesCollection,
|
||||
errors: AnimationParseError[]): AnimationKeyframeAst {
|
||||
function _createStartKeyframeFromEndKeyframe(
|
||||
endKeyframe: AnimationKeyframeAst, startTime: number, duration: number,
|
||||
collectedStyles: StylesCollection, errors: AnimationParseError[]): AnimationKeyframeAst {
|
||||
var values: {[key: string]: string | number} = {};
|
||||
var endTime = startTime + duration;
|
||||
endKeyframe.styles.styles.forEach((styleData: {[key: string]: string|number}) => {
|
||||
endKeyframe.styles.styles.forEach((styleData: {[key: string]: string | number}) => {
|
||||
StringMapWrapper.forEach(styleData, (val: any /** TODO #9100 */, prop: any /** TODO #9100 */) => {
|
||||
if (prop == 'offset') return;
|
||||
|
||||
var resultIndex = collectedStyles.indexOfAtOrBeforeTime(prop, startTime);
|
||||
var resultEntry: any /** TODO #9100 */, nextEntry: any /** TODO #9100 */, value: any /** TODO #9100 */;
|
||||
var resultEntry: any /** TODO #9100 */, nextEntry: any /** TODO #9100 */,
|
||||
value: any /** TODO #9100 */;
|
||||
if (isPresent(resultIndex)) {
|
||||
resultEntry = collectedStyles.getByIndex(prop, resultIndex);
|
||||
value = resultEntry.value;
|
||||
|
@ -1,10 +1,10 @@
|
||||
import {isPresent} from '../facade/lang';
|
||||
import {ListWrapper} from '../facade/collection';
|
||||
import {isPresent} from '../facade/lang';
|
||||
|
||||
export class StylesCollectionEntry {
|
||||
constructor(public time: number, public value: string | number) {}
|
||||
constructor(public time: number, public value: string|number) {}
|
||||
|
||||
matches(time: number, value: string | number): boolean {
|
||||
matches(time: number, value: string|number): boolean {
|
||||
return time == this.time && value == this.value;
|
||||
}
|
||||
}
|
||||
@ -12,7 +12,7 @@ export class StylesCollectionEntry {
|
||||
export class StylesCollection {
|
||||
styles: {[key: string]: StylesCollectionEntry[]} = {};
|
||||
|
||||
insertAtTime(property: string, time: number, value: string | number) {
|
||||
insertAtTime(property: string, time: number, value: string|number) {
|
||||
var tuple = new StylesCollectionEntry(time, value);
|
||||
var entries = this.styles[property];
|
||||
if (!isPresent(entries)) {
|
||||
|
Reference in New Issue
Block a user