jg-clipboard 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/API.md +290 -0
  2. package/CHANGELOG.md +13 -0
  3. package/LICENSE +21 -0
  4. package/README.md +95 -2
  5. package/dist/copy/copy.d.ts +73 -0
  6. package/dist/copy/copy.js +190 -0
  7. package/dist/copy/copy.js.map +1 -0
  8. package/dist/copy/image.d.ts +9 -0
  9. package/dist/copy/image.js +80 -0
  10. package/dist/copy/image.js.map +1 -0
  11. package/dist/copy/index.d.ts +1 -0
  12. package/dist/copy/index.js +2 -0
  13. package/dist/copy/index.js.map +1 -0
  14. package/dist/index.d.ts +5 -0
  15. package/dist/index.js +9 -0
  16. package/dist/index.js.map +1 -0
  17. package/dist/read/index.d.ts +1 -0
  18. package/dist/read/index.js +2 -0
  19. package/dist/read/index.js.map +1 -0
  20. package/dist/read/read.d.ts +43 -0
  21. package/dist/read/read.js +108 -0
  22. package/dist/read/read.js.map +1 -0
  23. package/dist/shared/errors.d.ts +9 -0
  24. package/dist/shared/errors.js +11 -0
  25. package/dist/shared/errors.js.map +1 -0
  26. package/dist/shared/exceptions.d.ts +25 -0
  27. package/dist/shared/exceptions.js +90 -0
  28. package/dist/shared/exceptions.js.map +1 -0
  29. package/dist/shared/globals.d.ts +40 -0
  30. package/dist/shared/globals.js +23 -0
  31. package/dist/shared/globals.js.map +1 -0
  32. package/dist/shared/index.d.ts +4 -0
  33. package/dist/shared/index.js +6 -0
  34. package/dist/shared/index.js.map +1 -0
  35. package/dist/shared/types.d.ts +17 -0
  36. package/dist/shared/types.js +2 -0
  37. package/dist/shared/types.js.map +1 -0
  38. package/dist/support/index.d.ts +1 -0
  39. package/dist/support/index.js +2 -0
  40. package/dist/support/index.js.map +1 -0
  41. package/dist/support/support.d.ts +16 -0
  42. package/dist/support/support.js +44 -0
  43. package/dist/support/support.js.map +1 -0
  44. package/package.json +63 -3
