react-smart-copy 1.17.1 → 1.18.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 (146) hide show
  1. package/README.md +22 -3
  2. package/dist/capture.cjs +30 -153
  3. package/dist/capture.cjs.map +1 -1
  4. package/dist/capture.d.cts +2 -25
  5. package/dist/capture.d.ts +2 -25
  6. package/dist/capture.js +5 -128
  7. package/dist/capture.js.map +1 -1
  8. package/dist/chunks/clipboard-adapter-Cfz-rzw3.cjs +102 -0
  9. package/dist/chunks/clipboard-adapter-Cfz-rzw3.cjs.map +1 -0
  10. package/dist/chunks/clipboard-adapter-CtH4VELE.d.cts +43 -0
  11. package/dist/chunks/clipboard-adapter-DEXkXxwV.js +97 -0
  12. package/dist/chunks/clipboard-adapter-DEXkXxwV.js.map +1 -0
  13. package/dist/chunks/clipboard-adapter-Ds0irroN.d.ts +43 -0
  14. package/dist/chunks/contrast-C6CVklEI.cjs +842 -0
  15. package/dist/chunks/contrast-C6CVklEI.cjs.map +1 -0
  16. package/dist/chunks/contrast-DpK2JIVu.js +789 -0
  17. package/dist/chunks/contrast-DpK2JIVu.js.map +1 -0
  18. package/dist/chunks/copy-interceptor-C6NABy1l.d.ts +141 -0
  19. package/dist/chunks/copy-interceptor-CZWzGOkL.d.cts +141 -0
  20. package/dist/chunks/core-Cp2HSpaz.js +1035 -0
  21. package/dist/chunks/core-Cp2HSpaz.js.map +1 -0
  22. package/dist/chunks/core-DYf_Lhbe.cjs +1142 -0
  23. package/dist/chunks/core-DYf_Lhbe.cjs.map +1 -0
  24. package/dist/chunks/deadline-C29AlS_Q.js +46 -0
  25. package/dist/chunks/deadline-C29AlS_Q.js.map +1 -0
  26. package/dist/chunks/deadline-DkiB8ZHE.cjs +51 -0
  27. package/dist/chunks/deadline-DkiB8ZHE.cjs.map +1 -0
  28. package/dist/chunks/errors-9h8sdFFX.js +120 -0
  29. package/dist/chunks/errors-9h8sdFFX.js.map +1 -0
  30. package/dist/chunks/errors-BwOF6T_M.cjs +167 -0
  31. package/dist/chunks/errors-BwOF6T_M.cjs.map +1 -0
  32. package/dist/chunks/index-mr7sSAgP.d.ts +426 -0
  33. package/dist/chunks/index-vz0iW5V2.d.cts +426 -0
  34. package/dist/chunks/mime--LB7kdqG.cjs +153 -0
  35. package/dist/chunks/mime--LB7kdqG.cjs.map +1 -0
  36. package/dist/chunks/mime-aa-HA2dm.js +100 -0
  37. package/dist/chunks/mime-aa-HA2dm.js.map +1 -0
  38. package/dist/chunks/paste-adapter--SPL4PRE.d.cts +35 -0
  39. package/dist/chunks/paste-adapter-uahXnTYk.d.ts +35 -0
  40. package/dist/chunks/paste-reader-Bo01IMC_.cjs +289 -0
  41. package/dist/chunks/paste-reader-Bo01IMC_.cjs.map +1 -0
  42. package/dist/chunks/paste-reader-D9i7yMXF.js +224 -0
  43. package/dist/chunks/paste-reader-D9i7yMXF.js.map +1 -0
  44. package/dist/chunks/paste-reader-DcXnRWQr.d.cts +96 -0
  45. package/dist/chunks/paste-reader-DcXnRWQr.d.ts +96 -0
  46. package/dist/chunks/payload-CUymxwim.cjs +100 -0
  47. package/dist/chunks/payload-CUymxwim.cjs.map +1 -0
  48. package/dist/chunks/payload-CcwKJ_bU.d.cts +162 -0
  49. package/dist/chunks/payload-Cl_8hCI5.d.ts +162 -0
  50. package/dist/chunks/payload-DGw-JOo7.js +71 -0
  51. package/dist/chunks/payload-DGw-JOo7.js.map +1 -0
  52. package/dist/chunks/payload-DI5AorDz.js +103 -0
  53. package/dist/chunks/payload-DI5AorDz.js.map +1 -0
  54. package/dist/chunks/payload-J6GjHuh3.cjs +132 -0
  55. package/dist/chunks/payload-J6GjHuh3.cjs.map +1 -0
  56. package/dist/chunks/share-Bop47Znn.js +208 -0
  57. package/dist/chunks/share-Bop47Znn.js.map +1 -0
  58. package/dist/chunks/share-C0esXvRK.d.cts +115 -0
  59. package/dist/chunks/share-ayDz974N.cjs +231 -0
  60. package/dist/chunks/share-ayDz974N.cjs.map +1 -0
  61. package/dist/chunks/share-e7FenIr2.d.ts +115 -0
  62. package/dist/chunks/text-field-Ba8W3v4R.cjs +77 -0
  63. package/dist/chunks/text-field-Ba8W3v4R.cjs.map +1 -0
  64. package/dist/chunks/text-field-C0SGmvvR.d.cts +18 -0
  65. package/dist/chunks/text-field-C0SGmvvR.d.ts +18 -0
  66. package/dist/chunks/text-field-DUvrMMaK.js +66 -0
  67. package/dist/chunks/text-field-DUvrMMaK.js.map +1 -0
  68. package/dist/chunks/url-BcMYVCXQ.js +135 -0
  69. package/dist/chunks/url-BcMYVCXQ.js.map +1 -0
  70. package/dist/chunks/url-D4PGsRm8.cjs +164 -0
  71. package/dist/chunks/url-D4PGsRm8.cjs.map +1 -0
  72. package/dist/chunks/url-DWdElCT3.d.cts +43 -0
  73. package/dist/chunks/url-DWdElCT3.d.ts +43 -0
  74. package/dist/code.cjs +20 -109
  75. package/dist/code.cjs.map +1 -1
  76. package/dist/code.d.cts +4 -28
  77. package/dist/code.d.ts +4 -28
  78. package/dist/code.js +4 -93
  79. package/dist/code.js.map +1 -1
  80. package/dist/color.cjs +21 -893
  81. package/dist/color.cjs.map +1 -1
  82. package/dist/color.d.cts +4 -28
  83. package/dist/color.d.ts +4 -28
  84. package/dist/color.js +4 -876
  85. package/dist/color.js.map +1 -1
  86. package/dist/core.cjs +52 -1659
  87. package/dist/core.d.cts +8 -878
  88. package/dist/core.d.ts +8 -878
  89. package/dist/core.js +7 -1614
  90. package/dist/image.cjs +23 -91
  91. package/dist/image.cjs.map +1 -1
  92. package/dist/image.d.cts +1 -0
  93. package/dist/image.d.ts +1 -0
  94. package/dist/image.js +5 -73
  95. package/dist/image.js.map +1 -1
  96. package/dist/index.cjs +74 -2072
  97. package/dist/index.cjs.map +1 -1
  98. package/dist/index.d.cts +8 -978
  99. package/dist/index.d.ts +8 -978
  100. package/dist/index.js +7 -2005
  101. package/dist/index.js.map +1 -1
  102. package/dist/link.cjs +24 -338
  103. package/dist/link.cjs.map +1 -1
  104. package/dist/link.d.cts +5 -83
  105. package/dist/link.d.ts +5 -83
  106. package/dist/link.js +5 -319
  107. package/dist/link.js.map +1 -1
  108. package/dist/markdown.cjs +8 -97
  109. package/dist/markdown.cjs.map +1 -1
  110. package/dist/markdown.d.cts +3 -16
  111. package/dist/markdown.d.ts +3 -16
  112. package/dist/markdown.js +3 -92
  113. package/dist/markdown.js.map +1 -1
  114. package/dist/rich.cjs +26 -934
  115. package/dist/rich.cjs.map +1 -1
  116. package/dist/rich.d.cts +4 -90
  117. package/dist/rich.d.ts +4 -90
  118. package/dist/rich.js +4 -912
  119. package/dist/rich.js.map +1 -1
  120. package/dist/share.cjs +5 -640
  121. package/dist/share.d.cts +3 -248
  122. package/dist/share.d.ts +3 -248
  123. package/dist/share.js +1 -637
  124. package/dist/structured.cjs +13 -95
  125. package/dist/structured.cjs.map +1 -1
  126. package/dist/structured.d.cts +2 -11
  127. package/dist/structured.d.ts +2 -11
  128. package/dist/structured.js +4 -86
  129. package/dist/structured.js.map +1 -1
  130. package/dist/table.cjs +11 -39
  131. package/dist/table.cjs.map +1 -1
  132. package/dist/table.d.cts +2 -12
  133. package/dist/table.d.ts +2 -12
  134. package/dist/table.js +2 -30
  135. package/dist/table.js.map +1 -1
  136. package/dist/testing.cjs +10 -43
  137. package/dist/testing.cjs.map +1 -1
  138. package/dist/testing.d.cts +6 -181
  139. package/dist/testing.d.ts +6 -181
  140. package/dist/testing.js +3 -36
  141. package/dist/testing.js.map +1 -1
  142. package/package.json +20 -2
  143. package/dist/core.cjs.map +0 -1
  144. package/dist/core.js.map +0 -1
  145. package/dist/share.cjs.map +0 -1
  146. package/dist/share.js.map +0 -1
