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