react-smart-copy 1.30.0 → 1.31.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/README.md +11 -1
  2. package/dist/chunks/copy-machine-B6apNst5.d.ts +132 -0
  3. package/dist/chunks/copy-machine-CmqX9J4V.d.cts +132 -0
  4. package/dist/chunks/copy-machine-DwdB-qva.js +292 -0
  5. package/dist/chunks/copy-machine-DwdB-qva.js.map +1 -0
  6. package/dist/chunks/copy-machine-oNmnrjMc.cjs +345 -0
  7. package/dist/chunks/copy-machine-oNmnrjMc.cjs.map +1 -0
  8. package/dist/chunks/{core-B8_wVOSU.js → core-CNSd-EgZ.js} +4 -290
  9. package/dist/chunks/core-CNSd-EgZ.js.map +1 -0
  10. package/dist/chunks/{core-BR8Jgea1.cjs → core-DsMKPNx_.cjs} +20 -348
  11. package/dist/chunks/core-DsMKPNx_.cjs.map +1 -0
  12. package/dist/chunks/{index-DjqQGsNs.d.ts → index-B4SEFtkx.d.ts} +3 -131
  13. package/dist/chunks/{index-uHZHddq0.d.cts → index-BDxj1EqC.d.cts} +3 -131
  14. package/dist/chunks/text-C2OYT-3o.cjs +478 -0
  15. package/dist/chunks/text-C2OYT-3o.cjs.map +1 -0
  16. package/dist/chunks/text-nc1LhgIh.js +413 -0
  17. package/dist/chunks/text-nc1LhgIh.js.map +1 -0
  18. package/dist/chunks/utils-C7_VlH79.cjs +53 -0
  19. package/dist/chunks/utils-C7_VlH79.cjs.map +1 -0
  20. package/dist/chunks/utils-CBBX2HN6.js +30 -0
  21. package/dist/chunks/utils-CBBX2HN6.js.map +1 -0
  22. package/dist/compat.cjs +94 -0
  23. package/dist/compat.cjs.map +1 -0
  24. package/dist/compat.d.cts +57 -0
  25. package/dist/compat.d.ts +57 -0
  26. package/dist/compat.js +88 -0
  27. package/dist/compat.js.map +1 -0
  28. package/dist/core.cjs +8 -7
  29. package/dist/core.d.cts +2 -1
  30. package/dist/core.d.ts +2 -1
  31. package/dist/core.js +2 -1
  32. package/dist/index.cjs +45 -68
  33. package/dist/index.cjs.map +1 -1
  34. package/dist/index.d.cts +2 -1
  35. package/dist/index.d.ts +2 -1
  36. package/dist/index.js +4 -27
  37. package/dist/index.js.map +1 -1
  38. package/dist/markdown.cjs +2 -1
  39. package/dist/markdown.cjs.map +1 -1
  40. package/dist/markdown.js +2 -1
  41. package/dist/markdown.js.map +1 -1
  42. package/dist/rich.cjs +14 -422
  43. package/dist/rich.cjs.map +1 -1
  44. package/dist/rich.js +1 -409
  45. package/dist/rich.js.map +1 -1
  46. package/package.json +20 -1
  47. package/dist/chunks/core-B8_wVOSU.js.map +0 -1
  48. package/dist/chunks/core-BR8Jgea1.cjs.map +0 -1
