@toantranmei/editor 0.3.0 → 0.4.0

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.
package/dist/render.js CHANGED
@@ -1,56 +1,56 @@
1
- import { a as e, f as t, g as n, h as r, m as i, y as a } from "./date-utils-DW99lT2W.js";
2
- import { i as o, t as s } from "./css-el97DJfy.js";
3
- import { createLowlight as c } from "lowlight";
4
- import l from "highlight.js/lib/languages/arduino";
5
- import u from "highlight.js/lib/languages/bash";
6
- import d from "highlight.js/lib/languages/c";
7
- import f from "highlight.js/lib/languages/cpp";
8
- import p from "highlight.js/lib/languages/csharp";
9
- import m from "highlight.js/lib/languages/css";
10
- import h from "highlight.js/lib/languages/diff";
11
- import g from "highlight.js/lib/languages/go";
12
- import _ from "highlight.js/lib/languages/graphql";
13
- import v from "highlight.js/lib/languages/ini";
14
- import y from "highlight.js/lib/languages/java";
15
- import b from "highlight.js/lib/languages/javascript";
16
- import ee from "highlight.js/lib/languages/json";
17
- import te from "highlight.js/lib/languages/kotlin";
18
- import ne from "highlight.js/lib/languages/less";
19
- import re from "highlight.js/lib/languages/lua";
20
- import ie from "highlight.js/lib/languages/makefile";
21
- import ae from "highlight.js/lib/languages/markdown";
22
- import oe from "highlight.js/lib/languages/objectivec";
23
- import se from "highlight.js/lib/languages/perl";
24
- import x from "highlight.js/lib/languages/php";
25
- import ce from "highlight.js/lib/languages/python";
26
- import le from "highlight.js/lib/languages/r";
27
- import S from "highlight.js/lib/languages/ruby";
28
- import C from "highlight.js/lib/languages/rust";
29
- import w from "highlight.js/lib/languages/scss";
30
- import T from "highlight.js/lib/languages/shell";
31
- import E from "highlight.js/lib/languages/sql";
32
- import D from "highlight.js/lib/languages/swift";
33
- import ue from "highlight.js/lib/languages/typescript";
34
- import de from "highlight.js/lib/languages/xml";
35
- import fe from "highlight.js/lib/languages/yaml";
1
+ import { a as e, f as t, g as n, h as r, m as i, y as a } from "./date-utils-CevhhRfQ.js";
2
+ import { a as o, f as s, m as c, n as l, o as u, p as d, t as f, u as p } from "./css-Cf_w91Fs.js";
3
+ import { createLowlight as m } from "lowlight";
4
+ import h from "highlight.js/lib/languages/arduino";
5
+ import g from "highlight.js/lib/languages/bash";
6
+ import _ from "highlight.js/lib/languages/c";
7
+ import v from "highlight.js/lib/languages/cpp";
8
+ import y from "highlight.js/lib/languages/csharp";
9
+ import b from "highlight.js/lib/languages/css";
10
+ import x from "highlight.js/lib/languages/diff";
11
+ import S from "highlight.js/lib/languages/go";
12
+ import ee from "highlight.js/lib/languages/graphql";
13
+ import te from "highlight.js/lib/languages/ini";
14
+ import ne from "highlight.js/lib/languages/java";
15
+ import re from "highlight.js/lib/languages/javascript";
16
+ import ie from "highlight.js/lib/languages/json";
17
+ import ae from "highlight.js/lib/languages/kotlin";
18
+ import oe from "highlight.js/lib/languages/less";
19
+ import se from "highlight.js/lib/languages/lua";
20
+ import ce from "highlight.js/lib/languages/makefile";
21
+ import le from "highlight.js/lib/languages/markdown";
22
+ import ue from "highlight.js/lib/languages/objectivec";
23
+ import de from "highlight.js/lib/languages/perl";
24
+ import fe from "highlight.js/lib/languages/php";
25
+ import pe from "highlight.js/lib/languages/python";
26
+ import me from "highlight.js/lib/languages/r";
27
+ import he from "highlight.js/lib/languages/ruby";
28
+ import ge from "highlight.js/lib/languages/rust";
29
+ import _e from "highlight.js/lib/languages/scss";
30
+ import ve from "highlight.js/lib/languages/shell";
31
+ import ye from "highlight.js/lib/languages/sql";
32
+ import be from "highlight.js/lib/languages/swift";
33
+ import C from "highlight.js/lib/languages/typescript";
34
+ import w from "highlight.js/lib/languages/xml";
35
+ import T from "highlight.js/lib/languages/yaml";
36
36
  // src/render/html.ts
