magic-editor-x 1.6.0 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (97) hide show
  1. package/CHANGELOG.md +322 -0
  2. package/LICENSE +1 -7
  3. package/README.md +398 -969
  4. package/dist/admin/ConfigurationPage-CK2AbfGW.mjs +886 -0
  5. package/dist/admin/ConfigurationPage-CzsT_dO_.js +888 -0
  6. package/dist/admin/CustomBlocksPage-B2A8S5MV.mjs +1741 -0
  7. package/dist/admin/CustomBlocksPage-CvLrsBds.js +1743 -0
  8. package/dist/admin/EditorField-7YCdXx-v.mjs +6829 -0
  9. package/dist/admin/EditorField-BdBCW15Q.js +6864 -0
  10. package/dist/admin/api-CmccMxlN.js +36 -0
  11. package/dist/admin/api-D5CAH0nh.mjs +37 -0
  12. package/dist/admin/de-BHPyA2S-.mjs +103 -0
  13. package/dist/admin/de-Bt6pYIWi.mjs +246 -0
  14. package/dist/admin/de-CVbi685U.js +246 -0
  15. package/dist/admin/de-CkUYGb7U.js +176 -0
  16. package/dist/admin/de-DBR893G4.js +13 -0
  17. package/dist/admin/de-RMs-_SCK.js +103 -0
  18. package/dist/admin/de-fBFh09Wl.mjs +13 -0
  19. package/dist/admin/de-rRIutpYJ.mjs +176 -0
  20. package/dist/admin/en-BX362fTp.js +246 -0
  21. package/dist/admin/en-B_HltUxZ.mjs +246 -0
  22. package/dist/admin/en-BluCStLw.mjs +103 -0
  23. package/dist/admin/en-C81faOHP.js +103 -0
  24. package/dist/admin/en-D9Nfccux.mjs +13 -0
  25. package/dist/admin/en-DulOcmXb.js +176 -0
  26. package/dist/admin/en-Puup8TFi.mjs +176 -0
  27. package/dist/admin/en-gueRT44P.js +13 -0
  28. package/dist/admin/es-257SSB7f.mjs +176 -0
  29. package/dist/admin/es-B0Zy8DVg.mjs +13 -0
  30. package/dist/admin/es-BoQZC86B.js +176 -0
  31. package/dist/admin/es-CHHEZi44.js +246 -0
  32. package/dist/admin/es-CQRI2Prp.mjs +103 -0
  33. package/dist/admin/es-CrhwOq-5.mjs +246 -0
  34. package/dist/admin/es-D1QzY0JW.js +103 -0
  35. package/dist/admin/es-DRGs7meF.js +13 -0
  36. package/dist/admin/fr-5djKfQ3s.mjs +246 -0
  37. package/dist/admin/fr-B3SL0TBV.js +246 -0
  38. package/dist/admin/fr-B8rdLAIL.js +13 -0
  39. package/dist/admin/fr-C5rSdKU4.mjs +176 -0
  40. package/dist/admin/fr-Di3R6gOX.mjs +103 -0
  41. package/dist/admin/fr-HxFcPpv4.js +176 -0
  42. package/dist/admin/fr-R3_MbzT5.js +103 -0
  43. package/dist/admin/fr-oiUb2bb_.mjs +13 -0
  44. package/dist/admin/index-0_b1iroK.mjs +156 -0
  45. package/dist/admin/index-6SZLli70.js +155 -0
  46. package/dist/admin/index.js +1 -1
  47. package/dist/admin/index.mjs +2 -2
  48. package/dist/admin/pt-B3Jce6uT.mjs +13 -0
  49. package/dist/admin/pt-BCW1u_Hp.js +103 -0
  50. package/dist/admin/pt-BdnY2Cth.mjs +246 -0
  51. package/dist/admin/pt-BiWuSBcH.js +13 -0
  52. package/dist/admin/pt-Cjn2Sc9k.js +176 -0
  53. package/dist/admin/pt-Cr9AL408.mjs +103 -0
  54. package/dist/admin/pt-D6UuEtPy.mjs +176 -0
  55. package/dist/admin/pt-EVwCuBUK.js +246 -0
  56. package/dist/admin/sanitize-DP5aeU7V.js +597 -0
  57. package/dist/admin/sanitize-jjCot5PM.mjs +596 -0
  58. package/dist/admin/useT-91ruePzq.js +130 -0
  59. package/dist/admin/useT-vgY88N_H.mjs +131 -0
  60. package/dist/server/index.js +5373 -64722
  61. package/dist/server/index.mjs +5373 -64731
  62. package/package.json +90 -66
  63. package/strapi-admin.js +3 -0
  64. package/strapi-server.js +3 -0
  65. package/COPYRIGHT_NOTICE.txt +0 -20
  66. package/dist/admin/App-BwMEZnS-.mjs +0 -2144
  67. package/dist/admin/App-HNr2tizR.js +0 -2147
  68. package/dist/admin/CustomBlocksPage-BjcA7MGz.js +0 -1519
  69. package/dist/admin/CustomBlocksPage-COPOZ2-_.mjs +0 -1517
  70. package/dist/admin/LicensePage-D0DMTF41.mjs +0 -392
  71. package/dist/admin/LicensePage-D0_9yPkw.js +0 -394
  72. package/dist/admin/LiveCollaborationPanel-CZAbgAVr.js +0 -223
  73. package/dist/admin/LiveCollaborationPanel-D8z72afw.mjs +0 -221
  74. package/dist/admin/Settings-DRenvRcG.js +0 -441
  75. package/dist/admin/Settings-DjyNURlS.mjs +0 -439
  76. package/dist/admin/de-C_0Mj-Zo.mjs +0 -296
  77. package/dist/admin/de-DVNVpAt9.js +0 -296
  78. package/dist/admin/en-B7AAf1ie.mjs +0 -296
  79. package/dist/admin/en-C2hv5GsA.js +0 -296
  80. package/dist/admin/es-BzJqcIST.js +0 -274
  81. package/dist/admin/es-zdP8sd-f.mjs +0 -274
  82. package/dist/admin/fr-CtAgOgH1.mjs +0 -274
  83. package/dist/admin/fr-D3GwqAAJ.js +0 -274
  84. package/dist/admin/getTranslation-2OiEgVGt.mjs +0 -49459
  85. package/dist/admin/getTranslation-DQ_WJ-7M.js +0 -49475
  86. package/dist/admin/index-Bn2tfJrC.js +0 -2186
  87. package/dist/admin/index-DAtClhqy.js +0 -6956
  88. package/dist/admin/index-FVEbTfqO.mjs +0 -2187
  89. package/dist/admin/index-gjWl-6E2.mjs +0 -6934
  90. package/dist/admin/magic-editor-x.css +0 -1103
  91. package/dist/admin/pt-BmUw6YMP.mjs +0 -274
  92. package/dist/admin/pt-CFo0nTbj.js +0 -274
  93. package/dist/admin/tools-CzHTZaY_.mjs +0 -2268
  94. package/dist/admin/tools-DALFhvPO.js +0 -2299
  95. package/pics/collab-magiceditorX.png +0 -0
  96. package/pics/editorX.png +0 -0
  97. package/pics/liveCollabwidget1.png +0 -0
