export type VNodeData = Record < string , unknown > ; const pattern = { kebab : /-(\w)/g , styleProp : /:(.*)/ , styleList : /;(?![^(]*\))/g , } as const ; function camelReplace ( _substr , match ) { return match . toUpperCase ( ) ; } function camelCase ( str ) { return str . replace ( pattern . kebab , camelReplace ) ; } function parseStyle ( style ) { let styleMap = { } ; for ( let s of style . split ( pattern . styleList ) ) { let [ key , val ] = s . split ( pattern . styleProp ) ; key = key . trim ( ) ; if ( ! key ) { continue ; } val = val . trim ( ) ; styleMap [ camelCase ( key ) ] = val ; } return styleMap ; } /**
 * Intelligently merges data for createElement.
 * Merges arguments left to right, preferring the right argument.
 * Returns new attributes (VNodeData) object.
 */ function mergeData ( ... vNodeData ) ; function mergeData ( ) { let mergeTarget = { } ; let i = arguments . length ; let prop ; while ( i -- ) { for ( prop of Object . keys ( arguments [ i ] ) ) { if ( arguments [ i ] [ prop ] == null ) { continue ; } switch ( prop ) { case "class" : { let classes = [ ] ; { let value = mergeTarget [ "class" ] ; if ( Array . isArray ( value ) ) { classes = value ; } } mergeTarget [ "class" ] = classes . concat ( arguments [ i ] [ "class" ] ) ; continue ; } case "style" : { let styles = [ ] ; { let value = mergeTarget . style ; if ( Array . isArray ( value ) ) { styles = value ; } } let thisStyle = [ ] ; if ( Array . isArray ( arguments [ i ] . style ) ) { thisStyle = arguments [ i ] . style ; } else { thisStyle . push ( arguments [ i ] . style ) ; } for ( let j = 0 ; j < thisStyle . length ; j ++ ) { let s = thisStyle [ j ] ; if ( typeof s === "string" ) { thisStyle [ j ] = parseStyle ( s ) ; } } mergeTarget [ prop ] = styles . concat ( thisStyle ) ; continue ; } case "id" : case "key" : case "ref" : case "keepAlive" : { if ( ! mergeTarget [ prop ] ) { mergeTarget [ prop ] = arguments [ i ] [ prop ] ; } continue ; } } if ( prop . startsWith ( "on" ) && prop !== "on" ) { if ( mergeTarget [ prop ] && ! Array . isArray ( mergeTarget [ prop ] ) ) { mergeTarget [ prop ] = [ mergeTarget [ prop ] , arguments [ i ] [ prop ] ] ; continue ; } let targetValue = mergeTarget [ prop ] ; let thisValue = arguments [ i ] [ prop ] ; if ( Array . isArray ( targetValue ) ) { if ( Array . isArray ( thisValue ) ) { targetValue . push ( ... thisValue ) ; } else { targetValue . push ( thisValue ) ; } continue ; } } mergeTarget [ prop ] = arguments [ i ] [ prop ] ; } } return mergeTarget ; } export { mergeData } ;