react-smart-copy 1.23.0 → 1.24.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 (148) hide show
  1. package/README.md +130 -1806
  2. package/dist/capture.cjs +3 -3
  3. package/dist/capture.d.cts +1 -1
  4. package/dist/capture.d.ts +1 -1
  5. package/dist/capture.js +3 -3
  6. package/dist/chunks/{clipboard-adapter-CtH4VELE.d.cts → clipboard-adapter-CfaIbZpv.d.cts} +2 -2
  7. package/dist/chunks/{clipboard-adapter-Ds0irroN.d.ts → clipboard-adapter-Chm6zq60.d.ts} +2 -2
  8. package/dist/chunks/{clipboard-adapter-DEXkXxwV.js → clipboard-adapter-CmKDTFdO.js} +3 -3
  9. package/dist/chunks/{clipboard-adapter-DEXkXxwV.js.map → clipboard-adapter-CmKDTFdO.js.map} +1 -1
  10. package/dist/chunks/{clipboard-adapter-Cfz-rzw3.cjs → clipboard-adapter-UIFc_Qso.cjs} +3 -3
  11. package/dist/chunks/{clipboard-adapter-Cfz-rzw3.cjs.map → clipboard-adapter-UIFc_Qso.cjs.map} +1 -1
  12. package/dist/chunks/{contrast-C6CVklEI.cjs → contrast-C9d8QuaF.cjs} +2 -2
  13. package/dist/chunks/{contrast-C6CVklEI.cjs.map → contrast-C9d8QuaF.cjs.map} +1 -1
  14. package/dist/chunks/{contrast-DpK2JIVu.js → contrast-DUaZq5SA.js} +2 -2
  15. package/dist/chunks/{contrast-DpK2JIVu.js.map → contrast-DUaZq5SA.js.map} +1 -1
  16. package/dist/chunks/{copy-interceptor-CZWzGOkL.d.cts → copy-interceptor-BClcHS_P.d.cts} +2 -2
  17. package/dist/chunks/{copy-interceptor-C6NABy1l.d.ts → copy-interceptor-D8c9EDnO.d.ts} +2 -2
  18. package/dist/chunks/{core-Cp2HSpaz.js → core-BH2uIumi.js} +5 -5
  19. package/dist/chunks/{core-Cp2HSpaz.js.map → core-BH2uIumi.js.map} +1 -1
  20. package/dist/chunks/{core-DYf_Lhbe.cjs → core-DmncxMt3.cjs} +5 -5
  21. package/dist/chunks/{core-DYf_Lhbe.cjs.map → core-DmncxMt3.cjs.map} +1 -1
  22. package/dist/chunks/{deadline-C29AlS_Q.js → deadline-CbwnZ3Oq.js} +2 -2
  23. package/dist/chunks/{deadline-C29AlS_Q.js.map → deadline-CbwnZ3Oq.js.map} +1 -1
  24. package/dist/chunks/{deadline-DkiB8ZHE.cjs → deadline-j2hD7JKz.cjs} +2 -2
  25. package/dist/chunks/{deadline-DkiB8ZHE.cjs.map → deadline-j2hD7JKz.cjs.map} +1 -1
  26. package/dist/chunks/{errors-9h8sdFFX.js → errors-CT-FfUtU.js} +2 -2
  27. package/dist/chunks/errors-CT-FfUtU.js.map +1 -0
  28. package/dist/chunks/{errors-BwOF6T_M.cjs → errors-DFmEAC4E.cjs} +2 -2
  29. package/dist/chunks/errors-DFmEAC4E.cjs.map +1 -0
  30. package/dist/chunks/{field-BHo5y-t_.js → field-CK3NxfkM.js} +43 -14
  31. package/dist/chunks/field-CK3NxfkM.js.map +1 -0
  32. package/dist/chunks/{field-Bytz2WfN.cjs → field-CNEcZqa9.cjs} +43 -14
  33. package/dist/chunks/field-CNEcZqa9.cjs.map +1 -0
  34. package/dist/chunks/{index-vz0iW5V2.d.cts → index-CqYzvxSN.d.cts} +4 -4
  35. package/dist/chunks/{index-mr7sSAgP.d.ts → index-Q_QeSwGr.d.ts} +4 -4
  36. package/dist/chunks/{paste-adapter--SPL4PRE.d.cts → paste-adapter-B6eucH3E.d.cts} +2 -2
  37. package/dist/chunks/{paste-adapter-uahXnTYk.d.ts → paste-adapter-CfIDT3mp.d.ts} +2 -2
  38. package/dist/chunks/{paste-reader-Bo01IMC_.cjs → paste-reader-BWQaYNaV.cjs} +2 -2
  39. package/dist/chunks/paste-reader-BWQaYNaV.cjs.map +1 -0
  40. package/dist/chunks/{paste-reader-D9i7yMXF.js → paste-reader-D6uOTDBM.js} +2 -2
  41. package/dist/chunks/paste-reader-D6uOTDBM.js.map +1 -0
  42. package/dist/chunks/{payload-DI5AorDz.js → payload-BWQ6sPtS.js} +3 -3
  43. package/dist/chunks/{payload-DI5AorDz.js.map → payload-BWQ6sPtS.js.map} +1 -1
  44. package/dist/chunks/{payload-DGw-JOo7.js → payload-BrQWGwyx.js} +2 -2
  45. package/dist/chunks/{payload-DGw-JOo7.js.map → payload-BrQWGwyx.js.map} +1 -1
  46. package/dist/chunks/{payload-Cl_8hCI5.d.ts → payload-CcvSx_Hq.d.ts} +4 -2
  47. package/dist/chunks/{payload-CcwKJ_bU.d.cts → payload-qkAWVXWA.d.cts} +4 -2
  48. package/dist/chunks/{payload-CUymxwim.cjs → payload-sBxkG7jH.cjs} +2 -2
  49. package/dist/chunks/{payload-CUymxwim.cjs.map → payload-sBxkG7jH.cjs.map} +1 -1
  50. package/dist/chunks/{payload-J6GjHuh3.cjs → payload-tTK6REua.cjs} +3 -3
  51. package/dist/chunks/{payload-J6GjHuh3.cjs.map → payload-tTK6REua.cjs.map} +1 -1
  52. package/dist/chunks/{share-Bop47Znn.js → share-CU91L4EK.js} +6 -6
  53. package/dist/chunks/{share-Bop47Znn.js.map → share-CU91L4EK.js.map} +1 -1
  54. package/dist/chunks/{share-e7FenIr2.d.ts → share-DVR_DhHc.d.ts} +3 -3
  55. package/dist/chunks/{share-C0esXvRK.d.cts → share-hIwth7Dh.d.cts} +3 -3
  56. package/dist/chunks/{share-ayDz974N.cjs → share-nx7M4Z0t.cjs} +6 -6
  57. package/dist/chunks/{share-ayDz974N.cjs.map → share-nx7M4Z0t.cjs.map} +1 -1
  58. package/dist/chunks/{url-D4PGsRm8.cjs → url-BrhVUwn7.cjs} +2 -2
  59. package/dist/chunks/{url-D4PGsRm8.cjs.map → url-BrhVUwn7.cjs.map} +1 -1
  60. package/dist/chunks/{url-BcMYVCXQ.js → url-COID0BLY.js} +2 -2
  61. package/dist/chunks/{url-BcMYVCXQ.js.map → url-COID0BLY.js.map} +1 -1
  62. package/dist/code.cjs +1 -1
  63. package/dist/code.cjs.map +1 -1
  64. package/dist/code.d.cts +1 -1
  65. package/dist/code.d.ts +1 -1
  66. package/dist/code.js +1 -1
  67. package/dist/code.js.map +1 -1
  68. package/dist/color.cjs +2 -2
  69. package/dist/color.d.cts +1 -1
  70. package/dist/color.d.ts +1 -1
  71. package/dist/color.js +2 -2
  72. package/dist/core.cjs +5 -5
  73. package/dist/core.d.cts +5 -5
  74. package/dist/core.d.ts +5 -5
  75. package/dist/core.js +5 -5
  76. package/dist/email.cjs +357 -0
  77. package/dist/email.cjs.map +1 -0
  78. package/dist/email.d.cts +163 -0
  79. package/dist/email.d.ts +163 -0
  80. package/dist/email.js +351 -0
  81. package/dist/email.js.map +1 -0
  82. package/dist/files.cjs +1 -1
  83. package/dist/files.cjs.map +1 -1
  84. package/dist/files.d.cts +3 -59
  85. package/dist/files.d.ts +3 -59
  86. package/dist/files.js +1 -1
  87. package/dist/files.js.map +1 -1
  88. package/dist/image.cjs +2 -2
  89. package/dist/image.cjs.map +1 -1
  90. package/dist/image.js +2 -2
  91. package/dist/image.js.map +1 -1
  92. package/dist/index.cjs +7 -7
  93. package/dist/index.cjs.map +1 -1
  94. package/dist/index.d.cts +43 -19
  95. package/dist/index.d.ts +43 -19
  96. package/dist/index.js +7 -7
  97. package/dist/index.js.map +1 -1
  98. package/dist/link.cjs +3 -3
  99. package/dist/link.d.cts +1 -1
  100. package/dist/link.d.ts +1 -1
  101. package/dist/link.js +3 -3
  102. package/dist/markdown.cjs +1 -1
  103. package/dist/markdown.cjs.map +1 -1
  104. package/dist/markdown.js +1 -1
  105. package/dist/markdown.js.map +1 -1
  106. package/dist/number.cjs +1 -1
  107. package/dist/number.d.cts +1 -1
  108. package/dist/number.d.ts +1 -1
  109. package/dist/number.js +1 -1
  110. package/dist/otp.cjs +1 -1
  111. package/dist/otp.js +1 -1
  112. package/dist/rich.cjs +3 -3
  113. package/dist/rich.cjs.map +1 -1
  114. package/dist/rich.d.cts +2 -2
  115. package/dist/rich.d.ts +2 -2
  116. package/dist/rich.js +3 -3
  117. package/dist/rich.js.map +1 -1
  118. package/dist/secrets.cjs +1 -1
  119. package/dist/secrets.cjs.map +1 -1
  120. package/dist/secrets.d.cts +1 -1
  121. package/dist/secrets.d.ts +1 -1
  122. package/dist/secrets.js +1 -1
  123. package/dist/secrets.js.map +1 -1
  124. package/dist/share.cjs +1 -1
  125. package/dist/share.d.cts +1 -1
  126. package/dist/share.d.ts +1 -1
  127. package/dist/share.js +1 -1
  128. package/dist/structured.cjs +2 -2
  129. package/dist/structured.cjs.map +1 -1
  130. package/dist/structured.js +2 -2
  131. package/dist/structured.js.map +1 -1
  132. package/dist/table.cjs +1 -1
  133. package/dist/table.cjs.map +1 -1
  134. package/dist/table.d.cts +1 -1
  135. package/dist/table.d.ts +1 -1
  136. package/dist/table.js +1 -1
  137. package/dist/table.js.map +1 -1
  138. package/dist/testing.cjs +2 -2
  139. package/dist/testing.d.cts +3 -3
  140. package/dist/testing.d.ts +3 -3
  141. package/dist/testing.js +2 -2
  142. package/package.json +35 -6
  143. package/dist/chunks/errors-9h8sdFFX.js.map +0 -1
  144. package/dist/chunks/errors-BwOF6T_M.cjs.map +0 -1
  145. package/dist/chunks/field-BHo5y-t_.js.map +0 -1
  146. package/dist/chunks/field-Bytz2WfN.cjs.map +0 -1
  147. package/dist/chunks/paste-reader-Bo01IMC_.cjs.map +0 -1
  148. package/dist/chunks/paste-reader-D9i7yMXF.js.map +0 -1
