react-smart-copy 1.26.1 → 1.27.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 (38) hide show
  1. package/README.md +6 -3
  2. package/dist/chunks/clipboard-adapter-0haPt4jJ.js +217 -0
  3. package/dist/chunks/clipboard-adapter-0haPt4jJ.js.map +1 -0
  4. package/dist/chunks/clipboard-adapter-5bmjKbyK.cjs +222 -0
  5. package/dist/chunks/clipboard-adapter-5bmjKbyK.cjs.map +1 -0
  6. package/dist/chunks/{clipboard-adapter-CfaIbZpv.d.cts → clipboard-adapter-CUvmAcRE.d.cts} +10 -1
  7. package/dist/chunks/{clipboard-adapter-Chm6zq60.d.ts → clipboard-adapter-CdOzN135.d.ts} +10 -1
  8. package/dist/chunks/{core-DF6jiigD.cjs → core-BRMlZOtj.cjs} +2 -2
  9. package/dist/chunks/{core-DF6jiigD.cjs.map → core-BRMlZOtj.cjs.map} +1 -1
  10. package/dist/chunks/{core-88XdCKaH.js → core-CnAFS4Wh.js} +2 -2
  11. package/dist/chunks/{core-88XdCKaH.js.map → core-CnAFS4Wh.js.map} +1 -1
  12. package/dist/chunks/{index-CZ6HpdKm.d.cts → index-Ct2V52et.d.cts} +2 -2
  13. package/dist/chunks/{index-BidyqUMa.d.ts → index-U91G1nS9.d.ts} +2 -2
  14. package/dist/chunks/{share-Bk6MPmJg.cjs → share-Bu5u2ItX.cjs} +2 -2
  15. package/dist/chunks/{share-Bk6MPmJg.cjs.map → share-Bu5u2ItX.cjs.map} +1 -1
  16. package/dist/chunks/{share-tdlNQeje.js → share-CL72PUqq.js} +2 -2
  17. package/dist/chunks/{share-tdlNQeje.js.map → share-CL72PUqq.js.map} +1 -1
  18. package/dist/chunks/{share-DVR_DhHc.d.ts → share-DMqvWz32.d.ts} +2 -2
  19. package/dist/chunks/{share-hIwth7Dh.d.cts → share-DQFF73gt.d.cts} +2 -2
  20. package/dist/core.cjs +2 -2
  21. package/dist/core.d.cts +2 -2
  22. package/dist/core.d.ts +2 -2
  23. package/dist/core.js +2 -2
  24. package/dist/index.cjs +3 -3
  25. package/dist/index.d.cts +3 -3
  26. package/dist/index.d.ts +3 -3
  27. package/dist/index.js +3 -3
  28. package/dist/share.cjs +1 -1
  29. package/dist/share.d.cts +1 -1
  30. package/dist/share.d.ts +1 -1
  31. package/dist/share.js +1 -1
  32. package/dist/testing.d.cts +1 -1
  33. package/dist/testing.d.ts +1 -1
  34. package/package.json +8 -8
  35. package/dist/chunks/clipboard-adapter-Bpuf5GmB.cjs +0 -102
  36. package/dist/chunks/clipboard-adapter-Bpuf5GmB.cjs.map +0 -1
  37. package/dist/chunks/clipboard-adapter-DyCmyZV9.js +0 -97
  38. package/dist/chunks/clipboard-adapter-DyCmyZV9.js.map +0 -1
package/README.md CHANGED
@@ -23,7 +23,7 @@ Phone +91 98xxx xxxxx [Copy]
23
23
  ID PLT-29018 [Copy]
24
24
  ```
25
25
 
26
- - **Small.** About 3.4 kB for `useCopy` (min + brotli), zero runtime dependencies, and every
26
+ - **Small.** About 4.2 kB for `useCopy` (min + brotli), zero runtime dependencies, and every
27
27
  module is a separate entry point that shares one copy of the core.
28
28
  - **Honest.** Every failure is a typed, classified error. Nothing silently does nothing.
29
29
  - **Accessible.** Real buttons, accessible names, polite announcements, reduced motion, and
@@ -46,6 +46,9 @@ without it, in browsers and in Node.js 18 or later.
46
46
 
47
47
  ## Quick start
48
48
 
49
+ Coming from `react-copy-to-clipboard`, `copy-to-clipboard` or `navigator.clipboard`? See
50
+ [Migrating](https://suprabhat02.github.io/react-smart-copy/start/migrating/).
51
+
49
52
  A copy button, with everything around it:
50
53
 
51
54
  ```tsx
@@ -135,8 +138,8 @@ Sizes are minified and brotli-compressed, for everything the entry point exports
135
138
 
136
139
  | Entry point | What it is for | Size |
137
140
  | --- | --- | --- |
