import { h } from "@stencil/core";
export class TextRenderer {
    /**
     * 要渲染的文本内容
     */
    content = '';
    /**
     * 是否保留换行符
     */
    preserveWhitespace = true;
    /**
     * 是否支持链接自动识别
     */
    autoLink = true;
    /**
     * 是否支持代码高亮
     */
    highlightCode = false;
    formatText(text) {
        if (!text)
            return '';
        let formattedText = text;
        // 处理换行符
        if (this.preserveWhitespace) {
            formattedText = formattedText.replace(/\n/g, '<br>');
        }
        // 自动识别链接
        if (this.autoLink) {
            const urlRegex = /(https?:\/\/[^\s]+)/g;
            formattedText = formattedText.replace(urlRegex, '<a href="$1" target="_blank" rel="noopener noreferrer">$1</a>');
        }
        // 处理代码块
        if (this.highlightCode) {
            const codeBlockRegex = /```([\s\S]*?)```/g;
            formattedText = formattedText.replace(codeBlockRegex, '<pre><code>$1</code></pre>');
            const inlineCodeRegex = /`([^`]+)`/g;
            formattedText = formattedText.replace(inlineCodeRegex, '<code>$1</code>');
        }
        return formattedText;
    }
    render() {
        const formattedContent = this.formatText(this.content);
        return (h("div", { key: 'd0c58038fa8cc5da57d72420ac4e3ea87ed1a080', class: "text-renderer", innerHTML: formattedContent }));
    }
    static get is() { return "text-renderer"; }
    static get encapsulation() { return "shadow"; }
    static get originalStyleUrls() {
        return {
            "$": ["text-renderer.css"]
        };
    }
    static get styleUrls() {
        return {
            "$": ["text-renderer.css"]
        };
    }
    static get properties() {
        return {
            "content": {
                "type": "string",
                "attribute": "content",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "\u8981\u6E32\u67D3\u7684\u6587\u672C\u5185\u5BB9"
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "defaultValue": "''"
            },
            "preserveWhitespace": {
                "type": "boolean",
                "attribute": "preserve-whitespace",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "\u662F\u5426\u4FDD\u7559\u6362\u884C\u7B26"
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "defaultValue": "true"
            },
            "autoLink": {
                "type": "boolean",
                "attribute": "auto-link",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "\u662F\u5426\u652F\u6301\u94FE\u63A5\u81EA\u52A8\u8BC6\u522B"
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "defaultValue": "true"
            },
            "highlightCode": {
                "type": "boolean",
                "attribute": "highlight-code",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "\u662F\u5426\u652F\u6301\u4EE3\u7801\u9AD8\u4EAE"
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "defaultValue": "false"
            }
        };
    }
}
//# sourceMappingURL=text-renderer.js.map