package/dist/email.cjs ADDED
@@ -0,0 +1,357 @@
1
+
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const require_errors = require("./chunks/errors-DFmEAC4E.cjs");
4
+ const require_text_field = require("./chunks/text-field-BEzUVOag.cjs");
5
+ //#region src/email/address.ts
6
+ /** Invisible and direction-changing characters, soft hyphens and variation selectors. */
7
+ const INVISIBLE = /[\u00AD\u061C\u115F\u1160\u180E\u200B-\u200F\u202A-\u202E\u2060-\u206F\u3164\uFEFF\uFFA0]|\u034F|\u17B4|\u17B5|\p{Variation_Selector}/u;
8
+ /** A dot-atom local part (RFC 5322), with letters of any script (RFC 6531). */
9
+ const LOCAL = /^[\p{L}\p{M}\p{N}!#$%&'*+/=?^_`{|}~-]+(?:\.[\p{L}\p{M}\p{N}!#$%&'*+/=?^_`{|}~-]+)*$/u;
10
+ /** Characters that change how a URL host is read: not part of any domain. */
11
+ const NOT_DOMAIN = /[\s/?#@:[\]\\%<>"'(),;]/u;
12
+ const LABEL = /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/;
13
+ /** A top-level domain: letters, or an international one in its ASCII form. */
14
+ const TLD = /^(?:[a-z]{2,63}|xn--[a-z0-9-]{1,59})$/;
15
+ const LATIN = /\p{Script=Latin}/u;
16
+ const LOOKALIKE_SCRIPT = /[\p{Script=Cyrillic}\p{Script=Greek}]/u;
17
+ /** The domain in its ASCII form, lower case, or `null` when it is not one. */
18
+ function asciiDomain(domain) {
19
+ if (NOT_DOMAIN.test(domain)) return null;
20
+ let host;
21
+ try {
22
+ host = new URL(`http://${domain}`).hostname;
23
+ } catch {
24
+ return null;
25
+ }
26
+ const labels = host.split(".");
27
+ if (host.length > 253 || labels.length < 2 || !labels.every((label) => LABEL.test(label))) return null;
28
+ return TLD.test(String(labels[labels.length - 1])) ? host : null;
29
+ }
30
+ /** Whether a label of `domain` mixes Latin letters with lookalike Cyrillic or Greek ones. */
31
+ function isLookalike(domain) {
32
+ return domain.split(".").some((label) => LATIN.test(label) && LOOKALIKE_SCRIPT.test(label));
33
+ }
34
+ /**
35
+ * Checks one address (`local@domain`, nothing around it) and gives it in its forms, or the
36
+ * reason it is not one. Quoted local parts (`"ana lima"@example.com`) and IP literals
37
+ * (`ana@[192.0.2.1]`) are not accepted: mail systems and people rarely use them, and they
38
+ * are a common way to slip past checks.
39
+ */
40
+ function checkAddress(text, name) {
41
+ if (INVISIBLE.test(text)) return "invisible";
42
+ const normalized = text.normalize("NFKC");
43
+ const at = normalized.lastIndexOf("@");
44
+ if (at === -1) return "syntax";
45
+ const local = normalized.slice(0, at);
46
+ const domain = normalized.slice(at + 1);
47
+ if (!LOCAL.test(local) || domain === "") return "syntax";
48
+ if (local.length > 64) return "too-long";
49
+ const ascii = asciiDomain(domain);
50
+ if (ascii === null) return "domain";
51
+ const address = `${local}@${ascii}`;
52
+ if (address.length > 254) return "too-long";
53
+ const unicode = domain.normalize("NFC").toLowerCase().replace(/\u3002/g, ".");
54
+ return {
55
+ address,
56
+ display: `${local}@${unicode}`,
57
+ name,
58
+ lookalike: isLookalike(unicode)
59
+ };
60
+ }
61
+ //#endregion
62
+ //#region src/email/parse.ts
63
+ /** Longer text is cut here: no list of recipients is this long. */
64
+ const ADDRESS_LIST_MAX_LENGTH = 1e5;
65
+ const MAX_NAME_LENGTH = 256;
66
+ /** An entry longer than this is no address with its name: it is not read. */
67
+ const MAX_ENTRY_LENGTH = 1024;
68
+ /**
69
+ * Splits the text at commas, semicolons, line breaks and tabs, but not inside quotes,
70
+ * angle brackets or parentheses: `"Lima, Ana" <ana@example.com>` stays one entry.
71
+ */
72
+ function split(text) {
73
+ const segments = [];
74
+ let current = "";
75
+ let separator = "";
76
+ let quoted = false;
77
+ let angle = 0;
78
+ let paren = 0;
79
+ for (let index = 0; index < text.length; index += 1) {
80
+ const char = text.charAt(index);
81
+ if (quoted) {
82
+ current += char;
83
+ if (char === "\\" && index + 1 < text.length) {
84
+ index += 1;
85
+ current += text.charAt(index);
86
+ } else if (char === "\"") quoted = false;
87
+ continue;
88
+ }
89
+ if (char === "\"") quoted = true;
90
+ else if (char === "<") angle += 1;
91
+ else if (char === ">") angle = Math.max(0, angle - 1);
92
+ else if (char === "(") paren += 1;
93
+ else if (char === ")") paren = Math.max(0, paren - 1);
94
+ else if (angle === 0 && paren === 0 && /[,;\n\t]/.test(char)) {
95
+ segments.push({
96
+ text: current,
97
+ separator
98
+ });
99
+ current = "";
100
+ separator = char;
101
+ continue;
102
+ }
103
+ current += char;
104
+ }
105
+ segments.push({
106
+ text: current,
107
+ separator
108
+ });
109
+ return segments;
110
+ }
111
+ /** `text` with what is inside double quotes blanked out, at the same length. */
112
+ function unquoted(text) {
113
+ return text.replace(/"(?:\\.|[^"\\])*"?/g, (quoted) => "_".repeat(quoted.length));
114
+ }
115
+ /**
116
+ * Joins names to the address they belong to. Outlook writes `Lima, Ana <ana@example.com>`
117
+ * with an unquoted comma, so names before a comma join an entry in angle brackets. A
118
+ * spreadsheet row puts names in the cells around the address, so cells of one row (tabs)
119
+ * join it, before or after. A line break starts a new row. Names that join nothing are
120
+ * entries of their own, and not addresses.
121
+ */
122
+ function join(segments) {
123
+ const entries = [];
124
+ let names = [];
125
+ /** The last entry is an address on this row, which cells after it can name. */
126
+ let rowAddress = false;
127
+ const flush = () => {
128
+ entries.push(...names.map((name) => name.text));
129
+ names = [];
130
+ };
131
+ for (const segment of segments) {
132
+ const { separator } = segment;
133
+ if (separator === "\n") {
134
+ flush();
135
+ rowAddress = false;
136
+ }
137
+ const text = unquoted(segment.text);
138
+ if (text.trim() === "") flush();
139
+ else if (!text.includes("@")) {
140
+ if (rowAddress && separator === " ") entries.push(`${String(entries.pop())}\t${segment.text}`);
141
+ else {
142
+ rowAddress = false;
143
+ names.push(segment);
144
+ }
145
+ } else {
146
+ let from = names.length;
147
+ if (separator === " " || separator === "," && text.includes("<")) {
148
+ from = Math.max(0, from - 1);
149
+ while (from > 0 && names[from]?.separator === separator) from -= 1;
150
+ }
151
+ const own = names.slice(from);
152
+ names = names.slice(0, from);
153
+ flush();
154
+ entries.push([...own, segment].map((part, index) => index === 0 ? part.text : part.separator + part.text).join(""));
155
+ names = [];
156
+ rowAddress = true;
157
+ }
158
+ }
159
+ flush();
160
+ return entries.map((entry) => entry.trim()).filter((entry) => entry !== "");
161
+ }
162
+ /** A name as people wrote it: quotes taken off, no control characters, spaces collapsed. */
163
+ function cleanName(raw, address) {
164
+ let name = raw.trim();
165
+ if (/^"(?:\\.|[^"\\])*"$/.test(name)) name = name.slice(1, -1).replace(/\\(.)/g, "$1");
166
+ else if (/^'[^']*'$/.test(name)) name = name.slice(1, -1);
167
+ name = name.replace(/[\p{Cc}\p{Cf}\p{Zl}\p{Zp}]/gu, " ").replace(/\s+/g, " ").trim().slice(0, MAX_NAME_LENGTH).trim();
168
+ return name === "" || name.toLowerCase() === address.toLowerCase() ? null : name;
169
+ }
170
+ /** The address part of an entry, without `mailto:` or a query. */
171
+ function addressPart(text) {
172
+ const trimmed = text.trim();
173
+ return /^mailto:/i.test(trimmed) ? String(trimmed.slice(7).split("?")[0]) : trimmed;
174
+ }
175
+ /** One entry as an address and the name written with it, or `null` when it is shaped like neither. */
176
+ function readEntry(entry) {
177
+ const strip = unquoted(entry);
178
+ const open = strip.indexOf("<");
179
+ if (open !== -1) {
180
+ const close = strip.indexOf(">", open);
181
+ if (close === -1 || strip.indexOf("<", open + 1) !== -1 || strip.slice(close + 1).trim() !== "") return null;
182
+ return {
183
+ address: addressPart(entry.slice(open + 1, close)),
184
+ name: entry.slice(0, open)
185
+ };
186
+ }
187
+ const paren = strip.indexOf("(");
188
+ if (paren !== -1) {
189
+ const address = entry.slice(0, paren).trim();
190
+ const name = entry.slice(paren + 1, -1);
191
+ return strip.endsWith(")") && !/[\s()]/.test(address) && !/[()]/.test(name) ? {
192
+ address: addressPart(address),
193
+ name
194
+ } : null;
195
+ }
196
+ const words = entry.split(/\s+/);
197
+ const at = words.filter((word) => word.includes("@"));
198
+ if (at.length !== 1) return null;
199
+ const address = String(at[0]);
200
+ const index = words.indexOf(address);
201
+ if (index !== 0 && index !== words.length - 1) return null;
202
+ return {
203
+ address: addressPart(address),
204
+ name: words.filter((_, position) => position !== index).join(" ")
205
+ };
206
+ }
207
+ /** Whether `address` is at one of `domains` (ASCII forms) or a subdomain of one. */
208
+ function isAllowed(address, domains) {
209
+ const domain = address.slice(address.lastIndexOf("@") + 1);
210
+ return domains.some((one) => domain === one || domain.endsWith(`.${one}`));
211
+ }
212
+ /** `domain` in its ASCII form, for comparing; throws for one that is not a domain. */
213
+ function allowedDomain(domain) {
214
+ const checked = checkAddress(`x@${domain}`, null);
215
+ if (typeof checked === "string") throw require_errors.copyFailure("invalid-payload", `"${domain.slice(0, 80)}" is not a domain.`);
216
+ return checked.address.slice(2);
217
+ }
218
+ /**
219
+ * Reads the e-mail addresses in a pasted list of recipients, as Outlook, Gmail, Apple Mail,
220
+ * contact cards and spreadsheet columns copy them:
221
+ *
222
+ * - separated by commas, semicolons, line breaks or tabs;
223
+ * - `ana@example.com`, `Ana Lima <ana@example.com>`, `"Lima, Ana" <ana@example.com>`,
224
+ * Outlook's unquoted `Lima, Ana <ana@example.com>`, `ana@example.com (Ana Lima)`,
225
+ * `mailto:` links, and a name in the cell before the address;
226
+ * - international domains and local parts, and full-width characters.
227
+ *
228
+ * Each address is checked: its local part, a domain that can exist (`localhost`, `a.b-` and
229
+ * IP addresses can't), lengths, and characters that hide what an address really is. Domains
230
+ * that mix scripts are flagged as `lookalike`.
231
+ *
232
+ * @throws {CopyFailure} `invalid-payload` for a `maxAddresses` that is not a positive whole
233
+ * number, or a `domains` entry that is not a domain.
234
+ * @example
235
+ * parseAddresses('Lima, Ana <ana@example.com>; bo@example.org, not an address');
236
+ * // addresses: [{ address: 'ana@example.com', name: 'Lima, Ana', ... }, { address: 'bo@example.org', name: null, ... }]
237
+ * // invalid: [{ text: 'not an address', reason: 'syntax' }]
238
+ */
239
+ function parseAddresses(text, options = {}) {
240
+ const max = options.maxAddresses ?? 1e3;
241
+ if (!(Number.isInteger(max) && max > 0)) throw require_errors.copyFailure("invalid-payload", `maxAddresses must be a positive whole number, not ${String(max)}.`);
242
+ const allowed = options.domains?.map(allowedDomain);
243
+ const entries = join(split(text.slice(0, ADDRESS_LIST_MAX_LENGTH).replace(/^\uFEFF/, "").replace(/\r\n?/g, "\n").normalize("NFKC")));
244
+ const truncated = text.length > 1e5 || entries.length > max;
245
+ const addresses = [];
246
+ const invalid = [];
247
+ const seen = /* @__PURE__ */ new Map();
248
+ let duplicates = 0;
249
+ for (const entry of entries.slice(0, max)) {
250
+ const read = entry.length > MAX_ENTRY_LENGTH ? null : readEntry(entry);
251
+ const checked = entry.length > MAX_ENTRY_LENGTH ? "too-long" : read === null ? "syntax" : checkAddress(read.address, cleanName(read.name, read.address));
252
+ const reason = typeof checked === "string" ? checked : allowed !== void 0 && !isAllowed(checked.address, allowed) ? "not-allowed" : null;
253
+ if (typeof checked === "string" || reason !== null) {
254
+ invalid.push({
255
+ text: entry.slice(0, MAX_NAME_LENGTH),
256
+ reason
257
+ });
258
+ continue;
259
+ }
260
+ const address = checked;
261
+ const key = address.address.toLowerCase();
262
+ const earlier = options.dedupe === false ? void 0 : seen.get(key);
263
+ if (earlier === void 0) {
264
+ seen.set(key, addresses.length);
265
+ addresses.push(address);
266
+ continue;
267
+ }
268
+ duplicates += 1;
269
+ const first = addresses[earlier];
270
+ if (first.name === null && address.name !== null) addresses[earlier] = {
271
+ ...first,
272
+ name: address.name
273
+ };
274
+ }
275
+ return {
276
+ addresses,
277
+ invalid,
278
+ duplicates,
279
+ truncated
280
+ };
281
+ }
282
+ /**
283
+ * Reads one e-mail address, with or without a name (`Ana Lima <ana@example.com>`), for a
284
+ * single-address field. `null` when the text is not exactly one valid address.
285
+ */
286
+ function parseAddress(text) {
287
+ const list = parseAddresses(text, { maxAddresses: 2 });
288
+ return list.addresses.length === 1 && list.invalid.length === 0 && list.duplicates === 0 ? list.addresses[0] : null;
289
+ }
290
+ //#endregion
291
+ //#region src/email/format.ts
292
+ /** Characters that make a name need quotes (RFC 5322 specials). */
293
+ const SPECIALS = /[()<>[\]:;@\\,."]/;
294
+ /**
295
+ * One address as mail programs write it: `Ana Lima <ana@example.com>`, with the name in
296
+ * quotes when it needs them (`"Lima, Ana" <ana@example.com>`), or the bare address. Line
297
+ * breaks and other control characters in the name become spaces, so a name can never end a
298
+ * mail header it is written into.
299
+ *
300
+ * @throws {CopyFailure} `invalid-payload` when `address` is not a valid e-mail address.
301
+ */
302
+ function formatAddress(address) {
303
+ if (typeof checkAddress(address.address, null) === "string") throw require_errors.copyFailure("invalid-payload", `"${address.address.slice(0, 80)}" is not an e-mail address.`);
304
+ const name = (address.name ?? "").replace(/[\p{Cc}\p{Cf}\p{Zl}\p{Zp}]/gu, " ").replace(/\s+/g, " ").trim();
305
+ if (name === "") return address.address;
306
+ return SPECIALS.test(name) ? `"${name.replace(/["\\]/g, "\\$&")}" <${address.address}>` : `${name} <${address.address}>`;
307
+ }
308
+ /**
309
+ * A copy payload for a list of recipients that pastes into the To field of any mail program,
310
+ * names and all. Pass it to `copy()` or `useCopy`.
311
+ *
312
+ * @throws {CopyFailure} `invalid-payload` when one of the addresses is not valid.
313
+ * @example
314
+ * copy(addressesPayload(team.map((person) => ({ address: person.email, name: person.name }))));
315
+ */
316
+ function addressesPayload(addresses, options = {}) {
317
+ return {
318
+ kind: "text",
319
+ value: addresses.map(formatAddress).join(options.separator ?? ", ")
320
+ };
321
+ }
322
+ //#endregion
323
+ //#region src/email/paste.ts
324
+ /**
325
+ * A paste handler for recipient fields: To and Cc boxes, invite and share dialogs. A list
326
+ * copied from Outlook, Gmail or a spreadsheet becomes addresses for your chips; what was not
327
+ * an address stays in the field to be corrected. Typing and pasting a name are left alone.
328
+ *
329
+ * @example
330
+ * <input
331
+ * type="email"
332
+ * multiple
333
+ * onPaste={(event) => pasteAddresses(event, { onAddresses: ({ addresses }) => addRecipients(addresses) })}
334
+ * />
335
+ */
336
+ function pasteAddresses(event, options) {
337
+ if (event.defaultPrevented || event.clipboardData === null) return "ignored";
338
+ const text = event.clipboardData.getData("text/plain");
339
+ if (!/[@\uFF20]/.test(text)) return "ignored";
340
+ event.preventDefault();
341
+ const list = parseAddresses(text, options);
342
+ options.onAddresses(list);
343
+ if (options.keepInvalid !== false && list.invalid.length > 0) {
344
+ const field = require_text_field.asTextField(event.currentTarget) ?? require_text_field.asTextField(event.target);
345
+ if (field !== null) require_text_field.insertText(field, list.invalid.map((entry) => entry.text).join(", "));
346
+ }
347
+ return "parsed";
348
+ }
349
+ //#endregion
350
+ exports.ADDRESS_LIST_MAX_LENGTH = ADDRESS_LIST_MAX_LENGTH;
351
+ exports.addressesPayload = addressesPayload;
352
+ exports.formatAddress = formatAddress;
353
+ exports.parseAddress = parseAddress;
354
+ exports.parseAddresses = parseAddresses;
355
+ exports.pasteAddresses = pasteAddresses;
356
+
357
+ //# sourceMappingURL=email.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"email.cjs","names":["copyFailure","copyFailure","asTextField"],"sources":["../src/email/address.ts","../src/email/parse.ts","../src/email/format.ts","../src/email/paste.ts"],"sourcesContent":["/** An e-mail address read from text. */\nexport interface EmailAddress {\n /**\n * The address to send to: the local part as written, the domain in lower case and, for an\n * international domain, in its ASCII form (`ana@xn--bcher-kva.de`). Compare and store this.\n */\n readonly address: string;\n /** The same address with the domain as people read it (`ana@b\\u00FCcher.de`). Show this. */\n readonly display: string;\n /** The name written with it (`Ana Lima` in `Ana Lima <ana@example.com>`), or `null`. */\n readonly name: string | null;\n /**\n * The domain mixes Latin letters with Cyrillic or Greek ones that look like them, as in\n * `ex\\u0430mple.com` with a Cyrillic `\\u0430`: a lookalike of another domain. Warn before sending.\n */\n readonly lookalike: boolean;\n}\n\n/** Why text was not an e-mail address. */\nexport type InvalidAddressReason =\n /** Not shaped like an address: no `@`, two of them, spaces, or characters an address can't have. */\n | 'syntax'\n /** The part after `@` is not a domain names can be registered under. */\n | 'domain'\n /** Longer than an address can be: 64 characters before `@`, 254 in all. */\n | 'too-long'\n /** Holds invisible or direction-changing characters: often a way to disguise an address. */\n | 'invisible'\n /** A valid address, at a domain `domains` does not allow. */\n | 'not-allowed';\n\n/** Invisible and direction-changing characters, soft hyphens and variation selectors. */\nexport const INVISIBLE: RegExp = /[\\u00AD\\u061C\\u115F\\u1160\\u180E\\u200B-\\u200F\\u202A-\\u202E\\u2060-\\u206F\\u3164\\uFEFF\\uFFA0]|\\u034F|\\u17B4|\\u17B5|\\p{Variation_Selector}/u;\n\n/** A dot-atom local part (RFC 5322), with letters of any script (RFC 6531). */\nconst LOCAL = /^[\\p{L}\\p{M}\\p{N}!#$%&'*+/=?^_`{|}~-]+(?:\\.[\\p{L}\\p{M}\\p{N}!#$%&'*+/=?^_`{|}~-]+)*$/u;\n/** Characters that change how a URL host is read: not part of any domain. */\nconst NOT_DOMAIN = /[\\s/?#@:[\\]\\\\%<>\"'(),;]/u;\nconst LABEL = /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/;\n/** A top-level domain: letters, or an international one in its ASCII form. */\nconst TLD = /^(?:[a-z]{2,63}|xn--[a-z0-9-]{1,59})$/;\nconst LATIN = /\\p{Script=Latin}/u;\nconst LOOKALIKE_SCRIPT = /[\\p{Script=Cyrillic}\\p{Script=Greek}]/u;\n\n/** The domain in its ASCII form, lower case, or `null` when it is not one. */\nfunction asciiDomain(domain: string): string | null {\n if (NOT_DOMAIN.test(domain)) return null;\n let host: string;\n try {\n // The URL parser applies IDNA (UTS #46): case, full-width forms and international labels.\n host = new URL(`http://${domain}`).hostname;\n } catch {\n return null;\n }\n const labels = host.split('.');\n if (host.length > 253 || labels.length < 2 || !labels.every((label) => LABEL.test(label))) return null;\n return TLD.test(String(labels[labels.length - 1])) ? host : null;\n}\n\n/** Whether a label of `domain` mixes Latin letters with lookalike Cyrillic or Greek ones. */\nfunction isLookalike(domain: string): boolean {\n return domain.split('.').some((label) => LATIN.test(label) && LOOKALIKE_SCRIPT.test(label));\n}\n\n/**\n * Checks one address (`local@domain`, nothing around it) and gives it in its forms, or the\n * reason it is not one. Quoted local parts (`\"ana lima\"@example.com`) and IP literals\n * (`ana@[192.0.2.1]`) are not accepted: mail systems and people rarely use them, and they\n * are a common way to slip past checks.\n */\nexport function checkAddress(text: string, name: string | null): EmailAddress | InvalidAddressReason {\n if (INVISIBLE.test(text)) return 'invisible';\n // Full-width `\\uFF20` and letters, as some keyboards type them.\n const normalized = text.normalize('NFKC');\n const at = normalized.lastIndexOf('@');\n if (at === -1) return 'syntax';\n const local = normalized.slice(0, at);\n const domain = normalized.slice(at + 1);\n if (!LOCAL.test(local) || domain === '') return 'syntax';\n if (local.length > 64) return 'too-long';\n const ascii = asciiDomain(domain);\n if (ascii === null) return 'domain';\n const address = `${local}@${ascii}`;\n if (address.length > 254) return 'too-long';\n // As people read it: ideographic full stops (`\\u3002`) are dots, as IDNA reads them.\n const unicode = domain.normalize('NFC').toLowerCase().replace(/\\u3002/g, '.');\n return { address, display: `${local}@${unicode}`, name, lookalike: isLookalike(unicode) };\n}\n","import { copyFailure } from '../core/errors';\nimport { checkAddress, type EmailAddress, type InvalidAddressReason } from './address';\n\n/** Text that was not an address, and why. */\nexport interface InvalidAddress {\n /** The text, as it was pasted (at most 256 characters of it). */\n readonly text: string;\n readonly reason: InvalidAddressReason;\n}\n\n/** The addresses in a pasted list of recipients. */\nexport interface AddressList {\n /** The valid addresses, in order, each once. */\n readonly addresses: readonly EmailAddress[];\n /** The entries that were not addresses, in order. */\n readonly invalid: readonly InvalidAddress[];\n /** How many addresses were left out because they came earlier in the list. */\n readonly duplicates: number;\n /** The text held more than `maxAddresses` entries, or more than {@link ADDRESS_LIST_MAX_LENGTH} characters: the rest was not read. */\n readonly truncated: boolean;\n}\n\nexport interface ParseAddressesOptions {\n /** Read at most this many entries (valid or not). Default 1000. */\n readonly maxAddresses?: number;\n /** Leave out addresses that came earlier in the list (compared without case). Default `true`. */\n readonly dedupe?: boolean;\n /**\n * Accept only addresses at these domains or their subdomains (`['example.com']` takes\n * `ana@example.com` and `ana@mail.example.com`). Others are `invalid` with `'not-allowed'`.\n */\n readonly domains?: readonly string[];\n}\n\n/** Longer text is cut here: no list of recipients is this long. */\nexport const ADDRESS_LIST_MAX_LENGTH = 100_000;\nconst MAX_NAME_LENGTH = 256;\n/** An entry longer than this is no address with its name: it is not read. */\nconst MAX_ENTRY_LENGTH = 1024;\n\ninterface Segment {\n text: string;\n /** The separator before it: `''` for the first. */\n readonly separator: string;\n}\n\n/**\n * Splits the text at commas, semicolons, line breaks and tabs, but not inside quotes,\n * angle brackets or parentheses: `\"Lima, Ana\" <ana@example.com>` stays one entry.\n */\nfunction split(text: string): Segment[] {\n const segments: Segment[] = [];\n let current = '';\n let separator = '';\n let quoted = false;\n let angle = 0;\n let paren = 0;\n for (let index = 0; index < text.length; index += 1) {\n const char = text.charAt(index);\n if (quoted) {\n current += char;\n if (char === '\\\\' && index + 1 < text.length) {\n index += 1;\n current += text.charAt(index);\n } else if (char === '\"') quoted = false;\n continue;\n }\n if (char === '\"') quoted = true;\n else if (char === '<') angle += 1;\n else if (char === '>') angle = Math.max(0, angle - 1);\n else if (char === '(') paren += 1;\n else if (char === ')') paren = Math.max(0, paren - 1);\n else if (angle === 0 && paren === 0 && /[,;\\n\\t]/.test(char)) {\n segments.push({ text: current, separator });\n current = '';\n separator = char;\n continue;\n }\n current += char;\n }\n segments.push({ text: current, separator });\n return segments;\n}\n\n/** `text` with what is inside double quotes blanked out, at the same length. */\nfunction unquoted(text: string): string {\n return text.replace(/\"(?:\\\\.|[^\"\\\\])*\"?/g, (quoted) => '_'.repeat(quoted.length));\n}\n\n/**\n * Joins names to the address they belong to. Outlook writes `Lima, Ana <ana@example.com>`\n * with an unquoted comma, so names before a comma join an entry in angle brackets. A\n * spreadsheet row puts names in the cells around the address, so cells of one row (tabs)\n * join it, before or after. A line break starts a new row. Names that join nothing are\n * entries of their own, and not addresses.\n */\nfunction join(segments: readonly Segment[]): string[] {\n const entries: string[] = [];\n let names: Segment[] = [];\n /** The last entry is an address on this row, which cells after it can name. */\n let rowAddress = false;\n const flush = (): void => {\n entries.push(...names.map((name) => name.text));\n names = [];\n };\n for (const segment of segments) {\n const { separator } = segment;\n if (separator === '\\n') {\n flush();\n rowAddress = false;\n }\n const text = unquoted(segment.text);\n if (text.trim() === '') {\n // An empty cell or a doubled separator ends a name.\n flush();\n } else if (!text.includes('@')) {\n if (rowAddress && separator === '\\t') entries.push(`${String(entries.pop())}\\t${segment.text}`);\n else {\n rowAddress = false;\n names.push(segment);\n }\n } else {\n // The names right before the address, joined to it by its own separator, belong to it.\n let from = names.length;\n if (separator === '\\t' || (separator === ',' && text.includes('<'))) {\n from = Math.max(0, from - 1);\n while (from > 0 && names[from]?.separator === separator) from -= 1;\n }\n const own = names.slice(from);\n names = names.slice(0, from);\n flush();\n entries.push([...own, segment].map((part, index) => (index === 0 ? part.text : part.separator + part.text)).join(''));\n names = [];\n rowAddress = true;\n }\n }\n flush();\n return entries.map((entry) => entry.trim()).filter((entry) => entry !== '');\n}\n\n/** A name as people wrote it: quotes taken off, no control characters, spaces collapsed. */\nfunction cleanName(raw: string, address: string): string | null {\n let name = raw.trim();\n if (/^\"(?:\\\\.|[^\"\\\\])*\"$/.test(name)) name = name.slice(1, -1).replace(/\\\\(.)/g, '$1');\n else if (/^'[^']*'$/.test(name)) name = name.slice(1, -1);\n // Control and format characters (line breaks among them) never belong in a name: they could\n // end a mail header the name is written into.\n name = name.replace(/[\\p{Cc}\\p{Cf}\\p{Zl}\\p{Zp}]/gu, ' ').replace(/\\s+/g, ' ').trim().slice(0, MAX_NAME_LENGTH).trim();\n return name === '' || name.toLowerCase() === address.toLowerCase() ? null : name;\n}\n\n/** The address part of an entry, without `mailto:` or a query. */\nfunction addressPart(text: string): string {\n const trimmed = text.trim();\n return /^mailto:/i.test(trimmed) ? String(trimmed.slice(7).split('?')[0]) : trimmed;\n}\n\n/** One entry as an address and the name written with it, or `null` when it is shaped like neither. */\nfunction readEntry(entry: string): { readonly address: string; readonly name: string } | null {\n const strip = unquoted(entry);\n const open = strip.indexOf('<');\n if (open !== -1) {\n // `Name <address>`: one pair of angle brackets, last.\n const close = strip.indexOf('>', open);\n if (close === -1 || strip.indexOf('<', open + 1) !== -1 || strip.slice(close + 1).trim() !== '') return null;\n return { address: addressPart(entry.slice(open + 1, close)), name: entry.slice(0, open) };\n }\n // `address (Name)`, an old form some systems still write.\n const paren = strip.indexOf('(');\n if (paren !== -1) {\n const address = entry.slice(0, paren).trim();\n const name = entry.slice(paren + 1, -1);\n return strip.endsWith(')') && !/[\\s()]/.test(address) && !/[()]/.test(name) ? { address: addressPart(address), name } : null;\n }\n // `Name address` or `address Name`, as contact cards and spreadsheet rows have them.\n const words = entry.split(/\\s+/);\n const at = words.filter((word) => word.includes('@'));\n if (at.length !== 1) return null;\n const address = String(at[0]);\n const index = words.indexOf(address);\n if (index !== 0 && index !== words.length - 1) return null;\n return { address: addressPart(address), name: words.filter((_, position) => position !== index).join(' ') };\n}\n\n/** Whether `address` is at one of `domains` (ASCII forms) or a subdomain of one. */\nfunction isAllowed(address: string, domains: readonly string[]): boolean {\n const domain = address.slice(address.lastIndexOf('@') + 1);\n return domains.some((one) => domain === one || domain.endsWith(`.${one}`));\n}\n\n/** `domain` in its ASCII form, for comparing; throws for one that is not a domain. */\nfunction allowedDomain(domain: string): string {\n const checked = checkAddress(`x@${domain}`, null);\n if (typeof checked === 'string') throw copyFailure('invalid-payload', `\"${domain.slice(0, 80)}\" is not a domain.`);\n return checked.address.slice(2);\n}\n\n/**\n * Reads the e-mail addresses in a pasted list of recipients, as Outlook, Gmail, Apple Mail,\n * contact cards and spreadsheet columns copy them:\n *\n * - separated by commas, semicolons, line breaks or tabs;\n * - `ana@example.com`, `Ana Lima <ana@example.com>`, `\"Lima, Ana\" <ana@example.com>`,\n * Outlook's unquoted `Lima, Ana <ana@example.com>`, `ana@example.com (Ana Lima)`,\n * `mailto:` links, and a name in the cell before the address;\n * - international domains and local parts, and full-width characters.\n *\n * Each address is checked: its local part, a domain that can exist (`localhost`, `a.b-` and\n * IP addresses can't), lengths, and characters that hide what an address really is. Domains\n * that mix scripts are flagged as `lookalike`.\n *\n * @throws {CopyFailure} `invalid-payload` for a `maxAddresses` that is not a positive whole\n * number, or a `domains` entry that is not a domain.\n * @example\n * parseAddresses('Lima, Ana <ana@example.com>; bo@example.org, not an address');\n * // addresses: [{ address: 'ana@example.com', name: 'Lima, Ana', ... }, { address: 'bo@example.org', name: null, ... }]\n * // invalid: [{ text: 'not an address', reason: 'syntax' }]\n */\nexport function parseAddresses(text: string, options: ParseAddressesOptions = {}): AddressList {\n const max = options.maxAddresses ?? 1000;\n if (!(Number.isInteger(max) && max > 0)) throw copyFailure('invalid-payload', `maxAddresses must be a positive whole number, not ${String(max)}.`);\n const allowed = options.domains?.map(allowedDomain);\n // A byte order mark at the start, as some programs copy it, is not part of the first entry.\n const input = text.slice(0, ADDRESS_LIST_MAX_LENGTH).replace(/^\\uFEFF/, '').replace(/\\r\\n?/g, '\\n').normalize('NFKC');\n const entries = join(split(input));\n const truncated = text.length > ADDRESS_LIST_MAX_LENGTH || entries.length > max;\n const addresses: EmailAddress[] = [];\n const invalid: InvalidAddress[] = [];\n const seen = new Map<string, number>();\n let duplicates = 0;\n for (const entry of entries.slice(0, max)) {\n const read = entry.length > MAX_ENTRY_LENGTH ? null : readEntry(entry);\n const checked = entry.length > MAX_ENTRY_LENGTH ? 'too-long' : read === null ? 'syntax' : checkAddress(read.address, cleanName(read.name, read.address));\n const reason = typeof checked === 'string' ? checked : allowed !== undefined && !isAllowed(checked.address, allowed) ? 'not-allowed' : null;\n if (typeof checked === 'string' || reason !== null) {\n invalid.push({ text: entry.slice(0, MAX_NAME_LENGTH), reason: reason as InvalidAddressReason });\n continue;\n }\n const address = checked;\n const key = address.address.toLowerCase();\n const earlier = options.dedupe === false ? undefined : seen.get(key);\n if (earlier === undefined) {\n seen.set(key, addresses.length);\n addresses.push(address);\n continue;\n }\n duplicates += 1;\n // The first mention wins, but a name given later fills one it lacked.\n const first = addresses[earlier] as EmailAddress;\n if (first.name === null && address.name !== null) addresses[earlier] = { ...first, name: address.name };\n }\n return { addresses, invalid, duplicates, truncated };\n}\n\n/**\n * Reads one e-mail address, with or without a name (`Ana Lima <ana@example.com>`), for a\n * single-address field. `null` when the text is not exactly one valid address.\n */\nexport function parseAddress(text: string): EmailAddress | null {\n const list = parseAddresses(text, { maxAddresses: 2 });\n return list.addresses.length === 1 && list.invalid.length === 0 && list.duplicates === 0 ? (list.addresses[0] as EmailAddress) : null;\n}\n","import { copyFailure } from '../core/errors';\nimport type { TextPayload } from '../core/payload';\nimport { checkAddress } from './address';\n\n/** An address to write: an `EmailAddress`, or any object with these fields. */\nexport interface AddressToWrite {\n readonly address: string;\n readonly name?: string | null;\n}\n\n/** Characters that make a name need quotes (RFC 5322 specials). */\nconst SPECIALS = /[()<>[\\]:;@\\\\,.\"]/;\n\n/**\n * One address as mail programs write it: `Ana Lima <ana@example.com>`, with the name in\n * quotes when it needs them (`\"Lima, Ana\" <ana@example.com>`), or the bare address. Line\n * breaks and other control characters in the name become spaces, so a name can never end a\n * mail header it is written into.\n *\n * @throws {CopyFailure} `invalid-payload` when `address` is not a valid e-mail address.\n */\nexport function formatAddress(address: AddressToWrite): string {\n if (typeof checkAddress(address.address, null) === 'string') {\n throw copyFailure('invalid-payload', `\"${address.address.slice(0, 80)}\" is not an e-mail address.`);\n }\n const name = (address.name ?? '').replace(/[\\p{Cc}\\p{Cf}\\p{Zl}\\p{Zp}]/gu, ' ').replace(/\\s+/g, ' ').trim();\n if (name === '') return address.address;\n return SPECIALS.test(name) ? `\"${name.replace(/[\"\\\\]/g, '\\\\$&')}\" <${address.address}>` : `${name} <${address.address}>`;\n}\n\nexport interface AddressesPayloadOptions {\n /** Between addresses. Default `', '`, which Gmail, Outlook and Apple Mail all read. */\n readonly separator?: ', ' | '; ' | '\\n';\n}\n\n/**\n * A copy payload for a list of recipients that pastes into the To field of any mail program,\n * names and all. Pass it to `copy()` or `useCopy`.\n *\n * @throws {CopyFailure} `invalid-payload` when one of the addresses is not valid.\n * @example\n * copy(addressesPayload(team.map((person) => ({ address: person.email, name: person.name }))));\n */\nexport function addressesPayload(addresses: readonly AddressToWrite[], options: AddressesPayloadOptions = {}): TextPayload {\n return { kind: 'text', value: addresses.map(formatAddress).join(options.separator ?? ', ') };\n}\n","import { asTextField, insertText } from '../core/text-field';\nimport { parseAddresses, type AddressList, type ParseAddressesOptions } from './parse';\n\n/** What {@link pasteAddresses} did. */\nexport type AddressPasteOutcome =\n /** The paste held addresses (or tried to): `onAddresses` was called with them. */\n | 'parsed'\n /** No `@` in the paste (a name being searched for, say), or no text: left to the browser. */\n | 'ignored';\n\nexport interface PasteAddressesOptions extends ParseAddressesOptions {\n /** Called with what the paste held: add `addresses` as recipients, show `invalid`. */\n readonly onAddresses: (list: AddressList) => void;\n /**\n * Put the entries that were not addresses into the field, so people can correct them.\n * Default `true`. Works on `<textarea>`s and text `<input>`s, with undo intact.\n */\n readonly keepInvalid?: boolean;\n}\n\n/** Structural paste event: a DOM `ClipboardEvent` and React's `onPaste` event both fit. */\nexport interface AddressPasteEvent {\n readonly clipboardData: { getData(format: string): string } | null;\n readonly currentTarget: EventTarget | null;\n readonly target: EventTarget | null;\n readonly defaultPrevented: boolean;\n preventDefault(): void;\n}\n\n/**\n * A paste handler for recipient fields: To and Cc boxes, invite and share dialogs. A list\n * copied from Outlook, Gmail or a spreadsheet becomes addresses for your chips; what was not\n * an address stays in the field to be corrected. Typing and pasting a name are left alone.\n *\n * @example\n * <input\n * type=\"email\"\n * multiple\n * onPaste={(event) => pasteAddresses(event, { onAddresses: ({ addresses }) => addRecipients(addresses) })}\n * />\n */\nexport function pasteAddresses(event: AddressPasteEvent, options: PasteAddressesOptions): AddressPasteOutcome {\n if (event.defaultPrevented || event.clipboardData === null) return 'ignored';\n const text = event.clipboardData.getData('text/plain');\n if (!/[@\\uFF20]/.test(text)) return 'ignored';\n event.preventDefault();\n const list = parseAddresses(text, options);\n options.onAddresses(list);\n if (options.keepInvalid !== false && list.invalid.length > 0) {\n const field = asTextField(event.currentTarget) ?? asTextField(event.target);\n if (field !== null) insertText(field, list.invalid.map((entry) => entry.text).join(', '));\n }\n return 'parsed';\n}\n"],"mappings":";;;;;;AAgCA,MAAa,YAAoB;;AAGjC,MAAM,QAAQ;;AAEd,MAAM,aAAa;AACnB,MAAM,QAAQ;;AAEd,MAAM,MAAM;AACZ,MAAM,QAAQ;AACd,MAAM,mB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,EAAE,4BAA4B;CAEpG,MAAM,QAAQ,QAAQ,QAAQ,GAAA,CAAI,QAAQ,gCAAgC,GAAG,CAAC,CAAC,QAAQ,QAAQ,GAAG,CAAC,CAAC,KAAK;CACzG,IAAI,SAAS,IAAI,OAAO,QAAQ;CAChC,OAAO,SAAS,KAAK,IAAI,IAAI,IAAI,KAAK,QAAQ,UAAU,MAAM,EAAE,KAAK,QAAQ,QAAQ,KAAK,GAAG,KAAK,IAAI,QAAQ,QAAQ;AACxH;;;;;;;;;AAeA,SAAgB,iBAAiB,WAAsC,UAAmC,CAAC,GAAgB;CACzH,OAAO;EAAE,MAAM;EAAQ,OAAO,UAAU,IAAI,aAAa,CAAC,CAAC,KAAK,QAAQ,aAAa,IAAI;CAAE;AAC7F;;;;;;;;;;;;;;;ACJA,SAAgB,eAAe,OAA0B,SAAqD;CAC5G,IAAI,MAAM,oBAAoB,MAAM,kBAAkB,MAAM,OAAO;CACnE,MAAM,OAAO,MAAM,cAAc,QAAQ,YAAY;CACrD,IAAI,CAAC,YAAY,KAAK,IAAI,GAAG,OAAO;CACpC,MAAM,eAAe;CACrB,MAAM,OAAO,eAAe,MAAM,OAAO;CACzC,QAAQ,YAAY,IAAI;CACxB,IAAI,QAAQ,gBAAgB,SAAS,KAAK,QAAQ,SAAS,GAAG;EAC5D,MAAM,QAAQC,mBAAAA,YAAY,MAAM,aAAa,KAAKA,mBAAAA,YAAY,MAAM,MAAM;EAC1E,IAAI,UAAU,MAAM,mBAAA,WAAW,OAAO,KAAK,QAAQ,KAAK,UAAU,MAAM,IAAI,CAAC,CAAC,KAAK,IAAI,CAAC;CAC1F;CACA,OAAO;AACT"}
@@ -0,0 +1,163 @@
1
+
2
+ import { f as TextPayload } from "./chunks/payload-qkAWVXWA.cjs";
3
+ //#region src/email/address.d.ts
4
+ /** An e-mail address read from text. */
5
+ interface EmailAddress {
6
+ /**
7
+ * The address to send to: the local part as written, the domain in lower case and, for an
8
+ * international domain, in its ASCII form (`ana@xn--bcher-kva.de`). Compare and store this.
9
+ */
10
+ readonly address: string;
11
+ /** The same address with the domain as people read it (`ana@b\u00FCcher.de`). Show this. */
12
+ readonly display: string;
13
+ /** The name written with it (`Ana Lima` in `Ana Lima <ana@example.com>`), or `null`. */
14
+ readonly name: string | null;
15
+ /**
16
+ * The domain mixes Latin letters with Cyrillic or Greek ones that look like them, as in
17
+ * `ex\u0430mple.com` with a Cyrillic `\u0430`: a lookalike of another domain. Warn before sending.
18
+ */
19
+ readonly lookalike: boolean;
20
+ }
21
+ /** Why text was not an e-mail address. */
22
+ type InvalidAddressReason =
23
+ /** Not shaped like an address: no `@`, two of them, spaces, or characters an address can't have. */
24
+ 'syntax' |
25
+ /** The part after `@` is not a domain names can be registered under. */
26
+ 'domain' |
27
+ /** Longer than an address can be: 64 characters before `@`, 254 in all. */
28
+ 'too-long' |
29
+ /** Holds invisible or direction-changing characters: often a way to disguise an address. */
30
+ 'invisible' |
31
+ /** A valid address, at a domain `domains` does not allow. */
32
+ 'not-allowed';
33
+ //#endregion
34
+ //#region src/email/parse.d.ts
35
+ /** Text that was not an address, and why. */
36
+ interface InvalidAddress {
37
+ /** The text, as it was pasted (at most 256 characters of it). */
38
+ readonly text: string;
39
+ readonly reason: InvalidAddressReason;
40
+ }
41
+ /** The addresses in a pasted list of recipients. */
42
+ interface AddressList {
43
+ /** The valid addresses, in order, each once. */
44
+ readonly addresses: readonly EmailAddress[];
45
+ /** The entries that were not addresses, in order. */
46
+ readonly invalid: readonly InvalidAddress[];
47
+ /** How many addresses were left out because they came earlier in the list. */
48
+ readonly duplicates: number;
49
+ /** The text held more than `maxAddresses` entries, or more than {@link ADDRESS_LIST_MAX_LENGTH} characters: the rest was not read. */
50
+ readonly truncated: boolean;
51
+ }
52
+ interface ParseAddressesOptions {
53
+ /** Read at most this many entries (valid or not). Default 1000. */
54
+ readonly maxAddresses?: number;
55
+ /** Leave out addresses that came earlier in the list (compared without case). Default `true`. */
56
+ readonly dedupe?: boolean;
57
+ /**
58
+ * Accept only addresses at these domains or their subdomains (`['example.com']` takes
59
+ * `ana@example.com` and `ana@mail.example.com`). Others are `invalid` with `'not-allowed'`.
60
+ */
61
+ readonly domains?: readonly string[];
62
+ }
63
+ /** Longer text is cut here: no list of recipients is this long. */
64
+ export declare const ADDRESS_LIST_MAX_LENGTH = 100000;
65
+ /**
66
+ * Reads the e-mail addresses in a pasted list of recipients, as Outlook, Gmail, Apple Mail,
67
+ * contact cards and spreadsheet columns copy them:
68
+ *
69
+ * - separated by commas, semicolons, line breaks or tabs;
70
+ * - `ana@example.com`, `Ana Lima <ana@example.com>`, `"Lima, Ana" <ana@example.com>`,
71
+ * Outlook's unquoted `Lima, Ana <ana@example.com>`, `ana@example.com (Ana Lima)`,
72
+ * `mailto:` links, and a name in the cell before the address;
73
+ * - international domains and local parts, and full-width characters.
74
+ *
75
+ * Each address is checked: its local part, a domain that can exist (`localhost`, `a.b-` and
76
+ * IP addresses can't), lengths, and characters that hide what an address really is. Domains
77
+ * that mix scripts are flagged as `lookalike`.
78
+ *
79
+ * @throws {CopyFailure} `invalid-payload` for a `maxAddresses` that is not a positive whole
80
+ * number, or a `domains` entry that is not a domain.
81
+ * @example
82
+ * parseAddresses('Lima, Ana <ana@example.com>; bo@example.org, not an address');
83
+ * // addresses: [{ address: 'ana@example.com', name: 'Lima, Ana', ... }, { address: 'bo@example.org', name: null, ... }]
84
+ * // invalid: [{ text: 'not an address', reason: 'syntax' }]
85
+ */
86
+ export declare function parseAddresses(text: string, options?: ParseAddressesOptions): AddressList;
87
+ /**
88
+ * Reads one e-mail address, with or without a name (`Ana Lima <ana@example.com>`), for a
89
+ * single-address field. `null` when the text is not exactly one valid address.
90
+ */
91
+ export declare function parseAddress(text: string): EmailAddress | null;
92
+ //#endregion
93
+ //#region src/email/format.d.ts
94
+ /** An address to write: an `EmailAddress`, or any object with these fields. */
95
+ interface AddressToWrite {
96
+ readonly address: string;
97
+ readonly name?: string | null;
98
+ }
99
+ /**
100
+ * One address as mail programs write it: `Ana Lima <ana@example.com>`, with the name in
101
+ * quotes when it needs them (`"Lima, Ana" <ana@example.com>`), or the bare address. Line
102
+ * breaks and other control characters in the name become spaces, so a name can never end a
103
+ * mail header it is written into.
104
+ *
105
+ * @throws {CopyFailure} `invalid-payload` when `address` is not a valid e-mail address.
106
+ */
107
+ export declare function formatAddress(address: AddressToWrite): string;
108
+ interface AddressesPayloadOptions {
109
+ /** Between addresses. Default `', '`, which Gmail, Outlook and Apple Mail all read. */
110
+ readonly separator?: ', ' | '; ' | '\n';
111
+ }
112
+ /**
113
+ * A copy payload for a list of recipients that pastes into the To field of any mail program,
114
+ * names and all. Pass it to `copy()` or `useCopy`.
115
+ *
116
+ * @throws {CopyFailure} `invalid-payload` when one of the addresses is not valid.
117
+ * @example
118
+ * copy(addressesPayload(team.map((person) => ({ address: person.email, name: person.name }))));
119
+ */
120
+ export declare function addressesPayload(addresses: readonly AddressToWrite[], options?: AddressesPayloadOptions): TextPayload;
121
+ //#endregion
122
+ //#region src/email/paste.d.ts
123
+ /** What {@link pasteAddresses} did. */
124
+ type AddressPasteOutcome =
125
+ /** The paste held addresses (or tried to): `onAddresses` was called with them. */
126
+ 'parsed' |
127
+ /** No `@` in the paste (a name being searched for, say), or no text: left to the browser. */
128
+ 'ignored';
129
+ interface PasteAddressesOptions extends ParseAddressesOptions {
130
+ /** Called with what the paste held: add `addresses` as recipients, show `invalid`. */
131
+ readonly onAddresses: (list: AddressList) => void;
132
+ /**
133
+ * Put the entries that were not addresses into the field, so people can correct them.
134
+ * Default `true`. Works on `<textarea>`s and text `<input>`s, with undo intact.
135
+ */
136
+ readonly keepInvalid?: boolean;
137
+ }
138
+ /** Structural paste event: a DOM `ClipboardEvent` and React's `onPaste` event both fit. */
139
+ interface AddressPasteEvent {
140
+ readonly clipboardData: {
141
+ getData(format: string): string;
142
+ } | null;
143
+ readonly currentTarget: EventTarget | null;
144
+ readonly target: EventTarget | null;
145
+ readonly defaultPrevented: boolean;
146
+ preventDefault(): void;
147
+ }
148
+ /**
149
+ * A paste handler for recipient fields: To and Cc boxes, invite and share dialogs. A list
150
+ * copied from Outlook, Gmail or a spreadsheet becomes addresses for your chips; what was not
151
+ * an address stays in the field to be corrected. Typing and pasting a name are left alone.
152
+ *
153
+ * @example
154
+ * <input
155
+ * type="email"
156
+ * multiple
157
+ * onPaste={(event) => pasteAddresses(event, { onAddresses: ({ addresses }) => addRecipients(addresses) })}
158
+ * />
159
+ */
160
+ export declare function pasteAddresses(event: AddressPasteEvent, options: PasteAddressesOptions): AddressPasteOutcome;
161
+ //#endregion
162
+ export type { AddressList, AddressPasteEvent, AddressPasteOutcome, AddressToWrite, AddressesPayloadOptions, EmailAddress, InvalidAddress, InvalidAddressReason, ParseAddressesOptions, PasteAddressesOptions };
163
+ //# sourceMappingURL=email.d.cts.map