react-smart-copy 1.30.0 → 1.31.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/README.md +4 -1
- package/dist/chunks/copy-machine-B6apNst5.d.ts +132 -0
- package/dist/chunks/copy-machine-CmqX9J4V.d.cts +132 -0
- package/dist/chunks/copy-machine-DwdB-qva.js +292 -0
- package/dist/chunks/copy-machine-DwdB-qva.js.map +1 -0
- package/dist/chunks/copy-machine-oNmnrjMc.cjs +345 -0
- package/dist/chunks/copy-machine-oNmnrjMc.cjs.map +1 -0
- package/dist/chunks/{core-B8_wVOSU.js → core-CNSd-EgZ.js} +4 -290
- package/dist/chunks/core-CNSd-EgZ.js.map +1 -0
- package/dist/chunks/{core-BR8Jgea1.cjs → core-DsMKPNx_.cjs} +20 -348
- package/dist/chunks/core-DsMKPNx_.cjs.map +1 -0
- package/dist/chunks/{index-DjqQGsNs.d.ts → index-B4SEFtkx.d.ts} +3 -131
- package/dist/chunks/{index-uHZHddq0.d.cts → index-BDxj1EqC.d.cts} +3 -131
- package/dist/chunks/text-C2OYT-3o.cjs +478 -0
- package/dist/chunks/text-C2OYT-3o.cjs.map +1 -0
- package/dist/chunks/text-nc1LhgIh.js +413 -0
- package/dist/chunks/text-nc1LhgIh.js.map +1 -0
- package/dist/chunks/utils-C7_VlH79.cjs +53 -0
- package/dist/chunks/utils-C7_VlH79.cjs.map +1 -0
- package/dist/chunks/utils-CBBX2HN6.js +30 -0
- package/dist/chunks/utils-CBBX2HN6.js.map +1 -0
- package/dist/compat.cjs +94 -0
- package/dist/compat.cjs.map +1 -0
- package/dist/compat.d.cts +57 -0
- package/dist/compat.d.ts +57 -0
- package/dist/compat.js +88 -0
- package/dist/compat.js.map +1 -0
- package/dist/core.cjs +8 -7
- package/dist/core.d.cts +2 -1
- package/dist/core.d.ts +2 -1
- package/dist/core.js +2 -1
- package/dist/index.cjs +45 -68
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +4 -27
- package/dist/index.js.map +1 -1
- package/dist/rich.cjs +14 -422
- package/dist/rich.cjs.map +1 -1
- package/dist/rich.js +1 -409
- package/dist/rich.js.map +1 -1
- package/package.json +20 -1
- package/dist/chunks/core-B8_wVOSU.js.map +0 -1
- package/dist/chunks/core-BR8Jgea1.cjs.map +0 -1
package/dist/rich.js
CHANGED
|
@@ -4,325 +4,7 @@ import { i as linkUrlResolver } from "./chunks/url-zB_krkuF.js";
|
|
|
4
4
|
import { n as parseInertHtml } from "./chunks/inert-html-BxuTrb6R.js";
|
|
5
5
|
import { a as unwrapRedirect } from "./chunks/url-vJaFPbNL.js";
|
|
6
6
|
import { i as formatColor, l as toGamut, n as contrastRatio, o as parseColor, s as color } from "./chunks/contrast-DnCunIr1.js";
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* What portable rich text may contain: the elements, attributes and CSS that Gmail,
|
|
10
|
-
* Outlook, Apple Mail, Google Docs, Word, Notion and Slack keep, and nothing that
|
|
11
|
-
* can run, load or track. Everything not listed here is left out.
|
|
12
|
-
*/
|
|
13
|
-
/** Elements written as they are. */
|
|
14
|
-
const KEEP = /* @__PURE__ */ new Set([
|
|
15
|
-
"a",
|
|
16
|
-
"abbr",
|
|
17
|
-
"b",
|
|
18
|
-
"bdi",
|
|
19
|
-
"bdo",
|
|
20
|
-
"blockquote",
|
|
21
|
-
"br",
|
|
22
|
-
"caption",
|
|
23
|
-
"cite",
|
|
24
|
-
"code",
|
|
25
|
-
"col",
|
|
26
|
-
"colgroup",
|
|
27
|
-
"dd",
|
|
28
|
-
"del",
|
|
29
|
-
"dfn",
|
|
30
|
-
"div",
|
|
31
|
-
"dl",
|
|
32
|
-
"dt",
|
|
33
|
-
"em",
|
|
34
|
-
"figcaption",
|
|
35
|
-
"figure",
|
|
36
|
-
"h1",
|
|
37
|
-
"h2",
|
|
38
|
-
"h3",
|
|
39
|
-
"h4",
|
|
40
|
-
"h5",
|
|
41
|
-
"h6",
|
|
42
|
-
"hr",
|
|
43
|
-
"i",
|
|
44
|
-
"img",
|
|
45
|
-
"ins",
|
|
46
|
-
"kbd",
|
|
47
|
-
"li",
|
|
48
|
-
"mark",
|
|
49
|
-
"ol",
|
|
50
|
-
"p",
|
|
51
|
-
"pre",
|
|
52
|
-
"q",
|
|
53
|
-
"s",
|
|
54
|
-
"samp",
|
|
55
|
-
"small",
|
|
56
|
-
"span",
|
|
57
|
-
"strong",
|
|
58
|
-
"sub",
|
|
59
|
-
"sup",
|
|
60
|
-
"table",
|
|
61
|
-
"tbody",
|
|
62
|
-
"td",
|
|
63
|
-
"tfoot",
|
|
64
|
-
"th",
|
|
65
|
-
"thead",
|
|
66
|
-
"time",
|
|
67
|
-
"tr",
|
|
68
|
-
"u",
|
|
69
|
-
"ul",
|
|
70
|
-
"var"
|
|
71
|
-
]);
|
|
72
|
-
/** Elements left out with everything inside them: they run, load, embed, or are page chrome. */
|
|
73
|
-
const DROP = /* @__PURE__ */ new Set([
|
|
74
|
-
"applet",
|
|
75
|
-
"audio",
|
|
76
|
-
"base",
|
|
77
|
-
"button",
|
|
78
|
-
"canvas",
|
|
79
|
-
"datalist",
|
|
80
|
-
"dialog",
|
|
81
|
-
"embed",
|
|
82
|
-
"frame",
|
|
83
|
-
"frameset",
|
|
84
|
-
"head",
|
|
85
|
-
"iframe",
|
|
86
|
-
"input",
|
|
87
|
-
"link",
|
|
88
|
-
"map",
|
|
89
|
-
"math",
|
|
90
|
-
"meta",
|
|
91
|
-
"meter",
|
|
92
|
-
"noembed",
|
|
93
|
-
"noframes",
|
|
94
|
-
"noscript",
|
|
95
|
-
"object",
|
|
96
|
-
"option",
|
|
97
|
-
"optgroup",
|
|
98
|
-
"output",
|
|
99
|
-
"param",
|
|
100
|
-
"portal",
|
|
101
|
-
"progress",
|
|
102
|
-
"script",
|
|
103
|
-
"select",
|
|
104
|
-
"slot",
|
|
105
|
-
"source",
|
|
106
|
-
"style",
|
|
107
|
-
"svg",
|
|
108
|
-
"template",
|
|
109
|
-
"textarea",
|
|
110
|
-
"title",
|
|
111
|
-
"track",
|
|
112
|
-
"video"
|
|
113
|
-
]);
|
|
114
|
-
/** Elements that become a `<div>`: blocks without an email-safe equivalent. */
|
|
115
|
-
const AS_BLOCK = /* @__PURE__ */ new Set([
|
|
116
|
-
"address",
|
|
117
|
-
"article",
|
|
118
|
-
"aside",
|
|
119
|
-
"body",
|
|
120
|
-
"center",
|
|
121
|
-
"details",
|
|
122
|
-
"fieldset",
|
|
123
|
-
"footer",
|
|
124
|
-
"form",
|
|
125
|
-
"header",
|
|
126
|
-
"hgroup",
|
|
127
|
-
"html",
|
|
128
|
-
"legend",
|
|
129
|
-
"listing",
|
|
130
|
-
"main",
|
|
131
|
-
"menu",
|
|
132
|
-
"nav",
|
|
133
|
-
"plaintext",
|
|
134
|
-
"search",
|
|
135
|
-
"section",
|
|
136
|
-
"summary",
|
|
137
|
-
"xmp"
|
|
138
|
-
]);
|
|
139
|
-
/** Elements whose children are block-level text in the plain-text version. */
|
|
140
|
-
const TEXT_BLOCKS = /* @__PURE__ */ new Set([
|
|
141
|
-
"blockquote",
|
|
142
|
-
"caption",
|
|
143
|
-
"dd",
|
|
144
|
-
"div",
|
|
145
|
-
"dl",
|
|
146
|
-
"dt",
|
|
147
|
-
"figcaption",
|
|
148
|
-
"figure",
|
|
149
|
-
"h1",
|
|
150
|
-
"h2",
|
|
151
|
-
"h3",
|
|
152
|
-
"h4",
|
|
153
|
-
"h5",
|
|
154
|
-
"h6",
|
|
155
|
-
"hr",
|
|
156
|
-
"li",
|
|
157
|
-
"ol",
|
|
158
|
-
"p",
|
|
159
|
-
"pre",
|
|
160
|
-
"table",
|
|
161
|
-
"tbody",
|
|
162
|
-
"tfoot",
|
|
163
|
-
"thead",
|
|
164
|
-
"tr",
|
|
165
|
-
"ul"
|
|
166
|
-
]);
|
|
167
|
-
/** What table parts may contain: anything else is moved out of the table by every HTML parser. */
|
|
168
|
-
const TABLE_CHILDREN = {
|
|
169
|
-
table: /* @__PURE__ */ new Set([
|
|
170
|
-
"caption",
|
|
171
|
-
"colgroup",
|
|
172
|
-
"thead",
|
|
173
|
-
"tbody",
|
|
174
|
-
"tfoot",
|
|
175
|
-
"tr"
|
|
176
|
-
]),
|
|
177
|
-
thead: /* @__PURE__ */ new Set(["tr"]),
|
|
178
|
-
tbody: /* @__PURE__ */ new Set(["tr"]),
|
|
179
|
-
tfoot: /* @__PURE__ */ new Set(["tr"]),
|
|
180
|
-
tr: /* @__PURE__ */ new Set(["td", "th"]),
|
|
181
|
-
colgroup: /* @__PURE__ */ new Set(["col"])
|
|
182
|
-
};
|
|
183
|
-
/** Elements that hold only text-level content: a block inside one would be split out by HTML parsers. */
|
|
184
|
-
const PHRASING = /* @__PURE__ */ new Set([
|
|
185
|
-
"a",
|
|
186
|
-
"abbr",
|
|
187
|
-
"b",
|
|
188
|
-
"bdi",
|
|
189
|
-
"bdo",
|
|
190
|
-
"cite",
|
|
191
|
-
"code",
|
|
192
|
-
"del",
|
|
193
|
-
"dfn",
|
|
194
|
-
"em",
|
|
195
|
-
"h1",
|
|
196
|
-
"h2",
|
|
197
|
-
"h3",
|
|
198
|
-
"h4",
|
|
199
|
-
"h5",
|
|
200
|
-
"h6",
|
|
201
|
-
"i",
|
|
202
|
-
"ins",
|
|
203
|
-
"kbd",
|
|
204
|
-
"mark",
|
|
205
|
-
"p",
|
|
206
|
-
"q",
|
|
207
|
-
"s",
|
|
208
|
-
"samp",
|
|
209
|
-
"small",
|
|
210
|
-
"span",
|
|
211
|
-
"strong",
|
|
212
|
-
"sub",
|
|
213
|
-
"sup",
|
|
214
|
-
"time",
|
|
215
|
-
"u",
|
|
216
|
-
"var"
|
|
217
|
-
]);
|
|
218
|
-
/** Table parts: outside their own parent, HTML parsers ignore their tags. */
|
|
219
|
-
const TABLE_PARTS = /* @__PURE__ */ new Set([
|
|
220
|
-
"caption",
|
|
221
|
-
"col",
|
|
222
|
-
"colgroup",
|
|
223
|
-
"tbody",
|
|
224
|
-
"td",
|
|
225
|
-
"tfoot",
|
|
226
|
-
"th",
|
|
227
|
-
"thead",
|
|
228
|
-
"tr"
|
|
229
|
-
]);
|
|
230
|
-
const HEADINGS$1 = /* @__PURE__ */ new Set([
|
|
231
|
-
"h1",
|
|
232
|
-
"h2",
|
|
233
|
-
"h3",
|
|
234
|
-
"h4",
|
|
235
|
-
"h5",
|
|
236
|
-
"h6"
|
|
237
|
-
]);
|
|
238
|
-
/** Elements whose start tag closes an open `<p>`: a paragraph holding one is split in two by HTML parsers. */
|
|
239
|
-
const CLOSES_P = /* @__PURE__ */ new Set([
|
|
240
|
-
"blockquote",
|
|
241
|
-
"dd",
|
|
242
|
-
"dl",
|
|
243
|
-
"dt",
|
|
244
|
-
"figcaption",
|
|
245
|
-
"figure",
|
|
246
|
-
"h1",
|
|
247
|
-
"h2",
|
|
248
|
-
"h3",
|
|
249
|
-
"h4",
|
|
250
|
-
"h5",
|
|
251
|
-
"h6",
|
|
252
|
-
"hr",
|
|
253
|
-
"li",
|
|
254
|
-
"ol",
|
|
255
|
-
"p",
|
|
256
|
-
"pre",
|
|
257
|
-
"table",
|
|
258
|
-
"ul"
|
|
259
|
-
]);
|
|
260
|
-
/** Where HTML parsers stop looking for an open list item to close: their "special" elements, less address, div and p. */
|
|
261
|
-
const ITEM_SCOPE = /* @__PURE__ */ new Set([
|
|
262
|
-
"blockquote",
|
|
263
|
-
"br",
|
|
264
|
-
"caption",
|
|
265
|
-
"col",
|
|
266
|
-
"colgroup",
|
|
267
|
-
"dd",
|
|
268
|
-
"dl",
|
|
269
|
-
"dt",
|
|
270
|
-
"figcaption",
|
|
271
|
-
"figure",
|
|
272
|
-
"h1",
|
|
273
|
-
"h2",
|
|
274
|
-
"h3",
|
|
275
|
-
"h4",
|
|
276
|
-
"h5",
|
|
277
|
-
"h6",
|
|
278
|
-
"hr",
|
|
279
|
-
"img",
|
|
280
|
-
"li",
|
|
281
|
-
"ol",
|
|
282
|
-
"pre",
|
|
283
|
-
"table",
|
|
284
|
-
"tbody",
|
|
285
|
-
"td",
|
|
286
|
-
"tfoot",
|
|
287
|
-
"th",
|
|
288
|
-
"thead",
|
|
289
|
-
"tr",
|
|
290
|
-
"ul"
|
|
291
|
-
]);
|
|
292
|
-
/** Whether a new `li` (or `dd`, `dt`) under `parent` would close an open one, as HTML parsers do with `<li>` in `<li>`. */
|
|
293
|
-
function closesItem(name, parent) {
|
|
294
|
-
const group = name === "li" ? ["li"] : ["dd", "dt"];
|
|
295
|
-
for (let node = parent; node !== null && node.nodeType === 1; node = node.parentNode) {
|
|
296
|
-
const tag = node.localName;
|
|
297
|
-
if (group.includes(tag)) return true;
|
|
298
|
-
if (ITEM_SCOPE.has(tag)) return false;
|
|
299
|
-
}
|
|
300
|
-
return false;
|
|
301
|
-
}
|
|
302
|
-
const INTEGER = /^\d{1,4}$/;
|
|
303
|
-
/** Attributes kept per element (after `href` and `src`, which are checked as URLs). */
|
|
304
|
-
function attributeAllowed(tag, name, value) {
|
|
305
|
-
switch (name) {
|
|
306
|
-
case "dir": return /^(?:ltr|rtl|auto)$/i.test(value);
|
|
307
|
-
case "lang": return /^[a-z]{2,3}(?:-[a-z\d]{1,8})*$/i.test(value);
|
|
308
|
-
case "title": return [
|
|
309
|
-
"a",
|
|
310
|
-
"abbr",
|
|
311
|
-
"dfn"
|
|
312
|
-
].includes(tag);
|
|
313
|
-
case "colspan":
|
|
314
|
-
case "rowspan": return (tag === "td" || tag === "th") && INTEGER.test(value) && Number(value) >= 1 && Number(value) <= 1e3;
|
|
315
|
-
case "scope": return tag === "th" && /^(?:row|col|rowgroup|colgroup)$/i.test(value);
|
|
316
|
-
case "span": return (tag === "col" || tag === "colgroup") && INTEGER.test(value);
|
|
317
|
-
case "start": return tag === "ol" && /^-?\d{1,9}$/.test(value);
|
|
318
|
-
case "reversed": return tag === "ol";
|
|
319
|
-
case "type": return tag === "ol" && /^[1aAiI]$/.test(value);
|
|
320
|
-
case "value": return tag === "li" && /^-?\d{1,9}$/.test(value);
|
|
321
|
-
case "datetime": return tag === "time" && /^[\d\-:T.+ Z]{1,40}$/.test(value);
|
|
322
|
-
default: return false;
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
//#endregion
|
|
7
|
+
import { a as HEADINGS$1, c as TABLE_CHILDREN, d as closesItem, i as DROP, l as TABLE_PARTS, n as AS_BLOCK, o as KEEP, r as CLOSES_P, s as PHRASING, t as plainText, u as attributeAllowed } from "./chunks/text-nc1LhgIh.js";
|
|
326
8
|
//#region src/rich/style.ts
|
|
327
9
|
const INHERITED = [
|
|
328
10
|
"color",
|
|
@@ -532,96 +214,6 @@ function box(values, background, colors) {
|
|
|
532
214
|
return out;
|
|
533
215
|
}
|
|
534
216
|
//#endregion
|
|
535
|
-
//#region src/rich/text.ts
|
|
536
|
-
/**
|
|
537
|
-
* Readable plain text for sanitized rich content: blocks on their own lines, list
|
|
538
|
-
* items with bullets or numbers (indented when nested), table cells separated by tabs,
|
|
539
|
-
* images by their alt text, and preformatted text as it is.
|
|
540
|
-
*/
|
|
541
|
-
function plainText(root) {
|
|
542
|
-
const lines = [];
|
|
543
|
-
let line = "";
|
|
544
|
-
const flush = () => {
|
|
545
|
-
const trimmed = line.replace(/[ \t\u00A0]+$/, "");
|
|
546
|
-
if (trimmed !== "" || lines.length > 0 && lines[lines.length - 1] !== "") lines.push(trimmed);
|
|
547
|
-
line = "";
|
|
548
|
-
};
|
|
549
|
-
const breakBlock = () => {
|
|
550
|
-
if (line.trim() !== "") flush();
|
|
551
|
-
else line = "";
|
|
552
|
-
};
|
|
553
|
-
const walk = (node, pre, depth) => {
|
|
554
|
-
if (node.nodeType === 3) {
|
|
555
|
-
const data = node.data;
|
|
556
|
-
if (pre) line += data.replace(/\r\n?/g, "\n");
|
|
557
|
-
else {
|
|
558
|
-
const collapsed = data.replace(/\s+/g, " ");
|
|
559
|
-
line += /(?:^|[ \t])$/.test(line) && collapsed.startsWith(" ") ? collapsed.slice(1) : collapsed;
|
|
560
|
-
}
|
|
561
|
-
if (pre && line.includes("\n")) {
|
|
562
|
-
const parts = line.split("\n");
|
|
563
|
-
line = parts.pop();
|
|
564
|
-
for (const part of parts) lines.push(part);
|
|
565
|
-
}
|
|
566
|
-
if (!pre && line.trimStart() === "") line = "";
|
|
567
|
-
return;
|
|
568
|
-
}
|
|
569
|
-
if (node.nodeType !== 1) return;
|
|
570
|
-
const element = node;
|
|
571
|
-
const tag = element.localName;
|
|
572
|
-
switch (tag) {
|
|
573
|
-
case "br":
|
|
574
|
-
flush();
|
|
575
|
-
return;
|
|
576
|
-
case "img":
|
|
577
|
-
line += element.getAttribute("alt") ?? "";
|
|
578
|
-
return;
|
|
579
|
-
case "hr":
|
|
580
|
-
breakBlock();
|
|
581
|
-
lines.push("—".repeat(3));
|
|
582
|
-
return;
|
|
583
|
-
case "td":
|
|
584
|
-
case "th":
|
|
585
|
-
if (element.previousElementSibling !== null) line += " ";
|
|
586
|
-
element.childNodes.forEach((child) => {
|
|
587
|
-
walk(child, pre, depth);
|
|
588
|
-
});
|
|
589
|
-
return;
|
|
590
|
-
case "li": {
|
|
591
|
-
breakBlock();
|
|
592
|
-
const list = element.parentElement;
|
|
593
|
-
const ordered = list?.localName === "ol";
|
|
594
|
-
let marker = "•";
|
|
595
|
-
if (ordered) {
|
|
596
|
-
const items = Array.from(list.children).filter((child) => child.localName === "li");
|
|
597
|
-
const start = Number(list.getAttribute("start") ?? "1");
|
|
598
|
-
const own = element.getAttribute("value");
|
|
599
|
-
marker = `${String(own === null ? start + items.indexOf(element) : Number(own))}.`;
|
|
600
|
-
}
|
|
601
|
-
line = `${" ".repeat(Math.max(0, depth - 1))}${marker} `;
|
|
602
|
-
element.childNodes.forEach((child) => {
|
|
603
|
-
walk(child, pre, depth);
|
|
604
|
-
});
|
|
605
|
-
breakBlock();
|
|
606
|
-
return;
|
|
607
|
-
}
|
|
608
|
-
default: {
|
|
609
|
-
const block = TEXT_BLOCKS.has(tag);
|
|
610
|
-
const list = tag === "ul" || tag === "ol";
|
|
611
|
-
if (block) breakBlock();
|
|
612
|
-
const keep = pre || tag === "pre" || /white-space:\s*pre/.test(element.getAttribute("style") ?? "");
|
|
613
|
-
element.childNodes.forEach((child) => {
|
|
614
|
-
walk(child, keep, list ? depth + 1 : depth);
|
|
615
|
-
});
|
|
616
|
-
if (block) breakBlock();
|
|
617
|
-
}
|
|
618
|
-
}
|
|
619
|
-
};
|
|
620
|
-
walk(root, false, 0);
|
|
621
|
-
flush();
|
|
622
|
-
return lines.join("\n").replace(/\n{3,}/g, "\n\n").trim();
|
|
623
|
-
}
|
|
624
|
-
//#endregion
|
|
625
217
|
//#region src/rich/walk.ts
|
|
626
218
|
const VOID = /* @__PURE__ */ new Set([
|
|
627
219
|
"br",
|