138
- | [`react-smart-copy`](https://suprabhat02.github.io/react-smart-copy/start/introduction/) | React hooks and components: `useCopy`, `usePaste`, `CopyField`, `PasteField`, `CopyGroup`, `useCopyInterceptor`, `useDragCopy`, `useShare`, `useOtpField`, `useClipboardPermission` | from 3.4 kB |
139
- | [`/core`](https://suprabhat02.github.io/react-smart-copy/guides/without-react/) | The framework-agnostic machines and adapters | 8.7 kB |
141
+ | [`react-smart-copy`](https://suprabhat02.github.io/react-smart-copy/start/introduction/) | React hooks and components: `useCopy`, `usePaste`, `CopyField`, `PasteField`, `CopyGroup`, `useCopyInterceptor`, `useDragCopy`, `useShare`, `useOtpField`, `useClipboardPermission` | from 4.2 kB |
142
+ | [`/core`](https://suprabhat02.github.io/react-smart-copy/guides/without-react/) | The framework-agnostic machines and adapters | 9.3 kB |
140
143
  | [`/capture`](https://suprabhat02.github.io/react-smart-copy/copy/capture/) | Copy an `<svg>` or a piece of your UI as a PNG | 3.4 kB |
141
144
  | [`/table`](https://suprabhat02.github.io/react-smart-copy/modules/tables/) | Ranges that paste into Excel and Google Sheets as cells, and back as typed records | 5.6 kB |
142
145
  | [`/structured`](https://suprabhat02.github.io/react-smart-copy/modules/structured/) | Your own typed, versioned, validated objects on the clipboard | 3.5 kB |
@@ -0,0 +1,217 @@
1
+
2
+ import { r as createCopyError, t as CopyFailure } from "./errors-CGcMvbhJ.js";
3
+ import { i as serializeJson, n as isBlob, t as IMAGE_MIME_TYPE } from "./payload-5uJedhwz.js";
4
+ import { i as isWebCustomFormat } from "./mime-aa-HA2dm.js";
5
+ //#region src/core/legacy-copy.ts
6
+ /**
7
+ * The copy that works where the async Clipboard API does not: plain HTTP pages (intranets,
8
+ * internal tools on an IP address) and webviews without `navigator.clipboard`.
9
+ *
10
+ * `document.execCommand('copy')` fires a `copy` event whose `clipboardData` takes any text
11
+ * format, so the payload is written exactly, as text and HTML alike. Nothing is shown and
12
+ * nothing moves: the selection the command needs is made on a node outside the layout, and
13
+ * the user's own selection and focus are put back before the function returns. It runs
14
+ * synchronously, inside the user's gesture. Internal: not part of the public API.
15
+ */
16
+ /** What can travel through a copy event: every text format, no images, no blobs, no web custom formats. */
17
+ function legacyEntries(payload) {
18
+ switch (payload.kind) {
19
+ case "text": return [["text/plain", payload.value]];
20
+ case "json": return [["text/plain", serializeJson(payload)]];
21
+ case "html": return [["text/html", payload.html], ["text/plain", payload.text]];
22
+ case "image": return null;
23
+ case "multi": {
24
+ const entries = [];
25
+ for (const { mimeType, data, optional } of payload.items) if (typeof data === "string" && !isWebCustomFormat(mimeType)) entries.push([mimeType, data]);
26
+ else if (optional !== true) return null;
27
+ return entries.length > 0 ? entries : null;
28
+ }
29
+ }
30
+ }
31
+ function saveFocus(doc) {
32
+ const element = doc.activeElement;
33
+ if (!element || element === doc.body) return null;
34
+ try {
35
+ const { selectionStart: start, selectionEnd: end, selectionDirection: direction } = element;
36
+ return [element, typeof start === "number" && typeof end === "number" ? [
37
+ start,
38
+ end,
39
+ direction ?? "none"
40
+ ] : null];
41
+ } catch {
42
+ return [element, null];
43
+ }
44
+ }
45
+ function restoreFocus(doc, saved) {
46
+ if (!saved?.[0].isConnected) return;
47
+ const [element, range] = saved;
48
+ if (doc.activeElement !== element) element.focus({ preventScroll: true });
49
+ if (range) element.setSelectionRange(...range);
50
+ }
51
+ /**
52
+ * Writes `entries` through `execCommand('copy')`. Returns whether the browser took them;
53
+ * `false` leaves the clipboard as it was (the caller reports its own, classified error).
54
+ */
55
+ function legacyCopy(doc, entries) {
56
+ if (typeof doc.execCommand !== "function" || !doc.body) return false;
57
+ const plain = entries.find(([format]) => format === "text/plain")?.[1];
58
+ const seen = { written: false };
59
+ const onCopy = (event) => {
60
+ const data = event.clipboardData;
61
+ if (!data) return;
62
+ event.preventDefault();
63
+ event.stopImmediatePropagation();
64
+ try {
65
+ for (const [format, value] of entries) data.setData(format, value);
66
+ seen.written = true;
67
+ } catch {}
68
+ };
69
+ const focus = saveFocus(doc);
70
+ const selection = doc.getSelection();
71
+ const ranges = [];
72
+ if (selection) for (let index = 0; index < selection.rangeCount; index += 1) ranges.push(selection.getRangeAt(index));
73
+ const holder = doc.createElement("span");
74
+ holder.textContent = plain === void 0 || plain === "" ? "\xA0" : plain;
75
+ holder.setAttribute("aria-hidden", "true");
76
+ holder.style.cssText = "position:fixed;top:0;left:0;clip-path:inset(50%);white-space:pre;user-select:text;-webkit-user-select:text";
77
+ doc.addEventListener("copy", onCopy, true);
78
+ doc.body.append(holder);
79
+ try {
80
+ if (selection) {
81
+ const range = doc.createRange();
82
+ range.selectNodeContents(holder);
83
+ selection.removeAllRanges();
84
+ selection.addRange(range);
85
+ }
86
+ doc.execCommand("copy");
87
+ } catch {} finally {
88
+ doc.removeEventListener("copy", onCopy, true);
89
+ holder.remove();
90
+ if (selection) {
91
+ selection.removeAllRanges();
92
+ for (const range of ranges) selection.addRange(range);
93
+ }
94
+ restoreFocus(doc, focus);
95
+ }
96
+ return seen.written;
97
+ }
98
+ //#endregion
99
+ //#region src/core/clipboard-adapter.ts
100
+ const fail = (type, message, cause) => new CopyFailure(createCopyError(type, message, cause));
101
+ const noop = () => void 0;
102
+ function defaultEnvironment() {
103
+ return typeof window === "undefined" ? void 0 : window;
104
+ }
105
+ function getRichClipboard(env, clipboard) {
106
+ const Item = env.ClipboardItem;
107
+ if (!Item || typeof clipboard.write !== "function") return null;
108
+ return {
109
+ Item,
110
+ write: clipboard.write.bind(clipboard)
111
+ };
112
+ }
113
+ function isTypeSupported(Item, type) {
114
+ return typeof Item.supports !== "function" || Item.supports(type);
115
+ }
116
+ async function resolveImageBlob(source, context) {
117
+ let blob;
118
+ try {
119
+ blob = await (typeof source === "function" ? source(context ?? { signal: new AbortController().signal }) : source);
120
+ } catch (cause) {
121
+ if (context?.signal.aborted) throw fail("aborted", "The image copy was cancelled.", cause);
122
+ throw fail("blob-generation-failed", "The image source threw or rejected while producing a Blob.", cause);
123
+ }
124
+ if (!isBlob(blob)) throw fail("blob-generation-failed", "The image source did not produce a Blob.");
125
+ if (blob.type !== "image/png") throw fail("unsupported-format", `Only ${IMAGE_MIME_TYPE} can be written to the clipboard (received "${blob.type || "unknown"}"). Convert with canvas.toBlob(cb, "${IMAGE_MIME_TYPE}").`);
126
+ return blob;
127
+ }
128
+ async function writeImage(rich, source, context) {
129
+ if (!isTypeSupported(rich.Item, "image/png")) throw fail("unsupported-format", `This browser cannot write ${IMAGE_MIME_TYPE} to the clipboard.`);
130
+ const blob = resolveImageBlob(source, context);
131
+ blob.catch(noop);
132
+ try {
133
+ await rich.write([new rich.Item({ [IMAGE_MIME_TYPE]: blob })]);
134
+ } catch (error) {
135
+ throw await blob.then(noop, (inner) => inner) ?? error;
136
+ }
137
+ await blob;
138
+ }
139
+ async function writeToClipboard(payload, env, settings, context) {
140
+ if (!env) throw fail("unsupported", "No browser environment: the clipboard only exists in the browser.");
141
+ /** Without the async API: the copy command if it can carry this payload, else `failure`. */
142
+ const legacy = (failure) => {
143
+ const entries = settings.legacyFallback && env.document ? legacyEntries(payload) : null;
144
+ if (entries && legacyCopy(env.document, entries)) return;
145
+ throw failure;
146
+ };
147
+ if (env.isSecureContext === false) {
148
+ legacy(fail("insecure-context", "The Clipboard API requires a secure context (HTTPS or localhost)."));
149
+ return;
150
+ }
151
+ const clipboard = env.navigator?.clipboard;
152
+ if (!clipboard) {
153
+ legacy(fail("unsupported", "navigator.clipboard is not available in this browser."));
154
+ return;
155
+ }
156
+ switch (payload.kind) {
157
+ case "text":
158
+ case "json": {
159
+ const text = payload.kind === "text" ? payload.value : serializeJson(payload);
160
+ if (typeof clipboard.writeText === "function") return clipboard.writeText(text);
161
+ legacy(fail("unsupported", "navigator.clipboard.writeText() is not available."));
162
+ return;
163
+ }
164
+ case "html": {
165
+ const rich = getRichClipboard(env, clipboard);
166
+ if (!rich || !isTypeSupported(rich.Item, "text/html")) {
167
+ const failure = fail("unsupported-format", "Rich HTML copy requires ClipboardItem and navigator.clipboard.write().");
168
+ try {
169
+ legacy(failure);
170
+ return;
171
+ } catch {
172
+ if (settings.degradeHtmlToText && typeof clipboard.writeText === "function") return clipboard.writeText(payload.text);
173
+ throw failure;
174
+ }
175
+ }
176
+ return rich.write([new rich.Item({
177
+ "text/html": new Blob([payload.html], { type: "text/html" }),
178
+ "text/plain": new Blob([payload.text], { type: "text/plain" })
179
+ })]);
180
+ }
181
+ case "image": {
182
+ const rich = getRichClipboard(env, clipboard);
183
+ if (!rich) throw fail("unsupported-format", "Image copy requires ClipboardItem and navigator.clipboard.write().");
184
+ return writeImage(rich, payload.blob, context);
185
+ }
186
+ case "multi": {
187
+ const rich = getRichClipboard(env, clipboard);
188
+ if (!rich) {
189
+ legacy(fail("unsupported-format", "Multi-format copy requires ClipboardItem and navigator.clipboard.write()."));
190
+ return;
191
+ }
192
+ const record = Object.create(null);
193
+ let written = 0;
194
+ for (const { mimeType, data, optional } of payload.items) {
195
+ if (optional === true && !(typeof rich.Item.supports === "function" && rich.Item.supports(mimeType))) continue;
196
+ if (!isTypeSupported(rich.Item, mimeType)) throw fail("unsupported-format", `This browser cannot write "${mimeType}" to the clipboard.`);
197
+ record[mimeType] = typeof data === "string" ? new Blob([data], { type: mimeType }) : data;
198
+ written += 1;
199
+ }
200
+ if (written === 0) throw fail("unsupported-format", "This browser can write none of the payload types.");
201
+ return rich.write([new rich.Item(record)]);
202
+ }
203
+ }
204
+ }
205
+ /** The default adapter: async Clipboard API with feature detection and honest errors. */
206
+ function createBrowserClipboardAdapter(options = {}) {
207
+ const getEnvironment = options.getEnvironment ?? defaultEnvironment;
208
+ const settings = {
209
+ degradeHtmlToText: options.degradeHtmlToText ?? true,
210
+ legacyFallback: options.legacyFallback ?? true
211
+ };
212
+ return { write: (payload, context) => writeToClipboard(payload, getEnvironment(), settings, context) };
213
+ }
214
+ //#endregion
215
+ export { createBrowserClipboardAdapter as t };
216
+
217
+ //# sourceMappingURL=clipboard-adapter-0haPt4jJ.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"clipboard-adapter-0haPt4jJ.js","names":[],"sources":["../../src/core/legacy-copy.ts","../../src/core/clipboard-adapter.ts"],"sourcesContent":["/**\n * The copy that works where the async Clipboard API does not: plain HTTP pages (intranets,\n * internal tools on an IP address) and webviews without `navigator.clipboard`.\n *\n * `document.execCommand('copy')` fires a `copy` event whose `clipboardData` takes any text\n * format, so the payload is written exactly, as text and HTML alike. Nothing is shown and\n * nothing moves: the selection the command needs is made on a node outside the layout, and\n * the user's own selection and focus are put back before the function returns. It runs\n * synchronously, inside the user's gesture. Internal: not part of the public API.\n */\nimport { isWebCustomFormat } from './mime';\nimport { serializeJson, type CopyPayload } from './payload';\n\n/** Each format and its text, in the order written. */\nexport type LegacyEntries = readonly (readonly [format: string, data: string])[];\n\n/** What can travel through a copy event: every text format, no images, no blobs, no web custom formats. */\nexport function legacyEntries(payload: CopyPayload): LegacyEntries | null {\n switch (payload.kind) {\n case 'text':\n return [['text/plain', payload.value]];\n case 'json':\n return [['text/plain', serializeJson(payload)]];\n case 'html':\n return [\n ['text/html', payload.html],\n ['text/plain', payload.text],\n ];\n case 'image':\n return null;\n case 'multi': {\n const entries: (readonly [string, string])[] = [];\n for (const { mimeType, data, optional } of payload.items) {\n if (typeof data === 'string' && !isWebCustomFormat(mimeType)) entries.push([mimeType, data]);\n // A required format that a copy event cannot carry: the copy would be incomplete.\n else if (optional !== true) return null;\n }\n return entries.length > 0 ? entries : null;\n }\n }\n}\n\ntype SavedFocus = readonly [element: HTMLElement, range: readonly [number, number, 'forward' | 'backward' | 'none'] | null];\n\nfunction saveFocus(doc: Document): SavedFocus | null {\n const element = doc.activeElement as (HTMLElement & Partial<HTMLInputElement>) | null;\n if (!element || element === doc.body) return null;\n try {\n const { selectionStart: start, selectionEnd: end, selectionDirection: direction } = element;\n return [element, typeof start === 'number' && typeof end === 'number' ? [start, end, direction ?? 'none'] : null];\n } catch {\n // Older engines throw for inputs without a selection API (email, number).\n return [element, null];\n }\n}\n\nfunction restoreFocus(doc: Document, saved: SavedFocus | null): void {\n if (!saved?.[0].isConnected) return;\n const [element, range] = saved;\n if (doc.activeElement !== element) element.focus({ preventScroll: true });\n if (range) (element as HTMLInputElement).setSelectionRange(...range);\n}\n\n/**\n * Writes `entries` through `execCommand('copy')`. Returns whether the browser took them;\n * `false` leaves the clipboard as it was (the caller reports its own, classified error).\n */\nexport function legacyCopy(doc: Document, entries: LegacyEntries): boolean {\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition, @typescript-eslint/no-deprecated -- missing in some webviews; the only copy without the async API\n if (typeof doc.execCommand !== 'function' || !doc.body) return false;\n const plain = entries.find(([format]) => format === 'text/plain')?.[1];\n // Set by the listener: an object, so the check after `execCommand` reads its latest value.\n const seen = { written: false };\n const onCopy = (event: Event): void => {\n const data = (event as ClipboardEvent).clipboardData;\n if (!data) return;\n event.preventDefault();\n // This copy carries an exact payload: page copy handlers and interceptors must not rewrite it.\n event.stopImmediatePropagation();\n try {\n for (const [format, value] of entries) data.setData(format, value);\n seen.written = true;\n } catch {\n // A format the browser refuses: the copy is reported as failed, not thrown into the page.\n }\n };\n\n // Saved first: in some engines reading or moving the selection already moves focus.\n const focus = saveFocus(doc);\n const selection = doc.getSelection();\n const ranges: Range[] = [];\n if (selection) for (let index = 0; index < selection.rangeCount; index += 1) ranges.push(selection.getRangeAt(index));\n\n // The copy command is only enabled over a selection, so select something nobody can see.\n const holder = doc.createElement('span');\n holder.textContent = plain === undefined || plain === '' ? ' ' : plain;\n holder.setAttribute('aria-hidden', 'true');\n // CSSOM, not a style attribute: allowed under a strict Content Security Policy.\n holder.style.cssText = 'position:fixed;top:0;left:0;clip-path:inset(50%);white-space:pre;user-select:text;-webkit-user-select:text';\n\n doc.addEventListener('copy', onCopy, true);\n doc.body.append(holder);\n try {\n if (selection) {\n const range = doc.createRange();\n range.selectNodeContents(holder);\n selection.removeAllRanges();\n selection.addRange(range);\n }\n // eslint-disable-next-line @typescript-eslint/no-deprecated -- the only copy without the async API\n doc.execCommand('copy');\n } catch {\n // Reported through `written`, which the listener never set.\n } finally {\n doc.removeEventListener('copy', onCopy, true);\n holder.remove();\n if (selection) {\n selection.removeAllRanges();\n for (const range of ranges) selection.addRange(range);\n }\n restoreFocus(doc, focus);\n }\n return seen.written;\n}\n","import { CopyFailure, createCopyError, type CopyErrorType } from './errors';\nimport { legacyCopy, legacyEntries } from './legacy-copy';\nimport type { OperationContext } from './machine-shared';\nimport { IMAGE_MIME_TYPE, isBlob, serializeJson, type BlobSource, type CopyPayload } from './payload';\n\n/** Minimal structural view of `navigator.clipboard`, so fakes and polyfills fit. */\nexport interface ClipboardLike {\n writeText?(text: string): Promise<void>;\n write?(items: readonly unknown[]): Promise<void>;\n}\n\nexport type ClipboardItemData = Blob | PromiseLike<Blob>;\n\nexport interface ClipboardItemConstructorLike {\n new (items: Record<string, ClipboardItemData>): unknown;\n supports?(type: string): boolean;\n}\n\nexport interface ClipboardEnvironment {\n readonly isSecureContext?: boolean;\n /** For the `execCommand('copy')` fallback; `window` has it. */\n readonly document?: Document | undefined;\n readonly navigator?: { readonly clipboard?: ClipboardLike | undefined } | undefined;\n readonly ClipboardItem?: ClipboardItemConstructorLike | undefined;\n}\n\n/**\n * The only thing the state machine needs. Implement it to target Electron,\n * a native bridge, a test double, or anything else.\n *\n * Contract: start the platform write synchronously (before any `await`) so the\n * browser still sees the user gesture, and reject with a `CopyFailure` when you\n * can classify the error. `context.signal` aborts when the copy is reset or its\n * host unmounts; honour it to stop expensive work early.\n */\nexport interface ClipboardAdapter {\n write(payload: CopyPayload, context?: OperationContext): Promise<void>;\n}\n\nexport interface BrowserClipboardAdapterOptions {\n /** Defaults to `window`, read lazily at copy time (SSR-safe). */\n readonly getEnvironment?: () => ClipboardEnvironment | undefined;\n /** When rich HTML copy is unavailable, fall back to its plain text. Default `true`. */\n readonly degradeHtmlToText?: boolean;\n /**\n * When the async Clipboard API is unavailable (a plain-HTTP page, a webview without\n * `navigator.clipboard`, no `ClipboardItem` for HTML), copy text, HTML and JSON through the\n * browser's `copy` command instead, as `react-copy-to-clipboard` does. Images still need the\n * async API. Default `true`; `false` reports `insecure-context` / `unsupported` instead.\n */\n readonly legacyFallback?: boolean;\n}\n\ninterface RichClipboard {\n readonly Item: ClipboardItemConstructorLike;\n readonly write: (items: readonly unknown[]) => Promise<void>;\n}\n\nconst fail = (type: CopyErrorType, message: string, cause?: unknown): CopyFailure =>\n new CopyFailure(createCopyError(type, message, cause));\n\nconst noop = (): void => undefined;\n\nfunction defaultEnvironment(): ClipboardEnvironment | undefined {\n return typeof window === 'undefined' ? undefined : window;\n}\n\nfunction getRichClipboard(env: ClipboardEnvironment, clipboard: ClipboardLike): RichClipboard | null {\n const Item = env.ClipboardItem;\n if (!Item || typeof clipboard.write !== 'function') return null;\n return { Item, write: clipboard.write.bind(clipboard) };\n}\n\nfunction isTypeSupported(Item: ClipboardItemConstructorLike, type: string): boolean {\n return typeof Item.supports !== 'function' || Item.supports(type);\n}\n\nasync function resolveImageBlob(source: BlobSource, context: OperationContext | undefined): Promise<Blob> {\n let blob: unknown;\n try {\n // Invoked before the first await, i.e. synchronously inside the gesture.\n blob = await (typeof source === 'function' ? source(context ?? { signal: new AbortController().signal }) : source);\n } catch (cause) {\n if (context?.signal.aborted) throw fail('aborted', 'The image copy was cancelled.', cause);\n throw fail('blob-generation-failed', 'The image source threw or rejected while producing a Blob.', cause);\n }\n if (!isBlob(blob)) throw fail('blob-generation-failed', 'The image source did not produce a Blob.');\n if (blob.type !== IMAGE_MIME_TYPE) {\n throw fail(\n 'unsupported-format',\n `Only ${IMAGE_MIME_TYPE} can be written to the clipboard (received \"${blob.type || 'unknown'}\"). ` +\n `Convert with canvas.toBlob(cb, \"${IMAGE_MIME_TYPE}\").`,\n );\n }\n return blob;\n}\n\nasync function writeImage(\n rich: RichClipboard,\n source: BlobSource,\n context: OperationContext | undefined,\n): Promise<void> {\n if (!isTypeSupported(rich.Item, IMAGE_MIME_TYPE)) {\n throw fail('unsupported-format', `This browser cannot write ${IMAGE_MIME_TYPE} to the clipboard.`);\n }\n // Hand ClipboardItem a *promise* so Safari keeps the gesture while the blob is produced.\n const blob = resolveImageBlob(source, context);\n blob.catch(noop); // Never an unhandled rejection, whichever side fails first.\n try {\n await rich.write([new rich.Item({ [IMAGE_MIME_TYPE]: blob })]);\n } catch (error) {\n // Browsers replace our classified reason with a generic DOMException. Prefer ours.\n const reason = await blob.then(noop, (inner: unknown) => inner);\n throw reason ?? error;\n }\n // Conforming browsers have consumed `blob` by now. Lax polyfills/webviews may resolve\n // without reading it: never report an image that failed to generate as copied.\n await blob;\n}\n\nasync function writeToClipboard(\n payload: CopyPayload,\n env: ClipboardEnvironment | undefined,\n settings: Required<Omit<BrowserClipboardAdapterOptions, 'getEnvironment'>>,\n context: OperationContext | undefined,\n): Promise<void> {\n if (!env) throw fail('unsupported', 'No browser environment: the clipboard only exists in the browser.');\n /** Without the async API: the copy command if it can carry this payload, else `failure`. */\n const legacy = (failure: CopyFailure): void => {\n const entries = settings.legacyFallback && env.document ? legacyEntries(payload) : null;\n if (entries && legacyCopy(env.document as Document, entries)) return;\n throw failure;\n };\n if (env.isSecureContext === false) {\n legacy(fail('insecure-context', 'The Clipboard API requires a secure context (HTTPS or localhost).'));\n return;\n }\n const clipboard = env.navigator?.clipboard;\n if (!clipboard) {\n legacy(fail('unsupported', 'navigator.clipboard is not available in this browser.'));\n return;\n }\n\n switch (payload.kind) {\n case 'text':\n case 'json': {\n const text = payload.kind === 'text' ? payload.value : serializeJson(payload);\n if (typeof clipboard.writeText === 'function') return clipboard.writeText(text);\n legacy(fail('unsupported', 'navigator.clipboard.writeText() is not available.'));\n return;\n }\n\n case 'html': {\n const rich = getRichClipboard(env, clipboard);\n if (!rich || !isTypeSupported(rich.Item, 'text/html')) {\n const failure = fail('unsupported-format', 'Rich HTML copy requires ClipboardItem and navigator.clipboard.write().');\n try {\n legacy(failure);\n return;\n } catch {\n if (settings.degradeHtmlToText && typeof clipboard.writeText === 'function') return clipboard.writeText(payload.text);\n throw failure;\n }\n }\n return rich.write([\n new rich.Item({\n 'text/html': new Blob([payload.html], { type: 'text/html' }),\n 'text/plain': new Blob([payload.text], { type: 'text/plain' }),\n }),\n ]);\n }\n\n case 'image': {\n const rich = getRichClipboard(env, clipboard);\n if (!rich) throw fail('unsupported-format', 'Image copy requires ClipboardItem and navigator.clipboard.write().');\n return writeImage(rich, payload.blob, context);\n }\n\n case 'multi': {\n const rich = getRichClipboard(env, clipboard);\n if (!rich) {\n legacy(fail('unsupported-format', 'Multi-format copy requires ClipboardItem and navigator.clipboard.write().'));\n return;\n }\n const record: Record<string, ClipboardItemData> = Object.create(null) as Record<string, ClipboardItemData>;\n let written = 0;\n for (const { mimeType, data, optional } of payload.items) {\n // Optional items need positive confirmation: an unknown type can make the whole write reject.\n if (optional === true && !(typeof rich.Item.supports === 'function' && rich.Item.supports(mimeType))) continue;\n if (!isTypeSupported(rich.Item, mimeType)) {\n throw fail('unsupported-format', `This browser cannot write \"${mimeType}\" to the clipboard.`);\n }\n record[mimeType] = typeof data === 'string' ? new Blob([data], { type: mimeType }) : data;\n written += 1;\n }\n if (written === 0) throw fail('unsupported-format', 'This browser can write none of the payload types.');\n return rich.write([new rich.Item(record)]);\n }\n }\n}\n\n/** The default adapter: async Clipboard API with feature detection and honest errors. */\nexport function createBrowserClipboardAdapter(options: BrowserClipboardAdapterOptions = {}): ClipboardAdapter {\n const getEnvironment = options.getEnvironment ?? defaultEnvironment;\n const settings = { degradeHtmlToText: options.degradeHtmlToText ?? true, legacyFallback: options.legacyFallback ?? true };\n return {\n write: (payload, context) => writeToClipboard(payload, getEnvironment(), settings, context),\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAiBA,SAAgB,cAAc,SAA4C;CACxE,QAAQ,QAAQ,MAAhB;EACE,KAAK,QACH,OAAO,CAAC,CAAC,cAAc,QAAQ,KAAK,CAAC;EACvC,KAAK,QACH,OAAO,CAAC,CAAC,cAAc,cAAc,OAAO,CAAC,CAAC;EAChD,KAAK,QACH,OAAO,CACL,CAAC,aAAa,QAAQ,IAAI,GAC1B,CAAC,cAAc,QAAQ,IAAI,CAC7B;EACF,KAAK,SACH,OAAO;EACT,KAAK,SAAS;GACZ,MAAM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AU;GACd,KAAK,MAAM,EAAE,UAAU,MAAM,cAAc,QAAQ,OAAO;IAExD,IAAI,aAAa,QAAQ,EAAE,OAAO,KAAK,KAAK,aAAa,cAAc,KAAK,KAAK,SAAS,QAAQ,IAAI;IACtG,IAAI,CAAC,gBAAgB,KAAK,MAAM,QAAQ,GACtC,MAAM,KAAK,sBAAsB,8BAA8B,SAAS,oBAAoB;IAE9F,OAAO,YAAY,OAAO,SAAS,WAAW,IAAI,KAAK,CAAC,IAAI,GAAG,EAAE,MAAM,SAAS,CAAC,IAAI;IACrF,WAAW;GACb;GACA,IAAI,YAAY,GAAG,MAAM,KAAK,sBAAsB,mDAAmD;GACvG,OAAO,KAAK,MAAM,CAAC,IAAI,KAAK,KAAK,MAAM,CAAC,CAAC;EAC3C;CACF;AACF;;AAGA,SAAgB,8BAA8B,UAA0C,CAAC,GAAqB;CAC5G,MAAM,iBAAiB,QAAQ,kBAAkB;CACjD,MAAM,WAAW;EAAE,mBAAmB,QAAQ,qBAAqB;EAAM,gBAAgB,QAAQ,kBAAkB;CAAK;CACxH,OAAO,EACL,QAAQ,SAAS,YAAY,iBAAiB,SAAS,eAAe,GAAG,UAAU,OAAO,EAC5F;AACF"}
@@ -0,0 +1,222 @@
1
+
2
+ const require_errors = require("./errors-CF2EQNbc.cjs");
3
+ const require_payload = require("./payload-DjSSLonm.cjs");
4
+ const require_mime = require("./mime--LB7kdqG.cjs");
5
+ //#region src/core/legacy-copy.ts
6
+ /**
7
+ * The copy that works where the async Clipboard API does not: plain HTTP pages (intranets,
8
+ * internal tools on an IP address) and webviews without `navigator.clipboard`.
9
+ *
10
+ * `document.execCommand('copy')` fires a `copy` event whose `clipboardData` takes any text
11
+ * format, so the payload is written exactly, as text and HTML alike. Nothing is shown and
12
+ * nothing moves: the selection the command needs is made on a node outside the layout, and
13
+ * the user's own selection and focus are put back before the function returns. It runs
14
+ * synchronously, inside the user's gesture. Internal: not part of the public API.
15
+ */
16
+ /** What can travel through a copy event: every text format, no images, no blobs, no web custom formats. */
17
+ function legacyEntries(payload) {
18
+ switch (payload.kind) {
19
+ case "text": return [["text/plain", payload.value]];
20
+ case "json": return [["text/plain", require_payload.serializeJson(payload)]];
21
+ case "html": return [["text/html", payload.html], ["text/plain", payload.text]];
22
+ case "image": return null;
23
+ case "multi": {
24
+ const entries = [];
25
+ for (const { mimeType, data, optional } of payload.items) if (typeof data === "string" && !require_mime.isWebCustomFormat(mimeType)) entries.push([mimeType, data]);
26
+ else if (optional !== true) return null;
27
+ return entries.length > 0 ? entries : null;
28
+ }
29
+ }
30
+ }
31
+ function saveFocus(doc) {
32
+ const element = doc.activeElement;
33
+ if (!element || element === doc.body) return null;
34
+ try {
35
+ const { selectionStart: start, selectionEnd: end, selectionDirection: direction } = element;
36
+ return [element, typeof start === "number" && typeof end === "number" ? [
37
+ start,
38
+ end,
39
+ direction ?? "none"
40
+ ] : null];
41
+ } catch {
42
+ return [element, null];
43
+ }
44
+ }
45
+ function restoreFocus(doc, saved) {
46
+ if (!saved?.[0].isConnected) return;
47
+ const [element, range] = saved;
48
+ if (doc.activeElement !== element) element.focus({ preventScroll: true });
49
+ if (range) element.setSelectionRange(...range);
50
+ }
51
+ /**
52
+ * Writes `entries` through `execCommand('copy')`. Returns whether the browser took them;
53
+ * `false` leaves the clipboard as it was (the caller reports its own, classified error).
54
+ */
55
+ function legacyCopy(doc, entries) {
56
+ if (typeof doc.execCommand !== "function" || !doc.body) return false;
57
+ const plain = entries.find(([format]) => format === "text/plain")?.[1];
58
+ const seen = { written: false };
59
+ const onCopy = (event) => {
60
+ const data = event.clipboardData;
61
+ if (!data) return;
62
+ event.preventDefault();
63
+ event.stopImmediatePropagation();
64
+ try {
65
+ for (const [format, value] of entries) data.setData(format, value);
66
+ seen.written = true;
67
+ } catch {}
68
+ };
69
+ const focus = saveFocus(doc);
70
+ const selection = doc.getSelection();
71
+ const ranges = [];
72
+ if (selection) for (let index = 0; index < selection.rangeCount; index += 1) ranges.push(selection.getRangeAt(index));
73
+ const holder = doc.createElement("span");
74
+ holder.textContent = plain === void 0 || plain === "" ? "\xA0" : plain;
75
+ holder.setAttribute("aria-hidden", "true");
76
+ holder.style.cssText = "position:fixed;top:0;left:0;clip-path:inset(50%);white-space:pre;user-select:text;-webkit-user-select:text";
77
+ doc.addEventListener("copy", onCopy, true);
78
+ doc.body.append(holder);
79
+ try {
80
+ if (selection) {
81
+ const range = doc.createRange();
82
+ range.selectNodeContents(holder);
83
+ selection.removeAllRanges();
84
+ selection.addRange(range);
85
+ }
86
+ doc.execCommand("copy");
87
+ } catch {} finally {
88
+ doc.removeEventListener("copy", onCopy, true);
89
+ holder.remove();
90
+ if (selection) {
91
+ selection.removeAllRanges();
92
+ for (const range of ranges) selection.addRange(range);
93
+ }
94
+ restoreFocus(doc, focus);
95
+ }
96
+ return seen.written;
97
+ }
98
+ //#endregion
99
+ //#region src/core/clipboard-adapter.ts
100
+ const fail = (type, message, cause) => new require_errors.CopyFailure(require_errors.createCopyError(type, message, cause));
101
+ const noop = () => void 0;
102
+ function defaultEnvironment() {
103
+ return typeof window === "undefined" ? void 0 : window;
104
+ }
105
+ function getRichClipboard(env, clipboard) {
106
+ const Item = env.ClipboardItem;
107
+ if (!Item || typeof clipboard.write !== "function") return null;
108
+ return {
109
+ Item,
110
+ write: clipboard.write.bind(clipboard)
111
+ };
112
+ }
113
+ function isTypeSupported(Item, type) {
114
+ return typeof Item.supports !== "function" || Item.supports(type);
115
+ }
116
+ async function resolveImageBlob(source, context) {
117
+ let blob;
118
+ try {
119
+ blob = await (typeof source === "function" ? source(context ?? { signal: new AbortController().signal }) : source);
120
+ } catch (cause) {
121
+ if (context?.signal.aborted) throw fail("aborted", "The image copy was cancelled.", cause);
122
+ throw fail("blob-generation-failed", "The image source threw or rejected while producing a Blob.", cause);
123
+ }
124
+ if (!require_payload.isBlob(blob)) throw fail("blob-generation-failed", "The image source did not produce a Blob.");
125
+ if (blob.type !== "image/png") throw fail("unsupported-format", `Only ${require_payload.IMAGE_MIME_TYPE} can be written to the clipboard (received "${blob.type || "unknown"}"). Convert with canvas.toBlob(cb, "${require_payload.IMAGE_MIME_TYPE}").`);
126
+ return blob;
127
+ }
128
+ async function writeImage(rich, source, context) {
129
+ if (!isTypeSupported(rich.Item, "image/png")) throw fail("unsupported-format", `This browser cannot write ${require_payload.IMAGE_MIME_TYPE} to the clipboard.`);
130
+ const blob = resolveImageBlob(source, context);
131
+ blob.catch(noop);
132
+ try {
133
+ await rich.write([new rich.Item({ [require_payload.IMAGE_MIME_TYPE]: blob })]);
134
+ } catch (error) {
135
+ throw await blob.then(noop, (inner) => inner) ?? error;
136
+ }
137
+ await blob;
138
+ }
139
+ async function writeToClipboard(payload, env, settings, context) {
140
+ if (!env) throw fail("unsupported", "No browser environment: the clipboard only exists in the browser.");
141
+ /** Without the async API: the copy command if it can carry this payload, else `failure`. */
142
+ const legacy = (failure) => {
143
+ const entries = settings.legacyFallback && env.document ? legacyEntries(payload) : null;
144
+ if (entries && legacyCopy(env.document, entries)) return;
145
+ throw failure;
146
+ };
147
+ if (env.isSecureContext === false) {
148
+ legacy(fail("insecure-context", "The Clipboard API requires a secure context (HTTPS or localhost)."));
149
+ return;
150
+ }
151
+ const clipboard = env.navigator?.clipboard;
152
+ if (!clipboard) {
153
+ legacy(fail("unsupported", "navigator.clipboard is not available in this browser."));
154
+ return;
155
+ }
156
+ switch (payload.kind) {
157
+ case "text":
158
+ case "json": {
159
+ const text = payload.kind === "text" ? payload.value : require_payload.serializeJson(payload);
160
+ if (typeof clipboard.writeText === "function") return clipboard.writeText(text);
161
+ legacy(fail("unsupported", "navigator.clipboard.writeText() is not available."));
162
+ return;
163
+ }
164
+ case "html": {
165
+ const rich = getRichClipboard(env, clipboard);
166
+ if (!rich || !isTypeSupported(rich.Item, "text/html")) {
167
+ const failure = fail("unsupported-format", "Rich HTML copy requires ClipboardItem and navigator.clipboard.write().");
168
+ try {
169
+ legacy(failure);
170
+ return;
171
+ } catch {
172
+ if (settings.degradeHtmlToText && typeof clipboard.writeText === "function") return clipboard.writeText(payload.text);
173
+ throw failure;
174
+ }
175
+ }
176
+ return rich.write([new rich.Item({
177
+ "text/html": new Blob([payload.html], { type: "text/html" }),
178
+ "text/plain": new Blob([payload.text], { type: "text/plain" })
179
+ })]);
180
+ }
181
+ case "image": {
182
+ const rich = getRichClipboard(env, clipboard);
183
+ if (!rich) throw fail("unsupported-format", "Image copy requires ClipboardItem and navigator.clipboard.write().");
184
+ return writeImage(rich, payload.blob, context);
185
+ }
186
+ case "multi": {
187
+ const rich = getRichClipboard(env, clipboard);
188
+ if (!rich) {
189
+ legacy(fail("unsupported-format", "Multi-format copy requires ClipboardItem and navigator.clipboard.write()."));
190
+ return;
191
+ }
192
+ const record = Object.create(null);
193
+ let written = 0;
194
+ for (const { mimeType, data, optional } of payload.items) {
195
+ if (optional === true && !(typeof rich.Item.supports === "function" && rich.Item.supports(mimeType))) continue;
196
+ if (!isTypeSupported(rich.Item, mimeType)) throw fail("unsupported-format", `This browser cannot write "${mimeType}" to the clipboard.`);
197
+ record[mimeType] = typeof data === "string" ? new Blob([data], { type: mimeType }) : data;
198
+ written += 1;
199
+ }
200
+ if (written === 0) throw fail("unsupported-format", "This browser can write none of the payload types.");
201
+ return rich.write([new rich.Item(record)]);
202
+ }
203
+ }
204
+ }
205
+ /** The default adapter: async Clipboard API with feature detection and honest errors. */
206
+ function createBrowserClipboardAdapter(options = {}) {
207
+ const getEnvironment = options.getEnvironment ?? defaultEnvironment;
208
+ const settings = {
209
+ degradeHtmlToText: options.degradeHtmlToText ?? true,
210
+ legacyFallback: options.legacyFallback ?? true
211
+ };
212
+ return { write: (payload, context) => writeToClipboard(payload, getEnvironment(), settings, context) };
213
+ }
214
+ //#endregion
215
+ Object.defineProperty(exports, "createBrowserClipboardAdapter", {
216
+ enumerable: true,
217
+ get: function() {
218
+ return createBrowserClipboardAdapter;
219
+ }
220
+ });
221
+
222
+ //# sourceMappingURL=clipboard-adapter-5bmjKbyK.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"clipboard-adapter-5bmjKbyK.cjs","names":["serializeJson","isWebCustomFormat","CopyFailure","createCopyError","isBlob","IMAGE_MIME_TYPE","serializeJson"],"sources":["../../src/core/legacy-copy.ts","../../src/core/clipboard-adapter.ts"],"sourcesContent":["/**\n * The copy that works where the async Clipboard API does not: plain HTTP pages (intranets,\n * internal tools on an IP address) and webviews without `navigator.clipboard`.\n *\n * `document.execCommand('copy')` fires a `copy` event whose `clipboardData` takes any text\n * format, so the payload is written exactly, as text and HTML alike. Nothing is shown and\n * nothing moves: the selection the command needs is made on a node outside the layout, and\n * the user's own selection and focus are put back before the function returns. It runs\n * synchronously, inside the user's gesture. Internal: not part of the public API.\n */\nimport { isWebCustomFormat } from './mime';\nimport { serializeJson, type CopyPayload } from './payload';\n\n/** Each format and its text, in the order written. */\nexport type LegacyEntries = readonly (readonly [format: string, data: string])[];\n\n/** What can travel through a copy event: every text format, no images, no blobs, no web custom formats. */\nexport function legacyEntries(payload: CopyPayload): LegacyEntries | null {\n switch (payload.kind) {\n case 'text':\n return [['text/plain', payload.value]];\n case 'json':\n return [['text/plain', serializeJson(payload)]];\n case 'html':\n return [\n ['text/html', payload.html],\n ['text/plain', payload.text],\n ];\n case 'image':\n return null;\n case 'multi': {\n const entries: (readonly [string, string])[] = [];\n for (const { mimeType, data, optional } of payload.items) {\n if (typeof data === 'string' && !isWebCustomFormat(mimeType)) entries.push([mimeType, data]);\n // A required format that a copy event cannot carry: the copy would be incomplete.\n else if (optional !== true) return null;\n }\n return entries.length > 0 ? entries : null;\n }\n }\n}\n\ntype SavedFocus = readonly [element: HTMLElement, range: readonly [number, number, 'forward' | 'backward' | 'none'] | null];\n\nfunction saveFocus(doc: Document): SavedFocus | null {\n const element = doc.activeElement as (HTMLElement & Partial<HTMLInputElement>) | null;\n if (!element || element === doc.body) return null;\n try {\n const { selectionStart: start, selectionEnd: end, selectionDirection: direction } = element;\n return [element, typeof start === 'number' && typeof end === 'number' ? [start, end, direction ?? 'none'] : null];\n } catch {\n // Older engines throw for inputs without a selection API (email, number).\n return [element, null];\n }\n}\n\nfunction restoreFocus(doc: Document, saved: SavedFocus | null): void {\n if (!saved?.[0].isConnected) return;\n const [element, range] = saved;\n if (doc.activeElement !== element) element.focus({ preventScroll: true });\n if (range) (element as HTMLInputElement).setSelectionRange(...range);\n}\n\n/**\n * Writes `entries` through `execCommand('copy')`. Returns whether the browser took them;\n * `false` leaves the clipboard as it was (the caller reports its own, classified error).\n */\nexport function legacyCopy(doc: Document, entries: LegacyEntries): boolean {\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition, @typescript-eslint/no-deprecated -- missing in some webviews; the only copy without the async API\n if (typeof doc.execCommand !== 'function' || !doc.body) return false;\n const plain = entries.find(([format]) => format === 'text/plain')?.[1];\n // Set by the listener: an object, so the check after `execCommand` reads its latest value.\n const seen = { written: false };\n const onCopy = (event: Event): void => {\n const data = (event as ClipboardEvent).clipboardData;\n if (!data) return;\n event.preventDefault();\n // This copy carries an exact payload: page copy handlers and interceptors must not rewrite it.\n event.stopImmediatePropagation();\n try {\n for (const [format, value] of entries) data.setData(format, value);\n seen.written = true;\n } catch {\n // A format the browser refuses: the copy is reported as failed, not thrown into the page.\n }\n };\n\n // Saved first: in some engines reading or moving the selection already moves focus.\n const focus = saveFocus(doc);\n const selection = doc.getSelection();\n const ranges: Range[] = [];\n if (selection) for (let index = 0; index < selection.rangeCount; index += 1) ranges.push(selection.getRangeAt(index));\n\n // The copy command is only enabled over a selection, so select something nobody can see.\n const holder = doc.createElement('span');\n holder.textContent = plain === undefined || plain === '' ? ' ' : plain;\n holder.setAttribute('aria-hidden', 'true');\n // CSSOM, not a style attribute: allowed under a strict Content Security Policy.\n holder.style.cssText = 'position:fixed;top:0;left:0;clip-path:inset(50%);white-space:pre;user-select:text;-webkit-user-select:text';\n\n doc.addEventListener('copy', onCopy, true);\n doc.body.append(holder);\n try {\n if (selection) {\n const range = doc.createRange();\n range.selectNodeContents(holder);\n selection.removeAllRanges();\n selection.addRange(range);\n }\n // eslint-disable-next-line @typescript-eslint/no-deprecated -- the only copy without the async API\n doc.execCommand('copy');\n } catch {\n // Reported through `written`, which the listener never set.\n } finally {\n doc.removeEventListener('copy', onCopy, true);\n holder.remove();\n if (selection) {\n selection.removeAllRanges();\n for (const range of ranges) selection.addRange(range);\n }\n restoreFocus(doc, focus);\n }\n return seen.written;\n}\n","import { CopyFailure, createCopyError, type CopyErrorType } from './errors';\nimport { legacyCopy, legacyEntries } from './legacy-copy';\nimport type { OperationContext } from './machine-shared';\nimport { IMAGE_MIME_TYPE, isBlob, serializeJson, type BlobSource, type CopyPayload } from './payload';\n\n/** Minimal structural view of `navigator.clipboard`, so fakes and polyfills fit. */\nexport interface ClipboardLike {\n writeText?(text: string): Promise<void>;\n write?(items: readonly unknown[]): Promise<void>;\n}\n\nexport type ClipboardItemData = Blob | PromiseLike<Blob>;\n\nexport interface ClipboardItemConstructorLike {\n new (items: Record<string, ClipboardItemData>): unknown;\n supports?(type: string): boolean;\n}\n\nexport interface ClipboardEnvironment {\n readonly isSecureContext?: boolean;\n /** For the `execCommand('copy')` fallback; `window` has it. */\n readonly document?: Document | undefined;\n readonly navigator?: { readonly clipboard?: ClipboardLike | undefined } | undefined;\n readonly ClipboardItem?: ClipboardItemConstructorLike | undefined;\n}\n\n/**\n * The only thing the state machine needs. Implement it to target Electron,\n * a native bridge, a test double, or anything else.\n *\n * Contract: start the platform write synchronously (before any `await`) so the\n * browser still sees the user gesture, and reject with a `CopyFailure` when you\n * can classify the error. `context.signal` aborts when the copy is reset or its\n * host unmounts; honour it to stop expensive work early.\n */\nexport interface ClipboardAdapter {\n write(payload: CopyPayload, context?: OperationContext): Promise<void>;\n}\n\nexport interface BrowserClipboardAdapterOptions {\n /** Defaults to `window`, read lazily at copy time (SSR-safe). */\n readonly getEnvironment?: () => ClipboardEnvironment | undefined;\n /** When rich HTML copy is unavailable, fall back to its plain text. Default `true`. */\n readonly degradeHtmlToText?: boolean;\n /**\n * When the async Clipboard API is unavailable (a plain-HTTP page, a webview without\n * `navigator.clipboard`, no `ClipboardItem` for HTML), copy text, HTML and JSON through the\n * browser's `copy` command instead, as `react-copy-to-clipboard` does. Images still need the\n * async API. Default `true`; `false` reports `insecure-context` / `unsupported` instead.\n */\n readonly legacyFallback?: boolean;\n}\n\ninterface RichClipboard {\n readonly Item: ClipboardItemConstructorLike;\n readonly write: (items: readonly unknown[]) => Promise<void>;\n}\n\nconst fail = (type: CopyErrorType, message: string, cause?: unknown): CopyFailure =>\n new CopyFailure(createCopyError(type, message, cause));\n\nconst noop = (): void => undefined;\n\nfunction defaultEnvironment(): ClipboardEnvironment | undefined {\n return typeof window === 'undefined' ? undefined : window;\n}\n\nfunction getRichClipboard(env: ClipboardEnvironment, clipboard: ClipboardLike): RichClipboard | null {\n const Item = env.ClipboardItem;\n if (!Item || typeof clipboard.write !== 'function') return null;\n return { Item, write: clipboard.write.bind(clipboard) };\n}\n\nfunction isTypeSupported(Item: ClipboardItemConstructorLike, type: string): boolean {\n return typeof Item.supports !== 'function' || Item.supports(type);\n}\n\nasync function resolveImageBlob(source: BlobSource, context: OperationContext | undefined): Promise<Blob> {\n let blob: unknown;\n try {\n // Invoked before the first await, i.e. synchronously inside the gesture.\n blob = await (typeof source === 'function' ? source(context ?? { signal: new AbortController().signal }) : source);\n } catch (cause) {\n if (context?.signal.aborted) throw fail('aborted', 'The image copy was cancelled.', cause);\n throw fail('blob-generation-failed', 'The image source threw or rejected while producing a Blob.', cause);\n }\n if (!isBlob(blob)) throw fail('blob-generation-failed', 'The image source did not produce a Blob.');\n if (blob.type !== IMAGE_MIME_TYPE) {\n throw fail(\n 'unsupported-format',\n `Only ${IMAGE_MIME_TYPE} can be written to the clipboard (received \"${blob.type || 'unknown'}\"). ` +\n `Convert with canvas.toBlob(cb, \"${IMAGE_MIME_TYPE}\").`,\n );\n }\n return blob;\n}\n\nasync function writeImage(\n rich: RichClipboard,\n source: BlobSource,\n context: OperationContext | undefined,\n): Promise<void> {\n if (!isTypeSupported(rich.Item, IMAGE_MIME_TYPE)) {\n throw fail('unsupported-format', `This browser cannot write ${IMAGE_MIME_TYPE} to the clipboard.`);\n }\n // Hand ClipboardItem a *promise* so Safari keeps the gesture while the blob is produced.\n const blob = resolveImageBlob(source, context);\n blob.catch(noop); // Never an unhandled rejection, whichever side fails first.\n try {\n await rich.write([new rich.Item({ [IMAGE_MIME_TYPE]: blob })]);\n } catch (error) {\n // Browsers replace our classified reason with a generic DOMException. Prefer ours.\n const reason = await blob.then(noop, (inner: unknown) => inner);\n throw reason ?? error;\n }\n // Conforming browsers have consumed `blob` by now. Lax polyfills/webviews may resolve\n // without reading it: never report an image that failed to generate as copied.\n await blob;\n}\n\nasync function writeToClipboard(\n payload: CopyPayload,\n env: ClipboardEnvironment | undefined,\n settings: Required<Omit<BrowserClipboardAdapterOptions, 'getEnvironment'>>,\n context: OperationContext | undefined,\n): Promise<void> {\n if (!env) throw fail('unsupported', 'No browser environment: the clipboard only exists in the browser.');\n /** Without the async API: the copy command if it can carry this payload, else `failure`. */\n const legacy = (failure: CopyFailure): void => {\n const entries = settings.legacyFallback && env.document ? legacyEntries(payload) : null;\n if (entries && legacyCopy(env.document as Document, entries)) return;\n throw failure;\n };\n if (env.isSecureContext === false) {\n legacy(fail('insecure-context', 'The Clipboard API requires a secure context (HTTPS or localhost).'));\n return;\n }\n const clipboard = env.navigator?.clipboard;\n if (!clipboard) {\n legacy(fail('unsupported', 'navigator.clipboard is not available in this browser.'));\n return;\n }\n\n switch (payload.kind) {\n case 'text':\n case 'json': {\n const text = payload.kind === 'text' ? payload.value : serializeJson(payload);\n if (typeof clipboard.writeText === 'function') return clipboard.writeText(text);\n legacy(fail('unsupported', 'navigator.clipboard.writeText() is not available.'));\n return;\n }\n\n case 'html': {\n const rich = getRichClipboard(env, clipboard);\n if (!rich || !isTypeSupported(rich.Item, 'text/html')) {\n const failure = fail('unsupported-format', 'Rich HTML copy requires ClipboardItem and navigator.clipboard.write().');\n try {\n legacy(failure);\n return;\n } catch {\n if (settings.degradeHtmlToText && typeof clipboard.writeText === 'function') return clipboard.writeText(payload.text);\n throw failure;\n }\n }\n return rich.write([\n new rich.Item({\n 'text/html': new Blob([payload.html], { type: 'text/html' }),\n 'text/plain': new Blob([payload.text], { type: 'text/plain' }),\n }),\n ]);\n }\n\n case 'image': {\n const rich = getRichClipboard(env, clipboard);\n if (!rich) throw fail('unsupported-format', 'Image copy requires ClipboardItem and navigator.clipboard.write().');\n return writeImage(rich, payload.blob, context);\n }\n\n case 'multi': {\n const rich = getRichClipboard(env, clipboard);\n if (!rich) {\n legacy(fail('unsupported-format', 'Multi-format copy requires ClipboardItem and navigator.clipboard.write().'));\n return;\n }\n const record: Record<string, ClipboardItemData> = Object.create(null) as Record<string, ClipboardItemData>;\n let written = 0;\n for (const { mimeType, data, optional } of payload.items) {\n // Optional items need positive confirmation: an unknown type can make the whole write reject.\n if (optional === true && !(typeof rich.Item.supports === 'function' && rich.Item.supports(mimeType))) continue;\n if (!isTypeSupported(rich.Item, mimeType)) {\n throw fail('unsupported-format', `This browser cannot write \"${mimeType}\" to the clipboard.`);\n }\n record[mimeType] = typeof data === 'string' ? new Blob([data], { type: mimeType }) : data;\n written += 1;\n }\n if (written === 0) throw fail('unsupported-format', 'This browser can write none of the payload types.');\n return rich.write([new rich.Item(record)]);\n }\n }\n}\n\n/** The default adapter: async Clipboard API with feature detection and honest errors. */\nexport function createBrowserClipboardAdapter(options: BrowserClipboardAdapterOptions = {}): ClipboardAdapter {\n const getEnvironment = options.getEnvironment ?? defaultEnvironment;\n const settings = { degradeHtmlToText: options.degradeHtmlToText ?? true, legacyFallback: options.legacyFallback ?? true };\n return {\n write: (payload, context) => writeToClipboard(payload, getEnvironment(), settings, context),\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAiBA,SAAgB,cAAc,SAA4C;CACxE,QAAQ,QAAQ,MAAhB;EACE,KAAK,QACH,OAAO,CAAC,CAAC,cAAc,QAA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,iBAAiB,KAAK,SAAS;GAC5C,IAAI,CAAC,MAAM,MAAM,KAAK,sBAAsB,oEAAoE;GAChH,OAAO,WAAW,MAAM,QAAQ,MAAM,OAAO;EAC/C;EAEA,KAAK,SAAS;GACZ,MAAM,OAAO,iBAAiB,KAAK,SAAS;GAC5C,IAAI,CAAC,MAAM;IACT,OAAO,KAAK,sBAAsB,2EAA2E,CAAC;IAC9G;GACF;GACA,MAAM,SAA4C,OAAO,OAAO,IAAI;GACpE,IAAI,UAAU;GACd,KAAK,MAAM,EAAE,UAAU,MAAM,cAAc,QAAQ,OAAO;IAExD,IAAI,aAAa,QAAQ,EAAE,OAAO,KAAK,KAAK,aAAa,cAAc,KAAK,KAAK,SAAS,QAAQ,IAAI;IACtG,IAAI,CAAC,gBAAgB,KAAK,MAAM,QAAQ,GACtC,MAAM,KAAK,sBAAsB,8BAA8B,SAAS,oBAAoB;IAE9F,OAAO,YAAY,OAAO,SAAS,WAAW,IAAI,KAAK,CAAC,IAAI,GAAG,EAAE,MAAM,SAAS,CAAC,IAAI;IACrF,WAAW;GACb;GACA,IAAI,YAAY,GAAG,MAAM,KAAK,sBAAsB,mDAAmD;GACvG,OAAO,KAAK,MAAM,CAAC,IAAI,KAAK,KAAK,MAAM,CAAC,CAAC;EAC3C;CACF;AACF;;AAGA,SAAgB,8BAA8B,UAA0C,CAAC,GAAqB;CAC5G,MAAM,iBAAiB,QAAQ,kBAAkB;CACjD,MAAM,WAAW;EAAE,mBAAmB,QAAQ,qBAAqB;EAAM,gBAAgB,QAAQ,kBAAkB;CAAK;CACxH,OAAO,EACL,QAAQ,SAAS,YAAY,iBAAiB,SAAS,eAAe,GAAG,UAAU,OAAO,EAC5F;AACF"}
@@ -13,6 +13,8 @@ interface ClipboardItemConstructorLike {
13
13
  }
14
14
  interface ClipboardEnvironment {
15
15
  readonly isSecureContext?: boolean;
16
+ /** For the `execCommand('copy')` fallback; `window` has it. */
17
+ readonly document?: Document | undefined;
16
18
  readonly navigator?: {
17
19
  readonly clipboard?: ClipboardLike | undefined;
18
20
  } | undefined;
@@ -35,9 +37,16 @@ interface BrowserClipboardAdapterOptions {
35
37
  readonly getEnvironment?: () => ClipboardEnvironment | undefined;
36
38
  /** When rich HTML copy is unavailable, fall back to its plain text. Default `true`. */
37
39
  readonly degradeHtmlToText?: boolean;
40
+ /**
41
+ * When the async Clipboard API is unavailable (a plain-HTTP page, a webview without
42
+ * `navigator.clipboard`, no `ClipboardItem` for HTML), copy text, HTML and JSON through the
43
+ * browser's `copy` command instead, as `react-copy-to-clipboard` does. Images still need the
44
+ * async API. Default `true`; `false` reports `insecure-context` / `unsupported` instead.
45
+ */
46
+ readonly legacyFallback?: boolean;
38
47
  }
39
48
  /** The default adapter: async Clipboard API with feature detection and honest errors. */
40
49
  declare function createBrowserClipboardAdapter(options?: BrowserClipboardAdapterOptions): ClipboardAdapter;
41
50
  //#endregion
42
51
  export { ClipboardItemData as a, ClipboardItemConstructorLike as i, ClipboardAdapter as n, ClipboardLike as o, ClipboardEnvironment as r, createBrowserClipboardAdapter as s, BrowserClipboardAdapterOptions as t };
43
- //# sourceMappingURL=clipboard-adapter-CfaIbZpv.d.cts.map
52
+ //# sourceMappingURL=clipboard-adapter-CUvmAcRE.d.cts.map
@@ -13,6 +13,8 @@ interface ClipboardItemConstructorLike {
13
13
  }
14
14
  interface ClipboardEnvironment {
15
15
  readonly isSecureContext?: boolean;
16
+ /** For the `execCommand('copy')` fallback; `window` has it. */
17
+ readonly document?: Document | undefined;
16
18
  readonly navigator?: {
17
19
  readonly clipboard?: ClipboardLike | undefined;
18
20
  } | undefined;
@@ -35,9 +37,16 @@ interface BrowserClipboardAdapterOptions {
35
37
  readonly getEnvironment?: () => ClipboardEnvironment | undefined;
36
38
  /** When rich HTML copy is unavailable, fall back to its plain text. Default `true`. */
37
39
  readonly degradeHtmlToText?: boolean;
40
+ /**
41
+ * When the async Clipboard API is unavailable (a plain-HTTP page, a webview without
42
+ * `navigator.clipboard`, no `ClipboardItem` for HTML), copy text, HTML and JSON through the
43
+ * browser's `copy` command instead, as `react-copy-to-clipboard` does. Images still need the
44
+ * async API. Default `true`; `false` reports `insecure-context` / `unsupported` instead.
45
+ */
46
+ readonly legacyFallback?: boolean;
38
47
  }
39
48
  /** The default adapter: async Clipboard API with feature detection and honest errors. */
40
49
  declare function createBrowserClipboardAdapter(options?: BrowserClipboardAdapterOptions): ClipboardAdapter;
41
50
  //#endregion
42
51
  export { ClipboardItemData as a, ClipboardItemConstructorLike as i, ClipboardAdapter as n, ClipboardLike as o, ClipboardEnvironment as r, createBrowserClipboardAdapter as s, BrowserClipboardAdapterOptions as t };
43
- //# sourceMappingURL=clipboard-adapter-Chm6zq60.d.ts.map
52
+ //# sourceMappingURL=clipboard-adapter-CdOzN135.d.ts.map
@@ -2,7 +2,7 @@
2
2
  const require_errors = require("./errors-CF2EQNbc.cjs");
3
3
  const require_payload = require("./payload-DjSSLonm.cjs");
4
4
  const require_mime = require("./mime--LB7kdqG.cjs");
5
- const require_clipboard_adapter = require("./clipboard-adapter-Bpuf5GmB.cjs");
5
+ const require_clipboard_adapter = require("./clipboard-adapter-5bmjKbyK.cjs");
6
6
  const require_paste_reader = require("./paste-reader-BL51Jt1y.cjs");
7
7
  //#region src/core/copy-coordinator.ts
8
8
  function createCopyCoordinator() {
@@ -1234,4 +1234,4 @@ Object.defineProperty(exports, "watchClipboardPermission", {
1234
1234
  }
1235
1235
  });
1236
1236
 
1237
- //# sourceMappingURL=core-DF6jiigD.cjs.map
1237
+ //# sourceMappingURL=core-BRMlZOtj.cjs.map