@protonradio/proton-ui 0.11.18-beta.3 → 0.11.18-beta.5

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.
@@ -1,2 +1,2 @@
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;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=async(o,c)=>{let e=!1;const n=t=>{const l=t instanceof Error?t.message:"Failed to copy to clipboard";console.error(l),c==null||c(new Error(l))};if(typeof navigator<"u"&&navigator.clipboard&&typeof navigator.clipboard.writeText=="function"){console.log("clipboard API detected, attempting to use it");try{await navigator.clipboard.writeText(o),e=!0,console.log("clipboard API succeeded")}catch(t){console.log("clipboard API failed, trying fallback",{error:t});try{e=d(o),e?console.log("fallback succeeded after clipboard API failure"):(console.log("fallback unsuccessful, calling onErrorCallback",{error:t}),n(t))}catch(l){console.log("fallback errored, calling onErrorCallback",{fallbackError:l}),n(l)}}}else{console.log("clipboard API NOT available, using fallback",{hasNavigator:typeof navigator<"u",hasClipboard:typeof navigator<"u"&&!!navigator.clipboard,hasWriteText:typeof navigator<"u"&&navigator.clipboard&&typeof navigator.clipboard.writeText=="function"});try{e=d(o),console.log("fallback result",{copySuccess:e,text:o}),e?(console.log("fallback successful - copy should have worked"),console.warn("Note: execCommand returned true, but the copy may have been silently blocked by browser security restrictions.")):(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, or Modal/Portal focus management).")))}catch(t){console.log("fallback errored, calling onErrorCallback",{error:t}),n(t)}}return console.log("copyTextToClipboard final result",{copySuccess:e}),e},d=(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;const i=document.body;e.style.position="fixed",e.style.top="0",e.style.left="0",e.style.width="2px",e.style.height="2px",e.style.padding="0",e.style.border="none",e.style.margin="0",e.style.outline="none",e.style.boxShadow="none",e.style.background="transparent",e.style.opacity="0",e.style.zIndex="-1",e.style.fontSize="12pt",e.setAttribute("tabindex","-1"),e.setAttribute("aria-hidden","true");const t=document.getSelection(),l=t.rangeCount>0&&t.getRangeAt(0);i.appendChild(e);let r=!1,s=null;try{if(e.focus({preventScroll:!0}),e.select(),e.setSelectionRange)try{e.setSelectionRange(0,o.length)}catch{e.select()}const a=e.selectionStart===0&&e.selectionEnd===o.length;console.log("element selection state before execCommand",{isSelected:a,selectionStart:e.selectionStart,selectionEnd:e.selectionEnd,textLength:o.length,isConnected:e.isConnected,ownerDocument:e.ownerDocument===document,hasFocus:document.activeElement===e}),(!a||document.activeElement!==e)&&o.length>0&&(e.focus({preventScroll:!0}),e.select(),e.setSelectionRange&&e.setSelectionRange(0,o.length)),r=document.execCommand("copy"),console.log("document.execCommand('copy') result",{isSuccess:r,textLength:o.length,activeElement:document.activeElement===e}),r?console.log("execCommand returned true - copy should have succeeded (but may be blocked by browser security)"):console.warn("execCommand returned false - copy failed")}catch(a){s=a,console.error("document.execCommand('copy') threw an error",a)}return e.remove(),l&&(t.removeAllRanges(),t.addRange(l)),n instanceof HTMLElement&&setTimeout(()=>{try{n.focus()}catch(a){console.log("Could not restore focus (non-critical)",a)}},0),s?(console.error("execCommand error",s),!1):r};exports.copyTextToClipboard=u;
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\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,I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AAM,SAAW,OAEnB,MAAAE,EAAY,SAAS,eACrBC,EAAgBD,EAAU,WAAa,GAAKA,EAAU,WAAW,CAAC,EAExEH,EAAO,OAAOC,CAAO,EAIrBA,EAAQ,MAAM,EACdA,EAAQ,OAAO,EAGX,GAAA,CACMA,EAAA,kBAAkB,EAAGT,EAAK,MAAM,QACjCa,EAAG,CAEF,QAAA,IAAI,0CAA2CA,CAAC,CAC1D,CAEA,IAAIC,EAAY,GACZC,EAAmB,KAInB,GAAA,CAEF,MAAMC,EACJP,EAAQ,iBAAmB,GAAKA,EAAQ,eAAiBT,EAAK,OAChE,QAAQ,IAAI,0BAA2B,CACrC,WAAAgB,EACA,eAAgBP,EAAQ,eACxB,aAAcA,EAAQ,aACtB,WAAYT,EAAK,MAAA,CAClB,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"}
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: The Clipboard API handles its own security checks.\n // If not in a secure context (HTTPS), navigator.clipboard will be undefined\n // or writeText() will throw an error. We don't need to manually check isSecureContext.\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 detected, attempting to use it\");\n try {\n await navigator.clipboard.writeText(text);\n copySuccess = true;\n console.log(\"clipboard API succeeded\");\n } catch (error) {\n // Clipboard API failed (could be security restriction, permission denied, etc.)\n // Fall back to execCommand method\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 } else {\n console.log(\"fallback succeeded after clipboard API failure\");\n }\n } catch (fallbackError) {\n console.log(\"fallback errored, calling onErrorCallback\", {\n fallbackError,\n });\n onErrorCallback(fallbackError);\n }\n }\n } else {\n // Clipboard API not available, use fallback method\n console.log(\"clipboard API NOT available, using fallback\", {\n hasNavigator: typeof navigator !== \"undefined\",\n hasClipboard: typeof navigator !== \"undefined\" && !!navigator.clipboard,\n hasWriteText:\n typeof navigator !== \"undefined\" &&\n navigator.clipboard &&\n typeof navigator.clipboard.writeText === \"function\",\n });\n\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, or Modal/Portal focus management).\"\n )\n );\n } else {\n console.log(\"fallback successful - copy should have worked\");\n // WARNING: In some contexts (iframes, cross-origin, Modal portals),\n // execCommand may return true but the copy may still be blocked by the browser.\n // There's no reliable way to verify if the copy actually succeeded.\n console.warn(\n \"Note: execCommand returned true, but the copy may have been silently blocked by browser security restrictions.\"\n );\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 // IMPORTANT: Always append to document.body, not the target\n // This ensures the element is in the active document, which is required\n // for execCommand to work, especially when inside portals/modals\n const container = document.body;\n\n // Style the element to be invisible but still \"visible\" to the browser\n // Some browsers require the element to be in the render tree and \"visible\"\n element.style.position = \"fixed\";\n element.style.top = \"0\";\n element.style.left = \"0\";\n element.style.width = \"2px\";\n element.style.height = \"2px\";\n element.style.padding = \"0\";\n element.style.border = \"none\";\n element.style.margin = \"0\";\n element.style.outline = \"none\";\n element.style.boxShadow = \"none\";\n element.style.background = \"transparent\";\n element.style.opacity = \"0\";\n element.style.zIndex = \"-1\";\n element.style.fontSize = \"12pt\"; // Prevent zooming on iOS\n // NOTE: Do NOT set readonly - some browsers require the element to be editable\n // for execCommand to work properly, especially in Modal/Portal contexts\n element.setAttribute(\"tabindex\", \"-1\");\n element.setAttribute(\"aria-hidden\", \"true\");\n\n const selection = document.getSelection();\n const originalRange = selection.rangeCount > 0 && selection.getRangeAt(0);\n\n // Append to document.body (critical for Modal/Portal contexts)\n container.appendChild(element);\n\n let isSuccess = false;\n let execCommandError = null;\n\n try {\n // Focus and select - must happen synchronously within user activation\n // Try multiple approaches to ensure it works in Modal contexts\n element.focus({ preventScroll: true });\n\n // Use both select() and setSelectionRange for maximum compatibility\n element.select();\n\n // Explicit selection workaround for iOS and ensure full selection\n if (element.setSelectionRange) {\n try {\n element.setSelectionRange(0, text.length);\n } catch (e) {\n // setSelectionRange may fail, try select() again\n element.select();\n }\n }\n\n // Verify selection before attempting copy\n const isSelected =\n element.selectionStart === 0 && element.selectionEnd === text.length;\n\n console.log(\"element selection state before execCommand\", {\n isSelected,\n selectionStart: element.selectionStart,\n selectionEnd: element.selectionEnd,\n textLength: text.length,\n isConnected: element.isConnected,\n ownerDocument: element.ownerDocument === document,\n hasFocus: document.activeElement === element,\n });\n\n // If not properly selected or focused, try again\n if (\n (!isSelected || document.activeElement !== element) &&\n text.length > 0\n ) {\n element.focus({ preventScroll: true });\n element.select();\n if (element.setSelectionRange) {\n element.setSelectionRange(0, text.length);\n }\n }\n\n // Execute copy command - must be synchronous within user activation\n // Some browsers will return true even if copy fails (security restriction)\n isSuccess = document.execCommand(\"copy\");\n\n console.log(\"document.execCommand('copy') result\", {\n isSuccess,\n textLength: text.length,\n activeElement: document.activeElement === element,\n });\n\n if (!isSuccess) {\n console.warn(\"execCommand returned false - copy failed\");\n } else {\n // Even if execCommand returns true, the copy might have been blocked\n // by browser security. There's no reliable way to verify, but we log it.\n console.log(\n \"execCommand returned true - copy should have succeeded (but may be blocked by browser security)\"\n );\n }\n } catch (error) {\n execCommandError = error;\n console.error(\"document.execCommand('copy') threw an error\", error);\n }\n\n // Clean up immediately\n element.remove();\n\n // Restore original selection\n if (originalRange) {\n selection.removeAllRanges();\n selection.addRange(originalRange);\n }\n\n // Restore focus to previously focused element\n // Use setTimeout to avoid focus conflicts with Modal's FocusScope\n if (previouslyFocusedElement instanceof HTMLElement) {\n // Small delay to let the Modal's focus management settle\n setTimeout(() => {\n try {\n previouslyFocusedElement.focus();\n } catch (e) {\n // Focus might fail if element is no longer in DOM, that's okay\n console.log(\"Could not restore focus (non-critical)\", e);\n }\n }, 0);\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","container","selection","originalRange","isSuccess","execCommandError","isSelected","e"],"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,EAYnC,GAJE,OAAO,UAAc,KACrB,UAAU,WACV,OAAO,UAAU,UAAU,WAAc,WAEjB,CACxB,QAAQ,IAAI,8CAA8C,EACtD,GAAA,CACI,MAAA,UAAU,UAAU,UAAUL,CAAI,EAC1BE,EAAA,GACd,QAAQ,IAAI,yBAAyB,QAC9BE,EAAO,CAGd,QAAQ,IAAI,wCAAyC,CAAE,MAAAA,CAAO,CAAA,EAC1D,GAAA,CACFF,EAAcI,EAA+BN,CAAI,EAE5CE,EAMH,QAAQ,IAAI,gDAAgD,GAL5D,QAAQ,IAAI,iDAAkD,CAC5D,MAAAE,CAAA,CACD,EACDD,EAAgBC,CAAK,SAIhBG,EAAe,CACtB,QAAQ,IAAI,4CAA6C,CACvD,cAAAA,CAAA,CACD,EACDJ,EAAgBI,CAAa,CAC/B,CACF,CAAA,KACK,CAEL,QAAQ,IAAI,8CAA+C,CACzD,aAAc,OAAO,UAAc,IACnC,aAAc,OAAO,UAAc,KAAe,CAAC,CAAC,UAAU,UAC9D,aACE,OAAO,UAAc,KACrB,UAAU,WACV,OAAO,UAAU,UAAU,WAAc,UAAA,CAC5C,EAEG,GAAA,CACFL,EAAcI,EAA+BN,CAA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o, c) => {
2
2
  let e = !1;
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));
3
+ const n = (t) => {
4
+ const l = t instanceof Error ? t.message : "Failed to copy to clipboard";
5
+ console.error(l), c == null || c(new Error(l));
6
6
  };
7
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
- });
8
+ console.log("clipboard API detected, attempting to use it");
11
9
  try {
12
- await navigator.clipboard.writeText(o), e = !0;
13
- } catch (l) {
14
- console.log("clipboard API failed, trying fallback", { error: l });
10
+ await navigator.clipboard.writeText(o), e = !0, console.log("clipboard API succeeded");
11
+ } catch (t) {
12
+ console.log("clipboard API failed, trying fallback", { error: t });
15
13
  try {
16
- e = i(o), e || (console.log("fallback unsuccessful, calling onErrorCallback", {
17
- error: l
18
- }), t(l));
19
- } catch (n) {
14
+ e = d(o), e ? console.log("fallback succeeded after clipboard API failure") : (console.log("fallback unsuccessful, calling onErrorCallback", {
15
+ error: t
16
+ }), n(t));
17
+ } catch (l) {
20
18
  console.log("fallback errored, calling onErrorCallback", {
21
- fallbackError: n
22
- }), t(n);
19
+ fallbackError: l
20
+ }), n(l);
23
21
  }
