magic-editor-x 2.1.0 → 2.3.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/CHANGELOG.md +125 -0
- package/README.md +593 -142
- package/bin/magic-editor-x.mjs +190 -0
- package/dist/admin/{ConfigurationPage-CK2AbfGW.mjs → ConfigurationPage-BxLHIQdo.mjs} +450 -21
- package/dist/admin/{ConfigurationPage-CzsT_dO_.js → ConfigurationPage-C-UktL1x.js} +479 -50
- package/dist/admin/ConfirmAction-DuQwvRYi.mjs +125 -0
- package/dist/admin/ConfirmAction-zLuIFj8t.js +124 -0
- package/dist/admin/{CustomBlocksPage-CvLrsBds.js → CustomBlocksPage-CxcTfdOT.js} +135 -84
- package/dist/admin/{CustomBlocksPage-B2A8S5MV.mjs → CustomBlocksPage-D8aMbVXc.mjs} +92 -41
- package/dist/admin/DraftSync-BIA8cZgA.js +11 -0
- package/dist/admin/DraftSync-CUxOMG-E.mjs +12 -0
- package/dist/admin/TemplatesPage-Hn6gyu2l.js +993 -0
- package/dist/admin/TemplatesPage-jhYi6Zdf.mjs +993 -0
- package/dist/admin/de-1cFMs-4c.mjs +43 -0
- package/dist/admin/{de-CkUYGb7U.js → de-2Ie5jy7j.js} +86 -2
- package/dist/admin/de-B1X46JJZ.js +453 -0
- package/dist/admin/{de-rRIutpYJ.mjs → de-BMY2LBaa.mjs} +86 -2
- package/dist/admin/{de-Bt6pYIWi.mjs → de-BUS1hUw0.mjs} +145 -0
- package/dist/admin/{de-CVbi685U.js → de-C3AsGauQ.js} +145 -0
- package/dist/admin/de-DOiGaTNX.mjs +453 -0
- package/dist/admin/de-Dn8athM8.js +43 -0
- package/dist/admin/{en-DulOcmXb.js → en-Ah-Cw0Wd.js} +86 -2
- package/dist/admin/{en-BX362fTp.js → en-BkEjpC3i.js} +145 -0
- package/dist/admin/en-CDg_18Bt.js +453 -0
- package/dist/admin/en-CIZ5Ggod.js +43 -0
- package/dist/admin/en-CU6UzV4g.mjs +453 -0
- package/dist/admin/{en-Puup8TFi.mjs → en-CvFiqti2.mjs} +86 -2
- package/dist/admin/en-Dc9y-6n9.mjs +43 -0
- package/dist/admin/{en-B_HltUxZ.mjs → en-GCzgS9Aw.mjs} +145 -0
- package/dist/admin/es-BCpJmUEM.js +453 -0
- package/dist/admin/es-BmfffNM2.mjs +453 -0
- package/dist/admin/es-C4IRHV5d.js +43 -0
- package/dist/admin/{es-CHHEZi44.js → es-C4pEnDRv.js} +145 -0
- package/dist/admin/{es-BoQZC86B.js → es-Cr8JH85N.js} +86 -2
- package/dist/admin/es-D2Kw6E4N.mjs +43 -0
- package/dist/admin/{es-CrhwOq-5.mjs → es-DHBBZKl2.mjs} +145 -0
- package/dist/admin/{es-257SSB7f.mjs → es-DbKHZz5l.mjs} +86 -2
- package/dist/admin/fr-BOvvfEH7.mjs +43 -0
- package/dist/admin/{fr-B3SL0TBV.js → fr-C2aLSwEu.js} +145 -0
- package/dist/admin/{fr-C5rSdKU4.mjs → fr-DQJ_7aq5.mjs} +86 -2
- package/dist/admin/fr-DZd2XJP6.mjs +453 -0
- package/dist/admin/{fr-5djKfQ3s.mjs → fr-Dvq4xk2e.mjs} +145 -0
- package/dist/admin/{fr-HxFcPpv4.js → fr-OJ4VW1kh.js} +86 -2
- package/dist/admin/fr-ZcN0yM_2.js +453 -0
- package/dist/admin/fr-Zkb8vfjN.js +43 -0
- package/dist/admin/index-BHBRr562.js +1940 -0
- package/dist/admin/index-CQk1XeNb.mjs +1939 -0
- package/dist/admin/index-Cm-fFUhE.js +18908 -0
- package/dist/admin/index-XgfwqLfV.mjs +18873 -0
- package/dist/admin/index.js +1 -1
- package/dist/admin/index.mjs +2 -2
- package/dist/admin/pt-1IUyx6ae.js +43 -0
- package/dist/admin/{pt-D6UuEtPy.mjs → pt-BSLzA17U.mjs} +86 -2
- package/dist/admin/pt-C3UdeIpd.mjs +453 -0
- package/dist/admin/pt-CImqDnLB.js +453 -0
- package/dist/admin/{pt-BdnY2Cth.mjs → pt-CilDggGF.mjs} +145 -0
- package/dist/admin/{pt-Cjn2Sc9k.js → pt-D0I0_JYs.js} +86 -2
- package/dist/admin/{pt-EVwCuBUK.js → pt-DX0OAIoL.js} +145 -0
- package/dist/admin/pt-etwsg3G4.mjs +43 -0
- package/dist/admin/useBreakpoint-D30eNTkF.js +37 -0
- package/dist/admin/useBreakpoint-DCfn6pDG.mjs +38 -0
- package/dist/admin/useT-CmaeZbCr.mjs +65 -0
- package/dist/admin/{useT-91ruePzq.js → useT-D3sM9Zf7.js} +4 -70
- package/dist/blocks/index.d.mts +167 -0
- package/dist/blocks/index.d.ts +167 -0
- package/dist/blocks/index.js +631 -0
- package/dist/blocks/index.mjs +609 -0
- package/dist/react/index.d.mts +39 -0
- package/dist/react/index.d.ts +39 -0
- package/dist/react/index.js +2687 -0
- package/dist/react/index.mjs +2657 -0
- package/dist/render/index.d.mts +201 -0
- package/dist/render/index.d.ts +201 -0
- package/dist/render/index.js +2918 -0
- package/dist/render/index.mjs +2896 -0
- package/dist/server/index.js +19400 -4738
- package/dist/server/index.mjs +19403 -4741
- package/dist/vue/index.d.mts +41 -0
- package/dist/vue/index.d.ts +41 -0
- package/dist/vue/index.js +2630 -0
- package/dist/vue/index.mjs +2610 -0
- package/package.json +49 -8
- package/schema/magic-editor-x.schema.json +1506 -0
- package/types/blocks.d.ts +167 -0
- package/types/index.d.ts +338 -0
- package/types/react.d.ts +39 -0
- package/types/render.d.ts +201 -0
- package/types/vue.d.ts +41 -0
- package/dist/admin/EditorField-7YCdXx-v.mjs +0 -6829
- package/dist/admin/EditorField-BdBCW15Q.js +0 -6864
- package/dist/admin/api-CmccMxlN.js +0 -36
- package/dist/admin/api-D5CAH0nh.mjs +0 -37
- package/dist/admin/de-BHPyA2S-.mjs +0 -103
- package/dist/admin/de-DBR893G4.js +0 -13
- package/dist/admin/de-RMs-_SCK.js +0 -103
- package/dist/admin/de-fBFh09Wl.mjs +0 -13
- package/dist/admin/en-BluCStLw.mjs +0 -103
- package/dist/admin/en-C81faOHP.js +0 -103
- package/dist/admin/en-D9Nfccux.mjs +0 -13
- package/dist/admin/en-gueRT44P.js +0 -13
- package/dist/admin/es-B0Zy8DVg.mjs +0 -13
- package/dist/admin/es-CQRI2Prp.mjs +0 -103
- package/dist/admin/es-D1QzY0JW.js +0 -103
- package/dist/admin/es-DRGs7meF.js +0 -13
- package/dist/admin/fr-B8rdLAIL.js +0 -13
- package/dist/admin/fr-Di3R6gOX.mjs +0 -103
- package/dist/admin/fr-R3_MbzT5.js +0 -103
- package/dist/admin/fr-oiUb2bb_.mjs +0 -13
- package/dist/admin/index-0_b1iroK.mjs +0 -156
- package/dist/admin/index-6SZLli70.js +0 -155
- package/dist/admin/pt-B3Jce6uT.mjs +0 -13
- package/dist/admin/pt-BCW1u_Hp.js +0 -103
- package/dist/admin/pt-BiWuSBcH.js +0 -13
- package/dist/admin/pt-Cr9AL408.mjs +0 -103
- package/dist/admin/sanitize-DP5aeU7V.js +0 -597
- package/dist/admin/sanitize-jjCot5PM.mjs +0 -596
- package/dist/admin/useT-vgY88N_H.mjs +0 -131
|
@@ -0,0 +1,2657 @@
|
|
|
1
|
+
// shared/frameworks/react.mjs
|
|
2
|
+
import * as ReactNamespace from "react";
|
|
3
|
+
|
|
4
|
+
// shared/blocks/active.mjs
|
|
5
|
+
var registry = /* @__PURE__ */ new Map();
|
|
6
|
+
var activeBlock = (type) => typeof type === "string" && registry.has(type) ? registry.get(type) : null;
|
|
7
|
+
|
|
8
|
+
// shared/built-in-marker.mjs
|
|
9
|
+
var isPlainObject = (value) => value !== null && typeof value === "object" && !Array.isArray(value) && (Object.getPrototypeOf(value) === Object.prototype || Object.getPrototypeOf(value) === null);
|
|
10
|
+
var BUILT_IN_MARKER = "_mex";
|
|
11
|
+
var BUILT_IN_MARKER_VERSION = 1;
|
|
12
|
+
var MARKED_BLOCKS = Object.freeze({
|
|
13
|
+
toc: Object.freeze({ keys: Object.freeze(["title", "minLevel", "maxLevel", "style"]), anchor: null }),
|
|
14
|
+
gallery: Object.freeze({
|
|
15
|
+
keys: Object.freeze(["images", "layout", "columns", "caption"]),
|
|
16
|
+
anchor: Object.freeze(["images", "array"])
|
|
17
|
+
}),
|
|
18
|
+
video: Object.freeze({
|
|
19
|
+
keys: Object.freeze(["file", "poster", "title", "caption", "loop", "muted", "tracks"]),
|
|
20
|
+
anchor: Object.freeze(["file", "object"])
|
|
21
|
+
}),
|
|
22
|
+
audio: Object.freeze({
|
|
23
|
+
keys: Object.freeze(["file", "title", "caption", "loop", "tracks"]),
|
|
24
|
+
anchor: Object.freeze(["file", "object"])
|
|
25
|
+
}),
|
|
26
|
+
synced: Object.freeze({ keys: Object.freeze(["ref"]), anchor: Object.freeze(["ref", "string"]) })
|
|
27
|
+
});
|
|
28
|
+
var isBuiltInMarker = (value) => Number.isInteger(value) && /** @type {number} */
|
|
29
|
+
value >= 1;
|
|
30
|
+
var hasBuiltInShape = (shape, data) => {
|
|
31
|
+
if (!Object.keys(data).every((key2) => shape.keys.includes(key2))) return false;
|
|
32
|
+
if (!shape.anchor) return true;
|
|
33
|
+
const [key, kind] = shape.anchor;
|
|
34
|
+
const value = data[key];
|
|
35
|
+
if (kind === "array") return Array.isArray(value);
|
|
36
|
+
if (kind === "object") return isPlainObject(value);
|
|
37
|
+
return typeof value === kind;
|
|
38
|
+
};
|
|
39
|
+
var isMarkedBuiltIn = (type, data) => {
|
|
40
|
+
if (!Object.prototype.hasOwnProperty.call(MARKED_BLOCKS, type) || !isPlainObject(data)) return false;
|
|
41
|
+
if (isBuiltInMarker(data[BUILT_IN_MARKER])) return true;
|
|
42
|
+
return hasBuiltInShape(MARKED_BLOCKS[type], data);
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
// shared/editor-data.mjs
|
|
46
|
+
var EDITOR_DATA_LIMITS = Object.freeze({
|
|
47
|
+
maxBlocks: 5e3,
|
|
48
|
+
maxBytes: 5 * 1024 * 1024,
|
|
49
|
+
maxDepth: 24,
|
|
50
|
+
maxBlockIdLength: 64,
|
|
51
|
+
maxTypeLength: 64
|
|
52
|
+
});
|
|
53
|
+
var FORBIDDEN_KEYS = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
|
|
54
|
+
var BLOCK_ID_PATTERN = /^[A-Za-z0-9_-]{1,64}$/;
|
|
55
|
+
var BLOCK_TYPE_PATTERN = /^[A-Za-z][A-Za-z0-9_-]{0,63}$/;
|
|
56
|
+
var isPlainObject2 = (value) => value !== null && typeof value === "object" && !Array.isArray(value) && (Object.getPrototypeOf(value) === Object.prototype || Object.getPrototypeOf(value) === null);
|
|
57
|
+
var EditorDataError = class extends Error {
|
|
58
|
+
/**
|
|
59
|
+
* @param {string} message - Fixed, non-sensitive message.
|
|
60
|
+
* @param {string} code - Machine-readable reason.
|
|
61
|
+
*/
|
|
62
|
+
constructor(message, code) {
|
|
63
|
+
super(message);
|
|
64
|
+
this.name = "EditorDataError";
|
|
65
|
+
this.code = code;
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
var cloneJsonSafe = (value, depth = 0) => {
|
|
69
|
+
if (depth > EDITOR_DATA_LIMITS.maxDepth) {
|
|
70
|
+
throw new EditorDataError("Editor content is nested too deeply", "TOO_DEEP");
|
|
71
|
+
}
|
|
72
|
+
if (value === null) return null;
|
|
73
|
+
if (Array.isArray(value)) {
|
|
74
|
+
const out = [];
|
|
75
|
+
for (const item of value) {
|
|
76
|
+
const cloned = cloneJsonSafe(item, depth + 1);
|
|
77
|
+
out.push(cloned === void 0 ? null : cloned);
|
|
78
|
+
}
|
|
79
|
+
return out;
|
|
80
|
+
}
|
|
81
|
+
switch (typeof value) {
|
|
82
|
+
case "string":
|
|
83
|
+
case "boolean":
|
|
84
|
+
return value;
|
|
85
|
+
case "number":
|
|
86
|
+
return Number.isFinite(value) ? value : null;
|
|
87
|
+
case "object": {
|
|
88
|
+
const out = {};
|
|
89
|
+
for (const key of Object.keys(value)) {
|
|
90
|
+
if (FORBIDDEN_KEYS.has(key)) continue;
|
|
91
|
+
const cloned = cloneJsonSafe(value[key], depth + 1);
|
|
92
|
+
if (cloned !== void 0) out[key] = cloned;
|
|
93
|
+
}
|
|
94
|
+
return out;
|
|
95
|
+
}
|
|
96
|
+
default:
|
|
97
|
+
return void 0;
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
var tryParseJson = (text) => {
|
|
101
|
+
try {
|
|
102
|
+
return { ok: true, value: JSON.parse(text) };
|
|
103
|
+
} catch {
|
|
104
|
+
return { ok: false };
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
var escapeHtml = (text) => String(text).replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
108
|
+
var hashString = (text) => {
|
|
109
|
+
let hash = 2166136261;
|
|
110
|
+
for (let i = 0; i < text.length; i += 1) {
|
|
111
|
+
hash ^= text.charCodeAt(i);
|
|
112
|
+
hash = Math.imul(hash, 16777619) >>> 0;
|
|
113
|
+
}
|
|
114
|
+
return hash.toString(16).padStart(8, "0");
|
|
115
|
+
};
|
|
116
|
+
var legacyBlockId = (index, type, data) => `mx${hashString(`${index}:${type}:${JSON.stringify(data)}`)}${index}`;
|
|
117
|
+
var textToBlocks = (text) => {
|
|
118
|
+
const trimmed = text.trim();
|
|
119
|
+
if (!trimmed) return [];
|
|
120
|
+
const looksLikeHtml = /<\/?[a-z][^>]{0,200}>/i.test(trimmed.slice(0, 2e3));
|
|
121
|
+
if (looksLikeHtml) {
|
|
122
|
+
return [{ type: "paragraph", data: { text: trimmed } }];
|
|
123
|
+
}
|
|
124
|
+
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>") } }));
|
|
125
|
+
};
|
|
126
|
+
var unwrapValue = (value) => {
|
|
127
|
+
let current = value;
|
|
128
|
+
let legacy = false;
|
|
129
|
+
for (let i = 0; i < 3 && typeof current === "string"; i += 1) {
|
|
130
|
+
const text = current.trim();
|
|
131
|
+
if (!text) return { candidate: null, legacy: true };
|
|
132
|
+
if (text.startsWith("{") || text.startsWith("[") || text.startsWith('"')) {
|
|
133
|
+
const parsed = tryParseJson(text);
|
|
134
|
+
if (parsed.ok) {
|
|
135
|
+
current = parsed.value;
|
|
136
|
+
legacy = true;
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
return { candidate: { blocks: textToBlocks(text) }, legacy: true };
|
|
141
|
+
}
|
|
142
|
+
if (Array.isArray(current)) {
|
|
143
|
+
return { candidate: { blocks: current }, legacy: true };
|
|
144
|
+
}
|
|
145
|
+
return { candidate: current, legacy };
|
|
146
|
+
};
|
|
147
|
+
var normalizeEditorData = (value) => {
|
|
148
|
+
if (value === null || value === void 0) return null;
|
|
149
|
+
if (typeof value === "string" && value.length > EDITOR_DATA_LIMITS.maxBytes) {
|
|
150
|
+
throw new EditorDataError("Editor content exceeds the size limit", "TOO_LARGE");
|
|
151
|
+
}
|
|
152
|
+
const { candidate } = unwrapValue(value);
|
|
153
|
+
if (candidate === null || candidate === void 0) return null;
|
|
154
|
+
if (!isPlainObject2(candidate)) {
|
|
155
|
+
throw new EditorDataError("Editor content must be an Editor.js object", "INVALID_SHAPE");
|
|
156
|
+
}
|
|
157
|
+
const clean = cloneJsonSafe(candidate);
|
|
158
|
+
const rawBlocks = Array.isArray(clean.blocks) ? clean.blocks : [];
|
|
159
|
+
if (rawBlocks.length > EDITOR_DATA_LIMITS.maxBlocks) {
|
|
160
|
+
throw new EditorDataError("Editor content has too many blocks", "TOO_MANY_BLOCKS");
|
|
161
|
+
}
|
|
162
|
+
const seen = /* @__PURE__ */ new Set();
|
|
163
|
+
const blocks = [];
|
|
164
|
+
rawBlocks.forEach((block, index) => {
|
|
165
|
+
if (!isPlainObject2(block)) return;
|
|
166
|
+
const type = typeof block.type === "string" ? block.type.trim() : "";
|
|
167
|
+
if (!BLOCK_TYPE_PATTERN.test(type)) return;
|
|
168
|
+
const data = isPlainObject2(block.data) ? block.data : {};
|
|
169
|
+
let id = typeof block.id === "string" && BLOCK_ID_PATTERN.test(block.id) ? block.id : "";
|
|
170
|
+
if (!id || seen.has(id)) id = legacyBlockId(index, type, data);
|
|
171
|
+
while (seen.has(id)) id = `${id}x`;
|
|
172
|
+
seen.add(id);
|
|
173
|
+
const normalized = { id, type, data };
|
|
174
|
+
if (isPlainObject2(block.tunes) && Object.keys(block.tunes).length > 0) normalized.tunes = block.tunes;
|
|
175
|
+
blocks.push(normalized);
|
|
176
|
+
});
|
|
177
|
+
const time = Number.isFinite(clean.time) && clean.time > 0 ? Math.floor(clean.time) : 0;
|
|
178
|
+
const version = typeof clean.version === "string" && clean.version.length <= 32 ? clean.version : "2.31.7";
|
|
179
|
+
const result = { time, blocks, version };
|
|
180
|
+
const size = byteLength(JSON.stringify(result));
|
|
181
|
+
if (size > EDITOR_DATA_LIMITS.maxBytes) {
|
|
182
|
+
throw new EditorDataError("Editor content exceeds the size limit", "TOO_LARGE");
|
|
183
|
+
}
|
|
184
|
+
return result;
|
|
185
|
+
};
|
|
186
|
+
var normalizeEditorDataSafe = (value) => {
|
|
187
|
+
try {
|
|
188
|
+
return normalizeEditorData(value);
|
|
189
|
+
} catch {
|
|
190
|
+
return null;
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
var byteLength = (text) => {
|
|
194
|
+
let bytes = 0;
|
|
195
|
+
for (let i = 0; i < text.length; i += 1) {
|
|
196
|
+
const code = text.charCodeAt(i);
|
|
197
|
+
if (code < 128) bytes += 1;
|
|
198
|
+
else if (code < 2048) bytes += 2;
|
|
199
|
+
else if (code >= 55296 && code <= 56319) {
|
|
200
|
+
bytes += 4;
|
|
201
|
+
i += 1;
|
|
202
|
+
} else bytes += 3;
|
|
203
|
+
}
|
|
204
|
+
return bytes;
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
// shared/sanitize-policy.mjs
|
|
208
|
+
var INLINE_TAGS = Object.freeze([
|
|
209
|
+
"b",
|
|
210
|
+
"strong",
|
|
211
|
+
"i",
|
|
212
|
+
"em",
|
|
213
|
+
"u",
|
|
214
|
+
"s",
|
|
215
|
+
"mark",
|
|
216
|
+
"code",
|
|
217
|
+
"a",
|
|
218
|
+
"br",
|
|
219
|
+
"span",
|
|
220
|
+
"sub",
|
|
221
|
+
"sup"
|
|
222
|
+
]);
|
|
223
|
+
var INTERNAL_LINK_ATTRIBUTES = Object.freeze([
|
|
224
|
+
"data-mex-uid",
|
|
225
|
+
"data-mex-document-id",
|
|
226
|
+
"data-mex-locale",
|
|
227
|
+
"data-mex-mention"
|
|
228
|
+
]);
|
|
229
|
+
var INTERNAL_LINK_RULES = Object.freeze({
|
|
230
|
+
"data-mex-uid": /^api::[a-z0-9-]{1,60}\.[a-z0-9-]{1,60}$/,
|
|
231
|
+
"data-mex-document-id": /^[a-z0-9]{1,64}$/,
|
|
232
|
+
"data-mex-locale": /^[A-Za-z]{2,8}(?:-[A-Za-z0-9]{1,8}){0,3}$/,
|
|
233
|
+
// Boolean flag: written as "true"; an empty value (`<a data-mex-mention>`) is accepted and normalised.
|
|
234
|
+
"data-mex-mention": /^(?:|true)$/
|
|
235
|
+
});
|
|
236
|
+
var cleanInternalLinkAttributes = (attribs) => {
|
|
237
|
+
const out = {};
|
|
238
|
+
if (!attribs || typeof attribs !== "object") return out;
|
|
239
|
+
for (const name of INTERNAL_LINK_ATTRIBUTES) {
|
|
240
|
+
const value = attribs[name];
|
|
241
|
+
if (typeof value === "string" && INTERNAL_LINK_RULES[name].test(value)) out[name] = value;
|
|
242
|
+
}
|
|
243
|
+
if (!out["data-mex-uid"] || !out["data-mex-document-id"]) return {};
|
|
244
|
+
if (out["data-mex-mention"] !== void 0) out["data-mex-mention"] = "true";
|
|
245
|
+
return out;
|
|
246
|
+
};
|
|
247
|
+
var isMentionLink = (attrs) => Boolean(
|
|
248
|
+
attrs && attrs["data-mex-mention"] === "true" && attrs["data-mex-uid"] && attrs["data-mex-document-id"]
|
|
249
|
+
);
|
|
250
|
+
var INLINE_ATTRIBUTES = Object.freeze({
|
|
251
|
+
a: ["href", "target", "rel", "title", ...INTERNAL_LINK_ATTRIBUTES],
|
|
252
|
+
span: ["class", "data-tooltip"],
|
|
253
|
+
mark: ["class"],
|
|
254
|
+
u: ["class"],
|
|
255
|
+
s: ["class"],
|
|
256
|
+
code: ["class"]
|
|
257
|
+
});
|
|
258
|
+
var INLINE_CLASSES = Object.freeze({
|
|
259
|
+
span: ["cdx-tooltip"],
|
|
260
|
+
mark: ["cdx-marker"],
|
|
261
|
+
u: ["cdx-underline"],
|
|
262
|
+
s: ["cdx-strikethrough", "cdx-strikethroughs"],
|
|
263
|
+
code: ["inline-code"]
|
|
264
|
+
});
|
|
265
|
+
var LINK_SCHEMES = Object.freeze(["http", "https", "mailto", "tel"]);
|
|
266
|
+
var MAX_URL_LENGTH = 2048;
|
|
267
|
+
var TARGETS = /* @__PURE__ */ new Set(["_blank", "_self", "_parent", "_top"]);
|
|
268
|
+
var sanitizeUrl = (value, options = {}) => {
|
|
269
|
+
const schemes = options.schemes || LINK_SCHEMES;
|
|
270
|
+
const allowRelative = options.allowRelative !== false;
|
|
271
|
+
if (typeof value !== "string") return "";
|
|
272
|
+
const url = value.trim();
|
|
273
|
+
if (!url || url.length > MAX_URL_LENGTH) return "";
|
|
274
|
+
if (/[\u0000-\u001f\u007f\s]/.test(url) && !/^(mailto|tel):/i.test(url)) return "";
|
|
275
|
+
if (url.startsWith("//") || url.startsWith("\\")) return "";
|
|
276
|
+
const scheme = /^([a-zA-Z][a-zA-Z0-9+.-]{0,20}):/.exec(url);
|
|
277
|
+
if (!scheme) {
|
|
278
|
+
return allowRelative && /^[/#?.]/.test(url) ? url : "";
|
|
279
|
+
}
|
|
280
|
+
if (!schemes.includes(scheme[1].toLowerCase())) return "";
|
|
281
|
+
if (scheme[1].toLowerCase().startsWith("http")) {
|
|
282
|
+
try {
|
|
283
|
+
const parsed = new URL(url);
|
|
284
|
+
if (parsed.username || parsed.password) return "";
|
|
285
|
+
} catch {
|
|
286
|
+
return "";
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
return url;
|
|
290
|
+
};
|
|
291
|
+
var plain = (value, max = 1e5) => typeof value === "string" ? value.slice(0, max) : "";
|
|
292
|
+
var oneOf = (value, allowed, fallback) => typeof value === "string" && allowed.includes(value) ? value : fallback;
|
|
293
|
+
var int = (value, min, max, fallback) => {
|
|
294
|
+
const number = typeof value === "string" ? Number(value) : value;
|
|
295
|
+
return Number.isInteger(number) && number >= min && number <= max ? number : fallback;
|
|
296
|
+
};
|
|
297
|
+
var bool = (value) => value === true;
|
|
298
|
+
var MAX_GALLERY_IMAGES = 50;
|
|
299
|
+
var MAX_MEDIA_TRACKS = 8;
|
|
300
|
+
var TRACK_KINDS = Object.freeze(["captions", "subtitles", "descriptions", "chapters"]);
|
|
301
|
+
var SRCLANG = /^[A-Za-z]{2,3}(?:-[A-Za-z0-9]{1,8}){0,3}$/;
|
|
302
|
+
var cleanFocalPoint = (value) => {
|
|
303
|
+
if (!isPlainObject2(value)) return void 0;
|
|
304
|
+
const { x, y } = value;
|
|
305
|
+
if (![x, y].every((n) => typeof n === "number" && Number.isFinite(n) && n >= 0 && n <= 1)) return void 0;
|
|
306
|
+
return { x: Math.round(x * 100) / 100, y: Math.round(y * 100) / 100 };
|
|
307
|
+
};
|
|
308
|
+
var cleanMediaFile = (value, kind = {}) => {
|
|
309
|
+
const file = isPlainObject2(value) ? value : {};
|
|
310
|
+
const out = { url: sanitizeUrl(file.url, { schemes: ["http", "https"] }) };
|
|
311
|
+
for (const key of ["mime", ...kind.image ? ["alt"] : [], "name", "hash", "ext"])
|
|
312
|
+
if (typeof file[key] === "string") out[key] = plain(file[key], 500);
|
|
313
|
+
for (const key of ["width", "height", "size"]) if (Number.isFinite(file[key])) out[key] = file[key];
|
|
314
|
+
if (kind.image && isPlainObject2(file.formats))
|
|
315
|
+
out.formats = generic(file.formats, (s) => plain(s, 2048), 0, "formats");
|
|
316
|
+
if (file.id !== void 0 && (Number.isInteger(file.id) || typeof file.id === "string")) out.id = file.id;
|
|
317
|
+
if (typeof file.documentId === "string") out.documentId = plain(file.documentId, 64);
|
|
318
|
+
const mime = typeof out.mime === "string" ? out.mime.toLowerCase() : "";
|
|
319
|
+
if (kind.mimePrefix && mime && !mime.startsWith(kind.mimePrefix)) out.url = "";
|
|
320
|
+
if (kind.vtt && out.url) {
|
|
321
|
+
const path = out.url.split(/[?#]/)[0].toLowerCase();
|
|
322
|
+
const ext = typeof out.ext === "string" ? out.ext.toLowerCase() : "";
|
|
323
|
+
if (mime !== "text/vtt" && ext !== ".vtt" && !path.endsWith(".vtt")) out.url = "";
|
|
324
|
+
}
|
|
325
|
+
return out;
|
|
326
|
+
};
|
|
327
|
+
var mediaTracks = (tracks) => {
|
|
328
|
+
if (!Array.isArray(tracks)) return [];
|
|
329
|
+
const out = [];
|
|
330
|
+
let hasDefault = false;
|
|
331
|
+
for (const track of tracks.slice(0, MAX_MEDIA_TRACKS)) {
|
|
332
|
+
if (!isPlainObject2(track)) continue;
|
|
333
|
+
const file = cleanMediaFile(track.file, { vtt: true });
|
|
334
|
+
if (!file.url) continue;
|
|
335
|
+
const clean = {
|
|
336
|
+
file,
|
|
337
|
+
kind: oneOf(track.kind, TRACK_KINDS, "captions"),
|
|
338
|
+
srclang: typeof track.srclang === "string" && SRCLANG.test(track.srclang) ? track.srclang : "",
|
|
339
|
+
label: plain(track.label, 100)
|
|
340
|
+
};
|
|
341
|
+
if (track.default === true && !hasDefault) {
|
|
342
|
+
clean.default = true;
|
|
343
|
+
hasDefault = true;
|
|
344
|
+
}
|
|
345
|
+
out.push(clean);
|
|
346
|
+
}
|
|
347
|
+
return out;
|
|
348
|
+
};
|
|
349
|
+
var generic = (value, inline, depth = 0, key = "") => {
|
|
350
|
+
if (depth > 20) return null;
|
|
351
|
+
if (typeof value === "string") {
|
|
352
|
+
if (/^(url|href|link|src|photo|source|embed)$/i.test(key)) return sanitizeUrl(value);
|
|
353
|
+
return inline(value);
|
|
354
|
+
}
|
|
355
|
+
if (Array.isArray(value)) return value.map((item) => generic(item, inline, depth + 1, key));
|
|
356
|
+
if (isPlainObject2(value)) {
|
|
357
|
+
const out = {};
|
|
358
|
+
for (const [childKey, child] of Object.entries(value))
|
|
359
|
+
out[childKey] = generic(child, inline, depth + 1, childKey);
|
|
360
|
+
return out;
|
|
361
|
+
}
|
|
362
|
+
return value;
|
|
363
|
+
};
|
|
364
|
+
var listItems = (items, inline, depth = 0) => {
|
|
365
|
+
if (!Array.isArray(items) || depth > 12) return [];
|
|
366
|
+
return items.map((item) => {
|
|
367
|
+
if (typeof item === "string") return inline(item);
|
|
368
|
+
if (!isPlainObject2(item)) return { content: "", items: [] };
|
|
369
|
+
const out = { content: inline(typeof item.content === "string" ? item.content : plain(item.text)) };
|
|
370
|
+
if (isPlainObject2(item.meta)) {
|
|
371
|
+
const meta = {};
|
|
372
|
+
if (typeof item.meta.checked === "boolean") meta.checked = item.meta.checked;
|
|
373
|
+
const start = int(item.meta.start, 0, 1e5, void 0);
|
|
374
|
+
if (start !== void 0) meta.start = start;
|
|
375
|
+
if (typeof item.meta.counterType === "string") {
|
|
376
|
+
meta.counterType = oneOf(
|
|
377
|
+
item.meta.counterType,
|
|
378
|
+
["numeric", "lower-roman", "upper-roman", "lower-alpha", "upper-alpha"],
|
|
379
|
+
"numeric"
|
|
380
|
+
);
|
|
381
|
+
}
|
|
382
|
+
out.meta = meta;
|
|
383
|
+
}
|
|
384
|
+
out.items = listItems(item.items, inline, depth + 1);
|
|
385
|
+
return out;
|
|
386
|
+
});
|
|
387
|
+
};
|
|
388
|
+
var BLOCK_POLICIES = {
|
|
389
|
+
paragraph: (d, inline) => ({ text: inline(d.text) }),
|
|
390
|
+
header: (d, inline) => ({ text: inline(d.text), level: int(d.level, 1, 6, 2) }),
|
|
391
|
+
quote: (d, inline) => ({
|
|
392
|
+
text: inline(d.text),
|
|
393
|
+
caption: inline(d.caption),
|
|
394
|
+
alignment: oneOf(d.alignment, ["left", "center"], "left")
|
|
395
|
+
}),
|
|
396
|
+
list: (d, inline) => {
|
|
397
|
+
const out = {
|
|
398
|
+
style: oneOf(d.style, ["ordered", "unordered", "checklist"], "unordered"),
|
|
399
|
+
items: listItems(d.items, inline)
|
|
400
|
+
};
|
|
401
|
+
if (isPlainObject2(d.meta)) {
|
|
402
|
+
const meta = {};
|
|
403
|
+
const start = int(d.meta.start, 0, 1e5, void 0);
|
|
404
|
+
if (start !== void 0) meta.start = start;
|
|
405
|
+
if (typeof d.meta.counterType === "string") {
|
|
406
|
+
meta.counterType = oneOf(
|
|
407
|
+
d.meta.counterType,
|
|
408
|
+
["numeric", "lower-roman", "upper-roman", "lower-alpha", "upper-alpha"],
|
|
409
|
+
"numeric"
|
|
410
|
+
);
|
|
411
|
+
}
|
|
412
|
+
out.meta = meta;
|
|
413
|
+
}
|
|
414
|
+
return out;
|
|
415
|
+
},
|
|
416
|
+
checklist: (d, inline) => ({
|
|
417
|
+
items: Array.isArray(d.items) ? d.items.filter(isPlainObject2).map((item) => ({ text: inline(item.text), checked: bool(item.checked) })) : []
|
|
418
|
+
}),
|
|
419
|
+
warning: (d, inline) => ({ title: inline(d.title), message: inline(d.message) }),
|
|
420
|
+
alert: (d, inline) => ({
|
|
421
|
+
type: oneOf(
|
|
422
|
+
d.type,
|
|
423
|
+
["primary", "secondary", "info", "success", "warning", "danger", "light", "dark"],
|
|
424
|
+
"info"
|
|
425
|
+
),
|
|
426
|
+
align: oneOf(d.align, ["left", "center", "right"], "left"),
|
|
427
|
+
message: inline(d.message)
|
|
428
|
+
}),
|
|
429
|
+
toggle: (d, inline) => ({
|
|
430
|
+
text: inline(d.text),
|
|
431
|
+
status: oneOf(d.status, ["open", "closed"], "open"),
|
|
432
|
+
fk: typeof d.fk === "string" ? d.fk.slice(0, 64) : void 0,
|
|
433
|
+
items: int(d.items, 0, 5e3, 0)
|
|
434
|
+
}),
|
|
435
|
+
code: (d) => ({ code: plain(d.code, 5e5) }),
|
|
436
|
+
codeFlask: (d) => {
|
|
437
|
+
const out = {
|
|
438
|
+
code: plain(d.code, 5e5),
|
|
439
|
+
language: typeof d.language === "string" && /^[a-z0-9+#-]{1,32}$/i.test(d.language) ? d.language : "plaintext"
|
|
440
|
+
};
|
|
441
|
+
if (typeof d.showlinenumbers === "boolean") out.showlinenumbers = d.showlinenumbers;
|
|
442
|
+
return out;
|
|
443
|
+
},
|
|
444
|
+
raw: (d, _inline, ctx) => {
|
|
445
|
+
const html = plain(d.html, 5e5);
|
|
446
|
+
if (ctx.rawHtml === "allow") return { html };
|
|
447
|
+
if (ctx.rawHtml === "disable") return { html: "" };
|
|
448
|
+
return { html: ctx.rawSanitizer(html) };
|
|
449
|
+
},
|
|
450
|
+
table: (d, inline) => ({
|
|
451
|
+
withHeadings: bool(d.withHeadings),
|
|
452
|
+
stretched: bool(d.stretched),
|
|
453
|
+
content: Array.isArray(d.content) ? d.content.slice(0, 500).map((row) => Array.isArray(row) ? row.slice(0, 100).map((cell) => inline(cell)) : []) : []
|
|
454
|
+
}),
|
|
455
|
+
image: (d, inline) => {
|
|
456
|
+
const file = isPlainObject2(d.file) ? d.file : {};
|
|
457
|
+
const cleanFile = { url: sanitizeUrl(file.url, { schemes: ["http", "https"] }) };
|
|
458
|
+
for (const key of ["mime", "alt", "name", "hash", "ext"])
|
|
459
|
+
if (typeof file[key] === "string") cleanFile[key] = plain(file[key], 500);
|
|
460
|
+
for (const key of ["width", "height", "size"]) if (Number.isFinite(file[key])) cleanFile[key] = file[key];
|
|
461
|
+
if (isPlainObject2(file.formats))
|
|
462
|
+
cleanFile.formats = generic(file.formats, (s) => plain(s, 2048), 0, "formats");
|
|
463
|
+
if (file.id !== void 0 && (Number.isInteger(file.id) || typeof file.id === "string"))
|
|
464
|
+
cleanFile.id = file.id;
|
|
465
|
+
if (typeof file.documentId === "string") cleanFile.documentId = plain(file.documentId, 64);
|
|
466
|
+
const out = {
|
|
467
|
+
file: cleanFile,
|
|
468
|
+
caption: inline(d.caption),
|
|
469
|
+
withBorder: bool(d.withBorder),
|
|
470
|
+
withBackground: bool(d.withBackground),
|
|
471
|
+
stretched: bool(d.stretched)
|
|
472
|
+
};
|
|
473
|
+
if (d.decorative === true) out.decorative = true;
|
|
474
|
+
const focalPoint = cleanFocalPoint(d.focalPoint);
|
|
475
|
+
if (focalPoint) out.focalPoint = focalPoint;
|
|
476
|
+
return out;
|
|
477
|
+
},
|
|
478
|
+
simpleImage: (d, inline) => {
|
|
479
|
+
const out = {
|
|
480
|
+
url: sanitizeUrl(d.url, { schemes: ["http", "https"] }),
|
|
481
|
+
caption: inline(d.caption),
|
|
482
|
+
withBorder: bool(d.withBorder),
|
|
483
|
+
withBackground: bool(d.withBackground),
|
|
484
|
+
stretched: bool(d.stretched)
|
|
485
|
+
};
|
|
486
|
+
if (typeof d.alt === "string") out.alt = plain(d.alt, 500);
|
|
487
|
+
if (d.decorative === true) out.decorative = true;
|
|
488
|
+
return out;
|
|
489
|
+
},
|
|
490
|
+
gallery: (d, inline) => {
|
|
491
|
+
const images = [];
|
|
492
|
+
for (const item of Array.isArray(d.images) ? d.images : []) {
|
|
493
|
+
if (images.length >= MAX_GALLERY_IMAGES) break;
|
|
494
|
+
if (!isPlainObject2(item)) continue;
|
|
495
|
+
const file = cleanMediaFile(item.file, { image: true, mimePrefix: "image/" });
|
|
496
|
+
if (!file.url) continue;
|
|
497
|
+
const image = { file, caption: inline(item.caption) };
|
|
498
|
+
if (item.decorative === true) image.decorative = true;
|
|
499
|
+
const focalPoint = cleanFocalPoint(item.focalPoint);
|
|
500
|
+
if (focalPoint) image.focalPoint = focalPoint;
|
|
501
|
+
images.push(image);
|
|
502
|
+
}
|
|
503
|
+
return {
|
|
504
|
+
images,
|
|
505
|
+
layout: oneOf(d.layout, ["grid", "carousel"], "grid"),
|
|
506
|
+
columns: int(d.columns, 1, 6, 3),
|
|
507
|
+
caption: inline(d.caption),
|
|
508
|
+
_mex: BUILT_IN_MARKER_VERSION
|
|
509
|
+
};
|
|
510
|
+
},
|
|
511
|
+
video: (d, inline) => {
|
|
512
|
+
const out = {
|
|
513
|
+
file: cleanMediaFile(d.file, { mimePrefix: "video/" }),
|
|
514
|
+
title: plain(d.title, 200),
|
|
515
|
+
caption: inline(d.caption),
|
|
516
|
+
loop: bool(d.loop),
|
|
517
|
+
muted: bool(d.muted),
|
|
518
|
+
tracks: mediaTracks(d.tracks)
|
|
519
|
+
};
|
|
520
|
+
if (isPlainObject2(d.poster)) {
|
|
521
|
+
const poster = cleanMediaFile(d.poster, { image: true, mimePrefix: "image/" });
|
|
522
|
+
if (poster.url) out.poster = poster;
|
|
523
|
+
}
|
|
524
|
+
out._mex = BUILT_IN_MARKER_VERSION;
|
|
525
|
+
return out;
|
|
526
|
+
},
|
|
527
|
+
audio: (d, inline) => ({
|
|
528
|
+
file: cleanMediaFile(d.file, { mimePrefix: "audio/" }),
|
|
529
|
+
title: plain(d.title, 200),
|
|
530
|
+
caption: inline(d.caption),
|
|
531
|
+
loop: bool(d.loop),
|
|
532
|
+
tracks: mediaTracks(d.tracks),
|
|
533
|
+
_mex: BUILT_IN_MARKER_VERSION
|
|
534
|
+
}),
|
|
535
|
+
linkTool: (d) => {
|
|
536
|
+
const meta = isPlainObject2(d.meta) ? d.meta : {};
|
|
537
|
+
const image = isPlainObject2(meta.image) ? { url: sanitizeUrl(meta.image.url, { schemes: ["http", "https"] }) } : void 0;
|
|
538
|
+
const cleanMeta = { title: plain(meta.title, 500), description: plain(meta.description, 2e3) };
|
|
539
|
+
if (typeof meta.site_name === "string") cleanMeta.site_name = plain(meta.site_name, 200);
|
|
540
|
+
if (image && image.url) cleanMeta.image = image;
|
|
541
|
+
return { link: sanitizeUrl(d.link, { schemes: ["http", "https"] }), meta: cleanMeta };
|
|
542
|
+
},
|
|
543
|
+
attaches: (d) => {
|
|
544
|
+
const file = isPlainObject2(d.file) ? d.file : {};
|
|
545
|
+
const cleanFile = { url: sanitizeUrl(file.url, { schemes: ["http", "https"] }) };
|
|
546
|
+
if (typeof file.name === "string") cleanFile.name = plain(file.name, 255);
|
|
547
|
+
if (typeof file.extension === "string") cleanFile.extension = plain(file.extension, 16);
|
|
548
|
+
if (Number.isFinite(file.size)) cleanFile.size = file.size;
|
|
549
|
+
if (typeof file.title === "string") cleanFile.title = plain(file.title, 255);
|
|
550
|
+
return { file: cleanFile, title: plain(d.title, 255) };
|
|
551
|
+
},
|
|
552
|
+
embed: (d, inline) => ({
|
|
553
|
+
service: typeof d.service === "string" && /^[a-z0-9_-]{1,40}$/i.test(d.service) ? d.service : "",
|
|
554
|
+
source: sanitizeUrl(d.source, { schemes: ["https", "http"], allowRelative: false }),
|
|
555
|
+
embed: sanitizeUrl(d.embed, { schemes: ["https"], allowRelative: false }),
|
|
556
|
+
width: int(d.width, 1, 1e4, void 0),
|
|
557
|
+
height: int(d.height, 1, 1e4, void 0),
|
|
558
|
+
caption: inline(d.caption)
|
|
559
|
+
}),
|
|
560
|
+
personality: (d) => ({
|
|
561
|
+
name: plain(d.name, 500),
|
|
562
|
+
description: plain(d.description, 2e3),
|
|
563
|
+
link: sanitizeUrl(d.link, { schemes: ["http", "https", "mailto"] }),
|
|
564
|
+
photo: sanitizeUrl(d.photo, { schemes: ["http", "https"] })
|
|
565
|
+
}),
|
|
566
|
+
button: (d) => ({
|
|
567
|
+
text: plain(d.text, 200),
|
|
568
|
+
link: sanitizeUrl(d.link),
|
|
569
|
+
style: oneOf(d.style, ["primary", "secondary", "outline", "ghost", "danger", "success"], "primary"),
|
|
570
|
+
openInNewTab: bool(d.openInNewTab)
|
|
571
|
+
}),
|
|
572
|
+
delimiter: () => ({}),
|
|
573
|
+
// Synced block (2.3): only the reference to its source is stored; an invalid reference becomes ''.
|
|
574
|
+
synced: (d) => ({
|
|
575
|
+
ref: typeof d.ref === "string" && /^[a-z0-9]{1,64}$/.test(d.ref) ? d.ref : "",
|
|
576
|
+
_mex: BUILT_IN_MARKER_VERSION
|
|
577
|
+
}),
|
|
578
|
+
toc: (d) => {
|
|
579
|
+
const minLevel = int(d.minLevel, 1, 6, 2);
|
|
580
|
+
const maxLevel = int(d.maxLevel, 1, 6, 4);
|
|
581
|
+
return {
|
|
582
|
+
title: plain(d.title, 200),
|
|
583
|
+
minLevel: Math.min(minLevel, maxLevel),
|
|
584
|
+
maxLevel: Math.max(minLevel, maxLevel),
|
|
585
|
+
style: oneOf(d.style, ["ordered", "unordered"], "unordered"),
|
|
586
|
+
_mex: BUILT_IN_MARKER_VERSION
|
|
587
|
+
};
|
|
588
|
+
}
|
|
589
|
+
};
|
|
590
|
+
var isBuiltInBlock = (block) => {
|
|
591
|
+
if (!block || typeof block.type !== "string") return false;
|
|
592
|
+
if (!Object.prototype.hasOwnProperty.call(BLOCK_POLICIES, block.type)) return false;
|
|
593
|
+
if (!Object.prototype.hasOwnProperty.call(MARKED_BLOCKS, block.type)) return true;
|
|
594
|
+
return isMarkedBuiltIn(block.type, block.data);
|
|
595
|
+
};
|
|
596
|
+
var sanitizeTunes = (tunes) => {
|
|
597
|
+
if (!isPlainObject2(tunes)) return void 0;
|
|
598
|
+
const out = {};
|
|
599
|
+
if (isPlainObject2(tunes.alignmentTune)) {
|
|
600
|
+
out.alignmentTune = {
|
|
601
|
+
alignment: oneOf(tunes.alignmentTune.alignment, ["left", "center", "right", "justify"], "left")
|
|
602
|
+
};
|
|
603
|
+
}
|
|
604
|
+
if (typeof tunes.textVariant === "string") {
|
|
605
|
+
out.textVariant = oneOf(tunes.textVariant, ["", "call-out", "citation", "details"], "");
|
|
606
|
+
}
|
|
607
|
+
if (isPlainObject2(tunes.indentTune)) {
|
|
608
|
+
out.indentTune = { indentLevel: int(tunes.indentTune.indentLevel, 0, 10, 0) };
|
|
609
|
+
}
|
|
610
|
+
return Object.keys(out).length ? out : void 0;
|
|
611
|
+
};
|
|
612
|
+
var registeredBlockOf = (block, explicit) => {
|
|
613
|
+
if (!block || typeof block.type !== "string" || isBuiltInBlock(block)) return null;
|
|
614
|
+
if (explicit instanceof Map) return explicit.get(block.type) || null;
|
|
615
|
+
return activeBlock(block.type);
|
|
616
|
+
};
|
|
617
|
+
var sanitizeTarget = (value) => typeof value === "string" && TARGETS.has(value) ? value : null;
|
|
618
|
+
|
|
619
|
+
// shared/render/nodes.mjs
|
|
620
|
+
var VOID_TAGS = /* @__PURE__ */ new Set([
|
|
621
|
+
"area",
|
|
622
|
+
"base",
|
|
623
|
+
"br",
|
|
624
|
+
"col",
|
|
625
|
+
"embed",
|
|
626
|
+
"hr",
|
|
627
|
+
"img",
|
|
628
|
+
"input",
|
|
629
|
+
"link",
|
|
630
|
+
"meta",
|
|
631
|
+
"source",
|
|
632
|
+
"track",
|
|
633
|
+
"wbr"
|
|
634
|
+
]);
|
|
635
|
+
var escapeHtml2 = (text) => String(text ?? "").replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
636
|
+
var TAG_NAME = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;
|
|
637
|
+
var ATTRIBUTE_NAME = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;
|
|
638
|
+
var isSafeAttributeName = (name) => ATTRIBUTE_NAME.test(name) && !name.startsWith("on") && name !== "style" && name !== "srcdoc";
|
|
639
|
+
var textNode = (value) => ({ type: "text", value: String(value ?? "") });
|
|
640
|
+
var el = (tag, attrs, children) => {
|
|
641
|
+
const clean = {};
|
|
642
|
+
for (const [name, value] of Object.entries(attrs || {})) {
|
|
643
|
+
if (value === void 0 || value === null || value === false) continue;
|
|
644
|
+
if (value === "" && name !== "alt") continue;
|
|
645
|
+
clean[name] = value === true ? true : String(value);
|
|
646
|
+
}
|
|
647
|
+
return { type: "element", tag, attrs: clean, children: toNodes(children) };
|
|
648
|
+
};
|
|
649
|
+
var toNodes = (children) => {
|
|
650
|
+
const out = [];
|
|
651
|
+
const visit = (child) => {
|
|
652
|
+
if (child === void 0 || child === null || child === false || child === "") return;
|
|
653
|
+
if (Array.isArray(child)) {
|
|
654
|
+
for (const item of child) visit(item);
|
|
655
|
+
} else if (typeof child === "string" || typeof child === "number") {
|
|
656
|
+
out.push(textNode(child));
|
|
657
|
+
} else if (typeof child === "object") {
|
|
658
|
+
out.push(
|
|
659
|
+
/** @type {RenderNode} */
|
|
660
|
+
child
|
|
661
|
+
);
|
|
662
|
+
}
|
|
663
|
+
};
|
|
664
|
+
visit(children);
|
|
665
|
+
return out;
|
|
666
|
+
};
|
|
667
|
+
var STYLE_PROPERTIES = Object.freeze(["object-position"]);
|
|
668
|
+
var STYLE_VALUE = /^[0-9]{1,3}(?:\.[0-9]{1,2})?% [0-9]{1,3}(?:\.[0-9]{1,2})?%$/;
|
|
669
|
+
var safeStyle = (style) => style && typeof style === "object" ? Object.entries(style).filter(
|
|
670
|
+
([name, value]) => STYLE_PROPERTIES.includes(name) && typeof value === "string" && STYLE_VALUE.test(value)
|
|
671
|
+
) : [];
|
|
672
|
+
var serializeNodes = (nodes) => {
|
|
673
|
+
let out = "";
|
|
674
|
+
for (const node of nodes) {
|
|
675
|
+
if (!node || typeof node !== "object") continue;
|
|
676
|
+
if (node.type === "text") out += escapeHtml2(node.value);
|
|
677
|
+
else if (node.type === "raw") out += node.html;
|
|
678
|
+
else if (node.type === "block") out += serializeNodes(node.children);
|
|
679
|
+
else if (node.type === "element") {
|
|
680
|
+
let attributes = "";
|
|
681
|
+
for (const [name, value] of Object.entries(node.attrs)) {
|
|
682
|
+
attributes += value === true ? ` ${name}` : ` ${name}="${escapeHtml2(value)}"`;
|
|
683
|
+
}
|
|
684
|
+
const style = safeStyle(node.style);
|
|
685
|
+
if (style.length)
|
|
686
|
+
attributes += ` style="${escapeHtml2(style.map(([name, value]) => `${name}:${value}`).join(";"))}"`;
|
|
687
|
+
out += VOID_TAGS.has(node.tag) ? `<${node.tag}${attributes}>` : `<${node.tag}${attributes}>${serializeNodes(node.children)}</${node.tag}>`;
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
return out;
|
|
691
|
+
};
|
|
692
|
+
var nodesTextContent = (nodes) => {
|
|
693
|
+
let out = "";
|
|
694
|
+
for (const node of nodes) {
|
|
695
|
+
if (node.type === "text") out += node.value;
|
|
696
|
+
else if (node.type === "element" || node.type === "block") out += nodesTextContent(node.children);
|
|
697
|
+
}
|
|
698
|
+
return out;
|
|
699
|
+
};
|
|
700
|
+
|
|
701
|
+
// shared/render/inline.mjs
|
|
702
|
+
var DROP_WITH_CONTENT = /* @__PURE__ */ new Set([
|
|
703
|
+
"script",
|
|
704
|
+
"style",
|
|
705
|
+
"textarea",
|
|
706
|
+
"title",
|
|
707
|
+
"xmp",
|
|
708
|
+
"noscript",
|
|
709
|
+
"noembed",
|
|
710
|
+
"noframes",
|
|
711
|
+
"template",
|
|
712
|
+
"iframe",
|
|
713
|
+
"object",
|
|
714
|
+
"embed",
|
|
715
|
+
"svg",
|
|
716
|
+
"math",
|
|
717
|
+
"select",
|
|
718
|
+
"option",
|
|
719
|
+
"plaintext"
|
|
720
|
+
]);
|
|
721
|
+
var ALLOWED = new Set(INLINE_TAGS);
|
|
722
|
+
var VOID = /* @__PURE__ */ new Set(["br"]);
|
|
723
|
+
var MAX_INPUT = 5e5;
|
|
724
|
+
var MAX_NODES = 5e4;
|
|
725
|
+
var MAX_DEPTH = 64;
|
|
726
|
+
var NAMED_ENTITIES = Object.freeze({
|
|
727
|
+
amp: "&",
|
|
728
|
+
lt: "<",
|
|
729
|
+
gt: ">",
|
|
730
|
+
quot: '"',
|
|
731
|
+
apos: "'",
|
|
732
|
+
nbsp: "\xA0",
|
|
733
|
+
shy: "\xAD",
|
|
734
|
+
copy: "\xA9",
|
|
735
|
+
reg: "\xAE",
|
|
736
|
+
trade: "\u2122",
|
|
737
|
+
hellip: "\u2026",
|
|
738
|
+
mdash: "\u2014",
|
|
739
|
+
ndash: "\u2013",
|
|
740
|
+
lsquo: "\u2018",
|
|
741
|
+
rsquo: "\u2019",
|
|
742
|
+
ldquo: "\u201C",
|
|
743
|
+
rdquo: "\u201D",
|
|
744
|
+
laquo: "\xAB",
|
|
745
|
+
raquo: "\xBB",
|
|
746
|
+
euro: "\u20AC",
|
|
747
|
+
middot: "\xB7",
|
|
748
|
+
bull: "\u2022",
|
|
749
|
+
times: "\xD7",
|
|
750
|
+
deg: "\xB0",
|
|
751
|
+
tab: " ",
|
|
752
|
+
newline: "\n",
|
|
753
|
+
colon: ":",
|
|
754
|
+
sol: "/",
|
|
755
|
+
lpar: "(",
|
|
756
|
+
rpar: ")"
|
|
757
|
+
});
|
|
758
|
+
var decodeEntities = (text) => String(text).replace(
|
|
759
|
+
/&(#[xX][0-9a-fA-F]{1,8}|#[0-9]{1,10}|[A-Za-z][A-Za-z0-9]{1,31});?/g,
|
|
760
|
+
(match, body) => {
|
|
761
|
+
if (body[0] === "#") {
|
|
762
|
+
const code = body[1] === "x" || body[1] === "X" ? parseInt(body.slice(2), 16) : parseInt(body.slice(1), 10);
|
|
763
|
+
if (!Number.isFinite(code) || code <= 0 || code > 1114111 || code >= 55296 && code <= 57343)
|
|
764
|
+
return "\uFFFD";
|
|
765
|
+
return String.fromCodePoint(code);
|
|
766
|
+
}
|
|
767
|
+
const named = NAMED_ENTITIES[body] ?? NAMED_ENTITIES[body.toLowerCase()];
|
|
768
|
+
return named === void 0 ? match : named;
|
|
769
|
+
}
|
|
770
|
+
);
|
|
771
|
+
var parseAttributes = (source) => {
|
|
772
|
+
const out = {};
|
|
773
|
+
const pattern = /([^\s"'<>/=]+)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'=<>`]+)))?/g;
|
|
774
|
+
let match;
|
|
775
|
+
while (match = pattern.exec(source)) {
|
|
776
|
+
const name = match[1].toLowerCase();
|
|
777
|
+
if (Object.prototype.hasOwnProperty.call(out, name)) continue;
|
|
778
|
+
const raw = match[2] ?? match[3] ?? match[4] ?? "";
|
|
779
|
+
out[name] = decodeEntities(raw);
|
|
780
|
+
}
|
|
781
|
+
return out;
|
|
782
|
+
};
|
|
783
|
+
var findTagEnd = (html, from) => {
|
|
784
|
+
let quote = "";
|
|
785
|
+
for (let i = from; i < html.length; i += 1) {
|
|
786
|
+
const char = html[i];
|
|
787
|
+
if (quote) {
|
|
788
|
+
if (char === quote) quote = "";
|
|
789
|
+
} else if (char === '"' || char === "'") quote = char;
|
|
790
|
+
else if (char === ">") return i;
|
|
791
|
+
}
|
|
792
|
+
return -1;
|
|
793
|
+
};
|
|
794
|
+
var cleanAttributes = (tag, attribs) => {
|
|
795
|
+
const allowed = INLINE_ATTRIBUTES[tag] || [];
|
|
796
|
+
const out = {};
|
|
797
|
+
for (const name of allowed) {
|
|
798
|
+
if (!Object.prototype.hasOwnProperty.call(attribs, name) || name.startsWith("data-mex-")) continue;
|
|
799
|
+
const value = attribs[name];
|
|
800
|
+
if (name === "href") {
|
|
801
|
+
const url = sanitizeUrl(value);
|
|
802
|
+
if (url) out.href = url;
|
|
803
|
+
} else if (name === "target") {
|
|
804
|
+
const target = sanitizeTarget(value);
|
|
805
|
+
if (target) out.target = target;
|
|
806
|
+
} else if (name === "rel") {
|
|
807
|
+
const rel = String(value).split(/\s+/).filter((token) => /^[a-z-]{1,20}$/.test(token));
|
|
808
|
+
if (rel.length) out.rel = rel.join(" ");
|
|
809
|
+
} else if (name === "class") {
|
|
810
|
+
const classes2 = String(value).split(/\s+/).filter((token) => (INLINE_CLASSES[tag] || []).includes(token));
|
|
811
|
+
if (classes2.length) out.class = classes2.join(" ");
|
|
812
|
+
} else {
|
|
813
|
+
out[name] = String(value).slice(0, 2e3);
|
|
814
|
+
}
|
|
815
|
+
}
|
|
816
|
+
if (tag === "a") Object.assign(out, cleanInternalLinkAttributes(attribs));
|
|
817
|
+
return out;
|
|
818
|
+
};
|
|
819
|
+
var parseInline = (input) => {
|
|
820
|
+
const html = typeof input === "string" ? input.slice(0, MAX_INPUT) : "";
|
|
821
|
+
const root = { type: "element", tag: "#root", attrs: {}, children: [] };
|
|
822
|
+
const stack = [root];
|
|
823
|
+
let nodes = 0;
|
|
824
|
+
let text = "";
|
|
825
|
+
const flush = () => {
|
|
826
|
+
if (!text) return;
|
|
827
|
+
const parent = stack[stack.length - 1];
|
|
828
|
+
const last = parent.children[parent.children.length - 1];
|
|
829
|
+
const value = decodeEntities(text);
|
|
830
|
+
if (last && last.type === "text") last.value += value;
|
|
831
|
+
else if (nodes < MAX_NODES) {
|
|
832
|
+
parent.children.push({ type: "text", value });
|
|
833
|
+
nodes += 1;
|
|
834
|
+
}
|
|
835
|
+
text = "";
|
|
836
|
+
};
|
|
837
|
+
let i = 0;
|
|
838
|
+
while (i < html.length) {
|
|
839
|
+
const lt = html.indexOf("<", i);
|
|
840
|
+
if (lt === -1) {
|
|
841
|
+
text += html.slice(i);
|
|
842
|
+
break;
|
|
843
|
+
}
|
|
844
|
+
text += html.slice(i, lt);
|
|
845
|
+
i = lt;
|
|
846
|
+
if (html.startsWith("<!--", i)) {
|
|
847
|
+
const end2 = html.indexOf("-->", i + 4);
|
|
848
|
+
flush();
|
|
849
|
+
i = end2 === -1 ? html.length : end2 + 3;
|
|
850
|
+
continue;
|
|
851
|
+
}
|
|
852
|
+
if (html.startsWith("<![CDATA[", i)) {
|
|
853
|
+
const end2 = html.indexOf("]]>", i + 9);
|
|
854
|
+
flush();
|
|
855
|
+
i = end2 === -1 ? html.length : end2 + 3;
|
|
856
|
+
continue;
|
|
857
|
+
}
|
|
858
|
+
if (html[i + 1] === "!" || html[i + 1] === "?") {
|
|
859
|
+
const end2 = html.indexOf(">", i + 2);
|
|
860
|
+
flush();
|
|
861
|
+
i = end2 === -1 ? html.length : end2 + 1;
|
|
862
|
+
continue;
|
|
863
|
+
}
|
|
864
|
+
const closing = html[i + 1] === "/";
|
|
865
|
+
const nameMatch = /^[A-Za-z][A-Za-z0-9-]{0,40}/.exec(html.slice(i + (closing ? 2 : 1), i + 45));
|
|
866
|
+
if (!nameMatch) {
|
|
867
|
+
text += "<";
|
|
868
|
+
i += 1;
|
|
869
|
+
continue;
|
|
870
|
+
}
|
|
871
|
+
const end = findTagEnd(html, i + 1);
|
|
872
|
+
if (end === -1) {
|
|
873
|
+
text += html.slice(i);
|
|
874
|
+
break;
|
|
875
|
+
}
|
|
876
|
+
flush();
|
|
877
|
+
const tag = nameMatch[0].toLowerCase();
|
|
878
|
+
const body = html.slice(i + (closing ? 2 : 1) + nameMatch[0].length, end);
|
|
879
|
+
i = end + 1;
|
|
880
|
+
if (closing) {
|
|
881
|
+
if (!ALLOWED.has(tag)) continue;
|
|
882
|
+
for (let s = stack.length - 1; s > 0; s -= 1) {
|
|
883
|
+
if (stack[s].tag === tag) {
|
|
884
|
+
stack.length = s;
|
|
885
|
+
break;
|
|
886
|
+
}
|
|
887
|
+
}
|
|
888
|
+
continue;
|
|
889
|
+
}
|
|
890
|
+
if (DROP_WITH_CONTENT.has(tag)) {
|
|
891
|
+
const selfClosing = /\/\s*$/.test(body);
|
|
892
|
+
if (selfClosing) continue;
|
|
893
|
+
const closeIndex = html.slice(i).search(new RegExp(`</${tag}[\\s/>]`, "i"));
|
|
894
|
+
if (closeIndex === -1) break;
|
|
895
|
+
const closeEnd = html.indexOf(">", i + closeIndex);
|
|
896
|
+
i = closeEnd === -1 ? html.length : closeEnd + 1;
|
|
897
|
+
continue;
|
|
898
|
+
}
|
|
899
|
+
if (!ALLOWED.has(tag) || nodes >= MAX_NODES) continue;
|
|
900
|
+
const element = {
|
|
901
|
+
type: "element",
|
|
902
|
+
tag,
|
|
903
|
+
attrs: cleanAttributes(tag, parseAttributes(body)),
|
|
904
|
+
children: []
|
|
905
|
+
};
|
|
906
|
+
stack[stack.length - 1].children.push(element);
|
|
907
|
+
nodes += 1;
|
|
908
|
+
if (!VOID.has(tag) && stack.length < MAX_DEPTH) stack.push(element);
|
|
909
|
+
}
|
|
910
|
+
flush();
|
|
911
|
+
return root.children;
|
|
912
|
+
};
|
|
913
|
+
var resolveLinkAttributes = (attrs, resolver) => {
|
|
914
|
+
if (typeof resolver !== "function" || !attrs["data-mex-uid"] || !attrs["data-mex-document-id"])
|
|
915
|
+
return attrs;
|
|
916
|
+
let result;
|
|
917
|
+
try {
|
|
918
|
+
result = resolver({
|
|
919
|
+
uid: attrs["data-mex-uid"],
|
|
920
|
+
documentId: attrs["data-mex-document-id"],
|
|
921
|
+
locale: attrs["data-mex-locale"] || null,
|
|
922
|
+
href: attrs.href || null,
|
|
923
|
+
...isMentionLink(attrs) ? { mention: true } : {}
|
|
924
|
+
});
|
|
925
|
+
} catch {
|
|
926
|
+
result = void 0;
|
|
927
|
+
}
|
|
928
|
+
if (result === false) return null;
|
|
929
|
+
if (typeof result === "string") {
|
|
930
|
+
const url = sanitizeUrl(result);
|
|
931
|
+
if (url) return { ...attrs, href: url };
|
|
932
|
+
}
|
|
933
|
+
return attrs;
|
|
934
|
+
};
|
|
935
|
+
var ATTRIBUTE_ORDER = [
|
|
936
|
+
"href",
|
|
937
|
+
"target",
|
|
938
|
+
"rel",
|
|
939
|
+
"title",
|
|
940
|
+
"class",
|
|
941
|
+
"data-tooltip",
|
|
942
|
+
"data-mex-uid",
|
|
943
|
+
"data-mex-document-id",
|
|
944
|
+
"data-mex-locale",
|
|
945
|
+
"data-mex-mention"
|
|
946
|
+
];
|
|
947
|
+
var MENTION_CLASS = "mex-mention";
|
|
948
|
+
var inlineNodesToRender = (nodes, options = {}) => {
|
|
949
|
+
const out = [];
|
|
950
|
+
for (const node of nodes) {
|
|
951
|
+
if (node.type === "text") {
|
|
952
|
+
out.push({ type: "text", value: node.value });
|
|
953
|
+
continue;
|
|
954
|
+
}
|
|
955
|
+
if (node.tag === "br") {
|
|
956
|
+
out.push({ type: "element", tag: "br", attrs: {}, children: [] });
|
|
957
|
+
continue;
|
|
958
|
+
}
|
|
959
|
+
let attrs = node.attrs;
|
|
960
|
+
if (node.tag === "a") {
|
|
961
|
+
attrs = resolveLinkAttributes(attrs, options.links);
|
|
962
|
+
if (!attrs || !attrs.href) {
|
|
963
|
+
out.push(...inlineNodesToRender(node.children, options));
|
|
964
|
+
continue;
|
|
965
|
+
}
|
|
966
|
+
if (attrs.target === "_blank") {
|
|
967
|
+
const rel = new Set(
|
|
968
|
+
String(attrs.rel || "").split(/\s+/).filter(Boolean)
|
|
969
|
+
);
|
|
970
|
+
rel.add("noopener");
|
|
971
|
+
rel.add("noreferrer");
|
|
972
|
+
attrs = { ...attrs, rel: Array.from(rel).sort().join(" ") };
|
|
973
|
+
}
|
|
974
|
+
if (!options.storage && isMentionLink(attrs)) attrs = { ...attrs, class: MENTION_CLASS };
|
|
975
|
+
}
|
|
976
|
+
const ordered = {};
|
|
977
|
+
for (const name of ATTRIBUTE_ORDER) {
|
|
978
|
+
if (attrs[name] !== void 0 && attrs[name] !== "") ordered[name] = String(attrs[name]);
|
|
979
|
+
}
|
|
980
|
+
out.push({
|
|
981
|
+
type: "element",
|
|
982
|
+
tag: node.tag,
|
|
983
|
+
attrs: ordered,
|
|
984
|
+
children: inlineNodesToRender(node.children, options)
|
|
985
|
+
});
|
|
986
|
+
}
|
|
987
|
+
return out;
|
|
988
|
+
};
|
|
989
|
+
var inlineToNodes = (html, options) => inlineNodesToRender(parseInline(html), options);
|
|
990
|
+
var nodesToHtml = (nodes, options = {}) => serializeNodes(inlineNodesToRender(nodes, options));
|
|
991
|
+
var nodesToText = (nodes) => nodes.map((node) => {
|
|
992
|
+
if (node.type === "text") return node.value;
|
|
993
|
+
if (node.tag === "br") return "\n";
|
|
994
|
+
return nodesToText(node.children);
|
|
995
|
+
}).join("");
|
|
996
|
+
var inlineToHtml = (html, options) => nodesToHtml(parseInline(html), options);
|
|
997
|
+
var inlineToText = (html) => nodesToText(parseInline(html)).replace(/\u00a0/g, " ");
|
|
998
|
+
|
|
999
|
+
// shared/blocks/define.mjs
|
|
1000
|
+
var BLOCK_FIELD_TYPES = Object.freeze([
|
|
1001
|
+
"text",
|
|
1002
|
+
"inline",
|
|
1003
|
+
"url",
|
|
1004
|
+
"enum",
|
|
1005
|
+
"number",
|
|
1006
|
+
"boolean",
|
|
1007
|
+
"array",
|
|
1008
|
+
"object"
|
|
1009
|
+
]);
|
|
1010
|
+
var BLOCK_LIMITS = Object.freeze({
|
|
1011
|
+
/** Fields per object (also the schema root). */
|
|
1012
|
+
maxFields: 50,
|
|
1013
|
+
/** Nesting of arrays and objects below the root. */
|
|
1014
|
+
maxDepth: 4,
|
|
1015
|
+
/** Largest `max` of a text or inline field. */
|
|
1016
|
+
maxText: 1e5,
|
|
1017
|
+
/** Default `max` of a text field. */
|
|
1018
|
+
defaultText: 1e3,
|
|
1019
|
+
/** Default `max` of an inline HTML field. */
|
|
1020
|
+
defaultInline: 1e4,
|
|
1021
|
+
/** Largest `max` of an array field. */
|
|
1022
|
+
maxItems: 500,
|
|
1023
|
+
/** Default `max` of an array field. */
|
|
1024
|
+
defaultItems: 50,
|
|
1025
|
+
/** Values of an enum field. */
|
|
1026
|
+
maxEnumValues: 100,
|
|
1027
|
+
/** Values cleaned per block; later array items are dropped. */
|
|
1028
|
+
maxValues: 2e4,
|
|
1029
|
+
/** Length of a URL value. */
|
|
1030
|
+
maxUrl: 2048
|
|
1031
|
+
});
|
|
1032
|
+
var BLOCK_PRESETS = Object.freeze(["article", "basic", "minimal"]);
|
|
1033
|
+
var RESERVED_BLOCK_NAMES = Object.freeze([
|
|
1034
|
+
"paragraph",
|
|
1035
|
+
"header",
|
|
1036
|
+
"list",
|
|
1037
|
+
"checklist",
|
|
1038
|
+
"quote",
|
|
1039
|
+
"warning",
|
|
1040
|
+
"alert",
|
|
1041
|
+
"toggle",
|
|
1042
|
+
"code",
|
|
1043
|
+
"codeFlask",
|
|
1044
|
+
"delimiter",
|
|
1045
|
+
"toc",
|
|
1046
|
+
"synced",
|
|
1047
|
+
"table",
|
|
1048
|
+
"embed",
|
|
1049
|
+
"raw",
|
|
1050
|
+
"image",
|
|
1051
|
+
"simpleImage",
|
|
1052
|
+
"gallery",
|
|
1053
|
+
"video",
|
|
1054
|
+
"audio",
|
|
1055
|
+
"linkTool",
|
|
1056
|
+
"attaches",
|
|
1057
|
+
"personality",
|
|
1058
|
+
"button",
|
|
1059
|
+
"mediaLib",
|
|
1060
|
+
"embeddedEntry",
|
|
1061
|
+
"bold",
|
|
1062
|
+
"italic",
|
|
1063
|
+
"hyperlink",
|
|
1064
|
+
"mention",
|
|
1065
|
+
"marker",
|
|
1066
|
+
"underline",
|
|
1067
|
+
"strikethrough",
|
|
1068
|
+
"inlineCode",
|
|
1069
|
+
"tooltip",
|
|
1070
|
+
"aiAssistant",
|
|
1071
|
+
"alignmentTune",
|
|
1072
|
+
"textVariant",
|
|
1073
|
+
"indentTune"
|
|
1074
|
+
]);
|
|
1075
|
+
var RESERVED = new Set(RESERVED_BLOCK_NAMES.map((name) => name.toLowerCase()));
|
|
1076
|
+
var BLOCK_NAME_PATTERN = /^[A-Za-z][A-Za-z0-9_-]{1,49}$/;
|
|
1077
|
+
var KEY_PATTERN = /^[A-Za-z][A-Za-z0-9_]{0,63}$/;
|
|
1078
|
+
var FORBIDDEN_KEYS2 = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
|
|
1079
|
+
var DEFINITION_KEYS = /* @__PURE__ */ new Set([
|
|
1080
|
+
"name",
|
|
1081
|
+
"version",
|
|
1082
|
+
"title",
|
|
1083
|
+
"description",
|
|
1084
|
+
"schema",
|
|
1085
|
+
"sanitize",
|
|
1086
|
+
"text",
|
|
1087
|
+
"markdown",
|
|
1088
|
+
"render",
|
|
1089
|
+
"presets"
|
|
1090
|
+
]);
|
|
1091
|
+
var FIELD_KEYS = {
|
|
1092
|
+
text: ["max", "multiline", "default"],
|
|
1093
|
+
inline: ["max", "default"],
|
|
1094
|
+
url: ["schemes", "relative"],
|
|
1095
|
+
enum: ["values", "default"],
|
|
1096
|
+
number: ["min", "max", "integer", "default"],
|
|
1097
|
+
boolean: ["default"],
|
|
1098
|
+
array: ["items", "max"],
|
|
1099
|
+
object: ["fields"]
|
|
1100
|
+
};
|
|
1101
|
+
var BlockDefinitionError = class extends Error {
|
|
1102
|
+
/**
|
|
1103
|
+
* @param {string} message - Message naming the definition and the problem.
|
|
1104
|
+
* @param {string} [code] - `INVALID_DEFINITION` | `RESERVED_NAME` | `NAME_TAKEN` | `REGISTRY_SEALED`.
|
|
1105
|
+
*/
|
|
1106
|
+
constructor(message, code = "INVALID_DEFINITION") {
|
|
1107
|
+
super(message);
|
|
1108
|
+
this.name = "BlockDefinitionError";
|
|
1109
|
+
this.code = code;
|
|
1110
|
+
}
|
|
1111
|
+
};
|
|
1112
|
+
var isObject = (value) => value !== null && typeof value === "object" && !Array.isArray(value) && (Object.getPrototypeOf(value) === Object.prototype || Object.getPrototypeOf(value) === null);
|
|
1113
|
+
var fail = (where, message) => {
|
|
1114
|
+
throw new BlockDefinitionError(`Magic Editor X block ${where}: ${message}`);
|
|
1115
|
+
};
|
|
1116
|
+
var boundedInt = (value, min, max, fallback, where, key) => {
|
|
1117
|
+
if (value === void 0) return fallback;
|
|
1118
|
+
if (!Number.isInteger(value) || value < min || value > max)
|
|
1119
|
+
fail(where, `"${key}" must be an integer from ${min} to ${max}`);
|
|
1120
|
+
return value;
|
|
1121
|
+
};
|
|
1122
|
+
var normalizeField = (input, where, depth) => {
|
|
1123
|
+
if (!isObject(input)) fail(where, 'a field must be an object with a "type"');
|
|
1124
|
+
const type = input.type;
|
|
1125
|
+
if (!BLOCK_FIELD_TYPES.includes(type)) fail(where, `unknown field type ${JSON.stringify(type)}`);
|
|
1126
|
+
for (const key of Object.keys(input))
|
|
1127
|
+
if (key !== "type" && key !== "label" && !FIELD_KEYS[type].includes(key))
|
|
1128
|
+
fail(where, `unknown option "${key}" for a ${type} field`);
|
|
1129
|
+
const out = { type };
|
|
1130
|
+
if (input.label !== void 0) {
|
|
1131
|
+
if (typeof input.label !== "string" || input.label.length > 100)
|
|
1132
|
+
fail(where, '"label" must be a string of at most 100 characters');
|
|
1133
|
+
out.label = input.label;
|
|
1134
|
+
}
|
|
1135
|
+
switch (type) {
|
|
1136
|
+
case "text":
|
|
1137
|
+
case "inline": {
|
|
1138
|
+
out.max = boundedInt(
|
|
1139
|
+
input.max,
|
|
1140
|
+
1,
|
|
1141
|
+
BLOCK_LIMITS.maxText,
|
|
1142
|
+
type === "text" ? BLOCK_LIMITS.defaultText : BLOCK_LIMITS.defaultInline,
|
|
1143
|
+
where,
|
|
1144
|
+
"max"
|
|
1145
|
+
);
|
|
1146
|
+
if (input.default !== void 0 && typeof input.default !== "string")
|
|
1147
|
+
fail(where, '"default" must be a string');
|
|
1148
|
+
out.default = (input.default || "").slice(0, out.max);
|
|
1149
|
+
if (type === "text") {
|
|
1150
|
+
if (input.multiline !== void 0 && typeof input.multiline !== "boolean")
|
|
1151
|
+
fail(where, '"multiline" must be a boolean');
|
|
1152
|
+
out.multiline = input.multiline === true;
|
|
1153
|
+
}
|
|
1154
|
+
break;
|
|
1155
|
+
}
|
|
1156
|
+
case "url": {
|
|
1157
|
+
const schemes = input.schemes === void 0 ? ["http", "https"] : input.schemes;
|
|
1158
|
+
if (!Array.isArray(schemes) || !schemes.length || schemes.some((scheme) => !LINK_SCHEMES.includes(scheme)))
|
|
1159
|
+
fail(where, `"schemes" must be a non-empty list of ${LINK_SCHEMES.join(", ")}`);
|
|
1160
|
+
if (input.relative !== void 0 && typeof input.relative !== "boolean")
|
|
1161
|
+
fail(where, '"relative" must be a boolean');
|
|
1162
|
+
out.schemes = Object.freeze([...new Set(schemes)]);
|
|
1163
|
+
out.relative = input.relative !== false;
|
|
1164
|
+
break;
|
|
1165
|
+
}
|
|
1166
|
+
case "enum": {
|
|
1167
|
+
const values = input.values;
|
|
1168
|
+
if (!Array.isArray(values) || values.length < 1 || values.length > BLOCK_LIMITS.maxEnumValues || values.some((value) => typeof value !== "string" || value.length < 1 || value.length > 100) || new Set(values).size !== values.length)
|
|
1169
|
+
fail(
|
|
1170
|
+
where,
|
|
1171
|
+
`"values" must be 1 to ${BLOCK_LIMITS.maxEnumValues} distinct strings (1-100 characters)`
|
|
1172
|
+
);
|
|
1173
|
+
out.values = Object.freeze([...values]);
|
|
1174
|
+
if (input.default !== void 0 && !values.includes(input.default))
|
|
1175
|
+
fail(where, '"default" must be one of "values"');
|
|
1176
|
+
out.default = input.default === void 0 ? values[0] : input.default;
|
|
1177
|
+
break;
|
|
1178
|
+
}
|
|
1179
|
+
case "number": {
|
|
1180
|
+
for (const key of ["min", "max", "default"])
|
|
1181
|
+
if (input[key] !== void 0 && (typeof input[key] !== "number" || !Number.isFinite(input[key])))
|
|
1182
|
+
fail(where, `"${key}" must be a finite number`);
|
|
1183
|
+
if (input.integer !== void 0 && typeof input.integer !== "boolean")
|
|
1184
|
+
fail(where, '"integer" must be a boolean');
|
|
1185
|
+
out.integer = input.integer === true;
|
|
1186
|
+
out.min = input.min === void 0 ? -Number.MAX_SAFE_INTEGER : input.min;
|
|
1187
|
+
out.max = input.max === void 0 ? Number.MAX_SAFE_INTEGER : input.max;
|
|
1188
|
+
if (out.min > out.max) fail(where, '"min" must not be greater than "max"');
|
|
1189
|
+
if (input.default !== void 0) {
|
|
1190
|
+
if (input.default < out.min || input.default > out.max || out.integer && !Number.isInteger(input.default))
|
|
1191
|
+
fail(where, '"default" must be a valid value of the field');
|
|
1192
|
+
out.default = input.default;
|
|
1193
|
+
}
|
|
1194
|
+
break;
|
|
1195
|
+
}
|
|
1196
|
+
case "boolean":
|
|
1197
|
+
if (input.default !== void 0 && typeof input.default !== "boolean")
|
|
1198
|
+
fail(where, '"default" must be a boolean');
|
|
1199
|
+
out.default = input.default === true;
|
|
1200
|
+
break;
|
|
1201
|
+
case "array":
|
|
1202
|
+
if (depth >= BLOCK_LIMITS.maxDepth) fail(where, `fields nest at most ${BLOCK_LIMITS.maxDepth} levels`);
|
|
1203
|
+
out.max = boundedInt(input.max, 1, BLOCK_LIMITS.maxItems, BLOCK_LIMITS.defaultItems, where, "max");
|
|
1204
|
+
out.items = normalizeField(input.items, `${where}[]`, depth + 1);
|
|
1205
|
+
break;
|
|
1206
|
+
case "object":
|
|
1207
|
+
if (depth >= BLOCK_LIMITS.maxDepth) fail(where, `fields nest at most ${BLOCK_LIMITS.maxDepth} levels`);
|
|
1208
|
+
out.fields = normalizeFields(input.fields, where, depth + 1);
|
|
1209
|
+
break;
|
|
1210
|
+
default:
|
|
1211
|
+
break;
|
|
1212
|
+
}
|
|
1213
|
+
return Object.freeze(out);
|
|
1214
|
+
};
|
|
1215
|
+
var normalizeFields = (input, where, depth) => {
|
|
1216
|
+
if (!isObject(input)) fail(where, '"fields" must be an object of field descriptors');
|
|
1217
|
+
const keys = Object.keys(input);
|
|
1218
|
+
if (keys.length < 1 || keys.length > BLOCK_LIMITS.maxFields)
|
|
1219
|
+
fail(where, `an object needs 1 to ${BLOCK_LIMITS.maxFields} fields`);
|
|
1220
|
+
const out = /* @__PURE__ */ Object.create(null);
|
|
1221
|
+
for (const key of keys) {
|
|
1222
|
+
if (!KEY_PATTERN.test(key) || FORBIDDEN_KEYS2.has(key))
|
|
1223
|
+
fail(where, `field name ${JSON.stringify(key)} must match ${KEY_PATTERN}`);
|
|
1224
|
+
out[key] = normalizeField(input[key], `${where}.${key}`, depth);
|
|
1225
|
+
}
|
|
1226
|
+
return Object.freeze(out);
|
|
1227
|
+
};
|
|
1228
|
+
var blockNameProblem = (name) => {
|
|
1229
|
+
if (typeof name !== "string" || !BLOCK_NAME_PATTERN.test(name))
|
|
1230
|
+
return `the name must match ${BLOCK_NAME_PATTERN}`;
|
|
1231
|
+
if (RESERVED.has(name.toLowerCase())) return `"${name}" is a built-in tool name`;
|
|
1232
|
+
return null;
|
|
1233
|
+
};
|
|
1234
|
+
var defineBlock = (definition) => {
|
|
1235
|
+
if (!isObject(definition))
|
|
1236
|
+
throw new BlockDefinitionError("Magic Editor X block: the definition must be an object");
|
|
1237
|
+
const label2 = typeof definition.name === "string" ? `"${definition.name.slice(0, 50)}"` : "(no name)";
|
|
1238
|
+
for (const key of Object.keys(definition))
|
|
1239
|
+
if (!DEFINITION_KEYS.has(key)) fail(label2, `unknown key "${key}"`);
|
|
1240
|
+
const problem = blockNameProblem(definition.name);
|
|
1241
|
+
if (problem)
|
|
1242
|
+
throw new BlockDefinitionError(
|
|
1243
|
+
`Magic Editor X block ${label2}: ${problem}`,
|
|
1244
|
+
problem.includes("built-in") ? "RESERVED_NAME" : "INVALID_DEFINITION"
|
|
1245
|
+
);
|
|
1246
|
+
const out = {
|
|
1247
|
+
name: definition.name,
|
|
1248
|
+
version: boundedInt(definition.version, 1, 1e6, 1, label2, "version")
|
|
1249
|
+
};
|
|
1250
|
+
for (const [key, max] of [
|
|
1251
|
+
["title", 100],
|
|
1252
|
+
["description", 500]
|
|
1253
|
+
]) {
|
|
1254
|
+
if (definition[key] === void 0) continue;
|
|
1255
|
+
if (typeof definition[key] !== "string" || definition[key].length > max)
|
|
1256
|
+
fail(label2, `"${key}" must be a string of at most ${max} characters`);
|
|
1257
|
+
out[key] = definition[key];
|
|
1258
|
+
}
|
|
1259
|
+
out.schema = normalizeFields(definition.schema, `${label2} schema`, 0);
|
|
1260
|
+
for (const key of ["sanitize", "text", "markdown", "render"]) {
|
|
1261
|
+
if (definition[key] === void 0) continue;
|
|
1262
|
+
if (typeof definition[key] !== "function") fail(label2, `"${key}" must be a function`);
|
|
1263
|
+
out[key] = definition[key];
|
|
1264
|
+
}
|
|
1265
|
+
const presets = definition.presets === void 0 ? [] : definition.presets;
|
|
1266
|
+
if (!Array.isArray(presets) || presets.some((preset) => !BLOCK_PRESETS.includes(preset)))
|
|
1267
|
+
fail(label2, `"presets" must list some of ${BLOCK_PRESETS.join(", ")}`);
|
|
1268
|
+
out.presets = Object.freeze([...new Set(presets)]);
|
|
1269
|
+
return Object.freeze(out);
|
|
1270
|
+
};
|
|
1271
|
+
var cleanValue = (field, value, inline, budget) => {
|
|
1272
|
+
budget.left -= 1;
|
|
1273
|
+
switch (field.type) {
|
|
1274
|
+
case "text":
|
|
1275
|
+
return typeof value === "string" ? value.slice(0, field.max) : field.default;
|
|
1276
|
+
case "inline":
|
|
1277
|
+
return inline(typeof value === "string" ? value.slice(0, field.max) : field.default);
|
|
1278
|
+
case "url":
|
|
1279
|
+
return typeof value === "string" ? sanitizeUrl(value.slice(0, BLOCK_LIMITS.maxUrl), {
|
|
1280
|
+
schemes: field.schemes,
|
|
1281
|
+
allowRelative: field.relative
|
|
1282
|
+
}) : "";
|
|
1283
|
+
case "enum":
|
|
1284
|
+
return typeof value === "string" && field.values.includes(value) ? value : field.default;
|
|
1285
|
+
case "number":
|
|
1286
|
+
return typeof value === "number" && Number.isFinite(value) && value >= field.min && value <= field.max && (!field.integer || Number.isInteger(value)) ? value : field.default;
|
|
1287
|
+
case "boolean":
|
|
1288
|
+
return typeof value === "boolean" ? value : field.default;
|
|
1289
|
+
case "array": {
|
|
1290
|
+
const out = [];
|
|
1291
|
+
if (!Array.isArray(value)) return out;
|
|
1292
|
+
for (const item of value) {
|
|
1293
|
+
if (out.length >= field.max || budget.left <= 0) break;
|
|
1294
|
+
if (!matchesType(field.items, item)) continue;
|
|
1295
|
+
const clean = cleanValue(field.items, item, inline, budget);
|
|
1296
|
+
if (clean !== void 0) out.push(clean);
|
|
1297
|
+
}
|
|
1298
|
+
return out;
|
|
1299
|
+
}
|
|
1300
|
+
case "object":
|
|
1301
|
+
return cleanObject(field.fields, isObject(value) ? value : {}, inline, budget);
|
|
1302
|
+
default:
|
|
1303
|
+
return void 0;
|
|
1304
|
+
}
|
|
1305
|
+
};
|
|
1306
|
+
var matchesType = (field, item) => {
|
|
1307
|
+
switch (field.type) {
|
|
1308
|
+
case "text":
|
|
1309
|
+
case "inline":
|
|
1310
|
+
case "url":
|
|
1311
|
+
case "enum":
|
|
1312
|
+
return typeof item === "string";
|
|
1313
|
+
case "number":
|
|
1314
|
+
return typeof item === "number";
|
|
1315
|
+
case "boolean":
|
|
1316
|
+
return typeof item === "boolean";
|
|
1317
|
+
case "array":
|
|
1318
|
+
return Array.isArray(item);
|
|
1319
|
+
default:
|
|
1320
|
+
return isObject(item);
|
|
1321
|
+
}
|
|
1322
|
+
};
|
|
1323
|
+
var cleanObject = (fields, value, inline, budget) => {
|
|
1324
|
+
const out = {};
|
|
1325
|
+
for (const key of Object.keys(fields)) {
|
|
1326
|
+
const own = Object.prototype.hasOwnProperty.call(value, key) ? value[key] : void 0;
|
|
1327
|
+
const clean = cleanValue(fields[key], own, inline, budget);
|
|
1328
|
+
if (clean !== void 0) out[key] = clean;
|
|
1329
|
+
}
|
|
1330
|
+
return out;
|
|
1331
|
+
};
|
|
1332
|
+
var eachLeaf = (fields, data, visit) => {
|
|
1333
|
+
const walk = (field, value, path, depth) => {
|
|
1334
|
+
if (depth > BLOCK_LIMITS.maxDepth + 1) return;
|
|
1335
|
+
if (field.type === "array") {
|
|
1336
|
+
if (!Array.isArray(value)) return;
|
|
1337
|
+
value.slice(0, field.max).forEach((item, index) => walk(field.items, item, [...path, index], depth + 1));
|
|
1338
|
+
} else if (field.type === "object") {
|
|
1339
|
+
if (!isObject(value)) return;
|
|
1340
|
+
for (const key of Object.keys(field.fields))
|
|
1341
|
+
if (Object.prototype.hasOwnProperty.call(value, key))
|
|
1342
|
+
walk(field.fields[key], value[key], [...path, key], depth + 1);
|
|
1343
|
+
} else visit(field, value, path);
|
|
1344
|
+
};
|
|
1345
|
+
if (!isObject(data)) return;
|
|
1346
|
+
for (const key of Object.keys(fields))
|
|
1347
|
+
if (Object.prototype.hasOwnProperty.call(data, key)) walk(fields[key], data[key], [key], 0);
|
|
1348
|
+
};
|
|
1349
|
+
var fieldAt = (fields, path) => {
|
|
1350
|
+
let current = { type: "object", fields };
|
|
1351
|
+
for (const part of String(path).split(".")) {
|
|
1352
|
+
if (!part) continue;
|
|
1353
|
+
if (current.type === "array") {
|
|
1354
|
+
if (/^\d+$/.test(part)) {
|
|
1355
|
+
current = current.items;
|
|
1356
|
+
continue;
|
|
1357
|
+
}
|
|
1358
|
+
return null;
|
|
1359
|
+
}
|
|
1360
|
+
if (current.type !== "object" || !Object.prototype.hasOwnProperty.call(current.fields, part)) return null;
|
|
1361
|
+
current = current.fields[part];
|
|
1362
|
+
}
|
|
1363
|
+
return current;
|
|
1364
|
+
};
|
|
1365
|
+
var compiled = /* @__PURE__ */ new WeakMap();
|
|
1366
|
+
var compileBlock = (definition) => {
|
|
1367
|
+
if (definition && typeof definition === "object" && compiled.has(definition))
|
|
1368
|
+
return compiled.get(definition);
|
|
1369
|
+
const def = defineBlock(definition && typeof definition === "object" ? { ...definition } : definition);
|
|
1370
|
+
const schema = def.schema;
|
|
1371
|
+
const run = (data, inline) => cleanObject(schema, isObject(data) ? data : {}, inline, { left: BLOCK_LIMITS.maxValues });
|
|
1372
|
+
const result = Object.freeze({
|
|
1373
|
+
...def,
|
|
1374
|
+
/**
|
|
1375
|
+
* Cleans untrusted block data (unknown keys dropped, values bounded).
|
|
1376
|
+
* The optional `sanitize` hook runs on the clean data; its result is
|
|
1377
|
+
* cleaned again, so it cannot add keys or unsafe values. A hook that
|
|
1378
|
+
* throws is ignored (the clean data is used).
|
|
1379
|
+
* @param {unknown} data - Block data.
|
|
1380
|
+
* @param {(html: string) => string} inline - Inline HTML sanitiser of the caller.
|
|
1381
|
+
* @returns {object} Clean data.
|
|
1382
|
+
*/
|
|
1383
|
+
clean: (data, inline) => {
|
|
1384
|
+
const first = run(data, inline);
|
|
1385
|
+
if (!def.sanitize) return first;
|
|
1386
|
+
let next;
|
|
1387
|
+
try {
|
|
1388
|
+
next = def.sanitize(copyData(first), { sanitizeUrl });
|
|
1389
|
+
} catch {
|
|
1390
|
+
return first;
|
|
1391
|
+
}
|
|
1392
|
+
return isObject(next) ? run(next, inline) : first;
|
|
1393
|
+
},
|
|
1394
|
+
/**
|
|
1395
|
+
* Text fields of the data in schema order: `{ path, kind, value }`
|
|
1396
|
+
* (`html` for inline fields, `plain` for text fields).
|
|
1397
|
+
* @param {unknown} data - Block data.
|
|
1398
|
+
* @returns {Array<{ path: Array<string|number>, kind: 'html'|'plain', value: string }>} Fields.
|
|
1399
|
+
*/
|
|
1400
|
+
fields: (data) => {
|
|
1401
|
+
const out = [];
|
|
1402
|
+
eachLeaf(schema, data, (field, value, path) => {
|
|
1403
|
+
if (typeof value !== "string") return;
|
|
1404
|
+
if (field.type === "inline") out.push({ path, kind: "html", value });
|
|
1405
|
+
else if (field.type === "text") out.push({ path, kind: "plain", value });
|
|
1406
|
+
});
|
|
1407
|
+
return out;
|
|
1408
|
+
},
|
|
1409
|
+
/**
|
|
1410
|
+
* Non-empty URL values: `{ path, value }`.
|
|
1411
|
+
* @param {unknown} data - Block data.
|
|
1412
|
+
* @returns {Array<{ path: Array<string|number>, value: string }>} URLs.
|
|
1413
|
+
*/
|
|
1414
|
+
urls: (data) => {
|
|
1415
|
+
const out = [];
|
|
1416
|
+
eachLeaf(schema, data, (field, value, path) => {
|
|
1417
|
+
if (field.type === "url" && typeof value === "string" && value) out.push({ path, value });
|
|
1418
|
+
});
|
|
1419
|
+
return out;
|
|
1420
|
+
},
|
|
1421
|
+
/**
|
|
1422
|
+
* Kind of the value at a dotted path, for the version diff.
|
|
1423
|
+
* @param {string} path - Dotted path.
|
|
1424
|
+
* @returns {'inline'|'plain'|'value'} Kind.
|
|
1425
|
+
*/
|
|
1426
|
+
kindOf: (path) => {
|
|
1427
|
+
const field = fieldAt(schema, path);
|
|
1428
|
+
if (!field) return "value";
|
|
1429
|
+
if (field.type === "inline") return "inline";
|
|
1430
|
+
if (field.type === "text") return "plain";
|
|
1431
|
+
return "value";
|
|
1432
|
+
}
|
|
1433
|
+
});
|
|
1434
|
+
compiled.set(result, result);
|
|
1435
|
+
if (definition && typeof definition === "object") compiled.set(definition, result);
|
|
1436
|
+
return result;
|
|
1437
|
+
};
|
|
1438
|
+
var copyData = (value) => {
|
|
1439
|
+
if (Array.isArray(value)) return value.map(copyData);
|
|
1440
|
+
if (isObject(value)) {
|
|
1441
|
+
const out = {};
|
|
1442
|
+
for (const [key, child] of Object.entries(value)) out[key] = copyData(child);
|
|
1443
|
+
return out;
|
|
1444
|
+
}
|
|
1445
|
+
return value;
|
|
1446
|
+
};
|
|
1447
|
+
var listCache = /* @__PURE__ */ new WeakMap();
|
|
1448
|
+
var compileBlockList = (list) => {
|
|
1449
|
+
if (!Array.isArray(list)) return /* @__PURE__ */ new Map();
|
|
1450
|
+
if (listCache.has(list)) return listCache.get(list);
|
|
1451
|
+
const map = /* @__PURE__ */ new Map();
|
|
1452
|
+
for (const definition of list) {
|
|
1453
|
+
const def = compileBlock(definition);
|
|
1454
|
+
map.set(def.name, def);
|
|
1455
|
+
}
|
|
1456
|
+
listCache.set(list, map);
|
|
1457
|
+
return map;
|
|
1458
|
+
};
|
|
1459
|
+
|
|
1460
|
+
// shared/toc.mjs
|
|
1461
|
+
var HEADING_ID_PREFIX = "mex-h-";
|
|
1462
|
+
var TOC_DEFAULTS = Object.freeze({ title: "", minLevel: 2, maxLevel: 4, style: "unordered" });
|
|
1463
|
+
var TOC_STYLES = Object.freeze(["unordered", "ordered"]);
|
|
1464
|
+
var SAFE_ID = /^[A-Za-z0-9_-]{1,64}$/;
|
|
1465
|
+
var createAnchorAllocator = () => {
|
|
1466
|
+
const used = /* @__PURE__ */ new Set();
|
|
1467
|
+
let position = 0;
|
|
1468
|
+
return (blockId) => {
|
|
1469
|
+
position += 1;
|
|
1470
|
+
const base = `${HEADING_ID_PREFIX}${typeof blockId === "string" && SAFE_ID.test(blockId) ? blockId : position}`;
|
|
1471
|
+
let id = base;
|
|
1472
|
+
for (let n = 2; used.has(id); n += 1) id = `${base}-${n}`;
|
|
1473
|
+
used.add(id);
|
|
1474
|
+
return id;
|
|
1475
|
+
};
|
|
1476
|
+
};
|
|
1477
|
+
var githubSlug = (text) => String(text || "").toLowerCase().trim().replace(/[^\p{L}\p{M}\p{N}\p{Pc} -]/gu, "").replace(/ /g, "-");
|
|
1478
|
+
var createSlugAllocator = () => {
|
|
1479
|
+
const seen = /* @__PURE__ */ new Map();
|
|
1480
|
+
return (text) => {
|
|
1481
|
+
const base = githubSlug(text);
|
|
1482
|
+
let slug = base;
|
|
1483
|
+
if (seen.has(base)) {
|
|
1484
|
+
let n = seen.get(base);
|
|
1485
|
+
do {
|
|
1486
|
+
n += 1;
|
|
1487
|
+
slug = `${base}-${n}`;
|
|
1488
|
+
} while (seen.has(slug));
|
|
1489
|
+
seen.set(base, n);
|
|
1490
|
+
}
|
|
1491
|
+
seen.set(slug, 0);
|
|
1492
|
+
return slug;
|
|
1493
|
+
};
|
|
1494
|
+
};
|
|
1495
|
+
var tocRange = (data) => {
|
|
1496
|
+
const pick = (value, fallback) => Number.isInteger(value) && value >= 1 && value <= 6 ? value : fallback;
|
|
1497
|
+
const a = pick(data && data.minLevel, TOC_DEFAULTS.minLevel);
|
|
1498
|
+
const b = pick(data && data.maxLevel, TOC_DEFAULTS.maxLevel);
|
|
1499
|
+
return { minLevel: Math.min(a, b), maxLevel: Math.max(a, b) };
|
|
1500
|
+
};
|
|
1501
|
+
var buildTocTree = (headings, data) => {
|
|
1502
|
+
const { minLevel, maxLevel } = tocRange(data);
|
|
1503
|
+
const root = { level: 0, children: [] };
|
|
1504
|
+
const stack = [root];
|
|
1505
|
+
for (const heading of headings || []) {
|
|
1506
|
+
if (!heading || heading.level < minLevel || heading.level > maxLevel) continue;
|
|
1507
|
+
const text = String(heading.text || "").replace(/\s+/g, " ").trim();
|
|
1508
|
+
if (!text) continue;
|
|
1509
|
+
while (stack.length > 1 && stack[stack.length - 1].level >= heading.level) stack.pop();
|
|
1510
|
+
const node = {
|
|
1511
|
+
id: heading.id || null,
|
|
1512
|
+
slug: heading.slug || null,
|
|
1513
|
+
level: heading.level,
|
|
1514
|
+
text: text.slice(0, 500),
|
|
1515
|
+
children: []
|
|
1516
|
+
};
|
|
1517
|
+
stack[stack.length - 1].children.push(node);
|
|
1518
|
+
stack.push(node);
|
|
1519
|
+
}
|
|
1520
|
+
return root.children;
|
|
1521
|
+
};
|
|
1522
|
+
|
|
1523
|
+
// shared/synced.mjs
|
|
1524
|
+
var SYNCED_TYPE = "synced";
|
|
1525
|
+
var SYNCED_REF_PATTERN = /^[a-z0-9]{1,64}$/;
|
|
1526
|
+
var SYNCED_LIMITS = Object.freeze({ refsPerResponse: 100 });
|
|
1527
|
+
var BLOCK_ID = /^[A-Za-z0-9_-]{1,64}$/;
|
|
1528
|
+
var MAX_TOGGLE_DEPTH = 16;
|
|
1529
|
+
var isSyncedBlock = (block) => Boolean(block) && block.type === SYNCED_TYPE && isBuiltInBlock(
|
|
1530
|
+
/** @type {any} */
|
|
1531
|
+
block
|
|
1532
|
+
);
|
|
1533
|
+
var syncedRefOf = (block) => {
|
|
1534
|
+
if (!isSyncedBlock(block)) return null;
|
|
1535
|
+
const ref = (
|
|
1536
|
+
/** @type {any} */
|
|
1537
|
+
block.data.ref
|
|
1538
|
+
);
|
|
1539
|
+
return typeof ref === "string" && SYNCED_REF_PATTERN.test(ref) ? ref : null;
|
|
1540
|
+
};
|
|
1541
|
+
var containsSynced = (blocks) => Array.isArray(blocks) && blocks.some(isSyncedBlock);
|
|
1542
|
+
var toBlockTree = (blocks) => {
|
|
1543
|
+
const build = (start, end, depth) => {
|
|
1544
|
+
const out = [];
|
|
1545
|
+
let i = start;
|
|
1546
|
+
while (i < end) {
|
|
1547
|
+
const block = blocks[i];
|
|
1548
|
+
i += 1;
|
|
1549
|
+
const node = { block, children: [], toggle: false };
|
|
1550
|
+
if (block && block.type === "toggle" && depth < MAX_TOGGLE_DEPTH && isPlainObject2(block.data)) {
|
|
1551
|
+
const count = Math.max(0, Math.min(Number(block.data.items) || 0, end - i));
|
|
1552
|
+
node.children = build(i, i + count, depth + 1);
|
|
1553
|
+
node.toggle = true;
|
|
1554
|
+
i += count;
|
|
1555
|
+
}
|
|
1556
|
+
out.push(node);
|
|
1557
|
+
}
|
|
1558
|
+
return out;
|
|
1559
|
+
};
|
|
1560
|
+
return build(0, Array.isArray(blocks) ? blocks.length : 0, 0);
|
|
1561
|
+
};
|
|
1562
|
+
var fromBlockTree = (nodes) => {
|
|
1563
|
+
const out = [];
|
|
1564
|
+
const walk = (list) => {
|
|
1565
|
+
for (const node of list) {
|
|
1566
|
+
const at = out.length;
|
|
1567
|
+
out.push(node.block);
|
|
1568
|
+
if (!node.toggle) continue;
|
|
1569
|
+
walk(node.children);
|
|
1570
|
+
const count = out.length - at - 1;
|
|
1571
|
+
if (Number(node.block.data.items) !== count)
|
|
1572
|
+
out[at] = { ...node.block, data: { ...node.block.data, items: count } };
|
|
1573
|
+
}
|
|
1574
|
+
};
|
|
1575
|
+
walk(nodes);
|
|
1576
|
+
return out;
|
|
1577
|
+
};
|
|
1578
|
+
var replaceBlocks = (blocks, replace) => {
|
|
1579
|
+
const map = (nodes) => {
|
|
1580
|
+
const out = [];
|
|
1581
|
+
for (const node of nodes) {
|
|
1582
|
+
const next = replace(node.block);
|
|
1583
|
+
const children = node.toggle ? map(node.children) : [];
|
|
1584
|
+
if (next === null || next === void 0) {
|
|
1585
|
+
out.push(node.toggle ? { ...node, children } : node);
|
|
1586
|
+
} else if (node.toggle && next.length === 1 && next[0] && next[0].type === "toggle") {
|
|
1587
|
+
out.push({ block: next[0], children, toggle: true });
|
|
1588
|
+
} else {
|
|
1589
|
+
out.push(...toBlockTree(next), ...children);
|
|
1590
|
+
}
|
|
1591
|
+
}
|
|
1592
|
+
return out;
|
|
1593
|
+
};
|
|
1594
|
+
return fromBlockTree(map(toBlockTree(blocks)));
|
|
1595
|
+
};
|
|
1596
|
+
var sourceBlocksOf = (source) => {
|
|
1597
|
+
const data = normalizeEditorDataSafe(source);
|
|
1598
|
+
if (!data || !data.blocks.length) return [];
|
|
1599
|
+
return containsSynced(data.blocks) ? replaceBlocks(data.blocks, (block) => isSyncedBlock(block) ? [] : null) : data.blocks;
|
|
1600
|
+
};
|
|
1601
|
+
var derivedId = (parentId, sourceId, taken) => {
|
|
1602
|
+
const joined = `${parentId}-${sourceId}`;
|
|
1603
|
+
let id = BLOCK_ID.test(joined) ? joined : `sx${hashString(joined)}${hashString(`${sourceId}|${parentId}`)}`;
|
|
1604
|
+
for (let n = 2; taken.has(id); n += 1) id = `sx${hashString(`${joined}|${n}`)}${n}`;
|
|
1605
|
+
taken.add(id);
|
|
1606
|
+
return id;
|
|
1607
|
+
};
|
|
1608
|
+
var expandSynced = (data, lookup, options = {}) => {
|
|
1609
|
+
const origins = /* @__PURE__ */ new Map();
|
|
1610
|
+
if (!data || !Array.isArray(data.blocks) || !containsSynced(data.blocks))
|
|
1611
|
+
return { data, origins, expanded: 0, unresolved: 0 };
|
|
1612
|
+
const maxBlocks = options.maxBlocks || EDITOR_DATA_LIMITS.maxBlocks;
|
|
1613
|
+
const maxBytes = options.maxBytes || EDITOR_DATA_LIMITS.maxBytes - 64 * 1024;
|
|
1614
|
+
const taken = new Set(data.blocks.map((block) => block.id));
|
|
1615
|
+
let total = data.blocks.filter((block) => !isSyncedBlock(block)).length;
|
|
1616
|
+
let bytes = byteLength(JSON.stringify(data));
|
|
1617
|
+
let expanded = 0;
|
|
1618
|
+
let unresolved = 0;
|
|
1619
|
+
const cache = /* @__PURE__ */ new Map();
|
|
1620
|
+
const sourceFor = (ref) => {
|
|
1621
|
+
if (!cache.has(ref)) {
|
|
1622
|
+
let blocks2;
|
|
1623
|
+
try {
|
|
1624
|
+
blocks2 = sourceBlocksOf(typeof lookup === "function" ? lookup(ref) : null);
|
|
1625
|
+
if (blocks2.length && typeof options.filter === "function") {
|
|
1626
|
+
const filtered = options.filter(blocks2);
|
|
1627
|
+
blocks2 = Array.isArray(filtered) ? filtered.filter((block) => !isSyncedBlock(block)) : [];
|
|
1628
|
+
}
|
|
1629
|
+
} catch {
|
|
1630
|
+
blocks2 = [];
|
|
1631
|
+
}
|
|
1632
|
+
cache.set(ref, { blocks: blocks2, size: blocks2.length ? byteLength(JSON.stringify(blocks2)) : 0 });
|
|
1633
|
+
}
|
|
1634
|
+
return cache.get(ref);
|
|
1635
|
+
};
|
|
1636
|
+
const blocks = replaceBlocks(data.blocks, (block) => {
|
|
1637
|
+
if (!isSyncedBlock(block)) return null;
|
|
1638
|
+
const ref = syncedRefOf(block);
|
|
1639
|
+
const source = ref ? sourceFor(ref) : { blocks: [], size: 0 };
|
|
1640
|
+
if (!source.blocks.length || total + source.blocks.length > maxBlocks || bytes + source.size > maxBytes) {
|
|
1641
|
+
unresolved += 1;
|
|
1642
|
+
return [];
|
|
1643
|
+
}
|
|
1644
|
+
total += source.blocks.length;
|
|
1645
|
+
bytes += source.size;
|
|
1646
|
+
expanded += 1;
|
|
1647
|
+
return source.blocks.map((item) => {
|
|
1648
|
+
const id = derivedId(block.id, item.id, taken);
|
|
1649
|
+
origins.set(id, ref);
|
|
1650
|
+
const copy = { id, type: item.type, data: JSON.parse(JSON.stringify(item.data || {})) };
|
|
1651
|
+
if (isPlainObject2(item.tunes) && Object.keys(item.tunes).length)
|
|
1652
|
+
copy.tunes = JSON.parse(JSON.stringify(item.tunes));
|
|
1653
|
+
return copy;
|
|
1654
|
+
});
|
|
1655
|
+
});
|
|
1656
|
+
return {
|
|
1657
|
+
data: { time: data.time || 0, version: data.version || "2.31.7", blocks },
|
|
1658
|
+
origins,
|
|
1659
|
+
expanded,
|
|
1660
|
+
unresolved
|
|
1661
|
+
};
|
|
1662
|
+
};
|
|
1663
|
+
var syncedLookup = (option) => {
|
|
1664
|
+
if (typeof option === "function") return (ref) => option(ref);
|
|
1665
|
+
if (option instanceof Map) return (ref) => option.get(ref);
|
|
1666
|
+
if (isPlainObject2(option))
|
|
1667
|
+
return (ref) => Object.prototype.hasOwnProperty.call(option, ref) ? option[ref] : null;
|
|
1668
|
+
return () => null;
|
|
1669
|
+
};
|
|
1670
|
+
|
|
1671
|
+
// shared/render/common.mjs
|
|
1672
|
+
var keepInline = (html) => inlineToHtml(html, { storage: true });
|
|
1673
|
+
var prepareBlocks = (value, options = {}) => {
|
|
1674
|
+
const normalized = normalizeEditorDataSafe(value);
|
|
1675
|
+
if (!normalized) return [];
|
|
1676
|
+
const data = containsSynced(normalized.blocks) ? expandSynced(normalized, syncedLookup(options.synced)).data : normalized;
|
|
1677
|
+
const rawPolicy = options.rawHtml === "allow" && typeof options.sanitizeRaw === "function" ? "allow" : "disable";
|
|
1678
|
+
const ctx = { rawHtml: rawPolicy, rawSanitizer: () => "" };
|
|
1679
|
+
const explicit = Array.isArray(options.blocks) ? compileBlockList(options.blocks) : null;
|
|
1680
|
+
const flat = data.blocks.map((block) => {
|
|
1681
|
+
const raw = isPlainObject2(block.data) ? block.data : {};
|
|
1682
|
+
const known = isBuiltInBlock({ type: block.type, data: raw });
|
|
1683
|
+
const definition = known ? null : registeredBlockOf({ type: block.type, data: raw }, explicit);
|
|
1684
|
+
const clean = known ? BLOCK_POLICIES[block.type](raw, keepInline, ctx) : definition ? definition.clean(raw, keepInline) : raw;
|
|
1685
|
+
for (const key of Object.keys(clean)) if (clean[key] === void 0) delete clean[key];
|
|
1686
|
+
return {
|
|
1687
|
+
id: block.id,
|
|
1688
|
+
type: block.type,
|
|
1689
|
+
data: clean,
|
|
1690
|
+
raw,
|
|
1691
|
+
tunes: sanitizeTunes(block.tunes),
|
|
1692
|
+
known,
|
|
1693
|
+
definition,
|
|
1694
|
+
children: []
|
|
1695
|
+
};
|
|
1696
|
+
});
|
|
1697
|
+
const group = (start, end, depth) => {
|
|
1698
|
+
const out = [];
|
|
1699
|
+
let i = start;
|
|
1700
|
+
while (i < end) {
|
|
1701
|
+
const block = flat[i];
|
|
1702
|
+
i += 1;
|
|
1703
|
+
if (block.type === "toggle" && depth < 16) {
|
|
1704
|
+
const count = Math.max(0, Math.min(Number(block.data.items) || 0, end - i));
|
|
1705
|
+
block.children = group(i, i + count, depth + 1);
|
|
1706
|
+
i += count;
|
|
1707
|
+
}
|
|
1708
|
+
out.push(block);
|
|
1709
|
+
}
|
|
1710
|
+
return out;
|
|
1711
|
+
};
|
|
1712
|
+
return group(0, flat.length, 0);
|
|
1713
|
+
};
|
|
1714
|
+
var FORMAT_ORDER = ["thumbnail", "xsmall", "small", "medium", "large", "xlarge"];
|
|
1715
|
+
var imageCandidates = (file) => {
|
|
1716
|
+
const out = [];
|
|
1717
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1718
|
+
const push = (url, width) => {
|
|
1719
|
+
const clean = sanitizeUrl(url, { schemes: ["http", "https"] });
|
|
1720
|
+
if (!clean || !Number.isInteger(width) || width <= 0 || seen.has(width)) return;
|
|
1721
|
+
seen.add(width);
|
|
1722
|
+
out.push({ url: clean, width });
|
|
1723
|
+
};
|
|
1724
|
+
if (isPlainObject2(file.formats)) {
|
|
1725
|
+
const names = Object.keys(file.formats).sort(
|
|
1726
|
+
(a, b) => (FORMAT_ORDER.indexOf(a) + 1 || 99) - (FORMAT_ORDER.indexOf(b) + 1 || 99) || (a < b ? -1 : a > b ? 1 : 0)
|
|
1727
|
+
);
|
|
1728
|
+
for (const name of names) {
|
|
1729
|
+
const format = file.formats[name];
|
|
1730
|
+
if (isPlainObject2(format)) push(format.url, Number(format.width));
|
|
1731
|
+
}
|
|
1732
|
+
}
|
|
1733
|
+
push(file.url, Number(file.width));
|
|
1734
|
+
return out.sort((a, b) => a.width - b.width);
|
|
1735
|
+
};
|
|
1736
|
+
var resolveMedia = (file, block, options, kind) => {
|
|
1737
|
+
if (typeof options.media !== "function") return file;
|
|
1738
|
+
if (kind) {
|
|
1739
|
+
let other;
|
|
1740
|
+
try {
|
|
1741
|
+
other = options.media({ ...file }, { id: block.id, type: block.type });
|
|
1742
|
+
} catch {
|
|
1743
|
+
other = null;
|
|
1744
|
+
}
|
|
1745
|
+
return isPlainObject2(other) ? cleanMediaFile(other, kind) : file;
|
|
1746
|
+
}
|
|
1747
|
+
let next;
|
|
1748
|
+
try {
|
|
1749
|
+
next = options.media({ ...file }, { id: block.id, type: block.type });
|
|
1750
|
+
} catch {
|
|
1751
|
+
next = null;
|
|
1752
|
+
}
|
|
1753
|
+
if (!isPlainObject2(next)) return file;
|
|
1754
|
+
const policy = BLOCK_POLICIES.image({ file: next }, (s) => s, {
|
|
1755
|
+
rawHtml: "disable",
|
|
1756
|
+
rawSanitizer: () => ""
|
|
1757
|
+
});
|
|
1758
|
+
return policy.file;
|
|
1759
|
+
};
|
|
1760
|
+
var DEFAULT_EMBED_HOSTS = Object.freeze([
|
|
1761
|
+
"www.youtube-nocookie.com",
|
|
1762
|
+
"www.youtube.com",
|
|
1763
|
+
"youtube.com",
|
|
1764
|
+
"player.vimeo.com",
|
|
1765
|
+
"codepen.io",
|
|
1766
|
+
"player.twitch.tv",
|
|
1767
|
+
"clips.twitch.tv",
|
|
1768
|
+
"embed.figma.com",
|
|
1769
|
+
"www.figma.com",
|
|
1770
|
+
"miro.com"
|
|
1771
|
+
]);
|
|
1772
|
+
var embedFrameUrl = (url, hosts) => {
|
|
1773
|
+
if (!url || !/^https:\/\//i.test(url)) return "";
|
|
1774
|
+
try {
|
|
1775
|
+
const parsed = new URL(url);
|
|
1776
|
+
return parsed.protocol === "https:" && hosts.includes(parsed.hostname.toLowerCase()) ? url : "";
|
|
1777
|
+
} catch {
|
|
1778
|
+
return "";
|
|
1779
|
+
}
|
|
1780
|
+
};
|
|
1781
|
+
var overrideFor = (options, type) => {
|
|
1782
|
+
const overrides = options && options.overrides;
|
|
1783
|
+
if (!overrides || typeof overrides !== "object" || !Object.prototype.hasOwnProperty.call(overrides, type))
|
|
1784
|
+
return null;
|
|
1785
|
+
return typeof overrides[type] === "function" ? overrides[type] : null;
|
|
1786
|
+
};
|
|
1787
|
+
var scalarFields = (data) => Object.keys(isPlainObject2(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])]);
|
|
1788
|
+
var formatSize = (bytes) => {
|
|
1789
|
+
if (!Number.isFinite(bytes) || bytes < 0) return "";
|
|
1790
|
+
if (bytes < 1024) return `${bytes} B`;
|
|
1791
|
+
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
|
|
1792
|
+
return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
|
|
1793
|
+
};
|
|
1794
|
+
var eachBlock = (blocks, fn, depth = 0) => {
|
|
1795
|
+
if (depth > 16) return;
|
|
1796
|
+
for (const block of blocks) {
|
|
1797
|
+
fn(block);
|
|
1798
|
+
if (block.children.length) eachBlock(block.children, fn, depth + 1);
|
|
1799
|
+
}
|
|
1800
|
+
};
|
|
1801
|
+
var annotateHeadings = (blocks, options = {}) => {
|
|
1802
|
+
const tocs = [];
|
|
1803
|
+
const headers = [];
|
|
1804
|
+
eachBlock(blocks, (block) => {
|
|
1805
|
+
if (!block.known) return;
|
|
1806
|
+
if (block.type === "toc") tocs.push(block);
|
|
1807
|
+
else if (block.type === "header") headers.push(block);
|
|
1808
|
+
});
|
|
1809
|
+
const enabled = options.headingIds === true || options.headingIds !== false && tocs.length > 0;
|
|
1810
|
+
if (!enabled && !tocs.length) return blocks;
|
|
1811
|
+
const allocate = createAnchorAllocator();
|
|
1812
|
+
const slugOf = createSlugAllocator();
|
|
1813
|
+
const headings = headers.map((block) => {
|
|
1814
|
+
const id = allocate(block.id);
|
|
1815
|
+
const text = inlineToText(block.data.text);
|
|
1816
|
+
if (enabled) block.anchor = id;
|
|
1817
|
+
return { id: enabled ? id : null, slug: slugOf(text.trim()), level: block.data.level, text };
|
|
1818
|
+
});
|
|
1819
|
+
for (const toc of tocs) {
|
|
1820
|
+
toc.headings = headings;
|
|
1821
|
+
toc.linkHeadings = enabled;
|
|
1822
|
+
}
|
|
1823
|
+
return blocks;
|
|
1824
|
+
};
|
|
1825
|
+
|
|
1826
|
+
// shared/render/tree.mjs
|
|
1827
|
+
var COUNTER_TYPES = Object.freeze({
|
|
1828
|
+
"lower-roman": "i",
|
|
1829
|
+
"upper-roman": "I",
|
|
1830
|
+
"lower-alpha": "a",
|
|
1831
|
+
"upper-alpha": "A"
|
|
1832
|
+
});
|
|
1833
|
+
var MAX_NUMBERED_LINES = 2e4;
|
|
1834
|
+
var classes = (base, tunes) => {
|
|
1835
|
+
const list = [...base];
|
|
1836
|
+
if (tunes && tunes.alignmentTune && tunes.alignmentTune.alignment !== "left")
|
|
1837
|
+
list.push(`mex-align-${tunes.alignmentTune.alignment}`);
|
|
1838
|
+
if (tunes && tunes.textVariant) list.push(`mex-variant-${tunes.textVariant}`);
|
|
1839
|
+
if (tunes && tunes.indentTune && tunes.indentTune.indentLevel > 0)
|
|
1840
|
+
list.push(`mex-indent-${tunes.indentTune.indentLevel}`);
|
|
1841
|
+
return list.join(" ");
|
|
1842
|
+
};
|
|
1843
|
+
var listItems2 = (items, style, options, depth) => items.map((item) => {
|
|
1844
|
+
if (typeof item === "string") return el("li", {}, inlineToNodes(item, options));
|
|
1845
|
+
const checked = Boolean(item.meta && item.meta.checked);
|
|
1846
|
+
const check = style === "checklist" ? [
|
|
1847
|
+
el("input", {
|
|
1848
|
+
type: "checkbox",
|
|
1849
|
+
disabled: true,
|
|
1850
|
+
checked,
|
|
1851
|
+
"aria-label": checked ? "done" : "open"
|
|
1852
|
+
}),
|
|
1853
|
+
" "
|
|
1854
|
+
] : [];
|
|
1855
|
+
const nested = Array.isArray(item.items) && item.items.length && depth < 12 ? listElement(item.items, style, {}, options, depth + 1, []) : null;
|
|
1856
|
+
return el(
|
|
1857
|
+
"li",
|
|
1858
|
+
style === "checklist" ? { class: "mex-checklist-item", "data-checked": String(checked) } : {},
|
|
1859
|
+
[check, inlineToNodes(item.content, options), nested]
|
|
1860
|
+
);
|
|
1861
|
+
});
|
|
1862
|
+
var listElement = (items, style, meta, options, depth, base, tunes) => {
|
|
1863
|
+
const tag = style === "ordered" ? "ol" : "ul";
|
|
1864
|
+
const attrs = {};
|
|
1865
|
+
if (base.length) attrs.class = classes(base, tunes);
|
|
1866
|
+
if (style === "ordered" && meta) {
|
|
1867
|
+
if (Number.isInteger(meta.start) && meta.start !== 1) attrs.start = meta.start;
|
|
1868
|
+
if (COUNTER_TYPES[meta.counterType]) attrs.type = COUNTER_TYPES[meta.counterType];
|
|
1869
|
+
}
|
|
1870
|
+
return el(tag, attrs, listItems2(items, style, options, depth));
|
|
1871
|
+
};
|
|
1872
|
+
var figure = (url, img, caption, cls) => el("figure", { class: cls }, [
|
|
1873
|
+
el("img", { src: url, ...img, loading: "lazy", decoding: "async" }),
|
|
1874
|
+
caption.length ? el("figcaption", {}, caption) : null
|
|
1875
|
+
]);
|
|
1876
|
+
var withFocalPoint = (img, point, o) => {
|
|
1877
|
+
if (!point || img.type !== "element") return img;
|
|
1878
|
+
img.attrs["data-mex-focal-x"] = String(point.x);
|
|
1879
|
+
img.attrs["data-mex-focal-y"] = String(point.y);
|
|
1880
|
+
if (o.focalPoint === "style")
|
|
1881
|
+
img.style = { "object-position": `${Math.round(point.x * 100)}% ${Math.round(point.y * 100)}%` };
|
|
1882
|
+
return img;
|
|
1883
|
+
};
|
|
1884
|
+
var libraryImageAttrs = (file, decorative, o) => {
|
|
1885
|
+
const candidates = imageCandidates(file);
|
|
1886
|
+
const img = {
|
|
1887
|
+
alt: decorative ? "" : file.alt || "",
|
|
1888
|
+
width: Number.isInteger(file.width) && file.width > 0 ? file.width : void 0,
|
|
1889
|
+
height: Number.isInteger(file.height) && file.height > 0 ? file.height : void 0
|
|
1890
|
+
};
|
|
1891
|
+
if (candidates.length > 1) {
|
|
1892
|
+
img.srcset = candidates.map((c) => `${c.url} ${c.width}w`).join(", ");
|
|
1893
|
+
img.sizes = typeof o.imageSizes === "string" && /^[\w\s(),.:%-]{1,200}$/.test(o.imageSizes) ? o.imageSizes : "100vw";
|
|
1894
|
+
}
|
|
1895
|
+
return img;
|
|
1896
|
+
};
|
|
1897
|
+
var trackNodes = (b, o) => b.data.tracks.map((track) => {
|
|
1898
|
+
const file = resolveMedia(track.file, b, o, { vtt: true });
|
|
1899
|
+
if (!file.url) return null;
|
|
1900
|
+
return el("track", {
|
|
1901
|
+
kind: track.kind,
|
|
1902
|
+
src: file.url,
|
|
1903
|
+
srclang: track.srclang || void 0,
|
|
1904
|
+
label: track.label || void 0,
|
|
1905
|
+
default: track.default === true
|
|
1906
|
+
});
|
|
1907
|
+
}).filter(Boolean);
|
|
1908
|
+
var mediaFigure = (tag, b, o) => {
|
|
1909
|
+
const file = resolveMedia(b.data.file, b, o, { mimePrefix: `${tag}/` });
|
|
1910
|
+
if (!file.url) return null;
|
|
1911
|
+
const caption = inlineToNodes(b.data.caption, o);
|
|
1912
|
+
const attrs = {
|
|
1913
|
+
src: file.url,
|
|
1914
|
+
controls: true,
|
|
1915
|
+
preload: "metadata",
|
|
1916
|
+
"aria-label": b.data.title || void 0,
|
|
1917
|
+
loop: b.data.loop === true
|
|
1918
|
+
};
|
|
1919
|
+
if (tag === "video") {
|
|
1920
|
+
const poster = b.data.poster ? resolveMedia(b.data.poster, b, o) : null;
|
|
1921
|
+
Object.assign(attrs, {
|
|
1922
|
+
playsinline: true,
|
|
1923
|
+
muted: b.data.muted === true,
|
|
1924
|
+
poster: poster && poster.url ? poster.url : void 0,
|
|
1925
|
+
width: Number.isInteger(file.width) && file.width > 0 ? file.width : void 0,
|
|
1926
|
+
height: Number.isInteger(file.height) && file.height > 0 ? file.height : void 0
|
|
1927
|
+
});
|
|
1928
|
+
}
|
|
1929
|
+
return el("figure", { class: classes([`mex-${tag}`], b.tunes) }, [
|
|
1930
|
+
el(tag, attrs, [
|
|
1931
|
+
trackNodes(b, o),
|
|
1932
|
+
// Fallback for browsers without media support.
|
|
1933
|
+
el("a", { href: file.url }, b.data.title || file.name || file.url)
|
|
1934
|
+
]),
|
|
1935
|
+
caption.length ? el("figcaption", {}, caption) : null
|
|
1936
|
+
]);
|
|
1937
|
+
};
|
|
1938
|
+
var label = (value, fallback) => {
|
|
1939
|
+
if (typeof value !== "string") return fallback;
|
|
1940
|
+
const clean = value.trim();
|
|
1941
|
+
return clean && clean.length <= 80 ? clean : fallback;
|
|
1942
|
+
};
|
|
1943
|
+
var tocLabel = (options) => label(isPlainObject2(options.toc) ? options.toc.label : void 0, "Table of contents");
|
|
1944
|
+
var codeOptions = (options) => {
|
|
1945
|
+
const code = isPlainObject2(options.code) ? options.code : {};
|
|
1946
|
+
const lineNumbers = code.lineNumbers === true ? "all" : code.lineNumbers === "block" ? "block" : "none";
|
|
1947
|
+
const button = code.copyButton;
|
|
1948
|
+
const copy = button === true || isPlainObject2(button) ? {
|
|
1949
|
+
label: label(isPlainObject2(button) ? button.label : void 0, "Copy code"),
|
|
1950
|
+
copied: label(isPlainObject2(button) ? button.copiedLabel : void 0, "Copied"),
|
|
1951
|
+
failed: label(isPlainObject2(button) ? button.failedLabel : void 0, "Copy failed")
|
|
1952
|
+
} : null;
|
|
1953
|
+
return { lineNumbers, copy };
|
|
1954
|
+
};
|
|
1955
|
+
var numberedLines = (code) => {
|
|
1956
|
+
const parts = code.split("\n");
|
|
1957
|
+
const trailing = parts.length > 1 && parts[parts.length - 1] === "";
|
|
1958
|
+
if (trailing) parts.pop();
|
|
1959
|
+
const out = [];
|
|
1960
|
+
parts.forEach((line, index) => {
|
|
1961
|
+
if (index) out.push("\n");
|
|
1962
|
+
out.push(el("span", { class: "mex-code-line" }, line));
|
|
1963
|
+
});
|
|
1964
|
+
if (trailing) out.push("\n");
|
|
1965
|
+
return out;
|
|
1966
|
+
};
|
|
1967
|
+
var codeBlock = (b, language, o) => {
|
|
1968
|
+
const { lineNumbers, copy } = codeOptions(o);
|
|
1969
|
+
const code = String(b.data.code);
|
|
1970
|
+
const wantNumbers = lineNumbers === "all" || lineNumbers === "block" && b.type === "codeFlask" && b.data.showlinenumbers !== false;
|
|
1971
|
+
const numbers = wantNumbers && code.split("\n").length <= MAX_NUMBERED_LINES;
|
|
1972
|
+
const pre = el(
|
|
1973
|
+
"pre",
|
|
1974
|
+
{
|
|
1975
|
+
class: classes(["mex-code", ...numbers ? ["mex-code-lines"] : []], b.tunes),
|
|
1976
|
+
"data-language": language
|
|
1977
|
+
},
|
|
1978
|
+
el("code", language ? { class: `language-${language}` } : {}, numbers ? numberedLines(code) : code)
|
|
1979
|
+
);
|
|
1980
|
+
if (!copy) return pre;
|
|
1981
|
+
return el("div", { class: "mex-code-block", "data-mex-code": "copy" }, [
|
|
1982
|
+
pre,
|
|
1983
|
+
el(
|
|
1984
|
+
"button",
|
|
1985
|
+
{
|
|
1986
|
+
type: "button",
|
|
1987
|
+
class: "mex-code-copy",
|
|
1988
|
+
"data-mex-copy": "code",
|
|
1989
|
+
"data-mex-copied": copy.copied,
|
|
1990
|
+
"data-mex-failed": copy.failed
|
|
1991
|
+
},
|
|
1992
|
+
copy.label
|
|
1993
|
+
),
|
|
1994
|
+
el("span", { class: "mex-code-copy-status", role: "status", "aria-live": "polite" })
|
|
1995
|
+
]);
|
|
1996
|
+
};
|
|
1997
|
+
var RENDERERS = {
|
|
1998
|
+
paragraph: (b, o) => el("p", { class: classes(["mex-paragraph"], b.tunes) }, inlineToNodes(b.data.text, o)),
|
|
1999
|
+
header: (b, o) => el(
|
|
2000
|
+
`h${b.data.level}`,
|
|
2001
|
+
{ id: b.anchor, class: classes(["mex-header"], b.tunes) },
|
|
2002
|
+
inlineToNodes(b.data.text, o)
|
|
2003
|
+
),
|
|
2004
|
+
quote: (b, o) => {
|
|
2005
|
+
const caption = inlineToNodes(b.data.caption, o);
|
|
2006
|
+
return el(
|
|
2007
|
+
"figure",
|
|
2008
|
+
{
|
|
2009
|
+
class: classes(
|
|
2010
|
+
["mex-quote", ...b.data.alignment === "center" ? ["mex-align-center"] : []],
|
|
2011
|
+
b.tunes
|
|
2012
|
+
)
|
|
2013
|
+
},
|
|
2014
|
+
[
|
|
2015
|
+
el("blockquote", {}, inlineToNodes(b.data.text, o)),
|
|
2016
|
+
caption.length ? el("figcaption", {}, caption) : null
|
|
2017
|
+
]
|
|
2018
|
+
);
|
|
2019
|
+
},
|
|
2020
|
+
list: (b, o) => listElement(
|
|
2021
|
+
b.data.items,
|
|
2022
|
+
b.data.style,
|
|
2023
|
+
b.data.meta,
|
|
2024
|
+
o,
|
|
2025
|
+
0,
|
|
2026
|
+
b.data.style === "checklist" ? ["mex-list", "mex-checklist"] : ["mex-list"],
|
|
2027
|
+
b.tunes
|
|
2028
|
+
),
|
|
2029
|
+
checklist: (b, o) => listElement(
|
|
2030
|
+
b.data.items.map((item) => ({ content: item.text, meta: { checked: item.checked }, items: [] })),
|
|
2031
|
+
"checklist",
|
|
2032
|
+
{},
|
|
2033
|
+
o,
|
|
2034
|
+
0,
|
|
2035
|
+
["mex-list", "mex-checklist"],
|
|
2036
|
+
b.tunes
|
|
2037
|
+
),
|
|
2038
|
+
warning: (b, o) => {
|
|
2039
|
+
const title = inlineToNodes(b.data.title, o);
|
|
2040
|
+
return el("aside", { class: classes(["mex-warning"], b.tunes), role: "note" }, [
|
|
2041
|
+
title.length ? el("p", { class: "mex-warning-title" }, el("strong", {}, title)) : null,
|
|
2042
|
+
el("p", { class: "mex-warning-message" }, inlineToNodes(b.data.message, o))
|
|
2043
|
+
]);
|
|
2044
|
+
},
|
|
2045
|
+
alert: (b, o) => el(
|
|
2046
|
+
"div",
|
|
2047
|
+
{
|
|
2048
|
+
class: classes(
|
|
2049
|
+
[
|
|
2050
|
+
"mex-alert",
|
|
2051
|
+
`mex-alert-${b.data.type}`,
|
|
2052
|
+
...b.data.align !== "left" ? [`mex-align-${b.data.align}`] : []
|
|
2053
|
+
],
|
|
2054
|
+
b.tunes
|
|
2055
|
+
),
|
|
2056
|
+
role: "note"
|
|
2057
|
+
},
|
|
2058
|
+
inlineToNodes(b.data.message, o)
|
|
2059
|
+
),
|
|
2060
|
+
toggle: (b, o, renderList) => el("details", { class: classes(["mex-toggle"], b.tunes), open: b.data.status !== "closed" }, [
|
|
2061
|
+
el("summary", {}, inlineToNodes(b.data.text, o)),
|
|
2062
|
+
renderList(b.children)
|
|
2063
|
+
]),
|
|
2064
|
+
code: (b, o) => codeBlock(b, void 0, o),
|
|
2065
|
+
codeFlask: (b, o) => codeBlock(b, b.data.language, o),
|
|
2066
|
+
raw: (b, o) => {
|
|
2067
|
+
if (o.rawHtml !== "allow" || typeof o.sanitizeRaw !== "function") return null;
|
|
2068
|
+
const html = o.sanitizeRaw(String(b.raw.html || ""));
|
|
2069
|
+
return typeof html === "string" && html ? el("div", { class: classes(["mex-raw"], b.tunes) }, { type: "raw", html }) : null;
|
|
2070
|
+
},
|
|
2071
|
+
table: (b, o) => {
|
|
2072
|
+
const rows = b.data.content;
|
|
2073
|
+
if (!rows.length) return null;
|
|
2074
|
+
const cells = (row, tag) => el(
|
|
2075
|
+
"tr",
|
|
2076
|
+
{},
|
|
2077
|
+
row.map((cell) => el(tag, tag === "th" ? { scope: "col" } : {}, inlineToNodes(cell, o)))
|
|
2078
|
+
);
|
|
2079
|
+
const head = b.data.withHeadings ? el("thead", {}, cells(rows[0], "th")) : null;
|
|
2080
|
+
const body = (b.data.withHeadings ? rows.slice(1) : rows).map((row) => cells(row, "td"));
|
|
2081
|
+
return el(
|
|
2082
|
+
"table",
|
|
2083
|
+
{ class: classes(["mex-table", ...b.data.stretched ? ["mex-stretched"] : []], b.tunes) },
|
|
2084
|
+
[head, body.length ? el("tbody", {}, body) : null]
|
|
2085
|
+
);
|
|
2086
|
+
},
|
|
2087
|
+
image: (b, o) => {
|
|
2088
|
+
const file = resolveMedia(b.data.file, b, o);
|
|
2089
|
+
if (!file.url) return null;
|
|
2090
|
+
const img = libraryImageAttrs(file, b.raw.decorative === true, o);
|
|
2091
|
+
const cls = ["mex-image"];
|
|
2092
|
+
if (b.data.withBorder) cls.push("mex-image-border");
|
|
2093
|
+
if (b.data.withBackground) cls.push("mex-image-background");
|
|
2094
|
+
if (b.data.stretched) cls.push("mex-stretched");
|
|
2095
|
+
const node = figure(file.url, img, inlineToNodes(b.data.caption, o), classes(cls, b.tunes));
|
|
2096
|
+
withFocalPoint(node.children[0], b.data.focalPoint, o);
|
|
2097
|
+
return node;
|
|
2098
|
+
},
|
|
2099
|
+
simpleImage: (b, o) => {
|
|
2100
|
+
if (!b.data.url) return null;
|
|
2101
|
+
const cls = ["mex-image"];
|
|
2102
|
+
if (b.data.withBorder) cls.push("mex-image-border");
|
|
2103
|
+
if (b.data.withBackground) cls.push("mex-image-background");
|
|
2104
|
+
if (b.data.stretched) cls.push("mex-stretched");
|
|
2105
|
+
return figure(
|
|
2106
|
+
b.data.url,
|
|
2107
|
+
{
|
|
2108
|
+
alt: b.data.decorative === true ? "" : typeof b.data.alt === "string" && b.data.alt.trim() ? b.data.alt : inlineToText(b.data.caption)
|
|
2109
|
+
},
|
|
2110
|
+
inlineToNodes(b.data.caption, o),
|
|
2111
|
+
classes(cls, b.tunes)
|
|
2112
|
+
);
|
|
2113
|
+
},
|
|
2114
|
+
gallery: (b, o) => {
|
|
2115
|
+
const items = b.data.images.map((image) => {
|
|
2116
|
+
const file = resolveMedia(image.file, b, o);
|
|
2117
|
+
if (!file.url) return null;
|
|
2118
|
+
const caption2 = inlineToNodes(image.caption, o);
|
|
2119
|
+
const img = el("img", {
|
|
2120
|
+
src: file.url,
|
|
2121
|
+
...libraryImageAttrs(file, image.decorative === true, o),
|
|
2122
|
+
loading: "lazy",
|
|
2123
|
+
decoding: "async"
|
|
2124
|
+
});
|
|
2125
|
+
withFocalPoint(img, image.focalPoint, o);
|
|
2126
|
+
return el(
|
|
2127
|
+
"li",
|
|
2128
|
+
{ class: "mex-gallery-item" },
|
|
2129
|
+
el("figure", { class: "mex-gallery-figure" }, [
|
|
2130
|
+
img,
|
|
2131
|
+
caption2.length ? el("figcaption", {}, caption2) : null
|
|
2132
|
+
])
|
|
2133
|
+
);
|
|
2134
|
+
}).filter(Boolean);
|
|
2135
|
+
if (!items.length) return null;
|
|
2136
|
+
const { layout, columns } = b.data;
|
|
2137
|
+
const caption = inlineToNodes(b.data.caption, o);
|
|
2138
|
+
return el(
|
|
2139
|
+
"figure",
|
|
2140
|
+
{
|
|
2141
|
+
class: classes(["mex-gallery", `mex-gallery-${layout}`, `mex-gallery-cols-${columns}`], b.tunes),
|
|
2142
|
+
"data-mex-layout": layout,
|
|
2143
|
+
"data-mex-columns": String(columns)
|
|
2144
|
+
},
|
|
2145
|
+
[el("ul", { class: "mex-gallery-items" }, items), caption.length ? el("figcaption", {}, caption) : null]
|
|
2146
|
+
);
|
|
2147
|
+
},
|
|
2148
|
+
video: (b, o) => mediaFigure("video", b, o),
|
|
2149
|
+
audio: (b, o) => mediaFigure("audio", b, o),
|
|
2150
|
+
linkTool: (b) => {
|
|
2151
|
+
if (!b.data.link) return null;
|
|
2152
|
+
const meta = b.data.meta;
|
|
2153
|
+
return el(
|
|
2154
|
+
"div",
|
|
2155
|
+
{ class: classes(["mex-link-preview"], b.tunes) },
|
|
2156
|
+
el("a", { href: b.data.link, rel: "nofollow noopener noreferrer" }, [
|
|
2157
|
+
meta.image && meta.image.url ? el("img", { class: "mex-link-image", src: meta.image.url, alt: "", loading: "lazy" }) : null,
|
|
2158
|
+
el("span", { class: "mex-link-title" }, meta.title || b.data.link),
|
|
2159
|
+
meta.description ? el("span", { class: "mex-link-description" }, meta.description) : null,
|
|
2160
|
+
meta.site_name ? el("span", { class: "mex-link-site" }, meta.site_name) : null
|
|
2161
|
+
])
|
|
2162
|
+
);
|
|
2163
|
+
},
|
|
2164
|
+
attaches: (b) => {
|
|
2165
|
+
const file = b.data.file;
|
|
2166
|
+
if (!file.url) return null;
|
|
2167
|
+
const text = b.data.title || file.title || file.name || file.url;
|
|
2168
|
+
const details = [file.extension ? file.extension.toUpperCase() : "", formatSize(file.size)].filter(Boolean).join(", ");
|
|
2169
|
+
return el("p", { class: classes(["mex-attachment"], b.tunes) }, [
|
|
2170
|
+
el("a", { href: file.url, download: true }, text),
|
|
2171
|
+
details ? [" ", el("span", { class: "mex-attachment-meta" }, `(${details})`)] : null
|
|
2172
|
+
]);
|
|
2173
|
+
},
|
|
2174
|
+
embed: (b, o) => {
|
|
2175
|
+
const hosts = Array.isArray(o.embedHosts) ? o.embedHosts.map((h) => String(h).toLowerCase()) : DEFAULT_EMBED_HOSTS;
|
|
2176
|
+
const frame = embedFrameUrl(b.data.embed, hosts);
|
|
2177
|
+
const caption = inlineToNodes(b.data.caption, o);
|
|
2178
|
+
const title = inlineToText(b.data.caption) || b.data.service || "Embedded content";
|
|
2179
|
+
if (!frame) {
|
|
2180
|
+
const href = b.data.source || b.data.embed;
|
|
2181
|
+
if (!href) return null;
|
|
2182
|
+
return el(
|
|
2183
|
+
"p",
|
|
2184
|
+
{ class: classes(["mex-embed", "mex-embed-link"], b.tunes) },
|
|
2185
|
+
el("a", { href, rel: "nofollow noopener noreferrer" }, caption.length ? caption : href)
|
|
2186
|
+
);
|
|
2187
|
+
}
|
|
2188
|
+
return el(
|
|
2189
|
+
"figure",
|
|
2190
|
+
{
|
|
2191
|
+
class: classes(
|
|
2192
|
+
["mex-embed", b.data.service ? `mex-embed-${b.data.service}` : ""].filter(Boolean),
|
|
2193
|
+
b.tunes
|
|
2194
|
+
)
|
|
2195
|
+
},
|
|
2196
|
+
[
|
|
2197
|
+
el("iframe", {
|
|
2198
|
+
src: frame,
|
|
2199
|
+
title,
|
|
2200
|
+
width: b.data.width,
|
|
2201
|
+
height: b.data.height,
|
|
2202
|
+
loading: "lazy",
|
|
2203
|
+
referrerpolicy: "strict-origin-when-cross-origin",
|
|
2204
|
+
sandbox: "allow-scripts allow-same-origin allow-popups allow-presentation",
|
|
2205
|
+
allow: "fullscreen; picture-in-picture; encrypted-media",
|
|
2206
|
+
allowfullscreen: true
|
|
2207
|
+
}),
|
|
2208
|
+
caption.length ? el("figcaption", {}, caption) : null
|
|
2209
|
+
]
|
|
2210
|
+
);
|
|
2211
|
+
},
|
|
2212
|
+
personality: (b) => {
|
|
2213
|
+
const d = b.data;
|
|
2214
|
+
if (!d.name && !d.description) return null;
|
|
2215
|
+
return el("div", { class: classes(["mex-personality"], b.tunes) }, [
|
|
2216
|
+
d.photo ? el("img", { class: "mex-personality-photo", src: d.photo, alt: "", loading: "lazy" }) : null,
|
|
2217
|
+
el("div", { class: "mex-personality-body" }, [
|
|
2218
|
+
d.name ? el("p", { class: "mex-personality-name" }, d.name) : null,
|
|
2219
|
+
d.description ? el("p", { class: "mex-personality-description" }, d.description) : null,
|
|
2220
|
+
d.link ? el("a", { class: "mex-personality-link", href: d.link }, d.link) : null
|
|
2221
|
+
])
|
|
2222
|
+
]);
|
|
2223
|
+
},
|
|
2224
|
+
button: (b) => {
|
|
2225
|
+
const d = b.data;
|
|
2226
|
+
if (!d.text) return null;
|
|
2227
|
+
const cls = `mex-button mex-button-${d.style}`;
|
|
2228
|
+
const inner = d.link ? el(
|
|
2229
|
+
"a",
|
|
2230
|
+
{
|
|
2231
|
+
class: cls,
|
|
2232
|
+
href: d.link,
|
|
2233
|
+
target: d.openInNewTab ? "_blank" : void 0,
|
|
2234
|
+
rel: d.openInNewTab ? "noopener noreferrer" : void 0
|
|
2235
|
+
},
|
|
2236
|
+
d.text
|
|
2237
|
+
) : el("span", { class: cls }, d.text);
|
|
2238
|
+
return el("p", { class: classes(["mex-button-block"], b.tunes) }, inner);
|
|
2239
|
+
},
|
|
2240
|
+
delimiter: (b) => el("hr", { class: classes(["mex-delimiter"], b.tunes) }),
|
|
2241
|
+
toc: (b, o) => {
|
|
2242
|
+
const tree = buildTocTree(b.headings || [], b.data);
|
|
2243
|
+
if (!tree.length) return null;
|
|
2244
|
+
const tag = b.data.style === "ordered" ? "ol" : "ul";
|
|
2245
|
+
const list = (nodes) => el(
|
|
2246
|
+
tag,
|
|
2247
|
+
{ class: "mex-toc-list" },
|
|
2248
|
+
nodes.map(
|
|
2249
|
+
(node) => el("li", { class: "mex-toc-item" }, [
|
|
2250
|
+
b.linkHeadings && node.id ? el("a", { href: `#${node.id}` }, node.text) : node.text,
|
|
2251
|
+
node.children.length ? list(node.children) : null
|
|
2252
|
+
])
|
|
2253
|
+
)
|
|
2254
|
+
);
|
|
2255
|
+
const title = b.data.title.trim();
|
|
2256
|
+
return el(
|
|
2257
|
+
"nav",
|
|
2258
|
+
{
|
|
2259
|
+
class: classes(["mex-toc", `mex-toc-${b.data.style}`], b.tunes),
|
|
2260
|
+
"aria-label": title || tocLabel(o)
|
|
2261
|
+
},
|
|
2262
|
+
[title ? el("p", { class: "mex-toc-title" }, title) : null, list(tree)]
|
|
2263
|
+
);
|
|
2264
|
+
}
|
|
2265
|
+
};
|
|
2266
|
+
var neutral = (b) => el(
|
|
2267
|
+
"div",
|
|
2268
|
+
{ class: classes(["mex-block", `mex-${b.type}`], b.tunes), "data-mex-block": b.type },
|
|
2269
|
+
scalarFields(b.data).map(
|
|
2270
|
+
([key, value]) => el("div", { class: "mex-field", "data-mex-field": key }, inlineToText(value))
|
|
2271
|
+
)
|
|
2272
|
+
);
|
|
2273
|
+
var registeredDefault = (b, o) => {
|
|
2274
|
+
const children = [];
|
|
2275
|
+
for (const [key, field] of Object.entries(b.definition.schema)) {
|
|
2276
|
+
const value = b.data[key];
|
|
2277
|
+
if (value === void 0 || value === null || value === "") continue;
|
|
2278
|
+
const attrs = { class: "mex-field", "data-mex-field": key };
|
|
2279
|
+
if (field.type === "inline") children.push(el("div", attrs, inlineToNodes(value, o)));
|
|
2280
|
+
else if (field.type === "url") children.push(el("div", attrs, el("a", { href: value }, value)));
|
|
2281
|
+
else if (["text", "enum", "number", "boolean"].includes(field.type))
|
|
2282
|
+
children.push(el("div", attrs, String(value)));
|
|
2283
|
+
}
|
|
2284
|
+
return el(
|
|
2285
|
+
"div",
|
|
2286
|
+
{ class: classes(["mex-block", `mex-${b.type}`], b.tunes), "data-mex-block": b.type },
|
|
2287
|
+
children
|
|
2288
|
+
);
|
|
2289
|
+
};
|
|
2290
|
+
var DENIED_TAGS = /* @__PURE__ */ new Set([
|
|
2291
|
+
"script",
|
|
2292
|
+
"style",
|
|
2293
|
+
"base",
|
|
2294
|
+
"meta",
|
|
2295
|
+
"link",
|
|
2296
|
+
"head",
|
|
2297
|
+
"html",
|
|
2298
|
+
"body",
|
|
2299
|
+
"title",
|
|
2300
|
+
"object",
|
|
2301
|
+
"embed",
|
|
2302
|
+
"applet",
|
|
2303
|
+
"frame",
|
|
2304
|
+
"frameset",
|
|
2305
|
+
"template",
|
|
2306
|
+
"noscript",
|
|
2307
|
+
"noembed",
|
|
2308
|
+
"noframes",
|
|
2309
|
+
"svg",
|
|
2310
|
+
"math",
|
|
2311
|
+
"xmp",
|
|
2312
|
+
"plaintext",
|
|
2313
|
+
"form"
|
|
2314
|
+
]);
|
|
2315
|
+
var URL_ATTRIBUTES = /* @__PURE__ */ new Set([
|
|
2316
|
+
"href",
|
|
2317
|
+
"src",
|
|
2318
|
+
"action",
|
|
2319
|
+
"formaction",
|
|
2320
|
+
"poster",
|
|
2321
|
+
"cite",
|
|
2322
|
+
"data",
|
|
2323
|
+
"background",
|
|
2324
|
+
"longdesc",
|
|
2325
|
+
"manifest",
|
|
2326
|
+
"ping",
|
|
2327
|
+
"xmlns"
|
|
2328
|
+
]);
|
|
2329
|
+
var RESOURCE_ATTRIBUTES = /* @__PURE__ */ new Set(["src", "poster", "data", "background", "manifest", "ping"]);
|
|
2330
|
+
var cleanUrlAttribute = (name, value) => {
|
|
2331
|
+
if (name === "srcset" || name === "imagesrcset") {
|
|
2332
|
+
const parts = value.split(",").map((part) => part.trim());
|
|
2333
|
+
const clean = [];
|
|
2334
|
+
for (const part of parts) {
|
|
2335
|
+
const [url, descriptor, extra] = part.split(/\s+/);
|
|
2336
|
+
if (extra !== void 0 || descriptor && !/^\d+(?:\.\d+)?[wx]$/.test(descriptor)) return "";
|
|
2337
|
+
const safe = sanitizeUrl(url, { schemes: ["http", "https"] });
|
|
2338
|
+
if (!safe) return "";
|
|
2339
|
+
clean.push(descriptor ? `${safe} ${descriptor}` : safe);
|
|
2340
|
+
}
|
|
2341
|
+
return clean.join(", ");
|
|
2342
|
+
}
|
|
2343
|
+
return sanitizeUrl(value, { schemes: RESOURCE_ATTRIBUTES.has(name) ? ["http", "https"] : LINK_SCHEMES });
|
|
2344
|
+
};
|
|
2345
|
+
var MAX_OVERRIDE_DEPTH = 64;
|
|
2346
|
+
var MAX_OVERRIDE_NODES = 5e4;
|
|
2347
|
+
var cleanOverrideNodes = (input, trusted) => {
|
|
2348
|
+
let budget = MAX_OVERRIDE_NODES;
|
|
2349
|
+
const visit = (value, depth) => {
|
|
2350
|
+
const list = Array.isArray(value) ? value.flat(Infinity) : [value];
|
|
2351
|
+
const out = [];
|
|
2352
|
+
for (const node of list) {
|
|
2353
|
+
if (budget <= 0 || depth > MAX_OVERRIDE_DEPTH) break;
|
|
2354
|
+
if (typeof node === "string" || typeof node === "number") {
|
|
2355
|
+
if (node !== "") out.push(textNode(node));
|
|
2356
|
+
continue;
|
|
2357
|
+
}
|
|
2358
|
+
if (!isPlainObject2(node)) continue;
|
|
2359
|
+
if (trusted.has(node)) {
|
|
2360
|
+
out.push(node);
|
|
2361
|
+
continue;
|
|
2362
|
+
}
|
|
2363
|
+
budget -= 1;
|
|
2364
|
+
if (node.type === "text") {
|
|
2365
|
+
out.push(textNode(typeof node.value === "string" ? node.value : ""));
|
|
2366
|
+
continue;
|
|
2367
|
+
}
|
|
2368
|
+
if (node.type !== "element" || typeof node.tag !== "string") continue;
|
|
2369
|
+
const tag = node.tag;
|
|
2370
|
+
if (!TAG_NAME.test(tag) || DENIED_TAGS.has(tag)) continue;
|
|
2371
|
+
const attrs = {};
|
|
2372
|
+
for (const [name, raw] of Object.entries(isPlainObject2(node.attrs) ? node.attrs : {})) {
|
|
2373
|
+
if (!isSafeAttributeName(name)) continue;
|
|
2374
|
+
if (raw === true) {
|
|
2375
|
+
if (!URL_ATTRIBUTES.has(name)) attrs[name] = true;
|
|
2376
|
+
continue;
|
|
2377
|
+
}
|
|
2378
|
+
if (!["string", "number"].includes(typeof raw)) continue;
|
|
2379
|
+
const text = String(raw).slice(0, 1e4);
|
|
2380
|
+
if (URL_ATTRIBUTES.has(name) || name === "srcset" || name === "imagesrcset") {
|
|
2381
|
+
const url = cleanUrlAttribute(name, text);
|
|
2382
|
+
if (url) attrs[name] = url;
|
|
2383
|
+
} else if (text !== "" || name === "alt") attrs[name] = text;
|
|
2384
|
+
}
|
|
2385
|
+
if (tag === "iframe" && !attrs.src) continue;
|
|
2386
|
+
out.push({
|
|
2387
|
+
type: "element",
|
|
2388
|
+
tag,
|
|
2389
|
+
attrs,
|
|
2390
|
+
children: visit(Array.isArray(node.children) ? node.children : [], depth + 1)
|
|
2391
|
+
});
|
|
2392
|
+
}
|
|
2393
|
+
return out;
|
|
2394
|
+
};
|
|
2395
|
+
return visit(input, 0);
|
|
2396
|
+
};
|
|
2397
|
+
var rawAllowed = (options) => options.rawHtml === "allow" && typeof options.sanitizeRaw === "function";
|
|
2398
|
+
var createTreeBuilder = (value, options, mode = {}) => {
|
|
2399
|
+
const opts = options && typeof options === "object" ? options : {};
|
|
2400
|
+
const publicOf = /* @__PURE__ */ new WeakMap();
|
|
2401
|
+
const preparedOf = /* @__PURE__ */ new WeakMap();
|
|
2402
|
+
const trusted = /* @__PURE__ */ new WeakSet();
|
|
2403
|
+
const toPublic = (block) => {
|
|
2404
|
+
const known = publicOf.get(block);
|
|
2405
|
+
if (known) return known;
|
|
2406
|
+
const pub = {
|
|
2407
|
+
id: block.id,
|
|
2408
|
+
type: block.type,
|
|
2409
|
+
data: block.data,
|
|
2410
|
+
tunes: block.tunes,
|
|
2411
|
+
children: block.children.map(toPublic)
|
|
2412
|
+
};
|
|
2413
|
+
publicOf.set(block, pub);
|
|
2414
|
+
preparedOf.set(pub, block);
|
|
2415
|
+
return pub;
|
|
2416
|
+
};
|
|
2417
|
+
const blockContent = (block) => {
|
|
2418
|
+
const override = overrideFor(opts, block.type);
|
|
2419
|
+
if (override) {
|
|
2420
|
+
const out = override(toPublic(block), helpers);
|
|
2421
|
+
if (typeof out === "string") {
|
|
2422
|
+
if (mode.overrideHtml) return out ? [{ type: "raw", html: out }] : [];
|
|
2423
|
+
if (rawAllowed(opts)) {
|
|
2424
|
+
const html = opts.sanitizeRaw(out);
|
|
2425
|
+
return typeof html === "string" && html ? [el("div", { class: "mex-override", "data-mex-block": block.type }, { type: "raw", html })] : [];
|
|
2426
|
+
}
|
|
2427
|
+
} else if (out && typeof out === "object") {
|
|
2428
|
+
return cleanOverrideNodes(out, trusted);
|
|
2429
|
+
}
|
|
2430
|
+
}
|
|
2431
|
+
if (block.known) return toNodes(RENDERERS[block.type](block, opts, renderList));
|
|
2432
|
+
if (block.definition) return registeredContent(block);
|
|
2433
|
+
return [neutral(block)];
|
|
2434
|
+
};
|
|
2435
|
+
const registeredContent = (block) => {
|
|
2436
|
+
const render = block.definition.render;
|
|
2437
|
+
if (render) {
|
|
2438
|
+
let out;
|
|
2439
|
+
try {
|
|
2440
|
+
out = render(toPublic(block), helpers);
|
|
2441
|
+
} catch {
|
|
2442
|
+
out = void 0;
|
|
2443
|
+
}
|
|
2444
|
+
if (typeof out === "string") {
|
|
2445
|
+
if (rawAllowed(opts)) {
|
|
2446
|
+
const html = opts.sanitizeRaw(out);
|
|
2447
|
+
if (typeof html === "string" && html)
|
|
2448
|
+
return [
|
|
2449
|
+
el("div", { class: "mex-override", "data-mex-block": block.type }, { type: "raw", html })
|
|
2450
|
+
];
|
|
2451
|
+
}
|
|
2452
|
+
} else if (out && typeof out === "object") {
|
|
2453
|
+
return cleanOverrideNodes(out, trusted);
|
|
2454
|
+
}
|
|
2455
|
+
}
|
|
2456
|
+
return [registeredDefault(block, opts)];
|
|
2457
|
+
};
|
|
2458
|
+
function renderList(blocks) {
|
|
2459
|
+
const out = [];
|
|
2460
|
+
for (const block of blocks) {
|
|
2461
|
+
const children = blockContent(block);
|
|
2462
|
+
if (!children.length) continue;
|
|
2463
|
+
const node = { type: "block", block: toPublic(block), children };
|
|
2464
|
+
trusted.add(node);
|
|
2465
|
+
if (out.length) out.push(textNode("\n"));
|
|
2466
|
+
out.push(node);
|
|
2467
|
+
}
|
|
2468
|
+
return out;
|
|
2469
|
+
}
|
|
2470
|
+
const renderBlocks = (blocks) => renderList((Array.isArray(blocks) ? blocks : []).map((b) => preparedOf.get(b)).filter(Boolean));
|
|
2471
|
+
const helpers = {
|
|
2472
|
+
escape: escapeHtml2,
|
|
2473
|
+
inline: (html) => inlineToHtml(html, opts),
|
|
2474
|
+
text: (html) => inlineToText(html),
|
|
2475
|
+
url: (input, schemes) => sanitizeUrl(input, schemes ? { schemes } : void 0),
|
|
2476
|
+
renderChildren: (blocks) => serializeNodes(renderBlocks(blocks)),
|
|
2477
|
+
h: (tag, attrs, children) => el(String(tag), attrs, children),
|
|
2478
|
+
textNode,
|
|
2479
|
+
inlineNodes: (html) => inlineToNodes(html, opts),
|
|
2480
|
+
childNodes: renderBlocks
|
|
2481
|
+
};
|
|
2482
|
+
const nodes = renderList(annotateHeadings(prepareBlocks(value, opts), opts));
|
|
2483
|
+
return { nodes, renderBlocks, helpers };
|
|
2484
|
+
};
|
|
2485
|
+
|
|
2486
|
+
// shared/render/dom.mjs
|
|
2487
|
+
var copyText = async (text) => {
|
|
2488
|
+
try {
|
|
2489
|
+
if (typeof navigator === "undefined" || !navigator.clipboard || !navigator.clipboard.writeText)
|
|
2490
|
+
return false;
|
|
2491
|
+
await navigator.clipboard.writeText(text);
|
|
2492
|
+
return true;
|
|
2493
|
+
} catch {
|
|
2494
|
+
return false;
|
|
2495
|
+
}
|
|
2496
|
+
};
|
|
2497
|
+
|
|
2498
|
+
// shared/frameworks/common.mjs
|
|
2499
|
+
var isRenderableElement = (node) => typeof node.tag === "string" && TAG_NAME.test(node.tag) && node.tag !== "script" && node.tag !== "style";
|
|
2500
|
+
var safeAttributes = (attrs) => Object.entries(attrs || {}).filter(
|
|
2501
|
+
([name, value]) => isSafeAttributeName(name) && (value === true || typeof value === "string")
|
|
2502
|
+
);
|
|
2503
|
+
var rawInner = (node) => node.children.length === 1 && node.children[0].type === "raw" ? String(node.children[0].html) : null;
|
|
2504
|
+
var isCopyBlock = (node) => node.type === "element" && Boolean(node.attrs) && node.attrs["data-mex-code"] === "copy";
|
|
2505
|
+
var copyBlockParts = (node) => {
|
|
2506
|
+
const pre = node.children.find((child) => child.type === "element" && child.tag === "pre");
|
|
2507
|
+
const button = node.children.find(
|
|
2508
|
+
(child) => child.type === "element" && child.tag === "button" && child.attrs["data-mex-copy"]
|
|
2509
|
+
);
|
|
2510
|
+
return {
|
|
2511
|
+
text: pre ? nodesTextContent(pre.children) : "",
|
|
2512
|
+
copied: button && button.attrs["data-mex-copied"] || "Copied",
|
|
2513
|
+
failed: button && button.attrs["data-mex-failed"] || "Copy failed"
|
|
2514
|
+
};
|
|
2515
|
+
};
|
|
2516
|
+
var componentFor = (components, type) => {
|
|
2517
|
+
if (!components || typeof components !== "object") return null;
|
|
2518
|
+
if (!Object.prototype.hasOwnProperty.call(components, type)) return null;
|
|
2519
|
+
const component = components[type];
|
|
2520
|
+
return typeof component === "function" || component && typeof component === "object" ? component : null;
|
|
2521
|
+
};
|
|
2522
|
+
|
|
2523
|
+
// shared/frameworks/react.mjs
|
|
2524
|
+
var React = ReactNamespace.default && typeof ReactNamespace.default.createElement === "function" ? ReactNamespace.default : ReactNamespace;
|
|
2525
|
+
var PROP_NAMES = Object.freeze({
|
|
2526
|
+
class: "className",
|
|
2527
|
+
for: "htmlFor",
|
|
2528
|
+
accesskey: "accessKey",
|
|
2529
|
+
allowfullscreen: "allowFullScreen",
|
|
2530
|
+
autoplay: "autoPlay",
|
|
2531
|
+
colspan: "colSpan",
|
|
2532
|
+
contenteditable: "contentEditable",
|
|
2533
|
+
controlslist: "controlsList",
|
|
2534
|
+
crossorigin: "crossOrigin",
|
|
2535
|
+
datetime: "dateTime",
|
|
2536
|
+
disablepictureinpicture: "disablePictureInPicture",
|
|
2537
|
+
frameborder: "frameBorder",
|
|
2538
|
+
hreflang: "hrefLang",
|
|
2539
|
+
imagesizes: "imageSizes",
|
|
2540
|
+
imagesrcset: "imageSrcSet",
|
|
2541
|
+
itemprop: "itemProp",
|
|
2542
|
+
itemscope: "itemScope",
|
|
2543
|
+
itemtype: "itemType",
|
|
2544
|
+
maxlength: "maxLength",
|
|
2545
|
+
playsinline: "playsInline",
|
|
2546
|
+
readonly: "readOnly",
|
|
2547
|
+
referrerpolicy: "referrerPolicy",
|
|
2548
|
+
rowspan: "rowSpan",
|
|
2549
|
+
spellcheck: "spellCheck",
|
|
2550
|
+
srclang: "srcLang",
|
|
2551
|
+
srcset: "srcSet",
|
|
2552
|
+
tabindex: "tabIndex",
|
|
2553
|
+
usemap: "useMap"
|
|
2554
|
+
});
|
|
2555
|
+
var BOOLEAN_PROPS = /* @__PURE__ */ new Set([
|
|
2556
|
+
"allowfullscreen",
|
|
2557
|
+
"async",
|
|
2558
|
+
"autofocus",
|
|
2559
|
+
"autoplay",
|
|
2560
|
+
"checked",
|
|
2561
|
+
"controls",
|
|
2562
|
+
"default",
|
|
2563
|
+
"defer",
|
|
2564
|
+
"disabled",
|
|
2565
|
+
"disablepictureinpicture",
|
|
2566
|
+
"download",
|
|
2567
|
+
"formnovalidate",
|
|
2568
|
+
"hidden",
|
|
2569
|
+
"itemscope",
|
|
2570
|
+
"loop",
|
|
2571
|
+
"multiple",
|
|
2572
|
+
"muted",
|
|
2573
|
+
"novalidate",
|
|
2574
|
+
"open",
|
|
2575
|
+
"playsinline",
|
|
2576
|
+
"readonly",
|
|
2577
|
+
"required",
|
|
2578
|
+
"reversed",
|
|
2579
|
+
"selected"
|
|
2580
|
+
]);
|
|
2581
|
+
var propsOf = (node, key) => {
|
|
2582
|
+
const props = { key };
|
|
2583
|
+
for (const [name, value] of safeAttributes(node.attrs)) {
|
|
2584
|
+
props[PROP_NAMES[name] || name] = value === true && !BOOLEAN_PROPS.has(name) ? "" : value;
|
|
2585
|
+
}
|
|
2586
|
+
const style = safeStyle(node.style);
|
|
2587
|
+
if (style.length)
|
|
2588
|
+
props.style = Object.fromEntries(
|
|
2589
|
+
style.map(([name, value]) => [name.replace(/-([a-z])/g, (_m, c) => c.toUpperCase()), value])
|
|
2590
|
+
);
|
|
2591
|
+
return props;
|
|
2592
|
+
};
|
|
2593
|
+
var CodeCopyBlock = ({ node, ctx }) => {
|
|
2594
|
+
if (typeof React.useState !== "function") {
|
|
2595
|
+
const { key: _key2, ...props2 } = propsOf(node, "root");
|
|
2596
|
+
return React.createElement("div", props2, ...renderNodes(node.children, ctx));
|
|
2597
|
+
}
|
|
2598
|
+
const [status, setStatus] = React.useState("");
|
|
2599
|
+
const parts = copyBlockParts(node);
|
|
2600
|
+
const onClick = () => {
|
|
2601
|
+
copyText(parts.text).then((ok) => setStatus(ok ? parts.copied : parts.failed));
|
|
2602
|
+
};
|
|
2603
|
+
const children = node.children.map((child, index) => {
|
|
2604
|
+
const key = `c${index}`;
|
|
2605
|
+
if (child.type === "element" && child.tag === "button" && child.attrs["data-mex-copy"])
|
|
2606
|
+
return React.createElement(
|
|
2607
|
+
"button",
|
|
2608
|
+
{ ...propsOf(child, key), onClick },
|
|
2609
|
+
...renderNodes(child.children, ctx)
|
|
2610
|
+
);
|
|
2611
|
+
if (child.type === "element" && child.attrs.role === "status")
|
|
2612
|
+
return React.createElement(child.tag, propsOf(child, key), status);
|
|
2613
|
+
return renderNode(child, ctx, key);
|
|
2614
|
+
});
|
|
2615
|
+
const { key: _key, ...props } = propsOf(node, "root");
|
|
2616
|
+
return React.createElement("div", props, ...children);
|
|
2617
|
+
};
|
|
2618
|
+
var renderNode = (node, ctx, key) => {
|
|
2619
|
+
if (!node || typeof node !== "object") return null;
|
|
2620
|
+
if (node.type === "text") return node.value;
|
|
2621
|
+
if (node.type === "block") {
|
|
2622
|
+
const children = renderNodes(node.children, ctx);
|
|
2623
|
+
const Component = componentFor(ctx.components, node.block.type);
|
|
2624
|
+
if (Component)
|
|
2625
|
+
return React.createElement(Component, { key, block: node.block, helpers: ctx.helpers, children });
|
|
2626
|
+
return React.createElement(React.Fragment, { key }, ...children);
|
|
2627
|
+
}
|
|
2628
|
+
if (node.type !== "element" || !isRenderableElement(node)) return null;
|
|
2629
|
+
if (isCopyBlock(node)) return React.createElement(CodeCopyBlock, { key, node, ctx });
|
|
2630
|
+
const props = propsOf(node, key);
|
|
2631
|
+
if (VOID_TAGS.has(node.tag)) return React.createElement(node.tag, props);
|
|
2632
|
+
const html = rawInner(node);
|
|
2633
|
+
if (html !== null)
|
|
2634
|
+
return React.createElement(node.tag, { ...props, dangerouslySetInnerHTML: { __html: html } });
|
|
2635
|
+
return React.createElement(node.tag, props, ...renderNodes(node.children, ctx));
|
|
2636
|
+
};
|
|
2637
|
+
function renderNodes(nodes, ctx) {
|
|
2638
|
+
return nodes.map((node, index) => renderNode(node, ctx, `n${index}`)).filter((n) => n !== null);
|
|
2639
|
+
}
|
|
2640
|
+
var MagicEditorXContent = ({ value, options, components }) => {
|
|
2641
|
+
const builder = createTreeBuilder(value, options);
|
|
2642
|
+
const ctx = { components, helpers: {} };
|
|
2643
|
+
ctx.helpers = {
|
|
2644
|
+
text: builder.helpers.text,
|
|
2645
|
+
url: builder.helpers.url,
|
|
2646
|
+
inline: (html) => renderNodes(builder.helpers.inlineNodes(html), ctx),
|
|
2647
|
+
renderBlocks: (blocks) => renderNodes(builder.renderBlocks(blocks), ctx)
|
|
2648
|
+
};
|
|
2649
|
+
return React.createElement(React.Fragment, null, ...renderNodes(builder.nodes, ctx));
|
|
2650
|
+
};
|
|
2651
|
+
var treeToReact = (nodes) => renderNodes(Array.isArray(nodes) ? nodes : [], { components: null, helpers: {} });
|
|
2652
|
+
var react_default = MagicEditorXContent;
|
|
2653
|
+
export {
|
|
2654
|
+
MagicEditorXContent,
|
|
2655
|
+
react_default as default,
|
|
2656
|
+
treeToReact
|
|
2657
|
+
};
|