react-smart-copy 1.17.1 → 1.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +22 -3
- package/dist/capture.cjs +30 -153
- package/dist/capture.cjs.map +1 -1
- package/dist/capture.d.cts +2 -25
- package/dist/capture.d.ts +2 -25
- package/dist/capture.js +5 -128
- package/dist/capture.js.map +1 -1
- package/dist/chunks/clipboard-adapter-Cfz-rzw3.cjs +102 -0
- package/dist/chunks/clipboard-adapter-Cfz-rzw3.cjs.map +1 -0
- package/dist/chunks/clipboard-adapter-CtH4VELE.d.cts +43 -0
- package/dist/chunks/clipboard-adapter-DEXkXxwV.js +97 -0
- package/dist/chunks/clipboard-adapter-DEXkXxwV.js.map +1 -0
- package/dist/chunks/clipboard-adapter-Ds0irroN.d.ts +43 -0
- package/dist/chunks/contrast-C6CVklEI.cjs +842 -0
- package/dist/chunks/contrast-C6CVklEI.cjs.map +1 -0
- package/dist/chunks/contrast-DpK2JIVu.js +789 -0
- package/dist/chunks/contrast-DpK2JIVu.js.map +1 -0
- package/dist/chunks/copy-interceptor-C6NABy1l.d.ts +141 -0
- package/dist/chunks/copy-interceptor-CZWzGOkL.d.cts +141 -0
- package/dist/chunks/core-Cp2HSpaz.js +1035 -0
- package/dist/chunks/core-Cp2HSpaz.js.map +1 -0
- package/dist/chunks/core-DYf_Lhbe.cjs +1142 -0
- package/dist/chunks/core-DYf_Lhbe.cjs.map +1 -0
- package/dist/chunks/deadline-C29AlS_Q.js +46 -0
- package/dist/chunks/deadline-C29AlS_Q.js.map +1 -0
- package/dist/chunks/deadline-DkiB8ZHE.cjs +51 -0
- package/dist/chunks/deadline-DkiB8ZHE.cjs.map +1 -0
- package/dist/chunks/errors-9h8sdFFX.js +120 -0
- package/dist/chunks/errors-9h8sdFFX.js.map +1 -0
- package/dist/chunks/errors-BwOF6T_M.cjs +167 -0
- package/dist/chunks/errors-BwOF6T_M.cjs.map +1 -0
- package/dist/chunks/index-mr7sSAgP.d.ts +426 -0
- package/dist/chunks/index-vz0iW5V2.d.cts +426 -0
- package/dist/chunks/mime--LB7kdqG.cjs +153 -0
- package/dist/chunks/mime--LB7kdqG.cjs.map +1 -0
- package/dist/chunks/mime-aa-HA2dm.js +100 -0
- package/dist/chunks/mime-aa-HA2dm.js.map +1 -0
- package/dist/chunks/paste-adapter--SPL4PRE.d.cts +35 -0
- package/dist/chunks/paste-adapter-uahXnTYk.d.ts +35 -0
- package/dist/chunks/paste-reader-Bo01IMC_.cjs +289 -0
- package/dist/chunks/paste-reader-Bo01IMC_.cjs.map +1 -0
- package/dist/chunks/paste-reader-D9i7yMXF.js +224 -0
- package/dist/chunks/paste-reader-D9i7yMXF.js.map +1 -0
- package/dist/chunks/paste-reader-DcXnRWQr.d.cts +96 -0
- package/dist/chunks/paste-reader-DcXnRWQr.d.ts +96 -0
- package/dist/chunks/payload-CUymxwim.cjs +100 -0
- package/dist/chunks/payload-CUymxwim.cjs.map +1 -0
- package/dist/chunks/payload-CcwKJ_bU.d.cts +162 -0
- package/dist/chunks/payload-Cl_8hCI5.d.ts +162 -0
- package/dist/chunks/payload-DGw-JOo7.js +71 -0
- package/dist/chunks/payload-DGw-JOo7.js.map +1 -0
- package/dist/chunks/payload-DI5AorDz.js +103 -0
- package/dist/chunks/payload-DI5AorDz.js.map +1 -0
- package/dist/chunks/payload-J6GjHuh3.cjs +132 -0
- package/dist/chunks/payload-J6GjHuh3.cjs.map +1 -0
- package/dist/chunks/share-Bop47Znn.js +208 -0
- package/dist/chunks/share-Bop47Znn.js.map +1 -0
- package/dist/chunks/share-C0esXvRK.d.cts +115 -0
- package/dist/chunks/share-ayDz974N.cjs +231 -0
- package/dist/chunks/share-ayDz974N.cjs.map +1 -0
- package/dist/chunks/share-e7FenIr2.d.ts +115 -0
- package/dist/chunks/text-field-Ba8W3v4R.cjs +77 -0
- package/dist/chunks/text-field-Ba8W3v4R.cjs.map +1 -0
- package/dist/chunks/text-field-C0SGmvvR.d.cts +18 -0
- package/dist/chunks/text-field-C0SGmvvR.d.ts +18 -0
- package/dist/chunks/text-field-DUvrMMaK.js +66 -0
- package/dist/chunks/text-field-DUvrMMaK.js.map +1 -0
- package/dist/chunks/url-BcMYVCXQ.js +135 -0
- package/dist/chunks/url-BcMYVCXQ.js.map +1 -0
- package/dist/chunks/url-D4PGsRm8.cjs +164 -0
- package/dist/chunks/url-D4PGsRm8.cjs.map +1 -0
- package/dist/chunks/url-DWdElCT3.d.cts +43 -0
- package/dist/chunks/url-DWdElCT3.d.ts +43 -0
- package/dist/code.cjs +20 -109
- package/dist/code.cjs.map +1 -1
- package/dist/code.d.cts +4 -28
- package/dist/code.d.ts +4 -28
- package/dist/code.js +4 -93
- package/dist/code.js.map +1 -1
- package/dist/color.cjs +21 -893
- package/dist/color.cjs.map +1 -1
- package/dist/color.d.cts +4 -28
- package/dist/color.d.ts +4 -28
- package/dist/color.js +4 -876
- package/dist/color.js.map +1 -1
- package/dist/core.cjs +52 -1659
- package/dist/core.d.cts +8 -878
- package/dist/core.d.ts +8 -878
- package/dist/core.js +7 -1614
- package/dist/image.cjs +23 -91
- package/dist/image.cjs.map +1 -1
- package/dist/image.d.cts +1 -0
- package/dist/image.d.ts +1 -0
- package/dist/image.js +5 -73
- package/dist/image.js.map +1 -1
- package/dist/index.cjs +74 -2072
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -978
- package/dist/index.d.ts +8 -978
- package/dist/index.js +7 -2005
- package/dist/index.js.map +1 -1
- package/dist/link.cjs +24 -338
- package/dist/link.cjs.map +1 -1
- package/dist/link.d.cts +5 -83
- package/dist/link.d.ts +5 -83
- package/dist/link.js +5 -319
- package/dist/link.js.map +1 -1
- package/dist/markdown.cjs +8 -97
- package/dist/markdown.cjs.map +1 -1
- package/dist/markdown.d.cts +3 -16
- package/dist/markdown.d.ts +3 -16
- package/dist/markdown.js +3 -92
- package/dist/markdown.js.map +1 -1
- package/dist/rich.cjs +26 -934
- package/dist/rich.cjs.map +1 -1
- package/dist/rich.d.cts +4 -90
- package/dist/rich.d.ts +4 -90
- package/dist/rich.js +4 -912
- package/dist/rich.js.map +1 -1
- package/dist/share.cjs +5 -640
- package/dist/share.d.cts +3 -248
- package/dist/share.d.ts +3 -248
- package/dist/share.js +1 -637
- package/dist/structured.cjs +13 -95
- package/dist/structured.cjs.map +1 -1
- package/dist/structured.d.cts +2 -11
- package/dist/structured.d.ts +2 -11
- package/dist/structured.js +4 -86
- package/dist/structured.js.map +1 -1
- package/dist/table.cjs +11 -39
- package/dist/table.cjs.map +1 -1
- package/dist/table.d.cts +2 -12
- package/dist/table.d.ts +2 -12
- package/dist/table.js +2 -30
- package/dist/table.js.map +1 -1
- package/dist/testing.cjs +10 -43
- package/dist/testing.cjs.map +1 -1
- package/dist/testing.d.cts +6 -181
- package/dist/testing.d.ts +6 -181
- package/dist/testing.js +3 -36
- package/dist/testing.js.map +1 -1
- package/package.json +20 -2
- package/dist/core.cjs.map +0 -1
- package/dist/core.js.map +0 -1
- package/dist/share.cjs.map +0 -1
- package/dist/share.js.map +0 -1
|
@@ -0,0 +1,426 @@
|
|
|
1
|
+
|
|
2
|
+
import { a as CopySource, f as TextPayload, l as JsonPayload, o as HtmlPayload, r as CopyPayload, v as CopyError } from "./payload-CcwKJ_bU.cjs";
|
|
3
|
+
import { d as PasteReadOptions, m as PasteSource, o as DataTransferLike$1, p as PasteResult } from "./paste-reader-DcXnRWQr.cjs";
|
|
4
|
+
import { n as ClipboardAdapter } from "./clipboard-adapter-CtH4VELE.cjs";
|
|
5
|
+
import { n as PasteAdapter } from "./paste-adapter--SPL4PRE.cjs";
|
|
6
|
+
//#region src/core/mime.d.ts
|
|
7
|
+
/**
|
|
8
|
+
* MIME helpers shared by paste and capture. Everything that comes from the
|
|
9
|
+
* clipboard is untrusted input, so types are normalised and validated before
|
|
10
|
+
* they are compared, and image types are confirmed from the bytes themselves.
|
|
11
|
+
*/
|
|
12
|
+
/** SVG is XML that can carry scripts; it is never matched by a wildcard. */
|
|
13
|
+
declare const SVG_MIME_TYPE = "image/svg+xml";
|
|
14
|
+
/** Lower-cased `type/subtype` without parameters, or `null` if it is not a valid MIME type. */
|
|
15
|
+
declare function normalizeMimeType(value: string): string | null;
|
|
16
|
+
/** Prefix of the async Clipboard API's web custom formats (`web application/vnd.acme+json`). */
|
|
17
|
+
declare const WEB_CUSTOM_FORMAT_PREFIX = "web ";
|
|
18
|
+
/** Whether a clipboard type is a web custom format (`web type/subtype`). */
|
|
19
|
+
declare function isWebCustomFormat(type: string): boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Like {@link normalizeMimeType}, but also accepts web custom formats
|
|
22
|
+
* (`web type/subtype`), returned as `web ` + the normalised MIME type.
|
|
23
|
+
*/
|
|
24
|
+
declare function normalizeClipboardType(value: string): string | null;
|
|
25
|
+
/**
|
|
26
|
+
* Does `mimeType` (already normalised) match `pattern` (`type/subtype`, `type/*` or `*\/*`)?
|
|
27
|
+
* Wildcards never match `image/svg+xml`, web custom formats or `+json` types: those must be listed exactly.
|
|
28
|
+
*/
|
|
29
|
+
declare function matchesMimePattern(mimeType: string, pattern: string): boolean;
|
|
30
|
+
/** Types whose clipboard data is text and is therefore surfaced as a `string`. */
|
|
31
|
+
declare function isTextualMimeType(mimeType: string): boolean;
|
|
32
|
+
/** Raster image formats recognised from their leading bytes. */
|
|
33
|
+
type RasterImageMimeType = 'image/png' | 'image/jpeg' | 'image/gif' | 'image/webp' | 'image/bmp' | 'image/avif';
|
|
34
|
+
/** Identifies a raster image from its magic bytes, ignoring whatever type the Blob claims. */
|
|
35
|
+
declare function sniffImageBytes(bytes: Uint8Array): RasterImageMimeType | null;
|
|
36
|
+
/** Reads only the first bytes of a Blob, so sniffing a 20 MB screenshot stays cheap. */
|
|
37
|
+
declare function sniffImageType(blob: Blob): Promise<RasterImageMimeType | null>;
|
|
38
|
+
//#endregion
|
|
39
|
+
//#region src/core/copy-coordinator.d.ts
|
|
40
|
+
/**
|
|
41
|
+
* A copy machine as seen by a coordinator. `release()` returns it from
|
|
42
|
+
* `copied` to `idle`; it is a no-op in any other state.
|
|
43
|
+
*/
|
|
44
|
+
interface CopyCoordinatorMember {
|
|
45
|
+
readonly release: () => void;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Makes a set of copy machines behave like one clipboard: when a member
|
|
49
|
+
* succeeds, the member that previously showed "Copied" goes back to idle,
|
|
50
|
+
* because the clipboard no longer holds its value.
|
|
51
|
+
*
|
|
52
|
+
* Failed copies never release anyone (the clipboard still holds the previous value).
|
|
53
|
+
*/
|
|
54
|
+
interface CopyCoordinator {
|
|
55
|
+
/** A member just reached `copied`. Releases the previous one. */
|
|
56
|
+
readonly activate: (member: CopyCoordinatorMember) => void;
|
|
57
|
+
/** A member left `copied` on its own (auto-reset, reset, unmount). */
|
|
58
|
+
readonly deactivate: (member: CopyCoordinatorMember) => void;
|
|
59
|
+
/** The member currently showing `copied`, if any. */
|
|
60
|
+
readonly getActive: () => CopyCoordinatorMember | null;
|
|
61
|
+
}
|
|
62
|
+
declare function createCopyCoordinator(): CopyCoordinator;
|
|
63
|
+
//#endregion
|
|
64
|
+
//#region src/core/copy-machine.d.ts
|
|
65
|
+
declare const DEFAULT_RESET_AFTER_MS = 2000;
|
|
66
|
+
interface IdleState {
|
|
67
|
+
readonly status: 'idle';
|
|
68
|
+
}
|
|
69
|
+
interface CopyingState {
|
|
70
|
+
readonly status: 'copying';
|
|
71
|
+
readonly payload: CopyPayload;
|
|
72
|
+
readonly retryCount: number;
|
|
73
|
+
}
|
|
74
|
+
interface CopiedState {
|
|
75
|
+
readonly status: 'copied';
|
|
76
|
+
readonly payload: CopyPayload;
|
|
77
|
+
/** Epoch ms when the write resolved. */
|
|
78
|
+
readonly at: number;
|
|
79
|
+
}
|
|
80
|
+
interface ErrorState {
|
|
81
|
+
readonly status: 'error';
|
|
82
|
+
/** `null` when the input itself could not be resolved. */
|
|
83
|
+
readonly payload: CopyPayload | null;
|
|
84
|
+
readonly error: CopyError;
|
|
85
|
+
readonly retryCount: number;
|
|
86
|
+
}
|
|
87
|
+
type CopyState = IdleState | CopyingState | CopiedState | ErrorState;
|
|
88
|
+
type CopyStatus = CopyState['status'];
|
|
89
|
+
/**
|
|
90
|
+
* `cancelled`: the copy was reset or its host unmounted before it finished,
|
|
91
|
+
* so its work was aborted. Nothing to report to the user.
|
|
92
|
+
*/
|
|
93
|
+
type CopyIgnoredReason = 'in-flight' | 'nothing-to-retry' | 'not-retryable' | 'cancelled';
|
|
94
|
+
/**
|
|
95
|
+
* Why an in-flight copy was cancelled: `reset` (`reset()` was called) or
|
|
96
|
+
* `disconnect` (its host disconnected, e.g. the React component unmounted).
|
|
97
|
+
*/
|
|
98
|
+
type CopyCancelReason = 'reset' | 'disconnect';
|
|
99
|
+
/** What `copy()`/`retry()` resolve to. They never reject. */
|
|
100
|
+
type CopyOutcome = {
|
|
101
|
+
readonly status: 'copied';
|
|
102
|
+
readonly payload: CopyPayload;
|
|
103
|
+
} | {
|
|
104
|
+
readonly status: 'error';
|
|
105
|
+
readonly error: CopyError;
|
|
106
|
+
} | {
|
|
107
|
+
readonly status: 'ignored';
|
|
108
|
+
readonly reason: CopyIgnoredReason;
|
|
109
|
+
};
|
|
110
|
+
interface CopyMachineOptions {
|
|
111
|
+
/** Defaults to the browser Clipboard API adapter. */
|
|
112
|
+
readonly adapter?: ClipboardAdapter;
|
|
113
|
+
/** Time in `copied` before returning to `idle`. `false`/`Infinity` disables. Default 2000. */
|
|
114
|
+
readonly resetAfterMs?: number | false;
|
|
115
|
+
/**
|
|
116
|
+
* Max `retry()` calls after the first failure. Default 3. `0` disables
|
|
117
|
+
* retry; `Infinity` allows unlimited retries.
|
|
118
|
+
*/
|
|
119
|
+
readonly maxRetries?: number;
|
|
120
|
+
/**
|
|
121
|
+
* Share "Copied" with other machines: only one member of a coordinator
|
|
122
|
+
* shows `copied` at a time. `null` explicitly opts out (e.g. of a React `<CopyGroup>`).
|
|
123
|
+
*/
|
|
124
|
+
readonly coordinator?: CopyCoordinator | null;
|
|
125
|
+
readonly onCopy?: (payload: CopyPayload) => void;
|
|
126
|
+
readonly onError?: (error: CopyError, payload: CopyPayload | null) => void;
|
|
127
|
+
/**
|
|
128
|
+
* `reset()` moved the machine back to `idle` from any other state. Not
|
|
129
|
+
* called for the automatic return after `resetAfterMs`, for a `<CopyGroup>`
|
|
130
|
+
* handing "Copied" to another member, or when already `idle`.
|
|
131
|
+
*/
|
|
132
|
+
readonly onReset?: () => void;
|
|
133
|
+
/**
|
|
134
|
+
* A copy in flight was cancelled before it settled: its `signal` aborted
|
|
135
|
+
* and its result will not reach state or `onCopy` / `onError`. Fires
|
|
136
|
+
* before `onReset` when `reset()` cancels a copy.
|
|
137
|
+
*/
|
|
138
|
+
readonly onCancel?: (reason: CopyCancelReason) => void;
|
|
139
|
+
/** Clock injection for tests and deterministic environments. */
|
|
140
|
+
readonly now?: () => number;
|
|
141
|
+
}
|
|
142
|
+
/** Options object, or a getter so hosts (like React) can supply the latest options. */
|
|
143
|
+
type CopyMachineOptionsSource = CopyMachineOptions | (() => CopyMachineOptions);
|
|
144
|
+
interface CopyMachine {
|
|
145
|
+
readonly getSnapshot: () => CopyState;
|
|
146
|
+
readonly subscribe: (listener: () => void) => () => void;
|
|
147
|
+
readonly copy: (source: CopySource) => Promise<CopyOutcome>;
|
|
148
|
+
readonly retry: () => Promise<CopyOutcome>;
|
|
149
|
+
/** Back to `idle`. Discards any in-flight result and aborts its `signal`. */
|
|
150
|
+
readonly reset: () => void;
|
|
151
|
+
/**
|
|
152
|
+
* Lifecycle hook for hosts. Re-arms a pending auto-reset; the returned
|
|
153
|
+
* cleanup clears timers, drops in-flight results, aborts in-flight work and
|
|
154
|
+
* unsticks `copying`.
|
|
155
|
+
* Safe to call repeatedly (React StrictMode).
|
|
156
|
+
*/
|
|
157
|
+
readonly connect: () => () => void;
|
|
158
|
+
}
|
|
159
|
+
declare const IDLE_STATE: IdleState;
|
|
160
|
+
/** Pure helper: can `retry()` do anything from this state? */
|
|
161
|
+
declare function canRetryState(state: CopyState, maxRetries?: number): boolean;
|
|
162
|
+
/** Framework-agnostic copy state machine. */
|
|
163
|
+
declare function createCopyMachine(options?: CopyMachineOptionsSource): CopyMachine;
|
|
164
|
+
//#endregion
|
|
165
|
+
//#region src/core/drag-copy.d.ts
|
|
166
|
+
/**
|
|
167
|
+
* The `effectAllowed` a drag operation advertises. Controls which cursor the
|
|
168
|
+
* browser shows and which `dropEffect` the drop target may request.
|
|
169
|
+
*
|
|
170
|
+
* - `'copy'` (default): dragging produces a copy of the data.
|
|
171
|
+
* - `'move'`: dragging removes the source after a drop (the app must do this).
|
|
172
|
+
* - `'link'`: dragging creates a link/reference.
|
|
173
|
+
* - `'copyMove'` / `'copyLink'` / `'linkMove'` / `'all'`: combinations.
|
|
174
|
+
* - `'none'`: the drag is not droppable anywhere.
|
|
175
|
+
* - `'uninitialized'`: browser default (same as `'all'` in most cases).
|
|
176
|
+
*/
|
|
177
|
+
type DragEffectAllowed = 'copy' | 'move' | 'link' | 'copyMove' | 'copyLink' | 'linkMove' | 'all' | 'none' | 'uninitialized';
|
|
178
|
+
/** What is put into `DataTransfer` when a drag starts. */
|
|
179
|
+
interface DragCopyItem {
|
|
180
|
+
/** Web custom formats (`web …`) are skipped: only the async Clipboard API writes them. */
|
|
181
|
+
readonly mimeType: string;
|
|
182
|
+
readonly data: string;
|
|
183
|
+
/** Accepted for parity with `MultiPayloadItem`; every non-web item can be written to a drag. */
|
|
184
|
+
readonly optional?: boolean;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* A multi-format drag payload — strings only (DataTransfer only accepts strings).
|
|
188
|
+
* Mirrors `SyncCopyPayload` from copy-interceptor but scoped to drag.
|
|
189
|
+
*/
|
|
190
|
+
type DragCopyPayload = TextPayload | HtmlPayload | JsonPayload | DragMultiPayload;
|
|
191
|
+
interface DragMultiPayload {
|
|
192
|
+
readonly kind: 'multi';
|
|
193
|
+
readonly items: readonly DragCopyItem[];
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* What the source getter returns:
|
|
197
|
+
* - a string: written as `text/plain`.
|
|
198
|
+
* - a `DragCopyPayload`: written according to its `kind`.
|
|
199
|
+
* - `false`: cancels the drag (`preventDefault()` on `dragstart`).
|
|
200
|
+
* - `null` / `undefined`: leaves the browser's default drag data untouched.
|
|
201
|
+
*/
|
|
202
|
+
type DragCopyDecision = string | DragCopyPayload | false | null | undefined;
|
|
203
|
+
/** Called once when the user begins dragging the element. Must be synchronous. */
|
|
204
|
+
type DragCopySource = (event: DragStartEventLike) => DragCopyDecision;
|
|
205
|
+
/** Structural `DragEvent`: DOM and React drag events both satisfy it. */
|
|
206
|
+
interface DragStartEventLike {
|
|
207
|
+
readonly type: string;
|
|
208
|
+
readonly dataTransfer: DataTransferLike | null;
|
|
209
|
+
readonly defaultPrevented: boolean;
|
|
210
|
+
preventDefault(): void;
|
|
211
|
+
}
|
|
212
|
+
/** The writable face of `DataTransfer`. */
|
|
213
|
+
interface DataTransferLike {
|
|
214
|
+
effectAllowed: string;
|
|
215
|
+
setData(format: string, data: string): void;
|
|
216
|
+
clearData?(format?: string): void;
|
|
217
|
+
}
|
|
218
|
+
type DragCopyStatus =
|
|
219
|
+
/** No drag has started yet, or it was cancelled / never had source data. */
|
|
220
|
+
'idle' |
|
|
221
|
+
/** The element is being dragged and data is on the DataTransfer. */
|
|
222
|
+
'dragging' |
|
|
223
|
+
/** The drag ended (dropped or abandoned). */
|
|
224
|
+
'done';
|
|
225
|
+
type DragCopyPassReason =
|
|
226
|
+
/** Source returned `null`/`undefined`. */
|
|
227
|
+
'declined' |
|
|
228
|
+
/** `DataTransfer` is not present on this event. */
|
|
229
|
+
'no-transfer' |
|
|
230
|
+
/** Source returned `false`. */
|
|
231
|
+
'cancelled';
|
|
232
|
+
type DragCopyOutcome = {
|
|
233
|
+
readonly status: 'written';
|
|
234
|
+
readonly payload: DragCopyPayload;
|
|
235
|
+
} | {
|
|
236
|
+
readonly status: 'passed';
|
|
237
|
+
readonly reason: DragCopyPassReason;
|
|
238
|
+
} | {
|
|
239
|
+
readonly status: 'failed';
|
|
240
|
+
readonly error: CopyError;
|
|
241
|
+
};
|
|
242
|
+
interface DragCopyState {
|
|
243
|
+
readonly status: DragCopyStatus;
|
|
244
|
+
/** The last `dragstart` outcome; `null` before the first drag. */
|
|
245
|
+
readonly outcome: DragCopyOutcome | null;
|
|
246
|
+
}
|
|
247
|
+
interface DragCopyOptions {
|
|
248
|
+
/**
|
|
249
|
+
* Returns the data to put in the drag. Called synchronously on `dragstart`.
|
|
250
|
+
* Return a string (shorthand for `{ kind: 'text' }`), a payload object,
|
|
251
|
+
* `false` to cancel the drag, or `null`/`undefined` to pass through.
|
|
252
|
+
*/
|
|
253
|
+
readonly source: DragCopySource;
|
|
254
|
+
/**
|
|
255
|
+
* `effectAllowed` advertised on the drag. Default `'copy'`.
|
|
256
|
+
* Setting `'move'` signals to drop targets that the source will be removed.
|
|
257
|
+
*/
|
|
258
|
+
readonly effectAllowed?: DragEffectAllowed;
|
|
259
|
+
/**
|
|
260
|
+
* Called each time a drag starts or ends, with the latest outcome and status.
|
|
261
|
+
* Stable across re-renders when written as a class method or via `useRef`.
|
|
262
|
+
*/
|
|
263
|
+
readonly onDrag?: (state: DragCopyState) => void;
|
|
264
|
+
/** Called when preparing the drag payload fails. */
|
|
265
|
+
readonly onError?: (error: CopyError) => void;
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Populates a `dragstart` event's `DataTransfer` with the given payload.
|
|
269
|
+
* Use this from a raw `dragstart` handler or a React `onDragStart` prop.
|
|
270
|
+
* Returns the outcome so you can inspect what happened.
|
|
271
|
+
*/
|
|
272
|
+
declare function applyDragCopy(event: DragStartEventLike, options: DragCopyOptions): DragCopyOutcome;
|
|
273
|
+
interface RegisterDragCopyResult {
|
|
274
|
+
/** Unsubscribes all listeners. Idempotent. */
|
|
275
|
+
readonly unsubscribe: () => void;
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Attaches `dragstart` and `dragend` listeners to `element`, calling
|
|
279
|
+
* `applyDragCopy` on every drag start. Returns an object with an
|
|
280
|
+
* `unsubscribe` function.
|
|
281
|
+
*
|
|
282
|
+
* Pass an options getter so the latest options are always used without
|
|
283
|
+
* re-registering — safe to pass an inline object from a React render.
|
|
284
|
+
*
|
|
285
|
+
* ```ts
|
|
286
|
+
* const { unsubscribe } = registerDragCopy(el, () => ({
|
|
287
|
+
* source: () => `${title}\n${url}`,
|
|
288
|
+
* }));
|
|
289
|
+
* ```
|
|
290
|
+
*/
|
|
291
|
+
declare function registerDragCopy(element: HTMLElement, options: DragCopyOptions | (() => DragCopyOptions)): RegisterDragCopyResult;
|
|
292
|
+
//#endregion
|
|
293
|
+
//#region src/core/paste-machine.d.ts
|
|
294
|
+
interface PasteIdleState {
|
|
295
|
+
readonly status: 'idle';
|
|
296
|
+
}
|
|
297
|
+
interface PasteReadingState {
|
|
298
|
+
readonly status: 'reading';
|
|
299
|
+
}
|
|
300
|
+
interface PasteReadState {
|
|
301
|
+
readonly status: 'read';
|
|
302
|
+
readonly result: PasteResult;
|
|
303
|
+
/** Epoch ms when the read resolved. */
|
|
304
|
+
readonly at: number;
|
|
305
|
+
}
|
|
306
|
+
interface PasteErrorState {
|
|
307
|
+
readonly status: 'error';
|
|
308
|
+
readonly error: CopyError;
|
|
309
|
+
/** Where the failed read came from. Only `'clipboard'` reads can be retried. */
|
|
310
|
+
readonly source: PasteSource;
|
|
311
|
+
/** `retry()` calls made since the last fresh `paste()`. */
|
|
312
|
+
readonly retryCount: number;
|
|
313
|
+
}
|
|
314
|
+
type PasteState = PasteIdleState | PasteReadingState | PasteReadState | PasteErrorState;
|
|
315
|
+
type PasteStatus = PasteState['status'];
|
|
316
|
+
/**
|
|
317
|
+
* `cancelled`: the read was superseded, reset, or its host unmounted before it
|
|
318
|
+
* finished, so its work was aborted. Nothing to report to the user.
|
|
319
|
+
*/
|
|
320
|
+
type PasteIgnoredReason = 'in-flight' | 'no-accepted-content' | 'nothing-to-retry' | 'not-retryable' | 'cancelled';
|
|
321
|
+
/**
|
|
322
|
+
* Why an in-flight read was cancelled: `reset` (`reset()` was called),
|
|
323
|
+
* `disconnect` (its host disconnected, e.g. the React component unmounted) or
|
|
324
|
+
* `superseded` (a paste or drop event arrived while a read was pending).
|
|
325
|
+
*/
|
|
326
|
+
type PasteCancelReason = 'reset' | 'disconnect' | 'superseded';
|
|
327
|
+
/** What `paste()` / `pasteEvent()` / `dropEvent()` / `retry()` resolve to. They never reject. */
|
|
328
|
+
type PasteOutcome = {
|
|
329
|
+
readonly status: 'read';
|
|
330
|
+
readonly result: PasteResult;
|
|
331
|
+
} | {
|
|
332
|
+
readonly status: 'error';
|
|
333
|
+
readonly error: CopyError;
|
|
334
|
+
} | {
|
|
335
|
+
readonly status: 'ignored';
|
|
336
|
+
readonly reason: PasteIgnoredReason;
|
|
337
|
+
};
|
|
338
|
+
/** Structural view of a DOM / React `paste` event. */
|
|
339
|
+
interface PasteEventLike {
|
|
340
|
+
readonly clipboardData: DataTransferLike$1 | null | undefined;
|
|
341
|
+
preventDefault(): void;
|
|
342
|
+
}
|
|
343
|
+
/** Structural view of a DOM / React `drop` event. */
|
|
344
|
+
interface PasteDropEventLike {
|
|
345
|
+
readonly dataTransfer: DataTransferLike$1 | null | undefined;
|
|
346
|
+
preventDefault(): void;
|
|
347
|
+
}
|
|
348
|
+
interface PasteMachineOptions extends PasteReadOptions {
|
|
349
|
+
/** Defaults to the browser Clipboard API adapter. */
|
|
350
|
+
readonly adapter?: PasteAdapter;
|
|
351
|
+
/** Return from `read` to `idle` after this many ms. `false` / `Infinity` / omitted = keep the result. */
|
|
352
|
+
readonly resetAfterMs?: number | false;
|
|
353
|
+
/**
|
|
354
|
+
* Paste events: call `event.preventDefault()` when the event carried accepted
|
|
355
|
+
* content, so the browser doesn't also insert it. Drop events: always call it,
|
|
356
|
+
* so the browser doesn't open the dropped file. Default `true`.
|
|
357
|
+
*/
|
|
358
|
+
readonly preventDefault?: boolean;
|
|
359
|
+
/**
|
|
360
|
+
* Max `retry()` calls after a failed clipboard read. Default 3. `0`
|
|
361
|
+
* disables retry; `Infinity` allows unlimited retries.
|
|
362
|
+
*/
|
|
363
|
+
readonly maxRetries?: number;
|
|
364
|
+
readonly onPaste?: (result: PasteResult) => void;
|
|
365
|
+
readonly onError?: (error: CopyError) => void;
|
|
366
|
+
/**
|
|
367
|
+
* `reset()` moved the machine back to `idle` from any other state. Not
|
|
368
|
+
* called for the automatic return after `resetAfterMs`, or when already `idle`.
|
|
369
|
+
*/
|
|
370
|
+
readonly onReset?: () => void;
|
|
371
|
+
/**
|
|
372
|
+
* A read in flight was cancelled before it settled: its `signal` aborted
|
|
373
|
+
* and its result will not reach state or `onPaste` / `onError`. Fires
|
|
374
|
+
* before `onReset` when `reset()` cancels a read.
|
|
375
|
+
*/
|
|
376
|
+
readonly onCancel?: (reason: PasteCancelReason) => void;
|
|
377
|
+
/** Clock injection for tests and deterministic environments. */
|
|
378
|
+
readonly now?: () => number;
|
|
379
|
+
}
|
|
380
|
+
/** Options object, or a getter so hosts (like React) can supply the latest options. */
|
|
381
|
+
type PasteMachineOptionsSource = PasteMachineOptions | (() => PasteMachineOptions);
|
|
382
|
+
interface PasteMachine {
|
|
383
|
+
readonly getSnapshot: () => PasteState;
|
|
384
|
+
readonly subscribe: (listener: () => void) => () => void;
|
|
385
|
+
/**
|
|
386
|
+
* Reads the system clipboard via the adapter. Call it from a user gesture
|
|
387
|
+
* (click, keypress). May show a permission prompt. Ignored while `reading`.
|
|
388
|
+
*/
|
|
389
|
+
readonly paste: () => Promise<PasteOutcome>;
|
|
390
|
+
/**
|
|
391
|
+
* Handles a `paste` event (Ctrl/⌘+V). No permission prompt: the data is
|
|
392
|
+
* already in the event. Supersedes any read in flight. Events without
|
|
393
|
+
* accepted content are ignored and left untouched for the browser.
|
|
394
|
+
*/
|
|
395
|
+
readonly pasteEvent: (event: PasteEventLike) => Promise<PasteOutcome>;
|
|
396
|
+
/**
|
|
397
|
+
* Handles a drag-and-drop `drop` event exactly like a paste event: same
|
|
398
|
+
* `accept`, limits and image checks, `result.source === 'drop'`. Always calls
|
|
399
|
+
* `event.preventDefault()` (unless `preventDefault: false`), so a rejected
|
|
400
|
+
* file is not opened by the browser in place of the page.
|
|
401
|
+
*/
|
|
402
|
+
readonly dropEvent: (event: PasteDropEventLike) => Promise<PasteOutcome>;
|
|
403
|
+
/**
|
|
404
|
+
* Re-reads the clipboard after a retryable failure (e.g. permission denied,
|
|
405
|
+
* page not focused), up to `maxRetries`. Call it from a user gesture.
|
|
406
|
+
* Paste-event failures can't be retried: their data is gone after dispatch.
|
|
407
|
+
*/
|
|
408
|
+
readonly retry: () => Promise<PasteOutcome>;
|
|
409
|
+
/** Back to `idle`. Discards any in-flight result and aborts its `signal`. */
|
|
410
|
+
readonly reset: () => void;
|
|
411
|
+
/**
|
|
412
|
+
* Lifecycle hook for hosts. Re-arms a pending auto-reset; the returned
|
|
413
|
+
* cleanup clears timers, drops in-flight results, aborts in-flight work and
|
|
414
|
+
* unsticks `reading`.
|
|
415
|
+
* Safe to call repeatedly (React StrictMode).
|
|
416
|
+
*/
|
|
417
|
+
readonly connect: () => () => void;
|
|
418
|
+
}
|
|
419
|
+
declare const PASTE_IDLE_STATE: PasteIdleState;
|
|
420
|
+
/** Pure helper: can `retry()` do anything from this state? */
|
|
421
|
+
declare function canRetryPasteState(state: PasteState, maxRetries?: number): boolean;
|
|
422
|
+
/** Framework-agnostic paste state machine. */
|
|
423
|
+
declare function createPasteMachine(options?: PasteMachineOptionsSource): PasteMachine;
|
|
424
|
+
//#endregion
|
|
425
|
+
export { SVG_MIME_TYPE as $, RegisterDragCopyResult as A, CopyState as B, DragCopyPayload as C, DragEffectAllowed as D, DragCopyStatus as E, CopyIgnoredReason as F, IDLE_STATE as G, CopyingState as H, CopyMachine as I, createCopyMachine as J, IdleState as K, CopyMachineOptions as L, registerDragCopy as M, CopiedState as N, DragMultiPayload as O, CopyCancelReason as P, RasterImageMimeType as Q, CopyMachineOptionsSource as R, DragCopyPassReason as S, DragCopyState as T, DEFAULT_RESET_AFTER_MS as U, CopyStatus as V, ErrorState as W, CopyCoordinatorMember as X, CopyCoordinator as Y, createCopyCoordinator as Z, createPasteMachine as _, PasteEventLike as a, normalizeMimeType as at, DragCopyOptions as b, PasteMachine as c, PasteOutcome as d, WEB_CUSTOM_FORMAT_PREFIX as et, PasteReadState as f, canRetryPasteState as g, PasteStatus as h, PasteErrorState as i, normalizeClipboardType as it, applyDragCopy as j, DragStartEventLike as k, PasteMachineOptions as l, PasteState as m, PasteCancelReason as n, isWebCustomFormat as nt, PasteIdleState as o, sniffImageBytes as ot, PasteReadingState as p, canRetryState as q, PasteDropEventLike as r, matchesMimePattern as rt, PasteIgnoredReason as s, sniffImageType as st, PASTE_IDLE_STATE as t, isTextualMimeType as tt, PasteMachineOptionsSource as u, DragCopyDecision as v, DragCopySource as w, DragCopyOutcome as x, DragCopyItem as y, CopyOutcome as z };
|
|
426
|
+
//# sourceMappingURL=index-vz0iW5V2.d.cts.map
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/core/mime.ts
|
|
3
|
+
/**
|
|
4
|
+
* MIME helpers shared by paste and capture. Everything that comes from the
|
|
5
|
+
* clipboard is untrusted input, so types are normalised and validated before
|
|
6
|
+
* they are compared, and image types are confirmed from the bytes themselves.
|
|
7
|
+
*/
|
|
8
|
+
/** RFC 6838 token shape, lower-cased. Parameters (`;charset=…`) are stripped first. */
|
|
9
|
+
const MIME_SHAPE = /^[a-z0-9][a-z0-9!#$&^_.+-]{0,126}\/[a-z0-9][a-z0-9!#$&^_.+-]{0,126}$/;
|
|
10
|
+
/** SVG is XML that can carry scripts; it is never matched by a wildcard. */
|
|
11
|
+
const SVG_MIME_TYPE = "image/svg+xml";
|
|
12
|
+
/** Lower-cased `type/subtype` without parameters, or `null` if it is not a valid MIME type. */
|
|
13
|
+
function normalizeMimeType(value) {
|
|
14
|
+
const separator = value.indexOf(";");
|
|
15
|
+
const base = (separator === -1 ? value : value.slice(0, separator)).trim().toLowerCase();
|
|
16
|
+
return MIME_SHAPE.test(base) ? base : null;
|
|
17
|
+
}
|
|
18
|
+
/** Prefix of the async Clipboard API's web custom formats (`web application/vnd.acme+json`). */
|
|
19
|
+
const WEB_CUSTOM_FORMAT_PREFIX = "web ";
|
|
20
|
+
/** Whether a clipboard type is a web custom format (`web type/subtype`). */
|
|
21
|
+
function isWebCustomFormat(type) {
|
|
22
|
+
return type.slice(0, 4).toLowerCase() === WEB_CUSTOM_FORMAT_PREFIX;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Like {@link normalizeMimeType}, but also accepts web custom formats
|
|
26
|
+
* (`web type/subtype`), returned as `web ` + the normalised MIME type.
|
|
27
|
+
*/
|
|
28
|
+
function normalizeClipboardType(value) {
|
|
29
|
+
if (!isWebCustomFormat(value)) return normalizeMimeType(value);
|
|
30
|
+
const inner = normalizeMimeType(value.slice(4));
|
|
31
|
+
return inner === null ? null : WEB_CUSTOM_FORMAT_PREFIX + inner;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Types a wildcard never matches, so accepting them must be explicit:
|
|
35
|
+
* `image/svg+xml` (scriptable XML), web custom formats and structured `+json` types
|
|
36
|
+
* (application-specific data that only the app that defined them should read).
|
|
37
|
+
*/
|
|
38
|
+
function requiresExactMatch(mimeType) {
|
|
39
|
+
return mimeType === "image/svg+xml" || isWebCustomFormat(mimeType) || mimeType.endsWith("+json");
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Does `mimeType` (already normalised) match `pattern` (`type/subtype`, `type/*` or `*\/*`)?
|
|
43
|
+
* Wildcards never match `image/svg+xml`, web custom formats or `+json` types: those must be listed exactly.
|
|
44
|
+
*/
|
|
45
|
+
function matchesMimePattern(mimeType, pattern) {
|
|
46
|
+
if (pattern === mimeType) return true;
|
|
47
|
+
if (requiresExactMatch(mimeType)) return false;
|
|
48
|
+
if (pattern === "*/*") return true;
|
|
49
|
+
return pattern.endsWith("/*") && mimeType.startsWith(pattern.slice(0, -1));
|
|
50
|
+
}
|
|
51
|
+
/** Types whose clipboard data is text and is therefore surfaced as a `string`. */
|
|
52
|
+
function isTextualMimeType(mimeType) {
|
|
53
|
+
const type = isWebCustomFormat(mimeType) ? mimeType.slice(4) : mimeType;
|
|
54
|
+
return type.startsWith("text/") || type === "image/svg+xml" || type === "application/json" || type === "application/xml" || type.endsWith("+json");
|
|
55
|
+
}
|
|
56
|
+
const SNIFF_BYTES = 16;
|
|
57
|
+
function startsWith(bytes, signature, offset = 0) {
|
|
58
|
+
return signature.every((byte, index) => bytes[offset + index] === byte);
|
|
59
|
+
}
|
|
60
|
+
const ascii = (text) => Array.from(text, (char) => char.charCodeAt(0));
|
|
61
|
+
const PNG = [
|
|
62
|
+
137,
|
|
63
|
+
80,
|
|
64
|
+
78,
|
|
65
|
+
71,
|
|
66
|
+
13,
|
|
67
|
+
10,
|
|
68
|
+
26,
|
|
69
|
+
10
|
|
70
|
+
];
|
|
71
|
+
const JPEG = [
|
|
72
|
+
255,
|
|
73
|
+
216,
|
|
74
|
+
255
|
|
75
|
+
];
|
|
76
|
+
const GIF = ascii("GIF8");
|
|
77
|
+
const RIFF = ascii("RIFF");
|
|
78
|
+
const WEBP = ascii("WEBP");
|
|
79
|
+
const BMP = ascii("BM");
|
|
80
|
+
const FTYP_AVIF = ascii("ftypavif");
|
|
81
|
+
const FTYP_AVIS = ascii("ftypavis");
|
|
82
|
+
/** Identifies a raster image from its magic bytes, ignoring whatever type the Blob claims. */
|
|
83
|
+
function sniffImageBytes(bytes) {
|
|
84
|
+
if (startsWith(bytes, PNG)) return "image/png";
|
|
85
|
+
if (startsWith(bytes, JPEG)) return "image/jpeg";
|
|
86
|
+
if (startsWith(bytes, GIF)) return "image/gif";
|
|
87
|
+
if (startsWith(bytes, RIFF) && startsWith(bytes, WEBP, 8)) return "image/webp";
|
|
88
|
+
if (startsWith(bytes, FTYP_AVIF, 4) || startsWith(bytes, FTYP_AVIS, 4)) return "image/avif";
|
|
89
|
+
if (startsWith(bytes, BMP)) return "image/bmp";
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
/** Reads only the first bytes of a Blob, so sniffing a 20 MB screenshot stays cheap. */
|
|
93
|
+
async function sniffImageType(blob) {
|
|
94
|
+
const head = await blob.slice(0, SNIFF_BYTES).arrayBuffer();
|
|
95
|
+
return sniffImageBytes(new Uint8Array(head));
|
|
96
|
+
}
|
|
97
|
+
//#endregion
|
|
98
|
+
Object.defineProperty(exports, "SVG_MIME_TYPE", {
|
|
99
|
+
enumerable: true,
|
|
100
|
+
get: function() {
|
|
101
|
+
return SVG_MIME_TYPE;
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
Object.defineProperty(exports, "WEB_CUSTOM_FORMAT_PREFIX", {
|
|
105
|
+
enumerable: true,
|
|
106
|
+
get: function() {
|
|
107
|
+
return WEB_CUSTOM_FORMAT_PREFIX;
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
Object.defineProperty(exports, "isTextualMimeType", {
|
|
111
|
+
enumerable: true,
|
|
112
|
+
get: function() {
|
|
113
|
+
return isTextualMimeType;
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
Object.defineProperty(exports, "isWebCustomFormat", {
|
|
117
|
+
enumerable: true,
|
|
118
|
+
get: function() {
|
|
119
|
+
return isWebCustomFormat;
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
Object.defineProperty(exports, "matchesMimePattern", {
|
|
123
|
+
enumerable: true,
|
|
124
|
+
get: function() {
|
|
125
|
+
return matchesMimePattern;
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
Object.defineProperty(exports, "normalizeClipboardType", {
|
|
129
|
+
enumerable: true,
|
|
130
|
+
get: function() {
|
|
131
|
+
return normalizeClipboardType;
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
Object.defineProperty(exports, "normalizeMimeType", {
|
|
135
|
+
enumerable: true,
|
|
136
|
+
get: function() {
|
|
137
|
+
return normalizeMimeType;
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
Object.defineProperty(exports, "sniffImageBytes", {
|
|
141
|
+
enumerable: true,
|
|
142
|
+
get: function() {
|
|
143
|
+
return sniffImageBytes;
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
Object.defineProperty(exports, "sniffImageType", {
|
|
147
|
+
enumerable: true,
|
|
148
|
+
get: function() {
|
|
149
|
+
return sniffImageType;
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
//# sourceMappingURL=mime--LB7kdqG.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mime--LB7kdqG.cjs","names":[],"sources":["../../src/core/mime.ts"],"sourcesContent":["/**\n * MIME helpers shared by paste and capture. Everything that comes from the\n * clipboard is untrusted input, so types are normalised and validated before\n * they are compared, and image types are confirmed from the bytes themselves.\n */\n\n/** RFC 6838 token shape, lower-cased. Parameters (`;charset=…`) are stripped first. */\nconst MIME_SHAPE = /^[a-z0-9][a-z0-9!#$&^_.+-]{0,126}\\/[a-z0-9][a-z0-9!#$&^_.+-]{0,126}$/;\n\n/** SVG is XML that can carry scripts; it is never matched by a wildcard. */\nexport const SVG_MIME_TYPE = 'image/svg+xml';\n\n/** Lower-cased `type/subtype` without parameters, or `null` if it is not a valid MIME type. */\nexport function normalizeMimeType(value: string): string | null {\n const separator = value.indexOf(';');\n const base = (separator === -1 ? value : value.slice(0, separator)).trim().toLowerCase();\n return MIME_SHAPE.test(base) ? base : null;\n}\n\n/** Prefix of the async Clipboard API's web custom formats (`web application/vnd.acme+json`). */\nexport const WEB_CUSTOM_FORMAT_PREFIX = 'web ';\n\n/** Whether a clipboard type is a web custom format (`web type/subtype`). */\nexport function isWebCustomFormat(type: string): boolean {\n return type.slice(0, 4).toLowerCase() === WEB_CUSTOM_FORMAT_PREFIX;\n}\n\n/**\n * Like {@link normalizeMimeType}, but also accepts web custom formats\n * (`web type/subtype`), returned as `web ` + the normalised MIME type.\n */\nexport function normalizeClipboardType(value: string): string | null {\n if (!isWebCustomFormat(value)) return normalizeMimeType(value);\n const inner = normalizeMimeType(value.slice(4));\n return inner === null ? null : WEB_CUSTOM_FORMAT_PREFIX + inner;\n}\n\n/**\n * Types a wildcard never matches, so accepting them must be explicit:\n * `image/svg+xml` (scriptable XML), web custom formats and structured `+json` types\n * (application-specific data that only the app that defined them should read).\n */\nfunction requiresExactMatch(mimeType: string): boolean {\n return mimeType === SVG_MIME_TYPE || isWebCustomFormat(mimeType) || mimeType.endsWith('+json');\n}\n\n/**\n * Does `mimeType` (already normalised) match `pattern` (`type/subtype`, `type/*` or `*\\/*`)?\n * Wildcards never match `image/svg+xml`, web custom formats or `+json` types: those must be listed exactly.\n */\nexport function matchesMimePattern(mimeType: string, pattern: string): boolean {\n if (pattern === mimeType) return true;\n if (requiresExactMatch(mimeType)) return false;\n if (pattern === '*/*') return true;\n return pattern.endsWith('/*') && mimeType.startsWith(pattern.slice(0, -1));\n}\n\n/** Types whose clipboard data is text and is therefore surfaced as a `string`. */\nexport function isTextualMimeType(mimeType: string): boolean {\n const type = isWebCustomFormat(mimeType) ? mimeType.slice(4) : mimeType;\n return (\n type.startsWith('text/') ||\n type === SVG_MIME_TYPE ||\n type === 'application/json' ||\n type === 'application/xml' ||\n type.endsWith('+json')\n );\n}\n\n/** Raster image formats recognised from their leading bytes. */\nexport type RasterImageMimeType = 'image/png' | 'image/jpeg' | 'image/gif' | 'image/webp' | 'image/bmp' | 'image/avif';\n\nconst SNIFF_BYTES = 16;\n\nfunction startsWith(bytes: Uint8Array, signature: readonly number[], offset = 0): boolean {\n return signature.every((byte, index) => bytes[offset + index] === byte);\n}\n\nconst ascii = (text: string): number[] => Array.from(text, (char) => char.charCodeAt(0));\n\nconst PNG = [0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a];\nconst JPEG = [0xff, 0xd8, 0xff];\nconst GIF = ascii('GIF8');\nconst RIFF = ascii('RIFF');\nconst WEBP = ascii('WEBP');\nconst BMP = ascii('BM');\nconst FTYP_AVIF = ascii('ftypavif');\nconst FTYP_AVIS = ascii('ftypavis');\n\n/** Identifies a raster image from its magic bytes, ignoring whatever type the Blob claims. */\nexport function sniffImageBytes(bytes: Uint8Array): RasterImageMimeType | null {\n if (startsWith(bytes, PNG)) return 'image/png';\n if (startsWith(bytes, JPEG)) return 'image/jpeg';\n if (startsWith(bytes, GIF)) return 'image/gif';\n if (startsWith(bytes, RIFF) && startsWith(bytes, WEBP, 8)) return 'image/webp';\n if (startsWith(bytes, FTYP_AVIF, 4) || startsWith(bytes, FTYP_AVIS, 4)) return 'image/avif';\n if (startsWith(bytes, BMP)) return 'image/bmp';\n return null;\n}\n\n/** Reads only the first bytes of a Blob, so sniffing a 20 MB screenshot stays cheap. */\nexport async function sniffImageType(blob: Blob): Promise<RasterImageMimeType | null> {\n const head = await blob.slice(0, SNIFF_BYTES).arrayBuffer();\n return sniffImageBytes(new Uint8Array(head));\n}\n"],"mappings":";;;;;;;;AAOA,MAAM,aAAa;;AAGnB,MAAa,gBAAgB;;AAG7B,SAAgB,kBAAkB,OAA8B;CAC9D,MAAM,YAAY,MAAM,QAAQ,GAAG;CACnC,MAAM,QAAQ,cAAc,KAAK,QAAQ,MAAM,MAAM,GAAG,SAAS,EAAA,CAAG,KAAK,CAAC,CAAC,YAAY;CACvF,OAAO,WAAW,KAAK,IAAI,IAAI,OAAO;AACxC;;AAGA,MAAa,2BAA2B;;AAGxC,SAAgB,kBAAkB,MAAuB;CACvD,OAAO,KAAK,MAAM,GAAG,CAAC,CAAC,CAAC,YAAY,MAAM;AAC5C;;;;;AAMA,SAAgB,uBAAuB,OAA8B;CACnE,IAAI,CAAC,kBAAkB,KAAK,GAAG,OAAO,kBAAkB,KAAK;CAC7D,MAAM,QAAQ,kBAAkB,MAAM,MAAM,CAAC,CAAC;CAC9C,OAAO,UAAU,OAAO,OAAO,2BAA2B;AAC5D;;;;;;AAOA,SAAS,mBAAmB,UAA2B;CACrD,OAAO,aAAA,mBAA8B,kBAAkB,QAAQ,KAAK,SAAS,SAAS,OAAO;AAC/F;;;;;AAMA,SAAgB,mBAAmB,UAAkB,SAA0B;CAC7E,IAAI,YAAY,UAAU,OAAO;CACjC,IAAI,mBAAmB,QAAQ,GAAG,OAAO;CACzC,IAAI,YAAY,OAAO,OAAO;CAC9B,OAAO,QAAQ,SAAS,IAAI,KAAK,SAAS,WAAW,QAAQ,MAAM,GAAG,EAAE,CAAC;AAC3E;;AAGA,SAAgB,kBAAkB,UAA2B;CAC3D,MAAM,OAAO,kBAAkB,QAAQ,IAAI,SAAS,MAAM,CAAC,IAAI;CAC/D,OACE,KAAK,WAAW,OAAO,KACvB,SAAA,mBACA,SAAS,sBACT,SAAS,qBACT,KAAK,SAAS,OAAO;AAEzB;AAKA,MAAM,cAAc;AAEpB,SAAS,WAAW,OAAmB,WAA8B,SAAS,GAAY;CACxF,OAAO,UAAU,OAAO,MAAM,UAAU,MAAM,SAAS,WAAW,IAAI;AACxE;AAEA,MAAM,SAAS,SAA2B,MAAM,KAAK,OAAO,SAAS,KAAK,WAAW,CAAC,CAAC;AAEvF,MAAM,MAAM;CAAC;CAAM;CAAM;CAAM;CAAM;CAAM;CAAM;CAAM;AAAI;AAC3D,MAAM,OAAO;CAAC;CAAM;CAAM;AAAI;AAC9B,MAAM,MAAM,MAAM,MAAM;AACxB,MAAM,OAAO,MAAM,MAAM;AACzB,MAAM,OAAO,MAAM,MAAM;AACzB,MAAM,MAAM,MAAM,IAAI;AACtB,MAAM,YAAY,MAAM,UAAU;AAClC,MAAM,YAAY,MAAM,UAAU;;AAGlC,SAAgB,gBAAgB,OAA+C;CAC7E,IAAI,WAAW,OAAO,GAAG,GAAG,OAAO;CACnC,IAAI,WAAW,OAAO,IAAI,GAAG,OAAO;CACpC,IAAI,WAAW,OAAO,GAAG,GAAG,OAAO;CACnC,IAAI,WAAW,OAAO,IAAI,KAAK,WAAW,OAAO,MAAM,CAAC,GAAG,OAAO;CAClE,IAAI,WAAW,OAAO,WAAW,CAAC,KAAK,WAAW,OAAO,WAAW,CAAC,GAAG,OAAO;CAC/E,IAAI,WAAW,OAAO,GAAG,GAAG,OAAO;CACnC,OAAO;AACT;;AAGA,eAAsB,eAAe,MAAiD;CACpF,MAAM,OAAO,MAAM,KAAK,MAAM,GAAG,WAAW,CAAC,CAAC,YAAY;CAC1D,OAAO,gBAAgB,IAAI,WAAW,IAAI,CAAC;AAC7C"}
|