11import prefixProperties from './prefixProps'
22import capitalizeString from '../utils/capitalizeString'
3- import assign from '../utils/assign'
43
54import calc from './plugins/calc'
65import cursor from './plugins/cursor'
@@ -34,9 +33,6 @@ export default function prefixAll(styles) {
3433 if ( value instanceof Object && ! Array . isArray ( value ) ) {
3534 // recurse through nested style objects
3635 styles [ property ] = prefixAll ( value )
37- } else if ( Array . isArray ( value ) ) {
38- // prefix fallback arrays
39- assign ( styles , prefixArray ( property , value ) )
4036 } else {
4137 Object . keys ( prefixProperties ) . forEach ( prefix => {
4238 const properties = prefixProperties [ prefix ]
@@ -49,42 +45,28 @@ export default function prefixAll(styles) {
4945 } )
5046
5147 Object . keys ( styles ) . forEach ( property => {
52- const value = styles [ property ]
53- // resolve every special plugins
54- plugins . forEach ( plugin => assign ( styles , plugin ( property , value ) ) )
48+ [ ] . concat ( styles [ property ] ) . forEach ( ( value , index ) => {
49+ // resolve every special plugins
50+ plugins . forEach ( plugin => assignStyles ( styles , plugin ( property , value ) ) )
51+ } )
5552 } )
5653
5754 return styles
5855}
5956
60- function prefixArray ( property , valueArray ) {
61- let result = { }
62- valueArray . forEach ( value => {
63- plugins . forEach ( plugin => {
64- let prefixed = plugin ( property , value )
65- if ( prefixed ) {
66- Object . keys ( prefixed ) . forEach ( prop => {
67- const entry = prefixed [ prop ]
68- result [ prop ] = result [ prop ] ? mergeValues ( result [ prop ] , entry ) : entry
69- } )
70- }
71- } )
72- if ( ! result [ property ] ) {
73- result [ property ] = value
74- }
75- } )
76- return result
77- }
78-
79- function mergeValues ( existing , toMerge ) {
80- let merged = existing
81- let valuesToMerge = Array . isArray ( toMerge ) ? toMerge : [ toMerge ]
82- valuesToMerge . forEach ( value => {
83- if ( Array . isArray ( merged ) && merged . indexOf ( value ) === - 1 ) {
84- merged . push ( value )
85- } else if ( merged !== value ) {
86- merged = [ merged , value ]
57+ function assignStyles ( base , extend = { } ) {
58+ Object . keys ( extend ) . forEach ( property => {
59+ const baseValue = base [ property ]
60+ if ( Array . isArray ( baseValue ) ) {
61+ [ ] . concat ( extend [ property ] ) . forEach ( value => {
62+ const valueIndex = baseValue . indexOf ( value )
63+ if ( valueIndex > - 1 ) {
64+ base [ property ] . splice ( valueIndex , 1 )
65+ }
66+ base [ property ] . push ( value )
67+ } )
68+ } else {
69+ base [ property ] = extend [ property ]
8770 }
8871 } )
89- return merged
9072}
0 commit comments