package/dist/code.cjs CHANGED
@@ -1,34 +1,7 @@
1
+
1
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- //#region src/core/errors.ts
3
- function createCopyError(type, message, cause) {
4
- return cause === void 0 ? {
5
- type,
6
- message
7
- } : {
8
- type,
9
- message,
10
- cause
11
- };
12
- }
13
- /**
14
- * Branded (not `instanceof`) so failures stay recognisable even when the core
15
- * is bundled twice, e.g. `react-smart-copy` and `react-smart-copy/core` together.
16
- */
17
- const COPY_FAILURE_BRAND = Symbol.for("react-smart-copy.CopyFailure");
18
- /** Error thrown by adapters to carry a fully classified {@link CopyError}. */
19
- var CopyFailure = class extends Error {
20
- constructor(copyError) {
21
- super(copyError.message);
22
- this[COPY_FAILURE_BRAND] = true;
23
- this.name = "CopyFailure";
24
- this.copyError = copyError;
25
- }
26
- };
27
- /** Shorthand for throwing a classified failure. */
28
- function copyFailure(type, message, cause) {
29
- return new CopyFailure(createCopyError(type, message, cause));
30
- }
31
- //#endregion
3
+ const require_errors = require("./chunks/errors-BwOF6T_M.cjs");
4
+ const require_text_field = require("./chunks/text-field-Ba8W3v4R.cjs");
32
5
  //#region src/code/inspect.ts
