react-smart-copy 1.17.2 → 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 +9 -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 -112
  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 +3 -95
  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 -94
  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 +3 -74
  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/link.d.cts CHANGED
@@ -1,70 +1,7 @@
1
- //#region src/core/payload.d.ts
2
- interface HtmlPayload {
3
- readonly kind: 'html';
4
- readonly html: string;
5
- /** Required plain-text fallback for targets that don't understand HTML. */
6
- readonly text: string;
7
- }
8
- interface MultiPayloadItem {
9
- /**
10
- * The MIME type, or a web custom format (`web application/vnd.acme+json`).
11
- * Web custom formats are only written by the async Clipboard API; copy and drag
12
- * events skip them.
13
- */
14
- readonly mimeType: string;
15
- readonly data: string | Blob;
16
- /**
17
- * Skip this item, instead of failing the copy, when the browser cannot write its type.
18
- * An optional item is only written when `ClipboardItem.supports()` confirms the type.
19
- * At least one item must be written.
20
- */
21
- readonly optional?: boolean;
22
- }
23
- interface MultiPayload {
24
- readonly kind: 'multi';
25
- readonly items: readonly MultiPayloadItem[];
26
- }
27
- //#endregion
28
- //#region src/link/url.d.ts
29
- /** Schemes a copied or pasted link may use by default. Never `javascript:`, `data:`, `vbscript:` or `file:`. */
30
- export declare const DEFAULT_LINK_PROTOCOLS: readonly string[];
31
- /**
32
- * Query parameters that only track where a click came from: the defaults of
33
- * {@link cleanLinkUrl}. `utm_` matches every parameter starting with it.
34
- */
35
- export declare const TRACKING_PARAMETERS: readonly string[];
36
- interface CleanLinkOptions {
37
- /**
38
- * Parameters to remove: exact names, names ending in `_` (a prefix, like
39
- * `utm_`), or regular expressions tested against the name. Default {@link TRACKING_PARAMETERS}.
40
- */
41
- readonly params?: readonly (string | RegExp)[];
42
- /** Parameters never removed, even when `params` matches them. */
43
- readonly keep?: readonly string[];
44
- }
45
- interface LinkUrlOptions {
46
- /** Resolves relative links. Default: the page's address in a browser; required elsewhere for relative links. */
47
- readonly base?: string | URL;
48
- /** Allowed schemes, with the colon. Default {@link DEFAULT_LINK_PROTOCOLS}. */
49
- readonly protocols?: readonly string[];
50
- /** Remove tracking parameters: `true` for {@link TRACKING_PARAMETERS}, or your own list. Default `false`. */
51
- readonly clean?: boolean | CleanLinkOptions;
52
- }
53
- /**
54
- * The link as an absolute, safe URL string, or a typed `invalid-payload` error:
55
- * relative links are resolved, the scheme must be allowed, user names and
56
- * passwords are always removed, and tracking parameters optionally.
57
- */
58
- export declare function resolveLinkUrl(input: string | URL, options?: LinkUrlOptions): string;
59
- /**
60
- * Removes tracking parameters (`utm_*`, `fbclid`, `gclid`, ...) from a link, keeping
61
- * everything else, including the fragment. Also validates it like every link here.
62
- *
63
- * @example
64
- * cleanLinkUrl('https://shop.example/p/42?utm_source=news&color=red'); // 'https://shop.example/p/42?color=red'
65
- */
66
- export declare function cleanLinkUrl(url: string | URL, options?: CleanLinkOptions & Omit<LinkUrlOptions, 'clean'>): string;
67
- //#endregion
1
+
2
+ import { o as HtmlPayload, u as MultiPayload } from "./chunks/payload-CcwKJ_bU.cjs";
3
+ import { t as insertText } from "./chunks/text-field-C0SGmvvR.cjs";
4
+ import { a as cleanLinkUrl, i as TRACKING_PARAMETERS, n as DEFAULT_LINK_PROTOCOLS, o as resolveLinkUrl, r as LinkUrlOptions, t as CleanLinkOptions } from "./chunks/url-DWdElCT3.cjs";
68
5
  //#region src/link/payload.d.ts
