magic-editor-x 2.0.0 → 2.2.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.
Files changed (93) hide show
  1. package/CHANGELOG.md +107 -0
  2. package/README.md +315 -103
  3. package/bin/magic-editor-x.mjs +190 -0
  4. package/dist/admin/{ConfigurationPage-DvAifELO.mjs → ConfigurationPage-3Dir3dAf.mjs} +126 -7
  5. package/dist/admin/{ConfigurationPage-B1uCIE3J.js → ConfigurationPage-YvnPnna6.js} +125 -4
  6. package/dist/admin/{CustomBlocksPage-6eWCOreU.js → CustomBlocksPage-BiiL2ORG.js} +4 -4
  7. package/dist/admin/{CustomBlocksPage-6-OQwpXQ.mjs → CustomBlocksPage-CR2BaP9O.mjs} +4 -4
  8. package/dist/admin/EditorField-B8pyAxPE.mjs +11935 -0
  9. package/dist/admin/EditorField-Diq1j8kc.js +11970 -0
  10. package/dist/admin/{api-B-RsxJCs.js → api-Dsq53giv.js} +3 -0
  11. package/dist/admin/{api-C4XsDZxd.mjs → api-RZ0Fz0BD.mjs} +3 -0
  12. package/dist/admin/de-62Vxb2iw.js +250 -0
  13. package/dist/admin/de-BVvwSYYO.mjs +250 -0
  14. package/dist/admin/de-BmmLBJli.mjs +41 -0
  15. package/dist/admin/{de-BMxADn2Z.mjs → de-Bt6pYIWi.mjs} +16 -1
  16. package/dist/admin/{de-DcDPRzV4.js → de-BteRx2iA.js} +28 -1
  17. package/dist/admin/{de-n5V6c5RT.mjs → de-CFX5atOk.mjs} +28 -1
  18. package/dist/admin/{de-Dx7vUW0Z.js → de-CVbi685U.js} +16 -1
  19. package/dist/admin/de-DaJwN6nk.js +41 -0
  20. package/dist/admin/{en-sNn4z9lA.js → en-BX362fTp.js} +16 -1
  21. package/dist/admin/{en-BQ5Pxe2o.mjs → en-B_HltUxZ.mjs} +16 -1
  22. package/dist/admin/en-Cg2Ak5Cr.mjs +250 -0
  23. package/dist/admin/en-Cn78RZs-.js +41 -0
  24. package/dist/admin/{en-D-DGftl0.js → en-CyjAcccB.js} +28 -1
  25. package/dist/admin/en-D7mZWLGp.mjs +41 -0
  26. package/dist/admin/en-VlkaIzrM.js +250 -0
  27. package/dist/admin/{en-BqNm3nMQ.mjs → en-ea0tfA5i.mjs} +28 -1
  28. package/dist/admin/es-BT9oAcHf.js +250 -0
  29. package/dist/admin/es-BmGtLkJD.js +41 -0
  30. package/dist/admin/{es-Di0pyQCh.js → es-C8GZFGjv.js} +28 -1
  31. package/dist/admin/es-C9-cXdb6.mjs +250 -0
  32. package/dist/admin/{es-SzeTV4q8.mjs → es-CEi_ycX8.mjs} +28 -1
  33. package/dist/admin/{es-DVsXnS0N.js → es-CHHEZi44.js} +16 -1
  34. package/dist/admin/{es-B6NYq0VH.mjs → es-CrhwOq-5.mjs} +16 -1
  35. package/dist/admin/es-joykG5I9.mjs +41 -0
  36. package/dist/admin/{fr-DmG3_Cn-.mjs → fr-5djKfQ3s.mjs} +16 -1
  37. package/dist/admin/{fr-Fwxcj4SM.js → fr-B3SL0TBV.js} +16 -1
  38. package/dist/admin/{fr-DhgPYHIH.mjs → fr-BAMSvQbR.mjs} +28 -1
  39. package/dist/admin/fr-CrzxGe5e.mjs +41 -0
  40. package/dist/admin/fr-Ct_uPqxV.js +41 -0
  41. package/dist/admin/fr-D6KJqPWi.js +250 -0
  42. package/dist/admin/fr-DpU_qiXR.mjs +250 -0
  43. package/dist/admin/{fr-D6F--jIB.js → fr-oRCJNdeJ.js} +28 -1
  44. package/dist/admin/index-C-lyON1B.mjs +303 -0
  45. package/dist/admin/index-iA0lued_.js +302 -0
  46. package/dist/admin/index.js +1 -1
  47. package/dist/admin/index.mjs +1 -1
  48. package/dist/admin/pt-BOrl6x-r.js +250 -0
  49. package/dist/admin/{pt-BbdwHlWF.mjs → pt-BdnY2Cth.mjs} +16 -1
  50. package/dist/admin/{pt-BvSl1btT.mjs → pt-CQrfqsCN.mjs} +28 -1
  51. package/dist/admin/{pt-C6nr71Yw.js → pt-EVwCuBUK.js} +16 -1
  52. package/dist/admin/pt-Ga-4Hsv0.mjs +41 -0
  53. package/dist/admin/pt-chN2jrXl.js +41 -0
  54. package/dist/admin/pt-jUqOR7Xh.mjs +250 -0
  55. package/dist/admin/{pt-BPo0ex21.js → pt-tUeJ2Ywd.js} +28 -1
  56. package/dist/admin/{sanitize-9UVcXFfc.js → sanitize-Cb4jvBhj.js} +88 -12
  57. package/dist/admin/{sanitize-D4kfZ_ly.mjs → sanitize-ClkX823p.mjs} +89 -13
  58. package/dist/admin/{useT-B5M49wGH.js → useT-BWZ_-Hel.js} +1 -1
  59. package/dist/admin/{useT-CjX6fL2m.mjs → useT-pvHmgBFj.mjs} +1 -1
  60. package/dist/render/index.d.mts +75 -0
  61. package/dist/render/index.d.ts +75 -0
  62. package/dist/render/index.js +1420 -0
  63. package/dist/render/index.mjs +1398 -0
  64. package/dist/server/index.js +9562 -589
  65. package/dist/server/index.mjs +9565 -592
  66. package/package.json +21 -4
  67. package/schema/magic-editor-x.schema.json +967 -0
  68. package/types/index.d.ts +211 -0
  69. package/types/render.d.ts +75 -0
  70. package/dist/admin/EditorField-DocyD2Q3.js +0 -5506
  71. package/dist/admin/EditorField-ThSoOCPm.mjs +0 -5471
  72. package/dist/admin/de-B8XFFhHh.js +0 -95
  73. package/dist/admin/de-DBR893G4.js +0 -13
  74. package/dist/admin/de-RAxzvrwm.mjs +0 -95
  75. package/dist/admin/de-fBFh09Wl.mjs +0 -13
  76. package/dist/admin/en-BzfyifEU.mjs +0 -95
  77. package/dist/admin/en-D9Nfccux.mjs +0 -13
  78. package/dist/admin/en-DcWUTE2J.js +0 -95
  79. package/dist/admin/en-gueRT44P.js +0 -13
  80. package/dist/admin/es-B0Zy8DVg.mjs +0 -13
  81. package/dist/admin/es-BOtVc9qv.js +0 -95
  82. package/dist/admin/es-C2OJVYkV.mjs +0 -95
  83. package/dist/admin/es-DRGs7meF.js +0 -13
  84. package/dist/admin/fr-B8rdLAIL.js +0 -13
  85. package/dist/admin/fr-Bpo5Uq1f.mjs +0 -95
  86. package/dist/admin/fr-DfxKaOc_.js +0 -95
  87. package/dist/admin/fr-oiUb2bb_.mjs +0 -13
  88. package/dist/admin/index-CwfaB5-e.js +0 -155
  89. package/dist/admin/index-D1Q5Rlt6.mjs +0 -156
  90. package/dist/admin/pt-B3Jce6uT.mjs +0 -13
  91. package/dist/admin/pt-BiWuSBcH.js +0 -13
  92. package/dist/admin/pt-DqCXuI4S.mjs +0 -95
  93. package/dist/admin/pt-LCvjwk0y.js +0 -95