37
- var pe = {
37
+ var E = {
38
38
  "&": "&",
39
39
  "<": "&lt;",
40
40
  ">": "&gt;",
41
41
  "\"": "&quot;",
42
42
  "'": "&#39;"
43
- }, O = /[&<>"']/g;
44
- function k(e) {
43
+ }, D = /[&<>"']/g;
44
+ function O(e) {
45
45
  if (e == null) return "";
46
46
  let t = String(e);
47
- return O.test(t) ? t.replace(O, (e) => pe[e]) : t;
47
+ return D.test(t) ? t.replace(D, (e) => E[e]) : t;
48
48
  }
49
- function A(e, t) {
50
- return t == null || t === !1 ? "" : t === !0 ? ` ${e}` : ` ${e}="${k(t)}"`;
49
+ function k(e, t) {
50
+ return t == null || t === !1 ? "" : t === !0 ? ` ${e}` : ` ${e}="${O(t)}"`;
51
51
  }
52
- var j = /^data:(?:image\/(?:png|jpe?g|gif|webp|avif|bmp|x-icon|svg\+xml)|audio\/[\w.+-]+|video\/[\w.+-]+)[;,]/i, M = /^data:(?:text\/html|application\/xhtml|image\/svg|text\/xml|application\/xml|text\/javascript|application\/javascript)/i;
53
- function N(e, t = "link") {
52
+ var A = /^data:(?:image\/(?:png|jpe?g|gif|webp|avif|bmp|x-icon|svg\+xml)|audio\/[\w.+-]+|video\/[\w.+-]+)[;,]/i, j = /^data:(?:text\/html|application\/xhtml|image\/svg|text\/xml|application\/xml|text\/javascript|application\/javascript)/i;
53
+ function M(e, t = "link") {
54
54
  if (typeof e != "string") return null;
55
55
  let n = e.trim();
56
56
  if (!n) return null;
@@ -60,73 +60,73 @@ function N(e, t = "link") {
60
60
  if (i === "http" || i === "https") return n;
61
61
  if (i === "mailto") return t === "link" ? n : null;
62
62
  if (i === "data") {
63
- if (t === "media") return j.test(r) ? n : null;
64
- if (t === "download") return M.test(r) ? null : n;
63
+ if (t === "media") return A.test(r) ? n : null;
64
+ if (t === "download") return j.test(r) ? null : n;
65
65
  }
66
66
  return null;
67
67
  }
68
- var P = (e) => /^https?:\/\//i.test(e) || e.startsWith("//"), F = c({
69
- arduino: l,
70
- bash: u,
71
- c: d,
72
- cpp: f,
73
- csharp: p,
74
- css: m,
75
- diff: h,
76
- go: g,
77
- graphql: _,
78
- ini: v,
79
- java: y,
80
- javascript: b,
81
- json: ee,
82
- kotlin: te,
83
- less: ne,
84
- lua: re,
85
- makefile: ie,
86
- markdown: ae,
87
- objectivec: oe,
88
- perl: se,
89
- php: x,
90
- python: ce,
91
- r: le,
92
- ruby: S,
93
- rust: C,
94
- scss: w,
95
- shell: T,
96
- sql: E,
97
- swift: D,
98
- typescript: ue,
99
- xml: de,
100
- yaml: fe
68
+ var N = (e) => /^https?:\/\//i.test(e) || e.startsWith("//"), P = m({
69
+ arduino: h,
70
+ bash: g,
71
+ c: _,
72
+ cpp: v,
73
+ csharp: y,
74
+ css: b,
75
+ diff: x,
76
+ go: S,
77
+ graphql: ee,
78
+ ini: te,
79
+ java: ne,
80
+ javascript: re,
81
+ json: ie,
82
+ kotlin: ae,
83
+ less: oe,
84
+ lua: se,
85
+ makefile: ce,
86
+ markdown: le,
87
+ objectivec: ue,
88
+ perl: de,
89
+ php: fe,
90
+ python: pe,
91
+ r: me,
92
+ ruby: he,
93
+ rust: ge,
94
+ scss: _e,
95
+ shell: ve,
96
+ sql: ye,
97
+ swift: be,
98
+ typescript: C,
99
+ xml: w,
100
+ yaml: T
101
101
  });
102
- function I(e) {
103
- if (e.type === "text") return k(e.value ?? "");
104
- let t = (e.children ?? []).map(I).join("");
102
+ function F(e) {
103
+ if (e.type === "text") return O(e.value ?? "");
104
+ let t = (e.children ?? []).map(F).join("");
105
105
  if (e.type === "element") {
106
106
  let n = e.properties?.className, r = (Array.isArray(n) ? n : n ? [n] : []).filter((e) => /^[\w-]+$/.test(e));
107
107
  return r.length ? `<span class="${r.join(" ")}">${t}</span>` : `<span>${t}</span>`;
108
108
  }
109
109
  return t;
110
110
  }
111
- function L(e) {
111
+ function xe(e) {
112
112
  if (!e) return null;
113
113
  let t = n[e] ?? e;
114
- return F.registered(t) ? t : null;
114
+ return P.registered(t) ? t : null;
115
115
  }
116
- function R(e, t) {
117
- let n = L(t);
118
- if (!n) return k(e);
116
+ function I(e, t) {
117
+ let n = xe(t);
118
+ if (!n) return O(e);
119
119
  try {
120
- return I(F.highlight(n, e));
120
+ return F(P.highlight(n, e));
121
121
  } catch {
122
- return k(e);
122
+ return O(e);
123
123
  }
124
124
  }
125
125
  // src/render/nodes.ts
126
- var z = (e) => e.state, B = (e) => e.type === "text" ? e.text ?? "" : (e.content ?? []).map(B).join(""), me = (e) => e.normalize("NFKD").replace(/[̀-ͯ]/g, "").replace(/đ/gi, "d").toLowerCase().replace(/[^\p{L}\p{N}]+/gu, "-").replace(/^-+|-+$/g, "").slice(0, 64) || "section";
127
- function he(e) {
126
+ var L = (e) => e.state, R = (e) => e.type === "text" ? e.text ?? "" : (e.content ?? []).map(R).join(""), Se = (e) => e.normalize("NFKD").replace(/[̀-ͯ]/g, "").replace(/đ/gi, "d").toLowerCase().replace(/[^\p{L}\p{N}]+/gu, "-").replace(/^-+|-+$/g, "").slice(0, 64) || "section";
127
+ function Ce(e) {
128
128
  let t = [], n = /* @__PURE__ */ new WeakMap(), r = /* @__PURE__ */ new Set(), i = (e, t) => {
129
- let i = typeof e.attrs?.id == "string" && e.attrs.id ? e.attrs.id : me(t);
129
+ let i = typeof e.attrs?.id == "string" && e.attrs.id ? e.attrs.id : Se(t);
130
130
  if (r.has(i)) {
131
131
  let e = 2;
132
132
  for (; r.has(`${i}-${e}`);) e++;
@@ -135,7 +135,7 @@ function he(e) {
135
135
  return r.add(i), n.set(e, i), i;
136
136
  }, a = (e) => {
137
137
  if (e.type === "heading") {
138
- let n = B(e);
138
+ let n = R(e);
139
139
  t.push({
140
140
  level: Number(e.attrs?.level) || 1,
141
141
  text: n,
@@ -143,7 +143,7 @@ function he(e) {
143
143
  });
144
144
  } else {
145
145
  if (e.type === "details" && e.attrs?.level) {
146
- let n = e.content?.[0] ? B(e.content[0]) : "";
146
+ let n = e.content?.[0] ? R(e.content[0]) : "";
147
147
  t.push({
148
148
  level: Number(e.attrs.level) || 1,
149
149
  text: n,
@@ -158,16 +158,16 @@ function he(e) {
158
158
  anchorOf: n
159
159
  };
160
160
  }
161
- var V = (e, t, n, r) => {
161
+ var z = (e, t, n, r) => {
162
162
  let i = Number(e);
163
163
  return Number.isFinite(i) ? Math.min(n, Math.max(t, i)) : r;
164
- }, H = (e) => typeof e == "number" && Number.isFinite(e) ? e : null, ge = /^[a-z]+$/, U = (e) => typeof e == "string" && ge.test(e) ? e : null, W = (e, t = "") => ((n, r) => `<${e}${t}${r.blockAttrs(n)}>${r.children(n)}</${e}>`);
165
- function G(e, t) {
166
- let n = (t.options.externalLinksInNewTab ?? !0) && P(e);
167
- return `${A("href", e)}${n ? " target=\"_blank\" rel=\"noopener noreferrer nofollow\"" : ""}`;
164
+ }, B = (e) => typeof e == "number" && Number.isFinite(e) ? e : null, we = /^[a-z]+$/, V = (e) => typeof e == "string" && we.test(e) ? e : null, H = (e, t = "") => ((n, r) => `<${e}${t}${r.blockAttrs(n)}>${r.children(n)}</${e}>`);
165
+ function U(e, t) {
166
+ let n = (t.options.externalLinksInNewTab ?? !0) && N(e);
167
+ return `${k("href", e)}${n ? " target=\"_blank\" rel=\"noopener noreferrer nofollow\"" : ""}`;
168
168
  }
169
- function K(e, t, n) {
170
- let r = z(n).katex;
169
+ function W(e, t, n) {
170
+ let r = L(n).katex;
171
171
  if (r) try {
172
172
  return r.renderToString(e, {
173
173
  displayMode: t,
@@ -177,9 +177,9 @@ function K(e, t, n) {
177
177
  output: "htmlAndMathml"
178
178
  });
179
179
  } catch {}
180
- return `<code class="me-math-source">${k(e)}</code>`;
180
+ return `<code class="me-math-source">${O(e)}</code>`;
181
181
  }
182
- function _e(e) {
182
+ function Te(e) {
183
183
  let t = Number(e);
184
184
  if (!t || !Number.isFinite(t) || t < 0) return "";
185
185
  let n = [
@@ -190,96 +190,96 @@ function _e(e) {
190
190
  ], r = Math.min(n.length - 1, Math.floor(Math.log(t) / Math.log(1024)));
191
191
  return `${(t / 1024 ** r).toFixed(+!!r)} ${n[r]}`;
192
192
  }
193
- var q = {
193
+ var G = {
194
194
  file: "file",
195
195
  audio: "audio",
196
196
  video: "video"
197
- }, ve = {
197
+ }, Ee = {
198
198
  doc: (e, t) => t.children(e),
199
- paragraph: W("p"),
199
+ paragraph: H("p"),
200
200
  hardBreak: () => "<br>",
201
201
  heading: (e, t) => {
202
- let n = V(e.attrs?.level, 1, 6, 1);
203
- return `<h${n}${A("id", z(t).anchorOf.get(e))}${t.blockAttrs(e)}>${t.children(e)}</h${n}>`;
202
+ let n = z(e.attrs?.level, 1, 6, 1);
203
+ return `<h${n}${k("id", L(t).anchorOf.get(e))}${t.blockAttrs(e)}>${t.children(e)}</h${n}>`;
204
204
  },
205
- blockquote: W("blockquote"),
205
+ blockquote: H("blockquote"),
206
206
  horizontalRule: (e, t) => `<hr${t.blockAttrs(e)}>`,
207
- bulletList: W("ul"),
207
+ bulletList: H("ul"),
208
208
  orderedList: (e, t) => {
209
- let n = H(e.attrs?.start);
210
- return `<ol${n !== null && n !== 1 ? A("start", Math.trunc(n)) : ""}${t.blockAttrs(e)}>${t.children(e)}</ol>`;
209
+ let n = B(e.attrs?.start);
210
+ return `<ol${n !== null && n !== 1 ? k("start", Math.trunc(n)) : ""}${t.blockAttrs(e)}>${t.children(e)}</ol>`;
211
211
  },
212
- listItem: W("li"),
213
- taskList: W("ul", " data-type=\"taskList\""),
212
+ listItem: H("li"),
213
+ taskList: H("ul", " data-type=\"taskList\""),
214
214
  taskItem: (e, t) => {
215
215
  let n = !!e.attrs?.checked;
216
216
  return `<li data-type="taskItem" data-checked="${n}"${t.blockAttrs(e)}><label><input type="checkbox" tabindex="-1" aria-readonly="true"${n ? " checked" : ""}><span></span></label><div>${t.children(e)}</div></li>`;
217
217
  },
218
218
  codeBlock: (e, t) => {
219
219
  let n = t.text(e), r = typeof e.attrs?.language == "string" ? e.attrs.language : "", i = /^[\w+#.-]{1,32}$/.test(r) ? r : "plaintext";
220
- return i === "mermaid" ? `<div class="me-code-block me-mermaid-block"${t.blockAttrs(e)}><pre class="mermaid">${k(n)}</pre></div>` : `<div class="me-code-block"${t.blockAttrs(e)}><div class="me-block-bar me-code-toolbar"><span class="me-code-lang">${k(i)}</span></div><pre><code class="hljs language-${k(i)}">${R(n, i)}</code></pre></div>`;
220
+ return i === "mermaid" ? `<div class="me-code-block me-mermaid-block"${t.blockAttrs(e)}><pre class="mermaid">${O(n)}</pre></div>` : `<div class="me-code-block"${t.blockAttrs(e)}><div class="me-block-bar me-code-toolbar"><span class="me-code-lang">${O(i)}</span></div><pre><code class="hljs language-${O(i)}">${I(n, i)}</code></pre></div>`;
221
221
  },
222
222
  image: (e, t) => {
223
223
  let n = e.attrs ?? {}, r = t.safeUrl(n.src, "media");
224
224
  if (!r) return "";
225
- let i = V(n.width, 1, 100, 100), a = ["left", "right"].includes(n.align) ? n.align : "center", o = n.crop && typeof n.crop == "object" ? n.crop : null, s = o && [
225
+ let i = z(n.width, 1, 100, 100), a = ["left", "right"].includes(n.align) ? n.align : "center", o = n.crop && typeof n.crop == "object" ? n.crop : null, s = o && [
226
226
  o.x,
227
227
  o.y,
228
228
  o.w,
229
229
  o.h,
230
230
  o.ratio
231
- ].every((e) => H(e) !== null) && o.w > 0 && o.h > 0 && o.ratio > 0 ? o : null, c = s ? ` style="width:${100 / s.w}%;left:${-s.x / s.w * 100}%;top:${-s.y / s.h * 100}%"` : "", l = typeof n.caption == "string" ? n.caption : "", u = (n.showCaption ?? !!l) && l;
232
- return `<div class="me-media"${t.blockAttrs(e)}><figure class="me-figure me-figure--${a}" style="width:${i}%"><div class="me-figure-frame"><div class="me-figure-media${s ? " is-cropped" : ""}"${s ? ` style="aspect-ratio:${s.ratio}"` : ""}><img class="me-figure-img"${A("src", r)}${A("alt", n.alt ?? "")}${A("title", n.title)} loading="lazy" decoding="async"${c}></div></div>${u ? `<figcaption class="me-caption">${k(l)}</figcaption>` : ""}</figure></div>`;
231
+ ].every((e) => B(e) !== null) && o.w > 0 && o.h > 0 && o.ratio > 0 ? o : null, c = s ? ` style="width:${100 / s.w}%;left:${-s.x / s.w * 100}%;top:${-s.y / s.h * 100}%"` : "", l = typeof n.caption == "string" ? n.caption : "", u = (n.showCaption ?? !!l) && l;
232
+ return `<div class="me-media"${t.blockAttrs(e)}><figure class="me-figure me-figure--${a}" style="width:${i}%"><div class="me-figure-frame"><div class="me-figure-media${s ? " is-cropped" : ""}"${s ? ` style="aspect-ratio:${s.ratio}"` : ""}><img class="me-figure-img"${k("src", r)}${k("alt", n.alt ?? "")}${k("title", n.title)} loading="lazy" decoding="async"${c}></div></div>${u ? `<figcaption class="me-caption">${O(l)}</figcaption>` : ""}</figure></div>`;
233
233
  },
234
234
  embed: (e, t) => {
235
235
  let n = t.safeUrl(typeof e.attrs?.src == "string" ? r(e.attrs.src) : null, "frame");
236
236
  if (!n) return "";
237
- let i = Math.round(V(e.attrs?.height, 50, 2e3, 400));
238
- return `<div class="me-media"${t.blockAttrs(e)}><div class="me-embed"><iframe class="me-embed-frame"${A("src", n)} height="${i}" sandbox="allow-scripts allow-same-origin allow-popups allow-presentation" allowfullscreen loading="lazy" referrerpolicy="strict-origin-when-cross-origin"></iframe></div></div>`;
237
+ let i = Math.round(z(e.attrs?.height, 50, 2e3, 400));
238
+ return `<div class="me-media"${t.blockAttrs(e)}><div class="me-embed"><iframe class="me-embed-frame"${k("src", n)} height="${i}" sandbox="allow-scripts allow-same-origin allow-popups allow-presentation" allowfullscreen loading="lazy" referrerpolicy="strict-origin-when-cross-origin"></iframe></div></div>`;
239
239
  },
240
240
  callout: (e, t) => {
241
241
  let n = typeof e.attrs?.icon == "string" ? e.attrs.icon : "💡";
242
- return `<div class="me-callout" data-type="callout"${A("data-color", U(e.attrs?.color) ?? "gray")}${t.blockAttrs(e)}><div class="me-callout-icon-wrap"><span class="me-callout-icon">${k(n)}</span></div><div class="me-callout-content">${t.children(e)}</div></div>`;
242
+ return `<div class="me-callout" data-type="callout"${k("data-color", V(e.attrs?.color) ?? "gray")}${t.blockAttrs(e)}><div class="me-callout-icon-wrap"><span class="me-callout-icon">${O(n)}</span></div><div class="me-callout-content">${t.children(e)}</div></div>`;
243
243
  },
244
244
  details: (e, t) => {
245
- let n = e.attrs?.level ? V(e.attrs.level, 1, 3, 1) : null;
246
- return `<details class="me-toggle" data-type="details"${A("id", z(t).anchorOf.get(e))}${n ? ` data-level="${n}"` : ""}${e.attrs?.open ? " open" : ""}${t.blockAttrs(e)}>${t.children(e)}</details>`;
245
+ let n = e.attrs?.level ? z(e.attrs.level, 1, 3, 1) : null;
246
+ return `<details class="me-toggle" data-type="details"${k("id", L(t).anchorOf.get(e))}${n ? ` data-level="${n}"` : ""}${e.attrs?.open ? " open" : ""}${t.blockAttrs(e)}>${t.children(e)}</details>`;
247
247
  },
248
248
  detailsSummary: (e, t) => `<summary${t.blockAttrs(e)}><span class="me-toggle-arrow" aria-hidden="true"></span><span class="me-toggle-title">${t.children(e)}</span></summary>`,
249
249
  detailsContent: (e, t) => `<div data-type="detailsContent">${t.children(e)}</div>`,
250
250
  table: (e, t) => {
251
251
  let n = e.content?.[0]?.content ?? [], r = [];
252
252
  for (let e of n) {
253
- let t = V(e.attrs?.colspan, 1, 100, 1), n = Array.isArray(e.attrs?.colwidth) ? e.attrs.colwidth : [];
254
- for (let e = 0; e < t; e++) r.push(H(n[e]));
253
+ let t = z(e.attrs?.colspan, 1, 100, 1), n = Array.isArray(e.attrs?.colwidth) ? e.attrs.colwidth : [];
254
+ for (let e = 0; e < t; e++) r.push(B(n[e]));
255
255
  }
256
256
  let i = r.some((e) => e !== null) ? `<colgroup>${r.map((e) => e === null ? "<col>" : `<col style="width:${Math.max(1, Math.round(e))}px">`).join("")}</colgroup>` : "";
257
257
  return `<div class="tableWrapper"${t.blockAttrs(e)}><table>${i}<tbody>${t.children(e)}</tbody></table></div>`;
258
258
  },
259
259
  tableRow: (e, t) => `<tr>${t.children(e)}</tr>`,
260
- tableHeader: (e, t) => J("th", e, t),
261
- tableCell: (e, t) => J("td", e, t),
260
+ tableHeader: (e, t) => K("th", e, t),
261
+ tableCell: (e, t) => K("td", e, t),
262
262
  columns: (e, t) => `<div class="me-columns" data-type="columns" style="--cols:${e.content?.length ?? 2}"${t.blockAttrs(e)}>${t.children(e)}</div>`,
263
263
  column: (e, t) => `<div class="me-column" data-type="column">${t.children(e)}</div>`,
264
264
  tableOfContents: (e, t) => {
265
- let { headings: n } = z(t);
265
+ let { headings: n } = L(t);
266
266
  if (!n.length) return "";
267
- let r = Math.min(...n.map((e) => e.level), 4), i = n.map((e) => `<a class="me-toc-item" data-depth="${e.level - r}" href="#${encodeURIComponent(e.id)}">${k(e.text || t.messages.toc.untitled)}</a>`).join("");
268
- return `<nav class="me-toc"${A("aria-label", t.messages.toc.title)}${t.blockAttrs(e)}>${i}</nav>`;
267
+ let r = Math.min(...n.map((e) => e.level), 4), i = n.map((e) => `<a class="me-toc-item" data-depth="${e.level - r}" href="#${encodeURIComponent(e.id)}">${O(e.text || t.messages.toc.untitled)}</a>`).join("");
268
+ return `<nav class="me-toc"${k("aria-label", t.messages.toc.title)}${t.blockAttrs(e)}>${i}</nav>`;
269
269
  },
270
270
  mathBlock: (e, t) => {
271
271
  let n = typeof e.attrs?.latex == "string" ? e.attrs.latex : "";
272
- return n.trim() ? `<div class="me-math-block" data-type="math-block"${t.blockAttrs(e)}><span class="me-math-render">${K(n, !0, t)}</span></div>` : "";
272
+ return n.trim() ? `<div class="me-math-block" data-type="math-block"${t.blockAttrs(e)}><span class="me-math-render">${W(n, !0, t)}</span></div>` : "";
273
273
  },
274
274
  mathInline: (e, t) => {
275
275
  let n = typeof e.attrs?.latex == "string" ? e.attrs.latex : "";
276
- return n.trim() ? `<span class="me-math-inline" data-type="math-inline"><span class="me-math-render">${K(n, !1, t)}</span></span>` : "";
276
+ return n.trim() ? `<span class="me-math-inline" data-type="math-inline"><span class="me-math-render">${W(n, !1, t)}</span></span>` : "";
277
277
  },
278
278
  fileBlock: (e, t) => {
279
- let n = e.attrs ?? {}, r = q[n.kind] ? n.kind : "file";
279
+ let n = e.attrs ?? {}, r = G[n.kind] ? n.kind : "file";
280
280
  if (!n.src) return "";
281
- let i = r === "file" ? null : t.safeUrl(n.src, "media"), a = t.safeUrl(n.src, "download"), o = typeof n.name == "string" && n.name ? n.name : a ? String(n.src).slice(0, 200) : "", s = _e(n.size);
282
- return `<div class="me-media"${t.blockAttrs(e)}><div class="me-file me-file--${r}">` + (i ? `<${r} class="me-file-player"${A("src", i)} controls preload="metadata"></${r}>` : "") + `<div class="me-file-row">${t.icon(q[r]).replace("class=\"lucide\"", "class=\"lucide me-file-icon\"")}<span class="me-file-name">${k(o)}</span>` + (s ? `<span class="me-file-size">${s}</span>` : "") + (a ? `<a class="me-tool-btn"${A("href", a)}${A("download", n.name || !0)} target="_blank" rel="noopener noreferrer"${A("title", t.messages.image.download)}>${t.icon("download")}</a>` : "") + "</div></div></div>";
281
+ let i = r === "file" ? null : t.safeUrl(n.src, "media"), a = t.safeUrl(n.src, "download"), o = typeof n.name == "string" && n.name ? n.name : a ? String(n.src).slice(0, 200) : "", s = Te(n.size);
282
+ return `<div class="me-media"${t.blockAttrs(e)}><div class="me-file me-file--${r}">` + (i ? `<${r} class="me-file-player"${k("src", i)} controls preload="metadata"></${r}>` : "") + `<div class="me-file-row">${t.icon(G[r]).replace("class=\"lucide\"", "class=\"lucide me-file-icon\"")}<span class="me-file-name">${O(o)}</span>` + (s ? `<span class="me-file-size">${s}</span>` : "") + (a ? `<a class="me-tool-btn"${k("href", a)}${k("download", n.name || !0)} target="_blank" rel="noopener noreferrer"${k("title", t.messages.image.download)}>${t.icon("download")}</a>` : "") + "</div></div></div>";
283
283
  },
284
284
  mention: (t, n) => {
285
285
  let r = t.attrs ?? {}, i = r.kind === "page" || r.kind === "date" ? r.kind : "user";
@@ -298,7 +298,7 @@ var q = {
298
298
  } catch {
299
299
  i = String(r.label ?? r.id ?? "");
300
300
  }
301
- return `<span class="me-mention me-mention--date" data-type="mention" data-kind="date"><span>@${k(i)}</span></span>`;
301
+ return `<span class="me-mention me-mention--date" data-type="mention" data-kind="date"><span>@${O(i)}</span></span>`;
302
302
  }
303
303
  let a = String(r.label ?? r.id ?? ""), o = n.options.mentionHref ? n.options.mentionHref({
304
304
  id: String(r.id ?? ""),
@@ -307,45 +307,45 @@ var q = {
307
307
  href: r.href
308
308
  }) : r.href, s = n.safeUrl(o, "link"), c = `${i === "page" ? n.icon("fileText").replace("class=\"lucide\"", "class=\"lucide me-mention-icon\"") : (() => {
309
309
  let e = n.safeUrl(r.avatar, "media");
310
- return e ? `<img class="me-mention-avatar"${A("src", e)} alt="" loading="lazy">` : "";
311
- })()}<span>${i === "page" ? "" : "@"}${k(a)}</span>`, l = `me-mention me-mention--${i}`, u = `data-type="mention" data-kind="${i}"${A("data-id", r.id)}`;
312
- return s ? `<a class="${l}" ${u}${G(s, n)}>${c}</a>` : `<span class="${l}" ${u}>${c}</span>`;
310
+ return e ? `<img class="me-mention-avatar"${k("src", e)} alt="" loading="lazy">` : "";
311
+ })()}<span>${i === "page" ? "" : "@"}${O(a)}</span>`, l = `me-mention me-mention--${i}`, u = `data-type="mention" data-kind="${i}"${k("data-id", r.id)}`;
312
+ return s ? `<a class="${l}" ${u}${U(s, n)}>${c}</a>` : `<span class="${l}" ${u}>${c}</span>`;
313
313
  },
314
314
  htmlBlock: (e, n) => {
315
315
  let r = typeof e.attrs?.code == "string" ? e.attrs.code : "";
316
316
  if (!r.trim()) return "";
317
- let { network: a, defaultHeight: o } = z(n).htmlOptions, s = Math.round(V(e.attrs?.height ?? o, 120, t, o)), c = typeof e.attrs?.fileName == "string" && e.attrs.fileName ? e.attrs.fileName : n.messages.html.title;
318
- return `<div class="me-html"${n.blockAttrs(e)}><div class="me-html-frame"><div class="me-html-body" style="height:${s}px"><iframe class="me-html-iframe is-live"${A("srcdoc", i(r, a))} sandbox="allow-scripts allow-forms allow-modals allow-popups allow-pointer-lock allow-downloads"${A("title", c)} loading="lazy" referrerpolicy="no-referrer"></iframe></div></div></div>`;
317
+ let { network: a, defaultHeight: o } = L(n).htmlOptions, s = Math.round(z(e.attrs?.height ?? o, 120, t, o)), c = typeof e.attrs?.fileName == "string" && e.attrs.fileName ? e.attrs.fileName : n.messages.html.title;
318
+ return `<div class="me-html"${n.blockAttrs(e)}><div class="me-html-frame"><div class="me-html-body" style="height:${s}px"><iframe class="me-html-iframe is-live"${k("srcdoc", i(r, a))} sandbox="allow-scripts allow-forms allow-modals allow-popups allow-pointer-lock allow-downloads"${k("title", c)} loading="lazy" referrerpolicy="no-referrer"></iframe></div></div></div>`;
319
319
  },
320
320
  unknownBlock: (e, t) => e.attrs?.data && typeof e.attrs.data == "object" && e.attrs.data.type !== "unknownBlock" ? t.render(e.attrs.data) : "",
321
321
  unknownInline: (e, t) => e.attrs?.data && typeof e.attrs.data == "object" && e.attrs.data.type !== "unknownInline" ? t.render(e.attrs.data) : ""
322
322
  };
323
- function J(e, t, n) {
324
- let r = t.attrs ?? {}, i = V(r.colspan, 1, 100, 1), a = V(r.rowspan, 1, 1e3, 1);
325
- return `<${e}${i > 1 ? ` colspan="${i}"` : ""}${a > 1 ? ` rowspan="${a}"` : ""}${A("data-color", U(r.color))}>${n.children(t)}</${e}>`;
323
+ function K(e, t, n) {
324
+ let r = t.attrs ?? {}, i = z(r.colspan, 1, 100, 1), a = z(r.rowspan, 1, 1e3, 1);
325
+ return `<${e}${i > 1 ? ` colspan="${i}"` : ""}${a > 1 ? ` rowspan="${a}"` : ""}${k("data-color", V(r.color))}>${n.children(t)}</${e}>`;
326
326
  }
327
- var Y = (e) => (t, n) => `<${e}>${n}</${e}>`, ye = {
328
- bold: Y("strong"),
329
- italic: Y("em"),
330
- underline: Y("u"),
331
- strike: Y("s"),
332
- code: Y("code"),
333
- subscript: Y("sub"),
334
- superscript: Y("sup"),
335
- highlight: Y("mark"),
327
+ var q = (e) => (t, n) => `<${e}>${n}</${e}>`, De = {
328
+ bold: q("strong"),
329
+ italic: q("em"),
330
+ underline: q("u"),
331
+ strike: q("s"),
332
+ code: q("code"),
333
+ subscript: q("sub"),
334
+ superscript: q("sup"),
335
+ highlight: q("mark"),
336
336
  link: (e, t, n) => {
337
337
  let r = n.safeUrl(e.attrs?.href, "link");
338
- return r ? `<a${G(r, n)}>${t}</a>` : t;
338
+ return r ? `<a${U(r, n)}>${t}</a>` : t;
339
339
  },
340
340
  textColor: (e, t) => {
341
- let n = U(e.attrs?.color);
341
+ let n = V(e.attrs?.color);
342
342
  return n ? `<span data-text-color="${n}">${t}</span>` : t;
343
343
  },
344
344
  bgColor: (e, t) => {
345
- let n = U(e.attrs?.color);
345
+ let n = V(e.attrs?.color);
346
346
  return n ? `<mark data-bg-color="${n}">${t}</mark>` : t;
347
347
  }
348
- }, be = {
348
+ }, Oe = {
349
349
  file: "<path d=\"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z\"/><path d=\"M14 2v5a1 1 0 0 0 1 1h5\"/>",
350
350
  fileText: "<path d=\"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z\"/><path d=\"M14 2v5a1 1 0 0 0 1 1h5\"/><path d=\"M10 9H8\"/><path d=\"M16 13H8\"/><path d=\"M16 17H8\"/>",
351
351
  fileQuestion: "<path d=\"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z\"/><path d=\"M12 17h.01\"/><path d=\"M9.1 9a3 3 0 0 1 5.82 1c0 2-3 3-3 3\"/>",
@@ -353,12 +353,12 @@ var Y = (e) => (t, n) => `<${e}>${n}</${e}>`, ye = {
353
353
  video: "<rect width=\"18\" height=\"18\" x=\"3\" y=\"3\" rx=\"2\"/><path d=\"M7 3v18\"/><path d=\"M3 7.5h4\"/><path d=\"M3 12h18\"/><path d=\"M3 16.5h4\"/><path d=\"M17 3v18\"/><path d=\"M17 7.5h4\"/><path d=\"M17 16.5h4\"/>",
354
354
  download: "<path d=\"M12 15V3\"/><path d=\"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4\"/><path d=\"m7 10 5 5 5-5\"/>"
355
355
  };
356
- function xe(e, t = "") {
357
- let n = be[e];
356
+ function ke(e, t = "") {
357
+ let n = Oe[e];
358
358
  return n ? `<svg class="lucide${t ? ` ${t}` : ""}" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">${n}</svg>` : "";
359
359
  }
360
360
  // src/render/mermaid.ts
361
- async function Se(e, t = {}) {
361
+ async function Ae(e, t = {}) {
362
362
  if (typeof document > "u") return;
363
363
  let n = [...(e ?? document).querySelectorAll("pre.mermaid:not([data-processed])")];
364
364
  if (!n.length) return;
@@ -373,11 +373,11 @@ async function Se(e, t = {}) {
373
373
  });
374
374
  }
375
375
  // src/render/index.ts
376
- var X = /^[a-z]+$/;
377
- function Z(e, t = {}) {
378
- let n = t.locale ?? "vi", r = t.blocks ?? [], i = a(n, ...r.map((e) => e.messages?.[n]), t.messages), o = { ...ve }, s = { ...ye };
376
+ var J = /^[a-z]+$/;
377
+ function Y(e, t = {}) {
378
+ let n = t.locale ?? "vi", r = t.blocks ?? [], i = a(n, ...r.map((e) => e.messages?.[n]), t.messages), o = { ...Ee }, s = { ...De };
379
379
  for (let e of r) Object.assign(o, e.render?.nodes), Object.assign(s, e.render?.marks);
380
- let c = r.find((e) => e.name === "html")?.options ?? {}, { headings: l, anchorOf: u } = he(e), d = {
380
+ let c = r.find((e) => e.name === "html")?.options ?? {}, { headings: l, anchorOf: u } = Ce(e), d = {
381
381
  headings: l,
382
382
  anchorOf: u,
383
383
  katex: t.katex ?? null,
@@ -386,7 +386,7 @@ function Z(e, t = {}) {
386
386
  defaultHeight: c.defaultHeight ?? 400
387
387
  }
388
388
  }, f = (e) => {
389
- let t = k(e.text ?? ""), n = e.marks ?? [];
389
+ let t = O(e.text ?? ""), n = e.marks ?? [];
390
390
  for (let e = n.length - 1; e >= 0; e--) {
391
391
  let r = n[e], i = s[r.type];
392
392
  t = i ? i(r, t, _) : t;
@@ -396,7 +396,7 @@ function Z(e, t = {}) {
396
396
  if (!e || typeof e != "object") return "";
397
397
  if (e.type === "text") return f(e);
398
398
  let t = e.type ? o[e.type] : void 0;
399
- return t ? t(e, _) : e.content?.length ? `<div${A("data-type", e.type)}${h(e)}>${m(e)}</div>` : "";
399
+ return t ? t(e, _) : e.content?.length ? `<div${k("data-type", e.type)}${h(e)}>${m(e)}</div>` : "";
400
400
  }, m = (e) => {
401
401
  let t = e.content;
402
402
  if (!t?.length) return "";
@@ -406,8 +406,8 @@ function Z(e, t = {}) {
406
406
  }, h = (e) => {
407
407
  let t = e.attrs;
408
408
  if (!t) return "";
409
- let n = A("data-id", t.id);
410
- return typeof t.blockColor == "string" && X.test(t.blockColor) && (n += ` data-text-color="${t.blockColor}"`), typeof t.blockBg == "string" && X.test(t.blockBg) && (n += ` data-bg-color="${t.blockBg}"`), n;
409
+ let n = k("data-id", t.id);
410
+ return typeof t.blockColor == "string" && J.test(t.blockColor) && (n += ` data-text-color="${t.blockColor}"`), typeof t.blockBg == "string" && J.test(t.blockBg) && (n += ` data-bg-color="${t.blockBg}"`), n;
411
411
  }, g = (e) => e.type === "text" ? e.text ?? "" : e.type === "hardBreak" ? "\n" : (e.content ?? []).map(g).join(""), _ = {
412
412
  locale: n,
413
413
  messages: i,
@@ -415,31 +415,49 @@ function Z(e, t = {}) {
415
415
  children: m,
416
416
  render: p,
417
417
  blockAttrs: h,
418
- escape: k,
419
- attr: A,
420
- safeUrl: N,
418
+ escape: O,
419
+ attr: k,
420
+ safeUrl: M,
421
421
  text: g,
422
- icon: (e) => xe(e),
422
+ icon: (e) => ke(e),
423
423
  state: d
424
424
  }, v = e ? p(e.type ? e : {
425
425
  type: "doc",
426
426
  content: []
427
427
  }) : "";
428
- return t.wrap === !1 ? v : `<div class="me-scope me-root me-render${t.theme === "light" ? " me-light" : t.theme === "dark" ? " me-dark" : ""}${t.className ? ` ${k(t.className)}` : ""}"><div class="me-content">${v}</div></div>`;
428
+ return t.wrap === !1 ? v : `<div class="me-scope me-root me-render${t.theme === "light" ? " me-light" : t.theme === "dark" ? " me-dark" : ""}${t.className ? ` ${O(t.className)}` : ""}"><div class="me-content">${v}</div></div>`;
429
429
  }
430
- function Q(e) {
431
- return e ? e.type === "mathBlock" || e.type === "mathInline" ? !0 : e.content?.some(Q) ?? !1 : !1;
430
+ function X(e) {
431
+ return e ? e.type === "mathBlock" || e.type === "mathInline" ? !0 : e.content?.some(X) ?? !1 : !1;
432
432
  }
433
- var $ = null;
434
- async function Ce(e, t = {}) {
435
- return t.katex === void 0 && Q(e) ? ($ ??= import("katex").then((e) => e.default ?? e).catch(() => null), Z(e, {
433
+ var Z = null;
434
+ async function je(e, t = {}) {
435
+ return t.katex === void 0 && X(e) ? (Z ??= import("katex").then((e) => e.default ?? e).catch(() => null), Y(e, {
436
436
  ...t,
437
- katex: await $
438
- })) : Z(e, t);
437
+ katex: await Z
438
+ })) : Y(e, t);
439
+ }
440
+ var Q = (e) => {
441
+ let t = Object.keys(e);
442
+ return t.includes("light") && t.every((e) => e === "light" || e === "dark");
443
+ };
444
+ function $(e) {
445
+ let t = [];
446
+ for (let [n, r] of Object.entries(e ?? {})) n !== "dark" && (typeof r == "string" ? t.push([n.startsWith("--") ? n : s(n), r]) : r && typeof r == "object" && t.push(...c(r, n === "components" ? "" : n)));
447
+ return u(t);
448
+ }
449
+ function Me({ light: e, dark: t }) {
450
+ let n = ".me-scope", r = $(e), i = e?.dark, a = [...$(i && typeof i == "object" ? i : void 0), ...$(t)], o = d(c(p));
451
+ return [
452
+ `@media (prefers-color-scheme: dark){@layer ${f}{:where(${n}:not(.me-light)){${o}}}}`,
453
+ r.length ? `${n}{${d(r)}}` : "",
454
+ a.length ? [`html.dark ${n}:not(.me-light),${n}.me-dark{${d(a)}}`, `@media (prefers-color-scheme: dark){${n}:not(.me-light){${d(a)}}}`].join("\n") : ""
455
+ ].filter(Boolean).join("\n");
439
456
  }
440
- function we(e) {
441
- return `<style id="mei-editor-tokens">${[s(), o(e)].filter(Boolean).join("\n").replace(/<\/style/gi, "<\\/style")}</style>`;
457
+ function Ne(e) {
458
+ let t = e && Q(e) ? Me(e) : o(e);
459
+ return `<style id="mei-editor-tokens">${[l(), t].filter(Boolean).join("\n").replace(/<\/style/gi, "<\\/style")}</style>`;
442
460
  }
443
- export { A as attr, s as baseTokensCss, k as escapeHtml, Q as hasMath, R as highlightCode, Se as hydrateMermaid, o as overridesCss, Z as renderHTML, Ce as renderHTMLAsync, we as renderTokensStyle, N as safeUrl };
461
+ export { k as attr, l as baseTokensCss, O as escapeHtml, X as hasMath, I as highlightCode, Ae as hydrateMermaid, o as overridesCss, Y as renderHTML, je as renderHTMLAsync, Ne as renderTokensStyle, M as safeUrl };
444
462
 
445
463
  //# sourceMappingURL=render.js.map