This repository was archived by the owner on Aug 25, 2020. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -231,15 +231,25 @@ TBD
231231
232232TBD
233233
234- ### Raw Styles
235-
236- Add styles to the global scope by defining selector :
234+ ### @keyframes
237235
238236` ` ` typescript
239- constructor(private stylerService: StylerService) {
240- this.stylerService.setRaw('body', {
241- background: '#222222',
242- color: '#eeeeee',
237+ constructor(private styler: StylerComponent,
238+ private stylerService: StylerService) {
239+ this.styler.register({
240+ host: {
241+ animationDuration: '1s',
242+ animationName: this.stylerService.keyframes({
243+ '0%': {
244+ transform: 'rotate(0deg)',
245+ },
246+ '100%': {
247+ transform: 'rotate(360deg)',
248+ },
249+ }),
250+ animationTimingFunction: 'linear',
251+ animationIterationCount: 'infinite',
252+ },
243253 });
244254}
245255` ` `
Original file line number Diff line number Diff line change 1+ import { DOCUMENT } from '@angular/common' ;
12import { Inject , Injectable } from '@angular/core' ;
2- import { DOCUMENT , ɵSharedStylesHost as SharedStylesHost } from '@angular/platform-browser' ;
3+ import { ɵSharedStylesHost as SharedStylesHost } from '@angular/platform-browser' ;
34import { processAutoPx } from '../helpers/process-auto-px' ;
45import { autoPx } from '../meta/compiler' ;
56import { StylerHashService } from '../meta/hash' ;
@@ -184,4 +185,15 @@ export class StylerCompilerService {
184185 // update hash in unit
185186 unit . hash . next ( newHash ) ;
186187 }
188+
189+ addKeyframes ( def : any ) : string {
190+ let css = '' ;
191+ for ( const key in def ) {
192+ css += `${ key } {${ this . compileProps ( def [ key ] ) } }`
193+ }
194+ const selector = `kf-${ this . hash . hash ( css ) } ` ;
195+ // @todo impr performace by hash-caching
196+ this . sharedStylesHost . addStyles ( [ `@keyframes ${ selector } {${ css } }` ] ) ;
197+ return selector ;
198+ }
187199}
Original file line number Diff line number Diff line change @@ -24,4 +24,8 @@ export class StylerService {
2424 } ) ;
2525 this . compiler . render ( ) ;
2626 }
27+
28+ keyframes ( def : any ) : string {
29+ return this . compiler . addKeyframes ( def ) ;
30+ }
2731}
You can’t perform that action at this time.
0 commit comments