(function(i,t){typeof exports=="object"&&typeof module<"u"?t(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],t):(i=typeof globalThis<"u"?globalThis:i||self,t(i.VitepressCopyHelper={},i.Vue))})(this,function(i,t){"use strict";async function S(o){try{return navigator.clipboard.writeText(o)}catch{const e=document.createElement("textarea"),a=document.activeElement;e.value=o,e.setAttribute("readonly",""),e.style.contain="strict",e.style.position="absolute",e.style.left="-9999px",e.style.fontSize="12pt";const n=document.getSelection(),l=n?n.rangeCount>0&&n.getRangeAt(0):null;document.body.appendChild(e),e.select(),e.selectionStart=0,e.selectionEnd=o.length,document.execCommand("copy"),document.body.removeChild(e),n&&l&&(n.removeAllRanges(),n.addRange(l)),a&&a.focus()}}const L="",C=(o,e)=>{const a=o.__vccOpts||o;for(const[n,l]of e)a[n]=l;return a},E=["data-message","data-label"],T=["innerHTML"],d={position:"auto",target:"auto",message:"copied",label:null,classes:"copy-btn",preferSibling:"previous"},m=C({__name:"CopyButton",props:{position:{type:String,default:()=>d.position},target:{type:String,default:()=>d.target},message:{type:String,default:()=>d.message},label:{type:String,default:()=>d.label},classes:{type:String,default:()=>d.classes},content:{type:String,default:null}},setup(o){var v,y;const e=o,a=t.useSlots(),n=t.ref(null),l=t.ref(null),g=t.ref(!0),p=t.ref(null),f=t.ref(null),x=e.label?e.label:(y=(v=a.default)==null?void 0:v.call(a)[0])==null?void 0:y.children,k=t.computed(()=>`<!-- Button not rendered: ${p.value} -->`),B=t.computed(()=>e.message.replace("$CONTENT",f.value));t.onMounted(()=>{var b,_;const r=((b=n.value.previousElementSibling)==null?void 0:b.tagName)==="CODE"?n.value.previousElementSibling:null,c=((_=n.value.nextElementSibling)==null?void 0:_.tagName)==="CODE"?n.value.nextElementSibling:null;if(!r&&!c&&!e.content){g.value=!1,p.value="No code element found and no content prop given";return}if(e.content){f.value=e.content;return}let s=e.position;if(e.target==="auto"?r&&c?(l.value=r,s==="auto"&&(s="end")):l.value=r||c:e.target==="previous"?(l.value=r,s==="auto"&&(s="end")):e.target==="next"&&(l.value=c,s==="auto"&&(s="start")),!l.value){p.value="Failed to select code node";return}let u="beforeend";s==="auto"?r?u="beforeend":c&&(u="afterbegin"):s==="start"?u="afterbegin":s==="end"&&(u="beforeend"),f.value=l.value.innerText,l.value.innerText="",l.value.insertAdjacentHTML("beforeend",`<span>${f.value}</span>`),l.value.insertAdjacentElement(u,n.value),n.value.classList.add(`copy-btn-${u}`)});async function A(){await S(f.value),n.value.classList.add("copied"),setTimeout(()=>{n.value.classList.remove("copied")},1e3)}return(r,c)=>g.value?(t.openBlock(),t.createElementBlock("span",{key:0,class:t.normalizeClass(o.classes),ref_key:"btn",ref:n,onClick:A,"data-message":B.value,"data-label":t.unref(x)},null,10,E)):(t.openBlock(),t.createElementBlock("span",{key:1,innerHTML:k.value},null,8,T))}},[["__scopeId","data-v-32f61984"]]),h=m;i.default=m,i.defaultSettings=h,Object.defineProperties(i,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
