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.
Files changed (44) hide show
  1. package/README.md +67 -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-BHo5y-t_.js +535 -0
  7. package/dist/chunks/field-BHo5y-t_.js.map +1 -0
  8. package/dist/chunks/field-BTsKTs2M.d.cts +87 -0
  9. package/dist/chunks/field-BTsKTs2M.d.ts +87 -0
  10. package/dist/chunks/field-Bytz2WfN.cjs +558 -0
  11. package/dist/chunks/field-Bytz2WfN.cjs.map +1 -0
  12. package/dist/chunks/{text-field-Ba8W3v4R.cjs → text-field-BEzUVOag.cjs} +26 -5
  13. package/dist/chunks/text-field-BEzUVOag.cjs.map +1 -0
  14. package/dist/chunks/{text-field-DUvrMMaK.js → text-field-D7PF2WlX.js} +21 -6
  15. package/dist/chunks/text-field-D7PF2WlX.js.map +1 -0
  16. package/dist/code.cjs +1 -1
  17. package/dist/code.js +1 -1
  18. package/dist/color.cjs +1 -1
  19. package/dist/color.js +1 -1
  20. package/dist/index.cjs +89 -0
  21. package/dist/index.cjs.map +1 -1
  22. package/dist/index.d.cts +42 -1
  23. package/dist/index.d.ts +42 -1
  24. package/dist/index.js +89 -1
  25. package/dist/index.js.map +1 -1
  26. package/dist/link.cjs +1 -1
  27. package/dist/link.js +1 -1
  28. package/dist/markdown.cjs +1 -1
  29. package/dist/markdown.js +1 -1
  30. package/dist/number.cjs +442 -0
  31. package/dist/number.cjs.map +1 -0
  32. package/dist/number.d.cts +172 -0
  33. package/dist/number.d.ts +172 -0
  34. package/dist/number.js +436 -0
  35. package/dist/number.js.map +1 -0
  36. package/dist/otp.cjs +7 -0
  37. package/dist/otp.d.cts +54 -0
  38. package/dist/otp.d.ts +54 -0
  39. package/dist/otp.js +2 -0
  40. package/dist/secrets.cjs +1 -1
  41. package/dist/secrets.js +1 -1
  42. package/package.json +71 -3
  43. package/dist/chunks/text-field-Ba8W3v4R.cjs.map +0 -1
  44. package/dist/chunks/text-field-DUvrMMaK.js.map +0 -1
package/dist/secrets.js CHANGED
@@ -1,6 +1,6 @@
1
1
 
2
2
  import { n as copyFailure } from "./chunks/errors-9h8sdFFX.js";
3
- import { n as insertText, t as asTextField } from "./chunks/text-field-DUvrMMaK.js";
3
+ import { n as insertText, t as asTextField } from "./chunks/text-field-D7PF2WlX.js";
4
4
  //#region src/secrets/checks.ts
5
5
  /** Checks that tell real secrets from look-alikes: checksums, structure and randomness. */
6
6
  /** The Luhn checksum of card numbers. `digits` holds only digits. */
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "react-smart-copy",
3
- "version": "1.21.0",
4
- "description": "Headless, type-safe clipboard interactions for React: copy and paste text, rich HTML, images, spreadsheet tables, typed application data, Markdown, code, privacy-safe images, links, sharing, colours, portable rich text, clean pastes from Word and Google Docs, safe file and folder drops with content-type checks, and secret detection and redaction in pastes and copies, with coordinated copy groups, SVG/DOM capture, Trojan Source and homoglyph detection, honest error states, retry and screen-reader announcements.",
3
+ "version": "1.23.0",
4
+ "description": "Headless, type-safe clipboard interactions for React: copy and paste text, rich HTML, images, spreadsheet tables, typed application data, Markdown, code, privacy-safe images, links, sharing, colours, portable rich text, clean pastes from Word and Google Docs, safe file and folder drops with content-type checks, secret detection and redaction in pastes and copies, one-time codes read from pasted messages into accessible code fields with SMS autofill and WebOTP, and numbers and amounts pasted and copied exactly across locales, with coordinated copy groups, SVG/DOM capture, Trojan Source and homoglyph detection, honest error states, retry and screen-reader announcements.",
5
5
  "keywords": [
6
6
  "react",
7
7
  "clipboard",
@@ -81,7 +81,15 @@
81
81
  "secret-scanning",
82
82
  "redaction",
83
83
  "api-key-detection",
84
- "data-loss-prevention"
84
+ "data-loss-prevention",
85
+ "one-time-code",
86
+ "otp",
87
+ "webotp",
88
+ "verification-code",
89
+ "number-parsing",
90
+ "currency",
91
+ "locale",
92
+ "i18n"
85
93
  ],
