// #region Imports
// #endregion
/**
 * A lightweight container that preserves Shadow DOM styles for elements
 * that are temporarily moved outside their original Shadow Root during drag operations.
 *
 * @description
 * When an element inside a Shadow DOM (e.g. a `[part='item']` inside `<mosaik-table-column-editor>`)
 * is moved to `document.body` for `position: fixed` dragging, it loses all scoped styles from its
 * host's Shadow Root. This container solves that by creating a temporary Shadow Root on `document.body`
 * and adopting the same `CSSStyleSheet` instances from the source Shadow Root.
 *
 * The element is placed **directly** in the new Shadow Tree (not slotted), so attribute selectors
 * like `[part='item']` continue to match. The Shadow Root also ensures full style isolation —
 * no styles leak in or out.
 *
 * @example
 * ```typescript
 * const container = new DragStyleContainer(sourceShadowRoot);
 * container.attach(dragElement);
 * // ... drag operation ...
 * container.dispose(); // removes container, element must be moved back before this
 * ```
 *
 * @public
 */
export class DragStyleContainer {
    // #region Fields
    _host;
    _shadowRoot;
    // #endregion
    // #region Ctor
    /**
     * Creates a new DragStyleContainer that adopts styles from the given source Shadow Root.
     *
     * @param source - The Shadow Root whose `adoptedStyleSheets` should be inherited.
     *
     * @public
     */
    constructor(source) {
        this._host = document.createElement('div');
        this._host.style.position = 'fixed';
        this._host.style.top = '0';
        this._host.style.left = '0';
        this._host.style.width = '0';
        this._host.style.height = '0';
        this._host.style.overflow = 'visible';
        this._host.style.pointerEvents = 'none';
        this._host.style.zIndex = '9999';
        this._host.setAttribute('data-drag-style-container', '');
        this._shadowRoot = this._host.attachShadow({ mode: 'open' });
        this._shadowRoot.adoptedStyleSheets = [...source.adoptedStyleSheets];
        document.body.appendChild(this._host);
    }
    // #endregion
    // #region Properties
    /**
     * Gets the Shadow Root of this container.
     * Use this to append drag elements into the styled scope.
     *
     * @public
     * @readonly
     */
    get root() {
        if (!this._shadowRoot) {
            throw new Error('[DragStyleContainer] Container has been disposed.');
        }
        return this._shadowRoot;
    }
    // #endregion
    // #region Methods
    /**
     * Appends an element into the styled Shadow Root.
     *
     * @param element - The element to place inside the container.
     *
     * @public
     */
    attach(element) {
        if (!this._shadowRoot) {
            throw new Error('[DragStyleContainer] Container has been disposed.');
        }
        this._shadowRoot.appendChild(element);
    }
    /**
     * Removes the container and its Shadow Root from the DOM.
     *
     * @remarks
     * The caller is responsible for moving any child elements back to their
     * original DOM position **before** calling dispose.
     *
     * @public
     */
    dispose() {
        if (this._host?.isConnected) {
            this._host.remove();
        }
        this._shadowRoot = null;
        this._host = null;
    }
}
//# sourceMappingURL=DragStyleContainer.js.map