react-smart-copy 1.17.2 → 1.19.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 (154) hide show
  1. package/README.md +86 -5
  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/inert-html-D75NyVvT.js +34 -0
  35. package/dist/chunks/inert-html-D75NyVvT.js.map +1 -0
  36. package/dist/chunks/inert-html-DyxjWDok.cjs +39 -0
  37. package/dist/chunks/inert-html-DyxjWDok.cjs.map +1 -0
  38. package/dist/chunks/mime--LB7kdqG.cjs +153 -0
  39. package/dist/chunks/mime--LB7kdqG.cjs.map +1 -0
  40. package/dist/chunks/mime-aa-HA2dm.js +100 -0
  41. package/dist/chunks/mime-aa-HA2dm.js.map +1 -0
  42. package/dist/chunks/paste-adapter--SPL4PRE.d.cts +35 -0
  43. package/dist/chunks/paste-adapter-uahXnTYk.d.ts +35 -0
  44. package/dist/chunks/paste-reader-Bo01IMC_.cjs +289 -0
  45. package/dist/chunks/paste-reader-Bo01IMC_.cjs.map +1 -0
  46. package/dist/chunks/paste-reader-D9i7yMXF.js +224 -0
  47. package/dist/chunks/paste-reader-D9i7yMXF.js.map +1 -0
  48. package/dist/chunks/paste-reader-DcXnRWQr.d.cts +96 -0
  49. package/dist/chunks/paste-reader-DcXnRWQr.d.ts +96 -0
  50. package/dist/chunks/payload-CUymxwim.cjs +100 -0
  51. package/dist/chunks/payload-CUymxwim.cjs.map +1 -0
  52. package/dist/chunks/payload-CcwKJ_bU.d.cts +162 -0
  53. package/dist/chunks/payload-Cl_8hCI5.d.ts +162 -0
  54. package/dist/chunks/payload-DGw-JOo7.js +71 -0
  55. package/dist/chunks/payload-DGw-JOo7.js.map +1 -0
  56. package/dist/chunks/payload-DI5AorDz.js +103 -0
  57. package/dist/chunks/payload-DI5AorDz.js.map +1 -0
  58. package/dist/chunks/payload-J6GjHuh3.cjs +132 -0
  59. package/dist/chunks/payload-J6GjHuh3.cjs.map +1 -0
  60. package/dist/chunks/share-Bop47Znn.js +208 -0
  61. package/dist/chunks/share-Bop47Znn.js.map +1 -0
  62. package/dist/chunks/share-C0esXvRK.d.cts +115 -0
  63. package/dist/chunks/share-ayDz974N.cjs +231 -0
  64. package/dist/chunks/share-ayDz974N.cjs.map +1 -0
  65. package/dist/chunks/share-e7FenIr2.d.ts +115 -0
  66. package/dist/chunks/text-field-Ba8W3v4R.cjs +77 -0
  67. package/dist/chunks/text-field-Ba8W3v4R.cjs.map +1 -0
  68. package/dist/chunks/text-field-C0SGmvvR.d.cts +18 -0
  69. package/dist/chunks/text-field-C0SGmvvR.d.ts +18 -0
  70. package/dist/chunks/text-field-DUvrMMaK.js +66 -0
  71. package/dist/chunks/text-field-DUvrMMaK.js.map +1 -0
  72. package/dist/chunks/url-B9jdFGQy.cjs +86 -0
  73. package/dist/chunks/url-B9jdFGQy.cjs.map +1 -0
  74. package/dist/chunks/url-BcMYVCXQ.js +135 -0
  75. package/dist/chunks/url-BcMYVCXQ.js.map +1 -0
  76. package/dist/chunks/url-D4PGsRm8.cjs +164 -0
  77. package/dist/chunks/url-D4PGsRm8.cjs.map +1 -0
  78. package/dist/chunks/url-DWdElCT3.d.cts +43 -0
  79. package/dist/chunks/url-DWdElCT3.d.ts +43 -0
  80. package/dist/chunks/url-vJaFPbNL.js +57 -0
  81. package/dist/chunks/url-vJaFPbNL.js.map +1 -0
  82. package/dist/code.cjs +22 -113
  83. package/dist/code.cjs.map +1 -1
  84. package/dist/code.d.cts +4 -28
  85. package/dist/code.d.ts +4 -28
  86. package/dist/code.js +5 -96
  87. package/dist/code.js.map +1 -1
  88. package/dist/color.cjs +21 -893
  89. package/dist/color.cjs.map +1 -1
  90. package/dist/color.d.cts +4 -28
  91. package/dist/color.d.ts +4 -28
  92. package/dist/color.js +4 -876
  93. package/dist/color.js.map +1 -1
  94. package/dist/core.cjs +52 -1659
  95. package/dist/core.d.cts +8 -878
  96. package/dist/core.d.ts +8 -878
  97. package/dist/core.js +7 -1614
  98. package/dist/image.cjs +23 -94
  99. package/dist/image.cjs.map +1 -1
  100. package/dist/image.d.cts +1 -0
  101. package/dist/image.d.ts +1 -0
  102. package/dist/image.js +3 -74
  103. package/dist/image.js.map +1 -1
  104. package/dist/index.cjs +74 -2072
  105. package/dist/index.cjs.map +1 -1
  106. package/dist/index.d.cts +8 -978
  107. package/dist/index.d.ts +8 -978
  108. package/dist/index.js +7 -2005
  109. package/dist/index.js.map +1 -1
  110. package/dist/link.cjs +26 -339
  111. package/dist/link.cjs.map +1 -1
  112. package/dist/link.d.cts +5 -83
  113. package/dist/link.d.ts +5 -83
  114. package/dist/link.js +7 -320
  115. package/dist/link.js.map +1 -1
  116. package/dist/markdown.cjs +19 -159
  117. package/dist/markdown.cjs.map +1 -1
  118. package/dist/markdown.d.cts +3 -16
  119. package/dist/markdown.d.ts +3 -16
  120. package/dist/markdown.js +6 -146
  121. package/dist/markdown.js.map +1 -1
  122. package/dist/rich.cjs +1123 -940
  123. package/dist/rich.cjs.map +1 -1
  124. package/dist/rich.d.cts +101 -91
  125. package/dist/rich.d.ts +101 -91
  126. package/dist/rich.js +1099 -919
  127. package/dist/rich.js.map +1 -1
  128. package/dist/share.cjs +5 -640
  129. package/dist/share.d.cts +3 -248
  130. package/dist/share.d.ts +3 -248
  131. package/dist/share.js +1 -637
  132. package/dist/structured.cjs +13 -95
  133. package/dist/structured.cjs.map +1 -1
  134. package/dist/structured.d.cts +2 -11
  135. package/dist/structured.d.ts +2 -11
  136. package/dist/structured.js +4 -86
  137. package/dist/structured.js.map +1 -1
  138. package/dist/table.cjs +13 -40
  139. package/dist/table.cjs.map +1 -1
  140. package/dist/table.d.cts +2 -12
  141. package/dist/table.d.ts +2 -12
  142. package/dist/table.js +4 -31
  143. package/dist/table.js.map +1 -1
  144. package/dist/testing.cjs +10 -43
  145. package/dist/testing.cjs.map +1 -1
  146. package/dist/testing.d.cts +6 -181
  147. package/dist/testing.d.ts +6 -181
  148. package/dist/testing.js +3 -36
  149. package/dist/testing.js.map +1 -1
  150. package/package.json +37 -5
  151. package/dist/core.cjs.map +0 -1
  152. package/dist/core.js.map +0 -1
  153. package/dist/share.cjs.map +0 -1
  154. package/dist/share.js.map +0 -1
