react-smart-copy 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +336 -0
- package/dist/core.cjs +429 -0
- package/dist/core.cjs.map +1 -0
- package/dist/core.d.cts +218 -0
- package/dist/core.d.ts +218 -0
- package/dist/core.js +411 -0
- package/dist/core.js.map +1 -0
- package/dist/index.cjs +821 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +378 -0
- package/dist/index.d.ts +378 -0
- package/dist/index.js +793 -0
- package/dist/index.js.map +1 -0
- package/package.json +136 -0
package/dist/core.cjs
ADDED
|
@@ -0,0 +1,429 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region src/core/errors.ts
|
|
3
|
+
function createCopyError(type, message, cause) {
|
|
4
|
+
return cause === void 0 ? {
|
|
5
|
+
type,
|
|
6
|
+
message
|
|
7
|
+
} : {
|
|
8
|
+
type,
|
|
9
|
+
message,
|
|
10
|
+
cause
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
const RETRYABLE_ERRORS = /* @__PURE__ */ new Set([
|
|
14
|
+
"permission-denied",
|
|
15
|
+
"not-focused",
|
|
16
|
+
"blob-generation-failed",
|
|
17
|
+
"unknown"
|
|
18
|
+
]);
|
|
19
|
+
/** Whether retrying the same payload could plausibly succeed. */
|
|
20
|
+
function isRetryableError(error) {
|
|
21
|
+
return RETRYABLE_ERRORS.has(error.type);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Branded (not `instanceof`) so failures stay recognisable even when the core
|
|
25
|
+
* is bundled twice, e.g. `react-smart-copy` and `react-smart-copy/core` together.
|
|
26
|
+
*/
|
|
27
|
+
const COPY_FAILURE_BRAND = Symbol.for("react-smart-copy.CopyFailure");
|
|
28
|
+
/** Error thrown by adapters to carry a fully classified {@link CopyError}. */
|
|
29
|
+
var CopyFailure = class extends Error {
|
|
30
|
+
constructor(copyError) {
|
|
31
|
+
super(copyError.message);
|
|
32
|
+
this[COPY_FAILURE_BRAND] = true;
|
|
33
|
+
this.name = "CopyFailure";
|
|
34
|
+
this.copyError = copyError;
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
function isCopyFailure(value) {
|
|
38
|
+
return typeof value === "object" && value !== null && value[COPY_FAILURE_BRAND] === true;
|
|
39
|
+
}
|
|
40
|
+
function readString(value, key) {
|
|
41
|
+
if (typeof value !== "object" || value === null) return void 0;
|
|
42
|
+
const field = value[key];
|
|
43
|
+
return typeof field === "string" ? field : void 0;
|
|
44
|
+
}
|
|
45
|
+
/** Classifies anything thrown by the platform or an adapter into a {@link CopyError}. */
|
|
46
|
+
function toCopyError(cause) {
|
|
47
|
+
if (isCopyFailure(cause)) return cause.copyError;
|
|
48
|
+
const name = readString(cause, "name");
|
|
49
|
+
const message = readString(cause, "message") ?? "";
|
|
50
|
+
switch (name) {
|
|
51
|
+
case "NotAllowedError": return /focus/i.test(message) ? createCopyError("not-focused", "The document was not focused when the copy was attempted.", cause) : createCopyError("permission-denied", "Clipboard write permission was denied.", cause);
|
|
52
|
+
case "SecurityError": return createCopyError("insecure-context", "The clipboard is blocked in this context.", cause);
|
|
53
|
+
case "NotSupportedError":
|
|
54
|
+
case "DataError": return createCopyError("unsupported-format", "The browser rejected this clipboard format.", cause);
|
|
55
|
+
default: return createCopyError("unknown", message || "The copy failed for an unknown reason.", cause);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
const DEFAULT_DESCRIPTIONS = {
|
|
59
|
+
unsupported: "Copying isn't supported in this browser.",
|
|
60
|
+
"insecure-context": "Copying requires a secure (HTTPS) connection.",
|
|
61
|
+
"permission-denied": "Clipboard access was blocked. Allow it and try again.",
|
|
62
|
+
"not-focused": "The page lost focus while copying. Try again.",
|
|
63
|
+
"invalid-payload": "There is nothing to copy.",
|
|
64
|
+
"unsupported-format": "This content can't be copied in this browser.",
|
|
65
|
+
"blob-generation-failed": "The image couldn't be prepared for copying.",
|
|
66
|
+
"max-retries-exceeded": "Copying failed after several attempts.",
|
|
67
|
+
unknown: "Couldn't copy to the clipboard. Try again."
|
|
68
|
+
};
|
|
69
|
+
/** Default English, user-facing sentence for an error. Replace for i18n. */
|
|
70
|
+
function describeCopyError(error) {
|
|
71
|
+
return DEFAULT_DESCRIPTIONS[error.type];
|
|
72
|
+
}
|
|
73
|
+
//#endregion
|
|
74
|
+
//#region src/core/payload.ts
|
|
75
|
+
/** The only image MIME type with reliable cross-browser clipboard write support. */
|
|
76
|
+
const IMAGE_MIME_TYPE = "image/png";
|
|
77
|
+
function normalizePayload(input) {
|
|
78
|
+
return typeof input === "string" ? {
|
|
79
|
+
kind: "text",
|
|
80
|
+
value: input
|
|
81
|
+
} : input;
|
|
82
|
+
}
|
|
83
|
+
function isBlob(value) {
|
|
84
|
+
if (typeof Blob !== "undefined" && value instanceof Blob) return true;
|
|
85
|
+
const tag = Object.prototype.toString.call(value);
|
|
86
|
+
return tag === "[object Blob]" || tag === "[object File]";
|
|
87
|
+
}
|
|
88
|
+
function isThenable(value) {
|
|
89
|
+
return (typeof value === "object" || typeof value === "function") && value !== null && typeof value.then === "function";
|
|
90
|
+
}
|
|
91
|
+
const invalid = (message) => createCopyError("invalid-payload", message);
|
|
92
|
+
/**
|
|
93
|
+
* Structural validation. Typed callers can't produce most of these states,
|
|
94
|
+
* but plain-JS callers and runtime data can, so the check is always on.
|
|
95
|
+
*/
|
|
96
|
+
function validatePayload(payload) {
|
|
97
|
+
if (typeof payload !== "object" || payload === null) return invalid("Copy input must be a string or a payload object.");
|
|
98
|
+
const candidate = payload;
|
|
99
|
+
switch (candidate["kind"]) {
|
|
100
|
+
case "text": return typeof candidate["value"] === "string" && candidate["value"].length > 0 ? null : invalid("Text payload must be a non-empty string.");
|
|
101
|
+
case "html":
|
|
102
|
+
if (typeof candidate["html"] !== "string" || candidate["html"].length === 0) return invalid("HTML payload requires a non-empty `html` string.");
|
|
103
|
+
return typeof candidate["text"] === "string" && candidate["text"].length > 0 ? null : invalid("HTML payload requires a non-empty plain-text `text` fallback.");
|
|
104
|
+
case "image": {
|
|
105
|
+
const source = candidate["blob"];
|
|
106
|
+
return isBlob(source) || typeof source === "function" || isThenable(source) ? null : invalid("Image payload requires a Blob, a Promise<Blob> or a function returning one.");
|
|
107
|
+
}
|
|
108
|
+
case "json": return candidate["value"] === void 0 ? invalid("JSON payload value is undefined.") : null;
|
|
109
|
+
case "multi": {
|
|
110
|
+
const items = candidate["items"];
|
|
111
|
+
if (!Array.isArray(items) || items.length === 0) return invalid("Multi payload requires at least one item.");
|
|
112
|
+
const seen = /* @__PURE__ */ new Set();
|
|
113
|
+
for (const item of items) {
|
|
114
|
+
const entry = typeof item === "object" && item !== null ? item : {};
|
|
115
|
+
const mimeType = entry["mimeType"];
|
|
116
|
+
const data = entry["data"];
|
|
117
|
+
if (typeof mimeType !== "string" || mimeType.length === 0) return invalid("Every multi item needs a non-empty `mimeType`.");
|
|
118
|
+
if (seen.has(mimeType)) return invalid(`Duplicate MIME type "${mimeType}" in multi payload.`);
|
|
119
|
+
seen.add(mimeType);
|
|
120
|
+
if (typeof data !== "string" && !isBlob(data)) return invalid(`Multi item "${mimeType}" must contain a string or a Blob.`);
|
|
121
|
+
}
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
124
|
+
default: return invalid(`Unknown payload kind: ${String(candidate["kind"])}.`);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
/** Serialises a JSON payload, throwing a classified failure instead of a raw TypeError. */
|
|
128
|
+
function serializeJson(payload) {
|
|
129
|
+
const indent = payload.pretty === true ? 2 : typeof payload.pretty === "number" ? payload.pretty : void 0;
|
|
130
|
+
let text;
|
|
131
|
+
try {
|
|
132
|
+
text = JSON.stringify(payload.value, null, indent);
|
|
133
|
+
} catch (cause) {
|
|
134
|
+
throw new CopyFailure(createCopyError("invalid-payload", "JSON payload could not be serialised (circular reference or BigInt?).", cause));
|
|
135
|
+
}
|
|
136
|
+
if (typeof text !== "string") throw new CopyFailure(createCopyError("invalid-payload", "JSON payload serialised to nothing (functions, symbols and undefined are not JSON)."));
|
|
137
|
+
return text;
|
|
138
|
+
}
|
|
139
|
+
//#endregion
|
|
140
|
+
//#region src/core/clipboard-adapter.ts
|
|
141
|
+
const fail = (type, message, cause) => new CopyFailure(createCopyError(type, message, cause));
|
|
142
|
+
const noop = () => void 0;
|
|
143
|
+
function defaultEnvironment() {
|
|
144
|
+
return typeof window === "undefined" ? void 0 : window;
|
|
145
|
+
}
|
|
146
|
+
function getRichClipboard(env, clipboard) {
|
|
147
|
+
const Item = env.ClipboardItem;
|
|
148
|
+
if (!Item || typeof clipboard.write !== "function") return null;
|
|
149
|
+
return {
|
|
150
|
+
Item,
|
|
151
|
+
write: clipboard.write.bind(clipboard)
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
function isTypeSupported(Item, type) {
|
|
155
|
+
return typeof Item.supports !== "function" || Item.supports(type);
|
|
156
|
+
}
|
|
157
|
+
function writeText(clipboard, text) {
|
|
158
|
+
if (typeof clipboard.writeText !== "function") throw fail("unsupported", "navigator.clipboard.writeText() is not available.");
|
|
159
|
+
return clipboard.writeText(text);
|
|
160
|
+
}
|
|
161
|
+
async function resolveImageBlob(source) {
|
|
162
|
+
let blob;
|
|
163
|
+
try {
|
|
164
|
+
blob = await (typeof source === "function" ? source() : source);
|
|
165
|
+
} catch (cause) {
|
|
166
|
+
throw fail("blob-generation-failed", "The image source threw or rejected while producing a Blob.", cause);
|
|
167
|
+
}
|
|
168
|
+
if (!isBlob(blob)) throw fail("blob-generation-failed", "The image source did not produce a Blob.");
|
|
169
|
+
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}").`);
|
|
170
|
+
return blob;
|
|
171
|
+
}
|
|
172
|
+
async function writeImage(rich, source) {
|
|
173
|
+
if (!isTypeSupported(rich.Item, "image/png")) throw fail("unsupported-format", `This browser cannot write ${IMAGE_MIME_TYPE} to the clipboard.`);
|
|
174
|
+
const blob = resolveImageBlob(source);
|
|
175
|
+
blob.catch(noop);
|
|
176
|
+
try {
|
|
177
|
+
await rich.write([new rich.Item({ [IMAGE_MIME_TYPE]: blob })]);
|
|
178
|
+
} catch (error) {
|
|
179
|
+
throw await blob.then(noop, (inner) => inner) ?? error;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
async function writeToClipboard(payload, env, degradeHtmlToText) {
|
|
183
|
+
if (!env) throw fail("unsupported", "No browser environment: the clipboard only exists in the browser.");
|
|
184
|
+
if (env.isSecureContext === false) throw fail("insecure-context", "The Clipboard API requires a secure context (HTTPS or localhost).");
|
|
185
|
+
const clipboard = env.navigator?.clipboard;
|
|
186
|
+
if (!clipboard) throw fail("unsupported", "navigator.clipboard is not available in this browser.");
|
|
187
|
+
switch (payload.kind) {
|
|
188
|
+
case "text": return writeText(clipboard, payload.value);
|
|
189
|
+
case "json": return writeText(clipboard, serializeJson(payload));
|
|
190
|
+
case "html": {
|
|
191
|
+
const rich = getRichClipboard(env, clipboard);
|
|
192
|
+
if (!rich || !isTypeSupported(rich.Item, "text/html")) {
|
|
193
|
+
if (degradeHtmlToText) return writeText(clipboard, payload.text);
|
|
194
|
+
throw fail("unsupported-format", "Rich HTML copy requires ClipboardItem and navigator.clipboard.write().");
|
|
195
|
+
}
|
|
196
|
+
return rich.write([new rich.Item({
|
|
197
|
+
"text/html": new Blob([payload.html], { type: "text/html" }),
|
|
198
|
+
"text/plain": new Blob([payload.text], { type: "text/plain" })
|
|
199
|
+
})]);
|
|
200
|
+
}
|
|
201
|
+
case "image": {
|
|
202
|
+
const rich = getRichClipboard(env, clipboard);
|
|
203
|
+
if (!rich) throw fail("unsupported-format", "Image copy requires ClipboardItem and navigator.clipboard.write().");
|
|
204
|
+
return writeImage(rich, payload.blob);
|
|
205
|
+
}
|
|
206
|
+
case "multi": {
|
|
207
|
+
const rich = getRichClipboard(env, clipboard);
|
|
208
|
+
if (!rich) throw fail("unsupported-format", "Multi-format copy requires ClipboardItem and navigator.clipboard.write().");
|
|
209
|
+
const record = {};
|
|
210
|
+
for (const { mimeType, data } of payload.items) {
|
|
211
|
+
if (!isTypeSupported(rich.Item, mimeType)) throw fail("unsupported-format", `This browser cannot write "${mimeType}" to the clipboard.`);
|
|
212
|
+
record[mimeType] = typeof data === "string" ? new Blob([data], { type: mimeType }) : data;
|
|
213
|
+
}
|
|
214
|
+
return rich.write([new rich.Item(record)]);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
/** The default adapter: async Clipboard API with feature detection and honest errors. */
|
|
219
|
+
function createBrowserClipboardAdapter(options = {}) {
|
|
220
|
+
const getEnvironment = options.getEnvironment ?? defaultEnvironment;
|
|
221
|
+
const degradeHtmlToText = options.degradeHtmlToText ?? true;
|
|
222
|
+
return { write: (payload) => writeToClipboard(payload, getEnvironment(), degradeHtmlToText) };
|
|
223
|
+
}
|
|
224
|
+
//#endregion
|
|
225
|
+
//#region src/core/copy-machine.ts
|
|
226
|
+
const DEFAULT_RESET_AFTER_MS = 2e3;
|
|
227
|
+
const DEFAULT_MAX_RETRIES = 3;
|
|
228
|
+
const IDLE_STATE = /* @__PURE__ */ Object.freeze({ status: "idle" });
|
|
229
|
+
const IGNORED_IN_FLIGHT = /* @__PURE__ */ Object.freeze({
|
|
230
|
+
status: "ignored",
|
|
231
|
+
reason: "in-flight"
|
|
232
|
+
});
|
|
233
|
+
const IGNORED_NOTHING = /* @__PURE__ */ Object.freeze({
|
|
234
|
+
status: "ignored",
|
|
235
|
+
reason: "nothing-to-retry"
|
|
236
|
+
});
|
|
237
|
+
const IGNORED_NOT_RETRYABLE = /* @__PURE__ */ Object.freeze({
|
|
238
|
+
status: "ignored",
|
|
239
|
+
reason: "not-retryable"
|
|
240
|
+
});
|
|
241
|
+
function resolveMaxRetries(value) {
|
|
242
|
+
if (value === Infinity) return Infinity;
|
|
243
|
+
if (value === void 0 || !Number.isFinite(value)) return 3;
|
|
244
|
+
return Math.max(0, Math.floor(value));
|
|
245
|
+
}
|
|
246
|
+
function resolveResetDelay(value) {
|
|
247
|
+
if (value === false || value === Infinity) return null;
|
|
248
|
+
if (value === void 0 || Number.isNaN(value)) return DEFAULT_RESET_AFTER_MS;
|
|
249
|
+
return Math.max(0, value);
|
|
250
|
+
}
|
|
251
|
+
/** Pure helper: can `retry()` do anything from this state? */
|
|
252
|
+
function canRetryState(state, maxRetries) {
|
|
253
|
+
return state.status === "error" && state.payload !== null && isRetryableError(state.error) && state.retryCount < resolveMaxRetries(maxRetries);
|
|
254
|
+
}
|
|
255
|
+
function reportCallbackError(error) {
|
|
256
|
+
const scope = globalThis;
|
|
257
|
+
if (typeof scope.reportError === "function") scope.reportError(error);
|
|
258
|
+
else setTimeout(() => {
|
|
259
|
+
throw error;
|
|
260
|
+
}, 0);
|
|
261
|
+
}
|
|
262
|
+
/** User callbacks must never corrupt machine state; their errors are reported, not swallowed. */
|
|
263
|
+
function invoke(fn, ...args) {
|
|
264
|
+
if (!fn) return;
|
|
265
|
+
try {
|
|
266
|
+
fn(...args);
|
|
267
|
+
} catch (error) {
|
|
268
|
+
reportCallbackError(error);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
let defaultAdapter;
|
|
272
|
+
const getDefaultAdapter = () => defaultAdapter ?? (defaultAdapter = createBrowserClipboardAdapter());
|
|
273
|
+
/** Framework-agnostic copy state machine. */
|
|
274
|
+
function createCopyMachine(options = {}) {
|
|
275
|
+
const read = typeof options === "function" ? options : () => options;
|
|
276
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
277
|
+
let state = IDLE_STATE;
|
|
278
|
+
let generation = 0;
|
|
279
|
+
let resetTimer;
|
|
280
|
+
const now = () => (read().now ?? Date.now)();
|
|
281
|
+
const setState = (next) => {
|
|
282
|
+
if (next === state) return;
|
|
283
|
+
state = next;
|
|
284
|
+
for (const listener of Array.from(listeners)) listener();
|
|
285
|
+
};
|
|
286
|
+
const clearResetTimer = () => {
|
|
287
|
+
if (resetTimer !== void 0) {
|
|
288
|
+
clearTimeout(resetTimer);
|
|
289
|
+
resetTimer = void 0;
|
|
290
|
+
}
|
|
291
|
+
};
|
|
292
|
+
const scheduleReset = (copied) => {
|
|
293
|
+
clearResetTimer();
|
|
294
|
+
const delay = resolveResetDelay(read().resetAfterMs);
|
|
295
|
+
if (delay === null) return;
|
|
296
|
+
const remaining = Math.max(0, delay - (now() - copied.at));
|
|
297
|
+
resetTimer = setTimeout(() => {
|
|
298
|
+
resetTimer = void 0;
|
|
299
|
+
if (state === copied) setState(IDLE_STATE);
|
|
300
|
+
}, remaining);
|
|
301
|
+
};
|
|
302
|
+
const settleError = (error, payload, retryCount) => {
|
|
303
|
+
setState({
|
|
304
|
+
status: "error",
|
|
305
|
+
payload,
|
|
306
|
+
error,
|
|
307
|
+
retryCount
|
|
308
|
+
});
|
|
309
|
+
invoke(read().onError, error, payload);
|
|
310
|
+
};
|
|
311
|
+
const run = (source, retryCount) => {
|
|
312
|
+
clearResetTimer();
|
|
313
|
+
const current = ++generation;
|
|
314
|
+
let payload;
|
|
315
|
+
try {
|
|
316
|
+
payload = normalizePayload(typeof source === "function" ? source() : source);
|
|
317
|
+
} catch (cause) {
|
|
318
|
+
const error = createCopyError("invalid-payload", "The copy source function threw.", cause);
|
|
319
|
+
settleError(error, null, retryCount);
|
|
320
|
+
return Promise.resolve({
|
|
321
|
+
status: "error",
|
|
322
|
+
error
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
const invalid = validatePayload(payload);
|
|
326
|
+
if (invalid) {
|
|
327
|
+
settleError(invalid, payload, retryCount);
|
|
328
|
+
return Promise.resolve({
|
|
329
|
+
status: "error",
|
|
330
|
+
error: invalid
|
|
331
|
+
});
|
|
332
|
+
}
|
|
333
|
+
setState({
|
|
334
|
+
status: "copying",
|
|
335
|
+
payload,
|
|
336
|
+
retryCount
|
|
337
|
+
});
|
|
338
|
+
let pending;
|
|
339
|
+
try {
|
|
340
|
+
pending = (read().adapter ?? getDefaultAdapter()).write(payload);
|
|
341
|
+
} catch (cause) {
|
|
342
|
+
pending = Promise.reject(cause);
|
|
343
|
+
}
|
|
344
|
+
return pending.then(() => {
|
|
345
|
+
if (current === generation) {
|
|
346
|
+
const copied = {
|
|
347
|
+
status: "copied",
|
|
348
|
+
payload,
|
|
349
|
+
at: now()
|
|
350
|
+
};
|
|
351
|
+
setState(copied);
|
|
352
|
+
scheduleReset(copied);
|
|
353
|
+
invoke(read().onCopy, payload);
|
|
354
|
+
}
|
|
355
|
+
return {
|
|
356
|
+
status: "copied",
|
|
357
|
+
payload
|
|
358
|
+
};
|
|
359
|
+
}, (cause) => {
|
|
360
|
+
const error = toCopyError(cause);
|
|
361
|
+
if (current === generation) settleError(error, payload, retryCount);
|
|
362
|
+
return {
|
|
363
|
+
status: "error",
|
|
364
|
+
error
|
|
365
|
+
};
|
|
366
|
+
});
|
|
367
|
+
};
|
|
368
|
+
const copy = (source) => state.status === "copying" ? Promise.resolve(IGNORED_IN_FLIGHT) : run(source, 0);
|
|
369
|
+
const retry = () => {
|
|
370
|
+
if (state.status !== "error") return Promise.resolve(IGNORED_NOTHING);
|
|
371
|
+
if (state.payload === null || !isRetryableError(state.error)) return Promise.resolve(IGNORED_NOT_RETRYABLE);
|
|
372
|
+
if (state.retryCount >= resolveMaxRetries(read().maxRetries)) {
|
|
373
|
+
const error = createCopyError("max-retries-exceeded", `Copy failed after ${String(state.retryCount)} retries.`, state.error);
|
|
374
|
+
settleError(error, state.payload, state.retryCount);
|
|
375
|
+
return Promise.resolve({
|
|
376
|
+
status: "error",
|
|
377
|
+
error
|
|
378
|
+
});
|
|
379
|
+
}
|
|
380
|
+
return run(state.payload, state.retryCount + 1);
|
|
381
|
+
};
|
|
382
|
+
const reset = () => {
|
|
383
|
+
++generation;
|
|
384
|
+
clearResetTimer();
|
|
385
|
+
setState(IDLE_STATE);
|
|
386
|
+
};
|
|
387
|
+
const connect = () => {
|
|
388
|
+
if (state.status === "copied") scheduleReset(state);
|
|
389
|
+
return () => {
|
|
390
|
+
++generation;
|
|
391
|
+
clearResetTimer();
|
|
392
|
+
if (state.status === "copying") setState(IDLE_STATE);
|
|
393
|
+
};
|
|
394
|
+
};
|
|
395
|
+
return {
|
|
396
|
+
getSnapshot: () => state,
|
|
397
|
+
subscribe: (listener) => {
|
|
398
|
+
listeners.add(listener);
|
|
399
|
+
return () => {
|
|
400
|
+
listeners.delete(listener);
|
|
401
|
+
};
|
|
402
|
+
},
|
|
403
|
+
copy,
|
|
404
|
+
retry,
|
|
405
|
+
reset,
|
|
406
|
+
connect
|
|
407
|
+
};
|
|
408
|
+
}
|
|
409
|
+
//#endregion
|
|
410
|
+
exports.CopyFailure = CopyFailure;
|
|
411
|
+
exports.DEFAULT_MAX_RETRIES = DEFAULT_MAX_RETRIES;
|
|
412
|
+
exports.DEFAULT_RESET_AFTER_MS = DEFAULT_RESET_AFTER_MS;
|
|
413
|
+
exports.IDLE_STATE = IDLE_STATE;
|
|
414
|
+
exports.IMAGE_MIME_TYPE = IMAGE_MIME_TYPE;
|
|
415
|
+
exports.canRetryState = canRetryState;
|
|
416
|
+
exports.createBrowserClipboardAdapter = createBrowserClipboardAdapter;
|
|
417
|
+
exports.createCopyError = createCopyError;
|
|
418
|
+
exports.createCopyMachine = createCopyMachine;
|
|
419
|
+
exports.describeCopyError = describeCopyError;
|
|
420
|
+
exports.isBlob = isBlob;
|
|
421
|
+
exports.isCopyFailure = isCopyFailure;
|
|
422
|
+
exports.isRetryableError = isRetryableError;
|
|
423
|
+
exports.normalizePayload = normalizePayload;
|
|
424
|
+
exports.resolveMaxRetries = resolveMaxRetries;
|
|
425
|
+
exports.serializeJson = serializeJson;
|
|
426
|
+
exports.toCopyError = toCopyError;
|
|
427
|
+
exports.validatePayload = validatePayload;
|
|
428
|
+
|
|
429
|
+
//# sourceMappingURL=core.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core.cjs","names":[],"sources":["../src/core/errors.ts","../src/core/payload.ts","../src/core/clipboard-adapter.ts","../src/core/copy-machine.ts"],"sourcesContent":["/**\n * Every way a copy can fail, as a closed union.\n *\n * `CopyError.message` is developer-facing (logs, telemetry). For user-facing\n * text use {@link describeCopyError} or map `type` through your own i18n layer.\n */\nexport type CopyErrorType =\n /** No Clipboard API (old browser, server, locked-down webview). Not retryable. */\n | 'unsupported'\n /** Page is not served over HTTPS/localhost. Not retryable. */\n | 'insecure-context'\n /** Browser or user blocked the write. Also what Safari reports for a missing user gesture. */\n | 'permission-denied'\n /** The document lost focus mid-copy (Chromium). Retrying after refocus usually works. */\n | 'not-focused'\n /** Empty or malformed payload, or a lazy source that threw. Caught before touching the clipboard. */\n | 'invalid-payload'\n /** The browser cannot write this MIME type (e.g. non-PNG image, HTML without ClipboardItem). */\n | 'unsupported-format'\n /** A lazy image source threw, rejected or did not produce a Blob. */\n | 'blob-generation-failed'\n /** `retry()` was called after `maxRetries` was reached. Terminal. */\n | 'max-retries-exceeded'\n /** Anything the platform threw that we could not classify. */\n | 'unknown';\n\nexport interface CopyError {\n readonly type: CopyErrorType;\n readonly message: string;\n readonly cause?: unknown;\n}\n\nexport function createCopyError(type: CopyErrorType, message: string, cause?: unknown): CopyError {\n return cause === undefined ? { type, message } : { type, message, cause };\n}\n\nconst RETRYABLE_ERRORS: ReadonlySet<CopyErrorType> = /* @__PURE__ */ new Set<CopyErrorType>([\n 'permission-denied',\n 'not-focused',\n 'blob-generation-failed',\n 'unknown',\n]);\n\n/** Whether retrying the same payload could plausibly succeed. */\nexport function isRetryableError(error: CopyError): boolean {\n return RETRYABLE_ERRORS.has(error.type);\n}\n\n/**\n * Branded (not `instanceof`) so failures stay recognisable even when the core\n * is bundled twice, e.g. `react-smart-copy` and `react-smart-copy/core` together.\n */\nconst COPY_FAILURE_BRAND = Symbol.for('react-smart-copy.CopyFailure');\n\n/** Error thrown by adapters to carry a fully classified {@link CopyError}. */\nexport class CopyFailure extends Error {\n readonly copyError: CopyError;\n readonly [COPY_FAILURE_BRAND] = true;\n\n constructor(copyError: CopyError) {\n super(copyError.message);\n this.name = 'CopyFailure';\n this.copyError = copyError;\n }\n}\n\nexport function isCopyFailure(value: unknown): value is CopyFailure {\n return (\n typeof value === 'object' &&\n value !== null &&\n (value as Record<PropertyKey, unknown>)[COPY_FAILURE_BRAND] === true\n );\n}\n\nfunction readString(value: unknown, key: string): string | undefined {\n if (typeof value !== 'object' || value === null) return undefined;\n const field = (value as Record<string, unknown>)[key];\n return typeof field === 'string' ? field : undefined;\n}\n\n/** Classifies anything thrown by the platform or an adapter into a {@link CopyError}. */\nexport function toCopyError(cause: unknown): CopyError {\n if (isCopyFailure(cause)) return cause.copyError;\n\n const name = readString(cause, 'name');\n const message = readString(cause, 'message') ?? '';\n\n switch (name) {\n case 'NotAllowedError':\n return /focus/i.test(message)\n ? createCopyError('not-focused', 'The document was not focused when the copy was attempted.', cause)\n : createCopyError('permission-denied', 'Clipboard write permission was denied.', cause);\n case 'SecurityError':\n return createCopyError('insecure-context', 'The clipboard is blocked in this context.', cause);\n case 'NotSupportedError':\n case 'DataError':\n return createCopyError('unsupported-format', 'The browser rejected this clipboard format.', cause);\n default:\n return createCopyError('unknown', message || 'The copy failed for an unknown reason.', cause);\n }\n}\n\nconst DEFAULT_DESCRIPTIONS: Readonly<Record<CopyErrorType, string>> = {\n unsupported: \"Copying isn't supported in this browser.\",\n 'insecure-context': 'Copying requires a secure (HTTPS) connection.',\n 'permission-denied': 'Clipboard access was blocked. Allow it and try again.',\n 'not-focused': 'The page lost focus while copying. Try again.',\n 'invalid-payload': 'There is nothing to copy.',\n 'unsupported-format': \"This content can't be copied in this browser.\",\n 'blob-generation-failed': \"The image couldn't be prepared for copying.\",\n 'max-retries-exceeded': 'Copying failed after several attempts.',\n unknown: \"Couldn't copy to the clipboard. Try again.\",\n};\n\n/** Default English, user-facing sentence for an error. Replace for i18n. */\nexport function describeCopyError(error: CopyError): string {\n return DEFAULT_DESCRIPTIONS[error.type];\n}\n","import { CopyFailure, createCopyError, type CopyError } from './errors';\n\n/** The only image MIME type with reliable cross-browser clipboard write support. */\nexport const IMAGE_MIME_TYPE = 'image/png';\n\n/**\n * An image as a Blob, a promise of one, or a function producing one.\n * Prefer the function form: it is invoked synchronously inside the user\n * gesture, which Safari requires for async image generation.\n */\nexport type BlobSource = Blob | PromiseLike<Blob> | (() => Blob | PromiseLike<Blob>);\n\nexport interface TextPayload {\n readonly kind: 'text';\n readonly value: string;\n}\n\nexport interface HtmlPayload {\n readonly kind: 'html';\n readonly html: string;\n /** Required plain-text fallback for targets that don't understand HTML. */\n readonly text: string;\n}\n\nexport interface ImagePayload {\n readonly kind: 'image';\n readonly blob: BlobSource;\n}\n\nexport interface JsonPayload {\n readonly kind: 'json';\n readonly value: unknown;\n /** `true` = 2-space indent, a number = that indent, falsy = compact. */\n readonly pretty?: boolean | number;\n}\n\nexport interface MultiPayloadItem {\n readonly mimeType: string;\n readonly data: string | Blob;\n}\n\nexport interface MultiPayload {\n readonly kind: 'multi';\n readonly items: readonly MultiPayloadItem[];\n}\n\nexport type CopyPayload = TextPayload | HtmlPayload | ImagePayload | JsonPayload | MultiPayload;\nexport type CopyPayloadKind = CopyPayload['kind'];\n\n/** A payload, or a bare string as shorthand for `{ kind: 'text' }`. */\nexport type CopyInput = string | CopyPayload;\n\n/**\n * What `copy()` accepts. The function form is resolved synchronously at copy\n * time, so it always reads the latest value without re-rendering.\n */\nexport type CopySource = CopyInput | (() => CopyInput);\n\nexport function normalizePayload(input: CopyInput): CopyPayload {\n return typeof input === 'string' ? { kind: 'text', value: input } : input;\n}\n\nexport function isBlob(value: unknown): value is Blob {\n if (typeof Blob !== 'undefined' && value instanceof Blob) return true;\n const tag = Object.prototype.toString.call(value);\n return tag === '[object Blob]' || tag === '[object File]';\n}\n\nfunction isThenable(value: unknown): value is PromiseLike<unknown> {\n return (\n (typeof value === 'object' || typeof value === 'function') &&\n value !== null &&\n typeof (value as { then?: unknown }).then === 'function'\n );\n}\n\nconst invalid = (message: string): CopyError => createCopyError('invalid-payload', message);\n\n/**\n * Structural validation. Typed callers can't produce most of these states,\n * but plain-JS callers and runtime data can, so the check is always on.\n */\nexport function validatePayload(payload: unknown): CopyError | null {\n if (typeof payload !== 'object' || payload === null) {\n return invalid('Copy input must be a string or a payload object.');\n }\n const candidate = payload as Record<string, unknown>;\n\n switch (candidate['kind']) {\n case 'text':\n return typeof candidate['value'] === 'string' && candidate['value'].length > 0\n ? null\n : invalid('Text payload must be a non-empty string.');\n case 'html':\n if (typeof candidate['html'] !== 'string' || candidate['html'].length === 0) {\n return invalid('HTML payload requires a non-empty `html` string.');\n }\n return typeof candidate['text'] === 'string' && candidate['text'].length > 0\n ? null\n : invalid('HTML payload requires a non-empty plain-text `text` fallback.');\n case 'image': {\n const source = candidate['blob'];\n return isBlob(source) || typeof source === 'function' || isThenable(source)\n ? null\n : invalid('Image payload requires a Blob, a Promise<Blob> or a function returning one.');\n }\n case 'json':\n return candidate['value'] === undefined ? invalid('JSON payload value is undefined.') : null;\n case 'multi': {\n const items = candidate['items'];\n if (!Array.isArray(items) || items.length === 0) {\n return invalid('Multi payload requires at least one item.');\n }\n const seen = new Set<string>();\n for (const item of items as unknown[]) {\n const entry = (typeof item === 'object' && item !== null ? item : {}) as Record<string, unknown>;\n const mimeType = entry['mimeType'];\n const data = entry['data'];\n if (typeof mimeType !== 'string' || mimeType.length === 0) {\n return invalid('Every multi item needs a non-empty `mimeType`.');\n }\n if (seen.has(mimeType)) return invalid(`Duplicate MIME type \"${mimeType}\" in multi payload.`);\n seen.add(mimeType);\n if (typeof data !== 'string' && !isBlob(data)) {\n return invalid(`Multi item \"${mimeType}\" must contain a string or a Blob.`);\n }\n }\n return null;\n }\n default:\n return invalid(`Unknown payload kind: ${String(candidate['kind'])}.`);\n }\n}\n\n/** Serialises a JSON payload, throwing a classified failure instead of a raw TypeError. */\nexport function serializeJson(payload: JsonPayload): string {\n const indent =\n payload.pretty === true ? 2 : typeof payload.pretty === 'number' ? payload.pretty : undefined;\n // Typed as `string` by lib.d.ts, but returns undefined for functions, symbols and undefined.\n let text: unknown;\n try {\n text = JSON.stringify(payload.value, null, indent);\n } catch (cause) {\n throw new CopyFailure(\n createCopyError('invalid-payload', 'JSON payload could not be serialised (circular reference or BigInt?).', cause),\n );\n }\n if (typeof text !== 'string') {\n throw new CopyFailure(\n createCopyError('invalid-payload', 'JSON payload serialised to nothing (functions, symbols and undefined are not JSON).'),\n );\n }\n return text;\n}\n","import { CopyFailure, createCopyError, type CopyErrorType } from './errors';\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 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.\n */\nexport interface ClipboardAdapter {\n write(payload: CopyPayload): 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\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\nfunction writeText(clipboard: ClipboardLike, text: string): Promise<void> {\n if (typeof clipboard.writeText !== 'function') {\n throw fail('unsupported', 'navigator.clipboard.writeText() is not available.');\n }\n return clipboard.writeText(text);\n}\n\nasync function resolveImageBlob(source: BlobSource): 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() : source);\n } catch (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(rich: RichClipboard, source: BlobSource): 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);\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}\n\nasync function writeToClipboard(\n payload: CopyPayload,\n env: ClipboardEnvironment | undefined,\n degradeHtmlToText: boolean,\n): Promise<void> {\n if (!env) throw fail('unsupported', 'No browser environment: the clipboard only exists in the browser.');\n if (env.isSecureContext === false) {\n throw fail('insecure-context', 'The Clipboard API requires a secure context (HTTPS or localhost).');\n }\n const clipboard = env.navigator?.clipboard;\n if (!clipboard) throw fail('unsupported', 'navigator.clipboard is not available in this browser.');\n\n switch (payload.kind) {\n case 'text':\n return writeText(clipboard, payload.value);\n\n case 'json':\n return writeText(clipboard, serializeJson(payload));\n\n case 'html': {\n const rich = getRichClipboard(env, clipboard);\n if (!rich || !isTypeSupported(rich.Item, 'text/html')) {\n if (degradeHtmlToText) return writeText(clipboard, payload.text);\n throw fail('unsupported-format', 'Rich HTML copy requires ClipboardItem and navigator.clipboard.write().');\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);\n }\n\n case 'multi': {\n const rich = getRichClipboard(env, clipboard);\n if (!rich) throw fail('unsupported-format', 'Multi-format copy requires ClipboardItem and navigator.clipboard.write().');\n const record: Record<string, ClipboardItemData> = {};\n for (const { mimeType, data } of payload.items) {\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 }\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 degradeHtmlToText = options.degradeHtmlToText ?? true;\n return {\n write: (payload) => writeToClipboard(payload, getEnvironment(), degradeHtmlToText),\n };\n}\n","import { createBrowserClipboardAdapter, type ClipboardAdapter } from './clipboard-adapter';\nimport { createCopyError, isRetryableError, toCopyError, type CopyError } from './errors';\nimport { normalizePayload, validatePayload, type CopyPayload, type CopySource } from './payload';\n\nexport const DEFAULT_RESET_AFTER_MS = 2000;\nexport const DEFAULT_MAX_RETRIES = 3;\n\nexport interface IdleState {\n readonly status: 'idle';\n}\nexport interface CopyingState {\n readonly status: 'copying';\n readonly payload: CopyPayload;\n readonly retryCount: number;\n}\nexport interface CopiedState {\n readonly status: 'copied';\n readonly payload: CopyPayload;\n /** Epoch ms when the write resolved. */\n readonly at: number;\n}\nexport interface ErrorState {\n readonly status: 'error';\n /** `null` when the input itself could not be resolved. */\n readonly payload: CopyPayload | null;\n readonly error: CopyError;\n readonly retryCount: number;\n}\n\nexport type CopyState = IdleState | CopyingState | CopiedState | ErrorState;\nexport type CopyStatus = CopyState['status'];\n\nexport type CopyIgnoredReason = 'in-flight' | 'nothing-to-retry' | 'not-retryable';\n\n/** What `copy()`/`retry()` resolve to. They never reject. */\nexport type CopyOutcome =\n | { readonly status: 'copied'; readonly payload: CopyPayload }\n | { readonly status: 'error'; readonly error: CopyError }\n | { readonly status: 'ignored'; readonly reason: CopyIgnoredReason };\n\nexport interface CopyMachineOptions {\n /** Defaults to the browser Clipboard API adapter. */\n readonly adapter?: ClipboardAdapter;\n /** Time in `copied` before returning to `idle`. `false`/`Infinity` disables. Default 2000. */\n readonly resetAfterMs?: number | false;\n /** Max `retry()` calls after the first failure. Default 3. */\n readonly maxRetries?: number;\n readonly onCopy?: (payload: CopyPayload) => void;\n readonly onError?: (error: CopyError, payload: CopyPayload | null) => void;\n /** Clock injection for tests and deterministic environments. */\n readonly now?: () => number;\n}\n\n/** Options object, or a getter so hosts (like React) can supply the latest options. */\nexport type CopyMachineOptionsSource = CopyMachineOptions | (() => CopyMachineOptions);\n\nexport interface CopyMachine {\n readonly getSnapshot: () => CopyState;\n readonly subscribe: (listener: () => void) => () => void;\n readonly copy: (source: CopySource) => Promise<CopyOutcome>;\n readonly retry: () => Promise<CopyOutcome>;\n readonly reset: () => void;\n /**\n * Lifecycle hook for hosts. Re-arms a pending auto-reset; the returned\n * cleanup clears timers, drops in-flight results and unsticks `copying`.\n * Safe to call repeatedly (React StrictMode).\n */\n readonly connect: () => () => void;\n}\n\nexport const IDLE_STATE: IdleState = /* @__PURE__ */ Object.freeze({ status: 'idle' });\n\nconst IGNORED_IN_FLIGHT: CopyOutcome = /* @__PURE__ */ Object.freeze({ status: 'ignored', reason: 'in-flight' });\nconst IGNORED_NOTHING: CopyOutcome = /* @__PURE__ */ Object.freeze({ status: 'ignored', reason: 'nothing-to-retry' });\nconst IGNORED_NOT_RETRYABLE: CopyOutcome = /* @__PURE__ */ Object.freeze({ status: 'ignored', reason: 'not-retryable' });\n\nexport function resolveMaxRetries(value: number | undefined): number {\n if (value === Infinity) return Infinity;\n if (value === undefined || !Number.isFinite(value)) return DEFAULT_MAX_RETRIES;\n return Math.max(0, Math.floor(value));\n}\n\nfunction resolveResetDelay(value: number | false | undefined): number | null {\n if (value === false || value === Infinity) return null;\n if (value === undefined || Number.isNaN(value)) return DEFAULT_RESET_AFTER_MS;\n return Math.max(0, value);\n}\n\n/** Pure helper: can `retry()` do anything from this state? */\nexport function canRetryState(state: CopyState, maxRetries?: number): boolean {\n return (\n state.status === 'error' &&\n state.payload !== null &&\n isRetryableError(state.error) &&\n state.retryCount < resolveMaxRetries(maxRetries)\n );\n}\n\nfunction reportCallbackError(error: unknown): void {\n const scope = globalThis as { reportError?: (error: unknown) => void };\n if (typeof scope.reportError === 'function') {\n scope.reportError(error);\n } else {\n setTimeout(() => {\n throw error;\n }, 0);\n }\n}\n\n/** User callbacks must never corrupt machine state; their errors are reported, not swallowed. */\nfunction invoke<Args extends unknown[]>(fn: ((...args: Args) => void) | undefined, ...args: Args): void {\n if (!fn) return;\n try {\n fn(...args);\n } catch (error) {\n reportCallbackError(error);\n }\n}\n\nlet defaultAdapter: ClipboardAdapter | undefined;\nconst getDefaultAdapter = (): ClipboardAdapter => (defaultAdapter ??= createBrowserClipboardAdapter());\n\n/** Framework-agnostic copy state machine. */\nexport function createCopyMachine(options: CopyMachineOptionsSource = {}): CopyMachine {\n const read = typeof options === 'function' ? options : (): CopyMachineOptions => options;\n const listeners = new Set<() => void>();\n let state: CopyState = IDLE_STATE;\n let generation = 0;\n let resetTimer: ReturnType<typeof setTimeout> | undefined;\n\n const now = (): number => (read().now ?? Date.now)();\n\n const setState = (next: CopyState): void => {\n if (next === state) return;\n state = next;\n for (const listener of Array.from(listeners)) listener();\n };\n\n const clearResetTimer = (): void => {\n if (resetTimer !== undefined) {\n clearTimeout(resetTimer);\n resetTimer = undefined;\n }\n };\n\n const scheduleReset = (copied: CopiedState): void => {\n clearResetTimer();\n const delay = resolveResetDelay(read().resetAfterMs);\n if (delay === null) return;\n const remaining = Math.max(0, delay - (now() - copied.at));\n resetTimer = setTimeout(() => {\n resetTimer = undefined;\n if (state === copied) setState(IDLE_STATE);\n }, remaining);\n };\n\n const settleError = (error: CopyError, payload: CopyPayload | null, retryCount: number): void => {\n setState({ status: 'error', payload, error, retryCount });\n invoke(read().onError, error, payload);\n };\n\n const run = (source: CopySource, retryCount: number): Promise<CopyOutcome> => {\n clearResetTimer();\n const current = ++generation;\n\n let payload: CopyPayload;\n try {\n payload = normalizePayload(typeof source === 'function' ? source() : source);\n } catch (cause) {\n const error = createCopyError('invalid-payload', 'The copy source function threw.', cause);\n settleError(error, null, retryCount);\n return Promise.resolve({ status: 'error', error });\n }\n\n const invalid = validatePayload(payload);\n if (invalid) {\n settleError(invalid, payload, retryCount);\n return Promise.resolve({ status: 'error', error: invalid });\n }\n\n setState({ status: 'copying', payload, retryCount });\n\n // The adapter is called synchronously: no await may precede it, or the\n // browser loses the transient user activation and rejects the write.\n let pending: Promise<void>;\n try {\n pending = (read().adapter ?? getDefaultAdapter()).write(payload);\n } catch (cause) {\n // Keep the raw reason: toCopyError() classifies it (DOMException names, CopyFailure brand).\n // eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors\n pending = Promise.reject(cause);\n }\n\n return pending.then(\n (): CopyOutcome => {\n if (current === generation) {\n const copied: CopiedState = { status: 'copied', payload, at: now() };\n setState(copied);\n scheduleReset(copied);\n invoke(read().onCopy, payload);\n }\n return { status: 'copied', payload };\n },\n (cause: unknown): CopyOutcome => {\n const error = toCopyError(cause);\n if (current === generation) settleError(error, payload, retryCount);\n return { status: 'error', error };\n },\n );\n };\n\n const copy = (source: CopySource): Promise<CopyOutcome> =>\n state.status === 'copying' ? Promise.resolve(IGNORED_IN_FLIGHT) : run(source, 0);\n\n const retry = (): Promise<CopyOutcome> => {\n if (state.status !== 'error') return Promise.resolve(IGNORED_NOTHING);\n if (state.payload === null || !isRetryableError(state.error)) return Promise.resolve(IGNORED_NOT_RETRYABLE);\n\n if (state.retryCount >= resolveMaxRetries(read().maxRetries)) {\n const error = createCopyError(\n 'max-retries-exceeded',\n `Copy failed after ${String(state.retryCount)} retries.`,\n state.error,\n );\n settleError(error, state.payload, state.retryCount);\n return Promise.resolve({ status: 'error', error });\n }\n return run(state.payload, state.retryCount + 1);\n };\n\n const reset = (): void => {\n ++generation;\n clearResetTimer();\n setState(IDLE_STATE);\n };\n\n const connect = (): (() => void) => {\n if (state.status === 'copied') scheduleReset(state);\n return () => {\n ++generation;\n clearResetTimer();\n if (state.status === 'copying') setState(IDLE_STATE);\n };\n };\n\n return {\n getSnapshot: () => state,\n subscribe: (listener) => {\n listeners.add(listener);\n return () => {\n listeners.delete(listener);\n };\n },\n copy,\n retry,\n reset,\n connect,\n };\n}\n"],"mappings":";;AAgCA,SA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