react-smart-copy 1.22.0 → 1.24.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/README.md +56 -0
  2. package/dist/chunks/digits-BUEvSVrs.cjs +51 -0
  3. package/dist/chunks/digits-BUEvSVrs.cjs.map +1 -0
  4. package/dist/chunks/digits-DkU-O9_A.js +46 -0
  5. package/dist/chunks/digits-DkU-O9_A.js.map +1 -0
  6. package/dist/chunks/{field-Cdq2LxEO.js → field-BHo5y-t_.js} +3 -31
  7. package/dist/chunks/field-BHo5y-t_.js.map +1 -0
  8. package/dist/chunks/{field-NaDdWy_5.cjs → field-Bytz2WfN.cjs} +3 -31
  9. package/dist/chunks/field-Bytz2WfN.cjs.map +1 -0
  10. package/dist/chunks/{text-field-Ba8W3v4R.cjs → text-field-BEzUVOag.cjs} +26 -5
  11. package/dist/chunks/text-field-BEzUVOag.cjs.map +1 -0
  12. package/dist/chunks/{text-field-DUvrMMaK.js → text-field-D7PF2WlX.js} +21 -6
  13. package/dist/chunks/text-field-D7PF2WlX.js.map +1 -0
  14. package/dist/code.cjs +1 -1
  15. package/dist/code.js +1 -1
  16. package/dist/color.cjs +1 -1
  17. package/dist/color.js +1 -1
  18. package/dist/email.cjs +357 -0
  19. package/dist/email.cjs.map +1 -0
  20. package/dist/email.d.cts +163 -0
  21. package/dist/email.d.ts +163 -0
  22. package/dist/email.js +351 -0
  23. package/dist/email.js.map +1 -0
  24. package/dist/index.cjs +1 -1
  25. package/dist/index.js +1 -1
  26. package/dist/link.cjs +1 -1
  27. package/dist/link.js +1 -1
  28. package/dist/markdown.cjs +1 -1
  29. package/dist/markdown.js +1 -1
  30. package/dist/number.cjs +442 -0
  31. package/dist/number.cjs.map +1 -0
  32. package/dist/number.d.cts +172 -0
  33. package/dist/number.d.ts +172 -0
  34. package/dist/number.js +436 -0
  35. package/dist/number.js.map +1 -0
  36. package/dist/otp.cjs +1 -1
  37. package/dist/otp.js +1 -1
  38. package/dist/secrets.cjs +1 -1
  39. package/dist/secrets.js +1 -1
  40. package/package.json +64 -3
  41. package/dist/chunks/field-Cdq2LxEO.js.map +0 -1
  42. package/dist/chunks/field-NaDdWy_5.cjs.map +0 -1
  43. package/dist/chunks/text-field-Ba8W3v4R.cjs.map +0 -1
  44. package/dist/chunks/text-field-DUvrMMaK.js.map +0 -1
@@ -1 +0,0 @@
1
- {"version":3,"file":"field-Cdq2LxEO.js","names":[],"sources":["../../src/otp/normalize.ts","../../src/otp/extract.ts","../../src/otp/state.ts","../../src/otp/web-otp.ts","../../src/otp/field.ts"],"sourcesContent":["/** What a one-time code is made of. */\nexport type OtpAlphabet = 'numeric' | 'alphanumeric';\n\n/**\n * Code points of zero in the decimal digit sets people receive codes in: Arabic-Indic,\n * Persian, Devanagari, Bengali, Gurmukhi, Gujarati, Oriya, Tamil, Telugu, Kannada,\n * Malayalam, Thai, Lao, Tibetan, Myanmar and Khmer. Full-width digits are handled by NFKC.\n */\nconst ZEROS: readonly number[] = [\n 0x0660, 0x06f0, 0x0966, 0x09e6, 0x0a66, 0x0ae6, 0x0b66, 0x0be6, 0x0c66, 0x0ce6, 0x0d66, 0x0e50, 0x0ed0, 0x0f20, 0x1040, 0x17e0,\n];\n\n/** `char` as an ASCII digit, when it is a digit of one of {@link ZEROS}' sets. */\nfunction asciiDigit(char: string): string {\n const code = char.charCodeAt(0);\n for (const zero of ZEROS) {\n if (code >= zero && code <= zero + 9) return String(code - zero);\n }\n return char;\n}\n\n/**\n * `text` with its digits in ASCII and, for alphanumeric codes, its letters in upper case:\n * full-width digits and letters, and Arabic-Indic, Devanagari and other scripts' digits,\n * become ASCII. Other characters are kept: callers decide what to drop.\n */\nexport function normalizeOtpText(text: string, alphabet: OtpAlphabet): string {\n const ascii = text.normalize('NFKC').replace(/[\\u0080-\\uffff]/g, asciiDigit);\n return alphabet === 'alphanumeric' ? ascii.toUpperCase() : ascii;\n}\n\n/** Whether `char` (already normalized) can be part of a code. */\nexport function isOtpChar(char: string, alphabet: OtpAlphabet): boolean {\n return alphabet === 'numeric' ? char >= '0' && char <= '9' && char.length === 1 : /^[0-9A-Z]$/.test(char);\n}\n\n/** The characters of `text` that can be part of a code, normalized, in order. */\nexport function otpChars(text: string, alphabet: OtpAlphabet): string[] {\n return Array.from(normalizeOtpText(text, alphabet)).filter((char) => isOtpChar(char, alphabet));\n}\n","import { copyFailure } from '../core/errors';\nimport { normalizeOtpText, type OtpAlphabet } from './normalize';\n\n/** Text past this many characters is not read: a code is near the start of a message. */\nexport const OTP_SCAN_LENGTH = 100_000;\n\nexport interface ExtractOtpOptions {\n /** The code's length, or its range. Default 4 to 8. */\n readonly length?: number | { readonly min: number; readonly max: number };\n /** Default `'numeric'`. Alphanumeric codes are upper case: pasted letters are made so. */\n readonly alphabet?: OtpAlphabet;\n /**\n * Your site's host name, as in `example.com`. An origin-bound message (`@example.com #123456`,\n * the format the WebOTP API reads) for another host gives no code: it was not meant for you.\n */\n readonly domain?: string;\n}\n\n/**\n * Where the code was found.\n *\n * - `whole-text`: the text is the code (`482913`, `482 913`, `482-913`).\n * - `origin-bound`: the message's last line binds it to a site (`@example.com #482913`).\n * - `keyword`: next to a word such as \"code\", \"OTP\", \"verification\" or \"PIN\", in any of\n * many languages.\n * - `only-candidate`: the only number of the right length that is not a price, a date, a\n * time, a phone number or an order number.\n */\nexport type OtpSource = 'whole-text' | 'origin-bound' | 'keyword' | 'only-candidate';\n\nexport interface OtpMatch {\n /** The code: ASCII digits (and upper-case letters, for alphanumeric codes), no separators. */\n readonly code: string;\n readonly source: OtpSource;\n /** `medium` for `only-candidate`; `high` otherwise. */\n readonly confidence: 'high' | 'medium';\n /** The site an origin-bound message names; `null` otherwise. */\n readonly domain: string | null;\n}\n\ninterface Range {\n readonly min: number;\n readonly max: number;\n}\n\nfunction rangeOf(length: ExtractOtpOptions['length']): Range {\n const range = typeof length === 'number' ? { min: length, max: length } : (length ?? { min: 4, max: 8 });\n const valid = (value: number): boolean => Number.isInteger(value) && value >= 1 && value <= 32;\n if (!valid(range.min) || !valid(range.max) || range.min > range.max) {\n throw copyFailure('invalid-payload', 'length must be a whole number from 1 to 32, or a range of them.');\n }\n return range;\n}\n\n/**\n * Words next to a one-time code, lower case: English, Hindi, Spanish, Portuguese, French,\n * German, Italian, Dutch, Indonesian, Turkish, Polish, Russian, Ukrainian, Arabic, Hebrew,\n * Persian, Chinese, Japanese, Korean, Vietnamese and Thai.\n */\nconst KEYWORDS: readonly string[] = [\n 'code', 'otp', 'one-time', 'one time', 'passcode', 'password', 'pin', 'verification', 'verify', 'security', 'login', 'log in',\n 'sign-in', 'sign in', '2fa', 'two-factor', 'authentication', 'token',\n '\\u0913\\u091F\\u0940\\u092A\\u0940', '\\u0915\\u094B\\u0921', '\\u0938\\u0924\\u094D\\u092F\\u093E\\u092A\\u0928',\n 'c\\u00F3digo', 'codigo', 'clave', 'contrase\\u00F1a', 'senha', 'mot de passe', 'v\\u00E9rification', 'best\\u00E4tigungscode',\n 'kennwort', 'codice', 'verificatie', 'kode', 'kod', 'do\\u011Frulama', 'weryfikacyjny',\n '\\u043A\\u043E\\u0434', '\\u043F\\u0430\\u0440\\u043E\\u043B\\u044C', '\\u0440\\u0430\\u0437\\u043E\\u0432\\u044B\\u0439',\n '\\u0631\\u0645\\u0632', '\\u0643\\u0648\\u062F', '\\u0627\\u0644\\u062A\\u062D\\u0642\\u0642', '\\u05E7\\u05D5\\u05D3', '\\u06A9\\u062F',\n '\\u9A8C\\u8BC1\\u7801', '\\u9A57\\u8B49\\u78BC', '\\u6821\\u9A8C\\u7801', '\\u52D5\\u614B\\u78BC', '\\u8A8D\\u8A3C\\u30B3\\u30FC\\u30C9',\n '\\u78BA\\u8A8D\\u30B3\\u30FC\\u30C9', '\\u30EF\\u30F3\\u30BF\\u30A4\\u30E0', '\\u8A8D\\u8A3C\\u756A\\u53F7', '\\uC778\\uC99D\\uBC88\\uD638',\n '\\uC778\\uC99D', '\\uCF54\\uB4DC', 'm\\u00E3', 'x\\u00E1c th\\u1EF1c', '\\u0E23\\u0E2B\\u0E31\\u0E2A',\n];\n\n/** Codes that are not one-time codes, right before a number: postal codes, coupons, orders. */\nconst NOT_OTP = /(?:pin ?code|zip|postal|post code|promo|coupon|discount|voucher|referral|order|invoice|ref\\.?|account|a\\/c|flight|pnr|room|tracking)[\\s:#.-]{0,4}$/;\n\n/** Currencies and units around a number: it is an amount, not a code. */\nconst CURRENCY_BEFORE = /(?:[$\\u20AC\\u00A3\\u20B9\\u00A5\\u20A9\\u20BD\\u00A2]|\\brs\\.?|\\binr|\\busd|\\beur|\\bgbp)\\s?$/;\nconst AMOUNT_AFTER = /^\\s?(?:%|[$\\u20AC\\u00A3\\u20B9\\u00A5]|inr\\b|usd\\b|eur\\b|rs\\b|rupees\\b|dollars\\b|euros\\b)/;\n\nconst NUMERIC = /(^|[^\\p{L}\\p{N}_])(\\d{2,4}(?:[ -]\\d{2,4}){1,3}|\\d{1,12})(?![\\p{L}\\p{N}_])/gu;\nconst ALPHANUMERIC = /(^|[^\\p{L}\\p{N}_])([A-Z0-9]{2,6}(?:-[A-Z0-9]{2,6}){1,3}|[A-Z0-9]{1,12})(?![\\p{L}\\p{N}_])/gu;\n\nconst isDigit = (char: string | undefined): boolean => char !== undefined && char >= '0' && char <= '9';\n\n/**\n * Whether the number at `start`-`end` is something else: part of a longer number (a phone\n * number), a date, a time or a decimal, an amount, an order or reference number, or inside\n * a URL or an e-mail address.\n */\nfunction excluded(text: string, lower: string, start: number, end: number): boolean {\n const before = text[start - 1];\n const after = text[end];\n if ((before === ' ' || before === '-') && isDigit(text[start - 2])) return true;\n if ((after === ' ' || after === '-') && isDigit(text[end + 1])) return true;\n // A time, a date, a decimal or a version (`10:30`, `23/10`, `3.14`), and thousands (`2,500`).\n if (before !== undefined && ':/.'.includes(before) && isDigit(text[start - 2])) return true;\n if (after !== undefined && ':/.'.includes(after) && isDigit(text[end + 1])) return true;\n if ((before === ',' && isDigit(text[start - 2]) && /^\\d{3}(?!\\d)/.test(text.slice(start, start + 4))) || /^,\\d{3}(?!\\d)/.test(text.slice(end, end + 5))) return true;\n if (before === '+' || before === '#' || before === '(' || (before === ' ' && text[start - 2] === ')')) return true;\n const head = lower.slice(Math.max(0, start - 24), start);\n if (CURRENCY_BEFORE.test(head) || NOT_OTP.test(head) || AMOUNT_AFTER.test(lower.slice(end, end + 10))) return true;\n // The word around it, between white space (up to 256 characters each way, so a scan stays\n // linear): a URL, with a scheme or a bare host and path (`example.com/t/48291`), or an\n // e-mail address holds no code.\n let from = start;\n while (from > Math.max(0, start - 256) && !/\\s/.test(text[from - 1] as string)) from -= 1;\n let to = end;\n while (to < Math.min(text.length, end + 256) && !/\\s/.test(text[to] as string)) to += 1;\n return /@|:\\/\\/|www\\.|[\\p{L}\\p{N}-]\\.\\p{L}{2,}\\//iu.test(text.slice(from, to));\n}\n\n/** Lower case, one character for one: positions in it are positions in `text`. */\nfunction lowerSameLength(text: string): string {\n let out = '';\n for (const char of text) {\n const lower = char.toLowerCase();\n out += lower.length === char.length ? lower : char;\n }\n return out;\n}\n\n/** The distance from the number at `start`-`end` to the nearest keyword: words before count closer. */\nfunction keywordDistance(lower: string, start: number, end: number): number {\n let best = Infinity;\n const window = lower.slice(Math.max(0, start - 60), Math.min(lower.length, end + 40));\n const offset = Math.max(0, start - 60);\n for (const keyword of KEYWORDS) {\n // Words in Latin script count only as whole words: `pin` is not in `spinning`.\n const whole = /^[a-z0-9 -]+$/.test(keyword);\n for (let at = window.indexOf(keyword); at !== -1; at = window.indexOf(keyword, at + 1)) {\n if (whole && (/[a-z]/.test(window[at - 1] ?? '') || /[a-z]/.test(window[at + keyword.length] ?? ''))) continue;\n const from = at + offset;\n const to = from + keyword.length;\n // A keyword inside the number itself (as in `otp` of an alphanumeric code) does not count.\n if (to <= start) best = Math.min(best, start - to);\n else if (from >= end) best = Math.min(best, from - end + 10);\n }\n }\n return best;\n}\n\n/** The origin-bound line of the WebOTP format: `@host #code`, last in the message. */\nconst ORIGIN_BOUND = /(?:^|\\n)@([a-z0-9.-]{1,253}(?::\\d{1,5})?) #([A-Za-z0-9]{1,32})(?: @[a-z0-9.-]{1,253}(?::\\d{1,5})?)?[ \\t]*$/i;\n\n/**\n * The one-time code in `text`: an SMS or e-mail people paste, or a code they copied. Digits\n * of any script and full-width characters are read as ASCII, and separators are dropped\n * (`482 913`, `482-913`).\n *\n * Prices, dates, times, phone numbers, order numbers and postal codes are never taken for a\n * code. When several numbers could be the code and no keyword points at one, the result is\n * `null`: guessing would fill in a wrong code.\n *\n * @throws {CopyFailure} `invalid-payload` for a `length` that is not 1 to 32, or a reversed range.\n */\nexport function extractOtp(text: string, options: ExtractOtpOptions = {}): OtpMatch | null {\n const range = rangeOf(options.length);\n const alphabet = options.alphabet ?? 'numeric';\n const fits = (code: string): boolean => code.length >= range.min && code.length <= range.max && (alphabet === 'alphanumeric' || /^\\d+$/.test(code));\n const normalized = normalizeOtpText(text.slice(0, OTP_SCAN_LENGTH), alphabet);\n\n // The text is the code itself.\n const whole = normalized.trim();\n if (/^[0-9A-Z]{1,32}(?:[ -][0-9A-Z]{1,32}){0,7}$/.test(whole)) {\n const code = whole.replace(/[ -]/g, '');\n if (fits(code)) return { code, source: 'whole-text', confidence: 'high', domain: null };\n }\n\n // A message bound to a site, in the format the WebOTP API reads.\n // Read with its case kept: host names are lower case, and an alphanumeric code is upper-cased after.\n const bound = ORIGIN_BOUND.exec(normalizeOtpText(text.slice(0, OTP_SCAN_LENGTH), 'numeric').trimEnd());\n if (bound !== null) {\n const domain = (bound[1] as string).toLowerCase();\n const code = (bound[2] as string).toUpperCase();\n if (options.domain !== undefined && options.domain.toLowerCase() !== domain) return null;\n if (fits(code)) return { code, source: 'origin-bound', confidence: 'high', domain };\n }\n\n const lower = lowerSameLength(normalized);\n const pattern = alphabet === 'numeric' ? NUMERIC : ALPHANUMERIC;\n const candidates: { readonly code: string; readonly distance: number }[] = [];\n for (const match of normalized.matchAll(pattern)) {\n const raw = match[2] as string;\n const start = match.index + (match[1] as string).length;\n const code = raw.replace(/[ -]/g, '');\n if (!fits(code) || (alphabet === 'alphanumeric' && !/\\d/.test(code)) || excluded(normalized, lower, start, start + raw.length)) continue;\n candidates.push({ code, distance: keywordDistance(lower, start, start + raw.length) });\n }\n const near = candidates.filter((candidate) => candidate.distance <= 60);\n if (near.length > 0) {\n const best = near.reduce((a, b) => (b.distance < a.distance ? b : a));\n return { code: best.code, source: 'keyword', confidence: 'high', domain: null };\n }\n const distinct = new Set(candidates.map((candidate) => candidate.code));\n return distinct.size === 1 ? { code: [...distinct][0] as string, source: 'only-candidate', confidence: 'medium', domain: null } : null;\n}\n","import { extractOtp } from './extract';\nimport { otpChars, type OtpAlphabet } from './normalize';\n\n/** The characters in each box ('' for an empty one), and the box to focus next. */\nexport interface OtpStep {\n readonly chars: readonly string[];\n /** The box to focus after the change. */\n readonly focus: number;\n}\n\nexport interface OtpSettings {\n readonly length: number;\n readonly alphabet: OtpAlphabet;\n}\n\n/** Keys a code field handles itself. */\nexport type OtpKey = 'Backspace' | 'Delete' | 'ArrowLeft' | 'ArrowRight' | 'Home' | 'End';\n\nexport const emptyChars = (length: number): readonly string[] => Array.from({ length }, () => '');\n\nconst clamp = (index: number, length: number): number => Math.min(Math.max(index, 0), length - 1);\n\n/** `chars` with `text`'s characters written from `index` on, as far as they fit. */\nfunction write(chars: readonly string[], index: number, text: readonly string[], settings: OtpSettings): OtpStep {\n const next = [...chars];\n // A whole code (an SMS autofill into one box, a paste) fills the field from the start.\n const from = text.length >= settings.length ? 0 : clamp(index, settings.length);\n const count = Math.min(text.length, settings.length - from);\n for (let offset = 0; offset < count; offset += 1) next[from + offset] = text[offset] as string;\n return { chars: next, focus: clamp(from + count, settings.length) };\n}\n\n/**\n * What typing (or an autofill, or an input method) does to box `index`, whose value went\n * from `previous` to `value`. A character typed next to the one already there replaces it;\n * several characters fill the boxes after it; characters a code can't have are ignored.\n */\nexport function inputStep(chars: readonly string[], index: number, previous: string, value: string, settings: OtpSettings): OtpStep {\n let typed = value;\n // One character added beside the one the box held: the new one is what was typed.\n if (previous !== '' && value.length === previous.length + 1) {\n if (value.startsWith(previous)) typed = value.slice(previous.length);\n else if (value.endsWith(previous)) typed = value.slice(0, value.length - previous.length);\n }\n const text = otpChars(typed, settings.alphabet);\n if (text.length > 0) return write(chars, index, text, settings);\n if (value === '') {\n // The box was emptied (a cut, or a delete the browser did itself).\n const next = [...chars];\n next[index] = '';\n return { chars: next, focus: index };\n }\n return { chars, focus: index };\n}\n\n/** What pasting `text` into box `index` does: the code in it fills the field, wherever it is pasted. */\nexport function pasteStep(chars: readonly string[], index: number, text: string, settings: OtpSettings): OtpStep {\n const match = extractOtp(text, { length: settings.length, alphabet: settings.alphabet });\n if (match !== null) return write(chars, 0, Array.from(match.code), settings);\n const typed = otpChars(text, settings.alphabet);\n return typed.length > 0 && typed.length < settings.length ? write(chars, index, typed, settings) : { chars, focus: index };\n}\n\n/** What a navigation or deletion key does in box `index`. */\nexport function keyStep(chars: readonly string[], index: number, key: OtpKey, settings: OtpSettings): OtpStep {\n const last = settings.length - 1;\n switch (key) {\n case 'Backspace': {\n const next = [...chars];\n // An empty box: the one before it is cleared, as if the cursor were between them.\n const target = chars[index] === '' ? Math.max(0, index - 1) : index;\n next[target] = '';\n return { chars: next, focus: target };\n }\n case 'Delete': {\n const next = [...chars];\n next[index] = '';\n return { chars: next, focus: index };\n }\n case 'ArrowLeft':\n return { chars, focus: Math.max(0, index - 1) };\n case 'ArrowRight':\n return { chars, focus: Math.min(last, index + 1) };\n case 'Home':\n return { chars, focus: 0 };\n case 'End': {\n const empty = chars.indexOf('');\n return { chars, focus: empty === -1 ? last : empty };\n }\n }\n}\n\n/** A whole code set at once (from WebOTP, or by the app): its characters from the first box. */\nexport function setStep(code: string, settings: OtpSettings): OtpStep {\n return write(emptyChars(settings.length), 0, otpChars(code, settings.alphabet).slice(0, settings.length), settings);\n}\n","/**\n * Where filling a code from an SMS (the WebOTP API) stands.\n *\n * - `idle`: not asked for.\n * - `waiting`: the browser is waiting for an SMS that ends with `@your.host #code`.\n * - `received`: it came, and filled the field.\n * - `unsupported`: this browser has no WebOTP API (only Chrome on Android has).\n * - `failed`: the browser refused or gave up (no permission, a timeout, an insecure page).\n * - `aborted`: the field was detached before an SMS came.\n */\nexport type WebOtpStatus = 'idle' | 'waiting' | 'received' | 'unsupported' | 'failed' | 'aborted';\n\nexport type WebOtpResult = { readonly status: 'received'; readonly code: string } | { readonly status: 'unsupported' | 'failed' };\n\n/** The parts of the Credential Management API the WebOTP API adds. */\ninterface OtpCredentials {\n get(options: { readonly otp: { readonly transport: readonly string[] }; readonly signal: AbortSignal }): Promise<{ readonly code?: unknown } | null>;\n}\n\n/** Asks the browser for the code of an SMS sent to this device, until `signal` aborts. Never rejects. */\nexport async function receiveWebOtp(signal: AbortSignal): Promise<WebOtpResult> {\n const credentials = (globalThis as { navigator?: { credentials?: OtpCredentials } }).navigator?.credentials;\n if (typeof (globalThis as { OTPCredential?: unknown }).OTPCredential === 'undefined' || credentials === undefined) return { status: 'unsupported' };\n try {\n const credential = await credentials.get({ otp: { transport: ['sms'] }, signal });\n return typeof credential?.code === 'string' ? { status: 'received', code: credential.code } : { status: 'failed' };\n } catch {\n return { status: 'failed' };\n }\n}\n","import { copyFailure } from '../core/errors';\nimport { emptyChars, inputStep, keyStep, pasteStep, setStep, type OtpKey, type OtpSettings, type OtpStep } from './state';\nimport type { OtpAlphabet } from './normalize';\nimport { receiveWebOtp, type WebOtpStatus } from './web-otp';\n\nexport interface OtpFieldOptions {\n /** How many characters the code has: one box each. Default 6. */\n readonly length?: number;\n /** Default `'numeric'`. */\n readonly alphabet?: OtpAlphabet;\n /**\n * Each box's accessible name. Default `Digit 1 of 6` (`Character 1 of 6` for alphanumeric\n * codes). Name the group around the boxes too (`role=\"group\"` with a label).\n */\n readonly label?: (index: number, length: number) => string;\n /**\n * Fill the code from an SMS with the WebOTP API, where the browser has it (Chrome on\n * Android): the message must end with `@your.host #code`. Asked for when the boxes are\n * attached; cancelled when they are detached, or when the code is typed. Default `false`.\n */\n readonly webOtp?: boolean;\n /** Called when the value changes. */\n readonly onChange?: (snapshot: OtpSnapshot) => void;\n /** Called when every box is filled, with the code. Again after an edit fills them anew. */\n readonly onComplete?: (code: string) => void;\n}\n\nexport interface OtpSnapshot {\n /** Each box's character: `''` for an empty box. */\n readonly chars: readonly string[];\n /** The characters typed so far, in order, without gaps. */\n readonly value: string;\n /** Every box holds a character: `value` is the code. */\n readonly complete: boolean;\n /** Where filling the code from an SMS stands. `idle` unless `webOtp` is on. */\n readonly webOtp: WebOtpStatus;\n}\n\n/** The field's functions are bound: pass them around freely (`onClick={field.clear}`). */\nexport interface OtpField {\n /**\n * Wires up the boxes (one `<input>` each, in order): their typing, pasting, autofill,\n * keys, focus and attributes. Returns a function that undoes it. Boxes are wired to one\n * field at a time: attaching again first detaches the previous boxes.\n */\n readonly attach: (inputs: readonly HTMLInputElement[]) => () => void;\n /** The current state. A new object after each change, the same one otherwise. */\n readonly getSnapshot: () => OtpSnapshot;\n /** Calls `listener` after each change. Returns a function that stops it. */\n readonly subscribe: (listener: () => void) => () => void;\n /** Fills the boxes with `code` from the first (characters a code can't have are dropped). */\n readonly setValue: (code: string) => void;\n /** Empties every box and focuses the first. */\n readonly clear: () => void;\n /** Focuses the first empty box (or the last, when all are filled). */\n readonly focus: () => void;\n}\n\nconst KEYS: ReadonlySet<string> = new Set<OtpKey>(['Backspace', 'Delete', 'ArrowLeft', 'ArrowRight', 'Home', 'End']);\n\n/**\n * A one-time code field over a row of single-character boxes, without a framework:\n * typing moves to the next box, Backspace to the one before; pasting a code, or an SMS\n * holding one, fills every box from any of them; an SMS autofill into the first box\n * (iOS, Android) fills them all. `useOtpField` is this, for React.\n *\n * @throws {CopyFailure} `invalid-payload` for a `length` that is not 1 to 32.\n */\nexport function createOtpField(options: OtpFieldOptions = {}): OtpField {\n const length = options.length ?? 6;\n if (!Number.isInteger(length) || length < 1 || length > 32) throw copyFailure('invalid-payload', 'length must be a whole number from 1 to 32.');\n const settings: OtpSettings = { length, alphabet: options.alphabet ?? 'numeric' };\n const listeners = new Set<() => void>();\n let snapshot: OtpSnapshot = { chars: emptyChars(length), value: '', complete: false, webOtp: 'idle' };\n let boxes: readonly HTMLInputElement[] = [];\n let detach: (() => void) | null = null;\n let webOtpAbort: AbortController | null = null;\n\n /** Stops waiting for an SMS, with how it ended. */\n function stopWebOtp(status: WebOtpStatus): void {\n if (webOtpAbort === null) return;\n webOtpAbort.abort();\n webOtpAbort = null;\n publish({ ...snapshot, webOtp: status });\n }\n\n function publish(next: OtpSnapshot): void {\n snapshot = next;\n options.onChange?.(next);\n for (const listener of [...listeners]) listener();\n }\n\n function render(step: OtpStep, focus: boolean): void {\n boxes.forEach((box, index) => {\n const char = step.chars[index] as string;\n if (box.value !== char) box.value = char;\n });\n if (focus) {\n const box = boxes[step.focus];\n box?.focus();\n box?.select();\n }\n const same = step.chars.every((char, index) => char === snapshot.chars[index]);\n if (same) return;\n const value = step.chars.join('');\n const complete = step.chars.every((char) => char !== '');\n publish({ ...snapshot, chars: step.chars, value, complete });\n // Only a change gets here: a complete field's code is a new one.\n if (complete) {\n // The code is in: an SMS that comes later must not replace it.\n stopWebOtp('aborted');\n options.onComplete?.(value);\n }\n }\n\n function wire(inputs: readonly HTMLInputElement[]): () => void {\n const stops: (() => void)[] = [];\n const on = <K extends keyof HTMLElementEventMap>(target: HTMLInputElement, type: K, handler: (event: HTMLElementEventMap[K]) => void): void => {\n target.addEventListener(type, handler);\n stops.push(() => {\n target.removeEventListener(type, handler);\n });\n };\n const label = options.label ?? ((index: number, total: number) => `${settings.alphabet === 'numeric' ? 'Digit' : 'Character'} ${String(index + 1)} of ${String(total)}`);\n inputs.forEach((input, index) => {\n const restore = ['autocomplete', 'inputmode', 'aria-label', 'autocapitalize', 'spellcheck', 'pattern'].map((name) => [name, input.getAttribute(name)] as const);\n stops.push(() => {\n for (const [name, value] of restore) {\n if (value === null) input.removeAttribute(name);\n else input.setAttribute(name, value);\n }\n });\n // Only the first box takes the SMS autofill: browsers put the whole code there.\n input.setAttribute('autocomplete', index === 0 ? 'one-time-code' : 'off');\n input.setAttribute('inputmode', settings.alphabet === 'numeric' ? 'numeric' : 'text');\n input.setAttribute('aria-label', label(index, length));\n input.setAttribute('autocapitalize', settings.alphabet === 'numeric' ? 'off' : 'characters');\n input.setAttribute('spellcheck', 'false');\n if (settings.alphabet === 'numeric') input.setAttribute('pattern', '[0-9]*');\n else input.removeAttribute('pattern');\n input.value = snapshot.chars[index] as string;\n\n // Selecting the box's character on focus makes typing replace it.\n on(input, 'focus', () => {\n input.select();\n });\n on(input, 'keydown', (event) => {\n if (!KEYS.has(event.key) || event.altKey || event.ctrlKey || event.metaKey) return;\n event.preventDefault();\n render(keyStep(snapshot.chars, index, event.key as OtpKey, settings), true);\n });\n on(input, 'beforeinput', (event) => {\n // A delete in an empty box (soft keyboards send no Backspace key): go back, as Backspace does.\n if (event.inputType.startsWith('delete') && input.value === '') {\n event.preventDefault();\n render(keyStep(snapshot.chars, index, 'Backspace', settings), true);\n }\n });\n on(input, 'input', () => {\n // The box showed its character in `snapshot` until this input: that is what was there before.\n render(inputStep(snapshot.chars, index, snapshot.chars[index] as string, input.value, settings), true);\n });\n on(input, 'paste', (event) => {\n event.preventDefault();\n const text = event.clipboardData?.getData('text/plain') ?? '';\n render(pasteStep(snapshot.chars, index, text, settings), true);\n });\n });\n\n if (options.webOtp === true && !snapshot.complete) {\n const abort = new AbortController();\n webOtpAbort = abort;\n publish({ ...snapshot, webOtp: 'waiting' });\n void receiveWebOtp(abort.signal).then((result) => {\n if (abort.signal.aborted) return;\n webOtpAbort = null;\n if (result.status === 'received') render(setStep(result.code, settings), false);\n publish({ ...snapshot, webOtp: result.status });\n });\n }\n return () => {\n for (const stop of stops) stop();\n stopWebOtp('aborted');\n };\n }\n\n const field: OtpField = {\n attach: (inputs) => {\n detach?.();\n boxes = [...inputs];\n const undo = wire(boxes);\n let attached = true;\n detach = () => {\n if (!attached) return;\n attached = false;\n undo();\n boxes = [];\n detach = null;\n };\n return detach;\n },\n getSnapshot: () => snapshot,\n subscribe: (listener) => {\n listeners.add(listener);\n return () => {\n listeners.delete(listener);\n };\n },\n setValue: (code) => {\n render(setStep(code, settings), false);\n },\n clear: () => {\n render({ chars: emptyChars(length), focus: 0 }, true);\n },\n focus: () => {\n const empty = snapshot.chars.indexOf('');\n boxes[empty === -1 ? length - 1 : empty]?.focus();\n },\n };\n return field;\n}\n"],"mappings":";;;;;;;;AAQA,MAAM,QAA2B;CAC/B;CAAQ;CAAQ;CAAQ;CAAQ;CAAQ;CAAQ;CAAQ;CAAQ;CAAQ;CAAQ;CAAQ;CAAQ;CAAQ;CAAQ;CAAQ;AAC1H;;AAGA,SAAS,WAAW,MAAsB;CACxC,MAAM,OAAO,KAAK,WAAW,CAAC;CAC9B,KAAK,MAAM,QAAQ,OACjB,IAAI,QAAQ,QAAQ,QAAQ,OAAO,GAAG,OAAO,OAAO,OAAO,IAAI;CAEjE,OAAO;AACT;;;;;;AAOA,SAAgB,iBAAiB,MAAc,UAA+B;CAC5E,MAAM,QAAQ,KAAK,UAAU,MAAM,CAAC,CAAC,QAAQ,oBAAoB,UAAU;CAC3E,OAAO,aAAa,iBAAiB,MAAM,YAAY,IAAI;AAC7D;;AAGA,SAAgB,UAAU,MAAc,UAAgC;CACtE,OAAO,aAAa,YAAY,QAAQ,OAAO,QAAQ,OAAO,KAAK,WAAW,IAAI,aAAa,KAAK,IAAI;AAC1G;;AAGA,SAAgB,SAAS,MAAc,UAAiC;CACtE,OAAO,MAAM,KAAK,iBAAiB,MAAM,QAAQ,CAAC,CAAC,CAAC,QAAQ,SAAS,UAAU,MAAM,QAAQ,CAAC;AAChG;;;;ACnCA,MAAa,kBAAkB;AAyC/B,SAAS,QAAQ,QAA4C;CAC3D,MAAM,QAAQ,OAAO,WAAW,WAAW;EAAE,KAAK;EAAQ,KAAK;CAAO,IAAK,UAAU;EAAE,KA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O;EAhCL,SAAS,WAAW;GAClB,SAAS;GACT,QAAQ,CAAC,GAAG,MAAM;GAClB,MAAM,OAAO,KAAK,KAAK;GACvB,IAAI,WAAW;GACf,eAAe;IACb,IAAI,CAAC,UAAU;IACf,WAAW;IACX,KAAK;IACL,QAAQ,CAAC;IACT,SAAS;GACX;GACA,OAAO;EACT;EACA,mBAAmB;EACnB,YAAY,aAAa;GACvB,UAAU,IAAI,QAAQ;GACtB,aAAa;IACX,UAAU,OAAO,QAAQ;GAC3B;EACF;EACA,WAAW,SAAS;GAClB,OAAO,QAAQ,MAAM,QAAQ,GAAG,KAAK;EACvC;EACA,aAAa;GACX,OAAO;IAAE,OAAO,WAAW,MAAM;IAAG,OAAO;GAAE,GAAG,IAAI;EACtD;EACA,aAAa;GACX,MAAM,QAAQ,SAAS,MAAM,QAAQ,EAAE;GACvC,MAAM,UAAU,KAAK,SAAS,IAAI,MAAM,EAAE,MAAM;EAClD;CAES;AACb"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"field-NaDdWy_5.cjs","names":["copyFailure","copyFailure"],"sources":["../../src/otp/normalize.ts","../../src/otp/extract.ts","../../src/otp/state.ts","../../src/otp/web-otp.ts","../../src/otp/field.ts"],"sourcesContent":["/** What a one-time code is made of. */\nexport type OtpAlphabet = 'numeric' | 'alphanumeric';\n\n/**\n * Code points of zero in the decimal digit sets people receive codes in: Arabic-Indic,\n * Persian, Devanagari, Bengali, Gurmukhi, Gujarati, Oriya, Tamil, Telugu, Kannada,\n * Malayalam, Thai, Lao, Tibetan, Myanmar and Khmer. Full-width digits are handled by NFKC.\n */\nconst ZEROS: readonly number[] = [\n 0x0660, 0x06f0, 0x0966, 0x09e6, 0x0a66, 0x0ae6, 0x0b66, 0x0be6, 0x0c66, 0x0ce6, 0x0d66, 0x0e50, 0x0ed0, 0x0f20, 0x1040, 0x17e0,\n];\n\n/** `char` as an ASCII digit, when it is a digit of one of {@link ZEROS}' sets. */\nfunction asciiDigit(char: string): string {\n const code = char.charCodeAt(0);\n for (const zero of ZEROS) {\n if (code >= zero && code <= zero + 9) return String(code - zero);\n }\n return char;\n}\n\n/**\n * `text` with its digits in ASCII and, for alphanumeric codes, its letters in upper case:\n * full-width digits and letters, and Arabic-Indic, Devanagari and other scripts' digits,\n * become ASCII. Other characters are kept: callers decide what to drop.\n */\nexport function normalizeOtpText(text: string, alphabet: OtpAlphabet): string {\n const ascii = text.normalize('NFKC').replace(/[\\u0080-\\uffff]/g, asciiDigit);\n return alphabet === 'alphanumeric' ? ascii.toUpperCase() : ascii;\n}\n\n/** Whether `char` (already normalized) can be part of a code. */\nexport function isOtpChar(char: string, alphabet: OtpAlphabet): boolean {\n return alphabet === 'numeric' ? char >= '0' && char <= '9' && char.length === 1 : /^[0-9A-Z]$/.test(char);\n}\n\n/** The characters of `text` that can be part of a code, normalized, in order. */\nexport function otpChars(text: string, alphabet: OtpAlphabet): string[] {\n return Array.from(normalizeOtpText(text, alphabet)).filter((char) => isOtpChar(char, alphabet));\n}\n","import { copyFailure } from '../core/errors';\nimport { normalizeOtpText, type OtpAlphabet } from './normalize';\n\n/** Text past this many characters is not read: a code is near the start of a message. */\nexport const OTP_SCAN_LENGTH = 100_000;\n\nexport interface ExtractOtpOptions {\n /** The code's length, or its range. Default 4 to 8. */\n readonly length?: number | { readonly min: number; readonly max: number };\n /** Default `'numeric'`. Alphanumeric codes are upper case: pasted letters are made so. */\n readonly alphabet?: OtpAlphabet;\n /**\n * Your site's host name, as in `example.com`. An origin-bound message (`@example.com #123456`,\n * the format the WebOTP API reads) for another host gives no code: it was not meant for you.\n */\n readonly domain?: string;\n}\n\n/**\n * Where the code was found.\n *\n * - `whole-text`: the text is the code (`482913`, `482 913`, `482-913`).\n * - `origin-bound`: the message's last line binds it to a site (`@example.com #482913`).\n * - `keyword`: next to a word such as \"code\", \"OTP\", \"verification\" or \"PIN\", in any of\n * many languages.\n * - `only-candidate`: the only number of the right length that is not a price, a date, a\n * time, a phone number or an order number.\n */\nexport type OtpSource = 'whole-text' | 'origin-bound' | 'keyword' | 'only-candidate';\n\nexport interface OtpMatch {\n /** The code: ASCII digits (and upper-case letters, for alphanumeric codes), no separators. */\n readonly code: string;\n readonly source: OtpSource;\n /** `medium` for `only-candidate`; `high` otherwise. */\n readonly confidence: 'high' | 'medium';\n /** The site an origin-bound message names; `null` otherwise. */\n readonly domain: string | null;\n}\n\ninterface Range {\n readonly min: number;\n readonly max: number;\n}\n\nfunction rangeOf(length: ExtractOtpOptions['length']): Range {\n const range = typeof length === 'number' ? { min: length, max: length } : (length ?? { min: 4, max: 8 });\n const valid = (value: number): boolean => Number.isInteger(value) && value >= 1 && value <= 32;\n if (!valid(range.min) || !valid(range.max) || range.min > range.max) {\n throw copyFailure('invalid-payload', 'length must be a whole number from 1 to 32, or a range of them.');\n }\n return range;\n}\n\n/**\n * Words next to a one-time code, lower case: English, Hindi, Spanish, Portuguese, French,\n * German, Italian, Dutch, Indonesian, Turkish, Polish, Russian, Ukrainian, Arabic, Hebrew,\n * Persian, Chinese, Japanese, Korean, Vietnamese and Thai.\n */\nconst KEYWORDS: readonly string[] = [\n 'code', 'otp', 'one-time', 'one time', 'passcode', 'password', 'pin', 'verification', 'verify', 'security', 'login', 'log in',\n 'sign-in', 'sign in', '2fa', 'two-factor', 'authentication', 'token',\n '\\u0913\\u091F\\u0940\\u092A\\u0940', '\\u0915\\u094B\\u0921', '\\u0938\\u0924\\u094D\\u092F\\u093E\\u092A\\u0928',\n 'c\\u00F3digo', 'codigo', 'clave', 'contrase\\u00F1a', 'senha', 'mot de passe', 'v\\u00E9rification', 'best\\u00E4tigungscode',\n 'kennwort', 'codice', 'verificatie', 'kode', 'kod', 'do\\u011Frulama', 'weryfikacyjny',\n '\\u043A\\u043E\\u0434', '\\u043F\\u0430\\u0440\\u043E\\u043B\\u044C', '\\u0440\\u0430\\u0437\\u043E\\u0432\\u044B\\u0439',\n '\\u0631\\u0645\\u0632', '\\u0643\\u0648\\u062F', '\\u0627\\u0644\\u062A\\u062D\\u0642\\u0642', '\\u05E7\\u05D5\\u05D3', '\\u06A9\\u062F',\n '\\u9A8C\\u8BC1\\u7801', '\\u9A57\\u8B49\\u78BC', '\\u6821\\u9A8C\\u7801', '\\u52D5\\u614B\\u78BC', '\\u8A8D\\u8A3C\\u30B3\\u30FC\\u30C9',\n '\\u78BA\\u8A8D\\u30B3\\u30FC\\u30C9', '\\u30EF\\u30F3\\u30BF\\u30A4\\u30E0', '\\u8A8D\\u8A3C\\u756A\\u53F7', '\\uC778\\uC99D\\uBC88\\uD638',\n '\\uC778\\uC99D', '\\uCF54\\uB4DC', 'm\\u00E3', 'x\\u00E1c th\\u1EF1c', '\\u0E23\\u0E2B\\u0E31\\u0E2A',\n];\n\n/** Codes that are not one-time codes, right before a number: postal codes, coupons, orders. */\nconst NOT_OTP = /(?:pin ?code|zip|postal|post code|promo|coupon|discount|voucher|referral|order|invoice|ref\\.?|account|a\\/c|flight|pnr|room|tracking)[\\s:#.-]{0,4}$/;\n\n/** Currencies and units around a number: it is an amount, not a code. */\nconst CURRENCY_BEFORE = /(?:[$\\u20AC\\u00A3\\u20B9\\u00A5\\u20A9\\u20BD\\u00A2]|\\brs\\.?|\\binr|\\busd|\\beur|\\bgbp)\\s?$/;\nconst AMOUNT_AFTER = /^\\s?(?:%|[$\\u20AC\\u00A3\\u20B9\\u00A5]|inr\\b|usd\\b|eur\\b|rs\\b|rupees\\b|dollars\\b|euros\\b)/;\n\nconst NUMERIC = /(^|[^\\p{L}\\p{N}_])(\\d{2,4}(?:[ -]\\d{2,4}){1,3}|\\d{1,12})(?![\\p{L}\\p{N}_])/gu;\nconst ALPHANUMERIC = /(^|[^\\p{L}\\p{N}_])([A-Z0-9]{2,6}(?:-[A-Z0-9]{2,6}){1,3}|[A-Z0-9]{1,12})(?![\\p{L}\\p{N}_])/gu;\n\nconst isDigit = (char: string | undefined): boolean => char !== undefined && char >= '0' && char <= '9';\n\n/**\n * Whether the number at `start`-`end` is something else: part of a longer number (a phone\n * number), a date, a time or a decimal, an amount, an order or reference number, or inside\n * a URL or an e-mail address.\n */\nfunction excluded(text: string, lower: string, start: number, end: number): boolean {\n const before = text[start - 1];\n const after = text[end];\n if ((before === ' ' || before === '-') && isDigit(text[start - 2])) return true;\n if ((after === ' ' || after === '-') && isDigit(text[end + 1])) return true;\n // A time, a date, a decimal or a version (`10:30`, `23/10`, `3.14`), and thousands (`2,500`).\n if (before !== undefined && ':/.'.includes(before) && isDigit(text[start - 2])) return true;\n if (after !== undefined && ':/.'.includes(after) && isDigit(text[end + 1])) return true;\n if ((before === ',' && isDigit(text[start - 2]) && /^\\d{3}(?!\\d)/.test(text.slice(start, start + 4))) || /^,\\d{3}(?!\\d)/.test(text.slice(end, end + 5))) return true;\n if (before === '+' || before === '#' || before === '(' || (before === ' ' && text[start - 2] === ')')) return true;\n const head = lower.slice(Math.max(0, start - 24), start);\n if (CURRENCY_BEFORE.test(head) || NOT_OTP.test(head) || AMOUNT_AFTER.test(lower.slice(end, end + 10))) return true;\n // The word around it, between white space (up to 256 characters each way, so a scan stays\n // linear): a URL, with a scheme or a bare host and path (`example.com/t/48291`), or an\n // e-mail address holds no code.\n let from = start;\n while (from > Math.max(0, start - 256) && !/\\s/.test(text[from - 1] as string)) from -= 1;\n let to = end;\n while (to < Math.min(text.length, end + 256) && !/\\s/.test(text[to] as string)) to += 1;\n return /@|:\\/\\/|www\\.|[\\p{L}\\p{N}-]\\.\\p{L}{2,}\\//iu.test(text.slice(from, to));\n}\n\n/** Lower case, one character for one: positions in it are positions in `text`. */\nfunction lowerSameLength(text: string): string {\n let out = '';\n for (const char of text) {\n const lower = char.toLowerCase();\n out += lower.length === char.length ? lower : char;\n }\n return out;\n}\n\n/** The distance from the number at `start`-`end` to the nearest keyword: words before count closer. */\nfunction keywordDistance(lower: string, start: number, end: number): number {\n let best = Infinity;\n const window = lower.slice(Math.max(0, start - 60), Math.min(lower.length, end + 40));\n const offset = Math.max(0, start - 60);\n for (const keyword of KEYWORDS) {\n // Words in Latin script count only as whole words: `pin` is not in `spinning`.\n const whole = /^[a-z0-9 -]+$/.test(keyword);\n for (let at = window.indexOf(keyword); at !== -1; at = window.indexOf(keyword, at + 1)) {\n if (whole && (/[a-z]/.test(window[at - 1] ?? '') || /[a-z]/.test(window[at + keyword.length] ?? ''))) continue;\n const from = at + offset;\n const to = from + keyword.length;\n // A keyword inside the number itself (as in `otp` of an alphanumeric code) does not count.\n if (to <= start) best = Math.min(best, start - to);\n else if (from >= end) best = Math.min(best, from - end + 10);\n }\n }\n return best;\n}\n\n/** The origin-bound line of the WebOTP format: `@host #code`, last in the message. */\nconst ORIGIN_BOUND = /(?:^|\\n)@([a-z0-9.-]{1,253}(?::\\d{1,5})?) #([A-Za-z0-9]{1,32})(?: @[a-z0-9.-]{1,253}(?::\\d{1,5})?)?[ \\t]*$/i;\n\n/**\n * The one-time code in `text`: an SMS or e-mail people paste, or a code they copied. Digits\n * of any script and full-width characters are read as ASCII, and separators are dropped\n * (`482 913`, `482-913`).\n *\n * Prices, dates, times, phone numbers, order numbers and postal codes are never taken for a\n * code. When several numbers could be the code and no keyword points at one, the result is\n * `null`: guessing would fill in a wrong code.\n *\n * @throws {CopyFailure} `invalid-payload` for a `length` that is not 1 to 32, or a reversed range.\n */\nexport function extractOtp(text: string, options: ExtractOtpOptions = {}): OtpMatch | null {\n const range = rangeOf(options.length);\n const alphabet = options.alphabet ?? 'numeric';\n const fits = (code: string): boolean => code.length >= range.min && code.length <= range.max && (alphabet === 'alphanumeric' || /^\\d+$/.test(code));\n const normalized = normalizeOtpText(text.slice(0, OTP_SCAN_LENGTH), alphabet);\n\n // The text is the code itself.\n const whole = normalized.trim();\n if (/^[0-9A-Z]{1,32}(?:[ -][0-9A-Z]{1,32}){0,7}$/.test(whole)) {\n const code = whole.replace(/[ -]/g, '');\n if (fits(code)) return { code, source: 'whole-text', confidence: 'high', domain: null };\n }\n\n // A message bound to a site, in the format the WebOTP API reads.\n // Read with its case kept: host names are lower case, and an alphanumeric code is upper-cased after.\n const bound = ORIGIN_BOUND.exec(normalizeOtpText(text.slice(0, OTP_SCAN_LENGTH), 'numeric').trimEnd());\n if (bound !== null) {\n const domain = (bound[1] as string).toLowerCase();\n const code = (bound[2] as string).toUpperCase();\n if (options.domain !== undefined && options.domain.toLowerCase() !== domain) return null;\n if (fits(code)) return { code, source: 'origin-bound', confidence: 'high', domain };\n }\n\n const lower = lowerSameLength(normalized);\n const pattern = alphabet === 'numeric' ? NUMERIC : ALPHANUMERIC;\n const candidates: { readonly code: string; readonly distance: number }[] = [];\n for (const match of normalized.matchAll(pattern)) {\n const raw = match[2] as string;\n const start = match.index + (match[1] as string).length;\n const code = raw.replace(/[ -]/g, '');\n if (!fits(code) || (alphabet === 'alphanumeric' && !/\\d/.test(code)) || excluded(normalized, lower, start, start + raw.length)) continue;\n candidates.push({ code, distance: keywordDistance(lower, start, start + raw.length) });\n }\n const near = candidates.filter((candidate) => candidate.distance <= 60);\n if (near.length > 0) {\n const best = near.reduce((a, b) => (b.distance < a.distance ? b : a));\n return { code: best.code, source: 'keyword', confidence: 'high', domain: null };\n }\n const distinct = new Set(candidates.map((candidate) => candidate.code));\n return distinct.size === 1 ? { code: [...distinct][0] as string, source: 'only-candidate', confidence: 'medium', domain: null } : null;\n}\n","import { extractOtp } from './extract';\nimport { otpChars, type OtpAlphabet } from './normalize';\n\n/** The characters in each box ('' for an empty one), and the box to focus next. */\nexport interface OtpStep {\n readonly chars: readonly string[];\n /** The box to focus after the change. */\n readonly focus: number;\n}\n\nexport interface OtpSettings {\n readonly length: number;\n readonly alphabet: OtpAlphabet;\n}\n\n/** Keys a code field handles itself. */\nexport type OtpKey = 'Backspace' | 'Delete' | 'ArrowLeft' | 'ArrowRight' | 'Home' | 'End';\n\nexport const emptyChars = (length: number): readonly string[] => Array.from({ length }, () => '');\n\nconst clamp = (index: number, length: number): number => Math.min(Math.max(index, 0), length - 1);\n\n/** `chars` with `text`'s characters written from `index` on, as far as they fit. */\nfunction write(chars: readonly string[], index: number, text: readonly string[], settings: OtpSettings): OtpStep {\n const next = [...chars];\n // A whole code (an SMS autofill into one box, a paste) fills the field from the start.\n const from = text.length >= settings.length ? 0 : clamp(index, settings.length);\n const count = Math.min(text.length, settings.length - from);\n for (let offset = 0; offset < count; offset += 1) next[from + offset] = text[offset] as string;\n return { chars: next, focus: clamp(from + count, settings.length) };\n}\n\n/**\n * What typing (or an autofill, or an input method) does to box `index`, whose value went\n * from `previous` to `value`. A character typed next to the one already there replaces it;\n * several characters fill the boxes after it; characters a code can't have are ignored.\n */\nexport function inputStep(chars: readonly string[], index: number, previous: string, value: string, settings: OtpSettings): OtpStep {\n let typed = value;\n // One character added beside the one the box held: the new one is what was typed.\n if (previous !== '' && value.length === previous.length + 1) {\n if (value.startsWith(previous)) typed = value.slice(previous.length);\n else if (value.endsWith(previous)) typed = value.slice(0, value.length - previous.length);\n }\n const text = otpChars(typed, settings.alphabet);\n if (text.length > 0) return write(chars, index, text, settings);\n if (value === '') {\n // The box was emptied (a cut, or a delete the browser did itself).\n const next = [...chars];\n next[index] = '';\n return { chars: next, focus: index };\n }\n return { chars, focus: index };\n}\n\n/** What pasting `text` into box `index` does: the code in it fills the field, wherever it is pasted. */\nexport function pasteStep(chars: readonly string[], index: number, text: string, settings: OtpSettings): OtpStep {\n const match = extractOtp(text, { length: settings.length, alphabet: settings.alphabet });\n if (match !== null) return write(chars, 0, Array.from(match.code), settings);\n const typed = otpChars(text, settings.alphabet);\n return typed.length > 0 && typed.length < settings.length ? write(chars, index, typed, settings) : { chars, focus: index };\n}\n\n/** What a navigation or deletion key does in box `index`. */\nexport function keyStep(chars: readonly string[], index: number, key: OtpKey, settings: OtpSettings): OtpStep {\n const last = settings.length - 1;\n switch (key) {\n case 'Backspace': {\n const next = [...chars];\n // An empty box: the one before it is cleared, as if the cursor were between them.\n const target = chars[index] === '' ? Math.max(0, index - 1) : index;\n next[target] = '';\n return { chars: next, focus: target };\n }\n case 'Delete': {\n const next = [...chars];\n next[index] = '';\n return { chars: next, focus: index };\n }\n case 'ArrowLeft':\n return { chars, focus: Math.max(0, index - 1) };\n case 'ArrowRight':\n return { chars, focus: Math.min(last, index + 1) };\n case 'Home':\n return { chars, focus: 0 };\n case 'End': {\n const empty = chars.indexOf('');\n return { chars, focus: empty === -1 ? last : empty };\n }\n }\n}\n\n/** A whole code set at once (from WebOTP, or by the app): its characters from the first box. */\nexport function setStep(code: string, settings: OtpSettings): OtpStep {\n return write(emptyChars(settings.length), 0, otpChars(code, settings.alphabet).slice(0, settings.length), settings);\n}\n","/**\n * Where filling a code from an SMS (the WebOTP API) stands.\n *\n * - `idle`: not asked for.\n * - `waiting`: the browser is waiting for an SMS that ends with `@your.host #code`.\n * - `received`: it came, and filled the field.\n * - `unsupported`: this browser has no WebOTP API (only Chrome on Android has).\n * - `failed`: the browser refused or gave up (no permission, a timeout, an insecure page).\n * - `aborted`: the field was detached before an SMS came.\n */\nexport type WebOtpStatus = 'idle' | 'waiting' | 'received' | 'unsupported' | 'failed' | 'aborted';\n\nexport type WebOtpResult = { readonly status: 'received'; readonly code: string } | { readonly status: 'unsupported' | 'failed' };\n\n/** The parts of the Credential Management API the WebOTP API adds. */\ninterface OtpCredentials {\n get(options: { readonly otp: { readonly transport: readonly string[] }; readonly signal: AbortSignal }): Promise<{ readonly code?: unknown } | null>;\n}\n\n/** Asks the browser for the code of an SMS sent to this device, until `signal` aborts. Never rejects. */\nexport async function receiveWebOtp(signal: AbortSignal): Promise<WebOtpResult> {\n const credentials = (globalThis as { navigator?: { credentials?: OtpCredentials } }).navigator?.credentials;\n if (typeof (globalThis as { OTPCredential?: unknown }).OTPCredential === 'undefined' || credentials === undefined) return { status: 'unsupported' };\n try {\n const credential = await credentials.get({ otp: { transport: ['sms'] }, signal });\n return typeof credential?.code === 'string' ? { status: 'received', code: credential.code } : { status: 'failed' };\n } catch {\n return { status: 'failed' };\n }\n}\n","import { copyFailure } from '../core/errors';\nimport { emptyChars, inputStep, keyStep, pasteStep, setStep, type OtpKey, type OtpSettings, type OtpStep } from './state';\nimport type { OtpAlphabet } from './normalize';\nimport { receiveWebOtp, type WebOtpStatus } from './web-otp';\n\nexport interface OtpFieldOptions {\n /** How many characters the code has: one box each. Default 6. */\n readonly length?: number;\n /** Default `'numeric'`. */\n readonly alphabet?: OtpAlphabet;\n /**\n * Each box's accessible name. Default `Digit 1 of 6` (`Character 1 of 6` for alphanumeric\n * codes). Name the group around the boxes too (`role=\"group\"` with a label).\n */\n readonly label?: (index: number, length: number) => string;\n /**\n * Fill the code from an SMS with the WebOTP API, where the browser has it (Chrome on\n * Android): the message must end with `@your.host #code`. Asked for when the boxes are\n * attached; cancelled when they are detached, or when the code is typed. Default `false`.\n */\n readonly webOtp?: boolean;\n /** Called when the value changes. */\n readonly onChange?: (snapshot: OtpSnapshot) => void;\n /** Called when every box is filled, with the code. Again after an edit fills them anew. */\n readonly onComplete?: (code: string) => void;\n}\n\nexport interface OtpSnapshot {\n /** Each box's character: `''` for an empty box. */\n readonly chars: readonly string[];\n /** The characters typed so far, in order, without gaps. */\n readonly value: string;\n /** Every box holds a character: `value` is the code. */\n readonly complete: boolean;\n /** Where filling the code from an SMS stands. `idle` unless `webOtp` is on. */\n readonly webOtp: WebOtpStatus;\n}\n\n/** The field's functions are bound: pass them around freely (`onClick={field.clear}`). */\nexport interface OtpField {\n /**\n * Wires up the boxes (one `<input>` each, in order): their typing, pasting, autofill,\n * keys, focus and attributes. Returns a function that undoes it. Boxes are wired to one\n * field at a time: attaching again first detaches the previous boxes.\n */\n readonly attach: (inputs: readonly HTMLInputElement[]) => () => void;\n /** The current state. A new object after each change, the same one otherwise. */\n readonly getSnapshot: () => OtpSnapshot;\n /** Calls `listener` after each change. Returns a function that stops it. */\n readonly subscribe: (listener: () => void) => () => void;\n /** Fills the boxes with `code` from the first (characters a code can't have are dropped). */\n readonly setValue: (code: string) => void;\n /** Empties every box and focuses the first. */\n readonly clear: () => void;\n /** Focuses the first empty box (or the last, when all are filled). */\n readonly focus: () => void;\n}\n\nconst KEYS: ReadonlySet<string> = new Set<OtpKey>(['Backspace', 'Delete', 'ArrowLeft', 'ArrowRight', 'Home', 'End']);\n\n/**\n * A one-time code field over a row of single-character boxes, without a framework:\n * typing moves to the next box, Backspace to the one before; pasting a code, or an SMS\n * holding one, fills every box from any of them; an SMS autofill into the first box\n * (iOS, Android) fills them all. `useOtpField` is this, for React.\n *\n * @throws {CopyFailure} `invalid-payload` for a `length` that is not 1 to 32.\n */\nexport function createOtpField(options: OtpFieldOptions = {}): OtpField {\n const length = options.length ?? 6;\n if (!Number.isInteger(length) || length < 1 || length > 32) throw copyFailure('invalid-payload', 'length must be a whole number from 1 to 32.');\n const settings: OtpSettings = { length, alphabet: options.alphabet ?? 'numeric' };\n const listeners = new Set<() => void>();\n let snapshot: OtpSnapshot = { chars: emptyChars(length), value: '', complete: false, webOtp: 'idle' };\n let boxes: readonly HTMLInputElement[] = [];\n let detach: (() => void) | null = null;\n let webOtpAbort: AbortController | null = null;\n\n /** Stops waiting for an SMS, with how it ended. */\n function stopWebOtp(status: WebOtpStatus): void {\n if (webOtpAbort === null) return;\n webOtpAbort.abort();\n webOtpAbort = null;\n publish({ ...snapshot, webOtp: status });\n }\n\n function publish(next: OtpSnapshot): void {\n snapshot = next;\n options.onChange?.(next);\n for (const listener of [...listeners]) listener();\n }\n\n function render(step: OtpStep, focus: boolean): void {\n boxes.forEach((box, index) => {\n const char = step.chars[index] as string;\n if (box.value !== char) box.value = char;\n });\n if (focus) {\n const box = boxes[step.focus];\n box?.focus();\n box?.select();\n }\n const same = step.chars.every((char, index) => char === snapshot.chars[index]);\n if (same) return;\n const value = step.chars.join('');\n const complete = step.chars.every((char) => char !== '');\n publish({ ...snapshot, chars: step.chars, value, complete });\n // Only a change gets here: a complete field's code is a new one.\n if (complete) {\n // The code is in: an SMS that comes later must not replace it.\n stopWebOtp('aborted');\n options.onComplete?.(value);\n }\n }\n\n function wire(inputs: readonly HTMLInputElement[]): () => void {\n const stops: (() => void)[] = [];\n const on = <K extends keyof HTMLElementEventMap>(target: HTMLInputElement, type: K, handler: (event: HTMLElementEventMap[K]) => void): void => {\n target.addEventListener(type, handler);\n stops.push(() => {\n target.removeEventListener(type, handler);\n });\n };\n const label = options.label ?? ((index: number, total: number) => `${settings.alphabet === 'numeric' ? 'Digit' : 'Character'} ${String(index + 1)} of ${String(total)}`);\n inputs.forEach((input, index) => {\n const restore = ['autocomplete', 'inputmode', 'aria-label', 'autocapitalize', 'spellcheck', 'pattern'].map((name) => [name, input.getAttribute(name)] as const);\n stops.push(() => {\n for (const [name, value] of restore) {\n if (value === null) input.removeAttribute(name);\n else input.setAttribute(name, value);\n }\n });\n // Only the first box takes the SMS autofill: browsers put the whole code there.\n input.setAttribute('autocomplete', index === 0 ? 'one-time-code' : 'off');\n input.setAttribute('inputmode', settings.alphabet === 'numeric' ? 'numeric' : 'text');\n input.setAttribute('aria-label', label(index, length));\n input.setAttribute('autocapitalize', settings.alphabet === 'numeric' ? 'off' : 'characters');\n input.setAttribute('spellcheck', 'false');\n if (settings.alphabet === 'numeric') input.setAttribute('pattern', '[0-9]*');\n else input.removeAttribute('pattern');\n input.value = snapshot.chars[index] as string;\n\n // Selecting the box's character on focus makes typing replace it.\n on(input, 'focus', () => {\n input.select();\n });\n on(input, 'keydown', (event) => {\n if (!KEYS.has(event.key) || event.altKey || event.ctrlKey || event.metaKey) return;\n event.preventDefault();\n render(keyStep(snapshot.chars, index, event.key as OtpKey, settings), true);\n });\n on(input, 'beforeinput', (event) => {\n // A delete in an empty box (soft keyboards send no Backspace key): go back, as Backspace does.\n if (event.inputType.startsWith('delete') && input.value === '') {\n event.preventDefault();\n render(keyStep(snapshot.chars, index, 'Backspace', settings), true);\n }\n });\n on(input, 'input', () => {\n // The box showed its character in `snapshot` until this input: that is what was there before.\n render(inputStep(snapshot.chars, index, snapshot.chars[index] as string, input.value, settings), true);\n });\n on(input, 'paste', (event) => {\n event.preventDefault();\n const text = event.clipboardData?.getData('text/plain') ?? '';\n render(pasteStep(snapshot.chars, index, text, settings), true);\n });\n });\n\n if (options.webOtp === true && !snapshot.complete) {\n const abort = new AbortController();\n webOtpAbort = abort;\n publish({ ...snapshot, webOtp: 'waiting' });\n void receiveWebOtp(abort.signal).then((result) => {\n if (abort.signal.aborted) return;\n webOtpAbort = null;\n if (result.status === 'received') render(setStep(result.code, settings), false);\n publish({ ...snapshot, webOtp: result.status });\n });\n }\n return () => {\n for (const stop of stops) stop();\n stopWebOtp('aborted');\n };\n }\n\n const field: OtpField = {\n attach: (inputs) => {\n detach?.();\n boxes = [...inputs];\n const undo = wire(boxes);\n let attached = true;\n detach = () => {\n if (!attached) return;\n attached = false;\n undo();\n boxes = [];\n detach = null;\n };\n return detach;\n },\n getSnapshot: () => snapshot,\n subscribe: (listener) => {\n listeners.add(listener);\n return () => {\n listeners.delete(listener);\n };\n },\n setValue: (code) => {\n render(setStep(code, settings), false);\n },\n clear: () => {\n render({ chars: emptyChars(length), focus: 0 }, true);\n },\n focus: () => {\n const empty = snapshot.chars.indexOf('');\n boxes[empty === -1 ? length - 1 : empty]?.focus();\n },\n };\n return field;\n}\n"],"mappings":";;;;;;;;AAQA,MAAM,QAA2B;CAC/B;CAAQ;CAAQ;CAAQ;CAAQ;CAAQ;CAAQ;CAAQ;CAAQ;CAAQ;CAAQ;CAAQ;CAAQ;CAAQ;CAAQ;CAAQ;AAC1H;;AAGA,SAAS,WAAW,MAAsB;CACxC,MAAM,OAAO,KAAK,WAAW,CAAC;CAC9B,KAAK,MAAM,QAAQ,OACjB,IAAI,QAAQ,QAAQ,QAAQ,OAAO,GAAG,OAAO,OAAO,OAAO,IAAI;CAEjE,OAAO;AACT;;;;;;AAOA,SAAgB,iBAAiB,MAAc,UAA+B;CAC5E,MAAM,QAAQ,KAAK,UAAU,MAAM,CAAC,CAAC,QAAQ,oBAAoB,UAAU;CAC3E,OAAO,aAAa,iBAAiB,MAAM,YAAY,IAAI;AAC7D;;AAGA,SAAgB,UAAU,MAAc,UAAgC;CACtE,OAAO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,cAAc;GACd,QAAQ;IAAE,GAAG;IAAU,QAAQ;GAAU,CAAC;GAC1C,cAAmB,MAAM,MAAM,CAAC,CAAC,MAAM,WAAW;IAChD,IAAI,MAAM,OAAO,SAAS;IAC1B,cAAc;IACd,IAAI,OAAO,WAAW,YAAY,OAAO,QAAQ,OAAO,MAAM,QAAQ,GAAG,KAAK;IAC9E,QAAQ;KAAE,GAAG;KAAU,QAAQ,OAAO;IAAO,CAAC;GAChD,CAAC;EACH;EACA,aAAa;GACX,KAAK,MAAM,QAAQ,OAAO,KAAK;GAC/B,WAAW,SAAS;EACtB;CACF;CAmCA,OAAO;EAhCL,SAAS,WAAW;GAClB,SAAS;GACT,QAAQ,CAAC,GAAG,MAAM;GAClB,MAAM,OAAO,KAAK,KAAK;GACvB,IAAI,WAAW;GACf,eAAe;IACb,IAAI,CAAC,UAAU;IACf,WAAW;IACX,KAAK;IACL,QAAQ,CAAC;IACT,SAAS;GACX;GACA,OAAO;EACT;EACA,mBAAmB;EACnB,YAAY,aAAa;GACvB,UAAU,IAAI,QAAQ;GACtB,aAAa;IACX,UAAU,OAAO,QAAQ;GAC3B;EACF;EACA,WAAW,SAAS;GAClB,OAAO,QAAQ,MAAM,QAAQ,GAAG,KAAK;EACvC;EACA,aAAa;GACX,OAAO;IAAE,OAAO,WAAW,MAAM;IAAG,OAAO;GAAE,GAAG,IAAI;EACtD;EACA,aAAa;GACX,MAAM,QAAQ,SAAS,MAAM,QAAQ,EAAE;GACvC,MAAM,UAAU,KAAK,SAAS,IAAI,MAAM,EAAE,MAAM;EAClD;CAES;AACb"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"text-field-Ba8W3v4R.cjs","names":[],"sources":["../../src/core/text-field.ts"],"sourcesContent":["/**\n * Text-field helpers shared by the paste handlers of the opt-in entry points.\n * Internal: not part of `react-smart-copy/core`'s public API.\n */\n\n/** Text fields `setRangeText` and `execCommand('insertText')` both support. */\nexport type TextField = HTMLTextAreaElement | HTMLInputElement;\n\nconst TEXT_INPUTS = new Set(['text', 'search', 'url', 'tel', 'password']);\n\nexport function asTextField(target: EventTarget | null): TextField | null {\n if (typeof target !== 'object' || target === null) return null;\n const element = target as Partial<Element> & { type?: unknown };\n if (element.nodeName === 'TEXTAREA') return target as HTMLTextAreaElement;\n if (element.nodeName === 'INPUT' && typeof element.type === 'string' && TEXT_INPUTS.has(element.type)) return target as HTMLInputElement;\n return null;\n}\n\n/**\n * Inserts text at the cursor of a `<textarea>` or text `<input>`, replacing the\n * selection, as typing or pasting would: the browser's undo (Ctrl/⌘+Z) still\n * works, `input` events fire (so React and other frameworks see the change),\n * and `maxlength` is respected. Returns `false` for disabled or read-only fields.\n */\nexport function insertText(field: TextField, text: string): boolean {\n if (field.disabled || field.readOnly) return false;\n // An <input> holds one line: each run of line breaks (a paragraph break too) becomes one space.\n const value = field.nodeName === 'INPUT' ? text.replace(/[ \\t]*(?:\\r\\n|\\r|\\n)+[ \\t]*/g, ' ') : text;\n const doc = field.ownerDocument;\n field.focus();\n // `null` for inputs without a selection API (email, number): the text is appended.\n const start = field.selectionStart;\n const end = field.selectionEnd;\n try {\n // Re-applying the selection ends the current typing run, so the paste gets its own undo step\n // (as a native paste does) instead of merging with what was typed just before.\n if (start !== null && end !== null) field.setSelectionRange(start, end);\n // The only way to keep the native undo stack; supported for text fields in every current browser.\n // eslint-disable-next-line @typescript-eslint/no-deprecated -- no replacement keeps undo history\n if (doc.activeElement === field && doc.execCommand('insertText', false, value)) return true;\n } catch {\n // Fall through to the manual insertion.\n }\n const from = start ?? field.value.length;\n const to = end ?? from;\n let insert = value;\n if (field.maxLength >= 0) {\n const room = Math.max(0, field.maxLength - (field.value.length - (to - from)));\n insert = insert.slice(0, room);\n // Never leave half of a surrogate pair (an emoji) behind.\n if (/[\\ud800-\\udbff]$/.test(insert)) insert = insert.slice(0, -1);\n }\n if (start === null) setNativeValue(field, field.value + insert);\n else field.setRangeText(insert, from, to, 'end');\n const view = doc.defaultView;\n const event =\n view !== null && typeof view.InputEvent === 'function'\n ? new view.InputEvent('input', { bubbles: true, inputType: 'insertFromPaste', data: insert })\n : new Event('input', { bubbles: true });\n field.dispatchEvent(event);\n return true;\n}\n\n/**\n * Sets a field's value through the prototype's setter. React tracks the value\n * set on the element itself; going around it lets React see the change and\n * call `onChange` for the `input` event that follows.\n */\nfunction setNativeValue(field: TextField, next: string): void {\n const descriptor = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(field) as object, 'value');\n // eslint-disable-next-line @typescript-eslint/unbound-method -- it is called right below with the field as `this`\n const setter = descriptor?.set;\n if (setter) setter.call(field, next);\n else field.value = next;\n}\n"],"mappings":";;AAQA,MAAM,8BAAc,IAAI,IAAI;CAAC;CAAQ;CAAU;CAAO;CAAO;AAAU,CAAC;AAExE,SAAgB,YAAY,QAA8C;CACxE,IAAI,OAAO,WAAW,YAAY,WAAW,MAAM,OAAO;CAC1D,MAAM,UAAU;CAChB,IAAI,QAAQ,aAAa,YAAY,OAAO;CAC5C,IAAI,QAAQ,aAAa,WAAW,OAAO,QAAQ,SAAS,YAAY,YAAY,IAAI,QAAQ,IAAI,GAAG,OAAO;CAC9G,OAAO;AACT;;;;;;;AAQA,SAAgB,WAAW,OAAkB,MAAuB;CAClE,IAAI,MAAM,YAAY,MAAM,UAAU,OAAO;CAE7C,MAAM,QAAQ,MAAM,aAAa,UAAU,KAAK,QAAQ,gCAAgC,GAAG,IAAI;CAC/F,MAAM,MAAM,MAAM;CAClB,MAAM,MAAM;CAEZ,MAAM,QAAQ,MAAM;CACpB,MAAM,MAAM,MAAM;CAClB,IAAI;EAGF,IAAI,UAAU,QAAQ,QAAQ,MAAM,MAAM,kBAAkB,OAAO,GAAG;EAGtE,IAAI,IAAI,kBAAkB,SAAS,IAAI,YAAY,cAAc,OAAO,KAAK,GAAG,OAAO;CACzF,QAAQ,CAER;CACA,MAAM,OAAO,SAAS,MAAM,MAAM;CAClC,MAAM,KAAK,OAAO;CAClB,IAAI,SAAS;CACb,IAAI,MAAM,aAAa,GAAG;EACxB,MAAM,OAAO,KAAK,IAAI,GAAG,MAAM,aAAa,MAAM,MAAM,UAAU,KAAK,MAAM;EAC7E,SAAS,OAAO,MAAM,GAAG,IAAI;EAE7B,IAAI,mBAAmB,KAAK,MAAM,GAAG,SAAS,OAAO,MAAM,GAAG,EAAE;CAClE;CACA,IAAI,UAAU,MAAM,eAAe,OAAO,MAAM,QAAQ,MAAM;MACzD,MAAM,aAAa,QAAQ,MAAM,IAAI,KAAK;CAC/C,MAAM,OAAO,IAAI;CACjB,MAAM,QACJ,SAAS,QAAQ,OAAO,KAAK,eAAe,aACxC,IAAI,KAAK,WAAW,SAAS;EAAE,SAAS;EAAM,WAAW;EAAmB,MAAM;CAAO,CAAC,IAC1F,IAAI,MAAM,SAAS,EAAE,SAAS,KAAK,CAAC;CAC1C,MAAM,cAAc,KAAK;CACzB,OAAO;AACT;;;;;;AAOA,SAAS,eAAe,OAAkB,MAAoB;CAG5D,MAAM,SAFa,OAAO,yBAAyB,OAAO,eAAe,KAAK,GAAa,OAEnE,CAAC,EAAE;CAC3B,IAAI,QAAQ,OAAO,KAAK,OAAO,IAAI;MAC9B,MAAM,QAAQ;AACrB"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"text-field-DUvrMMaK.js","names":[],"sources":["../../src/core/text-field.ts"],"sourcesContent":["/**\n * Text-field helpers shared by the paste handlers of the opt-in entry points.\n * Internal: not part of `react-smart-copy/core`'s public API.\n */\n\n/** Text fields `setRangeText` and `execCommand('insertText')` both support. */\nexport type TextField = HTMLTextAreaElement | HTMLInputElement;\n\nconst TEXT_INPUTS = new Set(['text', 'search', 'url', 'tel', 'password']);\n\nexport function asTextField(target: EventTarget | null): TextField | null {\n if (typeof target !== 'object' || target === null) return null;\n const element = target as Partial<Element> & { type?: unknown };\n if (element.nodeName === 'TEXTAREA') return target as HTMLTextAreaElement;\n if (element.nodeName === 'INPUT' && typeof element.type === 'string' && TEXT_INPUTS.has(element.type)) return target as HTMLInputElement;\n return null;\n}\n\n/**\n * Inserts text at the cursor of a `<textarea>` or text `<input>`, replacing the\n * selection, as typing or pasting would: the browser's undo (Ctrl/⌘+Z) still\n * works, `input` events fire (so React and other frameworks see the change),\n * and `maxlength` is respected. Returns `false` for disabled or read-only fields.\n */\nexport function insertText(field: TextField, text: string): boolean {\n if (field.disabled || field.readOnly) return false;\n // An <input> holds one line: each run of line breaks (a paragraph break too) becomes one space.\n const value = field.nodeName === 'INPUT' ? text.replace(/[ \\t]*(?:\\r\\n|\\r|\\n)+[ \\t]*/g, ' ') : text;\n const doc = field.ownerDocument;\n field.focus();\n // `null` for inputs without a selection API (email, number): the text is appended.\n const start = field.selectionStart;\n const end = field.selectionEnd;\n try {\n // Re-applying the selection ends the current typing run, so the paste gets its own undo step\n // (as a native paste does) instead of merging with what was typed just before.\n if (start !== null && end !== null) field.setSelectionRange(start, end);\n // The only way to keep the native undo stack; supported for text fields in every current browser.\n // eslint-disable-next-line @typescript-eslint/no-deprecated -- no replacement keeps undo history\n if (doc.activeElement === field && doc.execCommand('insertText', false, value)) return true;\n } catch {\n // Fall through to the manual insertion.\n }\n const from = start ?? field.value.length;\n const to = end ?? from;\n let insert = value;\n if (field.maxLength >= 0) {\n const room = Math.max(0, field.maxLength - (field.value.length - (to - from)));\n insert = insert.slice(0, room);\n // Never leave half of a surrogate pair (an emoji) behind.\n if (/[\\ud800-\\udbff]$/.test(insert)) insert = insert.slice(0, -1);\n }\n if (start === null) setNativeValue(field, field.value + insert);\n else field.setRangeText(insert, from, to, 'end');\n const view = doc.defaultView;\n const event =\n view !== null && typeof view.InputEvent === 'function'\n ? new view.InputEvent('input', { bubbles: true, inputType: 'insertFromPaste', data: insert })\n : new Event('input', { bubbles: true });\n field.dispatchEvent(event);\n return true;\n}\n\n/**\n * Sets a field's value through the prototype's setter. React tracks the value\n * set on the element itself; going around it lets React see the change and\n * call `onChange` for the `input` event that follows.\n */\nfunction setNativeValue(field: TextField, next: string): void {\n const descriptor = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(field) as object, 'value');\n // eslint-disable-next-line @typescript-eslint/unbound-method -- it is called right below with the field as `this`\n const setter = descriptor?.set;\n if (setter) setter.call(field, next);\n else field.value = next;\n}\n"],"mappings":";;AAQA,MAAM,8BAAc,IAAI,IAAI;CAAC;CAAQ;CAAU;CAAO;CAAO;AAAU,CAAC;AAExE,SAAgB,YAAY,QAA8C;CACxE,IAAI,OAAO,WAAW,YAAY,WAAW,MAAM,OAAO;CAC1D,MAAM,UAAU;CAChB,IAAI,QAAQ,aAAa,YAAY,OAAO;CAC5C,IAAI,QAAQ,aAAa,WAAW,OAAO,QAAQ,SAAS,YAAY,YAAY,IAAI,QAAQ,IAAI,GAAG,OAAO;CAC9G,OAAO;AACT;;;;;;;AAQA,SAAgB,WAAW,OAAkB,MAAuB;CAClE,IAAI,MAAM,YAAY,MAAM,UAAU,OAAO;CAE7C,MAAM,QAAQ,MAAM,aAAa,UAAU,KAAK,QAAQ,gCAAgC,GAAG,IAAI;CAC/F,MAAM,MAAM,MAAM;CAClB,MAAM,MAAM;CAEZ,MAAM,QAAQ,MAAM;CACpB,MAAM,MAAM,MAAM;CAClB,IAAI;EAGF,IAAI,UAAU,QAAQ,QAAQ,MAAM,MAAM,kBAAkB,OAAO,GAAG;EAGtE,IAAI,IAAI,kBAAkB,SAAS,IAAI,YAAY,cAAc,OAAO,KAAK,GAAG,OAAO;CACzF,QAAQ,CAER;CACA,MAAM,OAAO,SAAS,MAAM,MAAM;CAClC,MAAM,KAAK,OAAO;CAClB,IAAI,SAAS;CACb,IAAI,MAAM,aAAa,GAAG;EACxB,MAAM,OAAO,KAAK,IAAI,GAAG,MAAM,aAAa,MAAM,MAAM,UAAU,KAAK,MAAM;EAC7E,SAAS,OAAO,MAAM,GAAG,IAAI;EAE7B,IAAI,mBAAmB,KAAK,MAAM,GAAG,SAAS,OAAO,MAAM,GAAG,EAAE;CAClE;CACA,IAAI,UAAU,MAAM,eAAe,OAAO,MAAM,QAAQ,MAAM;MACzD,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