File tree Expand file tree Collapse file tree 4 files changed +12
-10
lines changed
Expand file tree Collapse file tree 4 files changed +12
-10
lines changed Original file line number Diff line number Diff line change 11{
22 "name" : " dom-renderer" ,
3- "version" : " 2.4.0 " ,
3+ "version" : " 2.4.1 " ,
44 "license" : " LGPL-3.0-or-later" ,
55 "author" : " shiy2008@gmail.com" ,
66 "description" : " A light-weight DOM Renderer supports Web components standard & TypeScript language" ,
Original file line number Diff line number Diff line change @@ -183,7 +183,7 @@ export class DOMRenderer {
183183 return newVNode ;
184184 }
185185
186- render ( vNode : VNode , node : ParentNode = this . document . body ) {
186+ render ( vNode : VNode , node : ParentNode = globalThis . document ? .body ) {
187187 this . document = node . ownerDocument ;
188188
189189 var root = this . treeCache . get ( node ) || VNode . fromDOM ( node ) ;
Original file line number Diff line number Diff line change @@ -50,8 +50,12 @@ export class VNode extends VNodeMeta {
5050 while ( ( current = current . parent ) ) yield current ;
5151 }
5252
53- findNamespace ( ) {
53+ namespaceOf ( tagName : string ) {
54+ if ( XMLNamespace [ tagName ] ) return XMLNamespace [ tagName ] ;
55+
5456 for ( const { namespace } of this . walkUp ( ) ) if ( namespace ) return namespace ;
57+
58+ return XMLNamespace . html ;
5559 }
5660
5761 createDOM ( document = globalThis . document ) {
@@ -61,11 +65,9 @@ export class VNode extends VNodeMeta {
6165 ? document . createTextNode ( text )
6266 : ! tagName
6367 ? document . createDocumentFragment ( )
64- : document . createElementNS (
65- ( this . namespace ||= XMLNamespace [ tagName ] || this . findNamespace ( ) ) ,
66- tagName ,
67- { is }
68- ) ) ;
68+ : document . createElementNS ( ( this . namespace ||= this . namespaceOf ( tagName ) ) , tagName , {
69+ is
70+ } ) ) ;
6971 }
7072
7173 toJSON ( ) : VNodeMeta {
Original file line number Diff line number Diff line change @@ -180,11 +180,11 @@ describe('JSX runtime', () => {
180180 < text x = "150" y = "125" font-size = "60" text-anchor = "middle" fill = "white" >
181181 SVG
182182 </ text >
183- </ svg > ,
184- document . body
183+ </ svg >
185184 ) ;
186185 expect ( document . body . innerHTML ) . toBe (
187186 '<svg version="1.1" width="300" height="200" xmlns="http://www.w3.org/2000/svg"><rect width="100%" height="100%" fill="red"></rect><circle cx="150" cy="100" r="80" fill="green"></circle><text x="150" y="125" font-size="60" text-anchor="middle" fill="white">SVG</text></svg>'
188187 ) ;
188+ expect ( document . body . firstElementChild ) . toBeInstanceOf ( SVGSVGElement ) ;
189189 } ) ;
190190} ) ;
You can’t perform that action at this time.
0 commit comments