Skip to content
Snippets Groups Projects
Select Git revision
  • a9b634a710b6195f32479fe9bad68be24b10d39b
  • master default protected
  • 1.31
  • 4.28.0
  • 4.27.0
  • 4.26.0
  • 4.25.5
  • 4.25.4
  • 4.25.3
  • 4.25.2
  • 4.25.1
  • 4.25.0
  • 4.24.3
  • 4.24.2
  • 4.24.1
  • 4.24.0
  • 4.23.6
  • 4.23.5
  • 4.23.4
  • 4.23.3
  • 4.23.2
  • 4.23.1
  • 4.23.0
23 results

Monster.Data.Pathfinder.html

Blame
  • jsdom.mjs 3.37 KiB
    'use strict';
    
    import {extend} from "../../source/data/extend.mjs";
    import {getGlobal} from "../../source/types/global.mjs";
    
    export const isBrowser = new Function("try {return this===window;}catch(e){ return false;}");
    export const isNode = new Function("try {return this===global;}catch(e){return false;}");
    
    let JSDOMExport = null;
    
    /**
     * this helper function creates the dom stack in the node environment
     *
     * @return {Promise<unknown>|Promise<void>}
     */
    function initJSDOM(options) {
        if (typeof window === "object" && window['DOMParser']) return Promise.resolve();
    
        const g = getGlobal();
    
        options = extend({}, {
            pretendToBeVisual: true,
            contentType: "text/html",
            includeNodeLocations: true,
            storageQuota: 10000000,
            runScripts: "dangerously",
            resources: "usable"
        }, options || {})
    
        return import("jsdom").then(({JSDOM}) => {
            JSDOMExport = JSDOM;
            const {window} = new JSDOM(`<!DOCTYPE html><html lang="en"><head><title>Test</title></head><body><div id="mocks"></div></body></html>`, options);
    
            g['window'] = window;
            
            return new Promise((resolve, reject) =>
                window.addEventListener("load", () => {
    
                    [
                        'Blob',
                        'CSSStyleSheet',
                        'customElements',
                        'CustomEvent',
                        'document',
                        'Document',
                        'DocumentFragment',
                        'DOMParser',
                        'Element',
                        'ElementInternals',
                        'Event',
                        'EventTarget',
                        'getComputedStyle',
                        'HTMLButtonElement',
                        'HTMLCollection',
                        'HTMLDivElement',
                        'HTMLDocument',
                        'HTMLElement',
                        'HTMLFormElement',
                        'HTMLInputElement',
                        'HTMLScriptElement',
                        'requestAnimationFrame',
                        'HTMLSelectElement',
                        'HTMLTemplateElement',
                        'HTMLTextAreaElement',
                        'InputEvent',
                        'KeyboardEvent',
                        'MutationObserver',
                        'navigator',
                        'Node',
                        'NodeFilter',
                        'NodeList',
                        'self',
                        'ShadowRoot',
                        'XMLSerializer',
                    ].forEach(key => {
                        try {
                            g[key] = window[key]    
                        } catch(e) {
                            console.error("Error setting key", key, e);
                        }
                        
                        
                    });
    
                    import("dom-storage").then(({default: Storage}) => {
                        
                        g.localStorage = new Storage(null, {strict: true});
                        g.sessionStorage = new Storage(null, {strict: true});
    
                        window['localStorage'] = g.localStorage;
                        window['sessionStorage'] = g.sessionStorage;
    
                        resolve(g);
                        
                    }).catch(e => {
                        console.error("Error loading dom-storage", e);
                        reject(e);
                    });
    
                })
            );
    
    
        });
    }
    
    export {initJSDOM, JSDOMExport}