Repository URL to install this package:
|
Version:
1.2.19 ▾
|
@skava/modules
/
___dist
/
view-container
/
styles
/
styled-components
/
src
/
constructors
/
keyframes.js
|
|---|
// @flow
import { fliphash as hashStr } from 'chain-able-boost'
import { Interpolation, NameGenerator, Stringifier } from '../types'
import StyleSheet from '../models/StyleSheet'
// @todo - dedupe
const replaceWhitespace = (str: string): string => str.replace(/\s|\\n/g, '')
type KeyframesFn = (
strings: Array<string>,
...interpolations: Array<Interpolation>
) => string
export default (
nameGenerator: NameGenerator,
stringifyRules: Stringifier,
css: Function
): KeyframesFn => (...arr): string => {
const styleSheet = StyleSheet.master
const rules = css(...arr)
const name = nameGenerator(hashStr(replaceWhitespace(JSON.stringify(rules))))
const id = `sc-keyframes-${name}`
if (!styleSheet.hasNameForId(id, name)) {
styleSheet.inject(id, stringifyRules(rules, name, '@keyframes'), name)
}
return name
}