1
0
mirror of https://github.com/jaandrle/deka-dom-el synced 2024-11-22 16:55:23 +01:00
deka-dom-el/jsdom.js

38 lines
974 B
JavaScript
Raw Normal View History

2023-09-13 21:37:00 +02:00
//TODO: https://www.npmjs.com/package/html-element
import { enviroment as env } from './src/dom-common.js';
env.ssr= " ssr";
const { setDeleteAttr }= env;
/** @param {HTMLElement} obj */
env.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= { H: "HTMLElement", S: "SVGElement", F: "DocumentFragment", M: "MutationObserver", D: "document" };
let env_bk= {};
let dom_last;
2023-09-13 21:37:00 +02:00
export function register(dom){
if(dom_last!==dom){
const w= dom.window;
Object.entries(keys).forEach(([ kE, kW ])=> {
env_bk[kE]= env[kE];
env[kE]= w[kW];
});
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;
Object.assign(env, env_bk);
env_bk= {};
dom_last= undefined;
return true;
2023-09-05 11:01:29 +02:00
}