import{g as y,P as l,a as _,S as w,b,W as g}from"./window-CFz_bT0q.js";import{listen as v,once as d,emit as f,emitTo as m,TauriEvent as r}from"./event-DmfRIRSd.js";import{i as s}from"./index-Bkuhln3H.js";function D(){return new p(y(),window.__TAURI_INTERNALS__.metadata.currentWebview.label,{skip:!0})}async function c(){return s("plugin:webview|get_all_webviews").then(u=>u.map(e=>new p(new g(e.windowLabel,{skip:!0}),e.label,{skip:!0})))}const o=["tauri://created","tauri://error"];class p{constructor(e,i,t){this.window=e,this.label=i,this.listeners=Object.create(null),t?.skip||s("plugin:webview|create_webview",{windowLabel:e.label,options:{...t,label:i}}).then(async()=>this.emit("tauri://created")).catch(async a=>this.emit("tauri://error",a))}static async getByLabel(e){var i;return(i=(await c()).find(t=>t.label===e))!==null&&i!==void 0?i:null}static getCurrent(){return D()}static async getAll(){return c()}async listen(e,i){return this._handleTauriEvent(e,i)?()=>{const t=this.listeners[e];t.splice(t.indexOf(i),1)}:v(e,i,{target:{kind:"Webview",label:this.label}})}async once(e,i){return this._handleTauriEvent(e,i)?()=>{const t=this.listeners[e];t.splice(t.indexOf(i),1)}:d(e,i,{target:{kind:"Webview",label:this.label}})}async emit(e,i){if(o.includes(e)){for(const t of this.listeners[e]||[])t({event:e,id:-1,payload:i});return}return f(e,i)}async emitTo(e,i,t){if(o.includes(i)){for(const a of this.listeners[i]||[])a({event:i,id:-1,payload:t});return}return m(e,i,t)}_handleTauriEvent(e,i){return o.includes(e)?(e in this.listeners?this.listeners[e].push(i):this.listeners[e]=[i],!0):!1}async position(){return s("plugin:webview|webview_position",{label:this.label}).then(e=>new l(e))}async size(){return s("plugin:webview|webview_size",{label:this.label}).then(e=>new _(e))}async close(){return s("plugin:webview|webview_close",{label:this.label})}async setSize(e){return s("plugin:webview|set_webview_size",{label:this.label,value:e instanceof w?e:new w(e)})}async setPosition(e){return s("plugin:webview|set_webview_position",{label:this.label,value:e instanceof b?e:new b(e)})}async setFocus(){return s("plugin:webview|set_webview_focus",{label:this.label})}async setAutoResize(e){return s("plugin:webview|set_webview_auto_resize",{label:this.label,value:e})}async hide(){return s("plugin:webview|webview_hide",{label:this.label})}async show(){return s("plugin:webview|webview_show",{label:this.label})}async setZoom(e){return s("plugin:webview|set_webview_zoom",{label:this.label,value:e})}async reparent(e){return s("plugin:webview|reparent",{label:this.label,window:typeof e=="string"?e:e.label})}async clearAllBrowsingData(){return s("plugin:webview|clear_all_browsing_data")}async setBackgroundColor(e){return s("plugin:webview|set_webview_background_color",{color:e})}async onDragDropEvent(e){const i=await this.listen(r.DRAG_ENTER,n=>{e({...n,payload:{type:"enter",paths:n.payload.paths,position:new l(n.payload.position)}})}),t=await this.listen(r.DRAG_OVER,n=>{e({...n,payload:{type:"over",position:new l(n.payload.position)}})}),a=await this.listen(r.DRAG_DROP,n=>{e({...n,payload:{type:"drop",paths:n.payload.paths,position:new l(n.payload.position)}})}),h=await this.listen(r.DRAG_LEAVE,n=>{e({...n,payload:{type:"leave"}})});return()=>{i(),a(),t(),h()}}}export{p as Webview,c as getAllWebviews,D as getCurrentWebview};
