1const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/supabase-Bmf_ZcoY.js","assets/supabase-client-DAL-3Fs3.js","assets/rolldown-runtime-C0FnF6B9.js","assets/preload-helper-kNmmqUCw.js","assets/desktop-Hapj3Rcb.js","assets/dist-dBHUV4CI.js","assets/browser-CH_aBGf7.js","assets/supabase-T70w-Fxh.js","assets/origin-j-jSMp4o.js","assets/session-start-Cth5hxmG.js","assets/telemetry-dMUQ7y5w.js","assets/use-is-mobile-DS45C9IV.js","assets/react-Ci090mG2.js","assets/api-Y0h6IQac.js","assets/local-DB2YXULi.js","assets/watch-Bwp1UJZt.js","assets/watch-DQTHlsmX.js","assets/db-BQ8QC1PZ.js","assets/capacity-report-h0ugTpcA.js","assets/workspace-topic-BqUy0OE5.js","assets/workspace-topic-DEhxa6qw.js","assets/workspace-topic-9__ZVqVN.js","assets/workspace-topic-CIoBJu8N.js","assets/item-client-CH_pgFic.js","assets/item-client-Bb5fSGWE.js","assets/rows-nY9NB7ZL.js","assets/url-helpers-BtH77Ffc.js","assets/url-helpers-B8W4X8pi.js","assets/check-balance-CvW6g6NH.js","assets/check-balance-Re49UUnI.js","assets/document-viewer-D_rFhRi4.js","assets/jsx-runtime-BdxMnOeJ.js","assets/utils-ajSpmF-2.js","assets/file-text-CH9OgMph.js","assets/createLucideIcon-eJJfzIhd.js","assets/empty-state-0A4JtJ5v.js","assets/loading-spinner-Df5JSjmQ.js","assets/loader-C0W7Zeqc.js","assets/document-editor-5ly0jBP_.js","assets/audio-peaks-CCqJfjxI.js","assets/hard-drive-BAmwr6Ns.js","assets/strikethrough-BJfUuvaB.js","assets/chevron-right-DVJrco6N.js","assets/code-Dempot_V.js","assets/square-code-Br_49s73.js","assets/list-BrYeCN1j.js","assets/play-q1SHWSxm.js","assets/x-DarFe5R-.js","assets/dropdown-menu-BeUAUI-v.js","assets/react-dom-CJb_rC07.js","assets/dist-DkXod8PZ.js","assets/rows-GO89RiSL.js","assets/export-prefs-D3ulu1lI.js","assets/checkbox-DOg4TkL9.js","assets/audio-waveform-kDgJrXAf.js","assets/local-DMwBhTRk.js","assets/local-media-BlpK6x0r.js","assets/pause-DBe4ai1D.js","assets/format-EEGbecXJ.js","assets/item-DGh1IQcr.js","assets/web-playable-BFmzPYjg.js","assets/new-document-Dq-FvAP4.js","assets/dist-CiQeHHhg.js","assets/with-selector-C4BkB9b9.js","assets/attach-items-dialog-BE4qu9VD.js","assets/tile-parts-DyiBiC9-.js","assets/document-editor-BySce9gg.css","assets/jszip.min-DIgHJL1D.js"])))=>i.map(i=>d[i]); 2import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{t}from"./react-Ci090mG2.js";import{r as n}from"./telemetry-dMUQ7y5w.js";import{t as r}from"./preload-helper-kNmmqUCw.js";import{s as i,t as a}from"./desktop-Hapj3Rcb.js";import{d as o,f as s,p as c,s as l,u}from"./feed-playback-DloZvb1j.js";import{t as d}from"./origin-j-jSMp4o.js";import{t as f}from"./use-is-mobile-DS45C9IV.js";import{t as p}from"./jsx-runtime-BdxMnOeJ.js";import{d as m,l as h,o as g,p as _}from"./db-BQ8QC1PZ.js";import{t as v}from"./react-dom-CJb_rC07.js";import{t as y}from"./useSearch-DbK8ovNu.js";import{t as b}from"./useNavigate-YvaXjqMv.js";import{t as x}from"./payment-page-iAvFa0AU.js";import{d as S,i as C,n as w}from"./audio-waveform-kDgJrXAf.js";import{i as T,r as E}from"./supabase-client-DAL-3Fs3.js";import{d as D,i as O,t as k}from"./api-Y0h6IQac.js";import{f as ee,h as te,o as ne,s as re}from"./local-DB2YXULi.js";import"./supabase-T70w-Fxh.js";import{n as A}from"./auth-provider-D9KJyDBW.js";import{t as ie}from"./watch-DQTHlsmX.js";import{i as ae}from"./rows-nY9NB7ZL.js";import{a as oe,n as j,s as M,t as se}from"./item-client-Bb5fSGWE.js";import{t as N}from"./utils-ajSpmF-2.js";import{s as ce}from"./surface-D_swEJJi.js";import{A as le,B as P,C as F,D as ue,E as de,F as fe,G as pe,H as I,I as me,J as L,K as he,L as ge,M as _e,N as ve,O as ye,P as be,R as xe,S as Se,T as Ce,U as we,V as Te,W as Ee,X as De,Y as Oe,_ as ke,a as Ae,b as je,c as Me,d as Ne,f as Pe,g as Fe,h as R,i as z,j as Ie,k as Le,l as Re,m as B,n as ze,o as Be,p as Ve,q as He,r as Ue,s as We,t as Ge,u as Ke,v as qe,w as Je,x as Ye,y as Xe,z as Ze}from"./direction-DDfjH0nL.js";import{c as Qe,d as $e,l as et,o as tt,s as nt,u as rt}from"./audio-peaks-CCqJfjxI.js";import{n as it,t as at}from"./frame-Ba4CdVhR.js";import{n as ot,r as V,t as st}from"./chevron-right-DVJrco6N.js";import{t as ct}from"./chevron-left-D3pEFfnw.js";import{t as lt}from"./cloud-upload-C8V_cQ-2.js";import{t as ut}from"./copy-tvII1Rb9.js";import{t as dt}from"./eye-off-6eUN2J9R.js";import{n as ft}from"./loader-C0W7Zeqc.js";import{t as pt}from"./maximize-2-CPsIP1KI.js";import{t as mt}from"./pause-DBe4ai1D.js";import{t as ht}from"./play-q1SHWSxm.js";import{t as gt}from"./plus-DGKkjpWy.js";import{t as _t}from"./x-DarFe5R-.js";import{n as H}from"./dist-Bf3fPfOz.js";import{a as vt,c as yt,d as bt,f as xt,i as St,l as Ct,m as wt,n as Tt,o as Et,p as Dt,r as Ot,s as kt,t as U,u as W}from"./query-client-D_R5v8eL.js";import{a as At,i as jt,n as Mt,r as Nt,u as Pt}
2from"./workspaces-context-DyNFBQWf.js";import"./workspace-topic-9__ZVqVN.js";import{t as Ft}from"./workspace-topic-DEhxa6qw.js";import{$ as It,A as Lt,C as Rt,D as zt,E as Bt,F as Vt,M as Ht,N as Ut,O as Wt,P as Gt,Q as Kt,S as qt,T as Jt,X as Yt,Y as Xt,Z as Zt,at as Qt,b as $t,ct as en,d as tn,et as nn,f as rn,g as an,i as G,it as on,j as sn,k as cn,l as ln,lt as un,m as dn,ot as fn,p as pn,r as mn,t as hn,tt as gn,v as _n,w as vn,x as yn,y as bn}from"./dropdown-menu-BeUAUI-v.js";import{i as xn,n as Sn}from"./dist-DkXod8PZ.js";import{B as Cn,F as wn,G as Tn,H as En,I as Dn,J as On,K as kn,U as An,V as jn,W as Mn,Y as Nn,a as Pn,i as Fn,n as In,q as Ln,y as Rn,z as zn}from"./rows-GO89RiSL.js";import{n as Bn,t as Vn}from"./loading-spinner-Df5JSjmQ.js";import{t as Hn}from"./tooltip-BTRLIWTw.js";import{n as Un}from"./settings-dialog-context-D5A7KzMA.js";import{a as K,n as Wn,t as Gn}from"./agent-kinds-_eY4u_kw.js";import{n as q,o as Kn,r as qn}from"./format-EEGbecXJ.js";import{i as Jn,n as Yn,o as Xn,s as Zn}from"./checkbox-DOg4TkL9.js";import{t as J}from"./url-helpers-B8W4X8pi.js";import{a as Qn,c as $n,l as er,o as tr,s as nr,t as rr}from"./item-DGh1IQcr.js";import{a as ir}from"./web-playable-BFmzPYjg.js";import{t as ar}from"./folders-client-Cixya3vH.js";import{d as or,i as sr,l as cr,m as lr,p as ur}from"./local-media-BlpK6x0r.js";import{f as dr,w as fr}from"./local-DMwBhTRk.js";import{a as pr,c as mr,t as hr}from"./sync-to-cloud-DMFknePe.js";import{t as gr}from"./aspect-ratios-DfSMK04_.js";import{n as _r}from"./import-file-B0cl3uR_.js";import{o as Y,t as vr}from"./format-CY6pmk1A.js";import{t as yr}from"./names-BLBrSric.js";var X=e(t(),1),Z=p(),br=X.createContext(void 0),xr=e=>{let t=X.useContext(br);if(e)return e;if(!t)throw Error(`No QueryClient set, use QueryClientProvider to set one`);return t},Sr=({client:e,children:t})=>(X.useEffect(()=>(e.mount(),()=>{e.unmount()}),[e]),(0,Z.jsx)(br.Provider,{value:e,children:t})),Cr=class extends vt{#e;#t=void 0;#n=void 0;#r=void 0;#i;#a;#o;#s;#c;#l;#u;#d;#f;#p=new Set;constructor(e,t){super(),this.options=t,this.#e=e,this.#o=null,this.bindMethods(),this.setOptions(t)}bindMethods(){this.refetch=this.refetch.bind(this)}onSubscribe(){this.listeners.size===1&&(this.#t.addObserver(this),Tr(this.#t,this.options)?this.#m():this.updateResult(),this.#y())}onUnsubscribe(){this.hasListeners()||this.destroy()}shouldFetchOnReconnect(){return Er(this.#t,this.options,this.options.refetchOnReconnect)}shouldFetchOnWindowFocus(){return Er(this.#t,this.options,this.options.refetchOnWindowFocus)}destroy(){this.listeners=new Set,this.#b(),this.#x(),this.#t.removeObserver(this)}setOptions(e){let t=this.options,n=this.#t;if(this.options=this.#e.defaultQueryOptions(e),this.options.enabled!==void 0&&typeof this.options.enabled!=`boolean`&&typeof this.options.enabled!=`function`&&typeof W(this.options.enabled,this.#t)!=`boolean`)throw Error(`Expected enabled to be a boolean or a callback that returns a boolean`);this.#S(),this.#t.setOptions(this.options),t._defaulted&&!bt(this.options,t)&&this.#e.getQueryCache().notify({type:`observerOptionsUpdated`,query:this.#t,observer:this});let r=this.hasListeners();r&&Dr(this.#t,n,this.options,t)&&this.#m(),this.updateResult(),r&&(this.#t!==n||W(this.options.enabled,this.#t)!==W(t.enabled,this.#t)||W(this.options.staleTime,this.#t)!==W(t.staleTime,this.#t))&&this.#g();let i=this.#_();r&&(this.#t!==n||W(this.options.enabled,this.#t)!==W(t.enabled,this.#t)||i!==this.#f)&&this.#v(i)}getOptimisticResult(e){let t=this.#e.getQueryCache().build(this.#e,e),n=this.createResult(t,e);return bt(this.getCurrentResult(),n)||(this.#r=n,this.#a=this.options,this.#i=this.#t.state),n}getCurrentResult(){return this.#r}trackResult(e,t){return new Proxy(e,{get:(e,n)=>(this.trackProp(n),t?.(n),Reflect.get(e,n))})}trackProp(e){this.#p.add(e)}getCurrentQuery(){return this.#t}refetch({...e}={}){return this.fetch({...e})}fetchOptimistic(e){let t=this.#e.defaultQueryOptions(e),n=this.#e.getQueryCache().build(this.#e,t),r=()=>{},i,a=new Promise(e=>{i=e,r=this.#e.getQueryCache().subscribe(i=>{i.type===`updated`&&i.query.queryHash===n.queryHash&&n.state.data!==void 0&&(r(),e(this.createResult(n,t)))})});return Promise.race([n.fetch().then(()=>{let e=this.createResult(n,t);return i?.(e),e}).finally(()=>{r()}),a])}fetch(e){return this.#m({...e,cancelRefetch:e.cancelRefetch??!0}).then(()=>(this.updateResult(),this.#r))}#m(e){this.#S();let t=this.#t.fetch(this.options,e);return e?.throwOnError||(t=t.catch(yt)),t}#h(e){return!Et()&&W(this.options.enabled,this.#t)!==!1&&kt(e)}#g(){this.#b();let e=W(this.options.staleTime,this.#t);if(this.#r.isStale||!this.#h(e))return;let t=Dt(this.#r.dataUpdatedAt,e)+1;this.#u=wt.setTimeout(()=>{this.#r.isStale||this.updateResult()},t)}#_(){return(typeof this.options.refetchInterval==`function`?this.options.refetchInterval(this.#t):this.options.refetchInterval)??!1}#v(e){this.#x(),this.#f=e,!(this.#f===0||!this.#h(this.#f))&&(this.#d=wt.setInterval(()=>
2{(this.options.refetchIntervalInBackground||St.isFocused())&&this.#m()},this.#f))}#y(){this.#g(),this.#v(this.#_())}#b(){this.#u!==void 0&&(wt.clearTimeout(this.#u),this.#u=void 0)}#x(){this.#d!==void 0&&(wt.clearInterval(this.#d),this.#d=void 0)}createResult(e,t){let n=this.#t,r=this.options,i=this.#r,a=this.#i,o=this.#a,s=e===n?this.#n:e.state,{state:c}=e,l={...c},u=!1,d;if(t._optimisticResults){let i=this.hasListeners(),a=!i&&Tr(e,t),o=i&&Dr(e,n,t,r);(a||o)&&(l={...l,...Tt(c.data,e.options)}),t._optimisticResults===`isRestoring`&&(l.fetchStatus=`idle`)}let{error:f,errorUpdatedAt:p,status:m}=l;d=l.data;let h=!1;if(t.placeholderData!==void 0&&d===void 0&&m===`pending`){let e;i?.isPlaceholderData&&t.placeholderData===o?.placeholderData?(e=i.data,h=!0):e=typeof t.placeholderData==`function`?t.placeholderData(this.#l?.state.data,this.#l):t.placeholderData,e!==void 0&&(m=`success`,d=Ct(i?.data,e,t),u=!0)}if(t.select&&d!==void 0&&!h){if(i&&d===a?.data&&t.select===this.#s)d=this.#c;else try{this.#s=t.select,d=t.select(d),d=Ct(i?.data,d,t),this.#c=d,this.#o=null}catch(e){this.#o=e}}else d===void 0&&(this.#o=null);this.#o&&(f=this.#o,d=this.#c,p=Date.now(),m=`error`,u=!1);let g=l.fetchStatus===`fetching`,_=m===`pending`,v=m===`error`,y=_&&g,b=d!==void 0;return{status:m,fetchStatus:l.fetchStatus,isPending:_,isSuccess:m===`success`,isError:v,isInitialLoading:y,isLoading:y,data:d,dataUpdatedAt:l.dataUpdatedAt,error:f,errorUpdatedAt:p,failureCount:l.fetchFailureCount,failureReason:l.fetchFailureReason,errorUpdateCount:l.errorUpdateCount,isFetched:e.isFetched(),isFetchedAfterMount:l.dataUpdateCount>s.dataUpdateCount||l.errorUpdateCount>s.errorUpdateCount,isFetching:g,isRefetching:g&&!_,isLoadingError:v&&!b,isPaused:l.fetchStatus===`paused`,isPlaceholderData:u,isRefetchError:v&&b,isStale:Or(e,t),refetch:this.refetch,isEnabled:W(t.enabled,e)!==!1}}updateResult(){let e=this.#r,t=this.createResult(this.#t,this.options);if(this.#i=this.#t.state,this.#a=this.options,this.#i.data!==void 0&&(this.#l=this.#t),bt(t,e))return;this.#r=t;let n=(()=>{if(!e)return!0;let{notifyOnChangeProps:t}=this.options,n=typeof t==`function`?t():t;if(n===`all`||!n&&!this.#p.size)return!0;let r=new Set(n??this.#p);return this.options.throwOnError&&r.add(`error`),Object.keys(this.#r).some(t=>{let n=t;return this.#r[n]!==e[n]&&r.has(n)})})();Ot.batch(()=>{n&&this.listeners.forEach(e=>{e(this.#r)}),this.#e.getQueryCache().notify({query:this.#t,type:`observerResultsUpdated`})})}#S(){let e=this.#e.getQueryCache().build(this.#e,this.options);if(e===this.#t)return;let t=this.#t;this.#t=e,this.#n=e.state,this.hasListeners()&&(t?.removeObserver(this),e.addObserver(this))}onQueryUpdate(){this.updateResult(),this.hasListeners()&&this.#y()}};function wr(e,t){return W(t.enabled,e)!==!1&&e.state.data===void 0&&(e.state.status!==`error`||W(t.retryOnMount,e)!==!1)}function Tr(e,t){return wr(e,t)||e.state.data!==void 0&&Er(e,t,t.refetchOnMount)}function Er(e,t,n){if(W(t.enabled,e)!==!1&&W(t.staleTime,e)!==`static`){let r=typeof n==`function`?n(e):n;return r===`always`||r!==!1&&Or(e,t)}return!1}function Dr(e,t,n,r){return(e!==t||W(r.enabled,e)===!1)&&(!n.suspense||e.state.status!==`error`)&&Or(e,n)}function Or(e,t){return W(t.enabled,e)!==!1&&e.isStaleByTime(W(t.staleTime,e))}var kr=X.createContext(!1),Ar=()=>X.useContext(kr);kr.Provider;function jr(){let e=!1;return{clearReset:()=>{e=!1},reset:()=>{e=!0},isReset:()=>e}}var Mr=X.createContext(jr()),Nr=()=>X.useContext(Mr),Pr=(e,t,n)=>{let r=n?.state.error&&typeof e.throwOnError==`function`?xt(e.throwOnError,[n.state.error,n]):e.throwOnError;(e.suspense||r)&&(t.isReset()||(e.retryOnMount=!1))},Fr=e=>{X.useEffect(()=>{e.clearReset()},[e])},Ir=({result:e,errorResetBoundary:t,throwOnError:n,query:r,suspense:i})=>e.isError&&!t.isReset()&&!e.isFetching&&r&&(i&&e.data===void 0||xt(n,[e.error,r])),Lr=e=>{if(e.suspense){let t=1e3,n=e=>e===`static`?e:Math.max(e??t,t),r=e.staleTime;e.staleTime=typeof r==`function`?(...e)=>n(r(...e)):n(r),typeof e.gcTime==`number`&&(e.gcTime=Math.max(e.gcTime,t))}},Rr=(e,t)=>e?.suspense&&t.isPending,zr=(e,t,n)=>t.fetchOptimistic(e).catch(()=>{n.clearReset()});function Br(e,t,n){let r=Ar(),i=Nr(),a=xr(n),o=a.defaultQueryOptions(e),s=a.getQueryCache().get(o.queryHash),c=e.subscribed!==!1;o._optimisticResults=r?`isRestoring`:c?`optimistic`:void 0,Lr(o),Pr(o,i,s),Fr
2(i);let[l]=X.useState(()=>new t(a,o)),u=l.getOptimisticResult(o),d=!r&&c;if(X.useSyncExternalStore(X.useCallback(e=>{let t=d?l.subscribe(Ot.batchCalls(e)):yt;return l.updateResult(),t},[l,d]),()=>l.getCurrentResult(),()=>l.getCurrentResult()),X.useEffect(()=>{l.setOptions(o)},[o,l]),Rr(o,u))throw zr(o,l,i);if(Ir({result:u,errorResetBoundary:i,throwOnError:o.throwOnError,query:s,suspense:o.suspense}))throw u.error;return o.notifyOnChangeProps?u:l.trackResult(u)}function Vr(e,t){return Br(e,Cr,t)}function Hr(){return typeof window>`u`||!window.matchMedia||!window.matchMedia(`(pointer: coarse)`).matches}var Ur=e(v(),1),Wr=e=>e.replace(/\s+/g,` `).trim().toLowerCase();function Gr(e){try{let t=localStorage.getItem(e);return t?JSON.parse(t):void 0}catch{return}}function Kr(e,t){try{localStorage.setItem(e,JSON.stringify(t))}catch{}}var qr=e=>Pt({queryKey:[`agent-names`,e],queryFn:async()=>{let t=await k.get(`/api/workspaces/${e}/agent-names`);return Kr(`agent-names:${e}`,t),t},initialData:()=>Gr(`agent-names:${e}`),initialDataUpdatedAt:0,staleTime:3e5});function Q(e,t){if(!t||e.author_type!==`mcp`&&e.author_type!==`api`||!e.author_key)return e.author_label;let[n,r]=[e.author_key.slice(0,e.author_key.indexOf(`:`)),e.author_key.slice(e.author_key.indexOf(`:`)+1)];return(n===`app`?t.connections[r]:n===`key`?t.keys[r]:void 0)??e.author_label}var Jr=e=>Pt({queryKey:[`agent-icons`,e],queryFn:async()=>{let t=(await k.get(`/api/workspaces/${e}/agent-icons`)).icons??[];return Kr(`agent-icons:${e}`,t),new Map(t.map(e=>[e.name_key,e.icon_url]))},initialData:()=>{let t=Gr(`agent-icons:${e}`);return t?new Map(t.map(e=>[e.name_key,e.icon_url])):void 0},initialDataUpdatedAt:0,staleTime:3e5});function Yr(e,t){let n=Mt(),r=t??n,{data:i}=Vr({...Jr(r??``),enabled:!!r&&!!e});if(!e)return null;let a=Wr(e);if(i?.has(a)){let e=i.get(a);if(!e)return null;let t=Wn.find(t=>t.src===e);return t?{src:t.src,ink:t.ink,custom:!1}:{src:e,custom:!0}}let o=K(e);return o?{src:o.src,ink:o.ink,custom:!1}:null}function Xr(e,t){let{data:n}=Vr({...Jr(t??``),enabled:!!t&&!!e});return!!e&&!!n?.has(Wr(e))}function Zr(e){let t=xr(),n=(0,X.useCallback)(async()=>{e&&await t.invalidateQueries({queryKey:[`agent-icons`,e]})},[t,e]);return{upload:(0,X.useCallback)(async(t,r)=>{if(!e)return;let i=new FormData;i.append(`name`,t),i.append(`file`,r),await k.upload(`/api/workspaces/${e}/agent-icons`,i),await n()},[e,n]),choose:(0,X.useCallback)(async(t,r)=>{e&&(await k.patch(`/api/workspaces/${e}/agent-icons`,{name:t,icon:r}),await n())},[e,n])}}var Qr=`eversince:account-prefs`,$r={},ei=new Map,ti=null,ni=0,ri=`account-prefs:unsent`;function ii(){try{ei.size===0?localStorage.removeItem(ri):localStorage.setItem(ri,JSON.stringify(Object.fromEntries(ei)))}catch{}}function ai(){ti=null;let e=$r;$r={},Object.keys(e).length!==0&&k.patch(`/api/account/preferences`,e).then(()=>{ni=0}).catch(()=>{for(let[t,n]of Object.entries(e))t in $r||($r[t]=n);ni+=1,ni<=3&&oi(2e3*2**ni)})}function oi(e){ti&&clearTimeout(ti),ti=setTimeout(ai,e)}function si(e,t){try{localStorage.setItem(e,t)}catch{}$r[e]=t,ei.set(e,t),ii(),ni=0,oi(400)}if(typeof window<`u`)try{let e=JSON.parse(localStorage.getItem(ri)??`{}`);for(let[t,n]of Object.entries(e))!ae(t)||typeof n!=`string`||(ei.set(t,n),$r[t]=n);Object.keys($r).length>0&&oi(1e3)}catch{}function ci(e){let t=!1;for(let[n,r]of Object.entries(e)){if(!ae(n)||typeof r!=`string`)continue;let e=ei.get(n);if(e!==void 0){e===r&&(ei.delete(n),ii());continue}try{if(localStorage.getItem(n)===r)continue;localStorage.setItem(n,r),t=!0}catch{}}t&&window.dispatchEvent(new Event(Qr))}function li(e){if(!e)return{};try{let t=JSON.parse(e);return t&&typeof t==`object`&&!Array.isArray(t)?t:{}}catch{return{}}}var ui=(0,X.createContext)(void 0);function di({children:e,initialProfile:t}){let{user:n}=A(),{setTheme:r}=S(),[i,a]=(0,X.useState)(t);(0,X.useEffect)(()=>{if(n?.id)return ie(`SELECT * FROM user_profiles WHERE id = ?`,[n.id],e=>({fullName:e.full_name??null,avatarUrl:e.avatar_url??null,theme:e.theme===`light`||e.theme===`dark`?e.theme:`system`,preferences:li(e.preferences)}),e=>{let t=e[0];if(!t)return;let{preferences:n,...r}=t;a(r),ci(n)})},[n?.id]),(0,X.useEffect)(()=>{r(i.theme)},[i.theme,r]);let o=(0,X.useCallback)(e=>{a(t=>({...t,...e}))},[]),s=(0,X.useCallback)(e=>{a(t=>({...t,theme:e})),k.patch(`/api/account/theme`,{theme:e}).catch(()=>{})},[]),c=(0,X.useMemo)(()=>({profile:i,updateProfile:o,setThemeChoice:s}
2),[i,o,s]);return(0,Z.jsx)(ui.Provider,{value:c,children:e})}function $(){let e=(0,X.useContext)(ui);if(e===void 0)throw Error(`useProfile must be used within a ProfileProvider`);return e}var fi=6e4,pi=new Map,mi=new Map,hi=new Set;function gi(){for(let e of hi)e()}async function _i(e){let t=mi.get(e);if(t)return t;let n=k.get(`/api/workspaces/${e}/members`).then(t=>{let n=t.members??[];return pi.set(e,{at:Date.now(),members:n}),n}).catch(()=>pi.get(e)?.members??[]).then(t=>(mi.delete(e),gi(),t));return mi.set(e,n),n}function vi(e,t=!0){let[,n]=(0,X.useState)(0);(0,X.useEffect)(()=>{let e=()=>n(e=>e+1);return hi.add(e),()=>{hi.delete(e)}},[]),(0,X.useEffect)(()=>{if(!t||!e)return;let n=pi.get(e);n&&Date.now()-n.at<fi||_i(e)},[e,t]);let r=(0,X.useCallback)(async()=>{e&&await _i(e)},[e]);return{members:e?pi.get(e)?.members??null:null,reload:r}}function yi(){let[e,t]=(0,X.useState)(m);return(0,X.useEffect)(()=>{t(m());let e=_(t);return()=>{e()}},[]),e}var bi=6e4,xi=new Map,Si=new Map;function Ci(e){let t=xi.get(e);if(t&&Date.now()-t.at<bi)return Promise.resolve(t.value);let n=Si.get(e);if(n)return n;let r=k.get(`/api/public-links`,{query:{commentable:`1`}}).then(e=>e.commentable===!0).catch(()=>!0).then(t=>(xi.set(e,{at:Date.now(),value:t}),Si.delete(e),t));return Si.set(e,r),r}function wi(e,t){let n=(0,X.useRef)(t);(0,X.useEffect)(()=>{n.current=t},[t]);let r=yi(),{members:i}=vi(e??null),[a,o]=(0,X.useState)(!1);(0,X.useEffect)(()=>{if(!e){o(!1);return}let t=!0;return Ci(e).then(e=>{t&&o(e)}),()=>{t=!1}},[e]);let s=(i??[]).length>1||a;(0,X.useEffect)(()=>{if(!e)return;let t;return ie(`SELECT id FROM tool_calls WHERE workspace_id = ? AND tool = 'manage_comments' ORDER BY created_at DESC LIMIT 1`,[e],e=>e.id,e=>{let r=e[0]??null;t!==void 0&&r!==t&&n.current(),t=r})},[e]);let c=(0,X.useRef)(!1);(0,X.useEffect)(()=>{if(!r){c.current=!0;return}c.current&&(c.current=!1,n.current())},[r]),(0,X.useEffect)(()=>{if(!(!e||!s||!r))return Ft(e,{onMessage:(e,t)=>{e===`row`&&t?.t===`library_comments`&&n.current()},onStatus:e=>{e===`rejoined`&&n.current()}})},[e,s,r])}var Ti=`eversince:comments-seen`;function Ei(e){let{activeWorkspaceId:t}=Nt(),[n,r]=(0,X.useState)(0),i=(0,X.useCallback)(async()=>{if(!e){r(0);return}try{let t=await k.get(`/api/library/comments/unread`,{query:{targets:e}});r(t.unread?.[e]??0)}catch{}},[e]);(0,X.useEffect)(()=>{i()},[i]);let a=(0,X.useRef)(null),o=(0,X.useCallback)(()=>{e&&(a.current&&clearTimeout(a.current),a.current=setTimeout(()=>void i(),400))},[e,i]);return(0,X.useEffect)(()=>{if(e)return window.addEventListener(Ti,o),()=>{a.current&&clearTimeout(a.current),window.removeEventListener(Ti,o)}},[e,o]),wi(e?t:null,o),n}var Di=Object.defineProperty,Oi=(e,t)=>Di(e,`name`,{value:t,configurable:!0}),[ki,Ai]=en(`AlertDialog`,[Nn]),ji=Nn(),Mi=Oi(e=>{let{__scopeAlertDialog:t,...n}=e,r=ji(t);return(0,Z.jsx)(jn,{...r,...n,modal:!0})},`AlertDialog`);X.forwardRef(Oi(function(e,t){let{__scopeAlertDialog:n,...r}=e,i=ji(n);return(0,Z.jsx)(On,{...i,...r,ref:t})},`AlertDialogTrigger`));var Ni=Oi(e=>{let{__scopeAlertDialog:t,...n}=e,r=ji(t);return(0,Z.jsx)(kn,{...r,...n})},`AlertDialogPortal`),Pi=X.forwardRef(Oi(function(e,t){let{__scopeAlertDialog:n,...r}=e,i=ji(n);return(0,Z.jsx)(Tn,{...i,...r,ref:t})},`AlertDialogOverlay`)),[Fi,Ii]=ki(`AlertDialogContent`),Li=X.forwardRef(Oi(function(e,t){let{__scopeAlertDialog:n,children:r,...i}=e,a=ji(n),o=X.useRef(null),s=xn(t,o),c=X.useRef(null);return(0,Z.jsx)(Fi,{scope:n,cancelRef:c,children:(0,Z.jsx)(An,{role:`alertdialog`,...a,...i,ref:s,onOpenAutoFocus:un(i.onOpenAutoFocus,e=>{e.preventDefault(),c.current?.focus({preventScroll:!0})}),onPointerDownOutside:e=>e.preventDefault(),onInteractOutside:e=>e.preventDefault(),children:r})})},`AlertDialogContent`)),Ri=X.forwardRef(Oi(function(e,t){let{__scopeAlertDialog:n,...r}=e,i=ji(n);return(0,Z.jsx)(Ln,{...i,...r,ref:t})},`AlertDialogTitle`)),zi=X.forwardRef(Oi(function(e,t){let{__scopeAlertDialog:n,...r}=e,i=ji(n);return(0,Z.jsx)(Mn,{...i,...r,ref:t})},`AlertDialogDescription`)),Bi=X.forwardRef(Oi(function(e,t){let{__scopeAlertDialog:n,...r}=e,i=ji(n);return(0,Z.jsx)(En,{...i,...r,ref:t})},`AlertDialogAction`)),Vi=`AlertDialogCancel`,Hi=X.forwardRef(Oi(function(e,t){let{__scopeAlertDialog:n,...r}=e,{cancelRef:i}=Ii(Vi,n),a=ji(n),o=xn(t,i);return(0,Z.jsx)(En,{...a,...r,ref:o})},`AlertDialogCancel`)),Ui=Mi,Wi=Ni,Gi=Pi,Ki=Li,qi=Bi,Ji=Hi,Yi=Ri,Xi=zi,Zi=Ui,Qi=Wi,$i=X.forwardRef(({className:e,...t},n)=>(0,Z.jsx)(Gi,{ref:n,className:N(`fixed inset-0 z-[10003] bg-white/60 dark:bg-black/70 backdrop-blur-sm dark:backdrop-blur-sm data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0`,e),...t}));$i.displayName=Gi.displayName;var ea=X.forwardRef(({className:e,...t},n)=>{let r=Cn();return(0,Z.jsxs)(Qi,{children:[(0,Z.jsx)($i,{}),(0,Z.jsx)(`div`,{className:`fixed inset-0 z-[10003] flex items-center justify-center p-4`,style:r?{bottom:r}:void 0,children:(0,Z.jsx)(Ki,{ref:n,className:N(`flex max-h-[80dvh] w-full max-w-[360px] flex-col overflow-y-auto rounded-xl border border-black/[0.06] bg-white p-3 text-foreground shadow-lg dark:border-[#252525] dark:bg-[#202020]`,`max-md:p-3.5`,e),...t,style:r?{...t.style,maxHeight:`calc(100% - 8px)`}:t.style,children:t.children})})]})});ea.displayName=Ki.displayName;var ta=({className:e,...t})=>(0,Z.jsx)(`div`,{className:N(`flex flex-col gap-1.5 text-left max-md:gap-2`,e),...t});ta.displayName=`AlertDialogHeader`;var na=({className:e,...t})=>(0,Z.jsx)(`div`,{className:N(`mt-3 flex flex-row items-center justify-end gap-1`,`max-md:mt-3.5 max-md:gap-1.5 max-md:[&>*]:!h-9 max-md:[&>*]:!px-3.5 max-md:[&>*]:!text-[13.5px]`,e),...t});na.displayName=`AlertDialogFooter`;var ra=X.forwardRef(({className:e,...t},n)=>(0,Z.jsx)(Yi,{ref:n,className:N(`text-[12.5px] font-[460] leading-[18px] max-md:text-[14.5px] max-md:leading-[20px]`,e),...t}));ra.displayName=Yi.displayName;var ia=X.forwardRef(({className:e,...t},n)=>(0,Z.jsx)(Xi,{ref:n,className:N(`text-[12px] font-[380] leading-[18px] text-zinc-500 dark:text-zinc-400 max-md:text-[14px] max-md:leading-[20px]`,e),...t}));ia.displayName=Xi.displayName;var aa=X.forwardRef(({className:e,...t},n)=>(0,Z.jsx)(qi,{ref:n,className:N(`inline-flex h-8 items-center justify-center gap-1.5 rounded-full bg-zinc-900 px-3 text-[11.5px] font-[440] text-white outline-none transition-colors duration-100 hover:bg-zinc-800 focus-visible:ring-2 focus-visible:ring-zinc-400/50 disabled:opacity-40 dark:bg-white dark:text-black dark:hover:bg-zinc-200`,e),...t}));aa.displayName=qi.displayName;var oa=X.forwardRef(({className:e,...t},n)=>(0,Z.jsx)(Ji,{ref:n,className:N(Rn,e),...t}));oa.displayName=Ji.displayName;function sa({name:e,kind:t,workspaceId:n,size:r=16,className:i}){let a={width:r,height:r},o=Yr(e||(t?Gn[t]:null),n),[s,c]=(0,X.useState)(null),l=o&&o.src!==s?o.src:void 0;return l?(0,Z.jsx)(`img`,{src:l,alt:``,"aria-hidden":!0,draggable:!1,
2className:N(`inline-block shrink-0`,o?.custom?`rounded-full object-cover`:`object-contain`,o?.ink===`black`&&`dark:invert`,o?.ink===`white`&&`invert dark:invert-0`,i),style:a,onError:()=>c(l)}):(0,Z.jsx)(R,{size:r,strokeWidth:1.6,className:N(`shrink-0 text-zinc-400 dark:text-zinc-500`,i)})}function ca({name:e,workspaceId:t,size:n,className:r}){let i=Yr(e,t),a=(e.trim()[0]??`?`).toUpperCase();return(0,Z.jsx)(`span`,{"aria-hidden":!0,className:N(`flex flex-shrink-0 items-center justify-center rounded-full bg-zinc-100 font-[460] text-zinc-600 dark:bg-white/[0.08] dark:text-zinc-300`,r),style:{width:n,height:n,fontSize:Math.round(n*.36)},children:i?(0,Z.jsx)(sa,{name:e,workspaceId:t,size:i.custom?n:Math.round(n*.58)}):a})}var la={item:Ie,canvas:at,timeline:P,link:Ce};function ua(e){return e===`user`||e===`visitor`?z:e===`mcp`||e===`api`?R:Ee}function da({author:e,avatarUrl:t,className:n}){let r=!!Yr(e.author_type===`mcp`||e.author_type===`api`?e.author_label:null);if(e.author_type===`user`&&t)return(0,Z.jsx)(`img`,{src:t,alt:``,"aria-hidden":!0,className:N(`h-[14px] w-[14px] flex-shrink-0 rounded-full object-cover`,n)});if(r)return(0,Z.jsx)(sa,{name:e.author_label,size:12,className:n});let i=ua(e.author_type);return(0,Z.jsx)(i,{className:N(`h-3 w-3 flex-shrink-0 text-zinc-400 dark:text-zinc-500`,n),strokeWidth:1.8})}function fa(e){return e.author_type===`user`?e.author_label||`Teammate`:e.author_type===`visitor`?e.author_label||`Visitor`:e.author_type===`api`?e.author_label||`API`:e.author_label||`Agent`}function pa({body:e,mentions:t}){let n=(t??[]).map(e=>e.label).filter(Boolean);if(n.length===0)return(0,Z.jsx)(Z.Fragment,{children:e});let r=n.sort((e,t)=>t.length-e.length).map(e=>e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)).join(`|`),i=e.split(RegExp(`(@(?:${r}))(?![\\w])`,`g`));return(0,Z.jsx)(Z.Fragment,{children:i.map((e,t)=>e.startsWith(`@`)&&n.some(t=>e===`@${t}`)?(0,Z.jsx)(`span`,{className:`font-[440] text-zinc-500 dark:text-zinc-400`,children:e},t):(0,Z.jsx)(`span`,{children:e},t))})}var ma=null,ha=()=>ma&&ma.workspace===O()?ma.list:null;function ga(){let{activeWorkspaceId:e}=Nt(),[t,n]=(0,X.useState)(ha),r=(0,X.useCallback)(async()=>{let e=ha();if(e)return n(e),e;let t=O(),r=[];try{r=(await k.get(`/api/library/mentionables`)).mentionables??[],t===O()&&(ma={workspace:t,list:r})}catch{}return n(r),r},[]);return(0,X.useEffect)(()=>{let e=ha();n(e),e||r()},[r,e]),{directory:t,loadDirectory:r}}var _a=36,va=132,ya=42,ba=200,xa={user:0,app:1,key:2},Sa={user:`People`,app:`Agents`,key:`Keys`};function Ca({placeholder:e,onSend:t,currentUserId:n,accessories:r,autoFocus:i,focusNonce:a,onEscape:o,canInvite:s=!1,onInvite:c}){let{directory:l,loadDirectory:u}=ga(),[d,p]=(0,X.useState)(``),[m,h]=(0,X.useState)(!1),[g,_]=(0,X.useState)(null),[v,y]=(0,X.useState)(0),b=(0,X.useRef)(new Map),x=(0,X.useRef)(null),S=f()===!0;(0,X.useEffect)(()=>{i&&requestAnimationFrame(()=>x.current?.focus())},[i]),(0,X.useEffect)(()=>{a&&requestAnimationFrame(()=>x.current?.focus())},[a]);let C=(0,X.useCallback)((e,t)=>{let n=e.slice(0,t),r=n.lastIndexOf(`@`);if(r===-1||r>0&&!/[\s(]/.test(n[r-1])){_(null);return}let i=n.slice(r+1),a=[...b.current.keys()].some(e=>i===e||i.startsWith(`${e} `));if(/\n/.test(i)||i.length>40||a){_(null);return}_({start:r,text:i}),y(0),u()},[u]),w=(l??[]).filter(e=>!(e.type===`user`&&n&&e.id===n)),T=(g?w.filter(e=>e.label.toLowerCase().startsWith(g.text.toLowerCase())).sort((e,t)=>xa[e.type]-xa[t.type]):[]).slice(0,8),E=(0,X.useCallback)(e=>{if(!g)return;let t=x.current,n=t?.selectionStart??d.length,r=`${d.slice(0,g.start)}@${e.label} ${d.slice(n)}`;b.current.set(e.label,e),p(r),_(null),requestAnimationFrame(()=>{let n=g.start+e.label.length+2;t?.focus(),t?.setSelectionRange(n,n)})},[d,g]);(0,X.useLayoutEffect)(()=>{let e=x.current;e&&(e.style.height=`0px`,e.style.height=`${Math.min(Math.max(e.scrollHeight,S?ya:_a),S?ba:va)}px`)},[d,S]);let D=(0,X.useCallback)(async()=>{let e=d.trim();!e||m||(h(!0),await t(e,Array.from(b.current.values()).filter(t=>RegExp(`@${t.label.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}(?![\\w])`).test(e)))&&(p(``),b.current.clear()),h(!1))},[d,m,t]);return(0,Z.jsxs)(`div`,{className:`relative rounded-xl border border-black/[0.08] bg-white shadow-[0_2px_8px_rgba(0,0,0,0.05)] dark:border-white/[0.08] dark:bg-white/[0.03] dark:shadow-none`,children:[g&&l&&T.length===0&&(0,Z.jsxs)(`div`,{className:N(`absolute bottom-full left-0 z-10 mb-1 w-56 max-md:w-64`,$t,`px-2.5 py-2`),children:[(0,Z.jsx)(`span`,{className:`block text-[12px] max-md:text-[14px] font-[400] text-zinc-500 dark:text-zinc-400`,children:w.length===0?`Nobody to mention here yet`:`No one by that name`}),s&&(0,Z.jsxs)(`button`,{type:`button`,onMouseDown:e=>{e.preventDefault(),c?.()},className:N(`flex cursor-default select-none items-center rounded-[7px] px-2 py-[6px] [@media(pointer:coarse)]:py-[10px] text-[12px] max-md:px-2.5 max-md:text-[14px] font-[380] text-foreground outline-none transition-colors duration-100 focus:bg-zinc-100 dark:focus:bg-white/[0.06]`,`mt-1.5 -mx-1 w-[calc(100%+0.5rem)] gap-2 text-left hover:bg-zinc-100 dark:hover:bg-white/[0.06]`),children:[(0,Z.jsx)(Be,{className:`h-3.5 w-3.5 max-md:h-4 max-md:w-4 flex-shrink-0 text-zinc-500 dark:text-zinc-400`,strokeWidth:1.4}),(0,Z.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:`Invite someone`})]})]}),g&&T.length>0&&(0,Z.jsx)(`div`,{className:N(`absolute bottom-full left-0 z-10 mb-1 w-56 max-md:w-64`,$t),children:T.map((e,t)=>{let n=e.type===`user`?z:e.type===`app`?R:Ee,r=t===0||T[t-1].type!==e.type;return(0,Z.jsxs)(`div`,{children:[r&&(0,Z.jsx)(`div`,{className:`px-2 pb-0.5 pt-1 text-[12px] max-md:px-2.5 max-md:text-[12.5px] font-[400] text-zinc-400 dark:text-zinc-500`,children:Sa[e.type]}),(0,Z.jsxs)(`button`,{type:`button`,onMouseDown:t=>{t.preventDefault(),E(e)},onMouseEnter:()=>y(t),className:N(`flex cursor-default select-none items-center rounded-[7px] px-2 py-[6px] [@media(pointer:coarse)]:py-[10px] text-[12px] max-md:px-2.5 max-md:text-[14px] font-[380] text-foreground outline-none transition-colors duration-100 focus:bg-zinc-100 dark:focus:bg-white/[0.06]`,`w-full gap-2 text-left`,t===v&&`bg-zinc-100 dark:bg-white/[0.06]`),children:[(0,Z.jsx)(n,{className:`h-3.5 w-3.5 max-md:h-4 max-md:w-4 flex-shrink-0 text-zinc-500 dark:text-zinc-400`,strokeWidth:1.4}),(0,Z.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:e.label})]})]},`${e.type}-${e.id}`)})}),(0,Z.jsx)(`textarea`,{dir:`auto`,ref:x,value:d,onChange:e=>{p(e.target.value),C(e.target.value,e.target.selectionStart??e.target.value.length)},onSelect:e=>C(d,e.target.selectionStart??d.length),onBlur:()=>_(null),onKeyDown:e=>{if(g&&T.length>0){if(e.key===`ArrowDown`){e.preventDefault(),e.stopPropagation(),y(e=>(e+1)%T.length);return}if(e.key===`ArrowUp`){e.preventDefault(),e.stopPropagation(),y(e=>(e-1+T.length)%T.length);return}if(e.key===`Enter`||e.key===`Tab`){e.preventDefault(),e.stopPropagation(),E(T[v]??T[0]);return}if(e.key===`Escape`){e.preventDefault(),e.stopPropagation(),_(null);return}}
2if(e.key===`Enter`&&!e.shiftKey&&Hr()&&(e.preventDefault(),D()),e.key===`Escape`){o&&(e.preventDefault(),e.stopPropagation(),o());return}e.stopPropagation()},rows:1,enterKeyHint:S?`enter`:`send`,placeholder:w.length>0?`${e.replace(/â¦$/,``)}⦠Use @ to notify someone`:e,style:{height:S?ya:_a,maxHeight:S?ba:va},className:`w-full resize-none overflow-y-auto bg-transparent px-3 pt-3 text-[12px] max-md:px-3.5 max-md:pt-3.5 max-md:text-[14.5px] max-md:leading-[21px] font-[380] leading-[18px] text-foreground outline-none placeholder:text-zinc-400 dark:placeholder:text-zinc-500`}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-1 px-2 pb-2 pt-0.5 max-md:pb-1.5`,children:[(0,Z.jsx)(`button`,{type:`button`,"aria-label":`Mention someone`,onClick:()=>{let e=x.current,t=e?.selectionStart??d.length,n=`${d.slice(0,t)}${t>0&&!/\s$/.test(d.slice(0,t))?` `:``}@${d.slice(t)}`;p(n);let r=n.indexOf(`@`,Math.max(0,t-1))+1;requestAnimationFrame(()=>{e?.focus(),e?.setSelectionRange(r,r),C(n,r)})},className:`flex h-8 w-8 items-center justify-center text-zinc-400 transition-colors hover:text-foreground md:h-6 md:w-6 dark:text-zinc-500`,children:(0,Z.jsx)($e,{className:`h-3 w-3 max-md:h-4 max-md:w-4`,strokeWidth:1.5})}),r,(0,Z.jsx)(`button`,{type:`button`,"aria-label":`Send`,disabled:!d.trim()||m,onClick:()=>void D(),className:N(`ml-auto flex h-7 w-7 items-center justify-center rounded-full bg-zinc-900 md:h-6 md:w-6 text-white transition-opacity hover:opacity-90 dark:bg-white dark:text-zinc-900`,!m&&`disabled:opacity-30`),children:m?(0,Z.jsx)(ft,{className:`h-3 w-3 max-md:h-4 max-md:w-4 animate-spin`,strokeWidth:2}):(0,Z.jsx)(pe,{className:`h-3.5 w-3.5 max-md:h-4 max-md:w-4`,strokeWidth:2})})]})]})}var wa=`h-[5px] w-[5px] max-md:h-[7px] max-md:w-[7px] flex-shrink-0 rounded-full bg-blue-500`,Ta=`h-4 w-4 max-md:h-5 max-md:w-5`,Ea=`inline-flex items-center gap-1 flex-shrink-0 rounded-full bg-zinc-100 px-1.5 text-[11px] leading-[16px] max-md:px-2 max-md:text-[12.5px] max-md:leading-[22px] tabular-nums text-zinc-600 dark:bg-white/[0.08] dark:text-zinc-300`,Da=`flex h-10 w-10 flex-shrink-0 items-center justify-center rounded-full text-zinc-700 active:bg-zinc-100 dark:text-zinc-200 dark:active:bg-white/[0.08]`,Oa=`flex h-7 w-7 max-md:h-10 max-md:w-10 flex-shrink-0 items-center justify-center text-zinc-400 transition-colors duration-100 hover:text-foreground data-[state=open]:text-foreground dark:text-zinc-500`,ka=new Map,Aa=`inline-flex h-6 items-center gap-1 rounded-full px-2 text-[11.5px] max-md:h-8 max-md:px-3 max-md:text-[13px] font-[400] transition-colors`,ja=`bg-zinc-100 text-zinc-500 hover:text-foreground dark:bg-white/[0.06] dark:text-zinc-400`,Ma=`bg-zinc-200/70 text-foreground dark:bg-white/[0.12]`;function Na({target:e,currentUserId:t,onOpenTarget:n,initialThreadId:r,onOpenCount:i,title:a,onClose:o,extraControls:s,notice:c,getCurrentTime:l,onSeek:u,getRange:d,getSelectedClip:p,pendingRegion:m,onRequestDraw:h,drawing:g=!1,onClearPending:_,onRegionsChange:v,activeRegionId:y,onRegionActivate:b,regionLabel:x,focusNonce:S,sheet:C=!1}){let{activeWorkspaceId:w,activeWorkspace:T}=Nt(),{openSettings:E}=Un(),O=f()===!0&&!e&&!C,ee=T?.is_owner===!0||T?.role===`owner`,te=(0,X.useCallback)(()=>E(`workspaces`),[E]),{directory:ne}=ga(),{members:re}=vi(w),{profile:A}=$(),ie=(0,X.useCallback)(e=>e.author_type!==`user`||!e.author_id?null:t&&e.author_id===t?A.avatarUrl??null:(re??[]).find(t=>t.user_id===e.author_id)?.avatar_url??null,[re,A.avatarUrl,t]),ae=`${w??``}|${JSON.stringify(e??null)}`,[j,M]=(0,X.useState)(()=>ka.get(ae)??null),[se,ce]=(0,X.useState)(()=>new Map);(0,X.useEffect)(()=>{let e=[...new Set((j??[]).flatMap(e=>e.target?.kind===`item`?[e.target.id]:[]))].filter(e=>!se.has(e));if(e.length===0)return;let t=!1;return oe(e).then(n=>{t||ce(t=>{let r=new Map(t);for(let t of e)r.set(t,Fa(n.get(t)));return r})}),()=>{t=!0}},[j,se]);let[P,F]=(0,X.useState)(r?{kind:`thread`,id:r}:{kind:`list`});(0,X.useEffect)(()=>{if(!(!O||P.kind===`list`))return document.body.classList.add(`comments-thread`),()=>document.body.classList.remove(`comments-thread`)},[O,P.kind]);let[ue,de]=(0,X.useState)(``),[fe,pe]=(0,X.useState)(``),[I,me]=(0,X.useState)(null),[L,he]=(0,X.useState)(`o
2pen`),[ge,_e]=(0,X.useState)(!1),[ve,ye]=(0,X.useState)(null),[be,xe]=(0,X.useState)(null),[Se,Ce]=(0,X.useState)(null),[we,Te]=(0,X.useState)(null),[Ee,De]=(0,X.useState)(0),ke=j!==null;(0,X.useEffect)(()=>{!S||!ke||(F(e=>e.kind===`list`?e:{kind:`list`}),De(S))},[S,ke]);let je=(0,X.useRef)(new Set),[Me,Ne]=(0,X.useState)(null),[Fe,R]=(0,X.useState)(null),z=(0,X.useRef)(P);z.current=P;let Ie=xr(),Le=(0,X.useCallback)(async e=>{if(!w)return e;let t=await Ie.fetchQuery(qr(w)).catch(()=>void 0);if(!t)return e;let n=e=>{let n=Q(e,t);return n===e.author_label?e:{...e,author_label:n}};return e.map(e=>({...e,root:n(e.root),last:n(e.last),...e.comments?{comments:e.comments.map(n)}:{}}))},[w,Ie]),Re=(0,X.useCallback)(async e=>{try{let t=await k.get(`/api/library/comments`,{query:{thread:e}});t.thread&&z.current.kind===`thread`&&z.current.id===e&&(Ne((await Le([t.thread]))[0]),R(null))}catch(t){z.current.kind===`thread`&&z.current.id===e&&R({id:e,missing:t instanceof D&&t.status===404})}},[Le]);(0,X.useEffect)(()=>{let e=setTimeout(()=>pe(ue.trim()),250);return()=>clearTimeout(e)},[ue]);let B=(0,X.useCallback)(async()=>{try{let t=await k.get(`/api/library/comments`,{query:{...e?{target:e}:{},...L===`archived`?{scope:`archived`}:{},...fe&&!e?{q:fe}:{},...I&&!e?{by:`${I.type}:${I.id}`}:{}}}),n=await Le(t.threads??[]);M(n),L===`open`&&!fe&&!I&&ka.set(ae,n)}catch{M(e=>e??[])}},[e,L,fe,I,ae,Le]);(0,X.useEffect)(()=>{B()},[B]);let ze=(0,X.useRef)(null),Be=(0,X.useCallback)(()=>{ze.current&&clearTimeout(ze.current),ze.current=setTimeout(()=>{B(),z.current.kind===`thread`&&Re(z.current.id)},400)},[B,Re]);(0,X.useEffect)(()=>()=>{ze.current&&clearTimeout(ze.current)},[]),wi(w,Be),(0,X.useEffect)(()=>{L===`open`&&j&&i?.(j.length)},[L,j,i]),(0,X.useEffect)(()=>{if(!v||!j)return;let e=[];for(let t of j)for(let n of t.comments??[t.root])n.region&&(!n.region.slideId&&!(typeof n.region.w==`number`&&n.region.w>0)||e.push({id:n.id,region:n.region,resolved:!!t.resolved,author:n.author_label}));v(e)},[j,v]);let Ve=(0,X.useCallback)(e=>{je.current.has(e)||(je.current.add(e),M(t=>t?.map(t=>t.id===e?{...t,unread:!1}:t)??t),k.post(`/api/library/comments/unread`,{threadId:e}).then(()=>window.dispatchEvent(new Event(Ti))).catch(()=>{}))},[]),Ue=(0,X.useCallback)(e=>{Ne(null),R(null),F({kind:`thread`,id:e}),z.current={kind:`thread`,id:e},Re(e),Ve(e)},[Ve,Re]);(0,X.useEffect)(()=>{r&&Ue(r)},[r,Ue]);let We=(0,X.useCallback)(async(t,n,r={})=>{try{return await k.post(`/api/library/comments`,{...e&&!r.parentId?{target:e}:{},...r.parentId?{parentId:r.parentId}:{},body:t,mentions:n,...be!==null&&!r.parentId?{timestampSeconds:be}:{},...be!==null&&Se!==null&&!r.parentId?{timestampEndSeconds:Se}:{},...we&&!r.parentId?{anchor:{clipId:we.id,clipName:we.name}}:{},...m&&!r.parentId?m.slideId?{anchor:{slideId:m.slideId,x:m.x,y:m.
2y,w:m.w,h:m.h,...m.layerId?{layerId:m.layerId}:{}}}:{region:{x:m.x,y:m.y,w:m.w,h:m.h}}:{}}),xe(null),Ce(null),Te(null),_?.(),P.kind===`new`&&F({kind:`list`}),await B(),z.current.kind===`thread`&&await Re(z.current.id),!0}catch(e){return H.error(e instanceof D?e.message:`Could not post that`),!1}},[e,be,Se,we,m,_,B,Re,P.kind]),Ge=(0,X.useCallback)(async(e,t)=>{M(n=>n?.map(n=>n.id===e.id?{...n,resolved:t}:n)??n),Ne(n=>n&&n.id===e.id?{...n,resolved:t}:n);try{await k.patch(`/api/library/comments/${e.id}`,{archived:t}),await B()}catch{H.error(`Could not update that`),B()}},[B]),Ke=(0,X.useCallback)(async(e,t)=>{let n=t.trim();if(!n||n===e.body)return!0;try{return await k.patch(`/api/library/comments/${e.id}`,{body:n}),await B(),z.current.kind===`thread`&&await Re(z.current.id),!0}catch(e){return H.error(e instanceof D?e.message:`Could not save that`),!1}},[B,Re]),qe=(0,X.useCallback)(async e=>{Ne(t=>t?.comments?{...t,comments:t.comments.filter(t=>t.id!==e.id)}:t);try{await k.delete(`/api/library/comments/${e.id}`),e.id===e.root_id&&F({kind:`list`}),await B(),z.current.kind===`thread`&&await Re(z.current.id)}catch(e){H.error(e instanceof D?e.message:`Could not delete that`),z.current.kind===`thread`&&Re(z.current.id)}},[B,Re]),Je=(0,X.useCallback)(async e=>{try{await k.delete(`/api/library/comments/${e}?thread=1`),Ne(null),F({kind:`list`}),await B()}catch(e){H.error(e instanceof D?e.message:`Could not delete that`)}},[B]),Ye=(0,Z.jsx)(Zi,{open:!!ve,onOpenChange:e=>{e||ye(null)},children:(0,Z.jsxs)(ea,{children:[(0,Z.jsxs)(ta,{children:[(0,Z.jsx)(ra,{children:`Delete this thread?`}),(0,Z.jsx)(ia,{children:`This deletes every message in it for everyone in the workspace. Archive it to hide it instead.`})]}),(0,Z.jsxs)(na,{children:[(0,Z.jsx)(oa,{children:`Cancel`}),(0,Z.jsx)(aa,{onClick:()=>{let e=ve;ye(null),e&&Je(e)},children:`Delete`})]})]})});if(P.kind===`thread`){let r=(Me?.id===P.id?Me:null)??j?.find(e=>e.id===P.id),i=Fe?.id===P.id?Fe:null;return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(Ra,{sheet:C,tabBar:O,thread:r,inTarget:!!e,picture:r?.target?.kind===`item`?se.get(r.target.id)??null:null,loading:j===null||!r&&Me===null&&!i,unreadable:!!i&&!i.missing,currentUserId:t,onBack:()=>F({kind:`list`}),onOpenTarget:n,onResolve:e=>r&&void Ge(r,e),onDelete:e=>e.id===e.root_id?ye(P.id):void qe(e),onEdit:Ke,canInvite:ee,onInvite:te,onDeleteThread:()=>ye(P.id),faceOf:ie,onClose:o,onSeek:u,onRegionActivate:b,regionLabel:x,onSend:(e,t)=>We(e,t,{parentId:P.id})}),Ye]})}let Xe=d?.()??null,Qe=p?.()??null,$e=(0,Z.jsx)(Ca,{placeholder:`Write a commentâ¦`,currentUserId:t,autoFocus:P.kind===`new`,focusNonce:Ee,onEscape:P.kind===`new`?()=>F({kind:`list`}):void 0,canInvite:ee,onInvite:te,onSend:(e,t)=>We(e,t),accessories:(0,Z.jsxs)(Z.Fragment,{children:[p&&(Qe||we)&&(0,Z.jsx)(Hn,{text:we?`Not about this clip`:`This comment is about ${Qe?.name??`this clip`}`,children:(0,Z.jsxs)(`button`,{type:`button`,"aria-label":we?`Not about this clip`:`About this clip`,onClick:()=>Te(we?null:Qe),className:N(Aa,`max-w-[110px]`,we?Ma:ja),children:[(0,Z.jsx)(le,{className:`h-3 w-3 flex-shrink-0`,strokeWidth:1.8}),(0,Z.jsx)(`span`,{className:`truncate`,children:(we??Qe)?.name??`Clip`})]})}),l&&(0,Z.jsx)(Hn,{text:be===null?Xe?`Pin to the marked stretch`:`Pin to the moment on screen`:`Remove the time`,children:(0,Z.jsxs)(`button`,{type:`button`,"aria-label":be===null?`Pin to the moment on screen`:`Remove the time`,onClick:()=>{if(be!==null){xe(null),Ce(null);return}if(Xe){xe(Xe.from),Ce(Xe.to);return}xe(l()),Ce(null)},className:N(Aa,`tabular-nums`,be===null?ja:Ma),children:[(0,Z.jsx)(Ze,{className:`h-3 w-3 max-md:h-3.5 max-md:w-3.5`,strokeWidth:1.8}),be===null?Xe?`Pin stretch`:`Pin time`:Se===null?q(be):`${q(be)}â${q(Se)}`]})}),h&&(0,Z.jsx)(Hn,{text:m?`Remove the pin`:g?`Stop drawing`:`Draw a box to pin this comment to`,children:(0,Z.jsxs)(`button`,{type:`button`,"aria-label":m?`Remove the pin`:g?`Stop drawing`:`Pin to a place`,onClick:()=>m||g?_?.():h(),className:N(Aa,m||g?Ma:ja),children:[(0,Z.jsx)(Pe,{className:`h-3 w-3 max-md:h-3.5 max-md:w-3.5`,strokeWidth:1.8}),m?`Pinned`:g?`Drawing`:`Pin`]})})]})});if(P.kind===`new`)return(0,Z.jsxs)(`div`,{className:`flex h-full flex-col`,children:[(0,Z.jsxs)(`div`,{className:N(`relative flex h-10 flex-shrink-0 items-center gap-0.5 pl-1.5 pr-1.5 max-md:pl-2 max-md:pr-1.5`,C?`max-md:h-10`:`max-md:h-12`,O&&`max-md:!h-10 max-md:px-1`),children:[(0,Z.jsx)(`button`,{type:`button`,onClick:()=>F({kind:`list`}),"aria-label":`Back`,className:O?Da:Oa,children:(0,Z.jsx)(He,{className:O?`h-5 w-5`:`h-[15px] w-[15px] max-md:h-[18px] max-md:w-[18px]`,strokeWidth:1.7})}),(0,Z.jsx)(`span`,{className:O?`pointer-events-none absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 text-[15.5px] font-[460] leading-[22px] text-foreground`:`text-[12px] max-md:text-[15px] font-[440] text-foreground`,children:`New comment`}),(0,Z.jsx)(`div`,{className:`flex-1`}),o&&!O&&(0,Z.jsx)(`button`,{type:`button`,"aria-label":`Close`,onClick:o,className:Oa,children:(0,Z.jsx)(_t,{className:`h-[15px] w-[15px] max-md:h-[18px] max-md:w-[18px]`,strokeWidth:1.7})})]}),c,(0,Z.jsx)(`div`,{className:`min-h-0 flex-1`}),(0,Z.jsx)(`div`,{className:`flex-shrink-0 px-2 pb-2 max-md:px-3 max-md:pb-3`,children:$e})]});let et=j??[],tt=L===`open`&&et.length===0&&!ue.trim()&&!I,rt=et.filter(e=>e.unread||e.waiting_on_me),it=et.filter(e=>!e.unread&&!e.waiting_on_me),at=ne??[],ot=t=>(0,Z.jsx)(La,{thread:t,inTarget:!!e,picture:t.target?.kind===`item`?se.get(t.target.id)??null:null,faceOf:ie,onOpen:()=>
2Ue(t.id),onResolve:()=>void Ge(t,!t.resolved)},t.id),st=(0,Z.jsx)(`div`,{className:N(`relative flex h-10 flex-shrink-0 items-center gap-0.5 pl-3 pr-1.5 max-md:pl-3 max-md:pr-1.5`,C?`max-md:h-10`:`max-md:h-12`,O&&!ge&&`max-md:!h-10 max-md:px-1`),children:ge&&!e?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(nt,{className:`mr-1.5 h-3 w-3 max-md:mr-2 max-md:h-4 max-md:w-4 flex-shrink-0 text-zinc-400`,strokeWidth:1.8}),(0,Z.jsx)(`input`,{autoFocus:!0,value:ue,onChange:e=>de(e.target.value),onKeyDown:e=>{e.key===`Escape`&&(de(``),_e(!1)),e.stopPropagation()},placeholder:`Find a commentâ¦`,"aria-label":`Find a comment`,className:`h-full min-w-0 flex-1 bg-transparent text-[12px] max-md:text-[14.5px] text-foreground outline-none placeholder:text-zinc-400 dark:placeholder:text-zinc-500`}),at.length>1&&(0,Z.jsxs)(hn,{children:[(0,Z.jsx)(dn,{asChild:!0,children:(0,Z.jsx)(`button`,{type:`button`,"aria-label":I?`Written by ${I.label}`:`Anyone`,className:N(Oa,I&&`text-foreground`),children:(0,Z.jsx)(Ae,{className:`h-[15px] w-[15px] max-md:h-[18px] max-md:w-[18px]`,strokeWidth:1.7})})}),(0,Z.jsxs)(mn,{align:`end`,className:`w-48`,children:[(0,Z.jsxs)(G,{onSelect:()=>me(null),children:[`Anyone`,!I&&(0,Z.jsx)(V,{className:N(`ml-auto`,`h-3 w-3 max-md:h-3.5 max-md:w-3.5 flex-shrink-0 text-foreground`),strokeWidth:2})]}),at.map(e=>(0,Z.jsxs)(G,{onSelect:()=>me(e),className:`gap-2`,children:[(0,Z.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:e.label}),I?.id===e.id&&I?.type===e.type&&(0,Z.jsx)(V,{className:`h-3 w-3 max-md:h-3.5 max-md:w-3.5 flex-shrink-0 text-foreground`,strokeWidth:2})]},`${e.type}-${e.id}`))]})]}),(0,Z.jsx)(`button`,{type:`button`,"aria-label":`Close search`,onClick:()=>{de(``),_e(!1)},className:Oa,children:(0,Z.jsx)(_t,{className:`h-[15px] w-[15px] max-md:h-[18px] max-md:w-[18px]`,strokeWidth:1.7})})]}):O?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`button`,{type:`button`,"aria-label":L===`archived`?`Back to the list`:`The archive`,"aria-pressed":L===`archived`,onClick:()=>{M(null),he(L===`archived`?`open`:`archived`)},className:N(Da,L===`archived`&&`bg-zinc-100 dark:bg-white/[0.08]`),children:(0,Z.jsx)(Oe,{className:`h-[18px] w-[18px]`,strokeWidth:1.6})}),a&&(0,Z.jsx)(`span`,{className:`pointer-events-none absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 text-[15.5px] font-[460] leading-[22px] text-foreground`,children:a}),(0,Z.jsx)(`div`,{className:`flex-1`}),s,(0,Z.jsx)(`button`,{type:`button`,"aria-label":`New comment`,onClick:()=>F({kind:`new`}),className:Da,children:(0,Z.jsx)(gt,{className:`h-5 w-5`,strokeWidth:1.8})})]}):(0,Z.jsxs)(Z.Fragment,{children:[a&&(0,Z.jsx)(`span`,{className:N(`text-[12px] font-[440] text-foreground`,C?`max-md:text-[14.5px]`:`max-md:text-[15px]`),children:a}),(0,Z.jsx)(`div`,{className:`flex-1`}),s,!e&&!tt&&(0,Z.jsx)(`button`,{type:`button`,"aria-label":`Find a comment`,onClick:()=>_e(!0),className:Oa,children:(0,Z.jsx)(nt,{className:`h-[15px] w-[15px] max-md:h-[18px] max-md:w-[18px]`,strokeWidth:1.7})}),!e&&(0,Z.jsx)(`button`,{type:`button`,"aria-label":`New comment`,onClick:()=>F({kind:`new`}),className:Oa,children:(0,Z.jsx)(gt,{className:`h-[15px] w-[15px] max-md:h-5 max-md:w-5`,strokeWidth:1.7})}),(0,Z.jsx)(`button`,{type:`button`,"aria-label":L===`archived`?`Back to the list`:`The archive`,"aria-pressed":L===`archived`,onClick:()=>{M(null),he(L===`archived`?`open`:`archived`)},className:N(Oa,L===`archived`&&`text-foreground`),children:(0,Z.jsx)(Oe,{className:`h-[13px] w-[13px] max-md:h-4 max-md:w-4`,strokeWidth:1.7})}),o&&(0,Z.jsx)(`button`,{type:`button`,"aria-label":`Close`,onClick:o,className:Oa,children:(0,Z.jsx)(_t,{className:`h-[15px] w-[15px] max-md:h-[18px] max-md:w-[18px]`,strokeWidth:1.7})})]})});return(0,Z.jsxs)(`div`,{className:`flex h-full flex-col`,children:[st,c,O&&!tt&&(0,Z.jsxs)(`div`,{className:`flex flex-shrink-0 items-center gap-2 px-3 pb-1 pt-1`,children:[(0,Z.jsxs)(`div`,{className:`flex h-10 min-w-0 flex-1 items-center gap-2 rounded-full bg-zinc-100 px-3.5 dark:bg-white/[0.06]`,children:[(0,Z.jsx)(nt,{className:`h-4 w-4 flex-shrink-0 text-zinc-400 dark:text-zinc-500`,strokeWidth:1.6}),(0,Z.jsx)(`input`,{value:ue,onChange:e=>de(e.target.value),placeholder:`Search commentsâ¦`,"aria-label":`Search comments`,className:`min-w-0 flex-1 bg-transparent text-[14px] font-[400] text-foreground outline-none placeholder:text-zinc-400 dark:placeholder:text-zinc-500`}),(0,Z.jsx)(Zn,{value:ue,onClear:()=>de(``)})]}),at.length>1&&(0,Z.jsxs)(hn,{children:[(0,Z.jsx)(dn,{asChild:!0,children:(0,Z.jsx)(`button`,{type:`button`,"aria-label":I?`Written by ${I.label}`:`Anyone`,className:N(`flex h-10 w-10 flex-shrink-0 items-center justify-center rounded-full bg-zinc-100 text-zinc-600 dark:bg-white/[0.06] dark:text-zinc-300`,I&&`text-foreground`),children:(0,Z.jsx)(Ae,{className:`h-[18px] w-[18px]`,strokeWidth:1.6})})}),(0,Z.jsxs)(mn,{align:`end`,className:`w-48`,children:[(0,Z.jsxs)(G,{onSelect:()=>me(null),children:[`Anyone`,!I&&(0,Z.jsx)(V,{className:N(`ml-auto`,`h-3 w-3 max-md:h-3.5 max-md:w-3.5 flex-shrink-0 text-foreground`),strokeWidth:2})]}),at.map(e=>(0,Z.jsxs)(G,{onSelect:()=>me(e),className:`gap-2`,children:[(0,Z.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:e.label}),I?.id===e.id&&I?.type===e.type&&(0,Z.jsx)(V,{className:`h-3 w-3 max-md:h-3.5 max-md:w-3.5 flex-shrink-0 text-foreground`,strokeWidth:2})]},`${e.type}-${e.id}`))]})]})]}),(0,Z.jsx)(`div`,{className:N(`min-h-0 flex-1 overflow-y-auto px-2 pb-2 max-md:px-3 max-md:pt-2 scrollbar-thin`,O&&`max-md:pb-[calc(84px+env(safe-area-inset-bottom))]`),children:j===null?(0,Z.jsx)(`div`,{className:`flex h-full items-center justify-center`,children:(0,Z.jsx)(Bn,{})}):et.length===0?(0,Z.jsx)(`div`,{className:`flex h-full items-center justify-center px-4 text-center text-12 font-[400] text-zinc-400 dark:text-zinc-500`,children:L===`archived`?`No archived comments`:ue.trim()||I?`No comments match that`:`No comments yet`}):L===`archived`?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(Pa,{children:`Archive`}),et.map(ot)]}):(0,Z.jsxs)(Z.Fragment,{children:[rt.length>0&&!e&&(0,Z.jsx)(Pa,{children:`For you`}),rt.map(ot),it.length>0&&rt.length>0&&!e&&(0,Z.jsx)(Pa,{children:`Everything else`}),it.map(ot)]})}),e&&(0,Z.jsx)(`div`,{className:`flex-shrink-0 px-2 pb-2 max-md:px-3 max-md:pb-3`,children:$e}),Ye]})}function Pa({children:e}){return(0,Z.jsx)(`p`,{className:`px-1 pb-2 pt-0.5 text-[12px] max-md:px-2 max-md:pt-1.5 max-md:text-[13px] font-[400] text-zinc-500 dark:text-zinc-400`,children:e})}function Fa(e){if(!e)return null;let t=e.storage_metadata??{};return t.thumbnail_url||t.poster_url||(Qn(e)===`image`&&e.url?J(e.url):null)}function Ia({src:e,icon:t,size:n}){let[r,i]=(0,X.useState)(!1),a=n===`lg`?`h-16 w-16`:n===`sm`?`h-8 w-8 max-md:h-10 max-md:w-10`:`h-6
2w-6 max-md:h-8 max-md:w-8`;return e&&!r?(0,Z.jsx)(`img`,{src:e,alt:``,loading:`lazy`,onError:()=>i(!0),className:N(a,`flex-shrink-0 rounded-[4px] bg-zinc-100 object-cover dark:bg-white/[0.06]`)}):t?(0,Z.jsx)(`span`,{className:N(`flex flex-shrink-0 items-center justify-center rounded-[4px] bg-zinc-100 dark:bg-white/[0.06]`,a),children:(0,Z.jsx)(t,{className:n===`lg`?`h-5 w-5 text-zinc-400 dark:text-zinc-500`:n===`sm`?`h-3.5 w-3.5 max-md:h-[18px] max-md:w-[18px] text-zinc-400 dark:text-zinc-500`:`h-3 w-3 max-md:h-4 max-md:w-4 text-zinc-400 dark:text-zinc-500`,strokeWidth:n===`sm`?1.5:n===`lg`?1.4:1.6})}):null}function La({thread:e,inTarget:t,picture:n,faceOf:r,onOpen:i,onResolve:a}){let o=e.target?la[e.target.kind]:null,s=f()===!0;if(s&&!t&&e.target)return(0,Z.jsxs)(`button`,{type:`button`,onClick:i,className:N(`-mx-3 flex w-[calc(100%+24px)] items-start gap-3 px-3 py-1.5 text-left transition-colors active:bg-zinc-100 dark:active:bg-white/[0.04]`,e.resolved&&`opacity-60`),children:[(0,Z.jsx)(Ia,{src:n??null,icon:o,size:`lg`}),(0,Z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Z.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[e.unread&&(0,Z.jsx)(`span`,{"aria-label":`New`,className:wa}),(0,Z.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-[14px] font-[400] text-foreground`,children:e.target.title}),(0,Z.jsx)(`span`,{className:`flex-shrink-0 text-[12.5px] tabular-nums text-zinc-400 dark:text-zinc-500`,children:Kn(e.last_at)})]}),(0,Z.jsxs)(`p`,{dir:`auto`,className:`mt-0.5 line-clamp-2 break-words text-[13.5px] font-[380] leading-[19px] text-zinc-500 dark:text-zinc-400`,children:[(0,Z.jsx)(`span`,{className:`font-[400] text-zinc-600 dark:text-zinc-300`,children:fa(e.root)}),` `,e.root.body.replace(/\s+/g,` `)]}),(e.replies>0||e.waiting_on_me&&!e.resolved)&&(0,Z.jsxs)(`div`,{className:`mt-1 flex items-center gap-1.5 text-[12.5px] text-zinc-400 dark:text-zinc-500`,children:[e.waiting_on_me&&!e.resolved&&(0,Z.jsx)(`span`,{className:`font-[440] text-foreground`,children:`Waiting on you`}),e.waiting_on_me&&!e.resolved&&e.replies>0&&(0,Z.jsx)(`span`,{"aria-hidden":!0,children:`·`}),e.replies>0&&(0,Z.jsxs)(`span`,{children:[e.replies+1,` comments`]})]})]})]});if(s)return(0,Z.jsxs)(`button`,{type:`button`,onClick:i,className:N(`-mx-3 flex w-[calc(100%+24px)] items-start gap-3 px-3 py-1.5 text-left transition-colors active:bg-zinc-100 dark:active:bg-white/[0.04]`,e.resolved&&`opacity-60`),children:[(0,Z.jsx)(`span`,{className:`flex h-8 w-8 flex-shrink-0 items-center justify-center`,children:(0,Z.jsx)(da,{author:e.root,avatarUrl:r?.(e.root),className:`h-8 w-8`})}),(0,Z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Z.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[e.unread&&(0,Z.jsx)(`span`,{"aria-label":`New`,className:wa}),(0,Z.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-[14px] font-[400] text-foreground`,children:fa(e.root)}),e.root.timestamp_seconds!=null&&(0,Z.jsxs)(`span`,{className:Ea,children:[(0,Z.jsx)(Ze,{className:`h-3 w-3`,strokeWidth:1.8}),e.root.timestamp_end_seconds==null?q(e.root.timestamp_seconds):`${q(e.root.timestamp_seconds)}â${q(e.root.timestamp_end_seconds)}`]}),(0,Z.jsx)(`span`,{className:`flex-shrink-0 text-[12.5px] tabular-nums text-zinc-400 dark:text-zinc-500`,children:Kn(e.last_at)})]}),(0,Z.jsx)(`p`,{dir:`auto`,className:`mt-0.5 line-clamp-2 whitespace-pre-wrap break-words text-[13.5px] font-[380] leading-[19px] text-zinc-500 dark:text-zinc-400`,children:(0,Z.jsx)(pa,{body:e.root.body,mentions:e.root.mentions})}),(e.replies>0||e.waiting_on_me&&!e.resolved)&&(0,Z.jsxs)(`div`,{className:`mt-1 flex items-center gap-1.5 text-[12.5px] text-zinc-400 dark:text-zinc-500`,children:[e.waiting_on_me&&!e.resolved&&(0,Z.jsx)(`span`,{className:`font-[440] text-foreground`,children:`Waiting on you`}),e.waiting_on_me&&!e.resolved&&e.replies>0&&(0,Z.jsx)(`span`,{"aria-hidden":!0,children:`·`}),e.replies>0&&(0,Z.jsxs)(`span`,{children:[e.replies+1,` comments`]})]})]})]});let c=(0,Z.jsx)(`button`,{type:`button`,"aria-label":e.resolved?`Bring back from the archive`:`Archive`,onClick:e=>{e.stopPropagation(),a()},className:N(`flex h-5 w-5 max-md:h-8 max-md:w-8 flex-shrink-0 items-center justify-center text-zinc-400 opacity-0 transition duration-100 hover:text-foreground focus-visible:opacity-100 group-hover:opacity-100 [@media(hover:none)]:opacity-100 dark:text-zinc-500`,e.resolved&&`opacity-100`),children:e.resolved?(0,Z.jsx)(De,{className:`h-3 w-3 max-md:h-4 max-md:w-4`,strokeWidth:1.7}):(0,Z.jsx)(Oe,{className:`h-3 w-3 max-md:h-4 max-md:w-4`,strokeWidth:1.7})});return(0,Z.jsx)(`div`,{className:N(`group relative rounded-[8px] transition-colors duration-100 hover:bg-zinc-100 dark:hover:bg-white/[0.04]`,e.resolved&&`opacity-60`,`mb-1`),children:(0,Z.jsxs)(`div`,{role:`button`,tabIndex:0,onClick:i,onKeyDown:e=>{e.target===e.currentTarget&&(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),i())},className:N(`flex w-full cursor-pointer gap-2.5 px-2 py-2 text-left outline-none max-md:gap-3 max-md:py-2.5`,!t&&e.target&&`items-center py-1.5 pl-1.5 max-md:py-2`),children:[!t&&e.target&&(0,Z.jsx)(Ia,{src:n??null,icon:o,size:`sm`}),(0,Z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[!t&&e.target?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`div`,{className:`flex min-h-[16px] min-w-0 items-center gap-1.5 text-[12px]`,children:[e.unread&&(0,Z.jsx)(`span`,{"aria-label":`New`,className:wa}),(0,Z.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-[11.5px] max-md:text-[14px] font-[440] text-zinc-600 dark:text-zinc-300`,children:e.target.title}),c]}),(0,Z.jsxs)(`div`,{className:`mt-0.5 flex min-w-0 items-center gap-2 text-[11.5px] max-md:text-[13px] font-[400] text-zinc-400 dark:text-zinc-500`,children:[(0,Z.jsxs)(`span`,{dir:`auto`,className:`min-w-0 flex-1 truncate`,children:[fa(e.root),`: `,e.root.body.replace(/\s+/g,` `)]}),(0,Z.jsxs)(`span`,{className:`flex-shrink-0 tabular-nums`,children:[e.replies>0&&(0,Z.jsxs)(Z.Fragment,{children:[e.replies+1,` comments`,(0,Z.jsx)(`span`,{"aria-hidden":!0,
2className:`mx-1.5`,children:`·`})]}),Kn(e.last_at)]})]})]}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`div`,{className:`flex min-h-[16px] min-w-0 items-center gap-1.5 text-[12px] max-md:gap-2 max-md:text-[14px] font-[400]`,children:[e.unread&&(0,Z.jsx)(`span`,{"aria-label":`New`,className:wa}),(0,Z.jsx)(da,{author:e.root,avatarUrl:r?.(e.root),className:Ta}),(0,Z.jsx)(`span`,{className:`min-w-0 truncate font-[440] text-foreground`,children:fa(e.root)}),e.root.timestamp_seconds!=null&&(0,Z.jsxs)(`span`,{className:Ea,children:[(0,Z.jsx)(Ze,{className:`h-2.5 w-2.5`,strokeWidth:1.8}),e.root.timestamp_end_seconds==null?q(e.root.timestamp_seconds):`${q(e.root.timestamp_seconds)}â${q(e.root.timestamp_end_seconds)}`]}),(0,Z.jsxs)(`span`,{className:`ml-auto flex flex-shrink-0 items-center gap-0.5 pl-2`,children:[c,(0,Z.jsxs)(`span`,{className:`text-[11px] max-md:text-[12.5px] tabular-nums text-zinc-400 dark:text-zinc-500`,children:[e.replies>0&&(0,Z.jsxs)(Z.Fragment,{children:[e.replies+1,` comments`,(0,Z.jsx)(`span`,{"aria-hidden":!0,className:`mx-1.5`,children:`·`})]}),Kn(e.last_at)]})]})]}),(0,Z.jsx)(`p`,{dir:`auto`,className:`mt-1 line-clamp-2 whitespace-pre-wrap break-words text-[12px] max-md:text-[14.5px] font-[380] leading-relaxed text-zinc-600 dark:text-zinc-300`,children:(0,Z.jsx)(pa,{body:e.root.body,mentions:e.root.mentions})})]}),e.waiting_on_me&&!e.resolved&&(0,Z.jsx)(`div`,{className:`mt-1.5 text-[12px] max-md:text-[13.5px] font-[440] text-foreground`,children:`Waiting on you`})]})]})})}function Ra({thread:e,inTarget:t,picture:n,loading:r,unreadable:i,currentUserId:a,onBack:o,onOpenTarget:s,onResolve:c,onDelete:l,onEdit:u,canInvite:d,onInvite:p,onDeleteThread:m,onSeek:h,onRegionActivate:g,regionLabel:_,onSend:v,faceOf:y,onClose:b,sheet:x=!1,tabBar:S=!1}){let C=f()===!0,w=(0,X.useRef)(null),T=(0,X.useRef)(null),[E,D]=(0,X.useState)(null),[O,k]=(0,X.useState)(``),ee=(0,X.useRef)(!1),[te,ne]=(0,X.useState)(!0);(0,X.useEffect)(()=>{w.current?.scrollIntoView({block:`end`})},[e?.comments?.length]);let re=(0,X.useCallback)(()=>{let e=T.current;e&&ne(e.scrollHeight-e.scrollTop-e.clientHeight<24)},[]);if(!e)return(0,Z.jsxs)(`div`,{className:`flex h-full flex-col`,children:[(0,Z.jsx)(`div`,{className:N(`flex h-10 flex-shrink-0 items-center gap-0.5 pl-1.5 pr-1.5 max-md:pl-2 max-md:pr-1.5`,x?`max-md:h-10`:`max-md:h-12`,S&&`max-md:!h-10 max-md:px-1`),children:(0,Z.jsx)(`button`,{type:`button`,onClick:o,"aria-label":`Back`,className:S?Da:Oa,children:(0,Z.jsx)(He,{className:S?`h-5 w-5`:`h-[15px] w-[15px] max-md:h-[18px] max-md:w-[18px]`,strokeWidth:1.7})})}),r?(0,Z.jsx)(`div`,{className:`flex h-full items-center justify-center`,children:(0,Z.jsx)(Bn,{})}):(0,Z.jsx)(`div`,{className:`flex h-full items-center justify-center px-4 text-center text-[12px] max-md:text-[14px] font-[400] text-zinc-500 dark:text-zinc-400`,children:i?`Could not load this conversation.`:`That conversation is no longer here.`})]});let A=e.target?la[e.target.kind]:null,ie=e.comments??[e.root],ae=C&&!t&&e.target?.kind===`item`&&s?()=>e.target&&s(e.target,e.id):null;return(0,Z.jsxs)(`div`,{className:`flex h-full flex-col`,children:[(0,Z.jsxs)(`div`,{className:N(`flex h-10 flex-shrink-0 items-center gap-0.5 pl-1.5 pr-1.5 max-md:pl-2 max-md:pr-1.5`,x?`max-md:h-10`:`max-md:h-12`,S&&`max-md:!h-10 max-md:mb-1 max-md:px-1`),children:[(0,Z.jsx)(`button`,{type:`button`,onClick:o,"aria-label":`Back`,className:S?Da:Oa,children:(0,Z.jsx)(He,{className:S?`h-5 w-5`:`h-[15px] w-[15px] max-md:h-[18px] max-md:w-[18px]`,strokeWidth:1.7})}),(0,Z.jsx)(`div`,{className:`flex-1`}),(0,Z.jsx)(Hn,{text:e.resolved?`Bring back from the archive`:`Archive`,children:(0,Z.jsx)(`button`,{type:`button`,"aria-label":e.resolved?`Bring back from the archive`:`Archive`,onClick:()=>c(!e.resolved),className:S?Da:Oa,children:e.resolved?(0,Z.jsx)(De,{className:S?`h-[18px] w-[18px]`:`h-[13px] w-[13px] max-md:h-4 max-md:w-4`,strokeWidth:1.7}):(0,Z.jsx)(Oe,{className:S?`h-[18px] w-[18px]`:`h-[13px] w-[13px] max-md:h-4 max-md:w-4`,strokeWidth:1.7})})}),m&&(0,Z.jsx)(Hn,{text:`Delete thread`,children:(0,Z.jsx)(`button`,{type:`button`,"aria-label":`Delete thread`,onClick:m,className:S?Da:Oa,children:(0,Z.jsx)(Ke,{className:S?`h-[18px] w-[18px]`:`h-[13px] w-[13px] max-md:h-4 max-md:w-4`,strokeWidth:1.7})})}),b&&!S&&(0,Z.jsx)(`button`,{type:`button`,"aria-label":`Close`,onClick:b,className:Oa,children:(0,Z.jsx)(_t,{className:`h-[15px] w-[15px] max-md:h-[18px] max-md:w-[18px]`,strokeWidth:1.7})})]}),!t&&e.target&&A&&s&&(e.target.kind===`item`||!C)&&(0,Z.jsx)(`div`,{className:`flex-shrink-0 px-2 pb-2 max-md:px-3`,children:(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>e.target&&s(e.target,e.id),className:`flex w-full min-w-0 items-center gap-2 rounded-[8px] px-1.5 py-1.5 text-left text-[12px] max-md:gap-3 max-md:px-2 max-md:text-[14px] font-[400] text-zinc-600 transition-colors hover:bg-zinc-100 hover:text-foreground dark:text-zinc-300 dark:hover:bg-white/[0.04] dark:hover:text-white`,children:[(0,Z.jsx)(Ia,{src:n??null,icon:A,size:`xs`}),(0,Z.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:e.target.title}),(0,Z.jsx)(he,{className:`h-3 w-3 max-md:hidden flex-shrink-0 text-zinc-400 dark:text-zinc-500`,strokeWidth:1.7})]})}),(0,Z.jsxs)(`div`,{ref:T,onScroll:re,className:`relative min-h-0 flex-1 space-y-1.5 overflow-y-auto px-2 pb-2 max-md:space-y-2 max-md:px-3 scrollbar-thin`,children:[ie.map(e=>(0,Z.jsxs)(`div`,{className:`group rounded-[8px] bg-zinc-100/60 px-2.5 py-2.5 max-md:px-3.5 max-md:pb-3 max-md:pt-2.5 dark:bg-white/[0.04]`,children:[(0,Z.jsxs)(`div`,{className:`flex min-h-[16px] items-center gap-1.5 max-md:gap-2`,children:[(0,Z.jsx)(da,{author:e,avatarUrl:y?.(e),className:Ta}),(0,Z.jsx)(`span`,{className:`min-w-0 truncate text-[12px] max-md:text-[14px] font-[440] text-foreground`,children:fa(e)}
2),e.region&&C&&!g&&ae&&(0,Z.jsxs)(`button`,{type:`button`,onClick:ae,"aria-label":`Open where this comment points`,className:N(Ea,`max-w-[140px]`),children:[(0,Z.jsx)(Pe,{className:`h-3 w-3 flex-shrink-0`,strokeWidth:1.8}),(0,Z.jsx)(`span`,{className:`truncate`,children:_?.(e.region)??e.region.clipName??`Area`})]}),e.timestamp_seconds!==null&&C&&!h&&ae&&(0,Z.jsxs)(`button`,{type:`button`,onClick:ae,"aria-label":`Open at this moment`,className:Ea,children:[(0,Z.jsx)(Ze,{className:`h-3 w-3`,strokeWidth:1.8}),e.timestamp_end_seconds==null?q(e.timestamp_seconds):`${q(e.timestamp_seconds)}â${q(e.timestamp_end_seconds)}`]}),e.region&&!(C&&!g)&&(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>g?.(e.id),"aria-label":`Show where this comment points`,className:N(Ea,`max-w-[120px] transition-colors hover:bg-zinc-200 dark:hover:bg-white/[0.12]`),children:[e.region.clipId?(0,Z.jsx)(le,{className:`h-2.5 w-2.5 flex-shrink-0`,strokeWidth:1.8}):(0,Z.jsx)(Pe,{className:`h-2.5 w-2.5 flex-shrink-0`,strokeWidth:1.8}),(0,Z.jsx)(`span`,{className:`truncate`,children:_?.(e.region)??e.region.clipName??`Area`})]}),e.timestamp_seconds!==null&&!(C&&!h)&&(0,Z.jsxs)(`button`,{type:`button`,"aria-label":`Go to this moment`,onClick:()=>h?.(e.timestamp_seconds),className:N(Ea,`transition-colors hover:bg-zinc-200 dark:hover:bg-white/[0.12]`),children:[(0,Z.jsx)(Ze,{className:`h-2.5 w-2.5`,strokeWidth:1.8}),e.timestamp_end_seconds==null?q(e.timestamp_seconds):`${q(e.timestamp_seconds)}â${q(e.timestamp_end_seconds)}`]}),!C&&(0,Z.jsx)(`span`,{className:`ml-auto flex items-center gap-0.5 opacity-0 transition-opacity group-hover:opacity-100 [@media(hover:none)]:opacity-100`,children:e.author_type===`user`&&a&&e.author_id===a&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`button`,{type:`button`,"aria-label":`Edit`,onClick:()=>{ee.current=!1,D(e.id),k(e.body)},className:`flex h-5 w-5 items-center justify-center text-zinc-400 transition-colors hover:text-foreground [@media(pointer:coarse)]:h-7 [@media(pointer:coarse)]:w-7 max-md:!h-8 max-md:!w-8 dark:text-zinc-500`,children:(0,Z.jsx)(Fe,{className:`h-3 w-3 max-md:h-4 max-md:w-4`,strokeWidth:1.7})}),(0,Z.jsx)(`button`,{type:`button`,"aria-label":`Delete`,onClick:()=>l(e),className:`flex h-5 w-5 items-center justify-center text-zinc-400 transition-colors hover:text-foreground [@media(pointer:coarse)]:h-7 [@media(pointer:coarse)]:w-7 max-md:!h-8 max-md:!w-8 dark:text-zinc-500`,children:(0,Z.jsx)(Ke,{className:`h-3 w-3 max-md:h-4 max-md:w-4`,strokeWidth:1.7})})]})}),(0,Z.jsx)(`span`,{className:N(`flex-shrink-0 pl-1 text-[11px] max-md:text-[12.5px] font-[400] tabular-nums text-zinc-400 dark:text-zinc-500`,C&&`ml-auto`),children:Kn(e.created_at)}),C&&e.author_type===`user`&&a&&e.author_id===a&&(0,Z.jsxs)(hn,{children:[(0,Z.jsx)(dn,{asChild:!0,children:(0,Z.jsx)(`button`,{type:`button`,"aria-label":`More`,className:`-my-1.5 -mr-2 flex h-8 w-8 flex-shrink-0 items-center justify-center text-zinc-400 dark:text-zinc-500`,children:(0,Z.jsx)(ve,{className:`h-4 w-4`,strokeWidth:1.7})})}),(0,Z.jsxs)(mn,{align:`end`,onCloseAutoFocus:e=>e.preventDefault(),children:[(0,Z.jsx)(G,{onSelect:()=>{ee.current=!1,D(e.id),k(e.body)},children:`Edit`}),(0,Z.jsx)(G,{onSelect:()=>l(e),children:`Delete`})]})]})]}),E===e.id?(0,Z.jsx)(`textarea`,{dir:`auto`,autoFocus:!0,value:O,onChange:e=>k(e.target.value),onKeyDown:t=>{if(t.key===`Escape`){ee.current=!0,D(null);return}t.key===`Enter`&&!t.shiftKey&&Hr()&&(t.preventDefault(),ee.current=!0,u(e,O).then(e=>{e?D(null):ee.current=!1}))},onBlur:()=>{ee.current||u(e,O).then(e=>{e&&D(null)})},rows:Math.min(8,O.split(` 3`).length+1),className:`mt-1.5 w-full resize-none rounded-[8px] border border-black/[0.08] bg-white px-2 py-1.5 text-[12px] max-md:mt-2 max-md:text-[14.5px] font-[380] leading-relaxed text-zinc-600 outline-none dark:border-white/[0.08] dark:bg-white/[0.03] dark:text-zinc-300`}):null,E===e.id&&(0,Z.jsxs)(`div`,{className:`mt-2 hidden items-center justify-end gap-1 max-md:flex`,children:[(0,Z.jsx)(`button`,{type:`button`,onPointerDown:e=>e.preventDefault(),onMouseDown:e=>e.preventDefault(),onClick:()=>{ee.current=!0,D(null)},className:`inline-flex h-8 items-center justify-center px-2.5 text-[11.5px] max-md:h-9 max-md:px-3.5 max-md:text-[13.5px] font-[400] text-zinc-500 outline-none transition-colors duration-100 hover:text-foreground focus-visible:text-foreground disabled:opacity-40 dark:text-zinc-400 dark:hover:text-foreground dark:focus-visible:text-foreground`,children:`Cancel`}),(0,Z.jsx)(`button`,{type:`button`,onPointerDown:e=>e.preventDefault(),onMouseDown:e=>e.preventDefault(),onClick:()=>{ee.current=!0,u(e,O).then(e=>{e?D(null):ee.current=!1})},className:`flex h-8 items-center gap-1.5 rounded-full bg-zinc-900 px-3.5 text-[11.5px] max-md:h-9 max-md:text-[13.5px] font-[440] leading-none text-white transition-colors duration-100 hover:bg-zinc-800 disabled:opacity-40 dark:bg-white dark:text-black dark:hover:bg-zinc-200`,children:`Save`})]}),E===e.id?null:(0,Z.jsx)(`p`,{dir:`auto`,className:`mt-1.5 whitespace-pre-wrap break-words text-[12px] max-md:mt-2 max-md:text-[14.5px] font-[380] leading-relaxed text-zinc-600 dark:text-zinc-300`,children:(0,Z.jsx)(pa,{body:e.body,mentions:e.mentions})})]},e.id)),(0,Z.jsx)(`div`,{ref:w})]}),(0,Z.jsxs)(`div`,{className:`relative flex-shrink-0 px-2 pb-2 max-md:px-3 max-md:pb-3`,children:[!te&&(0,Z.jsx)(`button`,{type:`button`,"aria-label":`Newest`,onClick:()=>w.current?.scrollIntoView({behavior:`smooth`,block:`end`}),className:`absolute -top-9 right-3 flex h-7 w-7 max-md:-top-11 max-md:right-4 max-md:h-9 max-md:w-9 items-center justify-center rounded-full bg-zinc-100 text-zinc-500 transition-colors hover:bg-zinc-200/70 hover:text-foreground dark:bg-white/[0.08] dark:text-zinc-400 dark:hover:bg-white/[0.12]`,children:(0,Z.jsx)(L,{className:`h-3.5 w-3.5 max-md:h-4 max-md:w-4`,strokeWidth:1.8})}
3),(0,Z.jsx)(Ca,{placeholder:`Replyâ¦`,currentUserId:a,canInvite:d,onInvite:p,onSend:v})]})]})}function za(e){let{onChanged:t,onDeleted:n}=e,[r,i]=(0,X.useState)(!1),a=lr();return{getItemUrl:(0,X.useCallback)(e=>cr(e)??e.url??void 0,[a]),renameLibraryItem:(0,X.useCallback)(async(e,n)=>{try{await M(e,n.trim()),t?.()}catch{H.error(`Could not rename`)}},[t]),moveToFolder:(0,X.useCallback)(async(e,n)=>{await ar({folderId:n,itemIds:[e]})?t?.():H.error(`Could not move`)},[t]),remove:(0,X.useCallback)(async(e,a)=>{if(!r){i(!0);try{await j(e),a?.onRemoved?.(),n?.(e),t?.()}catch{H.error(`Could not delete`)}finally{i(!1)}}},[r,t,n]),busy:r}}var Ba=`flex snap-x snap-mandatory overflow-y-hidden overscroll-x-contain [scrollbar-width:none] [&::-webkit-scrollbar]:hidden`,Va=`relative flex w-full flex-shrink-0 snap-center [scroll-snap-stop:always]`;function Ha(e,t){return Math.abs(e-t)<=2}function Ua({on:e,index:t,count:n,onIndex:r}){let i=(0,X.useRef)(null),a=(0,X.useRef)(!1),o=(0,X.useRef)(r);o.current=r;let s=(0,X.useRef)(t);s.current=t;let c=(0,X.useRef)(null),l=(0,X.useRef)(null),u=(0,X.useRef)(null);(0,X.useLayoutEffect)(()=>{let n=i.current;if(!e||!n||!n.clientWidth)return;if(c.current===t){c.current=null;return}let r=t*n.clientWidth;Math.abs(n.scrollLeft-r)>2&&!a.current&&(n.scrollLeft=r)},[e,t,n]),(0,X.useEffect)(()=>{if(!e)return;let t=()=>{let e=i.current;e&&e.clientWidth&&(e.scrollLeft=s.current*e.clientWidth)};return window.addEventListener(`resize`,t),()=>window.removeEventListener(`resize`,t)},[e]);let d=(0,X.useCallback)(()=>{if(u.current=null,a.current)return;let e=l.current;l.current=null,e!==null&&e!==s.current&&(c.current=e,s.current=e,o.current(e))},[]),f=(0,X.useCallback)(()=>{let e=i.current;!e||!e.clientWidth||(l.current=Math.min(n-1,Math.max(0,Math.round(e.scrollLeft/e.clientWidth))),u.current&&clearTimeout(u.current),u.current=setTimeout(d,80))},[n,d]),p=(0,X.useCallback)(e=>{a.current=e,!e&&l.current!==null&&!u.current&&(u.current=setTimeout(d,80))},[d]);return(0,X.useEffect)(()=>()=>{u.current&&clearTimeout(u.current)},[]),{ref:i,onScroll:f,touch:p}}var Wa=`fixed inset-0 flex items-stretch bg-white dark:bg-background`,Ga=`relative flex h-full w-full flex-col md:flex-row`,Ka=`relative flex min-h-0 min-w-0 flex-1 flex-col`,qa=`block max-h-full max-w-full rounded-[4px]`,Ja=`relative flex w-full max-h-[45dvh] flex-shrink-0 flex-col overflow-hidden border-t border-black/[0.08] dark:border-white/[0.08] max-md:pb-[env(safe-area-inset-bottom)] md:max-h-none md:w-[340px] md:border-l md:border-t-0`,Ya=`flex items-center gap-0.5 rounded-full bg-zinc-100/90 dark:bg-[#202020]/90 p-[3px] backdrop-blur-md`,Xa=`flex h-[26px] w-[26px] items-center justify-center rounded-full text-zinc-500 dark:text-zinc-400 aria-pressed:text-foreground dark:aria-pressed:text-white transition-colors duration-100 hover:bg-black/10 dark:hover:bg-white/10 hover:text-foreground dark:hover:text-white data-[state=open]:bg-black/10 dark:data-[state=open]:bg-white/10 data-[state=open]:text-foreground dark:data-[state=open]:text-white`,Za=`flex h-8 w-full items-center gap-1.5 rounded-full bg-zinc-100 px-3.5 text-12 font-[440] text-foreground transition-colors duration-100 max-md:h-10 max-md:text-[14px] hover:bg-zinc-200/70 data-[state=open]:bg-zinc-200/70 dark:bg-white/[0.06] dark:hover:bg-white/[0.1] dark:data-[state=open]:bg-white/[0.1]`,Qa=`h-3.5 w-3.5 flex-shrink-0 text-zinc-500 dark:text-zinc-400`,$a=`flex h-11 w-11 flex-shrink-0 items-center justify-center rounded-full bg-zinc-100/90 text-zinc-700 backdrop-blur-md active:bg-zinc-200/90 data-[state=open]:bg-zinc-200/90 dark:bg-[#202020]/90 dark:text-zinc-200 dark:active:bg-[#2a2a2a]/90 dark:data-[state=open]:bg-[#2a2a2a]/90`,eo=`flex items-center gap-1 rounded-full bg-zinc-100/90 p-1 backdrop-blur-md dark:bg-[#202020]/90`,to=`flex h-11 w-11 items-center justify-center rounded-full text-zinc-700 active:bg-black/[0.06] dark:text-zinc-200 dark:active:bg-white/[0.08]`,no=`pointer-events-none flex h-8 items-center rounded-full bg-zinc-100/90 px-3 text-[13px] font-[440] tabular-nums text-zinc-700 backdrop-blur-md dark:bg-[#202020]/90 dark:text-zinc-200`,ro={hasSubscribers:!1},io=ro,ao=ro,oo=typeof performance==`object`&&performance&&typeof performance.now==`function`?performance:Date,so=()=>io.hasSubscribers||ao.hasSubscribers,co=new Set,lo=typeof process==`object`&&process?process:{},uo=(e,t,n,r)=>{typeof lo.emitWarning==`function`?lo.emitWarning(e,t,n,r):`${n}${t}${e}`},fo=e=>!co.has(e),po=e=>!!e&&e===Math.floor(e)&&e>0&&isFinite(e),mo=e=>po(e)?e<=256?Uint8Array:e<=2**16?Uint16Array:e<=2**32?Uint32Array:e<=2**53-1?ho:null:null,ho=class extends Array{constructor(e){super(e),this.fill(0)}},go=class e{heap;length;static#e=!1;static create(t){let n=mo(t);if(!n)return[];e.#e=!0;let r=new e(t,n);return e.#e=!1,r}constructor(t,n){if(!e.#e)throw TypeError(`instantiate Stack using Stack.create(n)`);this.heap=new n(t),this.length=0}push(e){this.heap[this.length++]=e}pop(){return this.heap[--this.length]}},_o=class e{#e;#t;#n;#r;#i;#a;#o;#s;get perf(){return this.#s}ttl;ttlResolution;ttlAutopurge;updateAgeOnGet;updateAgeOnHas;allowStale;noDisposeOnSet;noUpdateTTL;maxEntrySize;sizeCalculation;noDeleteOnFetchRejection;noDeleteOnStaleGet;allowStaleOnFetchAbort;allowStaleOnFetchRejection;ignoreFetchAbort;backgroundFetchSize;#c;#l;#u;#d;#f;#p;#m;#h;#g;#_;#v;#y;#b;#x;#S;#C;#w;#T;#E;static unsafeExposeInternals(e){return{starts:e.#b,ttls:e.#x,autopurgeTimers:e.#S,sizes:e.#y,keyMap:e.#u,keyList:e.#d,valList:e.#f,next:e.#p,prev:e.#m,get head(){return e.#h},get tail(){return e.#g}
3,free:e.#_,isBackgroundFetch:t=>e.#W(t),backgroundFetch:(t,n,r,i)=>e.#U(t,n,r,i),moveToTail:t=>e.#X(t),indexes:t=>e.#I(t),rindexes:t=>e.#L(t),isStale:t=>e.#j(t)}}get max(){return this.#e}get maxSize(){return this.#t}get calculatedSize(){return this.#l}get size(){return this.#c}get fetchMethod(){return this.#a}get memoMethod(){return this.#o}get dispose(){return this.#n}get onInsert(){return this.#r}get disposeAfter(){return this.#i}constructor(t){let{max:n=0,ttl:r,ttlResolution:i=1,ttlAutopurge:a,updateAgeOnGet:o,updateAgeOnHas:s,allowStale:c,dispose:l,onInsert:u,disposeAfter:d,noDisposeOnSet:f,noUpdateTTL:p,maxSize:m=0,maxEntrySize:h=0,sizeCalculation:g,fetchMethod:_,memoMethod:v,noDeleteOnFetchRejection:y,noDeleteOnStaleGet:b,allowStaleOnFetchRejection:x,allowStaleOnFetchAbort:S,ignoreFetchAbort:C,backgroundFetchSize:w=1,perf:T}=t;if(this.backgroundFetchSize=w,T!==void 0&&typeof T?.now!=`function`)throw TypeError(`perf option must have a now() method if specified`);if(this.#s=T??oo,n!==0&&!po(n))throw TypeError(`max option must be a nonnegative integer`);let E=n?mo(n):Array;if(!E)throw Error(`invalid max value: `+n);if(this.#e=n,this.#t=m,this.maxEntrySize=h||this.#t,this.sizeCalculation=g,this.sizeCalculation){if(!this.#t&&!this.maxEntrySize)throw TypeError(`cannot set sizeCalculation without setting maxSize or maxEntrySize`);if(typeof this.sizeCalculation!=`function`)throw TypeError(`sizeCalculation set to non-function`)}if(v!==void 0&&typeof v!=`function`)throw TypeError(`memoMethod must be a function if defined`);if(this.#o=v,_!==void 0&&typeof _!=`function`)throw TypeError(`fetchMethod must be a function if specified`);if(this.#a=_,this.#w=!!_,this.#u=new Map,this.#d=Array.from({length:n}).fill(void 0),this.#f=Array.from({length:n}).fill(void 0),this.#p=new E(n),this.#m=new E(n),this.#h=0,this.#g=0,this.#_=go.create(n),this.#c=0,this.#l=0,typeof l==`function`&&(this.#n=l),typeof u==`function`&&(this.#r=u),typeof d==`function`?(this.#i=d,this.#v=[]):(this.#i=void 0,this.#v=void 0),this.#C=!!this.#n,this.#E=!!this.#r,this.#T=!!this.#i,this.noDisposeOnSet=!!f,this.noUpdateTTL=!!p,this.noDeleteOnFetchRejection=!!y,this.allowStaleOnFetchRejection=!!x,this.allowStaleOnFetchAbort=!!S,this.ignoreFetchAbort=!!C,this.maxEntrySize!==0){if(this.#t!==0&&!po(this.#t))throw TypeError(`maxSize must be a positive integer if specified`);if(!po(this.maxEntrySize))throw TypeError(`maxEntrySize must be a positive integer if specified`);this.#M()}if(this.allowStale=!!c,this.noDeleteOnStaleGet=!!b,this.updateAgeOnGet=!!o,this.updateAgeOnHas=!!s,this.ttlResolution=po(i)||i===0?i:1,this.ttlAutopurge=!!a,this.ttl=r||0,this.ttl){if(!po(this.ttl))throw TypeError(`ttl must be a positive integer if specified`);this.#D()}if(this.#e===0&&this.ttl===0&&this.#t===0)throw TypeError(`At least one of max, maxSize, or ttl is required`);if(!this.ttlAutopurge&&!this.#e&&!this.#t){let t=`LRU_CACHE_UNBOUNDED`;fo(t)&&(co.add(t),uo(`TTL caching without ttlAutopurge, max, or maxSize can result in unbounded memory consumption.`,`UnboundedCacheWarning`,t,e))}}getRemainingTTL(e){return this.#u.has(e)?1/0:0}#D(){let e=new ho(this.#e),t=new ho(this.#e);this.#x=e,this.#b=t;let n=this.ttlAutopurge?Array.from({length:this.#e}):void 0;this.#S=n,this.#A=(n,i,a=this.#s.now())=>{t[n]=i===0?0:a,e[n]=i,r(n,i)},this.#O=n=>{t[n]=e[n]===0?0:this.#s.now(),r(n,e[n])};let r=this.ttlAutopurge?(e,t)=>{if(n?.[e]&&(clearTimeout(n[e]),n[e]=void 0),t&&t!==0&&n){let i=setTimeout(()=>{this.#j(e)?(this.#Z(this.#d[e],`expire`),n[e]=void 0):r(e,o(e))},t+1);i.unref&&i.unref(),n[e]=i}}:()=>{};this.#k=(n,r)=>{if(e[r]){let o=e[r],s=t[r];if(!o||!s)return;n.ttl=o,n.start=s,n.now=i||a(),n.remainingTTL=o-(n.now-s)}};let i=0,a=()=>{let e=this.#s.now();if(this.ttlResolution>0){i=e;let t=setTimeout(()=>i=0,this.ttlResolution);t.unref&&t.unref()}return e};this.getRemainingTTL=e=>{let t=this.#u.get(e);return t===void 0?0:o(t)};let o=n=>{let r=e[n],o=t[n];return!r||!o?1/0:r-((i||a())-o)};this.#j=n=>{let r=t[n],o=e[n];return!!o&&!!r&&(i||a())-r>o}}#O=()=>{};#k=()=>{};#A=()=>{};#j=()=>!1;#M(){let e=new ho(this.#e);this.#l=0,this.#y=e,this.#N=t=>{this.#l-=e[t],e[t]=0},this.#F=(e,t,n,r)=>{if(!po(n)){if(this.#W(t))return this.backgroundFetchSize;if(r){if(typeof r!=`function`)throw TypeError(`sizeCalculation must be a function`);if(n=r(t,e),!po(n))throw TypeError(`sizeCalculation return invalid (expect positive integer)`)}else throw TypeError(`invalid size value (must be positive integer). When maxSize or maxEntrySize is used, sizeCalculation or size must be set.`)}return n},this.#P=(t,n,r)=>{if(e[t]=n,this.#t){let n=this.#t-e[t];for(;this.#l>n;)this.#B(!0)}this.#l+=e[t],r&&(r.entrySize=n,r.totalCalculatedSize=this.#l)}}#N=e=>{};#P=(e,t,n)=>{};#F=(e,t,n,r)=>{if(n||r)throw TypeError(`cannot set size without setting maxSize or maxEntrySize on cache`);return 0};*#I({allowStale:e=this.allowStale}={}){if(this.#c)for(let t=this.#g;this.#R(t)&&((e||!this.#j(t))&&(yield t),t!==this.#h);)t=this.#m[t]}*#L({allowStale:e=this.allowStale}={}){if(this.#c)for(let t=this.#h;this.#R(t)&&((e||!this.#j(t))&&(yield t),t!==this.#g);)t=this.#p[t]}#R(e){return e!==void 0&&this.#u.get(this.#d[e])===e}*entries(){for(let e of this.#I())this.#f[e]!==void 0&&this.#d[e]!==void 0&&!this.#W(this.#f[e])&&(yield[this.#d[e],this.#f[e]])}*rentries(){for(let e of this.#L())this.#f[e]!==void 0&&this.#d[e]!==void 0&&!this.#W(this.#f[e])&&(yield[this.#d[e],this.#f[e]])}*keys(){for(let e of this.#I()){let t=this.#d[e];t!==void 0&&!this.#W(this.#f[e])&&(yield t)}}*rkeys(){for(let e of this.#L()){let t=this.#d[e];t!==void 0&&!this.#W(this.#f[e])&&(yield t)}}*values(){for(let e of this.#I())this.#f[e]!==void 0&&!this.#W(this.#f[e])&&(yield this.#f[e])}*rvalues(){for(let e of this.#L())this.#f[e]!==void 0&&!this.#W(this.#f[e])&&(yield this.#f[e])}[Symbol.iterator](){return this.entries()}[Symbol.toStringTag]=`LRUCache`;find(e,t={}){for(let n of this.#I()){let r=this.#f[n],i=this.#W(r)?r.__staleWhileFetching:r;if(i!==void 0&&e(i,this.#d[n],this))return this.#J(this.#d[n],t)}}forEach(e,t=this){for(let n of this.#I()){let r=this.#f[n],i=this.#W(r)?r.__staleWhileFetching:r;i!==void 0&&e.call(t,i,this.#d[n],this)}}
vendor: 10,874 bytes, line 3
3rforEach(e,t=this){for(let n of this.#L()){let r=this.#f[n],i=this.#W(r)?r.__staleWhileFetching:r;i!==void 0&&e.call(t,i,this.#d[n],this)}}purgeStale(){let e=!1;for(let t of this.#L({allowStale:!0}))this.#j(t)&&(this.#Z(this.#d[t],`expire`),e=!0);return e}info(e){let t=this.#u.get(e);if(t===void 0)return;let n=this.#f[t],r=this.#W(n)?n.__staleWhileFetching:n;if(r===void 0)return;let i={value:r};if(this.#x&&this.#b){let e=this.#x[t],n=this.#b[t];e&&n&&(i.ttl=e-(this.#s.now()-n),i.start=Date.now())}return this.#y&&(i.size=this.#y[t]),i}dump(){let e=[];for(let t of this.#I({allowStale:!0})){let n=this.#d[t],r=this.#f[t],i=this.#W(r)?r.__staleWhileFetching:r;if(i===void 0||n===void 0)continue;let a={value:i};if(this.#x&&this.#b){a.ttl=this.#x[t];let e=this.#s.now()-this.#b[t];a.start=Math.floor(Date.now()-e)}this.#y&&(a.size=this.#y[t]),e.unshift([n,a])}return e}load(e){this.clear();for(let[t,n]of e){if(n.start){let e=Date.now()-n.start;n.start=this.#s.now()-e}this.#z(t,n.value,n)}}set(e,t,n={}){let{status:r=io.hasSubscribers?{}:void 0}=n;n.status=r,r&&(r.op=`set`,r.key=e,t!==void 0&&(r.value=t),r.cache=this);let i=this.#z(e,t,n);return r&&io.hasSubscribers&&io.publish(r),i}#z(e,t,n,r){let{ttl:i=this.ttl,start:a,noDisposeOnSet:o=this.noDisposeOnSet,sizeCalculation:s=this.sizeCalculation,status:c}=n,l=this.#W(t);if(t===void 0)return c&&(c.set=`deleted`),this.delete(e),this;let{noUpdateTTL:u=this.noUpdateTTL}=n;c&&!l&&(c.value=t);let d=this.#F(e,t,n.size||0,s,c);if(this.maxEntrySize&&d>this.maxEntrySize)return this.#Z(e,`set`),c&&(c.set=`miss`,c.maxEntrySizeExceeded=!0),this;let f=this.#c===0?void 0:this.#u.get(e);if(f===void 0)f=this.#c===0?this.#g:this.#_.length===0?this.#c===this.#e?this.#B(!1):this.#c:this.#_.pop(),this.#d[f]=e,this.#f[f]=t,this.#u.set(e,f),this.#p[this.#g]=f,this.#m[f]=this.#g,this.#g=f,this.#c++,this.#P(f,d,c),c&&(c.set=`add`),u=!1,this.#E&&!l&&this.#r?.(t,e,`add`);else{this.#X(f);let n=this.#f[f];if(t!==n){if(!o){if(this.#W(n)){n!==r&&n.__abortController.abort(Error(`replaced`));let{__staleWhileFetching:i}=n;i!==void 0&&i!==t&&(this.#C&&this.#n?.(i,e,`set`),this.#T&&this.#v?.push([i,e,`set`]))}else this.#C&&this.#n?.(n,e,`set`),this.#T&&this.#v?.push([n,e,`set`])}if(this.#N(f),this.#P(f,d,c),this.#f[f]=t,!l){let r=n&&this.#W(n)?n.__staleWhileFetching:n,i=r===void 0?`add`:t===r?`update`:`replace`;c&&(c.set=i,r!==void 0&&(c.oldValue=r)),this.#E&&this.onInsert?.(t,e,i)}}else l||(c&&(c.set=`update`),this.#E&&this.onInsert?.(t,e,`update`))}if(i!==0&&!this.#x&&this.#D(),this.#x&&(u||this.#A(f,i,a),c&&this.#k(c,f)),!o&&this.#T&&this.#v){let e=this.#v,t;for(;t=e?.shift();)this.#i?.(...t)}return this}pop(){try{for(;this.#c;){let e=this.#f[this.#h];if(this.#B(!0),this.#W(e)){if(e.__staleWhileFetching)return e.__staleWhileFetching}else if(e!==void 0)return e}}finally{if(this.#T&&this.#v){let e=this.#v,t;for(;t=e?.shift();)this.#i?.(...t)}}}#B(e){let t=this.#h,n=this.#d[t],r=this.#f[t],i=this.#W(r);i&&r.__abortController.abort(Error(`evicted`));let a=i?r.__staleWhileFetching:r;return(this.#C||this.#T)&&a!==void 0&&(this.#C&&this.#n?.(a,n,`evict`),this.#T&&this.#v?.push([a,n,`evict`])),this.#N(t),this.#S?.[t]&&(clearTimeout(this.#S[t]),this.#S[t]=void 0),e&&(this.#d[t]=void 0,this.#f[t]=void 0,this.#_.push(t)),this.#c===1?(this.#h=this.#g=0,this.#_.length=0):this.#h=this.#p[t],this.#u.delete(n),this.#c--,t}has(e,t={}){let{status:n=io.hasSubscribers?{}:void 0}=t;t.status=n,n&&(n.op=`has`,n.key=e,n.cache=this);let r=this.#V(e,t);return io.hasSubscribers&&io.publish(n),r}#V(e,t={}){let{updateAgeOnHas:n=this.updateAgeOnHas,status:r}=t,i=this.#u.get(e);if(i!==void 0){let e=this.#f[i];if(this.#W(e)&&e.__staleWhileFetching===void 0)return!1;if(this.#j(i))r&&(r.has=`stale`,this.#k(r,i));else return n&&this.#O(i),r&&(r.has=`hit`,this.#k(r,i)),!0}else r&&(r.has=`miss`);return!1}peek(e,t={}){let{status:n=so()?{}:void 0}=t;n&&(n.op=`peek`,n.key=e,n.cache=this),t.status=n;let r=this.#H(e,t);return io.hasSubscribers&&io.publish(n),r}#H(e,t){let{status:n,allowStale:r=this.allowStale}=t,i=this.#u.get(e);if(i===void 0||!r&&this.#j(i)){n&&(n.peek=i===void 0?`miss`:`stale`);return}let a=this.#f[i],o=this.#W(a)?a.__staleWhileFetching:a;return n&&(o===void 0?n.peek=`miss`:(n.peek=`hit`,n.value=o)),o}#U(e,t,n,r){let i=t===void 0?void 0:this.#f[t];if(this.#W(i))return i;let a=new AbortController,{signal:o}=n;o?.addEventListener(`abort`,()=>a.abort(o.reason),{signal:a.signal});let s={signal:a.signal,options:n,context:r},c=(r,i=!1)=>{let{aborted:o}=a.signal,c=n.ignoreFetchAbort&&r!==void 0,l=n.ignoreFetchAbort||!!(n.allowStaleOnFetchAbort&&r!==void 0);if(n.status&&(o&&!i?(n.status.fetchAborted=!0,n.status.fetchError=a.signal.reason,c&&(n.status.fetchAbortIgnored=!0)):n.status.fetchResolved=!0),o&&!c&&!i)return u(a.signal.reason,l);let d=f,p=this.#f[t];return(p===f||p===void 0&&c&&i)&&(r===void 0?d.__staleWhileFetching===void 0?this.#Z(e,`fetch`):this.#f[t]=d.__staleWhileFetching:(n.status&&(n.status.fetchUpdated=!0),this.#z(e,r,s.options,d))),r},l=e=>(n.status&&(n.status.fetchRejected=!0,n.status.fetchError=e),u(e,!1)),u=(r,i)=>{let{aborted:o}=a.signal,s=o&&n.allowStaleOnFetchAbort,c=s||n.allowStaleOnFetchRejection,l=c||n.noDeleteOnFetchRejection,u=f;if(this.#f[t]===f&&(!l||!i&&u.__staleWhileFetching===void 0?this.#Z(e,`fetch`):s||(this.#f[t]=u.__staleWhileFetching)),c)return n.status&&u.__staleWhileFetching!==void 0&&(n.status.returnedStale=!0),u.__staleWhileFetching;if(u.__returned===u)throw r},d=(t,r)=>{let o=this.#a?.(e,i,s);a.signal.addEventListener(`abort`,()=>{(!n.ignoreFetchAbort||n.allowStaleOnFetchAbort)&&(t(void 0),n.allowStaleOnFetchAbort&&(t=e=>c(e,!0)))}),o&&o instanceof Promise?o.then(e=>t(e===void 0?void 0:e),r):o!==void 0&&t(o)};n.status&&(n.status.fetchDispatched=!0);let f=new Promise(d).then(c,l),p=Object.assign(f,{__abortController:a,__staleWhileFetching:i,__returned:void 0});return t===void 0?(this.#z(e,p,{...s.options,status:void 0}),t=this.#u.get(e)):this.#f[t]=p,p}#W(e){if(!this.#w)return!1;let t=e;return!!t&&t instanceof Promise&&t.hasOwnProperty(`__staleWhileFetching`)&&t.__abortController instanceof AbortController}fetch(e,t={}){let n=ao.hasSubscribers,{status:r=so()?{}:void 0}=t;t.status=r,r&&t.context&&(r.context=t.context);let i=this.#G(e,t);return r&&n&&(r.trace=!0,ao.tracePromise(()=>i,r).catch(()=>{})),i}async#G(e,t={}){let{allowStale:n=this.allowStale,updateAgeOnGet:r=this.updateAgeOnGet,noDeleteOnStaleGet:i=this.noDeleteOnStaleGet,ttl:a=this.ttl,noDisposeOnSet:o=this.noDisposeOnSet,size:s=0,sizeCalculation:c=this.sizeCalculation,noUpdateTTL:l=this.noUpdateTTL,noDeleteOnFetchRejection:u=this.noDeleteOnFetchRejection,allowStaleOnFetchRejection:d=this.allowStaleOnFetchRejection,ignoreFetchAbort:f=this.ignoreFetchAbort,allowStaleOnFetchAbort:p=this.allowStaleOnFetchAbort,context:m,forceRefresh:h=!1,status:g,signal:_}=t;if(g&&(g.op=`fetch`,g.key=e,h&&(g.forceRefresh=!0),g.cache=this),!this.#w)return g&&(g.fetch=`get`),this.#J(e,{allowStale:n,updateAgeOnGet:r,noDeleteOnStaleGet:i,status:g});let v={allowStale:n,updateAgeOnGet:r,noDeleteOnStaleGet:i,ttl:a,noDisposeOnSet:o,size:s,sizeCalculation:c,noUpdateTTL:l,noDeleteOnFetchRejection:u,allowStaleOnFetchRejection:d,allowStaleOnFetchAbort:p,ignoreFetchAbort:f,status:g,signal:_},y=this.#u.get(e);if(y===void 0){g&&(g.fetch=`miss`);let t=this.#U(e,y,v,m);return t.__returned=t}{let t=this.#f[y];if(this.#W(t)){let e=n&&t.__staleWhileFetching!==void 0;return g&&(g.fetch=`inflight`,e&&(g.returnedStale=!0)),e?t.__staleWhileFetching:t.__returned=t}let i=this.#j(y);if(!h&&!i)return g&&(g.fetch=`hit`),this.#X(y),r&&this.#O(y),g&&this.#k(g,y),t;let a=this.#U(e,y,v,m),o=a.__staleWhileFetching!==void 0&&n;return g&&(g.fetch=i?`stale`:`refresh`,o&&i&&(g.returnedStale=!0)),o?a.__staleWhileFetching:a.__returned=a}}forceFetch(e,t={}){let n=ao.hasSubscribers,{status:r=so()?{}:void 0}=t;t.status=r,r&&t.context&&(r.context=t.context);let i=this.#K(e,t);return r&&n&&(r.trace=!0,ao.tracePromise(()=>i,r).catch(()=>{})),i}async#K(e,t={}){let n=await this.#G(e,t);if(n===void 0)throw Error(`fetch() returned undefined`);return n}memo(e,t={}){let{status:n=io.hasSubscribers?{}:void 0}=t;t.status=n,n&&(n.op=`memo`,n.key=e,t.context&&(n.context=t.context),n.cache=this);let r=this.#q(e,t);return n&&(n.value=r),io.hasSubscribers&&io.publish(n),r}#q(e,t={}){let n=this.#o;if(!n)throw Error(`no memoMethod provided to constructor`);let{context:r,status:i,forceRefresh:a,...o}=t;i&&a&&(i.forceRefresh=!0);let s=this.#J(e,o),c=a||s===void 0;if(i&&(i.memo=c?`miss`:`hit`,c||(i.value=s)),!c)return s;let l=n(e,s,{options:o,context:r});return i&&(i.value=l),this.#z(e,l,o),l}get(e,t={}){let{status:n=io.hasSubscribers?{}:void 0}=t;t.status=n,n&&(n.op=`get`,n.key=e,n.cache=this);let r=this.#J(e,t);return n&&(r!==void 0&&(n.value=r),io.hasSubscribers&&io.publish(n)),r}#J(e,t={}){let{allowStale:n=this.allowStale,updateAgeOnGet:r=this.updateAgeOnGet,noDeleteOnStaleGet:i=this.noDeleteOnStaleGet,status:a}=t,o=this.#u.get(e);if(o===void 0){a&&(a.get=`miss`);return}let s=this.#f[o],c=this.#W(s);return a&&this.#k(a,o),this.#j(o)?c?(a&&(a.get=`stale-fetching`),n&&s.__staleWhileFetching!==void 0?(a&&(a.returnedStale=!0),s.__staleWhileFetching):void 0):(i||this.#Z(e,`expire`),a&&(a.get=`stale`),n?(a&&(a.returnedStale=!0),s):void 0):(a&&(a.get=c?`fetching`:`hit`),this.#X(o),r&&this.#O(o),c?s.__staleWhileFetching:s)}#Y(e,t){this.#m[t]=e,this.#p[e]=t}#X(e){e!==this.#g&&(e===this.#h?this.#h=this.#p[e]:this.#Y(this.#m[e],this.#p[e]),this.#Y(this.#g,e),this.#g=e)}delete(e){return this.#Z(e,`delete`)}#Z(e,t){io.hasSubscribers&&io.publish({op:`delete`,delete:t,key:e,cache:this});let n=!1;if(this.#c!==0){let r=this.#u.get(e);if(r!==void 0){if(this.#S?.[r]&&(clearTimeout(this.#S[r]),this.#S[r]=void 0),n=!0,this.#c===1)this.#Q(t);else{this.#N(r);let n=this.#f[r];if(this.#W(n)?n.__abortController.abort(Error(`deleted`)):(this.#C||this.#T)&&(this.#C&&this.#n?.(n,e,t),this.#T&&this.#v?.push([n,e,t])),this.#u.delete(e),this.#d[r]=void 0,this.#f[r]=void 0,r===this.#g)this.#g=this.#m[r];else if(r===this.#h)this.#h=this.#p[r];else{let e=this.#m[r];this.#p[e]=this.#p[r];let t=this.#p[r];this.#m[t]=this.#m[r]}this.#c--,this.#_.push(r)}}}if(this.#T&&this.#v?.length){let e=this.#v,t;for(;t=e?.shift();)this.#i?.(...t)}return n}clear(){return this.#Q(`delete`)}#Q(e){for(let t of this.#L({allowStale:!0})){let n=this.#f[t];if(this.#W(n))n.__abortController.abort(Error(`deleted`));else{let r=this.#d[t];this.#C&&this.#n?.(n,r,e),this.#T&&this.#v?.push([n,r,e])}}if(this.#u.clear(),this.#f.fill(void 0),this.#d.fill(void 0),this.#x&&this.#b){this.#x.fill(0),this.#b.fill(0);for(let e of this.#S??[])e!==void 0&&clearTimeout(e);this.#S?.fill(void 0)}if(this.#y&&this.#y.fill(0),this.#h=0,this.#g=0,this.#_.length=0,this.#l=0,this.#c=0,this.#T&&this.#v){let e=this.#v,t;for(;t=e?.shift();)this.#i?.(...t)}}}
3,vo=`id, type, model, prompt, status, credits_used, metadata, created_at, completed_at`,yo=new _o({max:500,ttl:3e5,updateAgeOnGet:!0}),bo=async e=>{if(yo.has(e))return yo.get(e);try{let{data:t,error:n}=await E.from(`generations`).select(`*`).eq(`id`,e).single();if(n)throw T.error(`Error fetching generation:`,n),n;return t&&yo.set(e,t),t}catch(t){throw T.error(`Error in getGenerationById for ${e}:`,t),t}},xo=640,So=async e=>new Promise(t=>{try{let n=document.createElement(`video`),r=document.createElement(`canvas`),i=r.getContext(`2d`);if(!i){t(null);return}n.preload=`metadata`,n.muted=!0,n.playsInline=!0,n.onloadedmetadata=()=>{let e=Math.min(1,n.duration*.1);n.currentTime=e};let a=()=>{n.onseeked=null,n.onerror=null,URL.revokeObjectURL(n.src),n.removeAttribute(`src`),n.load()};n.onseeked=()=>{let e=Math.min(1,xo/Math.max(1,n.videoWidth,n.videoHeight));r.width=Math.max(1,Math.round(n.videoWidth*e)),r.height=Math.max(1,Math.round(n.videoHeight*e)),i.drawImage(n,0,0,r.width,r.height);let o=r.toDataURL(`image/jpeg`,.8);a(),t(o)},n.onerror=()=>{T.warn(`Error loading video for thumbnail extraction`),a(),t(null)},n.src=URL.createObjectURL(e)}catch(e){T.error(`Error extracting video thumbnail:`,e),t(null)}}),Co=.1,wo=.01,To={credits:20,minutes:10},Eo=5e3,Do=1e4;function Oo(e){return Math.round(e*Do)/Do}function ko(e){return e>0&&e<.005?`0.01`:e.toLocaleString(`en-US`,{minimumFractionDigits:0,maximumFractionDigits:2})}function Ao(e){return e/wo}function jo(e){return e<=0?`0`:e<.1?`under 0.1`:e<10?(Math.round(e*10)/10).toLocaleString(`en-US`):Math.round(e).toLocaleString(`en-US`)}function Mo(e){return Oo(e/Co)}function No(e){return Math.floor(e*50)}var Po=[`generation`,`item`];function Fo(e){if(e.length===0)return null;let t=e.filter(e=>e.transaction_type!==`refund`).reduce((e,t)=>e-t.amount,0),n=e.filter(e=>e.transaction_type===`refund`).reduce((e,t)=>e+t.amount,0),r=Math.max(0,Oo(t-n));return{credits:r,refunded:t>0&&r===0}}function Io(e){return e.refunded?`Not charged`:`${ko(e.credits)} ${e.credits===1?`credit`:`credits`}`}var Lo=new _o({max:500,ttl:3e5,updateAgeOnGet:!0});async function Ro(e){let t=[e.generationId,e.itemId].filter(e=>!!e);if(t.length===0)return null;let n=t.join(`|`),r=Lo.get(n);if(r)return r.spend;let{data:i,error:a}=await E.from(`credit_transactions`).select(`amount, transaction_type`).in(`reference_type`,Po).in(`reference_id`,t);if(a)return null;let o=Fo(i??[]);return Lo.set(n,{spend:o}),o}var zo=Object.defineProperty,Bo=(e,t)=>zo(e,`name`,{value:t,configurable:!0}),Vo=`ContextMenu`,[Ho,Uo]=en(Vo,[sn]),Wo=sn(),[Go,Ko]=Ho(Vo),qo=Bo(e=>{let{__scopeContextMenu:t,children:n,onOpenChange:r,open:i,dir:a,modal:o=!0}=e,s=X.useRef(!1),[c,l]=Qt({prop:i,defaultProp:!1,onChange:r,caller:Vo}),u=Wo(t);return(0,Z.jsx)(Go,{scope:t,open:c,onOpenChange:l,modal:o,hasInteractedRef:s,children:(0,Z.jsx)(Bt,{...u,dir:a,open:c,onOpenChange:l,modal:o,children:n})})},`ContextMenu`),Jo=`ContextMenuTrigger`,Yo=X.forwardRef(Bo(function(e,t){let{__scopeContextMenu:n,disabled:r=!1,...i}=e,a=Ko(Jo,n),o=Wo(n),[s,c]=X.useState({x:0,y:0}),l=X.useMemo(()=>({current:{getBoundingClientRect:Bo(()=>DOMRect.fromRect({width:0,height:0,...s}),`getBoundingClientRect`)}}),[s]),u=X.useRef(0),d=X.useCallback(()=>window.clearTimeout(u.current),[]),f=Bo(e=>{a.hasInteractedRef.current=!0,c({x:e.clientX,y:e.clientY}),a.onOpenChange(!0)},`handleOpen`);return X.useEffect(()=>d,[d]),X.useEffect(()=>void(r&&d()),[r,d]),(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(qt,{...o,virtualRef:l}),(0,Z.jsx)(on.span,{"data-state":a.open?`open`:`closed`,"data-disabled":r?``:void 0,...i,ref:t,style:{WebkitTouchCallout:`none`,...e.style},onContextMenu:r?e.onContextMenu:un(e.onContextMenu,e=>{d(),f(e),e.preventDefault()}),onPointerDown:r?e.onPointerDown:un(e.onPointerDown,as(e=>{d(),a.open&&a.onOpenChange(!1),u.current=window.setTimeout(()=>f(e),700)})),onPointerMove:r?e.onPointerMove:un(e.onPointerMove,as(d)),onPointerCancel:r?e.onPointerCancel:un(e.onPointerCancel,as(d)),onPointerUp:r?e.onPointerUp:un(e.onPointerUp,as(d))})]})},`ContextMenuTrigger`)),Xo=Bo(e=>{let{__scopeContextMenu:t,...n}=e,r=Wo(t);return(0,Z.jsx)(Jt,{...r,...n})},`ContextMenuPortal`),Zo=`ContextMenuContent`,Qo=X.forwardRef(Bo(function(e,t){let{__scopeContextMenu:n,...r}=e,i=Ko(Zo,n),a=Wo(n),o=X.useRef(!1);return(0,Z.jsx)(Rt,{...a,...r,ref:t,side:`right`,sideOffset:2,align:`start`,onCloseAutoFocus:t=>{e.onCloseAutoFocus?.(t),!t.defaultPrevented&&o.current&&t.preventDefault(),o.current=!1},onInteractOutside:t=>{e.onInteractOutside?.(t),!t.defaultPrevented&&!i.modal&&(o.current=!0)},style:{...e.style,"--radix-context-menu-content-transform-origin":`var(--radix-popper-transform-origin)`,"--radix-context-menu-content-available-width":`var(--radix-popper-available-width)`,"--radix-context-menu-content-available-height":`var(--radix-popper-available-height)`,"--radix-context-menu-trigger-width":`var(--radix-popper-anchor-width)`,"--radix-context-menu-trigger-height":`var(--radix-popper-anchor-height)`}})},`ContextMenuContent`)),$o=X.forwardRef(Bo(function(e,t){let{__scopeContextMenu:n,...r}=e,i=Wo(n);return(0,Z.jsx)(vn,{...i,...r,ref:t})},`ContextMenuItem`)),es=X.forwardRef(Bo(function(e,t){let{__scopeContextMenu:n,...r}=e,i=Wo(n);return(0,Z.jsx)(zt,{...i,...r,ref:t})},`ContextMenuSeparator`)),ts=`ContextMenuSub`,ns=Bo(e=>{let{__scopeContextMenu:t,children:n,onOpenChange:r,open:i,defaultOpen:a}=e,o=Wo(t),[s,c]=Qt({prop:i,defaultProp:a??!1,onChange:r,caller:ts});return(0,Z.jsx)(Wt,{...o,open:s,onOpenChange:c,children:n})},`ContextMenuSub`),rs=X.forwardRef(Bo(function(e,t){let{__scopeContextMenu:n,...r}=e,i=Wo(n);return(0,Z.jsx)(Lt,{...i,...r,ref:t})},`ContextMenuSubTrigger`)),is=X.forwardRef(Bo(function(e,t){let{__scopeContextMenu:n,...r}=e,i=Wo(n);return(0,Z.jsx)(cn,{...i,...r,ref:t,style:{...e.style,"--radix-context-menu-content-transform-origin":`var(--radix-popper-transform-origin)`,"--radix-context-menu-content-available-width":`var(--radix-popper-available-width)`,"--radix-context-menu-content-available-height":`var(--radix-popper-available-height)`,"--radix-context-menu-trigger-width":`var(--radix-popper-anchor-width)`,"--radix-context-menu-trigger-height":`var(--radix-popper-anchor-height)`}})},`ContextMenuSubContent`));function as(e){return t=>t.pointerType===`mouse`?void 0:e(t)}Bo(as,`whenTouchOrPen`);var os=qo,ss=Yo,cs=Xo,ls=Qo,us=$o,ds=es,fs=ns,ps=rs,ms=is,hs=os,gs=ss,_s=fs,vs=X.forwardRef(({className:e,inset:t,children:n,...r},i)=>(0,Z.jsxs)(ps,{ref:i,className:N(bn,`data-[state=open]:bg-zinc-100 dark:data-[state=open]:bg-white/[0.06]`,t&&`pl-8`,e),...r,children:[n,(0,Z.jsx)(st,{className:`ml-auto h-3.5 w-3.5 flex-shrink-0 text-zinc-400 dark:text-zinc-500`,strokeWidth:1.6})]}));vs.displayName=ps.displayName;var ys=X.forwardRef(({className:e,collisionPadding:t=12,...n},r)=>(0,Z.jsx)(cs,{children:(0,Z.jsx)(ms,{ref:r,collisionPadding:t,className:N(`z-[10010] min-w-[8rem] max-h-[var(--radix-context-menu-content-available-height)] overflow-y-auto`,$t,_n,`max-w-[calc(100vw-1.5rem)] md:max-w-none`,e),...n})}));ys.displayName=ms.displayName;var bs=X.forwardRef(({className:e,collisionPadding:t=12,...n},r)=>(0,Z.jsx)(cs,{children:(0,Z.jsx)(ls,{ref:r,collisionPadding:t,className:N(`z-[10010] min-w-[8rem] max-h-[var(--radix-context-menu-content-available-height)] overflow-y-auto`,$t,_n,`max-w-[calc(100vw-1.5rem)] md:max-w-none`,e),...n})}));bs.displayName=ls.displayName;var xs=X.forwardRef(({className:e,inset:t,...n},r)=>(0,Z.jsx)(us,{ref:r,className:N(`relative`,bn,`data-[disabled]:pointer-events-none data-[disabled]:opacity-50`,t&&`pl-8`,e),...n}));xs.displayName=us.displayName;var Ss=X.forwardRef(({className:e,...t},n)=>(0,Z.jsx)(ds,{ref:n,className:N(`my-1 h-px bg-black/[0.08] dark:bg-white/[0.08]`,e),...t}));Ss.displayName=ds.displayName;var Cs=[`gray`,`brown`,`orange`,`yellow`,`green`,`teal`,`blue`,`purple`,`pink`,`red`];function ws(e){return typeof e==`string`&&/^#[0-9a-f]{6}$/i.test(e)}function Ts(e){return ws(e)?``:ks[e??``]??ks.gray}function Es(e){return ws(e)?{backgroundColor:e}:void 0}function Ds(e){return ws(e)?``:Ns[e??``]??Ns.gray}function Os(e){return ws(e)?{backgroundColor:`${e}1A`,color:e}:void 0}var ks={gray:`bg-[#9B9A97]`,brown:`bg-[#A98A79]`,orange:`bg-[#E8A054]`,yellow:`bg-[#DFC15E]`,green:`bg-[#6FA97F]`,teal:`bg-[#5FB3A1]`,blue:`bg-[#6FA3D2]`,purple:`bg-[#A585D8]`,pink:`bg-[#D883B6]`,red:`bg-[#E1746E]`}
3,As={gray:`bg-[#9B9A97]/[0.07] dark:bg-[#9B9A97]/[0.08]`,brown:`bg-[#A98A79]/[0.07] dark:bg-[#A98A79]/[0.08]`,orange:`bg-[#E8A054]/[0.07] dark:bg-[#E8A054]/[0.08]`,yellow:`bg-[#DFC15E]/[0.07] dark:bg-[#DFC15E]/[0.08]`,green:`bg-[#6FA97F]/[0.07] dark:bg-[#6FA97F]/[0.08]`,teal:`bg-[#5FB3A1]/[0.07] dark:bg-[#5FB3A1]/[0.08]`,blue:`bg-[#6FA3D2]/[0.07] dark:bg-[#6FA3D2]/[0.08]`,purple:`bg-[#A585D8]/[0.07] dark:bg-[#A585D8]/[0.08]`,pink:`bg-[#D883B6]/[0.07] dark:bg-[#D883B6]/[0.08]`,red:`bg-[#E1746E]/[0.07] dark:bg-[#E1746E]/[0.08]`};function js(e){return ws(e)?``:As[e??``]??As.gray}function Ms(e){return ws(e)?{backgroundColor:`${e}10`}:void 0}var Ns={gray:`bg-[#9B9A97]/10 text-[#6f6e6b] dark:bg-[#9B9A97]/20 dark:text-[#b8b7b4]`,brown:`bg-[#A98A79]/10 text-[#82675a] dark:bg-[#A98A79]/20 dark:text-[#c4a897]`,orange:`bg-[#E8A054]/10 text-[#b0713a] dark:bg-[#E8A054]/20 dark:text-[#eebd85]`,yellow:`bg-[#DFC15E]/10 text-[#98803a] dark:bg-[#DFC15E]/20 dark:text-[#e7d288]`,green:`bg-[#6FA97F]/10 text-[#4e7f5c] dark:bg-[#6FA97F]/20 dark:text-[#96c3a3]`,teal:`bg-[#5FB3A1]/10 text-[#42887a] dark:bg-[#5FB3A1]/20 dark:text-[#8ccabd]`,blue:`bg-[#6FA3D2]/10 text-[#4b7aa5] dark:bg-[#6FA3D2]/20 dark:text-[#9cc0e0]`,purple:`bg-[#A585D8]/10 text-[#7c5fae] dark:bg-[#A585D8]/20 dark:text-[#c2ade5]`,pink:`bg-[#D883B6]/10 text-[#aa5b8a] dark:bg-[#D883B6]/20 dark:text-[#e4a8cc]`,red:`bg-[#E1746E]/10 text-[#b04f49] dark:bg-[#E1746E]/20 dark:text-[#eb9d99]`},Ps=`mr-2 h-1.5 w-1.5 flex-shrink-0 rounded-full max-md:h-2 max-md:w-2`;function Fs({label:e,checked:t}){return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`span`,{className:`${Ps} ${Ts(e.color)}`,style:Es(e.color)}),(0,Z.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:e.name}),t&&(0,Z.jsx)(V,{className:`ml-2 h-3 w-3 max-md:h-3.5 max-md:w-3.5 flex-shrink-0 text-foreground`,strokeWidth:2})]})}function Is(){return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(gt,{className:an,strokeWidth:1.5}),`New label`]})}var Ls=`flex h-8 flex-shrink-0 items-center gap-1.5 rounded-full px-2.5 text-12 font-[400] text-zinc-500 max-md:h-9 max-md:px-3 max-md:text-[13.5px] transition-colors duration-100 hover:bg-zinc-100 hover:text-foreground data-[state=open]:bg-zinc-100 data-[state=open]:text-foreground dark:text-zinc-400 dark:hover:bg-white/[0.06] dark:data-[state=open]:bg-white/[0.06]`,Rs=`flex h-8 w-8 flex-shrink-0 items-center justify-center rounded-full text-zinc-400 max-md:h-9 max-md:w-9 transition-colors duration-100 hover:bg-zinc-100 hover:text-foreground data-[state=open]:bg-zinc-100 data-[state=open]:text-foreground dark:text-zinc-500 dark:hover:bg-white/[0.06] dark:data-[state=open]:bg-white/[0.06]`,zs=`flex h-8 min-w-0 max-w-[220px] flex-shrink-0 items-center gap-1 rounded-full bg-zinc-100 pl-3 pr-2.5 text-12 font-[440] max-md:h-9 max-md:text-[13.5px] leading-none text-foreground transition-colors duration-100 hover:bg-zinc-200/70 data-[state=open]:bg-zinc-200/70 dark:bg-white/[0.06] dark:hover:bg-white/[0.1] dark:data-[state=open]:bg-white/[0.1]`,Bs=`bg-zinc-100 text-foreground dark:bg-white/[0.08] dark:text-foreground`;function Vs({path:e}){let t=e.lastIndexOf(` / `),n=t===-1?null:e.slice(0,t),r=t===-1?e:e.slice(t+3);return(0,Z.jsxs)(`span`,{className:`flex min-w-0 flex-1 items-baseline`,children:[n&&(0,Z.jsxs)(`span`,{className:`min-w-[1.5em] shrink-[100] truncate text-zinc-500 dark:text-zinc-400`,children:[n,`\xA0/\xA0`]}),(0,Z.jsx)(`span`,{className:`min-w-0 truncate`,children:r})]})}var Hs={Item:G,Separator:ln,Sub:tn,SubTrigger:pn,SubContent:rn},Us={Item:xs,Separator:Ss,Sub:_s,SubTrigger:vs,SubContent:ys};function Ws({menu:e,folders:t,showRemove:n,onMove:r,currentId:i,keepOpen:a}){let[o,s]=(0,X.useState)(void 0),[c,l]=(0,X.useState)(null),u=o===void 0?i:o,d=e=>t=>{if(!a){r(e);return}t.preventDefault(),!(c||e===u)&&(l(e??`none`),Promise.resolve(r(e)).then(t=>{t!==!1&&s(e)}).finally(()=>l(null)))};return(0,Z.jsxs)(Z.Fragment,{children:[t.length===0&&(0,Z.jsx)(e.Item,{disabled:!0,children:`No folders yet`}),t.map(t=>(0,Z.jsxs)(e.Item,{onSelect:d(t.id),children:[(0,Z.jsx)(de,{className:`mr-2.5 h-3.5 w-3.5 flex-shrink-0 fill-zinc-300 text-zinc-300 dark:fill-zinc-600 dark:text-zinc-600`,strokeWidth:1.4}),(0,Z.jsx)(Vs,{path:t.name}),c===t.id?(0,Z.jsx)(ft,{className:N(yn,`ml-3 animate-spin`),strokeWidth:2}):u===t.id&&(0,Z.jsx)(V,{className:N(`h-3 w-3 max-md:h-3.5 max-md:w-3.5 flex-shrink-0 text-foreground`,`ml-3`),strokeWidth:2})]},t.id)),n&&(0,Z.jsx)(Z.Fragment,{children:(0,Z.jsxs)(e.Item,{onSelect:d(null),children:[(0,Z.jsx)(Le,{className:`mr-2.5 h-3.5 w-3.5 flex-shrink-0 text-zinc-500 dark:text-zinc-400`,strokeWidth:1.4}),`Remove from folder`]})})]})}function Gs(e){let t=e.menu;return(0,Z.jsxs)(t.Sub,{children:[(0,Z.jsxs)(t.SubTrigger,{children:[(0,Z.jsx)(de,{className:`mr-2.5 h-3.5 w-3.5 flex-shrink-0 text-zinc-500 dark:text-zinc-400`,strokeWidth:1.4}),`Move to folder`]}),(0,Z.jsx)(t.SubContent,{className:`max-h-64 w-max min-w-[12rem] max-w-[min(28rem,calc(100vw-24px))] overflow-y-auto`,children:(0,Z.jsx)(Ws,{...e})})]})}function Ks({menu:e,labels:t,checkedIds:n,onToggle:r,onCreate:i,onDelete:a}){let o=f()===!0,[s,c]=(0,X.useState)(null);return(0,Z.jsxs)(Z.Fragment,{children:[t.map(t=>{let i=n?.has(t.id)??!1;return(0,Z.jsxs)(e.Item,{onClick:e=>{e.preventDefault(),r(t.id,!i)},className:`group/label`,children:[(0,Z.jsx)(Fs,{label:t,checked:i}),a&&o&&s===t.id?(0,Z.jsx)(`button`,{type:`button`,onClick:e=>{e.preventDefault(),e.stopPropagation(),c(null),a(t.id)},className:`ml-1 flex h-8 flex-shrink-0 items-center rounded-full bg-zinc-900 px-3 text-[13px] font-[440] text-white dark:bg-white dark:text-black`,children:`Delete`}):a&&(0,Z.jsx)(`button`,{type:`button`,"aria-label":`Delete ${t.name}`,onClick:e=>{e.preventDefault(),e.stopPropagation(),o?c(t.id):a(t.id)},className:`ml-1 hidden h-5 w-5 max-md:h-8 max-md:w-8 flex-shrink-0 items-center justify-center rounded-[5px] text-zinc-400 transition-colors hover:bg-zinc-100 hover:text-foreground group-hover/label:flex [@media(hover:none)]:flex dar
3k:text-zinc-500 dark:hover:bg-white/[0.06]`,children:(0,Z.jsx)(Ke,{className:`h-3 w-3 max-md:h-4 max-md:w-4`,strokeWidth:1.7})})]},t.id)}),i&&(0,Z.jsx)(Z.Fragment,{children:(0,Z.jsx)(e.Item,{onClick:()=>i(),children:(0,Z.jsx)(Is,{})})})]})}function qs(e){let t=e.menu;return(0,Z.jsxs)(t.Sub,{children:[(0,Z.jsxs)(t.SubTrigger,{children:[(0,Z.jsx)(Ne,{className:`mr-2.5 h-3.5 w-3.5 flex-shrink-0 text-zinc-500 dark:text-zinc-400`,strokeWidth:1.4}),`Labels`]}),(0,Z.jsx)(t.SubContent,{className:`max-h-64 w-max min-w-[12rem] max-w-[min(28rem,calc(100vw-24px))] overflow-y-auto`,children:(0,Z.jsx)(Ks,{...e})})]})}function Js(){let e=new Date;return`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,`0`)}-${String(e.getDate()).padStart(2,`0`)}`}function Ys(e){let t=new Date(`${e}T00:00:00`);return Number.isNaN(t.getTime())?e:t.toLocaleDateString(void 0,{month:`short`,day:`numeric`})}async function Xs(e,t,n={}){let r=(await Promise.all(e.map(e=>k.post(`/api/library/properties/values`,{itemId:e,propertyId:t.id,value:null}).then(()=>!0).catch(()=>!1)))).every(Boolean);return r?n.quiet||H.success(`Removed from ${t.name}`):H.error(`Could not remove from ${t.name}`),r}async function Zs(e,t,n,r={}){let i=(await Promise.all(e.map(e=>k.post(`/api/library/properties/values`,{itemId:e,propertyId:t.id,value:n}).then(()=>!0).catch(()=>!1)))).filter(Boolean).length;return i===e.length?r.quiet||H.success(`Added to ${t.name} on ${Ys(n)}`):i>0?H.error(`${e.length-i} could not be added to ${t.name}`):H.error(`Could not add to ${t.name}`),i===e.length}function Qs({calendar:e,current:t,onPlace:n,onDone:r}){let[i,a]=(0,X.useState)(t||Js()),[o,s]=(0,X.useState)(!1),c=async()=>{if(!i||o)return;s(!0);let t=await n(e,i);s(!1),t&&r()};return(0,Z.jsxs)(`form`,{className:`flex flex-col gap-1.5`,onSubmit:e=>{e.preventDefault(),c()},children:[(0,Z.jsx)(`span`,{className:`truncate px-1 text-[12px] font-[460] text-foreground max-md:text-[14px]`,children:e.name}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Z.jsx)(`input`,{type:`date`,autoFocus:typeof window>`u`||!window.matchMedia(`(hover: none)`).matches,value:i,onChange:e=>a(e.target.value),"aria-label":`Day`,className:`h-8 min-w-0 flex-1 rounded-lg border border-zinc-200/70 bg-transparent px-2.5 text-[12px] text-foreground outline-none dark:border-[#2f2f2f] max-md:h-10 max-md:text-[14px]`}),(0,Z.jsx)(`button`,{type:`submit`,disabled:!i||o||i===t,className:`h-8 flex-shrink-0 rounded-full bg-zinc-900 px-3.5 text-[12px] font-[440] text-white max-md:h-10 max-md:px-4 max-md:text-[14px] transition-colors duration-100 hover:bg-zinc-800 disabled:opacity-40 dark:bg-white dark:text-black dark:hover:bg-zinc-200`,children:t?`Move`:`Add`})]})]})}function $s(e){let[t,n]=(0,X.useState)(null);return{pickDate:(0,X.useCallback)(e=>(t,r)=>n({ids:e.map(e=>e.id),calendar:t,current:r}),[]),dialog:(0,Z.jsx)(wn,{open:!!t,onOpenChange:e=>{e||n(null)},children:(0,Z.jsxs)(Dn,{nested:!0,className:`w-64 max-w-[calc(100vw-2rem)] p-2`,children:[(0,Z.jsx)(zn,{className:`sr-only`,children:`Pick a date`}),t&&(0,Z.jsx)(Qs,{calendar:t.calendar,current:t.current,onPlace:async(n,r)=>{let i=await Zs(t.ids,n,r);return i&&e?.(),i},onDone:()=>n(null)})]})}),open:!!t}}var ec=`mr-2.5 h-3.5 w-3.5 flex-shrink-0 text-zinc-500 dark:text-zinc-400`,tc=`max-h-72 w-max min-w-[12rem] max-w-[20rem] overflow-y-auto`;function nc(e,t){let n;for(let r of e){let e=r.metadata?.properties?.[t],i=typeof e==`string`&&e?e:null;if(n===void 0)n=i;else if(n!==i)return null}return n??null}function rc(){let{activeWorkspaceId:e}=Nt(),{data:t=[]}=Vr(At.fields(e));return{boards:t.filter(e=>e.view===`board`),calendars:t.filter(e=>e.view===`calendar`)}}function ic({menu:e,board:t,items:n,onChanged:r}){let i=n.map(e=>e.id),[a,o]=(0,X.useState)(void 0),[s,c]=(0,X.useState)(null),l=a===void 0?nc(n,t.id):a,u=t.options.find(e=>e.id===l)??null,d=async e=>{c(e.id);try{await k.post(`/api/library/board`,{boardId:t.id,cards:i,columnId:e.id}),o(e.id),r?.()}catch{H.error(`Could not move to ${e.name}`)}finally{c(null)}},f=async()=>{c(`remove`);try{await k.post(`/api/library/board`,{boardId:t.id,action:`remove`,cards:i}),o(null),r?.()}catch{H.error(`Could not remove from ${t.name}`)}finally{c(null)}};return(0,Z.jsxs)(Z.Fragment,{children:[t.options.length===0&&(0,Z.jsx)(e.Item,{disabled:!0,children:`No columns yet`}),t.options.map(t=>(0,Z.jsxs)(e.Item,{onSelect:e=>{e.preventDefault(),!s&&t.id!==u?.id&&d(t)},children:[(0,Z.jsx)(`span`,{className:N(Ps,Ts(t.color)),style:Es(t.color)}),(0,Z.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:t.name}),s===t.id?(0,Z.jsx)(ft,{className:`ml-2 animate-spin ${yn}`,strokeWidth:2}):t.id===u?.id&&(0,Z.jsx)(V,{className:`ml-2 h-3 w-3 max-md:h-3.5 max-md:w-3.5 flex-shrink-0 text-foreground`,strokeWidth:2})]},t.id)),u&&(0,Z.jsx)(Z.Fragment,{children:(0,Z.jsxs)(e.Item,{onSelect:e=>{e.preventDefault(),s||f()},children:[s===`remove`?(0,Z.jsx)(ft,{className:N(ec,`animate-spin`),strokeWidth:1.4}):(0,Z.jsx)(_t,{className:ec,strokeWidth:1.4}),`Remove from board`]})})]})}function ac({menu:e,items:t,onChanged:n}){let{boards:r}=rc();return(0,Z.jsxs)(Z.Fragment,{children:[r.length===0&&(0,Z.jsx)(e.Item,{disabled:!0,children:`No boards yet`}),r.map(r=>{let i=r.options.find(e=>e.id===nc(t,r.id))??null;return(0,Z.jsxs)(e.Sub,{children:[(0,Z.jsxs)(e.SubTrigger,{children:[(0,Z.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:r.name}),i&&(0,Z.jsx)(`span`,{className:`ml-2 max-w-[45%] flex-shrink-0 truncate text-[12px] text-zinc-400 dark:text-zinc-500`,children:i.name})]}),(0,Z.jsx)(e.SubContent,{className:tc,children:(0,Z.jsx)(ic,{menu:e,board:r,items:t,onChanged:n})})]},r.id)})]})}function oc(e){let t=e.menu;return(0,Z.jsxs)(t.Sub,{children:[(0,Z.jsxs)(t.SubTrigger,{children:[(0,Z.jsx)(me,{className:ec,strokeWidth:1.4}),`Boards`]}),(0,Z.jsx)(t.SubContent,{className:tc,children:(0,Z.jsx)(ac,{...e})})]})}function sc(e){let t=new Date;return t.setDate(t.getDate()+e),`${t.getFullYear()}
3-${String(t.getMonth()+1).padStart(2,`0`)}-${String(t.getDate()).padStart(2,`0`)}`}function cc({menu:e,calendar:t,items:n,onChanged:r,onPickDate:i}){let a=n.map(e=>e.id),[o,s]=(0,X.useState)(void 0),[c,l]=(0,X.useState)(null),u=o===void 0?nc(n,t.id):o,d=async e=>{l(e);try{await Zs(a,t,e,{quiet:!0})&&(s(e),r?.())}finally{l(null)}},f=async()=>{l(`remove`);try{await Xs(a,t,{quiet:!0})&&(s(null),r?.())}finally{l(null)}},p=[{label:`Today`,day:Js()},{label:`Tomorrow`,day:sc(1)},{label:`In a week`,day:sc(7)}];return(0,Z.jsxs)(Z.Fragment,{children:[p.map(t=>(0,Z.jsxs)(e.Item,{onSelect:e=>{e.preventDefault(),!c&&t.day!==u&&d(t.day)},children:[(0,Z.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:t.label}),(0,Z.jsx)(`span`,{className:`ml-2 flex-shrink-0 text-[12px] tabular-nums text-zinc-400 dark:text-zinc-500`,children:Ys(t.day)}),c===t.day?(0,Z.jsx)(ft,{className:`ml-2 animate-spin ${yn}`,strokeWidth:2}):t.day===u&&(0,Z.jsx)(V,{className:`ml-2 h-3 w-3 max-md:h-3.5 max-md:w-3.5 flex-shrink-0 text-foreground`,strokeWidth:2})]},t.label)),(0,Z.jsx)(e.Item,{onClick:()=>i(t,u),children:u&&!p.some(e=>e.day===u)?`Pick a date (${Ys(u)})`:`Pick a date`}),u&&(0,Z.jsx)(Z.Fragment,{children:(0,Z.jsxs)(e.Item,{onSelect:e=>{e.preventDefault(),c||f()},children:[c===`remove`?(0,Z.jsx)(ft,{className:N(ec,`animate-spin`),strokeWidth:1.4}):(0,Z.jsx)(_t,{className:ec,strokeWidth:1.4}),`Remove from calendar`]})})]})}function lc({menu:e,items:t,onChanged:n,onPickDate:r}){let{calendars:i}=rc();return(0,Z.jsxs)(Z.Fragment,{children:[i.length===0&&(0,Z.jsx)(e.Item,{disabled:!0,children:`No calendars yet`}),i.map(i=>{let a=nc(t,i.id);return(0,Z.jsxs)(e.Sub,{children:[(0,Z.jsxs)(e.SubTrigger,{children:[(0,Z.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:i.name}),a&&(0,Z.jsx)(`span`,{className:`ml-2 flex-shrink-0 text-[12px] tabular-nums text-zinc-400 dark:text-zinc-500`,children:Ys(a)})]}),(0,Z.jsx)(e.SubContent,{className:tc,children:(0,Z.jsx)(cc,{menu:e,calendar:i,items:t,onChanged:n,onPickDate:r})})]},i.id)})]})}function uc(e){let t=e.menu;return(0,Z.jsxs)(t.Sub,{children:[(0,Z.jsxs)(t.SubTrigger,{children:[(0,Z.jsx)(we,{className:ec,strokeWidth:1.4}),`Calendar`]}),(0,Z.jsx)(t.SubContent,{className:tc,children:(0,Z.jsx)(lc,{...e})})]})}function dc(e){return[`public-links`,e??`active`]}function fc(){let{activeWorkspaceId:e}=Nt();return Vr({queryKey:dc(e),queryFn:async()=>(await k.get(`/api/public-links`)).links??[],staleTime:3e4})}function pc(e){return e.enabled?e.expires_at&&Date.parse(e.expires_at)<Date.now()?`expired`:e.published_at?`live`:`draft`:`off`}var mc={live:`Live`,draft:`Draft`,off:`Off`,expired:`Expired`};function hc(){let e=b(),t=xr(),{activeWorkspaceId:n}=Nt(),[r,i]=(0,X.useState)(!1);return{make:async(a={})=>{if(!r){i(!0);try{let r=await k.post(`/api/public-links`,{draft:!0,title:a.title??null,items:[]});t.invalidateQueries({queryKey:dc(n)}),e({to:`/app/library/links/$id`,params:{id:r.link.id}})}catch{H.error(`Could not make a public link`,{duration:3e3})}finally{i(!1)}}},making:r}}function gc({currentId:e,open:t,onClose:n}){let r=b(),{data:i,isPending:a}=fc(),{make:o,making:s}=hc(),[c,l]=(0,X.useState)(``),u=(0,X.useRef)(null);(0,X.useEffect)(()=>{t||l(``)},[t]);let d=(0,X.useMemo)(()=>{let e=c.trim().toLowerCase(),t=i??[];return e?t.filter(t=>(t.title??`Untitled link`).toLowerCase().includes(e)):t},[i,c]);return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`div`,{className:`mb-1 flex h-8 items-center gap-2 rounded-[8px] bg-zinc-50 px-2 dark:bg-white/5`,children:[(0,Z.jsx)(nt,{className:`h-3 w-3 flex-shrink-0 text-zinc-400`,strokeWidth:2}),(0,Z.jsx)(`input`,{ref:u,value:c,onChange:e=>l(e.target.value),onKeyDown:e=>e.stopPropagation(),placeholder:`Find a public linkâ¦`,"aria-label":`Find a public link`,className:`min-w-0 flex-1 bg-transparent text-[12px] text-foreground outline-none placeholder:text-zinc-400`})]}),(0,Z.jsxs)(`div`,{className:`max-h-72 overflow-y-auto`,children:[d.map(t=>{let n=pc(t);return(0,Z.jsxs)(G,{onSelect:()=>r({to:`/app/library/links/$id`,params:{id:t.id}}),className:`flex items-center gap-2`,children:[(0,Z.jsx)(`span`,{className:N(an,`mr-0.5 flex items-center justify-center max-md:mr-1`),children:(0,Z.jsx)(Ce,{className:`h-[13px] w-[13px] max-md:h-[15px] max-md:w-[15px]`,strokeWidth:1.5})}),(0,Z.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:t.title||`Untitled link`}),t.open_comments>0&&(0,Z.jsx)(`span`,{className:`h-[4px] w-[4px] flex-shrink-0 rounded-full bg-blue-500`,"aria-label":`Comments w
3aiting`}),(0,Z.jsx)(`span`,{className:`flex-shrink-0 text-[11px] font-[380] text-zinc-500 dark:text-zinc-400`,children:mc[n]}),t.id===e&&(0,Z.jsx)(V,{className:`h-3 w-3 max-md:h-3.5 max-md:w-3.5 flex-shrink-0 text-foreground`,strokeWidth:2})]},t.id)}),!d.length&&(0,Z.jsx)(`div`,{className:`px-2 py-2 text-[12px] text-zinc-500 dark:text-zinc-400`,children:a?`Loadingâ¦`:i?.length?`No link by that name`:`No public links yet`})]}),(0,Z.jsxs)(G,{disabled:s,onSelect:e=>{e.preventDefault(),o().then(()=>n?.())},children:[s?(0,Z.jsx)(ft,{className:N(an,`animate-spin`),strokeWidth:1.6}):(0,Z.jsx)(gt,{className:an,strokeWidth:1.6}),`New public link`]})]})}function _c(){let{data:e}=fc();return(e??[]).some(e=>e.open_comments>0)}function vc({currentId:e,children:t,align:n=`start`}){let[r,i]=(0,X.useState)(!1);return(0,Z.jsxs)(hn,{open:r,onOpenChange:i,children:[(0,Z.jsx)(dn,{asChild:!0,children:t}),(0,Z.jsx)(mn,{align:n,onCloseAutoFocus:e=>e.preventDefault(),className:`w-72`,children:(0,Z.jsx)(gc,{currentId:e,open:r,onClose:()=>i(!1)})})]})}function yc({label:e,className:t,...n}){let{data:r}=fc(),i=(r??[]).some(e=>e.open_comments>0),a=e!=null;return(0,Z.jsxs)(`button`,{type:`button`,"aria-label":a?void 0:`Public links`,...n,className:N(a?Ls:N(Rs,`relative`),t),children:[(0,Z.jsx)(Ce,{className:`h-3.5 w-3.5`,strokeWidth:1.6}),a?e:null,i&&(0,Z.jsx)(`span`,{"aria-label":`Comments waiting`,className:N(`h-[4px] w-[4px] flex-shrink-0 rounded-full bg-blue-500`,!a&&`absolute bottom-[8px] right-[8px]`)})]})}var bc=`mr-2.5 h-3.5 w-3.5 flex-shrink-0 text-zinc-500 dark:text-zinc-400`,xc=`px-2 pb-0.5 pt-1 text-[10.5px] font-[400] text-zinc-400 dark:text-zinc-500`;function Sc({menu:e,items:t}){return f()===!0?null:(0,Z.jsxs)(e.Sub,{children:[(0,Z.jsxs)(e.SubTrigger,{children:[(0,Z.jsx)(Ce,{className:bc,strokeWidth:1.4}),`Public link`]}),(0,Z.jsx)(e.SubContent,{className:`max-h-72 w-max min-w-[12rem] max-w-[20rem] overflow-y-auto`,children:(0,Z.jsx)(wc,{menu:e,items:t})})]})}function Cc(e){let t=xr(),{activeWorkspaceId:n}=Nt(),r=e&&Qn(e)!==`document`?e:null,i=[`item-public-link`,r?.id??null],{data:a,isFetched:o}=Vr({queryKey:i,enabled:!!r,queryFn:async()=>(await k.get(`/api/library/public-link`,{query:{kind:`item`,id:r.id}})).link??null,staleTime:3e4}),s=()=>void t.invalidateQueries({queryKey:dc(n)});return{canShare:!!r,shared:!!a?.published,ownLinkId:a?.linkId??null,known:!r||o,copyLink:async()=>{if(!r)return!1;try{let e=a?null:(await k.post(`/api/library/public-link`,{kind:`item`,id:r.id})).link,n=a?.slug??e.slug;return e&&(t.setQueryData(i,{slug:n,linkId:e.linkId}),s()),await navigator.clipboard.writeText(d(`/p/${n}`)),H.success(`Link copied`),!!e}catch(e){return H.error(e instanceof D?e.message:`Could not copy the link`),!1}},removeLink:async()=>{if(!r)return!1;try{return await k.delete(`/api/library/public-link`,{query:{kind:`item`,id:r.id}}),t.setQueryData(i,null),s(),H.success(`Link removed`),!0}catch(e){return H.error(e instanceof D?e.message:`Could not remove the link`),!1}},linksChanged:s}}function wc({menu:e,items:t,onLinks:n=[],onChanged:r}){let i=b(),{data:a=[]}=fc(),{canShare:o,shared:s,copyLink:c,removeLink:l,linksChanged:u}=Cc(t.length===1?t[0]:null),d=t.map(e=>e.id),f=a.filter(e=>!n.includes(e.id)),p=async()=>{try{let e=await k.post(`/api/public-links`,{draft:!0,title:null,items:d.map(e=>({item_id:e}))});u(),r?.(),i({to:`/app/library/links/$id`,params:{id:e.link.id}})}catch{H.error(`Could not make a public link`)}},[m,h]=(0,X.useState)(null),[g,_]=(0,X.useState)(new Set),v=async e=>{h(e.id);try{await k.post(`/api/public-links`,{linkId:e.id,addItems:d.map(e=>({item_id:e}))}),_(t=>new Set(t).add(e.id)),u(),r?.()}catch{H.error(`Could not add to that link`)}finally{h(null)}};return(0,Z.jsxs)(Z.Fragment,{children:[o&&s?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(e.Item,{onClick:()=>void c(),children:[(0,Z.jsx)(et,{className:bc,strokeWidth:1.4}),`Copy this item's link`]}),(0,Z.jsxs)(e.Item,{onClick:()=>void l().then(e=>{e&&r?.()}),children:[(0,Z.jsx)(We,{className:bc,strokeWidth:1.4}),`Remove this item's link`]})]}):(0,Z.jsxs)(e.Item,{onClick:()=>void p(),children:[(0,Z.jsx)(gt,{className:bc,strokeWidth:1.4}),`New public link`]}),f.length>0&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`div`,{className:xc,children:`Add to`}),f.map(t=>(0,Z.jsxs)(e.Item,{onSelect:e=>{e.preventDefault(),!m&&!g.has(t.id)&&v(t)},children:[(0,Z.jsx)(Ce,{className:bc,strokeWidth:1.4}),(0,Z.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:t.title||`Untitled link`}),m===t.id?(0,Z.jsx)(ft,{className:N(`h-3 w-3 max-md:h-3.5 max-md:w-3.5 flex-shrink-0 text-foreground`,`ml-3 animate-spin`),strokeWidth:2}):g.has(t.id)&&(0,Z.jsx)(V,{className:N(`h-3 w-3 max-md:h-3.5 max-md:w-3.5 flex-shrink-0 text-foreground`,`ml-3`),strokeWidth:2})]},t.id))]})]})}var Tc={labels:[],assignments:[]};function Ec(e){let{data:t=Tc}=Vr(At.labels(e)),n=t.labels,r=jt.labels(e).join(`/`),i=(0,X.useCallback)(t=>{U.setQueryData(jt.labels(e),e=>t(e??Tc))},[r]),a=(0,X.useCallback)(async()=>{await U.invalidateQueries({queryKey:jt.labels(e)})},[r]),o=(0,X.useMemo)(()=>{let e=new Map;for(let n of t.assignments){let t=n.item_id;t&&(e.has(t)||e.set(t,new Map),e.get(t).set(n.label_id,typeof n.position==`number`?n.position:null))}return e},[t.assignments]),[s,c]=(0,X.useState)(null),[l,u]=(0,X.useState)(!1),[d,f]=(0,X.useState)(``),[p,m]=(0,X.useState)(`gray`),[h,g]=(0,X.useState)(null),_=(0,X.useCallback)(async(e,t)=>{try{let n=await k.post(`/api/library/labels`,{name:e,color:t});return i(e=>e.labels.some(e=>e.id===n.label.id)?e:{...e,labels:[...e.labels,n.label]}),n.label}catch{return H.error(`Could not create label`),null}},[i]);return{labels:n,labelAssignments:o,createLabel:_,activeLabelId:s,setActiveLabelId:c,setLabelOnItems:(0,X.useCallback)(async(e,t,n)=>{if(n.length!==0){i(r=>{let i=new Set(n);if(!t)return{...r,assignments:r.assignments.filter(t=>!(t.label_id===e&&t.item_id&&i.has(t.item_id)))};let a=1,o=new Set;for(let t of r.assignments)t.label_id===e&&(t.item_id&&o.add(t.item_id),typeof t.position==`number`&&t.position<a&&(a=t.position));let s=n.filter(e=>!o.has(e)).map(t=>({item_id:t,label_id:e,position:--a}));return{...r,assignments:[...r.assignments,...s]}});try{await k.post(`/api/library/labels/assign`,{labelId:e,action:t?`add`:`remove`,itemIds:n})}catch{H.error(`Could not update labels`),a()}}},[i,a]),getItemLabelIds:(0,X.useCallback)(e=>
3{let t=o.get(e);return t?new Set(t.keys()):new Set},[o]),labelDialog:l,setLabelDialog:u,labelDialogName:d,setLabelDialogName:f,labelDialogColor:p,setLabelDialogColor:m,editingLabelId:h,setEditingLabelId:g,submitLabelDialog:(0,X.useCallback)(async()=>{let e=d.trim();if(e){if(h)try{await k.patch(`/api/library/labels/${h}`,{name:e,color:p}),i(t=>({...t,labels:t.labels.map(t=>t.id===h?{...t,name:e,color:p}:t)}))}catch{H.error(`Could not update label`)}else await _(e,p);u(!1),f(``),m(`gray`),g(null)}},[d,p,_,h,i]),openEditLabel:(0,X.useCallback)(e=>{g(e.id),f(e.name),m({zinc:`gray`,amber:`yellow`,violet:`purple`}[e.color]??e.color),u(!0)},[]),deleteLabel:(0,X.useCallback)(async e=>{try{await k.delete(`/api/library/labels/${e}`)}catch{H.error(`Could not delete label`);return}i(t=>({labels:t.labels.filter(t=>t.id!==e),assignments:t.assignments.filter(t=>t.label_id!==e)})),c(t=>t===e?null:t)},[i])}}function Dc({className:e}){return(0,Z.jsx)(ft,{"aria-hidden":!0,className:N(`h-3 w-3 flex-shrink-0 animate-spin opacity-60`,e),strokeWidth:1.75})}function Oc(e){let t=e.error?.code;return t===MediaError.MEDIA_ERR_DECODE||t===MediaError.MEDIA_ERR_SRC_NOT_SUPPORTED||e.readyState>=HTMLMediaElement.HAVE_METADATA&&e.videoWidth===0}function kc({itemId:e,className:t}){let[n,r]=(0,X.useState)(!1),i=async()=>{if(!n){r(!0);try{(await k.post(`/api/library/items/${e}/convert`,{}))?.status===`already_playable`?H.success(`This video is already converted, reload the page to play it`):H.success(`Converting, it plays here when it is done`)}catch(e){H.error(e instanceof D?e.message:`Could not start converting`)}finally{r(!1)}}};return(0,Z.jsxs)(`div`,{className:N(`pointer-events-none absolute inset-x-4 bottom-4 z-10 mx-auto max-w-md rounded-lg bg-zinc-900/80 px-3 py-2 text-center text-[12px] font-[380] leading-relaxed text-white backdrop-blur-sm max-md:flex max-md:items-center max-md:gap-3 max-md:rounded-[14px] max-md:bg-black/50 max-md:py-2.5 max-md:pl-4 max-md:pr-2.5 max-md:text-left max-md:backdrop-blur-md`,t),children:[(0,Z.jsx)(`span`,{className:`max-md:min-w-0 max-md:flex-1`,children:`This video can't play on this device.`}),(0,Z.jsxs)(`button`,{type:`button`,disabled:n,onPointerDown:e=>e.stopPropagation(),onClick:()=>void i(),className:`pointer-events-auto mt-2 flex w-full items-center justify-center gap-1.5 rounded-full bg-white/20 px-3 py-1.5 text-[12px] font-[440] text-white transition-colors hover:bg-white/25 disabled:opacity-60 max-md:mt-0 max-md:h-8 max-md:w-auto max-md:flex-shrink-0 max-md:bg-white max-md:px-3.5 max-md:py-0 max-md:text-[13px] max-md:text-black`,children:[n&&(0,Z.jsx)(Dc,{}),`Convert`]})]})}function Ac(e){let t=new Map(e.map(e=>[e.id,e])),n=e=>{let n=[e.name],r=e.parent_id?t.get(e.parent_id):null,i=0;for(;r&&i++<50;)n.unshift(r.name),r=r.parent_id?t.get(r.parent_id):null;return n.join(` / `)};return e.map(e=>({...e,name:n(e)}))}var jc=[];function Mc(e){let{data:t=jc}=Vr(At.folders(e)),n=jt.folders(e).join(`/`),r=(0,X.useCallback)(t=>{U.setQueryData(jt.folders(e),e=>t(e??[]))},[n]),i=y({strict:!1}),a=b(),[o,s]=(0,X.useState)(()=>i.folder??null);(0,X.useEffect)(()=>{s(i.folder??null)},[i.folder]);let c=(0,X.useCallback)(e=>{a({to:`/app/library`,search:e?{folder:e}:{}})},[a]),l=(0,X.useCallback)(async()=>{await U.invalidateQueries({queryKey:jt.folders(e)})},[n]);return{folders:t,activeFolderId:o,navigateToFolder:c,refreshFolders:l,visibleFolders:(0,X.useMemo)(()=>t.filter(e=>(e.parent_id??null)===o),[t,o]),folderBreadcrumb:(0,X.useMemo)(()=>{if(!o)return[];let e=new Map(t.map(e=>[e.id,e])),n=[],r=e.get(o)??null,i=0;for(;r&&i++<50;)n.unshift(r),r=r.parent_id?e.get(r.parent_id)??null:null;return n},[t,o]),foldersWithPaths:(0,X.useMemo)(()=>Ac(t),[t]),createFolder:(0,X.useCallback)(async e=>{try{let t=await k.post(`/api/library/folders`,{name:e,parentId:o??void 0});r(e=>[...e,{...t.folder,itemCount:t.folder.itemCount??0}])}catch(e){if(e instanceof D&&e.status>0)return;throw e}},[o,r]),moveFolder:(0,X.useCallback)(async(e,t)=>{r(n=>n.map(n=>n.id===e?{...n,parent_id:t}:n));try{await k.patch(`/api/library/folders/${e}`,{parentId:t}),await l()}catch(e){if(l(),e instanceof D&&e.status>0){H.error(e.message||`Could not move the folder`);return}throw e}},[l,r]),renameFolder:(0,X.useCallback)(async(e,t)=>{try{await k.patch(`/api/library/folders/${e}`,{name:t}),r(n=>n.map(n=>n.id===e?{...n,name:t}:n))}catch(e){if(e instanceof D&&e.status>0)return;throw e}},[r]),describeFolder:(0,X.useCallback)(async(e,t)=>{try{await k.patch(`/api/library/folders/${e}`,{description:t}),r(n=>n.map(n=>n.id===e?{...n,description:t||null}:n))}catch(e){if(e instanceof D&&e.status>0){H.error(e.message||`Could not save the description`);return}throw e}},[r]),deleteFolder:(0,X.useCallback)(async(e,n=!1)=>{let r=new Set([e]),i=!0;for(;i;){i=!1;for(let e of t)e.parent_id&&r.has(e.parent_id)&&!r.has(e.id)&&(r.add(e.id),i=!0)}try{return await k.delete(`/api/library/folders/${e}${n?`?items=delete`:``}`),o&&r.has(o)&&c(null),await l(),!0}catch(e){if(e instanceof D&&e.status>0)return H.error(e.message||`Could not delete the folder`),n&&await l(),!1;throw e}},[t,l,o,c])}}async function Nc(e,t){try{await k.post(`/api/library/favorite`,{itemId:e,on:t})}catch{throw Error(`Could not update favorite`)}}function Pc(e){return e.length>0&&e.every(e=>!!e.is_favorite)}function Fc(e){return e.length>0&&e.every(e=>!!e.hidden_at)}function Ic(e){return e.map(e=>e.short_ref).filter(e=>!!e).join(` `)}var Lc=`mr-2.5 h-3.5 w-3.5 flex-shrink-0 text-zinc-500 dark:text-zinc-400`,Rc=``;async function zc(e){let t=Ic(e);if(!t)return!1;try{return await navigator.clipboard.writeText(t),!0}catch{return H.error(`Could not copy`),!1}}function Bc({menu:e,items:t,handlers:n}){let{activeWorkspaceId:r}
3=Nt(),{foldersWithPaths:i}=Mc(r),{labels:a,getItemLabelIds:o,setLabelOnItems:s}=Ec(r),c=t.length===1?t[0]:null,l=t.map(e=>e.id),u=t.length>0&&t.every(e=>!!e.is_favorite),d=t.length>0&&t.every(e=>!!e.hidden_at),p=t.some(e=>!!e.folder_id),m=t.length>0&&t.every(e=>e.folder_id===t[0].folder_id)?t[0].folder_id??null:void 0,h=new Set(a.filter(e=>t.length>0&&t.every(t=>o(t.id).has(e.id))).map(e=>e.id)),g=n.showCopy!==!1&&t.some(e=>!!e.short_ref),_=t.some(e=>!ne(e)&&!!or(e)),v=t.length>0&&t.every(hr),y=()=>{if(n.onStar){n.onStar(!u);return}Promise.all(t.map(e=>Nc(e.id,!u))).then(()=>n.onChanged?.()).catch(()=>H.error(`Could not save that`))},b=()=>{if(n.onHide){n.onHide(!d);return}k.post(`/api/library/items/hidden`,{item_ids:l,hidden:!d,workspace_id:r}).then(()=>n.onChanged?.()).catch(()=>H.error(`Could not save that`))},x=async e=>{if(n.onMove)return n.onMove(e),!0;let t=await ar({folderId:e,itemIds:l});return t?n.onChanged?.():H.error(`Could not move`),t},S=()=>{if(n.onSyncCloud){n.onSyncCloud();return}mr(t).then(e=>{e.length>0&&n.onChanged?.()})},C=()=>{if(n.onRemoveCloud){n.onRemoveCloud();return}pr(t).then(e=>{e.length>0&&n.onChanged?.()})},[w,T]=(0,X.useState)(!1),E=async()=>{await zc(t)&&(T(!0),setTimeout(()=>T(!1),1600))},D=f()===!0,O=!!n.onDownload||!!c&&!!n.onOpen;return(0,Z.jsxs)(Z.Fragment,{children:[n.onDownload&&(0,Z.jsxs)(e.Item,{onClick:n.onDownload,children:[(0,Z.jsx)(be,{className:Lc,strokeWidth:1.4}),`Download`]}),c&&n.onOpen&&(0,Z.jsxs)(e.Item,{onClick:n.onOpen,children:[(0,Z.jsx)(pt,{className:Lc,strokeWidth:1.4}),`Open`]}),n.showPlacement!==!1&&(0,Z.jsxs)(Z.Fragment,{children:[O&&(0,Z.jsx)(e.Separator,{className:`my-1 bg-black/[0.08] dark:bg-white/[0.08]`}),(0,Z.jsx)(Gs,{menu:e,folders:i,showRemove:p,onMove:x,currentId:m,keepOpen:!0}),(0,Z.jsx)(qs,{menu:e,labels:a,checkedIds:h,onToggle:(e,t)=>void s(e,t,l),onCreate:n.onCreateLabel}),!D&&(0,Z.jsx)(oc,{menu:e,items:t,onChanged:n.onChanged}),(0,Z.jsx)(uc,{menu:e,items:t,onChanged:n.onChanged,onPickDate:n.onPickDate}),(0,Z.jsx)(Sc,{menu:e,items:t})]}),n.extras&&(0,Z.jsxs)(Z.Fragment,{children:[(O||n.showPlacement!==!1)&&(0,Z.jsx)(e.Separator,{className:`my-1 bg-black/[0.08] dark:bg-white/[0.08]`}),n.extras]}),(0,Z.jsxs)(Z.Fragment,{children:[(O||n.showPlacement!==!1||!!n.extras)&&(0,Z.jsx)(e.Separator,{className:`my-1 bg-black/[0.08] dark:bg-white/[0.08]`}),g&&(0,Z.jsxs)(e.Item,{onSelect:e=>{e.preventDefault(),E()},children:[w?(0,Z.jsx)(V,{className:Lc,strokeWidth:1.6}):(0,Z.jsx)(ut,{className:Lc,strokeWidth:1.4}),w?t.length===1?`ID copied`:`IDs copied`:t.length===1?`Copy ID`:`Copy IDs`]}),n.showStar!==!1&&(0,Z.jsxs)(e.Item,{onClick:y,children:[(0,Z.jsx)(tt,{className:N(Lc,u&&`text-foreground opacity-100`),fill:u?`currentColor`:`none`,strokeWidth:1.4}),u?`Unstar`:`Star`]}),c&&n.onComment&&(0,Z.jsxs)(e.Item,{onClick:n.onComment,children:[(0,Z.jsx)(Ye,{className:Lc,strokeWidth:1.4}),`Comment`]}),n.onSelect&&(0,Z.jsxs)(e.Item,{onClick:n.onSelect,children:[(0,Z.jsx)(I,{className:Lc,strokeWidth:1.4}),`Select`]}),n.send,c&&n.onRename&&(0,Z.jsxs)(e.Item,{onClick:n.onRename,children:[(0,Z.jsx)(Fe,{className:Lc,strokeWidth:1.4}),`Rename`]}),_&&n.showCloud!==!1&&(0,Z.jsxs)(e.Item,{onClick:S,children:[(0,Z.jsx)(lt,{className:Lc,strokeWidth:1.4}),`Sync to cloud`]}),v&&n.showCloud!==!1&&(0,Z.jsxs)(e.Item,{onClick:C,children:[(0,Z.jsx)(ge,{className:Lc,strokeWidth:1.4}),t.length===1?`Remove cloud copy`:`Remove cloud copies`]}),(0,Z.jsxs)(e.Item,{onClick:b,children:[(0,Z.jsx)(dt,{className:Lc,strokeWidth:1.4}),d?`Show on feed`:`Hide from feed`]}),n.onDelete&&(0,Z.jsxs)(e.Item,{onClick:n.onDelete,className:Rc,children:[(0,Z.jsx)(Ke,{className:Lc,strokeWidth:1.4}),t.length===1?`Delete`:`Delete ${t.length} items`]})]}),t.length>1&&n.onClearSelection&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(e.Separator,{className:`my-1 bg-black/[0.08] dark:bg-white/[0.08]`}),(0,Z.jsxs)(e.Item,{onClick:n.onClearSelection,children:[(0,Z.jsx)(_t,{className:Lc,strokeWidth:1.4}),`Clear selection`]})]})]})}function Vc({open:e,onOpenChange:t,name:n,onNameChange:r,color:i,onColorChange:a,onCancel:o,onSubmit:s,editing:c=!1,nested:l=!1}){return(0,Z.jsx)(wn,{open:e,onOpenChange:t,children:(0,Z.jsxs)(Dn,{nested:l,className:`sm:max-w-[425px]`,children:[(0,Z.jsx)(zn,{className:`text-[13px] font-[460] max-md:text-[14.5px]`,children:c?`Edit label`:`New label`}),(0,Z.jsx)(`input`,{autoFocus:!0,value:n,onChange:e=>r(e.target.value),onKeyDown:e=>{e.key===`Enter`&&s()},maxLength:40,placeholder:`Label name`,className:`mt-3.5 flex h-9 w-full rounded-lg border border-zinc-200/70 bg-transparent px-3 text-[12px] font-[400] text-foreground max-md:h-11 max-md:text-[14px] outline-none placeholder:text-zinc-400 dark:border-[#2f2f2f] dark:placeholder:text-zinc-500`}),(0,Z.jsxs)(`div`,{className:`mt-3 flex flex-wrap items-center gap-1.5 px-0.5`,children:[Cs.map(e=>(0,Z.jsx)(`button`,{type:`button`,"aria-label":`Color ${e}`,onClick:()=>a(e),className:N(`flex h-5 w-5 items-center justify-center rounded-full transition-transform [@media(pointer:coarse)]:h-8 [@media(pointer:coarse)]:w-8`,i===e&&`ring-1 ring-offset-2 ring-zinc-400 max-md:ring-offset-[0.5px] max-md:scale-100 dar
3k:ring-zinc-500 dark:ring-offset-[#202020] scale-105`),children:(0,Z.jsx)(`span`,{className:`h-3.5 w-3.5 rounded-full ${ks[e]}`})},e)),(0,Z.jsxs)(`label`,{className:N(`relative flex h-5 w-5 cursor-pointer items-center justify-center rounded-full transition-transform [@media(pointer:coarse)]:h-8 [@media(pointer:coarse)]:w-8`,ws(i)&&`ring-1 ring-offset-2 ring-zinc-400 max-md:ring-offset-[0.5px] max-md:scale-100 dark:ring-zinc-500 dark:ring-offset-[#202020] scale-105`),"aria-label":`Custom color`,children:[(0,Z.jsx)(`input`,{type:`color`,value:ws(i)?i:`#6FA3D2`,onChange:e=>a(e.target.value),className:`absolute h-0 w-0 opacity-0`}),(0,Z.jsx)(`span`,{className:`flex h-3.5 w-3.5 items-center justify-center rounded-full`,style:ws(i)?{backgroundColor:i}:{background:`conic-gradient(#E1746E, #DFC15E, #6FA97F, #6FA3D2, #A585D8, #E1746E)`}})]})]}),(0,Z.jsxs)(`div`,{className:In,children:[(0,Z.jsx)(`button`,{type:`button`,onClick:o,className:Rn,children:`Cancel`}),(0,Z.jsx)(`button`,{type:`button`,onClick:s,disabled:!n.trim(),className:Fn,children:c?`Save`:`Create`})]})]})})}function Hc({itemIds:e,onClose:t}){let{activeWorkspaceId:n}=Nt(),{createLabel:r,setLabelOnItems:i}=Ec(n),[a,o]=(0,X.useState)(``),[s,c]=(0,X.useState)(`gray`),l=async()=>{let n=a.trim();if(!n)return;t();let o=await r(n,s);o&&await i(o.id,!0,e)};return(0,Z.jsx)(Vc,{nested:!0,open:!0,onOpenChange:e=>{e||t()},name:a,onNameChange:o,color:s,onColorChange:c,onCancel:t,onSubmit:()=>void l()})}function Uc(e){let t=$s(e),[n,r]=(0,X.useState)(null),i=(0,X.useCallback)(e=>()=>r(e.map(e=>e.id)),[]),a=(0,Z.jsxs)(Z.Fragment,{children:[t.dialog,n&&(0,Z.jsx)(Hc,{itemIds:n,onClose:()=>r(null)})]});return{pickDate:t.pickDate,newLabel:i,dialogs:a,open:t.open||!!n}}function Wc({url:e,plus:t=!1}){let[n,r]=(0,X.useState)(!1);return(0,Z.jsx)(`span`,{className:`mr-2.5 flex h-5 w-5 flex-shrink-0 items-center justify-center overflow-hidden rounded-[4px] bg-zinc-100 dark:bg-white/[0.06]`,children:t?(0,Z.jsx)(gt,{className:`h-3 w-3 text-zinc-500 dark:text-zinc-400`,strokeWidth:1.8}):e&&!n?(0,Z.jsx)(`img`,{src:e,alt:``,loading:`lazy`,decoding:`async`,onError:()=>r(!0),className:`h-full w-full object-cover`}):null})}function Gc(){return(0,Z.jsx)(`div`,{className:`flex h-7 items-center justify-center text-zinc-400 dark:text-zinc-500`,role:`status`,"aria-label":`Loading`,children:(0,Z.jsx)(Vn,{size:`sm`})})}function Kc({menu:e,itemIds:t}){return t.length===0?null:(0,Z.jsxs)(e.Sub,{children:[(0,Z.jsxs)(e.SubTrigger,{children:[(0,Z.jsx)(P,{className:`mr-2.5 h-3.5 w-3.5 flex-shrink-0 text-zinc-500 dark:text-zinc-400`,strokeWidth:1.4}),`Send to timeline`]}),(0,Z.jsx)(e.SubContent,{className:`max-h-64 w-60 overflow-y-auto`,children:(0,Z.jsx)(Jc,{menu:e,itemIds:t})})]})}var qc=new Map;function Jc({menu:e,itemIds:t}){let[n,r]=(0,X.useState)(null),[i,a]=(0,X.useState)(()=>Object.fromEntries(qc));(0,X.useEffect)(()=>{if(!n?.length)return;let e=!1,t=n.slice(0,120).map(e=>e.id);return k.get(`/api/editor/timelines?cards=${t.join(`,`)}`).then(t=>{if(e)return;let n={};for(let[e,r]of Object.entries(t.cards??{}))r.stills?.[0]&&(n[e]=r.stills[0],qc.set(e,r.stills[0]));a(n)}).catch(()=>{}),()=>{e=!0}},[n]);let{activeWorkspaceId:o}=Nt(),s=b();(0,X.useEffect)(()=>{if(!o){r([]);return}let e=!1;return h().then(()=>g().getAll(`SELECT id, name FROM timeline_variations WHERE workspace_id = ? ORDER BY updated_at DESC`,[o])).then(t=>{e||r(t.map(e=>({id:e.id,name:e.name??`Untitled timeline`})))}).catch(()=>{e||r([])}),()=>{e=!0}},[o]);let c=(0,X.useCallback)(async(e,n)=>{try{let r=await k.post(`/api/library/items/send-to-timeline`,{timelineId:e,itemIds:t});r.placed?H.success(r.skipped?`Sent ${r.placed} to ${n}. ${r.skipped} could not be added.`:`Sent to ${n}`,{duration:4e3,action:{label:`Open`,onClick:()=>{s({to:`/app/editor/$id`,params:{id:e}})}}}):H.info(`None of these can go on a timeline`,{duration:3e3})}catch{H.error(`Could not send to that timeline`,{duration:3e3})}},[t,s]),l=(0,X.useCallback)(async()=>{try{let{id:e}=await k.post(`/api/editor/timelines`,{mode:`blank`});await c(e,`Untitled timeline`)}catch{H.error(`Could not create a timeline`,{duration:3e3})}},[c]);return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(e.Item,{onClick:()=>void l(),children:[(0,Z.jsx)(Wc,{plus:!0}),`New timeline`]}),n===null&&(0,Z.jsx)(Gc,{}),n?.map(t=>(0,Z.jsxs)(e.Item,{onClick:()=>void c(t.id,t.name),children:[(0,Z.jsx)(Wc,{url:i[t.id]}),(0,Z.jsx)(`span`,{className:`truncate`,children:t.name})]},t.id))]})}function Yc({menu:e,itemIds:t}){return t.length===0?null:(0,Z.jsxs)(e.Sub,{children:[(0,Z.jsxs)(e.SubTrigger,{children:[(0,Z.jsx)(rt,{className:`mr-2.5 h-3.5 w-3.5 flex-shrink-0 text-zinc-500 dark:text-zinc-400`,strokeWidth:1.4}),`Send to canvas`]}),(0,Z.jsx)(e.SubContent,{className:`max-h-64 w-60 overflow-y-auto`,children:(0,Z.jsx)(Xc,{menu:e,itemIds:t})})]})}function Xc({menu:e,itemIds:t}){let[n,r]=(0,X.useState)(null),i=b();(0,X.useEffect)(()=>{let e=!1;return k.get(`/api/canvases`).then(t=>{e||r((t.canvases??[]).filter(e=>!e.isTemplate))}).catch(()=>{e||r([])}),()=>{e=!0}},[]);let a=(e,t)=>{H.success(`Sent to ${t}`,{duration:4e3,action:{label:`Open`,onClick:()=>{i({to:`/app/image/$id`,params:{id:e}})}}})},o=(0,X.useCallback)(async(e,n,r=t)=>{try{(await k.post(`/api/canvases/${e}/place`,{itemIds:r})).placed?a(e,n):H.info(`Only images can go on a canvas`,{duration:3e3})}catch(e){H.error(e instanceof D?e.message:`Could not send to that canvas`,{duration:3e3})}},[t]),s=(0,X.useCallback)(async()=>{try{let{id:e}=await k.post(`/api/canvases`,{mode:`item`,itemId:t[0]});t.length>1?await o(e,`a new canvas`,t.slice(1)):a(e,`a new canvas`)}catch(e){H.error(e instanceof D?e.message:`Could not create a canvas`,{duration:3e3})}},[t,o]);return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(e.Item,{onClick:()=>void s(),children:[(0,Z.jsx)(Wc,{plus:!0}),`New canvas`]}),n===null&&(0,Z.jsx)(Gc,{}),n?.map(t=>(0,Z.jsxs)(e.Item,{onClick:()=>void o(t.id,t.name),children:[(0,Z.jsx)(Wc,{url:t.posterUrl}),(0,Z.jsx)(`span`,{className:`truncate`,children:t.name})]},t.id))]})}async function Zc(e){if(!a)return null;let t=i(),n=or(e);if(!t||!n)return null;let r=n.path.split(/[\\/]/).pop()||e.file_name||``,o=typeof e.sha256==`string`&&/^[a-f0-9]{64}$/.test(e.sha256)?e.sha256:void 0,s=await a.media.find({name:r,size:n.size,mtime:n.mtime,sha256:o}).catch(()=>null);if(!s){let[e]=await a.media.pick(`any`);if(!e)return null;s=e}let[c]=await a.media.import([s]);if(!c)return H.error(`That file could not be opened`),null;c.size!==n.size&&H.message(`This file is a different size from the one that was imported`);let{item:l}=await k.patch(`/api/library/local/${e.id}`,{device:t,presence:{path:c.path,size:c.size,mtime:c.mtime}});return sr(e.id),H.success(`File found`),l}function Qc({isOpen:e,onClose:t}){return(0,X.useEffect)(()=>{e&&(H(`Out of credits`,{duration:4e3}),t())},[e,t]),null}
3var $c=class extends Error{required;available;constructor(e,t){super(`Insufficient credits`),this.required=e,this.available=t,this.name=`EnhanceCreditsError`}},el=null;function tl(){return el||=k.get(`/api/pricing/enhancements`).catch(e=>{throw el=null,e}),el}function nl(){let[e,t]=(0,X.useState)(null);return(0,X.useEffect)(()=>{let e=!0,n=null,r=i=>{tl().then(n=>{e&&t(n)}).catch(()=>{e&&i<rl&&(n=setTimeout(()=>r(i+1),il))})};return r(0),()=>{e=!1,n&&clearTimeout(n)}},[]),e}var rl=5,il=4e3;function al(e,t){return Oo(e.upscaleVideoPerSecond*(t&&t>0?t:5))}function ol(e,t){return e?t.media===`video`?al(e,t.durationSeconds):e.upscaleImage:null}async function sl(e,t,n){try{return await k.post(e,t)}catch(e){if(e instanceof D){if(e.status===402||e.code===`insufficient_credits`){let t=e.details;throw new $c(t?.required??0,t?.available??0)}throw Error(e.message||n)}throw e}}function cl(e){return sl(`/api/library/items/upscale`,{url:e.url,mediaType:e.media,...e.itemId?{itemId:e.itemId}:{}},`Could not upscale this one`)}function ll(e,t){return sl(`/api/library/items/remove-background`,{url:e,...t?{itemId:t}:{}},`Could not remove the background`)}function ul(e){return sl(`/api/library/items/remove-video-background`,{url:e},`Could not start background removal`)}function dl(e,t){if(!e)return null;let n=t&&t>0?t:10;return Oo(e.removeVideoBackgroundPerSecond*n)}var fl=class extends Error{constructor(){super(`Still working on it. It appears in your library when it is done.`),this.name=`EnhanceStillRunningError`}};async function pl(e,t=3e5){let[{supabase:n},{watchRows:i},{listenWorkspace:a},{ROW_CHANGE_EVENT:o}]=await Promise.all([r(()=>import(`./supabase-Bmf_ZcoY.js`),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14])),r(()=>import(`./watch-Bwp1UJZt.js`),__vite__mapDeps([15,16,17,18,3,4,5,1,2,6,13,14])),r(()=>import(`./workspace-topic-BqUy0OE5.js`),__vite__mapDeps([19,20,18,1,2,3,4,5,6,21])),r(()=>import(`./workspace-topic-CIoBJu8N.js`),__vite__mapDeps([22,21]))]),s=e=>e===`failed`||e===`cancelled`,c=async()=>{let{data:t}=await n.from(`generations`).select(`status, workspace_id`).eq(`id`,e).maybeSingle();return t??null},l=async()=>(await c())?.status??null;return new Promise((r,u)=>{let d=!1,f,p=[],m=e=>{if(!d){d=!0,f&&clearTimeout(f);for(let e of p)e();e()}},h=e=>{if(e?.url){let t=e.url;m(()=>r({itemId:e.id,url:t}))}},g=()=>m(()=>u(Error(`The edit failed`)));p.push(i(`SELECT id, url FROM library_items WHERE generation_id = ? AND url IS NOT NULL LIMIT 1`,[e],e=>e,e=>h(e[0]))),c().then(t=>{if(d)return;if(s(t?.status)){g();return}let n=t?.workspace_id;n&&p.push(a(n,{onMessage:(t,n)=>{let r=n;t===o&&r?.t===`generations`&&r.id===e&&l().then(e=>{s(e)&&g()}).catch(()=>void 0)},onStatus:e=>{e!==`down`&&l().then(e=>{s(e)&&g()}).catch(()=>void 0)}}))}).catch(()=>void 0),f=setTimeout(()=>{(async()=>{try{if(s(await l())){g();return}let{data:t}=await n.from(`library_items`).select(`id, url`).eq(`generation_id`,e).not(`url`,`is`,null).limit(1).maybeSingle();h(t??void 0)}catch{}m(()=>u(new fl))})()},t)})}async function ml(e,t){let{uploadAttachment:n}=await r(async()=>{let{uploadAttachment:e}=await import(`./item-client-CH_pgFic.js`);return{uploadAttachment:e}},__vite__mapDeps([23,24,3,4,5,17,18,1,2,6,13,14,7,8,9,10,11,12,25])),i=await n(e),a=await pl((t===`upscale`?await cl({url:i.url,media:`image`}):await ll(i.url)).generationId),{getPublicMediaUrl:o}=await r(async()=>{let{getPublicMediaUrl:e}=await import(`./url-helpers-BtH77Ffc.js`);return{getPublicMediaUrl:e}},__vite__mapDeps([26,27])),s=o(a.url),c;try{let e=await fetch(s);if(!e.ok)throw Error(`Could not read the result`);c=await e.blob()}catch(e){if(e instanceof Error&&e.message===`Could not read the result`)throw e;c=await k.blob(`/api/proxy-image`,{query:{url:s}})}let l=e.name.replace(/\.[^./\\]+$/,``)||`image`,u=(c.type.split(`/`)[1]||`png`).split(`+`)[0];return new File([c],`${l}.${u}`,{type:c.type||`image/png`})}async function hl(e,t=.95){if(!e||!e.videoWidth||!e.videoHeight)throw Error(`Something went wrong, please try again.`);let n=document.createElement(`canvas`);n.width=e.videoWidth,n.height=e.videoHeight;let r=n.getContext(`2d`);if(!r)throw Error(`Something went wrong, please try again.`);r.drawImage(e,0,0,n.width,n.height);let i=await new Promise((e,r)=>{n.toBlob(t=>
3{t?e(t):r(Error(`Failed to create blob from canvas`))},`image/jpeg`,t)}),a=`snapshot-${Date.now()}.jpg`;return new File([i],a,{type:`image/jpeg`})}function gl(e){return q(e.currentTime||0)}function _l(e){if(!e)return null;for(let t of[e.storage_metadata,e.metadata]){let e=t&&typeof t==`object`?t.rendered_from_canvas_id:null;if(typeof e==`string`&&e)return e}return null}var vl=new Map;function yl(e){let t=vl.get(e);return t||(t=new Map,vl.set(e,t)),t}var bl=new Map,xl=new Map,Sl=1e4,Cl=new Map,wl=3e5;function Tl(e,t=!1){let n=bl.get(e);if(n)return n;let r=Cl.get(e);if(!t&&r&&Date.now()-r.at<wl)return Promise.resolve(r.detail);let i=(async()=>{try{let t=await k.get(`/api/library/item-detail`,{query:{itemId:e}});yl(`variations`).set(e,t.variations??[]),xl.set(e,Date.now());let n={transcript:t.transcript??null};return Cl.set(e,{at:Date.now(),detail:n}),n}catch{return null}finally{bl.delete(e)}})();return bl.set(e,i),i}function El(e,t,n,r){let i=yl(e),[a,o]=(0,X.useState)(()=>i.get(t)??null),s=(0,X.useRef)(r);s.current=r;let c=(0,X.useCallback)(async()=>{try{let e=s.current(await k.get(n));i.set(t,e),o(e)}catch{o(e=>e??[])}},[i,t,n]);return(0,X.useEffect)(()=>{o(i.get(t)??null);let e=!1;return(async()=>{await Promise.resolve();let n=bl.get(t);if(n&&await n,e)return;let r=i.get(t);if(r&&Date.now()-(xl.get(t)??0)<Sl){o(r);return}await c()})(),()=>{e=!0}},[i,t,c]),{data:a,reload:c,write:(0,X.useCallback)(e=>{e&&i.set(t,e),o(e)},[i,t]),invalidate:(0,X.useCallback)(()=>{i.delete(t)},[i,t]),invalidateAll:(0,X.useCallback)(()=>{i.clear()},[i])}}function Dl({target:e,onOpen:t,canOpen:n,onChanged:r}){let{data:i,reload:a,invalidateAll:o}=El(`variations`,e,`/api/library/variations?itemId=${e}`,e=>e.members??[]),[s,c]=(0,X.useState)(!1),[l,u]=(0,X.useState)(!1),[d,f]=(0,X.useState)(()=>new Set),p=(0,X.useCallback)(async e=>{if(!s){c(!0);try{await k.post(`/api/library/variations`,{action:`ungroup`,cards:[e.id]}),o(),await a(),r?.()}catch(e){H.error(e instanceof D?e.message:`Could not update variations`)}finally{c(!1)}}},[s,o,a,r]);if(!i||i.length<2)return null;let m=i.findIndex(t=>t.id===e),h=i.length>Ol,g=l||!h?i:i.filter((e,t)=>t<Ol||t===m);return(0,Z.jsxs)(`div`,{children:[(0,Z.jsxs)(`div`,{className:`flex items-start gap-1`,children:[(0,Z.jsx)(`span`,{className:`w-[80px] flex-shrink-0 pb-[8px] pt-[7px] text-[12px] font-[400] leading-[14px] text-zinc-400 dark:text-zinc-500`,children:`Variations`}),h&&(0,Z.jsx)(`button`,{type:`button`,"aria-expanded":l,onClick:()=>u(e=>!e),className:`flex min-h-[28px] items-center rounded-[7px] px-1.5 py-1 text-[12px] font-[400] text-zinc-700 transition-colors duration-100 hover:text-foreground dark:text-zinc-300 dark:hover:text-white`,children:l?`Hide`:`Show all ${i.length}`})]}),(0,Z.jsx)(`div`,{className:`-mx-1.5`,children:g.map(r=>{let i=r.id===e,a=!i&&(!n||n(r.id)),o=d.has(r.id);return(0,Z.jsxs)(`div`,{className:`group flex min-h-[32px] items-center gap-2 rounded-[7px] px-1.5 py-0.5 transition-colors duration-100 ${i?`text-foreground [&_img]:opacity-100`:`text-zinc-600 hover:text-foreground dark:text-zinc-400 dark:hover:text-white`}`,children:[(0,Z.jsxs)(`button`,{type:`button`,disabled:!a,"aria-label":!i&&!a?`Not in the current view`:void 0,onClick:()=>a&&t?.(r.id),className:`flex min-w-0 flex-1 items-center gap-2 text-left disabled:cursor-default`,children:[(0,Z.jsx)(`span`,{className:`relative h-6 w-6 flex-shrink-0 overflow-hidden rounded-[4px] bg-zinc-200 dark:bg-white/[0.08]`,children:r.thumbnail&&!o?(0,Z.jsx)(`img`,{src:J(r.thumbnail),alt:``,loading:`lazy`,decoding:`async`,onError:()=>f(e=>new Set(e).add(r.id)),className:`absolute inset-0 h-full w-full object-cover opacity-80 transition-opacity duration-100 group-hover:opacity-100`}):null}),(0,Z.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-[12px] font-[400]`,children:r.title||`Item`})]}),i&&(0,Z.jsx)(`span`,{className:`flex-shrink-0 text-[11px] font-[400] text-zinc-400 dark:text-zinc-500`,children:`Viewing`}),(0,Z.jsx)(Hn,{text:`Remove from variations`,children:(0,Z.jsx)(`button`,{type:`button`,"aria-label":`Remove from variations`,disabled:s,onClick:()=>p(r),className:`flex h-5 w-5 flex-shrink-0 items-center justify-center text-zinc-400 transition-colors duration-100 hover:text-foreground relative [@media(pointer:coarse)]:after:absolute [@media(pointer:coarse)]:after:-inset-2.5 [@media(pointer:coarse)]:after:content-[''] disabled:opacity-50 dark:text-zinc-500 dark:hover:text-white`,children:(0,Z.jsx)(Te,{className:`h-3 w-3`,strokeWidth:1.7})})})]},r.id)})})]})}var Ol=2;function kl({ratio:e,size:t=16,strokeWidth:n=1}){let r={width:t,height:t},i=String(e).split(`:`),a=Number(i[0])||1,o=Number(i[1])||1,s=a>=o?12:12*a/o,c=o>
3=a?12:12*o/a,l=(16-s)/2,u=(16-c)/2;return(0,Z.jsx)(`span`,{className:`flex items-center justify-center`,style:r,children:(0,Z.jsx)(`svg`,{width:t,height:t,viewBox:`0 0 16 16`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,children:(0,Z.jsx)(`rect`,{x:l,y:u,width:s,height:c,rx:`1`,stroke:`currentColor`,strokeWidth:n})})})}var Al=N(Za,`h-9 justify-center text-zinc-600 hover:text-foreground dark:text-zinc-300 dark:hover:text-foreground`),jl=`h-3.5 w-3.5 flex-shrink-0`;function Ml({isOpen:e,onClose:t,imageUrl:n,imageName:i,isEditable:a=!1,onImageEdit:o,onBackgroundRemoval:s,onUpscale:c,originalFile:l,cropOnly:u=!1}){let[d,p]=(0,X.useState)(1),[m,h]=(0,X.useState)({x:0,y:0}),[g,_]=(0,X.useState)(!1),[v,y]=(0,X.useState)({x:0,y:0}),[b,x]=(0,X.useState)(!1),[S,C]=(0,X.useState)({x:0,y:0,width:0,height:0}),[w,T]=(0,X.useState)(!1),[E,D]=(0,X.useState)({x:0,y:0}),[O,k]=(0,X.useState)(!1),[ee,te]=(0,X.useState)(!1),[ne,re]=(0,X.useState)({x:0,y:0}),[A,ie]=(0,X.useState)(`Custom`),ae=f()===!0&&b,[oe,j]=(0,X.useState)(!1),[M,se]=(0,X.useState)(!1),ce=nl(),le=ce?.upscaleImage??null,[P,F]=(0,X.useState)(null),[ue,de]=(0,X.useState)(!1),[pe,I]=(0,X.useState)(null),me=(0,X.useRef)(null),L=(0,X.useRef)(null);(0,X.useEffect)(()=>{e&&(p(1),h({x:0,y:0}),x(u),C({x:0,y:0,width:0,height:0}),k(!1),te(!1),ie(`Custom`),se(!1),j(!1),F(null))},[e,u]),(0,X.useEffect)(()=>{if(!e)return;let n=e=>{e.key===`Escape`&&(e.target instanceof Element&&e.target.closest(`[role="menu"]`)||(e.stopPropagation(),b&&!u?(x(!1),C({x:0,y:0,width:0,height:0}),p(1),h({x:0,y:0})):t()))};return window.addEventListener(`keydown`,n,!0),()=>window.removeEventListener(`keydown`,n,!0)},[e,t,b,u]);let he=(0,X.useRef)(null);(0,X.useEffect)(()=>{let t=he.current;if(!e||!t||b)return;let n=e=>{e.preventDefault();let t=e.deltaY>0?.9:1.1;p(e=>Math.max(.5,Math.min(3,e*t)))};return t.addEventListener(`wheel`,n,{passive:!1}),()=>t.removeEventListener(`wheel`,n)},[e,b]);let ge=e=>{if(b){let t=e.currentTarget.getBoundingClientRect(),n=e.clientX-t.left,r=e.clientY-t.top;S.width>0&&S.height>0&&n>=S.x&&n<=S.x+S.width&&r>=S.y&&r<=S.y+S.height?(te(!0),re({x:n-S.x,y:r-S.y})):(D({x:n,y:r}),k(!0),C({x:n,y:r,width:0,height:0}))}else d>1&&!b&&(_(!0),y({x:e.clientX-m.x,y:e.clientY-m.y}))},ve=e=>{if(b){let t=e.currentTarget.getBoundingClientRect(),n=e.clientX-t.left,r=e.clientY-t.top;if(ee){let e=n-ne.x,t=r-ne.y,i=L.current,a=0,o=0;if(i){let e=i.getBoundingClientRect();a=e.width-S.width,o=e.height-S.height}C({x:Math.max(0,Math.min(e,a)),y:Math.max(0,Math.min(t,o)),width:S.width,height:S.height})}else if(O){let e=Math.abs(n-E.x),t=Math.abs(r-E.y);if(A!==`Custom`){let[n,r]=A.split(`:`).map(Number),i=n/r;e>t?t=e/i:e=t*i}C({x:n>=E.x?E.x:E.x-e,y:r>=E.y?E.y:E.y-t,width:e,height:t})}}else g&&d>1&&!b&&h({x:e.clientX-v.x,y:e.clientY-v.y})},ye=()=>{b?ee?te(!1):O&&(k(!1),(S.width<10||S.height<10)&&C({x:0,y:0,width:0,height:0})):_(!1)},be=e=>{if(ie(e),S.width>0&&S.height>0&&e!==`Custom`){let[t,n]=e.split(`:`).map(Number),r=t/n,i=S.width,a=S.height;i>a?a=i/r:i=a*r,i>800&&(i=800,a=i/r),a>600&&(a=600,i=a*r),C({x:S.x,y:S.y,width:i,height:a})}},xe=()=>{x(!0),p(1),h({x:0,y:0}),C({x:0,y:0,width:0,height:0}),k(!1),te(!1)},Se=async()=>{if(!l||!o||S.width<10||S.height<10){H.error(`Drag on the image to choose an area`,{duration:4e3});return}T(!0);try{await o(await Te(l,S)),t()}catch{H.error(`Could not crop the image`,{duration:4e3})}finally{T(!1)}},Ce=async()=>{if(!l||!s||oe){oe||H.error(`Could not remove the background`,{duration:4e3});return}j(!0);let e=ce?.removeBackground??0,{checkMinimumBalance:n}=await r(async()=>{let{checkMinimumBalance:e}=await import(`./check-balance-CvW6g6NH.js`);return{checkMinimumBalance:e}},__vite__mapDeps([28,29,13,3,4,5,1,2,6,14])),i=await n(e);if(!i.hasEnough){j(!1),I({required:e,available:i.balance}),de(!0);return}try{await s(l),t()}catch{H.error(`Could not remove the background`,{duration:4e3})}finally{j(!1)}},we=async()=>{if(!l||!c||M)return;let e=le??0,{checkMinimumBalance:t}=await r(async()=>{let{checkMinimumBalance:e}=await import(`./check-balance-CvW6g6NH.js`);return{checkMinimumBalance:e}},__vite__mapDeps([28,29,13,3,4,5,1,2,6,14])),n=await t(e);if(!n.hasEnough){I({required:e,available:n.balance}),de(!0);return}se(!0);try{c(l)}catch{se(!1),H.error(`Could not upscale the image`,{duration:4e3})}},Te=async(e,t)=>new Promise((n,r)=>{let i=me.current;if(!i){r(Error(`Canvas not available`));return}let a=new Image,o=URL.createObjectURL(e);a.onload=()=>{try{let s=i.getContext(`2d`);if(!s){r(Error(`Canvas context not available`));return}let c=L.current;if(!c){r(Error(`Image element not available`));return}let l=c.getBoundingClientRect(),u=c.parentElement?.getBoundingClientRect();if(!u){r(Error(`Container not available`));return}
3let d=l.width,f=l.height,p=a.naturalWidth,m=a.naturalHeight,h=l.left-u.left,g=l.top-u.top,_=(t.x-h)*(p/d),v=(t.y-g)*(m/f),y=t.width*(p/d),b=t.height*(m/f);i.width=y,i.height=b,s.clearRect(0,0,i.width,i.height),s.drawImage(a,_,v,y,b,0,0,y,b),i.toBlob(t=>{if(URL.revokeObjectURL(o),!t||t.size===0){r(Error(`Failed to create blob from cropped image`));return}let i=t.type&&t.type.startsWith(`image/`)?t.type:`image/jpeg`,a=i===`image/png`?`png`:`jpg`,s=`${e.name.replace(/\.[^/.]+$/,``)}_cropped.${a}`;n(new File([t],s,{type:i}))},`image/jpeg`,.95)}catch(e){URL.revokeObjectURL(o),r(e)}},a.onerror=()=>{URL.revokeObjectURL(o),r(Error(`Failed to load image`))},a.src=o});return e?(0,Ur.createPortal)((0,Z.jsxs)(`div`,{className:N(`z-[9999]`,Wa,ae&&`pb-[env(safe-area-inset-bottom)] pt-[env(safe-area-inset-top)]`),onClick:e=>{e.target===e.currentTarget&&(e.stopPropagation(),t())},onPointerDown:e=>{e.target===e.currentTarget&&e.stopPropagation()},children:[(0,Z.jsxs)(`div`,{className:Ga,onMouseDown:e=>{e.target===e.currentTarget&&t()},children:[(0,Z.jsxs)(`div`,{className:N(Ka,`overflow-hidden`),onMouseDown:e=>{e.target===e.currentTarget&&t()},children:[!a&&(0,Z.jsx)(`button`,{type:`button`,"aria-label":`Close`,onClick:t,className:N(`absolute right-3 top-3 z-10`,`flex items-center gap-0.5 rounded-full bg-zinc-100/90 dark:bg-[#202020]/90 p-[3px] backdrop-blur-md`,`flex h-[26px] w-[26px] items-center justify-center rounded-full text-zinc-500 dark:text-zinc-400 aria-pressed:text-foreground dark:aria-pressed:text-white transition-colors duration-100 hover:bg-black/10 dark:hover:bg-white/10 hover:text-foreground dark:hover:text-white data-[state=open]:bg-black/10 dark:data-[state=open]:bg-white/10 data-[state=open]:text-foreground dark:data-[state=open]:text-white`,`max-md:top-[calc(env(safe-area-inset-top)+11px)] max-md:h-11 max-md:w-11 max-md:p-0 max-md:[&_svg]:h-5 max-md:[&_svg]:w-5`),children:(0,Z.jsx)(_t,{className:`h-3.5 w-3.5`,strokeWidth:1.8})}),(0,Z.jsx)(`div`,{className:N(`absolute inset-0 flex items-center justify-center px-4 pb-14 pt-4 pointer-events-none`,ae&&`pb-[92px] pt-[60px]`),children:(0,Z.jsxs)(`div`,{className:`relative flex max-h-full max-w-full pointer-events-auto touch-none`,onPointerDown:e=>{e.currentTarget.setPointerCapture(e.pointerId),ge(e)},onPointerMove:ve,onPointerUp:ye,onPointerCancel:ye,ref:he,children:[(0,Z.jsx)(`img`,{ref:L,src:n,alt:i||`Preview`,className:N(qa,`max-h-[calc(100dvh-4.5rem)] object-contain`,ae&&`max-h-[calc(100dvh-152px-env(safe-area-inset-top)-env(safe-area-inset-bottom))]`,b?`cursor-crosshair`:`cursor-move`),style:{transform:`scale(${d}) translate(${m.x}px, ${m.y}px)`,transition:g?`none`:`transform 0.1s ease-out`},draggable:!1}),b&&S.width>0&&S.height>0&&(0,Z.jsx)(`div`,{className:`absolute border-2 border-white shadow-lg cursor-move`,style:{left:S.x,top:S.y,width:S.width,height:S.height,pointerEvents:`auto`},children:(0,Z.jsx)(`div`,{className:`absolute inset-0 bg-black/20`})}),b&&S.width===0&&S.height===0&&(0,Z.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center pointer-events-none`,children:(0,Z.jsx)(`div`,{className:`rounded-full bg-black/60 px-3 py-1 text-[12px] font-[400] text-white max-md:px-3.5 max-md:py-1.5 max-md:text-[13.5px]`,children:`Drag to choose the area`})})]})})]}),ae&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`div`,{className:`absolute inset-x-0 top-0 z-20 flex h-[52px] items-center px-2`,children:[(0,Z.jsx)(`button`,{type:`button`,onClick:u?t:()=>x(!1),className:`flex h-10 items-center px-2.5 text-[14.5px] font-[400] text-zinc-500 active:text-foreground dark:text-zinc-400`,children:`Cancel`}),(0,Z.jsx)(`span`,{className:`flex-1 text-center text-[15px] font-[460] text-foreground`,children:`Crop`}),(0,Z.jsx)(`button`,{type:`button`,onClick:Se,disabled:w||S.width<10||S.height<10,className:`flex h-9 items-center rounded-full bg-zinc-900 px-4 text-[14px] font-[440] text-white disabled:opacity-40 dark:bg-white dark:text-black`,children:w?`Croppingâ¦`:`Apply`})]}),(0,Z.jsx)(`div`,{className:`absolute inset-x-0 bottom-0 z-20 flex h-[84px] items-center gap-1.5 overflow-x-auto px-3 [scrollbar-width:none] [&::-webkit-scrollbar]:hidden`,children:[...gr,`Custom`].map(e=>(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>be(e),"aria-pressed":A===e,className:N(`flex h-14 min-w-[56px] flex-shrink-0 flex-col items-center justify-center gap-1 rounded-[10px] px-2 text-[12px] font-[400] transition-colors`,A===e?`bg-zinc-100 text-foreground dark:bg-white/[0.08]`:`text-zinc-500 dark:text-zinc-400`),children:[e===`Custom`?(0,Z.jsx)(fe,{className:`h-4 w-4`,strokeWidth:1.4}):(0,Z.jsx)(kl,{ratio:e,size:16,strokeWidth:1.3}),e]},e))})]}),a&&!ae&&(0,Z.jsxs)(`div`,{className:`relative flex w-full max-h-[45dvh] flex-shrink-0 flex-col overflow-hidden border-t border-black/[0.08] dark:border-white/[0.08] max-md:pb-[env(safe-area-inset-bottom)] md:max-h-none md:w-[340px] md:border-l md:border-t-0`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-shrink-0 items-center gap-1.5 px-3 pt-3`,children:[(0,Z.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-[12px] font-[440] text-foreground`,children:i||`Attachment`}),(0,Z.jsx)(`button`,{type:`button`,"aria-label":`Close`,onClick:t,className:`flex h-7 w-7 items-center justify-center rounded-full text-zinc-400 transition-colors duration-100 hover:bg-zinc-100 hover:text-foreground dark:text-zinc-500 dark:hover:bg-white/[0.06] dark:hover:text-foreground max-md:h-10 max-md:w-10`,children:(0,Z.jsx)(_t,{className:`h-3.5 w-3.5`,strokeWidth:1.8})})]}),(0,Z.jsx)(`div`,{className:`flex-1 overflow-y-auto px-4 pb-3 pt-2`,children:b&&(0,Z.jsxs)(`div`,{className:`flex items-baseline gap-3 py-2`,children:[(0,Z.jsx)(`span`,{className:`w-14 flex-shrink-0 text-[12px] font-[380] text-zinc-400 dark:text-zinc-500`,children:`Crop`}),(0,Z.jsx)(`span`,{className:`min-w-0 truncate text-[12px] font-[380] text-zinc-500 dark:text-zinc-400`,children:`Drag on the image to choose`})]})}),(0,Z.jsx)(`div`,{className:`flex flex-col gap-1.5 px-3 pb-3 pt-2`,children:b?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(hn,{children:[(0,Z.jsx)(dn,{asChild:!0,children:(0,Z.jsxs)(`button`,{type:`button`,className:N(Al,`justify-between`),children:[(0,Z.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(fe,{className:jl,strokeWidth:1.6}),`Ratio: `,A]}),(0,Z.jsx)(ot,{className:jl,strokeWidth:1.6})]})}),(0,Z.jsx)(mn,{align:`start`,side:`top`,className:`z-[10000] w-[var(--radix-dropdown-menu-trigger-width)] min-w-0 max-h-[min(480px,var(--radix-dropdown-menu-content-available-height))] overflow-y-auto`,sideOffset:4,children:[...gr,`Custom`].map(e=>(0,Z.jsxs)(G,{onClick:()=>be(e),children:[(0,Z.jsx)(`span`,{className:`mr-2.5 flex h-3.5 w-3.5 flex-shrink-0 items-center justify-center text-zinc-500 dark:text-zinc-400`,children:e===`Custom`?(0,Z.jsx)(fe,{className:`h-3.5 w-3.5`,strokeWidth:1.4}):(0,Z.jsx)(kl,{ratio:e,size:14,strokeWidth:1.3})}),e]},e))})]}),(0,Z.jsxs)(`button`,{type:`button`,onClick:Se,disabled:w||S.width<10||S.height<10,className:N(Al,`disabled:opacity-40`),children:[(0,Z.jsx)(fe,{className:jl,strokeWidth:1.6}),w?`Croppingâ¦`:`Apply crop`]}),(0,Z.jsxs)(`button`,{type:`button`,onClick:u?t:()=>x(!1),className:Al,children:[(0,Z.jsx)(_t,{className:jl,strokeWidth:1.6}),`Exit crop`]})]}):(0,Z.jsxs)(Z.Fragment,{children:[!u&&(0,Z.jsxs)(`button`,{type:`button`,onClick:xe,className:`flex h-8 w-full items-center gap-1.5 rounded-full bg-zinc-100 px-3.5 text-12 font-[440] text-foreground transition-colors duration-100 max-md:h-10 max-md:text-[14px] hover:bg-zinc-200/70 data-[state=open]:bg-zinc-200/70 dark:bg-white/[0.06] dark:hover:bg-white/[0.1] dark:data-[state=open]:bg-white/[0.1]`,children:[(0,Z.jsx)(fe,{className:`h-3.5 w-3.5 flex-shrink-0 text-zinc-500 dark:text-zinc-400`,strokeWidth:1.6}),`Crop`]}),!u&&s&&(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>
3{if(P!==`background`){F(`background`);return}F(null),Ce()},disabled:oe,className:N(`flex h-8 w-full items-center gap-1.5 rounded-full bg-zinc-100 px-3.5 text-12 font-[440] text-foreground transition-colors duration-100 max-md:h-10 max-md:text-[14px] hover:bg-zinc-200/70 data-[state=open]:bg-zinc-200/70 dark:bg-white/[0.06] dark:hover:bg-white/[0.1] dark:data-[state=open]:bg-white/[0.1]`,`disabled:opacity-50`,P===`background`&&`bg-zinc-900 text-white hover:bg-zinc-800 focus:bg-zinc-800 focus:text-white dark:bg-white dark:text-black dark:hover:bg-zinc-200 dark:focus:bg-zinc-200 dark:focus:text-black`),children:[(0,Z.jsx)(_e,{className:N(`h-3.5 w-3.5 flex-shrink-0 text-zinc-500 dark:text-zinc-400`,P===`background`&&`text-current`),strokeWidth:1.6}),P===`background`&&!oe?`Confirm`:`Remove background`,oe&&(0,Z.jsx)(Dc,{className:`ml-auto`}),!oe&&ce&&(0,Z.jsxs)(`span`,{className:N(`ml-auto text-[12px] font-[400] tabular-nums`,P===`background`?`text-current opacity-80`:`text-zinc-400 dark:text-zinc-500`),children:[ko(ce.removeBackground),` credits`]})]}),!u&&c&&(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>{if(P!==`upscale`){F(`upscale`);return}F(null),we()},disabled:M,className:N(`flex h-8 w-full items-center gap-1.5 rounded-full bg-zinc-100 px-3.5 text-12 font-[440] text-foreground transition-colors duration-100 max-md:h-10 max-md:text-[14px] hover:bg-zinc-200/70 data-[state=open]:bg-zinc-200/70 dark:bg-white/[0.06] dark:hover:bg-white/[0.1] dark:data-[state=open]:bg-white/[0.1]`,`disabled:opacity-50`,P===`upscale`&&`bg-zinc-900 text-white hover:bg-zinc-800 focus:bg-zinc-800 focus:text-white dark:bg-white dark:text-black dark:hover:bg-zinc-200 dark:focus:bg-zinc-200 dark:focus:text-black`),children:[(0,Z.jsx)(Me,{className:N(`h-3.5 w-3.5 flex-shrink-0 text-zinc-500 dark:text-zinc-400`,P===`upscale`&&`text-current`),strokeWidth:1.6}),M?`Upscalingâ¦`:P===`upscale`?`Confirm`:`Upscale to 4K`,!M&&le!=null&&(0,Z.jsxs)(`span`,{className:N(`ml-auto text-[12px] font-[400] tabular-nums`,P===`upscale`?`text-current opacity-80`:`text-zinc-400 dark:text-zinc-500`),children:[ko(le),` credits`]})]})]})})]})]}),(0,Z.jsx)(`canvas`,{ref:me,className:`hidden`}),pe&&(0,Z.jsx)(Qc,{isOpen:ue,onClose:()=>de(!1),requiredCredits:pe.required,availableCredits:pe.available})]}),document.body):null}function Nl(e){let{item:t,onCreated:n,onStarted:r,onInsufficientCredits:i}=e,[a,o]=(0,X.useState)(null),[s,c]=(0,X.useState)(null),l=(0,X.useCallback)(async()=>{if(!t)throw Error(`No item`);let e=await fetch(J(t.url));if(!e.ok)throw Error(`Could not read this item`);let n=await e.blob(),r=(n.type.split(`/`)[1]||`png`).split(`+`)[0],i=(t.fileName||`image`).replace(/\.[^./\\]+$/,``)||`image`;return new File([n],`${i}.${r}`,{type:n.type||`image/png`})},[t]),u=(0,X.useCallback)(async(e,i,a)=>{if(!t)return;let{item:o}=await _r(e,{fileType:`image`,purpose:`general`,madeFrom:[t.itemId],edit:a,skipDuplicate:!1});i&&H(i,{duration:4e3}),await n?.({id:o.id,url:o.url??``,fileName:o.file_name??e.name,edit:a}),r?.()},[t,n,r]),d=(0,X.useCallback)(async()=>{if(!(!t||a)){o(`crop`);try{c(await l())}catch{H.error(`Could not open this item for cropping`,{duration:4e3})}finally{o(null)}}},[t,a,l]),f=(0,X.useCallback)(()=>c(null),[]),p=(0,X.useCallback)(async e=>{o(`crop`);try{await u(e,``,`crop`)}catch{H.error(`Could not save the crop`,{duration:4e3})}finally{o(null)}},[u]),m=(0,X.useCallback)(async e=>{await u(e,``,`frame`)},[u]),h=(0,X.useCallback)((e,t)=>{n&&pl(e).then(e=>n({id:e.itemId,url:e.url,fileName:t})).catch(()=>{})},[n]),g=(0,X.useCallback)((e,t)=>{e instanceof $c?i?.(e.required,e.available):H.error(t,{duration:4e3})},[i]);return{busy:a,cropFile:s,openCropper:d,closeCropper:f,applyCrop:p,keepFrame:m,removeBackground:(0,X.useCallback)(async()=>{if(!t||a)return!1;o(`background`);try{if(t.media===`video`)await ul(t.url);else{let e=await ll(t.url,t.itemId),n=(t.fileName||`image`).replace(/\.[^./\\]+$/,``)||`image`;h(e.generationId,`${n} (no background).png`)}return H(`Removing the background, check the feed`,{duration:3e3}),r?.(),!0}catch(e){return g(e,`Could not start background removal`),!1}finally{o(null)}},[t,a,h,g,r]),upscale:(0,X.useCallback)(async()=>
3{if(!t||a)return!1;let e=t.media===`video`?`video`:t.media===`image`?`image`:null;if(!e)return!1;o(`upscale`);try{let n=await cl({url:t.url,media:e,itemId:t.itemId});if(e===`image`){let e=(t.fileName||`image`).replace(/\.[^./\\]+$/,``)||`image`;h(n.generationId,`${e} 4K.png`)}return H(`Upscaling to 4K, check the feed`,{duration:3e3}),r?.(),!0}catch(e){return g(e,`Could not start the upscale`),!1}finally{o(null)}},[t,a,h,g,r])}}function Pl(e){if(!e)return``;let t=e.split(`?`)[0].split(`#`)[0].split(`.`);return t.length>1?t[t.length-1].toLowerCase():``}function Fl(e){if(!e)return!1;let t=[`mp4`,`webm`,`mov`,`avi`,`mkv`,`flv`,`wmv`,`m4v`],n=Pl(e);return t.includes(n)||e.includes(`/videos/`)}function Il(e,t){if(e.type===`voiceover`)return`voiceover`;if(e.type===`music`)return`music`;if(e.type===`sound_effect`||e.type===`sfx`)return`sound-effect`;if(e.type===`audio`)return`audio`;let n=e.metadata?.audioType;return n===`voiceover`?`voiceover`:n===`music`?`music`:n===`sound_effect`||n===`sfx`?`sound-effect`:e.metadata?.fileType===`video`||typeof e.metadata?.mimeType==`string`&&e.metadata.mimeType.startsWith(`video/`)||Fl(t??``)?`video`:`image`}var Ll=`Seedance 2.0 â multimodal references (images + videos + audio in one pass), native audio on by default, multi-shot via prose. 4 5Modes are exclusive (sourceImage and referenceImages never combine): 6- One image, one subject â frame mode: sourceImage (+ optional endImage). Combines with reference videos and audios â only reference images are excluded. 7- Multiple images (character + product, several subjects) â reference mode: everything as referenceImages (up to 9), each directed by its tag â [Image1], [Video1], [Audio1], numbered per type in input order; no implicit first/last frame role. Reference videos and audios: up to 3 each, total â¤15s per group. A reference video can also supply motion or style â the prompt combines its movement with the appearance carried by the image references. 8- Character holding or using a product: pass character and product as two referenceImages and combine them in the prompt â character as sourceImage with the product as a referenceImage is mode-mixing and rejected. 9 10Audio: native audio is the default â the model performs and voices dialogue itself. Put spoken words in double quotes for the strongest lip-sync (humans, animals, and characters alike), tagged [Speaker: name] (emotion): the emotion parenthetical drives facial expression, vocal tone, and body language at once; without it delivery goes flat. Works best in English, Chinese, Japanese, Korean, and Spanish; specify other languages inline. Describe ambient sound and SFX in the prompt or the generated audio is generic. Set generateAudio: false for silent video. Audio input is the rare exception, for two cases: keeping one voice consistent when the same character speaks as timeline voiceover and on camera (generate both lines from the same voice), and cutting motion to a music track. Pass the audio as a reference audio (requires at least one reference image or video as a visual anchor), describe what it is in the prompt prose, and keep generateAudio: true â false with audioInputs produces silent video. A reference audio is not a voice sample â the model reads its rhythm and energy and generates its own audio, so it will not speak new words in a supplied voice. To fix a voice, generate the line itself and pass that: the delivery is lip-synced to your audio rather than re-synthesised. Audio also makes the request reference-based, so it cannot ride with a start or end frame â pass the frame as a reference image instead. 11 12Multi-shot is the default way to prompt this model â internal cuts, shot-scale changes, and energy shifts inside one generation keep it alive. No shots parameter â write timestamped segments into the prompt. Up to 15s per generation; one 15s multi-shot holds lighting, identity, and environment better than chaining shorter generations. When shots need visually distinct framings, a grid storyboard can anchor them â pass the full-res first frame and the grid both as referenceImages, never a grid as sourceImage. To extend or edit an existing video, pass it as a referenceVideo and prompt what happens next, or describe the change while keeping the original motion. Subtitles can appear unsolicited â append "Generate video without subtitles." to suppress.`,Rl=[{id:`seedance-2.5`,name:`
12Seedance 2.5`,provider:`seedance`,mediaType:`video`,capabilities:{supportedTypes:[`text-to-video`,`image-to-video`,`ingredients-to-video`,`video-to-video`],aspectRatios:[`16:9`,`9:16`,`1:1`,`21:9`,`4:3`,`3:4`],resolutions:[`480p`,`720p`,`1080p`],durations:`4s.5s.6s.7s.8s.9s.10s.11s.12s.13s.14s.15s.16s.17s.18s.19s.20s.21s.22s.23s.24s.25s.26s.27s.28s.29s.30s`.split(`.`),maxVariations:1,hasSound:!0,supportsAudioToggle:!0,supportsAudioInput:!0,maxAudioInputs:10,audioInputsRequireVisualReference:!1,audioExcludesFrames:!0,supportsImageInput:!0,supportsEndFrame:!0,supportsReferenceImages:!0,maxReferenceImages:30,framesExcludeReferenceImages:!0,supportsReferenceVideos:!0,maxReferenceVideos:10,supportsVideoInput:!0,omniTaskTypes:[`reference`,`edit`,`extend`],supportsMultiShot:!0,multiShotFormat:`prose`,referenceTagFormat:`square-brackets`,maxInputVideoDuration:30,maxPromptLength:2500,defaultSettings:{aspectRatio:`16:9`,resolution:`720p`,duration:`5s`,variations:1,generateAudio:!0}},byteplusModel:`dreamina-seedance-2-5-260628`,description:`Long narrative (4-30s), 50 references, editing and extension, 11 languages, 1080p`,agentGuidance:`The long one. Thirty seconds in a single take, where the 2.0 family stops at fifteen, and up to 50 references at once: 30 images, 10 videos, 10 audio clips. It costs about half again what 2.0 does, so reach for it when the length, the reference count or the editing is the point, and stay on 2.0 when it is not. 13 14Four jobs, and the model decides which from the prompt. Say plainly what you want: 15- Reference to video: describe the shot, cite the assets. 16- EDIT an existing video: the words matter â "edit", "add", "remove", "replace", "change". The output keeps the source's ratio and length, so neither can be set, and the source must be 4-30s. 17- EXTEND an existing video: say "extend", "continue", or "continue the story". The output keeps the source's ratio. 18- First frame, or first and last: the output takes the first frame's shape. 19 20SAY WHICH ONE with the omniTaskType setting: edit, extend or reference. It is not decoration. Leave it off and the request goes up asking the model to guess, which forces the duration to the model choice and holds credits for the full thirty seconds however short the result turns out. Declare extend and you set the length yourself and pay for that length; declare edit and the hold matches the source clip. 21 22On the last three the aspect ratio is decided by the input and any value you set is refused, not ignored. On an edit the duration is too. 23 24Cite assets in the prompt the way the model expects: @Image1, @Video1, @Audio1, and say what each one is FOR â a face, a movement, a grade, a voice â and what to ignore in it. Sounds have their own marks: () music, <> effects, {} dialogue. 25 26Eleven languages natively, including the sung or spoken line. Name the language before the words. 27 281080p returns 10-bit H.265, which some players will not open. 720p is the safe delivery format.`,isAvailable:!0},{id:`seedance-2.0`,name:`Seedance 2.0`,provider:`seedance`,mediaType:`video`,capabilities:{supportedTypes:[`text-to-video`,`image-to-video`,`ingredients-to-video`,`video-to-video`],aspectRatios:[`16:9`,`9:16`,`1:1`,`21:9`,`4:3`,`3:4`],resolutions:[`480p`,`720p`,`1080p`,`4k`],durations:[`4s`,`5s`,`6s`,`7s`,`8s`,`9s`,`10s`,`11s`,`12s`,`13s`,`14s`,`15s`],maxVariations:1,hasSound:!0,supportsAudioToggle:!0,supportsAudioInput:!0,maxAudioInputs:3,audioInputsRequireVisualReference:!0,audioExcludesFrames:!0,supportsImageInput:!0,supportsEndFrame:!0,supportsReferenceImages:!0,maxReferenceImages:9,framesExcludeReferenceImages:!0,supportsReferenceVideos:!0,maxReferenceVideos:3,supportsVideoInput:!0,supportsMultiShot:!0,multiShotFormat:`prose`,referenceTagFormat:`square-brackets`,maxPromptLength:2500,defaultSettings:{aspectRatio:`16:9`,resolution:`720p`,duration:`5s`,variations:1,generateAudio:!0}},byteplusModel:`dreamina-seedance-2-0-260128`,description:`Multimodal reference (images + videos + audio), prose multi-shot, up to 4K (4-15s)`,agentGuidance:Ll,isAvailable:!0},{id:`seedance-2.0-fast`,name:`Seedance 2.0 Fast`,provider:`seedance`,mediaType:`video`,capabilities:{supportedTypes:[`text-to-vi
28deo`,`image-to-video`,`ingredients-to-video`,`video-to-video`],aspectRatios:[`16:9`,`9:16`,`1:1`,`21:9`,`4:3`,`3:4`],resolutions:[`480p`,`720p`],durations:[`4s`,`5s`,`6s`,`7s`,`8s`,`9s`,`10s`,`11s`,`12s`,`13s`,`14s`,`15s`],maxVariations:1,hasSound:!0,supportsAudioToggle:!0,supportsAudioInput:!0,maxAudioInputs:3,audioInputsRequireVisualReference:!0,audioExcludesFrames:!0,supportsImageInput:!0,supportsEndFrame:!0,supportsReferenceImages:!0,maxReferenceImages:9,framesExcludeReferenceImages:!0,supportsReferenceVideos:!0,maxReferenceVideos:3,supportsVideoInput:!0,supportsMultiShot:!0,multiShotFormat:`prose`,referenceTagFormat:`square-brackets`,maxPromptLength:2500,defaultSettings:{aspectRatio:`16:9`,resolution:`720p`,duration:`5s`,variations:1,generateAudio:!0}},byteplusModel:`dreamina-seedance-2-0-fast-260128`,description:`Lower-cost variant of Seedance 2.0 â same multimodal architecture, 720p (4-15s)`,agentGuidance:`Lower-cost variant of Seedance 2.0 â same architecture and rules, capped at 720p. 29 30`+Ll,isAvailable:!0},{id:`seedance-2.0-mini`,name:`Seedance 2.0 Mini`,provider:`seedance`,mediaType:`video`,capabilities:{supportedTypes:[`text-to-video`,`image-to-video`,`ingredients-to-video`,`video-to-video`],aspectRatios:[`16:9`,`9:16`,`1:1`,`21:9`,`4:3`,`3:4`],resolutions:[`480p`,`720p`],durations:[`4s`,`5s`,`6s`,`7s`,`8s`,`9s`,`10s`,`11s`,`12s`,`13s`,`14s`,`15s`],maxVariations:1,hasSound:!0,supportsAudioToggle:!0,supportsAudioInput:!0,maxAudioInputs:3,audioInputsRequireVisualReference:!0,audioExcludesFrames:!0,supportsImageInput:!0,supportsEndFrame:!0,supportsReferenceImages:!0,maxReferenceImages:9,framesExcludeReferenceImages:!0,supportsReferenceVideos:!0,maxReferenceVideos:3,supportsVideoInput:!0,supportsMultiShot:!0,multiShotFormat:`prose`,referenceTagFormat:`square-brackets`,maxPromptLength:2500,defaultSettings:{aspectRatio:`16:9`,resolution:`720p`,duration:`5s`,variations:1,generateAudio:!0}},byteplusModel:`dreamina-seedance-2-0-mini-260615`,description:`Lowest-cost Seedance 2.0 variant â same multimodal architecture, 480p/720p (4-15s)`,agentGuidance:`Lowest-cost variant of Seedance 2.0 â same architecture and rules, capped at 720p. 31 32`+Ll,isAvailable:!0},{id:`google-veo-3.1`,name:`Google Veo 3.1`,provider:`google`,mediaType:`video`,capabilities:{supportedTypes:[`text-to-video`,`image-to-video`],aspectRatios:[`16:9`,`9:16`],resolutions:[`720p`,`1080p`],durations:[`4s`,`6s`,`8s`],maxVariations:1,hasSound:!0,supportsAudioToggle:!0,supportsNegativePrompt:!0,supportsImageInput:!0,supportsEndFrame:!0,maxPromptLength:5e3,defaultSettings:{aspectRatio:`16:9`,resolution:`1080p`,duration:`4s`,variations:1,generateAudio:!0}},replicateModel:`google/veo-3.1`,replicateVersion:`latest`,vertexModel:`veo-3.1-generate-001`,description:`Audio, end frame, 1080p (4s, 6s, 8s)`,agentGuidance:`Image-to-video: pass a source image for subject consistency. Native audio co-generates voice and visuals â natural lip-sync but voice varies per generation, unreliable for cross-scene voice consistency. End frame: provide sourceImage (start) + endImage (end) for controlled transitions. No multi-shot â direct momentum by segmenting the prompt by time, so the shot moves through successive actions and camera moves instead of holding one pose.`,isAvailable:!0},{id:`google-veo-3.1-fast`,name:`Google Veo 3.1 Fast`,provider:`google`,mediaType:`video`,capabilities:{supportedTypes:[`text-to-video`,`image-to-video`],aspectRatios:[`16:9`,`9:16`],resolutions:[`720p`,`1080p`],durations:[`4s`,`6s`,`8s`],maxVariations:1,hasSound:!0,supportsAudioToggle:!0,supportsNegativePrompt:!0,supportsImageInput:!0,supportsEndFrame:!0,maxPromptLength:5e3,defaultSettings:{aspectRatio:`16:9`,resolution:`1080p`,duration:`4s`,variations:1,generateAudio:!0}},replicateModel:`google/veo-3.1-fast`,vertexModel:`veo-3.1-fast-generate-001`,description:`Fast with audio (4s, 6s, 8s)`,agentGuidance:`Supports image-to-video: pass a product photo or start frame as sourceImage to keep the subject consistent across shots. Native audio co-generates voice and visuals. End frame supported. No multi-reference-image support. No multi-shot â direct momentum by segmenting the prompt by time, so the shot moves through successive actions and camera moves instead of holding one pose.`,isAvailable:!0}
32,{id:`seedance-1.5-pro`,name:`Seedance 1.5 Pro`,provider:`seedance`,mediaType:`video`,capabilities:{supportedTypes:[`text-to-video`,`image-to-video`],aspectRatios:[`16:9`,`9:16`,`21:9`,`1:1`,`4:3`,`3:4`],resolutions:[`480p`,`720p`,`1080p`],durations:[`4s`,`5s`,`6s`,`7s`,`8s`,`9s`,`10s`,`11s`,`12s`],maxVariations:1,hasSound:!0,supportsAudioToggle:!0,supportsImageInput:!0,supportsEndFrame:!0,supportsCameraFixed:!0,maxPromptLength:2500,defaultSettings:{aspectRatio:`16:9`,resolution:`720p`,duration:`4s`,variations:1,generateAudio:!0,cameraFixed:!1}},replicateModel:`bytedance/seedance-1.5-pro`,description:`Flexible duration with optional audio (4-12s)`,isAvailable:!0},{id:`minimax-h3`,name:`MiniMax H3`,provider:`minimax`,mediaType:`video`,capabilities:{supportedTypes:[`text-to-video`,`image-to-video`,`ingredients-to-video`],aspectRatios:[`16:9`,`9:16`,`1:1`,`4:3`,`3:4`,`21:9`],resolutions:[`768p`,`2k`],durations:[`4s`,`5s`,`6s`,`7s`,`8s`,`9s`,`10s`,`11s`,`12s`,`13s`,`14s`,`15s`],maxVariations:1,hasSound:!1,supportsAudioInput:!0,maxAudioInputs:3,supportsImageInput:!0,supportsEndFrame:!0,supportsReferenceImages:!0,maxReferenceImages:9,framesExcludeReferenceImages:!0,supportsReferenceVideos:!0,maxReferenceVideos:3,maxPromptLength:2e3,defaultSettings:{aspectRatio:`16:9`,resolution:`768p`,duration:`5s`,variations:1}},replicateModel:`minimax/h3`,description:`Multimodal references (images + videos + audio), 768p or 2K (4-15s)`,agentGuidance:`The cheap quality tier: 2K costs less per second than most models charge for 720p, so it is the one to reach for when a shot has to look good and the budget is real. 33 34Slow. A four-second clip took 93 to 136 seconds to generate, around 25x realtime, and 2K is slower still. It runs in the background like every generation, but do not pick it when somebody is waiting on a quick look â pick it when the shot matters. 35 36Inputs: a first frame, a last frame, or both, to pin where a shot starts and ends, or up to 9 reference images instead of frames. Up to 3 reference videos and 3 reference audio clips ride with either and guide motion, camera, style, voice and cutting rhythm. Reference audio steers delivery; it is not a soundtrack you supply. 37 38Aspect ratio is required for text-to-video and ignored for image-to-video, where the frame decides the shape.`,isAvailable:!0},{id:`wan-2.7`,name:`Wan 2.7`,provider:`wan`,mediaType:`video`,capabilities:{supportedTypes:[`text-to-video`,`image-to-video`,`ingredients-to-video`],aspectRatios:[`16:9`,`9:16`,`1:1`,`4:3`,`3:4`],resolutions:[`720p`,`1080p`],durations:[`2s`,`3s`,`4s`,`5s`,`6s`,`7s`,`8s`,`9s`,`10s`,`11s`,`12s`,`13s`,`14s`,`15s`],durationsByType:{"ingredients-to-video":[`2s`,`3s`,`4s`,`5s`,`6s`,`7s`,`8s`,`9s`,`10s`]},maxVariations:1,hasSound:!0,supportsAudioInput:!0,maxAudioInputs:1,audioExcludesReferences:!0,referencesOnlyOnType:`ingredients-to-video`,supportsNegativePrompt:!0,supportsImageInput:!0,supportsEndFrame:!0,supportsReferenceImages:!0,maxReferenceImages:4,supportsReferenceVideos:!0,maxReferenceVideos:2,maxPromptLength:1500,maxNegativePromptLength:500,defaultSettings:{aspectRatio:`16:9`,resolution:`720p`,duration:`5s`,variations:1}},replicateModel:`wan-video/wan-2.7-t2v`,replicateModelByType:{"image-to-video":`wan-video/wan-2.7-i2v`,"ingredients-to-video":`wan-video/wan-2.7-r2v`},description:`End frame, refs, neg prompt, 720p/1080p (2-15s)`,agentGuidance:`Durations: any whole second, 2 to 15 â not tiered; pick what the shot needs. Reference-to-video stops at 10s. 39 40Text-to-video takes an aspect ratio (16:9, 9:16, 1:1, 4:3, 3:4). Image-to-video takes none â the start frame decides the shape, so crop the frame to the frame you want. 41 42End frame (endImage) works on image-to-video and needs a start frame alongside it; the model interpolates between the two. Reference images or videos instead route to reference-to-video, which holds a character, product or object identity across generations while the prompt directs the action â describe what happens, not what the subject looks like, since the references already carry that. 43 44Audio is generated to match and cannot be turned off. Supplying an audio file (3-30s) syncs the video to it instead, on text-to-vi
44deo and image-to-video. 45 46Negative prompt excludes unwanted elements; "blurry, distorted, low quality, static" is the provider's own suggestion for artifacts. Motion degrades and scenes drift past about 10s, and in-video text rendering is unreliable â keep lettering out of the prompt and add it in the timeline.`,isAvailable:!0},{id:`kling-3.0`,name:`Kling 3.0`,provider:`kling`,mediaType:`video`,capabilities:{supportedTypes:[`image-to-video`],aspectRatios:[`16:9`,`9:16`,`1:1`],resolutions:[`720p`,`1080p`,`4k`],durations:[`3s`,`4s`,`5s`,`6s`,`7s`,`8s`,`9s`,`10s`,`11s`,`12s`,`13s`,`14s`,`15s`],maxVariations:1,hasSound:!0,supportsAudioToggle:!0,supportsNegativePrompt:!0,supportsImageInput:!0,supportsEndFrame:!0,supportsMultiShot:!0,multiShotFormat:`structured`,maxShotCount:6,multiShotExcludesEndFrame:!0,maxPromptLength:2500,maxNegativePromptLength:2500,defaultSettings:{aspectRatio:`16:9`,resolution:`720p`,duration:`5s`,variations:1,generateAudio:!0}},replicateModel:`kwaivgi/kling-v3-video`,falModel:`fal-ai/kling-video/v3/pro`,falModelByType:{"image-to-video":`fal-ai/kling-video/v3/pro/image-to-video`},description:`Audio, neg prompt, multi-shot, end frame (3-15s)`,agentGuidance:`Combines start frame (sourceImage) + end frame (endImage) + audio in a single call. End frame and multi-shot cannot be used together â anchor the landing with endImage (single continuous prompt), or direct shot-by-shot with multi-shot (no endImage). No reference images or video inputs. Durations: any whole integer from 3 to 15 seconds â not tiered to 5s/10s; pick the exact duration the scene needs. Multi-shot is the default way to prompt this model â internal cuts, shot-scale changes, and energy shifts inside one generation keep it alive. Rules: up to 6 shots per generation, min 1s each, whole seconds only (no decimals), per-shot direction max 512 characters, and shot durations must sum exactly to the top-level duration. Supports negative prompt to exclude unwanted elements (watermarks, text, distortion). Audio prompting: put spoken dialogue in quotation marks; describe ambient sounds and SFX directly in the prompt. For multi-character scenes, use speaker tags: [Speaker: Name] (emotion): "dialogue" â the emotion parenthetical drives facial expression and vocal tone simultaneously. Native audio works best in English and Chinese. Lip sync tends to degrade after ~10s â when a character is delivering a key line, plan to land it inside one short scene (4-8s) rather than stretching across a long generation. Front-load the important word in each line â the first second of a generation is the most reliable for sync. Complex prompts may cause morphing on longer durations â simpler direction helps on 10s+ scenes. Strong at facial expressions and emotions.`,isAvailable:!0},{id:`kling-3.0-omni`,name:`Kling 3.0 Omni`,provider:`kling`,mediaType:`video`,capabilities:{supportedTypes:[`image-to-video`,`video-to-video`,`ingredients-to-video`],aspectRatios:[`16:9`,`9:16`,`1:1`],resolutions:[`720p`,`1080p`,`4k`],durations:[`3s`,`4s`,`5s`,`6s`,`7s`,`8s`,`9s`,`10s`,`11s`,`12s`,`13s`,`14s`,`15s`],maxVariations:1,hasSound:!0,supportsAudioToggle:!0,supportsNegativePrompt:!1,supportsImageInput:!0,supportsEndFrame:!0,supportsMultiShot:!0,multiShotFormat:`structured`,maxShotCount:6,multiShotExcludesEndFrame:!0,audioExcludesReferenceVideo:!0,referenceTagFormat:`angle-brackets`,supportsReferenceImages:!0,maxReferenceImages:7,supportsReferenceVideos:!0,maxReferenceVideos:1,supportsVideoInput:!0,maxInputVideoDuration:9,maxPromptLength:2500,defaultSettings:{aspectRatio:`16:9`,resolution:`720p`,duration:`5s`,variations:1,generateAudio:!0}},replicateModel:`kwaivgi/kling-v3-omni-video`,falModel:`fal-ai/kling-video/o3/pro`,falModelByType:{"image-to-video":`fal-ai/kling-video/o3/pro/image-to-video`,"video-to-video":`fal-ai/kling-video/o3/pro/video-to-video/edit`,"ingredients-to-video":`fal-ai/kling-video/o3/pro/reference-to-video`},description:`Audio, ref images/video, V2V, multi-shot, end frame (3-15s)`,agentGuidance:`Durations: any whole integer from 3 to 15 seconds â not tiered to 5s/10s; pick the exact duration the scene needs. Combines start frame (sourceImage) + end frame (endImage) + reference images (up to 7) + audio in a single call. End frame and multi-shot cannot be used together â anchor the landing with endImage (single continuous prompt), or direct shot-by-shot with multi-shot (no endImage). 47 48Multi-shot is the default way to prompt this model â internal
48cuts, shot-scale changes, and energy shifts inside one generation keep it alive. Rules: up to 6 shots per generation, min 1s each, whole seconds only, per-shot direction max 512 characters, and shot durations must sum exactly to the top-level duration. Reference tags â <<<image_1>>>, <<<image_2>>> â work in the prompt and inside shot directions; different references in different shots. When shots need visually distinct framings, a grid storyboard can anchor them â first frame as sourceImage, grid in referenceImages; never a grid as sourceImage. 49 50Video reference: referenceVideos for style/camera reference (feature mode), sourceVideo for video editing/V2V (base mode). Input video 3-9s, max 200MB. With a video reference the reference-image cap drops from 7 to 4. Audio is mutually exclusive with any video reference. 51 52Audio: put spoken dialogue in quotation marks; describe ambient sounds and SFX directly in the prompt. Multi-character scenes use speaker tags â [Speaker: Name] (emotion): the emotion parenthetical drives facial expression and vocal tone at once. Native audio works best in English and Chinese. Lip sync degrades after ~10s â land a key line inside one short shot (4-8s) rather than stretching it, and front-load the important word: the first second is the most reliable for sync. 53 54Complex prompts can morph on longer durations â simpler direction helps on 10s+ scenes. Strong at facial expressions and emotions.`,isAvailable:!0},{id:`kling-3.0-motion-control`,name:`Kling 3.0 Motion Control`,provider:`kling`,mediaType:`video`,capabilities:{supportedTypes:[`video-to-video`],aspectRatios:[],resolutions:[`720p`,`1080p`],durations:[],inputBasedDuration:!0,maxVariations:1,hasSound:!0,supportsAudioToggle:!0,supportsImageInput:!0,requiresImageInput:!0,supportsVideoInput:!0,requiresVideoInput:!0,maxInputVideoDuration:30,characterOrientations:[`image`,`video`],maxInputVideoDurationByOrientation:{image:10,video:30},maxPromptLength:2500,supportsNegativePrompt:!1,defaultSettings:{aspectRatio:`16:9`,resolution:`1080p`,characterOrientation:`image`,variations:1,generateAudio:!0}},replicateModel:`kwaivgi/kling-v3-motion-control`,description:`Transfers motion from a video onto a character image (3-30s)`,agentGuidance:`Takes two inputs and needs both: a character image (sourceImage) for who appears, and a driving video (sourceVideo) for how they move. The output is as long as the driving video, so duration is not a setting and the cost follows the clip you supply â a 30s reference costs six times a 5s one. 55 56Facing is a real choice, not a detail. 'From image' keeps the character oriented as in the still and leaves the camera to you â zoom in, zoom out, camera up, camera down or fixed, directed in the prompt â which suits portrait and character-led shots, and caps output at 10s. 'From video' takes orientation and camera movement from the footage, handles complex choreography and full-body performance, and allows the full 30s. When the character's pose in the still differs a lot from the reference, 'from video' maps the skeleton more accurately. Driving video 3-30s, max 100MB. Character image max 10MB, 340-3850px, aspect ratio between 1:2.5 and 2.5:1. Keep the framing of the two consistent: a half-body image against a full-body reference video transfers badly. 57 58The reference video's own audio is kept by default; turn audio off to drop it. The prompt is optional and only adds elements or effects on top of the transfer â the motion comes from the video, not from the words. 59 60Best on clear, steady movement; very fast or chaotic motion degrades. The character's whole body and head should be visible and unobstructed in the image.`,isAvailable:!0},{id:`gemini-omni-flash`,name:`Gemini Omni 1.1 Flash`,provider:`google`,mediaType:`video`,capabilities:{supportedTypes:[`text-to-video`,`image-to-video`,`ingredients-to-video`,`video-to-video`],aspectRatios:[`16:9`,`9:16`],aspectRatiosByType:{"image-to-video":[],"video-to-video":[]},resolutions:[`360p`,`720p`,`1080p`,`4k`],durations:[`3s`,`4s`,`5s`,`6s`,`7s`,`8s`,`9s`,`10s`],maxVariations:1,hasSound:!0,supportsImageInput:!0,supportsEndFrame:!0,supportsReferenceImages:!0,maxReferenceImages:10,supportsVideoInput:!0,maxInputVideoDuration:10,billsInputVideoSeconds:!0,omniTaskTypes:[`edit`,`extend`],supportsEditPoints:!0,supportsNegativePrompt:!1,maxPromptLength:5e3,defaultSettings:{aspectRatio:`16:9`,resolution:`720p`,duration:`5s`,variations:1}},omniModel:`gemini-omni-1.1-flash`,description:`Any-to-video with audio: edits, extensions, first and last frame, up to 4K (3-10s)`,agentGuidance:`One model, five jobs: text-to-vi
60deo, image-to-video (a first frame, optionally a last frame), reference-to-video (up to 10 images, optionally a clip beside them), and on an existing clip up to 10s, edit or extend. A prompt is required on every job, even an edit. 61 62On video-to-video set omniTaskType. Edit changes what you name and keeps everything else, and the output keeps the source's length and shape, so duration and aspect ratio are not sent. Extend continues the clip for the duration you set and keeps its shape. 63 64Image-to-video, edit and extend take their shape from the input; text and reference modes accept 16:9 or 9:16. 65 66720p is native. 360p is a cheap draft at about a third of the price; 1080p costs 1.5 times as much and 4K three times, both upscaled. Audio comes with the picture. Inputs are billed too, so trim a source clip to what the shot needs.`,isAvailable:!0},{id:`ltx-2.5-fast`,name:`LTX 2.5 Fast`,provider:`lightricks`,mediaType:`video`,capabilities:{supportedTypes:[`text-to-video`,`image-to-video`],aspectRatios:[`16:9`,`9:16`],resolutions:[`720p`,`1080p`,`2k`,`4k`],durations:[`2s`,`3s`,`4s`,`5s`,`6s`,`8s`,`10s`,`12s`,`14s`,`16s`,`18s`,`20s`],maxVariations:1,hasSound:!0,supportsAudioToggle:!0,supportsImageInput:!0,supportsEndFrame:!0,maxPromptLength:5e3,defaultSettings:{aspectRatio:`16:9`,resolution:`1080p`,duration:`6s`,variations:1,generateAudio:!1}},replicateModel:`lightricks/ltx-2.5-fast`,description:`Cheapest route to 2K and 4K, synchronized audio, end frame (2-20s)`,agentGuidance:`The high-resolution lane, and by a wide margin the cheapest one: 4K here costs about a third of what Seedance charges, and 1080p with audio is half of Seedance 1.5 Pro. It is also quick â a clip generates in well under a minute. 67 68Past 10 seconds it must be 720p or 1080p; 2K and 4K stop at 10. Ask for 20 seconds at 4K and the request is refused rather than trimmed. 69 70Only 16:9 and 9:16, so anything square or portrait-but-not-9:16 belongs on another model. No references, no video-to-video, no multi-shot. 71 72Camera direction goes in the prompt as words rather than a setting â name the move and the model follows it. Segment the prompt by time to carry momentum through successive actions instead of holding one pose. 73 74End frame: sourceImage starts the clip, endImage ends it, and the model interpolates between them.`,isAvailable:!0},{id:`grok-imagine-video-1.5`,name:`Grok Imagine Video 1.5`,provider:`xai`,mediaType:`video`,capabilities:{supportedTypes:[`image-to-video`],aspectRatios:[`16:9`,`9:16`,`1:1`,`4:3`,`3:4`,`3:2`,`2:3`],resolutions:[`480p`,`720p`],durations:[`1s`,`2s`,`3s`,`4s`,`5s`,`6s`,`7s`,`8s`,`9s`,`10s`,`11s`,`12s`,`13s`,`14s`,`15s`],maxVariations:1,hasSound:!0,supportsImageInput:!0,requiresImageInput:!0,supportsNegativePrompt:!1,maxPromptLength:5e3,defaultSettings:{aspectRatio:`16:9`,resolution:`720p`,duration:`5s`,variations:1}},replicateModel:`xai/grok-imagine-video-1.5`,description:`Animates a still, native audio, 480p/720p (1-15s)`,agentGuidance:`Image-to-video only â every generation needs a source image, and the cheapest way to use it is to generate the still first on an image model and animate that. 75 76Prompt the motion, not the picture. The model already sees the image, so describing what is in it wastes the prompt and contradicting it (writing a woman when the image shows a man) degrades the result. Name one subject, one action, one camera move: pan, tilt, dolly, orbit, tracking, handheld, slow push-in, static. Intensity words carry real weight â "racing past at high speed" moves more than "passing". Anchor the subject by a visible feature ("the woman in the red jacket") when the frame holds more than one. 77 78Audio generates alongside and cannot be turned off; mention music, sound effects, ambience or a short line of dialogue in the prompt to steer it, optionally under a closing AUDIO: section. 79 80Negative prompts are ignored entirely â state the desired result instead. Aspect ratio is sent explicitly and reframes the source, so set it to the source image's own shape unless the reframe is the point. 5-8s is the stable range, 15s runs but artifacts more.`,isAvailable:!0}],zl={supportedTypes:[`text-to-image`,`image-to-image`,`ingredients-to-image`],aspectRatios:[`16:9`,`9:16`,`1:1`,`4:3`,`3:4`,`3:2`,`2:3`,`4:5`,`5:4`,`21:9`,`9:21`],imageResolutions:[`1K`,`2K`,`4K`],imageQualities:[`low`,`medium`,`high`,`xhigh`,`max`],backgrounds:[`auto`,`opaque`,`transparent`],maxVariations:1,maxReferenceImages:16,supportsNegativePrompt:!1,supportsImageInput:!0,supportsMask:!0,supportsEditPoints:!0,maxPromptLength:32e3,defaultSettings:{aspectRatio:`16:9`,imageResolution:`2K`,imageQuality:`high`,background:`auto`,variations:1}},Bl=`Quality sets rendering effort and cost: low for drafts, medium for most images, high for small or dense text, diagrams and slides. Reach for xhigh or max only when high falls short; a higher level does not improve every prompt. OpenAI treats 2K square and all of 4K as experimental. 81 82For a transparent background set background "transparent" and also ask in the prompt for an isolated subject with no backdrop, shadow or checkerboard. 83 84Name the deliverable and its use, then subject, composition, style and constraints. For literal text, put the exact copy in double quotes, say where it sits and that it appears once. For edits, say to change only the one thing and list what must stay: identity, geometry, layout, lighting, labels. Number each reference image and give it a role. Refine one change at a time by passing the last output back in, restating what must not drift. A place and a date resolve a period scene without spelling it out.`,Vl=[{id:`google-nano-banana-pro`,name:`Google Nano Banana Pro`,provider:`google`,mediaType:`image`,capabilities:{supportedTypes:[`text-to-image`,`image-to-image`,`ingredients-to-image`],aspectRatios:[`16:9`,`9:16`,`21:9`,`1:1`,`4:3`,`3:4`,`3:2`,`2:3`,`4:5`,`5:4`],imageResolutions:[`2K`,`4K`],maxVariations:1,maxReferenceImages:5,supportsNegativePrompt:!1,supportsImageInput:!0,maxPromptLength:5e3,defaultSettings:{aspectRatio:`16:9`,imageResolution:`2K`,variations:1}},replicateModel:`google/nano-banana-pro`,geminiModel:`gemini-3-pro-image`,de
84scription:`2K resolution, ref images (max 5). Handles multi-panel compositions (grids, multi-view sheets, sequence images).`,agentGuidance:`When generating people, prefer passing a character reference image over detailed text descriptions of appearance â models handle visual references better than written physical descriptions, and it avoids safety filter triggers. Renders UI screens inside devices (phones, laptops, monitors, billboards) â pass the UI screenshot as a reference image and describe the device and scene context.`,isAvailable:!0},{id:`google-nano-banana-2`,name:`Google Nano Banana 2`,provider:`google`,mediaType:`image`,capabilities:{supportedTypes:[`text-to-image`,`image-to-image`,`ingredients-to-image`],aspectRatios:[`16:9`,`9:16`,`21:9`,`1:1`,`4:3`,`3:4`,`3:2`,`2:3`,`4:5`,`5:4`],imageResolutions:[`2K`,`4K`],maxVariations:1,maxReferenceImages:14,supportsNegativePrompt:!1,supportsImageInput:!0,maxPromptLength:5e3,defaultSettings:{aspectRatio:`16:9`,imageResolution:`2K`,variations:1}},replicateModel:`google/nano-banana-2`,geminiModel:`gemini-3.1-flash-image`,description:`2K resolution, ref images (max 14). Improved text rendering, multilingual support. Fast generation with Pro-level quality.`,agentGuidance:`Renders UI screens inside devices (phones, laptops, monitors, billboards) â pass the UI screenshot as a reference image and describe the device and scene context.`,isAvailable:!0},{id:`gpt-image-2.5-sunburst`,name:`GPT Image 2.5 Sunburst`,provider:`openai`,mediaType:`image`,capabilities:zl,openaiModel:`gpt-image-2.5-sunburst`,tokenPriced:!0,description:`OpenAI base image model. Highest quality and the most precise edits, slower than Flare. 1K/2K/4K, five quality levels, transparent backgrounds. Ref images (max 16).`,agentGuidance:`Sunburst is for work that has to land on quality, and for edits that must keep a subject exact. Flare renders faster at quality comparable to GPT Image 2. Both bill the same token rates, and the same quality level does not give the same result on the two.\n\n${Bl}`,isAvailable:!0},{id:`gpt-image-2.5-flare`,name:`GPT Image 2.5 Flare`,provider:`openai`,mediaType:`image`,capabilities:zl,openaiModel:`gpt-image-2.5-flare`,tokenPriced:!0,description:`OpenAI fast image model. Quality comparable to GPT Image 2 at lower latency, with more precise edits. 1K/2K/4K, five quality levels, transparent backgrounds. Ref images (max 16).`,agentGuidance:`Flare is the fast choice for everyday images at quality comparable to GPT Image 2. Sunburst renders slower at higher quality and holds edits more tightly. Both bill the same token rates, and the same quality level does not give the same result on the two.\n\n${Bl}`,isAvailable:!0},{id:`gpt-image-2`,name:`GPT Image 2`,provider:`openai`,mediaType:`image`,capabilities:{...zl,imageQualities:[`low`,`medium`,`high`],defaultSettings:{aspectRatio:`3:2`,imageResolution:`1K`,imageQuality:`high`,background:`auto`,variations:1}},openaiModel:`gpt-image-2`,tokenPriced:!0,description:`OpenAI image model. Strong instruction following, sharp text rendering, precise editing. 1K/2K/4K, three quality levels, transparent backgrounds. Ref images (max 16).`,agentGuidance:`Superseded by GPT Image 2.5: Flare matches its quality faster, Sunburst exceeds it. Quality sets rendering effort and cost: low for drafts, medium for most images, high for small or dense text. OpenAI treats 2K square and all of 4K as experimental, and transparent backgrounds as a preview. Strong cultural and world reasoning â a place and a date often resolve a scene without spelling it out. For photoreal output use photo language â lens, lighting quality, framing â not generic quality words. For literal text in the image, put the exact copy in double quotes and describe the typography. For edits, explicitly lock what must not change. For multi-image references, state each image's role in the prompt.`,isAvailable:!0},{id:`seedream-5`,name:`Seedream 5.0 Lite`,provider:`bytedance`,mediaType:`image`,capabilities:{supportedTypes:[`text-to-image`,`image-to-image`,`ingredients-to-image`],aspectRatios:[`16:9`,`9:16`,`21:9`,`1:1`,`4:3`,`3:4`,`3:2`,`2:3`],imageResolutions:[`2K`,`3K`],maxVariations:1,maxReferenceImages:14,maxPromptLength:3e3,
84supportsNegativePrompt:!1,defaultSettings:{aspectRatio:`16:9`,imageResolution:`2K`,variations:1}},replicateModel:`bytedance/seedream-5-lite`,description:`2K/3K resolution, ref images (max 14).`,agentGuidance:`Seedream 5 reads photographic vocabulary as real direction, not flavor words â film stocks, lens characteristics, lighting setups, named photographer or director references. Quality anchors ("8k", "extreme sharpness", "large format", "HDR look", named photographers) push it to its top tier â skip them for UGC character images, where they push faces into editorial polish; phone-camera realism markers (skin texture, subsurface scattering, hair strands, fabric texture) carry those instead. 85 86Defaults to Asian appearance when ethnicity is unspecified. For any non-Asian brief, state the target ethnicity or nationality explicitly and cast to the deliverable's audience â the model handles every ethnicity well but needs the cue. 87 88Prompting: 89- Natural language over keyword lists; state the use case, not just the visuals. 90- Text rendering: wrap the exact words in double quotes â quoted strings render literally. Multi-typeface layouts, mixed case, punctuation, and multilingual scripts hold up. 91- Editing: state what must not change â without an explicit keep-list, unrelated regions drift. 92- Visual markers in input images work â arrows, boxes, colored regions referenced by color in the prompt, with an instruction to remove the markers. 93- Example-based editing: pass a before/after pair plus a target image and direct applying the same operation to the target â for transformations hard to put into words (material swaps, style transfers, color grades). 94- Reasoning prompts work: the model can sort, classify, and arrange across reference images in a single instruction â lean on this for multi-step composition rather than chaining edits. 95- Multi-image series: a storyboard grid, a set of four, a brand flat-lay â character and style continuity holds across panels in one generation. 96- Renders UI screens well inside devices â pass the UI screenshot as a reference image and describe the device and scene context. 97 98Grid storyboards for video (two-step): generate the standalone first frame at full resolution with all relevant references, then generate the grid with that frame as its primary reference â panel 1 repeats the frame, the remaining panels build the arc forward. Two steps because each panel gets only a fraction of the pixels and a grid generated without the frame as reference drifts. Size by panel count â 2â4 panels: 2Ã2, 5â9: 3Ã3, 10â16: 4Ã4 â so every cell keeps the destination video's aspect ratio. Prompt in three parts: the grid instruction first (aspect ratio, columns à rows, all panels equal size), then the per-panel content, then a closing reinforcement of the strict grid.`,isAvailable:!0},{id:`seedream-5-pro`,name:`Seedream 5.0 Pro`,provider:`bytedance`,mediaType:`image`,capabilities:{supportedTypes:[`text-to-image`,`image-to-image`,`ingredients-to-image`],aspectRatios:[`16:9`,`9:16`,`21:9`,`1:1`,`4:3`,`3:4`,`3:2`,`2:3`],imageResolutions:[`1K`,`2K`],maxVariations:1,maxReferenceImages:10,maxPromptLength:4e3,supportsNegativePrompt:!1,defaultSettings:{aspectRatio:`16:9`,imageResolution:`2K`,variations:1}},replicateModel:`bytedance/seedream-5-pro`,description:`1K/2K resolution, ref images (max 10). ByteDance flagship.`,agentGuidance:`The flagship Seedream â reach for it over Lite when a single image has to land: character and product consistency across a set, multi-reference composition, and fine detail hold up better. Lite is the cheaper choice for iteration and for anything needing more than one image per call, and Lite alone reaches 3K. 99 100Up to 10 reference images guide character, product or style. With references present and no aspect ratio set, the output takes the shape of the first reference â pass an explicit aspect ratio when the deliverable has a fixed frame. 101 102The prompting that works on Lite works here: photographic vocabulary as real direction (film stocks, lens characteristics, lighting setups, named photographers), quoted strings for literal text rendering, and an explicit keep-list when editing so unrelated regi
102ons do not drift. It defaults to Asian appearance when ethnicity is unspecified â state the target explicitly for any other brief. Prompts run to 4000 characters, though ByteDance recommends staying under about 600 English words.`,isAvailable:!0},{id:`flux-2-max`,name:`Flux 2 Max`,provider:`flux`,mediaType:`image`,capabilities:{supportedTypes:[`text-to-image`,`image-to-image`,`ingredients-to-image`],aspectRatios:[`16:9`,`9:16`,`1:1`,`4:3`,`3:4`,`3:2`,`2:3`,`4:5`,`5:4`],maxVariations:1,maxReferenceImages:3,supportsNegativePrompt:!1,supportsImageInput:!0,maxPromptLength:5e3,defaultSettings:{aspectRatio:`16:9`,variations:1}},replicateModel:`black-forest-labs/flux-2-max`,description:`2MP resolution, ref images (max 3)`,agentGuidance:`No 21:9 support.`,isAvailable:!0},{id:`grok-imagine-image`,name:`Grok Imagine Image`,provider:`xai`,mediaType:`image`,capabilities:{supportedTypes:[`text-to-image`,`image-to-image`],aspectRatios:[`16:9`,`9:16`,`1:1`,`4:3`,`3:4`,`3:2`,`2:3`],maxVariations:1,maxReferenceImages:1,maxPromptLength:8e3,supportsNegativePrompt:!1,supportsImageInput:!0,defaultSettings:{aspectRatio:`16:9`,variations:1}},replicateModel:`xai/grok-imagine-image`,description:`Fastest and cheapest, strong text rendering, ref image (max 1)`,agentGuidance:`The cheapest and fastest image model here â around four seconds a generation. Reach for it to iterate on composition, to fill a board with options, or when the shot is a background rather than the hero. Step up to a stronger model once the direction is settled. 103 104Text rendering is its standout: legible typography inside the image, which most models cannot do. Say where the words sit and what they read. It also leans naturally toward moody, cinematic looks â subdued palettes, dramatic contrast, retro anime and cyberpunk â so a bright commercial style needs to be asked for directly. 105 106Editing takes one source image and a description of the change; the aspect ratio is ignored entirely in that mode and the source shape is kept, so reframing has to happen elsewhere.`,isAvailable:!0},{id:`flux-2-pro`,name:`Flux 2 Pro`,provider:`flux`,mediaType:`image`,capabilities:{supportedTypes:[`text-to-image`,`image-to-image`,`ingredients-to-image`],aspectRatios:[`16:9`,`9:16`,`1:1`,`4:3`,`3:4`,`3:2`,`2:3`,`4:5`,`5:4`],maxVariations:1,maxReferenceImages:3,supportsNegativePrompt:!1,supportsImageInput:!0,maxPromptLength:5e3,defaultSettings:{aspectRatio:`16:9`,variations:1}},replicateModel:`black-forest-labs/flux-2-pro`,description:`2MP resolution, ref images (max 3)`,agentGuidance:`The mainstream Flux 2 tier â half Max's per-megapixel rate for the same schema, so reach for it first and keep Max for work where fidelity has to be the deciding factor. Strong at legible text (typography, infographics, UI mockups), photorealistic texture and lighting, and holding a character or product consistent across a series through reference images. 107 108No 21:9, and no negative prompts â naming what you want excluded tends to summon it. Describe the desired state instead: "clean background, hands at rest out of frame" rather than "no clutter, no extra fingers". 109 110A prompt can be structured as JSON with scene, subjects, style, lighting, camera and color_palette fields, each taking plain English â useful when composition needs precise control. Hex codes in the prompt hold for brand color accuracy. With multiple references, cite them by index to say which element comes from where.`,isAvailable:!0}],Hl=new class{constructor(){this.models=new Map,this.initializeModels()}initializeModels(){[...Rl,...Vl].forEach(e=>{this.registerModel(e)})}registerModel(e){this.models.set(e.id,e)}getModel(e){return this.models.get(e)}getModelsByType(e){return Array.from(this.models.values()).filter(t=>t.mediaType===e)}getModelsByGenerationType(e){return Array.from(this.models.values()).filter(t=>t.capabilities.supportedTypes.includes(e))}getAvailableModels(){return Array.from(this.models.values()).filter(e=>e.isAvailable)}validateSettings(e,t,n){let r=this.getModel(e);if(!r)throw Error(`Something went wrong, please try again.`);let{capabilities:i}=r,a={...i.defaultSettings,...t};if(a.aspectRatio){let t=n&&i.aspectRatiosByType?.[n],r=t&&t.length>0?t:i.aspectRatios;if(!r.includes(a.aspectRatio)){let t=i.defaultSettings?.aspectRatio||r[0];T.info(`[ModelRegistry] Auto-corrected aspect ratio from ${a.aspectRatio} to ${t} for ${e}`),a.aspectRatio=t}}if(a.imageResolution&&i.imageResolutions?.length&&!i.imageResolutions.includes(a.imageResolution)){let t=i.defaultSettings?.imageResolution||i.imageResolutions[0];T.info(`[ModelRegistry] Auto-corrected image resolution from ${a.imageResolution} to ${t} for ${e}`),a.imageResolution=t}if(a.imageQuality&&i.imageQualities?.length&&!i.imageQualities.includes(a.imageQuality)
110){let t=i.defaultSettings?.imageQuality||i.imageQualities[0];T.info(`[ModelRegistry] Auto-corrected image quality from ${a.imageQuality} to ${t} for ${e}`),a.imageQuality=t}if(a.background&&i.backgrounds?.length&&!i.backgrounds.includes(a.background)){let t=i.defaultSettings?.background||i.backgrounds[0];T.info(`[ModelRegistry] Auto-corrected background from ${a.background} to ${t} for ${e}`),a.background=t}if(r.mediaType===`video`){if(a.resolution&&i.resolutions&&i.resolutions.length>0&&!i.resolutions.includes(a.resolution)){let t=i.defaultSettings?.resolution||i.resolutions[0];T.info(`[ModelRegistry] Auto-corrected resolution from ${a.resolution} to ${t} for ${e}`),a.resolution=t}if(a.duration&&i.durations){let t=typeof a.duration==`number`?`${a.duration}s`:a.duration,r=n&&i.durationsByType?.[n],o=r&&r.length>0?r:i.durations;if(!o.includes(t)){let n=parseInt(t.replace(`s`,``),10),r=o.map(e=>parseInt(e.replace(`s`,``),10)).reduce((e,t)=>Math.abs(t-n)<Math.abs(e-n)?t:e);a.duration=`${r}s`,T.info(`[ModelRegistry] Auto-corrected duration from ${t} to ${r}s for ${e}`)}}}if(a.variations!==void 0){let t=Math.max(1,Math.min(a.variations,i.maxVariations));t!==a.variations&&(T.info(`[ModelRegistry] Clamped variations from ${a.variations} to ${t} for ${e}`),a.variations=t)}return a}};function Ul(e){return e.mediaType===`video`}function Wl(){return Hl.getAvailableModels().filter(e=>e.mediaType===`video`)}function Gl(){return Hl.getAvailableModels().filter(e=>e.mediaType===`image`)}var Kl=[{id:`google`,name:`Google Lyria 3.5`,provider:`google`},{id:`minimax`,name:`MiniMax Music 2.6`,provider:`minimax`},{id:`elevenlabs`,name:`ElevenLabs Music v2.5`,provider:`elevenlabs`}],ql={seedance:`/Bytedance Icon.png`,bytedance:`/Bytedance Icon.png`,kling:`/Kling Icon.png`,wan:`/Qwen Icon.png`,google:`/Google Icon.png`,openai:`/OpenAI Icon.png`,xai:`/X Icon.png`,flux:`/Flux Icon.png`,seedream:`/Bytedance Icon.png`,elevenlabs:`data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%2024%2024%22%3E%3Crect%20x%3D%225.5%22%20y%3D%223%22%20width%3D%224%22%20height%3D%2218%22%20rx%3D%220.6%22%20fill%3D%22%23000%22%2F%3E%3Crect%20x%3D%2214.5%22%20y%3D%223%22%20width%3D%224%22%20height%3D%2218%22%20rx%3D%220.6%22%20fill%3D%22%23000%22%2F%3E%3C%2Fsvg%3E`,minimax:`/Minimax Icon.png`,lightricks:`/Lightricks Icon.png`},Jl=[`seedance-2.5`,`seedance-2.0`,`seedance-2.0-fast`,`seedance-2.0-mini`,`seedance-1.5-pro`,`minimax-h3`,`kling-3.0-omni`,`kling-3.0`,`kling-3.0-motion-control`,`gemini-omni-flash`,`google-veo-3.1`,`google-veo-3.1-fast`,`ltx-2.5-fast`,`wan-2.7`,`grok-imagine-video-1.5`],Yl=[`google-nano-banana-pro`,`google-nano-banana-2`,`gpt-image-2.5-sunburst`,`gpt-image-2.5-flare`,`gpt-image-2`,`seedream-5-pro`,`seedream-5`,`flux-2-max`,`flux-2-pro`,`grok-imagine-image`];function Xl(e,t){return[...e].sort((e,n)=>{let r=t.indexOf(e.id),i=t.indexOf(n.id);return(r===-1?999:r)-(i===-1?999:i)})}function Zl(){return Xl(Wl(),Jl)}function Ql(){return Xl(Gl(),Yl)}var $l={},eu={"user-upload":`Upload`,user_upload:`Upload`,google:`Google Lyria`,minimax:`MiniMax`,eleven_v4:`ElevenLabs v4`,music_v2_5:`ElevenLabs Music v2.5`,eleven_text_to_sound_v2:`ElevenLabs Sound Effects v2`,"mossformer2-se-48k-v1":`MossFormer2`,"topazlabs-video-upscale":`Topaz 4K Upscale`};function tu(e){return Hl.getModel(e)?.name||(eu[e]?eu[e]:$l[e]?$l[e]:e.split(/[-_]/).map(e=>e.length<=3?e.toUpperCase():e.charAt(0).toUpperCase()+e.slice(1)).join(` `))}var nu={reframe:!1,background_removal:!1,denoise:!1,isolate_voice:!1,extract_frame:!1,extract_crop:!1,extract_panel:!1,upscale_image:!1,upscale_video:!0};function ru(e){let t=e?.edited_from;return typeof t!=`string`||t.trim().length===0||nu[t.trim()]===!0}var iu=Object.defineProperty,au=(e,t)=>iu(e,`name`,{value:t,configurable:!0}),ou=`Popover`,[su,cu]=en(ou,[Vt]),lu=Vt(),[uu,du]=su(ou),fu=au(e=>{let{__scopePopover:t,children:n,open:r,defaultOpen:i,onOpenChange:a,modal:o=!1}=e,s=lu(t),c=X.useRef(null),[l,u]=X.useState(!1),[d,f]=Qt({prop:r,defaultProp:i??!1,onChange:a,caller:ou});return(0,Z.jsx)(Gt,{...s,children:(0,Z.jsx)(uu,{scope:t,contentId:fn(),triggerRef:c,open:d,onOpenChange:f,onOpenToggle:X.useCallback(()=>f(e=>!e),[f]),hasCustomAnchor:l,onCustomAnchorAdd:X.useCallback(()=>u(!0),[]),onCustomAnchorRemove:X.useCallback(()=>u(!1),[]),modal:o,children:n})})},`Popover`),pu=`PopoverAnchor`,mu=X.forwardRef(au(function(e,t){let{__scopePopover:n,...r}=e,i=du(pu,n),a=lu(n),{onCustomAnchorAdd:o,onCustomAnchorRemove:s}=i;return X.useEffect(()=>(o(),()=>s()),[o,s]),(0,Z.jsx)(Ht,{...a,...r,ref:t})},`PopoverAnchor`)),hu=`PopoverTrigger`,gu=X.forwardRef(au(function(e,t){let{__scopePopover:n,...r}=e,i=du(hu,n),a=lu(n),o=xn(t,i.triggerRef),s=(0,Z.jsx)(on.button,{type:`button`,"aria-haspopup":`dialog`,"aria-expanded":i.open,"aria-controls":i.open?i.contentId:void 0,"data-state":Du(i.open
110),...r,ref:o,onClick:un(e.onClick,i.onOpenToggle)});return i.hasCustomAnchor?s:(0,Z.jsx)(Ht,{asChild:!0,...a,children:s})},`PopoverTrigger`)),_u=`PopoverPortal`,[vu,yu]=su(_u,{forceMount:void 0}),bu=au(e=>{let{__scopePopover:t,forceMount:n,children:r,container:i}=e,a=du(_u,t);return(0,Z.jsx)(vu,{scope:t,forceMount:n,children:(0,Z.jsx)(Kt,{present:n||a.open,children:(0,Z.jsx)(It,{asChild:!0,container:i,children:r})})})},`PopoverPortal`),xu=`PopoverContent`,Su=X.forwardRef(au(function(e,t){let n=yu(xu,e.__scopePopover),{forceMount:r=n.forceMount,...i}=e,a=du(xu,e.__scopePopover);return(0,Z.jsx)(Kt,{present:r||a.open,children:a.modal?(0,Z.jsx)(wu,{...i,ref:t}):(0,Z.jsx)(Tu,{...i,ref:t})})},`PopoverContent`)),Cu=Sn(`PopoverContent.RemoveScroll`),wu=X.forwardRef(au(function(e,t){let n=du(xu,e.__scopePopover),r=X.useRef(null),i=xn(t,r),a=X.useRef(!1);return X.useEffect(()=>{let e=r.current;if(e)return Xt(e)},[]),(0,Z.jsx)(Yt,{as:Cu,allowPinchZoom:!0,children:(0,Z.jsx)(Eu,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:un(e.onCloseAutoFocus,e=>{e.preventDefault(),a.current||n.triggerRef.current?.focus()}),onPointerDownOutside:un(e.onPointerDownOutside,e=>{let t=e.detail.originalEvent,n=t.button===0&&t.ctrlKey===!0,r=t.button===2||n;a.current=r},{checkForDefaultPrevented:!1}),onFocusOutside:un(e.onFocusOutside,e=>e.preventDefault(),{checkForDefaultPrevented:!1})})})},`PopoverContentModal`)),Tu=X.forwardRef(au(function(e,t){let n=du(xu,e.__scopePopover),r=X.useRef(!1),i=X.useRef(!1);return(0,Z.jsx)(Eu,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:t=>{e.onCloseAutoFocus?.(t),t.defaultPrevented||(r.current||n.triggerRef.current?.focus(),t.preventDefault()),r.current=!1,i.current=!1},onInteractOutside:t=>{e.onInteractOutside?.(t),t.defaultPrevented||(r.current=!0,t.detail.originalEvent.type===`pointerdown`&&(i.current=!0));let a=t.target;n.triggerRef.current?.contains(a)&&t.preventDefault(),t.detail.originalEvent.type===`focusin`&&i.current&&t.preventDefault()}})},`PopoverContentNonModal`)),Eu=X.forwardRef(au(function(e,t){let{__scopePopover:n,trapFocus:r,onOpenAutoFocus:i,onCloseAutoFocus:a,disableOutsidePointerEvents:o,onEscapeKeyDown:s,onPointerDownOutside:c,onFocusOutside:l,onInteractOutside:u,...d}=e,f=du(xu,n),p=lu(n);return Zt(),(0,Z.jsx)(nn,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:i,onUnmountAutoFocus:a,children:(0,Z.jsx)(gn,{asChild:!0,disableOutsidePointerEvents:o,onInteractOutside:u,onEscapeKeyDown:s,onPointerDownOutside:c,onFocusOutside:l,onDismiss:()=>f.onOpenChange(!1),deferPointerDownOutside:!0,children:(0,Z.jsx)(Ut,{"data-state":Du(f.open),role:`dialog`,id:f.contentId,...p,...d,ref:t,style:{...d.style,"--radix-popover-content-transform-origin":`var(--radix-popper-transform-origin)`,"--radix-popover-content-available-width":`var(--radix-popper-available-width)`,"--radix-popover-content-available-height":`var(--radix-popper-available-height)`,"--radix-popover-trigger-width":`var(--radix-popper-anchor-width)`,"--radix-popover-trigger-height":`var(--radix-popper-anchor-height)`}})})})},`PopoverContentImpl`));function Du(e){return e?`open`:`closed`}au(Du,`getState`);var Ou=fu,ku=mu,Au=gu,ju=bu,Mu=Su,Nu=Ou,Pu=Au,Fu=ku,Iu=X.forwardRef(({className:e,align:t=`center`,sideOffset:n=4,collisionPadding:r=12,...i},a)=>(0,Z.jsx)(ju,{children:(0,Z.jsx)(Mu,{ref:a,align:t,sideOffset:n,collisionPadding:r,className:N(`z-[10010] w-full max-w-xs outline-none`,$t,`p-4`,_n,`max-w-[calc(100vw-1.5rem)] md:max-w-xs`,e),...i})}));Iu.displayName=Mu.displayName;var Lu={add_media:{line:`Added files`,made:`Added`},record_media:{line:`Recorded a video`,made:`Recorded`},generate_visual:{line:`Generated an image`,made:`Generated`},generate_music:{line:`Generated music`,made:`Generated`},generate_voiceover:{line:`Generated a voiceover`,made:`Generated`},generate_sound_effect:{line:`Generated a sound effect`,made:`Generated`},edit_remove_bg:{line:`Removed a background`,made:`Removed the background of`},edit_upscale:{line:`Upscaled`,made:`Upscaled`},edit_reframe:{line:`Reframed`,made:`Reframed`},edit_grab_frame:{line:`Kept a frame`,made:`Kept`},edit_crop:{line:`Cropped an image`,made:`Cropped`},publish_page:{line:`Shared a public link`},cut_clips:{line:`Cut clips`},edit_clips:{line:`Changed the clips`},render_clips:{line:`Rendered the clips`,made:`Rendered`},publish_to_feed:{line:`Published to the feed`},generate_image:{line:`Generated an image`,made:`Generated`},generate_video:{line:`Generated a video`,made:`Generated`},generate_audio:{line:`Generated audio`,made:`Generated`},import_media:{line:`Imported media`,made:`Imported`},import_store_products:{line:`Imported store products`,made:`Imported`},pull_posts:{line:`Pulled posts`},keep_posts:{line:`Kept posts`,made:`Kept`},extract_media:{line:`Extracted a still`,made:`Extracted`},upscale_media:{line:`Upscaled`,made:`Upscaled`},remove_background:{line:`Removed a background`,made:`Removed the background of`},reframe_image:{line:`Reframed an image`,made:`Reframed`},clean_audio:{line:`Cleaned up a recording`,made:`Cleaned up`},change_language:{line:`Changed the language`},render_timeline:{line:`Rendered the timeline`,made:`Rendered`},render_canvas:{line:`Rendered the canvas`,made:`Rendered`},save_document:{line:`Saved a document`,made:`Saved`},transcribe_media:{line:`Transcribed media`},convert_media:{line:`Converted a video`},edit_timeline:{line:`Edited the timeline`},manage_timelines:{line:`Updated a timeline`},timeline_media:{line:`Changed what a timeline works with`},apply_layout:{line:`Changed the layout`},auto_reframe:{line:`Reframed the timeline`},auto_zoom:{line:`Added zooms`},compose_motion:{line:`Added motion`},copy_clip_settings:{line:`Copied clip settings`},copy_clips:{line:`Copied clips`},duck_music:{line:`Ducked the music`},level_audio:{line:`Leveled the audio`},remove_silence:{line:`Removed silences`},remove_words:{line:`Removed words`},captions:{line:`Changed the captions`},switch_angle:{line:`Switched angles`},sync_recordings:{line:`Synced recordings`},undo:{line:`Undid a change`},edit_canvas:{line:`Edited the canvas`}
110,manage_canvases:{line:`Updated a canvas`},update_items:{line:`Updated items`},organize_items:{line:`Organized items`},delete_items:{line:`Deleted items`},manage_boards:{line:`Updated a board`},manage_calendars:{line:`Updated a calendar`},manage_comments:{line:`Commented`},manage_public_links:{line:`Updated a public link`},manage_brand_kit:{line:`Updated the brand kit`},manage_skills:{line:`Changed a skill`},manage_templates:{line:`Updated a saved template`},manage_settings:{line:`Changed the settings`},speakers:{line:`Named speakers`},cancel_jobs:{line:`Stopped work`}},Ru={image:[`an image`,`images`],video:[`a video`,`videos`],audio:[`a sound`,`sounds`],document:[`a document`,`documents`]};function zu(e){let t=e.length,n=e[0];return n&&e.every(e=>e===n)?t===1?Ru[n][0]:`${t} ${Ru[n][1]}`:t===1?`an item`:`${t} items`}var Bu={created:`Added a skill`,updated:`Updated a skill`,deleted:`Deleted a skill`},Vu={created:`Created a canvas`,copied:`Copied a canvas`,resized:`Resized a canvas`,renamed:`Renamed a canvas`,templated:`Kept a canvas as a template`,untemplated:`Stopped keeping a canvas as a template`,deleted:`Deleted a canvas`},Hu={created:`Created a timeline`,copied:`Copied a timeline`,templated:`Kept a timeline as a template`,untemplated:`Stopped keeping a timeline as a template`,renamed:`Renamed a timeline`,resized:`Changed a timeline's size or frame rate`,attached:`Added media to a timeline`,detached:`Took media off a timeline`,deleted:`Deleted a timeline`},Uu={created:`Made a calendar`,renamed:`Renamed a calendar`,channels:`Changed a calendar's channels`,statuses:`Changed a calendar's statuses`,ordered:`Reordered a day on a calendar`,deleted:`Deleted a calendar`},Wu={created:`Made a brand kit`,renamed:`Renamed a brand kit`,switched:`Switched the brand kit`,deleted:`Deleted a brand kit`},Gu={created:`Made a board`,renamed:`Renamed a board`,columns:`Changed a board's columns`,ordered:`Reordered cards on a board`,deleted:`Deleted a board`};function Ku(e){let[t,n,...r]=e.split(`:`),i=r.join(`:`),a=n===`graphic`?`saved graphic`:n===`caption`?`saved caption template`:null;return!a||!i?null:t===`renamed`?`Renamed a ${a} to "${i}"`:t===`deleted`?`Deleted the ${a} "${i}"`:null}function qu(e){let[t,n]=e.split(`:`),r=Number(n);if(!Number.isFinite(r)||r<1)return null;let i=r>1,a=i?`${r} items`:`an item`;return t===`renamed`?i?`Renamed ${r} items`:`Renamed an item`:t===`described`?`Described ${a}`:t===`tagged`?`Tagged ${a}`:t===`fields`?`Set fields on ${a}`:t===`lineage`?i?`Recorded where ${r} items came from`:`Recorded where an item came from`:t===`mixed`?`Updated ${a}`:t===`moved`?`Filed ${a}`:t===`labeled`?`Put a label on ${a}`:t===`unlabeled`?`Took a label off ${a}`:t===`starred`?`Starred ${a}`:t===`unstarred`?`Unstarred ${a}`:t===`hidden`?i?`Hid ${r} items`:`Hid an item`:t===`unhidden`?i?`Showed ${r} items again`:`Showed an item again`:t===`grouped`?`Grouped ${a} as variations`:t===`ungrouped`?i?`Ungrouped ${r} items`:`Ungrouped an item`:t===`folders_created`?i?`Made ${r} folders`:`Made a folder`:t===`folders_deleted`?i?`Deleted ${r} folders`:`Deleted a folder`:t===`labels_deleted`?i?`Deleted ${r} labels`:`Deleted a label`:null}var Ju=new Set([`edit_grab_frame`]);function Yu(e,t,n,r={}){let i=e=>!!yr(Lu,e)?.made,a=e.find(e=>i(e)&&!Ju.has(e)),o=e.every(i),s=t.length===0?void 0:a??(o?e.find(i):void 0);if(s)return`${yr(Lu,s)?.made} ${zu(t)}`;let c=e.find(e=>!Ju.has(e))??e[0],l=c?yr(Lu,c):void 0,u=c?c.replace(/_/g,` `).replace(/^./,e=>e.toUpperCase()):`Made a change`,d=(c===`manage_skills`&&r.skill?Bu[r.skill]:c===`manage_templates`&&r.saved?Ku(r.saved)??void 0:c===`manage_canvases`&&r.canvas?Vu[r.canvas]:(c===`manage_timelines`||c===`timeline_media`)&&r.timeline?Hu[r.timeline]:(c===`update_items`||c===`organize_items`)&&r.item?qu(r.item)??void 0:c===`manage_brand_kit`&&r.brandKit?Wu[r.brandKit]:c===`manage_calendars`&&r.calendar?Uu[r.calendar]:c===`manage_boards`&&r.board?Gu[r.board]:void 0)??l?.line??u;return n>1?`${d}, ${n} changes`:d}var Xu={dub:{going:`Changing the language`,did:`change the language`},transcription:{going:`Transcribing`,did:`transcribe`}
110,convert:{going:`Converting a file`,did:`convert the file`},index:{going:`Making a video searchable`,did:`make the video searchable`},describe:{going:`Writing shot lines`,did:`write the shot lines`},enrich:{going:`Describing files`,did:`describe the files`},speech:{going:`Reading the speech`,did:`read the speech`},speakers:{going:`Finding the speakers`,did:`find the speakers`},cutout:{going:`Separating the person`,did:`separate the person`},frames:{going:`Drawing frames`,did:`draw the frames`},store_import:{going:`Importing from a store`,did:`import from the store`},import:{going:`Importing a file`,did:`import the file`},reframe:{going:`Reading the subject`,did:`read the subject`},background_removal:{going:`Removing the background`,did:`remove the background`},upscale_image:{going:`Upscaling to 4K`,did:`upscale to 4K`},upscale_video:{going:`Upscaling to 4K`,did:`upscale to 4K`},isolate_voice:{going:`Isolating the voice`,did:`isolate the voice`},denoise:{going:`Cleaning up the sound`,did:`clean up the sound`}};function Zu(e){let t=e?.edited_from;return typeof t==`string`&&t in Xu?t:null}function Qu(e,t,n){if(e!==`generation`&&e!==`render`){let t=Xu[e]??{going:`Working`,did:`finish`};return n===`failed`?`Could not ${t.did}`:n===`stopped`?`Stopped ${t.going.replace(/^./,e=>e.toLowerCase())}`:t.going}let r=zu(t);return n===`failed`?`Could not ${e===`render`?`render`:`generate`} ${r}`:n===`stopped`?`Stopped ${e===`render`?`rendering`:`generating`} ${r}`:`${e===`render`?`Rendering`:`Generating`} ${r}`}var $u={meta_ad_library:{place:`the Meta Ad Library`,noun:[`ad`,`ads`],icon:`meta`},tiktok_ad_library:{place:`the TikTok Ad Library`,noun:[`ad`,`ads`],icon:`tiktok`},linkedin_ad_library:{place:`the LinkedIn Ad Library`,noun:[`ad`,`ads`],glyph:`Linkedin`},instagram:{place:`Instagram`,noun:[`post`,`posts`],icon:`instagram`},tiktok:{place:`TikTok`,noun:[`post`,`posts`],icon:`tiktok`},youtube:{place:`YouTube`,noun:[`video`,`videos`],icon:`youtube`},reddit:{place:`Reddit`,noun:[`post`,`posts`],icon:`reddit`}};function ed(e){let[t,n,...r]=e.split(`:`),i=Number(n);if(!t||!Number.isFinite(i))return null;let a=r.join(`:`);try{a=decodeURIComponent(a)}catch{}return{platform:t,count:i,target:a}}function td(e){let t=$u[e];return t?{name:t.place,icon:t.icon,glyph:t.glyph}:{name:e,glyph:`Globe`}}function nd(e){return e.length<2?e.join(``):`${e.slice(0,-1).join(`, `)} and ${e[e.length-1]}`}function rd(e){let t=[...new Set(e.map(e=>e.platform))],n=t.map(e=>$u[e]).filter(e=>!!e),r=n.length>0&&n.length===t.length?nd(n.map(e=>e.place)):``,i=e.reduce((e,t)=>e+t.count,0);if(i===0)return r?`Found nothing on ${r}`:`Found nothing`;let[a,o]=r&&new Set(n.map(e=>e.noun[1])).size===1?n[0].noun:[`post`,`posts`],s=`${i} ${i===1?a:o}`;return r?`Pulled ${s} from ${r}`:`Pulled ${s}`}function id(e,t=3){let n=[...new Set(e.map(e=>e.target.trim()).filter(Boolean))],r=n.slice(0,t).join(`, `);return n.length>t?`${r} +${n.length-t}`:r}var ad=6e4,od=200,sd=100,cd=3e3,ld=new Map;function ud(e,t,n,r,i){let a=`${e}:${n}`,o=ld.get(a);if(!o){let r={stop:()=>void 0,subscribers:new Set,fallbacks:new Set,pending:new Map};o=r,ld.set(a,r);let i=async o=>{if(ld.get(a)!==r||r.pending.size===0)return;let s=new Map([...r.pending].slice(0,sd));for(let e of s.keys())r.pending.delete(e);let{data:c,error:l}=await E.from(e).select(t).eq(`workspace_id`,n).in(`id`,[...s.keys()]);if(ld.get(a)===r){if(l){for(let[e,t]of s)r.pending.has(e)||r.pending.set(e,t);o&&setTimeout(()=>void i(!1),cd);return}for(let e of c??[]){if(!e.id)continue;let t=s.get(e.id)??`UPDATE`;for(let n of[...r.subscribers])n(e,t)}r.pending.size>0&&!r.batch&&(r.batch=setTimeout(()=>{r.batch=void 0,i(!0)},0))}};r.stop=Ft(n,{onMessage:(t,n)=>{if(t!==`row`)return;let a=n;a?.t!==e||typeof a.id!=`string`||a.op!==`INSERT`&&a.op!==`UPDATE`||((!r.pending.has(a.id)||a.op===`INSERT`)&&r.pending.set(a.id,a.op),r.batch||=setTimeout(()=>{r.batch=void 0,i(!0)},od))},onStatus:e=>{if(ld.get(a)===r){if(e===`down`){if(r.degraded)return;let e=()=>{if(document.visibilityState===`visible`)for(let e of[...r.fallbacks])e()};for(let e of[...r.fallbacks])e();r.degraded=setInterval(e,ad);return}if(r.degraded&&=(clearInterval(r.degraded),void 0),e===`rejoined`)for(let e of[...r.fallbacks])e()}}})}let s=o;return s.subscribers.add(r),i&&s.fallbacks.add(i),()=>{s.subscribers.delete(r),i&&s.fallbacks.delete(i),s.subscribers.size===0&&(s.degraded&&clearInterval(s.degraded),s.batch&&clearTimeout(s.batch),ld.delete(a),s.stop())}}function dd(e,t,n,r,i){let a=(0,X.useRef)(r);(0,X.useEffect)(()=>{a.current=r},[r]);let o=(0,X.useRef)(i);(0,X.useEffect)(()=>{o.current=i},[i]);let s=!!i,c=yi(),l=(0,X.useRef)(!1);(0,X.useEffect)(()=>
110{if(c||(l.current=!0),!(!n||!c))return l.current&&(l.current=!1,o.current?.()),ud(e,t,n,(e,t)=>a.current(e,t),s?()=>o.current?.():void 0)},[e,t,n,s,c])}function fd(e,t,n){dd(`generations`,vo,e,t,n)}function pd(e,t,n){dd(`library_items`,se,e,t,n)}var md=(e,t,n)=>({code:e,message:t,retryable:n}),hd=`The model did not produce a result. Try again, or try another model.`;function gd(e,t){switch(e){case`CONTENT_MODERATION`:return t===`adjust_inputs`?md(`refused`,`One of the reference images was declined. Change it and try again.`,!1):md(`refused`,`The prompt was declined. Change it and try again.`,!1);case`INPUT_NEEDS_VERIFICATION`:return md(`refused`,`One of the inputs looks like a real person, who must be verified before their face can be used.`,!1);case`INPUT_NOT_ACCEPTED`:return md(`validation_error`,`This model does not accept that source file. Use a shorter clip or another model.`,!1);case`INVALID_MODEL`:case`INVALID_REQUEST`:case`INVALID_SETTINGS`:case`MISSING_REQUIRED_FIELD`:return md(`validation_error`,`These settings were not accepted. Change them and try again.`,!1);case`INSUFFICIENT_CREDITS`:return md(`insufficient_credits`,`Out of credits. Add more in Usage & billing.`,!1);case`RATE_LIMITED`:case`QUEUE_FULL`:return md(`rate_limited`,`Busy right now. Try again in a minute.`,!0);case`PROVIDER_ACCOUNT`:return md(`unavailable`,`This model is unavailable right now. Try another model or try again later.`,!0);case`SERVICE_UNAVAILABLE`:case`NETWORK_ERROR`:case`PROVIDER_ERROR`:return md(`unavailable`,`Unavailable right now. Try again shortly.`,!0);case`GENERATION_TIMEOUT`:case`REQUEST_TIMEOUT`:case`SWEEP_TIMEOUT`:return md(`unavailable`,`It took too long and nothing was delivered. Try again.`,!0);case`STORAGE_UPLOAD_FAILED`:case`STORAGE_DOWNLOAD_FAILED`:case`DATABASE_ERROR`:case`RECORD_NOT_FOUND`:case`WEBHOOK_VALIDATION_FAILED`:return md(`internal_error`,`The result could not be saved. Try again.`,!0);case`GENERATION_FAILED`:return md(`unavailable`,hd,!0);case`USER_CANCELLED`:return md(`cancelled`,`It was cancelled.`,!0);default:return null}}function _d(e){let t=typeof e?.errorCode==`string`?e.errorCode:null,n=typeof e?.recoveryStrategy==`string`?e.recoveryStrategy:null;return(t?gd(t,n)?.message:null)??`The model did not produce a result. Try again, or try another model.`}var vd=`#version 300 es 111precision mediump float; 112 113layout(location = 0) in vec4 a_position; 114 115uniform vec2 u_resolution; 116uniform float u_pixelRatio; 117uniform float u_imageAspectRatio; 118uniform float u_originX; 119uniform float u_originY; 120uniform float u_worldWidth; 121uniform float u_worldHeight; 122uniform float u_fit; 123uniform float u_scale; 124uniform float u_rotation; 125uniform float u_offsetX; 126uniform float u_offsetY; 127 128out vec2 v_objectUV; 129out vec2 v_objectBoxSize; 130out vec2 v_responsiveUV; 131out vec2 v_responsiveBoxGivenSize; 132out vec2 v_patternUV; 133out vec2 v_patternBoxSize; 134out vec2 v_imageUV; 135 136vec3 getBoxSize(float boxRatio, vec2 givenBoxSize) { 137 vec2 box = vec2(0.);
138 // fit = none 139 box.x = boxRatio * min(givenBoxSize.x / boxRatio, givenBoxSize.y); 140 float noFitBoxWidth = box.x; 141 if (u_fit == 1.) { // fit = contain 142 box.x = boxRatio * min(u_resolution.x / boxRatio, u_resolution.y); 143 } else if (u_fit == 2.) { // fit = cover 144 box.x = boxRatio * max(u_resolution.x / boxRatio, u_resolution.y); 145 } 146 box.y = box.x / boxRatio; 147 return vec3(box, noFitBoxWidth); 148} 149 150void main() { 151 gl_Position = a_position; 152 153 vec2 uv = gl_Position.xy * .5; 154 vec2 boxOrigin = vec2(.5 - u_originX, u_originY - .5); 155 vec2 givenBoxSize = vec2(u_worldWidth, u_worldHeight); 156 givenBoxSize = max(givenBoxSize, vec2(1.)) * u_pixelRatio; 157 float r = u_rotation * 3.14159265358979323846 / 180.; 158 mat2 graphicRotation = mat2(cos(r), sin(r), -sin(r), cos(r)); 159 vec2 graphicOffset = vec2(-u_offsetX, u_offsetY); 160 161 162 // =================================================== 163 164 float fixedRatio = 1.; 165 vec2 fixedRatioBoxGivenSize = vec2( 166 (u_worldWidth == 0.) ? u_resolution.x : givenBoxSize.x, 167 (u_worldHeight == 0.) ? u_resolution.y : givenBoxSize.y 168 ); 169 170 v_objectBoxSize = getBoxSize(fixedRatio, fixedRatioBoxGivenSize).xy; 171 vec2 objectWorldScale = u_resolution.xy / v_objectBoxSize; 172 173 v_objectUV = uv; 174 v_objectUV *= objectWorldScale; 175 v_objectUV += boxOrigin * (objectWorldScale - 1.); 176 v_objectUV += graphicOffset; 177 v_objectUV /= u_scale; 178 v_objectUV = graphicRotation * v_objectUV; 179 180 // =================================================== 181 182 v_responsiveBoxGivenSize = vec2( 183 (u_worldWidth == 0.) ? u_resolution.x : givenBoxSize.x, 184 (u_worldHeight == 0.) ? u_resolution.y : givenBoxSize.y 185 ); 186 float responsiveRatio = v_responsiveBoxGivenSize.x / v_responsiveBoxGivenSize.y; 187 vec2 responsiveBoxSize = getBoxSize(responsiveRatio, v_responsiveBoxGivenSize).xy; 188 vec2 responsiveBoxScale = u_resolution.xy / responsiveBoxSize; 189 190 #ifdef ADD_HELPERS 191 v_responsiveHelperBox = uv; 192 v_responsiveHelperBox *= responsiveBoxScale; 193 v_responsiveHelperBox += boxOrigin * (responsiveBoxScale - 1.); 194 #endif 195 196 v_responsiveUV = uv; 197 v_responsiveUV *= responsiveBoxScale; 198 v_responsiveUV += boxOrigin * (responsiveBoxScale - 1.); 199 v_responsiveUV += graphicOffset; 200 v_responsiveUV /= u_scale; 201 v_responsiveUV.x *= responsiveRatio; 202 v_responsiveUV = graphicRotation * v_responsiveUV; 203 v_responsiveUV.x /= responsiveRatio; 204 205 // =================================================== 206 207 float patternBoxRatio = givenBoxSize.x / givenBoxSize.y; 208 vec2 patternBoxGivenSize = vec2( 209 (u_worldWidth == 0.) ? u_resolution.x : givenBoxSize.x, 210 (u_worldHeight == 0.) ? u_resolution.y : givenBoxSize.y 211 ); 212 patternBoxRatio = patternBoxGivenSize.x / patternBoxGivenSize.y; 213 214 vec3 boxSizeData = getBoxSize(patternBoxRatio, patternBoxGivenSize); 215 v_patternBoxSize = boxSizeData.xy; 216 float patternBoxNoFitBoxWidth = boxSizeData.z; 217 vec2 patternBoxScale = u_resolution.xy / v_patternBoxSize; 218 219 v_patternUV = uv; 220 v_patternUV += graphicOffset / patternBoxScale; 221 v_patternUV += boxOrigin; 222 v_patternUV -= boxOrigin / patternBoxScale; 223 v_patternUV *= u_resolution.xy; 224 v_patternUV /= u_pixelRatio; 225 if (u_fit > 0.) { 226 v_patternUV *= (patternBoxNoFitBoxWidth / v_patternBoxSize.x); 227 } 228 v_patternUV /= u_scale; 229 v_patternUV = graphicRotation * v_patternUV; 230 v_patternUV += boxOrigin / patternBoxScale; 231 v_patternUV -= boxOrigin; 232 // x100 is a default multiplier between vertex and fragmant shaders 233 // we use it to avoid UV presision issues 234 v_patternUV *= .01; 235 236 // =================================================== 237 238 vec2 imageBoxSize; 239 if (u_fit == 1.) { // contain 240 imageBoxSize.x = min(u_resolution.x / u_imageAspectRatio, u_resolution.y) * u_imageAspectRatio; 241 } else if (u_fit == 2.) { // cover 242 imageBoxSize.x = max(u_resolution.x / u_imageAspectRatio, u_resolution.y) * u_imageAspectRatio; 243 } else { 244 imageBoxSize.x = min(10.0, 10.0 / u_imageAspectRatio * u_imageAspectRatio); 245 } 246 imageBoxSize.y = imageBoxSize.x / u_imageAspectRatio; 247 vec2 imageBoxScale = u_resolution.xy / imageBoxSize; 248 249 v_imageUV = uv; 250 v_imageUV *= imageBoxScale; 251 v_imageUV += boxOrigin * (imageBoxScale - 1.); 252 v_imageUV += graphicOffset; 253 v_imageUV /= u_scale; 254 v_imageUV.x *= u_imageAspectRatio; 255 v_imageUV = graphicRotation * v_imageUV; 256 v_imageUV.x /= u_imageAspectRatio; 257 258 v_imageUV += .5; 259 v_imageUV.y = 1. - v_imageUV.y; 260}`,yd=8294400,bd=class{parentElement;canvasElement;gl;program=null;uniformLocations={};fragmentShader;rafId=null;lastRenderTime=0;currentFrame=0;speed=0;currentSpeed=0;providedUniforms;mipmaps=[];hasBeenDisposed=!1;resolutionChanged=!0;textures=new Map;minPixelRatio;maxPixelCount;isSafari=wd();uniformCache={};textureUnitMap=new Map;ownerDocument;
260constructor(e,t,n,r,i=0,a=0,o=2,s=yd,c=[]){if(e?.nodeType===1)this.parentElement=e;else throw Error(`Paper Shaders: parent element must be an HTMLElement`);if(this.ownerDocument=e.ownerDocument,!this.ownerDocument.querySelector(`style[data-paper-shader]`)){let e=this.ownerDocument.createElement(`style`);e.innerHTML=Cd,e.setAttribute(`data-paper-shader`,``),this.ownerDocument.head.prepend(e)}let l=this.ownerDocument.createElement(`canvas`);this.canvasElement=l,this.parentElement.prepend(l),this.fragmentShader=t,this.providedUniforms=n,this.mipmaps=c,this.currentFrame=a,this.minPixelRatio=o,this.maxPixelCount=s;let u=l.getContext(`webgl2`,r);if(!u)throw Error(`Paper Shaders: WebGL is not supported in this browser`);this.gl=u,this.initProgram(),this.setupPositionAttribute(),this.setupUniforms(),this.setUniformValues(this.providedUniforms),this.setupResizeObserver(),visualViewport?.addEventListener(`resize`,this.handleVisualViewportChange),this.setupIntersectionObserver(),this.setSpeed(i),this.parentElement.setAttribute(`data-paper-shader`,``),this.parentElement.paperShaderMount=this,this.ownerDocument.addEventListener(`visibilitychange`,this.handleDocumentVisibilityChange)}initProgram=()=>{let e=Sd(this.gl,vd,this.fragmentShader);e&&(this.program=e)};setupPositionAttribute=()=>{let e=this.gl.getAttribLocation(this.program,`a_position`),t=this.gl.createBuffer();this.gl.bindBuffer(this.gl.ARRAY_BUFFER,t),this.gl.bufferData(this.gl.ARRAY_BUFFER,new Float32Array([-1,-1,1,-1,-1,1,-1,1,1,-1,1,1]),this.gl.STATIC_DRAW),this.gl.enableVertexAttribArray(e),this.gl.vertexAttribPointer(e,2,this.gl.FLOAT,!1,0,0)};setupUniforms=()=>{let e={u_time:this.gl.getUniformLocation(this.program,`u_time`),u_pixelRatio:this.gl.getUniformLocation(this.program,`u_pixelRatio`),u_resolution:this.gl.getUniformLocation(this.program,`u_resolution`)};Object.entries(this.providedUniforms).forEach(([t,n])=>{if(e[t]=this.gl.getUniformLocation(this.program,t),n instanceof HTMLImageElement){let n=`${t}AspectRatio`;e[n]=this.gl.getUniformLocation(this.program,n)}}),this.uniformLocations=e};renderScale=1;parentWidth=0;parentHeight=0;parentDevicePixelWidth=0;parentDevicePixelHeight=0;devicePixelsSupported=!1;intersectionObserver=null;isInViewport=!0;resizeObserver=null;setupResizeObserver=()=>{this.resizeObserver=new ResizeObserver(([e])=>{if(e?.borderBoxSize[0]){let t=e.devicePixelContentBoxSize?.[0];t!==void 0&&(this.devicePixelsSupported=!0,this.parentDevicePixelWidth=t.inlineSize,this.parentDevicePixelHeight=t.blockSize),this.parentWidth=e.borderBoxSize[0].inlineSize,this.parentHeight=e.borderBoxSize[0].blockSize}this.handleResize()}),this.resizeObserver.observe(this.parentElement)};setupIntersectionObserver=()=>{let e=this.ownerDocument.defaultView;e?.IntersectionObserver&&(this.intersectionObserver=new e.IntersectionObserver(([e])=>{this.isInViewport=e?.isIntersecting??!0,this.updateCurrentSpeed()}),this.intersectionObserver.observe(this.parentElement))};handleVisualViewportChange=()=>{this.resizeObserver?.disconnect(),this.setupResizeObserver()};handleResize=()=>{let e=0,t=0,n=Math.max(1,window.devicePixelRatio),r=visualViewport?.scale??1;if(this.devicePixelsSupported){let i=Math.max(1,this.minPixelRatio/n);e=this.parentDevicePixelWidth*i*r,t=this.parentDevicePixelHeight*i*r}else{let i=Math.max(n,this.minPixelRatio)*r;if(this.isSafari){let e=Td(this.ownerDocument);i*=Math.max(1,e)}e=Math.round(this.parentWidth)*i,t=Math.round(this.parentHeight)*i}let i=Math.sqrt(this.maxPixelCount)/Math.sqrt(e*t),a=Math.min(1,i),o=Math.round(e*a),s=Math.round(t*a),c=o/Math.round(this.parentWidth);(this.canvasElement.width!==o||this.canvasElement.height!==s||this.renderScale!==c)&&(this.renderScale=c,this.canvasElement.width=o,this.canvasElement.height=s,this.resolutionChanged=!0,this.gl.viewport(0,0,this.gl.canvas.width,this.gl.canvas.height),this.render(performance.now()))};render=e=>{if(this.hasBeenDisposed||this.program===null)return;let t=e-this.lastRenderTime;this.lastRenderTime=e,this.currentSpeed!==0&&(this.currentFrame+=t*this.currentSpeed),this.gl.clear(this.gl.COLOR_BUFFER_BIT),this.gl.useProgram(this.program),this.gl.uniform1f(this.uniformLocations.u_time,this.currentFrame*.001),this.resolutionChanged&&=(this.gl.uniform2f(this.uniformLocations.u_resolution,this.gl.canvas.width,this.gl.canvas.height),this.gl.uniform1f(this.uniformLocations.u_pixelRatio,this.renderScale),!1),this.gl.drawArrays(this.gl.TRIANGLES,0,6),this.currentSpeed===0?this.rafId=null:this.requestRender()};requestRender=()=>{this.rafId!==null&&cancelAnimationFrame(this.rafId),this.rafId=requestAnimationFrame(this.render)};setTextureUniform=(e,t)=>
260{if(!t.complete||t.naturalWidth===0)throw Error(`Paper Shaders: image for uniform ${e} must be fully loaded`);let n=this.textures.get(e);n&&this.gl.deleteTexture(n),this.textureUnitMap.has(e)||this.textureUnitMap.set(e,this.textureUnitMap.size);let r=this.textureUnitMap.get(e);this.gl.activeTexture(this.gl.TEXTURE0+r);let i=this.gl.createTexture();if(this.gl.bindTexture(this.gl.TEXTURE_2D,i),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_S,this.gl.CLAMP_TO_EDGE),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_T,this.gl.CLAMP_TO_EDGE),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_MIN_FILTER,this.gl.LINEAR),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_MAG_FILTER,this.gl.LINEAR),this.gl.texImage2D(this.gl.TEXTURE_2D,0,this.gl.RGBA,this.gl.RGBA,this.gl.UNSIGNED_BYTE,t),this.mipmaps.includes(e)&&(this.gl.generateMipmap(this.gl.TEXTURE_2D),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_MIN_FILTER,this.gl.LINEAR_MIPMAP_LINEAR)),this.gl.getError()!==this.gl.NO_ERROR||i===null)return;this.textures.set(e,i);let a=this.uniformLocations[e];if(a){this.gl.uniform1i(a,r);let n=`${e}AspectRatio`,i=this.uniformLocations[n];if(i){let e=t.naturalWidth/t.naturalHeight;this.gl.uniform1f(i,e)}}};areUniformValuesEqual=(e,t)=>e===t?!0:Array.isArray(e)&&Array.isArray(t)&&e.length===t.length?e.every((e,n)=>this.areUniformValuesEqual(e,t[n])):!1;setUniformValues=e=>{this.gl.useProgram(this.program),Object.entries(e).forEach(([e,t])=>{let n=t;if(t instanceof HTMLImageElement&&(n=`${t.src.slice(0,200)}|${t.naturalWidth}x${t.naturalHeight}`),this.areUniformValuesEqual(this.uniformCache[e],n))return;this.uniformCache[e]=n;let r=this.uniformLocations[e];if(!r){`${e}`;return}if(t instanceof HTMLImageElement)this.setTextureUniform(e,t);else if(Array.isArray(t)){let n=null,i=null;if(t[0]!==void 0&&Array.isArray(t[0])){let r=t[0].length;if(t.every(e=>e.length===r))n=t.flat(),i=r;else{`${e}`;return}}else n=t,i=n.length;switch(i){case 2:this.gl.uniform2fv(r,n);break;case 3:this.gl.uniform3fv(r,n);break;case 4:this.gl.uniform4fv(r,n);break;case 9:this.gl.uniformMatrix3fv(r,!1,n);break;case 16:this.gl.uniformMatrix4fv(r,!1,n);break;default:`${i}`}}else typeof t==`number`?this.gl.uniform1f(r,t):typeof t==`boolean`?this.gl.uniform1i(r,+!!t):`${e}`})};getCurrentFrame=()=>this.currentFrame;setFrame=e=>{this.currentFrame=e,this.lastRenderTime=performance.now(),this.render(performance.now())};setSpeed=(e=1)=>{this.speed=e,this.updateCurrentSpeed()};updateCurrentSpeed=()=>{this.setCurrentSpeed(this.ownerDocument.hidden||!this.isInViewport?0:this.speed)};setCurrentSpeed=e=>{this.currentSpeed=e,this.rafId===null&&e!==0&&(this.lastRenderTime=performance.now(),this.rafId=requestAnimationFrame(this.render)),this.rafId!==null&&e===0&&(cancelAnimationFrame(this.rafId),this.rafId=null)};setMaxPixelCount=(e=yd)=>{this.maxPixelCount=e,this.handleResize()};setMinPixelRatio=(e=2)=>{this.minPixelRatio=e,this.handleResize()};setUniforms=e=>{this.setUniformValues(e),this.providedUniforms={...this.providedUniforms,...e},this.render(performance.now())};handleDocumentVisibilityChange=()=>{this.updateCurrentSpeed()};dispose=()=>{this.hasBeenDisposed=!0,this.rafId!==null&&(cancelAnimationFrame(this.rafId),this.rafId=null),this.gl&&this.program&&(this.textures.forEach(e=>{this.gl.deleteTexture(e)}),this.textures.clear(),this.gl.deleteProgram(this.program),this.program=null,this.gl.bindBuffer(this.gl.ARRAY_BUFFER,null),this.gl.bindBuffer(this.gl.ELEMENT_ARRAY_BUFFER,null),this.gl.bindRenderbuffer(this.gl.RENDERBUFFER,null),this.gl.bindFramebuffer(this.gl.FRAMEBUFFER,null),this.gl.getError()),this.resizeObserver&&=(this.resizeObserver.disconnect(),null),this.intersectionObserver&&=(this.intersectionObserver.disconnect(),null),visualViewport?.removeEventListener(`resize`,this.handleVisualViewportChange),this.ownerDocument.removeEventListener(`visibilitychange`,this.handleDocumentVisibilityChange),this.uniformLocations={},this.canvasElement.remove(),delete this.parentElement.paperShaderMount}};function xd(e,t,n){let r=e.createShader(t);return r?(e.shaderSource(r,n),e.compileShader(r),e.getShaderParameter(r,e.COMPILE_STATUS)?r:(``+e.getShaderInfoLog(r),e.deleteShader(r),null)):null}function Sd(e,t,n){let r=e.getShaderPrecisionFormat(e.FRAGMENT_SHADER,e.MEDIUM_FLOAT),i=r?r.precision:null;i&&i<23&&(t=t.replace(/precision\s+(lowp|mediump)\s+float;/g,`precision highp float;`),n=n.replace(/precision\s+(lowp|mediump)\s+float/g,`precision highp float`).replace(/\b(uniform|varying|attribute)\s+(lowp|mediump)\s+(\w+)/g,`$1 highp $3`));let a=xd(e,e.VERTEX_SHADER,t),o=xd(e,e.FRAGMENT_SHADER,n);if(!a||!o)return null;let s=e.createProgram();return s?(e.attachShader(s,a),e.attachShader(s,o),e.linkProgram(s),e.getProgramParameter(s,e.LINK_STATUS)?(e.detachShader(s,a),e.detachShader(s,o),e.deleteShader(a),e.deleteShader(o),s):(``+e.getProgramInfoLog(s),e.deleteProgram(s),e.deleteShader(a),e.deleteShader(o),null)):null}var Cd=`@layer paper-shaders { 261 :where([data-paper-shader]) { 262 isolation: isolate; 263 position: relative; 264 265 & canvas { 266 contain: strict; 267 display: block; 268 position: absolute; 269 inset: 0; 270 z-index: -1; 271 width: 100%; 272 height: 100%; 273 border-radius: inherit; 274 corner-shape: inherit; 275 } 276 } 277}`;function wd(){let e=navigator.userAgent.toLowerCase();return e.includes(`safari`)&&!e.includes(`chrome`)&&!e.includes(`android`)}
277function Td(e){let t=visualViewport?.scale??1,n=visualViewport?.width??window.innerWidth,r=window.innerWidth-e.documentElement.clientWidth,i=t*n+r,a=outerWidth/i,o=Math.round(100*a);return o%5==0?o/100:o===33?1/3:o===67?2/3:o===133?4/3:a}var Ed={fit:`contain`,scale:1,rotation:0,offsetX:0,offsetY:0,originX:.5,originY:.5,worldWidth:0,worldHeight:0},Dd={none:0,contain:1,cover:2},Od=` 278#define TWO_PI 6.28318530718 279#define PI 3.14159265358979323846 280`,kd=` 281vec2 rotate(vec2 uv, float th) { 282 return mat2(cos(th), sin(th), -sin(th), cos(th)) * uv; 283} 284`,Ad=` 285 float hash21(vec2 p) { 286 p = fract(p * vec2(0.3183099, 0.3678794)) + 0.1; 287 p += dot(p, p + 19.19); 288 return fract(p.x * p.y); 289 } 290`,jd={maxColorCount:10},Md=`#version 300 es 291precision mediump float; 292 293uniform float u_time; 294 295uniform vec4 u_colors[${jd.maxColorCount}]; 296uniform float u_colorsCount; 297 298uniform float u_distortion; 299uniform float u_swirl; 300uniform float u_grainMixer; 301uniform float u_grainOverlay; 302 303in vec2 v_objectUV; 304out vec4 fragColor; 305 306${Od} 307${kd} 308${Ad} 309 310float valueNoise(vec2 st) { 311 vec2 i = floor(st); 312 vec2 f = fract(st); 313 float a = hash21(i); 314 float b = hash21(i + vec2(1.0, 0.0)); 315 float c = hash21(i + vec2(0.0, 1.0)); 316 float d = hash21(i + vec2(1.0, 1.0)); 317 vec2 u = f * f * (3.0 - 2.0 * f); 318 float x1 = mix(a, b, u.x); 319 float x2 = mix(c, d, u.x); 320 return mix(x1, x2, u.y); 321} 322 323float noise(vec2 n, vec2 seedOffset) { 324 return valueNoise(n + seedOffset); 325} 326 327vec2 getPosition(int i, float t) { 328 float a = float(i) * .37; 329 float b = .6 + fract(float(i) / 3.) * .9; 330 float c = .8 + fract(float(i + 1) / 4.); 331 332 float x = sin(t * b + a); 333 float y = cos(t * c + a * 1.5); 334 335 return .5 + .5 * vec2(x, y); 336} 337 338void main() { 339 vec2 uv = v_objectUV; 340 uv += .5; 341 vec2 grainUV = uv * 1000.; 342 343 float grain = noise(grainUV, vec2(0.)); 344 float mixerGrain = .4 * u_grainMixer * (grain - .5); 345 346 const float firstFrameOffset = 41.5; 347 float t = .5 * (u_time + firstFrameOffset); 348 349 float radius = smoothstep(0., 1., length(uv - .5)); 350 float center = 1. - radius; 351 for (float i = 1.; i <= 2.; i++) { 352 uv.x += u_distortion * center / i * sin(t + i * .4 * smoothstep(.0, 1., uv.y)) * cos(.2 * t + i * 2.4 * smoothstep(.0, 1., uv.y)); 353 uv.y += u_distortion * center / i * cos(t + i * 2. * smoothstep(.0, 1., uv.x)); 354 } 355 356 vec2 uvRotated = uv; 357 uvRotated -= vec2(.5); 358 float angle = 3. * u_swirl * radius; 359 uvRotated = rotate(uvRotated, -angle); 360 uvRotated += vec2(.5); 361 362 vec3 color = vec3(0.); 363 float opacity = 0.; 364 float totalWeight = 0.; 365 366 for (int i = 0; i < ${jd.maxColorCount}; i++) { 367 if (i >= int(u_colorsCount)) break; 368 369 vec2 pos = getPosition(i, t) + mixerGrain; 370 vec3 colorFraction = u_colors[i].rgb * u_colors[i].a; 371 float opacityFraction = u_colors[i].a; 372 373 float dist = length(uvRotated - pos); 374 375 dist = pow(dist, 3.5); 376 float weight = 1. / (dist + 1e-3); 377 color += colorFraction * weight; 378 opacity += opacityFraction * weight; 379 totalWeight += weight; 380 } 381 382 color /= max(1e-4, totalWeight); 383 opacity /= max(1e-4, totalWeight); 384 385 float grainOverlay = valueNoise(rotate(grainUV, 1.) + vec2(3.)); 386 grainOverlay = mix(grainOverlay, valueNoise(rotate(grainUV, 2.) + vec2(-1.)), .5); 387 grainOverlay = pow(grainOverlay, 1.3); 388 389 float grainOverlayV = grainOverlay * 2. - 1.; 390 vec3 grainOverlayColor = vec3(step(0., grainOverlayV)); 391 float grainOverlayStrength = u_grainOverlay * abs(grainOverlayV); 392 grainOverlayStrength = pow(grainOverlayStrength, .8); 393 color = mix(color, grainOverlayColor, .35 * grainOverlayStrength); 394 395 opacity += .5 * grainOverlayStrength; 396 opacity = clamp(opacity, 0., 1.); 397 398 fragColor = vec4(color, opacity); 399} 400`;function Nd(e){if(Array.isArray(e))return e.length===4?e:e.length===3?[...e,1]:zd;if(typeof e!=`string`)return zd;let t,n,r,i=1;if(e.startsWith(`#`))[t,n,r,i]=Pd(e);else if(e.startsWith(`rgb`)){let a=Fd(e);if(a===null)return zd;[t,n,r,i]=a}else if(e.startsWith(`hsl`)){let a=Id(e);if(a===null)return zd;[t,n,r,i]=Ld(a)}else return zd;return[Rd(t,0,1),Rd(n,0,1),Rd(r,0,1),Rd(i,0,1)]}function Pd(e){return e=e.replace(/^#/,``),(e.length===3||e.length===4)&&(e=e.split(``).map(e=>e+e).join(``)),e.length===6&&(e+=`ff`),/^[0-9a-f]{8}$/i.test(e)?[parseInt(e.slice(0,2),16)/255,parseInt(e.slice(2,4),16)/255,parseInt(e.slice(4,6),16)/255,parseInt(e.slice(6,8),16)/255]:zd}function Fd(e){let t=e.match(/^rgba?\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*([0-9.]+))?\s*\)$/i);return t?[parseInt(t[1]??`0`)/255,parseInt(t[2]??`0`)/255,parseInt(t[3]??`0`)/255,t[4]===void 0?1:parseFloat(t[4])]:null}function Id(e){let t=e.match(/^hsla?\s*\(\s*(\d+)\s*,\s*(\d+)%\s*,\s*(\d+)%\s*(?:,\s*([0-9.]+))?\s*\)$/i);return t?[parseInt(t[1]??`0`),parseInt(t[2]??`0`),parseInt(t[3]??`0`),t[4]===void 0?1:parseFloat(t[4])]:null}function Ld(e){let[t,n,r,i]=e,a=t/360,o=n/100,s=r/100,c,l,u;
400if(n===0)c=l=u=s;else{let e=(e,t,n)=>(n<0&&(n+=1),n>1&&--n,n<1/6?e+(t-e)*6*n:n<1/2?t:n<2/3?e+(t-e)*(2/3-n)*6:e),t=s<.5?s*(1+o):s+o-s*o,n=2*s-t;c=e(n,t,a+1/3),l=e(n,t,a),u=e(n,t,a-1/3)}return[c,l,u,i]}var Rd=(e,t,n)=>Math.min(Math.max(e,t),n),zd=[.5,.5,.5,1];function Bd(e){let t=X.useRef(void 0),n=X.useCallback(t=>{let n=e.map(e=>{if(e!=null){if(typeof e==`function`){let n=e,r=n(t);return typeof r==`function`?r:()=>{n(null)}}return e.current=t,()=>{e.current=null}}});return()=>{n.forEach(e=>e?.())}},e);return X.useMemo(()=>e.every(e=>e==null)?null:e=>{t.current&&=(t.current(),void 0),e!=null&&(t.current=n(e))},e)}function Vd(e){if(e.naturalWidth<1024&&e.naturalHeight<1024){if(e.naturalWidth<1||e.naturalHeight<1)return;let t=e.naturalWidth/e.naturalHeight;e.width=Math.round(t>1?1024*t:1024),e.height=Math.round(t>1?1024:1024/t)}}async function Hd(e){let t={},n=[],r=e=>{try{return e.startsWith(`/`)||new URL(e),!0}catch{return!1}},i=e=>{try{return!e.startsWith(`/`)&&new URL(e,window.location.origin).origin!==window.location.origin}catch{return!1}};return Object.entries(e).forEach(([e,a])=>{if(typeof a==`string`){let o=a||`data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==`;if(!r(o)){`${e}${o}`;return}let s=new Promise((n,r)=>{let a=new Image;i(o)&&(a.crossOrigin=`anonymous`),a.onload=()=>{Vd(a),t[e]=a,n()},a.onerror=()=>{`${o}`,r()},a.src=o});n.push(s)}else if(a instanceof HTMLImageElement){let r=a.decode().then(()=>{Vd(a),t[e]=a});n.push(r)}else t[e]=a}),await Promise.all(n),t}var Ud=(0,X.forwardRef)(function({fragmentShader:e,uniforms:t,webGlContextAttributes:n,speed:r=0,frame:i=0,width:a,height:o,minPixelRatio:s,maxPixelCount:c,mipmaps:l,style:u,...d},f){let[p,m]=(0,X.useState)(!1),h=(0,X.useRef)(null),g=(0,X.useRef)(null),_=(0,X.useRef)(n);(0,X.useEffect)(()=>((async()=>{let n=await Hd(t);h.current&&!g.current&&(g.current=new bd(h.current,e,n,_.current,r,i,s,c,l),m(!0))})(),()=>{g.current?.dispose(),g.current=null}),[e]),(0,X.useEffect)(()=>{let e=!1;return(async()=>{let n=await Hd(t);e||g.current?.setUniforms(n)})(),()=>{e=!0}},[t,p]),(0,X.useEffect)(()=>{g.current?.setSpeed(r)},[r,p]),(0,X.useEffect)(()=>{g.current?.setMaxPixelCount(c)},[c,p]),(0,X.useEffect)(()=>{g.current?.setMinPixelRatio(s)},[s,p]),(0,X.useEffect)(()=>{g.current?.setFrame(i)},[i,p]);let v=Bd([h,f]);return(0,Z.jsx)(`div`,{ref:v,style:a!==void 0||o!==void 0?{width:typeof a==`string`&&isNaN(+a)===!1?+a:a,height:typeof o==`string`&&isNaN(+o)===!1?+o:o,...u}:u,...d})});Ud.displayName=`ShaderMount`;function Wd(e,t){if(Object.keys(e).length!==Object.keys(t).length)return!1;for(let n in e){if(n===`colors`){let n=Array.isArray(e.colors),r=Array.isArray(t.colors);if(!n||!r){if(Object.is(e.colors,t.colors)===!1)return!1;continue}if(e.colors?.length!==t.colors?.length||!e.colors?.every((e,n)=>e===t.colors?.[n]))return!1;continue}if(Object.is(e[n],t[n])===!1)return!1}return!0}var Gd={name:`Default`,params:{...Ed,speed:1,frame:0,colors:[`#e0eaff`,`#241d9a`,`#f75092`,`#9f50d3`],distortion:.8,swirl:.1,grainMixer:0,grainOverlay:0}};({...Ed}),{...Ed},{...Ed};var Kd=(0,X.memo)(function({speed:e=Gd.params.speed,frame:t=Gd.params.frame,colors:n=Gd.params.colors,distortion:r=Gd.params.distortion,swirl:i=Gd.params.swirl,grainMixer:a=Gd.params.grainMixer,grainOverlay:o=Gd.params.grainOverlay,fit:s=Gd.params.fit,rotation:c=Gd.params.rotation,scale:l=Gd.params.scale,originX:u=Gd.params.originX,originY:d=Gd.params.originY,offsetX:f=Gd.params.offsetX,offsetY:p=Gd.params.offsetY,worldWidth:m=Gd.params.worldWidth,worldHeight:h=Gd.params.worldHeight,...g}){let _={u_colors:n.map(Nd),u_colorsCount:n.length,u_distortion:r,u_swirl:i,u_grainMixer:a,u_grainOverlay:o,u_fit:Dd[s],u_rotation:c,u_scale:l,u_offsetX:f,u_offsetY:p,u_originX:u,u_originY:d,u_worldWidth:m,u_worldHeight:h};return(0,Z.jsx)(Ud,{...g,speed:e,frame:t,fragmentShader:Md,uniforms:_})},Wd),qd=0,Jd=new Set;function Yd(){for(let e of Jd)e()}function Xd(){qd+=1,Yd();let e=!1;return()=>{e||(e=!0,qd=Math.max(0,qd-1),Yd())}}function Zd(){return qd>0}function Qd(e){return Jd.add(e),()=>Jd.delete(e)}var $d=6,ef=2,tf=0,nf=new Set;function rf(e){return nf.add(e),()=>nf.delete(e)}function af(e){tf=Math.max(0,tf+e);for(let e of nf)e()}function of(e){return window.addEventListener(`focus`,e),window.addEventListener(`blur`,e),()=>{window.removeEventListener(`focus`,e),window.removeEventListener(`blur`,e)}}var sf=null;function cf(){if(sf===null)try{sf=!!document.createElement(`canvas`).getContext(`webgl2`)}catch{sf=!1}return sf&&!window.matchMedia(`(prefers-reduced-motion: reduce)`).matches}var lf=class extends X.Component{state={failed:!1};static getDerivedStateFromError(){return{failed:!0}}render(){return this.state.failed?null:this.props.children}},uf=[`#141414`,`#1f1f1f`,`#2b2b2b`,`#363636`],df=[`#f4f4f5`,`#ececec`,`#e3e3e3`,`#d9d9d9`];function ff(){return{rotation:Math.floor(Math.random()*360),frame:Math.random()*6e4}}function pf({className:e,overImage:t=!1}){let n=(0,X.useRef)(null),r=f(),{resolvedTheme:i}=S(),[a,o]=(0,X.useState)(!1),s=(0,X.useSyncExternalStore)(rf,()=>tf,()=>0),c=(0,X.useSyncExternalStore)(Qd,Zd,()=>!1),l=(0,X.useSyncExternalStore)(fr,dr,()=>!1),u=(0,X.useSyncExternalStore)(of,()=>document.hasFocus(),()=>!1),d=!c&&!l&&u,[{rotation:p,frame:m}]=(0,X.useState)(ff);(0,X.useEffect)(()=>{let e=n.current;if(!e||!cf())return;let t=new IntersectionObserver(([e])=>o(!!e?.isIntersecting),{rootMargin:`100px`});return t.observe(e),()=>t.disconnect()},[]),(0,X.useEffect)(()=>(af(1),()=>af(-1)),[]);let h=a&&d&&r!==null&&s<=(r?ef:$d),g=i===`dark`?uf:df;return(0,Z.jsx)(`div`,{ref:n,"data-live":h||void 0,className:N(`pending-shimmer pointer-events-none absolute inset-0`,e),"aria-hidden":!0,
400children:h&&(0,Z.jsx)(lf,{children:(0,Z.jsx)(Kd,{className:N(`absolute inset-0`,t&&`opacity-60`),width:`100%`,height:`100%`,colors:g,distortion:.6,swirl:.2,speed:.6,grainOverlay:i===`dark`?.03:0,rotation:p,frame:m,minPixelRatio:1,maxPixelCount:r?16e4:36e4})})})}function mf(){let{jobs:e,launched:t}=C();return e.length>0||t}function hf(e){let[t,n]=(0,X.useState)([]),r=yi(),i=mf(),a=i||t.length>0?e:null,[o,s]=(0,X.useState)(0),c=(0,X.useRef)(i);(0,X.useEffect)(()=>{i&&!c.current&&s(e=>e+1),c.current=i},[i]);let l=(0,X.useCallback)(async e=>{if(!e)return null;let{data:t}=await E.from(`generations`).select(vo).eq(`id`,e).maybeSingle();return t??null},[]);return(0,X.useEffect)(()=>{if(!e){n([]);return}if(!r)return;let t=!1;return(async()=>{let{data:r}=await E.from(`library_items`).select(se).eq(`workspace_id`,e).is(`url`,null).or(`storage_provider.is.null,storage_provider.neq.local`).order(`created_at`,{ascending:!1}).limit(100),i=(r??[]).filter(e=>!re(e)),a=[...new Set(i.map(e=>e.generation_id).filter(e=>!!e))],o=a.length?(await E.from(`generations`).select(`id, type, model, prompt, status, credits_used, metadata, created_at, completed_at`).in(`id`,a)).data??[]:[],s=new Map(o.map(e=>[e.id,e]));t||n(i.map(e=>({item:e,generation:e.generation_id?s.get(e.generation_id)??null:null})).filter(e=>!e.generation||e.generation.status!==`failed`&&e.generation.status!==`cancelled`&&e.generation.metadata?.cancelledByUser!==!0))})(),()=>{t=!0}},[e,r,o]),pd(a,e=>{if(e.url||re(e)){n(t=>t.filter(t=>t.item.id!==e.id));return}n(t=>t.find(t=>t.item.id===e.id)?t.map(t=>t.item.id===e.id?{...t,item:e}:t):[{item:e,generation:null},...t]),e.generation_id&&l(e.generation_id).then(t=>{t&&n(n=>n.map(n=>n.item.id===e.id?{...n,generation:t}:n))})}),fd(a,e=>{let t=e.status===`failed`||e.status===`cancelled`||e.metadata?.cancelledByUser===!0;n(n=>t?n.filter(t=>t.item.generation_id!==e.id):n.map(t=>t.item.generation_id===e.id?{...t,generation:e}:t))}),t}function gf(e){let[t,n]=(0,X.useState)([]),r=(0,X.useRef)(Date.now()),i=(0,X.useRef)(new Set);return(0,X.useEffect)(()=>{n([]),i.current.clear(),r.current=Date.now()},[e]),fd(mf()?e:null,e=>{if(e.status!==`failed`||i.current.has(e.id))return;let t=e.created_at?Date.parse(e.created_at):NaN;!Number.isFinite(t)||t<r.current||n(t=>t.some(t=>t.id===e.id)?t.map(t=>t.id===e.id?e:t):[e,...t])}),{failures:t,dismiss:(0,X.useCallback)(e=>{i.current.add(e),n(t=>t.filter(t=>t.id!==e))},[])}}function _f({generation:e,onDismiss:t,boxClassName:n=`aspect-square rounded-[10px] bg-zinc-100 dark:bg-white/[0.04]`,labelBelow:r=!1}){let i=_d(e.metadata),a=e.type?xf(e.type):`Generation`,o=(0,Z.jsx)(`span`,{className:`text-[12px] font-[440] text-foreground`,children:`Failed`});return(0,Z.jsxs)(`div`,{className:r?`flex flex-col`:void 0,"aria-label":`${a}: ${i}`,children:[(0,Z.jsxs)(`div`,{className:N(`group relative flex items-center justify-center overflow-hidden ring-1 ring-inset ring-black/[0.08] dark:ring-white/[0.08]`,n),children:[(0,Z.jsxs)(`div`,{className:`flex max-w-full flex-col items-center gap-0.5 px-2 text-center`,children:[(0,Z.jsx)(Re,{className:`h-3.5 w-3.5 text-zinc-500 dark:text-zinc-400`,strokeWidth:1.6}),!r&&o,(0,Z.jsx)(`span`,{className:`line-clamp-2 text-[10.5px] leading-tight text-zinc-500 dark:text-zinc-400`,children:i})]}),(0,Z.jsx)(`button`,{type:`button`,"aria-label":`Dismiss`,onClick:()=>t(e.id),className:`absolute right-1 top-1 flex h-4 w-4 items-center justify-center rounded-[4px] [@media(pointer:coarse)]:after:absolute [@media(pointer:coarse)]:after:-inset-3 [@media(pointer:coarse)]:after:content-[''] bg-background/80 text-zinc-500 dark:text-zinc-400 opacity-0 transition-opacity hover:text-foreground focus-visible:opacity-100 group-hover:opacity-100 [@media(hover:none)]:opacity-100`,children:(0,Z.jsx)(_t,{className:`h-2.5 w-2.5`,strokeWidth:2})})]}),r&&(0,Z.jsx)(`span`,{className:`mt-0.5 truncate`,children:o})]})}function vf(){return(0,X.useCallback)(async e=>{try{let{jobs:t}=await k.post(`/api/generations/cancel`,{ids:[e]}),n=t?.[0];if(!n)return H.error(`Could not stop that`),!1;if(n.status===`succeeded`||n.status===`failed`)return H(`It had already finished`),!1;if(n.status===`running`&&n.kind!==`generation`)return H(`It is too far along to stop`),!1;let r=typeof n.note==`string`&&n.note.includes(`credits come back`);return H(n.refunded?`Stopped. Credits refunded.`:n.status===`running`?r?`Stopped. Credits come back shortly.`:`Stopped. It had already started, so credits may not come back.`:`Stopped`),!0}catch{return H.error(`Could not stop that`),!1}},[])}function yf({boxClassName:e,labelBelow:t}={}){let{activeWorkspaceId:n}=Nt(),r=hf(n),i=vf();return r.length===0?null:(0,Z.jsx)(Z.Fragment,{children:r.map(({item:n,generation:r})=>(0,Z.jsx)(Cf,{item:n,generation:r,onCancel:i,boxClassName:e,labelBelow:t},n.id))})}function bf(e){if(!e)return[];let t=e.metadata??{},n=t.settings??{},r=e=>t[e]??n[e],i=[],a=Zu(t);a?i.push({label:`Edit`,value:Qu(a,[],`running`)}):e.type&&i.push({label:`Type`,value:xf(e.type)}),e.model&&ru(t)&&i.push({label:`Model`,value:tu(e.model)}
400);let o=r(`aspectRatio`)??r(`aspect_ratio`);o&&i.push({label:`Ratio`,value:String(o)});let s=e.type===`image`?r(`imageResolution`):r(`resolution`)??r(`imageResolution`);s&&i.push({label:`Resolution`,value:String(s)});let c=r(`duration`);c&&i.push({label:`Duration`,value:`${c}s`});let l=r(`generateAudio`);if(typeof l==`boolean`&&i.push({label:`Audio`,value:l?`With sound`:`No sound`}),e.credits_used){let t=Number(e.credits_used);i.push({label:`Cost`,value:`${t.toLocaleString(void 0,{maximumFractionDigits:2})} ${t===1?`credit`:`credits`}`})}return i}function xf(e){let t=e.replace(/[_-]+/g,` `);return t.charAt(0).toUpperCase()+t.slice(1).toLowerCase()}function Sf(e){let t=e?.metadata??{},n=[],r=(e,t)=>{typeof t==`string`&&t.trim()?n.push({role:e,url:t}):Array.isArray(t)&&t.forEach(t=>{typeof t==`string`&&t.trim()&&n.push({role:e,url:t})})};return r(`From`,t.sourceImage),r(`From`,t.sourceImages),r(`From`,t.sourceVideoThumbnail??t.sourceVideo),r(`Reference`,t.referenceImage),r(`Reference`,t.sourceVideos),r(`End frame`,t.endImage),n}function Cf({item:e,generation:t,onCancel:n,boxClassName:r=`aspect-square rounded-[10px] bg-zinc-100 dark:bg-white/[0.04]`,labelBelow:i=!1}){let[a,o]=(0,X.useState)(!1),s=b(),c=async e=>{let n=t?.metadata?.sourceItemId;if(typeof n==`string`&&n){s({href:`/app/library/${n}`});return}try{let t=(await k.post(`/api/library/resolve-media`,{urls:[e]})).resolved?.[0]?.itemId;if(t){s({href:`/app/library/${t}`});return}H(`That file is no longer in the library`)}catch{H.error(`Could not open that file`)}},l=bf(t),u=Sf(t),d=Zu(t?.metadata),f=d?null:t?.prompt?.trim()??e.title?.trim(),p=(0,Z.jsxs)(`span`,{className:`text-[12px] font-[400] text-zinc-500 dark:text-zinc-400`,children:[d?Qu(d,[],`running`):`Generating`,(0,Z.jsxs)(`span`,{className:`pending-dots`,"aria-hidden":!0,children:[(0,Z.jsx)(`i`,{children:`.`}),(0,Z.jsx)(`i`,{children:`.`}),(0,Z.jsx)(`i`,{children:`.`})]})]});return(0,Z.jsxs)(`div`,{className:i?`flex flex-col`:void 0,children:[(0,Z.jsxs)(`div`,{className:N(`group relative flex items-center justify-center overflow-hidden`,r),children:[u[0]?(0,Z.jsx)(`img`,{src:J(u[0].url),alt:``,"aria-hidden":!0,onError:e=>{e.currentTarget.style.display=`none`},className:`pointer-events-none absolute inset-0 h-full w-full scale-110 object-cover opacity-40 blur-md`}):null,(0,Z.jsx)(pf,{overImage:!!u[0]}),!i&&(0,Z.jsx)(`span`,{className:`relative`,children:p}),(0,Z.jsxs)(Nu,{children:[(0,Z.jsx)(Pu,{asChild:!0,children:(0,Z.jsx)(`button`,{type:`button`,"aria-label":`Generation details`,className:`absolute bottom-1.5 left-1.5 z-10 flex h-6 w-6 items-center justify-center rounded-full [@media(pointer:coarse)]:after:absolute [@media(pointer:coarse)]:after:-inset-2 [@media(pointer:coarse)]:after:content-[''] text-zinc-400 opacity-0 transition-opacity hover:bg-zinc-100 hover:text-foreground group-hover:opacity-100 focus-visible:opacity-100 data-[state=open]:opacity-100 data-[state=open]:bg-zinc-100 data-[state=open]:text-foreground [@media(hover:none)]:opacity-100 dark:text-zinc-500 dark:hover:bg-white/[0.06] dark:hover:text-foreground dark:data-[state=open]:bg-white/[0.06] dark:data-[state=open]:text-foreground`,children:(0,Z.jsx)(Je,{size:13,strokeWidth:1.6})})}),(0,Z.jsxs)(Iu,{side:`top`,align:`start`,sideOffset:6,className:`w-[260px] max-w-[calc(100vw-2rem)] p-0`,children:[(0,Z.jsxs)(`div`,{className:`max-h-[300px] overflow-y-auto scrollbar-thin px-2.5 pt-2.5`,children:[u.length>0&&(0,Z.jsx)(`div`,{className:`mb-2 flex flex-wrap gap-1.5`,children:u.map((e,t)=>(0,Z.jsx)(`button`,{type:`button`,"aria-label":`Open the ${e.role.toLowerCase()}`,onClick:()=>void c(e.url),className:`block h-12 w-12 shrink-0 overflow-hidden rounded-[6px] bg-zinc-100 transition-opacity duration-100 hover:opacity-80 dark:bg-white/[0.06]`,children:(0,Z.jsx)(`img`,{src:J(e.url),alt:``,onError:e=>{e.currentTarget.style.visibility=`hidden`},className:`h-full w-full object-cover`})},`${e.url}-${t}`))}),l.length>0&&(0,Z.jsx)(`dl`,{className:`grid grid-cols-[56px_1fr] items-start gap-x-2 gap-y-1.5 text-[12px] font-[400] leading-[18px]`,children:l.map(e=>(0,Z.jsxs)(X.Fragment,{children:[(0,Z.jsx)(`dt`,{className:`text-zinc-500 dark:text-zinc-400`,children:e.label}),(0,Z.jsx)(`dd`,{className:`break-words text-foreground`,children:e.value})]},e.label))}),f&&(0,Z.jsxs)(`div`,{className:`mt-2.5 text-[12px] font-[400]`,children:[(0,Z.jsx)(`div`,{className:`text-zinc-500 dark:text-zinc-400`,children:`Prompt`}),(0,Z.jsx)(`div`,{className:`mt-0.5 whitespace-pre-wrap break-words text-foreground`,children:f})]}),l.length===0&&!f&&u.length===0&&(0,Z.jsx)(`div`,{className:`text-[12px] text-zinc-500 dark:text-zinc-400`,children:`No details yet.`})]}),t&&(0,Z.jsx)(`div`,{className:`px-2.5 pb-2.5 pt-1.5`,children:(0,Z.jsx)(`button`,{type:`button`,disabled:a,onClick:async()=>{o(!0),await n(t.id)||o(!1)},className:`block text-[12px] font-[400] leading-[18px] text-zinc-500 transition-colors duration-100 hover:text-foreground active:text-foreground disabled:opacity-40 dark:text-zinc-400 dark:hover:text-white max-md:flex max-md:h-10 max-md:items-center max-md:text-[13.5px]`,children:a?`Cancelling`:`Cancel`})})]})]})]}),i&&(0,Z.jsx)(`span`,{className:`mt-0.5 truncate`,children:p})]})}function wf(e){return Math.min(2.6,Math.max(.45,e))}function Tf(e){let t=e.storage_metadata??{},n=e.metadata??{},r=Number(n.width)||Number(t.width),i=Number(n.height)||Number(t.height);if(r>0&&i>0)return wf(r/i);let a=t.aspectRatio;if(typeof a==`string`){let e=a.match(/^(\d+(?:\.\d+)?)[:/](\d+(?:\.\d+)?)$/);if(e&&Number(e[2])>0)return wf(Number(e[1])/Number(e[2]))}return null}function Ef(e,t){return t?wf(t):Tf(e)||(Qn(e)===`document`?.77:1)}function Df(e){let t=e.filter(e=>Qn(e)===`audio`);return t.length===0||t.length===e.length?e:[...e.filter(e=>Qn(e)!==`audio`),...t]}
400var Of={normal:{perRow:2,rowMax:640,single:560,wide:null,label:`Large`},compact:{perRow:3,rowMax:400,single:400,wide:720,label:`Small`}};function kf(e,t){let n=[];for(let r=0;r<e.length;r+=t)n.push(e.slice(r,r+t));return n.length>1&&n[n.length-1].length===1&&n[n.length-2].push(...n.pop()),n}function Af(e,t){return t.wide===null&&e>1?`calc(${e.toFixed(4)} * min(744px, 80dvh))`:`${Math.round(e*t.single)}px`}var jf=`feed-tile-size`,Mf=`feed-updates`;function Nf(){try{return localStorage.getItem(Mf)===`on`}catch{return!1}}function Pf(){try{return localStorage.getItem(`feed-tile-size`)===`compact`?`compact`:`normal`}catch{return`normal`}}var Ff=9e4,If=new Set([`completed`,`succeeded`,`failed`,`cancelled`,`expired`]),Lf=e=>`feed-ended:${e}`,Rf=e=>e===`failed`||e===`cancelled`;function zf(e){try{let t=localStorage.getItem(Lf(e));return t?JSON.parse(t):null}catch{return null}}function Bf(e,t){if(!(!Object.keys(t.g).length&&!Object.keys(t.r).length&&!Object.keys(t.o).length))try{let n=zf(e)??{g:{},r:{},o:{}},r=e=>Object.from
400Entries(Object.entries(e).slice(-300));localStorage.setItem(Lf(e),JSON.stringify({g:r({...n.g,...t.g}),r:r({...n.r,...t.r}),o:r({...n.o,...t.o})}))}catch{}}var Vf=new Set([`generation`,`render`,`dub`,`transcription`,`store_import`]),Hf=2e4,Uf=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i,Wf=`job_id, status, quality, error_message, completed_at, format:payload->>format, frames:payload->>durationInFrames, fps:payload->>fps, width:payload->>width, height:payload->>height`;function Gf(e){if(typeof e!=`string`)return null;let t=e.match(/^(\d+(?:\.\d+)?)[:/](\d+(?:\.\d+)?)$/);return t&&Number(t[2])>0?wf(Number(t[1])/Number(t[2])):null}function Kf(e){if(!Number.isFinite(e)||e<=0)return null;let t=Math.max(1,Math.round(e));return`${Math.floor(t/60)}:${String(t%60).padStart(2,`0`)}`}function qf(e){return typeof e!=`string`&&typeof e!=`number`?null:String(e).trim()||null}function Jf(e,t){if(t===`image`||t===`video`||t===`audio`)return t;if(e?.type===`image`||e?.type===`video`)return e.type;if(!e)return`image`;let n=Il(e);return n===`image`||n===`video`?n:`audio`}var Yf={low:`Low`,medium:`Medium`,high:`High`,xhigh:`Extra high`,max:`Max`};function Xf(e){return typeof e==`string`&&Yf[e]?`${Yf[e]} quality`:null}function Zf(e,t){let n=e?.metadata??{},r=n.settings??{},i=e=>n[e]??r[e],a=Number(i(`duration`));return{model:e?.model&&ru(n)?tu(e.model):null,shape:t===`audio`?null:qf(i(`aspectRatio`)??i(`aspect_ratio`)),resolution:qf(t===`image`?i(`imageResolution`):i(`resolution`)??i(`imageResolution`)),quality:t===`image`?Xf(i(`imageQuality`)):null,length:t!==`image`&&a>0?`${Math.round(a)}s`:null,credits:Number(e?.credits_used)||0}}function Qf(e){let t=t=>{let n=[...new Set(e.map(e=>e[t]).filter(e=>!!e))];return n.length===0||n.length>3?null:n.join(` / `)},n=e.reduce((e,t)=>e+t.credits,0);return[t(`model`),t(`shape`),t(`resolution`),t(`quality`),t(`length`),n>0?`${ko(n)} credits`:null].filter(e=>!!e)}function $f(e,t,n){let r=t?.metadata??{},i=r.settings??{},a=e=>r[e]??i[e],o=Jf(t,n?.file_type),s=qf(a(`aspectRatio`)??a(`aspect_ratio`)),c=t?.status===`failed`||t?.status===`cancelled`,l=r.cancelledByUser===!0||c&&(t?.status===`cancelled`||r.errorCode===`USER_CANCELLED`),u=c&&!l,d=n?.storage_metadata?.aspectRatio;return{jobId:e,kind:Zu(t?.metadata)??`generation`,shows:`tile`,stoppable:!0,state:l?`stopped`:u?`failed`:`running`,media:o,ratio:o===`audio`?2:Gf(s)??Gf(d)??(o===`video`?16/9:1),details:Qf([Zf(t,o)]),prompt:Zu(t?.metadata)?null:t?.prompt?.trim()||null,reason:u?_d(t?.metadata):null,from:Sf(t)[0]?.url??null}}function ep(e,t){let n=vr[Y(t.format)?t.format:`mp4`],r=n.fileType===`audio`?`audio`:n.fileType===`image`?`image`:`video`;return{jobId:e,kind:`render`,shows:`tile`,stoppable:(t.stoppable??!0)&&!e.startsWith(`desktop_`),state:t.state,media:r,ratio:r===`audio`?2:t.ratio&&t.ratio>0?wf(t.ratio):16/9,details:[r===`video`&&t.quality?t.quality===`4k`?`4K`:t.quality:null,n.extension.toUpperCase(),Kf(t.seconds)].filter(e=>!!e),prompt:null,reason:t.state===`failed`?t.reason?.trim()||`The render failed`:null,from:null}}function tp(e,t,n){return{jobId:e,kind:t,shows:`line`,stoppable:!0,state:n,media:`video`,ratio:16/9,details:[],prompt:null,reason:null,from:null}}function np(e,t){return t.status===`completed`||t.status===`expired`||t.pictures||t.status===`failed`&&(t.error===`Cancelled`||t.error===`Stopped`)?null:ep(e,{stoppable:!1,state:t.status===`failed`?`failed`:`running`,quality:t.quality,format:t.format,ratio:t.aspect??null,seconds:t.seconds??0,reason:t.error??null})}function rp(e,t,n){let r=hf(e),i=mf(),{jobs:a}=C(),o=(0,X.useMemo)(()=>JSON.stringify([...new Set(t)].sort()),[t]),s=(0,X.useMemo)(()=>a.map(e=>e.job_id).sort().join(`,`),[a]),[c,l]=(0,X.useState)(()=>new Map),[u,d]=(0,X.useState)(()=>new Map),[f,p]=(0,X.useState)(()=>new Map),[h,g]=(0,X.useState)(0),[v,y]=(0,X.useState)(0),b=(0,X.useRef)(new Set),x=(0,X.useRef)(null),S=(0,X.useRef)(null);(0,X.useEffect)(()=>()=>{S.current&&clearTimeout(S.current),x.current&&clearTimeout(x.current)},[]);let w=(0,X.useRef)(!1);(0,X.useEffect)(()=>{let e=()=>{!w.current||document.visibilityState!==`visible`||!m()||(w.current=!1,y(e=>e+1))};document.addEventListener(`visibilitychange`,e);let t=_(t=>{t&&e()});return()=>{document.removeEventListener(`visibilitychange`,e),t()}},[]);let T=(0,X.useCallback)(()=>{x.current&&clearTimeout(x.current),x.current=setTimeout(()=>g(Date.now()),91e3)},[]);return(0,X.useEffect)(()=>{let t=e?zf(e):null;
400b.current=new Set(t?[...Object.keys(t.g),...Object.keys(t.r),...Object.keys(t.o)]:[]),l(new Map(t?Object.entries(t.g):[])),d(new Map(t?Object.entries(t.r):[])),p(new Map(t?Object.entries(t.o):[]))},[e]),(0,X.useEffect)(()=>{let t=JSON.parse(o).filter(e=>!b.current.has(e));if(!e||t.length===0)return;let n=!1;return(async()=>{let r=new Map,i=new Map,a=!1;for(let e=0;e<t.length;e+=100){let n=t.slice(e,e+100),o=n.filter(e=>Uf.test(e)),[s,c]=await Promise.all([o.length?E.from(`generations`).select(vo).in(`id`,o):{data:[]},E.from(`export_history`).select(Wf).in(`job_id`,n)]);(`error`in s&&s.error||c.error)&&(a=!0);for(let e of s.data??[])r.set(e.id,e);for(let e of c.data??[])i.set(e.job_id,e)}let o=t.filter(e=>!r.has(e)&&!i.has(e)),s=new Map;for(let e=0;e<o.length;e+=20){let t=await k.get(`/api/jobs?ids=${o.slice(e,e+20).join(`,`)}`).catch(()=>null);t||(a=!0);for(let e of t?.jobs??[])s.set(e.job_id,{kind:e.kind,status:e.status})}if(n)return;let c=!1;for(let e of t){let t=r.get(e)?.status??i.get(e)?.status??s.get(e)?.status;(t===`completed`||t===`expired`)&&(c=!0),(t?If.has(t):!a)&&b.current.add(e)}l(e=>new Map([...e,...r])),d(e=>new Map([...e,...i])),p(e=>new Map([...e,...s])),Bf(e,{g:Object.fromEntries([...r].filter(([,e])=>Rf(e.status))),r:Object.fromEntries([...i].filter(([,e])=>Rf(e.status))),o:Object.fromEntries([...s].filter(([,e])=>Rf(e.status)))}),g(Date.now()),c&&T(),[...s.values()].some(e=>!If.has(e.status)&&!Vf.has(e.kind))&&(S.current&&clearTimeout(S.current),S.current=setTimeout(()=>{S.current=null,document.visibilityState===`visible`&&m()?y(e=>e+1):w.current=!0},Hf))})(),()=>{n=!0}},[e,o,s,v,T]),fd(i||r.length>0?e:null,e=>{l(t=>t.has(e.id)?new Map(t).set(e.id,e):t),e.status===`completed`&&T()}),(0,X.useMemo)(()=>{let e=new Map,t=JSON.parse(o);if(t.length===0)return e;let i=new Map;for(let e of r)e.item.generation_id&&i.set(e.item.generation_id,e);let s=new Map;for(let e of n)e.agentJobId&&s.set(e.agentJobId,e);let l=new Map(a.map(e=>[e.job_id,e.kind])),d=e=>!!e&&h-Date.parse(e)<Ff;for(let n of t){let t=i.get(n),r=c.get(n)??t?.generation??null;if(t||r){if(!t&&r?.status===`completed`&&!d(r.completed_at))continue;e.set(n,$f(n,r,t?.item??null));continue}let a=u.get(n);if(a){if((a.status===`completed`||a.status===`expired`)&&!d(a.completed_at))continue;let t=Number(a.width),r=Number(a.height);e.set(n,ep(n,{state:a.status===`failed`?a.error_message===`Cancelled`?`stopped`:`failed`:`running`,quality:a.quality,format:a.format,ratio:t>0&&r>0?t/r:null,seconds:Number(a.frames)/(Number(a.fps)||30),reason:a.error_message}));continue}let o=s.get(n);if(o){let t=np(n,o);t&&e.set(n,t);continue}let p=f.get(n);if(p){if(p.status===`succeeded`)continue;let t=p.status===`failed`?`failed`:p.status===`cancelled`?`stopped`:`running`;p.kind===`render`?e.set(n,ep(n,{state:t,quality:null,format:null,ratio:null,seconds:0,reason:null})):p.kind===`generation`?e.set(n,{...$f(n,null,null),state:t,reason:t===`failed`?`Something went wrong`:null}):e.set(n,tp(n,p.kind,t));continue}let m=l.get(n);m===`generation`?e.set(n,$f(n,null,null)):m===`render`?e.set(n,ep(n,{state:`running`,quality:null,format:null,ratio:null,seconds:0,reason:null})):m&&e.set(n,tp(n,m,`running`))}return e},[o,r,c,u,f,n,a,h])}var ip=`eversince:clock`,ap=15;function op(){try{let e=localStorage.getItem(ip);if(e===`12`||e===`24`)return e}catch{}try{return new Intl.DateTimeFormat(void 0,{hour:`numeric`}).resolvedOptions().hour12?`12`:`24`}catch{return`24`}}function sp(e,t){let n=e.match(/^([01]\d|2[0-3]):([0-5]\d)$/);if(!n)return e;let r=Number(n[1]);if(t===`24`)return e;let i=r<12?`AM`:`PM`;return`${r%12==0?12:r%12}:${n[2]} ${i}`}function cp(){let e=[];for(let t=0;t<1440;t+=ap)e.push(`${String(Math.floor(t/60)).padStart(2,`0`)}:${String(t%60).padStart(2,`0`)}`);return e}function lp(e){let t=e.trim().toLowerCase().replace(/\s+/g,``),n=t.match(/^(\d{1,2})(?::?(\d{2}))?(am|pm)?$/);if(!n)return null;let r=Number(n[1]),i=n[2]?Number(n[2]):0;if(i>59)return null;if(n[3]){if(r<1||r>12)return null;r=r%12+(n[3]===`pm`?12:0)}else if(r>23)return t.length===4&&!n[2]?lp(`${t.slice(0,2)}:${t.slice(2)}`):null;return`${String(r).padStart(2,`0`)}
400:${String(i).padStart(2,`0`)}`}function up({value:e,onChange:t,className:n,bare:r}){let[i,a]=(0,X.useState)(!1),[o,s]=(0,X.useState)(`24`),[c,l]=(0,X.useState)(``),u=(0,X.useRef)(null);(0,X.useEffect)(()=>{s(op());let e=()=>s(op());return window.addEventListener(Qr,e),()=>window.removeEventListener(Qr,e)},[]);let d=e=>{s(e),si(ip,e)},f=(0,X.useMemo)(()=>cp(),[]);(0,X.useEffect)(()=>{if(!i)return;let t=e&&f.includes(e)?e:`09:00`,n=requestAnimationFrame(()=>{u.current?.querySelector(`[data-time="${t}"]`)?.scrollIntoView({block:`center`})});return()=>cancelAnimationFrame(n)},[i,e,f]);let p=()=>{let e=lp(c);l(``),e&&(t(e),a(!1))};return(0,Z.jsxs)(hn,{open:i,onOpenChange:a,children:[(0,Z.jsx)(dn,{asChild:!0,children:(0,Z.jsxs)(`button`,{type:`button`,className:N(r?`flex w-full items-center text-left text-[12px] font-[400] tabular-nums`:`flex h-7 items-center gap-1.5 rounded-full px-2 text-[12px] font-[400] tabular-nums transition-colors max-md:h-9 max-md:text-[13.5px] hover:bg-zinc-100 data-[state=open]:bg-zinc-100 dark:hover:bg-white/[0.06] dark:data-[state=open]:bg-white/[0.06]`,r?e?``:`text-zinc-400 dark:text-zinc-500`:e?`text-foreground`:`text-zinc-400 dark:text-zinc-500`,n),children:[!r&&(0,Z.jsx)(xe,{className:`h-3 w-3 flex-shrink-0 text-zinc-400 dark:text-zinc-500`,strokeWidth:1.6}),e?sp(e,o):r?`None`:`Set a time`]})}),(0,Z.jsxs)(mn,{align:`start`,className:`w-[190px] max-md:w-[220px]`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-1.5 px-1 pb-1.5`,children:[(0,Z.jsx)(`input`,{autoFocus:typeof window<`u`&&!window.matchMedia(`(pointer: coarse)`).matches,value:c,onChange:e=>l(e.target.value),onKeyDown:e=>{e.stopPropagation(),e.key===`Enter`&&p(),e.key===`Escape`&&a(!1)},placeholder:o===`12`?`5 pm`:`17:00`,className:`h-7 min-w-0 flex-1 rounded-[8px] border border-border bg-transparent px-2 text-[12px] max-md:h-10 max-md:text-[14px] font-[400] tabular-nums outline-none placeholder:text-zinc-400 dark:border-[#2f2f2f]`}),(0,Z.jsx)(`div`,{className:`flex flex-shrink-0 items-center gap-0.5`,children:[`12`,`24`].map(e=>(0,Z.jsx)(`button`,{type:`button`,onClick:()=>d(e),className:N(`h-7 rounded-full px-2 text-[12px] font-[400] tabular-nums transition-colors max-md:h-10 max-md:px-3 max-md:text-[13.5px]`,o===e?`bg-zinc-100 text-foreground dark:bg-white/[0.08]`:`text-zinc-500 hover:text-foreground dark:text-zinc-400`),children:e},e))})]}),(0,Z.jsx)(`div`,{ref:u,className:`max-h-56 overflow-y-auto [scrollbar-width:thin]`,children:f.map(n=>(0,Z.jsx)(G,{"data-time":n,onSelect:()=>t(n),className:N(`tabular-nums`,n===e&&`bg-zinc-100 dark:bg-white/[0.08]`),children:sp(n,o)},n))}),e&&(0,Z.jsx)(G,{onSelect:()=>t(null),className:`mt-1`,children:`Clear`})]})]})}var dp=[{name:`Instagram`,icon:`instagram`},{name:`TikTok`,icon:`tiktok`},{name:`YouTube`,icon:`youtube`},{name:`X`,icon:`x`},{name:`LinkedIn`,glyph:`Linkedin`},{name:`Facebook`,icon:`facebook`},{name:`Threads`,icon:`threads`},{name:`Pinterest`,icon:`pinterest`},{name:`Twitch`,icon:`twitch`},{name:`Spotify`,icon:`spotify`},{name:`Newsletter`,glyph:`Mail`},{name:`Website`,glyph:`Globe`}];function fp(e){let t=e.trim().toLowerCase();return dp.find(e=>e.name.toLowerCase()===t)}var pp={Linkedin:F,Mail:Se,Globe:Ce,Rss:B,Send:Ve,MessageCircle:Ye};function mp({option:e,channel:t,className:n}){let r=(t&&!e.icon&&!e.glyph?fp(e.name??``):void 0)??e,i=r.glyph??(r.icon?.startsWith(`glyph:`)?r.icon.slice(6):null);if(i){let e=pp[i];if(e)return(0,Z.jsx)(e,{className:N(`h-3 w-3 flex-shrink-0`,n),strokeWidth:1.8})}if(r.icon&&!r.icon.startsWith(`glyph:`)){let e=`/platforms/${r.icon}.svg`;return(0,Z.jsx)(`span`,{"aria-hidden":!0,className:N(`inline-block h-3 w-3 flex-shrink-0 bg-zinc-800 dark:bg-zinc-200`,n),style:{maskImage:`url("${e}")`,WebkitMaskImage:`url("${e}")`,maskSize:`contain`,WebkitMaskSize:`contain`,maskRepeat:`no-repeat`,WebkitMaskRepeat:`no-repeat`,maskPosition:`center`,WebkitMaskPosition:`center`}})}return t?(0,Z.jsx)(`span`,{className:N(`flex h-3 w-3 flex-shrink-0 items-center justify-center rounded-[3px] bg-zinc-200 text-[8px] font-[560] uppercase leading-none text-zinc-600 dark:bg-white/20 dark:text-zinc-300`,n),children:(e.name??`?`).trim().charAt(0)}):(0,Z.jsx)(`span`,{className:N(`h-1.5 w-1.5 flex-shrink-0 rounded-full`,Ts(e.color),n),style:Es(e.color)})}function hp(e,t){let n={};for(let r of e)r.planOf===t&&(r.plan===`time`||r.plan===`channel`||r.plan===`status`)&&(n[r.plan]=r);return n}var gp=`truncate text-[12px] font-[400]`,_p=`truncate text-[11px] font-[380] tabular-nums text-zinc-500 dark:text-zinc-400`;function vp(e){let t=e.match(/^(\d{4})-(\d{2})-(\d{2})/);return(t?new Date(Number(t[1]),Number(t[2])-1,Number(t[3])):new Date(e)).toLocaleDateString(`en-US`,{month:`short`,day:`numeric`,year:`numeric`})}function yp({property:e,value:t,onChange:n,onAddOption:r,onRemoveOption:i,quiet:a,facts:o}){let[s,c]=(0,X.useState)(!1),[l,u]=(0,X.useState)(``),[d,f]=(0,X.useState)(null),p=e=>e.stopPropagation();if(e.type===`checkbox`)return(0,Z.jsx)(`span`,{onClick:p,className:`flex items-center`,children:(0,Z.jsx)(Yn,{checked:t===!0,onCheckedChange:e=>n(e===!0)})});if(e.plan===`time`)return(0,Z.jsx)(`span`,{onClick:p,className:`block`,children:(0,Z.jsx)(up,{value:typeof t==`string`&&t?t:null,onChange:e=>n(e),bare:a,className:a?void 0:`-ml-1.5`})});if(e.type===`select`||e.type===`multi_select`){let s=e.type===`select`?typeof t==`string`?[t]:[]:Array.isArray(t)?t:[],c=e.options.filter(e=>s.includes(e.id)),l=c.map(e=>e.name),u=new Set(e.options.map(e=>e.name.toLowerCase())),m=e.plan===`channel`?dp.filter(e=>!u.has(e.name.toLowerCase())):[];return(0,Z.jsx)(`span`,{onClick:p,children:(0,Z.jsxs)(hn,{children:[(0,Z.jsx)(dn,{asChild:!0,children:(0,Z.jsxs)(`button`,{type:`button`,className:N(o?_p:gp,`flex w-full items-center gap-1.5`,l.length&&!a&&!o&&`text-foreground`,bp(e)?`justify-center`:`text-left`),children:[c[0]&&!(o&&e.plan!==`channel`)&&(0,Z.jsx)(mp,{option:c[0],channel:e.plan===`channel`}),l.length?(0,Z.jsx)(`span`,{className:`truncate`,children:l.join(`, `)}):a?Sp:xp]})}),(0,Z.jsxs)(mn,{align:`start`,className:`max-h-64 overflow-y-auto`,children:[e.options.map(t=>{let r=s.includes(t.id);return(0,Z.jsxs)(G,{className:`group/option`,onSelect:i=>{e.type===`multi_select`&&i.preventDefault(),e.type===`select`?n(r?null:t.id):n(r?s.filter(e=>e!==t.id):[...s,t.id])},children:[(0,Z.jsx)(mp,{option:t,channel:e.plan===`channel`,className:`mr-2`}),(0,Z.jsx)(`span`,{className:`flex-1 truncate`,children:t.name}),r&&(0,Z.jsx)(V,{className:N(`ml-2`,`h-3 w-3 max-md:h-3.5 max-md:w-3.5 flex-shrink-0 text-foreground`),strokeWidth:2}),i&&(0,Z.jsx)(`span`,{role:`button`,tabIndex:-1,"aria-label":`Remove ${t.name}`,onClick:e=>{e.preventDefault(),e.stopPropagation(),i(t.id)},className:`ml-1 flex h-4 w-4 flex-shrink-0 items-center justify-center rounded-[4px] relative [@media(pointer:coarse)]:after:absolute [@media(pointer:coarse)]:after:-inset-2 [@media(pointer:coarse)]:after:content-[''] text-zinc-300 opacity-0 transition-opacity hover:bg-zinc-100 hover:text-foreground group-hover/option:opacity-100 [@media(hover:none)]:h-6 [@media(hover:none)]:w-6 [@media(hover:none)]:opacity-100 dark:text-zinc-600 dark:hover:bg-white/10`,children:(0,Z.jsx)(_t,{className:`h-2.5 w-2.5`,strokeWidth:2.4})})]},t.id)}),r&&m.length>0&&(0,Z.jsx)(Z.Fragment,{children:m.map(t=>(0,Z.jsxs)(G,{className:`text-zinc-500 dark:text-zinc-400`,onSelect:i=>{i.preventDefault(),r(t.name).then(t=>{t&&(e.type===`select`?n(t):n([...s,t]))})},children:[(0,Z.jsx)(mp,{option:t,channel:!0,className:`mr-2`}),(0,Z.jsx)(`span`,{className:`flex-1 truncate`,children:t.name})]},t.name))}),r&&(d===null?(0,Z.jsxs)(G,{className:`text-zinc-500 dark:text-zinc-400`,onSelect:e=>{e.preventDefault(),f(``)},children:[(0,Z.jsx)(gt,{className:`mr-2.5 h-3.5 w-3.5 flex-shrink-0 text-zinc-500 dark:text-zinc-400`,strokeWidth:1.5}),`Custom`]}):(0,Z.jsx)(`div`,{className:`px-1 py-1`,onKeyDown:e=>e.stopPropagation(),children:(0,Z.jsx)(`input`,{autoFocus:!0,value:d,placeholder:e.plan===`channel`?`Name the channel`:`Name it`,onChange:e=>f(e.target.value),onKeyDown:t=>{if(t.key===`Escape`){f(null);return}if(t.key!==`Enter`)return;let i=d.trim();f(null),i&&r(i).then(t=>{t&&(e.type===`select`?n(t):n([...s,t]))})},className:`h-7 w-full rounded-[8px] border border-border bg-transparent px-2 text-[12px] font-[400] outline-none placeholder:text-zinc-400 dark:border-[#2f2f2f]`})}))]})]})})}if(s){let t=()=>{c(!1);let t=l.trim();if(e.type===`number`){let e=t===``?null:Number(t);n(e!==null&&Number.isFinite(e)?e:null)}else n(t||null)};return(0,Z.jsx)(`span`,{onClick:p,className:`block`,children:(0,Z.jsx)(`input`,{autoFocus:!0,t
400ype:e.type===`number`?`number`:e.type===`date`?`date`:`text`,value:l,onChange:e=>u(e.target.value),onBlur:t,onKeyDown:e=>{e.key===`Enter`&&t(),e.key===`Escape`&&c(!1)},className:`w-full rounded border border-border bg-transparent px-1 py-0.5 text-[12px] outline-none dark:border-[#2f2f2f] max-md:h-10 max-md:rounded-lg max-md:px-3 max-md:text-[14px]`})})}let m=t==null||t===``?null:e.type===`date`&&typeof t==`string`?vp(t):String(t);return(0,Z.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),u(t==null?``:String(t)),c(!0)},className:N(o?_p:gp,`block w-full`,m&&!a&&!o?`text-foreground`:``,bp(e)?`text-center`:`text-left`),children:e.type===`url`&&m?(0,Z.jsx)(`a`,{href:m,target:`_blank`,rel:`noreferrer`,onClick:p,className:`underline decoration-zinc-300 underline-offset-2 dark:decoration-zinc-600`,children:m}):m??(a?Sp:xp)})}function bp(e){return e.type!==`text`&&e.type!==`url`}var xp=(0,Z.jsx)(`span`,{className:`text-[11px] font-[380] text-zinc-400 dark:text-zinc-500`,children:`â`}),Sp=(0,Z.jsx)(`span`,{className:`text-zinc-400 dark:text-zinc-500`,children:`None`}),Cp=[{value:`text`,label:`Text`,hint:`Free text`},{value:`number`,label:`Number`,hint:`Numeric value`},{value:`date`,label:`Date`,hint:`Calendar date`},{value:`select`,label:`Select`,hint:`One of a set of options`},{value:`multi_select`,label:`Multi-select`,hint:`Several of a set of options`},{value:`checkbox`,label:`Checkbox`,hint:`On or off`},{value:`url`,label:`URL`,hint:`A link`}];function wp({open:e,onOpenChange:t,onCreate:n}){let[r,i]=(0,X.useState)(``),[a,o]=(0,X.useState)(`text`),[s,c]=(0,X.useState)(``),[l,u]=(0,X.useState)(!1),d=a===`select`||a===`multi_select`,f=r.trim()&&(!d||s.trim()),p=Cp.find(e=>e.value===a)??Cp[0],m=async()=>{if(!(!f||l)){u(!0);try{await n({name:r.trim(),type:a,...d?{options:s.split(`,`).map(e=>e.trim()).filter(Boolean).map(e=>({name:e}))}:{}}),i(``),o(`text`),c(``),t(!1)}finally{u(!1)}}},h=`flex h-9 w-full rounded-lg border border-zinc-200/70 bg-transparent px-3 text-[12px] font-[400] text-foreground outline-none placeholder:text-zinc-400 dark:border-[#2f2f2f] dark:placeholder:text-zinc-500`;return(0,Z.jsx)(wn,{open:e,onOpenChange:t,children:(0,Z.jsxs)(Dn,{className:`sm:max-w-[460px] max-w-[calc(100vw-2rem)]`,children:[(0,Z.jsx)(zn,{className:Pn,children:`New field`}),(0,Z.jsx)(`input`,{autoFocus:!0,value:r,onChange:e=>i(e.target.value),maxLength:40,placeholder:`Field name`,className:N(`mt-4`,h)}),(0,Z.jsxs)(hn,{children:[(0,Z.jsx)(dn,{asChild:!0,children:(0,Z.jsxs)(`button`,{type:`button`,className:N(`mt-1.5 items-center gap-2 text-left`,h),children:[(0,Z.jsx)(`span`,{className:`text-foreground`,children:p.label}),(0,Z.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-[12px] text-zinc-500 dark:text-zinc-400`,children:p.hint}),(0,Z.jsx)(ot,{className:`h-3.5 w-3.5 flex-shrink-0 text-zinc-500 dark:text-zinc-400`,strokeWidth:1.8})]})}),(0,Z.jsx)(mn,{align:`start`,className:`w-[var(--radix-dropdown-menu-trigger-width)] max-w-[calc(100vw-2rem)]`,children:Cp.map(e=>(0,Z.jsxs)(G,{onSelect:()=>o(e.value),children:[(0,Z.jsx)(`span`,{className:`flex-1`,children:e.label}),(0,Z.jsx)(`span`,{className:`pl-3 text-[12px] text-zinc-500 dark:text-zinc-400`,children:e.hint}),a===e.value&&(0,Z.jsx)(V,{className:N(`ml-2`,`h-3 w-3 max-md:h-3.5 max-md:w-3.5 flex-shrink-0 text-foreground`),strokeWidth:2})]},e.value))})]}),d&&(0,Z.jsx)(`input`,{value:s,onChange:e=>c(e.target.value),placeholder:`Options, comma separated: Draft, Review, Approved`,className:N(`mt-1.5`,h)}),(0,Z.jsxs)(`div`,{className:N(In,`mt-5`),children:[(0,Z.jsx)(`button`,{type:`button`,onClick:()=>t(!1),className:Rn,children:`Cancel`}),(0,Z.jsx)(`button`,{type:`button`,onClick:m,disabled:!f||l,className:Fn,children:l?(0,Z.jsx)(ft,{className:`h-3 w-3 animate-spin`,strokeWidth:2}):`Create`})]})]})})}var Tp=(0,X.lazy)(()=>r(()=>import(`./document-viewer-D_rFhRi4.js`).then(e=>({default:e.DocumentViewer})),__vite__mapDeps([30,2,12,4,5,3,11,31,32,33,34,27,35,36,37]))),Ep=(0,X.lazy)(()=>r(()=>import(`./document-editor-5ly0jBP_.js`).then(e=>({default:e.DocumentEditor})),__vite__mapDeps([38,2,12,31,13,3,4,5,1,6,14,32,39,34,40,41,42,43,33,44,45,46,47,48,11,49,50,51,52,53,54,10,17,18,16,55,7,8,9,24,25,27,56,57,58,59,60,61,62,63,35,36,37,64,65,66]))),Dp=Za,Op=N(ce.footButton,`disabled:opacity-40`),kp=ce.footGlyph,Ap=ce.footStroke,jp=`w-[80px] flex-shrink-0 break-words py-[7px] text-[12px] font-[400] leading-[14px] text-zinc-400 dark:text-zinc-500`,Mp=`my-1 rounded-[8px] bg-zinc-100/60 px-3 py-2 text-[12px] font-[400] leading-[18px] text-zinc-700 dark:bg-white/[0.04] dark:text-zinc-300`,Np=`flex h-10 w-10 flex-shrink-0 items-center justify-center rounded-full text-zinc-600 active:bg-zinc-100 dark:text-zinc-300 dark:active:bg-white/[0.06]`,Pp=`flex h-6 w-6 items-center justify-center rounded-full text-zinc-400 transition-colors duration-100 hover:text-foreground dark:text-zinc-500 dark:hover:text-white`,Fp=`flex h-7 w-7 items-center justify-center rounded-full text-zinc-500 transition-[opacity,background-color,color] duration-150 hover:bg-zinc-100 hover:text-foreground dark:text-zinc-400 dark:hover:bg-white/[0.08] dark:hover:text-foreground`,Ip=Qa;function Lp(e){let t=e.storage_metadata??{},n=e.metadata??{},r=t.shape??{},i=Number(r.width)||Number(n.width)||Number(t.width),a=Number(r.height)||Number(n.height)||Number(t.height);return i>0&&a>0?{width:i,height:a}:null}function Rp(e){let t=e.storage_metadata?.thumbnail_url;return typeof t==`string`&&t?t:null}function zp({item:e,hidden:t=!1}){let n=Qn(e),r=n===`image`?Rp(e)??e.url:n===`video`?Xn(e):null,i=`max(env(safe-area-inset-top), env(safe-area-inset-bottom))`;return(0,Z.jsx)(`div`,{className:N(`relative flex-1`,t&&`invisible`),children:(0,Z.jsx)(`div`,{className:`absolute inset-x-0`,style:{to
400p:i,bottom:i},children:r&&(0,Z.jsx)(`img`,{src:J(r),alt:``,decoding:`async`,className:`absolute inset-0 h-full w-full object-contain`,onLoad:()=>(e.id,void 0)})})})}function Bp({on:e,pager:t,locked:n,items:r,index:i,underlay:a,children:o}){if(!e)return(0,Z.jsx)(Z.Fragment,{children:o});let s={start:Math.max(0,i-3),end:Math.min(r.length-1,i+3)};return(0,Z.jsxs)(`div`,{ref:t.ref,className:N(Ba,`min-h-0 w-full flex-1`,n?`overflow-x-hidden`:`overflow-x-auto`),onScroll:t.onScroll,onTouchStart:()=>t.touch(!0),onTouchEnd:e=>{e.touches.length===0&&t.touch(!1)},onTouchCancel:()=>t.touch(!1),children:[s.start>0&&(0,Z.jsx)(`div`,{"aria-hidden":!0,className:`flex-shrink-0`,style:{width:`${s.start*100}%`}}),r.slice(s.start,s.end+1).map((e,t)=>{let n=s.start+t;return(0,Z.jsxs)(`div`,{className:N(Va,`overflow-hidden`),children:[Ha(n,i)&&(0,Z.jsx)(zp,{item:e,hidden:n===i&&!a}),n===i&&(0,Z.jsx)(`div`,{className:`absolute inset-0 flex`,children:o})]},e.id)}),s.end<r.length-1&&(0,Z.jsx)(`div`,{"aria-hidden":!0,className:`flex-shrink-0`,style:{width:`${(r.length-1-s.end)*100}%`}})]})}function Vp({counted:e=!1,openOnComments:t=!1,initialThread:n=null,items:r,current:d,getItemUrl:p,onSelect:m,onClose:h,onDownload:g,onRename:_,onMove:v,onDelete:y,onGenerationCreated:x,onItemCreated:S,onOpenMade:C,suppressEsc:T=!1,currentUserId:E=null,onToggleFavorite:O,onHide:re}){let A=(0,X.useMemo)(()=>r.findIndex(e=>e.id===d),[r,d]),[ie,ae]=(0,X.useState)(null);(0,X.useEffect)(()=>{ae(null)},[d]);let oe=(0,X.useRef)(d);oe.current=d;let j=ie??(A>=0?r[A]:null),M=ur(j),se=w(j?.id),le=j?.is_favorite??!1,[P,F]=(0,X.useState)(le);(0,X.useEffect)(()=>{F(le)},[j?.id,le]);let de=e=>{F(e),O?.(e)},pe=b(),I=_l(j),[me,L]=(0,X.useState)(!1),[he,xe]=(0,X.useState)(``),[Se,Ce]=(0,X.useState)(null),{activeWorkspaceId:we}
400=Nt(),[Te,Ee]=(0,X.useState)(t),De=f(),Oe=(0,X.useRef)(null);r[A]&&Oe.current?.id!==r[A].id&&(Oe.current={id:r[A].id,head:s(r[A].id,`full`),frame:o(r[A].id)}),l(()=>{let e=Zt.current;e&&(Qt.current&&e.readyState>=1&&u(Qt.current,`full`,e.currentTime,e.muted),e.pause(),e.removeAttribute(`src`),e.load())});let Ae=Cn(),[Ne,Pe]=(0,X.useState)(!1),Fe=Ne&&De===!1,R=De===!0,[z,Ie]=(0,X.useState)(t?`comments`:null),[Le,Re]=(0,X.useState)(!0),[B,ze]=(0,X.useState)(null),Be=(0,X.useRef)(null),[Ve,He]=(0,X.useState)(+!!t),Ue=(0,X.useRef)(null);(0,X.useEffect)(()=>{r[A]&&c(`viewer`,{id:r[A].id,kind:Qn(r[A])})},[r,A]);let We=(0,X.useRef)(null);(0,X.useEffect)(()=>()=>{Ue.current!==null&&window.clearTimeout(Ue.current)},[]);let Ke=(0,X.useRef)(z);Ke.current=z;let Ze=(0,X.useRef)(null);(0,X.useEffect)(()=>{if(z||De!==!0)return;let e=document.activeElement;(e&&/^(INPUT|TEXTAREA)$/.test(e.tagName)||e?.isContentEditable)&&e.blur(),window.scrollTo(0,0);let t=Ze.current;if(!t)return;let n=()=>{t.style.display=`none`,t.offsetHeight,t.style.display=``};n();let r=window.setTimeout(n,350);return()=>window.clearTimeout(r)},[z,De]);let $e=Ei(j?`item:${j.id}`:null),[et,nt]=(0,X.useState)(!1),[rt,at]=(0,X.useState)(!1),[ot,dt]=(0,X.useState)(!1),{pickDate:mt,newLabel:ht,dialogs:vt,open:yt}=Uc(()=>void x?.()),[bt,xt]=(0,X.useState)({}),[St,Ct]=(0,X.useState)(null),[wt,Tt]=(0,X.useState)(null),[Et,Dt]=(0,X.useState)(null);(0,X.useEffect)(()=>{if(!j?.generation_id){Dt(null);return}let e=!1;return bo(j.generation_id).then(t=>{e||Dt(t)}).catch(()=>{e||Dt(null)}),()=>{e=!0}},[j?.generation_id]);let[Ot,kt]=(0,X.useState)(null);(0,X.useEffect)(()=>{if(!j?.id){kt(null);return}let e=!1;return Ro({generationId:j.generation_id??null,itemId:j.id}).then(t=>{e||kt(t)}).catch(()=>{e||kt(null)}),()=>{e=!0}},[j?.id,j?.generation_id]);let U=(0,X.useMemo)(()=>!j||!j.url?null:{itemId:j.id,url:j.url,fileName:j.file_name??$n(j).slice(0,40),generation:Et,media:Qn(j),durationSeconds:bt.durationSeconds??(Number(Et?.metadata?.duration)||void 0)},[j,Et,bt.durationSeconds]),W=nl(),jt=Nl({item:U,onCreated:e=>{if(S?.(e),e.edit===`crop`){if(C)return C(e.id);H(`Cropped copy saved to your library`,{duration:4e3})}},onStarted:()=>{x?.()},onInsufficientCredits:(e,t)=>Tt({required:e,available:t})}),Mt=jt.busy===`crop`||jt.busy===`background`?jt.busy:null,Pt=jt.busy===`upscale`,Ft=jt.cropFile,It=()=>void jt.openCropper(),[Lt,Rt]=(0,X.useState)({}),zt=async()=>{Lt.background||await jt.removeBackground()&&Rt(e=>({...e,background:!0}))},Bt=()=>{if(!(Lt.background||Mt===`background`)){if(!ot){dt(!0);return}dt(!1),zt()}},Vt=async()=>{Lt.upscale||await jt.upscale()&&Rt(e=>({...e,upscale:!0}))},[Ht,Ut]=(0,X.useState)(!1),[Wt,Gt]=(0,X.useState)(!1),[Kt,qt]=(0,X.useState)(!1),[Jt,Yt]=(0,X.useState)(null),Xt=(0,X.useRef)(null),Zt=(0,X.useRef)(null),Qt=(0,X.useRef)(null),$t=(0,X.useRef)(null),[en,tn]=(0,X.useState)(!1),[nn,rn]=(0,X.useState)(null),an=(0,X.useRef)(null),[on,sn]=(0,X.useState)([]),[cn,ln]=(0,X.useState)(null),[un,fn]=(0,X.useState)([]),[pn,gn]=(0,X.useState)([]),[_n,vn]=(0,X.useState)(null),[yn,bn]=(0,X.useState)(!1),[xn,Sn]=(0,X.useState)(!1),[wn,Tn]=(0,X.useState)(!1),[En,Dn]=(0,
400X.useState)(!1),[On,kn]=(0,X.useState)(null),{foldersWithPaths:An}=Mc(we),{labels:jn,getItemLabelIds:Mn,setLabelOnItems:Nn,deleteLabel:Pn}=Ec(we),{boards:Fn,calendars:In}=rc(),Ln=Cc(j),{data:Rn=[]}=Vr(At.fields(we)),[zn,Vn]=(0,X.useState)({});(0,X.useEffect)(()=>{Vn({})},[j?.id,j?.metadata]);let[Hn,Un]=(0,X.useState)(null),[K,Wn]=(0,X.useState)(!1),[Gn,Kn]=(0,X.useState)(null),[Yn,Zn]=(0,X.useState)([]),[ir,ar]=(0,X.useState)(null),sr=(0,X.useRef)(null),lr=(0,X.useCallback)(e=>{sr.current&&window.clearTimeout(sr.current),ar(e),e&&(sr.current=window.setTimeout(()=>ar(null),3500))},[]);(0,X.useEffect)(()=>()=>{sr.current&&window.clearTimeout(sr.current)},[]);let[dr,fr]=(0,X.useState)(null),gr=(0,X.useRef)(null),_r=(0,X.useRef)(null),[Y,vr]=(0,X.useState)(1),[yr,br]=(0,X.useState)({x:0,y:0}),xr=(0,X.useRef)(null),Sr=`scale(${Y}) translate(${yr.x}px, ${yr.y}px)`;(0,X.useEffect)(()=>{if(!K)return;let e=()=>{gr.current=null,Wn(!1),fr(e=>(e&&e.w>.01&&e.h>.01&&Kn(e),null))};return window.addEventListener(`pointerup`,e),window.addEventListener(`pointercancel`,e),()=>{window.removeEventListener(`pointerup`,e),window.removeEventListener(`pointercancel`,e)}},[K]),(0,X.useEffect)(()=>{if(!xr.current&&Y===1)return;let e=e=>{let t=xr.current;t&&br({x:t.ox+(e.clientX-t.x)/Y,y:t.oy+(e.clientY-t.y)/Y})},t=()=>{xr.current=null};return window.addEventListener(`mousemove`,e),window.addEventListener(`mouseup`,t),()=>{window.removeEventListener(`mousemove`,e),window.removeEventListener(`mouseup`,t)}},[Y]);let Cr=(0,X.useCallback)(e=>{let t=r[e];t&&m(t.id)},[r,m]),wr=De===!0&&!ie&&A>=0&&r.length>1,Tr=Y!==1||K,Er=Ua({on:wr,index:A,count:r.length,onIndex:Cr}),Dr=(0,X.useRef)(null),Or=(0,X.useRef)(null),[kr,Ar]=(0,X.useState)(!1);(0,X.useEffect)(()=>{if(!kr)return;let e=window.setTimeout(()=>Ar(!1),220);return()=>window.clearTimeout(e)},[kr]);let jr=(0,X.useRef)(null),Mr=e=>Math.hypot(e[0].clientX-e[1].clientX,e[0].clientY-e[1].clientY),Nr=(0,X.useCallback)(e=>{let t=r[A],n=t?Qn(t):null;if(e.touches.length===2&&!K&&(n===`image`||n===`video`)){Dr.current=null,jr.current=null,Or.current={distance:Mr(e.touches),zoom:Y};return}if(e.touches.length===1&&(Or.current=null),e.touches.length===1&&Y>1&&!K&&(jr.current={x:e.touches[0].clientX,y:e.touches[0].clientY,ox:yr.x,oy:yr.y}),Y>1||K||e.touches.length!==1){Dr.current=null;return}Dr.current={x:e.touches[0].clientX,y:e.touches[0].clientY}},[Y,yr,K,r,A]),Pr=(0,X.useCallback)(e=>{let t=Or.current;if(t&&e.touches.length===2){vr(Math.min(6,Math.max(.5,+(t.zoom*Mr(e.touches)/t.distance).toFixed(3))));return}let n=jr.current;n&&e.touches.length===1&&br({x:n.ox+(e.touches[0].clientX-n.x)/Y,y:n.oy+(e.touches[0].clientY-n.y)/Y})},[Y]),Fr=(0,X.useCallback)(()=>{Or.current=null,jr.current=null,Dr.current=null,Y<1.05&&(Ar(!0),vr(1),br({x:0,y:0}))},[Y]),Ir=(0,X.useCallback)(e=>{if(Or.current){e.touches.length<2&&(Or.current=null),Y<1.05&&(Ar(!0),vr(1),br({x:0,y:0}));return}jr.current=null;let t=Dr.current;if(Dr.current=null,!t)return;let n=e.changedTouches[0];if(!n)return;let i=n.clientX-t.x,a=n.clientY-t.y,o=r[A];if(De===!0&&!z&&a>90&&Math.abs(a)>Math.abs(i)*1.5&&o&&Qn(o)!==`document`){h();return}wr||Math.abs(i)<56||Math.abs(a)>Math.abs(i)||Cr(A+(i<0?1:-1))},[Cr,A,r,De,z,h,Y,wr]);(0,X.useEffect)(()=>{let e=e=>{if(yt)return;let t=e.target;if(!(t&&(t.tagName===`INPUT`||t.tagName===`TEXTAREA`||t.isContentEditable)&&e.key!==`Escape`)){if(e.key===`Escape`){if(me||T||Ft)return;if(e.preventDefault(),K||Gn){Wn(!1),Kn(null),fr(null);return}if(Se){Ce(null);return}h()}else if(e.key===`p`||e.key===`P`){if(me||T||Se||Ft)return;e.preventDefault(),O?.(!P)}else if(e.key===`ArrowRight`){if(Ft)return;e.preventDefault(),Cr(A+1)}else if(e.key===`ArrowLeft`){if(Ft)return;e.preventDefault(),Cr(A-1)}}};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[A,Cr,h,me,T,P,O,Se,Ft,K,Gn,yt]);let Lr=j;(0,X.useEffect)(()=>{if(!Lr)return;let e=!1;sn([]),fn([]),gn([]),Un(null),Wn(!1),Kn(null),ar(null),fr(null),Zn([]),vn(null),bn(!1),Tn(!1),Dn(!1),kn(null),Tl(Lr.id).then(t=>{e||vn(t)});let t=am.get(Lr.id);t&&(sn(t.used_in??[]),fn(t.made_from??[]),gn(t.made_from_external??[])),sm(Lr.id).then(t=>{e||!t||(sn(t.used_in??[]),fn(t.made_from??[]),gn(t.made_from_external??[]))});for(let e of[r[A+1],r[A-1]])e&&sm(e.id);return()=>{e=!0}},[Lr?.id]),(0,X.useLayoutEffect)(()=>{let e=Zt.current,t=Xt.current;Zt.current=t,Qt.current=j?.id??null,rn(null);let n=$t.current,r=()=>{!e||e===t||(e.pause(),e.removeAttribute(`src`),e.load())};if(R||!e||!t||e===t||!n||e.readyState<2||!e.videoWidth){r(),tn(!1);return}n.width=e.videoWidth,n.height=e.videoHeight,n.getContext(`2d`)?.drawImage(e,0,0),r(),tn(!0);let i=window.setTimeout(()=>tn(!1),1e3);return()=>window.clearTimeout(i)},[j?.id]);let Rr=r[A+1]?.id,zr=r[A-1]?.id;(0,X.useEffect)(()=>
400{for(let e of[r[A+1],r[A-1]]){if(!e)continue;cr(e);let t=Qn(e)===`image`?Rp(e):Xn(e);t&&(new Image().src=J(t)),Qn(e)===`image`&&e.url&&(new Image().src=J(e.url)),sm(e.id),im(e.id),Tl(e.id),e.generation_id&&bo(e.generation_id).catch(()=>void 0)}},[Rr,zr]);let Br=(0,X.useRef)(null);(0,X.useEffect)(()=>{let e=Lr?.id??null,t=Br.current;if(Br.current=se?e:null,se||!e||t!==e)return;let n=!1;return Tl(e,!0).then(e=>{!n&&e&&vn(e)}),()=>{n=!0}},[se,Lr?.id]);let[Hr,Wr]=(0,X.useState)(0);(0,X.useEffect)(()=>{if(!Lr)return;let e=!1;return ln(nm.get(Lr.id)??null),im(Lr.id,Hr>0).then(t=>{!e&&t&&ln(t)}),()=>{e=!0}},[Lr?.id,Hr]),(0,X.useEffect)(()=>{A<0&&h()},[A,r.length,h]),(0,X.useEffect)(()=>{vr(1),br({x:0,y:0}),at(!1),nt(!1),Sn(!1),xt({}),Rt({})},[A,ie?.id]);let[Gr,Kr]=(0,X.useState)(new Map),qr=(0,X.useMemo)(()=>{let e={images:[],video:void 0};if(!Et)return e;let t=Et.metadata??{};return{images:[...Array.isArray(t.sourceImages)?t.sourceImages:[],...typeof t.sourceImage==`string`?[t.sourceImage]:[],...typeof t.referenceImage==`string`?[t.referenceImage]:[],...typeof t.endImage==`string`?[t.endImage]:[]].filter((e,t,n)=>typeof e==`string`&&n.indexOf(e)===t),video:typeof t.sourceVideo==`string`?t.sourceVideo:void 0}},[Et]);if((0,X.useEffect)(()=>{let e=[...qr.images,...qr.video?[qr.video]:[]];if(e.length===0){Kr(new Map);return}let t=e.join(` 401`),n=tm.get(t);if(n){Kr(n);return}let r=!1;return(async()=>{try{let n=await k.post(`/api/library/resolve-media`,{urls:e});if(r)return;let i=new Map;for(let e of n.resolved??[])i.set(e.url,{itemId:e.itemId,freshUrl:e.freshUrl,title:e.title});tm.set(t,i),Kr(i)}catch{}})(),()=>{r=!0}},[qr]),!j)return null;let Q=Qn(j),Jr=(M.state===`here`?M.url??void 0:void 0)??p(j)??j.url??void 0,Yr=j.storage_metadata??{},Xr=Q===`document`&&/\.pdf$/i.test(j.file_name??$n(j)),Zr=Le||!(Q===`image`||Q===`video`||Q===`audio`||Xr),Qr=R?(()=>{let e=Q===`image`||Q===`video`||Q===`audio`,t=`max(env(safe-area-inset-top), env(safe-area-inset-bottom))`;return{top:e?t:`calc(env(safe-area-inset-top) + 60px)`,bottom:z&&!K?`66dvh`:e?t:`calc(env(safe-area-inset-bottom) + 76px)`}})():null,$r=Q===`document`&&!Yr.read_only&&(!!Yr.saved_document||/\.(md|markdown|txt)$/i.test(j.file_name??``)),ei=$n(j),ti=M.state===`here`,ni=nr(j)&&!ti,ri=ti&&nr(j)?null:tr(j),ii=async()=>{if(!Kt){qt(!0);try{await k.post(`/api/library/items/${j.id}/convert`,{}),H.success(`Converting, it plays here when it is done`)}catch(e){H.error(e instanceof D?e.message:`Could not start converting`)}finally{qt(!1)}}},ai=j.file_size??void 0,oi=()=>g(j),si=async()=>{if(Ht)return;let e=Xt.current;if(!e){H.error(`Video is still loading`);return}Ut(!0);try{e.pause();let t=await hl(e),n=(j.file_name||ei).replace(/\.[^./\\]+$/,``),r=new File([t],`${n} ${gl(e).replace(/:/g,`.`)}.jpg`,{type:t.type||`image/jpeg`});await jt.keepFrame(r),Gt(!0),setTimeout(()=>Gt(!1),1800)}catch{H.error(`Could not capture frame`)}finally{Ut(!1)}},ci=e=>v(j.id,e),li=e=>{if(e===d){ae(null);return}if(r.some(t=>t.id===e)){m(e);return}let t=d;k.get(`/api/library/items`,{query:{set:1,items:e}}).then(e=>{e.items?.[0]&&oe.current===t&&ae(e.items[0])}).catch(()=>H.error(`Could not open that item`))},ui=()=>y(j),di=e=>{if(re){re(j);return}k.post(`/api/library/items/hidden`,{item_ids:[j.id],hidden:e,workspace_id:we}).then(()=>void x?.()).catch(()=>H.error(`Could not save that`))},$=`mr-2.5 h-3.5 w-3.5 flex-shrink-0 text-zinc-500 dark:text-zinc-400`,fi=`ml-auto flex-shrink-0 whitespace-nowrap pl-2 text-[11.5px] font-[400] tabular-nums text-zinc-400 dark:text-zinc-500`,pi=Q===`video`&&U?dl(W,U.durationSeconds):null,mi=(Q===`image`||Q===`video`)&&U?ol(W,{url:U.url,media:Q,durationSeconds:U.durationSeconds}):null,hi=Q===`image`||Q===`video`&&!!U||M.state===`missing`,gi=Q===`document`||De===!0?void 0:(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(Kc,{menu:Hs,itemIds:[j.id]}),Q===`image`&&(0,Z.jsx)(Yc,{menu:Hs,itemIds:[j.id]})]}),_i=(0,Z.jsxs)(Z.Fragment,{children:[Q===`video`&&U&&(0,Z.jsxs)(G,{onSelect:e=>{e.preventDefault(),Ht||si()},children:[Ht?(0,Z.jsx)(ft,{className:N($,`animate-spin`),strokeWidth:1.4}):Wt?(0,Z.jsx)(V,{className:$,strokeWidth:1.8}):(0,Z.jsx)(it,{className:$,strokeWidth:1.4}),Wt?`Frame kept`:`Keep this frame`]}),Q===`image`&&(0,Z.jsxs)(Z.Fragment,{children:[I&&De!==!0&&(0,Z.jsxs)(G,{onClick:()=>void pe({to:`/app/image/$id`,params:{id:I}}),children:[(0,Z.jsx)(ke,{className:$,strokeWidth:1.4}),`Open its canvas`]}),(0,Z.jsxs)(G,{onClick:()=>void It(),disabled:Mt!==null||Ft!==null,children:[Mt===`crop`?(0,Z.jsx)(Dc,{className:`mr-2.5 h-3.5 w-3.5`}):(0,Z.jsx)(fe,{className:$,strokeWidth:1.4}),`Crop`]}),(0,Z.jsxs)(G,{onSelect:e=>{e.preventDefault(),Bt()},disabled:Mt!==null&&Mt!==`background`||Ft!==null,className:N(ot&&`bg-zinc-900 text-white hover:bg-zinc-800 focus:bg-zinc-800 focus:text-white dark:bg-white dark:text-black dark:hover:bg-zinc-200 dark:focus:bg-zinc-200 dark:focus:text-black`),children:[Mt===`background`?(0,Z.jsx)(ft,{className:N($,`animate-spin`),strokeWidth:1.4}):Lt.background?(0,Z.jsx)(V,{className:$,strokeWidth:1.8}):(0,Z.jsx)(_e,{className:N($,ot&&`text-current opacity-100`),strokeWidth:1.4}),(0,Z.jsx)(`span`,{className:`whitespace-nowrap`,children:Lt.background?`Removing the background`:ot?`Confirm`:`Remove background`}),W&&Mt!==`background`&&!Lt.background&&(0,Z.jsxs)(`span`,{className:N(fi,ot&&`text-current opacity-80 dark:text-current`),children:[ko(W.removeBackgroun
401d),` credits`]})]})]}),Q===`video`&&U&&(0,Z.jsxs)(G,{onSelect:e=>{e.preventDefault(),Bt()},disabled:Mt!==null&&Mt!==`background`||Ft!==null,className:N(ot&&`bg-zinc-900 text-white hover:bg-zinc-800 focus:bg-zinc-800 focus:text-white dark:bg-white dark:text-black dark:hover:bg-zinc-200 dark:focus:bg-zinc-200 dark:focus:text-black`),children:[Mt===`background`?(0,Z.jsx)(ft,{className:N($,`animate-spin`),strokeWidth:1.4}):Lt.background?(0,Z.jsx)(V,{className:$,strokeWidth:1.8}):(0,Z.jsx)(_e,{className:N($,ot&&`text-current opacity-100`),strokeWidth:1.4}),(0,Z.jsx)(`span`,{className:`whitespace-nowrap`,children:Lt.background?`Removing the background`:ot?`Confirm`:`Remove background`}),pi!==null&&Mt!==`background`&&!Lt.background&&(0,Z.jsxs)(`span`,{className:N(fi,ot&&`text-current opacity-80 dark:text-current`),children:[ko(pi),` credits`]})]}),(Q===`image`||Q===`video`)&&U&&(0,Z.jsxs)(G,{disabled:Pt,onSelect:e=>{if(e.preventDefault(),!(Lt.upscale||Pt)){if(!rt){at(!0);return}at(!1),Vt()}},className:N(rt&&`bg-zinc-900 text-white hover:bg-zinc-800 focus:bg-zinc-800 focus:text-white dark:bg-white dark:text-black dark:hover:bg-zinc-200 dark:focus:bg-zinc-200 dark:focus:text-black`),children:[Pt?(0,Z.jsx)(ft,{className:N($,`animate-spin`),strokeWidth:1.4}):Lt.upscale?(0,Z.jsx)(V,{className:$,strokeWidth:1.8}):(0,Z.jsx)(Me,{className:N($,rt&&`text-current opacity-100`),strokeWidth:1.4}),(0,Z.jsx)(`span`,{className:`whitespace-nowrap`,children:Lt.upscale?`Upscaling to 4K`:rt?`Confirm`:`Upscale to 4K`}),!Pt&&!Lt.upscale&&mi!==null&&(0,Z.jsxs)(`span`,{className:N(fi,rt&&`text-current opacity-80 dark:text-current`),children:[ko(mi),` credits`]})]}),M.state===`missing`&&(0,Z.jsxs)(G,{onClick:()=>void Zc(j),children:[(0,Z.jsx)(ue,{className:$,strokeWidth:1.4}),`Locate file`]})]}),vi=j.source??(j.origin===`generated`?`generation`:`upload`),yi=(()=>{let e=vi===`render`?`Timeline render`:vi===`capture`?`Captured frame`:vi===`import`?`Imported`:vi===`generation`?`Generated`:vi===`pull`?`Pulled from ${td(String(j.storage_metadata?.pulled_from?.platform??``)).name||`a platform`}`:vi===`mcp`?`Added by a connected agent`:vi===`api`?`Added through the API`:`Uploaded`,t=vi===`pull`?j.storage_metadata?.pulled_from?.url:null;return{how:e,howHref:(vi===`render`||vi===`capture`)&&j.source_ref?De===!0?null:`/app/editor/${encodeURIComponent(j.source_ref)}`:typeof t==`string`&&/^https?:\/\//.test(t)?t:null,howExternal:vi===`pull`,when:qn(new Date(j.created_at).getTime())}})(),bi=j.metadata?.foreign_provenance??null,xi=bi?.prompt?.trim()||null,Si=Et?Qf([{...Zf(Et,Q),credits:0}]):bi?.made_with?[bi.made_with]:[],Ci=Ot?Io(Ot):null,wi=Et?.prompt?.trim()||(xi===j.description?.trim()?null:xi),Ti=j.file_name?.includes(`.`)?j.file_name.split(`.`).pop().toUpperCase():null,Di=j.metadata??{},Oi=j.storage_metadata??{},ki=Number(Di.width)||Number(Oi.width)||0,Ai=Number(Di.height)||Number(Oi.height)||0,ji=ki&&Ai?ki:bt.width,Mi=ki&&Ai?Ai:bt.height,Ni=Number(Di.duration)||Number(Oi.duration)||bt.durationSeconds,Pi=[{label:`Type`,value:[er(Q),Ti].filter(Boolean).join(`, `)},ji&&Mi?{label:`Dimensions`,value:`${ji} à ${Mi}`}:null,Ni?{label:`Length`,value:q(Ni)}:null,ai?{label:`Size`,value:rr(ai)}:null,!Et&&Ci?{label:`Cost`,value:Ci}:null].filter(e=>!!e),Fi=j.folder_id?An.find(e=>e.id===j.folder_id)??null:null,Ii=(()=>{let e=ne(j),t=i()?.id??null,n=!!or(j),r=[...n?[`this ${a?.platform===`darwin`?`Mac`:`PC`}`]:[],...Object.entries(ee(j)).filter(([e])=>e!==t).map(([,e])=>te(e.device_name)??`another device`)],o=r.length?`on ${r.join(`, `)}`:null;return{inCloud:e,text:e?o?`In the cloud, and ${o}`:`In the cloud`:o?`Only ${o}`:`Not in the cloud`,action:!e&&n?`sync`:e&&hr(j)?`remove`:null}})(),Li=async e=>{if(!On){kn(e);try{(e===`sync`?await mr([j]):await pr([j])).length>0&&await x?.()}finally{kn(null)}}},Ri=qr.images.length>0||!!qr.video||un.length>0||pn.length>0,zi=()=>void x?.(),Bi=Mn(j.id),Vi=jn.filter(e=>Bi.has(e.id)),Hi=Fn.flatMap(e=>{let t=e.options.find(t=>t.id===nc([j],e.id));return t?[{board:e,column:t}]:[]}),Ui=In.flatMap(e=>{let t=nc([j],e.id);return t?[{calendar:e,day:t}]:[]}),Wi=cn?.links??[],Gi=new Set(Ui.map(({calendar:e})=>e.id)),Ki=Rn.filter(e=>!e.view&&e.plan!==`board`&&e.plan!==`calendar`&&(!e.plan||!!e.planOf&&Gi.has(e.planOf))),qi=j.metadata?.properties??{},Ji=e=>e in zn?zn[e]:qi[e]??null,Yi=(e,t)=>{let n=Ji(e);Vn(n=>({...n,[e]:t})),k.post(`/api/library/properties/values`,{itemId:j.id,propertyId:e,value:t}).then(zi).catch(t=>{H.error(t instanceof D?t.message:`Could not save the value`),Vn(t=>({...t,[e]:n}))})},Xi=Fi?`/app/library?folder=${encodeURIComponent(Fi.id)}`:null,Qi=(0,Z.jsxs)(`dl`,{children:[Pi.map(e=>(0,Z.jsx)(em,{label:e.label,value:(0,Z.jsx)(`span`,{className:`truncate tabular-nums`,children:e.value})},e.label)),(0,Z.jsx)(em,{label:`Storage`,value:(0,Z.jsx)(`span`,{className:`truncate`,children:On===`sync`?`Syncingâ¦`:On===`remove`?`Removing cloud copyâ¦`:Ii.text}),menu:Ii.action&&!On&&(0,Z.jsxs)(G,{onClick:()=>void Li(Ii.action),children:[Ii.action===`sync`?(0,Z.jsx)(lt,{className:Zp,strokeWidth:1.4}):(0,Z.jsx)(ge,{className:Zp,strokeWidth:1.4}),Ii.action===`sync`?`Sync to cloud`:`Remove cloud copy`]})}),(0,Z.jsx)(em,{label:`Added`,value:(0,Z.jsxs)(`span`,{className:`min-w-0 truncate`,children:[yi.howHref&&yi.howExternal?(0,Z.jsx)(`a`,{href:yi.howHref,target:`_blank`,rel:`noreferrer`,className:`transition-colors hover:text-foreground dark:hover:text-white`,children:yi.how}):yi.howHref?(0,Z.jsx)(`button`,{type:`button`,onClick:()=>pe({href:yi.howHref}),className:`transition-colors hover:text-foreground dark:hover:text-white`,children:yi.how}):yi.how,`, `,yi.when]})}),j.short_ref&&(0,Z.jsx)(em,{label:`ID`,onClick:async()=>{try{await navigator.clipboard.writeText(j.short_ref),Dn(!0),window.setTimeout(()=>Dn(!1),1600)}catch{H.error(`Could not copy`)}},value:(0,Z.jsxs)(`span`,{className:`flex min-w-0 items-center gap-1.5`,children:[(0,Z.jsx)(`span`,{className:`truncate tabular-nums`,children:j.short_ref}),En?(0,Z.jsx)(V,{className:`h-3 w-3 flex-shrink-0 text-foreground`,strokeWidth:2}):(0,Z.jsx)(ut,{className:`h-3 w-3 flex-shrink-0 text-zinc-400 dark:text-zinc-500`,strokeWidth:1.7}),(0,Z.jsx)(`span`,{className:`sr-only`,children:En?`Copied`:`Copy ID for your agent`})]})}),(0,Z.jsx)(em,{label:`Folder`,value:Fi&&(0,Z.jsx)(`span`,{className:`truncate`,children:Fi.name}),menu:(0,Z.jsxs)(Z.Fragment,{children:[Xi&&(0,Z.jsx)(Z.Fragment,{children:(0,Z.jsxs)(G,{onClick:()=>void pe({href:Xi}),children:[(0,Z.jsx)(ye,{className:Zp,strokeWidth:1.4}),`Open folder`]})}),(0,Z.jsx)(Ws,{menu:Hs,folders:An,showRemove:!!Fi,onMove:ci,currentId:j.folder_id??null,keepOpen:!0})]})}),(0,Z.jsx)(em,{label:`Labels`,value:Vi.length>0&&(0,Z.jsx)(`span`,{className:`flex flex-wrap gap-x-1 gap-y-1.5 py-px`,children:Vi.map(e=>(0,Z.jsx)(`span`,{className:N(`max-w-full truncate rounded-full px-2 py-px text-[11px] font-[440]`,Ds(e.color)),style:Os(e.color),children:e.name},e.id))}),menu:(0,Z.jsx)(Ks,{menu:Hs,labels:jn,checkedIds:Bi,onToggle:(e,t)=>
401void Nn(e,t,[j.id]),onDelete:e=>void Pn(e),onCreate:ht([j])})}),Fn.length>0&&!R&&(0,Z.jsx)(em,{label:`Board`,value:Hi.length>0&&(0,Z.jsx)(`span`,{className:`flex min-w-0 flex-col gap-1`,children:Hi.map(({board:e,column:t})=>(0,Z.jsxs)(`span`,{className:`flex min-w-0 items-center gap-1.5`,children:[(0,Z.jsx)(`span`,{className:N(`max-w-full truncate rounded-full px-2 py-px text-[11px] font-[440]`,Ds(t.color)),style:Os(t.color),children:t.name}),Fn.length>1&&(0,Z.jsx)(`span`,{className:`truncate text-zinc-400 dark:text-zinc-500`,children:e.name})]},e.id))}),menu:Fn.length===1?(0,Z.jsx)(ic,{menu:Hs,board:Fn[0],items:[j],onChanged:zi}):(0,Z.jsx)(ac,{menu:Hs,items:[j],onChanged:zi})}),In.length>0&&(0,Z.jsx)(em,{label:`Calendar`,value:Ui.length>0&&(0,Z.jsx)(`span`,{className:`flex min-w-0 flex-col gap-1`,children:Ui.map(({calendar:e,day:t})=>(0,Z.jsxs)(`span`,{className:`flex min-w-0 items-center gap-1.5`,children:[(0,Z.jsx)(`span`,{className:`flex-shrink-0 tabular-nums`,children:Ys(t)}),In.length>1&&(0,Z.jsx)(`span`,{className:`truncate text-zinc-400 dark:text-zinc-500`,children:e.name})]},e.id))}),menu:In.length===1?(0,Z.jsx)(cc,{menu:Hs,calendar:In[0],items:[j],onChanged:zi,onPickDate:mt([j])}):(0,Z.jsx)(lc,{menu:Hs,items:[j],onChanged:zi,onPickDate:mt([j])})}),Ki.map(e=>{let t=Ji(e.id);return(0,Z.jsx)(em,{label:e.plan===`time`?`Time`:e.plan===`channel`?`Channel`:e.plan===`status`?`Status`:e.name,value:(0,Z.jsx)(yp,{quiet:!0,property:e,value:t,onChange:t=>Yi(e.id,t)})},e.id)}),(0,Z.jsx)(em,{label:`Links`,value:Wi.length>0&&(0,Z.jsx)(`span`,{className:`flex min-w-0 flex-col gap-1`,children:Wi.map(e=>(0,Z.jsxs)(`span`,{className:`flex min-w-0 items-center gap-1.5`,children:[(0,Z.jsx)(`span`,{className:`truncate`,children:e.id===Ln.ownLinkId?`Its own link`:e.title}),!e.published&&(0,Z.jsx)(`span`,{className:`flex-shrink-0 text-zinc-400 dark:text-zinc-500`,children:`Draft`})]},e.id))}),menu:De!==!0&&(0,Z.jsxs)(Z.Fragment,{children:[Wi.map(e=>(0,Z.jsx)(G,{onClick:()=>void pe({to:`/app/library/links/$id`,params:{id:e.id}}),children:(0,Z.jsxs)(`span`,{className:`min-w-0 flex-1 truncate`,children:[`Open `,e.id===Ln.ownLinkId?`its own link`:e.title]})},e.id)),(0,Z.jsx)(wc,{menu:Hs,items:[j],onLinks:Wi.map(e=>e.id),onChanged:()=>Wr(e=>e+1)})]})}),Ri&&(0,Z.jsxs)(dm,{label:`Made from`,children:[(qr.images.length>0||qr.video)&&(0,Z.jsxs)(`div`,{className:`flex flex-wrap gap-1.5 px-1.5 py-1`,children:[qr.images.map(e=>{let t=Gr.get(e),n=t?r.some(e=>e.id===t.itemId):!1;return(0,Z.jsx)(`button`,{type:`button`,"aria-label":t?t.title:`View source`,onClick:()=>{t&&n?m(t.itemId):Ce({url:J(t?.freshUrl??e),kind:`image`})},className:`rounded-[8px] transition-opacity hover:opacity-80`,children:(0,Z.jsx)(`img`,{src:J(t?.freshUrl??e),alt:t?.title??`Source`,onError:e=>{e.currentTarget.style.visibility=`hidden`},className:`h-12 w-12 rounded-[8px] bg-white object-cover dark:bg-white/[0.04]`})},e)}),qr.video&&(0,Z.jsx)(`button`,{type:`button`,"aria-label":`View source`,onClick:()=>Ce({url:J(qr.video),kind:`video`}),className:`rounded-[8px] transition-opacity hover:opacity-80`,children:(0,Z.jsx)(`video`,{src:J(qr.video),muted:!0,playsInline:!0,preload:`metadata`,className:`h-12 w-12 rounded-[8px] bg-white object-cover dark:bg-white/[0.04]`})})]}),(0,Z.jsx)(lm,{children:[...un.map(e=>(0,Z.jsx)(cm,{title:e.title,onClick:()=>{r.some(t=>t.id===e.id)?m(e.id):pe({href:`/app/library/${e.id}`})}},e.id)),...pn.map(e=>(0,Z.jsx)(cm,{title:e.replace(/^https?:\/\//,``),href:e,external:!0},e))]},`from-${j.id}`)]}),(cn?.timelines.length??0)>0&&(0,Z.jsx)(dm,{label:`Used in`,children:(0,Z.jsx)(lm,{children:(cn?.timelines??[]).map(e=>(0,Z.jsx)(cm,{title:e.name,href:De===!0?void 0:`/app/editor/${e.id}`},`tl-${e.id}`))},`used-${j.id}`)}),on.length>0&&(0,Z.jsx)(dm,{label:`Made into`,children:(0,Z.jsx)(lm,{children:on.map(e=>(0,Z.jsx)(cm,{title:e.title,onClick:()=>{r.some(t=>t.id===e.id)?m(e.id):pe({href:`/app/library/${e.id}`})}},e.id))},`into-${j.id}`)})]}),$i=e=>(0,Z.jsxs)(hn,{onOpenChange:e=>{e||(at(!1),dt(!1))},children:[(0,Z.jsx)(dn,{asChild:!0,children:e}),(0,Z.jsx)(mn,{align:`end`,className:`w-max min-w-[12rem] max-w-[20rem] [&_[role=menuitem]>svg[class*='mr-2.5']]:hidden`,onCloseAutoFocus:e=>e.preventDefault(),children:(0,Z.jsx)(Bc,{menu:Hs,items:[j],handlers:{showCopy:!1,showStar:!1,showPlacement:!1,showCloud:!1,onPickDate:mt([j]),onHide:R?e=>{e?ze(`hide`):di(!1)}:re?()=>re(j):void 0,onDelete:R?()=>ze(`delete`):ui,onChanged:zi,extras:hi?_i:void 0,send:gi}})})]}),sa=e=>(0,Z.jsx)(Na,{target:`item:${j.id}`,initialThreadId:n?.itemId===j.id?n.threadId:null,title:`Comments`,onClose:e,sheet:R,focusNonce:R?0:Ve,currentUserId:E,pendingRegion:Gn,onRequestDraw:Q===`image`?()=>{Kn(null),Wn(!0)}:void 0,drawing:K,onClearPending:()=>{Kn(null),Wn(!1),fr(null)},onRegionsChange:Zn,activeRegionId:ir,onRegionActivate:lr,getCurrentTime:Q===`video`?()=>Xt.current?Xt.current.currentTime:null:Q===`audio`?()=>an.current?an.current.currentTime:null:void 0,onSeek:e=>
401{let t=Q===`video`?Xt.current:Q===`audio`?an.current:null;t&&(t.currentTime=e,t.play().catch(()=>{}))}},j.id),ca=(0,Z.jsxs)(`div`,{className:`px-2 pb-4 pt-2`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-col gap-1.5 pb-3`,children:[(0,Z.jsxs)(`div`,{className:`contents`,children:[me?(0,Z.jsx)(`textarea`,{autoFocus:!0,ref:Xp,rows:1,value:he,onChange:e=>{xe(e.target.value.replace(/\n/g,``)),Xp(e.currentTarget)},onBlur:()=>{let e=he.trim();e&&_?.(j.id,e),L(!1)},onKeyDown:e=>{e.stopPropagation(),e.key===`Enter`&&(e.preventDefault(),e.currentTarget.blur()),e.key===`Escape`&&(xe(``),L(!1))},"aria-label":`Name`,className:N(Kp,`block w-full resize-none overflow-hidden bg-transparent outline-none`)}):(0,Z.jsx)(`button`,{type:`button`,"aria-label":`Rename ${ei}`,onClick:()=>{xe(ei),L(!0)},disabled:!_,className:N(Kp,`block w-full text-left transition-colors hover:text-zinc-600 disabled:cursor-default disabled:hover:text-foreground dark:hover:text-zinc-300`),children:ei}),(0,Z.jsx)(Hp,{item:j},`desc-${j.id}`)]}),se&&(0,Z.jsx)(`p`,{className:`text-[12px] font-[380] leading-[18px] text-zinc-500 dark:text-zinc-400`,children:se})]}),Qi,(Si.length>0||Et&&Ci)&&(0,Z.jsxs)(`div`,{className:`flex items-start gap-1`,children:[(0,Z.jsx)(`span`,{className:jp,children:`Made with`}),(0,Z.jsx)(`div`,{className:N(Qp,`leading-[18px]`),children:[...Si,Et?Ci:null].filter(Boolean).join(`, `)})]}),wi&&(0,Z.jsxs)(`div`,{children:[(0,Z.jsxs)(`div`,{className:`flex items-start gap-1`,children:[(0,Z.jsx)(`span`,{className:jp,children:`Prompt`}),(0,Z.jsx)(`button`,{type:`button`,onClick:async()=>{try{await navigator.clipboard.writeText(wi),nt(!0),window.setTimeout(()=>nt(!1),1600)}catch{H.error(`Could not copy`)}},className:N(Qp,$p),children:et?`Copied`:`Copy`})]}),(0,Z.jsx)(`button`,{type:`button`,onClick:()=>Tn(e=>!e),"aria-expanded":wn,className:N(Mp,`block w-full text-left transition-colors hover:text-foreground dark:hover:text-white`),children:(0,Z.jsx)(`span`,{className:N(`whitespace-pre-wrap break-words`,!wn&&`line-clamp-4`),children:wi})})]}),_n?.transcript&&(0,Z.jsxs)(`div`,{children:[(0,Z.jsxs)(`div`,{className:`flex items-start gap-1`,children:[(0,Z.jsx)(`span`,{className:jp,children:`Transcript`}),(0,Z.jsx)(`button`,{type:`button`,"aria-expanded":yn,onClick:()=>bn(e=>!e),className:N(Qp,$p,`w-auto`),children:yn?`Hide`:`Show`}),(0,Z.jsx)(`button`,{type:`button`,"aria-label":`Copy transcript`,onClick:async()=>{try{await navigator.clipboard.writeText(Yp(_n.transcript,j.storage_metadata)),Sn(!0),window.setTimeout(()=>Sn(!1),1600)}catch{H.error(`Could not copy`)}},className:`-ml-1.5 flex h-7 w-5 flex-shrink-0 items-center justify-center text-zinc-400 transition-colors hover:text-foreground dark:text-zinc-500 dark:hover:text-white`,children:xn?(0,Z.jsx)(V,{className:`h-3 w-3 text-foreground`,strokeWidth:2}):(0,Z.jsx)(ut,{className:`h-3 w-3`,strokeWidth:1.7})})]}),yn&&(()=>{let e=qp(j.storage_metadata),t=Ge(_n.transcript.slice(0,4e3));if(!e)return(0,Z.jsx)(`p`,{dir:t,className:N(Mp,`max-h-[240px] overflow-y-auto whitespace-pre-wrap break-words [scrollbar-width:thin]`),children:Jp(_n.transcript)});let n=Q===`video`?Xt.current:Q===`audio`?an.current:null;return(0,Z.jsx)(`div`,{dir:t,className:N(Mp,`max-h-[240px] space-y-1 overflow-y-auto [scrollbar-width:thin]`),children:e.map((e,t)=>(0,Z.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,Z.jsx)(`button`,{type:`button`,disabled:!n,onClick:()=>{n&&(n.currentTime=e.start,n.play().catch(()=>{}))},className:`min-w-[36px] flex-shrink-0 text-left text-[11px] tabular-nums text-zinc-400 transition-colors hover:text-foreground disabled:cursor-default disabled:hover:text-zinc-400 dark:text-zinc-500 dark:hover:text-white`,children:q(e.start)}),(0,Z.jsx)(`span`,{className:`min-w-0 flex-1 break-words`,children:e.text})]},t))})})()]}),(0,Z.jsx)(Dl,{target:j.id,onOpen:li,canOpen:()=>!0},`var-${j.id}`)]});return(0,Ur.createPortal)((0,Z.jsxs)(`div`,{"data-item-viewer":!0,className:N(`pointer-events-auto z-[100] pb-[env(safe-area-inset-bottom)] pt-[env(safe-area-inset-top)]`,Wa,R&&`!pb-0 !pt-0 touch-pan-x touch-pan-y`,R&&!Zr&&`dark !bg-black`),style:Ae?{bottom:Ae,paddingBottom:0}:void 0,onClick:e=>e.stopPropagation(),onMouseDown:e=>{e.stopPropagation(),e.target===e.currentTarget&&h()}
401,children:[(!R||Zr)&&(0,Z.jsx)(`div`,{"aria-hidden":!0,className:`pointer-events-none fixed inset-x-0 -bottom-[50dvh] -top-[50dvh] -z-10 bg-white dark:bg-background md:hidden`}),(0,Z.jsxs)(`div`,{className:Ga,onMouseDown:e=>{e.target===e.currentTarget&&h()},children:[(0,Z.jsx)(`div`,{className:Ka,onMouseDown:e=>{e.target===e.currentTarget&&h()},children:(0,Z.jsx)(Bp,{on:wr,pager:Er,locked:Tr,items:r,index:A,underlay:(Q===`video`&&!z||Q===`image`)&&Y===1,children:(0,Z.jsxs)(`div`,{className:N(`group/stage relative flex min-h-[0px] flex-1 items-center justify-center px-4 md:pl-14 md:[container-type:size]`,Fe?`md:pr-14`:`md:pr-12`,$r?`py-0`:`py-4`,R&&`[container-type:size]`,R&&($r||Q===`image`||Q===`video`||Q===`audio`)&&`px-0`,R&&(Q===`image`||Q===`video`)&&(wr&&!Tr?`touch-pan-x`:`touch-none`)),style:Qr?{paddingTop:Qr.top,paddingBottom:Qr.bottom}:void 0,ref:Ze,onMouseDown:e=>{e.target===e.currentTarget&&(R?(Q===`image`||Q===`video`||Q===`audio`||Xr)&&Re(e=>!e):h())},onTouchStart:Nr,onTouchMove:Pr,onTouchEnd:Ir,onTouchCancel:Fr,children:[r.length>1&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`button`,{type:`button`,"aria-label":`Previous item`,disabled:A<=0,onClick:()=>Cr(A-1),className:N(`absolute left-2 top-1/2 z-20 -translate-y-1/2 md:left-4 max-md:hidden disabled:!opacity-0 [@media(hover:hover)]:opacity-0 [@media(hover:hover)]:group-hover/stage:opacity-100 [@media(hover:hover)]:focus-visible:opacity-100`,`flex h-7 w-7 items-center justify-center rounded-full text-zinc-500 transition-[opacity,background-color,color] duration-150 hover:bg-zinc-100 hover:text-foreground dark:text-zinc-400 dark:hover:bg-white/[0.08] dark:hover:text-foreground`),children:(0,Z.jsx)(ct,{className:`h-4 w-4`,strokeWidth:1.8})}),(0,Z.jsx)(`button`,{type:`button`,"aria-label":`Next item`,disabled:A>=r.length-1,onClick:()=>Cr(A+1),className:N(`absolute right-2 top-1/2 z-20 -translate-y-1/2 max-md:hidden disabled:!opacity-0`,Fe?`md:right-4`:`md:right-2`,` [@media(hover:hover)]:opacity-0 [@media(hover:hover)]:group-hover/stage:opacity-100 [@media(hover:hover)]:focus-visible:opacity-100`,`flex h-7 w-7 items-center justify-center rounded-full text-zinc-500 transition-[opacity,background-color,color] duration-150 hover:bg-zinc-100 hover:text-foreground dark:text-zinc-400 dark:hover:bg-white/[0.08] dark:hover:text-foreground`),children:(0,Z.jsx)(st,{className:`h-4 w-4`,strokeWidth:1.8})})]}),Q===`image`&&Jr&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`div`,{className:N(`absolute bottom-4 left-1/2 z-20 flex -translate-x-1/2 items-center rounded-full bg-zinc-100 p-0.5 opacity-0 transition-opacity duration-150 focus-within:opacity-100 group-hover/stage:opacity-100 dark:bg-[#202020] [@media(hover:none)]:hidden`,Y>1&&`opacity-100`),children:[(0,Z.jsx)(`button`,{type:`button`,"aria-label":`Zoom out`,disabled:Y===1,className:N(Pp,`disabled:opacity-30`),onClick:()=>vr(e=>Math.max(1,+(e-.5).toFixed(2))),children:(0,Z.jsx)(Qe,{className:`h-3 w-3`,strokeWidth:2})}),(0,Z.jsxs)(`span`,{className:`min-w-[32px] text-center text-[11px] font-[400] tabular-nums text-zinc-500 dark:text-zinc-400`,children:[Math.round(Y*100),`%`]}),(0,Z.jsx)(`button`,{type:`button`,"aria-label":`Zoom in`,disabled:Y>=6,className:N(Pp,`disabled:opacity-30`),onClick:()=>vr(e=>Math.min(6,+(e+.5).toFixed(2))),children:(0,Z.jsx)(gt,{className:`h-3 w-3`,strokeWidth:2})}),Y>1&&(0,Z.jsx)(`button`,{type:`button`,"aria-label":`Fit to screen`,className:Pp,onClick:()=>{vr(1),br({x:0,y:0})},children:(0,Z.jsx)(je,{className:`h-3 w-3`,strokeWidth:2})})]}),R&&nn!==Jr&&Rp(j)&&(0,Z.jsx)(`img`,{src:J(Rp(j)),alt:``,"aria-hidden":!0,className:N(`block max-h-full max-w-full rounded-[4px]`,`pointer-events-none absolute inset-0 m-auto h-full w-full rounded-none object-contain`),style:{transform:Sr},onLoad:()=>(j.id,void 0)},`small-${j.id}`),(0,Z.jsx)(`img`,{src:Jr,alt:ei,onLoad:e=>{let t=e.currentTarget,n=t.getAttribute(`src`);j.id,t.decode().catch(()=>void 0).then(()=>{j.id,rn(n)}),Un(t.naturalWidth&&t.naturalHeight?t.naturalWidth/t.naturalHeight:null),t.naturalWidth&&t.naturalHeight&&xt({width:t.naturalWidth,height:t.naturalHeight})},onMouseDown:e=>{K||Y===1||(e.preventDefault(),xr.current={x:e.clientX,y:e.clientY,ox:yr.x,oy:yr.y})},onClick:()=>{R&&!K&&Re(e=>!e)},onWheel:e=>{!e.ctrlKey&&!e.metaKey||(e.preventDefault(),vr(t=>Math.min(6,Math.max(1,+(t-e.deltaY*.002).toFixed(2)))))},style:{transform:Sr},className:N(`block max-h-full max-w-full rounded-[4px]`,`object-contain max-md:h-full max-md:w-full max-md:rounded-none`,kr&&`transition-transform duration-200 ease-out`,Y>1&&!K&&`cursor-grab active:cursor-grabbing`)},j.id),(0,Z.jsxs)(`div`,{ref:_r,className:N(`absolute inset-0 m-auto max-h-full max-w-full rounded-md max-md:rounded-none`,K?`cursor-crosshair touch-none`:`pointer-events-none`),style:{...Hn?{aspectRatio:String(Hn)}:{},transform:Sr,...Qr?{top:Qr.top,bottom:Qr.bottom}:{}},onPointerDown:e=>{if(!K||!_r.current)return;let t=_r.current.getBoundingClientRect();gr.current={x:(e.clientX-t.left)/t.width,y:(e.clientY-t.top)/t.height},fr({x:gr.current.x,y:gr.current.y,w:0,h:0})},onPointerMove:e=>{if(!K||!gr.current||!_r.current)return;let t=_r.current.getBoundingClientRect(),n=Math.min(1,Math.max(0,(e.clientX-t.left)/t.width)),r=Math.min(1,Math.max(0,(e.clientY-t.top)/t.height)),i=gr.current;fr({x:Math.min(i.x,n),y:Math.min(i.y,r),w:Math.abs(n-i.x),h:Math.abs(r-i.y)})},children:[Yn.filter(e=>e.id===ir).map(e=>
401(0,Z.jsx)(`div`,{"aria-hidden":!0,className:`pointer-events-none absolute rounded-[3px] border-2 border-white bg-white/20 shadow-[0_0_0_1px_rgba(0,0,0,0.25)]`,style:{left:`${e.region.x*100}%`,top:`${e.region.y*100}%`,width:`${e.region.w*100}%`,height:`${e.region.h*100}%`}},e.id)),(dr||Gn&&!K)&&(()=>{let e=dr||Gn;return(0,Z.jsx)(`div`,{className:`absolute rounded-[3px] border-2 border-dashed border-white bg-white/10`,style:{left:`${e.x*100}%`,top:`${e.y*100}%`,width:`${e.w*100}%`,height:`${e.h*100}%`}})})()]}),K&&(0,Z.jsx)(`div`,{className:`pointer-events-none absolute left-1/2 top-2 -translate-x-1/2 rounded-full bg-zinc-900/80 px-2.5 py-1 text-[12px] font-[440] text-white max-md:top-[60px] max-md:px-3 max-md:py-1.5 max-md:text-[13.5px]`,children:`Draw a box on the image`})]}),(M.state===`missing`||M.state===`elsewhere`&&!Jr)&&(0,Z.jsxs)(`div`,{className:`flex h-full w-full flex-col items-center justify-center gap-2 px-6 text-center`,children:[(0,Z.jsx)(`p`,{className:`text-[12px] font-[400] text-zinc-500 dark:text-zinc-400`,children:M.state===`missing`?`This file is not where it was when it was imported.`:`This file is stored locally on another device and has not been synced to the cloud.`}),M.state===`missing`&&(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>void Zc(j),className:N(Dp,`w-auto px-3`),children:[(0,Z.jsx)(ue,{className:Ip,strokeWidth:1.6}),`Locate file`]})]}),Q===`video`&&(0,Z.jsx)(`canvas`,{ref:$t,"aria-hidden":!0,className:N(`pointer-events-none absolute inset-0 z-10 h-full w-full object-scale-down px-4 py-4 md:pl-14 md:pr-12`,(!en||R)&&`hidden`)}),Q===`video`&&Jr&&(R?(0,Z.jsxs)(`div`,{className:`relative flex max-h-full max-w-full`,children:[(0,Z.jsx)(`video`,{onLoadedData:()=>tn(!1),onPlay:()=>{We.current!==j.id&&(We.current=j.id,Ue.current!==null&&window.clearTimeout(Ue.current),Ue.current=window.setTimeout(()=>{Ue.current=null,Ke.current||Re(!1)},0))},ref:Xt,src:Jr,poster:(Oe.current?.id===j.id?Oe.current.frame:null)??(Xn(j)?J(Xn(j)):void 0),controls:!R,autoPlay:!R,preload:`metadata`,playsInline:!0,crossOrigin:`anonymous`,onError:e=>{Oc(e.currentTarget)&&Yt(j.id)},onTimeUpdate:e=>{e.currentTarget.paused||u(j.id,`full`,e.currentTarget.currentTime,e.currentTarget.muted)},onLoadedMetadata:e=>{let t=e.currentTarget;Oc(t)&&Yt(j.id);let n=Oe.current?.id===j.id?Oe.current.head:null;n&&n.seconds>0&&n.seconds<t.duration-.5&&(t.currentTime=n.seconds),window.matchMedia(`(hover: none)`).matches&&tn(!1),t.videoWidth&&t.videoHeight&&Ct({id:j.id,width:t.videoWidth,height:t.videoHeight}),xt({width:t.videoWidth||void 0,height:t.videoHeight||void 0,durationSeconds:Number.isFinite(t.duration)?Math.round(t.duration):void 0})},onMouseDown:e=>{Y!==1&&(xr.current={x:e.clientX,y:e.clientY,ox:yr.x,oy:yr.y})},style:{transform:Sr,...(()=>{let e=(St?.id===j.id?St:null)??Lp(j)??(R?null:St);return e?{aspectRatio:`${e.width} / ${e.height}`,height:`auto`,width:R?`min(100cqw, calc(100cqh * ${e.width/e.height}))`:`min(100cqw, calc(100cqh * ${e.width/e.height}), ${e.width}px)`}:{}})()},className:N(`block max-h-full max-w-full rounded-[4px]`,`max-md:rounded-none`,Y>1&&`cursor-grab active:cursor-grabbing`)},j.id),(0,Z.jsx)(Gp,{videoRef:Xt,barsShown:Zr,onTap:()=>Re(e=>!e),autoPlay:z===null,startMuted:Oe.current?.id===j.id?Oe.current.head?.muted:void 0},j.id)]}):(0,Z.jsx)(`video`,{onLoadedData:()=>tn(!1),ref:Xt,src:Jr,poster:Xn(j)?J(Xn(j)):void 0,controls:!R,autoPlay:!R,preload:R?`metadata`:void 0,playsInline:!0,crossOrigin:`anonymous`,onError:e=>{Oc(e.currentTarget)&&Yt(j.id)},onTimeUpdate:e=>{e.currentTarget.paused||u(j.id,`full`,e.currentTarget.currentTime,e.currentTarget.muted)},onLoadedMetadata:e=>{let t=e.currentTarget;Oc(t)&&Yt(j.id);let n=Oe.current?.id===j.id?Oe.current.head:null;n&&n.seconds>0&&n.seconds<t.duration-.5&&(t.currentTime=n.seconds),n&&!R&&(t.muted=n.muted),window.matchMedia(`(hover: none)`).matches&&tn(!1),t.videoWidth&&t.videoHeight&&Ct({id:j.id,width:t.videoWidth,height:t.videoHeight}),xt({width:t.videoWidth||void 0,height:t.videoHeight||void 0,durationSeconds:Number.isFinite(t.duration)?Math.round(t.duration):void 0})},onMouseDown:e=>{Y!==1&&(xr.current={x:e.clientX,y:e.clientY,ox:yr.x,oy:yr.y})},style:{transform:Sr,...(()=>{let e=(St?.id===j.id?St:null)??Lp(j)??(R?null:St);return e?{aspectRatio:`${e.width} / ${e.height}`,height:`auto`,width:R?`min(100cqw, calc(100cqh * ${e.width/e.height}))`:`min(100cqw, calc(100cqh * ${e.width/e.height}), ${e.width}px)`}:{}})()},className:N(`block max-h-full max-w-full rounded-[4px]`,`max-md:rounded-none`,Y>1&&`cursor-grab active:cursor-grabbing`)},j.id)),Q===`audio`&&Jr&&(0,Z.jsx)(`div`,{className:`w-full max-w-xl max-md:max-w-none`,children:(0,Z.jsx)(Jn,{audioUrl:Jr,mediaRef:an,onBlack:R&&!Zr,edge:R},j.id)}),Q===`document`&&Jr&&($r?(0,Z.jsx)(X.Suspense,{fallback:(0,Z.jsx)(Bn,{}),children:(0,Z.jsx)(Ep,{itemRef:j.id,className:`mx-auto h-full w-full max-w-[960px] border-x border-black/[0.06] bg-zinc-50 dark:border-white/[0.06] dark:bg-white/[0.03]`,onOpenItem:e=>{r.some(t=>t.id===e)?m(e):pe({href:`/app/library/${e}`})}},j.id)}):(0,Z.jsx)(X.Suspense,{fallback:(0,Z.jsx)(Bn,{}),children:(0,Z.jsx)(Tp,{url:Jr,fileName:ei,onDownload:oi,poster:Xn(j)?J(Xn(j)):null,onBlack:R&&!Zr},j.id)})),ri&&(0,Z.jsxs)(`div`,{className:`pointer-events-none absolute inset-x-4 bottom-4 z-10 mx-auto max-w-md rounded-lg bg-zinc-900/80 px-3 py-2 text-center text-[12px] font-[380] max-md:inset-x-3 max-md:bottom-auto max-md:top-[calc(env(safe-area-inset-top)+64px)] max-md:text-[13.5px] leading-relaxed text-white backdrop-blur-sm max-md:flex max-md:items-center max-md:gap-3 max-md:rounded-[14px] max-md:bg-black/50 max-md:py-2.5 max-md:pl-4 max-md:pr-2.5 max-md:text-left max-md:backdrop-blur-md`,children:[(0,Z.jsx)(`span`,{className:`max-md:min-w-0 max-md:flex-1`,children:ri}),ni&&(0,Z.jsxs)(`button`,{type:`button`,disabled:Kt,onClick:()=>void ii(),className:`pointer-events-auto mt-2 flex w-full items-center justify-center gap-1.5 rounded-full bg-white/20 px-3 py-1.5 text-[12px] font-[440] text-white transition-colors hover:bg-white/25 disabled:opacity-60 max-md:mt-0 max-md:h-8 max-md:w-auto max-md:flex-shrink-0 max-md:bg-white max-md:px-3.5 max-md:py-0 max-md:text-[13px] max-md:text-black`,children:[Kt&&(0,Z.jsx)(Dc,{}),`Convert`]})]}),!ri&&!a&&!ti&&Q===`video`&&Jt===j.id&&(0,Z.jsx)(kc,{itemId:j.id,className:`max-md:bottom-auto max-md:top-[calc(env(safe-area-inset-top)+64px)] max-md:inset-x-3 max-md:text-[13.5px]`})]})})}),R&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`div`,{className:N(`absolute inset-x-0 top-0 z-30 flex items-center justify-between px-3 pt-[calc(env(safe-area-inset-top)+11px)]`,!Zr&&`hidden`),children:[(0,Z.jsx)(`button`,{type:`button`,"aria-label":`Back`,onClick:h,className:`flex h-11 w-11 flex-shrink-0 items-center justify-center rounded-full bg-zinc-100/90 text-zinc-700 backdrop-blur-md active:bg-zinc-200/90 data-[state=open]:bg-zinc-200/90 dark:bg-[#202020]/90 dark:text-zinc-200 dark:active:bg-[#2a2a2a]/90 dark:data-[state=open]:bg-[#2a2a2a]/90`,children:(0,Z.jsx)(ct,{className:`h-[22px] w-[22px]`,strokeWidth:1.6})}),e&&r.length>1&&A>=0&&(0,Z.jsxs)(`span`,{className:`pointer-events-none flex h-8 items-center rounded-full bg-zinc-100/90 px-3 text-[13px] font-[440] tabular-nums text-zinc-700 backdrop-blur-md dark:bg-[#202020]/90 dark:text-zinc-200`,children:[A+1,` / `,r.length]}),$i((0,Z.jsx)(`button`,{type:`button`,"aria-label":`More`,className:N(`flex h-11 w-11 flex-shrink-0 items-center justify-center rounded-full bg-zinc-100/90 text-zinc-700 backdrop-blur-md active:bg-zinc-200/90 data-[state=open]:bg-zinc-200/90 dark:bg-[#202020]/90 dark:text-zinc-200 dark:active:bg-[#2a2a2a]/90 dark:data-[state=open]:bg-[#2a2a2a]/90`,`data-[state=open]:bg-zinc-200/90 dark:data-[state=open]:bg-[#2a2a2a]/90`),children:(0,Z.jsx)(ve,{className:`h-5 w-5`,strokeWidth:1.6})}))]}),(0,Z.jsx)(`div`,{className:N(`absolute inset-x-0 bottom-0 z-30 flex justify-center pb-[calc(env(safe-area-inset-bottom)+8px)]`,!Zr&&`hidden`),children:(0,Z.jsxs)(`div`,{className:`flex items-center gap-1 rounded-full bg-zinc-100/90 p-1 backdrop-blur-md dark:bg-[#202020]/90`,children:[O&&(0,Z.jsx)(`button`,{type:`button`,"aria-label":P?`Unstar`:`Star`,"aria-pressed":P,onClick:()=>de(!P),className:N(`flex h-11 w-11 items-center justify-center rounded-full text-zinc-700 active:bg-black/[0.06] dark:text-zinc-200 dark:active:bg-white/[0.08]`,P&&`text-foreground`),children:(0,Z.jsx)(tt,{className:`h-5 w-5`,strokeWidth:1.6,fill:P?`currentColor`:`none`})}),(0,Z.jsxs)(`button`,{type:`button`,"aria-label":$e?`Comments, ${$e} for you`:`Comments`,onClick:()=>Ie(`comments`),className:N(`flex h-11 w-11 items-center justify-center rounded-full text-zinc-700 active:bg-black/[0.06] dark:text-zinc-200 dark:active:bg-white/[0.08]`,`relative`),children:[(0,Z.jsx)(Ye,{className:`h-5 w-5`,strokeWidth:1.6}),$e>
4010&&(0,Z.jsx)(`span`,{"aria-hidden":!0,className:`absolute right-[10px] top-[10px] h-[7px] w-[7px] rounded-full bg-blue-500`})]}),(0,Z.jsx)(`button`,{type:`button`,"aria-label":`Download`,onClick:oi,disabled:M.state===`elsewhere`&&!j.url,className:N(`flex h-11 w-11 items-center justify-center rounded-full text-zinc-700 active:bg-black/[0.06] dark:text-zinc-200 dark:active:bg-white/[0.08]`,`disabled:opacity-40`),children:(0,Z.jsx)(be,{className:`h-5 w-5`,strokeWidth:1.6})}),(0,Z.jsx)(`button`,{type:`button`,"aria-label":`Details`,onClick:()=>Ie(`details`),className:`flex h-11 w-11 items-center justify-center rounded-full text-zinc-700 active:bg-black/[0.06] dark:text-zinc-200 dark:active:bg-white/[0.08]`,children:(0,Z.jsx)(Je,{className:`h-5 w-5`,strokeWidth:1.6})}),Q===`video`&&(0,Z.jsx)(`button`,{type:`button`,"aria-label":`Full screen`,onClick:()=>Up(Xt.current),className:`flex h-11 w-11 items-center justify-center rounded-full text-zinc-700 active:bg-black/[0.06] dark:text-zinc-200 dark:active:bg-white/[0.08]`,children:(0,Z.jsx)(pt,{className:`h-[18px] w-[18px]`,strokeWidth:1.6})})]})}),z&&(0,Z.jsxs)(Z.Fragment,{children:[!K&&(0,Z.jsx)(`div`,{"aria-hidden":!0,className:`absolute inset-0 z-40`,onClick:()=>Ie(null)}),(0,Z.jsx)(`div`,{className:N(`absolute inset-x-0 bottom-0 z-50 h-[66dvh] max-h-[calc(100%-48px)] bg-white pb-[env(safe-area-inset-bottom)] dark:bg-[#1b1b1b]`,K&&`invisible`),children:(0,Z.jsxs)(`div`,{className:`flex h-full flex-col overflow-hidden rounded-t-[12px] bg-white shadow-[0_-8px_32px_rgba(0,0,0,0.12)] animate-in slide-in-from-bottom-8 duration-200 dark:bg-[#1b1b1b] dark:shadow-[0_-8px_32px_rgba(0,0,0,0.5)]`,children:[(0,Z.jsx)(`div`,{className:`flex flex-shrink-0 justify-center pb-0.5 pt-1.5`,onTouchStart:e=>{Be.current=e.touches[0].clientY},onTouchEnd:e=>{let t=Be.current;Be.current=null,t!==null&&e.changedTouches[0]&&e.changedTouches[0].clientY-t>48&&Ie(null)},children:(0,Z.jsx)(`span`,{"aria-hidden":!0,className:`h-1 w-9 rounded-full bg-zinc-300 dark:bg-zinc-600`})}),z===`comments`?(0,Z.jsx)(`div`,{className:`flex min-h-0 flex-1 flex-col overflow-hidden`,children:sa(()=>Ie(null))}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`div`,{className:`flex h-10 flex-shrink-0 items-center pl-4 pr-3`,children:[(0,Z.jsx)(`span`,{className:`min-w-0 flex-1 text-[14.5px] font-[440] text-foreground`,children:`Details`}),(0,Z.jsx)(`button`,{type:`button`,"aria-label":`Close details`,onClick:()=>Ie(null),className:N(Np,`text-zinc-400 dark:text-zinc-500`),children:(0,Z.jsx)(_t,{className:`h-5 w-5`,strokeWidth:1.5})})]}),(0,Z.jsx)(`div`,{className:`phone-details min-h-0 flex-1 overflow-y-auto px-2 pb-[env(safe-area-inset-bottom)]`,children:ca})]})]})})]})]}),R?null:Fe?(0,Z.jsx)(`div`,{className:`absolute right-0 top-0 z-30 m-2 flex w-10 flex-col items-center pt-2`,children:(0,Z.jsx)(`button`,{type:`button`,"aria-label":`Show details`,onClick:()=>Pe(!1),className:Op,children:(0,Z.jsx)(Xe,{className:kp,strokeWidth:Ap})})}):(0,Z.jsxs)(`div`,{className:Ja,children:[(0,Z.jsxs)(`div`,{className:`flex flex-shrink-0 items-center gap-0.5 px-2 pb-1 pt-2`,children:[De===!1&&(0,Z.jsx)(`button`,{type:`button`,"aria-label":`Hide details`,onClick:()=>Pe(!0),className:Op,children:(0,Z.jsx)(qe,{className:kp,strokeWidth:Ap})}),(0,Z.jsx)(`div`,{className:`flex-1`}),(0,Z.jsxs)(`button`,{type:`button`,"aria-label":$e?`Comments, ${$e} for you`:`Comments`,"aria-pressed":Te,onClick:()=>{Ee(e=>!e),He(0)},className:N(Op,`relative`,Te&&ce.footButtonHeld),children:[(0,Z.jsx)(Ye,{className:kp,strokeWidth:Ap}),$e>0&&(0,Z.jsx)(`span`,{"aria-hidden":!0,className:`absolute bottom-[5px] right-[5px] h-[4px] w-[4px] rounded-full bg-blue-500`})]}),O&&(0,Z.jsx)(`button`,{type:`button`,"aria-label":P?`Unstar`:`Star`,"aria-pressed":P,onClick:()=>de(!P),className:N(Op,P&&`text-foreground hover:text-foreground dark:text-foreground`),children:(0,Z.jsx)(tt,{className:kp,strokeWidth:Ap,fill:P?`currentColor`:`none`})}),$i((0,Z.jsx)(`button`,{type:`button`,"aria-label":`More`,className:N(Op,`data-[state=open]:text-foreground`),children:(0,Z.jsx)(ve,{className:kp,strokeWidth:Ap})})),(0,Z.jsx)(`button`,{type:`button`,"aria-label":`Close`,onClick:h,className:Op,children:(0,Z.jsx)(_t,{className:kp,strokeWidth:Ap})})]}),Te?(0,Z.jsx)(`div`,{className:`flex min-h-[0px] flex-1 flex-col overflow-hidden`,children:sa()}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`div`,{className:`min-h-[0px] flex-1 overflow-y-auto px-2 [scrollbar-width:thin]`,children:ca}),(0,Z.jsx)(`div`,{className:`flex-shrink-0 px-3 pb-3 pt-2`,children:(0,Z.jsxs)(`button`,{type:`button`,onClick:oi,disabled:M.state===`elsewhere`&&!j.url,className:N(Dp,`h-9 justify-center text-zinc-600 hover:text-foreground disabled:opacity-50 dark:text-zinc-300 dark:hover:text-foreground`),children:[(0,Z.jsx)(be,{className:`h-3.5 w-3.5 flex-shrink-0`,strokeWidth:1.6}),`Download`]})})]})]})]}),vt,(0,Z.jsx)(Zi,{open:B!==null,onOpenChange:e=>{e||ze(null)},children:(0,Z.jsxs)(ea,{children:[(0,Z.jsxs)(ta,{children:[(0,Z.jsx)(ra,{children:B===`delete`?`Delete this item?`:`Hide from the feed?`}),(0,Z.jsx)(ia,{children:B===`delete`?`It is removed from the library for everyone in the workspace.`:`It stays in the library.`})]}),(0,Z.jsxs)(na,{children:[(0,Z.jsx)(oa,{children:`Cancel`}),(0,Z.jsx)(aa,{onClick:()=>{let e=B;ze(null),e===`delete`?ui():e===`hide`&&di(!0)},children:B===`delete`?`Delete`:`Hide`})]})]})}),wt&&(0,Z.jsx)(Qc,{isOpen:!0,onClose:()=>Tt(null),requiredCredits:wt.required,availableCredits:wt.available}),Ft&&(0,Z.jsx)(Ml,{isOpen:!0,onClose:jt.closeCropper,imageUrl:J(Jr),imageName:ei,isEditable:!0,cropOnly:!0,originalFile:Ft,onImageEdit:e=>jt.applyCrop(e)}),Se&&(0,Z.jsxs)(`div`,{className:`fixed inset-0 z-[115] flex items-center justify-center bg-black/70 p-6 sm:p-12`,onMouseDown:()=>Ce(null),children:[Se.kind===`image`?(0,Z.jsx)(`img`,{src:Se.url,alt:`Source`,className:`max-h-full max-w-full rounded-lg object-contain`}):(0,Z.jsx)(`video`,{src:Se.url,controls:!0,autoPlay:!0,playsInl
401ine:!0,onMouseDown:e=>e.stopPropagation(),className:`max-h-full max-w-full rounded-lg`}),(0,Z.jsx)(`button`,{type:`button`,"aria-label":`Close`,onClick:()=>Ce(null),className:`absolute right-4 top-4 flex h-7 w-7 items-center justify-center rounded-full bg-black/50 text-white hover:bg-black/70 transition-colors max-md:right-3 max-md:top-[calc(env(safe-area-inset-top)+11px)] max-md:h-11 max-md:w-11 max-md:[&_svg]:h-5 max-md:[&_svg]:w-5`,children:(0,Z.jsx)(_t,{className:`h-3.5 w-3.5`,strokeWidth:1.8})})]})]}),document.body)}function Hp({item:e}){let[t,n]=(0,X.useState)(e.description),[r,i]=(0,X.useState)(!1),[a,o]=(0,X.useState)(``);(0,X.useEffect)(()=>{n(e.description),i(!1)},[e.id,e.description]);let s=()=>{i(!1);let r=a.trim();if(!r||r===(t??``))return;let o=t;n(r),k.patch(`/api/library/item-card`,{itemId:e.id,description:r}).catch(e=>{n(o),H.error(e instanceof D?e.message:`Could not save the description`)})},c=`block w-full whitespace-pre-wrap break-words text-left text-[12px] font-[400] leading-[18px]`;return r?(0,Z.jsx)(`textarea`,{autoFocus:!0,ref:Xp,value:a,onChange:e=>{o(e.target.value),Xp(e.currentTarget)},onBlur:s,onKeyDown:e=>{e.stopPropagation(),e.key===`Enter`&&!e.shiftKey&&Hr()&&(e.preventDefault(),s()),e.key===`Escape`&&i(!1)},rows:1,placeholder:`Add a descriptionâ¦`,"aria-label":`Description`,className:N(c,`max-h-[50dvh] resize-none overflow-y-auto bg-transparent p-0 text-foreground outline-none placeholder:text-zinc-400 dark:placeholder:text-zinc-500`)}):t?(0,Z.jsx)(`button`,{type:`button`,"aria-label":`Edit description`,onClick:()=>{o(t),i(!0)},className:N(c,`text-zinc-700 transition-colors hover:text-foreground dark:text-zinc-300 dark:hover:text-white`),children:t.split(/\n\s*\n/).map((e,t)=>(0,Z.jsx)(`span`,{className:N(`block`,t>0&&`mt-2`),children:e},t))}):(0,Z.jsx)(`button`,{type:`button`,onClick:()=>{o(``),i(!0)},className:N(c,`text-zinc-400 transition-colors hover:text-foreground dark:text-zinc-500`),children:`Add a description`})}function Up(e){let t=e;if(!t)return;let n=()=>{t.webkitEnterFullscreen?t.webkitEnterFullscreen():t.requestFullscreen?.()};try{n()}catch{t.play().then(()=>{try{n()}catch{}}).catch(()=>{})}}var Wp=!0;function Gp({videoRef:e,barsShown:t,onTap:n,autoPlay:r,startMuted:i}){let[a,o]=(0,X.useState)(!1),[s,c]=(0,X.useState)(0),[l,u]=(0,X.useState)(0),[d,f]=(0,X.useState)(!1),[p,m]=(0,X.useState)(!1);(0,X.useEffect)(()=>{let t=e.current;if(!t)return;let n=()=>{o(!t.paused),c(t.currentTime),u(Number.isFinite(t.duration)?t.duration:0),f(t.muted)},a=[`play`,`pause`,`timeupdate`,`durationchange`,`loadedmetadata`,`volumechange`,`ended`];return a.forEach(e=>t.addEventListener(e,n)),n(),t.muted=i??!Wp,r&&t.play().catch(()=>{t.muted||(t.muted=!0,t.play().catch(()=>{}))}),()=>a.forEach(e=>t.removeEventListener(e,n))},[e]);let h=()=>{let t=e.current;t&&(t.paused?t.play().catch(()=>{}):t.pause())},g=e=>e.stopPropagation(),_=l>0?Math.min(1,Math.max(0,s/l)):0,v=t=>{let n=e.current;if(!n||!(l>0))return;let r=t.currentTarget.getBoundingClientRect(),i=Math.min(1,Math.max(0,(t.clientX-r.left)/r.width))*l;n.currentTime=i,c(i)};return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`div`,{className:`absolute inset-0 z-10`,onClick:n}),t&&(0,Z.jsxs)(`div`,{className:`fixed inset-x-4 z-30 flex h-[52px] items-center gap-1 rounded-full bg-zinc-100/90 px-1 text-zinc-700 backdrop-blur-md dark:bg-[#202020]/90 dark:text-zinc-200`,style:{bottom:`calc(env(safe-area-inset-bottom) + 68px)`},children:[(0,Z.jsx)(`button`,{type:`button`,"aria-label":a?`Pause`:`Play`,onClick:h,className:`flex h-11 w-11 items-center justify-center rounded-full text-zinc-700 active:bg-black/[0.06] dark:text-zinc-200 dark:active:bg-white/[0.08]`,children:a?(0,Z.jsx)(mt,{className:`h-5 w-5`,fill:`currentColor`,strokeWidth:0}):(0,Z.jsx)(ht,{className:`h-5 w-5`,fill:`currentColor`,strokeWidth:0})}),(0,Z.jsxs)(`div`,{role:`slider`,"aria-label":`Position`,"aria-valuemin":0,"aria-valuemax":Math.round(l),"aria-valuenow":Math.round(s),className:`relative mx-1.5 flex h-11 min-w-0 flex-1 touch-none items-center`,onPointerDown:e=>{e.currentTarget.setPointerCapture(e.pointerId),m(!0),v(e)},onPointerMove:e=>{e.currentTarget.hasPointerCapture(e.pointerId)&&v(e)},onPointerUp:()=>m(!1),onPointerCancel:()=>m(!1),onTouchStart:g,onTouchMove:g,onTouchEnd:g,children:[(0,Z.jsxs)(`div`,{className:`relative h-1 w-full rounded-full bg-zinc-400/40 dark:bg-white/25`,children:[(0,Z.jsx)(`div`,{className:`absolute inset-y-0 left-0 rounded-full bg-zinc-800 dark:bg-white`,style:{width:`${_*100}%`}}),(0,Z.jsx)(`div`,{className:`absolute top-1/2 h-3.5 w-3.5 -translate-x-1/2 -translate-y-1/2 roun
401ded-full bg-zinc-800 dark:bg-white`,style:{left:`${_*100}%`}})]}),p&&(0,Z.jsxs)(`span`,{className:`pointer-events-none absolute -top-9 left-1/2 -translate-x-1/2 rounded-full bg-zinc-900/80 px-2.5 py-1 text-[12px] font-[400] tabular-nums text-white`,children:[q(s),` / `,q(l)]})]}),(0,Z.jsx)(`button`,{type:`button`,"aria-label":d?`Unmute`:`Mute`,onClick:()=>{let t=e.current;t&&(t.muted=!t.muted,Wp=!t.muted)},className:N(`flex h-11 w-11 items-center justify-center rounded-full text-zinc-700 active:bg-black/[0.06] dark:text-zinc-200 dark:active:bg-white/[0.08]`,`flex-shrink-0`),children:d?(0,Z.jsx)(ze,{className:`h-5 w-5`,strokeWidth:1.6}):(0,Z.jsx)(Ue,{className:`h-5 w-5`,strokeWidth:1.6})})]})]})}var Kp=`whitespace-pre-wrap break-words px-0 py-0 text-[12px] font-[460] leading-[18px] text-foreground`;function qp(e){let t=(e?.transcript??null)?.sentences;if(!Array.isArray(t)||t.length===0)return null;let n=t.flatMap(e=>{let t=e,n=typeof t.text==`string`?t.text.trim():``;return n&&typeof t.start==`number`&&Number.isFinite(t.start)?[{text:n,start:t.start}]:[]});return n.length>0?n:null}function Jp(e){return e.replace(/([.?!â¦"'])\s+-\s+/g,`$1 402- `)}function Yp(e,t){let n=qp(t);return n?n.map(e=>`${q(e.start)} ${e.text}`).join(` 403`):Jp(e)}function Xp(e){e&&(e.style.height=`auto`,e.style.height=`${e.scrollHeight}px`)}var Zp=`mr-2.5 h-3.5 w-3.5 flex-shrink-0 text-zinc-500 dark:text-zinc-400`,Qp=`flex min-h-[28px] w-full min-w-0 items-center rounded-[7px] px-1.5 py-1 text-left text-[12px] font-[400] text-zinc-700 dark:text-zinc-300 max-md:min-h-[34px]`,$p=`cursor-pointer transition-colors duration-100 hover:text-foreground data-[state=open]:text-foreground dark:hover:text-white dark:data-[state=open]:text-white [&:hover_.text-zinc-400]:text-zinc-500 dark:[&:hover_.text-zinc-500]:text-zinc-400`;function em({label:e,value:t,empty:n=`None`,menu:r,onClick:i}){let a=t||(0,Z.jsx)(`span`,{className:`text-zinc-400 dark:text-zinc-500`,children:n});return(0,Z.jsxs)(`div`,{className:`flex items-start gap-1`,children:[(0,Z.jsx)(`dt`,{className:jp,children:e}),(0,Z.jsx)(`dd`,{className:`min-w-0 flex-1`,children:r?(0,Z.jsxs)(hn,{children:[(0,Z.jsx)(dn,{asChild:!0,children:(0,Z.jsxs)(`button`,{type:`button`,className:N(Qp,$p),children:[(0,Z.jsxs)(`span`,{className:`sr-only`,children:[e,`: `]}),a]})}),(0,Z.jsx)(mn,{align:`start`,className:`max-h-72 w-52 overflow-y-auto`,onCloseAutoFocus:e=>e.preventDefault(),children:r})]}):i?(0,Z.jsx)(`button`,{type:`button`,onClick:i,className:N(Qp,$p),children:a}):(0,Z.jsx)(`div`,{className:Qp,children:a})})]})}var tm=new Map,nm=new Map,rm=new Map;function im(e,t=!1){let n=rm.get(e);if(n&&!t)return n;let r=k.get(`/api/library/items/${e}/where-used`).then(t=>(nm.set(e,t),t)).catch(()=>null).finally(()=>{window.setTimeout(()=>rm.delete(e),3e4)});return rm.set(e,r),r}var am=new Map,om=new Map;function sm(e){let t=om.get(e);if(t)return t;let n=k.get(`/api/library/item-links?itemId=${e}`).then(t=>(am.set(e,t),t)).catch(()=>null).finally(()=>{window.setTimeout(()=>om.delete(e),3e4)});return om.set(e,n),n}function cm({title:e,href:t,external:n=!1,onClick:r}){let i=b(),a=N(Qp,$p),o=(0,Z.jsx)(`span`,{className:`min-w-0 truncate`,children:e});return t&&n?(0,Z.jsx)(`a`,{href:t,target:`_blank`,rel:`noreferrer`,className:a,children:o}):!t&&!r?(0,Z.jsx)(`div`,{className:Qp,children:o}):(0,Z.jsx)(`button`,{type:`button`,onClick:t?()=>i({href:t}):r,className:a,children:o})}function lm({children:e}){let[t,n]=(0,X.useState)(!1),r=e.length>um;return(0,Z.jsxs)(Z.Fragment,{children:[t||!r?e:e.slice(0,um),r&&(0,Z.jsx)(`button`,{type:`button`,"aria-expanded":t,onClick:()=>n(e=>!e),className:N(Qp,$p),children:t?`Hide`:`Show all ${e.length}`})]})}var um=3;function dm({label:e,children:t}){return(0,Z.jsxs)(`div`,{className:`flex items-start gap-1`,children:[(0,Z.jsx)(`dt`,{className:jp,children:e}),(0,Z.jsx)(`dd`,{className:`flex min-w-0 flex-1 flex-col`,children:t})]})}var fm=new Map;function pm(e){return e}function mm(e){return fm.get(pm(e))}function hm(e,t){fm.set(pm(e),t)}async function gm(e){try{let t=await k.get(`/api/library/item-card`,{query:{itemId:e}}),n={description:t.card?.description??null,tags:Array.isArray(t.card?.tags)?t.card.tags:[],short_ref:t.card?.short_ref??null};return hm(e,n),n}catch{return null}}function _m(e,t){let n=URL.createObjectURL(e),r=document.createElement(`a`);r.href=n,r.download=t,document.body.appendChild(r),r.click(),r.remove(),setTimeout(()=>URL.revokeObjectURL(n),1e4)}var vm=new Set;async function ym(e){let t=mm(e.id);if(t)return t.short_ref;if(vm.has(e.id))return null;let n=await gm(e.id);return n?n.short_ref:(vm.add(e.id),null)}function bm(e,t){if(!t||e.toUpperCase().includes(t.toUpperCase()))return e;let n=e.lastIndexOf(`.`);return n>0&&e.length-n<=6?`${e.slice(0,n)}_${t}${e.slice(n)}`:`${e}_${t}`}async function xm(e,t,n,r){try{let n=r?bm(t,await ym(r)):t,i=await fetch(e);if(!i.ok)throw Error(`fetch failed: ${i.status}`);return _m(await i.blob(),n),!0}catch{return window.open(n??e,`_blank`,`noopener`),!1}}var Sm=null,Cm=null,wm=new Set,Tm=()=>
403wm.forEach(e=>e()),Em=e=>{Sm=e,Tm()},Dm={subscribe(e){return wm.add(e),()=>{wm.delete(e)}},get:()=>Sm,close(){Cm?.abort(),Cm=null,Em(null)}};function Om(e){return navigator.share({files:e}).then(()=>!0,e=>e instanceof DOMException&&e.name===`AbortError`)}var km=600,Am=314572800;async function jm(e){Cm?.abort();let t=new AbortController;Cm=t;let n=e.length===1?e[0].name:`${e.length} items`,r=!1,i=null,a=setTimeout(()=>{r=!0,Em({name:n,progress:i,files:null,missed:0,failed:!1})},km),o=[],s=0,c=0,l=!1;for(let[n,u]of e.entries()){if(!u.url){s++;continue}try{let a=await fetch(u.url,{signal:t.signal});if(!a.ok||!a.body)throw Error(`fetch failed: ${a.status}`);let s=Number(a.headers.get(`content-length`))||0;if(c+s>Am){a.body.cancel(),l=!0;break}let d=a.body.getReader(),f=[],p=0;for(;;){let{done:t,value:a}=await d.read();if(t)break;if(f.push(a),p+=a.byteLength,c+p>Am){d.cancel(),l=!0;break}(s>0||e.length>1)&&(i=Math.min(1,(n+(s>0?p/s:0))/e.length),r&&Sm&&Em({...Sm,progress:i}))}if(l)break;c+=p,o.push(new File(f,u.name,{type:a.headers.get(`content-type`)||`application/octet-stream`}))}catch{if(t.signal.aborted)return clearTimeout(a),!0;s++}}return clearTimeout(a),Cm===t&&(Cm=null),l||o.length>0&&!navigator.canShare({files:o})?(Em(null),!1):o.length===0?r?(Em({name:n,progress:null,files:null,missed:s,failed:!0}),!0):!1:(!r&&s===0&&await Om(o)||Em({name:n,progress:1,files:o,missed:s,failed:!1}),!0)}var Mm=4;function Nm(e,t=`here`){let n=a&&t===`here`?or(e)?.path.split(/[\\/]/).pop()?.match(/\.(?=[A-Za-z0-9]*[A-Za-z])[A-Za-z0-9]{2,5}$/)?.[0]:void 0;if(e.file_name)return bm(n?ir(e.file_name,n):e.file_name,e.short_ref);let r=e.title?.trim()?.slice(0,40)||`file`,i=e.url?.split(`?`)[0].split(`.`).pop();return bm(`${r}.${i&&i.length<=4?i:`bin`}`,e.short_ref)}async function Pm(e){let t=or(e);if(t&&a){let e=await a.media.open(t.path).catch(()=>null);if(e&&!(`missing`in e))return e.url}return e.url&&J(e.url)||null}async function Fm(e){let t=a?.media.saveCopies;if(!t)return!1;let n=e.flatMap(e=>{let t=or(e)?.path,n=e.url?J(e.url):``,r=t&&n?Nm(e,`cloud`):void 0;return t||n?[{name:Nm(e),...t?{path:t}:{},...n?{url:n}:{},...r&&r!==Nm(e)?{cloudName:r}:{}}]:[]}),r=e.length-n.length;if(n.length===0)return H.message(e.length===1?`This file is stored locally on another device and not synced yet`:`These files are stored locally on another device and not synced yet`),!0;let i=H.loading(n.length===1?`Downloadingâ¦`:`Downloading ${n.length} itemsâ¦`),o=await t(n).catch(()=>({saved:0,failed:n.length}));if(!o)return H.dismiss(i),!0;let s=[r>0?`${r} on another device`:null,o.failed>0?`${o.failed} could not be downloaded`:null].filter(Boolean).join(`, `);return o.saved===0?H.error(`Could not download`,{id:i,duration:4e3}):s?H.success(`Downloaded ${o.saved} of ${e.length} items. ${s}`,{id:i,duration:4e3}):H.success(o.saved===1?`Downloaded`:`Downloaded ${o.saved} items`,{id:i}),!0}async function Im(e,t){if(n(e.media_type??`file`,t),await Fm([e]))return;let r=await Pm(e);if(!r){H.message(`This file is stored locally on another device and not synced yet`);return}if(await Lm([{url:r,name:Nm(e)}]))return;let i=H.loading(`Downloadingâ¦`);await xm(r,Nm(e))?H.success(`Downloaded`,{id:i}):H.dismiss(i)}async function Lm(e){return typeof navigator>`u`||!navigator.canShare||!window.matchMedia(`(pointer: coarse)`).matches?!1:jm(e)}async function Rm({items:t,selectedIds:i,where:a}){let o=t.filter(e=>i.has(e.id)),s=o.length;if(s===0)return;if(s===1){await Im(o[0],a);return}let c=new Set(o.map(e=>e.media_type??`file`));if(n(c.size===1?[...c][0]:`mixed`,a,s),await Fm(o)||await Lm(await Promise.all(o.map(async e=>({url:await Pm(e),name:Nm(e)})))))return;let l=H.loading(`Downloading ${s} itemsâ¦`);try{let t=(await r(async()=>{let{default:t}=await import(`./jszip.min-DIgHJL1D.js`).then(t=>e(t.default,1));return{default:t}},__vite__mapDeps([67,2]))).default,n=new t,i=new Set,a=e=>{let t=e,n=1;for(;i.has(t);){let r=e.lastIndexOf(`.`);t=r>0?`${e.slice(0,r)} (${n})${e.slice(r)}`:`${e} (${n})`,n++}return i.add(t),t},c=0,u=0,d=0;await Promise.all(Array.from({length:Math.min(Mm,s)},async()=>{for(let e=d++;e<s;
403e=d++){let t=o[e],r=await Pm(t);if(!r){c++;continue}try{let e=await fetch(r);if(!e.ok)throw Error(String(e.status));n.file(a(Nm(t)),await e.blob())}catch{u++}}}));let f=s-c-u;if(f===0){H.error(c===s?`These files are stored locally on another device and not synced yet`:`Could not download`,{id:l,duration:4e3});return}_m(await n.generateAsync({type:`blob`}),`eversince-library.zip`);let p=[c>0?`${c} on another device`:null,u>0?`${u} could not be downloaded`:null].filter(Boolean).join(`, `);p?H.success(`Downloaded ${f} of ${s} items. ${p}`,{id:l,duration:4e3}):H.success(`Downloaded ${f} items`,{id:l})}catch{H.error(`Could not download`,{id:l,duration:4e3})}}function zm({items:e,current:t,onSelect:n,onClose:r,onChanged:i,onDeleted:a,onItemCreated:o,openOnComments:s,onHide:c,counted:l}){let{user:u}=A(),{renameLibraryItem:d,moveToFolder:f,remove:p}=za({onChanged:i,onDeleted:a});return(0,Z.jsx)(Vp,{items:e,current:t,openOnComments:s,counted:l,getItemUrl:e=>e.url??void 0,onSelect:n,onClose:r,onDownload:e=>Im(e,`viewer`),onRename:d,onMove:(e,t)=>void f(e,t),onDelete:e=>void p(e.id,{onRemoved:r}),onGenerationCreated:i,onItemCreated:o,currentUserId:u?.id??null,onToggleFavorite:e=>{Nc(t,e).then(()=>i?.())},onHide:c})}var Bm=36e5,Vm=6e4,Hm={usage:Pt({queryKey:[`settings`,`usage`],queryFn:async()=>(await k.get(`/api/account/usage`)).usage,staleTime:Vm,gcTime:Bm}),invoices:Pt({queryKey:[`settings`,`invoices`],queryFn:async()=>(await k.get(`/api/account/invoices`)).invoices??[],staleTime:Bm,gcTime:Bm}),modelDefaults:Pt({queryKey:[`settings`,`model-defaults`],queryFn:async()=>{let e=await k.get(`/api/account/model-defaults`);return{video:e?.video_model??null,image:e?.image_model??null,music:e?.music_model??null}},staleTime:Bm,gcTime:Bm}),grants:Pt({queryKey:[`settings`,`grants`],queryFn:async()=>{let e=await k.get(`/api/oauth/grants`);return{grants:Array.isArray(e.grants)?e.grants:[],sessions:Array.isArray(e.sessions)?e.sessions:[]}},staleTime:0,gcTime:Bm}),skills:Pt({queryKey:[`settings`,`skills`],queryFn:async()=>(await k.get(`/api/skills`,{query:{full:1}})).skills??[],staleTime:Vm,gcTime:Bm}),developer:Pt({queryKey:[`settings`,`developer`],queryFn:()=>k.get(`/api/account/developer`),staleTime:5*Vm,gcTime:Bm}),storage:Pt({queryKey:[`settings`,`storage`],queryFn:async()=>{if(!a?.storage)throw Error(`No storage bridge`);return a.storage.usage()},staleTime:Vm,gcTime:Bm})};function Um(){U.prefetchQuery(Hm.usage).catch(()=>void 0),U.prefetchQuery(Hm.modelDefaults).catch(()=>void 0),U.prefetchQuery(Hm.grants).catch(()=>void 0),U.prefetchQuery(Hm.skills).catch(()=>void 0),U.prefetchQuery(Hm.developer).catch(()=>void 0),U.prefetchQuery(Hm.invoices).catch(()=>void 0),a?.storage&&U.prefetchQuery(Hm.storage).catch(()=>void 0)}var Wm=6e4,Gm=(0,X.createContext)(void 0);function Km({children:e}){let{user:t,loading:n}=A(),{data:r,isPending:i,dataUpdatedAt:a,refetch:o}=Vr({...Hm.usage,enabled:!!t&&!n}),s=(0,X.useRef)(0);a&&(s.current=a),(0,X.useEffect)(()=>{if(!t)return;let e=()=>{s.current&&(x()||Date.now()-s.current>Wm)&&o()};return window.addEventListener(`focus`,e),()=>window.removeEventListener(`focus`,e)},[t,o]);let c=(0,X.useMemo)(()=>{let e=t?r??null:null;return{plan:e?.plan??`free`,subscription:e?.subscription??null,usage:e,pastDue:e?.subscription?.status===`past_due`,loading:n||!!t&&i,refresh:async()=>{await o()}}},[t,n,r,i,o]);return(0,Z.jsx)(Gm.Provider,{value:c,children:e})}function qm(){let e=(0,X.useContext)(Gm);if(e===void 0)throw Error(`useSubscription must be used within a SubscriptionProvider`);return e}var Jm=3e5,Ym=1500;function Xm(e){let t=JSON.stringify(e),n=yi(),{known:r,activation:i}=C(),{activeWorkspaceId:a}=Nt(),{members:o}=vi(a),s=(r&&!!i?.canWork||(o??[]).length>1)&&n;(0,X.useEffect)(()=>{if(!s)return;let e=()=>{k.post(`/api/workspaces/presence`,{surface:JSON.parse(t)}).catch(()=>void 0)},n=window.setTimeout(e,t===`null`?0:Ym),r=t===`null`?null:window.setInterval(e,Jm);return()=>{window.clearTimeout(n),r!==null&&window.clearInterval(r)}},[t,s])}var Zm=(0,X.createContext)(null);function Qm({children:e}){let[t,n]=(0,X.useState)(null),r=(0,X.useRef)(null),i=(0,X.useCallback)(e=>{r.current=e,n(e)},[]),a=(0,X.useCallback)(()=>r.current,[]);Xm(t);let o=(0,X.useMemo)(()=>({surface:t,setSurface:i,read:a}),[t,i,a]);return(0,Z.jsx)(Zm.Provider,{value:o,children:e})}var $m={surface:null,setSurface:()=>{},read:()=>null};function eh(){return(0,X.useContext)(Zm)??$m}export{id as $,ta as $n,Rs as $t,wf as A,no as An,Bc as At,yf as B,Ba as Bn,Ec as Bt,np as C,jo as Cn,cl as Ct,Of as D,vo as Dn,Qc as Dt,rp as E,Oo as En,pl as Et,Nf as F,Xa as Fn,Mc as Ft,Xd as G,ca as Gn,_c as Gt,gf as H,Ua as Hn,vc as Ht,Tf as I,Ya as In,Ac as It,fd as J,aa as Jn,Zs as Jt,_d as K,sa as Kn,fc as Kt,Pf as L,qa as Ln,kc as Lt,kf as M,to as Mn,Fc as Mt,Af as N,$a as Nn,Pc as Nt,jf as O,So as On,Uc as Ot,Df as P,Wa as Pn,Nc as Pt,td as Q,na as Qn,zs as Qt,_f as R,Ga as Rn,Oc as Rt,Qf as S,ko as Sn,ll as St,Jf as T,Ao as Tn,nl as Tt,vf as U,za as Un,yc as Ut,hf as V,Ha as Vn,gc as Vt,pf as W,Na as Wn,dc as Wt,Yu as X,ea as Xn,Hs as Xt,Zu as Y,oa as Yn,Us as Yt,rd as Z,ia as Zn,Vs as Zt,yp as _,Ro as _n,xr as _r,Ml as _t,Hm as a,Ts as an,vi as ar,Pu as at,sp as b,To as bn,fl as bt,Im as c,Ms as cn,Qr as cr,Kl as ct,Om as d,xs as dn,Zr as dr,tu as dt,Bs as en,ra as er,ed as et,Vp as f,Ss as fn,Xr as fr,Ql as ft,mp as g,gs as gn,Sr as gr,Fl as gt,xp as h,vs as hn,Vr as hr,Hl as ht,qm as i,Os as in,yi as ir,Iu as it,Ef as j,eo as jn,zc as jt,Mf as k,bo as kn,Vc as kt,Rm as l,hs as ln,si as lr,ql as lt,wp as m,ys as mn,Hr as mr,Ul as mt,eh as n,Cs as nn,Ei as nr,Nu as nt,Um as o,Es as on,di as or,ru as ot,Fp as p,_s as pn,Yr as pr,Zl as pt,pd as q,Zi as qn,Qs as qt,Km as r,Ds as rn,wi as rr,Fu as rt,zm as s,js as sn,$ as sr,Yl as st,Qm as t,Ls as tn,Ti as tr,Qu as tt,Dm as u,bs as un,qr as ur,Jl as ut,hp as v,Io as vn,kl as vt,Zf as w,No as wn,ol as wt,op as x,Mo as xn,ml as xt,bp as y,Eo as yn,$c as yt,Cf as z,Va as zn,Dc as zt};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.