Skip to content

Commit

Permalink
Merge pull request #29 from Automattic/update/remove-keyframes
Browse files Browse the repository at this point in the history
Remove @Keyframe definitions from output
  • Loading branch information
thingalon authored Mar 6, 2022
2 parents a4721f4 + d0d2530 commit 945e1c4
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions lib/style-ast.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const stringPattern = /^(["']).*\1$/;
const maxBase64Length = 1000;
const excludedSelectors = [ /::?(?:-moz-)?selection/ ];
const excludedProperties = [
/(.*)animation/,
/(.*)transition(.*)/,
/cursor/,
/pointer-events/,
Expand Down Expand Up @@ -70,6 +71,7 @@ class StyleAST {
);

clone.pruneMediaQueries();
clone.pruneKeyframes();
clone.pruneNonCriticalSelectors( criticalSelectors );
clone.pruneExcludedProperties();
clone.pruneLargeBase64Embeds();
Expand Down Expand Up @@ -265,6 +267,21 @@ class StyleAST {
} );
}

/**
* Remove keyframe definitions.
*/
pruneKeyframes() {
csstree.walk( this.ast, {
visit: 'Atrule',
enter: ( atrule, atitem, atlist ) => {
// Ignore non-keyframes.
if ( csstree.keyword( atrule.name ).basename === 'keyframes' ) {
atlist.remove( atitem );
}
},
} );
}

/**
* Returns true if the given CSS rule object relates to animation keyframes.
*
Expand Down

0 comments on commit 945e1c4

Please sign in to comment.