mirror of
				https://github.com/jaandrle/deka-dom-el
				synced 2025-11-04 07:09:15 +01:00 
			
		
		
		
	🧱 add jsdom support
This commit is contained in:
		@@ -1,6 +1,6 @@
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
	"name": "deka-dom-el",
 | 
						"name": "deka-dom-el",
 | 
				
			||||||
	"version": "0.1.0",
 | 
						"version": "0.1.1",
 | 
				
			||||||
	"description": "A low-code library that simplifies the creation of native DOM elements/components using small wrappers and tweaks.",
 | 
						"description": "A low-code library that simplifies the creation of native DOM elements/components using small wrappers and tweaks.",
 | 
				
			||||||
	"author": "Jan Andrle <andrle.jan@centrum.cz>",
 | 
						"author": "Jan Andrle <andrle.jan@centrum.cz>",
 | 
				
			||||||
	"license": "MIT",
 | 
						"license": "MIT",
 | 
				
			||||||
@@ -19,6 +19,9 @@
 | 
				
			|||||||
		".": {
 | 
							".": {
 | 
				
			||||||
			"import": "./index.js"
 | 
								"import": "./index.js"
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
 | 
							"./jsdom": {
 | 
				
			||||||
 | 
								"import": "./src/jsdom.js"
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
		"./signals": {
 | 
							"./signals": {
 | 
				
			||||||
			"import": "./src/signals.js"
 | 
								"import": "./src/signals.js"
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
@@ -31,6 +34,9 @@
 | 
				
			|||||||
			".": [
 | 
								".": [
 | 
				
			||||||
				"./index.d.ts"
 | 
									"./index.d.ts"
 | 
				
			||||||
			],
 | 
								],
 | 
				
			||||||
 | 
								"./jsdom": [
 | 
				
			||||||
 | 
									"./src/jsdom.d.ts"
 | 
				
			||||||
 | 
								],
 | 
				
			||||||
			"./signals": [
 | 
								"./signals": [
 | 
				
			||||||
				"./src/signals.d.ts"
 | 
									"./src/signals.d.ts"
 | 
				
			||||||
			],
 | 
								],
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -22,7 +22,7 @@ export function createElement(tag, attributes, ...connect){
 | 
				
			|||||||
		case typeof tag==="function": el= tag(attributes || undefined); break;
 | 
							case typeof tag==="function": el= tag(attributes || undefined); break;
 | 
				
			||||||
		case tag==="#text":           el= assign(document.createTextNode(""), attributes); break;
 | 
							case tag==="#text":           el= assign(document.createTextNode(""), attributes); break;
 | 
				
			||||||
		case namespace_curr!=="html": el= assign(document.createElementNS(namespace_curr, tag), attributes); break;
 | 
							case namespace_curr!=="html": el= assign(document.createElementNS(namespace_curr, tag), attributes); break;
 | 
				
			||||||
		default:                      el= assign(document.createElement(tag), attributes);
 | 
							case !el:                     el= assign(document.createElement(tag), attributes);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	connect.forEach(c=> c(el));
 | 
						connect.forEach(c=> c(el));
 | 
				
			||||||
	return el;
 | 
						return el;
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										6
									
								
								src/jsdom.d.ts
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								src/jsdom.d.ts
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,6 @@
 | 
				
			|||||||
 | 
					import { el, assign, on } from "../index.d";
 | 
				
			||||||
 | 
					export function register(dom: typeof document): Promise<{
 | 
				
			||||||
 | 
						el: typeof el,
 | 
				
			||||||
 | 
						assign: typeof assign,
 | 
				
			||||||
 | 
						on: typeof on
 | 
				
			||||||
 | 
					}>
 | 
				
			||||||
							
								
								
									
										11
									
								
								src/jsdom.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								src/jsdom.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,11 @@
 | 
				
			|||||||
 | 
					let keys= [];
 | 
				
			||||||
 | 
					export function register(dom){
 | 
				
			||||||
 | 
						const window= dom.window;
 | 
				
			||||||
 | 
						if(!keys.length)
 | 
				
			||||||
 | 
							keys= Object.getOwnPropertyNames(window).filter((k) => !k.startsWith('_') && !(k in globalThis));
 | 
				
			||||||
 | 
						keys.forEach(key=> globalThis[key]= window[key]);
 | 
				
			||||||
 | 
						global.document= window.document
 | 
				
			||||||
 | 
						global.window= window
 | 
				
			||||||
 | 
						window.console= global.console
 | 
				
			||||||
 | 
						return import("../index.js");
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Reference in New Issue
	
	Block a user