11import { createComponent , JSX , mergeProps , PropsWithChildren } from 'solid-js' ;
22import { Dynamic } from 'solid-js/web' ;
3+ import {
4+ CSS_PROPERTIES ,
5+ LOWERCASE_ATTRIBUTES ,
6+ MAPPED_ATTRIBUTES ,
7+ REPLACED_COMPAT ,
8+ SVG_ATTRIBUTES ,
9+ } from 'elements' ;
310
411export const Fragment = ( properties : PropsWithChildren ) : JSX . Element => properties . children ;
512
@@ -11,6 +18,11 @@ const getProperties = (
1118 properties_ [ jsxKeyToSolid ( key ) ] =
1219 typeof properties [ key ] === 'object' && ! Array . isArray ( properties [ key ] )
1320 ? getProperties ( properties [ key ] as Record < string , unknown > )
21+ : typeof properties [ key ] === 'string'
22+ ? ( properties [ key ] as string ) . replace (
23+ new RegExp ( [ ...REPLACED_COMPAT . keys ( ) ] . join ( '|' ) , 'g' ) ,
24+ ( match : string ) => REPLACED_COMPAT . get ( match ) ?? match
25+ )
1426 : properties [ key ] ;
1527 return properties_ ;
1628} ;
@@ -23,7 +35,10 @@ export const jsx = (
2335 ? type . name === 'Fragment'
2436 ? Fragment ( properties )
2537 : type ( getProperties ( properties ) )
26- : createComponent ( Dynamic , mergeProps ( getProperties ( properties ) , { component : type } ) ) ;
38+ : createComponent (
39+ Dynamic ,
40+ mergeProps ( getProperties ( properties ) , { component : REPLACED_COMPAT . get ( type ) ?? type } )
41+ ) ;
2742
2843// For the moment we do not distinguish static children from dynamic ones
2944export const jsxs = jsx ;
@@ -32,50 +47,23 @@ export const jsxs = jsx;
3247// function jsxDEV(type, props , maybeKey, isStaticChildren, source, self)
3348export const jsxDEV = jsx ;
3449
35- // Attributes that need to be renamed
36- const MAPPED_ATTRIBUTES = new Map < string , string > ( [
37- [ 'className' , 'class' ] ,
38- [ 'htmlFor' , 'for' ] ,
39- [ 'glyphName' , 'glyph-name' ] ,
40- [ 'glyphOrientationHorizontal' , 'glyph-orientation-horizontal' ] ,
41- [ 'glyphOrientationVertical' , 'glyph-orientation-vertical' ] ,
42- // ['horizAdvX', 'horiz-adv-x'],
43- // ['horizOriginX', 'horiz-origin-x'],
44- [ 'markerEnd' , 'marker-end' ] ,
45- [ 'markerMid' , 'marker-mid' ] ,
46- [ 'markerStart' , 'marker-start' ] ,
47- [ 'textAnchor' , 'text-anchor' ] ,
48- [ 'textDecoration' , 'text-decoration' ] ,
49- [ 'textRendering' , 'text-rendering' ] ,
50- ] ) ;
51-
52- // Attributes that need to be converted to lowercase
53- const LOWERCASE_ATTRIBUTES = new Map < string , string > (
54- [
55- 'autoComplete' ,
56- 'autoFocus' ,
57- 'allowFullScreen' ,
58- 'contentEditable' ,
59- 'formNoValidate' ,
60- 'isMap' ,
61- 'noModule' ,
62- 'noValidate' ,
63- 'playsInline' ,
64- 'readOnly' ,
65- 'tabIndex' ,
66- ] . map ( ( attribute ) => [ attribute , attribute . toLowerCase ( ) ] )
67- ) ;
68-
6950const jsxKeyToSolid = ( key : string ) : string =>
7051 MAPPED_ATTRIBUTES . get ( key ) ??
7152 LOWERCASE_ATTRIBUTES . get ( key ) ??
7253 key
7354 . replace (
74- / ^ ( x m l n s | x l i n k | x m l ) ( [ A - Z ] [ a - z ] + ) / ,
55+ / ^ ( x m l (?: n s ) ? | x l i n k ) ( [ A - Z ] [ a - z ] + ) / ,
7556 ( _ , p1 : string , p2 : string ) => `${ p1 } :${ p2 . toLowerCase ( ) } `
7657 )
7758 . replace (
78- / ^ ( a c c e n t | a r a b i c | b a s e l i n e | c a p | c l i p | c o l o r | d o m i n a n t | e n a b l e | f i l l | f l o o d | f o n t | i m a g e | l e t t e r | l i g h t n i n g | o v e r l i n e | p a i n t | p o i n t e r | r e n d e r i n g | s h a p e | s t o p | s t r i k e t h r o u g h | s t r o k e | t r a n s f o r m | u n d e r l i n e | u n i c o d e | v | v e c t o r | v e r t | v e r t i c a l | w o r d | w r i t i n g | x | ) ( [ A - Z ] [ a - z ] + ?) ( [ A - Z ] [ a - z ] + ?) ? / ,
79- ( _ , p1 : string , p2 : string , p3 : string | undefined ) =>
80- `${ p1 } -${ p2 . toLowerCase ( ) } ${ p3 ? `-${ p3 } ` : '' } `
59+ new RegExp (
60+ `^(${ [ ...CSS_PROPERTIES , ...SVG_ATTRIBUTES ] . join (
61+ '|'
62+ ) } )([A-Z][a-z]+)([A-Z][a-z]+)?([A-Z][a-z]+)?`
63+ ) ,
64+ ( _ , p1 : string , p2 : string , p3 ?: string , p4 ?: string ) =>
65+ [ p1 , p2 , p3 , p4 ]
66+ . filter ( Boolean )
67+ . map ( ( value ) => value ?. toLowerCase ( ) )
68+ . join ( '-' )
8169 ) ;
0 commit comments