UNPKG

bpmn-js-markdown-documentation-panel

Version:

A comprehensive documentation management plugin for Camunda Modeler with markdown support, element linking, and coverage tracking

3,524 lines 117 kB
//#region ../../node_modules/.pnpm/camunda-modeler-plugin-helpers@5.1.0/node_modules/camunda-modeler-plugin-helpers/index.js
/**
* Validate and register a client plugin.
*
* @param {Object} plugin
* @param {String} type
*/
function registerClientPlugin(plugin, type) {
	var plugins = window.plugins || [];
	window.plugins = plugins;
	if (!plugin) throw new Error("plugin not specified");
	if (!type) throw new Error("type not specified");
	plugins.push({
		plugin,
		type
	});
}
/**
* Validate and register a bpmn-js plugin.
*
* @param {Object} module
*
* @example
*
* import {
*   registerBpmnJSPlugin
* } from 'camunda-modeler-plugin-helpers';
*
* const BpmnJSModule = {
*   __init__: [ 'myService' ],
*   myService: [ 'type', ... ]
* };
*
* registerBpmnJSPlugin(BpmnJSModule);
*/
function registerBpmnJSPlugin(module$1) {
	registerClientPlugin(module$1, "bpmn.modeler.additionalModules");
}

//#endregion
//#region ../../node_modules/.pnpm/bpmn-js@13.2.2/node_modules/bpmn-js/lib/util/ModelUtil.js
/**
* @typedef { import('../model/Types').Element } Element
* @typedef { import('../model/Types').ModdleElement } ModdleElement
*/
/**
* Is an element of the given BPMN type?
*
* @param  {Element|ModdleElement} element
* @param  {string} type
*
* @return {boolean}
*/
function is(element, type) {
	var bo = getBusinessObject(element);
	return bo && typeof bo.$instanceOf === "function" && bo.$instanceOf(type);
}
/**
* Return the business object for a given element.
*
* @param {Element|ModdleElement} element
*
* @return {ModdleElement}
*/
function getBusinessObject(element) {
	return element && element.businessObject || element;
}

