import{r as e}from"./rolldown-runtime-C_s2cVnS.js";import{Ir as t,O as n}from"./i18n-CsN8OUP9.js";import{_ as r}from"./registry-CwOJ4xqK.js";import{Gr as i}from"./profile-DkxWhVLn.js";import{q as a,s as o}from"./layout-YUyGiRmm.js";var s=e({$previewReloadRequest:()=>y,$previewServerRestart:()=>b,$previewTabSources:()=>v,$previewTabs:()=>m,$previewTarget:()=>_,beginPreviewServerRestart:()=>N,closeArtifactPreviewTabs:()=>A,closePreviewForSource:()=>O,closePreviewMatching:()=>k,closeRightRail:()=>j,closeRightRailTab:()=>D,completePreviewServerRestart:()=>P,decodePreviewTabs:()=>p,failPreviewServerRestart:()=>I,openBrowserTab:()=>E,openPreview:()=>T,previewTabId:()=>S,progressPreviewServerRestart:()=>F,requestPreviewReload:()=>M}),c=`hermes.desktop.previewTabs.v2`,l=`hermes.desktop.sessionPreviews.v1`;function u(e){if(!e||typeof e!=`object`)return!1;let t=e;return(t.kind===`artifact`||t.kind===`file`||t.kind===`url`)&&typeof t.label==`string`&&typeof t.source==`string`&&typeof t.url==`string`}function d(e){if(!e||typeof e!=`object`)return!1;let t=e;return typeof t.id==`string`&&(t.id.startsWith(`file:`)||t.id.startsWith(`url:`))&&u(t.target)}function f(e){if(e.kind!==`file`)return!1;if(e.mimeType?.toLowerCase()===`application/pdf`||[e.path,e.source].some(e=>e?/\.pdf$/i.test(e):!1))return!0;try{return/\.pdf$/i.test(new URL(e.url).pathname)}catch{return!1}}function p(e){let t=JSON.parse(e),n=(Array.isArray(t)?t.filter(d):[]).map(e=>f(e.target)&&e.target.previewKind===`binary`?{...e,target:{...e.target,previewKind:`pdf`}}:e),r=n.findLast(e=>e.target.kind===`url`);return n.filter(e=>e.target.kind!==`url`||e===r).map(e=>e.target.kind===`url`?{...e,id:S(e.target)}:e)}var m=i(c,[],{decode:p,encode:e=>JSON.stringify(e.filter(e=>e.target.kind!==`artifact`&&!e.target.transient&&!(e.target.previewKind===`html`&&e.target.dataUrl)),(e,t)=>e===`dataUrl`?void 0:t)});if(typeof window<`u`)try{window.localStorage.removeItem(l)}catch{}function h(e,t){return e.find(e=>e.id===t)??e[0]??null}function g(){return h(m.get(),o.get())}a(g()?.id??null);var _=r([m,o],(e,t)=>h(e,t)?.target??null),v=r(m,e=>e.map(e=>e.target.source)),y=t(0),b=t(null),x=`url:browser`;function S(e){return e.kind===`url`?x:`${e.kind}:${e.url}`}function C(e){return e===`file-browser`||e===`manual`}function w(e,t){return e.kind!==`file`||e.previewKind!==`html`||e.renderMode===`source`?e:{...e,renderMode:C(t)?`source`:`preview`}}function T(e,t=`manual`){let n=w(e,t),r=S(n),i=m.get(),o=i.findIndex(e=>e.id===r),s={id:r,target:n};m.set(o===-1?[...i,s]:i.map((e,t)=>t===o?s:e)),a(r)}function E(){T(m.get().find(e=>e.id===x)?.target??{kind:`url`,label:`Browser`,source:`about:blank`,url:`about:blank`})}function D(e){let t=m.get(),n=t.findIndex(t=>t.id===e);if(n===-1)return;let r=t.filter(t=>t.id!==e);m.set(r),o.get()===e&&a(r[Math.min(n,r.length-1)]?.id??null),r.length===0&&a(null)}function O(e){return k(e)}function k(...e){let t=[...new Set(e.map(e=>e.trim()).filter(Boolean))];if(t.length===0)return!1;let n=m.get().find(e=>{let n=[e.target.source,e.target.url,e.target.label];return t.some(e=>n.includes(e))});return n?(D(n.id),!0):!1}function A(){for(let e of m.get())e.target.kind===`artifact`&&D(e.id)}function j(){m.set([]),a(null)}function M(){y.set(y.get()+1)}function N(e,t){b.set({status:`running`,taskId:e,url:t})}function P(e,t){let r=b.get();r?.taskId===e&&b.set({...r,message:t,status:n(t).startsWith(`error:`)?`error`:`complete`})}function F(e,t){let n=b.get();n?.taskId===e&&n.status===`running`&&b.set({...n,message:t})}function I(e,t){let n=b.get();n?.taskId===e&&n.status===`running`&&b.set({...n,message:t,status:`error`})}export{F as _,_ as a,O as c,D as d,P as f,s as g,T as h,m as i,k as l,E as m,b as n,N as o,I as p,v as r,A as s,y as t,j as u,M as v};