@@ -49,10 +49,19 @@ export function getStyledProps(
4949 const styledProps = state . stylesObs ?. get ( state . styleEffect ) ;
5050
5151 for ( const config of state . configs ) {
52- result = deepMergeConfig ( config , styledProps ?. normal , inline , true ) ;
52+ result = deepMergeConfig (
53+ config ,
54+ nativeStyleMapping ( config , styledProps ?. normal ) ,
55+ inline ,
56+ true ,
57+ ) ;
5358
5459 if ( styledProps ?. important ) {
55- result = deepMergeConfig ( config , result , styledProps . important ) ;
60+ result = deepMergeConfig (
61+ config ,
62+ result ,
63+ nativeStyleMapping ( config , styledProps . important ) ,
64+ ) ;
5665 }
5766
5867 // Apply the handlers
@@ -122,11 +131,11 @@ function deepMergeConfig(
122131 right : Record < string , any > | undefined | null ,
123132 rightIsInline = false ,
124133) {
125- if ( ! config . target || ! right ) {
134+ if ( ! right ) {
126135 return { ...left } ;
127136 }
128137
129- let result = Object . assign ( { } , left , right ) ;
138+ let result = config . target ? Object . assign ( { } , left , right ) : { ... left } ;
130139
131140 if (
132141 right &&
@@ -140,7 +149,7 @@ function deepMergeConfig(
140149 /**
141150 * If target is a path, deep merge until we get to the last key
142151 */
143- if ( Array . isArray ( config . target ) && config . target . length > 1 ) {
152+ if ( Array . isArray ( config . target ) ) {
144153 for ( let i = 0 ; i < config . target . length - 1 ; i ++ ) {
145154 const key = config . target [ i ] ;
146155
@@ -159,11 +168,9 @@ function deepMergeConfig(
159168 return result ;
160169 }
161170
162- const target = Array . isArray ( config . target )
163- ? config . target [ 0 ]
164- : config . target ;
171+ const target = config . target ;
165172
166- if ( target === undefined ) {
173+ if ( target === undefined || target === false ) {
167174 return result ;
168175 }
169176
@@ -196,3 +203,59 @@ function deepMergeConfig(
196203
197204 return result ;
198205}
206+
207+ function nativeStyleMapping (
208+ config : Config ,
209+ props : Record < string , any > | undefined ,
210+ ) {
211+ if ( ! config . nativeStyleMapping || ! props ) {
212+ return props ;
213+ }
214+
215+ let source : Record < string , any > | undefined ;
216+
217+ if ( typeof config . target === "string" ) {
218+ source = props [ config . target ] ;
219+ } else if ( config . target === false ) {
220+ source = props [ "style" ] ;
221+ } else {
222+ const tokens = [ ...config . target ] ;
223+ const lastToken = tokens . pop ( ) ! ;
224+
225+ source = props ;
226+ for ( const token of tokens ) {
227+ source = source [ token ] ;
228+ if ( ! source ) {
229+ return props ;
230+ }
231+ }
232+
233+ source = source [ lastToken ] ;
234+ }
235+
236+ if ( ! source ) {
237+ return props ;
238+ }
239+
240+ for ( const [ key , path ] of Object . entries ( config . nativeStyleMapping ) ) {
241+ const styleValue = source [ key ] ;
242+
243+ delete source [ key ] ;
244+
245+ if ( styleValue === undefined ) {
246+ continue ;
247+ }
248+
249+ let target = props ;
250+ const tokens = path . split ( "." ) ;
251+ const lastToken = tokens . pop ( ) ;
252+ for ( const token of tokens ) {
253+ target [ token ] ??= { } ;
254+ target = target [ token ] ;
255+ }
256+
257+ target [ lastToken ! ] = styleValue ;
258+ }
259+
260+ return props ;
261+ }
0 commit comments