import { ActiveLinkHighlighter } from "../content/ActiveLinkHighlighter.js";
import { TableOfContentsBuilder } from "../content/TableOfContentsBuilder.js";
import { AsideHandler } from "../elements/AsideHandler.js";
import { CollapsibleTableHandler } from "../elements/CollapsibleTableHandler.js";
import { DetailManager } from "../elements/DetailManager.js";
import { DropdownHandler } from "../elements/DropdownHandler.js";
import { ExclusiveDetails } from "../elements/ExclusiveDetails.js";
import { PasswordToggleManager } from "../elements/PasswordToggleManager.js";
import { ImageCompareSlider } from "../media/ImageCompareSlider.js";
import { ScrollElementManager } from "../scroll/ScrollElementManager.js";
import { ScrollPageManager } from "../scroll/ScrollPageManager.js";
import { AccordionState } from "../storage/AccordionState.js";
import { ClipboardHelper } from "../utilities/ClipboardHelper.js";
import { FontPreview } from "../utilities/FontPreview.js";
import { GridManager } from "../utilities/GridManager.js";
import { ThemeToggler } from "../utilities/ThemeToggler.js";
import { autoStart, destroy, getAllInstances, getInstance, init, observe, reinit, setAttributePrefix, setAutoInit, setDebug, setObserver, stopObserving, } from "./autoInit.js";
import { componentRegistry, getComponent, getComponentNames, hasComponent, registerComponent, } from "./registry.js";
export { autoStart, componentRegistry, destroy, getAllInstances, getComponent, getComponentNames, getInstance, hasComponent, init, observe, registerComponent, reinit, setAttributePrefix, setAutoInit, setDebug, setObserver, stopObserving, };
function createGlobal() {
    let autoInitEnabled = true;
    let debugEnabled = false;
    const stylescape = {
        init,
        getInstance,
        getAllInstances,
        reinit,
        destroy,
        observe,
        stopObserving,
        get autoInit() {
            return autoInitEnabled;
        },
        set autoInit(value) {
            autoInitEnabled = value;
            setAutoInit(value);
        },
        get debug() {
            return debugEnabled;
        },
        set debug(value) {
            debugEnabled = value;
            setDebug(value);
        },
        registerComponent,
        hasComponent,
        getComponentNames,
        version: "1.0.0",
    };
    return stylescape;
}
if (typeof window !== "undefined") {
    window.Stylescape = createGlobal();
    window.ClipboardHelper = ClipboardHelper;
}
export function initializeStylescape() {
    document.addEventListener("DOMContentLoaded", () => {
        init();
        observe();
        new ScrollPageManager();
        new ScrollElementManager("#main_content", "main_content_scroll", false);
        new ScrollElementManager("#sidebar_left_content", "sidebar_left_content_scroll", false);
        new ActiveLinkHighlighter();
        new PasswordToggleManager();
        ThemeToggler.registerOnLoad("themeToggle");
        const tocBuilder = new TableOfContentsBuilder("main_content", "toc");
        tocBuilder.buildAndAppendTOC();
        new ExclusiveDetails(".ribbon_menu_button");
        new DetailManager();
        new AccordionState("details.sidebar__accordion", "sidebar-accordion-state");
        const current = location.pathname.split("/").pop();
        const activeLink = document.querySelector(`a[href$="${current}"]`);
        if (activeLink) {
            activeLink.classList.add("active");
        }
        const handlers = [];
        document.querySelectorAll("[id$='_switch']").forEach((switchEl) => {
            const switchId = switchEl.id;
            const menuId = switchId.replace("_switch", "_menu");
            const menuEl = document.getElementById(menuId);
            if (menuEl) {
                handlers.push(new AsideHandler(menuId, switchId));
            }
        });
        window.asideHandlers = handlers;
        ImageCompareSlider.initAll();
        new DropdownHandler();
        new CollapsibleTableHandler();
        const fontPreviewInput = document.querySelector("#font-preview-input");
        if (fontPreviewInput) {
            try {
                new FontPreview("#font-preview-input", ".preview__font--output");
            }
            catch (_e) {
            }
        }
    });
    window.addEventListener("load", () => {
        requestAnimationFrame(() => {
            new GridManager();
        });
    });
}
if (typeof document !== "undefined") {
    const scriptTag = document.currentScript;
    const shouldSkipAutoStart = scriptTag?.hasAttribute("data-ss-no-auto") ||
        window
            .STYLESCAPE_AUTO_INIT === false;
    if (!shouldSkipAutoStart) {
        autoStart();
    }
}
//# sourceMappingURL=index.js.map