mirror of
https://github.com/jaandrle/deka-dom-el
synced 2024-11-23 17:19:37 +01:00
38 lines
973 B
JavaScript
38 lines
973 B
JavaScript
//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);
|
|
};
|
|
const keys= { H: "HTMLElement", S: "SVGElement", F: "DocumentFragment", M: "MutationObserver", D: "document" };
|
|
let env_bk= {};
|
|
let dom_last;
|
|
|
|
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;
|
|
}
|
|
dom_last= dom;
|
|
|
|
return import("./index.js");
|
|
}
|
|
export function unregister(){
|
|
if(!dom_last)
|
|
return false;
|
|
|
|
Object.assign(env, env_bk);
|
|
env_bk= {};
|
|
dom_last= undefined;
|
|
return true;
|
|
}
|