@@ -0,0 +1,597 @@
1
+ "use strict";
2
+ const createDOMPurify = require("dompurify");
3
+ const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
4
+ const createDOMPurify__default = /* @__PURE__ */ _interopDefault(createDOMPurify);
5
+ const EDITOR_DATA_LIMITS = Object.freeze({
6
+ maxBlocks: 5e3,
7
+ maxBytes: 5 * 1024 * 1024,
8
+ maxDepth: 24,
9
+ maxBlockIdLength: 64,
10
+ maxTypeLength: 64
11
+ });
12
+ const FORBIDDEN_KEYS = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
13
+ const BLOCK_ID_PATTERN = /^[A-Za-z0-9_-]{1,64}$/;
14
+ const BLOCK_TYPE_PATTERN = /^[A-Za-z][A-Za-z0-9_-]{0,63}$/;
15
+ const isPlainObject = (value) => value !== null && typeof value === "object" && !Array.isArray(value) && (Object.getPrototypeOf(value) === Object.prototype || Object.getPrototypeOf(value) === null);
16
+ class EditorDataError extends Error {
17
+ /**
18
+ * @param {string} message - Fixed, non-sensitive message.
19
+ * @param {string} code - Machine-readable reason.
20
+ */
21
+ constructor(message, code) {
22
+ super(message);
23
+ this.name = "EditorDataError";
24
+ this.code = code;
25
+ }
26
+ }
27
+ const cloneJsonSafe = (value, depth = 0) => {
28
+ if (depth > EDITOR_DATA_LIMITS.maxDepth) {
29
+ throw new EditorDataError("Editor content is nested too deeply", "TOO_DEEP");
30
+ }
31
+ if (value === null) return null;
32
+ if (Array.isArray(value)) {
33
+ const out = [];
34
+ for (const item of value) {
35
+ const cloned = cloneJsonSafe(item, depth + 1);
36
+ out.push(cloned === void 0 ? null : cloned);
37
+ }
38
+ return out;
39
+ }
40
+ switch (typeof value) {
41
+ case "string":
42
+ case "boolean":
43
+ return value;
44
+ case "number":
45
+ return Number.isFinite(value) ? value : null;
46
+ case "object": {
47
+ const out = {};
48
+ for (const key of Object.keys(value)) {
49
+ if (FORBIDDEN_KEYS.has(key)) continue;
50
+ const cloned = cloneJsonSafe(value[key], depth + 1);
51
+ if (cloned !== void 0) out[key] = cloned;
52
+ }
53
+ return out;
54
+ }
55
+ default:
56
+ return void 0;
57
+ }
58
+ };
59
+ const tryParseJson = (text) => {
60
+ try {
61
+ return { ok: true, value: JSON.parse(text) };
62
+ } catch {
63
+ return { ok: false };
64
+ }
65
+ };
66
+ const escapeHtml = (text) => String(text).replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
67
+ const hashString = (text) => {
68
+ let hash = 2166136261;
69
+ for (let i = 0; i < text.length; i += 1) {
70
+ hash ^= text.charCodeAt(i);
71
+ hash = Math.imul(hash, 16777619) >>> 0;
72
+ }
73
+ return hash.toString(16).padStart(8, "0");
74
+ };
75
+ const legacyBlockId = (index, type, data) => `mx${hashString(`${index}:${type}:${JSON.stringify(data)}`)}${index}`;
76
+ const textToBlocks = (text) => {
77
+ const trimmed = text.trim();
78
+ if (!trimmed) return [];
79
+ const looksLikeHtml = /<\/?[a-z][^>]{0,200}>/i.test(trimmed.slice(0, 2e3));
80
+ if (looksLikeHtml) {
81
+ return [{ type: "paragraph", data: { text: trimmed } }];
82
+ }
83
+ 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>") } }));
84
+ };
85
+ const unwrapValue = (value) => {
86
+ let current = value;
87
+ let legacy = false;
88
+ for (let i = 0; i < 3 && typeof current === "string"; i += 1) {
89
+ const text = current.trim();
90
+ if (!text) return { candidate: null, legacy: true };
91
+ if (text.startsWith("{") || text.startsWith("[") || text.startsWith('"')) {
92
+ const parsed = tryParseJson(text);
93
+ if (parsed.ok) {
94
+ current = parsed.value;
95
+ legacy = true;
96
+ continue;
97
+ }
98
+ }
99
+ return { candidate: { blocks: textToBlocks(text) }, legacy: true };
100
+ }
101
+ if (Array.isArray(current)) {
102
+ return { candidate: { blocks: current }, legacy: true };
103
+ }
104
+ return { candidate: current, legacy };
105
+ };
106
+ const normalizeEditorData = (value) => {
107
+ if (value === null || value === void 0) return null;
108
+ if (typeof value === "string" && value.length > EDITOR_DATA_LIMITS.maxBytes) {
109
+ throw new EditorDataError("Editor content exceeds the size limit", "TOO_LARGE");
110
+ }
111
+ const { candidate } = unwrapValue(value);
112
+ if (candidate === null || candidate === void 0) return null;
113
+ if (!isPlainObject(candidate)) {
114
+ throw new EditorDataError("Editor content must be an Editor.js object", "INVALID_SHAPE");
115
+ }
116
+ const clean = cloneJsonSafe(candidate);
117
+ const rawBlocks = Array.isArray(clean.blocks) ? clean.blocks : [];
118
+ if (rawBlocks.length > EDITOR_DATA_LIMITS.maxBlocks) {
119
+ throw new EditorDataError("Editor content has too many blocks", "TOO_MANY_BLOCKS");
120
+ }
121
+ const seen = /* @__PURE__ */ new Set();
122
+ const blocks = [];
123
+ rawBlocks.forEach((block, index) => {
124
+ if (!isPlainObject(block)) return;
125
+ const type = typeof block.type === "string" ? block.type.trim() : "";
126
+ if (!BLOCK_TYPE_PATTERN.test(type)) return;
127
+ const data = isPlainObject(block.data) ? block.data : {};
128
+ let id = typeof block.id === "string" && BLOCK_ID_PATTERN.test(block.id) ? block.id : "";
129
+ if (!id || seen.has(id)) id = legacyBlockId(index, type, data);
130
+ while (seen.has(id)) id = `${id}x`;
131
+ seen.add(id);
132
+ const normalized = { id, type, data };
133
+ if (isPlainObject(block.tunes) && Object.keys(block.tunes).length > 0) normalized.tunes = block.tunes;
134
+ blocks.push(normalized);
135
+ });
136
+ const time = Number.isFinite(clean.time) && clean.time > 0 ? Math.floor(clean.time) : 0;
137
+ const version = typeof clean.version === "string" && clean.version.length <= 32 ? clean.version : "2.31.7";
138
+ const result = { time, blocks, version };
139
+ const size = byteLength(JSON.stringify(result));
140
+ if (size > EDITOR_DATA_LIMITS.maxBytes) {
141
+ throw new EditorDataError("Editor content exceeds the size limit", "TOO_LARGE");
142
+ }
143
+ return result;
144
+ };
145
+ const byteLength = (text) => {
146
+ let bytes = 0;
147
+ for (let i = 0; i < text.length; i += 1) {
148
+ const code = text.charCodeAt(i);
149
+ if (code < 128) bytes += 1;
150
+ else if (code < 2048) bytes += 2;
151
+ else if (code >= 55296 && code <= 56319) {
152
+ bytes += 4;
153
+ i += 1;
154
+ } else bytes += 3;
155
+ }
156
+ return bytes;
157
+ };
158
+ const computeStats = (data) => {
159
+ if (!data || !Array.isArray(data.blocks)) return { blocks: 0, words: 0, characters: 0 };
160
+ let text = "";
161
+ const collect = (value, depth = 0) => {
162
+ if (depth > 8 || value === null || value === void 0) return;
163
+ if (typeof value === "string") {
164
+ text += ` ${value.replace(/<[^>]{0,500}>/g, " ").replace(/&nbsp;/g, " ")}`;
165
+ } else if (Array.isArray(value)) value.forEach((item) => collect(item, depth + 1));
166
+ else if (typeof value === "object") {
167
+ for (const [key, item] of Object.entries(value)) {
168
+ if (["url", "link", "href", "src", "id", "documentId", "style", "type", "service"].includes(key))
169
+ continue;
170
+ collect(item, depth + 1);
171
+ }
172
+ }
173
+ };
174
+ data.blocks.forEach((block) => collect(block.data));
175
+ const normalized = text.replace(/\s+/g, " ").trim();
176
+ return {
177
+ blocks: data.blocks.length,
178
+ words: normalized ? normalized.split(" ").length : 0,
179
+ characters: normalized.length
180
+ };
181
+ };
182
+ const INLINE_TAGS = Object.freeze([
183
+ "b",
184
+ "strong",
185
+ "i",
186
+ "em",
187
+ "u",
188
+ "s",
189
+ "mark",
190
+ "code",
191
+ "a",
192
+ "br",
193
+ "span",
194
+ "sub",
195
+ "sup"
196
+ ]);
197
+ const INTERNAL_LINK_ATTRIBUTES = Object.freeze([
198
+ "data-mex-uid",
199
+ "data-mex-document-id",
200
+ "data-mex-locale"
201
+ ]);
202
+ const INTERNAL_LINK_RULES = Object.freeze({
203
+ "data-mex-uid": /^api::[a-z0-9-]{1,60}\.[a-z0-9-]{1,60}$/,
204
+ "data-mex-document-id": /^[a-z0-9]{1,64}$/,
205
+ "data-mex-locale": /^[A-Za-z]{2,8}(?:-[A-Za-z0-9]{1,8}){0,3}$/
206
+ });
207
+ const cleanInternalLinkAttributes = (attribs) => {
208
+ const out = {};
209
+ if (!attribs || typeof attribs !== "object") return out;
210
+ for (const name of INTERNAL_LINK_ATTRIBUTES) {
211
+ const value = attribs[name];
212
+ if (typeof value === "string" && INTERNAL_LINK_RULES[name].test(value)) out[name] = value;
213
+ }
214
+ if (!out["data-mex-uid"] || !out["data-mex-document-id"]) return {};
215
+ return out;
216
+ };
217
+ const INLINE_ATTRIBUTES = Object.freeze({
218
+ a: ["href", "target", "rel", "title", ...INTERNAL_LINK_ATTRIBUTES],
219
+ span: ["class", "data-tooltip"],
220
+ mark: ["class"],
221
+ u: ["class"],
222
+ s: ["class"],
223
+ code: ["class"]
224
+ });
225
+ const INLINE_CLASSES = Object.freeze({
226
+ span: ["cdx-tooltip"],
227
+ mark: ["cdx-marker"],
228
+ u: ["cdx-underline"],
229
+ s: ["cdx-strikethrough", "cdx-strikethroughs"],
230
+ code: ["inline-code"]
231
+ });
232
+ const LINK_SCHEMES = Object.freeze(["http", "https", "mailto", "tel"]);
233
+ const MAX_URL_LENGTH = 2048;
234
+ const sanitizeUrl = (value, options = {}) => {
235
+ const schemes = options.schemes || LINK_SCHEMES;
236
+ const allowRelative = options.allowRelative !== false;
237
+ if (typeof value !== "string") return "";
238
+ const url = value.trim();
239
+ if (!url || url.length > MAX_URL_LENGTH) return "";
240
+ if (/[\u0000-\u001f\u007f\s]/.test(url) && !/^(mailto|tel):/i.test(url)) return "";
241
+ if (url.startsWith("//") || url.startsWith("\\")) return "";
242
+ const scheme = /^([a-zA-Z][a-zA-Z0-9+.-]{0,20}):/.exec(url);
243
+ if (!scheme) {
244
+ return allowRelative && /^[/#?.]/.test(url) ? url : "";
245
+ }
246
+ if (!schemes.includes(scheme[1].toLowerCase())) return "";
247
+ if (scheme[1].toLowerCase().startsWith("http")) {
248
+ try {
249
+ const parsed = new URL(url);
250
+ if (parsed.username || parsed.password) return "";
251
+ } catch {
252
+ return "";
253
+ }
254
+ }
255
+ return url;
256
+ };
257
+ const plain = (value, max = 1e5) => typeof value === "string" ? value.slice(0, max) : "";
258
+ const oneOf = (value, allowed, fallback) => typeof value === "string" && allowed.includes(value) ? value : fallback;
259
+ const int = (value, min, max, fallback) => {
260
+ const number = typeof value === "string" ? Number(value) : value;
261
+ return Number.isInteger(number) && number >= min && number <= max ? number : fallback;
262
+ };
263
+ const bool = (value) => value === true;
264
+ const generic = (value, inline, depth = 0, key = "") => {
265
+ if (depth > 20) return null;
266
+ if (typeof value === "string") {
267
+ if (/^(url|href|link|src|photo|source|embed)$/i.test(key)) return sanitizeUrl(value);
268
+ return inline(value);
269
+ }
270
+ if (Array.isArray(value)) return value.map((item) => generic(item, inline, depth + 1, key));
271
+ if (isPlainObject(value)) {
272
+ const out = {};
273
+ for (const [childKey, child] of Object.entries(value))
274
+ out[childKey] = generic(child, inline, depth + 1, childKey);
275
+ return out;
276
+ }
277
+ return value;
278
+ };
279
+ const listItems = (items, inline, depth = 0) => {
280
+ if (!Array.isArray(items) || depth > 12) return [];
281
+ return items.map((item) => {
282
+ if (typeof item === "string") return inline(item);
283
+ if (!isPlainObject(item)) return { content: "", items: [] };
284
+ const out = { content: inline(typeof item.content === "string" ? item.content : plain(item.text)) };
285
+ if (isPlainObject(item.meta)) {
286
+ const meta = {};
287
+ if (typeof item.meta.checked === "boolean") meta.checked = item.meta.checked;
288
+ const start = int(item.meta.start, 0, 1e5, void 0);
289
+ if (start !== void 0) meta.start = start;
290
+ if (typeof item.meta.counterType === "string") {
291
+ meta.counterType = oneOf(
292
+ item.meta.counterType,
293
+ ["numeric", "lower-roman", "upper-roman", "lower-alpha", "upper-alpha"],
294
+ "numeric"
295
+ );
296
+ }
297
+ out.meta = meta;
298
+ }
299
+ out.items = listItems(item.items, inline, depth + 1);
300
+ return out;
301
+ });
302
+ };
303
+ const BLOCK_POLICIES = {
304
+ paragraph: (d, inline) => ({ text: inline(d.text) }),
305
+ header: (d, inline) => ({ text: inline(d.text), level: int(d.level, 1, 6, 2) }),
306
+ quote: (d, inline) => ({
307
+ text: inline(d.text),
308
+ caption: inline(d.caption),
309
+ alignment: oneOf(d.alignment, ["left", "center"], "left")
310
+ }),
311
+ list: (d, inline) => {
312
+ const out = {
313
+ style: oneOf(d.style, ["ordered", "unordered", "checklist"], "unordered"),
314
+ items: listItems(d.items, inline)
315
+ };
316
+ if (isPlainObject(d.meta)) {
317
+ const meta = {};
318
+ const start = int(d.meta.start, 0, 1e5, void 0);
319
+ if (start !== void 0) meta.start = start;
320
+ if (typeof d.meta.counterType === "string") {
321
+ meta.counterType = oneOf(
322
+ d.meta.counterType,
323
+ ["numeric", "lower-roman", "upper-roman", "lower-alpha", "upper-alpha"],
324
+ "numeric"
325
+ );
326
+ }
327
+ out.meta = meta;
328
+ }
329
+ return out;
330
+ },
331
+ checklist: (d, inline) => ({
332
+ items: Array.isArray(d.items) ? d.items.filter(isPlainObject).map((item) => ({ text: inline(item.text), checked: bool(item.checked) })) : []
333
+ }),
334
+ warning: (d, inline) => ({ title: inline(d.title), message: inline(d.message) }),
335
+ alert: (d, inline) => ({
336
+ type: oneOf(
337
+ d.type,
338
+ ["primary", "secondary", "info", "success", "warning", "danger", "light", "dark"],
339
+ "info"
340
+ ),
341
+ align: oneOf(d.align, ["left", "center", "right"], "left"),
342
+ message: inline(d.message)
343
+ }),
344
+ toggle: (d, inline) => ({
345
+ text: inline(d.text),
346
+ status: oneOf(d.status, ["open", "closed"], "open"),
347
+ fk: typeof d.fk === "string" ? d.fk.slice(0, 64) : void 0,
348
+ items: int(d.items, 0, 5e3, 0)
349
+ }),
350
+ code: (d) => ({ code: plain(d.code, 5e5) }),
351
+ codeFlask: (d) => {
352
+ const out = {
353
+ code: plain(d.code, 5e5),
354
+ language: /^[a-z0-9+#-]{1,32}$/i.test(d.language || "") ? d.language : "plaintext"
355
+ };
356
+ if (typeof d.showlinenumbers === "boolean") out.showlinenumbers = d.showlinenumbers;
357
+ return out;
358
+ },
359
+ raw: (d, _inline, ctx) => {
360
+ const html = plain(d.html, 5e5);
361
+ if (ctx.rawHtml === "allow") return { html };
362
+ if (ctx.rawHtml === "disable") return { html: "" };
363
+ return { html: ctx.rawSanitizer(html) };
364
+ },
365
+ table: (d, inline) => ({
366
+ withHeadings: bool(d.withHeadings),
367
+ stretched: bool(d.stretched),
368
+ content: Array.isArray(d.content) ? d.content.slice(0, 500).map((row) => Array.isArray(row) ? row.slice(0, 100).map((cell) => inline(cell)) : []) : []
369
+ }),
370
+ image: (d, inline) => {
371
+ const file = isPlainObject(d.file) ? d.file : {};
372
+ const cleanFile = { url: sanitizeUrl(file.url, { schemes: ["http", "https"] }) };
373
+ for (const key of ["mime", "alt", "name", "hash", "ext"])
374
+ if (typeof file[key] === "string") cleanFile[key] = plain(file[key], 500);
375
+ for (const key of ["width", "height", "size"]) if (Number.isFinite(file[key])) cleanFile[key] = file[key];
376
+ if (isPlainObject(file.formats))
377
+ cleanFile.formats = generic(file.formats, (s) => plain(s, 2048), 0, "formats");
378
+ if (file.id !== void 0 && (Number.isInteger(file.id) || typeof file.id === "string"))
379
+ cleanFile.id = file.id;
380
+ if (typeof file.documentId === "string") cleanFile.documentId = plain(file.documentId, 64);
381
+ return {
382
+ file: cleanFile,
383
+ caption: inline(d.caption),
384
+ withBorder: bool(d.withBorder),
385
+ withBackground: bool(d.withBackground),
386
+ stretched: bool(d.stretched)
387
+ };
388
+ },
389
+ simpleImage: (d, inline) => ({
390
+ url: sanitizeUrl(d.url, { schemes: ["http", "https"] }),
391
+ caption: inline(d.caption),
392
+ withBorder: bool(d.withBorder),
393
+ withBackground: bool(d.withBackground),
394
+ stretched: bool(d.stretched)
395
+ }),
396
+ linkTool: (d) => {
397
+ const meta = isPlainObject(d.meta) ? d.meta : {};
398
+ const image = isPlainObject(meta.image) ? { url: sanitizeUrl(meta.image.url, { schemes: ["http", "https"] }) } : void 0;
399
+ const cleanMeta = { title: plain(meta.title, 500), description: plain(meta.description, 2e3) };
400
+ if (typeof meta.site_name === "string") cleanMeta.site_name = plain(meta.site_name, 200);
401
+ if (image && image.url) cleanMeta.image = image;
402
+ return { link: sanitizeUrl(d.link, { schemes: ["http", "https"] }), meta: cleanMeta };
403
+ },
404
+ attaches: (d) => {
405
+ const file = isPlainObject(d.file) ? d.file : {};
406
+ const cleanFile = { url: sanitizeUrl(file.url, { schemes: ["http", "https"] }) };
407
+ if (typeof file.name === "string") cleanFile.name = plain(file.name, 255);
408
+ if (typeof file.extension === "string") cleanFile.extension = plain(file.extension, 16);
409
+ if (Number.isFinite(file.size)) cleanFile.size = file.size;
410
+ if (typeof file.title === "string") cleanFile.title = plain(file.title, 255);
411
+ return { file: cleanFile, title: plain(d.title, 255) };
412
+ },
413
+ embed: (d, inline) => ({
414
+ service: /^[a-z0-9_-]{1,40}$/i.test(d.service || "") ? d.service : "",
415
+ source: sanitizeUrl(d.source, { schemes: ["https", "http"], allowRelative: false }),
416
+ embed: sanitizeUrl(d.embed, { schemes: ["https"], allowRelative: false }),
417
+ width: int(d.width, 1, 1e4, void 0),
418
+ height: int(d.height, 1, 1e4, void 0),
419
+ caption: inline(d.caption)
420
+ }),
421
+ personality: (d) => ({
422
+ name: plain(d.name, 500),
423
+ description: plain(d.description, 2e3),
424
+ link: sanitizeUrl(d.link, { schemes: ["http", "https", "mailto"] }),
425
+ photo: sanitizeUrl(d.photo, { schemes: ["http", "https"] })
426
+ }),
427
+ button: (d) => ({
428
+ text: plain(d.text, 200),
429
+ link: sanitizeUrl(d.link),
430
+ style: oneOf(d.style, ["primary", "secondary", "outline", "ghost", "danger", "success"], "primary"),
431
+ openInNewTab: bool(d.openInNewTab)
432
+ }),
433
+ delimiter: () => ({})
434
+ };
435
+ const sanitizeTunes = (tunes) => {
436
+ if (!isPlainObject(tunes)) return void 0;
437
+ const out = {};
438
+ if (isPlainObject(tunes.alignmentTune)) {
439
+ out.alignmentTune = {
440
+ alignment: oneOf(tunes.alignmentTune.alignment, ["left", "center", "right", "justify"], "left")
441
+ };
442
+ }
443
+ if (typeof tunes.textVariant === "string") {
444
+ out.textVariant = oneOf(tunes.textVariant, ["", "call-out", "citation", "details"], "");
445
+ }
446
+ if (isPlainObject(tunes.indentTune)) {
447
+ out.indentTune = { indentLevel: int(tunes.indentTune.indentLevel, 0, 10, 0) };
448
+ }
449
+ return Object.keys(out).length ? out : void 0;
450
+ };
451
+ const sanitizeEditorData = (data, options) => {
452
+ if (!data) return data;
453
+ const inline = (value) => typeof value === "string" ? options.sanitizeInlineHtml(value) : "";
454
+ const ctx = { rawHtml: options.rawHtml || "sanitize", rawSanitizer: options.sanitizeRawHtml };
455
+ const blocks = data.blocks.map((block) => {
456
+ const policy = Object.prototype.hasOwnProperty.call(BLOCK_POLICIES, block.type) ? BLOCK_POLICIES[block.type] : null;
457
+ const cleanData = policy ? policy(block.data || {}, inline, ctx) : generic(block.data || {}, inline, 0);
458
+ for (const key of Object.keys(cleanData)) if (cleanData[key] === void 0) delete cleanData[key];
459
+ const out = { id: block.id, type: block.type, data: cleanData };
460
+ const tunes = sanitizeTunes(block.tunes);
461
+ if (tunes) out.tunes = tunes;
462
+ return out;
463
+ });
464
+ return { time: data.time, blocks, version: data.version };
465
+ };
466
+ let purify = null;
467
+ const instance = () => {
468
+ if (purify) return purify;
469
+ purify = createDOMPurify__default.default(window);
470
+ purify.addHook("uponSanitizeAttribute", (node, data) => {
471
+ const tag = node.nodeName.toLowerCase();
472
+ if (data.attrName === "class") {
473
+ const allowed = INLINE_CLASSES[tag] || [];
474
+ const kept = String(data.attrValue).split(/\s+/).filter((name) => allowed.includes(name));
475
+ if (kept.length === 0) data.keepAttr = false;
476
+ else data.attrValue = kept.join(" ");
477
+ }
478
+ if (data.attrName === "href") {
479
+ const safe = sanitizeUrl(data.attrValue);
480
+ if (!safe) data.keepAttr = false;
481
+ else data.attrValue = safe;
482
+ }
483
+ if (data.attrName === "target" && !["_blank", "_self", "_parent", "_top"].includes(data.attrValue))
484
+ data.keepAttr = false;
485
+ });
486
+ purify.addHook("afterSanitizeAttributes", (node) => {
487
+ if (node.nodeName === "A" && node.getAttribute("target") === "_blank")
488
+ node.setAttribute("rel", "noopener noreferrer");
489
+ if (typeof node.hasAttribute !== "function") return;
490
+ if (!INTERNAL_LINK_ATTRIBUTES.some((name) => node.hasAttribute(name))) return;
491
+ const kept = node.nodeName === "A" ? cleanInternalLinkAttributes(
492
+ Object.fromEntries(INTERNAL_LINK_ATTRIBUTES.map((name) => [name, node.getAttribute(name)]))
493
+ ) : {};
494
+ for (const name of INTERNAL_LINK_ATTRIBUTES) {
495
+ if (kept[name]) node.setAttribute(name, kept[name]);
496
+ else node.removeAttribute(name);
497
+ }
498
+ });
499
+ return purify;
500
+ };
501
+ const ALLOWED_ATTR = Array.from(new Set(Object.values(INLINE_ATTRIBUTES).flat()));
502
+ const sanitizeInline = (html) => instance().sanitize(String(html || ""), {
503
+ ALLOWED_TAGS: [...INLINE_TAGS],
504
+ ALLOWED_ATTR,
505
+ ALLOW_DATA_ATTR: false
506
+ });
507
+ const sanitizeTemplate = (html) => instance().sanitize(String(html || ""), {
508
+ ALLOWED_TAGS: [
509
+ "div",
510
+ "span",
511
+ "p",
512
+ "h2",
513
+ "h3",
514
+ "h4",
515
+ "strong",
516
+ "b",
517
+ "em",
518
+ "i",
519
+ "u",
520
+ "s",
521
+ "small",
522
+ "br",
523
+ "hr",
524
+ "ul",
525
+ "ol",
526
+ "li",
527
+ "blockquote",
528
+ "figure",
529
+ "figcaption",
530
+ "img",
531
+ "a",
532
+ "section",
533
+ "header",
534
+ "footer",
535
+ "code",
536
+ "pre",
537
+ "mark"
538
+ ],
539
+ ALLOWED_ATTR: [
540
+ "class",
541
+ "data-field",
542
+ "title",
543
+ "href",
544
+ "target",
545
+ "rel",
546
+ "src",
547
+ "alt",
548
+ "width",
549
+ "height",
550
+ "loading"
551
+ ],
552
+ ALLOW_DATA_ATTR: false
553
+ });
554
+ const sanitizeSvg = (svg) => instance().sanitize(String(svg || ""), {
555
+ USE_PROFILES: { svg: true, svgFilters: false },
556
+ FORBID_TAGS: ["style", "use", "image", "foreignObject", "a", "script"],
557
+ FORBID_ATTR: ["style", "href", "xlink:href"]
558
+ });
559
+ const prepareEditorValue = (value, rawHtml = "allow") => {
560
+ try {
561
+ const data = normalizeEditorData(value);
562
+ if (!data) return { data: null, error: null };
563
+ return {
564
+ data: sanitizeEditorData(data, {
565
+ sanitizeInlineHtml: sanitizeInline,
566
+ sanitizeRawHtml: (html) => html,
567
+ rawHtml
568
+ }),
569
+ error: null
570
+ };
571
+ } catch (error) {
572
+ return { data: null, error: error && error.code || "INVALID" };
573
+ }
574
+ };
575
+ const prepareRemoteData = (data, cache) => {
576
+ const blocks = [];
577
+ for (const block of data && data.blocks || []) {
578
+ let clean = cache.get(block);
579
+ if (clean === void 0) {
580
+ const prepared = prepareEditorValue({ time: data.time, version: data.version, blocks: [block] }).data;
581
+ clean = prepared && prepared.blocks.length === 1 ? prepared.blocks[0] : null;
582
+ cache.set(block, clean);
583
+ }
584
+ if (clean) blocks.push(clean);
585
+ }
586
+ return { time: data && data.time || Date.now(), version: data && data.version || "2.31.7", blocks };
587
+ };
588
+ exports.EDITOR_DATA_LIMITS = EDITOR_DATA_LIMITS;
589
+ exports.cloneJsonSafe = cloneJsonSafe;
590
+ exports.computeStats = computeStats;
591
+ exports.isPlainObject = isPlainObject;
592
+ exports.prepareEditorValue = prepareEditorValue;
593
+ exports.prepareRemoteData = prepareRemoteData;
594
+ exports.sanitizeInline = sanitizeInline;
595
+ exports.sanitizeSvg = sanitizeSvg;
596
+ exports.sanitizeTemplate = sanitizeTemplate;
597
+ exports.sanitizeUrl = sanitizeUrl;