@protonradio/proton-ui 0.11.18-beta.1 → 0.11.18-beta.3
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/dist/utils/copy.cjs.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=async(o,c)=>{let e=!1;const n=l=>{const t=l instanceof Error?l.message:"Failed to copy to clipboard";console.error(t),c==null||c(new Error(t))};if(typeof navigator<"u"&&navigator.clipboard&&typeof navigator.clipboard.writeText=="function"){console.log("clipboard API IS available, using clipboard API",{navigator});try{await navigator.clipboard.writeText(o),e=!0}catch(l){console.log("clipboard API failed, trying fallback",{error:l});try{e=i(o),e||(console.log("fallback unsuccessful, calling onErrorCallback",{error:l}),n(l))}catch(t){console.log("fallback errored, calling onErrorCallback",{fallbackError:t}),n(t)}}}else{console.log("clipboard API NOT available, using fallback");try{e=i(o),console.log("fallback result",{copySuccess:e,text:o}),e?console.log("fallback successful - copy should have worked"):(console.log("fallback unsuccessful, calling onErrorCallback",{copySuccess:e}),n(new Error("Failed to copy to clipboard: Clipboard API not available and fallback method failed. This may be due to browser security restrictions (e.g., iframe permissions, non-HTTPS context).")))}catch(l){console.log("fallback errored, calling onErrorCallback",{error:l}),n(l)}}return console.log("copyTextToClipboard final result",{copySuccess:e}),e},i=(o,{target:c=document.body}={})=>{if(typeof o!="string")throw new TypeError(`Expected parameter \`text\` to be a \`string\`, got \`${typeof o}\`.`);if(!document.execCommand)return console.error("document.execCommand is not available"),!1;const e=document.createElement("textarea"),n=document.activeElement;e.value=o,e.setAttribute("readonly",""),e.style.contain="strict",e.style.position="absolute",e.style.left="-9999px",e.style.top="-9999px",e.style.width="2em",e.style.height="2em",e.style.padding="0",e.style.border="none",e.style.outline="none",e.style.boxShadow="none",e.style.background="transparent",e.style.fontSize="12pt";const r=document.getSelection(),l=r.rangeCount>0&&r.getRangeAt(0);c.append(e),e.focus(),e.select();try{e.setSelectionRange(0,o.length)}catch(a){console.log("setSelectionRange failed (non-critical)",a)}let t=!1,s=null;try{const a=e.selectionStart===0&&e.selectionEnd===o.length;console.log("element selection state",{isSelected:a,selectionStart:e.selectionStart,selectionEnd:e.selectionEnd,textLength:o.length}),!a&&o.length>0&&(e.select(),e.setSelectionRange(0,o.length)),t=document.execCommand("copy"),console.log("document.execCommand('copy') result",{isSuccess:t,textLength:o.length}),t?console.log("execCommand returned true - copy should have succeeded"):console.warn("execCommand returned false - copy failed")}catch(a){s=a,console.error("document.execCommand('copy') threw an error",a)}return e.remove(),l&&(r.removeAllRanges(),r.addRange(l)),n instanceof HTMLElement&&n.focus(),s?(console.error("execCommand error",s),!1):t};exports.copyTextToClipboard=d;
|
|
2
2
|
//# sourceMappingURL=copy.cjs.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"copy.cjs.js","sources":["../../src/utils/copy.ts"],"sourcesContent":["export const copyTextToClipboard = async (\n text: string,\n onError?: (error: Error) => void\n): Promise<boolean> => {\n let copySuccess = false;\n
|
|
1
|
+
{"version":3,"file":"copy.cjs.js","sources":["../../src/utils/copy.ts"],"sourcesContent":["export const copyTextToClipboard = async (\n text: string,\n onError?: (error: Error) => void\n): Promise<boolean> => {\n let copySuccess = false;\n\n const onErrorCallback = (error: Error) => {\n const errorMessage =\n error instanceof Error ? error.message : \"Failed to copy to clipboard\";\n\n console.error(errorMessage);\n onError?.(new Error(errorMessage));\n };\n\n // Check if clipboard API is available\n // Note: navigator.clipboard may be undefined in non-secure contexts (non-HTTPS)\n const isClipboardAvailable =\n typeof navigator !== \"undefined\" &&\n navigator.clipboard &&\n typeof navigator.clipboard.writeText === \"function\";\n\n if (isClipboardAvailable) {\n console.log(\"clipboard API IS available, using clipboard API\", {\n navigator,\n });\n try {\n await navigator.clipboard.writeText(text);\n copySuccess = true;\n } catch (error) {\n // If clipboard API fails, try fallback\n\n console.log(\"clipboard API failed, trying fallback\", { error });\n try {\n copySuccess = DEPRECATED_copyTextToClipboard(text);\n\n if (!copySuccess) {\n console.log(\"fallback unsuccessful, calling onErrorCallback\", {\n error,\n });\n onErrorCallback(error);\n }\n } catch (fallbackError) {\n console.log(\"fallback errored, calling onErrorCallback\", {\n fallbackError,\n });\n onErrorCallback(fallbackError);\n }\n }\n } else {\n // Use fallback method when clipboard API is not available\n\n console.log(\"clipboard API NOT available, using fallback\");\n try {\n copySuccess = DEPRECATED_copyTextToClipboard(text);\n console.log(\"fallback result\", { copySuccess, text });\n if (!copySuccess) {\n console.log(\"fallback unsuccessful, calling onErrorCallback\", {\n copySuccess,\n });\n onErrorCallback(\n new Error(\n \"Failed to copy to clipboard: Clipboard API not available and fallback method failed. This may be due to browser security restrictions (e.g., iframe permissions, non-HTTPS context).\"\n )\n );\n } else {\n console.log(\"fallback successful - copy should have worked\");\n // Note: In some contexts (iframes, cross-origin), execCommand may return true\n // but the copy may still be blocked by the browser. There's no reliable way to verify.\n }\n } catch (error) {\n console.log(\"fallback errored, calling onErrorCallback\", { error });\n onErrorCallback(error);\n }\n }\n\n console.log(\"copyTextToClipboard final result\", { copySuccess });\n return copySuccess;\n};\n\n/**\n * Fallback legacy function to copy text to clipboard for browsers that don't support navigator.clipboard.writeText\n * @reference https://github.com/sindresorhus/copy-text-to-clipboard/blob/main/index.js\n * @deprecated Use navigator.clipboard.writeText instead\n */\nconst DEPRECATED_copyTextToClipboard = (\n text,\n { target = document.body } = {}\n) => {\n if (typeof text !== \"string\") {\n throw new TypeError(\n `Expected parameter \\`text\\` to be a \\`string\\`, got \\`${typeof text}\\`.`\n );\n }\n\n // Check if execCommand is available\n if (!document.execCommand) {\n console.error(\"document.execCommand is not available\");\n return false;\n }\n\n const element = document.createElement(\"textarea\");\n const previouslyFocusedElement = document.activeElement;\n\n element.value = text;\n\n // Prevent keyboard from showing on mobile\n element.setAttribute(\"readonly\", \"\");\n\n element.style.contain = \"strict\";\n element.style.position = \"absolute\";\n element.style.left = \"-9999px\";\n element.style.top = \"-9999px\";\n element.style.width = \"2em\";\n element.style.height = \"2em\";\n element.style.padding = \"0\";\n element.style.border = \"none\";\n element.style.outline = \"none\";\n element.style.boxShadow = \"none\";\n element.style.background = \"transparent\";\n element.style.fontSize = \"12pt\"; // Prevent zooming on iOS\n\n const selection = document.getSelection();\n const originalRange = selection.rangeCount > 0 && selection.getRangeAt(0);\n\n target.append(element);\n\n // Focus and select the element\n // Use setTimeout to ensure the element is in the DOM and can receive focus\n element.focus();\n element.select();\n\n // Explicit selection workaround for iOS and ensure selection is set\n try {\n element.setSelectionRange(0, text.length);\n } catch (e) {\n // setSelectionRange may fail on non-text inputs, but that's okay\n console.log(\"setSelectionRange failed (non-critical)\", e);\n }\n\n let isSuccess = false;\n let execCommandError = null;\n\n // Small delay to ensure the element is properly focused and selected\n // This is especially important in some browsers/contexts\n try {\n // Check if the element is actually selected\n const isSelected =\n element.selectionStart === 0 && element.selectionEnd === text.length;\n console.log(\"element selection state\", {\n isSelected,\n selectionStart: element.selectionStart,\n selectionEnd: element.selectionEnd,\n textLength: text.length,\n });\n\n if (!isSelected && text.length > 0) {\n // Try to select again\n element.select();\n element.setSelectionRange(0, text.length);\n }\n\n isSuccess = document.execCommand(\"copy\");\n console.log(\"document.execCommand('copy') result\", {\n isSuccess,\n textLength: text.length,\n });\n\n // Additional verification: check if execCommand actually worked\n // Some browsers return true even when copy fails\n if (isSuccess) {\n console.log(\"execCommand returned true - copy should have succeeded\");\n } else {\n console.warn(\"execCommand returned false - copy failed\");\n }\n } catch (error) {\n execCommandError = error;\n console.error(\"document.execCommand('copy') threw an error\", error);\n }\n\n // Verify the copy worked by checking if we can read back (if possible)\n // Note: This is a best-effort check since we can't always read clipboard\n\n element.remove();\n\n if (originalRange) {\n selection.removeAllRanges();\n selection.addRange(originalRange);\n }\n\n // Get the focus back on the previously focused element, if any\n if (previouslyFocusedElement instanceof HTMLElement) {\n previouslyFocusedElement.focus();\n }\n\n if (execCommandError) {\n console.error(\"execCommand error\", execCommandError);\n return false;\n }\n\n return isSuccess;\n};\n"],"names":["copyTextToClipboard","text","onError","copySuccess","onErrorCallback","error","errorMessage","DEPRECATED_copyTextToClipboard","fallbackError","target","element","previouslyFocusedElement","selection","originalRange","e","isSuccess","execCommandError","isSelected"],"mappings":"gFAAa,MAAAA,EAAsB,MACjCC,EACAC,IACqB,CACrB,IAAIC,EAAc,GAEZ,MAAAC,EAAmBC,GAAiB,CACxC,MAAMC,EACJD,aAAiB,MAAQA,EAAM,QAAU,8BAE3C,QAAQ,MAAMC,CAAY,EAChBJ,GAAA,MAAAA,EAAA,IAAI,MAAMI,CAAY,EAAC,EAUnC,GAJE,OAAO,UAAc,KACrB,UAAU,WACV,OAAO,UAAU,UAAU,WAAc,WAEjB,CACxB,QAAQ,IAAI,kDAAmD,CAC7D,SAAA,CACD,EACG,GAAA,CACI,MAAA,UAAU,UAAU,UAAUL,CAAI,EAC1BE,EAAA,SACPE,EAAO,CAGd,QAAQ,IAAI,wCAAyC,CAAE,MAAAA,CAAO,CAAA,EAC1D,GAAA,CACFF,EAAcI,EAA+BN,CAAI,EAE5CE,IACH,QAAQ,IAAI,iDAAkD,CAC5D,MAAAE,CAAA,CACD,EACDD,EAAgBC,CAAK,SAEhBG,EAAe,CACtB,QAAQ,IAAI,4CAA6C,CACvD,cAAAA,CAAA,CACD,EACDJ,EAAgBI,CAAa,CAC/B,CACF,CAAA,KACK,CAGL,QAAQ,IAAI,8CAA8C,EACtD,GAAA,CACFL,EAAcI,EAA+BN,CAAI,EACjD,QAAQ,IAAI,kBAAmB,CAAE,YAAAE,EAAa,KAAAF,CAAM,CAAA,EAC/CE,EAUH,QAAQ,IAAI,+CAA+C,GAT3D,QAAQ,IAAI,iDAAkD,CAC5D,YAAAA,CAAA,CACD,EACDC,EACE,IAAI,MACF,sLACF,CAAA,SAOGC,EAAO,CACd,QAAQ,IAAI,4CAA6C,CAAE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B,EAEG,CAACgB,GAAchB,EAAK,OAAS,IAE/BS,EAAQ,OAAO,EACPA,EAAA,kBAAkB,EAAGT,EAAK,MAAM,GAG9Bc,EAAA,SAAS,YAAY,MAAM,EACvC,QAAQ,IAAI,sCAAuC,CACjD,UAAAA,EACA,WAAYd,EAAK,MAAA,CAClB,EAIGc,EACF,QAAQ,IAAI,wDAAwD,EAEpE,QAAQ,KAAK,0CAA0C,QAElDV,EAAO,CACKW,EAAAX,EACX,QAAA,MAAM,8CAA+CA,CAAK,CACpE,CAiBA,OAZAK,EAAQ,OAAO,EAEXG,IACFD,EAAU,gBAAgB,EAC1BA,EAAU,SAASC,CAAa,GAI9BF,aAAoC,aACtCA,EAAyB,MAAM,EAG7BK,GACM,QAAA,MAAM,oBAAqBA,CAAgB,EAC5C,IAGFD,CACT"}
|
package/dist/utils/copy.es.js
CHANGED
|
@@ -1,32 +1,76 @@
|
|
|
1
|
-
const
|
|
1
|
+
const d = async (o, c) => {
|
|
2
2
|
let e = !1;
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
const t = (l) => {
|
|
4
|
+
const n = l instanceof Error ? l.message : "Failed to copy to clipboard";
|
|
5
|
+
console.error(n), c == null || c(new Error(n));
|
|
6
|
+
};
|
|
7
|
+
if (typeof navigator < "u" && navigator.clipboard && typeof navigator.clipboard.writeText == "function") {
|
|
8
|
+
console.log("clipboard API IS available, using clipboard API", {
|
|
9
|
+
navigator
|
|
10
|
+
});
|
|
5
11
|
try {
|
|
6
12
|
await navigator.clipboard.writeText(o), e = !0;
|
|
7
|
-
} catch (
|
|
8
|
-
|
|
13
|
+
} catch (l) {
|
|
14
|
+
console.log("clipboard API failed, trying fallback", { error: l });
|
|
15
|
+
try {
|
|
16
|
+
e = i(o), e || (console.log("fallback unsuccessful, calling onErrorCallback", {
|
|
17
|
+
error: l
|
|
18
|
+
}), t(l));
|
|
19
|
+
} catch (n) {
|
|
20
|
+
console.log("fallback errored, calling onErrorCallback", {
|
|
21
|
+
fallbackError: n
|
|
22
|
+
}), t(n);
|
|
23
|
+
}
|
|
9
24
|
}
|
|
10
|
-
} else
|
|
11
|
-
console.log("
|
|
12
|
-
|
|
13
|
-
|
|
25
|
+
} else {
|
|
26
|
+
console.log("clipboard API NOT available, using fallback");
|
|
27
|
+
try {
|
|
28
|
+
e = i(o), console.log("fallback result", { copySuccess: e, text: o }), e ? console.log("fallback successful - copy should have worked") : (console.log("fallback unsuccessful, calling onErrorCallback", {
|
|
29
|
+
copySuccess: e
|
|
30
|
+
}), t(
|
|
31
|
+
new Error(
|
|
32
|
+
"Failed to copy to clipboard: Clipboard API not available and fallback method failed. This may be due to browser security restrictions (e.g., iframe permissions, non-HTTPS context)."
|
|
33
|
+
)
|
|
34
|
+
));
|
|
35
|
+
} catch (l) {
|
|
36
|
+
console.log("fallback errored, calling onErrorCallback", { error: l }), t(l);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return console.log("copyTextToClipboard final result", { copySuccess: e }), e;
|
|
40
|
+
}, i = (o, { target: c = document.body } = {}) => {
|
|
14
41
|
if (typeof o != "string")
|
|
15
42
|
throw new TypeError(
|
|
16
43
|
`Expected parameter \`text\` to be a \`string\`, got \`${typeof o}\`.`
|
|
17
44
|
);
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
45
|
+
if (!document.execCommand)
|
|
46
|
+
return console.error("document.execCommand is not available"), !1;
|
|
47
|
+
const e = document.createElement("textarea"), t = document.activeElement;
|
|
48
|
+
e.value = o, e.setAttribute("readonly", ""), e.style.contain = "strict", e.style.position = "absolute", e.style.left = "-9999px", e.style.top = "-9999px", e.style.width = "2em", e.style.height = "2em", e.style.padding = "0", e.style.border = "none", e.style.outline = "none", e.style.boxShadow = "none", e.style.background = "transparent", e.style.fontSize = "12pt";
|
|
49
|
+
const r = document.getSelection(), l = r.rangeCount > 0 && r.getRangeAt(0);
|
|
50
|
+
c.append(e), e.focus(), e.select();
|
|
51
|
+
try {
|
|
52
|
+
e.setSelectionRange(0, o.length);
|
|
53
|
+
} catch (a) {
|
|
54
|
+
console.log("setSelectionRange failed (non-critical)", a);
|
|
55
|
+
}
|
|
56
|
+
let n = !1, s = null;
|
|
23
57
|
try {
|
|
24
|
-
|
|
25
|
-
|
|
58
|
+
const a = e.selectionStart === 0 && e.selectionEnd === o.length;
|
|
59
|
+
console.log("element selection state", {
|
|
60
|
+
isSelected: a,
|
|
61
|
+
selectionStart: e.selectionStart,
|
|
62
|
+
selectionEnd: e.selectionEnd,
|
|
63
|
+
textLength: o.length
|
|
64
|
+
}), !a && o.length > 0 && (e.select(), e.setSelectionRange(0, o.length)), n = document.execCommand("copy"), console.log("document.execCommand('copy') result", {
|
|
65
|
+
isSuccess: n,
|
|
66
|
+
textLength: o.length
|
|
67
|
+
}), n ? console.log("execCommand returned true - copy should have succeeded") : console.warn("execCommand returned false - copy failed");
|
|
68
|
+
} catch (a) {
|
|
69
|
+
s = a, console.error("document.execCommand('copy') threw an error", a);
|
|
26
70
|
}
|
|
27
|
-
return e.remove(), l && (
|
|
71
|
+
return e.remove(), l && (r.removeAllRanges(), r.addRange(l)), t instanceof HTMLElement && t.focus(), s ? (console.error("execCommand error", s), !1) : n;
|
|
28
72
|
};
|
|
29
73
|
export {
|
|
30
|
-
|
|
74
|
+
d as copyTextToClipboard
|
|
31
75
|
};
|
|
32
76
|
//# sourceMappingURL=copy.es.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"copy.es.js","sources":["../../src/utils/copy.ts"],"sourcesContent":["export const copyTextToClipboard = async (\n text: string,\n onError?: (error: Error) => void\n): Promise<boolean> => {\n let copySuccess = false;\n
|
|
1
|
+
{"version":3,"file":"copy.es.js","sources":["../../src/utils/copy.ts"],"sourcesContent":["export const copyTextToClipboard = async (\n text: string,\n onError?: (error: Error) => void\n): Promise<boolean> => {\n let copySuccess = false;\n\n const onErrorCallback = (error: Error) => {\n const errorMessage =\n error instanceof Error ? error.message : \"Failed to copy to clipboard\";\n\n console.error(errorMessage);\n onError?.(new Error(errorMessage));\n };\n\n // Check if clipboard API is available\n // Note: navigator.clipboard may be undefined in non-secure contexts (non-HTTPS)\n const isClipboardAvailable =\n typeof navigator !== \"undefined\" &&\n navigator.clipboard &&\n typeof navigator.clipboard.writeText === \"function\";\n\n if (isClipboardAvailable) {\n console.log(\"clipboard API IS available, using clipboard API\", {\n navigator,\n });\n try {\n await navigator.clipboard.writeText(text);\n copySuccess = true;\n } catch (error) {\n // If clipboard API fails, try fallback\n\n console.log(\"clipboard API failed, trying fallback\", { error });\n try {\n copySuccess = DEPRECATED_copyTextToClipboard(text);\n\n if (!copySuccess) {\n console.log(\"fallback unsuccessful, calling onErrorCallback\", {\n error,\n });\n onErrorCallback(error);\n }\n } catch (fallbackError) {\n console.log(\"fallback errored, calling onErrorCallback\", {\n fallbackError,\n });\n onErrorCallback(fallbackError);\n }\n }\n } else {\n // Use fallback method when clipboard API is not available\n\n console.log(\"clipboard API NOT available, using fallback\");\n try {\n copySuccess = DEPRECATED_copyTextToClipboard(text);\n console.log(\"fallback result\", { copySuccess, text });\n if (!copySuccess) {\n console.log(\"fallback unsuccessful, calling onErrorCallback\", {\n copySuccess,\n });\n onErrorCallback(\n new Error(\n \"Failed to copy to clipboard: Clipboard API not available and fallback method failed. This may be due to browser security restrictions (e.g., iframe permissions, non-HTTPS context).\"\n )\n );\n } else {\n console.log(\"fallback successful - copy should have worked\");\n // Note: In some contexts (iframes, cross-origin), execCommand may return true\n // but the copy may still be blocked by the browser. There's no reliable way to verify.\n }\n } catch (error) {\n console.log(\"fallback errored, calling onErrorCallback\", { error });\n onErrorCallback(error);\n }\n }\n\n console.log(\"copyTextToClipboard final result\", { copySuccess });\n return copySuccess;\n};\n\n/**\n * Fallback legacy function to copy text to clipboard for browsers that don't support navigator.clipboard.writeText\n * @reference https://github.com/sindresorhus/copy-text-to-clipboard/blob/main/index.js\n * @deprecated Use navigator.clipboard.writeText instead\n */\nconst DEPRECATED_copyTextToClipboard = (\n text,\n { target = document.body } = {}\n) => {\n if (typeof text !== \"string\") {\n throw new TypeError(\n `Expected parameter \\`text\\` to be a \\`string\\`, got \\`${typeof text}\\`.`\n );\n }\n\n // Check if execCommand is available\n if (!document.execCommand) {\n console.error(\"document.execCommand is not available\");\n return false;\n }\n\n const element = document.createElement(\"textarea\");\n const previouslyFocusedElement = document.activeElement;\n\n element.value = text;\n\n // Prevent keyboard from showing on mobile\n element.setAttribute(\"readonly\", \"\");\n\n element.style.contain = \"strict\";\n element.style.position = \"absolute\";\n element.style.left = \"-9999px\";\n element.style.top = \"-9999px\";\n element.style.width = \"2em\";\n element.style.height = \"2em\";\n element.style.padding = \"0\";\n element.style.border = \"none\";\n element.style.outline = \"none\";\n element.style.boxShadow = \"none\";\n element.style.background = \"transparent\";\n element.style.fontSize = \"12pt\"; // Prevent zooming on iOS\n\n const selection = document.getSelection();\n const originalRange = selection.rangeCount > 0 && selection.getRangeAt(0);\n\n target.append(element);\n\n // Focus and select the element\n // Use setTimeout to ensure the element is in the DOM and can receive focus\n element.focus();\n element.select();\n\n // Explicit selection workaround for iOS and ensure selection is set\n try {\n element.setSelectionRange(0, text.length);\n } catch (e) {\n // setSelectionRange may fail on non-text inputs, but that's okay\n console.log(\"setSelectionRange failed (non-critical)\", e);\n }\n\n let isSuccess = false;\n let execCommandError = null;\n\n // Small delay to ensure the element is properly focused and selected\n // This is especially important in some browsers/contexts\n try {\n // Check if the element is actually selected\n const isSelected =\n element.selectionStart === 0 && element.selectionEnd === text.length;\n console.log(\"element selection state\", {\n isSelected,\n selectionStart: element.selectionStart,\n selectionEnd: element.selectionEnd,\n textLength: text.length,\n });\n\n if (!isSelected && text.length > 0) {\n // Try to select again\n element.select();\n element.setSelectionRange(0, text.length);\n }\n\n isSuccess = document.execCommand(\"copy\");\n console.log(\"document.execCommand('copy') result\", {\n isSuccess,\n textLength: text.length,\n });\n\n // Additional verification: check if execCommand actually worked\n // Some browsers return true even when copy fails\n if (isSuccess) {\n console.log(\"execCommand returned true - copy should have succeeded\");\n } else {\n console.warn(\"execCommand returned false - copy failed\");\n }\n } catch (error) {\n execCommandError = error;\n console.error(\"document.execCommand('copy') threw an error\", error);\n }\n\n // Verify the copy worked by checking if we can read back (if possible)\n // Note: This is a best-effort check since we can't always read clipboard\n\n element.remove();\n\n if (originalRange) {\n selection.removeAllRanges();\n selection.addRange(originalRange);\n }\n\n // Get the focus back on the previously focused element, if any\n if (previouslyFocusedElement instanceof HTMLElement) {\n previouslyFocusedElement.focus();\n }\n\n if (execCommandError) {\n console.error(\"execCommand error\", execCommandError);\n return false;\n }\n\n return isSuccess;\n};\n"],"names":["copyTextToClipboard","text","onError","copySuccess","onErrorCallback","error","errorMessage","DEPRECATED_copyTextToClipboard","fallbackError","target","element","previouslyFocusedElement","selection","originalRange","e","isSuccess","execCommandError","isSelected"],"mappings":"AAAa,MAAAA,IAAsB,OACjCC,GACAC,MACqB;AACrB,MAAIC,IAAc;AAEZ,QAAAC,IAAkB,CAACC,MAAiB;AACxC,UAAMC,IACJD,aAAiB,QAAQA,EAAM,UAAU;AAE3C,YAAQ,MAAMC,CAAY,GAChBJ,KAAA,QAAAA,EAAA,IAAI,MAAMI,CAAY;AAAA,EAAC;AAUnC,MAJE,OAAO,YAAc,OACrB,UAAU,aACV,OAAO,UAAU,UAAU,aAAc,YAEjB;AACxB,YAAQ,IAAI,mDAAmD;AAAA,MAC7D;AAAA,IAAA,CACD;AACG,QAAA;AACI,YAAA,UAAU,UAAU,UAAUL,CAAI,GAC1BE,IAAA;AAAA,aACPE,GAAO;AAGd,cAAQ,IAAI,yCAAyC,EAAE,OAAAA,EAAO,CAAA;AAC1D,UAAA;AACF,QAAAF,IAAcI,EAA+BN,CAAI,GAE5CE,MACH,QAAQ,IAAI,kDAAkD;AAAA,UAC5D,OAAAE;AAAA,QAAA,CACD,GACDD,EAAgBC,CAAK;AAAA,eAEhBG,GAAe;AACtB,gBAAQ,IAAI,6CAA6C;AAAA,UACvD,e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