Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const require_runtime = require("../../_virtual/_rolldown/runtime.cjs");
const require_safe_custom_element = require("../../shared/safe-custom-element.cjs");
const require_index = require("../../shared/tailwind-element/index.cjs");
const require_decorate = require("../../_virtual/_@oxc-project_runtime@0.127.0/helpers/decorate.cjs");
const require_components_lukso_sanitize_index = require("../lukso-sanitize/index.cjs");
const require_style = require("./style.css?inline.cjs");
let lit = require("lit");
let lit_decorators_js = require("lit/decorators.js");
let dompurify = require("dompurify");
dompurify = require_runtime.__toESM(dompurify, 1);
let marked = require("marked");
//#region src/components/lukso-markdown/index.ts
var LuksoMarkdown = class LuksoMarkdown extends require_index.TailwindStyledElement(require_style.default) {
	constructor(..._args) {
		super(..._args);
		this.value = "";
		this.isPre = false;
		this.proseClasses = "prose prose-base prose-inherit";
		this.customStyle = "";
		this.stripHtmlTags = false;
	}
	/**
	* Convert markdown to HTML using marked library
	*/
	convertMarkdownToHtml() {
		if (!this.value) return "";
		try {
			let content = this.value;
			if (this.stripHtmlTags) content = dompurify.default.sanitize(this.value, require_components_lukso_sanitize_index.NO_HTML_TAGS_OPTIONS);
			const processedMarkdown = this.preprocessNestedLists(content);
			marked.marked.setOptions({
				gfm: true,
				breaks: false
			});
			return (0, marked.marked)(processedMarkdown);
		} catch (error) {
			console.error("Error parsing markdown:", error);
			return "";
		}
	}
	/**
	* Preprocess markdown to handle nested lists with various indentation
	* by normalizing to CommonMark-compliant 4-space indentation
	*/
	preprocessNestedLists(markdown) {
		const lines = markdown.split("\n");
		const result = [];
		for (const line of lines) {
			const listMatch = line.match(/^(\s*)((?:\d+\.)|[-*+])\s+(.*)$/);
			if (listMatch) {
				const originalIndent = listMatch[1];
				const marker = listMatch[2];
				const content = listMatch[3];
				let nestingLevel = 0;
				if (originalIndent.length >= 2) {
					nestingLevel = Math.max(1, Math.floor(originalIndent.length / 4));
					if (originalIndent.length >= 2 && originalIndent.length < 4) nestingLevel = 1;
				}
				const newIndent = "    ".repeat(nestingLevel);
				result.push(`${newIndent}${marker} ${content}`);
			} else result.push(line);
		}
		return result.join("\n");
	}
	render() {
		const htmlContent = this.convertMarkdownToHtml();
		return lit.html`
      <lukso-sanitize
        html-content="<div class='flex flex-col ${this.proseClasses}' style='${this.customStyle}'>${htmlContent}</div>"
        ?is-pre="${this.isPre}"
        class="w-full"
      ></lukso-sanitize>
    `;
	}
};
require_decorate.__decorate([(0, lit_decorators_js.property)({ type: String })], LuksoMarkdown.prototype, "value", void 0);
require_decorate.__decorate([(0, lit_decorators_js.property)({
	type: Boolean,
	attribute: "is-pre",
	reflect: true
})], LuksoMarkdown.prototype, "isPre", void 0);
require_decorate.__decorate([(0, lit_decorators_js.property)({
	type: String,
	attribute: "prose-classes",
	reflect: true
})], LuksoMarkdown.prototype, "proseClasses", void 0);
require_decorate.__decorate([(0, lit_decorators_js.property)({
	type: String,
	attribute: "custom-style",
	reflect: true
})], LuksoMarkdown.prototype, "customStyle", void 0);
require_decorate.__decorate([(0, lit_decorators_js.property)({
	type: Boolean,
	attribute: "strip-html-tags"
})], LuksoMarkdown.prototype, "stripHtmlTags", void 0);
LuksoMarkdown = require_decorate.__decorate([require_safe_custom_element.safeCustomElement("lukso-markdown")], LuksoMarkdown);
//#endregion
Object.defineProperty(exports, "LuksoMarkdown", {
	enumerable: true,
	get: function() {
		return LuksoMarkdown;
	}
});
