@fungi.computer/prints 0.20.1 → 0.20.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -6
- package/dist/assets/audio-waveform-view-D-icMwdH.js +1 -0
- package/dist/assets/audio-waveform-xSq1S4ms.js +1 -0
- package/dist/assets/generation-quote-QXeME8FS.js +2 -0
- package/dist/assets/index-Cjzb4woV.js +2 -0
- package/dist/assets/print-info-drawer-Ch9LLyz1.js +2 -0
- package/dist/assets/{print-viewer-D7p4Tznx.js → print-viewer-CUqQskbh.js} +1 -1
- package/dist/assets/{prints-folder-dialog--W4H7Jx6.js → prints-folder-dialog-ScKmgagw.js} +1 -1
- package/dist/assets/textarea-DUwcxEMN.js +1 -0
- package/dist/assets/{upload-queue-BHAaEiPu.js → upload-queue-BHNUzgYV.js} +1 -1
- package/dist/index.html +6 -6
- package/package.json +9 -8
- package/dist/assets/audio-waveform-Be5wRu8s.js +0 -1
- package/dist/assets/audio-waveform-view-DbTyVH72.js +0 -1
- package/dist/assets/generation-quote-DcaCSlvV.js +0 -2
- package/dist/assets/index-D-LwJiG1.js +0 -2
- package/dist/assets/print-info-drawer-DDZan_oj.js +0 -2
- package/dist/assets/textarea-LIOZDOK4.js +0 -1
package/README.md
CHANGED
|
@@ -11,7 +11,22 @@ on your own Cloudflare account. On Oyster, Prints generates with Workers AI and
|
|
|
11
11
|
saves every file to a folder on the Computer, a Linux workspace in a Cloudflare
|
|
12
12
|
Container.
|
|
13
13
|
|
|
14
|
-
##
|
|
14
|
+
## Quick start
|
|
15
|
+
|
|
16
|
+
In a Fungi monorepo checkout with dependencies installed, run the component
|
|
17
|
+
workbench from the root:
|
|
18
|
+
|
|
19
|
+
```sh
|
|
20
|
+
pnpm workbench:prepare
|
|
21
|
+
pnpm exec ladle serve --port 61983
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Open <http://localhost:61983/?story=prints--studio&mode=preview&theme=light>.
|
|
25
|
+
This is Prints's real UI with local fixture data (a sample gallery; nothing is
|
|
26
|
+
generated), not a live Oyster. To run Prints on a real Oyster, see
|
|
27
|
+
[Get it](#get-it).
|
|
28
|
+
|
|
29
|
+
## Common tasks
|
|
15
30
|
|
|
16
31
|
- Type a prompt, pick a model and a size, and generate an image or a video. Each
|
|
17
32
|
file keeps its model's native format: PNG where the model supports it, JPEG
|
|
@@ -61,7 +76,9 @@ Container.
|
|
|
61
76
|
|
|
62
77
|
<img alt="Prints on a phone in the light theme: the Folders button, the Folder, All and Favorites switch, folder tiles and a two-column wall above the prompt bar" src="docs/media/gallery-phone.png" width="300">
|
|
63
78
|
|
|
64
|
-
##
|
|
79
|
+
## Reference
|
|
80
|
+
|
|
81
|
+
### Get it
|
|
65
82
|
|
|
66
83
|
Prints installs with the other starter Apps. On a deployed Oyster (see the
|
|
67
84
|
[Oyster quick start](https://github.com/fungi-computer/oyster#deploy-to-cloudflare)),
|
|
@@ -79,7 +96,7 @@ at `$OYSTER_URL/login` with the owner key and open Prints from the Tourtois
|
|
|
79
96
|
desktop. Run `install-apps` again to update; each App keeps its data. Generation
|
|
80
97
|
uses Workers AI on your Cloudflare account.
|
|
81
98
|
|
|
82
|
-
|
|
99
|
+
### Change it
|
|
83
100
|
|
|
84
101
|
Every installed App is also a template you can fork on your own Oyster. Fork
|
|
85
102
|
Prints into a Bonsai repository and clone it with ordinary `git`:
|
|
@@ -102,7 +119,7 @@ your forks with `--repositories <base URL>` and `--ref <branch or tag>`. The
|
|
|
102
119
|
installer reads all seven starter Apps from that base, so fork them under one
|
|
103
120
|
account.
|
|
104
121
|
|
|
105
|
-
|
|
122
|
+
### Agent tools
|
|
106
123
|
|
|
107
124
|
Agents call Prints through Oyster's MCP endpoint, or at
|
|
108
125
|
`POST $OYSTER_URL/apps/prints/methods/<name>` with a key; see
|
|
@@ -153,7 +170,7 @@ fund the request, not a Team credit refusal. Check the account's credits and
|
|
|
153
170
|
billing in the Cloudflare dashboard under AI Gateway or choose a Workers AI
|
|
154
171
|
model; do not retry a `retryable: false` result.
|
|
155
172
|
|
|
156
|
-
|
|
173
|
+
### Build and check
|
|
157
174
|
|
|
158
175
|
Prints is a React App built with Vite, with controls from
|
|
159
176
|
[Caps](https://github.com/fungi-computer/caps). Its backend keeps folder
|
|
@@ -175,6 +192,6 @@ records each finished print. The agent tools are in
|
|
|
175
192
|
[backend/methods.ts](backend/methods.ts), and [package.json](package.json)
|
|
176
193
|
declares the permissions the App asks for.
|
|
177
194
|
|
|
178
|
-
|
|
195
|
+
### License
|
|
179
196
|
|
|
180
197
|
MIT. See [LICENSE](LICENSE).
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{C as t,Cn as n,En as r,F as i,I as a,O as o,Tn as s,V as c,Vn as l,W as u,_ as d,_n as f,at as p,bn as m,d as h,dn as g,fn as _,g as v,gn as y,it as b,l as x,m as S,n as C,sn as w,t as T,v as E,w as D,wn as O,x as k,yn as A}from"./button-oE2Hrd5D.js";import{Mt as j,a as M,i as N,jt as P,o as F,r as I,s as L,zt as R}from"./dist-DAokFn5x.js";import{c as z,d as ee,n as B}from"./library-view-BBAeJjj6.js";import{t as V}from"./log-event-B3BGsDWO.js";import{g as H,h as te,i as ne,m as U,t as W}from"./query-CYqgVHJ7.js";import{G,K,O as re,W as ie,a as ae,c as oe,i as se,l as q,n as ce,o as le,t as ue}from"./audio-waveform-xSq1S4ms.js";import{a as de,i as fe,n as pe,o as me,r as he,t as ge}from"./computer-Bfe-Ioxr.js";import{i as _e,o as ve,r as ye,t as be}from"./status-DNJRO5m5.js";import{r as xe}from"./modules-C4mfDnjH.js";import{Dt as Se,Et as Ce,Ot as we,Tn as Te,Tt as Ee,an as De,gn as Oe,in as ke,mn as Ae,sn as je,wn as Me,xn as Ne,yn as Pe}from"./useTriggerFocusGuards-Bddw7Qdn.js";import{c as Fe,l as Ie,n as Le,r as Re,t as ze}from"./dropdown-menu-CAHLGfkb.js";import{t as Be}from"./keycap-D2RkH2IS.js";var Ve=class extends U{constructor(e,t){super(e,t)}bindMethods(){super.bindMethods(),this.fetchNextPage=this.fetchNextPage.bind(this),this.fetchPreviousPage=this.fetchPreviousPage.bind(this)}setOptions(e){e._type=`infinite`,super.setOptions(e)}getOptimisticResult(e){return e._type=`infinite`,super.getOptimisticResult(e)}fetchNextPage(e){return this.fetch({...e,meta:{fetchMore:{direction:`forward`}}})}fetchPreviousPage(e){return this.fetch({...e,meta:{fetchMore:{direction:`backward`}}})}createResult(e,t){let{state:n}=e,r=super.createResult(e,t),{isFetching:i,isRefetching:a,isError:o,isRefetchError:s}=r,c=n.fetchMeta?.fetchMore?.direction,l=o&&c===`forward`,u=i&&c===`forward`,d=o&&c===`backward`,f=i&&c===`backward`;return{...r,fetchNextPage:this.fetchNextPage,fetchPreviousPage:this.fetchPreviousPage,hasNextPage:te(t,n.data),hasPreviousPage:H(t,n.data),isFetchNextPageError:l,isFetchingNextPage:u,isFetchPreviousPageError:d,isFetchingPreviousPage:f,isRefetchError:s&&!l&&!d,isRefetching:a&&!u&&!f}}};function He(e){return e}function Ue(e,t){return K(e,Ve,t)}var We=c([a({kind:o(`compose`),text:i.pipe(u(p(1)),u(b(2e3)))}),a({kind:o(`navigate`),params:D(a({key:i.pipe(u(p(1)),u(b(64))),value:i.pipe(u(b(1024)))})).pipe(u(b(16)))})]);c([a({role:i.pipe(u(p(1)),u(b(80))),intent:We}),a({appId:i.pipe(u(p(1)),u(b(128))),intent:We})],{mode:`oneOf`});var Ge=n({displayName:O().min(1).max(80).nullable()}).nullable(),Ke=L(`apps.open`,1,y(()=>N({open:F,role:M(I(Ge))})));L(`apps.call`,1,y(()=>N({call:M(I(r().transform(e=>R(e))))})));var qe=O().regex(/^[a-zA-Z0-9._-]{1,128}$/).refine(e=>e!==`.`&&e!==`..`),J=O().regex(/^[0-9a-f]{40}$/);n({ref:O().startsWith(`refs/`).max(1024),before:J,after:J}),y(()=>O().min(1).max(512));var Je=`files`,Ye=n({name:O(),email:O()}),Xe=n({hash:J,treeHash:J,message:O(),author:Ye,committer:Ye,parents:g(J),authoredAt:A(),committedAt:A()}),Ze=n({name:O(),mode:O(),hash:J,type:w([`blob`,`tree`,`commit`])});n({ref:O(),commit:Xe,path:O(),entries:g(Ze)});var Qe=65536,$e=O().min(1).max(1024).refine(e=>!e.startsWith(`/`)&&!e.includes(`\\`)&&!e.includes(`\0`)&&e.split(`/`).every(e=>e!==``&&e!==`.`&&e!==`..`&&e!==`.git`),`Choose a relative repository file path.`),et=O().min(1).max(256),tt={repo:qe,branch:et,path:$e},nt=w([`pending`,`synced`,`conflict`,`failed`]),rt=n({text:O(),revision:A().int().positive(),state:nt,theirs:n({blob:J.nullable(),commit:J}).optional(),failure:w([`branch_missing`,`access_changed`,`sync_failed`,`permanent_material`]).optional()});n({...tt,baseBlob:J.nullable(),baseCommit:J,text:O().max(Qe),revision:A().int().positive().nullable()});var it=s([n({kind:f(`saved`),revision:A().int().positive(),state:f(`pending`)}),n({kind:f(`synced`),revision:A().int().positive(),commit:J}),n({kind:f(`conflict`),revision:A().int().nonnegative(),theirs:rt.shape.theirs.optional()}),n({kind:f(`failed`),revision:A().int().positive(),reason:w([`branch_missing`,`access_changed`,`sync_failed`,`permanent_material`])}),n({kind:f(`refused`),reason:w([`not-source-writer`,`background-unavailable`])})]);n({...tt,revision:A().int().positive()}),s([n({kind:w([`discarded`,`not_found`])}),n({kind:f(`conflict`),revision:A().int().positive()})]),n({settled:g(n({...tt,result:it})),more:_()}),n({version:A().int().positive().nullable(),commit:J,blob:J.nullable(),pending:rt.optional(),ref:O(),path:O(),size:A(),binary:_(),text:O().nullable()}),n({ref:O(),commits:g(n({commit:Xe,agent:O().nullable()})),next:O().optional()}),n({ref:O(),commit:Xe,paths:g(O()),truncated:_()}),n({kind:f(`rebuilding`)}),n({done:_(),cursor:O().nullable()}),s([n({repository:qe,branch:et,path:$e}),n({path:O().min(1).max(1024)})]);var at=k(`ArrowLeft`,[[`path`,{d:`m12 19-7-7 7-7`,key:`1l729n`}],[`path`,{d:`M19 12H5`,key:`x3x0zl`}]]),ot=k(`ArrowRight`,[[`path`,{d:`M5 12h14`,key:`1ays0h`}],[`path`,{d:`m12 5 7 7-7 7`,key:`xquz4c`}]]),st=k(`Info`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M12 16v-4`,key:`1dtifu`}],[`path`,{d:`M12 8h.01`,key:`e9boi3`}]]),ct=k(`Mic`,[[`path`,{d:`M12 2a3 3 0 0 0-3 3v7a3 3 0 0 0 6 0V5a3 3 0 0 0-3-3Z`,key:`131961`}],[`path`,{d:`M19 10v2a7 7 0 0 1-14 0v-2`,key:`1vc78b`}],[`line`,{x1:`12`,x2:`12`,y1:`19`,y2:`22`,key:`x3vr5v`}]]),lt=k(`Pause`,[[`rect`,{x:`14`,y:`4`,width:`4`,height:`16`,rx:`1`,key:`zuxfzm`}],[`rect`,{x:`6`,y:`4`,width:`4`,height:`16`,rx:`1`,key:`1okwgv`}]]),ut=k(`Play`,[[`polygon`,{points:`6 3 20 12 6 21 6 3`,key:`1oa8hb`}]]),Y=e(l(),1),dt=m({error:O()}),ft=O().min(1).max(4096),pt=w([`not_granted`,`not_found`,`conflict`,`invalid`,`unavailable`]),mt=m({moved:g(m({from:ft,to:ft})),failed:g(m({path:ft,error:pt}))}),ht=m({files:g(m({path:ft,kind:w([`image`,`video`,`audio`]).nullable(),model:O().nullable(),modelLabel:O().nullable(),durationSeconds:A().nullable(),favorite:_()}))}),gt=m({paths:g(ft),next:ft.nullable()});async function _t(e,t,n,r){let i=await e.capabilities.require(G).call(t,JSON.stringify(n)),a=r.safeParse(i);if(a.success)return a.data;let o=dt.safeParse(i);throw new j(o.success?`Prints refused ${t}: ${o.data.error}`:`Prints answered ${t} in an unexpected shape`,{code:`PROTOCOL`,retryable:!1})}function vt(e,t){return _t(e,`moveFiles`,{paths:[...t.paths],folder:t.folder,createFolder:t.createFolder??!1,name:t.name},mt)}async function yt(e,t){return(await _t(e,`describeFiles`,{paths:[...t]},ht)).files}async function bt(e,t,n){await _t(e,`setFavorite`,{paths:[...t],favorite:n},m({favorite:_(),count:A()}))}function xt(e,t,n){return _t(e,`listFavorites`,{after:t,limit:n},gt)}var St=24,Ct=256,wt=e=>e===null?null:e.kind===`folder`?e.path:`${e.kind}:${e.path}`,X={all:e=>ne.of(e,`prints`,`gallery`),listings:e=>[...X.all(e),`listing`],listing:(e,t)=>[...X.listings(e),t],file:(e,t)=>[...X.all(e),`file`,t],describedAll:e=>[...X.all(e),`described`],described:(e,t)=>[...X.describedAll(e),...t]};function Tt(e,t){return t.modifiedAt-e.modifiedAt||(e.path<t.path?-1:+(e.path>t.path))}function Et(e){let t=new Map;for(let n of e)for(let e of n.entries)t.set(e.path,e);return[...t.values()].sort(Tt)}var Dt=/\.(avif|gif|jpe?g|png|svg|webp|mp4|mp3)$/i;function Ot(e,t){let n=e?.context.get().computerId,r=t?.path??null,i={queue:r===null?[]:[r],offset:0,after:null};return He({queryKey:X.listing(e,wt(t)),initialPageParam:i,enabled:!!(n&&r&&e.capabilities.has(ge)&&e.capabilities.has(pe)),queryFn:async({pageParam:r,signal:i})=>{if(!e||!n||!t)throw new j(`No Computer folder selected`,{code:`SELECTION_CHANGED`,retryable:!1});let a=()=>{if(i.throwIfAborted(),e.context.get().computerId!==n)throw new j(`Computer selection changed`,{code:`SELECTION_CHANGED`,retryable:!1})};if(t.kind===`favorites`){let n=[];a();let i=await xt(e,r.after,Ct);return a(),{entries:i.paths.filter(e=>Dt.test(e)).map(e=>({path:e,name:e.slice(e.lastIndexOf(`/`)+1),modifiedAt:0,size:0,...kt(t.path,e)})),folders:n,next:i.next===null?null:{queue:[],offset:0,after:i.next}}}let o=[],s=[],c=[...r.queue],l=r.offset;for(;o.length<Ct&&c.length>0;){a();let n=c[0],r=await fe(e.capabilities,{path:n,limit:Ct-o.length,offset:l});if(a(),r.nextOffset!==null&&r.nextOffset<=l)throw new j(`Directory pagination did not advance`,{code:`PROTOCOL`,retryable:!1});let i=r.path.replace(/\/$/,``);for(let e of r.entries)e.name.startsWith(`.`)||(e.type===`directory`?t.kind===`all`?c.push(`${i}/${e.name}`):s.push(e.name):e.type===`file`&&Dt.test(e.name)&&o.push({...e,path:`${i}/${e.name}`,...kt(t.path,`${i}/${e.name}`)}));r.nextOffset===null?(c=c.slice(1),l=0):l=r.nextOffset}return{entries:o,folders:s,next:c.length===0?null:{queue:c,offset:l,after:null}}},getNextPageParam:e=>e.next})}function kt(e,t){let n=B(e,t);return n===void 0?{}:{folder:n}}function At(e,t,n){return{...W(e,pe,[...X.file(e,t.path),t.modifiedAt,t.size],async(n,r)=>{if(!e)throw new j(`Prints disconnected`,{code:`DISCONNECTED`,retryable:!0});let i=await de(e.capabilities,{path:t.path},{signal:r});return new File([i],i.name,{type:i.type,lastModified:t.modifiedAt})}),enabled:!!(n&&e?.context.get().computerId&&e.capabilities.has(pe)),structuralSharing:!1}}function jt(e,t){let n=e?.app??null,r=z(n),i=P(),[a,o]=(0,Y.useState)(()=>new Set),s=(0,Y.useCallback)(e=>{if(!r)return;let t=`${r}:${e}`;o(e=>e.has(t)?e:new Set([...e,t]))},[r]),c=(0,Y.useCallback)(e=>{s(e),i.resetQueries({queryKey:X.file(n,e)})},[n,i,s]),l=Ot(n,t),u=Ue(l),d=u.fetchNextPage;(0,Y.useEffect)(()=>{l.enabled&&u.hasNextPage&&!u.isFetching&&!u.error&&d({cancelRefetch:!1})},[l.enabled,u.hasNextPage,u.isFetching,u.error,d]);let f=!u.hasNextPage||u.error!==null,p=(0,Y.useMemo)(()=>l.enabled&&u.data&&f?Et(u.data.pages):[],[u.data,l.enabled,f]),m=`${r??``}|${wt(t)??``}`,[h,g]=(0,Y.useState)({key:m,count:St}),_=h.key===m?h.count:St,v=(0,Y.useMemo)(()=>p.slice(0,_),[p,_]),y=p.length>_,b=(0,Y.useCallback)(e=>({files:e.flatMap((e,t)=>e.data?[{path:v[t].path,file:e.data}]:[]),failures:e.flatMap((e,t)=>e.isError?[v[t].name]:[]),loading:e.some(e=>e.isLoading)}),[v]),x=ee({queries:v.map(e=>At(n,e,!!(r&&a.has(`${r}:${e.path}`)))),combine:b});return(0,Y.useEffect)(()=>{if(!n)return;let e=X.all(n),t=X.listings(n),a=!0;i.invalidateQueries({queryKey:e});let o=()=>{i.cancelQueries({queryKey:e})},s=n.context.subscribe(e=>{e.computerId!==r&&o()}),c=n.lifecycle.subscribe(e=>{(e===`disconnected`||e===`disposing`||e===`disposed`)&&o()}),l=n.capabilities.subscribe(()=>{queueMicrotask(()=>{!a||n.context.get().computerId!==r||i.resetQueries({queryKey:t})})});return()=>{a=!1,s(),c(),l(),o()}},[n,r,e,i]),{entries:v,folders:(0,Y.useMemo)(()=>[...new Set(u.data?.pages.flatMap(e=>e.folders)??[])],[u.data]),loadFile:s,retryFile:c,files:x.files,failures:x.failures,error:u.error,loading:u.isFetching||!f||x.loading,hasNextPage:y,nextPageReady:y,refresh:()=>{u.refetch({cancelRefetch:!1})},loadMore:()=>{y&&g({key:m,count:_+St})}}}function Mt(e){return e.replace(/\s/gu,` `).replace(/ +/g,` `).trim()}function Nt(e,t,n){let r=e.replace(/\/$/,``),i=t.lastIndexOf(`.`),a=i>0?t.slice(0,i):t,o=i>0?t.slice(i):``,s=`${r}/${t}`;for(let e=2;n(s);e+=1)s=`${r}/${a} ${String(e)}${o}`;return s}async function Pt(e,t){let n=e.replace(/\/$/,``),r=new Set,i=0;for(;i!==null;){let e=await t(i);if(e.nextOffset!==null&&e.nextOffset<=i)throw Error(`Directory pagination did not advance`);for(let t of e.entries)r.add(`${n}/${t.name}`);i=e.nextOffset}return r}function Ft(e,t){let[n,r]=(0,Y.useState)([]),i=(0,Y.useRef)(new Map),a=(0,Y.useRef)(Promise.resolve()),[o,s]=(0,Y.useState)(null),c=(0,Y.useRef)(new Map),l=(0,Y.useRef)(e);l.current=e;let u=(0,Y.useRef)(t);u.current=t;let d=(e,t,n)=>{let a=i.current.get(e);a&&i.current.set(e,{...a,status:t,message:n}),r([...i.current.values()])},f=(0,Y.useCallback)(async(e,t)=>{let n=()=>t.signal.aborted;if(n()){d(e.id,`cancelled`,`Cancelled before sending`),c.current.delete(e.id);return}let r=e.dimensions;if(!r)try{let t=await Ie(e.file,e.previewUrl);r={width:t.width,height:t.height},e.dimensions=r;let n=i.current.get(e.id);n&&i.current.set(e.id,{...n,dimensions:r})}catch(t){V(`decode-upload-image`,t),d(e.id,`error`,`Could not decode this image. No upload was sent.`),c.current.delete(e.id);return}try{if(n()){d(e.id,`cancelled`,`Cancelled before sending`);return}if(e.app.context.get().computerId!==e.computerId){d(e.id,`error`,`Computer changed. Select the original Computer and retry. No upload was sent.`);return}u.current({id:e.id,path:e.path,computerId:e.computerId,app:e.app,width:r.width,height:r.height}),d(e.id,`sending`,`Sending; awaiting Computer completion`),await me(e.app.capabilities,{path:e.path,content:e.file.slice()},{signal:t.signal}),d(e.id,`complete`,`Written to Computer`);try{await l.current(e.path,e.app,e.computerId)}catch(t){V(`refresh-upload-preview`,t),d(e.id,`complete`,`Written; fresh preview unavailable`)}}catch(t){n()||V(`write-computer-upload`,t),d(e.id,n()?`cancelled`:`error`,n()?`Cancelled request; check Computer before retrying`:`Completion not confirmed; check Computer or retry`)}finally{c.current.delete(e.id)}},[]),p=e=>{let t=new AbortController;c.current.set(e.id,t),d(e.id,`queued`,`Queued`),a.current=a.current.then(()=>f(e,t))},m=(0,Y.useCallback)(()=>{for(let e of c.current.values())e.abort()},[]);return(0,Y.useEffect)(()=>()=>{m();for(let e of i.current.values())URL.revokeObjectURL(e.previewUrl)},[m]),{items:n,error:o,cancelAll:m,add(e,t,n,r=new Set){s(null);let a=[...i.current.values()].reduce((e,t)=>e+t.file.size,0);for(let o of e){if(!o.type.startsWith(`image/`)){s(`Only image files can be uploaded here`);continue}if(i.current.size>=8||a+o.size>67108864){s(`Upload queue limit: eight files and 64 MiB. Remove finished rows before adding more.`);break}let e=n.context.get().computerId;if(!e){s(`Select a Computer before uploading images.`);continue}let c=Nt(t,Mt(o.name),e=>r.has(e)||i.current.has(e)),l={computerId:e,id:c,file:o,previewUrl:URL.createObjectURL(o),app:n,path:c,status:`queued`,message:`Queued`};i.current.set(l.id,l),a+=o.size,p(l)}},cancel(e){c.current.get(e)?.abort()},retry(e){let t=n.find(t=>t.id===e);t&&!c.current.has(e)&&p(t)},remove(e){if(!c.current.has(e)){let t=i.current.get(e);t&&URL.revokeObjectURL(t.previewUrl),i.current.delete(e),r([...i.current.values()])}}}}function It(e){return e.source.kind===`computer`?`${e.source.computerId}:${e.source.path}`:e.file.name}function Lt(e){return e.connection.app.ui.openNavigation({computerId:e.computerId,path:e.path})}function Rt(e){let[t,n]=(0,Y.useState)(!1);return(0,Y.useEffect)(()=>{if(n(!1),!e?.capabilities.has(Ke))return;let t=!0;return e.capabilities.require(Ke).role(Je).then(e=>{t&&n(e!==null)},e=>{V(`files-editor-role`,e)}),()=>{t=!1}},[e]),t}function zt(e,t){let n=t.landingPath,r=z(e?.app),i=(0,Y.useRef)(new Set),a=(0,Y.useRef)(0),o=(0,Y.useRef)(e);o.current=e;let s=e?.app.capabilities.has(ge)===!0,c=e?.app.capabilities.has(pe)===!0,l=e?.app.capabilities.has(he)===!0,u=jt(e,t.source),[d,f]=(0,Y.useState)([]),[p,m]=(0,Y.useState)([]),[h,g]=(0,Y.useState)([]),[_,v]=(0,Y.useState)([]);(0,Y.useEffect)(()=>{v([])},[e]);let y=e=>{v(t=>t.some(t=>t.key===e.key)?t.map(t=>t.key===e.key?e:t):[...t,e])},[b,x]=(0,Y.useState)(!1),S=(0,Y.useMemo)(()=>[...u.error?[`Could not refresh the Media gallery`]:[],...u.failures],[u.error,u.failures]),C=(0,Y.useRef)(new WeakMap),w=(0,Y.useMemo)(()=>{if(!c||!s)return d.filter(e=>e.kind===`local`);let t=r?u.files.map(({file:t,path:n})=>({kind:`computer`,computerId:r,connection:e,file:t,path:n})):[],i=d.filter(t=>t.kind===`local`||t.computerId===r&&t.connection===e&&t.path.slice(0,t.path.lastIndexOf(`/`))===n?.replace(/\/$/,``));return[...t.filter(e=>!i.some(t=>t.kind===`computer`&&e.kind===`computer`&&t.path===e.path)),...i]},[e,r,n,u.files,d,c,s]),T=(0,Y.useCallback)(()=>{a.current+=1;for(let e of i.current)e.abort();i.current.clear()},[]);(0,Y.useEffect)(()=>{if(!e)return()=>{T()};let t=e.app.lifecycle.subscribe(e=>{(e===`disconnected`||e===`disposing`||e===`disposed`)&&T()});return()=>{t(),T()}},[e,T]),(0,Y.useEffect)(()=>{if(e)return e.app.context.subscribe(e=>{e.computerId!==r&&T()})},[e,r,T]),(0,Y.useEffect)(()=>{v([]),f(e=>e.filter(e=>e.kind===`local`))},[r]);let E=(0,Y.useCallback)(async(e,t,n)=>{let r=n??t.app.context.get().computerId;if(!r){g([`The selected Computer is unavailable`]);return}if(o.current!==t){g([`Computer selection changed`]);return}if(t.app.context.get().computerId!==r){g([`Computer selection changed before the preview was loaded`]);return}let s=a.current,c=new AbortController;i.current.add(c);try{let n=await de(t.app.capabilities,{path:e},{signal:c.signal});if(c.signal.aborted||s!==a.current)return;v(t=>t.map(t=>t.key===`${r}:${e}`?{...t,previewFile:n}:t)),f(i=>[...i.filter(t=>t.kind!==`computer`||t.path!==e||t.computerId!==r),{kind:`computer`,computerId:r,file:n,path:e,connection:t}])}catch(t){c.signal.aborted||(V(`read-computer-file`,t),g([`Could not read ${e}`]),v(t=>t.map(t=>t.key===`${r}:${e}`?{...t,error:`Saved; preview unavailable. Retry loading it.`}:t)))}finally{i.current.delete(c)}},[]),D=(0,Y.useCallback)(t=>{let n=d.find(n=>n.kind===`computer`&&n.connection===e&&n.computerId===r&&n.path===t);n?.kind===`computer`?E(t,n.connection,n.computerId):u.retryFile(t)},[d,e,r,E,u.retryFile]),O=(0,Y.useRef)(new Set),k=(0,Y.useRef)(new Set),A=(0,Y.useRef)(new Map),j=(0,Y.useRef)(new Map),M=(0,Y.useCallback)(e=>{URL.revokeObjectURL(e),O.current.delete(e);let t=j.current.get(e);t&&A.current.delete(t),j.current.delete(e)},[]);(0,Y.useEffect)(()=>{let e=!0,t=new Set,n=new Map,r=new Set,i=[...w].sort((e,t)=>Tt({modifiedAt:e.file.lastModified,path:e.kind===`computer`?e.path:e.file.name},{modifiedAt:t.file.lastModified,path:t.kind===`computer`?t.path:t.file.name})).map(e=>{let t=A.current.get(e.file)??URL.createObjectURL(e.file);return A.current.set(e.file,t),j.current.set(t,e.file),O.current.add(t),{source:e,file:e.file,url:t}}),a=i.length;return g(S),x(a>0),a===0&&m([]),i.forEach(({file:o,url:s,source:c},l)=>{let u=C.current.get(o);u||(u=(async()=>{let e=URL.createObjectURL(o);try{let{width:t,height:n}=await Ie(o,e);return{width:t,height:n}}finally{URL.revokeObjectURL(e)}})(),C.current.set(o,u)),u.then(r=>{e&&(n.set(l,{...r,file:o,url:s,source:c}),t.add(s),m(i.flatMap((e,t)=>{let r=n.get(t);return r?[r]:[]})),v(e=>e.map(e=>e.previewFile===o?{...e,resolved:!0,previewFile:void 0,error:void 0}:e)))}).catch(t=>{e&&(V(`decode-gallery-image`,t),M(s),r.add(o.name),g([...S,...r]),c.kind===`computer`&&v(e=>e.map(e=>e.key===`${c.computerId}:${c.path}`?{...e,error:`Could not decode the saved image.`}:e)))}).finally(()=>{--a,e&&a===0&&(x(!1),m(i.flatMap((e,t)=>{let r=n.get(t);return r?[r]:[]})))})}),()=>{e=!1;for(let{url:e}of i)!t.has(e)&&!k.current.has(e)&&M(e)}},[w,S,M]),(0,Y.useEffect)(()=>{let e=new Set(p.map(e=>e.url));for(let t of k.current)e.has(t)||M(t);k.current=e},[p,M]),(0,Y.useEffect)(()=>{let e=O.current;return()=>{for(let t of e)URL.revokeObjectURL(t);e.clear()}},[]);let N=Ft(async(e,t,n)=>{let r=o.current,i=r?.app===t&&t.context.get().computerId===n?r:null;i&&await E(e,i,n)},e=>{o.current?.app===e.app&&e.app.context.get().computerId===e.computerId&&y({key:`${e.computerId}:${e.path}`,path:e.path,computerId:e.computerId,width:e.width,height:e.height,uploadId:e.id})});return(0,Y.useEffect)(()=>{let t=N.cancelAll,n=e?.app.lifecycle.subscribe(e=>{(e===`disposing`||e===`disconnected`||e===`disposed`)&&t()});return()=>{n?.(),t()}},[e,N.cancelAll]),{images:p,failed:h,loading:b,gallery:u,gallerySlots:_,canBrowse:s,canRead:c,canWrite:l,reserveSlot:y,addComputerFile:E,retryFile:D,uploads:N,uploadFiles:async i=>{if(!e||!l||n===null)return;let a=e,s=r,c=await t.ensureCreated();if(c){g([c]);return}if(o.current!==a||a.app.context.get().computerId!==s)return;let u;try{u=await Pt(n,e=>fe(a.app.capabilities,{path:n,limit:500,offset:e}))}catch(e){V(`list-upload-destination`,e),g([`Could not check the Computer folder. No upload was sent.`]);return}o.current===a&&a.app.context.get().computerId===s&&N.add(i,n,a.app,u)},failSlot:(e,t)=>{v(n=>n.map(n=>n.key===e?{...n,error:t}:n))},clearSlotError:e=>{v(t=>t.map(t=>t.key===e?{...t,error:void 0}:t))},removeSlot:e=>{v(t=>t.filter(t=>t.key!==e))}}}var Bt=Y.createContext(void 0);function Vt(){let e=Y.useContext(Bt);if(e===void 0)throw Error(Pe(53));return e}function Z(e,t,n){if(!e)return 0;let r=getComputedStyle(e),i=`${t}${n===`x`?`Inline`:`Block`}`,a=parseFloat(r[`${i}Start`]);return n===`x`&&t===`margin`?a*2:a+parseFloat(r[`${i}End`])}var Q=t(),Ht=`base-ui-disable-scrollbar`,Ut={className:Ht,getElement(e){return(0,Q.jsx)(`style`,{nonce:e,href:Ht,precedence:`base-ui:low`,children:`.${Ht}{scrollbar-width:none}.${Ht}::-webkit-scrollbar{display:none}`})}},Wt=`data-has-overflow-x`,Gt=`data-has-overflow-y`,Kt=`data-overflow-x-start`,qt=`data-overflow-x-end`,Jt=`data-overflow-y-start`,Yt=`data-overflow-y-end`,Xt=e=>t=>t?{[e]:``}:null,Zt={hasOverflowX:Xt(Wt),hasOverflowY:Xt(Gt),overflowXStart:Xt(Kt),overflowXEnd:Xt(qt),overflowYStart:Xt(Jt),overflowYEnd:Xt(Yt),cornerHidden:()=>null},Qt=Y.createContext(void 0),$t={disableStyleElements:!1};function en(){return Y.useContext(Qt)??$t}var tn=`--scroll-area-corner-height`,nn=`--scroll-area-corner-width`,rn=`data-orientation`,an={x:0,y:0},on={width:0,height:0},sn={xStart:!1,xEnd:!1,yStart:!1,yEnd:!1},cn={x:!0,y:!0,corner:!0},ln=Y.forwardRef(function(e,t){let{render:n,className:r,overflowEdgeThreshold:i,style:a,...o}=e,{xStart:s,xEnd:c,yStart:l,yEnd:u}=un(i),d=Ae(),f=Ne(),p=Ne(),{nonce:m,disableStyleElements:h}=en(),[g,_]=Y.useState(!1),[v,y]=Y.useState(!1),[b,x]=Y.useState(!1),[S,C]=Y.useState(!1),[w,T]=Y.useState(!1),[E,D]=Y.useState(on),[O,k]=Y.useState(on),[A,j]=Y.useState(sn),[M,N]=Y.useState(cn),P=Y.useRef(null),F=Y.useRef(null),I=Y.useRef(null),L=Y.useRef(null),R=Y.useRef(null),z=Y.useRef(null),ee=Y.useRef(null),B=Y.useRef(null),V=Y.useRef(0),H=Y.useRef(0),te=Y.useRef(0),ne=Y.useRef(0),U=Y.useRef(`vertical`),W=Y.useRef(an),G=Y.useRef(null);function K(e){let t=e?x:y,n=e?f:p;t(!0),n.start(500,()=>{t(!1)})}let re=Te(e=>{let t=e.x-W.current.x,n=e.y-W.current.y;W.current=e,n!==0&&K(!0),t!==0&&K(!1)}),ie=Te(()=>{let e=F.current;e&&G.current===null&&(G.current=e.style.scrollSnapType,e.style.scrollSnapType=`none`)}),ae=Te(e=>{if(e.button!==0||B.current!==null&&(U.current===`vertical`?R.current:z.current)?.hasPointerCapture(B.current))return;B.current=e.pointerId,V.current=e.clientY,H.current=e.clientX,U.current=e.currentTarget.getAttribute(rn);let t=F.current;t&&(te.current=t.scrollTop,ne.current=t.scrollLeft,ie()),(U.current===`vertical`?R.current:z.current)?.setPointerCapture(e.pointerId)}),oe=Te(e=>{if(e.pointerId!==B.current)return;B.current=null,(U.current===`vertical`?x:y)(!1),G.current!==null&&(F.current&&(F.current.style.scrollSnapType=G.current),G.current=null);let t=U.current===`vertical`?R.current:z.current;t?.hasPointerCapture(e.pointerId)&&t.releasePointerCapture(e.pointerId)}),se=Te(e=>{if(e.pointerId!==B.current)return;if(e.buttons%2==0){oe(e);return}let t=F.current;if(!t)return;let n=U.current===`vertical`,r=n?R.current:z.current,i=n?I.current:L.current;if(!r||!i)return;let a=n?`y`:`x`,o=Z(i,`padding`,a),s=Z(r,`margin`,a),c=n?r.offsetHeight:r.offsetWidth,l=(n?i.offsetHeight:i.offsetWidth)-c-o-s,u=n?e.clientY-V.current:e.clientX-H.current,d=l<=0?0:u/l,f=n?t.scrollHeight:t.scrollWidth,p=n?t.clientHeight:t.clientWidth,m=(n?te.current:ne.current)+d*(f-p);n?t.scrollTop=m:t.scrollLeft=m,e.preventDefault(),K(n)});function q(e){C(e.pointerType===`touch`)}function ce(e){if(q(e),e.pointerType!==`touch`){let t=ke(P.current,e.target);_(t)}}let le=Y.useMemo(()=>({scrolling:v||b,hasOverflowX:!M.x,hasOverflowY:!M.y,overflowXStart:A.xStart,overflowXEnd:A.xEnd,overflowYStart:A.yStart,overflowYEnd:A.yEnd,cornerHidden:M.corner}),[v,b,M.x,M.y,M.corner,A]),ue={role:`presentation`,onPointerEnter:ce,onPointerMove:ce,onPointerDown:q,onPointerLeave(){_(!1)},style:{position:`relative`,[tn]:`${E.height}px`,[nn]:`${E.width}px`}},de=Oe(`div`,e,{state:le,ref:[t,P],props:[ue,o],stateAttributesMapping:Zt}),fe=Y.useMemo(()=>({handlePointerDown:ae,handlePointerMove:se,handlePointerUp:oe,handleScroll:re,disableViewportSnap:ie,cornerSize:E,setCornerSize:D,thumbSize:O,setThumbSize:k,hasMeasuredScrollbar:w,setHasMeasuredScrollbar:T,touchModality:S,cornerRef:ee,scrollingX:v,scrollingY:b,hovering:g,setHovering:_,viewportRef:F,scrollbarYRef:I,scrollbarXRef:L,thumbYRef:R,thumbXRef:z,rootId:d,hiddenState:M,setHiddenState:N,overflowEdges:A,setOverflowEdges:j,viewportState:le,overflowEdgeThreshold:{xStart:s,xEnd:c,yStart:l,yEnd:u}}),[ae,se,oe,re,ie,E,O,w,S,v,b,g,d,M,A,le,s,c,l,u]);return(0,Q.jsxs)(Bt.Provider,{value:fe,children:[!h&&Ut.getElement(m),de]})});function un(e){let t=typeof e==`number`?{xStart:e,xEnd:e,yStart:e,yEnd:e}:e;return{xStart:Math.max(0,t?.xStart||0),xEnd:Math.max(0,t?.xEnd||0),yStart:Math.max(0,t?.yStart||0),yEnd:Math.max(0,t?.yEnd||0)}}function dn(e,t=-(2**53-1),n=2**53-1){return Math.max(t,Math.min(e,n))}var fn=Y.createContext(void 0);function pn(){let e=Y.useContext(fn);if(e===void 0)throw Error(Pe(55));return e}function mn(e,t){if(t<=0)return 0;let n=dn(e,0,t),r=n,i=t-n,a=r<=1,o=i<=1;return a&&o?r<=i?0:t:a?0:o?t:n}var hn=`--scroll-area-overflow-x-start`,gn=`--scroll-area-overflow-x-end`,_n=`--scroll-area-overflow-y-start`,vn=`--scroll-area-overflow-y-end`,yn=`--scroll-area-thumb-height`,bn=`--scroll-area-thumb-width`,xn=[hn,gn,_n,vn],Sn=!1;function Cn(){Sn||je||(typeof CSS<`u`&&`registerProperty`in CSS&&xn.forEach(e=>{try{CSS.registerProperty({name:e,syntax:`<length>`,inherits:!1,initialValue:`0px`})}catch{}}),Sn=!0)}var wn=Y.forwardRef(function(e,t){let{render:n,className:r,style:i,...a}=e,{viewportRef:o,scrollbarYRef:s,scrollbarXRef:c,thumbYRef:l,thumbXRef:u,cornerRef:d,cornerSize:f,setCornerSize:p,setThumbSize:m,rootId:h,setHiddenState:g,hiddenState:_,setHasMeasuredScrollbar:v,handleScroll:y,touchModality:b,setHovering:x,setOverflowEdges:S,overflowEdgeThreshold:C,viewportState:w}=Vt(),T=Se(),E=Y.useRef(!0),D=Y.useRef([NaN,NaN,NaN,NaN]),O=Ne(),k=Ne(),A=Te(()=>{let e=o.current,t=s.current,n=c.current,r=l.current,i=u.current,a=d.current;if(!e)return;let h=e.scrollHeight,_=e.scrollWidth,y=e.clientHeight,b=e.clientWidth,x=e.scrollTop,w=e.scrollLeft,E=D.current,O=Number.isNaN(E[0]);if(E[0]=y,E[1]=h,E[2]=b,E[3]=_,O&&v(!0),h===0||_===0)return;let k=Tn(e),A=k.y,j=k.x,M=b/_,N=y/h,P=Math.max(0,_-b),F=Math.max(0,h-y),I=0,L=0;j||(I=mn(T===`rtl`?-w:w,P),L=P-I);let R=A?0:mn(x,F),z=A?0:F-R,ee=j?0:b,B=A?0:y,V=0,H=0;!j&&!A&&(V=t?.offsetWidth||0,H=n?.offsetHeight||0);let te=f.width===0&&f.height===0,ne=te?V:0,U=te?H:0,W=Z(n,`padding`,`x`),G=Z(t,`padding`,`y`),K=Z(i,`margin`,`x`),re=Z(r,`margin`,`y`),ie=ee-W-K,ae=B-G-re,oe=n?Math.min(n.offsetWidth-ne,ie):ie,se=t?Math.min(t.offsetHeight-U,ae):ae,q=Math.max(16,oe*M),ce=Math.max(16,se*N);if(m(e=>En(e,{width:q,height:ce})),t&&r){let e=Dn(r,yn,x,F,h,ce,t.offsetHeight-ce-G-re);r.style.transform=`translate3d(0,${e}px,0)`}if(n&&i){let e=n.offsetWidth-q-W-K,t=Dn(i,bn,T===`rtl`?-w:w,P,_,q,e);i.style.transform=`translate3d(${T===`rtl`?-t:t}px,0,0)`}let le=[I,L,R,z];xn.forEach((t,n)=>{e.style.setProperty(t,`${le[n]}px`)}),a&&p(e=>En(e,{width:V,height:H})),g(e=>En(e,k));let ue={xStart:!j&&I>C.xStart,xEnd:!j&&L>C.xEnd,yStart:!A&&R>C.yStart,yEnd:!A&&z>C.yEnd};S(e=>En(e,ue))});we(()=>{Cn()},[]),we(()=>{queueMicrotask(A)},[A,_,T,C.xStart,C.xEnd,C.yStart,C.yEnd]),we(()=>{o.current?.matches(`:hover`)&&x(!0)},[o,x]),we(()=>{let e=o.current;if(typeof ResizeObserver>`u`||!e)return;let t=!1,n=new ResizeObserver(()=>{if(!t){t=!0;let n=D.current;if(n[0]===e.clientHeight&&n[1]===e.scrollHeight&&n[2]===e.clientWidth&&n[3]===e.scrollWidth)return}A()});return n.observe(e),k.start(0,()=>{let t=Ce(e,{subtree:!0});t.length!==0&&Promise.allSettled(t.map(e=>e.finished.then(Me))).then(A).catch(()=>{})}),()=>{n.disconnect(),k.clear()}},[A,o,k]);function j(){E.current=!1}let M={...h&&{"data-id":`${h}-viewport`},tabIndex:_.x&&_.y?-1:0,className:Ut.className,style:{overflow:`scroll`},onScroll(){o.current&&(A(),(b||!E.current)&&y({x:o.current.scrollLeft,y:o.current.scrollTop}),O.start(100,()=>{E.current=!0}))},onWheel:j,onPointerMove:j,onPointerEnter:j,onKeyDown:j},N=Oe(`div`,e,{ref:[t,o],state:w,props:[M,a],stateAttributesMapping:Zt}),P=Y.useMemo(()=>({computeThumbPosition:A}),[A]);return(0,Q.jsx)(fn.Provider,{value:P,children:N})});function Tn(e){let t=e.clientHeight>=e.scrollHeight,n=e.clientWidth>=e.scrollWidth;return{y:t,x:n,corner:t||n}}function En(e,t){for(let n in t)if(e[n]!==t[n])return t;return e}function Dn(e,t,n,r,i,a,o){let s=dn(n,0,r),c=n-s,l=Math.max(16,a*i/(i+Math.abs(c)));return e.style.setProperty(t,c?`${l}px`:``),(r?s/r*o:0)+(c>0?a-l:0)}var On=Y.createContext(void 0);function kn(){let e=Y.useContext(On);if(e===void 0)throw Error(Pe(54));return e}var An=Y.forwardRef(function(e,t){let{render:n,className:r,orientation:i=`vertical`,keepMounted:a=!1,style:o,...s}=e,{hovering:c,scrollingX:l,scrollingY:u,hiddenState:d,scrollbarYRef:f,scrollbarXRef:p,viewportRef:m,thumbYRef:h,thumbXRef:g,handlePointerDown:_,handlePointerUp:v,handleScroll:y,disableViewportSnap:b,rootId:x,thumbSize:S,hasMeasuredScrollbar:C,viewportState:w}=Vt(),T=i===`vertical`,E={...w,hovering:c,scrolling:T?u:l,orientation:i},D=Se(),O=!C&&!a,k=T?d.y:d.x,A=a||!k;Y.useEffect(()=>{if(!A)return;let e=m.current,t=T?f.current:p.current;if(!t)return;function n(t){if(!e||t.ctrlKey)return;let n=!T,r=n?`scrollLeft`:`scrollTop`,i=n?t.deltaX:t.deltaY;if(i===0)return;let a=n?e.scrollWidth-e.clientWidth:e.scrollHeight-e.clientHeight,o=n&&D===`rtl`?-a:0,s=n&&D===`rtl`?0:a,c=e[r];c<=o&&i<0||c>=s&&i>0||(t.preventDefault(),e[r]=Math.min(s,Math.max(o,c+i)),y({x:e.scrollLeft,y:e.scrollTop}))}return Ee(t,`wheel`,n,{passive:!1})},[D,y,T,p,f,A,m]);let j={...x&&{"data-id":`${x}-scrollbar`},"aria-hidden":!0,onPointerDown(e){if(e.button!==0)return;let t=De(e.nativeEvent),n=T?h.current:g.current;if(n&&ke(n,t))return;let r=m.current;if(!r)return;let i=T?f.current:p.current;if(!n||!i)return;let a=T?`y`:`x`,o=Z(n,`margin`,a),s=Z(i,`padding`,a),c=T?n.offsetHeight:n.offsetWidth,l=i.getBoundingClientRect(),u=T?e.clientY-l.top-c/2-s+o/2:e.clientX-l.left-c/2-s+o/2,d=T?r.scrollHeight:r.scrollWidth,v=T?r.clientHeight:r.clientWidth,x=(T?i.offsetHeight:i.offsetWidth)-c-s-o;if(x<=0)return;let S=u/x,C=d-v;b(),T?r.scrollTop=S*C:r.scrollLeft=D===`rtl`?-(1-S)*C:S*C,y({x:r.scrollLeft,y:r.scrollTop}),_(e)},onMouseDown(e){e.preventDefault()},onPointerUp:v,onPointerCancel:v,style:{position:`absolute`,touchAction:`none`,WebkitUserSelect:`none`,userSelect:`none`,visibility:O?`hidden`:void 0,...T?{top:0,bottom:`var(${tn})`,insetInlineEnd:0,[yn]:`${S.height}px`}:{insetInlineStart:0,insetInlineEnd:`var(${nn})`,bottom:0,[bn]:`${S.width}px`}}},M=Oe(`div`,e,{ref:[t,T?f:p],state:E,props:[j,s],stateAttributesMapping:Zt});return A?(0,Q.jsx)(On.Provider,{value:i,children:M}):null}),jn=Y.forwardRef(function(e,t){let{render:n,className:r,style:i,...a}=e,{computeThumbPosition:o}=pn(),{hasMeasuredScrollbar:s,viewportState:c}=Vt(),l=Y.useRef(null),u=Y.useRef(s);return we(()=>{if(typeof ResizeObserver>`u`)return;let e=!1,t=new ResizeObserver(()=>{!e&&(e=!0,!u.current)||o()});return l.current&&t.observe(l.current),()=>{t.disconnect()}},[o]),Oe(`div`,e,{ref:[t,l],state:c,stateAttributesMapping:Zt,props:[{role:`presentation`,style:{minWidth:`fit-content`}},a]})}),Mn=Y.forwardRef(function(e,t){let{render:n,className:r,style:i,...a}=e,{thumbYRef:o,thumbXRef:s,handlePointerDown:c,handlePointerMove:l,handlePointerUp:u,scrollingX:d,scrollingY:f,hasMeasuredScrollbar:p}=Vt(),m=kn(),h=m===`vertical`;return Oe(`div`,e,{ref:[t,h?o:s],state:{scrolling:h?f:d,orientation:m},props:[{onPointerDown:c,onPointerMove:l,onPointerUp:u,onPointerCancel:u,style:{visibility:p?void 0:`hidden`,...h?{height:`var(--scroll-area-thumb-height)`}:{width:`var(--scroll-area-thumb-width)`}}},a]})});function Nn(e,t,n){let r=(Math.abs(t)-Math.abs(e))/Math.max(16,n);if(Math.abs(r)<.035)return null;let i=Math.min(.04,Math.abs(r)*.3),a=r>0,o=Math.sign(t||e);return{scaleY:1+(a?i:-i),scaleX:1+(a?-i/2:i/2),origin:(a?o>0:o<0)?`center top`:`center bottom`}}function Pn(e,t,n){if(t<=0||Math.abs(n)<4)return null;let r=e<=0&&n<0,i=e>=t-1&&n>0;if(!r&&!i)return null;let a=Math.min(.06,Math.abs(n)/120*.06);return{scaleY:1-a,scaleX:1+a/2,origin:r?`center top`:`center bottom`}}var Fn=(0,Y.forwardRef)(function({children:e,className:t,surface:n=!1,surfaceSize:r,surfaceDepth:i,screen:a=!1,...o},s){let c=(0,Y.useRef)(null),l=(0,Y.useRef)(null),u=v();(0,Y.useEffect)(()=>{let e=c.current,t=e?.querySelector(`.caps-scroll-viewport`);if(!t||!e)return;let n=null,r,i=t.scrollTop,a=performance.now(),o=0,s=e=>{let t=l.current;if(!e||u||!t)return;n?.cancel(),t.style.transformOrigin=e.origin;let r=S(t),i=ye(r,{ease:`outQuad`,duration:45}),a=_e(r,{bounce:.18,duration:180});n=xe(t,{scaleY:[{to:e.scaleY,...i},{to:1,...a}],scaleX:[{to:e.scaleX,...i},{to:1,...a}]})},d=(e,t)=>{let n=Nn(o,e,t);o=e,s(n)},f=e=>{if(e.ctrlKey||Math.abs(e.deltaX)>Math.abs(e.deltaY))return;let n=e.deltaMode===1?16:e.deltaMode===2?t.clientHeight:1,i=Pn(t.scrollTop,t.scrollHeight-t.clientHeight,e.deltaY*n);i&&(clearTimeout(r),o=0,s(i))},p=()=>{let e=performance.now(),n=e-a,s=n>100?16:Math.max(16,n),c=t.scrollTop-i;n>100&&(o=0),d(c/s,s),i=t.scrollTop,a=e,clearTimeout(r),r=setTimeout(()=>{d(0,32)},64)};return t.addEventListener(`scroll`,p,{passive:!0}),e.addEventListener(`wheel`,f,{passive:!0}),()=>{clearTimeout(r),n?.cancel(),l.current&&(l.current.style.transform=`none`),t.removeEventListener(`scroll`,p),e.removeEventListener(`wheel`,f)}},[a,n,u]);let d=(0,Q.jsx)(wn,{render:a?(0,Q.jsx)(oe,{}):(0,Q.jsx)(`div`,{}),...o,ref:s,className:`caps-scroll-viewport`,children:(0,Q.jsx)(jn,{style:{minWidth:0},children:e})});return(0,Q.jsxs)(ln,{render:n?(0,Q.jsx)(q,{size:r??`md`,depth:i??`shallow`}):(0,Q.jsx)(`div`,{}),ref:c,className:E(`caps-scroll-area`,t),children:[a?(0,Q.jsx)(`div`,{className:`caps-display-gasket caps-scroll-display`,children:d}):d,(0,Q.jsx)(q,{size:`sm`,depth:`deep`,placement:`embedded`,className:`caps-scroll-track-surface`,children:(0,Q.jsx)(An,{className:`caps-scroll-track`,children:(0,Q.jsx)(Mn,{className:`caps-scroll-thumb`,children:(0,Q.jsx)(`span`,{className:`caps-scroll-thumb-surface`,ref:l})})})})]})}),In=(0,Y.forwardRef)(function({className:e,count:t,density:n=`row`,dismissAriaLabel:r,dismissLabel:i=`Dismiss`,message:a,onDismiss:o,onRetry:s,retryAriaLabel:c,retryLabel:l=`Retry`,role:u=`status`,...d},f){return(0,Q.jsxs)(`div`,{...d,className:E(`caps-failure-line`,e),"data-density":n,ref:f,role:u,children:[(0,Q.jsx)(be,{glyph:`dot`,tone:`error`}),(0,Q.jsxs)(`span`,{className:`caps-failure-line-copy`,children:[(0,Q.jsx)(`span`,{children:a}),t!==void 0&&t>1?(0,Q.jsxs)(`span`,{className:`caps-failure-line-count`,children:[`Failed `,t,` times`]}):null]}),s||o?(0,Q.jsxs)(`span`,{className:`caps-failure-line-actions`,children:[s?(0,Q.jsx)(T,{"aria-label":c,size:`sm`,variant:`outline`,onClick:s,children:l}):null,o?(0,Q.jsx)(T,{"aria-label":r,size:`sm`,variant:`ghost`,onClick:o,children:i}):null]}):null]})});function Ln(e){return e?.closest(`[data-app-pane="media"]`)??e}var Rn={voice:`Voice`,sfx:`Sound effects`,music:`Music`};function zn(e){return e.audio.mode===`speech`?`voice`:`music`}function Bn(e){return e.flatMap(e=>e.audio===null?[]:[{id:e.id,label:e.label,audio:e.audio}])}function Vn(e){return e.audio===null?null:e.audio.mode===`speech`?`voice`:`music`}function Hn(e){let t=new Set(e.map(zn));return[`voice`,`sfx`,`music`].filter(e=>t.has(e))}function Un(e,t){return e.filter(e=>zn(e)===t)}function Wn({modes:e,value:t,onChange:n,disabled:r=!1}){return(0,Q.jsx)(se,{className:`prints-audio-modes`,value:t,onValueChange:t=>{let r=e.find(e=>e===t);r!==void 0&&n(r)},children:(0,Q.jsx)(ae,{"aria-label":`Audio type`,className:`prints-audio-modes-list`,variant:`segmented`,children:e.map(e=>(0,Q.jsx)(le,{"data-audio-mode":e,disabled:r,value:e,children:Rn[e]},e))})})}function Gn({label:e,name:t,options:n,value:r,disabled:i,onChange:a,icon:o,compact:s=!1}){let[c,l]=(0,Y.useState)(null);return(0,Q.jsx)(`span`,{className:`contents`,ref:l,children:(0,Q.jsxs)(ze,{children:[(0,Q.jsx)(Fe,{"aria-label":t,disabled:i||n.length===0,render:(t,n)=>(0,Q.jsx)(Be,{...t,className:E(`parakeet-composer-model-key`,s&&`prints-audio-key-compact`),expanded:n.open,icon:o,label:e,readout:(0,Q.jsx)(ve,{"aria-hidden":`true`,className:`size-[var(--stipe-icon-size-sm)] shrink-0`})})}),(0,Q.jsx)(Re,{align:`start`,"aria-label":t,container:Ln(c),side:`top`,children:n.map(e=>(0,Q.jsx)(Le,{checked:e.value===r,closeOnClick:!0,onSelect:()=>{a(e.value)},children:e.label},String(e.value)))})]})})}function Kn({models:e,value:t,onChange:n,disabled:r=!1}){let i=e.find(e=>e.id===t);return(0,Q.jsx)(Gn,{disabled:r,label:i===void 0?`Model`:re(i),name:`Generation model`,onChange:n,options:e.map(e=>({value:e.id,label:e.label})),value:t})}function qn({voices:e,value:t,onChange:n,disabled:r=!1}){let i=e.find(e=>e.id===t);return(0,Q.jsx)(Gn,{disabled:r,compact:!0,icon:(0,Q.jsx)(ct,{}),label:i?.label??`Voice`,name:`Voice`,onChange:n,options:e.map(e=>({value:e.id,label:e.label})),value:t})}var Jn=[10,15,30,60,90,120,180,300,600];function Yn(e){let t=Jn.filter(t=>t>=e.min&&t<=e.max);return[...new Set([...t,e.default])].sort((e,t)=>e-t)}function Xn({seconds:e,value:t,onChange:n,disabled:r=!1}){return(0,Q.jsx)(Gn,{disabled:r,compact:!0,icon:(0,Q.jsx)(ie,{}),label:ue(t),name:`Length`,onChange:n,options:Yn(e).map(e=>({value:e,label:ue(e)})),value:t})}var Zn={queued:`Waiting to start`,generating:`Generating`,refining:`Refining`,done:void 0,failed:void 0},Qn=(0,Y.forwardRef)(function({status:e,children:t,aspectRatio:n,label:r,indicator:i,failure:a,className:o,style:s,...c},l){let u=(0,Y.useRef)(null);(0,Y.useImperativeHandle)(l,()=>u.current);let f=(0,Y.useRef)(e),[p,m]=(0,Y.useState)(!1),[g,_]=(0,Y.useState)(e);g!==e&&(_(e),m(e===`done`)),(0,Y.useLayoutEffect)(()=>{let t=u.current,n=f.current;if(f.current=e,!t||n===e)return;if(!x(t)){m(!1);return}let r=S(t),i=h(r,r.ease),a=[],o=t.querySelector(`:scope > [data-layer="media"]`),s=t.querySelector(`:scope > [data-layer="placeholder"]`),c=t.querySelector(`:scope > [data-layer="failure"]`);if(e===`done`&&o){let e=o.animate(r.reduced?[{opacity:0},{opacity:1}]:[{opacity:0,filter:`blur(10px)`,transform:`scale(1.03)`},{opacity:1,filter:`blur(0px)`,transform:`none`}],{duration:r.reduced?r.fast:r.slow*2,easing:i,fill:`backwards`});e.addEventListener(`finish`,()=>{m(!1)}),a.push(e),s&&a.push(s.animate([{opacity:1},{opacity:0}],{duration:r.reduced?r.fast:r.slow,easing:i,fill:`forwards`}))}return e===`failed`&&c&&a.push(c.animate([{opacity:0,transform:`translateY(${String(r.distance)}px)`},{opacity:1,transform:`none`}],{duration:r.normal,easing:i})),n===`failed`&&s&&a.push(s.animate([{opacity:.4},{opacity:1}],{duration:r.normal,easing:i})),()=>{for(let e of a)e.cancel()}},[e]);let v=e===`queued`||e===`generating`||e===`refining`,y=r??Zn[e],b=e===`done`||e===`refining`;return(0,Q.jsxs)(`div`,{...c,ref:u,className:E(`caps-generation-frame`,o),"data-status":e,"data-aspect":n===void 0?void 0:``,"aria-busy":v,style:n===void 0?s:{aspectRatio:n,...s},children:[e===`done`&&!p?null:(0,Q.jsxs)(`div`,{className:E(`caps-generation-placeholder`,e===`queued`&&`skeleton`),"data-layer":`placeholder`,role:e===`done`?void 0:`status`,"aria-hidden":e===`done`||void 0,children:[e===`generating`||e===`refining`||e===`done`?i??(0,Q.jsx)(C,{decorative:!0,size:`lg`,variant:`bloom`}):null,y===void 0?null:(0,Q.jsx)(d,{children:y})]}),b?(0,Q.jsx)(`div`,{className:`caps-generation-media`,"data-layer":`media`,children:t}):null,e===`failed`&&a!==void 0?(0,Q.jsx)(`div`,{className:`caps-generation-failure`,"data-layer":`failure`,role:`alert`,children:a}):null]})}),$=null;function $n(e,t){let n=(0,Y.useRef)(null),r=(0,Y.useRef)(t);r.current=t;let[i,a]=(0,Y.useState)(!1),[o,s]=(0,Y.useState)(0);(0,Y.useEffect)(()=>()=>{let e=n.current;e!==null&&(e.pause(),$===e&&($=null),n.current=null)},[e]),(0,Y.useEffect)(()=>{if(!i)return;let e=0,t=()=>{let r=n.current;r!==null&&r.duration>0&&s(Math.min(1,r.currentTime/r.duration)),e=requestAnimationFrame(t)};return e=requestAnimationFrame(t),()=>{cancelAnimationFrame(e)}},[i]);let c=(0,Y.useCallback)(()=>{if(n.current!==null)return n.current;let t=new Audio(e);return t.preload=`auto`,t.addEventListener(`ended`,()=>{a(!1),s(0),$===t&&($=null)}),t.addEventListener(`pause`,()=>{a(!1)}),t.addEventListener(`error`,()=>{a(!1),r.current(`This audio could not be played.`)}),n.current=t,t},[e]);return{playing:i,progress:o,toggle:(0,Y.useCallback)(()=>{let e=c();if(!e.paused){e.pause();return}$!==null&&$!==e&&$.pause(),$=e,a(!0),e.play().catch(e=>{V(`play-audio`,e),a(!1),r.current(`This audio could not be played.`)})},[c]),seek:(0,Y.useCallback)(e=>{let t=c();Number.isFinite(t.duration)&&t.duration>0&&(t.currentTime=Math.min(1,Math.max(0,e))*t.duration,s(Math.min(1,Math.max(0,e))))},[c])}}function er({url:e,progress:t=0,bars:n=64,className:r}){let i=ce(e,n),a=i.status===`ready`?i.peaks:null;return(0,Q.jsx)(`span`,{"aria-hidden":`true`,className:E(`prints-waveform`,r),"data-waveform":i.status,children:Array.from({length:n},(e,r)=>(0,Q.jsx)(`span`,{className:`prints-waveform-bar`,"data-played":r/n<t?``:void 0,style:{height:`max(2px, ${String((a?.[r]??0)*100)}%)`}},r))})}export{at as A,yt as C,lt as D,ut as E,st as O,Ot as S,bt as T,Lt as _,Xn as a,Mt as b,qn as c,Hn as d,Un as f,It as g,Fn as h,Rn as i,Ue as j,ot as k,Vn as l,In as m,$n as n,Wn as o,Ln as p,Qn as r,Kn as s,er as t,Bn as u,Rt as v,vt as w,X as x,zt as y};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{B as t,C as n,D as r,Dt as i,En as a,Et as o,F as s,I as c,K as l,N as u,O as d,Tt as f,Vn as p,gn as m,k as ee,ln as h,lt as g,q as _,st as te,v,wn as ne,x as re}from"./button-oE2Hrd5D.js";import{Mt as ie,Nt as ae,Pt as y,a as b,bt as oe,i as x,jt as se,n as ce,o as S,ot as le,r as C,s as w,zt as T}from"./dist-DAokFn5x.js";import{l as ue,n as E,t as de}from"./log-event-B3BGsDWO.js";import{c as fe,d as pe,f as me,l as he,o as ge,p as _e,s as ve,u as ye}from"./query-CYqgVHJ7.js";var D=e(p(),1);function be(e,t,n){let r=_e(),i=me(),a=se(n),o=a.defaultQueryOptions(e),s=a.getQueryCache().get(o.queryHash),c=e.subscribed!==!1;o._optimisticResults=r?`isRestoring`:c?`optimistic`:void 0,ge(o),he(o,i,s),pe(i);let[l]=D.useState(()=>new t(a,o)),u=l.getOptimisticResult(o),d=!r&&c;if(D.useSyncExternalStore(D.useCallback(e=>{let t=d?l.subscribe(le.batchCalls(e)):oe;return l.updateResult(),t},[l,d]),()=>l.getCurrentResult(),()=>l.getCurrentResult()),D.useEffect(()=>{l.setOptions(o)},[o,l]),fe(o,u))throw ve(o,l,i);if(ye({result:u,errorResetBoundary:i,throwOnError:o.throwOnError,query:s,suspense:o.suspense}))throw u.error;return o.notifyOnChangeProps?u:l.trackResult(u)}var xe=`gilled.velvety.spored.saprotrophic.mycorrhizal.luminescent.honeycomb.truffley.wispy.earthy.mossy.woody.waxy.gelatinous.coral.inkcapped.feathery.stiped.ringed.annulate.scaly.shaggy.fuzzy.spiky.conical.umbral.parasol.leathery.damp.dewy.bristly.powdery.yeasty.musty.ancient.patient.steady.faithful.hardy.rootbound.forested.shaded.sunlit.sporeladen.golden.honeyed.amber.ivory.crimson.violet.indigo.silver.mossgreen.midnight.creamy.buttery.porcelain.glossy.matte.ribbed.fluted.wavy.lobed.branched.curled.folded.hooded.crowned.blushing.weeping.laughing.dancing.singing.whistling.glowing.ghostly.fairy.elfin.rustic.homey.barnraised.pasture.orchard.mill.woven.gardened.herded.trailed.ridged.meadow.fielded.vined.rooted.tendered.seasoned.ripe.wild.tame.broody.stubborn.gentle.drowsy.watchful.wandering.migratory.burrowed.nested.perched.loamy.mulched.composted.fermented.brewed.cured.smoked.pickled.preserved.aged.vintage.heirloom.grandmothers.forgotten.remembered.beloved.cherished.worn.weathered.windblown.rainsoaked.frosted.snowed.bloomed.flowered.seeded.sprouted.grafted.pruned.harvested.threshed.milled.baked.proofed.risen.folded.twisted.braided.stitched.patched.mended.polished.burnished.glazed.gilded.verdigris.patinaed.microdosed.tripping.wavy.prismatic.shimmering.rippling.echoing.oracular.mystic.kaleidoscopic.auroral.nebular.azure.psychedelic.transcendent.visionary.wandering.dreaming.phantom.spectral.iridescent.liminal.tidal.celestial.cosmic.astral.ethereal.incandescent`.split(`.`),Se=`shiitake.morel.chanterelle.bolete.puffball.oyster.enoki.maitake.lionsmane.truffle.porcini.agaric.amanita.bracket.conk.stipe.cap.gill.spore.hypha.mycelium.sporocarp.earthstar.stinkhorn.jelly.milkcap.blewit.cep.hedgehog.woodear.waxcap.inkcap.birdnest.cup.saddle.fieldcap.rust.smut.ergot.lichen.yeast.mold.toadstool.fruitingbody.basidiocarp.ascocarp.perithecium.apothecium.cystidium.basidium.clamp.septa.rhizomorph.sclerotium.gemma.annulus.volva.pileus.lamella.trama.gleba.peridium.sporangium.zygospora.conidia.teleomorph.anamorph.saprobe.endophyte.epiphyte.decomposer.recycler.alchemist.mycorrhiza.hyphae.web.net.lattice.thread.strand.root.tendril.runner.vine.ivy.moss.fern.liverwort.mule.cairn.almanac.parrot.birddog.watchdog.pigeon.ranch.barn.coop.pasture.meadow.field.orchard.gate.fence.silo.well.windmill.homestead.trail.ridge.creek.hill.grove.vineyard.apiary.garden.plot.furrow.shed.stable.trough.hayloft.rootcellar.smokehouse.springhouse.millstone.weathervane.lantern.tinderbox.candlemold.honeycomb.beeswax.propolis.nectar.pollen.comb.burrow.den.nest.perch.warren.colony.swarm.flock.herd.pod.grist.flour.starter.mother.scoby.kombucha.miso.tempeh.cheese.rennet.whey.curd.cream.butter.braid.loaf.crust.crumb.fiddlehead.sorrel.ramp.morelberry.huckleberry.thimbleberry.salmonberry.serviceberry.chokecherry.microdose.trip.shroom.liberty.teacher.treasure.wanderer.seeker.dreamer.shaman.visionary.tripper.oracle.seer.augur.prism.fractal.kaleidoscope.spectrum.nebula.aurora.comet.meteor.eclipse.zenith.horizon.mirage.echo.ripple.shimmer.glimmer.phantom.twilight.starlight.moonbeam`.split(`.`);function O(e){let t=Math.floor(4294967296/e.length)*e.length,n;do{let e=crypto.getRandomValues(new Uint32Array(1))[0];if(e===void 0)throw Error(`CSPRNG returned no candidate value`);n=e}while(n>=t);let r=e[n%e.length];if(r===void 0)throw Error(`Candidate vocabulary is empty`);return r}function Ce(e){if(e?.count===1/0)throw RangeError(`words count must be finite`);let t=Math.max(1,Math.floor(e?.count??2)),n=e?.separator??`-`,r=[O(xe)];for(let e=1;e<t;e++)r.push(O(Se));return r.join(n)}w(`app.backend`,1,m(()=>x({request:b(C(a().transform(e=>T(e))))})));var k=w(`app.methods`,1,m(()=>x({call:b(C(a().transform(e=>T(e))))})));w(`app.region`,1,m(()=>x({connect:b(x({messages:b(h(ReadableStream).transform(e=>e.pipeThrough(new TransformStream({transform(e,t){t.enqueue(ne().parse(e))}})))),send:S,close:S}))})));var A=72e4,we=re(`Clock`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`polyline`,{points:`12 6 12 12 16 14`,key:`68esgv`}]]),Te=A+18e4,Ee=`4 generations are running. Wait for one to finish.`,De=c({error:d(`generation_limit`),limit:r,message:s}),j=class extends ie{constructor(e){super(e,{code:`CONFLICT`,retryable:!0})}};function Oe(e,t){return e.computerId===void 0||e.computerId===t}var M=`@cf/black-forest-labs/flux-2-klein-4b`,ke=`Image creation is unavailable for this Computer right now.`,N={landscape:{height:768,width:1024},portrait:{height:1024,width:768},square:{height:1024,width:1024}},P=[`landscape`,`portrait`,`square`];function F(e){return e instanceof E&&e.stage===`provider`&&e.provider!==void 0&&`reason`in e.provider&&e.provider.reason===`credits_exhausted`}function Ae(e){if(!(e instanceof E)||e.stage!==`provider`)return;let t=e.provider;if(t===void 0||!(`code`in t))return;let n=e.code===`MEDIA_PROVIDER_FAILURE_UNCHARGED`?` You weren’t charged.`:``,r=(e,t,r)=>({title:e,message:t+n,retryable:r});switch(t.reason){case`content_refused`:return r(`Generation refused`,`The model refused this prompt (content policy). Try rewording it.`,!1);case`invalid_input`:return r(`Generation failed`,t.detail===void 0?`The provider rejected the input. Check the prompt and the reference image’s size and format.`:`The provider rejected the input: ${t.detail}.`,!1);case`rate_limited`:return r(`Generation failed`,`The provider is overloaded. Retry in a minute.`,!0);case`provider_unavailable`:return r(`Generation failed`,`The provider is having an outage. Retry in a minute.`,!0);case`timeout`:return r(`Still waiting`,`The model took too long to answer. Retry to ask again.`,!0);case`spending_limit`:return r(`Generation failed`,`The provider’s daily allowance is used up. Try another model, or retry tomorrow.`,!1);case`credits_exhausted`:return;case void 0:return t.detail===void 0?void 0:r(`Generation failed`,`The model stopped before it finished: ${t.detail}. Retry, or pick another model.`,!1)}}function I(e){if(e instanceof j)return{title:`Too many generations`,message:e.message,retryable:!0};if(F(e))return{title:`AI Gateway credits unavailable`,message:`Cloudflare AI Gateway couldn't fund this request. Check the account's credits and billing in the Cloudflare dashboard under AI Gateway, or choose a Workers AI model such as Flux.${e.code===`MEDIA_PROVIDER_FAILURE_UNCHARGED`?` You weren't charged.`:``}`,retryable:!1};let t=Ae(e);return t===void 0?e instanceof E&&e.stage!==`provider`?{...y(e),message:e.message}:y(e,{INSUFFICIENT_CREDIT:{title:`Couldn’t create image`,message:`Media generation needs Team credits. Add credits in Billing, then retry.`},DAILY_LIMIT_REACHED:{title:`Couldn’t create image`,message:`Today's spending limit for this Oyster is used up. It resets at 00:00 UTC.`},MEDIA_PROVIDER_FAILURE:{title:`Generation failed`,message:`The model stopped before it finished. Retry, or pick another model.`},MEDIA_PROVIDER_FAILURE_UNCHARGED:{title:`Generation failed`,message:`The model stopped before it finished. You weren’t charged. Retry, or pick another model.`},SAFETY_FILTER_REFUSED:{title:`Generation refused`,message:`The model refused this prompt. Change the prompt or reference image, then retry.`},TIMEOUT:{title:`Still waiting`,message:`The model didn’t answer in time. Retry to ask again.`},SETUP_REQUIRED:{title:`Setup needed`,message:`This model isn’t connected. Connect one in Settings, then retry.`},DISCONNECTED:{title:`Connection lost`,message:`Prints lost its connection. Reopen it, then retry.`},HOST_FAILURE:{title:`Couldn’t create image`,message:`Couldn't generate this media. Try again.`}}):t}function je(e){let t=l(c({code:ee(ae)}))(e);return{reason:t._tag===`Some`?t.value.code:F(e)?`INSUFFICIENT_CREDIT`:`UNKNOWN`,message:I(e).message}}function Me(){return{destination:void 0,height:768,model:M,prompt:``,references:[],steps:void 0,width:1024}}function Ne(e,t,n=`png`){if(e.trim().length===0)throw Error(`Media generation token must not be empty.`);let r=e.trim();if(!/^[a-zA-Z0-9]+(?:-[a-zA-Z0-9]+)*$/.test(r))throw Error(`Media generation basename contains invalid characters.`);return`${t.replace(/\/$/,``)}/generated-${r}.${n}`}function Pe(e,t,n){let r=e.destination?.trim();if(r)return r;let i=n?.outputFormats.includes(`png`)?`png`:n?.outputFormats[0]??`png`,a=n?.kind===`video`?`mp4`:n?.kind===`audio`?`mp3`:i===`jpeg`?`jpg`:i;return Ne(Ce({count:4}),t,a)}function Fe(e){return e?.kind===`audio`?e.audio?.mode===`music`?`Generate music`:`Generate speech`:e?.kind===`video`?`Generate video`:`Generate image`}function Ie(e){return e.filter(e=>e.kind!==`audio`&&e.transform===null)}function Le(e){return e.filter(e=>e.kind===`audio`)}function Re(e){let{references:t,width:n,height:r,...i}=e.settings;return{...i,references:t??[],destination:e.destination.path,width:n??1,height:r??1}}function ze(e,t){return e?.kind===`audio`?ue:{width:t.width,height:t.height}}function Be(e,t,n=!1){if(e===void 0)return`Creating media…`;if(e.kind===`audio`)return e.audio?.mode===`music`?`Composing music…`:`Making speech…`;if(e.transform?.operation===`remove_background`)return`Removing background…`;if(e.transform?.operation===`upscale`)return`Upscaling…`;if(e.kind!==`video`)return`Creating image…`;if(t===void 0)return`Creating video… Videos take about 2 minutes`;let r=Math.max(0,Math.floor(t/1e3));return`Creating video… ${String(Math.floor(r/60))}:${String(r%60).padStart(2,`0`)} elapsed${n?` since reopening`:``} · Videos take about 2 minutes`}var L=(e,t)=>t===0?e:L(t,e%t),R=(e,t,n)=>n===void 0?`${String(e)} × ${String(t)} · ${U(e,t)}`:`${String(e)} × ${String(t)} · ${String(n[0])}:${String(n[1])}`,z=[[1,1],[4,3],[3,4],[3,2],[2,3],[16,9],[9,16],[21,9]],B=16,Ve=256,He=4e6,V=1048576;function H(e,t,n,r){let i=Math.floor((e.input.maxDimension??4096)/B)*B,a=e=>Math.round(e/B)*B,o=e=>Math.min(i,Math.max(Ve,e)),s=L(t,n),c=t/s*B,l=n/s*B,u=r&&e.input.maxDimensionDocumented,d,f;if(Math.max(c,l)<=i/4){let e=u?Math.floor(i/Math.max(c,l)):Math.max(1,Math.round(Math.sqrt(V/(c*l))));d=c*e,f=l*e}else{let e=t/n;d=u?e>=1?i:a(i*e):a(Math.sqrt(V*e)),f=u?e>=1?a(i/e):i:a(d/e)}let p=Math.max(d,f)/i;return p>1&&(d=a(d/p),f=a(f/p)),{width:o(d),height:o(f)}}function Ue(e){if(e.kind!==`image`||e.input.dimensions!==`own`)return[];let t=new Set,n=new Set;for(let e of P){let{width:r,height:i}=N[e],a=L(r,i);n.add(`${String(r/a)}:${String(i/a)}`),t.add(`${String(r)}x${String(i)}`)}let r=[];for(let[i,a]of z){let o=n.has(`${String(i)}:${String(a)}`)?[]:[{size:H(e,i,a,!1),group:`Standard`}];e.input.maxDimensionDocumented&&o.push({size:H(e,i,a,!0),group:`Largest`});for(let{size:{width:e,height:n},group:s}of o){let o=`${String(e)}x${String(n)}`;t.has(o)||(t.add(o),r.push({value:o,label:R(e,n,[i,a]),width:e,height:n,group:s}))}}return r}function U(e,t){let n=e/t,r=z.find(([e,t])=>Math.abs(n/(e/t)-1)<=.02);if(r!==void 0)return`${String(r[0])}:${String(r[1])}`;let i=L(e,t),a=e/i,o=t/i;return a<=21&&o<=21?`${String(a)}:${String(o)}`:`${n.toFixed(2)}:1`}function We(e,t,n){if(e?.kind!==`image`||e.input.dimensions!==`own`||!(t>0&&n>0))return;let r=Math.log(t/n);if(e.sizes!==null){let t;for(let n of e.sizes){let e=/^(\d+)x(\d+)$/u.exec(n);if(e===null)continue;let i=Number(e[1]),a=Number(e[2]),o=Math.abs(Math.log(i/a)-r);(t===void 0||o<t.gap-1e-9)&&(t={width:i,height:a,gap:o})}return t===void 0?void 0:{width:t.width,height:t.height}}let i=z.find(([e,r])=>Math.abs(t/n/(e/r)-1)<=.02);return i===void 0?H(e,t,n,!1):H(e,i[0],i[1],!1)}function Ge(e,t,n){if(e?.input.dimensions===`none`)return null;let r=e?.video?.formats.find(e=>e.width===t&&e.height===n);if(r!==void 0)return`${r.resolution} ${r.aspectRatio}`;let i=L(t,n),a=t/i,o=n/i;return a<=21&&o<=21?`${String(a)}:${String(o)}`:`${String(t)} × ${String(n)}`}function Ke(e){return e?.video!==void 0&&e.video!==null?e.video.formats.map(e=>({value:`${String(e.width)}x${String(e.height)}`,label:`${e.resolution} · ${e.aspectRatio} · ${String(e.width)} × ${String(e.height)}`,width:e.width,height:e.height})):e!==void 0&&e.sizes!==null?e.sizes.flatMap(e=>{let t=/^(\d+)x(\d+)$/u.exec(e);if(t===null)return[];let n=Number(t[1]),r=Number(t[2]);return[{value:e,label:R(n,r),width:n,height:r,group:n*r>=He?`Largest`:`Standard`}]}):[...P.map(e=>({value:e,label:R(N[e].width,N[e].height),...N[e],group:`Standard`})),...e===void 0?[]:Ue(e)]}function qe(e,t,n){return n?.kind===`video`&&t.kind===`video`||t.input.dimensions!==`none`&&i(_(K(()=>t))({model:t.id,width:e.width,height:e.height}))?{width:e.width,height:e.height}:{width:t.input.defaultWidth,height:t.input.defaultHeight}}function Je(e){return e.label.split(` — `)[0]??e.label}function Ye(e,t){return e.find(e=>e.id===t)}function Xe(e,t){return{...e,height:t.input.defaultHeight,model:t.id,steps:t.input.steps===`fixed`?void 0:t.input.defaultSteps??void 0,durationSeconds:t.video?.defaultSeconds??t.audio?.seconds?.default,voiceId:t.audio?.defaultVoiceId??void 0,generateAudio:t.video?.defaultGenerateAudio??void 0,width:t.input.defaultWidth}}var Ze={"first-frame":`First frame`,"last-frame":`Last frame`,reference:`Reference`};function Qe(e,t,n){let r=t[n]?.role,i=r===void 0?0:e.indexOf(r)+1;return[...e.slice(i),...e.slice(0,i)].find(e=>e!==r&&(e===`reference`||!t.some((t,r)=>r!==n&&t.role===e)))}function W(e){return e?.video?.referenceRoles??[]}function G(e,t,n=!1){let r=W(t);if(t?.video==null)return e.map(({path:e,computerId:t})=>t===void 0?{path:e}:{path:e,computerId:t});let i=e.map(e=>e.role!==void 0&&r.includes(e.role)?e.role:void 0),a=e=>i.includes(e),o=r.includes(`last-frame`),s=n&&r.includes(`reference`)||a(`reference`)||!a(`first-frame`)&&!a(`last-frame`)&&e.length>(o?2:1);return e.map((e,t)=>{let n=i[t];return n===void 0&&(n=s&&r.includes(`reference`)?`reference`:!a(`first-frame`)&&r.includes(`first-frame`)?`first-frame`:o&&!a(`last-frame`)?`last-frame`:r.includes(`reference`)?`reference`:`first-frame`,i[t]=n),{...e,role:n}})}function $e(e,t,n){let r=t.video;if(r===null||e.length===0)return;let i=t=>e.filter(e=>e.role===t).length,a=i(`first-frame`),o=i(`last-frame`),s=i(`reference`);if(a>1||o>1)return r.referenceRoles.includes(`last-frame`)?`${t.label} takes one first frame and one last frame.`:`${t.label} takes one first frame.`;if(o>0&&a===0)return`A last frame needs a first frame as well.`;if(s>0&&a+o>0)return`Frames and references cannot be mixed. Use a first and last frame, or references.`;if(s>r.maxReferenceImages)return r.maxReferenceImages===0?`${t.label} takes no reference images.`:`${t.label} takes up to ${String(r.maxReferenceImages)} reference images.`;if(s>0&&n!==void 0&&!r.referenceResolutions.some(e=>e===n))return`${t.label} takes reference images only at ${r.referenceResolutions.join(`, `)}.`}function et(e,t){let n=t.video?.formats.find(t=>t.width===e.width&&t.height===e.height);if(t.kind===`video`&&n===void 0)throw Error(`Choose a supported video resolution and aspect ratio.`);if(t.kind===`audio`){let n={model:e.model,prompt:e.prompt.trim()};return t.audio?.mode===`speech`&&e.voiceId!==void 0&&(n.voiceId=e.voiceId),t.audio?.mode===`music`&&e.durationSeconds!==void 0&&(n.durationSeconds=e.durationSeconds),{destination:{path:e.destination?.trim()??``},settings:n}}let r={height:e.height,model:e.model,prompt:e.prompt.trim(),width:e.width};return n!==void 0&&(r.resolution=n.resolution,r.aspectRatio=n.aspectRatio),e.steps!==void 0&&(r.steps=e.steps),e.durationSeconds!==void 0&&(r.durationSeconds=e.durationSeconds),e.references.length>0&&(r.references=G(e.references,t)),t.video?.supportsAudio===!0&&e.generateAudio!==void 0&&(r.generateAudio=e.generateAudio),{destination:{path:e.destination?.trim()??``},settings:r}}function K(e){return c({model:s,width:u,height:u,durationSeconds:g(t(u)),steps:g(t(u))}).check(te(t=>{let n=e(t.model);if(!Number.isSafeInteger(t.width)||t.width<1)return{path:[`width`],issue:`Width must be a positive integer.`};if(!Number.isSafeInteger(t.height)||t.height<1)return{path:[`height`],issue:`Height must be a positive integer.`};if(n!==void 0){if(n.input.dimensions===`own`){let e=n.input.maxDimension??4096;if(t.width<256||t.height<256)return{path:[t.width<256?`width`:`height`],issue:`${n.label} requires dimensions of at least 256 × 256.`};if(t.width>e||t.height>e)return{path:[t.width>e?`width`:`height`],issue:`${n.label} accepts dimensions up to ${String(e)}.`}}if(n.sizes!==null&&!n.sizes.includes(`${String(t.width)}x${String(t.height)}`))return{path:[`width`],issue:`${n.label} accepts only these sizes: ${n.sizes.join(`, `)}.`};if(n.audio?.seconds!=null&&t.durationSeconds!==void 0&&(!Number.isSafeInteger(t.durationSeconds)||t.durationSeconds<n.audio.seconds.min||t.durationSeconds>n.audio.seconds.max))return{path:[`durationSeconds`],issue:`${n.label} makes tracks from ${String(n.audio.seconds.min)} to ${String(n.audio.seconds.max)} seconds.`};if(n.video!==null&&t.durationSeconds!==void 0&&(!Number.isSafeInteger(t.durationSeconds)||t.durationSeconds<n.video.minSeconds||t.durationSeconds>n.video.maxSeconds))return{path:[`durationSeconds`],issue:`${n.label} makes clips from ${String(n.video.minSeconds)} to ${String(n.video.maxSeconds)} seconds.`};if(n.input.steps===`fixed`&&t.steps!==void 0)return{path:[`steps`],issue:`${n.label} uses fixed steps.`};if(t.steps!==void 0&&(!Number.isSafeInteger(t.steps)||t.steps<1||n.input.maxSteps!==null&&t.steps>n.input.maxSteps))return{path:[`steps`],issue:`${n.label} accepts at most ${String(n.input.maxSteps??`the provider limit`)} steps.`}}}))}function tt(e,t){let n=e.trim().length;return n>t.maxPromptLength?{length:n,excess:n-t.maxPromptLength}:null}function nt(e,t){if(e.destination?.trim().length===0)return`A destination file path is required.`;if(e.prompt.trim().length===0)return t?.kind===`video`?`Describe the video to generate.`:t?.kind===`audio`?t.audio?.mode===`music`?`Describe the music to generate.`:`Write what the voice should say.`:`Describe the image to generate.`;if(t===void 0)return`Choose a model from the granted registry.`;let n=tt(e.prompt,t);if(n!==null)return`${t.label} accepts prompts up to ${String(t.maxPromptLength)} characters; this one is ${String(n.length)}. Shorten it by ${String(n.excess)}.`;let r=_(K(()=>t))(e);if(o(r))return f()(r.failure.issue).issues.map(e=>e.message).join(` `);if(e.references.length>t.input.maxReferences)return`${t.label} accepts at most ${String(t.input.maxReferences)} reference images.`;if(e.references.length>0&&t.input.referenceField===null)return`${t.label} does not accept reference images.`;if(t.video!==null){let n=t.video.formats.find(t=>t.width===e.width&&t.height===e.height);return $e(G(e.references,t),t,n?.resolution)}}var q=n(),J=(0,D.forwardRef)(function({className:e,size:t=`md`,depth:n=`shallow`,placement:r=`standalone`,...i},a){return(0,q.jsx)(`div`,{...i,ref:a,"data-surface-size":t,"data-surface-depth":n,"data-surface-placement":r,className:v(`caps-surface`,e)})}),Y=(0,D.forwardRef)(function({className:e,...t},n){return(0,q.jsx)(`div`,{...t,ref:n,className:v(`caps-screen`,e)})});(0,D.forwardRef)(function({children:e,className:t,depth:n=`deep`,fit:r=`content`,density:i=`normal`,...a},o){let s=r===`fill`;return(0,q.jsx)(J,{...a,className:v(t,s&&`flex min-h-0 flex-1`),depth:n,ref:o,children:(0,q.jsx)(`div`,{className:v(`caps-display-gasket`,s&&`flex min-h-0 min-w-0 flex-1`),"data-display-density":i,children:(0,q.jsx)(Y,{className:v(s&&`flex min-h-0 min-w-0 flex-1 overflow-hidden`),children:e})})})}),(0,D.forwardRef)(function({className:e,icon:t,status:n,title:r,...i},a){return(0,q.jsxs)(`header`,{...i,className:v(`caps-screen-header`,e),ref:a,children:[t?(0,q.jsx)(`span`,{className:`caps-screen-header-icon`,"aria-hidden":`true`,children:t}):null,(0,q.jsx)(`span`,{className:`caps-screen-header-title`,children:r}),n?(0,q.jsx)(`span`,{className:`caps-screen-header-status`,children:n}):null]})}),(0,D.forwardRef)(function({appearance:e,className:t,...n},r){return(0,q.jsx)(`div`,{...n,className:v(`caps-screen-cells`,t),"data-appearance":e===`compact`?e:void 0,ref:r})}),(0,D.forwardRef)(function({children:e,className:t,legend:n,readout:r,icon:i,appearance:a,wide:o=!1,...s},c){return(0,q.jsxs)(`div`,{...s,className:v(`caps-screen-cell`,t),"data-wide":o||void 0,"data-appearance":a===`compact`?a:void 0,ref:c,children:[i?(0,q.jsx)(`span`,{className:`caps-screen-cell-icon`,children:i}):null,n?(0,q.jsx)(`span`,{className:`caps-screen-cell-legend`,children:n}):null,r?(0,q.jsx)(`span`,{className:`caps-screen-cell-readout`,children:r}):null,a===`compact`?(0,q.jsx)(`div`,{className:`caps-screen-cell-controls`,children:e}):e]})});function rt(e,t){ce.error(e,{id:t,toasterId:`prints-generation-notices`})}var X=(0,D.createContext)(null),it=(0,D.forwardRef)(function({children:e,defaultValue:t,onValueChange:n,value:r,...i},a){let[o,s]=(0,D.useState)(t),c=r??o,l=(0,D.useId)(),u=e=>{r===void 0&&s(e),n?.(e)},d=(e,t)=>`${l}-${e}-${encodeURIComponent(t)}`;return(0,q.jsx)(X.Provider,{value:{onValueChange:u,panelId:e=>d(`panel`,e),selectedValue:c,tabId:e=>d(`tab`,e)},children:(0,q.jsx)(`div`,{...i,className:v(`w-full`,i.className),ref:a,children:e})})});function Z(){let e=(0,D.useContext)(X);if(!e)throw Error(`Tabs parts must be used inside <Tabs>`);return e}var at=(0,D.forwardRef)(function({className:e,variant:t=`bordered`,...n},r){return(0,q.jsx)(`div`,{...n,"aria-orientation":n[`aria-orientation`]??`horizontal`,className:v(t===`segmented`?`tabs caps-tabs-segmented w-full`:`tabs tabs-border flex w-full items-center gap-xs`,e),"data-variant":t,ref:r,role:`tablist`})}),ot=(0,D.forwardRef)(function({className:e,disabled:t,onClick:n,onKeyDown:r,value:i,...a},o){let s=Z(),c=s.selectedValue===i,l=e=>{let t=e.currentTarget.closest(`[role="tablist"]`);if(!(t instanceof HTMLElement))return;let n=Array.from(t.querySelectorAll(`[role="tab"]`)).filter(e=>!e.disabled&&e.getAttribute(`aria-disabled`)!==`true`),r=n.indexOf(e.currentTarget);if(r<0||n.length===0)return;let a;if(e.key===`ArrowRight`)a=(r+1)%n.length;else if(e.key===`ArrowLeft`)a=(r-1+n.length)%n.length;else if(e.key===`Home`)a=0;else if(e.key===`End`)a=n.length-1;else return;e.preventDefault();let o=n[a];o?.focus(),o&&s.onValueChange(o.dataset.tabValue??i)};return(0,q.jsx)(`button`,{...a,"aria-controls":s.panelId(i),"aria-disabled":t?!0:void 0,"aria-selected":c,className:v(`tab whitespace-nowrap text-base-content transition-colors focus-visible:outline-none focus-visible:ring-2 caps-focus-color`,c&&`tab-active`,e),"data-tab-value":i,disabled:t,id:s.tabId(i),onClick:e=>{n?.(e),!e.defaultPrevented&&!t&&s.onValueChange(i)},onKeyDown:e=>{r?.(e),e.defaultPrevented||l(e)},ref:o,role:`tab`,tabIndex:t?-1:c?0:-1,type:a.type??`button`})});(0,D.forwardRef)(function({children:e,className:t,forceMount:n=!1,value:r,...i},a){let o=Z(),s=o.selectedValue===r;return!s&&!n?null:(0,q.jsx)(`div`,{...i,"aria-labelledby":o.tabId(r),className:v(`mt-md focus-visible:outline-none`,t),hidden:!s,id:o.panelId(r),ref:a,role:`tabpanel`,tabIndex:0,children:e})});var st=`modulepreload`,ct=function(e,t){return new URL(e,t).href},Q={},lt=function(e,t,n){let r=Promise.resolve();if(t&&t.length>0){let e=document.getElementsByTagName(`link`),i=document.querySelector(`meta[property=csp-nonce]`),a=i?.nonce||i?.getAttribute(`nonce`);function o(e){return Promise.all(e.map(e=>Promise.resolve(e).then(e=>({status:`fulfilled`,value:e}),e=>({status:`rejected`,reason:e}))))}function s(e){return import.meta.resolve?import.meta.resolve(e):new URL(e,import.meta.url).href}r=o(t.map(t=>{if(t=ct(t,n),t=s(t),t in Q)return;Q[t]=!0;let r=t.endsWith(`.css`);for(let n=e.length-1;n>=0;n--){let i=e[n];if(i.href===t&&(!r||i.rel===`stylesheet`))return}let i=document.createElement(`link`);if(i.rel=r?`stylesheet`:st,r||(i.as=`script`),i.crossOrigin=``,i.href=t,a&&i.setAttribute(`nonce`,a),document.head.appendChild(i),r)return new Promise((e,n)=>{i.addEventListener(`load`,e),i.addEventListener(`error`,()=>n(Error(`Unable to preload CSS for ${t}`)))})}))}function i(e){let t=new Event(`vite:preloadError`,{cancelable:!0});if(t.payload=e,window.dispatchEvent(t),!t.defaultPrevented)throw e}return r.then(t=>{for(let e of t||[])e.status===`rejected`&&i(e.reason);return e().catch(i)})};function ut(e,t=`length`){let n=Math.max(0,t===`length`?Math.ceil(e):Math.floor(e)),r=Math.floor(n/60);return`${String(r)}:${String(n%60).padStart(2,`0`)}`}function dt(e,t=64){let n=e.reduce((e,t)=>Math.max(e,t.length),0);if(n===0||t<=0)return Object.freeze(Array.from({length:Math.max(t,0)},()=>0));let r=Array.from({length:t},()=>0);for(let i=0;i<t;i+=1){let a=Math.floor(i*n/t),o=Math.max(a+1,Math.floor((i+1)*n/t)),s=0;for(let t of e){let e=Math.min(o,t.length);for(let n=a;n<e;n+=1)s=Math.max(s,Math.abs(t[n]??0))}r[i]=s}let i=r.reduce((e,t)=>Math.max(e,t),0);return Object.freeze(i===0?r:r.map(e=>e/i))}async function ft(e,t=64){let n=await new OfflineAudioContext(1,1,44100).decodeAudioData(e);return{peaks:dt(Array.from({length:n.numberOfChannels},(e,t)=>n.getChannelData(t)),t),durationSeconds:n.duration}}var $=new Map;async function pt(e,t){let n=await fetch(e);if(!n.ok)throw Error(`audio responded ${String(n.status)}`);return ft(await n.arrayBuffer(),t)}function mt(e,t){let n=`${String(t)}:${e}`,r=$.get(n);if(r!==void 0)return r;let i=pt(e,t).catch(e=>{throw $.delete(n),e});return $.set(n,i),i}function ht(e,t=64){let[n,r]=(0,D.useState)({status:`loading`});return(0,D.useEffect)(()=>{if(e===``){r({status:`failed`});return}let n=!0;return r({status:`loading`}),mt(e,t).then(e=>{n&&r({status:`ready`,...e})},e=>{de(`decode-audio-waveform`,e),n&&r({status:`failed`})}),()=>{n=!1}},[e,t]),n}export{Ie as A,j as B,et as C,Ye as D,We as E,Ke as F,k as G,Ee as H,qe as I,be as K,R as L,W as M,G as N,Je as O,Ge as P,nt as R,je as S,Oe as T,De as U,Te as V,we as W,I as _,at as a,Fe as b,Y as c,ke as d,Ze as f,Me as g,Le as h,it as i,U as j,Qe as k,J as l,N as m,ht as n,ot as o,P as p,lt as r,rt as s,ut as t,M as u,Xe as v,Be as w,Pe as x,Re as y,ze as z};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{A as t,C as n,D as r,F as i,I as a,J as o,M as s,T as c,Vn as l,W as u,at as d,b as f,ct as p,d as m,it as h,l as ee,m as te,n as ne,ot as g,v as _,w as v,x as y}from"./button-oE2Hrd5D.js";import{Mt as re}from"./dist-DAokFn5x.js";import{r as b,s as x}from"./log-event-B3BGsDWO.js";import{a as S,i as C,m as w,t as T}from"./query-CYqgVHJ7.js";import{C as E,G as D,K as O,N as k,R as A,x as j}from"./audio-waveform-xSq1S4ms.js";import{c as M,d as N,l as ie,n as ae,o as oe,s as se,t as ce}from"./textarea-DUwcxEMN.js";import{t as le}from"./keycap-D2RkH2IS.js";function ue(e,t){return O(e,w,t)}var de=y(`ArrowUp`,[[`path`,{d:`m5 12 7-7 7 7`,key:`hav0vg`}],[`path`,{d:`M12 19V5`,key:`x0mq9r`}]]),fe=y(`ChevronUp`,[[`path`,{d:`m18 15-6-6-6 6`,key:`153udz`}]]),pe=y(`Cpu`,[[`rect`,{width:`16`,height:`16`,x:`4`,y:`4`,rx:`2`,key:`14l7u7`}],[`rect`,{width:`6`,height:`6`,x:`9`,y:`9`,rx:`1`,key:`5aljv4`}],[`path`,{d:`M15 2v2`,key:`13l42r`}],[`path`,{d:`M15 20v2`,key:`15mkzm`}],[`path`,{d:`M2 15h2`,key:`1gxd5l`}],[`path`,{d:`M2 9h2`,key:`1bbxkp`}],[`path`,{d:`M20 15h2`,key:`19e6y8`}],[`path`,{d:`M20 9h2`,key:`19tzq7`}],[`path`,{d:`M9 2v2`,key:`165o2o`}],[`path`,{d:`M9 20v2`,key:`i2bqo8`}]]),me=y(`Maximize2`,[[`polyline`,{points:`15 3 21 3 21 9`,key:`mznyad`}],[`polyline`,{points:`9 21 3 21 3 15`,key:`1avn1i`}],[`line`,{x1:`21`,x2:`14`,y1:`3`,y2:`10`,key:`ota7mn`}],[`line`,{x1:`3`,x2:`10`,y1:`21`,y2:`14`,key:`1atl0r`}]]),he=y(`Square`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}]]),P={remove_background:`Remove background`,upscale:`Upscale`};function ge(e,t){return e.find(e=>e.transform?.operation===t)}function _e(e,t){let n=t.width*t.height/1e6;return(e.transform?.sizes??[]).map(({megapixels:e})=>({megapixels:e,disabledReason:n>=e?`This image is already ${n.toFixed(1)} MP.`:void 0}))}function ve(e,t){let n=e.transform?.source;if(n===void 0)return`${e.label} is not an image action.`;if(t.width*t.height>n.maxPixels)return`This image is over ${String(n.maxPixels/1e6)} MP, the most ${e.label} takes.`}function ye(e,t,n){let r=e.transform;if(r===null)throw Error(`${e.id} is not an image action`);let i={computerId:t.computerId,path:t.path};if(r.operation===`upscale`){let t=n??r.defaultMegapixels;if(t===null)throw Error(`${e.id} needs an output size`);return{model:e.id,prompt:`${P.upscale} to ${String(t)} MP`,references:[i],targetMegapixels:t}}return{model:e.id,prompt:P[r.operation],references:[i]}}var be=e=>{let t=e.lastIndexOf(`/`);return t<=0?`/`:e.slice(0,t)};function xe(e,t,n){let r=ye(e,t,n),i={model:e.id,prompt:r.prompt,references:r.references??[],width:t.width,height:t.height},a=j(i,be(t.path),e);return{input:{destination:{path:a},settings:r},draft:{...i,destination:a}}}var F={readNotices:`member.readNotices`,dismissNotices:`member.dismissNotices`,listStyles:`member.listStyles`,saveStyle:`member.saveStyle`,deleteStyle:`member.deleteStyle`,readPrintStyle:`member.readPrintStyle`,listCharacters:`member.listCharacters`,saveCharacter:`member.saveCharacter`,deleteCharacter:`member.deleteCharacter`,readFolder:`member.readFolder`,selectFolder:`member.selectFolder`,rememberGeneration:`member.rememberGeneration`,failGeneration:`member.failGeneration`,forgetGeneration:`member.forgetGeneration`,completeGeneration:`member.completeGeneration`,listGenerations:`member.listGenerations`};function I(e,t,n){return e.require(D).call(t,n)}var L=t,Se=t.pipe(u(h(1024))),Ce=v(Se).pipe(u(h(200)));a({computerId:L}),a({computerId:L,keys:Ce});var we=a({keys:Ce}),Te=o(we);async function Ee(e,t){return Te(await I(e,F.readNotices,JSON.stringify({computerId:t})))}async function De(e,t,n){return Te(await I(e,F.dismissNotices,JSON.stringify({computerId:t,keys:n})))}a({computerId:L,path:N});var Oe=a({path:N,configured:c}),ke=o(Oe);async function Ae(e,t){return ke(await I(e,F.readFolder,JSON.stringify({computerId:t})))}async function je(e,t,n){return ke(await I(e,F.selectFolder,JSON.stringify({computerId:t,path:n})))}var Me=2048,Ne=8e3,Pe=[{name:`Anime cel`,text:`Anime cel illustration with clean ink outlines, flat cel shading, and a limited palette of saturated colors. Soft painted backgrounds, expressive eyes, and crisp highlights, in the look of a hand-drawn animation frame.`},{name:`Cinematic film still`,text:`Cinematic film still shot on anamorphic lenses with shallow depth of field. Moody, motivated lighting, subtle film grain, and a considered color grade, composed like a frame from a feature film.`},{name:`Watercolor`,text:`Soft watercolor painting on textured paper, with translucent washes, visible pigment bleeds, and gentle color gradients. Loose brushwork, white paper left showing at the edges, and a calm, airy mood.`},{name:`Pixel art`,text:`Pixel art with a limited color palette, crisp square pixels, and no anti-aliasing. Clear readable silhouettes, dithered shading, and the charm of a classic 16-bit game sprite or scene.`},{name:`Product photo`,text:`Professional product photograph on a seamless studio background. Soft diffused lighting with gentle shadows, sharp focus across the subject, accurate colors, and clean, minimal composition suited to a catalog.`},{name:`Comic ink`,text:`Comic book panel with bold black ink linework, hatching and crosshatched shadows, and flat vivid colors. Dynamic angles, strong contrast, and a printed halftone texture.`}].map((e,t)=>({...e,id:-(t+1),builtIn:!0})),R=i.pipe(u(d(1)),u(h(64))),Fe=i.pipe(u(d(1)),u(h(Ne))),z=t,Ie=a({id:r,name:R,text:Fe,builtIn:c});a({computerId:z,id:p(r),name:R,text:Fe}),a({computerId:z,id:r}),a({computerId:z,path:t});var Le=a({styles:v(Ie).pipe(u(h(50+Pe.length)))}),Re=a({style:s(R)});function B(e,t){let n=t.trim();return e===void 0?n:`${e.trim()}\n\n${n}`}function ze(e){return e?.maxPromptLength??Me}function Be(e,t,n,r=[]){if(e.length<=t)return;let i=`${String(e.length)} characters; this model accepts at most ${String(t)}.`,a=r.map(e=>`@${e}`).join(`, `);return n!==void 0&&a!==``?`The "${n}" style and your prompt with ${a} expanded total ${i}`:n===void 0?a===``?`The prompt is ${i}`:`Your prompt with ${a} expanded is ${i}`:`The "${n}" style and your prompt total ${i}`}var V=o(Le);async function Ve(e,t){return V(await I(e,F.listStyles,JSON.stringify({computerId:t})))}async function He(e,t,n){return V(await I(e,F.saveStyle,JSON.stringify({computerId:t,id:n.id,name:n.name,text:n.text})))}async function Ue(e,t,n){return V(await I(e,F.deleteStyle,JSON.stringify({computerId:t,id:n})))}async function We(e,t,n){return o(Re)(await I(e,F.readPrintStyle,JSON.stringify({computerId:t,path:n})))}var H=/(?<![\p{L}\p{N}_@-])@image(\d+)(?![\p{L}\p{N}_-])/giu,U=e=>`image${String(e)}`;function W(e){let t=[];for(let n of e.matchAll(H)){let e=Number(n.at(1));t.includes(e)||t.push(e)}return t}var Ge=(e,t)=>JSON.stringify([e.computerId??t,e.path]),G={labels:new Map,next:1};function Ke(e,t,n){let r=W(n).length>0;if(t.length===0)return e.labels.size===0&&(e.next===1||r)?e:r?{labels:new Map,next:e.next}:G;let i=e.labels.size>0&&t.every(t=>!e.labels.has(t))?G:e,a=new Map,o=i.next;for(let e of t)a.has(e)||(a.set(e,i.labels.get(e)??o),i.labels.has(e)||(o+=1));return a.size===e.labels.size&&o===e.next&&[...a].every(([t,n])=>e.labels.get(t)===n)?e:{labels:a,next:o}}function qe(e,t){return t.map(t=>e.labels.get(t)??0)}function K(e,t){let n=0;return e.map(e=>{if(t?.kind===`video`){if(e.role===`first-frame`)return`the first frame`;if(e.role===`last-frame`)return`the last frame`}return n+=1,`image ${String(n)}`})}function Je(e,t,n){let r=[],i=e.replace(H,(e,i)=>{let a=t.indexOf(Number(i)),o=a<0?void 0:n.at(a);if(o===void 0){let t=U(Number(i));return r.includes(t)||r.push(t),e}return o});return r.length===0?{kind:`ready`,prompt:i}:{kind:`missing`,labels:r}}function Ye(e,t){return e.replace(H,(e,n)=>{let r=t(Number(n));return r===void 0||r<1?e:`@${U(r)}`})}var Xe=8,q=i.pipe(u(d(1)),u(h(32)),u(g(/^[\p{L}\p{N}_-]+$/u)),u(g(/^(?!image\d+$)/iu))),Ze=i.pipe(u(h(500))),Qe=t.pipe(u(h(4096))),$e=v(a({path:Qe})).pipe(u(h(8))),et=t,tt=a({id:r,name:q,description:Ze,references:$e});a({computerId:et,id:p(r),name:q,description:Ze,references:$e}),a({computerId:et,id:r});var nt=a({characters:v(tt).pipe(u(h(50)))}),J=(e,t)=>e.toLowerCase()===t.toLowerCase(),rt=/(?<![\p{L}\p{N}_@-])@([\p{L}\p{N}_-]+)/gu;function it(e){let t=[];for(let n of e.matchAll(rt)){let e=n.at(1);e!==void 0&&!t.some(t=>J(t,e))&&t.push(e)}return t}function Y(e,t){let n=[];return{prompt:e.replace(rt,(e,r)=>{let i=t.find(e=>J(e.name,r));if(i===void 0)return e;let a=!n.includes(i);return a&&n.push(i),a&&i.description.trim()!==``?`${i.name} (${i.description.trim()})`:i.name}),characters:n}}function at(e,t,n){let r=e.trim();return B(t,Y(r,n).prompt).length-r.length}function ot(e,t){let n=it(e),r=t.filter(e=>!n.some(t=>J(t,e)));return r.length===0?e:`${r.map(e=>`@${e}`).join(` `)} ${e}`}function st(e,t,n){let r=(e,t)=>e.path===t&&(e.computerId===void 0||e.computerId===n),i=[...e];for(let e of t)for(let t of e.references)i.some(e=>r(e,t.path))||i.push({path:t.path});return i}function ct(e){return{kind:`ready`,prompt:e,references:[],characters:[]}}function lt(e){let t=ot(e.prompt,e.names??[]),n=Y(t,e.saved),r=st(e.references,n.characters,e.computerId),i=(e.wording??(e=>K(e,void 0)))(r),a=Je(t,e.labels??e.references.map((e,t)=>t+1),i.slice(0,e.references.length));if(a.kind===`missing`)return{kind:`refused`,message:`${a.labels.map(e=>`@${e}`).join(`, `)} ${a.labels.length===1?`names a reference that is`:`name references that are`} not attached. Remove ${a.labels.length===1?`it`:`them`} from the prompt or attach the image again.`};let o=r.length-e.references.length;if(e.model!==void 0&&o>0&&r.length>e.model.maxReferences){let t=n.characters.map(e=>e.name).join(`, `);return{kind:`refused`,message:e.model.maxReferences===0?`${e.model.label} does not take reference images, so it cannot use ${t}.`:`${t} add ${String(o)} reference ${o===1?`image`:`images`} to your ${String(e.references.length)}; ${e.model.label} accepts at most ${String(e.model.maxReferences)}.`}}return{kind:`ready`,prompt:Y(a.prompt,e.saved).prompt,references:r,characters:n.characters}}function ut(e,t){let n=/(?<![\p{L}\p{N}_@-])@([\p{L}\p{N}_-]*)$/u.exec(e.slice(0,t));return n===null?null:{start:n.index,query:n.at(1)??``}}function dt(e,t,n){let r=n.toLowerCase(),i=e=>U(e.number).toLowerCase();return[...[...t.filter(e=>i(e).startsWith(r)),...t.filter(e=>!i(e).startsWith(r)&&i(e).includes(r))].map(e=>({kind:`reference`,reference:e})),...ft(e,n).map(e=>({kind:`character`,character:e}))]}function ft(e,t){let n=t.toLowerCase(),r=e=>e.name.toLowerCase();return[...e.filter(e=>r(e).startsWith(n)),...e.filter(e=>!r(e).startsWith(n)&&r(e).includes(n))].slice(0,Xe)}var pt=o(nt);async function mt(e,t){return pt(await I(e,F.listCharacters,JSON.stringify({computerId:t})))}async function ht(e,t,n){return pt(await I(e,F.saveCharacter,JSON.stringify({computerId:t,id:n.id,name:n.name,description:n.description,references:n.references})))}async function gt(e,t,n){return pt(await I(e,F.deleteCharacter,JSON.stringify({computerId:t,id:n})))}var X={models:e=>C.of(e,`prints`,`models`),folder:e=>C.of(e,`prints`,`folder`),dismissals:e=>C.of(e,`prints`,`dismissals`),styles:e=>C.of(e,`prints`,`styles`),printStyle:(e,t)=>C.of(e,`prints`,`print-style`,t),characters:e=>C.of(e,`prints`,`characters`)};function _t(e){return{...T(e,b,X.models(e),async(t,n)=>{if(!e)throw Error(`Prints is disconnected`);let r=await x(e.capabilities);return n.throwIfAborted(),r}),enabled:!!(e?.context.get().computerId&&e.capabilities.has(b)),structuralSharing:!1}}function vt(e){let t=e?.context.get().computerId;return{...T(e,D,X.folder(e),async(n,r)=>{if(!e||!t)throw Error(`No Computer selected`);let i=await Ae(e.capabilities,t);if(r.throwIfAborted(),e.context.get().computerId!==t)throw new re(`Computer selection changed`,{code:`SELECTION_CHANGED`,retryable:!1});return i}),enabled:!!(t&&e.capabilities.has(D))}}function yt(e){let t=e?.context.get().computerId;return{...T(e,D,X.dismissals(e),async(n,r)=>{if(!e||!t)throw Error(`No Computer selected`);let i=await Ee(e.capabilities,t);return r.throwIfAborted(),i}),enabled:!!(t&&e.capabilities.has(D))}}function bt(e){let t=e?.context.get().computerId;return{...T(e,D,X.styles(e),async(n,r)=>{if(!e||!t)throw Error(`No Computer selected`);let i=await Ve(e.capabilities,t);return r.throwIfAborted(),i}),enabled:!!(t&&e.capabilities.has(D))}}function xt(e,t){let n=e?.context.get().computerId;return{...T(e,D,X.printStyle(e,t??``),async(r,i)=>{if(!e||!n||t===null)throw Error(`No print selected`);let a=await We(e.capabilities,n,t);return i.throwIfAborted(),a}),enabled:!!(n&&t!==null&&e.capabilities.has(D))}}function St(e){let t=e?.context.get().computerId;return{...T(e,D,X.characters(e),async(n,r)=>{if(!e||!t)throw Error(`No Computer selected`);let i=await mt(e.capabilities,t);return r.throwIfAborted(),i}),enabled:!!(t&&e.capabilities.has(D))}}var Z=e(l(),1),Q=n();function Ct(e,t=/Mac|iPhone|iPad/u.test(globalThis.navigator.userAgent)){if(e.startsWith(`<leader>`)){let t=e.replaceAll(`<leader>`,`Ctrl K `).trimEnd();return e.endsWith(` `)?`${t} Space`:t}return e.split(` `).map(e=>e.split(`+`).map(e=>e===`mod`?t?`⌘`:`Ctrl`:e===`escape`?`Esc`:e.length===1?e.toUpperCase():e.charAt(0).toUpperCase()+e.slice(1)).join(e===`ctrl+k`||e===`mod+k`?` `:`+`)).join(` `)}function wt(e){let t=new Map;for(let n of e.bindings)t.set(n.commandId,[...t.get(n.commandId)??[],Ct(n.binding)]);return e.slash.map(e=>({alias:e.alias,commandId:e.commandId,command:e.command,title:e.title,description:e.description,category:e.category,order:e.order,grammar:e.arguments,consumesDraft:e.consumesDraft,keys:t.get(e.commandId)??[],availability:e.availability}))}function Tt(e,t){let n=e.toLocaleLowerCase(),r=t.toLocaleLowerCase();if(r.length===0)return{tier:0,spread:0,indices:[]};let i=e=>Array.from({length:r.length},(t,n)=>e+n);if(n.startsWith(r))return{tier:0,spread:n.length-r.length,indices:i(0)};let a=n.search(RegExp(`[-_\\s]${r.replaceAll(/[.*+?^${}()|[\]\\]/gu,`\\$&`)}`,`u`));if(a>=0)return{tier:1,spread:a,indices:i(a+1)};let o=n.indexOf(r);if(o>=0)return{tier:2,spread:o,indices:i(o)};let s=[],c=0;for(let e of r){let t=n.indexOf(e,c);if(t<0)return;s.push(t),c=t+1}let l=s[0]??0;return{tier:3,spread:(s.at(-1)??0)-l-r.length+1,indices:s}}function Et(e,t,n,r){return e.map(e=>({entry:e,match:Tt(t(e),n)})).filter(e=>e.match!==void 0).sort((e,n)=>e.match.tier-n.match.tier||e.match.spread-n.match.spread||r(e.entry)-r(n.entry)||t(e.entry).localeCompare(t(n.entry))).map(({entry:e,match:t})=>({entry:e,indices:t.indices}))}var Dt=[`help`,`login`,`model`];function Ot(e,t,n={}){if(!t.startsWith(`/`)||t.includes(`
|
|
2
|
+
`))return{kind:`none`};let r=t.search(/\s/u);if(r<0){let r=t.slice(1);return{kind:`commands`,query:r,items:Et(e.filter(e=>e.availability.status===`available`&&(r.length===0?e.category===(n.idleCategory??`Conversation`)||Dt.includes(e.alias):e.category!==`Advanced`||e.alias.toLocaleLowerCase().startsWith(r.toLocaleLowerCase()))),e=>e.alias,r,e=>{let t=Dt.indexOf(e.alias);return r.length===0&&t>=0?t-Dt.length:e.order}).map(({entry:e,indices:t})=>({command:e,label:`/${e.alias}`,matches:t.map(e=>e+1),insert:e.grammar===void 0?`/${e.alias}`:`/${e.alias} `}))}}let i=t.slice(1,r),a=e.find(e=>e.alias===i);if(a?.grammar===void 0||a.availability.status!==`available`)return{kind:`none`};let o=t.slice(r).trimStart(),s=(o.includes(` `)?[]:a.grammar.words??[]).filter(e=>e.word.toLocaleLowerCase().startsWith(o.toLocaleLowerCase())).map(e=>({word:e,label:e.word,matches:Array.from({length:o.length},(e,t)=>t),insert:`/${i} ${e.word}`}));return{kind:`arguments`,command:a,query:o,hint:`/${i} ${a.grammar.hint}`,items:s}}function kt(e,t){return e.animate(t.reduced?[{opacity:1},{opacity:0}]:[{opacity:1,transform:`none`},{opacity:0,transform:`translateY(-120%)`}],{duration:t.reduced?t.fast:t.normal,easing:m(t,t.easeExit),fill:`backwards`})}function At(e,t){let n=-12*Math.min(1.5,t.bounce/.3);return e.animate(t.reduced?[{opacity:0},{opacity:1}]:[{opacity:0,transform:`translateY(70%)`},{opacity:1,transform:`translateY(${String(n)}%)`,offset:.6},{opacity:1,transform:`none`}],{duration:t.reduced?t.fast:t.springDuration,easing:m(t,t.ease),fill:`backwards`})}function jt(e,t,n){return e.animate([{opacity:1-n},{opacity:n}],{duration:t.reduced?t.fast:t.normal,delay:n===1&&!t.reduced?t.fast/2:0,easing:m(t,t.ease),fill:`backwards`})}function Mt(e,t){let n=1+.05*Math.min(1.5,.4+t.bounce/.3);return e.animate([{transform:`scale(1)`},{transform:`scale(${String(n)})`,offset:.4},{transform:`scale(1)`}],{duration:t.springDuration,easing:m(t,`ease-out`)})}var Nt=(0,Z.forwardRef)(function({state:e,onStop:t,stopLabel:n=`Stop`,iconSize:r=20,onClick:i,disabled:a,className:o,tone:s=`primary`,"aria-label":c,...l},u){let d=(0,Z.useRef)(null);(0,Z.useImperativeHandle)(u,()=>d.current);let f=(0,Z.useRef)(e);(0,Z.useLayoutEffect)(()=>{let t=d.current,n=f.current;if(f.current=e,!t||n===e||!ee(t))return;let r=t.querySelector(`[data-glyph="arrow"]`),i=t.querySelector(`[data-glyph="busy"]`);if(!r||!i)return;let a=te(t),o=[];return e===`busy`?o.push(kt(r,a),jt(i,a,1)):n===`busy`&&o.push(jt(i,a,0),At(r,a)),n===`empty`&&e===`ready`&&!a.reduced&&o.push(Mt(t,a)),()=>{for(let e of o)e.cancel()}},[e]);let p=e===`busy`,m=p&&t!==void 0;return(0,Q.jsx)(le,{...l,ref:d,className:_(`caps-send-action`,o),tone:s,"aria-busy":p?!0:void 0,"aria-label":m?n:c,"data-send-state":e,disabled:a===!0||e===`empty`||p&&!m,onClick:m?t:i,label:null,icon:(0,Q.jsxs)(`span`,{className:`caps-send-glyph`,"data-state":e,children:[(0,Q.jsx)(`span`,{"data-glyph":`arrow`,children:(0,Q.jsx)(de,{"aria-hidden":`true`,size:r})}),(0,Q.jsx)(`span`,{"data-glyph":`busy`,children:t===void 0?(0,Q.jsx)(ne,{decorative:!0,size:`sm`}):(0,Q.jsx)(he,{"aria-hidden":`true`,fill:`currentColor`,size:Math.round(r*.7)})})]})})}),Pt=new Intl.NumberFormat(`en-US`,{style:`currency`,currency:`USD`,minimumFractionDigits:2,maximumFractionDigits:2}),Ft=new Intl.NumberFormat(`en-US`,{style:`currency`,currency:`USD`,minimumFractionDigits:2,maximumFractionDigits:5});function It(e,t){if(!Number.isFinite(e))throw RangeError(`Money amount must be finite`);let n=e!==0&&Math.abs(e)<.01;return n&&(t?.precision!==`exact`||Math.abs(e)<1e-5)?e<0?`>-$0.01`:`<$0.01`:n?Ft.format(e):Pt.format(e)}function Lt(e,t){return`${e}-${String(t)}`}function Rt(e){switch(e.key){case`ArrowDown`:return`next`;case`ArrowUp`:return`previous`;case`Enter`:return e.shiftKey?null:`accept`;case`Tab`:return`accept`;case`Escape`:return`dismiss`;default:return null}}function zt(e){return{role:`combobox`,"aria-autocomplete":`list`,"aria-expanded":e.open,"aria-controls":e.open?e.listId:void 0,"aria-activedescendant":e.open?Lt(e.listId,e.selected):void 0}}function Bt({open:e,rows:t,selected:n,listId:r,label:i,kind:a,hint:o,empty:s,onHighlight:c,onChoose:l}){return(0,Q.jsx)(oe,{open:e,side:`top`,"data-parakeet-slash":``,children:(0,Q.jsxs)(`div`,{className:`parakeet-slash-menu`,"data-kind":a,children:[o===void 0?null:(0,Q.jsx)(`p`,{className:`parakeet-slash-hint`,children:o}),t.length===0?s===void 0?null:(0,Q.jsx)(`p`,{className:`parakeet-slash-hint`,children:s}):(0,Q.jsx)(`div`,{id:r,role:`listbox`,"aria-label":i,children:t.map((e,t)=>(0,Q.jsxs)(M,{id:Lt(r,t),active:t===n,"aria-disabled":e.disabled===!0||void 0,"data-disabled":e.disabled===!0,onMouseEnter:()=>{c(t)},onClick:()=>{l(t)},children:[e.media===void 0?null:(0,Q.jsx)(`span`,{"aria-hidden":`true`,className:`parakeet-slash-media`,children:e.media}),(0,Q.jsx)(`span`,{className:`parakeet-slash-label`,children:e.label}),(0,Q.jsx)(`span`,{className:`parakeet-slash-detail`,children:e.detail}),e.keys===void 0||e.keys.length===0?null:(0,Q.jsx)(`kbd`,{className:`parakeet-slash-keys`,children:e.keys})]},e.key))})]})})}var Vt=(0,Z.forwardRef)(function({className:e,density:t=`regular`,...n},r){return(0,Q.jsx)(`ul`,{...n,className:_(`list`,t===`compact`&&`list-sm`,e),ref:r})}),Ht=(0,Z.forwardRef)(function({className:e,...t},n){return(0,Q.jsx)(`li`,{...t,className:_(`list-row`,e),ref:n})});(0,Z.forwardRef)(function({className:e,icon:t,label:n,children:r,...i},a){return(0,Q.jsxs)(`li`,{...i,className:_(`list-row caps-fact`,e),ref:a,children:[(0,Q.jsxs)(`span`,{className:`caps-fact-label`,children:[t?(0,Q.jsx)(`span`,{className:`caps-fact-icon`,"aria-hidden":`true`,children:t}):null,n]}),(0,Q.jsx)(`span`,{className:`caps-fact-value`,children:r})]})});var Ut=(0,Z.forwardRef)(function({aside:e,children:t,className:n,level:r=2,...i},a){return(0,Q.jsxs)(r===3?`h3`:`h2`,{...i,className:_(`caps-data-list-heading`,n),ref:a,children:[(0,Q.jsx)(`span`,{children:t}),e===void 0?null:(0,Q.jsx)(`span`,{className:`caps-data-list-heading-aside`,children:e})]})}),Wt=f(`card caps-card`,{variants:{variant:{surface:`caps-card-surface`,outline:`caps-card-outline`,interactive:`caps-card-interactive`,game:`caps-card-game caps-card-interactive`,fit:`caps-card-fit`},density:{regular:``,compact:`caps-card-compact`}},defaultVariants:{variant:`surface`,density:`regular`}}),Gt=(0,Z.forwardRef)(function({className:e,density:t,featured:n=!1,state:r,variant:i,...a},o){return(0,Q.jsx)(`div`,{...a,className:_(Wt({density:t,variant:i}),n&&`caps-card-featured`,e),"data-state":r,ref:o})});(0,Z.forwardRef)(function({className:e,density:t,variant:n,width:r=`default`,...i},a){return(0,Q.jsx)(`main`,{className:`caps-centered-card-stage`,children:(0,Q.jsx)(Gt,{...i,className:_(`caps-centered-card`,r===`wide`&&`caps-centered-card-wide`,e),ref:a,variant:n??`surface`,...t?{density:t}:{}})})}),(0,Z.forwardRef)(function({alignment:e=`start`,className:t,...n},r){return(0,Q.jsx)(`div`,{...n,className:_(`caps-card-header`,e===`center`&&`caps-card-header-centered`,t),ref:r})}),(0,Z.forwardRef)(function({className:e,level:t=3,...n},r){return(0,Q.jsx)(t===2?`h2`:`h3`,{...n,className:_(`caps-card-title`,e),ref:r})}),(0,Z.forwardRef)(function({className:e,...t},n){return(0,Q.jsx)(`p`,{...t,className:_(`caps-card-description`,e),ref:n})}),(0,Z.forwardRef)(function({className:e,...t},n){return(0,Q.jsx)(`div`,{...t,className:_(`caps-card-content`,e),ref:n})}),(0,Z.forwardRef)(function({className:e,...t},n){return(0,Q.jsx)(`div`,{...t,className:_(`caps-card-footer`,e),ref:n})});var Kt=(0,Z.forwardRef)(function({action:e,attachments:t,className:n,input:r,toolbar:i,...a},o){return(0,Q.jsxs)(`div`,{...a,ref:o,className:_(`caps-composer`,n),children:[t===void 0?null:(0,Q.jsx)(`div`,{className:`caps-composer-attachments`,children:t}),(0,Q.jsx)(`div`,{className:`caps-composer-input`,children:r}),i===void 0&&e===void 0?null:(0,Q.jsxs)(`div`,{className:`caps-composer-bar`,children:[(0,Q.jsx)(`div`,{className:`caps-composer-toolbar`,children:i}),e]})]})});function qt({draft:e,hasAttachments:t=!1,busy:n,queueWhileBusy:r=!1,blocked:i=!1}){let a=!i&&(e.trim().length>0||t);return n&&(!r||!a)?`busy`:a?`ready`:`empty`}function Jt({attachments:e,action:t,children:n,className:r,input:i,menu:a,row:o,...s}){return(0,Q.jsxs)(se,{className:`parakeet-composer-anchor`,children:[a,(0,Q.jsxs)(Gt,{...s,className:_(`parakeet-composer-shell`,r),children:[(0,Q.jsx)(Kt,{action:t,attachments:e,input:i,toolbar:o===void 0?void 0:(0,Q.jsx)(ae,{className:`parakeet-composer-row`,align:`start`,items:o.items,openId:o.openId,onOpenChange:o.onOpenChange,renderTrigger:({children:e,...t})=>(0,Q.jsx)(le,{...t,label:e,expanded:t[`aria-expanded`]===!0}),leading:o.controls,trailing:(0,Q.jsxs)(`span`,{className:`parakeet-composer-trailing`,children:[o.status,o.readout==null?null:(0,Q.jsx)(`span`,{className:`parakeet-composer-readout`,children:o.readout}),(0,Q.jsx)(`span`,{className:`parakeet-composer-action`,children:o.action})]})})}),n]})]})}var Yt=1e5;function Xt(e){return!Number.isFinite(e)||e<=0?null:It(e/Yt)}var Zt=`prints-prompt-counter`;function Qt({busy:e,disabled:t,disabledReason:n,draft:r,label:i,onGenerate:a,promptOver:o}){return(0,Q.jsx)(Nt,{"aria-describedby":o?Zt:void 0,"aria-label":i,className:`prints-generate`,"data-generation-submit":!0,disabled:t||o,onClick:a,state:qt({draft:r,busy:e}),title:(t||o)&&n?n:i})}function $({addedLength:e,length:t,maxLength:n}){return`${String(t)} / ${String(n)} characters. This model accepts up to ${String(n)}; shorten the prompt${e>0?` or its style and characters`:``} by ${String(t-n)} or pick another model.`}var $t=.8;function en(e){let t=window.getComputedStyle(e),n=Number.parseFloat(t.lineHeight);return(Number.isFinite(n)?n:26)+Number.parseFloat(t.paddingTop)+Number.parseFloat(t.paddingBottom)}function tn({caretRequest:e,layout:t,onOverflow:n,onOver:r,disabled:i,maxLength:a,addedLength:o=0,menu:s,mentionCount:c,onCaret:l,onChange:u,onMentionDismiss:d,onMentionMove:f,onMentionPick:p,onSend:m,onSlashMove:h,onSlashPick:ee,placeholder:te,slashCount:ne,value:g}){let _=(0,Z.useRef)(null),v=(0,Z.useRef)(g),[y,re]=(0,Z.useState)([]),[b,x]=(0,Z.useState)(-1),[S,C]=(0,Z.useState)(!1),w=(0,Z.useRef)(!1),T=(0,Z.useRef)(!1);v.current=g,(0,Z.useLayoutEffect)(()=>{if(S||i||!T.current)return;T.current=!1;let e=_.current;e&&e.ownerDocument.activeElement===e.ownerDocument.body&&e.focus({preventScroll:!0})},[i,S]),(0,Z.useLayoutEffect)(()=>{let t=_.current;!t||e?.value!==g||(t.setSelectionRange(e.caret,e.caret),t.focus({preventScroll:!0}))},[e,g]);let{cap:E,collapsed:D,fullscreen:O}=t;(0,Z.useLayoutEffect)(()=>{let e=_.current;if(!e)return;if(O){e.style.height=``,n(!1);return}e.style.height=`auto`;let t=e.scrollHeight;e.style.height=`${String(D?en(e):Math.min(t,E))}px`,n(!D&&t>E+1),D&&(e.scrollTop=0),D&&t>e.clientHeight+1?e.setAttribute(`data-clipped`,``):e.removeAttribute(`data-clipped`)},[g,E,D,O,n]),(0,Z.useLayoutEffect)(()=>{let e=_.current;!e||!O||(e.setSelectionRange(e.value.length,e.value.length),e.scrollTop=e.scrollHeight)},[O]);let k=(0,Z.useCallback)(async()=>{let e=v.current.trim();if(!(!e||i||w.current)){if(a!==void 0&&e.length+o>a){r($({addedLength:o,length:e.length+o,maxLength:a}));return}T.current=_.current===_.current?.ownerDocument.activeElement,w.current=!0,C(!0);try{if(!await m())return;re(t=>t.at(-1)===e?t:[...t,e].slice(-20)),x(-1)}finally{w.current=!1,C(!1)}}},[i,a,r,m,o]),A=g.trim().length,j=A>0?A+o:0,M=a!==void 0&&j>a,N=a!==void 0&&j>=Math.floor(a*$t);return(0,Q.jsxs)(`div`,{className:`relative min-w-0 flex-1`,children:[(0,Q.jsx)(ce,{"aria-invalid":M?!0:void 0,"aria-label":`Prompt`,className:`w-full`,"data-generation-prompt":!0,"data-counting":N?``:void 0,...zt(s),disabled:i===!0||S,onChange:e=>{u(e.currentTarget.value),l(e.currentTarget.selectionStart),x(-1)},onScroll:e=>{D&&(e.currentTarget.scrollTop=0)},onSelect:e=>{l(e.currentTarget.selectionStart)},onKeyDown:e=>{if(ie(e))return;let t=Rt(e);if(c>0&&t!==null){e.preventDefault(),t===`next`?f(1):t===`previous`?f(-1):t===`accept`?p():d();return}if(g.startsWith(`/`)&&t!==null&&(ne>0||t===`dismiss`||e.key===`Enter`)){if(e.preventDefault(),t===`dismiss`)u(g.slice(1));else if(ne)t===`next`?h(1):t===`previous`?h(-1):ee();else return;return}if(e.key===`Enter`&&!e.shiftKey){e.preventDefault(),k();return}if(e.key===`ArrowUp`&&_.current?.selectionStart===0&&y.length&&(b===-1||b>0)){e.preventDefault();let t=b===-1?y.length-1:b-1;x(t),u(y[t]);return}if(e.key===`ArrowDown`&&b!==-1){e.preventDefault();let t=b+1;t>=y.length?(x(-1),u(``)):(x(t),u(y[t]))}},placeholder:te,ref:_,style:{maxHeight:O?void 0:E},rows:1,value:g}),N?(0,Q.jsxs)(`p`,{className:`prints-prompt-counter ${M?`text-error`:`text-dim`}`,"data-prompt-counter":!0,id:Zt,role:`status`,title:M?$({addedLength:o,length:j,maxLength:a}):void 0,children:[`${String(j)} / ${String(a)}`,M?(0,Q.jsxs)(`span`,{className:`sr-only`,children:[` `,$({addedLength:o,length:j,maxLength:a})]}):null]}):null]})}function nn({index:e,listId:t,matches:n,onHighlight:r,onPick:i}){return(0,Q.jsx)(Bt,{open:!0,rows:n.map(e=>({key:e.id,label:`/${e.slash}`,detail:e.description??e.title})),selected:e,listId:t,label:`Commands`,kind:`commands`,empty:`No matching commands`,onHighlight:r,onChoose:i})}function rn(e,t){let[n,r]=(0,Z.useState)(0),i=t.startsWith(`/`),a=(0,Z.useMemo)(()=>{if(!i)return[];let n=Ot(e.map((e,t)=>({alias:e.slash,commandId:e.id,command:e.command,title:e.title,description:e.description,category:`Prompt`,order:t,keys:[],availability:{status:`available`}})),t,{idleCategory:`Prompt`});return n.kind===`commands`?n.items.flatMap(({command:t})=>e.find(e=>e.id===t.commandId)??[]):[]},[t,e,i]);return(0,Z.useEffect)(()=>{r(0)},[t]),{moveSlash:e=>{r(t=>a.length?(t+e+a.length)%a.length:0)},highlightSlash:r,resetSlash:()=>{r(0)},slashIndex:n,slashMatches:a,slashOpen:i}}function an({images:e,index:t,listId:n,matches:r,onHighlight:i,onPick:a}){return(0,Q.jsx)(Bt,{open:!0,rows:r.map(t=>{if(t.kind===`reference`)return{key:U(t.reference.number),label:`@${U(t.reference.number)}`,detail:t.reference.name,media:(0,Q.jsx)(`span`,{className:`prints-character-thumb mask mask-squircle`,children:t.reference.url?(0,Q.jsx)(`img`,{src:t.reference.url,alt:``}):null})};let{character:n}=t,r=n.references.at(0)?.path,i=e.find(e=>e.path===r);return{key:String(n.id),label:`@${n.name}`,detail:n.description||void 0,media:(0,Q.jsx)(`span`,{className:`prints-character-thumb mask mask-squircle`,children:i?(0,Q.jsx)(`img`,{src:i.url,alt:``}):null})}}),selected:t,listId:n,label:`References and characters`,kind:`characters`,onHighlight:i,onChoose:a})}var on=e=>e.kind===`reference`?U(e.reference.number):e.character.name;function sn(e,t,n,r){return it(e).flatMap(e=>{let i=/^image(\d+)$/i.exec(e);if(i!==null){let t=n.find(e=>e.number===Number(i.at(1)));return[{key:e.toLowerCase(),label:`@${e.toLowerCase()}`,url:t?.url,valid:t!==void 0}]}let a=t.find(t=>t.name.toLowerCase()===e.toLowerCase());if(a===void 0)return[];let o=a.references.at(0)?.path;return[{key:`character:${String(a.id)}`,label:`@${a.name}`,url:r.find(e=>e.path===o)?.url,valid:!0}]})}function cn({tokens:e}){return e.length===0?null:(0,Q.jsx)(`ul`,{className:`prints-mention-tokens`,"aria-label":`Mentioned in the prompt`,children:e.map(e=>(0,Q.jsxs)(`li`,{className:`prints-mention-token`,"data-mention-token":e.label,"data-invalid":e.valid?void 0:``,title:e.valid?void 0:`No longer attached`,children:[(0,Q.jsx)(`span`,{className:`prints-mention-thumb mask mask-squircle`,children:e.url?(0,Q.jsx)(`img`,{src:e.url,alt:``}):null}),(0,Q.jsx)(`span`,{children:e.label}),e.valid?null:(0,Q.jsx)(`span`,{children:` · not attached`})]},e.key))})}function ln(e,t,n){let[r,i]=(0,Z.useState)(0),[a,o]=(0,Z.useState)(0),[s,c]=(0,Z.useState)(null),[l,u]=(0,Z.useState)(null),d=s===n?null:ut(n,r),f=d?dt(e,t,d.query):[];return(0,Z.useEffect)(()=>{o(0)},[n]),{caretRequest:l,matches:f,index:a,setCaret:i,highlight:o,dismiss:()=>{c(n)},move:e=>{o(t=>f.length?(t+e+f.length)%f.length:0)},complete:e=>{let t=f.at(e);if(!d||!t)return null;let a=on(t),o=`${n.slice(0,d.start)}@${a} ${n.slice(r)}`,s=d.start+a.length+2;return u({value:o,caret:s}),i(s),o}}}function un(e,t,n){let[r,i]=(0,Z.useState)(G),a=e.map(e=>Ge(e,n)),o=Ke(r,a,t);return o!==r&&i(o),qe(o,a)}var dn=400;function fn(e){let{draft:t,model:n}=e;if(n===void 0||t.prompt.trim()===``)return null;let r=W(t.prompt).length>0,i=n.kind===`audio`?ct(t.prompt):lt({prompt:t.prompt,saved:e.characters,references:t.references,labels:e.labels,wording:e=>K(k(e,n,r),n),computerId:e.computerId,model:{label:n.label,maxReferences:n.input.maxReferences}});if(i.kind===`refused`)return null;let a=k(i.references,n,r),o={...t,prompt:B(n.kind===`audio`?void 0:e.styleText,i.prompt),references:a};return A(o,n)!==void 0||n.video!==null&&!n.video.formats.some(e=>e.width===o.width&&e.height===o.height)?null:E(o,n).settings}function pn(e,t){let n=e===null?null:JSON.stringify(e),r=(0,Z.useRef)(e);r.current=e;let[i,a]=(0,Z.useState)({key:n,settings:e});return(0,Z.useEffect)(()=>{let e=setTimeout(()=>{a({key:n,settings:r.current})},t);return()=>{clearTimeout(e)}},[n,t]),i}function mn(e,t){return S({queryKey:[`prints`,`quote`,e?.computerId??null,t.key],enabled:e!==void 0&&t.settings!==null,queryFn:()=>e===void 0||t.settings===null?null:e.quote(t.settings),staleTime:6e4,retry:!1})}function hn(e,t){let n=t===null?null:JSON.stringify(t),r=pn(t,dn),i=ue(mn(e,r));return t===null||e===void 0?{state:`idle`}:r.key!==n||i.isPending?{state:`loading`}:i.isError||i.data==null?{state:`unavailable`}:{state:`ready`,price:Xt(i.data.costMilliunits)}}function gn(e,t){let n=hn(e,t);return n.state===`ready`?n.price:null}export{_e as $,Y as A,Be as B,xt as C,at as D,bt as E,U as F,je as G,He as H,K as I,P as J,I as K,Ye as L,lt as M,ht as N,q as O,W as P,ye as Q,B as R,yt as S,St as T,R as U,ze as V,De as W,ge as X,xe as Y,ve as Z,Ut as _,tn as a,vt as b,nn as c,rn as d,he as et,ln as f,Vt as g,Jt as h,Qt as i,ue as it,ct as j,gt as k,sn as l,Xt as m,gn as n,pe as nt,an as o,un as p,F as q,hn as r,fe as rt,cn as s,fn as t,me as tt,$ as u,Ht as v,X as w,_t as x,wt as y,Ue as z};
|