react-smart-copy 1.24.1 → 1.25.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.
- package/README.md +2 -0
- package/dist/chunks/{core-BH2uIumi.js → core-BcEpjsB_.js} +21 -2
- package/dist/chunks/core-BcEpjsB_.js.map +1 -0
- package/dist/chunks/{core-DmncxMt3.cjs → core-C1IV8E15.cjs} +21 -2
- package/dist/chunks/core-C1IV8E15.cjs.map +1 -0
- package/dist/chunks/{field-CNEcZqa9.cjs → field-B6SRWRbI.cjs} +17 -6
- package/dist/chunks/field-B6SRWRbI.cjs.map +1 -0
- package/dist/chunks/{field-CK3NxfkM.js → field-DsRKkbav.js} +12 -7
- package/dist/chunks/field-DsRKkbav.js.map +1 -0
- package/dist/chunks/limits-9wi1f6xT.cjs +23 -0
- package/dist/chunks/limits-9wi1f6xT.cjs.map +1 -0
- package/dist/chunks/limits-BP9R5wnr.js +18 -0
- package/dist/chunks/limits-BP9R5wnr.js.map +1 -0
- package/dist/code.cjs +3 -7
- package/dist/code.cjs.map +1 -1
- package/dist/code.js +1 -5
- package/dist/code.js.map +1 -1
- package/dist/core.cjs +1 -1
- package/dist/core.js +1 -1
- package/dist/email.cjs +11 -7
- package/dist/email.cjs.map +1 -1
- package/dist/email.d.cts +8 -4
- package/dist/email.d.ts +8 -4
- package/dist/email.js +11 -8
- package/dist/email.js.map +1 -1
- package/dist/index.cjs +2 -2
- package/dist/index.js +2 -2
- package/dist/number.cjs +8 -3
- package/dist/number.cjs.map +1 -1
- package/dist/number.d.cts +8 -3
- package/dist/number.d.ts +8 -3
- package/dist/number.js +8 -4
- package/dist/number.js.map +1 -1
- package/dist/otp.cjs +2 -1
- package/dist/otp.d.cts +8 -3
- package/dist/otp.d.ts +8 -3
- package/dist/otp.js +1 -1
- package/package.json +7 -3
- package/dist/chunks/core-BH2uIumi.js.map +0 -1
- package/dist/chunks/core-DmncxMt3.cjs.map +0 -1
- package/dist/chunks/field-CK3NxfkM.js.map +0 -1
- package/dist/chunks/field-CNEcZqa9.cjs.map +0 -1
package/dist/email.cjs.map
CHANGED
|
@@ -1 +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,mBAAmB;;AAGzB,SAAS,YAAY,QAA+B;CAClD,IAAI,WAAW,KAAK,MAAM,GAAG,OAAO;CACpC,IAAI;CACJ,IAAI;EAEF,OAAO,IAAI,IAAI,UAAU,QAAQ,CAAC,CAAC;CACrC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AAI,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"}
|
|
1
|
+
{"version":3,"file":"email.cjs","names":["copyFailure","positiveLimit","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 { positiveLimit } from '../core/limits';\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 `maxLength` 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 /** Read only this many characters of the text. Default {@link DEFAULT_ADDRESS_LIST_MAX_LENGTH}. */\n readonly maxLength?: number;\n}\n\n/** Longer text is cut here: no list of recipients is this long. */\nexport const DEFAULT_ADDRESS_LIST_MAX_LENGTH = 100_000;\n/** @deprecated The old name of {@link DEFAULT_ADDRESS_LIST_MAX_LENGTH}; removed in 2.0. */\nexport const ADDRESS_LIST_MAX_LENGTH: number = DEFAULT_ADDRESS_LIST_MAX_LENGTH;\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` or `maxLength` that is not a\n * positive whole 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 = positiveLimit(options.maxAddresses, 1000, 'maxAddresses');\n const maxLength = positiveLimit(options.maxLength, DEFAULT_ADDRESS_LIST_MAX_LENGTH, 'maxLength');\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, maxLength).replace(/^\\uFEFF/, '').replace(/\\r\\n?/g, '\\n').normalize('NFKC');\n const entries = join(split(input));\n const truncated = text.length > maxLength || 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,mBAAmB;;AAGzB,SAAS,YAAY,QAA+B;CAClD,IAAI,WAAW,KAAK,MAAM,GAAG,OAAO;CACpC,IAAI;CACJ,IAAI;EAEF,OAAO,IAAI,IAAI,UAAU,QAAQ,CAAC,CAAC;CACrC,QAAQ;EACN,OAAO;CACT;CACA,MAAM,SAAS,KAAK,MAAM,GAAG;CAC7B,IAAI,KAAK,SAAS,OAAO,OAAO,SAAS,KAAK,CAAC,OAAO,OAAO,UAAU,MAAM,KAAK,KAAK,CAAC,GAAG,OAAO;CAClG,OAAO,IAAI,KAAK,OAAO,OAAO,OAAO,SAAS,EAAE,CAAC,IAAI,OAAO;AAC9D;;AA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,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"}
|
package/dist/email.d.cts
CHANGED
|
@@ -46,7 +46,7 @@ interface AddressList {
|
|
|
46
46
|
readonly invalid: readonly InvalidAddress[];
|
|
47
47
|
/** How many addresses were left out because they came earlier in the list. */
|
|
48
48
|
readonly duplicates: number;
|
|
49
|
-
/** The text held more than `maxAddresses` entries, or more than
|
|
49
|
+
/** The text held more than `maxAddresses` entries, or more than `maxLength` characters: the rest was not read. */
|
|
50
50
|
readonly truncated: boolean;
|
|
51
51
|
}
|
|
52
52
|
interface ParseAddressesOptions {
|
|
@@ -59,9 +59,13 @@ interface ParseAddressesOptions {
|
|
|
59
59
|
* `ana@example.com` and `ana@mail.example.com`). Others are `invalid` with `'not-allowed'`.
|
|
60
60
|
*/
|
|
61
61
|
readonly domains?: readonly string[];
|
|
62
|
+
/** Read only this many characters of the text. Default {@link DEFAULT_ADDRESS_LIST_MAX_LENGTH}. */
|
|
63
|
+
readonly maxLength?: number;
|
|
62
64
|
}
|
|
63
65
|
/** Longer text is cut here: no list of recipients is this long. */
|
|
64
|
-
export declare const
|
|
66
|
+
export declare const DEFAULT_ADDRESS_LIST_MAX_LENGTH = 100000;
|
|
67
|
+
/** @deprecated The old name of {@link DEFAULT_ADDRESS_LIST_MAX_LENGTH}; removed in 2.0. */
|
|
68
|
+
export declare const ADDRESS_LIST_MAX_LENGTH: number;
|
|
65
69
|
/**
|
|
66
70
|
* Reads the e-mail addresses in a pasted list of recipients, as Outlook, Gmail, Apple Mail,
|
|
67
71
|
* contact cards and spreadsheet columns copy them:
|
|
@@ -76,8 +80,8 @@ export declare const ADDRESS_LIST_MAX_LENGTH = 100000;
|
|
|
76
80
|
* IP addresses can't), lengths, and characters that hide what an address really is. Domains
|
|
77
81
|
* that mix scripts are flagged as `lookalike`.
|
|
78
82
|
*
|
|
79
|
-
* @throws {CopyFailure} `invalid-payload` for a `maxAddresses` that is not a
|
|
80
|
-
* number, or a `domains` entry that is not a domain.
|
|
83
|
+
* @throws {CopyFailure} `invalid-payload` for a `maxAddresses` or `maxLength` that is not a
|
|
84
|
+
* positive whole number, or a `domains` entry that is not a domain.
|
|
81
85
|
* @example
|
|
82
86
|
* parseAddresses('Lima, Ana <ana@example.com>; bo@example.org, not an address');
|
|
83
87
|
* // addresses: [{ address: 'ana@example.com', name: 'Lima, Ana', ... }, { address: 'bo@example.org', name: null, ... }]
|
package/dist/email.d.ts
CHANGED
|
@@ -46,7 +46,7 @@ interface AddressList {
|
|
|
46
46
|
readonly invalid: readonly InvalidAddress[];
|
|
47
47
|
/** How many addresses were left out because they came earlier in the list. */
|
|
48
48
|
readonly duplicates: number;
|
|
49
|
-
/** The text held more than `maxAddresses` entries, or more than
|
|
49
|
+
/** The text held more than `maxAddresses` entries, or more than `maxLength` characters: the rest was not read. */
|
|
50
50
|
readonly truncated: boolean;
|
|
51
51
|
}
|
|
52
52
|
interface ParseAddressesOptions {
|
|
@@ -59,9 +59,13 @@ interface ParseAddressesOptions {
|
|
|
59
59
|
* `ana@example.com` and `ana@mail.example.com`). Others are `invalid` with `'not-allowed'`.
|
|
60
60
|
*/
|
|
61
61
|
readonly domains?: readonly string[];
|
|
62
|
+
/** Read only this many characters of the text. Default {@link DEFAULT_ADDRESS_LIST_MAX_LENGTH}. */
|
|
63
|
+
readonly maxLength?: number;
|
|
62
64
|
}
|
|
63
65
|
/** Longer text is cut here: no list of recipients is this long. */
|
|
64
|
-
export declare const
|
|
66
|
+
export declare const DEFAULT_ADDRESS_LIST_MAX_LENGTH = 100000;
|
|
67
|
+
/** @deprecated The old name of {@link DEFAULT_ADDRESS_LIST_MAX_LENGTH}; removed in 2.0. */
|
|
68
|
+
export declare const ADDRESS_LIST_MAX_LENGTH: number;
|
|
65
69
|
/**
|
|
66
70
|
* Reads the e-mail addresses in a pasted list of recipients, as Outlook, Gmail, Apple Mail,
|
|
67
71
|
* contact cards and spreadsheet columns copy them:
|
|
@@ -76,8 +80,8 @@ export declare const ADDRESS_LIST_MAX_LENGTH = 100000;
|
|
|
76
80
|
* IP addresses can't), lengths, and characters that hide what an address really is. Domains
|
|
77
81
|
* that mix scripts are flagged as `lookalike`.
|
|
78
82
|
*
|
|
79
|
-
* @throws {CopyFailure} `invalid-payload` for a `maxAddresses` that is not a
|
|
80
|
-
* number, or a `domains` entry that is not a domain.
|
|
83
|
+
* @throws {CopyFailure} `invalid-payload` for a `maxAddresses` or `maxLength` that is not a
|
|
84
|
+
* positive whole number, or a `domains` entry that is not a domain.
|
|
81
85
|
* @example
|
|
82
86
|
* parseAddresses('Lima, Ana <ana@example.com>; bo@example.org, not an address');
|
|
83
87
|
* // addresses: [{ address: 'ana@example.com', name: 'Lima, Ana', ... }, { address: 'bo@example.org', name: null, ... }]
|
package/dist/email.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
|
|
2
2
|
import { n as copyFailure } from "./chunks/errors-CT-FfUtU.js";
|
|
3
|
+
import { t as positiveLimit } from "./chunks/limits-BP9R5wnr.js";
|
|
3
4
|
import { n as insertText, t as asTextField } from "./chunks/text-field-D7PF2WlX.js";
|
|
4
5
|
//#region src/email/address.ts
|
|
5
6
|
/** Invisible and direction-changing characters, soft hyphens and variation selectors. */
|
|
@@ -60,7 +61,9 @@ function checkAddress(text, name) {
|
|
|
60
61
|
//#endregion
|
|
61
62
|
//#region src/email/parse.ts
|
|
62
63
|
/** Longer text is cut here: no list of recipients is this long. */
|
|
63
|
-
const
|
|
64
|
+
const DEFAULT_ADDRESS_LIST_MAX_LENGTH = 1e5;
|
|
65
|
+
/** @deprecated The old name of {@link DEFAULT_ADDRESS_LIST_MAX_LENGTH}; removed in 2.0. */
|
|
66
|
+
const ADDRESS_LIST_MAX_LENGTH = DEFAULT_ADDRESS_LIST_MAX_LENGTH;
|
|
64
67
|
const MAX_NAME_LENGTH = 256;
|
|
65
68
|
/** An entry longer than this is no address with its name: it is not read. */
|
|
66
69
|
const MAX_ENTRY_LENGTH = 1024;
|
|
@@ -228,19 +231,19 @@ function allowedDomain(domain) {
|
|
|
228
231
|
* IP addresses can't), lengths, and characters that hide what an address really is. Domains
|
|
229
232
|
* that mix scripts are flagged as `lookalike`.
|
|
230
233
|
*
|
|
231
|
-
* @throws {CopyFailure} `invalid-payload` for a `maxAddresses` that is not a
|
|
232
|
-
* number, or a `domains` entry that is not a domain.
|
|
234
|
+
* @throws {CopyFailure} `invalid-payload` for a `maxAddresses` or `maxLength` that is not a
|
|
235
|
+
* positive whole number, or a `domains` entry that is not a domain.
|
|
233
236
|
* @example
|
|
234
237
|
* parseAddresses('Lima, Ana <ana@example.com>; bo@example.org, not an address');
|
|
235
238
|
* // addresses: [{ address: 'ana@example.com', name: 'Lima, Ana', ... }, { address: 'bo@example.org', name: null, ... }]
|
|
236
239
|
* // invalid: [{ text: 'not an address', reason: 'syntax' }]
|
|
237
240
|
*/
|
|
238
241
|
function parseAddresses(text, options = {}) {
|
|
239
|
-
const max = options.maxAddresses
|
|
240
|
-
|
|
242
|
+
const max = positiveLimit(options.maxAddresses, 1e3, "maxAddresses");
|
|
243
|
+
const maxLength = positiveLimit(options.maxLength, DEFAULT_ADDRESS_LIST_MAX_LENGTH, "maxLength");
|
|
241
244
|
const allowed = options.domains?.map(allowedDomain);
|
|
242
|
-
const entries = join(split(text.slice(0,
|
|
243
|
-
const truncated = text.length >
|
|
245
|
+
const entries = join(split(text.slice(0, maxLength).replace(/^\uFEFF/, "").replace(/\r\n?/g, "\n").normalize("NFKC")));
|
|
246
|
+
const truncated = text.length > maxLength || entries.length > max;
|
|
244
247
|
const addresses = [];
|
|
245
248
|
const invalid = [];
|
|
246
249
|
const seen = /* @__PURE__ */ new Map();
|
|
@@ -346,6 +349,6 @@ function pasteAddresses(event, options) {
|
|
|
346
349
|
return "parsed";
|
|
347
350
|
}
|
|
348
351
|
//#endregion
|
|
349
|
-
export { ADDRESS_LIST_MAX_LENGTH, addressesPayload, formatAddress, parseAddress, parseAddresses, pasteAddresses };
|
|
352
|
+
export { ADDRESS_LIST_MAX_LENGTH, DEFAULT_ADDRESS_LIST_MAX_LENGTH, addressesPayload, formatAddress, parseAddress, parseAddresses, pasteAddresses };
|
|
350
353
|
|
|
351
354
|
//# sourceMappingURL=email.js.map
|
package/dist/email.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"email.js","names":[],"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,mBAAmB;;AAGzB,SAAS,YAAY,QAA+B;CAClD,IAAI,WAAW,KAAK,MAAM,GAAG,OAAO;CACpC,IAAI;CACJ,IAAI;EAEF,OAAO,IAAI,IAAI,UAAU,QAAQ,CAAC,CAAC;CACrC,QAAQ;EACN,OAAO;CACT;CACA,MAAM,SAAS,KAAK,MAAM,GAAG;CAC7B,IAAI,KAAK,SAAS,OAAO,OAAO,SAAS,KAAK,CAAC,OAAO,OAAO,UAAU,MAAM,KAAK,KAAK,CAAC,GAAG,OAAO;CAClG,OAAO,IAAI,KAAK,OAAO,OAAO,OAAO,SAAS,EAAE,CAAC,IAAI,OAAO;AAC9D;;AAGA,SAAS,YAAY,QAAyB;CAC5C,OAAO,OAAO,MAAM,GAAG,CAAC,CAAC,MAAM,UAAU,MAAM,KAAK,KAAK,KAAK,iBAAiB,KAAK,KAAK,CAAC;AAC5F;;;;;;;AAQA,SAAgB,aAAa,MAAc,MAA0D;CACnG,IAAI,UAAU,KAAK,IAAI,GAAG,OAAO;CAEjC,MAAM,aAAa,KAAK,UAAU,MAAM;CACxC,MAAM,KAAK,WAAW,YAAY,GAAG;CACrC,IAAI,OAAO,IAAI,OAAO;CACtB,MAAM,QAAQ,WAAW,MAAM,GAAG,EAAE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Q,SAAS,GAAG;EAC5D,MAAM,QAAQ,YAAY,MAAM,aAAa,KAAK,YAAY,MAAM,MAAM;EAC1E,IAAI,UAAU,MAAM,WAAW,OAAO,KAAK,QAAQ,KAAK,UAAU,MAAM,IAAI,CAAC,CAAC,KAAK,IAAI,CAAC;CAC1F;CACA,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"email.js","names":[],"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 { positiveLimit } from '../core/limits';\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 `maxLength` 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 /** Read only this many characters of the text. Default {@link DEFAULT_ADDRESS_LIST_MAX_LENGTH}. */\n readonly maxLength?: number;\n}\n\n/** Longer text is cut here: no list of recipients is this long. */\nexport const DEFAULT_ADDRESS_LIST_MAX_LENGTH = 100_000;\n/** @deprecated The old name of {@link DEFAULT_ADDRESS_LIST_MAX_LENGTH}; removed in 2.0. */\nexport const ADDRESS_LIST_MAX_LENGTH: number = DEFAULT_ADDRESS_LIST_MAX_LENGTH;\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` or `maxLength` that is not a\n * positive whole 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 = positiveLimit(options.maxAddresses, 1000, 'maxAddresses');\n const maxLength = positiveLimit(options.maxLength, DEFAULT_ADDRESS_LIST_MAX_LENGTH, 'maxLength');\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, maxLength).replace(/^\\uFEFF/, '').replace(/\\r\\n?/g, '\\n').normalize('NFKC');\n const entries = join(split(input));\n const truncated = text.length > maxLength || 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":";;;;;;AAg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mime = require("./chunks/mime--LB7kdqG.cjs");
|
|
6
6
|
const require_clipboard_adapter = require("./chunks/clipboard-adapter-UIFc_Qso.cjs");
|
|
7
|
-
const require_core = require("./chunks/core-
|
|
7
|
+
const require_core = require("./chunks/core-C1IV8E15.cjs");
|
|
8
8
|
const require_paste_reader = require("./chunks/paste-reader-BWQaYNaV.cjs");
|
|
9
9
|
const require_share = require("./chunks/share-nx7M4Z0t.cjs");
|
|
10
|
-
const require_field = require("./chunks/field-
|
|
10
|
+
const require_field = require("./chunks/field-B6SRWRbI.cjs");
|
|
11
11
|
let react = require("react");
|
|
12
12
|
let react_jsx_runtime = require("react/jsx-runtime");
|
|
13
13
|
//#region src/react/CopyGroup.tsx
|
package/dist/index.js
CHANGED
|
@@ -3,10 +3,10 @@ import { a as describePasteError, c as toCopyError, i as describeCopyError, n as
|
|
|
3
3
|
import { a as validatePayload, i as serializeJson, n as isBlob, r as normalizePayload, t as IMAGE_MIME_TYPE } from "./chunks/payload-BrQWGwyx.js";
|
|
4
4
|
import { a as matchesMimePattern, c as sniffImageBytes, i as isWebCustomFormat, l as sniffImageType, n as WEB_CUSTOM_FORMAT_PREFIX, o as normalizeClipboardType, r as isTextualMimeType, s as normalizeMimeType, t as SVG_MIME_TYPE } from "./chunks/mime-aa-HA2dm.js";
|
|
5
5
|
import { t as createBrowserClipboardAdapter } from "./chunks/clipboard-adapter-CmKDTFdO.js";
|
|
6
|
-
import { _ as resolveMaxRetries, a as applyDragCopy, c as interceptCopyEvent, d as DEFAULT_RESET_AFTER_MS, f as IDLE_STATE, g as invoke, h as DEFAULT_MAX_RETRIES, i as createBrowserPasteAdapter, l as readCopySelection, m as createCopyMachine, n as canRetryPasteState, o as registerDragCopy, p as canRetryState, r as createPasteMachine, s as DEFAULT_INTERCEPTED_EVENTS, t as PASTE_IDLE_STATE, u as registerCopyInterceptor, v as createCopyCoordinator } from "./chunks/core-
|
|
6
|
+
import { _ as resolveMaxRetries, a as applyDragCopy, c as interceptCopyEvent, d as DEFAULT_RESET_AFTER_MS, f as IDLE_STATE, g as invoke, h as DEFAULT_MAX_RETRIES, i as createBrowserPasteAdapter, l as readCopySelection, m as createCopyMachine, n as canRetryPasteState, o as registerDragCopy, p as canRetryState, r as createPasteMachine, s as DEFAULT_INTERCEPTED_EVENTS, t as PASTE_IDLE_STATE, u as registerCopyInterceptor, v as createCopyCoordinator } from "./chunks/core-BcEpjsB_.js";
|
|
7
7
|
import { i as canAcceptDrag, l as resolvePasteReadOptions, n as DEFAULT_PASTE_MAX_BYTES, r as DEFAULT_PASTE_MAX_ITEMS, t as DEFAULT_PASTE_ACCEPT } from "./chunks/paste-reader-D6uOTDBM.js";
|
|
8
8
|
import { i as shareOrCopy, r as shareMethod, t as TOUCH_FIRST } from "./chunks/share-CU91L4EK.js";
|
|
9
|
-
import { t as createOtpField } from "./chunks/field-
|
|
9
|
+
import { t as createOtpField } from "./chunks/field-DsRKkbav.js";
|
|
10
10
|
import { createContext, forwardRef, useCallback, useContext, useEffect, useId, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
|
|
11
11
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
12
12
|
//#region src/react/CopyGroup.tsx
|
package/dist/number.cjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const require_errors = require("./chunks/errors-DFmEAC4E.cjs");
|
|
4
|
+
const require_limits = require("./chunks/limits-9wi1f6xT.cjs");
|
|
4
5
|
const require_digits = require("./chunks/digits-BUEvSVrs.cjs");
|
|
5
6
|
const require_text_field = require("./chunks/text-field-BEzUVOag.cjs");
|
|
6
7
|
//#region src/number/currency.ts
|
|
@@ -111,7 +112,9 @@ function numberSymbols(locale) {
|
|
|
111
112
|
}
|
|
112
113
|
//#endregion
|
|
113
114
|
//#region src/number/parse.ts
|
|
114
|
-
/** Longer text holds more than a number: it is not read at all. */
|
|
115
|
+
/** Longer text holds more than a number: it is not read at all, unless `maxLength` allows it. */
|
|
116
|
+
const DEFAULT_NUMBER_MAX_LENGTH = 256;
|
|
117
|
+
/** @deprecated The old name of {@link DEFAULT_NUMBER_MAX_LENGTH}; removed in 2.0. */
|
|
115
118
|
const NUMBER_MAX_LENGTH = 256;
|
|
116
119
|
/** Group separators that are never decimal separators: spaces and apostrophes. */
|
|
117
120
|
const GROUP_ONLY = /* @__PURE__ */ new Set([" ", "'"]);
|
|
@@ -220,14 +223,15 @@ function shift(integer, fraction, exponent) {
|
|
|
220
223
|
* - `%` and `\u2030`, before or after; scientific notation (`1.5E-7`).
|
|
221
224
|
* - Digits of any script, full-width characters, and Arabic separators.
|
|
222
225
|
*
|
|
223
|
-
* @throws {CopyFailure} `invalid-payload` for a `locale` that is not one
|
|
226
|
+
* @throws {CopyFailure} `invalid-payload` for a `locale` that is not one, or a `maxLength`
|
|
227
|
+
* that is not a positive whole number.
|
|
224
228
|
* @example
|
|
225
229
|
* parseNumber('1.234,50 \u20AC', { locale: 'de-DE' });
|
|
226
230
|
* // { value: 1234.5, exact: '1234.50', kind: 'number', currency: { symbol: '\u20AC', code: 'EUR' }, ambiguous: false }
|
|
227
231
|
*/
|
|
228
232
|
function parseNumber(text, options = {}) {
|
|
229
233
|
const symbols = numberSymbols(options.locale ?? "en-US");
|
|
230
|
-
if (text.length > 256) return null;
|
|
234
|
+
if (text.length > require_limits.positiveLimit(options.maxLength, 256, "maxLength")) return null;
|
|
231
235
|
const arabicDecimal = text.includes("٫");
|
|
232
236
|
const normalized = normalize(text.replace(/\u066B/g, "."));
|
|
233
237
|
let start = normalized.search(/\d/);
|
|
@@ -432,6 +436,7 @@ function pasteAsNumber(event, options = {}) {
|
|
|
432
436
|
return "rejected";
|
|
433
437
|
}
|
|
434
438
|
//#endregion
|
|
439
|
+
exports.DEFAULT_NUMBER_MAX_LENGTH = DEFAULT_NUMBER_MAX_LENGTH;
|
|
435
440
|
exports.NUMBER_MAX_LENGTH = NUMBER_MAX_LENGTH;
|
|
436
441
|
exports.formatNumber = formatNumber;
|
|
437
442
|
exports.numberPayload = numberPayload;
|