"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.defaultWebBoot = defaultWebBoot;
exports.webBoot = webBoot;
const boot_1 = require("../../../boot");
const _classes_1 = __importDefault(require("../../../system/_classes"));
const _components_1 = __importDefault(require("../../../system/_components"));
const _specs_1 = __importDefault(require("../../../system/_specs"));
const SYSTEM_ROOT_ID_1 = require("../../constants/SYSTEM_ROOT_ID");
const attachApp_1 = require("../../render/attachApp");
const attachGesture_1 = require("../../render/attachGesture");
const attachHTML_1 = require("../../render/attachHTML");
const attachLayout_1 = require("../../render/attachLayout");
const attachLongPress_1 = require("../../render/attachLongPress");
const attachStyle_1 = require("../../render/attachStyle");
const attachSVG_1 = require("../../render/attachSVG");
const attachVoid_1 = require("../../render/attachVoid");
const alert_1 = require("./api/alert");
const animation_1 = require("./api/animation");
const bluetooth_1 = require("./api/bluetooth");
const clipboard_1 = require("./api/clipboard");
const crypto_1 = require("./api/crypto");
const db_1 = require("./api/db");
const device_1 = require("./api/device");
const document_1 = require("./api/document");
const file_1 = require("./api/file");
const geolocation_1 = require("./api/geolocation");
const history_1 = require("./api/history");
const http_1 = require("./api/http");
const input_1 = require("./api/input");
const layout_1 = require("./api/layout");
const location_1 = require("./api/location");
const media_1 = require("./api/media");
const navigator_1 = require("./api/navigator");
const querystring_1 = require("./api/querystring");
const screen_1 = require("./api/screen");
const selection_1 = require("./api/selection");
const speech_1 = require("./api/speech");
const text_1 = require("./api/text");
const theme_1 = require("./api/theme");
const uri_1 = require("./api/uri");
const url_1 = require("./api/url");
const window_1 = require("./api/window");
const worker_1 = require("./api/worker");
function defaultWebBoot(opt) {
    const root = document.getElementById(SYSTEM_ROOT_ID_1.SYSTEM_ROOT_ID);
    return webBoot(window, root, opt);
}
function webBoot(window, root, opt = {
    specs: _specs_1.default,
    classes: _classes_1.default,
    components: _components_1.default,
}) {
    root.attachShadow({ mode: 'open' });
    const http = (0, http_1.webHTTP)(window, opt);
    const file = (0, file_1.webFile)(window, opt);
    const screen = (0, screen_1.webScreen)(window, opt);
    const device = (0, device_1.webDevice)(window, opt);
    const geolocation = (0, geolocation_1.webGeolocation)(window, opt);
    const speech = (0, speech_1.webSpeech)(window, opt);
    const media = (0, media_1.webMedia)(window, opt);
    const clipboard = (0, clipboard_1.webClipboard)(window, opt);
    const selection = (0, selection_1.webSelection)(window, opt);
    const animation = (0, animation_1.webAnimation)(window, opt);
    const document = (0, document_1.webDocument)(window, root, opt);
    const querystring = (0, querystring_1.webQuerystring)(window, opt);
    const bluetooth = (0, bluetooth_1.webBluetooth)(window, opt);
    const text = (0, text_1.webText)(window, opt);
    const input = (0, input_1.webInput)(window, root, opt);
    const db = (0, db_1.webDB)(window, opt);
    const worker = (0, worker_1.webWorker)(window, opt);
    const url = (0, url_1.webURL)(window, opt);
    const uri = (0, uri_1.webURI)(window, opt);
    const alert = (0, alert_1.webAlert)(window, opt);
    const location = (0, location_1.webLocation)(window, opt);
    const history = (0, history_1.webHistory)(window, opt);
    const _window = (0, window_1.webWindow)(window, opt);
    const navigator = (0, navigator_1.webNavigator)(window, opt);
    const layout = (0, layout_1.webLayout)(window, opt);
    const theme = (0, theme_1.webTheme)(window, root, opt);
    const crypto = (0, crypto_1.webCrypto)(window, opt);
    const api = {
        alert,
        selection,
        file,
        animation,
        db,
        device,
        screen,
        bluetooth,
        clipboard,
        crypto,
        location,
        history,
        geolocation,
        layout,
        media,
        http,
        input,
        speech,
        document,
        querystring,
        text,
        worker,
        url,
        uri,
        window: _window,
        navigator,
        theme,
    };
    const system = (0, boot_1.boot)(null, api, opt);
    system.emitter.addListener('listen', ({ event }) => {
        if (event === 'hashchange') {
            const listener = (event) => {
                const { oldURL, newURL } = event;
                system.emitter.emit('hashchange', { oldURL, newURL });
            };
            window.addEventListener('hashchange', listener);
            return () => {
                window.removeEventListener('hashchange', listener);
            };
        }
    });
    root.style.fontFamily = "'Inconsolata', monospace";
    system.root = root;
    (0, attachStyle_1.attachStyle)(system);
    (0, attachApp_1.attachApp)(system);
    (0, attachSVG_1.attachSVG)(system);
    (0, attachHTML_1.attachHTML)(system);
    (0, attachGesture_1.attachGesture)(system);
    (0, attachLongPress_1.attachLongPress)(system);
    (0, attachLayout_1.attachLayout)(system);
    (0, attachVoid_1.attachVoid)(system);
    // attachFocus(system)
    const unlisten = () => { };
    return [system, unlisten];
}
//# sourceMappingURL=boot.js.map