Skip to content

Commit

Permalink
refactor: migrate animations to prettier formatting (#53977)
Browse files Browse the repository at this point in the history
Migrate formatting to prettier for animations from clang-format

PR Close #53977
  • Loading branch information
josephperrott authored and pkozlowski-opensource committed Jan 19, 2024
1 parent 711cb41 commit bbbe477
Show file tree
Hide file tree
Showing 52 changed files with 4,059 additions and 2,600 deletions.
2 changes: 2 additions & 0 deletions .ng-dev/format.mts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export const format: FormatConfig = {
'tools/**/*.{js,ts}',
'modules/**/*.{js,ts}',
'scripts/**/*.{js,ts}',
'packages/animations/**/*.{js,ts}',
],
},
'clang-format': {
Expand Down Expand Up @@ -43,6 +44,7 @@ export const format: FormatConfig = {
'!tools/**/*.{js,ts}',
'!modules/**/*.{js,ts}',
'!scripts/**/*.{js,ts}',
'!packages/animations/**/*.{js,ts}',
],
},
'buildifier': true,
Expand Down
18 changes: 14 additions & 4 deletions packages/animations/browser/src/create_engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,24 @@ import {AnimationEngine} from './render/animation_engine_next';
import {WebAnimationsDriver} from './render/web_animations/web_animations_driver';

export function createEngine(
type: 'animations'|'noop', doc: Document,
scheduler: ChangeDetectionScheduler|null): AnimationEngine {
type: 'animations' | 'noop',
doc: Document,
scheduler: ChangeDetectionScheduler | null,
): AnimationEngine {
// TODO: find a way to make this tree shakable.
if (type === 'noop') {
return new AnimationEngine(
doc, new NoopAnimationDriver(), new NoopAnimationStyleNormalizer(), scheduler);
doc,
new NoopAnimationDriver(),
new NoopAnimationStyleNormalizer(),
scheduler,
);
}

return new AnimationEngine(
doc, new WebAnimationsDriver(), new WebAnimationsStyleNormalizer(), scheduler);
doc,
new WebAnimationsDriver(),
new WebAnimationsStyleNormalizer(),
scheduler,
);
}
44 changes: 33 additions & 11 deletions packages/animations/browser/src/dsl/animation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
* 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
*/
import {AnimationMetadata, AnimationMetadataType, AnimationOptions, ɵStyleDataMap} from '@angular/animations';
import {
AnimationMetadata,
AnimationMetadataType,
AnimationOptions,
ɵStyleDataMap,
} from '@angular/animations';

import {buildingFailed, validationFailed} from '../error_helpers';
import {AnimationDriver} from '../render/animation_driver';
Expand All @@ -20,7 +25,10 @@ import {ElementInstructionMap} from './element_instruction_map';

export class Animation {
private _animationAst: Ast<AnimationMetadataType>;
constructor(private _driver: AnimationDriver, input: AnimationMetadata|AnimationMetadata[]) {
constructor(
private _driver: AnimationDriver,
input: AnimationMetadata | AnimationMetadata[],
) {
const errors: Error[] = [];
const warnings: string[] = [];
const ast = buildAnimationAst(_driver, input, errors, warnings);
Expand All @@ -34,18 +42,32 @@ export class Animation {
}

buildTimelines(
element: any, startingStyles: ɵStyleDataMap|Array<ɵStyleDataMap>,
destinationStyles: ɵStyleDataMap|Array<ɵStyleDataMap>, options: AnimationOptions,
subInstructions?: ElementInstructionMap): AnimationTimelineInstruction[] {
const start = Array.isArray(startingStyles) ? normalizeStyles(startingStyles) :
<ɵStyleDataMap>startingStyles;
const dest = Array.isArray(destinationStyles) ? normalizeStyles(destinationStyles) :
<ɵStyleDataMap>destinationStyles;
element: any,
startingStyles: ɵStyleDataMap | Array<ɵStyleDataMap>,
destinationStyles: ɵStyleDataMap | Array<ɵStyleDataMap>,
options: AnimationOptions,
subInstructions?: ElementInstructionMap,
): AnimationTimelineInstruction[] {
const start = Array.isArray(startingStyles)
? normalizeStyles(startingStyles)
: <ɵStyleDataMap>startingStyles;
const dest = Array.isArray(destinationStyles)
? normalizeStyles(destinationStyles)
: <ɵStyleDataMap>destinationStyles;
const errors: any = [];
subInstructions = subInstructions || new ElementInstructionMap();
const result = buildAnimationTimelines(
this._driver, element, this._animationAst, ENTER_CLASSNAME, LEAVE_CLASSNAME, start, dest,
options, subInstructions, errors);
this._driver,
element,
this._animationAst,
ENTER_CLASSNAME,
LEAVE_CLASSNAME,
start,
dest,
options,
subInstructions,
errors,
);
if (errors.length) {
throw buildingFailed(errors);
}
Expand Down
24 changes: 15 additions & 9 deletions packages/animations/browser/src/dsl/animation_ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
* 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
*/
import {AnimateTimings, AnimationMetadataType, AnimationOptions, ɵStyleDataMap} from '@angular/animations';
import {
AnimateTimings,
AnimationMetadataType,
AnimationOptions,
ɵStyleDataMap,
} from '@angular/animations';

const EMPTY_ANIMATION_OPTIONS: AnimationOptions = {};

Expand All @@ -27,7 +32,7 @@ export interface AstVisitor {

export interface Ast<T extends AnimationMetadataType> {
type: T;
options: AnimationOptions|null;
options: AnimationOptions | null;
}

export interface TriggerAst extends Ast<AnimationMetadataType.Trigger> {
Expand All @@ -46,8 +51,9 @@ export interface StateAst extends Ast<AnimationMetadataType.State> {
}

export interface TransitionAst extends Ast<AnimationMetadataType.Transition> {
matchers: Array<(
(fromState: string, toState: string, element: any, params: {[key: string]: any}) => boolean)>;
matchers: Array<
(fromState: string, toState: string, element: any, params: {[key: string]: any}) => boolean
>;
animation: Ast<AnimationMetadataType>;
queryCount: number;
depCount: number;
Expand All @@ -63,13 +69,13 @@ export interface GroupAst extends Ast<AnimationMetadataType.Group> {

export interface AnimateAst extends Ast<AnimationMetadataType.Animate> {
timings: TimingAst;
style: StyleAst|KeyframesAst;
style: StyleAst | KeyframesAst;
}

export interface StyleAst extends Ast<AnimationMetadataType.Style> {
styles: Array<(ɵStyleDataMap | string)>;
easing: string|null;
offset: number|null;
styles: Array<ɵStyleDataMap | string>;
easing: string | null;
offset: number | null;
containsDynamicStyles: boolean;
isEmptyStep?: boolean;
}
Expand Down Expand Up @@ -105,7 +111,7 @@ export interface StaggerAst extends Ast<AnimationMetadataType.Stagger> {
export interface TimingAst {
duration: number;
delay: number;
easing: string|null;
easing: string | null;
dynamic?: boolean;
}

Expand Down
Loading

0 comments on commit bbbe477

Please sign in to comment.