PageSourceSearch

https://tesana.com/assets/StudioPage-BpXFDIPL.js

js tesana.com collected 2026-10-09 22:40:24 UTC 469,036 bytes, 241 lines download raw bytes

1const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ModelOrbitViewer-B5v3ssr6.js","assets/vendor-motion-hRg_q8lq.js","assets/vendor-react-E98sgxjj.js","assets/vendor-fa-Bn2dnpnC.js","assets/ViewerScene-R0lCmUu4.js","assets/vendor-three-Cz2JVrfJ.js","assets/index-BKzE8EQ8.js","assets/vendor-query-bOUN_gKe.js","assets/index-36zER57x.css","assets/Grid-CXpTWUo7.js","assets/Gltf-kFBePvvf.js","assets/useAnimations-CPqp3P7o.js","assets/ThirdPersonViewer-D-wJ2WG7.js","assets/ImagePreview-DlhLxFM_.js","assets/AudioPreview-Br79jIjx.js","assets/MonacoPane-DpdRQGtV.js","assets/useGameVolume-DDLs3th3.js","assets/StudioContext-C1fnzqLL.js","assets/useLocaleNavigate-BNriJdRU.js","assets/useOrchestrationEnabled-BWYxrOff.js","assets/paywall-CG7xVZtx.js","assets/plansApi-C_2vGYRm.js","assets/planChat-Cir7UVv6.js","assets/useFullscreen-Cs7diftf.js","assets/Tooltip-C8AvPGtA.js","assets/VolumeControl-DJ2K5ohZ.js","assets/screenshotStore-B6ItflPb.js","assets/reveal-De4EoCkr.js","assets/ChatPanel-YMYP4TKG.js","assets/Markdown-BgzYVg9N.js","assets/StreamingWords-Ds3Ch0UQ.js","assets/index-DtA29OOy.js","assets/index-Cq7f-X06.js","assets/useHasCredits-D0Kot1Ju.js","assets/LoopBudgetModal-MJKH0M3w.js","assets/useIsMaxTier-CA74KWZY.js","assets/useDevModelsVisible-BHgONHQI.js","assets/plans-CbMJY2XS.js","assets/index-i1nPji9k.js","assets/pricingExperiments-zMZby8z7.js","assets/organization-BuGhuc22.js","assets/index-DoPwtVAc.js","assets/ActivityGrid-DDQeSjer.js","assets/GamePreview-DXVKEh7P.js","assets/GameFrame-COJWxWBt.js","assets/index-BxtVm1Yj.js","assets/exploreHandoff-RQymaHkp.js","assets/AuthShell-DPeun0C_.js","assets/AuthPanel-B4zt6SJ5.js","assets/pendingReferral-B4JPXhl_.js","assets/LaunchPromoClips-eRoWsyBt.js","assets/CoinTopUpModal-CAwRJTIr.js","assets/makeCopy-DTZjoJnY.js","assets/useIsStaff-DZf24Ivp.js","assets/useIsPaid-Cw2jGyd_.js","assets/SiteBanner-DKwegxEe.js","assets/MakeCopy-DWExybqc.js","assets/SubmitVideoModal-DzX5MAqQ.js","assets/PayoutCountryModal-MHoRKH3v.js","assets/earnProgram-B9pqjKbP.js","assets/usePublishingFeatures-C8zY31rs.js","assets/SharingScopePicker-CajJSJS_.js","assets/OrgScopeLabel-C9yeV7Fb.js","assets/useVisibilityControl-m_534sCR.js","assets/ShareModal-YOmfr9ti.js","assets/trailerShare-BGlMG0RV.js","assets/useReleases-n_bF3yQQ.js","assets/PlanPreviewCard-C70rpRPP.js","assets/PlayingNowBadge-CH2HUoBo.js","assets/playingNowApi-CB_pr25U.js","assets/RecentGamesList-C-KNAh2e.js","assets/UserAvatarMenu-BoKKInby.js","assets/Avatar-B60wpoS5.js","assets/MediaImage-DKgx-nW4.js","assets/useCanUseDesktopApp-CjJ0K-dR.js","assets/DesktopGamePanel-BehZ5Jia.js","assets/useExperiment-DuA8vjwk.js","assets/usePlayFeatures-C6KNVcgO.js","assets/usePlayingNow-D0BSBy1C.js","assets/useChatUnread-BF3F7z48.js","assets/useGameChatSocket-Ca57ylO8.js","assets/chatRoomStore-oLAeRb02.js","assets/event-CnyWr2tN.js","assets/core-DhEqZVGG.js","assets/PlayablePreview-9BS6jErK.js","assets/libraryAssets-BbcE5eh7.js","assets/index-B_kJqugV.js","assets/planPerks-uEcgEuVc.js","assets/socialLinks-DmmZmq5v.js","assets/vanitySite-BtpHcDVO.js","assets/PlayPanelHost-DZaYs6Qz.js","assets/useFocusTrap-BzqZufCW.js","assets/playIntent-BFBGkqRe.js","assets/chatReturn-BikAGK6w.js","assets/ChatPanel-CprUFb98.js"])))=>i.map(i=>d[i]);
2import{u as Ee,d as me,s as Ce,_ as Ye,c as Rt,b as Ut,de as qi,b0 as la,dx as Qi,aO as on,l as Ft,L as vt,a0 as Ji,o as ca,R as da,n as Yt,aU as Zi,$ as ua,dy as el,dz as tl,T as _t,x as Xt,C as fa,V as rl,dA as nl,a1 as gr,a5 as ma,cv as sl,dB as eo,dC as to,dD as ol,dE as al,dF as il,dG as Ln,dH as On,dI as ll,J as cl,aq as Br,a9 as dl,dJ as ul,dK as fl,v as At,bm as ha,bn as pa,bo as ga,aN as ml,dL as hl,bB as pl,b1 as Gn,ac as ro,dM as gl,bM as Vr,H as xl,Z as bl,b_ as vl}from"./index-BKzE8EQ8.js";import{j as r,A as lt,m as Be}from"./vendor-motion-hRg_q8lq.js";import{r as f,i as xa,R as qt,a as ba,b as yl,d as wl}from"./vendor-react-E98sgxjj.js";import{R as at,S as va,O as ya,T as ms,U as wa,h as ja,e as jl,V as kl,k as Nl,q as Sl,j as _l,L as Cl,W as El,X as Tl}from"./StudioContext-C1fnzqLL.js";import{c as wt,i as no,d as Ml,H as Al,e as Pl,j as Dl,u as Rl,b as ka,f as Na,g as Sa,E as Ul,S as Fl,N as 
2Ll}from"./useGameVolume-DDLs3th3.js";import{b as Ol,E as Gl,a as _a,S as Il,r as jr,u as mn}from"./reveal-De4EoCkr.js";import{a as Ca,b as Ea,P as Ta,D as Ma,c as Bl,d as Vl,h as zl,e as Wl,f as Hl,C as Kl,p as Yl,g as Aa,i as Xl,r as $l,j as ql}from"./ChatPanel-YMYP4TKG.js";import{R as Ql,G as Pa,a as Jl}from"./GamePreview-DXVKEh7P.js";import{u as Da}from"./useLocaleNavigate-BNriJdRU.js";import{u as mt,b as er,a as Qt}from"./vendor-query-bOUN_gKe.js";import{du as H,hM as Zl,bG as hs,bH as ps,bz as gs,a9 as ec,al as tc,bE as rc,bF as nc}from"./vendor-fa-Bn2dnpnC.js";import{m as sc}from"./makeCopy-DTZjoJnY.js";import{m as oc}from"./pricingExperiments-zMZby8z7.js";import{u as ac}from"./useIsStaff-DZf24Ivp.js";import{u as ic}from"./useIsPaid-Cw2jGyd_.js";import{g as lc,i as cc,R as dc,d as uc}from"./useHasCredits-D0Kot1Ju.js";import{P as tt,a as so,b as oo}from"./paywall-CG7xVZtx.js";import{G as fc,N as mc,S as hc}from"./SiteBanner-DKwegxEe.js";import{u as pc,M as gc}from"./MakeCopy-DWExybqc.js";import{S as xc}from"./SubmitVideoModal-DzX5MAqQ.js";import{P as bc}from"./PayoutCountryModal-MHoRKH3v.js";import{E as vc}from"./earnProgram-B9pqjKbP.js";import{b as yc,c as ao,V as wc}from"./usePublishingFeatures-C8zY31rs.js";import{C as jc,S as kc,u as Nc}from"./SharingScopePicker-CajJSJS_.js";import{O as io}from"./OrgScopeLabel-C9yeV7Fb.js";import{u as Sc,V as _c}from"./useVisibilityControl-m_534sCR.js";import Ra from"./ShareModal-YOmfr9ti.js";import{O as Cc,r as Ec,c as Tc,d as Mc,e as Ac,s as Pc,R as Ua,a as hn,f as Fa,v as Dc,L as La,b as Rc,N as Uc,g as lo,h as co,i as zr,j as Fc,U as Lc}from"./useReleases-n_bF3yQQ.js";import{M as Oa}from"./Markdown-BgzYVg9N.js";import{a as Ga,g as Lt,b as xs}from"./index-DoPwtVAc.js";import{u as Oc,f as Ia,g as Ba,a as Va,b as za,s as Wa,S as Ha,B as Gc,H as Ka,c as Ic,A as Bc,d as Ya,e as Vc,h as zc,i as Xa,j as Wc,k as Hc,l as Kc,P as Yc}from"./PlanPreviewCard-C70rpRPP.js";import{T as Ke}from"./Tooltip-C8AvPGtA.js";import{b as Ct,aj as Pt,ak as Xc,g as $c,al as qc,U as Qc,am as Jc,f as kr,I as Zc,h as Re,V as Ae,an as $a,ao as an,ap as ed,aq as td,B as bs,ar as rd,T as nd,q as ln,as as sd,at as uo,au as Zt,P as vs,c as Ge,av as od,W as ad,t as id,aw as ld,F as cd,ax as dd,O as cn,r as ud,a9 as fd,af as md,C as hd,ay as pd,u as ys,ac as ws,$ as js,az as dn,aA as gd,aB as In,ag as fo,aC as Wr}from"./vendor-three-Cz2JVrfJ.js";import{_ as st,G as xd}from"./Grid-CXpTWUo7.js";import{u as bd}from"./Gltf-kFBePvvf.js";import{P as vd}from"./PlayingNowBadge-CH2HUoBo.js";import{u as yd}from"./organization-BuGhuc22.js";import{R as wd}from"./RecentGamesList-C-KNAh2e.js";import{U as jd}from"./UserAvatarMenu-BoKKInby.js";import{U as qa}from"./index-i1nPji9k.js";import"./plans-CbMJY2XS.js";import{G as kd}from"./GameFrame-COJWxWBt.js";import{C as Nd}from"./CoinTopUpModal-CAwRJTIr.js";import{u as Sd}from"./useCanUseDesktopApp-CjJ0K-dR.js";import{D as _d}from"./DesktopGamePanel-BehZ5Jia.js";import{u as Cd}from"./useExperiment-DuA8vjwk.js";import{u as Ed}from"./usePlayFeatures-C6KNVcgO.js";import{u as Td}from"./usePlayingNow-D0BSBy1C.js";import{u as Md}from"./useChatUnread-BF3F7z48.js";const Ad=5e3,Bn=4;function Pd({open:e,onClose:t,controls:i}){const{t:c,i18n:s}=Ee("releases",{useSuspense:!1}),n=f.useId(),o=i.gameId??0,a=s?.language||"en",l=mt({queryKey:Tc.owner(o),queryFn:()=>Ec.ownerList(o),enabled:e&&!!i.gameId,staleTime:Cc,refetchInterval:S=>e&&S.state.data?.releases?.some(T=>T.notes_status==="pending")?Ad:!1}),d=Mc(o,i.publicId),u=Ac(o,i.publicId),[m,h]=f.useState(null),[p,g]=f.useState(null),b=l.data,x=b?Pc(b.releases??[]):[],w=i.status,v=w?.liveNumber??b?.live_release_number??null,N=!!w?.hasUnpublished&&!i.isPublishing,y=b?.unpublished_versions??[],k=()=>{g(null),h(null),t()};return r.jsxs(Ua,{open:e,onClose:k,labelledBy:n,children:[r.jsxs("header",{className:"flex shrink-0 items-start justify-between gap-4 border-b border-border px-5 pb-4 pt-3 md:px-6 md:pt-5",children:[r.jsxs("div",{className:"min-w-0",children:[r.jsx("h2",{id:n,className:"text-lg font-medium leading-7 text-foreground",children:c("modal.title")}),r.jsx("p",{className:"mt-0.5 text-sm text-muted-foreground",children:v!=null?c("studio.playersSee",{number:hn(v,a)}):c("studio.playersSeeLatest")})]}),r.jsx("button",{type:"button",onClick:k,"aria-label":c("modal.close"),"data-autofocus":"",className:"-mr-2 flex size-9 shrink-0 cursor-pointer items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-foreground
2/5 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",children:r.jsx(H,{icon:["far","xmark"],className:"text-base","aria-hidden":!0})})]}),r.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto overscroll-contain px-5 py-4 md:px-6 md:py-5",children:[N&&r.jsxs("section",{"aria-label":c("modal.unpublishedTitle"),className:"mb-5 rounded-md border border-accent/25 bg-accent/6 p-4","data-unpublished-summary":"",children:[r.jsxs("p",{className:"flex items-center gap-2 text-sm font-medium text-foreground",children:[r.jsx("span",{"aria-hidden":"true",className:"size-1.5 shrink-0 rounded-full bg-accent"}),c("modal.unpublishedTitle")]}),y.length>0&&r.jsxs("ul",{className:"mt-2.5 space-y-1.5",children:[y.slice(0,Bn).map(S=>r.jsxs("li",{className:"flex items-baseline gap-3 text-sm leading-5",children:[r.jsx("span",{className:"min-w-0 flex-1 break-words text-foreground/90",children:S.summary||c("modal.unnamedChange")}),r.jsx("time",{dateTime:S.created_at,className:"shrink-0 text-xs text-muted-foreground",children:Fa(S.created_at,a)})]},S.number)),y.length>Bn&&r.jsx("li",{className:"text-xs text-muted-foreground",children:c("modal.moreChanges",{count:y.length-Bn})})]}),r.jsxs("button",{type:"button",onClick:i.publish,className:"mt-3.5 inline-flex h-9 w-full cursor-pointer items-center justify-center gap-2 rounded-md bg-foreground px-4 sm:w-auto text-sm font-medium text-background transition-opacity hover:opacity-80 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-card",children:[r.jsx(H,{icon:["far","rocket-launch"],className:"text-xs","aria-hidden":!0}),c("studio.publish")]})]}),l.isPending&&e?r.jsx(Dd,{label:c("modal.loading")}):l.isError&&!b?r.jsxs("div",{role:"alert",className:"py-10 text-center",children:[r.jsx("p",{className:"text-sm text-muted-foreground",children:c("modal.loadFailed")}),r.jsx("button",{type:"button",onClick:()=>void l.refetch(),className:"mt-3 h-8 cursor-pointer rounded-md bg-foreground
2/8 px-3 text-xs text-foreground hover:bg-foreground/12",children:c("modal.retry")})]}):x.length===0?r.jsxs("div",{className:"flex flex-col items-center px-4 py-12 text-center","data-releases-empty":"",children:[r.jsx("span",{className:"flex size-11 items-center justify-center rounded-full bg-foreground/6 text-muted-foreground",children:r.jsx(H,{icon:["far","clock-rotate-left"],className:"text-base","aria-hidden":!0})}),r.jsx("p",{className:"mt-3 text-sm font-medium text-foreground",children:c("modal.empty")}),r.jsx("p",{className:"mt-1 max-w-[280px] text-xs leading-5 text-muted-foreground",children:c("modal.emptyHint")})]}):r.jsx("ol",{className:"divide-y divide-border","aria-label":c("modal.listLabel"),children:x.map(S=>r.jsx(Rd,{release:S,language:a,t:c,editing:p===S.number,onEdit:()=>g(S.number),onCancelEdit:()=>g(null),onSave:T=>{u.mutate({number:S.number,notes:T}),g(null)},onMakeLive:()=>h(S.number),switching:d.isPending&&d.variables===S.number},S.number))})]}),r.jsx(Fd,{number:m,language:a,t:c,onCancel:()=>h(null),onConfirm:S=>{h(null),d.mutate(S)}})]})}function Dd({label:e}){return r.jsx("div",{role:"status","aria-label":e,className:"divide-y divide-border",children:[0,1,2].map(t=>r.jsxs("div",{"aria-hidden":"true",className:"space-y-2.5 py-4",children:[r.jsx("div",{className:"h-3.5 w-28 animate-pulse rounded-sm bg-foreground
2/8"}),r.jsx("div",{className:"h-3 w-4/5 animate-pulse rounded-sm bg-foreground/6"}),r.jsx("div",{className:"h-3 w-3/5 animate-pulse rounded-sm bg-foreground/6"})]},t))})}function Rd({release:e,language:t,t:i,editing:c,onEdit:s,onCancelEdit:n,onSave:o,onMakeLive:a,switching:l}){const d=Dc(e),u=e.notes_status==="pending"&&d.length===0,m=i("version",{number:hn(e.number,t)}),h=f.useId();return r.jsxs("li",{className:"py-4 first:pt-1 last:pb-1","aria-labelledby":h,"data-release":e.number,children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("h3",{id:h,className:"text-sm font-medium text-foreground",children:m}),e.is_live&&r.jsx(La,{}),r.jsx("time",{dateTime:e.published_at,className:"ml-auto shrink-0 text-xs text-muted-foreground",children:Fa(e.published_at,t)})]}),c?r.jsx(Ud,{initial:d,version:m,t:i,onCancel:n,onSave:o}):r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"mt-2",children:u?r.jsx(Rc,{}):d.length>0?r.jsx(Uc,{notes:d,size:"md"}):r.jsx("p",{className:"text-sm italic text-muted-foreground",children:i("modal.noNotes")})}),r.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-2",children:[r.jsxs("button",{type:"button",onClick:s,"aria-label":i("modal.editNotesFor",{version:m}),"data-edit-notes":"",className:"-ml-2 inline-flex h-7 cursor-pointer items-center gap-1.5 rounded-md px-2 text-xs text-muted-foreground transition-colors hover:bg-foreground
2/6 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",children:[r.jsx(H,{icon:["far","pen"],className:"text-[10px]","aria-hidden":!0}),d.length>0?i("modal.editNotes"):i("modal.addNotes")]}),!e.is_live&&r.jsxs("button",{type:"button",onClick:a,disabled:l,"aria-label":i("modal.makeLiveFor",{version:m}),"data-make-live":"",className:"inline-flex h-7 cursor-pointer items-center gap-1.5 rounded-md bg-foreground/6 px-2.5 text-xs text-foreground transition-colors hover:bg-foreground/10 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-default disabled:opacity-50",children:[r.jsx(H,{icon:["far","clock-rotate-left"],className:"text-[10px]","aria-hidden":!0}),i("modal.makeLive")]})]})]})]})}function Ud({initial:e,version:t,t:i,onCancel:c,onSave:s}){const[n,o]=f.useState(()=>Array.from({length:lo},(g,b)=>e[b]??"")),a=f.useRef(null);f.useEffect(()=>{a.current?.focus()},[]);const l=co(n),d=l.join(`
3`)===co(e).join(`
4`),u=l.length>0&&!d,m=f.useId(),h=()=>{u&&s(l)},p=g=>{g.key==="Enter"?(g.preventDefault(),h()):g.key==="Escape"&&(g.preventDefault(),g.stopPropagation(),c())};return r.jsxs("div",{role:"group","aria-labelledby":m,className:"mt-2.5","data-notes-editor":"",children:[r.jsx("p",{id:m,className:"sr-only",children:i("modal.editNotesFor",{version:t})}),r.jsx("div",{className:"space-y-1.5",children:n.map((g,b)=>{const x=zr-g.length;return r.jsxs("div",{className:"relative flex items-center",children:[r.jsx("span",{"aria-hidden":"true",className:"pointer-events-none absolute left-3 size-1 rounded-full bg-muted-foreground"}),r.jsx("input",{ref:b===0?a:void 0,type:"text",value:g,maxLength:zr,onChange:w=>{const v=[...n];v[b]=w.target.value,o(v)},onKeyDown:p,"aria-label":i("modal.noteLine",{n:b+1}),placeholder:b===0?i("modal.notePlaceholder"):"",className:"h-9 w-full rounded-md border border-border bg-foreground
4/[0.03] pl-6 pr-12 text-sm text-foreground placeholder:text-muted-foreground/60 focus:border-foreground/40 focus:outline-none"}),g.length>=zr-20&&r.jsx("span",{"aria-live":"polite",className:me("pointer-events-none absolute right-3 text-[10px] tabular-nums",x<=5?"text-accent":"text-muted-foreground"),children:x})]},b)})}),r.jsx("p",{className:"mt-1.5 text-[11px] leading-4 text-muted-foreground",children:i("modal.notesHint",{lines:lo,chars:zr})}),r.jsxs("div",{className:"mt-2.5 flex items-center gap-2",children:[r.jsx("button",{type:"button",onClick:h,disabled:!u,"data-save-notes":"",className:"h-8 cursor-pointer rounded-md bg-foreground px-3 text-xs font-medium text-background transition-opacity hover:opacity-80 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-card disabled:cursor-default disabled:opacity-30",children:i("modal.save")}),r.jsx("button",{type:"button",onClick:c,className:"h-8 cursor-pointer rounded-md px-3 text-xs text-muted-foreground transition-colors hover:bg-foreground
4/6 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",children:i("modal.cancel")})]})]})}function Fd({number:e,language:t,t:i,onCancel:c,onConfirm:s}){const n=f.useId(),o=f.useId(),a=f.useRef(null);e!=null&&(a.current=e);const l=a.current,d=l!=null?hn(l,t):"";return r.jsx(Ua,{open:e!=null,onClose:c,labelledBy:n,describedBy:o,role:"alertdialog",variant:"confirm",zIndex:1010,children:r.jsxs("div",{className:"p-5 md:p-6","data-make-live-confirm":"",children:[r.jsx("h2",{id:n,className:"text-base font-medium text-foreground",children:i("confirm.title",{number:d})}),r.jsx("p",{id:o,className:"mt-2 text-sm leading-5 text-muted-foreground",children:i("confirm.body",{number:d})}),r.jsxs("div",{className:"mt-5 flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",children:[r.jsx("button",{type:"button",onClick:c,"data-autofocus":"",className:"h-9 cursor-pointer rounded-md bg-foreground/6 px-4 text-sm text-foreground transition-colors hover:bg-foreground/10 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",children:i("confirm.cancel")}),r.jsx("button",{type:"button",onClick:()=>{e!=null&&s(e)},"data-confirm-make-live":"",className:"h-9 cursor-pointer rounded-md bg-foreground px-4 text-sm font-medium text-background transition-opacity hover:opacity-80 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-card",children:i("confirm.confirm",{number:d})})]})]})})}function Ld({controls:e,onSeeAll:t}){const{t:i,i18n:c,ready:s}=Ee("releases",{useSuspense:!1}),n=f.useId(),o=f.useId(),a=f.useId(),{status:l,available:d,isPublishing:u,isSavingMode:m}=e;if(!d||!l||!s)return null;const h=l.mode==="auto",p=c?.language||"en";return r.jsxs("section",{"aria-labelledby":n,className:"border-b border-border px-4 py-3","data-release-updates":"",children:[r.jsxs("div",{className:"mb-2 flex items-center justify-between",children:[r.jsx("h3",{id:n,className:"text-xs font-normal text-muted-foreground",children:i("studio.title")}),r.jsx("button",{type:"button",onClick:t,className:"cursor-pointer text-[10px] text-accent hover:underline focus-visible:underline focus-visible:outline-none",children:i("studio.seeAll")})]}),r.jsxs("div",{className:"flex min-h-5 items-center gap-2",children:[r.jsx("p",{className:"min-w-0 truncate text-sm text-foreground",children:l.liveNumber!=null?i("studio.playersSee",{number:hn(l.liveNumber,p)}):i("studio.playersSeeLatest")}),u?r.jsxs("span",{role:"status",className:"inline-flex shrink-0 items-center gap-1 text-[10px] text-muted-foreground",children:[r.jsx(H,{icon:["far","spinner-third"],spin:!0,className:"text-[10px]","aria-hidden":!0}),i("studio.publishing")]}):l.liveNumber!=null&&r.jsx(La,{})]}),l.hasUnpublished&&!u&&r.jsxs("div",{className:"mt-2.5 rounded-md bg-accent/8 p-2.5",children:[r.jsxs("p",{className:"flex items-start gap-2 text-xs leading-4 text-foreground",children:[r.jsx("span",{"aria-hidden":"true",className:"mt-[5px] size-1.5 shrink-0 rounded-full bg-accent"}),i("studio.unpublished")]}),r.jsxs("button",{type:"button",onClick:e.publish,"data-publish-update":"",className:"mt-2.5 flex h-8 w-full cursor-pointer items-center justify-center gap-1.5 rounded-md bg-foreground text-xs font-medium text-background transition-opacity hover:opacity-80 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-card",children:[r.jsx(H,{icon:["far","rocket-launch"],className:"text-[11px]","aria-hidden":!0}),i("studio.publish")]})]}),r.jsxs("div",{className:"mt-3 flex items-center justify-between gap-3",children:[r.jsx("span",{id:o,className:"text-xs text-foreground",children:i("studio.auto")}),r.jsx("button",{type:"button",role:"switch","aria-checked":h,"aria-labelledby":o,"aria-describedby":a,"aria-busy":m||void 0,onClick:()=>e.setMode(h?"manual":"auto"),"data-release-mode-switch":"",className:me("relative h-5 w-9 shrink-0 cursor-pointer rounded-full transition-colors duration-200","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-card",h?"bg-accent":"bg-foreground
4/15",m&&"opacity-60"),children:r.jsx("span",{"aria-hidden":"true",className:me("absolute top-0.5 size-4 rounded-full bg-white shadow-sm transition-all duration-200",h?"left-[18px]":"left-0.5")})})]}),r.jsx("p",{id:a,className:"mt-1 text-[11px] leading-4 text-muted-foreground",children:i(h?"studio.autoHelp":"studio.manualHelp")})]})}const Od=f.forwardRef(function({children:t,follow:i=!0,lockX:c=!1,lockY:s=!1,lockZ:n=!1,...o},a){const l=f.useRef(null),d=f.useRef(null),u=new Pt;return Ct(({camera:m})=>{if(!i||!d.current)return;const h=l.current.rotation.clone();d.current.updateMatrix(),d.current.updateWorldMatrix(!1,!1),d.current.getWorldQuaternion(u),m.getWorldQuaternion(l.current.quaternion).premultiply(u.invert()),c&&(l.current.rotation.x=h.x),s&&(l.current.rotation.y=h.y),n&&(l.current.rotation.z=h.z)}),f.useImperativeHandle(a,()=>d.current,[]),f.createElement("group",st({ref:d},o),f.createElement("group",{ref:l},t))});function Gd(){var e=Object.create(null);function t(s,n){var o=s.id,a=s.name,l=s.dependencies;l===void 0&&(l=[]);var d=s.init;d===void 0&&(d=function(){});var u=s.getTransferables;if(u===void 0&&(u=null),!e[o])try{l=l.map(function(h){return h&&h.isWorkerModule&&(t(h,function(p){if(p instanceof Error)throw p}
4),h=e[h.id].value),h}),d=c("<"+a+">.init",d),u&&(u=c("<"+a+">.getTransferables",u));var m=null;typeof d=="function"?m=d.apply(void 0,l):console.error("worker module init function failed to rehydrate"),e[o]={id:o,value:m,getTransferables:u},n(m)}catch(h){h&&h.noLog||console.error(h),n(h)}}function i(s,n){var o,a=s.id,l=s.args;(!e[a]||typeof e[a].value!="function")&&n(new Error("Worker module "+a+": not found or its 'init' did not return a function"));try{var d=(o=e[a]).value.apply(o,l);d&&typeof d.then=="function"?d.then(u,function(m){return n(m instanceof Error?m:new Error(""+m))}):u(d)}catch(m){n(m)}function u(m){try{var h=e[a].getTransferables&&e[a].getTransferables(m);(!h||!Array.isArray(h)||!h.length)&&(h=void 0),n(m,h)}catch(p){console.error(p),n(p)}}}function c(s,n){var o=void 0;self.troikaDefine=function(l){return o=l};var a=URL.createObjectURL(new Blob(["/** "+s.replace(/\*/g,"")+` **/
5
6troikaDefine(
7`+n+`
8)`],{type:"application/javascript"}));try{importScripts(a)}catch(l){console.error(l)}return URL.revokeObjectURL(a),delete self.troikaDefine,o}self.addEventListener("message",function(s){var n=s.data,o=n.messageId,a=n.action,l=n.data;try{a==="registerModule"&&t(l,function(d){d instanceof Error?postMessage({messageId:o,success:!1,error:d.message}):postMessage({messageId:o,success:!0,result:{isCallable:typeof d=="function"}})}),a==="callModule"&&i(l,function(d,u){d instanceof Error?postMessage({messageId:o,success:!1,error:d.message}):postMessage({messageId:o,success:!0,result:d},u||void 0)})}catch(d){postMessage({messageId:o,success:!1,error:d.stack})}})}function Id(e){var t=function(){for(var i=[],c=arguments.length;c--;)i[c]=arguments[c];return t._getInitResult().then(function(s){if(typeof s=="function")return s.apply(void 0,i);throw new Error("Worker module function was called but `init` did not return a callable function")})};return t._getInitResult=function(){var i=e.dependencies,c=e.init;i=Array.isArray(i)?i.map(function(n){return n&&(n=n.onMainThread||n,n._getInitResult&&(n=n._getInitResult())),n}):[];var s=Promise.all(i).then(function(n){return c.apply(null,n)});return t._getInitResult=function(){return s},s},t}var Qa=function(){var e=!1;if(typeof window<"u"&&typeof window.document<"u")try{var t=new Worker(URL.createObjectURL(new Blob([""],{type:"application/javascript"})));t.terminate(),e=!0}catch(i){console.log("Troika createWorkerModule: web workers not allowed; falling back to main thread execution. Cause: ["+i.message+"]")}return Qa=function(){return e},e},Bd=0,Vd=0,Vn=!1,xr=Object.create(null),br=Object.create(null),os=Object.create(null);function tr(e){if((!e||typeof e.init!="function")&&!Vn)throw new Error("requires `options.init` function");var t=e.dependencies,i=e.init,c=e.getTransferables,s=e.workerId,n=Id(e);s==null&&(s="#default");var o="workerModule"+ ++Bd,a=e.name||o,l=null;t=t&&t.map(function(u){return typeof u=="function"&&!u.workerModuleData&&(Vn=!0,u=tr({workerId:s,name:"<"+a+"> function dependency: "+u.name,init:`function(){return (
9`+en(u)+`
10)}`}),Vn=!1),u&&u.workerModuleData&&(u=u.workerModuleData),u});function d(){for(var u=[],m=arguments.length;m--;)u[m]=arguments[m];if(!Qa())return n.apply(void 0,u);if(!l){l=mo(s,"registerModule",d.workerModuleData);var h=function(){l=null,br[s].delete(h)};(br[s]||(br[s]=new Set)).add(h)}return l.then(function(p){var g=p.isCallable;if(g)return mo(s,"callModule",{id:o,args:u});throw new Error("Worker module function was called but `init` did not return a callable function")})}return d.workerModuleData={isWorkerModule:!0,id:o,name:a,dependencies:t,init:en(i),getTransferables:c&&en(c)},d.onMainThread=n,d}function zd(e){br[e]&&br[e].forEach(function(t){t()}),xr[e]&&(xr[e].terminate(),delete xr[e])}function en(e){var t=e.toString();return!/^function/.test(t)&&/^\w+\s*\(/.test(t)&&(t="function "+t),t}function Wd(e){var t=xr[e];if(!t){var i=en(Gd);t=xr[e]=new Worker(URL.createObjectURL(new Blob(["/** Worker Module Bootstrap: "+e.replace(/\*/g,"")+` **/
11
12;(`+i+")()"],{type:"application/javascript"}))),t.onmessage=function(c){var s=c.data,n=s.messageId,o=os[n];if(!o)throw new Error("WorkerModule response with empty or unknown messageId");delete os[n],o(s)}}return t}function mo(e,t,i){return new Promise(function(c,s){var n=++Vd;os[n]=function(o){o.success?c(o.result):s(new Error("Error in worker "+t+" call: "+o.error))},Wd(e).postMessage({messageId:n,action:t,data:i})})}function Ja(){var e=function(t){function i(O,L,j,D,I,B,G,q){var V=1-G;q.x=V*V*O+2*V*G*j+G*G*I,q.y=V*V*L+2*V*G*D+G*G*B}function c(O,L,j,D,I,B,G,q,V,W){var ee=1-V;W.x=ee*ee*ee*O+3*ee*ee*V*j+3*ee*V*V*I+V*V*V*G,W.y=ee*ee*ee*L+3*ee*ee*V*D+3*ee*V*V*B+V*V*V*q}function s(O,L){for(var j=/([MLQCZ])([^MLQCZ]*)/g,D,I,B,G,q;D=j.exec(O);){var V=D[2].replace(/^\s*|\s*$/g,"").split(/[,\s]+/).map(function(W){return parseFloat(W)});switch(D[1]){case"M":G=I=V[0],q=B=V[1];break;case"L":(V[0]!==G||V[1]!==q)&&L("L",G,q,G=V[0],q=V[1]);break;case"Q":{L("Q",G,q,G=V[2],q=V[3],V[0],V[1]);break}case"C":{L("C",G,q,G=V[4],q=V[5],V[0],V[1],V[2],V[3]);break}case"Z":(G!==I||q!==B)&&L("L",G,q,I,B);break}}}function n(O,L,j){j===void 0&&(j=16);var D={x:0,y:0};
12s(O,function(I,B,G,q,V,W,ee,ne,J){switch(I){case"L":L(B,G,q,V);break;case"Q":{for(var $=B,ge=G,ce=1;ce<j;ce++)i(B,G,W,ee,q,V,ce/(j-1),D),L($,ge,D.x,D.y),$=D.x,ge=D.y;break}case"C":{for(var re=B,oe=G,de=1;de<j;de++)c(B,G,W,ee,ne,J,q,V,de/(j-1),D),L(re,oe,D.x,D.y),re=D.x,oe=D.y;break}}})}var o="precision highp float;attribute vec2 aUV;varying vec2 vUV;void main(){vUV=aUV;gl_Position=vec4(mix(vec2(-1.0),vec2(1.0),aUV),0.0,1.0);}",a="precision highp float;uniform sampler2D tex;varying vec2 vUV;void main(){gl_FragColor=texture2D(tex,vUV);}",l=new WeakMap,d={premultipliedAlpha:!1,preserveDrawingBuffer:!0,antialias:!1,depth:!1};function u(O,L){var j=O.getContext?O.getContext("webgl",d):O,D=l.get(j);if(!D){let ee=function(re){var oe=B[re];if(!oe&&(oe=B[re]=j.getExtension(re),!oe))throw new Error(re+" not supported");return oe},ne=function(re,oe){var de=j.createShader(oe);return j.shaderSource(de,re),j.compileShader(de),de},J=function(re,oe,de,Z){if(!G[re]){var le={},ie={},Q=j.createProgram();j.attachShader(Q,ne(oe,j.VERTEX_SHADER)),j.attachShader(Q,ne(de,j.FRAGMENT_SHADER)),j.linkProgram(Q),G[re]={program:Q,transaction:function(ae){j.useProgram(Q),ae({setUniform:function(se,Ne){for(var ue=[],he=arguments.length-2;he-- >0;)ue[he]=arguments[he+2];var Y=ie[Ne]||(ie[Ne]=j.getUniformLocation(Q,Ne));j["uniform"+se].apply(j,[Y].concat(ue))},setAttribute:function(se,Ne,ue,he,Y){var X=le[se];X||(X=le[se]={buf:j.createBuffer(),loc:j.getAttribLocation(Q,se),data:null}),j.bindBuffer(j.ARRAY_BUFFER,X.buf),j.vertexAttribPointer(X.loc,Ne,j.FLOAT,!1,0,0),j.enableVertexAttribArray(X.loc),I?j.vertexAttribDivisor(X.loc,he):ee("ANGLE_instanced_arrays").vertexAttribDivisorANGLE(X.loc,he),Y!==X.data&&(j.bufferData(j.ARRAY_BUFFER,Y,ue),X.data=Y)}})}}}G[re].transaction(Z)},$=function(re,oe){V++;try{j.activeTexture(j.TEXTURE0+V);var de=q[re];de||(de=q[re]=j.createTexture(),j.bindTexture(j.TEXTURE_2D,de),j.texParameteri(j.TEXTURE_2D,j.TEXTURE_MIN_FILTER,j.NEAREST),j.texParameteri(j.TEXTURE_2D,j.TEXTURE_MAG_FILTER,j.NEAREST)),j.bindTexture(j.TEXTURE_2D,de),oe(de,V)}finally{V--}},ge=function(re,oe,de){var Z=j.createFramebuffer();W.push(Z),j.bindFramebuffer(j.FRAMEBUFFER,Z),j.activeTexture(j.TEXTURE0+oe),j.bindTexture(j.TEXTURE_2D,re),j.framebufferTexture2D(j.FRAMEBUFFER,j.COLOR_ATTACHMENT0,j.TEXTURE_2D,re,0);try{de(Z)}finally{j.deleteFramebuffer(Z),j.bindFramebuffer(j.FRAMEBUFFER,W[--W.length-1]||null)}},ce=function(){B={},G={},q={},V=-1,W.length=0};var I=typeof WebGL2RenderingContext<"u"&&j instanceof WebGL2RenderingContext,B={},G={},q={},V=-1,W=[];j.canvas.addEventListener("webglcontextlost",function(re){ce(),re.preventDefault()},!1),l.set(j,D={gl:j,isWebGL2:I,getExtension:ee,withProgram:J,withTexture:$,withTextureFramebuffer:ge,handleContextLoss:ce})}L(D)}function m(O,L,j,D,I,B,G,q){G===void 0&&(G=15),q===void 0&&(q=null),u(O,function(V){var W=V.gl,ee=V.withProgram,ne=V.withTexture;ne("copy",function(J,$){W.texImage2D(W.TEXTURE_2D,0,W.RGBA,I,B,0,W.RGBA,W.UNSIGNED_BYTE,L),ee("copy",o,a,function(ge){var ce=ge.setUniform,re=ge.setAttribute;re("aUV",2,W.STATIC_DRAW,0,new Float32Array([0,0,2,0,0,2])),ce("1i","image",$),W.bindFramebuffer(W.FRAMEBUFFER,q||null),W.disable(W.BLEND),W.colorMask(G&8,G&4,G&2,G&1),W.viewport(j,D,I,B),W.scissor(j,D,I,B),W.drawArrays(W.TRIANGLES,0,3)})})})}function h(O,L,j){var D=O.width,I=O.height;u(O,function(B){var G=B.gl,q=new Uint8Array(D*I*4);G.readPixels(0,0,D,I,G.RGBA,G.UNSIGNED_BYTE,q),O.width=L,O.height=j,m(G,q,0,0,D,I)})}var p=Object.freeze({__proto__:null,withWebGLContext:u,renderImageData:m,resizeWebGLCanvasWithoutClearing:h});function g(O,L,j,D,I,B){B===void 0&&(B=1);var G=new Uint8Array(O*L),q=D[2]-D[0],V=D[3]-D[1],W=[];n(j,function(re,oe,de,Z){W.push({x1:re,y1:oe,x2:de,y2:Z,minX:Math.min(re,de),minY:Math.min(oe,Z),maxX:Math.max(re,de),maxY:Math.max(oe,Z)})}),W.sort(function(re,oe){return re.maxX-oe.maxX});for(var ee=0;ee<O;ee++)for(var ne=0;ne<L;ne++){var J=ge(D[0]+q*(ee+.5)/O,D[1]+V*(ne+.5)/L),$=Math.pow(1-Math.abs(J)/I,B)/2;J<0&&($=1-$),$=Math.max(0,Math.min(255,Math.round($*255))),G[ne*O+ee]=$}return G;function ge(re,oe){for(var de=1/0,Z=1/0,le=W.length;le--;){var ie=W[le];if(ie.maxX+Z<=re)break;
12if(re+Z>ie.minX&&oe-Z<ie.maxY&&oe+Z>ie.minY){var Q=w(re,oe,ie.x1,ie.y1,ie.x2,ie.y2);Q<de&&(de=Q,Z=Math.sqrt(de))}}return ce(re,oe)&&(Z=-Z),Z}function ce(re,oe){for(var de=0,Z=W.length;Z--;){var le=W[Z];if(le.maxX<=re)break;var ie=le.y1>oe!=le.y2>oe&&re<(le.x2-le.x1)*(oe-le.y1)/(le.y2-le.y1)+le.x1;ie&&(de+=le.y1<le.y2?1:-1)}return de!==0}}function b(O,L,j,D,I,B,G,q,V,W){B===void 0&&(B=1),q===void 0&&(q=0),V===void 0&&(V=0),W===void 0&&(W=0),x(O,L,j,D,I,B,G,null,q,V,W)}function x(O,L,j,D,I,B,G,q,V,W,ee){B===void 0&&(B=1),V===void 0&&(V=0),W===void 0&&(W=0),ee===void 0&&(ee=0);for(var ne=g(O,L,j,D,I,B),J=new Uint8Array(ne.length*4),$=0;$<ne.length;$++)J[$*4+ee]=ne[$];m(G,J,V,W,O,L,1<<3-ee,q)}function w(O,L,j,D,I,B){var G=I-j,q=B-D,V=G*G+q*q,W=V?Math.max(0,Math.min(1,((O-j)*G+(L-D)*q)/V)):0,ee=O-(j+W*G),ne=L-(D+W*q);return ee*ee+ne*ne}var v=Object.freeze({__proto__:null,generate:g,generateIntoCanvas:b,generateIntoFramebuffer:x}),N="precision highp float;uniform vec4 uGlyphBounds;attribute vec2 aUV;attribute vec4 aLineSegment;varying vec4 vLineSegment;varying vec2 vGlyphXY;void main(){vLineSegment=aLineSegment;vGlyphXY=mix(uGlyphBounds.xy,uGlyphBounds.zw,aUV);gl_Position=vec4(mix(vec2(-1.0),vec2(1.0),aUV),0.0,1.0);}",y="precision highp float;uniform vec4 uGlyphBounds;uniform float uMaxDistance;uniform float uExponent;varying vec4 vLineSegment;varying vec2 vGlyphXY;float absDistToSegment(vec2 point,vec2 lineA,vec2 lineB){vec2 lineDir=lineB-lineA;float lenSq=dot(lineDir,lineDir);float t=lenSq==0.0 ? 0.0 : clamp(dot(point-lineA,lineDir)/lenSq,0.0,1.0);vec2 linePt=lineA+t*lineDir;return distance(point,linePt);}void main(){vec4 seg=vLineSegment;vec2 p=vGlyphXY;float dist=absDistToSegment(p,seg.xy,seg.zw);float val=pow(1.0-clamp(dist/uMaxDistance,0.0,1.0),uExponent)*0.5;bool crossing=(seg.y>p.y!=seg.w>p.y)&&(p.x<(seg.z-seg.x)*(p.y-seg.y)/(seg.w-seg.y)+seg.x);bool crossingUp=crossing&&vLineSegment.y<vLineSegment.w;gl_FragColor=vec4(crossingUp ? 1.0/255.0 : 0.0,crossing&&!crossingUp ? 1.0/255.0 : 0.0,0.0,val);}",k="precision highp float;uniform sampler2D tex;varying vec2 vUV;void main(){vec4 color=texture2D(tex,vUV);bool inside=color.r!=color.g;float val=inside ? 1.0-color.a : color.a;gl_FragColor=vec4(val);}",S=new Float32Array([0,0,2,0,0,2]),T=null,E=!1,A={},M=new WeakMap;function R(O){if(!E&&!P(O))throw new Error("WebGL generation not supported")}function _(O,L,j,D,I,B,G){if(B===void 0&&(B=1),G===void 0&&(G=null),!G&&(G=T,!G)){var q=typeof OffscreenCanvas=="function"?new OffscreenCanvas(1,1):typeof document<"u"?document.createElement("canvas"):null;if(!q)throw new Error("OffscreenCanvas or DOM canvas not supported");G=T=q.getContext("webgl",{depth:!1})}R(G);var V=new Uint8Array(O*L*4);u(G,function(J){var $=J.gl,ge=J.withTexture,ce=J.withTextureFramebuffer;ge("readable",function(re,oe){$.texImage2D($.TEXTURE_2D,0,$.RGBA,O,L,0,$.RGBA,$.UNSIGNED_BYTE,null),ce(re,oe,function(de){C(O,L,j,D,I,B,$,de,0,0,0),$.readPixels(0,0,O,L,$.RGBA,$.UNSIGNED_BYTE,V)})})});for(var W=new Uint8Array(O*L),ee=0,ne=0;ee<V.length;ee+=4)W[ne++]=V[ee];return W}function F(O,L,j,D,I,B,G,q,V,W){B===void 0&&(B=1),q===void 0&&(q=0),V===void 0&&(V=0),W===void 0&&(W=0),C(O,L,j,D,I,B,G,null,q,V,W)}function C(O,L,j,D,I,B,G,q,V,W,ee){B===void 0&&(B=1),V===void 0&&(V=0),W===void 0&&(W=0),ee===void 0&&(ee=0),R(G);var ne=[];n(j,function(J,$,ge,ce){ne.push(J,$,ge,ce)}),ne=new Float32Array(ne),u(G,function(J){var $=J.gl,ge=J.isWebGL2,ce=J.getExtension,re=J.withProgram,oe=J.withTexture,de=J.withTextureFramebuffer,Z=J.handleContextLoss;if(oe("rawDistances",function(le,ie){(O!==le._lastWidth||L!==le._lastHeight)&&$.texImage2D($.TEXTURE_2D,0,$.RGBA,le._lastWidth=O,le._lastHeight=L,0,$.RGBA,$.UNSIGNED_BYTE,null),re("main",N,y,function(Q){var be=Q.setAttribute,ae=Q.setUniform,fe=!ge&&ce("ANGLE_instanced_arrays"),se=!ge&&ce("EXT_blend_minmax");be("aUV",2,$.STATIC_DRAW,0,S),be("aLineSegment",4,$.DYNAMIC_DRAW,1,ne),ae.apply(void 0,["4f","uGlyphBounds"].concat(D)),ae("1f","uMaxDistance",I),ae("1f","uExponent",B),de(le,ie,function(Ne){$.enable($.BLEND),$.colorMask(!0,!0,!0,!0),$.viewport(0,0,O,L),$.scissor(0,0,O,L),$.blendFunc($.ONE,$.ONE),$.blendEquationSeparate($.FUNC_ADD,ge?$.MAX:se.MAX_EXT),$.clear($.COLOR_BUFFER_BIT),ge?$.drawArraysInstanced($.TRIANGLES,0,3,ne.length/4):fe.drawArraysInstancedANGLE($.TRIANGLES,0,3,ne.length/4)})}),re("post",o,k,function(Q){Q.setAttribute("aUV",2,$.STATIC_DRAW,0,S),Q.setUniform("1i","tex",ie),$.bindFramebuffer($.FRAMEBUFFER,q),$.disable($.BLEND),$.colorMask(ee===0,ee===1,ee===2,ee===3),$.viewport(V,W,O,L),$.scissor(V,W,O,L),$.drawArrays($.TRIANGLES,0,3)})}),$.isContextLost())throw Z(),new Error("webgl context lost")})}function P(O){var L=!O||O===T?A:O.canvas||O,j=M.get(L);if(j===void 0){E=!0;var D=null;try{var I=[97,106,97,61,99,137,118,80,80,118,137,99,61,97,106,97],B=_(4,4,"M8,8L16,8L24,24L16,24Z",[0,0,32,32],24,1,O);j=B&&I.length===B.length&&B.every(function(G,q){return G===I[q]}),j||(D="bad trial run results",console.info(I,B))}catch(G){j=!1,D=G.message}D&&console.warn("WebGL SDF generation not supported:",D),E=!1,M.set(L,j)}return j}var U=Object.freeze({__proto__:null,generate:_,generateIntoCanvas:F,generateIntoFramebuffer:C,isSupported:P});function K(O,L,j,D,I,B){I===void 0&&(I=Math.max(D[2]-D[0],D[3]-D[1])/2),B===void 0&&(B=1);try{return _.apply(U,arguments)}catch(G){return console.info("WebGL SDF generation failed, falling back to JS",G),g.apply(v,arguments)}}function z(O,L,j,D,I,B,G,q,V,W){I===void 0&&(I=Math.max(D[2]-D[0],D[3]-D[1])/2),B===void 0&&(B=1),q===void 0&&(q=0),V===void 0&&(V=0),W===void 0&&(W=0);try{return F.apply(U,arguments)}catch(ee){return console.info("WebGL SDF generation failed, falling back to JS",ee),b.apply(v,arguments)}}return t.forEachPathCommand=s,t.generate=K,t.generateIntoCanvas=z,t.javascript=v,t.pathToLineSegments=n,t.webgl=U,t.webglUtils=p,Object.defineProperty(t,"__esMo
12dule",{value:!0}),t}({});return e}function Hd(){var e=function(t){var i={R:"13k,1a,2,3,3,2+1j,ch+16,a+1,5+2,2+n,5,a,4,6+16,4+3,h+1b,4mo,179q,2+9,2+11,2i9+7y,2+68,4,3+4,5+13,4+3,2+4k,3+29,8+cf,1t+7z,w+17,3+3m,1t+3z,16o1+5r,8+30,8+mc,29+1r,29+4v,75+73",EN:"1c+9,3d+1,6,187+9,513,4+5,7+9,sf+j,175h+9,qw+q,161f+1d,4xt+a,25i+9",ES:"17,2,6dp+1,f+1,av,16vr,mx+1,4o,2",ET:"z+2,3h+3,b+1,ym,3e+1,2o,p4+1,8,6u,7c,g6,1wc,1n9+4,30+1b,2n,6d,qhx+1,h0m,a+1,49+2,63+1,4+1,6bb+3,12jj",AN:"16o+5,2j+9,2+1,35,ed,1ff2+9,87+u",CS:"18,2+1,b,2u,12k,55v,l,17v0,2,3,53,2+1,b",B:"a,3,f+2,2v,690",S:"9,2,k",WS:"c,k,4f4,1vk+a,u,1j,335",ON:"x+1,4+4,h+5,r+5,r+3,z,5+3,2+1,2+1,5,2+2,3+4,o,w,ci+1,8+d,3+d,6+8,2+g,39+1,9,6+1,2,33,b8,3+1,3c+1,7+1,5r,b,7h+3,sa+5,2,3i+6,jg+3,ur+9,2v,ij+1,9g+9,7+a,8m,4+1,49+x,14u,2+2,c+2,e+2,e+2,e+1,i+n,e+e,2+p,u+2,e+2,36+1,2+3,2+1,b,2+2,6+5,2,2,2,h+1,5+4,6+3,3+f,16+2,5+3l,3+81,1y+p,2+40,q+a,m+13,2r+ch,2+9e,75+hf,3+v,2+2w,6e+5,f+6,75+2a,1a+p,2+2g,d+5x,r+b,6+3,4+o,g,6+1,6+2,2k+1,4,2j,5h+z,1m+1,1e+f,t+2,1f+e,d+3,4o+3,2s+1,w,535+1r,h3l+1i,93+2,2s,b+1,3l+x,2v,4g+3,21+3,kz+1,g5v+1,5a,j+9,n+v,2,3,2+8,2+1,3+2,2,3,46+1,4+4,h+5,r+5,r+a,3h+2,4+6,b+4,78,1r+24,4+c,4,1hb,ey+6,103+j,16j+c,1ux+7,5+g,fsh,jdq+1t,4,57+2e,p1,1m,1m,1m,1m,4kt+1,7j+17,5+2r,d+e,3+e,2+e,2+10,m+4,w,1n+5,1q,4z+5,4b+rb,9+c,4+c,4+37,d+2g,8+b,l+b,5+1j,9+9,7+13,9+t,3+1,27+3c,2+29,2+3q,d+d,3+4,4+2,6+6,a+o,8+6,a+2,e+6,16+42,2+1i",BN:"0+8,6+d,2s+5,2+p,e,4m9,1kt+2,2b+5,5+5,17q9+v,7k,6p+8,6+1,119d+3,440+7,96s+1,1ekf+1,1ekf+1,1ekf+1,1ekf+1,1ekf+1,1ekf+1,1ekf+1,1ekf+1,1ekf+1,1ekf+1,1ekf+1,1ekf+75,6p+2rz,1ben+1,1ekf+1,1ekf+1",NSM:"lc+33,7o+6,7c+18,2,2+1,2+1,2,21+a,1d+k,h,2u+6,3+5,3+1,2+3,10,v+q,2k+a,1n+8,a,p+3,2+8,2+2,2+4,18+2,3c+e,2+v,1k,2,5+7,5,4+6,b+1,u,1n,5+3,9,l+1,r,3+1,1m,5+1,5+1,3+2,4,v+1,4,c+1,1m,5+4,2+1,5,l+1,n+5,2,1n,3,2+3,9,8+1,c+1,v,1q,d,1f,4,1m+2,6+2,2+3,8+1,c+1,u,1n,g+1,l+1,t+1,1m+1,5+3,9,l+1,u,21,8+2,2,2j,3+6,d+7,2r,3+8,c+5,23+1,s,2,2,1k+d,2+4,2+1,6+a,2+z,a,2v+3,2+5,2+1,3+1,q+1,5+2,h+3,e,3+1,7,g,jk+2,qb+2,u+2,u+1,v+1,1t+1,2+6,9,3+a,a,1a+2,3c+1,z,3b+2,5+1,a,7+2,64+1,3,1n,2+6,2,2,3+7,7+9,3,1d+g,1s+3,1d,2+4,2,6,15+8,d+1,x+3,3+1,2+2,1l,2+1,4,2+2,1n+7,3+1,49+2,2+c,2+6,5,7,4+1,5j+1l,2+4,k1+w,2db+2,3y,2p+v,ff+3,30+1,n9x+3,2+9,x+1,29+1,7l,4,5,q+1,6,48+1,r+h,e,13+7,q+a,1b+2,1d,3+3,3+1,14,1w+5,3+1,3+1,d,9,1c,1g,2+2,3+1,6+1,2,17+1,9,6n,3,5,fn5,ki+f,h+f,r2,6b,46+4,1af+2,2+1,6+3,15+2,5,4m+1,fy+3,as+1,4a+a,4x,1j+e,1l+2,1e+3,3+1,1y+2,11+4,2+7,1r,d+1,1h+8,b+3,3,2o+2,3,2+1,7,4h,4+7,m+1,1m+1,4,12+6,4+4,5g+7,3+2,2,o,2d+5,2,5+1,2+1,6n+3,7+1,2+1,s+1,2e+7,3,2+1,2z,2,3+5,2,2u+2,3+3,2+4,78+8,2+1,75+1,2,5,41+3,3+1,5,x+5,3+1,15+5,3+3,9,a+5,3+2,1b+c,2+1,bb+6,2+5,2d+l,3+6,2+1,2+1,3f+5,4,2+1,2+6,2,21+1,4,2,9o+1,f0c+4,1o+6,t5,1s+3,2a,f5l+1,43t+2,i+7,3+6,v+3,45+2,1j0+1i,5+1d,9,f,n+4,2+e,11t+6,2+g,3+6,2+1,2+4,7a+6,c6+3,15t+6,32+6,gzhy+6n",AL:"16w,3,2,e+1b,z+2,2+2s,g+1,8+1,b+m,2+t,s+2i,c+e,4h+f,1d+1e,1bwe+dp,3+3z,x+c,2+1,35+3y,2rm+z,5+7,b+5,dt+l,c+u,17nl+27,1t+27,4x+6n,3+d",LRO:"6ct",RLO:"6cu",LRE:"6cq",RLE:"6cr",PDF:"6cs",LRI:"6ee",RLI:"6ef",FSI:"6eg",PDI:"6eh"},c={},s={};
vendor: 7,684 bytes, line 12
12c.L=1,s[1]="L",Object.keys(i).forEach(function(Z,le){c[Z]=1<<le+1,s[c[Z]]=Z}),Object.freeze(c);var n=c.LRI|c.RLI|c.FSI,o=c.L|c.R|c.AL,a=c.B|c.S|c.WS|c.ON|c.FSI|c.LRI|c.RLI|c.PDI,l=c.BN|c.RLE|c.LRE|c.RLO|c.LRO|c.PDF,d=c.S|c.WS|c.B|n|c.PDI|l,u=null;function m(){if(!u){u=new Map;var Z=function(ie){if(i.hasOwnProperty(ie)){var Q=0;i[ie].split(",").forEach(function(be){var ae=be.split("+"),fe=ae[0],se=ae[1];fe=parseInt(fe,36),se=se?parseInt(se,36):0,u.set(Q+=fe,c[ie]);for(var Ne=0;Ne<se;Ne++)u.set(++Q,c[ie])})}};for(var le in i)Z(le)}}function h(Z){return m(),u.get(Z.codePointAt(0))||c.L}function p(Z){return s[h(Z)]}var g={pairs:"14>1,1e>2,u>2,2wt>1,1>1,1ge>1,1wp>1,1j>1,f>1,hm>1,1>1,u>1,u6>1,1>1,+5,28>1,w>1,1>1,+3,b8>1,1>1,+3,1>3,-1>-1,3>1,1>1,+2,1s>1,1>1,x>1,th>1,1>1,+2,db>1,1>1,+3,3>1,1>1,+2,14qm>1,1>1,+1,4q>1,1e>2,u>2,2>1,+1",canonical:"6f1>-6dx,6dy>-6dx,6ec>-6ed,6ee>-6ed,6ww>2jj,-2ji>2jj,14r4>-1e7l,1e7m>-1e7l,1e7m>-1e5c,1e5d>-1e5b,1e5c>-14qx,14qy>-14qx,14vn>-1ecg,1ech>-1ecg,1edu>-1ecg,1eci>-1ecg,1eda>-1ecg,1eci>-1ecg,1eci>-168q,168r>-168q,168s>-14ye,14yf>-14ye"};function b(Z,le){var ie=36,Q=0,be=new Map,ae=le&&new Map,fe;return Z.split(",").forEach(function se(Ne){if(Ne.indexOf("+")!==-1)for(var ue=+Ne;ue--;)se(fe);else{fe=Ne;var he=Ne.split(">"),Y=he[0],X=he[1];Y=String.fromCodePoint(Q+=parseInt(Y,ie)),X=String.fromCodePoint(Q+=parseInt(X,ie)),be.set(Y,X),le&&ae.set(X,Y)}}),{map:be,reverseMap:ae}}var x,w,v;function N(){if(!x){var Z=b(g.pairs,!0),le=Z.map,ie=Z.reverseMap;x=le,w=ie,v=b(g.canonical,!1).map}}function y(Z){return N(),x.get(Z)||null}function k(Z){return N(),w.get(Z)||null}function S(Z){return N(),v.get(Z)||null}var T=c.L,E=c.R,A=c.EN,M=c.ES,R=c.ET,_=c.AN,F=c.CS,C=c.B,P=c.S,U=c.ON,K=c.BN,z=c.NSM,O=c.AL,L=c.LRO,j=c.RLO,D=c.LRE,I=c.RLE,B=c.PDF,G=c.LRI,q=c.RLI,V=c.FSI,W=c.PDI;function ee(Z,le){for(var ie=125,Q=new Uint32Array(Z.length),be=0;be<Z.length;be++)Q[be]=h(Z[be]);var ae=new Map;function fe(Ze,ft){var et=Q[Ze];Q[Ze]=ft,ae.set(et,ae.get(et)-1),et&a&&ae.set(a,ae.get(a)-1),ae.set(ft,(ae.get(ft)||0)+1),ft&a&&ae.set(a,(ae.get(a)||0)+1)}for(var se=new Uint8Array(Z.length),Ne=new Map,ue=[],he=null,Y=0;Y<Z.length;Y++)he||ue.push(he={start:Y,end:Z.length-1,level:le==="rtl"?1:le==="ltr"?0:Js(Y,!1)}),Q[Y]&C&&(he.end=Y,he=null);for(var X=I|D|j|L|n|W|B|C,ye=function(Ze){return Ze+(Ze&1?1:2)},ke=function(Ze){return Ze+(Ze&1?2:1)},we=0;we<ue.length;we++){he=ue[we];var je=[{_level:he.level,_override:0,_isolate:0}],pe=void 0,Fe=0,Le=0,qe=0;ae.clear();for(var Ue=he.start;Ue<=he.end;Ue++){var ve=Q[Ue];if(pe=je[je.length-1],ae.set(ve,(ae.get(ve)||0)+1),ve&a&&ae.set(a,(ae.get(a)||0)+1),ve&X)if(ve&(I|D)){se[Ue]=pe._level;var Te=(ve===I?ke:ye)(pe._level);Te<=ie&&!Fe&&!Le?je.push({_level:Te,_override:0,_isolate:0}):Fe||Le++}else if(ve&(j|L)){se[Ue]=pe._level;var Je=(ve===j?ke:ye)(pe._level);Je<=ie&&!Fe&&!Le?je.push({_level:Je,_override:ve&j?E:T,_isolate:0}):Fe||Le++}else if(ve&n){ve&V&&(ve=Js(Ue+1,!0)===1?q:G),se[Ue]=pe._level,pe._override&&fe(Ue,pe._override);var Pe=(ve===q?ke:ye)(pe._level);Pe<=ie&&Fe===0&&Le===0?(qe++,je.push({_level:Pe,_override:0,_isolate:1,_isolInitIndex:Ue})):Fe++}else if(ve&W){if(Fe>0)Fe--;else if(qe>0){for(Le=0;!je[je.length-1]._isolate;)je.pop();var _e=je[je.length-1]._isolInitIndex;_e!=null&&(Ne.set(_e,Ue),Ne.set(Ue,_e)),je.pop(),qe--}pe=je[je.length-1],se[Ue]=pe._level,pe._override&&fe(Ue,pe._override)}else ve&B?(Fe===0&&(Le>0?Le--:!pe._isolate&&je.length>1&&(je.pop(),pe=je[je.length-1])),se[Ue]=pe._level):ve&C&&(se[Ue]=he.level);else se[Ue]=pe._level,pe._override&&ve!==K&&fe(Ue,pe._override)}for(var Ve=[],Ie=null,Se=he.start;Se<=he.end;Se++){var Oe=Q[Se];if(!(Oe&l)){var ze=se[Se],Xe=Oe&n,We=Oe===W;Ie&&ze===Ie._level?(Ie._end=Se,Ie._endsWithIsolInit=Xe):Ve.push(Ie={_start:Se,_end:Se,_level:ze,_startsWithPDI:We,_endsWithIsolInit:Xe})}}for(var rt=[],ht=0;ht<Ve.length;ht++){var ct=Ve[ht];if(!ct._startsWithPDI||ct._startsWithPDI&&!Ne.has(ct._start)){for(var pt=[Ie=ct],it=void 0;Ie&&Ie._endsWithIsolInit&&(it=Ne.get(Ie._end))!=null;)for(var dt=ht+1;dt<Ve.length;dt++)if(Ve[dt]._start===it){pt.push(Ie=Ve[dt]);break}for(var te=[],Me=0;Me<pt.length;Me++)for(var He=pt[Me],gt=He._start;gt<=He._end;gt++)te.push(gt);for(var Ps=se[te[0]],Ds=he.level,Er=te[0]-1;Er>=0;Er--)if(!(Q[Er]&l)){Ds=se[Er];break}var bn=te[te.length-1],Hi=se[bn],Rs=he.level;if(!(Q[bn]&n)){for(var Tr=bn+1;Tr<=he.end;Tr++)if(!(Q[Tr]&l)){Rs=se[Tr];break}}rt.push({_seqIndices:te,_sosType:Math.max(Ds,Ps)%2?E:T,_eosType:Math.max(Rs,Hi)%2?E:T})}}for(var vn=0;vn<rt.length;vn++){var yn=rt[vn],xe=yn._seqIndices,nr=yn._sosType,Ki=yn._eosType,Ot=se[xe[0]]&1?E:T;if(ae.get(z))for(var Mr=0;Mr<xe.length;Mr++){var Us=xe[Mr];if(Q[Us]&z){for(var wn=nr,Ar=Mr-1;Ar>=0;Ar--)if(!(Q[xe[Ar]]&l)){wn=Q[xe[Ar]];break}fe(Us,wn&(n|W)?U:wn)}}if(ae.get(A))for(var Pr=0;Pr<xe.length;Pr++){var Fs=xe[Pr];if(Q[Fs]&A)for(var Dr=Pr-1;Dr>=-1;Dr--){var Ls=Dr===-1?nr:Q[xe[Dr]];if(Ls&o){Ls===O&&fe(Fs,_);break}}}if(ae.get(O))for(var jn=0;jn<xe.length;jn++){var Os=xe[jn];Q[Os]&O&&fe(Os,E)}if(ae.get(M)||ae.get(F))for(var sr=1;sr<xe.length-1;sr++){var kn=xe[sr];if(Q[kn]&(M|F)){for(var Gt=0,Nn=0,Sn=sr-1;Sn>=0&&(Gt=Q[xe[Sn]],!!(Gt&l));Sn--);for(var _n=sr+1;_n<xe.length&&(Nn=Q[xe[_n]],!!(Nn&l));_n++);Gt===Nn&&(Q[kn]===M?Gt===A:Gt&(A|_))&&fe(kn,Gt)}}if(ae.get(A))for(var xt=0;xt<xe.length;xt++){var Yi=xe[xt];if(Q[Yi]&A){for(var Rr=xt-1;Rr>=0&&Q[xe[Rr]]&(R|l);Rr--)fe(xe[Rr],A);for(xt++;xt<xe.length&&Q[xe[xt]]&(R|l|A);xt++)Q[xe[xt]]!==A&&fe(xe[xt],A)}}if(ae.get(R)||ae.get(M)||ae.get(F))for(var or=0;or<xe.length;or++){var Gs=xe[or];if(Q[Gs]&(R|M|F)){fe(Gs,U);for(var Ur=or-1;Ur>=0&&Q[xe[Ur]]&l;Ur--)fe(xe[Ur],U);for(var Fr=or+1;Fr<xe.length&&Q[xe[Fr]]&l;Fr++)fe(xe[Fr],U)}}if(ae.get(A))for(var Cn=0,Is=nr;Cn<xe.length;Cn++){var Bs=xe[Cn],En=Q[Bs];En&A?Is===T&&fe(Bs,T):En&o&&(Is=En)}if(ae.get(a)){var ar=E|A|_,Vs=ar|T,Lr=[];{for(var It=[],Bt=0;Bt<xe.length;Bt++)if(Q[xe[Bt]]&a){var ir=Z[xe[Bt]],zs=void 0;if(y(ir)!==null)if(It.length<63)It.push({char:ir,seqIndex:Bt});else break;else if((zs=k(ir))!==null)for(var lr=It.length-1;lr>=0;lr--){var Tn=It[lr].char;if(Tn===zs||Tn===k(S(ir))||y(S(Tn))===ir){Lr.push([It[lr].seqIndex,Bt]),It.length=lr;break}}}Lr.sort(function(Ze,ft){return Ze[0]-ft[0]})}for(var Mn=0;Mn<Lr.length;Mn++){for(var Ws=Lr[Mn],Or=Ws[0],An=Ws[1],Hs=!1,ut=0,Pn=Or+1;Pn<An;Pn++){var Ks=xe[Pn];if(Q[Ks]&Vs){Hs=!0;var Ys=Q[Ks]&ar?E:T;if(Ys===Ot){ut=Ys;break}}}if(Hs&&!ut){ut=nr;for(var Dn=Or-1;Dn>=0;Dn--){var Xs=xe[Dn];if(Q[Xs]&Vs){var $s=Q[Xs]&ar?E:T;$s!==Ot?ut=$s:ut=Ot;break}}}if(ut){if(Q[xe[Or]]=Q[xe[An]]=ut,ut!==Ot){for(var cr=Or+1;cr<xe.length;cr++)if(!(Q[xe[cr]]&l)){h(Z[xe[cr]])&z&&(Q[xe[cr]]=ut);break}}if(ut!==Ot){for(var dr=An+1;dr<xe.length;dr++)if(!(Q[xe[dr]]&l)){h(Z[xe[dr]])&z&&(Q[xe[dr]]=ut);break}}}}for(var jt=0;jt<xe.length;jt++)if(Q[xe[jt]]&a){for(var qs=jt,Rn=jt,Un=nr,ur=jt-1;ur>=0;ur--)if(Q[xe[ur]]&l)qs=ur;else{Un=Q[xe[ur]]&ar?E:T;break}for(var Qs=Ki,fr=jt+1;fr<xe.length;fr++)if(Q[xe[fr]]&(a|l))Rn=fr;else{Qs=Q[xe[fr]]&ar?E:T;break}for(var Fn=qs;Fn<=Rn;Fn++)Q[xe[Fn]]=Un===Qs?Un:Ot;jt=Rn}}}for(var nt=he.start;nt<=he.end;nt++){var Xi=se[nt],Gr=Q[nt];if(Xi&1?Gr&(T|A|_)&&se[nt]++:Gr&E?se[nt]++:Gr&(_|A)&&(se[nt]+=2),Gr&l&&(se[nt]=nt===0?he.level:se[nt-1]),nt===he.end||h(Z[nt])&(P|C))for(var Ir=nt;Ir>=0&&h(Z[Ir])&d;Ir--)se[Ir]=he.level}}return{levels:se,paragraphs:ue};function Js(Ze,ft){for(var et=Ze;et<Z.length;et++){var kt=Q[et];if(kt&(E|O))return 1;if(kt&(C|T)||ft&&kt===W)return 0;if(kt&n){var Zs=$i(et);et=Zs===-1?Z.length:Zs}}return 0}function $i(Ze){for(var ft=1,et=Ze+1;et<Z.length;et++){var kt=Q[et];if(kt&C)break;if(kt&W){if(--ft===0)return et}else kt&n&&ft++}return-1}}var ne="14>1,j>2,t>2,u>2,1a>g,2v3>
121,1>1,1ge>1,1wd>1,b>1,1j>1,f>1,ai>3,-2>3,+1,8>1k0,-1jq>1y7,-1y6>1hf,-1he>1h6,-1h5>1ha,-1h8>1qi,-1pu>1,6>3u,-3s>7,6>1,1>1,f>1,1>1,+2,3>1,1>1,+13,4>1,1>1,6>1eo,-1ee>1,3>1mg,-1me>1mk,-1mj>1mi,-1mg>1mi,-1md>1,1>1,+2,1>10k,-103>1,1>1,4>1,5>1,1>1,+10,3>1,1>8,-7>8,+1,-6>7,+1,a>1,1>1,u>1,u6>1,1>1,+5,26>1,1>1,2>1,2>2,8>1,7>1,4>1,1>1,+5,b8>1,1>1,+3,1>3,-2>1,2>1,1>1,+2,c>1,3>1,1>1,+2,h>1,3>1,a>1,1>1,2>1,3>1,1>1,d>1,f>1,3>1,1a>1,1>1,6>1,7>1,13>1,k>1,1>1,+19,4>1,1>1,+2,2>1,1>1,+18,m>1,a>1,1>1,lk>1,1>1,4>1,2>1,f>1,3>1,1>1,+3,db>1,1>1,+3,3>1,1>1,+2,14qm>1,1>1,+1,6>1,4j>1,j>2,t>2,u>2,2>1,+1",J;function $(){if(!J){var Z=b(ne,!0),le=Z.map,ie=Z.reverseMap;ie.forEach(function(Q,be){le.set(be,Q)}),J=le}}function ge(Z){return $(),J.get(Z)||null}function ce(Z,le,ie,Q){var be=Z.length;ie=Math.max(0,ie==null?0:+ie),Q=Math.min(be-1,Q==null?be-1:+Q);for(var ae=new Map,fe=ie;fe<=Q;fe++)if(le[fe]&1){var se=ge(Z[fe]);se!==null&&ae.set(fe,se)}return ae}function re(Z,le,ie,Q){var be=Z.length;ie=Math.max(0,ie==null?0:+ie),Q=Math.min(be-1,Q==null?be-1:+Q);var ae=[];return le.paragraphs.forEach(function(fe){var se=Math.max(ie,fe.start),Ne=Math.min(Q,fe.end);if(se<Ne){for(var ue=le.levels.slice(se,Ne+1),he=Ne;he>=se&&h(Z[he])&d;he--)ue[he]=fe.level;for(var Y=fe.level,X=1/0,ye=0;ye<ue.length;ye++){var ke=ue[ye];ke>Y&&(Y=ke),ke<X&&(X=ke|1)}for(var we=Y;we>=X;we--)for(var je=0;je<ue.length;je++)if(ue[je]>=we){for(var pe=je;je+1<ue.length&&ue[je+1]>=we;)je++;je>pe&&ae.push([pe+se,je+se])}}}),ae}function oe(Z,le,ie,Q){var be=de(Z,le,ie,Q),ae=[].concat(Z);return be.forEach(function(fe,se){ae[se]=(le.levels[fe]&1?ge(Z[fe]):null)||Z[fe]}),ae.join("")}function de(Z,le,ie,Q){for(var be=re(Z,le,ie,Q),ae=[],fe=0;fe<Z.length;fe++)ae[fe]=fe;return be.forEach(function(se){for(var Ne=se[0],ue=se[1],he=ae.slice(Ne,ue+1),Y=he.length;Y--;)ae[ue-Y]=he[Y]}),ae}return t.closingToOpeningBracket=k,t.getBidiCharType=h,t.getBidiCharTypeName=p,t.getCanonicalBracket=S,t.getEmbeddingLevels=ee,t.getMirroredCharacter=ge,t.getMirroredCharactersMap=ce,t.getReorderSegments=re,t.getReorderedIndices=de,t.getReorderedString=oe,t.openingToClosingBracket=y,Object.defineProperty(t,"__esModule",{value:!0}),t}({});return e}const Za=/\bvoid\s+main\s*\(\s*\)\s*{/g;function as(e){const t=/^[ \t]*#include +<([\w\d./]+)>/gm;function i(c,s){let n=Jc[s];return n?as(n):c}return e.replace(t,i)}const $e=[];for(let e=0;e<256;e++)$e[e]=(e<16?"0":"")+e.toString(16);function Kd(){const e=Math.random()*4294967295|0,t=Math.random()*4294967295|0,i=Math.random()*4294967295|0,c=Math.random()*4294967295|0;return($e[e&255]+$e[e>>8&255]+$e[e>>16&255]+$e[e>>24&255]+"-"+$e[t&255]+$e[t>>8&255]+"-"+$e[t>>16&15|64]+$e[t>>24&255]+"-"+$e[i&63|128]+$e[i>>8&255]+"-"+$e[i>>16&255]+$e[i>>24&255]+$e[c&255]+$e[c>>8&255]+$e[c>>16&255]+$e[c>>24&255]).toUpperCase()}const Et=Object.assign||function(){let e=arguments[0];for(let t=1,i=arguments.length;t<i;t++){let c=arguments[t];if(c)for(let s in c)Object.prototype.hasOwnProperty.call(c,s)&&(e[s]=c[s])}return e},Yd=Date.now(),ho=new WeakMap,po=new Map;let Xd=1e10;function is(e,t){const i=Jd(t);let c=ho.get(e);if(c||ho.set(e,c=Object.create(null)),c[i])return new c[i];const s=`_onBeforeCompile${i}`,n=function(d,u){e.onBeforeCompile.call(this,d,u);const m=this.customProgramCacheKey()+"|"+d.vertexShader+"|"+d.fragmentShader;let h=po[m];if(!h){const p=$d(this,d,t,i);h=po[m]=p}d.vertexShader=h.vertexShader,d.fragmentShader=h.fragmentShader,Et(d.uniforms,this.uniforms),t.timeUniform&&(d.uniforms[t.timeUniform]={get value(){return Date.now()-Yd}}),this[s]&&this[s](d)},o=function(){return a(t.chained?e:e.clone())},a=function(d){const u=Object.create(d,l);return Object.defineProperty(u,"baseMaterial",{value:e}),Object.defineProperty(u,"id",{value:Xd++}),u.uuid=Kd(),u.uniforms=Et({},d.uniforms,t.uniforms),u.defines=Et({},d.defines,t.defines),u.defines[`TROIKA_DERIVED_MATERIAL_${i}`]="",u.extensions=Et({},d.extensions,t.extensions),u._listeners=void 0,u},l={constructor:{value:o},isDerivedMaterial:{value:!0},type:{get:()=>e.type,set:d=>{e.type=d}},isDerivedFrom:{writable:!0,configurable:!0,value:function(d){const u=this.baseMaterial;return d===u||u.isDerivedMaterial&&u.isDerivedFrom(d)||!1}},customProgramCacheKey:{writable:!0,configurable:!0,value:function(){return e.customProgramCacheKey()+"|"+i}},onBeforeCompile:{get(){return n},set(d){this[s]=d}},copy:{writable:!0,configurable:!0,value:function(d){return e.copy.call(this,d),!e.isShaderMaterial&&!e.isDerivedMaterial&&(Et(this.extensions,d.extensions),Et(this.defines,d.defines),Et(this.uniforms,Qc.clone(d.uniforms)
12)),this}},clone:{writable:!0,configurable:!0,value:function(){const d=new e.constructor;return a(d).copy(this)}},getDepthMaterial:{writable:!0,configurable:!0,value:function(){let d=this._depthMaterial;return d||(d=this._depthMaterial=is(e.isDerivedMaterial?e.getDepthMaterial():new $c({depthPacking:qc}),t),d.defines.IS_DEPTH_MATERIAL="",d.uniforms=this.uniforms),d}},getDistanceMaterial:{writable:!0,configurable:!0,value:function(){let d=this._distanceMaterial;return d||(d=this._distanceMaterial=is(e.isDerivedMaterial?e.getDistanceMaterial():new Xc,t),d.defines.IS_DISTANCE_MATERIAL="",d.uniforms=this.uniforms),d}},dispose:{writable:!0,configurable:!0,value(){const{_depthMaterial:d,_distanceMaterial:u}=this;d&&d.dispose(),u&&u.dispose(),e.dispose.call(this)}}};return c[i]=o,new o}function $d(e,{vertexShader:t,fragmentShader:i},c,s){let{vertexDefs:n,vertexMainIntro:o,vertexMainOutro:a,vertexTransform:l,fragmentDefs:d,fragmentMainIntro:u,fragmentMainOutro:m,fragmentColorTransform:h,customRewriter:p,timeUniform:g}=c;if(n=n||"",o=o||"",a=a||"",d=d||"",u=u||"",m=m||"",(l||p)&&(t=as(t)),(h||p)&&(i=i.replace(/^[ \t]*#include <((?:tonemapping|encodings|colorspace|fog|premultiplied_alpha|dithering)_fragment)>/gm,`
13//!BEGIN_POST_CHUNK $1
14$&
15//!END_POST_CHUNK
16`),i=as(i)),p){let b=p({vertexShader:t,fragmentShader:i});t=b.vertexShader,i=b.fragmentShader}if(h){let b=[];i=i.replace(/^\/\/!BEGIN_POST_CHUNK[^]+?^\/\/!END_POST_CHUNK/gm,x=>(b.push(x),"")),m=`${h}
17${b.join(`
18`)}
19${m}`}if(g){const b=`
20uniform float ${g};
21`;n=b+n,d=b+d}return l&&(t=`vec3 troika_position_${s};
22vec3 troika_normal_${s};
23vec2 troika_uv_${s};
24${t}
25`,n=`${n}
26void troikaVertexTransform${s}(inout vec3 position, inout vec3 normal, inout vec2 uv) {
27  ${l}
28}
29`,o=`
30troika_position_${s} = vec3(position);
31troika_normal_${s} = vec3(normal);
32troika_uv_${s} = vec2(uv);
33troikaVertexTransform${s}(troika_position_${s}, troika_normal_${s}, troika_uv_${s});
34${o}
35`,t=t.replace(/\b(position|normal|uv)\b/g,(b,x,w,v)=>/\battribute\s+vec[23]\s+$/.test(v.substr(0,w))?x:`troika_${x}_${s}`),e.map&&e.map.channel>0||(t=t.replace(/\bMAP_UV\b/g,`troika_uv_${s}`))),t=go(t,s,n,o,a),i=go(i,s,d,u,m),{vertexShader:t,fragmentShader:i}}function go(e,t,i,c,s){return(c||s||i)&&(e=e.replace(Za,`
36${i}
37void troikaOrigMain${t}() {`),e+=`
38void main() {
39  ${c}
40  troikaOrigMain${t}();
41  ${s}
42}`),e}function qd(e,t){return e==="uniforms"?void 0:typeof t=="function"?t.toString():t}let Qd=0;const xo=new Map;function Jd(e){const t=JSON.stringify(e,qd);let i=xo.get(t);return i==null&&xo.set(t,i=++Qd),i}/*!
43Custom build of Typr.ts (https://github.com/fredli74/Typr.ts) for use in Troika text rendering.
44Original MIT license applies: https://github.com/fredli74/Typr.ts/blob/master/LICENSE
45*/function Zd(){return typeof window>"u"&&(self.window=self),function(e){var t={parse:function(s){var n=t._bin,o=new Uint8Array(s);if(n.readASCII(o,0,4)=="ttcf"){var a=4;n.readUshort(o,a),a+=2,n.readUshort(o,a),a+=2;var l=n.readUint(o,a);a+=4;for(var d=[],u=0;u<l;u++){var m=n.readUint(o,a);a+=4,d.push(t._readFont(o,m))}return d}return[t._readFont(o,0)]},_readFont:function(s,n){var o=t._bin,a=n;o.readFixed(s,n),n+=4;var l=o.readUshort(s,n);n+=2,o.readUshort(s,n),n+=2,o.readUshort(s,n),n+=2,o.readUshort(s,n),n+=2;for(var d=["cmap","head","hhea","maxp","hmtx","name","OS/2","post","loca","glyf","kern","CFF ","GDEF","GPOS","GSUB","SVG "],u={_data:s,_offset:a},m={},h=0;h<l;h++){var p=o.readASCII(s,n,4);n+=4,o.readUint(s,n),n+=4;var g=o.readUint(s,n);n+=4;var b=o.readUint(s,n);n+=4,m[p]={offset:g,length:b}}for(h=0;h<d.length;h++){var x=d[h];m[x]&&(u[x.trim()]=t[x.trim()].parse(s,m[x].offset,m[x].length,u))}return u},_tabOffset:function(s,n,o){for(var a=t._bin,l=a.readUshort(s,o+4),d=o+12,u=0;u<l;u++){var m=a.readASCII(s,d,4);d+=4,a.readUint(s,d),d+=4;var h=a.readUint(s,d);if(d+=4,a.readUint(s,d),d+=4,m==n)return h}return 0}};t._bin={readFixed:function(s,n){return(s[n]<<8|s[n+1])+(s[n+2]<<8|s[n+3])/65540},readF2dot14:function(s,n){return t._bin.readShort(s,n)/16384},readInt:function(s,n){return t._bin._view(s).getInt32(n)},readInt8:function(s,n){return t._bin._view(s).getInt8(n)},readShort:function(s,n){return t._bin._view(s).getInt16(n)},readUshort:function(s,n){return t._bin._view(s).getUint16(n)},readUshorts:function(s,n,o){for(var a=[],l=0;l<o;l++)a.push(t._bin.readUshort(s,n+2*l));return a},readUint:function(s,n){return t._bin._view(s).getUint32(n)},readUint64:function(s,n){return 4294967296*t._bin.readUint(s,n)+t._bin.readUint(s,n+4)},readASCII:function(s,n,o){for(var a="",l=0;l<o;l++)a+=String.fromCharCode(s[n+l]);return a},readUnicode:function(s,n,o){for(var a="",l=0;l<o;l++){var d=s[n++]<<8|s[n++];a+=String.fromCharCode(d)}return a},_tdec:typeof window<"u"&&window.TextDecoder?new window.TextDecoder:null,readUTF8:function(s,n,o){var a=t._bin._tdec;return a&&n==0&&o==s.length?a.decode(s):t._bin.readASCII(s,n,o)},readBytes:function(s,n,o){for(var a=[],l=0;l<o;l++)a.push(s[n+l]);return a},readASCIIArray:function(s,n,o){for(var a=[],l=0;l<o;l++)a.push(String.fromCharCode(s[n+l]));return a},_view:function(s){return s._dataView||(s._dataView=s.buffer?new DataView(s.buffer,s.byteOffset,s.byteLength):new DataView(new Uint8Array(s).buffer))}},t._lctf={},t._lctf.parse=function(s,n,o,a,l){var d=t._bin,u={},m=n;d.readFixed(s,n),n+=4;var h=d.readUshort(s,n);n+=2;var p=d.readUshort(s,n);n+=2;var g=d.readUshort(s,n);return n+=2,u.scriptList=t._lctf.readScriptList(s,m+h),u.featureList=t._lctf.readFeatureList(s,m+p),u.lookupList=t._lctf.readLookupList(s,m+g,l),u},t._lctf.readLookupList=function(s,n,o){var a=t._bin,l=n,d=[],u=a.readUshort(s,n);n+=2;for(var m=0;m<u;m++){var h=a.readUshort(s,n);n+=2;var p=t._lctf.readLookupTable(s,l+h,o);d.push(p)}return d},t._lctf.readLookupTable=function(s,n,o){var a=t._bin,l=n,d={tabs:[]};d.ltype=a.readUshort(s,n),n+=2,d.flag=a.readUshort(s,n),n+=2;var u=a.readUshort(s,n);n+=2;for(var m=d.ltype,h=0;h<u;h++){var p=a.readUshort(s,n);n+=2;var g=o(s,m,l+p,d);d.tabs.push(g)}return d},t._lctf.numOfOnes=function(s){for(var n=0,o=0;o<32;o++)s>>>o&1&&n++;return n},t._lctf.readClassDef=function(s,n){var o=t._bin,a=[],l=o.readUshort(s,n);if(n+=2,l==1){var d=o.readUshort(s,n);n+=2;var u=o.readUshort(s,n);n+=2;for(var m=0;m<u;m++)a.push(d+m),a.push(d+m),a.push(o.readUshort(s,n)),n+=2}if(l==2){var h=o.readUshort(s,n);for(n+=2,m=0;m<h;m++)a.push(o.readUshort(s,n)),n+=2,a.push(o.readUshort(s,n)),n+=2,a.push(o.readUshort(s,n)),n+=2}return a},t._lctf.getInterval=function(s,n){for(var o=0;o<s.length;o+=3){var a=s[o],l=s[o+1];if(s[o+2],a<=n&&n<=l)return o}return-1},t._lctf.readCoverage=function(s,n){var o=t._bin,a={};a.fmt=o.readUshort(s,n),n+=2;var l=o.readUshort(s,n);return n+=2,a.fmt==1&&(a.tab=o.readUshorts(s,n,l)),a.fmt==2&&(a.tab=o.readUshorts(s,n,3*l)),a},t._lctf.coverageIndex=function(s,n){var o=s.tab;if(s.fmt==1)return o.indexOf(n);if(s.fmt==2){var a=t._lctf.getInterval(o,n);if(a!=-1)return o[a+2]+(n-o[a])}return-1},t._lctf.readFeatureList=function(s,n){var o=t._bin,a=n,l=[],d=o.readUshort(s,n);n+=2;for(var u=0;u<d;u++){var m=o.readASCII(s,n,4);n+=4;var h=o.readUshort(s,n);n+=2;var p=t._lctf.readFeatureTable(s,a+h);p.tag=m.trim(),l.push(p)}return l},t._lctf.readFeatureTable=function(s,n){var o=t._bin,a=n,l={},d=o.readUshort(s,n);n+=2,d>
450&&(l.featureParams=a+d);var u=o.readUshort(s,n);n+=2,l.tab=[];for(var m=0;m<u;m++)l.tab.push(o.readUshort(s,n+2*m));return l},t._lctf.readScriptList=function(s,n){var o=t._bin,a=n,l={},d=o.readUshort(s,n);n+=2;for(var u=0;u<d;u++){var m=o.readASCII(s,n,4);n+=4;var h=o.readUshort(s,n);n+=2,l[m.trim()]=t._lctf.readScriptTable(s,a+h)}return l},t._lctf.readScriptTable=function(s,n){var o=t._bin,a=n,l={},d=o.readUshort(s,n);n+=2,d>0&&(l.default=t._lctf.readLangSysTable(s,a+d));var u=o.readUshort(s,n);n+=2;for(var m=0;m<u;m++){var h=o.readASCII(s,n,4);n+=4;var p=o.readUshort(s,n);n+=2,l[h.trim()]=t._lctf.readLangSysTable(s,a+p)}return l},t._lctf.readLangSysTable=function(s,n){var o=t._bin,a={};o.readUshort(s,n),n+=2,a.reqFeature=o.readUshort(s,n),n+=2;var l=o.readUshort(s,n);return n+=2,a.features=o.readUshorts(s,n,l),a},t.CFF={},t.CFF.parse=function(s,n,o){var a=t._bin;(s=new Uint8Array(s.buffer,n,o))[n=0],s[++n],s[++n],s[++n],n++;var l=[];n=t.CFF.readIndex(s,n,l);for(var d=[],u=0;u<l.length-1;u++)d.push(a.readASCII(s,n+l[u],l[u+1]-l[u]));n+=l[l.length-1];var m=[];n=t.CFF.readIndex(s,n,m);var h=[];for(u=0;u<m.length-1;u++)h.push(t.CFF.readDict(s,n+m[u],n+m[u+1]));n+=m[m.length-1];var p=h[0],g=[];n=t.CFF.readIndex(s,n,g);var b=[];for(u=0;u<g.length-1;u++)b.push(a.readASCII(s,n+g[u],g[u+1]-g[u]));if(n+=g[g.length-1],t.CFF.readSubrs(s,n,p),p.CharStrings){n=p.CharStrings,g=[],n=t.CFF.readIndex(s,n,g);var x=[];for(u=0;u<g.length-1;u++)x.push(a.readBytes(s,n+g[u],g[u+1]-g[u]));p.CharStrings=x}if(p.ROS){n=p.FDArray;var w=[];for(n=t.CFF.readIndex(s,n,w),p.FDArray=[],u=0;u<w.length-1;u++){var v=t.CFF.readDict(s,n+w[u],n+w[u+1]);t.CFF._readFDict(s,v,b),p.FDArray.push(v)}n+=w[w.length-1],n=p.FDSelect,p.FDSelect=[];var N=s[n];if(n++,N!=3)throw N;var y=a.readUshort(s,n);for(n+=2,u=0;u<y+1;u++)p.FDSelect.push(a.readUshort(s,n),s[n+2]),n+=3}return p.Encoding&&(p.Encoding=t.CFF.readEncoding(s,p.Encoding,p.CharStrings.length)),p.charset&&(p.charset=t.CFF.readCharset(s,p.charset,p.CharStrings.length)),t.CFF._readFDict(s,p,b),p},t.CFF._readFDict=function(s,n,o){var a;for(var l in n.Private&&(a=n.Private[1],n.Private=t.CFF.readDict(s,a,a+n.Private[0]),n.Private.Subrs&&t.CFF.readSubrs(s,a+n.Private.Subrs,n.Private)),n)["FamilyName","FontName","FullName","Notice","version","Copyright"].indexOf(l)!=-1&&(n[l]=o[n[l]-426+35])},t.CFF.readSubrs=function(s,n,o){var a=t._bin,l=[];n=t.CFF.readIndex(s,n,l);var d,u=l.length;d=u<1240?107:u<33900?1131:32768,o.Bias=d,o.Subrs=[];for(var m=0;m<l.length-1;m++)o.Subrs.push(a.readBytes(s,n+l[m],l[m+1]-l[m]))},t.CFF.tableSE=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,0,111,112,113,114,0,115,116,117,118,119,120,121,122,0,123,0,124,125,126,127,128,129,130,131,0,132,133,0,134,135,136,137,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,138,0,139,0,0,0,0,140,141,142,143,0,0,0,0,0,144,0,0,0,145,0,0,146,147,148,149,0,0,0,0],t.CFF.glyphByUnicode=function(s,n){for(var o=0;o<s.charset.length;o++)if(s.charset[o]==n)return o;return-1},t.CFF.glyphBySE=function(s,n){return n<0||n>255?-1:t.CFF.glyphByUnicode(s,t.CFF.tableSE[n])},t.CFF.readEncoding=function(s,n,o){t._bin;var a=[".notdef"],l=s[n];if(n++,l!=0)throw"error: unknown encoding format: "+l;var d=s[n];n++;for(var u=0;u<d;u++)a.push(s[n+u]);return a},t.CFF.readCharset=function(s,n,o){var a=t._bin,l=[".notdef"],d=s[n];if(n++,d==0)for(var u=0;u<o;u++){var m=a.readUshort(s,n);n+=2,l.push(m)}else{if(d!=1&&d!=2)throw"error: format: "+d;for(;l.length<o;){m=a.readUshort(s,n),n+=2;var h=0;for(d==1?(h=s[n],n++):(h=a.readUshort(s,n),n+=2),u=0;u<=h;u++)l.push(m),m++}}return l},t.CFF.readIndex=function(s,n,o){var a=t._bin,l=a.readUshort(s,n)+1,d=s[n+=2];if(n++,d==1)for(var u=0;u<l;u++)o.push(s[n+u]);else if(d==2)for(u=0;
45u<l;u++)o.push(a.readUshort(s,n+2*u));else if(d==3)for(u=0;u<l;u++)o.push(16777215&a.readUint(s,n+3*u-1));else if(l!=1)throw"unsupported offset size: "+d+", count: "+l;return(n+=l*d)-1},t.CFF.getCharString=function(s,n,o){var a=t._bin,l=s[n],d=s[n+1];s[n+2],s[n+3],s[n+4];var u=1,m=null,h=null;l<=20&&(m=l,u=1),l==12&&(m=100*l+d,u=2),21<=l&&l<=27&&(m=l,u=1),l==28&&(h=a.readShort(s,n+1),u=3),29<=l&&l<=31&&(m=l,u=1),32<=l&&l<=246&&(h=l-139,u=1),247<=l&&l<=250&&(h=256*(l-247)+d+108,u=2),251<=l&&l<=254&&(h=256*-(l-251)-d-108,u=2),l==255&&(h=a.readInt(s,n+1)/65535,u=5),o.val=h??"o"+m,o.size=u},t.CFF.readCharString=function(s,n,o){for(var a=n+o,l=t._bin,d=[];n<a;){var u=s[n],m=s[n+1];s[n+2],s[n+3],s[n+4];var h=1,p=null,g=null;u<=20&&(p=u,h=1),u==12&&(p=100*u+m,h=2),u!=19&&u!=20||(p=u,h=2),21<=u&&u<=27&&(p=u,h=1),u==28&&(g=l.readShort(s,n+1),h=3),29<=u&&u<=31&&(p=u,h=1),32<=u&&u<=246&&(g=u-139,h=1),247<=u&&u<=250&&(g=256*(u-247)+m+108,h=2),251<=u&&u<=254&&(g=256*-(u-251)-m-108,h=2),u==255&&(g=l.readInt(s,n+1)/65535,h=5),d.push(g??"o"+p),n+=h}return d},t.CFF.readDict=function(s,n,o){for(var a=t._bin,l={},d=[];n<o;){var u=s[n],m=s[n+1];s[n+2],s[n+3],s[n+4];var h=1,p=null,g=null;if(u==28&&(g=a.readShort(s,n+1),h=3),u==29&&(g=a.readInt(s,n+1),h=5),32<=u&&u<=246&&(g=u-139,h=1),247<=u&&u<=250&&(g=256*(u-247)+m+108,h=2),251<=u&&u<=254&&(g=256*-(u-251)-m-108,h=2),u==255)throw g=a.readInt(s,n+1)/65535,h=5,"unknown number";if(u==30){var b=[];for(h=1;;){var x=s[n+h];h++;var w=x>>4,v=15&x;if(w!=15&&b.push(w),v!=15&&b.push(v),v==15)break}for(var N="",y=[0,1,2,3,4,5,6,7,8,9,".","e","e-","reserved","-","endOfNumber"],k=0;k<b.length;k++)N+=y[b[k]];g=parseFloat(N)}u<=21&&(p=["version","Notice","FullName","FamilyName","Weight","FontBBox","BlueValues","OtherBlues","FamilyBlues","FamilyOtherBlues","StdHW","StdVW","escape","UniqueID","XUID","charset","Encoding","CharStrings","Private","Subrs","defaultWidthX","nominalWidthX"][u],h=1,u==12&&(p=["Copyright","isFixedPitch","ItalicAngle","UnderlinePosition","UnderlineThickness","PaintType","CharstringType","FontMatrix","StrokeWidth","BlueScale","BlueShift","BlueFuzz","StemSnapH","StemSnapV","ForceBold",0,0,"LanguageGroup","ExpansionFactor","initialRandomSeed","SyntheticBase","PostScript","BaseFontName","BaseFontBlend",0,0,0,0,0,0,"ROS","CIDFontVersion","CIDFontRevision","CIDFontType","CIDCount","UIDBase","FDArray","FDSelect","FontName"][m],h=2)),p!=null?(l[p]=d.length==1?d[0]:d,d=[]):d.push(g),n+=h}return l},t.cmap={},t.cmap.parse=function(s,n,o){s=new Uint8Array(s.buffer,n,o),n=0;var a=t._bin,l={};a.readUshort(s,n),n+=2;var d=a.readUshort(s,n);n+=2;var u=[];l.tables=[];for(var m=0;m<d;m++){var h=a.readUshort(s,n);n+=2;var p=a.readUshort(s,n);n+=2;var g=a.readUint(s,n);n+=4;var b="p"+h+"e"+p,x=u.indexOf(g);if(x==-1){var w;x=l.tables.length,u.push(g);var v=a.readUshort(s,g);v==0?w=t.cmap.parse0(s,g):v==4?w=t.cmap.parse4(s,g):v==6?w=t.cmap.parse6(s,g):v==12?w=t.cmap.parse12(s,g):console.debug("unknown format: "+v,h,p,g),l.tables.push(w)}if(l[b]!=null)throw"multiple tables for one platform+encoding";l[b]=x}return l},t.cmap.parse0=function(s,n){var o=t._bin,a={};a.format=o.readUshort(s,n),n+=2;var l=o.readUshort(s,n);n+=2,o.readUshort(s,n),n+=2,a.map=[];for(var d=0;d<l-6;d++)a.map.push(s[n+d]);return a},t.cmap.parse4=function(s,n){var o=t._bin,a=n,l={};l.format=o.readUshort(s,n),n+=2;var d=o.readUshort(s,n);n+=2,o.readUshort(s,n),n+=2;var u=o.readUshort(s,n);n+=2;var m=u/2;l.searchRange=o.readUshort(s,n),n+=2,l.entrySelector=o.readUshort(s,n),n+=2,l.rangeShift=o.readUshort(s,n),n+=2,l.endCount=o.readUshorts(s,n,m),n+=2*m,n+=2,l.startCount=o.readUshorts(s,n,m),n+=2*m,l.idDelta=[];for(var h=0;h<m;h++)l.idDelta.push(o.readShort(s,n)),n+=2;for(l.idRangeOffset=o.readUshorts(s,n,m),n+=2*m,l.glyphIdArray=[];n<a+d;)l.glyphIdArray.push(o.readUshort(s,n)),n+=2;return l},t.cmap.parse6=function(s,n){var o=t._bin,a={};a.format=o.readUshort(s,n),n+=2,o.readUshort(s,n),n+=2,o.readUshort(s,n),n+=2,a.firstCode=o.readUshort(s,n),n+=2;var l=o.readUshort(s,n);n+=2,a.glyphIdArray=[];for(var d=0;d<l;d++)a.glyphIdArray.push(o.readUshort(s,n)),n+=2;return a},t.cmap.parse12=function(s,n){var o=t._bin,a={};a.format=o.readUshort(s,n),n+=2,n+=2,o.readUint(s,n),n+=4,o.readUint(s,n),n+=4;var l=o.readUint(s,n);n+=4,a.groups=[];for(var d=0;d<l;d++){var u=n+12*d,m=o.readUint(s,u+0),h=o.readUint(s,u+4),p=o.readUint(s,u+8);a.groups.push([m,h,p])}return a},t.glyf={},t.glyf.parse=function(s,n,o,a){for(var l=[],d=0;d<a.maxp.numGlyphs;d++)l.push(null);return l},t.glyf._parseGlyf=function(s,n){var o=t._bin,a=s._data,l=t._tabOffset(a,"glyf",s._offset)+s.loca[n];if(s.loca[n]==s.loca[n+1])return null;var d={};if(d.noc=o.readShort(a,l),l+=2,d.xMin=o.readShort(a,l),l+=2,d.yMin=o.readShort(a,l),l+=2,d.xMax=o.readShort(a,l),l+=2,d.yMax=o.readShort(a,l),l+=2,d.xMin>=d.xMax||d.yMin>=d.yMax)return null;if(d.noc>0){d.endPts=[];for(var u=0;u<d.noc;u++)d.endPts.push(o.readUshort(a,l)),l+=2;var m=o.readUshort(a,l);if(l+=2,a.length-l<m)return null;d.instructions=o.readBytes(a,l,m),l+=m;var h=d.endPts[d.noc-1]+1;for(d.flags=[],u=0;u<h;u++){var p=a[l];if(l++,d.flags.push(p),(8&p)!=0){var g=a[l];l++;for(var b=0;b<g;b++)d.flags.push(p),u++}}for(d.xs=[],u=0;u<h;u++){var x=(2&d.flags[u])!=0,w=(16&d.flags[u])!=0;x?(d.xs.push(w?a[l]:-a[l]),l++):w?d.xs.push(0):(d.xs.push(o.readShort(a,l)),l+=2)}for(d.ys=[],u=0;u<h;u++)x=(4&d.flags[u])!=0,w=(32&d.flags[u])!=0,x?(d.ys.push(w?a[l]:-a[l]),l++):w?d.ys.push(0):(d.ys.push(o.readShort(a,l)),l+=2);var v=0,N=0;for(u=0;
45u<h;u++)v+=d.xs[u],N+=d.ys[u],d.xs[u]=v,d.ys[u]=N}else{var y;d.parts=[];do{y=o.readUshort(a,l),l+=2;var k={m:{a:1,b:0,c:0,d:1,tx:0,ty:0},p1:-1,p2:-1};if(d.parts.push(k),k.glyphIndex=o.readUshort(a,l),l+=2,1&y){var S=o.readShort(a,l);l+=2;var T=o.readShort(a,l);l+=2}else S=o.readInt8(a,l),l++,T=o.readInt8(a,l),l++;2&y?(k.m.tx=S,k.m.ty=T):(k.p1=S,k.p2=T),8&y?(k.m.a=k.m.d=o.readF2dot14(a,l),l+=2):64&y?(k.m.a=o.readF2dot14(a,l),l+=2,k.m.d=o.readF2dot14(a,l),l+=2):128&y&&(k.m.a=o.readF2dot14(a,l),l+=2,k.m.b=o.readF2dot14(a,l),l+=2,k.m.c=o.readF2dot14(a,l),l+=2,k.m.d=o.readF2dot14(a,l),l+=2)}while(32&y);if(256&y){var E=o.readUshort(a,l);for(l+=2,d.instr=[],u=0;u<E;u++)d.instr.push(a[l]),l++}}return d},t.GDEF={},t.GDEF.parse=function(s,n,o,a){var l=n;n+=4;var d=t._bin.readUshort(s,n);return{glyphClassDef:d===0?null:t._lctf.readClassDef(s,l+d)}},t.GPOS={},t.GPOS.parse=function(s,n,o,a){return t._lctf.parse(s,n,o,a,t.GPOS.subt)},t.GPOS.subt=function(s,n,o,a){var l=t._bin,d=o,u={};if(u.fmt=l.readUshort(s,o),o+=2,n==1||n==2||n==3||n==7||n==8&&u.fmt<=2){var m=l.readUshort(s,o);o+=2,u.coverage=t._lctf.readCoverage(s,m+d)}if(n==1&&u.fmt==1){var h=l.readUshort(s,o);o+=2,h!=0&&(u.pos=t.GPOS.readValueRecord(s,o,h))}else if(n==2&&u.fmt>=1&&u.fmt<=2){h=l.readUshort(s,o),o+=2;var p=l.readUshort(s,o);o+=2;var g=t._lctf.numOfOnes(h),b=t._lctf.numOfOnes(p);if(u.fmt==1){u.pairsets=[];var x=l.readUshort(s,o);o+=2;for(var w=0;w<x;w++){var v=d+l.readUshort(s,o);o+=2;var N=l.readUshort(s,v);v+=2;for(var y=[],k=0;k<N;k++){var S=l.readUshort(s,v);v+=2,h!=0&&(_=t.GPOS.readValueRecord(s,v,h),v+=2*g),p!=0&&(F=t.GPOS.readValueRecord(s,v,p),v+=2*b),y.push({gid2:S,val1:_,val2:F})}u.pairsets.push(y)}}if(u.fmt==2){var T=l.readUshort(s,o);o+=2;var E=l.readUshort(s,o);o+=2;var A=l.readUshort(s,o);o+=2;var M=l.readUshort(s,o);for(o+=2,u.classDef1=t._lctf.readClassDef(s,d+T),u.classDef2=t._lctf.readClassDef(s,d+E),u.matrix=[],w=0;w<A;w++){var R=[];for(k=0;k<M;k++){var _=null,F=null;h!=0&&(_=t.GPOS.readValueRecord(s,o,h),o+=2*g),p!=0&&(F=t.GPOS.readValueRecord(s,o,p),o+=2*b),R.push({val1:_,val2:F})}u.matrix.push(R)}}}else if(n==4&&u.fmt==1)u.markCoverage=t._lctf.readCoverage(s,l.readUshort(s,o)+d),u.baseCoverage=t._lctf.readCoverage(s,l.readUshort(s,o+2)+d),u.markClassCount=l.readUshort(s,o+4),u.markArray=t.GPOS.readMarkArray(s,l.readUshort(s,o+6)+d),u.baseArray=t.GPOS.readBaseArray(s,l.readUshort(s,o+8)+d,u.markClassCount);else if(n==6&&u.fmt==1)u.mark1Coverage=t._lctf.readCoverage(s,l.readUshort(s,o)+d),u.mark2Coverage=t._lctf.readCoverage(s,l.readUshort(s,o+2)+d),u.markClassCount=l.readUshort(s,o+4),u.mark1Array=t.GPOS.readMarkArray(s,l.readUshort(s,o+6)+d),u.mark2Array=t.GPOS.readBaseArray(s,l.readUshort(s,o+8)+d,u.markClassCount);else{if(n==9&&u.fmt==1){var C=l.readUshort(s,o);o+=2;var P=l.readUint(s,o);if(o+=4,a.ltype==9)a.ltype=C;else if(a.ltype!=C)throw"invalid extension substitution";return t.GPOS.subt(s,a.ltype,d+P)}console.debug("unsupported GPOS table LookupType",n,"format",u.fmt)}return u},t.GPOS.readValueRecord=function(s,n,o){var a=t._bin,l=[];return l.push(1&o?a.readShort(s,n):0),n+=1&o?2:0,l.push(2&o?a.readShort(s,n):0),n+=2&o?2:0,l.push(4&o?a.readShort(s,n):0),n+=4&o?2:0,l.push(8&o?a.readShort(s,n):0),n+=8&o?2:0,l},t.GPOS.readBaseArray=function(s,n,o){var a=t._bin,l=[],d=n,u=a.readUshort(s,n);n+=2;for(var m=0;m<u;m++){for(var h=[],p=0;p<o;p++)h.push(t.GPOS.readAnchorRecord(s,d+a.readUshort(s,n))),n+=2;l.push(h)}return l},t.GPOS.readMarkArray=function(s,n){var o=t._bin,a=[],l=n,d=o.readUshort(s,n);n+=2;for(var u=0;u<d;u++){var m=t.GPOS.readAnchorRecord(s,o.readUshort(s,n+2)+l);m.markClass=o.readUshort(s,n),a.push(m),n+=4}return a},t.GPOS.readAnchorRecord=function(s,n){var o=t._bin,a={};return a.fmt=o.readUshort(s,n),a.x=o.readShort(s,n+2),a.y=o.readShort(s,n+4),a},t.GSUB={},t.GSUB.parse=function(s,n,o,a){return t._lctf.parse(s,n,o,a,t.GSUB.subt)},t.GSUB.subt=function(s,n,o,a){var l=t._bin,d=o,u={};if(u.fmt=l.readUshort(s,o),o+=2,n!=1&&n!=2&&n!=4&&n!=5&&n!=6)return null;if(n==1||n==2||n==4||n==5&&u.fmt<=2||n==6&&u.fmt<=2){var m=l.readUshort(s,o);o+=2,u.coverage=t._lctf.readCoverage(s,d+m)}if(n==1&&u.fmt>=1&&u.fmt<=2){if(u.fmt==1)u.delta=l.readShort(s,o),o+=2;else if(u.fmt==2){var h=l.readUshort(s,o);o+=2,u.newg=l.readUshorts(s,o,h),o+=2*u.newg.length}}else if(n==2&&u.fmt==1){h=l.readUshort(s,o),o+=2,u.seqs=[];for(var p=0;p<h;p++){var g=l.readUshort(s,o)+d;o+=2;var b=l.readUshort(s,g);u.seqs.push(l.readUshorts(s,g+2,b))}}else if(n==4)for(u.vals=[],h=l.readUshort(s,o),o+=2,p=0;p<h;p++){var x=l.readUshort(s,o);o+=2,u.vals.push(t.GSUB.readLigatureSet(s,d+x))}else if(n==5&&u.fmt==2){if(u.fmt==2){var w=l.readUshort(s,o);o+=2,u.cDef=t._lctf.readClassDef(s,d+w),u.scset=[];var v=l.readUshort(s,o);for(o+=2,p=0;p<v;p++){var N=l.readUshort(s,o);o+=2,u.scset.push(N==0?null:t.GSUB.readSubClassSet(s,d+N))}}}else if(n==6&&u.fmt==3){if(u.fmt==3){for(p=0;p<3;p++){h=l.readUshort(s,o),o+=2;for(var y=[],k=0;k<h;k++)y.push(t._lctf.readCoverage(s,d+l.readUshort(s,o+2*k)));o+=2*h,p==0&&(u.backCvg=y),p==1&&(u.inptCvg=y),p==2&&(u.ahedCvg=y)}h=l.readUshort(s,o),o+=2,u.lookupRec=t.GSUB.readSubstLookupRecords(s,o,h)}}else{if(n==7&&u.fmt==1){var S=l.readUshort(s,o);o+=2;var T=l.readUint(s,o);if(o+=4,a.ltype==9)a.ltype=S;else if(a.ltype!=S)throw"invalid extension substitution";return t.GSUB.subt(s,a.ltype,d+T)}console.debug("unsupported GSUB table LookupType",n,"format",u.fmt)}return u},t.GSUB.readSubClassSet=function(s,n){var o=t._bin.readUshort,a=n,l=[],d=o(s,n);n+=2;for(var u=0;u<d;u++){var m=o(s,n);n+=2,l.push(t.GSUB.readSubClassRule(s,a+m))}return l},t.GSUB.readSubClassRule=function(s,n){var o=t._bin.readUshort,a={},l=o(s,n),d=o(s,n+=2);n+=2,a.input=[];for(var u=0;u<l-1;u++)a.input.push(o(s,n)),n+=2;return a.substLookupRecords=t.GSUB.readSubstLookupRecords(s,n,d),a},t.GSUB.readSubstLookupRecords=function(s,n,o){for(var a=t._bin.readUshort,l=[],d=0;d<o;d++)l.push(a(s,n),a(s,n+2)),n+=4;return l},t.GSUB.readChainSubClassSet=function(s,n){var o=t._bin,a=n,l=[],d=o.readUshort(s,n);n+=2;for(var u=0;u<d;u++){var m=o.readUshort(s,n);n+=2,l.push(t.GSUB.readChainSubClassRule(s,a+m))}return l},t.GSUB.readChainSubClassRule=function(s,n){for(var o=t._bin,a={},l=["backtrack","input","lookahead"],d=0;d<l.length;d++){var u=o.readUshort(s,n);n+=2,d==1&&u--,a[l[d]]=o.readUshorts(s,n,u),n+=2*a[l[d]].length}return u=o.readUshort(s,n),n+=2,a.subst=o.readUshorts(s,n,2*u),n+=2*a.subst.length,a},t.GSUB.readLigatureSet=function(s,n){var o=t._bin,a=n,l=[],d=o.readUshort(s,n);n+=2;for(var u=0;u<d;u++){var m=o.readUshort(s,n);n+=2,l.push(t.GSUB.readLigature(s,a+m))}return l},t.GSUB.readLigature=function(s,n){var o=t._bin,a={chain:[]};a.nglyph=o.readUshort(s,n),n+=2;var l=o.readUshort(s,n);n+=2;for(var d=0;d<l-1;d++)a.chain.push(o.readUshort(s,n)),n+=2;return a},t.head={},t.head.parse=function(s,n,o){var a=t._bin,l={};return a.readFixed(s,n),n+=4,l.fontRevision=a.readFixed(s,n),n+=4,a.readUint(s,n),n+=4,a.readUint(s,n),n+=4,l.flags=a.readUshort(s,n),n+=2,l.unitsPerEm=a.readUshort(s,n),n+=2,l.created=a.readUint64(s,n),n+=8,l.modified=a.readUint64(s,n),n+=8,l.xMin=a.readShort(s,n),n+=2,l.yMin=a.readShort(s,n),n+=2,l.xMax=a.readShort(s,n),n+=2,l.yMax=a.readShort(s,n),n+=2,l.macStyle=a.readUshort(s,n),n+=2,l.lowestRecPPEM=a.readUshort(s,n),n+=2,l.fontDirectionHint=a.readShort(s,n),n+=2,l.indexToLocFormat=a.readShort(s,n),n+=2,l.glyphDataFormat=a.readShort(s,n),n+=2,l},t.hhea={},t.hhea.parse=function(s,n,o){var a=t._bin,l={};return a.readFixed(s,n),n+=4,l.ascender=a.readShort(s,n),n+=2,l.descender=a.readShort(s,n),n+=2,l.lineGap=a.readShort(s,n),n+=2,l.advanceWidthMax=a.readUshort(s,n),n+=2,l.minLeftSideBearing=a.readShort(s,n),n+=2,l.minRightSideBearing=a.readShort(s,n),n+=2,l.xMaxExtent=a.readShort(s,n),n+=2,l.caretSlopeRise=a.readShort(s,n),n+=2,l.caretSlopeRun=a.readShort(s,n),n+=2,l.caretOffset=a.readShort(s,n),n+=2,n+=8,l.metricDataFormat=a.readShort(s,n),n+=2,l.numberOfHMetrics=a.readUshort(s,n),n+=2,l},t.hmtx={},t.hmtx.parse=function(s,n,o,a){for(var l=t._bin,d={aWidth:[],lsBearing:[]},u=0,m=0,h=0;h<a.maxp.numGlyphs;h++)h<a.hhea.numberOfHMetrics&&(u=l.readUshort(s,n),n+=2,m=l.readShort(s,n),n+=2),d.aWidth.push(u),d.lsBearing.push(m);return d},t.kern={},t.kern.parse=function(s,n,o,a){var l=t._bin,d=l.readUshort(s,n);if(n+=2,d==1)return t.kern.parseV1(s,n-2,o,a);var u=l.readUshort(s,n);n+=2;for(var m={glyph1:[],rval:[]},h=0;h<u;h++){n+=2,o=l.readUshort(s,n),n+=2;var p=l.readUshort(s,n);n+=2;var g=p>>>8;if((g&=15)!=0)throw"unknown kern table format: "+g;n=t.kern.readFormat0(s,n,m)}return m},t.kern.parseV1=function(s,n,o,a){var l=t._bin;l.readFixed(s,n),n+=4;var d=l.readUint(s,n);n+=4;for(var u={glyph1:[],rval:[]},m=0;m<d;m++){l.readUint(s,n),n+=4;var h=l.readUshort(s,n);n+=2,l.readUshort(s,n),n+=2;
45var p=h>>>8;if((p&=15)!=0)throw"unknown kern table format: "+p;n=t.kern.readFormat0(s,n,u)}return u},t.kern.readFormat0=function(s,n,o){var a=t._bin,l=-1,d=a.readUshort(s,n);n+=2,a.readUshort(s,n),n+=2,a.readUshort(s,n),n+=2,a.readUshort(s,n),n+=2;for(var u=0;u<d;u++){var m=a.readUshort(s,n);n+=2;var h=a.readUshort(s,n);n+=2;var p=a.readShort(s,n);n+=2,m!=l&&(o.glyph1.push(m),o.rval.push({glyph2:[],vals:[]}));var g=o.rval[o.rval.length-1];g.glyph2.push(h),g.vals.push(p),l=m}return n},t.loca={},t.loca.parse=function(s,n,o,a){var l=t._bin,d=[],u=a.head.indexToLocFormat,m=a.maxp.numGlyphs+1;if(u==0)for(var h=0;h<m;h++)d.push(l.readUshort(s,n+(h<<1))<<1);if(u==1)for(h=0;h<m;h++)d.push(l.readUint(s,n+(h<<2)));return d},t.maxp={},t.maxp.parse=function(s,n,o){var a=t._bin,l={},d=a.readUint(s,n);return n+=4,l.numGlyphs=a.readUshort(s,n),n+=2,d==65536&&(l.maxPoints=a.readUshort(s,n),n+=2,l.maxContours=a.readUshort(s,n),n+=2,l.maxCompositePoints=a.readUshort(s,n),n+=2,l.maxCompositeContours=a.readUshort(s,n),n+=2,l.maxZones=a.readUshort(s,n),n+=2,l.maxTwilightPoints=a.readUshort(s,n),n+=2,l.maxStorage=a.readUshort(s,n),n+=2,l.maxFunctionDefs=a.readUshort(s,n),n+=2,l.maxInstructionDefs=a.readUshort(s,n),n+=2,l.maxStackElements=a.readUshort(s,n),n+=2,l.maxSizeOfInstructions=a.readUshort(s,n),n+=2,l.maxComponentElements=a.readUshort(s,n),n+=2,l.maxComponentDepth=a.readUshort(s,n),n+=2),l},t.name={},t.name.parse=function(s,n,o){var a=t._bin,l={};a.readUshort(s,n),n+=2;var d=a.readUshort(s,n);n+=2,a.readUshort(s,n);for(var u,m=["copyright","fontFamily","fontSubfamily","ID","fullName","version","postScriptName","trademark","manufacturer","designer","description","urlVendor","urlDesigner","licence","licenceURL","---","typoFamilyName","typoSubfamilyName","compatibleFull","sampleText","postScriptCID","wwsFamilyName","wwsSubfamilyName","lightPalette","darkPalette"],h=n+=2,p=0;p<d;p++){var g=a.readUshort(s,n);n+=2;var b=a.readUshort(s,n);n+=2;var x=a.readUshort(s,n);n+=2;var w=a.readUshort(s,n);n+=2;var v=a.readUshort(s,n);n+=2;var N=a.readUshort(s,n);n+=2;var y,k=m[w],S=h+12*d+N;if(g==0)y=a.readUnicode(s,S,v/2);else if(g==3&&b==0)y=a.readUnicode(s,S,v/2);else if(b==0)y=a.readASCII(s,S,v);else if(b==1)y=a.readUnicode(s,S,v/2);else if(b==3)y=a.readUnicode(s,S,v/2);else{if(g!=1)throw"unknown encoding "+b+", platformID: "+g;y=a.readASCII(s,S,v),console.debug("reading unknown MAC encoding "+b+" as ASCII")}var T="p"+g+","+x.toString(16);l[T]==null&&(l[T]={}),l[T][k!==void 0?k:w]=y,l[T]._lang=x}for(var E in l)if(l[E].postScriptName!=null&&l[E]._lang==1033)return l[E];for(var E in l)if(l[E].postScriptName!=null&&l[E]._lang==0)return l[E];for(var E in l)if(l[E].postScriptName!=null&&l[E]._lang==3084)return l[E];for(var E in l)if(l[E].postScriptName!=null)return l[E];for(var E in l){u=E;break}return console.debug("returning name table with languageID "+l[u]._lang),l[u]},t["OS/2"]={},t["OS/2"].parse=function(s,n,o){var a=t._bin.readUshort(s,n);n+=2;var l={};if(a==0)t["OS/2"].version0(s,n,l);else if(a==1)t["OS/2"].version1(s,n,l);else if(a==2||a==3||a==4)t["OS/2"].version2(s,n,l);else{if(a!=5)throw"unknown OS/2 table version: "+a;t["OS/2"].version5(s,n,l)}return l},t["OS/2"].version0=function(s,n,o){var a=t._bin;return o.xAvgCharWidth=a.readShort(s,n),n+=2,o.usWeightClass=a.readUshort(s,n),n+=2,o.usWidthClass=a.readUshort(s,n),n+=2,o.fsType=a.readUshort(s,n),n+=2,o.ySubscriptXSize=a.readShort(s,n),n+=2,o.ySubscriptYSize=a.readShort(s,n),n+=2,o.ySubscriptXOffset=a.readShort(s,n),n+=2,o.ySubscriptYOffset=a.readShort(s,n),n+=2,o.ySuperscriptXSize=a.readShort(s,n),n+=2,o.ySuperscriptYSize=a.readShort(s,n),n+=2,o.ySuperscriptXOffset=a.readShort(s,n),n+=2,o.ySuperscriptYOffset=a.readShort(s,n),n+=2,o.yStrikeoutSize=a.readShort(s,n),n+=2,o.yStrikeoutPosition=a.readShort(s,n),n+=2,o.sFamilyClass=a.readShort(s,n),n+=2,o.panose=a.readBytes(s,n,10),n+=10,o.ulUnicodeRange1=a.readUint(s,n),n+=4,o.ulUnicodeRange2=a.readUint(s,n),n+=4,o.ulUnicodeRange3=a.readUint(s,n),n+=4,o.ulUnicodeRange4=a.readUint(s,n),n+=4,o.achVendID=[a.readInt8(s,n),a.readInt8(s,n+1),a.readInt8(s,n+2),a.readInt8(s,n+3)],n+=4,o.fsSelection=a.readUshort(s,n),n+=2,o.usFirstCharIndex=a.readUshort(s,n),n+=2,o.usLastCharIndex=a.readUshort(s,n),n+=2,o.sTypoAscender=a.readShort(s,n),n+=2,o.sTypoDescender=a.readShort(s,n),n+=2,o.sTypoLineGap=a.readShort(s,n),n+=2,o.usWinAscent=a.readUshort(s,n),n+=2,o.usWinDescent=a.readUshort(s,n),n+=2},t["OS/2"].version1=function(s,n,o){var a=t._bin;return n=t["OS/2"].version0(s,n,o),o.ulCodePageRange1=a.readUint(s,n),n+=4,o.ulCodePageRange2=a.readUint(s,n),n+=4},t["OS/2"].version2=function(s,n,o){var a=t._bin;return n=t["OS/2"].version1(s,n,o),o.sxHeight=a.readShort(s,n),n+=2,o.sCapHeight=a.readShort(s,n),n+=2,o.usDefault=a.readUshort(s,n),n+=2,o.usBreak=a.readUshort(s,n),n+=2,o.usMaxContext=a.readUshort(s,n),n+=2},t["OS/2"].version5=function(s,n,o){var a=t._bin;return n=t["OS/2"].version2(s,n,o),o.usLowerOpticalPointSize=a.readUshort(s,n),n+=2,o.usUpperOpticalPointSize=a.readUshort(s,n),n+=2},t.post={},t.post.parse=function(s,n,o){var a=t._bin,l={};return l.version=a.readFixed(s,n),n+=4,l.italicAngle=a.readFixed(s,n),n+=4,l.underlinePosition=a.readShort(s,n),n+=2,l.underlineThickness=a.readShort(s,n),n+=2,l},t==null&&(t={}),t.U==null&&(t.U={}),t.U.codeToGlyph=function(s,n){var o=s.cmap,a=-1;if(o.p0e4!=null?a=o.p0e4:o.p3e1!=null?a=o.p3e1:o.p1e0!=null?a=o.p1e0:o.p0e3!=null&&(a=o.p0e3),a==-1)throw"no familiar platform and encoding!";var l=o.tables[a];if(l.format==0)return n>=l.map.length?0:l.map[n];if(l.format==4){for(var d=-1,u=0;u<l.endCount.length;u++)if(n<=l.endCount[u]){d=u;break}
45return d==-1||l.startCount[d]>n?0:65535&(l.idRangeOffset[d]!=0?l.glyphIdArray[n-l.startCount[d]+(l.idRangeOffset[d]>>1)-(l.idRangeOffset.length-d)]:n+l.idDelta[d])}if(l.format==12){if(n>l.groups[l.groups.length-1][1])return 0;for(u=0;u<l.groups.length;u++){var m=l.groups[u];if(m[0]<=n&&n<=m[1])return m[2]+(n-m[0])}return 0}throw"unknown cmap table format "+l.format},t.U.glyphToPath=function(s,n){var o={cmds:[],crds:[]};if(s.SVG&&s.SVG.entries[n]){var a=s.SVG.entries[n];return a==null?o:(typeof a=="string"&&(a=t.SVG.toPath(a),s.SVG.entries[n]=a),a)}if(s.CFF){var l={x:0,y:0,stack:[],nStems:0,haveWidth:!1,width:s.CFF.Private?s.CFF.Private.defaultWidthX:0,open:!1},d=s.CFF,u=s.CFF.Private;if(d.ROS){for(var m=0;d.FDSelect[m+2]<=n;)m+=2;u=d.FDArray[d.FDSelect[m+1]].Private}t.U._drawCFF(s.CFF.CharStrings[n],l,d,u,o)}else s.glyf&&t.U._drawGlyf(n,s,o);return o},t.U._drawGlyf=function(s,n,o){var a=n.glyf[s];a==null&&(a=n.glyf[s]=t.glyf._parseGlyf(n,s)),a!=null&&(a.noc>-1?t.U._simpleGlyph(a,o):t.U._compoGlyph(a,n,o))},t.U._simpleGlyph=function(s,n){for(var o=0;o<s.noc;o++){for(var a=o==0?0:s.endPts[o-1]+1,l=s.endPts[o],d=a;d<=l;d++){var u=d==a?l:d-1,m=d==l?a:d+1,h=1&s.flags[d],p=1&s.flags[u],g=1&s.flags[m],b=s.xs[d],x=s.ys[d];if(d==a)if(h){if(!p){t.U.P.moveTo(n,b,x);continue}t.U.P.moveTo(n,s.xs[u],s.ys[u])}else p?t.U.P.moveTo(n,s.xs[u],s.ys[u]):t.U.P.moveTo(n,(s.xs[u]+b)/2,(s.ys[u]+x)/2);h?p&&t.U.P.lineTo(n,b,x):g?t.U.P.qcurveTo(n,b,x,s.xs[m],s.ys[m]):t.U.P.qcurveTo(n,b,x,(b+s.xs[m])/2,(x+s.ys[m])/2)}t.U.P.closePath(n)}},t.U._compoGlyph=function(s,n,o){for(var a=0;a<s.parts.length;a++){var l={cmds:[],crds:[]},d=s.parts[a];t.U._drawGlyf(d.glyphIndex,n,l);for(var u=d.m,m=0;m<l.crds.length;m+=2){var h=l.crds[m],p=l.crds[m+1];o.crds.push(h*u.a+p*u.b+u.tx),o.crds.push(h*u.c+p*u.d+u.ty)}for(m=0;m<l.cmds.length;m++)o.cmds.push(l.cmds[m])}},t.U._getGlyphClass=function(s,n){var o=t._lctf.getInterval(n,s);return o==-1?0:n[o+2]},t.U._applySubs=function(s,n,o,a){for(var l=s.length-n-1,d=0;d<o.tabs.length;d++)if(o.tabs[d]!=null){var u,m=o.tabs[d];if(!m.coverage||(u=t._lctf.coverageIndex(m.coverage,s[n]))!=-1){if(o.ltype==1)s[n],m.fmt==1?s[n]=s[n]+m.delta:s[n]=m.newg[u];else if(o.ltype==4)for(var h=m.vals[u],p=0;p<h.length;p++){var g=h[p],b=g.chain.length;if(!(b>l)){for(var x=!0,w=0,v=0;v<b;v++){for(;s[n+w+(1+v)]==-1;)w++;g.chain[v]!=s[n+w+(1+v)]&&(x=!1)}if(x){for(s[n]=g.nglyph,v=0;v<b+w;v++)s[n+v+1]=-1;break}}}else if(o.ltype==5&&m.fmt==2)for(var N=t._lctf.getInterval(m.cDef,s[n]),y=m.cDef[N+2],k=m.scset[y],S=0;S<k.length;S++){var T=k[S],E=T.input;if(!(E.length>l)){for(x=!0,v=0;v<E.length;v++){var A=t._lctf.getInterval(m.cDef,s[n+1+v]);if(N==-1&&m.cDef[A+2]!=E[v]){x=!1;break}}if(x){var M=T.substLookupRecords;for(p=0;p<M.length;p+=2)M[p],M[p+1]}}}else if(o.ltype==6&&m.fmt==3){if(!t.U._glsCovered(s,m.backCvg,n-m.backCvg.length)||!t.U._glsCovered(s,m.inptCvg,n)||!t.U._glsCovered(s,m.ahedCvg,n+m.inptCvg.length))continue;var R=m.lookupRec;for(S=0;S<R.length;S+=2){N=R[S];var _=a[R[S+1]];t.U._applySubs(s,n+N,_,a)}}}}},t.U._glsCovered=function(s,n,o){for(var a=0;a<n.length;a++)if(t._lctf.coverageIndex(n[a],s[o+a])==-1)return!1;return!0},t.U.glyphsToPath=function(s,n,o){for(var a={cmds:[],crds:[]},l=0,d=0;d<n.length;d++){var u=n[d];if(u!=-1){for(var m=d<n.length-1&&n[d+1]!=-1?n[d+1]:0,h=t.U.glyphToPath(s,u),p=0;p<h.crds.length;p+=2)a.crds.push(h.crds[p]+l),a.crds.push(h.crds[p+1]);for(o&&a.cmds.push(o),p=0;p<h.cmds.length;p++)a.cmds.push(h.cmds[p]);o&&a.cmds.push("X"),l+=s.hmtx.aWidth[u],d<n.length-1&&(l+=t.U.getPairAdjustment(s,u,m))}}return a},t.U.P={},t.U.P.moveTo=function(s,n,o){s.cmds.push("M"),s.crds.push(n,o)},t.U.P.lineTo=function(s,n,o){s.cmds.push("L"),s.crds.push(n,o)},t.U.P.curveTo=function(s,n,o,a,l,d,u){s.cmds.push("C"),s.crds.push(n,o,a,l,d,u)},t.U.P.qcurveTo=function(s,n,o,a,l){s.cmds.push("Q"),s.crds.push(n,o,a,l)},t.U.P.closePath=function(s){s.cmds.push("Z")},t.U._drawCFF=function(s,n,o,a,l){for(var d=n.stack,u=n.nStems,m=n.haveWidth,h=n.width,p=n.open,g=0,b=n.x,x=n.y,w=0,v=0,N=0,y=0,k=0,S=0,T=0,E=0,A=0,M=0,R={val:0,size:0};g<s.length;){t.CFF.getCharString(s,g,R);var _=R.val;if(g+=R.size,_=="o1"||_=="o18")d.length%2!=0&&!m&&(h=d.shift()+a.nominalWidthX),u+=d.length>>1,d.length=0,m=!0;else if(_=="o3"||_=="o23")d.length%2!=0&&!m&&(h=d.shift()+a.nominalWidthX),u+=d.length>>1,d.length=0,m=!0;else if(_=="o4")d.length>1&&!m&&(h=d.shift()+a.nominalWidthX,m=!0),p&&t.U.P.closePath(l),x+=d.pop(),t.U.P.moveTo(l,b,x),p=!0;else if(_=="o5")for(;d.length>0;)b+=d.shift(),x+=d.shift(),t.U.P.lineTo(l,b,x);else if(_=="o6"||_=="o7")for(var F=d.length,C=_=="o6",P=0;P<F;P++){var U=d.shift();C?b+=U:x+=U,C=!C,t.U.P.lineTo(l,b,x)}else if(_=="o8"||_=="o24"){F=d.length;for(var K=0;K+6<=F;)w=b+d.shift(),v=x+d.shift(),N=w+d.shift(),y=v+d.shift(),b=N+d.shift(),x=y+d.shift(),t.U.P.curveTo(l,w,v,N,y,b,x),K+=6;_=="o24"&&(b+=d.shift(),x+=d.shift(),t.U.P.lineTo(l,b,x))}else{if(_=="o11")break;
45if(_=="o1234"||_=="o1235"||_=="o1236"||_=="o1237")_=="o1234"&&(v=x,N=(w=b+d.shift())+d.shift(),M=y=v+d.shift(),S=y,E=x,b=(T=(k=(A=N+d.shift())+d.shift())+d.shift())+d.shift(),t.U.P.curveTo(l,w,v,N,y,A,M),t.U.P.curveTo(l,k,S,T,E,b,x)),_=="o1235"&&(w=b+d.shift(),v=x+d.shift(),N=w+d.shift(),y=v+d.shift(),A=N+d.shift(),M=y+d.shift(),k=A+d.shift(),S=M+d.shift(),T=k+d.shift(),E=S+d.shift(),b=T+d.shift(),x=E+d.shift(),d.shift(),t.U.P.curveTo(l,w,v,N,y,A,M),t.U.P.curveTo(l,k,S,T,E,b,x)),_=="o1236"&&(w=b+d.shift(),v=x+d.shift(),N=w+d.shift(),M=y=v+d.shift(),S=y,T=(k=(A=N+d.shift())+d.shift())+d.shift(),E=S+d.shift(),b=T+d.shift(),t.U.P.curveTo(l,w,v,N,y,A,M),t.U.P.curveTo(l,k,S,T,E,b,x)),_=="o1237"&&(w=b+d.shift(),v=x+d.shift(),N=w+d.shift(),y=v+d.shift(),A=N+d.shift(),M=y+d.shift(),k=A+d.shift(),S=M+d.shift(),T=k+d.shift(),E=S+d.shift(),Math.abs(T-b)>Math.abs(E-x)?b=T+d.shift():x=E+d.shift(),t.U.P.curveTo(l,w,v,N,y,A,M),t.U.P.curveTo(l,k,S,T,E,b,x));else if(_=="o14"){if(d.length>0&&!m&&(h=d.shift()+o.nominalWidthX,m=!0),d.length==4){var z=d.shift(),O=d.shift(),L=d.shift(),j=d.shift(),D=t.CFF.glyphBySE(o,L),I=t.CFF.glyphBySE(o,j);t.U._drawCFF(o.CharStrings[D],n,o,a,l),n.x=z,n.y=O,t.U._drawCFF(o.CharStrings[I],n,o,a,l)}p&&(t.U.P.closePath(l),p=!1)}else if(_=="o19"||_=="o20")d.length%2!=0&&!m&&(h=d.shift()+a.nominalWidthX),u+=d.length>>1,d.length=0,m=!0,g+=u+7>>3;else if(_=="o21")d.length>2&&!m&&(h=d.shift()+a.nominalWidthX,m=!0),x+=d.pop(),b+=d.pop(),p&&t.U.P.closePath(l),t.U.P.moveTo(l,b,x),p=!0;else if(_=="o22")d.length>1&&!m&&(h=d.shift()+a.nominalWidthX,m=!0),b+=d.pop(),p&&t.U.P.closePath(l),t.U.P.moveTo(l,b,x),p=!0;else if(_=="o25"){for(;d.length>6;)b+=d.shift(),x+=d.shift(),t.U.P.lineTo(l,b,x);w=b+d.shift(),v=x+d.shift(),N=w+d.shift(),y=v+d.shift(),b=N+d.shift(),x=y+d.shift(),t.U.P.curveTo(l,w,v,N,y,b,x)}else if(_=="o26")for(d.length%2&&(b+=d.shift());d.length>0;)w=b,v=x+d.shift(),b=N=w+d.shift(),x=(y=v+d.shift())+d.shift(),t.U.P.curveTo(l,w,v,N,y,b,x);else if(_=="o27")for(d.length%2&&(x+=d.shift());d.length>0;)v=x,N=(w=b+d.shift())+d.shift(),y=v+d.shift(),b=N+d.shift(),x=y,t.U.P.curveTo(l,w,v,N,y,b,x);else if(_=="o10"||_=="o29"){var B=_=="o10"?a:o;if(d.length==0)console.debug("error: empty stack");else{var G=d.pop(),q=B.Subrs[G+B.Bias];n.x=b,n.y=x,n.nStems=u,n.haveWidth=m,n.width=h,n.open=p,t.U._drawCFF(q,n,o,a,l),b=n.x,x=n.y,u=n.nStems,m=n.haveWidth,h=n.width,p=n.open}}else if(_=="o30"||_=="o31"){var V=d.length,W=(K=0,_=="o31");for(K+=V-(F=-3&V);K<F;)W?(v=x,N=(w=b+d.shift())+d.shift(),x=(y=v+d.shift())+d.shift(),F-K==5?(b=N+d.shift(),K++):b=N,W=!1):(w=b,v=x+d.shift(),N=w+d.shift(),y=v+d.shift(),b=N+d.shift(),F-K==5?(x=y+d.shift(),K++):x=y,W=!0),t.U.P.curveTo(l,w,v,N,y,b,x),K+=4}else{if((_+"").charAt(0)=="o")throw console.debug("Unknown operation: "+_,s),_;d.push(_)}}}n.x=b,n.y=x,n.nStems=u,n.haveWidth=m,n.width=h,n.open=p};var i=t,c={Typr:i};return e.Typr=i,e.default=c,Object.defineProperty(e,"__esModule",{value:!0}),e}({}).Typr}/*!
46Custom bundle of woff2otf (https://github.com/arty-name/woff2otf) with fflate
47(https://github.com/101arrowz/fflate) for use in Troika text rendering. 
48Original licenses apply: 
49- fflate: https://github.com/101arrowz/fflate/blob/master/LICENSE (MIT)
50- woff2otf.js: https://github.com/arty-name/woff2otf/blob/master/woff2otf.js (Apache2)
51*/function eu(){return function(e){var t=Uint8Array,i=Uint16Array,c=Uint32Array,s=new t([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]),n=new t([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0]),o=new t([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),a=function(_,F){for(var C=new i(31),P=0;P<31;++P)C[P]=F+=1<<_[P-1];var U=new c(C[30]);for(P=1;P<30;++P)for(var K=C[P];K<C[P+1];++K)U[K]=K-C[P]<<5|P;return[C,U]},l=a(s,2),d=l[0],u=l[1];d[28]=258,u[258]=28;for(var m=a(n,0)[0],h=new i(32768),p=0;p<32768;++p){var g=(43690&p)>>>1|(21845&p)<<1;g=(61680&(g=(52428&g)>>>2|(13107&g)<<2))>>>4|(3855&g)<<4,h[p]=((65280&g)>>>8|(255&g)<<8)>>>1}var b=function(_,F,C){for(var P=_.length,U=0,K=new i(F);U<P;++U)++K[_[U]-1];var z,O=new i(F);for(U=0;U<F;++U)O[U]=O[U-1]+K[U-1]<<1;{z=new i(1<<F);var L=15-F;for(U=0;U<P;++U)if(_[U])for(var j=U<<4|_[U],D=F-_[U],I=O[_[U]-1]++<<D,B=I|(1<<D)-1;I<=B;++I)z[h[I]>>>L]=j}return z},x=new t(288);for(p=0;p<144;++p)x[p]=8;for(p=144;p<256;++p)x[p]=9;for(p=256;p<280;++p)x[p]=7;for(p=280;p<288;++p)x[p]=8;var w=new t(32);for(p=0;p<32;++p)w[p]=5;var v=b(x,9),N=b(w,5),y=function(_){for(var F=_[0],C=1;C<_.length;++C)_[C]>F&&(F=_[C]);return F},k=function(_,F,C){var P=F/8|0;
51return(_[P]|_[P+1]<<8)>>(7&F)&C},S=function(_,F){var C=F/8|0;return(_[C]|_[C+1]<<8|_[C+2]<<16)>>(7&F)},T=["unexpected EOF","invalid block type","invalid length/literal","invalid distance","stream finished","no stream handler",,"no callback","invalid UTF-8 data","extra field too long","date not in range 1980-2099","filename too long","stream finishing","invalid zip data"],E=function(_,F,C){var P=new Error(F||T[_]);if(P.code=_,Error.captureStackTrace&&Error.captureStackTrace(P,E),!C)throw P;return P},A=function(_,F,C){var P=_.length;if(!P||C&&!C.l&&P<5)return F||new t(0);var U=!F||C,K=!C||C.i;C||(C={}),F||(F=new t(3*P));var z,O=function(pe){var Fe=F.length;if(pe>Fe){var Le=new t(Math.max(2*Fe,pe));Le.set(F),F=Le}},L=C.f||0,j=C.p||0,D=C.b||0,I=C.l,B=C.d,G=C.m,q=C.n,V=8*P;do{if(!I){C.f=L=k(_,j,1);var W=k(_,j+1,3);if(j+=3,!W){var ee=_[(ie=((z=j)/8|0)+(7&z&&1)+4)-4]|_[ie-3]<<8,ne=ie+ee;if(ne>P){K&&E(0);break}U&&O(D+ee),F.set(_.subarray(ie,ne),D),C.b=D+=ee,C.p=j=8*ne;continue}if(W==1)I=v,B=N,G=9,q=5;else if(W==2){var J=k(_,j,31)+257,$=k(_,j+10,15)+4,ge=J+k(_,j+5,31)+1;j+=14;for(var ce=new t(ge),re=new t(19),oe=0;oe<$;++oe)re[o[oe]]=k(_,j+3*oe,7);j+=3*$;var de=y(re),Z=(1<<de)-1,le=b(re,de);for(oe=0;oe<ge;){var ie,Q=le[k(_,j,Z)];if(j+=15&Q,(ie=Q>>>4)<16)ce[oe++]=ie;else{var be=0,ae=0;for(ie==16?(ae=3+k(_,j,3),j+=2,be=ce[oe-1]):ie==17?(ae=3+k(_,j,7),j+=3):ie==18&&(ae=11+k(_,j,127),j+=7);ae--;)ce[oe++]=be}}var fe=ce.subarray(0,J),se=ce.subarray(J);G=y(fe),q=y(se),I=b(fe,G),B=b(se,q)}else E(1);if(j>V){K&&E(0);break}}U&&O(D+131072);for(var Ne=(1<<G)-1,ue=(1<<q)-1,he=j;;he=j){var Y=(be=I[S(_,j)&Ne])>>>4;if((j+=15&be)>V){K&&E(0);break}if(be||E(2),Y<256)F[D++]=Y;else{if(Y==256){he=j,I=null;break}var X=Y-254;if(Y>264){var ye=s[oe=Y-257];X=k(_,j,(1<<ye)-1)+d[oe],j+=ye}var ke=B[S(_,j)&ue],we=ke>>>4;if(ke||E(3),j+=15&ke,se=m[we],we>3&&(ye=n[we],se+=S(_,j)&(1<<ye)-1,j+=ye),j>V){K&&E(0);break}U&&O(D+131072);for(var je=D+X;D<je;D+=4)F[D]=F[D-se],F[D+1]=F[D+1-se],F[D+2]=F[D+2-se],F[D+3]=F[D+3-se];D=je}}C.l=I,C.p=he,C.b=D,I&&(L=1,C.m=G,C.d=B,C.n=q)}while(!L);return D==F.length?F:function(pe,Fe,Le){(Le==null||Le>pe.length)&&(Le=pe.length);var qe=new(pe instanceof i?i:pe instanceof c?c:t)(Le-Fe);return qe.set(pe.subarray(Fe,Le)),qe}(F,0,D)},M=new t(0),R=typeof TextDecoder<"u"&&new TextDecoder;try{R.decode(M,{stream:!0})}catch{}return e.convert_streams=function(_){var F=new DataView(_),C=0;function P(){var J=F.getUint16(C);return C+=2,J}function U(){var J=F.getUint32(C);return C+=4,J}function K(J){ee.setUint16(ne,J),ne+=2}function z(J){ee.setUint32(ne,J),ne+=4}for(var O={signature:U(),flavor:U(),length:U(),numTables:P(),reserved:P(),totalSfntSize:U(),majorVersion:P(),minorVersion:P(),metaOffset:U(),metaLength:U(),metaOrigLength:U(),privOffset:U(),privLength:U()},L=0;Math.pow(2,L)<=O.numTables;)L++;L--;for(var j=16*Math.pow(2,L),D=16*O.numTables-j,I=12,B=[],G=0;G<O.numTables;G++)B.push({tag:U(),offset:U(),compLength:U(),origLength:U(),origChecksum:U()}),I+=16;var q,V=new Uint8Array(12+16*B.length+B.reduce(function(J,$){return J+$.origLength+4},0)),W=V.buffer,ee=new DataView(W),ne=0;return z(O.flavor),K(O.numTables),K(j),K(L),K(D),B.forEach(function(J){z(J.tag),z(J.origChecksum),z(I),z(J.origLength),J.outOffset=I,(I+=J.origLength)%4!=0&&(I+=4-I%4)}),B.forEach(function(J){var $,ge=_.slice(J.offset,J.offset+J.compLength);if(J.compLength!=J.origLength){var ce=new Uint8Array(J.origLength);$=new Uint8Array(ge,2),A($,ce)}else ce=new Uint8Array(ge);V.set(ce,J.outOffset);var re=0;(I=J.outOffset+J.origLength)%4!=0&&(re=4-I%4),V.set(new Uint8Array(re).buffer,J.outOffset+J.origLength),q=I+re}),W.slice(0,q)},Object.defineProperty(e,"__esModule",{value:!0}),e}({}).convert_streams}function tu(e,t){const i={M:2,L:2,Q:4,C:6,Z:0},c={C:"18g,ca,368,1kz",D:"17k,6,2,2+4,5+c,2+6,2+1,10+1,9+f,j+11,2+1,a,2,2+1,15+2,3,j+2,6+3,2+8,2,2,2+1,w+a,4+e,3+3,2,3+2,3+5,23+w,2f+4,3,2+9,2,b,2+3,3,1k+9,6+1,3+1,2+2,2+d,30g,p+y,1,1+1g,f+x,2,sd2+1d,jf3+4,f+3,2+4,2+2,b+3,42,2,4+2,2+1,2,3,t+1,9f+w,2,el+2,2+g,d+2,2l,2+1,5,3+1,2+1,2,3,6,16wm+1v",R:"17m+3,2,2,6+3,m,15+2,2+2,h+h,13,3+8,2,2,3+1,2,p+1,x,5+4,5,a,2,2,3,u,c+2,g+1,5,2+1,4+1,5j,6+1,2,b,2+2,f,2+1,1s+2,2,3+1,7,1ez0,2,2+1,4+4,b,4,3,b,42,2+2,4,3,2+1,2,o+3,ae,ep,x,2o+2,3+1,3,5+1,6",L:"x9u,jff,a,fd,jv",T:"4t,gj+33,7o+4,1+1,7c+18,2,2+1,2+1,2,21+a,2,1b+k,h,2u+6,3+5,3+1,2+3,y,2,v+q,2k+a,1n+8,a,p+3,2+8,2+2,2+4,18+2,3c+e,2+v,1k,2,5+7,5,4+6,b+1,u,1n,5+3,9,l+1,r,3+1,1m,5+1,5+1,3+2,4,v+1,4,c+1,1m,5+4,2+1,5,l+1,n+5,2,1n,3,2+3,9,8+1,c+1,v,1q,d,1f,4,1m+2,6+2,2+3,8+1,c+1,u,1n,3,7,6+1,l+1,t+1,1m+1,5+3,9,l+1,u,21,8+2,2,2j,3+6,d+7,2r,3+8,c+5,23+1,s,2,2,1k+d,2+4,2+1,6+a,2+z,a,2v+3,2+5,2+1,3+1,q+1,5+2,h+3,e,3+1,7,g,jk+2,qb+2,u+2,u+1,v+1,1t+1,2+6,9,3+a,a,1a+2,3c+1,z,3b+2,5+1,a,7+2,64+1,3,1n,2+6,2,2,3+7,7+9,3,1d+d,1,1+1,1s+3,1d,2+4,2,6,15+8,d+1,x+3,3+1,2+2,1l,2+1,4,2+2,1n+7,3+1,49+2,2+c,2+6,5,7,4+1,5j+1l,2+4,ek,3+1,r+4,1e+4,6+5,2p+c,1+3,1,1+2,1+b,2db+2,3y,2p+v,ff+3,30+1,n9x,1+2,2+9,x+1,29+1,7l,4,5,q+1,6,48+1,r+h,e,13+7,q+a,1b+2,1d,3+3,3+1,14,1w+5,3+1,3+1,d,9,1c,1g,2+2,3+1,6+1,2,17+1,9,6n,3,5,fn5,ki+f,h+f,5s,6y+2,ea,6b,46+4,1af+2,2+1,6+3,15+2,5,4m+1,fy+3,as+1,4a+a,4x,1j+e,1l+2,1e+3,3+1,1y+2,11+4,2+7,1r,d+1,1h+8,b+3,3,2o+2,3,2+1,7,4h,4+7,m+1,1m+1,4,12+6,4+4,5g+7,3+2,2,o,2d+5,2,5+1,2+1,6n+3,7+1,2+1,s+1,2e+7,3,2+1,2z,2,3+5,2,2u+2,3+3,2+4,78+8,2+1,75+1,2,5,41+3,3+1,5,x+9,15+5,3+3,9,a+5,3+2,1b+c,2+1,bb+6,2+5,2,2b+l,3+6,2+1,2+1,3f+5,4,2+1,2+6,2,21+1,4,2,9o+1,470+8,at4+4,1o+6,t5,1s+3,2a,f5l+1,2+3,43o+2,a+7,1+7,3+6,v+3,45+2,1j0+1i,5+1d,9,f,n+4,2+e,11t+6,2+g,3+6,2+1,2+4,7a+6,c6+3,15t+6,32+6,1,gzau,v+2n,3l+6n"},s=1,n=2,o=4,a=8,l=16,d=32;let u;function m(T){if(!u){const E={R:n,L:s,D:o,C:l,U:d,T:a};u=new Map;for(let A in c){let M=0;c[A].split(",").forEach(R=>{let[_,F]=R.split("+");_=parseInt(_,36),F=F?parseInt(F,36):0,u.set(M+=_,E[A]);for(let C=F;C--;)u.set(++M,E[A])})}}return u.get(T)||d}const h=1,p=2,g=3,b=4,x=[null,"isol","init","fina","medi"];function w(T){const E=new Uint8Array(T.length);let A=d,M=h,R=-1;for(let _=0;_<T.length;_++){const F=T.codePointAt(_);let C=m(F)|0,P=h;
51C&a||(A&(s|o|l)?C&(n|o|l)?(P=g,(M===h||M===g)&&E[R]++):C&(s|d)&&(M===p||M===b)&&E[R]--:A&(n|d)&&(M===p||M===b)&&E[R]--,M=E[_]=P,A=C,R=_,F>65535&&_++)}return E}function v(T,E){const A=[];for(let R=0;R<E.length;R++){const _=E.codePointAt(R);_>65535&&R++,A.push(e.U.codeToGlyph(T,_))}const M=T.GSUB;if(M){const{lookupList:R,featureList:_}=M;let F;const C=/^(rlig|liga|mset|isol|init|fina|medi|half|pres|blws|ccmp)$/,P=[];_.forEach(U=>{if(C.test(U.tag))for(let K=0;K<U.tab.length;K++){if(P[U.tab[K]])continue;P[U.tab[K]]=!0;const z=R[U.tab[K]],O=/^(isol|init|fina|medi)$/.test(U.tag);O&&!F&&(F=w(E));for(let L=0;L<A.length;L++)(!F||!O||x[F[L]]===U.tag)&&e.U._applySubs(A,L,z,R)}})}return A}function N(T,E){const A=new Int16Array(E.length*3);let M=0;for(;M<E.length;M++){const C=E[M];if(C===-1)continue;A[M*3+2]=T.hmtx.aWidth[C];const P=T.GPOS;if(P){const U=P.lookupList;for(let K=0;K<U.length;K++){const z=U[K];for(let O=0;O<z.tabs.length;O++){const L=z.tabs[O];if(z.ltype===1){if(e._lctf.coverageIndex(L.coverage,C)!==-1&&L.pos){F(L.pos,M);break}}else if(z.ltype===2){let j=null,D=R();if(D!==-1){const I=e._lctf.coverageIndex(L.coverage,E[D]);if(I!==-1){if(L.fmt===1){const B=L.pairsets[I];for(let G=0;G<B.length;G++)B[G].gid2===C&&(j=B[G])}else if(L.fmt===2){const B=e.U._getGlyphClass(E[D],L.classDef1),G=e.U._getGlyphClass(C,L.classDef2);j=L.matrix[B][G]}if(j){j.val1&&F(j.val1,D),j.val2&&F(j.val2,M);break}}}}else if(z.ltype===4){const j=e._lctf.coverageIndex(L.markCoverage,C);if(j!==-1){const D=R(_),I=D===-1?-1:e._lctf.coverageIndex(L.baseCoverage,E[D]);if(I!==-1){const B=L.markArray[j],G=L.baseArray[I][B.markClass];A[M*3]=G.x-B.x+A[D*3]-A[D*3+2],A[M*3+1]=G.y-B.y+A[D*3+1];break}}}else if(z.ltype===6){const j=e._lctf.coverageIndex(L.mark1Coverage,C);if(j!==-1){const D=R();if(D!==-1){const I=E[D];if(y(T,I)===3){const B=e._lctf.coverageIndex(L.mark2Coverage,I);if(B!==-1){const G=L.mark1Array[j],q=L.mark2Array[B][G.markClass];A[M*3]=q.x-G.x+A[D*3]-A[D*3+2],A[M*3+1]=q.y-G.y+A[D*3+1];break}}}}}}}}else if(T.kern&&!T.cff){const U=R();if(U!==-1){const K=T.kern.glyph1.indexOf(E[U]);if(K!==-1){const z=T.kern.rval[K].glyph2.indexOf(C);z!==-1&&(A[U*3+2]+=T.kern.rval[K].vals[z])}}}}return A;function R(C){for(let P=M-1;P>=0;P--)if(E[P]!==-1&&(!C||C(E[P])))return P;return-1}function _(C){return y(T,C)===1}function F(C,P){for(let U=0;U<3;U++)A[P*3+U]+=C[U]||0}}function y(T,E){const A=T.GDEF&&T.GDEF.glyphClassDef;return A?e.U._getGlyphClass(E,A):0}function k(...T){for(let E=0;E<T.length;E++)if(typeof T[E]=="number")return T[E]}function S(T){const E=Object.create(null),A=T["OS/2"],M=T.hhea,R=T.head.unitsPerEm,_=k(A&&A.sTypoAscender,M&&M.ascender,R),F={unitsPerEm:R,ascender:_,descender:k(A&&A.sTypoDescender,M&&M.descender,0),capHeight:k(A&&A.sCapHeight,_),xHeight:k(A&&A.sxHeight,_),lineGap:k(A&&A.sTypoLineGap,M&&M.lineGap),supportsCodePoint(C){return e.U.codeToGlyph(T,C)>0},forEachGlyph(C,P,U,K){let z=0;const O=1/F.unitsPerEm*P,L=v(T,C);let j=0;const D=N(T,L);return L.forEach((I,B)=>{if(I!==-1){let G=E[I];if(!G){const{cmds:q,crds:V}=e.U.glyphToPath(T,I);let W="",ee=0;for(let ce=0,re=q.length;ce<re;ce++){const oe=i[q[ce]];W+=q[ce];for(let de=1;de<=oe;de++)W+=(de>1?",":"")+V[ee++]}let ne,J,$,ge;if(V.length){ne=J=1/0,$=ge=-1/0;for(let ce=0,re=V.length;ce<re;ce+=2){let oe=V[ce],de=V[ce+1];oe<ne&&(ne=oe),de<J&&(J=de),oe>$&&($=oe),de>ge&&(ge=de)}}else ne=$=J=ge=0;G=E[I]={index:I,advanceWidth:T.hmtx.aWidth[I],xMin:ne,yMin:J,xMax:$,yMax:ge,path:W}}K.call(null,G,z+D[B*3]*O,D[B*3+1]*O,j),z+=D[B*3+2]*O,U&&(z+=U*P)}j+=C.codePointAt(j)>65535?2:1}),z}};return F}return function(E){const A=new Uint8Array(E,0,4),M=e._bin.readASCII(A,0,4);if(M==="wOFF")E=t(E);else if(M==="wOF2")throw new Error("woff2 fonts not supported");return S(e.parse(E)[0])}}const ru=tr({name:"Typr Font Parser",dependencies:[Zd,eu,tu],init(e,t,i){const c=e(),s=t();return i(c,s)}});/*!
52Custom bundle of @unicode-font-resolver/client v1.0.2 (https://github.com/lojjic/unicode-font-resolver)
53for use in Troika text rendering. 
54Original MIT license applies
55*/function nu(){return function(e){var t=function(){this.buckets=new Map};t.prototype.add=function(N){var y=N>>5;this.buckets.set(y,(this.buckets.get(y)||0)|1<<(31&N))},t.prototype.has=function(N){var y=this.buckets.get(N>>5);return y!==void 0&&(y&1<<(31&N))!=0},t.prototype.serialize=function(){var N=[];return this.buckets.forEach(function(y,k){N.push((+k).toString(36)+":"+y.toString(36))}),N.join(",")},t.prototype.deserialize=function(N){var y=this;this.buckets.clear(),N.split(",").forEach(function(k){var S=k.split(":");y.buckets.set(parseInt(S[0],36),parseInt(S[1],36))})};var i=Math.pow(2,8),c=i-1,s=~c;function n(N){var y=function(S){return S&s}(N).toString(16),k=function(S){return(S&s)+i-1}(N).toString(16);return"codepoint-index/plane"+(N>>16)+"/"+y+"-"+k+".json"}function o(N,y){var k=N&c,S=y.codePointAt(k/6|0);return((S=(S||48)-48)&1<<k%6)!=0}function a(N,y){var k;(k=N,k.replace(/U\+/gi,"").replace(/^,+|,+$/g,"").split(/,+/).map(function(S){return S.split("-").map(function(T){return parseInt(T.trim(),16)})})).forEach(function(S){var T=S[0],E=S[1];E===void 0&&(E=T),y(T,E)})}function l(N,y){a(N,function(k,S){for(var T=k;T<=S;T++)y(T)})}var d={},u={},m=new WeakMap,h="https://cdn.jsdelivr.net/gh/lojjic/[email protected]/packages/data";function p(N){var y=m.get(N);return y||(y=new t,l(N.ranges,function(k){return y.add(k)}),m.set(N,y)),y}var g,b=new Map;function x(N,y,k){return N[y]?y:N[k]?k:function(S){for(var T in S)return T}(N)}function w(N,y){var k=y;if(!N.includes(k)){k=1/0;for(var S=0;S<N.length;S++)Math.abs(N[S]-y)<Math.abs(k-y)&&(k=N[S])}return k}function v(N){return g||(g=new Set,l("9-D,20,85,A0,1680,2000-200A,2028-202F,205F,3000",function(y){g.add(y)})),g.has(N)}return e.CodePointSet=t,e.clearCache=function(){d={},u={}},e.getFontsForString=function(N,y){y===void 0&&(y={});var k,S=y.lang;S===void 0&&(S=/\p{Script=Hangul}/u.test(k=N)?"ko":/\p{Script=Hiragana}|\p{Script=Katakana}/u.test(k)?"ja":"en");var T=y.category;T===void 0&&(T="sans-serif");var E=y.style;E===void 0&&(E="normal");var A=y.weight;A===void 0&&(A=400);var M=(y.dataUrl||h).replace(/\/$/g,""),R=new Map,_=new Uint8Array(N.length),F={},C={},P=new Array(N.length),U=new Map,K=!1;function z(j){var D=b.get(j);return D||(D=fetch(M+"/"+j).then(function(I){if(!I.ok)throw new Error(I.statusText);return I.json().then(function(B){if(!Array.isArray(B)||B[0]!==1)throw new Error("Incorrect schema version; need 1, got "+B[0]);return B[1]})}).catch(function(I){if(M!==h)return K||(console.error('unicode-font-resolver: Failed loading from dataUrl "'+M+'", trying default CDN. '+I.message),K=!0),M=h,b.delete(j),z(j);throw I}),b.set(j,D)),D}for(var O=function(j){var D=N.codePointAt(j),I=n(D);P[j]=I,d[I]||U.has(I)||U.set(I,z(I).then(function(B){d[I]=B})),D>65535&&(j++,L=j)},L=0;L<N.length;L++)O(L);return Promise.all(U.values()).then(function(){U.clear();for(var j=function(I){var B=N.codePointAt(I),G=null,q=d[P[I]],V=void 0;for(var W in q){var ee=C[W];if(ee===void 0&&(ee=C[W]=new RegExp(W).test(S||"en")),ee){for(var ne in V=W,q[W])if(o(B,q[W][ne])){G=ne;break}break}}if(!G){e:for(var J in q)if(J!==V){for(var $ in q[J])if(o(B,q[J][$])){G=$;break e}}}G||(console.debug("No font coverage for U+"+B.toString(16)),G="latin"),P[I]=G,u[G]||U.has(G)||U.set(G,z("font-meta/"+G+".json").then(function(ge){u[G]=ge})),B>65535&&(I++,D=I)},D=0;D<N.length;D++)j(D);return Promise.all(U.values())}).then(function(){for(var j,D=null,I=0;I<N.length;I++){var B=N.codePointAt(I);if(D&&(v(B)||p(D).has(B)))_[I]=_[I-1];else{D=u[P[I]];var G=F[D.id];if(!G){var q=D.typeforms,V=x(q,T,"sans-serif"),W=x(q[V],E,"normal"),ee=w((j=q[V])===null||j===void 0?void 0:j[W],A);G=F[D.id]=M+"/font-files/"+D.id+"/"+V+"."+W+"."+ee+".woff"}var ne=R.get(G);ne==null&&(ne=R.size,R.set(G,ne)),_[I]=ne}B>65535&&(I++,_[I]=_[I-1])}return{fontUrls:Array.from(R.keys()),chars:_}})},Object.defineProperty(e,"__esModule",{value:!0}),e}({})}function su(e,t){const i=Object.create(null),c=Object.create(null);function s(o,a){const l=d=>{console.error(`Failure loading font ${o}`,d)};try{const d=new XMLHttpRequest;d.open("get",o,!0),d.responseType="arraybuffer",d.onload=function(){if(d.status>=400)l(new Error(d.statusText));else if(d.status>0)try{const u=e(d.response);u.src=o,a(u)}catch(u){l(u)}},d.onerror=l,d.send()}catch(d){l(d)}}function n(o,a){let l=i[o];l?a(l):c[o]?c[o].push(a):(c[o]=[a],s(o,d=>
55{d.src=o,i[o]=d,c[o].forEach(u=>u(d)),delete c[o]}))}return function(o,a,{lang:l,fonts:d=[],style:u="normal",weight:m="normal",unicodeFontsURL:h}={}){const p=new Uint8Array(o.length),g=[];o.length||v();const b=new Map,x=[];if(u!=="italic"&&(u="normal"),typeof m!="number"&&(m=m==="bold"?700:400),d&&!Array.isArray(d)&&(d=[d]),d=d.slice().filter(y=>!y.lang||y.lang.test(l)).reverse(),d.length){let T=0;(function E(A=0){for(let M=A,R=o.length;M<R;M++){const _=o.codePointAt(M);if(T===1&&g[p[M-1]].supportsCodePoint(_)||M>0&&/\s/.test(o[M]))p[M]=p[M-1],T===2&&(x[x.length-1][1]=M);else for(let F=p[M],C=d.length;F<=C;F++)if(F===C){const P=T===2?x[x.length-1]:x[x.length]=[M,M];P[1]=M,T=2}else{p[M]=F;const{src:P,unicodeRange:U}=d[F];if(!U||N(_,U)){const K=i[P];if(!K){n(P,()=>{E(M)});return}if(K.supportsCodePoint(_)){let z=b.get(K);typeof z!="number"&&(z=g.length,g.push(K),b.set(K,z)),p[M]=z,T=1;break}}}_>65535&&M+1<R&&(p[M+1]=p[M],M++,T===2&&(x[x.length-1][1]=M))}w()})()}else x.push([0,o.length-1]),w();function w(){if(x.length){const y=x.map(k=>o.substring(k[0],k[1]+1)).join(`
56`);t.getFontsForString(y,{lang:l||void 0,style:u,weight:m,dataUrl:h}).then(({fontUrls:k,chars:S})=>{const T=g.length;let E=0;x.forEach(M=>{for(let R=0,_=M[1]-M[0];R<=_;R++)p[M[0]+R]=S[E++]+T;E++});let A=0;k.forEach((M,R)=>{n(M,_=>{g[R+T]=_,++A===k.length&&v()})})})}else v()}function v(){a({chars:p,fonts:g})}function N(y,k){for(let S=0;S<k.length;S++){const[T,E=T]=k[S];if(T<=y&&y<=E)return!0}return!1}}}const ou=tr({name:"FontResolver",dependencies:[su,ru,nu],init(e,t,i){return e(t,i())}});function au(e,t){const c=/[\u00AD\u034F\u061C\u115F-\u1160\u17B4-\u17B5\u180B-\u180E\u200B-\u200F\u202A-\u202E\u2060-\u206F\u3164\uFE00-\uFE0F\uFEFF\uFFA0\uFFF0-\uFFF8]/,s="[^\\S\\u00A0]",n=new RegExp(`${s}|[\\-\\u007C\\u00AD\\u2010\\u2012-\\u2014\\u2027\\u2056\\u2E17\\u2E40]`);function o({text:g,lang:b,fonts:x,style:w,weight:v,preResolvedFonts:N,unicodeFontsURL:y},k){const S=({chars:T,fonts:E})=>{let A,M;const R=[];for(let _=0;_<T.length;_++)T[_]!==M?(M=T[_],R.push(A={start:_,end:_,fontObj:E[T[_]]})):A.end=_;k(R)};N?S(N):e(g,S,{lang:b,fonts:x,style:w,weight:v,unicodeFontsURL:y})}function a({text:g="",font:b,lang:x,sdfGlyphSize:w=64,fontSize:v=400,fontWeight:N=1,fontStyle:y="normal",letterSpacing:k=0,lineHeight:S="normal",maxWidth:T=1/0,direction:E,textAlign:A="left",textIndent:M=0,whiteSpace:R="normal",overflowWrap:_="normal",anchorX:F=0,anchorY:C=0,metricsOnly:P=!1,unicodeFontsURL:U,preResolvedFonts:K=null,includeCaretPositions:z=!1,chunkedBoundsSize:O=8192,colorRanges:L=null},j){const D=m(),I={fontLoad:0,typesetting:0};g.indexOf("\r")>-1&&(console.info("Typesetter: got text with \\r chars; normalizing to \\n"),g=g.replace(/\r\n/g,`
57`).replace(/\r/g,`
58`)),v=+v,k=+k,T=+T,S=S||"normal",M=+M,o({text:g,lang:x,style:y,weight:N,fonts:typeof b=="string"?[{src:b}]:b,unicodeFontsURL:U,preResolvedFonts:K},B=>{I.fontLoad=m()-D;const G=isFinite(T);let q=null,V=null,W=null,ee=null,ne=null,J=null,$=null,ge=null,ce=0,re=0,oe=R!=="nowrap";const de=new Map,Z=m();let le=M,ie=0,Q=new h;const be=[Q];B.forEach(ue=>{const{fontObj:he}=ue,{ascender:Y,descender:X,unitsPerEm:ye,lineGap:ke,capHeight:we,xHeight:je}=he;let pe=de.get(he);if(!pe){const ve=v/ye,Te=S==="normal"?(Y-X+ke)*ve:S*v,Je=(Te-(Y-X)*ve)/2,Pe=Math.min(Te,(Y-X)*ve),_e=(Y+X)/2*ve+Pe/2;pe={index:de.size,src:he.src,fontObj:he,fontSizeMult:ve,unitsPerEm:ye,ascender:Y*ve,descender:X*ve,capHeight:we*ve,xHeight:je*ve,lineHeight:Te,baseline:-Je-Y*ve,caretTop:_e,caretBottom:_e-Pe},de.set(he,pe)}const{fontSizeMult:Fe}=pe,Le=g.slice(ue.start,ue.end+1);let qe,Ue;he.forEachGlyph(Le,v,k,(ve,Te,Je,Pe)=>{Te+=ie,Pe+=ue.start,qe=Te,Ue=ve;const _e=g.charAt(Pe),Ve=ve.advanceWidth*Fe,Ie=Q.count;let Se;if("isEmpty"in ve||(ve.isWhitespace=!!_e&&new RegExp(s).test(_e),ve.canBreakAfter=!!_e&&n.test(_e),ve.isEmpty=ve.xMin===ve.xMax||ve.yMin===ve.yMax||c.test(_e)),!ve.isWhitespace&&!ve.isEmpty&&re++,oe&&G&&!ve.isWhitespace&&Te+Ve+le>T&&Ie){if(Q.glyphAt(Ie-1).glyphObj.canBreakAfter)Se=new h,le=-Te;else for(let ze=Ie;ze--;)if(ze===0&&_==="break-word"){Se=new h,le=-Te;break}else if(Q.glyphAt(ze).glyphObj.canBreakAfter){Se=Q.splitAt(ze+1);const Xe=Se.glyphAt(0).x;le-=Xe;for(let We=Se.count;We--;)Se.glyphAt(We).x-=Xe;break}Se&&(Q.isSoftWrapped=!0,Q=Se,be.push(Q),ce=T)}let Oe=Q.glyphAt(Q.count);Oe.glyphObj=ve,Oe.x=Te+le,Oe.y=Je,Oe.width=Ve,Oe.charIndex=Pe,Oe.fontData=pe,_e===`
59`&&(Q=new h,be.push(Q),le=-(Te+Ve+k*v)+M)}),ie=qe+Ue.advanceWidth*Fe+k*v});let ae=0;be.forEach(ue=>{let he=!0;for(let Y=ue.count;Y--;){const X=ue.glyphAt(Y);he&&!X.glyphObj.isWhitespace&&(ue.width=X.x+X.width,ue.width>ce&&(ce=ue.width),he=!1);let{lineHeight:ye,capHeight:ke,xHeight:we,baseline:je}=X.fontData;ye>ue.lineHeight&&(ue.lineHeight=ye);const pe=je-ue.baseline;pe<0&&(ue.baseline+=pe,ue.cap+=pe,ue.ex+=pe),ue.cap=Math.max(ue.cap,ue.baseline+ke),ue.ex=Math.max(ue.ex,ue.baseline+we)}ue.baseline-=ae,ue.cap-=ae,ue.ex-=ae,ae+=ue.lineHeight});let fe=0,se=0;if(F&&(typeof F=="number"?fe=-F:typeof F=="string"&&(fe=-ce*(F==="left"?0:F==="center"?.5:F==="right"?1:d(F)))),C&&(typeof C=="number"?se=-C:typeof C=="string"&&(se=C==="top"?0:C==="top-baseline"?-be[0].baseline:C==="top-cap"?-be[0].cap:C==="top-ex"?-be[0].ex:C==="middle"?ae/2:C==="bottom"?ae:C==="bottom-baseline"?-be[be.length-1].baseline:d(C)*ae)),!P){const ue=t.getEmbeddingLevels(g,E);q=new Uint16Array(re),V=new Uint8Array(re),W=new Float32Array(re*2),ee={},$=[1/0,1/0,-1/0,-1/0],ge=[],z&&(J=new Float32Array(g.length*4)),L&&(ne=new Uint8Array(re*3));let he=0,Y=-1,X=-1,ye,ke;if(be.forEach((we,je)=>{let{count:pe,width:Fe}=we;if(pe>0){let Le=0;for(let Pe=pe;Pe--&&we.glyphAt(Pe).glyphObj.isWhitespace;)Le++;let qe=0,Ue=0;if(A==="center")qe=(ce-Fe)/2;else if(A==="right")qe=ce-Fe;else if(A==="justify"&&we.isSoftWrapped){let Pe=0;for(let _e=pe-Le;_e--;)we.glyphAt(_e).glyphObj.isWhitespace&&Pe++;Ue=(ce-Fe)/Pe}if(Ue||qe){let Pe=0;for(let _e=0;_e<pe;_e++){let Ve=we.glyphAt(_e);const Ie=Ve.glyphObj;Ve.x+=qe+Pe,Ue!==0&&Ie.isWhitespace&&_e<pe-Le&&(Pe+=Ue,Ve.width+=Ue)}}const ve=t.getReorderSegments(g,ue,we.glyphAt(0).charIndex,we.glyphAt(we.count-1).charIndex);for(let Pe=0;Pe<ve.length;Pe++){const[_e,Ve]=ve[Pe];let Ie=1/0,Se=-1/0;for(let Oe=0;Oe<pe;Oe++)if(we.glyphAt(Oe).charIndex>=_e){let ze=Oe,Xe=Oe;
59for(;Xe<pe;Xe++){let We=we.glyphAt(Xe);if(We.charIndex>Ve)break;Xe<pe-Le&&(Ie=Math.min(Ie,We.x),Se=Math.max(Se,We.x+We.width))}for(let We=ze;We<Xe;We++){const rt=we.glyphAt(We);rt.x=Se-(rt.x+rt.width-Ie)}break}}let Te;const Je=Pe=>Te=Pe;for(let Pe=0;Pe<pe;Pe++){const _e=we.glyphAt(Pe);Te=_e.glyphObj;const Ve=Te.index,Ie=ue.levels[_e.charIndex]&1;if(Ie){const Se=t.getMirroredCharacter(g[_e.charIndex]);Se&&_e.fontData.fontObj.forEachGlyph(Se,0,0,Je)}if(z){const{charIndex:Se,fontData:Oe}=_e,ze=_e.x+fe,Xe=_e.x+_e.width+fe;J[Se*4]=Ie?Xe:ze,J[Se*4+1]=Ie?ze:Xe,J[Se*4+2]=we.baseline+Oe.caretBottom+se,J[Se*4+3]=we.baseline+Oe.caretTop+se;const We=Se-Y;We>1&&u(J,Y,We),Y=Se}if(L){const{charIndex:Se}=_e;for(;Se>X;)X++,L.hasOwnProperty(X)&&(ke=L[X])}if(!Te.isWhitespace&&!Te.isEmpty){const Se=he++,{fontSizeMult:Oe,src:ze,index:Xe}=_e.fontData,We=ee[ze]||(ee[ze]={});We[Ve]||(We[Ve]={path:Te.path,pathBounds:[Te.xMin,Te.yMin,Te.xMax,Te.yMax]});const rt=_e.x+fe,ht=_e.y+we.baseline+se;W[Se*2]=rt,W[Se*2+1]=ht;const ct=rt+Te.xMin*Oe,pt=ht+Te.yMin*Oe,it=rt+Te.xMax*Oe,dt=ht+Te.yMax*Oe;ct<$[0]&&($[0]=ct),pt<$[1]&&($[1]=pt),it>$[2]&&($[2]=it),dt>$[3]&&($[3]=dt),Se%O===0&&(ye={start:Se,end:Se,rect:[1/0,1/0,-1/0,-1/0]},ge.push(ye)),ye.end++;const te=ye.rect;if(ct<te[0]&&(te[0]=ct),pt<te[1]&&(te[1]=pt),it>te[2]&&(te[2]=it),dt>te[3]&&(te[3]=dt),q[Se]=Ve,V[Se]=Xe,L){const Me=Se*3;ne[Me]=ke>>16&255,ne[Me+1]=ke>>8&255,ne[Me+2]=ke&255}}}}}),J){const we=g.length-Y;we>1&&u(J,Y,we)}}const Ne=[];de.forEach(({index:ue,src:he,unitsPerEm:Y,ascender:X,descender:ye,lineHeight:ke,capHeight:we,xHeight:je})=>{Ne[ue]={src:he,unitsPerEm:Y,ascender:X,descender:ye,lineHeight:ke,capHeight:we,xHeight:je}}),I.typesetting=m()-Z,j({glyphIds:q,glyphFontIndices:V,glyphPositions:W,glyphData:ee,fontData:Ne,caretPositions:J,glyphColors:ne,chunkedBounds:ge,fontSize:v,topBaseline:se+be[0].baseline,blockBounds:[fe,se-ae,fe+ce,se],visibleBounds:$,timings:I})})}function l(g,b){a({...g,metricsOnly:!0},x=>{const[w,v,N,y]=x.blockBounds;b({width:N-w,height:y-v})})}function d(g){let b=g.match(/^([\d.]+)%$/),x=b?parseFloat(b[1]):NaN;return isNaN(x)?0:x/100}function u(g,b,x){const w=g[b*4],v=g[b*4+1],N=g[b*4+2],y=g[b*4+3],k=(v-w)/x;for(let S=0;S<x;S++){const T=(b+S)*4;g[T]=w+k*S,g[T+1]=w+k*(S+1),g[T+2]=N,g[T+3]=y}}function m(){return(self.performance||Date).now()}function h(){this.data=[]}const p=["glyphObj","x","y","width","charIndex","fontData"];return h.prototype={width:0,lineHeight:0,baseline:0,cap:0,ex:0,isSoftWrapped:!1,get count(){return Math.ceil(this.data.length/p.length)},glyphAt(g){let b=h.flyweight;return b.data=this.data,b.index=g,b},splitAt(g){let b=new h;return b.data=this.data.splice(g*p.length),b}},h.flyweight=p.reduce((g,b,x,w)=>(Object.defineProperty(g,b,{get(){return this.data[this.index*p.length+x]},set(v){this.data[this.index*p.length+x]=v}}),g),{data:null,index:0}),{typeset:a,measure:l}}const Dt=()=>(self.performance||Date).now(),pn=Ja();let bo;function iu(e,t,i,c,s,n,o,a,l,d,u=!0){return u?cu(e,t,i,c,s,n,o,a,l,d).then(null,m=>(bo||(console.warn("WebGL SDF generation failed, falling back to JS",m),bo=!0),yo(e,t,i,c,s,n,o,a,l,d))):yo(e,t,i,c,s,n,o,a,l,d)}const tn=[],lu=5;let ls=0;function ei(){const e=Dt();for(;tn.length&&Dt()-e<lu;)tn.shift()();ls=tn.length?setTimeout(ei,0):0}const cu=(...e)=>new Promise((t,i)=>{tn.push(()=>{const c=Dt();try{pn.webgl.generateIntoCanvas(...e),t({timing:Dt()-c})}catch(s){i(s)}}),ls||(ls=setTimeout(ei,0))}),du=4,uu=2e3,vo={};let fu=0;function yo(e,t,i,c,s,n,o,a,l,d){const u="TroikaTextSDFGenerator_JS_"+fu++%du;let m=vo[u];return m||(m=vo[u]={workerModule:tr({name:u,workerId:u,dependencies:[Ja,Dt],init(h,p){const g=h().javascript.generate;return function(...b){const x=p();return{textureData:g(...b),timing:p()-x}}},getTransferables(h){return[h.textureData.buffer]}}),requests:0,idleTimer:null}),m.requests++,clearTimeout(m.idleTimer),m.workerModule(e,t,i,c,s,n).then(({textureData:h,timing:p})=>{const g=Dt(),b=new Uint8Array(h.length*4);for(let x=0;x<h.length;x++)b[x*4+d]=h[x];return pn.webglUtils.renderImageData(o,b,a,l,e,t,1<<3-d),p+=Dt()-g,--m.requests===0&&(m.idleTimer=setTimeout(()=>{zd(u)},uu)),{timing:p}})}function mu(e){e._warm||(pn.webgl.isSupported(e),e._warm=!0)}const hu=pn.webglUtils.resizeWebGLCanvasWithoutClearing,hr={unicodeFontsURL:null,sdfGlyphSize:64,sdfMargin:1/16,sdfExponent:9,textureWidth:2048},pu=new Re;function Vt(){return(self.performance||Date).now()}const wo=Object.create(null);function ti(e,t){e=bu({},e);const i=Vt(),c=[];if(e.font&&c.push({label:"user",src:vu(e.font)}),e.font=c,e.text=""+e.text,e.sdfGlyphSize=e.sdfGlyphSize||hr.sdfGlyphSize,e.unicodeFontsURL=e.unicodeFontsURL||hr.unicodeFontsURL,e.colorRanges!=null){let h={};for(let p in e.colorRanges)if(e.colorRanges.hasOwnProperty(p)){let g=e.colorRanges[p];typeof g!="number"&&(g=pu.set(g).getHex()),h[p]=g}e.colorRanges=h}Object.freeze(e);const{textureWidth:s,sdfExponent:n}=hr,{sdfGlyphSize:o}=e,a=s/o*4;let l=wo[o];if(!l){const h=document.createElement("canvas");h.width=s,h.height=o*256/a,l=wo[o]={glyphCount:0,sdfGlyphSize:o,sdfCanvas:h,sdfTexture:new nd(h,void 0,void 0,void 0,ln,ln),contextLost:!1,glyphsByFont:new Map},l.sdfTexture.generateMipmaps=!1,gu(l)}const{sdfTexture:d,sdfCanvas:u}=l;
59si(e).then(h=>{const{glyphIds:p,glyphFontIndices:g,fontData:b,glyphPositions:x,fontSize:w,timings:v}=h,N=[],y=new Float32Array(p.length*4);let k=0,S=0;const T=Vt(),E=b.map(F=>{let C=l.glyphsByFont.get(F.src);return C||l.glyphsByFont.set(F.src,C=new Map),C});p.forEach((F,C)=>{const P=g[C],{src:U,unitsPerEm:K}=b[P];let z=E[P].get(F);if(!z){const{path:I,pathBounds:B}=h.glyphData[U][F],G=Math.max(B[2]-B[0],B[3]-B[1])/o*(hr.sdfMargin*o+.5),q=l.glyphCount++,V=[B[0]-G,B[1]-G,B[2]+G,B[3]+G];E[P].set(F,z={path:I,atlasIndex:q,sdfViewBox:V}),N.push(z)}const{sdfViewBox:O}=z,L=x[S++],j=x[S++],D=w/K;y[k++]=L+O[0]*D,y[k++]=j+O[1]*D,y[k++]=L+O[2]*D,y[k++]=j+O[3]*D,p[C]=z.atlasIndex}),v.quads=(v.quads||0)+(Vt()-T);const A=Vt();v.sdf={};const M=u.height,R=Math.ceil(l.glyphCount/a),_=Math.pow(2,Math.ceil(Math.log2(R*o)));_>M&&(console.info(`Increasing SDF texture size ${M}->${_}`),hu(u,s,_),d.dispose()),Promise.all(N.map(F=>ri(F,l,e.gpuAccelerateSDF).then(({timing:C})=>{v.sdf[F.atlasIndex]=C}))).then(()=>{N.length&&!l.contextLost&&(ni(l),d.needsUpdate=!0),v.sdfTotal=Vt()-A,v.total=Vt()-i,t(Object.freeze({parameters:e,sdfTexture:d,sdfGlyphSize:o,sdfExponent:n,glyphBounds:y,glyphAtlasIndices:p,glyphColors:h.glyphColors,caretPositions:h.caretPositions,chunkedBounds:h.chunkedBounds,ascender:h.ascender,descender:h.descender,lineHeight:h.lineHeight,capHeight:h.capHeight,xHeight:h.xHeight,topBaseline:h.topBaseline,blockBounds:h.blockBounds,visibleBounds:h.visibleBounds,timings:h.timings}))})}),Promise.resolve().then(()=>{l.contextLost||mu(u)})}function ri({path:e,atlasIndex:t,sdfViewBox:i},{sdfGlyphSize:c,sdfCanvas:s,contextLost:n},o){if(n)return Promise.resolve({timing:-1});const{textureWidth:a,sdfExponent:l}=hr,d=Math.max(i[2]-i[0],i[3]-i[1]),u=Math.floor(t/4),m=u%(a/c)*c,h=Math.floor(u/(a/c))*c,p=t%4;return iu(c,c,e,i,d,l,s,m,h,p,o)}function gu(e){const t=e.sdfCanvas;t.addEventListener("webglcontextlost",i=>{console.log("Context Lost",i),i.preventDefault(),e.contextLost=!0}),t.addEventListener("webglcontextrestored",i=>{console.log("Context Restored",i),e.contextLost=!1;const c=[];e.glyphsByFont.forEach(s=>{s.forEach(n=>{c.push(ri(n,e,!0))})}),Promise.all(c).then(()=>{ni(e),e.sdfTexture.needsUpdate=!0})})}function xu({font:e,characters:t,sdfGlyphSize:i},c){let s=Array.isArray(t)?t.join(`
60`):""+t;ti({font:e,sdfGlyphSize:i,text:s},c)}function bu(e,t){for(let i in t)t.hasOwnProperty(i)&&(e[i]=t[i]);return e}let Hr;function vu(e){return Hr||(Hr=typeof document>"u"?{}:document.createElement("a")),Hr.href=e,Hr.href}function ni(e){if(typeof createImageBitmap!="function"){console.info("Safari<15: applying SDF canvas workaround");const{sdfCanvas:t,sdfTexture:i}=e,{width:c,height:s}=t,n=e.sdfCanvas.getContext("webgl");let o=i.image.data;(!o||o.length!==c*s*4)&&(o=new Uint8Array(c*s*4),i.image={width:c,height:s,data:o},i.flipY=!1,i.isDataTexture=!0),n.readPixels(0,0,c,s,n.RGBA,n.UNSIGNED_BYTE,o)}}
60const yu=tr({name:"Typesetter",dependencies:[au,ou,Hd],init(e,t,i){return e(t,i())}}),si=tr({name:"Typesetter",dependencies:[yu],init(e){return function(t){return new Promise(i=>{e.typeset(t,i)})}},getTransferables(e){const t=[];for(let i in e)e[i]&&e[i].buffer&&t.push(e[i].buffer);return t}});si.onMainThread;const jo={};function wu(e){let t=jo[e];return t||(t=jo[e]=new vs(1,1,e,e).translate(.5,.5,0)),t}const ju="aTroikaGlyphBounds",ko="aTroikaGlyphIndex",ku="aTroikaGlyphColor";class Nu extends ed{constructor(){super(),this.detail=1,this.curveRadius=0,this.groups=[{start:0,count:1/0,materialIndex:0},{start:0,count:1/0,materialIndex:1}],this.boundingSphere=new td,this.boundingBox=new bs}computeBoundingSphere(){}computeBoundingBox(){}set detail(t){if(t!==this._detail){this._detail=t,(typeof t!="number"||t<1)&&(t=1);let i=wu(t);["position","normal","uv"].forEach(c=>{this.attributes[c]=i.attributes[c].clone()}),this.setIndex(i.getIndex().clone())}}get detail(){return this._detail}set curveRadius(t){t!==this._curveRadius&&(this._curveRadius=t,this._updateBounds())}get curveRadius(){return this._curveRadius}updateGlyphs(t,i,c,s,n){this.updateAttributeData(ju,t,4),this.updateAttributeData(ko,i,1),this.updateAttributeData(ku,n,3),this._blockBounds=c,this._chunkedBounds=s,this.instanceCount=i.length,this._updateBounds()}_updateBounds(){const t=this._blockBounds;if(t){const{curveRadius:i,boundingBox:c}=this;if(i){const{PI:s,floor:n,min:o,max:a,sin:l,cos:d}=Math,u=s/2,m=s*2,h=Math.abs(i),p=t[0]/h,g=t[2]/h,b=n((p+u)/m)!==n((g+u)/m)?-h:o(l(p)*h,l(g)*h),x=n((p-u)/m)!==n((g-u)/m)?h:a(l(p)*h,l(g)*h),w=n((p+s)/m)!==n((g+s)/m)?h*2:a(h-d(p)*h,h-d(g)*h);c.min.set(b,t[1],i<0?-w:0),c.max.set(x,t[3],i<0?0:w)}else c.min.set(t[0],t[1],0),c.max.set(t[2],t[3],0);c.getBoundingSphere(this.boundingSphere)}}applyClipRect(t){let i=this.getAttribute(ko).count,c=this._chunkedBounds;if(c)for(let s=c.length;s--;){i=c[s].end;let n=c[s].rect;if(n[1]<t.w&&n[3]>t.y&&n[0]<t.z&&n[2]>t.x)break}this.instanceCount=i}updateAttributeData(t,i,c){const s=this.getAttribute(t);i?s&&s.array.length===i.length?(s.array.set(i),s.needsUpdate=!0):(this.setAttribute(t,new rd(i,c)),delete this._maxInstanceCount,this.dispose()):s&&this.deleteAttribute(t)}}const Su=`
61uniform vec2 uTroikaSDFTextureSize;
62uniform float uTroikaSDFGlyphSize;
63uniform vec4 uTroikaTotalBounds;
64uniform vec4 uTroikaClipRect;
65uniform mat3 uTroikaOrient;
66uniform bool uTroikaUseGlyphColors;
67uniform float uTroikaEdgeOffset;
68uniform float uTroikaBlurRadius;
69uniform vec2 uTroikaPositionOffset;
70uniform float uTroikaCurveRadius;
71attribute vec4 aTroikaGlyphBounds;
72attribute float aTroikaGlyphIndex;
73attribute vec3 aTroikaGlyphColor;
74varying vec2 vTroikaGlyphUV;
75varying vec4 vTroikaTextureUVBounds;
76varying float vTroikaTextureChannel;
77varying vec3 vTroikaGlyphColor;
78varying vec2 vTroikaGlyphDimensions;
79`,_u=`
80vec4 bounds = aTroikaGlyphBounds;
81bounds.xz += uTroikaPositionOffset.x;
82bounds.yw -= uTroikaPositionOffset.y;
83
84vec4 outlineBounds = vec4(
85  bounds.xy - uTroikaEdgeOffset - uTroikaBlurRadius,
86  bounds.zw + uTroikaEdgeOffset + uTroikaBlurRadius
87);
88vec4 clippedBounds = vec4(
89  clamp(outlineBounds.xy, uTroikaClipRect.xy, uTroikaClipRect.zw),
90  clamp(outlineBounds.zw, uTroikaClipRect.xy, uTroikaClipRect.zw)
91);
92
93vec2 clippedXY = (mix(clippedBounds.xy, clippedBounds.zw, position.xy) - bounds.xy) / (bounds.zw - bounds.xy);
94
95position.xy = mix(bounds.xy, bounds.zw, clippedXY);
96
97uv = (position.xy - uTroikaTotalBounds.xy) / (uTroikaTotalBounds.zw - uTroikaTotalBounds.xy);
98
99float rad = uTroikaCurveRadius;
100if (rad != 0.0) {
101  float angle = position.x / rad;
102  position.xz = vec2(sin(angle) * rad, rad - cos(angle) * rad);
103  normal.xz = vec2(sin(angle), cos(angle));
104}
105  
106position = uTroikaOrient * position;
107normal = uTroikaOrient * normal;
108
109vTroikaGlyphUV = clippedXY.xy;
110vTroikaGlyphDimensions = vec2(bounds[2] - bounds[0], bounds[3] - bounds[1]);
111
112
113float txCols = uTroikaSDFTextureSize.x / uTroikaSDFGlyphSize;
114vec2 txUvPerSquare = uTroikaSDFGlyphSize / uTroikaSDFTextureSize;
115vec2 txStartUV = txUvPerSquare * vec2(
116  mod(floor(aTroikaGlyphIndex / 4.0), txCols),
117  floor(floor(aTroikaGlyphIndex / 4.0) / txCols)
118);
119vTroikaTextureUVBounds = vec4(txStartUV, vec2(txStartUV) + txUvPerSquare);
120vTroikaTextureChannel = mod(aTroikaGlyphIndex, 4.0);
121`,Cu=`
122uniform sampler2D uTroikaSDFTexture;
123uniform vec2 uTroikaSDFTextureSize;
124uniform float uTroikaSDFGlyphSize;
125uniform float uTroikaSDFExponent;
126uniform float uTroikaEdgeOffset;
127uniform float uTroikaFillOpacity;
128uniform float uTroikaBlurRadius;
129uniform vec3 uTroikaStrokeColor;
130uniform float uTroikaStrokeWidth;
131uniform float uTroikaStrokeOpacity;
132uniform bool uTroikaSDFDebug;
133varying vec2 vTroikaGlyphUV;
134varying vec4 vTroikaTextureUVBounds;
135varying float vTroikaTextureChannel;
136varying vec2 vTroikaGlyphDimensions;
137
138float troikaSdfValueToSignedDistance(float alpha) {
139  // Inverse of exponential encoding in webgl-sdf-generator
140  
141  float maxDimension = max(vTroikaGlyphDimensions.x, vTroikaGlyphDimensions.y);
142  float absDist = (1.0 - pow(2.0 * (alpha > 0.5 ? 1.0 - alpha : alpha), 1.0 / uTroikaSDFExponent)) * maxDimension;
143  float signedDist = absDist * (alpha > 0.5 ? -1.0 : 1.0);
144  return signedDist;
145}
146
147float troikaGlyphUvToSdfValue(vec2 glyphUV) {
148  vec2 textureUV = mix(vTroikaTextureUVBounds.xy, vTroikaTextureUVBounds.zw, glyphUV);
149  vec4 rgba = texture2D(uTroikaSDFTexture, textureUV);
150  float ch = floor(vTroikaTextureChannel + 0.5); //NOTE: can't use round() in WebGL1
151  return ch == 0.0 ? rgba.r : ch == 1.0 ? rgba.g : ch == 2.0 ? rgba.b : rgba.a;
152}
153
154float troikaGlyphUvToDistance(vec2 uv) {
155  return troikaSdfValueToSignedDistance(troikaGlyphUvToSdfValue(uv));
156}
157
158float troikaGetAADist() {
159  
160  #if defined(GL_OES_standard_derivatives) || __VERSION__ >= 300
161  return length(fwidth(vTroikaGlyphUV * vTroikaGlyphDimensions)) * 0.5;
162  #else
163  return vTroikaGlyphDimensions.x / 64.0;
164  #endif
165}
166
167float troikaGetFragDistValue() {
168  vec2 clampedGlyphUV = clamp(vTroikaGlyphUV, 0.5 / uTroikaSDFGlyphSize, 1.0 - 0.5 / uTroikaSDFGlyphSize);
169  float distance = troikaGlyphUvToDistance(clampedGlyphUV);
170 
171  // Extrapolate distance when outside bounds:
172  distance += clampedGlyphUV == vTroikaGlyphUV ? 0.0 : 
173    length((vTroikaGlyphUV - clampedGlyphUV) * vTroikaGlyphDimensions);
174
175  
176
177  return distance;
178}
179
180float troikaGetEdgeAlpha(float distance, float distanceOffset, float aaDist) {
181  #if defined(IS_DEPTH_MATERIAL) || defined(IS_DISTANCE_MATERIAL)
182  float alpha = step(-distanceOffset, -distance);
183  #else
184
185  float alpha = smoothstep(
186    distanceOffset + aaDist,
187    distanceOffset - aaDist,
188    distance
189  );
190  #endif
191
192  return alpha;
193}
194`,Eu=`
195float aaDist = troikaGetAADist();
196float fragDistance = troikaGetFragDistValue();
197float edgeAlpha = uTroikaSDFDebug ?
198  troikaGlyphUvToSdfValue(vTroikaGlyphUV) :
199  troikaGetEdgeAlpha(fragDistance, uTroikaEdgeOffset, max(aaDist, uTroikaBlurRadius));
200
201#if !defined(IS_DEPTH_MATERIAL) && !defined(IS_DISTANCE_MATERIAL)
202vec4 fillRGBA = gl_FragColor;
203fillRGBA.a *= uTroikaFillOpacity;
204vec4 strokeRGBA = uTroikaStrokeWidth == 0.0 ? fillRGBA : vec4(uTroikaStrokeColor, uTroikaStrokeOpacity);
205if (fillRGBA.a == 0.0) fillRGBA.rgb = strokeRGBA.rgb;
206gl_FragColor = mix(fillRGBA, strokeRGBA, smoothstep(
207  -uTroikaStrokeWidth - aaDist,
208  -uTroikaStrokeWidth + aaDist,
209  fragDistance
210));
211gl_FragColor.a *= edgeAlpha;
212#endif
213
214if (edgeAlpha == 0.0) {
215  discard;
216}
217`;function Tu(e){const t=is(e,{chained:!0,extensions:{derivatives:!0},uniforms:{uTroikaSDFTexture:{value:null},uTroikaSDFTextureSize:{value:new an},uTroikaSDFGlyphSize:{value:0},uTroikaSDFExponent:{value:0},uTroikaTotalBounds:{value:new uo(0,0,0,0)},uTroikaClipRect:{value:new uo(0,0,0,0)},uTroikaEdgeOffset:{value:0},uTroikaFillOpacity:{value:1},uTroikaPositionOffset:{value:new an},uTroikaCurveRadius:{value:0},uTroikaBlurRadius:{value:0},uTroikaStrokeWidth:{value:0},uTroikaStrokeColor:{value:new Re},uTroikaStrokeOpacity:{value:1},uTroikaOrient:{value:new sd},uTroikaUseGlyphColors:{value:!0},uTroikaSDFDebug:{value:!1}},vertexDefs:Su,vertexTransform:_u,fragmentDefs:Cu,fragmentColorTransform:Eu,customRewriter({vertexShader:i,fragmentShader:c}){let s=/\buniform\s+vec3\s+diffuse\b/;return s.test(c)&&(c=c.replace(s,"varying vec3 vTroikaGlyphColor").replace(/\bdiffuse\b/g,"vTroikaGlyphColor"),s.test(i)||(i=i.replace(Za,`uniform vec3 diffuse;
218$&
219vTroikaGlyphColor = uTroikaUseGlyphColors ? aTroikaGlyphColor / 255.0 : diffuse;
220`))),{vertexShader:i,fragmentShader:c}}});return t.transparent=!0,t.forceSinglePass=!0,Object.defineProperties(t,{isTroikaTextMaterial:{value:!0},shadowSide:{get(){return this.side},set(){}}}),t}const ks=new Zc({color:16777215,side:Zt,transparent:!0}),No=8421504,So=new $a,Kr=new Ae,zn=new Ae,mr=[],Mu=new Ae,Wn="+x+y";function _o(e){return Array.isArray(e)?e[0]:e}let oi=()=>{const e=new kr(new vs(1,1),ks);return oi=()=>e,e},ai=()=>{const e=new kr(new vs(1,1,32,1),ks);return ai=()=>e,e};const Au={type:"syncstart"},Pu={type:"synccomplete"},ii=["font","fontSize","fontStyle","fontWeight","lang","letterSpacing","lineHeight","maxWidth","overflowWrap","text","direction","textAlign","textIndent","whiteSpace","anchorX","anchorY","colorRanges","sdfGlyphSize"],Du=ii.concat("material","color","depthOffset","clipRect","curveRadius","orientation","glyphGeometryDetail");let li=class extends kr{constructor(){const t=new Nu;super(t,null),this.text="",this.anchorX=0,this.anchorY=0,this.curveRadius=0,this.direction="auto",this.font=null,this.unicodeFontsURL=null,this.fontSize=.1,this.fontWeight="normal",this.fontStyle="normal",this.lang=null,this.letterSpacing=0,this.lineHeight="normal",this.maxWidth=1/0,this.overflowWrap="normal",this.textAlign="left",this.textIndent=0,this.whiteSpace="normal",this.material=null,this.color=null,this.colorRanges=null,this.outlineWidth=0,this.outlineColor=0,this.outlineOpacity=1,this.outlineBlur=0,this.outlineOffsetX=0,this.outlineOffsetY=0,this.strokeWidth=0,this.strokeColor=No,this.strokeOpacity=1,this.fillOpacity=1,this.depthOffset=0,this.clipRect=null,this.orientation=Wn,this.glyphGeometryDetail=1,this.sdfGlyphSize=null,this.gpuAccelerateSDF=!0,this.debugSDF=!1}sync(t){this._needsSync&&(this._needsSync=!1,this._isSyncing?(this._queuedSyncs||(this._queuedSyncs=[])).push(t):(this._isSyncing=!0,this.dispatchEvent(Au),ti({text:this.text,font:this.font,lang:this.lang,fontSize:this.fontSize||.1,fontWeight:this.fontWeight||"normal",fontStyle:this.fontStyle||"normal",letterSpacing:this.letterSpacing||0,lineHeight:this.lineHeight||"normal",maxWidth:this.maxWidth,direction:this.direction||"auto",textAlign:this.textAlign,textIndent:this.textIndent,whiteSpace:this.whiteSpace,overflowWrap:this.overflowWrap,anchorX:this.anchorX,anchorY:this.anchorY,colorRanges:this.colorRanges,includeCaretPositions:!0,sdfGlyphSize:this.sdfGlyphSize,gpuAccelerateSDF:this.gpuAccelerateSDF,unicodeFontsURL:this.unicodeFontsURL},i=>{this._isSyncing=!1,this._textRenderInfo=i,this.geometry.updateGlyphs(i.glyphBounds,i.glyphAtlasIndices,i.blockBounds,i.chunkedBounds,i.glyphColors);const c=this._queuedSyncs;c&&(this._queuedSyncs=null,this._needsSync=!0,this.sync(()=>{c.forEach(s=>s&&s())})),this.dispatchEvent(Pu),t&&t()})))}onBeforeRender(t,i,c,s,n,o){this.sync(),n.isTroikaTextMaterial&&this._prepareForRender(n)}dispose(){this.geometry.dispose()}get textRenderInfo(){return this._textRenderInfo||null}createDerivedMaterial(t){return Tu(t)}get material(){let t=this._derivedMaterial;const i=this._baseMaterial||this._defaultMaterial||(this._defaultMaterial=ks.clone());if((!t||!t.isDerivedFrom(i))&&(t=this._derivedMaterial=this.createDerivedMaterial(i),i.addEventListener("dispose",function c(){i.removeEventListener("dispose",c),t.dis
220pose()})),this.hasOutline()){let c=t._outlineMtl;return c||(c=t._outlineMtl=Object.create(t,{id:{value:t.id+.1}}),c.isTextOutlineMaterial=!0,c.depthWrite=!1,c.map=null,t.addEventListener("dispose",function s(){t.removeEventListener("dispose",s),c.dispose()})),[c,t]}else return t}set material(t){t&&t.isTroikaTextMaterial?(this._derivedMaterial=t,this._baseMaterial=t.baseMaterial):this._baseMaterial=t}hasOutline(){return!!(this.outlineWidth||this.outlineBlur||this.outlineOffsetX||this.outlineOffsetY)}get glyphGeometryDetail(){return this.geometry.detail}set glyphGeometryDetail(t){this.geometry.detail=t}get curveRadius(){return this.geometry.curveRadius}set curveRadius(t){this.geometry.curveRadius=t}get customDepthMaterial(){return _o(this.material).getDepthMaterial()}set customDepthMaterial(t){}get customDistanceMaterial(){return _o(this.material).getDistanceMaterial()}set customDistanceMaterial(t){}_prepareForRender(t){const i=t.isTextOutlineMaterial,c=t.uniforms,s=this.textRenderInfo;if(s){const{sdfTexture:a,blockBounds:l}=s;c.uTroikaSDFTexture.value=a,c.uTroikaSDFTextureSize.value.set(a.image.width,a.image.height),c.uTroikaSDFGlyphSize.value=s.sdfGlyphSize,c.uTroikaSDFExponent.value=s.sdfExponent,c.uTroikaTotalBounds.value.fromArray(l),c.uTroikaUseGlyphColors.value=!i&&!!s.glyphColors;let d=0,u=0,m=0,h,p,g,b=0,x=0;if(i){let{outlineWidth:v,outlineOffsetX:N,outlineOffsetY:y,outlineBlur:k,outlineOpacity:S}=this;d=this._parsePercent(v)||0,u=Math.max(0,this._parsePercent(k)||0),h=S,b=this._parsePercent(N)||0,x=this._parsePercent(y)||0}else m=Math.max(0,this._parsePercent(this.strokeWidth)||0),m&&(g=this.strokeColor,c.uTroikaStrokeColor.value.set(g??No),p=this.strokeOpacity,p==null&&(p=1)),h=this.fillOpacity;c.uTroikaEdgeOffset.value=d,c.uTroikaPositionOffset.value.set(b,x),c.uTroikaBlurRadius.value=u,c.uTroikaStrokeWidth.value=m,c.uTroikaStrokeOpacity.value=p,c.uTroikaFillOpacity.value=h??1,c.uTroikaCurveRadius.value=this.curveRadius||0;let w=this.clipRect;if(w&&Array.isArray(w)&&w.length===4)c.uTroikaClipRect.value.fromArray(w);else{const v=(this.fontSize||.1)*100;c.uTroikaClipRect.value.set(l[0]-v,l[1]-v,l[2]+v,l[3]+v)}this.geometry.applyClipRect(c.uTroikaClipRect.value)}c.uTroikaSDFDebug.value=!!this.debugSDF,t.polygonOffset=!!this.depthOffset,t.polygonOffsetFactor=t.polygonOffsetUnits=this.depthOffset||0;const n=i?this.outlineColor||0:this.color;if(n==null)delete t.color;else{const a=t.hasOwnProperty("color")?t.color:t.color=new Re;(n!==a._input||typeof n=="object")&&a.set(a._input=n)}let o=this.orientation||Wn;if(o!==t._orientation){let a=c.uTroikaOrient.value;o=o.replace(/[^-+xyz]/g,"");let l=o!==Wn&&o.match(/^([-+])([xyz])([-+])([xyz])$/);if(l){let[,d,u,m,h]=l;Kr.set(0,0,0)[u]=d==="-"?1:-1,zn.set(0,0,0)[h]=m==="-"?-1:1,So.lookAt(Mu,Kr.cross(zn),zn),a.setFromMatrix4(So)}else a.identity();t._orientation=o}}_parsePercent(t){if(typeof t=="string"){let i=t.match(/^(-?[\d.]+)%$/),c=i?parseFloat(i[1]):NaN;t=(isNaN(c)?0:c/100)*this.fontSize}return t}localPositionToTextCoords(t,i=new an){i.copy(t);const c=this.curveRadius;return c&&(i.x=Math.atan2(t.x,Math.abs(c)-Math.abs(t.z))*Math.abs(c)),i}worldPositionToTextCoords(t,i=new an){return Kr.copy(t),this.localPositionToTextCoords(this.worldToLocal(Kr),i)}raycast(t,i){const{textRenderInfo:c,curveRadius:s}=this;if(c){const n=c.blockBounds,o=s?ai():oi(),a=o.geometry,{position:l,uv:d}=a.attributes;for(let u=0;u<d.count;u++){let m=n[0]+d.getX(u)*(n[2]-n[0]);const h=n[1]+d.getY(u)*(n[3]-n[1]);let p=0;s&&(p=s-Math.cos(m/s)*s,m=Math.sin(m/s)*s),l.setXYZ(u,m,h,p)}a.boundingSphere=this.geometry.boundingSphere,a.boundingBox=this.geometry.boundingBox,o.matrixWorld=this.matrixWorld,o.material.side=this.material.side,mr.length=0,o.raycast(t,mr);for(let u=0;u<mr.length;u++)mr[u].object=this,i.push(mr[u])}}copy(t){const i=this.geometry;return super.copy(t),this.geometry=i,Du.forEach(c=>{this[c]=t[c]}),this}clone(){return new this.constructor().copy(this)}};ii.forEach(e=>{const t="_private_"+e;Object.defineProperty(li.prototype,e,{get(){return this[t]},set(i){i!==this[t]&&(this[t]=i,this._needsSync=!0)}})});new bs;new Re;const Ru=f.forwardRef(({sdfGlyphSize:e=64,anchorX:t="center",anchorY:i="middle",font:c,fontSize:s=1,children:n,characters:o,onSync:a,...l},d)=>{const u=Ge(({invalidate:g})=>g),[m]=f.useState(()=>new li),[h,p]=f.useMemo(()=>{const g=[];let b="";
220return f.Children.forEach(n,x=>{typeof x=="string"||typeof x=="number"?b+=x:g.push(x)}),[g,b]},[n]);return od(()=>new Promise(g=>xu({font:c,characters:o},g)),["troika-text",c,o]),f.useLayoutEffect(()=>void m.sync(()=>{u(),a&&a(m)})),f.useEffect(()=>()=>m.dispose(),[m]),f.createElement("primitive",st({object:m,ref:d,font:c,text:p,anchorX:t,anchorY:i,fontSize:s,sdfGlyphSize:e},l),h)});function ci(e,t,i){const c=Ge(h=>h.size),s=Ge(h=>h.viewport),n=typeof e=="number"?e:c.width*s.dpr,o=c.height*s.dpr,a=(typeof e=="number"?i:e)||{},{samples:l=0,depth:d,...u}=a,m=f.useMemo(()=>{const h=new ad(n,o,{minFilter:ln,magFilter:ln,type:id,...u});return d&&(h.depthTexture=new ld(n,o,cd)),h.samples=l,h},[]);return f.useLayoutEffect(()=>{m.setSize(n,o),l&&(m.samples=l)},[l,m,n,o]),f.useEffect(()=>()=>m.dispose(),[]),m}const Uu=e=>typeof e=="function",di=f.forwardRef(({envMap:e,resolution:t=256,frames:i=1/0,children:c,makeDefault:s,...n},o)=>{const a=Ge(({set:x})=>x),l=Ge(({camera:x})=>x),d=Ge(({size:x})=>x),u=f.useRef(null);f.useImperativeHandle(o,()=>u.current,[]);const m=f.useRef(null),h=ci(t);f.useLayoutEffect(()=>{n.manual||u.current.updateProjectionMatrix()},[d,n]),f.useLayoutEffect(()=>{u.current.updateProjectionMatrix()}),f.useLayoutEffect(()=>{if(s){const x=l;return a(()=>({camera:u.current})),()=>a(()=>({camera:x}))}},[u,s,a]);let p=0,g=null;const b=Uu(c);return Ct(x=>{b&&(i===1/0||p<i)&&(m.current.visible=!1,x.gl.setRenderTarget(h),g=x.scene.background,e&&(x.scene.background=e),x.gl.render(x.scene,u.current),x.scene.background=g,x.gl.setRenderTarget(null),m.current.visible=!0,p++)}),f.createElement(f.Fragment,null,f.createElement("orthographicCamera",st({left:d.width/-2,right:d.width/2,top:d.height/2,bottom:d.height/-2,ref:u},n),!b&&c),f.createElement("group",{ref:m},b&&c(h.texture)))}),Fu=e=>typeof e=="function",Lu=f.forwardRef(({envMap:e,resolution:t=256,frames:i=1/0,makeDefault:c,children:s,...n},o)=>{const a=Ge(({set:x})=>x),l=Ge(({camera:x})=>x),d=Ge(({size:x})=>x),u=f.useRef(null);f.useImperativeHandle(o,()=>u.current,[]);const m=f.useRef(null),h=ci(t);f.useLayoutEffect(()=>{n.manual||(u.current.aspect=d.width/d.height)},[d,n]),f.useLayoutEffect(()=>{u.current.updateProjectionMatrix()});let p=0,g=null;const b=Fu(s);return Ct(x=>{b&&(i===1/0||p<i)&&(m.current.visible=!1,x.gl.setRenderTarget(h),g=x.scene.background,e&&(x.scene.background=e),x.gl.render(x.scene,u.current),x.scene.background=g,x.gl.setRenderTarget(null),m.current.visible=!0,p++)}),f.useLayoutEffect(()=>{if(c){const x=l;return a(()=>({camera:u.current})),()=>a(()=>({camera:x}))}},[u,c,a]),f.createElement(f.Fragment,null,f.createElement("perspectiveCamera",st({ref:u},n),!b&&s),f.createElement("group",{ref:m},b&&s(h.texture)))}),Ou=f.forwardRef(({children:e,domElement:t,onChange:i,onMouseDown:c,onMouseUp:s,onObjectChange:n,object:o,makeDefault:a,camera:l,enabled:d,axis:u,mode:m,translationSnap:h,rotationSnap:p,scaleSnap:g,space:b,size:x,showX:w,showY:v,showZ:N,...y},k)=>{const S=Ge(j=>j.controls),T=Ge(j=>j.gl),E=Ge(j=>j.events),A=Ge(j=>j.camera),M=Ge(j=>j.invalidate),R=Ge(j=>j.get),_=Ge(j=>j.set),F=l||A,C=t||E.connected||T.domElement,P=f.useMemo(()=>new dd(F,C),[F,C]),U=f.useRef(null);f.useLayoutEffect(()=>(o?P.attach(o instanceof cn?o:o.current):U.current instanceof cn&&P.attach(U.current),()=>void P.detach()),[o,e,P]),f.useEffect(()=>{if(S){const j=D=>S.enabled=!D.value;return P.addEventListener("dragging-changed",j),()=>P.removeEventListener("dragging-changed",j)}},[P,S]);const K=f.useRef(),z=f.useRef(),O=f.useRef(),L=f.useRef();return f.useLayoutEffect(()=>void(K.current=i),[i]),f.useLayoutEffect(()=>void(z.current=c),[c]),f.useLayoutEffect(()=>void(O.current=s),[s]),f.useLayoutEffect(()=>void(L.current=n),[n]),f.useEffect(()=>{const j=G=>{M(),K.current==null||K.current(G)},D=G=>z.current==null?void 0:z.current(G),I=G=>O.current==null?void 0:O.current(G),B=G=>L.current==null?void 0:L.current(G);return P.addEventListener("change",j),P.addEventListener("mouseDown",D),P.addEventListener("mouseUp",I),P.addEventListener("objectChange",B),()=>{P.removeEventListener("change",j),P.removeEventListener("mouseDown",D),P.removeEventListener("mouseUp",I),P.removeEventListener("objectChange",B)}},[M,P]),f.useEffect(()=>{if(a){const j=R().controls;return _({controls:P}),()=>_({controls:j})}},[a,P]),f.createElement(f.Fragment,null,f.createElement("primitive",{ref:k,object:P,enabled:d,axis:u,mode:m,translationSnap:h,rotationSnap:p,scaleSnap:g,space
220:b,size:x,showX:w,showY:v,showZ:N}),f.createElement("group",st({ref:U},y),e))});function Gu({defaultScene:e,defaultCamera:t,renderPriority:i=1}){const{gl:c,scene:s,camera:n}=Ge();let o;return Ct(()=>{o=c.autoClear,i===1&&(c.autoClear=!0,c.render(e,t)),c.autoClear=!1,c.clearDepth(),c.render(s,n),c.autoClear=o},i),f.createElement("group",{onPointerOver:()=>null})}function Iu({children:e,renderPriority:t=1}){const{scene:i,camera:c}=Ge(),[s]=f.useState(()=>new ud);return f.createElement(f.Fragment,null,fd(f.createElement(f.Fragment,null,e,f.createElement(Gu,{defaultScene:i,defaultCamera:c,renderPriority:t})),s,{events:{priority:t+1}}))}const ui=f.createContext({}),Bu=()=>f.useContext(ui),Vu=2*Math.PI,Hn=new cn,Co=new $a,[zt,Kn]=[new Pt,new Pt],Eo=new Ae,To=new Ae,zu=e=>"minPolarAngle"in e,Mo=e=>"getTarget"in e,Wu=({alignment:e="bottom-right",margin:t=[80,80],renderPriority:i=1,onUpdate:c,onTarget:s,children:n})=>{const o=Ge(S=>S.size),a=Ge(S=>S.camera),l=Ge(S=>S.controls),d=Ge(S=>S.invalidate),u=f.useRef(null),m=f.useRef(null),h=f.useRef(!1),p=f.useRef(0),g=f.useRef(new Ae(0,0,0)),b=f.useRef(new Ae(0,0,0));f.useEffect(()=>{b.current.copy(a.up),Hn.up.copy(a.up)},[a]);const x=f.useCallback(S=>{h.current=!0,(l||s)&&(g.current=s?.()||(Mo(l)?l.getTarget(g.current):l?.target)),p.current=a.position.distanceTo(Eo),zt.copy(a.quaternion),To.copy(S).multiplyScalar(p.current).add(Eo),Hn.lookAt(To),Kn.copy(Hn.quaternion),d()},[l,a,s,d]);Ct((S,T)=>{if(m.current&&u.current){var E;if(h.current)if(zt.angleTo(Kn)<.01)h.current=!1,zu(l)&&a.up.copy(b.current);else{const A=T*Vu;zt.rotateTowards(Kn,A),a.position.set(0,0,1).applyQuaternion(zt).multiplyScalar(p.current).add(g.current),a.up.set(0,1,0).applyQuaternion(zt).normalize(),a.quaternion.copy(zt),Mo(l)&&l.setPosition(a.position.x,a.position.y,a.position.z),c?c():l&&l.update(T),d()}Co.copy(a.matrix).invert(),(E=u.current)==null||E.quaternion.setFromRotationMatrix(Co)}});const w=f.useMemo(()=>({tweenCamera:x}),[x]),[v,N]=t,y=e.endsWith("-center")?0:e.endsWith("-left")?-o.width/2+v:o.width/2-v,k=e.startsWith("center-")?0:e.startsWith("top-")?o.height/2-N:-o.height/2+N;return f.createElement(Iu,{renderPriority:i},f.createElement(ui.Provider,{value:w},f.createElement(di,{makeDefault:!0,ref:m,position:[0,0,200]}),f.createElement("group",{ref:u,position:[y,k,0]},n)))};function Yn({scale:e=[.8,.05,.05],color:t,rotation:i}){return f.createElement("group",{rotation:i},f.createElement("mesh",{position:[.4,0,0]},f.createElement("boxGeometry",{args:e}),f.createElement("meshBasicMaterial",{color:t,toneMapped:!1})))}function Wt({onClick:e,font:t,disabled:i,arcStyle:c,label:s,labelColor:n,axisHeadScale:o=1,...a}){const l=Ge(b=>b.gl),d=f.useMemo(()=>{const b=document.createElement("canvas");b.width=64,b.height=64;const x=b.getContext("2d");return x.beginPath(),x.arc(32,32,16,0,2*Math.PI),x.closePath(),x.fillStyle=c,x.fill(),s&&(x.font=t,x.textAlign="center",x.fillStyle=n,x.fillText(s,32,41)),new md(b)},[c,s,n,t]),[u,m]=f.useState(!1),h=(s?1:.75)*(u?1.2:1)*o,p=b=>{b.stopPropagation(),m(!0)},g=b=>{b.stopPropagation(),m(!1)};return f.createElement("sprite",st({scale:h,onPointerOver:i?void 0:p,onPointerOut:i?void 0:e||g},a),f.createElement("spriteMaterial",{map:d,"map-anisotropy":l.capabilities.getMaxAnisotropy()||1,alphaTest:.3,opacity:s?1:.75,toneMapped:!1}))}const Hu=({hideNegativeAxes:e,hideAxisHeads:t,disabled:i,font:c="18px Inter var, Arial, sans-serif",axisColors:s=["#ff2060","#20df80","#2080ff"],axisHeadScale:n=1,axisScale:o,labels:a=["X","Y","Z"],labelColor:l="#000",onClick:d,...u})=>{const[m,h,p]=s,{tweenCamera:g}=Bu(),b={font:c,disabled:i,labelColor:l,onClick:d,axisHeadScale:n,onPointerDown:i?void 0:x=>{g(x.object.position),x.stopPropagation()}};return f.createElement("group",st({scale:40},u),f.createElement(Yn,{color:m,rotation:[0,0,0],scale:o}),f.createElement(Yn,{color:h,rotation:[0,0,Math.PI/2],scale:o}),f.createElement(Yn,{color:p,rotation:[0,-Math.PI/2,0],scale:o}),!t&&f.createElement(f.Fragment,null,f.createElement(Wt,st({arcStyle:m,position:[1,0,0],label:a[0]},b)),f.createElement(Wt,st({arcStyle:h,position:[0,1,0],label:a[1]},b)),f.createElement(Wt,st({arcStyle:p,position:[0,0,1],label:a[2]},b)),!e&&f.createElement(f.Fragment,null,f.createElement(Wt,st({arcStyle:m,position:[-1,0,0]},b)),f.createElement(Wt,st({arcStyle:h,position:[0,-1,0]},b)),f.createElement(Wt,st({arcStyle:p,position:[0,0,-1]},b)))))};function _r(){const[e,t]=f.useState(null),[i,c]=f.useState(Ce),[s,n]=f.useState(!1),[o,a]=f.useState(null),l=f.useCallback(async()=>
220{if(!Ce){t(null),c(!1);return}c(!0),a(null);try{const{invoke:h}=await Ye(async()=>{const{invoke:g}=await import("./core-DhEqZVGG.js");return{invoke:g}},[]),p=await h("get_workspace_root");t(p??null)}catch(h){a(h instanceof Error?h.message:String(h))}finally{c(!1)}},[]);f.useEffect(()=>{l()},[l]);const d=f.useCallback(async h=>{if(Ce){n(!0),a(null);try{const{invoke:p}=await Ye(async()=>{const{invoke:g}=await import("./core-DhEqZVGG.js");return{invoke:g}},[]);await p("set_workspace_root",{path:h}),t(h)}catch(p){throw a(p instanceof Error?p.message:String(p)),p}finally{n(!1)}}},[]),u=f.useCallback(async()=>{if(!Ce)return null;n(!0),a(null);try{const{invoke:h}=await Ye(async()=>{const{invoke:g}=await import("./core-DhEqZVGG.js");return{invoke:g}},[]),p=await h("default_workspace_root");return await h("set_workspace_root",{path:p}),t(p),p}catch(h){return a(h instanceof Error?h.message:String(h)),null}finally{n(!1)}},[]),m=f.useCallback(async()=>{if(!Ce)return null;n(!0),a(null);try{const{invoke:h}=await Ye(async()=>{const{invoke:g}=await import("./core-DhEqZVGG.js");return{invoke:g}},[]),p=await h("pick_workspace_folder");return p?(await h("set_workspace_root",{path:p}),t(p),p):null}catch(h){return a(h instanceof Error?h.message:String(h)),null}finally{n(!1)}},[]);return{isDesktop:Ce,root:e,loading:i,setting:s,error:o,refresh:l,setToDefault:u,setViaPicker:m,setExplicit:d}}const Ku={free:0,hobby:1250,pro:2500,gamer:7500,max:5250,ultra:22e3},Yu=200;function Ao(e,t){if(!e)return"";const i=Math.floor((Date.now()-new Date(e).getTime())/1e3);if(i<5)return t("studioMenu.timeAgo.justNow");const c=[[31536e3,"year"],[2592e3,"month"],[86400,"day"],[3600,"hour"],[60,"minute"],[1,"second"]];for(const[s,n]of c){const o=Math.floor(i/s);if(o>=1)return t(`studioMenu.timeAgo.${n}`,{count:o})}return t("studioMenu.timeAgo.justNow")}function fi({game:e,usage:t,onShare:i,onPublish:c,renderAs:s="default",titleNode:n,subtitle:o}){const{t:a,i18n:l}=Ee("studio"),[d,u]=f.useState(!1),[m,h]=f.useState(!1),[p,g]=f.useState(!1),[b,x]=f.useState(null),[w,v]=f.useState(!1),N=f.useRef(null),y=Da(),{isLight:k,theme:S,toggleTheme:T}=Rt(),{user:E}=Ut(),A=E?.organization?.billing_managed?E.organization.name:null,M=ic(),R=lc(),{setShowUpgradeModal:_,setUpgradeModalContext:F}=at(),C=!!(e?.remixed_from_id||e?.template_derived_from_id);f.useEffect(()=>{if(!d)return;const W=ne=>{N.current&&!N.current.contains(ne.target)&&u(!1)},ee=ne=>{ne.key==="Escape"&&u(!1)};return document.addEventListener("mousedown",W),document.addEventListener("keydown",ee),()=>{document.removeEventListener("mousedown",W),document.removeEventListener("keydown",ee)}},[d]);const P=!E?.subscription_tier||E.subscription_tier==="free",U=ac(),K=sc(e,E?.username,U),[z,O]=f.useState(!1),L=pc(e?.id,{surface:"studio_menu",isOwner:K==="owner",hardNavigate:!0}),j=f.useCallback(W=>{u(!1),W()},[]),D=va(),I=()=>{F("general"),_(!0)},B=[{label:A?l.t("company:usage.poolTitle",{org:A,defaultValue:"{{org}} credits"}):a(P&&!R?"studioMenu.upgrade":"studioMenu.buyCredits"),icon:"coins",action:()=>j(I)},{label:a("studioMenu.getFreeCredits"),icon:"gift",iconPrefix:"fas",action:()=>j(()=>g(!0))},"separator",{label:a("studioMenu.settings"),icon:"gear",action:()=>j(()=>y(e?`/studio/${e.id}/settings`:"/settings/account"))},...e?[{label:a("studioMenu.rename"),icon:"text-size",action:()=>j(()=>h(!0))}]:[],...K?[{label:L.isPending?l.t("common:makeCopy.making","Making a copy…"):l.t("common:makeCopy.action","Make a copy"),icon:"copy",action:()=>{u(!1),K==="staff"?O(!0):L.start()},disabled:L.isPending}]:[],"separator",...e?["exportFlyout"]:[{label:a("studioMenu.export"),icon:"download",action:()=>{},disabled:!0}],{label:a("studioMenu.publish"),icon:"globe",action:()=>j(c)},...e?[{label:a("studioMenu.share"),icon:"share-nodes",action:()=>j(i)}]:[],"separator",{label:a(S==="dark"?"studioMenu.lightMode":"studioMenu.darkMode"),icon:S==="dark"?"sun-bright":"moon",action:()=>{T()}},{label:a("studioMenu.exitDashboard"),icon:"arrow-left",action:()=>j(()=>y("/dashboard"))}],G=W=>{u(!1),x(W)},q=W=>{u(!1),W==="tier"?(F(tt.exportLocked),_(!0)):v(!0)},V=s==="chatNavTrigger";return r.jsxs(r.Fragment,{children:[r.jsxs("div",{ref:N,className:"relative",children:[V?r.jsxs("button",{onClick:()=>u(!d),className:"flex items-center gap-3 hover:opacity-80 transition-opacity cursor-pointer",children:[r.jsxs("div",{className:"max-w-[100px] md:max-w-full flex-1 min-w-0 flex flex-col text-left mr-1",children:[r.jsx("h3",{className:me("text-sm font-medium truncate"),children:n??(e?.name||"New Game")}),r.jsx("p",{className:me("text-xs text-muted-foreground truncate"),children:o||(e?.name?a("studioMenu.editingLatestVersion",{timeAgo:Ao(e?.updated_at,a)}):a("studioMenu.editingLatest"))})]}),r.jsx(H,{icon:["far","chevron-down"],className:me("text-[10px] text-muted-foreground transition-transform duration-150",d&&"rotate-180")}
220)]}):r.jsxs("button",{onClick:()=>u(!d),className:"flex items-center gap-3 hover:opacity-80 transition-opacity cursor-pointer",children:[r.jsx("img",{src:"/logos/tessala-icon-svg.svg",alt:"Tesana",className:me("w-6 h-6 object-contain transition-opacity",k?"invert-0":"invert")}),r.jsxs("div",{className:"max-w-[100px] md:max-w-full flex-1 min-w-0 flex flex-col text-left mr-1",children:[r.jsx("h3",{className:me("text-sm font-medium truncate"),children:e?.name||"New Game"}),r.jsx("p",{className:me("text-xs text-muted-foreground truncate"),children:e?.name?a("studioMenu.editingLatestVersion",{timeAgo:Ao(e?.updated_at,a)}):a("studioMenu.editingLatest")})]}),r.jsx(H,{icon:["far","chevron-down"],className:me("text-[10px] text-muted-foreground transition-transform duration-150",d&&"rotate-180")})]}),r.jsxs("div",{className:me("absolute top-full left-0 mt-2 min-w-[240px] rounded-md border border-border bg-card shadow-lg z-50 p-2 transition-all duration-150 origin-top-left",d?"scale-100 opacity-100":"scale-95 opacity-0 pointer-events-none"),children:[t&&(()=>{const ee=t.daily_credits_enabled!==!1?t.daily_credits_per_day??qi:0,ne=D??la(t),J=oc(t,Ku[E?.subscription_tier||"free"]??0),$=ee+J,ge=$>0?Math.min(100,Math.max(2,Math.round(ne/$*100))):0,ce=t.min_credits_to_start_run??Yu,re=!t.is_overdrawn&&ne>ce,oe=Qi(t.monthly_resets_at,l.language),de=ne<0;return r.jsxs("div",{className:"px-3 pt-1 pb-3",children:[r.jsxs("div",{className:"flex items-center justify-between mb-1.5",children:[r.jsx("span",{className:"text-xs text-muted-foreground",children:A?l.t("company:usage.poolTitle",{org:A,defaultValue:"{{org}} credits"}):a("studioMenu.credits")}),r.jsx("span",{className:me("text-sm font-medium",re?"text-foreground":"text-red-400"),children:ne.toLocaleString()})]}),de&&r.jsx("p",{className:"mb-1.5 text-[11px] text-red-400",children:a("studioMenu.overdrawnNotice",{defaultValue:"Balance is negative from a previous build — top-ups clear it first."})}),r.jsx("div",{className:"w-full h-1.5 rounded-full bg-foreground
220/10 overflow-hidden",children:r.jsx("div",{className:me("h-full rounded-full transition-all",re?"bg-yellow-600":"bg-red-400"),style:{width:`${ge}%`}})}),oe&&r.jsx("p",{className:"mt-1.5 text-[11px] text-muted-foreground",children:a("studioMenu.creditsReset",{date:oe,defaultValue:"Resets {{date}}"})})]})})(),t&&r.jsx("div",{className:"my-2 -mx-2 border-b border-border"}),B.map((W,ee)=>W==="separator"?r.jsx("div",{className:"my-2 -mx-2 border-t border-border"},`sep-${ee}`):W==="exportFlyout"&&e?r.jsx(Ol,{label:a("studioMenu.export"),icon:"download",children:r.jsx(Gl,{gameId:e.id,isPaid:M,isDerivative:C,engineKind:on(e),onSelectFormat:G,onLockedClick:q})},"exportFlyout"):typeof W=="string"?null:r.jsxs("button",{onClick:W.action,disabled:W.disabled,className:me("w-full px-3 py-2 rounded-sm text-sm text-left flex items-center gap-2 transition-colors cursor-pointer disabled:opacity-50","text-muted-foreground hover:text-foreground hover:bg-foreground/5","disabled:opacity-40 disabled:cursor-default disabled:hover:bg-transparent"),children:[r.jsx(H,{icon:[W.iconPrefix||"far",W.icon],className:"text-xs w-4 text-center"}),r.jsx("span",{className:"flex-1",children:W.label}),W.badge&&r.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-foreground
220/8 text-muted-foreground",children:W.badge})]},W.label))]})]}),e&&r.jsx(Xu,{isOpen:m,onClose:()=>h(!1),game:e}),e&&K==="staff"&&r.jsx(gc,{open:z,onClose:()=>O(!1),gameName:e.name,onConfirm:()=>L.start(()=>O(!1)),pending:L.isPending}),r.jsx(fc,{isOpen:p,onClose:()=>g(!1)}),e&&b&&r.jsx(_a,{isOpen:!!b,onClose:()=>x(null),game:e,format:b}),e&&r.jsx(Il,{isOpen:w,onClose:()=>v(!1),reason:e.remixed_from_id?"remix":"template_clone"})]})}function Xu({isOpen:e,onClose:t,game:i}){const{t:c}=Ee("studio"),[s,n]=f.useState(i.name),o=er();f.useEffect(()=>{e&&n(i.name)},[e,i.name]);const a=Qt({mutationFn:()=>Ft.update(i.id,{name:s}),onSuccess:()=>{o.invalidateQueries({queryKey:["games"]}),t()}});return r.jsx(lt,{children:e&&r.jsxs(r.Fragment,{children:[r.jsx(Be.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:"fixed inset-0 bg-black/80 z-50",onClick:t}),r.jsx(Be.div,{initial:{opacity:0,scale:.95,y:20},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.95,y:20},transition:{duration:.2,ease:[.16,1,.3,1]},className:"fixed inset-0 z-50 flex items-center justify-center p-4 pointer-events-none",children:r.jsxs("div",{className:"relative bg-card rounded-lg border border-border p-4 pt-10 md:p-8 md:pt-8 max-w-md w-full pointer-events-auto",onClick:l=>l.stopPropagation(),children:[r.jsx("button",{onClick:t,className:"absolute top-2 right-2 md:top-4 md:right-4 w-9 h-9 flex items-center justify-center rounded-md transition-colors cursor-pointer hover:bg-foreground
220/4 text-muted-foreground hover:text-foreground",children:r.jsx(H,{icon:["far","xmark"]})}),r.jsx("h3",{className:"text-lg text-foreground mb-4",children:c("studioMenu.renameTitle")}),r.jsx("p",{className:"text-base text-muted-foreground mb-6",children:c("studioMenu.renameDescription")}),r.jsx("input",{type:"text",value:s,onChange:l=>n(l.target.value),onKeyDown:l=>{l.key==="Enter"&&s.trim()&&s!==i.name&&a.mutate()},className:"w-full h-9 px-3 border border-border rounded-md text-sm text-foreground placeholder:text-muted-foreground focus:outline-none focus:border-foreground transition-colors mb-6 bg-transparent",placeholder:c("studioMenu.gameNamePlaceholder"),autoFocus:!0}),r.jsxs("div",{className:"flex gap-3 items-center justify-start",children:[r.jsx("button",{onClick:t,className:"h-9 px-3 bg-foreground/6 text-foreground text-sm rounded-md hover:bg-foreground/10 transition-colors cursor-pointer",children:c("studioMenu.cancel")}),r.jsx("button",{onClick:()=>a.mutate(),disabled:!s.trim()||s===i.name||a.isPending,className:"h-9 px-3 bg-foreground text-background text-sm rounded-md hover:opacity-80 transition-all disabled:opacity-30 cursor-pointer",children:a.isPending?c("studioMenu.saving"):c("studioMenu.save")})]})]})})]})})}function $u({gameId:e,orgName:t,scope:i,onScopeChange:c,canChange:s,canPublishPublicly:n,isSaving:o,shareUrl:a,canShare:l,onNavigate:d}){const{t:u}=Ee("company"),[m,h]=f.useState(!1),p=()=>{navigator.clipboard.writeText(a),h(!0),window.setTimeout(()=>h(!1),2e3)};return r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"border-b border-border px-4 py-3",children:[r.jsxs("div",{className:"mb-2 flex items-center justify-between gap-2",children:[r.jsx("p",{className:"text-xs text-muted-foreground",children:u("sharing.whoCanOpen")}),r.jsx(jc,{orgName:t})]}),r.jsx(kc,{variant:"compact",value:i,onChange:c,orgName:t,canPublishPublicly:n,readOnly:!s,busy:o})]}),r.jsxs("div",{className:"border-b border-border px-4 py-3",children:[r.jsx("p",{className:"mb-1.5 text-xs text-muted-foreground",children:u("sharing.link")}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("input",{type:"text",readOnly:!0,value:a,"aria-label":u("sharing.link"),className:"flex-1 truncate rounded border border-border bg-foreground
220/5 px-2 py-1.5 text-xs text-muted-foreground"}),r.jsx("button",{type:"button",onClick:p,disabled:!l,className:me("cursor-pointer rounded px-2 py-1.5 text-xs transition-colors disabled:cursor-not-allowed disabled:opacity-40",m?"bg-green-500/15 text-green-400":"bg-foreground/8 text-muted-foreground hover:text-foreground"),children:u(m?"common.copied":"common.copy")})]}),i!=="public"&&r.jsx("p",{className:"mt-1.5 text-[11px] leading-4 text-muted-foreground",children:i==="organization"?u("sharing.linkNoteOrg",{org:t}):u("sharing.linkNotePrivate",{org:t})})]}),r.jsx("div",{className:"p-3",children:r.jsxs(vt,{to:`/studio/${e}/settings/preferences`,onClick:d,className:"flex h-8 w-full items-center justify-center gap-1.5 rounded-md px-3 text-xs text-muted-foreground transition-colors hover:bg-foreground/5 hover:text-foreground",children:[r.jsx(H,{icon:["far","gear"],className:"text-[10px]","aria-hidden":!0}),u("sharing.moreSettings")]})})]})}const mi="tesana_live_notice:",hi=new Map;function Po(e){const t=`${mi}${e}`;try{const i=window.localStorage.getItem(t);return i==="armed"||i==="seen"?i:null}catch{return hi.get(t)??null}}function Do(e,t){const i=`${mi}${e}`;try{window.localStorage.setItem(i,t)}catch{hi.set(i,t)}}function qu(e,t){const[i,c]=f.useState(()=>e?Po(e):null);f.useEffect(()=>{c(e?Po(e):null)},[e]),f.useEffect(()=>{!e||t||i||(Do(e,"armed"),c("armed"))},[e,t,i]);const s=f.useCallback(()=>{e&&(Do(e,"seen"),c("seen"))},[e]);return{armed:i==="armed",markSeen:s}}function Qu({open:e,address:t,gameId:i,gameName:c,onSeen:s}){const{t:n}=Ee("publishing"),[o,a]=f.useState(!1),[l,d]=f.useState(!1),u=t.replace(/^https?:\/\//,"").replace(/\/$/,""),m=async()=>{try{await navigator.clipboard.writeText(t)}catch{return}a(!0),window.setTimeout(()=>{a(!1),s()},1500)};return r.jsxs(r.Fragment,{children:[r.jsx("div",{role:"status","aria-live":"polite",children:e&&r.jsx("div",{"data-testid":"game-live-notice",className:"absolute top-full right-0 z-40 mt-2 w-[320px] rounded-md border border-border bg-card p-3 shadow-xl",children:r.jsxs("div",{className:"flex items-start gap-2.5",children:[r.jsx("span",{className:"flex h-7 w-7 shrink-0 items-center justify-center rounded-md bg-green-500/15 text-green-500",children:r.jsx(H,{icon:["far","globe"],className:"text-xs","aria-hidden":!0})}),r.jsxs("div",{className:"min-w-0 flex-1",children:[r.jsx("p",{className:"break-words text-sm text-foreground",children:n("live.title",{address:u})}),r.jsxs("div",{className:"mt-2 flex items-center gap-2",children:[r.jsxs("button",{type:"button",onClick:()=>{m()},className:me("inline-flex h-7 cursor-pointer items-center gap-1.5 rounded-md px-2.5 text-xs transition-colors",o?"bg-green-500/15 text-green-500":"bg-foreground text-background hover:opacity-80"),children:[r.jsx(H,{icon:["far",o?"check":"copy"],className:"text-[10px]","aria-hidden":!0}),n(o?"live.copied":"live.copy")]}),r.jsxs("button",{type:"button",onClick:()=>{d(!0),s()},className:"inline-flex h-7 cursor-pointer items-center gap-1.5 rounded-md border border-border px-2.5 text-xs text-foreground transition-colors hover:bg-foreground
220/5",children:[r.jsx(H,{icon:["far","share-nodes"],className:"text-[10px]","aria-hidden":!0}),n("live.share")]})]})]}),r.jsx("button",{type:"button",onClick:s,"aria-label":n("live.dismiss"),className:"flex h-6 w-6 shrink-0 cursor-pointer items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-foreground/5 hover:text-foreground",children:r.jsx(H,{icon:["far","xmark"],className:"text-xs","aria-hidden":!0})})]})})}),l&&r.jsx(Ra,{isOpen:!0,onClose:()=>d(!1),title:c,shareUrl:t,gameId:i,isOwner:!0})]})}const Ju={public:{dot:"bg-green-500",pulse:!0},private:{dot:"bg-blue-400",pulse:!1},pending:{dot:"bg-blue-400",pulse:!1},draft:{dot:"bg-blue-400",pulse:!1},building:{dot:"bg-yellow-500",pulse:!0}};function pi({game:e,isGenerating:t,runMode:i,externalOpen:c,onOpenChange:s}){const{t:n}=Ee("studio"),{t:o}=Ee("publishing"),[a,l]=f.useState(!1),d=f.useRef(null),u=f.useRef(null),m=er(),{isLight:h}=Rt(),p=e?.organization?.name??null,g=Nc(e),b=p?g.scope:null,x=c??a,w=f.useCallback(X=>{l(X),s?.(X)},[s]),v=Sc(e),N=yc({enabled:!!e&&!p}),y=Fc(e,{active:x}),[k,S]=f.useState(!1),T=()=>{u.current?.focus(),w(!1),S(!0)},E=r.jsx(Ld,{controls:y,onSeeAll:T}),A=t?"building":b?b==="public"?"public":"draft":v.view.status,M=A==="building"?i??(e?.default_run_mode||null):null,R=M?dc[M]:null,_=M?cc[M]:A,F=Ju[A],C=!!p&&!!b&&A!=="building",P={...F,dot:R?.dot??(C&&b==="organization"?"bg-accent":F.dot),label:C?r.jsx(io,{scope:b,orgName:p}):A==="building"?n(`publish.state.${_}`):o(`status.${A}`),description:C?r.jsx(io,{scope:b,orgName:p,form:"description"}):A==="building"?n(`publish.stateDesc.${_}`):o(`statusDesc.${A}`)};f.useEffect(()=>{if(!x)return;const X=ke=>{d.current&&!d.current.contains(ke.target)&&w(!1)},ye=ke=>{ke.key==="Escape"&&w(!1)};return document.addEventListener("mousedown",X),document.addEventListener("keydown",ye),()=>{document.removeEventListener("mousedown",X),document.removeEventListener("keydown",ye)}},[x]);const{data:U}=mt({queryKey:["game-analytics-quick",e?.id],queryFn:()=>Ji.getAnalytics(e.id),enabled:x&&!!e?.id,staleTime:3e4}),{user:K}=Ut(),z=!!K?.can_publish_to_steam,O=!!K?.can_publish_to_appstore,[L,j]=f.useState(!1),[D,I]=f.useState(""),[B,G]=f.useState("free"),[q,V]=f.useState(!1),[W,ee]=f.useState(!1),ne=e?ca(e):null,J=e?`${window.location.origin}${da(e)}`:"",$=v.isSaving?e?.visibility:v.visibility,ge=!p&&$==="published",ce=qu(p?null:e?.id,ge),{data:re}=mt({queryKey:ao(e?.id),queryFn:()=>Yt.getVanity(e.id),enabled:!!e?.id&&!p,staleTime:3e4,refetchInterval:X=>ce.armed&&ge&&!X.state.data?.address?15e3:!1}),oe=(re?.address?`https://${re.address}`:null)??Zi(e),de=e?{...e,visibility:v.visibility,is_public:v.visibility==="published"?e.is_public:!1}:null,Z=oe??(de?ua(de):""),le=oe?"address":el(de)?"store":"play",ie=!oe&&N.ready&&!N.vanityAutoAssign,Q=!oe&&N.vanityAutoAssign&&!ge;f.useEffect(()=>{e&&(G(e.pricing_type==="free"?"free":"paid"),I(e.price||""))},[e?.pricing_type,e?.price]);const be=Qt({mutationFn:X=>Ft.updateSettings(e.id,X),onSuccess:()=>{m.invalidateQueries({queryKey:["game-settings"]}),m.invalidateQueries({queryKey:["games"]})}}),ae=X=>{G(X),X==="free"&&be.mutate({pricing_type:"free",price:null})},fe=()=>
220{const X=parseFloat(D);!isNaN(X)&&X>=.5&&be.mutate({pricing_type:"paid",price:X.toFixed(2)})},[se,Ne]=f.useState(!1),ue=K?.connect_onboarding_complete,he=e?.pricing_type==="paid"&&e.price?`$${parseFloat(e.price).toFixed(2)}`:e?.pricing_type==="pay_what_you_want"&&e.minimum_price?`From $${parseFloat(e.minimum_price).toFixed(2)}`:n("publish.free"),Y=e?[{label:n("publish.readiness.description"),done:!!e.description},{label:n("publish.readiness.tagline"),done:!!e.tagline},{label:n("publish.readiness.poster"),done:!!e.poster_image},{label:n("publish.readiness.category"),done:!!e.classified_category}]:[];return e?r.jsxs("div",{ref:d,className:"relative",children:[r.jsxs("button",{ref:u,onClick:()=>w(!x),"aria-expanded":x,className:me("relative flex items-center gap-2 h-9 px-3 rounded-md text-sm transition-all cursor-pointer",A==="public"?h?"bg-green-500/25 text-green-700 hover:bg-green-500/30":"bg-green-500/25 text-green-400 hover:bg-green-500/30":A==="building"&&R?h?me(R.surface,R.textLight,"hover:opacity-80"):R.chip:A==="building"?h?"bg-yellow-500/25 text-yellow-700 hover:bg-yellow-500/30":"bg-yellow-500/25 text-yellow-400 hover:bg-yellow-500/30":A==="private"||A==="pending"?"bg-foreground
220/[0.08] text-foreground hover:bg-foreground/[0.12]":"bg-foreground text-background hover:opacity-80"),children:[r.jsx("span",{className:me("w-2 h-2 rounded-full",P.dot,P.pulse&&"animate-pulse")}),P.label,r.jsx(Lc,{show:y.showDot})]}),r.jsxs("div",{className:me("absolute top-full right-0 mt-2 w-[320px] rounded-md border border-border bg-card shadow-xl z-50 transition-all duration-150 origin-top-right","max-h-[min(70vh,calc(100dvh-7rem))] overflow-y-auto overscroll-contain",x?"scale-100 opacity-100":"scale-95 opacity-0 pointer-events-none"),children:[r.jsxs("div",{className:"px-4 pt-3 pb-3 border-b border-border",children:[r.jsxs("div",{className:"flex items-center gap-2.5 mb-1",children:[r.jsx("span",{className:me("w-2.5 h-2.5 rounded-full",P.dot,P.pulse&&"animate-pulse")}),r.jsx("span",{className:"text-sm font-medium text-foreground",children:P.label})]}),r.jsx("p",{className:"text-xs text-muted-foreground",children:P.description})]}),r.jsx("div",{className:"px-4 py-3 border-b border-border",children:r.jsxs("div",{className:"flex items-center gap-3",children:[ne&&r.jsx("div",{className:"w-14 h-10 rounded overflow-hidden shrink-0 border border-border",children:r.jsx("img",{src:ne,alt:"",className:"w-full h-full object-cover"})}),r.jsxs("div",{className:"min-w-0 flex-1",children:[r.jsx("p",{className:"text-sm font-medium text-foreground truncate",children:e.name}),e.tagline&&r.jsx("p",{className:"text-xs text-muted-foreground truncate mt-0.5",children:e.tagline})]})]})}),p&&b?r.jsxs(r.Fragment,{children:[r.jsx($u,{gameId:e.id,orgName:p,scope:b,onScopeChange:g.setScope,canChange:g.canChange,canPublishPublicly:g.canPublishPublicly,isSaving:g.isSaving,shareUrl:J,canShare:!!e.download_url,onNavigate:()=>w(!1)}),E]}):r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"px-4 py-3 border-b border-border",children:[r.jsx("p",{className:"text-xs text-muted-foreground mb-2",children:o("whoCanPlay")}),r.jsx(_c,{control:v,variant:"compact",gameId:e.id})]}),E,r.jsxs("div",{className:"px-4 py-3 border-b border-border",children:[r.jsxs("div",{className:"flex items-center justify-between mb-2",children:[r.jsx("p",{className:"text-xs text-muted-foreground",children:n("publish.pricing")}),r.jsx("span",{className:"text-xs font-medium text-foreground",children:he})]}),r.jsxs("div",{className:"flex items-center gap-1.5 mb-2",children:[r.jsx("button",{onClick:()=>ae("free"),className:me("flex-1 h-7 text-xs rounded transition-colors cursor-pointer",B==="free"?"bg-foreground text-background font-medium":"bg-foreground
220/6 text-muted-foreground hover:text-foreground"),children:n("publish.free")}),r.jsx("button",{onClick:()=>ae("paid"),className:me("flex-1 h-7 text-xs rounded transition-colors cursor-pointer",B==="paid"?"bg-foreground text-background font-medium":"bg-foreground/6 text-muted-foreground hover:text-foreground"),children:n("publish.paid")})]}),B==="paid"&&r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsxs("div",{className:"relative flex-1",children:[r.jsx("span",{className:"absolute left-2 top-1/2 -translate-y-1/2 text-xs text-muted-foreground",children:"$"}),r.jsx("input",{type:"number",step:"0.01",min:"0.50",value:D,onChange:X=>I(X.target.value),onBlur:fe,onKeyDown:X=>X.key==="Enter"&&fe(),placeholder:n("publish.pricePlaceholder"),className:"w-full h-7 text-xs bg-foreground/5 border border-border rounded pl-5 pr-2 text-foreground placeholder:text-muted-foreground/50"})]}),r.jsx("span",{className:"text-[10px] text-muted-foreground shrink-0",children:n("publish.currencyUSD")})]}),!ue&&r.jsxs("button",{onClick:()=>Ne(!0),className:"w-full mt-2 h-7 text-xs rounded bg-emerald-500/10 text-emerald-400 hover:bg-emerald-500/15 transition-colors cursor-pointer disabled:opacity-50 flex items-center justify-center gap-1.5",children:[r.jsx(H,{icon:["far","building-columns"],className:"text-[10px]"}),n("publish.connectStripe")]}),ue&&D&&parseFloat(D)>=.5&&r.jsx("p",{className:"text-[10px] text-muted-foreground mt-1.5",children:n("publish.earningsPerSale",{amount:(parseFloat(D)*.7).toFixed(2)})})]})]}),U&&r.jsxs("div",{className:"px-4 py-2.5 border-b border-border flex items-center gap-5 text-xs text-muted-foreground",children:[r.jsxs("span",{children:[r.jsx("strong",{className:"text-foreground",children:U.total_views})," ",n("publish.views")]}),r.jsxs("span",{children:[r.jsx("strong",{className:"text-foreground",children:U.total_plays})," ",n("publish.plays")]}),r.jsxs("span",{children:[r.jsx("strong",{className:"text-foreground",children:U.total_favorites})," ",n("publish.favs")]})]}),v.visibility==="draft"&&r.jsxs("div",{className:"px-4 py-3 border-b border-border",children:[r.jsx("p",{className:"text-xs text-muted-foreground mb-2",children:n("publish.storefrontReadiness")}),r.jsx("div",{className:"grid grid-cols-2 gap-1.5",children:Y.map(X=>r.jsxs("div",{className:"flex items-center gap-1.5 text-xs",children:[r.jsx(H,{icon:["far",X.done?"circle-check":"circle"],className:me("text-[10px]",X.done?"text-green-500":"text-muted-foreground/40")}),r.jsx("span",{className:X.done?"text-foreground":"text-muted-foreground",children:X.label})]},X.label))}),r.jsxs(vt,{to:`/studio/${e.id}/settings/information`,onClick:()=>w(!1),className:"flex items-center gap-1.5 text-xs text-accent hover:underline mt-2",children:[r.jsx(H,{icon:["far","gear"],className:"text-[10px]"}),n("publish.setupStorefront")]})]}),r.jsxs("div",{className:"px-4 py-3 border-b border-border",children:[r.jsxs("div",{className:"flex items-center justify-between mb-1.5",children:[r.jsx("p",{className:"text-xs text-muted-foreground",children:o(le==="address"?"link.yourAddress":le==="store"?"link.storePage":"link.playLink")}),(oe||ie)&&r.jsx("button",{onClick:()=>{w(!1),ee(!0)},className:"text-[10px] text-accent hover:underline cursor-pointer",children:o(oe?"link.change":"link.claim")})]}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("input",{type:"text",readOnly:!0,value:Z,"aria-label":o(le==="address"?"link.yourAddress":"link.playLink"),className:"flex-1 text-xs bg-foreground
220/5 border border-border rounded px-2 py-1.5 text-muted-foreground truncate"}),r.jsx("button",{onClick:()=>{navigator.clipboard.writeText(Z),j(!0),setTimeout(()=>j(!1),2e3)},className:me("text-xs px-2 py-1.5 rounded transition-colors cursor-pointer",L?"bg-green-500/15 text-green-400":"bg-foreground/8 text-muted-foreground hover:text-foreground"),children:n(L?"publish.copied":"publish.copy")})]}),Q&&r.jsx("p",{className:"mt-1.5 text-[11px] leading-4 text-muted-foreground",children:o("address.whenPublic")})]}),r.jsxs("div",{className:"p-3 space-y-2",children:[v.view.status==="public"&&r.jsxs(r.Fragment,{children:[e.slug&&r.jsxs("a",{href:`/game/${e.slug}`,target:"_blank",rel:"noopener noreferrer",className:"w-full h-9 px-3 text-sm rounded-md bg-foreground text-background hover:opacity-80 transition-all cursor-pointer font-medium flex items-center justify-center gap-2",children:[n("publish.viewStorePage"),r.jsx(H,{icon:["far","arrow-up-right"],className:"text-[10px]"})]}),vc,r.jsx("button",{type:"button",onClick:()=>v.choose("private"),"aria-disabled":v.isSaving||void 0,className:"w-full h-9 px-3 text-sm rounded-md bg-foreground
220/6 text-muted-foreground hover:text-foreground hover:bg-foreground/10 transition-colors cursor-pointer aria-disabled:opacity-30 aria-disabled:cursor-not-allowed",children:o("action.makePrivate")})]}),r.jsxs(vt,{to:`/studio/${e.id}/settings/information`,onClick:()=>w(!1),className:"w-full h-8 px-3 text-xs rounded-md text-muted-foreground hover:text-foreground hover:bg-foreground/5 transition-colors flex items-center justify-center gap-1.5",children:[r.jsx(H,{icon:["far","gear"],className:"text-[10px]"}),n("publish.storefrontSettings")]}),z&&r.jsxs(vt,{to:`/studio/${e.id}/settings/steam`,onClick:()=>w(!1),className:"w-full h-8 px-3 text-xs rounded-md text-muted-foreground hover:text-foreground hover:bg-foreground/5 transition-colors flex items-center justify-center gap-1.5",children:[r.jsx(H,{icon:["fab","steam"],className:"text-[11px]"}),n("publish.publishOnSteam","Publish on Steam")]}),O&&r.jsxs(vt,{to:`/studio/${e.id}/settings/app-store`,onClick:()=>w(!1),className:"w-full h-8 px-3 text-xs rounded-md text-muted-foreground hover:text-foreground hover:bg-foreground
220/5 transition-colors flex items-center justify-center gap-1.5",children:[r.jsx(H,{icon:["fab","apple"],className:"text-[11px]"}),n("publish.publishOnAppStore","Publish on the App Store")]})]})]})]}),!p&&oe&&r.jsx(Qu,{open:ce.armed&&ge&&!x,address:oe,gameId:e.id,gameName:e.name,onSeen:ce.markSeen}),r.jsx(xc,{isOpen:q,onClose:()=>V(!1),initialGameId:e.id}),r.jsx(bc,{isOpen:se,onClose:()=>Ne(!1),returnUrl:`${window.location.origin}/studio/${e.id}/settings/monetization`}),y.available&&r.jsx(Pd,{open:k,onClose:()=>S(!1),controls:y}),!p&&r.jsx(wc,{isOpen:W,onClose:()=>ee(!1),game:e,onChanged:()=>m.invalidateQueries({queryKey:ao(e.id)})})]}):null}function Zu({version:e,gameId:t,open:i,onClose:c,onRevert:s,anchorRect:n}){const{t:o}=Ee("studio"),[a,l]=f.useState(!1),d=f.useRef(null),u=er(),m=Qt({mutationFn:()=>Ft.revertToVersion(t,e.version_number),onSuccess:x=>{u.invalidateQueries({queryKey:["versions",t]}),u.invalidateQueries({queryKey:["games"]}),s(e.version_number,x)}});f.useEffect(()=>{i||l(!1)},[i]),f.useEffect(()=>{if(!i)return;const x=v=>{d.current&&!d.current.contains(v.target)&&c()},w=v=>{v.key==="Escape"&&c()};return document.addEventListener("mousedown",x),document.addEventListener("keydown",w),()=>{document.removeEventListener("mousedown",x),document.removeEventListener("keydown",w)}},[i,c]);const h=f.useCallback(()=>{if(!a){l(!0);return}m.mutate()},[a,m]),p=!e.is_current&&!e.reverted,g=x=>{const w=Math.floor((Date.now()-new Date(x).getTime())/1e3);if(w<60)return o("version.timeAgo.justNow");const v=[[31536e3,"yearsAgo"],[2592e3,"monthsAgo"],[86400,"daysAgo"],[3600,"hoursAgo"],[60,"minutesAgo"]];for(const[N,y]of v){const k=Math.floor(w/N);if(k>=1)return o(`version.timeAgo.${y}`,{count:k})}return o("version.timeAgo.justNow")},b={};if(n){const x=Math.max(8,n.top),w=window.innerHeight-x-16;b.position="fixed",b.top=x,b.left=n.right+12,b.zIndex=50,b.maxHeight=`${w}px`}return r.jsx(lt,{children:i&&r.jsxs(Be.div,{ref:d,style:b,initial:{opacity:0,scale:.95,x:-8},animate:{opacity:1,scale:1,x:0},exit:{opacity:0,scale:.95,x:-8},transition:{duration:.15,ease:[.16,1,.3,1]},className:"w-[340px] max-h-[70vh] rounded-md border border-border bg-card shadow-xl overflow-hidden flex flex-col origin-left",children:[r.jsxs("div",{className:"flex items-center justify-between px-4 pt-3 pb-3",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsxs("span",{className:me("text-xs font-medium px-1.5 py-0.5 rounded",e.version_type==="generate"?"bg-green-500/15 text-green-400":"bg-blue-500/15 text-blue-400"),children:["v",e.version_number]}),r.jsx("span",{className:"text-xs text-muted-foreground",children:g(e.created_at)})]}),r.jsx("button",{onClick:c,className:"w-6 h-6 flex items-center justify-center rounded-sm text-muted-foreground hover:text-foreground hover:bg-foreground
220/5 transition-colors cursor-pointer",children:r.jsx(H,{icon:["far","xmark"],className:"text-xs"})})]}),r.jsxs("div",{className:"flex-1 overflow-y-auto px-4 pb-4",children:[r.jsxs("div",{className:"mb-2",children:[r.jsx("p",{className:"text-xs text-muted-foreground mb-1",children:o("version.detail.prompt")}),r.jsx("p",{className:"text-sm text-foreground leading-relaxed",children:e.prompt})]}),e.summary&&r.jsxs("div",{className:"mb-3",children:[r.jsx("p",{className:"text-xs text-muted-foreground mb-1",children:o("version.detail.summary")}),r.jsx("p",{className:"text-sm text-foreground/80",children:e.summary})]}),r.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[r.jsxs("span",{className:"flex items-center gap-1",children:[r.jsx(H,{icon:["far","code"],className:"text-[9px]"}),o("version.detail.filesChanged",{count:e.files_changed})]}),r.jsx("span",{children:"•"}),r.jsx("span",{className:"capitalize",children:e.version_type==="continue"?o("version.detail.typeEdit"):e.version_type})]})]}),p&&r.jsx("div",{className:"px-4 py-3 border-t border-border",children:a?r.jsxs("div",{children:[r.jsx("p",{className:"text-xs text-muted-foreground mb-2",children:o("version.detail.revertWarning")}),r.jsxs("div",{className:"flex gap-2",children:[r.jsx("button",{onClick:()=>
220l(!1),className:"flex-1 h-8 text-xs rounded-md bg-foreground/5 text-foreground hover:bg-foreground/10 transition-colors cursor-pointer",disabled:m.isPending,children:o("version.detail.cancel")}),r.jsx("button",{onClick:h,disabled:m.isPending,className:"flex-1 h-8 text-xs rounded-md bg-red-500/15 text-red-400 hover:bg-red-500/25 transition-colors cursor-pointer disabled:opacity-50",children:m.isPending?r.jsxs(r.Fragment,{children:[r.jsx(H,{icon:["far","spinner-third"],spin:!0,className:"mr-1.5"}),o("version.detail.reverting")]}):o("version.detail.confirmRevert")})]})]}):r.jsxs("button",{onClick:h,className:"w-full h-8 text-xs rounded-md bg-foreground/5 text-muted-foreground hover:text-foreground hover:bg-foreground/8 transition-colors cursor-pointer flex items-center justify-center gap-1.5",children:[r.jsx(H,{icon:["far","arrow-rotate-right"],className:"text-[10px]"}),o("version.detail.revertButton")]})}),e.reverted&&r.jsx("div",{className:"px-4 py-2.5 border-t border-border",children:r.jsx("p",{className:"text-xs text-muted-foreground text-center",children:o("version.detail.revertedPast")})}),e.is_current&&!e.reverted&&r.jsx("div",{className:"px-4 py-2.5 border-t border-border",children:r.jsxs("p",{className:"text-xs text-green-400 text-center flex items-center justify-center gap-1.5",children:[r.jsx(H,{icon:["far","circle-check"],className:"text-[10px]"}),o("version.detail.currentVersion")]})})]})})}function ef(e,t){const i=Math.floor((Date.now()-new Date(e).getTime())/1e3);if(i<60)return t("version.timeAgo.justNow");const c=[[31536e3,"y"],[2592e3,"mo"],[86400,"d"],[3600,"h"],[60,"min"]];for(const[s,n]of c){const o=Math.floor(i/s);if(o>=1)return t(`version.timeAgo.${n}`,{count:o})}return t("version.timeAgo.justNow")}function tf(){const{t:e}=Ee("studio"),t=at(),i=t.currentGame?.id,[c,s]=f.useState(null),[n,o]=f.useState(null),a=f.useRef(new Map),{data:l,isLoading:d}=mt({queryKey:["versions",i],queryFn:()=>Ft.getVersions(i),enabled:!!i,staleTime:3e4}),u=f.useCallback((g,b)=>{if(c?.version_number===g.version_number){s(null),o(null);return}s(g),o(b.getBoundingClientRect())},[c]),m=f.useCallback((g,b)=>{s(null),o(null),t.handleRevert(g,b)},[t]),h=f.useCallback(()=>{t.setShowTimeline(!1)},[t]),p=l?[...l].sort((g,b)=>b.version_number-g.version_number):[];return r.jsxs("div",{className:"flex flex-col h-full border border-border rounded-md overflow-hidden ml-3 mr-3 mb-2",children:[r.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(H,{icon:["far","clock"],className:"text-sm text-muted-foreground"}),r.jsx("h2",{className:"text-sm font-medium text-foreground",children:e("version.title")}),l&&r.jsxs("span",{className:"text-xs text-muted-foreground",children:["(",e("version.count",{count:l.filter(g=>!g.reverted).length}),")"]})]}),r.jsx("button",{onClick:h,className:"w-8 h-8 flex items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-foreground
220/5 transition-colors cursor-pointer",children:r.jsx(H,{icon:["far","xmark"],className:"text-sm"})})]}),r.jsx("div",{className:"flex-1 overflow-y-auto px-4 py-4",children:d?r.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-muted-foreground",children:[r.jsx(H,{icon:["far","spinner-third"],spin:!0,className:"text-lg mb-3"}),r.jsx("p",{className:"text-sm",children:e("version.loading")})]}):p.length===0?r.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-muted-foreground",children:[r.jsx(H,{icon:["far","clock"],className:"text-2xl mb-3 opacity-40"}),r.jsx("p",{className:"text-sm",children:e("version.empty")}),r.jsx("p",{className:"text-xs mt-1 opacity-60",children:e("version.emptyHint")})]}):r.jsxs("div",{className:"relative",children:[r.jsx("div",{className:"absolute left-[11px] top-3 bottom-3 w-px bg-border"}),p.map(g=>{const b=c?.version_number===g.version_number;return r.jsxs("button",{ref:x=>{x?a.current.set(g.version_number,x):a.current.delete(g.version_number)},onClick:x=>u(g,x.currentTarget),className:me("relative w-full text-left pl-8 pr-2 py-3 rounded-md transition-colors cursor-pointer group",b?"bg-foreground
220/8":"hover:bg-foreground/4",g.reverted&&"opacity-40"),children:[r.jsx("div",{className:me("absolute left-[4.5px] top-4 w-[14px] h-[14px] rounded-full border-2 transition-colors",g.is_current&&!g.reverted?"border-green-500 bg-card":g.reverted?"border-border bg-card":b?"border-foreground bg-card":"border-border bg-card group-hover:border-muted-foreground")}),r.jsxs("div",{className:"flex flex-col flex-1 min-w-0",children:[r.jsxs("div",{className:"flex items-center gap-2 mb-0.5",children:[r.jsxs("span",{className:me("text-[10px] font-medium px-1.5 py-0.5 rounded shrink-0",g.version_type==="generate"?"bg-green-500/10 text-green-500":"bg-blue-500/10 text-blue-400"),children:["v",g.version_number]}),g.is_current&&!g.reverted&&r.jsx("span",{className:"text-[10px] text-green-500 font-medium",children:e("version.current")}),g.reverted&&r.jsx("span",{className:"text-[10px] text-muted-foreground line-through",children:e("version.reverted")}),r.jsx("span",{className:"text-[10px] text-muted-foreground ml-auto shrink-0",children:ef(g.created_at,e)})]}),r.jsx("p",{className:me("text-sm leading-snug truncate overflow-hidden",g.reverted?"text-muted-foreground":"text-foreground"),children:g.prompt.length>80?g.prompt.slice(0,80)+"...":g.prompt}),g.summary&&!g.reverted&&r.jsx("p",{className:"text-xs text-muted-foreground mt-0.5 truncate overflow-hidden",children:g.summary})]})]},g.version_number)})]})}),r.jsx("div",{className:"px-4 py-3 border-t border-border",children:r.jsxs("button",{onClick:h,className:"w-full h-9 text-sm rounded-md bg-foreground
220/5 text-muted-foreground hover:text-foreground hover:bg-foreground/8 transition-colors cursor-pointer flex items-center justify-center gap-2",children:[r.jsx(H,{icon:["far","comment"],className:"text-xs"}),e("version.backToChat")]})}),c&&i&&xa.createPortal(r.jsx(Zu,{version:c,gameId:i,open:!!c,onClose:()=>{s(null),o(null)},onRevert:m,anchorRect:n}),document.body)]})}function rf(e){if(e==null)return null;const t=Math.max(0,Math.round(e/1e3)),i=Math.floor(t/60),c=t%60;return i===0?`${c}s`:`${i}m${c.toString().padStart(2,"0")}s`}const gi=f.memo(function({record:t,onBack:i,backLabel:c,embedded:s=!1,gameId:n,sessionId:o,agentKey:a}){const{t:l}=Ee("studio"),d=t?.status,u=d==="launching"||d==="running",m=d==="error",h=f.useMemo(()=>tl(t?.agent_id,a,t?.key),[t?.agent_id,t?.key,a]),p=f.useMemo(()=>({status:u?"in_progress":m?"failed":"complete",summary:t?.current_action||"",steps:[],updated_at:t?.ended_at||t?.started_at||new Date().toISOString(),activity_log:t?.entries||[]}),[u,m,t?.current_action,t?.ended_at,t?.started_at,t?.entries]),g=t?.usage,b=[t?.subagent_type?t.subagent_type.replace("-"," ").replace(/\b\w/g,v=>v.toUpperCase()):void 0,t?.mode==="async"?"async":null,rf(g?.duration_ms),g?.tool_uses!=null?`${g.tool_uses} tools`:null].filter(Boolean).join(" · "),x=r.jsxs("div",{className:me("flex items-center gap-3",s?"pb-2.5 mb-1":"px-4 py-2.25 border-b border-border"),children:[r.jsx("span",{className:me("w-2 h-2 rounded-full flex-shrink-0",u&&"bg-amber-400 animate-pulse",d==="completed"&&"bg-emerald-500",m&&"bg-destructive",d==="stopped"&&"bg-muted-foreground/50")}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("div",{className:"truncate text-sm font-medium text-foreground",title:t?.description||"",children:t?.description||l("subagent.title",{defaultValue:"Specialized agent"})}),b&&r.jsx("div",{className:"truncate text-xs text-muted-foreground",children:b})]}),r.jsx("button",{onClick:i,className:"w-8 h-8 flex items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-foreground
220/5 transition-colors cursor-pointer","aria-label":c||l("subagent.back",{defaultValue:"Back"}),title:c||l("subagent.back",{defaultValue:"Back"}),children:r.jsx(H,{icon:["far","xmark"],className:"text-sm"})})]}),w=r.jsxs(r.Fragment,{children:[r.jsx(Ga,{metadata:p,isLast:!1,isGenerating:u,messageTimestamp:t?.started_at||new Date().toISOString(),mode:"forward",gameId:n,sessionId:o,slice:h,emptyLabel:u?l("subagent.working",{defaultValue:"Working — activity will appear here…"}):l("subagent.noActivity",{defaultValue:"No captured activity for this agent."})}),t?.result_summary&&r.jsx("div",{className:"text-sm text-foreground/90 break-words",style:{wordBreak:"break-word"},children:r.jsx(Oa,{className:"leading-relaxed whitespace-pre-line",children:t.result_summary})})]});return s?r.jsxs("div",{children:[x,w]}):r.jsxs("div",{className:"flex-1 min-h-0 flex flex-col border border-border rounded-md mb-2 mr-3 ml-3",children:[x,r.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto px-3 pb-4",children:w}),r.jsx("div",{className:"px-4 py-3 border-t border-border",children:r.jsxs("button",{onClick:i,className:"w-full h-9 text-sm rounded-md bg-foreground
220/5 text-muted-foreground hover:text-foreground hover:bg-foreground/8 transition-colors cursor-pointer flex items-center justify-center gap-2",children:[r.jsx(H,{icon:["far","comment"],className:"text-xs"}),l("version.backToChat")]})})]})}),nf=f.memo(function(){const{t}=Ee("studio"),i=at(),c=i.subagentDrill,s=f.useMemo(()=>c?[...i.messages].reverse().find(o=>o.message_type==="generation"&&(o.session_id===c.sessionId||o.metadata?.session_id===c.sessionId))?.metadata?.subagents?.[c.key]:void 0,[i.messages,c]);return c?r.jsx(gi,{record:s,onBack:i.closeSubagentDrill,backLabel:t("subagent.backToChat",{defaultValue:"Back to chat"}),gameId:i.currentGame?.id??null,sessionId:c.sessionId,agentKey:c.key}):null});function xi({defaultPx:e,minPx:t,maxPx:i,storageKey:c,direction:s="right"}){const n=f.useCallback(g=>Math.max(t,Math.min(i,g)),[t,i]),[o,a]=f.useState(()=>{if(typeof window>"u"||!c)return n(e);const g=window.localStorage.getItem(c);if(!g)return n(e);const b=Number(g);return Number.isNaN(b)?n(e):n(b)}),[l,d]=f.useState(!1),u=f.useRef(0),m=f.useRef(0);f.useEffect(()=>{typeof window>"u"||!c||window.localStorage.setItem(c,String(o))},[o,c]),f.useEffect(()=>{a(g=>n(g))},[n]);const h=f.useCallback(g=>{a(n(g))},[n]),p=f.useCallback(g=>{g.preventDefault(),u.current=o,m.current=g.clientX,d(!0)},[o]);return f.useEffect(()=>{if(!l)return;const g=x=>{const w=x.clientX-m.current,v=s==="right"?u.current+w:u.current-w;a(n(v))},b=()=>d(!1);return document.addEventListener("mousemove",g),document.addEventListener("mouseup",b),document.body.style.cursor="col-resize",document.body.style.userSelect="none",()=>{document.removeEventListener("mousemove",g),document.removeEventListener("mouseup",b),document.body.style.cursor="",document.body.style.userSelect=""}},[l,n,s]),{width:o,isDragging:l,startResize:p,setWidth:h}}const sf={character:{icon:"user",color:"#66BB6A"},prop:{icon:"cube",color:"#AB47BC"},environment:{icon:"mountain",color:"#42A5F5"},texture:{icon:"palette",color:"#FF8C00"},image:{icon:"file-image",color:"#26A69A"},weapon:{icon:"sword",color:"#EF5350"},vehicle:{icon:"car",color:"#FFB300"},audio:{icon:"music",color:"#EF5350"}},of={icon:"file",color:"#90A4AE"},af={icon:"window",color:"#26C6DA"},lf=/\/(?:assets\/)?ui\//i;function Ns(e){return e.type!=="image"?!1:lf.test(e.url||"")}const cf={music:{icon:"music",color:"#7E57C2"},voice:{icon:"microphone",color:"#26A69A"},sfx:{icon:"volume",color:"#EF5350"},ui:{icon:"bell",color:"#FFB300"},ambient:{icon:"wind",color:"#66BB6A"}};function bi(e){const t=e.toLowerCase();if(t.includes("/audio/voice/"))return"voice";if(t.includes("/audio/music/"))return"music";if(t.includes("/audio/sfx/ui/"))return"ui";if(t.includes("/audio/ambient/"))return"ambient";if(t.includes("/audio/sfx/"))return"sfx";const i=t.split("/").pop()??"";return i.startsWith("music_")||i.startsWith("jingle_")?"music":i.startsWith("voice_")?"voice":i.startsWith("ui_")?"ui":i.startsWith("ambient_")?"ambient":null}function df(e){if(e.type==="audio"){const t=bi(e.url);if(t)return cf[t]}return Ns(e)?af:sf[e.type]||of}function uf(e){if(e.type==="audio"){const t=bi(e.url);if(t)return t}return Ns(e)?"ui":e.type}const ff=new Set(["image","texture"]),mf=["3d_models","textures","images","ui","audio"],hf=/\.(glb|gltf|fbx|obj)(\?|$)/i,pf=/\.(png|jpe?g|gif|webp|svg|avif)(\?|$)/i;function gf(e){if(e.type==="audio")return"audio";if(e.type==="texture")return"textures";if(Ns(e))return"ui";if(e.type==="image")return"images";const t=e.url||"";return hf.test(t)?"3d_models":pf.test(t)?"images":"3d_models"}function xf({assets:e,onSelect:t,selectedId:i}){const{t:c}=Ee("studio"),s=f.useMemo(()=>{const a={"3d_models":[],textures:[],images:[],ui:[],audio:[]};for(const l of e)a[gf(l)].push(l);return a},[e]),n=mf.filter(a=>s[a].length>0);if(n.length===0)return r.jsx("div",{className:"p-3 grid grid-cols-2 md:grid-cols-3 lg:grid-cols-5 gap-3"});const o={"3d_models":c("assetViewer.group3dModels",{defaultValue:"3D Models"}),textures:c("assetViewer.groupTextures",{defaultValue:"Textures"}),images:c("assetViewer.groupImages",{defaultValue:"Images"}),ui:c("assetViewer.groupUi",{defaultValue:"UI"}),audio:c("assetViewer.groupAudio",{defaultValue:"Audio"})};return r.jsx("div",{className:"p-6 space-y-6",children:n.map(a=>r.jsxs("section",{children:[r.jsxs("div",{className:"flex items-center gap-2 mb-2 px-1",children:[r.jsx("h3",{className:"text-[10px] uppercase tracking-wider text-muted-foreground font-medium",children:o[a]}
220),r.jsx("span",{className:"text-[10px] text-muted-foreground/60 tabular-nums",children:s[a].length})]}),r.jsx("div",{className:"grid grid-cols-2 md:grid-cols-3 lg:grid-cols-5 gap-3",children:s[a].map(l=>r.jsx(bf,{asset:l,isSelected:l.id===i,onSelect:t},l.id))})]},a))})}function bf({asset:e,isSelected:t,onSelect:i}){const{t:c}=Ee("studio"),s=e.status==="ready",n=df(e),o=uf(e),a=ff.has(e.type)?e.url:e.thumbnail_url,{previewSrc:l,showImage:d,onError:u}=Oc(a),m=s&&d;return r.jsxs("button",{onClick:()=>s&&i(e),disabled:!s,className:`
221        relative flex flex-col items-center p-3 rounded-lg transition-all duration-100
222        ${s?"cursor-pointer":"cursor-wait opacity-60"}
223        ${t?"bg-accent/10 shadow-[0_0_12px_color-mix(in_srgb,var(--color-accent)_15%,transparent)]":"bg-card hover:border-border-hover hover:bg-foreground/6"}
224        animate-in fade-in slide-in-from-bottom-2
225      `,children:[r.jsx("div",{className:"w-full aspect-square rounded-md bg-foreground/4 flex items-center justify-center mb-2 overflow-hidden",children:s?m&&l?r.jsx("img",{src:l,alt:e.name,loading:"lazy",draggable:!1,onError:u,className:"w-full h-full object-contain"}):r.jsx(H,{icon:["far",n.icon],style:{color:n.color},className:"text-4xl"}):r.jsxs("div",{className:"flex flex-col items-center gap-2",children:[r.jsx("div",{className:"spinner w-5 h-5 border-2"}),r.jsx("span",{className:"text-[10px] text-muted-foreground",children:c("assetViewer.generating")})]})}),r.jsx("p",{className:"text-xs text-foreground truncate w-full text-center mb-2",children:e.name}),r.jsx("span",{className:"text-[9px] uppercase tracking-wider px-1.5 py-px rounded bg-foreground
225/[0.06] text-muted-foreground",children:o}),e.has_animations&&s&&r.jsx("div",{className:"absolute top-2 right-2 w-4 h-4 rounded-full bg-accent/20 border border-accent/40 flex items-center justify-center text-accent",title:c("assetViewer.hasAnimations"),children:r.jsx(H,{icon:["far","play"],className:"text-[7px]"})})]})}const vi=12,vf=22,yf=8;function wf(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(0)} KB`:`${(e/(1024*1024)).toFixed(1)} MB`}function jf({node:e,depth:t,expanded:i,onToggle:c,onSelectFile:s,selectedUrl:n}){const o=xs(i),a=!!(e.children&&e.children.length>0);return r.jsxs("li",{children:[r.jsxs("button",{type:"button",onClick:c,className:"flex w-full items-center gap-1.5 truncate px-2 py-0.5 text-left text-foreground hover:bg-foreground/5",style:{paddingLeft:`${t*vi+yf}px`},children:[r.jsx(H,{icon:["far","chevron-right"],className:`w-2.5 shrink-0 text-[9px] text-muted-foreground transition-transform ${i?"rotate-90":""}`}),r.jsx(H,{icon:["far",o.icon],style:{color:o.color},className:"w-3.5 shrink-0 text-[12px]"}),r.jsx("span",{className:"truncate",children:e.name})]}),i&&a?r.jsx("ul",{children:e.children.map((l,d)=>r.jsx(yi,{node:l,depth:t+1,onSelectFile:s,selectedUrl:n},`${l.name}-${d}`))}):null]})}function kf({node:e,depth:t,onSelectFile:i,selectedUrl:c}){const s=!!e.url&&e.url===c,n=Lt(e.name);return r.jsxs("li",{className:`group relative flex items-stretch ${s?"bg-accent/10 text-accent":"text-foreground hover:bg-foreground
225/5"}`,children:[r.jsxs("button",{type:"button",onClick:()=>i(e),className:"flex min-w-0 flex-1 items-center gap-1.5 truncate py-0.5 pr-1 text-left",style:{paddingLeft:`${t*vi+vf}px`},children:[r.jsx(H,{icon:["far",n.icon],style:{color:n.color},className:"w-3.5 shrink-0 text-[12px]"}),r.jsx("span",{className:"truncate",children:e.name})]}),e.size_bytes!=null&&e.size_bytes>0?r.jsx("span",{className:"flex shrink-0 items-center pr-2 text-[10px] text-muted-foreground/70",children:wf(e.size_bytes)}):null]})}function yi({node:e,depth:t,onSelectFile:i,selectedUrl:c}){const[s,n]=f.useState(t<2);return e.type!=="directory"?r.jsx(kf,{node:e,depth:t,onSelectFile:i,selectedUrl:c}):r.jsx(jf,{node:e,depth:t,expanded:s,onToggle:()=>n(o=>!o),onSelectFile:i,selectedUrl:c})}function Ro({tree:e,onSelectFile:t,selectedUrl:i}){return!e.children||e.children.length===0?r.jsx("div",{className:"p-4 text-xs text-muted-foreground text-center",children:"No assets found"}):r.jsx("ul",{className:"h-full overflow-y-auto py-1 text-[13px] leading-tight",children:e.children.map((c,s)=>r.jsx(yi,{node:c,depth:0,onSelectFile:t,selectedUrl:i},`${c.name}-${s}`))})}const Xn={duration:.18,ease:[.16,1,.3,1]},Ht={opacity:0,scale:.96,y:8},$n={opacity:1,scale:1,y:0},Uo="bg-card/95 border border-border shadow-xl rounded-md",Nf="w-full px-3 py-2 rounded-md text-sm bg-transparent border border-border text-foreground placeholder:text-muted-foreground/50 focus:outline-none focus:border-foreground transition-all",Sf=f.memo(function({asset:t,hidden:i,onRegenerate:c,onRequestDelete:s}){const{t:n}=Ee("studio"),[o,a]=f.useState("idle"),[l,d]=f.useState(""),u=f.useRef(null),m=f.useRef(null);f.useEffect(()=>{m.current!==t.id&&(m.current=t.id,a("idle"),d(""))},[t.id]),f.useEffect(()=>{if(o!=="editing-prompt")return;const x=u.current;if(!x)return;const w=window.requestAnimationFrame(()=>{x.focus(),x.setSelectionRange(x.value.length,x.value.length)});return()=>window.cancelAnimationFrame(w)},[o]);const h=()=>{d(t.generation_prompt??""),a("editing-prompt")},p=()=>{c(t.id,l),a("idle"),d("")},g=()=>{a("idle"),d("")},b=()=>s(t);return r.jsx(lt,{children:!i&&r.jsx(Be.div,{className:"absolute bottom-6 left-1/2 -translate-x-1/2 z-20",initial:Ht,animate:$n,exit:Ht,transition:Xn,children:r.jsx(lt,{mode:"wait",initial:!1,children:o==="idle"?r.jsxs(Be.div,{initial:Ht,animate:$n,exit:Ht,transition:Xn,className:me("inline-flex items-center gap-2 pl-2 pr-2 py-2",Uo),children:[r.jsxs("button",{type:"button",onClick:h,className:"h-8 px-2.5 text-sm rounded-sm bg-foreground text-background hover:opacity-80 transition-opacity cursor-pointer flex items-center gap-1.5 whitespace-nowrap flex-shrink-0",children:[r.jsx(H,{icon:["far","arrow-rotate-right"],className:"text-xs"}),n("assetActions.regenerate",{defaultValue:"Regenerate"})]}),r.jsx(Ke,{content:n("assetActions.deleteTooltip",{defaultValue:"Delete asset"}),position:"top",children:r.jsx("button",{type:"button",onClick:b,"aria-label":n("assetActions.deleteTooltip",{defaultValue:"Delete asset"}),className:"w-8 h-8 rounded-sm text-red-400 hover:text-red-300 bg-red-500/10 hover:bg-red-500/16 transition-colors flex items-center justify-center cursor-pointer flex-shrink-0",children:r.jsx(H,{icon:["far","trash"],className:"text-sm"})})})]},"idle"):r.jsxs(Be.div,{initial:Ht,animate:$n,exit:Ht,transition:Xn,className:me("w-[320px] sm:w-[440px] p-3",Uo),children:[r.jsx("p",{className:"text-[11px] uppercase tracking-wider mb-2 text-muted-foreground",children:n("assetActions.editPromptLabel",{defaultValue:"Regenerate prompt"})}),r.jsx("textarea",{ref:u,value:l,onChange:x=>d(x.target.value),onKeyDown:x=>{x.key==="Escape"&&(x.preventDefault(),g()),(x.metaKey||x.ctrlKey)&&x.key==="Enter"&&(x.preventDefault(),p())},placeholder:n("assetActions.editPromptPlaceholder",{defaultValue:"Describe what you want this asset to look / sound like…"}),rows:4,className:me(Nf,"leading-relaxed resize-y")}),r.jsxs("div",{className:"flex items-center justify-end gap-2 mt-2",children:[r.jsx("button",{type:"button",onClick:g,className:"h-8 px-2.5 text-sm rounded-sm text-muted-foreground hover:text-foreground hover:bg-foreground
225/8 transition-colors cursor-pointer",children:n("assetActions.cancel",{defaultValue:"Cancel"})}),r.jsxs("button",{type:"button",onClick:p,className:"h-8 px-2.5 text-sm rounded-sm bg-foreground text-background hover:opacity-80 transition-opacity cursor-pointer flex items-center gap-1.5",children:[r.jsx(H,{icon:["far","arrow-rotate-right"],className:"text-xs"}),n("assetActions.confirmRegenerate",{defaultValue:"Regenerate"})]})]})]},"edit")})},"asset-actions-root")})});function _f({isOpen:e,onClose:t,asset:i,onConfirm:c}){const{t:s}=Ee("studio"),[n,o]=f.useState(!1),[a,l]=f.useState(null),d=async()=>{if(i){o(!0),l(null);try{await c(i),t()}catch(p){l(p instanceof Error?p.message:String(p))}finally{o(!1)}}},u=i?.id??"",m=u.split("/").pop()??"",h=u.split("/").slice(0,-1).join("/");return r.jsx(lt,{onExitComplete:()=>{l(null)},children:e&&i&&r.jsxs(r.Fragment,{children:[r.jsx(Be.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:"fixed inset-0 bg-black/80 z-50",onClick:t}),r.jsx(Be.div,{initial:{opacity:0,scale:.95,y:20},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.95,y:20},transition:{duration:.2,ease:[.16,1,.3,1]},className:"fixed inset-0 z-50 flex items-center justify-center p-4 pointer-events-none",children:r.jsxs("div",{className:"relative bg-card rounded-lg border border-border p-4 pt-10 md:p-8 md:pt-8 max-w-md w-full pointer-events-auto",onClick:p=>p.stopPropagation(),children:[r.jsx("button",{onClick:t,disabled:n,className:"absolute top-2 right-2 md:top-4 md:right-4 w-9 h-9 flex items-center justify-center rounded-md transition-colors cursor-pointer hover:bg-foreground
225/4 text-muted-foreground hover:text-foreground disabled:opacity-30","aria-label":s("deleteAssetModal.close",{defaultValue:"Close"}),children:r.jsx(H,{icon:["far","xmark"]})}),r.jsx("h3",{className:"text-lg text-foreground mb-4",children:s("deleteAssetModal.title",{defaultValue:"Delete asset"})}),r.jsxs("p",{className:"text-base text-muted-foreground mb-6",children:[s("deleteAssetModal.bodyPrefix",{defaultValue:"Are you sure you want to delete"})," ",r.jsxs("strong",{className:"text-foreground",children:['"',m,'"']}),h?r.jsxs(r.Fragment,{children:[" ",s("deleteAssetModal.bodyFromPrefix",{defaultValue:"from"})," ",r.jsx("span",{className:"font-mono text-foreground",children:h})]}):null,"? ",s("deleteAssetModal.bodyTrail",{defaultValue:"This is permanent — the AI will remove the file from the game, clean up any references to it, and rebuild so it's gone next play."})]}),a?r.jsx("div",{className:"p-3 bg-red-500/8 border border-red-500/20 rounded-md text-red-400 text-sm mb-6",children:a}):null,r.jsxs("div",{className:"flex gap-3 items-center justify-start",children:[r.jsx("button",{onClick:t,disabled:n,className:"h-9 px-3 bg-foreground
225/6 text-foreground text-sm rounded-md hover:bg-foreground/10 transition-colors cursor-pointer disabled:opacity-30",children:s("deleteAssetModal.cancel",{defaultValue:"Cancel"})}),r.jsx("button",{onClick:d,disabled:n,className:"h-9 px-3 bg-red-500/8 text-red-400 text-sm rounded-md hover:bg-red-500/12 transition-all disabled:opacity-60 cursor-pointer",children:n?s("deleteAssetModal.deleting",{defaultValue:"Deleting…"}):s("deleteAssetModal.confirm",{defaultValue:"Delete asset"})})]})]})})]})})}const Fo=f.lazy(()=>Ye(()=>import("./ModelOrbitViewer-B5v3ssr6.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11]))),Cf=f.lazy(()=>Ye(()=>import("./ThirdPersonViewer-D-wJ2WG7.js"),__vite__mapDeps([12,1,2,4,5,6,3,7,8,9,10,11]))),Lo=f.lazy(()=>Ye(()=>import("./ImagePreview-DlhLxFM_.js"),__vite__mapDeps([13,1,2,3,6,7,8]))),Ef=f.lazy(()=>Ye(()=>import("./AudioPreview-Br79jIjx.js"),__vite__mapDeps([14,1,2,3,6,7,8]))),Tf=new Set(["third_person","first_person","top_down","2d_platformer"]);function Mf(e,t){return e.type==="character"&&e.has_animations&&!!t&&Tf.has(t)}function Af(){return r.jsx("div",{className:"w-full h-full flex items-center justify-center bg-card",children:r.jsx(_t,{size:"md",text:Xt.t("assetViewer.loadingViewer",{ns:"studio"}),overlayColor:fa})})}class Pf extends f.Component{constructor(t){super(t),this.state={hasError:!1,errorMessage:"",errorMessageKey:null}}static getDerivedStateFromError(t){let i=null,c=t.message||"";if(c.includes("Could not load")){const n=c.match(/Could not load (.+?):/)?.[1]||"";i=n.startsWith("/Users")||n.startsWith("/home")||n.startsWith("C:\\")?"assetViewer.invalidAssetUrl":"assetViewer.failedToLoadModel",c=""}return{hasError:!0,errorMessage:c,errorMessageKey:i}}render(){return this.state.hasError?r.jsx("div",{className:"w-full h-full flex items-center justify-center bg-card",children:r.jsxs("div",{className:"flex flex-col items-center gap-4 max-w-sm px-6 text-center",children:[r.jsx("div",{className:"w-12 h-12 rounded-full bg-destructive/15 border border-destructive/30 flex items-center justify-center text-destructive",children:r.jsx(H,{icon:["far","circle-exclamation"],className:"text-xl"})}),r.jsx("p",{className:"text-sm text-foreground",children:Xt.t("assetViewer.couldNotLoad",{ns:"studio",name:this.props.assetName||Xt.t("assetViewer.asset",{ns:"studio"})})}),r.jsx("p",{className:"text-xs text-muted-foreground leading-relaxed",children:this.state.errorMessageKey?Xt.t(this.state.errorMessageKey,{ns:"studio"}):this.state.errorMessage}),this.props.onBack&&r.jsx("button",{onClick:this.props.onBack,className:"px-4 py-2 rounded-md bg-foreground
225/5 hover:bg-foreground/10 text-muted-foreground hover:text-foreground text-sm transition-colors",children:Xt.t("assetViewer.backToGallery",{ns:"studio"})})]})}):this.props.children}}function Df(e,t){if(!e.url)return null;const i=t.find(l=>l.url===e.url);if(i)return i;const c=e.name.split(".").pop()?.toLowerCase()??"",s=new Set(["glb","gltf"]),n=new Set(["png","jpg","jpeg","gif","webp","svg"]),o=new Set(["mp3","wav","ogg","m4a","webm"]);let a="prop";if(o.has(c))a="audio";else if(n.has(c))a="texture";else if(!s.has(c))return null;return{id:`tree-${e.url}`,type:a,name:e.name.replace(/\.[^.]+$/,""),url:e.url,has_animations:!1,status:"ready"}}function Rf({assets:e,projectTemplate:t,isGenerating:i,tree:c,onSelectAsset:s,isHydrating:n,onRegenerateAsset:o,onDeleteAsset:a}){const{t:l}=Ee("studio"),[d,u]=f.useState("gallery"),[m,h]=f.useState("grid"),[p,g]=f.useState(null),b=f.useRef(!1),[x,w]=f.useState(null),v=xi({defaultPx:220,minPx:180,maxPx:480,storageKey:"onetap_asset_tree_width"}),N=!!c&&!!c.children&&c.children.length>0,y=e.filter(M=>M.status==="ready");f.useEffect(()=>{if(b.current)return;const M=y.find(R=>R.type==="character");M&&(b.current=!0,g(M),u("detail"),s?.())},[y,s]);const k=f.useCallback(M=>{g(M),u("detail"),s?.()},[s]),S=f.useCallback(M=>{const R=Df(M,e);R&&(g(R),u("detail"),s?.())},[e,s]),T=f.useCallback(()=>{u("gallery"),g(null)},[]),E=()=>{if(!p)return null;if(p.type==="audio")return r.jsx(Ef,{asset:p});if(p.type==="image")return r.jsx(Lo,{asset:p});if(p.type==="texture")return r.jsx(Lo,{asset:p});if(Mf(p,t))switch(t){case"third_person":return r.jsx(Cf,{asset:p});default:return r.jsx(Fo,{asset:p})}return r.jsx(Fo,{asset:p})},A=d==="detail"&&N;return r.jsxs("div",{className:"h-full flex flex-col",children:[r.jsxs("div",{className:"flex items-center gap-3 px-4 py-3 min-h-14.25 border-b border-border",children:[d==="detail"&&r.jsx("button",{onClick:T,className:"w-7 h-7 flex items-center justify-center rounded-md bg-foreground
225/5 hover:bg-foreground/10 text-muted-foreground hover:text-foreground transition-colors",title:l("assetViewer.backToGallery"),"aria-label":l("assetViewer.backToGallery"),children:r.jsx(H,{icon:["far","arrow-left"],className:"text-xs"})}),r.jsx("div",{className:"flex-1 min-w-0",children:r.jsxs("div",{className:"flex items-center gap-2",children:[i&&r.jsx("div",{className:"w-2 h-2 rounded-full bg-accent animate-pulse"}),r.jsx("span",{className:"text-sm text-foreground",children:l(i?"assetViewer.assetsGenerating":"assetViewer.assetPreview")})]})}),d==="gallery"&&N&&r.jsxs("div",{className:"p-1 gap-1 bg-foreground/6 flex rounded-md overflow-hidden",children:[r.jsx("button",{onClick:()=>h("grid"),className:`px-2 h-6 rounded-sm text-xs transition-colors ${m==="grid"?"bg-foreground/10 text-foreground":"text-muted-foreground hover:text-foreground hover:bg-foreground/6"}`,title:l("assetViewer.gridViewTitle"),children:l("assetViewer.grid")}),r.jsx("button",{onClick:()=>h("tree"),className:`px-2 h-6 rounded-sm text-xs transition-colors ${m==="tree"?"bg-foreground
225/10 text-foreground":"text-muted-foreground hover:text-foreground hover:bg-foreground/6"}`,title:l("assetViewer.folderViewTitle"),children:l("assetViewer.files")})]}),r.jsx("span",{className:"text-xs text-muted-foreground",children:l("assetViewer.assetCount",{count:e.length})})]}),r.jsxs("div",{className:"flex-1 overflow-hidden relative flex",children:[A&&r.jsxs("aside",{className:"relative shrink-0 flex flex-col border-r border-border bg-background",style:{width:`${v.width}px`},children:[r.jsx("div",{className:"flex-1 min-h-0",children:r.jsx(Ro,{tree:c,onSelectFile:S,selectedUrl:p?.url})}),r.jsx("div",{role:"separator","aria-orientation":"vertical","aria-label":l("assetViewer.resizeTree",{defaultValue:"Resize asset tree"}),onMouseDown:v.startResize,className:`absolute -right-1 top-0 bottom-0 z-10 w-2 cursor-col-resize ${v.isDragging?"":"group"}`,children:r.jsx("div",{className:`mx-auto h-full w-px transition-colors ${v.isDragging?"bg-accent/80":"bg-transparent group-hover:bg-accent/40"}`})})]}),r.jsx("div",{className:"flex-1 overflow-hidden",children:d==="gallery"?r.jsx("div",{className:"h-full overflow-y-auto",children:m==="grid"||!N?r.jsx(xf,{assets:e,onSelect:k,selectedId:p?.id}):r.jsx(Ro,{tree:c,onSelectFile:S,selectedUrl:p?.url})}):r.jsxs("div",{className:"relative w-full h-full",children:[r.jsx(Pf,{assetName:p?.name,onBack:T,children:r.jsx(f.Suspense,{fallback:r.jsx(Af,{}),children:E()})},p?.id),p&&o&&a&&r.jsx(Sf,{asset:p,hidden:i,onRegenerate:o,onRequestDelete:M=>w(M)}),n&&r.jsx("div",{className:"absolute inset-0 bg-background/90 flex items-center justify-center z-10 pointer-events-none",children:r.jsx(_t,{size:"md",text:Xt.t("assetViewer.hydratingGame",{ns:"studio",defaultValue:"Loading game files..."})})})]})})]}),r.jsx(_f,{isOpen:x!==null,onClose:()=>w(null),asset:x,onConfirm:M=>{a?.(M)}})]})}const wi=["ual1_Idle","ual2_Walk_Fwd","ual1_Jog_Fwd","ual1_Sprint","ual1_Jump","ual1_Roll","ual1_Interact","ual1_PickUp_Kneeling","ual1_Punch_Jab","ual1_Punch_Cross","ual1_Kick","ual2_Sword_Light_A","ual2_Sword_Heavy_A","ual2_Sword_Block","ual2_Sword_Light_Combo","ual2_Bow_Shoot","ual1_Pistol_Shoot","ual1_Hit_Chest","ual1_Hit_Head","ual2_Hit_Knockback","ual1_Death01","ual1_Celebration","ual1_Crouch_Idle","ual1_Crouch_Fwd"];new Set(wi);new Map(wi.map((e,t)=>[e,t]));f.forwardRef(function({icon:t,previewUrl:i},c){return i?r.jsx("div",{className:"relative w-[34%] max-w-[150px] shrink-0 self-stretch overflow-hidden bg-[#161616]",children:r.jsx(rl,{ref:c,src:i,muted:!0,loop:!0,playsInline:!0,preload:"metadata",className:"absolute inset-0 h-full w-full object-cover"})}):r.jsx("div",{className:"flex w-[34%] max-w-[150px] shrink-0 items-center justify-center self-stretch bg-gradient-to-br from-foreground
225/[0.08] to-foreground/[0.02]",children:r.jsx(H,{icon:["far",t],className:"text-xl text-muted-foreground/70"})})});function Uf(e,t){return e.id==="in-app-purchases"?t.canSellInGames:!0}const Ff=[{id:"cloud-saving",activation:"ai",name:"Cloud Saving",blurb:"Progress follows the player to any device they sign in on, instead of living in one browser.",icon:"cloud-arrow-up",highlights:["Picks up where they left off on their phone","Works offline and for players who are not signed in","The AI works out what is worth saving in your game"],enablePromptHint:"Work out what is worth saving yourself, rather than asking me to list it — save at moments that mean something, like clearing a level or reaching a checkpoint, and restore it before the first frame so the game never flashes a fresh state and then snaps to the loaded one. Keep it working with no connection and for players who are not signed in, and never make the game wait on a save. Just the saving, please."},{id:"in-app-purchases",activation:"ai",name:"In-App Purchases",blurb:"Sell things inside your game for coins players already hold on Tesana.",icon:"cart-shopping",highlights:["A shop players can open and buy from","Remembers what each player owns","You decide what to sell later, in chat"],enablePromptHint:"Add a shop the player can open, which lists whatever is currently for sale with its price, lets them buy with the coins they already have, remembers what they own so a one-time item is not sold twice, and offers a top-up when they are short. Do not invent things to sell — I will tell you what I want sold later. Always ask what something costs rather than writing a price into the game, never put a payment form on screen, and if a purchase fails or the player backs out, carry on without making it feel like an error. Just the buying, please."},{id:"vanity-address",activation:"manual",name:"Your Own Web Address",blurb:"Give the game a short, memorable link like sky-raiders.tesana.ai instead of a long build link.",icon:"link",highlights:["A name you can say out loud or put on a poster","Named after your game’s storefront link, so it reads like it","Works the moment it’s on, for every player"],onEnable:{action:"assign-address",label:"Give it an address",hint:"Named after your game"}},{id:"in-game-ads",activation:"ai",name:"Ads",blurb:"Show an ad at a natural break in the game, at moments you choose.",icon:"rectangle-ad",highlights:["Ads only where you place them, at a pause you pick","Off entirely for players who paid to remove them","Never blocks the game, a save, or a purchase"],enablePromptHint:"Let the game show an ad at a natural break — between levels, on a retry, at a pause — never in the middle of the action and never as something the player has to sit through to keep playing. Only offer one when the game has been told ads are on for this player, so a player who paid to remove them sees none, and keep the game playable whatever the answer: if no ad runs, or the service is unavailable, carry on without making it look like a failure. Do not draw the ad yourself and do not pay the player anything for watching one. Just the ad breaks, please."},{id:"leaderboards",activation:"ai",name:"Leaderboards",blurb:"Players compete on a high-score board that follows their account.",icon:"ranking-star",highlights:["A board for scores, times, or any run worth ranking","Follows the player between devices and phones","You decide what is ranked and which way it sorts"],enablePromptHint:"Give the game a leaderboard for a result it already produces — a score, a time, a streak. Decide the boards yourself from what the game actually measures, rank the number it is best to have on top, and make sure a lower number wins on anything that is a time. Show the board where the result appears, so a player sees where they stand right after they finish, and highlight their own row. Keep the game fully playable if the board cannot be reached, and do not pay the player coins or anything else for a score. Just the leaderboard, please."}
225,{id:"achievements",activation:"ai",name:"Achievements",blurb:"Badges for what a player accomplishes, kept on their Tesana account.",icon:"medal",highlights:["Badges for milestones, and progress toward them","The game says when a target is met, not the player","Follows the player between devices and phones"],enablePromptHint:"Add achievements a player can earn by actually playing. Pick a handful that are worth recognising rather than one per action, and where something can be counted, make it count toward a target so progress is tracked and the badge arrives when the target is met. Report progress when something settles — the end of a level or a run — not on every single event. Show them somewhere the player can look, with progress toward the ones still locked, and never interrupt play when one is earned. Do not give the player coins or items for a badge, and never unlock one they did not earn. Just the achievements, please."}],Lf="Keep everything web-safe, leave the game playable the whole way through, and rebuild it when you are done.";function Of(e){if(e.activation!=="ai")throw new Error(`Service "${e.id}" is set up on the platform and has no enable prompt; open its own screen instead of sending a message.`);return[`I’d like to add ${e.name.toLowerCase()} to my game.`,"",e.enablePromptHint,"",Lf].join(`
226`)}const Tt={claimed:!1,via:null};function Gf(e,t){if(!t?.readable)return!1;const i=nl.find(c=>c.serviceId===e);return i?t.matches.some(c=>i.probe.test(c.line)):!1}function If(e,t){const{game:i,roster:c,vanityAddress:s,source:n}=t;switch(e){case"in-app-purchases":return i?.has_shop===!0||Array.isArray(i?.shop_items)?{claimed:!0,via:"declaration"}:Tt;case"leaderboards":return c?.available===!0&&c.boards.length>0?{claimed:!0,via:"declaration"}:Tt;case"achievements":return c?.available===!0&&c.achievements.length>0?{claimed:!0,via:"declaration"}:Tt;case"vanity-address":return s?{claimed:!0,via:"platform"}:Tt;case"in-game-ads":return i?.ads_enabled===!0?{claimed:!0,via:"platform"}:Tt;case"cloud-saving":return Gf(e,n)?{claimed:!0,via:"source"}:Tt;default:return Tt}}function Bf(){const{t:e}=Ee("studio"),t=at(),{user:i}=Ut(),c=er(),[s,n]=f.useState(null),o=t.currentGame?.id,a=!t.currentGame,{data:l}=mt({queryKey:["vanity",String(o)],queryFn:()=>Yt.getVanity(o),enabled:!!o}),{data:d}=mt({queryKey:["game-roster",o],queryFn:()=>Yt.getRoster(o),enabled:!!o}),{data:u}=mt({queryKey:["game-service-source",o],queryFn:()=>Yt.getServiceSourceSignals(o),enabled:!!o,staleTime:5*6e4}),m=f.useMemo(()=>Ff.filter(w=>Uf(w,{canSellInGames:!!i?.can_sell_in_games})),[i?.can_sell_in_games]),h=f.useMemo(()=>{const w=new Map,v={game:t.currentGame,roster:d,vanityAddress:l?.address??null,source:u};for(const N of m)w.set(N.id,If(N.id,v));return w},[m,t.currentGame,d,l,u]),p=f.useCallback(async w=>{const v=t.currentGame;if(v){n(w.id);try{const y=(await Yt.assignVanity(v.id)).address??"";gr.success(y?e("library.services.addressReady","Your game is now at {{address}}",{address:y}):e("library.services.addressSet","Your address is ready")),c.invalidateQueries({queryKey:["vanity",String(v.id)]})}catch(N){ma(N,e("library.services.assignFailed","We could not set your address just now. Try again in a moment."))}finally{n(null)}}},[t.currentGame,e,c]),g=f.useCallback(async w=>{if(w.activation==="manual")switch(w.onEnable.action){case"assign-address":await p(w);return}n(w.id);try{const v=Of(w),N=await t.sendMessage(v,{source:"service-apply"});N==="queued"?gr.success(e("library.queued","Added to the build queue")):N!=="blocked"&&gr.success(e("library.applied","Sent to AI"))}finally{n(null)}},[t,e,p]),b=t.generationStatus?.status,x=f.useRef(!1);return f.useEffect(()=>{const w=t.isGenerating===!0;if(x.current&&!w&&o)for(const v of["game-service-source","game-roster","vanity","game"])c.invalidateQueries({queryKey:[v]});x.current=w},[b,t.isGenerating,o,c]),r.jsxs("div",{className:"flex h-full w-full flex-col bg-background",children:[r.jsx("div",{className:"shrink-0 border-b border-border px-4 py-3",children:r.jsx("span",{className:"text-sm text-foreground",children:e("library.services.title","Services")})}),r.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto",children:r.jsxs("div",{className:"space-y-6 p-6",children:[r.jsx("p",{className:"max-w-[70ch] text-[12px] leading-relaxed text-muted-foreground",children:e("library.services.intro","Capabilities Tesana runs for your game. Some the AI builds into the game you already have; others you set up here.")}),r.jsx("div",{className:"grid grid-cols-1 gap-3 2xl:grid-cols-2",children:m.map(w=>r.jsx(Vf,{service:w,disabled:a,disabledHint:a?e("library.services.requireGame","Generate a game first, then add this to it."):void 0,pending:s===w.id,added:h.get(w.id)?.claimed===!0,onEnable:()=>g(w)},w.id))})]})})]})}function Vf({service:e,disabled:t,disabledHint:i,pending:c,added:s,onEnable:n}){const{t:o}=Ee("studio");return r.jsxs("div",{className:"flex min-h-[150px] flex-col overflow-hidden rounded-xl bg-card ring-1 ring-transparent transition-all duration-100 hover:ring-border/60",children:[r.jsxs("div",{className:"flex items-start gap-3 p-4",children:[r.jsx("div",{className:"flex h-10 w-10 shrink-0 items-center justify-center rounded-lg bg-gradient-to-br from-foreground
226/[0.08] to-foreground/[0.02]",children:r.jsx(H,{icon:["far",e.icon],className:"text-base text-muted-foreground/70"})}),r.jsxs("div",{className:"min-w-0 flex-1",children:[r.jsx("p",{className:"truncate text-sm font-medium text-foreground",title:e.name,children:e.name}),r.jsx("p",{className:"mt-1 text-[12px] leading-snug text-muted-foreground",children:e.blurb})]})]}),r.jsx("ul",{className:"space-y-1.5 border-t border-border/60 px-4 py-3",children:e.highlights.map(a=>r.jsxs("li",{className:"flex items-start gap-2 text-[12px] text-muted-foreground",children:[r.jsx(H,{icon:["far","check"],className:"mt-[3px] shrink-0 text-[9px] text-muted-foreground/60"}),r.jsx("span",{className:"min-w-0",children:a})]},a))}),r.jsxs("div",{className:"mt-auto flex items-center gap-3 border-t border-border/60 px-4 py-3",children:[s?r.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1.5 text-[11px] text-muted-foreground/70",children:[r.jsx(H,{icon:["far","check"],className:"shrink-0 text-[9px]"}),o("library.services.added","Added")]}):null,!s&&!c&&e.activation==="manual"&&e.onEnable?r.jsx("span",{className:"min-w-0 text-[11px] text-muted-foreground/70",children:e.onEnable.hint}):null,!s&&t&&i?r.jsx("span",{className:"min-w-0 text-[11px] text-muted-foreground/70",children:i}):null,r.jsxs("button",{type:"button",disabled:t||c||s,onClick:n,title:s?o("library.services.alreadyAdded","This game already has it"):t?i:void 0,className:me("ml-auto inline-flex shrink-0 items-center gap-2 rounded-md px-3 py-1.5 text-[12px] font-medium transition-all","bg-foreground text-background hover:opacity-90","disabled:cursor-not-allowed disabled:opacity-40"),children:[c?r.jsx(H,{icon:["far","spinner"],className:"animate-spin text-[10px]"}):null,s?o("library.services.added","Added"):e.activation==="manual"?e.onEnable?.label??o("library.services.setUp","Set up"):o("library.services.enable","Add to game")]})]})]})}const qn=!1;function zf({path:e}){if(!e)return r.jsx("div",{className:"flex h-7 items-center bg-card px-3 text-[11px] text-muted-foreground",children:"No file open"});const t=e.split("/").filter(Boolean),i=Lt(e);return r.jsx("div",{className:"flex h-7 items-center gap-1 overflow-x-auto bg-card px-3 text-[11px] text-muted-foreground","aria-label":`Breadcrumbs: ${e}`,children:t.map((c,s)=>{const n=s===t.length-1;return r.jsxs("span",{className:"flex items-center gap-1",children:[s>0?r.jsx(H,{icon:["far","chevron-right"],className:"text-[8px] opacity-50"}):null,n?r.jsxs("span",{className:"flex items-center gap-1.5",children:[r.jsx(H,{icon:["far",i.icon],style:{color:i.color},className:"text-[10px]"}),r.jsx("span",{className:"font-mono font-medium text-foreground",children:c})]}):r.jsx("span",{className:"font-mono",children:c})]},`${s}-${c}`)})})}function Oo(e,t){(t==null||t>e.length)&&(t=e.length);for(var i=0,c=Array(t);i<t;i++)c[i]=e[i];return c}function Wf(e){if(Array.isArray(e))return e}function Hf(e,t,i){return(t=Jf(t))in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,e}function Kf(e,t){var i=e==null?null:typeof Symbol<"u"&&e[Symbol.iterator]||e["@@iterator"];if(i!=null){var c,s,n,o,a=[],l=!0,d=!1;try{if(n=(i=i.call(e)).next,t!==0)for(;!(l=(c=n.call(i)).done)&&(a.push(c.value),a.length!==t);l=!0);}catch(u){d=!0,s=u}finally{try{if(!l&&i.return!=null&&(o=i.return(),Object(o)!==o))return}finally{if(d)throw s}}return a}}function Yf(){throw new TypeError(`Invalid attempt to destructure non-iterable instance.
227In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function Go(e,t){var i=Object.keys(e);if(Object.getOwnPropertySymbols){var c=Object.getOwnPropertySymbols(e);t&&(c=c.filter(function(s){return Object.getOwnPropertyDescriptor(e,s).enumerable})),i.push.apply(i,c)}return i}function Io(e){for(var t=1;t<arguments.length;t++){var i=arguments[t]!=null?arguments[t]:{};t%2?Go(Object(i),!0).forEach(function(c){Hf(e,c,i[c])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(i)):Go(Object(i)).forEach(function(c){Object.defineProperty(e,c,Object.getOwnPropertyDescriptor(i,c))})}return e}function Xf(e,t){if(e==null)return{};var i,c,s=$f(e,t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);for(c=0;c<n.length;c++)i=n[c],t.indexOf(i)===-1&&{}.propertyIsEnumerable.call(e,i)&&(s[i]=e[i])}return s}function $f(e,t){if(e==null)return{};var i={};for(var c in e)if({}.hasOwnProperty.call(e,c)){if(t.indexOf(c)!==-1)continue;i[c]=e[c]}return i}function qf(e,t){return Wf(e)||Kf(e,t)||Zf(e,t)||Yf()}function Qf(e,t){if(typeof e!="object"||!e)return e;var i=e[Symbol.toPrimitive];if(i!==void 0){var c=i.call(e,t);if(typeof c!="object")return c;throw new TypeError("@@toPrimitive must return a primitive value.")}return(t==="string"?String:Number)(e)}function Jf(e){var t=Qf(e,"string");return typeof t=="symbol"?t:t+""}function Zf(e,t){if(e){if(typeof e=="string")return Oo(e,t);var i={}.toString.call(e).slice(8,-1);return i==="Object"&&e.constructor&&(i=e.constructor.name),i==="Map"||i==="Set"?Array.from(e):i==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(i)?Oo(e,t):void 0}}function em(e,t,i){return t in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,e}function Bo(e,t){var i=Object.keys(e);if(Object.getOwnPropertySymbols){var c=Object.getOwnPropertySymbols(e);t&&(c=c.filter(function(s){return Object.getOwnPropertyDescriptor(e,s).enumerable})),i.push.apply(i,c)}return i}function Vo(e){for(var t=1;t<arguments.length;t++){var i=arguments[t]!=null?arguments[t]:{};
vendor: 2,463 bytes, line 227
227t%2?Bo(Object(i),!0).forEach(function(c){em(e,c,i[c])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(i)):Bo(Object(i)).forEach(function(c){Object.defineProperty(e,c,Object.getOwnPropertyDescriptor(i,c))})}return e}function tm(){for(var e=arguments.length,t=new Array(e),i=0;i<e;i++)t[i]=arguments[i];return function(c){return t.reduceRight(function(s,n){return n(s)},c)}}function pr(e){return function t(){for(var i=this,c=arguments.length,s=new Array(c),n=0;n<c;n++)s[n]=arguments[n];return s.length>=e.length?e.apply(this,s):function(){for(var o=arguments.length,a=new Array(o),l=0;l<o;l++)a[l]=arguments[l];return t.apply(i,[].concat(s,a))}}}function un(e){return{}.toString.call(e).includes("Object")}function rm(e){return!Object.keys(e).length}function Nr(e){return typeof e=="function"}function nm(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function sm(e,t){return un(t)||St("changeType"),Object.keys(t).some(function(i){return!nm(e,i)})&&St("changeField"),t}function om(e){Nr(e)||St("selectorType")}function am(e){Nr(e)||un(e)||St("handlerType"),un(e)&&Object.values(e).some(function(t){return!Nr(t)})&&St("handlersType")}function im(e){e||St("initialIsRequired"),un(e)||St("initialType"),rm(e)&&St("initialContent")}function lm(e,t){throw new Error(e[t]||e.default)}var cm={initialIsRequired:"initial state is required",initialType:"initial state should be an object",initialContent:"initial state shouldn't be an empty object",handlerType:"handler should be an object or a function",handlersType:"all handlers should be a functions",selectorType:"selector should be a function",changeType:"provided value of changes should be an object",changeField:'it seams you want to change a field in the state which is not specified in the "initial" state',default:"an unknown error accured in `state-local` package"},St=pr(lm)(cm),Yr={changes:sm,selector:om,handler:am,initial:im};function dm(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};Yr.initial(e),Yr.handler(t);var i={current:e},c=pr(mm)(i,t),s=pr(fm)(i),n=pr(Yr.changes)(e),o=pr(um)(i);function a(){var d=arguments.length>0&&arguments[0]!==void 0?arguments[0]:function(u){return u};return Yr.selector(d),d(i.current)}function l(d){tm(c,s,n,o)(d)}return[a,l]}function um(e,t){return Nr(t)?t(e.current):t}function fm(e,t){return e.current=Vo(Vo({},e.current),t),t}function mm(e,t,i){return Nr(t)?t(e.current):Object.keys(i).forEac
227h(function(c){var s;return(s=t[c])===null||s===void 0?void 0:s.call(t,e.current[c])}),i}var hm={create:dm},pm={paths:{vs:"https://cdn.jsdelivr.net/npm/[email protected]/min/vs"}};function gm(e){return function t(){for(var i=this,c=arguments.length,s=new Array(c),n=0;n<c;n++)s[n]=arguments[n];return s.length>=e.length?e.apply(this,s):function(){for(var o=arguments.length,a=new Array(o),l=0;l<o;l++)a[l]=arguments[l];return t.apply(i,[].concat(s,a))}}}function xm(e){return{}.toString.call(e).includes("Object")}function bm(e){return e||zo("configIsRequired"),xm(e)||zo("configType"),e.urls?(vm(),{paths:{vs:e.urls.monacoBase}}):e}function vm(){console.warn(ji.deprecation)}function ym(e,t){throw new Error(e[t]||e.default)}var ji={configIsRequired:"the configuration object is required",configType:"the configuration object should be an object",default:"an unknown error accured in `@monaco-editor/loader` package",deprecation:`Deprecation warning!
228    You are using deprecated way of configuration.
229
230    Instead of using
231      monaco.config({ urls: { monacoBase: '...' } })
232    use
233      monaco.config({ paths: { vs: '...' } })
234
235    For more please check the link https://github.com/suren-atoyan/monaco-loader#config
236  `},zo=gm(ym)(ji),wm={config:bm},jm=function(){for(var t=arguments.length,i=new Array(t),c=0;c<t;c++)i[c]=arguments[c];return function(s){return i.reduceRight(function(n,o){return o(n)},s)}};function ki(e,t){return Object.keys(t).forEach(function(i){t[i]instanceof Object&&e[i]&&Object.assign(t[i],ki(e[i],t[i]))}),Io(Io({},e),t)}var km={type:"cancelation",msg:"operation is manually canceled"};function Qn(e){var t=!1,i=new Promise(function(c,s){e.then(function(n){return t?s(km):c(n)}),e.catch(s)});return i.cancel=function(){return t=!0},i}var Nm=["monaco"],Sm=hm.create({config:pm,isInitialized:!1,resolve:null,reject:null,monaco:null}),Ni=qf(Sm,2),Cr=Ni[0],gn=Ni[1];function _m(e){var t=wm.config(e),i=t.monaco,c=Xf(t,Nm);gn(function(s){return{config:ki(s.config,c),monaco:i}})}function Cm(){var e=Cr(function(t){var i=t.monaco,c=t.isInitialized,s=t.resolve;return{monaco:i,isInitialized:c,resolve:s}});if(!e.isInitialized){if(gn({isInitialized:!0}),e.monaco)return e.resolve(e.monaco),Qn(Jn);if(window.monaco&&window.monaco.editor)return Si(window.monaco),e.resolve(window.monaco),Qn(Jn);jm(Em,Mm)(Am)}return Qn(Jn)}function Em(e){return document.body.appendChild(e)}function Tm(e){var t=document.createElement("script");return e&&(t.src=e),t}function Mm(e){var t=Cr(function(c){var s=c.config,n=c.reject;return{config:s,reject:n}}),i=Tm("".concat(t.config.paths.vs,"/loader.js"));return i.onload=function(){return e()},i.onerror=t.reject,i}function Am(){var e=Cr(function(i){var c=i.config,s=i.resolve,n=i.reject;return{config:c,resolve:s,reject:n}}),t=window.require;t.config(e.config),t(["vs/editor/editor.main"],function(i){var c=i.m||i;Si(c),e.resolve(c)},function(i){e.reject(i)})}function Si(e){Cr().monaco||gn({monaco:e})}function Pm(){return Cr(function(e){var t=e.monaco;return t})}var Jn=new Promise(function(e,t){return gn({resolve:e,reject:t})}),_i={config:_m,init:Cm,__getMonacoInstance:Pm},Dm={wrapper:{display:"flex",position:"relative",textAlign:"initial"},fullWidth:{width:"100%"},hide:{display:"none"}},Zn=Dm,Rm={container:{display:"flex",height:"100%",width:"100%",justifyContent:"center",alignItems:"center"}},Um=Rm;function Fm({children:e}){return qt.createElement("div",{style:Um.container},e)}var Lm=Fm,Om=Lm;function Gm({width:e,height:t,isEditorReady:i,loading:c,_ref:s,className:n,wrapperProps:o}){return qt.createElement("section",{style:{...Zn.wrapper,width:e,height:t},...o},!i&&qt.createElement(Om,null,c),qt.createElement("div",{ref:s,style:{...Zn.fullWidth,...!i&&Zn.hide},className:n}))}var Im=Gm,Ci=f.memo(Im);function Bm(e){f.useEffect(e,[])}var Ei=Bm;function Vm(e,t,i=!0){let c=f.useRef(!0);f.useEffect(c.current||!i?()=>{c.current=!1}:e,t)}var ot=Vm;function vr(){}function $t(e,t,i,c){return zm(e,c)||Wm(e,t,i,c)}function zm(e,t){return e.editor.getModel(Ti(e,t))}function Wm(e,t,i,c){return e.editor.createModel(t,i,c?Ti(e,c):void 0)}function Ti(e,t){return e.Uri.parse(t)}function Hm({original:e,modified:t,language:i,originalLanguage:c,modifiedLanguage:s,originalModelPath:n,modifiedModelPath:o,keepCurrentOriginalModel:a=!1,keepCurrentModifiedModel:l=!1,theme:d="light",loading:u="Loading...",options:m={},height:h="100%",width:p="100%",className:g,wrapperProps:b={},beforeMount:x=vr,onMount:w=vr}){let[v,N]=f.useState(!1),[y,k]=f.useState(!0),S=f.useRef(null),T=f.useRef(null),E=f.useRef(null),A=f.useRef(w),M=f.useRef(x),R=f.useRef(!1);Ei(()=>{let P=_i.init();return P.then(U=>(T.current=U)&&k(!1)).catch(U=>U?.type!=="cancelation"&&console.error("Monaco initialization: error:",U)),()=>S.current?C():P.cancel()}),ot(()=>{if(S.current&&T.current){let P=S.current.getOriginalEditor(),U=$t(T.current,e||"",c||i||"text",n||"");U!==P.getModel()&&P.setModel(U)}},[n],v),ot(()=>{if(S.current&&T.current){let P=S.current.getModifiedEditor(),U=$t(T.current,t||"",s||i||"text",o||"");U!==P.getModel()&&P.setModel(U)}},[o],v),ot(()=>{let P=S.current.getModifiedEditor();P.getOption(T.current.editor.EditorOption.readOnly)?P.setValue(t||""):t!==P.getValue()&&(P.executeEdits("",[{range:P.getModel().getFullModelRange(),text:t||"",forceMoveMarkers:!0}]),P.pushUndoStop())},[t],v),ot(()=>{S.current?.getModel()?.original.setValue(e||"")},[e],v),ot(()=>{let{original:P,modified:U}=S.current.getModel();T.current.editor.setModelLanguage(P,c||i||"text"),T.current.editor.setModelLanguage(U,s||i||"text")},[i,c,s],v),ot(()=>{T.current?.editor.setTheme(d)},[d],v),ot(()=>{S.current?.updateOptions(m)},[m],v);let _=f.useCallback(()=>
236{if(!T.current)return;M.current(T.current);let P=$t(T.current,e||"",c||i||"text",n||""),U=$t(T.current,t||"",s||i||"text",o||"");S.current?.setModel({original:P,modified:U})},[i,t,s,e,c,n,o]),F=f.useCallback(()=>{!R.current&&E.current&&(S.current=T.current.editor.createDiffEditor(E.current,{automaticLayout:!0,...m}),_(),T.current?.editor.setTheme(d),N(!0),R.current=!0)},[m,d,_]);f.useEffect(()=>{v&&A.current(S.current,T.current)},[v]),f.useEffect(()=>{!y&&!v&&F()},[y,v,F]);function C(){let P=S.current?.getModel();a||P?.original?.dispose(),l||P?.modified?.dispose(),S.current?.dispose()}return qt.createElement(Ci,{width:p,height:h,isEditorReady:v,loading:u,_ref:E,className:g,wrapperProps:b})}var Km=Hm,Mi=f.memo(Km);function Ym(e){let t=f.useRef();return f.useEffect(()=>{t.current=e},[e]),t.current}var Xm=Ym,Xr=new Map;function $m({defaultValue:e,defaultLanguage:t,defaultPath:i,value:c,language:s,path:n,theme:o="light",line:a,loading:l="Loading...",options:d={},overrideServices:u={},saveViewState:m=!0,keepCurrentModel:h=!1,width:p="100%",height:g="100%",className:b,wrapperProps:x={},beforeMount:w=vr,onMount:v=vr,onChange:N,onValidate:y=vr}){let[k,S]=f.useState(!1),[T,E]=f.useState(!0),A=f.useRef(null),M=f.useRef(null),R=f.useRef(null),_=f.useRef(v),F=f.useRef(w),C=f.useRef(),P=f.useRef(c),U=Xm(n),K=f.useRef(!1),z=f.useRef(!1);Ei(()=>{let j=_i.init();return j.then(D=>(A.current=D)&&E(!1)).catch(D=>D?.type!=="cancelation"&&console.error("Monaco initialization: error:",D)),()=>M.current?L():j.cancel()}),ot(()=>{let j=$t(A.current,e||c||"",t||s||"",n||i||"");j!==M.current?.getModel()&&(m&&Xr.set(U,M.current?.saveViewState()),M.current?.setModel(j),m&&M.current?.restoreViewState(Xr.get(n)))},[n],k),ot(()=>{M.current?.updateOptions(d)},[d],k),ot(()=>{!M.current||c===void 0||(M.current.getOption(A.current.editor.EditorOption.readOnly)?M.current.setValue(c):c!==M.current.getValue()&&(z.current=!0,M.current.executeEdits("",[{range:M.current.getModel().getFullModelRange(),text:c,forceMoveMarkers:!0}]),M.current.pushUndoStop(),z.current=!1))},[c],k),ot(()=>{let j=M.current?.getModel();j&&s&&A.current?.editor.setModelLanguage(j,s)},[s],k),ot(()=>{a!==void 0&&M.current?.revealLine(a)},[a],k),ot(()=>{A.current?.editor.setTheme(o)},[o],k);let O=f.useCallback(()=>{if(!(!R.current||!A.current)&&!K.current){F.current(A.current);let j=n||i,D=$t(A.current,c||e||"",t||s||"",j||"");M.current=A.current?.editor.create(R.current,{model:D,automaticLayout:!0,...d},u),m&&M.current.restoreViewState(Xr.get(j)),A.current.editor.setTheme(o),a!==void 0&&M.current.revealLine(a),S(!0),K.current=!0}},[e,t,i,c,s,n,d,u,m,o,a]);f.useEffect(()=>{k&&_.current(M.current,A.current)},[k]),f.useEffect(()=>{!T&&!k&&O()},[T,k,O]),P.current=c,f.useEffect(()=>{k&&N&&(C.current?.dispose(),C.current=M.current?.onDidChangeModelContent(j=>{z.current||N(M.current.getValue(),j)}))},[k,N]),f.useEffect(()=>{if(k){let j=A.current.editor.onDidChangeMarkers(D=>{let I=M.current.getModel()?.uri;if(I&&D.find(B=>B.path===I.path)){let B=A.current.editor.getModelMarkers({resource:I});y?.(B)}});return()=>{j?.dispose()}}return()=>{}},[k,y]);function L(){C.current?.dispose(),h?m&&Xr.set(n,M.current.saveViewState()):M.current.getModel()?.dispose(),M.current.dispose()}return qt.createElement(Ci,{width:p,height:g,isEditorReady:k,loading:l,_ref:R,className:b,wrapperProps:x})}var qm=$m,Qm=f.memo(qm),Gx=Qm;const rn="gdscript",Jm={comments:{lineComment:"#"},brackets:[["{","}"],["[","]"],["(",")"]],autoClosingPairs:[{open:"{",close:"}"},{open:"[",close:"]"},{open:"(",close:")"},{open:'"',close:'"',notIn:["string"]},{open:"'",close:"'",notIn:["string","comment"]}],surroundingPairs:[{open:"{",close:"}"},{open:"[",close:"]"},{open:"(",close:")"},{open:'"',close:'"'},{open:"'",close:"'"}],indentationRules:{increaseIndentPattern:/^\s*(class|func|if|elif|else|while|for|match|enum)\b.*:\s*$/,decreaseIndentPattern:/^\s*(return|break|continue|pass)\b/}},Zm={defaultToken:"",tokenPostfix:".gd",keywords:["and","as","assert","await","break","breakpoint","class","class_name","const","continue","elif","else","enum","export","extends","false","for","func","if","in","is","master","mastersync","match","not","null","or","pass","preload","puppet","puppetsync","remote","remotesync","return","self","setget","signal","static","super","tool","true","var","void","while","yield"],builtinFunctions:["abs","acos","asin","atan","atan2","ceil","clamp","cos","deg_to_rad","exp","floor","fmod","fposmod","lerp","lerp_angle","linear_to_db","log","max","min","pingpong","pow","print","print_rich","printerr","printraw","prints","printt","rad_to_deg","randf","randf_range","randi","randi_range","randomize","range","remap","round","seed","sign","sin","smoothstep","snapped","sqrt","str","tan","typeof","wrapf","wrapi"],builtinTypes:["AnimatedSprite2D","AnimatedSprite3D","AnimationPlayer","AnimationTree","Area2D","Area3D","Camera2D","Camera3D","CanvasLayer","CharacterBody2D","CharacterBody3D","CollisionShape2D","CollisionShape3D","Color","Control","DirectionalLight3D","GPUParticles3D","Input","InputEvent","Label","Line2D","MeshInstance3D","Node","Node2D","Node3D","Object","OmniLight3D","PackedScene","Path3D","PathFollow3D","Polygon2D","RandomNumberGenerator","RayCast3D","Rect2","RemoteTransform3D","RigidBody2D","RigidBody3D","Sky","Skeleton3D","Sprite2D","Sprite3D","StaticBody2D","StaticBody3D","Texture","Tween","Vector2","Vector3","Viewport","WorldEnvironment"],operators:["=",">","<","!","~","?",":","==","<=",">=","!=","&&","||","++","--","+","-","*","/","&","|","^","%","<<",">>",">>>","+=","-=","*=","/=","&=","|=","^=","%=","<<=",">>=",">>>="],symbols:/[=><!~?:&|+\-*/^%]+/,escapes:/\\(?:[abfnrtv\\"'?]|x[0-9A-Fa-f]{1,4}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})/,tokenizer:{root:[[/@[a-zA-Z_]\w*/,"annotation"],[/[a-zA-Z_]\w*/,{cases:{"@keywords":"keyword","@builtinTypes":"type","@builtinFunctions":"predefined","@default":"identifier"}}],{include:"@whitespace"},[/0[xX][0-9a-fA-F]+/,"number.hex"],[/\d+\.\d+([eE][\-+]?\d+)?/,"number.float"],[/\d+/,"number"],[/[;
236,.]/,"delimiter"],[/"([^"\\]|\\.)*$/,"string.invalid"],[/"/,"string","@string_double"],[/'([^'\\]|\\.)*$/,"string.invalid"],[/'/,"string","@string_single"],[/@symbols/,{cases:{"@operators":"operator","@default":""}}]],string_double:[[/[^\\"]+/,"string"],[/@escapes/,"string.escape"],[/\\./,"string.escape.invalid"],[/"/,"string","@pop"]],string_single:[[/[^\\']+/,"string"],[/@escapes/,"string.escape"],[/\\./,"string.escape.invalid"],[/'/,"string","@pop"]],whitespace:[[/[ \t\r\n]+/,"white"],[/#.*$/,"comment"]]}};let Wo=!1;function eh(e){Wo||(Wo=!0,e.languages.register({id:rn,extensions:[".gd"],aliases:["GDScript","gdscript"],mimetypes:["text/x-gdscript"]}),e.languages.setLanguageConfiguration(rn,Jm),e.languages.setMonarchTokensProvider(rn,Zm))}function Ss(e){switch(e.toLowerCase().split(".").pop()??""){case"gd":return rn;case"gdshader":case"gdshaderinc":return"cpp";case"tscn":case"tres":case"godot":case"cfg":case"ini":return"ini";case"json":return"json";case"md":return"markdown";case"py":return"python";case"js":case"jsx":return"javascript";case"ts":case"tsx":return"typescript";case"html":case"htm":return"html";case"css":return"css";case"yml":case"yaml":return"yaml";case"toml":return"toml";default:return"plaintext"}}function th({gameId:e,path:t}){const{buffers:i,acceptServer:c,acceptLocal:s,dismissConflict:n}=wt(),{theme:o}=Rt(),[a,l]=f.useState(null),[d,u]=f.useState(null),m=i[t],h=Ss(t);return f.useEffect(()=>{let p=!1;return u(null),l(null),sl.readFile(e,t).then(g=>{if(!p){if(g.binary){u("Binary file conflicts cannot be merged in the editor.");return}l(g.lines.join(`
237`))}}).catch(g=>{if(p)return;const b=g instanceof Error?g.message:String(g);u(b)}),()=>{p=!0}},[e,t]),r.jsx("div",{className:"fixed inset-0 z-[100] flex items-center justify-center bg-black/60 p-4",children:r.jsxs("div",{className:"flex h-[80vh] w-[min(1200px,95vw)] flex-col overflow-hidden rounded-lg border border-border bg-card shadow-xl",children:[r.jsxs("header",{className:"flex items-center justify-between border-b border-border px-4 py-3",children:[r.jsxs("div",{children:[r.jsxs("h2",{className:"text-sm font-medium text-foreground",children:["Conflict on ",r.jsx("span",{className:"font-mono",children:t})]}),r.jsx("p",{className:"mt-0.5 text-xs text-muted-foreground",children:"The AI edited this file while you had unsaved changes. Pick one to keep."})]}),r.jsx("button",{type:"button",onClick:()=>n(t),className:"rounded px-2 py-1 text-xs text-muted-foreground hover:bg-foreground
237/5 hover:text-foreground",children:"Decide later"})]}),r.jsx("div",{className:"flex-1 overflow-hidden",children:d?r.jsx("div",{className:"flex h-full items-center justify-center px-6 text-center text-sm text-rose-400",children:d}):!m||a===null?r.jsx("div",{className:"flex h-full items-center justify-center text-sm text-muted-foreground",children:"Loading both versions…"}):r.jsx(Mi,{original:m.content,modified:a,originalLanguage:h,modifiedLanguage:h,theme:o==="dark"?"vs-dark":"vs",options:{readOnly:!0,renderSideBySide:!0,originalEditable:!1,minimap:{enabled:!1},fontSize:12,fontFamily:'"JetBrains Mono", "Fira Code", "SF Mono", Menlo, monospace'}})}),r.jsxs("footer",{className:"flex items-center justify-between border-t border-border px-4 py-3",children:[r.jsxs("div",{className:"text-xs text-muted-foreground",children:[r.jsxs("span",{className:"mr-3",children:[r.jsx("span",{className:"mr-1 inline-block h-2 w-2 rounded-full bg-amber-400"})," Your version"]}),r.jsxs("span",{children:[r.jsx("span",{className:"mr-1 inline-block h-2 w-2 rounded-full bg-accent"})," AI version"]})]}),r.jsxs("div",{className:"flex gap-2",children:[r.jsx("button",{type:"button",onClick:()=>c(t),className:"rounded border border-border bg-transparent px-3 py-1.5 text-xs text-foreground hover:bg-foreground
237/5",children:"Keep AI's version"}),r.jsx("button",{type:"button",onClick:()=>s(t),className:"rounded bg-accent px-3 py-1.5 text-xs font-medium text-accent-foreground hover:opacity-90",children:"Keep mine (force save)"})]})]})]})})}const rh=220,nh=12,Kt=8;function Ho({open:e,position:t,items:i,onClose:c,ariaLabel:s}){const n=f.useRef(null),o=f.useMemo(()=>{const p=[];return i.forEach((g,b)=>{g.kind==="item"&&!g.disabled&&p.push(b)}),p},[i]),[a,l]=f.useState(-1),[d,u]=f.useState(null);f.useLayoutEffect(()=>{if(!e||!n.current)return;const p=n.current.getBoundingClientRect(),g=window.innerWidth,b=window.innerHeight;let x=t.x,w=t.y;x+p.width+Kt>g&&(x=Math.max(Kt,g-p.width-Kt)),w+p.height+Kt>b&&(w=Math.max(Kt,b-p.height-Kt)),u({x,y:w})},[e,t.x,t.y,i.length]),f.useEffect(()=>{if(!e)return;const p=performance.now(),g=()=>performance.now()-p>50,b=w=>{g()&&n.current&&(n.current.contains(w.target)||c())},x=w=>{if(w.key==="Escape"){w.preventDefault(),c();return}if(w.key==="ArrowDown"){if(w.preventDefault(),o.length===0)return;l(v=>{const N=o.indexOf(v),y=N<0?0:(N+1)%o.length;return o[y]});return}if(w.key==="ArrowUp"){if(w.preventDefault(),o.length===0)return;l(v=>{const N=o.indexOf(v),y=N<=0?o.length-1:N-1;return o[y]});return}if(w.key==="Enter"||w.key===" "){if(a<0)return;const v=i[a];v&&v.kind==="item"&&!v.disabled&&(w.preventDefault(),v.onSelect(),c())}};return window.addEventListener("mousedown",b),window.addEventListener("contextmenu",b),window.addEventListener("keydown",x),()=>{window.removeEventListener("mousedown",b),window.removeEventListener("contextmenu",b),window.removeEventListener("keydown",x)}},[e,c,a,o,i]);const m=f.useCallback(p=>{p.kind!=="item"||p.disabled||(p.onSelect(),c())},[c]),h=d?{left:d.x,top:d.y}:{left:t.x,top:t.y,visibility:"hidden"};return xa.createPortal(r.jsx(lt,{onExitComplete:()=>{l(-1),u(null)},children:e?r.jsx(Be.div,{ref:n,role:"menu","aria-label":s??"Context menu",initial:{opacity:0,scale:.96,y:-2},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.96,y:-2},transition:{duration:.12,ease:[.16,1,.3,1]},className:"fixed z-[100] flex flex-col rounded-md border border-border bg-card py-1.5 shadow-2xl shadow-black/40",style:{minWidth:rh,padding:`${nh/2}px 0`,...h},onContextMenu:p=>p.preventDefault(),children:i.map((p,g)=>{if(p.kind==="divider")return r.jsx("div",{role:"separator",className:"my-1.5 h-px bg-border"},`divider-${g}`);const b=g===a,x=p.disabled?"text-muted-foreground/40 cursor-not-allowed":p.danger?"text-red-400 hover:bg-red-500/10":"text-foreground hover:bg-foreground
237/8";return r.jsxs("button",{type:"button",role:"menuitem",disabled:p.disabled,onMouseEnter:()=>!p.disabled&&l(g),onClick:()=>m(p),className:`mx-1.5 rounded-sm flex items-center justify-between gap-3 px-3 py-1.5 text-left text-[13px] transition-colors outline-none ${x} ${b&&!p.disabled?p.danger?"bg-red-500/10":"bg-foreground/8":""}`,children:[r.jsxs("span",{className:"flex min-w-0 items-center gap-2.5",children:[p.icon?r.jsx(H,{icon:p.icon,className:"w-3.5 shrink-0 text-[12px] opacity-80"}):r.jsx("span",{className:"w-3.5 shrink-0"}),r.jsx("span",{className:"truncate",children:p.label})]}),p.shortcut?r.jsx("span",{className:"ml-3 shrink-0 text-[11px] text-muted-foreground",children:p.shortcut}):null]},p.id)})},"context-menu"):null}),document.body)}function Ko(){const[e,t]=f.useState(!1),[i,c]=f.useState({x:0,y:0}),s=f.useCallback((o,a)=>{c({x:o,y:a}),t(!0)},[]),n=f.useCallback(()=>t(!1),[]);return{open:e,position:i,openAt:s,close:n}}function sh({isOpen:e,onClose:t,path:i}){const{deleteFile:c}=wt(),[s,n]=f.useState(!1),[o,a]=f.useState(null),l=async()=>{if(i){n(!0),a(null);try{if(!await c(i)){a("The file couldn't be deleted on the server.");return}t()}catch(m){a(m instanceof Error?m.message:String(m))}finally{n(!1)}}},d=i?.split("/").pop()??"",u=i?.split("/").slice(0,-1).join("/")??"";return r.jsx(lt,{onExitComplete:()=>{a(null)},children:e&&i&&r.jsxs(r.Fragment,{children:[r.jsx(Be.div,{initial:{opacity:0}
237,animate:{opacity:1},exit:{opacity:0},className:"fixed inset-0 bg-black/80 z-50",onClick:t}),r.jsx(Be.div,{initial:{opacity:0,scale:.95,y:20},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.95,y:20},transition:{duration:.2,ease:[.16,1,.3,1]},className:"fixed inset-0 z-50 flex items-center justify-center p-4 pointer-events-none",children:r.jsxs("div",{className:"relative bg-card rounded-lg border border-border p-4 pt-10 md:p-8 md:pt-8 max-w-md w-full pointer-events-auto",onClick:m=>m.stopPropagation(),children:[r.jsx("button",{onClick:t,disabled:s,className:"absolute top-2 right-2 md:top-4 md:right-4 w-9 h-9 flex items-center justify-center rounded-md transition-colors cursor-pointer hover:bg-foreground/4 text-muted-foreground hover:text-foreground disabled:opacity-30","aria-label":"Close",children:r.jsx(H,{icon:["far","xmark"]})}),r.jsx("h3",{className:"text-lg text-foreground mb-4",children:"Delete file"}),r.jsxs("p",{className:"text-base text-muted-foreground mb-6",children:["Are you sure you want to delete"," ",r.jsxs("strong",{className:"text-foreground",children:['"',d,'"']}),u?r.jsxs(r.Fragment,{children:[" from ",r.jsx("span",{className:"font-mono text-foreground",children:u})]}):null,"? This is"," ",r.jsx("span",{className:"text-red-400",children:"permanent"})," — the file is removed from both the cloud copy and your local mirror, and the AI won't see it on the next generation."]}),o?r.jsx("div",{className:"p-3 bg-red-500/8 border border-red-500/20 rounded-md text-red-400 text-sm mb-6",children:o}):null,r.jsxs("div",{className:"flex gap-3 items-center justify-start",children:[r.jsx("button",{onClick:t,disabled:s,className:"h-9 px-3 bg-foreground
237/6 text-foreground text-sm rounded-md hover:bg-foreground/10 transition-colors cursor-pointer disabled:opacity-30",children:"Cancel"}),r.jsx("button",{onClick:l,disabled:s,className:"h-9 px-3 bg-red-500/8 text-red-400 text-sm rounded-md hover:bg-red-500/12 transition-all disabled:opacity-60 cursor-pointer",children:s?"Deleting…":"Delete file"})]})]})})]})})}const oh=[12,13,14,16];function ah({open:e,anchor:t,settings:i,onChange:c,onClose:s,triggerRef:n}){const o=f.useRef(null);f.useEffect(()=>{if(!e)return;const d=m=>{const h=m.target;o.current&&o.current.contains(h)||n?.current&&n.current.contains(h)||s()},u=m=>{m.key==="Escape"&&s()};return window.addEventListener("mousedown",d),window.addEventListener("keydown",u),()=>{window.removeEventListener("mousedown",d),window.removeEventListener("keydown",u)}},[e,s,n]);const a=t?Math.max(8,window.innerWidth-t.right):-9999,l=t?t.bottom+4:-9999;return r.jsx(lt,{children:e&&t?r.jsxs(Be.div,{ref:o,role:"dialog","aria-label":"Editor settings",initial:{opacity:0,scale:.96,y:-2},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.96,y:-2},transition:{duration:.12,ease:[.16,1,.3,1]},className:"fixed z-[100] w-64 rounded-md border border-border bg-card p-3 text-[13px] shadow-2xl shadow-black/40",style:{right:a,top:l},children:[r.jsxs("div",{className:"flex items-center justify-between mb-3",children:[r.jsx("h3",{className:"text-foreground text-[13px] font-medium",children:"Editor settings"}),r.jsx("button",{type:"button",onClick:s,className:"text-muted-foreground hover:text-foreground","aria-label":"Close settings",children:r.jsx(H,{icon:["far","xmark"]})})]}),r.jsx(Yo,{label:"AI completions",description:"Inline ghost-text suggestions powered by Claude Haiku.",checked:i.monacopilotEnabled,onChange:d=>c({monacopilotEnabled:d})}),r.jsx(Yo,{label:"Word wrap",description:"Soft-wrap long lines instead of horizontal scroll.",checked:i.wordWrap,onChange:d=>c({wordWrap:d})}),r.jsxs("div",{className:"mt-3",children:[r.jsx("div",{className:"text-foreground text-[13px] mb-1",children:"Font size"}),r.jsx("div",{className:"flex gap-1.5",children:oh.map(d=>r.jsx("button",{type:"button",onClick:()=>c({fontSize:d}),className:`flex-1 rounded h-7 text-[12px] border transition-colors ${i.fontSize===d?"bg-accent/15 border-accent text-foreground":"bg-transparent border-border text-muted-foreground hover:bg-foreground
237/5 hover:text-foreground"}`,children:d},d))})]})]},"editor-settings-popover"):null})}function Yo({label:e,description:t,checked:i,onChange:c}){return r.jsxs("label",{className:"flex items-start justify-between gap-3 py-1.5 cursor-pointer select-none",children:[r.jsxs("span",{className:"flex flex-col min-w-0",children:[r.jsx("span",{className:"text-foreground text-[13px]",children:e}),t?r.jsx("span",{className:"text-muted-foreground text-[11px]",children:t}):null]}),r.jsx("span",{className:`mt-0.5 relative inline-flex h-4 w-7 shrink-0 items-center rounded-full transition-colors ${i?"bg-accent":"bg-foreground/15"}`,role:"switch","aria-checked":i,children:r.jsx("span",{className:`inline-block h-3 w-3 rounded-full bg-background transition-transform ${i?"translate-x-3.5":"translate-x-0.5"}`})}),r.jsx("input",{type:"checkbox",className:"sr-only",checked:i,onChange:s=>c(s.target.checked)})]})}function ih({openPaths:e,activePath:t,dirtyPaths:i,onSelect:c,onClose:s,onReorder:n,onContextMenu:o}){const a=Ca(Ea(Ta,{activationConstraint:{distance:5}})),l=f.useMemo(()=>e,[e]);if(e.length===0)return r.jsx("div",{className:"flex h-9 items-center border-b border-border bg-background px-3 text-xs text-muted-foreground",children:"No file open. Pick one from the tree on the left."});const d=u=>{const{active:m,over:h}=u;if(!h||m.id===h.id)return;const p=e.indexOf(String(m.id)),g=e.indexOf(String(h.id));p<0||g<0||n(Wl(e,p,g))};return r.jsx(Ma,{sensors:a,collisionDetection:Bl,onDragEnd:d,children:r.jsx(Vl,{items:l,strategy:zl,children:r.jsxs("div",{className:"flex h-9 items-center overflow-x-auto bg-background text-[12px]",children:[e.map(u=>r.jsx(lh,{path:u,active:u===t,dirty:i.has(u),onSelect:c,onClose:s,onContextMenu:o},u)),r.jsx("div",{className:"flex-1 self-stretch border-b border-border"})]})})})}function lh({path:e,active:t,dirty:i,onSelect:c,onClose:s,onContextMenu:n}){const{attributes:o,listeners:a,setNodeRef:l,transform:d,transition:u,isDragging:m}=Hl({id:e}),h=e.split("/").pop()??e,p=Lt(e),g={transform:Kl.Transform.toString(d),transition:u};return r.jsxs("div",{ref:l,style:g,className:`group relative flex h-9 items-center gap-1.5 border-r border-border border-b px-2.5 ${t?"bg-card text-foreground border-b-card":"bg-transparent text-muted-foreground border-b-border"} ${m?"z-10 opacity-70":""}`,title:e,onContextMenu:b=>{n&&(b.preventDefault(),b.stopPropagation(),c(e),n(e,b.clientX,b.clientY))},children:[r.jsxs("button",{type:"button",onClick:()=>c(e),className:"flex cursor-pointer items-center gap-1.5 outline-none",...o,...a,children:[r.jsx(H,{icon:["far",p.icon],style:{color:p.color},className:"w-3.5 shrink-0 text-[11px]"}),r.jsx("span",{className:"max-w-[180px] truncate",children:h}),i?r.jsx("span",{className:"text-amber-400",children:"●"}):null]}),r.jsx("button",{type:"button",onClick:b=>{b.stopPropagation(),s(e)},"aria-label":`Close ${h}`,className:"ml-1 flex items-center justify-center w-4 h-4 rounded text-muted-foreground opacity-0 hover:bg-foreground
237/5 hover:text-foreground group-hover:opacity-100 cursor-pointer",children:r.jsx(H,{icon:["far","times"],className:"text-xs"})})]})}function Ai({kind:e,depth:t,paddingLeftPx:i,onCommit:c,onCancel:s,initialValue:n="",suggestedExtension:o}){const[a,l]=f.useState(()=>n||(e==="file"&&o?o:"")),[d,u]=f.useState(null),m=f.useRef(null);f.useEffect(()=>{if(m.current)if(m.current.focus(),e==="file"&&o&&a===o)m.current.setSelectionRange(0,0);else if(a.includes(".")){const v=a.lastIndexOf(".");m.current.setSelectionRange(0,v)}else m.current.select()},[]);const h=no(a,e),p=!h.ok&&a.length>0?h.reason:null,g=d||p,b=()=>{const v=no(a,e);if(!v.ok){u(v.reason);return}c(a)},x=e==="file",w=x?Lt(a||"untitled.txt"):xs(!0);return r.jsxs("li",{className:"group relative flex flex-col",onKeyDown:v=>v.stopPropagation(),children:[r.jsxs("div",{className:"flex items-center gap-1.5 py-0.5 pr-1.5",style:{paddingLeft:`${i}px`},children:[r.jsx(H,{icon:["far",w.icon],style:{color:w.color},className:"w-3.5 shrink-0 text-[12px]"}),r.jsx("input",{ref:m,type:"text",value:a,onChange:v=>{l(v.target.value),d&&u(null)},onKeyDown:v=>{v.key==="Enter"?(v.preventDefault(),b()):v.key==="Escape"&&(v.preventDefault(),s())},onBlur:()=>{setTimeout(()=>s(),0)},placeholder:x?"name.gd":"New folder",className:"min-w-0 flex-1 bg-background border border-accent/40 rounded px-1 py-0 text-[13px] text-foreground outline-none focus:border-accent",spellCheck:!1,autoComplete:"off",autoCorrect:"off",autoCapitalize:"off"})]}),g?r.jsx("div",{role:"alert",className:"text-[11px] text-amber-400 pl-1.5",style:{paddingLeft:`${i}px`},children:g}):null]})}function ch(e){const t={type:"dir",name:"",path:"",children:[]};for(const i of e){const c=i.path.split("/").filter(Boolean);if(c.length===0)continue;const s=c[c.length-1],n=Al.has(s);let o=t;for(let a=0;a<c.length;a++){const l=c[a],d=a===c.length-1;if(d&&n)break;const u=c.slice(0,a+1).join("/");let m=o.children.find(h=>h.name===l);m||(d?m={type:"file",name:l,path:u,size:i.size}:m={type:"dir",name:l,path:u,children:[]},o.children.push(m)),d||(o=m)}}return Pi(t),t}function Pi(e){e.children.sort((t,i)=>t.type!==i.type?t.type==="dir"?-1:1:t.name.localeCompare(i.name));for(const t of e.children)t.type==="dir"&&Pi(t)}const Di="__tesana_root__",dh=f.forwardRef(function({activePath:t,onSelectFile:i,onRequestRename:c,onRequestDelete:s,onContextMenu:n,inlineNew:o,onInlineNewCommit:a,onInlineNewCancel:l},d){const{fileTree:u,status:m,renameFile:h}=wt(),[p,g]=f.useState(()=>({scripts:!0,scenes:!0,assets:!0})),[b,x]=f.useState(null),w=Ca(Ea(Ta,{activationConstraint:{distance:5}})),v=f.useMemo(()=>ch(u.filter(k=>!Ml(k.path))),[u]),N=f.useCallback(k=>{g(S=>({...S,[k]:!S[k]}))},[]);f.useEffect(()=>{!o||!o.parentPath||g(k=>k[o.parentPath]?k:{...k,[o.parentPath]:!0})},[o]),f.useImperativeHandle(d,()=>({collapseAll:()=>g({}),expand:k=>g(S=>S[k]?S:{...S,[k]:!0})}),[]);const y=f.useCallback(k=>{const S=String(k.active.id),T=k.over?.id?String(k.over.id):null;if(!T)return;const E=T===Di?"":T,A=S.split("/").pop()??S,M=E?`${E}/${A}`:A;M!==S&&h(S,M).catch(R=>{const _=R instanceof Error?R.message:String(R);x(_),window.setTimeout(()=>x(null),4500)})},[h]);return m==="connecting"||m==="snapshotting"?r.jsx("div",{className:"flex h-full items-center justify-center px-3 text-center",children:r.jsx(_t,{size:"sm",text:"Loading project files…"})}):m==="disconnected"||m==="error"?r.jsx("div",{className:"flex h-full items-center justify-center px-3 text-center text-xs text-amber-400",children:"Disconnected from sync. Reconnecting…"}):r.jsxs("div",{className:"flex h-full flex-col",children:[r.jsx(Ma,{sensors:w,collisionDetection:Yl,onDragEnd:y,children:r.jsx(uh,{onContextMenu:(k,S)=>n?.({kind:"folder",path:""},k,S),children:r.jsxs("ul",{className:"overflow-y-auto py-1 text-[13px] leading-tight",children:[o&&o.parentPath===""?r.jsx(Ai,{kind:o.kind,depth:0,paddingLeftPx:_s,onCommit:k=>a?.(o.kind,"",k),onCancel:()=>l?.()}):null,v.children.map(k=>r.jsx(Ri,{node:k,depth:0,activePath:t,expanded:p,onToggle:N,onSelectFile:i,onRequestRename:c,onRequestDelete:s,onContextMenu:n,inlineNew:o,onInlineNewCommit:a,onInlineNewCancel:l},k.path))]})})}),b?r.jsx("div",{role:"alert",className:"border-t border-border bg-destructive/10 px-3 py-1.5 text-[11px] text-destructive",children:b}):null]})});function uh({children:e,onContextMenu:t}){const{setNodeRef:i,isOver:c}=Aa({id:Di});return r.jsx("div",{ref:i,className:`flex-1 overflow-y-auto ${c?"bg-accent/10":""}`,onContextMenu:s=>{t&&(s.preventDefault(),t(s.clientX,s.clientY))},children:e})}const cs=12,_s=22,fh=8;
237function Ri(e){return e.node.type==="dir"?r.jsx(mh,{...e,node:e.node}):r.jsx(hh,{...e,node:e.node})}function mh({node:e,depth:t,activePath:i,expanded:c,onToggle:s,onSelectFile:n,onRequestRename:o,onRequestDelete:a,onContextMenu:l,inlineNew:d,onInlineNewCommit:u,onInlineNewCancel:m}){const h=!!c[e.path],p=xs(h),{setNodeRef:g,isOver:b}=Aa({id:e.path});return r.jsxs("li",{children:[r.jsxs("button",{ref:g,type:"button",onClick:()=>s(e.path),onContextMenu:x=>{l&&(x.preventDefault(),x.stopPropagation(),l({kind:"folder",path:e.path},x.clientX,x.clientY))},className:`flex w-full items-center gap-1.5 truncate px-2 py-0.5 text-left text-foreground hover:bg-foreground/5 ${b?"bg-accent/10":""}`,style:{paddingLeft:`${t*cs+fh}px`},children:[r.jsx(H,{icon:["far","chevron-right"],className:`w-2.5 shrink-0 text-[9px] text-muted-foreground transition-transform ${h?"rotate-90":""}`}),r.jsx(H,{icon:["far",p.icon],style:{color:p.color},className:"w-3.5 shrink-0 text-[12px]"}),r.jsx("span",{className:"truncate",children:e.name})]}),h?r.jsxs("ul",{children:[d&&d.parentPath===e.path?r.jsx(Ai,{kind:d.kind,depth:t+1,paddingLeftPx:(t+1)*cs+_s,onCommit:x=>u?.(d.kind,e.path,x),onCancel:()=>m?.()}):null,e.children.map(x=>r.jsx(Ri,{node:x,depth:t+1,activePath:i,expanded:c,onToggle:s,onSelectFile:n,onRequestRename:o,onRequestDelete:a,onContextMenu:l,inlineNew:d,onInlineNewCommit:u,onInlineNewCancel:m},x.path))]}):null]})}function hh({node:e,depth:t,activePath:i,onSelectFile:c,onRequestRename:s,onRequestDelete:n,onContextMenu:o}){const a=e.path===i,l=Lt(e.path),{attributes:d,listeners:u,setNodeRef:m,transform:h,isDragging:p}=Xl({id:e.path}),g=h?{transform:`translate3d(${h.x}px, ${h.y}px, 0)`}:{};return r.jsxs("li",{className:`group relative flex items-stretch ${a?"bg-accent/10 text-accent":"text-foreground hover:bg-foreground
237/5"} ${p?"opacity-50":""}`,style:g,onContextMenu:b=>{o&&(b.preventDefault(),b.stopPropagation(),o({kind:"file",path:e.path},b.clientX,b.clientY))},children:[r.jsxs("button",{ref:m,type:"button",onClick:()=>c(e.path),className:"flex min-w-0 flex-1 items-center gap-1.5 truncate py-0.5 pr-1 text-left",style:{paddingLeft:`${t*cs+_s}px`},...d,...u,children:[r.jsx(H,{icon:["far",l.icon],style:{color:l.color},className:"w-3.5 shrink-0 text-[12px]"}),r.jsx("span",{className:"truncate",children:e.name})]}),s||n?r.jsxs("div",{className:"flex shrink-0 items-center gap-0.5 pr-1.5 opacity-0 transition-opacity group-hover:opacity-100 focus-within:opacity-100",onMouseDown:b=>b.stopPropagation(),onPointerDown:b=>b.stopPropagation(),children:[s?r.jsx("button",{type:"button",onClick:b=>{b.stopPropagation(),s(e.path)},className:"flex h-5 w-5 items-center justify-center rounded text-muted-foreground hover:bg-foreground/10 hover:text-foreground",title:"Rename file","aria-label":`Rename ${e.name}`,children:r.jsx(H,{icon:["far","pen-to-square"],className:"text-[10px]"})}):null,n?r.jsx("button",{type:"button",onClick:b=>{b.stopPropagation(),n(e.path)},className:"flex h-5 w-5 items-center justify-center rounded text-muted-foreground hover:bg-red-500/15 hover:text-red-400",title:"Delete file","aria-label":`Delete ${e.name}`,children:r.jsx(H,{icon:["far","trash"],className:"text-[10px]"})}):null]}):null]})}const es=50;function ph({isOpen:e,recentPaths:t,onSelect:i,onClose:c}){const{fileTree:s}=wt(),n=f.useMemo(()=>s.filter(g=>!Pl(g.path)),[s]),[o,a]=f.useState(""),[l,d]=f.useState(0),u=f.useRef(null),m=f.useRef(null);f.useEffect(()=>{e&&u.current?.focus()},[e]),f.useEffect(()=>{e&&(a(""),d(0))},[e]);const h=f.useMemo(()=>{if(!o.trim()){const x=t.filter(v=>n.some(N=>N.path===v)).slice(0,es);if(x.length>=8)return x;const w=n.map(v=>v.path).filter(v=>!x.includes(v)).slice(0,es-x.length);return[...x,...w]}const g=o.toLowerCase(),b=[];for(const x of n){const w=vh(g,x.path);w>0&&b.push({path:x.path,score:w})}return b.sort((x,w)=>w.score-x.score),b.slice(0,es).map(x=>x.path)},[n,o,t]);f.useEffect(()=>{d(0)},[h]),f.useEffect(()=>{const g=m.current?.children[l];g&&g.scrollIntoView({block:"nearest"})},[l]);const p=g=>{if(g.key==="Escape")g.preventDefault(),c();else if(g.key==="ArrowDown")g.preventDefault(),d(b=>Math.min(b+1,h.length-1));else if(g.key==="ArrowUp")g.preventDefault(),d(b=>Math.max(b-1,0));else if(g.key==="Enter"){g.preventDefault();const b=h[l];b&&i(b)}};return r.jsx(lt,{children:e&&r.jsxs(r.Fragment,{children:[r.jsx(Be.div,{initial:{opacity:0}
237,animate:{opacity:1},exit:{opacity:0},transition:{duration:.2},className:"fixed inset-0 z-[95] bg-black/40",onClick:c}),r.jsx(Be.div,{initial:{opacity:0,scale:.95,y:20},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.95,y:20},transition:{duration:.2,ease:[.16,1,.3,1]},className:"pointer-events-none fixed inset-0 z-[95] flex items-start justify-center px-4 pt-[10vh]",children:r.jsxs("div",{className:"pointer-events-auto flex max-h-[60vh] w-[min(640px,90vw)] flex-col overflow-hidden rounded-lg border border-border bg-card shadow-2xl",onClick:g=>g.stopPropagation(),children:[r.jsx("div",{className:"border-b border-border px-3 py-2.5",children:r.jsx("input",{ref:u,value:o,onChange:g=>a(g.target.value),onKeyDown:p,placeholder:"Type to search files…",className:"w-full bg-transparent text-sm text-foreground placeholder:text-muted-foreground focus:outline-none"})}),r.jsx("ul",{ref:m,className:"flex-1 overflow-y-auto py-1 text-[12px]",children:h.length===0?r.jsx("li",{className:"px-3 py-4 text-center text-muted-foreground",children:"No matching files."}):h.map((g,b)=>r.jsxs("li",{onMouseEnter:()=>d(b),onClick:()=>i(g),className:`flex cursor-pointer items-center gap-2 px-3 py-1.5 ${b===l?"bg-accent/15 text-foreground":"text-foreground hover:bg-foreground
237/5"}`,children:[r.jsx(gh,{path:g}),r.jsx("span",{className:"truncate font-mono text-[12px]",children:xh(g)}),r.jsx("span",{className:"ml-2 truncate text-[11px] text-muted-foreground",children:bh(g)})]},g))}),r.jsxs("footer",{className:"border-t border-border px-3 py-1.5 text-[11px] text-muted-foreground",children:[r.jsx("span",{className:"mr-3",children:"↑↓ navigate"}),r.jsx("span",{className:"mr-3",children:"⏎ open"}),r.jsx("span",{children:"esc close"})]})]})})]})})}function gh({path:e}){const t=Lt(e);return r.jsx(H,{icon:["far",t.icon],style:{color:t.color},className:"w-3.5 shrink-0 text-[12px]"})}function xh(e){const t=e.lastIndexOf("/");return t===-1?e:e.slice(t+1)}function bh(e){const t=e.lastIndexOf("/");return t===-1?"":e.slice(0,t)}function vh(e,t){const i=t.toLowerCase(),c=i.slice(i.lastIndexOf("/")+1);if(c===e||i===e)return 1e4;if(c.startsWith(e))return 5e3-i.length;if(i.startsWith(e))return 4e3-i.length;const s=c.indexOf(e);if(s>=0)return 3e3-s-i.length;const n=i.indexOf(e);if(n>=0)return 2e3-n-i.length;let o=0;for(let a=0;a<e.length;a++){if(o=i.indexOf(e[a],o),o===-1)return 0;o++}return 1e3-i.length}function Xo(e){const t=e.lastIndexOf("/");return t<0?{dir:"",name:e}:{dir:e.slice(0,t),name:e.slice(t+1)}}function yh({isOpen:e,onClose:t,path:i}){const{renameFile:c}=wt(),s=i?Xo(i).name:"",n=i?Xo(i).dir:"",[o,a]=f.useState(s),[l,d]=f.useState(!1),[u,m]=f.useState(null);f.useEffect(()=>{e&&(a(s),m(null))},[e,s]);const h=o.trim(),p=h===s,g=!h||h.includes("/")||h.includes("\\")||h==="."||h==="..",b=async()=>{if(!(!i||g||p)){d(!0),m(null);try{const x=n?`${n}/${h}`:h;if(!await c(i,x)){m("The file couldn't be renamed on the server.");return}t()}catch(x){m(x instanceof Error?x.message:String(x))}finally{d(!1)}}};return r.jsx(lt,{onExitComplete:()=>m(null),children:e&&i&&r.jsxs(r.Fragment,{children:[r.jsx(Be.div,{initial:{opacity:0}
237,animate:{opacity:1},exit:{opacity:0},className:"fixed inset-0 bg-black/80 z-50",onClick:t}),r.jsx(Be.div,{initial:{opacity:0,scale:.95,y:20},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.95,y:20},transition:{duration:.2,ease:[.16,1,.3,1]},className:"fixed inset-0 z-50 flex items-center justify-center p-4 pointer-events-none",children:r.jsxs("div",{className:"relative bg-card rounded-lg border border-border p-4 pt-10 md:p-8 md:pt-8 max-w-md w-full pointer-events-auto",onClick:x=>x.stopPropagation(),children:[r.jsx("button",{onClick:t,disabled:l,className:"absolute top-2 right-2 md:top-4 md:right-4 w-9 h-9 flex items-center justify-center rounded-md transition-colors cursor-pointer hover:bg-foreground/4 text-muted-foreground hover:text-foreground disabled:opacity-30","aria-label":"Close",children:r.jsx(H,{icon:["far","xmark"]})}),r.jsx("h3",{className:"text-lg text-foreground mb-4",children:"Rename file"}),r.jsxs("p",{className:"text-base text-muted-foreground mb-6",children:["Enter a new name for this file.",n?r.jsxs(r.Fragment,{children:[" ","It will stay in ",r.jsxs("span",{className:"font-mono text-foreground",children:[n,"/"]}),"."]}):null," ","To move it to a different folder, drag it in the file tree instead."]}),r.jsx("input",{type:"text",value:o,onChange:x=>a(x.target.value),onKeyDown:x=>{x.key==="Enter"&&!g&&!p&&!l&&b()},className:"w-full h-9 px-3 border border-border rounded-md text-sm text-foreground placeholder:text-muted-foreground focus:outline-none focus:border-foreground transition-colors mb-6 font-mono",placeholder:s||"filename",autoFocus:!0}),u?r.jsx("div",{className:"p-3 bg-red-500/8 border border-red-500/20 rounded-md text-red-400 text-sm mb-6",children:u}):null,r.jsxs("div",{className:"flex gap-3 items-center justify-start",children:[r.jsx("button",{onClick:t,disabled:l,className:"h-9 px-3 bg-foreground
237/6 text-foreground text-sm rounded-md hover:bg-foreground/10 transition-colors cursor-pointer disabled:opacity-30",children:"Cancel"}),r.jsx("button",{onClick:b,disabled:g||p||l,className:"h-9 px-3 bg-foreground text-background text-sm rounded-md hover:opacity-80 transition-all disabled:opacity-30 cursor-pointer",children:l?"Renaming…":"Rename"})]})]})})]})})}function wh(e,t,i){if(i&&i.length>0){const c=i.length;return{dot:"#F87171",label:`${c} file${c===1?"":"s"} failed to sync — retry`,tone:"text-rose-300",severity:"bad"}}if(e==="error")return{dot:"#F87171",label:"Sync error — retry",tone:"text-rose-300",severity:"bad"};if(e==="degraded")return{dot:"#F87171",label:"Sync stuck — retry",tone:"text-rose-300",severity:"bad"};if(e==="disconnected")return{dot:"#F87171",label:"Reconnecting…",tone:"text-rose-300",pulsing:!0,severity:"bad"};if(e==="snapshotting")return{dot:"#FBBF24",label:"Loading project files…",tone:"text-amber-300",pulsing:!0,severity:"busy"};if(e==="connecting")return{dot:"#FBBF24",label:"Connecting…",tone:"text-amber-300",pulsing:!0,severity:"busy"};if(e==="connected"){if(t){const c=Math.max(1,t.total),s=t.downloaded+t.skipped,n=Math.min(100,Math.round(s/c*100));return{dot:"#FBBF24",label:`Mirroring ${s}/${t.total} (${n}%)`,tone:"text-sky-300",pulsing:!0,severity:"busy"}}return{dot:"#34D399",label:"Synced",tone:"text-emerald-300",severity:"ok"}}return null}function jh({status:e,mirrorProgress:t,mirrorErrors:i=null,onRetry:c,variant:s="compact",className:n}){const o=wh(e,t,i),[a,l]=f.useState(!1);if(f.useEffect(()=>{if(s!=="compact"){l(!1);return}if(!o||o.severity!=="ok"){l(!1);return}const h=window.setTimeout(()=>l(!0),2e3);return()=>window.clearTimeout(h)},[o,s]),!o||s==="compact"&&o.severity==="ok"&&a)return null;const d=o.severity==="bad"&&!!c,u=d?"button":"span",m=d?{type:"button",onClick:c,"aria-label":"Retry sync"}:{};return r.jsxs(u,{...m,title:o.severity==="bad"&&c?`Sync: ${o.label} (click to retry)`:`Sync: ${o.label}`,className:me("flex items-center gap-1.5 text-[11px]",d&&"cursor-pointer hover:opacity-80",n),children:[r.jsx("span",{className:me("inline-block h-2 w-2 rounded-full",o.pulsing&&"animate-pulse"),style:{backgroundColor:o.dot,boxShadow:`0 0 6px ${o.dot}88`},"aria-hidden":"true"}),r.jsx("span",{className:o.tone,children:o.label})]})}function kh({activePath:e,cursorPosition:t,language:i,fileSize:c}){const{status:s,agentState:n,mirrorProgress:o,mirrorErrors:a,retryMirror:l,reconnect:d}=wt();return r.jsxs("footer",{className:"flex h-6 shrink-0 items-center justify-between border-t border-border bg-background px-3 text-[11px] text-muted-foreground",role:"status","aria-live":"polite",children:[r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsx(jh,{status:s,mirrorProgress:o,mirrorErrors:a,onRetry:a?l:d,variant:"default"}),r.jsx(Nh,{state:n})]}),r.jsx("div",{className:"flex items-center gap-3",children:e?r.jsxs(r.Fragment,{children:[i?r.jsx("span",{title:`Language: ${i}`,children:Sh(i)}):null,r.jsx("span",{children:"UTF-8"}),t?r.jsxs("span",{children:["Ln ",t.line,", Col ",t.column]}):null,typeof c=="number"?r.jsx("span",{title:"File size",children:_h(c)}):null]}):r.jsx("span",{children:"No file open"})})]})}function Nh({state:e}){return e==="generating"?r.jsxs("span",{className:"flex items-center gap-1.5 text-amber-300",title:"Agent is mid-generation; saves are queued",children:[r.jsx("span",{className:"inline-block h-1.5 w-1.5 animate-pulse rounded-full bg-amber-300"}),"Agent editing"]}):r.jsx("span",{className:"text-muted-foreground",children:"Agent idle"})}function Sh(e){switch(e){case"gdscript":return"GDScript";case"godot-scene":return"Godot Scene";case"godot-resource":return"Godot Resource";case"plaintext":return"Plain text";case"json":return"JSON";case"markdown":return"Markdown";case"yaml":return"YAML";case"toml":return"TOML";case"ini":return"INI";case"javascript":return"JavaScript";case"typescript":return"TypeScript";case"python":return"Python";case"cpp":return"GLSL";default:return e.charAt(0).toUpperCase()+e.slice(1)}}function _h(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:e<1024*1024*1024?`${(e/(1024*1024)).toFixed(1)} MB`:`${(e/(1024*1024*1024)).toFixed(2)} GB`}function Ch(e){const{path:t,tabActions:i,gameId:c,appendPrompt:s,notify:n,onAction:o}=e,a=[{kind:"item",id:"close",label:"Close",icon:Zl,onSelect:()=>{i.closeOne(t),o?.("close")}},{kind:"item",id:"closeOthers",label:"Close Others",disabled:!i.canCloseOthers(t),onSelect:()=>{i.closeOthers(t),o?.("closeOthers")}},{kind:"item",id:"closeRight",label:"Close to the Right",disabled:!i.canCloseToRight(t),onSelect:()=>{i.closeToRight(t),o?.("closeRight")}},{kind:"item",id:"closeSaved",label:"Close Saved",disabled:!i.canCloseSaved,onSelect:()=>{i.closeSaved(),o?.("closeSaved")}},{kind:"item",id:"closeAll",label:"Close All",onSelect:()=>{i.closeAll(),o?.("closeAll")}},{kind:"divider"},{kind:"item",id:"copyPath",label:"Copy Path",icon:hs,onSelect:()=>{Cs(t,n),o?.("copyPath")}},{kind:"item",id:"addToChat",label:"Add to Tesana Chat",icon:ps,onSelect:()=>{s(`@${t}`),o?.("addToChat")}}];return Ce&&(a.push({kind:"divider"}),a.push({kind:"item",id:"reveal",label:"Reveal in Finder",icon:gs,onSelect:()=>
237{jr(c,t).catch(l=>{n?.(`Couldn't reveal: ${l instanceof Error?l.message:String(l)}`)}),o?.("reveal")}})),a}function Eh(e){const{path:t,onRequestRename:i,onRequestDelete:c,gameId:s,appendPrompt:n,notify:o,onAction:a}=e,l=[];return Ce&&(l.push({kind:"item",id:"reveal",label:"Reveal in Finder",icon:gs,onSelect:()=>{jr(s,t).catch(d=>{o?.(`Couldn't reveal: ${d instanceof Error?d.message:String(d)}`)}),a?.("reveal")}}),l.push({kind:"divider"})),l.push({kind:"item",id:"rename",label:"Rename",icon:ec,onSelect:()=>{i(t),a?.("rename")}},{kind:"item",id:"delete",label:"Delete",icon:tc,danger:!0,onSelect:()=>{c(t),a?.("delete")}},{kind:"divider"},{kind:"item",id:"copyPath",label:"Copy Path",icon:hs,onSelect:()=>{Cs(t,o),a?.("copyPath")}},{kind:"item",id:"addToChat",label:"Add to Tesana Chat",icon:ps,onSelect:()=>{n(`@${t}`),a?.("addToChat")}}),l}function Th(e){const{path:t,onRequestInlineNew:i,gameId:c,appendPrompt:s,notify:n,onAction:o}=e,a=[{kind:"item",id:"newFile",label:"New File",icon:rc,onSelect:()=>{i("file",t),o?.("newFile")}},{kind:"item",id:"newFolder",label:"New Folder",icon:nc,onSelect:()=>{i("folder",t),o?.("newFolder")}}];return Ce&&(a.push({kind:"divider"}),a.push({kind:"item",id:"reveal",label:"Reveal in Finder",icon:gs,onSelect:()=>{jr(c,t||void 0).catch(l=>{n?.(`Couldn't reveal: ${l instanceof Error?l.message:String(l)}`)}),o?.("reveal")}})),a.push({kind:"divider"},{kind:"item",id:"copyPath",label:"Copy Path",icon:hs,disabled:!t,onSelect:()=>{t&&(Cs(t,n),o?.("copyPath"))}},{kind:"item",id:"addToChat",label:"Add to Tesana Chat",icon:ps,disabled:!t,onSelect:()=>{t&&(s(`@${t}`),o?.("addToChat"))}}),a}async function Cs(e,t){try{await navigator.clipboard.writeText(e),t?.(`Copied: ${e}`)}catch{const i=document.createElement("textarea");i.value=e,i.style.position="fixed",i.style.opacity="0",document.body.appendChild(i),i.select();try{document.execCommand("copy"),t?.(`Copied: ${e}`)}finally{document.body.removeChild(i)}}}function Mh(e,t,i){if(i!==t)return i;const c=e.indexOf(t);if(c<0)return i;const s=e[c+1];return s||(e[c-1]??null)}function Ah(e){const{openPaths:t,activePath:i,dirtyPaths:c,setOpenPaths:s,setActivePath:n}=e,o=f.useCallback(g=>{const b=t.filter(w=>w!==g),x=Mh(t,g,i);s(b),x!==i&&n(x)},[t,i,s,n]),a=f.useCallback(g=>{t.includes(g)&&(s([g]),n(g))},[t,s,n]),l=f.useCallback(g=>{const b=t.indexOf(g);if(b<0||b>=t.length-1)return;const x=t.slice(0,b+1);s(x),i&&!x.includes(i)&&n(g)},[t,i,s,n]),d=f.useCallback(()=>{const g=t.filter(b=>c.has(b));s(g),i&&!g.includes(i)&&n(g[g.length-1]??null)},[t,c,i,s,n]),u=f.useCallback(()=>{s([]),n(null)},[s,n]),m=f.useCallback(g=>t.length>1&&t.includes(g),[t]),h=f.useCallback(g=>{const b=t.indexOf(g);return b>=0&&b<t.length-1},[t]),p=f.useMemo(()=>t.some(g=>!c.has(g)),[t,c]);return f.useMemo(()=>({closeOne:o,closeOthers:a,closeToRight:l,closeSaved:d,closeAll:u,canCloseOthers:m,canCloseToRight:h,canCloseSaved:p}),[o,a,l,d,u,m,h,p])}const Es="tesana.editor.settings.v1",Nt={monacopilotEnabled:!0,wordWrap:!1,fontSize:13};function $o(){if(typeof window>"u")return Nt;try{const e=window.localStorage.getItem(Es);if(!e)return Nt;const t=JSON.parse(e);return{monacopilotEnabled:typeof t.monacopilotEnabled=="boolean"?t.monacopilotEnabled:Nt.monacopilotEnabled,wordWrap:typeof t.wordWrap=="boolean"?t.wordWrap:Nt.wordWrap,fontSize:t.fontSize===12||t.fontSize===14||t.fontSize===16?t.fontSize:Nt.fontSize}}catch{return Nt}}function qo(e){try{window.localStorage.setItem(Es,JSON.stringify(e))}catch{}}function Ph(){const[e,t]=f.useState(()=>$o());f.useEffect(()=>{const s=n=>{n.key===Es&&t($o())};return window.addEventListener("storage",s),()=>window.removeEventListener("storage",s)},[]);const i=f.useCallback(s=>{t(n=>{const o={...n,...s};return qo(o),o})},[]),c=f.useCallback(()=>{t(Nt),qo(Nt)},[]);return{settings:e,update:i,reset:c}}const Dh=f.lazy(()=>Ye(()=>import("./MonacoPane-DpdRQGtV.js"),__vite__mapDeps([15,1,2,6,3,7,8,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,5,9,10,68,69,70,71,72,73,74,75,76,77,78,79,80,81])).then(e=>({default:e.MonacoPane}))),Rh=16;function Uh({gameId:e}){const{buffers:t,openFile:i,saveBuffer:c,pendingConflicts:s,createFile:n,createFolder:o,fileTree:a,status:l}=wt(),{appendPrompt:d,sendMessage:u}=ya(),{unbuiltCodeEdits:m,markCodeEditSaved:h,clearCodeEditDirty:p}=ms(),{isGenerating:g}=wa(),{t:b}=Ee("studio"),x=f.useCallback(()=>{u(b("codeEditor.rebuildPromptMessage",{defaultValue:"I made a few manual code edits — please rebuild the game so I can see them."}),{source:"code-editor-rebuild"}),p()},[u,p,b]),{settings:w,update:v}=Ph(),N=f.useRef(null),y=f.useRef(null),[k,S]=f.useState(!1),[T,E]=f.useState(null),[A,M]=f.useState([]),[R,_]=f.useState(null),[F,C]=f.useState(!1),[P,U]=f.useState(null),[K,z]=f.useState(null),[O,L]=f.useState([]),[j,D]=f.useState(null),[I,B]=f.useState(null),G=f.useCallback(Y=>{M(X=>X.includes(Y)?X:[...X,Y]),_(Y),L(X=>[Y,...X.filter(ke=>ke!==Y)].slice(0,Rh)),i(Y).catch(X=>{const ye=X instanceof Error?X.message:String(X);U(`Failed to open ${Y}: ${ye}`)})},[i]),q=f.useMemo(()=>{const Y=new Set;for(const X of Object.keys(t))t[X].dirty&&Y.add(X);return Y},[t]),V=Ah({openPaths:A,activePath:R,dirtyPaths:q,setOpenPaths:M,setA
237ctivePath:_}),W=f.useCallback(Y=>{V.closeOne(Y),eo(e,"close",A.length)},[e,A.length,V]),ee=Ko(),[ne,J]=f.useState(null),$=f.useCallback((Y,X,ye)=>{J(Y),ee.openAt(X,ye),to(e,"tab")},[e,ee]),ge=f.useMemo(()=>ne?Ch({gameId:e,path:ne,tabActions:V,appendPrompt:d,notify:U,onAction:Y=>{Y==="copyPath"?Ln(e,"tab"):Y==="addToChat"?On(e,"tab"):Y==="reveal"||eo(e,Y,A.length)}}):[],[d,e,A.length,V,ne]),ce=Ko(),[re,oe]=f.useState(null),[de,Z]=f.useState(null),le=f.useCallback((Y,X)=>{Z({kind:Y,parentPath:X})},[]),ie=f.useCallback((Y,X,ye)=>{oe(Y),ce.openAt(X,ye),to(e,Y.kind==="folder"&&!Y.path?"tree-root":Y.kind)},[e,ce]),Q=f.useCallback(async(Y,X,ye)=>{const ke=Dl(X,ye),we=ce.open?"context-menu":"navbar";try{Y==="file"?(await n(ke,""),Z(null),G(ke),N.current?.expand(X),ol(e,X,we)):(await o(ke),Z(null),N.current?.expand(ke),al(e,X,we))}catch(je){const pe=je instanceof Error?je.message:String(je);U(`Failed to create ${Y}: ${pe}`)}},[n,o,e,G,ce.open]),be=f.useMemo(()=>{if(!re)return[];const Y=re.kind==="folder"&&!re.path?"tree-root":re.kind;return re.kind==="file"?Eh({gameId:e,path:re.path,appendPrompt:d,notify:U,onRequestRename:X=>B(X),onRequestDelete:X=>D(X),onAction:X=>{X==="copyPath"?Ln(e,Y):X==="addToChat"&&On(e,Y)}}):Th({gameId:e,path:re.path,appendPrompt:d,notify:U,onRequestInlineNew:le,onAction:X=>{X==="copyPath"?Ln(e,Y):X==="addToChat"&&On(e,Y)}})},[d,e,le,re]);f.useEffect(()=>{z(null)},[R]),f.useEffect(()=>{const Y=X=>{const ye=X.metaKey||X.ctrlKey;if(ye&&!X.shiftKey&&X.key.toLowerCase()==="p"){X.preventDefault(),C(!0);return}if(ye&&!X.shiftKey&&X.key.toLowerCase()==="s"&&R){X.preventDefault(),c(R).then(ke=>{ke&&h()}).catch(ke=>{const we=ke instanceof Error?ke.message:String(ke);U(`Save failed: ${we}`)});return}X.key==="Escape"&&F&&C(!1)};return window.addEventListener("keydown",Y),()=>window.removeEventListener("keydown",Y)},[R,F,c]),f.useEffect(()=>{if(!P)return;const Y=window.setTimeout(()=>U(null),4e3);return()=>window.clearTimeout(Y)},[P]);const ae=f.useCallback(Y=>{U(`Save failed: ${Y.message}`)},[]),fe=f.useCallback(Y=>{C(!1),G(Y)},[G]),se=R?s.find(Y=>Y.path===R):void 0,Ne=xi({defaultPx:240,minPx:180,maxPx:480,storageKey:"onetap_code_file_tree_width"}),ue=f.useMemo(()=>R?Ss(R):null,[R]),he=f.useMemo(()=>R?t[R]?.size??null:null,[R,t]);return r.jsxs("div",{className:"flex h-full flex-col",children:[r.jsxs("div",{className:"flex min-h-0 flex-1",children:[r.jsxs("aside",{className:"relative flex shrink-0 flex-col border-r border-border bg-background",style:{width:`${Ne.width}px`},children:[r.jsxs("div",{className:"flex items-center justify-between border-b border-border pl-4 pr-2.5 h-9",children:[r.jsx("p",{className:"truncate mr-4 text-[11px] uppercase tracking-wide text-muted-foreground",children:"Project files"}),r.jsxs("div",{className:"flex items-center gap-1",children:[r.jsx(Ke,{content:"New file",delay:200,position:"bottom",children:r.jsx("button",{type:"button",onClick:()=>Z({kind:"file",parentPath:""}),className:"rounded px-1.5 py-0.5 text-[11px] text-muted-foreground hover:bg-foreground
237/5 hover:text-foreground","aria-label":"New file at project root",title:"New file",children:r.jsx(H,{icon:["far","file-plus"],className:"text-[11px]"})})}),r.jsx(Ke,{content:"New folder",delay:200,position:"bottom",children:r.jsx("button",{type:"button",onClick:()=>Z({kind:"folder",parentPath:""}),className:"rounded px-1.5 py-0.5 text-[11px] text-muted-foreground hover:bg-foreground/5 hover:text-foreground","aria-label":"New folder at project root",title:"New folder",children:r.jsx(H,{icon:["far","folder-plus"],className:"text-[11px]"})})}),Ce&&e!=null?r.jsx(Ke,{content:"Reveal in Finder",delay:200,position:"bottom",children:r.jsx("button",{type:"button",onClick:async()=>{try{const{invoke:Y}=await Ye(async()=>{const{invoke:X}=await import("./core-DhEqZVGG.js");return{invoke:X}},[]);await Y("reveal_local_folder",{gameId:String(e)})}catch(Y){const X=Y instanceof Error?Y.message:String(Y);U(`Couldn't open folder: ${X}`)}},className:"rounded px-1.5 py-0.5 text-[11px] text-muted-foreground hover:bg-foreground/5 hover:text-foreground","aria-label":"Open project folder in file manager",title:"Reveal mirror folder in Finder/Explorer",children:r.jsx(H,{icon:["far","folder-open"],className:"text-[11px]"})})}):null,r.jsx(Ke,{content:"Collapse all folders",delay:200,position:"bottom",children:r.jsx("button",{type:"button",onClick:()=>{N.current?.collapseAll(),il(e)},className:"rounded px-1.5 py-0.5 text-[11px] text-muted-foreground hover:bg-foreground
237/5 hover:text-foreground","aria-label":"Collapse all folders",title:"Collapse all folders",children:r.jsx(H,{icon:["far","arrows-to-dotted-line"],className:"text-[11px]"})})}),r.jsx(Ke,{content:"Editor settings",delay:200,position:"bottom",children:r.jsx("button",{ref:y,type:"button",onClick:()=>{const Y=y.current?.getBoundingClientRect();Y&&E({right:Y.right,bottom:Y.bottom}),S(X=>!X)},className:"rounded px-1.5 py-0.5 text-[11px] text-muted-foreground hover:bg-foreground/5 hover:text-foreground","aria-label":"Editor settings",title:"Editor settings",children:r.jsx(H,{icon:["far","gear"],className:"text-[11px]"})})})]})]}),r.jsx("div",{className:"flex-1 overflow-y-auto relative",children:a.length===0&&l==="connected"&&!de?r.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-2 px-4 text-center",children:[r.jsxs("span",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[r.jsx("span",{className:"inline-block h-2 w-2 animate-pulse rounded-full bg-emerald-400"}),"Connected — watching for changes"]}),r.jsx("p",{className:"text-[11px] leading-relaxed text-muted-foreground/70 max-w-[180px]",children:"Files appear here live as the AI writes them."})]}):r.jsx(dh,{ref:N,activePath:R,onSelectFile:G,onRequestRename:Y=>B(Y),onRequestDelete:Y=>D(Y),onContextMenu:ie,inlineNew:de,onInlineNewCommit:Q,onInlineNewCancel:()=>Z(null)})}),r.jsx("div",{className:"absolute bottom-2 right-2 flex items-center gap-1",children:r.jsx(Ke,{content:"Quick open",delay:200,position:"top",children:r.jsx("button",{type:"button",onClick:()=>C(!0),className:"rounded px-1.5 py-0.5 text-[11px] text-muted-foreground hover:bg-foreground
237/5 hover:text-foreground","aria-label":"Quick open file",title:"Quick open (⌘P)",children:"⌘P"})})}),r.jsx("div",{role:"separator","aria-orientation":"vertical","aria-label":"Resize file tree",onMouseDown:Ne.startResize,className:`absolute -right-1 top-0 bottom-0 z-10 w-2 cursor-col-resize ${Ne.isDragging?"":"group"}`,children:r.jsx("div",{className:`mx-auto h-full w-px transition-colors ${Ne.isDragging?"bg-accent/80":"bg-transparent group-hover:bg-accent/40"}`})})]}),r.jsxs("main",{className:"flex min-w-0 flex-1 flex-col bg-background",children:[r.jsx(ih,{openPaths:A,activePath:R,dirtyPaths:q,onSelect:_,onClose:W,onReorder:M,onContextMenu:$}),r.jsx(zf,{path:R}),r.jsxs("div",{className:"min-h-0 flex-1 relative",children:[R?r.jsx(f.Suspense,{fallback:r.jsx("div",{className:"flex h-full items-center justify-center bg-card",children:r.jsx(_t,{size:"md",text:"Loading editor…",overlayColor:fa})}),children:r.jsx(Dh,{path:R,gameId:e,onSaveError:ae,onSaveSuccess:h,onCursorChange:z})}):r.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-2 text-center text-sm text-muted-foreground bg-card",children:[r.jsx("div",{children:"Pick a file from the left to start editing."}),r.jsx("div",{className:"text-xs",children:"⌘P to quick-open."})]}),m&&!g&&r.jsx(Ql,{message:b("codeEditor.unbuiltEditsBanner",{defaultValue:"You saved changes — rebuild to see them in the game?"}),ctaLabel:b("codeEditor.rebuildNow",{defaultValue:"Rebuild"}),ctaIcon:"hammer",onAccept:x,onDismiss:p,dismissAriaLabel:b("codeEditor.dismissRebuildPrompt",{defaultValue:"Dismiss rebuild prompt"})})]}),P?r.jsx("div",{className:"border-t border-border bg-orange-500/[0.04] px-3 py-1 text-[11px] text-amber-300",children:P}):null]})]}),r.jsx(kh,{activePath:R,cursorPosition:K,language:ue,fileSize:he}),r.jsx(ph,{isOpen:F,recentPaths:O,onSelect:fe,onClose:()=>C(!1)}),se?r.jsx(th,{gameId:e,path:se.path}):null,r.jsx(Ho,{open:ee.open,position:ee.position,items:ge,onClose:ee.close,ariaLabel:"Tab actions"}),r.jsx(Ho,{open:ce.open,position:ce.position,items:be,onClose:ce.close,ariaLabel:re?.kind==="folder"?"Folder actions":"File actions"}),r.jsx(ah,{open:k,anchor:T,settings:w,onChange:v,onClose:()=>S(!1),triggerRef:y}),r.jsx(yh,{isOpen:!!I,onClose:()=>B(null),path:I}),r.jsx(sh,{isOpen:!!j,onClose:()=>{j&&j===R&&W(j),D(null)},path:j})]})}function Ts({onComplete:e}){const t=_r(),i=async()=>{const s=await t.setToDefault();s&&e(s)},c=async()=>{const s=await t.setViaPicker();s&&e(s)};return r.jsx("div",{className:"flex h-full flex-col items-center justify-center px-8 text-center",children:r.jsxs("div",{className:"max-w-md",children:[r.jsx("h2",{className:"text-base font-medium text-foreground",children:"Set up your Tesana workspace folder"}),r.jsx("p",{className:"mt-4 text-sm text-muted-foreground",children:"We'll mirror every game you build to a folder on your computer so you can edit code in the editor and run native builds for the smoothest performance."}),r.jsx("p",{className:"mt-2 text-xs text-muted-foreground",children:"Each game becomes its own subfolder. The cloud copy stays the source of truth — your edits flow back up automatically, and the AI's edits flow down. You can change this later in Settings."}),r.jsxs("div",{className:"mt-6 flex flex-col gap-3 items-center justify-center",children:[r.jsx("button",{type:"button",onClick:i,disabled:t.setting,className:"rounded-md bg-foreground px-3 h-9 text-sm font-medium text-background hover:opacity-80 disabled:opacity-30 cursor-pointer transition-opacity",children:t.setting?"Setting up…":"Use ~/Documents/Tesana Games (recommended)"}),r.jsx("button",{type:"button",onClick:c,disabled:t.setting,className:"rounded-md px-3 h-9 text-sm text-foreground bg-foreground
237/6 hover:bg-foreground/10 disabled:opacity-30 cursor-pointer transition-all",children:"Pick a different folder…"})]}),t.error?r.jsx("p",{className:"mt-4 text-xs text-rose-400",children:t.error}):null]})})}function Fh({gameId:e,engineGameName:t}){const i=_r(),c=mn({gameId:e,engineGameName:t}),s=!!(c.record&&t&&c.record.engine_game_name!==t),n=f.useRef(!1);if(f.useEffect(()=>{Ce&&(i.loading||c.loading||i.root&&t&&(c.linking||n.current||c.linked&&!s||(n.current=!0,c.link())))},[i.loading,i.root,c.loading,c.linked,c.linking,c.link,s,t]),f.useEffect(()=>{n.current=!1},[e,s]),Ce&&(i.loading||c.loading))return r.jsx("div",{className:"flex h-full items-center justify-center bg-background",children:r.jsx(_t,{size:"md",text:"Setting up local mirror…"})});if(Ce&&!i.root)return r.jsx(Ts,{onComplete:()=>i.refresh()});if(Ce&&(!c.linked||s)){const o=c.linking?s?"Updating mirror folder for renamed game…":"Creating mirror folder…":"Preparing local mirror…";return r.jsx("div",{className:"flex h-full items-center justify-center bg-background",children:r.jsxs("div",{className:"flex flex-col items-center gap-2",children:[r.jsx(_t,{size:"md",text:o}),c.error?r.jsxs("span",{className:"text-xs text-rose-400",children:["— ",c.error]}):null]})})}return r.jsx(Uh,{gameId:e,engineGameName:t})}function Lh(e,t){switch(e){case"connecting":return{icon:"wifi",headline:"Connecting to your game",body:"Opening a live link to your project in the cloud.",bar:"indeterminate"};case"loading-project":return{icon:"folder-tree",headline:"Loading your project",body:"Reading your game's file list from the cloud.",bar:"indeterminate"};case"mirroring":return{icon:"arrow-down-to-line",headline:"Preparing your local copy",body:"Downloading your game files so builds and edits run right on this computer. Usually under a minute.",bar:"determinate"};case"reconnecting":return{icon:"wifi-slash",headline:"Reconnecting…",body:"The connection to your project dropped — retrying automatically.",bar:"indeterminate"};case"blocked":{const i=t?.length??0;return{icon:"triangle-exclamation",headline:i>0?`${i} file${i===1?"":"s"} failed to sync`:"Some files failed to sync",body:"Local builds are paused so your game can never be built with missing files. Retry usually resolves this.",bar:"none",isError:!0,showRetry:!0}}case"stuck":return{icon:"triangle-exclamation",headline:"Sync is stuck",body:"We've retried several times without luck. Check your internet connection, then retry.",bar:"none",isError:!0,showRetry:!0};case"error":return{icon:"triangle-exclamation",headline:"Sync hit an error",body:"Something went wrong opening this game's sync session.",bar:"none",isError:!0,showRetry:!0};default:return null}}function Ui({phase:e,mirrorProgress:t,mirrorErrors:i=null,onRetry:c,onRevealFolder:s}){const n=Lh(e,i);if(!n)return null;const o=t?Math.max(1,t.total):0,a=t?t.downloaded+t.skipped:0,l=t?Math.min(100,Math.round(a/o*100)):0;return r.jsx("div",{className:"flex h-full flex-col items-center justify-center px-8 bg-background",children:r.jsxs("div",{className:"w-full max-w-sm flex flex-col items-center text-center",children:[r.jsx("div",{className:me("mb-5 flex h-14 w-14 items-center justify-center rounded-full",n.isError?"bg-rose-500/10 text-rose-400":"bg-foreground
237/6 text-foreground/80"),children:r.jsx(H,{icon:["far",n.icon],className:"text-xl"})}),r.jsx("h3",{className:"text-base font-medium text-foreground mb-1.5",children:n.headline}),r.jsx("p",{className:"text-sm text-muted-foreground leading-relaxed",children:n.body}),n.bar!=="none"&&r.jsxs("div",{className:"mt-5 w-full",children:[r.jsx("div",{className:"h-1.5 w-full overflow-hidden rounded-full bg-muted",children:n.bar==="determinate"&&t?r.jsx("div",{className:"h-full rounded-full bg-foreground/60 transition-[width] duration-300",style:{width:`${l}%`}}):r.jsx("div",{className:"compact-sweep h-full w-[28%] rounded-full bg-foreground/40"})}),n.bar==="determinate"&&t&&r.jsxs("p",{className:"mt-2 text-xs tabular-nums text-muted-foreground",children:[a," of ",t.total," files · ",l,"%"]})]}),(n.showRetry||s)&&r.jsxs("div",{className:"mt-6 flex items-center gap-2",children:[n.showRetry&&c&&r.jsx("button",{type:"button",onClick:c,className:"rounded-md bg-foreground px-4 h-9 text-sm font-medium text-background hover:opacity-85 transition-opacity cursor-pointer",children:"Retry"}),s&&r.jsx("button",{type:"button",onClick:s,className:"rounded-md border border-border px-4 h-9 text-sm text-foreground hover:bg-foreground
237/5 transition-colors cursor-pointer",children:"Show local folder"})]})]})})}const ts={ok:!1,python_ok:!1,sdk_ok:!1,godot_ok:!1,python_path:null,sdk_path:null,godot_path:null};function Oh(){const[e,t]=f.useState(ts),[i,c]=f.useState(Ce),[s,n]=f.useState(null),o=f.useCallback(async()=>{if(!Ce){t(ts),c(!1);return}c(!0),n(null);try{const{invoke:a}=await Ye(async()=>{const{invoke:d}=await import("./core-DhEqZVGG.js");return{invoke:d}},[]),l=await a("native_build_availability");t(l)}catch(a){n(a instanceof Error?a.message:String(a)),t(ts)}finally{c(!1)}},[]);return f.useEffect(()=>{o()},[o]),{isDesktop:Ce,availability:e,loading:i,error:s,refresh:o}}const Fi="tesana.playMode";function Gh(){if(typeof window>"u")return null;try{const e=window.localStorage.getItem(Fi);return e==="embedded"||e==="external"?e:null}catch{return null}}function Ih(e){if(!(typeof window>"u"))try{window.localStorage.setItem(Fi,e)}catch{}}function Qo(e){const t=Gh();return!e||t==="external"?"external":"embedded"}function Bh({mode:e,embeddedAvailable:t,embeddedUnavailableReason:i,onChange:c}){return r.jsxs("label",{className:"flex items-center gap-1.5 text-[11px] text-muted-foreground",children:[r.jsx("span",{children:"Play mode:"}),r.jsxs("select",{value:e,onChange:s=>c(s.target.value),className:"rounded border border-border bg-background/80 px-1.5 py-0.5 text-xs text-foreground hover:bg-background focus:outline-none focus:ring-1 focus:ring-accent",children:[r.jsxs("option",{value:"embedded",disabled:!t,title:t?"Game renders inline inside Tesana — recommended":i??"Embedded mode is unavailable",children:["Embedded (recommended)",t?"":" — unavailable"]}),r.jsx("option",{value:"external",title:"Game launches in its own window",children:"External window"})]})]})}function Vh(){const[e,t]=f.useState(null);return f.useEffect(()=>{if(!Ce)return;let i=null,c=!1,s=0;return(async()=>{try{const{listen:n}=await Ye(async()=>{const{listen:a}=await import("./event-CnyWr2tN.js");return{listen:a}},__vite__mapDeps([82,83])),o=await n("embedded://frame-stats",a=>{if(c)return;const l=performance.now();l-s<400||(s=l,t({frame:a.payload.frame,fps:a.payload.fps,frameTimeMs:a.payload.frame_time_ms}))});c?o():i=o}catch(n){console.warn("[useEmbeddedFps] listen failed",n)}})(),()=>{c=!0,i&&i()}},[]),f.useEffect(()=>{if(!e)return;const i=window.setTimeout(()=>t(null),5e3);return()=>window.clearTimeout(i)},[e]),e}function zh(e){const t=_r(),i=mn({gameId:e.gameId,engineGameName:e.engineGameName}),c=!!(i.record&&e.engineGameName&&i.record.engine_game_name!==e.engineGameName),s=f.useRef(!1);return f.useEffect(()=>{Ce&&(t.loading||i.loading||t.root&&e.engineGameName&&(i.linking||s.current||i.linked&&!c||(s.current=!0,i.link())))},[t.loading,t.root,i.loading,i.linked,i.linking,i.link,c,e.engineGameName]),f.useEffect(()=>{s.current=!1},[e.gameId,c]),Ce?t.loading||i.loading?r.jsx(fn,{children:"Setting up local mirror…"}):t.root?!i.linked||c?r.jsxs(fn,{children:[i.linking?c?"Updating mirror folder for renamed game…":"Creating mirror folder…":"Preparing local mirror…",i.error?r.jsxs("span",{className:"ml-2 text-rose-400",children:["— ",i.error]}):null]}):r.jsx(Wh,{...e,localPath:i.record?.local_path??null}):r.jsx(Ts,{onComplete:()=>t.refresh()}):null}function Wh({gameId:e,engineGameName:t,title:i,posterUrl:c,localPath:s}){const n=Oh(),o=wt(),{attachScreenshot:a}=ya(),{cloudBuildHash:l,isGenerating:d,activeRunMode:u}=wa(),m=Rl(),h=f.useRef(null),[p,g]=f.useState(!1);f.useEffect(()=>{g(!1)},[e]);const b=o.fileTree.some(j=>j.path==="project.godot"||j.path.endsWith("/project.godot")),[x,w]=f.useState(null),[v,N]=f.useState(()=>Qo(!1));f.useEffect(()=>{let j=!1;return ja().then(D=>{j||(w(D),N(Qo(D.ok)))}),()=>{j=!0}},[]);const y=f.useCallback(j=>{N(D=>D===j?D:(Ih(j),ll(e,D,j),j))},[e]),k=v==="embedded"&&!!x?.ok&&!!s&&!!t,S=f.useMemo(()=>!k||!s||!t?null:s,[k,s,t]),T=x?r.jsx(Bh,{mode:v,embeddedAvailable:x.ok,embeddedUnavailableReason:x.reason??null,onChange:y}):null,[E,A]=ka();f.useEffect(()=>{(m.status==="ready"||m.status==="playing"||m.status==="launching")&&jl(E)},[E,m.status]);const[M,R]=f.useState(!1),_=f.useCallback(async()=>
237{if(!M){R(!0);try{const j=await kl();j&&a(j)}catch(j){console.warn("[embedded:screenshot] capture failed",j)}finally{R(!1)}}},[a,M]),F=Vh(),C=m.status==="ready"||m.status==="playing"||m.status==="launching",P=m.status==="building"||m.status==="launching",U=f.useCallback(()=>m.build(),[m.build]),K={title:i??t??"this game",isGenerating:d,isBuilding:P,hasBuildError:m.status==="error",buildErrorMessage:m.error??null,fps:F?.fps??null,frameTimeMs:F?.frameTimeMs??null,volume:E,onVolumeChange:A,canAdjustVolume:C,isCapturingScreenshot:M,onCaptureScreenshot:()=>void _(),canCaptureScreenshot:C,isRebuilding:P,onRebuild:()=>void U(),canRebuild:n.availability.ok&&o.localMirrorReady,playMode:v,embeddedAvailable:!!x?.ok,embeddedUnavailableReason:x?.reason??null,onChangePlayMode:y,syncStatus:o.status,mirrorProgress:o.mirrorProgress,mirrorErrors:o.mirrorErrors,onSyncRetry:o.mirrorErrors?o.retryMirror:o.reconnect,onRevealFolder:Ce&&m.linked?()=>void jr(e).catch(j=>console.warn("[desktop-host] reveal folder failed",j)):void 0,fullscreenAvailable:!1},z=f.useRef(null),O=f.useRef(!1);f.useEffect(()=>{z.current=null},[e]),f.useEffect(()=>{e!=null&&n.availability.ok&&o.status==="connected"&&l&&o.localMirrorReady&&b&&m.pckPathHash!==l&&(m.status==="building"||m.status==="launching"||m.status==="error"&&z.current===l||O.current||(O.current=!0,z.current=l,console.info("[external:hook:drift] cloud=%s local=%s → converge + build",l,m.pckPathHash),(async()=>{try{await U()||(z.current=null)}finally{O.current=!1}})()))},[e,l,n.availability.ok,o.status,o.localMirrorReady,b,m.pckPathHash,m.status,U]),f.useEffect(()=>{h.current&&(m.status!=="building"&&m.status!=="launching"||(h.current.scrollTop=h.current.scrollHeight))},[m.status,m.transcript.length]);const L=i??t??"this game";if(n.loading)return r.jsx(fn,{children:"Checking native build environment…"});if(!n.availability.ok)return r.jsx(Hh,{availability:n.availability,onRetry:()=>void n.refresh()});if(!b)return o.isDesktop&&Na(o.phase)?r.jsx(Ui,{phase:o.phase,mirrorProgress:o.mirrorProgress,mirrorErrors:o.mirrorErrors,onRetry:o.mirrorErrors?o.retryMirror:o.reconnect,onRevealFolder:Ce&&m.linked?()=>void jr(e).catch(()=>{}):void 0}):r.jsx("div",{className:"relative flex h-full w-full flex-col",children:r.jsx("div",{className:"flex-1 overflow-hidden",children:r.jsx(Pa,{isGenerating:d,runMode:u})})});if(k&&S){const j=m.pckPath!=null&&(!l||m.pckPathHash===l),D=p?m.pckPath!=null:j;return D&&!p&&queueMicrotask(()=>g(!0)),D?r.jsx(qh,{runner:m,displayTitle:L,gameId:e,baseToolbarConfig:K}):r.jsx($h,{runnerStatus:m.status,isGenerating:d,runMode:u,baseToolbarConfig:K,remotePckState:m.remotePckState})}return r.jsxs("div",{children:[r.jsxs("div",{className:"relative z-20 flex shrink-0 items-center justify-end gap-2 border-b border-border/40 bg-background/90 px-3 py-2",children:[r.jsx(Xh,{runner:m}),T]}),(m.status==="building"||m.status==="launching")&&r.jsx(Kh,{title:L,transcript:m.transcript,transcriptRef:h}),m.status==="error"&&r.jsx(Yh,{title:L,error:m.error,transcript:m.transcript,transcriptRef:h,onRetry:()=>void m.build()}),(m.status==="ready"||m.status==="playing")&&r.jsx(Qh,{title:L,posterUrl:c,status:m.status,outputPath:m.outputPath,onPlay:()=>void m.play(),onRebuild:()=>void m.build(),headerSlot:T}),(m.status==="idle"||m.status==="unavailable")&&r.jsx(fn,{children:"Preparing first build…"})]})}function fn({children:e,tone:t}){const i=t==="error"?"text-rose-300":"text-muted-foreground";return r.jsx("div",{className:"flex h-full items-center justify-center bg-background",children:r.jsx("div",{className:`text-sm ${i}`,children:e})})}function Hh({availability:e,onRetry:t}){const i=[];return e.python_ok||i.push("Python"),e.sdk_ok||i.push("Engine SDK"),e.godot_ok||i.push("Godot"),r.jsx("div",{className:"flex h-full items-center justify-center bg-background px-8 text-center",children:r.jsxs("div",{className:"max-w-md rounded-lg border border-border bg-card p-6",children:[r.jsx("h2",{className:"text-base font-medium text-foreground",children:"Native build environment isn't ready"}),r.jsxs("p",{className:"mt-2 text-sm text-muted-foreground",children:["The desktop app couldn't find ",i.join(" + ")," on this machine. Native builds are required on desktop — there is no WASM fallback in the bundled app."]}),r.jsxs("ul",{className:"mt-4 space-y-1 text-left text-xs text-muted-foreground",children:[r.jsxs("li",{children:[r.jsx("span",{className:"inline-block w-16 text-right pr-2",children:"Python:"}),e.python_ok?e.python_path??"detected":"NOT FOUND"]}),r.jsxs("li",{children:[r.jsx("span",{className:"inline-block w-16 text-right pr-2",children:"SDK:"}),e.sdk_ok?e.sdk_path??"detected":"NOT FOUND"]}),r.jsxs("li",{children:[r.jsx("span",{className:"inline-block w-16 text-right pr-2",children:"Godot:"}),e.godot_ok?e.godot_path??"detected":"NOT FOUND"]})]}),r.jsx("div",{className:"mt-6 flex justify-center gap-2",children:r.jsx("button",{type:"button",onClick:t,className:"rounded bg-accent px-3 py-1.5 text-xs font-medium text-accent-foreground hover:opacity-90",children:"Retry"})}),r.jsx("p",{className:"mt-4 text-xs text-muted-foreground",children:"If this persists, please contact support so we can help with the install."})]})})}function Kh({title:e,transcript:t,transcriptRef:i}){return r.jsxs("div",{className:"flex h-full flex-col bg-background",children:[r.jsxs("header",{className:"border-b border-border px-4 py-3",children:[r.jsxs("div",{className:"text-sm font-medium text-foreground",children:["Building ",e,"…"]}),r.jsx("div",{className:"text-xs text-muted-foreground",children:"Compiling locally with the bundled Godot — usually 8–15 seconds."})]}),r.jsx("div",{ref:i,className:"flex-1 overflow-y-auto bg-foreground
237/[0.04] px-4 py-3 font-mono text-[11px] leading-relaxed",children:t.length===0?r.jsx("div",{className:"text-muted-foreground",children:"Waiting for Godot output…"}):t.map(c=>r.jsx("div",{className:c.stream==="stderr"?"whitespace-pre-wrap text-amber-300":"whitespace-pre-wrap text-foreground",children:c.line},c.ts+c.line.slice(0,60)))})]})}function Yh({title:e,error:t,transcript:i,transcriptRef:c,onRetry:s}){return r.jsxs("div",{className:"flex h-full flex-col bg-background",children:[r.jsxs("header",{className:"flex items-center justify-between border-b border-border bg-rose-500/10 px-4 py-3",children:[r.jsxs("div",{children:[r.jsxs("div",{className:"text-sm font-medium text-foreground",children:["Build failed for ",e]}),t?r.jsx("div",{className:"mt-0.5 text-xs text-rose-300",children:t}):null]}),r.jsx("button",{type:"button",onClick:s,className:"rounded bg-accent px-3 py-1.5 text-xs font-medium text-accent-foreground hover:opacity-90",children:"Retry"})]}),r.jsx("div",{ref:c,className:"flex-1 overflow-y-auto bg-foreground
237/[0.04] px-4 py-3 font-mono text-[11px] leading-relaxed",children:i.length===0?r.jsx("div",{className:"text-muted-foreground",children:"No build output captured."}):i.map(n=>r.jsx("div",{className:n.stream==="stderr"?"whitespace-pre-wrap text-amber-300":"whitespace-pre-wrap text-foreground",children:n.line},n.ts+n.line.slice(0,60)))})]})}function Xh({runner:e}){return e.status==="building"?r.jsxs("span",{className:"flex items-center gap-1.5 rounded-full bg-amber-500/15 px-2 py-0.5 text-[11px] text-amber-200",children:[r.jsx("span",{className:"inline-block h-1.5 w-1.5 animate-pulse rounded-full bg-amber-300"}),"Rebuilding…"]}):e.status==="error"?r.jsx("button",{type:"button",onClick:()=>void e.build(),className:"rounded-full bg-rose-500/20 px-2 py-0.5 text-[11px] text-rose-200 hover:bg-rose-500/30",title:e.error??"Build failed",children:"Build failed — retry"}):null}function $h({runnerStatus:e,isGenerating:t,runMode:i,baseToolbarConfig:c,remotePckState:s}){const n=wt(),o=e==="building"||e==="launching",a={...c,hasPendingBuild:!1,onApplyPendingBuild:()=>{},fullscreenAvailable:!1},l=n.isDesktop&&Na(n.phase);return r.jsxs("div",{className:"relative flex h-full w-full flex-col",children:[r.jsx(Sa,{...a,isFullscreen:!1,onToggleFullscreen:()=>{},canToggleFullscreen:!1}),r.jsx("div",{className:"relative flex-1 overflow-hidden",children:l?r.jsx(Ui,{phase:n.phase,mirrorProgress:n.mirrorProgress,mirrorErrors:n.mirrorErrors,onRetry:n.mirrorErrors?n.retryMirror:n.reconnect}):r.jsx(Pa,{isGenerating:t||o||s==="downloading",runMode:i})})]})}function qh({runner:e,displayTitle:t,gameId:i,baseToolbarConfig:c}){const[s,n]=f.useState(e.pckPath);f.useEffect(()=>{e.pckPath&&!s&&n(e.pckPath)},[e.pckPath,s]);const o=s&&e.pckPath&&e.pckPath!==s?e.pckPath:null,[a,l]=f.useState(0),d=f.useCallback(()=>{(async()=>{try{const{invoke:p}=await Ye(async()=>{const{invoke:g}=await import("./core-DhEqZVGG.js");return{invoke:g}},[]);await p("embedded_engine_shutdown")}catch(p){console.warn("[embedded:restart] shutdown failed (continuing)",p)}l(p=>p+1)})()},[]),u=f.useCallback((p,g)=>{console.warn("[embedded:running] boot failed for %s: %s — clearing meta + rebuilding",p,g),n(null),e.invali
237datePck().then(()=>{e.status!=="building"&&e.status!=="launching"&&e.build()})},[e]),m={...c,hasPendingBuild:!!o,onApplyPendingBuild:()=>{o&&n(o)},onRestartGame:d,canRestartGame:!0,fullscreenAvailable:!0},h=s??e.pckPath;return h?r.jsx(Ul,{pckPath:h,pendingPckPath:o,title:t,gameId:i,toolbar:m,onSwappedToPck:p=>n(p),onBootError:u},a):r.jsxs("div",{className:"relative flex h-full w-full flex-col",children:[r.jsx(Sa,{...m,isFullscreen:!1,onToggleFullscreen:()=>{},canToggleFullscreen:!1}),r.jsx("div",{className:"flex-1"})]})}function Qh({title:e,posterUrl:t,status:i,outputPath:c,onPlay:s,onRebuild:n,headerSlot:o}){const a=f.useMemo(()=>i==="playing"?"Running externally":"Play",[i]);return r.jsxs("div",{className:"relative flex h-full flex-col items-center justify-center bg-background",style:t?{backgroundImage:`linear-gradient(rgba(0,0,0,0.55), rgba(0,0,0,0.55)), url(${t})`,backgroundSize:"cover",backgroundPosition:"center"}:void 0,children:[o?r.jsx("div",{className:"absolute right-3 top-3 z-10",children:o}):null,r.jsxs("div",{className:"flex flex-col items-center gap-3 px-8 text-center",children:[r.jsx("h2",{className:"text-xl font-semibold text-foreground drop-shadow-md",children:e}),r.jsx("p",{className:"text-xs text-muted-foreground drop-shadow",children:"Native build ready. Click Play to launch the game in its own window."}),r.jsxs("div",{className:"mt-3 flex items-center gap-2",children:[r.jsx("button",{type:"button",onClick:s,disabled:i==="playing",className:"rounded-full bg-accent px-6 py-2.5 text-sm font-semibold text-accent-foreground hover:opacity-90 disabled:cursor-default disabled:opacity-70",children:a}),r.jsx("button",{type:"button",onClick:n,disabled:i==="playing",className:"rounded-full border border-border bg-background/90 px-4 py-2 text-xs text-foreground hover:bg-background disabled:opacity-50",children:"Rebuild"})]})]}),c?r.jsx("div",{className:"absolute bottom-3 left-1/2 -translate-x-1/2 max-w-[80%] truncate rounded bg-black/40 px-2 py-1 font-mono text-[10px] text-white/70",children:c}):null]})}const Jh=/^[@_][A-Za-z][A-Za-z0-9]+[@_]\d+$/;function rr(e){return Jh.test(e)}const Zh=new Set(["StaticBody2D","StaticBody3D","RigidBody2D","RigidBody3D","CharacterBody2D","CharacterBody3D","Area2D","Area3D","CollisionShape2D","CollisionShape3D","CollisionPolygon2D","CollisionPolygon3D"]),ep=new Set(["OmniLight3D","SpotLight3D","DirectionalLight3D","PointLight2D","DirectionalLight2D"]);function tp(e){return e==="CharacterBody2D"||e==="CharacterBody3D"?!1:Zh.has(e)}function Ms(e){const i=!rr(e.name),c=!!e.script_path&&e.script_path.length>0,s=!!e.scene_file_path&&e.scene_file_path.length>0;return i||c||s?"entity":tp(e.type)?"attached":ep.has(e.type)?"decoration":"infrastructure"}function ds(e){return e.transform3d?e.transform3d.position:e.transform2d?e.transform2d.position:null}function rp(e,t){const i=Math.min(e.length,t.length);let c=0;for(let s=0;s<i;s++){const n=(e[s]??0)-(t[s]??0);c+=n*n}return Math.sqrt(c)}function Jo(e,t,i){if(rr(e.name))return e.type==="OmniLight3D"||e.type==="PointLight2D"?`Light #${i??"?"}`:e.type==="SpotLight3D"?`Spot Light #${i??"?"}`:e.type==="DirectionalLight3D"?`Sun Light #${i??"?"}`:`${e.type} #${i??"?"}`;if(e.scene_file_path){const c=e.scene_file_path.split("/").pop()??e.scene_file_path;return e.name===c.replace(/\.[^.]+$/,"")?e.name:`${e.name} (${c})`}if(e.script_path){const c=e.script_path.split("/").pop()??e.script_path;return`${e.name} (${c})`}return e.name}function Li(e,t){const i=[],c=new Map;if(!e)return{entities:i,ownerByNodeId:c};const s=t?1.5:50,n=new Map,o=(a,l)=>{const d=Ms(l);if(d==="entity"||d==="decoration"){const u=d==="decoration";let m;if(u){const p=(n.get(l.type)??0)+1;n.set(l.type,p),m=Jo(l,"decoration",p)}else m=Jo(l);const h={id:l.id,name:m,category:u?"decoration":"entity",primaryNode:l,attached:[],position:ds(l)};i.push(h),c.set(l.id,h)}for(const u of l.children)o(l,u)};return o(null,e),Oi(e,s,c),{entities:i,ownerByNodeId:c}}function Oi(e,t,i){const c=[],s=[];e.children.forEach((n,o)=>{const a=i.get(n.id);a?c.push({node:n,entity:a,index:o}):Ms(n)==="attached"&&s.push({node:n,index:o})});for(const n of s){const o=ds(n.node);
237if(!o||c.length===0)continue;let a=null;for(const l of c){const d=ds(l.node);if(!d)continue;const u=rp(o,d);u>t||(a===null||u<a.dist||u===a.dist&&Math.abs(n.index-l.index)<Math.abs(n.index-a.entityIndex))&&(a={entity:l.entity,entityIndex:l.index,dist:u})}a&&(a.entity.attached.push(n.node),i.set(n.node.id,a.entity))}for(const n of e.children)Oi(n,t,i)}function Jt(e,t){if(!e)return null;if(e.id===t)return e;for(const i of e.children){const c=Jt(i,t);if(c)return c}return null}const np={enabled:!0,translate:.5,rotate:15,scale:.1},sp=100;class op{state={gizmoMode:"translate",snap:{...np},lockAspect:!0,selectedIds:[],undoStack:[],redoStack:[]};listeners=new Set;subscribe=t=>(this.listeners.add(t),()=>this.listeners.delete(t));getSnapshot=()=>this.state;set(t){this.state={...this.state,...t};for(const i of this.listeners)i()}setGizmoMode(t){this.set({gizmoMode:t})}setSnapEnabled(t){this.set({snap:{...this.state.snap,enabled:t}})}setSnapValue(t,i){this.set({snap:{...this.state.snap,[t]:i}})}setLockAspect(t){this.set({lockAspect:t})}setSelection(t){this.set({selectedIds:t})}toggleSelection(t){const i=this.state.selectedIds.includes(t);this.set({selectedIds:i?this.state.selectedIds.filter(c=>c!==t):[...this.state.selectedIds,t]})}addToSelection(t){this.state.selectedIds.includes(t)||this.set({selectedIds:[...this.state.selectedIds,t]})}selectOnly(t){this.set({selectedIds:t==null?[]:[t]})}pushUndo(t){const i=[...this.state.undoStack,t];for(;i.length>sp;)i.shift();this.set({undoStack:i,redoStack:[]})}popUndo(){if(this.state.undoStack.length===0)return null;const t=this.state.undoStack[this.state.undoStack.length-1];return this.set({undoStack:this.state.undoStack.slice(0,-1),redoStack:[...this.state.redoStack,t]}),t}popRedo(){if(this.state.redoStack.length===0)return null;const t=this.state.redoStack[this.state.redoStack.length-1];return this.set({redoStack:this.state.redoStack.slice(0,-1),undoStack:[...this.state.undoStack,t]}),t}clearHistory(){this.set({undoStack:[],redoStack:[]})}}const De=new op;function As(){return f.useSyncExternalStore(De.subscribe,De.getSnapshot,De.getSnapshot)}const Gi="spike.scenePanel.mode";function ap(){try{const e=localStorage.getItem(Gi);if(e==="advanced"||e==="simple")return e}catch{}return"simple"}function ip(e){try{localStorage.setItem(Gi,e)}catch{}}function lp(e){const{root:t,rootKind:i,selectedIds:c,onSelect:s,status:n,onReconnect:o,lastUpdate:a,onSetTransform:l,onSetProperty:d}=e,[u,m]=f.useState(()=>ap());f.useEffect(()=>ip(u),[u]);const h=i==="3d",p=f.useMemo(()=>Li(t,h),[t,h]),g=c.length>0?c[c.length-1]:null,b=f.useMemo(()=>g==null?null:Jt(t,g),[t,g]),x=f.useMemo(()=>g==null?null:p.ownerByNodeId.get(g)??null,[p,g]),w=f.useMemo(()=>{if(!t)return{entities:0,decorations:0,totalNodes:0};let v=0,N=0;for(const S of p.entities)S.category==="entity"?v++:N++;let y=0;const k=[t];for(;k.length;){const S=k.pop();y++;for(const T of S.children)k.push(T)}return{entities:v,decorations:N,totalNodes:y}},[p,t]);return r.jsxs("div",{className:"panel",children:[r.jsxs("div",{className:"panel-header",children:[r.jsxs("div",{className:"title-row",children:[r.jsx("h1",{children:"Tesana Scene Spike"}),r.jsx(cp,{status:n,onClick:o})]}),r.jsxs("div",{className:"mode-row",children:[r.jsx("span",{children:"View:"}),r.jsxs("div",{className:"toggle",children:[r.jsx("button",{className:u==="simple"?"active":"",onClick:()=>m("simple"),title:"Show only entities and decorations (designer view)",children:"Simple"}),r.jsx("button",{className:u==="advanced"?"active":"",onClick:()=>m("advanced"),title:"Show every raw node in the scene tree",children:"Advanced"})]}),r.jsx("span",{style:{marginLeft:"auto"},children:u==="simple"?`${w.entities} ent · ${w.decorations} dec`:`${w.totalNodes} nodes`})]}),r.jsxs("div",{className:"mode-row",children:[r.jsxs("span",{children:["Scene root: ",r.jsx("b",{children:i}),c.length>1&&r.jsxs("span",{style:{marginLeft:8,color:"#fde68a"},children:["· ",c.length," selected"]})]}),r.jsx("span",{style:{marginLeft:"auto"},children:a?`↻ ${bp(a)}`:"no data"})]})]}),r.jsx("div",{className:"scene-tree",children:t?u==="simple"?r.jsx(up,{entities:p.entities,selectedIds:c,onSelect:s}):r.jsx(Ii,{node:t,depth:0,selectedIds:c,onSelect:s}):r.jsx(dp,{status:n})}),r.jsx(fp,{node:b,entity:x,mode:u,multiCount:c.length,onSetTransform:l,onSetProperty:d})]})}function cp({status:e,onClick:t}){return r.jsxs("span",{className:`connection-badge ${e}`,onClick:t,style:{cursor:"pointer"},title:"Click to reconnect",children:[r.jsx("span",{className:"dot"}),e]})}function dp({status:e}){return r.jsxs("div",{style:{padding:"20px",color:"#6b7280",fontSize:"12px",lineHeight:1.6},children:[r.jsx("p",{style:{margin:"0 0 10px 0"},children:r.jsx("b",{children:e==="connecting"?"Connecting…":"Waiting for snapshot"})}),r.jsxs("ol",{style:{margin:0,paddingLeft:"16px"},children:[r.jsxs("li",{children:["Make sure your Godot game has the ",r.jsx("code",{children:"scene_export.gd"})," autoload registered."]}),r.jsx("li",{children:"Run the game (F5) and start a level so the world spawns."}),r.jsxs("li",{children:["The autoload listens on ",r.jsx("code",{children:"127.0.0.1:5180"}),"."]})]})]})}function up({entities:e,selectedIds:t,onSelect:i}){const c=f.useMemo(()=>[...e].sort((s,n)=>s.category!==n.category?s.category==="entity"?-1:1:s.name.localeCompare(n.name)),[e]);return c.length===0?r.jsx("div",{style:{padding:"12px",color:"#6b7280",fontSize:"12px"},children:"No entities or decorations in current scene."}):r.jsx(r.Fragment,{children:c.map(s=>
237{const n=t.includes(s.id),o=`tree-row ${s.category}${n?" selected":""}`;return r.jsxs("div",{className:o,onClick:a=>i(s.id,{shift:a.shiftKey,meta:a.metaKey||a.ctrlKey}),children:[r.jsx("span",{className:"toggle-arrow",children:"·"}),r.jsx("span",{className:"name",children:s.name}),r.jsx("span",{className:"meta",children:s.primaryNode.type}),s.attached.length>0&&r.jsxs("span",{className:"badge",title:`${s.attached.length} attached collision/infrastructure node(s) move with this entity`,children:["+",s.attached.length]})]},s.id)})})}function Ii({node:e,depth:t,selectedIds:i,onSelect:c}){const[s,n]=f.useState(t<2),o=Ms(e),a=i.includes(e.id),l=e.children.length>0,d=8+t*12,u=e.scene_file_path?`instance ${e.scene_file_path.split("/").pop()??""}`:e.script_path?`script ${e.script_path.split("/").pop()??""}`:e.type;return r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:`tree-row ${o}${a?" selected":""}`,style:{paddingLeft:d},onClick:m=>{m.stopPropagation(),c(e.id,{shift:m.shiftKey,meta:m.metaKey||m.ctrlKey})},children:[r.jsx("span",{className:"toggle-arrow",onClick:m=>{m.stopPropagation(),n(h=>!h)},style:{cursor:l?"pointer":"default"},children:l?s?"▾":"▸":"·"}),r.jsx("span",{className:"name",children:rr(e.name)?r.jsx("i",{children:e.name}):e.name}),r.jsx("span",{className:"meta",children:u}),l&&r.jsx("span",{className:"badge",children:e.children.length})]}),s&&e.children.map(m=>r.jsx(Ii,{node:m,depth:t+1,selectedIds:i,onSelect:c},m.id))]})}function fp({node:e,entity:t,mode:i,multiCount:c,onSetTransform:s,onSetProperty:n}){return e?r.jsxs("div",{className:"inspector",children:[r.jsxs("h2",{children:[t?t.name:e.name,c>1&&r.jsxs("span",{style:{marginLeft:6,color:"#fde68a",fontSize:11},children:["(+",c-1," more)"]})]}),r.jsx(Qe,{k:"Type",v:e.type}),r.jsx(Qe,{k:"Path",v:e.path,mono:!0}),e.script_path&&r.jsx(Qe,{k:"Script",v:e.script_path,mono:!0}),e.scene_file_path&&r.jsx(Qe,{k:"Scene file",v:e.scene_file_path,mono:!0}),e.inferred_scene_file_path&&r.jsx(Qe,{k:"Inferred GLB",v:e.inferred_scene_file_path,mono:!0}),r.jsx(mp,{node:e,onSetTransform:s}),r.jsx(hp,{node:e,onSetProperty:n}),e.mesh_kind&&r.jsxs("div",{className:"section",children:[r.jsx(Qe,{k:"Mesh",v:e.mesh_kind}),e.mesh_size&&r.jsx(Qe,{k:"Mesh size",v:us(e.mesh_size),mono:!0}),e.mesh_path&&r.jsx(Qe,{k:"Mesh path",v:e.mesh_path,mono:!0})]}),e.shape_kind&&r.jsxs("div",{className:"section",children:[r.jsx(Qe,{k:"Collision",v:e.shape_kind}),e.shape_size&&r.jsx(Qe,{k:"Shape size",v:us(e.shape_size),mono:!0})]}),e.exports&&Object.keys(e.exports).length>
2370&&r.jsxs("div",{className:"section",children:[r.jsx(Qe,{k:"Exports",v:""}),Object.entries(e.exports).map(([o,a])=>r.jsx(Qe,{k:`  ${o}`,v:xp(a),mono:!0},o))]}),t&&t.attached.length>0&&i==="simple"&&r.jsxs("div",{className:"section",children:[r.jsx(Qe,{k:"Attached",v:`${t.attached.length} hidden node(s) move with this entity`}),t.attached.map(o=>r.jsx(Qe,{k:`  · ${o.type}`,v:rr(o.name)?"":o.name,mono:!0},o.id))]})]}):r.jsxs("div",{className:"inspector",children:[r.jsx("h2",{children:"Inspector"}),r.jsx("div",{className:"empty",children:"Nothing selected."})]})}function mp({node:e,onSetTransform:t}){if(e.transform3d){const i=e.transform3d;return r.jsxs("div",{className:"section",children:[r.jsx(rs,{label:"Position",value:i.position,step:.1,onCommit:c=>t(e.id,"position",c)}),r.jsx(rs,{label:"Rotation°",value:[qr(i.rotation_euler_rad[0]),qr(i.rotation_euler_rad[1]),qr(i.rotation_euler_rad[2])],step:1,onCommit:c=>t(e.id,"rotation",[Qr(c[0]),Qr(c[1]),Qr(c[2])])}),r.jsx(rs,{label:"Scale",value:i.scale,step:.05,onCommit:c=>t(e.id,"scale",c)})]})}if(e.transform2d){const i=e.transform2d;return r.jsxs("div",{className:"section",children:[r.jsx(Zo,{label:"Position",value:i.position,step:1,onCommit:c=>t(e.id,"position",c)}),r.jsx(pp,{label:"Rotation°",value:qr(i.rotation_rad),step:1,onCommit:c=>t(e.id,"rotation",Qr(c))}),r.jsx(Zo,{label:"Scale",value:i.scale,step:.05,onCommit:c=>t(e.id,"scale",c)})]})}return null}function hp({node:e,onSetProperty:t}){return e.type!=="OmniLight3D"&&e.type!=="SpotLight3D"&&e.type!=="DirectionalLight3D"?null:r.jsxs("div",{className:"section",children:[r.jsx(Qe,{k:"Light",v:e.type}),e.light_color&&r.jsx(gp,{label:"Color",value:e.light_color,onCommit:i=>t(e.id,"light_color",i)}),e.light_energy!=null&&r.jsx($r,{label:"Energy",value:e.light_energy,min:0,max:5,step:.05,onCommit:i=>t(e.id,"light_energy",i)}),e.omni_range!=null&&r.jsx($r,{label:"Range",value:e.omni_range,min:.5,max:50,step:.5,onCommit:i=>t(e.id,"omni_range",i)}),e.spot_range!=null&&r.jsx($r,{label:"Spot range",value:e.spot_range,min:.5,max:50,step:.5,onCommit:i=>t(e.id,"spot_range",i)}),e.spot_angle_deg!=null&&r.jsx($r,{label:"Spot angle°",value:e.spot_angle_deg,min:1,max:89,step:1,onCommit:i=>t(e.id,"spot_angle",i)})]})}function Qe({k:e,v:t,mono:i}){return r.jsxs("div",{className:"row",children:[r.jsx("span",{className:"key",children:e}),r.jsx("span",{className:"val",style:i?void 0:{fontFamily:"inherit"},children:t})]})}function pp({label:e,value:t,step:i,onCommit:c}){const[s,n]=f.useState(t.toFixed(2));return f.useEffect(()=>{n(t.toFixed(2))},[t]),r.jsxs("div",{className:"row",children:[r.jsx("span",{className:"key",children:e}),r.jsx("span",{className:"val",children:r.jsx("input",{className:"num",type:"number",step:i,value:s,onChange:a=>n(a.target.value),onBlur:()=>o(),onKeyDown:a=>{a.key==="Enter"&&a.target.blur(),a.key==="Escape"&&n(t.toFixed(2))}})})]});function o(){const a=Number(s);Number.isFinite(a)&&a!==t?c(a):n(t.toFixed(2))}}function Zo({label:e,value:t,step:i,onCommit:c}){const[s,n]=f.useState([t[0].toFixed(2),t[1].toFixed(2)]);return f.useEffect(()=>{n([t[0].toFixed(2),t[1].toFixed(2)])},[t]),r.jsxs("div",{className:"row",children:[r.jsx("span",{className:"key",children:e}),r.jsx("span",{className:"val",children:r.jsxs("span",{className:"vec3-row",children:[r.jsx("span",{className:"axis x",children:"X"}),r.jsx(yr,{draft:s[0],setDraft:a=>n([a,s[1]]),commit:()=>o(),step:i}),r.jsx("span",{className:"axis y",children:"Y"}),r.jsx(yr,{draft:s[1],setDraft:a=>n([s[0],a]),commit:()=>o(),step:i})]})})]});function o(){const a=Number(s[0]),l=Number(s[1]);Number.isFinite(a)&&Number.isFinite(l)&&(a!==t[0]||l!==t[1])?c([a,l]):n([t[0].toFixed(2),t[1].toFixed(2)])}}function rs({label:e,value:t,step:i,onCommit:c}){const[s,n]=f.useState([t[0].toFixed(2),t[1].toFixed(2),t[2].toFixed(2)]);return f.useEffect(()=>{n([t[0].toFixed(2),t[1].toFixed(2),t[2].toFixed(2)])},[t]),r.jsxs("div",{className:"row",children:[r.jsx("span",{className:"key",children:e}),r.jsx("span",{className:"val",children:r.jsxs("span",{className:"vec3-row",children:[r.jsx("span",{className:"axis x",children:"X"}),r.jsx(yr,{draft:s[0],setDraft:a=>n([a,s[1],s[2]]),commit:()=>o(),step:i}),r.jsx("span",{className:"axis y",children:"Y"}),r.jsx(yr,{draft:s[1],setDraft:a=>n([s[0],a,s[2]]),commit:()=>o(),step:i}),r.jsx("span",{className:"axis z",children:"Z"}),r.jsx(yr,{draft:s[2],setDraft:a=>n([s[0],s[1],a]),commit:()=>o(),step:i})]})})]});function o(){const a=Number(s[0]),l=Number(s[1]),d=Number(s[2]);Number.isFinite(a)&&Number.isFinite(l)&&Number.isFinite(d)&&(a!==t[0]||l!==t[1]||d!==t[2])?c([a,l,d]):n([t[0].toFixed(2),t[1].toFixed(2),t[2].toFixed(2)])}}function yr({draft:e,setDraft:t,commit:i,step:c}){return r.jsx("input",{className:"num",type:"number",step:c,value:e,onCh
237ange:s=>t(s.target.value),onBlur:i,onKeyDown:s=>{s.key==="Enter"&&s.target.blur()}})}function $r({label:e,value:t,min:i,max:c,step:s,onCommit:n}){const[o,a]=f.useState(t);return f.useEffect(()=>a(t),[t]),r.jsxs("div",{className:"row",children:[r.jsx("span",{className:"key",children:e}),r.jsxs("span",{className:"val",style:{flex:1},children:[r.jsx("input",{className:"slider",type:"range",min:i,max:c,step:s,value:o,onChange:l=>a(Number(l.target.value)),onMouseUp:()=>n(o),onTouchEnd:()=>n(o),onKeyUp:l=>{l.key.startsWith("Arrow")&&n(o)}}),r.jsx("span",{style:{marginLeft:6,color:"#fde68a",fontFamily:"ui-monospace, monospace"},children:o.toFixed(2)})]})]})}function gp({label:e,value:t,onCommit:i}){const c=f.useMemo(()=>{const s=n=>Math.max(0,Math.min(255,Math.round(n*255))).toString(16).padStart(2,"0");return`#${s(t[0])}${s(t[1])}${s(t[2])}`},[t]);return r.jsxs("div",{className:"row",children:[r.jsx("span",{className:"key",children:e}),r.jsxs("span",{className:"val",style:{display:"flex",alignItems:"center",gap:8},children:[r.jsx("input",{className:"color",type:"color",value:c,onChange:s=>{const n=s.target.value,o=parseInt(n.slice(1,3),16)/255,a=parseInt(n.slice(3,5),16)/255,l=parseInt(n.slice(5,7),16)/255;i([o,a,l,t[3]??1])}}),r.jsx("span",{style:{fontFamily:"ui-monospace, monospace",fontSize:10},children:c})]})]})}function us(e){return`[${e.map(t=>t.toFixed(2)).join(", ")}]`}function xp(e){return e==null?"null":Array.isArray(e)?us(e):typeof e=="number"?e.toFixed(3):String(e)}function qr(e){return e*180/Math.PI}function Qr(e){return e*Math.PI/180}function bp(e){const t=Math.max(0,(Date.now()-e)/1e3);if(t<1)return"<1s ago";if(t<60)return`${t.toFixed(0)}s ago`;const i=t/60;return i<60?`${i.toFixed(0)}m ago`:`${(i/60).toFixed(1)}h ago`}const vp="http://127.0.0.1:5181";function xn(e){return!e||!e.startsWith("res://")?null:vp+"/"+e.slice(6)}const wr={active:!1,justEndedAt:0},yp=250,bt={entityInstance:"#ffd966",collision:"#22c55e",area:"#22c55e",staticBody:"#6366f1",characterBody:"#22d3ee",fallback:"#6b7280"};function wp(e){const{rootKind:t,root:i,focusRequest:c}=e,s=t==="3d",n=f.useMemo(()=>kp(i),[i]),o=f.useMemo(()=>Np(i),[i]);return r.jsxs("div",{className:"viewer",children:[r.jsxs(hd,{shadows:!1,dpr:[1,2],gl:{antialias:!0,alpha:!1},children:[s?r.jsx(_p,{}):r.jsx(Ep,{root:i}),r.jsx(Sp,{env:o,isThreeD:s}),!s&&r.jsx(Mp,{}),s&&r.jsx(Ap,{}),r.jsx(f.Suspense,{fallback:null,children:r.jsx(Pp,{...e})}),s&&r.jsx(Wu,{alignment:"top-right",margin:[80,80],children:r.jsx(Hu,{axisColors:["#ef4444","#22c55e","#3b82f6"],labelColor:"#0d0f12"})}),r.jsx(jp,{focusRequest:c})]}),r.jsxs("div",{className:"viewer-overlay",children:["scene root: ",t," · ",i?i.name:"—"]}),n&&r.jsxs("div",{style:{position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",background:"rgba(20,23,28,0.92)",border:"1px solid #2c3038",borderRadius:6,padding:"16px 20px",color:"#e6e8eb",fontSize:12,maxWidth:360,textAlign:"center",lineHeight:1.5,pointerEvents:"none"},children:[r.jsx("b",{style:{display:"block",marginBottom:6,fontSize:13},children:"Open the Game tab and play to a real scene"}),"Your game is currently on a menu (Control nodes only — no spatial transforms). Switch to the Game tab and play through to the world you want to edit, then come back here. The editor will populate as soon as the game loads a 2D or 3D scene."]}),r.jsx("div",{className:"viewer-help",children:s?r.jsxs(r.Fragment,{children:[r.jsx("b",{children:"WASD"})," move ",r.jsx("b",{children:"QE"})," ↕ ",r.jsx("b",{children:"Shift"})," sprint ",r.jsx("b",{children:"L-drag"})," look ",r.jsx("b",{children:"Scroll"})," dolly",r.jsx("span",{style:{margin:"0 6px",opacity:.4},children:"·"}),r.jsx("b",{children:"1/2/3"})," tools ",r.jsx("b",{children:"T"})," snap ",r.jsx("b",{children:"F"})," focus",r.jsx("span",{style:{margin:"0 6px",opacity:.4},children:"·"}),r.jsx("b",{children:"Click"})," select ",r.jsx("b",{children:"Shift+click"})," +sel ",r.jsx("b",{children:"⌘D"})," dup ",r.jsx("b",{children:"Del"})," delete ",r.jsx("b",{children:"⌘Z"})," undo"]}):r.jsxs(r.Fragment,{children:[r.jsx("b",{children:"M-drag"})," / ",r.jsx("b",{children:"Space+drag"})," / ",r.jsx("b",{children:"WASD"})," pan ",r.jsx("b",{children:"Scroll"})," zoom ",r.jsx("b",{children:"F"})," focus",r.jsx("span",{style:{margin:"0 6px",opacity:.4},children:"·"}),r.jsx("b",{children:"1/2/3"})," tools ",r.jsx("b",{children:"T"})," snap",r.jsx("span",{style:{margin:"0 6px",opacity:.4},children:"·"}),r.jsx("b",{children:"Click"})," select ",r.jsx("b",{children:"Shift+click"})," +sel ",r.jsx("b",{children:"⌘D"})," dup ",r.jsx("b",{children:"Del"})," delete ",r.jsx("b",{children:"⌘Z"})," undo"]}
237)})]})}function jp({focusRequest:e}){const{camera:t}=Ge(),i=f.useRef(0),c=f.useRef(null);return Ct(()=>{const s=e.current;if(s.token!==i.current){i.current=s.token;const l=t.isOrthographicCamera===!0;let d,u=t.zoom??1;if(l)d=new Ae(s.position.x,s.position.y,t.position.z),u=Math.max(.4,Math.min(2.5,200/Math.max(s.size*4,50)));else{const m=new Ae(s.size*2,s.size*1.5,s.size*2);d=s.position.clone().add(m)}c.current={startPos:t.position.clone(),targetPos:d,lookAt:s.position.clone(),startZoom:t.zoom??1,targetZoom:u,startTime:performance.now(),duration:300,isOrtho:l}}const n=c.current;if(!n)return;const o=Math.min(1,(performance.now()-n.startTime)/n.duration),a=1-Math.pow(1-o,3);if(t.position.lerpVectors(n.startPos,n.targetPos,a),n.isOrtho){const l=t;l.zoom=n.startZoom+(n.targetZoom-n.startZoom)*a,l.updateProjectionMatrix()}else t.lookAt(n.lookAt);o>=1&&(c.current=null)}),null}function kp(e){if(!e)return!1;const t=[e];for(;t.length;){const i=t.pop();if(i.transform2d||i.transform3d)return!1;for(const c of i.children)t.push(c)}return!0}function Np(e){if(!e)return null;const t=[e];for(;t.length;){const i=t.pop();if(i.environment)return i.environment;for(const c of i.children)t.push(c)}return null}function Sp({env:e,isThreeD:t}){const{scene:i}=Ge();f.useEffect(()=>{if(!e){i.background=new Re(461068),i.fog=null;return}const n=e.sky_top_color?new Re(e.sky_top_color[0],e.sky_top_color[1],e.sky_top_color[2]):new Re(e.background_color[0],e.background_color[1],e.background_color[2]);if(i.background=n,e.fog_enabled&&e.fog_light_color&&e.fog_density!=null){const o=new Re(e.fog_light_color[0],e.fog_light_color[1],e.fog_light_color[2]);i.fog=new pd(o,e.fog_density*.5)}else i.fog=null},[e,i]);const c=e?.ambient_light_color?new Re(e.ambient_light_color[0],e.ambient_light_color[1],e.ambient_light_color[2]):new Re(16777215),s=e?.ambient_light_energy??(t?.4:1);return r.jsx("ambientLight",{color:c,intensity:s})}function _p(){return r.jsx(Lu,{makeDefault:!0,position:[20,8,20],fov:60,near:.05,far:2e3})}function Cp({active:e}){const{camera:t,gl:i}=Ge(),c=f.useRef(0),s=f.useRef(0),n=f.useRef(!1),o=f.useRef(new Set);return f.useEffect(()=>{t.rotation.order="YXZ";const a=new Ae(0,1.5,0);t.lookAt(a),c.current=t.rotation.y,s.current=t.rotation.x},[t]),f.useEffect(()=>{if(!e)return;const a=i.domElement,l={x:0,y:0},d={value:!1},u=4,m=v=>{v.button===0&&(d.value=!0,n.current=!1,l.x=v.clientX,l.y=v.clientY)},h=v=>{v.button===0&&(d.value=!1,n.current=!1)},p=v=>{if(!d.value)return;if(!n.current){const y=v.clientX-l.x,k=v.clientY-l.y;if(y*y+k*k<u*u)return;n.current=!0}const N=.0035;c.current-=v.movementX*N,s.current-=v.movementY*N,s.current=Math.max(-Math.PI/2+.05,Math.min(Math.PI/2-.05,s.current)),t.rotation.order="YXZ",t.rotation.y=c.current,t.rotation.x=s.current,t.rotation.z=0},g=v=>{v.preventDefault();const N=new Ae;t.getWorldDirection(N);const y=-v.deltaY*.05;t.position.addScaledVector(N,y)},b=()=>{const v=document.activeElement;if(!v)return!1;const N=v.tagName;return N==="INPUT"||N==="TEXTAREA"||N==="SELECT"||v.isContentEditable===!0},x=v=>{b()||(o.current.add(v.code),(v.code==="Space"||v.code==="ArrowUp"||v.code==="ArrowDown"||v.code==="ArrowLeft"||v.code==="ArrowRight")&&v.preventDefault())},w=v=>{o.current.delete(v.code)};return a.addEventListener("mousedown",m),window.addEventListener("mouseup",h),a.addEventListener("mousemove",p),a.addEventListener("wheel",g,{passive:!1}),window.addEventListener("keydown",x),window.addEventListener("keyup",w),()=>{a.removeEventListener("mousedown",m),window.removeEventListener("mouseup",h),a.removeEventListener("mousemove",p),a.removeEventListener("wheel",g),window.removeEventListener("keydown",x),window.removeEventListener("keyup",w),o.current.clear(),n.current=!1}},[t,i,e]),Ct((a,l)=>{if(!e)return;const u=(o.current.has("ShiftLeft")||o.current.has("ShiftRight")?30:10)*l,m=new Ae;t.getWorldDirection(m);const h=new Ae(m.x,0,m.z);h.lengthSq()<1e-6&&h.set(0,0,-1),h.normalize();const p=new Ae().crossVectors(h,new Ae(0,1,0)).normalize(),g=new Ae;(o.current.has("KeyW")||o.current.has("ArrowUp"))&&g.addScaledVector(h,1),(o.current.has("KeyS")||o.current.has("ArrowDown"))&&g.addScaledVector(h,-1),(o.current.has("KeyD")||o.current.has("ArrowRight"))&&g.addScaledVector(p,1),(o.current.has("KeyA")||o.current.has("ArrowLeft"))&&g.addScaledVector(p,-1),(o.current.has("KeyE")||o.current.has("Space"))&&(g.y+=1),o.current.has("KeyQ")&&(g.y-=1),(o.current.has("Control
237Left")||o.current.has("ControlRight"))&&(g.y-=1),g.lengthSq()>0&&(g.normalize().multiplyScalar(u),t.position.add(g))}),null}function Ep({root:e}){const t=f.useRef(null),i=f.useRef(!1);return f.useLayoutEffect(()=>{if(i.current||!e||!t.current)return;const c=new Ae;let s=0;const n=o=>{const a=o.transform2d?.position;a&&(c.x+=a[0],c.y-=a[1],s++);for(const l of o.children)n(l)};n(e),s>0&&c.divideScalar(s),t.current.position.set(c.x,c.y,1e3),t.current.zoom=.4,t.current.updateProjectionMatrix(),i.current=!0},[e]),r.jsx(di,{ref:t,makeDefault:!0,near:.1,far:5e3})}function Tp({active:e}){const{camera:t,gl:i}=Ge(),c=f.useRef(new Set),s=f.useRef(!1),n=f.useRef(null);return f.useEffect(()=>{t.rotation.set(0,0,0),t.up.set(0,1,0)},[t]),f.useEffect(()=>{if(!e)return;const o=i.domElement,a=(x,w)=>{const v=t,N=o.getBoundingClientRect(),y=(v.right-v.left)/v.zoom,k=(v.top-v.bottom)/v.zoom;return{x:x/N.width*y,y:w/N.height*k}},l=()=>{const x=document.activeElement;if(!x)return!1;const w=x.tagName;return w==="INPUT"||w==="TEXTAREA"||w==="SELECT"||x.isContentEditable===!0},d=x=>{x.button===1?(x.preventDefault(),n.current="middle"):x.button===0&&s.current&&(x.preventDefault(),n.current="space")},u=()=>{n.current=null},m=x=>{if(!n.current)return;const w=a(x.movementX,x.movementY);t.position.x-=w.x,t.position.y+=w.y},h=x=>{x.preventDefault();const w=t,v=w.zoom,N=Math.exp(-x.deltaY*.0015),y=Math.max(.05,Math.min(20,v*N));if(y===v)return;const k=o.getBoundingClientRect(),S=(x.clientX-k.left)/k.width*2-1,T=-((x.clientY-k.top)/k.height*2-1),E=(w.right-w.left)/v,A=(w.top-w.bottom)/v,M=t.position.x+S*E/2,R=t.position.y+T*A/2;w.zoom=y,w.updateProjectionMatrix();const _=(w.right-w.left)/y,F=(w.top-w.bottom)/y,C=t.position.x+S*_/2,P=t.position.y+T*F/2;t.position.x+=M-C,t.position.y+=R-P},p=x=>{l()||(x.code==="Space"&&(s.current=!0),c.current.add(x.code),(x.code==="ArrowUp"||x.code==="ArrowDown"||x.code==="ArrowLeft"||x.code==="ArrowRight")&&x.preventDefault())},g=x=>{x.code==="Space"&&(s.current=!1,n.current==="space"&&(n.current=null)),c.current.delete(x.code)},b=x=>{x.preventDefault()};return o.addEventListener("mousedown",d),window.addEventListener("mouseup",u),o.addEventListener("mousemove",m),o.addEventListener("wheel",h,{passive:!1}),o.addEventListener("contextmenu",b),window.addEventListener("keydown",p),window.addEventListener("keyup",g),()=>{o.removeEventListener("mousedown",d),window.removeEventListener("mouseup",u),o.removeEventListener("mousemove",m),o.removeEventListener("wheel",h),o.removeEventListener("contextmenu",b),window.removeEventListener("keydown",p),window.removeEventListener("keyup",g),c.current.clear(),n.current=null,s.current=!1}},[t,i,e]),Ct((o,a)=>{if(!e)return;const l=c.current.has("ShiftLeft")||c.current.has("ShiftRight"),d=t,m=(l?900:360)*a/d.zoom;let h=0,p=0;if((c.current.has("KeyW")||c.current.has("ArrowUp"))&&(p+=1),(c.current.has("KeyS")||c.current.has("ArrowDown"))&&(p-=1),(c.current.has("KeyD")||c.current.has("ArrowRight"))&&(h+=1),(c.current.has("KeyA")||c.current.has("ArrowLeft"))&&(h-=1),h!==0||p!==0){const g=Math.hypot(h,p);t.position.x+=h/g*m,t.position.y+=p/g*m}}),null}function Mp(){return r.jsx("gridHelper",{args:[8e3,80,2040617,1316636],rotation:[Math.PI/2,0,0]})}function Ap(){return r.jsx(xd,{args:[100,100],cellSize:1,sectionSize:5,cellColor:"#1f2329",sectionColor:"#2c3038",fadeDistance:80,fadeStrength:1.5,followCamera:!1,infiniteGrid:!0})}function Pp(e){const{root:t,rootKind:i,selectedIds:c,onSelect:s,ownerByNodeId:n,onApplyDelta:o,onApplyRotation:a,onApplyScale:l,gizmoMode:d,snap:u,lockAspect:m,showAdvanced:h=!1}=e,p=i==="3d",[g,b]=f.useState(!0),x=f.useRef(new Map);return t?r.jsxs(r.Fragment,{children:[p?r.jsx(Cp,{active:g}):r.jsx(Tp,{active:g}),p?r.jsx(fs,{node:t,isThreeD:!0,showAdvanced:h,selectedIds:c,ownerByNodeId:n,onSelect:s,meshRegistry:x}):r.jsx("group",{scale:[1,-1,1],children:r.jsx(fs,{node:t,isThreeD:!1,showAdvanced:h,selectedIds:c,ownerByNodeId:n,onSelect:s,meshRegistry:x})}),c.length>0&&r.jsx(Ip,{selectedIds:c,isThreeD:p,meshRegistry:x,ownerByNodeId:n,onApplyDelta:o,onApplyRotation:a,onApplyScale:l,onDraggingChanged:b,gizmoMode:d,snap:u,lockAspect:m})]}):null}function fs({node:e,isThreeD:t,showAdvanced:i,selectedIds:c,ownerByNodeId:s,onSelect:n,meshRegistry:o,insideInstancedScene:a=!1}){const l=f.useRef(null),d=s.get(e.id),u=d!=null&&d.id!==e.id,m=s.get(e.id)?.category??null,p=!!(e.scene_file_path?.endsWith(".glb")||e.scene_file_path?.endsWith(".gltf")?e.scene_file_path:e.inferred_scene_file_path),g=rr(e.name),b=d!=null&&d.id===e.id,x=g&&(e.type==="MeshInstance3D"||e.type==="Sprite2D"||e.type==="AnimatedSprite2D"||e.type==="Sprite3D"||e.type==="TileMap"||e.type==="TileMapLayer"),w=g&&(e.type==="Parallax2D"||e.type==="ParallaxLayer"||e.type==="Node2D"),y=!((e.type==="StaticBody3D"||e.type==="RigidBody3D"||e.type==="Area3D"||e.type==="CollisionShape3D"||e.type==="StaticBody2D"||e.type==="RigidBody2D"||e.type==="Area2D"||e.type==="CollisionShape2D"||e.type==="CollisionPolygon3D"||e.type==="CollisionPolygon2D")&&!d)&&
237(b||!g||m==="decoration"||!!e.scene_file_path||!!e.script_path||x||w),k=i||y,S=!i&&(x||w)&&!b,T=a||p;f.useEffect(()=>(l.current&&o.current.set(e.id,l.current),()=>{o.current.delete(e.id)}),[e.id,o]);let E=[0,0,0],A=[0,0,0],M=[1,1,1];if(t&&e.transform3d){const P=e.transform3d;E=[P.position[0],P.position[1],P.position[2]],A=[P.rotation_euler_rad[0],P.rotation_euler_rad[1],P.rotation_euler_rad[2]],M=[P.scale[0],P.scale[1],P.scale[2]]}else if(!t&&e.transform2d){const P=e.transform2d,U=e.id%999*.001,K=(e.z_index??0)+U;E=[P.position[0],P.position[1],K],A=[0,0,P.rotation_rad],M=[P.scale[0],P.scale[1],1]}const R=c.includes(e.id)||d!=null&&c.includes(d.id),_=P=>{if(S||wr.active||Date.now()-wr.justEndedAt<yp)return;P.stopPropagation();const U=d&&!b&&!i?d.id:e.id,K=P.nativeEvent;n(U,{shift:K.shiftKey,meta:K.metaKey||K.ctrlKey})},F=a&&!i?null:Dp(e,u||S,R,t),C=F&&!S&&k?_:void 0;return r.jsxs("group",{ref:l,position:E,"rotation-order":t?"YXZ":"XYZ",rotation:A,scale:M,userData:{nodeId:e.id},visible:k,onClick:C,children:[F,e.children.map(P=>r.jsx(fs,{node:P,isThreeD:t,showAdvanced:i,selectedIds:c,ownerByNodeId:s,onSelect:n,meshRegistry:o,insideInstancedScene:T},P.id))]})}function Dp(e,t,i,c){const s=i,n=t?.55:1,o=e.scene_file_path?.endsWith(".glb")||e.scene_file_path?.endsWith(".gltf")?e.scene_file_path:e.inferred_scene_file_path;if(o&&c){const a=xn(o),l=o.split("/").pop()??o;if(a)return r.jsx(f.Suspense,{fallback:r.jsxs("mesh",{children:[r.jsx("boxGeometry",{args:[.6,.6,.6]}),r.jsx("meshStandardMaterial",{color:s?"#fbbf24":bt.entityInstance,transparent:!0,opacity:.4})]}),children:r.jsx(Gp,{url:a,selected:s,fallbackLabel:l})})}switch(e.type){case"MeshInstance3D":{const a=e.mesh_size??[1,1,1];return r.jsx(Rp,{size:a,material:e.material,autoNamed:rr(e.name),selected:s,dim:n})}case"OmniLight3D":{const a=ns(e.light_color)??new Re(16707722),l=e.light_energy??1,d=e.omni_range??5;return r.jsxs(r.Fragment,{children:[r.jsxs("mesh",{children:[r.jsx("sphereGeometry",{args:[.15,12,8]}),r.jsx("meshBasicMaterial",{color:s?"#fbbf24":a})]}),r.jsx("pointLight",{color:a,intensity:l*8,distance:d,decay:2})]})}case"SpotLight3D":{const a=ns(e.light_color)??new Re(16707722),l=e.light_energy??1,d=e.spot_range??10,u=(e.spot_angle_deg??30)*(Math.PI/180);return r.jsxs(r.Fragment,{children:[r.jsxs("mesh",{children:[r.jsx("coneGeometry",{args:[.2,.3,8]}),r.jsx("meshBasicMaterial",{color:s?"#fbbf24":a})]}),r.jsx("spotLight",{color:a,intensity:l*6,distance:d,angle:u,decay:2})]})}case"DirectionalLight3D":{const a=ns(e.light_color)??new Re(16777215),l=e.light_energy??1;return r.jsxs(r.Fragment,{children:[r.jsxs("mesh",{rotation:[Math.PI/2,0,0],children:[r.jsx("coneGeometry",{args:[.15,.6,6]}),r.jsx("meshBasicMaterial",{color:s?"#fbbf24":a})]}),r.jsx("directionalLight",{color:a,intensity:l})]})}case"CharacterBody3D":return r.jsxs("mesh",{children:[r.jsx("capsuleGeometry",{args:[.3,.9,4,8]}),r.jsx("meshBasicMaterial",{color:s?"#fbbf24":bt.characterBody,wireframe:!0,transparent:!0,opacity:s?.8:.18})]});case"Camera3D":return r.jsx("group",{children:r.jsxs("mesh",{children:[r.jsx("boxGeometry",{args:[.4,.3,.5]}),r.jsx("meshBasicMaterial",{wireframe:!0,color:s?"#fbbf24":"#22d3ee"})]})});case"StaticBody3D":return r.jsxs("mesh",{children:[r.jsx("sphereGeometry",{args:[.05,6,4]}),r.jsx("meshBasicMaterial",{color:s?"#fbbf24":bt.staticBody,transparent:!0,opacity:.6})]});case"RigidBody3D":return r.jsxs("mesh",{children:[r.jsx("sphereGeometry",{args:[.12,8,6]}),r.jsx("meshBasicMaterial",{color:s?"#fbbf24":"#a855f7",wireframe:!0,transparent:!0,opacity:s?.8:.18})]});case"Area3D":return r.jsxs("mesh",{children:[r.jsx("sphereGeometry",{args:[.08,8,6]}),r.jsx("meshBasicMaterial",{color:s?"#fbbf24":bt.area,wireframe:!0,transparent:!0,opacity:s?.6:.15})]});case"CollisionShape3D":{const a=e.shape_size??[.5,.5,.5];return r.jsxs("mesh",{children:[r.jsx("boxGeometry",{args:a}),r.jsx("meshBasicMaterial",{color:s?"#fbbf24":bt.collision,wireframe:!0})]})}case"Sprite2D":return r.jsx(ta,{info:e.texture,centered:e.centered!==!1,flipH:!!e.flip_h,flipV:!!e.flip_v,selected:s,dim:n});case"AnimatedSprite2D":return r.jsx(ta,{info:e.frame_texture,centered:e.centered!==!1,flipH:!!e.flip_h,flipV:!!e.flip_v,selected:s,dim:n});case"CharacterBody2D":return r.jsxs("mesh",{children:[r.jsx("boxGeometry",{args:[40,60,.1]}),r.jsx("meshBasicMaterial",{color:s?"#fbbf24":bt.characterBody,wireframe:!0,transparent:!0,depthWrite:!1,opacity:s?.7:.
23718})]});case"RigidBody2D":case"StaticBody2D":return r.jsxs("mesh",{children:[r.jsx("boxGeometry",{args:[20,20,.1]}),r.jsx("meshBasicMaterial",{color:s?"#fbbf24":bt.staticBody,wireframe:!0,transparent:!0,depthWrite:!1,opacity:s?.6:.15})]});case"Area2D":return r.jsxs("mesh",{children:[r.jsx("boxGeometry",{args:[30,30,.1]}),r.jsx("meshBasicMaterial",{color:s?"#fbbf24":bt.area,wireframe:!0,transparent:!0,depthWrite:!1,opacity:s?.5:.15})]});case"Camera2D":return r.jsxs("mesh",{children:[r.jsx("boxGeometry",{args:[1280,720,.1]}),r.jsx("meshBasicMaterial",{color:s?"#fbbf24":"#22d3ee",wireframe:!0,transparent:!0,depthWrite:!1,opacity:.35})]});case"TileMap":case"TileMapLayer":return r.jsx(Lp,{node:e,selected:s});case"CollisionShape2D":{const a=e.shape_size;let l=20,d=20;return Array.isArray(a)&&a.length>=2&&(l=a[0]||20,d=a[1]||20),r.jsxs("mesh",{children:[r.jsx("boxGeometry",{args:[l,d,.1]}),r.jsx("meshBasicMaterial",{color:s?"#fbbf24":bt.collision,wireframe:!0,transparent:!0,depthWrite:!1,opacity:s?.5:.18})]})}case"Node2D":case"Node3D":case"Node":case"Control":case"CanvasLayer":case"WorldEnvironment":case"Skeleton3D":case"BoneAttachment3D":case"AnimationPlayer":case"AnimationTree":case"AudioStreamPlayer3D":case"AudioStreamPlayer2D":case"AudioStreamPlayer":case"Timer":case"Parallax2D":case"ParallaxLayer":case"ParallaxBackground":return null;default:return r.jsxs("mesh",{children:[c?r.jsx("sphereGeometry",{args:[.05,6,4]}):r.jsx("planeGeometry",{args:[6,6]}),r.jsx("meshBasicMaterial",{color:s?"#fbbf24":bt.fallback})]})}}function Rp({size:e,material:t,autoNamed:i,selected:c,dim:s}){const n=xn(t?.albedo_texture_path);return n?r.jsx(f.Suspense,{fallback:r.jsx(ea,{size:e,material:t,autoNamed:i,selected:c,dim:s}),children:r.jsx(Up,{size:e,material:t,albedoUrl:n,autoNamed:i,selected:c,dim:s})}):r.jsx(ea,{size:e,material:t,autoNamed:i,selected:c,dim:s})}function Up({size:e,material:t,albedoUrl:i,autoNamed:c,selected:s,dim:n}){const o=ys(ws,i);f.useEffect(()=>
237{o&&(o.colorSpace=js,t?.uv1_scale&&(o.wrapS=fo,o.wrapT=fo,o.repeat.set(t.uv1_scale[0],t.uv1_scale[1])),o.needsUpdate=!0)},[o,t]);const a=t?.albedo_color?new Re(t.albedo_color[0],t.albedo_color[1],t.albedo_color[2]):new Re(16777215),l=t?.albedo_color?.[3]??1,d=s?1:l*n,u=t?.transparent??l<1,m=t?.emission_color?new Re(t.emission_color[0],t.emission_color[1],t.emission_color[2]):null,h=t?.emission_energy??1;return r.jsxs("mesh",{children:[r.jsx("boxGeometry",{args:e}),r.jsx("meshStandardMaterial",{color:s?new Re("#fbbf24"):a,map:o,roughness:t?.roughness??.85,metalness:t?.metallic??0,transparent:u,opacity:d,emissive:m??new Re(0),emissiveIntensity:m?h:0})]})}function ea({size:e,material:t,autoNamed:i,selected:c,dim:s}){const n=t?.albedo_color?new Re(t.albedo_color[0],t.albedo_color[1],t.albedo_color[2]):new Re(i?7041664:10265519),o=t?.albedo_color?.[3]??1,a=c?1:o*(i?.85*s:s),l=t?.transparent??a<1,d=t?.emission_color?new Re(t.emission_color[0],t.emission_color[1],t.emission_color[2]):null,u=t?.emission_energy??1;return r.jsxs("mesh",{children:[r.jsx("boxGeometry",{args:e}),r.jsx("meshStandardMaterial",{color:c?new Re("#fbbf24"):n,roughness:t?.roughness??.85,metalness:t?.metallic??0,transparent:l,opacity:a,emissive:d??new Re(0),emissiveIntensity:d?u:0})]})}function ta({info:e,centered:t,flipH:i,flipV:c,selected:s,dim:n}){if(!e?.path)return r.jsxs("mesh",{children:[r.jsx("planeGeometry",{args:[64,64]}),r.jsx("meshBasicMaterial",{color:s?"#fbbf24":"#cbd5e1",side:Zt,transparent:!0,depthWrite:!1,opacity:.7*n})]});const o=xn(e.path);return o?r.jsx(f.Suspense,{fallback:r.jsxs("mesh",{children:[r.jsx("planeGeometry",{args:[e.width||64,e.height||64]}),r.jsx("meshBasicMaterial",{color:"#475569",side:Zt,transparent:!0,depthWrite:!1,opacity:.3})]}),children:r.jsx(Fp,{info:e,url:o,centered:t,flipH:i,flipV:c,selected:s,dim:n})}):null}function Fp({info:e,url:t,centered:i,flipH:c,flipV:s,selected:n,dim:o}){const a=ys(ws,t),l=f.useMemo(()=>{const h=a.clone();
237if(h.colorSpace=js,h.magFilter=dn,h.minFilter=dn,h.generateMipmaps=!1,e.region&&a.image){const[p,g,b,x]=e.region,w=a.image.width,v=a.image.height;h.repeat.set(b/w,x/v),h.offset.set(p/w,1-(g+x)/v)}return c&&(h.repeat.x*=-1,h.offset.x+=e.region?e.region[2]/(a.image?.width||1):1),s&&(h.repeat.y*=-1,h.offset.y+=e.region?e.region[3]/(a.image?.height||1):1),h.needsUpdate=!0,h},[a,e,c,s]),d=e.width||a.image?.width||64,u=e.height||a.image?.height||64,m=i?[0,0,0]:[d/2,u/2,0];return r.jsxs("mesh",{position:m,scale:[1,-1,1],children:[r.jsx("planeGeometry",{args:[d,u]}),r.jsx("meshBasicMaterial",{map:l,transparent:!0,depthWrite:!1,side:Zt,color:n?new Re("#fbbf24"):new Re(16777215),opacity:n?1:o,toneMapped:!1})]})}function Lp({node:e,selected:t}){const i=e.tile_size,c=e.tile_sources,s=e.tile_cells;if(!i||!c||!s||s.length===0)return r.jsxs("mesh",{children:[r.jsx("planeGeometry",{args:[400,100]}),r.jsx("meshBasicMaterial",{color:t?"#fbbf24":"#475569",side:Zt,transparent:!0,depthWrite:!1,opacity:.4})]});const n=f.useMemo(()=>{const o=new Map;for(const a of s){const l=String(a[2]),d=o.get(l);d?d.push(a):o.set(l,[a])}return o},[s]);return r.jsx("group",{children:Array.from(n.entries()).map(([o,a])=>{const l=c[o];return l?r.jsx(f.Suspense,{fallback:null,children:r.jsx(Op,{source:l,cells:a,tileSize:i,selected:t})},o):null})})}function Op({source:e,cells:t,tileSize:i,selected:c}){const s=xn(e.texture_path),n=ys(ws,s??""),o=f.useMemo(()=>{const l=n.clone();return l.colorSpace=js,l.magFilter=dn,l.minFilter=dn,l.generateMipmaps=!1,l.needsUpdate=!0,l},[n]),a=f.useMemo(()=>{const[l,d]=i,[u,m]=e.region_size,h=n.image?.width??1,p=n.image?.height??1,g=t.length,b=new Float32Array(g*4*3),x=new Float32Array(g*4*2),w=new Uint32Array(g*6);for(let N=0;N<g;N++){const[y,k,,S,T]=t[N],E=y*l,A=k*d,M=E+l,R=A+d,_=N*4*3;b[_+0]=E,b[_+1]=A,b[_+2]=0,b[_+3]=M,b[_+4]=A,b[_+5]=0,b[_+6]=M,b[_+7]=R,b[_+8]=0,b[_+9]=E,b[_+10]=R,b[_+11]=0;const F=S*u/h,C=(S*u+u)/h,P=T*m/p,U=(T*m+m)/p,K=1-P,z=1-U,O=N*4*2;x[O+0]=F,x[O+1]=z,x[O+2]=C,x[O+3]=z,x[O+4]=C,x[O+5]=K,x[O+6]=F,x[O+7]=K;const L=N*6,j=N*4;w[L+0]=j+0,w[L+1]=j+1,w[L+2]=j+2,w[L+3]=j+0,w[L+4]=j+2,w[L+5]=j+3}const v=new gd;return v.setAttribute("position",new In(b,3)),v.setAttribute("uv",new In(x,2)),v.setIndex(new In(w,1)),v.computeBoundingBox(),v.computeBoundingSphere(),v},[t,i,e.region_size,n]);return r.jsx("mesh",{geometry:a,children:r.jsx("meshBasicMaterial",{map:o,transparent:!0,depthWrite:!1,side:Zt,color:c?new Re("#fbbf24"):new Re(16777215),toneMapped:!1})})}function Gp({url:e,selected:t,fallbackLabel:i}){const c=bd(e),s=f.useMemo(()=>{const o=c.scene.clone(!0);return o.traverse(a=>{a instanceof kr&&a.material&&(Array.isArray(a.material)?a.material=a.material.map(l=>l.clone()):a.material=a.material.clone())}),o},[c.scene]);f.useEffect(()=>{s.traverse(o=>{if(!(o instanceof kr))return;const a=Array.isArray(o.material)?o.material:[o.material];for(const l of a)if(l&&"emissive"in l){const d=l;t?(d.emissive=new Re("#fbbf24"),d.emissiveIntensity=.4):d.emissiveIntensity=0,d.needsUpdate=!0}})},[s,t]);const n=f.useMemo(()=>{const o=new bs().setFromObject(s),a=new Ae,l=new Ae;return o.getSize(a),o.getCenter(l),a.x=Math.max(a.x,.2),a.y=Math.max(a.y,.2),a.z=Math.max(a.z,.2),{size:a,center:l,halfHeight:a.y*.5}},[s]);return r.jsxs(r.Fragment,{children:[r.jsx("primitive",{object:s}),r.jsxs("mesh",{position:[n.center.x,n.center.y,n.center.z],children:[r.jsx("boxGeometry",{args:[n.size.x,n.size.y,n.size.z]}),r.jsx("meshBasicMaterial",{transparent:!0,opacity:0,depthWrite:!1})]}),r.jsx(Od,{position:[0,n.center.y+n.halfHeight+.15,0],children:r.jsx(Ru,{fontSize:.12,color:t?"#fbbf24":"#fde68a",anchorX:"center",anchorY:"middle",outlineWidth:.012,outlineColor:"#0d0f12",children:i})})]})}function ns(e){return!e||e.length<3?null:new Re(e[0],e[1],e[2])}function Ip(e){const{selectedIds:t,isThreeD:i,meshRegistry:c,onApplyDelta:s,onApplyRotation:n,onApplyScale:o,onDraggingChanged:a,gizmoMode:l,snap:d,lockAspect:u}=e,m=t.length>1,h=f.useRef(new cn),p=f.useRef(new Ae),g=f.useRef(new Pt),b=f.useRef(new Ae(1,1,1)),x=f.useRef(!1),w=f.useRef(!1);f.useEffect(()=>{const R=F=>{F.key==="Shift"&&(w.current=!0)},_=F=>{F.key==="Shift"&&(w.current=!1)};return window.addEventListener("keydown",R),window.addEventListener("keyup",_),()=>{window.removeEventListener("keydown",R),window.removeEventListener("keyup",_)}},[]);const v=f.useMemo(()=>
237{if(t.length===0)return null;if(m){const R=h.current,_=new Ae;let F=0;for(const C of t){const P=c.current.get(C);if(!P)continue;P.updateMatrixWorld(!0);const U=new Ae().setFromMatrixPosition(P.matrixWorld);_.add(U),F++}return F===0?null:(_.divideScalar(F),R.position.copy(_),R.rotation.set(0,0,0),R.scale.set(1,1,1),R.updateMatrixWorld(!0),R)}return c.current.get(t[0])??null},[t,c,m]);if(f.useEffect(()=>{v&&(v.updateMatrixWorld(!0),p.current.setFromMatrixPosition(v.matrixWorld),v.matrixWorld.decompose(new Ae,g.current,new Ae),b.current.copy(v.scale))},[v]),!v)return null;const N=m?"translate":l,y=d.enabled!==w.current,k=N==="translate"&&y?d.translate:null,S=N==="rotate"&&y?d.rotate*Math.PI/180:null,T=N==="scale"&&y?d.scale:null,E=i?!0:N!=="rotate",A=i?!0:N!=="rotate",M=i?!0:N==="rotate";return r.jsx(Ou,{object:v,mode:N,size:i?.8:1,showX:E,showY:A,showZ:M,translationSnap:k??void 0,rotationSnap:S??void 0,scaleSnap:T??void 0,onMouseDown:()=>{x.current=!0,wr.active=!0,a(!1),v.updateMatrixWorld(!0),p.current.setFromMatrixPosition(v.matrixWorld),v.matrixWorld.decompose(new Ae,g.current,new Ae),b.current.copy(v.scale)},onMouseUp:()=>{x.current=!1,wr.active=!1,wr.justEndedAt=Date.now(),a(!0)},onObjectChange:()=>{if(x.current){if(v.updateMatrixWorld(!0),N==="translate"){const R=new Ae().setFromMatrixPosition(v.matrixWorld),_=R.clone().sub(p.current);if(_.lengthSq()<1e-10)return;s(_),p.current.copy(R)}else if(N==="rotate")v.rotation.order="YXZ",n(v.rotation.clone());else if(N==="scale"){if(u){const R=b.current,_=v.scale,F=R.x!==0?_.x/R.x:1,C=R.y!==0?_.y/R.y:1,P=R.z!==0?_.z/R.z:1,U=Math.abs(F-1),K=Math.abs(C-1),z=Math.abs(P-1);let O=1;U>=K&&U>=z?O=F:K>=z?O=C:O=P,v.scale.set(R.x*O,R.y*O,R.z*O)}o(v.scale.clone())}}}})}const nn="ws://127.0.0.1:5180",ra=350;class Bp{state={status:"disconnected",rootKind:"unknown",root:null,lastUpdate:0};listeners=new Set;ws=null;reconnectTimer=null;disconnectTimer=null;url=nn;activeSubscribers=0;subscribe=t=>(this.listeners.add(t),()=>this.listeners.delete(t));getSnapshot=()=>this.state;setState(t){this.state={...this.state,...t};for(const i of this.listeners)i()}acquire(t=nn){this.activeSubscribers+=1,this.disconnectTimer!=null&&(window.clearTimeout(this.disconnectTimer),this.disconnectTimer=null,console.debug("[world-editor:ws:acquire] cancelled pending grace-period disconnect")),console.debug("[world-editor:ws:acquire] subscribers=%d url=%s",this.activeSubscribers,t),this.connect(t)}release(){if(this.activeSubscribers<=0){this.activeSubscribers=0;return}this.activeSubscribers-=1,console.debug("[world-editor:ws:release] subscribers=%d",this.activeSubscribers),this.activeSubscribers===0&&(this.disconnectTimer!=null&&window.clearTimeout(this.disconnectTimer),console.info("[world-editor:ws:release] last subscriber gone — disconnecting in %dms (grace)",ra),this.disconnectTimer=window.setTimeout(()=>{if(this.disconnectTimer=null,this.activeSubscribers>0){console.debug("[world-editor:ws:release] grace window expired but subscribers=%d — keeping connection",this.activeSubscribers);return}console.info("[world-editor:ws:release] grace expired — closing WS"),this.disconnect(),this.setState({status:"disconnected"})},ra))}connect(t=nn){if(this.activeSubscribers<=0){console.warn("[world-editor:ws:connect] no subscribers — refusing to dial");return}if(this.ws&&(this.ws.readyState===WebSocket.OPEN||this.ws.readyState===WebSocket.CONNECTING)&&this.url===t){console.info("[world-editor:ws:connect] already %s on %s — no-op",this.ws.readyState===WebSocket.OPEN?"open":"connecting",t);return}this.disconnect(),this.url=t,console.info("[world-editor:ws:connect] dialing",t),this.setState({status:"connecting"});try{const i=new WebSocket(t);this.ws=i,i.onopen=()=>{console.info("[world-editor:ws:open]",t),this.activeSubscribers>0&&this.disconnectTimer!=null&&(window.clearTimeout(this.disconnectTimer),this.disconnectTimer=null,console.info("[world-editor:ws:open] cancelled stale grace-period disconnect (subs=%d)",this.activeSubscribers)),this.setState({status:"connected"})},i.onmessage=c=>{try{const s=JSON.parse(c.data);s.type==="snapshot"&&(console.debug("[world-editor:ws:snapshot] root_kind=%s nodes≈%d",s.scene_root_kind,Bi(s.tree)),this.setState({rootKind:s.scene_root_kind,root:s.tree,lastUpdate:Date.now()}))}catch(s){console.warn("[world-editor:ws:parse] failed:",s)}},i.onerror=c=>{console.warn("[world-editor:ws:error]",c),this.setState({status:"error"})}
237,i.onclose=c=>{console.info("[world-editor:ws:close] code=%s reason=%s clean=%s",c.code,c.reason,c.wasClean),this.ws=null,this.state.status!=="error"&&this.setState({status:"disconnected"}),this.scheduleReconnect()}}catch(i){console.warn("[world-editor:ws:connect] threw:",i),this.setState({status:"error"}),this.scheduleReconnect()}}scheduleReconnect(){if(this.reconnectTimer==null){if(this.activeSubscribers<=0){console.info("[world-editor:ws:reconnect] suppressed (no subscribers)");return}console.info("[world-editor:ws:reconnect] scheduled in 1500ms"),this.reconnectTimer=window.setTimeout(()=>{this.reconnectTimer=null,this.activeSubscribers>0&&this.connect(this.url)},1500)}}disconnect(){if(this.reconnectTimer!=null&&(window.clearTimeout(this.reconnectTimer),this.reconnectTimer=null),this.disconnectTimer!=null&&(window.clearTimeout(this.disconnectTimer),this.disconnectTimer=null),this.ws){try{this.ws.onopen=null,this.ws.onmessage=null,this.ws.onerror=null,this.ws.onclose=null,this.ws.close()}catch{}this.ws=null}}sendOutbound(t){if(!this.ws||this.ws.readyState!==WebSocket.OPEN)return console.warn("[world-editor:ws:send] dropped — readyState=%s",this.ws?.readyState??"no-ws"),!1;try{return this.ws.send(JSON.stringify(t)),console.debug("[world-editor:ws:send]",t),!0}catch(i){return console.warn("[world-editor:ws:send] failed:",i),!1}}}function Bi(e,t=0){if(!e)return t;if(t+=1,Array.isArray(e.children))for(const i of e.children)t=Bi(i,t);return t}const yt=new Bp;function Vi(e){const t=typeof e=="string"?{url:e}:e??{},i=t.url??nn,c=t.enabled??!0,s=f.useSyncExternalStore(yt.subscribe,yt.getSnapshot,yt.getSnapshot),n=f.useRef(i);n.current=i,f.useEffect(()=>{if(c)return yt.acquire(i),()=>{yt.release()}},[c,i]);const o=f.useCallback(d=>yt.sendOutbound(d),[]),a=f.useCallback(d=>yt.sendOutbound({type:"batch",ops:d}),[]),l=f.useCallback(()=>{yt.disconnect(),c&&yt.connect(n.current)},[c]);return{status:s.status,rootKind:s.rootKind,root:s.root,lastUpdate:s.lastUpdate,sendMutation:o,sendBatch:a,reconnect:l}}function Vp(e,t){const i=new Map,c=new Map;for(const h of e)for(let p=0;p<h.forward.length;p++){const g=h.forward[p],b=h.inverse[p]??null,x=g.node_id;if(typeof x!="number")continue;let w=i.get(x);if(!w){const v=t(x);w={...v?{nodeId:x,name:v.name,path:v.path,type:v.type}:{nodeId:x,name:c.get(x)?.name??`node-${x}`,path:c.get(x)?.path??"",type:c.get(x)?.type??"Node"},initial:{},final:{},propertyChanges:new Map,cloned:!1,deleted:!1},i.set(x,w)}zp(w,g,b)}const s=Array.from(i.values()).filter(h=>Wp(h)||h.cloned||h.deleted);let n=0,o=0,a=0,l=0,d=0,u=0;for(const h of s)h.deleted&&u++,h.cloned&&d++,Sr(h.initial.position,h.final.position)&&n++,zi(h.initial.rotation,h.final.rotation)&&o++,Sr(h.initial.scale,h.final.scale)&&a++,l+=h.propertyChanges.size;const m=s.map(Hp);return{changes:s,totals:{moved:n,rotated:o,scaled:a,propertyChanged:l,cloned:d,deleted:u},summaryLines:m}}function zp(e,t,i){switch(t.type){case"set_position":{const c=t,s=i;e.initial.position==null&&s&&(e.initial.position=s.position),e.final.position=c.position;return}case"set_rotation":{const c=t,s=i;e.initial.rotation==null&&s&&(e.initial.rotation=s.rotation),e.final.rotation=c.rotation;return}case"set_scale":{const c=t,s=i;e.initial.scale==null&&s&&(e.initial.scale=s.scale),e.final.scale=c.scale;return}case"set_property":{const c=t,s=i,n=e.propertyChanges.get(c.property);n?n.final=c.value:e.propertyChanges.set(c.property,{initial:s?.value??null,final:c.value});return}case"delete_node":{e.deleted=!0;return}case"clone_node":{e.cloned=!0;return}}}function Wp(e){return e.final.position!==void 0||e.final.rotation!==void 0||e.final.scale!==void 0||e.propertyChanges.size>0}function Sr(e,t){if(!e||!t)return e!==t;if(e.length!==t.length)return!0;for(let i=0;i<e.length;i++)if(Math.abs(e[i]-t[i])>1e-4)return!0;return!1}function zi(e,t){return e===void 0||t===void 0?e!==t:typeof e=="number"&&typeof t=="number"?Math.abs(e-t)>1e-4:Array.isArray(e)&&Array.isArray(t)?Sr(e,t):!0}function Jr(e){return e?"("+e.map(t=>t.toFixed(2)).join(", ")+")":"?"}function na(e){return e===void 0?"?":typeof e=="number"?(e*180/Math.PI).toFixed(1)+"°":"("+e.map(t=>(t*180/Math.PI).toFixed(1)+"°").join(", ")+")"}function Hp(e){const t=e.name+(e.path?` (${e.path})`:"");
237if(e.deleted)return`Deleted ${t}`;if(e.cloned)return`Duplicated ${t}`;const i=[];Sr(e.initial.position,e.final.position)&&i.push(`position ${Jr(e.initial.position)} → ${Jr(e.final.position)}`),zi(e.initial.rotation,e.final.rotation)&&i.push(`rotation ${na(e.initial.rotation)} → ${na(e.final.rotation)}`),Sr(e.initial.scale,e.final.scale)&&i.push(`scale ${Jr(e.initial.scale)} → ${Jr(e.final.scale)}`);for(const[c,{initial:s,final:n}]of e.propertyChanges)i.push(`${c} ${JSON.stringify(s)} → ${JSON.stringify(n)}`);return`${t}: ${i.join("; ")}`}function Kp(e,t){const i=[];i.push("I just used the World Editor in the Tesana Studio to make positioning changes to my game while it was running. Please update the GDScript so these changes are reflected the next time the game launches."),i.push(""),i.push("Changes I made:");for(const c of e.summaryLines)i.push(`  - ${c}`);return i.push(""),t.trim()&&(i.push("Additional context from me:"),i.push(t.trim()),i.push("")),i.push("Find the placement code (almost always in `scripts/*.gd` or in the script that spawns the relevant nodes in `_ready()`) and adjust the position/rotation/scale numbers there. Do NOT refactor the placement structure unless absolutely necessary — just change the numbers."),i.push("If the placement is procedurally derived from a seed (e.g. via `RandomNumberGenerator`), make sure the change is preserved across rebuilds (e.g. by writing the new value as a constant or by overriding the procedural result for that specific node). Do not blindly remove the procedural logic."),i.push('Names like "hospital_bed" or "Player" refer to Godot nodes by their `name` property — that is the most reliable identifier. The path in parentheses is the SceneTree path for disambiguation when there are multiple nodes with the same name.'),i.join(`
238`)}function Yp({open:e,onClose:t,diff:i}){const c=at(),[s,n]=f.useState(""),[o,a]=f.useState(!1),l=f.useMemo(()=>{const u=i.totals,m=[];return u.moved&&m.push(`${u.moved} move${u.moved===1?"":"s"}`),u.rotated&&m.push(`${u.rotated} rotation${u.rotated===1?"":"s"}`),u.scaled&&m.push(`${u.scaled} scale${u.scaled===1?"":"s"}`),u.cloned&&m.push(`${u.cloned} duplicate${u.cloned===1?"":"s"}`),u.deleted&&m.push(`${u.deleted} delete${u.deleted===1?"":"s"}`),u.propertyChanged&&m.push(`${u.propertyChanged} property change${u.propertyChanged===1?"":"s"}`),m.join(", ")||"no changes"},[i.totals]);if(!e)return null;const d=async()=>{if(!o){a(!0);try{const u=Kp(i,s);c.sendMessage(u,{source:"world-editor-save"}),De.clearHistory(),gr.success("Saving your World Editor changes — see the chat for progress."),t()}catch(u){ma(u,"Failed to save your changes. Please try again.")}finally{a(!1)}}};return r.jsx("div",{className:"fixed inset-0 z-[1100] flex items-center justify-center bg-black/70",onClick:t,children:r.jsxs("div",{className:"w-full max-w-lg overflow-hidden rounded-lg border border-border bg-card shadow-2xl",onClick:u=>u.stopPropagation(),children:[r.jsxs("header",{className:"border-b border-border px-5 py-4",children:[r.jsx("h2",{className:"text-base font-semibold text-foreground",children:"Save World Editor changes"}),r.jsxs("p",{className:"mt-1 text-xs text-muted-foreground",children:["We'll ask the AI to update your game's GDScript so these changes (",l,") survive a rebuild. Until then, restarting the game wipes them."]})]}),r.jsx("div",{className:"max-h-72 overflow-y-auto bg-foreground
238/[0.04] px-5 py-3 font-mono text-[11px] leading-relaxed",children:i.summaryLines.length===0?r.jsx("div",{className:"text-muted-foreground",children:"No changes to save yet — make some edits in the viewport first."}):i.summaryLines.map((u,m)=>r.jsx("div",{className:"whitespace-pre-wrap text-foreground",children:u},m))}),r.jsxs("div",{className:"px-5 py-4",children:[r.jsx("label",{className:"block text-xs font-medium text-foreground",children:"Anything else to tell the AI? (optional)"}),r.jsx("textarea",{value:s,onChange:u=>n(u.target.value),placeholder:"e.g. The player needs more space to wall-jump, so I moved the platform further from the wall.",rows:3,className:"mt-2 w-full resize-none rounded border border-border bg-background px-3 py-2 text-sm text-foreground outline-none focus:border-accent"})]}),r.jsxs("footer",{className:"flex items-center justify-end gap-2 border-t border-border bg-foreground/[0.02] px-5 py-3",children:[r.jsx("button",{type:"button",onClick:t,disabled:o,className:"rounded-md border border-border bg-background px-3 py-1.5 text-xs text-foreground hover:bg-foreground
238/10 disabled:opacity-50",children:"Cancel"}),r.jsx("button",{type:"button",onClick:()=>void d(),disabled:o||i.summaryLines.length===0,className:"rounded-md bg-accent px-4 py-1.5 text-xs font-medium text-accent-foreground hover:opacity-90 disabled:cursor-not-allowed disabled:opacity-50",children:o?"Sending…":"Save to game"})]})]})})}function Xp(){const e=As(),t=Vi({enabled:!1}),[i,c]=f.useState(!1),s=f.useMemo(()=>Vp(e.undoStack,a=>Jt(t.root,a)),[e.undoStack,t.root]),n=s.summaryLines.length>0,o=n?`Save (${s.summaryLines.length})`:"Save";return r.jsxs(r.Fragment,{children:[r.jsx("button",{type:"button",className:"toolbar-btn primary",disabled:!n,onClick:()=>c(!0),title:n?"Save these changes back to your game source via the AI agent.":"Make some edits first, then come back here to save.",children:o}),r.jsx(Yp,{open:i,onClose:()=>c(!1),diff:s})]})}const $p={translate:{letter:"T",label:"Move",key:"1"},rotate:{letter:"R",label:"Rotate",key:"2"},scale:{letter:"S",label:"Scale",key:"3"}};function qp({allowedModes:e}){const t=As(),i=e??["translate","rotate","scale"];return r.jsxs("div",{className:"toolbar",children:[r.jsx("div",{className:"toolbar-section",title:"Transform tool (1/2/3)",children:i.map(c=>{const s=$p[c],n=t.gizmoMode===c;return r.jsx("button",{className:`toolbar-btn ${n?"active":""}`,onClick:()=>De.setGizmoMode(c),title:`${s.label} (${s.key})`,children:s.label},c)})}),r.jsx("div",{className:"toolbar-divider"}),r.jsx("div",{className:"toolbar-section",children:r.jsx(Xp,{})}),r.jsx("div",{className:"toolbar-divider"}),r.jsxs("div",{className:"toolbar-section",children:[r.jsx("button",{className:`toolbar-btn ${t.lockAspect?"active":""}`,onClick:()=>De.setLockAspect(!t.lockAspect),title:"Lock aspect ratio: scaling stays uniform across all axes.",style:{display:t.gizmoMode==="scale"?void 0:"none"},children:t.lockAspect?"Aspect Locked":"Aspect Free"}),r.jsxs("button",{className:`toolbar-btn ${t.snap.enabled?"active":""}`,onClick:()=>De.setSnapEnabled(!t.snap.enabled),title:"Toggle snap (T). Hold Shift while dragging to temporarily invert.",children:["Snap ",t.snap.enabled?"On":"Off"]}),r.jsx(ss,{label:"◇",tip:`Move snap: ${t.snap.translate} units`,value:t.snap.translate,onCommit:c=>De.setSnapValue("translate",c),step:.1,min:.05,max:10}),r.jsx(ss,{label:"∠",tip:`Rotate snap: ${t.snap.rotate}°`,value:t.snap.rotate,onCommit:c=>De.setSnapValue("rotate",c),step:1,min:1,max:90,suffix:"°"}),r.jsx(ss,{label:"↕",tip:`Scale snap: ${t.snap.scale}×`,value:t.snap.scale,onCommit:c=>De.setSnapValue("scale",c),step:.05,min:.05,max:2,suffix:"×"})]})]})}function ss({label:e,tip:t,value:i,onCommit:c,step:s,min:n,max:o,suffix:a}){return r.jsxs("span",{className:"snap-field",title:t,children:[r.jsx("span",{className:"snap-label",children:e}),r.jsx("input",{type:"number",step:s,min:n,max:o,value:i,onChange:l=>{const d=Number(l.target.value);Number.isFinite(d)&&d>0&&c(d)}}),a&&r.jsx("span",{className:"snap-suffix",children:a})]})}function Qp({socketUrl:e}){const t=Vi(e),i=As(),c=t.rootKind==="3d",s=f.useMemo(()=>Li(t.root,c),[t.root,c]),n=at(),o=f.useRef(n.previewTab);f.useEffect(()=>{o.current=n.previewTab},[n.previewTab]),f.useEffect(()=>(Nl().catch(y=>{console.warn("[world-editor:keepalive] resume() failed -- engine may not be booted",y)}),()=>{if(o.current==="game"){console.info("[world-editor:keepalive] unmount → previewTab=game, viewport will resume");return}console.info("[world-editor:keepalive] unmount → suspend engine (next tab=%s)",o.current),Sl().catch(y=>{console.warn("[world-editor:keepalive] suspend() failed",y)})}),[]);const a=f.useRef({socket:t,editor:i,grouping:s,isThreeD:c});a.current={socket:t,editor:i,grouping:s,isThreeD:c};const l=()=>{const y=document.activeElement;if(!y)return!1;const k=y.tagName;return k==="INPUT"||k==="TEXTAREA"||k==="SELECT"||y.isContentEditable===!0},d=f.useCallback(y=>{const{editor:k,grouping:S,isThreeD:T,socket:E}=a.current,A=Mt(k.selectedIds,S.ownerByNodeId);if(A.length===0)return;const M=y.x,R=T?y.y:-y.y,_=y.z,F=[],C=[];for(const P of A)for(const U of[P.primaryNode,...P.attached])if(U.transform3d){const K=U.transform3d.position,z=[K[0]+M,K[1]+R,K[2]+_];F.push({type:"set_position",node_id:U.id,position:z}),C.push({type:"set_position",node_id:U.id,position:[...K]}),U.transform3d.position=z}else if(U.transform2d){const K=U.transform2d.position,z=[K[0]+M,K[1]+R];F.push({type:"set_position",node_id:U.id,position:z}),C.push({type:"set_position",node_id:U.id,position:[...K]}),U.transform2d.position=z}F.length!==0&&(E.sendBatch(F),De.pushUndo({forward:F,inverse:C,label:"translate"}))},[]),u=f.useCallback(y=>{const{editor:k,grouping:S,isThreeD:T,socket:E}=a.current,A=Mt(k.selectedIds,S.ownerByNodeId);if(A.length!==1)return;const M=A[0],R=M.primaryNode,_=[],F=[];if(T&&R.transform3d){const C=R.transform3d.rotation_euler_rad,P=[y.x,y.y,y.z],U=new Pt().setFromEuler(new Wr(C[0],C[1],C[2],"YXZ")),z=new Pt().setFromEuler(new Wr(y.x,y.y,y.z,"YXZ")).clone().multiply(U.clone().invert()),O=R.transform3d.position;_.push({type:"set_rotation",node_id:R.id,rotation:P}),F.push({type:"set_rotation",node_id:R.id,rotation:[...C]}),R.transform3d.rotation_euler_rad=P;
238for(const L of M.attached){if(!L.transform3d)continue;const j=L.transform3d.position,D=L.transform3d.rotation_euler_rad,I=new Pt().setFromEuler(new Wr(D[0],D[1],D[2],"YXZ")),B=z.clone().multiply(I),G=new Wr().setFromQuaternion(B,"YXZ"),q=[G.x,G.y,G.z],V=new Ae(j[0]-O[0],j[1]-O[1],j[2]-O[2]);V.applyQuaternion(z);const W=[O[0]+V.x,O[1]+V.y,O[2]+V.z];_.push({type:"set_rotation",node_id:L.id,rotation:q}),_.push({type:"set_position",node_id:L.id,position:W}),F.push({type:"set_rotation",node_id:L.id,rotation:[...D]}),F.push({type:"set_position",node_id:L.id,position:[...j]}),L.transform3d.rotation_euler_rad=q,L.transform3d.position=W}}else if(!T&&R.transform2d){const C=R.transform2d.rotation_rad,P=-y.z,U=P-C,K=Math.cos(U),z=Math.sin(U),O=R.transform2d.position;_.push({type:"set_rotation",node_id:R.id,rotation:P}),F.push({type:"set_rotation",node_id:R.id,rotation:C}),R.transform2d.rotation_rad=P;for(const L of M.attached){if(!L.transform2d)continue;const j=L.transform2d.position,D=L.transform2d.rotation_rad,I=D+U,B=j[0]-O[0],G=j[1]-O[1],q=[O[0]+(K*B-z*G),O[1]+(z*B+K*G)];_.push({type:"set_rotation",node_id:L.id,rotation:I}),_.push({type:"set_position",node_id:L.id,position:q}),F.push({type:"set_rotation",node_id:L.id,rotation:D}),F.push({type:"set_position",node_id:L.id,position:[...j]}),L.transform2d.rotation_rad=I,L.transform2d.position=q}}else return;_.length!==0&&(E.sendBatch(_),De.pushUndo({forward:_,inverse:F,label:"rotate (group)"}))},[]),m=f.useCallback(y=>{const{editor:k,grouping:S,isThreeD:T,socket:E}=a.current,A=Mt(k.selectedIds,S.ownerByNodeId);if(A.length!==1)return;const M=A[0],R=M.primaryNode,_=[],F=[];if(T&&R.transform3d){const C=R.transform3d.scale,P=[y.x,y.y,y.z],U=[C[0]!==0?y.x/C[0]:1,C[1]!==0?y.y/C[1]:1,C[2]!==0?y.z/C[2]:1],K=R.transform3d.position;_.push({type:"set_scale",node_id:R.id,scale:P}),F.push({type:"set_scale",node_id:R.id,scale:[...C]}),R.transform3d.scale=P;for(const z of M.attached){if(!z.transform3d)continue;const O=z.transform3d.position,L=z.transform3d.scale,j=[L[0]*U[0],L[1]*U[1],L[2]*U[2]],D=[K[0]+(O[0]-K[0])*U[0],K[1]+(O[1]-K[1])*U[1],K[2]+(O[2]-K[2])*U[2]];_.push({type:"set_scale",node_id:z.id,scale:j}),_.push({type:"set_position",node_id:z.id,position:D}),F.push({type:"set_scale",node_id:z.id,scale:[...L]}),F.push({type:"set_position",node_id:z.id,position:[...O]}),z.transform3d.scale=j,z.transform3d.position=D}}else if(!T&&R.transform2d){const C=R.transform2d.scale,P=[y.x,y.y],U=[C[0]!==0?y.x/C[0]:1,C[1]!==0?y.y/C[1]:1],K=R.transform2d.position;_.push({type:"set_scale",node_id:R.id,scale:P}),F.push({type:"set_scale",node_id:R.id,scale:[...C]}),R.transform2d.scale=P;for(const z of M.attached){if(!z.transform2d)continue;const O=z.transform2d.position,L=z.transform2d.scale,j=[L[0]*U[0],L[1]*U[1]],D=[K[0]+(O[0]-K[0])*U[0],K[1]+(O[1]-K[1])*U[1]];_.push({type:"set_scale",node_id:z.id,scale:j}),_.push({type:"set_position",node_id:z.id,position:D}),F.push({type:"set_scale",node_id:z.id,scale:[...L]}),F.push({type:"set_position",node_id:z.id,position:[...O]}),z.transform2d.scale=j,z.transform2d.position=D}}else return;_.length!==0&&(E.sendBatch(_),De.pushUndo({forward:_,inverse:F,label:"scale (group)"}))},[]),h=f.useCallback((y,k,S)=>{const{socket:T}=a.current,E=Jt(a.current.socket.root,y);if(!E)return;const A=[],M=[];k==="position"?E.transform3d?(M.push({type:"set_position",node_id:y,position:[...E.transform3d.position]}),A.push({type:"set_position",node_id:y,position:S}),E.transform3d.position=S):E.transform2d&&(M.push({type:"set_position",node_id:y,position:[...E.transform2d.position]}),A.push({type:"set_position",node_id:y,position:S}),E.transform2d.position=S):k==="rotation"?E.transform3d?(M.push({type:"set_rotation",node_id:y,rotation:[...E.transform3d.rotation_euler_rad]}),A.push({type:"set_rotation",node_id:y,rotation:S}
238),E.transform3d.rotation_euler_rad=S):E.transform2d&&(M.push({type:"set_rotation",node_id:y,rotation:E.transform2d.rotation_rad}),A.push({type:"set_rotation",node_id:y,rotation:S}),E.transform2d.rotation_rad=S):E.transform3d?(M.push({type:"set_scale",node_id:y,scale:[...E.transform3d.scale]}),A.push({type:"set_scale",node_id:y,scale:S}),E.transform3d.scale=S):E.transform2d&&(M.push({type:"set_scale",node_id:y,scale:[...E.transform2d.scale]}),A.push({type:"set_scale",node_id:y,scale:S}),E.transform2d.scale=S),A.length!==0&&(T.sendBatch(A),De.pushUndo({forward:A,inverse:M,label:`${k} (inspector)`}))},[]),p=f.useCallback((y,k,S)=>{const{socket:T}=a.current,E=Jt(a.current.socket.root,y);if(!E)return;const A=E[k],M=[{type:"set_property",node_id:y,property:k,value:S}],R=[{type:"set_property",node_id:y,property:k,value:A}];E[k]=S,T.sendBatch(M),De.pushUndo({forward:M,inverse:R,label:`set ${k}`})},[]),g=f.useCallback(()=>{const{editor:y,grouping:k}=a.current,S=Mt(y.selectedIds,k.ownerByNodeId);if(S.length===0)return;const T=[];for(const E of S)T.push({type:"clone_node",node_id:E.primaryNode.id});a.current.socket.sendBatch(T)},[]),b=f.useCallback(()=>{const{editor:y,grouping:k}=a.current,S=Mt(y.selectedIds,k.ownerByNodeId);if(S.length===0)return;const T=[];for(const E of S)for(const A of[E.primaryNode,...E.attached])T.pu
238sh({type:"delete_node",node_id:A.id});a.current.socket.sendBatch(T),De.setSelection([])},[]),x=f.useCallback((y,k)=>{if(y==null){De.setSelection([]);return}k?.shift||k?.meta?De.toggleSelection(y):De.selectOnly(y)},[]),w=f.useRef({token:0,position:new Ae,size:1}),v=f.useCallback(()=>{const{editor:y,grouping:k,isThreeD:S}=a.current,T=Mt(y.selectedIds,k.ownerByNodeId);if(T.length===0)return;const E=new Ae;let A=0;for(const R of T){const _=R.primaryNode.transform3d?.position,F=R.primaryNode.transform2d?.position;_?(E.x+=_[0],E.y+=_[1],E.z+=_[2],A++):F&&(E.x+=F[0],E.y+=-F[1],A++)}if(A===0)return;E.divideScalar(A);const M=S?3:100;w.current={token:w.current.token+1,position:E,size:M}},[]);f.useEffect(()=>{const y=k=>{if(l())return;const S=k.metaKey||k.ctrlKey;if(S&&k.key==="z"&&!k.shiftKey){k.preventDefault();const T=De.popUndo();T&&a.current.socket.sendBatch(T.inverse);return}if(S&&(k.key==="Z"||k.key==="z"&&k.shiftKey)){k.preventDefault();const T=De.popRedo();T&&a.current.socket.sendBatch(T.forward);return}if(S&&k.key==="d"){k.preventDefault(),g();return}if(k.key==="Delete"||k.key==="Backspace"){a.current.editor.selectedIds.length>0&&(k.preventDefault(),b());return}if(k.key==="1"){De.setGizmoMode("translate");return}if(k.key==="2"){De.setGizmoMode("rotate");return}if(k.key==="3"){De.setGizmoMode("scale");return}if(k.key==="t"||k.key==="T"){De.setSnapEnabled(!a.current.editor.snap.enabled);return}if(k.key==="f"||k.key==="F"){v();return}if(k.key==="Escape"){De.setSelection([]);return}};return window.addEventListener("keydown",y),()=>window.removeEventListener("keydown",y)},[g,b,v]),f.useEffect(()=>{if(i.selectedIds.length===0)return;const y=S=>Jt(t.root,S)!=null,k=i.selectedIds.filter(y);k.length!==i.selectedIds.length&&De.setSelection(k)},[t.root,i.selectedIds]);const N=f.useMemo(()=>{const y=Mt(i.selectedIds,s.ownerByNodeId);if(y.length===0)return["translate","rotate","scale"];let k=!0,S=!0;for(const E of y){const A=E.primaryNode.type;A==="OmniLight3D"&&(k=!1),(A==="OmniLight3D"||A==="SpotLight3D"||A==="DirectionalLight3D"||A==="Camera2D"||A==="Camera3D")&&(S=!1)}const T=["translate"];return k&&T.push("rotate"),S&&T.push("scale"),T},[i.selectedIds,s]);return f.useEffect(()=>{N.includes(i.gizmoMode)||De.setGizmoMode("translate")},[N,i.gizmoMode]),r.jsxs("div",{className:"app",children:[r.jsx(lp,{root:t.root,rootKind:t.rootKind,selectedIds:i.selectedIds,onSelect:(y,k)=>x(y,k),status:t.status,onReconnect:t.reconnect,lastUpdate:t.lastUpdate,onSetTransform:h,onSetProperty:p}),r.jsxs("div",{style:{position:"relative",overflow:"hidden"},children:[r.jsx(wp,{root:t.root,rootKind:t.rootKind,selectedIds:i.selectedIds,onSelect:(y,k)=>x(y,k),ownerByNodeId:s.ownerByNodeId,onApplyDelta:d,onApplyRotation:u,onApplyScale:m,gizmoMode:i.gizmoMode,snap:i.snap,lockAspect:i.lockAspect,focusRequest:w}),r.jsx(qp,{allowedModes:N})]})]})}function Mt(e,t){const i=new Map;for(const c of e){const s=t.get(c);s&&i.set(s.id,s)}return Array.from(i.values())}const Jp=1500,Zp=3e3,eg="addons/tesana_world_editor/scene_export.gd";function tg({gameId:e,engineGameName:t}){const i=_r(),c=mn({gameId:e,engineGameName:t}),s=f.useRef(!1),n=!!(c.record&&t&&c.record.engine_game_name!==t);f.useEffect(()=>{Ce&&(i.loading||c.loading||i.root&&t&&(c.linking||s.current||c.linked&&!n||(s.current=!0,c.link())))},[i.loading,i.root,c.loading,c.linked,c.linking,c.link,n,t]),f.useEffect(()=>{s.current=!1},[e,n]);const[o,a]=f.useState(null);f.useEffect(()=>{let b=!1;return ja().then(x=>{b||a(x)}),()=>{b=!0}},[]);const[l,d]=f.useState(null);f.useEffect(()=>{if(!o?.ok)return;let b=!1,x=null;const w=async()=>{try{const v=await _l();b||d(v)}catch(v){console.warn("[world-editor] embeddedStatus failed",v)}b||(x=setTimeout(w,Jp))};return w(),()=>{b=!0,x&&clearTimeout(x)}},[o?.ok]);const[u,m]=f.useState(null),h=f.useCallback(async()=>{if(Ce)try{const{invoke:b}=await Ye(async()=>{const{invoke:x}=await import("./core-DhEqZVGG.js");return{invoke:x}},[]);await b("read_local_file",{gameId:String(e),path:eg}),m(!0)}catch{m(!1)}},[e]);f.useEffect(()=>{if(!c.linked||n)return;h();const b=setInterval(()=>{u||h()},Zp);return()=>clearInterval(b)}
238,[c.linked,n,h,u]);const p=c.record?.local_path??null;if(!Ce)return r.jsx(sa,{title:"World Editor is a desktop feature",body:"The World Editor needs the embedded Godot runtime that ships with the Tesana desktop app. Open this game on your Mac to use it."});if(o&&!o.ok)return r.jsx(sa,{title:"World Editor isn't available on this device",body:o.reason?`${o.reason}. Currently supported on macOS Apple Silicon; Windows is coming next.`:"Currently supported on macOS Apple Silicon; Windows is coming next."});if(i.loading||c.loading)return r.jsx(Zr,{children:"Setting up local mirror…"});if(!i.root)return r.jsx(Ts,{onComplete:()=>i.refresh()});if(!c.linked||n)return r.jsxs(Zr,{children:[c.linking?"Creating local mirror…":"Preparing local mirror…",c.error?r.jsxs("span",{className:"ml-2 text-rose-400",children:["— ",c.error]}):null]});if(u===null)return r.jsx(Zr,{children:"Checking World Editor…"});if(!u)return r.jsx(ng,{});if(!l)return r.jsx(Zr,{children:"Checking engine…"});const g=l.running&&l.project!=null&&p!=null&&!l.project.startsWith(p);return!l.running||g?r.jsx(rg,{}):r.jsx("div",{className:"world-editor-root",children:r.jsx(Qp,{})})}function rg(){const e=at();return r.jsx("div",{className:"flex h-full items-center justify-center bg-background px-8 text-center",children:r.jsxs("div",{className:"max-w-md rounded-lg border border-border bg-card p-6",children:[r.jsx(H,{icon:["far","gamepad-modern"],className:"text-3xl text-muted-foreground"}),r.jsx("h2",{className:"mt-3 text-base font-medium text-foreground",children:"Open the Game tab and start playing"}),r.jsx("p",{className:"mt-2 text-sm text-muted-foreground",children:"The World Editor mirrors your game's live scene. Open the Game tab and play to the moment you want to edit (e.g. past the main menu, into the level), then come back here to start tweaking positions and props in real time."}),r.jsx("div",{className:"mt-5 flex justify-center",children:r.jsx("button",{type:"button",onClick:()=>e.setPreviewTab("game"),className:"rounded-md bg-accent px-4 py-2 text-sm font-medium text-accent-foreground hover:opacity-90",children:"Open Game tab"})})]})})}function ng(){const e=at(),[t,i]=f.useState(!1),c=f.useCallback(()=>{t||(i(!0),e.sendMessage("Please trigger a quick rebuild — the World Editor needs to be added to this game. Don't change any gameplay code; the engine's build pipeline will add the World Editor autoload automatically during the build. Just kick off a rebuild and exit. No need to plan or write any code.",{source:"world-editor-install"}),gr.info("Installing World Editor — see chat for build progress. The editor will open here automatically once the build completes."))},[e,t]);return r.jsx("div",{className:"flex h-full items-center justify-center bg-background px-8 text-center",children:r.jsxs("div",{className:"max-w-md rounded-lg border border-border bg-card p-6",children:[r.jsx(H,{icon:["far","earth-americas"],className:"text-3xl text-muted-foreground"}),r.jsx("h2",{className:"mt-3 text-base font-medium text-foreground",children:"Install the World Editor in this game"}),r.jsx("p",{className:"mt-2 text-sm text-muted-foreground",children:"This game was built before the World Editor was available. One quick rebuild adds it — your gameplay code won't be touched, just the build pipeline will include the editor's hooks. The editor will open automatically when the build is done."}),r.jsx("div",{className:"mt-5 flex justify-center",children:r.jsx("button",{type:"button",onClick:c,disabled:t,className:"rounded-md bg-accent px-4 py-2 text-sm font-medium text-accent-foreground hover:opacity-90 disabled:cursor-not-allowed disabled:opacity-50",children:t?"Rebuilding…":"Install (rebuilds your game)"})})]})})}function sa({title:e,body:t}){return r.jsx("div",{className:"flex h-full items-center justify-center bg-background px-8 text-center",children:r.jsxs("div",{className:"max-w-md rounded-lg border border-border bg-card p-6",children:[r.jsx(H,{icon:["far","earth-americas"],className:"text-3xl text-muted-foreground"}),r.jsx("h2",{className:"mt-3 text-base font-medium text-foreground",children:e}),r.jsx("p",{className:"mt-2 text-sm text-muted-foreground",children:t})]})})}function Zr({children:e,tone:t}){const i=t==="error"?"text-rose-300":"text-muted-foreground";return r.jsx("div",{className:"flex h-full items-center justify-center bg-background",children:r.jsx("div",{className:`text-sm ${i} px-8 text-center`,children:e})})}function sg({onShare:e,onPublish:t,playingNow:i=0}){const{t:c}=Ee("studio"),s=at(),n=s.currentGame,o=r.jsxs("span",{className:"flex min-w-0 items-center gap-2",children:[r.jsx("span",{className:"truncate",children:n?.name??c("studio.untitled","New Game")}),r.jsx(vd,{count:i,className:"text-xs font-normal text-muted-foreground"})]}),a=og(n,c);return r.jsxs("header",{className:"flex h-[62px] shrink-0 items-center justify-between gap-3 bg-background px-4",children:[r.jsx("div",{className:"min-w-0 flex-1",children:r.jsx(fi,{game:n,usage:s.usage,onShare:e,onPublish:t,renderAs:"chatNavTrigger",titleNode:o,subtitle:a})}),r.jsxs("div",{className:"flex items-center gap-1",children:[n?.id?r.jsx(Ke,{content:c("studio.history","Version history"),position:"bottom",delay:200,children:r.jsx("button",{type:"button",onClick:()=>s.setShowTimeline(!s.showTimeline),className:me("flex h-8 w-8 cursor-pointer items-center justify-center rounded-md text-[13px] transition-colors",s.showTimeline?"bg-foreground
238/10 text-foreground":"text-muted-foreground hover:bg-foreground/5 hover:text-foreground"),"aria-label":c("studio.history","Version history"),"aria-pressed":s.showTimeline,children:r.jsx(H,{icon:["far","clock"]})})}):null,r.jsx(Ke,{content:c("studio.collapseChat","Collapse chat"),position:"bottom",delay:200,children:r.jsx("button",{type:"button",onClick:()=>s.setChatCollapsed(!0),className:"flex h-8 w-8 cursor-pointer items-center justify-center rounded-md text-[13px] text-muted-foreground transition-colors hover:bg-foreground/5 hover:text-foreground","aria-label":c("studio.collapseChat","Collapse chat"),children:r.jsx(H,{icon:["far","arrow-left-to-line"]})})})]})]})}function og(e,t){if(!e)return"";const i=ag(e);if(!i)return t("studio.editingLatest",{defaultValue:"Editing latest version"});const c=Math.floor((Date.now()-i)/1e3);if(c<60)return t("studio.editingNow",{defaultValue:"Editing now"});const s=[[31536e3,"year"],[2592e3,"month"],[86400,"day"],[3600,"hour"],[60,"minute"]];for(const[n,o]of s){const a=Math.floor(c/n);if(a>=1)return t(`studio.editingAgo.${o}`,{count:a,defaultValue:`Editing latest version (${a} ${o}${a!==1?"s":""} ago)`})}return t("studio.editingLatest",{defaultValue:"Editing latest version"})}function ag(e){const t=[e.last_session_at,e.edited_at,e.updated_at];for(const i of t)if(i){const c=Date.parse(i);if(!Number.isNaN(c))return c}return null}function ig({gameOrgId:e,orgName:t}){const{t:i}=Ee("company"),c=cl(),{data:s}=yd();if(!c||c.id!==e||!s||s.policies.allow_external_collaborators)return null;const n=s.email_domains.map(o=>`@${o}`).join(", ");return r.jsx("p",{className:"mt-1.5 text-[11px] leading-4 text-muted-foreground",children:i("collaborators.orgOnly",{org:t,domains:n})})}function lg({game:e,externalOpen:t,onOpenChange:i,collaborationStatus:c}){const[s,n]=f.useState(!1),[o,a]=f.useState(""),[l,d]=f.useState(!1),[u,m]=f.useState(null),h=f.useRef(null),p=er(),{user:g}=Ut(),{t:b}=Ee("studio"),x=t??s,w=f.useCallback(C=>{n(C),i?.(C)},[i]);f.useEffect(()=>{if(!x)return;const C=U=>{h.current&&!h.current.contains(U.target)&&w(!1)},P=U=>{U.key==="Escape"&&w(!1)};return document.addEventListener("mousedown",C),document.addEventListener("keydown",P),()=>{document.removeEventListener("mousedown",C),document.removeEventListener("keydown",P)}},[x,w]);const v=c??null,{data:N}=mt({queryKey:["invite-link",e?.id],queryFn:()=>Br.getInviteLink(e.id),enabled:x&&!!e?.id&&v?.is_owner===!0,staleTime:3e4}),y=Qt({mutationFn:C=>Br.invite(e.id,C),onSuccess:()=>{a(""),m(null),p.invalidateQueries({queryKey:["collaboration-status",e?.id]})},onError:C=>{m(C.response?.data?.error||b("collaborate.errorSendInvite"))}}),k=Qt({mutationFn:C=>Br.removeCollaborator(e.id,C),onSuccess:()=>{p.invalidateQueries({queryKey:["collaboration-status",e?.id]})}}),S=Qt({mutationFn:C=>Br.toggleInviteLink(e.id,C),onSuccess:()=>{p.invalidateQueries({queryKey:["invite-link",e?.id]})}}),T=f.useCallback(()=>{const C=o.trim().toLowerCase();if(C){if(!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(C)){m(b("collaborate.errorInvalidEmail"));return}y.mutate(C)}},[o,y]),E=f.useCallback(()=>{N?.url&&(navigator.clipboard.writeText(N.url),d(!0),setTimeout(()=>d(!1),2e3))},[N?.url]),A=v?.is_owner??e?.user===g?.username,M=v?.collaborators??[],R=v?.pending_invitations??[],_=1+M.length,F=M.filter(C=>C.is_online);return e?r.jsxs("div",{ref:h,className:"hidden md:block relative",children:[r.jsx("div",{className:"flex items-center",children:r.jsxs("div",{className:"flex items-center -space-x-1.5",children:[r.jsx(Ke,{content:b("collaborate.tooltipYou"),position:"bottom",delay:200,children:r.jsx("div",{className:"w-8 h-8 rounded-full border-2 border-background overflow-hidden shrink-0 z-10",children:g?.profile_picture?r.jsx("img",{src:g.profile_picture,alt:"",className:"w-full h-full object-cover"}):r.jsx("div",{className:"w-full h-full bg-accent/20 flex items-center justify-center text-accent text-xs font-medium",children:g?.username?.[0]?.toUpperCase()||"?"})})}),F.filter(C=>C.user.id!==g?.id).slice(0,3).map((C,P)=>r.jsx(Ke,{content:C.user.username,position:"bottom",delay:200,children:r.jsx("div",{className:"w-8 h-8 rounded-full border-2 border-background overflow-hidden shrink-0",style:{zIndex:9-P},title:C.user.username,children:C.user.profile_picture?r.jsx("img",{src:C.user.profile_picture,alt:"",className:"w-full h-full object-cover"}):r.jsx("div",{className:"w-full h-full bg-blue-500/20 flex items-center justify-center text-blue-400 text-xs font-medium",children:C.user.username[0]?.toUpperCase()})})},C.id)),r.jsxs("button",{onClick:()=>w(!x),className:me("flex items-center gap-1.5 h-8 pl-2.5 pr-2 roun
238ded-full text-sm transition-all cursor-pointer border-1 border-background","bg-foreground/6 text-muted-foreground hover:bg-foreground/10 hover:text-foreground"),children:[r.jsx(H,{icon:["far","user-plus"],className:"text-xs"}),r.jsx("span",{children:b("collaborate.invite")}),M.length>0&&r.jsx("span",{className:"text-[11px] bg-accent/15 text-accent min-w-[18px] h-[18px] px-1 rounded-full flex items-center justify-center font-medium",children:_})]})]})}),r.jsxs("div",{className:me("absolute top-full right-0 mt-2 w-[340px] rounded-md border border-border bg-card shadow-xl z-50 transition-all duration-150 origin-top-right",x?"scale-100 opacity-100":"scale-95 opacity-0 pointer-events-none"),children:[r.jsx("div",{className:"px-4 pt-3 pb-2.5 border-b border-border",children:r.jsx("h3",{className:"text-sm font-medium text-foreground",children:b("collaborate.title")})}),A&&r.jsxs("div",{className:"px-4 py-3 border-b border-border",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("input",{type:"email",value:o,onChange:C=>{a(C.target.value),m(null)},onKeyDown:C=>C.key==="Enter"&&T(),placeholder:b("collaborate.placeholder"),className:"flex-1 h-8 text-sm border border-border rounded-sm px-3 bg-foreground
238/5 text-foreground placeholder:text-muted-foreground/50 outline-none focus:border-foreground transition-all"}),r.jsx("button",{onClick:T,disabled:y.isPending||!o.trim(),className:"h-8 px-3 text-sm rounded-sm bg-foreground text-background hover:opacity-80 transition-all cursor-pointer disabled:opacity-30 font-medium",children:y.isPending?r.jsx(H,{icon:["far","spinner-third"],className:"animate-spin text-xs"}):b("collaborate.invite")})]}),u&&r.jsx("p",{className:"text-xs text-red-400 mt-1.5",children:u}),e.organization&&r.jsx(ig,{gameOrgId:e.organization.id,orgName:e.organization.name})]}),r.jsxs("div",{className:"px-4 py-3 border-b border-border",children:[r.jsx("p",{className:"text-xs text-muted-foreground mb-2",children:b("collaborate.projectAccess")}),r.jsxs("div",{className:"flex items-center gap-3 py-1.5",children:[r.jsxs("div",{className:"relative",children:[v?.owner?.profile_picture?r.jsx("img",{src:v.owner.profile_picture,alt:"",className:"w-8 h-8 rounded-full object-cover"}):r.jsx("div",{className:"w-8 h-8 rounded-full bg-accent/20 flex items-center justify-center text-accent text-xs font-medium",children:(v?.owner?.username||e.user)?.[0]?.toUpperCase()}),v?.owner_is_online&&r.jsx("span",{className:"absolute -bottom-0.5 -right-0.5 w-2.5 h-2.5 bg-green-500 rounded-full border-2 border-card"})]}),r.jsx("div",{className:"flex-1 min-w-0",children:r.jsxs("p",{className:"text-sm text-foreground truncate",children:[v?.owner?.username||e.user,A&&r.jsxs("span",{className:"text-muted-foreground",children:[" ",b("collaborate.you")]})]})}),r.jsx("span",{className:"text-xs text-muted-foreground",children:b("collaborate.owner")})]}),M.map(C=>r.jsxs("div",{className:"flex items-center gap-3 py-1.5",children:[r.jsxs("div",{className:"relative",children:[C.user.profile_picture?r.jsx("img",{src:C.user.profile_picture,alt:"",className:"w-8 h-8 rounded-full object-cover"}):r.jsx("div",{className:"w-8 h-8 rounded-full bg-blue-500/20 flex items-center justify-center text-blue-400 text-xs font-medium",children:C.user.username[0]?.toUpperCase()}),C.is_online&&r.jsx("span",{className:"absolute -bottom-0.5 -right-0.5 w-2.5 h-2.5 bg-green-500 rounded-full border-2 border-card"})]}),r.jsx("div",{className:"flex-1 min-w-0",children:r.jsxs("p",{className:"text-sm text-foreground truncate",children:[C.user.username,C.user.id===g?.id&&r.jsxs("span",{className:"text-muted-foreground",children:[" ",b("collaborate.you")]})]})}),r.jsx("span",{className:"text-xs text-muted-foreground capitalize",children:C.role}),A&&r.jsx("button",{onClick:()=>k.mutate(C.user.id),className:"text-muted-foreground/50 hover:text-red-400 transition-colors cursor-pointer p-1",children:r.jsx(H,{icon:["far","xmark"],className:"text-xs"})})]},C.id)),R.map(C=>r.jsxs("div",{className:"flex items-center gap-3 py-1.5",children:[r.jsx("div",{className:"w-8 h-8 rounded-full bg-foreground
238/5 flex items-center justify-center text-muted-foreground/50",children:r.jsx(H,{icon:["far","envelope"],className:"text-xs"})}),r.jsx("div",{className:"flex-1 min-w-0",children:r.jsx("p",{className:"text-sm text-muted-foreground truncate",children:C.email})}),r.jsx("span",{className:"text-[11px] text-yellow-400/80 bg-yellow-400/10 px-1.5 py-0.5 rounded",children:b("collaborate.pending")})]},C.id))]}),A&&r.jsxs("div",{className:"px-4 py-3 flex flex-col gap-3",children:[r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(H,{icon:["far","link"],className:"text-xs text-muted-foreground"}),r.jsx("span",{className:"text-xs text-muted-foreground",children:b("collaborate.inviteLink")})]}),r.jsx("button",{onClick:()=>S.mutate(!N?.is_active),className:me("relative w-8 h-[18px] rounded-full transition-colors cursor-pointer",N?.is_active?"bg-accent":"bg-foreground/15"),children:r.jsx("span",{className:me("absolute top-[2px] w-[14px] h-[14px] rounded-full bg-white transition-transform",N?.is_active?"left-[16px]":"left-[2px]")})})]}),N?.is_active&&N.url&&r.jsxs("button",{onClick:E,className:me("w-full h-9 px-3 text-sm rounded-md transition-colors cursor-pointer flex items-center justify-center gap-2",l?"bg-green-500/10 text-green-400":"bg-foreground
238/6 text-muted-foreground hover:text-foreground hover:bg-foreground/10"),children:[r.jsx(H,{icon:["far",l?"check":"link"],className:"text-xs"}),b(l?"collaborate.linkCopied":"collaborate.copyLink")]})]})]})]}):null}function Wi({compact:e=!1}){const{t}=Ee("studio"),{user:i}=Ut(),c=at();if(!(!i?.subscription_tier||i.subscription_tier==="free")||i?.organization?.billing_managed)return null;const n=t("studio.upgrade","Upgrade");return r.jsxs("button",{type:"button",onClick:()=>{c.setUpgradeModalContext(tt.studioNavUpgrade),c.setShowUpgradeModal(!0)},className:me("flex h-9 cursor-pointer items-center justify-center gap-2 rounded-md bg-accent text-sm font-medium text-accent-foreground transition-opacity hover:opacity-90",e?"w-9":"px-3"),"aria-label":n,title:e?n:void 0,children:[r.jsx(H,{icon:["far","bolt"],className:"text-sm"}),e?null:n]})}const cg=[{id:"game",labelKey:"studio.tabGame",defaultLabel:"Game",icon:"gamepad-modern"},{id:"assets",labelKey:"studio.tabAssets",defaultLabel:"Assets",icon:"cube"},{id:"animations",labelKey:"studio.tabAnimations",defaultLabel:"Animations",icon:"person-running",library:!0},{id:"vfx",labelKey:"studio.tabVFX",defaultLabel:"VFX",icon:"fire",library:!0},{id:"addons",labelKey:"studio.tabAddons",defaultLabel:"Add-ons",icon:"puzzle-piece",library:!0},{id:"services",labelKey:"studio.tabServices",defaultLabel:"Services",icon:"sparkles",iconStyle:"far"},{id:"code",labelKey:"studio.tabCode",defaultLabel:"Code",icon:"code-simple"}],dg=cg.filter(e=>!e.library);function ug({onShare:e,showPublishPopover:t,onPublishOpenChange:i}){const{t:c}=Ee("studio"),s=at();Da(),s.currentGame;const n=s.chatCollapsed;return r.jsxs("header",{className:`tesana-fs-hide flex h-[62px] shrink-0 items-center justify-between gap-3 bg-background ${n?"pl-3":""} pr-4`,children:[r.jsxs("div",{className:"flex items-center gap-3",children:[n?r.jsx(Ke,{content:c("studio.openChat","Open chat"),position:"bottom",delay:200,children:r.jsx("button",{type:"button",onClick:()=>s.setChatCollapsed(!1),className:"flex h-8 w-8 cursor-pointer items-center justify-center rounded-md text-[13px] text-muted-foreground transition-colors hover:bg-foreground
238/5 hover:text-foreground","aria-label":c("studio.openChat","Open chat"),children:r.jsx(H,{icon:["far","arrow-right-from-line"]})})}):null,s.showPreview?r.jsx("nav",{className:"flex items-center gap-1 justify-between","aria-label":c("studio.previewTabs","Preview tabs"),children:dg.map(o=>{const a=s.previewTab===o.id,l=c(o.labelKey,o.defaultLabel),d=o.id==="game"&&s.isGenerating;return r.jsx(Ke,{content:a?null:l,position:"bottom",delay:200,children:r.jsxs("button",{type:"button",onClick:()=>s.setPreviewTab(o.id),className:me("group relative flex h-8 cursor-pointer items-center justify-center rounded-md text-sm font-medium overflow-hidden","transition-all duration-200 ease-out",a?"bg-accent/10 text-accent w-[132px]":"bg-foreground/[0.04] text-muted-foreground hover:bg-foreground/[0.09] hover:text-foreground w-[32px]"),"aria-pressed":a,"aria-label":l,children:[r.jsx(H,{icon:[o.iconStyle??"far",o.icon],className:"shrink-0 text-sm"}),r.jsx("span",{className:me("overflow-hidden whitespace-nowrap transition-all duration-300 ease-out",a?"ml-1.5 max-w-[160px] opacity-100":"ml-0 max-w-0 opacity-0"),children:l}),d&&a?r.jsx("span",{className:"ml-1.5 h-1.5 w-1.5 shrink-0 animate-pulse rounded-full bg-accent"}):null,d&&!a?r.jsx("span",{className:"pointer-events-none absolute right-0.5 top-0.5 h-1.5 w-1.5 animate-pulse rounded-full bg-accent ring-2 ring-background","aria-hidden":!0}):null]})},o.id)})}):null,null]}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(Wi,{}),r.jsx(lg,{game:s.currentGame,collaborationStatus:s.collaborationStatus}),s.gameUrl?r.jsxs("button",{type:"button",onClick:e,disabled:!s.currentGame?.id,className:"flex h-9 cursor-pointer items-center justify-center gap-2 rounded-md bg-foreground
238/[0.06] px-3 text-sm text-muted-foreground transition-all hover:bg-foreground/10 hover:text-foreground disabled:cursor-not-allowed disabled:opacity-30",children:[r.jsx(H,{icon:["far","share-nodes"],className:"text-sm"}),c("studio.share")]}):null,r.jsx(pi,{game:s.currentGame,isGenerating:s.isGenerating,runMode:s.activeRunMode,externalOpen:t,onOpenChange:i})]})]})}const fg=53;function mg({activeGameId:e,activeGame:t}){const{t:i}=Ee("nav"),{isAuthenticated:c,user:s}=Ut(),{isLight:n}=Rt(),[o,a]=f.useState(!1),{data:l}=mt({queryKey:["user-usage"],queryFn:dl.getUsage,enabled:c,refetchInterval:3e4,staleTime:15e3}),d=va(),u=l?d??la(l):void 0;return mt({...ul(),enabled:c&&!!s&&s.subscription_tier!=="free"}),r.jsxs(r.Fragment,{children:[r.jsxs("aside",{"aria-label":"Studio navigation",className:"tesana-fs-hide hidden md:flex shrink-0 flex-col border-r border-border bg-background",style:{width:`${fg}px`},children:[r.jsx("div",{className:"flex justify-center pt-4",children:r.jsx(Ke,{content:i("sidebar.dashboard","Dashboard"),position:"right",delay:200,children:r.jsx(vt,{to:"/dashboard","aria-label":"Tesana dashboard",className:"flex h-6 w-6 items-center justify-center",children:r.jsx("img",{src:"/logos/tessala-icon-svg.svg",alt:"Tesana",className:me("h-6 w-6 object-contain",n?"invert-0":"invert")})})})}),r.jsxs("div",{className:"mt-8 flex flex-col gap-2 items-center",children:[r.jsx(Ke,{content:i("sidebar.dashboard","Dashboard"),position:"right",delay:200,children:r.jsx(vt,{to:"/dashboard","aria-label":i("sidebar.dashboard","Dashboard"),
238className:"w-9 h-9 flex items-center justify-center rounded-md transition-colors bg-foreground/0 hover:bg-foreground/6 text-muted-foreground hover:text-foreground",children:r.jsx(H,{icon:["far","home"],className:"text-[14px]"})})}),r.jsx(Ke,{content:i("sidebar.explore","Explore"),position:"right",delay:200,children:r.jsx(vt,{to:"/explore","aria-label":i("sidebar.explore","Explore"),className:"w-9 h-9 flex items-center justify-center rounded-md transition-colors bg-foreground/0 hover:bg-foreground/6 text-muted-foreground hover:text-foreground",children:r.jsx(H,{icon:["far","compass"],className:"text-[14px]"})})}),r.jsx(Ke,{content:i("sidebar.myGames","My Games"),position:"right",delay:200,children:r.jsx(vt,{to:"/my-games","aria-label":i("sidebar.myGames","My Games"),className:"w-9 h-9 flex items-center justify-center rounded-md transition-colors bg-foreground/0 hover:bg-foreground/6 text-muted-foreground hover:text-foreground",children:r.jsx(H,{icon:["far","gamepad-modern"],className:"text-[14px]"})})}),s?.username&&r.jsx(Ke,{content:i("sidebar.profile","Profile"),position:"right",delay:200,children:r.jsx(vt,{to:`/u/${s.username}`,"aria-label":i("sidebar.profile","Profile"),className:"w-9 h-9 flex items-center justify-center rounded-md transition-colors bg-foreground
238/0 hover:bg-foreground/6 text-muted-foreground hover:text-foreground",children:r.jsx(H,{icon:["far","user-circle"],className:"text-[14px]"})})})]}),r.jsx("div",{className:"mx-auto mt-4 mb-6.25 h-px w-5 bg-border"}),r.jsx(wd,{activeGameId:e,activeGame:t}),r.jsx("div",{className:"flex-1"}),r.jsx("div",{className:"flex justify-center pb-3",children:r.jsx(Ke,{content:i("sidebar.notifications","Notifications"),position:"right",delay:200,children:r.jsx(mc,{collapsed:!0})})}),r.jsx("div",{className:"flex justify-center pb-3",children:r.jsx(jd,{onOpenUpgradeModal:()=>a(!0)})}),r.jsx("div",{className:"flex justify-center pb-6",children:typeof u=="number"?r.jsx(Ke,{content:i("sidebar.getCreditsTooltip","Get more credits"),position:"right",delay:200,children:r.jsx("button",{type:"button",onClick:()=>a(!0),className:me("rounded text-[12px] font-medium cursor-pointer",u<0?"text-destructive hover:opacity-80":"text-amber-400 hover:text-amber-300"),children:fl(u)})}):r.jsx("span",{className:"text-[11px] text-muted-foreground",children:"—"})})]}),r.jsx(qa,{isOpen:o,onClose:()=>a(!1)})]})}function hg({visible:e,payload:t,designPhase:i,complexity:c,gameId:s,onPrimary:n,onDismiss:o}){const{t:a}=Ee("studio"),{isLight:l}=Rt(),d=f.useRef(!1);if(f.useEffect(()=>{e&&t&&!d.current&&(d.current=!0,At("Phase Modal Shown",{game_id:s,design_phase:i,complexity:c})),e||(d.current=!1)},[e,t,s,i,c]),!t)return null;const u=()=>{At("Phase Modal Cta Clicked",{game_id:s,design_phase:i,complexity:c,cta:"primary"});const h=t.headline||"Add the gameplay loop now.";n(h)},m=h=>{At("Phase Modal Dismissed",{game_id:s,design_phase:i,complexity:c,cta:h}),o(h)};return r.jsx(lt,{children:e&&r.jsxs(r.Fragment,{children:[r.jsx(Be.div,{initial:{opacity:0}
238,animate:{opacity:1},exit:{opacity:0},transition:{duration:.2},className:`fixed inset-0 z-[1000] ${l?"bg-black/50":"bg-black/60"}`,onClick:()=>m("backdrop")}),r.jsx(Be.div,{initial:{opacity:0,scale:.96,y:20},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.96,y:20},transition:{duration:.3,ease:[.16,1,.3,1]},className:"fixed left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 z-[1001] w-full max-w-md px-4",children:r.jsxs("div",{className:`relative rounded-lg p-6 ${l?"bg-white border border-gray-200 shadow-2xl shadow-black/10":"bg-card border border-border/60 shadow-2xl shadow-black/50"}`,children:[r.jsx("button",{onClick:()=>m("close"),"aria-label":a("phaseModal.close","Close"),className:"absolute top-3 right-3 w-8 h-8 flex items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-foreground/5 transition-colors cursor-pointer",children:r.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[r.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),r.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}),r.jsx("div",{className:"flex items-center gap-2 mb-3",children:r.jsx("span",{className:`text-[10px] uppercase tracking-wider px-2 py-0.5 rounded-full font-medium ${l?"bg-accent/15 text-accent":"bg-accent/20 text-accent"}`,children:a("phaseModal.gameplayLoopPill","Gameplay loop")})}),r.jsx("h2",{className:"text-xl font-medium text-foreground mb-2 pr-6",children:t.headline}),r.jsx("p",{className:"text-sm text-muted-foreground mb-6 leading-relaxed",children:t.body}),r.jsxs("div",{className:"flex flex-col gap-2",children:[r.jsx("button",{onClick:u,className:"w-full h-10 px-4 rounded-md bg-foreground text-background hover:opacity-80 transition-opacity cursor-pointer text-sm font-medium",children:t.primary_cta_label}),t.secondary_cta_label&&r.jsx("button",{onClick:()=>m("secondary"),className:"w-full h-10 px-4 rounded-md text-foreground hover:bg-foreground
238/5 transition-colors cursor-pointer text-sm",children:t.secondary_cta_label})]})]})})]})})}const pg=f.lazy(()=>Ye(()=>import("./PlayablePreview-9BS6jErK.js"),__vite__mapDeps([84,1,2,85,5,4,6,3,7,8,9,10])));function gg({messages:e,assets:t,isGenerating:i,isHydratingAssets:c,ensureHydratedAssets:s,projectTemplate:n,isLockedToUpgrade:o=!1,onApprove:a,onUpgrade:l,disabled:d=!1,onClose:u,variant:m,gameId:h,gameName:p}){const{t:g}=Ee("studio"),b=f.useMemo(()=>Ia(e),[e]),x=f.useMemo(()=>Ba(b),[b]),w=Va(b),v=f.useMemo(()=>za(x),[x]),N=f.useMemo(()=>Wa(t),[t]),[y,k]=f.useState(null),S=f.useMemo(()=>t.some(U=>U.type==="character"&&!!U.preview_url&&/\.(glb|gltf)(\?|$)/i.test(U.url||"")),[t]),T=f.useRef(!1);f.useEffect(()=>{T.current||t.length===0||(T.current=!0,s?.())},[t.length,s]);const E=f.useRef(!1);f.useEffect(()=>{E.current||(E.current=!0,ha({game_id:h,game_name:p,variant:`${m}_immersive`,has_plan_preview:!!x,asset_count:t.length,hero_type:N.type}))},[]);const A=f.useCallback((U,K)=>{pa({game_id:h,variant:`${m}_immersive`,interaction:U,asset_type:K.type})},[h,m]),M=f.useCallback(U=>{k(U),s?.()},[s]),R=f.useCallback(()=>{d||(ga({game_id:h,variant:`${m}_immersive`,locked:o}),o?l?.():a?.())},[d,o,l,a,h,m]);if(!b||!x)return null;const _=x.title||(N.poster?.name??g("planPreview.untitled",{defaultValue:"Your game"})),F=x.tagline??null,C=o?g("planView.upgradeToBuild",{defaultValue:"Build this game"}):w==="approved"?g("planView.alreadyApproved",{defaultValue:"Plan approved — generating"}):g("planView.approveAndBuild",{defaultValue:"Approve & Build"}),P=o?null:w==="approved"?"circle-check":"hammer";return r.jsxs("div",{className:"absolute inset-0 z-20 flex flex-col bg-background animate-in fade-in duration-200",children:[r.jsx("button",{type:"button",onClick:u,className:"absolute top-3 right-3 z-10 w-9 h-9 rounded-md bg-foreground
238/[0.06] hover:bg-foreground/10 text-muted-foreground hover:text-foreground flex items-center justify-center transition-colors cursor-pointer","aria-label":g("planView.close",{defaultValue:"Close"}),children:r.jsx(H,{icon:["far","xmark"],className:"text-sm"})}),r.jsxs("div",{className:"flex-1 min-h-0 flex flex-col lg:flex-row",children:[r.jsxs("div",{className:"lg:w-[32rem] shrink-0 flex flex-col overflow-y-auto px-8 pt-8 pb-8 border-b lg:border-b-0 lg:border-r border-border",children:[r.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[r.jsx(H,{icon:["far","sparkles"],className:"text-accent"}),r.jsx("span",{className:"text-muted-foreground",children:o?g("planPreview.lockedSubtitle",{defaultValue:"These are your real assets — upgrade to bring them to life."}):g("planPreview.immersiveSubtitle",{defaultValue:"Your game is ready to explore."})})]}),r.jsxs("div",{className:"mt-5 flex items-start gap-4",children:[N.poster&&r.jsx("button",{type:"button",onClick:()=>M(N.poster),className:"w-16 h-16 rounded-xl overflow-hidden border border-border shrink-0 cursor-zoom-in","aria-label":g("planPreview.openPoster",{defaultValue:"Open poster"}),children:r.jsx("img",{src:N.poster.url,alt:_,className:"w-full h-full object-cover",draggable:!1})}),r.jsxs("div",{className:"min-w-0",children:[r.jsx("h1",{className:"text-3xl font-semibold text-foreground leading-tight break-words",children:_}),F&&r.jsx("p",{className:"text-sm text-muted-foreground mt-1.5",children:F})]})]}),v.length>0&&r.jsx("div",{className:"mt-6",children:r.jsx(Ha,{fields:v})}),r.jsx("div",{className:"flex-1 min-h-6"}),r.jsxs("button",{type:"button",onClick:R,disabled:d||w==="approved",className:me("mt-6 w-full flex items-center justify-center gap-2 h-12 px-6 rounded-md text-base font-medium transition-all cursor-pointer","bg-foreground text-background hover:opacity-80 disabled:opacity-50 disabled:cursor-not-allowed"),children:[P&&r.jsx(H,{icon:["far",P],className:"text-sm"}),C]}),r.jsx("div",{className:"mt-3",children:r.jsx(Gc,{})})]}),r.jsxs("div",{className:"flex-1 min-h-0 flex flex-col gap-3 p-4 pt-16",children:[r.jsx("div",{className:"flex-1 min-h-0 rounded-xl overflow-hidden border border-border bg-[#070712]",children:S&&!i?r.jsx(f.Suspense,{fallback:r.jsx("div",{className:"w-full h-full bg-foreground
238/5 animate-pulse"}),children:r.jsx(pg,{assets:t,className:"relative w-full h-full"})}):r.jsx(Ka,{poster:N.poster,model:y?null:N.model,title:_,tagline:F,isGenerating:i,onOpenPoster:M,aspectClassName:"h-full w-full"})}),t.length>0&&r.jsxs("div",{className:"shrink-0",children:[r.jsx(Ic,{icon:"grid-2",children:g("planPreview.yourAssets",{defaultValue:"Your assets"})}),r.jsx("div",{className:"mt-2 max-h-40 overflow-y-auto pr-1",children:r.jsx(Bc,{assets:t,onSelect:M})})]})]})]}),r.jsx(Ya,{asset:y,onClose:()=>k(null),isHydrating:c,projectTemplate:n,onInteraction:A})]})}function xg({messages:e,assets:t,isGenerating:i,isHydratingAssets:c,ensureHydratedAssets:s,projectTemplate:n,isLockedToUpgrade:o=!1,onApprove:a,onUpgrade:l,disabled:d=!1,onClose:u,variant:m,gameId:h,gameName:p}){const{t:g}=Ee("studio"),{isLight:b}=Rt(),x=f.useMemo(()=>Ia(e),[e]),w=f.useMemo(()=>Ba(x),[x]),v=Va(x),N=(x?.content||"").trim(),y=f.useMemo(()=>Vc(t),[t]),k=f.useMemo(()=>za(w),[w]),S=f.useMemo(()=>Wa(t),[t]),T=f.useMemo(()=>zc(N),[N]),[E,A]=f.useState(null),M=f.useRef(!1);f.useEffect(()=>{x&&(M.current||t.length!==0&&(M.current=!0,s?.()))},[x,t.length,s]);const R=!!x&&!!w,_=f.useRef(!1);f.useEffect(()=>{R&&(_.current||(_.current=!0,ha({game_id:h,game_name:p,variant:m,has_plan_preview:!!w,asset_count:t.length,hero_type:S.type})))},[R]);const F=f.useCallback((L,j)=>{pa({game_id:h,variant:m,interaction:L,asset_type:j.type})},[h,m]),C=f.useCallback(L=>{A(L),s?.()},[s]),P=f.useCallback(()=>{if(!d)return ga({game_id:h,variant:m,locked:o}),o?l?.():a?.()},[d,o,l,a,h,m]);if(!R)return r.jsx(Xa,{messages:e,isLockedToUpgrade:o,onApprove:a,onUpgrade:l,disabled:d,onClose:u});const U=w?.title??null,K=w?.tagline??null,z=t.length===0&&i,O=y.slice(T.length);return r.jsxs("div",{className:"relative flex flex-col h-full overflow-hidden",children:[r.jsxs("div",{className:"flex items-center justify-between px-8 py-5 border-b border-border",children:[r.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[r.jsx("span",{className:me("w-9 h-9 rounded-md flex items-center justify-center shrink-0",b?"bg-foreground
238/8":"bg-foreground/6"),children:r.jsx(H,{icon:["far","list-check"],className:"text-base text-foreground"})}),r.jsxs("div",{className:"min-w-0",children:[r.jsx("h2",{className:"text-base font-medium text-foreground leading-tight truncate",children:g("planView.title",{defaultValue:"Your game plan"})}),r.jsx("p",{className:"text-xs text-muted-foreground truncate",children:o?g("planPreview.lockedSubtitle",{defaultValue:"These are your real assets — upgrade to bring them to life."}):g("planView.subtitle",{defaultValue:"Review the plan, tweak it in chat, then build."})})]})]}),u&&r.jsx("button",{onClick:u,className:"w-7 h-7 rounded-md text-muted-foreground hover:text-foreground hover:bg-foreground/6 flex items-center justify-center transition-colors cursor-pointer shrink-0","aria-label":g("planView.close",{defaultValue:"Close plan view"}),children:r.jsx(H,{icon:["far","xmark"],className:"text-sm"})})]}),r.jsx("div",{className:"flex-1 overflow-auto",children:r.jsxs("div",{className:"max-w-3xl mx-auto px-6 sm:px-8 py-8 pb-32 space-y-7",children:[r.jsx(Ka,{poster:S.poster,model:E?null:S.model,title:U,tagline:K,isGenerating:i,onOpenPoster:C,aspectClassName:"aspect-[16/9]",compact:!0}),k.length>0&&r.jsx(Ha,{fields:k}),T.length===0&&z&&r.jsx(Wc,{count:6}),T.map((L,j)=>r.jsxs("div",{className:"space-y-4",children:[r.jsx(Oa,{className:"markdown-prose-compact",children:L}),y[j]&&r.jsx(aa,{group:y[j],onSelect:C,moreLabel:g("planPreview.more",{defaultValue:"more"})})]},j)),O.length>0&&r.jsx("div",{className:"space-y-4",children:O.map(L=>r.jsx(aa,{group:L,onSelect:C,moreLabel:g("planPreview.more",{defaultValue:"more"})},L.type))})]})}),r.jsx(Hc,{isLockedToUpgrade:o,status:v,disabled:d,onClick:P}),r.jsx(Ya,{asset:E,onClose:()=>A(null),isHydrating:c,projectTemplate:n,onInteraction:F})]})}const oa=8;function aa({group:e,onSelect:t,moreLabel:i}){const[c,s]=f.useState(!1),n=e.assets.length>oa,o=c||!n?e.assets:e.assets.slice(0,oa-1),a=e.assets.length-o.length;return r.jsxs("div",{className:"rounded-xl border border-border bg-foreground
238/[0.02] p-4",children:[r.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[r.jsx("span",{className:"w-6 h-6 rounded-md flex items-center justify-center",style:{backgroundColor:`${e.color}1A`,color:e.color},children:r.jsx(H,{icon:["far",e.icon],className:"text-[11px]"})}),r.jsx("h4",{className:"text-xs font-medium text-foreground",children:e.label}),r.jsx("span",{className:"text-[11px] text-muted-foreground tabular-nums",children:e.count})]}),r.jsxs("div",{className:"grid grid-cols-4 sm:grid-cols-6 gap-2.5",children:[o.map(l=>r.jsx(Kc,{asset:l,onSelect:t},l.id)),!c&&a>0&&r.jsxs("button",{onClick:()=>s(!0),className:"aspect-square rounded-lg border border-dashed border-border bg-foreground/[0.02] hover:bg-foreground/[0.06] hover:border-foreground/25 transition-all cursor-pointer flex flex-col items-center justify-center text-muted-foreground hover:text-foreground",children:[r.jsxs("span",{className:"text-base font-semibold tabular-nums leading-none",children:["+",a]}),r.jsx("span",{className:"text-[10px] mt-0.5",children:i})]})]})]})}function ia(e){if(!e||e.length===0)return[];const t=[];for(const i of e)i.file_diff&&(i.tool_name!=="Write"&&i.tool_name!=="Edit"||t.push({entry:i,diff:i.file_diff}));return t}function bg(e){const t=e.replace(/\/$/,""),i=t.lastIndexOf("/");return i===-1?t:t.slice(i+1)}function sn(e){return`diff-section-${e.replace(/[^a-zA-Z0-9_-]/g,"_")}`}function vg(e,t){if(!t)return{};const i=e.findIndex(o=>o.message_type==="generation"&&o.session_id===t);if(i===-1)return{};const c=e[i];let s;for(let o=i+1;o<e.length;o++){const a=e[o];if(a.message_type==="summary"&&a.session_id===t){s=a;break}if(a.session_id&&a.session_id!==t)break}let n;for(let o=i-1;o>=0;o--){const a=e[o];if(a.role==="user"){n=a.content;break}}return{generation:c,summary:s,precedingPrompt:n}}function yg({diff:e,isFocused:t,gameId:i,sessionId:c,entryId:s}){const{t:n}=Ee("studio"),{theme:o}=Rt(),a=f.useMemo(()=>Ss(e.file_path),[e.file_path]),l=Lt(e.file_path),d=bg(e.file_path),[u,m]=f.useState(!0),h=!!e.body_deferred&&!e.binary&&!e.truncated,p=h&&!!i&&!!c&&!!s,[g,b]=f.useState(null),[x,w]=f.useState(!1);f.useEffect(()=>{if(!p||!u||g||x)return;let A=!1;return Ft.getActivityEntry(i,c,s).then(M=>{if(A)return;const R=M?.entry?.file_diff;R&&(R.before!==void 0||R.after!==void 0)?b(R):w(!0)}).catch(()=>{A||w(!0)}),()=>{A=!0}},[p,u,g,x,i,c,s]);const v=g??e,N=x||h&&!p,y=h&&!g&&!N,k=A=>{eh(A)},S=f.useMemo(()=>{const A=v.before??"",M=v.after??"";return Math.max(A?A.split(`
239`).length:0,M?M.split(`
240`).length:0)},[v.before,v.after]),T=Math.max(160,S*19+32),E=!v.binary&&!v.truncated&&(v.before!==void 0||v.after!==void 0);return r.jsxs("section",{id:sn(e.file_path),className:me("rounded-md border bg-card overflow-hidden transition-colors",t?"border-primary/40 ring-1 ring-primary/30":"border-border"),children:[r.jsxs("button",{type:"button",onClick:()=>m(A=>!A),"aria-expanded":u,"aria-controls":`${sn(e.file_path)}-body`,className:me("w-full flex items-center gap-2 px-3 h-10 bg-foreground
240/[0.015] hover:bg-foreground/[0.04] transition-colors text-left cursor-pointer",u&&"border-b border-border"),children:[l?r.jsx(H,{icon:["far",l.icon],style:{color:l.color},className:"text-xs flex-shrink-0"}):r.jsx(H,{icon:["far","file"],className:"text-xs text-muted-foreground/70 flex-shrink-0"}),r.jsxs("div",{className:"flex-1 min-w-0 flex items-baseline gap-2",children:[r.jsx("span",{className:"text-sm text-foreground truncate",title:e.file_path,children:d}),d!==e.file_path&&r.jsx("span",{className:"text-[11px] text-muted-foreground/60 truncate",children:e.file_path})]}),!e.binary&&r.jsxs(r.Fragment,{children:[e.additions>0&&r.jsxs("span",{className:"text-xs tabular-nums text-emerald-500 flex-shrink-0",children:["+",e.additions]}),e.deletions>0&&r.jsxs("span",{className:"text-xs tabular-nums text-destructive flex-shrink-0",children:["-",e.deletions]})]}),e.binary&&r.jsx("span",{className:"text-[10px] uppercase tracking-wider text-muted-foreground/70",children:n("detailsView.binary",{defaultValue:"binary"})}),e.truncated&&!e.binary&&r.jsx("span",{className:"text-[10px] uppercase tracking-wider text-amber-500/80",children:n("detailsView.truncated",{defaultValue:"truncated"})}),r.jsx(H,{icon:["far",u?"chevron-down":"chevron-up"],className:"text-xs text-muted-foreground/60 flex-shrink-0","aria-hidden":!0})]}),u&&y?r.jsxs("div",{className:"px-4 py-6 flex items-center justify-center gap-2",children:[r.jsx(H,{icon:["far","spinner-third"],className:"text-xs text-muted-foreground/70 animate-spin"}),r.jsx("p",{className:"text-sm text-muted-foreground",children:n("detailsView.loadingDiff",{defaultValue:"Loading this file’s changes…"})})]}):u&&E?r.jsx("div",{id:`${sn(e.file_path)}-body`,style:{height:T},children:r.jsx(Mi,{original:v.before??"",modified:v.after??"",originalLanguage:a,modifiedLanguage:a,theme:o==="dark"?"vs-dark":"vs",beforeMount:k,options:{readOnly:!0,renderSideBySide:!0,originalEditable:!1,minimap:{enabled:!1},fontSize:12,fontFamily:'"JetBrains Mono", "Fira Code", "SF Mono", Menlo, monospace',lineNumbers:"on",scrollBeyondLastLine:!1,renderLineHighlight:"none",folding:!1,automaticLayout:!0,scrollbar:{alwaysConsumeMouseWheel:!1},renderIndicators:!1}})}):u?r.jsx("div",{className:"px-4 py-6 text-center",children:r.jsx("p",{className:"text-sm text-muted-foreground",children:v.binary?n("detailsView.binaryPlaceholder",{defaultValue:"Binary content — diff omitted."}):N?n("detailsView.diffUnavailable",{defaultValue:"Could not load this file’s changes. The counts above are still accurate."}):n("detailsView.truncatedPlaceholder",{defaultValue:"File too large to render inline. Counts are approximate."})})}):null]})}function wg({diffs:e,focusedFile:t,onConsumeFocus:i,gameId:c,sessionId:s,partial:n}){const{t:o}=Ee("studio"),a=f.useRef(null);return f.useLayoutEffect(()=>{if(!t||a.current===t)return;a.current=t;const l=document.getElementById(sn(t));l&&l.scrollIntoView({behavior:"smooth",block:"start"}),i()},[t,i]),e.length===0?r.jsxs("div",{className:"mt-8 px-4 py-10 rounded-md border border-dashed border-border bg-foreground
240/[0.02] text-center",children:[r.jsx(H,{icon:["far","code"],className:"text-base text-muted-foreground/60 mb-3 block"}),r.jsx("p",{className:"text-sm text-muted-foreground",children:o("detailsView.noDiffs",{defaultValue:"No file changes captured for this generation."})})]}):r.jsxs("div",{className:"mt-6 space-y-4",children:[e.map(({entry:l,diff:d})=>r.jsx(yg,{diff:d,isFocused:a.current===d.file_path,gameId:c,sessionId:s,entryId:l.entry_id},l.entry_id||`${d.file_path}-${d.additions}-${d.deletions}`)),n&&r.jsx("p",{className:"pt-1 text-center text-xs text-muted-foreground",children:o("detailsView.diffsPartial",{defaultValue:"Showing changes from the activity loaded so far — load earlier activity on the Timeline tab to see the rest."})})]})}function jg({messages:e,targetSessionId:t,onClose:i}){const{t:c}=Ee("studio"),{detailsViewInitialTab:s,detailsViewFocusedFile:n,consumeDetailsViewFocusedFile:o}=ms(),[a,l]=f.useState(s),[d,u]=f.useState(null),m=f.useRef("");f.useEffect(()=>{const z=`${t}|${s}`;m.current!==z&&(m.current=z,l(s),u(null))},[t,s]);const{generation:h,summary:p,precedingPrompt:g}=f.useMemo(()=>vg(e,t),[e,t]),b=f.useMemo(()=>h?$l(h,p,g,c("detailsView.fallbackTitle",{defaultValue:"Generation details"})):c("detailsView.fallbackTitle",{defaultValue:"Generation details"}),[h,p,g,c]),{currentGame:x}=at(),w=x?.id??null,v=typeof h?.id=="number"?h.id:null,N=h?.session_id||t||null,[y,k]=f.useState({entries:[],settled:!1,hasMore:!1}),S=f.useCallback(z=>k(z),[]);f.useEffect(()=>{k({entries:[],settled:!1,hasMore:!1})}
240,[N]);const E=!!h?.metadata?.activity_log_truncated,[A,M]=f.useState(null),[R,_]=f.useState(null);f.useEffect(()=>{if(!(!!h&&E&&y.settled&&y.entries.length===0&&v!==null&&w!==null&&R!==v))return;let O=!1;return Ft.getMessage(w,v).then(L=>{O||(M(L?.metadata??null),_(v))}).catch(()=>{O||_(v)}),()=>{O=!0}},[h,E,v,w,R,y.settled,y.entries.length]);const F=f.useMemo(()=>{if(y.entries.length>0)return ia(y.entries);const z=A?.activity_log??h?.metadata?.activity_log;return ia(z)},[y.entries,A,h]);if(!h)return r.jsxs("div",{className:"flex flex-col h-full",children:[r.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b border-border",children:[r.jsx("p",{className:"text-sm text-muted-foreground",children:c("detailsView.empty",{defaultValue:"No details to show."})}),r.jsx("button",{onClick:i,className:"w-7 h-7 rounded-md text-muted-foreground hover:text-foreground hover:bg-foreground/6 flex items-center justify-center transition-colors cursor-pointer","aria-label":c("detailsView.close",{defaultValue:"Close details view"}),children:r.jsx(H,{icon:["far","xmark"],className:"text-sm"})})]}),r.jsx("div",{className:"flex-1 overflow-auto px-8 py-10",children:r.jsxs("div",{className:"max-w-3xl mx-auto",children:[r.jsx("div",{className:"h-7 w-48 bg-foreground
240/8 rounded animate-pulse mb-4"}),r.jsx("div",{className:"h-4 w-3/4 bg-foreground/6 rounded animate-pulse mb-2"}),r.jsx("div",{className:"h-4 w-2/3 bg-foreground/6 rounded animate-pulse mb-2"}),r.jsx("div",{className:"h-4 w-9/12 bg-foreground/6 rounded animate-pulse mb-2"}),r.jsx("div",{className:"h-4 w-1/2 bg-foreground/6 rounded animate-pulse"})]})})]});const C=A??h.metadata??{status:"complete",summary:"",steps:[],updated_at:h.timestamp},P=F.length>0,U=a==="changes"&&!P?"timeline":a,K=d?(C.subagents||{})[d]:void 0;return r.jsxs("div",{className:"flex flex-col h-full overflow-hidden",children:[r.jsxs("div",{className:"relative flex items-center justify-between lg:justify-center gap-3 px-6 py-3 border-b border-border",children:[r.jsxs("button",{onClick:i,className:"lg:absolute lg:left-6 flex items-center gap-2 text-sm text-muted-foreground hover:text-foreground transition-colors cursor-pointer","aria-label":c("detailsView.back",{defaultValue:"Back to latest"}),children:[r.jsx(H,{icon:["far","arrow-left"],className:"text-xs"}),r.jsx("span",{className:"hidden sm:flex",children:c("detailsView.back",{defaultValue:"Back to latest"})})]}),r.jsxs("div",{className:"flex items-center gap-1 rounded-md border border-border bg-card p-0.5",children:[r.jsx("button",{type:"button",onClick:()=>l("timeline"),className:me("px-3 h-7 text-xs rounded-sm transition-colors cursor-pointer",U==="timeline"?"bg-foreground
240/8 text-foreground":"text-muted-foreground hover:text-foreground"),children:c("detailsView.tabTimeline",{defaultValue:"Timeline"})}),r.jsxs("button",{type:"button",onClick:()=>P&&l("changes"),disabled:!P,"aria-disabled":!P,title:P?void 0:c("detailsView.changesEmpty",{defaultValue:"No file changes in this generation"}),className:me("px-3 h-7 text-xs rounded-sm transition-colors flex items-center gap-1.5",P?U==="changes"?"bg-foreground/8 text-foreground cursor-pointer":"text-muted-foreground hover:text-foreground cursor-pointer":"text-muted-foreground/40 cursor-not-allowed"),children:[c("detailsView.tabChanges",{defaultValue:"Changes"}),P&&r.jsx("span",{className:"text-[10px] tabular-nums px-1 py-px rounded bg-foreground/[0.06] text-muted-foreground/70",children:F.length})]})]}),r.jsx("button",{onClick:i,className:"lg:absolute lg:right-6 w-7 h-7 rounded-md text-muted-foreground hover:text-foreground hover:bg-foreground/6 flex items-center justify-center transition-colors cursor-pointer","aria-label":c("detailsView.close",{defaultValue:"Close details view"}),children:r.jsx(H,{icon:["far","xmark"],className:"text-sm"})})]}),r.jsx("div",{className:"flex-1 overflow-auto",children:r.jsxs("div",{className:"max-w-3xl mx-auto px-8 py-8",children:[!(U==="timeline"&&d)&&r.jsx("h2",{className:"text-base font-medium text-foreground leading-tight mb-2",children:b}),U==="timeline"&&d&&r.jsx(gi,{record:K,onBack:()=>u(null),backLabel:c("subagent.backToTimeline",{defaultValue:"Back to timeline"}),embedded:!0,gameId:w,sessionId:N,agentKey:d}),r.jsx("div",{className:U==="timeline"&&!d?void 0:"hidden",children:r.jsx(Ga,{metadata:C,isLast:!1,isGenerating:!1,messageTimestamp:h.timestamp,nextMessageType:p?.message_type??null,onOpenSubagent:z=>u(z),mode:"forward",gameId:w,sessionId:N,onEntriesChange:S})}),U==="changes"&&r.jsx(wg,{diffs:F,focusedFile:n,onConsumeFocus:o,gameId:w,sessionId:N,partial:y.hasMore})]})})]})}function kg({onClose:e}){const{t}=Ee("studio"),{previewBuild:i}=ms(),{currentGame:c}=Cl(),s=f.useRef(null),[n,o]=f.useState(!1),[a,l]=f.useState(null),d=f.useCallback(()=>{l(s.current?.playAuth()??null),o(!0)},[]),u=f.useCallback(h=>{if(o(!1),typeof h=="number"){s.current?.completeTopUp(!0,h);return}Yt.getWallet().then(p=>s.current?.completeTopUp(!0,p.balance)).catch(()=>s.current?.completeTopUp(!1))},[]),m=i.versionNumber?t("previewBuildView.headerWithVersion",{defaultValue:"Previewing version {{version}}",version:i.versionNumber}):t("previewBuildView.headerNoVersion",{defaultValue:"Previewing earlier build"});return r.jsxs("div",{className:"flex flex-col h-full overflow-hidden bg-background",children:[r.jsxs("div",{className:"flex items-center justify-between lg:justify-center gap-3 px-6 py-3 border-b border-border relative",children:[r.jsxs("button",{onClick:e,className:"lg:absolute lg:left-6 flex items-center gap-2 text-sm text-muted-foreground hover:text-foreground transition-colors cursor-pointer","aria-label":t("previewBuildView.back",{defaultValue:"Back to latest"}),children:[r.jsx(H,{icon:["far","arrow-left"],className:"text-xs"}),r.jsx("span",{className:"hidden sm:flex",children:t("previewBuildView.back",{defaultValue:"Back to latest"})})]}),r.jsxs("div",{className:"flex items-center gap-2 min-w-0 h-8.5",children:[r.jsx("span",{className:"w-2 h-2 rounded-full bg-amber-400 animate-pulse flex-shrink-0"}),r.jsx("p",{className:"text-sm text-foreground truncate",title:m,children:m})]}),r.jsx("button",{onClick:e,className:"lg:absolute lg:right-6 w-7 h-7 rounded-md text-muted-foreground hover:text-foreground hover:bg-foreground
240/6 flex items-center justify-center transition-colors cursor-pointer","aria-label":t("previewBuildView.close",{defaultValue:"Close preview"}),children:r.jsx(H,{icon:["far","xmark"],className:"text-sm"})})]}),r.jsxs("div",{className:"flex-1 relative bg-black",children:[i.status==="building"&&r.jsxs("div",{className:"absolute inset-0 flex flex-col items-center justify-center text-center px-8 gap-4",children:[r.jsx(H,{icon:["far","spinner-third"],className:"text-2xl text-muted-foreground/70 animate-spin"}),r.jsxs("div",{className:"space-y-1.5",children:[r.jsx("p",{className:"text-sm text-foreground",children:t("previewBuildView.buildingTitle",{defaultValue:"Building a temporary playable preview…"})}),r.jsx("p",{className:"text-xs text-muted-foreground max-w-md",children:t("previewBuildView.buildingSubtitle",{defaultValue:"This usually takes a couple of minutes. Your live game stays untouched — close this anytime to return."})})]})]}),i.status==="ready"&&i.playUrl&&r.jsx(kd,{ref:s,gameId:c?.id??null,playGameId:c?.public_id??null,studio:!0,onTopUpRequest:d,src:i.playUrl,title:"Preview build",className:"w-full h-full border-0",allow:"autoplay; fullscreen; gamepad; xr-spatial-tracking",allowFullScreen:!0},i.playUrl),i.status==="error"&&r.jsxs("div",{className:"absolute inset-0 flex flex-col items-center justify-center text-center px-8 gap-4",children:[r.jsx(H,{icon:["far","circle-exclamation"],className:"text-2xl text-amber-400"}),r.jsxs("div",{className:"space-y-1.5",children:[r.jsx("p",{className:"text-sm text-foreground",children:t("previewBuildView.errorTitle",{defaultValue:"Preview build failed."})}),r.jsx("p",{className:"text-xs text-muted-foreground max-w-md break-words",children:i.error??t("previewBuildView.errorFallback",{defaultValue:"Something went wrong. Try again later."})})]})]}),i.status==="idle"&&r.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:r.jsx("p",{className:"text-sm text-muted-foreground",children:t("previewBuildView.idle",{defaultValue:"No preview active."})})})]}),r.jsx(Nd,{isOpen:n,onClose:u,returnUrl:typeof window>"u"?"":window.location.href,testGameId:c?.id??null,play:a})]})}function Ng({prompt:e,onChoose:t,onCancel:i,onUpgradeRequest:c}){const{t:s}=Ee("studio"),n=Sd(),o=f.useRef(!1);f.useEffect(()=>{o.current||(o.current=!0,At("Tier Chooser Shown",{is_desktop_app:Ce}))},[]);const a=h=>{if(h==="desktop"&&!n){At("Tier Chooser Locked Clicked",{is_desktop_app:Ce}),c?.();return}At("Tier Chosen",{platform_tier:h,is_desktop_app:Ce}),t(h)},l=[s("tierChooser.desktop.benefit1","Cinematic 3D — real skies, terrain and materials"),s("tierChooser.desktop.benefit2","Bigger worlds, no browser limits"),s("tierChooser.desktop.benefit3","High-end physics and lighting")],d=[s("tierChooser.desktop.drawback1","Plays in the Tesana app, not the browser")],u=[s("tierChooser.web.benefit1","Plays instantly in any browser"),s("tierChooser.web.benefit2","Share with a single link"),s("tierChooser.web.benefit3","Best for quick games you iterate on fast")],m=[s("tierChooser.web.drawback1","Lighter visuals — browser-scale worlds")];return r.jsx(Be.div,{initial:{opacity:0}
240,animate:{opacity:1},transition:{duration:.25},className:"fixed inset-0 z-[900] bg-background overflow-y-auto",children:r.jsx("div",{className:"min-h-full w-full flex flex-col items-center justify-center",children:r.jsxs("div",{className:"w-full max-w-3xl px-6 py-10 flex flex-col items-center",children:[r.jsxs("p",{className:"text-xs text-muted-foreground/80 max-w-lg text-center truncate mb-4",children:["“",e,"”"]}),r.jsx("h1",{className:"text-2xl sm:text-3xl font-medium text-foreground text-center mb-2",children:s("tierChooser.title","Where will your game live?")}),r.jsx("p",{className:"text-sm text-muted-foreground text-center mb-8",children:s("tierChooser.subtitle","This choice is permanent for this game — pick the platform it will be built for.")}),r.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4 w-full",children:[r.jsxs(Be.div,{initial:{opacity:0,y:16},animate:{opacity:1,y:0},transition:{duration:.3,delay:.05,ease:[.16,1,.3,1]},className:me("relative rounded-xl border p-6 flex flex-col text-left cursor-pointer transition-all",n?"border-accent/60 bg-accent/[0.04] shadow-lg shadow-accent/5 hover:border-accent hover:bg-accent/[0.08]":"border-border/60 bg-card hover:border-amber-500/50 hover:bg-amber-500/[0.04]"),role:"button",tabIndex:0,onClick:()=>a("desktop"),onKeyDown:h=>{(h.key==="Enter"||h.key===" ")&&a("desktop")},children:[n?Ce&&r.jsx("span",{className:"absolute -top-2.5 left-5 text-[10px] uppercase tracking-wider px-2 py-0.5 rounded-full font-medium bg-accent text-background",children:s("tierChooser.recommended","Recommended")}):r.jsxs("span",{className:"absolute -top-2.5 left-5 text-[10px] uppercase tracking-wider px-2 py-0.5 rounded-full font-medium bg-amber-500 text-black flex items-center gap-1",children:[r.jsx(H,{icon:["fas","lock"],className:"text-[8px]"}),s("tierChooser.desktop.ultraBadge","Ultra")]}),r.jsxs("div",{className:"flex items-center gap-3 mb-3",children:[r.jsx("span",{className:"w-10 h-10 rounded-lg bg-accent/15 text-accent flex items-center justify-center",children:r.jsx(H,{icon:["far","desktop"],className:"text-lg"})}),r.jsx("h2",{className:"text-lg font-medium text-foreground",children:s("tierChooser.desktop.title","Desktop game")})]}),r.jsx("ul",{className:"flex flex-col gap-1.5 mb-3",children:l.map(h=>r.jsxs("li",{className:"flex items-start gap-2 text-sm text-foreground/90",children:[r.jsx(H,{icon:["far","check"],className:"text-accent text-xs mt-1 shrink-0"}),r.jsx("span",{children:h})]},h))}),r.jsx("ul",{className:"flex flex-col gap-1.5 mb-5",children:d.map(h=>r.jsxs("li",{className:"flex items-start gap-2 text-sm text-muted-foreground",children:[r.jsx(H,{icon:["far","minus"],className:"text-xs mt-1 shrink-0"}),r.jsx("span",{children:h})]},h))}),r.jsxs("div",{className:"mt-auto",children:[r.jsxs("span",{className:me("w-full h-10 px-4 rounded-md hover:opacity-90 transition-opacity text-sm font-medium flex items-center justify-center gap-2",n?"bg-accent text-background":"bg-amber-500 text-black"),children:[!n&&r.jsx(H,{icon:["fas","lock"],className:"text-xs"}),n?s("tierChooser.desktop.cta","Build a desktop game"):s("tierChooser.desktop.ctaLocked","Upgrade to Ultra")]}),n?!Ce&&r.jsx("p",{className:"text-[11px] text-muted-foreground/80 text-center mt-2",children:s("tierChooser.desktop.webHint","You’ll need the free Tesana app to play it")}):r.jsx("p",{className:"text-[11px] text-muted-foreground/80 text-center mt-2",children:s("tierChooser.desktop.lockHint","Ultra members only while desktop is in early access")})]})]}),r.jsxs(Be.div,{initial:{opacity:0,y:16},animate:{opacity:1,y:0},transition:{duration:.3,delay:.1,ease:[.16,1,.3,1]},className:"relative rounded-xl border border-border/60 bg-card p-6 flex flex-col text-left cursor-pointer transition-all hover:border-foreground
240/40 hover:bg-foreground/[0.03]",role:"button",tabIndex:0,onClick:()=>a("web"),onKeyDown:h=>{(h.key==="Enter"||h.key===" ")&&a("web")},children:[r.jsxs("div",{className:"flex items-center gap-3 mb-3",children:[r.jsx("span",{className:"w-10 h-10 rounded-lg bg-foreground/10 text-foreground flex items-center justify-center",children:r.jsx(H,{icon:["far","globe"],className:"text-lg"})}),r.jsx("h2",{className:"text-lg font-medium text-foreground",children:s("tierChooser.web.title","Web game")})]}),r.jsx("ul",{className:"flex flex-col gap-1.5 mb-3",children:u.map(h=>r.jsxs("li",{className:"flex items-start gap-2 text-sm text-foreground/90",children:[r.jsx(H,{icon:["far","check"],className:"text-foreground/60 text-xs mt-1 shrink-0"}),r.jsx("span",{children:h})]},h))}),r.jsx("ul",{className:"flex flex-col gap-1.5 mb-5",children:m.map(h=>r.jsxs("li",{className:"flex items-start gap-2 text-sm text-muted-foreground",children:[r.jsx(H,{icon:["far","minus"],className:"text-xs mt-1 shrink-0"}),r.jsx("span",{children:h})]},h))}),r.jsx("div",{className:"mt-auto",children:r.jsx("span",{className:"w-full h-10 px-4 rounded-md bg-foreground text-background hover:opacity-80 transition-opacity text-sm font-medium flex items-center justify-center",children:s("tierChooser.web.cta","Build a web game")})})]})]}),r.jsx("button",{onClick:()=>{At("Tier Chooser Cancelled",{is_desktop_app:Ce}),i()},className:"mt-8 text-sm text-muted-foreground hover:text-foreground transition-colors cursor-pointer",children:s("tierChooser.cancel","← Back to dashboard")})]})})})}const Sg=4e3,_g=1e4,Cg=5e3,Eg=3e4,Tg=2e4;function Mg(e){const t=e?.response;return t?.status===403||t?.status===404&&t.data?.code==="live_unavailable"}function Ag(e,t){return!!e.origin&&t.startsWith(e.origin)}function Pg(e,{active:t}){const[i,c]=f.useState(null),[s,n]=f.useState(0),o=f.useRef(null);return f.useEffect(()=>{c(null),o.current=null},[e]),f.useEffect(()=>{if(!e||i||o.current===e)return;let a=!1,l,d=0;const u=async()=>{try{const{live_url:m,ready:h}=await Ft.openLivePreview(e);if(a)return;d=0,h?c(m):l=setTimeout(u,t?Sg:_g)}catch(m){if(a)return;if(Mg(m)){o.current=e;return}d+=1,l=setTimeout(u,Math.min(Cg*d,Eg))}};return u(),()=>{a=!0,clearTimeout(l)}},[e,t,i,s]),f.useEffect(()=>{if(!i)return;const a=()=>{c(null),n(u=>u+1)},l=setTimeout(a,Tg),d=u=>{Ag(u,i)&&(u.data?.type==="tesana:live-connected"?clearTimeout(l):u.data?.type==="tesana:live-gone"&&(clearTimeout(l),a()))};return window.addEventListener("message",d),()=>{clearTimeout(l),window.removeEventListener("message",d)}},[i]),i}const Dg={macos:["fab","apple"],windows:["fab","windows"],web:["far","globe"],code:["far","code"]};function Rg({game:e}){const{t}=Ee("exports"),i=on(e)==="web",c=er(),[s,n]=f.useState(null),[o,a]=f.useState(!1),{data:l=[]}=mt({queryKey:["gameExports",e?.id],queryFn:()=>e?ml.list(e.id):Promise.resolve([]),enabled:!!e,refetchInterval:p=>(p.state.data??[]).some(x=>x.status==="queued"||x.status==="building"||x.status==="uploading")?4e3:!1}),d=f.useMemo(()=>l.filter(p=>p.status==="queued"||p.status==="building"||p.status==="uploading"),[l]),u=f.useMemo(()=>l.filter(p=>{if(p.status!=="ready"||!p.completed_at)return!1;const g=new Date(p.completed_at).getTime();return Date.now()-g<60*60*1e3}),[l]),m=d.length+u.length;if(!e||m===0)return null;const h=d.length>0?t("dock.buildingPill",{count:d.length}):t("dock.readyPill",{count:u.length});return r.jsxs(r.Fragment,{children:[r.jsxs(Be.button,{type:"button",onClick:()=>a(p=>!p),"aria-label":t("dock.expandAria"),initial:{opacity:0,y:12},animate:{opacity:1,y:0},exit:{opacity:0,y:12},className:me("fixed bottom-4 right-4 z-40 flex items-center gap-2 px-3 py-2 rounded-full shadow-lg cursor-pointer transition-colors",d.length>0?"bg-foreground text-background hover:opacity-90":"bg-emerald-500/15 text-emerald-700 dark:text-emerald-300 hover:bg-emerald-500/20 border border-emerald-500/30"),children:[d.length>0?r.jsx(H,{icon:["far","spinner"],className:"animate-spin text-xs"}):r.jsx(H,{icon:["far","circle-check"],className:"text-xs"}),r.jsx("span",{className:"text-sm font-medium",children:h})]}),r.jsx(lt,{children:o&&r.jsx(Be.div,{initial:{opacity:0,y:12,scale:.95}
240,animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:12,scale:.95},transition:{duration:.18,ease:[.16,1,.3,1]},className:"fixed bottom-16 right-4 z-40 w-[320px] max-w-[calc(100vw-2rem)] bg-card border border-border rounded-md shadow-xl overflow-hidden",children:r.jsx("div",{className:"p-2",children:[...d,...u].map(p=>{const g=p.status==="ready",b=p.status==="uploading";return r.jsxs("button",{type:"button",onClick:()=>{a(!1),n({format:p.format,exportId:p.id})},className:"w-full flex items-center gap-3 p-2.5 rounded-sm hover:bg-foreground/5 transition-colors text-left cursor-pointer",children:[r.jsx("div",{className:"w-8 h-8 rounded bg-foreground/5 flex items-center justify-center flex-shrink-0",children:r.jsx(H,{icon:Dg[p.format],className:"text-foreground/70"})}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("p",{className:"text-sm text-foreground truncate",children:t(p.format==="code"&&i?"formats.codeWeb.label":`formats.${p.format}.label`)}),r.jsxs("p",{className:"text-xs text-muted-foreground truncate",children:[g&&t("status.ready"),b&&t("status.uploading"),!g&&!b&&t("status.building",{percent:p.progress_percent})]})]}),!g&&r.jsx("div",{className:"w-12 h-1 rounded-full bg-foreground
240/10 overflow-hidden flex-shrink-0",children:r.jsx(Be.div,{className:"h-full bg-foreground",animate:{width:`${Math.max(2,p.progress_percent)}%`},transition:{duration:.3}})}),g&&r.jsx(H,{icon:["far","circle-check"],className:"text-emerald-500 flex-shrink-0"})]},p.id)})})})}),s&&e&&r.jsx(_a,{isOpen:!!s,onClose:()=>{n(null),c.invalidateQueries({queryKey:["gameExports",e.id]})},game:e,format:s.format,existingExportId:s.exportId})]})}function Ug(){const e=navigator.userAgent.toLowerCase();return e.includes("win")?"windows":e.includes("mac")?"macos":"linux"}function Fg(e,t){const[i,c]=f.useState("idle"),[s,n]=f.useState(null),[o,a]=f.useState(null),l=f.useCallback(async()=>{if(!Ce||!e)return;const{invoke:u}=await Ye(async()=>{const{invoke:p}=await import("./core-DhEqZVGG.js");return{invoke:p}},[]),m=Ug(),h=hl(t);try{n(null),c("building");const p=await fetch(`${h}/build/desktop/${e}?platform=${m}`,{method:"POST",headers:{"Content-Type":"application/json"}});if(!p.ok){const w=await p.text();throw new Error(`Build failed: ${w}`)}const{download_url:g}=await p.json(),b=`${h}${g}`;c("downloading");const x=await u("download_game",{url:b,gameId:e});a(x),c("launching"),await u("launch_game",{gamePath:x}),c("ready")}catch(p){n(p.message||"Unknown error"),c("error")}},[e,t]),d=f.useCallback(async()=>{if(o)try{c("launching");const{invoke:u}=await Ye(async()=>{const{invoke:m}=await import("./core-DhEqZVGG.js");return{invoke:m}},[]);await u("launch_game",{gamePath:o}),c("ready")}catch(u){n(u.message||"Failed to relaunch"),c("error")}},[o]);return{status:i,error:s,gamePath:o,launchDesktop:l,relaunch:d,isAvailable:Ce}}const Lg=f.lazy(()=>Ye(()=>import("./index-B_kJqugV.js").then(e=>e.i),__vite__mapDeps([86,1,2,6,3,7,8,18,64,57,59,65,60,87,37,88,23,44,45,46,47,48,49,50,51,53,77,78,69,89,79,80,81,72,73,90,68,91,92,93]))),Og=f.lazy(()=>Ye(()=>import("./ChatPanel-CprUFb98.js"),__vite__mapDeps([94,1,2,6,3,7,8,45,18,46,47,48,49,50,89,72,73,93,80,81])));function Gg(e,t){return t&&t>0?t:vl(e)}const Ig=()=>{const[e,t]=f.useState(window.innerWidth<=768);return f.useEffect(()=>{const i=()=>t(window.innerWidth<=768);return window.addEventListener("resize",i),()=>window.removeEventListener("resize",i)},[]),e};function Bg(){const e=at(),t=Ig(),{isAuthenticated:i,user:c}=Ut(),{t:s}=Ee("studio"),n=ba(),{gameId:o}
240=yl(),a=!!o&&!e.currentGame,l=n.state?.tier,d=e.currentGame?.platform_tier==="desktop",u=on(e.currentGame)==="godot",m=!Ce&&!!e.currentGame?.id&&d,h=Pg(!d&&!u?e.currentGame?.id??null:null,{active:e.isGenerating}),[p,g]=f.useState(0),[b,x]=ka(),{playerShell:w,gameChat:v}=Ed(),{t:N}=Ee("play",{useSuspense:!1}),[y,k]=f.useState(!1),[S,T]=f.useState(!1),E=e.currentGame,A=v&&!!E?.public_id&&E.chat_enabled!==!1&&!E.organization,M=Md(A?E:null),R=Td(E,{live:M.playingNow,enabled:w||v}),_=f.useCallback(()=>T(te=>!te),[]),F=f.useCallback(()=>T(!1),[]),C=f.useCallback(()=>k(!1),[]);f.useEffect(()=>{k(!1),T(!1)},[E?.id]);const[P,U]=f.useState(!1),[K,z]=f.useState(!1),[O,L]=f.useState(!1),[j,D]=f.useState(!1),I=f.useRef(null),B=f.useRef(null),G=f.useRef(!1),q=f.useRef(!1),V=e.viewableAssets,W=e.assetTree,ee=e.isHydratingAssets,ne=e.ensureHydratedAssets,J=_r(),$=mn({gameId:e.currentGame?.id,engineGameName:e.currentGame?.engine_game_name}),ge=!!($.record&&e.currentGame?.engine_game_name&&$.record.engine_game_name!==e.currentGame.engine_game_name),ce=f.useRef(!1);f.useEffect(()=>{Ce&&(J.loading||$.loading||J.root&&e.currentGame?.engine_game_name&&($.linking||ce.current||$.linked&&!ge||(ce.current=!0,$.link())))},[J.loading,J.root,$.loading,$.linked,$.linking,$.link,ge,e.currentGame?.engine_game_name]),f.useEffect(()=>{ce.current=!1},[e.currentGame?.id,ge]);const re=f.useMemo(()=>e.currentGame?.id?Ce?!(J.loading||$.loading||!J.root||!$.linked||ge):!0:!1,[e.currentGame?.id,J.loading,J.root,$.loading,$.linked,ge]),oe=Fg(e.generationStatus?.game_name??e.currentGame?.engine_game_name,e.currentGame?.engine_version),de=f.useRef(0);f.useEffect(()=>{const te=de.current,Me=V.length;de.current=Me;const He=e.messages.some(gt=>gt.message_type==="plan"&&!gt.reverted);e.isGenerating&&te===0&&Me>0&&!He&&!e.currentGame?.template_derived_from_id&&e.gameUrl},[V.length,e.isGenerating,e.messages,e.forcePreviewTab,e.currentGame?.template_derived_from_id]),f.useEffect(()=>{!u&&e.previewTab==="world"&&e.setPreviewTab("game")},[u,e.previewTab,e.setPreviewTab]);const[Z,le]=f.useState(!1),ie=f.useRef(0),Q=f.useCallback(te=>{te.preventDefault(),ie.current++,te.dataTransfer.types.includes("Files")&&le(!0)},[]),be=f.useCallback(te=>{te.preventDefault(),ie.current--,ie.current<=0&&(ie.current=0,le(!1))},[]),ae=f.useCallback(te=>{te.preventDefault(),ie.current=0,le(!1)},[]),fe=!c?.subscription_tier||c.subscription_tier==="free",se=Cd("signature_asset_preview"),[Ne,ue]=f.useState(!1),he=()=>{ue(!1),e.setChatCollapsed(!1)};f.useEffect(()=>{Ne&&!e.chatCollapsed&&ue(!1)},[e.chatCollapsed,Ne]),f.useEffect(()=>{Ne&&e.previewTab!=="plan"&&he()},[e.previewTab]);const Y=f.useMemo(()=>e.messages.some(te=>te.message_type==="plan"&&!te.reverted),[e.messages]),[X]=wl(),ye=f.useRef(!1);f.useEffect(()=>{ye.current||X.get("payment_success")==="1"&&Y&&(ye.current=!0,e.forcePreviewTab("plan"))},[X,Y,e]),f.useEffect(()=>{ye.current=!1},[e.currentGame?.id]);const ke=f.useRef(!1);f.useEffect(()=>{e.previewTab==="plan"&&Y&&(ke.current||(ke.current=!0,pl("signature_asset_preview","plan_view",c?.id)))},[e.previewTab,Y,c?.id]),f.useEffect(()=>{ke.current=!1},[e.currentGame?.id]);const we=f.useCallback(async()=>I.current?.captureScreenshot()??null,[]),je=f.useCallback(async()=>I.current?.captureConsoleLogs()??null,[]);f.useEffect(()=>(e.captureScreenshotRef.current=we,()=>{e.captureScreenshotRef.current=null}),[we,e.captureScreenshotRef]),f.useEffect(()=>(e.captureConsoleLogsRef.current=je,()=>{e.captureConsoleLogsRef.current=null}),[je,e.captureConsoleLogsRef]),f.useEffect(()=>{const te=e.usage?.available_balance??e.usage?.edits_remaining;if(typeof te!="number")return;const Me=B.current,He=te<=Gn,gt=Me!==null&&Me>Gn&&He;(Me===null&&He||gt)&&(L(!0),D(!1)),He||(L(!1),D(!1)),B.current=te},[e.usage?.available_balance,e.usage?.edits_remaining]),f.useEffect(()=>{if(G.current)return;const te=e.usage?.edits_remaining;if(typeof te!="number"||te===0||te>Gn||!(!c?.subscription_tier||c.subscription_tier==="free"))return;const He=ro(so.ambientLastCredit,c?.id);G.current=!0,He==="show_nudge"?gl(tt.lastCredit,He):Vr(tt.lastCredit,"ab_variant_control",He)},[e.usage?.edits_remaining,c?.subscription_tier,c?.id]);const pe=f.useCallback(()=>
240{if(U(!1),!q.current)return;if(q.current=!1,!(!c?.subscription_tier||c.subscription_tier==="free")){Vr(tt.shareSuccess,"has_pro");return}if(localStorage.getItem(oo.shareSuccess)==="1"){Vr(tt.shareSuccess,"one_shot_seen");return}const He=ro(so.postShareSuccess,c?.id);if(He!=="show_modal"){Vr(tt.shareSuccess,"ab_variant_control",He);return}localStorage.setItem(oo.shareSuccess,"1"),e.setUpgradeModalContext(tt.shareSuccess),e.setShowUpgradeModal(!0)},[c?.subscription_tier,c?.id,e]),Fe=f.useCallback(()=>{q.current=!0,U(!0)},[]),Le=f.useCallback(async()=>{if(e.pendingGameUrl){e.applyPendingGameUrl();return}await e.reloadLatestBuild(),g(te=>te+1)},[e.pendingGameUrl,e.applyPendingGameUrl,e.reloadLatestBuild]),qe=f.useCallback(()=>{if(e.currentGame?.id){if(w){k(!0);return}window.open(`${window.location.origin}${da(e.currentGame)}`,"_blank")}},[e.currentGame?.id,e.currentGame?.public_id,w]),Ue=f.useMemo(()=>({visible:!!(i&&e.usage&&O&&!j),credits:e.usage?.available_balance??e.usage?.edits_remaining??0,overdrawn:!!e.usage?.is_overdrawn}),[i,e.usage,O,j]),ve=f.useCallback(()=>{L(!1),D(!0)},[]),Te=f.useCallback(()=>{const te=e.usage?.is_overdrawn?"overdrawn":fe?"general":"credits-exhausted";e.setUpgradeModalContext(te),e.setShowUpgradeModal(!0)},[e.setUpgradeModalContext,e.setShowUpgradeModal,e.usage?.is_overdrawn]),Je=f.useCallback(()=>e.setShowUpgradeModal(!0),[e.setShowUpgradeModal]),Pe=f.useCallback(()=>{e.setUpgradeModalContext(tt.assetImportLocked),e.setShowUpgradeModal(!0)},[e.setUpgradeModalContext,e.setShowUpgradeModal]),_e=f.useCallback(()=>{e.setUpgradeModalContext(tt.atomosLocked),e.setShowUpgradeModal(!0)},[e.setUpgradeModalContext,e.setShowUpgradeModal]),Ve=f.useCallback(()=>{e.setUpgradeModalContext(tt.muranyiLocked),e.setShowUpgradeModal(!0)},[e.setUpgradeModalContext,e.setShowUpgradeModal]),Ie=f.useCallback(()=>{e.setUpgradeModalContext(tt.loopLocked),e.setShowUpgradeModal(!0)},[e.setUpgradeModalContext,e.setShowUpgradeModal]),Se=f.useCallback(()=>{e.setUpgradeModalContext("credits-exhausted"),e.setShowUpgradeModal(!0)},[e.setUpgradeModalContext,e.setShowUpgradeModal]),Oe=uc(),ze=f.useCallback((te,Me)=>{if(Oe){e.setUpgradeModalContext(tt.planPreviewBuild),e.setShowUpgradeModal(!0);return}e.approvePlan(te,Me)},[Oe,e.approvePlan,e.setUpgradeModalContext,e.setShowUpgradeModal]),Xe=f.useCallback(te=>{if(te){e.openPreviewBuild(te);return}e.setPreviewTab(e.gameUrl?"game":"code"),e.setMobileActiveTab("preview")},[e.gameUrl,e.setPreviewTab,e.setMobileActiveTab,e.openPreviewBuild]),We=f.useCallback(te=>{e.openDetailsView(te),e.setMobileActiveTab("preview")},[e.openDetailsView,e.setMobileActiveTab]),rt=f.useCallback((te,Me)=>{e.openDetailsView(te,{initialTab:"changes",focusedFile:Me}),e.setMobileActiveTab("preview")},[e.openDetailsView,e.setMobileActiveTab]),ht=f.useCallback((te,Me)=>{const He=Me.trim(),gt=He?` using this prompt: "${He}"`:"";e.sendMessage(`Please regenerate the asset at \`${te}\`${gt}.
241Use the same generation tool that originally produced this asset, replace the file at the same path, and rebuild the game once it is in.`,{source:"asset-regenerate"}),e.setMobileActiveTab("chat")},[e]),ct=f.useCallback(te=>{e.sendMessage(`Please delete the asset at \`${te.id}\` from the game. `+(u?"Remove any references to it (preloads, scene wiring, autoload entries, GDScript imports) and rebuild the game so the change takes effect.":"Remove any references to it (imports, preloads, scene wiring) and rebuild the game so the change takes effect."),{source:"asset-delete"}),e.setMobileActiveTab("chat")},[e,u]),pt=f.useCallback(()=>{e.setCrashErrors([{message:s("studio.userReportedIssue")}]),e.setShowCrashModal(!0)},[e.setCrashErrors,e.setShowCrashModal,s]),it=!t&&!e.chatCollapsed,dt=!t&&it&&e.showPreview;return r.jsxs("div",{className:"tesana-embedded-clearpath h-screen flex flex-col bg-background overflow-hidden",onDragEnter:Q,onDragLeave:be,onDragOver:te=>te.preventDefault(),onDrop:ae,children:[r.jsx(xl,{children:r.jsx("title",{children:s("studio.pageTitle")})}),r.jsx(hc,{}),r.jsxs("div",{className:"flex flex-1 min-h-0 overflow-hidden",children:[!t&&r.jsx(mg,{activeGameId:e.currentGame?.id??null,activeGame:e.currentGame??null}),r.jsxs("div",{className:"flex flex-1 min-w-0 flex-col",children:[t&&r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"relative z-10 flex items-center px-4 py-3",children:[r.jsx("div",{className:"flex-1 min-w-0 flex items-center justify-between gap-2",children:r.jsx(fi,{game:e.currentGame,usage:e.usage,onShare:Fe,onPublish:()=>z(!0)})}),r.jsxs("div",{className:"flex gap-2 items-center justify-end",children:[r.jsx(Wi,{compact:!0}),e.gameUrl&&r.jsx("button",{onClick:Fe,className:"text-sm px-3 h-9 flex items-center justify-center rounded-md text-sm text-muted-foreground hover:text-foreground bg-foreground
241/[0.06] hover:bg-foreground/10 transition-all cursor-pointer gap-2 disabled:opacity-30 disabled:cursor-not-allowed",disabled:!e.currentGame?.id,children:r.jsx(H,{icon:["far","share-nodes"],className:"text-sm"})}),r.jsx(pi,{game:e.currentGame,isGenerating:e.isGenerating,runMode:e.activeRunMode,externalOpen:K,onOpenChange:z})]})]}),r.jsxs("div",{className:"relative flex border-b border-border bg-background/95",children:[r.jsx("button",{onClick:()=>e.setMobileActiveTab("chat"),className:`flex-1 px-4 py-3 text-sm transition-colors ${e.mobileActiveTab==="chat"?"text-foreground border-b-2 border-foreground":"text-muted-foreground"}`,children:s("studio.chat")}),r.jsxs("button",{onClick:()=>e.setMobileActiveTab("preview"),className:`flex-1 px-4 py-3 text-sm transition-colors relative ${e.mobileActiveTab==="preview"?"text-foreground border-b-2 border-foreground":"text-muted-foreground"}`,children:[s("studio.preview"),e.isGenerating&&r.jsx("span",{className:"absolute top-2 right-[18%] w-2 h-2 bg-accent rounded-full animate-pulse"})]})]})]}),r.jsxs("div",{ref:e.splitContainerRef,className:`relative z-9 flex-1 overflow-hidden ${t?"flex flex-col":"flex"}`,children:[r.jsxs("div",{className:`tesana-fs-hide relative flex flex-col bg-background transition-all duration-300 ease-out ${t&&e.mobileActiveTab!=="chat"?"hidden":"flex"} ${!t&&!it?"hidden":""}  ${t?"flex-1":""}`,style:!t&&it?{minWidth:375,width:`${Math.round(e.chatPanelRatio*100)}%`}:void 0,children:[!t&&r.jsx(sg,{onShare:Fe,onPublish:()=>z(!0),playingNow:R}),r.jsx("div",{className:"flex-1 min-h-0 flex flex-col",children:e.subagentDrill?r.jsx(nf,{}):e.showTimeline?r.jsx(tf,{}):r.jsxs(r.Fragment,{children:[e.isPromptLocked&&e.promptLockedBy&&r.jsxs("div",{className:"mx-3 mb-1 px-3 py-2 rounded-md bg-yellow-500/10 border border-yellow-500/20 flex items-center gap-2",children:[r.jsx(H,{icon:["far","lock"],className:"text-yellow-500 text-xs"}),r.jsx("span",{className:"text-xs text-yellow-400",children:s("studio.userBuilding",{username:e.promptLockedBy.username})})]}),r.jsx(ql,{messages:e.messages,onSendMessage:e.sendMessage,onApprovePlan:ze,onAnswerQuestion:e.answerQuestion,onCancel:e.cancelGeneration,remixSetup:e.isRemixSetup,onFillPrompt:e.fillPrompt,onRewindToMessage:e.rewindToMessage,onOpenPlanView:()=>{e.openPlanView(),e.setMobileActiveTab("preview")},onOpenDetailsView:We,onOpenSubagent:e.openSubagentDrill,contextUsage:e.contextUsage,onCompactNow:e.compactNow,isCompacting:e.isCompacting,isCancelling:e.isCancelling,onCloseDetailsView:e.closeDetailsView,onOpenDiffEntry:rt,onPreviewGeneration:Xe,detailsViewSessionId:e.previewTab==="details"?e.detailsViewSessionId:null,
241suggestions:e.suggestions,onCaptureConsoleLogs:e.playable?je:void 0,planMode:e.planMode,onPlanModeChange:e.setPlanMode,isLoading:e.isSendingNew||e.isSendingContinue,isGenerating:e.isGenerating,showPreview:e.showPreview,hideEmptyState:e.suppressChatEmptyState,placeholder:e.isPromptLocked?e.promptLockedBy?.username?s("studio.userBuilding",{username:e.promptLockedBy.username}):s("studio.someoneBuilding"):e.editingQueueItemId!=null?s("studio.placeholderEditQueued"):e.isGenerating||e.messageQueue.length>0?s("studio.placeholderFollowUp"):void 0,pageDragActive:Z,hasGame:e.playable&&!!e.gameUrl,gameId:e.currentGame?.id||null,gameDefaultTierId:e.currentGame?.default_tier_id||null,gameEngineKind:e.currentGame?.engine_kind??null,gameDefaultRunMode:e.currentGame?.default_run_mode||null,gameDefaultLoopBudgetCredits:e.currentGame?.default_loop_budget_credits??null,gameTalkAvailable:!!e.currentGame?.talk_available,initialTier:l,isPromptLocked:e.isPromptLocked,isFreeUser:fe,usage:e.usage,onUpgradeClick:Je,messageQueue:e.messageQueue,queuePaused:e.queuePaused,onQueueMessage:e.queueMessage,onRemoveQueuedMessage:e.removeQueuedMessage,onClearQueue:e.clearQueue,onReorderQueue:e.reorderQueue,onSetQueuePaused:e.setQueuePaused,editingQueueItemId:e.editingQueueItemId,onBeginEditQueuedMessage:e.beginEditQueuedMessage,onCancelEditQueuedMessage:e.cancelEditQueuedMessage,onConfirmEditQueuedMessage:e.confirmEditQueuedMessage,lowCreditsNotice:Ue,onGetCredits:Te,onResumePausedRun:e.resumePausedRun,onDismissLowCreditsNotice:ve,onAssetUploadBlocked:Pe,onAtomosBlocked:_e,onMuranyiBlocked:Ve,onLoopBlocked:Ie,onBuildBlocked:Se,onSendNote:e.sendNote,steeringNotes:e.steeringNotes,generationStatus:e.generationStatus,activeRunMode:e.activeRunMode,onRequestBuild:e.requestBuild,onWindDown:e.windDown,windingDown:e.windingDown,milestones:e.milestones,awayMarker:e.awayMarker,onDismissAwayRecap:e.dismissAwayRecap,criticVerdicts:e.criticVerdicts})]})}),dt&&r.jsx("div",{role:"separator","aria-orientation":"vertical","aria-label":s("studio.resizePanels"),onMouseDown:te=>{te.preventDefault(),e.setIsResizingSplit(!0)},className:"absolute right-0.5 top-0 bottom-0 z-10 w-2 cursor-col-resize group flex items-center justify-center",children:r.jsx("div",{className:`mx-auto my-auto h-12 w-1 rounded-full transition-colors ${e.isResizingSplit?"bg-accent/80":"bg-transparent group-hover:bg-accent/40"}`})})]}),r.jsxs("div",{className:`h-full flex flex-col overflow-hidden transition-all duration-300 ease-out ${t&&e.mobileActiveTab!=="preview"?"hidden":""} ${!t&&!e.showPreview&&!e.chatCollapsed?"w-0 opacity-0 overflow-hidden":"opacity-100 flex-1"}`,children:[!t&&r.jsx(ug,{onShare:Fe,showPublishPopover:K,onPublishOpenChange:z}),t&&r.jsx("div",{className:"hidden md:flex items-center gap-0.5 p-1.5",children:[{id:"game",label:s("studio.tabGame"),icon:"gamepad-modern"},{id:"assets",label:s("studio.tabAssets"),icon:"cube"},{id:"code",label:s("studio.tabCode","Code"),icon:"code-simple"}].map(te=>{const Me=e.previewTab===te.id,He=V.length;return r.jsxs("button",{onClick:()=>e.setPreviewTab(te.id),className:me("flex-1 flex items-center justify-center gap-1.5 h-8 rounded-md text-xs transition-all",Me?"bg-foreground
241/10 text-foreground":"text-muted-foreground"),children:[r.jsx(H,{icon:["far",te.icon],className:"text-[11px]"}),te.label,te.id==="assets"&&He>0&&r.jsx("span",{className:me("min-w-[16px] h-4 px-1 rounded-full text-[10px] flex items-center justify-center",Me?"bg-accent/20 text-accent":"bg-foreground/10 text-muted-foreground"),children:He}),te.id==="game"&&e.isGenerating&&r.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-accent animate-pulse"})]},te.id)})}),r.jsx(Fl,{gameId:e.currentGame?.id??null,enabled:re,engineKind:on(e.currentGame),children:r.jsx(Ll,{gameId:e.currentGame?.id??null,cloudHash:e.cloudBuildHash??null,children:r.jsxs("div",{className:`tesana-fs-stage relative flex-1 flex flex-col ${t?"":`border border-border rounded-md overflow-hidden mr-2 mb-2 ${it?"":"ml-2"}`}`,children:[a&&r.jsx("div",{className:"absolute inset-0 z-30 flex items-center justify-center bg-background",children:r.jsx(_t,{size:"lg"})}),e.previewTab==="plan"&&r.jsxs("div",{className:"relative flex-1 flex flex-col overflow-hidden",children:[se==="visual_card"?r.jsx(Yc,{messages:e.messages,assets:V,isGenerating:e.isGenerating,isHydratingAssets:ee,ensureHydratedAssets:ne,projectTemplate:e.projectTemplate,onApprove:te=>ze(te),onUpgrade:Je,disabled:e.isGenerating&&!Y,onClose:e.closePlanView,variant:se,gameId:e.currentGame?.id??null,gameName:e.currentGame?.name??null,onOpenImmersive:void 0}):se==="hybrid"?r.jsx(xg,{messages:e.messages,assets:V,isGenerating:e.isGenerating,isHydratingAssets:ee,ensureHydratedAssets:ne,projectTemplate:e.projectTemplate,onApprove:te=>ze(te),onUpgrade:Je,disabled:e.isGenerating&&!Y,onClose:e.closePlanView,variant:se,gameId:e.currentGame?.id??null,gameName:e.currentGame?.name??null}):r.jsx(Xa,{messages:e.messages,onApprove:te=>ze(te),onUpgrade:Je,disabled:e.isGenerating&&!Y,onClose:e.closePlanView}),Ne&&r.jsx(gg,{messages:e.messages,assets:V,isGenerating:e.isGenerating,isHydratingAssets:ee,ensureHydratedAssets:ne,projectTemplate:e.projectTemplate,onApprove:te=>ze(te),onUpgrade:Je,disabled:e.isGenerating&&!Y,onClose:he,variant:se,gameId:e.currentGame?.id??null,gameName:e.currentGame?.name??null})]}),e.previewTab==="details"&&r.jsx("div",{className:"flex-1 flex flex-col overflow-hidden",children:r.jsx(jg,{messages:e.messages,targetSessionId:e.detailsViewSessionId??"",onClose:e.closeDetailsView})}),e.previewTab==="preview-build"&&r.jsx("div",{className:"flex-1 flex flex-col overflow-hidden",children:r.jsx(kg,{onClose:e.closePreviewBuild})}),e.previewTab==="assets"&&!t&&r.jsx("div",{className:"flex-1 overflow-hidden flex flex-col",children:r.jsx(Rf,{assets:e.isGenerating&&e.currentGame?.template_derived_from_id?[]:V,projectTemplate:e.projectTemplate,isGenerating:e.isGenerating,onRegenerateAsset:ht,onDeleteAsset:ct,tree:e.isGenerating&&e.currentGame?.template_derived_from_id?null:W,onSelectAsset:ne,isHydrating:ee})}),e.previewTab==="code"&&!t&&e.currentGame?.id&&r.jsx("div",{className:"flex-1 overflow-hidden flex flex-col",children:r.jsx(Fh,{gameId:e.currentGame.id,engineGameName:e.currentGame.engine_game_name})}),e.previewTab==="world"&&!t&&e.currentGame?.id&&u&&r.jsx("div",{className:"flex-1 overflow-hidden flex flex-col",children:r.jsx(tg,{gameId:e.currentGame.id,engineGameName:e.currentGame.engine_game_name})}),qn,qn,qn,e.previewTab==="services"&&!t&&r.jsx("div",{className:"flex-1 overflow-hidden flex flex-col",children:r.jsx(Bf,{})}),!t&&Ce&&e.currentGame?.id&&d&&u&&e.previewTab==="game"&&r.jsx("div",{className:"flex-1 flex flex-col min-h-0",children:r.jsx(zh,{gameId:e.currentGame.id,engineGameName:e.currentGame.engine_game_name,title:e.currentGame.name,posterUrl:e.currentGame.cover_image_url||e.currentGame.title_poster_url})}),m&&e.currentGame&&r.jsx("div",{className:me("relative flex-1 flex flex-col min-h-0",e.previewTab==="game"?"":"hidden"),children:r.jsx(_d,{gameName:e.currentGame.name,posterUrl:e.currentGame.cover_image_url||e.currentGame.title_poster_url,surface:"studio-preview"})}),(t||!e.currentGame?.id||!d)&&!m&&r.jsxs("div",{className:me("flex-1 flex min-h-0",e.previewTab==="game"?"":"hidden"),children:[r.jsx("div",{className:"flex-1 flex flex-col min-h-0 min-w-0",children:r.jsx(Jl,{ref:I,gameUrl:h??e.gameUrl,gameId:e.currentGame?.id??null,playGameId:e.currentGame?.public_id??null,isGenerating:e.isGenerating,generationStatus:e.generationStatus,runMode:e.activeRunMode||e.currentGame?.default_run_mode,assets:e.gameAssets,disableIframeInteraction:e.isResizingSplit,onReportCrash:pt,canFixCrash:!!e.currentGame?.claude_session_id,refreshKey:p,handleRefresh:Le,handleExpand:qe,isMuted:e.previewTab!=="game"||y,volume:b,onVolumeChange:x,handleLaunchDesktop:oe.isAvailable&&e.playable?oe.gamePath?oe.relau
241nch:oe.launchDesktop:void 0,desktopBuildStatus:oe.status,pendingGameUrl:h?null:e.pendingGameUrl,onApplyPendingGameUrl:()=>{e.applyPendingGameUrl(),g(te=>te+1)},onDismissPendingGameUrl:e.dismissPendingGameUrl,appearanceRebuildPending:!!e.currentGame?.appearance_rebuild_pending,onScreenshotCaptured:e.playable?e.attachScreenshot:void 0,disableScreenshot:e.isSendingNew||e.isSendingContinue||e.isPromptLocked,expandLabel:w?N("studio.playMode",{defaultValue:"Play"}):void 0,onToggleChat:A&&!t?_:void 0,chatOpen:S,chatUnread:M.unread,chatLabel:S?N("studio.hideChat",{defaultValue:"Hide game chat"}):N("studio.showChat",{defaultValue:"Game chat"})})}),A&&S&&!t&&E&&r.jsx("aside",{"aria-label":N("studio.showChat",{defaultValue:"Game chat"}),className:"w-[340px] shrink-0 flex flex-col min-h-0 border-l border-border bg-background",children:r.jsx(f.Suspense,{fallback:null,children:r.jsx(Og,{game:E,variant:"desktop",placement:"docked",playingNow:R,onClose:F})})})]})]})})})]})]})]})]}),y&&E&&r.jsx("div",{className:"fixed inset-0 z-[90] bg-black",children:r.jsx(f.Suspense,{fallback:r.jsx("div",{className:"flex h-full items-center justify-center",children:r.jsx(_t,{size:"lg",overlay:!1})}),children:r.jsx(Lg,{game:E,surface:"studio",src:h??e.gameUrl,onClose:C})})}),Tl&&e.pendingCreation&&r.jsx(Ng,{prompt:e.pendingCreation.message,onChoose:e.confirmPlatformTier,onCancel:e.cancelPendingCreation,onUpgradeRequest:()=>{e.setUpgradeModalContext(tt.desktopTierLocked),e.setShowUpgradeModal(!0)}}),r.jsx(qa,{isOpen:e.showUpgradeModal,onClose:()=>{e.setShowUpgradeModal(!1),e.setPendingUpgradePrompt(null),e.setUpgradeModalContext("credits-exhausted")},pendingPrompt:e.pendingUpgradePrompt||void 0,gameId:e.currentGame?.id,context:e.upgradeModalContext}),r.jsx(hg,{visible:e.phaseModalVisible,payload:e.currentGame?.completed_work?.next_phase_prompt??null,designPhase:e.currentGame?.completed_work?.design_phase,complexity:e.currentGame?.completed_work?.complexity,gameId:e.currentGame?.id??null,onPrimary:te=>{e.dismissPhaseModal(),e.fillPrompt(te)},onDismiss:()=>e.dismissPhaseModal()}),e.currentGame&&r.jsx(Ra,{isOpen:P,onClose:pe,title:e.currentGame.name,shareUrl:ua(e.currentGame),previewImage:ca(e.currentGame)||void 0,gameId:e.currentGame.id,isOwner:e.collaborationStatus?.is_owner??(!!c&&e.currentGame.user===c.username),visibility:e.currentGame.visibility,slug:e.currentGame.slug,restrictedToOrg:bl(e.currentGame)}),e.errorBanner&&!e.showCrashModal&&!e.isGenerating&&(()=>{const te=e.errorBanner.kind,Me={fixable:{icon:"exclamation-triangle",iconClass:"text-yellow-500",borderClass:"border-yellow-500/30",title:s("studio.runtimeError.detected"),detail:e.errorBanner.message},infra:{icon:"wifi-slash",iconClass:"text-blue-400",borderClass:"border-blue-500/30",title:s("studio.gameError.infra.title"),detail:s("studio.gameError.infra.detail")},"browser-compat":{icon:"browser",iconClass:"text-orange-400",borderClass:"border-orange-500/30",title:s("studio.gameError.browser.title"),detail:s("studio.gameError.browser.detail")},oom:{icon:"memory",iconClass:"text-purple-400",borderClass:"border-purple-500/30",title:s("studio.gameError.oom.title"),detail:s("studio.gameError.oom.detail")}}[te];return r.jsx("div",{className:"fixed bottom-4 right-4 z-[999] max-w-lg w-[calc(100%-2rem)] animate-in slide-in-from-bottom-4 fade-in duration-300",children:r.jsxs("div",{className:`flex gap-3 px-4 py-3 pr-3 rounded-md border ${Me.borderClass} bg-card shadow-lg`,children:[r.jsx(H,{icon:["far",Me.icon],className:`${Me.iconClass} text-md flex-shrink-0 mt-0.75`}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("p",{className:"text-sm text-foreground font-medium",children:Me.title}),r.jsx("p",{className:"text-xs text-muted-foreground truncate mt-1",children:Me.detail}),te==="fixable"&&r.jsx("button",{onClick:e.fixErrorBanner,className:"mt-3 px-3 h-9 text-sm rounded-md bg-foreground text-background hover:opacity-80 transition-opacity cursor-pointer whitespace-nowrap flex-shrink-0",children:s("studio.fixIt")}),te==="infra"&&r.jsx("button",{onClick:()=>{e.dismissErrorBanner(),Le()},className:"mt-3 px-3 h-9 text-sm rounded-md bg-foreground text-background hover:opacity-80 transition-opacity cursor-pointer whitespace-nowrap flex-shrink-0",children:s("studio.gameError.infra.reload")})]}),r.jsx("button",{onClick:e.dismissErrorBanner,className:"w-7 h-7 rounded-md text-muted-foreground hover:text-foreground hover:bg-foreground
241/6 transition-colors flex items-center justify-center cursor-pointer flex-shrink-0","aria-label":s("studio.dismiss"),children:r.jsx(H,{icon:["far","xmark"]})})]})})})(),e.restoredFromColdTier&&e.isGenerating&&r.jsx("div",{className:"fixed bottom-4 right-4 z-[998] max-w-md w-[calc(100%-2rem)] animate-in slide-in-from-bottom-4 fade-in duration-300",children:r.jsxs("div",{className:"flex gap-3 px-4 py-3 rounded-md border border-blue-500/30 bg-card shadow-lg",children:[r.jsx(H,{icon:["far","snowflake"],className:"text-blue-400 text-md flex-shrink-0 mt-0.75 animate-pulse"}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("p",{className:"text-sm text-foreground font-medium",children:"Restoring your game from archive"}),r.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"This game has been idle a while; we're unpacking it from cold storage. Usually 30–60 seconds."})]})]})}),e.showCrashModal&&r.jsx("div",{className:"fixed bottom-4 right-4 z-[1001] max-w-lg w-[calc(100%-2rem)] animate-in slide-in-from-bottom-4 fade-in duration-300",children:r.jsxs("div",{className:"flex items-start gap-3 px-4 py-3 pr-3 rounded-md border border-destructive/40 bg-card shadow-lg",children:[r.jsx(H,{icon:["far","circle-exclamation"],className:"text-destructive text-md flex-shrink-0 mt-0.75"}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("p",{className:"text-sm text-foreground font-medium",children:s("studio.gameCrashed")}),e.crashErrors.length>0&&r.jsxs("p",{className:"text-xs text-muted-foreground mt-1 line-clamp-2",children:[e.crashErrors[0]?.message,e.crashErrors[0]?.filename&&r.jsxs("span",{className:"ml-1 text-muted-foreground/60",children:["(",e.crashErrors[0].filename,e.crashErrors[0].lineno?`:${e.crashErrors[0].lineno}`:"",")"]})]}),r.jsx("button",{onClick:e.handleFixCrash,disabled:e.isFixing||!!e.usage?.is_overdrawn||(e.usage?.edits_remaining||0)<Gg(e.usage,e.runStartFloor),className:"mt-3 px-3 h-9 text-sm rounded-md bg-foreground text-background hover:opacity-80 transition-opacity cursor-pointer whitespace-nowrap flex-shrink-0 disabled:opacity-50 flex items-center gap-2",children:e.isFixing?r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"w-3.5 h-3.5 border-2 border-current/30 border-t-current rounded-full animate-spin"}),s("studio.fixing")]}):s("studio.autoFixGame")})]}),r.jsx("button",{onClick:()=>{e.setShowCrashModal(!1),e.setCrashErrors([])},disabled:e.isFixing,className:"w-7 h-7 rounded-md text-muted-foreground hover:text-foreground hover:bg-foreground
241/6 transition-colors flex items-center justify-center cursor-pointer flex-shrink-0 disabled:opacity-50","aria-label":s("studio.dismiss"),children:r.jsx(H,{icon:["far","xmark"]})})]})}),r.jsx(Rg,{game:e.currentGame})]})}function Vg(){const e=ba(),t=e.state?.prompt||"",i=e.state?.styleReferenceUrls,c=e.state?.omniReferenceUrl,s=e.state?.assetIds,n=e.state?.planFirst,o=e.state?.templateActivityLog,a=e.state?.tier,l=e.state?.runMode,d=e.state?.loopBudgetCredits,u=e.state?.runSource,m=e.state?.conceptId;return r.jsx(El,{initialPrompt:t,initialRunSource:u,initialConceptId:m,initialStyleReferenceUrls:i,initialOmniReferenceUrl:c,initialAssetIds:s,initialPlanFirst:n,initialRunMode:l,initialLoopBudgetCredits:d,initialTier:a,templateActivityLog:o,children:r.jsx(Bg,{})})}const Ix=Object.freeze(Object.defineProperty({__proto__:null,default:Vg},Symbol.toStringTag,{value:"Module"}));export{Gx as F,Ix as S,Ss as l,eh as r,Ph as u};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.