1
0
mirror of https://github.com/jaandrle/deka-dom-el synced 2024-11-24 01:29:36 +01:00
deka-dom-el/jsdom.js

36 lines
1.0 KiB
JavaScript
Raw Normal View History

2023-09-13 21:37:00 +02:00
//TODO: https://www.npmjs.com/package/html-element
2023-11-10 17:15:59 +01:00
import { enviroment } from './src/dom-common.js';
2023-11-10 18:02:56 +01:00
enviroment.ssr= " ssr";
2023-11-10 17:15:59 +01:00
const { setDeleteAttr }= enviroment;
/** @param {HTMLElement} obj */
2023-11-10 17:15:59 +01:00
enviroment.setDeleteAttr= function(obj, prop, value){
if("value"===prop) return obj.setAttribute(prop, value);
if("checked"!==prop) return setDeleteAttr(obj, prop, value);
if(value) return obj.setAttribute(prop, "");
obj.removeAttribute(prop);
2023-09-13 13:20:00 +02:00
};
const keys= [ "HTMLElement", "SVGElement", "DocumentFragment", "MutationObserver", "document" ];
let dom_last;
2023-09-13 21:37:00 +02:00
export function register(dom, keys_aditional= []){
if(dom_last!==dom){
keys.push(...keys_aditional);
const w= dom.window;
keys.forEach(key=> globalThis[key]= w[key]);
globalThis.window= w;
w.console= globalThis.console;
}
2023-11-07 15:10:55 +01:00
dom_last= dom;
2023-09-13 21:37:00 +02:00
return import("./index.js");
}
export function unregister(){
if(!dom_last)
return false;
keys.forEach(key=> Reflect.deleteProperty(globalThis, key));
Reflect.deleteProperty(globalThis, "window");
dom_last= undefined;
return true;
2023-09-05 11:01:29 +02:00
}