@pinkpixel/marzipan 1.1.2 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/README.md +4 -5
  2. package/dist/index-CEbRSdyd.js +31 -0
  3. package/dist/index-CEbRSdyd.js.map +1 -0
  4. package/dist/index-xgEXHeDh.js +31 -0
  5. package/dist/index-xgEXHeDh.js.map +1 -0
  6. package/dist/index.d.ts +0 -7
  7. package/dist/index.d.ts.map +1 -1
  8. package/dist/index.js +710 -620
  9. package/dist/index.js.map +1 -1
  10. package/dist/parser.d.ts +8 -1
  11. package/dist/parser.d.ts.map +1 -1
  12. package/dist/parser.js +63 -6
  13. package/dist/parser.js.map +1 -1
  14. package/dist/plugins/accentSwatchPlugin.d.ts.map +1 -1
  15. package/dist/plugins/accentSwatchPlugin.js +96 -80
  16. package/dist/plugins/accentSwatchPlugin.js.map +1 -1
  17. package/dist/plugins/index.d.ts +1 -1
  18. package/dist/plugins/index.d.ts.map +1 -1
  19. package/dist/plugins/index.js +24 -27
  20. package/dist/plugins/index.js.map +1 -1
  21. package/dist/plugins/tableGenerator.js +1 -1
  22. package/dist/plugins/tableGridPlugin.d.ts +1 -1
  23. package/dist/plugins/tableGridPlugin.d.ts.map +1 -1
  24. package/dist/plugins/tableGridPlugin.js +143 -42
  25. package/dist/plugins/tableGridPlugin.js.map +1 -1
  26. package/dist/plugins/tablePlugin.js +1 -1
  27. package/dist/plugins/utils/table.d.ts +12 -1
  28. package/dist/plugins/utils/table.d.ts.map +1 -1
  29. package/dist/plugins/utils/table.js +31 -6
  30. package/dist/plugins/utils/table.js.map +1 -1
  31. package/dist/styles.d.ts.map +1 -1
  32. package/dist/styles.js +65 -1
  33. package/dist/styles.js.map +1 -1
  34. package/dist/table-CJHCBhPo.js +33 -0
  35. package/dist/table-CJHCBhPo.js.map +1 -0
  36. package/docs/index.md +2 -3
  37. package/docs/plugins.md +85 -7
  38. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1,16 +1,15 @@