package/API.md ADDED
@@ -0,0 +1,290 @@
1
+ # <a id="api-reference"></a>jg-clipboard API reference
2
+
3
+ Every export of `jg-clipboard@0.1.0`, 10 in all, with its signature, its errors, and an example. It's generated from the package's TSDoc.
4
+
5
+ - Functions: [`copyHtml`](#api-copyHtml), [`copyImage`](#api-copyImage), [`copyText`](#api-copyText), [`getClipboardSupport`](#api-getClipboardSupport), [`readClipboard`](#api-readClipboard), [`readText`](#api-readText)
6
+ - Constants: [`ERRORS`](#api-ERRORS)
7
+ - Types: [`IClipboardContent`](#api-IClipboardContent), [`IClipboardSupport`](#api-IClipboardSupport), [`ICopyHtmlOptions`](#api-ICopyHtmlOptions)
8
+
9
+ ## <a id="api-functions"></a>Functions
10
+
11
+ ### <a id="api-copyHtml"></a>`copyHtml`
12
+
13
+ *Function*
14
+
15
+ Copies HTML to the clipboard, with plain text for places that can't paste HTML: `options.text`, or else the HTML's text content. Call it from a click or key press handler; like copyText, it calls the clipboard before its first await, and either value can be a promise.
16
+
17
+ ```ts
18
+ copyHtml(
19
+ html: string | Promise<string>,
20
+ options?: ICopyHtmlOptions,
21
+ ): Promise<void>
22
+ ```
23
+
24
+ **Parameters**
25
+
26
+ - `html` `string | Promise<string>`: The HTML, or a promise of it.
27
+ - `options?` `ICopyHtmlOptions`: The plain text that goes with it. Defaults to `{}`.
28
+
29
+ **Returns** `Promise<void>`: A promise that resolves once the HTML is on the clipboard.
30
+
31
+ **Throws**
32
+
33
+ - `CLIPBOARD_UNSUPPORTED`: The clipboard can't copy HTML here.
34
+ - `CLIPBOARD_NOT_FOCUSED`: The page must have focus to use the clipboard.
35
+ - `CLIPBOARD_NO_USER_GESTURE`: The browser only allows this right after a click or a key press.
36
+ - `CLIPBOARD_PERMISSION_DENIED`: The permission to use the clipboard was denied.
37
+ - `CLIPBOARD_WRITE_FAILED`: The content couldn't be copied to the clipboard.
38
+
39
+ **Example**
40
+
41
+ ```ts
42
+ import { copyHtml } from 'jg-clipboard';
43
+
44
+ button.addEventListener('click', () => {
45
+ void copyHtml('<strong>Order #42</strong> shipped', { text: 'Order #42 shipped' });
46
+ });
47
+ ```
48
+
49
+ ### <a id="api-copyImage"></a>`copyImage`
50
+
51
+ *Function*
52
+
53
+ Copies an image to the clipboard as PNG, the only image type browsers accept there. A PNG is written as it is, and other types the browser can decode, such as JPEG or WebP, are redrawn as PNG. Call it from a click or key press handler; it calls the clipboard before its first await, and the image can be a promise, such as a fetched Blob.
54
+
55
+ ```ts
56
+ copyImage(image: Blob | Promise<Blob>): Promise<void>
57
+ ```
58
+
59
+ **Parameters**
60
+
61
+ - `image` `Blob | Promise<Blob>`: The image, or a promise of it.
62
+
63
+ **Returns** `Promise<void>`: A promise that resolves once the image is on the clipboard.
64
+
65
+ **Throws**
66
+
67
+ - `CLIPBOARD_UNSUPPORTED`: The clipboard can't copy images here.
68
+ - `CLIPBOARD_INVALID_IMAGE`: The image couldn't be decoded, so it can't be copied as PNG.
69
+ - `CLIPBOARD_NOT_FOCUSED`: The page must have focus to use the clipboard.
70
+ - `CLIPBOARD_NO_USER_GESTURE`: The browser only allows this right after a click or a key press.
71
+ - `CLIPBOARD_PERMISSION_DENIED`: The permission to use the clipboard was denied.
72
+ - `CLIPBOARD_WRITE_FAILED`: The content couldn't be copied to the clipboard.
73
+
74
+ **Example**
75
+
76
+ ```ts
77
+ import { copyImage } from 'jg-clipboard';
78
+
79
+ button.addEventListener('click', () => {
80
+ void copyImage(fetch('/chart.png').then((response) => response.blob()));
81
+ });
82
+ ```
83
+
84
+ ### <a id="api-copyText"></a>`copyText`
85
+
86
+ *Function*
87
+
88
+ Copies text to the clipboard. Call it from a click or key press handler. It calls the clipboard before its first await, so the browser still sees that gesture. Text that loads after the click, such as from a request, can be a promise: it goes through a ClipboardItem that waits for it, which Safari needs. Browsers without ClipboardItem wait for the promise first, and may then refuse the copy.
89
+
90
+ ```ts
91
+ copyText(text: string | Promise<string>): Promise<void>
92
+ ```
93
+
94
+ **Parameters**
95
+
96
+ - `text` `string | Promise<string>`: The text, or a promise of it.
97
+
98
+ **Returns** `Promise<void>`: A promise that resolves once the text is on the clipboard.
99
+
100
+ **Throws**
101
+
102
+ - `CLIPBOARD_UNSUPPORTED`: The clipboard can't copy text here.
103
+ - `CLIPBOARD_NOT_FOCUSED`: The page must have focus to use the clipboard.
104
+ - `CLIPBOARD_NO_USER_GESTURE`: The browser only allows this right after a click or a key press.
105
+ - `CLIPBOARD_PERMISSION_DENIED`: The permission to use the clipboard was denied.
106
+ - `CLIPBOARD_WRITE_FAILED`: The content couldn't be copied to the clipboard.
107
+
108
+ **Example 1**
109
+
110
+ ```ts
111
+ import { copyText } from 'jg-clipboard';
112
+
113
+ button.addEventListener('click', () => {
114
+ void copyText('npm install jg-clipboard');
115
+ });
116
+ ```
117
+
118
+ **Example 2**
119
+
120
+ ```ts
121
+ import { copyText } from 'jg-clipboard';
122
+
123
+ // the text loads after the click
124
+ button.addEventListener('click', () => {
125
+ void copyText(fetch('/share-link').then((response) => response.text()));
126
+ });
127
+ ```
128
+
129
+ ### <a id="api-getClipboardSupport"></a>`getClipboardSupport`
130
+
131
+ *Function*
132
+
133
+ Tells what the browser lets the page do with the clipboard, from feature detection and `ClipboardItem.supports` where the browser has it. It never throws, and it's safe to call during server rendering, where everything is false. A supported feature can still be refused, such as without a click or a permission.
134
+
135
+ ```ts
136
+ getClipboardSupport(): IClipboardSupport
137
+ ```
138
+
139
+ **Returns** `IClipboardSupport`: Whether the page is a secure context, and whether each function can run.
140
+
141
+ **Example**
142
+
143
+ ```ts
144
+ import { getClipboardSupport } from 'jg-clipboard';
145
+
146
+ const support = getClipboardSupport();
147
+ if (support.copyImage) {
148
+ showCopyImageButton();
149
+ }
150
+ ```
151
+
152
+ ### <a id="api-readClipboard"></a>`readClipboard`
153
+
154
+ *Function*
155
+
156
+ Reads the clipboard's text, HTML, and image with one `read()` call, so the person pasting sees one prompt at most. Call it from a click or key press handler, which Safari requires.
157
+
158
+ ```ts
159
+ readClipboard(): Promise<IClipboardContent>
160
+ ```
161
+
162
+ **Returns** `Promise<IClipboardContent>`: A promise that resolves to each kind of content, with null for the kinds the clipboard doesn't hold. The image is PNG.
163
+
164
+ **Throws**
165
+
166
+ - `CLIPBOARD_UNSUPPORTED`: The clipboard can't read here.
167
+ - `CLIPBOARD_NOT_FOCUSED`: The page must have focus to use the clipboard.
168
+ - `CLIPBOARD_NO_USER_GESTURE`: The browser only allows this right after a click or a key press.
169
+ - `CLIPBOARD_PERMISSION_DENIED`: The permission to use the clipboard was denied.
170
+ - `CLIPBOARD_INVALID_IMAGE`: The image couldn't be decoded, so it can't be copied as PNG.
171
+ - `CLIPBOARD_READ_FAILED`: The clipboard couldn't be read.
172
+
173
+ **Example**
174
+
175
+ ```ts
176
+ import { readClipboard } from 'jg-clipboard';
177
+
178
+ pasteButton.addEventListener('click', async () => {
179
+ const { html, text, image } = await readClipboard();
180
+ if (image) {
181
+ preview.src = URL.createObjectURL(image);
182
+ }
183
+ });
184
+ ```
185
+
186
+ ### <a id="api-readText"></a>`readText`
187
+
188
+ *Function*
189
+
190
+ Reads the text on the clipboard. Browsers ask before a page reads it: Safari and Firefox show a paste prompt, and Chromium asks for the clipboard-read permission once. Call it from a click or key press handler, which Safari requires.
191
+
192
+ ```ts
193
+ readText(): Promise<string>
194
+ ```
195
+
196
+ **Returns** `Promise<string>`: A promise that resolves to the text, or `''` when the clipboard holds none.
197
+
198
+ **Throws**
199
+
200
+ - `CLIPBOARD_UNSUPPORTED`: The clipboard can't read text here.
201
+ - `CLIPBOARD_NOT_FOCUSED`: The page must have focus to use the clipboard.
202
+ - `CLIPBOARD_NO_USER_GESTURE`: The browser only allows this right after a click or a key press.
203
+ - `CLIPBOARD_PERMISSION_DENIED`: The permission to use the clipboard was denied.
204
+ - `CLIPBOARD_READ_FAILED`: The clipboard couldn't be read.
205
+
206
+ **Example**
207
+
208
+ ```ts
209
+ import { readText } from 'jg-clipboard';
210
+
211
+ pasteButton.addEventListener('click', async () => {
212
+ input.value = await readText();
213
+ });
214
+ ```
215
+
216
+ ## <a id="api-constants"></a>Constants
217
+
218
+ ### <a id="api-ERRORS"></a>`ERRORS`
219
+
220
+ *Constant*
221
+
222
+ the codes for every error the package throws
223
+
224
+ ```ts
225
+ const ERRORS: { CLIPBOARD_UNSUPPORTED: "CLIPBOARD_UNSUPPORTED"; CLIPBOARD_PERMISSION_DENIED: "CLIPBOARD_PERMISSION_DENIED"; CLIPBOARD_NO_USER_GESTURE: "CLIPBOARD_NO_USER_GESTURE"; CLIPBOARD_NOT_FOCUSED: "CLIPBOARD_NOT_FOCUSED"; CLIPBOARD_INVALID_IMAGE: "CLIPBOARD_INVALID_IMAGE"; CLIPBOARD_WRITE_FAILED: "CLIPBOARD_WRITE_FAILED"; CLIPBOARD_READ_FAILED: "CLIPBOARD_READ_FAILED" }
226
+ ```
227
+
228
+ ## <a id="api-types"></a>Types
229
+
230
+ ### <a id="api-IClipboardContent"></a>`IClipboardContent`
231
+
232
+ *Type*
233
+
234
+ what readClipboard found, with null for each kind of content the clipboard doesn't hold
235
+
236
+ ```ts
237
+ type IClipboardContent = {
238
+ text: string | null;
239
+ html: string | null;
240
+ image: Blob | null;
241
+ };
242
+ ```
243
+
244
+ **Members**
245
+
246
+ - `text: string | null` (property)
247
+ - `html: string | null` (property)
248
+ - `image: Blob | null` (property): the image, as PNG
249
+
250
+ ### <a id="api-IClipboardSupport"></a>`IClipboardSupport`
251
+
252
+ *Type*
253
+
254
+ what the browser lets the page do with the clipboard, each from feature detection
255
+
256
+ ```ts
257
+ type IClipboardSupport = {
258
+ isSecureContext: boolean;
259
+ copyText: boolean;
260
+ copyHtml: boolean;
261
+ copyImage: boolean;
262
+ readText: boolean;
263
+ read: boolean;
264
+ };
265
+ ```
266
+
267
+ **Members**
268
+
269
+ - `isSecureContext: boolean` (property): whether the page is in a secure context, such as HTTPS or localhost, which the clipboard needs
270
+ - `copyText: boolean` (property): whether copyText can run
271
+ - `copyHtml: boolean` (property): whether copyHtml can run
272
+ - `copyImage: boolean` (property): whether copyImage can run
273
+ - `readText: boolean` (property): whether readText can run
274
+ - `read: boolean` (property): whether readClipboard can run
275
+
276
+ ### <a id="api-ICopyHtmlOptions"></a>`ICopyHtmlOptions`
277
+
278
+ *Type*
279
+
280
+ what copyHtml accepts besides the HTML
281
+
282
+ ```ts
283
+ type ICopyHtmlOptions = {
284
+ text?: string | Promise<string>;
285
+ };
286
+ ```
287
+
288
+ **Members**
289
+
290
+ - `text: string | Promise<string>` (property): the plain text pasted where HTML can't go. Defaults to the HTML's text content
package/CHANGELOG.md ADDED
@@ -0,0 +1,13 @@
1
+ # Changelog
2
+
3
+ ## 0.1.0
4
+
5
+ The first release.
6
+
7
+ ### Added
8
+
9
+ - `copyText`, `copyHtml`, and `copyImage`, which call the clipboard before their first await and accept promised content, for Safari. Images that aren't PNG are redrawn as PNG.
10
+ - `readText` and `readClipboard`, which reads text, HTML, and a PNG image with one call.
11
+ - `getClipboardSupport`, which never throws and is safe during server rendering.
12
+ - `ERRORS`: `CLIPBOARD_UNSUPPORTED`, `CLIPBOARD_PERMISSION_DENIED`, `CLIPBOARD_NO_USER_GESTURE`, `CLIPBOARD_NOT_FOCUSED`, `CLIPBOARD_INVALID_IMAGE`, `CLIPBOARD_WRITE_FAILED`, and `CLIPBOARD_READ_FAILED`, each with the browser's error as its cause.
13
+ - `API.md`, the full API reference, generated from the TSDoc of the version it ships with, so it can be read from `node_modules` without a browser.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Jesus Graterol
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,96 @@
1
- # Temporary Holding Version
1
+ # jg-clipboard
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Copy and read text, HTML, and images on the browser clipboard, with support detection and coded errors that say why the browser refused.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install jg-clipboard
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ Copy from a click or key press handler. Each copy calls the clipboard before its first `await`, so the browser still sees the gesture:
14
+
15
+ ```ts
16
+ import { copyText, ERRORS } from 'jg-clipboard';
17
+ import { hasErrorCode } from 'jg-exception';
18
+
19
+ copyButton.addEventListener('click', async () => {
20
+ try {
21
+ await copyText('npm install jg-clipboard');
22
+ showToast('Copied');
23
+ } catch (error) {
24
+ if (hasErrorCode(error, ERRORS.CLIPBOARD_PERMISSION_DENIED)) {
25
+ showToast('Allow clipboard access to copy');
26
+ }
27
+ }
28
+ });
29
+ ```
30
+
31
+ Content that loads after the click can be a promise. It goes through a `ClipboardItem` that waits for it, which Safari needs:
32
+
33
+ ```ts
34
+ shareButton.addEventListener('click', () => {
35
+ void copyText(fetch('/share-link').then((response) => response.text()));
36
+ });
37
+ ```
38
+
39
+ Copy HTML with its plain text, and images. A PNG is copied as it is, and other types the browser can decode, such as JPEG or WebP, are redrawn as PNG, the only image type browsers accept on the clipboard:
40
+
41
+ ```ts
42
+ import { copyHtml, copyImage } from 'jg-clipboard';
43
+
44
+ await copyHtml('<strong>Order #42</strong> shipped', { text: 'Order #42 shipped' });
45
+ await copyImage(fetch('/chart.jpg').then((response) => response.blob()));
46
+ ```
47
+
48
+ Read from a paste button. `readClipboard` reads the text, HTML, and image with one call, so the person pasting sees one prompt at most:
49
+
50
+ ```ts
51
+ import { readClipboard, readText } from 'jg-clipboard';
52
+
53
+ pasteButton.addEventListener('click', async () => {
54
+ const { text, html, image } = await readClipboard(); // each null when the clipboard lacks it
55
+ input.value = text ?? (await readText());
56
+ });
57
+ ```
58
+
59
+ Show only what the browser supports. `getClipboardSupport` never throws, and reports everything as `false` during server rendering:
60
+
61
+ ```ts
62
+ import { getClipboardSupport } from 'jg-clipboard';
63
+
64
+ const support = getClipboardSupport(); // { isSecureContext, copyText, copyHtml, copyImage, readText, read }
65
+ copyImageButton.hidden = !support.copyImage;
66
+ ```
67
+
68
+ ### Errors
69
+
70
+ Every failure is an `Exception` with one of these codes, and the browser's error as its `cause`:
71
+
72
+ | Code | When |
73
+ | ----------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------- |
74
+ | `CLIPBOARD_UNSUPPORTED` | The page isn't a secure context, such as HTTPS or localhost, or the browser lacks the API |
75
+ | `CLIPBOARD_NOT_FOCUSED` | The browser refused because the page doesn't have focus |
76
+ | `CLIPBOARD_NO_USER_GESTURE` | The browser refused because the call didn't follow a click or a key press |
77
+ | `CLIPBOARD_PERMISSION_DENIED` | The browser refused for any other reason, such as a denied or dismissed permission; `data.permission` holds the Permissions API's state, or `null` |
78
+ | `CLIPBOARD_INVALID_IMAGE` | The image can't be decoded, so it can't be copied as PNG |
79
+ | `CLIPBOARD_WRITE_FAILED` | A copy failed otherwise, such as content whose promise rejected |
80
+ | `CLIPBOARD_READ_FAILED` | A read failed otherwise |
81
+
82
+ ### Browser limits
83
+
84
+ - The clipboard needs a secure context: HTTPS, or `localhost` while developing.
85
+ - Copy and read from a click or key press handler. Safari refuses calls that don't follow one directly, and Chromium needs the page to have focus.
86
+ - Reading asks first. Safari and Firefox show a paste prompt each time, and Chromium asks once for the clipboard-read permission.
87
+ - Images go on the clipboard as PNG only. Converting another type needs `createImageBitmap`, so it works in every current browser, but not in very old ones.
88
+ - Without `ClipboardItem`, a promised text loads before the copy starts, and Safari may then refuse it.
89
+
90
+ ## Documentation
91
+
92
+ The full API reference ships in the package as `API.md`, generated from its TSDoc for the installed version, and is at https://jg-packages.jesusgraterol.dev/packages/jg-clipboard/.
93
+
94
+ ## License
95
+
96
+ [MIT](https://github.com/jesusgraterol/jg-packages/blob/main/packages/jg-clipboard/LICENSE)
@@ -0,0 +1,73 @@
1
+ import { type ICopyHtmlOptions } from '../shared/index.js';
2
+ /**
3
+ * Copies text to the clipboard. Call it from a click or key press handler. It calls the clipboard
4
+ * before its first await, so the browser still sees that gesture. Text that loads after the click,
5
+ * such as from a request, can be a promise: it goes through a ClipboardItem that waits for it, which
6
+ * Safari needs. Browsers without ClipboardItem wait for the promise first, and may then refuse the
7
+ * copy.
8
+ * @param text The text, or a promise of it.
9
+ * @returns A promise that resolves once the text is on the clipboard.
10
+ * @example
11
+ * import { copyText } from 'jg-clipboard';
12
+ *
13
+ * button.addEventListener('click', () => {
14
+ * void copyText('npm install jg-clipboard');
15
+ * });
16
+ * @example
17
+ * import { copyText } from 'jg-clipboard';
18
+ *
19
+ * // the text loads after the click
20
+ * button.addEventListener('click', () => {
21
+ * void copyText(fetch('/share-link').then((response) => response.text()));
22
+ * });
23
+ * @throws
24
+ * - CLIPBOARD_UNSUPPORTED: The clipboard can't copy text here.
25
+ * - CLIPBOARD_NOT_FOCUSED: The page must have focus to use the clipboard.
26
+ * - CLIPBOARD_NO_USER_GESTURE: The browser only allows this right after a click or a key press.
27
+ * - CLIPBOARD_PERMISSION_DENIED: The permission to use the clipboard was denied.
28
+ * - CLIPBOARD_WRITE_FAILED: The content couldn't be copied to the clipboard.
29
+ */
30
+ export declare const copyText: (text: string | Promise<string>) => Promise<void>;
31
+ /**
32
+ * Copies HTML to the clipboard, with plain text for places that can't paste HTML: `options.text`,
33
+ * or else the HTML's text content. Call it from a click or key press handler; like copyText, it
34
+ * calls the clipboard before its first await, and either value can be a promise.
35
+ * @param html The HTML, or a promise of it.
36
+ * @param options The plain text that goes with it.
37
+ * @returns A promise that resolves once the HTML is on the clipboard.
38
+ * @example
39
+ * import { copyHtml } from 'jg-clipboard';
40
+ *
41
+ * button.addEventListener('click', () => {
42
+ * void copyHtml('<strong>Order #42</strong> shipped', { text: 'Order #42 shipped' });
43
+ * });
44
+ * @throws
45
+ * - CLIPBOARD_UNSUPPORTED: The clipboard can't copy HTML here.
46
+ * - CLIPBOARD_NOT_FOCUSED: The page must have focus to use the clipboard.
47
+ * - CLIPBOARD_NO_USER_GESTURE: The browser only allows this right after a click or a key press.
48
+ * - CLIPBOARD_PERMISSION_DENIED: The permission to use the clipboard was denied.
49
+ * - CLIPBOARD_WRITE_FAILED: The content couldn't be copied to the clipboard.
50
+ */
51
+ export declare const copyHtml: (html: string | Promise<string>, options?: ICopyHtmlOptions) => Promise<void>;
52
+ /**
53
+ * Copies an image to the clipboard as PNG, the only image type browsers accept there. A PNG is
54
+ * written as it is, and other types the browser can decode, such as JPEG or WebP, are redrawn as
55
+ * PNG. Call it from a click or key press handler; it calls the clipboard before its first await, and
56
+ * the image can be a promise, such as a fetched Blob.
57
+ * @param image The image, or a promise of it.
58
+ * @returns A promise that resolves once the image is on the clipboard.
59
+ * @example
60
+ * import { copyImage } from 'jg-clipboard';
61
+ *
62
+ * button.addEventListener('click', () => {
63
+ * void copyImage(fetch('/chart.png').then((response) => response.blob()));
64
+ * });
65
+ * @throws
66
+ * - CLIPBOARD_UNSUPPORTED: The clipboard can't copy images here.
67
+ * - CLIPBOARD_INVALID_IMAGE: The image couldn't be decoded, so it can't be copied as PNG.
68
+ * - CLIPBOARD_NOT_FOCUSED: The page must have focus to use the clipboard.
69
+ * - CLIPBOARD_NO_USER_GESTURE: The browser only allows this right after a click or a key press.
70
+ * - CLIPBOARD_PERMISSION_DENIED: The permission to use the clipboard was denied.
71
+ * - CLIPBOARD_WRITE_FAILED: The content couldn't be copied to the clipboard.
72
+ */
73
+ export declare const copyImage: (image: Blob | Promise<Blob>) => Promise<void>;