@@ -0,0 +1,162 @@
1
+
2
+ import { m as PasteSource } from "./paste-reader-DcXnRWQr.cjs";
3
+ //#region src/core/machine-shared.d.ts
4
+ /**
5
+ * Internals shared by the copy and paste state machines. Kept in one module so
6
+ * apps that use both don't ship two copies.
7
+ */
8
+ declare const DEFAULT_MAX_RETRIES = 3;
9
+ /**
10
+ * Passed to adapters and lazy sources as their last argument. `signal` aborts
11
+ * when the operation is superseded, `reset()`, or its host unmounts, so
12
+ * expensive work (rasterising, decoding) can stop early.
13
+ */
14
+ interface OperationContext {
15
+ readonly signal: AbortSignal;
16
+ }
17
+ declare function resolveMaxRetries(value: number | undefined): number;
18
+ //#endregion
19
+ //#region src/core/errors.d.ts
20
+ /**
21
+ * Every way a clipboard operation can fail, as a closed union.
22
+ *
23
+ * `CopyError.message` is developer-facing (logs, telemetry). For user-facing
24
+ * text use {@link describeCopyError} / {@link describePasteError}, or map
25
+ * `type` through your own i18n layer.
26
+ */
27
+ type CopyErrorType =
28
+ /** No Clipboard API (old browser, server, locked-down webview). Not retryable. */
29
+ 'unsupported' |
30
+ /** Page is not served over HTTPS/localhost. Not retryable. */
31
+ 'insecure-context' |
32
+ /** Browser or user blocked the operation. Also what Safari reports for a missing user gesture. */
33
+ 'permission-denied' |
34
+ /** The document lost focus mid-operation (Chromium). Retrying after refocus usually works. */
35
+ 'not-focused' |
36
+ /** Empty or malformed payload, or a lazy source that threw. Caught before touching the clipboard. */
37
+ 'invalid-payload' |
38
+ /** The browser cannot handle this MIME type (e.g. non-PNG image, HTML without ClipboardItem). */
39
+ 'unsupported-format' |
40
+ /** A lazy image source (or capture) threw, rejected or did not produce a Blob. */
41
+ 'blob-generation-failed' |
42
+ /** `retry()` was called after `maxRetries` was reached. Terminal. */
43
+ 'max-retries-exceeded' |
44
+ /** Paste: the clipboard held nothing matching `accept`. */
45
+ 'no-content' |
46
+ /** Content exceeded a configured safety limit (bytes, items or pixels). Not retryable. */
47
+ 'too-large' |
48
+ /** An operation did not settle within its deadline. Retryable. */
49
+ 'timeout' |
50
+ /** The caller aborted the operation through an `AbortSignal`. Not retryable. */
51
+ 'aborted' |
52
+ /** Anything the platform threw that we could not classify. */
53
+ 'unknown';
54
+ /** Which clipboard direction failed; only changes developer-facing messages. */
55
+ type ClipboardOperation = 'write' | 'read';
56
+ interface CopyError {
57
+ readonly type: CopyErrorType;
58
+ readonly message: string;
59
+ readonly cause?: unknown;
60
+ }
61
+ declare function createCopyError(type: CopyErrorType, message: string, cause?: unknown): CopyError;
62
+ /** Whether retrying the same payload could plausibly succeed. */
63
+ declare function isRetryableError(error: CopyError): boolean;
64
+ /**
65
+ * Branded (not `instanceof`) so failures stay recognisable even when the core
66
+ * is bundled twice, e.g. `react-smart-copy` and `react-smart-copy/core` together.
67
+ */
68
+ declare const COPY_FAILURE_BRAND: unique symbol;
69
+ /** Error thrown by adapters to carry a fully classified {@link CopyError}. */
70
+ declare class CopyFailure extends Error {
71
+ readonly copyError: CopyError;
72
+ readonly [COPY_FAILURE_BRAND] = true;
73
+ constructor(copyError: CopyError);
74
+ }
75
+ declare function isCopyFailure(value: unknown): value is CopyFailure;
76
+ /** Shorthand for throwing a classified failure. */
77
+ declare function copyFailure(type: CopyErrorType, message: string, cause?: unknown): CopyFailure;
78
+ /**
79
+ * Classifies anything thrown by the platform or an adapter into a {@link CopyError}.
80
+ * `operation` only tailors the developer-facing message.
81
+ */
82
+ declare function toCopyError(cause: unknown, operation?: ClipboardOperation): CopyError;
83
+ /** Default English, user-facing sentence for a copy error. Replace for i18n. */
84
+ declare function describeCopyError(error: CopyError): string;
85
+ /**
86
+ * Default English, user-facing sentence for a paste error. Pass the error
87
+ * state's `source` to word drag-and-drop failures as drops. Replace for i18n.
88
+ */
89
+ declare function describePasteError(error: CopyError, source?: PasteSource): string;
90
+ //#endregion
91
+ //#region src/core/payload.d.ts
92
+ /** The only image MIME type with reliable cross-browser clipboard write support. */
93
+ declare const IMAGE_MIME_TYPE = "image/png";
94
+ /**
95
+ * An image as a Blob, a promise of one, or a function producing one.
96
+ * Prefer the function form: it is invoked synchronously inside the user
97
+ * gesture, which Safari requires for async image generation. The browser
98
+ * adapter always passes an `OperationContext`: stop work once
99
+ * `context.signal` aborts (reset, superseded, unmount). Optional in the type
100
+ * so adapters that call sources themselves keep compiling.
101
+ */
102
+ type BlobSource = Blob | PromiseLike<Blob> | ((context?: OperationContext) => Blob | PromiseLike<Blob>);
103
+ interface TextPayload {
104
+ readonly kind: 'text';
105
+ readonly value: string;
106
+ }
107
+ interface HtmlPayload {
108
+ readonly kind: 'html';
109
+ readonly html: string;
110
+ /** Required plain-text fallback for targets that don't understand HTML. */
111
+ readonly text: string;
112
+ }
113
+ interface ImagePayload {
114
+ readonly kind: 'image';
115
+ readonly blob: BlobSource;
116
+ }
117
+ interface JsonPayload {
118
+ readonly kind: 'json';
119
+ readonly value: unknown;
120
+ /** `true` = 2-space indent, a number = that indent, falsy = compact. */
121
+ readonly pretty?: boolean | number;
122
+ }
123
+ interface MultiPayloadItem {
124
+ /**
125
+ * The MIME type, or a web custom format (`web application/vnd.acme+json`).
126
+ * Web custom formats are only written by the async Clipboard API; copy and drag
127
+ * events skip them.
128
+ */
129
+ readonly mimeType: string;
130
+ readonly data: string | Blob;
131
+ /**
132
+ * Skip this item, instead of failing the copy, when the browser cannot write its type.
133
+ * An optional item is only written when `ClipboardItem.supports()` confirms the type.
134
+ * At least one item must be written.
135
+ */
136
+ readonly optional?: boolean;
137
+ }
138
+ interface MultiPayload {
139
+ readonly kind: 'multi';
140
+ readonly items: readonly MultiPayloadItem[];
141
+ }
142
+ type CopyPayload = TextPayload | HtmlPayload | ImagePayload | JsonPayload | MultiPayload;
143
+ type CopyPayloadKind = CopyPayload['kind'];
144
+ /** A payload, or a bare string as shorthand for `{ kind: 'text' }`. */
145
+ type CopyInput = string | CopyPayload;
146
+ /**
147
+ * What `copy()` accepts. The function form is resolved synchronously at copy
148
+ * time, so it always reads the latest value without re-rendering.
149
+ */
150
+ type CopySource = CopyInput | (() => CopyInput);
151
+ declare function normalizePayload(input: CopyInput): CopyPayload;
152
+ declare function isBlob(value: unknown): value is Blob;
153
+ /**
154
+ * Structural validation. Typed callers can't produce most of these states,
155
+ * but plain-JS callers and runtime data can, so the check is always on.
156
+ */
157
+ declare function validatePayload(payload: unknown): CopyError | null;
158
+ /** Serialises a JSON payload, throwing a classified failure instead of a raw TypeError. */
159
+ declare function serializeJson(payload: JsonPayload): string;
160
+ //#endregion
161
+ export { resolveMaxRetries as A, describeCopyError as C, toCopyError as D, isRetryableError as E, DEFAULT_MAX_RETRIES as O, createCopyError as S, isCopyFailure as T, ClipboardOperation as _, CopySource as a, CopyFailure as b, ImagePayload as c, MultiPayloadItem as d, TextPayload as f, validatePayload as g, serializeJson as h, CopyPayloadKind as i, OperationContext as k, JsonPayload as l, normalizePayload as m, CopyInput as n, HtmlPayload as o, isBlob as p, CopyPayload as r, IMAGE_MIME_TYPE as s, BlobSource as t, MultiPayload as u, CopyError as v, describePasteError as w, copyFailure as x, CopyErrorType as y };
162
+ //# sourceMappingURL=payload-CcwKJ_bU.d.cts.map
@@ -0,0 +1,162 @@
1
+
2
+ import { m as PasteSource } from "./paste-reader-DcXnRWQr.js";
3
+ //#region src/core/machine-shared.d.ts
4
+ /**
5
+ * Internals shared by the copy and paste state machines. Kept in one module so
6
+ * apps that use both don't ship two copies.
7
+ */
8
+ declare const DEFAULT_MAX_RETRIES = 3;
9
+ /**
10
+ * Passed to adapters and lazy sources as their last argument. `signal` aborts
11
+ * when the operation is superseded, `reset()`, or its host unmounts, so
12
+ * expensive work (rasterising, decoding) can stop early.
13
+ */
14
+ interface OperationContext {
15
+ readonly signal: AbortSignal;
16
+ }
17
+ declare function resolveMaxRetries(value: number | undefined): number;
18
+ //#endregion
19
+ //#region src/core/errors.d.ts
20
+ /**
21
+ * Every way a clipboard operation can fail, as a closed union.
22
+ *
23
+ * `CopyError.message` is developer-facing (logs, telemetry). For user-facing
24
+ * text use {@link describeCopyError} / {@link describePasteError}, or map
25
+ * `type` through your own i18n layer.
26
+ */
27
+ type CopyErrorType =
28
+ /** No Clipboard API (old browser, server, locked-down webview). Not retryable. */
29
+ 'unsupported' |
30
+ /** Page is not served over HTTPS/localhost. Not retryable. */
31
+ 'insecure-context' |
32
+ /** Browser or user blocked the operation. Also what Safari reports for a missing user gesture. */
33
+ 'permission-denied' |
34
+ /** The document lost focus mid-operation (Chromium). Retrying after refocus usually works. */
35
+ 'not-focused' |
36
+ /** Empty or malformed payload, or a lazy source that threw. Caught before touching the clipboard. */
37
+ 'invalid-payload' |
38
+ /** The browser cannot handle this MIME type (e.g. non-PNG image, HTML without ClipboardItem). */
39
+ 'unsupported-format' |
40
+ /** A lazy image source (or capture) threw, rejected or did not produce a Blob. */
41
+ 'blob-generation-failed' |
42
+ /** `retry()` was called after `maxRetries` was reached. Terminal. */
43
+ 'max-retries-exceeded' |
44
+ /** Paste: the clipboard held nothing matching `accept`. */
45
+ 'no-content' |
46
+ /** Content exceeded a configured safety limit (bytes, items or pixels). Not retryable. */
47
+ 'too-large' |
48
+ /** An operation did not settle within its deadline. Retryable. */
49
+ 'timeout' |
50
+ /** The caller aborted the operation through an `AbortSignal`. Not retryable. */
51
+ 'aborted' |
52
+ /** Anything the platform threw that we could not classify. */
53
+ 'unknown';
54
+ /** Which clipboard direction failed; only changes developer-facing messages. */
55
+ type ClipboardOperation = 'write' | 'read';
56
+ interface CopyError {
57
+ readonly type: CopyErrorType;
58
+ readonly message: string;
59
+ readonly cause?: unknown;
60
+ }
61
+ declare function createCopyError(type: CopyErrorType, message: string, cause?: unknown): CopyError;
62
+ /** Whether retrying the same payload could plausibly succeed. */
63
+ declare function isRetryableError(error: CopyError): boolean;
64
+ /**
65
+ * Branded (not `instanceof`) so failures stay recognisable even when the core
66
+ * is bundled twice, e.g. `react-smart-copy` and `react-smart-copy/core` together.
67
+ */
68
+ declare const COPY_FAILURE_BRAND: unique symbol;
69
+ /** Error thrown by adapters to carry a fully classified {@link CopyError}. */
70
+ declare class CopyFailure extends Error {
71
+ readonly copyError: CopyError;
72
+ readonly [COPY_FAILURE_BRAND] = true;
73
+ constructor(copyError: CopyError);
74
+ }
75
+ declare function isCopyFailure(value: unknown): value is CopyFailure;
76
+ /** Shorthand for throwing a classified failure. */
77
+ declare function copyFailure(type: CopyErrorType, message: string, cause?: unknown): CopyFailure;
78
+ /**
79
+ * Classifies anything thrown by the platform or an adapter into a {@link CopyError}.
80
+ * `operation` only tailors the developer-facing message.
81
+ */
82
+ declare function toCopyError(cause: unknown, operation?: ClipboardOperation): CopyError;
83
+ /** Default English, user-facing sentence for a copy error. Replace for i18n. */
84
+ declare function describeCopyError(error: CopyError): string;
85
+ /**
86
+ * Default English, user-facing sentence for a paste error. Pass the error
87
+ * state's `source` to word drag-and-drop failures as drops. Replace for i18n.
88
+ */
89
+ declare function describePasteError(error: CopyError, source?: PasteSource): string;
90
+ //#endregion
91
+ //#region src/core/payload.d.ts
92
+ /** The only image MIME type with reliable cross-browser clipboard write support. */
93
+ declare const IMAGE_MIME_TYPE = "image/png";
94
+ /**
95
+ * An image as a Blob, a promise of one, or a function producing one.
96
+ * Prefer the function form: it is invoked synchronously inside the user
97
+ * gesture, which Safari requires for async image generation. The browser
98
+ * adapter always passes an `OperationContext`: stop work once
99
+ * `context.signal` aborts (reset, superseded, unmount). Optional in the type
100
+ * so adapters that call sources themselves keep compiling.
101
+ */
102
+ type BlobSource = Blob | PromiseLike<Blob> | ((context?: OperationContext) => Blob | PromiseLike<Blob>);
103
+ interface TextPayload {
104
+ readonly kind: 'text';
105
+ readonly value: string;
106
+ }
107
+ interface HtmlPayload {
108
+ readonly kind: 'html';
109
+ readonly html: string;
110
+ /** Required plain-text fallback for targets that don't understand HTML. */
111
+ readonly text: string;
112
+ }
113
+ interface ImagePayload {
114
+ readonly kind: 'image';
115
+ readonly blob: BlobSource;
116
+ }
117
+ interface JsonPayload {
118
+ readonly kind: 'json';
119
+ readonly value: unknown;
120
+ /** `true` = 2-space indent, a number = that indent, falsy = compact. */
121
+ readonly pretty?: boolean | number;
122
+ }
123
+ interface MultiPayloadItem {
124
+ /**
125
+ * The MIME type, or a web custom format (`web application/vnd.acme+json`).
126
+ * Web custom formats are only written by the async Clipboard API; copy and drag
127
+ * events skip them.
128
+ */
129
+ readonly mimeType: string;
130
+ readonly data: string | Blob;
131
+ /**
132
+ * Skip this item, instead of failing the copy, when the browser cannot write its type.
133
+ * An optional item is only written when `ClipboardItem.supports()` confirms the type.
134
+ * At least one item must be written.
135
+ */
136
+ readonly optional?: boolean;
137
+ }
138
+ interface MultiPayload {
139
+ readonly kind: 'multi';
140
+ readonly items: readonly MultiPayloadItem[];
141
+ }
142
+ type CopyPayload = TextPayload | HtmlPayload | ImagePayload | JsonPayload | MultiPayload;
143
+ type CopyPayloadKind = CopyPayload['kind'];
144
+ /** A payload, or a bare string as shorthand for `{ kind: 'text' }`. */
145
+ type CopyInput = string | CopyPayload;
146
+ /**
147
+ * What `copy()` accepts. The function form is resolved synchronously at copy
148
+ * time, so it always reads the latest value without re-rendering.
149
+ */
150
+ type CopySource = CopyInput | (() => CopyInput);
151
+ declare function normalizePayload(input: CopyInput): CopyPayload;
152
+ declare function isBlob(value: unknown): value is Blob;
153
+ /**
154
+ * Structural validation. Typed callers can't produce most of these states,
155
+ * but plain-JS callers and runtime data can, so the check is always on.
156
+ */
157
+ declare function validatePayload(payload: unknown): CopyError | null;
158
+ /** Serialises a JSON payload, throwing a classified failure instead of a raw TypeError. */
159
+ declare function serializeJson(payload: JsonPayload): string;
160
+ //#endregion
161
+ export { resolveMaxRetries as A, describeCopyError as C, toCopyError as D, isRetryableError as E, DEFAULT_MAX_RETRIES as O, createCopyError as S, isCopyFailure as T, ClipboardOperation as _, CopySource as a, CopyFailure as b, ImagePayload as c, MultiPayloadItem as d, TextPayload as f, validatePayload as g, serializeJson as h, CopyPayloadKind as i, OperationContext as k, JsonPayload as l, normalizePayload as m, CopyInput as n, HtmlPayload as o, isBlob as p, CopyPayload as r, IMAGE_MIME_TYPE as s, BlobSource as t, MultiPayload as u, CopyError as v, describePasteError as w, copyFailure as x, CopyErrorType as y };
162
+ //# sourceMappingURL=payload-Cl_8hCI5.d.ts.map
@@ -0,0 +1,71 @@
1
+
2
+ import { r as createCopyError, t as CopyFailure } from "./errors-9h8sdFFX.js";
3
+ //#region src/core/payload.ts
4
+ /** The only image MIME type with reliable cross-browser clipboard write support. */
5
+ const IMAGE_MIME_TYPE = "image/png";
6
+ function normalizePayload(input) {
7
+ return typeof input === "string" ? {
8
+ kind: "text",
9
+ value: input
10
+ } : input;
11
+ }
12
+ function isBlob(value) {
13
+ if (typeof Blob !== "undefined" && value instanceof Blob) return true;
14
+ const tag = Object.prototype.toString.call(value);
15
+ return tag === "[object Blob]" || tag === "[object File]";
16
+ }
17
+ function isThenable(value) {
18
+ return (typeof value === "object" || typeof value === "function") && value !== null && typeof value.then === "function";
19
+ }
20
+ const invalid = (message) => createCopyError("invalid-payload", message);
21
+ /**
22
+ * Structural validation. Typed callers can't produce most of these states,
23
+ * but plain-JS callers and runtime data can, so the check is always on.
24
+ */
25
+ function validatePayload(payload) {
26
+ if (typeof payload !== "object" || payload === null) return invalid("Copy input must be a string or a payload object.");
27
+ const candidate = payload;
28
+ switch (candidate["kind"]) {
29
+ case "text": return typeof candidate["value"] === "string" && candidate["value"].length > 0 ? null : invalid("Text payload must be a non-empty string.");
30
+ case "html":
31
+ if (typeof candidate["html"] !== "string" || candidate["html"].length === 0) return invalid("HTML payload requires a non-empty `html` string.");
32
+ return typeof candidate["text"] === "string" && candidate["text"].length > 0 ? null : invalid("HTML payload requires a non-empty plain-text `text` fallback.");
33
+ case "image": {
34
+ const source = candidate["blob"];
35
+ return isBlob(source) || typeof source === "function" || isThenable(source) ? null : invalid("Image payload requires a Blob, a Promise<Blob> or a function returning one.");
36
+ }
37
+ case "json": return candidate["value"] === void 0 ? invalid("JSON payload value is undefined.") : null;
38
+ case "multi": {
39
+ const items = candidate["items"];
40
+ if (!Array.isArray(items) || items.length === 0) return invalid("Multi payload requires at least one item.");
41
+ const seen = /* @__PURE__ */ new Set();
42
+ for (const item of items) {
43
+ const entry = typeof item === "object" && item !== null ? item : {};
44
+ const mimeType = entry["mimeType"];
45
+ const data = entry["data"];
46
+ if (typeof mimeType !== "string" || mimeType.length === 0) return invalid("Every multi item needs a non-empty `mimeType`.");
47
+ if (seen.has(mimeType)) return invalid(`Duplicate MIME type "${mimeType}" in multi payload.`);
48
+ seen.add(mimeType);
49
+ if (typeof data !== "string" && !isBlob(data)) return invalid(`Multi item "${mimeType}" must contain a string or a Blob.`);
50
+ }
51
+ return null;
52
+ }
53
+ default: return invalid(`Unknown payload kind: ${String(candidate["kind"])}.`);
54
+ }
55
+ }
56
+ /** Serialises a JSON payload, throwing a classified failure instead of a raw TypeError. */
57
+ function serializeJson(payload) {
58
+ const indent = payload.pretty === true ? 2 : typeof payload.pretty === "number" ? payload.pretty : void 0;
59
+ let text;
60
+ try {
61
+ text = JSON.stringify(payload.value, null, indent);
62
+ } catch (cause) {
63
+ throw new CopyFailure(createCopyError("invalid-payload", "JSON payload could not be serialised (circular reference or BigInt?).", cause));
64
+ }
65
+ if (typeof text !== "string") throw new CopyFailure(createCopyError("invalid-payload", "JSON payload serialised to nothing (functions, symbols and undefined are not JSON)."));
66
+ return text;
67
+ }
68
+ //#endregion
69
+ export { validatePayload as a, serializeJson as i, isBlob as n, normalizePayload as r, IMAGE_MIME_TYPE as t };
70
+
71
+ //# sourceMappingURL=payload-DGw-JOo7.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"payload-DGw-JOo7.js","names":[],"sources":["../../src/core/payload.ts"],"sourcesContent":["import { CopyFailure, createCopyError, type CopyError } from './errors';\nimport type { OperationContext } from './machine-shared';\n\n/** The only image MIME type with reliable cross-browser clipboard write support. */\nexport const IMAGE_MIME_TYPE = 'image/png';\n\n/**\n * An image as a Blob, a promise of one, or a function producing one.\n * Prefer the function form: it is invoked synchronously inside the user\n * gesture, which Safari requires for async image generation. The browser\n * adapter always passes an `OperationContext`: stop work once\n * `context.signal` aborts (reset, superseded, unmount). Optional in the type\n * so adapters that call sources themselves keep compiling.\n */\nexport type BlobSource = Blob | PromiseLike<Blob> | ((context?: OperationContext) => Blob | PromiseLike<Blob>);\n\nexport interface TextPayload {\n readonly kind: 'text';\n readonly value: string;\n}\n\nexport interface HtmlPayload {\n readonly kind: 'html';\n readonly html: string;\n /** Required plain-text fallback for targets that don't understand HTML. */\n readonly text: string;\n}\n\nexport interface ImagePayload {\n readonly kind: 'image';\n readonly blob: BlobSource;\n}\n\nexport interface JsonPayload {\n readonly kind: 'json';\n readonly value: unknown;\n /** `true` = 2-space indent, a number = that indent, falsy = compact. */\n readonly pretty?: boolean | number;\n}\n\nexport interface MultiPayloadItem {\n /**\n * The MIME type, or a web custom format (`web application/vnd.acme+json`).\n * Web custom formats are only written by the async Clipboard API; copy and drag\n * events skip them.\n */\n readonly mimeType: string;\n readonly data: string | Blob;\n /**\n * Skip this item, instead of failing the copy, when the browser cannot write its type.\n * An optional item is only written when `ClipboardItem.supports()` confirms the type.\n * At least one item must be written.\n */\n readonly optional?: boolean;\n}\n\nexport interface MultiPayload {\n readonly kind: 'multi';\n readonly items: readonly MultiPayloadItem[];\n}\n\nexport type CopyPayload = TextPayload | HtmlPayload | ImagePayload | JsonPayload | MultiPayload;\nexport type CopyPayloadKind = CopyPayload['kind'];\n\n/** A payload, or a bare string as shorthand for `{ kind: 'text' }`. */\nexport type CopyInput = string | CopyPayload;\n\n/**\n * What `copy()` accepts. The function form is resolved synchronously at copy\n * time, so it always reads the latest value without re-rendering.\n */\nexport type CopySource = CopyInput | (() => CopyInput);\n\nexport function normalizePayload(input: CopyInput): CopyPayload {\n return typeof input === 'string' ? { kind: 'text', value: input } : input;\n}\n\nexport function isBlob(value: unknown): value is Blob {\n if (typeof Blob !== 'undefined' && value instanceof Blob) return true;\n const tag = Object.prototype.toString.call(value);\n return tag === '[object Blob]' || tag === '[object File]';\n}\n\nfunction isThenable(value: unknown): value is PromiseLike<unknown> {\n return (\n (typeof value === 'object' || typeof value === 'function') &&\n value !== null &&\n typeof (value as { then?: unknown }).then === 'function'\n );\n}\n\nconst invalid = (message: string): CopyError => createCopyError('invalid-payload', message);\n\n/**\n * Structural validation. Typed callers can't produce most of these states,\n * but plain-JS callers and runtime data can, so the check is always on.\n */\nexport function validatePayload(payload: unknown): CopyError | null {\n if (typeof payload !== 'object' || payload === null) {\n return invalid('Copy input must be a string or a payload object.');\n }\n const candidate = payload as Record<string, unknown>;\n\n switch (candidate['kind']) {\n case 'text':\n return typeof candidate['value'] === 'string' && candidate['value'].length > 0\n ? null\n : invalid('Text payload must be a non-empty string.');\n case 'html':\n if (typeof candidate['html'] !== 'string' || candidate['html'].length === 0) {\n return invalid('HTML payload requires a non-empty `html` string.');\n }\n return typeof candidate['text'] === 'string' && candidate['text'].length > 0\n ? null\n : invalid('HTML payload requires a non-empty plain-text `text` fallback.');\n case 'image': {\n const source = candidate['blob'];\n return isBlob(source) || typeof source === 'function' || isThenable(source)\n ? null\n : invalid('Image payload requires a Blob, a Promise<Blob> or a function returning one.');\n }\n case 'json':\n return candidate['value'] === undefined ? invalid('JSON payload value is undefined.') : null;\n case 'multi': {\n const items = candidate['items'];\n if (!Array.isArray(items) || items.length === 0) {\n return invalid('Multi payload requires at least one item.');\n }\n const seen = new Set<string>();\n for (const item of items as unknown[]) {\n const entry = (typeof item === 'object' && item !== null ? item : {}) as Record<string, unknown>;\n const mimeType = entry['mimeType'];\n const data = entry['data'];\n if (typeof mimeType !== 'string' || mimeType.length === 0) {\n return invalid('Every multi item needs a non-empty `mimeType`.');\n }\n if (seen.has(mimeType)) return invalid(`Duplicate MIME type \"${mimeType}\" in multi payload.`);\n seen.add(mimeType);\n if (typeof data !== 'string' && !isBlob(data)) {\n return invalid(`Multi item \"${mimeType}\" must contain a string or a Blob.`);\n }\n }\n return null;\n }\n default:\n return invalid(`Unknown payload kind: ${String(candidate['kind'])}.`);\n }\n}\n\n/** Serialises a JSON payload, throwing a classified failure instead of a raw TypeError. */\nexport function serializeJson(payload: JsonPayload): string {\n const indent =\n payload.pretty === true ? 2 : typeof payload.pretty === 'number' ? payload.pretty : undefined;\n // Typed as `string` by lib.d.ts, but returns undefined for functions, symbols and undefined.\n let text: unknown;\n try {\n text = JSON.stringify(payload.value, null, indent);\n } catch (cause) {\n throw new CopyFailure(\n createCopyError('invalid-payload', 'JSON payload could not be serialised (circular reference or BigInt?).', cause),\n );\n }\n if (typeof text !== 'string') {\n throw new CopyFailure(\n createCopyError('invalid-payload', 'JSON payload serialised to nothing (functions, symbols and undefined are not JSON).'),\n );\n }\n return text;\n}\n"],"mappings":";;;;AAIA,MAAa,kBAAkB;AAqE/B,SAAgB,iBAAiB,OAA+B;CAC9D,OAAO,OAAO,UAAU,WAAW;EAAE,MAAM;EAAQ,OAAO;CAAM,IAAI;AACtE;AAEA,SAAgB,OAAO,OAA+B;CACpD,IAAI,OAAO,SAAS,eAAe,iBAAiB,MAAM,OAAO;CACjE,MAAM,MAAM,OAAO,UAAU,SAAS,KAAK,KAAK;CAChD,OAAO,QAAQ,mBAAmB,QAAQ;AAC5C;AAEA,SAAS,WAAW,OAA+C;CACjE,QACG,OAAO,UAAU,YAAY,OAAO,UAAU,eAC/C,UAAU,QACV,OAAQ,MAA6B,SAAS;AAElD;AAEA,MAAM,WAAW,YAA+B,gBAAgB,mBAAmB,OAAO;;;;;AAM1F,SAAgB,gBAAgB,SAAoC;CAClE,IAAI,OAAO,YAAY,YAAY,YAAY,MAC7C,OAAO,QAAQ,kDAAkD;CAEnE,MAAM,YAAY;CAElB,QAAQ,UAAU,SAAlB;EACE,KAAK,QACH,OAAO,OAAO,UAAU,aAAa,YAAY,UAAU,QAAQ,CAAC,SAAS,IACzE,OACA,QAAQ,0CAA0C;EACxD,KA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ACnD,SAAS,OAAO;EACd,MAAM,IAAI,YACR,gBAAgB,mBAAmB,yEAAyE,KAAK,CACnH;CACF;CACA,IAAI,OAAO,SAAS,UAClB,MAAM,IAAI,YACR,gBAAgB,mBAAmB,qFAAqF,CAC1H;CAEF,OAAO;AACT"}
@@ -0,0 +1,103 @@
1
+
2
+ import { n as copyFailure } from "./errors-9h8sdFFX.js";
3
+ import { a as resolveLinkUrl } from "./url-BcMYVCXQ.js";
4
+ //#region src/link/payload.ts
5
+ const DEFAULT_LINK_TITLE_LENGTH = 300;
6
+ const invalid = (message) => copyFailure("invalid-payload", message);
7
+ /**
8
+ * Characters a title never keeps: controls, bidi overrides and isolates (which can
9
+ * make a title read differently), and zero-width characters.
10
+ */
11
+ const HIDDEN = /[\0-\x08\x0b\x0c\x0e-\x1f\x7f-\x9f\u061C\u200B-\u200F\u202A-\u202E\u2060-\u2064\u2066-\u2069\uFEFF]/g;
12
+ /** A title as one clean line: hidden characters removed, whitespace collapsed, length capped. */
13
+ function cleanTitle(title, maxLength) {
14
+ const clean = title.replace(HIDDEN, "").replace(/\s+/g, " ").trim();
15
+ if (clean.length <= maxLength) return clean;
16
+ return `${Array.from(clean).slice(0, maxLength - 1).join("").trimEnd()}\u2026`;
17
+ }
18
+ function maxTitle(value) {
19
+ if (value === void 0) return 300;
20
+ if (Number.isInteger(value) && value >= 1) return value;
21
+ throw invalid(`\`maxTitleLength\` must be a positive integer (received ${String(value)}).`);
22
+ }
23
+ function isAnchor(source) {
24
+ return typeof source === "object" && source !== null && source.nodeName === "A" && typeof source.href === "string";
25
+ }
26
+ /**
27
+ * Validates a link and its title: see {@link resolveLinkUrl} for the URL rules.
28
+ * An `<a>` element gives its `href` and its text (or `title` attribute).
29
+ */
30
+ function resolveLink(source, options = {}) {
31
+ let url;
32
+ let title;
33
+ if (typeof source === "string" || source instanceof URL) url = source;
34
+ else if (isAnchor(source)) {
35
+ url = source.getAttribute("href") ?? "";
36
+ title = source.textContent.trim() !== "" ? source.textContent : source.getAttribute("title") ?? void 0;
37
+ if (url !== "" && options.base === void 0) url = source.href;
38
+ } else if (typeof source === "object" && source !== null && "url" in source) {
39
+ url = source.url;
40
+ title = source.title;
41
+ } else throw invalid("A link must be a URL, a { url, title } object or an <a> element.");
42
+ if (title !== void 0 && typeof title !== "string") throw invalid("A link title must be a string.");
43
+ const href = resolveLinkUrl(url, options);
44
+ const clean = title === void 0 ? "" : cleanTitle(title, maxTitle(options.maxTitleLength));
45
+ return {
46
+ url: href,
47
+ title: clean === "" ? href : clean,
48
+ titled: clean !== ""
49
+ };
50
+ }
51
+ const escapeHtml = (text) => text.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
52
+ /** `[title](url)`, safe in every CommonMark renderer: brackets and backslashes escaped, parentheses and spaces encoded. */
53
+ function markdownLink(link) {
54
+ return `[${link.title.replace(/[\\[\]]/g, "\\$&")}](${link.url.replace(/[()<> ]/g, (char) => `%${char.charCodeAt(0).toString(16).toUpperCase()}`)})`;
55
+ }
56
+ function plainText(link, format) {
57
+ switch (format) {
58
+ case "url": return link.url;
59
+ case "title": return link.title;
60
+ case "title-and-url": return link.titled ? `${link.title}\n${link.url}` : link.url;
61
+ case "markdown": return markdownLink(link);
62
+ default: throw invalid(`\`text\` must be "url", "title", "title-and-url" or "markdown" (received ${JSON.stringify(format)}).`);
63
+ }
64
+ }
65
+ function linkPayload(source, options = {}) {
66
+ const target = options.target ?? "clipboard";
67
+ if (target !== "drag" && target !== "clipboard") throw invalid("`target` must be \"clipboard\" or \"drag\".");
68
+ const link = resolveLink(source, options);
69
+ const text = plainText(link, options.text ?? "url");
70
+ const html = `<a href="${escapeHtml(link.url)}">${escapeHtml(link.title)}</a>`;
71
+ if (target === "clipboard") return {
72
+ kind: "html",
73
+ html,
74
+ text
75
+ };
76
+ return {
77
+ kind: "multi",
78
+ items: [
79
+ {
80
+ mimeType: "text/plain",
81
+ data: text
82
+ },
83
+ {
84
+ mimeType: "text/html",
85
+ data: html
86
+ },
87
+ {
88
+ mimeType: "text/uri-list",
89
+ data: link.url,
90
+ optional: true
91
+ },
92
+ {
93
+ mimeType: "text/x-moz-url",
94
+ data: `${link.url}\n${link.title}`,
95
+ optional: true
96
+ }
97
+ ]
98
+ };
99
+ }
100
+ //#endregion
101
+ export { resolveLink as a, markdownLink as i, cleanTitle as n, linkPayload as r, DEFAULT_LINK_TITLE_LENGTH as t };
102
+
103
+ //# sourceMappingURL=payload-DI5AorDz.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"payload-DI5AorDz.js","names":[],"sources":["../../src/link/payload.ts"],"sourcesContent":["import { copyFailure } from '../core/errors';\nimport type { HtmlPayload, MultiPayload } from '../core/payload';\nimport { resolveLinkUrl, type LinkUrlOptions } from './url';\n\n/** A link with an optional title. */\nexport interface Link {\n readonly url: string | URL;\n /** What the link says when pasted into a document or chat. Default: the URL. */\n readonly title?: string;\n}\n\n/** A link: a URL, a `{ url, title }` object, or an `<a>` element (its `href` and text). */\nexport type LinkSource = string | URL | Link | HTMLAnchorElement;\n\n/** A validated link: an absolute, safe URL and a clean title. */\nexport interface ResolvedLink {\n readonly url: string;\n /** Never empty: the URL when there is no title. */\n readonly title: string;\n /** Whether `title` came from the input (`false`: it is the URL). */\n readonly titled: boolean;\n}\n\n/**\n * What the plain-text flavour holds (editors, terminals and address bars paste it):\n * `'url'` (the default), `'title'`, `'title-and-url'` (the title, then the URL on\n * the next line) or `'markdown'` (`[Title](URL)`).\n */\nexport type LinkTextFormat = 'url' | 'title' | 'title-and-url' | 'markdown';\n\nexport interface LinkPayloadOptions extends LinkUrlOptions {\n /** Default `'url'`. */\n readonly text?: LinkTextFormat;\n /** Longest title kept, in characters; longer ones end in an ellipsis. Default {@link DEFAULT_LINK_TITLE_LENGTH}. */\n readonly maxTitleLength?: number;\n}\n\nexport interface LinkDragPayloadOptions extends LinkPayloadOptions {\n /**\n * `'drag'`: a multi-format payload that also carries `text/uri-list` and\n * Firefox's `text/x-moz-url`, for `useDragCopy` and `useCopyInterceptor` (a link\n * dropped on the tab bar opens). Clipboard writes skip those two where the\n * browser can't write them.\n */\n readonly target: 'drag';\n}\n\nexport const DEFAULT_LINK_TITLE_LENGTH = 300;\n\nconst invalid = (message: string) => copyFailure('invalid-payload', message);\n\n/**\n * Characters a title never keeps: controls, bidi overrides and isolates (which can\n * make a title read differently), and zero-width characters.\n */\n// eslint-disable-next-line no-control-regex -- matching control characters is the point\nconst HIDDEN = /[\\0-\\x08\\x0b\\x0c\\x0e-\\x1f\\x7f-\\x9f\\u061C\\u200B-\\u200F\\u202A-\\u202E\\u2060-\\u2064\\u2066-\\u2069\\uFEFF]/g;\n\n/** A title as one clean line: hidden characters removed, whitespace collapsed, length capped. */\nexport function cleanTitle(title: string, maxLength: number): string {\n const clean = title.replace(HIDDEN, '').replace(/\\s+/g, ' ').trim();\n if (clean.length <= maxLength) return clean;\n // Cut on a code point boundary and mark the cut.\n return `${Array.from(clean).slice(0, maxLength - 1).join('').trimEnd()}\\u2026`;\n}\n\nfunction maxTitle(value: number | undefined): number {\n if (value === undefined) return DEFAULT_LINK_TITLE_LENGTH;\n if (Number.isInteger(value) && value >= 1) return value;\n throw invalid(`\\`maxTitleLength\\` must be a positive integer (received ${String(value)}).`);\n}\n\nfunction isAnchor(source: unknown): source is HTMLAnchorElement {\n return typeof source === 'object' && source !== null && (source as { nodeName?: unknown }).nodeName === 'A' && typeof (source as { href?: unknown }).href === 'string';\n}\n\n/**\n * Validates a link and its title: see {@link resolveLinkUrl} for the URL rules.\n * An `<a>` element gives its `href` and its text (or `title` attribute).\n */\nexport function resolveLink(source: LinkSource, options: LinkPayloadOptions = {}): ResolvedLink {\n let url: string | URL;\n let title: unknown;\n if (typeof source === 'string' || source instanceof URL) {\n url = source;\n } else if (isAnchor(source)) {\n url = source.getAttribute('href') ?? '';\n title = source.textContent.trim() !== '' ? source.textContent : (source.getAttribute('title') ?? undefined);\n if (url !== '' && options.base === undefined) url = source.href; // Resolved against the anchor's own document.\n } else if (typeof (source as unknown) === 'object' && (source as unknown) !== null && 'url' in source) {\n url = source.url;\n title = source.title;\n } else {\n throw invalid('A link must be a URL, a { url, title } object or an <a> element.');\n }\n if (title !== undefined && typeof title !== 'string') throw invalid('A link title must be a string.');\n const href = resolveLinkUrl(url, options);\n const clean = title === undefined ? '' : cleanTitle(title, maxTitle(options.maxTitleLength));\n return { url: href, title: clean === '' ? href : clean, titled: clean !== '' };\n}\n\nexport const escapeHtml = (text: string): string =>\n text.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/\"/g, '&quot;').replace(/'/g, '&#39;');\n\n/** `[title](url)`, safe in every CommonMark renderer: brackets and backslashes escaped, parentheses and spaces encoded. */\nexport function markdownLink(link: ResolvedLink): string {\n const label = link.title.replace(/[\\\\[\\]]/g, '\\\\$&');\n const target = link.url.replace(/[()<> ]/g, (char) => `%${char.charCodeAt(0).toString(16).toUpperCase()}`);\n return `[${label}](${target})`;\n}\n\nfunction plainText(link: ResolvedLink, format: LinkTextFormat): string {\n switch (format) {\n case 'url':\n return link.url;\n case 'title':\n return link.title;\n case 'title-and-url':\n return link.titled ? `${link.title}\\n${link.url}` : link.url;\n case 'markdown':\n return markdownLink(link);\n default:\n throw invalid(`\\`text\\` must be \"url\", \"title\", \"title-and-url\" or \"markdown\" (received ${JSON.stringify(format)}).`);\n }\n}\n\n/**\n * A copy payload for a link: an HTML anchor, so Slack, Google Docs, Notion,\n * Teams, Word and mail paste a titled link, and plain text (the URL by default)\n * for editors and address bars. The URL is validated (allowed schemes only,\n * credentials removed, optionally cleaned of tracking) and the title is cleaned\n * of hidden characters; both are escaped.\n *\n * @example\n * copy(() => linkPayload({ url: location.href, title: document.title }, { clean: true }));\n * useDragCopy({ payload: () => linkPayload(anchor, { target: 'drag' }) });\n */\nexport function linkPayload(source: LinkSource, options: LinkDragPayloadOptions): MultiPayload;\nexport function linkPayload(source: LinkSource, options?: LinkPayloadOptions): HtmlPayload;\nexport function linkPayload(source: LinkSource, options: LinkPayloadOptions & { readonly target?: 'drag' | 'clipboard' } = {}): HtmlPayload | MultiPayload {\n const target: unknown = options.target ?? 'clipboard'; // Plain-JS callers can pass anything.\n if (target !== 'drag' && target !== 'clipboard') throw invalid('`target` must be \"clipboard\" or \"drag\".');\n const link = resolveLink(source, options);\n const text = plainText(link, options.text ?? 'url');\n const html = `<a href=\"${escapeHtml(link.url)}\">${escapeHtml(link.title)}</a>`;\n if (target === 'clipboard') return { kind: 'html', html, text };\n return {\n kind: 'multi',\n items: [\n { mimeType: 'text/plain', data: text },\n { mimeType: 'text/html', data: html },\n { mimeType: 'text/uri-list', data: link.url, optional: true },\n // Firefox's titled-link format: the URL, a line break, the title.\n { mimeType: 'text/x-moz-url', data: `${link.url}\\n${link.title}`, optional: true },\n ],\n };\n}\n"],"mappings":";;;;AA+CA,MAAa,4BAA4B;AAEzC,MAAM,WAAW,YAAoB,YAAY,mBAAmB,OAAO;;;;;AAO3E,MAAM,SAAS;;AAGf,SAAgB,WAAW,OAAe,WAA2B;CACnE,MAAM,QAAQ,MAAM,QAAQ,QAAQ,EAAE,CAAC,CAAC,QAAQ,QAAQ,GAAG,CAAC,CAAC,KAAK;CAClE,IAAI,MAAM,UAAU,WAAW,OAAO;CAEtC,OAAO,GAAG,MAAM,KAAK,KAAK,CAAC,CAAC,MAAM,GAAG,YAAY,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,QAAQ,EAAE;AACzE;AAEA,SAAS,SAAS,OAAmC;CACnD,IAAI,UAAU,KAAA,GAAW,OAAA;CACzB,IAAI,OAAO,UAAU,KAAK,KAAK,SAAS,GAAG,OAAO;CAClD,MAAM,QAAQ,2DAA2D,OAAO,KAAK,EAAE,GAAG;AAC5F;AAEA,SAAS,SAAS,QAA8C;CAC9D,OAAO,OAAO,WAAW,YAAY,WAAW,QAAS,OAAkC,aAAa,OAAO,OAAQ,OAA8B,SAAS;AAChK;;;;;AA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