//#endregion
//#region ../../node_modules/.pnpm/marked@16.0.0/node_modules/marked/lib/marked.esm.js
/**
* marked v16.0.0 - a markdown parser
* Copyright (c) 2011-2025, Christopher Jeffrey. (MIT Licensed)
* https://github.com/markedjs/marked
*/
/**
* DO NOT EDIT THIS FILE
* The code in this file is generated from files in ./src/
*/
function M() {
	return {
		async: !1,
		breaks: !1,
		extensions: null,
		gfm: !0,
		hooks: null,
		pedantic: !1,
		renderer: null,
		silent: !1,
		tokenizer: null,
		walkTokens: null
	};
}
var w = M();
function H(a) {
	w = a;
}
var C = { exec: () => null };
function h(a, e = "") {
	let t = typeof a == "string" ? a : a.source, n = {
		replace: (s, i) => {
			let r = typeof i == "string" ? i : i.source;
			return r = r.replace(m.caret, "$1"), t = t.replace(s, r), n;
		},
		getRegex: () => new RegExp(t, e)
	};
	return n;
}
var m = {
	codeRemoveIndent: /^(?: {1,4}| {0,3}\t)/gm,
	outputLinkReplace: /\\([\[\]])/g,
	indentCodeCompensation: /^(\s+)(?:```)/,
	beginningSpace: /^\s+/,
	endingHash: /#$/,
	startingSpaceChar: /^ /,
	endingSpaceChar: / $/,
	nonSpaceChar: /[^ ]/,
	newLineCharGlobal: /\n/g,
	tabCharGlobal: /\t/g,
	multipleSpaceGlobal: /\s+/g,
	blankLine: /^[ \t]*$/,
	doubleBlankLine: /\n[ \t]*\n[ \t]*$/,
	blockquoteStart: /^ {0,3}>/,
	blockquoteSetextReplace: /\n {0,3}((?:=+|-+) *)(?=\n|$)/g,
	blockquoteSetextReplace2: /^ {0,3}>[ \t]?/gm,
	listReplaceTabs: /^\t+/,
	listReplaceNesting: /^ {1,4}(?=( {4})*[^ ])/g,
	listIsTask: /^\[[ xX]\] /,
	listReplaceTask: /^\[[ xX]\] +/,
	anyLine: /\n.*\n/,
	hrefBrackets: /^<(.*)>$/,
	tableDelimiter: /[:|]/,
	tableAlignChars: /^\||\| *$/g,
	tableRowBlankLine: /\n[ \t]*$/,
	tableAlignRight: /^ *-+: *$/,
	tableAlignCenter: /^ *:-+: *$/,
	tableAlignLeft: /^ *:-+ *$/,
	startATag: /^<a /i,
	endATag: /^<\/a>/i,
	startPreScriptTag: /^<(pre|code|kbd|script)(\s|>)/i,
	endPreScriptTag: /^<\/(pre|code|kbd|script)(\s|>)/i,
	startAngleBracket: /^</,
	endAngleBracket: />$/,
	pedanticHrefTitle: /^([^'"]*[^\s])\s+(['"])(.*)\2/,
	unicodeAlphaNumeric: /[\p{L}\p{N}]/u,
	escapeTest: /[&<>"']/,
	escapeReplace: /[&<>"']/g,
	escapeTestNoEncode: /[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,
	escapeReplaceNoEncode: /[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/g,
	unescapeTest: /&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/gi,
	caret: /(^|[^\[])\^/g,
	percentDecode: /%25/g,
	findPipe: /\|/g,
	splitPipe: / \|/,
	slashPipe: /\\\|/g,
	carriageReturn: /\r\n|\r/g,
	spaceLine: /^ +$/gm,
	notSpaceStart: /^\S*/,
	endingNewline: /\n$/,
	listItemRegex: (a) => /* @__PURE__ */ new RegExp(`^( {0,3}${a})((?:[	 ][^\\n]*)?(?:\\n|$))`),
	nextBulletRegex: (a) => /* @__PURE__ */ new RegExp(`^ {0,${Math.min(3, a - 1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ 	][^\\n]*)?(?:\\n|$))`),
	hrRegex: (a) => /* @__PURE__ */ new RegExp(`^ {0,${Math.min(3, a - 1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`),
	fencesBeginRegex: (a) => /* @__PURE__ */ new RegExp(`^ {0,${Math.min(3, a - 1)}}(?:\`\`\`|~~~)`),
	headingBeginRegex: (a) => /* @__PURE__ */ new RegExp(`^ {0,${Math.min(3, a - 1)}}#`),
	htmlBeginRegex: (a) => new RegExp(`^ {0,${Math.min(3, a - 1)}}<(?:[a-z].*>|!--)`, "i")
}, xe = /^(?:[ \t]*(?:\n|$))+/, be = /^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/, Te = /^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/, I = /^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/, we = /^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/, j = /(?:[*+-]|\d{1,9}[.)])/, re = /^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/, ie = h(re).replace(/bull/g, j).replace(/blockCode/g, /(?: {4}| {0,3}\t)/).replace(/fences/g, / {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g, / {0,3}>/).replace(/heading/g, / {0,3}#{1,6}/).replace(/html/g, / {0,3}<[^\n>]+>\n/).replace(/\|table/g, "").getRegex(), ye = h(re).replace(/bull/g, j).replace(/blockCode/g, /(?: {4}| {0,3}\t)/).replace(/fences/g, / {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g, / {0,3}>/).replace(/heading/g, / {0,3}#{1,6}/).replace(/html/g, / {0,3}<[^\n>]+>\n/).replace(/table/g, / {0,3}\|?(?:[:\- ]*\|)+[\:\- ]*\n/).getRegex(), F = /^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/, Re = /^[^\n]+/, Q = /(?!\s*\])(?:\\.|[^\[\]\\])+/, Se = h(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label", Q).replace("title", /(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(), $e = h(/^( {0,3}bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g, j).getRegex(), v = "address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|search|section|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul", U = /<!--(?:-?>|[\s\S]*?(?:-->|$))/, _e = h("^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>\\n*|$)|<![A-Z][\\s\\S]*?(?:>\\n*|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>\\n*|$)|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n[ 	]*)+\\n|$)|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ 	]*)+\\n|$)|</(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ 	]*)+\\n|$))", "i").replace("comment", U).replace("tag", v).replace("attribute", / +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(), oe = h(F).replace("hr", I).replace("heading", " {0,3}#{1,6}(?:\\s|$)").replace("|lheading", "").replace("|table", "").replace("blockquote", " {0,3}>").replace("fences", " {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list", " {0,3}(?:[*+-]|1[.)]) ").replace("html", "</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag", v).getRegex(), Le = h(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph", oe).getRegex(), K = {
	blockquote: Le,
	code: be,
	def: Se,
	fences: Te,
	heading: we,
	hr: I,
	html: _e,
	lheading: ie,
	list: $e,
	newline: xe,
	paragraph: oe,
	table: C,
	text: Re
}, se = h("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr", I).replace("heading", " {0,3}#{1,6}(?:\\s|$)").replace("blockquote", " {0,3}>").replace("code", "(?: {4}| {0,3}	)[^\\n]").replace("fences", " {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list", " {0,3}(?:[*+-]|1[.)]) ").replace("html", "</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag", v).getRegex(), ze = {
	...K,
	lheading: ye,
	table: se,
	paragraph: h(F).replace("hr", I).replace("heading", " {0,3}#{1,6}(?:\\s|$)").replace("|lheading", "").replace("table", se).replace("blockquote", " {0,3}>").replace("fences", " {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list", " {0,3}(?:[*+-]|1[.)]) ").replace("html", "</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag", v).getRegex()
}, Me = {
	...K,
	html: h(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment", U).replace(/tag/g, "(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b").getRegex(),
	def: /^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,
	heading: /^(#{1,6})(.*)(?:\n+|$)/,
	fences: C,
	lheading: /^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,
	paragraph: h(F).replace("hr", I).replace("heading", ` *#{1,6} *[^
]`).replace("lheading", ie).replace("|table", "").replace("blockquote", " {0,3}>").replace("|fences", "").replace("|list", "").replace("|html", "").replace("|tag", "").getRegex()
}, Pe = /^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/, Ae = /^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/, le = /^( {2,}|\\)\n(?!\s*$)/, Ee = /^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/, D = /[\p{P}\p{S}]/u, X = /[\s\p{P}\p{S}]/u, ae = /[^\s\p{P}\p{S}]/u, Ce = h(/^((?![*_])punctSpace)/, "u").replace(/punctSpace/g, X).getRegex(), ce = /(?!~)[\p{P}\p{S}]/u, Ie = /(?!~)[\s\p{P}\p{S}]/u, Oe = /(?:[^\s\p{P}\p{S}]|~)/u, Be = /\[[^[\]]*?\]\((?:\\.|[^\\\(\)]|\((?:\\.|[^\\\(\)])*\))*\)|`[^`]*?`|<[^<>]*?>/g, pe = /^(?:\*+(?:((?!\*)punct)|[^\s*]))|^_+(?:((?!_)punct)|([^\s_]))/, qe = h(pe, "u").replace(/punct/g, D).getRegex(), ve = h(pe, "u").replace(/punct/g, ce).getRegex(), ue = "^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)", De = h(ue, "gu").replace(/notPunctSpace/g, ae).replace(/punctSpace/g, X).replace(/punct/g, D).getRegex(), Ze = h(ue, "gu").replace(/notPunctSpace/g, Oe).replace(/punctSpace/g, Ie).replace(/punct/g, ce).getRegex(), Ge = h("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)", "gu").replace(/notPunctSpace/g, ae).replace(/punctSpace/g, X).replace(/punct/g, D).getRegex(), He = h(/\\(punct)/, "gu").replace(/punct/g, D).getRegex(), Ne = h(/^<(scheme:[^\s\x00-\x1f<>]*|email)>/).replace("scheme", /[a-zA-Z][a-zA-Z0-9+.-]{1,31}/).replace("email", /[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+(@)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(?![-_])/).getRegex(), je = h(U).replace("(?:-->|$)", "-->").getRegex(), Fe = h("^comment|^</[a-zA-Z][\\w:-]*\\s*>|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>|^<\\?[\\s\\S]*?\\?>|^<![a-zA-Z]+\\s[\\s\\S]*?>|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>").replace("comment", je).replace("attribute", /\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(), q = /(?:\[(?:\\.|[^\[\]\\])*\]|\\.|`[^`]*`|[^\[\]\\`])*?/, Qe = h(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]*(?:\n[ \t]*)?)(title))?\s*\)/).replace("label", q).replace("href", /<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]*/).replace("title", /"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(), he = h(/^!?\[(label)\]\[(ref)\]/).replace("label", q).replace("ref", Q).getRegex(), ke = h(/^!?\[(ref)\](?:\[\])?/).replace("ref", Q).getRegex(), Ue = h("reflink|nolink(?!\\()", "g").replace("reflink", he).replace("nolink", ke).getRegex(), W = {
	_backpedal: C,
	anyPunctuation: He,
	autolink: Ne,
	blockSkip: Be,
	br: le,
	code: Ae,
	del: C,
	emStrongLDelim: qe,
	emStrongRDelimAst: De,
	emStrongRDelimUnd: Ge,
	escape: Pe,
	link: Qe,
	nolink: ke,
	punctuation: Ce,
	reflink: he,
	reflinkSearch: Ue,
	tag: Fe,
	text: Ee,
	url: C
}, Ke = {
	...W,
	link: h(/^!?\[(label)\]\((.*?)\)/).replace("label", q).getRegex(),
	reflink: h(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label", q).getRegex()
}, N = {
	...W,
	emStrongRDelimAst: Ze,
	emStrongLDelim: ve,
	url: h(/^((?:ftp|https?):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/, "i").replace("email", /[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/).getRegex(),
	_backpedal: /(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,
	del: /^(~~?)(?=[^\s~])((?:\\.|[^\\])*?(?:\\.|[^\s~\\]))\1(?=[^~]|$)/,
	text: /^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|https?:\/\/|ftp:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/
}, Xe = {
	...N,
	br: h(le).replace("{2,}", "*").getRegex(),
	text: h(N.text).replace("\\b_", "\\b_| {2,}\\n").replace(/\{2,\}/g, "*").getRegex()
}, O = {
	normal: K,
	gfm: ze,
	pedantic: Me
}, P = {
	normal: W,
	gfm: N,
	breaks: Xe,
	pedantic: Ke
};
var We = {
	"&": "&amp;",
	"<": "&lt;",
	">": "&gt;",
	"\"": "&quot;",
	"'": "&#39;"
}, ge = (a) => We[a];
function R(a, e) {
	if (e) {
		if (m.escapeTest.test(a)) return a.replace(m.escapeReplace, ge);
	} else if (m.escapeTestNoEncode.test(a)) return a.replace(m.escapeReplaceNoEncode, ge);
	return a;
}
function J(a) {
	try {
		a = encodeURI(a).replace(m.percentDecode, "%");
	} catch {
		return null;
	}
	return a;
}
function V(a, e) {
	let t = a.replace(m.findPipe, (i, r, o) => {
		let l = !1, c = r;
		for (; --c >= 0 && o[c] === "\\";) l = !l;
		return l ? "|" : " |";
	}), n = t.split(m.splitPipe), s = 0;
	if (n[0].trim() || n.shift(), n.length > 0 && !n.at(-1)?.trim() && n.pop(), e) if (n.length > e) n.splice(e);
	else for (; n.length < e;) n.push("");
	for (; s < n.length; s++) n[s] = n[s].trim().replace(m.slashPipe, "|");
	return n;
}
function A(a, e, t) {
	let n = a.length;
	if (n === 0) return "";
	let s = 0;
	for (; s < n;) {
		let i = a.charAt(n - s - 1);
		if (i === e && !t) s++;
		else if (i !== e && t) s++;
		else break;
	}
	return a.slice(0, n - s);
}
function fe(a, e) {
	if (a.indexOf(e[1]) === -1) return -1;
	let t = 0;
	for (let n = 0; n < a.length; n++) if (a[n] === "\\") n++;
	else if (a[n] === e[0]) t++;
	else if (a[n] === e[1] && (t--, t < 0)) return n;
	return t > 0 ? -2 : -1;
}
function de(a, e, t, n, s) {
	let i = e.href, r = e.title || null, o = a[1].replace(s.other.outputLinkReplace, "$1");
	n.state.inLink = !0;
	let l = {
		type: a[0].charAt(0) === "!" ? "image" : "link",
		raw: t,
		href: i,
		title: r,
		text: o,
		tokens: n.inlineTokens(o)
	};
	return n.state.inLink = !1, l;
}
function Je(a, e, t) {
	let n = a.match(t.other.indentCodeCompensation);
	if (n === null) return e;
	let s = n[1];
	return e.split(`
`).map((i) => {
		let r = i.match(t.other.beginningSpace);
		if (r === null) return i;
		let [o] = r;
		return o.length >= s.length ? i.slice(s.length) : i;
	}).join(`
`);
}
var S = class {
	options;
	rules;
	lexer;
	constructor(e) {
		this.options = e || w;
	}
	space(e) {
		let t = this.rules.block.newline.exec(e);
		if (t && t[0].length > 0) return {
			type: "space",
			raw: t[0]
		};
	}
	code(e) {
		let t = this.rules.block.code.exec(e);
		if (t) {
			let n = t[0].replace(this.rules.other.codeRemoveIndent, "");
			return {
				type: "code",
				raw: t[0],
				codeBlockStyle: "indented",
				text: this.options.pedantic ? n : A(n, `
`)
			};
		}
	}
	fences(e) {
		let t = this.rules.block.fences.exec(e);
		if (t) {
			let n = t[0], s = Je(n, t[3] || "", this.rules);
			return {
				type: "code",
				raw: n,
				lang: t[2] ? t[2].trim().replace(this.rules.inline.anyPunctuation, "$1") : t[2],
				text: s
			};
		}
	}
	heading(e) {
		let t = this.rules.block.heading.exec(e);
		if (t) {
			let n = t[2].trim();
			if (this.rules.other.endingHash.test(n)) {
				let s = A(n, "#");
				(this.options.pedantic || !s || this.rules.other.endingSpaceChar.test(s)) && (n = s.trim());
			}
			return {
				type: "heading",
				raw: t[0],
				depth: t[1].length,
				text: n,
				tokens: this.lexer.inline(n)
			};
		}
	}
	hr(e) {
		let t = this.rules.block.hr.exec(e);
		if (t) return {
			type: "hr",
			raw: A(t[0], `
`)
		};
	}
	blockquote(e) {
		let t = this.rules.block.blockquote.exec(e);
		if (t) {
			let n = A(t[0], `
`).split(`
`), s = "", i = "", r = [];
			for (; n.length > 0;) {
				let o = !1, l = [], c;
				for (c = 0; c < n.length; c++) if (this.rules.other.blockquoteStart.test(n[c])) l.push(n[c]), o = !0;
				else if (!o) l.push(n[c]);
				else break;
				n = n.slice(c);
				let p = l.join(`
`), u = p.replace(this.rules.other.blockquoteSetextReplace, `
    $1`).replace(this.rules.other.blockquoteSetextReplace2, "");
				s = s ? `${s}
${p}` : p, i = i ? `${i}
${u}` : u;
				let d = this.lexer.state.top;
				if (this.lexer.state.top = !0, this.lexer.blockTokens(u, r, !0), this.lexer.state.top = d, n.length === 0) break;
				let g = r.at(-1);
				if (g?.type === "code") break;
				if (g?.type === "blockquote") {
					let x = g, f = x.raw + `
` + n.join(`
`), y = this.blockquote(f);
					r[r.length - 1] = y, s = s.substring(0, s.length - x.raw.length) + y.raw, i = i.substring(0, i.length - x.text.length) + y.text;
					break;
				} else if (g?.type === "list") {
					let x = g, f = x.raw + `
` + n.join(`
`), y = this.list(f);
					r[r.length - 1] = y, s = s.substring(0, s.length - g.raw.length) + y.raw, i = i.substring(0, i.length - x.raw.length) + y.raw, n = f.substring(r.at(-1).raw.length).split(`
`);
					continue;
				}
			}
			return {
				type: "blockquote",
				raw: s,
				tokens: r,
				text: i
			};
		}
	}
	list(e) {
		let t = this.rules.block.list.exec(e);
		if (t) {
			let n = t[1].trim(), s = n.length > 1, i = {
				type: "list",
				raw: "",
				ordered: s,
				start: s ? +n.slice(0, -1) : "",
				loose: !1,
				items: []
			};
			n = s ? `\\d{1,9}\\${n.slice(-1)}` : `\\${n}`, this.options.pedantic && (n = s ? n : "[*+-]");
			let r = this.rules.other.listItemRegex(n), o = !1;
			for (; e;) {
				let c = !1, p = "", u = "";
				if (!(t = r.exec(e)) || this.rules.block.hr.test(e)) break;
				p = t[0], e = e.substring(p.length);
				let d = t[2].split(`
`, 1)[0].replace(this.rules.other.listReplaceTabs, (Z) => " ".repeat(3 * Z.length)), g = e.split(`
`, 1)[0], x = !d.trim(), f = 0;
				if (this.options.pedantic ? (f = 2, u = d.trimStart()) : x ? f = t[1].length + 1 : (f = t[2].search(this.rules.other.nonSpaceChar), f = f > 4 ? 1 : f, u = d.slice(f), f += t[1].length), x && this.rules.other.blankLine.test(g) && (p += g + `
`, e = e.substring(g.length + 1), c = !0), !c) {
					let Z = this.rules.other.nextBulletRegex(f), ee = this.rules.other.hrRegex(f), te = this.rules.other.fencesBeginRegex(f), ne = this.rules.other.headingBeginRegex(f), me = this.rules.other.htmlBeginRegex(f);
					for (; e;) {
						let G = e.split(`
`, 1)[0], E;
						if (g = G, this.options.pedantic ? (g = g.replace(this.rules.other.listReplaceNesting, "  "), E = g) : E = g.replace(this.rules.other.tabCharGlobal, "    "), te.test(g) || ne.test(g) || me.test(g) || Z.test(g) || ee.test(g)) break;
						if (E.search(this.rules.other.nonSpaceChar) >= f || !g.trim()) u += `
` + E.slice(f);
						else {
							if (x || d.replace(this.rules.other.tabCharGlobal, "    ").search(this.rules.other.nonSpaceChar) >= 4 || te.test(d) || ne.test(d) || ee.test(d)) break;
							u += `
` + g;
						}
						!x && !g.trim() && (x = !0), p += G + `
`, e = e.substring(G.length + 1), d = E.slice(f);
					}
				}
				i.loose || (o ? i.loose = !0 : this.rules.other.doubleBlankLine.test(p) && (o = !0));
				let y = null, Y;
				this.options.gfm && (y = this.rules.other.listIsTask.exec(u), y && (Y = y[0] !== "[ ] ", u = u.replace(this.rules.other.listReplaceTask, ""))), i.items.push({
					type: "list_item",
					raw: p,
					task: !!y,
					checked: Y,
					loose: !1,
					text: u,
					tokens: []
				}), i.raw += p;
			}
			let l = i.items.at(-1);
			if (l) l.raw = l.raw.trimEnd(), l.text = l.text.trimEnd();
			else return;
			i.raw = i.raw.trimEnd();
			for (let c = 0; c < i.items.length; c++) if (this.lexer.state.top = !1, i.items[c].tokens = this.lexer.blockTokens(i.items[c].text, []), !i.loose) {
				let p = i.items[c].tokens.filter((d) => d.type === "space"), u = p.length > 0 && p.some((d) => this.rules.other.anyLine.test(d.raw));
				i.loose = u;
			}
			if (i.loose) for (let c = 0; c < i.items.length; c++) i.items[c].loose = !0;
			return i;
		}
	}
	html(e) {
		let t = this.rules.block.html.exec(e);
		if (t) return {
			type: "html",
			block: !0,
			raw: t[0],
			pre: t[1] === "pre" || t[1] === "script" || t[1] === "style",
			text: t[0]
		};
	}
	def(e) {
		let t = this.rules.block.def.exec(e);
		if (t) {
			let n = t[1].toLowerCase().replace(this.rules.other.multipleSpaceGlobal, " "), s = t[2] ? t[2].replace(this.rules.other.hrefBrackets, "$1").replace(this.rules.inline.anyPunctuation, "$1") : "", i = t[3] ? t[3].substring(1, t[3].length - 1).replace(this.rules.inline.anyPunctuation, "$1") : t[3];
			return {
				type: "def",
				tag: n,
				raw: t[0],
				href: s,
				title: i
			};
		}
	}
	table(e) {
		let t = this.rules.block.table.exec(e);
		if (!t || !this.rules.other.tableDelimiter.test(t[2])) return;
		let n = V(t[1]), s = t[2].replace(this.rules.other.tableAlignChars, "").split("|"), i = t[3]?.trim() ? t[3].replace(this.rules.other.tableRowBlankLine, "").split(`
`) : [], r = {
			type: "table",
			raw: t[0],
			header: [],
			align: [],
			rows: []
		};
		if (n.length === s.length) {
			for (let o of s) this.rules.other.tableAlignRight.test(o) ? r.align.push("right") : this.rules.other.tableAlignCenter.test(o) ? r.align.push("center") : this.rules.other.tableAlignLeft.test(o) ? r.align.push("left") : r.align.push(null);
			for (let o = 0; o < n.length; o++) r.header.push({
				text: n[o],
				tokens: this.lexer.inline(n[o]),
				header: !0,
				align: r.align[o]
			});
			for (let o of i) r.rows.push(V(o, r.header.length).map((l, c) => ({
				text: l,
				tokens: this.lexer.inline(l),
				header: !1,
				align: r.align[c]
			})));
			return r;
		}
	}
	lheading(e) {
		let t = this.rules.block.lheading.exec(e);
		if (t) return {
			type: "heading",
			raw: t[0],
			depth: t[2].charAt(0) === "=" ? 1 : 2,
			text: t[1],
			tokens: this.lexer.inline(t[1])
		};
	}
	paragraph(e) {
		let t = this.rules.block.paragraph.exec(e);
		if (t) {
			let n = t[1].charAt(t[1].length - 1) === `
` ? t[1].slice(0, -1) : t[1];
			return {
				type: "paragraph",
				raw: t[0],
				text: n,
				tokens: this.lexer.inline(n)
			};
		}
	}
	text(e) {
		let t = this.rules.block.text.exec(e);
		if (t) return {
			type: "text",
			raw: t[0],
			text: t[0],
			tokens: this.lexer.inline(t[0])
		};
	}
	escape(e) {
		let t = this.rules.inline.escape.exec(e);
		if (t) return {
			type: "escape",
			raw: t[0],
			text: t[1]
		};
	}
	tag(e) {
		let t = this.rules.inline.tag.exec(e);
		if (t) return !this.lexer.state.inLink && this.rules.other.startATag.test(t[0]) ? this.lexer.state.inLink = !0 : this.lexer.state.inLink && this.rules.other.endATag.test(t[0]) && (this.lexer.state.inLink = !1), !this.lexer.state.inRawBlock && this.rules.other.startPreScriptTag.test(t[0]) ? this.lexer.state.inRawBlock = !0 : this.lexer.state.inRawBlock && this.rules.other.endPreScriptTag.test(t[0]) && (this.lexer.state.inRawBlock = !1), {
			type: "html",
			raw: t[0],
			inLink: this.lexer.state.inLink,
			inRawBlock: this.lexer.state.inRawBlock,
			block: !1,
			text: t[0]
		};
	}
	link(e) {
		let t = this.rules.inline.link.exec(e);
		if (t) {
			let n = t[2].trim();
			if (!this.options.pedantic && this.rules.other.startAngleBracket.test(n)) {
				if (!this.rules.other.endAngleBracket.test(n)) return;
				let r = A(n.slice(0, -1), "\\");
				if ((n.length - r.length) % 2 === 0) return;
			} else {
				let r = fe(t[2], "()");
				if (r === -2) return;
				if (r > -1) {
					let l = (t[0].indexOf("!") === 0 ? 5 : 4) + t[1].length + r;
					t[2] = t[2].substring(0, r), t[0] = t[0].substring(0, l).trim(), t[3] = "";
				}
			}
			let s = t[2], i = "";
			if (this.options.pedantic) {
				let r = this.rules.other.pedanticHrefTitle.exec(s);
				r && (s = r[1], i = r[3]);
			} else i = t[3] ? t[3].slice(1, -1) : "";
			return s = s.trim(), this.rules.other.startAngleBracket.test(s) && (this.options.pedantic && !this.rules.other.endAngleBracket.test(n) ? s = s.slice(1) : s = s.slice(1, -1)), de(t, {
				href: s && s.replace(this.rules.inline.anyPunctuation, "$1"),
				title: i && i.replace(this.rules.inline.anyPunctuation, "$1")
			}, t[0], this.lexer, this.rules);
		}
	}
	reflink(e, t) {
		let n;
		if ((n = this.rules.inline.reflink.exec(e)) || (n = this.rules.inline.nolink.exec(e))) {
			let s = (n[2] || n[1]).replace(this.rules.other.multipleSpaceGlobal, " "), i = t[s.toLowerCase()];
			if (!i) {
				let r = n[0].charAt(0);
				return {
					type: "text",
					raw: r,
					text: r
				};
			}
			return de(n, i, n[0], this.lexer, this.rules);
		}
	}
	emStrong(e, t, n = "") {
		let s = this.rules.inline.emStrongLDelim.exec(e);
		if (!s || s[3] && n.match(this.rules.other.unicodeAlphaNumeric)) return;
		if (!(s[1] || s[2] || "") || !n || this.rules.inline.punctuation.exec(n)) {
			let r = [...s[0]].length - 1, o, l, c = r, p = 0, u = s[0][0] === "*" ? this.rules.inline.emStrongRDelimAst : this.rules.inline.emStrongRDelimUnd;
			for (u.lastIndex = 0, t = t.slice(-1 * e.length + r); (s = u.exec(t)) != null;) {
				if (o = s[1] || s[2] || s[3] || s[4] || s[5] || s[6], !o) continue;
				if (l = [...o].length, s[3] || s[4]) {
					c += l;
					continue;
				} else if ((s[5] || s[6]) && r % 3 && !((r + l) % 3)) {
					p += l;
					continue;
				}
				if (c -= l, c > 0) continue;
				l = Math.min(l, l + c + p);
				let d = [...s[0]][0].length, g = e.slice(0, r + s.index + d + l);
				if (Math.min(r, l) % 2) {
					let f = g.slice(1, -1);
					return {
						type: "em",
						raw: g,
						text: f,
						tokens: this.lexer.inlineTokens(f)
					};
				}
				let x = g.slice(2, -2);
				return {
					type: "strong",
					raw: g,
					text: x,
					tokens: this.lexer.inlineTokens(x)
				};
			}
		}
	}
	codespan(e) {
		let t = this.rules.inline.code.exec(e);
		if (t) {
			let n = t[2].replace(this.rules.other.newLineCharGlobal, " "), s = this.rules.other.nonSpaceChar.test(n), i = this.rules.other.startingSpaceChar.test(n) && this.rules.other.endingSpaceChar.test(n);
			return s && i && (n = n.substring(1, n.length - 1)), {
				type: "codespan",
				raw: t[0],
				text: n
			};
		}
	}
	br(e) {
		let t = this.rules.inline.br.exec(e);
		if (t) return {
			type: "br",
			raw: t[0]
		};
	}
	del(e) {
		let t = this.rules.inline.del.exec(e);
		if (t) return {
			type: "del",
			raw: t[0],
			text: t[2],
			tokens: this.lexer.inlineTokens(t[2])
		};
	}
	autolink(e) {
		let t = this.rules.inline.autolink.exec(e);
		if (t) {
			let n, s;
			return t[2] === "@" ? (n = t[1], s = "mailto:" + n) : (n = t[1], s = n), {
				type: "link",
				raw: t[0],
				text: n,
				href: s,
				tokens: [{
					type: "text",
					raw: n,
					text: n
				}]
			};
		}
	}
	url(e) {
		let t;
		if (t = this.rules.inline.url.exec(e)) {
			let n, s;
			if (t[2] === "@") n = t[0], s = "mailto:" + n;
			else {
				let i;
				do
					i = t[0], t[0] = this.rules.inline._backpedal.exec(t[0])?.[0] ?? "";
				while (i !== t[0]);
				n = t[0], t[1] === "www." ? s = "http://" + t[0] : s = t[0];
			}
			return {
				type: "link",
				raw: t[0],
				text: n,
				href: s,
				tokens: [{
					type: "text",
					raw: n,
					text: n
				}]
			};
		}
	}
	inlineText(e) {
		let t = this.rules.inline.text.exec(e);
		if (t) {
			let n = this.lexer.state.inRawBlock;
			return {
				type: "text",
				raw: t[0],
				text: t[0],
				escaped: n
			};
		}
	}
};
var b = class a {
	tokens;
	options;
	state;
	tokenizer;
	inlineQueue;
	constructor(e) {
		this.tokens = [], this.tokens.links = Object.create(null), this.options = e || w, this.options.tokenizer = this.options.tokenizer || new S(), this.tokenizer = this.options.tokenizer, this.tokenizer.options = this.options, this.tokenizer.lexer = this, this.inlineQueue = [], this.state = {
			inLink: !1,
			inRawBlock: !1,
			top: !0
		};
		let t = {
			other: m,
			block: O.normal,
			inline: P.normal
		};
		this.options.pedantic ? (t.block = O.pedantic, t.inline = P.pedantic) : this.options.gfm && (t.block = O.gfm, this.options.breaks ? t.inline = P.breaks : t.inline = P.gfm), this.tokenizer.rules = t;
	}
	static get rules() {
		return {
			block: O,
			inline: P
		};
	}
	static lex(e, t) {
		return new a(t).lex(e);
	}
	static lexInline(e, t) {
		return new a(t).inlineTokens(e);
	}
	lex(e) {
		e = e.replace(m.carriageReturn, `
`), this.blockTokens(e, this.tokens);
		for (let t = 0; t < this.inlineQueue.length; t++) {
			let n = this.inlineQueue[t];
			this.inlineTokens(n.src, n.tokens);
		}
		return this.inlineQueue = [], this.tokens;
	}
	blockTokens(e, t = [], n = !1) {
		for (this.options.pedantic && (e = e.replace(m.tabCharGlobal, "    ").replace(m.spaceLine, "")); e;) {
			let s;
			if (this.options.extensions?.block?.some((r) => (s = r.call({ lexer: this }, e, t)) ? (e = e.substring(s.raw.length), t.push(s), !0) : !1)) continue;
			if (s = this.tokenizer.space(e)) {
				e = e.substring(s.raw.length);
				let r = t.at(-1);
				s.raw.length === 1 && r !== void 0 ? r.raw += `
` : t.push(s);
				continue;
			}
			if (s = this.tokenizer.code(e)) {
				e = e.substring(s.raw.length);
				let r = t.at(-1);
				r?.type === "paragraph" || r?.type === "text" ? (r.raw += `
` + s.raw, r.text += `
` + s.text, this.inlineQueue.at(-1).src = r.text) : t.push(s);
				continue;
			}
			if (s = this.tokenizer.fences(e)) {
				e = e.substring(s.raw.length), t.push(s);
				continue;
			}
			if (s = this.tokenizer.heading(e)) {
				e = e.substring(s.raw.length), t.push(s);
				continue;
			}
			if (s = this.tokenizer.hr(e)) {
				e = e.substring(s.raw.length), t.push(s);
				continue;
			}
			if (s = this.tokenizer.blockquote(e)) {
				e = e.substring(s.raw.length), t.push(s);
				continue;
			}
			if (s = this.tokenizer.list(e)) {
				e = e.substring(s.raw.length), t.push(s);
				continue;
			}
			if (s = this.tokenizer.html(e)) {
				e = e.substring(s.raw.length), t.push(s);
				continue;
			}
			if (s = this.tokenizer.def(e)) {
				e = e.substring(s.raw.length);
				let r = t.at(-1);
				r?.type === "paragraph" || r?.type === "text" ? (r.raw += `
` + s.raw, r.text += `
` + s.raw, this.inlineQueue.at(-1).src = r.text) : this.tokens.links[s.tag] || (this.tokens.links[s.tag] = {
					href: s.href,
					title: s.title
				});
				continue;
			}
			if (s = this.tokenizer.table(e)) {
				e = e.substring(s.raw.length), t.push(s);
				continue;
			}
			if (s = this.tokenizer.lheading(e)) {
				e = e.substring(s.raw.length), t.push(s);
				continue;
			}
			let i = e;
			if (this.options.extensions?.startBlock) {
				let r = Infinity, o = e.slice(1), l;
				this.options.extensions.startBlock.forEach((c) => {
					l = c.call({ lexer: this }, o), typeof l == "number" && l >= 0 && (r = Math.min(r, l));
				}), r < Infinity && r >= 0 && (i = e.substring(0, r + 1));
			}
			if (this.state.top && (s = this.tokenizer.paragraph(i))) {
				let r = t.at(-1);
				n && r?.type === "paragraph" ? (r.raw += `
` + s.raw, r.text += `
` + s.text, this.inlineQueue.pop(), this.inlineQueue.at(-1).src = r.text) : t.push(s), n = i.length !== e.length, e = e.substring(s.raw.length);
				continue;
			}
			if (s = this.tokenizer.text(e)) {
				e = e.substring(s.raw.length);
				let r = t.at(-1);
				r?.type === "text" ? (r.raw += `
` + s.raw, r.text += `
` + s.text, this.inlineQueue.pop(), this.inlineQueue.at(-1).src = r.text) : t.push(s);
				continue;
			}
			if (e) {
				let r = "Infinite loop on byte: " + e.charCodeAt(0);
				if (this.options.silent) {
					console.error(r);
					break;
				} else throw new Error(r);
			}
		}
		return this.state.top = !0, t;
	}
	inline(e, t = []) {
		return this.inlineQueue.push({
			src: e,
			tokens: t
		}), t;
	}
	inlineTokens(e, t = []) {
		let n = e, s = null;
		if (this.tokens.links) {
			let o = Object.keys(this.tokens.links);
			if (o.length > 0) for (; (s = this.tokenizer.rules.inline.reflinkSearch.exec(n)) != null;) o.includes(s[0].slice(s[0].lastIndexOf("[") + 1, -1)) && (n = n.slice(0, s.index) + "[" + "a".repeat(s[0].length - 2) + "]" + n.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex));
		}
		for (; (s = this.tokenizer.rules.inline.anyPunctuation.exec(n)) != null;) n = n.slice(0, s.index) + "++" + n.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);
		for (; (s = this.tokenizer.rules.inline.blockSkip.exec(n)) != null;) n = n.slice(0, s.index) + "[" + "a".repeat(s[0].length - 2) + "]" + n.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);
		let i = !1, r = "";
		for (; e;) {
			i || (r = ""), i = !1;
			let o;
			if (this.options.extensions?.inline?.some((c) => (o = c.call({ lexer: this }, e, t)) ? (e = e.substring(o.raw.length), t.push(o), !0) : !1)) continue;
			if (o = this.tokenizer.escape(e)) {
				e = e.substring(o.raw.length), t.push(o);
				continue;
			}
			if (o = this.tokenizer.tag(e)) {
				e = e.substring(o.raw.length), t.push(o);
				continue;
			}
			if (o = this.tokenizer.link(e)) {
				e = e.substring(o.raw.length), t.push(o);
				continue;
			}
			if (o = this.tokenizer.reflink(e, this.tokens.links)) {
				e = e.substring(o.raw.length);
				let c = t.at(-1);
				o.type === "text" && c?.type === "text" ? (c.raw += o.raw, c.text += o.text) : t.push(o);
				continue;
			}
			if (o = this.tokenizer.emStrong(e, n, r)) {
				e = e.substring(o.raw.length), t.push(o);
				continue;
			}
			if (o = this.tokenizer.codespan(e)) {
				e = e.substring(o.raw.length), t.push(o);
				continue;
			}
			if (o = this.tokenizer.br(e)) {
				e = e.substring(o.raw.length), t.push(o);
				continue;
			}
			if (o = this.tokenizer.del(e)) {
				e = e.substring(o.raw.length), t.push(o);
				continue;
			}
			if (o = this.tokenizer.autolink(e)) {
				e = e.substring(o.raw.length), t.push(o);
				continue;
			}
			if (!this.state.inLink && (o = this.tokenizer.url(e))) {
				e = e.substring(o.raw.length), t.push(o);
				continue;
			}
			let l = e;
			if (this.options.extensions?.startInline) {
				let c = Infinity, p = e.slice(1), u;
				this.options.extensions.startInline.forEach((d) => {
					u = d.call({ lexer: this }, p), typeof u == "number" && u >= 0 && (c = Math.min(c, u));
				}), c < Infinity && c >= 0 && (l = e.substring(0, c + 1));
			}
			if (o = this.tokenizer.inlineText(l)) {
				e = e.substring(o.raw.length), o.raw.slice(-1) !== "_" && (r = o.raw.slice(-1)), i = !0;
				let c = t.at(-1);
				c?.type === "text" ? (c.raw += o.raw, c.text += o.text) : t.push(o);
				continue;
			}
			if (e) {
				let c = "Infinite loop on byte: " + e.charCodeAt(0);
				if (this.options.silent) {
					console.error(c);
					break;
				} else throw new Error(c);
			}
		}
		return t;
	}
};
var $ = class {
	options;
	parser;
	constructor(e) {
		this.options = e || w;
	}
	space(e) {
		return "";
	}
	code({ text: e, lang: t, escaped: n }) {
		let s = (t || "").match(m.notSpaceStart)?.[0], i = e.replace(m.endingNewline, "") + `
`;
		return s ? "<pre><code class=\"language-" + R(s) + "\">" + (n ? i : R(i, !0)) + `</code></pre>
` : "<pre><code>" + (n ? i : R(i, !0)) + `</code></pre>
`;
	}
	blockquote({ tokens: e }) {
		return `<blockquote>
${this.parser.parse(e)}</blockquote>
`;
	}
	html({ text: e }) {
		return e;
	}
	heading({ tokens: e, depth: t }) {
		return `<h${t}>${this.parser.parseInline(e)}</h${t}>
`;
	}
	hr(e) {
		return `<hr>
`;
	}
	list(e) {
		let t = e.ordered, n = e.start, s = "";
		for (let o = 0; o < e.items.length; o++) {
			let l = e.items[o];
			s += this.listitem(l);
		}
		let i = t ? "ol" : "ul", r = t && n !== 1 ? " start=\"" + n + "\"" : "";
		return "<" + i + r + `>
` + s + "</" + i + `>
`;
	}
	listitem(e) {
		let t = "";
		if (e.task) {
			let n = this.checkbox({ checked: !!e.checked });
			e.loose ? e.tokens[0]?.type === "paragraph" ? (e.tokens[0].text = n + " " + e.tokens[0].text, e.tokens[0].tokens && e.tokens[0].tokens.length > 0 && e.tokens[0].tokens[0].type === "text" && (e.tokens[0].tokens[0].text = n + " " + R(e.tokens[0].tokens[0].text), e.tokens[0].tokens[0].escaped = !0)) : e.tokens.unshift({
				type: "text",
				raw: n + " ",
				text: n + " ",
				escaped: !0
			}) : t += n + " ";
		}
		return t += this.parser.parse(e.tokens, !!e.loose), `<li>${t}</li>
`;
	}
	checkbox({ checked: e }) {
		return "<input " + (e ? "checked=\"\" " : "") + "disabled=\"\" type=\"checkbox\">";
	}
	paragraph({ tokens: e }) {
		return `<p>${this.parser.parseInline(e)}</p>
`;
	}
	table(e) {
		let t = "", n = "";
		for (let i = 0; i < e.header.length; i++) n += this.tablecell(e.header[i]);
		t += this.tablerow({ text: n });
		let s = "";
		for (let i = 0; i < e.rows.length; i++) {
			let r = e.rows[i];
			n = "";
			for (let o = 0; o < r.length; o++) n += this.tablecell(r[o]);
			s += this.tablerow({ text: n });
		}
		return s && (s = `<tbody>${s}</tbody>`), `<table>
<thead>
` + t + `</thead>
` + s + `</table>
`;
	}
	tablerow({ text: e }) {
		return `<tr>
${e}</tr>
`;
	}
	tablecell(e) {
		let t = this.parser.parseInline(e.tokens), n = e.header ? "th" : "td";
		return (e.align ? `<${n} align="${e.align}">` : `<${n}>`) + t + `</${n}>
`;
	}
	strong({ tokens: e }) {
		return `<strong>${this.parser.parseInline(e)}</strong>`;
	}
	em({ tokens: e }) {
		return `<em>${this.parser.parseInline(e)}</em>`;
	}
	codespan({ text: e }) {
		return `<code>${R(e, !0)}</code>`;
	}
	br(e) {
		return "<br>";
	}
	del({ tokens: e }) {
		return `<del>${this.parser.parseInline(e)}</del>`;
	}
	link({ href: e, title: t, tokens: n }) {
		let s = this.parser.parseInline(n), i = J(e);
		if (i === null) return s;
		e = i;
		let r = "<a href=\"" + e + "\"";
		return t && (r += " title=\"" + R(t) + "\""), r += ">" + s + "</a>", r;
	}
	image({ href: e, title: t, text: n, tokens: s }) {
		s && (n = this.parser.parseInline(s, this.parser.textRenderer));
		let i = J(e);
		if (i === null) return R(n);
		e = i;
		let r = `<img src="${e}" alt="${n}"`;
		return t && (r += ` title="${R(t)}"`), r += ">", r;
	}
	text(e) {
		return "tokens" in e && e.tokens ? this.parser.parseInline(e.tokens) : "escaped" in e && e.escaped ? e.text : R(e.text);
	}
};
var _ = class {
	strong({ text: e }) {
		return e;
	}
	em({ text: e }) {
		return e;
	}
	codespan({ text: e }) {
		return e;
	}
	del({ text: e }) {
		return e;
	}
	html({ text: e }) {
		return e;
	}
	text({ text: e }) {
		return e;
	}
	link({ text: e }) {
		return "" + e;
	}
	image({ text: e }) {
		return "" + e;
	}
	br() {
		return "";
	}
};
var T = class a {
	options;
	renderer;
	textRenderer;
	constructor(e) {
		this.options = e || w, this.options.renderer = this.options.renderer || new $(), this.renderer = this.options.renderer, this.renderer.options = this.options, this.renderer.parser = this, this.textRenderer = new _();
	}
	static parse(e, t) {
		return new a(t).parse(e);
	}
	static parseInline(e, t) {
		return new a(t).parseInline(e);
	}
	parse(e, t = !0) {
		let n = "";
		for (let s = 0; s < e.length; s++) {
			let i = e[s];
			if (this.options.extensions?.renderers?.[i.type]) {
				let o = i, l = this.options.extensions.renderers[o.type].call({ parser: this }, o);
				if (l !== !1 || ![
					"space",
					"hr",
					"heading",
					"code",
					"table",
					"blockquote",
					"list",
					"html",
					"paragraph",
					"text"
				].includes(o.type)) {
					n += l || "";
					continue;
				}
			}
			let r = i;
			switch (r.type) {
				case "space": {
					n += this.renderer.space(r);
					continue;
				}
				case "hr": {
					n += this.renderer.hr(r);
					continue;
				}
				case "heading": {
					n += this.renderer.heading(r);
					continue;
				}
				case "code": {
					n += this.renderer.code(r);
					continue;
				}
				case "table": {
					n += this.renderer.table(r);
					continue;
				}
				case "blockquote": {
					n += this.renderer.blockquote(r);
					continue;
				}
				case "list": {
					n += this.renderer.list(r);
					continue;
				}
				case "html": {
					n += this.renderer.html(r);
					continue;
				}
				case "paragraph": {
					n += this.renderer.paragraph(r);
					continue;
				}
				case "text": {
					let o = r, l = this.renderer.text(o);
					for (; s + 1 < e.length && e[s + 1].type === "text";) o = e[++s], l += `
` + this.renderer.text(o);
					t ? n += this.renderer.paragraph({
						type: "paragraph",
						raw: l,
						text: l,
						tokens: [{
							type: "text",
							raw: l,
							text: l,
							escaped: !0
						}]
					}) : n += l;
					continue;
				}
				default: {
					let o = "Token with \"" + r.type + "\" type was not found.";
					if (this.options.silent) return console.error(o), "";
					throw new Error(o);
				}
			}
		}
		return n;
	}
	parseInline(e, t = this.renderer) {
		let n = "";
		for (let s = 0; s < e.length; s++) {
			let i = e[s];
			if (this.options.extensions?.renderers?.[i.type]) {
				let o = this.options.extensions.renderers[i.type].call({ parser: this }, i);
				if (o !== !1 || ![
					"escape",
					"html",
					"link",
					"image",
					"strong",
					"em",
					"codespan",
					"br",
					"del",
					"text"
				].includes(i.type)) {
					n += o || "";
					continue;
				}
			}
			let r = i;
			switch (r.type) {
				case "escape": {
					n += t.text(r);
					break;
				}
				case "html": {
					n += t.html(r);
					break;
				}
				case "link": {
					n += t.link(r);
					break;
				}
				case "image": {
					n += t.image(r);
					break;
				}
				case "strong": {
					n += t.strong(r);
					break;
				}
				case "em": {
					n += t.em(r);
					break;
				}
				case "codespan": {
					n += t.codespan(r);
					break;
				}
				case "br": {
					n += t.br(r);
					break;
				}
				case "del": {
					n += t.del(r);
					break;
				}
				case "text": {
					n += t.text(r);
					break;
				}
				default: {
					let o = "Token with \"" + r.type + "\" type was not found.";
					if (this.options.silent) return console.error(o), "";
					throw new Error(o);
				}
			}
		}
		return n;
	}
};
var L = class {
	options;
	block;
	constructor(e) {
		this.options = e || w;
	}
	static passThroughHooks = new Set([
		"preprocess",
		"postprocess",
		"processAllTokens"
	]);
	preprocess(e) {
		return e;
	}
	postprocess(e) {
		return e;
	}
	processAllTokens(e) {
		return e;
	}
	provideLexer() {
		return this.block ? b.lex : b.lexInline;
	}
	provideParser() {
		return this.block ? T.parse : T.parseInline;
	}
};
var B = class {
	defaults = M();
	options = this.setOptions;
	parse = this.parseMarkdown(!0);
	parseInline = this.parseMarkdown(!1);
	Parser = T;
	Renderer = $;
	TextRenderer = _;
	Lexer = b;
	Tokenizer = S;
	Hooks = L;
	constructor(...e) {
		this.use(...e);
	}
	walkTokens(e, t) {
		let n = [];
		for (let s of e) switch (n = n.concat(t.call(this, s)), s.type) {
			case "table": {
				let i = s;
				for (let r of i.header) n = n.concat(this.walkTokens(r.tokens, t));
				for (let r of i.rows) for (let o of r) n = n.concat(this.walkTokens(o.tokens, t));
				break;
			}
			case "list": {
				let i = s;
				n = n.concat(this.walkTokens(i.items, t));
				break;
			}
			default: {
				let i = s;
				this.defaults.extensions?.childTokens?.[i.type] ? this.defaults.extensions.childTokens[i.type].forEach((r) => {
					let o = i[r].flat(Infinity);
					n = n.concat(this.walkTokens(o, t));
				}) : i.tokens && (n = n.concat(this.walkTokens(i.tokens, t)));
			}
		}
		return n;
	}
	use(...e) {
		let t = this.defaults.extensions || {
			renderers: {},
			childTokens: {}
		};
		return e.forEach((n) => {
			let s = { ...n };
			if (s.async = this.defaults.async || s.async || !1, n.extensions && (n.extensions.forEach((i) => {
				if (!i.name) throw new Error("extension name required");
				if ("renderer" in i) {
					let r = t.renderers[i.name];
					r ? t.renderers[i.name] = function(...o) {
						let l = i.renderer.apply(this, o);
						return l === !1 && (l = r.apply(this, o)), l;
					} : t.renderers[i.name] = i.renderer;
				}
				if ("tokenizer" in i) {
					if (!i.level || i.level !== "block" && i.level !== "inline") throw new Error("extension level must be 'block' or 'inline'");
					let r = t[i.level];
					r ? r.unshift(i.tokenizer) : t[i.level] = [i.tokenizer], i.start && (i.level === "block" ? t.startBlock ? t.startBlock.push(i.start) : t.startBlock = [i.start] : i.level === "inline" && (t.startInline ? t.startInline.push(i.start) : t.startInline = [i.start]));
				}
				"childTokens" in i && i.childTokens && (t.childTokens[i.name] = i.childTokens);
			}), s.extensions = t), n.renderer) {
				let i = this.defaults.renderer || new $(this.defaults);
				for (let r in n.renderer) {
					if (!(r in i)) throw new Error(`renderer '${r}' does not exist`);
					if (["options", "parser"].includes(r)) continue;
					let o = r, l = n.renderer[o], c = i[o];
					i[o] = (...p) => {
						let u = l.apply(i, p);
						return u === !1 && (u = c.apply(i, p)), u || "";
					};
				}
				s.renderer = i;
			}
			if (n.tokenizer) {
				let i = this.defaults.tokenizer || new S(this.defaults);
				for (let r in n.tokenizer) {
					if (!(r in i)) throw new Error(`tokenizer '${r}' does not exist`);
					if ([
						"options",
						"rules",
						"lexer"
					].includes(r)) continue;
					let o = r, l = n.tokenizer[o], c = i[o];
					i[o] = (...p) => {
						let u = l.apply(i, p);
						return u === !1 && (u = c.apply(i, p)), u;
					};
				}
				s.tokenizer = i;
			}
			if (n.hooks) {
				let i = this.defaults.hooks || new L();
				for (let r in n.hooks) {
					if (!(r in i)) throw new Error(`hook '${r}' does not exist`);
					if (["options", "block"].includes(r)) continue;
					let o = r, l = n.hooks[o], c = i[o];
					L.passThroughHooks.has(r) ? i[o] = (p) => {
						if (this.defaults.async) return Promise.resolve(l.call(i, p)).then((d) => c.call(i, d));
						let u = l.call(i, p);
						return c.call(i, u);
					} : i[o] = (...p) => {
						let u = l.apply(i, p);
						return u === !1 && (u = c.apply(i, p)), u;
					};
				}
				s.hooks = i;
			}
			if (n.walkTokens) {
				let i = this.defaults.walkTokens, r = n.walkTokens;
				s.walkTokens = function(o) {
					let l = [];
					return l.push(r.call(this, o)), i && (l = l.concat(i.call(this, o))), l;
				};
			}
			this.defaults = {
				...this.defaults,
				...s
			};
		}), this;
	}
	setOptions(e) {
		return this.defaults = {
			...this.defaults,
			...e
		}, this;
	}
	lexer(e, t) {
		return b.lex(e, t ?? this.defaults);
	}
	parser(e, t) {
		return T.parse(e, t ?? this.defaults);
	}
	parseMarkdown(e) {
		return (n, s) => {
			let i = { ...s }, r = {
				...this.defaults,
				...i
			}, o = this.onError(!!r.silent, !!r.async);
			if (this.defaults.async === !0 && i.async === !1) return o(/* @__PURE__ */ new Error("marked(): The async option was set to true by an extension. Remove async: false from the parse options object to return a Promise."));
			if (typeof n > "u" || n === null) return o(/* @__PURE__ */ new Error("marked(): input parameter is undefined or null"));
			if (typeof n != "string") return o(/* @__PURE__ */ new Error("marked(): input parameter is of type " + Object.prototype.toString.call(n) + ", string expected"));
			r.hooks && (r.hooks.options = r, r.hooks.block = e);
			let l = r.hooks ? r.hooks.provideLexer() : e ? b.lex : b.lexInline, c = r.hooks ? r.hooks.provideParser() : e ? T.parse : T.parseInline;
			if (r.async) return Promise.resolve(r.hooks ? r.hooks.preprocess(n) : n).then((p) => l(p, r)).then((p) => r.hooks ? r.hooks.processAllTokens(p) : p).then((p) => r.walkTokens ? Promise.all(this.walkTokens(p, r.walkTokens)).then(() => p) : p).then((p) => c(p, r)).then((p) => r.hooks ? r.hooks.postprocess(p) : p).catch(o);
			try {
				r.hooks && (n = r.hooks.preprocess(n));
				let p = l(n, r);
				r.hooks && (p = r.hooks.processAllTokens(p)), r.walkTokens && this.walkTokens(p, r.walkTokens);
				let u = c(p, r);
				return r.hooks && (u = r.hooks.postprocess(u)), u;
			} catch (p) {
				return o(p);
			}
		};
	}
	onError(e, t) {
		return (n) => {
			if (n.message += `
Please report this to https://github.com/markedjs/marked.`, e) {
				let s = "<p>An error occurred:</p><pre>" + R(n.message + "", !0) + "</pre>";
				return t ? Promise.resolve(s) : s;
			}
			if (t) return Promise.reject(n);
			throw n;
		};
	}
};
var z = new B();
function k(a, e) {
	return z.parse(a, e);
}
k.options = k.setOptions = function(a) {
	return z.setOptions(a), k.defaults = z.defaults, H(k.defaults), k;
};
k.getDefaults = M;
k.defaults = w;
k.use = function(...a) {
	return z.use(...a), k.defaults = z.defaults, H(k.defaults), k;
};
k.walkTokens = function(a, e) {
	return z.walkTokens(a, e);
};
k.parseInline = z.parseInline;
k.Parser = T;
k.parser = T.parse;
k.Renderer = $;
k.TextRenderer = _;
k.Lexer = b;
k.lexer = b.lex;
k.Tokenizer = S;
k.Hooks = L;
k.parse = k;
var Dt = k.options, Zt = k.setOptions, Gt = k.use, Ht = k.walkTokens, Nt = k.parseInline, jt = k, Ft = T.parse, Qt = b.lex;

//#endregion
//#region src/extension/managers/AutocompleteManager.ts
var AutocompleteManager = class {
	_callbacks;
	_selectedIndex = -1;
	constructor(options) {
		this._callbacks = options.callbacks;
	}
	setupAutocompleteEventListeners() {
		setTimeout(() => {
			const textarea = document.getElementById("doc-textarea");
			if (!textarea) return;
			textarea.addEventListener("input", () => {
				this.handleAutocomplete();
			});
			textarea.addEventListener("keydown", (event) => {
				this._handleAutocompleteKeydown(event);
			});
			document.addEventListener("click", (event) => {
				const dropdown = document.getElementById("autocomplete-dropdown");
				const textarea$1 = document.getElementById("doc-textarea");
				if (dropdown && !(event.target instanceof Node && dropdown.contains(event.target)) && event.target !== textarea$1) this.hideAutocomplete();
			});
		}, 100);
	}
	handleAutocomplete() {
		const textarea = document.getElementById("doc-textarea");
		if (!textarea) return;
		const cursorPos = textarea.selectionStart;
		const text = textarea.value;
		let hashPos = -1;
		for (let i = cursorPos - 1; i >= 0; i--) {
			if (text[i] === "#") {
				hashPos = i;
				break;
			}
			if (text[i] === " " || text[i] === "\n" || text[i] === "	") break;
		}
		if (hashPos >= 0) {
			if (hashPos > 0 && text[hashPos - 1] === "(") {
				let foundClosingBracket = false;
				for (let i = hashPos - 2; i >= 0; i--) {
					if (text[i] === "]") {
						foundClosingBracket = true;
						break;
					}
					if (text[i] === "\n" || text[i] === "\r") break;
				}
				if (foundClosingBracket) {
					const searchText = text.substring(hashPos + 1, cursorPos);
					if (!searchText.includes(" ") && !searchText.includes("\n")) {
						this._showAutocomplete(searchText, hashPos);
						return;
					}
				}
			}
		}
		this.hideAutocomplete();
	}
	hideAutocomplete() {
		const dropdown = document.getElementById("autocomplete-dropdown");
		if (!dropdown) return;
		dropdown.classList.remove("visible");
		this._selectedIndex = -1;
	}
	destroy() {
		this.hideAutocomplete();
	}
	_showAutocomplete(searchText, hashPos) {
		const dropdown = document.getElementById("autocomplete-dropdown");
		const autocompleteList = document.getElementById("autocomplete-list");
		const textarea = document.getElementById("doc-textarea");
		if (!dropdown || !autocompleteList || !textarea) return;
		const allElements = this._getAllElements();
		const filteredElements = allElements.filter((element) => element.id.toLowerCase().includes(searchText.toLowerCase()) || element.name.toLowerCase().includes(searchText.toLowerCase()));
		if (filteredElements.length === 0) {
			this.hideAutocomplete();
			return;
		}
		autocompleteList.innerHTML = "";
		filteredElements.slice(0, 10).forEach((element) => {
			const item = document.createElement("div");
			item.className = "autocomplete-item";
			item.innerHTML = `
        <div class="autocomplete-item-id">${element.id}</div>
        <div class="autocomplete-item-name">${element.name}</div>
        <div class="autocomplete-item-type">${element.type}</div>
      `;
			item.addEventListener("click", () => {
				this._selectAutocompleteItem(element.id, hashPos);
			});
			autocompleteList.appendChild(item);
		});
		this._positionAutocomplete(textarea, hashPos);
		dropdown.classList.add("visible");
		this._selectedIndex = 0;
		this._updateAutocompleteSelection(Array.from(autocompleteList.children));
	}
	_positionAutocomplete(textarea, hashPos) {
		const dropdown = document.getElementById("autocomplete-dropdown");
		if (!dropdown) return;
		const textareaRect = textarea.getBoundingClientRect();
		const style = window.getComputedStyle(textarea);
		const tempSpan = document.createElement("span");
		tempSpan.style.visibility = "hidden";
		tempSpan.style.position = "absolute";
		tempSpan.style.top = "-9999px";
		tempSpan.style.fontFamily = style.fontFamily;
		tempSpan.style.fontSize = style.fontSize;
		tempSpan.style.fontWeight = style.fontWeight;
		tempSpan.style.letterSpacing = style.letterSpacing;
		tempSpan.style.whiteSpace = "pre";
		const textUpToHash = textarea.value.substring(0, hashPos);
		const linesUpToHash = textUpToHash.split("\n");
		const currentLine = linesUpToHash[linesUpToHash.length - 1];
		tempSpan.textContent = currentLine;
		this._callbacks.getCanvasContainer().appendChild(tempSpan);
		this._callbacks.getCanvasContainer().removeChild(tempSpan);
		const left = textareaRect.left + 10;
		const top = textareaRect.top + 100;
		dropdown.style.setProperty("left", `${left}px`, "important");
		dropdown.style.setProperty("top", `${top}px`, "important");
		dropdown.style.setProperty("position", "fixed", "important");
		dropdown.style.setProperty("z-index", "10001", "important");
	}
	_getAllElements() {
		const elements = [];
		const seenIds = /* @__PURE__ */ new Set();
		const allElements = this._callbacks.getAllElements();
		allElements.forEach((element) => {
			if (element.businessObject?.id) {
				const bo = element.businessObject;
				const elementId = bo.id;
				if (seenIds.has(elementId)) return;
				seenIds.add(elementId);
				elements.push({
					id: elementId,
					name: bo.name || "Unnamed",
					type: this._callbacks.getElementTypeName(element)
				});
			}
		});
		return elements.sort((a, b$1) => a.id.localeCompare(b$1.id));
	}
	_handleAutocompleteKeydown(event) {
		const dropdown = document.getElementById("autocomplete-dropdown");
		if (!dropdown || !dropdown.classList.contains("visible")) return;
		const items = Array.from(dropdown.querySelectorAll(".autocomplete-item"));
		if (event.key === "ArrowDown") {
			event.preventDefault();
			this._selectedIndex = Math.min(this._selectedIndex + 1, items.length - 1);
			this._updateAutocompleteSelection(items);
		} else if (event.key === "ArrowUp") {
			event.preventDefault();
			this._selectedIndex = Math.max(this._selectedIndex - 1, 0);
			this._updateAutocompleteSelection(items);
		} else if (event.key === "Enter") {
			event.preventDefault();
			if (this._selectedIndex >= 0 && items[this._selectedIndex]) {
				const selectedId = items[this._selectedIndex].querySelector(".autocomplete-item-id")?.textContent;
				const textarea = document.getElementById("doc-textarea");
				if (!textarea) return;
				const cursorPos = textarea.selectionStart;
				const text = textarea.value;
				let hashPos = -1;
				for (let i = cursorPos - 1; i >= 0; i--) if (text[i] === "#") {
					hashPos = i;
					break;
				}
				if (hashPos >= 0 && selectedId) this._selectAutocompleteItem(selectedId, hashPos);
			}
		} else if (event.key === "Escape") {
			event.preventDefault();
			this.hideAutocomplete();
		}
	}
	_updateAutocompleteSelection(items) {
		const dropdown = document.getElementById("autocomplete-dropdown");
		const autocompleteList = document.getElementById("autocomplete-list");
		if (!dropdown || !autocompleteList) return;
		Array.from(items).forEach((item, index) => {
			if (index === this._selectedIndex) {
				item.classList.add("selected");
				const itemTop = item.offsetTop;
				const itemBottom = itemTop + item.offsetHeight;
				const dropdownTop = dropdown.scrollTop;
				const dropdownBottom = dropdownTop + dropdown.clientHeight;
				if (itemTop < dropdownTop) dropdown.scrollTop = itemTop;
				else if (itemBottom > dropdownBottom) dropdown.scrollTop = itemBottom - dropdown.clientHeight;
			} else item.classList.remove("selected");
		});
	}
	_selectAutocompleteItem(elementId, hashPos) {
		const textarea = document.getElementById("doc-textarea");
		if (!textarea) return;
		const text = textarea.value;
		const cursorPos = textarea.selectionStart;
		const beforeHash = text.substring(0, hashPos + 1);
		const afterCursor = text.substring(cursorPos);
		const newText = beforeHash + elementId + afterCursor;
		textarea.value = newText;
		const newCursorPos = hashPos + 1 + elementId.length;
		textarea.setSelectionRange(newCursorPos, newCursorPos);
		this.hideAutocomplete();
		this._callbacks.updatePreview();
		this._callbacks.saveDocumentationLive();
		textarea.focus();
	}
};

//#endregion
//#region src/extension/managers/ExportManager.ts
var ExportManager = class {
	_elementRegistry;
	_moddle;
	_canvas;
	constructor(elementRegistry, moddle, canvas) {
		this._elementRegistry = elementRegistry;
		this._moddle = moddle;
		this._canvas = canvas;
	}
	setupExportEventListeners() {
		setTimeout(() => {
			document.getElementById("export-btn")?.addEventListener("click", () => {
				this.handleExport();
			});
		}, 100);
	}
	handleExport() {
		this.exportDocumentation().catch((error) => {
			console.error("Export failed:", error);
			this._showNotification("Export failed", "error");
		});
	}
	/**
	* Export documentation in HTML format
	*/
	async exportDocumentation() {
		try {
			const processInfo = this._getProcessInfo();
			const elements = this._getAllElementsWithDocumentation();
			const documentedElements = elements.filter((el) => el.hasDocumentation);
			if (documentedElements.length === 0) {
				this._showNotification("No documented elements found to export", "warning");
				return;
			}
			const htmlContent = await this._generateHTMLExport(elements, processInfo);
			const processName = processInfo.name || processInfo.id || "Process";
			const filename = `${processName}_Documentation.html`;
			this._downloadFile(htmlContent, filename, "text/html");
			this._showNotification(`Documentation exported successfully (${documentedElements.length} elements)`, "success");
		} catch (error) {
			console.error("Export failed:", error);
			const errorMessage = error instanceof Error ? error.message : "Unknown error";
			this._showNotification(`Export failed: ${errorMessage}`, "error");
		}
	}
	/**
	* Get BPMN diagram as SVG
	*/
	async _getDiagramSVG() {
		try {
			const canvasContainer = this._canvas.getContainer();
			const svgElement = canvasContainer.querySelector("svg");
			if (svgElement) {
				const svgCopy = svgElement.cloneNode(true);
				const allElements = this._elementRegistry.getAll();
				let minX = Number.POSITIVE_INFINITY;
				let minY = Number.POSITIVE_INFINITY;
				let maxX = Number.NEGATIVE_INFINITY;
				let maxY = Number.NEGATIVE_INFINITY;
				allElements.forEach((element) => {
					if (element.x !== void 0 && element.y !== void 0 && element.width !== void 0 && element.height !== void 0) {
						minX = Math.min(minX, element.x);
						minY = Math.min(minY, element.y);
						maxX = Math.max(maxX, element.x + element.width);
						maxY = Math.max(maxY, element.y + element.height);
					}
				});
				const padding = 50;
				const diagramWidth = maxX - minX;
				const diagramHeight = maxY - minY;
				const viewBoxX = minX - padding;
				const viewBoxY = minY - padding;
				const viewBoxWidth = diagramWidth + padding * 2;
				const viewBoxHeight = diagramHeight + padding * 2;
				const viewBox = `${viewBoxX} ${viewBoxY} ${viewBoxWidth} ${viewBoxHeight}`;
				svgCopy.setAttribute("viewBox", viewBox);
				const aspectRatio = viewBoxWidth / viewBoxHeight;
				let svgWidth = 800;
				let svgHeight = 600;
				if (aspectRatio > svgWidth / svgHeight) svgHeight = svgWidth / aspectRatio;
				else svgWidth = svgHeight * aspectRatio;
				svgCopy.setAttribute("width", Math.round(svgWidth).toString());
				svgCopy.setAttribute("height", Math.round(svgHeight).toString());
				const background = document.createElementNS("http://www.w3.org/2000/svg", "rect");
				background.setAttribute("x", viewBoxX.toString());
				background.setAttribute("y", viewBoxY.toString());
				background.setAttribute("width", viewBoxWidth.toString());
				background.setAttribute("height", viewBoxHeight.toString());
				background.setAttribute("fill", "#ffffff");
				svgCopy.insertBefore(background, svgCopy.firstChild);
				return svgCopy.outerHTML;
			}
			return "";
		} catch (error) {
			console.error("Error getting diagram SVG:", error);
			return "";
		}
	}
	/**
	* Get all elements with their documentation status
	*/
	_getAllElementsWithDocumentation() {
		const elements = [];
		const seenIds = /* @__PURE__ */ new Set();
		const allElements = this._elementRegistry.getAll();
		allElements.forEach((element) => {
			if (element.businessObject?.id) {
				const bo = element.businessObject;
				const elementId = bo.id;
				if (seenIds.has(elementId)) return;
				seenIds.add(elementId);
				const documentation = this._getElementDocumentation(element);
				elements.push({
					id: elementId,
					name: bo.name || "Unnamed",
					type: this._getElementTypeName(element),
					hasDocumentation: !!documentation?.trim(),
					documentation: documentation || "",
					element
				});
			}
		});
		return elements.sort((a, b$1) => a.id.localeCompare(b$1.id));
	}
	/**
	* Get documentation for a specific element
	*/
	_getElementDocumentation(element) {
		if (!element || !element.businessObject) return "";
		const bo = element.businessObject;
		if (bo.documentation && bo.documentation.length > 0) return bo.documentation[0].text || "";
		return "";
	}
	/**
	* Get element type name for display
	*/
	_getElementTypeName(element) {
		if (!element || !element.businessObject) return "Unknown";
		const bo = element.businessObject;
		const type = bo.$type || "";
		if (type.includes(":")) {
			const typeName = type.split(":")[1];
			return typeName.replace(/([A-Z])/g, " $1").trim();
		}
		return type || "Unknown";
	}
	/**
	* Generate HTML export content
	*/
	async _generateHTMLExport(elements, processInfo) {
		const totalElements = elements.length;
		const documentedCount = elements.filter((el) => el.hasDocumentation).length;
		const undocumentedCount = totalElements - documentedCount;
		const coveragePercentage = totalElements > 0 ? Math.round(documentedCount / totalElements * 100) : 0;
		const processTitle = processInfo.name || processInfo.id || "BPMN Process";
		const processDocumentation = processInfo.element ? this._getElementDocumentation(processInfo.element) : "";
		const diagramSVG = await this._getDiagramSVG();
		const tocItems = elements.map((el) => `<li><a href="#element-${el.id}" class="toc-link">${el.name} (${el.id})</a></li>`).join("");
		const elementSections = elements.map((el) => {
			const markdownContent = el.documentation || "";
			const htmlContent = markdownContent ? k(markdownContent) : "<p class='no-documentation'><em>No documentation available</em></p>";
			return `
        <div class="element-section" id="element-${el.id}">
          <div class="element-header">
            <div class="element-title-info">
              <h2 class="element-title">${el.name}</h2>
              <div class="element-meta">
                <span class="element-id">${el.id}</span>
              </div>
            </div>
          </div>
          <div class="element-content">
            ${htmlContent}
          </div>
        </div>
      `;
		}).join("");
		return `<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>${this._escapeHtml(processTitle)} - Documentation</title>
  <style>
    ${this._generateStyles()}
  </style>
</head>
<body>
  <div class="container">
    <header class="header">
      <h1 class="main-title">${this._escapeHtml(processTitle)}</h1>
      ${processDocumentation ? `<p class="subtitle">${this._escapeHtml(processDocumentation)}</p>` : ""}
      <div class="export-info">
        <span class="export-date">Generated on ${(/* @__PURE__ */ new Date()).toLocaleDateString()}</span>
      </div>
    </header>
    
    <div class="stats-section">
      <div class="stats-grid">
        <div class="stat-card">
          <div class="stat-number">${totalElements}</div>
          <div class="stat-label">Total Elements</div>
        </div>
        <div class="stat-card documented">
          <div class="stat-number">${documentedCount}</div>
          <div class="stat-label">Documented</div>
        </div>
        <div class="stat-card undocumented">
          <div class="stat-number">${undocumentedCount}</div>
          <div class="stat-label">Undocumented</div>
        </div>
        <div class="stat-card coverage">
          <div class="stat-number">${coveragePercentage}%</div>
          <div class="stat-label">Coverage</div>
        </div>
      </div>
    </div>
    
    ${diagramSVG ? `
    <div class="diagram-section">
      <h2 class="section-title">Process Diagram</h2>
      <div class="diagram-container">
        ${diagramSVG}
      </div>
    </div>
    ` : ""}
    
    <div class="toc-section">
      <h2 class="section-title">Table of Contents</h2>
      <div class="toc-container">
        <ul class="toc-list">
          ${tocItems}
        </ul>
      </div>
    </div>
    
    <div class="documentation-section">
      <h2 class="section-title">Element Documentation</h2>
      ${elementSections}
    </div>
    
    <div class="back-to-top">
      <button onclick="window.scrollTo({top: 0, behavior: 'smooth'})" class="back-to-top-btn">
        ↑ Back to Top
      </button>
    </div>
  </div>
  
  <script>
    // Add smooth scrolling for table of contents links
    document.querySelectorAll('.toc-link').forEach(link => {
      link.addEventListener('click', function(e) {
        e.preventDefault();
        const target = document.querySelector(this.getAttribute('href'));
        if (target) {
          target.scrollIntoView({ behavior: 'smooth', block: 'start' });
        }
      });
    });
    
    // Show/hide back to top button
    window.addEventListener('scroll', function() {
      const backToTop = document.querySelector('.back-to-top');
      if (window.scrollY > 300) {
        backToTop.style.display = 'block';
      } else {
        backToTop.style.display = 'none';
      }
    });
  <\/script>
</body>
</html>`;
	}
	/**
	* Generate CSS styles for the HTML export
	*/
	_generateStyles() {
		return `
    * {
      margin: 0;
      padding: 0;
      box-sizing: border-box;
    }
    
    body {
      font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
      line-height: 1.6;
      color: #262c33;
      background: #f8f9fa;
      min-height: 100vh;
    }
    
    .container {
      max-width: 1200px;
      margin: 20px auto;
      padding: 0;
      background: white;
      border: 1px solid #dae2ec;
      border-radius: 8px;
      overflow: hidden;
    }
    
    .header {
      background: white;
      color: #262c33;
      padding: 60px 40px;
      text-align: center;
      border-bottom: 1px solid #dae2ec;
    }
    

    
    .main-title {
      font-size: 2.5em;
      font-weight: 600;
      margin-bottom: 10px;
    }
    
    .subtitle {
      font-size: 1.1em;
      opacity: 0.9;
      margin-bottom: 20px;
    }
    
    .export-date {
      font-size: 0.9em;
      opacity: 0.8;
      background: #fafafa;
      padding: 4px 12px;
      border-radius: 4px;
      display: inline-block;
      border: 1px solid #dae2ec;
    }
    
    .stats-section {
      padding: 40px;
      background: #fafafa;
      border-bottom: 1px solid #dae2ec;
    }
    
    .stats-grid {
      display: grid;
      grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
      gap: 20px;
    }
    
    .stat-card {
      background: white;
      padding: 25px 20px;
      border-radius: 4px;
      text-align: center;
      border: 1px solid #dae2ec;
    }
    
    .stat-number {
      font-size: 2.2em;
      font-weight: 600;
      color: #262c33;
      display: block;
      margin-bottom: 5px;
    }
    
    .stat-label {
      color: #666;
      font-size: 0.9em;
      font-weight: 500;
      text-transform: uppercase;
      letter-spacing: 0.5px;
    }
    
    .diagram-section {
      padding: 40px;
      background: white;
      border-bottom: 1px solid #dae2ec;
    }
    
    .section-title {
      font-size: 1.8em;
      color: #262c33;
      margin-bottom: 25px;
      display: inline-block;
    }
    
    .diagram-container {
      background: #fafafa;
      border-radius: 4px;
      padding: 20px;
      text-align: center;
      border: 1px solid #dae2ec;
    }
    
    .diagram-container svg {
      max-width: 100%;
      height: auto;
      border-radius: 4px;
    }
    
    .toc-section {
      padding: 40px;
      background: #fafafa;
      border-bottom: 1px solid #dae2ec;
    }
    
    .toc-container {
      background: white;
      border-radius: 4px;
      padding: 30px;
      border: 1px solid #dae2ec;
    }
    
    .toc-list {
      list-style: none;
      columns: 2;
      column-gap: 30px;
      column-fill: balance;
    }
    
    .toc-list li {
      break-inside: avoid;
      margin-bottom: 8px;
      position: relative;
    }
    
    .toc-link {
      color: #262c33;
      text-decoration: none;
      font-weight: 500;
      transition: color 0.3s ease;
    }
    
    .toc-link:hover {
      color: #666;
    }
    
    .documentation-section {
      padding: 40px;
      background: white;
    }
    
    .element-section {
      margin-bottom: 30px;
      background: white;
      border-radius: 4px;
      border: 1px solid #dae2ec;
      overflow: hidden;
    }
    
    .element-header {
      background: white;
      color: #262c33;
      padding: 20px 25px;
      display: flex;
      align-items: center;
      gap: 15px;
      border-bottom: 1px solid #dae2ec;
    }
    
    
    .element-title-info {
      flex: 1;
    }
    
    .element-title {
      font-size: 1.3em;
      font-weight: 600;
      margin-bottom: 8px;
    }
    
    .element-meta {
      display: flex;
      gap: 15px;
      align-items: center;
    }
    
    
    .element-id {
      font-size: 0.9em;
      opacity: 0.8;
      font-family: 'Monaco', 'Consolas', monospace;
    }
    
    .element-content {
      padding: 25px;
      background: white;
    }
    
    .element-content h1,
    .element-content h2,
    .element-content h3,
    .element-content h4,
    .element-content h5,
    .element-content h6 {
      color: #262c33;
      margin-top: 20px;
      margin-bottom: 12px;
      font-weight: 600;
    }
    
    .element-content p {
      margin-bottom: 15px;
      line-height: 1.7;
    }
    
    .element-content ul,
    .element-content ol {
      margin-bottom: 15px;
      padding-left: 25px;
    }
    
    .element-content li {
      margin-bottom: 8px;
      line-height: 1.6;
    }
    
    .element-content code {
      background: #fafafa;
      padding: 2px 6px;
      border-radius: 4px;
      font-family: 'Monaco', 'Consolas', monospace;
      font-size: 0.9em;
      color: #262c33;
    }
    
    .element-content pre {
      background: #fafafa;
      padding: 15px;
      border-radius: 4px;
      overflow-x: auto;
      margin-bottom: 15px;
      border-left: 3px solid #bfcbd9;
    }
    
    .element-content blockquote {
      border-left: 3px solid #bfcbd9;
      padding-left: 15px;
      margin: 15px 0;
      color: #666;
      font-style: italic;
      background: #fafafa;
      padding: 12px 15px;
      border-radius: 0 4px 4px 0;
    }
    
    .element-content table {
      width: 100%;
      border-collapse: collapse;
      margin-bottom: 15px;
      border: 1px solid #dae2ec;
      border-radius: 4px;
      overflow: hidden;
    }
    
    .element-content th,
    .element-content td {
      padding: 10px 12px;
      text-align: left;
      border-bottom: 1px solid #dae2ec;
    }
    
    .element-content th {
      background: #fafafa;
      color: #262c33;
      font-weight: 600;
    }
    
    .element-content tr:hover {
      background: #fafafa;
    }
    
    .element-content a {
      color: #262c33;
      text-decoration: none;
      font-weight: 500;
    }
    
    .element-content a:hover {
      color: #666;
      text-decoration: underline;
    }
    
    .no-documentation {
      color: #666;
      font-style: italic;
      text-align: center;
      padding: 15px;
      background: #fafafa;
      border-radius: 4px;
    }
    
    .back-to-top {
      position: fixed;
      bottom: 30px;
      right: 30px;
      display: none;
      z-index: 1000;
    }
    
    .back-to-top-btn {
      background: white;
      color: #262c33;
      border: 1px solid #dae2ec;
      padding: 10px 12px;
      border-radius: 4px;
      cursor: pointer;
      font-size: 1em;
      transition: background-color 0.3s ease;
    }
    
    .back-to-top-btn:hover {
      background: #fafafa;
    }
    
    @media (max-width: 768px) {
      .container {
        margin: 0;
        box-shadow: none;
      }
      
      .header {
        padding: 40px 20px;
      }
      
      .main-title {
        font-size: 2.2em;
      }
      
      .stats-section,
      .diagram-section,
      .toc-section,
      .documentation-section {
        padding: 20px;
      }
      
      .stats-grid {
        grid-template-columns: 1fr;
      }
      
      .toc-list {
        columns: 1;
      }
      
      .element-header {
        padding: 20px;
        flex-direction: column;
        text-align: center;
        gap: 10px;
      }
      
      .element-meta {
        justify-content: center;
      }
      
      .element-content {
        padding: 20px;
      }
    }
    
    @media print {
      body {
        background: white;
      }
      
      .container {
        box-shadow: none;
      }
      
      .back-to-top {
        display: none;
      }
      
      .element-section {
        page-break-inside: avoid;
        break-inside: avoid;
      }
    }
    `;
	}
	/**
	* Escape HTML special characters
	*/
	_escapeHtml(unsafe) {
		return unsafe.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#039;");
	}
	/**
	* Get process information from BPMN diagram
	*/
	_getProcessInfo() {
		try {
			const rootElement = this._canvas.getRootElement();
			if (rootElement?.businessObject) {
				const bo = rootElement.businessObject;
				return {
					name: bo.name || null,
					id: bo.id || null,
					filename: "process.bpmn",
					element: rootElement
				};
			}
			return {
				name: null,
				id: null,
				filename: "process.bpmn",
				element: null
			};
		} catch (error) {
			console.error("Error getting process info:", error);
			return {
				name: null,
				id: null,
				filename: "process.bpmn",
				element: null
			};
		}
	}
	/**
	* Download file to user's system
	*/
	_downloadFile(content, filename, mimeType) {
		const blob = new Blob([content], { type: mimeType });
		const url = URL.createObjectURL(blob);
		const a = document.createElement("a");
		a.href = url;
		a.download = filename;
		document.body.appendChild(a);
		a.click();
		document.body.removeChild(a);
		URL.revokeObjectURL(url);
	}
	/**
	* Show notification to user
	*/
	_showNotification(message, type) {
		const notification = document.createElement("div");
		notification.className = `notification notification-${type}`;
		notification.textContent = message;
		Object.assign(notification.style, {
			position: "fixed",
			top: "20px",
			right: "20px",
			padding: "12px 16px",
			borderRadius: "4px",
			color: "white",
			fontSize: "14px",
			fontWeight: "500",
			zIndex: "10000",
			maxWidth: "300px",
			wordWrap: "break-word",
			backgroundColor: type === "success" ? "#28a745" : type === "warning" ? "#ffc107" : "#dc3545",
			boxShadow: "0 2px 8px rgba(0,0,0,0.2)"
		});
		this._canvas.getContainer().appendChild(notification);
		setTimeout(() => {
			if (notification.parentNode) notification.parentNode.removeChild(notification);
		}, 3e3);
	}
	destroy() {}
};

//#endregion
//#region src/extension/managers/OverviewManager.ts
var OverviewManager = class {
	_callbacks;
	_currentFilter = "all";
	_currentSearchTerm = "";
	constructor(options) {
		this._callbacks = options.callbacks;
	}
	setupOverviewEventListeners() {
		setTimeout(() => {
			document.getElementById("overview-search")?.addEventListener("input", (event) => {
				this.filterOverviewList(event.target.value);
			});
			document.getElementById("show-all")?.addEventListener("click", () => {
				this.setOverviewFilter("all");
			});
			document.getElementById("show-documented")?.addEventListener("click", () => {
				this.setOverviewFilter("documented");
			});
			document.getElementById("show-undocumented")?.addEventListener("click", () => {
				this.setOverviewFilter("undocumented");
			});
		}, 100);
	}
	refreshOverview() {
		this._updateFilterButtonStates();
		this._updateCoverageStats();
		this._updateOverviewList();
	}
	filterOverviewList(searchTerm) {
		this._currentSearchTerm = searchTerm;
		this._updateOverviewList();
	}
	setOverviewFilter(filter) {
		this._currentFilter = filter;
		const sidebar = this._callbacks.getSidebar();
		if (!sidebar) return;
		sidebar.querySelectorAll(".btn-small").forEach((btn) => {
			btn.classList.remove("active");
		});
		const activeButton = sidebar.querySelector(`#show-${filter}`);
		if (activeButton) activeButton.classList.add("active");
		this._updateOverviewList();
	}
	destroy() {}
	_updateFilterButtonStates() {
		const sidebar = this._callbacks.getSidebar();
		if (!sidebar) return;
		sidebar.querySelectorAll(".btn-small").forEach((btn) => {
			btn.classList.remove("active");
		});
		const activeButton = sidebar.querySelector(`#show-${this._currentFilter}`);
		if (activeButton) activeButton.classList.add("active");
	}
	_updateCoverageStats() {
		const sidebar = this._callbacks.getSidebar();
		if (!sidebar) return;
		const elements = this._getAllElementsWithDocumentation();
		const documentedCount = elements.filter((el) => el.hasDocumentation).length;
		const totalCount = elements.length;
		const percentage = totalCount > 0 ? Math.round(documentedCount / totalCount * 100) : 0;
		const documentedCountEl = sidebar.querySelector("#documented-count");
		if (documentedCountEl) documentedCountEl.textContent = documentedCount.toString();
		const totalCountEl = sidebar.querySelector("#total-count");
		if (totalCountEl) totalCountEl.textContent = totalCount.toString();
		const coveragePercentageEl = sidebar.querySelector("#coverage-percentage");
		if (coveragePercentageEl) coveragePercentageEl.textContent = `${percentage}%`;
		const progressBar = sidebar.querySelector("#coverage-progress");
		if (progressBar) progressBar.style.width = `${percentage}%`;
	}
	_getAllElementsWithDocumentation() {
		const elements = [];
		const seenIds = /* @__PURE__ */ new Set();
		const allElements = this._callbacks.getAllElements();
		allElements.forEach((element) => {
			if (element.businessObject?.id) {
				const bo = element.businessObject;
				const elementId = bo.id;
				if (seenIds.has(elementId)) return;
				seenIds.add(elementId);
				const documentation = this._callbacks.getElementDocumentation(element);
				elements.push({
					id: elementId,
					name: bo.name || "Unnamed",
					type: this._callbacks.getElementTypeName(element),
					hasDocumentation: !!documentation?.trim(),
					documentation: documentation || "",
					element
				});
			}
		});
		return elements.sort((a, b$1) => a.id.localeCompare(b$1.id));
	}
	_updateOverviewList() {
		const sidebar = this._callbacks.getSidebar();
		if (!sidebar) return;
		const overviewList = sidebar.querySelector("#overview-list");
		if (!overviewList) return;
		const elements = this._getAllElementsWithDocumentation();
		let filteredElements = elements;
		if (this._currentFilter === "documented") filteredElements = elements.filter((el) => el.hasDocumentation);
		else if (this._currentFilter === "undocumented") filteredElements = elements.filter((el) => !el.hasDocumentation);
		if (this._currentSearchTerm) {
			const searchTerm = this._currentSearchTerm.toLowerCase();
			filteredElements = filteredElements.filter((el) => el.id.toLowerCase().includes(searchTerm) || el.name.toLowerCase().includes(searchTerm) || el.documentation.toLowerCase().includes(searchTerm));
		}
		if (filteredElements.length === 0) {
			overviewList.innerHTML = "<div class=\"overview-loading\">No elements found</div>";
			return;
		}
		overviewList.innerHTML = filteredElements.map((element) => {
			const statusClass = element.hasDocumentation ? "documented" : "undocumented";
			const statusText = element.hasDocumentation ? "documented" : "undocumented";
			return `
        <div class="element-item ${statusClass}" data-element-id="${element.id}">
          <div class="element-header">
            <span class="element-id">${element.id}</span>
            <span class="element-status ${statusClass}">${statusText}</span>
          </div>
          <div class="element-info">
            <span>${element.name}</span>
            <span>•</span>
            <span>${element.type}</span>
          </div>
        </div>
      `;
		}).join("");
		overviewList.querySelectorAll(".element-item").forEach((card) => {
			card.addEventListener("click", () => {
				const elementId = card.getAttribute("data-element-id");
				if (elementId) {
					this._callbacks.selectElementById(elementId);
					this._callbacks.switchToElementTab();
				}
			});
		});
	}
};

//#endregion
//#region src/extension/managers/SidebarManager.ts
var SidebarManager = class {
	_canvas;
	_htmlGenerator;
	_onSidebarReady;
	_sidebar = null;
	_resizeObserver = null;
	_cleanupRaf = null;
	_isResizing = false;
	_resizeStartX = 0;
	_resizeStartWidth = 0;
	_isVerticalResizing = false;
	_resizeStartY = 0;
	_resizeStartHeight = 0;
	_customWidth = null;
	_wasVisible = false;
	constructor(options) {
		this._canvas = options.canvas;
		this._htmlGenerator = options.htmlGenerator;
		this._onSidebarReady = options.onSidebarReady;
	}
	initializeSidebar() {
		const existingSidebar = document.getElementById("documentation-sidebar");
		if (existingSidebar) existingSidebar.remove();
		const existingHandle = document.getElementById("horizontal-resize-handle");
		if (existingHandle) existingHandle.remove();
		const existingHelpPopover = document.getElementById("help-popover");
		if (existingHelpPopover) existingHelpPopover.remove();
		const sidebar = document.createElement("div");
		sidebar.id = "documentation-sidebar";
		sidebar.className = "documentation-sidebar";
		sidebar.style.display = "none";
		sidebar.innerHTML = this._htmlGenerator.generateSidebarHTML();
		const canvasContainer = this._getCanvasContainer();
		const currentPosition = window.getComputedStyle(canvasContainer).position;
		if (currentPosition === "static") canvasContainer.style.position = "relative";
		canvasContainer.appendChild(sidebar);
		this._sidebar = sidebar;
		const helpPopoverDiv = document.createElement("div");
		helpPopoverDiv.innerHTML = this._htmlGenerator.generateHelpPopoverHTML();
		const helpPopover = helpPopoverDiv.firstElementChild;
		canvasContainer.appendChild(helpPopover);
		const horizontalResizeHandle = document.createElement("div");
		horizontalResizeHandle.id = "horizontal-resize-handle";
		horizontalResizeHandle.className = "horizontal-resize-handle";
		canvasContainer.appendChild(horizontalResizeHandle);
		if (this._onSidebarReady) setTimeout(() => {
			this._onSidebarReady?.(sidebar);
		}, 10);
		setTimeout(() => {
			this.updateSidebarPosition();
			this.setupResizeObserver();
			this.setupResizeHandles();
		}, 100);
	}
	showSidebar() {
		if (this._sidebar && !this._sidebar.parentElement) {
			this.initializeSidebar();
			setTimeout(() => {
				this.showSidebar();
			}, 10);
			return;
		}
		this.updateSidebarPosition();
		if (this._sidebar) {
			this._sidebar.style.display = "flex";
			this._sidebar.classList.add("visible");
		}
		const horizontalHandle = document.getElementById("horizontal-resize-handle");
		if (horizontalHandle) horizontalHandle.style.display = "block";
		this._wasVisible = true;
	}
	hideSidebar() {
		if (this._sidebar) {
			this._wasVisible = this._sidebar.classList.contains("visible");
			this._sidebar.classList.remove("visible");
			this._sidebar.style.display = "none";
		}
		const horizontalHandle = document.getElementById("horizontal-resize-handle");
		if (horizontalHandle) horizontalHandle.style.display = "none";
	}
	updateSidebarPosition() {
		const canvasContainer = this._getCanvasContainer();
		const containerRect = canvasContainer.getBoundingClientRect();
		const propertiesPanel = document.querySelector(".bio-properties-panel-container") || document.querySelector(".djs-properties-panel") || document.querySelector("[data-tab=\"properties\"]") || document.querySelector(".properties-panel");
		if (propertiesPanel) {
			const panelRect = propertiesPanel.getBoundingClientRect();
			const topOffset = Math.max(panelRect.top - containerRect.top, 0);
			const bottomOffset = Math.max(containerRect.bottom - panelRect.bottom, 0);
			const availableHeight = containerRect.height - topOffset - bottomOffset;
			if (this._sidebar) {
				this._sidebar.style.top = `${topOffset}px`;
				this._sidebar.style.height = `${Math.max(availableHeight, 300)}px`;
				if (!this._isResizing) {
					const width = this._customWidth ? `${this._customWidth}px` : "350px";
					this._sidebar.style.setProperty("width", width, "important");
					const horizontalHandle = document.getElementById("horizontal-resize-handle");
					if (horizontalHandle) {
						const sidebarWidth = this._customWidth || 350;
						horizontalHandle.style.right = `${sidebarWidth}px`;
						horizontalHandle.style.top = `${topOffset}px`;
						horizontalHandle.style.height = `${Math.max(availableHeight, 900)}px`;
					}
				}
			}
		} else if (this._sidebar) {
			this._sidebar.style.right = "0px";
			this._sidebar.style.top = "0px";
			this._sidebar.style.height = "100%";
			if (!this._isResizing) {
				const width = this._customWidth ? `${this._customWidth}px` : "350px";
				this._sidebar.style.setProperty("width", width, "important");
				const horizontalHandle = document.getElementById("horizontal-resize-handle");
				if (horizontalHandle) {
					const sidebarWidth = this._customWidth || 350;
					horizontalHandle.style.right = `${sidebarWidth}px`;
					horizontalHandle.style.top = "0px";
					horizontalHandle.style.height = "100%";
				}
			}
		}
	}
	setupResizeObserver() {
		if (this._resizeObserver) this._resizeObserver.disconnect();
		const propertiesPanel = document.querySelector(".bio-properties-panel-container") || document.querySelector(".djs-properties-panel") || document.querySelector("[data-tab=\"properties\"]") || document.querySelector(".properties-panel");
		if (propertiesPanel && window.ResizeObserver) {
			this._resizeObserver = new ResizeObserver(() => {
				requestAnimationFrame(() => {
					this.updateSidebarPosition();
				});
			});
			this._resizeObserver.observe(propertiesPanel);
			const parentContainer = propertiesPanel.parentElement;
			if (parentContainer) this._resizeObserver.observe(parentContainer);
			const rightPanel = document.querySelector(".djs-properties-panel-parent") || document.querySelector(".properties-panel-parent") || propertiesPanel.closest(".panel");
			if (rightPanel && rightPanel !== propertiesPanel) this._resizeObserver.observe(rightPanel);
		}
		let rafId;
		const updatePosition = () => {
			if (this._sidebar?.classList.contains("visible") && this._sidebar.style.display !== "none" && !this._isResizing && !this._isVerticalResizing) this.updateSidebarPosition();
			rafId = requestAnimationFrame(updatePosition);
		};
		updatePosition();
		this._cleanupRaf = () => {
			if (rafId) cancelAnimationFrame(rafId);
		};
		window.addEventListener("resize", () => {
			this.updateSidebarPosition();
		});
	}
	setupResizeHandles() {
		this._setupHorizontalResize();
		this._setupVerticalResize();
	}
	getSidebar() {
		return this._sidebar;
	}
	isSidebarVisible() {
		return this._sidebar?.classList.contains("visible") ?? false;
	}
	destroy() {
		if (this._resizeObserver) this._resizeObserver.disconnect();
		if (this._cleanupRaf) this._cleanupRaf();
		if (this._sidebar) this._sidebar.remove();
		const horizontalHandle = document.getElementById("horizontal-resize-handle");
		if (horizontalHandle) horizontalHandle.remove();
		const helpPopover = document.getElementById("help-popover");
		if (helpPopover) helpPopover.remove();
	}
	_getCanvasContainer() {
		return this._canvas?.getContainer() ?? document.body;
	}
	_setupHorizontalResize() {
		const horizontalHandle = document.getElementById("horizontal-resize-handle");
		if (!horizontalHandle) return;
		let rafId = null;
		let pendingWidth = null;
		const handleMouseDown = (e) => {
			e.preventDefault();
			this._isResizing = true;
			this._resizeStartX = e.clientX;
			this._resizeStartWidth = this._sidebar?.offsetWidth || 350;
			document.body.style.cursor = "ew-resize";
			document.body.style.userSelect = "none";
			document.addEventListener("mousemove", handleMouseMove);
			document.addEventListener("mouseup", handleMouseUp);
		};
		const updateResize = () => {
			if (pendingWidth !== null && this._sidebar) {
				this._sidebar.style.setProperty("width", `${pendingWidth}px`, "important");
				const horizontalHandle$1 = document.getElementById("horizontal-resize-handle");
				if (horizontalHandle$1) horizontalHandle$1.style.right = `${pendingWidth}px`;
				pendingWidth = null;
			}
			rafId = null;
		};
		const handleMouseMove = (e) => {
			if (!this._isResizing || !this._sidebar) return;
			e.preventDefault();
			const deltaX = this._resizeStartX - e.clientX;
			const newWidth = this._resizeStartWidth + deltaX;
			const minWidth = 250;
			const maxWidth = window.innerWidth * .6;
			const constrainedWidth = Math.max(minWidth, Math.min(maxWidth, newWidth));
			this._customWidth = constrainedWidth;
			pendingWidth = constrainedWidth;
			if (rafId === null) rafId = requestAnimationFrame(updateResize);
		};
		const handleMouseUp = () => {
			this._isResizing = false;
			document.body.style.cursor = "";
			document.body.style.userSelect = "";
			if (rafId !== null) {
				cancelAnimationFrame(rafId);
				updateResize();
			}
			document.removeEventListener("mousemove", handleMouseMove);
			document.removeEventListener("mouseup", handleMouseUp);
		};
		horizontalHandle.addEventListener("mousedown", handleMouseDown);
	}
	_setupVerticalResize() {
		const verticalHandle = document.getElementById("resize-handle");
		if (!verticalHandle) return;
		let rafId = null;
		let pendingHeight = null;
		const handleMouseDown = (e) => {
			e.preventDefault();
			this._isVerticalResizing = true;
			this._resizeStartY = e.clientY;
			const previewElement = document.getElementById("doc-preview");
			this._resizeStartHeight = previewElement?.offsetHeight || 200;
			document.body.style.cursor = "ns-resize";
			document.body.style.userSelect = "none";
			document.addEventListener("mousemove", handleMouseMove);
			document.addEventListener("mouseup", handleMouseUp);
		};
		const updateResize = () => {
			if (pendingHeight !== null) {
				const previewElement = document.getElementById("doc-preview");
				if (previewElement) previewElement.style.height = `${pendingHeight}px`;
				pendingHeight = null;
			}
			rafId = null;
		};
		const handleMouseMove = (e) => {
			if (!this._isVerticalResizing) return;
			e.preventDefault();
			const deltaY = e.clientY - this._resizeStartY;
			const newHeight = this._resizeStartHeight + deltaY;
			const minHeight = 100;
			const maxHeight = window.innerHeight * .6;
			const constrainedHeight = Math.max(minHeight, Math.min(maxHeight, newHeight));
			pendingHeight = constrainedHeight;
			if (rafId === null) rafId = requestAnimationFrame(updateResize);
		};
		const handleMouseUp = () => {
			this._isVerticalResizing = false;
			document.body.style.cursor = "";
			document.body.style.userSelect = "";
			if (rafId !== null) {
				cancelAnimationFrame(rafId);
				updateResize();
			}
			document.removeEventListener("mousemove", handleMouseMove);
			document.removeEventListener("mouseup", handleMouseUp);
		};
		verticalHandle.addEventListener("mousedown", handleMouseDown);
	}
};

//#endregion
//#region src/extension/managers/TabManager.ts
var TabManager = class {
	_callbacks;
	constructor(options) {
		this._callbacks = options.callbacks;
	}
	setupTabEventListeners() {
		setTimeout(() => {
			document.getElementById("element-tab")?.addEventListener("click", () => {
				this.switchTab("element");
			});
			document.getElementById("overview-tab")?.addEventListener("click", () => {
				this.switchTab("overview");
				this._callbacks.onOverviewTabActivated();
			});
		}, 100);
	}
	switchTab(tabName) {
		if (!this._callbacks.isSidebarVisible()) return;
		const sidebar = this._callbacks.getSidebar();
		if (!sidebar) return;
		Array.from(sidebar.querySelectorAll(".tab-btn")).forEach((btn) => {
			const btnEl = btn;
			if (btnEl.dataset.tab === tabName) btnEl.classList.add("active");
			else btnEl.classList.remove("active");
		});
		Array.from(sidebar.querySelectorAll(".tab-panel")).forEach((panel) => {
			const panelEl = panel;
			if (panelEl.id === `${tabName}-panel`) panelEl.classList.add("active");
			else panelEl.classList.remove("active");
		});
		const elementMetadata = sidebar.querySelector("#element-metadata");
		if (elementMetadata) elementMetadata.style.display = "block";
		if (tabName === "element") this._callbacks.onElementTabActivated();
	}
	destroy() {}
};

//#endregion
//#region src/extension/managers/ViewManager.ts
var ViewManager = class {
	_currentView = "diagram";
	_viewCheckInterval = null;
	_callbacks;
	constructor(callbacks) {
		this._callbacks = callbacks;
	}
	getCurrentView() {
		return this._currentView;
	}
	setupViewDetection() {
		this._viewCheckInterval = setInterval(() => {
			const newView = this._detectCurrentView();
			if (newView !== this._currentView) {
				this._currentView = newView;
				this._callbacks.onViewChanged(newView);
				this.updateSidebarVisibility();
			}
		}, 500);
	}
	updateSidebarVisibility() {
		if (this._currentView === "xml") this._callbacks.hideSidebar();
		else if (this._currentView === "diagram") {
			const currentElement = this._callbacks.getCurrentElement();
			if (currentElement) {
				const documentation = this._callbacks.getElementDocumentation(currentElement);
				this._callbacks.showSidebar(documentation || "");
			}
		}
	}
	destroy() {
		if (this._viewCheckInterval) {
			clearInterval(this._viewCheckInterval);
			this._viewCheckInterval = null;
		}
	}
	_detectCurrentView() {
		const xmlEditor = document.querySelector(".cm-editor");
		const codeEditor = document.querySelector(".CodeMirror");
		if (xmlEditor && xmlEditor.offsetParent !== null || codeEditor && codeEditor.offsetParent !== null) return "xml";
		return "diagram";
	}
};

//#endregion
//#region src/extension/templates/HtmlTemplateGenerator.ts
var HtmlTemplateGenerator = class {
	_options;
	constructor(options) {
		this._options = options;
	}
	generateSidebarHTML() {
		const editorSection = this._generateEditorSection();
		return `
      <div class="documentation-header">
        <div class="header-content">
          <div class="title-row">
            <h3>Documentation${this._options.isModeler ? "" : " (Read-only)"}</h3>
            <button class="help-btn" id="help-btn">?</button>
          </div>
          <div class="element-metadata" id="element-metadata">
            <span class="element-name" id="element-name"></span>
          </div>
        </div>
        <button class="close-btn" id="close-sidebar">×</button>
      </div>
      <div class="tab-container">
        <div class="tab-buttons">
          <button class="tab-btn active" id="element-tab" data-tab="element">Element</button>
          <button class="tab-btn" id="overview-tab" data-tab="overview">Overview</button>
        </div>
        <button class="btn-export" id="export-btn">
          <span class="export-btn-icon">📤</span>
          <span>Export</span>
        </button>
      </div>
      <div class="tab-content">
        <div class="tab-panel active" id="element-panel">
          <div class="documentation-content">
            <div class="documentation-preview" id="doc-preview"></div>
            ${editorSection}
          </div>
        </div>
        <div class="tab-panel" id="overview-panel">
          <div class="overview-content">
            <div class="overview-header">
              <div class="coverage-summary">
                <div class="coverage-stats">
                  <span class="stat-item">
                    <strong id="documented-count">0</strong> documented
                  </span>
                  <span class="stat-item">
                    <strong id="total-count">0</strong> total elements
                  </span>
                  <span class="stat-item">
                    <strong id="coverage-percentage">0%</strong> coverage
                  </span>
                </div>
                <div class="coverage-bar">
                  <div class="coverage-progress" id="coverage-progress"></div>
                </div>
              </div>
              <div class="overview-search">
                <input type="text" id="overview-search" placeholder="Search documentation..." />
                <div class="search-actions">
                  <button class="btn-small" id="show-documented">Documented</button>
                  <button class="btn-small" id="show-undocumented">Undocumented</button>
                  <button class="btn-small active" id="show-all">All</button>
                </div>
              </div>
            </div>
            <div class="overview-list" id="overview-list">
              <div class="overview-loading">Loading elements...</div>
            </div>
          </div>
        </div>
      </div>
    `;
	}
	generateHelpPopoverHTML() {
		const helpContent = this._generateHelpContent();
		return `
      <div class="help-popover" id="help-popover">
        <div class="help-content">
          <h4>Documentation Panel Guide</h4>
          ${helpContent}
        </div>
      </div>
    `;
	}
	_generateHelpContent() {
		return this._options.isModeler ? `
      <div class="help-section">
        <strong>What is this panel?</strong>
        <p>This panel allows you to add and view documentation for BPMN elements in your diagram.</p>
      </div>
      <div class="help-section">
        <strong>How to use:</strong>
        <ul>
          <li><strong>Select an element</strong> - Click on any BPMN element (task, gateway, event, etc.) to view or edit its documentation</li>
          <li><strong>Edit documentation</strong> - Use the editor below to write documentation in Markdown format</li>
          <li><strong>Preview</strong> - The top section shows a live preview of your formatted documentation</li>
        </ul>
      </div>
      <div class="help-section">
        <strong>Markdown support:</strong>
        <p>Use standard Markdown syntax for formatting: **bold**, *italic*, lists, links, and more.</p>
      </div>
      <div class="help-section">
        <strong>Creating links:</strong>
        <p>Link to other BPMN elements using their ID:</p>
        <code>[Element Name](#elementId)</code>
        <p>Example: <code>[Check Inventory](#Task_CheckInventory)</code></p>
        <p>Link to external resources:</p>
        <code>[External Link](https://example.com)</code>
        <p><em>Tip: Element IDs can be found in the properties panel or by selecting the element. Type # inside () for autocomplete suggestions.</em></p>
      </div>
    ` : `
      <div class="help-section">
        <strong>What is this panel?</strong>
        <p>This panel displays documentation for BPMN elements in this diagram.</p>
      </div>
      <div class="help-section">
        <strong>How to use:</strong>
        <ul>
          <li><strong>Select an element</strong> - Click on any BPMN element (task, gateway, event, etc.) to view its documentation</li>
          <li><strong>Navigate</strong> - Click on element links to jump to related elements in the diagram</li>
          <li><strong>Overview</strong> - Use the Overview tab to see all documented elements</li>
        </ul>
      </div>
      <div class="help-section">
        <strong>Reading documentation:</strong>
        <p>Documentation is displayed in formatted view. Click on element links (shown in blue) to navigate to related elements in the diagram.</p>
      </div>
    `;
	}
	_generateEditorSection() {
		return this._options.isModeler ? `
      <div class="documentation-bottom">
        <div class="resize-handle" id="resize-handle"></div>
        <div class="documentation-editor">
          <div class="editor-container">
            <textarea id="doc-textarea" placeholder="Write documentation in Markdown..."></textarea>
            <div class="autocomplete-dropdown" id="autocomplete-dropdown">
              <div class="autocomplete-list" id="autocomplete-list"></div>
            </div>
          </div>
        </div>
      </div>
    ` : "";
	}
};

//#endregion
//#region src/extension/index.ts
var DocumentationExtension = class {
	_eventBus;
	_elementRegistry;
	_modeling;
	_moddle;
	_selection;
	_canvas;
	_currentElement;
	_isModeler;
	_currentView;
	_viewManager;
	_htmlGenerator;
	_sidebarManager;
	_tabManager;
	_overviewManager;
	_autocompleteManager;
	_exportManager;
	constructor(eventBus, elementRegistry, injector, moddle, selection, canvas) {
		this._modeling = injector.get("modeling", false);
		this._isModeler = !!this._modeling;
		this._eventBus = eventBus;
		this._elementRegistry = elementRegistry;
		this._moddle = moddle;
		this._selection = selection;
		this._canvas = canvas;
		this._currentElement = null;
		this._currentView = "diagram";
		this._htmlGenerator = new HtmlTemplateGenerator({ isModeler: this._isModeler });
		this._sidebarManager = new SidebarManager({
			canvas: this._canvas,
			htmlGenerator: this._htmlGenerator,
			onSidebarReady: () => this._onSidebarReady()
		});
		const tabCallbacks = {
			onOverviewTabActivated: () => this._overviewManager.refreshOverview(),
			onElementTabActivated: () => {},
			getSidebar: () => this._sidebarManager.getSidebar(),
			isSidebarVisible: () => this._sidebarManager.isSidebarVisible()
		};
		this._tabManager = new TabManager({ callbacks: tabCallbacks });
		const viewCallbacks = {
			onViewChanged: (newView) => {
				this._currentView = newView;
			},
			hideSidebar: () => this._sidebarManager.hideSidebar(),
			showSidebar: (documentation) => this._showSidebar(documentation),
			getElementDocumentation: (element) => this._getElementDocumentation(element),
			getCurrentElement: () => this._currentElement
		};
		this._viewManager = new ViewManager(viewCallbacks);
		const overviewCallbacks = {
			getAllElements: () => this._elementRegistry.getAll(),
			getElementDocumentation: (element) => this._getElementDocumentation(element),
			getElementTypeName: (element) => this._getElementTypeName(element),
			getSidebar: () => this._sidebarManager.getSidebar(),
			selectElementById: (elementId) => this._selectElementById(elementId),
			switchToElementTab: () => this._tabManager.switchTab("element")
		};
		this._overviewManager = new OverviewManager({ callbacks: overviewCallbacks });
		const autocompleteCallbacks = {
			getAllElements: () => this._elementRegistry.getAll(),
			getElementTypeName: (element) => this._getElementTypeName(element),
			getCanvasContainer: () => this._getCanvasContainer(),
			updatePreview: () => this._updatePreview(),
			saveDocumentationLive: () => this._saveDocumentationLive(),
			selectElementById: (elementId) => this._selectElementById(elementId),
			getCurrentElement: () => this._currentElement
		};
		this._autocompleteManager = new AutocompleteManager({ callbacks: autocompleteCallbacks });
		this._exportManager = new ExportManager(this._elementRegistry, this._moddle, this._canvas);
		this._sidebarManager.initializeSidebar();
		this._viewManager.setupViewDetection();
		this._exportManager.setupExportEventListeners();
		eventBus.on("element.click", (event) => {
			const { element } = event;
			this._handleElementClick(element);
		});
		eventBus.on("selection.changed", (event) => {
			const { newSelection } = event;
			if (newSelection && newSelection.length > 0) this._handleElementClick(newSelection[0]);
			else this._sidebarManager.hideSidebar();
		});
		eventBus.on("connection.click", (event) => {
			const { element } = event;
			this._handleElementClick(element);
		});
		eventBus.on("canvas.click", () => {
			setTimeout(() => {
				if (!this._currentElement) this._sidebarManager.hideSidebar();
			}, 10);
		});
		eventBus.on("import.done", () => {
			this._handleDiagramImport();
		});
		eventBus.on("import.parse.complete", () => {
			this._handleDiagramImport();
		});
		eventBus.on("diagram.destroy", () => {
			this._handleDiagramDestroy();
		});
		eventBus.on("diagram.clear", () => {
			this._handleDiagramClear();
		});
	}
	_onSidebarReady() {
		const helpBtn = document.getElementById("help-btn");
		if (helpBtn) {
			helpBtn.replaceWith(helpBtn.cloneNode(true));
			const newHelpBtn = document.getElementById("help-btn");
			newHelpBtn?.addEventListener("click", (event) => {
				event.preventDefault();
				event.stopPropagation();
				this._toggleHelpPopover();
			});
		}
		document.addEventListener("click", (event) => {
			const helpPopover = document.getElementById("help-popover");
			const helpBtn$1 = document.getElementById("help-btn");
			if (helpPopover?.classList.contains("visible") && !(event.target instanceof Node && helpPopover.contains(event.target)) && !(event.target instanceof Node && helpBtn$1 && helpBtn$1.contains(event.target))) this._hideHelpPopover();
		});
		if (this._isModeler) {
			const textarea = document.getElementById("doc-textarea");
			if (textarea) textarea.addEventListener("input", () => {
				this._updatePreview();
				this._saveDocumentationLive();
			});
			this._autocompleteManager.setupAutocompleteEventListeners();
		}
		setTimeout(() => {
			document.getElementById("close-sidebar")?.addEventListener("click", () => {
				this._currentElement = null;
				this._sidebarManager.hideSidebar();
			});
		}, 100);
		this._tabManager.setupTabEventListeners();
		this._overviewManager.setupOverviewEventListeners();
		this._setupScrollEventHandling();
	}
	_setupScrollEventHandling() {
		setTimeout(() => {
			const sidebar = document.getElementById("documentation-sidebar");
			if (sidebar) {
				sidebar.addEventListener("wheel", (event) => {
					if (event.target instanceof Element && sidebar.contains(event.target)) event.stopPropagation();
				}, { passive: false });
				sidebar.addEventListener("scroll", (event) => {
					if (event.target instanceof Element && sidebar.contains(event.target)) event.stopPropagation();
				}, { passive: true });
				const sidebarScrollableSelectors = [
					"#doc-preview",
					"#overview-list",
					"#doc-textarea",
					"#autocomplete-dropdown"
				];
				sidebarScrollableSelectors.forEach((selector) => {
					const element = sidebar.querySelector(selector);
					if (element) {
						element.addEventListener("wheel", (event) => {
							event.stopPropagation();
						}, { passive: false });
						element.addEventListener("scroll", (event) => {
							event.stopPropagation();
						}, { passive: true });
					}
				});
			}
			const helpPopover = document.getElementById("help-popover");
			if (helpPopover) {
				helpPopover.addEventListener("wheel", (event) => {
					event.stopPropagation();
				}, { passive: false });
				helpPopover.addEventListener("scroll", (event) => {
					event.stopPropagation();
				}, { passive: true });
			}
		}, 150);
	}
	_handleElementClick(element) {
		if (this._currentView === "xml") return;
		if (!element || !element.businessObject) {
			this._currentElement = null;
			this._sidebarManager.hideSidebar();
			return;
		}
		const documentation = this._getElementDocumentation(element);
		const hasCapability = this._hasDocumentationCapability(element);
		if (documentation || hasCapability) {
			this._currentElement = element;
			this._showSidebar(documentation || "");
		} else {
			this._currentElement = null;
			this._sidebarManager.hideSidebar();
		}
	}
	_getElementDocumentation(element) {
		const businessObject = element.businessObject;
		if (businessObject.documentation && businessObject.documentation.length > 0) return businessObject.documentation[0].text;
		return null;
	}
	_hasDocumentationCapability(element) {
		return element.businessObject;
	}
	_showSidebar(documentation) {
		if (this._isModeler) {
			const textarea = document.getElementById("doc-textarea");
			if (textarea) textarea.value = documentation || "";
		}
		this._updateElementMetadata();
		this._updatePreview();
		this._sidebarManager.showSidebar();
	}
	_hideSidebar() {
		this._sidebarManager.hideSidebar();
	}
	_toggleHelpPopover() {
		const helpPopover = document.getElementById("help-popover");
		console.log("Toggle help popover:", helpPopover?.classList.contains("visible"));
		if (helpPopover?.classList.contains("visible")) this._hideHelpPopover();
		else if (helpPopover) this._showHelpPopover();
	}
	_showHelpPopover() {
		const helpPopover = document.getElementById("help-popover");
		if (helpPopover) helpPopover.classList.add("visible");
	}
	_hideHelpPopover() {
		const helpPopover = document.getElementById("help-popover");
		if (helpPopover) helpPopover.classList.remove("visible");
	}
	_getCanvasContainer() {
		return this._canvas?.getContainer() ?? document.body;
	}
	async _updatePreview() {
		const preview = document.getElementById("doc-preview");
		if (!preview) return;
		let value = "";
		if (this._isModeler) {
			const textarea = document.getElementById("doc-textarea");
			if (!textarea) return;
			value = textarea.value;
		} else if (this._currentElement) value = this._getElementDocumentation(this._currentElement) || "";
		if (value?.trim()) {
			const rendered = await Promise.resolve(k(value));
			preview.innerHTML = typeof rendered === "string" ? rendered : "";
			this._setupElementLinks(preview);
		} else preview.innerHTML = "<em>No documentation.</em>";
	}
	_setupElementLinks(container) {
		const links = container.querySelectorAll("a[href^=\"#\"]");
		links.forEach((link) => {
			link.addEventListener("click", (event) => {
				event.preventDefault();
				const elementId = link.getAttribute("href")?.substring(1);
				if (elementId) this._selectElementById(elementId);
			});
			link.addEventListener("mouseenter", () => {
				link.classList.add("hovered");
			});
			link.addEventListener("mouseleave", () => {
				link.classList.remove("hovered");
			});
		});
	}
	_selectElementById(elementId) {
		try {
			const element = this._elementRegistry.get(elementId);
			if (element) {
				this._selection.select(element);
				this._canvas.scrollToElement(element);
			} else {
				console.warn(`Element with ID "${elementId}" not found in the diagram`);
				this._showLinkNotification(`Element "${elementId}" not found`);
			}
		} catch (error) {
			console.error("Error selecting element:", error);
			this._showLinkNotification(`Error selecting element "${elementId}"`);
		}
	}
	_showLinkNotification(message) {
		const notification = document.createElement("div");
		notification.textContent = message;
		notification.style.cssText = `
      position: fixed;
      top: 20px;
      right: 20px;
      background: #f44336;
      color: white;
      padding: 8px 16px;
      border-radius: 4px;
      font-size: 12px;
      z-index: 10000;
      box-shadow: 0 2px 8px rgba(0,0,0,0.2);
    `;
		this._getCanvasContainer().appendChild(notification);
		setTimeout(() => {
			if (notification.parentNode) notification.parentNode.removeChild(notification);
		}, 3e3);
	}
	_saveDocumentationLive() {
		if (!this._currentElement || !this._modeling) return;
		const textarea = document.getElementById("doc-textarea");
		if (!textarea) return;
		const documentation = textarea.value;
		try {
			const documentationArray = [];
			if (documentation.trim()) {
				const docElement = this._moddle.create("bpmn:Documentation", { text: documentation });
				documentationArray.push(docElement);
			}
			this._modeling.updateProperties(this._currentElement, { documentation: documentationArray });
		} catch (error) {
			console.error("Error saving documentation:", error);
		}
	}
	_updateElementMetadata() {
		if (!this._currentElement) return;
		const businessObject = this._currentElement.businessObject;
		const elementId = businessObject.id || "Unknown ID";
		const elementNameElement = document.getElementById("element-name");
		if (elementNameElement) elementNameElement.textContent = elementId;
	}
	_getElementTypeName(element) {
		if (is(element, "bpmn:Task")) return "Task";
		if (is(element, "bpmn:UserTask")) return "User Task";
		if (is(element, "bpmn:ServiceTask")) return "Service Task";
		if (is(element, "bpmn:ScriptTask")) return "Script Task";
		if (is(element, "bpmn:CallActivity")) return "Call Activity";
		if (is(element, "bpmn:SubProcess")) return "Sub Process";
		if (is(element, "bpmn:StartEvent")) return "Start Event";
		if (is(element, "bpmn:EndEvent")) return "End Event";
		if (is(element, "bpmn:IntermediateThrowEvent")) return "Intermediate Event";
		if (is(element, "bpmn:IntermediateCatchEvent")) return "Intermediate Event";
		if (is(element, "bpmn:Gateway")) return "Gateway";
		if (is(element, "bpmn:ExclusiveGateway")) return "Exclusive Gateway";
		if (is(element, "bpmn:ParallelGateway")) return "Parallel Gateway";
		if (is(element, "bpmn:InclusiveGateway")) return "Inclusive Gateway";
		if (is(element, "bpmn:SequenceFlow")) return "Sequence Flow";
		if (is(element, "bpmn:MessageFlow")) return "Message Flow";
		if (is(element, "bpmn:DataObject")) return "Data Object";
		if (is(element, "bpmn:DataStore")) return "Data Store";
		if (is(element, "bpmn:Lane")) return "Lane";
		if (is(element, "bpmn:Participant")) return "Pool";
		if (is(element, "bpmn:Process")) return "Process";
		return "Element";
	}
	_handleDiagramImport() {
		this._currentElement = null;
		this._sidebarManager.hideSidebar();
		this._sidebarManager.initializeSidebar();
	}
	_handleDiagramDestroy() {
		this._cleanup();
	}
	_handleDiagramClear() {
		this._currentElement = null;
		this._sidebarManager.hideSidebar();
	}
	_cleanup() {
		this._currentElement = null;
		this._sidebarManager.hideSidebar();
	}
	destroy() {
		this._cleanup();
		this._sidebarManager.destroy();
		this._viewManager.destroy();
		this._autocompleteManager.destroy();
		this._exportManager.destroy();
	}
};
var extension_default = {
	__init__: ["documentationExtension"],
	documentationExtension: [
		"type",
		DocumentationExtension,
		"eventBus",
		"elementRegistry",
		"injector",
		"moddle",
		"selection",
		"canvas"
	]
};

//#endregion
//#region src/camunda-modeler-entry.ts
registerBpmnJSPlugin(extension_default);

//#endregion
//# sourceMappingURL=camunda-modeler-entry.js.map