2023-09-13 21:37:00 +02:00
|
|
|
//TODO: https://www.npmjs.com/package/html-element
|
2023-09-13 21:06:13 +02:00
|
|
|
import { prop_process } from './src/dom-common.js';
|
2023-09-19 12:34:42 +02:00
|
|
|
const { setDeleteAttr }= prop_process;
|
2023-09-13 13:02:17 +02:00
|
|
|
/** @param {HTMLElement} obj */
|
2023-09-19 12:34:42 +02:00
|
|
|
prop_process.setDeleteAttr= function(obj, prop, value){
|
2023-09-19 16:19:37 +02:00
|
|
|
if("value"===prop) return obj.setAttribute(prop, value);
|
2023-09-19 13:40:18 +02:00
|
|
|
if("checked"!==prop) return setDeleteAttr(obj, prop, value);
|
2023-09-19 13:36:20 +02:00
|
|
|
if(value) return obj.setAttribute(prop, "");
|
|
|
|
obj.removeAttribute(prop);
|
2023-09-13 13:20:00 +02:00
|
|
|
};
|
2023-09-06 14:54:02 +02:00
|
|
|
const keys= [ "HTMLElement", "SVGElement", "DocumentFragment", "MutationObserver", "document" ];
|
|
|
|
let dom_last;
|
2023-09-13 21:37:00 +02:00
|
|
|
|
2023-11-05 21:49:32 +01: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-09-13 21:37:00 +02:00
|
|
|
|
2023-11-05 21:49:32 +01:00
|
|
|
return import("./index.js");
|
2023-09-06 14:54:02 +02:00
|
|
|
}
|
|
|
|
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
|
|
|
}
|