mirror of
https://github.com/jaandrle/deka-dom-el
synced 2025-04-02 20:15:53 +02:00
* ⚡ 🎉 * ⚡ wip * 🔤 * ⚡ wip * ⚡ wip * ⚡ Refatc signals to .get/.set syntax #26 * 🐛 Better types for on* * 🔤 * 🔤 * 🐛 coumputed signal * 🔤 ⚡ Docs UI/UX * ⚡ 🔤 UI enhancements * ⚡ (bs) (un)min * 🔤 adds debugging * 🔤 ssr * 🔤 * ⚡ bs/lint * 🔤 * 🔤 UI * 🔤 updates texts * 🔤UI * ⚡ dispatch * 🔤 events * 🔤 elements * 🔤 intro * 🐛 fixes completitions for el with components * 🐛 wrong file(s) in git * 🔤 logo * 🐛 🔤 types 3ps * 🔤 ui/ux * 🔤 * 🔤 * 🔤 scopes * 🔤 * 🔤 ui/ux * 🔤 * ⚡ issignal * 🔤 improvemens * ⚡ irelands * 🔤 UI/UX/wording * 🐛 npx-hint [Scrollable region must have keyboard access | Axe Rules | Deque University | Deque Systems](https://dequeuniversity.com/rules/axe/4.10/scrollable-region-focusable?application=axeAPI) * 🔤 logos * ⚡ better? dts builds * Update README.md
43 lines
1.4 KiB
JavaScript
43 lines
1.4 KiB
JavaScript
import { JSDOM } from "jsdom";
|
|
const html_default= "<!doctype html><html lang=\"en\"><head><meta charset=\"utf-8\"></head><body></body></html>";
|
|
let keys= [];
|
|
let dom= null;
|
|
import { relative } from 'node:path';
|
|
import { writeFileSync } from 'node:fs';
|
|
/** @param {string} html */
|
|
export function createHTMl(html, options= {}){
|
|
if(!html) html= html_default;
|
|
if(dom) cleanHTML();
|
|
// set a default url if we don't get one - otherwise things explode when we copy localstorage keys
|
|
if (!('url' in options)) { Object.assign(options, { url: 'http://localhost:3000' }) }
|
|
|
|
dom= new JSDOM(html, options);
|
|
const window= dom.window;
|
|
return {
|
|
dom,
|
|
writeToFS({ html, css }){
|
|
if(css) this.style.writeToFile(css, relative(html, css).slice(1));
|
|
if(html) writeFileSync(html, dom.serialize());
|
|
},
|
|
/** @param {string[]} [names] */
|
|
registerGlobally(...names){
|
|
keys.push(...names);
|
|
if(!keys.length)
|
|
keys= Object.getOwnPropertyNames(window).filter((k) => !k.startsWith('_') && !(k in globalThis));
|
|
keys.forEach(key=> globalThis[key]= window[key]);
|
|
globalThis.document= window.document
|
|
globalThis.window= window
|
|
window.console= globalThis.console
|
|
return this;
|
|
},
|
|
serialize(){ return dom.serialize(); },
|
|
window, document: window.document
|
|
};
|
|
}
|
|
export function cleanHTML(){
|
|
if(!dom) return;
|
|
keys.forEach(key=> delete globalThis[key]);
|
|
keys.length= 0;
|
|
dom= false;
|
|
}
|