import { proxyCustomElement, HTMLElement, h, Host } from '@stencil/core/internal/client';

const XCopy$1 = /*@__PURE__*/ proxyCustomElement(class XCopy extends HTMLElement {
    constructor() {
        super();
        this.__registerHost();
        this.content = undefined;
    }
    /**
     * Copy the content to clipboard
     *
     * @returns
     */
    copyContent() {
        if (!navigator.clipboard) {
            this.fallbackCopyTextToClipboard();
            return;
        }
        navigator.clipboard
            .writeText(this.content)
            .then(() => { }, err => {
            console.warn(err);
        });
    }
    /**
     * Fallback for copy text
     */
    fallbackCopyTextToClipboard() {
        const textArea = document.createElement("textarea");
        textArea.value = this.content;
        textArea.style.top = "0";
        textArea.style.left = "0";
        textArea.style.position = "fixed";
        document.body.appendChild(textArea);
        textArea.focus();
        textArea.select();
        try {
            document.execCommand('copy');
        }
        catch (err) {
            console.warn(err);
        }
        document.body.removeChild(textArea);
    }
    /**
     * Render element
     */
    render() {
        return h(Host, { key: '4878b251d70673186652db1a139dfaa42484e0fe', onClick: this.copyContent }, h("slot", { key: 'ec847c0c6ed3e915df80d3bf12976f150053b228' }));
    }
}, [4, "x-copy", {
        "content": [1]
    }]);
function defineCustomElement$1() {
    if (typeof customElements === "undefined") {
        return;
    }
    const components = ["x-copy"];
    components.forEach(tagName => { switch (tagName) {
        case "x-copy":
            if (!customElements.get(tagName)) {
                customElements.define(tagName, XCopy$1);
            }
            break;
    } });
}

const XCopy = XCopy$1;
const defineCustomElement = defineCustomElement$1;

export { XCopy, defineCustomElement };
