css: prevent error with non-string css (#253)

This commit is contained in:
jean-emmanuel 2018-03-20 00:10:59 +01:00
parent 1a409a4efe
commit e339c1aa49
2 changed files with 10 additions and 12 deletions

View file

@ -3,7 +3,8 @@
## 0.27.1
- bug fixes
- prevent error when resizing a widget and its clone(s) at the same time
- error when resizing a widget and its clone(s) at the same time
- error with non string css property
## 0.27.0

View file

@ -18,10 +18,10 @@ var OSCProps = [
'bypass'
]
var fallbackContainer
var dummyDOM
DOM.ready(()=>{
fallbackContainer = DOM.create('<div></div>')
dummyDOM = DOM.create('<div></div>')
})
setTimeout(()=>{
@ -151,7 +151,7 @@ class Widget extends EventEmitter {
this.container._widget_instance = this
this.setContainerStyles()
} else {
this.container = fallbackContainer
this.container = dummyDOM
}
}
@ -559,16 +559,13 @@ class Widget extends EventEmitter {
if (styles.includes('css')) {
// css
var prefix = '#' + this.hash,
scopedCss = scopeCss(this.getProp('css'), prefix),
var css = String(this.getProp('css')),
prefix = '#' + this.hash,
scopedCss = scopeCss(css, prefix),
unScopedCss = ''
this.getProp('css')
.replace(/\{[^\}]*\}/g, '')
.replace(/^@media.*/gm,'')
.replace(/^.*\:.*/gm, (m) => {
unScopedCss += m[m.length - 1] === ';' ? m : m + ';'
})
dummyDOM.style = css
unScopedCss = dummyDOM.getAttribute('style') || ''
if (scopedCss.indexOf('@keyframes') > -1) scopedCss = scopedCss.replace(new RegExp(prefix + '\\s+([0-9]+%|to|from)', 'g'), ' $1')
if (scopedCss.indexOf('&') > -1) scopedCss = scopedCss.replace(new RegExp(prefix + '\\s&', 'g'), prefix)