import{aD as W,aE as m,aF as v,aG as j,aH as O,w as k,S as w,q,aI as G,o as I,M as D}from"./index-CIAVq8iD-1776148658686.js";function E(e){return j()?(O(e),!0):!1}const C=typeof window<"u"&&typeof document<"u";typeof WorkerGlobalScope<"u"&&globalThis instanceof WorkerGlobalScope;const F=Object.prototype.toString,_=e=>F.call(e)==="[object Object]";function B(e){let t;function i(){return t||(t=e()),t}return i.reset=async()=>{const d=t;t=void 0,d&&await d},i}function S(e){return Array.isArray(e)?e:[e]}function H(e,t,i={}){const{immediate:d=!0,immediateCallback:f=!1}=i,l=m(!1);let s;function n(){s&&(clearTimeout(s),s=void 0)}function o(){l.value=!1,n()}function a(...u){f&&e(),n(),l.value=!0,s=setTimeout(()=>{l.value=!1,s=void 0,e(...u)},v(t))}return d&&(l.value=!0,C&&a()),E(o),{isPending:W(l),start:a,stop:o}}function N(e,t,i){return k(e,t,{...i,immediate:!0})}const V=C?window:void 0,M=C?window.navigator:void 0;function $(e){var t;const i=v(e);return(t=i?.$el)!=null?t:i}function A(...e){const t=[],i=()=>{t.forEach(n=>n()),t.length=0},d=(n,o,a,u)=>(n.addEventListener(o,a,u),()=>n.removeEventListener(o,a,u)),f=w(()=>{const n=S(v(e[0])).filter(o=>o!=null);return n.every(o=>typeof o!="string")?n:void 0}),l=N(()=>{var n,o;return[(o=(n=f.value)==null?void 0:n.map(a=>$(a)))!=null?o:[V].filter(a=>a!=null),S(v(f.value?e[1]:e[0])),S(q(f.value?e[2]:e[1])),v(f.value?e[3]:e[2])]},([n,o,a,u])=>{if(i(),!n?.length||!o?.length||!a?.length)return;const p=_(u)?{...u}:u;t.push(...n.flatMap(y=>o.flatMap(g=>a.map(b=>d(y,g,b,p)))))},{flush:"post"}),s=()=>{l(),i()};return E(i),s}function z(){const e=m(!1),t=D();return t&&I(()=>{e.value=!0},t),e}function L(e){const t=z();return w(()=>(t.value,!!e()))}function x(e,t={}){const{controls:i=!1,navigator:d=M}=t,f=L(()=>d&&"permissions"in d),l=m(),s=typeof e=="string"?{name:e}:e,n=m(),o=()=>{var u,p;n.value=(p=(u=l.value)==null?void 0:u.state)!=null?p:"prompt"};A(l,"change",o,{passive:!0});const a=B(async()=>{if(f.value){if(!l.value)try{l.value=await d.permissions.query(s)}catch{l.value=void 0}finally{o()}if(i)return G(l.value)}});return a(),i?{state:n,isSupported:f,query:a}:n}function K(e={}){const{navigator:t=M,read:i=!1,source:d,copiedDuring:f=1500,legacy:l=!1}=e,s=L(()=>t&&"clipboard"in t),n=x("clipboard-read"),o=x("clipboard-write"),a=w(()=>s.value||l),u=m(""),p=m(!1),y=H(()=>p.value=!1,f,{immediate:!1});async function g(){let r=!(s.value&&T(n.value));if(!r)try{u.value=await t.clipboard.readText()}catch{r=!0}r&&(u.value=R())}a.value&&i&&A(["copy","cut"],g,{passive:!0});async function b(r=v(d)){if(a.value&&r!=null){let c=!(s.value&&T(o.value));if(!c)try{await t.clipboard.writeText(r)}catch{c=!0}c&&P(r),u.value=r,p.value=!0,y.start()}}function P(r){const c=document.createElement("textarea");c.value=r??"",c.style.position="absolute",c.style.opacity="0",document.body.appendChild(c),c.select(),document.execCommand("copy"),c.remove()}function R(){var r,c,h;return(h=(c=(r=document?.getSelection)==null?void 0:r.call(document))==null?void 0:c.toString())!=null?h:""}function T(r){return r==="granted"||r==="prompt"}return{isSupported:a,text:u,copied:p,copy:b}}export{K as u};