@@ -0,0 +1,478 @@
1
+
2
+ //#region src/rich/policy.ts
3
+ /**
4
+ * What portable rich text may contain: the elements, attributes and CSS that Gmail,
5
+ * Outlook, Apple Mail, Google Docs, Word, Notion and Slack keep, and nothing that
6
+ * can run, load or track. Everything not listed here is left out.
7
+ */
8
+ /** Elements written as they are. */
9
+ const KEEP = /* @__PURE__ */ new Set([
10
+ "a",
11
+ "abbr",
12
+ "b",
13
+ "bdi",
14
+ "bdo",
15
+ "blockquote",
16
+ "br",
17
+ "caption",
18
+ "cite",
19
+ "code",
20
+ "col",
21
+ "colgroup",
22
+ "dd",
23
+ "del",
24
+ "dfn",
25
+ "div",
26
+ "dl",
27
+ "dt",
28
+ "em",
29
+ "figcaption",
30
+ "figure",
31
+ "h1",
32
+ "h2",
33
+ "h3",
34
+ "h4",
35
+ "h5",
36
+ "h6",
37
+ "hr",
38
+ "i",
39
+ "img",
40
+ "ins",
41
+ "kbd",
42
+ "li",
43
+ "mark",
44
+ "ol",
45
+ "p",
46
+ "pre",
47
+ "q",
48
+ "s",
49
+ "samp",
50
+ "small",
51
+ "span",
52
+ "strong",
53
+ "sub",
54
+ "sup",
55
+ "table",
56
+ "tbody",
57
+ "td",
58
+ "tfoot",
59
+ "th",
60
+ "thead",
61
+ "time",
62
+ "tr",
63
+ "u",
64
+ "ul",
65
+ "var"
66
+ ]);
67
+ /** Elements left out with everything inside them: they run, load, embed, or are page chrome. */
68
+ const DROP = /* @__PURE__ */ new Set([
69
+ "applet",
70
+ "audio",
71
+ "base",
72
+ "button",
73
+ "canvas",
74
+ "datalist",
75
+ "dialog",
76
+ "embed",
77
+ "frame",
78
+ "frameset",
79
+ "head",
80
+ "iframe",
81
+ "input",
82
+ "link",
83
+ "map",
84
+ "math",
85
+ "meta",
86
+ "meter",
87
+ "noembed",
88
+ "noframes",
89
+ "noscript",
90
+ "object",
91
+ "option",
92
+ "optgroup",
93
+ "output",
94
+ "param",
95
+ "portal",
96
+ "progress",
97
+ "script",
98
+ "select",
99
+ "slot",
100
+ "source",
101
+ "style",
102
+ "svg",
103
+ "template",
104
+ "textarea",
105
+ "title",
106
+ "track",
107
+ "video"
108
+ ]);
109
+ /** Elements that become a `<div>`: blocks without an email-safe equivalent. */
110
+ const AS_BLOCK = /* @__PURE__ */ new Set([
111
+ "address",
112
+ "article",
113
+ "aside",
114
+ "body",
115
+ "center",
116
+ "details",
117
+ "fieldset",
118
+ "footer",
119
+ "form",
120
+ "header",
121
+ "hgroup",
122
+ "html",
123
+ "legend",
124
+ "listing",
125
+ "main",
126
+ "menu",
127
+ "nav",
128
+ "plaintext",
129
+ "search",
130
+ "section",
131
+ "summary",
132
+ "xmp"
133
+ ]);
134
+ /** Elements whose children are block-level text in the plain-text version. */
135
+ const TEXT_BLOCKS = /* @__PURE__ */ new Set([
136
+ "blockquote",
137
+ "caption",
138
+ "dd",
139
+ "div",
140
+ "dl",
141
+ "dt",
142
+ "figcaption",
143
+ "figure",
144
+ "h1",
145
+ "h2",
146
+ "h3",
147
+ "h4",
148
+ "h5",
149
+ "h6",
150
+ "hr",
151
+ "li",
152
+ "ol",
153
+ "p",
154
+ "pre",
155
+ "table",
156
+ "tbody",
157
+ "tfoot",
158
+ "thead",
159
+ "tr",
160
+ "ul"
161
+ ]);
162
+ /** What table parts may contain: anything else is moved out of the table by every HTML parser. */
163
+ const TABLE_CHILDREN = {
164
+ table: /* @__PURE__ */ new Set([
165
+ "caption",
166
+ "colgroup",
167
+ "thead",
168
+ "tbody",
169
+ "tfoot",
170
+ "tr"
171
+ ]),
172
+ thead: /* @__PURE__ */ new Set(["tr"]),
173
+ tbody: /* @__PURE__ */ new Set(["tr"]),
174
+ tfoot: /* @__PURE__ */ new Set(["tr"]),
175
+ tr: /* @__PURE__ */ new Set(["td", "th"]),
176
+ colgroup: /* @__PURE__ */ new Set(["col"])
177
+ };
178
+ /** Elements that hold only text-level content: a block inside one would be split out by HTML parsers. */
179
+ const PHRASING = /* @__PURE__ */ new Set([
180
+ "a",
181
+ "abbr",
182
+ "b",
183
+ "bdi",
184
+ "bdo",
185
+ "cite",
186
+ "code",
187
+ "del",
188
+ "dfn",
189
+ "em",
190
+ "h1",
191
+ "h2",
192
+ "h3",
193
+ "h4",
194
+ "h5",
195
+ "h6",
196
+ "i",
197
+ "ins",
198
+ "kbd",
199
+ "mark",
200
+ "p",
201
+ "q",
202
+ "s",
203
+ "samp",
204
+ "small",
205
+ "span",
206
+ "strong",
207
+ "sub",
208
+ "sup",
209
+ "time",
210
+ "u",
211
+ "var"
212
+ ]);
213
+ /** Table parts: outside their own parent, HTML parsers ignore their tags. */
214
+ const TABLE_PARTS = /* @__PURE__ */ new Set([
215
+ "caption",
216
+ "col",
217
+ "colgroup",
218
+ "tbody",
219
+ "td",
220
+ "tfoot",
221
+ "th",
222
+ "thead",
223
+ "tr"
224
+ ]);
225
+ const HEADINGS = /* @__PURE__ */ new Set([
226
+ "h1",
227
+ "h2",
228
+ "h3",
229
+ "h4",
230
+ "h5",
231
+ "h6"
232
+ ]);
233
+ /** Elements whose start tag closes an open `<p>`: a paragraph holding one is split in two by HTML parsers. */
234
+ const CLOSES_P = /* @__PURE__ */ new Set([
235
+ "blockquote",
236
+ "dd",
237
+ "dl",
238
+ "dt",
239
+ "figcaption",
240
+ "figure",
241
+ "h1",
242
+ "h2",
243
+ "h3",
244
+ "h4",
245
+ "h5",
246
+ "h6",
247
+ "hr",
248
+ "li",
249
+ "ol",
250
+ "p",
251
+ "pre",
252
+ "table",
253
+ "ul"
254
+ ]);
255
+ /** Where HTML parsers stop looking for an open list item to close: their "special" elements, less address, div and p. */
256
+ const ITEM_SCOPE = /* @__PURE__ */ new Set([
257
+ "blockquote",
258
+ "br",
259
+ "caption",
260
+ "col",
261
+ "colgroup",
262
+ "dd",
263
+ "dl",
264
+ "dt",
265
+ "figcaption",
266
+ "figure",
267
+ "h1",
268
+ "h2",
269
+ "h3",
270
+ "h4",
271
+ "h5",
272
+ "h6",
273
+ "hr",
274
+ "img",
275
+ "li",
276
+ "ol",
277
+ "pre",
278
+ "table",
279
+ "tbody",
280
+ "td",
281
+ "tfoot",
282
+ "th",
283
+ "thead",
284
+ "tr",
285
+ "ul"
286
+ ]);
287
+ /** Whether a new `li` (or `dd`, `dt`) under `parent` would close an open one, as HTML parsers do with `<li>` in `<li>`. */
288
+ function closesItem(name, parent) {
289
+ const group = name === "li" ? ["li"] : ["dd", "dt"];
290
+ for (let node = parent; node !== null && node.nodeType === 1; node = node.parentNode) {
291
+ const tag = node.localName;
292
+ if (group.includes(tag)) return true;
293
+ if (ITEM_SCOPE.has(tag)) return false;
294
+ }
295
+ return false;
296
+ }
297
+ const INTEGER = /^\d{1,4}$/;
298
+ /** Attributes kept per element (after `href` and `src`, which are checked as URLs). */
299
+ function attributeAllowed(tag, name, value) {
300
+ switch (name) {
301
+ case "dir": return /^(?:ltr|rtl|auto)$/i.test(value);
302
+ case "lang": return /^[a-z]{2,3}(?:-[a-z\d]{1,8})*$/i.test(value);
303
+ case "title": return [
304
+ "a",
305
+ "abbr",
306
+ "dfn"
307
+ ].includes(tag);
308
+ case "colspan":
309
+ case "rowspan": return (tag === "td" || tag === "th") && INTEGER.test(value) && Number(value) >= 1 && Number(value) <= 1e3;
310
+ case "scope": return tag === "th" && /^(?:row|col|rowgroup|colgroup)$/i.test(value);
311
+ case "span": return (tag === "col" || tag === "colgroup") && INTEGER.test(value);
312
+ case "start": return tag === "ol" && /^-?\d{1,9}$/.test(value);
313
+ case "reversed": return tag === "ol";
314
+ case "type": return tag === "ol" && /^[1aAiI]$/.test(value);
315
+ case "value": return tag === "li" && /^-?\d{1,9}$/.test(value);
316
+ case "datetime": return tag === "time" && /^[\d\-:T.+ Z]{1,40}$/.test(value);
317
+ default: return false;
318
+ }
319
+ }
320
+ //#endregion
321
+ //#region src/rich/text.ts
322
+ /**
323
+ * Readable plain text for sanitized rich content: blocks on their own lines, list
324
+ * items with bullets or numbers (indented when nested), table cells separated by tabs,
325
+ * images by their alt text, and preformatted text as it is.
326
+ */
327
+ function plainText(root) {
328
+ const lines = [];
329
+ let line = "";
330
+ const flush = () => {
331
+ const trimmed = line.replace(/[ \t\u00A0]+$/, "");
332
+ if (trimmed !== "" || lines.length > 0 && lines[lines.length - 1] !== "") lines.push(trimmed);
333
+ line = "";
334
+ };
335
+ const breakBlock = () => {
336
+ if (line.trim() !== "") flush();
337
+ else line = "";
338
+ };
339
+ const walk = (node, pre, depth) => {
340
+ if (node.nodeType === 3) {
341
+ const data = node.data;
342
+ if (pre) line += data.replace(/\r\n?/g, "\n");
343
+ else {
344
+ const collapsed = data.replace(/\s+/g, " ");
345
+ line += /(?:^|[ \t])$/.test(line) && collapsed.startsWith(" ") ? collapsed.slice(1) : collapsed;
346
+ }
347
+ if (pre && line.includes("\n")) {
348
+ const parts = line.split("\n");
349
+ line = parts.pop();
350
+ for (const part of parts) lines.push(part);
351
+ }
352
+ if (!pre && line.trimStart() === "") line = "";
353
+ return;
354
+ }
355
+ if (node.nodeType !== 1) return;
356
+ const element = node;
357
+ const tag = element.localName;
358
+ switch (tag) {
359
+ case "br":
360
+ flush();
361
+ return;
362
+ case "img":
363
+ line += element.getAttribute("alt") ?? "";
364
+ return;
365
+ case "hr":
366
+ breakBlock();
367
+ lines.push("—".repeat(3));
368
+ return;
369
+ case "td":
370
+ case "th":
371
+ if (element.previousElementSibling !== null) line += " ";
372
+ element.childNodes.forEach((child) => {
373
+ walk(child, pre, depth);
374
+ });
375
+ return;
376
+ case "li": {
377
+ breakBlock();
378
+ const list = element.parentElement;
379
+ const ordered = list?.localName === "ol";
380
+ let marker = "•";
381
+ if (ordered) {
382
+ const items = Array.from(list.children).filter((child) => child.localName === "li");
383
+ const start = Number(list.getAttribute("start") ?? "1");
384
+ const own = element.getAttribute("value");
385
+ marker = `${String(own === null ? start + items.indexOf(element) : Number(own))}.`;
386
+ }
387
+ line = `${" ".repeat(Math.max(0, depth - 1))}${marker} `;
388
+ element.childNodes.forEach((child) => {
389
+ walk(child, pre, depth);
390
+ });
391
+ breakBlock();
392
+ return;
393
+ }
394
+ default: {
395
+ const block = TEXT_BLOCKS.has(tag);
396
+ const list = tag === "ul" || tag === "ol";
397
+ if (block) breakBlock();
398
+ const keep = pre || tag === "pre" || /white-space:\s*pre/.test(element.getAttribute("style") ?? "");
399
+ element.childNodes.forEach((child) => {
400
+ walk(child, keep, list ? depth + 1 : depth);
401
+ });
402
+ if (block) breakBlock();
403
+ }
404
+ }
405
+ };
406
+ walk(root, false, 0);
407
+ flush();
408
+ return lines.join("\n").replace(/\n{3,}/g, "\n\n").trim();
409
+ }
410
+ //#endregion
411
+ Object.defineProperty(exports, "AS_BLOCK", {
412
+ enumerable: true,
413
+ get: function() {
414
+ return AS_BLOCK;
415
+ }
416
+ });
417
+ Object.defineProperty(exports, "CLOSES_P", {
418
+ enumerable: true,
419
+ get: function() {
420
+ return CLOSES_P;
421
+ }
422
+ });
423
+ Object.defineProperty(exports, "DROP", {
424
+ enumerable: true,
425
+ get: function() {
426
+ return DROP;
427
+ }
428
+ });
429
+ Object.defineProperty(exports, "HEADINGS", {
430
+ enumerable: true,
431
+ get: function() {
432
+ return HEADINGS;
433
+ }
434
+ });
435
+ Object.defineProperty(exports, "KEEP", {
436
+ enumerable: true,
437
+ get: function() {
438
+ return KEEP;
439
+ }
440
+ });
441
+ Object.defineProperty(exports, "PHRASING", {
442
+ enumerable: true,
443
+ get: function() {
444
+ return PHRASING;
445
+ }
446
+ });
447
+ Object.defineProperty(exports, "TABLE_CHILDREN", {
448
+ enumerable: true,
449
+ get: function() {
450
+ return TABLE_CHILDREN;
451
+ }
452
+ });
453
+ Object.defineProperty(exports, "TABLE_PARTS", {
454
+ enumerable: true,
455
+ get: function() {
456
+ return TABLE_PARTS;
457
+ }
458
+ });
459
+ Object.defineProperty(exports, "attributeAllowed", {
460
+ enumerable: true,
461
+ get: function() {
462
+ return attributeAllowed;
463
+ }
464
+ });
465
+ Object.defineProperty(exports, "closesItem", {
466
+ enumerable: true,
467
+ get: function() {
468
+ return closesItem;
469
+ }
470
+ });
471
+ Object.defineProperty(exports, "plainText", {
472
+ enumerable: true,
473
+ get: function() {
474
+ return plainText;
475
+ }
476
+ });
477
+
478
+ //# sourceMappingURL=text-C2OYT-3o.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"text-C2OYT-3o.cjs","names":[],"sources":["../../src/rich/policy.ts","../../src/rich/text.ts"],"sourcesContent":["/**\n * What portable rich text may contain: the elements, attributes and CSS that Gmail,\n * Outlook, Apple Mail, Google Docs, Word, Notion and Slack keep, and nothing that\n * can run, load or track. Everything not listed here is left out.\n */\n\n/** Elements written as they are. */\nexport const KEEP: ReadonlySet<string> = /* @__PURE__ */ new Set([\n 'a', 'abbr', 'b', 'bdi', 'bdo', 'blockquote', 'br', 'caption', 'cite', 'code', 'col', 'colgroup', 'dd', 'del', 'dfn', 'div', 'dl', 'dt',\n 'em', 'figcaption', 'figure', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'hr', 'i', 'img', 'ins', 'kbd', 'li', 'mark', 'ol', 'p', 'pre', 'q', 's',\n 'samp', 'small', 'span', 'strong', 'sub', 'sup', 'table', 'tbody', 'td', 'tfoot', 'th', 'thead', 'time', 'tr', 'u', 'ul', 'var',\n]);\n\n/** Elements left out with everything inside them: they run, load, embed, or are page chrome. */\nexport const DROP: ReadonlySet<string> = /* @__PURE__ */ new Set([\n 'applet', 'audio', 'base', 'button', 'canvas', 'datalist', 'dialog', 'embed', 'frame', 'frameset', 'head', 'iframe', 'input', 'link',\n 'map', 'math', 'meta', 'meter', 'noembed', 'noframes', 'noscript', 'object', 'option', 'optgroup', 'output', 'param', 'portal',\n 'progress', 'script', 'select', 'slot', 'source', 'style', 'svg', 'template', 'textarea', 'title', 'track', 'video',\n]);\n\n/** Elements that become a `<div>`: blocks without an email-safe equivalent. */\nexport const AS_BLOCK: ReadonlySet<string> = /* @__PURE__ */ new Set([\n 'address', 'article', 'aside', 'body', 'center', 'details', 'fieldset', 'footer', 'form', 'header', 'hgroup', 'html', 'legend',\n 'listing', 'main', 'menu', 'nav', 'plaintext', 'search', 'section', 'summary', 'xmp',\n]);\n\n/** Elements whose children are block-level text in the plain-text version. */\nexport const TEXT_BLOCKS: ReadonlySet<string> = /* @__PURE__ */ new Set([\n 'blockquote', 'caption', 'dd', 'div', 'dl', 'dt', 'figcaption', 'figure', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'hr', 'li', 'ol', 'p',\n 'pre', 'table', 'tbody', 'tfoot', 'thead', 'tr', 'ul',\n]);\n\n/** What table parts may contain: anything else is moved out of the table by every HTML parser. */\nexport const TABLE_CHILDREN: Readonly<Record<string, ReadonlySet<string>>> = {\n table: /* @__PURE__ */ new Set(['caption', 'colgroup', 'thead', 'tbody', 'tfoot', 'tr']),\n thead: /* @__PURE__ */ new Set(['tr']),\n tbody: /* @__PURE__ */ new Set(['tr']),\n tfoot: /* @__PURE__ */ new Set(['tr']),\n tr: /* @__PURE__ */ new Set(['td', 'th']),\n colgroup: /* @__PURE__ */ new Set(['col']),\n};\n\n/** Elements that hold only text-level content: a block inside one would be split out by HTML parsers. */\nexport const PHRASING: ReadonlySet<string> = /* @__PURE__ */ new Set([\n 'a', 'abbr', 'b', 'bdi', 'bdo', 'cite', 'code', 'del', 'dfn', 'em', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'i', 'ins', 'kbd', 'mark', 'p', 'q',\n 's', 'samp', 'small', 'span', 'strong', 'sub', 'sup', 'time', 'u', 'var',\n]);\n\n/** Table parts: outside their own parent, HTML parsers ignore their tags. */\nexport const TABLE_PARTS: ReadonlySet<string> = /* @__PURE__ */ new Set(['caption', 'col', 'colgroup', 'tbody', 'td', 'tfoot', 'th', 'thead', 'tr']);\n\nexport const HEADINGS: ReadonlySet<string> = /* @__PURE__ */ new Set(['h1', 'h2', 'h3', 'h4', 'h5', 'h6']);\n\n/** Elements whose start tag closes an open `<p>`: a paragraph holding one is split in two by HTML parsers. */\nexport const CLOSES_P: ReadonlySet<string> = /* @__PURE__ */ new Set([\n 'blockquote', 'dd', 'dl', 'dt', 'figcaption', 'figure', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'hr', 'li', 'ol', 'p', 'pre', 'table', 'ul',\n]);\n\n/** Where HTML parsers stop looking for an open list item to close: their \"special\" elements, less address, div and p. */\nconst ITEM_SCOPE: ReadonlySet<string> = /* @__PURE__ */ new Set([\n 'blockquote', 'br', 'caption', 'col', 'colgroup', 'dd', 'dl', 'dt', 'figcaption', 'figure', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'hr', 'img',\n 'li', 'ol', 'pre', 'table', 'tbody', 'td', 'tfoot', 'th', 'thead', 'tr', 'ul',\n]);\n\n/** Whether a new `li` (or `dd`, `dt`) under `parent` would close an open one, as HTML parsers do with `<li>` in `<li>`. */\nexport function closesItem(name: 'li' | 'dd' | 'dt', parent: Node | null): boolean {\n const group = name === 'li' ? ['li'] : ['dd', 'dt'];\n for (let node = parent; node !== null && node.nodeType === 1; node = node.parentNode) {\n const tag = (node as Element).localName;\n if (group.includes(tag)) return true;\n if (ITEM_SCOPE.has(tag)) return false;\n }\n return false;\n}\n\nconst INTEGER = /^\\d{1,4}$/;\n\n/** Attributes kept per element (after `href` and `src`, which are checked as URLs). */\nexport function attributeAllowed(tag: string, name: string, value: string): boolean {\n switch (name) {\n case 'dir':\n return /^(?:ltr|rtl|auto)$/i.test(value);\n case 'lang':\n return /^[a-z]{2,3}(?:-[a-z\\d]{1,8})*$/i.test(value);\n case 'title':\n // Images write their own title, alt, size and source.\n return ['a', 'abbr', 'dfn'].includes(tag);\n case 'colspan':\n case 'rowspan':\n return (tag === 'td' || tag === 'th') && INTEGER.test(value) && Number(value) >= 1 && Number(value) <= 1000;\n case 'scope':\n return tag === 'th' && /^(?:row|col|rowgroup|colgroup)$/i.test(value);\n case 'span':\n return (tag === 'col' || tag === 'colgroup') && INTEGER.test(value);\n case 'start':\n return tag === 'ol' && /^-?\\d{1,9}$/.test(value);\n case 'reversed':\n return tag === 'ol';\n case 'type':\n return tag === 'ol' && /^[1aAiI]$/.test(value);\n case 'value':\n return tag === 'li' && /^-?\\d{1,9}$/.test(value);\n case 'datetime':\n return tag === 'time' && /^[\\d\\-:T.+ Z]{1,40}$/.test(value);\n default:\n return false;\n }\n}\n","import { TEXT_BLOCKS } from './policy';\n\n/**\n * Readable plain text for sanitized rich content: blocks on their own lines, list\n * items with bullets or numbers (indented when nested), table cells separated by tabs,\n * images by their alt text, and preformatted text as it is.\n */\nexport function plainText(root: HTMLElement): string {\n const lines: string[] = [];\n let line = '';\n const flush = () => {\n const trimmed = line.replace(/[ \\t\\u00A0]+$/, '');\n if (trimmed !== '' || (lines.length > 0 && lines[lines.length - 1] !== '')) lines.push(trimmed);\n line = '';\n };\n const breakBlock = () => {\n if (line.trim() !== '') flush();\n else line = '';\n };\n\n const walk = (node: Node, pre: boolean, depth: number): void => {\n if (node.nodeType === 3) {\n const data = (node as Text).data;\n if (pre) line += data.replace(/\\r\\n?/g, '\\n');\n else {\n // Whitespace collapses across text nodes too, as it does when a browser renders it.\n const collapsed = data.replace(/\\s+/g, ' ');\n // A space at the start of a line or a cell shows nothing.\n line += /(?:^|[ \\t])$/.test(line) && collapsed.startsWith(' ') ? collapsed.slice(1) : collapsed;\n }\n if (pre && line.includes('\\n')) {\n const parts = line.split('\\n');\n line = parts.pop() as string;\n for (const part of parts) lines.push(part);\n }\n if (!pre && line.trimStart() === '') line = '';\n return;\n }\n if (node.nodeType !== 1) return;\n const element = node as HTMLElement;\n const tag = element.localName;\n switch (tag) {\n case 'br':\n flush();\n return;\n case 'img':\n line += element.getAttribute('alt') ?? '';\n return;\n case 'hr':\n breakBlock();\n lines.push('\\u2014'.repeat(3));\n return;\n case 'td':\n case 'th':\n if (element.previousElementSibling !== null) line += '\\t';\n element.childNodes.forEach((child) => {\n walk(child, pre, depth);\n });\n return;\n case 'li': {\n breakBlock();\n const list = element.parentElement;\n const ordered = list?.localName === 'ol';\n let marker = '\\u2022';\n if (ordered) {\n const items = Array.from(list.children).filter((child) => child.localName === 'li');\n const start = Number(list.getAttribute('start') ?? '1');\n const own = element.getAttribute('value');\n marker = `${String(own === null ? start + items.indexOf(element) : Number(own))}.`;\n }\n line = `${' '.repeat(Math.max(0, depth - 1))}${marker} `;\n element.childNodes.forEach((child) => {\n walk(child, pre, depth);\n });\n breakBlock();\n return;\n }\n default: {\n const block = TEXT_BLOCKS.has(tag);\n const list = tag === 'ul' || tag === 'ol';\n if (block) breakBlock();\n const keep = pre || tag === 'pre' || /white-space:\\s*pre/.test(element.getAttribute('style') ?? '');\n element.childNodes.forEach((child) => {\n walk(child, keep, list ? depth + 1 : depth);\n });\n if (block) breakBlock();\n }\n }\n };\n walk(root, false, 0);\n flush();\n return lines\n .join('\\n')\n .replace(/\\n{3,}/g, '\\n\\n')\n .trim();\n}\n"],"mappings":";;;;;;;;AAOA,MAAa,uBAA4C,IAAI,IAAI;CAC/D;CAAK;CAAQ;CAAK;CAAO;CAAO;CAAc;CAAM;CAAW;CAAQ;CAAQ;CAAO;CAAY;CAAM;CAAO;CAAO;CAAO;CAAM;CACnI;CAAM;CAAc;CAAU;CAAM;CAAM;CAAM;CAAM;CAAM;CAAM;CAAM;CAAK;CAAO;CAAO;CAAO;CAAM;CAAQ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