69
6
  /** A link with an optional title. */
70
7
  interface Link {
@@ -240,20 +177,5 @@ interface SelectionLinkOptions extends TextFragmentOptions {
240
177
  */
241
178
  export declare function selectionLink(options?: SelectionLinkOptions): SelectionLink | null;
242
179
  //#endregion
243
- //#region src/core/text-field.d.ts
244
- /**
245
- * Text-field helpers shared by the paste handlers of the opt-in entry points.
246
- * Internal: not part of `react-smart-copy/core`'s public API.
247
- */
248
- /** Text fields `setRangeText` and `execCommand('insertText')` both support. */
249
- type TextField = HTMLTextAreaElement | HTMLInputElement;
250
- /**
251
- * Inserts text at the cursor of a `<textarea>` or text `<input>`, replacing the
252
- * selection, as typing or pasting would: the browser's undo (Ctrl/⌘+Z) still
253
- * works, `input` events fire (so React and other frameworks see the change),
254
- * and `maxlength` is respected. Returns `false` for disabled or read-only fields.
255
- */
256
- export declare function insertText(field: TextField, text: string): boolean;
257
- //#endregion
258
- export type { CleanLinkOptions, Link, LinkDragPayloadOptions, LinkPasteEvent, LinkPasteSource, LinkPayloadOptions, LinkSource, LinkTextFormat, LinkUrlOptions, PasteAsLinkOptions, ResolvedLink, SelectionLink, SelectionLinkOptions, TextFragment, TextFragmentOptions };
180
+ export { type CleanLinkOptions, DEFAULT_LINK_PROTOCOLS, type Link, type LinkDragPayloadOptions, type LinkPasteEvent, type LinkPasteSource, type LinkPayloadOptions, type LinkSource, type LinkTextFormat, type LinkUrlOptions, type PasteAsLinkOptions, type ResolvedLink, type SelectionLink, type SelectionLinkOptions, TRACKING_PARAMETERS, type TextFragment, type TextFragmentOptions, cleanLinkUrl, insertText, resolveLinkUrl };
259
181
  //# sourceMappingURL=link.d.cts.map
package/dist/link.d.ts CHANGED
@@ -1,70 +1,7 @@
1
- //#region src/core/payload.d.ts
2
- interface HtmlPayload {
3
- readonly kind: 'html';
4
- readonly html: string;
5
- /** Required plain-text fallback for targets that don't understand HTML. */
6
- readonly text: string;
7
- }
8
- interface MultiPayloadItem {
9
- /**
10
- * The MIME type, or a web custom format (`web application/vnd.acme+json`).
11
- * Web custom formats are only written by the async Clipboard API; copy and drag
12
- * events skip them.
13
- */
14
- readonly mimeType: string;
15
- readonly data: string | Blob;
16
- /**
17
- * Skip this item, instead of failing the copy, when the browser cannot write its type.
18
- * An optional item is only written when `ClipboardItem.supports()` confirms the type.
19
- * At least one item must be written.
20
- */
21
- readonly optional?: boolean;
22
- }
23
- interface MultiPayload {
24
- readonly kind: 'multi';
25
- readonly items: readonly MultiPayloadItem[];
26
- }
27
- //#endregion
28
- //#region src/link/url.d.ts
29
- /** Schemes a copied or pasted link may use by default. Never `javascript:`, `data:`, `vbscript:` or `file:`. */
30
- export declare const DEFAULT_LINK_PROTOCOLS: readonly string[];
31
- /**
32
- * Query parameters that only track where a click came from: the defaults of
33
- * {@link cleanLinkUrl}. `utm_` matches every parameter starting with it.
34
- */
35
- export declare const TRACKING_PARAMETERS: readonly string[];
36
- interface CleanLinkOptions {
37
- /**
38
- * Parameters to remove: exact names, names ending in `_` (a prefix, like
39
- * `utm_`), or regular expressions tested against the name. Default {@link TRACKING_PARAMETERS}.
40
- */
41
- readonly params?: readonly (string | RegExp)[];
42
- /** Parameters never removed, even when `params` matches them. */
43
- readonly keep?: readonly string[];
44
- }
45
- interface LinkUrlOptions {
46
- /** Resolves relative links. Default: the page's address in a browser; required elsewhere for relative links. */
47
- readonly base?: string | URL;
48
- /** Allowed schemes, with the colon. Default {@link DEFAULT_LINK_PROTOCOLS}. */
49
- readonly protocols?: readonly string[];
50
- /** Remove tracking parameters: `true` for {@link TRACKING_PARAMETERS}, or your own list. Default `false`. */
51
- readonly clean?: boolean | CleanLinkOptions;
52
- }
53
- /**
54
- * The link as an absolute, safe URL string, or a typed `invalid-payload` error:
55
- * relative links are resolved, the scheme must be allowed, user names and
56
- * passwords are always removed, and tracking parameters optionally.
57
- */
58
- export declare function resolveLinkUrl(input: string | URL, options?: LinkUrlOptions): string;
59
- /**
60
- * Removes tracking parameters (`utm_*`, `fbclid`, `gclid`, ...) from a link, keeping
61
- * everything else, including the fragment. Also validates it like every link here.
62
- *
63
- * @example
64
- * cleanLinkUrl('https://shop.example/p/42?utm_source=news&color=red'); // 'https://shop.example/p/42?color=red'
65
- */
66
- export declare function cleanLinkUrl(url: string | URL, options?: CleanLinkOptions & Omit<LinkUrlOptions, 'clean'>): string;
67
- //#endregion
1
+
2
+ import { o as HtmlPayload, u as MultiPayload } from "./chunks/payload-Cl_8hCI5.js";
3
+ import { t as insertText } from "./chunks/text-field-C0SGmvvR.js";
4
+ import { a as cleanLinkUrl, i as TRACKING_PARAMETERS, n as DEFAULT_LINK_PROTOCOLS, o as resolveLinkUrl, r as LinkUrlOptions, t as CleanLinkOptions } from "./chunks/url-DWdElCT3.js";
68
5
  //#region src/link/payload.d.ts
69
6
  /** A link with an optional title. */
70
7
  interface Link {
@@ -240,20 +177,5 @@ interface SelectionLinkOptions extends TextFragmentOptions {
240
177
  */
241
178
  export declare function selectionLink(options?: SelectionLinkOptions): SelectionLink | null;
242
179
  //#endregion
243
- //#region src/core/text-field.d.ts
244
- /**
245
- * Text-field helpers shared by the paste handlers of the opt-in entry points.
246
- * Internal: not part of `react-smart-copy/core`'s public API.
247
- */
248
- /** Text fields `setRangeText` and `execCommand('insertText')` both support. */
249
- type TextField = HTMLTextAreaElement | HTMLInputElement;
250
- /**
251
- * Inserts text at the cursor of a `<textarea>` or text `<input>`, replacing the
252
- * selection, as typing or pasting would: the browser's undo (Ctrl/⌘+Z) still
253
- * works, `input` events fire (so React and other frameworks see the change),
254
- * and `maxlength` is respected. Returns `false` for disabled or read-only fields.
255
- */
256
- export declare function insertText(field: TextField, text: string): boolean;
257
- //#endregion
258
- export type { CleanLinkOptions, Link, LinkDragPayloadOptions, LinkPasteEvent, LinkPasteSource, LinkPayloadOptions, LinkSource, LinkTextFormat, LinkUrlOptions, PasteAsLinkOptions, ResolvedLink, SelectionLink, SelectionLinkOptions, TextFragment, TextFragmentOptions };
180
+ export { type CleanLinkOptions, DEFAULT_LINK_PROTOCOLS, type Link, type LinkDragPayloadOptions, type LinkPasteEvent, type LinkPasteSource, type LinkPayloadOptions, type LinkSource, type LinkTextFormat, type LinkUrlOptions, type PasteAsLinkOptions, type ResolvedLink, type SelectionLink, type SelectionLinkOptions, TRACKING_PARAMETERS, type TextFragment, type TextFragmentOptions, cleanLinkUrl, insertText, resolveLinkUrl };
259
181
  //# sourceMappingURL=link.d.ts.map
package/dist/link.js CHANGED
@@ -1,260 +1,8 @@
1
- //#region src/core/errors.ts
2
- function createCopyError(type, message, cause) {
3
- return cause === void 0 ? {
4
- type,
5
- message
6
- } : {
7
- type,
8
- message,
9
- cause
10
- };
11
- }
12
- /**
13
- * Branded (not `instanceof`) so failures stay recognisable even when the core
14
- * is bundled twice, e.g. `react-smart-copy` and `react-smart-copy/core` together.
15
- */
16
- const COPY_FAILURE_BRAND = Symbol.for("react-smart-copy.CopyFailure");
17
- /** Error thrown by adapters to carry a fully classified {@link CopyError}. */
18
- var CopyFailure = class extends Error {
19
- constructor(copyError) {
20
- super(copyError.message);
21
- this[COPY_FAILURE_BRAND] = true;
22
- this.name = "CopyFailure";
23
- this.copyError = copyError;
24
- }
25
- };
26
- /** Shorthand for throwing a classified failure. */
27
- function copyFailure(type, message, cause) {
28
- return new CopyFailure(createCopyError(type, message, cause));
29
- }
30
- //#endregion
31
- //#region src/link/url.ts
32
- /** Schemes a copied or pasted link may use by default. Never `javascript:`, `data:`, `vbscript:` or `file:`. */
33
- const DEFAULT_LINK_PROTOCOLS = /* @__PURE__ */ Object.freeze([
34
- "https:",
35
- "http:",
36
- "mailto:",
37
- "tel:"
38
- ]);
39
- /**
40
- * Query parameters that only track where a click came from: the defaults of
41
- * {@link cleanLinkUrl}. `utm_` matches every parameter starting with it.
42
- */
43
- const TRACKING_PARAMETERS = /* @__PURE__ */ Object.freeze([
44
- "utm_",
45
- "fbclid",
46
- "gclid",
47
- "gclsrc",
48
- "dclid",
49
- "gbraid",
50
- "wbraid",
51
- "msclkid",
52
- "yclid",
53
- "twclid",
54
- "ttclid",
55
- "li_fat_id",
56
- "igshid",
57
- "igsh",
58
- "mc_cid",
59
- "mc_eid",
60
- "_hsenc",
61
- "_hsmi",
62
- "mkt_tok",
63
- "oly_anon_id",
64
- "oly_enc_id",
65
- "vero_id",
66
- "wickedid",
67
- "_gl"
68
- ]);
69
- const invalid$2 = (message) => copyFailure("invalid-payload", message);
70
- function baseUrl(base) {
71
- if (base !== void 0) {
72
- if (typeof base === "string" || base instanceof URL) return String(base);
73
- throw invalid$2("`base` must be a string or a URL.");
74
- }
75
- return typeof location === "undefined" ? void 0 : location.href;
76
- }
77
- function protocolSet(protocols) {
78
- const list = protocols ?? DEFAULT_LINK_PROTOCOLS;
79
- const valid = (protocol) => typeof protocol === "string" && /^[a-z][a-z\d+.-]*:$/i.test(protocol);
80
- if (!Array.isArray(list) || list.length === 0 || !list.every(valid)) throw invalid$2("`protocols` must be a non-empty list of schemes with their colon, like \"https:\".");
81
- return new Set(list.map((protocol) => protocol.toLowerCase()));
82
- }
83
- function matcher(params) {
84
- const list = params ?? TRACKING_PARAMETERS;
85
- if (!Array.isArray(list) || !list.every((param) => typeof param === "string" || param instanceof RegExp)) throw invalid$2("`clean.params` must be a list of strings and regular expressions.");
86
- return (name) => {
87
- const lower = name.toLowerCase();
88
- return list.some((param) => {
89
- if (typeof param !== "string") return new RegExp(param.source, param.flags.replace(/[gy]/g, "")).test(name);
90
- const wanted = param.toLowerCase();
91
- return wanted.endsWith("_") ? lower.startsWith(wanted) : lower === wanted;
92
- });
93
- };
94
- }
95
- /** The cleaning step `clean` asks for, or `null`. Throws for an invalid option. */
96
- function cleaner(option) {
97
- const cleaning = option ?? false;
98
- if (cleaning === false) return null;
99
- if (cleaning !== true && (typeof cleaning !== "object" || cleaning === null)) throw invalid$2("`clean` must be a boolean or an options object.");
100
- const settings = cleaning === true ? {} : cleaning;
101
- const tracking = matcher(settings.params);
102
- const keep = settings.keep ?? [];
103
- if (!Array.isArray(keep) || !keep.every((name) => typeof name === "string")) throw invalid$2("`clean.keep` must be a list of strings.");
104
- const kept = new Set(keep.map((name) => name.toLowerCase()));
105
- return (url) => {
106
- for (const name of [...new Set(url.searchParams.keys())]) if (tracking(name) && !kept.has(name.toLowerCase())) url.searchParams.delete(name);
107
- };
108
- }
109
- /**
110
- * Validates `options` once (throwing a typed `invalid-payload` error for invalid
111
- * ones) and returns a resolver that throws only for invalid links.
112
- * @internal
113
- */
114
- function linkUrlResolver(options = {}) {
115
- const protocols = protocolSet(options.protocols);
116
- const base = baseUrl(options.base);
117
- const clean = cleaner(options.clean);
118
- return (input) => {
119
- if (typeof input !== "string" && !(input instanceof URL)) throw invalid$2("A link must be a string or a URL.");
120
- const raw = String(input).trim();
121
- if (raw === "") throw invalid$2("A link must not be empty.");
122
- let url;
123
- try {
124
- url = new URL(raw, base);
125
- } catch (cause) {
126
- throw copyFailure("invalid-payload", `Not a valid link: ${JSON.stringify(raw.slice(0, 200))}.`, cause);
127
- }
128
- if (!protocols.has(url.protocol)) throw invalid$2(`Links with the scheme "${url.protocol}" are not allowed (allowed: ${[...protocols].join(", ")}).`);
129
- url.username = "";
130
- url.password = "";
131
- clean?.(url);
132
- return url.href;
133
- };
134
- }
135
- /**
136
- * The link as an absolute, safe URL string, or a typed `invalid-payload` error:
137
- * relative links are resolved, the scheme must be allowed, user names and
138
- * passwords are always removed, and tracking parameters optionally.
139
- */
140
- function resolveLinkUrl(input, options = {}) {
141
- return linkUrlResolver(options)(input);
142
- }
143
- /**
144
- * Removes tracking parameters (`utm_*`, `fbclid`, `gclid`, ...) from a link, keeping
145
- * everything else, including the fragment. Also validates it like every link here.
146
- *
147
- * @example
148
- * cleanLinkUrl('https://shop.example/p/42?utm_source=news&color=red'); // 'https://shop.example/p/42?color=red'
149
- */
150
- function cleanLinkUrl(url, options = {}) {
151
- const { params, keep, ...rest } = options;
152
- return resolveLinkUrl(url, {
153
- ...rest,
154
- clean: {
155
- ...params === void 0 ? {} : { params },
156
- ...keep === void 0 ? {} : { keep }
157
- }
158
- });
159
- }
160
- //#endregion
161
- //#region src/link/payload.ts
162
- const DEFAULT_LINK_TITLE_LENGTH = 300;
163
- const invalid$1 = (message) => copyFailure("invalid-payload", message);
164
- /**
165
- * Characters a title never keeps: controls, bidi overrides and isolates (which can
166
- * make a title read differently), and zero-width characters.
167
- */
168
- const HIDDEN = /[\0-\x08\x0b\x0c\x0e-\x1f\x7f-\x9f\u061C\u200B-\u200F\u202A-\u202E\u2060-\u2064\u2066-\u2069\uFEFF]/g;
169
- /** A title as one clean line: hidden characters removed, whitespace collapsed, length capped. */
170
- function cleanTitle(title, maxLength) {
171
- const clean = title.replace(HIDDEN, "").replace(/\s+/g, " ").trim();
172
- if (clean.length <= maxLength) return clean;
173
- return `${Array.from(clean).slice(0, maxLength - 1).join("").trimEnd()}\u2026`;
174
- }
175
- function maxTitle(value) {
176
- if (value === void 0) return 300;
177
- if (Number.isInteger(value) && value >= 1) return value;
178
- throw invalid$1(`\`maxTitleLength\` must be a positive integer (received ${String(value)}).`);
179
- }
180
- function isAnchor(source) {
181
- return typeof source === "object" && source !== null && source.nodeName === "A" && typeof source.href === "string";
182
- }
183
- /**
184
- * Validates a link and its title: see {@link resolveLinkUrl} for the URL rules.
185
- * An `<a>` element gives its `href` and its text (or `title` attribute).
186
- */
187
- function resolveLink(source, options = {}) {
188
- let url;
189
- let title;
190
- if (typeof source === "string" || source instanceof URL) url = source;
191
- else if (isAnchor(source)) {
192
- url = source.getAttribute("href") ?? "";
193
- title = source.textContent.trim() !== "" ? source.textContent : source.getAttribute("title") ?? void 0;
194
- if (url !== "" && options.base === void 0) url = source.href;
195
- } else if (typeof source === "object" && source !== null && "url" in source) {
196
- url = source.url;
197
- title = source.title;
198
- } else throw invalid$1("A link must be a URL, a { url, title } object or an <a> element.");
199
- if (title !== void 0 && typeof title !== "string") throw invalid$1("A link title must be a string.");
200
- const href = resolveLinkUrl(url, options);
201
- const clean = title === void 0 ? "" : cleanTitle(title, maxTitle(options.maxTitleLength));
202
- return {
203
- url: href,
204
- title: clean === "" ? href : clean,
205
- titled: clean !== ""
206
- };
207
- }
208
- const escapeHtml = (text) => text.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
209
- /** `[title](url)`, safe in every CommonMark renderer: brackets and backslashes escaped, parentheses and spaces encoded. */
210
- function markdownLink(link) {
211
- return `[${link.title.replace(/[\\[\]]/g, "\\$&")}](${link.url.replace(/[()<> ]/g, (char) => `%${char.charCodeAt(0).toString(16).toUpperCase()}`)})`;
212
- }
213
- function plainText(link, format) {
214
- switch (format) {
215
- case "url": return link.url;
216
- case "title": return link.title;
217
- case "title-and-url": return link.titled ? `${link.title}\n${link.url}` : link.url;
218
- case "markdown": return markdownLink(link);
219
- default: throw invalid$1(`\`text\` must be "url", "title", "title-and-url" or "markdown" (received ${JSON.stringify(format)}).`);
220
- }
221
- }
222
- function linkPayload(source, options = {}) {
223
- const target = options.target ?? "clipboard";
224
- if (target !== "drag" && target !== "clipboard") throw invalid$1("`target` must be \"clipboard\" or \"drag\".");
225
- const link = resolveLink(source, options);
226
- const text = plainText(link, options.text ?? "url");
227
- const html = `<a href="${escapeHtml(link.url)}">${escapeHtml(link.title)}</a>`;
228
- if (target === "clipboard") return {
229
- kind: "html",
230
- html,
231
- text
232
- };
233
- return {
234
- kind: "multi",
235
- items: [
236
- {
237
- mimeType: "text/plain",
238
- data: text
239
- },
240
- {
241
- mimeType: "text/html",
242
- data: html
243
- },
244
- {
245
- mimeType: "text/uri-list",
246
- data: link.url,
247
- optional: true
248
- },
249
- {
250
- mimeType: "text/x-moz-url",
251
- data: `${link.url}\n${link.title}`,
252
- optional: true
253
- }
254
- ]
255
- };
256
- }
257
- //#endregion
1
+
2
+ import { n as copyFailure } from "./chunks/errors-9h8sdFFX.js";
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
+ 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
+ import { n as insertText, t as asTextField } from "./chunks/text-field-DUvrMMaK.js";
258
6
  //#region src/link/fragment.ts
259
7
  const invalid = (message) => copyFailure("invalid-payload", message);
260
8
  const collapse = (text) => text.replace(/\s+/g, " ").trim();
@@ -435,68 +183,6 @@ function supportsTextFragments() {
435
183
  return typeof document !== "undefined" && "fragmentDirective" in document;
436
184
  }
437
185
  //#endregion
438
- //#region src/core/text-field.ts
439
- const TEXT_INPUTS = /* @__PURE__ */ new Set([
440
- "text",
441
- "search",
442
- "url",
443
- "tel",
444
- "password"
445
- ]);
446
- function asTextField(target) {
447
- if (typeof target !== "object" || target === null) return null;
448
- const element = target;
449
- if (element.nodeName === "TEXTAREA") return target;
450
- if (element.nodeName === "INPUT" && typeof element.type === "string" && TEXT_INPUTS.has(element.type)) return target;
451
- return null;
452
- }
453
- /**
454
- * Inserts text at the cursor of a `<textarea>` or text `<input>`, replacing the
455
- * selection, as typing or pasting would: the browser's undo (Ctrl/⌘+Z) still
456
- * works, `input` events fire (so React and other frameworks see the change),
457
- * and `maxlength` is respected. Returns `false` for disabled or read-only fields.
458
- */
459
- function insertText(field, text) {
460
- if (field.disabled || field.readOnly) return false;
461
- const value = field.nodeName === "INPUT" ? text.replace(/[ \t]*(?:\r\n|\r|\n)+[ \t]*/g, " ") : text;
462
- const doc = field.ownerDocument;
463
- field.focus();
464
- const start = field.selectionStart;
465
- const end = field.selectionEnd;
466
- try {
467
- if (start !== null && end !== null) field.setSelectionRange(start, end);
468
- if (doc.activeElement === field && doc.execCommand("insertText", false, value)) return true;
469
- } catch {}
470
- const from = start ?? field.value.length;
471
- const to = end ?? from;
472
- let insert = value;
473
- if (field.maxLength >= 0) {
474
- const room = Math.max(0, field.maxLength - (field.value.length - (to - from)));
475
- insert = insert.slice(0, room);
476
- if (/[\ud800-\udbff]$/.test(insert)) insert = insert.slice(0, -1);
477
- }
478
- if (start === null) setNativeValue(field, field.value + insert);
479
- else field.setRangeText(insert, from, to, "end");
480
- const view = doc.defaultView;
481
- const event = view !== null && typeof view.InputEvent === "function" ? new view.InputEvent("input", {
482
- bubbles: true,
483
- inputType: "insertFromPaste",
484
- data: insert
485
- }) : new Event("input", { bubbles: true });
486
- field.dispatchEvent(event);
487
- return true;
488
- }
489
- /**
490
- * Sets a field's value through the prototype's setter. React tracks the value
491
- * set on the element itself; going around it lets React see the change and
492
- * call `onChange` for the `input` event that follows.
493
- */
494
- function setNativeValue(field, next) {
495
- const setter = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(field), "value")?.set;
496
- if (setter) setter.call(field, next);
497
- else field.value = next;
498
- }
499
- //#endregion
500
186
  //#region src/link/paste.ts
501
187
  /** One URL with no spaces, as a whole pasted text (surrounding whitespace allowed). */
502
188
  const SINGLE_URL = /^\s*<?([a-z][a-z\d+.-]*:[^\s<>]+?)>?\s*$/i;