@@ -53,7 +53,7 @@ export class SvgElement extends StylableJsxWidget {
5353 */
5454 readonly stroke ?: Color ;
5555
56- readonly children ;
56+ readonly children : StylableJsxWidget [ ] ;
5757
5858 constructor ( p : {
5959 key : WidgetKey ;
@@ -81,39 +81,40 @@ export class SvgElement extends StylableJsxWidget {
8181 this . children = this . _init_children ( ) ;
8282 }
8383
84- private _init_children ( ) {
85- const path_with_fill = ( fill : string | false ) =>
86- < StylableJsxWidget > {
87- key : new WidgetKey ( ` ${ this . key . id } .svg-path` , "svg-path" ) ,
88- styleData : ( ) => null ,
89- jsxConfig : ( ) => {
90- const _tag = JSX . identifier ( "path" ) ;
91- return {
92- tag : _tag ,
93- type : "tag-and-attr" ,
94- attributes : [
95- fill &&
96- new JSXAttribute ( "fill " , new StringLiteral ( fill || "current ") ) ,
97- new JSXAttribute ( "d" , new StringLiteral ( this . data ?? "" ) ) ,
98- ] ,
99- } ;
100- } ,
101- } ;
84+ path ( { fill } : { fill : string | false } ) {
85+ return < StylableJsxWidget > {
86+ key : new WidgetKey ( ` ${ this . key . id } .svg-path` , "svg-path" ) ,
87+ styleData : ( ) => null ,
88+ jsxConfig : ( ) => {
89+ const _tag = JSX . identifier ( "path" ) ;
90+ return {
91+ tag : _tag ,
92+ type : "tag-and-attr" ,
93+ attributes : [
94+ fill &&
95+ new JSXAttribute ( " fill" , new StringLiteral ( fill || "current" ) ) ,
96+ new JSXAttribute ( "d " , new StringLiteral ( this . data ?? " ") ) ,
97+ ] ,
98+ } ;
99+ } ,
100+ } ;
101+ }
102102
103+ private _init_children ( ) {
103104 if ( ! this . fill ) {
104- return [ path_with_fill ( "transparent" ) ] ;
105+ return [ this . path ( { fill : "transparent" } ) ] ;
105106 }
106107
107108 if ( Array . isArray ( this . fill ) ) {
108109 console . error ( "multiple fills for svg path is not supported." ) ;
109110 } else {
110111 switch ( this . fill . type ) {
111112 case "solid-color" : {
112- return [ path_with_fill ( css . color ( this . fill as Color ) ) ] ;
113+ return [ this . path ( { fill : css . color ( this . fill as Color ) } ) ] ;
113114 }
114115 case "graphics" : {
115116 console . error ( "graphics fill for svg not supported." ) ;
116- return [ path_with_fill ( "black" ) ] ;
117+ return [ this . path ( { fill : "black" } ) ] ;
117118 }
118119 case "gradient" : {
119120 switch ( this . fill . _type ) {
@@ -168,11 +169,11 @@ export class SvgElement extends StylableJsxWidget {
168169 } ,
169170 } ;
170171
171- return [ fill , path_with_fill ( `url(#${ fillid } )` ) ] ;
172+ return [ fill , this . path ( { fill : `url(#${ fillid } )` } ) ] ;
172173 }
173174 default : {
174175 console . error ( "unsupported gradient type for svg path." ) ;
175- return [ path_with_fill ( "black" ) ] ;
176+ return [ this . path ( { fill : "black" } ) ] ;
176177 }
177178 }
178179 }
@@ -199,8 +200,8 @@ export class SvgElement extends StylableJsxWidget {
199200 } ;
200201 }
201202
202- jsxConfig ( ) : StylableJSXElementConfig {
203- return {
203+ jsxConfig ( ) : StylableJSXElementConfig | UnstylableJSXElementConfig {
204+ return < StylableJSXElementConfig > {
204205 type : "tag-and-attr" ,
205206 tag : JSX . identifier ( "svg" ) ,
206207 attributes : [
0 commit comments