@@ -0,0 +1,1398 @@
1
+ // shared/editor-data.mjs
2
+ var EDITOR_DATA_LIMITS = Object.freeze({
3
+ maxBlocks: 5e3,
4
+ maxBytes: 5 * 1024 * 1024,
5
+ maxDepth: 24,
6
+ maxBlockIdLength: 64,
7
+ maxTypeLength: 64
8
+ });
9
+ var FORBIDDEN_KEYS = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
10
+ var BLOCK_ID_PATTERN = /^[A-Za-z0-9_-]{1,64}$/;
11
+ var BLOCK_TYPE_PATTERN = /^[A-Za-z][A-Za-z0-9_-]{0,63}$/;
12
+ var isPlainObject = (value) => value !== null && typeof value === "object" && !Array.isArray(value) && (Object.getPrototypeOf(value) === Object.prototype || Object.getPrototypeOf(value) === null);
13
+ var EditorDataError = class extends Error {
14
+ /**
15
+ * @param {string} message - Fixed, non-sensitive message.
16
+ * @param {string} code - Machine-readable reason.
17
+ */
18
+ constructor(message, code) {
19
+ super(message);
20
+ this.name = "EditorDataError";
21
+ this.code = code;
22
+ }
23
+ };
24
+ var cloneJsonSafe = (value, depth = 0) => {
25
+ if (depth > EDITOR_DATA_LIMITS.maxDepth) {
26
+ throw new EditorDataError("Editor content is nested too deeply", "TOO_DEEP");
27
+ }
28
+ if (value === null) return null;
29
+ if (Array.isArray(value)) {
30
+ const out = [];
31
+ for (const item of value) {
32
+ const cloned = cloneJsonSafe(item, depth + 1);
33
+ out.push(cloned === void 0 ? null : cloned);
34
+ }
35
+ return out;
36
+ }
37
+ switch (typeof value) {
38
+ case "string":
39
+ case "boolean":
40
+ return value;
41
+ case "number":
42
+ return Number.isFinite(value) ? value : null;
43
+ case "object": {
44
+ const out = {};
45
+ for (const key of Object.keys(value)) {
46
+ if (FORBIDDEN_KEYS.has(key)) continue;
47
+ const cloned = cloneJsonSafe(value[key], depth + 1);
48
+ if (cloned !== void 0) out[key] = cloned;
49
+ }
50
+ return out;
51
+ }
52
+ default:
53
+ return void 0;
54
+ }
55
+ };
56
+ var tryParseJson = (text) => {
57
+ try {
58
+ return { ok: true, value: JSON.parse(text) };
59
+ } catch {
60
+ return { ok: false };
61
+ }
62
+ };
63
+ var escapeHtml = (text) => String(text).replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
64
+ var hashString = (text) => {
65
+ let hash = 2166136261;
66
+ for (let i = 0; i < text.length; i += 1) {
67
+ hash ^= text.charCodeAt(i);
68
+ hash = Math.imul(hash, 16777619) >>> 0;
69
+ }
70
+ return hash.toString(16).padStart(8, "0");
71
+ };
72
+ var legacyBlockId = (index, type, data) => `mx${hashString(`${index}:${type}:${JSON.stringify(data)}`)}${index}`;
73
+ var textToBlocks = (text) => {
74
+ const trimmed = text.trim();
75
+ if (!trimmed) return [];
76
+ const looksLikeHtml = /<\/?[a-z][^>]{0,200}>/i.test(trimmed.slice(0, 2e3));
77
+ if (looksLikeHtml) {
78
+ return [{ type: "paragraph", data: { text: trimmed } }];
79
+ }
80
+ return trimmed.split(/\r?\n\s*\r?\n/).map((part) => part.trim()).filter(Boolean).map((part) => ({ type: "paragraph", data: { text: escapeHtml(part).replace(/\r?\n/g, "<br>") } }));
81
+ };
82
+ var unwrapValue = (value) => {
83
+ let current = value;
84
+ let legacy = false;
85
+ for (let i = 0; i < 3 && typeof current === "string"; i += 1) {
86
+ const text = current.trim();
87
+ if (!text) return { candidate: null, legacy: true };
88
+ if (text.startsWith("{") || text.startsWith("[") || text.startsWith('"')) {
89
+ const parsed = tryParseJson(text);
90
+ if (parsed.ok) {
91
+ current = parsed.value;
92
+ legacy = true;
93
+ continue;
94
+ }
95
+ }
96
+ return { candidate: { blocks: textToBlocks(text) }, legacy: true };
97
+ }
98
+ if (Array.isArray(current)) {
99
+ return { candidate: { blocks: current }, legacy: true };
100
+ }
101
+ return { candidate: current, legacy };
102
+ };
103
+ var normalizeEditorData = (value) => {
104
+ if (value === null || value === void 0) return null;
105
+ if (typeof value === "string" && value.length > EDITOR_DATA_LIMITS.maxBytes) {
106
+ throw new EditorDataError("Editor content exceeds the size limit", "TOO_LARGE");
107
+ }
108
+ const { candidate } = unwrapValue(value);
109
+ if (candidate === null || candidate === void 0) return null;
110
+ if (!isPlainObject(candidate)) {
111
+ throw new EditorDataError("Editor content must be an Editor.js object", "INVALID_SHAPE");
112
+ }
113
+ const clean = cloneJsonSafe(candidate);
114
+ const rawBlocks = Array.isArray(clean.blocks) ? clean.blocks : [];
115
+ if (rawBlocks.length > EDITOR_DATA_LIMITS.maxBlocks) {
116
+ throw new EditorDataError("Editor content has too many blocks", "TOO_MANY_BLOCKS");
117
+ }
118
+ const seen = /* @__PURE__ */ new Set();
119
+ const blocks = [];
120
+ rawBlocks.forEach((block, index) => {
121
+ if (!isPlainObject(block)) return;
122
+ const type = typeof block.type === "string" ? block.type.trim() : "";
123
+ if (!BLOCK_TYPE_PATTERN.test(type)) return;
124
+ const data = isPlainObject(block.data) ? block.data : {};
125
+ let id = typeof block.id === "string" && BLOCK_ID_PATTERN.test(block.id) ? block.id : "";
126
+ if (!id || seen.has(id)) id = legacyBlockId(index, type, data);
127
+ while (seen.has(id)) id = `${id}x`;
128
+ seen.add(id);
129
+ const normalized = { id, type, data };
130
+ if (isPlainObject(block.tunes) && Object.keys(block.tunes).length > 0) normalized.tunes = block.tunes;
131
+ blocks.push(normalized);
132
+ });
133
+ const time = Number.isFinite(clean.time) && clean.time > 0 ? Math.floor(clean.time) : 0;
134
+ const version = typeof clean.version === "string" && clean.version.length <= 32 ? clean.version : "2.31.7";
135
+ const result = { time, blocks, version };
136
+ const size = byteLength(JSON.stringify(result));
137
+ if (size > EDITOR_DATA_LIMITS.maxBytes) {
138
+ throw new EditorDataError("Editor content exceeds the size limit", "TOO_LARGE");
139
+ }
140
+ return result;
141
+ };
142
+ var normalizeEditorDataSafe = (value) => {
143
+ try {
144
+ return normalizeEditorData(value);
145
+ } catch {
146
+ return null;
147
+ }
148
+ };
149
+ var byteLength = (text) => {
150
+ let bytes = 0;
151
+ for (let i = 0; i < text.length; i += 1) {
152
+ const code = text.charCodeAt(i);
153
+ if (code < 128) bytes += 1;
154
+ else if (code < 2048) bytes += 2;
155
+ else if (code >= 55296 && code <= 56319) {
156
+ bytes += 4;
157
+ i += 1;
158
+ } else bytes += 3;
159
+ }
160
+ return bytes;
161
+ };
162
+
163
+ // shared/sanitize-policy.mjs
164
+ var INLINE_TAGS = Object.freeze([
165
+ "b",
166
+ "strong",
167
+ "i",
168
+ "em",
169
+ "u",
170
+ "s",
171
+ "mark",
172
+ "code",
173
+ "a",
174
+ "br",
175
+ "span",
176
+ "sub",
177
+ "sup"
178
+ ]);
179
+ var INTERNAL_LINK_ATTRIBUTES = Object.freeze([
180
+ "data-mex-uid",
181
+ "data-mex-document-id",
182
+ "data-mex-locale"
183
+ ]);
184
+ var INTERNAL_LINK_RULES = Object.freeze({
185
+ "data-mex-uid": /^api::[a-z0-9-]{1,60}\.[a-z0-9-]{1,60}$/,
186
+ "data-mex-document-id": /^[a-z0-9]{1,64}$/,
187
+ "data-mex-locale": /^[A-Za-z]{2,8}(?:-[A-Za-z0-9]{1,8}){0,3}$/
188
+ });
189
+ var cleanInternalLinkAttributes = (attribs) => {
190
+ const out = {};
191
+ if (!attribs || typeof attribs !== "object") return out;
192
+ for (const name of INTERNAL_LINK_ATTRIBUTES) {
193
+ const value = attribs[name];
194
+ if (typeof value === "string" && INTERNAL_LINK_RULES[name].test(value)) out[name] = value;
195
+ }
196
+ if (!out["data-mex-uid"] || !out["data-mex-document-id"]) return {};
197
+ return out;
198
+ };
199
+ var INLINE_ATTRIBUTES = Object.freeze({
200
+ a: ["href", "target", "rel", "title", ...INTERNAL_LINK_ATTRIBUTES],
201
+ span: ["class", "data-tooltip"],
202
+ mark: ["class"],
203
+ u: ["class"],
204
+ s: ["class"],
205
+ code: ["class"]
206
+ });
207
+ var INLINE_CLASSES = Object.freeze({
208
+ span: ["cdx-tooltip"],
209
+ mark: ["cdx-marker"],
210
+ u: ["cdx-underline"],
211
+ s: ["cdx-strikethrough", "cdx-strikethroughs"],
212
+ code: ["inline-code"]
213
+ });
214
+ var LINK_SCHEMES = Object.freeze(["http", "https", "mailto", "tel"]);
215
+ var MAX_URL_LENGTH = 2048;
216
+ var TARGETS = /* @__PURE__ */ new Set(["_blank", "_self", "_parent", "_top"]);
217
+ var sanitizeUrl = (value, options = {}) => {
218
+ const schemes = options.schemes || LINK_SCHEMES;
219
+ const allowRelative = options.allowRelative !== false;
220
+ if (typeof value !== "string") return "";
221
+ const url = value.trim();
222
+ if (!url || url.length > MAX_URL_LENGTH) return "";
223
+ if (/[\u0000-\u001f\u007f\s]/.test(url) && !/^(mailto|tel):/i.test(url)) return "";
224
+ if (url.startsWith("//") || url.startsWith("\\")) return "";
225
+ const scheme = /^([a-zA-Z][a-zA-Z0-9+.-]{0,20}):/.exec(url);
226
+ if (!scheme) {
227
+ return allowRelative && /^[/#?.]/.test(url) ? url : "";
228
+ }
229
+ if (!schemes.includes(scheme[1].toLowerCase())) return "";
230
+ if (scheme[1].toLowerCase().startsWith("http")) {
231
+ try {
232
+ const parsed = new URL(url);
233
+ if (parsed.username || parsed.password) return "";
234
+ } catch {
235
+ return "";
236
+ }
237
+ }
238
+ return url;
239
+ };
240
+ var plain = (value, max = 1e5) => typeof value === "string" ? value.slice(0, max) : "";
241
+ var oneOf = (value, allowed, fallback) => typeof value === "string" && allowed.includes(value) ? value : fallback;
242
+ var int = (value, min, max, fallback) => {
243
+ const number = typeof value === "string" ? Number(value) : value;
244
+ return Number.isInteger(number) && number >= min && number <= max ? number : fallback;
245
+ };
246
+ var bool = (value) => value === true;
247
+ var generic = (value, inline, depth = 0, key = "") => {
248
+ if (depth > 20) return null;
249
+ if (typeof value === "string") {
250
+ if (/^(url|href|link|src|photo|source|embed)$/i.test(key)) return sanitizeUrl(value);
251
+ return inline(value);
252
+ }
253
+ if (Array.isArray(value)) return value.map((item) => generic(item, inline, depth + 1, key));
254
+ if (isPlainObject(value)) {
255
+ const out = {};
256
+ for (const [childKey, child] of Object.entries(value))
257
+ out[childKey] = generic(child, inline, depth + 1, childKey);
258
+ return out;
259
+ }
260
+ return value;
261
+ };
262
+ var listItems = (items, inline, depth = 0) => {
263
+ if (!Array.isArray(items) || depth > 12) return [];
264
+ return items.map((item) => {
265
+ if (typeof item === "string") return inline(item);
266
+ if (!isPlainObject(item)) return { content: "", items: [] };
267
+ const out = { content: inline(typeof item.content === "string" ? item.content : plain(item.text)) };
268
+ if (isPlainObject(item.meta)) {
269
+ const meta = {};
270
+ if (typeof item.meta.checked === "boolean") meta.checked = item.meta.checked;
271
+ const start = int(item.meta.start, 0, 1e5, void 0);
272
+ if (start !== void 0) meta.start = start;
273
+ if (typeof item.meta.counterType === "string") {
274
+ meta.counterType = oneOf(
275
+ item.meta.counterType,
276
+ ["numeric", "lower-roman", "upper-roman", "lower-alpha", "upper-alpha"],
277
+ "numeric"
278
+ );
279
+ }
280
+ out.meta = meta;
281
+ }
282
+ out.items = listItems(item.items, inline, depth + 1);
283
+ return out;
284
+ });
285
+ };
286
+ var BLOCK_POLICIES = {
287
+ paragraph: (d, inline) => ({ text: inline(d.text) }),
288
+ header: (d, inline) => ({ text: inline(d.text), level: int(d.level, 1, 6, 2) }),
289
+ quote: (d, inline) => ({
290
+ text: inline(d.text),
291
+ caption: inline(d.caption),
292
+ alignment: oneOf(d.alignment, ["left", "center"], "left")
293
+ }),
294
+ list: (d, inline) => {
295
+ const out = {
296
+ style: oneOf(d.style, ["ordered", "unordered", "checklist"], "unordered"),
297
+ items: listItems(d.items, inline)
298
+ };
299
+ if (isPlainObject(d.meta)) {
300
+ const meta = {};
301
+ const start = int(d.meta.start, 0, 1e5, void 0);
302
+ if (start !== void 0) meta.start = start;
303
+ if (typeof d.meta.counterType === "string") {
304
+ meta.counterType = oneOf(
305
+ d.meta.counterType,
306
+ ["numeric", "lower-roman", "upper-roman", "lower-alpha", "upper-alpha"],
307
+ "numeric"
308
+ );
309
+ }
310
+ out.meta = meta;
311
+ }
312
+ return out;
313
+ },
314
+ checklist: (d, inline) => ({
315
+ items: Array.isArray(d.items) ? d.items.filter(isPlainObject).map((item) => ({ text: inline(item.text), checked: bool(item.checked) })) : []
316
+ }),
317
+ warning: (d, inline) => ({ title: inline(d.title), message: inline(d.message) }),
318
+ alert: (d, inline) => ({
319
+ type: oneOf(
320
+ d.type,
321
+ ["primary", "secondary", "info", "success", "warning", "danger", "light", "dark"],
322
+ "info"
323
+ ),
324
+ align: oneOf(d.align, ["left", "center", "right"], "left"),
325
+ message: inline(d.message)
326
+ }),
327
+ toggle: (d, inline) => ({
328
+ text: inline(d.text),
329
+ status: oneOf(d.status, ["open", "closed"], "open"),
330
+ fk: typeof d.fk === "string" ? d.fk.slice(0, 64) : void 0,
331
+ items: int(d.items, 0, 5e3, 0)
332
+ }),
333
+ code: (d) => ({ code: plain(d.code, 5e5) }),
334
+ codeFlask: (d) => {
335
+ const out = {
336
+ code: plain(d.code, 5e5),
337
+ language: typeof d.language === "string" && /^[a-z0-9+#-]{1,32}$/i.test(d.language) ? d.language : "plaintext"
338
+ };
339
+ if (typeof d.showlinenumbers === "boolean") out.showlinenumbers = d.showlinenumbers;
340
+ return out;
341
+ },
342
+ raw: (d, _inline, ctx) => {
343
+ const html = plain(d.html, 5e5);
344
+ if (ctx.rawHtml === "allow") return { html };
345
+ if (ctx.rawHtml === "disable") return { html: "" };
346
+ return { html: ctx.rawSanitizer(html) };
347
+ },
348
+ table: (d, inline) => ({
349
+ withHeadings: bool(d.withHeadings),
350
+ stretched: bool(d.stretched),
351
+ content: Array.isArray(d.content) ? d.content.slice(0, 500).map((row) => Array.isArray(row) ? row.slice(0, 100).map((cell2) => inline(cell2)) : []) : []
352
+ }),
353
+ image: (d, inline) => {
354
+ const file = isPlainObject(d.file) ? d.file : {};
355
+ const cleanFile = { url: sanitizeUrl(file.url, { schemes: ["http", "https"] }) };
356
+ for (const key of ["mime", "alt", "name", "hash", "ext"])
357
+ if (typeof file[key] === "string") cleanFile[key] = plain(file[key], 500);
358
+ for (const key of ["width", "height", "size"]) if (Number.isFinite(file[key])) cleanFile[key] = file[key];
359
+ if (isPlainObject(file.formats))
360
+ cleanFile.formats = generic(file.formats, (s) => plain(s, 2048), 0, "formats");
361
+ if (file.id !== void 0 && (Number.isInteger(file.id) || typeof file.id === "string"))
362
+ cleanFile.id = file.id;
363
+ if (typeof file.documentId === "string") cleanFile.documentId = plain(file.documentId, 64);
364
+ const out = {
365
+ file: cleanFile,
366
+ caption: inline(d.caption),
367
+ withBorder: bool(d.withBorder),
368
+ withBackground: bool(d.withBackground),
369
+ stretched: bool(d.stretched)
370
+ };
371
+ if (d.decorative === true) out.decorative = true;
372
+ return out;
373
+ },
374
+ simpleImage: (d, inline) => {
375
+ const out = {
376
+ url: sanitizeUrl(d.url, { schemes: ["http", "https"] }),
377
+ caption: inline(d.caption),
378
+ withBorder: bool(d.withBorder),
379
+ withBackground: bool(d.withBackground),
380
+ stretched: bool(d.stretched)
381
+ };
382
+ if (typeof d.alt === "string") out.alt = plain(d.alt, 500);
383
+ if (d.decorative === true) out.decorative = true;
384
+ return out;
385
+ },
386
+ linkTool: (d) => {
387
+ const meta = isPlainObject(d.meta) ? d.meta : {};
388
+ const image = isPlainObject(meta.image) ? { url: sanitizeUrl(meta.image.url, { schemes: ["http", "https"] }) } : void 0;
389
+ const cleanMeta = { title: plain(meta.title, 500), description: plain(meta.description, 2e3) };
390
+ if (typeof meta.site_name === "string") cleanMeta.site_name = plain(meta.site_name, 200);
391
+ if (image && image.url) cleanMeta.image = image;
392
+ return { link: sanitizeUrl(d.link, { schemes: ["http", "https"] }), meta: cleanMeta };
393
+ },
394
+ attaches: (d) => {
395
+ const file = isPlainObject(d.file) ? d.file : {};
396
+ const cleanFile = { url: sanitizeUrl(file.url, { schemes: ["http", "https"] }) };
397
+ if (typeof file.name === "string") cleanFile.name = plain(file.name, 255);
398
+ if (typeof file.extension === "string") cleanFile.extension = plain(file.extension, 16);
399
+ if (Number.isFinite(file.size)) cleanFile.size = file.size;
400
+ if (typeof file.title === "string") cleanFile.title = plain(file.title, 255);
401
+ return { file: cleanFile, title: plain(d.title, 255) };
402
+ },
403
+ embed: (d, inline) => ({
404
+ service: typeof d.service === "string" && /^[a-z0-9_-]{1,40}$/i.test(d.service) ? d.service : "",
405
+ source: sanitizeUrl(d.source, { schemes: ["https", "http"], allowRelative: false }),
406
+ embed: sanitizeUrl(d.embed, { schemes: ["https"], allowRelative: false }),
407
+ width: int(d.width, 1, 1e4, void 0),
408
+ height: int(d.height, 1, 1e4, void 0),
409
+ caption: inline(d.caption)
410
+ }),
411
+ personality: (d) => ({
412
+ name: plain(d.name, 500),
413
+ description: plain(d.description, 2e3),
414
+ link: sanitizeUrl(d.link, { schemes: ["http", "https", "mailto"] }),
415
+ photo: sanitizeUrl(d.photo, { schemes: ["http", "https"] })
416
+ }),
417
+ button: (d) => ({
418
+ text: plain(d.text, 200),
419
+ link: sanitizeUrl(d.link),
420
+ style: oneOf(d.style, ["primary", "secondary", "outline", "ghost", "danger", "success"], "primary"),
421
+ openInNewTab: bool(d.openInNewTab)
422
+ }),
423
+ delimiter: () => ({})
424
+ };
425
+ var sanitizeTunes = (tunes) => {
426
+ if (!isPlainObject(tunes)) return void 0;
427
+ const out = {};
428
+ if (isPlainObject(tunes.alignmentTune)) {
429
+ out.alignmentTune = {
430
+ alignment: oneOf(tunes.alignmentTune.alignment, ["left", "center", "right", "justify"], "left")
431
+ };
432
+ }
433
+ if (typeof tunes.textVariant === "string") {
434
+ out.textVariant = oneOf(tunes.textVariant, ["", "call-out", "citation", "details"], "");
435
+ }
436
+ if (isPlainObject(tunes.indentTune)) {
437
+ out.indentTune = { indentLevel: int(tunes.indentTune.indentLevel, 0, 10, 0) };
438
+ }
439
+ return Object.keys(out).length ? out : void 0;
440
+ };
441
+ var sanitizeTarget = (value) => typeof value === "string" && TARGETS.has(value) ? value : null;
442
+
443
+ // shared/render/inline.mjs
444
+ var DROP_WITH_CONTENT = /* @__PURE__ */ new Set([
445
+ "script",
446
+ "style",
447
+ "textarea",
448
+ "title",
449
+ "xmp",
450
+ "noscript",
451
+ "noembed",
452
+ "noframes",
453
+ "template",
454
+ "iframe",
455
+ "object",
456
+ "embed",
457
+ "svg",
458
+ "math",
459
+ "select",
460
+ "option",
461
+ "plaintext"
462
+ ]);
463
+ var ALLOWED = new Set(INLINE_TAGS);
464
+ var VOID = /* @__PURE__ */ new Set(["br"]);
465
+ var MAX_INPUT = 5e5;
466
+ var MAX_NODES = 5e4;
467
+ var MAX_DEPTH = 64;
468
+ var NAMED_ENTITIES = Object.freeze({
469
+ amp: "&",
470
+ lt: "<",
471
+ gt: ">",
472
+ quot: '"',
473
+ apos: "'",
474
+ nbsp: "\xA0",
475
+ shy: "\xAD",
476
+ copy: "\xA9",
477
+ reg: "\xAE",
478
+ trade: "\u2122",
479
+ hellip: "\u2026",
480
+ mdash: "\u2014",
481
+ ndash: "\u2013",
482
+ lsquo: "\u2018",
483
+ rsquo: "\u2019",
484
+ ldquo: "\u201C",
485
+ rdquo: "\u201D",
486
+ laquo: "\xAB",
487
+ raquo: "\xBB",
488
+ euro: "\u20AC",
489
+ middot: "\xB7",
490
+ bull: "\u2022",
491
+ times: "\xD7",
492
+ deg: "\xB0",
493
+ tab: " ",
494
+ newline: "\n",
495
+ colon: ":",
496
+ sol: "/",
497
+ lpar: "(",
498
+ rpar: ")"
499
+ });
500
+ var decodeEntities = (text) => String(text).replace(
501
+ /&(#[xX][0-9a-fA-F]{1,8}|#[0-9]{1,10}|[A-Za-z][A-Za-z0-9]{1,31});?/g,
502
+ (match, body) => {
503
+ if (body[0] === "#") {
504
+ const code = body[1] === "x" || body[1] === "X" ? parseInt(body.slice(2), 16) : parseInt(body.slice(1), 10);
505
+ if (!Number.isFinite(code) || code <= 0 || code > 1114111 || code >= 55296 && code <= 57343)
506
+ return "\uFFFD";
507
+ return String.fromCodePoint(code);
508
+ }
509
+ const named = NAMED_ENTITIES[body] ?? NAMED_ENTITIES[body.toLowerCase()];
510
+ return named === void 0 ? match : named;
511
+ }
512
+ );
513
+ var escapeHtml2 = (text) => String(text ?? "").replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
514
+ var parseAttributes = (source) => {
515
+ const out = {};
516
+ const pattern = /([^\s"'<>/=]+)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'=<>`]+)))?/g;
517
+ let match;
518
+ while (match = pattern.exec(source)) {
519
+ const name = match[1].toLowerCase();
520
+ if (Object.prototype.hasOwnProperty.call(out, name)) continue;
521
+ const raw = match[2] ?? match[3] ?? match[4] ?? "";
522
+ out[name] = decodeEntities(raw);
523
+ }
524
+ return out;
525
+ };
526
+ var findTagEnd = (html, from) => {
527
+ let quote = "";
528
+ for (let i = from; i < html.length; i += 1) {
529
+ const char = html[i];
530
+ if (quote) {
531
+ if (char === quote) quote = "";
532
+ } else if (char === '"' || char === "'") quote = char;
533
+ else if (char === ">") return i;
534
+ }
535
+ return -1;
536
+ };
537
+ var cleanAttributes = (tag, attribs) => {
538
+ const allowed = INLINE_ATTRIBUTES[tag] || [];
539
+ const out = {};
540
+ for (const name of allowed) {
541
+ if (!Object.prototype.hasOwnProperty.call(attribs, name) || name.startsWith("data-mex-")) continue;
542
+ const value = attribs[name];
543
+ if (name === "href") {
544
+ const url = sanitizeUrl(value);
545
+ if (url) out.href = url;
546
+ } else if (name === "target") {
547
+ const target = sanitizeTarget(value);
548
+ if (target) out.target = target;
549
+ } else if (name === "rel") {
550
+ const rel = String(value).split(/\s+/).filter((token) => /^[a-z-]{1,20}$/.test(token));
551
+ if (rel.length) out.rel = rel.join(" ");
552
+ } else if (name === "class") {
553
+ const classes2 = String(value).split(/\s+/).filter((token) => (INLINE_CLASSES[tag] || []).includes(token));
554
+ if (classes2.length) out.class = classes2.join(" ");
555
+ } else {
556
+ out[name] = String(value).slice(0, 2e3);
557
+ }
558
+ }
559
+ if (tag === "a") Object.assign(out, cleanInternalLinkAttributes(attribs));
560
+ return out;
561
+ };
562
+ var parseInline = (input) => {
563
+ const html = typeof input === "string" ? input.slice(0, MAX_INPUT) : "";
564
+ const root = { type: "element", tag: "#root", attrs: {}, children: [] };
565
+ const stack = [root];
566
+ let nodes = 0;
567
+ let text = "";
568
+ const flush = () => {
569
+ if (!text) return;
570
+ const parent = stack[stack.length - 1];
571
+ const last = parent.children[parent.children.length - 1];
572
+ const value = decodeEntities(text);
573
+ if (last && last.type === "text") last.value += value;
574
+ else if (nodes < MAX_NODES) {
575
+ parent.children.push({ type: "text", value });
576
+ nodes += 1;
577
+ }
578
+ text = "";
579
+ };
580
+ let i = 0;
581
+ while (i < html.length) {
582
+ const lt = html.indexOf("<", i);
583
+ if (lt === -1) {
584
+ text += html.slice(i);
585
+ break;
586
+ }
587
+ text += html.slice(i, lt);
588
+ i = lt;
589
+ if (html.startsWith("<!--", i)) {
590
+ const end2 = html.indexOf("-->", i + 4);
591
+ flush();
592
+ i = end2 === -1 ? html.length : end2 + 3;
593
+ continue;
594
+ }
595
+ if (html.startsWith("<![CDATA[", i)) {
596
+ const end2 = html.indexOf("]]>", i + 9);
597
+ flush();
598
+ i = end2 === -1 ? html.length : end2 + 3;
599
+ continue;
600
+ }
601
+ if (html[i + 1] === "!" || html[i + 1] === "?") {
602
+ const end2 = html.indexOf(">", i + 2);
603
+ flush();
604
+ i = end2 === -1 ? html.length : end2 + 1;
605
+ continue;
606
+ }
607
+ const closing = html[i + 1] === "/";
608
+ const nameMatch = /^[A-Za-z][A-Za-z0-9-]{0,40}/.exec(html.slice(i + (closing ? 2 : 1), i + 45));
609
+ if (!nameMatch) {
610
+ text += "<";
611
+ i += 1;
612
+ continue;
613
+ }
614
+ const end = findTagEnd(html, i + 1);
615
+ if (end === -1) {
616
+ text += html.slice(i);
617
+ break;
618
+ }
619
+ flush();
620
+ const tag = nameMatch[0].toLowerCase();
621
+ const body = html.slice(i + (closing ? 2 : 1) + nameMatch[0].length, end);
622
+ i = end + 1;
623
+ if (closing) {
624
+ if (!ALLOWED.has(tag)) continue;
625
+ for (let s = stack.length - 1; s > 0; s -= 1) {
626
+ if (stack[s].tag === tag) {
627
+ stack.length = s;
628
+ break;
629
+ }
630
+ }
631
+ continue;
632
+ }
633
+ if (DROP_WITH_CONTENT.has(tag)) {
634
+ const selfClosing = /\/\s*$/.test(body);
635
+ if (selfClosing) continue;
636
+ const closeIndex = html.slice(i).search(new RegExp(`</${tag}[\\s/>]`, "i"));
637
+ if (closeIndex === -1) break;
638
+ const closeEnd = html.indexOf(">", i + closeIndex);
639
+ i = closeEnd === -1 ? html.length : closeEnd + 1;
640
+ continue;
641
+ }
642
+ if (!ALLOWED.has(tag) || nodes >= MAX_NODES) continue;
643
+ const element = {
644
+ type: "element",
645
+ tag,
646
+ attrs: cleanAttributes(tag, parseAttributes(body)),
647
+ children: []
648
+ };
649
+ stack[stack.length - 1].children.push(element);
650
+ nodes += 1;
651
+ if (!VOID.has(tag) && stack.length < MAX_DEPTH) stack.push(element);
652
+ }
653
+ flush();
654
+ return root.children;
655
+ };
656
+ var resolveLinkAttributes = (attrs, resolver) => {
657
+ if (typeof resolver !== "function" || !attrs["data-mex-uid"] || !attrs["data-mex-document-id"])
658
+ return attrs;
659
+ let result;
660
+ try {
661
+ result = resolver({
662
+ uid: attrs["data-mex-uid"],
663
+ documentId: attrs["data-mex-document-id"],
664
+ locale: attrs["data-mex-locale"] || null,
665
+ href: attrs.href || null
666
+ });
667
+ } catch {
668
+ result = void 0;
669
+ }
670
+ if (result === false) return null;
671
+ if (typeof result === "string") {
672
+ const url = sanitizeUrl(result);
673
+ if (url) return { ...attrs, href: url };
674
+ }
675
+ return attrs;
676
+ };
677
+ var ATTRIBUTE_ORDER = [
678
+ "href",
679
+ "target",
680
+ "rel",
681
+ "title",
682
+ "class",
683
+ "data-tooltip",
684
+ "data-mex-uid",
685
+ "data-mex-document-id",
686
+ "data-mex-locale"
687
+ ];
688
+ var serializeAttributes = (attrs) => ATTRIBUTE_ORDER.filter((name) => attrs[name] !== void 0 && attrs[name] !== "").map((name) => ` ${name}="${escapeHtml2(attrs[name])}"`).join("");
689
+ var nodesToHtml = (nodes, options = {}) => nodes.map((node) => {
690
+ if (node.type === "text") return escapeHtml2(node.value);
691
+ if (node.tag === "br") return "<br>";
692
+ let attrs = node.attrs;
693
+ if (node.tag === "a") {
694
+ attrs = resolveLinkAttributes(attrs, options.links);
695
+ if (!attrs || !attrs.href) return nodesToHtml(node.children, options);
696
+ if (attrs.target === "_blank") {
697
+ const rel = new Set(
698
+ String(attrs.rel || "").split(/\s+/).filter(Boolean)
699
+ );
700
+ rel.add("noopener");
701
+ rel.add("noreferrer");
702
+ attrs = { ...attrs, rel: Array.from(rel).sort().join(" ") };
703
+ }
704
+ }
705
+ return `<${node.tag}${serializeAttributes(attrs)}>${nodesToHtml(node.children, options)}</${node.tag}>`;
706
+ }).join("");
707
+ var nodesToText = (nodes) => nodes.map((node) => {
708
+ if (node.type === "text") return node.value;
709
+ if (node.tag === "br") return "\n";
710
+ return nodesToText(node.children);
711
+ }).join("");
712
+ var inlineToHtml = (html, options) => nodesToHtml(parseInline(html), options);
713
+ var inlineToText = (html) => nodesToText(parseInline(html)).replace(/\u00a0/g, " ");
714
+
715
+ // shared/render/common.mjs
716
+ var keepInline = (html) => inlineToHtml(html);
717
+ var prepareBlocks = (value, options = {}) => {
718
+ const data = normalizeEditorDataSafe(value);
719
+ if (!data) return [];
720
+ const rawPolicy = options.rawHtml === "allow" && typeof options.sanitizeRaw === "function" ? "allow" : "disable";
721
+ const ctx = { rawHtml: rawPolicy, rawSanitizer: () => "" };
722
+ const flat = data.blocks.map((block) => {
723
+ const known = Object.prototype.hasOwnProperty.call(BLOCK_POLICIES, block.type);
724
+ const raw = isPlainObject(block.data) ? block.data : {};
725
+ const clean = known ? BLOCK_POLICIES[block.type](raw, keepInline, ctx) : raw;
726
+ for (const key of Object.keys(clean)) if (clean[key] === void 0) delete clean[key];
727
+ return {
728
+ id: block.id,
729
+ type: block.type,
730
+ data: clean,
731
+ raw,
732
+ tunes: sanitizeTunes(block.tunes),
733
+ known,
734
+ children: []
735
+ };
736
+ });
737
+ const group = (start, end, depth) => {
738
+ const out = [];
739
+ let i = start;
740
+ while (i < end) {
741
+ const block = flat[i];
742
+ i += 1;
743
+ if (block.type === "toggle" && depth < 16) {
744
+ const count = Math.max(0, Math.min(Number(block.data.items) || 0, end - i));
745
+ block.children = group(i, i + count, depth + 1);
746
+ i += count;
747
+ }
748
+ out.push(block);
749
+ }
750
+ return out;
751
+ };
752
+ return group(0, flat.length, 0);
753
+ };
754
+ var FORMAT_ORDER = ["thumbnail", "xsmall", "small", "medium", "large", "xlarge"];
755
+ var imageCandidates = (file) => {
756
+ const out = [];
757
+ const seen = /* @__PURE__ */ new Set();
758
+ const push = (url, width) => {
759
+ const clean = sanitizeUrl(url, { schemes: ["http", "https"] });
760
+ if (!clean || !Number.isInteger(width) || width <= 0 || seen.has(width)) return;
761
+ seen.add(width);
762
+ out.push({ url: clean, width });
763
+ };
764
+ if (isPlainObject(file.formats)) {
765
+ const names = Object.keys(file.formats).sort(
766
+ (a, b) => (FORMAT_ORDER.indexOf(a) + 1 || 99) - (FORMAT_ORDER.indexOf(b) + 1 || 99) || (a < b ? -1 : a > b ? 1 : 0)
767
+ );
768
+ for (const name of names) {
769
+ const format = file.formats[name];
770
+ if (isPlainObject(format)) push(format.url, Number(format.width));
771
+ }
772
+ }
773
+ push(file.url, Number(file.width));
774
+ return out.sort((a, b) => a.width - b.width);
775
+ };
776
+ var resolveMedia = (file, block, options) => {
777
+ if (typeof options.media !== "function") return file;
778
+ let next;
779
+ try {
780
+ next = options.media({ ...file }, { id: block.id, type: block.type });
781
+ } catch {
782
+ next = null;
783
+ }
784
+ if (!isPlainObject(next)) return file;
785
+ const policy = BLOCK_POLICIES.image({ file: next }, (s) => s, {
786
+ rawHtml: "disable",
787
+ rawSanitizer: () => ""
788
+ });
789
+ return policy.file;
790
+ };
791
+ var DEFAULT_EMBED_HOSTS = Object.freeze([
792
+ "www.youtube-nocookie.com",
793
+ "www.youtube.com",
794
+ "youtube.com",
795
+ "player.vimeo.com",
796
+ "codepen.io",
797
+ "player.twitch.tv",
798
+ "clips.twitch.tv",
799
+ "embed.figma.com",
800
+ "www.figma.com",
801
+ "miro.com"
802
+ ]);
803
+ var embedFrameUrl = (url, hosts) => {
804
+ if (!url || !/^https:\/\//i.test(url)) return "";
805
+ try {
806
+ const parsed = new URL(url);
807
+ return parsed.protocol === "https:" && hosts.includes(parsed.hostname.toLowerCase()) ? url : "";
808
+ } catch {
809
+ return "";
810
+ }
811
+ };
812
+ var overrideFor = (options, type) => {
813
+ const overrides = options && options.overrides;
814
+ if (!overrides || typeof overrides !== "object" || !Object.prototype.hasOwnProperty.call(overrides, type))
815
+ return null;
816
+ return typeof overrides[type] === "function" ? overrides[type] : null;
817
+ };
818
+ var scalarFields = (data) => Object.keys(isPlainObject(data) ? data : {}).filter((key) => /^[A-Za-z][A-Za-z0-9_-]{0,63}$/.test(key)).filter((key) => ["string", "number", "boolean"].includes(typeof data[key])).map((key) => [key, String(data[key])]);
819
+ var formatSize = (bytes) => {
820
+ if (!Number.isFinite(bytes) || bytes < 0) return "";
821
+ if (bytes < 1024) return `${bytes} B`;
822
+ if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
823
+ return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
824
+ };
825
+
826
+ // shared/render/html.mjs
827
+ var COUNTER_TYPES = Object.freeze({
828
+ "lower-roman": "i",
829
+ "upper-roman": "I",
830
+ "lower-alpha": "a",
831
+ "upper-alpha": "A"
832
+ });
833
+ var el = (tag, attrs, inner) => {
834
+ const attributes = Object.entries(attrs || {}).filter(
835
+ ([name, value]) => value !== void 0 && value !== null && value !== false && (value !== "" || name === "alt")
836
+ ).map(([name, value]) => value === true ? ` ${name}` : ` ${name}="${escapeHtml2(value)}"`).join("");
837
+ return inner === void 0 ? `<${tag}${attributes}>` : `<${tag}${attributes}>${inner}</${tag}>`;
838
+ };
839
+ var classes = (base, tunes) => {
840
+ const list = [...base];
841
+ if (tunes && tunes.alignmentTune && tunes.alignmentTune.alignment !== "left")
842
+ list.push(`mex-align-${tunes.alignmentTune.alignment}`);
843
+ if (tunes && tunes.textVariant) list.push(`mex-variant-${tunes.textVariant}`);
844
+ if (tunes && tunes.indentTune && tunes.indentTune.indentLevel > 0)
845
+ list.push(`mex-indent-${tunes.indentTune.indentLevel}`);
846
+ return list.join(" ");
847
+ };
848
+ var listItems2 = (items, style, options, depth) => items.map((item) => {
849
+ if (typeof item === "string") return el("li", {}, inlineToHtml(item, options));
850
+ const checked = Boolean(item.meta && item.meta.checked);
851
+ const check = style === "checklist" ? `${el("input", { type: "checkbox", disabled: true, checked, "aria-label": checked ? "done" : "open" })} ` : "";
852
+ const nested = Array.isArray(item.items) && item.items.length && depth < 12 ? listElement(item.items, style, {}, options, depth + 1, []) : "";
853
+ return el(
854
+ "li",
855
+ style === "checklist" ? { class: "mex-checklist-item", "data-checked": String(checked) } : {},
856
+ check + inlineToHtml(item.content, options) + nested
857
+ );
858
+ }).join("");
859
+ var listElement = (items, style, meta, options, depth, base, tunes) => {
860
+ const tag = style === "ordered" ? "ol" : "ul";
861
+ const attrs = {};
862
+ if (base.length) attrs.class = classes(base, tunes);
863
+ if (style === "ordered" && meta) {
864
+ if (Number.isInteger(meta.start) && meta.start !== 1) attrs.start = meta.start;
865
+ if (COUNTER_TYPES[meta.counterType]) attrs.type = COUNTER_TYPES[meta.counterType];
866
+ }
867
+ return el(tag, attrs, listItems2(items, style, options, depth));
868
+ };
869
+ var figure = (url, img, caption, cls) => el(
870
+ "figure",
871
+ { class: cls },
872
+ el("img", { src: url, ...img, loading: "lazy", decoding: "async" }) + (caption ? el("figcaption", {}, caption) : "")
873
+ );
874
+ var RENDERERS = {
875
+ paragraph: (b, o) => el("p", { class: classes(["mex-paragraph"], b.tunes) }, inlineToHtml(b.data.text, o)),
876
+ header: (b, o) => el(`h${b.data.level}`, { class: classes(["mex-header"], b.tunes) }, inlineToHtml(b.data.text, o)),
877
+ quote: (b, o) => {
878
+ const caption = inlineToHtml(b.data.caption, o);
879
+ return el(
880
+ "figure",
881
+ {
882
+ class: classes(
883
+ ["mex-quote", ...b.data.alignment === "center" ? ["mex-align-center"] : []],
884
+ b.tunes
885
+ )
886
+ },
887
+ el("blockquote", {}, inlineToHtml(b.data.text, o)) + (caption ? el("figcaption", {}, caption) : "")
888
+ );
889
+ },
890
+ list: (b, o) => listElement(
891
+ b.data.items,
892
+ b.data.style,
893
+ b.data.meta,
894
+ o,
895
+ 0,
896
+ b.data.style === "checklist" ? ["mex-list", "mex-checklist"] : ["mex-list"],
897
+ b.tunes
898
+ ),
899
+ checklist: (b, o) => listElement(
900
+ b.data.items.map((item) => ({ content: item.text, meta: { checked: item.checked }, items: [] })),
901
+ "checklist",
902
+ {},
903
+ o,
904
+ 0,
905
+ ["mex-list", "mex-checklist"],
906
+ b.tunes
907
+ ),
908
+ warning: (b, o) => {
909
+ const title = inlineToHtml(b.data.title, o);
910
+ return el(
911
+ "aside",
912
+ { class: classes(["mex-warning"], b.tunes), role: "note" },
913
+ (title ? el("p", { class: "mex-warning-title" }, el("strong", {}, title)) : "") + el("p", { class: "mex-warning-message" }, inlineToHtml(b.data.message, o))
914
+ );
915
+ },
916
+ alert: (b, o) => el(
917
+ "div",
918
+ {
919
+ class: classes(
920
+ [
921
+ "mex-alert",
922
+ `mex-alert-${b.data.type}`,
923
+ ...b.data.align !== "left" ? [`mex-align-${b.data.align}`] : []
924
+ ],
925
+ b.tunes
926
+ ),
927
+ role: "note"
928
+ },
929
+ inlineToHtml(b.data.message, o)
930
+ ),
931
+ toggle: (b, o, render) => el(
932
+ "details",
933
+ { class: classes(["mex-toggle"], b.tunes), open: b.data.status !== "closed" },
934
+ el("summary", {}, inlineToHtml(b.data.text, o)) + render(b.children)
935
+ ),
936
+ code: (b) => el("pre", { class: classes(["mex-code"], b.tunes) }, el("code", {}, escapeHtml2(b.data.code))),
937
+ codeFlask: (b) => el(
938
+ "pre",
939
+ { class: classes(["mex-code"], b.tunes), "data-language": b.data.language },
940
+ el("code", { class: `language-${b.data.language}` }, escapeHtml2(b.data.code))
941
+ ),
942
+ raw: (b, o) => {
943
+ if (o.rawHtml !== "allow" || typeof o.sanitizeRaw !== "function") return "";
944
+ const html = o.sanitizeRaw(String(b.raw.html || ""));
945
+ return typeof html === "string" && html ? el("div", { class: classes(["mex-raw"], b.tunes) }, html) : "";
946
+ },
947
+ table: (b, o) => {
948
+ const rows = b.data.content;
949
+ if (!rows.length) return "";
950
+ const cells = (row, tag) => el(
951
+ "tr",
952
+ {},
953
+ row.map((cell2) => el(tag, tag === "th" ? { scope: "col" } : {}, inlineToHtml(cell2, o))).join("")
954
+ );
955
+ const head = b.data.withHeadings ? el("thead", {}, cells(rows[0], "th")) : "";
956
+ const body = (b.data.withHeadings ? rows.slice(1) : rows).map((row) => cells(row, "td")).join("");
957
+ return el(
958
+ "table",
959
+ { class: classes(["mex-table", ...b.data.stretched ? ["mex-stretched"] : []], b.tunes) },
960
+ head + (body ? el("tbody", {}, body) : "")
961
+ );
962
+ },
963
+ image: (b, o) => {
964
+ const file = resolveMedia(b.data.file, b, o);
965
+ if (!file.url) return "";
966
+ const decorative = b.raw.decorative === true;
967
+ const candidates = imageCandidates(file);
968
+ const img = {
969
+ alt: decorative ? "" : file.alt || "",
970
+ width: Number.isInteger(file.width) && file.width > 0 ? file.width : void 0,
971
+ height: Number.isInteger(file.height) && file.height > 0 ? file.height : void 0
972
+ };
973
+ if (candidates.length > 1) {
974
+ img.srcset = candidates.map((c) => `${c.url} ${c.width}w`).join(", ");
975
+ img.sizes = typeof o.imageSizes === "string" && /^[\w\s(),.:%-]{1,200}$/.test(o.imageSizes) ? o.imageSizes : "100vw";
976
+ }
977
+ const cls = ["mex-image"];
978
+ if (b.data.withBorder) cls.push("mex-image-border");
979
+ if (b.data.withBackground) cls.push("mex-image-background");
980
+ if (b.data.stretched) cls.push("mex-stretched");
981
+ return figure(file.url, img, inlineToHtml(b.data.caption, o), classes(cls, b.tunes));
982
+ },
983
+ simpleImage: (b, o) => {
984
+ if (!b.data.url) return "";
985
+ const cls = ["mex-image"];
986
+ if (b.data.withBorder) cls.push("mex-image-border");
987
+ if (b.data.withBackground) cls.push("mex-image-background");
988
+ if (b.data.stretched) cls.push("mex-stretched");
989
+ return figure(
990
+ b.data.url,
991
+ {
992
+ alt: b.data.decorative === true ? "" : typeof b.data.alt === "string" && b.data.alt.trim() ? b.data.alt : inlineToText(b.data.caption)
993
+ },
994
+ inlineToHtml(b.data.caption, o),
995
+ classes(cls, b.tunes)
996
+ );
997
+ },
998
+ linkTool: (b) => {
999
+ if (!b.data.link) return "";
1000
+ const meta = b.data.meta;
1001
+ const image = meta.image && meta.image.url ? el("img", { class: "mex-link-image", src: meta.image.url, alt: "", loading: "lazy" }) : "";
1002
+ const inner = image + el("span", { class: "mex-link-title" }, escapeHtml2(meta.title || b.data.link)) + (meta.description ? el("span", { class: "mex-link-description" }, escapeHtml2(meta.description)) : "") + (meta.site_name ? el("span", { class: "mex-link-site" }, escapeHtml2(meta.site_name)) : "");
1003
+ return el(
1004
+ "div",
1005
+ { class: classes(["mex-link-preview"], b.tunes) },
1006
+ el("a", { href: b.data.link, rel: "nofollow noopener noreferrer" }, inner)
1007
+ );
1008
+ },
1009
+ attaches: (b) => {
1010
+ const file = b.data.file;
1011
+ if (!file.url) return "";
1012
+ const label = b.data.title || file.title || file.name || file.url;
1013
+ const details = [file.extension ? file.extension.toUpperCase() : "", formatSize(file.size)].filter(Boolean).join(", ");
1014
+ return el(
1015
+ "p",
1016
+ { class: classes(["mex-attachment"], b.tunes) },
1017
+ el("a", { href: file.url, download: true }, escapeHtml2(label)) + (details ? ` ${el("span", { class: "mex-attachment-meta" }, `(${escapeHtml2(details)})`)}` : "")
1018
+ );
1019
+ },
1020
+ embed: (b, o) => {
1021
+ const hosts = Array.isArray(o.embedHosts) ? o.embedHosts.map((h) => String(h).toLowerCase()) : DEFAULT_EMBED_HOSTS;
1022
+ const frame = embedFrameUrl(b.data.embed, hosts);
1023
+ const caption = inlineToHtml(b.data.caption, o);
1024
+ const title = inlineToText(b.data.caption) || b.data.service || "Embedded content";
1025
+ if (!frame) {
1026
+ const href = b.data.source || b.data.embed;
1027
+ if (!href) return "";
1028
+ return el(
1029
+ "p",
1030
+ { class: classes(["mex-embed", "mex-embed-link"], b.tunes) },
1031
+ el("a", { href, rel: "nofollow noopener noreferrer" }, caption || escapeHtml2(href))
1032
+ );
1033
+ }
1034
+ return el(
1035
+ "figure",
1036
+ {
1037
+ class: classes(
1038
+ ["mex-embed", b.data.service ? `mex-embed-${b.data.service}` : ""].filter(Boolean),
1039
+ b.tunes
1040
+ )
1041
+ },
1042
+ el(
1043
+ "iframe",
1044
+ {
1045
+ src: frame,
1046
+ title,
1047
+ width: b.data.width,
1048
+ height: b.data.height,
1049
+ loading: "lazy",
1050
+ referrerpolicy: "strict-origin-when-cross-origin",
1051
+ sandbox: "allow-scripts allow-same-origin allow-popups allow-presentation",
1052
+ allow: "fullscreen; picture-in-picture; encrypted-media",
1053
+ allowfullscreen: true
1054
+ },
1055
+ ""
1056
+ ) + (caption ? el("figcaption", {}, caption) : "")
1057
+ );
1058
+ },
1059
+ personality: (b) => {
1060
+ const d = b.data;
1061
+ if (!d.name && !d.description) return "";
1062
+ return el(
1063
+ "div",
1064
+ { class: classes(["mex-personality"], b.tunes) },
1065
+ (d.photo ? el("img", { class: "mex-personality-photo", src: d.photo, alt: "", loading: "lazy" }) : "") + el(
1066
+ "div",
1067
+ { class: "mex-personality-body" },
1068
+ (d.name ? el("p", { class: "mex-personality-name" }, escapeHtml2(d.name)) : "") + (d.description ? el("p", { class: "mex-personality-description" }, escapeHtml2(d.description)) : "") + (d.link ? el("a", { class: "mex-personality-link", href: d.link }, escapeHtml2(d.link)) : "")
1069
+ )
1070
+ );
1071
+ },
1072
+ button: (b) => {
1073
+ const d = b.data;
1074
+ if (!d.text) return "";
1075
+ const cls = `mex-button mex-button-${d.style}`;
1076
+ const inner = d.link ? el(
1077
+ "a",
1078
+ {
1079
+ class: cls,
1080
+ href: d.link,
1081
+ target: d.openInNewTab ? "_blank" : void 0,
1082
+ rel: d.openInNewTab ? "noopener noreferrer" : void 0
1083
+ },
1084
+ escapeHtml2(d.text)
1085
+ ) : el("span", { class: cls }, escapeHtml2(d.text));
1086
+ return el("p", { class: classes(["mex-button-block"], b.tunes) }, inner);
1087
+ },
1088
+ delimiter: (b) => el("hr", { class: classes(["mex-delimiter"], b.tunes) })
1089
+ };
1090
+ var neutral = (b) => el(
1091
+ "div",
1092
+ { class: classes(["mex-block", `mex-${b.type}`], b.tunes), "data-mex-block": b.type },
1093
+ scalarFields(b.data).map(
1094
+ ([key, value]) => el("div", { class: "mex-field", "data-mex-field": key }, escapeHtml2(inlineToText(value)))
1095
+ ).join("")
1096
+ );
1097
+ var helpersFor = (options, render) => ({
1098
+ escape: escapeHtml2,
1099
+ inline: (html) => inlineToHtml(html, options),
1100
+ text: (html) => inlineToText(html),
1101
+ url: (value, schemes) => sanitizeUrl(value, schemes ? { schemes } : void 0),
1102
+ renderChildren: (blocks) => render(blocks)
1103
+ });
1104
+ var renderHtml = (value, options = {}) => {
1105
+ const opts = options && typeof options === "object" ? options : {};
1106
+ const render = (blocks) => blocks.map((block) => {
1107
+ const override = overrideFor(opts, block.type);
1108
+ if (override) {
1109
+ const out = override(
1110
+ {
1111
+ id: block.id,
1112
+ type: block.type,
1113
+ data: block.data,
1114
+ tunes: block.tunes,
1115
+ children: block.children
1116
+ },
1117
+ helpersFor(opts, render)
1118
+ );
1119
+ if (typeof out === "string") return out;
1120
+ }
1121
+ if (block.known) return RENDERERS[block.type](block, opts, render);
1122
+ return neutral(block);
1123
+ }).filter(Boolean).join("\n");
1124
+ return render(prepareBlocks(value, opts));
1125
+ };
1126
+
1127
+ // shared/render/text.mjs
1128
+ var listLines = (items, style, start, depth) => {
1129
+ const lines = [];
1130
+ items.forEach((item, index) => {
1131
+ const content = typeof item === "string" ? item : item.content;
1132
+ let marker = "-";
1133
+ if (style === "ordered") marker = `${start + index}.`;
1134
+ else if (style === "checklist") marker = item.meta && item.meta.checked ? "[x]" : "[ ]";
1135
+ const indent = " ".repeat(depth);
1136
+ const text = inlineToText(content).trim().replace(/\n/g, `
1137
+ ${indent} `);
1138
+ lines.push(`${indent}${marker} ${text}`);
1139
+ if (typeof item !== "string" && Array.isArray(item.items) && item.items.length && depth < 12)
1140
+ lines.push(...listLines(item.items, style, 1, depth + 1));
1141
+ });
1142
+ return lines;
1143
+ };
1144
+ var t = (html) => inlineToText(html).trim();
1145
+ var RENDERERS2 = {
1146
+ paragraph: (b) => t(b.data.text),
1147
+ header: (b) => t(b.data.text),
1148
+ quote: (b) => [t(b.data.text), t(b.data.caption) ? `\u2014 ${t(b.data.caption)}` : ""].filter(Boolean).join("\n"),
1149
+ list: (b) => listLines(
1150
+ b.data.items,
1151
+ b.data.style,
1152
+ Number.isInteger(b.data.meta && b.data.meta.start) ? b.data.meta.start : 1,
1153
+ 0
1154
+ ).join("\n"),
1155
+ checklist: (b) => b.data.items.map((item) => `${item.checked ? "[x]" : "[ ]"} ${t(item.text)}`).join("\n"),
1156
+ warning: (b) => [t(b.data.title), t(b.data.message)].filter(Boolean).join("\n"),
1157
+ alert: (b) => t(b.data.message),
1158
+ toggle: (b, _o, render) => [t(b.data.text), render(b.children)].filter(Boolean).join("\n\n"),
1159
+ code: (b) => b.data.code,
1160
+ codeFlask: (b) => b.data.code,
1161
+ raw: () => "",
1162
+ table: (b) => b.data.content.map((row) => row.map((cell2) => t(cell2).replace(/\s+/g, " ")).join(" ")).join("\n"),
1163
+ image: (b) => t(b.data.caption) || (b.raw.decorative === true ? "" : (b.data.file.alt || "").trim()),
1164
+ simpleImage: (b) => t(b.data.caption),
1165
+ linkTool: (b) => [b.data.meta.title, b.data.link].filter(Boolean).join("\n"),
1166
+ attaches: (b) => b.data.file.url ? b.data.title || b.data.file.title || b.data.file.name || b.data.file.url : "",
1167
+ embed: (b) => [t(b.data.caption), b.data.source || b.data.embed].filter(Boolean).join("\n"),
1168
+ personality: (b) => [b.data.name, b.data.description, b.data.link].filter(Boolean).join("\n"),
1169
+ button: (b) => b.data.link ? `${b.data.text} (${b.data.link})` : b.data.text,
1170
+ delimiter: () => "---"
1171
+ };
1172
+ var renderText = (value, options = {}) => {
1173
+ const opts = options && typeof options === "object" ? options : {};
1174
+ const render = (blocks) => blocks.map((block) => {
1175
+ const override = overrideFor(opts, block.type);
1176
+ if (override) {
1177
+ const out = override(
1178
+ {
1179
+ id: block.id,
1180
+ type: block.type,
1181
+ data: block.data,
1182
+ tunes: block.tunes,
1183
+ children: block.children
1184
+ },
1185
+ { text: (html) => inlineToText(html), renderChildren: render }
1186
+ );
1187
+ if (typeof out === "string") return out;
1188
+ }
1189
+ if (block.known) return RENDERERS2[block.type](block, opts, render);
1190
+ return scalarFields(block.data).map(([, v]) => inlineToText(v).trim()).filter(Boolean).join("\n");
1191
+ }).map((text) => String(text).replace(/\u00a0/g, " ")).filter((text) => text.trim() !== "").join("\n\n");
1192
+ return render(prepareBlocks(value, opts));
1193
+ };
1194
+
1195
+ // shared/render/markdown.mjs
1196
+ var escapeMarkdown = (text) => String(text).replace(/\u00a0/g, " ").replace(/[\\`*_[\]<>|~&{}]/g, (char) => `\\${char}`).replace(
1197
+ /(^|\n)(\s*)([#>+=-]|\d{1,9}[.)])/g,
1198
+ (_m, nl, space, mark) => `${nl}${space}${mark.replace(/^(\d*)([#>+=.)-])$/, "$1\\$2")}`
1199
+ );
1200
+ var linkUrl = (url) => String(url).replace(
1201
+ /[ ()<>\\]/g,
1202
+ (char) => `%${char.charCodeAt(0).toString(16).toUpperCase().padStart(2, "0")}`
1203
+ );
1204
+ var linkTitle = (title) => {
1205
+ const clean = String(title || "").replace(/\s+/g, " ").trim();
1206
+ return clean ? ` "${clean.replace(/[\\"<>]/g, (char) => `\\${char}`)}"` : "";
1207
+ };
1208
+ var wrap = (marker, inner) => {
1209
+ const match = /^(\s*)([\s\S]*?)(\s*)$/.exec(inner);
1210
+ if (!match[2]) return inner;
1211
+ return `${match[1]}${marker}${match[2]}${marker}${match[3]}`;
1212
+ };
1213
+ var codeSpan = (code) => {
1214
+ const text = code.replace(/\n/g, " ");
1215
+ if (!text) return "";
1216
+ const longest = Math.max(0, ...(text.match(/`+/g) || []).map((run) => run.length));
1217
+ const fence2 = "`".repeat(longest + 1);
1218
+ const pad = text.startsWith("`") || text.endsWith("`") || text.startsWith(" ") && text.endsWith(" ") ? " " : "";
1219
+ return `${fence2}${pad}${text}${pad}${fence2}`;
1220
+ };
1221
+ var rawText = (nodes) => nodes.map((n) => n.type === "text" ? n.value : n.tag === "br" ? "\n" : rawText(n.children)).join("");
1222
+ var nodesToMarkdown = (nodes, options) => nodes.map((node) => {
1223
+ if (node.type === "text") return escapeMarkdown(node.value);
1224
+ const inner = () => nodesToMarkdown(node.children, options);
1225
+ switch (node.tag) {
1226
+ case "br":
1227
+ return "\\\n";
1228
+ case "b":
1229
+ case "strong":
1230
+ return wrap("**", inner());
1231
+ case "i":
1232
+ case "em":
1233
+ return wrap("_", inner());
1234
+ case "s":
1235
+ return wrap("~~", inner());
1236
+ case "code":
1237
+ return codeSpan(rawText(node.children));
1238
+ case "a": {
1239
+ const attrs = resolveLinkAttributes(node.attrs, options.links);
1240
+ const text = inner();
1241
+ if (!attrs || !attrs.href) return text;
1242
+ return `[${text || escapeMarkdown(attrs.href)}](${linkUrl(attrs.href)}${linkTitle(attrs.title)})`;
1243
+ }
1244
+ default:
1245
+ return inner();
1246
+ }
1247
+ }).join("");
1248
+ var md = (html, options) => nodesToMarkdown(parseInline(html), options).trim();
1249
+ var oneLine = (text) => text.replace(/\\\n/g, " ").replace(/\n/g, " ");
1250
+ var prefixLines = (text, prefix) => text.split("\n").map((line) => line ? `${prefix}${line}` : prefix.trimEnd()).join("\n");
1251
+ var listLines2 = (items, style, start, options, indent, depth) => {
1252
+ const lines = [];
1253
+ items.forEach((item, index) => {
1254
+ const content = typeof item === "string" ? item : item.content;
1255
+ let marker = "-";
1256
+ if (style === "ordered") marker = `${start + index}.`;
1257
+ else if (style === "checklist") marker = `- [${item.meta && item.meta.checked ? "x" : " "}]`;
1258
+ const childIndent = `${indent}${" ".repeat((style === "checklist" ? 2 : marker.length) + 1)}`;
1259
+ const text = md(content, options).replace(/\n/g, `
1260
+ ${childIndent}`);
1261
+ lines.push(`${indent}${marker} ${text}`.trimEnd());
1262
+ if (typeof item !== "string" && Array.isArray(item.items) && item.items.length && depth < 12)
1263
+ lines.push(...listLines2(item.items, style, 1, options, childIndent, depth + 1));
1264
+ });
1265
+ return lines;
1266
+ };
1267
+ var fence = (code, language) => {
1268
+ const longest = Math.max(2, ...(code.match(/`{3,}/g) || []).map((run) => run.length));
1269
+ const marks = "`".repeat(longest + 1);
1270
+ const info = language && /^[a-z0-9+#-]{1,32}$/i.test(language) && language !== "plaintext" ? language : "";
1271
+ return `${marks}${info}
1272
+ ${code.replace(/\n$/, "")}
1273
+ ${marks}`;
1274
+ };
1275
+ var cell = (html, options) => oneLine(md(html, options)) || " ";
1276
+ var RENDERERS3 = {
1277
+ paragraph: (b, o) => md(b.data.text, o),
1278
+ header: (b, o) => {
1279
+ const text = oneLine(md(b.data.text, o));
1280
+ return text ? `${"#".repeat(b.data.level)} ${text}` : "";
1281
+ },
1282
+ quote: (b, o) => {
1283
+ const text = md(b.data.text, o);
1284
+ const caption = md(b.data.caption, o);
1285
+ if (!text && !caption) return "";
1286
+ return prefixLines(caption ? `${text}
1287
+
1288
+ \u2014 ${caption}` : text, "> ");
1289
+ },
1290
+ list: (b, o) => listLines2(
1291
+ b.data.items,
1292
+ b.data.style,
1293
+ Number.isInteger(b.data.meta && b.data.meta.start) ? b.data.meta.start : 1,
1294
+ o,
1295
+ "",
1296
+ 0
1297
+ ).join("\n"),
1298
+ checklist: (b, o) => b.data.items.map((item) => `- [${item.checked ? "x" : " "}] ${oneLine(md(item.text, o))}`.trimEnd()).join("\n"),
1299
+ warning: (b, o) => {
1300
+ const title = md(b.data.title, o);
1301
+ const message = md(b.data.message, o);
1302
+ return prefixLines([title ? `**${oneLine(title)}**` : "", message].filter(Boolean).join("\n\n"), "> ");
1303
+ },
1304
+ alert: (b, o) => {
1305
+ const message = md(b.data.message, o);
1306
+ return message ? prefixLines(message, "> ") : "";
1307
+ },
1308
+ toggle: (b, o, render) => [b.data.text ? `**${oneLine(md(b.data.text, o))}**` : "", render(b.children)].filter(Boolean).join("\n\n"),
1309
+ code: (b) => b.data.code ? fence(b.data.code) : "",
1310
+ codeFlask: (b) => b.data.code ? fence(b.data.code, b.data.language) : "",
1311
+ raw: (b, o) => {
1312
+ if (o.rawHtml !== "allow" || typeof o.sanitizeRaw !== "function") return "";
1313
+ const html = o.sanitizeRaw(String(b.raw.html || ""));
1314
+ return typeof html === "string" ? html.trim() : "";
1315
+ },
1316
+ table: (b, o) => {
1317
+ const rows = b.data.content.filter((row) => row.length);
1318
+ if (!rows.length) return "";
1319
+ const width = Math.max(...rows.map((row) => row.length));
1320
+ const line = (row) => `| ${Array.from({ length: width }, (_, i) => cell(row[i] || "", o)).join(" | ")} |`;
1321
+ const head = b.data.withHeadings ? rows[0] : [];
1322
+ const body = b.data.withHeadings ? rows.slice(1) : rows;
1323
+ return [
1324
+ line(head),
1325
+ `| ${Array.from({ length: width }, () => "---").join(" | ")} |`,
1326
+ ...body.map(line)
1327
+ ].join("\n");
1328
+ },
1329
+ image: (b, o) => {
1330
+ const file = resolveMedia(b.data.file, b, o);
1331
+ if (!file.url) return "";
1332
+ const alt = b.raw.decorative === true ? "" : escapeMarkdown(oneLine(file.alt || ""));
1333
+ const caption = inlineToText(b.data.caption);
1334
+ return `![${alt}](${linkUrl(file.url)}${linkTitle(caption)})`;
1335
+ },
1336
+ simpleImage: (b) => {
1337
+ if (!b.data.url) return "";
1338
+ const text = typeof b.data.alt === "string" && b.data.alt.trim() ? b.data.alt : inlineToText(b.data.caption);
1339
+ const alt = b.data.decorative === true ? "" : escapeMarkdown(oneLine(text));
1340
+ return `![${alt}](${linkUrl(b.data.url)})`;
1341
+ },
1342
+ linkTool: (b) => b.data.link ? `[${escapeMarkdown(b.data.meta.title || b.data.link)}](${linkUrl(b.data.link)})` : "",
1343
+ attaches: (b) => {
1344
+ const file = b.data.file;
1345
+ if (!file.url) return "";
1346
+ return `[${escapeMarkdown(b.data.title || file.title || file.name || file.url)}](${linkUrl(file.url)})`;
1347
+ },
1348
+ embed: (b, o) => {
1349
+ const href = b.data.source || b.data.embed;
1350
+ if (!href) return "";
1351
+ return `[${oneLine(md(b.data.caption, o)) || escapeMarkdown(b.data.service || href)}](${linkUrl(href)})`;
1352
+ },
1353
+ personality: (b) => {
1354
+ const d = b.data;
1355
+ return [
1356
+ d.name ? `**${escapeMarkdown(d.name)}**` : "",
1357
+ d.description ? escapeMarkdown(d.description) : "",
1358
+ d.link ? `[${escapeMarkdown(d.link)}](${linkUrl(d.link)})` : ""
1359
+ ].filter(Boolean).join("\n\n");
1360
+ },
1361
+ button: (b) => {
1362
+ if (!b.data.text) return "";
1363
+ return b.data.link ? `[${escapeMarkdown(b.data.text)}](${linkUrl(b.data.link)})` : escapeMarkdown(b.data.text);
1364
+ },
1365
+ delimiter: () => "---"
1366
+ };
1367
+ var renderMarkdown = (value, options = {}) => {
1368
+ const opts = options && typeof options === "object" ? options : {};
1369
+ const render = (blocks) => blocks.map((block) => {
1370
+ const override = overrideFor(opts, block.type);
1371
+ if (override) {
1372
+ const out = override(
1373
+ {
1374
+ id: block.id,
1375
+ type: block.type,
1376
+ data: block.data,
1377
+ tunes: block.tunes,
1378
+ children: block.children
1379
+ },
1380
+ { escape: escapeMarkdown, inline: (html) => md(html, opts), renderChildren: render }
1381
+ );
1382
+ if (typeof out === "string") return out;
1383
+ }
1384
+ if (block.known) return RENDERERS3[block.type](block, opts, render);
1385
+ return scalarFields(block.data).map(([, v]) => md(v, opts)).filter(Boolean).join("\n\n");
1386
+ }).filter((text) => text && text.trim() !== "").join("\n\n");
1387
+ return render(prepareBlocks(value, opts));
1388
+ };
1389
+ export {
1390
+ DEFAULT_EMBED_HOSTS,
1391
+ escapeHtml2 as escapeHtml,
1392
+ escapeMarkdown,
1393
+ inlineToHtml,
1394
+ inlineToText,
1395
+ renderHtml,
1396
+ renderMarkdown,
1397
+ renderText
1398
+ };