Skip to content

Commit 456cdfc

Browse files
author
rofrischmann
committed
added array prefixing to Prefixer.prefix
1 parent aa1eaa4 commit 456cdfc

13 files changed

Lines changed: 93 additions & 56 deletions

File tree

modules/Prefixer.js

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import prefixAll from './static/prefixAll'
22
import getBrowserInformation from './utils/getBrowserInformation'
33
import getPrefixedKeyframes from './utils/getPrefixedKeyframes'
44
import capitalizeString from './utils/capitalizeString'
5-
import assign from './utils/assign'
65
import prefixProps from './prefixProps'
76

87
import calc from './plugins/calc'
@@ -82,11 +81,9 @@ export default class Prefixer {
8281
return styles
8382
}
8483

85-
styles = assign({ }, styles)
86-
8784
Object.keys(styles).forEach(property => {
8885
let value = styles[property]
89-
if (value instanceof Object) {
86+
if (value instanceof Object && !Array.isArray(value)) {
9087
// recurse through nested style objects
9188
styles[property] = this.prefix(value)
9289
} else {
@@ -101,24 +98,24 @@ export default class Prefixer {
10198
})
10299

103100
Object.keys(styles).forEach(property => {
104-
const value = styles[property]
105-
// resolve plugins
106-
plugins.forEach(plugin => {
107-
// generates a new plugin interface with current data
108-
const resolvedStyles = plugin({
109-
property: property,
110-
value: value,
111-
styles: styles,
112-
browserInfo: this._browserInfo,
113-
prefix: {
114-
js: this.jsPrefix,
115-
css: this.cssPrefix,
116-
keyframes: this.prefixedKeyframes
117-
},
118-
keepUnprefixed: this._keepUnprefixed,
119-
requiresPrefix: this._requiresPrefix
101+
[ ].concat(styles[property]).forEach(value => {
102+
// resolve plugins
103+
plugins.forEach(plugin => {
104+
// generates a new plugin interface with current data
105+
assignStyles(styles, plugin({
106+
property: property,
107+
value: value,
108+
styles: styles,
109+
browserInfo: this._browserInfo,
110+
prefix: {
111+
js: this.jsPrefix,
112+
css: this.cssPrefix,
113+
keyframes: this.prefixedKeyframes
114+
},
115+
keepUnprefixed: this._keepUnprefixed,
116+
requiresPrefix: this._requiresPrefix
117+
}), value, this._keepUnprefixed)
120118
})
121-
assign(styles, resolvedStyles)
122119
})
123120
})
124121

@@ -134,3 +131,18 @@ export default class Prefixer {
134131
return prefixAll(styles)
135132
}
136133
}
134+
135+
function assignStyles(base, extend = { }, value, keepUnprefixed) {
136+
Object.keys(extend).forEach(property => {
137+
const baseValue = base[property]
138+
if (Array.isArray(baseValue)) {
139+
[ ].concat(extend[property]).forEach(val => {
140+
if (base[property].indexOf(val) === -1) {
141+
base[property].splice(baseValue.indexOf(value), keepUnprefixed ? 0 : 1, val)
142+
}
143+
})
144+
} else {
145+
base[property] = extend[property]
146+
}
147+
})
148+
}

modules/plugins/calc.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import getPrefixedValue from '../utils/getPrefixedValue'
2+
13
export default function calc({ property, value, browserInfo: { browser, version }, prefix: { css }, keepUnprefixed }) {
24
if (
35
typeof value === 'string' && value.indexOf('calc(') > -1 &&
@@ -8,9 +10,8 @@ export default function calc({ property, value, browserInfo: { browser, version
810
browser === 'ios_saf' && version < 7
911
)
1012
) {
11-
const prefixedValue = value.replace(/calc\(/g, css + 'calc(')
1213
return {
13-
[property]: keepUnprefixed ? [ prefixedValue, value ] : prefixedValue
14+
[property]: getPrefixedValue(value.replace(/calc\(/g, css + 'calc('), value, keepUnprefixed)
1415
}
1516
}
1617
}

modules/plugins/flex.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import getPrefixedValue from '../utils/getPrefixedValue'
2+
13
const values = { flex: true, 'inline-flex': true }
24

35
export default function flex({ property, value, browserInfo: { browser, version }, prefix: { css }, keepUnprefixed }) {
@@ -9,9 +11,8 @@ export default function flex({ property, value, browserInfo: { browser, version
911
browser === 'opera' && (version == 15 || version == 16)
1012
)
1113
) {
12-
const prefixedValue = css + value
1314
return {
14-
display: keepUnprefixed ? [ prefixedValue, value ] : prefixedValue
15+
display: getPrefixedValue(css + value, value, keepUnprefixed)
1516
}
1617
}
1718
}

modules/plugins/flexboxIE.js

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import getPrefixedValue from '../utils/getPrefixedValue'
2+
13
const alternativeValues = {
24
'space-around': 'distribute',
35
'space-between': 'justify',
@@ -17,24 +19,18 @@ const alternativeProps = {
1719
flexBasis: 'msPreferredSize'
1820
}
1921

20-
const properties = Object.keys(alternativeProps).reduce((result, prop) => {
21-
result[prop] = true
22-
return result
23-
}, { })
24-
2522
export default function flexboxIE({ property, value, styles, browserInfo: { browser, version }, prefix: { css }, keepUnprefixed }) {
2623
if (
27-
(properties[property] || property === 'display' && typeof value === 'string' && value.indexOf('flex') > -1) &&
24+
(alternativeProps[property] || property === 'display' && typeof value === 'string' && value.indexOf('flex') > -1) &&
2825
(
2926
(browser === 'ie_mob' || browser === 'ie') && version == 10)
3027
) {
31-
if (!keepUnprefixed) {
28+
if (!keepUnprefixed && !Array.isArray(styles[property])) {
3229
delete styles[property]
3330
}
3431
if (property === 'display' && alternativeValues[value]) {
35-
const prefixedValue = css + alternativeValues[value]
3632
return {
37-
display: keepUnprefixed ? [ prefixedValue, value ] : prefixedValue
33+
display: getPrefixedValue(css + alternativeValues[value], value, keepUnprefixed)
3834
}
3935
}
4036
if (alternativeProps[property]) {

modules/plugins/flexboxOld.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import getPrefixedValue from '../utils/getPrefixedValue'
2+
13
const alternativeValues = {
24
'space-around': 'justify',
35
'space-between': 'justify',
@@ -16,15 +18,11 @@ const alternativeProps = {
1618
}
1719

1820
const otherProps = [ 'alignContent', 'alignSelf', 'order', 'flexGrow', 'flexShrink', 'flexBasis', 'flexDirection' ]
19-
20-
const properties = Object.keys(alternativeProps).concat(otherProps).reduce((result, prop) => {
21-
result[prop] = true
22-
return result
23-
}, { })
21+
const properties = Object.keys(alternativeProps).concat(otherProps)
2422

2523
export default function flexboxOld({ property, value, styles, browserInfo: { browser, version }, prefix: { css }, keepUnprefixed }) {
2624
if (
27-
(properties[property] || property === 'display' && typeof value === 'string' && value.indexOf('flex') > -1) &&
25+
(properties.indexOf(property) > -1 || property === 'display' && typeof value === 'string' && value.indexOf('flex') > -1) &&
2826
(
2927
browser === 'firefox' && version < 22 ||
3028
browser === 'chrome' && version < 21 ||
@@ -33,7 +31,7 @@ export default function flexboxOld({ property, value, styles, browserInfo: { bro
3331
browser === 'and_uc'
3432
)
3533
) {
36-
if (!keepUnprefixed) {
34+
if (!keepUnprefixed && !Array.isArray(styles[property])) {
3735
delete styles[property]
3836
}
3937
if (property === 'flexDirection') {
@@ -43,9 +41,8 @@ export default function flexboxOld({ property, value, styles, browserInfo: { bro
4341
}
4442
}
4543
if (property === 'display' && alternativeValues[value]) {
46-
const prefixedValue = css + alternativeValues[value]
4744
return {
48-
display: keepUnprefixed ? [ prefixedValue, value ] : prefixedValue
45+
display: getPrefixedValue(css + alternativeValues[value], value, keepUnprefixed)
4946
}
5047
}
5148
if (alternativeProps[property]) {

modules/plugins/grabCursor.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import getPrefixedValue from '../utils/getPrefixedValue'
2+
13
const values = { grab: true, grabbing: true }
24

35
export default function grabCursor({ property, value, browserInfo: { browser, version }, prefix: { css }, keepUnprefixed }) {
@@ -11,9 +13,8 @@ export default function grabCursor({ property, value, browserInfo: { browser, ve
1113
browser === 'opera'
1214
)
1315
) {
14-
const prefixedValue = css + value
1516
return {
16-
cursor: keepUnprefixed ? [ prefixedValue, value ] : prefixedValue
17+
cursor: getPrefixedValue(css + value, value, keepUnprefixed)
1718
}
1819
}
1920
}

modules/plugins/gradient.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import getPrefixedValue from '../utils/getPrefixedValue'
2+
13
const values = /linear-gradient|radial-gradient|repeating-linear-gradient|repeating-radial-gradient/
24

35
export default function gradient({ property, value, browserInfo: { browser, version }, prefix: { css }, keepUnprefixed }) {
@@ -12,9 +14,8 @@ export default function gradient({ property, value, browserInfo: { browser, vers
1214
browser === 'and_uc'
1315
)
1416
) {
15-
const prefixedValue = css + value
1617
return {
17-
[property]: keepUnprefixed ? [ prefixedValue, value ] : prefixedValue
18+
[property]: getPrefixedValue(css + value, value, keepUnprefixed)
1819
}
1920
}
2021
}

modules/plugins/sizing.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import getPrefixedValue from '../utils/getPrefixedValue'
2+
13
const properties = {
24
maxHeight: true,
35
maxWidth: true,
@@ -19,9 +21,8 @@ export default function sizing({ property, value, prefix: { css }, keepUnprefixe
1921
// This might change in the future
2022
// Keep an eye on it
2123
if (properties[property] && values[value]) {
22-
const prefixedValue = css + value
2324
return {
24-
[property]: keepUnprefixed ? [ prefixedValue, value ] : prefixedValue
25+
[property]: getPrefixedValue(css + value, value, keepUnprefixed)
2526
}
2627
}
2728
}

modules/plugins/transition.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export default function transition({ property, value, prefix: { css }, requiresP
99
const unprefixedProperty = unprefixProperty(property)
1010

1111
if (typeof value === 'string' && properties[unprefixedProperty]) {
12+
// TODO: memoize this array
1213
const requiresPrefixDashCased = Object.keys(requiresPrefix).map(prop => hyphenateStyleName(prop))
1314

1415
// only split multi values, not cubic beziers

modules/plugins/zoomCursor.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import getPrefixedValue from '../utils/getPrefixedValue'
2+
13
const values = { 'zoom-in': true, 'zoom-out': true }
24

35
export default function zoomCursor({ property, value, browserInfo: { browser, version }, prefix: { css }, keepUnprefixed }) {
@@ -10,9 +12,8 @@ export default function zoomCursor({ property, value, browserInfo: { browser, ve
1012
browser === 'opera' && version < 24
1113
)
1214
) {
13-
const prefixedValue = css + value
1415
return {
15-
cursor: keepUnprefixed ? [ prefixedValue, value ] : prefixedValue
16+
cursor: getPrefixedValue(css + value, value, keepUnprefixed)
1617
}
1718
}
1819
}

0 commit comments

Comments
 (0)