1
- import { i as at } from "./index-kKw24iiA.js";
2
- import { accentSwatchPlugin as ct, accentSwatchStyles as pt } from "./plugins/accentSwatchPlugin.js";
3
- import { b as mt, r as ht } from "./table-DMIy93NJ.js";
4
- import { imagePickerPlugin as ft } from "./plugins/imagePicker.js";
5
- import { imageManagerPlugin as bt, imageManagerStyles as vt } from "./plugins/imageManagerPlugin.js";
6
- import { imagePickerPlugin as kt } from "./plugins/imagePickerPlugin.js";
7
- import { mermaidExternalPlugin as xt } from "./plugins/mermaidExternal.js";
8
- import { mermaidPlugin as Lt } from "./plugins/mermaidPlugin.js";
9
- import { tableGeneratorPlugin as Ct } from "./plugins/tableGenerator.js";
10
- import { tableGridPlugin as Tt, tableGridStyles as Ht } from "./plugins/tableGridPlugin.js";
11
- import { tablePlugin as Mt } from "./plugins/tablePlugin.js";
12
- import { tinyHighlightPlugin as _t, tinyHighlightStyles as Pt } from "./plugins/tinyHighlight.js";
13
- const I = class I {
1
+ import { i as st } from "./index-CEbRSdyd.js";
2
+ import { b as ct, r as pt } from "./table-CJHCBhPo.js";
3
+ import { imagePickerPlugin as mt } from "./plugins/imagePicker.js";
4
+ import { imageManagerPlugin as ut, imageManagerStyles as ft } from "./plugins/imageManagerPlugin.js";
5
+ import { imagePickerPlugin as bt } from "./plugins/imagePickerPlugin.js";
6
+ import { mermaidExternalPlugin as wt } from "./plugins/mermaidExternal.js";
7
+ import { mermaidPlugin as yt } from "./plugins/mermaidPlugin.js";
8
+ import { tableGeneratorPlugin as zt } from "./plugins/tableGenerator.js";
9
+ import { tableGridPlugin as St, tableGridStyles as Ct } from "./plugins/tableGridPlugin.js";
10
+ import { tablePlugin as Et } from "./plugins/tablePlugin.js";
11
+ import { tinyHighlightPlugin as $t, tinyHighlightStyles as Mt } from "./plugins/tinyHighlight.js";
12
+ const N = class N {
14
13
  /**
15
14
  * Reset link index (call before parsing a new document)
16
15
  */
@@ -148,16 +147,28 @@ const I = class I {
148
147
  static isTableSeparator(e) {
149
148
  return /^\|\s*[-:]+\s*(?:\|\s*[-:]+\s*)*\|$/.test(e);
150
149
  }
150
+ /**
151
+ * Parse column alignments from a table separator row
152
+ * @param {string} separatorText - Raw text of the separator row
153
+ * @returns {string[]} Array of alignment values ('left', 'center', 'right')
154
+ */
155
+ static parseTableAlignments(e) {
156
+ return e.slice(1, -1).split(/(?<!\\)\|/).map((n) => {
157
+ const r = n.trim(), o = r.startsWith(":"), a = r.endsWith(":");
158
+ return o && a ? "center" : a ? "right" : "left";
159
+ });
160
+ }
151
161
  /**
152
162
  * Parse a table row into cells
153
163
  * @param {string} html - HTML table row
154
164
  * @param {string} tag - Tag to use for cells (th or td)
165
+ * @param {string[]} alignments - Optional column alignment array
155
166
  * @returns {string} HTML table row
156
167
  */
157
- static parseTableRow(e, t = "td") {
158
- return `<tr>${e.slice(1, -1).split(/(?<!\\)\|/).map((o) => {
159
- const s = o.trim(), a = this.parseInlineElements(s || "&nbsp;");
160
- return `<${t}>${a}</${t}>`;
168
+ static parseTableRow(e, t = "td", n = []) {
169
+ return `<tr>${e.slice(1, -1).split(/(?<!\\)\|/).map((a, s) => {
170
+ const l = a.trim(), c = this.parseInlineElements(l || "&nbsp;"), d = n[s], p = d && d !== "left" ? ` style="text-align: ${d}"` : "";
171
+ return `<${t}${p}>${c}</${t}>`;
161
172
  }).join("")}</tr>`;
162
173
  }
163
174
  /**
@@ -175,8 +186,8 @@ const I = class I {
175
186
  */
176
187
  static parseImages(e) {
177
188
  return e.replace(/!\[([^\]]*)\]\(([^\s)]+)(?:\s+"([^"]+)")?\)/g, (t, n, r, o) => {
178
- const s = this.sanitizeUrl(r), a = this.escapeHtml(n || ""), l = o ? ` title="${this.escapeHtml(o)}"` : "";
179
- return `<img src="${s}" alt="${a}"${l} class="marzipan-image" />`;
189
+ const a = this.sanitizeUrl(r), s = this.escapeHtml(n || ""), l = o ? ` title="${this.escapeHtml(o)}"` : "";
190
+ return `<img src="${a}" alt="${s}"${l} class="marzipan-image" />`;
180
191
  });
181
192
  }
182
193
  /**
@@ -191,8 +202,8 @@ const I = class I {
191
202
  "mailto:",
192
203
  "ftp://",
193
204
  "ftps://"
194
- ].some((a) => n.startsWith(a)), s = t.startsWith("/") || t.startsWith("#") || t.startsWith("?") || t.startsWith(".") || !t.includes(":") && !t.includes("//");
195
- return o || s ? e : "#";
205
+ ].some((s) => n.startsWith(s)), a = t.startsWith("/") || t.startsWith("#") || t.startsWith("?") || t.startsWith(".") || !t.includes(":") && !t.includes("//");
206
+ return o || a ? e : "#";
196
207
  }
197
208
  /**
198
209
  * Parse links
@@ -213,53 +224,53 @@ const I = class I {
213
224
  static identifyAndProtectSanctuaries(e) {
214
225
  const t = /* @__PURE__ */ new Map();
215
226
  let n = 0, r = e;
216
- const o = [], s = /\[([^\]]+)\]\(([^)]+)\)/g;
217
- let a;
218
- for (; (a = s.exec(e)) !== null; ) {
219
- const m = a.index + a[0].indexOf("](") + 2, u = m + a[2].length;
220
- o.push({ start: m, end: u });
227
+ const o = [], a = /\[([^\]]+)\]\(([^)]+)\)/g;
228
+ let s;
229
+ for (; (s = a.exec(e)) !== null; ) {
230
+ const h = s.index + s[0].indexOf("](") + 2, m = h + s[2].length;
231
+ o.push({ start: h, end: m });
221
232
  }
222
233
  const l = /(?<!`)(`+)(?!`)((?:(?!\1).)+?)(\1)(?!`)/g;
223
- let p;
234
+ let c;
224
235
  const d = [];
225
- for (; (p = l.exec(e)) !== null; ) {
226
- const c = p.index, m = p.index + p[0].length;
236
+ for (; (c = l.exec(e)) !== null; ) {
237
+ const p = c.index, h = c.index + c[0].length;
227
238
  o.some(
228
- (h) => c >= h.start && m <= h.end
239
+ (u) => p >= u.start && h <= u.end
229
240
  ) || d.push({
230
- match: p[0],
231
- index: p.index,
232
- openTicks: p[1],
233
- content: p[2],
234
- closeTicks: p[3]
241
+ match: c[0],
242
+ index: c.index,
243
+ openTicks: c[1],
244
+ content: c[2],
245
+ closeTicks: c[3]
235
246
  });
236
247
  }
237
- return d.sort((c, m) => m.index - c.index), d.forEach((c) => {
238
- const m = `${n++}`;
239
- t.set(m, {
248
+ return d.sort((p, h) => h.index - p.index), d.forEach((p) => {
249
+ const h = `${n++}`;
250
+ t.set(h, {
240
251
  type: "code",
241
- original: c.match,
242
- openTicks: c.openTicks,
243
- content: c.content,
244
- closeTicks: c.closeTicks
245
- }), r = r.substring(0, c.index) + m + r.substring(c.index + c.match.length);
246
- }), r = r.replace(/!\[([^\]]*)\]\(([^\s)]+)(?:\s+"([^"]+)")?\)/g, (c, m, u, h) => {
252
+ original: p.match,
253
+ openTicks: p.openTicks,
254
+ content: p.content,
255
+ closeTicks: p.closeTicks
256
+ }), r = r.substring(0, p.index) + h + r.substring(p.index + p.match.length);
257
+ }), r = r.replace(/!\[([^\]]*)\]\(([^\s)]+)(?:\s+"([^"]+)")?\)/g, (p, h, m, u) => {
247
258
  const f = `${n++}`;
248
259
  return t.set(f, {
249
260
  type: "image",
250
- original: c,
251
- alt: m,
252
- url: u,
253
- title: h
261
+ original: p,
262
+ alt: h,
263
+ url: m,
264
+ title: u
254
265
  }), f;
255
- }), r = r.replace(/\[([^\]]+)\]\(([^)]+)\)/g, (c, m, u) => {
256
- const h = `${n++}`;
257
- return t.set(h, {
266
+ }), r = r.replace(/\[([^\]]+)\]\(([^)]+)\)/g, (p, h, m) => {
267
+ const u = `${n++}`;
268
+ return t.set(u, {
258
269
  type: "link",
259
- original: c,
260
- linkText: m,
261
- url: u
262
- }), h;
270
+ original: p,
271
+ linkText: h,
272
+ url: m
273
+ }), u;
263
274
  }), { protectedText: r, sanctuaries: t };
264
275
  }
265
276
  /**
@@ -270,28 +281,28 @@ const I = class I {
270
281
  */
271
282
  static restoreAndTransformSanctuaries(e, t) {
272
283
  return Array.from(t.keys()).sort((r, o) => {
273
- const s = e.indexOf(r), a = e.indexOf(o);
274
- return s - a;
284
+ const a = e.indexOf(r), s = e.indexOf(o);
285
+ return a - s;
275
286
  }).forEach((r) => {
276
287
  const o = t.get(r);
277
- let s;
288
+ let a;
278
289
  if (o.type === "code")
279
- s = `<code><span class="syntax-marker">${o.openTicks}</span>${this.escapeHtml(o.content)}<span class="syntax-marker">${o.closeTicks}</span></code>`;
290
+ a = `<code><span class="syntax-marker">${o.openTicks}</span>${this.escapeHtml(o.content)}<span class="syntax-marker">${o.closeTicks}</span></code>`;
280
291
  else if (o.type === "image") {
281
- const a = this.sanitizeUrl(o.url), l = this.escapeHtml(o.alt || ""), p = o.title ? ` title="${this.escapeHtml(o.title)}"` : "";
282
- s = `<img src="${a}" alt="${l}"${p} class="marzipan-image" />`;
292
+ const s = this.sanitizeUrl(o.url), l = this.escapeHtml(o.alt || ""), c = o.title ? ` title="${this.escapeHtml(o.title)}"` : "";
293
+ a = `<img src="${s}" alt="${l}"${c} class="marzipan-image" />`;
283
294
  } else if (o.type === "link") {
284
- let a = o.linkText;
285
- t.forEach((d, c) => {
286
- if (a.includes(c) && d.type === "code") {
287
- const m = `<code><span class="syntax-marker">${d.openTicks}</span>${this.escapeHtml(d.content)}<span class="syntax-marker">${d.closeTicks}</span></code>`;
288
- a = a.replace(c, m);
295
+ let s = o.linkText;
296
+ t.forEach((d, p) => {
297
+ if (s.includes(p) && d.type === "code") {
298
+ const h = `<code><span class="syntax-marker">${d.openTicks}</span>${this.escapeHtml(d.content)}<span class="syntax-marker">${d.closeTicks}</span></code>`;
299
+ s = s.replace(p, h);
289
300
  }
290
- }), a = this.parseStrikethrough(a), a = this.parseBold(a), a = this.parseItalic(a);
301
+ }), s = this.parseStrikethrough(s), s = this.parseBold(s), s = this.parseItalic(s);
291
302
  const l = `--link-${this.linkIndex++}`;
292
- s = `<a href="${this.sanitizeUrl(o.url)}" style="anchor-name: ${l}"><span class="syntax-marker">[</span>${a}<span class="syntax-marker url-part">](${this.escapeHtml(o.url)})</span></a>`;
303
+ a = `<a href="${this.sanitizeUrl(o.url)}" style="anchor-name: ${l}"><span class="syntax-marker">[</span>${s}<span class="syntax-marker url-part">](${this.escapeHtml(o.url)})</span></a>`;
293
304
  }
294
- e = e.replace(r, s);
305
+ e = e.replace(r, a);
295
306
  }), e;
296
307
  }
297
308
  /**
@@ -314,12 +325,12 @@ const I = class I {
314
325
  let n = this.escapeHtml(e);
315
326
  n = this.preserveIndentation(n, e);
316
327
  let r = "paragraph", o = "";
317
- const s = this.parseHorizontalRule(n);
318
- if (s)
319
- return r = "hr", o = ` data-block-id="${this.generateBlockId()}" data-block-type="${r}" data-line-start="${t}" data-line-end="${t}"`, s.replace("<div", `<div${o}`);
320
- const a = this.parseCodeBlock(n);
328
+ const a = this.parseHorizontalRule(n);
321
329
  if (a)
322
- return r = "code-fence", o = ` data-block-id="${this.generateBlockId()}" data-block-type="${r}" data-line-start="${t}" data-line-end="${t}"`, a.replace("<div", `<div${o}`);
330
+ return r = "hr", o = ` data-block-id="${this.generateBlockId()}" data-block-type="${r}" data-line-start="${t}" data-line-end="${t}"`, a.replace("<div", `<div${o}`);
331
+ const s = this.parseCodeBlock(n);
332
+ if (s)
333
+ return r = "code-fence", o = ` data-block-id="${this.generateBlockId()}" data-block-type="${r}" data-line-start="${t}" data-line-end="${t}"`, s.replace("<div", `<div${o}`);
323
334
  const l = e.trim();
324
335
  return /^#{1,6}\s/.test(l) ? r = "heading" : /^>/.test(l) ? r = "quote" : (/^[-*+]\s/.test(l) || /^\d+\.\s/.test(l)) && (r = "list-item"), n = this.parseHeader(n), n = this.parseBlockquote(n), n = this.parseBulletList(n), n = this.parseNumberedList(n), n = this.parseInlineElements(n), o = ` data-block-id="${this.generateBlockId()}" data-block-type="${r}" data-line-start="${t}" data-line-end="${t}"`, n.trim() === "" ? `<div${o}>&nbsp;</div>` : `<div${o}>${n}</div>`;
325
336
  }
@@ -335,25 +346,29 @@ const I = class I {
335
346
  const r = e.split(`
336
347
  `);
337
348
  let o = !1;
338
- const a = r.map((l, p) => {
339
- if (n && p === t) {
349
+ const s = r.map((l, c) => {
350
+ if (n && c === t) {
340
351
  const m = this.escapeHtml(l) || "&nbsp;";
341
- return `<div class="raw-line" data-block-id="${this.generateBlockId()}" data-block-type="paragraph" data-line-start="${p}" data-line-end="${p}">${m}</div>`;
352
+ return `<div class="raw-line" data-block-id="${this.generateBlockId()}" data-block-type="paragraph" data-line-start="${c}" data-line-end="${c}">${m}</div>`;
342
353
  }
343
354
  if (/^```[^`]*$/.test(l))
344
- return o = !o, this.parseLine(l, p);
355
+ return o = !o, this.parseLine(l, c);
345
356
  if (o) {
346
357
  const m = this.escapeHtml(l), u = this.preserveIndentation(m, l);
347
- return `<div data-block-id="${this.generateBlockId()}" data-block-type="code-content" data-line-start="${p}" data-line-end="${p}">${u || "&nbsp;"}</div>`;
358
+ return `<div data-block-id="${this.generateBlockId()}" data-block-type="code-content" data-line-start="${c}" data-line-end="${c}">${u || "&nbsp;"}</div>`;
359
+ }
360
+ const p = this.escapeHtml(l), h = l.match(/^<!--\s*mz-table:\s*(.+?)\s*-->$/);
361
+ if (h) {
362
+ const m = this.generateBlockId();
363
+ return `<div class="mz-table-annotation" data-mz-annotation="${this.escapeHtml(h[1])}" data-block-id="${m}" data-block-type="table-annotation" data-line-start="${c}" data-line-end="${c}" style="display:none">${p}</div>`;
348
364
  }
349
- const c = this.escapeHtml(l);
350
- if (this.isTableRow(c)) {
365
+ if (this.isTableRow(p)) {
351
366
  const m = this.generateBlockId();
352
- return this.isTableSeparator(c) ? `<div class="table-separator" data-block-id="${m}" data-block-type="table-separator" data-line-start="${p}" data-line-end="${p}">${c}</div>` : `<div class="table-row" data-block-id="${m}" data-block-type="table-row" data-line-start="${p}" data-line-end="${p}">${c}</div>`;
367
+ return this.isTableSeparator(p) ? `<div class="table-separator" data-block-id="${m}" data-block-type="table-separator" data-line-start="${c}" data-line-end="${c}">${p}</div>` : `<div class="table-row" data-block-id="${m}" data-block-type="table-row" data-line-start="${c}" data-line-end="${c}">${p}</div>`;
353
368
  }
354
- return this.parseLine(l, p);
369
+ return this.parseLine(l, c);
355
370
  }).join("");
356
- return this.postProcessHTML(a);
371
+ return this.postProcessHTML(s);
357
372
  }
358
373
  /**
359
374
  * Post-process HTML to consolidate lists and code blocks
@@ -365,69 +380,82 @@ const I = class I {
365
380
  return this.postProcessHTMLManual(e);
366
381
  const t = document.createElement("div");
367
382
  t.innerHTML = e;
368
- let n = null, r = null, o = null, s = !1, a = null, l = !1;
383
+ let n = null, r = null, o = null, a = !1, s = null, l = !1, c = [], d = null;
369
384
  const p = Array.from(t.children);
370
- for (let d = 0; d < p.length; d++) {
371
- const c = p[d];
372
- if (!c.parentNode) continue;
373
- if (c.classList && (c.classList.contains("table-row") || c.classList.contains("table-separator"))) {
374
- if (c.classList.contains("table-separator")) {
375
- if (!a) {
376
- c.remove();
385
+ for (let h = 0; h < p.length; h++) {
386
+ const m = p[h];
387
+ if (!m.parentNode) continue;
388
+ if (m.classList && m.classList.contains("mz-table-annotation")) {
389
+ d = m.getAttribute("data-mz-annotation") || "", m.remove();
390
+ continue;
391
+ }
392
+ if (m.classList && (m.classList.contains("table-row") || m.classList.contains("table-separator"))) {
393
+ if (m.classList.contains("table-separator")) {
394
+ if (!s) {
395
+ m.remove();
377
396
  continue;
378
397
  }
379
- l = !1, c.remove();
398
+ c = this.parseTableAlignments(m.textContent || ""), s.querySelectorAll("thead th").forEach((P, L) => {
399
+ const z = c[L];
400
+ z && z !== "left" && (P.style.textAlign = z);
401
+ }), l = !1, m.remove();
380
402
  continue;
381
403
  }
382
- a || (a = document.createElement("table"), a.className = "marzipan-table", t.insertBefore(a, c), l = !0);
383
- const f = c.textContent, g = l ? "th" : "td", b = this.parseTableRow(f, g);
384
- let v;
385
- l ? (v = a.querySelector("thead"), v || (v = document.createElement("thead"), a.appendChild(v))) : (v = a.querySelector("tbody"), v || (v = document.createElement("tbody"), a.appendChild(v))), v.innerHTML += b, c.remove();
404
+ if (!s) {
405
+ if (s = document.createElement("table"), s.className = "marzipan-table", d) {
406
+ const B = d.match(/style=(\S+)/), P = d.match(/border=(\S+)/);
407
+ B && s.classList.add(`mz-table-${B[1]}`), P && s.classList.add(`mz-border-${P[1]}`), d = null;
408
+ }
409
+ t.insertBefore(s, m), l = !0, c = [];
410
+ }
411
+ const b = m.textContent, v = l ? "th" : "td", k = this.parseTableRow(b, v, l ? [] : c);
412
+ let y;
413
+ l ? (y = s.querySelector("thead"), y || (y = document.createElement("thead"), s.appendChild(y))) : (y = s.querySelector("tbody"), y || (y = document.createElement("tbody"), s.appendChild(y))), y.innerHTML += k, m.remove();
386
414
  continue;
387
415
  } else
388
- a = null, l = !1;
389
- const m = c.querySelector(".code-fence");
390
- if (m) {
391
- const h = m.textContent;
392
- if (h.startsWith("```"))
393
- if (s) {
394
- s = !1, o = null;
416
+ s = null, l = !1, c = [];
417
+ const u = m.querySelector(".code-fence");
418
+ if (u) {
419
+ const g = u.textContent;
420
+ if (g.startsWith("```"))
421
+ if (a) {
422
+ a = !1, o = null;
395
423
  continue;
396
424
  } else {
397
- s = !0, o = document.createElement("pre");
398
- const f = document.createElement("code");
399
- o.appendChild(f), o.className = "code-block";
400
- const g = h.slice(3).trim();
401
- g && (f.className = `language-${g}`), t.insertBefore(o, c.nextSibling), o._codeElement = f;
425
+ a = !0, o = document.createElement("pre");
426
+ const b = document.createElement("code");
427
+ o.appendChild(b), o.className = "code-block";
428
+ const v = g.slice(3).trim();
429
+ v && (b.className = `language-${v}`), t.insertBefore(o, m.nextSibling), o._codeElement = b;
402
430
  continue;
403
431
  }
404
432
  }
405
- if (s && o && c.tagName === "DIV" && !c.querySelector(".code-fence")) {
406
- const h = o._codeElement || o.querySelector("code");
407
- h.textContent.length > 0 && (h.textContent += `
433
+ if (a && o && m.tagName === "DIV" && !m.querySelector(".code-fence")) {
434
+ const g = o._codeElement || o.querySelector("code");
435
+ g.textContent.length > 0 && (g.textContent += `
408
436
  `);
409
- const f = c.textContent.replace(/\u00A0/g, " ");
410
- h.textContent += f, c.remove();
437
+ const b = m.textContent.replace(/\u00A0/g, " ");
438
+ g.textContent += b, m.remove();
411
439
  continue;
412
440
  }
413
- let u = null;
414
- if (c.tagName === "DIV" && (u = c.querySelector("li")), u) {
415
- const h = u.classList.contains("bullet-list"), f = u.classList.contains("ordered-list");
416
- if (!h && !f) {
441
+ let f = null;
442
+ if (m.tagName === "DIV" && (f = m.querySelector("li")), f) {
443
+ const g = f.classList.contains("bullet-list"), b = f.classList.contains("ordered-list");
444
+ if (!g && !b) {
417
445
  n = null, r = null;
418
446
  continue;
419
447
  }
420
- const g = h ? "ul" : "ol";
421
- (!n || r !== g) && (n = document.createElement(g), t.insertBefore(n, c), r = g);
422
- const b = [];
423
- for (const v of c.childNodes)
424
- if (v.nodeType === 3 && v.textContent.match(/^\u00A0+$/))
425
- b.push(v.cloneNode(!0));
426
- else if (v === u)
448
+ const v = g ? "ul" : "ol";
449
+ (!n || r !== v) && (n = document.createElement(v), t.insertBefore(n, m), r = v);
450
+ const k = [];
451
+ for (const y of m.childNodes)
452
+ if (y.nodeType === 3 && y.textContent.match(/^\u00A0+$/))
453
+ k.push(y.cloneNode(!0));
454
+ else if (y === f)
427
455
  break;
428
- b.forEach((v) => {
429
- u.insertBefore(v, u.firstChild);
430
- }), n.appendChild(u), c.remove();
456
+ k.forEach((y) => {
457
+ f.insertBefore(y, f.firstChild);
458
+ }), n.appendChild(f), m.remove();
431
459
  } else
432
460
  n = null, r = null;
433
461
  }
@@ -442,31 +470,31 @@ const I = class I {
442
470
  let t = e;
443
471
  t = t.replace(/((?:<div>(?:&nbsp;)*<li class="bullet-list">.*?<\/li><\/div>\s*)+)/gs, (r) => {
444
472
  const o = r.match(/<div>(?:&nbsp;)*<li class="bullet-list">.*?<\/li><\/div>/gs) || [];
445
- return o.length > 0 ? "<ul>" + o.map((a) => {
446
- const l = a.match(/<div>((?:&nbsp;)*)<li/), p = a.match(/<li class="bullet-list">.*?<\/li>/);
447
- if (l && p) {
473
+ return o.length > 0 ? "<ul>" + o.map((s) => {
474
+ const l = s.match(/<div>((?:&nbsp;)*)<li/), c = s.match(/<li class="bullet-list">.*?<\/li>/);
475
+ if (l && c) {
448
476
  const d = l[1];
449
- return p[0].replace(/<li class="bullet-list">/, `<li class="bullet-list">${d}`);
477
+ return c[0].replace(/<li class="bullet-list">/, `<li class="bullet-list">${d}`);
450
478
  }
451
- return p ? p[0] : "";
479
+ return c ? c[0] : "";
452
480
  }).filter(Boolean).join("") + "</ul>" : r;
453
481
  }), t = t.replace(/((?:<div>(?:&nbsp;)*<li class="ordered-list">.*?<\/li><\/div>\s*)+)/gs, (r) => {
454
482
  const o = r.match(/<div>(?:&nbsp;)*<li class="ordered-list">.*?<\/li><\/div>/gs) || [];
455
- return o.length > 0 ? "<ol>" + o.map((a) => {
456
- const l = a.match(/<div>((?:&nbsp;)*)<li/), p = a.match(/<li class="ordered-list">.*?<\/li>/);
457
- if (l && p) {
483
+ return o.length > 0 ? "<ol>" + o.map((s) => {
484
+ const l = s.match(/<div>((?:&nbsp;)*)<li/), c = s.match(/<li class="ordered-list">.*?<\/li>/);
485
+ if (l && c) {
458
486
  const d = l[1];
459
- return p[0].replace(/<li class="ordered-list">/, `<li class="ordered-list">${d}`);
487
+ return c[0].replace(/<li class="ordered-list">/, `<li class="ordered-list">${d}`);
460
488
  }
461
- return p ? p[0] : "";
489
+ return c ? c[0] : "";
462
490
  }).filter(Boolean).join("") + "</ol>" : r;
463
491
  });
464
492
  const n = /<div><span class="code-fence">(```[^<]*)<\/span><\/div>(.*?)<div><span class="code-fence">(```)<\/span><\/div>/gs;
465
- return t = t.replace(n, (r, o, s, a) => {
466
- const p = (s.match(/<div>(.*?)<\/div>/gs) || []).map((u) => u.replace(/<div>(.*?)<\/div>/s, "$1").replace(/&nbsp;/g, " ")).join(`
467
- `), d = o.slice(3).trim(), c = d ? ` class="language-${d}"` : "";
468
- let m = `<div><span class="code-fence">${o}</span></div>`;
469
- return m += `<pre class="code-block"><code${c}>${p}</code></pre>`, m += `<div><span class="code-fence">${a}</span></div>`, m;
493
+ return t = t.replace(n, (r, o, a, s) => {
494
+ const c = (a.match(/<div>(.*?)<\/div>/gs) || []).map((m) => m.replace(/<div>(.*?)<\/div>/s, "$1").replace(/&nbsp;/g, " ")).join(`
495
+ `), d = o.slice(3).trim(), p = d ? ` class="language-${d}"` : "";
496
+ let h = `<div><span class="code-fence">${o}</span></div>`;
497
+ return h += `<pre class="code-block"><code${p}>${c}</code></pre>`, h += `<div><span class="code-fence">${s}</span></div>`, h;
470
498
  }), t;
471
499
  }
472
500
  /**
@@ -478,30 +506,30 @@ const I = class I {
478
506
  static getListContext(e, t) {
479
507
  const n = e.split(`
480
508
  `);
481
- let r = 0, o = 0, s = 0;
482
- for (let m = 0; m < n.length; m++) {
483
- const u = n[m].length;
484
- if (r + u >= t) {
485
- o = m, s = r;
509
+ let r = 0, o = 0, a = 0;
510
+ for (let h = 0; h < n.length; h++) {
511
+ const m = n[h].length;
512
+ if (r + m >= t) {
513
+ o = h, a = r;
486
514
  break;
487
515
  }
488
- r += u + 1;
516
+ r += m + 1;
489
517
  }
490
- const a = n[o], l = s + a.length, p = a.match(this.LIST_PATTERNS.checkbox);
491
- if (p)
518
+ const s = n[o], l = a + s.length, c = s.match(this.LIST_PATTERNS.checkbox);
519
+ if (c)
492
520
  return {
493
521
  inList: !0,
494
522
  listType: "checkbox",
495
- indent: p[1],
523
+ indent: c[1],
496
524
  marker: "-",
497
- checked: p[2] === "x",
498
- content: p[3],
499
- lineStart: s,
525
+ checked: c[2] === "x",
526
+ content: c[3],
527
+ lineStart: a,
500
528
  lineEnd: l,
501
- markerEndPos: s + p[1].length + p[2].length + 5
529
+ markerEndPos: a + c[1].length + c[2].length + 5
502
530
  // indent + "- [ ] "
503
531
  };
504
- const d = a.match(this.LIST_PATTERNS.bullet);
532
+ const d = s.match(this.LIST_PATTERNS.bullet);
505
533
  if (d)
506
534
  return {
507
535
  inList: !0,
@@ -509,31 +537,31 @@ const I = class I {
509
537
  indent: d[1],
510
538
  marker: d[2],
511
539
  content: d[3],
512
- lineStart: s,
540
+ lineStart: a,
513
541
  lineEnd: l,
514
- markerEndPos: s + d[1].length + d[2].length + 1
542
+ markerEndPos: a + d[1].length + d[2].length + 1
515
543
  // indent + marker + space
516
544
  };
517
- const c = a.match(this.LIST_PATTERNS.numbered);
518
- return c ? {
545
+ const p = s.match(this.LIST_PATTERNS.numbered);
546
+ return p ? {
519
547
  inList: !0,
520
548
  listType: "numbered",
521
- indent: c[1],
522
- marker: parseInt(c[2]),
523
- content: c[3],
524
- lineStart: s,
549
+ indent: p[1],
550
+ marker: parseInt(p[2]),
551
+ content: p[3],
552
+ lineStart: a,
525
553
  lineEnd: l,
526
- markerEndPos: s + c[1].length + c[2].length + 2
554
+ markerEndPos: a + p[1].length + p[2].length + 2
527
555
  // indent + number + ". "
528
556
  } : {
529
557
  inList: !1,
530
558
  listType: null,
531
559
  indent: "",
532
560
  marker: null,
533
- content: a,
534
- lineStart: s,
561
+ content: s,
562
+ lineStart: a,
535
563
  lineEnd: l,
536
- markerEndPos: s
564
+ markerEndPos: a
537
565
  };
538
566
  }
539
567
  /**
@@ -562,29 +590,29 @@ const I = class I {
562
590
  const t = e.split(`
563
591
  `), n = /* @__PURE__ */ new Map();
564
592
  let r = !1;
565
- return t.map((s) => {
566
- const a = s.match(this.LIST_PATTERNS.numbered);
567
- if (a) {
568
- const l = a[1], p = l.length, d = a[3];
593
+ return t.map((a) => {
594
+ const s = a.match(this.LIST_PATTERNS.numbered);
595
+ if (s) {
596
+ const l = s[1], c = l.length, d = s[3];
569
597
  r || n.clear();
570
- const c = (n.get(p) || 0) + 1;
571
- n.set(p, c);
572
- for (const [m] of n)
573
- m > p && n.delete(m);
574
- return r = !0, `${l}${c}. ${d}`;
598
+ const p = (n.get(c) || 0) + 1;
599
+ n.set(c, p);
600
+ for (const [h] of n)
601
+ h > c && n.delete(h);
602
+ return r = !0, `${l}${p}. ${d}`;
575
603
  } else
576
- return (s.trim() === "" || !s.match(/^\s/)) && (r = !1, n.clear()), s;
604
+ return (a.trim() === "" || !a.match(/^\s/)) && (r = !1, n.clear()), a;
577
605
  }).join(`
578
606
  `);
579
607
  }
580
608
  };
581
- I.linkIndex = 0, I.blockIndex = 0, I.LIST_PATTERNS = {
609
+ N.linkIndex = 0, N.blockIndex = 0, N.LIST_PATTERNS = {
582
610
  bullet: /^(\s*)([-*+])\s+(.*)$/,
583
611
  numbered: /^(\s*)(\d+)\.\s+(.*)$/,
584
612
  checkbox: /^(\s*)-\s+\[([ x])\]\s+(.*)$/
585
613
  };
586
- let H = I;
587
- const L = {
614
+ let $ = N;
615
+ const C = {
588
616
  bold: {
589
617
  prefix: "**",
590
618
  suffix: "**",
@@ -662,64 +690,64 @@ function E(i) {
662
690
  };
663
691
  return e.scanFor = i.scanFor ?? null, e;
664
692
  }
665
- let B = !1;
666
- function ce(i) {
667
- B = i;
693
+ let j = !1;
694
+ function de(i) {
695
+ j = i;
668
696
  }
669
- function F() {
670
- return B;
697
+ function D() {
698
+ return j;
671
699
  }
672
- function k(i, e, t) {
673
- B && (console.group(`🔍 ${i}`), console.log(e), console.groupEnd());
700
+ function x(i, e, t) {
701
+ j && (console.group(`🔍 ${i}`), console.log(e), console.groupEnd());
674
702
  }
675
- function N(i, e) {
676
- if (!B) return;
703
+ function F(i, e) {
704
+ if (!j) return;
677
705
  const t = i.value.slice(i.selectionStart, i.selectionEnd);
678
706
  console.group(`📍 Selection: ${e}`), console.log("Position:", `${i.selectionStart}-${i.selectionEnd}`), console.log("Selected text:", JSON.stringify(t)), console.log("Length:", t.length);
679
707
  const n = i.value.slice(Math.max(0, i.selectionStart - 10), i.selectionStart), r = i.value.slice(i.selectionEnd, Math.min(i.value.length, i.selectionEnd + 10));
680
708
  console.log("Context:", `${JSON.stringify(n)}[SELECTION]${JSON.stringify(r)}`), console.groupEnd();
681
709
  }
682
- function V(i) {
683
- B && (console.group("📝 Result"), console.log("Text to insert:", JSON.stringify(i.text)), console.log("New selection:", `${i.selectionStart}-${i.selectionEnd}`), console.groupEnd());
710
+ function q(i) {
711
+ j && (console.group("📝 Result"), console.log("Text to insert:", JSON.stringify(i.text)), console.log("New selection:", `${i.selectionStart}-${i.selectionEnd}`), console.groupEnd());
684
712
  }
685
- let x = null;
686
- function T(i, e) {
687
- const t = F();
713
+ let S = null;
714
+ function H(i, e) {
715
+ const t = D();
688
716
  t && (console.group("🔧 insertText"), console.log("Current selection:", `${i.selectionStart}-${i.selectionEnd}`), console.log("Text to insert:", JSON.stringify(e.text)), console.log("New selection to set:", e.selectionStart, "-", e.selectionEnd)), i.focus();
689
- const n = i.selectionStart, r = i.selectionEnd, o = i.value.slice(0, n), s = i.value.slice(r);
690
- t && (console.log("Before text (last 20):", JSON.stringify(o.slice(-20))), console.log("After text (first 20):", JSON.stringify(s.slice(0, 20))), console.log(
717
+ const n = i.selectionStart, r = i.selectionEnd, o = i.value.slice(0, n), a = i.value.slice(r);
718
+ t && (console.log("Before text (last 20):", JSON.stringify(o.slice(-20))), console.log("After text (first 20):", JSON.stringify(a.slice(0, 20))), console.log(
691
719
  "Selected text being replaced:",
692
720
  JSON.stringify(i.value.slice(n, r))
693
721
  ));
694
- const a = i.value;
695
- if (x === null || x === !0) {
722
+ const s = i.value;
723
+ if (S === null || S === !0) {
696
724
  i.contentEditable = "true";
697
725
  try {
698
- x = document.execCommand("insertText", !1, e.text), t && console.log(
726
+ S = document.execCommand("insertText", !1, e.text), t && console.log(
699
727
  "execCommand returned:",
700
- x,
728
+ S,
701
729
  "for text with",
702
730
  e.text.split(`
703
731
  `).length,
704
732
  "lines"
705
733
  );
706
734
  } catch (l) {
707
- x = !1, t && console.log("execCommand threw error:", l);
735
+ S = !1, t && console.log("execCommand threw error:", l);
708
736
  }
709
737
  i.contentEditable = "false";
710
738
  }
711
- if (t && (console.log("canInsertText before:", x), console.log("execCommand result:", x)), x) {
712
- const l = o + e.text + s, p = i.value;
713
- t && (console.log("Expected length:", l.length), console.log("Actual length:", p.length)), p !== l && t && (console.log("execCommand changed the value but not as expected"), console.log("Expected:", JSON.stringify(l.slice(0, 100))), console.log("Actual:", JSON.stringify(p.slice(0, 100))));
739
+ if (t && (console.log("canInsertText before:", S), console.log("execCommand result:", S)), S) {
740
+ const l = o + e.text + a, c = i.value;
741
+ t && (console.log("Expected length:", l.length), console.log("Actual length:", c.length)), c !== l && t && (console.log("execCommand changed the value but not as expected"), console.log("Expected:", JSON.stringify(l.slice(0, 100))), console.log("Actual:", JSON.stringify(c.slice(0, 100))));
714
742
  }
715
- if (!x)
716
- if (t && console.log("Using manual insertion"), i.value === a) {
743
+ if (!S)
744
+ if (t && console.log("Using manual insertion"), i.value === s) {
717
745
  t && console.log("Value unchanged, doing manual replacement");
718
746
  try {
719
747
  document.execCommand("ms-beginUndoUnit");
720
748
  } catch {
721
749
  }
722
- i.value = o + e.text + s;
750
+ i.value = o + e.text + a;
723
751
  try {
724
752
  document.execCommand("ms-endUndoUnit");
725
753
  } catch {
@@ -728,27 +756,27 @@ function T(i, e) {
728
756
  } else t && console.log("Value was changed by execCommand, skipping manual insertion");
729
757
  t && console.log("Setting selection range:", e.selectionStart, e.selectionEnd), e.selectionStart != null && e.selectionEnd != null ? i.setSelectionRange(e.selectionStart, e.selectionEnd) : i.setSelectionRange(n, i.selectionEnd), t && (console.log("Final value length:", i.value.length), console.groupEnd());
730
758
  }
731
- function pe(i) {
759
+ function me(i) {
732
760
  switch (i) {
733
761
  case "native":
734
- x = !0;
762
+ S = !0;
735
763
  break;
736
764
  case "manual":
737
- x = !1;
765
+ S = !1;
738
766
  break;
739
767
  default:
740
- x = null;
768
+ S = null;
741
769
  break;
742
770
  }
743
771
  }
744
- function Ee() {
745
- return x === !0 ? "native" : x === !1 ? "manual" : "auto";
772
+ function Te() {
773
+ return S === !0 ? "native" : S === !1 ? "manual" : "auto";
746
774
  }
747
- function O(i) {
775
+ function U(i) {
748
776
  return i.trim().split(`
749
777
  `).length > 1;
750
778
  }
751
- function Te(i, e) {
779
+ function Ee(i, e) {
752
780
  let t = e;
753
781
  for (; i[t] && i[t - 1] != null && !/\s/.test(i[t - 1]); )
754
782
  t -= 1;
@@ -761,7 +789,7 @@ function He(i, e, t) {
761
789
  n += 1;
762
790
  return n;
763
791
  }
764
- function de(i) {
792
+ function he(i) {
765
793
  const e = i.value.split(`
766
794
  `);
767
795
  let t = 0;
@@ -772,134 +800,134 @@ function de(i) {
772
800
  }
773
801
  function $e(i, e, t, n = !1) {
774
802
  if (i.selectionStart === i.selectionEnd)
775
- i.selectionStart = Te(i.value, i.selectionStart), i.selectionEnd = He(i.value, i.selectionEnd, n);
803
+ i.selectionStart = Ee(i.value, i.selectionStart), i.selectionEnd = He(i.value, i.selectionEnd, n);
776
804
  else {
777
- const r = i.selectionStart - e.length, o = i.selectionEnd + t.length, s = i.value.slice(r, i.selectionStart) === e, a = i.value.slice(i.selectionEnd, o) === t;
778
- s && a && (i.selectionStart = r, i.selectionEnd = o);
805
+ const r = i.selectionStart - e.length, o = i.selectionEnd + t.length, a = i.value.slice(r, i.selectionStart) === e, s = i.value.slice(i.selectionEnd, o) === t;
806
+ a && s && (i.selectionStart = r, i.selectionEnd = o);
779
807
  }
780
808
  return i.value.slice(i.selectionStart, i.selectionEnd);
781
809
  }
782
- function U(i) {
783
- const e = i.value.slice(0, i.selectionStart), t = i.value.slice(i.selectionEnd), n = e.match(/\n*$/), r = t.match(/^\n*/), o = n ? n[0].length : 0, s = r ? r[0].length : 0;
784
- let a = "", l = "";
785
- return /\S/.test(e) && o < 2 && (a = `
786
- `.repeat(2 - o)), /\S/.test(t) && s < 2 && (l = `
787
- `.repeat(2 - s)), { newlinesToAppend: a, newlinesToPrepend: l };
810
+ function W(i) {
811
+ const e = i.value.slice(0, i.selectionStart), t = i.value.slice(i.selectionEnd), n = e.match(/\n*$/), r = t.match(/^\n*/), o = n ? n[0].length : 0, a = r ? r[0].length : 0;
812
+ let s = "", l = "";
813
+ return /\S/.test(e) && o < 2 && (s = `
814
+ `.repeat(2 - o)), /\S/.test(t) && a < 2 && (l = `
815
+ `.repeat(2 - a)), { newlinesToAppend: s, newlinesToPrepend: l };
788
816
  }
789
- function me(i, e) {
817
+ function ue(i, e) {
790
818
  const t = i.selectionStart, n = i.selectionEnd, r = i.scrollTop;
791
819
  e(), i.selectionStart = t, i.selectionEnd = n, i.scrollTop = r;
792
820
  }
793
- function j(i, e, t = {}) {
794
- const n = i.selectionStart, r = i.selectionEnd, o = n === r, s = i.value;
795
- let a = n;
796
- for (; a > 0 && s[a - 1] !== `
821
+ function V(i, e, t = {}) {
822
+ const n = i.selectionStart, r = i.selectionEnd, o = n === r, a = i.value;
823
+ let s = n;
824
+ for (; s > 0 && a[s - 1] !== `
797
825
  `; )
798
- a -= 1;
826
+ s -= 1;
799
827
  if (o) {
800
- let p = n;
801
- for (; p < s.length && s[p] !== `
828
+ let c = n;
829
+ for (; c < a.length && a[c] !== `
802
830
  `; )
803
- p += 1;
804
- i.selectionStart = a, i.selectionEnd = p;
831
+ c += 1;
832
+ i.selectionStart = s, i.selectionEnd = c;
805
833
  } else
806
- de(i);
834
+ he(i);
807
835
  const l = e(i);
808
836
  if (t.adjustSelection) {
809
- const p = i.value.slice(i.selectionStart, i.selectionEnd), d = t.prefix ?? "", c = d.length > 0 && p.startsWith(d), m = t.adjustSelection(
810
- c,
837
+ const c = i.value.slice(i.selectionStart, i.selectionEnd), d = t.prefix ?? "", p = d.length > 0 && c.startsWith(d), h = t.adjustSelection(
838
+ p,
811
839
  n,
812
840
  r,
813
- a
841
+ s
814
842
  );
815
- return l.selectionStart = m.start, l.selectionEnd = m.end, l;
843
+ return l.selectionStart = h.start, l.selectionEnd = h.end, l;
816
844
  }
817
845
  if (t.prefix) {
818
846
  const d = i.value.slice(i.selectionStart, i.selectionEnd).startsWith(t.prefix);
819
847
  if (o)
820
848
  if (d) {
821
- const c = Math.max(n - t.prefix.length, a);
822
- l.selectionStart = c, l.selectionEnd = c;
849
+ const p = Math.max(n - t.prefix.length, s);
850
+ l.selectionStart = p, l.selectionEnd = p;
823
851
  } else {
824
- const c = n + t.prefix.length;
825
- l.selectionStart = c, l.selectionEnd = c;
852
+ const p = n + t.prefix.length;
853
+ l.selectionStart = p, l.selectionEnd = p;
826
854
  }
827
- else d ? (l.selectionStart = Math.max(n - t.prefix.length, a), l.selectionEnd = Math.max(r - t.prefix.length, a)) : (l.selectionStart = n + t.prefix.length, l.selectionEnd = r + t.prefix.length);
855
+ else d ? (l.selectionStart = Math.max(n - t.prefix.length, s), l.selectionEnd = Math.max(r - t.prefix.length, s)) : (l.selectionStart = n + t.prefix.length, l.selectionEnd = r + t.prefix.length);
828
856
  }
829
857
  return l;
830
858
  }
831
- function M(i, e) {
859
+ function A(i, e) {
832
860
  const {
833
861
  prefix: t,
834
862
  suffix: n,
835
863
  blockPrefix: r,
836
864
  blockSuffix: o,
837
- replaceNext: s,
838
- prefixSpace: a,
865
+ replaceNext: a,
866
+ prefixSpace: s,
839
867
  scanFor: l,
840
- surroundWithNewlines: p,
868
+ surroundWithNewlines: c,
841
869
  trimFirst: d
842
- } = e, c = i.selectionStart, m = i.selectionEnd;
843
- let u = i.value.slice(i.selectionStart, i.selectionEnd), h = O(u) && r && r.length > 0 ? `${r}
844
- ` : t, f = O(u) && o && o.length > 0 ? `
870
+ } = e, p = i.selectionStart, h = i.selectionEnd;
871
+ let m = i.value.slice(i.selectionStart, i.selectionEnd), u = U(m) && r && r.length > 0 ? `${r}
872
+ ` : t, f = U(m) && o && o.length > 0 ? `
845
873
  ${o}` : n;
846
- if (a) {
847
- const z = i.value[i.selectionStart - 1];
848
- i.selectionStart !== 0 && z != null && !/\s/.test(z) && (h = ` ${h}`);
874
+ if (s) {
875
+ const L = i.value[i.selectionStart - 1];
876
+ i.selectionStart !== 0 && L != null && !/\s/.test(L) && (u = ` ${u}`);
849
877
  }
850
- u = $e(i, h, f, e.multiline);
878
+ m = $e(i, u, f, e.multiline);
851
879
  let g = i.selectionStart, b = i.selectionEnd;
852
- const v = !!s && s.length > 0 && f.includes(s) && u.length > 0;
853
- let y = "", Y = "";
854
- if (p) {
855
- const z = U(i);
856
- y = z.newlinesToAppend, Y = z.newlinesToPrepend, h = y + t, f += Y;
857
- }
858
- if (u.startsWith(h) && u.endsWith(f)) {
859
- const z = u.slice(h.length, u.length - f.length);
860
- if (c === m) {
861
- let S = c - h.length;
862
- S = Math.max(S, g), S = Math.min(S, g + z.length), g = S, b = S;
880
+ const v = !!a && a.length > 0 && f.includes(a) && m.length > 0;
881
+ let k = "", y = "";
882
+ if (c) {
883
+ const L = W(i);
884
+ k = L.newlinesToAppend, y = L.newlinesToPrepend, u = k + t, f += y;
885
+ }
886
+ if (m.startsWith(u) && m.endsWith(f)) {
887
+ const L = m.slice(u.length, m.length - f.length);
888
+ if (p === h) {
889
+ let z = p - u.length;
890
+ z = Math.max(z, g), z = Math.min(z, g + L.length), g = z, b = z;
863
891
  } else
864
- b = g + z.length;
865
- return { text: z, selectionStart: g, selectionEnd: b };
892
+ b = g + L.length;
893
+ return { text: L, selectionStart: g, selectionEnd: b };
866
894
  }
867
895
  if (!v) {
868
- let z = h + u + f;
869
- g = c + h.length, b = m + h.length;
870
- const S = u.match(/^\s*|\s*$/g);
871
- if (d && S) {
872
- const ee = S[0] ?? "", te = S[1] ?? "";
873
- z = ee + h + u.trim() + f + te, g += ee.length, b -= te.length;
896
+ let L = u + m + f;
897
+ g = p + u.length, b = h + u.length;
898
+ const z = m.match(/^\s*|\s*$/g);
899
+ if (d && z) {
900
+ const ne = z[0] ?? "", ie = z[1] ?? "";
901
+ L = ne + u + m.trim() + f + ie, g += ne.length, b -= ie.length;
874
902
  }
875
- return { text: z, selectionStart: g, selectionEnd: b };
903
+ return { text: L, selectionStart: g, selectionEnd: b };
876
904
  }
877
- if (l && (typeof l == "string" ? new RegExp(l) : l).test(u)) {
878
- const S = h + f.replace(s, u);
879
- return g = g + h.length, b = g, { text: S, selectionStart: g, selectionEnd: b };
905
+ if (l && (typeof l == "string" ? new RegExp(l) : l).test(m)) {
906
+ const z = u + f.replace(a, m);
907
+ return g = g + u.length, b = g, { text: z, selectionStart: g, selectionEnd: b };
880
908
  }
881
- const Le = h + u + f, Se = f.indexOf(s);
882
- return g = g + h.length + u.length + Se, b = g + s.length, { text: Le, selectionStart: g, selectionEnd: b };
909
+ const B = u + m + f, P = f.indexOf(a);
910
+ return g = g + u.length + m.length + P, b = g + a.length, { text: B, selectionStart: g, selectionEnd: b };
883
911
  }
884
- function D(i, e) {
912
+ function K(i, e) {
885
913
  const { prefix: t, suffix: n, surroundWithNewlines: r } = e;
886
- let o = i.value.slice(i.selectionStart, i.selectionEnd), s = i.selectionStart, a = i.selectionEnd;
914
+ let o = i.value.slice(i.selectionStart, i.selectionEnd), a = i.selectionStart, s = i.selectionEnd;
887
915
  const l = o.split(`
888
916
  `);
889
917
  if (l.every((d) => d.startsWith(t) && (!n || d.endsWith(n))))
890
918
  o = l.map((d) => {
891
- let c = d.slice(t.length);
892
- return n && (c = c.slice(0, c.length - n.length)), c;
919
+ let p = d.slice(t.length);
920
+ return n && (p = p.slice(0, p.length - n.length)), p;
893
921
  }).join(`
894
- `), a = s + o.length;
922
+ `), s = a + o.length;
895
923
  else if (o = l.map((d) => t + d + (n ?? "")).join(`
896
924
  `), r) {
897
- const { newlinesToAppend: d, newlinesToPrepend: c } = U(i);
898
- s += d.length, a = s + o.length, o = d + o + c;
925
+ const { newlinesToAppend: d, newlinesToPrepend: p } = W(i);
926
+ a += d.length, s = a + o.length, o = d + o + p;
899
927
  }
900
- return { text: o, selectionStart: s, selectionEnd: a };
928
+ return { text: o, selectionStart: a, selectionEnd: s };
901
929
  }
902
- function ne(i) {
930
+ function re(i) {
903
931
  const e = i.split(`
904
932
  `), t = /^\d+\.\s+/, n = e.every((o) => t.test(o));
905
933
  return {
@@ -908,7 +936,7 @@ function ne(i) {
908
936
  processed: n
909
937
  };
910
938
  }
911
- function ie(i) {
939
+ function oe(i) {
912
940
  const e = i.split(`
913
941
  `), t = "- ", n = e.every((o) => o.startsWith(t));
914
942
  return {
@@ -917,176 +945,176 @@ function ie(i) {
917
945
  processed: n
918
946
  };
919
947
  }
920
- function P(i, e) {
948
+ function R(i, e) {
921
949
  return e ? "- " : `${i + 1}. `;
922
950
  }
923
951
  function Me(i, e) {
924
952
  let t, n, r;
925
- return i.orderedList ? (t = ne(e), n = ie(t.text), r = n.text) : (t = ie(e), n = ne(t.text), r = n.text), [t, n, r];
953
+ return i.orderedList ? (t = re(e), n = oe(t.text), r = n.text) : (t = oe(e), n = re(t.text), r = n.text), [t, n, r];
926
954
  }
927
955
  function Ae(i, e) {
928
956
  const t = i.selectionStart === i.selectionEnd;
929
957
  let n = i.selectionStart, r = i.selectionEnd;
930
- de(i);
931
- const o = i.value.slice(i.selectionStart, i.selectionEnd), [s, a, l] = Me(e, o), p = l.split(`
932
- `).map((f, g) => `${P(g, e.unorderedList)}${f}`), d = p.reduce((f, g, b) => f + P(b, e.unorderedList).length, 0), c = p.reduce((f, g, b) => f + P(b, !e.unorderedList).length, 0);
933
- if (s.processed)
934
- return t ? (n = Math.max(n - P(0, e.unorderedList).length, 0), r = n) : (n = i.selectionStart, r = i.selectionEnd - d), { text: l, selectionStart: n, selectionEnd: r };
935
- const { newlinesToAppend: m, newlinesToPrepend: u } = U(i), h = m + p.join(`
936
- `) + u;
958
+ he(i);
959
+ const o = i.value.slice(i.selectionStart, i.selectionEnd), [a, s, l] = Me(e, o), c = l.split(`
960
+ `).map((f, g) => `${R(g, e.unorderedList)}${f}`), d = c.reduce((f, g, b) => f + R(b, e.unorderedList).length, 0), p = c.reduce((f, g, b) => f + R(b, !e.unorderedList).length, 0);
961
+ if (a.processed)
962
+ return t ? (n = Math.max(n - R(0, e.unorderedList).length, 0), r = n) : (n = i.selectionStart, r = i.selectionEnd - d), { text: l, selectionStart: n, selectionEnd: r };
963
+ const { newlinesToAppend: h, newlinesToPrepend: m } = W(i), u = h + c.join(`
964
+ `) + m;
937
965
  return t ? (n = Math.max(
938
- n + P(0, e.unorderedList).length + m.length,
966
+ n + R(0, e.unorderedList).length + h.length,
939
967
  0
940
- ), r = n) : a.processed ? (n = Math.max(i.selectionStart + m.length, 0), r = i.selectionEnd + m.length + d - c) : (n = Math.max(i.selectionStart + m.length, 0), r = i.selectionEnd + m.length + d), { text: h, selectionStart: n, selectionEnd: r };
968
+ ), r = n) : s.processed ? (n = Math.max(i.selectionStart + h.length, 0), r = i.selectionEnd + h.length + d - p) : (n = Math.max(i.selectionStart + h.length, 0), r = i.selectionEnd + h.length + d), { text: u, selectionStart: n, selectionEnd: r };
941
969
  }
942
- function he(i, e) {
943
- const t = j(
970
+ function fe(i, e) {
971
+ const t = V(
944
972
  i,
945
973
  (n) => Ae(n, e),
946
974
  {
947
- adjustSelection: (n, r, o, s) => {
948
- const a = i.value.slice(s, i.selectionEnd), l = /^\d+\.\s+/, p = /^- /, d = l.test(a), c = p.test(a), m = e.orderedList && d || e.unorderedList && c;
975
+ adjustSelection: (n, r, o, a) => {
976
+ const s = i.value.slice(a, i.selectionEnd), l = /^\d+\.\s+/, c = /^- /, d = l.test(s), p = c.test(s), h = e.orderedList && d || e.unorderedList && p;
949
977
  if (r === o) {
950
- if (m) {
951
- const f = a.match(e.orderedList ? l : p), g = f ? f[0].length : 0;
978
+ if (h) {
979
+ const f = s.match(e.orderedList ? l : c), g = f ? f[0].length : 0;
952
980
  return {
953
- start: Math.max(r - g, s),
954
- end: Math.max(r - g, s)
981
+ start: Math.max(r - g, a),
982
+ end: Math.max(r - g, a)
955
983
  };
956
984
  }
957
- if (d || c) {
958
- const f = a.match(d ? l : p), g = f ? f[0].length : 0, v = (e.unorderedList ? 2 : 3) - g;
985
+ if (d || p) {
986
+ const f = s.match(d ? l : c), g = f ? f[0].length : 0, v = (e.unorderedList ? 2 : 3) - g;
959
987
  return {
960
988
  start: r + v,
961
989
  end: r + v
962
990
  };
963
991
  }
964
- const h = e.unorderedList ? 2 : 3;
992
+ const u = e.unorderedList ? 2 : 3;
965
993
  return {
966
- start: r + h,
967
- end: r + h
994
+ start: r + u,
995
+ end: r + u
968
996
  };
969
997
  }
970
- if (m) {
971
- const h = a.match(e.orderedList ? l : p), f = h ? h[0].length : 0;
998
+ if (h) {
999
+ const u = s.match(e.orderedList ? l : c), f = u ? u[0].length : 0;
972
1000
  return {
973
- start: Math.max(r - f, s),
974
- end: Math.max(o - f, s)
1001
+ start: Math.max(r - f, a),
1002
+ end: Math.max(o - f, a)
975
1003
  };
976
1004
  }
977
- if (d || c) {
978
- const h = a.match(d ? l : p), f = h ? h[0].length : 0, b = (e.unorderedList ? 2 : 3) - f;
1005
+ if (d || p) {
1006
+ const u = s.match(d ? l : c), f = u ? u[0].length : 0, b = (e.unorderedList ? 2 : 3) - f;
979
1007
  return {
980
1008
  start: r + b,
981
1009
  end: o + b
982
1010
  };
983
1011
  }
984
- const u = e.unorderedList ? 2 : 3;
1012
+ const m = e.unorderedList ? 2 : 3;
985
1013
  return {
986
- start: r + u,
987
- end: o + u
1014
+ start: r + m,
1015
+ end: o + m
988
1016
  };
989
1017
  },
990
1018
  prefix: e.unorderedList ? "- " : "1. "
991
1019
  }
992
1020
  );
993
- T(i, t);
1021
+ H(i, t);
994
1022
  }
995
1023
  function _e(i, e) {
996
- const t = L[e];
1024
+ const t = C[e];
997
1025
  if (!t) return !1;
998
1026
  const n = t.prefix ?? "", r = t.suffix ?? "";
999
1027
  return n ? r ? i.startsWith(n) && i.endsWith(r) : i.startsWith(n) : !1;
1000
1028
  }
1001
- function q(i) {
1029
+ function Z(i) {
1002
1030
  if (!i) return [];
1003
1031
  const e = [], { selectionStart: t, selectionEnd: n, value: r } = i, o = r.split(`
1004
1032
  `);
1005
- let s = 0, a = "";
1006
- for (const c of o) {
1007
- if (t >= s && t <= s + c.length) {
1008
- a = c;
1033
+ let a = 0, s = "";
1034
+ for (const p of o) {
1035
+ if (t >= a && t <= a + p.length) {
1036
+ s = p;
1009
1037
  break;
1010
1038
  }
1011
- s += c.length + 1;
1039
+ a += p.length + 1;
1012
1040
  }
1013
- a.startsWith("- ") && (a.startsWith("- [ ] ") || a.startsWith("- [x] ") ? e.push("task-list") : e.push("bullet-list")), /^\d+\.\s/.test(a) && e.push("numbered-list"), a.startsWith("> ") && e.push("quote"), a.startsWith("### ") ? e.push("header-3") : a.startsWith("## ") ? e.push("header-2") : a.startsWith("# ") && e.push("header");
1014
- const l = Math.max(0, t - 10), p = Math.min(r.length, n + 10), d = r.slice(l, p);
1041
+ s.startsWith("- ") && (s.startsWith("- [ ] ") || s.startsWith("- [x] ") ? e.push("task-list") : e.push("bullet-list")), /^\d+\.\s/.test(s) && e.push("numbered-list"), s.startsWith("> ") && e.push("quote"), s.startsWith("### ") ? e.push("header-3") : s.startsWith("## ") ? e.push("header-2") : s.startsWith("# ") && e.push("header");
1042
+ const l = Math.max(0, t - 10), c = Math.min(r.length, n + 10), d = r.slice(l, c);
1015
1043
  if (d.includes("**")) {
1016
- const c = r.slice(Math.max(0, t - 100), t), m = r.slice(n, Math.min(r.length, n + 100)), u = c.lastIndexOf("**"), h = m.indexOf("**");
1017
- u !== -1 && h !== -1 && e.push("bold");
1044
+ const p = r.slice(Math.max(0, t - 100), t), h = r.slice(n, Math.min(r.length, n + 100)), m = p.lastIndexOf("**"), u = h.indexOf("**");
1045
+ m !== -1 && u !== -1 && e.push("bold");
1018
1046
  }
1019
1047
  if (d.includes("_")) {
1020
- const c = r.slice(Math.max(0, t - 100), t), m = r.slice(n, Math.min(r.length, n + 100)), u = c.lastIndexOf("_"), h = m.indexOf("_");
1021
- u !== -1 && h !== -1 && e.push("italic");
1048
+ const p = r.slice(Math.max(0, t - 100), t), h = r.slice(n, Math.min(r.length, n + 100)), m = p.lastIndexOf("_"), u = h.indexOf("_");
1049
+ m !== -1 && u !== -1 && e.push("italic");
1022
1050
  }
1023
1051
  if (d.includes("`")) {
1024
- const c = r.slice(Math.max(0, t - 100), t), m = r.slice(n, Math.min(r.length, n + 100));
1025
- c.includes("`") && m.includes("`") && e.push("code");
1052
+ const p = r.slice(Math.max(0, t - 100), t), h = r.slice(n, Math.min(r.length, n + 100));
1053
+ p.includes("`") && h.includes("`") && e.push("code");
1026
1054
  }
1027
1055
  if (d.includes("[") && d.includes("]")) {
1028
- const c = r.slice(Math.max(0, t - 100), t), m = r.slice(n, Math.min(r.length, n + 100)), u = c.lastIndexOf("["), h = m.indexOf("]");
1029
- u !== -1 && h !== -1 && r.slice(n + h + 1, n + h + 10).startsWith("(") && e.push("link");
1056
+ const p = r.slice(Math.max(0, t - 100), t), h = r.slice(n, Math.min(r.length, n + 100)), m = p.lastIndexOf("["), u = h.indexOf("]");
1057
+ m !== -1 && u !== -1 && r.slice(n + u + 1, n + u + 10).startsWith("(") && e.push("link");
1030
1058
  }
1031
1059
  return e;
1032
1060
  }
1033
- function ue(i, e) {
1034
- return q(i).includes(e);
1061
+ function ge(i, e) {
1062
+ return Z(i).includes(e);
1035
1063
  }
1036
- function fe(i, e = {}) {
1064
+ function be(i, e = {}) {
1037
1065
  if (!i) return;
1038
- const { toWord: t, toLine: n, toFormat: r } = e, { selectionStart: o, selectionEnd: s, value: a } = i;
1066
+ const { toWord: t, toLine: n, toFormat: r } = e, { selectionStart: o, selectionEnd: a, value: s } = i;
1039
1067
  if (n) {
1040
- const l = a.split(`
1068
+ const l = s.split(`
1041
1069
  `);
1042
- let p = 0, d = 0, c = 0;
1043
- for (const m of l) {
1044
- if (o >= c && o <= c + m.length) {
1045
- p = c, d = c + m.length;
1070
+ let c = 0, d = 0, p = 0;
1071
+ for (const h of l) {
1072
+ if (o >= p && o <= p + h.length) {
1073
+ c = p, d = p + h.length;
1046
1074
  break;
1047
1075
  }
1048
- c += m.length + 1;
1076
+ p += h.length + 1;
1049
1077
  }
1050
- i.selectionStart = p, i.selectionEnd = d;
1078
+ i.selectionStart = c, i.selectionEnd = d;
1051
1079
  return;
1052
1080
  }
1053
- if (r && _e(a.slice(o, s), r)) {
1054
- const l = L[r], p = (l.prefix ?? "").length, d = (l.suffix ?? "").length;
1055
- i.selectionStart = Math.max(0, o - p), i.selectionEnd = Math.min(a.length, s + d);
1081
+ if (r && _e(s.slice(o, a), r)) {
1082
+ const l = C[r], c = (l.prefix ?? "").length, d = (l.suffix ?? "").length;
1083
+ i.selectionStart = Math.max(0, o - c), i.selectionEnd = Math.min(s.length, a + d);
1056
1084
  return;
1057
1085
  }
1058
- if (t && o === s) {
1059
- let l = o, p = s;
1060
- for (; l > 0 && !/\s/.test(a[l - 1]); )
1086
+ if (t && o === a) {
1087
+ let l = o, c = a;
1088
+ for (; l > 0 && !/\s/.test(s[l - 1]); )
1061
1089
  l -= 1;
1062
- for (; p < a.length && !/\s/.test(a[p]); )
1063
- p += 1;
1064
- i.selectionStart = l, i.selectionEnd = p;
1090
+ for (; c < s.length && !/\s/.test(s[c]); )
1091
+ c += 1;
1092
+ i.selectionStart = l, i.selectionEnd = c;
1065
1093
  }
1066
1094
  }
1067
- function C(i) {
1095
+ function T(i) {
1068
1096
  return !!i && !i.disabled && !i.readOnly;
1069
1097
  }
1070
- function W(i) {
1071
- if (!C(i)) return;
1072
- k("toggleBold", "Starting"), N(i, "Before");
1073
- const e = E(L.bold), t = M(i, e);
1074
- V(t), T(i, t), N(i, "After");
1098
+ function J(i) {
1099
+ if (!T(i)) return;
1100
+ x("toggleBold", "Starting"), F(i, "Before");
1101
+ const e = E(C.bold), t = A(i, e);
1102
+ q(t), H(i, t), F(i, "After");
1075
1103
  }
1076
- function K(i) {
1077
- if (!C(i)) return;
1078
- const e = E(L.italic), t = M(i, e);
1079
- T(i, t);
1104
+ function G(i) {
1105
+ if (!T(i)) return;
1106
+ const e = E(C.italic), t = A(i, e);
1107
+ H(i, t);
1080
1108
  }
1081
- function ge(i) {
1082
- if (!C(i)) return;
1083
- const e = E(L.code), t = M(i, e);
1084
- T(i, t);
1109
+ function ve(i) {
1110
+ if (!T(i)) return;
1111
+ const e = E(C.code), t = A(i, e);
1112
+ H(i, t);
1085
1113
  }
1086
- function Z(i, e = {}) {
1087
- if (!C(i)) return;
1114
+ function Q(i, e = {}) {
1115
+ if (!T(i)) return;
1088
1116
  const t = i.value.slice(i.selectionStart, i.selectionEnd);
1089
- let n = E(L.link);
1117
+ let n = E(C.link);
1090
1118
  if (t && /^https?:\/\//.test(t) && !e.url ? n = {
1091
1119
  ...n,
1092
1120
  suffix: `](${t})`,
@@ -1096,48 +1124,48 @@ function Z(i, e = {}) {
1096
1124
  suffix: `](${e.url})`,
1097
1125
  replaceNext: ""
1098
1126
  }), e.text && !t) {
1099
- const s = i.selectionStart;
1100
- i.value = i.value.slice(0, s) + e.text + i.value.slice(s), i.selectionStart = s, i.selectionEnd = s + e.text.length;
1127
+ const a = i.selectionStart;
1128
+ i.value = i.value.slice(0, a) + e.text + i.value.slice(a), i.selectionStart = a, i.selectionEnd = a + e.text.length;
1101
1129
  }
1102
- const o = M(i, n);
1103
- T(i, o);
1130
+ const o = A(i, n);
1131
+ H(i, o);
1104
1132
  }
1105
- function J(i) {
1106
- if (!C(i)) return;
1107
- const e = E(L.bulletList);
1108
- he(i, e);
1133
+ function X(i) {
1134
+ if (!T(i)) return;
1135
+ const e = E(C.bulletList);
1136
+ fe(i, e);
1109
1137
  }
1110
- function G(i) {
1111
- if (!C(i)) return;
1112
- const e = E(L.numberedList);
1113
- he(i, e);
1138
+ function Y(i) {
1139
+ if (!T(i)) return;
1140
+ const e = E(C.numberedList);
1141
+ fe(i, e);
1114
1142
  }
1115
- function Q(i) {
1116
- if (!C(i)) return;
1117
- k("toggleQuote", "Starting"), N(i, "Initial");
1118
- const e = E(L.quote), t = j(
1143
+ function ee(i) {
1144
+ if (!T(i)) return;
1145
+ x("toggleQuote", "Starting"), F(i, "Initial");
1146
+ const e = E(C.quote), t = V(
1119
1147
  i,
1120
- (n) => D(n, e),
1148
+ (n) => K(n, e),
1121
1149
  { prefix: e.prefix }
1122
1150
  );
1123
- V(t), T(i, t), N(i, "Final");
1151
+ q(t), H(i, t), F(i, "Final");
1124
1152
  }
1125
- function X(i) {
1126
- if (!C(i)) return;
1127
- const e = E(L.taskList), t = j(
1153
+ function te(i) {
1154
+ if (!T(i)) return;
1155
+ const e = E(C.taskList), t = V(
1128
1156
  i,
1129
- (n) => D(n, e),
1157
+ (n) => K(n, e),
1130
1158
  { prefix: e.prefix }
1131
1159
  );
1132
- T(i, t);
1160
+ H(i, t);
1133
1161
  }
1134
- function be(i) {
1135
- if (!C(i)) return;
1136
- const e = E(L.strikethrough), t = M(i, e);
1137
- T(i, t);
1162
+ function we(i) {
1163
+ if (!T(i)) return;
1164
+ const e = E(C.strikethrough), t = A(i, e);
1165
+ H(i, t);
1138
1166
  }
1139
- function ve(i) {
1140
- if (!C(i)) return;
1167
+ function ke(i) {
1168
+ if (!T(i)) return;
1141
1169
  const e = i.selectionStart, n = i.value.slice(0, e), o = (n.length > 0 && !n.endsWith(`
1142
1170
  `) ? `
1143
1171
  ` : "") + `
@@ -1157,27 +1185,27 @@ function Pe(i, e, t) {
1157
1185
  r += 1;
1158
1186
  return { lineStart: n, lineEnd: r };
1159
1187
  }
1160
- function R(i, e = 1, t = !1) {
1161
- if (!C(i)) return;
1162
- (e < 1 || e > 6) && (e = 1), k("insertHeader", "============ START ============"), k("insertHeader", `Level: ${e}, Toggle: ${t}`), k("insertHeader", `Initial cursor: ${i.selectionStart}-${i.selectionEnd}`);
1163
- const n = `header${e === 1 ? "1" : e}`, r = E(L[n] || L.header1);
1164
- k("insertHeader", `Style prefix: "${r.prefix}"`);
1165
- const o = i.value, s = i.selectionStart, a = i.selectionEnd, { lineStart: l, lineEnd: p } = Pe(o, s, a), d = o.slice(l, p);
1166
- k("insertHeader", `Current line (before): "${d}"`);
1167
- const c = d.match(/^(#{1,6})\s*/), m = c ? c[1].length : 0, u = c ? c[0].length : 0;
1168
- k("insertHeader", `Existing header match: ${c ? c[0] : "none"}`), k("insertHeader", `Existing level: ${m}`), k("insertHeader", `Target level: ${e}`);
1169
- const h = t && m === e;
1170
- k("insertHeader", `Should toggle OFF: ${h}`);
1171
- const f = j(
1188
+ function O(i, e = 1, t = !1) {
1189
+ if (!T(i)) return;
1190
+ (e < 1 || e > 6) && (e = 1), x("insertHeader", "============ START ============"), x("insertHeader", `Level: ${e}, Toggle: ${t}`), x("insertHeader", `Initial cursor: ${i.selectionStart}-${i.selectionEnd}`);
1191
+ const n = `header${e === 1 ? "1" : e}`, r = E(C[n] || C.header1);
1192
+ x("insertHeader", `Style prefix: "${r.prefix}"`);
1193
+ const o = i.value, a = i.selectionStart, s = i.selectionEnd, { lineStart: l, lineEnd: c } = Pe(o, a, s), d = o.slice(l, c);
1194
+ x("insertHeader", `Current line (before): "${d}"`);
1195
+ const p = d.match(/^(#{1,6})\s*/), h = p ? p[1].length : 0, m = p ? p[0].length : 0;
1196
+ x("insertHeader", `Existing header match: ${p ? p[0] : "none"}`), x("insertHeader", `Existing level: ${h}`), x("insertHeader", `Target level: ${e}`);
1197
+ const u = t && h === e;
1198
+ x("insertHeader", `Should toggle OFF: ${u}`);
1199
+ const f = V(
1172
1200
  i,
1173
1201
  (g) => {
1174
1202
  const b = g.value.slice(g.selectionStart, g.selectionEnd);
1175
- k("insertHeader", `Line in operation: "${b}"`);
1203
+ x("insertHeader", `Line in operation: "${b}"`);
1176
1204
  const v = b.replace(/^#{1,6}\s*/, "");
1177
- k("insertHeader", `Cleaned line: "${v}"`);
1178
- let y;
1179
- return h ? (k("insertHeader", "ACTION: Toggling OFF - removing header"), y = v) : m > 0 ? (k("insertHeader", `ACTION: Replacing H${m} with H${e}`), y = r.prefix + v) : (k("insertHeader", "ACTION: Adding new header"), y = r.prefix + v), k("insertHeader", `New line: "${y}"`), {
1180
- text: y,
1205
+ x("insertHeader", `Cleaned line: "${v}"`);
1206
+ let k;
1207
+ return u ? (x("insertHeader", "ACTION: Toggling OFF - removing header"), k = v) : h > 0 ? (x("insertHeader", `ACTION: Replacing H${h} with H${e}`), k = r.prefix + v) : (x("insertHeader", "ACTION: Adding new header"), k = r.prefix + v), x("insertHeader", `New line: "${k}"`), {
1208
+ text: k,
1181
1209
  selectionStart: g.selectionStart,
1182
1210
  selectionEnd: g.selectionEnd
1183
1211
  };
@@ -1185,18 +1213,18 @@ function R(i, e = 1, t = !1) {
1185
1213
  {
1186
1214
  prefix: r.prefix,
1187
1215
  adjustSelection: (g, b, v) => {
1188
- if (k("insertHeader", `Adjusting selection with existing prefix length ${u}`), h) {
1189
- const y = Math.max(b - u, l);
1216
+ if (x("insertHeader", `Adjusting selection with existing prefix length ${m}`), u) {
1217
+ const k = Math.max(b - m, l);
1190
1218
  return {
1191
- start: y,
1192
- end: b === v ? y : Math.max(v - u, l)
1219
+ start: k,
1220
+ end: b === v ? k : Math.max(v - m, l)
1193
1221
  };
1194
1222
  }
1195
- if (u > 0) {
1196
- const y = r.prefix.length - u;
1223
+ if (m > 0) {
1224
+ const k = r.prefix.length - m;
1197
1225
  return {
1198
- start: b + y,
1199
- end: v + y
1226
+ start: b + k,
1227
+ end: v + k
1200
1228
  };
1201
1229
  }
1202
1230
  return {
@@ -1206,78 +1234,78 @@ function R(i, e = 1, t = !1) {
1206
1234
  }
1207
1235
  }
1208
1236
  );
1209
- V(f), k("insertHeader", "============ END ============"), T(i, f);
1237
+ q(f), x("insertHeader", "============ END ============"), H(i, f);
1210
1238
  }
1211
- function we(i) {
1212
- R(i, 1, !0);
1239
+ function ye(i) {
1240
+ O(i, 1, !0);
1213
1241
  }
1214
- function ke(i) {
1215
- R(i, 2, !0);
1242
+ function xe(i) {
1243
+ O(i, 2, !0);
1216
1244
  }
1217
- function ye(i) {
1218
- R(i, 3, !0);
1245
+ function ze(i) {
1246
+ O(i, 3, !0);
1219
1247
  }
1220
- function xe(i, e) {
1221
- if (!C(i)) return;
1248
+ function Le(i, e) {
1249
+ if (!T(i)) return;
1222
1250
  const t = E(e);
1223
1251
  let n;
1224
1252
  if (t.multiline) {
1225
1253
  const r = i.value.slice(i.selectionStart, i.selectionEnd);
1226
- O(r) ? n = D(i, t) : n = M(i, t);
1254
+ U(r) ? n = K(i, t) : n = A(i, t);
1227
1255
  } else
1228
- n = M(i, t);
1229
- T(i, n);
1256
+ n = A(i, t);
1257
+ H(i, n);
1230
1258
  }
1231
- const re = {
1232
- toggleBold: W,
1233
- toggleItalic: K,
1234
- toggleCode: ge,
1235
- toggleStrikethrough: be,
1236
- insertLink: Z,
1237
- insertHorizontalRule: ve,
1238
- toggleBulletList: J,
1239
- toggleNumberedList: G,
1240
- toggleQuote: Q,
1241
- toggleTaskList: X,
1242
- insertHeader: R,
1243
- toggleH1: we,
1244
- toggleH2: ke,
1245
- toggleH3: ye,
1246
- getActiveFormats: q,
1247
- hasFormat: ue,
1248
- expandSelection: fe,
1249
- applyCustomFormat: xe,
1250
- preserveSelection: me,
1251
- setUndoMethod: pe,
1252
- setDebugMode: ce,
1253
- getDebugMode: F
1259
+ const ae = {
1260
+ toggleBold: J,
1261
+ toggleItalic: G,
1262
+ toggleCode: ve,
1263
+ toggleStrikethrough: we,
1264
+ insertLink: Q,
1265
+ insertHorizontalRule: ke,
1266
+ toggleBulletList: X,
1267
+ toggleNumberedList: Y,
1268
+ toggleQuote: ee,
1269
+ toggleTaskList: te,
1270
+ insertHeader: O,
1271
+ toggleH1: ye,
1272
+ toggleH2: xe,
1273
+ toggleH3: ze,
1274
+ getActiveFormats: Z,
1275
+ hasFormat: ge,
1276
+ expandSelection: be,
1277
+ applyCustomFormat: Le,
1278
+ preserveSelection: ue,
1279
+ setUndoMethod: me,
1280
+ setDebugMode: de,
1281
+ getDebugMode: D
1254
1282
  }, Ie = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
1255
1283
  __proto__: null,
1256
- actions: re,
1257
- applyCustomFormat: xe,
1258
- default: re,
1259
- expandSelection: fe,
1260
- getActiveFormats: q,
1261
- getDebugMode: F,
1262
- getUndoMethod: Ee,
1263
- hasFormat: ue,
1264
- insertHeader: R,
1265
- insertHorizontalRule: ve,
1266
- insertLink: Z,
1267
- preserveSelection: me,
1268
- setDebugMode: ce,
1269
- setUndoMethod: pe,
1270
- toggleBold: W,
1271
- toggleBulletList: J,
1272
- toggleCode: ge,
1273
- toggleH1: we,
1274
- toggleH2: ke,
1275
- toggleH3: ye,
1276
- toggleItalic: K,
1277
- toggleNumberedList: G,
1278
- toggleQuote: Q,
1279
- toggleStrikethrough: be,
1280
- toggleTaskList: X
1284
+ actions: ae,
1285
+ applyCustomFormat: Le,
1286
+ default: ae,
1287
+ expandSelection: be,
1288
+ getActiveFormats: Z,
1289
+ getDebugMode: D,
1290
+ getUndoMethod: Te,
1291
+ hasFormat: ge,
1292
+ insertHeader: O,
1293
+ insertHorizontalRule: ke,
1294
+ insertLink: Q,
1295
+ preserveSelection: ue,
1296
+ setDebugMode: de,
1297
+ setUndoMethod: me,
1298
+ toggleBold: J,
1299
+ toggleBulletList: X,
1300
+ toggleCode: ve,
1301
+ toggleH1: ye,
1302
+ toggleH2: xe,
1303
+ toggleH3: ze,
1304
+ toggleItalic: G,
1305
+ toggleNumberedList: Y,
1306
+ toggleQuote: ee,
1307
+ toggleStrikethrough: we,
1308
+ toggleTaskList: te
1281
1309
  }, Symbol.toStringTag, { value: "Module" })), Be = {
1282
1310
  b: "toggleBold",
1283
1311
  i: "toggleItalic",
@@ -1286,39 +1314,39 @@ const re = {
1286
1314
  Digit7: "toggleNumberedList",
1287
1315
  Digit8: "toggleBulletList"
1288
1316
  };
1289
- class ze {
1317
+ class Se {
1290
1318
  constructor(e) {
1291
1319
  this.editor = e, this.textarea = e.textarea;
1292
1320
  }
1293
1321
  handleKeydown(e) {
1294
1322
  if (!(navigator.platform.toLowerCase().includes("mac") ? e.metaKey : e.ctrlKey)) return !1;
1295
- const o = e.key.toLowerCase(), s = Re[e.code], a = s ?? Be[o];
1296
- return !a || s && !e.shiftKey || !s && (o === "b" || o === "i" || o === "k") && e.shiftKey ? !1 : (e.preventDefault(), this.editor.toolbar ? this.editor.toolbar.handleAction(a) : this.handleAction(a), !0);
1323
+ const o = e.key.toLowerCase(), a = Re[e.code], s = a ?? Be[o];
1324
+ return !s || a && !e.shiftKey || !a && (o === "b" || o === "i" || o === "k") && e.shiftKey ? !1 : (e.preventDefault(), this.editor.toolbar ? this.editor.toolbar.handleAction(s) : this.handleAction(s), !0);
1297
1325
  }
1298
1326
  handleAction(e) {
1299
1327
  const t = this.textarea;
1300
1328
  if (t) {
1301
1329
  switch (t.focus(), e) {
1302
1330
  case "toggleBold":
1303
- W(t);
1331
+ J(t);
1304
1332
  break;
1305
1333
  case "toggleItalic":
1306
- K(t);
1334
+ G(t);
1307
1335
  break;
1308
1336
  case "insertLink":
1309
- Z(t);
1337
+ Q(t);
1310
1338
  break;
1311
1339
  case "toggleBulletList":
1312
- J(t);
1340
+ X(t);
1313
1341
  break;
1314
1342
  case "toggleNumberedList":
1315
- G(t);
1343
+ Y(t);
1316
1344
  break;
1317
1345
  case "toggleQuote":
1318
- Q(t);
1346
+ ee(t);
1319
1347
  break;
1320
1348
  case "toggleTaskList":
1321
- X(t);
1349
+ te(t);
1322
1350
  break;
1323
1351
  }
1324
1352
  t.dispatchEvent(new Event("input", { bubbles: !0 }));
@@ -1327,7 +1355,7 @@ class ze {
1327
1355
  destroy() {
1328
1356
  }
1329
1357
  }
1330
- const _ = {
1358
+ const I = {
1331
1359
  name: "solar",
1332
1360
  colors: {
1333
1361
  bgPrimary: "#faf0ca",
@@ -1378,7 +1406,7 @@ const _ = {
1378
1406
  border: "rgba(13, 59, 102, 0.25)"
1379
1407
  // Table/element borders
1380
1408
  }
1381
- }, oe = {
1409
+ }, se = {
1382
1410
  name: "cave",
1383
1411
  colors: {
1384
1412
  bgPrimary: "#141E26",
@@ -1429,15 +1457,15 @@ const _ = {
1429
1457
  border: "rgba(197, 221, 232, 0.2)"
1430
1458
  // Table/element borders
1431
1459
  }
1432
- }, se = {
1433
- solar: _,
1434
- cave: oe,
1460
+ }, le = {
1461
+ solar: I,
1462
+ cave: se,
1435
1463
  // Aliases for backward compatibility
1436
- light: _,
1437
- dark: oe
1464
+ light: I,
1465
+ dark: se
1438
1466
  };
1439
- function $(i) {
1440
- return typeof i == "string" ? { ...se[i] || se.solar, name: i } : i;
1467
+ function M(i) {
1468
+ return typeof i == "string" ? { ...le[i] || le.solar, name: i } : i;
1441
1469
  }
1442
1470
  function Ne(i) {
1443
1471
  const e = [];
@@ -1448,7 +1476,7 @@ function Ne(i) {
1448
1476
  return e.join(`
1449
1477
  `);
1450
1478
  }
1451
- function ae(i, e = {}) {
1479
+ function ce(i, e = {}) {
1452
1480
  return {
1453
1481
  ...i,
1454
1482
  colors: {
@@ -1465,12 +1493,12 @@ function je(i = {}) {
1465
1493
  fontFamily: n = '"SF Mono", SFMono-Regular, Menlo, Monaco, "Cascadia Code", Consolas, "Roboto Mono", "Noto Sans Mono", "Droid Sans Mono", "Ubuntu Mono", "DejaVu Sans Mono", "Liberation Mono", "Courier New", Courier, monospace',
1466
1494
  padding: r = "20px",
1467
1495
  theme: o = null,
1468
- mobile: s = {}
1469
- } = i, a = Object.keys(s).length > 0 ? `
1496
+ mobile: a = {}
1497
+ } = i, s = Object.keys(a).length > 0 ? `
1470
1498
  @media (max-width: 640px) {
1471
1499
  .marzipan-wrapper .marzipan-input,
1472
1500
  .marzipan-wrapper .marzipan-preview {
1473
- ${Object.entries(s).map(([p, d]) => `${p.replace(/([A-Z])/g, "-$1").toLowerCase()}: ${d} !important;`).join(`
1501
+ ${Object.entries(a).map(([c, d]) => `${c.replace(/([A-Z])/g, "-$1").toLowerCase()}: ${d} !important;`).join(`
1474
1502
  `)}
1475
1503
  }
1476
1504
  }
@@ -2246,7 +2274,7 @@ function je(i = {}) {
2246
2274
  .marzipan-preview .marzipan-table {
2247
2275
  border-collapse: collapse !important;
2248
2276
  margin: 1em 0 !important;
2249
- width: 100% !important;
2277
+ width: auto !important;
2250
2278
  overflow: auto !important;
2251
2279
  display: table !important;
2252
2280
  }
@@ -2276,6 +2304,70 @@ function je(i = {}) {
2276
2304
  .marzipan-preview .marzipan-table tr {
2277
2305
  display: table-row !important;
2278
2306
  }
2307
+
2308
+ /* Table alignment (parsed from GFM :--- :---: ---: markers) */
2309
+ .marzipan-preview .marzipan-table th[style*="text-align: center"],
2310
+ .marzipan-preview .marzipan-table td[style*="text-align: center"] {
2311
+ text-align: center !important;
2312
+ }
2313
+ .marzipan-preview .marzipan-table th[style*="text-align: right"],
2314
+ .marzipan-preview .marzipan-table td[style*="text-align: right"] {
2315
+ text-align: right !important;
2316
+ }
2317
+
2318
+ /* Table style presets */
2319
+ .marzipan-preview .marzipan-table.mz-table-striped tr:nth-child(odd) td {
2320
+ background: transparent !important;
2321
+ }
2322
+ .marzipan-preview .marzipan-table.mz-table-striped tr:nth-child(even) td {
2323
+ background: var(--bg-secondary, rgba(128,128,128,0.08)) !important;
2324
+ }
2325
+
2326
+ .marzipan-preview .marzipan-table.mz-table-rainbow tr:nth-child(even) td { background: transparent !important; }
2327
+ .marzipan-preview .marzipan-table.mz-table-rainbow tbody tr:nth-child(6n+1) td { background: rgba(236,72,153,0.10) !important; }
2328
+ .marzipan-preview .marzipan-table.mz-table-rainbow tbody tr:nth-child(6n+2) td { background: rgba(139,92,246,0.10) !important; }
2329
+ .marzipan-preview .marzipan-table.mz-table-rainbow tbody tr:nth-child(6n+3) td { background: rgba(6,182,212,0.10) !important; }
2330
+ .marzipan-preview .marzipan-table.mz-table-rainbow tbody tr:nth-child(6n+4) td { background: rgba(16,185,129,0.10) !important; }
2331
+ .marzipan-preview .marzipan-table.mz-table-rainbow tbody tr:nth-child(6n+5) td { background: rgba(245,158,11,0.10) !important; }
2332
+ .marzipan-preview .marzipan-table.mz-table-rainbow tbody tr:nth-child(6n+6) td { background: rgba(59,130,246,0.10) !important; }
2333
+ .marzipan-preview .marzipan-table.mz-table-rainbow th {
2334
+ background: rgba(236,72,153,0.18) !important;
2335
+ }
2336
+
2337
+ .marzipan-preview .marzipan-table.mz-table-minimal {
2338
+ border: none !important;
2339
+ }
2340
+ .marzipan-preview .marzipan-table.mz-table-minimal th,
2341
+ .marzipan-preview .marzipan-table.mz-table-minimal td {
2342
+ border: none !important;
2343
+ border-bottom: 1px solid var(--border, rgba(128,128,128,0.25)) !important;
2344
+ }
2345
+ .marzipan-preview .marzipan-table.mz-table-minimal th {
2346
+ border-bottom: 2px solid var(--border, rgba(128,128,128,0.5)) !important;
2347
+ background: transparent !important;
2348
+ }
2349
+ .marzipan-preview .marzipan-table.mz-table-minimal tr:nth-child(even) td {
2350
+ background: transparent !important;
2351
+ }
2352
+
2353
+ /* Table border style presets */
2354
+ .marzipan-preview .marzipan-table.mz-border-dashed th,
2355
+ .marzipan-preview .marzipan-table.mz-border-dashed td {
2356
+ border-style: dashed !important;
2357
+ }
2358
+ .marzipan-preview .marzipan-table.mz-border-dotted th,
2359
+ .marzipan-preview .marzipan-table.mz-border-dotted td {
2360
+ border-style: dotted !important;
2361
+ }
2362
+ .marzipan-preview .marzipan-table.mz-border-double th,
2363
+ .marzipan-preview .marzipan-table.mz-border-double td {
2364
+ border-style: double !important;
2365
+ border-width: 3px !important;
2366
+ }
2367
+ .marzipan-preview .marzipan-table.mz-border-none th,
2368
+ .marzipan-preview .marzipan-table.mz-border-none td {
2369
+ border-color: transparent !important;
2370
+ }
2279
2371
 
2280
2372
  /* In preview mode - hide table syntax markers */
2281
2373
  .marzipan-container.preview-mode .marzipan-wrapper .marzipan-preview .table-row,
@@ -2298,7 +2390,7 @@ function je(i = {}) {
2298
2390
  margin: 1em auto;
2299
2391
  }
2300
2392
 
2301
- ${a}
2393
+ ${s}
2302
2394
  `;
2303
2395
  }
2304
2396
  const Oe = `<svg viewBox="0 0 18 18">
@@ -2548,15 +2640,15 @@ class nt {
2548
2640
  { id: "normal", label: "Normal Edit", icon: "✓" },
2549
2641
  { id: "plain", label: "Plain Textarea", icon: "✓" },
2550
2642
  { id: "preview", label: "Preview Mode", icon: "✓" }
2551
- ].forEach((s) => {
2552
- const a = document.createElement("button");
2553
- a.className = "marzipan-dropdown-item", a.type = "button";
2643
+ ].forEach((a) => {
2644
+ const s = document.createElement("button");
2645
+ s.className = "marzipan-dropdown-item", s.type = "button";
2554
2646
  const l = document.createElement("span");
2555
- l.className = "marzipan-dropdown-check", l.textContent = r === s.id ? s.icon : "";
2556
- const p = document.createElement("span");
2557
- p.textContent = s.label, a.appendChild(l), a.appendChild(p), r === s.id && a.classList.add("active"), a.addEventListener("click", (d) => {
2558
- d.stopPropagation(), this.setViewMode(s.id), e.remove(), this.viewModeButton?.classList.remove("dropdown-active"), this.handleDocumentClick && document.removeEventListener("click", this.handleDocumentClick);
2559
- }), e.appendChild(a);
2647
+ l.className = "marzipan-dropdown-check", l.textContent = r === a.id ? a.icon : "";
2648
+ const c = document.createElement("span");
2649
+ c.textContent = a.label, s.appendChild(l), s.appendChild(c), r === a.id && s.classList.add("active"), s.addEventListener("click", (d) => {
2650
+ d.stopPropagation(), this.setViewMode(a.id), e.remove(), this.viewModeButton?.classList.remove("dropdown-active"), this.handleDocumentClick && document.removeEventListener("click", this.handleDocumentClick);
2651
+ }), e.appendChild(s);
2560
2652
  }), e;
2561
2653
  }
2562
2654
  setViewMode(e) {
@@ -2576,9 +2668,9 @@ class nt {
2576
2668
  this.container && (this.handleDocumentClick && document.removeEventListener("click", this.handleDocumentClick), this.container.remove(), this.container = null, this.buttons = {}, this.viewModeButton = void 0, this.handleDocumentClick = void 0);
2577
2669
  }
2578
2670
  }
2579
- let le = !1;
2671
+ let pe = !1;
2580
2672
  function it() {
2581
- if (le || typeof document > "u") return;
2673
+ if (pe || typeof document > "u") return;
2582
2674
  const i = document.createElement("style");
2583
2675
  i.className = "marzipan-link-tooltip-styles", i.textContent = `
2584
2676
  @supports (position-anchor: --x) and (position-area: center) {
@@ -2609,7 +2701,7 @@ function it() {
2609
2701
  display: flex !important;
2610
2702
  }
2611
2703
  }
2612
- `, document.head.appendChild(i), le = !0;
2704
+ `, document.head.appendChild(i), pe = !0;
2613
2705
  }
2614
2706
  class rt {
2615
2707
  constructor(e) {
@@ -2654,14 +2746,14 @@ class rt {
2654
2746
  const n = /\[([^\]]+)\]\(([^)]+)\)/g;
2655
2747
  let r, o = 0;
2656
2748
  for (; (r = n.exec(e)) !== null; ) {
2657
- const s = r.index, a = r.index + r[0].length;
2658
- if (t >= s && t <= a)
2749
+ const a = r.index, s = r.index + r[0].length;
2750
+ if (t >= a && t <= s)
2659
2751
  return {
2660
2752
  text: r[1],
2661
2753
  url: r[2],
2662
2754
  index: o,
2663
- start: s,
2664
- end: a
2755
+ start: a,
2756
+ end: s
2665
2757
  };
2666
2758
  o++;
2667
2759
  }
@@ -2710,8 +2802,8 @@ const w = class w {
2710
2802
  return n.map((o) => {
2711
2803
  if (o.MarzipanInstance)
2712
2804
  return o.MarzipanInstance.reinit(t), o.MarzipanInstance;
2713
- const s = Object.create(w.prototype);
2714
- return s._init(o, t), o.MarzipanInstance = s, w.instances.set(o, s), s;
2805
+ const a = Object.create(w.prototype);
2806
+ return a._init(o, t), o.MarzipanInstance = a, w.instances.set(o, a), a;
2715
2807
  });
2716
2808
  }
2717
2809
  /**
@@ -2721,9 +2813,9 @@ const w = class w {
2721
2813
  _init(e, t = {}) {
2722
2814
  this.element = e, this.options = this._mergeOptions(t), this.instanceTheme = this.options.theme ?? null, this.instanceColors = this.options.colors ? { ...this.options.colors } : null, this._appliedThemeColorKeys = /* @__PURE__ */ new Set(), this.instanceId = ++w.instanceCount, this.initialized = !1, this._autoResizeInputHandler = null, this._autoResizeResizeHandler = null, this._minAutoHeight = null, this._maxAutoHeight = null, w.injectStyles(), w.initGlobalListeners();
2723
2815
  const n = e.querySelector(".marzipan-container"), r = e.querySelector(".marzipan-wrapper");
2724
- if (n || r ? this._recoverFromDOM(n, r) : this._buildFromScratch(), this.shortcuts = new ze(this), this.linkTooltip = new rt(this), this.options.toolbar) {
2725
- const s = typeof this.options.toolbar == "object" ? this.options.toolbar.buttons : null;
2726
- this.toolbar = new nt(this, s), this.toolbar.create(), this.textarea.addEventListener("selectionchange", () => {
2816
+ if (n || r ? this._recoverFromDOM(n, r) : this._buildFromScratch(), this.shortcuts = new Se(this), this.linkTooltip = new rt(this), this.options.toolbar) {
2817
+ const a = typeof this.options.toolbar == "object" ? this.options.toolbar.buttons : null;
2818
+ this.toolbar = new nt(this, a), this.toolbar.create(), this.textarea.addEventListener("selectionchange", () => {
2727
2819
  this.toolbar?.updateButtonStates?.();
2728
2820
  }), this.textarea.addEventListener("input", () => {
2729
2821
  this.toolbar?.updateButtonStates?.();
@@ -2775,11 +2867,11 @@ const w = class w {
2775
2867
  // Theme overrides
2776
2868
  theme: null,
2777
2869
  colors: void 0
2778
- }, { hooks: n, plugins: r, ...o } = e, s = {
2870
+ }, { hooks: n, plugins: r, ...o } = e, a = {
2779
2871
  ...t,
2780
2872
  ...o
2781
2873
  };
2782
- return n && (s.hooks = { ...n }), Array.isArray(r) && (s.plugins = [...r]), s.theme && typeof s.theme == "object" && (s.theme = { ...s.theme }), s.colors && (s.colors = { ...s.colors }), s;
2874
+ return n && (a.hooks = { ...n }), Array.isArray(r) && (a.plugins = [...r]), a.theme && typeof a.theme == "object" && (a.theme = { ...a.theme }), a.colors && (a.colors = { ...a.colors }), a;
2783
2875
  }
2784
2876
  /**
2785
2877
  * Apply plugins attached to this editor instance
@@ -2804,7 +2896,7 @@ const w = class w {
2804
2896
  }
2805
2897
  _resolveTheme() {
2806
2898
  let e = this.instanceTheme;
2807
- return typeof e == "string" && (e = $(e)), e || (e = w.currentTheme || _), typeof e == "string" && (e = $(e)), this.instanceColors ? ae(e, this.instanceColors) : e;
2899
+ return typeof e == "string" && (e = M(e)), e || (e = w.currentTheme || I), typeof e == "string" && (e = M(e)), this.instanceColors ? ce(e, this.instanceColors) : e;
2808
2900
  }
2809
2901
  _applyTheme(e) {
2810
2902
  if (!e) return;
@@ -2815,10 +2907,10 @@ const w = class w {
2815
2907
  this._appliedThemeColorKeys.clear();
2816
2908
  const r = t?.colors;
2817
2909
  if (r)
2818
- for (const [o, s] of Object.entries(r)) {
2819
- if (s == null) continue;
2820
- const a = `--${o.replace(/([A-Z])/g, "-$1").toLowerCase()}`;
2821
- e.style.setProperty(a, String(s)), this._appliedThemeColorKeys.add(a);
2910
+ for (const [o, a] of Object.entries(r)) {
2911
+ if (a == null) continue;
2912
+ const s = `--${o.replace(/([A-Z])/g, "-$1").toLowerCase()}`;
2913
+ e.style.setProperty(s, String(a)), this._appliedThemeColorKeys.add(s);
2822
2914
  }
2823
2915
  }
2824
2916
  /**
@@ -2879,7 +2971,7 @@ const w = class w {
2879
2971
  * Update preview with parsed markdown
2880
2972
  */
2881
2973
  updatePreview() {
2882
- const e = this.textarea.value, t = this.textarea.selectionStart, n = this._getCurrentLine(e, t), r = H.parse(e, n, this.options.showActiveLineRaw);
2974
+ const e = this.textarea.value, t = this.textarea.selectionStart, n = this._getCurrentLine(e, t), r = $.parse(e, n, this.options.showActiveLineRaw);
2883
2975
  if (this.preview.innerHTML = r || '<span style="color: #808080;">Start typing...</span>', this.options?.hooks?.afterPreviewRender)
2884
2976
  try {
2885
2977
  this.options.hooks.afterPreviewRender(this.preview, this);
@@ -2895,8 +2987,8 @@ const w = class w {
2895
2987
  _applyCodeBlockBackgrounds() {
2896
2988
  const e = this.preview.querySelectorAll(".code-fence");
2897
2989
  for (let t = 0; t < e.length - 1; t += 2) {
2898
- const n = e[t], r = e[t + 1], o = n.parentElement, s = r.parentElement;
2899
- !o || !s || (n.style.display = "block", r.style.display = "block", o.classList.add("code-block-line"), s.classList.add("code-block-line"));
2990
+ const n = e[t], r = e[t + 1], o = n.parentElement, a = r.parentElement;
2991
+ !o || !a || (n.style.display = "block", r.style.display = "block", o.classList.add("code-block-line"), a.classList.add("code-block-line"));
2900
2992
  }
2901
2993
  }
2902
2994
  /**
@@ -2923,15 +3015,15 @@ const w = class w {
2923
3015
  e.preventDefault();
2924
3016
  const n = this.textarea.selectionStart, r = this.textarea.selectionEnd, o = this.textarea.value;
2925
3017
  if (n !== r && e.shiftKey) {
2926
- const s = o.substring(0, n), a = o.substring(n, r), l = o.substring(r), d = a.split(`
2927
- `).map((c) => c.replace(/^ {2}/, "")).join(`
3018
+ const a = o.substring(0, n), s = o.substring(n, r), l = o.substring(r), d = s.split(`
3019
+ `).map((p) => p.replace(/^ {2}/, "")).join(`
2928
3020
  `);
2929
- document.execCommand ? (this.textarea.setSelectionRange(n, r), document.execCommand("insertText", !1, d)) : (this.textarea.value = s + d + l, this.textarea.selectionStart = n, this.textarea.selectionEnd = n + d.length);
3021
+ document.execCommand ? (this.textarea.setSelectionRange(n, r), document.execCommand("insertText", !1, d)) : (this.textarea.value = a + d + l, this.textarea.selectionStart = n, this.textarea.selectionEnd = n + d.length);
2930
3022
  } else if (n !== r) {
2931
- const s = o.substring(0, n), a = o.substring(n, r), l = o.substring(r), d = a.split(`
2932
- `).map((c) => " " + c).join(`
3023
+ const a = o.substring(0, n), s = o.substring(n, r), l = o.substring(r), d = s.split(`
3024
+ `).map((p) => " " + p).join(`
2933
3025
  `);
2934
- document.execCommand ? (this.textarea.setSelectionRange(n, r), document.execCommand("insertText", !1, d)) : (this.textarea.value = s + d + l, this.textarea.selectionStart = n, this.textarea.selectionEnd = n + d.length);
3026
+ document.execCommand ? (this.textarea.setSelectionRange(n, r), document.execCommand("insertText", !1, d)) : (this.textarea.value = a + d + l, this.textarea.selectionStart = n, this.textarea.selectionEnd = n + d.length);
2935
3027
  } else
2936
3028
  document.execCommand ? document.execCommand("insertText", !1, " ") : (this.textarea.value = o.substring(0, n) + " " + o.substring(r), this.textarea.selectionStart = this.textarea.selectionEnd = n + 2);
2937
3029
  this.textarea.dispatchEvent(new Event("input", { bubbles: !0 }));
@@ -2948,7 +3040,7 @@ const w = class w {
2948
3040
  * @returns {boolean} Whether the event was handled
2949
3041
  */
2950
3042
  handleSmartListContinuation() {
2951
- const e = this.textarea, t = e.selectionStart, n = H.getListContext(e.value, t);
3043
+ const e = this.textarea, t = e.selectionStart, n = $.getListContext(e.value, t);
2952
3044
  return !n || !n.inList ? !1 : n.content.trim() === "" && t >= n.markerEndPos ? (this.deleteListMarker(n), !0) : (t > n.markerEndPos && t < n.lineEnd ? this.splitListItem(n, t) : this.insertNewListItem(n), n.listType === "numbered" && this.scheduleNumberedListUpdate(), !0);
2953
3045
  }
2954
3046
  /**
@@ -2963,7 +3055,7 @@ const w = class w {
2963
3055
  * @private
2964
3056
  */
2965
3057
  insertNewListItem(e) {
2966
- const t = H.createNewListItem(e);
3058
+ const t = $.createNewListItem(e);
2967
3059
  document.execCommand("insertText", !1, `
2968
3060
  ` + t), this.textarea.dispatchEvent(new Event("input", { bubbles: !0 }));
2969
3061
  }
@@ -2974,7 +3066,7 @@ const w = class w {
2974
3066
  splitListItem(e, t) {
2975
3067
  const n = e.content.substring(t - e.markerEndPos);
2976
3068
  this.textarea.setSelectionRange(t, e.lineEnd), document.execCommand("delete");
2977
- const r = H.createNewListItem(e);
3069
+ const r = $.createNewListItem(e);
2978
3070
  document.execCommand("insertText", !1, `
2979
3071
  ` + r + n);
2980
3072
  const o = this.textarea.selectionStart - n.length;
@@ -2994,19 +3086,19 @@ const w = class w {
2994
3086
  * @private
2995
3087
  */
2996
3088
  updateNumberedLists() {
2997
- const e = this.textarea.value, t = this.textarea.selectionStart, n = H.renumberLists(e);
3089
+ const e = this.textarea.value, t = this.textarea.selectionStart, n = $.renumberLists(e);
2998
3090
  if (n !== e) {
2999
3091
  let r = 0;
3000
3092
  const o = e.split(`
3001
- `), s = n.split(`
3093
+ `), a = n.split(`
3002
3094
  `);
3003
- let a = 0;
3004
- for (let p = 0; p < o.length && a < t; p++) {
3005
- if (o[p] !== s[p]) {
3006
- const d = s[p].length - o[p].length;
3007
- a + o[p].length < t && (r += d);
3095
+ let s = 0;
3096
+ for (let c = 0; c < o.length && s < t; c++) {
3097
+ if (o[c] !== a[c]) {
3098
+ const d = a[c].length - o[c].length;
3099
+ s + o[c].length < t && (r += d);
3008
3100
  }
3009
- a += o[p].length + 1;
3101
+ s += o[c].length + 1;
3010
3102
  }
3011
3103
  this.textarea.value = n;
3012
3104
  const l = t + r;
@@ -3056,7 +3148,7 @@ const w = class w {
3056
3148
  */
3057
3149
  getRenderedHTML(e = {}) {
3058
3150
  const t = this.getValue();
3059
- let n = H.parse(t);
3151
+ let n = $.parse(t);
3060
3152
  return e.cleanHTML && (n = n.replace(/<span class="syntax-marker[^"]*">.*?<\/span>/g, ""), n = n.replace(/\sclass="(bullet-list|ordered-list|code-fence|hr-marker|blockquote|url-part)"/g, ""), n = n.replace(/\sclass=""/g, "")), n;
3061
3153
  }
3062
3154
  /**
@@ -3115,14 +3207,14 @@ const w = class w {
3115
3207
  column: 0
3116
3208
  };
3117
3209
  const e = this.textarea.value, t = e.split(`
3118
- `), n = e.length, r = e.split(/\s+/).filter((d) => d.length > 0).length, o = this.textarea.selectionStart, a = e.substring(0, o).split(`
3119
- `), l = a.length, p = a[a.length - 1].length + 1;
3210
+ `), n = e.length, r = e.split(/\s+/).filter((d) => d.length > 0).length, o = this.textarea.selectionStart, s = e.substring(0, o).split(`
3211
+ `), l = s.length, c = s[s.length - 1].length + 1;
3120
3212
  return {
3121
3213
  chars: n,
3122
3214
  words: r,
3123
3215
  lines: t.length,
3124
3216
  line: l,
3125
- column: p
3217
+ column: c
3126
3218
  };
3127
3219
  }
3128
3220
  _updateStats() {
@@ -3154,13 +3246,13 @@ const w = class w {
3154
3246
  if (!this.options.autoResize) return;
3155
3247
  const e = this.textarea, t = this.preview, n = this.wrapper, r = e.scrollTop;
3156
3248
  e.style.setProperty("height", "auto", "important");
3157
- let o = e.scrollHeight, s = "hidden";
3158
- const a = this._minAutoHeight;
3159
- typeof a == "number" && a > 0 && (o = Math.max(o, a));
3249
+ let o = e.scrollHeight, a = "hidden";
3250
+ const s = this._minAutoHeight;
3251
+ typeof s == "number" && s > 0 && (o = Math.max(o, s));
3160
3252
  const l = this._maxAutoHeight;
3161
- typeof l == "number" && l > 0 && o > l && (o = l, s = "auto");
3162
- const p = o + "px";
3163
- e.style.setProperty("height", p, "important"), e.style.setProperty("overflow-y", s, "important"), t.style.setProperty("height", p, "important"), t.style.setProperty("overflow-y", s, "important"), n.style.setProperty("height", p, "important"), e.scrollTop = r, t.scrollTop = r, this.previousHeight !== o && (this.previousHeight = o);
3253
+ typeof l == "number" && l > 0 && o > l && (o = l, a = "auto");
3254
+ const c = o + "px";
3255
+ e.style.setProperty("height", c, "important"), e.style.setProperty("overflow-y", a, "important"), t.style.setProperty("height", c, "important"), t.style.setProperty("overflow-y", a, "important"), n.style.setProperty("height", c, "important"), e.scrollTop = r, t.scrollTop = r, this.previousHeight !== o && (this.previousHeight = o);
3164
3256
  }
3165
3257
  _refreshAutoResizeConstraints() {
3166
3258
  this._minAutoHeight = this._resolveSizeToPixels(this.options.minHeight), this._maxAutoHeight = this._resolveSizeToPixels(this.options.maxHeight);
@@ -3262,7 +3354,7 @@ const w = class w {
3262
3354
  if (w.stylesInjected && !e) return;
3263
3355
  const t = document.querySelector("style.marzipan-styles");
3264
3356
  t && t.remove();
3265
- const n = w.currentTheme || _, r = je({ theme: n }), o = document.createElement("style");
3357
+ const n = w.currentTheme || I, r = je({ theme: n }), o = document.createElement("style");
3266
3358
  o.className = "marzipan-styles", o.textContent = r, document.head.appendChild(o), w.stylesInjected = !0;
3267
3359
  }
3268
3360
  /**
@@ -3271,16 +3363,16 @@ const w = class w {
3271
3363
  * @param {Object} customColors - Optional color overrides
3272
3364
  */
3273
3365
  static setTheme(e, t = null) {
3274
- let n = typeof e == "string" ? $(e) : e;
3275
- t && (n = ae(n, t)), w.currentTheme = n, w.injectStyles(!0);
3366
+ let n = typeof e == "string" ? M(e) : e;
3367
+ t && (n = ce(n, t)), w.currentTheme = n, w.injectStyles(!0);
3276
3368
  const r = typeof e == "string" ? e : n?.name;
3277
3369
  document.querySelectorAll(".marzipan-container").forEach((o) => {
3278
- const a = o.querySelector(".marzipan-wrapper")?._instance;
3279
- a ? (a._applyTheme(o), a.updatePreview()) : r && o.setAttribute("data-theme", r);
3370
+ const s = o.querySelector(".marzipan-wrapper")?._instance;
3371
+ s ? (s._applyTheme(o), s.updatePreview()) : r && o.setAttribute("data-theme", r);
3280
3372
  }), document.querySelectorAll(".marzipan-wrapper").forEach((o) => {
3281
3373
  if (!o.closest(".marzipan-container")) {
3282
- const s = o._instance;
3283
- s ? (s._applyTheme(o), s.updatePreview()) : r && o.setAttribute("data-theme", r);
3374
+ const a = o._instance;
3375
+ a ? (a._applyTheme(o), a.updatePreview()) : r && o.setAttribute("data-theme", r);
3284
3376
  }
3285
3377
  });
3286
3378
  }
@@ -3315,48 +3407,46 @@ const w = class w {
3315
3407
  }
3316
3408
  };
3317
3409
  w.instances = /* @__PURE__ */ new WeakMap(), w.stylesInjected = !1, w.globalListenersInitialized = !1, w.instanceCount = 0;
3318
- let A = w;
3319
- A.MarkdownParser = H;
3320
- A.ShortcutsManager = ze;
3321
- A.themes = {
3322
- solar: _,
3323
- cave: $("cave"),
3324
- light: $("light"),
3325
- dark: $("dark")
3410
+ let _ = w;
3411
+ _.MarkdownParser = $;
3412
+ _.ShortcutsManager = Se;
3413
+ _.themes = {
3414
+ solar: I,
3415
+ cave: M("cave"),
3416
+ light: M("light"),
3417
+ dark: M("dark")
3326
3418
  };
3327
- A.getTheme = $;
3328
- A.currentTheme = _;
3419
+ _.getTheme = M;
3420
+ _.currentTheme = I;
3329
3421
  export {
3330
3422
  rt as LinkTooltip,
3331
- H as MarkdownParser,
3332
- A as Marzipan,
3333
- ze as ShortcutsManager,
3423
+ $ as MarkdownParser,
3424
+ _ as Marzipan,
3425
+ Se as ShortcutsManager,
3334
3426
  nt as Toolbar,
3335
- ct as accentSwatchPlugin,
3336
- pt as accentSwatchStyles,
3337
3427
  Ie as actions,
3338
- mt as buildTableMarkdown,
3339
- oe as cave,
3340
- ft as coreImagePickerPlugin,
3341
- A as default,
3428
+ ct as buildTableMarkdown,
3429
+ se as cave,
3430
+ mt as coreImagePickerPlugin,
3431
+ _ as default,
3342
3432
  je as generateStyles,
3343
- $ as getTheme,
3344
- bt as imageManagerPlugin,
3345
- vt as imageManagerStyles,
3346
- kt as imagePickerPlugin,
3347
- ae as mergeTheme,
3348
- xt as mermaidExternalPlugin,
3349
- Lt as mermaidPlugin,
3350
- at as plugins,
3351
- ht as resolvePositiveInteger,
3352
- _ as solar,
3353
- Ct as tableGeneratorPlugin,
3354
- Tt as tableGridPlugin,
3355
- Ht as tableGridStyles,
3356
- Mt as tablePlugin,
3433
+ M as getTheme,
3434
+ ut as imageManagerPlugin,
3435
+ ft as imageManagerStyles,
3436
+ bt as imagePickerPlugin,
3437
+ ce as mergeTheme,
3438
+ wt as mermaidExternalPlugin,
3439
+ yt as mermaidPlugin,
3440
+ st as plugins,
3441
+ pt as resolvePositiveInteger,
3442
+ I as solar,
3443
+ zt as tableGeneratorPlugin,
3444
+ St as tableGridPlugin,
3445
+ Ct as tableGridStyles,
3446
+ Et as tablePlugin,
3357
3447
  Ne as themeToCSSVars,
3358
- se as themes,
3359
- _t as tinyHighlightPlugin,
3360
- Pt as tinyHighlightStyles
3448
+ le as themes,
3449
+ $t as tinyHighlightPlugin,
3450
+ Mt as tinyHighlightStyles
3361
3451
  };
3362
3452
  //# sourceMappingURL=index.js.map