@engenty/wizards-runtime 0.7.9 → 0.7.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE-FIGURES +37 -0
- package/README.md +5 -2
- package/TRADEMARKS.md +47 -0
- package/apps/runtime/dist/app.js +2 -2
- package/apps/runtime/dist/cli/autostart.js +90 -7
- package/apps/runtime/dist/cli/autoupdate.js +18 -5
- package/apps/runtime/dist/cli/clients.js +25 -6
- package/apps/runtime/dist/cli/connect.js +7 -2
- package/apps/runtime/dist/cli/environment.js +33 -2
- package/apps/runtime/dist/cli/exec.js +38 -1
- package/apps/runtime/dist/cli/home.js +15 -0
- package/apps/runtime/dist/cli/machine.js +18 -8
- package/apps/runtime/dist/cli/processes.js +23 -3
- package/apps/runtime/dist/cli/setup.js +11 -1
- package/apps/runtime/dist/cli/start.js +33 -7
- package/apps/runtime/dist/cli/uninstall.js +100 -6
- package/apps/runtime/dist/cli/update.js +28 -12
- package/apps/runtime/dist/cli/versions.js +16 -4
- package/apps/runtime/dist/docs/user/install.md +18 -8
- package/apps/runtime/dist/harness/env.js +41 -8
- package/apps/runtime/dist/harness/index.js +10 -1
- package/apps/runtime/dist/harness/model.js +1 -1
- package/apps/runtime/dist/render/browser-path.js +43 -11
- package/apps/runtime/dist/services/engenty-shapes.js +3 -2
- package/apps/runtime/dist/update.js +4 -0
- package/apps/web/dist/assets/{AboutDialog-CShc0mRo.js → AboutDialog-CPRAlD2H.js} +1 -1
- package/apps/web/dist/assets/{ChangelogDialog-C4dVSwtN.js → ChangelogDialog-CZrd-MgC.js} +1 -1
- package/apps/web/dist/assets/{ChatView-KkOboyOo.js → ChatView-DVeERQdi.js} +1 -1
- package/apps/web/dist/assets/{EditorPage-lQ3YgsFT.js → EditorPage-DhUoKcss.js} +1 -1
- package/apps/web/dist/assets/{Harness-D6mgLWTb.js → Harness-DiB8CBdY.js} +1 -1
- package/apps/web/dist/assets/{NewWizardChannels-CPlh_37J.js → NewWizardChannels-Ba3XGpro.js} +1 -1
- package/apps/web/dist/assets/{NewWizardPage-D0FVJtXK.js → NewWizardPage-C2Oh2sMM.js} +1 -1
- package/apps/web/dist/assets/{OnboardingPage-BXPOMrQR.js → OnboardingPage-D_4ShWrL.js} +1 -1
- package/apps/web/dist/assets/{ProjectPage-DroTprqs.js → ProjectPage-C58rq50b.js} +1 -1
- package/apps/web/dist/assets/{PublicRunner-j3qoKjQQ.js → PublicRunner-CE0ohzyd.js} +1 -1
- package/apps/web/dist/assets/{ReadOnly-CKgSQ2z1.js → ReadOnly-CD5YWvrW.js} +1 -1
- package/apps/web/dist/assets/{RunDrawer-CJZ_ISAd.js → RunDrawer-Cd8-qHV7.js} +1 -1
- package/apps/web/dist/assets/{SettingsPage-BHZ0Z-og.js → SettingsPage-ChYLv-MG.js} +1 -1
- package/apps/web/dist/assets/{SetupPage-CDkYkjJX.js → SetupPage-hX7deF0g.js} +1 -1
- package/apps/web/dist/assets/{SharePage-BlVjVjHG.js → SharePage-B6u9kS12.js} +1 -1
- package/apps/web/dist/assets/changelog-Dn9LT4MS.js +1 -0
- package/apps/web/dist/assets/engenty-Cko4qGFV.js +1 -0
- package/apps/web/dist/assets/fluffy-engenty-Db7agOjV.js +520 -0
- package/apps/web/dist/assets/index-4jH2mkp7.js +14 -0
- package/apps/web/dist/assets/index-BwW652E-.css +1 -0
- package/apps/web/dist/assets/{oss-credits-qGhcbqiM.js → oss-credits-Bc05Qv5H.js} +1 -1
- package/apps/web/dist/favicon.svg +2 -1
- package/apps/web/dist/icons/apple-touch-icon.png +0 -0
- package/apps/web/dist/icons/icon-192.png +0 -0
- package/apps/web/dist/icons/icon-512.png +0 -0
- package/apps/web/dist/icons/icon-maskable-512.png +0 -0
- package/apps/web/dist/index.html +3 -3
- package/apps/web/dist/install.ps1 +307 -0
- package/apps/web/dist/mcp/flow.html +33 -88
- package/bin/wizards.mjs +59 -35
- package/package.json +6 -7
- package/plugin/.claude-plugin/plugin.json +1 -1
- package/plugin/hooks/engenty.ts +3 -2
- package/apps/web/dist/assets/changelog-Be0i5Jjw.js +0 -1
- package/apps/web/dist/assets/engenty-WpMi3xwq.js +0 -1
- package/apps/web/dist/assets/fluffy-engenty-DPNHytrz.js +0 -575
- package/apps/web/dist/assets/index-C4aHMcg9.css +0 -1
- package/apps/web/dist/assets/index-C61HAltK.js +0 -14
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{n as t,t as n}from"./jsx-runtime-BNakU3Ej.js";import{A as r,B as i,Br as a,Bt as o,C as s,D as c,E as l,Er as u,F as d,Gn as f,Gr as p,H as m,Hr as h,Ht as g,I as _,It as v,Jt as y,Kt as b,L as x,Lr as S,Lt as C,M as w,N as T,Nr as E,O as D,P as O,Qn as k,Qt as A,R as j,Rt as M,S as ee,T as te,U as N,Ur as ne,Ut as P,V as re,Vr as ie,Vt as F,W as I,Wr as L,Xt as ae,Yn as R,Yt as oe,Zt as se,_ as ce,_r as z,a as le,an as B,ar as V,b as H,cr as U,en as W,er as G,fr as K,ft as ue,g as de,gi as fe,gr as pe,hr as me,ir as q,j as J,k as he,kr as ge,nr as _e,pr as ve,qt as ye,v as Y,w as X,x as be,xr as xe,y as Se,yr as Ce,z as we,zt as Z}from"./ui-DMmT-cSO.js";import{S as Te,_ as Ee,a as De,c as Oe,d as ke,f as Ae,g as je,h as Me,i as Ne,l as Pe,m as Fe,n as Ie,o as Le,p as Re,s as ze,u as Be,v as Ve,x as He,y as Ue}from"./RunDrawer-CJZ_ISAd.js";import{t as We}from"./phone-BjmhIKuT.js";import{n as Ge,r as Ke,t as qe}from"./ReadOnly-CKgSQ2z1.js";import{t as Je}from"./upload-JX9BcMTq.js";import{$ as Ye,Bt as Xe,Gt as Ze,It as Qe,Kt as $e,Lt as et,Mt as tt,Pt as nt,Qt as rt,Xt as it,_t as at,a as ot,an as st,c as ct,ct as lt,d as ut,f as dt,gt as ft,h as pt,ht as mt,kt as ht,l as gt,m as _t,n as vt,p as yt,r as bt,u as xt}from"./index-C61HAltK.js";import{a as St,c as Ct,f as wt,i as Tt,n as Et,o as Dt,r as Ot,s as kt,t as At,u as jt}from"./settings-menu-Dpkp3f56.js";import{t as Mt}from"./RunnerView-BW1h4x63.js";var Nt={name:`blend`,size:24,node:[[`circle`,{cx:`15`,cy:`9`,r:`7`,key:`1i12rt`}],[`circle`,{cx:`9`,cy:`15`,r:`7`,key:`19bs8k`}]]};Nt.node;var Pt=E(Nt),Ft={name:`box`,size:24,node:[[`path`,{d:`M21 8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16Z`,key:`hh9hay`}],[`path`,{d:`m3.3 7 8.7 5 8.7-5`,key:`g66t2b`}],[`path`,{d:`M12 22V12`,key:`d0xqtd`}]]};Ft.node;var It=E(Ft),Lt={name:`case-upper`,size:24,node:[[`path`,{d:`M15 11h4.5a1 1 0 0 1 0 5h-4a.5.5 0 0 1-.5-.5v-9a.5.5 0 0 1 .5-.5h3a1 1 0 0 1 0 5`,key:`nxs35`}],[`path`,{d:`m2 16 4.039-9.69a.5.5 0 0 1 .923 0L11 16`,key:`d5nyq2`}],[`path`,{d:`M3.304 13h6.392`,key:`1q3zxz`}]]};Lt.node;var Rt=E(Lt),zt={name:`folder-plus`,size:24,node:[[`path`,{d:`M12 10v6`,key:`1bos4e`}],[`path`,{d:`M9 13h6`,key:`1uhe8q`}],[`path`,{d:`M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z`,key:`1kt360`}]]};zt.node;var Bt=E(zt),Vt={name:`grid-2x2`,size:24,node:[[`path`,{d:`M12 3v18`,key:`108xh3`}],[`path`,{d:`M3 12h18`,key:`1i2n21`}],[`rect`,{x:`3`,y:`3`,width:`18`,height:`18`,rx:`2`,key:`h1oib`}]],aliases:[`grid-2-x-2`]};Vt.node;var Ht=E(Vt),Ut={name:`layers`,size:24,node:[[`path`,{d:`M12.83 2.18a2 2 0 0 0-1.66 0L2.6 6.08a1 1 0 0 0 0 1.83l8.58 3.91a2 2 0 0 0 1.66 0l8.58-3.9a1 1 0 0 0 0-1.83z`,key:`zw3jo`}],[`path`,{d:`M2 12a1 1 0 0 0 .58.91l8.6 3.91a2 2 0 0 0 1.65 0l8.58-3.9A1 1 0 0 0 22 12`,key:`1wduqc`}],[`path`,{d:`M2 17a1 1 0 0 0 .58.91l8.6 3.91a2 2 0 0 0 1.65 0l8.58-3.9A1 1 0 0 0 22 17`,key:`kqbvx6`}]],aliases:[`layers-3`]};Ut.node;var Wt=E(Ut),Gt={name:`layout-grid`,size:24,node:[[`rect`,{width:`7`,height:`7`,x:`3`,y:`3`,rx:`1`,key:`1g98yp`}],[`rect`,{width:`7`,height:`7`,x:`14`,y:`3`,rx:`1`,key:`6d4xhi`}],[`rect`,{width:`7`,height:`7`,x:`14`,y:`14`,rx:`1`,key:`nxv5o0`}],[`rect`,{width:`7`,height:`7`,x:`3`,y:`14`,rx:`1`,key:`1bb6yr`}]]};Gt.node;var Kt=E(Gt),qt={name:`link`,size:24,node:[[`path`,{d:`M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71`,key:`1cjeqo`}],[`path`,{d:`M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71`,key:`19qd67`}]]};qt.node;var Jt=E(qt),Yt={name:`list`,size:24,node:[[`path`,{d:`M3 5h.01`,key:`18ugdj`}],[`path`,{d:`M3 12h.01`,key:`nlz23k`}],[`path`,{d:`M3 19h.01`,key:`noohij`}],[`path`,{d:`M8 5h13`,key:`1pao27`}],[`path`,{d:`M8 12h13`,key:`1za7za`}],[`path`,{d:`M8 19h13`,key:`m83p4d`}]]};Yt.node;var Xt=E(Yt),Zt={name:`music`,size:24,node:[[`path`,{d:`M9 18V5l12-2v13`,key:`1jmyc2`}],[`circle`,{cx:`6`,cy:`18`,r:`3`,key:`fqmcym`}],[`circle`,{cx:`18`,cy:`16`,r:`3`,key:`1hluhg`}]]};Zt.node;var Qt=E(Zt),$t=L(),Q=e(t(),1),$=e(n(),1),en={backgroundImage:`repeating-conic-gradient(#c9c9c9 0% 25%, #dedede 0% 50%)`,backgroundSize:`16px 16px`};function tn({file:e,actions:t}){let[n,r]=(0,Q.useState)(e.description),i=(0,Q.useRef)(e.description),a=(0,Q.useRef)(null);(0,Q.useEffect)(()=>{e.description!==i.current&&(r(t=>t===i.current?e.description:t),i.current=e.description)},[e.description]),(0,Q.useLayoutEffect)(()=>{let e=a.current;e&&(e.style.height=`auto`,e.style.height=`${e.scrollHeight}px`)},[n]);let o=e.status===`pending`&&!n;return t.readOnly?n?(0,$.jsx)(`p`,{className:`text-[0.8125rem] text-ink-2 leading-snug`,children:n}):null:(0,$.jsx)(`textarea`,{ref:a,rows:1,value:n,maxLength:600,placeholder:B(o?`project.describing`:`project.description`),onChange:e=>r(e.target.value),onBlur:()=>{n.trim()!==e.description&&(i.current=n.trim(),t.describe(e.id,n.trim()))},className:`-mx-1 block w-[calc(100%+0.5rem)] resize-none overflow-hidden rounded-md bg-transparent px-1 py-0.5 text-[0.8125rem] text-ink-2 leading-snug outline-none transition placeholder:text-ink-4 hover:bg-paper-2 focus:bg-card focus:text-ink focus:ring-1 focus:ring-border`})}function nn(e,t){confirm(B(`project.removeConfirm`,{name:e.name}))&&t.remove(e.id)}function rn({projectId:e,file:t,small:n}){let r=we(e,t.id);if(t.mime.startsWith(`image/`))return(0,$.jsx)(`img`,{src:r,alt:``,loading:`lazy`,className:A(`size-full`,t.kind===`logo`?`object-contain p-3`:`object-cover`)});if(t.mime.startsWith(`video/`))return(0,$.jsx)(`video`,{src:`${r}#t=0.1`,preload:`metadata`,controls:!n,className:`size-full object-cover`});if(t.mime.startsWith(`font/`))return(0,$.jsx)(an,{src:r,small:n});let i=n?`size-5`:`size-7`;return(0,$.jsxs)(`div`,{className:`flex size-full flex-col items-center justify-center gap-1.5 text-ink-3`,children:[t.mime.startsWith(`audio/`)?(0,$.jsx)(Qt,{className:i}):t.mime===`application/pdf`?(0,$.jsx)(pe,{className:i}):t.mime===`application/json`?(0,$.jsx)(k,{className:i}):t.mime.startsWith(`model/`)?(0,$.jsx)(It,{className:i}):(0,$.jsx)(me,{className:i}),n?null:(0,$.jsx)(`span`,{className:`text-[0.6875rem] uppercase tracking-wide`,children:t.mime===`application/json`?`Lottie / JSON`:t.mime.split(`/`).pop()})]})}function an({src:e,small:t}){let[n,r]=(0,Q.useState)(null);return(0,Q.useEffect)(()=>{let t=`asset-${e.split(`/`).slice(-2,-1)[0]}`;new FontFace(t,`url("${e}")`).load().then(e=>{document.fonts.add(e),r(t)}).catch(()=>r(null))},[e]),(0,$.jsx)(`div`,{className:A(`flex size-full items-center justify-center text-ink`,t?`text-[1.25rem]`:`text-[2.75rem]`),style:n?{fontFamily:`"${n}"`}:void 0,children:`Aa`})}var on=`application/x-wizards-logo`;function sn({projectId:e,kind:t,files:n,actions:r,accept:i,addLabel:a,onUpload:o,onPreview:s,mainId:c,onMakeMain:l,moveTo:u,onRemove:d}){let f=e=>d?d(e):nn(e,r);return(0,$.jsxs)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(184px,1fr))] gap-3`,children:[n.map(n=>(0,$.jsxs)(`div`,{draggable:u&&!r.readOnly?!0:void 0,onDragStart:e=>e.dataTransfer.setData(on,n.id),className:`group relative flex flex-col gap-1.5 rounded-lg bg-paper p-2 pb-2.5 ring-1 ring-border-soft`,children:[n.id===c?(0,$.jsx)(`span`,{className:`absolute -top-3 left-3 z-10 rounded-full ring-2 ring-card`,children:(0,$.jsx)(M,{tone:`ember`,children:B(`project.logoMain`)})}):null,(0,$.jsxs)(`div`,{className:`relative h-28 overflow-hidden rounded-md bg-paper-2`,style:t===`logo`?en:void 0,children:[s&&n.mime.startsWith(`image/`)?(0,$.jsx)(`button`,{type:`button`,"aria-label":`${B(`project.preview`)}: ${n.name}`,onClick:()=>s(n),className:`block size-full cursor-zoom-in`,children:(0,$.jsx)(rn,{projectId:e,file:n})}):(0,$.jsx)(rn,{projectId:e,file:n}),(0,$.jsxs)(`div`,{className:`absolute top-1 right-1 flex gap-1 opacity-0 transition focus-within:opacity-100 group-hover:opacity-100 coarse:opacity-100`,children:[s?(0,$.jsx)(F,{label:B(`project.preview`),onClick:()=>s(n),className:`size-8 bg-card shadow-soft`,children:(0,$.jsx)(rt,{className:`size-4`})}):null,l&&n.id!==c&&!r.readOnly?(0,$.jsx)(F,{label:B(`project.logoMakeMain`),onClick:()=>l(n),className:`size-8 bg-card shadow-soft`,children:(0,$.jsx)(nt,{className:`size-4`})}):null,u&&!r.readOnly?(0,$.jsx)(be,{options:u.options,value:u.current(n),onChange:e=>u.onMove(n,e),className:`bg-card shadow-soft`}):null,r.readOnly?null:(0,$.jsx)(F,{label:B(`project.remove`),onClick:()=>f(n),className:`size-8 bg-card shadow-soft hover:text-rose`,children:(0,$.jsx)(R,{className:`size-4`})})]})]}),t===`asset`?(0,$.jsx)(`div`,{className:`truncate px-0.5 text-[0.75rem] text-ink-3`,title:n.name,children:n.name}):null,(0,$.jsx)(tn,{file:n,actions:r})]},n.id)),a&&!r.readOnly?(0,$.jsxs)(Se,{accept:i,multiple:!1,onFiles:e=>o?o(e):r.upload(t,e),className:`min-h-28 flex-col p-3`,children:[r.busy?(0,$.jsx)(ye,{className:`size-5`}):(0,$.jsx)(q,{className:`size-5`}),a]}):null]})}function cn({kind:e,fetchUrl:t,onAdded:n,onClose:r}){let[i,a]=(0,Q.useState)(``),[o,s]=(0,Q.useState)(!1),[c,l]=(0,Q.useState)(null),[d,f]=(0,Q.useState)(null),[p,m]=(0,Q.useState)([]),h=async()=>{s(!0),l(null);try{let a=await t(i.trim());a.file?(n([a.file]),r()):a.candidates?.length?(f(a.candidates),m([a.candidates[0].url])):l(B(e===`logo`?`project.logoNoneFound`:`project.assetNoneFound`))}catch(e){l(e.message)}s(!1)},_=async()=>{s(!0),l(null);let e=[];try{for(let n of p){let r=await t(n);r.file&&e.push(r.file)}}catch(e){l(e.message)}s(!1),e.length&&n(e),e.length===p.length&&r()};return(0,$.jsx)(Z,{open:!0,onClose:r,wide:d?!0:void 0,title:B(d?e===`logo`?`project.logoFound`:`project.assetFound`:e===`logo`?`project.logoFromUrl`:`project.assetFromUrl`),children:d?(0,$.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,$.jsx)(`p`,{className:`-mt-2 text-[0.875rem] text-ink-3`,children:B(e===`logo`?`project.logoFoundHint`:`project.assetFoundHint`)}),(0,$.jsx)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(150px,1fr))] gap-3`,children:d.map(t=>{let n=p.includes(t.url);return(0,$.jsxs)(`button`,{type:`button`,"aria-pressed":n,title:t.hint,onClick:()=>m(e=>n?e.filter(e=>e!==t.url):[...e,t.url]),className:A(`relative h-28 overflow-hidden rounded-lg ring-1 transition`,n?`ring-2 ring-ember`:`ring-border-soft hover:ring-ink-4`),style:en,children:[(0,$.jsx)(`img`,{src:t.url,alt:``,className:A(`size-full`,e===`logo`?`object-contain p-3`:`object-cover`)}),n?(0,$.jsx)(`span`,{className:`absolute top-1.5 right-1.5 grid size-5 place-items-center rounded-full bg-ember text-white`,children:(0,$.jsx)(u,{className:`size-3.5`})}):null]},t.url)})}),c?(0,$.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:c}):null,(0,$.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,$.jsx)(v,{variant:`ghost`,onClick:()=>f(null),children:B(`run.back`)}),(0,$.jsx)(v,{busy:o,disabled:!p.length,onClick:()=>void _(),children:p.length>1?B(`project.addMany`,{n:p.length}):B(`project.add`)})]})]}):(0,$.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),h()},className:`flex flex-col gap-5`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(P,{children:B(`project.logoUrl`)}),(0,$.jsx)(g,{autoFocus:!0,value:i,inputMode:`url`,placeholder:`https://example.com`,onChange:e=>a(e.target.value)}),(0,$.jsx)(`p`,{className:`mt-1.5 text-[0.8125rem] text-ink-3`,children:B(e===`logo`?`project.logoUrlHint`:`project.assetUrlHint`)})]}),c?(0,$.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:c}):null,(0,$.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,$.jsx)(v,{variant:`ghost`,onClick:r,children:B(`common.cancel`)}),(0,$.jsx)(v,{type:`submit`,busy:o,disabled:!i.trim(),children:B(`run.next`)})]})]})})}function ln(e,t,n){return p({queryKey:[`project-file-text`,t.id,t.chars,n],queryFn:()=>I.get(`/api/studio/projects/${e}/files/${t.id}/text?limit=${n}`),enabled:t.status===`ready`,staleTime:6e4})}function un(e){return((e.name.includes(`.`)?e.name.split(`.`).pop():``)||e.mime.split(`/`).pop()||``).toUpperCase().slice(0,5)}var dn=e=>[un(e),e.pages?B(`project.pages`,{n:e.pages}):null,f(e.size)].filter(Boolean).join(` · `),fn=2e5;function pn({projectId:e,fileId:t,readOnly:n,onGone:r}){let i=fe(),a=N(e),o=Fe(e),s=re(e,n),c=a.data?.files.find(e=>e.id===t),l=c?c.mime===`application/pdf`||c.mime.startsWith(`image/`):!1,[u,d]=(0,Q.useState)(null);if(!c)return a.isLoading?(0,$.jsx)(ye,{className:`mx-auto text-ink-3`}):null;let f=u??(l?`original`:`text`),p=o.data?.items.find(e=>e.key===`f:${c.id}`),m=we(e,c.id),h=(e,t)=>(0,$.jsx)(`button`,{type:`button`,"aria-pressed":f===e,onClick:()=>d(e),className:A(`rounded-full px-3 py-1 text-[0.8125rem] transition`,f===e?`bg-paper-2 font-medium text-ink`:`text-ink-3 hover:text-ink`),children:t});return(0,$.jsxs)(`section`,{className:`flex flex-col gap-3`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 px-1`,children:[(0,$.jsx)(`h2`,{className:`min-w-0 flex-1 truncate font-display font-semibold text-lg`,children:c.name}),(0,$.jsx)(`span`,{className:`text-[0.8125rem] text-ink-3 max-sm:hidden`,children:dn(c)}),(0,$.jsx)(`a`,{href:m,target:`_blank`,rel:`noreferrer`,"aria-label":B(`project.openOriginal`),title:B(`project.openOriginal`),className:`inline-flex size-9 items-center justify-center rounded-full text-ink-3 transition hover:bg-accent hover:text-ink`,children:(0,$.jsx)(z,{className:`size-4`})}),n?null:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(F,{label:B(`project.reindex`),onClick:async()=>{await s.reindex(c.id),await i.invalidateQueries({queryKey:[`knowledge`,e]})},children:(0,$.jsx)(_e,{className:`size-4`})}),(0,$.jsx)(F,{label:B(`know.deleteFile`),className:`hover:text-rose`,onClick:async()=>{confirm(B(`data.confirmDelete`,{title:c.name}))&&(await s.remove(c.id),await i.invalidateQueries({queryKey:[`knowledge`,e]}),r())},children:(0,$.jsx)(R,{className:`size-4`})})]})]}),(0,$.jsx)(Ae,{projectId:e,itemKey:`f:${c.id}`,has:p?.categories??[],originLabel:p?.originLabel??null,kept:!1,review:null,file:null,readOnly:n,onReviewed:()=>void 0}),(0,$.jsx)(`div`,{className:`px-1`,children:(0,$.jsx)(tn,{file:c,actions:s})}),c.status===`failed`?(0,$.jsx)(`p`,{className:`px-1 text-[0.875rem] text-rose`,children:c.error}):null,(0,$.jsxs)(C,{className:`flex flex-col`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1 border-border-soft border-b px-2 py-1.5`,children:[l?h(`original`,B(`project.original`)):null,h(`text`,B(`project.readText`))]}),f===`original`?c.mime===`application/pdf`?(0,$.jsx)(`iframe`,{src:m,title:c.name,className:`h-[70dvh] w-full rounded-b-xl bg-paper-2`}):(0,$.jsx)(`img`,{src:m,alt:``,className:`mx-auto max-h-[70dvh] object-contain p-4`}):(0,$.jsx)(mn,{projectId:e,file:c})]})]})}function mn({projectId:e,file:t}){let n=ln(e,t,fn);return n.isLoading||t.status===`pending`?(0,$.jsx)(`div`,{className:`flex h-40 items-center justify-center text-ink-3`,children:(0,$.jsx)(ye,{})}):n.data?.text?(0,$.jsxs)(`div`,{className:`overflow-x-auto p-4 sm:p-5`,children:[(0,$.jsx)(ue,{text:n.data.text,className:`text-[0.875rem]`}),n.data.chars>n.data.text.length?(0,$.jsx)(`p`,{className:`mt-3 text-[0.8125rem] text-ink-3`,children:B(`project.textCut`,{shown:n.data.text.length.toLocaleString(W),total:n.data.chars.toLocaleString(W)})}):null]}):(0,$.jsx)(`p`,{className:`py-8 text-center text-[0.875rem] text-ink-3`,children:B(`project.noText`)})}var hn=`image/*,video/*,audio/*,application/pdf,.pdf,.woff2,.woff,.ttf,.otf,.json,.glb,.gltf`,gn=e=>[(e.name.includes(`.`)?e.name.split(`.`).pop():e.mime.split(`/`).pop())?.toUpperCase().slice(0,5),f(e.size)].filter(Boolean).join(` · `);function _n({projectId:e,file:t,actions:n,onClose:r}){let i=we(e,t.id);return(0,$.jsxs)(Z,{open:!0,onClose:r,wide:`page`,title:t.name,children:[(0,$.jsxs)(`div`,{className:`-mt-2 mb-4 flex items-center justify-between gap-3`,children:[(0,$.jsx)(`span`,{className:`text-[0.8125rem] text-ink-3`,children:gn(t)}),(0,$.jsx)(`a`,{href:i,target:`_blank`,rel:`noreferrer`,"aria-label":B(`project.openOriginal`),title:B(`project.openOriginal`),className:`inline-flex size-9 items-center justify-center rounded-full text-ink-3 transition hover:bg-accent hover:text-ink`,children:(0,$.jsx)(z,{className:`size-4`})})]}),t.mime.startsWith(`image/`)?(0,$.jsx)(`div`,{className:`overflow-hidden rounded-lg`,style:en,children:(0,$.jsx)(`img`,{src:i,alt:``,className:`mx-auto max-h-[68dvh] object-contain`})}):t.mime.startsWith(`video/`)?(0,$.jsx)(`video`,{src:i,controls:!0,className:`max-h-[68dvh] w-full rounded-lg bg-black`}):(0,$.jsx)(`audio`,{src:i,controls:!0,className:`w-full`}),(0,$.jsx)(`div`,{className:`mt-4`,children:(0,$.jsx)(tn,{file:t,actions:n})})]})}function vn({projectId:e,file:t,actions:n,moveTo:r,onPreview:i,onRemove:a}){return(0,$.jsxs)(`li`,{className:`group/row flex items-start gap-3 rounded-lg bg-paper p-2 ring-1 ring-border-soft`,children:[(0,$.jsx)(`button`,{type:`button`,"aria-label":`${B(`project.preview`)}: ${t.name}`,onClick:i,className:`size-14 shrink-0 cursor-zoom-in overflow-hidden rounded-md bg-paper-2`,children:(0,$.jsx)(rn,{projectId:e,file:t,small:!0})}),(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col gap-1 py-0.5`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-3`,children:[(0,$.jsx)(`button`,{type:`button`,onClick:i,title:t.name,className:`min-w-0 truncate font-medium text-[0.875rem] hover:underline`,children:t.name}),(0,$.jsx)(`span`,{className:`text-[0.75rem] text-ink-3`,children:gn(t)})]}),(0,$.jsx)(tn,{file:t,actions:n})]}),(0,$.jsxs)(`div`,{className:`flex shrink-0 items-start opacity-0 transition focus-within:opacity-100 group-hover/row:opacity-100 coarse:opacity-100`,children:[(0,$.jsx)(F,{label:B(`project.preview`),onClick:i,children:(0,$.jsx)(rt,{className:`size-4`})}),r&&!n.readOnly?(0,$.jsx)(be,{options:r.options,value:r.current(t),onChange:e=>r.onMove(t,e),className:`size-9`}):null,n.readOnly?null:(0,$.jsx)(F,{label:B(`project.remove`),onClick:a,className:`hover:text-rose`,children:(0,$.jsx)(R,{className:`size-4`})})]})]})}function yn({section:e,onSave:t,onRemove:n,onClose:r}){let[i,a]=(0,Q.useState)(e?.title??``);return(0,$.jsx)(Z,{open:!0,onClose:r,title:B(e?`project.assetSectionRename`:`project.assetSectionAdd`),children:(0,$.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),i.trim()&&(t(i.trim()),r())},className:`flex flex-col gap-5`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(P,{children:B(`project.assetSectionName`)}),(0,$.jsx)(g,{autoFocus:!0,value:i,maxLength:80,placeholder:B(`project.assetSectionTitle`),onChange:e=>a(e.target.value)})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[n?(0,$.jsx)(v,{variant:`danger`,onClick:n,children:B(`project.sectionRemove`)}):null,(0,$.jsx)(`span`,{className:`flex-1`}),(0,$.jsx)(v,{variant:`ghost`,onClick:r,children:B(`common.cancel`)}),(0,$.jsx)(v,{type:`submit`,disabled:!i.trim(),children:B(e?`settings.save`:`project.add`)})]})]})})}function bn({projectId:e,data:t,readOnly:n,sections:r,save:a}){let o=re(e,n),[c,u]=m(`assets`,`cards`),[d,f]=(0,Q.useState)(``),[p,h]=(0,Q.useState)(null),[g,_]=(0,Q.useState)(r),[v,y]=(0,Q.useState)(``),[b,x]=(0,Q.useState)(null),[S,C]=(0,Q.useState)(!1),w=(0,Q.useRef)(null),E=i({assetSections:g},a),D=t.files.filter(e=>e.kind===`asset`),O=new Map(D.map(e=>[e.id,e])),k=new Set(g.flatMap(e=>e.assets)),A=g.find(e=>e.id===v)??null,j=A?A.assets.map(e=>O.get(e)).filter(e=>!!e):D.filter(e=>!k.has(e.id)),M=D.find(e=>e.id===p),ee=d.trim().toLowerCase(),te=ee?j.filter(e=>`${e.name} ${e.description}`.toLowerCase().includes(ee)):j,N=(e,t)=>_(n=>n.map(n=>{let r=n.assets.filter(t=>t!==e);return{...n,assets:n.id===t?[...r,e]:r}})),ne=async e=>{let t=A?.id??null;for(let n of await o.upload(`asset`,e))N(n.id,t)},P=e=>{confirm(B(`project.removeConfirm`,{name:e.name}))&&(o.remove(e.id),N(e.id,null))},ie=g.length?{options:[{value:``,label:B(`project.assetsGeneral`)},...g.map(e=>({value:e.id,label:e.title||B(`project.sectionUntitled`)}))],current:e=>g.find(t=>t.assets.includes(e.id))?.id??``,onMove:(e,t)=>N(e.id,t||null)}:void 0,I=[{label:B(`project.assetUpload`),icon:(0,$.jsx)(Je,{className:`size-4 shrink-0`}),onPick:()=>w.current?.click()},{label:B(`project.assetFromUrl`),icon:(0,$.jsx)(Jt,{className:`size-4 shrink-0`}),onPick:()=>C(!0)},...g.length<T.logoSections?[{label:B(`project.assetSectionAdd`),icon:(0,$.jsx)(Bt,{className:`size-4 shrink-0`}),onPick:()=>x(`new`)}]:[]],L=g.length||D.length?(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsxs)(`div`,{className:`-mx-1 flex min-w-0 flex-1 items-center gap-1 overflow-x-auto px-1 pb-0.5`,children:[g.length?(0,$.jsx)(ae,{value:v,onChange:e=>{y(e),f(``)},label:B(`project.assets`),options:[{id:``,label:B(`project.assetsGeneral`)},...g.map(e=>({id:e.id,label:e.title||B(`project.sectionUntitled`)}))]}):null,A&&!n?(0,$.jsx)(F,{label:B(`project.assetSectionRename`),onClick:()=>x(`current`),children:(0,$.jsx)(V,{className:`size-4`})}):null]}),j.length?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`w-56 max-w-[45%] shrink`,children:(0,$.jsx)(s,{value:d,onChange:f,placeholder:B(`project.assetSearch`)})}),(0,$.jsx)(F,{label:B(c===`list`?`project.viewCards`:`project.viewList`),onClick:u,children:c===`list`?(0,$.jsx)(Kt,{className:`size-4`}):(0,$.jsx)(Xt,{className:`size-4`})})]}):null]}):null;return(0,$.jsxs)(X,{title:B(`project.assets`),hint:B(`project.assetsHint`),save:E,tabs:L,action:n?null:(0,$.jsx)(de,{entries:I}),children:[(0,$.jsx)(`input`,{ref:w,type:`file`,multiple:!0,accept:hn,className:`sr-only`,tabIndex:-1,"aria-hidden":!0,onChange:e=>{let t=Array.from(e.target.files??[]);e.target.value=``,t.length&&ne(t)}}),te.length?c===`cards`?(0,$.jsx)(sn,{projectId:e,kind:`asset`,files:te,actions:o,moveTo:ie,onRemove:P,onPreview:e=>h(e.id)}):(0,$.jsx)(`ul`,{className:`flex flex-col gap-2`,children:te.map(t=>(0,$.jsx)(vn,{projectId:e,file:t,actions:o,moveTo:ie,onPreview:()=>h(t.id),onRemove:()=>P(t)},t.id))}):j.length?null:n?(0,$.jsx)(`p`,{className:`text-[0.875rem] text-ink-3`,children:B(`project.staysLocal`)}):(0,$.jsxs)(Se,{accept:hn,onFiles:e=>void ne(e),className:`h-16 w-full`,children:[o.busy?(0,$.jsx)(ye,{className:`size-4`}):(0,$.jsx)(Je,{className:`size-4`}),B(`project.drop`),` `,(0,$.jsx)(`span`,{className:`underline`,children:B(`project.assetAdd`)})]}),o.error?(0,$.jsx)(`p`,{className:`mt-3 text-[0.875rem] text-rose`,children:o.error}):null,M?(0,$.jsx)(_n,{projectId:e,file:M,actions:o,onClose:()=>h(null)}):null,b?(0,$.jsx)(yn,{section:b===`current`?A:null,onClose:()=>x(null),onSave:e=>{if(b===`current`&&A)_(t=>t.map(t=>t.id===A.id?{...t,title:e}:t));else{let t=l();_(n=>[...n,{id:t,title:e,assets:[]}]),y(t)}},onRemove:b===`current`&&A?()=>{(!A.assets.length||confirm(B(`project.assetSectionRemoveConfirm`,{name:A.title})))&&(_(e=>e.filter(e=>e.id!==A.id)),y(``),x(null))}:void 0}):null,S?(0,$.jsx)(cn,{kind:`asset`,onClose:()=>C(!1),fetchUrl:e=>o.fromUrl(`asset`,e),onAdded:e=>{for(let t of e)N(t.id,A?.id??null)}}):null]})}var xn=/^#[0-9a-fA-F]{6}$/;async function Sn(e,t){let[n,r]=[1920,1080],i=document.createElement(`canvas`);i.width=n,i.height=r;let a=i.getContext(`2d`);if(!a)return;let o=e.angle*Math.PI/180,s;if(e.type===`radial`)s=a.createRadialGradient(n/2,r/2,0,n/2,r/2,Math.hypot(n,r)/2);else if(e.type===`conic`)s=a.createConicGradient(o-Math.PI/2,n/2,r/2);else{let e=Math.abs(n*Math.sin(o))+Math.abs(r*Math.cos(o)),[t,i]=[Math.sin(o)*e/2,-Math.cos(o)*e/2];s=a.createLinearGradient(n/2-t,r/2-i,n/2+t,r/2+i)}for(let t of[...e.stops].sort((e,t)=>e.at-t.at))s.addColorStop(Math.min(1,Math.max(0,t.at/100)),t.color);a.fillStyle=s,a.fillRect(0,0,n,r);let c=await new Promise(e=>i.toBlob(e,`image/png`));if(c){let e=document.createElement(`a`);e.href=URL.createObjectURL(c),e.download=`${t||`gradient`}.png`,e.click(),setTimeout(()=>URL.revokeObjectURL(e.href),5e3)}}var Cn={linear:`project.gradientLinear`,radial:`project.gradientRadial`,conic:`project.gradientConic`};function wn({projectId:e,gradient:t,isNew:n,brand:r,onSave:i,onClose:a}){let[o,s]=(0,Q.useState)(t),[c,l]=(0,Q.useState)(_(t)),[u,d]=(0,Q.useState)(!1),[f,p]=(0,Q.useState)(``),[m,h]=(0,Q.useState)(!1),[b,x]=(0,Q.useState)(null),[S,C]=(0,Q.useState)(!n),T=e=>{s(e),l(_(e)),d(!1)},E=(e,t)=>T({...o,stops:o.stops.map((n,r)=>r===e?{...n,...t}:n)}),D=e=>{let t=[...o.stops].sort((e,t)=>e.at-t.at),n=50,r=-1;for(let e=0;e<t.length-1;e++)t[e+1].at-t[e].at>r&&(r=t[e+1].at-t[e].at,n=Math.round((t[e].at+t[e+1].at)/2));T({...o,stops:[...o.stops,{color:e??t[0]?.color??`#888888`,at:n}]})},O=async()=>{h(!0),x(null);try{let{gradient:t}=await I.post(`/api/studio/projects/${e}/gradients/describe`,{text:f.trim(),...S?{gradient:{name:o.name,type:o.type,angle:o.angle,stops:o.stops}}:{}});T({...o,...t,name:o.name.trim()?o.name:t.name}),p(``),C(!0)}catch(e){x(e.message)}h(!1)};return(0,$.jsx)(Z,{open:!0,onClose:a,wide:!0,title:B(n?`project.gradientNew`:`project.gradientEdit`),children:(0,$.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,$.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),f.trim()&&!m&&O()},children:[(0,$.jsxs)(`div`,{className:`flex gap-2`,children:[(0,$.jsx)(g,{"data-autofocus":n||void 0,value:f,maxLength:1e3,"aria-label":B(`project.gradientDescribe`),placeholder:B(S?`project.gradientDescribeChange`:`project.gradientDescribeNew`),onChange:e=>p(e.target.value),className:`min-w-0 flex-1`}),(0,$.jsxs)(v,{type:`submit`,variant:`secondary`,busy:m,disabled:!f.trim(),children:[(0,$.jsx)(k,{className:`size-4`}),B(S?`project.gradientDescribeApply`:`project.gradientDescribeMake`)]})]}),(0,$.jsx)(`p`,{className:A(`mt-1.5 text-[0.8125rem]`,b?`text-rose`:`text-ink-3`),children:b??B(`project.gradientDescribeHint`)})]}),(0,$.jsx)(`div`,{className:`h-40 rounded-lg ring-1 ring-border-soft`,style:{background:_(o)}}),(0,$.jsxs)(`div`,{className:`grid gap-x-6 gap-y-4 sm:grid-cols-2`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(P,{children:B(`project.gradientName`)}),(0,$.jsx)(g,{value:o.name,maxLength:80,placeholder:B(`project.gradientNamePlaceholder`),onChange:e=>s({...o,name:e.target.value})})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(P,{children:B(`project.fillUseLabel`)}),(0,$.jsx)(g,{value:o.description??``,maxLength:400,placeholder:B(`project.gradientUse`),onChange:e=>s({...o,description:e.target.value})})]})]}),(0,$.jsxs)(`div`,{className:`flex flex-wrap items-end gap-x-6 gap-y-4`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(P,{children:B(`project.gradientType`)}),(0,$.jsx)(`div`,{className:`flex gap-1 rounded-full bg-paper-2 p-0.5 ring-1 ring-border-soft`,children:w.map(e=>(0,$.jsx)(`button`,{type:`button`,"aria-pressed":o.type===e,onClick:()=>T({...o,type:e}),className:A(`h-9 rounded-full px-4 font-medium text-[0.875rem] transition`,o.type===e?`bg-card text-ink shadow-sm`:`text-ink-3 hover:text-ink-2`),children:B(Cn[e])},e))})]}),o.type===`radial`?null:(0,$.jsxs)(`div`,{className:`min-w-56`,children:[(0,$.jsx)(P,{children:B(`project.gradientAngle`)}),(0,$.jsxs)(`div`,{className:`flex h-11 items-center gap-3`,children:[(0,$.jsx)(`input`,{type:`range`,min:0,max:360,value:o.angle,"aria-label":B(`project.gradientAngle`),onChange:e=>T({...o,angle:Number(e.target.value)}),className:`flex-1 accent-ink`}),(0,$.jsxs)(`span`,{className:`w-12 text-right text-[0.875rem] text-ink-2 tabular-nums`,children:[Math.round(o.angle),`°`]})]})]})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(P,{children:B(`project.gradientStops`)}),(0,$.jsx)(`div`,{className:`flex flex-col gap-2`,children:o.stops.map((e,t)=>(0,$.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,$.jsx)(y,{value:xn.test(e.color)?e.color:`#888888`,onChange:e=>E(t,{color:e.target.value})}),(0,$.jsx)(g,{value:e.color,spellCheck:!1,onChange:e=>{let n=e.target.value.trim();xn.test(n)&&E(t,{color:n.toLowerCase()})},className:`w-28 font-mono text-[0.8125rem]`}),(0,$.jsx)(`input`,{type:`range`,min:0,max:100,value:e.at,"aria-label":B(`project.gradientAt`),onChange:e=>E(t,{at:Number(e.target.value)}),className:`flex-1 accent-ink`}),(0,$.jsxs)(`span`,{className:`w-10 text-right text-[0.875rem] text-ink-2 tabular-nums`,children:[Math.round(e.at),`%`]}),(0,$.jsx)(F,{label:B(`project.remove`),disabled:o.stops.length<=2,onClick:()=>T({...o,stops:o.stops.filter((e,n)=>n!==t)}),className:`hover:text-rose`,children:(0,$.jsx)(R,{className:`size-4`})})]},t))}),(0,$.jsxs)(`div`,{className:`mt-3 flex flex-wrap items-center gap-2`,children:[o.stops.length<12?(0,$.jsxs)(v,{variant:`secondary`,size:`sm`,onClick:()=>D(),children:[(0,$.jsx)(q,{className:`size-4`}),` `,B(`project.gradientStopAdd`)]}):null,r.length&&o.stops.length<12?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{className:`ml-2 text-[0.8125rem] text-ink-3`,children:B(`project.gradientFromBrand`)}),r.slice(0,10).map(e=>(0,$.jsx)(`button`,{type:`button`,title:e.name||e.value,"aria-label":e.name||e.value,onClick:()=>D(e.value),className:`size-6 rounded-full ring-1 ring-border transition hover:scale-110`,style:{background:e.value}},e.value))]}):null]})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(P,{children:`CSS`}),(0,$.jsx)(g,{value:c,spellCheck:!1,onChange:e=>{l(e.target.value);let t=j(e.target.value);d(!t),t&&s({...o,...t})},className:`font-mono text-[0.8125rem]`}),(0,$.jsx)(`p`,{className:A(`mt-1.5 text-[0.8125rem]`,u?`text-rose`:`text-ink-3`),children:B(u?`project.gradientCssError`:`project.gradientCssHint`)})]}),(0,$.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,$.jsx)(v,{variant:`ghost`,onClick:a,children:B(`common.cancel`)}),(0,$.jsx)(v,{onClick:()=>{i(o),a()},children:B(`settings.save`)})]})]})})}var Tn=`absolute top-1.5 right-1.5 flex gap-1 opacity-0 transition focus-within:opacity-100 group-hover/card:opacity-100 coarse:opacity-100`,En=`size-8 bg-card shadow-soft hover:bg-card`;function Dn({name:e,namePlaceholder:t,description:n,usePlaceholder:r,readOnly:i,onChange:a}){return i?(0,$.jsxs)(`div`,{className:`min-w-0 px-0.5`,children:[(0,$.jsx)(`p`,{className:`truncate text-[0.875rem]`,children:e||t}),n?(0,$.jsx)(`p`,{className:`text-[0.8125rem] text-ink-3 leading-snug`,children:n}):null]}):(0,$.jsxs)(`div`,{className:`min-w-0 px-0.5`,children:[(0,$.jsx)(H,{value:e,label:B(`project.gradientName`),placeholder:t,maxLength:80,onChange:e=>a({name:e}),className:`font-medium text-[0.875rem]`}),(0,$.jsx)(H,{value:n??``,label:B(`project.fillUseLabel`),placeholder:r,maxLength:400,onChange:e=>a({description:e}),className:`text-[0.8125rem] text-ink-3`})]})}function On({gradient:e,readOnly:t,onEdit:n,onChange:r,onRemove:i}){let a=_(e),[o,s]=(0,Q.useState)(!1);return(0,$.jsxs)(`div`,{className:`group/card flex flex-col gap-2 rounded-lg bg-paper p-2 ring-1 ring-border-soft`,children:[(0,$.jsxs)(`div`,{className:`relative`,children:[(0,$.jsx)(`button`,{type:`button`,disabled:t,"aria-label":B(`project.gradientEdit`),onClick:n,className:`block h-28 w-full rounded-md ring-1 ring-border-soft transition enabled:hover:brightness-105`,style:{background:a}}),(0,$.jsxs)(`div`,{className:Tn,children:[(0,$.jsx)(F,{label:B(o?`project.gradientCopied`:`project.gradientCopy`),onClick:()=>{navigator.clipboard.writeText(`background: ${a};`),s(!0),setTimeout(()=>s(!1),1500)},className:En,children:(0,$.jsx)(xe,{className:`size-4`})}),(0,$.jsx)(F,{label:B(`project.download`),onClick:()=>void Sn(e,e.name),className:En,children:(0,$.jsx)(Ce,{className:`size-4`})}),t?null:(0,$.jsx)(F,{label:B(`project.remove`),onClick:i,className:A(En,`hover:text-rose`),children:(0,$.jsx)(R,{className:`size-4`})})]})]}),(0,$.jsx)(Dn,{name:e.name,namePlaceholder:B(`project.gradientName`),description:e.description,usePlaceholder:B(`project.gradientUse`),readOnly:t,onChange:r})]})}function kn(e,t){return{backgroundImage:`url("${e}")`,backgroundSize:t?`64px`:`cover`,backgroundRepeat:t?`repeat`:`no-repeat`,backgroundPosition:`center`}}function An({projectId:e,pattern:t,fileName:n,readOnly:r,onEdit:i,onChange:a,onRemove:o}){let s=we(e,t.file);return(0,$.jsxs)(`div`,{className:`group/card flex flex-col gap-2 rounded-lg bg-paper p-2 ring-1 ring-border-soft`,children:[(0,$.jsxs)(`div`,{className:`relative`,children:[(0,$.jsx)(`button`,{type:`button`,disabled:r,"aria-label":B(`project.patternEdit`),onClick:i,className:`block h-28 w-full rounded-md ring-1 ring-border-soft transition enabled:hover:brightness-105`,style:kn(s,t.tile)}),(0,$.jsxs)(`div`,{className:Tn,children:[(0,$.jsx)(`a`,{href:s,download:n,"aria-label":B(`project.download`),title:B(`project.download`),className:A(`inline-flex items-center justify-center rounded-full text-ink-3 transition hover:text-ink`,En),children:(0,$.jsx)(Ce,{className:`size-4`})}),r?null:(0,$.jsx)(F,{label:B(`project.remove`),onClick:o,className:A(En,`hover:text-rose`),children:(0,$.jsx)(R,{className:`size-4`})})]})]}),(0,$.jsx)(Dn,{name:t.name,namePlaceholder:n,description:t.description,usePlaceholder:B(`project.patternUse`),readOnly:r,onChange:a})]})}function jn({projectId:e,pattern:t,isNew:n,fileName:r,busy:i,error:a,upload:o,removeFile:s,onSave:c,onClose:l}){let[u,d]=(0,Q.useState)(t),[f,p]=(0,Q.useState)([]),m=async e=>{let t=e[0];if(!t)return;let n=await o(t);n&&(p(e=>[...e,n.id]),d(e=>({...e,file:n.id,name:e.name||n.name.replace(/\.[^.]+$/,``)})))},h=()=>{for(let e of f)s(e);l()};return(0,$.jsx)(Z,{open:!0,onClose:h,wide:!0,title:B(n?`project.patternNew`:`project.patternEdit`),children:(0,$.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[u.file?(0,$.jsx)(`div`,{className:`relative h-40 rounded-lg ring-1 ring-border-soft`,style:kn(we(e,u.file),u.tile),children:(0,$.jsxs)(Se,{accept:`image/*`,multiple:!1,onFiles:e=>void m(e),className:`absolute right-2 bottom-2 h-9 border-solid bg-card px-3.5 text-ink-2 shadow-soft`,children:[i?(0,$.jsx)(ye,{className:`size-4`}):(0,$.jsx)(ve,{className:`size-4`}),B(`project.patternReplace`)]})}):(0,$.jsxs)(Se,{accept:`image/*`,multiple:!1,onFiles:e=>void m(e),className:`h-40 flex-col`,children:[i?(0,$.jsx)(ye,{className:`size-5`}):(0,$.jsx)(ve,{className:`size-5`}),B(`project.patternPick`)]}),(0,$.jsxs)(`div`,{className:`grid gap-x-6 gap-y-4 sm:grid-cols-2`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(P,{children:B(`project.patternName`)}),(0,$.jsx)(g,{value:u.name,maxLength:80,placeholder:u.file?r(u.file):B(`project.patternNamePlaceholder`),onChange:e=>d({...u,name:e.target.value})})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(P,{children:B(`project.fillUseLabel`)}),(0,$.jsx)(g,{value:u.description??``,maxLength:400,placeholder:B(`project.patternUse`),onChange:e=>d({...u,description:e.target.value})})]})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(P,{children:B(`project.patternShow`)}),(0,$.jsx)(`div`,{className:`flex w-fit gap-1 rounded-full bg-paper-2 p-0.5 ring-1 ring-border-soft`,children:[!1,!0].map(e=>(0,$.jsx)(`button`,{type:`button`,"aria-pressed":!!u.tile===e,onClick:()=>d({...u,tile:e||void 0}),className:A(`h-9 rounded-full px-4 font-medium text-[0.875rem] transition`,!!u.tile===e?`bg-card text-ink shadow-sm`:`text-ink-3 hover:text-ink-2`),children:B(e?`project.patternTile`:`project.patternFill`)},String(e)))})]}),(0,$.jsxs)(`div`,{className:`flex items-center justify-end gap-2`,children:[a?(0,$.jsx)(`p`,{className:`mr-auto text-[0.8125rem] text-rose`,children:a}):null,(0,$.jsx)(v,{variant:`ghost`,onClick:h,children:B(`common.cancel`)}),(0,$.jsx)(v,{disabled:!u.file||i,onClick:()=>{for(let e of f.filter(e=>e!==u.file))s(e);t.file&&t.file!==u.file&&s(t.file),c({...u,name:u.name.trim(),description:u.description?.trim()||void 0}),l()},children:B(n?`project.add`:`settings.save`)})]})]})})}var Mn=/^#[0-9a-fA-F]{6}$/;function Nn({projectId:e,onAdd:t,onClose:n}){let[r,i]=(0,Q.useState)(``),[a,o]=(0,Q.useState)(!1),[s,c]=(0,Q.useState)(null),[l,d]=(0,Q.useState)(null),[f,p]=(0,Q.useState)([]),m=async()=>{o(!0),c(null);try{let{colors:t}=await I.post(`/api/studio/projects/${e}/colors/scan`,{url:r.trim()});t.length?(d(t),p([])):c(B(`project.colorsNoneFound`))}catch(e){c(e.message)}o(!1)};return(0,$.jsx)(Z,{open:!0,onClose:n,wide:l?!0:void 0,title:B(l?`project.colorsFound`:`project.colorsFromUrl`),children:l?(0,$.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,$.jsx)(`p`,{className:`-mt-2 text-[0.875rem] text-ink-3`,children:B(`project.colorsFoundHint`)}),(0,$.jsx)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(120px,1fr))] gap-3`,children:l.map(e=>{let t=f.includes(e.value);return(0,$.jsxs)(`button`,{type:`button`,"aria-pressed":t,onClick:()=>p(n=>t?n.filter(t=>t!==e.value):[...n,e.value]),className:A(`relative flex flex-col overflow-hidden rounded-lg text-left ring-1 transition`,t?`ring-2 ring-ember`:`ring-border-soft hover:ring-ink-4`),children:[(0,$.jsx)(`span`,{className:`h-16`,style:{background:e.value}}),(0,$.jsxs)(`span`,{className:`flex flex-col px-2.5 py-2`,children:[(0,$.jsx)(`span`,{className:`truncate text-[0.8125rem] text-ink-2`,children:e.name||`—`}),(0,$.jsx)(`span`,{className:`font-mono text-[0.75rem] text-ink-3`,children:e.value})]}),t?(0,$.jsx)(`span`,{className:`absolute top-1.5 right-1.5 grid size-5 place-items-center rounded-full bg-ember text-white`,children:(0,$.jsx)(u,{className:`size-3.5`})}):null]},e.value)})}),(0,$.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,$.jsx)(v,{variant:`ghost`,onClick:()=>d(null),children:B(`run.back`)}),(0,$.jsx)(v,{disabled:!f.length,onClick:()=>{t(l.filter(e=>f.includes(e.value))),n()},children:f.length>1?B(`project.addMany`,{n:f.length}):B(`project.add`)})]})]}):(0,$.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),m()},className:`flex flex-col gap-5`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(P,{children:B(`project.logoUrl`)}),(0,$.jsx)(g,{autoFocus:!0,value:r,inputMode:`url`,placeholder:`https://example.com`,onChange:e=>i(e.target.value)}),(0,$.jsx)(`p`,{className:`mt-1.5 text-[0.8125rem] text-ink-3`,children:B(`project.colorsUrlHint`)})]}),s?(0,$.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:s}):null,(0,$.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,$.jsx)(v,{variant:`ghost`,onClick:n,children:B(`common.cancel`)}),(0,$.jsx)(v,{type:`submit`,busy:a,disabled:!r.trim(),children:B(`run.next`)})]})]})})}function Pn({projectId:e,data:t,colors:n,sections:r,gradients:a,patterns:o,rules:s,sectioned:u,ruled:d,save:f,readOnly:p}){let[m,h]=(0,Q.useState)(()=>n.map(e=>({...e,id:l()}))),[_,v]=(0,Q.useState)(r),[b,x]=(0,Q.useState)(a),[S,C]=(0,Q.useState)(o),[w,E]=(0,Q.useState)(null),[D,O]=(0,Q.useState)(null),k=re(e,p),A=c(s),[j,N]=(0,Q.useState)(null),[ne,P]=(0,Q.useState)(null),[ie,I]=(0,Q.useState)(!1),L=i({colors:m.filter(e=>Mn.test(e.value)).map(({name:e,value:t,section:n})=>({name:e.trim(),value:t,...n?{section:n}:{}})),colorSections:_,gradients:b,patterns:S,colorRules:A.rules},f),ae=u?_:[],oe=ae.filter(e=>(e.kind??`colors`)===`colors`),se=e=>oe.some(t=>t.id===e.section),z=m.filter(e=>!se(e)),le=(z[0]??m[0])?.id,V=(e,t)=>h(n=>n.map(n=>n.id===e?{...n,...t}:n)),H=e=>h(t=>[...t,...e.map(e=>({...e,id:l()}))].slice(0,T.colors)),U=[{value:``,label:B(`project.sectionStandard`)},...oe.map(e=>({value:e.id,label:e.title||B(`project.sectionUntitled`)}))],W=(e,t)=>{let n=l();N(n),v(r=>[...r,{id:n,title:t,...e===`colors`?{}:{kind:e}}])},G=e=>({id:l(),name:``,section:e,type:`linear`,angle:90,stops:[{color:m[0]?.value&&Mn.test(m[0].value)?m[0].value:`#4b73ff`,at:0},{color:m[1]?.value&&Mn.test(m[1].value)?m[1].value:`#ff6d1b`,at:100}]}),K=e=>t.files.find(t=>t.id===e)?.name??`pattern`,ue=[...m.length<T.colors?[{label:B(`project.colorNew`),icon:(0,$.jsx)(q,{className:`size-4 shrink-0`}),onPick:()=>pe()},{label:B(`project.colorsFromUrl`),icon:(0,$.jsx)(Jt,{className:`size-4 shrink-0`}),onPick:()=>I(!0)}]:[],...u&&_.length<T.logoSections?[{label:B(`project.colorSectionAdd`),icon:(0,$.jsx)(Bt,{className:`size-4 shrink-0`}),onPick:()=>W(`colors`,``)},{label:B(`project.gradientSectionAdd`),icon:(0,$.jsx)(Pt,{className:`size-4 shrink-0`}),onPick:()=>W(`gradients`,B(`project.gradientSectionTitle`))},{label:B(`project.patternSectionAdd`),icon:(0,$.jsx)(Ht,{className:`size-4 shrink-0`}),onPick:()=>W(`patterns`,B(`project.patternSectionTitle`))}]:[],...!d||A.full?[]:[{label:B(`project.ruleNew`),icon:(0,$.jsx)($e,{className:`size-4 shrink-0`}),onPick:()=>A.add()}]],fe=e=>(0,$.jsxs)(`div`,{className:`group/row flex items-center gap-2`,children:[(0,$.jsx)(y,{value:Mn.test(e.value)?e.value:`#888888`,onChange:t=>V(e.id,{value:t.target.value})}),(0,$.jsx)(g,{value:e.name,autoFocus:e.id===ne,placeholder:B(`project.colorName`),maxLength:120,onChange:t=>V(e.id,{name:t.target.value}),className:`min-w-0 flex-1`}),(0,$.jsx)(g,{value:e.value,placeholder:`#e0531b`,spellCheck:!1,onChange:t=>V(e.id,{value:t.target.value.trim()}),className:`w-28 font-mono text-[0.8125rem]`}),(0,$.jsxs)(`div`,{className:`flex w-28 shrink-0 items-center justify-end max-sm:w-auto`,children:[e.id===le?(0,$.jsx)(`span`,{className:`mr-1 max-sm:hidden`,children:(0,$.jsx)(M,{tone:`ember`,children:B(`project.colorAccent`)})}):p?null:(0,$.jsx)(F,{label:B(`project.colorFirst`),onClick:()=>h(t=>[{...e,section:void 0},...t.filter(t=>t.id!==e.id)]),className:`opacity-0 transition focus:opacity-100 group-hover/row:opacity-100 coarse:opacity-100`,children:(0,$.jsx)(ge,{className:`size-4`})}),p||!oe.length?null:(0,$.jsx)(be,{options:U,value:se(e)?e.section??``:``,onChange:t=>V(e.id,{section:t||void 0}),className:`opacity-0 focus-within:opacity-100 group-hover/row:opacity-100 coarse:opacity-100`}),p?null:(0,$.jsx)(F,{label:B(`project.remove`),onClick:()=>h(t=>t.filter(t=>t.id!==e.id)),className:`opacity-0 transition focus:opacity-100 group-hover/row:opacity-100 coarse:opacity-100 hover:text-rose`,children:(0,$.jsx)(R,{className:`size-4`})})]})]},e.id),pe=e=>{let t=l();P(t),h(n=>[...n,{id:t,name:``,value:`#888888`,...e?{section:e}:{}}])};return(0,$.jsxs)(X,{title:B(`project.colors`),hint:B(`project.colorsHint`),save:L,locked:p,action:p?null:(0,$.jsx)(de,{entries:ue}),children:[(0,$.jsxs)(`div`,{className:`flex flex-col gap-7`,children:[z.length?(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:`flex flex-col gap-2`,children:z.map(fe)}),p?null:(0,$.jsx)(`p`,{className:`mt-1.5 text-[0.8125rem] text-ink-3`,children:B(`project.colorUse`)})]}):m.length?null:(0,$.jsx)(`p`,{className:`text-[0.875rem] text-ink-3`,children:B(`project.colorsEmpty`)}),ae.map(t=>{let n=t.kind??`colors`,r=m.filter(e=>e.section===t.id),i=b.filter(e=>e.section===t.id),a=S.filter(e=>e.section===t.id),o=n===`gradients`?i.length:n===`patterns`?a.length:r.length;return(0,$.jsxs)(`div`,{className:`group/section flex flex-col gap-3`,children:[(0,$.jsx)(te,{title:t.title,titlePlaceholder:B(n===`gradients`?`project.gradientSectionTitlePlaceholder`:n===`patterns`?`project.patternSectionTitlePlaceholder`:`project.colorSectionTitle`),kind:n===`gradients`?{icon:(0,$.jsx)(Pt,{}),label:B(`project.kindGradients`)}:n===`patterns`?{icon:(0,$.jsx)(Ht,{}),label:B(`project.kindPatterns`)}:{icon:(0,$.jsx)(Xe,{}),label:B(`project.kindColors`)},autoFocus:j===t.id,readOnly:p,onChange:e=>v(n=>n.map(n=>n.id===t.id?{...n,...e}:n)),onRemove:()=>{if(!o||confirm(B(n===`colors`?`project.colorSectionRemoveConfirm`:`project.fillSectionRemoveConfirm`,{name:t.title||B(`project.sectionUntitled`)}))){v(e=>e.filter(e=>e.id!==t.id)),h(e=>e.map(e=>e.section===t.id?{...e,section:void 0}:e)),x(e=>e.filter(e=>e.section!==t.id));for(let e of a)k.remove(e.file);C(e=>e.filter(e=>e.section!==t.id))}}}),n===`gradients`?(0,$.jsxs)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(200px,1fr))] gap-3`,children:[i.map(e=>(0,$.jsx)(On,{gradient:e,readOnly:p,onEdit:()=>E(e),onChange:t=>x(n=>n.map(n=>n.id===e.id?{...n,...t}:n)),onRemove:()=>x(t=>t.filter(t=>t.id!==e.id))},e.id)),p||b.length>=T.gradients?null:(0,$.jsxs)(`button`,{type:`button`,onClick:()=>E(G(t.id)),className:`flex min-h-28 flex-col items-center justify-center gap-2 rounded-lg border border-input border-dashed text-[0.875rem] text-ink-3 transition hover:border-ink-4 hover:text-ink`,children:[(0,$.jsx)(q,{className:`size-5`}),B(`project.gradientAdd`)]})]}):n===`patterns`?(0,$.jsxs)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(200px,1fr))] gap-3`,children:[a.map(t=>(0,$.jsx)(An,{projectId:e,pattern:t,fileName:K(t.file),readOnly:p,onEdit:()=>O(t),onChange:e=>C(n=>n.map(n=>n.id===t.id?{...n,...e}:n)),onRemove:()=>{k.remove(t.file),C(e=>e.filter(e=>e.id!==t.id))}},t.id)),p||S.length>=T.files.pattern?null:(0,$.jsxs)(`button`,{type:`button`,onClick:()=>O({id:l(),name:``,section:t.id,file:``}),className:`flex min-h-28 flex-col items-center justify-center gap-2 rounded-lg border border-input border-dashed text-[0.875rem] text-ink-3 transition hover:border-ink-4 hover:text-ink`,children:[(0,$.jsx)(q,{className:`size-5`}),B(`project.patternAdd`)]})]}):(0,$.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[r.map(fe),p||m.length>=T.colors?null:(0,$.jsx)(ce,{label:B(`project.colorAdd`),onClick:()=>pe(t.id)})]})]},t.id)}),d?(0,$.jsx)(ee,{rules:A,placeholder:B(`project.colorRulePlaceholder`),readOnly:p}):null]}),k.error?(0,$.jsx)(`p`,{className:`mt-3 text-[0.875rem] text-rose`,children:k.error}):null,w?(0,$.jsx)(wn,{projectId:e,gradient:w,isNew:!b.some(e=>e.id===w.id),brand:m.filter(e=>Mn.test(e.value)),onClose:()=>E(null),onSave:e=>x(t=>t.some(t=>t.id===e.id)?t.map(t=>t.id===e.id?e:t):[...t,e])}):null,D?(0,$.jsx)(jn,{projectId:e,pattern:D,isNew:!S.some(e=>e.id===D.id),fileName:K,busy:k.busy,error:k.error,upload:async e=>(await k.upload(`pattern`,[e]))[0]??null,removeFile:e=>void k.remove(e),onClose:()=>O(null),onSave:e=>C(t=>t.some(t=>t.id===e.id)?t.map(t=>t.id===e.id?e:t):[...t,e])}):null,ie?(0,$.jsx)(Nn,{projectId:e,onClose:()=>I(!1),onAdd:H}):null]})}var Fn=e=>/^(ja|yes|true)$/i.test(e.trim()),In={text:tt,longtext:Ke,number:He,date:Te,url:K,email:Ze,phone:We,boolean:Ue};function Ln({type:e,detected:t,onChange:n}){let[r,i]=(0,Q.useState)(!1),[a,o]=(0,Q.useState)(!1),s=(0,Q.useRef)(null);(0,Q.useEffect)(()=>{if(!r)return;let e=e=>{s.current?.contains(e.target)||i(!1)},t=e=>e.key===`Escape`&&i(!1);return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[r]);let c=In[e??t],l=`${B(`project.factType`)}: ${B(`project.type.${e??t}`)}`,d=`flex w-full items-center gap-3 rounded-lg px-3 py-2 text-left text-[0.875rem] text-ink-2 hover:bg-accent hover:text-ink`,f=e=>{n(e),i(!1)};return(0,$.jsxs)(`div`,{className:`relative`,ref:s,children:[(0,$.jsx)(`button`,{type:`button`,"aria-label":l,title:l,"aria-haspopup":`menu`,"aria-expanded":r,onClick:e=>{o(window.innerHeight-e.currentTarget.getBoundingClientRect().bottom<400),i(e=>!e)},className:A(`inline-flex size-11 items-center justify-center rounded-lg transition hover:bg-accent hover:text-ink`,r?`bg-accent text-ink`:e?`text-ink-2`:`text-ink-4`),children:(0,$.jsx)(c,{className:`size-4`})}),r?(0,$.jsxs)(`div`,{role:`menu`,className:A(`absolute right-0 z-50 w-56 animate-rise rounded-xl bg-card p-1.5 shadow-overlay ring-1 ring-border-soft`,a?`bottom-12`:`top-12`),children:[(0,$.jsxs)(`button`,{type:`button`,role:`menuitemradio`,"aria-checked":!e,className:d,onClick:()=>f(void 0),children:[(0,$.jsx)(ht,{className:`size-4 shrink-0`}),(0,$.jsx)(`span`,{className:`flex-1`,children:B(`project.factAuto`)}),(0,$.jsx)(`span`,{className:`text-[0.75rem] text-ink-4`,children:B(`project.type.${t}`)}),(0,$.jsx)(u,{className:A(`size-4 shrink-0`,e&&`invisible`)})]}),(0,$.jsx)(`div`,{className:`mx-2 my-1 h-px bg-border-soft`}),he.map(t=>{let n=In[t];return(0,$.jsxs)(`button`,{type:`button`,role:`menuitemradio`,"aria-checked":e===t,className:d,onClick:()=>f(t),children:[(0,$.jsx)(n,{className:`size-4 shrink-0`}),(0,$.jsx)(`span`,{className:`flex-1`,children:B(`project.type.${t}`)}),(0,$.jsx)(u,{className:A(`size-4 shrink-0`,e!==t&&`invisible`)})]},t)})]}):null]})}function Rn({facts:e,save:t,readOnly:n}){let r=(0,Q.useRef)(0),a=(0,Q.useRef)(null),[o,s]=(0,Q.useState)(()=>e.map(e=>({...e,id:`f${r.current++}`}))),c=i(o.filter(e=>e.key&&e.label.trim()).map(({key:e,label:t,value:n,type:r})=>({key:e,label:t.trim(),value:n,...r?{type:r}:{}})),t),l=(e,t)=>s(n=>n.map(n=>n.id===e?{...n,...t}:n)),u=(e,t,n=!1)=>{let i=`f${r.current++}`;a.current=`${i}:${t}`;let o={id:i,key:``,label:``,value:``,...e};s(e=>n?[o,...e]:[...e,o])},f=e=>t=>{t&&a.current===e&&(a.current=null,t.focus())},p=D.filter(e=>!o.some(t=>t.key===e));return(0,$.jsxs)(X,{title:B(`project.facts`),hint:B(`project.factsHint`),save:c,locked:n,action:o.length<T.facts&&!n?(0,$.jsxs)(v,{variant:`secondary`,size:`sm`,onClick:()=>u({},`label`,!0),children:[(0,$.jsx)(q,{className:`size-4`}),` `,B(`project.factAdd`)]}):null,children:[(0,$.jsx)(`div`,{className:`flex flex-col gap-2`,children:o.map(e=>{let t=O(e.value),r=e.type??t;return(0,$.jsxs)(`div`,{className:`grid grid-cols-[minmax(0,1fr)_auto_auto] items-start gap-x-1 gap-y-2 sm:grid-cols-[minmax(0,2fr)_minmax(0,3fr)_auto_auto]`,children:[(0,$.jsx)(g,{ref:f(`${e.id}:label`),value:e.label,placeholder:B(`project.factLabel`),title:e.key?`{{facts.${e.key}}}`:void 0,onChange:t=>l(e.id,{label:t.target.value}),onBlur:()=>{!e.key&&e.label.trim()&&l(e.id,{key:d(e.label,o.map(e=>e.key))})},className:`max-sm:col-span-3 max-sm:font-medium sm:mr-1`}),e.type===`boolean`?(0,$.jsxs)(`div`,{className:`flex h-11 items-center gap-3`,children:[(0,$.jsx)(oe,{checked:Fn(e.value),label:e.label,onChange:t=>l(e.id,{value:B(t?`project.yes`:`project.no`)})}),(0,$.jsx)(`span`,{className:`text-[0.875rem] text-ink-2`,children:Fn(e.value)?B(`project.yes`):B(`project.no`)})]}):(0,$.jsx)(se,{ref:f(`${e.id}:value`),rows:1,minRows:r===`longtext`?2:1,maxRows:10,value:e.value,placeholder:B(`project.factValue`),onChange:t=>l(e.id,{value:t.target.value}),className:`min-h-11`}),(0,$.jsx)(Ln,{type:e.type,detected:t,onChange:t=>l(e.id,{type:t})}),n?null:(0,$.jsx)(F,{label:B(`project.remove`),onClick:()=>s(t=>t.filter(t=>t.id!==e.id)),className:`size-11 rounded-lg hover:text-rose`,children:(0,$.jsx)(R,{className:`size-4`})})]},e.id)})}),o.length<T.facts&&!n?(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 ${o.length?`mt-4`:``}`,children:[(0,$.jsxs)(v,{variant:`secondary`,size:`sm`,onClick:()=>u({},`label`),children:[(0,$.jsx)(q,{className:`size-4`}),` `,B(`project.factAdd`)]}),p.map(e=>(0,$.jsxs)(`button`,{type:`button`,onClick:()=>u({key:e,label:B(`fact.${e}`)},`value`),className:`inline-flex h-8 items-center gap-1 rounded-full bg-paper-2 px-3 text-[0.8125rem] text-ink-2 transition hover:bg-paper-3 hover:text-ink`,children:[(0,$.jsx)(q,{className:`size-3.5`}),` `,B(`fact.${e}`)]},e))]}):null]})}function zn({onLogo:e,children:t,className:n}){let[r,i]=(0,Q.useState)(!1);return e?(0,$.jsx)(`div`,{onDragOver:e=>{e.dataTransfer.types.includes(`application/x-wizards-logo`)&&(e.preventDefault(),i(!0))},onDragLeave:()=>i(!1),onDrop:t=>{let n=t.dataTransfer.getData(on);i(!1),n&&(t.preventDefault(),e(n))},className:A(`-m-2 rounded-xl p-2 transition`,r&&`bg-paper-2 ring-1 ring-focus`,n),children:t}):(0,$.jsx)(`div`,{className:n,children:t})}function Bn({projectId:e,data:t,readOnly:n,sections:r,rules:a,sectioned:o,ruled:s,save:u}){let d=re(e,n),[f,p]=(0,Q.useState)(r),m=c(a),[h,g]=(0,Q.useState)(null),[_,v]=(0,Q.useState)(!1),y=(0,Q.useRef)(null),b=i({logoSections:f,logoRules:m.rules},u),S=t.files.filter(e=>e.kind===`logo`),C=new Map(S.map(e=>[e.id,e])),w=o?f:[],E=new Set(w.flatMap(e=>e.logos)),D=S.filter(e=>!E.has(e.id)),O=x(S,f)?.id,k=(e,t)=>p(n=>n.map(n=>{let r=n.logos.filter(t=>t!==e);return{...n,logos:n.id===t?[...r,e]:r}})),A=(e,t)=>p(n=>n.map(n=>n.id===e?{...n,...t}:n)),j=async(e,t)=>{let n=await d.upload(`logo`,e);for(let e of n)k(e.id,t)},M=w.length?{options:[{value:``,label:B(`project.sectionStandard`)},...w.map(e=>({value:e.id,label:e.title||B(`project.sectionUntitled`)}))],current:e=>w.find(t=>t.logos.includes(e.id))?.id??``,onMove:(e,t)=>k(e.id,t||null)}:void 0,N=(t,n,r)=>(0,$.jsx)(sn,{projectId:e,kind:`logo`,files:t,actions:d,accept:`image/*`,addLabel:r?B(`project.logoAdd`):void 0,onUpload:e=>void j(e,n),mainId:O,onMakeMain:e=>{k(e.id,null),d.order(`logo`,[e.id,...S.filter(t=>t.id!==e.id).map(e=>e.id)])},moveTo:M,onRemove:e=>{confirm(B(`project.removeConfirm`,{name:e.name}))&&(d.remove(e.id),k(e.id,null))}}),ne=n?void 0:e=>t=>k(t,e),P=[{label:B(`project.logoUpload`),icon:(0,$.jsx)(Je,{className:`size-4 shrink-0`}),onPick:()=>y.current?.click()},{label:B(`project.logoFromUrl`),icon:(0,$.jsx)(Jt,{className:`size-4 shrink-0`}),onPick:()=>v(!0)},...o&&f.length<T.logoSections?[{label:B(`project.logoSectionAdd`),icon:(0,$.jsx)(Bt,{className:`size-4 shrink-0`}),onPick:()=>{let e=l();g(e),p(t=>[...t,{id:e,title:``,description:``,logos:[]}])}}]:[],...!s||m.full?[]:[{label:B(`project.ruleNew`),icon:(0,$.jsx)($e,{className:`size-4 shrink-0`}),onPick:()=>m.add()}]];return(0,$.jsxs)(X,{title:B(`project.logos`),hint:B(`project.logosHint`),save:b,action:n?null:(0,$.jsx)(de,{entries:P}),children:[(0,$.jsx)(`input`,{ref:y,type:`file`,accept:`image/*`,className:`sr-only`,tabIndex:-1,"aria-hidden":!0,onChange:e=>{let t=Array.from(e.target.files??[]);e.target.value=``,t.length&&j(t,null)}}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-7`,children:[(0,$.jsx)(zn,{onLogo:ne?.(null),children:N(D,null,!0)}),w.map(e=>(0,$.jsx)(`div`,{className:`group/section`,children:(0,$.jsxs)(zn,{onLogo:ne?.(e.id),className:`flex flex-col gap-3`,children:[(0,$.jsx)(te,{title:e.title,description:e.description,titlePlaceholder:B(`project.logoSectionTitle`),descriptionPlaceholder:B(`project.logoSectionUse`),autoFocus:h===e.id,readOnly:n,onChange:t=>A(e.id,t),onRemove:()=>{(!e.logos.length||confirm(B(`project.logoSectionRemoveConfirm`,{name:e.title||B(`project.sectionUntitled`)})))&&p(t=>t.filter(t=>t.id!==e.id))}}),N(e.logos.map(e=>C.get(e)).filter(e=>!!e),e.id,!0)]})},e.id)),s?(0,$.jsx)(ee,{rules:m,placeholder:B(`project.logoRulePlaceholder`),readOnly:n}):null]}),d.error?(0,$.jsx)(`p`,{className:`mt-3 text-[0.875rem] text-rose`,children:d.error}):null,_?(0,$.jsx)(cn,{kind:`logo`,onClose:()=>v(!1),fetchUrl:e=>d.fromUrl(`logo`,e),onAdded:e=>{for(let t of e)k(t.id,null)}}):null]})}var Vn=new Set;function Hn(e){(0,Q.useEffect)(()=>{let t=e.trim().toLowerCase().replace(/\s+/g,`-`);if(!t||Vn.has(t))return;Vn.add(t);let n=document.createElement(`link`);n.rel=`stylesheet`,n.href=`https://fonts.bunny.net/css?family=${encodeURIComponent(t)}:${J.join(`,`)}&display=swap`,document.head.append(n)},[e])}var Un=e=>e?`"${e}", system-ui, sans-serif`:`system-ui, sans-serif`;function Wn({unit:e,label:t,...n}){return(0,$.jsxs)(`label`,{className:`inline-flex items-center gap-1 text-[0.75rem] text-ink-3`,title:t,children:[(0,$.jsx)(`input`,{type:`number`,"aria-label":t,className:`h-8 w-14 rounded-md border border-input bg-card px-1.5 text-right text-[0.8125rem] text-ink tabular-nums outline-none transition focus:border-focus focus:ring-2 focus:ring-focus-glow`,...n}),e]})}var Gn=`h-8 rounded-md border border-input bg-card px-1.5 text-[0.8125rem] text-ink outline-none transition focus:border-focus focus:ring-2 focus:ring-focus-glow`,Kn={web:`project.fontUseWeb`,documents:`project.fontUseDocuments`,print:`project.fontUsePrint`,images:`project.fontUseImages`,video:`project.fontUseVideo`};function qn({font:e,first:t,readOnly:n,autoFocus:i,onChange:a,onRemove:o}){return Hn(e.family),(0,$.jsxs)(`div`,{className:`group/font relative flex flex-col gap-2 rounded-lg bg-paper p-3 ring-1 ring-border-soft`,children:[(0,$.jsxs)(`div`,{className:`flex h-28 items-end justify-between overflow-hidden rounded-md bg-card px-4 pb-3 ring-1 ring-border-soft`,style:{fontFamily:Un(e.family)},children:[(0,$.jsx)(`span`,{className:`text-[3.5rem] text-ink leading-none`,children:`Aa`}),(0,$.jsx)(`span`,{className:`truncate pl-3 text-[0.875rem] text-ink-3`,children:`ABCDEFG abcdefg 0123456789`})]}),n?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`font-medium text-[0.9375rem]`,children:e.family}),e.role?(0,$.jsx)(`p`,{className:`text-[0.875rem] text-ink-3`,children:e.role}):null]}):(0,$.jsxs)(`div`,{children:[(0,$.jsx)(H,{value:e.family,label:B(`project.fontFamily`),placeholder:B(`project.fontFamily`),maxLength:80,autoFocus:i,onChange:e=>a({family:e}),className:`font-medium text-[0.9375rem]`}),(0,$.jsx)(H,{value:e.role,label:B(`project.fontRole`),placeholder:B(t?`project.fontRoleFirst`:`project.fontRole`),maxLength:200,onChange:e=>a({role:e}),className:`text-[0.875rem] text-ink-3`})]}),(0,$.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:J.map(t=>{let r=e.weights.includes(t);return(0,$.jsx)(`button`,{type:`button`,disabled:n,"aria-pressed":r,onClick:()=>a({weights:r?e.weights.filter(e=>e!==t):[...e.weights,t].sort((e,t)=>e-t)}),style:{fontFamily:Un(e.family),fontWeight:t},className:A(`h-7 rounded-full px-2.5 text-[0.8125rem] tabular-nums transition`,r?`bg-ink text-paper`:`bg-paper-2 text-ink-3 hover:text-ink`,n&&!r&&`hidden`),children:t},t)})}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[n?e.license?(0,$.jsx)(`p`,{className:`text-[0.8125rem] text-ink-3`,children:e.license}):null:(0,$.jsx)(H,{value:e.license??``,label:B(`project.fontLicense`),placeholder:B(`project.fontLicensePlaceholder`),maxLength:200,onChange:e=>a({license:e}),className:`text-[0.8125rem] text-ink-3`}),n&&!e.uses?.length?null:(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1`,children:[(0,$.jsx)(`span`,{className:`mr-1 text-[0.8125rem] text-ink-3`,children:B(`project.fontUses`)}),r.map(t=>{let i=!!e.uses?.includes(t);return(0,$.jsxs)(`button`,{type:`button`,disabled:n,"aria-pressed":i,onClick:()=>{let n=i?(e.uses??[]).filter(e=>e!==t):r.filter(n=>n===t||e.uses?.includes(n));a({uses:n.length?n:void 0})},className:A(`inline-flex h-7 items-center gap-1 rounded-full px-2.5 text-[0.8125rem] transition`,i?`bg-card text-ink ring-1 ring-border`:`bg-paper-2 text-ink-3 hover:text-ink`,n&&!i&&`hidden`),children:[i?(0,$.jsx)(u,{className:`size-3.5`}):null,B(Kn[t])]},t)})]})]}),n?null:(0,$.jsx)(F,{label:B(`project.remove`),onClick:o,className:`absolute top-4 right-4 size-8 bg-card opacity-0 shadow-soft transition focus:opacity-100 group-hover/font:opacity-100 coarse:opacity-100 hover:text-rose`,children:(0,$.jsx)(R,{className:`size-4`})})]})}function Jn({style:e,fonts:t,sample:n,readOnly:r,autoFocus:i,onChange:a,onRemove:o}){let s=t.find(t=>t.id===e.font)??t[0],c={fontFamily:Un(s?.family),fontWeight:e.weight,fontSize:`${Math.min(e.size,56)}px`,lineHeight:`${e.lineHeight}%`,letterSpacing:`${e.tracking/100}em`,textTransform:e.uppercase?`uppercase`:void 0};return(0,$.jsxs)(`li`,{className:`group/row flex flex-col gap-2 border-border-soft border-b py-4 first:pt-1 last:border-b-0`,children:[(0,$.jsx)(`div`,{className:`truncate text-ink`,style:c,children:n}),(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-2`,children:[r?(0,$.jsx)(`span`,{className:`font-medium text-[0.8125rem] text-ink-2 uppercase tracking-wide`,children:e.name}):(0,$.jsx)(`div`,{className:`w-40`,children:(0,$.jsx)(H,{value:e.name,label:B(`project.styleName`),placeholder:B(`project.styleName`),maxLength:60,autoFocus:i,onChange:e=>a({name:e}),className:`font-medium text-[0.8125rem] text-ink-2 uppercase tracking-wide`})}),(0,$.jsxs)(`fieldset`,{disabled:r,className:`flex flex-wrap items-center gap-x-3 gap-y-2`,children:[t.length>1?(0,$.jsx)(`select`,{"aria-label":B(`project.styleFont`),value:s?.id??``,onChange:e=>a({font:e.target.value}),className:A(Gn,`max-w-40`),children:t.map(e=>(0,$.jsx)(`option`,{value:e.id,children:e.family||B(`project.fontFamily`)},e.id))}):null,(0,$.jsx)(`select`,{"aria-label":B(`project.styleWeight`),value:e.weight,onChange:e=>a({weight:Number(e.target.value)}),className:Gn,children:[...new Set([...J,e.weight])].sort().map(e=>(0,$.jsx)(`option`,{value:e,children:e},e))}),(0,$.jsx)(Wn,{unit:`px`,label:B(`project.styleSize`),min:6,max:400,value:e.size,onChange:e=>a({size:Number(e.target.value)||16})}),(0,$.jsx)(Wn,{unit:B(`project.styleLine`),label:B(`project.styleLineLabel`),min:50,max:300,value:e.lineHeight,onChange:e=>a({lineHeight:Number(e.target.value)||100})}),(0,$.jsx)(Wn,{unit:B(`project.styleTracking`),label:B(`project.styleTrackingLabel`),min:-20,max:50,step:.5,value:e.tracking,onChange:e=>a({tracking:Number(e.target.value)||0})}),(0,$.jsx)(`button`,{type:`button`,"aria-pressed":!!e.uppercase,title:B(`project.styleUpper`),"aria-label":B(`project.styleUpper`),onClick:()=>a({uppercase:!e.uppercase}),className:A(`grid size-8 place-items-center rounded-md transition`,e.uppercase?`bg-ink text-paper`:`text-ink-3 hover:bg-paper-2 hover:text-ink`),children:(0,$.jsx)(Rt,{className:`size-4`})})]}),r?null:(0,$.jsx)(F,{label:B(`project.remove`),onClick:o,className:`ml-auto size-8 opacity-0 transition focus:opacity-100 group-hover/row:opacity-100 coarse:opacity-100 hover:text-rose`,children:(0,$.jsx)(R,{className:`size-4`})})]})]})}function Yn({projectId:e,onAdd:t,onClose:n}){let[r,i]=(0,Q.useState)(``),[a,o]=(0,Q.useState)(!1),[s,c]=(0,Q.useState)(null),[l,u]=(0,Q.useState)(null),[d,f]=(0,Q.useState)([]),p=async()=>{o(!0),c(null);try{let{fonts:t}=await I.post(`/api/studio/projects/${e}/fonts/scan`,{url:r.trim()});t.length?(u(t),f(t.slice(0,2).map(e=>e.family))):c(B(`project.fontsNoneFound`))}catch(e){c(e.message)}o(!1)};return(0,$.jsx)(Z,{open:!0,onClose:n,wide:l?!0:void 0,title:B(l?`project.fontsFound`:`project.fontsFromUrl`),children:l?(0,$.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,$.jsx)(`p`,{className:`-mt-2 text-[0.875rem] text-ink-3`,children:B(`project.fontsFoundHint`)}),(0,$.jsx)(`div`,{className:`flex flex-col gap-2`,children:l.map(e=>(0,$.jsx)(Xn,{font:e,on:d.includes(e.family),onToggle:()=>f(t=>t.includes(e.family)?t.filter(t=>t!==e.family):[...t,e.family])},e.family))}),(0,$.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,$.jsx)(v,{variant:`ghost`,onClick:()=>u(null),children:B(`run.back`)}),(0,$.jsx)(v,{disabled:!d.length,onClick:()=>{t(l.filter(e=>d.includes(e.family))),n()},children:d.length>1?B(`project.addMany`,{n:d.length}):B(`project.add`)})]})]}):(0,$.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),p()},className:`flex flex-col gap-5`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(P,{children:B(`project.logoUrl`)}),(0,$.jsx)(g,{autoFocus:!0,value:r,inputMode:`url`,placeholder:`https://example.com`,onChange:e=>i(e.target.value)}),(0,$.jsx)(`p`,{className:`mt-1.5 text-[0.8125rem] text-ink-3`,children:B(`project.fontsUrlHint`)})]}),s?(0,$.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:s}):null,(0,$.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,$.jsx)(v,{variant:`ghost`,onClick:n,children:B(`common.cancel`)}),(0,$.jsx)(v,{type:`submit`,busy:a,disabled:!r.trim(),children:B(`run.next`)})]})]})})}function Xn({font:e,on:t,onToggle:n}){return Hn(e.family),(0,$.jsxs)(`button`,{type:`button`,"aria-pressed":t,onClick:n,className:A(`flex items-center gap-4 rounded-lg px-4 py-3 text-left ring-1 transition`,t?`ring-2 ring-ember`:`ring-border-soft hover:ring-ink-4`),children:[(0,$.jsx)(`span`,{className:`text-[2rem] text-ink leading-none`,style:{fontFamily:Un(e.family)},children:`Aa`}),(0,$.jsxs)(`span`,{className:`flex min-w-0 flex-1 flex-col`,children:[(0,$.jsx)(`span`,{className:`font-medium text-[0.9375rem]`,children:e.family}),(0,$.jsx)(`span`,{className:`text-[0.8125rem] text-ink-3 tabular-nums`,children:e.weights.length?e.weights.join(` · `):B(`project.fontWeightsUnknown`)})]}),t?(0,$.jsx)(`span`,{className:`grid size-5 place-items-center rounded-full bg-ember text-white`,children:(0,$.jsx)(u,{className:`size-3.5`})}):null]})}function Zn({projectId:e,fonts:t,styles:n,rules:r,ruled:a,sample:o,save:s,readOnly:u}){let[d,f]=(0,Q.useState)(t),[p,m]=(0,Q.useState)(n),h=c(r),[g,_]=(0,Q.useState)(null),[v,y]=(0,Q.useState)(!1),b=i({fonts:d,textStyles:p,typeRules:h.rules},s),x=(e,t=!1)=>{let n=e.map(e=>({id:l(),family:e.family,role:``,weights:e.weights}));t&&n[0]&&_(n[0].id),f(e=>[...e,...n].slice(0,T.fonts))},S=()=>{let e=l();_(e),m(t=>[...t,{id:e,name:``,size:16,weight:400,lineHeight:150,tracking:0}])},C=[...d.length<T.fonts?[{label:B(`project.fontNew`),icon:(0,$.jsx)(q,{className:`size-4 shrink-0`}),onPick:()=>x([{family:``,weights:[400,700]}],!0)},{label:B(`project.fontsFromUrl`),icon:(0,$.jsx)(Jt,{className:`size-4 shrink-0`}),onPick:()=>y(!0)}]:[],...p.length<T.textStyles?[{label:B(`project.styleNew`),icon:(0,$.jsx)(Qe,{className:`size-4 shrink-0`}),onPick:S}]:[],...!a||h.full?[]:[{label:B(`project.ruleNew`),icon:(0,$.jsx)($e,{className:`size-4 shrink-0`}),onPick:()=>h.add()}]];return(0,$.jsxs)(X,{title:B(`project.typography`),hint:B(`project.typographyHint`),save:b,action:u?null:(0,$.jsx)(de,{entries:C}),children:[(0,$.jsxs)(`div`,{className:`flex flex-col gap-7`,children:[d.length?(0,$.jsx)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(260px,1fr))] gap-3`,children:d.map((e,t)=>(0,$.jsx)(qn,{font:e,first:t===0,readOnly:u,autoFocus:g===e.id,onChange:t=>f(n=>n.map(n=>n.id===e.id?{...n,...t}:n)),onRemove:()=>f(t=>t.filter(t=>t.id!==e.id))},e.id))}):(0,$.jsx)(`p`,{className:`text-[0.875rem] text-ink-3`,children:B(`project.fontsEmpty`)}),p.length?(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h3`,{className:`font-medium text-[0.9375rem]`,children:B(`project.styles`)}),u?null:(0,$.jsx)(`p`,{className:`text-[0.875rem] text-ink-3 leading-snug`,children:B(`project.stylesHint`)}),(0,$.jsx)(`ul`,{className:`mt-2 flex flex-col`,children:p.map(e=>(0,$.jsx)(Jn,{style:e,fonts:d,sample:o,readOnly:u,autoFocus:g===e.id,onChange:t=>m(n=>n.map(n=>n.id===e.id?{...n,...t}:n)),onRemove:()=>m(t=>t.filter(t=>t.id!==e.id))},e.id))})]}):null,a?(0,$.jsx)(ee,{rules:h,placeholder:B(`project.typeRulePlaceholder`),readOnly:u}):null]}),v?(0,$.jsx)(Yn,{projectId:e,onClose:()=>y(!1),onAdd:e=>x(e)}):null]})}function Qn({project:e,save:t}){let[n,r]=(0,Q.useState)(e.brand.name??``),[a,o]=(0,Q.useState)(e.brand.about??``),s=i({name:n.trim(),about:a.trim()},e=>t({brand:e}));return(0,$.jsx)(X,{title:B(`project.base`),hint:B(`project.baseHint`),save:s,locked:e.readOnly,children:(0,$.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(P,{children:B(`project.title`)}),(0,$.jsx)(g,{value:n,maxLength:120,onChange:e=>r(e.target.value)}),(0,$.jsx)(`p`,{className:`mt-1.5 text-[0.8125rem] text-ink-3`,children:B(`project.titleHint`)})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(P,{children:B(`project.about`)}),(0,$.jsx)(se,{minRows:4,value:a,onChange:e=>o(e.target.value)}),(0,$.jsx)(`p`,{className:`mt-1.5 text-[0.8125rem] text-ink-3`,children:B(`project.aboutHint`)})]})]})})}function $n({project:e,group:t,children:n}){let r=fe(),i=N(e.id),[a,o]=(0,Q.useState)(0),[s,c]=(0,Q.useState)(!1),l=async t=>{await I.patch(`/api/studio/projects/${e.id}`,t),await r.invalidateQueries({queryKey:[`projects`]})},u=st({mutationFn:()=>I.del(`/api/studio/projects/${e.id}`),onSuccess:()=>r.invalidateQueries({queryKey:[`projects`]})}),d=at(),f=ft(),p=i.data??{files:[],embeddings:!0},m=`${e.id}:${a}`,h=e.readOnly,g=t===`knowledge`,_=lt(`brandSections`),y=lt(`brandRules`),b=lt(`typography`);return Ye(h?{}:{title:B(g?`project.assistantTitleKnowledge`:`project.assistantTitle`),hello:B(g?`project.assistantHelloKnowledge`:`project.assistantHello`),placeholder:B(g?`project.assistantComposerKnowledge`:`project.assistantComposer`),suggestions:g?[{label:B(`assistant.suggest.knowledgeHow`)},{label:B(`assistant.suggest.knowledgeSite`),fill:!0},{label:B(`assistant.suggest.knowledgeCategories`)}]:[{label:B(`assistant.suggest.readSite`),fill:!0},{label:B(`assistant.suggest.missing`)},{label:B(`assistant.suggest.facts`)}],summary:g?void 0:[e.brand.name?`title "${e.brand.name}"`:`no title`,`${e.facts.length} facts`,`${e.brand.colors?.length??0} colours`,`${p.files.filter(e=>e.kind===`logo`).length} logos`].join(` · `),onChanged:()=>o(e=>e+1)}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-9`,children:[h?(0,$.jsx)(qe,{children:Ge(e)}):null,t===`info`?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Y,{id:`base`,children:(0,$.jsx)(Qn,{project:e,save:l},`base:${m}`)}),(0,$.jsx)(Y,{id:`facts`,children:(0,$.jsx)(Rn,{facts:e.facts,save:e=>l({facts:e}),readOnly:h},`facts:${m}`)}),(0,$.jsx)(Y,{id:`logos`,children:(0,$.jsx)(Bn,{projectId:e.id,data:p,readOnly:h,sections:e.brand.logoSections??[],rules:e.brand.logoRules??[],sectioned:_,ruled:y,save:e=>l({brand:e})},`logos:${m}`)}),(0,$.jsx)(Y,{id:`colors`,children:(0,$.jsx)(Pn,{projectId:e.id,data:p,colors:e.brand.colors??[],sections:e.brand.colorSections??[],gradients:e.brand.gradients??[],patterns:e.brand.patterns??[],rules:e.brand.colorRules??[],sectioned:_,ruled:y,save:e=>l({brand:e}),readOnly:h},`colors:${m}`)}),b?(0,$.jsx)(Y,{id:`typography`,children:(0,$.jsx)(Zn,{projectId:e.id,fonts:e.brand.fonts??[],styles:e.brand.textStyles??[],rules:e.brand.typeRules??[],ruled:y,sample:e.brand.name||B(`project.typeSample`),save:e=>l({brand:e}),readOnly:h},`typography:${m}`)}):null,(0,$.jsx)(Y,{id:`assets`,children:(0,$.jsx)(bn,{projectId:e.id,data:p,readOnly:h,sections:e.brand.assetSections??[],save:e=>l({brand:e})},`assets:${m}`)})]}):null,n,t===`info`&&d&&!h&&f?(0,$.jsxs)(`div`,{children:[(0,$.jsx)(v,{variant:`danger`,onClick:()=>c(!0),children:B(`settings.delete`)}),(0,$.jsxs)(Z,{open:s,onClose:()=>c(!1),title:B(`settings.deleteTitle`,{name:e.name}),children:[(0,$.jsx)(`p`,{className:`-mt-2 text-[0.875rem] text-ink-2`,children:B(`settings.deleteBody`)}),u.error?(0,$.jsx)(`p`,{className:`mt-3 text-[0.8125rem] text-rose`,children:u.error.message}):null,(0,$.jsxs)(`div`,{className:`mt-5 flex justify-end gap-2`,children:[(0,$.jsx)(v,{variant:`ghost`,onClick:()=>c(!1),children:B(`common.cancel`)}),(0,$.jsx)(v,{variant:`danger`,busy:u.isPending,onClick:()=>u.mutate(),children:B(`common.delete`)})]})]})]}):null]})}var er={q:``,mode:``,days:0};function tr(e,t,n){let r=new URLSearchParams;t&&r.set(`wizard`,t),n.q.trim()&&r.set(`q`,n.q.trim()),n.mode&&r.set(`mode`,n.mode),n.days&&r.set(`days`,String(n.days));let i=r.toString();return p({queryKey:[`results`,e,i],queryFn:()=>I.get(`/api/studio/projects/${e}/results${i&&`?${i}`}`),enabled:!!e,placeholderData:e=>e,refetchInterval:15e3})}function nr({filter:e,onFilter:t}){let[n,r]=(0,Q.useState)(e.q);return(0,Q.useEffect)(()=>{if(n===e.q)return;let r=setTimeout(()=>t({...e,q:n}),250);return()=>clearTimeout(r)},[n,e,t]),(0,$.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,$.jsxs)(`div`,{className:`relative min-w-0 flex-1 basis-56`,children:[(0,$.jsx)(G,{className:`-translate-y-1/2 pointer-events-none absolute top-1/2 left-3 size-4 text-ink-3`}),(0,$.jsx)(g,{type:`search`,value:n,onChange:e=>r(e.target.value),placeholder:B(`space.resultsSearch`),"aria-label":B(`space.resultsSearch`),className:`w-full pl-9`})]}),(0,$.jsx)(b,{value:e.mode,onChange:n=>t({...e,mode:n}),options:[{value:``,label:B(`space.resultsModeAll`)},{value:`live`,label:`Live`},{value:`test`,label:`Test`}],className:`w-32`}),(0,$.jsx)(b,{value:String(e.days),onChange:n=>t({...e,days:Number(n)}),options:[{value:`0`,label:B(`space.resultsAnyTime`)},{value:`1`,label:B(`space.resultsDay`)},{value:`7`,label:B(`space.resultsDays`,{n:7})},{value:`30`,label:B(`space.resultsDays`,{n:30})}],className:`w-44`})]})}function rr({data:e,wizardId:t,filter:n,onFilter:r}){let[i,a]=(0,Q.useState)(null),s=t=>e.wizards.find(e=>e.id===t)?.title??``,c=new Intl.DateTimeFormat(W,{dateStyle:`medium`,timeStyle:`short`});return(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(X,{title:t?s(t):B(`space.resultsAll`),hint:B(`space.resultsHint`),plain:!0,children:[(0,$.jsx)(nr,{filter:n,onFilter:r}),e.runs.length?(0,$.jsx)(C,{className:`flex flex-col p-1.5`,children:e.runs.map(e=>(0,$.jsxs)(`button`,{type:`button`,onClick:()=>a(e),className:`flex items-center gap-3 rounded-lg px-3 py-2.5 text-left transition hover:bg-accent`,children:[(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`div`,{className:`truncate text-[0.875rem]`,children:t?c.format(new Date(e.doneAt)):s(e.wizardId)}),(0,$.jsxs)(`div`,{className:`truncate text-[0.75rem] text-ink-3`,children:[t?null:`${c.format(new Date(e.doneAt))} · `,B(`space.resultCredits`,{n:e.credits})]})]}),e.assets?(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-[0.75rem] text-ink-3 tabular-nums`,title:B(`space.resultFiles`,{n:e.assets}),children:[(0,$.jsx)(U,{className:`size-3.5`}),e.assets]}):null,e.mode===`test`?(0,$.jsx)(M,{children:B(`run.testChip`)}):(0,$.jsxs)(M,{tone:`live`,children:[`Live v`,e.version]})]},e.id))}):(0,$.jsx)(C,{children:(0,$.jsx)(o,{children:n.q.trim()||n.mode||n.days?B(`space.resultsNone`):B(`space.resultsEmpty`)})})]}),i?(0,$.jsx)(Ie,{header:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-medium text-[0.875rem]`,children:s(i.wizardId)}),i.mode===`test`?(0,$.jsx)(M,{children:B(`run.testChip`)}):(0,$.jsxs)(M,{tone:`live`,children:[`Live v`,i.version]})]}),onClose:()=>a(null),children:(0,$.jsx)(Mt,{runId:i.id,compact:!0,studio:!0},i.id)}):null]})}function ir({project:e,save:t}){let[n,r]=(0,Q.useState)(!1),[i,a]=(0,Q.useState)(e.name),o=st({mutationFn:()=>t({name:i.trim()}),onSuccess:()=>r(!1)});return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(F,{label:B(`project.rename`),onClick:()=>{a(e.name),r(!0)},children:(0,$.jsx)(V,{className:`size-4`})}),(0,$.jsx)(Z,{open:n,onClose:()=>r(!1),title:B(`project.rename`),children:(0,$.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),i.trim()&&o.mutate()},children:[(0,$.jsx)(g,{"data-autofocus":!0,value:i,maxLength:80,onChange:e=>a(e.target.value)}),o.error?(0,$.jsx)(`p`,{className:`mt-3 text-[0.875rem] text-rose`,children:o.error.message}):null,(0,$.jsxs)(`div`,{className:`mt-5 flex justify-end gap-2`,children:[(0,$.jsx)(v,{variant:`ghost`,onClick:()=>r(!1),children:B(`common.cancel`)}),(0,$.jsx)(v,{type:`submit`,busy:o.isPending,disabled:!i.trim(),children:B(`settings.save`)})]})]})})]})}function ar({project:e}){let t=fe();return(0,$.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,$.jsx)(pt,{}),e.readOnly?null:(0,$.jsx)(ir,{project:e,save:async n=>{await I.patch(`/api/studio/projects/${e.id}`,n),await t.invalidateQueries({queryKey:[`projects`]})}})]})}function or(e){let t=e.join(` `),[n,r]=(0,Q.useState)(e[0]);return(0,Q.useEffect)(()=>{let e=t.split(` `),n=0,i=()=>{n=0;let t=ct(),i=t.scrollTop>0&&t.clientHeight+t.scrollTop>=t.scrollHeight-4,a=(t===document.documentElement?0:t.getBoundingClientRect().top)+Math.max(120,t.clientHeight/3),o=e[0];for(let t of e){let e=document.getElementById(t)?.getBoundingClientRect().top;e!==void 0&&e<=a&&(o=t)}r(i?e.at(-1):o)},a=()=>{n||=requestAnimationFrame(i)};return i(),window.addEventListener(`scroll`,a,{passive:!0,capture:!0}),window.addEventListener(`resize`,a),()=>{cancelAnimationFrame(n),window.removeEventListener(`scroll`,a,{capture:!0}),window.removeEventListener(`resize`,a)}},[t]),n}function sr(e,t){let n=window.matchMedia(`(prefers-reduced-motion: reduce)`).matches;document.getElementById(e)?.scrollIntoView({block:`start`,behavior:t&&!n?`smooth`:`auto`})}function cr({groups:e,current:t,onPick:n}){return e.map(e=>{let r=e.sections.map(e=>(0,$.jsx)(St,{icon:e.icon??et,label:e.label,selected:e.id===t,onPick:()=>n(e.id)},e.id));return e.label?(0,$.jsx)(Tt,{label:e.label,children:r},e.plugin):(0,$.jsx)(`ul`,{className:`flex flex-col gap-0.5`,children:r},`own`)})}function lr(){let{group:e}=h(),[t,n]=ne(),r=ie(),i=a(),{hash:s}=i,{project:c,loading:l}=mt(),u=at(),d=ot(),f=jt(),[p,m]=(0,Q.useState)(null),[g,_]=(0,Q.useState)(null),[v,y]=(0,Q.useState)(null),b=ut(e)?e:void 0,x=b?void 0:d.spaceParts.find(t=>t.id===e),C=b??x?.id,w=i.state?.parts===!0,T=_t(yt(),d).map(e=>({...e,to:`/space/${e.id}`})),E=T.find(e=>e.id===C),D=t.get(`show`),O=C?D?2:1:0,k=f?Math.min(O,1):C&&v!==C&&!w?1:0,j=wt(k),M=wt(O),ee=(0,Q.useMemo)(()=>({slot:p,narrow:f,setDetail:_}),[p,f]),te=c?c.brand.name?.trim()||c.name:B(`nav.project`),N=le(),P=!!N&&!f,re=lt(`typography`)?[]:[`typography`],F=x?d.spaceMenus[x.id]??[]:[],I=x?[{plugin:null,label:null,sections:F}]:b&&b!==`results`?dt(b,d,re):[],L=b?dt(b,d).filter(e=>e.plugin):[],ae=or([...I,...b===`results`?L:[]].flatMap(e=>e.sections.map(e=>e.id))),R=b===`results`&&D&&D!==`all`?D:null,[oe,se]=(0,Q.useState)(er),ce=tr(b===`results`?c?.id:void 0,R,oe),z=ce.data?.wizards.find(e=>e.id===R)?.title,V=b===`data`&&D&&D!==`all`||b===`knowledge`&&D&&/^[ptfcvs]:/.test(D)?D:null,H=V?.startsWith(`s:`)?d.spaceSections.find(e=>e.id===V.slice(2)):void 0,U=b===`knowledge`&&V&&/^[ptf]:/.test(V)?V:null,W=Oe(b===`data`?c?.id:void 0),G=Fe(b===`knowledge`?c?.id:void 0),K=Ve(V?.startsWith(`v:`)?V.slice(2):``),ue=G.data?.categories.find(e=>e.id===(V?.startsWith(`c:`)?V.slice(2):K.data?.category.id)),de=b===`knowledge`?H?H.label():V?.startsWith(`v:`)?K.data&&`${K.data.category.name}: ${K.data.value}`:V?.startsWith(`c:`)?ue?.name:G.data?.items.find(e=>e.key===V)?.title:W.data?ze(W.data).flatMap(e=>e.items).find(e=>e.key===V)?.title:void 0;gt([{label:B(`nav.project`),to:`/space`},...E?[{label:E.label,to:`/space/${E.id}`}]:[],...E&&(g??z??de)?[{label:g??z??de}]:[]]);let fe={p:`page`,t:`table`,f:`file`,c:`category`,v:`category value`,s:`plugin section`};Ye({...b===`data`||b===`results`?{compact:!0}:{},...b===`data`?{suggestions:[{label:B(`assistant.suggest.dataWhat`)},{label:B(`assistant.suggest.dataWho`)},{label:B(`assistant.suggest.dataEdit`)}]}:b===`results`?{suggestions:[{label:B(`assistant.suggest.resultsFailed`)},{label:B(`assistant.suggest.resultsCost`)},{label:B(`assistant.suggest.resultsShare`)}]}:{},...V&&de?{open:{kind:fe[V[0]]??`item`,id:V.slice(2),label:de}}:R&&z?{open:{kind:`wizard`,id:R,label:z}}:{}});let pe=b===`results`||b===`data`||V?s.slice(1):D||s.slice(1),me=(0,Q.useRef)(``);if((0,Q.useEffect)(()=>{let e=`${C}#${pe}`;pe&&me.current!==e&&document.getElementById(pe)&&(me.current=e,requestAnimationFrame(()=>sr(pe,!1)))},[C,pe,c?.id,d.spaceSections,F.length]),!C){let t=s.slice(1),n=t?xt(t,d):null;if(n===`knowledge`&&d.spaceSections.some(e=>e.id===t))return(0,$.jsx)(S,{to:`/space/knowledge?show=s:${t}`,replace:!0});if(n)return(0,$.jsx)(S,{to:f?`/space/${n}?show=${t}`:{pathname:`/space/${n}`,hash:t},replace:!0});if((t||e)&&d.status!==`ready`)return null;if(e!==void 0||!f)return(0,$.jsx)(S,{to:`/space/info`,replace:!0,state:{parts:!0}})}if(b===`knowledge`&&!D&&d.spaceSections.some(e=>e.id===s.slice(1)))return(0,$.jsx)(S,{to:`/space/knowledge?show=s:${s.slice(1)}`,replace:!0});let q=e=>{if(f){r({search:`?show=${e}`});return}me.current=`${C}#${e}`,sr(e,!0),r({search:``,hash:e},{replace:!0})},J=e=>f?n({show:e}):n(e===`all`?{}:{show:e},{replace:!0}),he=e=>e.flatMap(e=>e.sections).map(e=>d.spaceSections.find(t=>t.id===e.id)).filter(e=>e!==void 0).map(e=>(0,$.jsx)(Y,{id:e.id,children:(0,$.jsx)(X,{title:e.label(),hint:e.hint?.(),plain:!0,children:(0,$.jsx)(vt,{of:e,children:(0,$.jsx)(e.component,{})})})},e.serial)),ge=f?void 0:ae,_e=(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Et,{title:te,open:k===1?E??null:null,onBack:()=>f?r(`/space`):y(C??null),root:{icon:it,label:B(`nav.project`),backLabel:B(`nav.wizards`),onBack:()=>r(`/`)}}),(0,$.jsx)(`div`,{className:A(Ct(j)),children:k===0?(0,$.jsx)(Ot,{entries:T,current:f?void 0:E,onPick:()=>y(null)}):(0,$.jsx)(`div`,{ref:m})},k)]});return(0,$.jsxs)(Dt.Provider,{value:ee,children:[P&&N?(0,$t.createPortal)(_e,N):null,(0,$.jsx)(`div`,{className:`animate-rise`,children:(0,$.jsxs)(`div`,{className:A(`grid gap-6`,!P&&`md:grid-cols-[13.5rem_minmax(0,1fr)] md:gap-8 lg:grid-cols-[15rem_minmax(0,1fr)] lg:gap-10`),children:[P?null:(0,$.jsx)(`aside`,{className:A(`min-w-0 md:sticky md:top-6 md:self-start`,f&&O===2&&`hidden`,f&&M===`back`&&Ct(`back`)),children:_e}),C?(0,$.jsxs)(`div`,{className:A(`min-w-0`,f&&O<2&&`hidden`,f&&M===`deeper`&&Ct(`deeper`)),children:[f?(0,$.jsx)(`div`,{className:`mb-3`,children:(0,$.jsx)(At,{label:E?.label??te,onBack:()=>r(`/space/${C}`)})}):null,u&&c?(0,$.jsx)(`div`,{className:`mb-6`,children:(0,$.jsx)(ar,{project:c})}):null,b===`results`?(0,$.jsxs)(kt,{children:[(0,$.jsxs)(`ul`,{className:`flex flex-col gap-0.5`,children:[(0,$.jsx)(St,{icon:Wt,label:B(`space.resultsAll`),selected:!f&&!R,onPick:()=>J(`all`)}),ce.data?.wizards.filter(e=>e.results||e.id===R).map(e=>(0,$.jsx)(St,{icon:ht,label:e.title,badge:e.results?(0,$.jsx)(`span`,{className:`text-[0.75rem] text-ink-3 tabular-nums`,children:e.results}):null,selected:!f&&e.id===R,onPick:()=>J(e.id)},e.id))]}),(0,$.jsx)(cr,{groups:L,current:ge,onPick:q})]}):b===`data`?(0,$.jsxs)(kt,{children:[(0,$.jsx)(`ul`,{className:`flex flex-col gap-0.5`,children:(0,$.jsx)(St,{icon:Kt,label:B(`data.all`),selected:!f&&!V,onPick:()=>J(`all`)})}),W.data?ze(W.data).map(e=>(0,$.jsx)(Tt,{label:e.label,children:e.items.map(e=>(0,$.jsx)(St,{icon:De[e.kind],label:e.title,selected:!f&&e.key===V,onPick:()=>J(e.key)},e.key))},e.key)):null,(0,$.jsx)(cr,{groups:L,current:ge,onPick:q})]}):b===`knowledge`?(0,$.jsxs)(kt,{children:[(0,$.jsx)(`ul`,{className:`flex flex-col gap-0.5`,children:(0,$.jsx)(St,{icon:Kt,label:B(`know.all`),selected:!(f||V),onPick:()=>J(`all`)})}),G.data?.categories.length?(0,$.jsx)(Tt,{label:B(`know.categories`),children:G.data.categories.map(e=>(0,$.jsx)(St,{icon:Me[e.type],label:e.name,badge:(0,$.jsx)(`span`,{className:`text-[0.75rem] text-ink-3 tabular-nums`,children:e.proposed?`·`:e.count}),selected:!f&&(V===`c:${e.id}`||K.data?.category.id===e.id),onPick:()=>J(`c:${e.id}`)},e.id))}):null,(0,$.jsx)(cr,{groups:L,current:f?void 0:H?.id,onPick:e=>J(`s:${e}`)})]}):(0,$.jsx)(kt,{children:(0,$.jsx)(cr,{groups:I,current:ge,onPick:q})}),c&&(b===`info`||b===`knowledge`)?(0,$.jsxs)($n,{project:c,group:b,children:[b===`knowledge`?U?U.startsWith(`p:`)?(0,$.jsx)(Pe,{pageId:U.slice(2),onGone:()=>J(`all`),onOpen:J},U):U.startsWith(`t:`)?(0,$.jsx)(Ne,{tableId:U.slice(2),onGone:()=>J(`all`)},U):(0,$.jsx)(pn,{projectId:c.id,fileId:U.slice(2),readOnly:c.readOnly,onGone:()=>J(`all`)},U):G.data?H?(0,$.jsx)(X,{title:H.label(),hint:H.hint?.(),plain:!0,children:(0,$.jsx)(vt,{of:H,children:(0,$.jsx)(H.component,{})})},V):V?.startsWith(`c:`)?ue?(0,$.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,$.jsx)(je,{projectId:c.id,category:ue,readOnly:c.readOnly,onOpen:J,onGone:()=>J(`all`)}),ue.type===`choice`?null:(0,$.jsx)(Be,{projectId:c.id,category:ue,categories:G.data.categories,onOpen:J})]},V):null:V?.startsWith(`v:`)?K.data?(0,$.jsx)(Ee,{value:K.data,readOnly:c.readOnly,children:(0,$.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[K.data.items.length?(0,$.jsx)(`div`,{className:`flex flex-col rounded-xl bg-card p-1.5 shadow-soft ring-1 ring-border-soft`,children:K.data.items.map(e=>(0,$.jsx)(ke,{item:e,categories:G.data.categories.filter(e=>e.id!==K.data?.category.id),onOpen:J},e.key))}):null,K.data.rows.map(e=>(0,$.jsx)(`button`,{type:`button`,onClick:()=>J(`t:${e.tableId}`),className:`px-1 text-left text-[0.8125rem] text-ink-3 hover:text-ink`,children:B(`know.tocRows`,{n:e.count,table:e.title})},e.tableId))]})},V):null:(0,$.jsx)(Y,{id:`documents`,children:(0,$.jsx)(Re,{projectId:c.id,data:G.data,readOnly:c.readOnly,onOpen:J})}):null:null,b===`info`?he(L):null]},c.id):null,c&&x?(0,$.jsx)(vt,{of:x,children:(0,$.jsx)(bt,{part:x.id,children:(0,$.jsx)(x.component,{})},c.id)}):null,c&&b===`data`?(0,$.jsx)(`div`,{className:`flex flex-col gap-9 pb-20`,children:V?.startsWith(`t:`)?(0,$.jsx)(Ne,{tableId:V.slice(2),onGone:()=>J(`all`)},V):V?.startsWith(`p:`)?(0,$.jsx)(Pe,{pageId:V.slice(2),onGone:()=>J(`all`)},V):(0,$.jsxs)($.Fragment,{children:[W.data?(0,$.jsx)(Le,{projectId:c.id,data:W.data,readOnly:c.readOnly,onOpen:J}):null,he(L)]})}):null,c&&b===`results`?(0,$.jsxs)(`div`,{className:`flex flex-col gap-9 pb-20`,children:[ce.data?(0,$.jsx)(rr,{data:ce.data,wizardId:R,filter:oe,onFilter:se}):null,ce.isError?(0,$.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:ce.error.message}):null,he(L)]}):null,c||l?null:(0,$.jsx)(o,{children:B(`settings.noProject`)})]}):null]})})]})}export{lr as ProjectPage};
|
|
1
|
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{n as t,t as n}from"./jsx-runtime-BNakU3Ej.js";import{A as r,B as i,Br as a,Bt as o,C as s,D as c,E as l,Er as u,F as d,Gn as f,Gr as p,H as m,Hr as h,Ht as g,I as _,It as v,Jt as y,Kt as b,L as x,Lr as S,Lt as C,M as w,N as T,Nr as E,O as D,P as O,Qn as k,Qt as A,R as j,Rt as M,S as ee,T as te,U as N,Ur as ne,Ut as P,V as re,Vr as ie,Vt as F,W as I,Wr as L,Xt as ae,Yn as R,Yt as oe,Zt as se,_ as ce,_r as z,a as le,an as B,ar as V,b as H,cr as U,en as W,er as G,fr as K,ft as ue,g as de,gi as fe,gr as pe,hr as me,ir as q,j as J,k as he,kr as ge,nr as _e,pr as ve,qt as ye,v as Y,w as X,x as be,xr as xe,y as Se,yr as Ce,z as we,zt as Z}from"./ui-DMmT-cSO.js";import{S as Te,_ as Ee,a as De,c as Oe,d as ke,f as Ae,g as je,h as Me,i as Ne,l as Pe,m as Fe,n as Ie,o as Le,p as Re,s as ze,u as Be,v as Ve,x as He,y as Ue}from"./RunDrawer-Cd8-qHV7.js";import{t as We}from"./phone-BjmhIKuT.js";import{n as Ge,r as Ke,t as qe}from"./ReadOnly-CD5YWvrW.js";import{t as Je}from"./upload-JX9BcMTq.js";import{$ as Ye,Bt as Xe,Gt as Ze,It as Qe,Kt as $e,Lt as et,Mt as tt,Pt as nt,Qt as rt,Xt as it,_t as at,a as ot,an as st,c as ct,ct as lt,d as ut,f as dt,gt as ft,h as pt,ht as mt,kt as ht,l as gt,m as _t,n as vt,p as yt,r as bt,u as xt}from"./index-4jH2mkp7.js";import{a as St,c as Ct,f as wt,i as Tt,n as Et,o as Dt,r as Ot,s as kt,t as At,u as jt}from"./settings-menu-Dpkp3f56.js";import{t as Mt}from"./RunnerView-BW1h4x63.js";var Nt={name:`blend`,size:24,node:[[`circle`,{cx:`15`,cy:`9`,r:`7`,key:`1i12rt`}],[`circle`,{cx:`9`,cy:`15`,r:`7`,key:`19bs8k`}]]};Nt.node;var Pt=E(Nt),Ft={name:`box`,size:24,node:[[`path`,{d:`M21 8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16Z`,key:`hh9hay`}],[`path`,{d:`m3.3 7 8.7 5 8.7-5`,key:`g66t2b`}],[`path`,{d:`M12 22V12`,key:`d0xqtd`}]]};Ft.node;var It=E(Ft),Lt={name:`case-upper`,size:24,node:[[`path`,{d:`M15 11h4.5a1 1 0 0 1 0 5h-4a.5.5 0 0 1-.5-.5v-9a.5.5 0 0 1 .5-.5h3a1 1 0 0 1 0 5`,key:`nxs35`}],[`path`,{d:`m2 16 4.039-9.69a.5.5 0 0 1 .923 0L11 16`,key:`d5nyq2`}],[`path`,{d:`M3.304 13h6.392`,key:`1q3zxz`}]]};Lt.node;var Rt=E(Lt),zt={name:`folder-plus`,size:24,node:[[`path`,{d:`M12 10v6`,key:`1bos4e`}],[`path`,{d:`M9 13h6`,key:`1uhe8q`}],[`path`,{d:`M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z`,key:`1kt360`}]]};zt.node;var Bt=E(zt),Vt={name:`grid-2x2`,size:24,node:[[`path`,{d:`M12 3v18`,key:`108xh3`}],[`path`,{d:`M3 12h18`,key:`1i2n21`}],[`rect`,{x:`3`,y:`3`,width:`18`,height:`18`,rx:`2`,key:`h1oib`}]],aliases:[`grid-2-x-2`]};Vt.node;var Ht=E(Vt),Ut={name:`layers`,size:24,node:[[`path`,{d:`M12.83 2.18a2 2 0 0 0-1.66 0L2.6 6.08a1 1 0 0 0 0 1.83l8.58 3.91a2 2 0 0 0 1.66 0l8.58-3.9a1 1 0 0 0 0-1.83z`,key:`zw3jo`}],[`path`,{d:`M2 12a1 1 0 0 0 .58.91l8.6 3.91a2 2 0 0 0 1.65 0l8.58-3.9A1 1 0 0 0 22 12`,key:`1wduqc`}],[`path`,{d:`M2 17a1 1 0 0 0 .58.91l8.6 3.91a2 2 0 0 0 1.65 0l8.58-3.9A1 1 0 0 0 22 17`,key:`kqbvx6`}]],aliases:[`layers-3`]};Ut.node;var Wt=E(Ut),Gt={name:`layout-grid`,size:24,node:[[`rect`,{width:`7`,height:`7`,x:`3`,y:`3`,rx:`1`,key:`1g98yp`}],[`rect`,{width:`7`,height:`7`,x:`14`,y:`3`,rx:`1`,key:`6d4xhi`}],[`rect`,{width:`7`,height:`7`,x:`14`,y:`14`,rx:`1`,key:`nxv5o0`}],[`rect`,{width:`7`,height:`7`,x:`3`,y:`14`,rx:`1`,key:`1bb6yr`}]]};Gt.node;var Kt=E(Gt),qt={name:`link`,size:24,node:[[`path`,{d:`M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71`,key:`1cjeqo`}],[`path`,{d:`M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71`,key:`19qd67`}]]};qt.node;var Jt=E(qt),Yt={name:`list`,size:24,node:[[`path`,{d:`M3 5h.01`,key:`18ugdj`}],[`path`,{d:`M3 12h.01`,key:`nlz23k`}],[`path`,{d:`M3 19h.01`,key:`noohij`}],[`path`,{d:`M8 5h13`,key:`1pao27`}],[`path`,{d:`M8 12h13`,key:`1za7za`}],[`path`,{d:`M8 19h13`,key:`m83p4d`}]]};Yt.node;var Xt=E(Yt),Zt={name:`music`,size:24,node:[[`path`,{d:`M9 18V5l12-2v13`,key:`1jmyc2`}],[`circle`,{cx:`6`,cy:`18`,r:`3`,key:`fqmcym`}],[`circle`,{cx:`18`,cy:`16`,r:`3`,key:`1hluhg`}]]};Zt.node;var Qt=E(Zt),$t=L(),Q=e(t(),1),$=e(n(),1),en={backgroundImage:`repeating-conic-gradient(#c9c9c9 0% 25%, #dedede 0% 50%)`,backgroundSize:`16px 16px`};function tn({file:e,actions:t}){let[n,r]=(0,Q.useState)(e.description),i=(0,Q.useRef)(e.description),a=(0,Q.useRef)(null);(0,Q.useEffect)(()=>{e.description!==i.current&&(r(t=>t===i.current?e.description:t),i.current=e.description)},[e.description]),(0,Q.useLayoutEffect)(()=>{let e=a.current;e&&(e.style.height=`auto`,e.style.height=`${e.scrollHeight}px`)},[n]);let o=e.status===`pending`&&!n;return t.readOnly?n?(0,$.jsx)(`p`,{className:`text-[0.8125rem] text-ink-2 leading-snug`,children:n}):null:(0,$.jsx)(`textarea`,{ref:a,rows:1,value:n,maxLength:600,placeholder:B(o?`project.describing`:`project.description`),onChange:e=>r(e.target.value),onBlur:()=>{n.trim()!==e.description&&(i.current=n.trim(),t.describe(e.id,n.trim()))},className:`-mx-1 block w-[calc(100%+0.5rem)] resize-none overflow-hidden rounded-md bg-transparent px-1 py-0.5 text-[0.8125rem] text-ink-2 leading-snug outline-none transition placeholder:text-ink-4 hover:bg-paper-2 focus:bg-card focus:text-ink focus:ring-1 focus:ring-border`})}function nn(e,t){confirm(B(`project.removeConfirm`,{name:e.name}))&&t.remove(e.id)}function rn({projectId:e,file:t,small:n}){let r=we(e,t.id);if(t.mime.startsWith(`image/`))return(0,$.jsx)(`img`,{src:r,alt:``,loading:`lazy`,className:A(`size-full`,t.kind===`logo`?`object-contain p-3`:`object-cover`)});if(t.mime.startsWith(`video/`))return(0,$.jsx)(`video`,{src:`${r}#t=0.1`,preload:`metadata`,controls:!n,className:`size-full object-cover`});if(t.mime.startsWith(`font/`))return(0,$.jsx)(an,{src:r,small:n});let i=n?`size-5`:`size-7`;return(0,$.jsxs)(`div`,{className:`flex size-full flex-col items-center justify-center gap-1.5 text-ink-3`,children:[t.mime.startsWith(`audio/`)?(0,$.jsx)(Qt,{className:i}):t.mime===`application/pdf`?(0,$.jsx)(pe,{className:i}):t.mime===`application/json`?(0,$.jsx)(k,{className:i}):t.mime.startsWith(`model/`)?(0,$.jsx)(It,{className:i}):(0,$.jsx)(me,{className:i}),n?null:(0,$.jsx)(`span`,{className:`text-[0.6875rem] uppercase tracking-wide`,children:t.mime===`application/json`?`Lottie / JSON`:t.mime.split(`/`).pop()})]})}function an({src:e,small:t}){let[n,r]=(0,Q.useState)(null);return(0,Q.useEffect)(()=>{let t=`asset-${e.split(`/`).slice(-2,-1)[0]}`;new FontFace(t,`url("${e}")`).load().then(e=>{document.fonts.add(e),r(t)}).catch(()=>r(null))},[e]),(0,$.jsx)(`div`,{className:A(`flex size-full items-center justify-center text-ink`,t?`text-[1.25rem]`:`text-[2.75rem]`),style:n?{fontFamily:`"${n}"`}:void 0,children:`Aa`})}var on=`application/x-wizards-logo`;function sn({projectId:e,kind:t,files:n,actions:r,accept:i,addLabel:a,onUpload:o,onPreview:s,mainId:c,onMakeMain:l,moveTo:u,onRemove:d}){let f=e=>d?d(e):nn(e,r);return(0,$.jsxs)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(184px,1fr))] gap-3`,children:[n.map(n=>(0,$.jsxs)(`div`,{draggable:u&&!r.readOnly?!0:void 0,onDragStart:e=>e.dataTransfer.setData(on,n.id),className:`group relative flex flex-col gap-1.5 rounded-lg bg-paper p-2 pb-2.5 ring-1 ring-border-soft`,children:[n.id===c?(0,$.jsx)(`span`,{className:`absolute -top-3 left-3 z-10 rounded-full ring-2 ring-card`,children:(0,$.jsx)(M,{tone:`ember`,children:B(`project.logoMain`)})}):null,(0,$.jsxs)(`div`,{className:`relative h-28 overflow-hidden rounded-md bg-paper-2`,style:t===`logo`?en:void 0,children:[s&&n.mime.startsWith(`image/`)?(0,$.jsx)(`button`,{type:`button`,"aria-label":`${B(`project.preview`)}: ${n.name}`,onClick:()=>s(n),className:`block size-full cursor-zoom-in`,children:(0,$.jsx)(rn,{projectId:e,file:n})}):(0,$.jsx)(rn,{projectId:e,file:n}),(0,$.jsxs)(`div`,{className:`absolute top-1 right-1 flex gap-1 opacity-0 transition focus-within:opacity-100 group-hover:opacity-100 coarse:opacity-100`,children:[s?(0,$.jsx)(F,{label:B(`project.preview`),onClick:()=>s(n),className:`size-8 bg-card shadow-soft`,children:(0,$.jsx)(rt,{className:`size-4`})}):null,l&&n.id!==c&&!r.readOnly?(0,$.jsx)(F,{label:B(`project.logoMakeMain`),onClick:()=>l(n),className:`size-8 bg-card shadow-soft`,children:(0,$.jsx)(nt,{className:`size-4`})}):null,u&&!r.readOnly?(0,$.jsx)(be,{options:u.options,value:u.current(n),onChange:e=>u.onMove(n,e),className:`bg-card shadow-soft`}):null,r.readOnly?null:(0,$.jsx)(F,{label:B(`project.remove`),onClick:()=>f(n),className:`size-8 bg-card shadow-soft hover:text-rose`,children:(0,$.jsx)(R,{className:`size-4`})})]})]}),t===`asset`?(0,$.jsx)(`div`,{className:`truncate px-0.5 text-[0.75rem] text-ink-3`,title:n.name,children:n.name}):null,(0,$.jsx)(tn,{file:n,actions:r})]},n.id)),a&&!r.readOnly?(0,$.jsxs)(Se,{accept:i,multiple:!1,onFiles:e=>o?o(e):r.upload(t,e),className:`min-h-28 flex-col p-3`,children:[r.busy?(0,$.jsx)(ye,{className:`size-5`}):(0,$.jsx)(q,{className:`size-5`}),a]}):null]})}function cn({kind:e,fetchUrl:t,onAdded:n,onClose:r}){let[i,a]=(0,Q.useState)(``),[o,s]=(0,Q.useState)(!1),[c,l]=(0,Q.useState)(null),[d,f]=(0,Q.useState)(null),[p,m]=(0,Q.useState)([]),h=async()=>{s(!0),l(null);try{let a=await t(i.trim());a.file?(n([a.file]),r()):a.candidates?.length?(f(a.candidates),m([a.candidates[0].url])):l(B(e===`logo`?`project.logoNoneFound`:`project.assetNoneFound`))}catch(e){l(e.message)}s(!1)},_=async()=>{s(!0),l(null);let e=[];try{for(let n of p){let r=await t(n);r.file&&e.push(r.file)}}catch(e){l(e.message)}s(!1),e.length&&n(e),e.length===p.length&&r()};return(0,$.jsx)(Z,{open:!0,onClose:r,wide:d?!0:void 0,title:B(d?e===`logo`?`project.logoFound`:`project.assetFound`:e===`logo`?`project.logoFromUrl`:`project.assetFromUrl`),children:d?(0,$.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,$.jsx)(`p`,{className:`-mt-2 text-[0.875rem] text-ink-3`,children:B(e===`logo`?`project.logoFoundHint`:`project.assetFoundHint`)}),(0,$.jsx)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(150px,1fr))] gap-3`,children:d.map(t=>{let n=p.includes(t.url);return(0,$.jsxs)(`button`,{type:`button`,"aria-pressed":n,title:t.hint,onClick:()=>m(e=>n?e.filter(e=>e!==t.url):[...e,t.url]),className:A(`relative h-28 overflow-hidden rounded-lg ring-1 transition`,n?`ring-2 ring-ember`:`ring-border-soft hover:ring-ink-4`),style:en,children:[(0,$.jsx)(`img`,{src:t.url,alt:``,className:A(`size-full`,e===`logo`?`object-contain p-3`:`object-cover`)}),n?(0,$.jsx)(`span`,{className:`absolute top-1.5 right-1.5 grid size-5 place-items-center rounded-full bg-ember text-white`,children:(0,$.jsx)(u,{className:`size-3.5`})}):null]},t.url)})}),c?(0,$.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:c}):null,(0,$.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,$.jsx)(v,{variant:`ghost`,onClick:()=>f(null),children:B(`run.back`)}),(0,$.jsx)(v,{busy:o,disabled:!p.length,onClick:()=>void _(),children:p.length>1?B(`project.addMany`,{n:p.length}):B(`project.add`)})]})]}):(0,$.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),h()},className:`flex flex-col gap-5`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(P,{children:B(`project.logoUrl`)}),(0,$.jsx)(g,{autoFocus:!0,value:i,inputMode:`url`,placeholder:`https://example.com`,onChange:e=>a(e.target.value)}),(0,$.jsx)(`p`,{className:`mt-1.5 text-[0.8125rem] text-ink-3`,children:B(e===`logo`?`project.logoUrlHint`:`project.assetUrlHint`)})]}),c?(0,$.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:c}):null,(0,$.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,$.jsx)(v,{variant:`ghost`,onClick:r,children:B(`common.cancel`)}),(0,$.jsx)(v,{type:`submit`,busy:o,disabled:!i.trim(),children:B(`run.next`)})]})]})})}function ln(e,t,n){return p({queryKey:[`project-file-text`,t.id,t.chars,n],queryFn:()=>I.get(`/api/studio/projects/${e}/files/${t.id}/text?limit=${n}`),enabled:t.status===`ready`,staleTime:6e4})}function un(e){return((e.name.includes(`.`)?e.name.split(`.`).pop():``)||e.mime.split(`/`).pop()||``).toUpperCase().slice(0,5)}var dn=e=>[un(e),e.pages?B(`project.pages`,{n:e.pages}):null,f(e.size)].filter(Boolean).join(` · `),fn=2e5;function pn({projectId:e,fileId:t,readOnly:n,onGone:r}){let i=fe(),a=N(e),o=Fe(e),s=re(e,n),c=a.data?.files.find(e=>e.id===t),l=c?c.mime===`application/pdf`||c.mime.startsWith(`image/`):!1,[u,d]=(0,Q.useState)(null);if(!c)return a.isLoading?(0,$.jsx)(ye,{className:`mx-auto text-ink-3`}):null;let f=u??(l?`original`:`text`),p=o.data?.items.find(e=>e.key===`f:${c.id}`),m=we(e,c.id),h=(e,t)=>(0,$.jsx)(`button`,{type:`button`,"aria-pressed":f===e,onClick:()=>d(e),className:A(`rounded-full px-3 py-1 text-[0.8125rem] transition`,f===e?`bg-paper-2 font-medium text-ink`:`text-ink-3 hover:text-ink`),children:t});return(0,$.jsxs)(`section`,{className:`flex flex-col gap-3`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 px-1`,children:[(0,$.jsx)(`h2`,{className:`min-w-0 flex-1 truncate font-display font-semibold text-lg`,children:c.name}),(0,$.jsx)(`span`,{className:`text-[0.8125rem] text-ink-3 max-sm:hidden`,children:dn(c)}),(0,$.jsx)(`a`,{href:m,target:`_blank`,rel:`noreferrer`,"aria-label":B(`project.openOriginal`),title:B(`project.openOriginal`),className:`inline-flex size-9 items-center justify-center rounded-full text-ink-3 transition hover:bg-accent hover:text-ink`,children:(0,$.jsx)(z,{className:`size-4`})}),n?null:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(F,{label:B(`project.reindex`),onClick:async()=>{await s.reindex(c.id),await i.invalidateQueries({queryKey:[`knowledge`,e]})},children:(0,$.jsx)(_e,{className:`size-4`})}),(0,$.jsx)(F,{label:B(`know.deleteFile`),className:`hover:text-rose`,onClick:async()=>{confirm(B(`data.confirmDelete`,{title:c.name}))&&(await s.remove(c.id),await i.invalidateQueries({queryKey:[`knowledge`,e]}),r())},children:(0,$.jsx)(R,{className:`size-4`})})]})]}),(0,$.jsx)(Ae,{projectId:e,itemKey:`f:${c.id}`,has:p?.categories??[],originLabel:p?.originLabel??null,kept:!1,review:null,file:null,readOnly:n,onReviewed:()=>void 0}),(0,$.jsx)(`div`,{className:`px-1`,children:(0,$.jsx)(tn,{file:c,actions:s})}),c.status===`failed`?(0,$.jsx)(`p`,{className:`px-1 text-[0.875rem] text-rose`,children:c.error}):null,(0,$.jsxs)(C,{className:`flex flex-col`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1 border-border-soft border-b px-2 py-1.5`,children:[l?h(`original`,B(`project.original`)):null,h(`text`,B(`project.readText`))]}),f===`original`?c.mime===`application/pdf`?(0,$.jsx)(`iframe`,{src:m,title:c.name,className:`h-[70dvh] w-full rounded-b-xl bg-paper-2`}):(0,$.jsx)(`img`,{src:m,alt:``,className:`mx-auto max-h-[70dvh] object-contain p-4`}):(0,$.jsx)(mn,{projectId:e,file:c})]})]})}function mn({projectId:e,file:t}){let n=ln(e,t,fn);return n.isLoading||t.status===`pending`?(0,$.jsx)(`div`,{className:`flex h-40 items-center justify-center text-ink-3`,children:(0,$.jsx)(ye,{})}):n.data?.text?(0,$.jsxs)(`div`,{className:`overflow-x-auto p-4 sm:p-5`,children:[(0,$.jsx)(ue,{text:n.data.text,className:`text-[0.875rem]`}),n.data.chars>n.data.text.length?(0,$.jsx)(`p`,{className:`mt-3 text-[0.8125rem] text-ink-3`,children:B(`project.textCut`,{shown:n.data.text.length.toLocaleString(W),total:n.data.chars.toLocaleString(W)})}):null]}):(0,$.jsx)(`p`,{className:`py-8 text-center text-[0.875rem] text-ink-3`,children:B(`project.noText`)})}var hn=`image/*,video/*,audio/*,application/pdf,.pdf,.woff2,.woff,.ttf,.otf,.json,.glb,.gltf`,gn=e=>[(e.name.includes(`.`)?e.name.split(`.`).pop():e.mime.split(`/`).pop())?.toUpperCase().slice(0,5),f(e.size)].filter(Boolean).join(` · `);function _n({projectId:e,file:t,actions:n,onClose:r}){let i=we(e,t.id);return(0,$.jsxs)(Z,{open:!0,onClose:r,wide:`page`,title:t.name,children:[(0,$.jsxs)(`div`,{className:`-mt-2 mb-4 flex items-center justify-between gap-3`,children:[(0,$.jsx)(`span`,{className:`text-[0.8125rem] text-ink-3`,children:gn(t)}),(0,$.jsx)(`a`,{href:i,target:`_blank`,rel:`noreferrer`,"aria-label":B(`project.openOriginal`),title:B(`project.openOriginal`),className:`inline-flex size-9 items-center justify-center rounded-full text-ink-3 transition hover:bg-accent hover:text-ink`,children:(0,$.jsx)(z,{className:`size-4`})})]}),t.mime.startsWith(`image/`)?(0,$.jsx)(`div`,{className:`overflow-hidden rounded-lg`,style:en,children:(0,$.jsx)(`img`,{src:i,alt:``,className:`mx-auto max-h-[68dvh] object-contain`})}):t.mime.startsWith(`video/`)?(0,$.jsx)(`video`,{src:i,controls:!0,className:`max-h-[68dvh] w-full rounded-lg bg-black`}):(0,$.jsx)(`audio`,{src:i,controls:!0,className:`w-full`}),(0,$.jsx)(`div`,{className:`mt-4`,children:(0,$.jsx)(tn,{file:t,actions:n})})]})}function vn({projectId:e,file:t,actions:n,moveTo:r,onPreview:i,onRemove:a}){return(0,$.jsxs)(`li`,{className:`group/row flex items-start gap-3 rounded-lg bg-paper p-2 ring-1 ring-border-soft`,children:[(0,$.jsx)(`button`,{type:`button`,"aria-label":`${B(`project.preview`)}: ${t.name}`,onClick:i,className:`size-14 shrink-0 cursor-zoom-in overflow-hidden rounded-md bg-paper-2`,children:(0,$.jsx)(rn,{projectId:e,file:t,small:!0})}),(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col gap-1 py-0.5`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-3`,children:[(0,$.jsx)(`button`,{type:`button`,onClick:i,title:t.name,className:`min-w-0 truncate font-medium text-[0.875rem] hover:underline`,children:t.name}),(0,$.jsx)(`span`,{className:`text-[0.75rem] text-ink-3`,children:gn(t)})]}),(0,$.jsx)(tn,{file:t,actions:n})]}),(0,$.jsxs)(`div`,{className:`flex shrink-0 items-start opacity-0 transition focus-within:opacity-100 group-hover/row:opacity-100 coarse:opacity-100`,children:[(0,$.jsx)(F,{label:B(`project.preview`),onClick:i,children:(0,$.jsx)(rt,{className:`size-4`})}),r&&!n.readOnly?(0,$.jsx)(be,{options:r.options,value:r.current(t),onChange:e=>r.onMove(t,e),className:`size-9`}):null,n.readOnly?null:(0,$.jsx)(F,{label:B(`project.remove`),onClick:a,className:`hover:text-rose`,children:(0,$.jsx)(R,{className:`size-4`})})]})]})}function yn({section:e,onSave:t,onRemove:n,onClose:r}){let[i,a]=(0,Q.useState)(e?.title??``);return(0,$.jsx)(Z,{open:!0,onClose:r,title:B(e?`project.assetSectionRename`:`project.assetSectionAdd`),children:(0,$.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),i.trim()&&(t(i.trim()),r())},className:`flex flex-col gap-5`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(P,{children:B(`project.assetSectionName`)}),(0,$.jsx)(g,{autoFocus:!0,value:i,maxLength:80,placeholder:B(`project.assetSectionTitle`),onChange:e=>a(e.target.value)})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[n?(0,$.jsx)(v,{variant:`danger`,onClick:n,children:B(`project.sectionRemove`)}):null,(0,$.jsx)(`span`,{className:`flex-1`}),(0,$.jsx)(v,{variant:`ghost`,onClick:r,children:B(`common.cancel`)}),(0,$.jsx)(v,{type:`submit`,disabled:!i.trim(),children:B(e?`settings.save`:`project.add`)})]})]})})}function bn({projectId:e,data:t,readOnly:n,sections:r,save:a}){let o=re(e,n),[c,u]=m(`assets`,`cards`),[d,f]=(0,Q.useState)(``),[p,h]=(0,Q.useState)(null),[g,_]=(0,Q.useState)(r),[v,y]=(0,Q.useState)(``),[b,x]=(0,Q.useState)(null),[S,C]=(0,Q.useState)(!1),w=(0,Q.useRef)(null),E=i({assetSections:g},a),D=t.files.filter(e=>e.kind===`asset`),O=new Map(D.map(e=>[e.id,e])),k=new Set(g.flatMap(e=>e.assets)),A=g.find(e=>e.id===v)??null,j=A?A.assets.map(e=>O.get(e)).filter(e=>!!e):D.filter(e=>!k.has(e.id)),M=D.find(e=>e.id===p),ee=d.trim().toLowerCase(),te=ee?j.filter(e=>`${e.name} ${e.description}`.toLowerCase().includes(ee)):j,N=(e,t)=>_(n=>n.map(n=>{let r=n.assets.filter(t=>t!==e);return{...n,assets:n.id===t?[...r,e]:r}})),ne=async e=>{let t=A?.id??null;for(let n of await o.upload(`asset`,e))N(n.id,t)},P=e=>{confirm(B(`project.removeConfirm`,{name:e.name}))&&(o.remove(e.id),N(e.id,null))},ie=g.length?{options:[{value:``,label:B(`project.assetsGeneral`)},...g.map(e=>({value:e.id,label:e.title||B(`project.sectionUntitled`)}))],current:e=>g.find(t=>t.assets.includes(e.id))?.id??``,onMove:(e,t)=>N(e.id,t||null)}:void 0,I=[{label:B(`project.assetUpload`),icon:(0,$.jsx)(Je,{className:`size-4 shrink-0`}),onPick:()=>w.current?.click()},{label:B(`project.assetFromUrl`),icon:(0,$.jsx)(Jt,{className:`size-4 shrink-0`}),onPick:()=>C(!0)},...g.length<T.logoSections?[{label:B(`project.assetSectionAdd`),icon:(0,$.jsx)(Bt,{className:`size-4 shrink-0`}),onPick:()=>x(`new`)}]:[]],L=g.length||D.length?(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsxs)(`div`,{className:`-mx-1 flex min-w-0 flex-1 items-center gap-1 overflow-x-auto px-1 pb-0.5`,children:[g.length?(0,$.jsx)(ae,{value:v,onChange:e=>{y(e),f(``)},label:B(`project.assets`),options:[{id:``,label:B(`project.assetsGeneral`)},...g.map(e=>({id:e.id,label:e.title||B(`project.sectionUntitled`)}))]}):null,A&&!n?(0,$.jsx)(F,{label:B(`project.assetSectionRename`),onClick:()=>x(`current`),children:(0,$.jsx)(V,{className:`size-4`})}):null]}),j.length?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`w-56 max-w-[45%] shrink`,children:(0,$.jsx)(s,{value:d,onChange:f,placeholder:B(`project.assetSearch`)})}),(0,$.jsx)(F,{label:B(c===`list`?`project.viewCards`:`project.viewList`),onClick:u,children:c===`list`?(0,$.jsx)(Kt,{className:`size-4`}):(0,$.jsx)(Xt,{className:`size-4`})})]}):null]}):null;return(0,$.jsxs)(X,{title:B(`project.assets`),hint:B(`project.assetsHint`),save:E,tabs:L,action:n?null:(0,$.jsx)(de,{entries:I}),children:[(0,$.jsx)(`input`,{ref:w,type:`file`,multiple:!0,accept:hn,className:`sr-only`,tabIndex:-1,"aria-hidden":!0,onChange:e=>{let t=Array.from(e.target.files??[]);e.target.value=``,t.length&&ne(t)}}),te.length?c===`cards`?(0,$.jsx)(sn,{projectId:e,kind:`asset`,files:te,actions:o,moveTo:ie,onRemove:P,onPreview:e=>h(e.id)}):(0,$.jsx)(`ul`,{className:`flex flex-col gap-2`,children:te.map(t=>(0,$.jsx)(vn,{projectId:e,file:t,actions:o,moveTo:ie,onPreview:()=>h(t.id),onRemove:()=>P(t)},t.id))}):j.length?null:n?(0,$.jsx)(`p`,{className:`text-[0.875rem] text-ink-3`,children:B(`project.staysLocal`)}):(0,$.jsxs)(Se,{accept:hn,onFiles:e=>void ne(e),className:`h-16 w-full`,children:[o.busy?(0,$.jsx)(ye,{className:`size-4`}):(0,$.jsx)(Je,{className:`size-4`}),B(`project.drop`),` `,(0,$.jsx)(`span`,{className:`underline`,children:B(`project.assetAdd`)})]}),o.error?(0,$.jsx)(`p`,{className:`mt-3 text-[0.875rem] text-rose`,children:o.error}):null,M?(0,$.jsx)(_n,{projectId:e,file:M,actions:o,onClose:()=>h(null)}):null,b?(0,$.jsx)(yn,{section:b===`current`?A:null,onClose:()=>x(null),onSave:e=>{if(b===`current`&&A)_(t=>t.map(t=>t.id===A.id?{...t,title:e}:t));else{let t=l();_(n=>[...n,{id:t,title:e,assets:[]}]),y(t)}},onRemove:b===`current`&&A?()=>{(!A.assets.length||confirm(B(`project.assetSectionRemoveConfirm`,{name:A.title})))&&(_(e=>e.filter(e=>e.id!==A.id)),y(``),x(null))}:void 0}):null,S?(0,$.jsx)(cn,{kind:`asset`,onClose:()=>C(!1),fetchUrl:e=>o.fromUrl(`asset`,e),onAdded:e=>{for(let t of e)N(t.id,A?.id??null)}}):null]})}var xn=/^#[0-9a-fA-F]{6}$/;async function Sn(e,t){let[n,r]=[1920,1080],i=document.createElement(`canvas`);i.width=n,i.height=r;let a=i.getContext(`2d`);if(!a)return;let o=e.angle*Math.PI/180,s;if(e.type===`radial`)s=a.createRadialGradient(n/2,r/2,0,n/2,r/2,Math.hypot(n,r)/2);else if(e.type===`conic`)s=a.createConicGradient(o-Math.PI/2,n/2,r/2);else{let e=Math.abs(n*Math.sin(o))+Math.abs(r*Math.cos(o)),[t,i]=[Math.sin(o)*e/2,-Math.cos(o)*e/2];s=a.createLinearGradient(n/2-t,r/2-i,n/2+t,r/2+i)}for(let t of[...e.stops].sort((e,t)=>e.at-t.at))s.addColorStop(Math.min(1,Math.max(0,t.at/100)),t.color);a.fillStyle=s,a.fillRect(0,0,n,r);let c=await new Promise(e=>i.toBlob(e,`image/png`));if(c){let e=document.createElement(`a`);e.href=URL.createObjectURL(c),e.download=`${t||`gradient`}.png`,e.click(),setTimeout(()=>URL.revokeObjectURL(e.href),5e3)}}var Cn={linear:`project.gradientLinear`,radial:`project.gradientRadial`,conic:`project.gradientConic`};function wn({projectId:e,gradient:t,isNew:n,brand:r,onSave:i,onClose:a}){let[o,s]=(0,Q.useState)(t),[c,l]=(0,Q.useState)(_(t)),[u,d]=(0,Q.useState)(!1),[f,p]=(0,Q.useState)(``),[m,h]=(0,Q.useState)(!1),[b,x]=(0,Q.useState)(null),[S,C]=(0,Q.useState)(!n),T=e=>{s(e),l(_(e)),d(!1)},E=(e,t)=>T({...o,stops:o.stops.map((n,r)=>r===e?{...n,...t}:n)}),D=e=>{let t=[...o.stops].sort((e,t)=>e.at-t.at),n=50,r=-1;for(let e=0;e<t.length-1;e++)t[e+1].at-t[e].at>r&&(r=t[e+1].at-t[e].at,n=Math.round((t[e].at+t[e+1].at)/2));T({...o,stops:[...o.stops,{color:e??t[0]?.color??`#888888`,at:n}]})},O=async()=>{h(!0),x(null);try{let{gradient:t}=await I.post(`/api/studio/projects/${e}/gradients/describe`,{text:f.trim(),...S?{gradient:{name:o.name,type:o.type,angle:o.angle,stops:o.stops}}:{}});T({...o,...t,name:o.name.trim()?o.name:t.name}),p(``),C(!0)}catch(e){x(e.message)}h(!1)};return(0,$.jsx)(Z,{open:!0,onClose:a,wide:!0,title:B(n?`project.gradientNew`:`project.gradientEdit`),children:(0,$.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,$.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),f.trim()&&!m&&O()},children:[(0,$.jsxs)(`div`,{className:`flex gap-2`,children:[(0,$.jsx)(g,{"data-autofocus":n||void 0,value:f,maxLength:1e3,"aria-label":B(`project.gradientDescribe`),placeholder:B(S?`project.gradientDescribeChange`:`project.gradientDescribeNew`),onChange:e=>p(e.target.value),className:`min-w-0 flex-1`}),(0,$.jsxs)(v,{type:`submit`,variant:`secondary`,busy:m,disabled:!f.trim(),children:[(0,$.jsx)(k,{className:`size-4`}),B(S?`project.gradientDescribeApply`:`project.gradientDescribeMake`)]})]}),(0,$.jsx)(`p`,{className:A(`mt-1.5 text-[0.8125rem]`,b?`text-rose`:`text-ink-3`),children:b??B(`project.gradientDescribeHint`)})]}),(0,$.jsx)(`div`,{className:`h-40 rounded-lg ring-1 ring-border-soft`,style:{background:_(o)}}),(0,$.jsxs)(`div`,{className:`grid gap-x-6 gap-y-4 sm:grid-cols-2`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(P,{children:B(`project.gradientName`)}),(0,$.jsx)(g,{value:o.name,maxLength:80,placeholder:B(`project.gradientNamePlaceholder`),onChange:e=>s({...o,name:e.target.value})})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(P,{children:B(`project.fillUseLabel`)}),(0,$.jsx)(g,{value:o.description??``,maxLength:400,placeholder:B(`project.gradientUse`),onChange:e=>s({...o,description:e.target.value})})]})]}),(0,$.jsxs)(`div`,{className:`flex flex-wrap items-end gap-x-6 gap-y-4`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(P,{children:B(`project.gradientType`)}),(0,$.jsx)(`div`,{className:`flex gap-1 rounded-full bg-paper-2 p-0.5 ring-1 ring-border-soft`,children:w.map(e=>(0,$.jsx)(`button`,{type:`button`,"aria-pressed":o.type===e,onClick:()=>T({...o,type:e}),className:A(`h-9 rounded-full px-4 font-medium text-[0.875rem] transition`,o.type===e?`bg-card text-ink shadow-sm`:`text-ink-3 hover:text-ink-2`),children:B(Cn[e])},e))})]}),o.type===`radial`?null:(0,$.jsxs)(`div`,{className:`min-w-56`,children:[(0,$.jsx)(P,{children:B(`project.gradientAngle`)}),(0,$.jsxs)(`div`,{className:`flex h-11 items-center gap-3`,children:[(0,$.jsx)(`input`,{type:`range`,min:0,max:360,value:o.angle,"aria-label":B(`project.gradientAngle`),onChange:e=>T({...o,angle:Number(e.target.value)}),className:`flex-1 accent-ink`}),(0,$.jsxs)(`span`,{className:`w-12 text-right text-[0.875rem] text-ink-2 tabular-nums`,children:[Math.round(o.angle),`°`]})]})]})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(P,{children:B(`project.gradientStops`)}),(0,$.jsx)(`div`,{className:`flex flex-col gap-2`,children:o.stops.map((e,t)=>(0,$.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,$.jsx)(y,{value:xn.test(e.color)?e.color:`#888888`,onChange:e=>E(t,{color:e.target.value})}),(0,$.jsx)(g,{value:e.color,spellCheck:!1,onChange:e=>{let n=e.target.value.trim();xn.test(n)&&E(t,{color:n.toLowerCase()})},className:`w-28 font-mono text-[0.8125rem]`}),(0,$.jsx)(`input`,{type:`range`,min:0,max:100,value:e.at,"aria-label":B(`project.gradientAt`),onChange:e=>E(t,{at:Number(e.target.value)}),className:`flex-1 accent-ink`}),(0,$.jsxs)(`span`,{className:`w-10 text-right text-[0.875rem] text-ink-2 tabular-nums`,children:[Math.round(e.at),`%`]}),(0,$.jsx)(F,{label:B(`project.remove`),disabled:o.stops.length<=2,onClick:()=>T({...o,stops:o.stops.filter((e,n)=>n!==t)}),className:`hover:text-rose`,children:(0,$.jsx)(R,{className:`size-4`})})]},t))}),(0,$.jsxs)(`div`,{className:`mt-3 flex flex-wrap items-center gap-2`,children:[o.stops.length<12?(0,$.jsxs)(v,{variant:`secondary`,size:`sm`,onClick:()=>D(),children:[(0,$.jsx)(q,{className:`size-4`}),` `,B(`project.gradientStopAdd`)]}):null,r.length&&o.stops.length<12?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{className:`ml-2 text-[0.8125rem] text-ink-3`,children:B(`project.gradientFromBrand`)}),r.slice(0,10).map(e=>(0,$.jsx)(`button`,{type:`button`,title:e.name||e.value,"aria-label":e.name||e.value,onClick:()=>D(e.value),className:`size-6 rounded-full ring-1 ring-border transition hover:scale-110`,style:{background:e.value}},e.value))]}):null]})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(P,{children:`CSS`}),(0,$.jsx)(g,{value:c,spellCheck:!1,onChange:e=>{l(e.target.value);let t=j(e.target.value);d(!t),t&&s({...o,...t})},className:`font-mono text-[0.8125rem]`}),(0,$.jsx)(`p`,{className:A(`mt-1.5 text-[0.8125rem]`,u?`text-rose`:`text-ink-3`),children:B(u?`project.gradientCssError`:`project.gradientCssHint`)})]}),(0,$.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,$.jsx)(v,{variant:`ghost`,onClick:a,children:B(`common.cancel`)}),(0,$.jsx)(v,{onClick:()=>{i(o),a()},children:B(`settings.save`)})]})]})})}var Tn=`absolute top-1.5 right-1.5 flex gap-1 opacity-0 transition focus-within:opacity-100 group-hover/card:opacity-100 coarse:opacity-100`,En=`size-8 bg-card shadow-soft hover:bg-card`;function Dn({name:e,namePlaceholder:t,description:n,usePlaceholder:r,readOnly:i,onChange:a}){return i?(0,$.jsxs)(`div`,{className:`min-w-0 px-0.5`,children:[(0,$.jsx)(`p`,{className:`truncate text-[0.875rem]`,children:e||t}),n?(0,$.jsx)(`p`,{className:`text-[0.8125rem] text-ink-3 leading-snug`,children:n}):null]}):(0,$.jsxs)(`div`,{className:`min-w-0 px-0.5`,children:[(0,$.jsx)(H,{value:e,label:B(`project.gradientName`),placeholder:t,maxLength:80,onChange:e=>a({name:e}),className:`font-medium text-[0.875rem]`}),(0,$.jsx)(H,{value:n??``,label:B(`project.fillUseLabel`),placeholder:r,maxLength:400,onChange:e=>a({description:e}),className:`text-[0.8125rem] text-ink-3`})]})}function On({gradient:e,readOnly:t,onEdit:n,onChange:r,onRemove:i}){let a=_(e),[o,s]=(0,Q.useState)(!1);return(0,$.jsxs)(`div`,{className:`group/card flex flex-col gap-2 rounded-lg bg-paper p-2 ring-1 ring-border-soft`,children:[(0,$.jsxs)(`div`,{className:`relative`,children:[(0,$.jsx)(`button`,{type:`button`,disabled:t,"aria-label":B(`project.gradientEdit`),onClick:n,className:`block h-28 w-full rounded-md ring-1 ring-border-soft transition enabled:hover:brightness-105`,style:{background:a}}),(0,$.jsxs)(`div`,{className:Tn,children:[(0,$.jsx)(F,{label:B(o?`project.gradientCopied`:`project.gradientCopy`),onClick:()=>{navigator.clipboard.writeText(`background: ${a};`),s(!0),setTimeout(()=>s(!1),1500)},className:En,children:(0,$.jsx)(xe,{className:`size-4`})}),(0,$.jsx)(F,{label:B(`project.download`),onClick:()=>void Sn(e,e.name),className:En,children:(0,$.jsx)(Ce,{className:`size-4`})}),t?null:(0,$.jsx)(F,{label:B(`project.remove`),onClick:i,className:A(En,`hover:text-rose`),children:(0,$.jsx)(R,{className:`size-4`})})]})]}),(0,$.jsx)(Dn,{name:e.name,namePlaceholder:B(`project.gradientName`),description:e.description,usePlaceholder:B(`project.gradientUse`),readOnly:t,onChange:r})]})}function kn(e,t){return{backgroundImage:`url("${e}")`,backgroundSize:t?`64px`:`cover`,backgroundRepeat:t?`repeat`:`no-repeat`,backgroundPosition:`center`}}function An({projectId:e,pattern:t,fileName:n,readOnly:r,onEdit:i,onChange:a,onRemove:o}){let s=we(e,t.file);return(0,$.jsxs)(`div`,{className:`group/card flex flex-col gap-2 rounded-lg bg-paper p-2 ring-1 ring-border-soft`,children:[(0,$.jsxs)(`div`,{className:`relative`,children:[(0,$.jsx)(`button`,{type:`button`,disabled:r,"aria-label":B(`project.patternEdit`),onClick:i,className:`block h-28 w-full rounded-md ring-1 ring-border-soft transition enabled:hover:brightness-105`,style:kn(s,t.tile)}),(0,$.jsxs)(`div`,{className:Tn,children:[(0,$.jsx)(`a`,{href:s,download:n,"aria-label":B(`project.download`),title:B(`project.download`),className:A(`inline-flex items-center justify-center rounded-full text-ink-3 transition hover:text-ink`,En),children:(0,$.jsx)(Ce,{className:`size-4`})}),r?null:(0,$.jsx)(F,{label:B(`project.remove`),onClick:o,className:A(En,`hover:text-rose`),children:(0,$.jsx)(R,{className:`size-4`})})]})]}),(0,$.jsx)(Dn,{name:t.name,namePlaceholder:n,description:t.description,usePlaceholder:B(`project.patternUse`),readOnly:r,onChange:a})]})}function jn({projectId:e,pattern:t,isNew:n,fileName:r,busy:i,error:a,upload:o,removeFile:s,onSave:c,onClose:l}){let[u,d]=(0,Q.useState)(t),[f,p]=(0,Q.useState)([]),m=async e=>{let t=e[0];if(!t)return;let n=await o(t);n&&(p(e=>[...e,n.id]),d(e=>({...e,file:n.id,name:e.name||n.name.replace(/\.[^.]+$/,``)})))},h=()=>{for(let e of f)s(e);l()};return(0,$.jsx)(Z,{open:!0,onClose:h,wide:!0,title:B(n?`project.patternNew`:`project.patternEdit`),children:(0,$.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[u.file?(0,$.jsx)(`div`,{className:`relative h-40 rounded-lg ring-1 ring-border-soft`,style:kn(we(e,u.file),u.tile),children:(0,$.jsxs)(Se,{accept:`image/*`,multiple:!1,onFiles:e=>void m(e),className:`absolute right-2 bottom-2 h-9 border-solid bg-card px-3.5 text-ink-2 shadow-soft`,children:[i?(0,$.jsx)(ye,{className:`size-4`}):(0,$.jsx)(ve,{className:`size-4`}),B(`project.patternReplace`)]})}):(0,$.jsxs)(Se,{accept:`image/*`,multiple:!1,onFiles:e=>void m(e),className:`h-40 flex-col`,children:[i?(0,$.jsx)(ye,{className:`size-5`}):(0,$.jsx)(ve,{className:`size-5`}),B(`project.patternPick`)]}),(0,$.jsxs)(`div`,{className:`grid gap-x-6 gap-y-4 sm:grid-cols-2`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(P,{children:B(`project.patternName`)}),(0,$.jsx)(g,{value:u.name,maxLength:80,placeholder:u.file?r(u.file):B(`project.patternNamePlaceholder`),onChange:e=>d({...u,name:e.target.value})})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(P,{children:B(`project.fillUseLabel`)}),(0,$.jsx)(g,{value:u.description??``,maxLength:400,placeholder:B(`project.patternUse`),onChange:e=>d({...u,description:e.target.value})})]})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(P,{children:B(`project.patternShow`)}),(0,$.jsx)(`div`,{className:`flex w-fit gap-1 rounded-full bg-paper-2 p-0.5 ring-1 ring-border-soft`,children:[!1,!0].map(e=>(0,$.jsx)(`button`,{type:`button`,"aria-pressed":!!u.tile===e,onClick:()=>d({...u,tile:e||void 0}),className:A(`h-9 rounded-full px-4 font-medium text-[0.875rem] transition`,!!u.tile===e?`bg-card text-ink shadow-sm`:`text-ink-3 hover:text-ink-2`),children:B(e?`project.patternTile`:`project.patternFill`)},String(e)))})]}),(0,$.jsxs)(`div`,{className:`flex items-center justify-end gap-2`,children:[a?(0,$.jsx)(`p`,{className:`mr-auto text-[0.8125rem] text-rose`,children:a}):null,(0,$.jsx)(v,{variant:`ghost`,onClick:h,children:B(`common.cancel`)}),(0,$.jsx)(v,{disabled:!u.file||i,onClick:()=>{for(let e of f.filter(e=>e!==u.file))s(e);t.file&&t.file!==u.file&&s(t.file),c({...u,name:u.name.trim(),description:u.description?.trim()||void 0}),l()},children:B(n?`project.add`:`settings.save`)})]})]})})}var Mn=/^#[0-9a-fA-F]{6}$/;function Nn({projectId:e,onAdd:t,onClose:n}){let[r,i]=(0,Q.useState)(``),[a,o]=(0,Q.useState)(!1),[s,c]=(0,Q.useState)(null),[l,d]=(0,Q.useState)(null),[f,p]=(0,Q.useState)([]),m=async()=>{o(!0),c(null);try{let{colors:t}=await I.post(`/api/studio/projects/${e}/colors/scan`,{url:r.trim()});t.length?(d(t),p([])):c(B(`project.colorsNoneFound`))}catch(e){c(e.message)}o(!1)};return(0,$.jsx)(Z,{open:!0,onClose:n,wide:l?!0:void 0,title:B(l?`project.colorsFound`:`project.colorsFromUrl`),children:l?(0,$.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,$.jsx)(`p`,{className:`-mt-2 text-[0.875rem] text-ink-3`,children:B(`project.colorsFoundHint`)}),(0,$.jsx)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(120px,1fr))] gap-3`,children:l.map(e=>{let t=f.includes(e.value);return(0,$.jsxs)(`button`,{type:`button`,"aria-pressed":t,onClick:()=>p(n=>t?n.filter(t=>t!==e.value):[...n,e.value]),className:A(`relative flex flex-col overflow-hidden rounded-lg text-left ring-1 transition`,t?`ring-2 ring-ember`:`ring-border-soft hover:ring-ink-4`),children:[(0,$.jsx)(`span`,{className:`h-16`,style:{background:e.value}}),(0,$.jsxs)(`span`,{className:`flex flex-col px-2.5 py-2`,children:[(0,$.jsx)(`span`,{className:`truncate text-[0.8125rem] text-ink-2`,children:e.name||`—`}),(0,$.jsx)(`span`,{className:`font-mono text-[0.75rem] text-ink-3`,children:e.value})]}),t?(0,$.jsx)(`span`,{className:`absolute top-1.5 right-1.5 grid size-5 place-items-center rounded-full bg-ember text-white`,children:(0,$.jsx)(u,{className:`size-3.5`})}):null]},e.value)})}),(0,$.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,$.jsx)(v,{variant:`ghost`,onClick:()=>d(null),children:B(`run.back`)}),(0,$.jsx)(v,{disabled:!f.length,onClick:()=>{t(l.filter(e=>f.includes(e.value))),n()},children:f.length>1?B(`project.addMany`,{n:f.length}):B(`project.add`)})]})]}):(0,$.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),m()},className:`flex flex-col gap-5`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(P,{children:B(`project.logoUrl`)}),(0,$.jsx)(g,{autoFocus:!0,value:r,inputMode:`url`,placeholder:`https://example.com`,onChange:e=>i(e.target.value)}),(0,$.jsx)(`p`,{className:`mt-1.5 text-[0.8125rem] text-ink-3`,children:B(`project.colorsUrlHint`)})]}),s?(0,$.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:s}):null,(0,$.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,$.jsx)(v,{variant:`ghost`,onClick:n,children:B(`common.cancel`)}),(0,$.jsx)(v,{type:`submit`,busy:a,disabled:!r.trim(),children:B(`run.next`)})]})]})})}function Pn({projectId:e,data:t,colors:n,sections:r,gradients:a,patterns:o,rules:s,sectioned:u,ruled:d,save:f,readOnly:p}){let[m,h]=(0,Q.useState)(()=>n.map(e=>({...e,id:l()}))),[_,v]=(0,Q.useState)(r),[b,x]=(0,Q.useState)(a),[S,C]=(0,Q.useState)(o),[w,E]=(0,Q.useState)(null),[D,O]=(0,Q.useState)(null),k=re(e,p),A=c(s),[j,N]=(0,Q.useState)(null),[ne,P]=(0,Q.useState)(null),[ie,I]=(0,Q.useState)(!1),L=i({colors:m.filter(e=>Mn.test(e.value)).map(({name:e,value:t,section:n})=>({name:e.trim(),value:t,...n?{section:n}:{}})),colorSections:_,gradients:b,patterns:S,colorRules:A.rules},f),ae=u?_:[],oe=ae.filter(e=>(e.kind??`colors`)===`colors`),se=e=>oe.some(t=>t.id===e.section),z=m.filter(e=>!se(e)),le=(z[0]??m[0])?.id,V=(e,t)=>h(n=>n.map(n=>n.id===e?{...n,...t}:n)),H=e=>h(t=>[...t,...e.map(e=>({...e,id:l()}))].slice(0,T.colors)),U=[{value:``,label:B(`project.sectionStandard`)},...oe.map(e=>({value:e.id,label:e.title||B(`project.sectionUntitled`)}))],W=(e,t)=>{let n=l();N(n),v(r=>[...r,{id:n,title:t,...e===`colors`?{}:{kind:e}}])},G=e=>({id:l(),name:``,section:e,type:`linear`,angle:90,stops:[{color:m[0]?.value&&Mn.test(m[0].value)?m[0].value:`#4b73ff`,at:0},{color:m[1]?.value&&Mn.test(m[1].value)?m[1].value:`#ff6d1b`,at:100}]}),K=e=>t.files.find(t=>t.id===e)?.name??`pattern`,ue=[...m.length<T.colors?[{label:B(`project.colorNew`),icon:(0,$.jsx)(q,{className:`size-4 shrink-0`}),onPick:()=>pe()},{label:B(`project.colorsFromUrl`),icon:(0,$.jsx)(Jt,{className:`size-4 shrink-0`}),onPick:()=>I(!0)}]:[],...u&&_.length<T.logoSections?[{label:B(`project.colorSectionAdd`),icon:(0,$.jsx)(Bt,{className:`size-4 shrink-0`}),onPick:()=>W(`colors`,``)},{label:B(`project.gradientSectionAdd`),icon:(0,$.jsx)(Pt,{className:`size-4 shrink-0`}),onPick:()=>W(`gradients`,B(`project.gradientSectionTitle`))},{label:B(`project.patternSectionAdd`),icon:(0,$.jsx)(Ht,{className:`size-4 shrink-0`}),onPick:()=>W(`patterns`,B(`project.patternSectionTitle`))}]:[],...!d||A.full?[]:[{label:B(`project.ruleNew`),icon:(0,$.jsx)($e,{className:`size-4 shrink-0`}),onPick:()=>A.add()}]],fe=e=>(0,$.jsxs)(`div`,{className:`group/row flex items-center gap-2`,children:[(0,$.jsx)(y,{value:Mn.test(e.value)?e.value:`#888888`,onChange:t=>V(e.id,{value:t.target.value})}),(0,$.jsx)(g,{value:e.name,autoFocus:e.id===ne,placeholder:B(`project.colorName`),maxLength:120,onChange:t=>V(e.id,{name:t.target.value}),className:`min-w-0 flex-1`}),(0,$.jsx)(g,{value:e.value,placeholder:`#e0531b`,spellCheck:!1,onChange:t=>V(e.id,{value:t.target.value.trim()}),className:`w-28 font-mono text-[0.8125rem]`}),(0,$.jsxs)(`div`,{className:`flex w-28 shrink-0 items-center justify-end max-sm:w-auto`,children:[e.id===le?(0,$.jsx)(`span`,{className:`mr-1 max-sm:hidden`,children:(0,$.jsx)(M,{tone:`ember`,children:B(`project.colorAccent`)})}):p?null:(0,$.jsx)(F,{label:B(`project.colorFirst`),onClick:()=>h(t=>[{...e,section:void 0},...t.filter(t=>t.id!==e.id)]),className:`opacity-0 transition focus:opacity-100 group-hover/row:opacity-100 coarse:opacity-100`,children:(0,$.jsx)(ge,{className:`size-4`})}),p||!oe.length?null:(0,$.jsx)(be,{options:U,value:se(e)?e.section??``:``,onChange:t=>V(e.id,{section:t||void 0}),className:`opacity-0 focus-within:opacity-100 group-hover/row:opacity-100 coarse:opacity-100`}),p?null:(0,$.jsx)(F,{label:B(`project.remove`),onClick:()=>h(t=>t.filter(t=>t.id!==e.id)),className:`opacity-0 transition focus:opacity-100 group-hover/row:opacity-100 coarse:opacity-100 hover:text-rose`,children:(0,$.jsx)(R,{className:`size-4`})})]})]},e.id),pe=e=>{let t=l();P(t),h(n=>[...n,{id:t,name:``,value:`#888888`,...e?{section:e}:{}}])};return(0,$.jsxs)(X,{title:B(`project.colors`),hint:B(`project.colorsHint`),save:L,locked:p,action:p?null:(0,$.jsx)(de,{entries:ue}),children:[(0,$.jsxs)(`div`,{className:`flex flex-col gap-7`,children:[z.length?(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:`flex flex-col gap-2`,children:z.map(fe)}),p?null:(0,$.jsx)(`p`,{className:`mt-1.5 text-[0.8125rem] text-ink-3`,children:B(`project.colorUse`)})]}):m.length?null:(0,$.jsx)(`p`,{className:`text-[0.875rem] text-ink-3`,children:B(`project.colorsEmpty`)}),ae.map(t=>{let n=t.kind??`colors`,r=m.filter(e=>e.section===t.id),i=b.filter(e=>e.section===t.id),a=S.filter(e=>e.section===t.id),o=n===`gradients`?i.length:n===`patterns`?a.length:r.length;return(0,$.jsxs)(`div`,{className:`group/section flex flex-col gap-3`,children:[(0,$.jsx)(te,{title:t.title,titlePlaceholder:B(n===`gradients`?`project.gradientSectionTitlePlaceholder`:n===`patterns`?`project.patternSectionTitlePlaceholder`:`project.colorSectionTitle`),kind:n===`gradients`?{icon:(0,$.jsx)(Pt,{}),label:B(`project.kindGradients`)}:n===`patterns`?{icon:(0,$.jsx)(Ht,{}),label:B(`project.kindPatterns`)}:{icon:(0,$.jsx)(Xe,{}),label:B(`project.kindColors`)},autoFocus:j===t.id,readOnly:p,onChange:e=>v(n=>n.map(n=>n.id===t.id?{...n,...e}:n)),onRemove:()=>{if(!o||confirm(B(n===`colors`?`project.colorSectionRemoveConfirm`:`project.fillSectionRemoveConfirm`,{name:t.title||B(`project.sectionUntitled`)}))){v(e=>e.filter(e=>e.id!==t.id)),h(e=>e.map(e=>e.section===t.id?{...e,section:void 0}:e)),x(e=>e.filter(e=>e.section!==t.id));for(let e of a)k.remove(e.file);C(e=>e.filter(e=>e.section!==t.id))}}}),n===`gradients`?(0,$.jsxs)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(200px,1fr))] gap-3`,children:[i.map(e=>(0,$.jsx)(On,{gradient:e,readOnly:p,onEdit:()=>E(e),onChange:t=>x(n=>n.map(n=>n.id===e.id?{...n,...t}:n)),onRemove:()=>x(t=>t.filter(t=>t.id!==e.id))},e.id)),p||b.length>=T.gradients?null:(0,$.jsxs)(`button`,{type:`button`,onClick:()=>E(G(t.id)),className:`flex min-h-28 flex-col items-center justify-center gap-2 rounded-lg border border-input border-dashed text-[0.875rem] text-ink-3 transition hover:border-ink-4 hover:text-ink`,children:[(0,$.jsx)(q,{className:`size-5`}),B(`project.gradientAdd`)]})]}):n===`patterns`?(0,$.jsxs)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(200px,1fr))] gap-3`,children:[a.map(t=>(0,$.jsx)(An,{projectId:e,pattern:t,fileName:K(t.file),readOnly:p,onEdit:()=>O(t),onChange:e=>C(n=>n.map(n=>n.id===t.id?{...n,...e}:n)),onRemove:()=>{k.remove(t.file),C(e=>e.filter(e=>e.id!==t.id))}},t.id)),p||S.length>=T.files.pattern?null:(0,$.jsxs)(`button`,{type:`button`,onClick:()=>O({id:l(),name:``,section:t.id,file:``}),className:`flex min-h-28 flex-col items-center justify-center gap-2 rounded-lg border border-input border-dashed text-[0.875rem] text-ink-3 transition hover:border-ink-4 hover:text-ink`,children:[(0,$.jsx)(q,{className:`size-5`}),B(`project.patternAdd`)]})]}):(0,$.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[r.map(fe),p||m.length>=T.colors?null:(0,$.jsx)(ce,{label:B(`project.colorAdd`),onClick:()=>pe(t.id)})]})]},t.id)}),d?(0,$.jsx)(ee,{rules:A,placeholder:B(`project.colorRulePlaceholder`),readOnly:p}):null]}),k.error?(0,$.jsx)(`p`,{className:`mt-3 text-[0.875rem] text-rose`,children:k.error}):null,w?(0,$.jsx)(wn,{projectId:e,gradient:w,isNew:!b.some(e=>e.id===w.id),brand:m.filter(e=>Mn.test(e.value)),onClose:()=>E(null),onSave:e=>x(t=>t.some(t=>t.id===e.id)?t.map(t=>t.id===e.id?e:t):[...t,e])}):null,D?(0,$.jsx)(jn,{projectId:e,pattern:D,isNew:!S.some(e=>e.id===D.id),fileName:K,busy:k.busy,error:k.error,upload:async e=>(await k.upload(`pattern`,[e]))[0]??null,removeFile:e=>void k.remove(e),onClose:()=>O(null),onSave:e=>C(t=>t.some(t=>t.id===e.id)?t.map(t=>t.id===e.id?e:t):[...t,e])}):null,ie?(0,$.jsx)(Nn,{projectId:e,onClose:()=>I(!1),onAdd:H}):null]})}var Fn=e=>/^(ja|yes|true)$/i.test(e.trim()),In={text:tt,longtext:Ke,number:He,date:Te,url:K,email:Ze,phone:We,boolean:Ue};function Ln({type:e,detected:t,onChange:n}){let[r,i]=(0,Q.useState)(!1),[a,o]=(0,Q.useState)(!1),s=(0,Q.useRef)(null);(0,Q.useEffect)(()=>{if(!r)return;let e=e=>{s.current?.contains(e.target)||i(!1)},t=e=>e.key===`Escape`&&i(!1);return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[r]);let c=In[e??t],l=`${B(`project.factType`)}: ${B(`project.type.${e??t}`)}`,d=`flex w-full items-center gap-3 rounded-lg px-3 py-2 text-left text-[0.875rem] text-ink-2 hover:bg-accent hover:text-ink`,f=e=>{n(e),i(!1)};return(0,$.jsxs)(`div`,{className:`relative`,ref:s,children:[(0,$.jsx)(`button`,{type:`button`,"aria-label":l,title:l,"aria-haspopup":`menu`,"aria-expanded":r,onClick:e=>{o(window.innerHeight-e.currentTarget.getBoundingClientRect().bottom<400),i(e=>!e)},className:A(`inline-flex size-11 items-center justify-center rounded-lg transition hover:bg-accent hover:text-ink`,r?`bg-accent text-ink`:e?`text-ink-2`:`text-ink-4`),children:(0,$.jsx)(c,{className:`size-4`})}),r?(0,$.jsxs)(`div`,{role:`menu`,className:A(`absolute right-0 z-50 w-56 animate-rise rounded-xl bg-card p-1.5 shadow-overlay ring-1 ring-border-soft`,a?`bottom-12`:`top-12`),children:[(0,$.jsxs)(`button`,{type:`button`,role:`menuitemradio`,"aria-checked":!e,className:d,onClick:()=>f(void 0),children:[(0,$.jsx)(ht,{className:`size-4 shrink-0`}),(0,$.jsx)(`span`,{className:`flex-1`,children:B(`project.factAuto`)}),(0,$.jsx)(`span`,{className:`text-[0.75rem] text-ink-4`,children:B(`project.type.${t}`)}),(0,$.jsx)(u,{className:A(`size-4 shrink-0`,e&&`invisible`)})]}),(0,$.jsx)(`div`,{className:`mx-2 my-1 h-px bg-border-soft`}),he.map(t=>{let n=In[t];return(0,$.jsxs)(`button`,{type:`button`,role:`menuitemradio`,"aria-checked":e===t,className:d,onClick:()=>f(t),children:[(0,$.jsx)(n,{className:`size-4 shrink-0`}),(0,$.jsx)(`span`,{className:`flex-1`,children:B(`project.type.${t}`)}),(0,$.jsx)(u,{className:A(`size-4 shrink-0`,e!==t&&`invisible`)})]},t)})]}):null]})}function Rn({facts:e,save:t,readOnly:n}){let r=(0,Q.useRef)(0),a=(0,Q.useRef)(null),[o,s]=(0,Q.useState)(()=>e.map(e=>({...e,id:`f${r.current++}`}))),c=i(o.filter(e=>e.key&&e.label.trim()).map(({key:e,label:t,value:n,type:r})=>({key:e,label:t.trim(),value:n,...r?{type:r}:{}})),t),l=(e,t)=>s(n=>n.map(n=>n.id===e?{...n,...t}:n)),u=(e,t,n=!1)=>{let i=`f${r.current++}`;a.current=`${i}:${t}`;let o={id:i,key:``,label:``,value:``,...e};s(e=>n?[o,...e]:[...e,o])},f=e=>t=>{t&&a.current===e&&(a.current=null,t.focus())},p=D.filter(e=>!o.some(t=>t.key===e));return(0,$.jsxs)(X,{title:B(`project.facts`),hint:B(`project.factsHint`),save:c,locked:n,action:o.length<T.facts&&!n?(0,$.jsxs)(v,{variant:`secondary`,size:`sm`,onClick:()=>u({},`label`,!0),children:[(0,$.jsx)(q,{className:`size-4`}),` `,B(`project.factAdd`)]}):null,children:[(0,$.jsx)(`div`,{className:`flex flex-col gap-2`,children:o.map(e=>{let t=O(e.value),r=e.type??t;return(0,$.jsxs)(`div`,{className:`grid grid-cols-[minmax(0,1fr)_auto_auto] items-start gap-x-1 gap-y-2 sm:grid-cols-[minmax(0,2fr)_minmax(0,3fr)_auto_auto]`,children:[(0,$.jsx)(g,{ref:f(`${e.id}:label`),value:e.label,placeholder:B(`project.factLabel`),title:e.key?`{{facts.${e.key}}}`:void 0,onChange:t=>l(e.id,{label:t.target.value}),onBlur:()=>{!e.key&&e.label.trim()&&l(e.id,{key:d(e.label,o.map(e=>e.key))})},className:`max-sm:col-span-3 max-sm:font-medium sm:mr-1`}),e.type===`boolean`?(0,$.jsxs)(`div`,{className:`flex h-11 items-center gap-3`,children:[(0,$.jsx)(oe,{checked:Fn(e.value),label:e.label,onChange:t=>l(e.id,{value:B(t?`project.yes`:`project.no`)})}),(0,$.jsx)(`span`,{className:`text-[0.875rem] text-ink-2`,children:Fn(e.value)?B(`project.yes`):B(`project.no`)})]}):(0,$.jsx)(se,{ref:f(`${e.id}:value`),rows:1,minRows:r===`longtext`?2:1,maxRows:10,value:e.value,placeholder:B(`project.factValue`),onChange:t=>l(e.id,{value:t.target.value}),className:`min-h-11`}),(0,$.jsx)(Ln,{type:e.type,detected:t,onChange:t=>l(e.id,{type:t})}),n?null:(0,$.jsx)(F,{label:B(`project.remove`),onClick:()=>s(t=>t.filter(t=>t.id!==e.id)),className:`size-11 rounded-lg hover:text-rose`,children:(0,$.jsx)(R,{className:`size-4`})})]},e.id)})}),o.length<T.facts&&!n?(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 ${o.length?`mt-4`:``}`,children:[(0,$.jsxs)(v,{variant:`secondary`,size:`sm`,onClick:()=>u({},`label`),children:[(0,$.jsx)(q,{className:`size-4`}),` `,B(`project.factAdd`)]}),p.map(e=>(0,$.jsxs)(`button`,{type:`button`,onClick:()=>u({key:e,label:B(`fact.${e}`)},`value`),className:`inline-flex h-8 items-center gap-1 rounded-full bg-paper-2 px-3 text-[0.8125rem] text-ink-2 transition hover:bg-paper-3 hover:text-ink`,children:[(0,$.jsx)(q,{className:`size-3.5`}),` `,B(`fact.${e}`)]},e))]}):null]})}function zn({onLogo:e,children:t,className:n}){let[r,i]=(0,Q.useState)(!1);return e?(0,$.jsx)(`div`,{onDragOver:e=>{e.dataTransfer.types.includes(`application/x-wizards-logo`)&&(e.preventDefault(),i(!0))},onDragLeave:()=>i(!1),onDrop:t=>{let n=t.dataTransfer.getData(on);i(!1),n&&(t.preventDefault(),e(n))},className:A(`-m-2 rounded-xl p-2 transition`,r&&`bg-paper-2 ring-1 ring-focus`,n),children:t}):(0,$.jsx)(`div`,{className:n,children:t})}function Bn({projectId:e,data:t,readOnly:n,sections:r,rules:a,sectioned:o,ruled:s,save:u}){let d=re(e,n),[f,p]=(0,Q.useState)(r),m=c(a),[h,g]=(0,Q.useState)(null),[_,v]=(0,Q.useState)(!1),y=(0,Q.useRef)(null),b=i({logoSections:f,logoRules:m.rules},u),S=t.files.filter(e=>e.kind===`logo`),C=new Map(S.map(e=>[e.id,e])),w=o?f:[],E=new Set(w.flatMap(e=>e.logos)),D=S.filter(e=>!E.has(e.id)),O=x(S,f)?.id,k=(e,t)=>p(n=>n.map(n=>{let r=n.logos.filter(t=>t!==e);return{...n,logos:n.id===t?[...r,e]:r}})),A=(e,t)=>p(n=>n.map(n=>n.id===e?{...n,...t}:n)),j=async(e,t)=>{let n=await d.upload(`logo`,e);for(let e of n)k(e.id,t)},M=w.length?{options:[{value:``,label:B(`project.sectionStandard`)},...w.map(e=>({value:e.id,label:e.title||B(`project.sectionUntitled`)}))],current:e=>w.find(t=>t.logos.includes(e.id))?.id??``,onMove:(e,t)=>k(e.id,t||null)}:void 0,N=(t,n,r)=>(0,$.jsx)(sn,{projectId:e,kind:`logo`,files:t,actions:d,accept:`image/*`,addLabel:r?B(`project.logoAdd`):void 0,onUpload:e=>void j(e,n),mainId:O,onMakeMain:e=>{k(e.id,null),d.order(`logo`,[e.id,...S.filter(t=>t.id!==e.id).map(e=>e.id)])},moveTo:M,onRemove:e=>{confirm(B(`project.removeConfirm`,{name:e.name}))&&(d.remove(e.id),k(e.id,null))}}),ne=n?void 0:e=>t=>k(t,e),P=[{label:B(`project.logoUpload`),icon:(0,$.jsx)(Je,{className:`size-4 shrink-0`}),onPick:()=>y.current?.click()},{label:B(`project.logoFromUrl`),icon:(0,$.jsx)(Jt,{className:`size-4 shrink-0`}),onPick:()=>v(!0)},...o&&f.length<T.logoSections?[{label:B(`project.logoSectionAdd`),icon:(0,$.jsx)(Bt,{className:`size-4 shrink-0`}),onPick:()=>{let e=l();g(e),p(t=>[...t,{id:e,title:``,description:``,logos:[]}])}}]:[],...!s||m.full?[]:[{label:B(`project.ruleNew`),icon:(0,$.jsx)($e,{className:`size-4 shrink-0`}),onPick:()=>m.add()}]];return(0,$.jsxs)(X,{title:B(`project.logos`),hint:B(`project.logosHint`),save:b,action:n?null:(0,$.jsx)(de,{entries:P}),children:[(0,$.jsx)(`input`,{ref:y,type:`file`,accept:`image/*`,className:`sr-only`,tabIndex:-1,"aria-hidden":!0,onChange:e=>{let t=Array.from(e.target.files??[]);e.target.value=``,t.length&&j(t,null)}}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-7`,children:[(0,$.jsx)(zn,{onLogo:ne?.(null),children:N(D,null,!0)}),w.map(e=>(0,$.jsx)(`div`,{className:`group/section`,children:(0,$.jsxs)(zn,{onLogo:ne?.(e.id),className:`flex flex-col gap-3`,children:[(0,$.jsx)(te,{title:e.title,description:e.description,titlePlaceholder:B(`project.logoSectionTitle`),descriptionPlaceholder:B(`project.logoSectionUse`),autoFocus:h===e.id,readOnly:n,onChange:t=>A(e.id,t),onRemove:()=>{(!e.logos.length||confirm(B(`project.logoSectionRemoveConfirm`,{name:e.title||B(`project.sectionUntitled`)})))&&p(t=>t.filter(t=>t.id!==e.id))}}),N(e.logos.map(e=>C.get(e)).filter(e=>!!e),e.id,!0)]})},e.id)),s?(0,$.jsx)(ee,{rules:m,placeholder:B(`project.logoRulePlaceholder`),readOnly:n}):null]}),d.error?(0,$.jsx)(`p`,{className:`mt-3 text-[0.875rem] text-rose`,children:d.error}):null,_?(0,$.jsx)(cn,{kind:`logo`,onClose:()=>v(!1),fetchUrl:e=>d.fromUrl(`logo`,e),onAdded:e=>{for(let t of e)k(t.id,null)}}):null]})}var Vn=new Set;function Hn(e){(0,Q.useEffect)(()=>{let t=e.trim().toLowerCase().replace(/\s+/g,`-`);if(!t||Vn.has(t))return;Vn.add(t);let n=document.createElement(`link`);n.rel=`stylesheet`,n.href=`https://fonts.bunny.net/css?family=${encodeURIComponent(t)}:${J.join(`,`)}&display=swap`,document.head.append(n)},[e])}var Un=e=>e?`"${e}", system-ui, sans-serif`:`system-ui, sans-serif`;function Wn({unit:e,label:t,...n}){return(0,$.jsxs)(`label`,{className:`inline-flex items-center gap-1 text-[0.75rem] text-ink-3`,title:t,children:[(0,$.jsx)(`input`,{type:`number`,"aria-label":t,className:`h-8 w-14 rounded-md border border-input bg-card px-1.5 text-right text-[0.8125rem] text-ink tabular-nums outline-none transition focus:border-focus focus:ring-2 focus:ring-focus-glow`,...n}),e]})}var Gn=`h-8 rounded-md border border-input bg-card px-1.5 text-[0.8125rem] text-ink outline-none transition focus:border-focus focus:ring-2 focus:ring-focus-glow`,Kn={web:`project.fontUseWeb`,documents:`project.fontUseDocuments`,print:`project.fontUsePrint`,images:`project.fontUseImages`,video:`project.fontUseVideo`};function qn({font:e,first:t,readOnly:n,autoFocus:i,onChange:a,onRemove:o}){return Hn(e.family),(0,$.jsxs)(`div`,{className:`group/font relative flex flex-col gap-2 rounded-lg bg-paper p-3 ring-1 ring-border-soft`,children:[(0,$.jsxs)(`div`,{className:`flex h-28 items-end justify-between overflow-hidden rounded-md bg-card px-4 pb-3 ring-1 ring-border-soft`,style:{fontFamily:Un(e.family)},children:[(0,$.jsx)(`span`,{className:`text-[3.5rem] text-ink leading-none`,children:`Aa`}),(0,$.jsx)(`span`,{className:`truncate pl-3 text-[0.875rem] text-ink-3`,children:`ABCDEFG abcdefg 0123456789`})]}),n?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`font-medium text-[0.9375rem]`,children:e.family}),e.role?(0,$.jsx)(`p`,{className:`text-[0.875rem] text-ink-3`,children:e.role}):null]}):(0,$.jsxs)(`div`,{children:[(0,$.jsx)(H,{value:e.family,label:B(`project.fontFamily`),placeholder:B(`project.fontFamily`),maxLength:80,autoFocus:i,onChange:e=>a({family:e}),className:`font-medium text-[0.9375rem]`}),(0,$.jsx)(H,{value:e.role,label:B(`project.fontRole`),placeholder:B(t?`project.fontRoleFirst`:`project.fontRole`),maxLength:200,onChange:e=>a({role:e}),className:`text-[0.875rem] text-ink-3`})]}),(0,$.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:J.map(t=>{let r=e.weights.includes(t);return(0,$.jsx)(`button`,{type:`button`,disabled:n,"aria-pressed":r,onClick:()=>a({weights:r?e.weights.filter(e=>e!==t):[...e.weights,t].sort((e,t)=>e-t)}),style:{fontFamily:Un(e.family),fontWeight:t},className:A(`h-7 rounded-full px-2.5 text-[0.8125rem] tabular-nums transition`,r?`bg-ink text-paper`:`bg-paper-2 text-ink-3 hover:text-ink`,n&&!r&&`hidden`),children:t},t)})}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[n?e.license?(0,$.jsx)(`p`,{className:`text-[0.8125rem] text-ink-3`,children:e.license}):null:(0,$.jsx)(H,{value:e.license??``,label:B(`project.fontLicense`),placeholder:B(`project.fontLicensePlaceholder`),maxLength:200,onChange:e=>a({license:e}),className:`text-[0.8125rem] text-ink-3`}),n&&!e.uses?.length?null:(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1`,children:[(0,$.jsx)(`span`,{className:`mr-1 text-[0.8125rem] text-ink-3`,children:B(`project.fontUses`)}),r.map(t=>{let i=!!e.uses?.includes(t);return(0,$.jsxs)(`button`,{type:`button`,disabled:n,"aria-pressed":i,onClick:()=>{let n=i?(e.uses??[]).filter(e=>e!==t):r.filter(n=>n===t||e.uses?.includes(n));a({uses:n.length?n:void 0})},className:A(`inline-flex h-7 items-center gap-1 rounded-full px-2.5 text-[0.8125rem] transition`,i?`bg-card text-ink ring-1 ring-border`:`bg-paper-2 text-ink-3 hover:text-ink`,n&&!i&&`hidden`),children:[i?(0,$.jsx)(u,{className:`size-3.5`}):null,B(Kn[t])]},t)})]})]}),n?null:(0,$.jsx)(F,{label:B(`project.remove`),onClick:o,className:`absolute top-4 right-4 size-8 bg-card opacity-0 shadow-soft transition focus:opacity-100 group-hover/font:opacity-100 coarse:opacity-100 hover:text-rose`,children:(0,$.jsx)(R,{className:`size-4`})})]})}function Jn({style:e,fonts:t,sample:n,readOnly:r,autoFocus:i,onChange:a,onRemove:o}){let s=t.find(t=>t.id===e.font)??t[0],c={fontFamily:Un(s?.family),fontWeight:e.weight,fontSize:`${Math.min(e.size,56)}px`,lineHeight:`${e.lineHeight}%`,letterSpacing:`${e.tracking/100}em`,textTransform:e.uppercase?`uppercase`:void 0};return(0,$.jsxs)(`li`,{className:`group/row flex flex-col gap-2 border-border-soft border-b py-4 first:pt-1 last:border-b-0`,children:[(0,$.jsx)(`div`,{className:`truncate text-ink`,style:c,children:n}),(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-2`,children:[r?(0,$.jsx)(`span`,{className:`font-medium text-[0.8125rem] text-ink-2 uppercase tracking-wide`,children:e.name}):(0,$.jsx)(`div`,{className:`w-40`,children:(0,$.jsx)(H,{value:e.name,label:B(`project.styleName`),placeholder:B(`project.styleName`),maxLength:60,autoFocus:i,onChange:e=>a({name:e}),className:`font-medium text-[0.8125rem] text-ink-2 uppercase tracking-wide`})}),(0,$.jsxs)(`fieldset`,{disabled:r,className:`flex flex-wrap items-center gap-x-3 gap-y-2`,children:[t.length>1?(0,$.jsx)(`select`,{"aria-label":B(`project.styleFont`),value:s?.id??``,onChange:e=>a({font:e.target.value}),className:A(Gn,`max-w-40`),children:t.map(e=>(0,$.jsx)(`option`,{value:e.id,children:e.family||B(`project.fontFamily`)},e.id))}):null,(0,$.jsx)(`select`,{"aria-label":B(`project.styleWeight`),value:e.weight,onChange:e=>a({weight:Number(e.target.value)}),className:Gn,children:[...new Set([...J,e.weight])].sort().map(e=>(0,$.jsx)(`option`,{value:e,children:e},e))}),(0,$.jsx)(Wn,{unit:`px`,label:B(`project.styleSize`),min:6,max:400,value:e.size,onChange:e=>a({size:Number(e.target.value)||16})}),(0,$.jsx)(Wn,{unit:B(`project.styleLine`),label:B(`project.styleLineLabel`),min:50,max:300,value:e.lineHeight,onChange:e=>a({lineHeight:Number(e.target.value)||100})}),(0,$.jsx)(Wn,{unit:B(`project.styleTracking`),label:B(`project.styleTrackingLabel`),min:-20,max:50,step:.5,value:e.tracking,onChange:e=>a({tracking:Number(e.target.value)||0})}),(0,$.jsx)(`button`,{type:`button`,"aria-pressed":!!e.uppercase,title:B(`project.styleUpper`),"aria-label":B(`project.styleUpper`),onClick:()=>a({uppercase:!e.uppercase}),className:A(`grid size-8 place-items-center rounded-md transition`,e.uppercase?`bg-ink text-paper`:`text-ink-3 hover:bg-paper-2 hover:text-ink`),children:(0,$.jsx)(Rt,{className:`size-4`})})]}),r?null:(0,$.jsx)(F,{label:B(`project.remove`),onClick:o,className:`ml-auto size-8 opacity-0 transition focus:opacity-100 group-hover/row:opacity-100 coarse:opacity-100 hover:text-rose`,children:(0,$.jsx)(R,{className:`size-4`})})]})]})}function Yn({projectId:e,onAdd:t,onClose:n}){let[r,i]=(0,Q.useState)(``),[a,o]=(0,Q.useState)(!1),[s,c]=(0,Q.useState)(null),[l,u]=(0,Q.useState)(null),[d,f]=(0,Q.useState)([]),p=async()=>{o(!0),c(null);try{let{fonts:t}=await I.post(`/api/studio/projects/${e}/fonts/scan`,{url:r.trim()});t.length?(u(t),f(t.slice(0,2).map(e=>e.family))):c(B(`project.fontsNoneFound`))}catch(e){c(e.message)}o(!1)};return(0,$.jsx)(Z,{open:!0,onClose:n,wide:l?!0:void 0,title:B(l?`project.fontsFound`:`project.fontsFromUrl`),children:l?(0,$.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,$.jsx)(`p`,{className:`-mt-2 text-[0.875rem] text-ink-3`,children:B(`project.fontsFoundHint`)}),(0,$.jsx)(`div`,{className:`flex flex-col gap-2`,children:l.map(e=>(0,$.jsx)(Xn,{font:e,on:d.includes(e.family),onToggle:()=>f(t=>t.includes(e.family)?t.filter(t=>t!==e.family):[...t,e.family])},e.family))}),(0,$.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,$.jsx)(v,{variant:`ghost`,onClick:()=>u(null),children:B(`run.back`)}),(0,$.jsx)(v,{disabled:!d.length,onClick:()=>{t(l.filter(e=>d.includes(e.family))),n()},children:d.length>1?B(`project.addMany`,{n:d.length}):B(`project.add`)})]})]}):(0,$.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),p()},className:`flex flex-col gap-5`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(P,{children:B(`project.logoUrl`)}),(0,$.jsx)(g,{autoFocus:!0,value:r,inputMode:`url`,placeholder:`https://example.com`,onChange:e=>i(e.target.value)}),(0,$.jsx)(`p`,{className:`mt-1.5 text-[0.8125rem] text-ink-3`,children:B(`project.fontsUrlHint`)})]}),s?(0,$.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:s}):null,(0,$.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,$.jsx)(v,{variant:`ghost`,onClick:n,children:B(`common.cancel`)}),(0,$.jsx)(v,{type:`submit`,busy:a,disabled:!r.trim(),children:B(`run.next`)})]})]})})}function Xn({font:e,on:t,onToggle:n}){return Hn(e.family),(0,$.jsxs)(`button`,{type:`button`,"aria-pressed":t,onClick:n,className:A(`flex items-center gap-4 rounded-lg px-4 py-3 text-left ring-1 transition`,t?`ring-2 ring-ember`:`ring-border-soft hover:ring-ink-4`),children:[(0,$.jsx)(`span`,{className:`text-[2rem] text-ink leading-none`,style:{fontFamily:Un(e.family)},children:`Aa`}),(0,$.jsxs)(`span`,{className:`flex min-w-0 flex-1 flex-col`,children:[(0,$.jsx)(`span`,{className:`font-medium text-[0.9375rem]`,children:e.family}),(0,$.jsx)(`span`,{className:`text-[0.8125rem] text-ink-3 tabular-nums`,children:e.weights.length?e.weights.join(` · `):B(`project.fontWeightsUnknown`)})]}),t?(0,$.jsx)(`span`,{className:`grid size-5 place-items-center rounded-full bg-ember text-white`,children:(0,$.jsx)(u,{className:`size-3.5`})}):null]})}function Zn({projectId:e,fonts:t,styles:n,rules:r,ruled:a,sample:o,save:s,readOnly:u}){let[d,f]=(0,Q.useState)(t),[p,m]=(0,Q.useState)(n),h=c(r),[g,_]=(0,Q.useState)(null),[v,y]=(0,Q.useState)(!1),b=i({fonts:d,textStyles:p,typeRules:h.rules},s),x=(e,t=!1)=>{let n=e.map(e=>({id:l(),family:e.family,role:``,weights:e.weights}));t&&n[0]&&_(n[0].id),f(e=>[...e,...n].slice(0,T.fonts))},S=()=>{let e=l();_(e),m(t=>[...t,{id:e,name:``,size:16,weight:400,lineHeight:150,tracking:0}])},C=[...d.length<T.fonts?[{label:B(`project.fontNew`),icon:(0,$.jsx)(q,{className:`size-4 shrink-0`}),onPick:()=>x([{family:``,weights:[400,700]}],!0)},{label:B(`project.fontsFromUrl`),icon:(0,$.jsx)(Jt,{className:`size-4 shrink-0`}),onPick:()=>y(!0)}]:[],...p.length<T.textStyles?[{label:B(`project.styleNew`),icon:(0,$.jsx)(Qe,{className:`size-4 shrink-0`}),onPick:S}]:[],...!a||h.full?[]:[{label:B(`project.ruleNew`),icon:(0,$.jsx)($e,{className:`size-4 shrink-0`}),onPick:()=>h.add()}]];return(0,$.jsxs)(X,{title:B(`project.typography`),hint:B(`project.typographyHint`),save:b,action:u?null:(0,$.jsx)(de,{entries:C}),children:[(0,$.jsxs)(`div`,{className:`flex flex-col gap-7`,children:[d.length?(0,$.jsx)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(260px,1fr))] gap-3`,children:d.map((e,t)=>(0,$.jsx)(qn,{font:e,first:t===0,readOnly:u,autoFocus:g===e.id,onChange:t=>f(n=>n.map(n=>n.id===e.id?{...n,...t}:n)),onRemove:()=>f(t=>t.filter(t=>t.id!==e.id))},e.id))}):(0,$.jsx)(`p`,{className:`text-[0.875rem] text-ink-3`,children:B(`project.fontsEmpty`)}),p.length?(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h3`,{className:`font-medium text-[0.9375rem]`,children:B(`project.styles`)}),u?null:(0,$.jsx)(`p`,{className:`text-[0.875rem] text-ink-3 leading-snug`,children:B(`project.stylesHint`)}),(0,$.jsx)(`ul`,{className:`mt-2 flex flex-col`,children:p.map(e=>(0,$.jsx)(Jn,{style:e,fonts:d,sample:o,readOnly:u,autoFocus:g===e.id,onChange:t=>m(n=>n.map(n=>n.id===e.id?{...n,...t}:n)),onRemove:()=>m(t=>t.filter(t=>t.id!==e.id))},e.id))})]}):null,a?(0,$.jsx)(ee,{rules:h,placeholder:B(`project.typeRulePlaceholder`),readOnly:u}):null]}),v?(0,$.jsx)(Yn,{projectId:e,onClose:()=>y(!1),onAdd:e=>x(e)}):null]})}function Qn({project:e,save:t}){let[n,r]=(0,Q.useState)(e.brand.name??``),[a,o]=(0,Q.useState)(e.brand.about??``),s=i({name:n.trim(),about:a.trim()},e=>t({brand:e}));return(0,$.jsx)(X,{title:B(`project.base`),hint:B(`project.baseHint`),save:s,locked:e.readOnly,children:(0,$.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(P,{children:B(`project.title`)}),(0,$.jsx)(g,{value:n,maxLength:120,onChange:e=>r(e.target.value)}),(0,$.jsx)(`p`,{className:`mt-1.5 text-[0.8125rem] text-ink-3`,children:B(`project.titleHint`)})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(P,{children:B(`project.about`)}),(0,$.jsx)(se,{minRows:4,value:a,onChange:e=>o(e.target.value)}),(0,$.jsx)(`p`,{className:`mt-1.5 text-[0.8125rem] text-ink-3`,children:B(`project.aboutHint`)})]})]})})}function $n({project:e,group:t,children:n}){let r=fe(),i=N(e.id),[a,o]=(0,Q.useState)(0),[s,c]=(0,Q.useState)(!1),l=async t=>{await I.patch(`/api/studio/projects/${e.id}`,t),await r.invalidateQueries({queryKey:[`projects`]})},u=st({mutationFn:()=>I.del(`/api/studio/projects/${e.id}`),onSuccess:()=>r.invalidateQueries({queryKey:[`projects`]})}),d=at(),f=ft(),p=i.data??{files:[],embeddings:!0},m=`${e.id}:${a}`,h=e.readOnly,g=t===`knowledge`,_=lt(`brandSections`),y=lt(`brandRules`),b=lt(`typography`);return Ye(h?{}:{title:B(g?`project.assistantTitleKnowledge`:`project.assistantTitle`),hello:B(g?`project.assistantHelloKnowledge`:`project.assistantHello`),placeholder:B(g?`project.assistantComposerKnowledge`:`project.assistantComposer`),suggestions:g?[{label:B(`assistant.suggest.knowledgeHow`)},{label:B(`assistant.suggest.knowledgeSite`),fill:!0},{label:B(`assistant.suggest.knowledgeCategories`)}]:[{label:B(`assistant.suggest.readSite`),fill:!0},{label:B(`assistant.suggest.missing`)},{label:B(`assistant.suggest.facts`)}],summary:g?void 0:[e.brand.name?`title "${e.brand.name}"`:`no title`,`${e.facts.length} facts`,`${e.brand.colors?.length??0} colours`,`${p.files.filter(e=>e.kind===`logo`).length} logos`].join(` · `),onChanged:()=>o(e=>e+1)}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-9`,children:[h?(0,$.jsx)(qe,{children:Ge(e)}):null,t===`info`?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Y,{id:`base`,children:(0,$.jsx)(Qn,{project:e,save:l},`base:${m}`)}),(0,$.jsx)(Y,{id:`facts`,children:(0,$.jsx)(Rn,{facts:e.facts,save:e=>l({facts:e}),readOnly:h},`facts:${m}`)}),(0,$.jsx)(Y,{id:`logos`,children:(0,$.jsx)(Bn,{projectId:e.id,data:p,readOnly:h,sections:e.brand.logoSections??[],rules:e.brand.logoRules??[],sectioned:_,ruled:y,save:e=>l({brand:e})},`logos:${m}`)}),(0,$.jsx)(Y,{id:`colors`,children:(0,$.jsx)(Pn,{projectId:e.id,data:p,colors:e.brand.colors??[],sections:e.brand.colorSections??[],gradients:e.brand.gradients??[],patterns:e.brand.patterns??[],rules:e.brand.colorRules??[],sectioned:_,ruled:y,save:e=>l({brand:e}),readOnly:h},`colors:${m}`)}),b?(0,$.jsx)(Y,{id:`typography`,children:(0,$.jsx)(Zn,{projectId:e.id,fonts:e.brand.fonts??[],styles:e.brand.textStyles??[],rules:e.brand.typeRules??[],ruled:y,sample:e.brand.name||B(`project.typeSample`),save:e=>l({brand:e}),readOnly:h},`typography:${m}`)}):null,(0,$.jsx)(Y,{id:`assets`,children:(0,$.jsx)(bn,{projectId:e.id,data:p,readOnly:h,sections:e.brand.assetSections??[],save:e=>l({brand:e})},`assets:${m}`)})]}):null,n,t===`info`&&d&&!h&&f?(0,$.jsxs)(`div`,{children:[(0,$.jsx)(v,{variant:`danger`,onClick:()=>c(!0),children:B(`settings.delete`)}),(0,$.jsxs)(Z,{open:s,onClose:()=>c(!1),title:B(`settings.deleteTitle`,{name:e.name}),children:[(0,$.jsx)(`p`,{className:`-mt-2 text-[0.875rem] text-ink-2`,children:B(`settings.deleteBody`)}),u.error?(0,$.jsx)(`p`,{className:`mt-3 text-[0.8125rem] text-rose`,children:u.error.message}):null,(0,$.jsxs)(`div`,{className:`mt-5 flex justify-end gap-2`,children:[(0,$.jsx)(v,{variant:`ghost`,onClick:()=>c(!1),children:B(`common.cancel`)}),(0,$.jsx)(v,{variant:`danger`,busy:u.isPending,onClick:()=>u.mutate(),children:B(`common.delete`)})]})]})]}):null]})}var er={q:``,mode:``,days:0};function tr(e,t,n){let r=new URLSearchParams;t&&r.set(`wizard`,t),n.q.trim()&&r.set(`q`,n.q.trim()),n.mode&&r.set(`mode`,n.mode),n.days&&r.set(`days`,String(n.days));let i=r.toString();return p({queryKey:[`results`,e,i],queryFn:()=>I.get(`/api/studio/projects/${e}/results${i&&`?${i}`}`),enabled:!!e,placeholderData:e=>e,refetchInterval:15e3})}function nr({filter:e,onFilter:t}){let[n,r]=(0,Q.useState)(e.q);return(0,Q.useEffect)(()=>{if(n===e.q)return;let r=setTimeout(()=>t({...e,q:n}),250);return()=>clearTimeout(r)},[n,e,t]),(0,$.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,$.jsxs)(`div`,{className:`relative min-w-0 flex-1 basis-56`,children:[(0,$.jsx)(G,{className:`-translate-y-1/2 pointer-events-none absolute top-1/2 left-3 size-4 text-ink-3`}),(0,$.jsx)(g,{type:`search`,value:n,onChange:e=>r(e.target.value),placeholder:B(`space.resultsSearch`),"aria-label":B(`space.resultsSearch`),className:`w-full pl-9`})]}),(0,$.jsx)(b,{value:e.mode,onChange:n=>t({...e,mode:n}),options:[{value:``,label:B(`space.resultsModeAll`)},{value:`live`,label:`Live`},{value:`test`,label:`Test`}],className:`w-32`}),(0,$.jsx)(b,{value:String(e.days),onChange:n=>t({...e,days:Number(n)}),options:[{value:`0`,label:B(`space.resultsAnyTime`)},{value:`1`,label:B(`space.resultsDay`)},{value:`7`,label:B(`space.resultsDays`,{n:7})},{value:`30`,label:B(`space.resultsDays`,{n:30})}],className:`w-44`})]})}function rr({data:e,wizardId:t,filter:n,onFilter:r}){let[i,a]=(0,Q.useState)(null),s=t=>e.wizards.find(e=>e.id===t)?.title??``,c=new Intl.DateTimeFormat(W,{dateStyle:`medium`,timeStyle:`short`});return(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(X,{title:t?s(t):B(`space.resultsAll`),hint:B(`space.resultsHint`),plain:!0,children:[(0,$.jsx)(nr,{filter:n,onFilter:r}),e.runs.length?(0,$.jsx)(C,{className:`flex flex-col p-1.5`,children:e.runs.map(e=>(0,$.jsxs)(`button`,{type:`button`,onClick:()=>a(e),className:`flex items-center gap-3 rounded-lg px-3 py-2.5 text-left transition hover:bg-accent`,children:[(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`div`,{className:`truncate text-[0.875rem]`,children:t?c.format(new Date(e.doneAt)):s(e.wizardId)}),(0,$.jsxs)(`div`,{className:`truncate text-[0.75rem] text-ink-3`,children:[t?null:`${c.format(new Date(e.doneAt))} · `,B(`space.resultCredits`,{n:e.credits})]})]}),e.assets?(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-[0.75rem] text-ink-3 tabular-nums`,title:B(`space.resultFiles`,{n:e.assets}),children:[(0,$.jsx)(U,{className:`size-3.5`}),e.assets]}):null,e.mode===`test`?(0,$.jsx)(M,{children:B(`run.testChip`)}):(0,$.jsxs)(M,{tone:`live`,children:[`Live v`,e.version]})]},e.id))}):(0,$.jsx)(C,{children:(0,$.jsx)(o,{children:n.q.trim()||n.mode||n.days?B(`space.resultsNone`):B(`space.resultsEmpty`)})})]}),i?(0,$.jsx)(Ie,{header:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-medium text-[0.875rem]`,children:s(i.wizardId)}),i.mode===`test`?(0,$.jsx)(M,{children:B(`run.testChip`)}):(0,$.jsxs)(M,{tone:`live`,children:[`Live v`,i.version]})]}),onClose:()=>a(null),children:(0,$.jsx)(Mt,{runId:i.id,compact:!0,studio:!0},i.id)}):null]})}function ir({project:e,save:t}){let[n,r]=(0,Q.useState)(!1),[i,a]=(0,Q.useState)(e.name),o=st({mutationFn:()=>t({name:i.trim()}),onSuccess:()=>r(!1)});return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(F,{label:B(`project.rename`),onClick:()=>{a(e.name),r(!0)},children:(0,$.jsx)(V,{className:`size-4`})}),(0,$.jsx)(Z,{open:n,onClose:()=>r(!1),title:B(`project.rename`),children:(0,$.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),i.trim()&&o.mutate()},children:[(0,$.jsx)(g,{"data-autofocus":!0,value:i,maxLength:80,onChange:e=>a(e.target.value)}),o.error?(0,$.jsx)(`p`,{className:`mt-3 text-[0.875rem] text-rose`,children:o.error.message}):null,(0,$.jsxs)(`div`,{className:`mt-5 flex justify-end gap-2`,children:[(0,$.jsx)(v,{variant:`ghost`,onClick:()=>r(!1),children:B(`common.cancel`)}),(0,$.jsx)(v,{type:`submit`,busy:o.isPending,disabled:!i.trim(),children:B(`settings.save`)})]})]})})]})}function ar({project:e}){let t=fe();return(0,$.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,$.jsx)(pt,{}),e.readOnly?null:(0,$.jsx)(ir,{project:e,save:async n=>{await I.patch(`/api/studio/projects/${e.id}`,n),await t.invalidateQueries({queryKey:[`projects`]})}})]})}function or(e){let t=e.join(` `),[n,r]=(0,Q.useState)(e[0]);return(0,Q.useEffect)(()=>{let e=t.split(` `),n=0,i=()=>{n=0;let t=ct(),i=t.scrollTop>0&&t.clientHeight+t.scrollTop>=t.scrollHeight-4,a=(t===document.documentElement?0:t.getBoundingClientRect().top)+Math.max(120,t.clientHeight/3),o=e[0];for(let t of e){let e=document.getElementById(t)?.getBoundingClientRect().top;e!==void 0&&e<=a&&(o=t)}r(i?e.at(-1):o)},a=()=>{n||=requestAnimationFrame(i)};return i(),window.addEventListener(`scroll`,a,{passive:!0,capture:!0}),window.addEventListener(`resize`,a),()=>{cancelAnimationFrame(n),window.removeEventListener(`scroll`,a,{capture:!0}),window.removeEventListener(`resize`,a)}},[t]),n}function sr(e,t){let n=window.matchMedia(`(prefers-reduced-motion: reduce)`).matches;document.getElementById(e)?.scrollIntoView({block:`start`,behavior:t&&!n?`smooth`:`auto`})}function cr({groups:e,current:t,onPick:n}){return e.map(e=>{let r=e.sections.map(e=>(0,$.jsx)(St,{icon:e.icon??et,label:e.label,selected:e.id===t,onPick:()=>n(e.id)},e.id));return e.label?(0,$.jsx)(Tt,{label:e.label,children:r},e.plugin):(0,$.jsx)(`ul`,{className:`flex flex-col gap-0.5`,children:r},`own`)})}function lr(){let{group:e}=h(),[t,n]=ne(),r=ie(),i=a(),{hash:s}=i,{project:c,loading:l}=mt(),u=at(),d=ot(),f=jt(),[p,m]=(0,Q.useState)(null),[g,_]=(0,Q.useState)(null),[v,y]=(0,Q.useState)(null),b=ut(e)?e:void 0,x=b?void 0:d.spaceParts.find(t=>t.id===e),C=b??x?.id,w=i.state?.parts===!0,T=_t(yt(),d).map(e=>({...e,to:`/space/${e.id}`})),E=T.find(e=>e.id===C),D=t.get(`show`),O=C?D?2:1:0,k=f?Math.min(O,1):C&&v!==C&&!w?1:0,j=wt(k),M=wt(O),ee=(0,Q.useMemo)(()=>({slot:p,narrow:f,setDetail:_}),[p,f]),te=c?c.brand.name?.trim()||c.name:B(`nav.project`),N=le(),P=!!N&&!f,re=lt(`typography`)?[]:[`typography`],F=x?d.spaceMenus[x.id]??[]:[],I=x?[{plugin:null,label:null,sections:F}]:b&&b!==`results`?dt(b,d,re):[],L=b?dt(b,d).filter(e=>e.plugin):[],ae=or([...I,...b===`results`?L:[]].flatMap(e=>e.sections.map(e=>e.id))),R=b===`results`&&D&&D!==`all`?D:null,[oe,se]=(0,Q.useState)(er),ce=tr(b===`results`?c?.id:void 0,R,oe),z=ce.data?.wizards.find(e=>e.id===R)?.title,V=b===`data`&&D&&D!==`all`||b===`knowledge`&&D&&/^[ptfcvs]:/.test(D)?D:null,H=V?.startsWith(`s:`)?d.spaceSections.find(e=>e.id===V.slice(2)):void 0,U=b===`knowledge`&&V&&/^[ptf]:/.test(V)?V:null,W=Oe(b===`data`?c?.id:void 0),G=Fe(b===`knowledge`?c?.id:void 0),K=Ve(V?.startsWith(`v:`)?V.slice(2):``),ue=G.data?.categories.find(e=>e.id===(V?.startsWith(`c:`)?V.slice(2):K.data?.category.id)),de=b===`knowledge`?H?H.label():V?.startsWith(`v:`)?K.data&&`${K.data.category.name}: ${K.data.value}`:V?.startsWith(`c:`)?ue?.name:G.data?.items.find(e=>e.key===V)?.title:W.data?ze(W.data).flatMap(e=>e.items).find(e=>e.key===V)?.title:void 0;gt([{label:B(`nav.project`),to:`/space`},...E?[{label:E.label,to:`/space/${E.id}`}]:[],...E&&(g??z??de)?[{label:g??z??de}]:[]]);let fe={p:`page`,t:`table`,f:`file`,c:`category`,v:`category value`,s:`plugin section`};Ye({...b===`data`||b===`results`?{compact:!0}:{},...b===`data`?{suggestions:[{label:B(`assistant.suggest.dataWhat`)},{label:B(`assistant.suggest.dataWho`)},{label:B(`assistant.suggest.dataEdit`)}]}:b===`results`?{suggestions:[{label:B(`assistant.suggest.resultsFailed`)},{label:B(`assistant.suggest.resultsCost`)},{label:B(`assistant.suggest.resultsShare`)}]}:{},...V&&de?{open:{kind:fe[V[0]]??`item`,id:V.slice(2),label:de}}:R&&z?{open:{kind:`wizard`,id:R,label:z}}:{}});let pe=b===`results`||b===`data`||V?s.slice(1):D||s.slice(1),me=(0,Q.useRef)(``);if((0,Q.useEffect)(()=>{let e=`${C}#${pe}`;pe&&me.current!==e&&document.getElementById(pe)&&(me.current=e,requestAnimationFrame(()=>sr(pe,!1)))},[C,pe,c?.id,d.spaceSections,F.length]),!C){let t=s.slice(1),n=t?xt(t,d):null;if(n===`knowledge`&&d.spaceSections.some(e=>e.id===t))return(0,$.jsx)(S,{to:`/space/knowledge?show=s:${t}`,replace:!0});if(n)return(0,$.jsx)(S,{to:f?`/space/${n}?show=${t}`:{pathname:`/space/${n}`,hash:t},replace:!0});if((t||e)&&d.status!==`ready`)return null;if(e!==void 0||!f)return(0,$.jsx)(S,{to:`/space/info`,replace:!0,state:{parts:!0}})}if(b===`knowledge`&&!D&&d.spaceSections.some(e=>e.id===s.slice(1)))return(0,$.jsx)(S,{to:`/space/knowledge?show=s:${s.slice(1)}`,replace:!0});let q=e=>{if(f){r({search:`?show=${e}`});return}me.current=`${C}#${e}`,sr(e,!0),r({search:``,hash:e},{replace:!0})},J=e=>f?n({show:e}):n(e===`all`?{}:{show:e},{replace:!0}),he=e=>e.flatMap(e=>e.sections).map(e=>d.spaceSections.find(t=>t.id===e.id)).filter(e=>e!==void 0).map(e=>(0,$.jsx)(Y,{id:e.id,children:(0,$.jsx)(X,{title:e.label(),hint:e.hint?.(),plain:!0,children:(0,$.jsx)(vt,{of:e,children:(0,$.jsx)(e.component,{})})})},e.serial)),ge=f?void 0:ae,_e=(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Et,{title:te,open:k===1?E??null:null,onBack:()=>f?r(`/space`):y(C??null),root:{icon:it,label:B(`nav.project`),backLabel:B(`nav.wizards`),onBack:()=>r(`/`)}}),(0,$.jsx)(`div`,{className:A(Ct(j)),children:k===0?(0,$.jsx)(Ot,{entries:T,current:f?void 0:E,onPick:()=>y(null)}):(0,$.jsx)(`div`,{ref:m})},k)]});return(0,$.jsxs)(Dt.Provider,{value:ee,children:[P&&N?(0,$t.createPortal)(_e,N):null,(0,$.jsx)(`div`,{className:`animate-rise`,children:(0,$.jsxs)(`div`,{className:A(`grid gap-6`,!P&&`md:grid-cols-[13.5rem_minmax(0,1fr)] md:gap-8 lg:grid-cols-[15rem_minmax(0,1fr)] lg:gap-10`),children:[P?null:(0,$.jsx)(`aside`,{className:A(`min-w-0 md:sticky md:top-6 md:self-start`,f&&O===2&&`hidden`,f&&M===`back`&&Ct(`back`)),children:_e}),C?(0,$.jsxs)(`div`,{className:A(`min-w-0`,f&&O<2&&`hidden`,f&&M===`deeper`&&Ct(`deeper`)),children:[f?(0,$.jsx)(`div`,{className:`mb-3`,children:(0,$.jsx)(At,{label:E?.label??te,onBack:()=>r(`/space/${C}`)})}):null,u&&c?(0,$.jsx)(`div`,{className:`mb-6`,children:(0,$.jsx)(ar,{project:c})}):null,b===`results`?(0,$.jsxs)(kt,{children:[(0,$.jsxs)(`ul`,{className:`flex flex-col gap-0.5`,children:[(0,$.jsx)(St,{icon:Wt,label:B(`space.resultsAll`),selected:!f&&!R,onPick:()=>J(`all`)}),ce.data?.wizards.filter(e=>e.results||e.id===R).map(e=>(0,$.jsx)(St,{icon:ht,label:e.title,badge:e.results?(0,$.jsx)(`span`,{className:`text-[0.75rem] text-ink-3 tabular-nums`,children:e.results}):null,selected:!f&&e.id===R,onPick:()=>J(e.id)},e.id))]}),(0,$.jsx)(cr,{groups:L,current:ge,onPick:q})]}):b===`data`?(0,$.jsxs)(kt,{children:[(0,$.jsx)(`ul`,{className:`flex flex-col gap-0.5`,children:(0,$.jsx)(St,{icon:Kt,label:B(`data.all`),selected:!f&&!V,onPick:()=>J(`all`)})}),W.data?ze(W.data).map(e=>(0,$.jsx)(Tt,{label:e.label,children:e.items.map(e=>(0,$.jsx)(St,{icon:De[e.kind],label:e.title,selected:!f&&e.key===V,onPick:()=>J(e.key)},e.key))},e.key)):null,(0,$.jsx)(cr,{groups:L,current:ge,onPick:q})]}):b===`knowledge`?(0,$.jsxs)(kt,{children:[(0,$.jsx)(`ul`,{className:`flex flex-col gap-0.5`,children:(0,$.jsx)(St,{icon:Kt,label:B(`know.all`),selected:!(f||V),onPick:()=>J(`all`)})}),G.data?.categories.length?(0,$.jsx)(Tt,{label:B(`know.categories`),children:G.data.categories.map(e=>(0,$.jsx)(St,{icon:Me[e.type],label:e.name,badge:(0,$.jsx)(`span`,{className:`text-[0.75rem] text-ink-3 tabular-nums`,children:e.proposed?`·`:e.count}),selected:!f&&(V===`c:${e.id}`||K.data?.category.id===e.id),onPick:()=>J(`c:${e.id}`)},e.id))}):null,(0,$.jsx)(cr,{groups:L,current:f?void 0:H?.id,onPick:e=>J(`s:${e}`)})]}):(0,$.jsx)(kt,{children:(0,$.jsx)(cr,{groups:I,current:ge,onPick:q})}),c&&(b===`info`||b===`knowledge`)?(0,$.jsxs)($n,{project:c,group:b,children:[b===`knowledge`?U?U.startsWith(`p:`)?(0,$.jsx)(Pe,{pageId:U.slice(2),onGone:()=>J(`all`),onOpen:J},U):U.startsWith(`t:`)?(0,$.jsx)(Ne,{tableId:U.slice(2),onGone:()=>J(`all`)},U):(0,$.jsx)(pn,{projectId:c.id,fileId:U.slice(2),readOnly:c.readOnly,onGone:()=>J(`all`)},U):G.data?H?(0,$.jsx)(X,{title:H.label(),hint:H.hint?.(),plain:!0,children:(0,$.jsx)(vt,{of:H,children:(0,$.jsx)(H.component,{})})},V):V?.startsWith(`c:`)?ue?(0,$.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,$.jsx)(je,{projectId:c.id,category:ue,readOnly:c.readOnly,onOpen:J,onGone:()=>J(`all`)}),ue.type===`choice`?null:(0,$.jsx)(Be,{projectId:c.id,category:ue,categories:G.data.categories,onOpen:J})]},V):null:V?.startsWith(`v:`)?K.data?(0,$.jsx)(Ee,{value:K.data,readOnly:c.readOnly,children:(0,$.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[K.data.items.length?(0,$.jsx)(`div`,{className:`flex flex-col rounded-xl bg-card p-1.5 shadow-soft ring-1 ring-border-soft`,children:K.data.items.map(e=>(0,$.jsx)(ke,{item:e,categories:G.data.categories.filter(e=>e.id!==K.data?.category.id),onOpen:J},e.key))}):null,K.data.rows.map(e=>(0,$.jsx)(`button`,{type:`button`,onClick:()=>J(`t:${e.tableId}`),className:`px-1 text-left text-[0.8125rem] text-ink-3 hover:text-ink`,children:B(`know.tocRows`,{n:e.count,table:e.title})},e.tableId))]})},V):null:(0,$.jsx)(Y,{id:`documents`,children:(0,$.jsx)(Re,{projectId:c.id,data:G.data,readOnly:c.readOnly,onOpen:J})}):null:null,b===`info`?he(L):null]},c.id):null,c&&x?(0,$.jsx)(vt,{of:x,children:(0,$.jsx)(bt,{part:x.id,children:(0,$.jsx)(x.component,{})},c.id)}):null,c&&b===`data`?(0,$.jsx)(`div`,{className:`flex flex-col gap-9 pb-20`,children:V?.startsWith(`t:`)?(0,$.jsx)(Ne,{tableId:V.slice(2),onGone:()=>J(`all`)},V):V?.startsWith(`p:`)?(0,$.jsx)(Pe,{pageId:V.slice(2),onGone:()=>J(`all`)},V):(0,$.jsxs)($.Fragment,{children:[W.data?(0,$.jsx)(Le,{projectId:c.id,data:W.data,readOnly:c.readOnly,onOpen:J}):null,he(L)]})}):null,c&&b===`results`?(0,$.jsxs)(`div`,{className:`flex flex-col gap-9 pb-20`,children:[ce.data?(0,$.jsx)(rr,{data:ce.data,wizardId:R,filter:oe,onFilter:se}):null,ce.isError?(0,$.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:ce.error.message}):null,he(L)]}):null,c||l?null:(0,$.jsx)(o,{children:B(`settings.noProject`)})]}):null]})})]})}export{lr as ProjectPage};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{n as t,t as n}from"./jsx-runtime-BNakU3Ej.js";import{$ as r,Ar as i,At as a,Gr as o,Hr as s,It as c,J as l,Lr as u,Mn as d,Nr as f,Qt as p,Vr as m,Vt as h,W as g,an as _,at as ee,et as v,it as y,qn as b,qt as x,rn as S,sn as C}from"./ui-DMmT-cSO.js";import{a as w,i as T,n as E,o as D,r as O,s as k,t as te}from"./ChatView-KkOboyOo.js";import{Ct as A,Dt as ne,J as j,St as M,wt as N}from"./index-C61HAltK.js";import{t as re}from"./RunnerView-BW1h4x63.js";var P={name:`bookmark`,size:24,node:[[`path`,{d:`M17 3a2 2 0 0 1 2 2v15a1 1 0 0 1-1.496.868l-4.512-2.578a2 2 0 0 0-1.984 0l-4.512 2.578A1 1 0 0 1 5 20V5a2 2 0 0 1 2-2z`,key:`oz39mx`}]]};P.node;var ie=f(P),F={name:`smartphone`,size:24,node:[[`rect`,{width:`14`,height:`20`,x:`5`,y:`2`,rx:`2`,ry:`2`,key:`1yt0o3`}],[`path`,{d:`M12 18h.01`,key:`mhygvu`}]]};F.node;var ae=f(F),I={name:`square-plus`,size:24,node:[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M8 12h8`,key:`1wcyev`}],[`path`,{d:`M12 8v8`,key:`napkw2`}]],aliases:[`plus-square`]};I.node;var oe=f(I),L=e(t(),1);function se(){if(window.self===window.top)return null;let e=new URLSearchParams(window.location.search).get(`embed`);return e===`inline`||e===`modal`||e===`popout`?e:null}var R=se(),ce=R?new URLSearchParams(window.location.search).get(`page`):null,z=(e,t={})=>window.parent.postMessage({type:`engenty-wizard:${e}`,...t},`*`),le=()=>z(`close`);function ue(e){(0,L.useEffect)(()=>{if(R===`inline`&&!e){let e=document.documentElement;document.getElementById(`root`)?.style.setProperty(`min-height`,`0`),e.style.overflow=`hidden`;let t=new ResizeObserver(()=>z(`height`,{height:Math.ceil(e.getBoundingClientRect().height)}));return t.observe(e),()=>t.disconnect()}if(R===`modal`||R===`popout`){let e=e=>{e.key===`Escape`&&!document.querySelector(`dialog[open]`)&&z(`close`)};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)}},[e])}var B=e(n(),1),V=`wizards.runner.translate`,H=new Set;function de(){try{return localStorage.getItem(V)===`on`}catch{return!1}}function fe(e){try{localStorage.setItem(V,e?`on`:`off`)}catch{}for(let e of H)e()}function pe(){return(0,L.useSyncExternalStore)(e=>(H.add(e),()=>H.delete(e)),de)}function me(e){let t=pe(),[n]=(0,L.useState)(()=>C()),r=e?.lang??`en`,i=e?.translatable&&n&&n!==r?n:null,a=i&&t?i:r,s=e?.token,c=o({queryKey:[`public-translation`,s,a],enabled:!!(s&&a!==r),queryFn:()=>g.post(`/api/public/wizards/${s}/translation`,{lang:a}),staleTime:1/0,retry:!1}),l=o({queryKey:[`public-texts`,s,a],enabled:!(!s||d(a)),queryFn:()=>g.get(`/api/public/wizards/${s}/texts/${a}`),staleTime:1/0,retry:!1}),u=!d(a),f=a===r||c.data&&(!u||l.data),p=a!==r&&(c.isError||u&&l.isError),m=f&&!p?a:r,h=(0,L.useMemo)(()=>!d(m)&&l.data?.lang===m?{lang:l.data.lang,runner:l.data.runner,notes:l.data.notes}:null,[m,l.data]);if((0,L.useEffect)(()=>{e&&S(m,h)},[e,m,h]),(0,L.useEffect)(()=>()=>S(null),[]),!e)return null;let _=m!==r&&c.data?c.data:null;return{own:r,other:i,shown:m,wizard:_??e,translating:a!==r&&!f&&!p,failed:!!p,translated:!!_,machine:_?.translation?.machine??!1,pick:e=>fe(e!==r)}}function U({page:e,tone:t=`ground`}){if(!e?.other)return null;let n=e.translating?e.other:e.shown;return(0,B.jsx)(j,{langs:[e.own,e.other],value:n,onPick:e.pick,tone:t})}function W({page:e,small:t}){if(!e)return null;let n=t?`truncate text-[0.75rem]`:`text-[0.8125rem]`;return e.failed?(0,B.jsx)(`p`,{className:p(`text-ink-3`,n),children:_(`translation.failed`)}):e.translated?(0,B.jsxs)(`p`,{className:p(`text-ink-3`,n),children:[e.machine?(0,B.jsxs)(B.Fragment,{children:[_(`translation.machine`),` · `]}):null,(0,B.jsx)(`button`,{type:`button`,className:`underline-offset-4 hover:text-ink hover:underline coarse:min-h-11`,onClick:()=>e.pick(e.own),children:_(`translation.showOriginal`)})]}):null}var he=`ui-sans-serif, system-ui, sans-serif`,ge=`ui-serif, Georgia, serif`;function G(e){return`"${e.replace(/"/g,``)}", ${/serif/i.test(e)&&!/sans/i.test(e)?ge:he}`}function K(e){let t=JSON.stringify(e??{});(0,L.useEffect)(()=>{let e=JSON.parse(t),n=document.documentElement,r=[[`--raw-primary`,e.accent],[`--raw-second`,e.second],[`--raw-background`,e.background],[`--brand-stage`,e.background?e.dark?e.background:`oklch(from ${e.background} 0.3 clamp(0.02, calc(c * 3), 0.1) h)`:null],[`--f-display`,e.display?G(e.display):null],[`--f-ui`,e.body?G(e.body):null]].filter(e=>!!e[1]);for(let[e,t]of r)n.style.setProperty(e,t);let i=n.classList.contains(`dark`);return e.dark&&n.classList.add(`dark`),()=>{for(let[e]of r)n.style.removeProperty(e);e.dark&&!i&&n.classList.remove(`dark`)}},[t])}function _e(e,t){let n=(0,L.useRef)(null),r=t&&!t.translating?t.translated?t.shown:null:void 0;(0,L.useEffect)(()=>{if(!e||r===void 0)return;let t=`${e}:${r}`;n.current!==t&&(n.current=t,g.post(`/api/runs/${e}/lang`,{lang:r}).catch(()=>void 0))},[e,r])}function ve(e,t){(0,L.useEffect)(()=>{if(!e||!t)return;let n=r(`/api/public/wizards/${e}`),i=[{rel:`manifest`,href:`${n}/manifest.webmanifest`},{rel:`apple-touch-icon`,href:`${n}/icons/apple-touch-icon.png`},{rel:`icon`,href:`${n}/icons/favicon.png`,type:`image/png`}].flatMap(({rel:e,href:t,type:n})=>{let r=document.querySelector(`link[rel="${e}"]`);if(!r)return[];let i={href:r.getAttribute(`href`),type:r.getAttribute(`type`)};return r.setAttribute(`href`,t),n&&r.setAttribute(`type`,n),[{link:r,before:i}]}),a=document.createElement(`meta`);return a.name=`apple-mobile-web-app-title`,a.content=t,document.head.appendChild(a),()=>{for(let{link:e,before:t}of i)for(let[n,r]of Object.entries(t))r===null?e.removeAttribute(n):e.setAttribute(n,r);a.remove()}},[e,t])}var q=/iPhone|iPad|iPod/.test(navigator.userAgent)||navigator.platform===`MacIntel`&&navigator.maxTouchPoints>1,J=q||/Android/.test(navigator.userAgent);function ye(){let[e,t]=(0,L.useState)(()=>window.wizardInstall??null),[n,r]=(0,L.useState)(!1);if((0,L.useEffect)(()=>{let e=()=>t(window.wizardInstall??null);return window.addEventListener(`wizard-install`,e),()=>window.removeEventListener(`wizard-install`,e)},[]),window.matchMedia(`(display-mode: standalone)`).matches||navigator.standalone===!0||J&&!e&&!q)return null;let i=/Mac/.test(navigator.platform),a=_(J?`install.ios`:i?`install.bookmark.mac`:`install.bookmark.pc`);return(0,B.jsxs)(`div`,{className:`mt-6 flex flex-col items-center gap-2 text-[0.8125rem] text-ink-3`,children:[(0,B.jsxs)(`button`,{type:`button`,onClick:()=>{J&&e?(e.prompt(),window.wizardInstall=null,t(null)):r(e=>!e)},className:`inline-flex items-center gap-1.5 underline-offset-4 hover:text-ink hover:underline coarse:min-h-11`,children:[J?(0,B.jsx)(oe,{className:`size-4`}):(0,B.jsx)(ie,{className:`size-4`}),_(J?`install.add`:`install.bookmark`)]}),n?(0,B.jsx)(`p`,{className:`max-w-xs leading-relaxed`,children:a}):null]})}function Y({brand:e,toggle:t=!0,start:n}){return(0,B.jsx)(`header`,{className:`safe-top`,children:(0,B.jsxs)(`div`,{className:`relative flex h-14 items-center justify-center px-5`,children:[n?(0,B.jsx)(`div`,{className:`absolute left-3`,children:n}):null,e.logoUrl?(0,B.jsx)(`img`,{src:r(e.logoUrl),alt:e.name,className:`h-7 max-w-[160px] object-contain`}):e.name?(0,B.jsx)(`span`,{className:`max-w-[60%] truncate font-display font-semibold text-[0.9375rem] text-ink-2 tracking-tight`,children:e.name}):null,t?(0,B.jsx)(`div`,{className:`absolute right-3`,children:(0,B.jsx)(N,{})}):null]})})}function X({siteKey:e,onToken:t}){let n=(0,L.useRef)(null);return(0,L.useEffect)(()=>{let r=()=>{n.current&&window.turnstile&&!n.current.childElementCount&&window.turnstile.render(n.current,{sitekey:e,callback:t,appearance:`interaction-only`})};if(window.turnstile){r();return}let i=document.createElement(`script`);i.src=`https://challenges.cloudflare.com/turnstile/v0/api.js`,i.async=!0,i.onload=r,document.head.appendChild(i)},[e,t]),(0,B.jsx)(`div`,{ref:n,className:`mt-4 flex justify-center`})}function be({token:e}){return!/iPhone|iPad|iPod|Android/.test(navigator.userAgent)||v||R?null:(0,B.jsxs)(`a`,{href:y(`${window.location.origin}${l}/w/${e}`),className:`mt-3 inline-flex items-center gap-1.5 text-[0.8125rem] text-ink-3 underline-offset-4 hover:text-ink hover:underline coarse:min-h-11`,children:[(0,B.jsx)(ae,{className:`size-4`}),` `,_(`install.app`)]})}var Z=e=>`wz.run.${e}`,xe=v&&new URLSearchParams(window.location.search).get(`start`)===`1`,Q=R===`inline`?`min-h-80`:`min-h-dvh`;function $(e,t,n){let r=m(),[i,a]=(0,L.useState)(!1),[o,s]=(0,L.useState)(null),[c,l]=(0,L.useState)(null),u=(()=>{try{return localStorage.getItem(Z(e.token))}catch{return null}})();return{busy:i,error:o,captcha:c,setCaptcha:l,start:async()=>{a(!0),s(null);try{let{runId:i}=await g.post(`/api/public/wizards/${e.token}/runs`,{turnstileToken:c??void 0,embedded:R!==null,origin:ce??void 0,lang:n??void 0});try{localStorage.setItem(Z(e.token),i)}catch{}r(`${t}/${i}`,{replace:xe})}catch(e){s(e.message),a(!1)}},resume:u?()=>r(`${t}/${u}`):null}}function Se({wizard:e,page:t}){let{busy:n,error:r,captcha:a,setCaptcha:o,start:s,resume:l}=$(e,`/w/${e.token}`,t?.translated?t.shown:null),u=xe&&e.available&&!e.turnstileSiteKey,d=(0,L.useRef)(!1);return(0,L.useEffect)(()=>{u&&!d.current&&(d.current=!0,s())},[u]),u&&!r?(0,B.jsx)(`div`,{className:`flex min-h-[60dvh] items-center justify-center text-ink-4`,children:(0,B.jsx)(x,{})}):(0,B.jsxs)(`div`,{className:`mx-auto flex max-w-lg animate-rise flex-col items-center px-6 pt-6 pb-12 text-center sm:pt-16 sm:pb-16`,children:[(0,B.jsx)(A,{kind:e.avatar,size:190,fluffy:!0}),(0,B.jsx)(`h1`,{className:`mt-2 text-balance font-display font-semibold text-[1.875rem] leading-[1.1] tracking-tight sm:text-[2.125rem]`,children:e.title}),e.description?(0,B.jsx)(`p`,{className:`mt-3 text-[1rem] text-ink-2 leading-relaxed`,children:e.description}):null,(0,B.jsx)(`div`,{className:`mt-3`,children:(0,B.jsx)(W,{page:t})}),e.available?(0,B.jsxs)(B.Fragment,{children:[(0,B.jsxs)(c,{size:`lg`,className:`mt-10 min-w-48`,busy:n,disabled:!!e.turnstileSiteKey&&!a,onClick:s,children:[_(`run.start`),` `,(0,B.jsx)(i,{className:`size-4`})]}),e.turnstileSiteKey?(0,B.jsx)(X,{siteKey:e.turnstileSiteKey,onToken:o}):null,l?(0,B.jsx)(`button`,{type:`button`,onClick:l,className:`mt-4 text-[0.875rem] text-ink-3 underline-offset-4 hover:text-ink hover:underline coarse:min-h-11`,children:_(`run.resume`)}):null,(0,B.jsx)(Ce,{wizard:e,current:`steps`}),R||v?null:(0,B.jsx)(ye,{}),(0,B.jsx)(be,{token:e.token})]}):(0,B.jsx)(`p`,{className:`mt-10 rounded-xl bg-paper-2 px-5 py-4 text-[0.9375rem] text-ink-2`,children:e.unavailableReason??_(`run.unavailable`)}),r?(0,B.jsx)(`p`,{className:`mt-4 text-[0.875rem] text-rose`,children:r}):null]})}function Ce({wizard:e,current:t}){let n=e.runners.filter(e=>e.id!==t&&e.kind===`page`&&e.url);return n.length?(0,B.jsx)(`p`,{className:`mt-4 flex flex-wrap justify-center gap-x-4 text-[0.875rem] text-ink-3`,children:n.map(e=>(0,B.jsx)(`a`,{href:e.url??void 0,className:`underline-offset-4 hover:text-ink hover:underline coarse:min-h-11`,children:_(`run.orAs`,{label:e.label})},e.id))}):null}function we({wizard:e,page:t}){let n=k();return(0,B.jsx)(`header`,{className:`safe-top shrink-0 border-border-soft border-b`,children:(0,B.jsxs)(`div`,{className:`mx-auto flex h-16 w-full max-w-[760px] items-center gap-3 pr-2 pl-4 sm:pr-4 sm:pl-6`,children:[(0,B.jsx)(`span`,{className:p(n?.speaking&&`animate-breathe`),children:(0,B.jsx)(A,{kind:e.avatar,size:38})}),(0,B.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,B.jsx)(`div`,{className:`truncate font-display font-semibold text-[1rem] leading-tight tracking-tight`,children:e.title}),e.brand.name?(0,B.jsx)(`div`,{className:`truncate text-[0.75rem] text-ink-3`,children:e.brand.name}):null,(0,B.jsx)(W,{page:t,small:!0})]}),e.brand.logoUrl&&R!==`popout`?(0,B.jsx)(`img`,{src:r(e.brand.logoUrl),alt:e.brand.name,className:`h-6 max-w-[120px] object-contain max-sm:hidden`}):null,(0,B.jsx)(U,{page:t,tone:`surface`}),R?null:(0,B.jsx)(N,{}),R===`popout`?(0,B.jsx)(h,{label:_(`common.close`),onClick:le,children:(0,B.jsx)(b,{className:`size-5`})}):null]})})}function Te({door:e,wizard:t,page:n,header:r,footer:a}){let{busy:o,error:s,captcha:c,setCaptcha:l,start:u,resume:d}=$(t,`/w/${t.token}/${e}`,n?.translated?n.shown:null),f=[{key:`hello`,who:`bot`,node:t.description||t.title}];return e!==`chat`&&f.push({key:e,who:`bot`,node:_(e===`video`?`video.hint`:`talk.joinHint`)}),t.available||f.push({key:`unavailable`,who:`bot`,node:t.unavailableReason??_(`run.unavailable`)}),s&&f.push({key:`error`,who:`bot`,node:s,tone:`error`}),t.available&&f.push(D(`start`,(0,B.jsxs)(B.Fragment,{children:[(0,B.jsxs)(T,{primary:!0,busy:o,disabled:!!t.turnstileSiteKey&&!c,onClick:()=>void u(),children:[_(`run.start`),` `,(0,B.jsx)(i,{className:`size-4`})]}),d?(0,B.jsx)(T,{onClick:d,children:_(`run.resume`)}):null,t.turnstileSiteKey?(0,B.jsx)(X,{siteKey:t.turnstileSiteKey,onToken:l}):null]}))),(0,B.jsxs)(E,{header:r,footer:a,children:[(0,B.jsx)(w,{avatar:t.avatar,lines:f}),(0,B.jsx)(O,{})]})}function Ee({className:e}){return(0,B.jsx)(`footer`,{className:p(`text-center text-ink-4`,e),children:(0,B.jsx)(`a`,{href:`${l}/`,target:R?`_blank`:void 0,rel:`noreferrer`,className:`inline-block hover:text-ink-2`,children:_(`run.madeWith`).replace(`engenty wizards`,M.name)})})}function De({chat:e=!1,steps:t=!1,talk:n=!1,video:r=!1}){let{token:i,runId:d}=s(),f=m(),h=o({queryKey:[`public`,i],queryFn:()=>g.get(`/api/public/wizards/${i}`),retry:(e,t)=>a(t)&&e<3}),y=h.data?.runners??[],b=!h.data||y.some(e=>e.id===`talk`),S=!h.data||y.some(e=>e.id===`video`),C=!h.data||y.some(e=>e.id===`chat`)||n&&b||r&&S,w=y[0]?.id,T=e||R===`popout`||!t&&!d&&C&&(w===`chat`||w===`talk`||w===`video`),E=r&&S||!t&&!e&&!n&&w===`video`,D=!E&&(n&&b||!t&&!e&&w===`talk`),O=E?`video`:D?`talk`:`chat`,k=me(h.data);_e(d,k),K(h.data?.brand.theme),ne(h.data?.avatar),ve(i,h.data?.title),ue(T);let j=k?.wizard.title??h.data?.title;if((0,L.useEffect)(()=>{j&&(document.title=j)},[j]),(0,L.useEffect)(()=>{i&&d&&ee(`run`,{token:i,runId:d})},[i,d]),h.isLoading)return(0,B.jsx)(`div`,{className:p(`flex items-center justify-center text-ink-4`,Q),children:(0,B.jsx)(x,{})});if(e&&h.data&&!C||n&&h.data&&!b||r&&h.data&&!S)return(0,B.jsx)(u,{to:`/w/${i}`,replace:!0});if(!h.data){let e=a(h.error);return(0,B.jsxs)(`div`,{className:p(`flex flex-col items-center justify-center gap-4 px-6 text-center`,Q),children:[(0,B.jsx)(A,{kind:`pebble`,size:80}),(0,B.jsx)(`p`,{className:`max-w-xs text-ink-3`,children:_(e?`common.offline`:`run.notFound`)}),e?(0,B.jsx)(c,{variant:`secondary`,onClick:()=>void h.refetch(),children:_(`common.retry`)}):null]})}let N=k?.wizard??h.data,P=k?.translating?(0,B.jsxs)(`div`,{className:p(`flex flex-col items-center justify-center gap-3 text-ink-3`,Q),children:[(0,B.jsx)(x,{}),(0,B.jsx)(`p`,{className:`text-[0.875rem]`,children:_(`translation.working`)})]}):null;if(T){let e=(0,B.jsx)(we,{wizard:N,page:k}),t=v?(0,B.jsx)(`div`,{className:`safe-bottom`}):(0,B.jsx)(Ee,{className:`pb-[max(0.375rem,env(safe-area-inset-bottom))] text-[0.6875rem]`});return(0,B.jsx)(`div`,{className:`flex h-dvh flex-col`,children:P??(d?(0,B.jsx)(te,{runId:d,talk:D,call:E?`video`:D?`audio`:!1,onRestart:()=>f(`/w/${i}/${O}`),header:E||D?void 0:e,footer:t}):(0,B.jsx)(Te,{wizard:N,page:k,header:e,footer:t,door:O}))})}return(0,B.jsxs)(`div`,{className:p(`flex flex-col`,Q),children:[R===`inline`||v?null:(0,B.jsx)(Y,{brand:h.data.brand,toggle:!R,start:(0,B.jsx)(U,{page:k})}),R===`inline`||v?(0,B.jsx)(`div`,{className:`flex justify-end px-3 pt-2`,children:(0,B.jsx)(U,{page:k,tone:`surface`})}):null,d&&(k?.translated||k?.failed)?(0,B.jsx)(`div`,{className:`flex justify-center px-5`,children:(0,B.jsx)(W,{page:k})}):null,(0,B.jsx)(`div`,{className:`flex-1`,children:P??(d?(0,B.jsx)(re,{runId:d,onRestart:()=>f(`/w/${i}`)}):(0,B.jsx)(Se,{wizard:N,page:k}))}),v?(0,B.jsx)(`div`,{className:`safe-bottom`}):(0,B.jsx)(`footer`,{className:`safe-bottom pt-6 text-center text-[0.75rem] text-ink-4`,children:(0,B.jsx)(`a`,{href:`${l}/`,target:R?`_blank`:void 0,rel:`noreferrer`,className:`inline-block py-3.5 hover:text-ink-2`,children:_(`run.madeWith`).replace(`engenty wizards`,M.name)})})]})}export{Y as BrandHeader,De as PublicRunner,K as t};
|
|
1
|
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{n as t,t as n}from"./jsx-runtime-BNakU3Ej.js";import{$ as r,Ar as i,At as a,Gr as o,Hr as s,It as c,J as l,Lr as u,Mn as d,Nr as f,Qt as p,Vr as m,Vt as h,W as g,an as _,at as ee,et as v,it as y,qn as b,qt as x,rn as S,sn as C}from"./ui-DMmT-cSO.js";import{a as w,i as T,n as E,o as D,r as O,s as k,t as te}from"./ChatView-DVeERQdi.js";import{Ct as A,Dt as ne,J as j,St as M,wt as N}from"./index-4jH2mkp7.js";import{t as re}from"./RunnerView-BW1h4x63.js";var P={name:`bookmark`,size:24,node:[[`path`,{d:`M17 3a2 2 0 0 1 2 2v15a1 1 0 0 1-1.496.868l-4.512-2.578a2 2 0 0 0-1.984 0l-4.512 2.578A1 1 0 0 1 5 20V5a2 2 0 0 1 2-2z`,key:`oz39mx`}]]};P.node;var ie=f(P),F={name:`smartphone`,size:24,node:[[`rect`,{width:`14`,height:`20`,x:`5`,y:`2`,rx:`2`,ry:`2`,key:`1yt0o3`}],[`path`,{d:`M12 18h.01`,key:`mhygvu`}]]};F.node;var ae=f(F),I={name:`square-plus`,size:24,node:[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M8 12h8`,key:`1wcyev`}],[`path`,{d:`M12 8v8`,key:`napkw2`}]],aliases:[`plus-square`]};I.node;var oe=f(I),L=e(t(),1);function se(){if(window.self===window.top)return null;let e=new URLSearchParams(window.location.search).get(`embed`);return e===`inline`||e===`modal`||e===`popout`?e:null}var R=se(),ce=R?new URLSearchParams(window.location.search).get(`page`):null,z=(e,t={})=>window.parent.postMessage({type:`engenty-wizard:${e}`,...t},`*`),le=()=>z(`close`);function ue(e){(0,L.useEffect)(()=>{if(R===`inline`&&!e){let e=document.documentElement;document.getElementById(`root`)?.style.setProperty(`min-height`,`0`),e.style.overflow=`hidden`;let t=new ResizeObserver(()=>z(`height`,{height:Math.ceil(e.getBoundingClientRect().height)}));return t.observe(e),()=>t.disconnect()}if(R===`modal`||R===`popout`){let e=e=>{e.key===`Escape`&&!document.querySelector(`dialog[open]`)&&z(`close`)};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)}},[e])}var B=e(n(),1),V=`wizards.runner.translate`,H=new Set;function de(){try{return localStorage.getItem(V)===`on`}catch{return!1}}function fe(e){try{localStorage.setItem(V,e?`on`:`off`)}catch{}for(let e of H)e()}function pe(){return(0,L.useSyncExternalStore)(e=>(H.add(e),()=>H.delete(e)),de)}function me(e){let t=pe(),[n]=(0,L.useState)(()=>C()),r=e?.lang??`en`,i=e?.translatable&&n&&n!==r?n:null,a=i&&t?i:r,s=e?.token,c=o({queryKey:[`public-translation`,s,a],enabled:!!(s&&a!==r),queryFn:()=>g.post(`/api/public/wizards/${s}/translation`,{lang:a}),staleTime:1/0,retry:!1}),l=o({queryKey:[`public-texts`,s,a],enabled:!(!s||d(a)),queryFn:()=>g.get(`/api/public/wizards/${s}/texts/${a}`),staleTime:1/0,retry:!1}),u=!d(a),f=a===r||c.data&&(!u||l.data),p=a!==r&&(c.isError||u&&l.isError),m=f&&!p?a:r,h=(0,L.useMemo)(()=>!d(m)&&l.data?.lang===m?{lang:l.data.lang,runner:l.data.runner,notes:l.data.notes}:null,[m,l.data]);if((0,L.useEffect)(()=>{e&&S(m,h)},[e,m,h]),(0,L.useEffect)(()=>()=>S(null),[]),!e)return null;let _=m!==r&&c.data?c.data:null;return{own:r,other:i,shown:m,wizard:_??e,translating:a!==r&&!f&&!p,failed:!!p,translated:!!_,machine:_?.translation?.machine??!1,pick:e=>fe(e!==r)}}function U({page:e,tone:t=`ground`}){if(!e?.other)return null;let n=e.translating?e.other:e.shown;return(0,B.jsx)(j,{langs:[e.own,e.other],value:n,onPick:e.pick,tone:t})}function W({page:e,small:t}){if(!e)return null;let n=t?`truncate text-[0.75rem]`:`text-[0.8125rem]`;return e.failed?(0,B.jsx)(`p`,{className:p(`text-ink-3`,n),children:_(`translation.failed`)}):e.translated?(0,B.jsxs)(`p`,{className:p(`text-ink-3`,n),children:[e.machine?(0,B.jsxs)(B.Fragment,{children:[_(`translation.machine`),` · `]}):null,(0,B.jsx)(`button`,{type:`button`,className:`underline-offset-4 hover:text-ink hover:underline coarse:min-h-11`,onClick:()=>e.pick(e.own),children:_(`translation.showOriginal`)})]}):null}var he=`ui-sans-serif, system-ui, sans-serif`,ge=`ui-serif, Georgia, serif`;function G(e){return`"${e.replace(/"/g,``)}", ${/serif/i.test(e)&&!/sans/i.test(e)?ge:he}`}function K(e){let t=JSON.stringify(e??{});(0,L.useEffect)(()=>{let e=JSON.parse(t),n=document.documentElement,r=[[`--raw-primary`,e.accent],[`--raw-second`,e.second],[`--raw-background`,e.background],[`--brand-stage`,e.background?e.dark?e.background:`oklch(from ${e.background} 0.3 clamp(0.02, calc(c * 3), 0.1) h)`:null],[`--f-display`,e.display?G(e.display):null],[`--f-ui`,e.body?G(e.body):null]].filter(e=>!!e[1]);for(let[e,t]of r)n.style.setProperty(e,t);let i=n.classList.contains(`dark`);return e.dark&&n.classList.add(`dark`),()=>{for(let[e]of r)n.style.removeProperty(e);e.dark&&!i&&n.classList.remove(`dark`)}},[t])}function _e(e,t){let n=(0,L.useRef)(null),r=t&&!t.translating?t.translated?t.shown:null:void 0;(0,L.useEffect)(()=>{if(!e||r===void 0)return;let t=`${e}:${r}`;n.current!==t&&(n.current=t,g.post(`/api/runs/${e}/lang`,{lang:r}).catch(()=>void 0))},[e,r])}function ve(e,t){(0,L.useEffect)(()=>{if(!e||!t)return;let n=r(`/api/public/wizards/${e}`),i=[{rel:`manifest`,href:`${n}/manifest.webmanifest`},{rel:`apple-touch-icon`,href:`${n}/icons/apple-touch-icon.png`},{rel:`icon`,href:`${n}/icons/favicon.png`,type:`image/png`}].flatMap(({rel:e,href:t,type:n})=>{let r=document.querySelector(`link[rel="${e}"]`);if(!r)return[];let i={href:r.getAttribute(`href`),type:r.getAttribute(`type`)};return r.setAttribute(`href`,t),n&&r.setAttribute(`type`,n),[{link:r,before:i}]}),a=document.createElement(`meta`);return a.name=`apple-mobile-web-app-title`,a.content=t,document.head.appendChild(a),()=>{for(let{link:e,before:t}of i)for(let[n,r]of Object.entries(t))r===null?e.removeAttribute(n):e.setAttribute(n,r);a.remove()}},[e,t])}var q=/iPhone|iPad|iPod/.test(navigator.userAgent)||navigator.platform===`MacIntel`&&navigator.maxTouchPoints>1,J=q||/Android/.test(navigator.userAgent);function ye(){let[e,t]=(0,L.useState)(()=>window.wizardInstall??null),[n,r]=(0,L.useState)(!1);if((0,L.useEffect)(()=>{let e=()=>t(window.wizardInstall??null);return window.addEventListener(`wizard-install`,e),()=>window.removeEventListener(`wizard-install`,e)},[]),window.matchMedia(`(display-mode: standalone)`).matches||navigator.standalone===!0||J&&!e&&!q)return null;let i=/Mac/.test(navigator.platform),a=_(J?`install.ios`:i?`install.bookmark.mac`:`install.bookmark.pc`);return(0,B.jsxs)(`div`,{className:`mt-6 flex flex-col items-center gap-2 text-[0.8125rem] text-ink-3`,children:[(0,B.jsxs)(`button`,{type:`button`,onClick:()=>{J&&e?(e.prompt(),window.wizardInstall=null,t(null)):r(e=>!e)},className:`inline-flex items-center gap-1.5 underline-offset-4 hover:text-ink hover:underline coarse:min-h-11`,children:[J?(0,B.jsx)(oe,{className:`size-4`}):(0,B.jsx)(ie,{className:`size-4`}),_(J?`install.add`:`install.bookmark`)]}),n?(0,B.jsx)(`p`,{className:`max-w-xs leading-relaxed`,children:a}):null]})}function Y({brand:e,toggle:t=!0,start:n}){return(0,B.jsx)(`header`,{className:`safe-top`,children:(0,B.jsxs)(`div`,{className:`relative flex h-14 items-center justify-center px-5`,children:[n?(0,B.jsx)(`div`,{className:`absolute left-3`,children:n}):null,e.logoUrl?(0,B.jsx)(`img`,{src:r(e.logoUrl),alt:e.name,className:`h-7 max-w-[160px] object-contain`}):e.name?(0,B.jsx)(`span`,{className:`max-w-[60%] truncate font-display font-semibold text-[0.9375rem] text-ink-2 tracking-tight`,children:e.name}):null,t?(0,B.jsx)(`div`,{className:`absolute right-3`,children:(0,B.jsx)(N,{})}):null]})})}function X({siteKey:e,onToken:t}){let n=(0,L.useRef)(null);return(0,L.useEffect)(()=>{let r=()=>{n.current&&window.turnstile&&!n.current.childElementCount&&window.turnstile.render(n.current,{sitekey:e,callback:t,appearance:`interaction-only`})};if(window.turnstile){r();return}let i=document.createElement(`script`);i.src=`https://challenges.cloudflare.com/turnstile/v0/api.js`,i.async=!0,i.onload=r,document.head.appendChild(i)},[e,t]),(0,B.jsx)(`div`,{ref:n,className:`mt-4 flex justify-center`})}function be({token:e}){return!/iPhone|iPad|iPod|Android/.test(navigator.userAgent)||v||R?null:(0,B.jsxs)(`a`,{href:y(`${window.location.origin}${l}/w/${e}`),className:`mt-3 inline-flex items-center gap-1.5 text-[0.8125rem] text-ink-3 underline-offset-4 hover:text-ink hover:underline coarse:min-h-11`,children:[(0,B.jsx)(ae,{className:`size-4`}),` `,_(`install.app`)]})}var Z=e=>`wz.run.${e}`,xe=v&&new URLSearchParams(window.location.search).get(`start`)===`1`,Q=R===`inline`?`min-h-80`:`min-h-dvh`;function $(e,t,n){let r=m(),[i,a]=(0,L.useState)(!1),[o,s]=(0,L.useState)(null),[c,l]=(0,L.useState)(null),u=(()=>{try{return localStorage.getItem(Z(e.token))}catch{return null}})();return{busy:i,error:o,captcha:c,setCaptcha:l,start:async()=>{a(!0),s(null);try{let{runId:i}=await g.post(`/api/public/wizards/${e.token}/runs`,{turnstileToken:c??void 0,embedded:R!==null,origin:ce??void 0,lang:n??void 0});try{localStorage.setItem(Z(e.token),i)}catch{}r(`${t}/${i}`,{replace:xe})}catch(e){s(e.message),a(!1)}},resume:u?()=>r(`${t}/${u}`):null}}function Se({wizard:e,page:t}){let{busy:n,error:r,captcha:a,setCaptcha:o,start:s,resume:l}=$(e,`/w/${e.token}`,t?.translated?t.shown:null),u=xe&&e.available&&!e.turnstileSiteKey,d=(0,L.useRef)(!1);return(0,L.useEffect)(()=>{u&&!d.current&&(d.current=!0,s())},[u]),u&&!r?(0,B.jsx)(`div`,{className:`flex min-h-[60dvh] items-center justify-center text-ink-4`,children:(0,B.jsx)(x,{})}):(0,B.jsxs)(`div`,{className:`mx-auto flex max-w-lg animate-rise flex-col items-center px-6 pt-6 pb-12 text-center sm:pt-16 sm:pb-16`,children:[(0,B.jsx)(A,{kind:e.avatar,size:190,fluffy:!0}),(0,B.jsx)(`h1`,{className:`mt-2 text-balance font-display font-semibold text-[1.875rem] leading-[1.1] tracking-tight sm:text-[2.125rem]`,children:e.title}),e.description?(0,B.jsx)(`p`,{className:`mt-3 text-[1rem] text-ink-2 leading-relaxed`,children:e.description}):null,(0,B.jsx)(`div`,{className:`mt-3`,children:(0,B.jsx)(W,{page:t})}),e.available?(0,B.jsxs)(B.Fragment,{children:[(0,B.jsxs)(c,{size:`lg`,className:`mt-10 min-w-48`,busy:n,disabled:!!e.turnstileSiteKey&&!a,onClick:s,children:[_(`run.start`),` `,(0,B.jsx)(i,{className:`size-4`})]}),e.turnstileSiteKey?(0,B.jsx)(X,{siteKey:e.turnstileSiteKey,onToken:o}):null,l?(0,B.jsx)(`button`,{type:`button`,onClick:l,className:`mt-4 text-[0.875rem] text-ink-3 underline-offset-4 hover:text-ink hover:underline coarse:min-h-11`,children:_(`run.resume`)}):null,(0,B.jsx)(Ce,{wizard:e,current:`steps`}),R||v?null:(0,B.jsx)(ye,{}),(0,B.jsx)(be,{token:e.token})]}):(0,B.jsx)(`p`,{className:`mt-10 rounded-xl bg-paper-2 px-5 py-4 text-[0.9375rem] text-ink-2`,children:e.unavailableReason??_(`run.unavailable`)}),r?(0,B.jsx)(`p`,{className:`mt-4 text-[0.875rem] text-rose`,children:r}):null]})}function Ce({wizard:e,current:t}){let n=e.runners.filter(e=>e.id!==t&&e.kind===`page`&&e.url);return n.length?(0,B.jsx)(`p`,{className:`mt-4 flex flex-wrap justify-center gap-x-4 text-[0.875rem] text-ink-3`,children:n.map(e=>(0,B.jsx)(`a`,{href:e.url??void 0,className:`underline-offset-4 hover:text-ink hover:underline coarse:min-h-11`,children:_(`run.orAs`,{label:e.label})},e.id))}):null}function we({wizard:e,page:t}){let n=k();return(0,B.jsx)(`header`,{className:`safe-top shrink-0 border-border-soft border-b`,children:(0,B.jsxs)(`div`,{className:`mx-auto flex h-16 w-full max-w-[760px] items-center gap-3 pr-2 pl-4 sm:pr-4 sm:pl-6`,children:[(0,B.jsx)(`span`,{className:p(n?.speaking&&`animate-breathe`),children:(0,B.jsx)(A,{kind:e.avatar,size:38})}),(0,B.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,B.jsx)(`div`,{className:`truncate font-display font-semibold text-[1rem] leading-tight tracking-tight`,children:e.title}),e.brand.name?(0,B.jsx)(`div`,{className:`truncate text-[0.75rem] text-ink-3`,children:e.brand.name}):null,(0,B.jsx)(W,{page:t,small:!0})]}),e.brand.logoUrl&&R!==`popout`?(0,B.jsx)(`img`,{src:r(e.brand.logoUrl),alt:e.brand.name,className:`h-6 max-w-[120px] object-contain max-sm:hidden`}):null,(0,B.jsx)(U,{page:t,tone:`surface`}),R?null:(0,B.jsx)(N,{}),R===`popout`?(0,B.jsx)(h,{label:_(`common.close`),onClick:le,children:(0,B.jsx)(b,{className:`size-5`})}):null]})})}function Te({door:e,wizard:t,page:n,header:r,footer:a}){let{busy:o,error:s,captcha:c,setCaptcha:l,start:u,resume:d}=$(t,`/w/${t.token}/${e}`,n?.translated?n.shown:null),f=[{key:`hello`,who:`bot`,node:t.description||t.title}];return e!==`chat`&&f.push({key:e,who:`bot`,node:_(e===`video`?`video.hint`:`talk.joinHint`)}),t.available||f.push({key:`unavailable`,who:`bot`,node:t.unavailableReason??_(`run.unavailable`)}),s&&f.push({key:`error`,who:`bot`,node:s,tone:`error`}),t.available&&f.push(D(`start`,(0,B.jsxs)(B.Fragment,{children:[(0,B.jsxs)(T,{primary:!0,busy:o,disabled:!!t.turnstileSiteKey&&!c,onClick:()=>void u(),children:[_(`run.start`),` `,(0,B.jsx)(i,{className:`size-4`})]}),d?(0,B.jsx)(T,{onClick:d,children:_(`run.resume`)}):null,t.turnstileSiteKey?(0,B.jsx)(X,{siteKey:t.turnstileSiteKey,onToken:l}):null]}))),(0,B.jsxs)(E,{header:r,footer:a,children:[(0,B.jsx)(w,{avatar:t.avatar,lines:f}),(0,B.jsx)(O,{})]})}function Ee({className:e}){return(0,B.jsx)(`footer`,{className:p(`text-center text-ink-4`,e),children:(0,B.jsx)(`a`,{href:`${l}/`,target:R?`_blank`:void 0,rel:`noreferrer`,className:`inline-block hover:text-ink-2`,children:_(`run.madeWith`).replace(`engenty wizards`,M.name)})})}function De({chat:e=!1,steps:t=!1,talk:n=!1,video:r=!1}){let{token:i,runId:d}=s(),f=m(),h=o({queryKey:[`public`,i],queryFn:()=>g.get(`/api/public/wizards/${i}`),retry:(e,t)=>a(t)&&e<3}),y=h.data?.runners??[],b=!h.data||y.some(e=>e.id===`talk`),S=!h.data||y.some(e=>e.id===`video`),C=!h.data||y.some(e=>e.id===`chat`)||n&&b||r&&S,w=y[0]?.id,T=e||R===`popout`||!t&&!d&&C&&(w===`chat`||w===`talk`||w===`video`),E=r&&S||!t&&!e&&!n&&w===`video`,D=!E&&(n&&b||!t&&!e&&w===`talk`),O=E?`video`:D?`talk`:`chat`,k=me(h.data);_e(d,k),K(h.data?.brand.theme),ne(h.data?.avatar),ve(i,h.data?.title),ue(T);let j=k?.wizard.title??h.data?.title;if((0,L.useEffect)(()=>{j&&(document.title=j)},[j]),(0,L.useEffect)(()=>{i&&d&&ee(`run`,{token:i,runId:d})},[i,d]),h.isLoading)return(0,B.jsx)(`div`,{className:p(`flex items-center justify-center text-ink-4`,Q),children:(0,B.jsx)(x,{})});if(e&&h.data&&!C||n&&h.data&&!b||r&&h.data&&!S)return(0,B.jsx)(u,{to:`/w/${i}`,replace:!0});if(!h.data){let e=a(h.error);return(0,B.jsxs)(`div`,{className:p(`flex flex-col items-center justify-center gap-4 px-6 text-center`,Q),children:[(0,B.jsx)(A,{kind:`pebble`,size:80}),(0,B.jsx)(`p`,{className:`max-w-xs text-ink-3`,children:_(e?`common.offline`:`run.notFound`)}),e?(0,B.jsx)(c,{variant:`secondary`,onClick:()=>void h.refetch(),children:_(`common.retry`)}):null]})}let N=k?.wizard??h.data,P=k?.translating?(0,B.jsxs)(`div`,{className:p(`flex flex-col items-center justify-center gap-3 text-ink-3`,Q),children:[(0,B.jsx)(x,{}),(0,B.jsx)(`p`,{className:`text-[0.875rem]`,children:_(`translation.working`)})]}):null;if(T){let e=(0,B.jsx)(we,{wizard:N,page:k}),t=v?(0,B.jsx)(`div`,{className:`safe-bottom`}):(0,B.jsx)(Ee,{className:`pb-[max(0.375rem,env(safe-area-inset-bottom))] text-[0.6875rem]`});return(0,B.jsx)(`div`,{className:`flex h-dvh flex-col`,children:P??(d?(0,B.jsx)(te,{runId:d,talk:D,call:E?`video`:D?`audio`:!1,onRestart:()=>f(`/w/${i}/${O}`),header:E||D?void 0:e,footer:t}):(0,B.jsx)(Te,{wizard:N,page:k,header:e,footer:t,door:O}))})}return(0,B.jsxs)(`div`,{className:p(`flex flex-col`,Q),children:[R===`inline`||v?null:(0,B.jsx)(Y,{brand:h.data.brand,toggle:!R,start:(0,B.jsx)(U,{page:k})}),R===`inline`||v?(0,B.jsx)(`div`,{className:`flex justify-end px-3 pt-2`,children:(0,B.jsx)(U,{page:k,tone:`surface`})}):null,d&&(k?.translated||k?.failed)?(0,B.jsx)(`div`,{className:`flex justify-center px-5`,children:(0,B.jsx)(W,{page:k})}):null,(0,B.jsx)(`div`,{className:`flex-1`,children:P??(d?(0,B.jsx)(re,{runId:d,onRestart:()=>f(`/w/${i}`)}):(0,B.jsx)(Se,{wizard:N,page:k}))}),v?(0,B.jsx)(`div`,{className:`safe-bottom`}):(0,B.jsx)(`footer`,{className:`safe-bottom pt-6 text-center text-[0.75rem] text-ink-4`,children:(0,B.jsx)(`a`,{href:`${l}/`,target:R?`_blank`:void 0,rel:`noreferrer`,className:`inline-block py-3.5 hover:text-ink-2`,children:_(`run.madeWith`).replace(`engenty wizards`,M.name)})})]})}export{Y as BrandHeader,De as PublicRunner,K as t};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{t}from"./jsx-runtime-BNakU3Ej.js";import{Nr as n,an as r}from"./ui-DMmT-cSO.js";import{Jt as i}from"./index-
|
|
1
|
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{t}from"./jsx-runtime-BNakU3Ej.js";import{Nr as n,an as r}from"./ui-DMmT-cSO.js";import{Jt as i}from"./index-4jH2mkp7.js";var a={name:`text-align-start`,size:24,node:[[`path`,{d:`M21 5H3`,key:`1fi0y6`}],[`path`,{d:`M15 12H3`,key:`6jk70r`}],[`path`,{d:`M17 19H3`,key:`z6ezky`}]],aliases:[`text`,`align-left`]};a.node;var o=n(a),s=e(t(),1);function c(e){return r(e.origin===`local`?`readonly.project`:`readonly.server`)}function l({children:e}){return(0,s.jsxs)(`div`,{className:`flex items-start gap-3 rounded-xl bg-amber-tint px-4 py-3 font-medium text-[0.875rem] text-ink leading-relaxed`,children:[(0,s.jsx)(i,{className:`mt-0.5 size-4 shrink-0 text-amber`}),(0,s.jsx)(`p`,{className:`min-w-0`,children:e})]})}export{c as n,o as r,l as t};
|