@fungi.computer/prints 0.20.15 → 0.20.17

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 CHANGED
@@ -67,9 +67,9 @@ generated), not a live Oyster. To run Prints on a real Oyster, see
67
67
  Computer stays as it is.
68
68
  - **Share** a generated print from Image info, where the host offers it (the
69
69
  Fungi Hub does): a public, read-only page shows the picture or video, with its
70
- prompt only if you leave **On page** on. Prints are private until you turn
71
- sharing on, and turning it off stops the link at once. Changing **On page**
72
- while shared makes a new link.
70
+ prompt only if **Shared page: Show prompt** is on. Prints are private until
71
+ you turn sharing on, and turning it off stops the link at once. Changing that
72
+ switch while shared makes a new link.
73
73
  - Retry a failed attempt from its tile or from **Activity**, the key in the
74
74
  window's status bar. A retry resumes the same attempt instead of generating
75
75
  again, and **Resume** picks up an unfinished image after a reload.
@@ -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,Mt as u,N as d,O as f,Tt as p,Vn as ee,gn as m,k as te,ln as ne,lt as h,q as g,st as re,v as _,wn as ie,x as ae}from"./button-oE2Hrd5D.js";import{Mt as oe,Nt as se,Pt as v,a as y,bt as ce,i as b,jt as le,n as ue,o as x,ot as de,r as S,s as C,zt as w}from"./dist-DAokFn5x.js";import{l as fe,n as T,t as pe}from"./log-event-BfZxbz9a.js";import{c as me,d as he,f as ge,l as _e,o as ve,p as ye,s as be,u as xe}from"./query-CYqgVHJ7.js";var E=e(ee(),1);function Se(e,t,n){let r=ye(),i=ge(),a=le(n),o=a.defaultQueryOptions(e),s=a.getQueryCache().get(o.queryHash),c=e.subscribed!==!1;o._optimisticResults=r?`isRestoring`:c?`optimistic`:void 0,ve(o),_e(o,i,s),he(i);let[l]=E.useState(()=>new t(a,o)),u=l.getOptimisticResult(o),d=!r&&c;if(E.useSyncExternalStore(E.useCallback(e=>{let t=d?l.subscribe(de.batchCalls(e)):ce;return l.updateResult(),t},[l,d]),()=>l.getCurrentResult(),()=>l.getCurrentResult()),E.useEffect(()=>{l.setOptions(o)},[o,l]),me(o,u))throw be(o,l,i);if(xe({result:u,errorResetBoundary:i,throwOnError:o.throwOnError,query:s,suspense:o.suspense}))throw u.error;return o.notifyOnChangeProps?u:l.trackResult(u)}var Ce=`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(`.`),we=`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 D(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 Te(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=[D(Ce)];for(let e=1;e<t;e++)r.push(D(we));return r.join(n)}C(`app.backend`,1,m(()=>b({request:y(S(a().transform(e=>w(e))))})));var Ee=C(`app.methods`,1,m(()=>b({call:y(S(a().transform(e=>w(e))))})));C(`app.region`,1,m(()=>b({connect:y(b({messages:y(ne(ReadableStream).transform(e=>e.pipeThrough(new TransformStream({transform(e,t){t.enqueue(ie().parse(e))}})))),send:x,close:x}))})));var De=72e4,Oe=ae(`Clock`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`polyline`,{points:`12 6 12 12 16 14`,key:`68esgv`}]]),ke=De+18e4,Ae=`4 generations are running. Wait for one to finish.`,je=c({error:f(`generation_limit`),limit:r,message:s}),O=class extends oe{constructor(e){super(e,{code:`CONFLICT`,retryable:!0})}};function Me(e,t){return e.computerId===void 0||e.computerId===t}var k=`@cf/black-forest-labs/flux-2-klein-4b`,Ne=`Image creation is unavailable for this Computer right now.`,Pe=`Didn’t finish`,A={landscape:{height:768,width:1024},portrait:{height:1024,width:768},square:{height:1024,width:1024}},j=[`landscape`,`portrait`,`square`];function M(e){return e instanceof T&&e.stage===`provider`&&e.provider!==void 0&&`reason`in e.provider&&e.provider.reason===`credits_exhausted`}function N(e){return e.requestId===void 0?``:` Ref ${e.requestId.slice(-8)}.`}var Fe={invalid_request:`the media service rejected the request (invalid_request)`,unauthorized:`the media service refused Fungi’s credentials (unauthorized)`,unavailable:`the media service is unavailable (unavailable)`,rate_limited:`the media service is busy (rate_limited)`,too_large:`the request was too large for the media service (too_large)`,unreachable:`Fungi couldn’t reach the media service (unreachable)`,invalid_response:`the media service sent an answer Fungi couldn’t read (invalid_response)`};function Ie(e){if(e===void 0)return{cause:`the media service didn’t report why (internal error)`,next:`Retry, or pick another model.`,retryable:!1,unexplained:!0};if(e.category===`media_service`)return{cause:Fe[e.failure],next:e.failure===`rate_limited`?`Retry in a minute.`:`Retry, or pick another model.`,retryable:e.failure===`rate_limited`,unexplained:!0};if(e.category===`result_download`)return{cause:`the finished file couldn’t be downloaded (HTTP ${String(e.status)})`,next:`Retry, or pick another model.`,retryable:!1};switch(e.reason){case`content_refused`:return{title:`Generation refused`,cause:`the provider refused the prompt (content policy)`,next:`Reword the prompt, then retry.`,retryable:!1};case`invalid_input`:return{cause:e.detail===void 0?`the provider rejected the input`:`the provider rejected the input (${e.detail})`,next:`Check the prompt and the reference image’s size and format.`,retryable:!1};case`rate_limited`:return{cause:`the provider is overloaded`,next:`Retry in a minute.`,retryable:!0};case`provider_unavailable`:return{cause:`the provider is down right now`,next:`Retry in a minute.`,retryable:!0};case`timeout`:return{title:`Still waiting`,cause:`the provider timed out`,next:`Retry to ask again.`,retryable:!0};case`spending_limit`:return{cause:`the provider’s daily allowance is used up`,next:`Try another model, or retry tomorrow.`,retryable:!1};case`credits_exhausted`:return{cause:`Cloudflare AI Gateway credits are used up`,next:`Choose a Workers AI model such as Flux.`,retryable:!1};case void 0:}return e.detail===void 0?e.category===`TimeoutError`||e.category===`AbortError`?{title:`Still waiting`,cause:`the provider timed out`,next:`Retry to ask again.`,retryable:!0}:{cause:e.code===null?`the provider failed without a reason (${e.category})`:`the provider failed with error ${String(e.code)} and gave no reason`,next:`Retry, or pick another model.`,retryable:!1,unexplained:!0}:{cause:`the provider said “${e.detail}”`,next:`Retry, or pick another model.`,retryable:!1}}function Le(e){if(!(e instanceof T)||e.stage!==`provider`)return!1;if(e.code===`MEDIA_PROVIDER_FAILURE`||e.code===`MEDIA_PROVIDER_FAILURE_UNCHARGED`||e.code===`SAFETY_FILTER_REFUSED`)return!0;let t=e.provider;return t!==void 0&&(t.category===`result_download`||t.category===`media_service`||t.reason!==void 0||t.detail!==void 0)}function Re(e,t){let n=Ie(e.code===`SAFETY_FILTER_REFUSED`?{category:`Error`,code:null,reason:`content_refused`}:e.provider),r=e.code===`MEDIA_PROVIDER_FAILURE_UNCHARGED`?` You weren’t charged.`:``;return{title:n.title??`Generation failed`,message:`${t.model??`The model`} stopped: ${n.cause}.${r} ${n.next}${n.unexplained===!0?N(t):``}`,retryable:n.retryable}}var P=l(c({code:te(se)}));function F(e,t={}){if(e instanceof O)return{title:`Too many generations`,message:e.message,retryable:!0};if(M(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};if(Le(e))return Re(e,t);if(e instanceof T&&e.stage!==`provider`)return{...v(e),message:e.message};let n=t.model??`The model`,r=P(e);if(u(r))return{title:`Generation failed`,message:`${n} stopped: Prints hit an unexpected error (${e instanceof Error?e.name:`no error details`}). Retry, or pick another model.${N(t)}`,retryable:!0};let i=`${n} stopped: the cause wasn’t reported (internal error).`;return v(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:`${i} Retry, or pick another model.${N(t)}`},MEDIA_PROVIDER_FAILURE_UNCHARGED:{title:`Generation failed`,message:`${i} You weren’t charged. Retry, or pick another model.${N(t)}`},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:`Prints couldn’t reach the media service, and it didn’t say why. Try again.${N(t)}`}})}function ze(e,t={}){let n=P(e);return{reason:n._tag===`Some`?n.value.code:M(e)?`INSUFFICIENT_CREDIT`:`UNKNOWN`,message:F(e,t).message}}function Be(){return{destination:void 0,height:768,model:k,prompt:``,references:[],steps:void 0,width:1024}}function Ve(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 He(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 Ve(Te({count:4}),t,a)}function Ue(e){return e?.kind===`audio`?e.audio?.mode===`music`?`Generate music`:`Generate speech`:e?.kind===`video`?`Generate video`:`Generate image`}function We(e){return e.filter(e=>e.kind!==`audio`&&e.transform===null)}function Ge(e){return e.filter(e=>e.kind===`audio`)}function Ke(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 qe(e,t){return e?.kind===`audio`?fe:{width:t.width,height:t.height}}function Je(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 I=(e,t)=>t===0?e:I(t,e%t),L=(e,t,n)=>n===void 0?`${String(e)} × ${String(t)} · ${H(e,t)}`:`${String(e)} × ${String(t)} · ${String(n[0])}:${String(n[1])}`,R=[[1,1],[4,3],[3,4],[3,2],[2,3],[16,9],[9,16],[21,9]],z=16,Ye=256,Xe=4e6,B=1048576;function V(e,t,n,r){let i=Math.floor((e.input.maxDimension??4096)/z)*z,a=e=>Math.round(e/z)*z,o=e=>Math.min(i,Math.max(Ye,e)),s=I(t,n),c=t/s*z,l=n/s*z,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(B/(c*l))));d=c*e,f=l*e}else{let e=t/n;d=u?e>=1?i:a(i*e):a(Math.sqrt(B*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 Ze(e){if(e.kind!==`image`||e.input.dimensions!==`own`)return[];let t=new Set,n=new Set;for(let e of j){let{width:r,height:i}=A[e],a=I(r,i);n.add(`${String(r/a)}:${String(i/a)}`),t.add(`${String(r)}x${String(i)}`)}let r=[];for(let[i,a]of R){let o=n.has(`${String(i)}:${String(a)}`)?[]:[{size:V(e,i,a,!1),group:`Standard`}];e.input.maxDimensionDocumented&&o.push({size:V(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:L(e,n,[i,a]),width:e,height:n,group:s}))}}return r}function H(e,t){let n=e/t,r=R.find(([e,t])=>Math.abs(n/(e/t)-1)<=.02);if(r!==void 0)return`${String(r[0])}:${String(r[1])}`;let i=I(e,t),a=e/i,o=t/i;return a<=21&&o<=21?`${String(a)}:${String(o)}`:`${n.toFixed(2)}:1`}function Qe(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=R.find(([e,r])=>Math.abs(t/n/(e/r)-1)<=.02);return i===void 0?V(e,t,n,!1):V(e,i[0],i[1],!1)}function $e(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=I(t,n),a=t/i,o=n/i;return a<=21&&o<=21?`${String(a)}:${String(o)}`:`${String(t)} × ${String(n)}`}function et(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:L(n,r),width:n,height:r,group:n*r>=Xe?`Largest`:`Standard`}]}):[...j.map(e=>({value:e,label:L(A[e].width,A[e].height),...A[e],group:`Standard`})),...e===void 0?[]:Ze(e)]}function tt(e,t,n){return n?.kind===`video`&&t.kind===`video`||t.input.dimensions!==`none`&&i(g(G(()=>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 nt(e){return e.label.split(` — `)[0]??e.label}function rt(e,t){return e.find(e=>e.id===t)}function it(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 at={"first-frame":`First frame`,"last-frame":`Last frame`,reference:`Reference`};function ot(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 U(e){return e?.video?.referenceRoles??[]}function W(e,t,n=!1){let r=U(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 st(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 ct(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=W(e.references,t)),t.video?.supportsAudio===!0&&e.generateAudio!==void 0&&(r.generateAudio=e.generateAudio),{destination:{path:e.destination?.trim()??``},settings:r}}function G(e){return c({model:s,width:d,height:d,durationSeconds:h(t(d)),steps:h(t(d))}).check(re(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 lt(e,t){let n=e.trim().length;return n>t.maxPromptLength?{length:n,excess:n-t.maxPromptLength}:null}function ut(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=lt(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=g(G(()=>t))(e);if(o(r))return p()(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 st(W(e.references,t),t,n?.resolution)}}var K=n(),q=(0,E.forwardRef)(function({className:e,size:t=`md`,depth:n=`shallow`,placement:r=`standalone`,...i},a){return(0,K.jsx)(`div`,{...i,ref:a,"data-surface-size":t,"data-surface-depth":n,"data-surface-placement":r,className:_(`caps-surface`,e)})}),J=(0,E.forwardRef)(function({className:e,...t},n){return(0,K.jsx)(`div`,{...t,ref:n,className:_(`caps-screen`,e)})});(0,E.forwardRef)(function({children:e,className:t,depth:n=`deep`,fit:r=`content`,density:i=`normal`,...a},o){let s=r===`fill`;return(0,K.jsx)(q,{...a,className:_(t,s&&`flex min-h-0 flex-1`),depth:n,ref:o,children:(0,K.jsx)(`div`,{className:_(`caps-display-gasket`,s&&`flex min-h-0 min-w-0 flex-1`),"data-display-density":i,children:(0,K.jsx)(J,{className:_(s&&`flex min-h-0 min-w-0 flex-1 overflow-hidden`),children:e})})})}),(0,E.forwardRef)(function({className:e,icon:t,status:n,title:r,...i},a){return(0,K.jsxs)(`header`,{...i,className:_(`caps-screen-header`,e),ref:a,children:[t?(0,K.jsx)(`span`,{className:`caps-screen-header-icon`,"aria-hidden":`true`,children:t}):null,(0,K.jsx)(`span`,{className:`caps-screen-header-title`,children:r}),n?(0,K.jsx)(`span`,{className:`caps-screen-header-status`,children:n}):null]})}),(0,E.forwardRef)(function({appearance:e,className:t,...n},r){return(0,K.jsx)(`div`,{...n,className:_(`caps-screen-cells`,t),"data-appearance":e===`compact`?e:void 0,ref:r})}),(0,E.forwardRef)(function({children:e,className:t,legend:n,readout:r,icon:i,appearance:a,wide:o=!1,...s},c){return(0,K.jsxs)(`div`,{...s,className:_(`caps-screen-cell`,t),"data-wide":o||void 0,"data-appearance":a===`compact`?a:void 0,ref:c,children:[i?(0,K.jsx)(`span`,{className:`caps-screen-cell-icon`,children:i}):null,n?(0,K.jsx)(`span`,{className:`caps-screen-cell-legend`,children:n}):null,r?(0,K.jsx)(`span`,{className:`caps-screen-cell-readout`,children:r}):null,a===`compact`?(0,K.jsx)(`div`,{className:`caps-screen-cell-controls`,children:e}):e]})});function dt(e,t){ue.error(e,{id:t,toasterId:`prints-generation-notices`})}var Y=(0,E.createContext)(null),ft=(0,E.forwardRef)(function({children:e,defaultValue:t,onValueChange:n,value:r,...i},a){let[o,s]=(0,E.useState)(t),c=r??o,l=(0,E.useId)(),u=e=>{r===void 0&&s(e),n?.(e)},d=(e,t)=>`${l}-${e}-${encodeURIComponent(t)}`;return(0,K.jsx)(Y.Provider,{value:{onValueChange:u,panelId:e=>d(`panel`,e),selectedValue:c,tabId:e=>d(`tab`,e)},children:(0,K.jsx)(`div`,{...i,className:_(`w-full`,i.className),ref:a,children:e})})});function X(){let e=(0,E.useContext)(Y);if(!e)throw Error(`Tabs parts must be used inside <Tabs>`);return e}var pt=(0,E.forwardRef)(function({className:e,variant:t=`bordered`,...n},r){return(0,K.jsx)(`div`,{...n,"aria-orientation":n[`aria-orientation`]??`horizontal`,className:_(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`})}),mt=(0,E.forwardRef)(function({className:e,disabled:t,onClick:n,onKeyDown:r,value:i,...a},o){let s=X(),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,K.jsx)(`button`,{...a,"aria-controls":s.panelId(i),"aria-disabled":t?!0:void 0,"aria-selected":c,className:_(`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,E.forwardRef)(function({children:e,className:t,forceMount:n=!1,value:r,...i},a){let o=X(),s=o.selectedValue===r;return!s&&!n?null:(0,K.jsx)(`div`,{...i,"aria-labelledby":o.tabId(r),className:_(`mt-md focus-visible:outline-none`,t),hidden:!s,id:o.panelId(r),ref:a,role:`tabpanel`,tabIndex:0,children:e})});var ht=`modulepreload`,gt=function(e,t){return new URL(e,t).href},Z={},_t=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=gt(t,n),t=s(t),t in Z)return;Z[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`:ht,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 vt(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 yt(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 Q(e,t=64){let n=await new OfflineAudioContext(1,1,44100).decodeAudioData(e);return{peaks:yt(Array.from({length:n.numberOfChannels},(e,t)=>n.getChannelData(t)),t),durationSeconds:n.duration}}var $=new Map;async function bt(e,t){let n=await fetch(e);if(!n.ok)throw Error(`audio responded ${String(n.status)}`);return Q(await n.arrayBuffer(),t)}function xt(e,t){let n=`${String(t)}:${e}`,r=$.get(n);if(r!==void 0)return r;let i=bt(e,t).catch(e=>{throw $.delete(n),e});return $.set(n,i),i}function St(e,t=64){let[n,r]=(0,E.useState)({status:`loading`});return(0,E.useEffect)(()=>{if(e===``){r({status:`failed`});return}let n=!0;return r({status:`loading`}),xt(e,t).then(e=>{n&&r({status:`ready`,...e})},e=>{pe(`decode-audio-waveform`,e),n&&r({status:`failed`})}),()=>{n=!1}},[e,t]),n}export{ot as A,qe as B,ze as C,Qe as D,Me as E,$e as F,Oe as G,ke as H,et as I,Ee as K,tt as L,H as M,U as N,rt as O,W as P,L as R,He as S,Je as T,Ae as U,O as V,je as W,Be as _,pt as a,Ke as b,J as c,Pe as d,Ne as f,Ge as g,A as h,ft as i,We as j,nt as k,q as l,j as m,St as n,mt as o,at as p,Se as q,_t as r,dt as s,vt as t,k as u,F as v,ct as w,Ue as x,it as y,ut as z};
@@ -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-BfZxbz9a.js";import{g as H,h as te,i as ne,m as U,t as W}from"./query-CYqgVHJ7.js";import{G,K,a as re,c as q,i as ie,k as ae,l as oe,n as se,o as ce,q as le,t as ue}from"./audio-waveform-8Le2_ags.js";import{a as de,i as fe,n as pe,o as me,r as he,t as ge}from"./computer-BugY64UO.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-Bjq0vUfs.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 le(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(K).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)}),q=Te(()=>{let e=F.current;e&&G.current===null&&(G.current=e.style.scrollSnapType,e.style.scrollSnapType=`none`)}),ie=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,q()),(U.current===`vertical`?R.current:z.current)?.setPointerCapture(e.pointerId)}),ae=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)}),oe=Te(e=>{if(e.pointerId!==B.current)return;if(e.buttons%2==0){ae(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 se(e){C(e.pointerType===`touch`)}function ce(e){if(se(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:se,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:ie,handlePointerMove:oe,handlePointerUp:ae,handleScroll:re,disableViewportSnap:q,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}}),[ie,oe,ae,re,q,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`),q=ee-W-K,ie=B-G-re,ae=n?Math.min(n.offsetWidth-ne,q):q,oe=t?Math.min(t.offsetHeight-U,ie):ie,se=Math.max(16,ae*M),ce=Math.max(16,oe*N);if(m(e=>En(e,{width:se,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-se-W-K,t=Dn(i,bn,T===`rtl`?-w:w,P,_,se,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)(q,{}):(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)(oe,{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)(oe,{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)(ie,{className:`prints-audio-modes`,value:t,onValueChange:t=>{let r=e.find(e=>e===t);r!==void 0&&n(r)},children:(0,Q.jsx)(re,{"aria-label":`Audio type`,className:`prints-audio-modes-list`,variant:`segmented`,children:e.map(e=>(0,Q.jsx)(ce,{"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`:ae(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)(G,{}),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=se(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{A as e,En as t,F as n,I as r,J as i,K as a,M as o,N as s,O as c,Q as l,T as u,V as d,W as f,X as p,Y as m,at as h,et as g,gn as _,it as v,k as y,ln as b,lt as x,nt as S,tt as C,w}from"./button-oE2Hrd5D.js";import{It as T,Mt as E,a as D,i as O,l as k,o as A,r as j,s as M}from"./dist-DAokFn5x.js";function N(e,t){console.error(JSON.stringify({source:`agar`,operation:e,failureKind:t instanceof Error?`Error`:`NonErrorThrown`}),T(t))}var P=a(m(r({error:c(`too_large`)})));async function F(e,t){let n,r=()=>n??=e.close(),a=()=>{r().catch(e=>{N(`files.read.abort-close`,e)})};t.signal?.addEventListener(`abort`,a,{once:!0});try{t.signal?.throwIfAborted();let n=await e.response();try{let e=i(p(Response))(n);if(e.status===413){let t=P(await e.text());throw new E(`App file exceeds the read bound`,{code:t._tag===`Some`?`FILE_TOO_LARGE`:`PROTOCOL`,retryable:!1})}if(!e.ok)throw Error(`App file unavailable (${String(e.status)})`);let r=await e.blob();return t.signal?.throwIfAborted(),new File([r],t.name,{type:r.type,lastModified:0})}finally{k(n)}}finally{t.signal?.removeEventListener(`abort`,a);try{await r()}finally{e[Symbol.dispose]()}}}async function ee(e,t,n){let r,i=()=>r??=e.close(),a=()=>{i().catch(e=>{N(`files.write.abort-close`,e)})};n.signal?.addEventListener(`abort`,a,{once:!0});try{n.signal?.throwIfAborted(),await e.write(t.stream())}finally{n.signal?.removeEventListener(`abort`,a);try{await i()}catch(e){N(`files.write.remote-close`,e)}try{e[Symbol.dispose]()}catch(e){N(`files.write.local-dispose`,e)}}}var I=r({path:n,entries:w(r({name:n,type:y([`file`,`directory`,`symlink`]),size:s,modifiedAt:s})),nextOffset:o(s)}),L=M(`computer.list`,1,_(()=>O({list:D(j(t().transform(e=>i(I)(e))))}))),R=d([r({state:y([`running`,`sleeping`,`starting`])}),r({state:c(`start_failed`),reason:x(n.pipe(f(h(1)),f(v(1024))))}),r({state:c(`queued`),position:s.pipe(f(S()),f(g(0)))})]),z=r({enabled:u,effective:u,blockedBy:o(y([`team`,`global`]))}),B=r({computerId:e,name:e,runtime:R,backends:w(r({id:e,kind:y([`platform-container`,`on-box-vm`,`local`]),status:y([`ready`,`queued`,`online`,`offline`]),queuePosition:o(s.pipe(f(S()),f(g(0)))),hostId:o(n),hostLabel:o(n),folderLabel:o(n),detachable:u})),internet:z});M(`computer.instrument.read`,1,_(()=>O({read:D(j(t().transform(e=>i(B)(e))))}))),M(`computer.instrument.control`,1,_(()=>O({start:D(j(t().transform(e=>i(R)(e)))),setInternetAccess:D(j(t().transform(e=>i(z)(e)))),detachLocal:D(j(t().transform(e=>i(r({detached:u}))(e))))})));var V=r({ports:w(r({port:s.pipe(f(S()),f(l({minimum:1,maximum:65535}))),previewUrl:e,openMode:y([`inline`,`external-only`])})).pipe(f(v(64)))}),H=d([V,r({error:c(`port_previews_not_configured`)})]),U=r({port:s.annotate({message:`Use a port from 1 to 65535.`}).check(S({message:`Use a port from 1 to 65535.`}),l({minimum:1,maximum:65535},{message:`Use a port from 1 to 65535.`})),exposed:u}),W=r({port:s.pipe(f(S()),f(l({minimum:1,maximum:65535}))),removed:u});M(`computer.ports`,2,_(()=>O({list:D(j(t().transform(e=>i(H)(e)))),expose:D(j(t().transform(e=>i(U)(e)))),unexpose:D(j(t().transform(e=>i(W)(e))))})));var G=y([`synced`,`pending`,`unknown`]),K=r({port:o(U.fields.port),id:e,command:e,cwd:o(n),startedAt:s.pipe(f(S()),f(C(0))),state:y([`running`,`exited`,`uncertain`]),exitCode:o(s.pipe(f(S()))),sync:G,endedAt:o(s.pipe(f(S()),f(C(0)))),endedReason:o(c(`idle-sleep`))}),q=r({processes:w(K)}),J=r({process:K,signalled:u}),Y=r({process:K,lines:w(n.pipe(f(v(2e3)))).pipe(f(v(200))),truncated:u});r({requestId:e.pipe(f(v(256))),command:e.pipe(f(v(16384))),cwd:x(n),port:x(U.fields.port)}),M(`computer.processes`,1,_(()=>O({start:D(j(t().transform(e=>i(K)(e)))),list:D(j(t().transform(e=>i(q)(e)))),kill:D(j(t().transform(e=>i(J)(e)))),logs:D(j(t().transform(e=>i(Y)(e))))})));var X=M(`computer.readFile`,1,_(()=>O({open:D(O({response:D(b(Response)),close:A}))})));async function Z(e,t,n){return await F(await e.require(X).open(t),{...n,name:t.path.split(`/`).at(-1)??`file`})}async function Q(e,t){return i(I)(await e.require(L).list(t))}var $=M(`computer.writeFile`,3,_(()=>O({open:D(O({write:A,close:A})),mkdir:A,replace:D(j(t().transform(e=>i(te)(e))))}))),te=d([r({kind:c(`replaced`),path:e,bytes:s.pipe(f(S()),f(C(0)))}),r({kind:c(`conflict`)})]),ne=r({computerName:e.pipe(f(v(256))),teamName:e.pipe(f(v(256))),modelDoor:e.pipe(f(v(256))),uptimeSeconds:s.pipe(f(S()),f(C(0))),version:e.pipe(f(v(64)))});M(`computer.terminal`,2,_(()=>O({open:D(O({information:D(j(t().transform(e=>i(ne)(e)))),output:D(b(ReadableStream).transform(e=>e.pipeThrough(new TransformStream({transform(e,t){t.enqueue(b(Uint8Array).parse(e))}})))),input:D(b(WritableStream)),resize:A,close:A}))})));async function re(e,t,n){await ee(await e.require($).open({path:t.path}),t.content,n)}export{Z as a,Q as i,X as n,re as o,$ as r,N as s,L as t};
@@ -1 +1 @@
1
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{C as t,Vn as n,v as r,y as i}from"./button-oE2Hrd5D.js";import{l as a,u as o}from"./log-event-B3BGsDWO.js";import{$ as s,$t as c,A as l,At as u,B as d,Bt as f,C as p,Cn as m,Ct as h,D as g,Dt as _,E as v,En as y,F as b,Ft as x,G as ee,Gt as S,H as C,Ht as w,I as T,It as E,J as te,K as ne,Kt as D,L as O,Lt as re,M as ie,Mt as ae,Nt as oe,On as k,Ot as A,Pt as se,Q as j,Qt as M,R as N,Rt as P,S as F,Sn as I,St as L,T as R,Tn as z,Tt as B,U as V,Ut as H,V as ce,Vt as U,W,Y as le,Z as ue,_ as G,_n as de,_t as K,a as fe,an as pe,at as me,b as he,bt as q,c as J,cn as ge,ct as _e,dn as ve,dt as ye,en as be,et as xe,f as Se,fn as Ce,ft as we,g as Te,gn as Y,gt as Ee,h as De,hn as Oe,ht as ke,i as Ae,in as X,it as je,j as Me,jt as Ne,k as Pe,kn as Fe,kt as Ie,l as Le,ln as Re,lt as ze,m as Be,mn as Ve,n as Z,nn as He,nt as Ue,o as We,on as Ge,p as Ke,pn as qe,pt as Je,q as Ye,r as Xe,rn as Ze,rt as Qe,s as $e,sn as et,t as tt,tn as nt,tt as rt,un as it,ut as at,v as ot,vn as st,w as ct,wn as lt,wt as ut,x as dt,xn as ft,xt as pt,y as mt,yn as ht,z as gt,zt as _t}from"./useTriggerFocusGuards-Bddw7Qdn.js";function vt(e){return/\.mp4$/iu.test(e)}async function yt(e,t){if(vt(e.name)){let n=document.createElement(`video`);return n.preload=`metadata`,n.muted=!0,await new Promise((e,r)=>{n.addEventListener(`loadedmetadata`,()=>{e()},{once:!0}),n.addEventListener(`error`,()=>{r(Error(`MP4 metadata could not be read`))},{once:!0}),n.src=t}),{file:e,url:t,width:n.videoWidth,height:n.videoHeight}}if(o(e.name)){let n=new Audio;return n.preload=`metadata`,await new Promise((e,r)=>{n.addEventListener(`loadedmetadata`,()=>{e()},{once:!0}),n.addEventListener(`error`,()=>{r(Error(`MP3 metadata could not be read`))},{once:!0}),n.src=t}),{file:e,url:t,...a}}let n=new Image;return n.src=t,await n.decode(),{file:e,url:t,width:n.naturalWidth,height:n.naturalHeight}}var Q=e(n(),1),bt=ge&&et;function xt(e,t={}){let{enabled:n=!0,delay:r}=t,{events:i,dataRef:a}=e.context,o=Q.useRef(!1),s=Q.useRef(null),c=Q.useRef(!0),l=ft();Q.useEffect(()=>{let t=e.select(`domReferenceElement`);if(!n)return;let r=it(t);function i(){let t=e.select(`domReferenceElement`);!e.select(`open`)&&Ce(t)&&t===Ze(Ie(t))&&(o.current=!0,s.current=t)}function a(){c.current=!0}function l(){c.current=!1}return je(B(r,`blur`,i),bt&&B(r,`keydown`,a,!0),bt&&B(r,`pointerdown`,l,!0))},[e,n]),Q.useEffect(()=>{if(!n)return;function t(t){if(t.reason===`trigger-press`||t.reason===`escape-key`){let t=e.select(`domReferenceElement`);ve(t)&&(s.current=t,o.current=!0)}}return i.on(`openchange`,t),()=>{i.off(`openchange`,t)}},[i,n,e]);let u=Q.useMemo(()=>{function t(){o.current=!1,s.current=null}return{onMouseLeave(){t()},onFocus(n){let i=n.currentTarget;if(o.current){if(s.current===i)return;t()}let a=pe(n.nativeEvent);if(ve(a)){if(bt&&!n.relatedTarget){if(!c.current&&!w(a))return}else if(!H(a))return}let u=f(n.relatedTarget,e.context.triggerElements),{nativeEvent:d,currentTarget:p}=n;if(e.select(`open`)&&u||!r){e.setOpen(!0,q(K,d,p));return}l.start(r,()=>{o.current||e.setOpen(!0,q(K,d,p))})},onBlur(n){t();let r=n.relatedTarget,i=n.nativeEvent,o=ve(r)&&r.hasAttribute(xe(`focus-guard`))&&r.getAttribute(`data-type`)===`outside`;l.start(0,()=>{let t=e.select(`domReferenceElement`),n=Ze(Ie(t));!r&&n===t||X(a.current.floatingContext?.refs.floating.current,n)||X(t,n)||o||f(r??n,e.context.triggerElements)||e.setOpen(!1,q(K,i))})}}},[a,r,e,l]);return Q.useMemo(()=>n?{reference:u,trigger:u}:{},[n,u])}function St(e){return et&&e.movementX===0&&e.movementY===0}function Ct(e,t,n){switch(e){case`vertical`:return t;case`horizontal`:return n;default:return t||n}}function wt(e,t){return Ct(t,e===`ArrowUp`||e===`ArrowDown`,e===`ArrowLeft`||e===`ArrowRight`)}function Tt(e,t,n){return Ct(t,e===`ArrowDown`,n?e===`ArrowLeft`:e===`ArrowRight`)||e===`Enter`||e===` `||e===``}function Et(e,t,n){return Ct(t,n?e===be:e===nt,e===c)}function Dt(e,t,n,r){return t===`both`||t===`horizontal`&&r?e===`Escape`:Ct(t,n?e===nt:e===be,e===He)}function Ot(e,t){let{listRef:n,activeIndex:r,onNavigate:i=()=>{},enabled:a=!0,selectedIndex:o=null,allowEscape:c=!1,loopFocus:l=!1,nested:d=!1,rtl:f=!1,virtual:p=!1,focusItemOnOpen:m=`auto`,focusItemOnHover:h=!0,openOnArrowKeyDown:g=!0,disabledIndices:_=void 0,orientation:v=`vertical`,triggerOrientation:y=v,parentOrientation:b,id:x,resetOnPointerLeave:ee=!0,externalTree:S,nestedReturnFocusRef:C,grid:T}=t,te=T!=null,D=e.useState(`open`),O=e.useState(`floatingElement`),ie=e.useState(`domReferenceElement`),oe=e.context.dataRef,k=_t(O),j=U(ie),M=Qe(k),N=ne(),F=Ye(S),I=Q.useRef(m),L=Q.useRef(o??-1),R=Q.useRef(null),B=Q.useRef(!0),V=z(e=>{i(L.current===-1?null:L.current,e)}),H=Q.useRef(!!O),ce=Q.useRef(D),W=Q.useRef(!1),le=Q.useRef(!1),ue=Q.useRef(null),G=Qe(_),de=Qe(D),K=Qe(o),fe=Qe(ee),me=Ue(),he=Ue(),J=z(()=>{me.cancel();function e(e){p||(ue.current=s(e,{sync:W.current,preventScroll:!0}))}let t=n.current[L.current],r=le.current;t&&e(t),(W.current?e=>e():e=>me.request(e))(()=>{let i=n.current[L.current]||t;i&&(t||e(i),Se&&(r||!B.current)&&i.scrollIntoView?.({block:`nearest`,inline:`nearest`}))})});A(()=>{oe.current.orientation=v},[oe,v]),A(()=>{D||(R.current=null),(!D||m!==`auto`)&&(I.current=m)},[D,m]),A(()=>{a&&(D&&O?(L.current=o??-1,I.current&&o!=null&&(le.current=!0,V())):H.current&&(L.current=-1,V()))},[a,D,O,o,V]),A(()=>{if(a){if(!D){W.current=!1;return}if(O){if(r==null){if(W.current=!1,K.current!=null)return;if(H.current&&(L.current=-1,J()),(!ce.current||!H.current)&&I.current&&(R.current!=null||I.current===!0&&R.current==null)){let e=0,t=()=>{n.current[0]==null?(e<2&&(e?e=>he.request(e):queueMicrotask)(t),e+=1):(L.current=R.current==null||Tt(R.current,y,f)||d?Ne(n):u(n),R.current=null,V())};t()}}else se(n.current,r)||(L.current=r,J(),le.current=!1)}}},[a,D,O,r,K,d,n,y,f,V,J,he]),A(()=>{if(!a||O||!F||p||!H.current)return;let e=F.nodesRef.current,t=e.find(e=>e.id===N)?.context?.elements.floating,n=Ze(Ie(ie??t??null)),r=e.some(e=>e.context&&X(e.context.elements.floating,n));t&&!r&&B.current&&t.focus({preventScroll:!0})},[a,O,ie,F,N,p]),A(()=>{ce.current=D,H.current=!!O});let ge=r!=null,ve=z(e=>{if(!de.current)return;let t=n.current.indexOf(e.currentTarget);t!==-1&&(L.current!==t||r!==t)&&(L.current=t,V(e))}),ye=z(()=>b??F?.nodesRef.current.find(e=>e.id===N)?.context?.dataRef?.current.orientation),be=z(()=>Ne(n,G.current)),xe=z(t=>{if(B.current=!1,W.current=!0,t.which===229||!de.current&&t.currentTarget===M.current)return;if(d&&Dt(t.key,v,f,te)){wt(t.key,ye())||P(t),e.setOpen(!1,q(we,t.nativeEvent));let n=C?.current??ie;Ce(n)&&n.focus();return}r!=null&&r!==L.current&&!se(n.current,r)&&(L.current=r);let i=L.current,a=Ne(n,_),o=u(n,_);if(j||(t.key===`Home`&&(P(t),L.current=a,V(t)),t.key===`End`&&(P(t),L.current=o,V(t))),T!=null){let e=T(t,L.current,n,v,l,f,_,a,o);if(e!=null&&e!==L.current&&(L.current=e,V(t)),v===`both`)return}if(wt(t.key,v)){P(t);let e=Ze(t.currentTarget.ownerDocument);if(D&&!p&&X(t.currentTarget,e)&&!n.current.some(t=>t!=null&&X(t,e))){L.current=Tt(t.key,v,f)?a:o,V(t),r===L.current&&J();return}let{index:s,wrapped:u}=ae(n.current,i,{decrement:!Tt(t.key,v,f),loopFocus:l,allowEscape:c,disabledIndices:_,minIndex:a,maxIndex:o});u&&(W.current=!1),L.current=s,V(t)}}),Se=Q.useMemo(()=>({onFocus(e){W.current=!0,ve(e)},onClick({currentTarget:e}){p||e.focus({preventScroll:!0})},onMouseMove(e){St(e)||(W.current=!0,le.current=!1,h&&ve(e))},onPointerLeave(e){if(!de.current||!B.current||e.pointerType===`touch`)return;W.current=!0;let t=e.relatedTarget;if(!(!h||n.current.includes(t))&&fe.current&&(ue.current?.(),ue.current=null,L.current=-1,V(e),!p)){let e=M.current,t=Ze(Ie(e));e&&X(e,t)&&e.focus({preventScroll:!0})}}}),[ve,de,M,h,n,V,fe,p]),Te=Q.useMemo(()=>p&&D&&ge&&{"aria-activedescendant":`${x}-${r}`},[p,D,ge,x,r]),Y=Q.useMemo(()=>({...j?{}:Te,onKeyDown(t){if(t.key===`Tab`&&t.shiftKey&&D&&!p){let n=pe(t.nativeEvent);if(n&&!X(M.current,n))return;P(t);let r=q(_e,t.nativeEvent);e.setOpen(!1,r);let i=C?.current??ie;!r.isCanceled&&Ce(i)&&i.focus();return}xe(t)},onPointerMove(e){St(e)||(B.current=!0)}}),[Te,xe,M,j,e,D,p,ie,C]),Ee=Q.useMemo(()=>{function t(t){e.setOpen(!0,q(we,t.nativeEvent,t.currentTarget))}function n(e){m===`auto`&&E(e.nativeEvent)&&(I.current=!p)}function r(e){I.current=m,m===`auto`&&re(e.nativeEvent)&&(I.current=!0)}return{onKeyDown(n){let r=e.select(`open`);B.current=!1;let i=n.key.startsWith(`Arrow`),a=Et(n.key,ye(),f),o=wt(n.key,r?v:y),s=(d?a:o)||n.key===`Enter`||n.key.trim()===``;if(p&&r&&(!d||w(n.currentTarget)))return xe(n);if(!(!r&&!g&&i)){if(s){let e=wt(n.key,ye());R.current=d&&e?null:n.key}if(d){a&&(P(n),r?(L.current=be(),V(n),p&&M.current?.focus()):t(n));return}o&&(K.current!=null&&(L.current=K.current),P(n),!r&&g?t(n):xe(n),r&&V(n))}},onFocus(t){t.target===t.currentTarget&&e.select(`open`)&&!p&&(L.current=-1,V(t))},onPointerDown:r,onPointerEnter:r,onMouseDown:n,onClick:n}},[xe,m,be,d,V,e,g,v,y,ye,f,K,p,M]),De=Q.useMemo(()=>({...Te,...Ee}),[Te,Ee]);return Q.useMemo(()=>a?{reference:De,floating:Y,item:Se,trigger:Ee}:{},[a,De,Y,Ee,Se])}function kt(e,t){let{listRef:n,elementsRef:r,activeIndex:i,onMatch:a,disabledIndices:o,onTyping:s,enabled:c=!0,resetMs:l=750,selectedIndex:u=null}=t,d=z(s),f=e.useState(`open`),p=ft(),m=Q.useRef(``),h=Q.useRef(u??i??-1),g=Q.useRef(null),_=z(e=>{function t(e){return r?.current[e]}function s(e){let n=t(e);return n&&!oe(n)||n?.matches(`:disabled`)?!1:o==null||!x(I,e,o)}function c(e,t,n=0){if(e.length===0)return-1;let r=(n%e.length+e.length)%e.length,i=t.toLowerCase();for(let t=0;t<e.length;t+=1){let n=(r+t)%e.length;if(!(!e[n]?.toLowerCase().startsWith(i)||!s(n)))return n}return-1}let _=n.current;if(m.current.length>0&&e.key===` `&&(P(e),d?.(!0)),m.current.length>0&&m.current[0]!==` `&&c(_,m.current)===-1&&e.key!==` `&&d?.(!1),_==null||e.key.length!==1||e.ctrlKey||e.metaKey||e.altKey)return;f&&e.key!==` `&&(P(e),d?.(!0));let v=m.current===``;v&&(h.current=u??i??-1),_.every((e,t)=>e&&s(t)?e[0]?.toLowerCase()!==e[1]?.toLowerCase():!0)&&m.current===e.key&&(m.current=``,h.current=g.current),m.current+=e.key,p.start(l,()=>{m.current=``,h.current=g.current,d?.(!1)});let y=((v?u??i??-1:h.current)??0)+1,b=c(_,m.current,y);b===-1?e.key!==` `&&(m.current=``,d?.(!1)):(a?.(b,e),g.current=b)}),v=z(t=>{let n=t.relatedTarget,r=e.select(`domReferenceElement`),i=e.select(`floatingElement`);X(r,n)||X(i,n)||(p.clear(),m.current=``,h.current=g.current,d?.(!1))});A(()=>{!f&&u!==null||(p.clear(),g.current=null,m.current!==``&&(m.current=``,d?.(!1)))},[f,u,p,d]);let y=Q.useMemo(()=>({onKeyDown:_,onBlur:v}),[_,v]);return Q.useMemo(()=>c?{reference:y,floating:y}:{},[c,y])}function At({controlled:e,default:t,name:n,state:r=`value`}){let{current:i}=Q.useRef(e!==void 0),[a,o]=Q.useState(()=>t);return[i&&e!==void 0?e:a,Q.useCallback(e=>{i||o(e)},[])]}var $=t(),jt=Q.createContext(void 0);function Mt(e){let t=Q.useContext(jt);if(t===void 0&&!e)throw Error(ht(33));return t}var Nt=Q.createContext(void 0);function Pt(e){let t=Q.useContext(Nt);if(t===void 0&&!e)throw Error(ht(36));return t}var Ft=Q.createContext(void 0);function It(e=!0){let t=Q.useContext(Ft);if(t===void 0&&!e)throw Error(ht(25));return t}var Lt=Q.createContext(null);function Rt(e=`root`){let t=Q.useContext(Lt),n=Q.useContext(Nt);return t===null||n===void 0?null:(e===`submenu-trigger`?n.virtualFocus||n.parentVirtualFocus:n.virtualFocus)?t:null}var zt={visible:!0,ref:null};function Bt(){return zt}function Vt(e,t,n=`root`){let r=Rt(n),i=((n===`submenu-trigger`?r?.useSubmenuTrigger:r?.useItem)??Bt)({label:e.label,children:e.children,render:e.render}),a=st(t,i.ref);return{visible:i.visible,ref:a,props:i.props}}var Ht=Q.createContext(void 0);function Ut(){let e=Q.useContext(Ht);if(e===void 0)throw Error(ht(30));return e}function Wt(e){e.preventDefault()}function Gt(e){let{closeOnClick:t,highlighted:n,id:r,nodeId:i,store:a,typingRef:o,itemRef:s,itemMetadata:c}=e,l=Pt(),u=It(!0),d=c.type===`submenu-trigger`,f=d?l.parentVirtualFocus:l.virtualFocus,p=(d&&l.parent.type===`menu`?l.parent.store:l.store).useState(`webkitAriaSelected`,n),{events:m}=a.useState(`floatingTreeRoot`),g=a.useState(`open`),_=u!==void 0,v=!f&&g&&n?0:-1;return Q.useMemo(()=>({id:r,role:`menuitem`,tabIndex:v,"aria-selected":p,onMouseDown:f?Wt:void 0,onKeyDown(e){e.key===` `&&o?.current&&e.preventDefault()},onMouseMove(e){i&&m.emit(`itemhover`,{nodeId:i,target:e.currentTarget})},onClick(e){t&&m.emit(`close`,{domEvent:e.nativeEvent,reason:at})},onMouseUp(e){if(u){let t=u.initialCursorPointRef.current;if(u.initialCursorPointRef.current=null,_&&t&&Math.abs(e.clientX-t.x)<=1&&Math.abs(e.clientY-t.y)<=1||_&&!ge&&e.button===2)return}s.current&&a.context.allowMouseUpTriggerRef.current&&(!_||e.button===2)&&c.type===`regular-item`&&h(s.current,e,{detail:1,pointerType:`mouse`})}}),[t,v,r,m,i,a.context.allowMouseUpTriggerRef,o,s,u,_,c.type,p,f])}var Kt={type:`regular-item`};function qt(e){let{closeOnClick:t,disabled:n,highlighted:r,id:i,store:a,typingRef:o=a.context.typingRef,nativeButton:s,itemMetadata:c,nodeId:l}=e,u=Q.useRef(null),{getButtonProps:d,buttonRef:f}=L({disabled:n,focusableWhenDisabled:!0,native:s,composite:!0}),p=Gt({closeOnClick:t,highlighted:r,id:i,nodeId:l,store:a,typingRef:o,itemRef:u,itemMetadata:c}),m=Q.useCallback(e=>de(p,{onMouseEnter(e){c.type===`submenu-trigger`&&c.setActive(e.nativeEvent)}},e,d),[p,d,c]),h=st(u,f);return Q.useMemo(()=>({getItemProps:m,itemRef:h}),[m,h])}var Jt=Q.createContext({register:()=>{},unregister:()=>{},subscribeMapChange:()=>()=>{},nextIndexRef:{current:0}});function Yt(){return Q.useContext(Jt)}function Xt(e={}){let{guess:t,label:n,metadata:r,textRef:i,index:a}=e,{register:o,unregister:s,subscribeMapChange:c,nextIndexRef:l}=Yt(),u=Q.useRef(-1),[d,f]=Q.useState(a==null&&t?()=>{if(u.current===-1){let e=l.current;l.current+=1,u.current=e}return u.current}:-1),p=a??d,m=Q.useRef(null),h=Q.useCallback(e=>{let t=m.current;t&&s(t),m.current=e,e&&o(e,{metadata:r??null,index:a??null,label:n,textRef:i})},[a,o,s,r,n,i]);return A(()=>{if(a==null)return c(e=>{let t=m.current?e.get(m.current)?.index:null;t!=null&&f(t)})},[a,c]),{ref:h,index:p}}var Zt=`data-checked`,Qt=`data-unchecked`,$t={checked(e){return e?{[Zt]:``}:{[Qt]:``}},...M},en=Q.forwardRef(function(e,t){let{render:n,className:r,id:i,label:a,nativeButton:o=!1,disabled:s=!1,closeOnClick:c=!1,checked:l=!1,onCheckedChange:u,style:d,...f}=e,{store:p}=Pt(),m=Xt({guess:!0,label:a}),h=Ve(i),g=p.useState(`disabled`),_=p.useState(`isActive`,m.index),v=p.useState(`floatingNodeId`),y=p.useState(`itemProps`),b=s||g,{getItemProps:x,itemRef:ee}=qt({closeOnClick:c,disabled:b,highlighted:_,id:h,store:p,nativeButton:o,nodeId:v,itemMetadata:Kt}),S=Q.useMemo(()=>({disabled:b,highlighted:_,checked:l}),[b,_,l]);function C(e){let t=q(at,e.nativeEvent,void 0,{preventUnmountOnClose:lt});u?.(!l,t)}let w=Y(`div`,e,{state:S,stateAttributesMapping:$t,props:[y,{role:`menuitemcheckbox`,"aria-checked":l,onClick:C},f,x],ref:[ee,t,m.ref]});return(0,$.jsx)(Ht.Provider,{value:S,children:w})}),tn=Q.forwardRef(function(e,t){let{checked:n,defaultChecked:r,onCheckedChange:i,...a}=e,[o,s]=At({controlled:n,default:r??!1,name:`MenuCheckboxItem`,state:`checked`}),c=Vt(e,t);function l(e,t){i?.(e,t),t.isCanceled||s(e)}return c.visible?(0,$.jsx)(en,{...a,checked:o,onCheckedChange:l,ref:c.ref}):null}),nn=Q.forwardRef(function(e,t){let{render:n,className:r,style:i,keepMounted:a=!1,...o}=e,s=Ut(),c=Q.useRef(null),{transitionStatus:l,mounted:u,setMounted:d}=N(s.checked);T({batch:!0,enabled:!s.checked,open:s.checked,ref:c,onComplete(){s.checked||d(!1)}});let f={checked:s.checked,disabled:s.disabled,highlighted:s.highlighted,transitionStatus:l};return Y(`span`,e,{state:f,ref:[t,c],stateAttributesMapping:$t,props:{"aria-hidden":!0,...o},enabled:a||u})}),rn=Q.createContext(void 0);function an(){let e=Q.useContext(rn);if(e===void 0)throw Error(ht(31));return e}var on=Q.forwardRef(function(e,t){let{render:n,className:r,style:i,...a}=e,[o,s]=Q.useState(void 0),c=Y(`div`,e,{ref:t,props:{role:`group`,"aria-labelledby":o,...a}});return(0,$.jsx)(rn.Provider,{value:s,children:c})}),sn=Q.forwardRef(function(e,t){let n=Rt()?.Group??on;return(0,$.jsx)(n,{...e,ref:t})}),cn=Q.forwardRef(function(e,t){let{render:n,className:r,style:i,id:a,...o}=e,s=Ve(a),c=an();return A(()=>(c(s),()=>{c(e=>e===s?void 0:e)}),[c,s]),Y(`div`,e,{ref:t,props:{id:s,"aria-hidden":!0,...o}})}),ln=Q.forwardRef(function(e,t){let{render:n,className:r,id:i,label:a,nativeButton:o=!1,disabled:s=!1,closeOnClick:c=!0,style:l,...u}=e,{store:d}=Pt(),f=Xt({guess:!0,label:a}),p=Ve(i),m=d.useState(`disabled`),h=d.useState(`isActive`,f.index),g=d.useState(`floatingNodeId`),_=d.useState(`itemProps`),v=s||m,{getItemProps:y,itemRef:b}=qt({closeOnClick:c,disabled:v,highlighted:h,id:p,store:d,nativeButton:o,nodeId:g,itemMetadata:Kt});return Y(`div`,e,{state:{disabled:v,highlighted:h},props:[_,u,y],ref:[b,t,f.ref]})}),un=Q.forwardRef(function(e,t){let n=Vt(e,t);return n.visible?(0,$.jsx)(ln,{...e,ref:n.ref}):null}),dn=Q.createContext(void 0);function fn(){return Q.useContext(dn)}function pn(e,t){let n=Oe(e.render);if(Q.isValidElement(n)){let e=n.props;if(Object.hasOwn(e,`id`))return e.id??``}return e.id??t}function mn(e,t,n){let r=pn(e,t),i=r===t?void 0:r;return[r,Q.useCallback(e=>n?.(e?i:void 0),[i,n])]}function hn(e,t,n){let r=Oe(e.render),i=Q.isValidElement(r)?r.props:void 0,a=e[`aria-label`]??i?.[`aria-label`],o=e[`aria-labelledby`]??i?.[`aria-labelledby`];return o==null&&!a&&(o=t?t.id||void 0:n||void 0),o}var gn=Q.forwardRef(function(e,t){let{render:n,className:r,style:i,finalFocus:a,id:o,initialFocus:s,...c}=e,{store:l,defaultFloatingId:u,setRenderedFloatingId:d,virtualFocus:f,orientation:p}=Pt(),m=fn(),{side:h,align:g}=Mt(),_=$e(!0)!=null,v=l.useState(`open`),y=l.useState(`transitionStatus`),b=l.useState(`popupProps`),x=l.useState(`mounted`),ee=l.useState(`instantType`),w=l.useState(`activeTriggerElement`),E=l.useState(`parent`),te=l.useState(`lastOpenChangeReason`),ne=l.useState(`rootId`),D=l.useState(`floatingRootContext`),O=l.useState(`floatingTreeRoot`),re=l.useState(`closeDelay`),ie=l.useState(`hoverEnabled`),ae=l.useState(`disabled`),oe=l.useState(`openMethod`),k=l.useState(`activeTriggerId`),A=l.useState(`listElement`),[se,j]=mn(e,u,d),M=hn(e,w,k),N=E.type===`menu`?m:void 0,P=E.type===`context-menu`,F=s??E.type!==`menu`;s===void 0&&A&&E.type!==`menu`&&(F=()=>l.state.activeIndex===null&&A),T({open:v,ref:l.context.popupRef,onComplete(){v&&l.context.onOpenChangeComplete?.(!0)}}),Q.useEffect(()=>{function e(e){l.setOpen(!1,q(e.reason,e.domEvent))}return O.events.on(`close`,e),()=>{O.events.off(`close`,e)}},[O.events,l]),G(D,{enabled:ie&&!ae&&!P&&E.type!==`menubar`,closeDelay:re});let I=l.useStateSetter(`popupElement`),{parentVirtualFocusRef:L,handleFocus:R}=(Q.useContext(Lt)?.useParentHandoff??vn)(l,E,v,f),z={transitionStatus:y,side:h,align:g,open:v,nested:E.type===`menu`,instant:ee},B=Y(`div`,e,{state:z,ref:[t,l.context.popupRef,I,j],stateAttributesMapping:S,props:[b,{id:se,...A?{role:`presentation`}:{role:`menu`,"aria-orientation":p===`horizontal`?`horizontal`:void 0,"aria-labelledby":M},onKeyDown(e){N?.onPopupKeyDown?.(e),_&&Be.has(e.key)&&e.stopPropagation()},onFocus:R},We(y),c,{"data-rootownerid":ne}]}),V=E.type===void 0||P;(w||E.type===`menubar`&&te!==`outside-press`)&&(V=!0);let H=N?.getReturnElement??L;return(0,$.jsx)(C,{context:D,openInteractionType:oe,modal:P,disabled:!x,returnFocus:a??H??V,explicitReturnFocus:a===void 0&&H?!1:void 0,initialFocus:F,restoreFocus:!0,getInsideElements:E.type===void 0?()=>[l.context.beforeTriggerFocusGuardRef.current]:void 0,externalTree:E.type===`menubar`?void 0:O,previousFocusableElement:w,nextFocusableElement:E.type===void 0?l.context.triggerFocusTargetRef:void 0,beforeContentFocusGuardRef:l.context.beforeContentFocusGuardRef,children:B})}),_n={parentVirtualFocusRef:void 0,handleFocus:void 0};function vn(){return _n}var yn=Q.forwardRef(function(e,t){let n=Rt()?.Popup??gn;return(0,$.jsx)(n,{...e,ref:t})}),bn=Q.createContext(void 0);function xn(){let e=Q.useContext(bn);if(e===void 0)throw Error(ht(32));return e}var Sn=Q.forwardRef(function(e,t){let{keepMounted:n=!1,...r}=e,{store:i,parent:a}=Pt();if(!(i.useState(`mounted`)||n))return null;let o=a.type===`menu`||a.type===`menubar`?`group`:void 0;return(0,$.jsx)(bn.Provider,{value:n,children:(0,$.jsx)(le,{ref:t,...r,portalOwnerRole:o})})});function Cn(e){let{children:t,elementsRef:n,labelsRef:r,onMapChange:i}=e,a=z(i),[,o]=Q.useState(0),s=y(Tn).current,c=y(wn).current,l=Q.useRef(0),u=Q.useRef(!0),d=Q.useRef(null),f=Q.useRef(null),p=z(()=>{u.current||(u.current=!0,o(e=>e+1))}),m=z((e,t)=>{c.set(e,t),p()}),h=z(e=>{c.delete(e),p()}),g=z(e=>{let t=new Map;return n.current.length=0,r&&(r.current.length=0),e.forEach(e=>{t.set(e.element,{...e.registration.metadata??{},index:e.index}),n.current[e.index]=e.element,r&&(r.current[e.index]=e.registration.label===void 0?e.registration.textRef?.current?.textContent??e.element.textContent:e.registration.label)}),l.current=n.current.length,t});function _(e){if(f.current?.disconnect(),f.current=null,typeof MutationObserver!=`function`||e.length<2)return;let t=new MutationObserver(n=>{if(!On(n))return;let r=null;for(let n of e)if(n.isConnected){if(r&&kn(r,n)>0){t.disconnect(),p();return}r=n}});f.current=t;let n=new Set;for(let t=1;t<e.length;t+=1){let r=Dn(e[t-1],e[t]);r&&n.add(r)}n.forEach(e=>t.observe(e,{childList:!0}))}let v=z(()=>{let[e,t]=En(c),n=g(e),r=d.current,i=!r||r.length!==e.length||e.some((e,t)=>{let n=r[t];return e.index!==n.index||e.element!==n.element||e.registration.index!==n.registration.index||e.registration.metadata!==n.registration.metadata});_(t),d.current=e,u.current=!1,i&&(s.forEach(e=>e(n)),a(n))});A(()=>(!u.current&&d.current&&g(d.current),()=>{n.current=[],r&&(r.current=[])}),[n,r,g]),A(()=>{u.current&&v()}),A(()=>()=>{f.current?.disconnect(),u.current=!0},[]);let b=z(e=>(s.add(e),()=>{s.delete(e)})),x=Q.useMemo(()=>({register:m,unregister:h,subscribeMapChange:b,nextIndexRef:l}),[m,h,b,l]);return(0,$.jsx)(Jt.Provider,{value:x,children:t})}function wn(){return new Map}function Tn(){return new Set}function En(e){let t=new Set,n=[],r=[];e.forEach((e,i)=>{if(!i.isConnected)return;let a=e.index,o={index:a??-1,element:i,registration:e};a===null?r.push(o):a>=0&&(t.add(a),n.push(o))});let i=0;return r.sort((e,t)=>kn(e.element,t.element)),r.forEach(e=>{for(;t.has(i);)i+=1;e.index=i,n.push(e),i+=1}),t.size>0&&n.sort((e,t)=>e.index-t.index),[n,r.map(e=>e.element)]}function Dn(e,t){let n=e.parentElement;for(;n&&!n.contains(t);)n=n.parentElement;return n}function On(e){for(let t of e)for(let e=0;e<t.removedNodes.length;e+=1)if(t.removedNodes[e].isConnected)return!0;return!1}function kn(e,t){return e.nextElementSibling===t?-1:t.nextElementSibling===e?1:e.compareDocumentPosition(t)&Node.DOCUMENT_POSITION_FOLLOWING?-1:1}var An=Q.forwardRef(function(e,t){let{anchor:n,positionMethod:r=`absolute`,className:i,render:a,side:o,align:s,sideOffset:c=0,alignOffset:l=0,collisionBoundary:u=`clipping-ancestors`,collisionPadding:d=5,arrowPadding:f=5,sticky:p=!1,disableAnchorTracking:m=!1,collisionAvoidance:h=ue,style:g,..._}=e,{store:v,virtualFocus:y,syncHighlightedItem:b}=Pt(),x=xn(),ee=It(!0),S=v.useState(`parent`),C=v.useState(`floatingRootContext`),w=v.useState(`floatingTreeRoot`),T=v.useState(`mounted`),E=v.useState(`open`),te=v.useState(`modal`),ne=v.useState(`openMethod`),D=v.useState(`activeTriggerElement`),O=v.useState(`transitionStatus`),re=v.useState(`positionerElement`),ie=v.useState(`instantType`),ae=v.useState(`adaptiveOrigin`),oe=v.useState(`lastOpenChangeReason`),k=v.useState(`floatingNodeId`),A=v.useState(`floatingParentNodeId`),se=C.useState(`domReferenceElement`),M=n,N=c,P=l,F=s,I=h;S.type===`context-menu`&&(M=n??S.context?.anchor,F??=`start`,!o&&F!==`center`&&(P=e.alignOffset??2,N=e.sideOffset??-5));let L=o,R=F;S.type===`menu`?(L??=`inline-end`,R??=`start`,I=e.collisionAvoidance??j):S.type===`menubar`&&(L??=S.context.orientation===`vertical`?`inline-end`:`bottom`,R??=`start`);let z=S.type===`context-menu`,B=fe({anchor:M,floatingRootContext:C,positionMethod:ee?`fixed`:r,mounted:T,side:L,sideOffset:N,align:R,alignOffset:P,arrowPadding:z?0:f,collisionBoundary:u,collisionPadding:d,sticky:p,nodeId:k,keepMounted:x,disableAnchorTracking:m,collisionAvoidance:I,shift:z?{crossAxis:!(`side`in I&&I.side===`flip`),rootBoundary:`layoutViewport`}:void 0,externalTree:w,adaptiveOrigin:ae,lazyFlip:y?`placement`:!1});Q.useEffect(()=>{function e(e){e.open&&(e.parentNodeId===k&&v.set(`hoverEnabled`,!1),e.nodeId!==k&&e.parentNodeId===v.select(`floatingParentNodeId`)&&v.setOpen(!1,q(Ee)))}return w.events.on(`menuopenchange`,e),()=>{w.events.off(`menuopenchange`,e)}},[v,w.events,k]),Q.useEffect(()=>{if(v.select(`floatingParentNodeId`)==null)return;function e(e){if(e.open||e.nodeId!==v.select(`floatingParentNodeId`))return;let t=e.reason??`sibling-open`;v.setOpen(!1,q(t))}return w.events.on(`menuopenchange`,e),()=>{w.events.off(`menuopenchange`,e)}},[w.events,v]);let H=ft();Q.useEffect(()=>{E||H.clear()},[E,H]),Q.useEffect(()=>{function e(e){if(!(!E||e.nodeId!==v.select(`floatingParentNodeId`))){if(e.target&&D&&D!==e.target){let e=v.select(`closeDelay`);e>0?H.isStarted()||H.start(e,()=>{v.setOpen(!1,q(Ee))}):v.setOpen(!1,q(Ee))}else H.clear()}}return w.events.on(`itemhover`,e),()=>{w.events.off(`itemhover`,e)}},[w.events,E,D,v,H]),Q.useEffect(()=>{let e={open:E,nodeId:k,parentNodeId:A,reason:v.select(`lastOpenChangeReason`)};w.events.emit(`menuopenchange`,e)},[w.events,E,v,k,A]),Ae({store:v,domReference:se,positionerElement:re,open:E});let ce={open:E,side:B.side,align:B.align,anchorHidden:B.anchorHidden,nested:S.type===`menu`,instant:ie},U=S.type===`menubar`&&S.context.modal;Z(E&&(U||te&&oe!==`trigger-hover`),ne===`touch`,re,D);let W=Xe(e,ce,{styles:B.positionerStyles,transitionStatus:O,props:_,refs:[t,v.useStateSetter(`positionerElement`)],hidden:!T,inert:!E}),le=T&&S.type!==`menu`&&(S.type!==`menubar`&&te&&oe!==`trigger-hover`||S.type===`menubar`&&S.context.modal),G=null;return S.type===`menubar`?G=S.context.contentElement:S.type===void 0&&(G=D),(0,$.jsxs)(jt.Provider,{value:B,children:[le&&(0,$.jsx)(Se,{ref:S.type===`context-menu`||S.type===`nested-context-menu`?S.context.internalBackdropRef:null,inert:Ke(!E),cutout:G}),(0,$.jsx)(V,{id:k,children:(0,$.jsx)(Cn,{elementsRef:v.context.itemDomElements,labelsRef:v.context.itemLabels,onMapChange:b,children:W})})]})}),jn=Q.createContext(null);function Mn(e){let t=Q.useContext(jn);if(t===null&&!e)throw Error(ht(5));return t}function Nn(e){return e==null?Je:e.type.startsWith(`key`)?ye:e.type.startsWith(`mouse`)||e.type.startsWith(`pointer`)?ke:Je}var Pn={...he,disabled:e=>e.parent.type===`menubar`&&e.parent.context.disabled||e.disabled,modal:e=>(e.parent.type===void 0||e.parent.type===`context-menu`)&&(e.modal??!0),openMethod:e=>e.openMethod,keyboardOpen:e=>e.keyboardOpen,allowMouseEnter:e=>e.allowMouseEnter,highlightItemOnHover:e=>e.highlightItemOnHover,parent:e=>e.parent,rootId:e=>e.parent.type===`menu`?e.parent.store.select(`rootId`):e.parent.type===void 0?e.rootId:e.parent.context.rootId,activeIndex:e=>e.activeIndex,listElement:e=>e.listElement,triggerControlsId:(e,t)=>{let n=he.triggerPopupId(e,t);return n?e.listElement?.id||n:void 0},filterTriggerProps:e=>e.filterTriggerProps,inputProps:e=>e.inputProps,webkitAriaSelected:(e,t)=>et&&e.inputFocused&&t?!0:void 0,highlightedItemId:e=>e.highlightedItem?.id||void 0,isActive:(e,t)=>e.activeIndex===t,hoverEnabled:e=>e.hoverEnabled,instantType:e=>e.instantType===`trigger-change`&&!he.open(e)?void 0:e.instantType,lastOpenChangeReason:e=>e.openChangeReason,floatingTreeRoot:e=>e.parent.type===`menu`?e.parent.store.select(`floatingTreeRoot`):e.floatingTreeRoot,floatingNodeId:e=>e.floatingNodeId,floatingParentNodeId:e=>e.floatingParentNodeId,itemProps:e=>e.itemProps,closeDelay:e=>e.closeDelay,adaptiveOrigin:e=>e.adaptiveOrigin,keyboardEventRelay:e=>{if(e.keyboardEventRelay)return e.keyboardEventRelay;if(e.parent.type===`menu`)return e.parent.store.select(`keyboardEventRelay`)}},Fn=class extends dt{constructor(e,t,n=!1){let r=new ct,i=Ln(r,t,n,e);super(i,In(r),Pn),this.observe(`parent`,e=>{e.type===`menu`?this.context.allowMouseUpTriggerRef=e.store.context.allowMouseUpTriggerRef:e.type!==void 0&&(this.context.allowMouseUpTriggerRef=e.context.allowMouseUpTriggerRef)})}subscribeToParentMenu(){let e=this.state.parent;if(e.type!==`menu`)return;let t=e.store.select(`rootId`),n=e.store.select(`floatingTreeRoot`),r=e.store.select(`keyboardEventRelay`);return e.store.subscribe(()=>{let i=e.store.select(`rootId`),a=e.store.select(`floatingTreeRoot`),o=e.store.select(`keyboardEventRelay`);(t!==i||n!==a||r!==o)&&(t=i,n=a,r=o,this.notifyAll())})}setOpen(e,t){this.state.floatingRootContext.context.events.emit(`setOpen`,{open:e,eventDetails:t})}setActiveIndex(e,t,n){if(this.state.activeIndex!==e){let r=(e===null?void 0:this.context.itemDomElements.current[e])===this.context.reportedItem;this.context.highlightReason=r?`none`:t,this.context.highlightEvent=r?void 0:n}this.set(`activeIndex`,e)}highlightItem(e,t,n){let r=this.context.itemDomElements.current.indexOf(e);r>-1&&this.setActiveIndex(r,t,n)}};function In(e){return{positionerRef:Q.createRef(),popupRef:Q.createRef(),typingRef:{current:!1},itemDomElements:{current:[]},itemLabels:{current:[]},highlightReason:`none`,highlightEvent:void 0,reportedItem:void 0,allowMouseUpTriggerRef:{current:!1},virtualFocusRef:void 0,triggerFocusTargetRef:Q.createRef(),beforeTriggerFocusGuardRef:Q.createRef(),beforeContentFocusGuardRef:Q.createRef(),onOpenChangeComplete:void 0,triggerElements:e}}function Ln(e,t,n=!1,r){return{...mt(e,t,n),disabled:!1,modal:!0,openMethod:null,keyboardOpen:!1,allowMouseEnter:!1,highlightItemOnHover:!0,parent:{type:void 0},rootId:void 0,activeIndex:null,listElement:null,filterTriggerProps:m,inputProps:m,inputFocused:!1,highlightedItem:void 0,hoverEnabled:!0,instantType:void 0,openChangeReason:null,floatingTreeRoot:new te,floatingNodeId:void 0,floatingParentNodeId:null,itemProps:m,keyboardEventRelay:void 0,closeDelay:0,adaptiveOrigin:void 0,...r}}var Rn=Q.createContext(null);function zn(e,t){return(e===`trigger-press`||e===`item-press`)&&t?.detail===0}function Bn(e,t){return e===`list-navigation`||zn(e,t)}var Vn=F(function(e){let{children:t,open:n,onOpenChange:r,onOpenChangeComplete:i,onItemHighlighted:a,defaultOpen:o=!1,disabled:s=!1,modal:c,loopFocus:u=!0,orientation:f=`vertical`,actionsRef:p,closeParentOnEsc:h=!1,handle:b,triggerId:x,defaultTriggerId:S=null,highlightItemOnHover:C=!0,isSubmenu:w=!1,virtualFocus:T=!1,virtualFocusRef:E,allowEscape:te=!0,resetOnPointerLeave:D=!0}=e,re=It(!0),ae=Pt(!0),oe=Mn(!0),k=ae?.store,se=ae?.virtualFocus??!1,j=Q.useMemo(()=>w&&k?{type:`menu`,store:k}:oe?{type:`menubar`,context:oe}:re&&!k?{type:`context-menu`,context:re}:{type:void 0},[re,k,oe,w]),M=Ve(),N=Ve(),[P,F]=Q.useState(void 0),L=(P??N)||void 0,B=ne(),V=j.type===`menu`?j.store:void 0,H=(n??o)&&V?.state.transitionStatus===`starting`,ce=y(()=>H?V?.state.instantType:void 0).current,U=y(()=>{let e=new Fn({open:o,openProp:n,activeTriggerId:S,triggerIdProp:x,parent:j,disabled:s,highlightItemOnHover:C,modal:j.type===void 0?c:void 0,rootId:M,instantType:ce},L,B!=null);return e.context.virtualFocusRef=E,e}).current;U.useControlledProp(`openProp`,n),U.useControlledProp(`triggerIdProp`,x),U.useContextCallback(`onOpenChangeComplete`,i);let le=U.useState(`floatingTreeRoot`),ue=ee(le),G=U.useState(`open`),K=U.useState(`activeTriggerElement`),fe=U.useState(`positionerElement`),pe=U.useState(`hoverEnabled`),me=U.useState(`disabled`),he=U.useState(`lastOpenChangeReason`),J=U.useState(`parent`),ge=U.useState(`activeIndex`),_e=U.useState(`keyboardOpen`),ve=U.useState(`payload`),be=U.useState(`floatingParentNodeId`),xe=Q.useRef(null),Se=Q.useRef(J.type!==`context-menu`),Ce=ft(),we=Q.useRef(!0),Te=ft(),Y=be!=null,{openMethod:Ee,triggerProps:De}=Le(G);U.useSyncedValues({disabled:s,highlightItemOnHover:C,modal:J.type===void 0?c:void 0,openMethod:Ee,rootId:M}),l(U);let{forceUnmount:Oe,transitionStatus:ke}=Me(G,U,()=>{U.set(`allowMouseEnter`,!1)},H),Ae=O(U.context.popupRef);Q.useEffect(()=>{if(ce===void 0)return;let e=()=>{U.state.instantType===ce&&U.set(`instantType`,void 0)};if(!G){e();return}if(ke!==void 0)return;if(U.context.popupRef.current==null){e();return}let t=new AbortController;return Ae(e,t.signal),()=>{t.abort()}},[ce,G,ke,Ae,U]),A(()=>{re&&!ae?U.update({parent:{type:`context-menu`,context:re},floatingNodeId:ue,floatingParentNodeId:B}):(ae||!U.select(`activeTriggerElement`))&&U.update({floatingNodeId:ue,floatingParentNodeId:B})},[re,ae,ue,B,K,U]),Q.useEffect(()=>{if(G||(xe.current=null),J.type===`context-menu`){if(!G){Ce.clear(),Se.current=!1;return}Ce.start(500,()=>{Se.current=!0})}},[Ce,G,J.type]),A(()=>{!G&&!pe&&U.set(`hoverEnabled`,!0)},[G,pe,U]);let X=z((e,t)=>{let n=t.reason;if(!e&&!U.select(`open`)||G===e&&t.trigger===K&&he===n)return;let i=g(t);if(!e&&t.trigger==null&&(t.trigger=K??void 0),r?.(e,t),t.isCanceled)return;U.state.floatingRootContext.dispatchOpenChange(e,t);let a=t.event;if(e===!1&&n!==`item-press`&&a?.type===`click`&&a.pointerType===`touch`&&!we.current)return;e&&n===`trigger-focus`?(we.current=!1,Te.start(300,()=>{we.current=!0})):(we.current=!0,Te.clear());let o=!e&&(n===`escape-key`||n==null);xe.current=t.event;let s=Pe(U.state,e,t.trigger,i());s.openChangeReason=n,s.keyboardOpen=e&&Bn(n,a),s.instantType=J.type===`menubar`&&(n===`trigger-focus`||n===`focus-out`||n===`trigger-hover`||n===`list-navigation`||n===`sibling-open`)?`group`:zn(n,a)?`click`:o?`dismiss`:void 0,U.update(s)}),je=gt({popupStore:U,floatingRootContext:U.state.floatingRootContext,floatingId:L,nested:B!=null,onOpenChange:X}),Ne=je.context.events;A(()=>{let e=({open:e,eventDetails:t})=>X(e,t);return Ne.on(`setOpen`,e),()=>{Ne?.off(`setOpen`,e)}},[Ne,X]),A(()=>U.subscribeToParentMenu(),[U]);let Fe=Q.useCallback(()=>{U.setOpen(!1,q(ze))},[U]);Q.useImperativeHandle(p,()=>({unmount:Oe,close:Fe}),[Oe,Fe]);let Ie;J.type===`context-menu`&&(Ie=J.context),Q.useImperativeHandle(Ie?.positionerRef,()=>fe,[fe]),Q.useImperativeHandle(Ie?.actionsRef,()=>({setOpen:X}),[X]);let Re=d(je,{enabled:!me,bubbles:{escapeKey:h&&J.type===`menu`},outsidePress(){return J.type!==`context-menu`||xe.current?.type===`contextmenu`||Se.current},externalTree:Y?le:void 0}),Be=_(),Z=Ot(je,{enabled:!me,listRef:U.context.itemDomElements,activeIndex:ge,virtual:T,nested:J.type===`menubar`||!T&&J.type!==void 0,parentOrientation:J.type===`menubar`?J.context.orientation:void 0,loopFocus:u,focusItemOnOpen:T?_e:void 0,allowEscape:T&&u&&te,orientation:f,triggerOrientation:T?`vertical`:f,rtl:Be===`rtl`,disabledIndices:I,onNavigate(e,t){U.setActiveIndex(e,Nn(t),t?.nativeEvent)},openOnArrowKeyDown:J.type!==`context-menu`&&!(T&&w),externalTree:!T&&Y?le:void 0,nestedReturnFocusRef:V?.context.virtualFocusRef,focusItemOnHover:C,resetOnPointerLeave:D}),He=Q.useCallback(e=>{U.context.typingRef.current=e},[U]),Ue=kt(je,{enabled:!me&&!T,listRef:U.context.itemLabels,elementsRef:U.context.itemDomElements,activeIndex:ge,resetMs:500,onMatch:(e,t)=>{G&&e!==ge&&U.setActiveIndex(e,ye,t.nativeEvent)},onTyping:He}),We=z(a),Ge=Q.useRef(-1),Ke=z(()=>{let e=U.state.activeIndex,t=e===null?void 0:U.context.itemDomElements.current[e]??void 0;if(t?.isConnected===!1)return;let n=t===void 0?-1:e;if(Ge.current===n&&U.context.reportedItem===t)return;Ge.current=n,U.context.reportedItem=t,T&&U.set(`highlightedItem`,t);let{highlightReason:r,highlightEvent:i}=U.context;U.context.highlightReason=Je,U.context.highlightEvent=void 0,a&&We(t,pt(r,i,{label:t===void 0?void 0:U.context.itemLabels.current[n]??void 0}))});A(()=>{Ke()},[ge,Ke]);let qe=Q.useMemo(()=>{if(!T)return Z.reference;if(!Z.trigger)return m;let{onFocus:e,...t}=Z.trigger;return t},[T,Z.reference,Z.trigger]);U.useSyncedValue(`inputProps`,T?Z.reference??m:m);let Ye=Q.useMemo(()=>{let e=de(Ue.reference,qe,Re.reference,{onMouseMove(){U.set(`allowMouseEnter`,!0)}},De);return e[`aria-haspopup`]=`menu`,e[`aria-expanded`]=G,e},[U,Ue.reference,qe,Re.reference,De,G]),Xe=Q.useMemo(()=>{let e=de(Z.trigger,Re.trigger,De);return e[`aria-haspopup`]=`menu`,e[`aria-expanded`]=!1,e},[Z.trigger,Re.trigger,De]);y(()=>(U.update({inactiveTriggerProps:Xe}),null));let Ze=Q.useMemo(()=>de(R,{onMouseMove(){U.set(`allowMouseEnter`,!0),J.type===`menu`&&U.set(`hoverEnabled`,!1)},onClick(){U.select(`hoverEnabled`)&&U.set(`hoverEnabled`,!1)},onKeyDown(e){let t=U.select(`keyboardEventRelay`);t&&!e.isPropagationStopped()&&t(e)}},Ue.floating,Z.floating,Re.floating),[J.type,U,Ue.floating,Z.floating,Re.floating]),Qe=Z.item??m;ie(U,{floatingRootContext:je,activeTriggerProps:Ye,inactiveTriggerProps:Xe,popupProps:Ze,itemProps:Qe});let $e=Q.useMemo(()=>({store:U,parent:j,orientation:f,loopFocus:u,allowEscape:te,defaultFloatingId:N,setRenderedFloatingId:F,virtualFocus:T,parentVirtualFocus:se,syncHighlightedItem:Ke}),[U,j,f,u,te,N,T,se,Ke]),et=typeof t==`function`?t({payload:ve}):t,tt=(0,$.jsxs)(Nt.Provider,{value:$e,children:[b&&(0,$.jsx)(v,{handle:b,store:U}),et]});return(J.type===void 0||J.type===`context-menu`)&&(tt=(0,$.jsx)(W,{externalTree:le,children:tt})),tt});function Hn(e){let t=Q.useContext(Rn);if(t===null)return(0,$.jsx)(Vn,{...e});let n=t.Root;return(0,$.jsx)(Rn.Provider,{value:null,children:(0,$.jsx)(n,{...t.options,...e})})}var Un=5;function Wn(e,t){let n=Gn(t);return e.clientX>=n.left-Un&&e.clientX<=n.right+Un&&e.clientY>=n.top-Un&&e.clientY<=n.bottom+Un}function Gn(e){let t=e.getBoundingClientRect(),n=it(e);if(Ge)return t;let r=n.getComputedStyle(e,`::before`),i=n.getComputedStyle(e,`::after`);if(r.content===`none`&&i.content===`none`)return t;let a=parseFloat(r.width)||0,o=parseFloat(r.height)||0,s=parseFloat(i.width)||0,c=parseFloat(i.height)||0,l=Math.max(t.width,a,s),u=Math.max(t.height,o,c),d=l-t.width,f=u-t.height;return{left:t.left-d/2,right:t.right+d/2,top:t.top-f/2,bottom:t.bottom+f/2}}function Kn(e={}){let{highlightItemOnHover:t,highlightedIndex:n,onHighlightedIndexChange:r}=ut(),{ref:i,index:a}=Xt(e),o=n===a,s=Q.useRef(null),c=st(i,s);return{compositeProps:{tabIndex:o?0:-1,onFocus(){r(a)},onMouseMove(){let e=s.current;if(!t||!e)return;let n=e.hasAttribute(`disabled`)||e.ariaDisabled===`true`;!o&&!n&&e.focus()}},compositeRef:c,index:a}}function qn(e){let{render:t,className:n,style:r,state:i=m,props:a=I,refs:o=I,metadata:s,stateAttributesMapping:c,tag:l=`div`,...u}=e,{compositeProps:d,compositeRef:f}=Kn({metadata:s});return Y(l,e,{state:i,ref:[f,...o],props:[d,...a,u],stateAttributesMapping:c})}function Jn(e){if(Ce(e)&&e.hasAttribute(`data-rootownerid`))return e.getAttribute(`data-rootownerid`);if(!qe(e))return Jn(Re(e))}function Yn(e){let{enabled:t=!0,mouseDownAction:n,open:r}=e,i=Q.useRef(!1);return Q.useMemo(()=>t?{onMouseDown:e=>{(n===`open`&&!r||n===`close`&&r)&&(i.current=!0,Ie(e.currentTarget).addEventListener(`click`,()=>{i.current=!1},{once:!0}))},onClick:e=>{i.current&&(i.current=!1,e.preventBaseUIHandler())}}:m,[t,n,r])}var Xn=p(function(e,t){let{render:n,className:r,style:i,disabled:a=!1,nativeButton:o=!0,id:s,openOnHover:c,delay:l=100,closeDelay:u=0,handle:d,payload:f,...p}=e,h=Pt(!0),g=ot(d)??h?.store;if(!g)throw Error(ht(85));let _=Ve(s),v=g.useState(`isTriggerActive`,_),y=g.useState(`floatingRootContext`),x=g.useState(`isOpenedByTrigger`,_),S=g.useState(`triggerControlsId`,_),C=Q.useRef(null),w=Qn(),T=ut(!0),E=Ye(),O=Q.useMemo(()=>E??new te,[E]),re=ee(O),ie=ne(),{registerTrigger:ae,isMountedByThisTrigger:oe}=b(_,C,g,{payload:f,closeDelay:u,parent:w,floatingTreeRoot:O,floatingNodeId:re,floatingParentNodeId:ie,keyboardEventRelay:T?.relayKeyboardEvent}),k=w.type===`menubar`,A=g.useState(`disabled`),se=a||A||k&&w.context.disabled,{getButtonProps:j,buttonRef:M}=L({disabled:se,native:o});Q.useEffect(()=>{!x&&w.type===void 0&&(g.context.allowMouseUpTriggerRef.current=!1)},[g,x,w.type]);let N=Q.useRef(null),P=ft(),F=z(e=>{if(!N.current)return;P.clear(),g.context.allowMouseUpTriggerRef.current=!1;let t=e.target;X(N.current,t)||X(g.select(`positionerElement`),t)||t===N.current||(t==null||Jn(t)!==g.select(`rootId`))&&(Wn(e,N.current)||O.events.emit(`close`,{domEvent:e,reason:me}))});Q.useEffect(()=>{let e=Ie(N.current);if(x&&g.select(`lastOpenChangeReason`)===`trigger-hover`)return e.addEventListener(`mouseup`,F,{once:!0}),()=>{e.removeEventListener(`mouseup`,F)}},[x,F,g]);let I=k&&w.context.hasSubmenuOpen,R=Te(y,{enabled:(c??I)&&!se&&(!k||I&&!oe),handleClose:De({blockPointerEvents:!k}),mouseOnly:!0,move:!1,restMs:w.type===void 0?l:void 0,delay:{close:u},triggerElementRef:C,externalTree:O,isActiveTrigger:v,isClosing:()=>g.select(`transitionStatus`)===`ending`}),B=Zn(x,g.select(`lastOpenChangeReason`)),V=ce(y,{enabled:!se,event:x&&k?`click`:`mousedown`,toggle:!0,ignoreMouse:!1,stickIfOpen:w.type===void 0&&B}),H=xt(y,{enabled:!se&&I}),U=Yn({open:x,enabled:k,mouseDownAction:`open`}),W=Q.useMemo(()=>de(H.reference,V.reference),[H.reference,V.reference]),le=g.useState(`triggerProps`,oe),ue=g.useState(`filterTriggerProps`),{handlePreFocusGuardFocus:G,handleFocusTargetFocus:K}=tt(g,C),fe={disabled:se,open:x},pe=[N,t,M,ae,C],he=[W,R??m,le,{"aria-haspopup":`menu`,"aria-controls":S,id:_,onMouseDown:e=>{g.select(`open`)||(P.start(200,()=>{g.context.allowMouseUpTriggerRef.current=!0}),Ie(e.currentTarget).addEventListener(`mouseup`,F,{once:!0}))}},ue,k?{role:`menuitem`}:{},U,p,j],q=Y(`button`,e,{enabled:!k,stateAttributesMapping:D,state:fe,ref:pe,props:he});return k?(0,$.jsx)(qn,{tag:`button`,render:n,className:r,style:i,state:fe,refs:pe,props:he,stateAttributesMapping:D}):x?(0,$.jsxs)(Q.Fragment,{children:[(0,$.jsx)(rt,{ref:g.context.beforeTriggerFocusGuardRef,onFocus:G},`${_}-pre-focus-guard`),(0,$.jsx)(Q.Fragment,{children:q},_),(0,$.jsx)(rt,{ref:g.context.triggerFocusTargetRef,onFocus:K},`${_}-post-focus-guard`)]}):(0,$.jsx)(Q.Fragment,{children:q},_)});function Zn(e,t){let n=ft(),[r,i]=Q.useState(!1);return A(()=>{e&&t===`trigger-hover`?(i(!0),n.start(500,()=>{i(!1)})):e||(n.clear(),i(!1))},[e,t,n]),r}function Qn(){let e=Mn(!0);return Q.useMemo(()=>e?{type:`menubar`,context:e}:{type:void 0},[e])}var $n=Q.forwardRef(function(e,t){let{className:n,render:r,orientation:i=`horizontal`,style:a,...o}=e;return Y(`div`,e,{state:{orientation:i},ref:t,props:[{role:`separator`,"aria-orientation":i},o]})}),er=(0,Q.createContext)(null);function tr({actionsRef:e,children:t,interactionOwner:n=`local`,onOpenChange:r,...i}){let a=(0,Q.useRef)(null),o=e??a;return k(()=>o.current?.close()),(0,$.jsx)(er.Provider,{value:{actionsRef:o,interactionOwner:n},children:(0,$.jsx)(Hn,{...i,actionsRef:o,onOpenChange:(e,t)=>{if(n===`host`&&!e&&t.reason===`escape-key`){t.cancel(),t.allowPropagation();return}r?.(e,t)},children:t})})}function nr(){let e=(0,Q.useContext)(er);if(!e)throw Error(`DropdownMenu parts must be used inside <DropdownMenu>`);return e}var rr=(0,Q.forwardRef)(function({className:e,render:t,type:n=`button`,...a},o){return(0,$.jsx)(Xn,{...a,className:t=>r(`btn caps-dropdown-trigger`,i(e,t)),ref:o,render:t,type:n})}),ir=(0,Q.forwardRef)(function({container:e,...t},n){let r=Fe(`popover`);return e==null&&r===null?null:(0,$.jsx)(Sn,{...t,container:e??r,ref:n})}),ar=(0,Q.forwardRef)(function({collisionBoundary:e,...t},n){let r=Fe(`popover`);return(0,$.jsx)(An,{...t,collisionBoundary:e??(r&&r!==document.body?r:void 0),ref:n})}),or=(0,Q.forwardRef)(function({className:e,finalFocus:t,...n},a){let{interactionOwner:o}=nr(),s=(0,Q.useRef)(null);(0,Q.useImperativeHandle)(a,()=>s.current);let c=J(`.caps-dropdown-item[data-highlighted]`),l=(0,Q.useCallback)(e=>{s.current=e,c(e)},[c]);return(0,$.jsx)(yn,{...n,className:t=>r(`caps-dropdown-popup min-w-40 rounded-box border border-base-300 bg-base-100 p-xs shadow-lg outline-none`,i(e,t)),finalFocus:o===`host`?!1:t??!0,ref:l})}),sr=(0,Q.forwardRef)(function({align:e=`end`,alignOffset:t,children:n,container:r,keepMounted:i,side:a=`bottom`,sideOffset:o=4,...s},c){return(0,$.jsx)(ir,{container:r,keepMounted:i,children:(0,$.jsx)(ar,{align:e,alignOffset:t,side:a,sideOffset:o,children:(0,$.jsx)(or,{...s,ref:c,children:n})})})}),cr=`caps-dropdown-item flex w-full items-center gap-sm rounded-field px-md py-sm text-left text-sm outline-none transition-colors hover:bg-base-200 focus-visible:bg-base-200 aria-[current=page]:bg-base-200 aria-[current=page]:font-semibold disabled:cursor-not-allowed disabled:text-base-content/40 data-disabled:cursor-not-allowed data-disabled:text-base-content/40`,lr=(0,Q.forwardRef)(function({className:e,onClick:t,onSelect:n,variant:a=`default`,...o},s){return(0,$.jsx)(un,{...o,className:t=>r(cr,a===`destructive`&&`text-error hover:bg-error hover:text-error-content focus-visible:bg-error focus-visible:text-error-content`,i(e,t)),onClick:e=>{t?.(e),e.defaultPrevented||n?.(e)},ref:s})}),ur=(0,Q.forwardRef)(function({children:e,className:t,onClick:n,onSelect:a,...o},s){return(0,$.jsxs)(tn,{...o,className:e=>r(cr,i(t,e)),onClick:e=>{n?.(e),e.defaultPrevented||a?.(e)},ref:s,children:[(0,$.jsx)(`span`,{className:`min-w-0 flex-1`,children:e}),(0,$.jsx)(nn,{"aria-hidden":`true`,className:`shrink-0`,children:`✓`})]})}),dr=(0,Q.forwardRef)(function({className:e,...t},n){return(0,$.jsx)($n,{...t,className:t=>r(`my-xs h-px bg-base-300`,i(e,t)),ref:n})}),fr=sn,pr=(0,Q.forwardRef)(function({className:e,...t},n){return(0,$.jsx)(cn,{...t,className:t=>r(`px-md pb-xs pt-sm text-xs font-semibold text-base-content/60`,i(e,t)),ref:n})});export{lr as a,rr as c,fr as i,yt as l,ur as n,pr as o,sr as r,dr as s,tr as t,vt as u};
1
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{C as t,Vn as n,v as r,y as i}from"./button-oE2Hrd5D.js";import{l as a,u as o}from"./log-event-BfZxbz9a.js";import{$ as s,$t as c,A as l,At as u,B as d,Bt as f,C as p,Cn as m,Ct as h,D as g,Dt as _,E as v,En as y,F as b,Ft as x,G as ee,Gt as S,H as C,Ht as w,I as T,It as E,J as te,K as ne,Kt as D,L as O,Lt as re,M as ie,Mt as ae,Nt as oe,On as k,Ot as A,Pt as se,Q as j,Qt as M,R as N,Rt as P,S as F,Sn as I,St as L,T as R,Tn as z,Tt as B,U as V,Ut as H,V as ce,Vt as U,W,Y as le,Z as ue,_ as G,_n as de,_t as K,a as fe,an as pe,at as me,b as he,bt as q,c as J,cn as ge,ct as _e,dn as ve,dt as ye,en as be,et as xe,f as Se,fn as Ce,ft as we,g as Te,gn as Y,gt as Ee,h as De,hn as Oe,ht as ke,i as Ae,in as X,it as je,j as Me,jt as Ne,k as Pe,kn as Fe,kt as Ie,l as Le,ln as Re,lt as ze,m as Be,mn as Ve,n as Z,nn as He,nt as Ue,o as We,on as Ge,p as Ke,pn as qe,pt as Je,q as Ye,r as Xe,rn as Ze,rt as Qe,s as $e,sn as et,t as tt,tn as nt,tt as rt,un as it,ut as at,v as ot,vn as st,w as ct,wn as lt,wt as ut,x as dt,xn as ft,xt as pt,y as mt,yn as ht,z as gt,zt as _t}from"./useTriggerFocusGuards-Bddw7Qdn.js";function vt(e){return/\.mp4$/iu.test(e)}async function yt(e,t){if(vt(e.name)){let n=document.createElement(`video`);return n.preload=`metadata`,n.muted=!0,await new Promise((e,r)=>{n.addEventListener(`loadedmetadata`,()=>{e()},{once:!0}),n.addEventListener(`error`,()=>{r(Error(`MP4 metadata could not be read`))},{once:!0}),n.src=t}),{file:e,url:t,width:n.videoWidth,height:n.videoHeight}}if(o(e.name)){let n=new Audio;return n.preload=`metadata`,await new Promise((e,r)=>{n.addEventListener(`loadedmetadata`,()=>{e()},{once:!0}),n.addEventListener(`error`,()=>{r(Error(`MP3 metadata could not be read`))},{once:!0}),n.src=t}),{file:e,url:t,...a}}let n=new Image;return n.src=t,await n.decode(),{file:e,url:t,width:n.naturalWidth,height:n.naturalHeight}}var Q=e(n(),1),bt=ge&&et;function xt(e,t={}){let{enabled:n=!0,delay:r}=t,{events:i,dataRef:a}=e.context,o=Q.useRef(!1),s=Q.useRef(null),c=Q.useRef(!0),l=ft();Q.useEffect(()=>{let t=e.select(`domReferenceElement`);if(!n)return;let r=it(t);function i(){let t=e.select(`domReferenceElement`);!e.select(`open`)&&Ce(t)&&t===Ze(Ie(t))&&(o.current=!0,s.current=t)}function a(){c.current=!0}function l(){c.current=!1}return je(B(r,`blur`,i),bt&&B(r,`keydown`,a,!0),bt&&B(r,`pointerdown`,l,!0))},[e,n]),Q.useEffect(()=>{if(!n)return;function t(t){if(t.reason===`trigger-press`||t.reason===`escape-key`){let t=e.select(`domReferenceElement`);ve(t)&&(s.current=t,o.current=!0)}}return i.on(`openchange`,t),()=>{i.off(`openchange`,t)}},[i,n,e]);let u=Q.useMemo(()=>{function t(){o.current=!1,s.current=null}return{onMouseLeave(){t()},onFocus(n){let i=n.currentTarget;if(o.current){if(s.current===i)return;t()}let a=pe(n.nativeEvent);if(ve(a)){if(bt&&!n.relatedTarget){if(!c.current&&!w(a))return}else if(!H(a))return}let u=f(n.relatedTarget,e.context.triggerElements),{nativeEvent:d,currentTarget:p}=n;if(e.select(`open`)&&u||!r){e.setOpen(!0,q(K,d,p));return}l.start(r,()=>{o.current||e.setOpen(!0,q(K,d,p))})},onBlur(n){t();let r=n.relatedTarget,i=n.nativeEvent,o=ve(r)&&r.hasAttribute(xe(`focus-guard`))&&r.getAttribute(`data-type`)===`outside`;l.start(0,()=>{let t=e.select(`domReferenceElement`),n=Ze(Ie(t));!r&&n===t||X(a.current.floatingContext?.refs.floating.current,n)||X(t,n)||o||f(r??n,e.context.triggerElements)||e.setOpen(!1,q(K,i))})}}},[a,r,e,l]);return Q.useMemo(()=>n?{reference:u,trigger:u}:{},[n,u])}function St(e){return et&&e.movementX===0&&e.movementY===0}function Ct(e,t,n){switch(e){case`vertical`:return t;case`horizontal`:return n;default:return t||n}}function wt(e,t){return Ct(t,e===`ArrowUp`||e===`ArrowDown`,e===`ArrowLeft`||e===`ArrowRight`)}function Tt(e,t,n){return Ct(t,e===`ArrowDown`,n?e===`ArrowLeft`:e===`ArrowRight`)||e===`Enter`||e===` `||e===``}function Et(e,t,n){return Ct(t,n?e===be:e===nt,e===c)}function Dt(e,t,n,r){return t===`both`||t===`horizontal`&&r?e===`Escape`:Ct(t,n?e===nt:e===be,e===He)}function Ot(e,t){let{listRef:n,activeIndex:r,onNavigate:i=()=>{},enabled:a=!0,selectedIndex:o=null,allowEscape:c=!1,loopFocus:l=!1,nested:d=!1,rtl:f=!1,virtual:p=!1,focusItemOnOpen:m=`auto`,focusItemOnHover:h=!0,openOnArrowKeyDown:g=!0,disabledIndices:_=void 0,orientation:v=`vertical`,triggerOrientation:y=v,parentOrientation:b,id:x,resetOnPointerLeave:ee=!0,externalTree:S,nestedReturnFocusRef:C,grid:T}=t,te=T!=null,D=e.useState(`open`),O=e.useState(`floatingElement`),ie=e.useState(`domReferenceElement`),oe=e.context.dataRef,k=_t(O),j=U(ie),M=Qe(k),N=ne(),F=Ye(S),I=Q.useRef(m),L=Q.useRef(o??-1),R=Q.useRef(null),B=Q.useRef(!0),V=z(e=>{i(L.current===-1?null:L.current,e)}),H=Q.useRef(!!O),ce=Q.useRef(D),W=Q.useRef(!1),le=Q.useRef(!1),ue=Q.useRef(null),G=Qe(_),de=Qe(D),K=Qe(o),fe=Qe(ee),me=Ue(),he=Ue(),J=z(()=>{me.cancel();function e(e){p||(ue.current=s(e,{sync:W.current,preventScroll:!0}))}let t=n.current[L.current],r=le.current;t&&e(t),(W.current?e=>e():e=>me.request(e))(()=>{let i=n.current[L.current]||t;i&&(t||e(i),Se&&(r||!B.current)&&i.scrollIntoView?.({block:`nearest`,inline:`nearest`}))})});A(()=>{oe.current.orientation=v},[oe,v]),A(()=>{D||(R.current=null),(!D||m!==`auto`)&&(I.current=m)},[D,m]),A(()=>{a&&(D&&O?(L.current=o??-1,I.current&&o!=null&&(le.current=!0,V())):H.current&&(L.current=-1,V()))},[a,D,O,o,V]),A(()=>{if(a){if(!D){W.current=!1;return}if(O){if(r==null){if(W.current=!1,K.current!=null)return;if(H.current&&(L.current=-1,J()),(!ce.current||!H.current)&&I.current&&(R.current!=null||I.current===!0&&R.current==null)){let e=0,t=()=>{n.current[0]==null?(e<2&&(e?e=>he.request(e):queueMicrotask)(t),e+=1):(L.current=R.current==null||Tt(R.current,y,f)||d?Ne(n):u(n),R.current=null,V())};t()}}else se(n.current,r)||(L.current=r,J(),le.current=!1)}}},[a,D,O,r,K,d,n,y,f,V,J,he]),A(()=>{if(!a||O||!F||p||!H.current)return;let e=F.nodesRef.current,t=e.find(e=>e.id===N)?.context?.elements.floating,n=Ze(Ie(ie??t??null)),r=e.some(e=>e.context&&X(e.context.elements.floating,n));t&&!r&&B.current&&t.focus({preventScroll:!0})},[a,O,ie,F,N,p]),A(()=>{ce.current=D,H.current=!!O});let ge=r!=null,ve=z(e=>{if(!de.current)return;let t=n.current.indexOf(e.currentTarget);t!==-1&&(L.current!==t||r!==t)&&(L.current=t,V(e))}),ye=z(()=>b??F?.nodesRef.current.find(e=>e.id===N)?.context?.dataRef?.current.orientation),be=z(()=>Ne(n,G.current)),xe=z(t=>{if(B.current=!1,W.current=!0,t.which===229||!de.current&&t.currentTarget===M.current)return;if(d&&Dt(t.key,v,f,te)){wt(t.key,ye())||P(t),e.setOpen(!1,q(we,t.nativeEvent));let n=C?.current??ie;Ce(n)&&n.focus();return}r!=null&&r!==L.current&&!se(n.current,r)&&(L.current=r);let i=L.current,a=Ne(n,_),o=u(n,_);if(j||(t.key===`Home`&&(P(t),L.current=a,V(t)),t.key===`End`&&(P(t),L.current=o,V(t))),T!=null){let e=T(t,L.current,n,v,l,f,_,a,o);if(e!=null&&e!==L.current&&(L.current=e,V(t)),v===`both`)return}if(wt(t.key,v)){P(t);let e=Ze(t.currentTarget.ownerDocument);if(D&&!p&&X(t.currentTarget,e)&&!n.current.some(t=>t!=null&&X(t,e))){L.current=Tt(t.key,v,f)?a:o,V(t),r===L.current&&J();return}let{index:s,wrapped:u}=ae(n.current,i,{decrement:!Tt(t.key,v,f),loopFocus:l,allowEscape:c,disabledIndices:_,minIndex:a,maxIndex:o});u&&(W.current=!1),L.current=s,V(t)}}),Se=Q.useMemo(()=>({onFocus(e){W.current=!0,ve(e)},onClick({currentTarget:e}){p||e.focus({preventScroll:!0})},onMouseMove(e){St(e)||(W.current=!0,le.current=!1,h&&ve(e))},onPointerLeave(e){if(!de.current||!B.current||e.pointerType===`touch`)return;W.current=!0;let t=e.relatedTarget;if(!(!h||n.current.includes(t))&&fe.current&&(ue.current?.(),ue.current=null,L.current=-1,V(e),!p)){let e=M.current,t=Ze(Ie(e));e&&X(e,t)&&e.focus({preventScroll:!0})}}}),[ve,de,M,h,n,V,fe,p]),Te=Q.useMemo(()=>p&&D&&ge&&{"aria-activedescendant":`${x}-${r}`},[p,D,ge,x,r]),Y=Q.useMemo(()=>({...j?{}:Te,onKeyDown(t){if(t.key===`Tab`&&t.shiftKey&&D&&!p){let n=pe(t.nativeEvent);if(n&&!X(M.current,n))return;P(t);let r=q(_e,t.nativeEvent);e.setOpen(!1,r);let i=C?.current??ie;!r.isCanceled&&Ce(i)&&i.focus();return}xe(t)},onPointerMove(e){St(e)||(B.current=!0)}}),[Te,xe,M,j,e,D,p,ie,C]),Ee=Q.useMemo(()=>{function t(t){e.setOpen(!0,q(we,t.nativeEvent,t.currentTarget))}function n(e){m===`auto`&&E(e.nativeEvent)&&(I.current=!p)}function r(e){I.current=m,m===`auto`&&re(e.nativeEvent)&&(I.current=!0)}return{onKeyDown(n){let r=e.select(`open`);B.current=!1;let i=n.key.startsWith(`Arrow`),a=Et(n.key,ye(),f),o=wt(n.key,r?v:y),s=(d?a:o)||n.key===`Enter`||n.key.trim()===``;if(p&&r&&(!d||w(n.currentTarget)))return xe(n);if(!(!r&&!g&&i)){if(s){let e=wt(n.key,ye());R.current=d&&e?null:n.key}if(d){a&&(P(n),r?(L.current=be(),V(n),p&&M.current?.focus()):t(n));return}o&&(K.current!=null&&(L.current=K.current),P(n),!r&&g?t(n):xe(n),r&&V(n))}},onFocus(t){t.target===t.currentTarget&&e.select(`open`)&&!p&&(L.current=-1,V(t))},onPointerDown:r,onPointerEnter:r,onMouseDown:n,onClick:n}},[xe,m,be,d,V,e,g,v,y,ye,f,K,p,M]),De=Q.useMemo(()=>({...Te,...Ee}),[Te,Ee]);return Q.useMemo(()=>a?{reference:De,floating:Y,item:Se,trigger:Ee}:{},[a,De,Y,Ee,Se])}function kt(e,t){let{listRef:n,elementsRef:r,activeIndex:i,onMatch:a,disabledIndices:o,onTyping:s,enabled:c=!0,resetMs:l=750,selectedIndex:u=null}=t,d=z(s),f=e.useState(`open`),p=ft(),m=Q.useRef(``),h=Q.useRef(u??i??-1),g=Q.useRef(null),_=z(e=>{function t(e){return r?.current[e]}function s(e){let n=t(e);return n&&!oe(n)||n?.matches(`:disabled`)?!1:o==null||!x(I,e,o)}function c(e,t,n=0){if(e.length===0)return-1;let r=(n%e.length+e.length)%e.length,i=t.toLowerCase();for(let t=0;t<e.length;t+=1){let n=(r+t)%e.length;if(!(!e[n]?.toLowerCase().startsWith(i)||!s(n)))return n}return-1}let _=n.current;if(m.current.length>0&&e.key===` `&&(P(e),d?.(!0)),m.current.length>0&&m.current[0]!==` `&&c(_,m.current)===-1&&e.key!==` `&&d?.(!1),_==null||e.key.length!==1||e.ctrlKey||e.metaKey||e.altKey)return;f&&e.key!==` `&&(P(e),d?.(!0));let v=m.current===``;v&&(h.current=u??i??-1),_.every((e,t)=>e&&s(t)?e[0]?.toLowerCase()!==e[1]?.toLowerCase():!0)&&m.current===e.key&&(m.current=``,h.current=g.current),m.current+=e.key,p.start(l,()=>{m.current=``,h.current=g.current,d?.(!1)});let y=((v?u??i??-1:h.current)??0)+1,b=c(_,m.current,y);b===-1?e.key!==` `&&(m.current=``,d?.(!1)):(a?.(b,e),g.current=b)}),v=z(t=>{let n=t.relatedTarget,r=e.select(`domReferenceElement`),i=e.select(`floatingElement`);X(r,n)||X(i,n)||(p.clear(),m.current=``,h.current=g.current,d?.(!1))});A(()=>{!f&&u!==null||(p.clear(),g.current=null,m.current!==``&&(m.current=``,d?.(!1)))},[f,u,p,d]);let y=Q.useMemo(()=>({onKeyDown:_,onBlur:v}),[_,v]);return Q.useMemo(()=>c?{reference:y,floating:y}:{},[c,y])}function At({controlled:e,default:t,name:n,state:r=`value`}){let{current:i}=Q.useRef(e!==void 0),[a,o]=Q.useState(()=>t);return[i&&e!==void 0?e:a,Q.useCallback(e=>{i||o(e)},[])]}var $=t(),jt=Q.createContext(void 0);function Mt(e){let t=Q.useContext(jt);if(t===void 0&&!e)throw Error(ht(33));return t}var Nt=Q.createContext(void 0);function Pt(e){let t=Q.useContext(Nt);if(t===void 0&&!e)throw Error(ht(36));return t}var Ft=Q.createContext(void 0);function It(e=!0){let t=Q.useContext(Ft);if(t===void 0&&!e)throw Error(ht(25));return t}var Lt=Q.createContext(null);function Rt(e=`root`){let t=Q.useContext(Lt),n=Q.useContext(Nt);return t===null||n===void 0?null:(e===`submenu-trigger`?n.virtualFocus||n.parentVirtualFocus:n.virtualFocus)?t:null}var zt={visible:!0,ref:null};function Bt(){return zt}function Vt(e,t,n=`root`){let r=Rt(n),i=((n===`submenu-trigger`?r?.useSubmenuTrigger:r?.useItem)??Bt)({label:e.label,children:e.children,render:e.render}),a=st(t,i.ref);return{visible:i.visible,ref:a,props:i.props}}var Ht=Q.createContext(void 0);function Ut(){let e=Q.useContext(Ht);if(e===void 0)throw Error(ht(30));return e}function Wt(e){e.preventDefault()}function Gt(e){let{closeOnClick:t,highlighted:n,id:r,nodeId:i,store:a,typingRef:o,itemRef:s,itemMetadata:c}=e,l=Pt(),u=It(!0),d=c.type===`submenu-trigger`,f=d?l.parentVirtualFocus:l.virtualFocus,p=(d&&l.parent.type===`menu`?l.parent.store:l.store).useState(`webkitAriaSelected`,n),{events:m}=a.useState(`floatingTreeRoot`),g=a.useState(`open`),_=u!==void 0,v=!f&&g&&n?0:-1;return Q.useMemo(()=>({id:r,role:`menuitem`,tabIndex:v,"aria-selected":p,onMouseDown:f?Wt:void 0,onKeyDown(e){e.key===` `&&o?.current&&e.preventDefault()},onMouseMove(e){i&&m.emit(`itemhover`,{nodeId:i,target:e.currentTarget})},onClick(e){t&&m.emit(`close`,{domEvent:e.nativeEvent,reason:at})},onMouseUp(e){if(u){let t=u.initialCursorPointRef.current;if(u.initialCursorPointRef.current=null,_&&t&&Math.abs(e.clientX-t.x)<=1&&Math.abs(e.clientY-t.y)<=1||_&&!ge&&e.button===2)return}s.current&&a.context.allowMouseUpTriggerRef.current&&(!_||e.button===2)&&c.type===`regular-item`&&h(s.current,e,{detail:1,pointerType:`mouse`})}}),[t,v,r,m,i,a.context.allowMouseUpTriggerRef,o,s,u,_,c.type,p,f])}var Kt={type:`regular-item`};function qt(e){let{closeOnClick:t,disabled:n,highlighted:r,id:i,store:a,typingRef:o=a.context.typingRef,nativeButton:s,itemMetadata:c,nodeId:l}=e,u=Q.useRef(null),{getButtonProps:d,buttonRef:f}=L({disabled:n,focusableWhenDisabled:!0,native:s,composite:!0}),p=Gt({closeOnClick:t,highlighted:r,id:i,nodeId:l,store:a,typingRef:o,itemRef:u,itemMetadata:c}),m=Q.useCallback(e=>de(p,{onMouseEnter(e){c.type===`submenu-trigger`&&c.setActive(e.nativeEvent)}},e,d),[p,d,c]),h=st(u,f);return Q.useMemo(()=>({getItemProps:m,itemRef:h}),[m,h])}var Jt=Q.createContext({register:()=>{},unregister:()=>{},subscribeMapChange:()=>()=>{},nextIndexRef:{current:0}});function Yt(){return Q.useContext(Jt)}function Xt(e={}){let{guess:t,label:n,metadata:r,textRef:i,index:a}=e,{register:o,unregister:s,subscribeMapChange:c,nextIndexRef:l}=Yt(),u=Q.useRef(-1),[d,f]=Q.useState(a==null&&t?()=>{if(u.current===-1){let e=l.current;l.current+=1,u.current=e}return u.current}:-1),p=a??d,m=Q.useRef(null),h=Q.useCallback(e=>{let t=m.current;t&&s(t),m.current=e,e&&o(e,{metadata:r??null,index:a??null,label:n,textRef:i})},[a,o,s,r,n,i]);return A(()=>{if(a==null)return c(e=>{let t=m.current?e.get(m.current)?.index:null;t!=null&&f(t)})},[a,c]),{ref:h,index:p}}var Zt=`data-checked`,Qt=`data-unchecked`,$t={checked(e){return e?{[Zt]:``}:{[Qt]:``}},...M},en=Q.forwardRef(function(e,t){let{render:n,className:r,id:i,label:a,nativeButton:o=!1,disabled:s=!1,closeOnClick:c=!1,checked:l=!1,onCheckedChange:u,style:d,...f}=e,{store:p}=Pt(),m=Xt({guess:!0,label:a}),h=Ve(i),g=p.useState(`disabled`),_=p.useState(`isActive`,m.index),v=p.useState(`floatingNodeId`),y=p.useState(`itemProps`),b=s||g,{getItemProps:x,itemRef:ee}=qt({closeOnClick:c,disabled:b,highlighted:_,id:h,store:p,nativeButton:o,nodeId:v,itemMetadata:Kt}),S=Q.useMemo(()=>({disabled:b,highlighted:_,checked:l}),[b,_,l]);function C(e){let t=q(at,e.nativeEvent,void 0,{preventUnmountOnClose:lt});u?.(!l,t)}let w=Y(`div`,e,{state:S,stateAttributesMapping:$t,props:[y,{role:`menuitemcheckbox`,"aria-checked":l,onClick:C},f,x],ref:[ee,t,m.ref]});return(0,$.jsx)(Ht.Provider,{value:S,children:w})}),tn=Q.forwardRef(function(e,t){let{checked:n,defaultChecked:r,onCheckedChange:i,...a}=e,[o,s]=At({controlled:n,default:r??!1,name:`MenuCheckboxItem`,state:`checked`}),c=Vt(e,t);function l(e,t){i?.(e,t),t.isCanceled||s(e)}return c.visible?(0,$.jsx)(en,{...a,checked:o,onCheckedChange:l,ref:c.ref}):null}),nn=Q.forwardRef(function(e,t){let{render:n,className:r,style:i,keepMounted:a=!1,...o}=e,s=Ut(),c=Q.useRef(null),{transitionStatus:l,mounted:u,setMounted:d}=N(s.checked);T({batch:!0,enabled:!s.checked,open:s.checked,ref:c,onComplete(){s.checked||d(!1)}});let f={checked:s.checked,disabled:s.disabled,highlighted:s.highlighted,transitionStatus:l};return Y(`span`,e,{state:f,ref:[t,c],stateAttributesMapping:$t,props:{"aria-hidden":!0,...o},enabled:a||u})}),rn=Q.createContext(void 0);function an(){let e=Q.useContext(rn);if(e===void 0)throw Error(ht(31));return e}var on=Q.forwardRef(function(e,t){let{render:n,className:r,style:i,...a}=e,[o,s]=Q.useState(void 0),c=Y(`div`,e,{ref:t,props:{role:`group`,"aria-labelledby":o,...a}});return(0,$.jsx)(rn.Provider,{value:s,children:c})}),sn=Q.forwardRef(function(e,t){let n=Rt()?.Group??on;return(0,$.jsx)(n,{...e,ref:t})}),cn=Q.forwardRef(function(e,t){let{render:n,className:r,style:i,id:a,...o}=e,s=Ve(a),c=an();return A(()=>(c(s),()=>{c(e=>e===s?void 0:e)}),[c,s]),Y(`div`,e,{ref:t,props:{id:s,"aria-hidden":!0,...o}})}),ln=Q.forwardRef(function(e,t){let{render:n,className:r,id:i,label:a,nativeButton:o=!1,disabled:s=!1,closeOnClick:c=!0,style:l,...u}=e,{store:d}=Pt(),f=Xt({guess:!0,label:a}),p=Ve(i),m=d.useState(`disabled`),h=d.useState(`isActive`,f.index),g=d.useState(`floatingNodeId`),_=d.useState(`itemProps`),v=s||m,{getItemProps:y,itemRef:b}=qt({closeOnClick:c,disabled:v,highlighted:h,id:p,store:d,nativeButton:o,nodeId:g,itemMetadata:Kt});return Y(`div`,e,{state:{disabled:v,highlighted:h},props:[_,u,y],ref:[b,t,f.ref]})}),un=Q.forwardRef(function(e,t){let n=Vt(e,t);return n.visible?(0,$.jsx)(ln,{...e,ref:n.ref}):null}),dn=Q.createContext(void 0);function fn(){return Q.useContext(dn)}function pn(e,t){let n=Oe(e.render);if(Q.isValidElement(n)){let e=n.props;if(Object.hasOwn(e,`id`))return e.id??``}return e.id??t}function mn(e,t,n){let r=pn(e,t),i=r===t?void 0:r;return[r,Q.useCallback(e=>n?.(e?i:void 0),[i,n])]}function hn(e,t,n){let r=Oe(e.render),i=Q.isValidElement(r)?r.props:void 0,a=e[`aria-label`]??i?.[`aria-label`],o=e[`aria-labelledby`]??i?.[`aria-labelledby`];return o==null&&!a&&(o=t?t.id||void 0:n||void 0),o}var gn=Q.forwardRef(function(e,t){let{render:n,className:r,style:i,finalFocus:a,id:o,initialFocus:s,...c}=e,{store:l,defaultFloatingId:u,setRenderedFloatingId:d,virtualFocus:f,orientation:p}=Pt(),m=fn(),{side:h,align:g}=Mt(),_=$e(!0)!=null,v=l.useState(`open`),y=l.useState(`transitionStatus`),b=l.useState(`popupProps`),x=l.useState(`mounted`),ee=l.useState(`instantType`),w=l.useState(`activeTriggerElement`),E=l.useState(`parent`),te=l.useState(`lastOpenChangeReason`),ne=l.useState(`rootId`),D=l.useState(`floatingRootContext`),O=l.useState(`floatingTreeRoot`),re=l.useState(`closeDelay`),ie=l.useState(`hoverEnabled`),ae=l.useState(`disabled`),oe=l.useState(`openMethod`),k=l.useState(`activeTriggerId`),A=l.useState(`listElement`),[se,j]=mn(e,u,d),M=hn(e,w,k),N=E.type===`menu`?m:void 0,P=E.type===`context-menu`,F=s??E.type!==`menu`;s===void 0&&A&&E.type!==`menu`&&(F=()=>l.state.activeIndex===null&&A),T({open:v,ref:l.context.popupRef,onComplete(){v&&l.context.onOpenChangeComplete?.(!0)}}),Q.useEffect(()=>{function e(e){l.setOpen(!1,q(e.reason,e.domEvent))}return O.events.on(`close`,e),()=>{O.events.off(`close`,e)}},[O.events,l]),G(D,{enabled:ie&&!ae&&!P&&E.type!==`menubar`,closeDelay:re});let I=l.useStateSetter(`popupElement`),{parentVirtualFocusRef:L,handleFocus:R}=(Q.useContext(Lt)?.useParentHandoff??vn)(l,E,v,f),z={transitionStatus:y,side:h,align:g,open:v,nested:E.type===`menu`,instant:ee},B=Y(`div`,e,{state:z,ref:[t,l.context.popupRef,I,j],stateAttributesMapping:S,props:[b,{id:se,...A?{role:`presentation`}:{role:`menu`,"aria-orientation":p===`horizontal`?`horizontal`:void 0,"aria-labelledby":M},onKeyDown(e){N?.onPopupKeyDown?.(e),_&&Be.has(e.key)&&e.stopPropagation()},onFocus:R},We(y),c,{"data-rootownerid":ne}]}),V=E.type===void 0||P;(w||E.type===`menubar`&&te!==`outside-press`)&&(V=!0);let H=N?.getReturnElement??L;return(0,$.jsx)(C,{context:D,openInteractionType:oe,modal:P,disabled:!x,returnFocus:a??H??V,explicitReturnFocus:a===void 0&&H?!1:void 0,initialFocus:F,restoreFocus:!0,getInsideElements:E.type===void 0?()=>[l.context.beforeTriggerFocusGuardRef.current]:void 0,externalTree:E.type===`menubar`?void 0:O,previousFocusableElement:w,nextFocusableElement:E.type===void 0?l.context.triggerFocusTargetRef:void 0,beforeContentFocusGuardRef:l.context.beforeContentFocusGuardRef,children:B})}),_n={parentVirtualFocusRef:void 0,handleFocus:void 0};function vn(){return _n}var yn=Q.forwardRef(function(e,t){let n=Rt()?.Popup??gn;return(0,$.jsx)(n,{...e,ref:t})}),bn=Q.createContext(void 0);function xn(){let e=Q.useContext(bn);if(e===void 0)throw Error(ht(32));return e}var Sn=Q.forwardRef(function(e,t){let{keepMounted:n=!1,...r}=e,{store:i,parent:a}=Pt();if(!(i.useState(`mounted`)||n))return null;let o=a.type===`menu`||a.type===`menubar`?`group`:void 0;return(0,$.jsx)(bn.Provider,{value:n,children:(0,$.jsx)(le,{ref:t,...r,portalOwnerRole:o})})});function Cn(e){let{children:t,elementsRef:n,labelsRef:r,onMapChange:i}=e,a=z(i),[,o]=Q.useState(0),s=y(Tn).current,c=y(wn).current,l=Q.useRef(0),u=Q.useRef(!0),d=Q.useRef(null),f=Q.useRef(null),p=z(()=>{u.current||(u.current=!0,o(e=>e+1))}),m=z((e,t)=>{c.set(e,t),p()}),h=z(e=>{c.delete(e),p()}),g=z(e=>{let t=new Map;return n.current.length=0,r&&(r.current.length=0),e.forEach(e=>{t.set(e.element,{...e.registration.metadata??{},index:e.index}),n.current[e.index]=e.element,r&&(r.current[e.index]=e.registration.label===void 0?e.registration.textRef?.current?.textContent??e.element.textContent:e.registration.label)}),l.current=n.current.length,t});function _(e){if(f.current?.disconnect(),f.current=null,typeof MutationObserver!=`function`||e.length<2)return;let t=new MutationObserver(n=>{if(!On(n))return;let r=null;for(let n of e)if(n.isConnected){if(r&&kn(r,n)>0){t.disconnect(),p();return}r=n}});f.current=t;let n=new Set;for(let t=1;t<e.length;t+=1){let r=Dn(e[t-1],e[t]);r&&n.add(r)}n.forEach(e=>t.observe(e,{childList:!0}))}let v=z(()=>{let[e,t]=En(c),n=g(e),r=d.current,i=!r||r.length!==e.length||e.some((e,t)=>{let n=r[t];return e.index!==n.index||e.element!==n.element||e.registration.index!==n.registration.index||e.registration.metadata!==n.registration.metadata});_(t),d.current=e,u.current=!1,i&&(s.forEach(e=>e(n)),a(n))});A(()=>(!u.current&&d.current&&g(d.current),()=>{n.current=[],r&&(r.current=[])}),[n,r,g]),A(()=>{u.current&&v()}),A(()=>()=>{f.current?.disconnect(),u.current=!0},[]);let b=z(e=>(s.add(e),()=>{s.delete(e)})),x=Q.useMemo(()=>({register:m,unregister:h,subscribeMapChange:b,nextIndexRef:l}),[m,h,b,l]);return(0,$.jsx)(Jt.Provider,{value:x,children:t})}function wn(){return new Map}function Tn(){return new Set}function En(e){let t=new Set,n=[],r=[];e.forEach((e,i)=>{if(!i.isConnected)return;let a=e.index,o={index:a??-1,element:i,registration:e};a===null?r.push(o):a>=0&&(t.add(a),n.push(o))});let i=0;return r.sort((e,t)=>kn(e.element,t.element)),r.forEach(e=>{for(;t.has(i);)i+=1;e.index=i,n.push(e),i+=1}),t.size>0&&n.sort((e,t)=>e.index-t.index),[n,r.map(e=>e.element)]}function Dn(e,t){let n=e.parentElement;for(;n&&!n.contains(t);)n=n.parentElement;return n}function On(e){for(let t of e)for(let e=0;e<t.removedNodes.length;e+=1)if(t.removedNodes[e].isConnected)return!0;return!1}function kn(e,t){return e.nextElementSibling===t?-1:t.nextElementSibling===e?1:e.compareDocumentPosition(t)&Node.DOCUMENT_POSITION_FOLLOWING?-1:1}var An=Q.forwardRef(function(e,t){let{anchor:n,positionMethod:r=`absolute`,className:i,render:a,side:o,align:s,sideOffset:c=0,alignOffset:l=0,collisionBoundary:u=`clipping-ancestors`,collisionPadding:d=5,arrowPadding:f=5,sticky:p=!1,disableAnchorTracking:m=!1,collisionAvoidance:h=ue,style:g,..._}=e,{store:v,virtualFocus:y,syncHighlightedItem:b}=Pt(),x=xn(),ee=It(!0),S=v.useState(`parent`),C=v.useState(`floatingRootContext`),w=v.useState(`floatingTreeRoot`),T=v.useState(`mounted`),E=v.useState(`open`),te=v.useState(`modal`),ne=v.useState(`openMethod`),D=v.useState(`activeTriggerElement`),O=v.useState(`transitionStatus`),re=v.useState(`positionerElement`),ie=v.useState(`instantType`),ae=v.useState(`adaptiveOrigin`),oe=v.useState(`lastOpenChangeReason`),k=v.useState(`floatingNodeId`),A=v.useState(`floatingParentNodeId`),se=C.useState(`domReferenceElement`),M=n,N=c,P=l,F=s,I=h;S.type===`context-menu`&&(M=n??S.context?.anchor,F??=`start`,!o&&F!==`center`&&(P=e.alignOffset??2,N=e.sideOffset??-5));let L=o,R=F;S.type===`menu`?(L??=`inline-end`,R??=`start`,I=e.collisionAvoidance??j):S.type===`menubar`&&(L??=S.context.orientation===`vertical`?`inline-end`:`bottom`,R??=`start`);let z=S.type===`context-menu`,B=fe({anchor:M,floatingRootContext:C,positionMethod:ee?`fixed`:r,mounted:T,side:L,sideOffset:N,align:R,alignOffset:P,arrowPadding:z?0:f,collisionBoundary:u,collisionPadding:d,sticky:p,nodeId:k,keepMounted:x,disableAnchorTracking:m,collisionAvoidance:I,shift:z?{crossAxis:!(`side`in I&&I.side===`flip`),rootBoundary:`layoutViewport`}:void 0,externalTree:w,adaptiveOrigin:ae,lazyFlip:y?`placement`:!1});Q.useEffect(()=>{function e(e){e.open&&(e.parentNodeId===k&&v.set(`hoverEnabled`,!1),e.nodeId!==k&&e.parentNodeId===v.select(`floatingParentNodeId`)&&v.setOpen(!1,q(Ee)))}return w.events.on(`menuopenchange`,e),()=>{w.events.off(`menuopenchange`,e)}},[v,w.events,k]),Q.useEffect(()=>{if(v.select(`floatingParentNodeId`)==null)return;function e(e){if(e.open||e.nodeId!==v.select(`floatingParentNodeId`))return;let t=e.reason??`sibling-open`;v.setOpen(!1,q(t))}return w.events.on(`menuopenchange`,e),()=>{w.events.off(`menuopenchange`,e)}},[w.events,v]);let H=ft();Q.useEffect(()=>{E||H.clear()},[E,H]),Q.useEffect(()=>{function e(e){if(!(!E||e.nodeId!==v.select(`floatingParentNodeId`))){if(e.target&&D&&D!==e.target){let e=v.select(`closeDelay`);e>0?H.isStarted()||H.start(e,()=>{v.setOpen(!1,q(Ee))}):v.setOpen(!1,q(Ee))}else H.clear()}}return w.events.on(`itemhover`,e),()=>{w.events.off(`itemhover`,e)}},[w.events,E,D,v,H]),Q.useEffect(()=>{let e={open:E,nodeId:k,parentNodeId:A,reason:v.select(`lastOpenChangeReason`)};w.events.emit(`menuopenchange`,e)},[w.events,E,v,k,A]),Ae({store:v,domReference:se,positionerElement:re,open:E});let ce={open:E,side:B.side,align:B.align,anchorHidden:B.anchorHidden,nested:S.type===`menu`,instant:ie},U=S.type===`menubar`&&S.context.modal;Z(E&&(U||te&&oe!==`trigger-hover`),ne===`touch`,re,D);let W=Xe(e,ce,{styles:B.positionerStyles,transitionStatus:O,props:_,refs:[t,v.useStateSetter(`positionerElement`)],hidden:!T,inert:!E}),le=T&&S.type!==`menu`&&(S.type!==`menubar`&&te&&oe!==`trigger-hover`||S.type===`menubar`&&S.context.modal),G=null;return S.type===`menubar`?G=S.context.contentElement:S.type===void 0&&(G=D),(0,$.jsxs)(jt.Provider,{value:B,children:[le&&(0,$.jsx)(Se,{ref:S.type===`context-menu`||S.type===`nested-context-menu`?S.context.internalBackdropRef:null,inert:Ke(!E),cutout:G}),(0,$.jsx)(V,{id:k,children:(0,$.jsx)(Cn,{elementsRef:v.context.itemDomElements,labelsRef:v.context.itemLabels,onMapChange:b,children:W})})]})}),jn=Q.createContext(null);function Mn(e){let t=Q.useContext(jn);if(t===null&&!e)throw Error(ht(5));return t}function Nn(e){return e==null?Je:e.type.startsWith(`key`)?ye:e.type.startsWith(`mouse`)||e.type.startsWith(`pointer`)?ke:Je}var Pn={...he,disabled:e=>e.parent.type===`menubar`&&e.parent.context.disabled||e.disabled,modal:e=>(e.parent.type===void 0||e.parent.type===`context-menu`)&&(e.modal??!0),openMethod:e=>e.openMethod,keyboardOpen:e=>e.keyboardOpen,allowMouseEnter:e=>e.allowMouseEnter,highlightItemOnHover:e=>e.highlightItemOnHover,parent:e=>e.parent,rootId:e=>e.parent.type===`menu`?e.parent.store.select(`rootId`):e.parent.type===void 0?e.rootId:e.parent.context.rootId,activeIndex:e=>e.activeIndex,listElement:e=>e.listElement,triggerControlsId:(e,t)=>{let n=he.triggerPopupId(e,t);return n?e.listElement?.id||n:void 0},filterTriggerProps:e=>e.filterTriggerProps,inputProps:e=>e.inputProps,webkitAriaSelected:(e,t)=>et&&e.inputFocused&&t?!0:void 0,highlightedItemId:e=>e.highlightedItem?.id||void 0,isActive:(e,t)=>e.activeIndex===t,hoverEnabled:e=>e.hoverEnabled,instantType:e=>e.instantType===`trigger-change`&&!he.open(e)?void 0:e.instantType,lastOpenChangeReason:e=>e.openChangeReason,floatingTreeRoot:e=>e.parent.type===`menu`?e.parent.store.select(`floatingTreeRoot`):e.floatingTreeRoot,floatingNodeId:e=>e.floatingNodeId,floatingParentNodeId:e=>e.floatingParentNodeId,itemProps:e=>e.itemProps,closeDelay:e=>e.closeDelay,adaptiveOrigin:e=>e.adaptiveOrigin,keyboardEventRelay:e=>{if(e.keyboardEventRelay)return e.keyboardEventRelay;if(e.parent.type===`menu`)return e.parent.store.select(`keyboardEventRelay`)}},Fn=class extends dt{constructor(e,t,n=!1){let r=new ct,i=Ln(r,t,n,e);super(i,In(r),Pn),this.observe(`parent`,e=>{e.type===`menu`?this.context.allowMouseUpTriggerRef=e.store.context.allowMouseUpTriggerRef:e.type!==void 0&&(this.context.allowMouseUpTriggerRef=e.context.allowMouseUpTriggerRef)})}subscribeToParentMenu(){let e=this.state.parent;if(e.type!==`menu`)return;let t=e.store.select(`rootId`),n=e.store.select(`floatingTreeRoot`),r=e.store.select(`keyboardEventRelay`);return e.store.subscribe(()=>{let i=e.store.select(`rootId`),a=e.store.select(`floatingTreeRoot`),o=e.store.select(`keyboardEventRelay`);(t!==i||n!==a||r!==o)&&(t=i,n=a,r=o,this.notifyAll())})}setOpen(e,t){this.state.floatingRootContext.context.events.emit(`setOpen`,{open:e,eventDetails:t})}setActiveIndex(e,t,n){if(this.state.activeIndex!==e){let r=(e===null?void 0:this.context.itemDomElements.current[e])===this.context.reportedItem;this.context.highlightReason=r?`none`:t,this.context.highlightEvent=r?void 0:n}this.set(`activeIndex`,e)}highlightItem(e,t,n){let r=this.context.itemDomElements.current.indexOf(e);r>-1&&this.setActiveIndex(r,t,n)}};function In(e){return{positionerRef:Q.createRef(),popupRef:Q.createRef(),typingRef:{current:!1},itemDomElements:{current:[]},itemLabels:{current:[]},highlightReason:`none`,highlightEvent:void 0,reportedItem:void 0,allowMouseUpTriggerRef:{current:!1},virtualFocusRef:void 0,triggerFocusTargetRef:Q.createRef(),beforeTriggerFocusGuardRef:Q.createRef(),beforeContentFocusGuardRef:Q.createRef(),onOpenChangeComplete:void 0,triggerElements:e}}function Ln(e,t,n=!1,r){return{...mt(e,t,n),disabled:!1,modal:!0,openMethod:null,keyboardOpen:!1,allowMouseEnter:!1,highlightItemOnHover:!0,parent:{type:void 0},rootId:void 0,activeIndex:null,listElement:null,filterTriggerProps:m,inputProps:m,inputFocused:!1,highlightedItem:void 0,hoverEnabled:!0,instantType:void 0,openChangeReason:null,floatingTreeRoot:new te,floatingNodeId:void 0,floatingParentNodeId:null,itemProps:m,keyboardEventRelay:void 0,closeDelay:0,adaptiveOrigin:void 0,...r}}var Rn=Q.createContext(null);function zn(e,t){return(e===`trigger-press`||e===`item-press`)&&t?.detail===0}function Bn(e,t){return e===`list-navigation`||zn(e,t)}var Vn=F(function(e){let{children:t,open:n,onOpenChange:r,onOpenChangeComplete:i,onItemHighlighted:a,defaultOpen:o=!1,disabled:s=!1,modal:c,loopFocus:u=!0,orientation:f=`vertical`,actionsRef:p,closeParentOnEsc:h=!1,handle:b,triggerId:x,defaultTriggerId:S=null,highlightItemOnHover:C=!0,isSubmenu:w=!1,virtualFocus:T=!1,virtualFocusRef:E,allowEscape:te=!0,resetOnPointerLeave:D=!0}=e,re=It(!0),ae=Pt(!0),oe=Mn(!0),k=ae?.store,se=ae?.virtualFocus??!1,j=Q.useMemo(()=>w&&k?{type:`menu`,store:k}:oe?{type:`menubar`,context:oe}:re&&!k?{type:`context-menu`,context:re}:{type:void 0},[re,k,oe,w]),M=Ve(),N=Ve(),[P,F]=Q.useState(void 0),L=(P??N)||void 0,B=ne(),V=j.type===`menu`?j.store:void 0,H=(n??o)&&V?.state.transitionStatus===`starting`,ce=y(()=>H?V?.state.instantType:void 0).current,U=y(()=>{let e=new Fn({open:o,openProp:n,activeTriggerId:S,triggerIdProp:x,parent:j,disabled:s,highlightItemOnHover:C,modal:j.type===void 0?c:void 0,rootId:M,instantType:ce},L,B!=null);return e.context.virtualFocusRef=E,e}).current;U.useControlledProp(`openProp`,n),U.useControlledProp(`triggerIdProp`,x),U.useContextCallback(`onOpenChangeComplete`,i);let le=U.useState(`floatingTreeRoot`),ue=ee(le),G=U.useState(`open`),K=U.useState(`activeTriggerElement`),fe=U.useState(`positionerElement`),pe=U.useState(`hoverEnabled`),me=U.useState(`disabled`),he=U.useState(`lastOpenChangeReason`),J=U.useState(`parent`),ge=U.useState(`activeIndex`),_e=U.useState(`keyboardOpen`),ve=U.useState(`payload`),be=U.useState(`floatingParentNodeId`),xe=Q.useRef(null),Se=Q.useRef(J.type!==`context-menu`),Ce=ft(),we=Q.useRef(!0),Te=ft(),Y=be!=null,{openMethod:Ee,triggerProps:De}=Le(G);U.useSyncedValues({disabled:s,highlightItemOnHover:C,modal:J.type===void 0?c:void 0,openMethod:Ee,rootId:M}),l(U);let{forceUnmount:Oe,transitionStatus:ke}=Me(G,U,()=>{U.set(`allowMouseEnter`,!1)},H),Ae=O(U.context.popupRef);Q.useEffect(()=>{if(ce===void 0)return;let e=()=>{U.state.instantType===ce&&U.set(`instantType`,void 0)};if(!G){e();return}if(ke!==void 0)return;if(U.context.popupRef.current==null){e();return}let t=new AbortController;return Ae(e,t.signal),()=>{t.abort()}},[ce,G,ke,Ae,U]),A(()=>{re&&!ae?U.update({parent:{type:`context-menu`,context:re},floatingNodeId:ue,floatingParentNodeId:B}):(ae||!U.select(`activeTriggerElement`))&&U.update({floatingNodeId:ue,floatingParentNodeId:B})},[re,ae,ue,B,K,U]),Q.useEffect(()=>{if(G||(xe.current=null),J.type===`context-menu`){if(!G){Ce.clear(),Se.current=!1;return}Ce.start(500,()=>{Se.current=!0})}},[Ce,G,J.type]),A(()=>{!G&&!pe&&U.set(`hoverEnabled`,!0)},[G,pe,U]);let X=z((e,t)=>{let n=t.reason;if(!e&&!U.select(`open`)||G===e&&t.trigger===K&&he===n)return;let i=g(t);if(!e&&t.trigger==null&&(t.trigger=K??void 0),r?.(e,t),t.isCanceled)return;U.state.floatingRootContext.dispatchOpenChange(e,t);let a=t.event;if(e===!1&&n!==`item-press`&&a?.type===`click`&&a.pointerType===`touch`&&!we.current)return;e&&n===`trigger-focus`?(we.current=!1,Te.start(300,()=>{we.current=!0})):(we.current=!0,Te.clear());let o=!e&&(n===`escape-key`||n==null);xe.current=t.event;let s=Pe(U.state,e,t.trigger,i());s.openChangeReason=n,s.keyboardOpen=e&&Bn(n,a),s.instantType=J.type===`menubar`&&(n===`trigger-focus`||n===`focus-out`||n===`trigger-hover`||n===`list-navigation`||n===`sibling-open`)?`group`:zn(n,a)?`click`:o?`dismiss`:void 0,U.update(s)}),je=gt({popupStore:U,floatingRootContext:U.state.floatingRootContext,floatingId:L,nested:B!=null,onOpenChange:X}),Ne=je.context.events;A(()=>{let e=({open:e,eventDetails:t})=>X(e,t);return Ne.on(`setOpen`,e),()=>{Ne?.off(`setOpen`,e)}},[Ne,X]),A(()=>U.subscribeToParentMenu(),[U]);let Fe=Q.useCallback(()=>{U.setOpen(!1,q(ze))},[U]);Q.useImperativeHandle(p,()=>({unmount:Oe,close:Fe}),[Oe,Fe]);let Ie;J.type===`context-menu`&&(Ie=J.context),Q.useImperativeHandle(Ie?.positionerRef,()=>fe,[fe]),Q.useImperativeHandle(Ie?.actionsRef,()=>({setOpen:X}),[X]);let Re=d(je,{enabled:!me,bubbles:{escapeKey:h&&J.type===`menu`},outsidePress(){return J.type!==`context-menu`||xe.current?.type===`contextmenu`||Se.current},externalTree:Y?le:void 0}),Be=_(),Z=Ot(je,{enabled:!me,listRef:U.context.itemDomElements,activeIndex:ge,virtual:T,nested:J.type===`menubar`||!T&&J.type!==void 0,parentOrientation:J.type===`menubar`?J.context.orientation:void 0,loopFocus:u,focusItemOnOpen:T?_e:void 0,allowEscape:T&&u&&te,orientation:f,triggerOrientation:T?`vertical`:f,rtl:Be===`rtl`,disabledIndices:I,onNavigate(e,t){U.setActiveIndex(e,Nn(t),t?.nativeEvent)},openOnArrowKeyDown:J.type!==`context-menu`&&!(T&&w),externalTree:!T&&Y?le:void 0,nestedReturnFocusRef:V?.context.virtualFocusRef,focusItemOnHover:C,resetOnPointerLeave:D}),He=Q.useCallback(e=>{U.context.typingRef.current=e},[U]),Ue=kt(je,{enabled:!me&&!T,listRef:U.context.itemLabels,elementsRef:U.context.itemDomElements,activeIndex:ge,resetMs:500,onMatch:(e,t)=>{G&&e!==ge&&U.setActiveIndex(e,ye,t.nativeEvent)},onTyping:He}),We=z(a),Ge=Q.useRef(-1),Ke=z(()=>{let e=U.state.activeIndex,t=e===null?void 0:U.context.itemDomElements.current[e]??void 0;if(t?.isConnected===!1)return;let n=t===void 0?-1:e;if(Ge.current===n&&U.context.reportedItem===t)return;Ge.current=n,U.context.reportedItem=t,T&&U.set(`highlightedItem`,t);let{highlightReason:r,highlightEvent:i}=U.context;U.context.highlightReason=Je,U.context.highlightEvent=void 0,a&&We(t,pt(r,i,{label:t===void 0?void 0:U.context.itemLabels.current[n]??void 0}))});A(()=>{Ke()},[ge,Ke]);let qe=Q.useMemo(()=>{if(!T)return Z.reference;if(!Z.trigger)return m;let{onFocus:e,...t}=Z.trigger;return t},[T,Z.reference,Z.trigger]);U.useSyncedValue(`inputProps`,T?Z.reference??m:m);let Ye=Q.useMemo(()=>{let e=de(Ue.reference,qe,Re.reference,{onMouseMove(){U.set(`allowMouseEnter`,!0)}},De);return e[`aria-haspopup`]=`menu`,e[`aria-expanded`]=G,e},[U,Ue.reference,qe,Re.reference,De,G]),Xe=Q.useMemo(()=>{let e=de(Z.trigger,Re.trigger,De);return e[`aria-haspopup`]=`menu`,e[`aria-expanded`]=!1,e},[Z.trigger,Re.trigger,De]);y(()=>(U.update({inactiveTriggerProps:Xe}),null));let Ze=Q.useMemo(()=>de(R,{onMouseMove(){U.set(`allowMouseEnter`,!0),J.type===`menu`&&U.set(`hoverEnabled`,!1)},onClick(){U.select(`hoverEnabled`)&&U.set(`hoverEnabled`,!1)},onKeyDown(e){let t=U.select(`keyboardEventRelay`);t&&!e.isPropagationStopped()&&t(e)}},Ue.floating,Z.floating,Re.floating),[J.type,U,Ue.floating,Z.floating,Re.floating]),Qe=Z.item??m;ie(U,{floatingRootContext:je,activeTriggerProps:Ye,inactiveTriggerProps:Xe,popupProps:Ze,itemProps:Qe});let $e=Q.useMemo(()=>({store:U,parent:j,orientation:f,loopFocus:u,allowEscape:te,defaultFloatingId:N,setRenderedFloatingId:F,virtualFocus:T,parentVirtualFocus:se,syncHighlightedItem:Ke}),[U,j,f,u,te,N,T,se,Ke]),et=typeof t==`function`?t({payload:ve}):t,tt=(0,$.jsxs)(Nt.Provider,{value:$e,children:[b&&(0,$.jsx)(v,{handle:b,store:U}),et]});return(J.type===void 0||J.type===`context-menu`)&&(tt=(0,$.jsx)(W,{externalTree:le,children:tt})),tt});function Hn(e){let t=Q.useContext(Rn);if(t===null)return(0,$.jsx)(Vn,{...e});let n=t.Root;return(0,$.jsx)(Rn.Provider,{value:null,children:(0,$.jsx)(n,{...t.options,...e})})}var Un=5;function Wn(e,t){let n=Gn(t);return e.clientX>=n.left-Un&&e.clientX<=n.right+Un&&e.clientY>=n.top-Un&&e.clientY<=n.bottom+Un}function Gn(e){let t=e.getBoundingClientRect(),n=it(e);if(Ge)return t;let r=n.getComputedStyle(e,`::before`),i=n.getComputedStyle(e,`::after`);if(r.content===`none`&&i.content===`none`)return t;let a=parseFloat(r.width)||0,o=parseFloat(r.height)||0,s=parseFloat(i.width)||0,c=parseFloat(i.height)||0,l=Math.max(t.width,a,s),u=Math.max(t.height,o,c),d=l-t.width,f=u-t.height;return{left:t.left-d/2,right:t.right+d/2,top:t.top-f/2,bottom:t.bottom+f/2}}function Kn(e={}){let{highlightItemOnHover:t,highlightedIndex:n,onHighlightedIndexChange:r}=ut(),{ref:i,index:a}=Xt(e),o=n===a,s=Q.useRef(null),c=st(i,s);return{compositeProps:{tabIndex:o?0:-1,onFocus(){r(a)},onMouseMove(){let e=s.current;if(!t||!e)return;let n=e.hasAttribute(`disabled`)||e.ariaDisabled===`true`;!o&&!n&&e.focus()}},compositeRef:c,index:a}}function qn(e){let{render:t,className:n,style:r,state:i=m,props:a=I,refs:o=I,metadata:s,stateAttributesMapping:c,tag:l=`div`,...u}=e,{compositeProps:d,compositeRef:f}=Kn({metadata:s});return Y(l,e,{state:i,ref:[f,...o],props:[d,...a,u],stateAttributesMapping:c})}function Jn(e){if(Ce(e)&&e.hasAttribute(`data-rootownerid`))return e.getAttribute(`data-rootownerid`);if(!qe(e))return Jn(Re(e))}function Yn(e){let{enabled:t=!0,mouseDownAction:n,open:r}=e,i=Q.useRef(!1);return Q.useMemo(()=>t?{onMouseDown:e=>{(n===`open`&&!r||n===`close`&&r)&&(i.current=!0,Ie(e.currentTarget).addEventListener(`click`,()=>{i.current=!1},{once:!0}))},onClick:e=>{i.current&&(i.current=!1,e.preventBaseUIHandler())}}:m,[t,n,r])}var Xn=p(function(e,t){let{render:n,className:r,style:i,disabled:a=!1,nativeButton:o=!0,id:s,openOnHover:c,delay:l=100,closeDelay:u=0,handle:d,payload:f,...p}=e,h=Pt(!0),g=ot(d)??h?.store;if(!g)throw Error(ht(85));let _=Ve(s),v=g.useState(`isTriggerActive`,_),y=g.useState(`floatingRootContext`),x=g.useState(`isOpenedByTrigger`,_),S=g.useState(`triggerControlsId`,_),C=Q.useRef(null),w=Qn(),T=ut(!0),E=Ye(),O=Q.useMemo(()=>E??new te,[E]),re=ee(O),ie=ne(),{registerTrigger:ae,isMountedByThisTrigger:oe}=b(_,C,g,{payload:f,closeDelay:u,parent:w,floatingTreeRoot:O,floatingNodeId:re,floatingParentNodeId:ie,keyboardEventRelay:T?.relayKeyboardEvent}),k=w.type===`menubar`,A=g.useState(`disabled`),se=a||A||k&&w.context.disabled,{getButtonProps:j,buttonRef:M}=L({disabled:se,native:o});Q.useEffect(()=>{!x&&w.type===void 0&&(g.context.allowMouseUpTriggerRef.current=!1)},[g,x,w.type]);let N=Q.useRef(null),P=ft(),F=z(e=>{if(!N.current)return;P.clear(),g.context.allowMouseUpTriggerRef.current=!1;let t=e.target;X(N.current,t)||X(g.select(`positionerElement`),t)||t===N.current||(t==null||Jn(t)!==g.select(`rootId`))&&(Wn(e,N.current)||O.events.emit(`close`,{domEvent:e,reason:me}))});Q.useEffect(()=>{let e=Ie(N.current);if(x&&g.select(`lastOpenChangeReason`)===`trigger-hover`)return e.addEventListener(`mouseup`,F,{once:!0}),()=>{e.removeEventListener(`mouseup`,F)}},[x,F,g]);let I=k&&w.context.hasSubmenuOpen,R=Te(y,{enabled:(c??I)&&!se&&(!k||I&&!oe),handleClose:De({blockPointerEvents:!k}),mouseOnly:!0,move:!1,restMs:w.type===void 0?l:void 0,delay:{close:u},triggerElementRef:C,externalTree:O,isActiveTrigger:v,isClosing:()=>g.select(`transitionStatus`)===`ending`}),B=Zn(x,g.select(`lastOpenChangeReason`)),V=ce(y,{enabled:!se,event:x&&k?`click`:`mousedown`,toggle:!0,ignoreMouse:!1,stickIfOpen:w.type===void 0&&B}),H=xt(y,{enabled:!se&&I}),U=Yn({open:x,enabled:k,mouseDownAction:`open`}),W=Q.useMemo(()=>de(H.reference,V.reference),[H.reference,V.reference]),le=g.useState(`triggerProps`,oe),ue=g.useState(`filterTriggerProps`),{handlePreFocusGuardFocus:G,handleFocusTargetFocus:K}=tt(g,C),fe={disabled:se,open:x},pe=[N,t,M,ae,C],he=[W,R??m,le,{"aria-haspopup":`menu`,"aria-controls":S,id:_,onMouseDown:e=>{g.select(`open`)||(P.start(200,()=>{g.context.allowMouseUpTriggerRef.current=!0}),Ie(e.currentTarget).addEventListener(`mouseup`,F,{once:!0}))}},ue,k?{role:`menuitem`}:{},U,p,j],q=Y(`button`,e,{enabled:!k,stateAttributesMapping:D,state:fe,ref:pe,props:he});return k?(0,$.jsx)(qn,{tag:`button`,render:n,className:r,style:i,state:fe,refs:pe,props:he,stateAttributesMapping:D}):x?(0,$.jsxs)(Q.Fragment,{children:[(0,$.jsx)(rt,{ref:g.context.beforeTriggerFocusGuardRef,onFocus:G},`${_}-pre-focus-guard`),(0,$.jsx)(Q.Fragment,{children:q},_),(0,$.jsx)(rt,{ref:g.context.triggerFocusTargetRef,onFocus:K},`${_}-post-focus-guard`)]}):(0,$.jsx)(Q.Fragment,{children:q},_)});function Zn(e,t){let n=ft(),[r,i]=Q.useState(!1);return A(()=>{e&&t===`trigger-hover`?(i(!0),n.start(500,()=>{i(!1)})):e||(n.clear(),i(!1))},[e,t,n]),r}function Qn(){let e=Mn(!0);return Q.useMemo(()=>e?{type:`menubar`,context:e}:{type:void 0},[e])}var $n=Q.forwardRef(function(e,t){let{className:n,render:r,orientation:i=`horizontal`,style:a,...o}=e;return Y(`div`,e,{state:{orientation:i},ref:t,props:[{role:`separator`,"aria-orientation":i},o]})}),er=(0,Q.createContext)(null);function tr({actionsRef:e,children:t,interactionOwner:n=`local`,onOpenChange:r,...i}){let a=(0,Q.useRef)(null),o=e??a;return k(()=>o.current?.close()),(0,$.jsx)(er.Provider,{value:{actionsRef:o,interactionOwner:n},children:(0,$.jsx)(Hn,{...i,actionsRef:o,onOpenChange:(e,t)=>{if(n===`host`&&!e&&t.reason===`escape-key`){t.cancel(),t.allowPropagation();return}r?.(e,t)},children:t})})}function nr(){let e=(0,Q.useContext)(er);if(!e)throw Error(`DropdownMenu parts must be used inside <DropdownMenu>`);return e}var rr=(0,Q.forwardRef)(function({className:e,render:t,type:n=`button`,...a},o){return(0,$.jsx)(Xn,{...a,className:t=>r(`btn caps-dropdown-trigger`,i(e,t)),ref:o,render:t,type:n})}),ir=(0,Q.forwardRef)(function({container:e,...t},n){let r=Fe(`popover`);return e==null&&r===null?null:(0,$.jsx)(Sn,{...t,container:e??r,ref:n})}),ar=(0,Q.forwardRef)(function({collisionBoundary:e,...t},n){let r=Fe(`popover`);return(0,$.jsx)(An,{...t,collisionBoundary:e??(r&&r!==document.body?r:void 0),ref:n})}),or=(0,Q.forwardRef)(function({className:e,finalFocus:t,...n},a){let{interactionOwner:o}=nr(),s=(0,Q.useRef)(null);(0,Q.useImperativeHandle)(a,()=>s.current);let c=J(`.caps-dropdown-item[data-highlighted]`),l=(0,Q.useCallback)(e=>{s.current=e,c(e)},[c]);return(0,$.jsx)(yn,{...n,className:t=>r(`caps-dropdown-popup min-w-40 rounded-box border border-base-300 bg-base-100 p-xs shadow-lg outline-none`,i(e,t)),finalFocus:o===`host`?!1:t??!0,ref:l})}),sr=(0,Q.forwardRef)(function({align:e=`end`,alignOffset:t,children:n,container:r,keepMounted:i,side:a=`bottom`,sideOffset:o=4,...s},c){return(0,$.jsx)(ir,{container:r,keepMounted:i,children:(0,$.jsx)(ar,{align:e,alignOffset:t,side:a,sideOffset:o,children:(0,$.jsx)(or,{...s,ref:c,children:n})})})}),cr=`caps-dropdown-item flex w-full items-center gap-sm rounded-field px-md py-sm text-left text-sm outline-none transition-colors hover:bg-base-200 focus-visible:bg-base-200 aria-[current=page]:bg-base-200 aria-[current=page]:font-semibold disabled:cursor-not-allowed disabled:text-base-content/40 data-disabled:cursor-not-allowed data-disabled:text-base-content/40`,lr=(0,Q.forwardRef)(function({className:e,onClick:t,onSelect:n,variant:a=`default`,...o},s){return(0,$.jsx)(un,{...o,className:t=>r(cr,a===`destructive`&&`text-error hover:bg-error hover:text-error-content focus-visible:bg-error focus-visible:text-error-content`,i(e,t)),onClick:e=>{t?.(e),e.defaultPrevented||n?.(e)},ref:s})}),ur=(0,Q.forwardRef)(function({children:e,className:t,onClick:n,onSelect:a,...o},s){return(0,$.jsxs)(tn,{...o,className:e=>r(cr,i(t,e)),onClick:e=>{n?.(e),e.defaultPrevented||a?.(e)},ref:s,children:[(0,$.jsx)(`span`,{className:`min-w-0 flex-1`,children:e}),(0,$.jsx)(nn,{"aria-hidden":`true`,className:`shrink-0`,children:`✓`})]})}),dr=(0,Q.forwardRef)(function({className:e,...t},n){return(0,$.jsx)($n,{...t,className:t=>r(`my-xs h-px bg-base-300`,i(e,t)),ref:n})}),fr=sn,pr=(0,Q.forwardRef)(function({className:e,...t},n){return(0,$.jsx)(cn,{...t,className:t=>r(`px-md pb-xs pt-sm text-xs font-semibold text-base-content/60`,i(e,t)),ref:n})});export{lr as a,rr as c,fr as i,yt as l,ur as n,pr as o,sr as r,dr as s,tr as t,vt as u};
@@ -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 g,ot as _,v,w as y,x as b}from"./button-oE2Hrd5D.js";import{Mt as ne}from"./dist-DAokFn5x.js";import{r as x,s as S}from"./log-event-BfZxbz9a.js";import{a as C,i as w,m as T,t as E}from"./query-CYqgVHJ7.js";import{K as D,P as O,S as k,q as re,w as ie,z as A}from"./audio-waveform-8Le2_ags.js";import{c as j,d as M,l as ae,n as oe,o as se,s as ce,t as le}from"./textarea-DUwcxEMN.js";import{t as ue}from"./keycap-D2RkH2IS.js";function de(e,t){return re(e,T,t)}var fe=b(`ArrowUp`,[[`path`,{d:`m5 12 7-7 7 7`,key:`hav0vg`}],[`path`,{d:`M12 19V5`,key:`x0mq9r`}]]),pe=b(`ChevronUp`,[[`path`,{d:`m18 15-6-6-6 6`,key:`153udz`}]]),me=b(`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`}]]),he=b(`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`}]]),ge=b(`Square`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}]]),N={remove_background:`Remove background`,upscale:`Upscale`};function _e(e,t){return e.find(e=>e.transform?.operation===t)}function ve(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 ye(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 be(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:`${N.upscale} to ${String(t)} MP`,references:[i],targetMegapixels:t}}return{model:e.id,prompt:N[r.operation],references:[i]}}var xe=e=>{let t=e.lastIndexOf(`/`);return t<=0?`/`:e.slice(0,t)};function Se(e,t,n){let r=be(e,t,n),i={model:e.id,prompt:r.prompt,references:r.references??[],width:t.width,height:t.height},a=k(i,xe(t.path),e);return{input:{destination:{path:a},settings:r},draft:{...i,destination:a}}}var P={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 F(e,t,n){return e.require(D).call(t,n)}var I=t,Ce=t.pipe(u(h(1024))),we=y(Ce).pipe(u(h(200)));a({computerId:I}),a({computerId:I,keys:we});var Te=a({keys:we}),Ee=o(Te);async function De(e,t){return Ee(await F(e,P.readNotices,JSON.stringify({computerId:t})))}async function Oe(e,t,n){return Ee(await F(e,P.dismissNotices,JSON.stringify({computerId:t,keys:n})))}a({computerId:I,path:M});var ke=a({path:M,configured:c}),Ae=o(ke);async function je(e,t){return Ae(await F(e,P.readFolder,JSON.stringify({computerId:t})))}async function Me(e,t,n){return Ae(await F(e,P.selectFolder,JSON.stringify({computerId:t,path:n})))}var Ne=2048,Pe=8e3,Fe=[{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})),L=i.pipe(u(d(1)),u(h(64))),Ie=i.pipe(u(d(1)),u(h(Pe))),R=t,Le=a({id:r,name:L,text:Ie,builtIn:c});a({computerId:R,id:p(r),name:L,text:Ie}),a({computerId:R,id:r}),a({computerId:R,path:t});var Re=a({styles:y(Le).pipe(u(h(50+Fe.length)))}),ze=a({style:s(L)});function z(e,t){let n=t.trim();return e===void 0?n:`${e.trim()}\n\n${n}`}function Be(e){return e?.maxPromptLength??Ne}function Ve(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 B=o(Re);async function He(e,t){return B(await F(e,P.listStyles,JSON.stringify({computerId:t})))}async function Ue(e,t,n){return B(await F(e,P.saveStyle,JSON.stringify({computerId:t,id:n.id,name:n.name,text:n.text})))}async function We(e,t,n){return B(await F(e,P.deleteStyle,JSON.stringify({computerId:t,id:n})))}async function Ge(e,t,n){return o(ze)(await F(e,P.readPrintStyle,JSON.stringify({computerId:t,path:n})))}var V=/(?<![\p{L}\p{N}_@-])@image(\d+)(?![\p{L}\p{N}_-])/giu,H=e=>`image${String(e)}`;function U(e){let t=[];for(let n of e.matchAll(V)){let e=Number(n.at(1));t.includes(e)||t.push(e)}return t}var Ke=(e,t)=>JSON.stringify([e.computerId??t,e.path]),W={labels:new Map,next:1};function qe(e,t,n){let r=U(n).length>0;if(t.length===0)return e.labels.size===0&&(e.next===1||r)?e:r?{labels:new Map,next:e.next}:W;let i=e.labels.size>0&&t.every(t=>!e.labels.has(t))?W: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 Je(e,t){return t.map(t=>e.labels.get(t)??0)}function G(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 Ye(e,t,n){let r=[],i=e.replace(V,(e,i)=>{let a=t.indexOf(Number(i)),o=a<0?void 0:n.at(a);if(o===void 0){let t=H(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 Xe(e,t){return e.replace(V,(e,n)=>{let r=t(Number(n));return r===void 0||r<1?e:`@${H(r)}`})}var Ze=8,K=i.pipe(u(d(1)),u(h(32)),u(_(/^[\p{L}\p{N}_-]+$/u)),u(_(/^(?!image\d+$)/iu))),Qe=i.pipe(u(h(500))),$e=t.pipe(u(h(4096))),et=y(a({path:$e})).pipe(u(h(8))),tt=t,nt=a({id:r,name:K,description:Qe,references:et});a({computerId:tt,id:p(r),name:K,description:Qe,references:et}),a({computerId:tt,id:r});var rt=a({characters:y(nt).pipe(u(h(50)))}),q=(e,t)=>e.toLowerCase()===t.toLowerCase(),it=/(?<![\p{L}\p{N}_@-])@([\p{L}\p{N}_-]+)/gu;function at(e){let t=[];for(let n of e.matchAll(it)){let e=n.at(1);e!==void 0&&!t.some(t=>q(t,e))&&t.push(e)}return t}function J(e,t){let n=[];return{prompt:e.replace(it,(e,r)=>{let i=t.find(e=>q(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 ot(e,t,n){let r=e.trim();return z(t,J(r,n).prompt).length-r.length}function st(e,t){let n=at(e),r=t.filter(e=>!n.some(t=>q(t,e)));return r.length===0?e:`${r.map(e=>`@${e}`).join(` `)} ${e}`}function ct(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 lt(e){return{kind:`ready`,prompt:e,references:[],characters:[]}}function ut(e){let t=st(e.prompt,e.names??[]),n=J(t,e.saved),r=ct(e.references,n.characters,e.computerId),i=(e.wording??(e=>G(e,void 0)))(r),a=Ye(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:J(a.prompt,e.saved).prompt,references:r,characters:n.characters}}function dt(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 ft(e,t,n){let r=n.toLowerCase(),i=e=>H(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})),...pt(e,n).map(e=>({kind:`character`,character:e}))]}function pt(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,Ze)}var Y=o(rt);async function mt(e,t){return Y(await F(e,P.listCharacters,JSON.stringify({computerId:t})))}async function ht(e,t,n){return Y(await F(e,P.saveCharacter,JSON.stringify({computerId:t,id:n.id,name:n.name,description:n.description,references:n.references})))}async function gt(e,t,n){return Y(await F(e,P.deleteCharacter,JSON.stringify({computerId:t,id:n})))}var X={models:e=>w.of(e,`prints`,`models`),folder:e=>w.of(e,`prints`,`folder`),dismissals:e=>w.of(e,`prints`,`dismissals`),styles:e=>w.of(e,`prints`,`styles`),printStyle:(e,t)=>w.of(e,`prints`,`print-style`,t),characters:e=>w.of(e,`prints`,`characters`)};function _t(e){return{...E(e,x,X.models(e),async(t,n)=>{if(!e)throw Error(`Prints is disconnected`);let r=await S(e.capabilities);return n.throwIfAborted(),r}),enabled:!!(e?.context.get().computerId&&e.capabilities.has(x)),structuralSharing:!1}}function vt(e){let t=e?.context.get().computerId;return{...E(e,D,X.folder(e),async(n,r)=>{if(!e||!t)throw Error(`No Computer selected`);let i=await je(e.capabilities,t);if(r.throwIfAborted(),e.context.get().computerId!==t)throw new ne(`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{...E(e,D,X.dismissals(e),async(n,r)=>{if(!e||!t)throw Error(`No Computer selected`);let i=await De(e.capabilities,t);return r.throwIfAborted(),i}),enabled:!!(t&&e.capabilities.has(D))}}function bt(e){let t=e?.context.get().computerId;return{...E(e,D,X.styles(e),async(n,r)=>{if(!e||!t)throw Error(`No Computer selected`);let i=await He(e.capabilities,t);return r.throwIfAborted(),i}),enabled:!!(t&&e.capabilities.has(D))}}function xt(e,t){let n=e?.context.get().computerId;return{...E(e,D,X.printStyle(e,t??``),async(r,i)=>{if(!e||!n||t===null)throw Error(`No print selected`);let a=await Ge(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{...E(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)(ue,{...l,ref:d,className:v(`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)(fe,{"aria-hidden":`true`,size:r})}),(0,Q.jsx)(`span`,{"data-glyph":`busy`,children:t===void 0?(0,Q.jsx)(g,{decorative:!0,size:`sm`}):(0,Q.jsx)(ge,{"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)(se,{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)(j,{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:v(`list`,t===`compact`&&`list-sm`,e),ref:r})}),Ht=(0,Z.forwardRef)(function({className:e,...t},n){return(0,Q.jsx)(`li`,{...t,className:v(`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:v(`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:v(`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:v(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:v(`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:v(`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:v(`caps-card-title`,e),ref:r})}),(0,Z.forwardRef)(function({className:e,...t},n){return(0,Q.jsx)(`p`,{...t,className:v(`caps-card-description`,e),ref:n})}),(0,Z.forwardRef)(function({className:e,...t},n){return(0,Q.jsx)(`div`,{...t,className:v(`caps-card-content`,e),ref:n})}),(0,Z.forwardRef)(function({className:e,...t},n){return(0,Q.jsx)(`div`,{...t,className:v(`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:v(`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)(ce,{className:`parakeet-composer-anchor`,children:[a,(0,Q.jsxs)(Gt,{...s,className:v(`parakeet-composer-shell`,r),children:[(0,Q.jsx)(Kt,{action:t,attachments:e,input:i,toolbar:o===void 0?void 0:(0,Q.jsx)(oe,{className:`parakeet-composer-row`,align:`start`,items:o.items,openId:o.openId,onOpenChange:o.onOpenChange,renderTrigger:({children:e,...t})=>(0,Q.jsx)(ue,{...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:g,value:_}){let v=(0,Z.useRef)(null),y=(0,Z.useRef)(_),[b,ne]=(0,Z.useState)([]),[x,S]=(0,Z.useState)(-1),[C,w]=(0,Z.useState)(!1),T=(0,Z.useRef)(!1),E=(0,Z.useRef)(!1);y.current=_,(0,Z.useLayoutEffect)(()=>{if(C||i||!E.current)return;E.current=!1;let e=v.current;e&&e.ownerDocument.activeElement===e.ownerDocument.body&&e.focus({preventScroll:!0})},[i,C]),(0,Z.useLayoutEffect)(()=>{let t=v.current;!t||e?.value!==_||(t.setSelectionRange(e.caret,e.caret),t.focus({preventScroll:!0}))},[e,_]);let{cap:D,collapsed:O,fullscreen:k}=t;(0,Z.useLayoutEffect)(()=>{let e=v.current;if(!e)return;if(k){e.style.height=``,n(!1);return}e.style.height=`auto`;let t=e.scrollHeight;e.style.height=`${String(O?en(e):Math.min(t,D))}px`,n(!O&&t>D+1),O&&(e.scrollTop=0),O&&t>e.clientHeight+1?e.setAttribute(`data-clipped`,``):e.removeAttribute(`data-clipped`)},[_,D,O,k,n]),(0,Z.useLayoutEffect)(()=>{let e=v.current;!e||!k||(e.setSelectionRange(e.value.length,e.value.length),e.scrollTop=e.scrollHeight)},[k]);let re=(0,Z.useCallback)(async()=>{let e=y.current.trim();if(!(!e||i||T.current)){if(a!==void 0&&e.length+o>a){r($({addedLength:o,length:e.length+o,maxLength:a}));return}E.current=v.current===v.current?.ownerDocument.activeElement,T.current=!0,w(!0);try{if(!await m())return;ne(t=>t.at(-1)===e?t:[...t,e].slice(-20)),S(-1)}finally{T.current=!1,w(!1)}}},[i,a,r,m,o]),ie=_.trim().length,A=ie>0?ie+o:0,j=a!==void 0&&A>a,M=a!==void 0&&A>=Math.floor(a*$t);return(0,Q.jsxs)(`div`,{className:`relative min-w-0 flex-1`,children:[(0,Q.jsx)(le,{"aria-invalid":j?!0:void 0,"aria-label":`Prompt`,className:`w-full`,"data-generation-prompt":!0,"data-counting":M?``:void 0,...zt(s),disabled:i===!0||C,onChange:e=>{u(e.currentTarget.value),l(e.currentTarget.selectionStart),S(-1)},onScroll:e=>{O&&(e.currentTarget.scrollTop=0)},onSelect:e=>{l(e.currentTarget.selectionStart)},onKeyDown:e=>{if(ae(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(_.startsWith(`/`)&&t!==null&&(g>0||t===`dismiss`||e.key===`Enter`)){if(e.preventDefault(),t===`dismiss`)u(_.slice(1));else if(g)t===`next`?h(1):t===`previous`?h(-1):ee();else return;return}if(e.key===`Enter`&&!e.shiftKey){e.preventDefault(),re();return}if(e.key===`ArrowUp`&&v.current?.selectionStart===0&&b.length&&(x===-1||x>0)){e.preventDefault();let t=x===-1?b.length-1:x-1;S(t),u(b[t]);return}if(e.key===`ArrowDown`&&x!==-1){e.preventDefault();let t=x+1;t>=b.length?(S(-1),u(``)):(S(t),u(b[t]))}},placeholder:te,ref:v,style:{maxHeight:k?void 0:D},rows:1,value:_}),M?(0,Q.jsxs)(`p`,{className:`prints-prompt-counter ${j?`text-error`:`text-dim`}`,"data-prompt-counter":!0,id:Zt,role:`status`,title:j?$({addedLength:o,length:A,maxLength:a}):void 0,children:[`${String(A)} / ${String(a)}`,j?(0,Q.jsxs)(`span`,{className:`sr-only`,children:[` `,$({addedLength:o,length:A,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:H(t.reference.number),label:`@${H(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`?H(e.reference.number):e.character.name;function sn(e,t,n,r){return at(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:dt(n,r),f=d?ft(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)(W),a=e.map(e=>Ke(e,n)),o=qe(r,a,t);return o!==r&&i(o),Je(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=U(t.prompt).length>0,i=n.kind===`audio`?lt(t.prompt):ut({prompt:t.prompt,saved:e.characters,references:t.references,labels:e.labels,wording:e=>G(O(e,n,r),n),computerId:e.computerId,model:{label:n.label,maxReferences:n.input.maxReferences}});if(i.kind===`refused`)return null;let a=O(i.references,n,r),o={...t,prompt:z(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:ie(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 C({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=de(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{ve as $,J as A,Ve as B,xt as C,ot as D,bt as E,H as F,Me as G,Ue as H,G as I,N as J,F as K,Xe as L,ut as M,ht as N,K as O,U as P,be as Q,z as R,yt as S,St as T,L as U,Be as V,Oe as W,_e as X,Se as Y,ye as Z,Ut as _,tn as a,vt as b,nn as c,rn as d,ge as et,ln as f,Vt as g,Jt as h,Qt as i,de as it,lt as j,gt as k,sn as l,Xt as m,gn as n,me as nt,an as o,un as p,P as q,hn as r,pe as rt,cn as s,fn as t,he as tt,$ as u,Ht as v,X as w,_t as x,wt as y,We as z};