function l(e){const t=document.createElement("pre");return t.style.width="1px",t.style.height="1px",t.style.position="fixed",t.style.top="5px",t.textContent=e,t}function a(e){if("clipboard"in navigator)return navigator.clipboard.writeText(e.textContent||"");const t=getSelection();if(t==null)return Promise.reject(new Error);t.removeAllRanges();const n=document.createRange();return n.selectNodeContents(e),t.addRange(n),document.execCommand("copy"),t.removeAllRanges(),Promise.resolve()}function o(e){if("clipboard"in navigator)return navigator.clipboard.writeText(e);const t=document.body;if(!t)return Promise.reject(new Error);const n=l(e);return t.appendChild(n),a(n),t.removeChild(n),Promise.resolve()}async function u(e){const t=e.getAttribute("for"),n=e.getAttribute("value");function i(){e.dispatchEvent(new CustomEvent("clipboard-copy",{bubbles:!0}))}if(e.getAttribute("aria-disabled")!=="true"){if(n)await o(n),i();else if(t){const r="getRootNode"in Element.prototype?e.getRootNode():e.ownerDocument;if(!(r instanceof Document||"ShadowRoot"in window&&r instanceof ShadowRoot))return;const s=r.getElementById(t);s&&(await f(s),i())}}}function f(e){return e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement?o(e.value):e instanceof HTMLAnchorElement&&e.hasAttribute("href")?o(e.href):a(e)}function p(e){const t=e.currentTarget;t instanceof HTMLElement&&u(t)}function d(e){if(e.key===" "||e.key==="Enter"){const t=e.currentTarget;t instanceof HTMLElement&&(e.preventDefault(),u(t))}}function m(e){e.currentTarget.addEventListener("keydown",d)}function b(e){e.currentTarget.removeEventListener("keydown",d)}class h extends HTMLElement{static define(t="clipboard-copy",n=customElements){return n.define(t,this),this}constructor(){super(),this.addEventListener("click",p),this.addEventListener("focus",m),this.addEventListener("blur",b)}connectedCallback(){this.hasAttribute("tabindex")||this.setAttribute("tabindex","0"),this.hasAttribute("role")||this.setAttribute("role","button")}get value(){return this.getAttribute("value")||""}set value(t){this.setAttribute("value",t)}}const c=typeof globalThis<"u"?globalThis:window;try{c.ClipboardCopyElement=h.define()}catch(e){if(!(c.DOMException&&e instanceof DOMException&&e.name==="NotSupportedError")&&!(e instanceof ReferenceError))throw e}
