react-smart-copy 1.22.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.
Files changed (38) hide show
  1. package/README.md +28 -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/index.cjs +1 -1
  19. package/dist/index.js +1 -1
  20. package/dist/link.cjs +1 -1
  21. package/dist/link.js +1 -1
  22. package/dist/markdown.cjs +1 -1
  23. package/dist/markdown.js +1 -1
  24. package/dist/number.cjs +442 -0
  25. package/dist/number.cjs.map +1 -0
  26. package/dist/number.d.cts +172 -0
  27. package/dist/number.d.ts +172 -0
  28. package/dist/number.js +436 -0
  29. package/dist/number.js.map +1 -0
  30. package/dist/otp.cjs +1 -1
  31. package/dist/otp.js +1 -1
  32. package/dist/secrets.cjs +1 -1
  33. package/dist/secrets.js +1 -1
  34. package/package.json +37 -3
  35. package/dist/chunks/field-Cdq2LxEO.js.map +0 -1
  36. package/dist/chunks/field-NaDdWy_5.cjs.map +0 -1
  37. package/dist/chunks/text-field-Ba8W3v4R.cjs.map +0 -1
  38. package/dist/chunks/text-field-DUvrMMaK.js.map +0 -1
package/dist/index.cjs CHANGED
@@ -7,7 +7,7 @@ const require_clipboard_adapter = require("./chunks/clipboard-adapter-Cfz-rzw3.c
7
7
  const require_core = require("./chunks/core-DYf_Lhbe.cjs");
8
8
  const require_paste_reader = require("./chunks/paste-reader-Bo01IMC_.cjs");
9
9
  const require_share = require("./chunks/share-ayDz974N.cjs");
10
- const require_field = require("./chunks/field-NaDdWy_5.cjs");
10
+ const require_field = require("./chunks/field-Bytz2WfN.cjs");
11
11
  let react = require("react");
12
12
  let react_jsx_runtime = require("react/jsx-runtime");
13
13
  //#region src/react/CopyGroup.tsx
package/dist/index.js CHANGED
@@ -6,7 +6,7 @@ import { t as createBrowserClipboardAdapter } from "./chunks/clipboard-adapter-D
6
6
  import { _ as resolveMaxRetries, a as applyDragCopy, c as interceptCopyEvent, d as DEFAULT_RESET_AFTER_MS, f as IDLE_STATE, g as invoke, h as DEFAULT_MAX_RETRIES, i as createBrowserPasteAdapter, l as readCopySelection, m as createCopyMachine, n as canRetryPasteState, o as registerDragCopy, p as canRetryState, r as createPasteMachine, s as DEFAULT_INTERCEPTED_EVENTS, t as PASTE_IDLE_STATE, u as registerCopyInterceptor, v as createCopyCoordinator } from "./chunks/core-Cp2HSpaz.js";
7
7
  import { i as canAcceptDrag, l as resolvePasteReadOptions, n as DEFAULT_PASTE_MAX_BYTES, r as DEFAULT_PASTE_MAX_ITEMS, t as DEFAULT_PASTE_ACCEPT } from "./chunks/paste-reader-D9i7yMXF.js";
8
8
  import { i as shareOrCopy, r as shareMethod, t as TOUCH_FIRST } from "./chunks/share-Bop47Znn.js";
9
- import { t as createOtpField } from "./chunks/field-Cdq2LxEO.js";
9
+ import { t as createOtpField } from "./chunks/field-BHo5y-t_.js";
10
10
  import { createContext, forwardRef, useCallback, useContext, useEffect, useId, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
11
11
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
12
12
  //#region src/react/CopyGroup.tsx
package/dist/link.cjs CHANGED
@@ -4,7 +4,7 @@ const require_errors = require("./chunks/errors-BwOF6T_M.cjs");
4
4
  const require_url = require("./chunks/url-D4PGsRm8.cjs");
5
5
  const require_payload = require("./chunks/payload-J6GjHuh3.cjs");
6
6
  const require_inert_html = require("./chunks/inert-html-DyxjWDok.cjs");
7
- const require_text_field = require("./chunks/text-field-Ba8W3v4R.cjs");
7
+ const require_text_field = require("./chunks/text-field-BEzUVOag.cjs");
8
8
  //#region src/link/fragment.ts
9
9
  const invalid = (message) => require_errors.copyFailure("invalid-payload", message);
10
10
  const collapse = (text) => text.replace(/\s+/g, " ").trim();
package/dist/link.js CHANGED
@@ -3,7 +3,7 @@ import { n as copyFailure } from "./chunks/errors-9h8sdFFX.js";
3
3
  import { a as resolveLinkUrl, i as linkUrlResolver, n as TRACKING_PARAMETERS, r as cleanLinkUrl, t as DEFAULT_LINK_PROTOCOLS } from "./chunks/url-BcMYVCXQ.js";
4
4
  import { a as resolveLink, i as markdownLink, n as cleanTitle, r as linkPayload, t as DEFAULT_LINK_TITLE_LENGTH } from "./chunks/payload-DI5AorDz.js";
5
5
  import { t as parseInertHtml } from "./chunks/inert-html-D75NyVvT.js";
6
- import { n as insertText, t as asTextField } from "./chunks/text-field-DUvrMMaK.js";
6
+ import { n as insertText, t as asTextField } from "./chunks/text-field-D7PF2WlX.js";
7
7
  //#region src/link/fragment.ts
8
8
  const invalid = (message) => copyFailure("invalid-payload", message);
9
9
  const collapse = (text) => text.replace(/\s+/g, " ").trim();
package/dist/markdown.cjs CHANGED
@@ -3,7 +3,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const require_errors = require("./chunks/errors-BwOF6T_M.cjs");
4
4
  const require_inert_html = require("./chunks/inert-html-DyxjWDok.cjs");
5
5
  const require_url = require("./chunks/url-B9jdFGQy.cjs");
6
- const require_text_field = require("./chunks/text-field-Ba8W3v4R.cjs");
6
+ const require_text_field = require("./chunks/text-field-BEzUVOag.cjs");
7
7
  //#region src/markdown/escape.ts
8
8
  /**
9
9
  * CommonMark escaping. Pasted text must render as the same text, never as
package/dist/markdown.js CHANGED
@@ -2,7 +2,7 @@
2
2
  import { n as copyFailure } from "./chunks/errors-9h8sdFFX.js";
3
3
  import { t as parseInertHtml } from "./chunks/inert-html-D75NyVvT.js";
4
4
  import { i as safeUrl, n as DEFAULT_LINK_PROTOCOLS, r as linkDestination, t as DEFAULT_IMAGE_PROTOCOLS } from "./chunks/url-vJaFPbNL.js";
5
- import { n as insertText, t as asTextField } from "./chunks/text-field-DUvrMMaK.js";
5
+ import { n as insertText, t as asTextField } from "./chunks/text-field-D7PF2WlX.js";
6
6
  //#region src/markdown/escape.ts
7
7
  /**
8
8
  * CommonMark escaping. Pasted text must render as the same text, never as
@@ -0,0 +1,442 @@
1
+
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const require_errors = require("./chunks/errors-BwOF6T_M.cjs");
4
+ const require_digits = require("./chunks/digits-BUEvSVrs.cjs");
5
+ const require_text_field = require("./chunks/text-field-BEzUVOag.cjs");
6
+ //#region src/number/currency.ts
7
+ /** Longest first, so `US$` is read before `$` and `Rs.` before `Rs`. */
8
+ const BY_LENGTH = [...[
9
+ ["US$", "USD"],
10
+ ["CA$", "CAD"],
11
+ ["C$", "CAD"],
12
+ ["AU$", "AUD"],
13
+ ["A$", "AUD"],
14
+ ["NZ$", "NZD"],
15
+ ["HK$", "HKD"],
16
+ ["S$", "SGD"],
17
+ ["R$", "BRL"],
18
+ ["MX$", "MXN"],
19
+ ["NT$", "TWD"],
20
+ ["$", null],
21
+ ["€", "EUR"],
22
+ ["£", "GBP"],
23
+ ["JP¥", "JPY"],
24
+ ["CN¥", "CNY"],
25
+ ["¥", null],
26
+ ["₹", "INR"],
27
+ ["Rs.", null],
28
+ ["Rs", null],
29
+ ["₩", "KRW"],
30
+ ["₽", "RUB"],
31
+ ["₺", "TRY"],
32
+ ["₪", "ILS"],
33
+ ["₫", "VND"],
34
+ ["₱", "PHP"],
35
+ ["฿", "THB"],
36
+ ["₴", "UAH"],
37
+ ["₦", "NGN"],
38
+ ["₸", "KZT"],
39
+ ["৳", "BDT"],
40
+ ["zł", "PLN"],
41
+ ["Kč", "CZK"],
42
+ ["kr.", null],
43
+ ["kr", null],
44
+ ["Fr.", "CHF"]
45
+ ]].sort((a, b) => b[0].length - a[0].length).map(([symbol, code]) => [
46
+ symbol,
47
+ symbol.toLowerCase(),
48
+ code
49
+ ]);
50
+ let codes;
51
+ /** Whether `code` (upper case) is an ISO 4217 code the runtime knows; any three letters where it can't say. */
52
+ function isCurrencyCode(code) {
53
+ if (codes === void 0) {
54
+ const supported = Intl.supportedValuesOf;
55
+ codes = typeof supported === "function" ? new Set(supported("currency")) : null;
56
+ }
57
+ return /^[A-Z]{3}$/.test(code) && (codes === null || codes.has(code));
58
+ }
59
+ const LETTER = /\p{L}/u;
60
+ /**
61
+ * The currency at the start of `text`, and how many characters it takes. A symbol or code
62
+ * made of letters must end there: `Rs` is not read from `Rsx`, nor `USD` from `USDT`.
63
+ */
64
+ function readCurrency(text) {
65
+ const lower = text.toLowerCase();
66
+ for (const [symbol, key, code] of BY_LENGTH) if (lower.startsWith(key) && !(LETTER.test(symbol.slice(-1)) && LETTER.test(text.charAt(key.length)))) return {
67
+ currency: {
68
+ symbol,
69
+ code
70
+ },
71
+ length: key.length
72
+ };
73
+ const word = /^\p{L}+/u.exec(text)?.[0] ?? "";
74
+ const code = word.toUpperCase();
75
+ return word.length === 3 && isCurrencyCode(code) ? {
76
+ currency: {
77
+ symbol: code,
78
+ code
79
+ },
80
+ length: 3
81
+ } : null;
82
+ }
83
+ //#endregion
84
+ //#region src/number/locale.ts
85
+ const cache = /* @__PURE__ */ new Map();
86
+ const CACHE_SIZE = 32;
87
+ /**
88
+ * How `locale` writes numbers, from `Intl.NumberFormat`.
89
+ *
90
+ * @throws {CopyFailure} `invalid-payload` for a string that is not a locale.
91
+ */
92
+ function numberSymbols(locale) {
93
+ const cached = cache.get(locale);
94
+ if (cached !== void 0) return cached;
95
+ let parts;
96
+ try {
97
+ parts = new Intl.NumberFormat(locale, { numberingSystem: "latn" }).formatToParts(123456789012.5);
98
+ } catch (cause) {
99
+ throw require_errors.copyFailure("invalid-payload", `"${locale}" is not a locale.`, cause);
100
+ }
101
+ const integers = parts.filter((part) => part.type === "integer").map((part) => part.value.length);
102
+ const symbols = {
103
+ decimal: parts.some((part) => part.type === "decimal" && part.value === ",") ? "," : ".",
104
+ group: parts.find((part) => part.type === "group")?.value ?? "",
105
+ primary: Number(integers[integers.length - 1]),
106
+ secondary: Number(integers[Math.max(0, integers.length - 2)])
107
+ };
108
+ if (cache.size >= CACHE_SIZE) cache.clear();
109
+ cache.set(locale, symbols);
110
+ return symbols;
111
+ }
112
+ //#endregion
113
+ //#region src/number/parse.ts
114
+ /** Longer text holds more than a number: it is not read at all. */
115
+ const NUMBER_MAX_LENGTH = 256;
116
+ /** Group separators that are never decimal separators: spaces and apostrophes. */
117
+ const GROUP_ONLY = /* @__PURE__ */ new Set([" ", "'"]);
118
+ /** The largest exponent read from scientific notation, past which no number is finite. */
119
+ const MAX_EXPONENT = 400;
120
+ /**
121
+ * Reads the signs, brackets, currency and percent on one side of the number. Returns
122
+ * `false` when something else is there, or when one of them appears twice.
123
+ */
124
+ function readAdornments(text, into, side) {
125
+ let rest = text;
126
+ for (;;) {
127
+ rest = rest.trimStart();
128
+ if (rest === "") return true;
129
+ const char = rest.charAt(0);
130
+ let length = 1;
131
+ if (char === "(" && side === "prefix" && !into.open) into.open = true;
132
+ else if (char === ")" && side === "suffix" && !into.close) into.close = true;
133
+ else if ((char === "-" || char === "+" && side === "prefix") && into.sign === "") into.sign = char;
134
+ else if ((char === "%" || char === "‰") && into.kind === "number") into.kind = char === "%" ? "percent" : "permille";
135
+ else {
136
+ const read = into.currency === null ? readCurrency(rest) : null;
137
+ if (read === null) return false;
138
+ into.currency = read.currency;
139
+ length = read.length;
140
+ }
141
+ rest = rest.slice(length);
142
+ }
143
+ }
144
+ /** The text in a form the reader understands: ASCII digits, one minus, one apostrophe, plain spaces. */
145
+ function normalize(text) {
146
+ return require_digits.asciiDigits(text).replace(/[\u2212\u2012\u2013]/g, "-").replace(/\u066A/g, "%").replace(/[\u2019\u02BC\u066C]/g, "'").replace(/\s/g, " ");
147
+ }
148
+ /** Whether `groups` (the integer part, split at its group separator) are grouped the way locales group. */
149
+ function validGroups(groups) {
150
+ const [first, ...rest] = groups;
151
+ if (first === void 0 || first === "" || first.length > 3 || rest.length === 0) return false;
152
+ if (rest.every((group) => group.length === 3)) return true;
153
+ return first.length <= 2 && rest.slice(0, -1).every((group) => group.length === 2) && rest[rest.length - 1]?.length === 3;
154
+ }
155
+ /** The integer and fractional digits of `text` (digits and separators only), or `null`. */
156
+ function readMantissa(text, decimalOfLocale, arabicDecimal) {
157
+ const separators = text.replace(/\d/g, "");
158
+ if (separators === "") return {
159
+ integer: text,
160
+ fraction: "",
161
+ ambiguous: false
162
+ };
163
+ const candidate = arabicDecimal ? "." : separators.charAt(separators.length - 1);
164
+ const once = separators.split(candidate).length === 2;
165
+ if (arabicDecimal && !once) return null;
166
+ let decimal = null;
167
+ let ambiguous = false;
168
+ if (once && !GROUP_ONLY.has(candidate)) {
169
+ const at = text.lastIndexOf(candidate);
170
+ const before = text.slice(0, at);
171
+ if (arabicDecimal || separators.length > 1 || text.length - at - 1 !== 3 || before === "" || before.length > 3 || before.startsWith("0")) decimal = candidate;
172
+ else {
173
+ ambiguous = true;
174
+ decimal = candidate === decimalOfLocale ? candidate : null;
175
+ }
176
+ }
177
+ const at = decimal === null ? text.length : text.lastIndexOf(decimal);
178
+ const integerPart = text.slice(0, at);
179
+ const fraction = text.slice(at + 1);
180
+ if (!/^\d*$/.test(fraction)) return null;
181
+ const groupSeparators = integerPart.replace(/\d/g, "");
182
+ if (groupSeparators === "") return {
183
+ integer: integerPart,
184
+ fraction,
185
+ ambiguous
186
+ };
187
+ const group = groupSeparators.charAt(0);
188
+ if (groupSeparators !== group.repeat(groupSeparators.length) || !validGroups(integerPart.split(group))) return null;
189
+ return {
190
+ integer: integerPart.split(group).join(""),
191
+ fraction,
192
+ ambiguous
193
+ };
194
+ }
195
+ /** `integer.fraction` times ten to the `exponent`, as an exact decimal string without a sign. */
196
+ function shift(integer, fraction, exponent) {
197
+ const digits = integer + fraction;
198
+ const point = integer.length + exponent;
199
+ let whole;
200
+ let decimals;
201
+ if (exponent === 0) [whole, decimals] = [integer, fraction];
202
+ else if (point <= 0) [whole, decimals] = ["0", "0".repeat(-point) + digits];
203
+ else if (point >= digits.length) [whole, decimals] = [digits + "0".repeat(point - digits.length), ""];
204
+ else [whole, decimals] = [digits.slice(0, point), digits.slice(point)];
205
+ if (exponent !== 0) decimals = decimals.replace(/0+$/, "");
206
+ whole = whole.replace(/^0+(?=\d)/, "");
207
+ return decimals === "" ? whole : `${whole}.${decimals}`;
208
+ }
209
+ /**
210
+ * Reads a number the way people paste one: from a spreadsheet, a bank statement, an invoice
211
+ * or a web page, in any locale's format. The whole text must be one number, with at most a
212
+ * sign, a currency and a percent sign around it; anything else gives `null`.
213
+ *
214
+ * - Group separators `,` `.` `'` and spaces (no-break and narrow ones too), in groups of
215
+ * three or the lakh and crore grouping (`12,34,567`). Wrong grouping gives `null`.
216
+ * - The decimal separator is whichever of `,` and `.` the text shows is one (`1.234,5`,
217
+ * `1,5`, `0.500`); only a lone separator before three digits (`1,234`) is settled by `locale`.
218
+ * - `-`, `+`, `\u2212`, a trailing minus (`1234-`) and accounting brackets (`(1,234)`).
219
+ * - Currency symbols and ISO codes, before or after: `$`, `\u20AC`, `R$`, `kr`, `USD`, `CHF`.
220
+ * - `%` and `\u2030`, before or after; scientific notation (`1.5E-7`).
221
+ * - Digits of any script, full-width characters, and Arabic separators.
222
+ *
223
+ * @throws {CopyFailure} `invalid-payload` for a `locale` that is not one.
224
+ * @example
225
+ * parseNumber('1.234,50 \u20AC', { locale: 'de-DE' });
226
+ * // { value: 1234.5, exact: '1234.50', kind: 'number', currency: { symbol: '\u20AC', code: 'EUR' }, ambiguous: false }
227
+ */
228
+ function parseNumber(text, options = {}) {
229
+ const symbols = numberSymbols(options.locale ?? "en-US");
230
+ if (text.length > 256) return null;
231
+ const arabicDecimal = text.includes("٫");
232
+ const normalized = normalize(text.replace(/\u066B/g, "."));
233
+ let start = normalized.search(/\d/);
234
+ if (start === -1) return null;
235
+ if (/[.,]/.test(normalized.charAt(start - 1)) && !/\p{L}/u.test(normalized.charAt(start - 2))) start -= 1;
236
+ let end = normalized.length;
237
+ while (!/\d/.test(normalized.charAt(end - 1))) end -= 1;
238
+ const adornments = {
239
+ sign: "",
240
+ open: false,
241
+ close: false,
242
+ currency: null,
243
+ kind: "number"
244
+ };
245
+ if (!readAdornments(normalized.slice(0, start), adornments, "prefix") || !readAdornments(normalized.slice(end), adornments, "suffix")) return null;
246
+ if (adornments.open !== adornments.close || adornments.open && adornments.sign !== "") return null;
247
+ const core = normalized.slice(start, end);
248
+ const scientific = /^(\d*)(?:[.,](\d*))?[eE]([+-]?\d{1,3})$/.exec(core);
249
+ let mantissa;
250
+ if (scientific === null) mantissa = /^[\d.,' ]+$/.test(core) ? readMantissa(core, symbols.decimal, arabicDecimal) : null;
251
+ else mantissa = {
252
+ integer: String(scientific[1]),
253
+ fraction: scientific[2] ?? "",
254
+ ambiguous: false
255
+ };
256
+ if (mantissa === null) return null;
257
+ const exponent = scientific === null ? 0 : Number(scientific[3]);
258
+ if (Math.abs(exponent) > MAX_EXPONENT) return null;
259
+ const digits = shift(mantissa.integer === "" ? "0" : mantissa.integer, mantissa.fraction, exponent);
260
+ const zero = /^0(?:\.0*)?$/.test(digits);
261
+ const negative = (adornments.sign === "-" || adornments.open) && !zero;
262
+ const exact = negative ? `-${digits}` : digits;
263
+ const value = Number(exact);
264
+ if (!Number.isFinite(value)) return null;
265
+ if (options.negative === false && negative) return null;
266
+ if (options.fraction === false && /\.\d*[1-9]/.test(digits)) return null;
267
+ if (options.currency === false && adornments.currency !== null) return null;
268
+ if (options.percent === false && adornments.kind !== "number") return null;
269
+ if (adornments.currency !== null && adornments.kind !== "number") return null;
270
+ return {
271
+ value,
272
+ exact,
273
+ kind: adornments.kind,
274
+ currency: adornments.currency,
275
+ ambiguous: mantissa.ambiguous
276
+ };
277
+ }
278
+ //#endregion
279
+ //#region src/number/format.ts
280
+ /** Plain decimal notation, as `parseNumber` gives in `exact`: `-1234.50`, `0.00000015`. */
281
+ const EXACT = /^(-?)(\d+)(?:\.(\d+))?$/;
282
+ const NUMBER = /^(-?)(\d+)(?:\.(\d+))?(?:e([+-]\d+))?$/;
283
+ /** `value` as sign, integer digits and fraction digits, exactly. */
284
+ function decompose(value) {
285
+ if (typeof value === "bigint") {
286
+ const text = value.toString();
287
+ return text.startsWith("-") ? [
288
+ true,
289
+ text.slice(1),
290
+ ""
291
+ ] : [
292
+ false,
293
+ text,
294
+ ""
295
+ ];
296
+ }
297
+ if (typeof value === "number") {
298
+ if (!Number.isFinite(value)) throw require_errors.copyFailure("invalid-payload", `${String(value)} is not a finite number.`);
299
+ const match = NUMBER.exec(String(value));
300
+ const sign = String(match[1]);
301
+ const integer = String(match[2]);
302
+ const fraction = match[3] ?? "";
303
+ const shiftBy = Number(match[4] ?? "0");
304
+ const digits = integer + fraction;
305
+ const point = integer.length + shiftBy;
306
+ if (point <= 0) return [
307
+ sign === "-",
308
+ "0",
309
+ "0".repeat(-point) + digits
310
+ ];
311
+ if (point >= digits.length) return [
312
+ sign === "-",
313
+ digits + "0".repeat(point - digits.length),
314
+ ""
315
+ ];
316
+ return [
317
+ sign === "-",
318
+ digits.slice(0, point),
319
+ digits.slice(point)
320
+ ];
321
+ }
322
+ const match = EXACT.exec(value);
323
+ if (match === null) throw require_errors.copyFailure("invalid-payload", `"${value.slice(0, 40)}" is not a decimal number such as "-1234.5".`);
324
+ return [
325
+ match[1] === "-",
326
+ String(match[2]),
327
+ match[3] ?? ""
328
+ ];
329
+ }
330
+ /** `digits` plus one, carrying: `"199"` gives `"200"`, `"99"` gives `"100"`. */
331
+ function increment(digits) {
332
+ let out = "";
333
+ let carry = true;
334
+ for (let index = digits.length - 1; index >= 0; index -= 1) {
335
+ const digit = Number(digits.charAt(index)) + (carry ? 1 : 0);
336
+ carry = digit === 10;
337
+ out = String(digit % 10) + out;
338
+ }
339
+ return carry ? `1${out}` : out;
340
+ }
341
+ /** Groups `integer` from the right: the last group of `primary` digits, the others of `secondary`. */
342
+ function group(integer, separator, primary, secondary) {
343
+ if (integer.length <= primary) return integer;
344
+ const groups = [integer.slice(-primary)];
345
+ let rest = integer.slice(0, -primary);
346
+ while (rest.length > secondary) {
347
+ groups.unshift(rest.slice(-secondary));
348
+ rest = rest.slice(0, -secondary);
349
+ }
350
+ groups.unshift(rest);
351
+ return groups.join(separator);
352
+ }
353
+ /**
354
+ * Writes a number in a locale's format, exactly: no float rounding, whatever its size.
355
+ * Takes a `number`, a `bigint`, or an exact decimal string (`parseNumber`'s `exact`), so
356
+ * money read from one locale can be written in another without losing a cent.
357
+ *
358
+ * @throws {CopyFailure} `invalid-payload` for a number that is not finite, a string that is
359
+ * not plain decimal notation, a `fractionDigits` out of range, or a `locale` that is not one.
360
+ * @example
361
+ * formatNumber('1234.5', { locale: 'de-DE', grouping: true, fractionDigits: 2 }); // "1.234,50"
362
+ */
363
+ function formatNumber(value, options = {}) {
364
+ const symbols = numberSymbols(options.locale ?? "en-US");
365
+ const digits = options.fractionDigits;
366
+ if (digits !== void 0 && !(Number.isInteger(digits) && digits >= 0 && digits <= 100)) throw require_errors.copyFailure("invalid-payload", `fractionDigits must be a whole number from 0 to 100, not ${String(digits)}.`);
367
+ const [negative, rawInteger, rawFraction] = decompose(value);
368
+ let integer = rawInteger.replace(/^0+(?=\d)/, "");
369
+ let fraction = rawFraction;
370
+ if (digits !== void 0) {
371
+ if (fraction.length > digits) {
372
+ const roundUp = fraction.charAt(digits) >= "5";
373
+ fraction = fraction.slice(0, digits);
374
+ if (roundUp) {
375
+ const rounded = increment(integer + fraction);
376
+ integer = rounded.slice(0, rounded.length - digits);
377
+ fraction = rounded.slice(rounded.length - digits);
378
+ }
379
+ } else fraction = fraction.padEnd(digits, "0");
380
+ }
381
+ const zero = /^0*$/.test(integer + fraction);
382
+ const whole = options.grouping === true ? group(integer, symbols.group, symbols.primary, symbols.secondary) : integer;
383
+ return `${negative && !zero ? "-" : ""}${whole}${fraction === "" ? "" : symbols.decimal + fraction}`;
384
+ }
385
+ /**
386
+ * A copy payload for a number, written for the locale it will be pasted in: ungrouped by
387
+ * default, so a spreadsheet reads it as a number. Pass it to `copy()` or `useCopy`.
388
+ *
389
+ * @example
390
+ * copy(numberPayload(invoice.total, { locale: navigator.language, fractionDigits: 2 }));
391
+ */
392
+ function numberPayload(value, options = {}) {
393
+ return {
394
+ kind: "text",
395
+ value: formatNumber(value, options)
396
+ };
397
+ }
398
+ //#endregion
399
+ //#region src/number/paste.ts
400
+ function asNumberInput(target) {
401
+ const element = target;
402
+ return element?.nodeName === "INPUT" && element.type === "number" ? target : null;
403
+ }
404
+ /**
405
+ * A paste handler for number and amount fields. People paste `1.234,50 €` from a bank
406
+ * statement, `$1,234.50` from an invoice, or `(1,234)` from a spreadsheet; a browser either
407
+ * rejects these from `<input type="number">` or keeps the text as it is. This reads the
408
+ * number, inserts it the way the field takes it (with undo intact in text fields), and
409
+ * turns away pastes that are not a number.
410
+ *
411
+ * Works on `<input type="number">`, text `<input>`s (use `inputmode="decimal"`) and
412
+ * `<textarea>`s; other elements are left to the browser.
413
+ *
414
+ * @example
415
+ * <input inputMode="decimal" onPaste={(event) => pasteAsNumber(event, { locale: 'de-DE' })} />
416
+ */
417
+ function pasteAsNumber(event, options = {}) {
418
+ if (event.defaultPrevented || event.clipboardData === null) return "ignored";
419
+ const numberInput = asNumberInput(event.currentTarget) ?? asNumberInput(event.target);
420
+ const field = numberInput ?? require_text_field.asTextField(event.currentTarget) ?? require_text_field.asTextField(event.target);
421
+ if (field === null) return "ignored";
422
+ const text = event.clipboardData.getData("text/plain");
423
+ if (text === "") return "ignored";
424
+ event.preventDefault();
425
+ const parsed = parseNumber(text.trim(), options);
426
+ if (parsed !== null && !field.disabled && !field.readOnly) {
427
+ options.onNumber?.(parsed);
428
+ const value = options.format?.(parsed) ?? (numberInput === null ? formatNumber(parsed.exact, options) : parsed.exact);
429
+ if (numberInput === null ? require_text_field.insertText(field, value) : require_text_field.replaceFieldValue(numberInput, value)) return "pasted";
430
+ }
431
+ options.onReject?.(text);
432
+ return "rejected";
433
+ }
434
+ //#endregion
435
+ exports.NUMBER_MAX_LENGTH = NUMBER_MAX_LENGTH;
436
+ exports.formatNumber = formatNumber;
437
+ exports.numberPayload = numberPayload;
438
+ exports.numberSymbols = numberSymbols;
439
+ exports.parseNumber = parseNumber;
440
+ exports.pasteAsNumber = pasteAsNumber;
441
+
442
+ //# sourceMappingURL=number.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"number.cjs","names":["copyFailure","asciiDigits","copyFailure","asTextField","insertText","replaceFieldValue"],"sources":["../src/number/currency.ts","../src/number/locale.ts","../src/number/parse.ts","../src/number/format.ts","../src/number/paste.ts"],"sourcesContent":["/** A currency written next to a number. */\nexport interface NumberCurrency {\n /** As it was written, normalized: `\\u20AC`, `R$`, `kr`, `USD`. */\n readonly symbol: string;\n /** Its ISO 4217 code, when the symbol names one currency: `null` for `$`, `\\u00A5`, `kr` and `Rs`. */\n readonly code: string | null;\n}\n\n/**\n * Currency symbols, after NFKC (so `\\uFF04` is `$` and `\\u20A8` is `Rs`). Symbols that several\n * currencies share have no code: the text alone can't tell a dollar from another.\n */\nconst SYMBOLS: readonly (readonly [string, string | null])[] = [\n ['US$', 'USD'], ['CA$', 'CAD'], ['C$', 'CAD'], ['AU$', 'AUD'], ['A$', 'AUD'], ['NZ$', 'NZD'], ['HK$', 'HKD'],\n ['S$', 'SGD'], ['R$', 'BRL'], ['MX$', 'MXN'], ['NT$', 'TWD'], ['$', null],\n ['\\u20AC', 'EUR'], ['\\u00A3', 'GBP'], ['JP\\u00A5', 'JPY'], ['CN\\u00A5', 'CNY'], ['\\u00A5', null],\n ['\\u20B9', 'INR'], ['Rs.', null], ['Rs', null], ['\\u20A9', 'KRW'], ['\\u20BD', 'RUB'], ['\\u20BA', 'TRY'],\n ['\\u20AA', 'ILS'], ['\\u20AB', 'VND'], ['\\u20B1', 'PHP'], ['\\u0E3F', 'THB'], ['\\u20B4', 'UAH'], ['\\u20A6', 'NGN'],\n ['\\u20B8', 'KZT'], ['\\u09F3', 'BDT'], ['z\\u0142', 'PLN'], ['K\\u010D', 'CZK'], ['kr.', null], ['kr', null], ['Fr.', 'CHF'],\n];\n\n/** Longest first, so `US$` is read before `$` and `Rs.` before `Rs`. */\nconst BY_LENGTH = [...SYMBOLS].sort((a, b) => b[0].length - a[0].length).map(([symbol, code]) => [symbol, symbol.toLowerCase(), code] as const);\n\nlet codes: ReadonlySet<string> | null | undefined;\n\n/** Whether `code` (upper case) is an ISO 4217 code the runtime knows; any three letters where it can't say. */\nexport function isCurrencyCode(code: string): boolean {\n if (codes === undefined) {\n const supported = (Intl as { supportedValuesOf?: (key: 'currency') => string[] }).supportedValuesOf;\n codes = typeof supported === 'function' ? new Set(supported('currency')) : null;\n }\n return /^[A-Z]{3}$/.test(code) && (codes === null || codes.has(code));\n}\n\n/** For tests: forget the runtime's codes, so they are read again. */\nexport function resetCurrencyCodes(): void {\n codes = undefined;\n}\n\nconst LETTER = /\\p{L}/u;\n\n/**\n * The currency at the start of `text`, and how many characters it takes. A symbol or code\n * made of letters must end there: `Rs` is not read from `Rsx`, nor `USD` from `USDT`.\n */\nexport function readCurrency(text: string): { readonly currency: NumberCurrency; readonly length: number } | null {\n const lower = text.toLowerCase();\n for (const [symbol, key, code] of BY_LENGTH) {\n if (lower.startsWith(key) && !(LETTER.test(symbol.slice(-1)) && LETTER.test(text.charAt(key.length)))) {\n return { currency: { symbol, code }, length: key.length };\n }\n }\n const word = /^\\p{L}+/u.exec(text)?.[0] ?? '';\n const code = word.toUpperCase();\n return word.length === 3 && isCurrencyCode(code) ? { currency: { symbol: code, code }, length: 3 } : null;\n}\n","import { copyFailure } from '../core/errors';\n\n/** How a locale writes numbers, in Latin digits. */\nexport interface NumberSymbols {\n /** The decimal separator. */\n readonly decimal: '.' | ',';\n /** The group separator, as the locale writes it (a no-break space in French, for one); `''` for none. */\n readonly group: string;\n /** Digits in the last group of the integer part: 3 almost everywhere. */\n readonly primary: number;\n /** Digits in the groups before it: 2 in India's lakh and crore grouping, 3 elsewhere. */\n readonly secondary: number;\n}\n\nconst cache = new Map<string, NumberSymbols>();\nconst CACHE_SIZE = 32;\n\n/**\n * How `locale` writes numbers, from `Intl.NumberFormat`.\n *\n * @throws {CopyFailure} `invalid-payload` for a string that is not a locale.\n */\nexport function numberSymbols(locale: string): NumberSymbols {\n const cached = cache.get(locale);\n if (cached !== undefined) return cached;\n let parts: Intl.NumberFormatPart[];\n try {\n parts = new Intl.NumberFormat(locale, { numberingSystem: 'latn' }).formatToParts(123456789012.5);\n } catch (cause) {\n throw copyFailure('invalid-payload', `\"${locale}\" is not a locale.`, cause);\n }\n // 123,456,789,012 in most locales; 1,23,45,67,89,012 in India's.\n const integers = parts.filter((part) => part.type === 'integer').map((part) => part.value.length);\n const symbols: NumberSymbols = {\n decimal: parts.some((part) => part.type === 'decimal' && part.value === ',') ? ',' : '.',\n // A locale that writes no group separator has none to add.\n group: parts.find((part) => part.type === 'group')?.value ?? '',\n primary: Number(integers[integers.length - 1]),\n secondary: Number(integers[Math.max(0, integers.length - 2)]),\n };\n // A small cache: locales come from settings, but a hostile caller could pass many.\n if (cache.size >= CACHE_SIZE) cache.clear();\n cache.set(locale, symbols);\n return symbols;\n}\n","import { asciiDigits } from '../core/digits';\nimport { readCurrency, type NumberCurrency } from './currency';\nimport { numberSymbols } from './locale';\n\n/** What a number was written as: `12` is a number, `12%` a percentage, `12\\u2030` per mille. */\nexport type NumberKind = 'number' | 'percent' | 'permille';\n\n/** A number read from text. */\nexport interface ParsedNumber {\n /** The number as written: `12` for `12%`, `-1234.5` for `(1.234,50 \\u20AC)`. */\n readonly value: number;\n /**\n * The same number as an exact decimal string, without rounding: `-1234.50` keeps its\n * trailing zero, and `0.1` is not `0.1000000000000000055\\u2026`. Use it for money.\n */\n readonly exact: string;\n /** `'percent'` or `'permille'` when the number was written with `%` or `\\u2030`. */\n readonly kind: NumberKind;\n /** The currency written with it, if any. */\n readonly currency: NumberCurrency | null;\n /**\n * The text had one `,` or `.` before exactly three digits (`1,234`, `1.234`): a group\n * separator in some locales and a decimal separator in others. `locale` decided which;\n * ask the person when it matters.\n */\n readonly ambiguous: boolean;\n}\n\nexport interface ParseNumberOptions {\n /**\n * The locale whose decimal separator settles an ambiguous `1,234` or `1.234`: grouping\n * in `en-US`, a decimal in `de-DE`. Default `'en-US'`. Text that can only be read one way\n * is read that way in every locale: `1.234,5` is 1234.5 everywhere.\n */\n readonly locale?: string;\n /** Accept negative numbers. Default `true`. */\n readonly negative?: boolean;\n /** Accept numbers with a fractional part. Default `true`. */\n readonly fraction?: boolean;\n /** Accept a currency symbol or code. Default `true`. */\n readonly currency?: boolean;\n /** Accept `%` and `\\u2030`. Default `true`. */\n readonly percent?: boolean;\n}\n\n/** Longer text holds more than a number: it is not read at all. */\nexport const NUMBER_MAX_LENGTH = 256;\n\n/** Group separators that are never decimal separators: spaces and apostrophes. */\nconst GROUP_ONLY = new Set([' ', \"'\"]);\n/** The largest exponent read from scientific notation, past which no number is finite. */\nconst MAX_EXPONENT = 400;\n\ninterface Adornments {\n sign: '' | '-' | '+';\n /** An opening bracket before the number, and a closing one after it: accounting's minus. */\n open: boolean;\n close: boolean;\n currency: NumberCurrency | null;\n kind: NumberKind;\n}\n\n/**\n * Reads the signs, brackets, currency and percent on one side of the number. Returns\n * `false` when something else is there, or when one of them appears twice.\n */\nfunction readAdornments(text: string, into: Adornments, side: 'prefix' | 'suffix'): boolean {\n let rest = text;\n for (;;) {\n rest = rest.trimStart();\n if (rest === '') return true;\n const char = rest.charAt(0);\n let length = 1;\n if (char === '(' && side === 'prefix' && !into.open) into.open = true;\n else if (char === ')' && side === 'suffix' && !into.close) into.close = true;\n // A minus after the number is a trailing minus (`1234-`), as some accounting systems write it.\n else if ((char === '-' || (char === '+' && side === 'prefix')) && into.sign === '') into.sign = char;\n else if ((char === '%' || char === '\\u2030') && into.kind === 'number') into.kind = char === '%' ? 'percent' : 'permille';\n else {\n const read = into.currency === null ? readCurrency(rest) : null;\n if (read === null) return false;\n into.currency = read.currency;\n length = read.length;\n }\n rest = rest.slice(length);\n }\n}\n\n/** The text in a form the reader understands: ASCII digits, one minus, one apostrophe, plain spaces. */\nfunction normalize(text: string): string {\n return (\n asciiDigits(text)\n // Minus signs and dashes used as one.\n .replace(/[\\u2212\\u2012\\u2013]/g, '-')\n // Arabic percent sign; Arabic decimal and thousands separators come next.\n .replace(/\\u066A/g, '%')\n .replace(/[\\u2019\\u02BC\\u066C]/g, \"'\")\n .replace(/\\s/g, ' ')\n );\n}\n\n/** Whether `groups` (the integer part, split at its group separator) are grouped the way locales group. */\nfunction validGroups(groups: readonly string[]): boolean {\n const [first, ...rest] = groups;\n if (first === undefined || first === '' || first.length > 3 || rest.length === 0) return false;\n if (rest.every((group) => group.length === 3)) return true;\n // Lakh and crore: 12,34,567. The last group has 3 digits and the others 2.\n return first.length <= 2 && rest.slice(0, -1).every((group) => group.length === 2) && rest[rest.length - 1]?.length === 3;\n}\n\ninterface Mantissa {\n readonly integer: string;\n readonly fraction: string;\n readonly ambiguous: boolean;\n}\n\n/** The integer and fractional digits of `text` (digits and separators only), or `null`. */\nfunction readMantissa(text: string, decimalOfLocale: '.' | ',', arabicDecimal: boolean): Mantissa | null {\n const separators = text.replace(/\\d/g, '');\n if (separators === '') return { integer: text, fraction: '', ambiguous: false };\n // The decimal separator can only be the last separator, appearing once: `1,234,567.8`,\n // `1.234,5`. An Arabic decimal separator is one wherever it is.\n const candidate = arabicDecimal ? '.' : separators.charAt(separators.length - 1);\n const once = separators.split(candidate).length === 2;\n if (arabicDecimal && !once) return null;\n let decimal: string | null = null;\n let ambiguous = false;\n if (once && !GROUP_ONLY.has(candidate)) {\n const at = text.lastIndexOf(candidate);\n const before = text.slice(0, at);\n // A lone separator is a decimal unless it could also start a group of three.\n if (arabicDecimal || separators.length > 1 || text.length - at - 1 !== 3 || before === '' || before.length > 3 || before.startsWith('0')) decimal = candidate;\n else {\n ambiguous = true;\n decimal = candidate === decimalOfLocale ? candidate : null;\n }\n }\n const at = decimal === null ? text.length : text.lastIndexOf(decimal);\n const integerPart = text.slice(0, at);\n const fraction = text.slice(at + 1);\n if (!/^\\d*$/.test(fraction)) return null;\n const groupSeparators = integerPart.replace(/\\d/g, '');\n if (groupSeparators === '') return { integer: integerPart, fraction, ambiguous };\n const group = groupSeparators.charAt(0);\n if (groupSeparators !== group.repeat(groupSeparators.length) || !validGroups(integerPart.split(group))) return null;\n return { integer: integerPart.split(group).join(''), fraction, ambiguous };\n}\n\n/** `integer.fraction` times ten to the `exponent`, as an exact decimal string without a sign. */\nfunction shift(integer: string, fraction: string, exponent: number): string {\n const digits = integer + fraction;\n const point = integer.length + exponent;\n let whole: string;\n let decimals: string;\n if (exponent === 0) [whole, decimals] = [integer, fraction];\n else if (point <= 0) [whole, decimals] = ['0', '0'.repeat(-point) + digits];\n else if (point >= digits.length) [whole, decimals] = [digits + '0'.repeat(point - digits.length), ''];\n else [whole, decimals] = [digits.slice(0, point), digits.slice(point)];\n // Scientific notation's own trailing zeros say nothing about precision: they go.\n if (exponent !== 0) decimals = decimals.replace(/0+$/, '');\n whole = whole.replace(/^0+(?=\\d)/, '');\n return decimals === '' ? whole : `${whole}.${decimals}`;\n}\n\n/**\n * Reads a number the way people paste one: from a spreadsheet, a bank statement, an invoice\n * or a web page, in any locale's format. The whole text must be one number, with at most a\n * sign, a currency and a percent sign around it; anything else gives `null`.\n *\n * - Group separators `,` `.` `'` and spaces (no-break and narrow ones too), in groups of\n * three or the lakh and crore grouping (`12,34,567`). Wrong grouping gives `null`.\n * - The decimal separator is whichever of `,` and `.` the text shows is one (`1.234,5`,\n * `1,5`, `0.500`); only a lone separator before three digits (`1,234`) is settled by `locale`.\n * - `-`, `+`, `\\u2212`, a trailing minus (`1234-`) and accounting brackets (`(1,234)`).\n * - Currency symbols and ISO codes, before or after: `$`, `\\u20AC`, `R$`, `kr`, `USD`, `CHF`.\n * - `%` and `\\u2030`, before or after; scientific notation (`1.5E-7`).\n * - Digits of any script, full-width characters, and Arabic separators.\n *\n * @throws {CopyFailure} `invalid-payload` for a `locale` that is not one.\n * @example\n * parseNumber('1.234,50 \\u20AC', { locale: 'de-DE' });\n * // { value: 1234.5, exact: '1234.50', kind: 'number', currency: { symbol: '\\u20AC', code: 'EUR' }, ambiguous: false }\n */\nexport function parseNumber(text: string, options: ParseNumberOptions = {}): ParsedNumber | null {\n const symbols = numberSymbols(options.locale ?? 'en-US');\n if (text.length > NUMBER_MAX_LENGTH) return null;\n const arabicDecimal = text.includes('\\u066B');\n const normalized = normalize(text.replace(/\\u066B/g, '.'));\n // The number: from its first digit (or a separator right before it, as in `.5`) to its last\n // digit. Not a dot that ends a word (`Rs.5` is 5 rupees).\n let start = normalized.search(/\\d/);\n if (start === -1) return null;\n if (/[.,]/.test(normalized.charAt(start - 1)) && !/\\p{L}/u.test(normalized.charAt(start - 2))) start -= 1;\n let end = normalized.length;\n while (!/\\d/.test(normalized.charAt(end - 1))) end -= 1;\n const adornments: Adornments = { sign: '', open: false, close: false, currency: null, kind: 'number' };\n if (!readAdornments(normalized.slice(0, start), adornments, 'prefix') || !readAdornments(normalized.slice(end), adornments, 'suffix')) return null;\n // Brackets come in pairs, and mean the minus: `-(5)` is a typo, not a number.\n if (adornments.open !== adornments.close || (adornments.open && adornments.sign !== '')) return null;\n\n const core = normalized.slice(start, end);\n // Scientific notation, as spreadsheets copy it: one decimal separator, never grouped.\n const scientific = /^(\\d*)(?:[.,](\\d*))?[eE]([+-]?\\d{1,3})$/.exec(core);\n let mantissa: Mantissa | null;\n if (scientific === null) mantissa = /^[\\d.,' ]+$/.test(core) ? readMantissa(core, symbols.decimal, arabicDecimal) : null;\n else mantissa = { integer: String(scientific[1]), fraction: scientific[2] ?? '', ambiguous: false };\n if (mantissa === null) return null;\n const exponent = scientific === null ? 0 : Number(scientific[3]);\n if (Math.abs(exponent) > MAX_EXPONENT) return null;\n\n const digits = shift(mantissa.integer === '' ? '0' : mantissa.integer, mantissa.fraction, exponent);\n const zero = /^0(?:\\.0*)?$/.test(digits);\n const negative = (adornments.sign === '-' || adornments.open) && !zero;\n const exact = negative ? `-${digits}` : digits;\n const value = Number(exact);\n if (!Number.isFinite(value)) return null;\n\n if (options.negative === false && negative) return null;\n if (options.fraction === false && /\\.\\d*[1-9]/.test(digits)) return null;\n if (options.currency === false && adornments.currency !== null) return null;\n if (options.percent === false && adornments.kind !== 'number') return null;\n if (adornments.currency !== null && adornments.kind !== 'number') return null;\n return { value, exact, kind: adornments.kind, currency: adornments.currency, ambiguous: mantissa.ambiguous };\n}\n","import { copyFailure } from '../core/errors';\nimport type { TextPayload } from '../core/payload';\nimport { numberSymbols } from './locale';\n\nexport interface FormatNumberOptions {\n /** The locale whose decimal and group separators to use. Default `'en-US'`. Digits are always Latin. */\n readonly locale?: string;\n /**\n * Group the integer part (`1,234,567`; `12,34,567` in `en-IN`). Default `false`: spreadsheets\n * read ungrouped numbers in every locale, and grouped ones only in their own.\n */\n readonly grouping?: boolean;\n /** Exactly this many decimals (0 to 100), rounding half away from zero. Default: as many as the number has. */\n readonly fractionDigits?: number;\n}\n\n/** Plain decimal notation, as `parseNumber` gives in `exact`: `-1234.50`, `0.00000015`. */\nconst EXACT = /^(-?)(\\d+)(?:\\.(\\d+))?$/;\nconst NUMBER = /^(-?)(\\d+)(?:\\.(\\d+))?(?:e([+-]\\d+))?$/;\n\n/** `value` as sign, integer digits and fraction digits, exactly. */\nfunction decompose(value: number | string | bigint): readonly [boolean, string, string] {\n if (typeof value === 'bigint') {\n const text = value.toString();\n return text.startsWith('-') ? [true, text.slice(1), ''] : [false, text, ''];\n }\n if (typeof value === 'number') {\n if (!Number.isFinite(value)) throw copyFailure('invalid-payload', `${String(value)} is not a finite number.`);\n // `String` gives the shortest text that reads back as the same number: 0.1 is `0.1`.\n const match = NUMBER.exec(String(value)) as RegExpExecArray;\n const sign = String(match[1]);\n const integer = String(match[2]);\n const fraction = match[3] ?? '';\n const shiftBy = Number(match[4] ?? '0');\n const digits = integer + fraction;\n const point = integer.length + shiftBy;\n if (point <= 0) return [sign === '-', '0', '0'.repeat(-point) + digits];\n if (point >= digits.length) return [sign === '-', digits + '0'.repeat(point - digits.length), ''];\n return [sign === '-', digits.slice(0, point), digits.slice(point)];\n }\n const match = EXACT.exec(value);\n if (match === null) throw copyFailure('invalid-payload', `\"${value.slice(0, 40)}\" is not a decimal number such as \"-1234.5\".`);\n return [match[1] === '-', String(match[2]), match[3] ?? ''];\n}\n\n/** `digits` plus one, carrying: `\"199\"` gives `\"200\"`, `\"99\"` gives `\"100\"`. */\nfunction increment(digits: string): string {\n let out = '';\n let carry = true;\n for (let index = digits.length - 1; index >= 0; index -= 1) {\n const digit: number = Number(digits.charAt(index)) + (carry ? 1 : 0);\n carry = digit === 10;\n out = String(digit % 10) + out;\n }\n return carry ? `1${out}` : out;\n}\n\n/** Groups `integer` from the right: the last group of `primary` digits, the others of `secondary`. */\nfunction group(integer: string, separator: string, primary: number, secondary: number): string {\n if (integer.length <= primary) return integer;\n const groups = [integer.slice(-primary)];\n let rest = integer.slice(0, -primary);\n while (rest.length > secondary) {\n groups.unshift(rest.slice(-secondary));\n rest = rest.slice(0, -secondary);\n }\n groups.unshift(rest);\n return groups.join(separator);\n}\n\n/**\n * Writes a number in a locale's format, exactly: no float rounding, whatever its size.\n * Takes a `number`, a `bigint`, or an exact decimal string (`parseNumber`'s `exact`), so\n * money read from one locale can be written in another without losing a cent.\n *\n * @throws {CopyFailure} `invalid-payload` for a number that is not finite, a string that is\n * not plain decimal notation, a `fractionDigits` out of range, or a `locale` that is not one.\n * @example\n * formatNumber('1234.5', { locale: 'de-DE', grouping: true, fractionDigits: 2 }); // \"1.234,50\"\n */\nexport function formatNumber(value: number | string | bigint, options: FormatNumberOptions = {}): string {\n const symbols = numberSymbols(options.locale ?? 'en-US');\n const digits = options.fractionDigits;\n if (digits !== undefined && !(Number.isInteger(digits) && digits >= 0 && digits <= 100)) {\n throw copyFailure('invalid-payload', `fractionDigits must be a whole number from 0 to 100, not ${String(digits)}.`);\n }\n const [negative, rawInteger, rawFraction] = decompose(value);\n let integer = rawInteger.replace(/^0+(?=\\d)/, '');\n let fraction = rawFraction;\n if (digits !== undefined) {\n if (fraction.length > digits) {\n const roundUp = fraction.charAt(digits) >= '5';\n fraction = fraction.slice(0, digits);\n if (roundUp) {\n const rounded = increment(integer + fraction);\n integer = rounded.slice(0, rounded.length - digits);\n fraction = rounded.slice(rounded.length - digits);\n }\n } else fraction = fraction.padEnd(digits, '0');\n }\n const zero = /^0*$/.test(integer + fraction);\n const whole = options.grouping === true ? group(integer, symbols.group, symbols.primary, symbols.secondary) : integer;\n return `${negative && !zero ? '-' : ''}${whole}${fraction === '' ? '' : symbols.decimal + fraction}`;\n}\n\n/**\n * A copy payload for a number, written for the locale it will be pasted in: ungrouped by\n * default, so a spreadsheet reads it as a number. Pass it to `copy()` or `useCopy`.\n *\n * @example\n * copy(numberPayload(invoice.total, { locale: navigator.language, fractionDigits: 2 }));\n */\nexport function numberPayload(value: number | string | bigint, options: FormatNumberOptions = {}): TextPayload {\n return { kind: 'text', value: formatNumber(value, options) };\n}\n","import { asTextField, insertText, replaceFieldValue, type TextField } from '../core/text-field';\nimport { formatNumber } from './format';\nimport { parseNumber, type ParsedNumber, type ParseNumberOptions } from './parse';\n\n/** What {@link pasteAsNumber} did. */\nexport type NumberPasteOutcome =\n /** The paste held a number: it was inserted, written the way the field takes it. */\n | 'pasted'\n /** The paste was not a number (or the field is read-only): nothing was inserted. */\n | 'rejected'\n /** Not a paste for this handler (no text, already handled, or not a text or number field): left to the browser. */\n | 'ignored';\n\nexport interface PasteAsNumberOptions extends ParseNumberOptions {\n /**\n * How to write the number into the field. Default: `exact` for `<input type=\"number\">`,\n * which only takes `.` as the decimal separator; elsewhere the number in `locale`'s format,\n * ungrouped (`1234,5` in `de-DE`).\n */\n readonly format?: (parsed: ParsedNumber) => string;\n /** Called with the number before it is inserted: show `ambiguous` readings here. */\n readonly onNumber?: (parsed: ParsedNumber) => void;\n /** Called with the pasted text when it was not a number, or the field takes no input. */\n readonly onReject?: (text: string) => void;\n}\n\n/** Structural paste event: a DOM `ClipboardEvent` and React's `onPaste` event both fit. */\nexport interface NumberPasteEvent {\n readonly clipboardData: { getData(format: string): string } | null;\n readonly currentTarget: EventTarget | null;\n readonly target: EventTarget | null;\n readonly defaultPrevented: boolean;\n preventDefault(): void;\n}\n\nfunction asNumberInput(target: EventTarget | null): HTMLInputElement | null {\n const element = target as (Partial<Element> & { type?: unknown }) | null;\n return element?.nodeName === 'INPUT' && element.type === 'number' ? (target as HTMLInputElement) : null;\n}\n\n/**\n * A paste handler for number and amount fields. People paste `1.234,50 €` from a bank\n * statement, `$1,234.50` from an invoice, or `(1,234)` from a spreadsheet; a browser either\n * rejects these from `<input type=\"number\">` or keeps the text as it is. This reads the\n * number, inserts it the way the field takes it (with undo intact in text fields), and\n * turns away pastes that are not a number.\n *\n * Works on `<input type=\"number\">`, text `<input>`s (use `inputmode=\"decimal\"`) and\n * `<textarea>`s; other elements are left to the browser.\n *\n * @example\n * <input inputMode=\"decimal\" onPaste={(event) => pasteAsNumber(event, { locale: 'de-DE' })} />\n */\nexport function pasteAsNumber(event: NumberPasteEvent, options: PasteAsNumberOptions = {}): NumberPasteOutcome {\n if (event.defaultPrevented || event.clipboardData === null) return 'ignored';\n const numberInput = asNumberInput(event.currentTarget) ?? asNumberInput(event.target);\n const field: TextField | null = numberInput ?? asTextField(event.currentTarget) ?? asTextField(event.target);\n if (field === null) return 'ignored';\n const text = event.clipboardData.getData('text/plain');\n if (text === '') return 'ignored';\n event.preventDefault();\n const parsed = parseNumber(text.trim(), options);\n if (parsed !== null && !field.disabled && !field.readOnly) {\n options.onNumber?.(parsed);\n const value = options.format?.(parsed) ?? (numberInput === null ? formatNumber(parsed.exact, options) : parsed.exact);\n if (numberInput === null ? insertText(field, value) : replaceFieldValue(numberInput, value)) return 'pasted';\n }\n options.onReject?.(text);\n return 'rejected';\n}\n"],"mappings":";;;;;;;AAsBA,MAAM,YAAY,CAAC,GAAG;CATpB,CAAC,OAAO,KAAK;CAAG,CAAC,OAAO,KAAK;CAAG,CAAC,MAAM,KAAK;CAAG,CAAC,OAAO,KAAK;CAAG,CAAC,MAAM,KAAK;CAAG,CAAC,OAAO,KAAK;CAAG,CAAC,OAAO,KAAK;CAC3G,CAAC,MAAM,KAAK;CAAG,CAAC,MAAM,KAAK;CAAG,CAAC,OAAO,KAAK;CAAG,CAAC,OAAO,KAAK;CAAG,CAAC,KAAK,IAAI;CACxE,CAAC,KAAU,KAAK;CAAG,CAAC,KAAU,KAAK;CAAG,CAAC,OAAY,KAAK;CAAG,CAAC,OAAY,KAAK;CAAG,CAAC,KAAU,IAAI;CAC/F,CAAC,KAAU,KAAK;CAAG,CAAC,OAAO,IAAI;CAAG,CAAC,MAAM,IAAI;CAAG,CAAC,KAAU,KAAK;CAAG,CAAC,KAAU,KAAK;CAAG,CAAC,KAAU,KAAK;CACtG,CAAC,KAAU,KAAK;CAAG,CAAC,KAAU,KAAK;CAAG,CAAC,KAAU,KAAK;CAAG,CAAC,KAAU,KAAK;CAAG,CAAC,KAAU,KAAK;CAAG,CAAC,KAAU,KAAK;CAC/G,CAAC,KAAU,KAAK;CAAG,CAAC,KAAU,KAAK;CAAG,CAAC,MAAW,KAAK;CAAG,CAAC,MAAW,KAAK;CAAG,CAAC,OAAO,IAAI;CAAG,CAAC,MAAM,IAAI;CAAG,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