86
94
  "license": "MIT",
87
95
  "author": {
@@ -149,6 +157,12 @@
149
157
  ],
150
158
  "secrets": [
151
159
  "./dist/secrets.d.ts"
160
+ ],
161
+ "otp": [
162
+ "./dist/otp.d.ts"
163
+ ],
164
+ "number": [
165
+ "./dist/number.d.ts"
152
166
  ]
153
167
  }
154
168
  },
@@ -303,6 +317,26 @@
303
317
  "default": "./dist/secrets.cjs"
304
318
  }
305
319
  },
320
+ "./otp": {
321
+ "import": {
322
+ "types": "./dist/otp.d.ts",
323
+ "default": "./dist/otp.js"
324
+ },
325
+ "require": {
326
+ "types": "./dist/otp.d.cts",
327
+ "default": "./dist/otp.cjs"
328
+ }
329
+ },
330
+ "./number": {
331
+ "import": {
332
+ "types": "./dist/number.d.ts",
333
+ "default": "./dist/number.js"
334
+ },
335
+ "require": {
336
+ "types": "./dist/number.d.cts",
337
+ "default": "./dist/number.cjs"
338
+ }
339
+ },
306
340
  "./package.json": "./package.json"
307
341
  },
308
342
  "engines": {
@@ -547,6 +581,40 @@
547
581
  "import": "{ scanSecrets }",
548
582
  "limit": "3.45 kB"
549
583
  },
