UNPKG

@tabnews/ui

Version:
2 lines (1 loc) 2.41 kB
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u='<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16" fill="currentColor"><path d="M13.78 4.22a.75.75 0 0 1 0 1.06l-7.25 7.25a.75.75 0 0 1-1.06 0L2.22 9.28a.751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018L6 10.94l6.72-6.72a.75.75 0 0 1 1.06 0Z"/></svg>',h='<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16" fill="currentColor"><path d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 0 1 0 1.5h-1.5a.25.25 0 0 0-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 0 0 .25-.25v-1.5a.75.75 0 0 1 1.5 0v1.5A1.75 1.75 0 0 1 9.25 16h-7.5A1.75 1.75 0 0 1 0 14.25Z"/><path d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0 1 14.25 11h-7.5A1.75 1.75 0 0 1 5 9.25Zm1.75-.25a.25.25 0 0 0-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 0 0 .25-.25v-7.5a.25.25 0 0 0-.25-.25Z"/></svg>';function v(){function d(i,o){const e=a();return e.onclick=async()=>{await navigator.clipboard.writeText(o),c(e),setTimeout(()=>s(e),2e3)},i.appendChild(e);function a(){const t=document.createElement("button");return t.setAttribute("type","button"),r(t,{width:"32px",height:"32px",display:"grid","place-content":"center",cursor:"pointer","border-style":"solid","border-width":"1px","border-radius":"6px",transition:"0.2s ease-in-out","transition-property":"color, background-color, border-color"}),s(t),t.classList.add("copy-button"),t}function s(t){n(t,{title:"Copiar","aria-label":"Copiar"}),r(t,{"pointer-events":"auto"}),t.innerHTML=h,t.classList.remove("copied")}function c(t){n(t,{title:"Copiado","aria-label":"Copiado"}),r(t,{"pointer-events":"none"}),t.innerHTML=u,t.classList.add("copied")}function n(t,p){for(const l in p)t.setAttribute(l,p[l])}}function r(i,o){for(const e in o)i.style.setProperty(e,o[e])}return{viewerEffect({markdownBody:i}){if(!navigator.clipboard)return;const o=i.querySelectorAll("pre > code");o.length!==0&&o.forEach(e=>{if(!e.innerHTML)return;const a=e.parentElement;if(a.childElementCount>1)return;const s=e.innerText,c=document.createElement("div");r(c,{position:"relative",top:"-6px",right:"-6px","min-width":"32px"}),r(a,{display:"flex","justify-content":"space-between",gap:"4px"}),a.appendChild(c);const n=document.createElement("div");n.style.position="absolute",c.appendChild(n),d(n,s)})}}}exports.copyCodeToClipboardPlugin=v;