24
22
  }
25
23
  } else {
26
- console.log("clipboard API NOT available, using fallback");
24
+ console.log("clipboard API NOT available, using fallback", {
25
+ hasNavigator: typeof navigator < "u",
26
+ hasClipboard: typeof navigator < "u" && !!navigator.clipboard,
27
+ hasWriteText: typeof navigator < "u" && navigator.clipboard && typeof navigator.clipboard.writeText == "function"
28
+ });
27
29
  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", {
30
+ e = d(o), console.log("fallback result", { copySuccess: e, text: o }), e ? (console.log("fallback successful - copy should have worked"), console.warn(
31
+ "Note: execCommand returned true, but the copy may have been silently blocked by browser security restrictions."
32
+ )) : (console.log("fallback unsuccessful, calling onErrorCallback", {
29
33
  copySuccess: e
30
- }), t(
34
+ }), n(
31
35
  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)."
36
+ "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, or Modal/Portal focus management)."
33
37
  )
34
38
  ));
35
- } catch (l) {
36
- console.log("fallback errored, calling onErrorCallback", { error: l }), t(l);
39
+ } catch (t) {
40
+ console.log("fallback errored, calling onErrorCallback", { error: t }), n(t);
37
41
  }
38
42
  }
39
43
  return console.log("copyTextToClipboard final result", { copySuccess: e }), e;