584
+ {
585
+ "name": "otp, all exports",
586
+ "path": "dist/otp.js",
587
+ "limit": "3.8 kB"
588
+ },
589
+ {
590
+ "name": "otp: extractOtp",
591
+ "path": "dist/otp.js",
592
+ "import": "{ extractOtp }",
593
+ "limit": "2.2 kB"
594
+ },
595
+ {
596
+ "name": "React: useOtpField",
597
+ "path": "dist/index.js",
598
+ "import": "{ useOtpField }",
599
+ "limit": "4.3 kB"
600
+ },
601
+ {
602
+ "name": "number, all exports",
603
+ "path": "dist/number.js",
604
+ "limit": "3.7 kB"
605
+ },
606
+ {
607
+ "name": "number: parseNumber",
608
+ "path": "dist/number.js",
609
+ "import": "{ parseNumber }",
610
+ "limit": "2.4 kB"
611
+ },
612
+ {
613
+ "name": "number: pasteAsNumber",
614
+ "path": "dist/number.js",
615
+ "import": "{ pasteAsNumber }",
616
+ "limit": "3.6 kB"
617
+ },
550
618
  {
551
619
  "name": "An app using five entry points (one shared core)",
552
620
  "path": [
@@ -1 +0,0 @@
1
- {"version":3,"file":"text-field-Ba8W3v4R.cjs","names":[],"sources":["../../src/core/text-field.ts"],"sourcesContent":["/**\n * Text-field helpers shared by the paste handlers of the opt-in entry points.\n * Internal: not part of `react-smart-copy/core`'s public API.\n */\n\n/** Text fields `setRangeText` and `execCommand('insertText')` both support. */\nexport type TextField = HTMLTextAreaElement | HTMLInputElement;\n\nconst TEXT_INPUTS = new Set(['text', 'search', 'url', 'tel', 'password']);\n\nexport function asTextField(target: EventTarget | null): TextField | null {\n if (typeof target !== 'object' || target === null) return null;\n const element = target as Partial<Element> & { type?: unknown };\n if (element.nodeName === 'TEXTAREA') return target as HTMLTextAreaElement;\n if (element.nodeName === 'INPUT' && typeof element.type === 'string' && TEXT_INPUTS.has(element.type)) return target as HTMLInputElement;\n return null;\n}\n\n/**\n * Inserts text at the cursor of a `<textarea>` or text `<input>`, replacing the\n * selection, as typing or pasting would: the browser's undo (Ctrl/⌘+Z) still\n * works, `input` events fire (so React and other frameworks see the change),\n * and `maxlength` is respected. Returns `false` for disabled or read-only fields.\n */\nexport function insertText(field: TextField, text: string): boolean {\n if (field.disabled || field.readOnly) return false;\n // An <input> holds one line: each run of line breaks (a paragraph break too) becomes one space.\n const value = field.nodeName === 'INPUT' ? text.replace(/[ \\t]*(?:\\r\\n|\\r|\\n)+[ \\t]*/g, ' ') : text;\n const doc = field.ownerDocument;\n field.focus();\n // `null` for inputs without a selection API (email, number): the text is appended.\n const start = field.selectionStart;\n const end = field.selectionEnd;\n try {\n // Re-applying the selection ends the current typing run, so the paste gets its own undo step\n // (as a native paste does) instead of merging with what was typed just before.\n if (start !== null && end !== null) field.setSelectionRange(start, end);\n // The only way to keep the native undo stack; supported for text fields in every current browser.\n // eslint-disable-next-line @typescript-eslint/no-deprecated -- no replacement keeps undo history\n if (doc.activeElement === field && doc.execCommand('insertText', false, value)) return true;\n } catch {\n // Fall through to the manual insertion.\n }\n const from = start ?? field.value.length;\n const to = end ?? from;\n let insert = value;\n if (field.maxLength >= 0) {\n const room = Math.max(0, field.maxLength - (field.value.length - (to - from)));\n insert = insert.slice(0, room);\n // Never leave half of a surrogate pair (an emoji) behind.\n if (/[\\ud800-\\udbff]$/.test(insert)) insert = insert.slice(0, -1);\n }\n if (start === null) setNativeValue(field, field.value + insert);\n else field.setRangeText(insert, from, to, 'end');\n const view = doc.defaultView;\n const event =\n view !== null && typeof view.InputEvent === 'function'\n ? new view.InputEvent('input', { bubbles: true, inputType: 'insertFromPaste', data: insert })\n : new Event('input', { bubbles: true });\n field.dispatchEvent(event);\n return true;\n}\n\n/**\n * Sets a field's value through the prototype's setter. React tracks the value\n * set on the element itself; going around it lets React see the change and\n * call `onChange` for the `input` event that follows.\n */\nfunction setNativeValue(field: TextField, next: string): void {\n const descriptor = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(field) as object, 'value');\n // eslint-disable-next-line @typescript-eslint/unbound-method -- it is called right below with the field as `this`\n const setter = descriptor?.set;\n if (setter) setter.call(field, next);\n else field.value = next;\n}\n"],"mappings":";;AAQA,MAAM,8BAAc,IAAI,IAAI;CAAC;CAAQ;CAAU;CAAO;CAAO;AAAU,CAAC;AAExE,SAAgB,YAAY,QAA8C;CACxE,IAAI,OAAO,WAAW,YAAY,WAAW,MAAM,OAAO;CAC1D,MAAM,UAAU;CAChB,IAAI,QAAQ,aAAa,YAAY,OAAO;CAC5C,IAAI,QAAQ,aAAa,WAAW,OAAO,QAAQ,SAAS,YAAY,YAAY,IAAI,QAAQ,IAAI,GAAG,OAAO;CAC9G,OAAO;AACT;;;;;;;AAQA,SAAgB,WAAW,OAAkB,MAAuB;CAClE,IAAI,MAAM,YAAY,MAAM,UAAU,OAAO;CAE7C,MAAM,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sourcesContent":["/**\n * Text-field helpers shared by the paste handlers of the opt-in entry points.\n * Internal: not part of `react-smart-copy/core`'s public API.\n */\n\n/** Text fields `setRangeText` and `execCommand('insertText')` both support. */\nexport type TextField = HTMLTextAreaElement | HTMLInputElement;\n\nconst TEXT_INPUTS = new Set(['text', 'search', 'url', 'tel', 'password']);\n\nexport function asTextField(target: EventTarget | null): TextField | null {\n if (typeof target !== 'object' || target === null) return null;\n const element = target as Partial<Element> & { type?: unknown };\n if (element.nodeName === 'TEXTAREA') return target as HTMLTextAreaElement;\n if (element.nodeName === 'INPUT' && typeof element.type === 'string' && TEXT_INPUTS.has(element.type)) return target as HTMLInputElement;\n return null;\n}\n\n/**\n * Inserts text at the cursor of a `<textarea>` or text `<input>`, replacing the\n * selection, as typing or pasting would: the browser's undo (Ctrl/⌘+Z) still\n * works, `input` events fire (so React and other frameworks see the change),\n * and `maxlength` is respected. Returns `false` for disabled or read-only fields.\n */\nexport function insertText(field: TextField, text: string): boolean {\n if (field.disabled || field.readOnly) return false;\n // An <input> holds one line: each run of line breaks (a paragraph break too) becomes one space.\n const value = field.nodeName === 'INPUT' ? text.replace(/[ \\t]*(?:\\r\\n|\\r|\\n)+[ \\t]*/g, ' ') : text;\n const doc = field.ownerDocument;\n field.focus();\n // `null` for inputs without a selection API (email, number): the text is appended.\n const start = field.selectionStart;\n const end = field.selectionEnd;\n try {\n // Re-applying the selection ends the current typing run, so the paste gets its own undo step\n // (as a native paste does) instead of merging with what was typed just before.\n if (start !== null && end !== null) field.setSelectionRange(start, end);\n // The only way to keep the native undo stack; supported for text fields in every current browser.\n // eslint-disable-next-line @typescript-eslint/no-deprecated -- no replacement keeps undo history\n if (doc.activeElement === field && doc.execCommand('insertText', false, value)) return true;\n } catch {\n // Fall through to the manual insertion.\n }\n const from = start ?? field.value.length;\n const to = end ?? from;\n let insert = value;\n if (field.maxLength >= 0) {\n const room = Math.max(0, field.maxLength - (field.value.length - (to - from)));\n insert = insert.slice(0, room);\n // Never leave half of a surrogate pair (an emoji) behind.\n if (/[\\ud800-\\udbff]$/.test(insert)) insert = insert.slice(0, -1);\n }\n if (start === null) setNativeValue(field, field.value + insert);\n else field.setRangeText(insert, from, to, 'end');\n const view = doc.defaultView;\n const event =\n view !== null && typeof view.InputEvent === 'function'\n ? new view.InputEvent('input', { bubbles: true, inputType: 'insertFromPaste', data: insert })\n : new Event('input', { bubbles: true });\n field.dispatchEvent(event);\n return true;\n}\n\n/**\n * Sets a field's value through the prototype's setter. React tracks the value\n * set on the element itself; going around it lets React see the change and\n * call `onChange` for the `input` event that follows.\n */\nfunction setNativeValue(field: TextField, next: string): void {\n const descriptor = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(field) as object, 'value');\n // eslint-disable-next-line @typescript-eslint/unbound-method -- it is called right below with the field as `this`\n const setter = descriptor?.set;\n if (setter) setter.call(field, next);\n else field.value = next;\n}\n"],"mappings":";;AAQA,MAAM,8BAAc,IAAI,IAAI;CAAC;CAAQ;CAAU;CAAO;CAAO;AAAU,CAAC;AAExE,SAAgB,YAAY,QAA8C;CACxE,IAAI,OAAO,WAAW,YAAY,WAAW,MAAM,OAAO;CAC1D,MAAM,UAAU;CAChB,IAAI,QAAQ,aAAa,YAAY,OAAO;CAC5C,IAAI,QAAQ,aAAa,WAAW,OAAO,QAAQ,SAAS,YAAY,YAAY,IAAI,QAAQ,IAAI,GAAG,OAAO;CAC9G,OAAO;AACT;;;;;;;AAQA,SAAgB,WAAW,OAAkB,MAAuB;CAClE,IAAI,MAAM,YAAY,MAAM,UAAU,OAAO;CAE7C,MAAM,QAAQ,MAAM,aAAa,UAAU,KAAK,QAAQ,gCAAgC,GAAG,IAAI;CAC/F,MAAM,MAAM,MAAM;CAClB,MAAM,MAAM;CAEZ,MAAM,QAAQ,MAAM;CACpB,MAAM,MAAM,MAAM;CAClB,IAAI;EAGF,IAAI,UAAU,QAAQ,QAAQ,MAAM,MAAM,kBAAkB,OAAO,GAAG;EAGtE,IAAI,IAAI,kBAAkB,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