33
6
  /** Every finding kind, in a stable order. */
34
7
  const CODE_FINDING_KINDS = Object.freeze([
@@ -209,7 +182,7 @@ function classify(codePoint, before, after) {
209
182
  const ALL = /* @__PURE__ */ new Set(CODE_FINDING_KINDS);
210
183
  function kindSet(kinds, name) {
211
184
  if (kinds === void 0) return ALL;
212
- if (!Array.isArray(kinds) || !kinds.every((kind) => ALL.has(kind))) throw copyFailure("invalid-payload", `\`${name}\` must be a list of: ${CODE_FINDING_KINDS.join(", ")}.`);
185
+ if (!Array.isArray(kinds) || !kinds.every((kind) => ALL.has(kind))) throw require_errors.copyFailure("invalid-payload", `\`${name}\` must be a list of: ${CODE_FINDING_KINDS.join(", ")}.`);
213
186
  return new Set(kinds);
214
187
  }
215
188
  /** Every suspicious character in `text`, in order of position. Stops once `limit` are found. */
@@ -302,7 +275,7 @@ function toFindings(text, raw) {
302
275
  function positiveLimit(value, fallback, name) {
303
276
  if (value === void 0) return fallback;
304
277
  if (value === Infinity || Number.isInteger(value) && value > 0) return value;
305
- throw copyFailure("invalid-payload", `\`${name}\` must be a positive integer or Infinity (received ${String(value)}).`);
278
+ throw require_errors.copyFailure("invalid-payload", `\`${name}\` must be a positive integer or Infinity (received ${String(value)}).`);
306
279
  }
307
280
  /**
308
281
  * Finds characters that make code read differently from how it runs, or that a
@@ -499,7 +472,7 @@ const AUTO = [
499
472
  ];
500
473
  /** A user pattern without `g` / `y`, so `exec` is stateless. */
501
474
  function stateless(pattern, name) {
502
- if (!(pattern instanceof RegExp)) throw copyFailure("invalid-payload", `\`prompt.${name}\` must be a RegExp.`);
475
+ if (!(pattern instanceof RegExp)) throw require_errors.copyFailure("invalid-payload", `\`prompt.${name}\` must be a RegExp.`);
503
476
  return new RegExp(pattern.source, pattern.flags.replace(/[gy]/g, ""));
504
477
  }
505
478
  function resolvePrompt(prompt, fallback) {
@@ -507,10 +480,10 @@ function resolvePrompt(prompt, fallback) {
507
480
  if (value === false) return null;
508
481
  if (value === "auto") return "auto";
509
482
  if (typeof value === "string") {
510
- if (!Object.prototype.hasOwnProperty.call(PROMPTS, value)) throw copyFailure("invalid-payload", `\`prompt\` must be 'auto', false, a PromptPattern or one of: ${PROMPT_STYLES.join(", ")}.`);
483
+ if (!Object.prototype.hasOwnProperty.call(PROMPTS, value)) throw require_errors.copyFailure("invalid-payload", `\`prompt\` must be 'auto', false, a PromptPattern or one of: ${PROMPT_STYLES.join(", ")}.`);
511
484
  return PROMPTS[value];
512
485
  }
513
- if (typeof value !== "object" || value === null) throw copyFailure("invalid-payload", `\`prompt\` must be 'auto', false, a PromptPattern or one of: ${PROMPT_STYLES.join(", ")}.`);
486
+ if (typeof value !== "object" || value === null) throw require_errors.copyFailure("invalid-payload", `\`prompt\` must be 'auto', false, a PromptPattern or one of: ${PROMPT_STYLES.join(", ")}.`);
514
487
  return {
515
488
  command: stateless(value.command, "command"),
516
489
  continuation: value.continuation === void 0 ? null : stateless(value.continuation, "continuation"),
@@ -661,7 +634,7 @@ function dedentLines(lines) {
661
634
  const oneOf = (value, allowed, fallback, name) => {
662
635
  if (value === void 0) return fallback;
663
636
  if (allowed.includes(value)) return value;
664
- throw copyFailure("invalid-payload", `\`${name}\` must be one of: ${allowed.map((option) => JSON.stringify(option)).join(", ")}.`);
637
+ throw require_errors.copyFailure("invalid-payload", `\`${name}\` must be one of: ${allowed.map((option) => JSON.stringify(option)).join(", ")}.`);
665
638
  };
666
639
  const flag = (value, fallback, name) => oneOf(value, [true, false], fallback, name);
667
640
  function resolveText(options, defaults) {
@@ -822,7 +795,7 @@ const NO_SELECT = /(?:^|;)\s*(?:-webkit-)?user-select\s*:\s*none/i;
822
795
  const SAFE_COLOR = /^(?:#[\da-f]{3,8}|[a-z]{3,20}|(?:rgba?|hsla?|hwb|lab|lch|oklab|oklch)\([\d\s.,%/+-]{1,80}\)|color\([a-z\d-]{1,24}[\d\s.,%/+-]{1,80}\))$/i;
823
796
  const TRANSPARENT = /^(?:transparent|rgba\(\s*0,\s*0,\s*0,\s*0\s*\))$/i;
824
797
  function assertElement(value, name) {
825
- if (typeof value !== "object" || value === null || value.nodeType !== 1) throw copyFailure("invalid-payload", `\`${name}\` must be a string or an Element.`);
798
+ if (typeof value !== "object" || value === null || value.nodeType !== 1) throw require_errors.copyFailure("invalid-payload", `\`${name}\` must be a string or an Element.`);
826
799
  }
827
800
  function lookOf(style) {
828
801
  const weight = style.fontWeight;
@@ -844,7 +817,7 @@ function extract(root, options) {
844
817
  if (ignore !== void 0) try {
845
818
  root.matches(ignore);
846
819
  } catch (cause) {
847
- throw copyFailure("invalid-payload", `\`ignore\` is not a valid CSS selector: ${ignore}`, cause);
820
+ throw require_errors.copyFailure("invalid-payload", `\`ignore\` is not a valid CSS selector: ${ignore}`, cause);
848
821
  }
849
822
  const view = root.ownerDocument.defaultView;
850
823
  const computed = (element) => view === null ? null : view.getComputedStyle(element);
@@ -973,9 +946,9 @@ function codePayload(source, options = {}) {
973
946
  clean: false
974
947
  });
975
948
  const withHtml = options.html ?? true;
976
- if (typeof withHtml !== "boolean") throw copyFailure("invalid-payload", "`html` must be a boolean.");
949
+ if (typeof withHtml !== "boolean") throw require_errors.copyFailure("invalid-payload", "`html` must be a boolean.");
977
950
  const { language } = options;
978
- if (language !== void 0 && (typeof language !== "string" || !LANGUAGE.test(language))) throw copyFailure("invalid-payload", "`language` may only hold letters, digits and _ + # . - (at most 64).");
951
+ if (language !== void 0 && (typeof language !== "string" || !LANGUAGE.test(language))) throw require_errors.copyFailure("invalid-payload", "`language` may only hold letters, digits and _ + # . - (at most 64).");
979
952
  let lines;
980
953
  let blockStyle = "";
981
954
  if (typeof source === "string") lines = toLines([{
@@ -1004,68 +977,6 @@ function codePayload(source, options = {}) {
1004
977
  };
1005
978
  }
1006
979
  //#endregion
1007
- //#region src/core/text-field.ts
1008
- const TEXT_INPUTS = /* @__PURE__ */ new Set([
1009
- "text",
1010
- "search",
1011
- "url",
1012
- "tel",
1013
- "password"
1014
- ]);
1015
- function asTextField(target) {
1016
- if (typeof target !== "object" || target === null) return null;
1017
- const element = target;
1018
- if (element.nodeName === "TEXTAREA") return target;
1019
- if (element.nodeName === "INPUT" && typeof element.type === "string" && TEXT_INPUTS.has(element.type)) return target;
1020
- return null;
1021
- }
1022
- /**
1023
- * Inserts text at the cursor of a `<textarea>` or text `<input>`, replacing the
1024
- * selection, as typing or pasting would: the browser's undo (Ctrl/⌘+Z) still
1025
- * works, `input` events fire (so React and other frameworks see the change),
1026
- * and `maxlength` is respected. Returns `false` for disabled or read-only fields.
1027
- */
1028
- function insertText(field, text) {
1029
- if (field.disabled || field.readOnly) return false;
1030
- const value = field.nodeName === "INPUT" ? text.replace(/[ \t]*(?:\r\n|\r|\n)+[ \t]*/g, " ") : text;
1031
- const doc = field.ownerDocument;
1032
- field.focus();
1033
- const start = field.selectionStart;
1034
- const end = field.selectionEnd;
1035
- try {
1036
- if (start !== null && end !== null) field.setSelectionRange(start, end);
1037
- if (doc.activeElement === field && doc.execCommand("insertText", false, value)) return true;
1038
- } catch {}
1039
- const from = start ?? field.value.length;
1040
- const to = end ?? from;
1041
- let insert = value;
1042
- if (field.maxLength >= 0) {
1043
- const room = Math.max(0, field.maxLength - (field.value.length - (to - from)));
1044
- insert = insert.slice(0, room);
1045
- if (/[\ud800-\udbff]$/.test(insert)) insert = insert.slice(0, -1);
1046
- }
1047
- if (start === null) setNativeValue(field, field.value + insert);
1048
- else field.setRangeText(insert, from, to, "end");
1049
- const view = doc.defaultView;
1050
- const event = view !== null && typeof view.InputEvent === "function" ? new view.InputEvent("input", {
1051
- bubbles: true,
1052
- inputType: "insertFromPaste",
1053
- data: insert
1054
- }) : new Event("input", { bubbles: true });
1055
- field.dispatchEvent(event);
1056
- return true;
1057
- }
1058
- /**
1059
- * Sets a field's value through the prototype's setter. React tracks the value
1060
- * set on the element itself; going around it lets React see the change and
1061
- * call `onChange` for the `input` event that follows.
1062
- */
1063
- function setNativeValue(field, next) {
1064
- const setter = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(field), "value")?.set;
1065
- if (setter) setter.call(field, next);
1066
- else field.value = next;
1067
- }
1068
- //#endregion
1069
980
  //#region src/code/paste.ts
1070
981
  const DEFAULT_CODE_MAX_LENGTH = 2e6;
1071
982
  const INDENT = /^[ \t]*$/;
@@ -1095,16 +1006,16 @@ function pasteToCode(source, options = {}) {
1095
1006
  });
1096
1007
  const maxLength = positiveLimit(options.maxLength, DEFAULT_CODE_MAX_LENGTH, "maxLength");
1097
1008
  const indent = options.indent ?? "";
1098
- if (typeof indent !== "string" || !INDENT.test(indent)) throw copyFailure("invalid-payload", "`indent` may only hold spaces and tabs.");
1009
+ if (typeof indent !== "string" || !INDENT.test(indent)) throw require_errors.copyFailure("invalid-payload", "`indent` may only hold spaces and tabs.");
1099
1010
  let text = source.text ?? "";
1100
1011
  let from = "text";
1101
1012
  if (text === "" && typeof source.html === "string" && source.html.trim() !== "" && typeof DOMParser !== "undefined") {
1102
- if (source.html.length > maxLength) throw copyFailure("too-large", `The pasted HTML is longer than maxLength (${String(maxLength)}).`);
1013
+ if (source.html.length > maxLength) throw require_errors.copyFailure("too-large", `The pasted HTML is longer than maxLength (${String(maxLength)}).`);
1103
1014
  const body = new DOMParser().parseFromString(source.html, "text/html").body;
1104
1015
  text = extract(body, { styles: false }).runs.map((run) => run.text).join("");
1105
1016
  from = "html";
1106
1017
  }
1107
- if (text.length > maxLength) throw copyFailure("too-large", `The pasted text is longer than maxLength (${String(maxLength)}).`);
1018
+ if (text.length > maxLength) throw require_errors.copyFailure("too-large", `The pasted text is longer than maxLength (${String(maxLength)}).`);
1108
1019
  if (text.trim() === "") return null;
1109
1020
  const { lines, fixed } = transform(toLines([{
1110
1021
  text,
@@ -1137,7 +1048,7 @@ function pasteToCode(source, options = {}) {
1137
1048
  */
1138
1049
  function pasteAsCode(event, options = {}) {
1139
1050
  if (event.defaultPrevented || event.clipboardData === null) return false;
1140
- const field = asTextField(event.currentTarget) ?? asTextField(event.target);
1051
+ const field = require_text_field.asTextField(event.currentTarget) ?? require_text_field.asTextField(event.target);
1141
1052
  if (field === null || field.disabled || field.readOnly) return false;
1142
1053
  const { indentToCursor, onPaste, ...rest } = options;
1143
1054
  let indent = "";
@@ -1155,13 +1066,13 @@ function pasteAsCode(event, options = {}) {
1155
1066
  indent
1156
1067
  });
1157
1068
  } catch (error) {
1158
- if (error instanceof CopyFailure) return false;
1069
+ if (require_errors.isCopyFailure(error)) return false;
1159
1070
  throw error;
1160
1071
  }
1161
1072
  if (result === null) return false;
1162
1073
  event.preventDefault();
1163
1074
  if (onPaste?.(result) === false) return true;
1164
- insertText(field, result.code);
1075
+ require_text_field.insertText(field, result.code);
1165
1076
  return true;
1166
1077
  }
1167
1078
  //#endregion
@@ -1172,7 +1083,7 @@ exports.PROMPT_STYLES = PROMPT_STYLES;
1172
1083
  exports.cleanCode = cleanCode;
1173
1084
  exports.codeFromElement = codeFromElement;
1174
1085
  exports.codePayload = codePayload;
1175
- exports.insertText = insertText;
1086
+ exports.insertText = require_text_field.insertText;
1176
1087
  exports.inspectCode = inspectCode;
1177
1088
  exports.normalizeCode = normalizeCode;
1178
1089
  exports.pasteAsCode = pasteAsCode;