40
- }, i = (o, { target: c = document.body } = {}) => {
44
+ }, d = (o, { target: c = document.body } = {}) => {
41
45
  if (typeof o != "string")
42
46
  throw new TypeError(
43
47
  `Expected parameter \`text\` to be a \`string\`, got \`${typeof o}\`.`
44
48
  );
45
49
  if (!document.execCommand)
46
50
  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;
51
+ const e = document.createElement("textarea"), n = document.activeElement;
52
+ e.value = o;
53
+ const i = document.body;
54
+ e.style.position = "fixed", e.style.top = "0", e.style.left = "0", e.style.width = "2px", e.style.height = "2px", e.style.padding = "0", e.style.border = "none", e.style.margin = "0", e.style.outline = "none", e.style.boxShadow = "none", e.style.background = "transparent", e.style.opacity = "0", e.style.zIndex = "-1", e.style.fontSize = "12pt", e.setAttribute("tabindex", "-1"), e.setAttribute("aria-hidden", "true");
55
+ const t = document.getSelection(), l = t.rangeCount > 0 && t.getRangeAt(0);
56
+ i.appendChild(e);
57
+ let r = !1, s = null;
57
58
  try {
59
+ if (e.focus({ preventScroll: !0 }), e.select(), e.setSelectionRange)
60
+ try {
61
+ e.setSelectionRange(0, o.length);
62
+ } catch {
63
+ e.select();
64
+ }
58
65
  const a = e.selectionStart === 0 && e.selectionEnd === o.length;
59
- console.log("element selection state", {
66
+ console.log("element selection state before execCommand", {
60
67
  isSelected: a,
61
68
  selectionStart: e.selectionStart,
62
69
  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");
70
+ textLength: o.length,
71
+ isConnected: e.isConnected,
72
+ ownerDocument: e.ownerDocument === document,
73
+ hasFocus: document.activeElement === e
74
+ }), (!a || document.activeElement !== e) && o.length > 0 && (e.focus({ preventScroll: !0 }), e.select(), e.setSelectionRange && e.setSelectionRange(0, o.length)), r = document.execCommand("copy"), console.log("document.execCommand('copy') result", {
75
+ isSuccess: r,
76
+ textLength: o.length,
77
+ activeElement: document.activeElement === e
78
+ }), r ? console.log(
79
+ "execCommand returned true - copy should have succeeded (but may be blocked by browser security)"
80
+ ) : console.warn("execCommand returned false - copy failed");
68
81
  } catch (a) {
69
82
  s = a, console.error("document.execCommand('copy') threw an error", a);
70
83
  }
71
- return e.remove(), l && (r.removeAllRanges(), r.addRange(l)), t instanceof HTMLElement && t.focus(), s ? (console.error("execCommand error", s), !1) : n;
84
+ return e.remove(), l && (t.removeAllRanges(), t.addRange(l)), n instanceof HTMLElement && setTimeout(() => {
85
+ try {
86
+ n.focus();
87
+ } catch (a) {
88
+ console.log("Could not restore focus (non-critical)", a);
89
+ }
90
+ }, 0), s ? (console.error("execCommand error", s), !1) : r;
72
91
  };
73
92
  export {
74
- d as copyTextToClipboard
93
+ g as copyTextToClipboard
75
94
  };
76
95
  //# 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\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,UAA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;AACK,IAAAW,IAAAX,GACX,QAAA,MAAM,+CAA+CA,CAAK;AAAA,EACpE;AAiBA,SAZAK,EAAQ,OAAO,GAEXG,MACFD,EAAU,gBAAgB,GAC1BA,EAAU,SAASC,CAAa,IAI9BF,aAAoC,eACtCA,EAAyB,MAAM,GAG7BK,KACM,QAAA,MAAM,qBAAqBA,CAAgB,GAC5C,MAGFD;AACT;"}
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: The Clipboard API handles its own security checks.\n // If not in a secure context (HTTPS), navigator.clipboard will be undefined\n // or writeText() will throw an error. We don't need to manually check isSecureContext.\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 detected, attempting to use it\");\n try {\n await navigator.clipboard.writeText(text);\n copySuccess = true;\n console.log(\"clipboard API succeeded\");\n } catch (error) {\n // Clipboard API failed (could be security restriction, permission denied, etc.)\n // Fall back to execCommand method\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 } else {\n console.log(\"fallback succeeded after clipboard API failure\");\n }\n } catch (fallbackError) {\n console.log(\"fallback errored, calling onErrorCallback\", {\n fallbackError,\n });\n onErrorCallback(fallbackError);\n }\n }\n } else {\n // Clipboard API not available, use fallback method\n console.log(\"clipboard API NOT available, using fallback\", {\n hasNavigator: typeof navigator !== \"undefined\",\n hasClipboard: typeof navigator !== \"undefined\" && !!navigator.clipboard,\n hasWriteText:\n typeof navigator !== \"undefined\" &&\n navigator.clipboard &&\n typeof navigator.clipboard.writeText === \"function\",\n });\n\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, or Modal/Portal focus management).\"\n )\n );\n } else {\n console.log(\"fallback successful - copy should have worked\");\n // WARNING: In some contexts (iframes, cross-origin, Modal portals),\n // execCommand may return true but the copy may still be blocked by the browser.\n // There's no reliable way to verify if the copy actually succeeded.\n console.warn(\n \"Note: execCommand returned true, but the copy may have been silently blocked by browser security restrictions.\"\n );\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 // IMPORTANT: Always append to document.body, not the target\n // This ensures the element is in the active document, which is required\n // for execCommand to work, especially when inside portals/modals\n const container = document.body;\n\n // Style the element to be invisible but still \"visible\" to the browser\n // Some browsers require the element to be in the render tree and \"visible\"\n element.style.position = \"fixed\";\n element.style.top = \"0\";\n element.style.left = \"0\";\n element.style.width = \"2px\";\n element.style.height = \"2px\";\n element.style.padding = \"0\";\n element.style.border = \"none\";\n element.style.margin = \"0\";\n element.style.outline = \"none\";\n element.style.boxShadow = \"none\";\n element.style.background = \"transparent\";\n element.style.opacity = \"0\";\n element.style.zIndex = \"-1\";\n element.style.fontSize = \"12pt\"; // Prevent zooming on iOS\n // NOTE: Do NOT set readonly - some browsers require the element to be editable\n // for execCommand to work properly, especially in Modal/Portal contexts\n element.setAttribute(\"tabindex\", \"-1\");\n element.setAttribute(\"aria-hidden\", \"true\");\n\n const selection = document.getSelection();\n const originalRange = selection.rangeCount > 0 && selection.getRangeAt(0);\n\n // Append to document.body (critical for Modal/Portal contexts)\n container.appendChild(element);\n\n let isSuccess = false;\n let execCommandError = null;\n\n try {\n // Focus and select - must happen synchronously within user activation\n // Try multiple approaches to ensure it works in Modal contexts\n element.focus({ preventScroll: true });\n\n // Use both select() and setSelectionRange for maximum compatibility\n element.select();\n\n // Explicit selection workaround for iOS and ensure full selection\n if (element.setSelectionRange) {\n try {\n element.setSelectionRange(0, text.length);\n } catch (e) {\n // setSelectionRange may fail, try select() again\n element.select();\n }\n }\n\n // Verify selection before attempting copy\n const isSelected =\n element.selectionStart === 0 && element.selectionEnd === text.length;\n\n console.log(\"element selection state before execCommand\", {\n isSelected,\n selectionStart: element.selectionStart,\n selectionEnd: element.selectionEnd,\n textLength: text.length,\n isConnected: element.isConnected,\n ownerDocument: element.ownerDocument === document,\n hasFocus: document.activeElement === element,\n });\n\n // If not properly selected or focused, try again\n if (\n (!isSelected || document.activeElement !== element) &&\n text.length > 0\n ) {\n element.focus({ preventScroll: true });\n element.select();\n if (element.setSelectionRange) {\n element.setSelectionRange(0, text.length);\n }\n }\n\n // Execute copy command - must be synchronous within user activation\n // Some browsers will return true even if copy fails (security restriction)\n isSuccess = document.execCommand(\"copy\");\n\n console.log(\"document.execCommand('copy') result\", {\n isSuccess,\n textLength: text.length,\n activeElement: document.activeElement === element,\n });\n\n if (!isSuccess) {\n console.warn(\"execCommand returned false - copy failed\");\n } else {\n // Even if execCommand returns true, the copy might have been blocked\n // by browser security. There's no reliable way to verify, but we log it.\n console.log(\n \"execCommand returned true - copy should have succeeded (but may be blocked by browser security)\"\n );\n }\n } catch (error) {\n execCommandError = error;\n console.error(\"document.execCommand('copy') threw an error\", error);\n }\n\n // Clean up immediately\n element.remove();\n\n // Restore original selection\n if (originalRange) {\n selection.removeAllRanges();\n selection.addRange(originalRange);\n }\n\n // Restore focus to previously focused element\n // Use setTimeout to avoid focus conflicts with Modal's FocusScope\n if (previouslyFocusedElement instanceof HTMLElement) {\n // Small delay to let the Modal's focus management settle\n setTimeout(() => {\n try {\n previouslyFocusedElement.focus();\n } catch (e) {\n // Focus might fail if element is no longer in DOM, that's okay\n console.log(\"Could not restore focus (non-critical)\", e);\n }\n }, 0);\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","container","selection","originalRange","isSuccess","execCommandError","isSelected","e"],"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;AAYnC,MAJE,OAAO,YAAc,OACrB,UAAU,aACV,OAAO,UAAU,UAAU,aAAc,YAEjB;AACxB,YAAQ,IAAI,8CAA8C;AACtD,QAAA;AACI,YAAA,UAAU,UAAU,UAAUL,CAAI,GAC1BE,IAAA,IACd,QAAQ,IAAI,yBAAyB;AAAA,aAC9BE,GAAO;AAGd,cAAQ,IAAI,yCAAyC,EAAE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C,IAIE,CAACO,KAAc,SAAS,kBAAkBP,MAC3CT,EAAK,SAAS,MAEdS,EAAQ,MAAM,EAAE,eAAe,GAAM,CAAA,GACrCA,EAAQ,OAAO,GACXA,EAAQ,qBACFA,EAAA,kBAAkB,GAAGT,EAAK,MAAM,IAMhCc,IAAA,SAAS,YAAY,MAAM,GAEvC,QAAQ,IAAI,uCAAuC;AAAA,MACjD,WAAAA;AAAA,MACA,YAAYd,EAAK;AAAA,MACjB,eAAe,SAAS,kBAAkBS;AAAA,IAAA,CAC3C,GAEIK,IAKK,QAAA;AAAA,MACN;AAAA,IAAA,IALF,QAAQ,KAAK,0CAA0C;AAAA,WAQlDV,GAAO;AACK,IAAAW,IAAAX,GACX,QAAA,MAAM,+CAA+CA,CAAK;AAAA,EACpE;AAyBA,SAtBAK,EAAQ,OAAO,GAGXI,MACFD,EAAU,gBAAgB,GAC1BA,EAAU,SAASC,CAAa,IAK9BH,aAAoC,eAEtC,WAAW,MAAM;AACX,QAAA;AACF,MAAAA,EAAyB,MAAM;AAAA,aACxBO,GAAG;AAEF,cAAA,IAAI,0CAA0CA,CAAC;AAAA,IACzD;AAAA,KACC,CAAC,GAGFF,KACM,QAAA,MAAM,qBAAqBA,CAAgB,GAC5C,MAGFD;AACT;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@protonradio/proton-ui",
3
- "version": "0.11.18-beta.3",
3
+ "version": "0.11.18-beta.5",
4
4
  "description": "",
5
5
  "main": "./dist/proton-ui.umd.js",
6
6
  "module": "./dist/proton-ui.es.js",