Revert "perf(animations): reduce size of bundle by removing AST classes (#19539)"
This reverts commit d5c9c5f183
.
This commit is contained in:
parent
9fecd72f44
commit
b1ca5d4ddf
|
@ -5,7 +5,7 @@
|
||||||
* Use of this source code is governed by an MIT-style license that can be
|
* 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
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
import {AnimationMetadata, AnimationMetadataType, AnimationOptions, ɵStyleData} from '@angular/animations';
|
import {AnimationMetadata, AnimationOptions, ɵStyleData} from '@angular/animations';
|
||||||
|
|
||||||
import {AnimationDriver} from '../render/animation_driver';
|
import {AnimationDriver} from '../render/animation_driver';
|
||||||
import {normalizeStyles} from '../util';
|
import {normalizeStyles} from '../util';
|
||||||
|
@ -17,7 +17,7 @@ import {AnimationTimelineInstruction} from './animation_timeline_instruction';
|
||||||
import {ElementInstructionMap} from './element_instruction_map';
|
import {ElementInstructionMap} from './element_instruction_map';
|
||||||
|
|
||||||
export class Animation {
|
export class Animation {
|
||||||
private _animationAst: Ast<AnimationMetadataType>;
|
private _animationAst: Ast;
|
||||||
constructor(private _driver: AnimationDriver, input: AnimationMetadata|AnimationMetadata[]) {
|
constructor(private _driver: AnimationDriver, input: AnimationMetadata|AnimationMetadata[]) {
|
||||||
const errors: any[] = [];
|
const errors: any[] = [];
|
||||||
const ast = buildAnimationAst(_driver, input, errors);
|
const ast = buildAnimationAst(_driver, input, errors);
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
* Use of this source code is governed by an MIT-style license that can be
|
* 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
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
import {AnimateTimings, AnimationMetadataType, AnimationOptions, ɵStyleData} from '@angular/animations';
|
import {AnimateTimings, AnimationOptions, ɵStyleData} from '@angular/animations';
|
||||||
|
|
||||||
const EMPTY_ANIMATION_OPTIONS: AnimationOptions = {};
|
const EMPTY_ANIMATION_OPTIONS: AnimationOptions = {};
|
||||||
|
|
||||||
|
@ -23,90 +23,129 @@ export interface AstVisitor {
|
||||||
visitAnimateRef(ast: AnimateRefAst, context: any): any;
|
visitAnimateRef(ast: AnimateRefAst, context: any): any;
|
||||||
visitQuery(ast: QueryAst, context: any): any;
|
visitQuery(ast: QueryAst, context: any): any;
|
||||||
visitStagger(ast: StaggerAst, context: any): any;
|
visitStagger(ast: StaggerAst, context: any): any;
|
||||||
|
visitTiming(ast: TimingAst, context: any): any;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Ast<T extends AnimationMetadataType> {
|
export abstract class Ast {
|
||||||
type: T;
|
abstract visit(ast: AstVisitor, context: any): any;
|
||||||
options: AnimationOptions|null;
|
public options: AnimationOptions = EMPTY_ANIMATION_OPTIONS;
|
||||||
|
|
||||||
|
get params(): {[name: string]: any}|null { return this.options['params'] || null; }
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface TriggerAst extends Ast<AnimationMetadataType.Trigger> {
|
export class TriggerAst extends Ast {
|
||||||
type: AnimationMetadataType.Trigger;
|
public queryCount: number = 0;
|
||||||
name: string;
|
public depCount: number = 0;
|
||||||
states: StateAst[];
|
|
||||||
transitions: TransitionAst[];
|
constructor(public name: string, public states: StateAst[], public transitions: TransitionAst[]) {
|
||||||
queryCount: number;
|
super();
|
||||||
depCount: number;
|
}
|
||||||
|
|
||||||
|
visit(visitor: AstVisitor, context: any): any { return visitor.visitTrigger(this, context); }
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface StateAst extends Ast<AnimationMetadataType.State> {
|
export class StateAst extends Ast {
|
||||||
type: AnimationMetadataType.State;
|
constructor(public name: string, public style: StyleAst) { super(); }
|
||||||
name: string;
|
|
||||||
style: StyleAst;
|
visit(visitor: AstVisitor, context: any): any { return visitor.visitState(this, context); }
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface TransitionAst extends Ast<AnimationMetadataType.Transition> {
|
export class TransitionAst extends Ast {
|
||||||
matchers: ((fromState: string, toState: string) => boolean)[];
|
public queryCount: number = 0;
|
||||||
animation: Ast<AnimationMetadataType>;
|
public depCount: number = 0;
|
||||||
queryCount: number;
|
|
||||||
depCount: number;
|
constructor(
|
||||||
|
public matchers: ((fromState: string, toState: string) => boolean)[], public animation: Ast) {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
visit(visitor: AstVisitor, context: any): any { return visitor.visitTransition(this, context); }
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface SequenceAst extends Ast<AnimationMetadataType.Sequence> {
|
export class SequenceAst extends Ast {
|
||||||
steps: Ast<AnimationMetadataType>[];
|
constructor(public steps: Ast[]) { super(); }
|
||||||
|
|
||||||
|
visit(visitor: AstVisitor, context: any): any { return visitor.visitSequence(this, context); }
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface GroupAst extends Ast<AnimationMetadataType.Group> {
|
export class GroupAst extends Ast {
|
||||||
steps: Ast<AnimationMetadataType>[];
|
constructor(public steps: Ast[]) { super(); }
|
||||||
|
|
||||||
|
visit(visitor: AstVisitor, context: any): any { return visitor.visitGroup(this, context); }
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface AnimateAst extends Ast<AnimationMetadataType.Animate> {
|
export class AnimateAst extends Ast {
|
||||||
timings: TimingAst;
|
constructor(public timings: TimingAst, public style: StyleAst|KeyframesAst) { super(); }
|
||||||
style: StyleAst|KeyframesAst;
|
|
||||||
|
visit(visitor: AstVisitor, context: any): any { return visitor.visitAnimate(this, context); }
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface StyleAst extends Ast<AnimationMetadataType.Style> {
|
export class StyleAst extends Ast {
|
||||||
styles: (ɵStyleData|string)[];
|
public isEmptyStep = false;
|
||||||
easing: string|null;
|
public containsDynamicStyles = false;
|
||||||
offset: number|null;
|
|
||||||
containsDynamicStyles: boolean;
|
constructor(
|
||||||
isEmptyStep?: boolean;
|
public styles: (ɵStyleData|string)[], public easing: string|null,
|
||||||
|
public offset: number|null) {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
visit(visitor: AstVisitor, context: any): any { return visitor.visitStyle(this, context); }
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface KeyframesAst extends Ast<AnimationMetadataType.Keyframes> { styles: StyleAst[]; }
|
export class KeyframesAst extends Ast {
|
||||||
|
constructor(public styles: StyleAst[]) { super(); }
|
||||||
|
|
||||||
export interface ReferenceAst extends Ast<AnimationMetadataType.Reference> {
|
visit(visitor: AstVisitor, context: any): any { return visitor.visitKeyframes(this, context); }
|
||||||
animation: Ast<AnimationMetadataType>;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface AnimateChildAst extends Ast<AnimationMetadataType.AnimateChild> {}
|
export class ReferenceAst extends Ast {
|
||||||
|
constructor(public animation: Ast) { super(); }
|
||||||
|
|
||||||
export interface AnimateRefAst extends Ast<AnimationMetadataType.AnimateRef> {
|
visit(visitor: AstVisitor, context: any): any { return visitor.visitReference(this, context); }
|
||||||
animation: ReferenceAst;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface QueryAst extends Ast<AnimationMetadataType.Query> {
|
export class AnimateChildAst extends Ast {
|
||||||
selector: string;
|
constructor() { super(); }
|
||||||
limit: number;
|
|
||||||
optional: boolean;
|
visit(visitor: AstVisitor, context: any): any { return visitor.visitAnimateChild(this, context); }
|
||||||
includeSelf: boolean;
|
|
||||||
animation: Ast<AnimationMetadataType>;
|
|
||||||
originalSelector: string;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface StaggerAst extends Ast<AnimationMetadataType.Stagger> {
|
export class AnimateRefAst extends Ast {
|
||||||
timings: AnimateTimings;
|
constructor(public animation: ReferenceAst) { super(); }
|
||||||
animation: Ast<AnimationMetadataType>;
|
|
||||||
|
visit(visitor: AstVisitor, context: any): any { return visitor.visitAnimateRef(this, context); }
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface TimingAst {
|
export class QueryAst extends Ast {
|
||||||
duration: number;
|
public originalSelector: string;
|
||||||
delay: number;
|
|
||||||
easing: string|null;
|
constructor(
|
||||||
dynamic?: boolean;
|
public selector: string, public limit: number, public optional: boolean,
|
||||||
|
public includeSelf: boolean, public animation: Ast) {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
visit(visitor: AstVisitor, context: any): any { return visitor.visitQuery(this, context); }
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface DynamicTimingAst extends TimingAst {
|
export class StaggerAst extends Ast {
|
||||||
strValue: string;
|
constructor(public timings: AnimateTimings, public animation: Ast) { super(); }
|
||||||
dynamic: true;
|
|
||||||
|
visit(visitor: AstVisitor, context: any): any { return visitor.visitStagger(this, context); }
|
||||||
|
}
|
||||||
|
|
||||||
|
export class TimingAst extends Ast {
|
||||||
|
constructor(
|
||||||
|
public duration: number, public delay: number = 0, public easing: string|null = null) {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
visit(visitor: AstVisitor, context: any): any { return visitor.visitTiming(this, context); }
|
||||||
|
}
|
||||||
|
|
||||||
|
export class DynamicTimingAst extends TimingAst {
|
||||||
|
constructor(public value: string) { super(0, 0, ''); }
|
||||||
|
|
||||||
|
visit(visitor: AstVisitor, context: any): any { return visitor.visitTiming(this, context); }
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,10 +9,10 @@ import {AUTO_STYLE, AnimateTimings, AnimationAnimateChildMetadata, AnimationAnim
|
||||||
|
|
||||||
import {AnimationDriver} from '../render/animation_driver';
|
import {AnimationDriver} from '../render/animation_driver';
|
||||||
import {getOrSetAsInMap} from '../render/shared';
|
import {getOrSetAsInMap} from '../render/shared';
|
||||||
import {ENTER_SELECTOR, LEAVE_SELECTOR, NG_ANIMATING_SELECTOR, NG_TRIGGER_SELECTOR, SUBSTITUTION_EXPR_START, copyObj, extractStyleParams, iteratorToArray, normalizeAnimationEntry, resolveTiming, validateStyleParams, visitDslNode} from '../util';
|
import {ENTER_SELECTOR, LEAVE_SELECTOR, NG_ANIMATING_SELECTOR, NG_TRIGGER_SELECTOR, SUBSTITUTION_EXPR_START, copyObj, extractStyleParams, iteratorToArray, normalizeAnimationEntry, resolveTiming, validateStyleParams} from '../util';
|
||||||
|
|
||||||
import {AnimateAst, AnimateChildAst, AnimateRefAst, Ast, DynamicTimingAst, GroupAst, KeyframesAst, QueryAst, ReferenceAst, SequenceAst, StaggerAst, StateAst, StyleAst, TimingAst, TransitionAst, TriggerAst} from './animation_ast';
|
import {AnimateAst, AnimateChildAst, AnimateRefAst, Ast, DynamicTimingAst, GroupAst, KeyframesAst, QueryAst, ReferenceAst, SequenceAst, StaggerAst, StateAst, StyleAst, TimingAst, TransitionAst, TriggerAst} from './animation_ast';
|
||||||
import {AnimationDslVisitor} from './animation_dsl_visitor';
|
import {AnimationDslVisitor, visitAnimationNode} from './animation_dsl_visitor';
|
||||||
import {parseTransitionExpr} from './animation_transition_expr';
|
import {parseTransitionExpr} from './animation_transition_expr';
|
||||||
|
|
||||||
const SELF_TOKEN = ':self';
|
const SELF_TOKEN = ':self';
|
||||||
|
@ -56,7 +56,7 @@ const SELF_TOKEN_REGEX = new RegExp(`\s*${SELF_TOKEN}\s*,?`, 'g');
|
||||||
*/
|
*/
|
||||||
export function buildAnimationAst(
|
export function buildAnimationAst(
|
||||||
driver: AnimationDriver, metadata: AnimationMetadata | AnimationMetadata[],
|
driver: AnimationDriver, metadata: AnimationMetadata | AnimationMetadata[],
|
||||||
errors: any[]): Ast<AnimationMetadataType> {
|
errors: any[]): Ast {
|
||||||
return new AnimationAstBuilderVisitor(driver).build(metadata, errors);
|
return new AnimationAstBuilderVisitor(driver).build(metadata, errors);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,12 +69,10 @@ const ROOT_SELECTOR = '';
|
||||||
export class AnimationAstBuilderVisitor implements AnimationDslVisitor {
|
export class AnimationAstBuilderVisitor implements AnimationDslVisitor {
|
||||||
constructor(private _driver: AnimationDriver) {}
|
constructor(private _driver: AnimationDriver) {}
|
||||||
|
|
||||||
build(metadata: AnimationMetadata|AnimationMetadata[], errors: any[]):
|
build(metadata: AnimationMetadata|AnimationMetadata[], errors: any[]): Ast {
|
||||||
Ast<AnimationMetadataType> {
|
|
||||||
const context = new AnimationAstBuilderContext(errors);
|
const context = new AnimationAstBuilderContext(errors);
|
||||||
this._resetContextStyleTimingState(context);
|
this._resetContextStyleTimingState(context);
|
||||||
return <Ast<AnimationMetadataType>>visitDslNode(
|
return visitAnimationNode(this, normalizeAnimationEntry(metadata), context) as Ast;
|
||||||
this, normalizeAnimationEntry(metadata), context);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private _resetContextStyleTimingState(context: AnimationAstBuilderContext) {
|
private _resetContextStyleTimingState(context: AnimationAstBuilderContext) {
|
||||||
|
@ -110,12 +108,11 @@ export class AnimationAstBuilderVisitor implements AnimationDslVisitor {
|
||||||
'only state() and transition() definitions can sit inside of a trigger()');
|
'only state() and transition() definitions can sit inside of a trigger()');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
const ast = new TriggerAst(metadata.name, states, transitions);
|
||||||
return {
|
ast.options = normalizeAnimationOptions(metadata.options);
|
||||||
type: AnimationMetadataType.Trigger,
|
ast.queryCount = queryCount;
|
||||||
name: metadata.name, states, transitions, queryCount, depCount,
|
ast.depCount = depCount;
|
||||||
options: null
|
return ast;
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
visitState(metadata: AnimationStateMetadata, context: AnimationAstBuilderContext): StateAst {
|
visitState(metadata: AnimationStateMetadata, context: AnimationAstBuilderContext): StateAst {
|
||||||
|
@ -143,38 +140,31 @@ export class AnimationAstBuilderVisitor implements AnimationDslVisitor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
const stateAst = new StateAst(metadata.name, styleAst);
|
||||||
type: AnimationMetadataType.State,
|
if (astParams) {
|
||||||
name: metadata.name,
|
stateAst.options = {params: astParams};
|
||||||
style: styleAst,
|
}
|
||||||
options: astParams ? {params: astParams} : null
|
return stateAst;
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
visitTransition(metadata: AnimationTransitionMetadata, context: AnimationAstBuilderContext):
|
visitTransition(metadata: AnimationTransitionMetadata, context: AnimationAstBuilderContext):
|
||||||
TransitionAst {
|
TransitionAst {
|
||||||
context.queryCount = 0;
|
context.queryCount = 0;
|
||||||
context.depCount = 0;
|
context.depCount = 0;
|
||||||
const animation = visitDslNode(this, normalizeAnimationEntry(metadata.animation), context);
|
const entry = visitAnimationNode(this, normalizeAnimationEntry(metadata.animation), context);
|
||||||
const matchers = parseTransitionExpr(metadata.expr, context.errors);
|
const matchers = parseTransitionExpr(metadata.expr, context.errors);
|
||||||
|
const ast = new TransitionAst(matchers, entry);
|
||||||
return {
|
ast.options = normalizeAnimationOptions(metadata.options);
|
||||||
type: AnimationMetadataType.Transition,
|
ast.queryCount = context.queryCount;
|
||||||
matchers,
|
ast.depCount = context.depCount;
|
||||||
animation,
|
return ast;
|
||||||
queryCount: context.queryCount,
|
|
||||||
depCount: context.depCount,
|
|
||||||
options: normalizeAnimationOptions(metadata.options)
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
visitSequence(metadata: AnimationSequenceMetadata, context: AnimationAstBuilderContext):
|
visitSequence(metadata: AnimationSequenceMetadata, context: AnimationAstBuilderContext):
|
||||||
SequenceAst {
|
SequenceAst {
|
||||||
return {
|
const ast = new SequenceAst(metadata.steps.map(s => visitAnimationNode(this, s, context)));
|
||||||
type: AnimationMetadataType.Sequence,
|
ast.options = normalizeAnimationOptions(metadata.options);
|
||||||
steps: metadata.steps.map(s => visitDslNode(this, s, context)),
|
return ast;
|
||||||
options: normalizeAnimationOptions(metadata.options)
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
visitGroup(metadata: AnimationGroupMetadata, context: AnimationAstBuilderContext): GroupAst {
|
visitGroup(metadata: AnimationGroupMetadata, context: AnimationAstBuilderContext): GroupAst {
|
||||||
|
@ -182,17 +172,15 @@ export class AnimationAstBuilderVisitor implements AnimationDslVisitor {
|
||||||
let furthestTime = 0;
|
let furthestTime = 0;
|
||||||
const steps = metadata.steps.map(step => {
|
const steps = metadata.steps.map(step => {
|
||||||
context.currentTime = currentTime;
|
context.currentTime = currentTime;
|
||||||
const innerAst = visitDslNode(this, step, context);
|
const innerAst = visitAnimationNode(this, step, context);
|
||||||
furthestTime = Math.max(furthestTime, context.currentTime);
|
furthestTime = Math.max(furthestTime, context.currentTime);
|
||||||
return innerAst;
|
return innerAst;
|
||||||
});
|
});
|
||||||
|
|
||||||
context.currentTime = furthestTime;
|
context.currentTime = furthestTime;
|
||||||
return {
|
const ast = new GroupAst(steps);
|
||||||
type: AnimationMetadataType.Group,
|
ast.options = normalizeAnimationOptions(metadata.options);
|
||||||
steps,
|
return ast;
|
||||||
options: normalizeAnimationOptions(metadata.options)
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
visitAnimate(metadata: AnimationAnimateMetadata, context: AnimationAstBuilderContext):
|
visitAnimate(metadata: AnimationAnimateMetadata, context: AnimationAstBuilderContext):
|
||||||
|
@ -200,10 +188,10 @@ export class AnimationAstBuilderVisitor implements AnimationDslVisitor {
|
||||||
const timingAst = constructTimingAst(metadata.timings, context.errors);
|
const timingAst = constructTimingAst(metadata.timings, context.errors);
|
||||||
context.currentAnimateTimings = timingAst;
|
context.currentAnimateTimings = timingAst;
|
||||||
|
|
||||||
let styleAst: StyleAst|KeyframesAst;
|
let styles: StyleAst|KeyframesAst;
|
||||||
let styleMetadata: AnimationMetadata = metadata.styles ? metadata.styles : style({});
|
let styleMetadata: AnimationMetadata = metadata.styles ? metadata.styles : style({});
|
||||||
if (styleMetadata.type == AnimationMetadataType.Keyframes) {
|
if (styleMetadata.type == AnimationMetadataType.Keyframes) {
|
||||||
styleAst = this.visitKeyframes(styleMetadata as AnimationKeyframesSequenceMetadata, context);
|
styles = this.visitKeyframes(styleMetadata as AnimationKeyframesSequenceMetadata, context);
|
||||||
} else {
|
} else {
|
||||||
let styleMetadata = metadata.styles as AnimationStyleMetadata;
|
let styleMetadata = metadata.styles as AnimationStyleMetadata;
|
||||||
let isEmpty = false;
|
let isEmpty = false;
|
||||||
|
@ -216,18 +204,13 @@ export class AnimationAstBuilderVisitor implements AnimationDslVisitor {
|
||||||
styleMetadata = style(newStyleData);
|
styleMetadata = style(newStyleData);
|
||||||
}
|
}
|
||||||
context.currentTime += timingAst.duration + timingAst.delay;
|
context.currentTime += timingAst.duration + timingAst.delay;
|
||||||
const _styleAst = this.visitStyle(styleMetadata, context);
|
const styleAst = this.visitStyle(styleMetadata, context);
|
||||||
_styleAst.isEmptyStep = isEmpty;
|
styleAst.isEmptyStep = isEmpty;
|
||||||
styleAst = _styleAst;
|
styles = styleAst;
|
||||||
}
|
}
|
||||||
|
|
||||||
context.currentAnimateTimings = null;
|
context.currentAnimateTimings = null;
|
||||||
return {
|
return new AnimateAst(timingAst, styles);
|
||||||
type: AnimationMetadataType.Animate,
|
|
||||||
timings: timingAst,
|
|
||||||
style: styleAst,
|
|
||||||
options: null
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
visitStyle(metadata: AnimationStyleMetadata, context: AnimationAstBuilderContext): StyleAst {
|
visitStyle(metadata: AnimationStyleMetadata, context: AnimationAstBuilderContext): StyleAst {
|
||||||
|
@ -277,13 +260,9 @@ export class AnimationAstBuilderVisitor implements AnimationDslVisitor {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return {
|
const ast = new StyleAst(styles, collectedEasing, metadata.offset);
|
||||||
type: AnimationMetadataType.Style,
|
ast.containsDynamicStyles = containsDynamicStyles;
|
||||||
styles,
|
return ast;
|
||||||
easing: collectedEasing,
|
|
||||||
offset: metadata.offset, containsDynamicStyles,
|
|
||||||
options: null
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private _validateStyleAst(ast: StyleAst, context: AnimationAstBuilderContext): void {
|
private _validateStyleAst(ast: StyleAst, context: AnimationAstBuilderContext): void {
|
||||||
|
@ -334,10 +313,9 @@ export class AnimationAstBuilderVisitor implements AnimationDslVisitor {
|
||||||
|
|
||||||
visitKeyframes(metadata: AnimationKeyframesSequenceMetadata, context: AnimationAstBuilderContext):
|
visitKeyframes(metadata: AnimationKeyframesSequenceMetadata, context: AnimationAstBuilderContext):
|
||||||
KeyframesAst {
|
KeyframesAst {
|
||||||
const ast: KeyframesAst = {type: AnimationMetadataType.Keyframes, styles: [], options: null};
|
|
||||||
if (!context.currentAnimateTimings) {
|
if (!context.currentAnimateTimings) {
|
||||||
context.errors.push(`keyframes() must be placed inside of a call to animate()`);
|
context.errors.push(`keyframes() must be placed inside of a call to animate()`);
|
||||||
return ast;
|
return new KeyframesAst([]);
|
||||||
}
|
}
|
||||||
|
|
||||||
const MAX_KEYFRAME_OFFSET = 1;
|
const MAX_KEYFRAME_OFFSET = 1;
|
||||||
|
@ -391,38 +369,33 @@ export class AnimationAstBuilderVisitor implements AnimationDslVisitor {
|
||||||
currentAnimateTimings.duration = durationUpToThisFrame;
|
currentAnimateTimings.duration = durationUpToThisFrame;
|
||||||
this._validateStyleAst(kf, context);
|
this._validateStyleAst(kf, context);
|
||||||
kf.offset = offset;
|
kf.offset = offset;
|
||||||
|
|
||||||
ast.styles.push(kf);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return ast;
|
return new KeyframesAst(keyframes);
|
||||||
}
|
}
|
||||||
|
|
||||||
visitReference(metadata: AnimationReferenceMetadata, context: AnimationAstBuilderContext):
|
visitReference(metadata: AnimationReferenceMetadata, context: AnimationAstBuilderContext):
|
||||||
ReferenceAst {
|
ReferenceAst {
|
||||||
return {
|
const entry = visitAnimationNode(this, normalizeAnimationEntry(metadata.animation), context);
|
||||||
type: AnimationMetadataType.Reference,
|
const ast = new ReferenceAst(entry);
|
||||||
animation: visitDslNode(this, normalizeAnimationEntry(metadata.animation), context),
|
ast.options = normalizeAnimationOptions(metadata.options);
|
||||||
options: normalizeAnimationOptions(metadata.options)
|
return ast;
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
visitAnimateChild(metadata: AnimationAnimateChildMetadata, context: AnimationAstBuilderContext):
|
visitAnimateChild(metadata: AnimationAnimateChildMetadata, context: AnimationAstBuilderContext):
|
||||||
AnimateChildAst {
|
AnimateChildAst {
|
||||||
context.depCount++;
|
context.depCount++;
|
||||||
return {
|
const ast = new AnimateChildAst();
|
||||||
type: AnimationMetadataType.AnimateChild,
|
ast.options = normalizeAnimationOptions(metadata.options);
|
||||||
options: normalizeAnimationOptions(metadata.options)
|
return ast;
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
visitAnimateRef(metadata: AnimationAnimateRefMetadata, context: AnimationAstBuilderContext):
|
visitAnimateRef(metadata: AnimationAnimateRefMetadata, context: AnimationAstBuilderContext):
|
||||||
AnimateRefAst {
|
AnimateRefAst {
|
||||||
return {
|
const animation = this.visitReference(metadata.animation, context);
|
||||||
type: AnimationMetadataType.AnimateRef,
|
const ast = new AnimateRefAst(animation);
|
||||||
animation: this.visitReference(metadata.animation, context),
|
ast.options = normalizeAnimationOptions(metadata.options);
|
||||||
options: normalizeAnimationOptions(metadata.options)
|
return ast;
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
visitQuery(metadata: AnimationQueryMetadata, context: AnimationAstBuilderContext): QueryAst {
|
visitQuery(metadata: AnimationQueryMetadata, context: AnimationAstBuilderContext): QueryAst {
|
||||||
|
@ -436,18 +409,14 @@ export class AnimationAstBuilderVisitor implements AnimationDslVisitor {
|
||||||
parentSelector.length ? (parentSelector + ' ' + selector) : selector;
|
parentSelector.length ? (parentSelector + ' ' + selector) : selector;
|
||||||
getOrSetAsInMap(context.collectedStyles, context.currentQuerySelector, {});
|
getOrSetAsInMap(context.collectedStyles, context.currentQuerySelector, {});
|
||||||
|
|
||||||
const animation = visitDslNode(this, normalizeAnimationEntry(metadata.animation), context);
|
const entry = visitAnimationNode(this, normalizeAnimationEntry(metadata.animation), context);
|
||||||
context.currentQuery = null;
|
context.currentQuery = null;
|
||||||
context.currentQuerySelector = parentSelector;
|
context.currentQuerySelector = parentSelector;
|
||||||
|
|
||||||
return {
|
const ast = new QueryAst(selector, options.limit || 0, !!options.optional, includeSelf, entry);
|
||||||
type: AnimationMetadataType.Query,
|
ast.originalSelector = metadata.selector;
|
||||||
selector,
|
ast.options = normalizeAnimationOptions(metadata.options);
|
||||||
limit: options.limit || 0,
|
return ast;
|
||||||
optional: !!options.optional, includeSelf, animation,
|
|
||||||
originalSelector: metadata.selector,
|
|
||||||
options: normalizeAnimationOptions(metadata.options)
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
visitStagger(metadata: AnimationStaggerMetadata, context: AnimationAstBuilderContext):
|
visitStagger(metadata: AnimationStaggerMetadata, context: AnimationAstBuilderContext):
|
||||||
|
@ -458,12 +427,9 @@ export class AnimationAstBuilderVisitor implements AnimationDslVisitor {
|
||||||
const timings = metadata.timings === 'full' ?
|
const timings = metadata.timings === 'full' ?
|
||||||
{duration: 0, delay: 0, easing: 'full'} :
|
{duration: 0, delay: 0, easing: 'full'} :
|
||||||
resolveTiming(metadata.timings, context.errors, true);
|
resolveTiming(metadata.timings, context.errors, true);
|
||||||
|
const animation =
|
||||||
return {
|
visitAnimationNode(this, normalizeAnimationEntry(metadata.animation), context);
|
||||||
type: AnimationMetadataType.Stagger,
|
return new StaggerAst(timings, animation);
|
||||||
animation: visitDslNode(this, normalizeAnimationEntry(metadata.animation), context), timings,
|
|
||||||
options: null
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -535,20 +501,17 @@ function constructTimingAst(value: string | number | AnimateTimings, errors: any
|
||||||
timings = value as AnimateTimings;
|
timings = value as AnimateTimings;
|
||||||
} else if (typeof value == 'number') {
|
} else if (typeof value == 'number') {
|
||||||
const duration = resolveTiming(value as number, errors).duration;
|
const duration = resolveTiming(value as number, errors).duration;
|
||||||
return makeTimingAst(duration as number, 0, '');
|
return new TimingAst(value as number, 0, '');
|
||||||
}
|
}
|
||||||
|
|
||||||
const strValue = value as string;
|
const strValue = value as string;
|
||||||
const isDynamic = strValue.split(/\s+/).some(v => v.charAt(0) == '{' && v.charAt(1) == '{');
|
const isDynamic = strValue.split(/\s+/).some(v => v.charAt(0) == '{' && v.charAt(1) == '{');
|
||||||
if (isDynamic) {
|
if (isDynamic) {
|
||||||
const ast = makeTimingAst(0, 0, '') as any;
|
return new DynamicTimingAst(strValue);
|
||||||
ast.dynamic = true;
|
|
||||||
ast.strValue = strValue;
|
|
||||||
return ast as DynamicTimingAst;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
timings = timings || resolveTiming(strValue, errors);
|
timings = timings || resolveTiming(strValue, errors);
|
||||||
return makeTimingAst(timings.duration, timings.delay, timings.easing);
|
return new TimingAst(timings.duration, timings.delay, timings.easing);
|
||||||
}
|
}
|
||||||
|
|
||||||
function normalizeAnimationOptions(options: AnimationOptions | null): AnimationOptions {
|
function normalizeAnimationOptions(options: AnimationOptions | null): AnimationOptions {
|
||||||
|
@ -562,7 +525,3 @@ function normalizeAnimationOptions(options: AnimationOptions | null): AnimationO
|
||||||
}
|
}
|
||||||
return options;
|
return options;
|
||||||
}
|
}
|
||||||
|
|
||||||
function makeTimingAst(duration: number, delay: number, easing: string | null): TimingAst {
|
|
||||||
return {duration, delay, easing};
|
|
||||||
}
|
|
||||||
|
|
|
@ -5,20 +5,54 @@
|
||||||
* Use of this source code is governed by an MIT-style license that can be
|
* 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
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
import {AnimationAnimateChildMetadata, AnimationAnimateMetadata, AnimationAnimateRefMetadata, AnimationGroupMetadata, AnimationKeyframesSequenceMetadata, AnimationMetadata, AnimationQueryMetadata, AnimationReferenceMetadata, AnimationSequenceMetadata, AnimationStaggerMetadata, AnimationStateMetadata, AnimationStyleMetadata, AnimationTransitionMetadata, AnimationTriggerMetadata} from '@angular/animations';
|
import {AnimationAnimateChildMetadata, AnimationAnimateMetadata, AnimationAnimateRefMetadata, AnimationGroupMetadata, AnimationKeyframesSequenceMetadata, AnimationMetadata, AnimationMetadataType, AnimationQueryMetadata, AnimationReferenceMetadata, AnimationSequenceMetadata, AnimationStaggerMetadata, AnimationStateMetadata, AnimationStyleMetadata, AnimationTransitionMetadata, AnimationTriggerMetadata} from '@angular/animations';
|
||||||
|
|
||||||
export interface AnimationDslVisitor {
|
export interface AnimationDslVisitor {
|
||||||
visitTrigger(node: AnimationTriggerMetadata, context: any): any;
|
visitTrigger(ast: AnimationTriggerMetadata, context: any): any;
|
||||||
visitState(node: AnimationStateMetadata, context: any): any;
|
visitState(ast: AnimationStateMetadata, context: any): any;
|
||||||
visitTransition(node: AnimationTransitionMetadata, context: any): any;
|
visitTransition(ast: AnimationTransitionMetadata, context: any): any;
|
||||||
visitSequence(node: AnimationSequenceMetadata, context: any): any;
|
visitSequence(ast: AnimationSequenceMetadata, context: any): any;
|
||||||
visitGroup(node: AnimationGroupMetadata, context: any): any;
|
visitGroup(ast: AnimationGroupMetadata, context: any): any;
|
||||||
visitAnimate(node: AnimationAnimateMetadata, context: any): any;
|
visitAnimate(ast: AnimationAnimateMetadata, context: any): any;
|
||||||
visitStyle(node: AnimationStyleMetadata, context: any): any;
|
visitStyle(ast: AnimationStyleMetadata, context: any): any;
|
||||||
visitKeyframes(node: AnimationKeyframesSequenceMetadata, context: any): any;
|
visitKeyframes(ast: AnimationKeyframesSequenceMetadata, context: any): any;
|
||||||
visitReference(node: AnimationReferenceMetadata, context: any): any;
|
visitReference(ast: AnimationReferenceMetadata, context: any): any;
|
||||||
visitAnimateChild(node: AnimationAnimateChildMetadata, context: any): any;
|
visitAnimateChild(ast: AnimationAnimateChildMetadata, context: any): any;
|
||||||
visitAnimateRef(node: AnimationAnimateRefMetadata, context: any): any;
|
visitAnimateRef(ast: AnimationAnimateRefMetadata, context: any): any;
|
||||||
visitQuery(node: AnimationQueryMetadata, context: any): any;
|
visitQuery(ast: AnimationQueryMetadata, context: any): any;
|
||||||
visitStagger(node: AnimationStaggerMetadata, context: any): any;
|
visitStagger(ast: AnimationStaggerMetadata, context: any): any;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function visitAnimationNode(
|
||||||
|
visitor: AnimationDslVisitor, node: AnimationMetadata, context: any) {
|
||||||
|
switch (node.type) {
|
||||||
|
case AnimationMetadataType.Trigger:
|
||||||
|
return visitor.visitTrigger(node as AnimationTriggerMetadata, context);
|
||||||
|
case AnimationMetadataType.State:
|
||||||
|
return visitor.visitState(node as AnimationStateMetadata, context);
|
||||||
|
case AnimationMetadataType.Transition:
|
||||||
|
return visitor.visitTransition(node as AnimationTransitionMetadata, context);
|
||||||
|
case AnimationMetadataType.Sequence:
|
||||||
|
return visitor.visitSequence(node as AnimationSequenceMetadata, context);
|
||||||
|
case AnimationMetadataType.Group:
|
||||||
|
return visitor.visitGroup(node as AnimationGroupMetadata, context);
|
||||||
|
case AnimationMetadataType.Animate:
|
||||||
|
return visitor.visitAnimate(node as AnimationAnimateMetadata, context);
|
||||||
|
case AnimationMetadataType.Keyframes:
|
||||||
|
return visitor.visitKeyframes(node as AnimationKeyframesSequenceMetadata, context);
|
||||||
|
case AnimationMetadataType.Style:
|
||||||
|
return visitor.visitStyle(node as AnimationStyleMetadata, context);
|
||||||
|
case AnimationMetadataType.Reference:
|
||||||
|
return visitor.visitReference(node as AnimationReferenceMetadata, context);
|
||||||
|
case AnimationMetadataType.AnimateChild:
|
||||||
|
return visitor.visitAnimateChild(node as AnimationAnimateChildMetadata, context);
|
||||||
|
case AnimationMetadataType.AnimateRef:
|
||||||
|
return visitor.visitAnimateRef(node as AnimationAnimateRefMetadata, context);
|
||||||
|
case AnimationMetadataType.Query:
|
||||||
|
return visitor.visitQuery(node as AnimationQueryMetadata, context);
|
||||||
|
case AnimationMetadataType.Stagger:
|
||||||
|
return visitor.visitStagger(node as AnimationStaggerMetadata, context);
|
||||||
|
default:
|
||||||
|
throw new Error(`Unable to resolve animation metadata node #${node.type}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,10 +5,10 @@
|
||||||
* Use of this source code is governed by an MIT-style license that can be
|
* 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
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
import {AUTO_STYLE, AnimateChildOptions, AnimateTimings, AnimationMetadataType, AnimationOptions, AnimationQueryOptions, ɵPRE_STYLE as PRE_STYLE, ɵStyleData} from '@angular/animations';
|
import {AUTO_STYLE, AnimateChildOptions, AnimateTimings, AnimationOptions, AnimationQueryOptions, ɵPRE_STYLE as PRE_STYLE, ɵStyleData} from '@angular/animations';
|
||||||
|
|
||||||
import {AnimationDriver} from '../render/animation_driver';
|
import {AnimationDriver} from '../render/animation_driver';
|
||||||
import {copyObj, copyStyles, interpolateParams, iteratorToArray, resolveTiming, resolveTimingValue, visitDslNode} from '../util';
|
import {copyObj, copyStyles, interpolateParams, iteratorToArray, resolveTiming, resolveTimingValue} from '../util';
|
||||||
|
|
||||||
import {AnimateAst, AnimateChildAst, AnimateRefAst, Ast, AstVisitor, DynamicTimingAst, GroupAst, KeyframesAst, QueryAst, ReferenceAst, SequenceAst, StaggerAst, StateAst, StyleAst, TimingAst, TransitionAst, TriggerAst} from './animation_ast';
|
import {AnimateAst, AnimateChildAst, AnimateRefAst, Ast, AstVisitor, DynamicTimingAst, GroupAst, KeyframesAst, QueryAst, ReferenceAst, SequenceAst, StaggerAst, StateAst, StyleAst, TimingAst, TransitionAst, TriggerAst} from './animation_ast';
|
||||||
import {AnimationTimelineInstruction, createTimelineInstruction} from './animation_timeline_instruction';
|
import {AnimationTimelineInstruction, createTimelineInstruction} from './animation_timeline_instruction';
|
||||||
|
@ -101,8 +101,8 @@ const ONE_FRAME_IN_MILLISECONDS = 1;
|
||||||
* the `AnimationValidatorVisitor` code.
|
* the `AnimationValidatorVisitor` code.
|
||||||
*/
|
*/
|
||||||
export function buildAnimationTimelines(
|
export function buildAnimationTimelines(
|
||||||
driver: AnimationDriver, rootElement: any, ast: Ast<AnimationMetadataType>,
|
driver: AnimationDriver, rootElement: any, ast: Ast, startingStyles: ɵStyleData = {},
|
||||||
startingStyles: ɵStyleData = {}, finalStyles: ɵStyleData = {}, options: AnimationOptions,
|
finalStyles: ɵStyleData = {}, options: AnimationOptions,
|
||||||
subInstructions?: ElementInstructionMap, errors: any[] = []): AnimationTimelineInstruction[] {
|
subInstructions?: ElementInstructionMap, errors: any[] = []): AnimationTimelineInstruction[] {
|
||||||
return new AnimationTimelineBuilderVisitor().buildKeyframes(
|
return new AnimationTimelineBuilderVisitor().buildKeyframes(
|
||||||
driver, rootElement, ast, startingStyles, finalStyles, options, subInstructions, errors);
|
driver, rootElement, ast, startingStyles, finalStyles, options, subInstructions, errors);
|
||||||
|
@ -110,15 +110,15 @@ export function buildAnimationTimelines(
|
||||||
|
|
||||||
export class AnimationTimelineBuilderVisitor implements AstVisitor {
|
export class AnimationTimelineBuilderVisitor implements AstVisitor {
|
||||||
buildKeyframes(
|
buildKeyframes(
|
||||||
driver: AnimationDriver, rootElement: any, ast: Ast<AnimationMetadataType>,
|
driver: AnimationDriver, rootElement: any, ast: Ast, startingStyles: ɵStyleData,
|
||||||
startingStyles: ɵStyleData, finalStyles: ɵStyleData, options: AnimationOptions,
|
finalStyles: ɵStyleData, options: AnimationOptions, subInstructions?: ElementInstructionMap,
|
||||||
subInstructions?: ElementInstructionMap, errors: any[] = []): AnimationTimelineInstruction[] {
|
errors: any[] = []): AnimationTimelineInstruction[] {
|
||||||
subInstructions = subInstructions || new ElementInstructionMap();
|
subInstructions = subInstructions || new ElementInstructionMap();
|
||||||
const context = new AnimationTimelineContext(driver, rootElement, subInstructions, errors, []);
|
const context = new AnimationTimelineContext(driver, rootElement, subInstructions, errors, []);
|
||||||
context.options = options;
|
context.options = options;
|
||||||
context.currentTimeline.setStyles([startingStyles], null, context.errors, options);
|
context.currentTimeline.setStyles([startingStyles], null, context.errors, options);
|
||||||
|
|
||||||
visitDslNode(this, ast, context);
|
ast.visit(this, context);
|
||||||
|
|
||||||
// this checks to see if an actual animation happened
|
// this checks to see if an actual animation happened
|
||||||
const timelines = context.timelines.filter(timeline => timeline.containsAnimation());
|
const timelines = context.timelines.filter(timeline => timeline.containsAnimation());
|
||||||
|
@ -193,7 +193,7 @@ export class AnimationTimelineBuilderVisitor implements AstVisitor {
|
||||||
|
|
||||||
visitReference(ast: ReferenceAst, context: AnimationTimelineContext) {
|
visitReference(ast: ReferenceAst, context: AnimationTimelineContext) {
|
||||||
context.updateOptions(ast.options, true);
|
context.updateOptions(ast.options, true);
|
||||||
visitDslNode(this, ast.animation, context);
|
ast.animation.visit(this, context);
|
||||||
context.previousNode = ast;
|
context.previousNode = ast;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -207,7 +207,7 @@ export class AnimationTimelineBuilderVisitor implements AstVisitor {
|
||||||
ctx.transformIntoNewTimeline();
|
ctx.transformIntoNewTimeline();
|
||||||
|
|
||||||
if (options.delay != null) {
|
if (options.delay != null) {
|
||||||
if (ctx.previousNode.type == AnimationMetadataType.Style) {
|
if (ctx.previousNode instanceof StyleAst) {
|
||||||
ctx.currentTimeline.snapshotCurrentStyles();
|
ctx.currentTimeline.snapshotCurrentStyles();
|
||||||
ctx.previousNode = DEFAULT_NOOP_PREVIOUS_NODE;
|
ctx.previousNode = DEFAULT_NOOP_PREVIOUS_NODE;
|
||||||
}
|
}
|
||||||
|
@ -218,7 +218,7 @@ export class AnimationTimelineBuilderVisitor implements AstVisitor {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ast.steps.length) {
|
if (ast.steps.length) {
|
||||||
ast.steps.forEach(s => visitDslNode(this, s, ctx));
|
ast.steps.forEach(s => s.visit(this, ctx));
|
||||||
|
|
||||||
// this is here just incase the inner steps only contain or end with a style() call
|
// this is here just incase the inner steps only contain or end with a style() call
|
||||||
ctx.currentTimeline.applyStylesToKeyframe();
|
ctx.currentTimeline.applyStylesToKeyframe();
|
||||||
|
@ -245,7 +245,7 @@ export class AnimationTimelineBuilderVisitor implements AstVisitor {
|
||||||
innerContext.delayNextStep(delay);
|
innerContext.delayNextStep(delay);
|
||||||
}
|
}
|
||||||
|
|
||||||
visitDslNode(this, s, innerContext);
|
s.visit(this, innerContext);
|
||||||
furthestTime = Math.max(furthestTime, innerContext.currentTimeline.currentTime);
|
furthestTime = Math.max(furthestTime, innerContext.currentTimeline.currentTime);
|
||||||
innerTimelines.push(innerContext.currentTimeline);
|
innerTimelines.push(innerContext.currentTimeline);
|
||||||
});
|
});
|
||||||
|
@ -259,19 +259,19 @@ export class AnimationTimelineBuilderVisitor implements AstVisitor {
|
||||||
context.previousNode = ast;
|
context.previousNode = ast;
|
||||||
}
|
}
|
||||||
|
|
||||||
private _visitTiming(ast: TimingAst, context: AnimationTimelineContext): AnimateTimings {
|
visitTiming(ast: TimingAst, context: AnimationTimelineContext): AnimateTimings {
|
||||||
if ((ast as DynamicTimingAst).dynamic) {
|
if (ast instanceof DynamicTimingAst) {
|
||||||
const strValue = (ast as DynamicTimingAst).strValue;
|
const strValue = context.params ?
|
||||||
const timingValue =
|
interpolateParams(ast.value, context.params, context.errors) :
|
||||||
context.params ? interpolateParams(strValue, context.params, context.errors) : strValue;
|
ast.value.toString();
|
||||||
return resolveTiming(timingValue, context.errors);
|
return resolveTiming(strValue, context.errors);
|
||||||
} else {
|
} else {
|
||||||
return {duration: ast.duration, delay: ast.delay, easing: ast.easing};
|
return {duration: ast.duration, delay: ast.delay, easing: ast.easing};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
visitAnimate(ast: AnimateAst, context: AnimationTimelineContext) {
|
visitAnimate(ast: AnimateAst, context: AnimationTimelineContext) {
|
||||||
const timings = context.currentAnimateTimings = this._visitTiming(ast.timings, context);
|
const timings = context.currentAnimateTimings = this.visitTiming(ast.timings, context);
|
||||||
const timeline = context.currentTimeline;
|
const timeline = context.currentTimeline;
|
||||||
if (timings.delay) {
|
if (timings.delay) {
|
||||||
context.incrementTime(timings.delay);
|
context.incrementTime(timings.delay);
|
||||||
|
@ -279,7 +279,7 @@ export class AnimationTimelineBuilderVisitor implements AstVisitor {
|
||||||
}
|
}
|
||||||
|
|
||||||
const style = ast.style;
|
const style = ast.style;
|
||||||
if (style.type == AnimationMetadataType.Keyframes) {
|
if (style instanceof KeyframesAst) {
|
||||||
this.visitKeyframes(style, context);
|
this.visitKeyframes(style, context);
|
||||||
} else {
|
} else {
|
||||||
context.incrementTime(timings.duration);
|
context.incrementTime(timings.duration);
|
||||||
|
@ -343,7 +343,7 @@ export class AnimationTimelineBuilderVisitor implements AstVisitor {
|
||||||
const options = (ast.options || {}) as AnimationQueryOptions;
|
const options = (ast.options || {}) as AnimationQueryOptions;
|
||||||
const delay = options.delay ? resolveTimingValue(options.delay) : 0;
|
const delay = options.delay ? resolveTimingValue(options.delay) : 0;
|
||||||
|
|
||||||
if (delay && (context.previousNode.type === AnimationMetadataType.Style ||
|
if (delay && (context.previousNode instanceof StyleAst ||
|
||||||
(startTime == 0 && context.currentTimeline.getCurrentStyleProperties().length))) {
|
(startTime == 0 && context.currentTimeline.getCurrentStyleProperties().length))) {
|
||||||
context.currentTimeline.snapshotCurrentStyles();
|
context.currentTimeline.snapshotCurrentStyles();
|
||||||
context.previousNode = DEFAULT_NOOP_PREVIOUS_NODE;
|
context.previousNode = DEFAULT_NOOP_PREVIOUS_NODE;
|
||||||
|
@ -368,7 +368,7 @@ export class AnimationTimelineBuilderVisitor implements AstVisitor {
|
||||||
sameElementTimeline = innerContext.currentTimeline;
|
sameElementTimeline = innerContext.currentTimeline;
|
||||||
}
|
}
|
||||||
|
|
||||||
visitDslNode(this, ast.animation, innerContext);
|
ast.animation.visit(this, innerContext);
|
||||||
|
|
||||||
// this is here just incase the inner steps only contain or end
|
// 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
|
// with a style() call (which is here to signal that this is a preparatory
|
||||||
|
@ -415,7 +415,7 @@ export class AnimationTimelineBuilderVisitor implements AstVisitor {
|
||||||
}
|
}
|
||||||
|
|
||||||
const startingTime = timeline.currentTime;
|
const startingTime = timeline.currentTime;
|
||||||
visitDslNode(this, ast.animation, context);
|
ast.animation.visit(this, context);
|
||||||
context.previousNode = ast;
|
context.previousNode = ast;
|
||||||
|
|
||||||
// time = duration + delay
|
// time = duration + delay
|
||||||
|
@ -431,12 +431,12 @@ export declare type StyleAtTime = {
|
||||||
time: number; value: string | number;
|
time: number; value: string | number;
|
||||||
};
|
};
|
||||||
|
|
||||||
const DEFAULT_NOOP_PREVIOUS_NODE = <Ast<AnimationMetadataType>>{};
|
const DEFAULT_NOOP_PREVIOUS_NODE = <Ast>{};
|
||||||
export class AnimationTimelineContext {
|
export class AnimationTimelineContext {
|
||||||
public parentContext: AnimationTimelineContext|null = null;
|
public parentContext: AnimationTimelineContext|null = null;
|
||||||
public currentTimeline: TimelineBuilder;
|
public currentTimeline: TimelineBuilder;
|
||||||
public currentAnimateTimings: AnimateTimings|null = null;
|
public currentAnimateTimings: AnimateTimings|null = null;
|
||||||
public previousNode: Ast<AnimationMetadataType> = DEFAULT_NOOP_PREVIOUS_NODE;
|
public previousNode: Ast = DEFAULT_NOOP_PREVIOUS_NODE;
|
||||||
public subContextCount = 0;
|
public subContextCount = 0;
|
||||||
public options: AnimationOptions = {};
|
public options: AnimationOptions = {};
|
||||||
public currentQueryIndex: number = 0;
|
public currentQueryIndex: number = 0;
|
||||||
|
@ -489,7 +489,7 @@ export class AnimationTimelineContext {
|
||||||
const oldParams = this.options.params;
|
const oldParams = this.options.params;
|
||||||
if (oldParams) {
|
if (oldParams) {
|
||||||
const params: {[name: string]: any} = options['params'] = {};
|
const params: {[name: string]: any} = options['params'] = {};
|
||||||
Object.keys(oldParams).forEach(name => { params[name] = oldParams[name]; });
|
Object.keys(this.options.params).forEach(name => { params[name] = oldParams[name]; });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return options;
|
return options;
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
* Use of this source code is governed by an MIT-style license that can be
|
* 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
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
import {AnimationMetadataType, ɵStyleData} from '@angular/animations';
|
import {ɵStyleData} from '@angular/animations';
|
||||||
|
|
||||||
import {copyStyles, interpolateParams} from '../util';
|
import {copyStyles, interpolateParams} from '../util';
|
||||||
|
|
||||||
|
@ -13,7 +13,6 @@ import {SequenceAst, StyleAst, TransitionAst, TriggerAst} from './animation_ast'
|
||||||
import {AnimationStateStyles, AnimationTransitionFactory} from './animation_transition_factory';
|
import {AnimationStateStyles, AnimationTransitionFactory} from './animation_transition_factory';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @experimental Animation support is experimental.
|
* @experimental Animation support is experimental.
|
||||||
*/
|
*/
|
||||||
|
@ -61,15 +60,8 @@ function createFallbackTransition(
|
||||||
triggerName: string,
|
triggerName: string,
|
||||||
states: {[stateName: string]: AnimationStateStyles}): AnimationTransitionFactory {
|
states: {[stateName: string]: AnimationStateStyles}): AnimationTransitionFactory {
|
||||||
const matchers = [(fromState: any, toState: any) => true];
|
const matchers = [(fromState: any, toState: any) => true];
|
||||||
const animation: SequenceAst = {type: AnimationMetadataType.Sequence, steps: [], options: null};
|
const animation = new SequenceAst([]);
|
||||||
const transition: TransitionAst = {
|
const transition = new TransitionAst(matchers, animation);
|
||||||
type: AnimationMetadataType.Transition,
|
|
||||||
animation,
|
|
||||||
matchers,
|
|
||||||
options: null,
|
|
||||||
queryCount: 0,
|
|
||||||
depCount: 0
|
|
||||||
};
|
|
||||||
return new AnimationTransitionFactory(triggerName, transition, states);
|
return new AnimationTransitionFactory(triggerName, transition, states);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
* Use of this source code is governed by an MIT-style license that can be
|
* 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
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
import {AUTO_STYLE, AnimationMetadata, AnimationMetadataType, AnimationOptions, AnimationPlayer, ɵStyleData} from '@angular/animations';
|
import {AUTO_STYLE, AnimationMetadata, AnimationOptions, AnimationPlayer, ɵStyleData} from '@angular/animations';
|
||||||
|
|
||||||
import {Ast} from '../dsl/animation_ast';
|
import {Ast} from '../dsl/animation_ast';
|
||||||
import {buildAnimationAst} from '../dsl/animation_ast_builder';
|
import {buildAnimationAst} from '../dsl/animation_ast_builder';
|
||||||
|
@ -20,7 +20,7 @@ import {getOrSetAsInMap, listenOnPlayer, makeAnimationEvent, normalizeKeyframes,
|
||||||
const EMPTY_INSTRUCTION_MAP = new ElementInstructionMap();
|
const EMPTY_INSTRUCTION_MAP = new ElementInstructionMap();
|
||||||
|
|
||||||
export class TimelineAnimationEngine {
|
export class TimelineAnimationEngine {
|
||||||
private _animations: {[id: string]: Ast<AnimationMetadataType>} = {};
|
private _animations: {[id: string]: Ast} = {};
|
||||||
private _playersById: {[id: string]: AnimationPlayer} = {};
|
private _playersById: {[id: string]: AnimationPlayer} = {};
|
||||||
public players: AnimationPlayer[] = [];
|
public players: AnimationPlayer[] = [];
|
||||||
|
|
||||||
|
|
|
@ -5,9 +5,7 @@
|
||||||
* Use of this source code is governed by an MIT-style license that can be
|
* 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
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
import {AnimateTimings, AnimationMetadata, AnimationMetadataType, AnimationOptions, sequence, ɵStyleData} from '@angular/animations';
|
import {AnimateTimings, AnimationMetadata, AnimationOptions, sequence, ɵStyleData} from '@angular/animations';
|
||||||
import {Ast as AnimationAst, AstVisitor as AnimationAstVisitor} from './dsl/animation_ast';
|
|
||||||
import {AnimationDslVisitor} from './dsl/animation_dsl_visitor';
|
|
||||||
|
|
||||||
export const ONE_SECOND = 1000;
|
export const ONE_SECOND = 1000;
|
||||||
|
|
||||||
|
@ -234,40 +232,3 @@ export function dashCaseToCamelCase(input: string): string {
|
||||||
export function allowPreviousPlayerStylesMerge(duration: number, delay: number) {
|
export function allowPreviousPlayerStylesMerge(duration: number, delay: number) {
|
||||||
return duration === 0 || delay === 0;
|
return duration === 0 || delay === 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function visitDslNode(
|
|
||||||
visitor: AnimationDslVisitor, node: AnimationMetadata, context: any): any;
|
|
||||||
export function visitDslNode(
|
|
||||||
visitor: AnimationAstVisitor, node: AnimationAst<AnimationMetadataType>, context: any): any;
|
|
||||||
export function visitDslNode(visitor: any, node: any, context: any): any {
|
|
||||||
switch (node.type) {
|
|
||||||
case AnimationMetadataType.Trigger:
|
|
||||||
return visitor.visitTrigger(node, context);
|
|
||||||
case AnimationMetadataType.State:
|
|
||||||
return visitor.visitState(node, context);
|
|
||||||
case AnimationMetadataType.Transition:
|
|
||||||
return visitor.visitTransition(node, context);
|
|
||||||
case AnimationMetadataType.Sequence:
|
|
||||||
return visitor.visitSequence(node, context);
|
|
||||||
case AnimationMetadataType.Group:
|
|
||||||
return visitor.visitGroup(node, context);
|
|
||||||
case AnimationMetadataType.Animate:
|
|
||||||
return visitor.visitAnimate(node, context);
|
|
||||||
case AnimationMetadataType.Keyframes:
|
|
||||||
return visitor.visitKeyframes(node, context);
|
|
||||||
case AnimationMetadataType.Style:
|
|
||||||
return visitor.visitStyle(node, context);
|
|
||||||
case AnimationMetadataType.Reference:
|
|
||||||
return visitor.visitReference(node, context);
|
|
||||||
case AnimationMetadataType.AnimateChild:
|
|
||||||
return visitor.visitAnimateChild(node, context);
|
|
||||||
case AnimationMetadataType.AnimateRef:
|
|
||||||
return visitor.visitAnimateRef(node, context);
|
|
||||||
case AnimationMetadataType.Query:
|
|
||||||
return visitor.visitQuery(node, context);
|
|
||||||
case AnimationMetadataType.Stagger:
|
|
||||||
return visitor.visitStagger(node, context);
|
|
||||||
default:
|
|
||||||
throw new Error(`Unable to resolve animation metadata node #${node.type}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue