react-smart-copy 1.21.0 → 1.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +67 -0
- package/dist/chunks/digits-BUEvSVrs.cjs +51 -0
- package/dist/chunks/digits-BUEvSVrs.cjs.map +1 -0
- package/dist/chunks/digits-DkU-O9_A.js +46 -0
- package/dist/chunks/digits-DkU-O9_A.js.map +1 -0
- package/dist/chunks/field-BHo5y-t_.js +535 -0
- package/dist/chunks/field-BHo5y-t_.js.map +1 -0
- package/dist/chunks/field-BTsKTs2M.d.cts +87 -0
- package/dist/chunks/field-BTsKTs2M.d.ts +87 -0
- package/dist/chunks/field-Bytz2WfN.cjs +558 -0
- package/dist/chunks/field-Bytz2WfN.cjs.map +1 -0
- package/dist/chunks/{text-field-Ba8W3v4R.cjs → text-field-BEzUVOag.cjs} +26 -5
- package/dist/chunks/text-field-BEzUVOag.cjs.map +1 -0
- package/dist/chunks/{text-field-DUvrMMaK.js → text-field-D7PF2WlX.js} +21 -6
- package/dist/chunks/text-field-D7PF2WlX.js.map +1 -0
- package/dist/code.cjs +1 -1
- package/dist/code.js +1 -1
- package/dist/color.cjs +1 -1
- package/dist/color.js +1 -1
- package/dist/index.cjs +89 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +42 -1
- package/dist/index.d.ts +42 -1
- package/dist/index.js +89 -1
- package/dist/index.js.map +1 -1
- package/dist/link.cjs +1 -1
- package/dist/link.js +1 -1
- package/dist/markdown.cjs +1 -1
- package/dist/markdown.js +1 -1
- package/dist/number.cjs +442 -0
- package/dist/number.cjs.map +1 -0
- package/dist/number.d.cts +172 -0
- package/dist/number.d.ts +172 -0
- package/dist/number.js +436 -0
- package/dist/number.js.map +1 -0
- package/dist/otp.cjs +7 -0
- package/dist/otp.d.cts +54 -0
- package/dist/otp.d.ts +54 -0
- package/dist/otp.js +2 -0
- package/dist/secrets.cjs +1 -1
- package/dist/secrets.js +1 -1
- package/package.json +71 -3
- package/dist/chunks/text-field-Ba8W3v4R.cjs.map +0 -1
- package/dist/chunks/text-field-DUvrMMaK.js.map +0 -1
|
@@ -0,0 +1,558 @@
|
|
|
1
|
+
|
|
2
|
+
const require_errors = require("./errors-BwOF6T_M.cjs");
|
|
3
|
+
const require_digits = require("./digits-BUEvSVrs.cjs");
|
|
4
|
+
//#region src/otp/normalize.ts
|
|
5
|
+
/**
|
|
6
|
+
* `text` with its digits in ASCII and, for alphanumeric codes, its letters in upper case:
|
|
7
|
+
* full-width digits and letters, and Arabic-Indic, Devanagari and other scripts' digits,
|
|
8
|
+
* become ASCII. Other characters are kept: callers decide what to drop.
|
|
9
|
+
*/
|
|
10
|
+
function normalizeOtpText(text, alphabet) {
|
|
11
|
+
const ascii = require_digits.asciiDigits(text);
|
|
12
|
+
return alphabet === "alphanumeric" ? ascii.toUpperCase() : ascii;
|
|
13
|
+
}
|
|
14
|
+
/** Whether `char` (already normalized) can be part of a code. */
|
|
15
|
+
function isOtpChar(char, alphabet) {
|
|
16
|
+
return alphabet === "numeric" ? char >= "0" && char <= "9" && char.length === 1 : /^[0-9A-Z]$/.test(char);
|
|
17
|
+
}
|
|
18
|
+
/** The characters of `text` that can be part of a code, normalized, in order. */
|
|
19
|
+
function otpChars(text, alphabet) {
|
|
20
|
+
return Array.from(normalizeOtpText(text, alphabet)).filter((char) => isOtpChar(char, alphabet));
|
|
21
|
+
}
|
|
22
|
+
//#endregion
|
|
23
|
+
//#region src/otp/extract.ts
|
|
24
|
+
/** Text past this many characters is not read: a code is near the start of a message. */
|
|
25
|
+
const OTP_SCAN_LENGTH = 1e5;
|
|
26
|
+
function rangeOf(length) {
|
|
27
|
+
const range = typeof length === "number" ? {
|
|
28
|
+
min: length,
|
|
29
|
+
max: length
|
|
30
|
+
} : length ?? {
|
|
31
|
+
min: 4,
|
|
32
|
+
max: 8
|
|
33
|
+
};
|
|
34
|
+
const valid = (value) => Number.isInteger(value) && value >= 1 && value <= 32;
|
|
35
|
+
if (!valid(range.min) || !valid(range.max) || range.min > range.max) throw require_errors.copyFailure("invalid-payload", "length must be a whole number from 1 to 32, or a range of them.");
|
|
36
|
+
return range;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Words next to a one-time code, lower case: English, Hindi, Spanish, Portuguese, French,
|
|
40
|
+
* German, Italian, Dutch, Indonesian, Turkish, Polish, Russian, Ukrainian, Arabic, Hebrew,
|
|
41
|
+
* Persian, Chinese, Japanese, Korean, Vietnamese and Thai.
|
|
42
|
+
*/
|
|
43
|
+
const KEYWORDS = [
|
|
44
|
+
"code",
|
|
45
|
+
"otp",
|
|
46
|
+
"one-time",
|
|
47
|
+
"one time",
|
|
48
|
+
"passcode",
|
|
49
|
+
"password",
|
|
50
|
+
"pin",
|
|
51
|
+
"verification",
|
|
52
|
+
"verify",
|
|
53
|
+
"security",
|
|
54
|
+
"login",
|
|
55
|
+
"log in",
|
|
56
|
+
"sign-in",
|
|
57
|
+
"sign in",
|
|
58
|
+
"2fa",
|
|
59
|
+
"two-factor",
|
|
60
|
+
"authentication",
|
|
61
|
+
"token",
|
|
62
|
+
"ओटीपी",
|
|
63
|
+
"कोड",
|
|
64
|
+
"सत्यापन",
|
|
65
|
+
"código",
|
|
66
|
+
"codigo",
|
|
67
|
+
"clave",
|
|
68
|
+
"contraseña",
|
|
69
|
+
"senha",
|
|
70
|
+
"mot de passe",
|
|
71
|
+
"vérification",
|
|
72
|
+
"bestätigungscode",
|
|
73
|
+
"kennwort",
|
|
74
|
+
"codice",
|
|
75
|
+
"verificatie",
|
|
76
|
+
"kode",
|
|
77
|
+
"kod",
|
|
78
|
+
"doğrulama",
|
|
79
|
+
"weryfikacyjny",
|
|
80
|
+
"код",
|
|
81
|
+
"пароль",
|
|
82
|
+
"разовый",
|
|
83
|
+
"رمز",
|
|
84
|
+
"كود",
|
|
85
|
+
"التحقق",
|
|
86
|
+
"קוד",
|
|
87
|
+
"کد",
|
|
88
|
+
"验证码",
|
|
89
|
+
"驗證碼",
|
|
90
|
+
"校验码",
|
|
91
|
+
"動態碼",
|
|
92
|
+
"認証コード",
|
|
93
|
+
"確認コード",
|
|
94
|
+
"ワンタイム",
|
|
95
|
+
"認証番号",
|
|
96
|
+
"인증번호",
|
|
97
|
+
"인증",
|
|
98
|
+
"코드",
|
|
99
|
+
"mã",
|
|
100
|
+
"xác thực",
|
|
101
|
+
"รหัส"
|
|
102
|
+
];
|
|
103
|
+
/** Codes that are not one-time codes, right before a number: postal codes, coupons, orders. */
|
|
104
|
+
const 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}$/;
|
|
105
|
+
/** Currencies and units around a number: it is an amount, not a code. */
|
|
106
|
+
const CURRENCY_BEFORE = /(?:[$\u20AC\u00A3\u20B9\u00A5\u20A9\u20BD\u00A2]|\brs\.?|\binr|\busd|\beur|\bgbp)\s?$/;
|
|
107
|
+
const AMOUNT_AFTER = /^\s?(?:%|[$\u20AC\u00A3\u20B9\u00A5]|inr\b|usd\b|eur\b|rs\b|rupees\b|dollars\b|euros\b)/;
|
|
108
|
+
const NUMERIC = /(^|[^\p{L}\p{N}_])(\d{2,4}(?:[ -]\d{2,4}){1,3}|\d{1,12})(?![\p{L}\p{N}_])/gu;
|
|
109
|
+
const 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;
|
|
110
|
+
const isDigit = (char) => char !== void 0 && char >= "0" && char <= "9";
|
|
111
|
+
/**
|
|
112
|
+
* Whether the number at `start`-`end` is something else: part of a longer number (a phone
|
|
113
|
+
* number), a date, a time or a decimal, an amount, an order or reference number, or inside
|
|
114
|
+
* a URL or an e-mail address.
|
|
115
|
+
*/
|
|
116
|
+
function excluded(text, lower, start, end) {
|
|
117
|
+
const before = text[start - 1];
|
|
118
|
+
const after = text[end];
|
|
119
|
+
if ((before === " " || before === "-") && isDigit(text[start - 2])) return true;
|
|
120
|
+
if ((after === " " || after === "-") && isDigit(text[end + 1])) return true;
|
|
121
|
+
if (before !== void 0 && ":/.".includes(before) && isDigit(text[start - 2])) return true;
|
|
122
|
+
if (after !== void 0 && ":/.".includes(after) && isDigit(text[end + 1])) return true;
|
|
123
|
+
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;
|
|
124
|
+
if (before === "+" || before === "#" || before === "(" || before === " " && text[start - 2] === ")") return true;
|
|
125
|
+
const head = lower.slice(Math.max(0, start - 24), start);
|
|
126
|
+
if (CURRENCY_BEFORE.test(head) || NOT_OTP.test(head) || AMOUNT_AFTER.test(lower.slice(end, end + 10))) return true;
|
|
127
|
+
let from = start;
|
|
128
|
+
while (from > Math.max(0, start - 256) && !/\s/.test(text[from - 1])) from -= 1;
|
|
129
|
+
let to = end;
|
|
130
|
+
while (to < Math.min(text.length, end + 256) && !/\s/.test(text[to])) to += 1;
|
|
131
|
+
return /@|:\/\/|www\.|[\p{L}\p{N}-]\.\p{L}{2,}\//iu.test(text.slice(from, to));
|
|
132
|
+
}
|
|
133
|
+
/** Lower case, one character for one: positions in it are positions in `text`. */
|
|
134
|
+
function lowerSameLength(text) {
|
|
135
|
+
let out = "";
|
|
136
|
+
for (const char of text) {
|
|
137
|
+
const lower = char.toLowerCase();
|
|
138
|
+
out += lower.length === char.length ? lower : char;
|
|
139
|
+
}
|
|
140
|
+
return out;
|
|
141
|
+
}
|
|
142
|
+
/** The distance from the number at `start`-`end` to the nearest keyword: words before count closer. */
|
|
143
|
+
function keywordDistance(lower, start, end) {
|
|
144
|
+
let best = Infinity;
|
|
145
|
+
const window = lower.slice(Math.max(0, start - 60), Math.min(lower.length, end + 40));
|
|
146
|
+
const offset = Math.max(0, start - 60);
|
|
147
|
+
for (const keyword of KEYWORDS) {
|
|
148
|
+
const whole = /^[a-z0-9 -]+$/.test(keyword);
|
|
149
|
+
for (let at = window.indexOf(keyword); at !== -1; at = window.indexOf(keyword, at + 1)) {
|
|
150
|
+
if (whole && (/[a-z]/.test(window[at - 1] ?? "") || /[a-z]/.test(window[at + keyword.length] ?? ""))) continue;
|
|
151
|
+
const from = at + offset;
|
|
152
|
+
const to = from + keyword.length;
|
|
153
|
+
if (to <= start) best = Math.min(best, start - to);
|
|
154
|
+
else if (from >= end) best = Math.min(best, from - end + 10);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
return best;
|
|
158
|
+
}
|
|
159
|
+
/** The origin-bound line of the WebOTP format: `@host #code`, last in the message. */
|
|
160
|
+
const 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;
|
|
161
|
+
/**
|
|
162
|
+
* The one-time code in `text`: an SMS or e-mail people paste, or a code they copied. Digits
|
|
163
|
+
* of any script and full-width characters are read as ASCII, and separators are dropped
|
|
164
|
+
* (`482 913`, `482-913`).
|
|
165
|
+
*
|
|
166
|
+
* Prices, dates, times, phone numbers, order numbers and postal codes are never taken for a
|
|
167
|
+
* code. When several numbers could be the code and no keyword points at one, the result is
|
|
168
|
+
* `null`: guessing would fill in a wrong code.
|
|
169
|
+
*
|
|
170
|
+
* @throws {CopyFailure} `invalid-payload` for a `length` that is not 1 to 32, or a reversed range.
|
|
171
|
+
*/
|
|
172
|
+
function extractOtp(text, options = {}) {
|
|
173
|
+
const range = rangeOf(options.length);
|
|
174
|
+
const alphabet = options.alphabet ?? "numeric";
|
|
175
|
+
const fits = (code) => code.length >= range.min && code.length <= range.max && (alphabet === "alphanumeric" || /^\d+$/.test(code));
|
|
176
|
+
const normalized = normalizeOtpText(text.slice(0, OTP_SCAN_LENGTH), alphabet);
|
|
177
|
+
const whole = normalized.trim();
|
|
178
|
+
if (/^[0-9A-Z]{1,32}(?:[ -][0-9A-Z]{1,32}){0,7}$/.test(whole)) {
|
|
179
|
+
const code = whole.replace(/[ -]/g, "");
|
|
180
|
+
if (fits(code)) return {
|
|
181
|
+
code,
|
|
182
|
+
source: "whole-text",
|
|
183
|
+
confidence: "high",
|
|
184
|
+
domain: null
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
const bound = ORIGIN_BOUND.exec(normalizeOtpText(text.slice(0, OTP_SCAN_LENGTH), "numeric").trimEnd());
|
|
188
|
+
if (bound !== null) {
|
|
189
|
+
const domain = bound[1].toLowerCase();
|
|
190
|
+
const code = bound[2].toUpperCase();
|
|
191
|
+
if (options.domain !== void 0 && options.domain.toLowerCase() !== domain) return null;
|
|
192
|
+
if (fits(code)) return {
|
|
193
|
+
code,
|
|
194
|
+
source: "origin-bound",
|
|
195
|
+
confidence: "high",
|
|
196
|
+
domain
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
const lower = lowerSameLength(normalized);
|
|
200
|
+
const pattern = alphabet === "numeric" ? NUMERIC : ALPHANUMERIC;
|
|
201
|
+
const candidates = [];
|
|
202
|
+
for (const match of normalized.matchAll(pattern)) {
|
|
203
|
+
const raw = match[2];
|
|
204
|
+
const start = match.index + match[1].length;
|
|
205
|
+
const code = raw.replace(/[ -]/g, "");
|
|
206
|
+
if (!fits(code) || alphabet === "alphanumeric" && !/\d/.test(code) || excluded(normalized, lower, start, start + raw.length)) continue;
|
|
207
|
+
candidates.push({
|
|
208
|
+
code,
|
|
209
|
+
distance: keywordDistance(lower, start, start + raw.length)
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
const near = candidates.filter((candidate) => candidate.distance <= 60);
|
|
213
|
+
if (near.length > 0) return {
|
|
214
|
+
code: near.reduce((a, b) => b.distance < a.distance ? b : a).code,
|
|
215
|
+
source: "keyword",
|
|
216
|
+
confidence: "high",
|
|
217
|
+
domain: null
|
|
218
|
+
};
|
|
219
|
+
const distinct = new Set(candidates.map((candidate) => candidate.code));
|
|
220
|
+
return distinct.size === 1 ? {
|
|
221
|
+
code: [...distinct][0],
|
|
222
|
+
source: "only-candidate",
|
|
223
|
+
confidence: "medium",
|
|
224
|
+
domain: null
|
|
225
|
+
} : null;
|
|
226
|
+
}
|
|
227
|
+
//#endregion
|
|
228
|
+
//#region src/otp/state.ts
|
|
229
|
+
const emptyChars = (length) => Array.from({ length }, () => "");
|
|
230
|
+
const clamp = (index, length) => Math.min(Math.max(index, 0), length - 1);
|
|
231
|
+
/** `chars` with `text`'s characters written from `index` on, as far as they fit. */
|
|
232
|
+
function write(chars, index, text, settings) {
|
|
233
|
+
const next = [...chars];
|
|
234
|
+
const from = text.length >= settings.length ? 0 : clamp(index, settings.length);
|
|
235
|
+
const count = Math.min(text.length, settings.length - from);
|
|
236
|
+
for (let offset = 0; offset < count; offset += 1) next[from + offset] = text[offset];
|
|
237
|
+
return {
|
|
238
|
+
chars: next,
|
|
239
|
+
focus: clamp(from + count, settings.length)
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* What typing (or an autofill, or an input method) does to box `index`, whose value went
|
|
244
|
+
* from `previous` to `value`. A character typed next to the one already there replaces it;
|
|
245
|
+
* several characters fill the boxes after it; characters a code can't have are ignored.
|
|
246
|
+
*/
|
|
247
|
+
function inputStep(chars, index, previous, value, settings) {
|
|
248
|
+
let typed = value;
|
|
249
|
+
if (previous !== "" && value.length === previous.length + 1) {
|
|
250
|
+
if (value.startsWith(previous)) typed = value.slice(previous.length);
|
|
251
|
+
else if (value.endsWith(previous)) typed = value.slice(0, value.length - previous.length);
|
|
252
|
+
}
|
|
253
|
+
const text = otpChars(typed, settings.alphabet);
|
|
254
|
+
if (text.length > 0) return write(chars, index, text, settings);
|
|
255
|
+
if (value === "") {
|
|
256
|
+
const next = [...chars];
|
|
257
|
+
next[index] = "";
|
|
258
|
+
return {
|
|
259
|
+
chars: next,
|
|
260
|
+
focus: index
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
return {
|
|
264
|
+
chars,
|
|
265
|
+
focus: index
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
/** What pasting `text` into box `index` does: the code in it fills the field, wherever it is pasted. */
|
|
269
|
+
function pasteStep(chars, index, text, settings) {
|
|
270
|
+
const match = extractOtp(text, {
|
|
271
|
+
length: settings.length,
|
|
272
|
+
alphabet: settings.alphabet
|
|
273
|
+
});
|
|
274
|
+
if (match !== null) return write(chars, 0, Array.from(match.code), settings);
|
|
275
|
+
const typed = otpChars(text, settings.alphabet);
|
|
276
|
+
return typed.length > 0 && typed.length < settings.length ? write(chars, index, typed, settings) : {
|
|
277
|
+
chars,
|
|
278
|
+
focus: index
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
/** What a navigation or deletion key does in box `index`. */
|
|
282
|
+
function keyStep(chars, index, key, settings) {
|
|
283
|
+
const last = settings.length - 1;
|
|
284
|
+
switch (key) {
|
|
285
|
+
case "Backspace": {
|
|
286
|
+
const next = [...chars];
|
|
287
|
+
const target = chars[index] === "" ? Math.max(0, index - 1) : index;
|
|
288
|
+
next[target] = "";
|
|
289
|
+
return {
|
|
290
|
+
chars: next,
|
|
291
|
+
focus: target
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
case "Delete": {
|
|
295
|
+
const next = [...chars];
|
|
296
|
+
next[index] = "";
|
|
297
|
+
return {
|
|
298
|
+
chars: next,
|
|
299
|
+
focus: index
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
case "ArrowLeft": return {
|
|
303
|
+
chars,
|
|
304
|
+
focus: Math.max(0, index - 1)
|
|
305
|
+
};
|
|
306
|
+
case "ArrowRight": return {
|
|
307
|
+
chars,
|
|
308
|
+
focus: Math.min(last, index + 1)
|
|
309
|
+
};
|
|
310
|
+
case "Home": return {
|
|
311
|
+
chars,
|
|
312
|
+
focus: 0
|
|
313
|
+
};
|
|
314
|
+
case "End": {
|
|
315
|
+
const empty = chars.indexOf("");
|
|
316
|
+
return {
|
|
317
|
+
chars,
|
|
318
|
+
focus: empty === -1 ? last : empty
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
/** A whole code set at once (from WebOTP, or by the app): its characters from the first box. */
|
|
324
|
+
function setStep(code, settings) {
|
|
325
|
+
return write(emptyChars(settings.length), 0, otpChars(code, settings.alphabet).slice(0, settings.length), settings);
|
|
326
|
+
}
|
|
327
|
+
//#endregion
|
|
328
|
+
//#region src/otp/web-otp.ts
|
|
329
|
+
/** Asks the browser for the code of an SMS sent to this device, until `signal` aborts. Never rejects. */
|
|
330
|
+
async function receiveWebOtp(signal) {
|
|
331
|
+
const credentials = globalThis.navigator?.credentials;
|
|
332
|
+
if (typeof globalThis.OTPCredential === "undefined" || credentials === void 0) return { status: "unsupported" };
|
|
333
|
+
try {
|
|
334
|
+
const credential = await credentials.get({
|
|
335
|
+
otp: { transport: ["sms"] },
|
|
336
|
+
signal
|
|
337
|
+
});
|
|
338
|
+
return typeof credential?.code === "string" ? {
|
|
339
|
+
status: "received",
|
|
340
|
+
code: credential.code
|
|
341
|
+
} : { status: "failed" };
|
|
342
|
+
} catch {
|
|
343
|
+
return { status: "failed" };
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
//#endregion
|
|
347
|
+
//#region src/otp/field.ts
|
|
348
|
+
const KEYS = /* @__PURE__ */ new Set([
|
|
349
|
+
"Backspace",
|
|
350
|
+
"Delete",
|
|
351
|
+
"ArrowLeft",
|
|
352
|
+
"ArrowRight",
|
|
353
|
+
"Home",
|
|
354
|
+
"End"
|
|
355
|
+
]);
|
|
356
|
+
/**
|
|
357
|
+
* A one-time code field over a row of single-character boxes, without a framework:
|
|
358
|
+
* typing moves to the next box, Backspace to the one before; pasting a code, or an SMS
|
|
359
|
+
* holding one, fills every box from any of them; an SMS autofill into the first box
|
|
360
|
+
* (iOS, Android) fills them all. `useOtpField` is this, for React.
|
|
361
|
+
*
|
|
362
|
+
* @throws {CopyFailure} `invalid-payload` for a `length` that is not 1 to 32.
|
|
363
|
+
*/
|
|
364
|
+
function createOtpField(options = {}) {
|
|
365
|
+
const length = options.length ?? 6;
|
|
366
|
+
if (!Number.isInteger(length) || length < 1 || length > 32) throw require_errors.copyFailure("invalid-payload", "length must be a whole number from 1 to 32.");
|
|
367
|
+
const settings = {
|
|
368
|
+
length,
|
|
369
|
+
alphabet: options.alphabet ?? "numeric"
|
|
370
|
+
};
|
|
371
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
372
|
+
let snapshot = {
|
|
373
|
+
chars: emptyChars(length),
|
|
374
|
+
value: "",
|
|
375
|
+
complete: false,
|
|
376
|
+
webOtp: "idle"
|
|
377
|
+
};
|
|
378
|
+
let boxes = [];
|
|
379
|
+
let detach = null;
|
|
380
|
+
let webOtpAbort = null;
|
|
381
|
+
/** Stops waiting for an SMS, with how it ended. */
|
|
382
|
+
function stopWebOtp(status) {
|
|
383
|
+
if (webOtpAbort === null) return;
|
|
384
|
+
webOtpAbort.abort();
|
|
385
|
+
webOtpAbort = null;
|
|
386
|
+
publish({
|
|
387
|
+
...snapshot,
|
|
388
|
+
webOtp: status
|
|
389
|
+
});
|
|
390
|
+
}
|
|
391
|
+
function publish(next) {
|
|
392
|
+
snapshot = next;
|
|
393
|
+
options.onChange?.(next);
|
|
394
|
+
for (const listener of [...listeners]) listener();
|
|
395
|
+
}
|
|
396
|
+
function render(step, focus) {
|
|
397
|
+
boxes.forEach((box, index) => {
|
|
398
|
+
const char = step.chars[index];
|
|
399
|
+
if (box.value !== char) box.value = char;
|
|
400
|
+
});
|
|
401
|
+
if (focus) {
|
|
402
|
+
const box = boxes[step.focus];
|
|
403
|
+
box?.focus();
|
|
404
|
+
box?.select();
|
|
405
|
+
}
|
|
406
|
+
if (step.chars.every((char, index) => char === snapshot.chars[index])) return;
|
|
407
|
+
const value = step.chars.join("");
|
|
408
|
+
const complete = step.chars.every((char) => char !== "");
|
|
409
|
+
publish({
|
|
410
|
+
...snapshot,
|
|
411
|
+
chars: step.chars,
|
|
412
|
+
value,
|
|
413
|
+
complete
|
|
414
|
+
});
|
|
415
|
+
if (complete) {
|
|
416
|
+
stopWebOtp("aborted");
|
|
417
|
+
options.onComplete?.(value);
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
function wire(inputs) {
|
|
421
|
+
const stops = [];
|
|
422
|
+
const on = (target, type, handler) => {
|
|
423
|
+
target.addEventListener(type, handler);
|
|
424
|
+
stops.push(() => {
|
|
425
|
+
target.removeEventListener(type, handler);
|
|
426
|
+
});
|
|
427
|
+
};
|
|
428
|
+
const label = options.label ?? ((index, total) => `${settings.alphabet === "numeric" ? "Digit" : "Character"} ${String(index + 1)} of ${String(total)}`);
|
|
429
|
+
inputs.forEach((input, index) => {
|
|
430
|
+
const restore = [
|
|
431
|
+
"autocomplete",
|
|
432
|
+
"inputmode",
|
|
433
|
+
"aria-label",
|
|
434
|
+
"autocapitalize",
|
|
435
|
+
"spellcheck",
|
|
436
|
+
"pattern"
|
|
437
|
+
].map((name) => [name, input.getAttribute(name)]);
|
|
438
|
+
stops.push(() => {
|
|
439
|
+
for (const [name, value] of restore) if (value === null) input.removeAttribute(name);
|
|
440
|
+
else input.setAttribute(name, value);
|
|
441
|
+
});
|
|
442
|
+
input.setAttribute("autocomplete", index === 0 ? "one-time-code" : "off");
|
|
443
|
+
input.setAttribute("inputmode", settings.alphabet === "numeric" ? "numeric" : "text");
|
|
444
|
+
input.setAttribute("aria-label", label(index, length));
|
|
445
|
+
input.setAttribute("autocapitalize", settings.alphabet === "numeric" ? "off" : "characters");
|
|
446
|
+
input.setAttribute("spellcheck", "false");
|
|
447
|
+
if (settings.alphabet === "numeric") input.setAttribute("pattern", "[0-9]*");
|
|
448
|
+
else input.removeAttribute("pattern");
|
|
449
|
+
input.value = snapshot.chars[index];
|
|
450
|
+
on(input, "focus", () => {
|
|
451
|
+
input.select();
|
|
452
|
+
});
|
|
453
|
+
on(input, "keydown", (event) => {
|
|
454
|
+
if (!KEYS.has(event.key) || event.altKey || event.ctrlKey || event.metaKey) return;
|
|
455
|
+
event.preventDefault();
|
|
456
|
+
render(keyStep(snapshot.chars, index, event.key, settings), true);
|
|
457
|
+
});
|
|
458
|
+
on(input, "beforeinput", (event) => {
|
|
459
|
+
if (event.inputType.startsWith("delete") && input.value === "") {
|
|
460
|
+
event.preventDefault();
|
|
461
|
+
render(keyStep(snapshot.chars, index, "Backspace", settings), true);
|
|
462
|
+
}
|
|
463
|
+
});
|
|
464
|
+
on(input, "input", () => {
|
|
465
|
+
render(inputStep(snapshot.chars, index, snapshot.chars[index], input.value, settings), true);
|
|
466
|
+
});
|
|
467
|
+
on(input, "paste", (event) => {
|
|
468
|
+
event.preventDefault();
|
|
469
|
+
const text = event.clipboardData?.getData("text/plain") ?? "";
|
|
470
|
+
render(pasteStep(snapshot.chars, index, text, settings), true);
|
|
471
|
+
});
|
|
472
|
+
});
|
|
473
|
+
if (options.webOtp === true && !snapshot.complete) {
|
|
474
|
+
const abort = new AbortController();
|
|
475
|
+
webOtpAbort = abort;
|
|
476
|
+
publish({
|
|
477
|
+
...snapshot,
|
|
478
|
+
webOtp: "waiting"
|
|
479
|
+
});
|
|
480
|
+
receiveWebOtp(abort.signal).then((result) => {
|
|
481
|
+
if (abort.signal.aborted) return;
|
|
482
|
+
webOtpAbort = null;
|
|
483
|
+
if (result.status === "received") render(setStep(result.code, settings), false);
|
|
484
|
+
publish({
|
|
485
|
+
...snapshot,
|
|
486
|
+
webOtp: result.status
|
|
487
|
+
});
|
|
488
|
+
});
|
|
489
|
+
}
|
|
490
|
+
return () => {
|
|
491
|
+
for (const stop of stops) stop();
|
|
492
|
+
stopWebOtp("aborted");
|
|
493
|
+
};
|
|
494
|
+
}
|
|
495
|
+
return {
|
|
496
|
+
attach: (inputs) => {
|
|
497
|
+
detach?.();
|
|
498
|
+
boxes = [...inputs];
|
|
499
|
+
const undo = wire(boxes);
|
|
500
|
+
let attached = true;
|
|
501
|
+
detach = () => {
|
|
502
|
+
if (!attached) return;
|
|
503
|
+
attached = false;
|
|
504
|
+
undo();
|
|
505
|
+
boxes = [];
|
|
506
|
+
detach = null;
|
|
507
|
+
};
|
|
508
|
+
return detach;
|
|
509
|
+
},
|
|
510
|
+
getSnapshot: () => snapshot,
|
|
511
|
+
subscribe: (listener) => {
|
|
512
|
+
listeners.add(listener);
|
|
513
|
+
return () => {
|
|
514
|
+
listeners.delete(listener);
|
|
515
|
+
};
|
|
516
|
+
},
|
|
517
|
+
setValue: (code) => {
|
|
518
|
+
render(setStep(code, settings), false);
|
|
519
|
+
},
|
|
520
|
+
clear: () => {
|
|
521
|
+
render({
|
|
522
|
+
chars: emptyChars(length),
|
|
523
|
+
focus: 0
|
|
524
|
+
}, true);
|
|
525
|
+
},
|
|
526
|
+
focus: () => {
|
|
527
|
+
const empty = snapshot.chars.indexOf("");
|
|
528
|
+
boxes[empty === -1 ? length - 1 : empty]?.focus();
|
|
529
|
+
}
|
|
530
|
+
};
|
|
531
|
+
}
|
|
532
|
+
//#endregion
|
|
533
|
+
Object.defineProperty(exports, "OTP_SCAN_LENGTH", {
|
|
534
|
+
enumerable: true,
|
|
535
|
+
get: function() {
|
|
536
|
+
return OTP_SCAN_LENGTH;
|
|
537
|
+
}
|
|
538
|
+
});
|
|
539
|
+
Object.defineProperty(exports, "createOtpField", {
|
|
540
|
+
enumerable: true,
|
|
541
|
+
get: function() {
|
|
542
|
+
return createOtpField;
|
|
543
|
+
}
|
|
544
|
+
});
|
|
545
|
+
Object.defineProperty(exports, "extractOtp", {
|
|
546
|
+
enumerable: true,
|
|
547
|
+
get: function() {
|
|
548
|
+
return extractOtp;
|
|
549
|
+
}
|
|
550
|
+
});
|
|
551
|
+
Object.defineProperty(exports, "normalizeOtpText", {
|
|
552
|
+
enumerable: true,
|
|
553
|
+
get: function() {
|
|
554
|
+
return normalizeOtpText;
|
|
555
|
+
}
|
|
556
|
+
});
|
|
557
|
+
|
|
558
|
+
//# sourceMappingURL=field-Bytz2WfN.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"field-Bytz2WfN.cjs","names":["asciiDigits","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":["import { asciiDigits } from '../core/digits';\n\n/** What a one-time code is made of. */\nexport type OtpAlphabet = 'numeric' | 'alphanumeric';\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 = asciiDigits(text);\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":";;;;;;;;;AAUA,SAAgB,iBAAiB,MAAc,UAA+B;CAC5E,MAAM,QAAQA,eAAAA,YAAY,IAAI;CAC9B,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,CA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