libre-webui 0.13.0 → 0.13.1
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/backend/package.json +1 -1
- package/frontend/dist/assets/{index-pmlsmnQ4.js → index-6X4Fay3z.js} +3 -3
- package/frontend/dist/index.html +2 -2
- package/frontend/dist/js/{ArtifactContainer-DYmgznWk.js → ArtifactContainer-lBT2Cf0m.js} +1 -1
- package/frontend/dist/js/{ArtifactDemoPage-D9cUJCUT.js → ArtifactDemoPage-622qBoTt.js} +1 -1
- package/frontend/dist/js/{ArtifactSlideOutPanel-DlS_laML.js → ArtifactSlideOutPanel-CfbbHcaI.js} +1 -1
- package/frontend/dist/js/{ChatPage-CQ0V4ote.js → ChatPage-DGqHo1eh.js} +1 -1
- package/frontend/dist/js/{FirstTimeSetup-BO1IPnfI.js → FirstTimeSetup-BDCojgfX.js} +1 -1
- package/frontend/dist/js/{GalleryPage-B2hhzIun.js → GalleryPage-DWjvQFPR.js} +1 -1
- package/frontend/dist/js/{LibreClawPage-Bs8vK_yo.js → LibreClawPage-BQ5dN-0J.js} +1 -1
- package/frontend/dist/js/{ModelManagerModals-CSGR9o2J.js → ModelManagerModals-BECfRnGl.js} +1 -1
- package/frontend/dist/js/{ModelsPage-CpVM6Qhl.js → ModelsPage-Ccmog6B5.js} +2 -2
- package/frontend/dist/js/{PersonasPage-CwqOhNVH.js → PersonasPage-DvTDH2Fy.js} +1 -1
- package/frontend/dist/js/{RichMessageContent-DH5WM9fX.js → RichMessageContent-CBR2ML5W.js} +1 -1
- package/frontend/dist/js/{SettingsModal-DzkKC4ks.js → SettingsModal-CV9iz6Lk.js} +1 -1
- package/frontend/dist/js/{UserManagementPage-C0bC1w1D.js → UserManagementPage-k1mBGCDH.js} +1 -1
- package/frontend/dist/js/{api-D9FuobIF.js → api-Ddawdcbi.js} +2 -2
- package/frontend/dist/js/{useBaseQuery-D0MMQYNQ.js → useBaseQuery-5VtX6QMw.js} +1 -1
- package/frontend/dist/js/useQuery-CXwvr2_e.js +1 -0
- package/package.json +5 -4
- package/scripts/postinstall.js +54 -0
- package/frontend/dist/js/useQuery-B2OUd39C.js +0 -1
package/frontend/dist/index.html
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
name="description"
|
|
11
11
|
content="A modern, minimalist WebUI for interacting with local LLMs through Ollama API"
|
|
12
12
|
/>
|
|
13
|
-
<script type="module" crossorigin src="/assets/index-
|
|
13
|
+
<script type="module" crossorigin src="/assets/index-6X4Fay3z.js"></script>
|
|
14
14
|
<link rel="modulepreload" crossorigin href="/js/rolldown-runtime-QTnfLwEv.js">
|
|
15
15
|
<link rel="modulepreload" crossorigin href="/js/markdown-core-fkbHPd-g.js">
|
|
16
16
|
<link rel="modulepreload" crossorigin href="/js/react-vendor-Co1u1rWb.js">
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
<link rel="modulepreload" crossorigin href="/js/logger-BmpKNkls.js">
|
|
19
19
|
<link rel="modulepreload" crossorigin href="/js/ui-vendor-njo77ljx.js">
|
|
20
20
|
<link rel="modulepreload" crossorigin href="/js/utils-vendor-BX3ZwoIK.js">
|
|
21
|
-
<link rel="modulepreload" crossorigin href="/js/api-
|
|
21
|
+
<link rel="modulepreload" crossorigin href="/js/api-Ddawdcbi.js">
|
|
22
22
|
<link rel="modulepreload" crossorigin href="/js/utils-BaPYjs_z.js">
|
|
23
23
|
<link rel="modulepreload" crossorigin href="/js/Button-Cgmt_2gR.js">
|
|
24
24
|
<link rel="stylesheet" crossorigin href="/assets/index-j-Q57B_D.css">
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{d as t,f as n}from"./markdown-core-fkbHPd-g.js";import{t as r}from"./logger-BmpKNkls.js";import{I as i,Ot as a,Rt as o,Y as s,at as c,dt as l,ot as u,st as d,tt as f,ut as p,vt as m}from"./ui-vendor-njo77ljx.js";import{t as h}from"./utils-BaPYjs_z.js";import{t as g}from"./Button-Cgmt_2gR.js";import{P as _,w as v}from"../assets/index-
|
|
1
|
+
import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{d as t,f as n}from"./markdown-core-fkbHPd-g.js";import{t as r}from"./logger-BmpKNkls.js";import{I as i,Ot as a,Rt as o,Y as s,at as c,dt as l,ot as u,st as d,tt as f,ut as p,vt as m}from"./ui-vendor-njo77ljx.js";import{t as h}from"./utils-BaPYjs_z.js";import{t as g}from"./Button-Cgmt_2gR.js";import{P as _,w as v}from"../assets/index-6X4Fay3z.js";import{t as y}from"./OptimizedSyntaxHighlighter-CNjLqj1Z.js";import{n as b,r as x,t as S}from"./artifactHtml-B7Oy2e__.js";var C=e(n(),1),w=t(),T=r(`components:artifact-renderer`),E=({artifact:e,className:t})=>{let{t:n}=_(),[r,E]=(0,C.useState)(!1),[D,O]=(0,C.useState)(`preview`),k=(0,C.useRef)(null),{theme:A,openArtifactPanel:j}=v(),M=async e=>{try{await navigator.clipboard.writeText(e),E(!0),setTimeout(()=>E(!1),2e3)}catch(e){T.error(`Failed to copy:`,e)}},N=()=>{let t=e.type===`html`?x(e.content,e.title):e.content,n=new Blob([t],{type:P(e.type)}),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=`${e.title}.${F(e.type)}`,document.body.appendChild(i),i.click(),document.body.removeChild(i),URL.revokeObjectURL(r)},P=e=>{switch(e){case`html`:return`text/html`;case`react`:return`text/javascript`;case`svg`:return`image/svg+xml`;case`css`:return`text/css`;case`json`:return`application/json`;default:return`text/plain`}},F=e=>{switch(e){case`html`:return`html`;case`react`:return`jsx`;case`svg`:return`svg`;case`css`:return`css`;case`json`:return`json`;default:return`txt`}},I=()=>{switch(e.type){case`html`:return(0,w.jsx)(s,{className:`h-4 w-4`});case`react`:return(0,w.jsx)(l,{className:`h-4 w-4`});case`svg`:return(0,w.jsx)(f,{className:`h-4 w-4`});case`code`:return(0,w.jsx)(l,{className:`h-4 w-4`});default:return(0,w.jsx)(f,{className:`h-4 w-4`})}},L=()=>(0,w.jsx)(`div`,{"data-testid":`artifact-html-fallback`,className:`w-full h-64 sm:h-80 lg:h-96 flex items-center justify-center bg-gray-50 dark:bg-dark-100 rounded-lg border border-gray-200 dark:border-dark-200 p-4`,children:(0,w.jsxs)(`div`,{className:`max-w-sm text-center`,children:[(0,w.jsx)(a,{className:`h-8 w-8 text-primary-500 mx-auto mb-3`}),(0,w.jsx)(`p`,{className:`text-sm font-medium text-gray-900 dark:text-gray-100`,children:n(`artifacts.previewUnavailable`)}),(0,w.jsx)(`p`,{className:`mt-1 text-sm text-gray-600 dark:text-gray-400`,children:n(`artifacts.previewUnavailableDescription`)}),(0,w.jsxs)(g,{variant:`outline`,size:`sm`,onClick:()=>O(`code`),className:`mt-4`,children:[(0,w.jsx)(o,{className:`h-3.5 w-3.5 mr-1.5`}),n(`artifacts.code`)]})]})}),R=()=>e.content.trim()?(0,w.jsx)(`iframe`,{ref:k,"data-testid":`artifact-html-preview`,srcDoc:x(e.content,e.title),className:`w-full h-64 sm:h-80 lg:h-96 border-0 rounded-lg`,sandbox:b,allow:S,allowFullScreen:!0,title:e.title}):L(),z=()=>{try{return(0,w.jsx)(`div`,{className:`w-full h-64 sm:h-80 lg:h-96 flex items-center justify-center bg-gray-50 dark:bg-dark-100 rounded-lg overflow-hidden border border-gray-200 dark:border-dark-200`,dangerouslySetInnerHTML:{__html:e.content}})}catch{return(0,w.jsx)(`div`,{className:`w-full h-64 sm:h-80 lg:h-96 flex items-center justify-center bg-gray-50 dark:bg-dark-100 rounded-lg border border-gray-200 dark:border-dark-200`,children:(0,w.jsxs)(`div`,{className:`text-center`,children:[(0,w.jsx)(a,{className:`h-8 w-8 text-primary-500 mx-auto mb-2`}),(0,w.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-dark-600`,children:n(`artifacts.invalidSvg`)})]})})}},B=()=>(0,w.jsx)(`div`,{className:`relative max-h-64 sm:max-h-80 lg:max-h-96 overflow-auto`,children:(0,w.jsx)(y,{language:(()=>{if(e.language)return e.language;switch(e.type){case`html`:return`html`;case`react`:return`jsx`;case`svg`:return`xml`;case`json`:return`json`;default:return`text`}})(),isDark:A.mode===`dark`,className:`!m-0 !rounded-lg`,children:e.content})}),V=()=>{try{let t=JSON.parse(e.content),n=JSON.stringify(t,null,2);return(0,w.jsx)(`div`,{className:`relative max-h-64 sm:max-h-80 lg:max-h-96 overflow-auto`,children:(0,w.jsx)(y,{language:`json`,isDark:A.mode===`dark`,className:`!m-0 !rounded-lg`,children:n})})}catch{return(0,w.jsx)(`div`,{className:`w-full h-32 flex items-center justify-center bg-gray-50 dark:bg-dark-100 rounded-lg border border-gray-200 dark:border-dark-200`,children:(0,w.jsxs)(`div`,{className:`text-center`,children:[(0,w.jsx)(a,{className:`h-8 w-8 text-primary-500 mx-auto mb-2`}),(0,w.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-dark-600`,children:n(`artifacts.invalidJson`)})]})})}},H=()=>{if(D===`code`)return B();switch(e.type){case`html`:return R();case`svg`:return z();case`json`:return V();default:return B()}},U=()=>e.type===`html`||e.type===`svg`||e.type===`react`;return(0,w.jsxs)(`div`,{className:h(`border border-gray-200 dark:border-dark-200 rounded-xl bg-white dark:bg-dark-25 shadow-lg transition-all duration-300 hover:shadow-xl`,`w-full max-w-full overflow-hidden animate-fade-in`,`max-h-[400px] flex flex-col`,t),children:[(0,w.jsxs)(`div`,{className:`px-1.5 py-1.5 sm:p-4 border-b border-gray-100 dark:border-dark-200 flex-shrink-0`,children:[(0,w.jsxs)(`div`,{className:`flex flex-col gap-2 sm:hidden`,children:[(0,w.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,w.jsx)(`div`,{className:`h-4 w-4 flex-shrink-0 flex items-center justify-center`,children:I()}),(0,w.jsx)(`h3`,{className:`font-medium text-gray-900 dark:text-gray-100 truncate text-sm leading-tight flex-1`,children:e.title})]}),(0,w.jsxs)(`div`,{className:`flex items-center justify-end gap-0.5`,children:[U()&&(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(g,{variant:D===`preview`?`primary`:`ghost`,size:`sm`,onClick:()=>O(`preview`),className:`h-5 px-0.5 text-xs`,title:n(`artifacts.previewMode`),children:(0,w.jsx)(c,{className:`h-2.5 w-2.5`})}),(0,w.jsx)(g,{variant:D===`code`?`primary`:`ghost`,size:`sm`,onClick:()=>O(`code`),className:`h-5 px-0.5 text-xs`,title:n(`artifacts.codeMode`),children:(0,w.jsx)(o,{className:`h-2.5 w-2.5`})}),(0,w.jsx)(`div`,{className:`w-px h-2 bg-gray-300 dark:bg-gray-600 mx-0.5`})]}),(0,w.jsx)(g,{variant:`ghost`,size:`sm`,onClick:()=>M(e.content),className:`h-5 w-5 p-0 hover:bg-gray-100 dark:hover:bg-dark-200 touch-manipulation`,title:n(`artifacts.copyContent`),children:r?(0,w.jsx)(m,{className:`h-2.5 w-2.5 text-green-500`}):(0,w.jsx)(p,{className:`h-2.5 w-2.5`})}),(0,w.jsx)(g,{variant:`ghost`,size:`sm`,onClick:N,className:`h-5 w-5 p-0 hover:bg-gray-100 dark:hover:bg-dark-200 touch-manipulation`,title:n(`artifacts.download`),children:(0,w.jsx)(d,{className:`h-2.5 w-2.5`})}),(0,w.jsx)(g,{variant:`ghost`,size:`sm`,onClick:()=>j(e),className:`h-5 w-5 p-0 hover:bg-gray-100 dark:hover:bg-dark-200 touch-manipulation border border-gray-200 dark:border-dark-300 hover:border-gray-300 dark:hover:border-dark-400`,title:n(`artifacts.openInPanel`),children:(0,w.jsx)(i,{className:`h-2.5 w-2.5`})})]})]}),(0,w.jsxs)(`div`,{className:`hidden sm:flex items-center justify-between gap-2`,children:[(0,w.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0 flex-1`,children:[(0,w.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0 flex-1`,children:[(0,w.jsx)(`div`,{className:`flex-shrink-0`,children:I()}),(0,w.jsx)(`h3`,{className:`font-semibold text-gray-900 dark:text-gray-100 truncate`,children:e.title})]}),(0,w.jsx)(`span`,{className:`text-xs bg-primary-50 dark:bg-primary-900/20 text-primary-700 dark:text-primary-300 px-2 py-1 rounded-full font-medium flex-shrink-0`,children:e.type.toUpperCase()})]}),(0,w.jsxs)(`div`,{className:`flex items-center gap-1 flex-shrink-0`,children:[U()&&(0,w.jsxs)(w.Fragment,{children:[(0,w.jsxs)(g,{variant:D===`preview`?`primary`:`ghost`,size:`sm`,onClick:()=>O(`preview`),className:`h-8 px-3 text-xs`,title:n(`artifacts.previewMode`),children:[(0,w.jsx)(c,{className:`h-3 w-3 mr-1`}),n(`artifacts.preview`)]}),(0,w.jsxs)(g,{variant:D===`code`?`primary`:`ghost`,size:`sm`,onClick:()=>O(`code`),className:`h-8 px-3 text-xs`,title:n(`artifacts.codeMode`),children:[(0,w.jsx)(o,{className:`h-3 w-3 mr-1`}),n(`artifacts.code`)]}),(0,w.jsx)(`div`,{className:`w-px h-4 bg-gray-300 dark:bg-gray-600 mx-1`})]}),(0,w.jsx)(g,{variant:`ghost`,size:`sm`,onClick:()=>M(e.content),className:`h-8 w-8 p-0 hover:bg-gray-100 dark:hover:bg-dark-200`,title:n(`artifacts.copyContent`),children:r?(0,w.jsx)(m,{className:`h-4 w-4 text-green-500`}):(0,w.jsx)(p,{className:`h-4 w-4`})}),(0,w.jsx)(g,{variant:`ghost`,size:`sm`,onClick:N,className:`h-8 w-8 p-0 hover:bg-gray-100 dark:hover:bg-dark-200`,title:n(`artifacts.download`),children:(0,w.jsx)(d,{className:`h-4 w-4`})}),(0,w.jsx)(g,{variant:`ghost`,size:`sm`,onClick:()=>j(e),className:`h-8 w-8 p-0 hover:bg-gray-100 dark:hover:bg-dark-200`,title:n(`artifacts.openInPanel`),children:(0,w.jsx)(i,{className:`h-4 w-4`})})]})]})]}),(0,w.jsxs)(`div`,{className:`p-4 flex-1 overflow-hidden min-h-0`,children:[e.description&&(0,w.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-400 mb-4`,children:e.description}),(0,w.jsx)(`div`,{className:`h-full overflow-auto`,children:H()})]}),(0,w.jsxs)(`div`,{className:`flex items-center justify-between p-3 border-t border-gray-100 dark:border-dark-200 bg-gray-50 dark:bg-dark-100/50 flex-shrink-0`,children:[(0,w.jsxs)(`div`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:[n(`artifacts.created`),`:`,` `,new Date(e.createdAt).toLocaleString()]}),(e.type===`html`||e.type===`react`)&&(0,w.jsxs)(g,{variant:`ghost`,size:`sm`,onClick:()=>{let t=window.open(``,`_blank`);t&&(t.document.write(x(e.content,e.title)),t.document.close())},className:`text-xs hover:bg-gray-100 dark:hover:bg-dark-200`,children:[(0,w.jsx)(u,{className:`h-3 w-3 mr-1`}),n(`artifacts.openInNewWindow`)]})]})]})},D=({artifacts:e,className:t})=>!e||e.length===0?null:(0,w.jsx)(`div`,{className:h(`space-y-3`,t),children:e.map(e=>(0,w.jsx)(E,{artifact:e},e.id))});export{D as t};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{d as t,f as n}from"./markdown-core-fkbHPd-g.js";import{t as r}from"./Button-Cgmt_2gR.js";import{t as i}from"./ArtifactContainer-
|
|
1
|
+
import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{d as t,f as n}from"./markdown-core-fkbHPd-g.js";import{t as r}from"./Button-Cgmt_2gR.js";import{t as i}from"./ArtifactContainer-lBT2Cf0m.js";var a=e(n(),1),o=t(),s=[{id:`demo-html-1`,type:`html`,title:`Interactive Button Demo`,description:`A simple HTML page with interactive elements`,content:`<div style="text-align: center; padding: 20px;">
|
|
2
2
|
<h1 style="color: #333; font-family: Arial, sans-serif;">Welcome to Libre WebUI!</h1>
|
|
3
3
|
<p style="color: #666; font-size: 16px;">This is an interactive HTML artifact.</p>
|
|
4
4
|
<button
|
package/frontend/dist/js/{ArtifactSlideOutPanel-DlS_laML.js → ArtifactSlideOutPanel-CfbbHcaI.js}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{d as t,f as n}from"./markdown-core-fkbHPd-g.js";import{n as r}from"./react-vendor-Co1u1rWb.js";import{t as i}from"./logger-BmpKNkls.js";import{J as a,Ot as o,Rt as s,Y as c,at as ee,dt as l,n as u,ot as d,st as f,tt as p,ut as m,vt as te}from"./ui-vendor-njo77ljx.js";import{t as h}from"./utils-BaPYjs_z.js";import{t as g}from"./Button-Cgmt_2gR.js";import{P as _,w as v}from"../assets/index-pmlsmnQ4.js";import{t as y}from"./OptimizedSyntaxHighlighter-CNjLqj1Z.js";import{n as b,r as x,t as ne}from"./artifactHtml-B7Oy2e__.js";var S=e(n(),1),C=r(),w=t(),T=i(`components:artifact-slide-out-panel`),E=320,D=.9,O=600,k=()=>{let{t:e}=_(),{artifactPanelOpen:t,artifactPanelArtifact:n,closeArtifactPanel:r,theme:i}=v(),[k,A]=(0,S.useState)(!1),[j,M]=(0,S.useState)(`preview`),[N,P]=(0,S.useState)(O),[F,I]=(0,S.useState)(!1),L=(0,S.useRef)(null),R=(0,S.useRef)(null),z=(0,S.useRef)(null),B=(0,S.useRef)(0),V=(0,S.useRef)(0),H=(0,S.useRef)(null),U=(0,S.useRef)(null),W=(0,S.useRef)(N),G=n?.id??null;G!==z.current&&(z.current=G,j!==`preview`&&M(`preview`));let K=(0,S.useCallback)(e=>{W.current=e,U.current===null&&(U.current=window.requestAnimationFrame(()=>{U.current=null,P(W.current)}))},[]),q=(0,S.useCallback)(()=>{H.current=null,I(!1),U.current!==null&&(window.cancelAnimationFrame(U.current),U.current=null,P(W.current))},[]),J=(0,S.useCallback)(e=>{e.preventDefault(),e.stopPropagation(),H.current=e.pointerId,V.current=N,B.current=e.clientX,W.current=N,e.currentTarget.setPointerCapture(e.pointerId),I(!0)},[N]),Y=(0,S.useCallback)(e=>{if(!F||H.current!==null&&e.pointerId!==H.current)return;e.preventDefault();let t=B.current-e.clientX,n=window.innerWidth*D;K(Math.min(n,Math.max(E,V.current+t)))},[F,K]);if((0,S.useEffect)(()=>{if(!F){document.body.style.userSelect=``,document.body.style.cursor=``;return}let e=e=>{(H.current===null||e.pointerId===H.current)&&q()};return window.addEventListener(`pointermove`,Y,{passive:!1}),window.addEventListener(`pointerup`,e),window.addEventListener(`pointercancel`,e),window.addEventListener(`blur`,q),document.body.style.userSelect=`none`,document.body.style.cursor=`col-resize`,()=>{window.removeEventListener(`pointermove`,Y),window.removeEventListener(`pointerup`,e),window.removeEventListener(`pointercancel`,e),window.removeEventListener(`blur`,q),document.body.style.userSelect=``,document.body.style.cursor=``}},[F,Y,q]),(0,S.useEffect)(()=>{let e=()=>{let e=window.innerWidth*D;N>e&&P(e)};return window.addEventListener(`resize`,e),()=>window.removeEventListener(`resize`,e)},[N]),(0,S.useEffect)(()=>{let e=e=>{e.key===`Escape`&&t&&r()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t,r]),(0,S.useEffect)(()=>{let e=e=>{F||R.current&&!R.current.contains(e.target)&&t&&r()},n=setTimeout(()=>{window.addEventListener(`mousedown`,e)},100);return()=>{clearTimeout(n),window.removeEventListener(`mousedown`,e)}},[t,r,F]),!n)return null;let X=n,re=async e=>{try{await navigator.clipboard.writeText(e),A(!0),setTimeout(()=>A(!1),2e3)}catch(e){T.error(`Failed to copy:`,e)}},ie=()=>{let e=X.type===`html`?x(X.content,X.title):X.content,t=new Blob([e],{type:ae(X.type)}),n=URL.createObjectURL(t),r=document.createElement(`a`);r.href=n,r.download=`${X.title}.${oe(X.type)}`,document.body.appendChild(r),r.click(),document.body.removeChild(r),URL.revokeObjectURL(n)},ae=e=>{switch(e){case`html`:return`text/html`;case`react`:return`text/javascript`;case`svg`:return`image/svg+xml`;case`css`:return`text/css`;case`json`:return`application/json`;default:return`text/plain`}},oe=e=>{switch(e){case`html`:return`html`;case`react`:return`jsx`;case`svg`:return`svg`;case`css`:return`css`;case`json`:return`json`;default:return`txt`}},se=()=>{switch(X.type){case`html`:return(0,w.jsx)(c,{className:`h-5 w-5`});case`react`:return(0,w.jsx)(l,{className:`h-5 w-5`});case`svg`:return(0,w.jsx)(p,{className:`h-5 w-5`});case`code`:return(0,w.jsx)(l,{className:`h-5 w-5`});default:return(0,w.jsx)(p,{className:`h-5 w-5`})}},ce=()=>(0,w.jsx)(`div`,{"data-testid":`artifact-html-fallback`,className:`w-full h-full flex items-center justify-center bg-gray-50 dark:bg-dark-100 rounded-lg border border-gray-200 dark:border-dark-200 p-4`,children:(0,w.jsxs)(`div`,{className:`max-w-sm text-center`,children:[(0,w.jsx)(o,{className:`h-8 w-8 text-primary-500 mx-auto mb-3`}),(0,w.jsx)(`p`,{className:`text-sm font-medium text-gray-900 dark:text-gray-100`,children:e(`artifacts.previewUnavailable`)}),(0,w.jsx)(`p`,{className:`mt-1 text-sm text-gray-600 dark:text-gray-400`,children:e(`artifacts.previewUnavailableDescription`)}),(0,w.jsxs)(g,{variant:`outline`,size:`sm`,onClick:()=>M(`code`),className:`mt-4`,children:[(0,w.jsx)(s,{className:`h-3.5 w-3.5 mr-1.5`}),e(`artifacts.code`)]})]})}),Z=()=>X.content.trim()?(0,w.jsx)(`iframe`,{ref:L,"data-testid":`artifact-html-preview`,srcDoc:x(X.content,X.title),className:h(`w-full h-full border-0 rounded-lg bg-white`,F&&`pointer-events-none`),sandbox:b,allow:ne,allowFullScreen:!0,title:X.title}):ce(),le=()=>{try{return(0,w.jsx)(`div`,{className:`w-full h-full flex items-center justify-center bg-gray-50 dark:bg-dark-100 rounded-lg overflow-auto p-4`,dangerouslySetInnerHTML:{__html:X.content}})}catch{return(0,w.jsx)(`div`,{className:`w-full h-full flex items-center justify-center bg-gray-50 dark:bg-dark-100 rounded-lg`,children:(0,w.jsxs)(`div`,{className:`text-center`,children:[(0,w.jsx)(o,{className:`h-8 w-8 text-primary-500 mx-auto mb-2`}),(0,w.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-dark-600`,children:e(`artifacts.invalidSvg`)})]})})}},Q=()=>(0,w.jsx)(`div`,{className:`h-full overflow-auto`,children:(0,w.jsx)(y,{language:(()=>{if(X.language)return X.language;switch(X.type){case`html`:return`html`;case`react`:return`jsx`;case`svg`:return`xml`;case`json`:return`json`;default:return`text`}})(),isDark:i.mode===`dark`,className:`!m-0 !rounded-lg !h-full`,children:X.content})}),ue=()=>{try{let e=JSON.parse(X.content),t=JSON.stringify(e,null,2);return(0,w.jsx)(`div`,{className:`h-full overflow-auto`,children:(0,w.jsx)(y,{language:`json`,isDark:i.mode===`dark`,className:`!m-0 !rounded-lg !h-full`,children:t})})}catch{return(0,w.jsx)(`div`,{className:`w-full h-full flex items-center justify-center bg-gray-50 dark:bg-dark-100 rounded-lg`,children:(0,w.jsxs)(`div`,{className:`text-center`,children:[(0,w.jsx)(o,{className:`h-8 w-8 text-primary-500 mx-auto mb-2`}),(0,w.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-dark-600`,children:e(`artifacts.invalidJson`)})]})})}},de=()=>{if(j===`code`)return Q();switch(X.type){case`html`:return Z();case`svg`:return le();case`json`:return ue();default:return Q()}},fe=()=>X.type===`html`||X.type===`svg`||X.type===`react`,$=typeof window<`u`&&window.innerWidth<640,pe=$?`100%`:`${N}px`;return(0,C.createPortal)((0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`div`,{className:h(`fixed inset-0 bg-black/30 dark:bg-black/50 z-40 transition-opacity duration-300`,t?`opacity-100`:`opacity-0 pointer-events-none`)}),F&&(0,w.jsx)(`div`,{className:`fixed inset-0 z-[55] cursor-col-resize select-none`,"aria-hidden":`true`}),(0,w.jsxs)(`div`,{ref:R,"data-testid":`artifact-slide-out-panel`,style:{width:pe},className:h(`fixed top-0 right-0 h-full z-50`,`bg-white dark:bg-dark-25`,`shadow-2xl border-l border-gray-200 dark:border-dark-200`,`flex flex-col`,`transform transition-transform duration-300 ease-out`,t?`translate-x-0`:`translate-x-full`),children:[!$&&(0,w.jsxs)(`div`,{onPointerDown:J,"data-testid":`artifact-resize-handle`,className:h(`absolute left-0 top-0 bottom-0 w-4 -ml-2 cursor-col-resize z-[56]`,`flex items-center justify-center`,`touch-none select-none group`),children:[(0,w.jsx)(`div`,{className:h(`w-1 h-16 rounded-full transition-all duration-200`,`bg-gray-300 dark:bg-dark-300`,`group-hover:bg-primary-500 group-hover:h-24`,F&&`bg-primary-500 h-24`)}),(0,w.jsx)(`div`,{className:h(`absolute left-1/2 -translate-x-1/2 opacity-0 group-hover:opacity-100 transition-opacity`,`text-gray-400 dark:text-dark-500`,F&&`opacity-100`),children:(0,w.jsx)(a,{className:`h-4 w-4`})})]}),(0,w.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-gray-200 dark:border-dark-200`,children:[(0,w.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0 flex-1`,children:[(0,w.jsx)(`div`,{className:`text-gray-600 dark:text-gray-400 flex-shrink-0`,children:se()}),(0,w.jsx)(`h2`,{className:`font-semibold text-gray-900 dark:text-gray-100 truncate`,children:X.title}),(0,w.jsx)(`span`,{className:`text-xs bg-primary-50 dark:bg-primary-900/20 text-primary-700 dark:text-primary-300 px-2 py-1 rounded-full font-medium flex-shrink-0`,children:X.type.toUpperCase()})]}),(0,w.jsx)(g,{variant:`ghost`,size:`sm`,onClick:r,className:`h-8 w-8 p-0 hover:bg-gray-100 dark:hover:bg-dark-200 flex-shrink-0`,title:e(`artifacts.closePanelEsc`),children:(0,w.jsx)(u,{className:`h-5 w-5`})})]}),(0,w.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-2 border-b border-gray-100 dark:border-dark-200 bg-gray-50 dark:bg-dark-100/50`,children:[(0,w.jsx)(`div`,{className:`flex items-center gap-1`,children:fe()&&(0,w.jsxs)(w.Fragment,{children:[(0,w.jsxs)(g,{variant:j===`preview`?`primary`:`ghost`,size:`sm`,onClick:()=>M(`preview`),className:`h-8 px-3 text-xs`,title:e(`artifacts.previewMode`),children:[(0,w.jsx)(ee,{className:`h-3.5 w-3.5 mr-1.5`}),e(`artifacts.preview`)]}),(0,w.jsxs)(g,{variant:j===`code`?`primary`:`ghost`,size:`sm`,onClick:()=>M(`code`),className:`h-8 px-3 text-xs`,title:e(`artifacts.codeMode`),children:[(0,w.jsx)(s,{className:`h-3.5 w-3.5 mr-1.5`}),e(`artifacts.code`)]})]})}),(0,w.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,w.jsx)(g,{variant:`ghost`,size:`sm`,onClick:()=>re(X.content),className:`h-8 px-3 text-xs hover:bg-gray-100 dark:hover:bg-dark-200`,title:e(`artifacts.copyContent`),children:k?(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(te,{className:`h-3.5 w-3.5 mr-1.5 text-green-500`}),e(`artifacts.copied`)]}):(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(m,{className:`h-3.5 w-3.5 mr-1.5`}),e(`artifacts.copyButton`)]})}),(0,w.jsxs)(g,{variant:`ghost`,size:`sm`,onClick:ie,className:`h-8 px-3 text-xs hover:bg-gray-100 dark:hover:bg-dark-200`,title:e(`artifacts.download`),children:[(0,w.jsx)(f,{className:`h-3.5 w-3.5 mr-1.5`}),e(`artifacts.download`)]}),(X.type===`html`||X.type===`react`)&&(0,w.jsxs)(g,{variant:`ghost`,size:`sm`,onClick:()=>{let e=window.open(``,`_blank`);e&&(e.document.write(x(X.content,X.title)),e.document.close())},className:`h-8 px-3 text-xs hover:bg-gray-100 dark:hover:bg-dark-200`,title:e(`artifacts.openInNewWindow`),children:[(0,w.jsx)(d,{className:`h-3.5 w-3.5 mr-1.5`}),e(`artifacts.open`)]})]})]}),X.description&&(0,w.jsx)(`div`,{className:`px-4 py-3 border-b border-gray-100 dark:border-dark-200`,children:(0,w.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-400`,children:X.description})}),(0,w.jsx)(`div`,{className:`flex-1 p-4 overflow-hidden`,children:de()}),(0,w.jsx)(`div`,{className:`px-4 py-2 border-t border-gray-100 dark:border-dark-200 bg-gray-50 dark:bg-dark-100/50`,children:(0,w.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,w.jsxs)(`div`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:[e(`artifacts.created`),`:`,` `,new Date(X.createdAt).toLocaleString()]}),!$&&(0,w.jsx)(`div`,{className:`text-xs text-gray-400 dark:text-dark-500`,children:e(`artifacts.dragEdgeToResize`)})]})})]})]}),document.body)};export{k as ArtifactSlideOutPanel};
|
|
1
|
+
import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{d as t,f as n}from"./markdown-core-fkbHPd-g.js";import{n as r}from"./react-vendor-Co1u1rWb.js";import{t as i}from"./logger-BmpKNkls.js";import{J as a,Ot as o,Rt as s,Y as c,at as ee,dt as l,n as u,ot as d,st as f,tt as p,ut as m,vt as te}from"./ui-vendor-njo77ljx.js";import{t as h}from"./utils-BaPYjs_z.js";import{t as g}from"./Button-Cgmt_2gR.js";import{P as _,w as v}from"../assets/index-6X4Fay3z.js";import{t as y}from"./OptimizedSyntaxHighlighter-CNjLqj1Z.js";import{n as b,r as x,t as ne}from"./artifactHtml-B7Oy2e__.js";var S=e(n(),1),C=r(),w=t(),T=i(`components:artifact-slide-out-panel`),E=320,D=.9,O=600,k=()=>{let{t:e}=_(),{artifactPanelOpen:t,artifactPanelArtifact:n,closeArtifactPanel:r,theme:i}=v(),[k,A]=(0,S.useState)(!1),[j,M]=(0,S.useState)(`preview`),[N,P]=(0,S.useState)(O),[F,I]=(0,S.useState)(!1),L=(0,S.useRef)(null),R=(0,S.useRef)(null),z=(0,S.useRef)(null),B=(0,S.useRef)(0),V=(0,S.useRef)(0),H=(0,S.useRef)(null),U=(0,S.useRef)(null),W=(0,S.useRef)(N),G=n?.id??null;G!==z.current&&(z.current=G,j!==`preview`&&M(`preview`));let K=(0,S.useCallback)(e=>{W.current=e,U.current===null&&(U.current=window.requestAnimationFrame(()=>{U.current=null,P(W.current)}))},[]),q=(0,S.useCallback)(()=>{H.current=null,I(!1),U.current!==null&&(window.cancelAnimationFrame(U.current),U.current=null,P(W.current))},[]),J=(0,S.useCallback)(e=>{e.preventDefault(),e.stopPropagation(),H.current=e.pointerId,V.current=N,B.current=e.clientX,W.current=N,e.currentTarget.setPointerCapture(e.pointerId),I(!0)},[N]),Y=(0,S.useCallback)(e=>{if(!F||H.current!==null&&e.pointerId!==H.current)return;e.preventDefault();let t=B.current-e.clientX,n=window.innerWidth*D;K(Math.min(n,Math.max(E,V.current+t)))},[F,K]);if((0,S.useEffect)(()=>{if(!F){document.body.style.userSelect=``,document.body.style.cursor=``;return}let e=e=>{(H.current===null||e.pointerId===H.current)&&q()};return window.addEventListener(`pointermove`,Y,{passive:!1}),window.addEventListener(`pointerup`,e),window.addEventListener(`pointercancel`,e),window.addEventListener(`blur`,q),document.body.style.userSelect=`none`,document.body.style.cursor=`col-resize`,()=>{window.removeEventListener(`pointermove`,Y),window.removeEventListener(`pointerup`,e),window.removeEventListener(`pointercancel`,e),window.removeEventListener(`blur`,q),document.body.style.userSelect=``,document.body.style.cursor=``}},[F,Y,q]),(0,S.useEffect)(()=>{let e=()=>{let e=window.innerWidth*D;N>e&&P(e)};return window.addEventListener(`resize`,e),()=>window.removeEventListener(`resize`,e)},[N]),(0,S.useEffect)(()=>{let e=e=>{e.key===`Escape`&&t&&r()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t,r]),(0,S.useEffect)(()=>{let e=e=>{F||R.current&&!R.current.contains(e.target)&&t&&r()},n=setTimeout(()=>{window.addEventListener(`mousedown`,e)},100);return()=>{clearTimeout(n),window.removeEventListener(`mousedown`,e)}},[t,r,F]),!n)return null;let X=n,re=async e=>{try{await navigator.clipboard.writeText(e),A(!0),setTimeout(()=>A(!1),2e3)}catch(e){T.error(`Failed to copy:`,e)}},ie=()=>{let e=X.type===`html`?x(X.content,X.title):X.content,t=new Blob([e],{type:ae(X.type)}),n=URL.createObjectURL(t),r=document.createElement(`a`);r.href=n,r.download=`${X.title}.${oe(X.type)}`,document.body.appendChild(r),r.click(),document.body.removeChild(r),URL.revokeObjectURL(n)},ae=e=>{switch(e){case`html`:return`text/html`;case`react`:return`text/javascript`;case`svg`:return`image/svg+xml`;case`css`:return`text/css`;case`json`:return`application/json`;default:return`text/plain`}},oe=e=>{switch(e){case`html`:return`html`;case`react`:return`jsx`;case`svg`:return`svg`;case`css`:return`css`;case`json`:return`json`;default:return`txt`}},se=()=>{switch(X.type){case`html`:return(0,w.jsx)(c,{className:`h-5 w-5`});case`react`:return(0,w.jsx)(l,{className:`h-5 w-5`});case`svg`:return(0,w.jsx)(p,{className:`h-5 w-5`});case`code`:return(0,w.jsx)(l,{className:`h-5 w-5`});default:return(0,w.jsx)(p,{className:`h-5 w-5`})}},ce=()=>(0,w.jsx)(`div`,{"data-testid":`artifact-html-fallback`,className:`w-full h-full flex items-center justify-center bg-gray-50 dark:bg-dark-100 rounded-lg border border-gray-200 dark:border-dark-200 p-4`,children:(0,w.jsxs)(`div`,{className:`max-w-sm text-center`,children:[(0,w.jsx)(o,{className:`h-8 w-8 text-primary-500 mx-auto mb-3`}),(0,w.jsx)(`p`,{className:`text-sm font-medium text-gray-900 dark:text-gray-100`,children:e(`artifacts.previewUnavailable`)}),(0,w.jsx)(`p`,{className:`mt-1 text-sm text-gray-600 dark:text-gray-400`,children:e(`artifacts.previewUnavailableDescription`)}),(0,w.jsxs)(g,{variant:`outline`,size:`sm`,onClick:()=>M(`code`),className:`mt-4`,children:[(0,w.jsx)(s,{className:`h-3.5 w-3.5 mr-1.5`}),e(`artifacts.code`)]})]})}),Z=()=>X.content.trim()?(0,w.jsx)(`iframe`,{ref:L,"data-testid":`artifact-html-preview`,srcDoc:x(X.content,X.title),className:h(`w-full h-full border-0 rounded-lg bg-white`,F&&`pointer-events-none`),sandbox:b,allow:ne,allowFullScreen:!0,title:X.title}):ce(),le=()=>{try{return(0,w.jsx)(`div`,{className:`w-full h-full flex items-center justify-center bg-gray-50 dark:bg-dark-100 rounded-lg overflow-auto p-4`,dangerouslySetInnerHTML:{__html:X.content}})}catch{return(0,w.jsx)(`div`,{className:`w-full h-full flex items-center justify-center bg-gray-50 dark:bg-dark-100 rounded-lg`,children:(0,w.jsxs)(`div`,{className:`text-center`,children:[(0,w.jsx)(o,{className:`h-8 w-8 text-primary-500 mx-auto mb-2`}),(0,w.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-dark-600`,children:e(`artifacts.invalidSvg`)})]})})}},Q=()=>(0,w.jsx)(`div`,{className:`h-full overflow-auto`,children:(0,w.jsx)(y,{language:(()=>{if(X.language)return X.language;switch(X.type){case`html`:return`html`;case`react`:return`jsx`;case`svg`:return`xml`;case`json`:return`json`;default:return`text`}})(),isDark:i.mode===`dark`,className:`!m-0 !rounded-lg !h-full`,children:X.content})}),ue=()=>{try{let e=JSON.parse(X.content),t=JSON.stringify(e,null,2);return(0,w.jsx)(`div`,{className:`h-full overflow-auto`,children:(0,w.jsx)(y,{language:`json`,isDark:i.mode===`dark`,className:`!m-0 !rounded-lg !h-full`,children:t})})}catch{return(0,w.jsx)(`div`,{className:`w-full h-full flex items-center justify-center bg-gray-50 dark:bg-dark-100 rounded-lg`,children:(0,w.jsxs)(`div`,{className:`text-center`,children:[(0,w.jsx)(o,{className:`h-8 w-8 text-primary-500 mx-auto mb-2`}),(0,w.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-dark-600`,children:e(`artifacts.invalidJson`)})]})})}},de=()=>{if(j===`code`)return Q();switch(X.type){case`html`:return Z();case`svg`:return le();case`json`:return ue();default:return Q()}},fe=()=>X.type===`html`||X.type===`svg`||X.type===`react`,$=typeof window<`u`&&window.innerWidth<640,pe=$?`100%`:`${N}px`;return(0,C.createPortal)((0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`div`,{className:h(`fixed inset-0 bg-black/30 dark:bg-black/50 z-40 transition-opacity duration-300`,t?`opacity-100`:`opacity-0 pointer-events-none`)}),F&&(0,w.jsx)(`div`,{className:`fixed inset-0 z-[55] cursor-col-resize select-none`,"aria-hidden":`true`}),(0,w.jsxs)(`div`,{ref:R,"data-testid":`artifact-slide-out-panel`,style:{width:pe},className:h(`fixed top-0 right-0 h-full z-50`,`bg-white dark:bg-dark-25`,`shadow-2xl border-l border-gray-200 dark:border-dark-200`,`flex flex-col`,`transform transition-transform duration-300 ease-out`,t?`translate-x-0`:`translate-x-full`),children:[!$&&(0,w.jsxs)(`div`,{onPointerDown:J,"data-testid":`artifact-resize-handle`,className:h(`absolute left-0 top-0 bottom-0 w-4 -ml-2 cursor-col-resize z-[56]`,`flex items-center justify-center`,`touch-none select-none group`),children:[(0,w.jsx)(`div`,{className:h(`w-1 h-16 rounded-full transition-all duration-200`,`bg-gray-300 dark:bg-dark-300`,`group-hover:bg-primary-500 group-hover:h-24`,F&&`bg-primary-500 h-24`)}),(0,w.jsx)(`div`,{className:h(`absolute left-1/2 -translate-x-1/2 opacity-0 group-hover:opacity-100 transition-opacity`,`text-gray-400 dark:text-dark-500`,F&&`opacity-100`),children:(0,w.jsx)(a,{className:`h-4 w-4`})})]}),(0,w.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-gray-200 dark:border-dark-200`,children:[(0,w.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0 flex-1`,children:[(0,w.jsx)(`div`,{className:`text-gray-600 dark:text-gray-400 flex-shrink-0`,children:se()}),(0,w.jsx)(`h2`,{className:`font-semibold text-gray-900 dark:text-gray-100 truncate`,children:X.title}),(0,w.jsx)(`span`,{className:`text-xs bg-primary-50 dark:bg-primary-900/20 text-primary-700 dark:text-primary-300 px-2 py-1 rounded-full font-medium flex-shrink-0`,children:X.type.toUpperCase()})]}),(0,w.jsx)(g,{variant:`ghost`,size:`sm`,onClick:r,className:`h-8 w-8 p-0 hover:bg-gray-100 dark:hover:bg-dark-200 flex-shrink-0`,title:e(`artifacts.closePanelEsc`),children:(0,w.jsx)(u,{className:`h-5 w-5`})})]}),(0,w.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-2 border-b border-gray-100 dark:border-dark-200 bg-gray-50 dark:bg-dark-100/50`,children:[(0,w.jsx)(`div`,{className:`flex items-center gap-1`,children:fe()&&(0,w.jsxs)(w.Fragment,{children:[(0,w.jsxs)(g,{variant:j===`preview`?`primary`:`ghost`,size:`sm`,onClick:()=>M(`preview`),className:`h-8 px-3 text-xs`,title:e(`artifacts.previewMode`),children:[(0,w.jsx)(ee,{className:`h-3.5 w-3.5 mr-1.5`}),e(`artifacts.preview`)]}),(0,w.jsxs)(g,{variant:j===`code`?`primary`:`ghost`,size:`sm`,onClick:()=>M(`code`),className:`h-8 px-3 text-xs`,title:e(`artifacts.codeMode`),children:[(0,w.jsx)(s,{className:`h-3.5 w-3.5 mr-1.5`}),e(`artifacts.code`)]})]})}),(0,w.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,w.jsx)(g,{variant:`ghost`,size:`sm`,onClick:()=>re(X.content),className:`h-8 px-3 text-xs hover:bg-gray-100 dark:hover:bg-dark-200`,title:e(`artifacts.copyContent`),children:k?(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(te,{className:`h-3.5 w-3.5 mr-1.5 text-green-500`}),e(`artifacts.copied`)]}):(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(m,{className:`h-3.5 w-3.5 mr-1.5`}),e(`artifacts.copyButton`)]})}),(0,w.jsxs)(g,{variant:`ghost`,size:`sm`,onClick:ie,className:`h-8 px-3 text-xs hover:bg-gray-100 dark:hover:bg-dark-200`,title:e(`artifacts.download`),children:[(0,w.jsx)(f,{className:`h-3.5 w-3.5 mr-1.5`}),e(`artifacts.download`)]}),(X.type===`html`||X.type===`react`)&&(0,w.jsxs)(g,{variant:`ghost`,size:`sm`,onClick:()=>{let e=window.open(``,`_blank`);e&&(e.document.write(x(X.content,X.title)),e.document.close())},className:`h-8 px-3 text-xs hover:bg-gray-100 dark:hover:bg-dark-200`,title:e(`artifacts.openInNewWindow`),children:[(0,w.jsx)(d,{className:`h-3.5 w-3.5 mr-1.5`}),e(`artifacts.open`)]})]})]}),X.description&&(0,w.jsx)(`div`,{className:`px-4 py-3 border-b border-gray-100 dark:border-dark-200`,children:(0,w.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-400`,children:X.description})}),(0,w.jsx)(`div`,{className:`flex-1 p-4 overflow-hidden`,children:de()}),(0,w.jsx)(`div`,{className:`px-4 py-2 border-t border-gray-100 dark:border-dark-200 bg-gray-50 dark:bg-dark-100/50`,children:(0,w.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,w.jsxs)(`div`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:[e(`artifacts.created`),`:`,` `,new Date(X.createdAt).toLocaleString()]}),!$&&(0,w.jsx)(`div`,{className:`text-xs text-gray-400 dark:text-dark-500`,children:e(`artifacts.dragEdgeToResize`)})]})})]})]}),document.body)};export{k as ArtifactSlideOutPanel};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{d as t,f as n}from"./markdown-core-fkbHPd-g.js";import{n as r}from"./react-vendor-Co1u1rWb.js";import{t as i}from"./useQuery-B2OUd39C.js";import{t as a}from"./logger-BmpKNkls.js";import{A as o,At as s,Bt as c,C as l,Ct as u,D as d,G as f,H as p,Mt as m,N as h,Nt as g,P as _,Q as v,Rt as y,S as b,St as x,T as S,Tt as C,U as w,Vt as T,Y as E,Z as D,_t as O,a as k,c as A,ct as ee,d as j,dt as M,et as N,ft as P,h as te,ht as ne,i as F,lt as I,mt as re,n as L,o as ie,ot as ae,q as oe,r as se,st as ce,t as R,tt as z,ut as le,v as B,vt as ue,x as V,xt as de,y as fe,z as H}from"./ui-vendor-njo77ljx.js";import{n as pe}from"./demoMode-BhEpMVh5.js";import{a as me,c as he,d as ge,f as U,m as _e,n as ve,o as ye,s as be,u as xe}from"./api-D9FuobIF.js";import{i as Se,n as Ce,r as we,t as W}from"./utils-BaPYjs_z.js";import{t as G}from"./Button-Cgmt_2gR.js";import{A as K,G as Te,K as Ee,P as q,S as J,W as De,_ as Oe,f as ke,h as Ae,m as je,v as Me,w as Ne,x as Pe,y as Fe}from"../assets/index-pmlsmnQ4.js";import{a as Ie,i as Le}from"./artifactHtml-B7Oy2e__.js";import{t as Re}from"./ArtifactContainer-DYmgznWk.js";var ze=r(),Y=e(n(),1),X=t(),Be=({statistics:e,className:t=``})=>{let[n,r]=(0,Y.useState)(!1),{t:i}=q(),a=e=>{if(e==null)return`N/A`;let t=e/1e6;return t<1e3?`${Math.round(t)}ms`:`${(t/1e3).toFixed(2)}s`},o=e=>e?`${e.toFixed(1)} t/s`:`N/A`,s=e.prompt_eval_count||0,c=e.eval_count||0,l=s+c,u=a(e.total_duration),d=o(e.tokens_per_second);return(0,X.jsxs)(`div`,{className:`text-xs text-gray-500 dark:text-dark-500 mt-2 ${t}`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-4 mb-1`,children:[(0,X.jsxs)(`span`,{className:`flex items-center gap-1 text-gray-600 dark:text-dark-600`,children:[(0,X.jsx)(p,{size:12,className:`text-primary-500`}),c,` tokens`]}),(0,X.jsx)(`span`,{className:`text-gray-500 dark:text-dark-500`,children:d}),(0,X.jsx)(`span`,{className:`text-gray-500 dark:text-dark-500`,children:u}),e.model&&(0,X.jsx)(`span`,{className:`text-gray-400 dark:text-dark-400 bg-gray-100 dark:bg-dark-200 px-2 py-0.5 rounded-full truncate max-w-32 sm:max-w-48`,title:e.model,children:e.model})]}),(0,X.jsxs)(`button`,{onClick:()=>r(!n),className:`flex items-center gap-1 text-gray-400 dark:text-dark-400 hover:text-gray-600 dark:hover:text-dark-600 transition-colors`,children:[n?(0,X.jsx)(O,{size:12}):(0,X.jsx)(ne,{size:12}),(0,X.jsx)(`span`,{children:i(`generationStats.details`)})]}),n&&(0,X.jsxs)(`div`,{className:`mt-2 p-3 bg-gray-50 dark:bg-dark-100 border border-gray-200 dark:border-dark-300 rounded-lg text-xs space-y-2`,children:[(0,X.jsxs)(`div`,{className:`grid grid-cols-2 gap-x-4 gap-y-2`,children:[(0,X.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,X.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.promptTokens`)}),` `,s]}),(0,X.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,X.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.generatedTokens`)}),` `,c]}),(0,X.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,X.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.totalTokens`)}),` `,l]}),(0,X.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,X.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.speed`)}),` `,d]}),(0,X.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,X.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.promptEval`)}),` `,a(e.prompt_eval_duration)]}),(0,X.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,X.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.generation`)}),` `,a(e.eval_duration)]}),(0,X.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,X.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.modelLoad`)}),` `,a(e.load_duration)]}),(0,X.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,X.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.totalTime`)}),` `,u]})]}),e.created_at&&(0,X.jsxs)(`div`,{className:`pt-2 border-t border-gray-200 dark:border-dark-300 text-gray-600 dark:text-dark-600`,children:[(0,X.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.generatedAt`)}),` `,new Date(e.created_at).toLocaleTimeString()]})]})]})},Ve=a(`components:ttsbutton`),He=null,Ue=null,We=0,Ge=300*1e3;async function Ke(){let e=Date.now();return He!==null&&e-We<Ge?He:Ue||(Ue=(async()=>{try{let t=await ve.getModels();return t.success&&t.data&&t.data.length>0?(He=t.data,We=e,t.data):(He=[],We=e,[])}catch{return He=[],We=e,[]}finally{Ue=null}})(),Ue)}function qe(e){return e.split(/(?<=[.!?]["']?\s)|(?<=[.!?]["']?$)/).map(e=>e.trim()).filter(e=>e.length>0)}var Je=({text:e,className:t,size:n=`sm`})=>{let{t:r}=q(),{preferences:i}=Ne(),[a,o]=(0,Y.useState)(!1),[s,c]=(0,Y.useState)(!1),[l,u]=(0,Y.useState)(null),[d,f]=(0,Y.useState)([]),[p,m]=(0,Y.useState)(null),h=(0,Y.useRef)(null),_=(0,Y.useRef)(!1),v=(0,Y.useRef)([]),y=(0,Y.useRef)(0);(0,Y.useEffect)(()=>{let e=!0;return Ke().then(t=>{e&&(f(t),m(t.length>0))}),()=>{e=!1}},[]);let b=(0,Y.useCallback)(async(e,t,n,i)=>{let a=await ve.generateBase64({model:t,input:e,voice:n,speed:i,response_format:`mp3`});if(!a.success||!a.data?.audio)throw Error(a.message||r(`ttsButton.generateFailed`));let o=`data:${a.data.mimeType};base64,${a.data.audio}`,s=new Audio(o);return h.current=s,new Promise((e,t)=>{s.onended=()=>{h.current=null,e()},s.onerror=()=>{h.current=null,t(Error(r(`ttsButton.playbackFailed`)))},s.play().catch(t)})},[r]),x=(0,Y.useCallback)(async(e,t,n,r)=>{v.current=e,y.current=0,_.current=!1;let i=null,a=async e=>{try{let i=await ve.generateBase64({model:t,input:e,voice:n,speed:r,response_format:`mp3`});return!i.success||!i.data?.audio?null:{audioUrl:`data:${i.data.mimeType};base64,${i.data.audio}`,mimeType:i.data.mimeType}}catch{return null}};e.length>0&&(i=a(e[0]));for(let t=0;t<e.length&&!_.current;t++){y.current=t;try{let n=await i;if(_.current)break;if(i=t+1<e.length?a(e[t+1]):null,!n){Ve.warn(`Failed to generate audio for sentence ${t+1}, skipping`);continue}let r=new Audio(n.audioUrl);h.current=r,await new Promise((e,t)=>{r.onended=()=>{h.current=null,e()},r.onerror=()=>{h.current=null,e()},r.play().catch(()=>{e()})})}catch(e){Ve.error(`Error playing sentence ${t+1}:`,e)}}},[]),S=(0,Y.useCallback)(()=>{_.current=!0,h.current&&(h.current.pause(),h.current.currentTime=0,h.current=null),o(!1),c(!1)},[]),C=async()=>{if(!s){if(a){S();return}c(!0),u(null),_.current=!1;try{let t=i.ttsSettings,n=t?.model||d[0]?.model||`tts-1`,a=t?.voice||d[0]?.config?.default_voice||`alloy`,s=t?.speed||1;if(t?.streamSentences){let t=qe(e);if(t.length===0)throw Error(r(`ttsButton.generateFailed`));c(!1),o(!0),await x(t,n,a,s),_.current||o(!1)}else await b(e,n,a,s),c(!1),o(!0),h.current&&(h.current.onended=()=>{o(!1),h.current=null},h.current.onerror=()=>{u(r(`ttsButton.playbackFailed`)),o(!1),h.current=null})}catch(e){u(e instanceof Error?e.message:r(`ttsButton.generateFailed`)),Ve.error(`TTS error:`,e),o(!1),c(!1)}}};if((0,Y.useEffect)(()=>()=>{_.current=!0,h.current&&(h.current.pause(),h.current=null)},[]),p===!1||p===null)return null;let w={sm:`h-6 w-6 p-1`,md:`h-8 w-8 p-1.5`,lg:`h-10 w-10 p-2`},T={sm:`h-3.5 w-3.5`,md:`h-4 w-4`,lg:`h-5 w-5`};return(0,X.jsx)(`button`,{onClick:C,disabled:s||!e,title:l||r(a?`ttsButton.stopSpeaking`:s?`ttsButton.generatingSpeech`:`ttsButton.readAloud`),className:W(`rounded-full transition-all duration-200`,`hover:bg-gray-100 dark:hover:bg-dark-200`,`focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-1`,`disabled:opacity-50 disabled:cursor-not-allowed`,l?`text-red-500 dark:text-red-400`:a?`text-primary-600 dark:text-primary-400 bg-primary-50 dark:bg-primary-900/20`:`text-gray-500 dark:text-gray-400`,w[n],t),children:s?(0,X.jsx)(g,{className:W(T[n],`animate-spin`)}):a?(0,X.jsx)(te,{className:T[n]}):l?(0,X.jsx)(F,{className:T[n]}):(0,X.jsx)(k,{className:T[n]})})},Ye=/```([^\n`]*)\n([\s\S]*?)\n```/g,Xe=/[\w@./-]+\.(?:html?|css|mjs|js|jsx|ts|tsx|svg|json|py)/i,Ze=[`html`,`react`,`svg`,`mermaid`,`chart`,`code`,`text`,`json`],Qe=[{regex:/<artifact\s+type="([^"]+)"\s+title="([^"]+)"[^>]*>([\s\S]*?)<\/artifact>/gi,extract:e=>({type:ot(e[1]),title:$e(e[2]).trim()||`Artifact`,content:e[3].trim()})},{regex:/<artifact\s+type="([^"]+)"[^>]*>([\s\S]*?)<\/artifact>/gi,extract:e=>{let t=ot(e[1]);return{type:t,title:`${t.toUpperCase()} Artifact`,content:e[2].trim()}}}];function $e(e){if(typeof document<`u`){let t=document.createElement(`div`);return t.innerHTML=e,t.textContent||t.innerText||``}return tt(et(e))}function et(e){return e.replace(/&(lt|gt|quot|apos|#39);/gi,(e,t)=>{switch(t.toLowerCase()){case`lt`:return`<`;case`gt`:return`>`;case`quot`:return`"`;case`apos`:case`#39`:return`'`;default:return``}}).replace(/&/gi,`&`)}function tt(e){let t=``,n=!1,r=null;for(let i=0;i<e.length;i+=1){let a=e[i];if(n){if(r){a===r&&(r=null);continue}if(a===`"`||a===`'`){r=a;continue}a===`>`&&(n=!1);continue}if(a===`<`){let t=e[i+1];if(t&&/[!/A-Za-z?]/.test(t)){n=!0;continue}}t+=a}return t}function nt(e){let t=e.match(/<title[^>]*>([\s\S]*?)<\/title>/i);if(t)return $e(t[1]).trim()||null;let n=e.match(/<h1[^>]*>([\s\S]*?)<\/h1>/i);return n&&$e(n[1]).trim()||null}function rt(e){let t=e.match(/(?:function|const)\s+(\w+)/);if(t)return t[1];let n=e.match(/class\s+(\w+)/);return n?n[1]:null}function it(e){if(e.includes(`def main(`))return`Python Script`;let t=e.match(/class\s+(\w+)/);if(t)return`${t[1]} Class`;let n=e.match(/def\s+(\w+)/);return n&&n[1]!==`__init__`?`${n[1]} Function`:null}function at(e){let t=e.match(/function\s+(\w+)/);if(t)return`${t[1]} Function`;let n=e.match(/(?:const|let)\s+(\w+)\s*=/);return n?n[1]:null}function ot(e){let t=e.trim().toLowerCase();return Ze.includes(t)?t:`text`}function Z(e){if(!e)return;let t=e.trim().toLowerCase().replace(/^\./,``).replace(/[,:;]+$/,``);switch(t){case`htm`:case`html`:return`html`;case`js`:case`mjs`:case`javascript`:return`javascript`;case`jsx`:case`tsx`:case`react`:return`react`;case`ts`:case`typescript`:return`typescript`;case`py`:case`python`:return`python`;case`css`:case`svg`:case`json`:return t;default:return t||void 0}}function st(e){let t=[],n=new RegExp(Ye),r;for(;(r=n.exec(e))!==null;){let n=r[1].trim(),i=ct(n,ut(e,r.index));t.push({raw:r[0],info:n,content:r[2].trim(),start:r.index,end:r.index+r[0].length,language:i.language,fileName:i.fileName})}return t}function ct(e,t){let n=lt(e)||t,r=e.split(/\s+/).filter(Boolean)[0]?.replace(/[{}[\]()]/g,``);return{language:(r&&!Xe.test(r)&&!r.includes(`=`)?Z(r):void 0)||Z(ft(n)),fileName:n}}function lt(e){let t=e.match(/(?:file(?:name)?|path|name)\s*=\s*["']?([^"'\s]+)["']?/i);if(t&&Xe.test(t[1]))return dt(t[1]);let n=e.match(Xe);return n?dt(n[0]):void 0}function ut(e,t){let n=e.slice(Math.max(0,t-180),t).split(`
|
|
1
|
+
import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{d as t,f as n}from"./markdown-core-fkbHPd-g.js";import{n as r}from"./react-vendor-Co1u1rWb.js";import{t as i}from"./useQuery-CXwvr2_e.js";import{t as a}from"./logger-BmpKNkls.js";import{A as o,At as s,Bt as c,C as l,Ct as u,D as d,G as f,H as p,Mt as m,N as h,Nt as g,P as _,Q as v,Rt as y,S as b,St as x,T as S,Tt as C,U as w,Vt as T,Y as E,Z as D,_t as O,a as k,c as A,ct as ee,d as j,dt as M,et as N,ft as P,h as te,ht as ne,i as F,lt as I,mt as re,n as L,o as ie,ot as ae,q as oe,r as se,st as ce,t as R,tt as z,ut as le,v as B,vt as ue,x as V,xt as de,y as fe,z as H}from"./ui-vendor-njo77ljx.js";import{n as pe}from"./demoMode-BhEpMVh5.js";import{a as me,c as he,d as ge,f as U,m as _e,n as ve,o as ye,s as be,u as xe}from"./api-Ddawdcbi.js";import{i as Se,n as Ce,r as we,t as W}from"./utils-BaPYjs_z.js";import{t as G}from"./Button-Cgmt_2gR.js";import{A as K,G as Te,K as Ee,P as q,S as J,W as De,_ as Oe,f as ke,h as Ae,m as je,v as Me,w as Ne,x as Pe,y as Fe}from"../assets/index-6X4Fay3z.js";import{a as Ie,i as Le}from"./artifactHtml-B7Oy2e__.js";import{t as Re}from"./ArtifactContainer-lBT2Cf0m.js";var ze=r(),Y=e(n(),1),X=t(),Be=({statistics:e,className:t=``})=>{let[n,r]=(0,Y.useState)(!1),{t:i}=q(),a=e=>{if(e==null)return`N/A`;let t=e/1e6;return t<1e3?`${Math.round(t)}ms`:`${(t/1e3).toFixed(2)}s`},o=e=>e?`${e.toFixed(1)} t/s`:`N/A`,s=e.prompt_eval_count||0,c=e.eval_count||0,l=s+c,u=a(e.total_duration),d=o(e.tokens_per_second);return(0,X.jsxs)(`div`,{className:`text-xs text-gray-500 dark:text-dark-500 mt-2 ${t}`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-4 mb-1`,children:[(0,X.jsxs)(`span`,{className:`flex items-center gap-1 text-gray-600 dark:text-dark-600`,children:[(0,X.jsx)(p,{size:12,className:`text-primary-500`}),c,` tokens`]}),(0,X.jsx)(`span`,{className:`text-gray-500 dark:text-dark-500`,children:d}),(0,X.jsx)(`span`,{className:`text-gray-500 dark:text-dark-500`,children:u}),e.model&&(0,X.jsx)(`span`,{className:`text-gray-400 dark:text-dark-400 bg-gray-100 dark:bg-dark-200 px-2 py-0.5 rounded-full truncate max-w-32 sm:max-w-48`,title:e.model,children:e.model})]}),(0,X.jsxs)(`button`,{onClick:()=>r(!n),className:`flex items-center gap-1 text-gray-400 dark:text-dark-400 hover:text-gray-600 dark:hover:text-dark-600 transition-colors`,children:[n?(0,X.jsx)(O,{size:12}):(0,X.jsx)(ne,{size:12}),(0,X.jsx)(`span`,{children:i(`generationStats.details`)})]}),n&&(0,X.jsxs)(`div`,{className:`mt-2 p-3 bg-gray-50 dark:bg-dark-100 border border-gray-200 dark:border-dark-300 rounded-lg text-xs space-y-2`,children:[(0,X.jsxs)(`div`,{className:`grid grid-cols-2 gap-x-4 gap-y-2`,children:[(0,X.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,X.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.promptTokens`)}),` `,s]}),(0,X.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,X.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.generatedTokens`)}),` `,c]}),(0,X.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,X.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.totalTokens`)}),` `,l]}),(0,X.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,X.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.speed`)}),` `,d]}),(0,X.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,X.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.promptEval`)}),` `,a(e.prompt_eval_duration)]}),(0,X.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,X.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.generation`)}),` `,a(e.eval_duration)]}),(0,X.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,X.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.modelLoad`)}),` `,a(e.load_duration)]}),(0,X.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,X.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.totalTime`)}),` `,u]})]}),e.created_at&&(0,X.jsxs)(`div`,{className:`pt-2 border-t border-gray-200 dark:border-dark-300 text-gray-600 dark:text-dark-600`,children:[(0,X.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.generatedAt`)}),` `,new Date(e.created_at).toLocaleTimeString()]})]})]})},Ve=a(`components:ttsbutton`),He=null,Ue=null,We=0,Ge=300*1e3;async function Ke(){let e=Date.now();return He!==null&&e-We<Ge?He:Ue||(Ue=(async()=>{try{let t=await ve.getModels();return t.success&&t.data&&t.data.length>0?(He=t.data,We=e,t.data):(He=[],We=e,[])}catch{return He=[],We=e,[]}finally{Ue=null}})(),Ue)}function qe(e){return e.split(/(?<=[.!?]["']?\s)|(?<=[.!?]["']?$)/).map(e=>e.trim()).filter(e=>e.length>0)}var Je=({text:e,className:t,size:n=`sm`})=>{let{t:r}=q(),{preferences:i}=Ne(),[a,o]=(0,Y.useState)(!1),[s,c]=(0,Y.useState)(!1),[l,u]=(0,Y.useState)(null),[d,f]=(0,Y.useState)([]),[p,m]=(0,Y.useState)(null),h=(0,Y.useRef)(null),_=(0,Y.useRef)(!1),v=(0,Y.useRef)([]),y=(0,Y.useRef)(0);(0,Y.useEffect)(()=>{let e=!0;return Ke().then(t=>{e&&(f(t),m(t.length>0))}),()=>{e=!1}},[]);let b=(0,Y.useCallback)(async(e,t,n,i)=>{let a=await ve.generateBase64({model:t,input:e,voice:n,speed:i,response_format:`mp3`});if(!a.success||!a.data?.audio)throw Error(a.message||r(`ttsButton.generateFailed`));let o=`data:${a.data.mimeType};base64,${a.data.audio}`,s=new Audio(o);return h.current=s,new Promise((e,t)=>{s.onended=()=>{h.current=null,e()},s.onerror=()=>{h.current=null,t(Error(r(`ttsButton.playbackFailed`)))},s.play().catch(t)})},[r]),x=(0,Y.useCallback)(async(e,t,n,r)=>{v.current=e,y.current=0,_.current=!1;let i=null,a=async e=>{try{let i=await ve.generateBase64({model:t,input:e,voice:n,speed:r,response_format:`mp3`});return!i.success||!i.data?.audio?null:{audioUrl:`data:${i.data.mimeType};base64,${i.data.audio}`,mimeType:i.data.mimeType}}catch{return null}};e.length>0&&(i=a(e[0]));for(let t=0;t<e.length&&!_.current;t++){y.current=t;try{let n=await i;if(_.current)break;if(i=t+1<e.length?a(e[t+1]):null,!n){Ve.warn(`Failed to generate audio for sentence ${t+1}, skipping`);continue}let r=new Audio(n.audioUrl);h.current=r,await new Promise((e,t)=>{r.onended=()=>{h.current=null,e()},r.onerror=()=>{h.current=null,e()},r.play().catch(()=>{e()})})}catch(e){Ve.error(`Error playing sentence ${t+1}:`,e)}}},[]),S=(0,Y.useCallback)(()=>{_.current=!0,h.current&&(h.current.pause(),h.current.currentTime=0,h.current=null),o(!1),c(!1)},[]),C=async()=>{if(!s){if(a){S();return}c(!0),u(null),_.current=!1;try{let t=i.ttsSettings,n=t?.model||d[0]?.model||`tts-1`,a=t?.voice||d[0]?.config?.default_voice||`alloy`,s=t?.speed||1;if(t?.streamSentences){let t=qe(e);if(t.length===0)throw Error(r(`ttsButton.generateFailed`));c(!1),o(!0),await x(t,n,a,s),_.current||o(!1)}else await b(e,n,a,s),c(!1),o(!0),h.current&&(h.current.onended=()=>{o(!1),h.current=null},h.current.onerror=()=>{u(r(`ttsButton.playbackFailed`)),o(!1),h.current=null})}catch(e){u(e instanceof Error?e.message:r(`ttsButton.generateFailed`)),Ve.error(`TTS error:`,e),o(!1),c(!1)}}};if((0,Y.useEffect)(()=>()=>{_.current=!0,h.current&&(h.current.pause(),h.current=null)},[]),p===!1||p===null)return null;let w={sm:`h-6 w-6 p-1`,md:`h-8 w-8 p-1.5`,lg:`h-10 w-10 p-2`},T={sm:`h-3.5 w-3.5`,md:`h-4 w-4`,lg:`h-5 w-5`};return(0,X.jsx)(`button`,{onClick:C,disabled:s||!e,title:l||r(a?`ttsButton.stopSpeaking`:s?`ttsButton.generatingSpeech`:`ttsButton.readAloud`),className:W(`rounded-full transition-all duration-200`,`hover:bg-gray-100 dark:hover:bg-dark-200`,`focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-1`,`disabled:opacity-50 disabled:cursor-not-allowed`,l?`text-red-500 dark:text-red-400`:a?`text-primary-600 dark:text-primary-400 bg-primary-50 dark:bg-primary-900/20`:`text-gray-500 dark:text-gray-400`,w[n],t),children:s?(0,X.jsx)(g,{className:W(T[n],`animate-spin`)}):a?(0,X.jsx)(te,{className:T[n]}):l?(0,X.jsx)(F,{className:T[n]}):(0,X.jsx)(k,{className:T[n]})})},Ye=/```([^\n`]*)\n([\s\S]*?)\n```/g,Xe=/[\w@./-]+\.(?:html?|css|mjs|js|jsx|ts|tsx|svg|json|py)/i,Ze=[`html`,`react`,`svg`,`mermaid`,`chart`,`code`,`text`,`json`],Qe=[{regex:/<artifact\s+type="([^"]+)"\s+title="([^"]+)"[^>]*>([\s\S]*?)<\/artifact>/gi,extract:e=>({type:ot(e[1]),title:$e(e[2]).trim()||`Artifact`,content:e[3].trim()})},{regex:/<artifact\s+type="([^"]+)"[^>]*>([\s\S]*?)<\/artifact>/gi,extract:e=>{let t=ot(e[1]);return{type:t,title:`${t.toUpperCase()} Artifact`,content:e[2].trim()}}}];function $e(e){if(typeof document<`u`){let t=document.createElement(`div`);return t.innerHTML=e,t.textContent||t.innerText||``}return tt(et(e))}function et(e){return e.replace(/&(lt|gt|quot|apos|#39);/gi,(e,t)=>{switch(t.toLowerCase()){case`lt`:return`<`;case`gt`:return`>`;case`quot`:return`"`;case`apos`:case`#39`:return`'`;default:return``}}).replace(/&/gi,`&`)}function tt(e){let t=``,n=!1,r=null;for(let i=0;i<e.length;i+=1){let a=e[i];if(n){if(r){a===r&&(r=null);continue}if(a===`"`||a===`'`){r=a;continue}a===`>`&&(n=!1);continue}if(a===`<`){let t=e[i+1];if(t&&/[!/A-Za-z?]/.test(t)){n=!0;continue}}t+=a}return t}function nt(e){let t=e.match(/<title[^>]*>([\s\S]*?)<\/title>/i);if(t)return $e(t[1]).trim()||null;let n=e.match(/<h1[^>]*>([\s\S]*?)<\/h1>/i);return n&&$e(n[1]).trim()||null}function rt(e){let t=e.match(/(?:function|const)\s+(\w+)/);if(t)return t[1];let n=e.match(/class\s+(\w+)/);return n?n[1]:null}function it(e){if(e.includes(`def main(`))return`Python Script`;let t=e.match(/class\s+(\w+)/);if(t)return`${t[1]} Class`;let n=e.match(/def\s+(\w+)/);return n&&n[1]!==`__init__`?`${n[1]} Function`:null}function at(e){let t=e.match(/function\s+(\w+)/);if(t)return`${t[1]} Function`;let n=e.match(/(?:const|let)\s+(\w+)\s*=/);return n?n[1]:null}function ot(e){let t=e.trim().toLowerCase();return Ze.includes(t)?t:`text`}function Z(e){if(!e)return;let t=e.trim().toLowerCase().replace(/^\./,``).replace(/[,:;]+$/,``);switch(t){case`htm`:case`html`:return`html`;case`js`:case`mjs`:case`javascript`:return`javascript`;case`jsx`:case`tsx`:case`react`:return`react`;case`ts`:case`typescript`:return`typescript`;case`py`:case`python`:return`python`;case`css`:case`svg`:case`json`:return t;default:return t||void 0}}function st(e){let t=[],n=new RegExp(Ye),r;for(;(r=n.exec(e))!==null;){let n=r[1].trim(),i=ct(n,ut(e,r.index));t.push({raw:r[0],info:n,content:r[2].trim(),start:r.index,end:r.index+r[0].length,language:i.language,fileName:i.fileName})}return t}function ct(e,t){let n=lt(e)||t,r=e.split(/\s+/).filter(Boolean)[0]?.replace(/[{}[\]()]/g,``);return{language:(r&&!Xe.test(r)&&!r.includes(`=`)?Z(r):void 0)||Z(ft(n)),fileName:n}}function lt(e){let t=e.match(/(?:file(?:name)?|path|name)\s*=\s*["']?([^"'\s]+)["']?/i);if(t&&Xe.test(t[1]))return dt(t[1]);let n=e.match(Xe);return n?dt(n[0]):void 0}function ut(e,t){let n=e.slice(Math.max(0,t-180),t).split(`
|
|
2
2
|
`).slice(-3).reverse();for(let e of n){let t=e.trim().replace(/^#{1,6}\s*/,``).replace(/^[-*]\s*/,``).replace(/[::]\s*$/,``).match(Xe);if(t)return dt(t[0])}}function dt(e){return e.replace(/^["'`]+|["'`:]+$/g,``)}function ft(e){return e?.match(/\.([a-z0-9]+)$/i)?.[1]}function pt(e){return e?.split(/[\\/]/).pop()}function Q(e){let t=pt(e);if(!t)return null;let n=t.replace(/\.[^.]+$/,``);return/^(index|main|app)$/i.test(n)?null:n.replace(/[-_]+/g,` `).replace(/\b\w/g,e=>e.toUpperCase())}function mt(e){let t=Date.now();return{...e,id:`artifact-${t}-${Math.random().toString(36).slice(2,11)}`,createdAt:t,updatedAt:t}}function ht(e){let t=Z(e.language)||Z(ft(e.fileName));switch(t){case`html`:return{type:`html`,title:nt(e.content)||Q(e.fileName)||`HTML Document`};case`svg`:return{type:`svg`,title:Q(e.fileName)||`SVG Image`};case`react`:return{type:`react`,title:rt(e.content)||Q(e.fileName)||`React Component`,language:`jsx`};case`json`:return{type:`json`,title:Q(e.fileName)||`JSON Data`};case`python`:return{type:`code`,title:it(e.content)||Q(e.fileName)||`Python Code`,language:`python`};case`css`:return{type:`code`,title:Q(e.fileName)||`CSS Styles`,language:`css`};case`javascript`:return{type:`code`,title:at(e.content)||Q(e.fileName)||`JavaScript Code`,language:`javascript`};case`typescript`:return{type:`code`,title:Q(e.fileName)||`TypeScript Code`,language:`typescript`};default:return t?{type:`code`,title:Q(e.fileName)||`${t.toUpperCase()} Code`,language:t}:null}}function gt(e){return(Z(e.language)||Z(ft(e.fileName)))===`html`}function _t(e){return(Z(e.language)||Z(ft(e.fileName)))===`css`}function vt(e){return(Z(e.language)||Z(ft(e.fileName)))===`javascript`}function yt(e){let t=st(e),n=t.filter(gt);if(n.length===0)return null;let r=t.filter(_t),i=t.filter(vt);if(r.length===0&&i.length===0)return null;let a=n.find(e=>/(^|[/\\])index\.html?$/i.test(e.fileName||``))||n[0],o=Ie(bt(a.content,r,i),r.map(e=>e.content),i.map(e=>e.content));return Tt(o,`html`)?{artifact:mt({type:`html`,title:nt(o)||Q(a.fileName)||`Interactive HTML App`,description:`Bundled generated HTML, CSS, and JavaScript files into one runnable artifact.`,content:o}),ranges:[a,...r,...i]}:null}function bt(e,t,n){let r=e;for(let e of t){let t=pt(e.fileName);t&&(r=r.replace(RegExp(`<link\\b[^>]*href=["'][^"']*${wt(t)}["'][^>]*>`,`gi`),``))}for(let e of n){let t=pt(e.fileName);t&&(r=r.replace(RegExp(`<script\\b[^>]*src=["'][^"']*${wt(t)}["'][^>]*>\\s*<\\/script>`,`gi`),``))}return r}function xt(e){let t=/<!doctype\s+html|<html[\s>]/i.exec(e);if(!t||t.index===void 0)return null;let n=st(e);if(St(t.index,n))return null;let r=t.index,i=/<\/html>/gi;i.lastIndex=r;let a=i.exec(e),o=a?a.index+a[0].length:e.length,s=e.slice(r,o).trim();return Tt(s,`html`)?{artifact:mt({type:`html`,title:nt(s)||`HTML Document`,content:s}),ranges:[{start:r,end:o}]}:null}function St(e,t){return t.some(t=>e>=t.start&&e<=t.end)}function Ct(e,t){return[...t].sort((e,t)=>t.start-e.start).reduce((e,t)=>`${e.slice(0,t.start)}${e.slice(t.end)}`,e)}function wt(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function Tt(e,t){if(t===`html`){let t=e.trim(),n=/<[^>]+>/.test(t),r=/<(canvas|script|style|button|form|input|select|textarea|video|audio)\b/i.test(t)||/\bon(?:click|input|submit|keydown|keyup|mousemove)=/i.test(t);return n&&(Le(t)||t.length>160||r)}if(t===`svg`)return/<svg[^>]*>/.test(e);if(t===`react`)return/<[A-Z][^>]*>/.test(e)||/return\s*\(/.test(e);if(t===`json`)try{return JSON.parse(e),e.trim().length>100}catch{return!1}if(t===`code`){let t=e.split(`
|
|
3
3
|
`).length,n=e.trim().length,r=/function|class|def |import |from |const |let |var |if |for |while |try |catch/.test(e);return(n>500||t>15)&&r}return e.trim().length>200}function Et(e){let t=[],n=e;for(let e of Qe){e.regex.lastIndex=0;let r=[],i;for(;(i=e.regex.exec(n))!==null;){let n=e.extract(i);Tt(n.content,n.type)&&(t.push(mt({type:n.type,title:n.title,content:n.content})),r.push({start:i.index,end:i.index+i[0].length}))}n=Ct(n,r)}let r=yt(n);for(;r;)t.push(r.artifact),n=Ct(n,r.ranges),r=yt(n);let i=xt(n);i&&(t.push(i.artifact),n=Ct(n,i.ranges));let a=st(n),o=[];for(let e of a){let n=ht(e);!n||!Tt(e.content,n.type)||(t.push(mt({type:n.type,title:n.title,content:e.content,language:n.language})),o.push(e))}return n=Ct(n,o),{content:n.trim(),artifacts:t}}var Dt=a(`components:chat-message`),Ot=({message:e,isStreaming:t=!1,className:n,isLastAssistantMessage:r=!1,onRegenerate:i})=>{let{t:a}=q(),o=e.role===`user`,s=e.role===`system`,{preferences:c}=Ne(),{user:u}=Pe(),{setSystemMessage:d,getCurrentPersona:f}=K(),p=f(),[h,g]=(0,Y.useState)(!1),[_,v]=(0,Y.useState)(e.content),[y,b]=(0,Y.useState)(null),[x,C]=(0,Y.useState)(!1),[w,T]=(0,Y.useState)(!1),[E,D]=(0,Y.useState)(!1),[k,A]=(0,Y.useState)(!1),[ee,j]=(0,Y.useState)(!1),M=(0,Y.useRef)(null),N=(0,Y.useRef)(t),P=(0,Y.useRef)(!1),te=async()=>{try{await navigator.clipboard.writeText(e.content),j(!0),setTimeout(()=>j(!1),2e3)}catch(e){Dt.error(`Failed to copy message:`,e)}},{thinkingContent:ne,parsedContent:F,artifacts:I}=(0,Y.useMemo)(()=>{if(o||s||!e.content)return{thinkingContent:null,parsedContent:e.content,artifacts:e.artifacts||[]};let n=Se(e.content),r=n.content;if(e.artifacts&&e.artifacts.length>0)return{thinkingContent:n.thinking,parsedContent:r,artifacts:e.artifacts};if(!t){let e=Et(r);return{thinkingContent:n.thinking,parsedContent:e.content,artifacts:e.artifacts}}return{thinkingContent:n.thinking,parsedContent:r,artifacts:[]}},[e.content,e.artifacts,o,s,t]);(0,Y.useEffect)(()=>{let e=N.current&&!t;return N.current=t,e&&!P.current&&!o&&!s&&F&&c.ttsSettings?.enabled&&c.ttsSettings?.autoPlay&&(P.current=!0,(async()=>{A(!0);try{let e=await ve.generateBase64({model:c.ttsSettings?.model||`tts-1`,input:F,voice:c.ttsSettings?.voice||`alloy`,speed:c.ttsSettings?.speed||1,response_format:`mp3`});if(e.success&&e.data?.audio){let t=`data:${e.data.mimeType};base64,${e.data.audio}`,n=new Audio(t);M.current=n,n.onended=()=>{A(!1),M.current=null},n.onerror=()=>{A(!1),M.current=null},await n.play()}}catch(e){Dt.error(`Auto-play TTS failed:`,e),A(!1)}})()),()=>{M.current&&(M.current.pause(),M.current=null)}},[t,o,s,F,c.ttsSettings]);let ie=()=>s?a(`chatMessage.system`):o?c.showUsername&&u?.username?u.username:a(`chatMessage.you`):p?.name?p.name:e.model||a(`chatMessage.assistant`),ae=()=>{g(!0),v(e.content)},oe=async()=>{C(!0);try{d(_),g(!1),Dt.debug(`✅ System message updated:`,_)}catch(e){Dt.error(`Failed to save system message:`,e)}finally{C(!1)}},se=()=>{g(!1),v(e.content)},ce=(e,t=100)=>e.length<=t?e:e.substring(0,t)+`...`,R=s&&e.content.length>100;return(0,X.jsxs)(`div`,{className:W(`group flex py-3 transition-colors sm:py-4`,o?`justify-end`:`justify-start`,n),children:[(0,X.jsx)(`div`,{className:W(`flex min-w-0`,o?`max-w-[88%] sm:max-w-[72%]`:`w-full`),children:(0,X.jsxs)(`div`,{className:W(`min-w-0 flex-1`,o?`rounded-[1.35rem] rounded-br-md border border-black/[0.06] bg-gray-900 px-4 py-3 text-white shadow-sm dark:border-white/[0.07] dark:bg-dark-300`:s?`bg-transparent py-2`:`bg-transparent py-1`),children:[!s&&(0,X.jsxs)(`div`,{className:W(`mb-2 flex items-center gap-2.5`,o&&`justify-end`),children:[(0,X.jsx)(`span`,{className:W(`text-[11px] font-semibold uppercase tracking-[0.1em]`,o?`text-white/70`:`text-gray-700 dark:text-dark-700`),children:ie()}),e.model&&!o&&p?.name&&(0,X.jsx)(`span`,{className:`max-w-32 truncate rounded-full bg-gray-100 px-2 py-0.5 text-[10px] text-gray-500 dark:bg-dark-200 dark:text-dark-600 sm:max-w-48`,title:e.model,children:e.model}),(0,X.jsx)(`span`,{className:W(`text-[10px] tabular-nums`,o?`text-white/45`:`text-gray-400 dark:text-dark-500`),children:Ce(e.timestamp)})]}),(0,X.jsxs)(`div`,{className:W(o?`text-[15px] text-white`:`text-[15px] leading-7 text-gray-800 dark:text-dark-800 sm:text-base`),children:[e.images&&e.images.length>0&&(0,X.jsx)(`div`,{className:`mb-3 grid max-w-lg grid-cols-2 gap-2 sm:grid-cols-3`,children:e.images.map((e,t)=>(0,X.jsx)(`div`,{className:`aspect-square overflow-hidden rounded-xl border border-white/10 bg-gray-100 dark:bg-gray-800`,children:(0,X.jsx)(`img`,{src:e,alt:`Uploaded image ${t+1}`,className:`w-full h-full object-cover cursor-pointer hover:opacity-90 transition-opacity`,onClick:()=>b(e)})},t))}),o?(0,X.jsx)(`p`,{className:`whitespace-pre-wrap leading-relaxed`,children:e.content}):s?(0,X.jsxs)(`div`,{className:`relative z-0 rounded-2xl border border-black/[0.06] bg-white/55 p-3 dark:border-white/[0.06] dark:bg-dark-200/45`,children:[(0,X.jsxs)(`div`,{className:`mb-2 flex items-center justify-between text-[10px] font-semibold uppercase tracking-[0.12em] text-gray-500 dark:text-dark-500`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,X.jsx)(B,{className:`h-2.5 w-2.5 opacity-50`}),a(`chatMessage.system`)]}),(0,X.jsx)(`div`,{className:`flex items-center gap-1`,children:h?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`button`,{onClick:oe,disabled:x,className:`rounded-lg p-1.5 transition-colors hover:bg-gray-100 disabled:opacity-50 dark:hover:bg-dark-300`,title:a(`chatMessage.saveChanges`),children:(0,X.jsx)(l,{className:`h-3 w-3 text-green-600 dark:text-green-400`})}),(0,X.jsx)(`button`,{onClick:se,disabled:x,className:`rounded-lg p-1.5 transition-colors hover:bg-gray-100 disabled:opacity-50 dark:hover:bg-dark-300`,title:a(`chatMessage.cancelEditing`),children:(0,X.jsx)(L,{className:`h-3 w-3 text-red-600 dark:text-red-400`})})]}):(0,X.jsx)(`button`,{onClick:ae,className:`rounded-lg p-1.5 transition-colors hover:bg-gray-100 dark:hover:bg-dark-300`,title:a(`chatMessage.editSystemMessage`),children:(0,X.jsx)(m,{className:`h-3 w-3 text-gray-600 dark:text-gray-400`})})})]}),h?(0,X.jsx)(`textarea`,{value:_,onChange:e=>v(e.target.value),className:`min-h-[100px] w-full resize-none rounded-xl border border-black/[0.08] bg-white p-3 text-sm text-gray-900 focus:border-transparent focus:outline-none focus:ring-2 focus:ring-primary-500 dark:border-white/[0.08] dark:bg-dark-100 dark:text-dark-900 dark:focus:ring-primary-400`,placeholder:a(`chatMessage.systemMessagePlaceholder`),disabled:x}):(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`p`,{className:`whitespace-pre-wrap text-xs leading-relaxed text-gray-500 dark:text-dark-600`,children:w?e.content:ce(e.content)}),R&&(0,X.jsx)(`button`,{onClick:()=>T(!w),className:`mt-2 flex items-center gap-1 text-xs text-gray-400 transition-colors hover:text-gray-900 dark:text-dark-500 dark:hover:text-dark-900`,children:w?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(re,{className:`h-3 w-3`}),a(`chatMessage.showLess`)]}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(O,{className:`h-3 w-3`}),a(`chatMessage.showMore`)]})})]})]}):(0,X.jsxs)(`div`,{className:`relative`,children:[ne&&(0,X.jsxs)(`div`,{className:`mb-4 border-l border-gray-200 pl-3 dark:border-dark-300`,children:[(0,X.jsxs)(`button`,{onClick:()=>D(!E),className:`flex items-center gap-2 text-xs text-gray-500 transition-colors hover:text-gray-900 dark:text-dark-600 dark:hover:text-dark-900`,children:[(0,X.jsx)(de,{className:`h-4 w-4`}),(0,X.jsx)(`span`,{className:`font-medium`,children:a(`chatMessage.thinking`)}),E?(0,X.jsx)(re,{className:`h-4 w-4`}):(0,X.jsx)(O,{className:`h-4 w-4`})]}),E&&(0,X.jsx)(`div`,{className:`mt-3 rounded-xl bg-gray-100/60 p-3 dark:bg-dark-200/60`,children:(0,X.jsx)(`p`,{className:`whitespace-pre-wrap text-sm leading-relaxed text-gray-600 dark:text-dark-700`,children:ne})})]}),(0,X.jsx)(ke,{content:F,isStreaming:t}),t&&!F.includes("```")&&(0,X.jsx)(`div`,{className:`ml-1 inline-block h-5 w-1 animate-pulse rounded-full bg-primary-500`})]}),!o&&!s&&I.length>0&&(0,X.jsx)(`div`,{className:`mt-4`,children:(0,X.jsx)(Re,{artifacts:I})}),!o&&!s&&e.statistics&&(0,X.jsx)(`div`,{className:`mt-3`,children:(0,X.jsx)(Be,{statistics:e.statistics})}),!s&&!t&&(0,X.jsxs)(`div`,{className:W(`mt-3 flex items-center gap-1`,o?`justify-end border-t border-white/10 pt-2 text-white/65`:`text-gray-400 dark:text-dark-500`),children:[!o&&F&&(0,X.jsx)(Je,{text:F,size:`sm`,className:W(`transition-colors`,k&&`bg-primary-50 text-primary-600 dark:bg-primary-900/20 dark:text-primary-400`)}),(0,X.jsx)(`button`,{onClick:te,className:W(`flex h-8 w-8 items-center justify-center rounded-full transition-colors`,o?`hover:bg-white/10 hover:text-white`:`hover:bg-gray-100 hover:text-gray-800 dark:hover:bg-dark-200 dark:hover:text-dark-800`),title:a(ee?`chatMessage.copied`:`chatMessage.copyMessage`),children:ee?(0,X.jsx)(ue,{className:`h-3.5 w-3.5 text-green-400`}):(0,X.jsx)(le,{className:`h-3.5 w-3.5`})}),!o&&r&&i&&(0,X.jsx)(`button`,{onClick:i,className:`flex h-8 w-8 items-center justify-center rounded-full transition-colors hover:bg-gray-100 hover:text-gray-800 dark:hover:bg-dark-200 dark:hover:text-dark-800`,title:a(`chatMessage.regenerateResponse`),children:(0,X.jsx)(S,{className:`h-3.5 w-3.5`})})]})]})]})}),y&&(0,ze.createPortal)((0,X.jsxs)(`div`,{role:`dialog`,"aria-modal":`true`,"aria-label":a(`chatMessage.fullSizeImage`),className:`fixed inset-0 z-[9999] flex items-center justify-center bg-black/85 p-6 backdrop-blur-md`,onClick:()=>b(null),children:[(0,X.jsx)(`button`,{className:`absolute right-6 top-6 rounded-full border border-white/15 bg-white/10 p-3 text-white transition-colors hover:bg-white/20`,onClick:e=>{e.stopPropagation(),b(null)},children:(0,X.jsx)(L,{className:`h-7 w-7`})}),(0,X.jsx)(`img`,{src:y,alt:a(`chatMessage.fullSizeImage`),className:`max-h-[90vh] max-w-[90vw] rounded-2xl object-contain shadow-2xl`,onClick:e=>e.stopPropagation()})]}),document.body)]})},kt=({messages:e,isStreaming:t=!1,streamingMessage:n,streamingMessageId:r,isLastAssistantMessage:i=!1,onRegenerate:a,onSelectBranch:o,className:s})=>{if(e.length===1){let o=e[0],c=t&&r===o.id;return(0,X.jsx)(Ot,{message:c&&n?{...o,content:n}:o,isStreaming:c,isLastAssistantMessage:i,onRegenerate:a,className:s})}return(0,X.jsxs)(`div`,{className:W(`relative py-2`,s),children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 pb-3 text-[10px] font-medium uppercase tracking-[0.12em] text-gray-400 dark:text-dark-500`,children:[(0,X.jsx)(D,{className:`h-3 w-3`}),(0,X.jsxs)(`span`,{children:[e.length,` variants`]})]}),(0,X.jsx)(`div`,{className:`grid grid-cols-1 gap-3 md:grid-cols-2`,children:e.map((e,s)=>{let c=e.isActive!==!1,l=t&&r===e.id,u=l&&n?{...e,content:n}:e;return(0,X.jsxs)(`div`,{className:W(`relative overflow-hidden rounded-2xl border bg-white/45 transition-colors duration-150 dark:bg-dark-200/35`,c||l?`border-primary-500/30 ring-1 ring-primary-500/10 dark:border-primary-400/30`:`border-black/[0.07] hover:bg-white/80 dark:border-white/[0.07] dark:hover:bg-dark-200/70`,!c&&!l&&`cursor-pointer`),role:!c&&!l?`button`:void 0,tabIndex:!c&&!l?0:void 0,onClick:()=>!c&&!l&&o?.(e.id),onKeyDown:t=>{!c&&!l&&(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),o?.(e.id))},children:[(0,X.jsxs)(`div`,{className:W(`flex items-center justify-between border-b px-3 py-2 text-[10px] font-medium uppercase tracking-[0.12em]`,c||l?`border-primary-500/10 bg-primary-50/50 text-primary-600 dark:border-primary-400/10 dark:bg-primary-900/10 dark:text-primary-400`:`border-black/[0.05] text-gray-400 dark:border-white/[0.05] dark:text-dark-500`),children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,X.jsx)(`span`,{className:`font-medium`,children:s+1}),l&&(0,X.jsx)(`span`,{className:`text-[10px] opacity-70 animate-pulse`,children:`generating...`})]}),c&&!l&&(0,X.jsx)(ue,{className:`h-3 w-3`}),!c&&!l&&(0,X.jsx)(`span`,{className:`text-[10px] opacity-50`,children:`select`})]}),(0,X.jsx)(`div`,{className:W(!c&&!l&&`opacity-75`),children:(0,X.jsx)(Ot,{message:u,isStreaming:l,isLastAssistantMessage:i&&(c||l),onRegenerate:c&&!t?a:void 0,className:`px-3 pb-3 !text-sm`})})]},e.id)})})]})},At={web_search:b,web_fetch:E,exec:j,browser:E,Read:z,Write:z,Edit:z,image:w,memory_search:ee,memory_get:ee,working:se,thinking:se,default:se},jt={web_search:`Searching the web`,web_fetch:`Fetching page`,exec:`Running command`,browser:`Using browser`,Read:`Reading file`,Write:`Writing file`,Edit:`Editing file`,image:`Analyzing image`,memory_search:`Searching memory`,memory_get:`Reading memory`,cron:`Managing schedule`,message:`Sending message`,tts:`Generating speech`,nodes:`Checking devices`,sessions_spawn:`Spawning agent`,canvas:`Rendering canvas`,process:`Managing process`,working:`Using tools`,thinking:`Thinking`},Mt=({tools:e,className:t})=>{if(e.length===0)return null;let n=e.filter(e=>e.phase!==`result`&&e.phase!==`done`);return n.length===0?null:(0,X.jsx)(`div`,{className:W(`flex flex-col gap-1 py-2 px-1`,t),children:n.map(e=>{let t=At[e.name]||At.default,n=jt[e.name]||`Using ${e.name}`,r=e.phase===`result`;return(0,X.jsxs)(`div`,{className:W(`flex items-center gap-2 text-sm transition-all duration-300`,r?`text-green-600 dark:text-green-400 opacity-60`:`text-gray-500 dark:text-gray-400`),children:[(0,X.jsx)(`div`,{className:W(`flex items-center justify-center w-5 h-5`,!r&&`animate-spin-slow`),children:(0,X.jsx)(t,{className:`h-3.5 w-3.5`})}),(0,X.jsx)(`span`,{className:`text-xs font-medium`,children:r?`✓ ${n}`:`${n}…`}),!r&&(0,X.jsxs)(`div`,{className:`flex gap-0.5`,children:[(0,X.jsx)(`div`,{className:`w-1 h-1 bg-current rounded-full animate-bounce`,style:{animationDelay:`0ms`}}),(0,X.jsx)(`div`,{className:`w-1 h-1 bg-current rounded-full animate-bounce`,style:{animationDelay:`150ms`}}),(0,X.jsx)(`div`,{className:`w-1 h-1 bg-current rounded-full animate-bounce`,style:{animationDelay:`300ms`}})]})]},e.toolCallId)})})};a(`components:chat-messages`);var Nt=({messages:e,streamingMessage:t,streamingMessageId:n,isStreaming:r=!1,toolActivities:i=[],className:a,onRegenerate:o,onSelectBranch:c})=>{let{t:l}=q(),u=(0,Y.useRef)(null),d=(0,Y.useRef)(),f=(0,Y.useRef)(null),p=(0,Y.useRef)(!1),[m,h]=(0,Y.useState)(!1),g=(0,Y.useMemo)(()=>{let t=[],n=new Set,r=[...e].sort((e,t)=>e.role===`system`&&t.role!==`system`?-1:t.role===`system`&&e.role!==`system`?1:e.parentId===t.parentId?(e.branchIndex||0)-(t.branchIndex||0):e.timestamp-t.timestamp);for(let i of r){if(n.has(i.id))continue;let r=i.parentId;if(r){let a=t.findIndex(e=>e.id===r);if(a>=0)t[a].messages.push(i);else{let a=e.find(e=>e.id===r);a&&!n.has(r)?(t.push({id:r,messages:[a,i],messageIndex:t.length}),n.add(r)):t.push({id:i.id,messages:[i],messageIndex:t.length})}n.add(i.id)}else{let r=e.filter(e=>e.parentId===i.id);r.length>0?(t.push({id:i.id,messages:[i,...r],messageIndex:t.length}),n.add(i.id),r.forEach(e=>n.add(e.id))):(t.push({id:i.id,messages:[i],messageIndex:t.length}),n.add(i.id))}}return t.sort((e,t)=>{let n=e.messages[0],r=t.messages[0];return n.role===`system`&&r.role!==`system`?-1:r.role===`system`&&n.role!==`system`?1:n.timestamp-r.timestamp})},[e]),_=(0,Y.useCallback)((e=!1)=>{p.current&&!e||u.current?.scrollIntoView({behavior:`smooth`})},[]),v=(0,Y.useCallback)(()=>{let t=f.current;if(!t)return;let{scrollTop:n,scrollHeight:r,clientHeight:i}=t,a=r-n-i<100;p.current=!a,h(!a&&e.length>0)},[e.length]),y=(0,Y.useRef)(e.length);if((0,Y.useEffect)(()=>{e.length>y.current&&!p.current&&_(),y.current=e.length},[e.length,_]),(0,Y.useEffect)(()=>{r&&t&&!p.current&&requestAnimationFrame(()=>{let e=f.current;e&&(e.scrollTop=e.scrollHeight)})},[r,t]),(0,Y.useEffect)(()=>{let e=d.current;return()=>{e&&clearTimeout(e)}},[]),e.length===0&&!r)return(0,X.jsx)(`div`,{className:W(`flex-1 flex items-center justify-center p-6 sm:p-10`,a),children:(0,X.jsxs)(`div`,{className:`max-w-sm text-center text-gray-500 dark:text-dark-600`,children:[(0,X.jsx)(`div`,{className:`mx-auto mb-5 flex h-11 w-11 items-center justify-center rounded-2xl border border-black/[0.06] bg-white/70 text-gray-500 shadow-sm dark:border-white/[0.07] dark:bg-dark-200/70 dark:text-dark-600`,children:(0,X.jsx)(s,{className:`h-4 w-4`})}),(0,X.jsx)(`h3`,{className:`mb-2 text-lg font-medium tracking-[-0.02em] text-gray-900 dark:text-dark-900 sm:text-xl`,children:l(`chatMessage.startConversation`)}),(0,X.jsx)(`p`,{className:`px-4 text-sm leading-relaxed`,children:l(`chatMessage.startConversationDescription`)})]})});let b=-1;for(let e=g.length-1;e>=0;e--)if(g[e].messages.some(e=>e.role===`assistant`)){b=e;break}return(0,X.jsxs)(`div`,{ref:f,onScroll:v,className:W(`relative flex-1 overflow-y-auto scrollbar-thin scrollbar-thumb-gray-300 dark:scrollbar-thumb-gray-600`,`scrollbar-track-transparent hover:scrollbar-thumb-gray-400 dark:hover:scrollbar-thumb-gray-500`,`overscroll-behavior-y-contain`,`[-webkit-overflow-scrolling:touch]`,a),style:{WebkitOverflowScrolling:`touch`,overscrollBehaviorY:`contain`,WebkitAppRegion:`no-drag`},children:[(0,X.jsxs)(`div`,{className:`mx-auto w-full min-w-0 max-w-4xl px-4 sm:px-6 md:px-8`,children:[g.map((e,i)=>{let a=i===b,s=r&&e.messages.some(e=>e.id===n);if(e.messages.length===1){let s=e.messages[0],c=r&&s.id===n;return(0,X.jsx)(Ot,{message:c&&t?{...s,content:t}:s,isStreaming:c,isLastAssistantMessage:a,onRegenerate:a?o:void 0,className:i===0?`mt-5 sm:mt-7`:``},s.id)}return(0,X.jsx)(kt,{messages:e.messages,isStreaming:s,streamingMessage:t,streamingMessageId:n||void 0,isLastAssistantMessage:a,onRegenerate:a?o:void 0,onSelectBranch:c,className:i===0?`mt-5 sm:mt-7`:``},e.id)}),r&&i.length>0&&(0,X.jsx)(Mt,{tools:i,className:`px-0`}),(0,X.jsx)(`div`,{ref:u,className:`h-4 sm:h-6`})]}),m&&(0,X.jsxs)(`button`,{onClick:()=>{p.current=!1,u.current?.scrollIntoView({behavior:`smooth`}),h(!1)},className:W(`absolute bottom-4 left-1/2 -translate-x-1/2 z-10`,`flex items-center justify-center gap-1.5`,`px-3.5 py-2 rounded-full`,`bg-white/90 dark:bg-dark-200/90`,`border border-black/[0.07] dark:border-white/[0.08]`,`shadow-[0_8px_28px_rgba(15,23,42,0.12)] backdrop-blur-xl`,`text-gray-600 dark:text-dark-600`,`hover:bg-white dark:hover:bg-dark-200`,`hover:text-gray-900 dark:hover:text-dark-800`,`transition-colors duration-150`),title:l(`chatMessage.scrollToBottom`),children:[(0,X.jsx)(C,{className:`h-4 w-4`}),(0,X.jsx)(`span`,{className:`text-xs font-medium`,children:l(`chatMessage.newMessages`)})]})]})};function Pt(e){let t=(e.match(/```/g)||[]).length,n=t%2==1,r=null;if(n){let t=e.lastIndexOf("```");if(t!==-1){let n=e.slice(t+3).match(/^(\w+)/);n&&(r=n[1])}}return{hasCodeBlocks:t>0,isInCodeBlock:n,language:r}}var Ft=Y.forwardRef(({value:e,onChange:t,className:n,placeholder:r,disabled:i,onKeyDown:a,...o},s)=>{let{hasCodeBlocks:c,isInCodeBlock:l,language:u}=(0,Y.useMemo)(()=>Pt(e),[e]);return(0,X.jsxs)(`div`,{className:`relative w-full`,children:[(0,X.jsx)(`textarea`,{ref:s,value:e,onChange:t,onKeyDown:a,placeholder:r,disabled:i,className:W(`w-full resize-none transition-all duration-200`,l&&[`font-mono text-[13px]`,`bg-gray-50 dark:bg-dark-100/50`,`rounded-lg`],n),...o}),c&&(0,X.jsx)(`div`,{className:`absolute right-0 top-0 pointer-events-none flex items-center gap-1`,children:(0,X.jsxs)(`div`,{className:W(`flex items-center gap-1 px-1.5 py-0.5 rounded-md text-[10px] font-medium`,`bg-gray-100 dark:bg-dark-200`,`text-gray-500 dark:text-gray-400`,`border border-gray-200/50 dark:border-dark-300/50`,l&&`animate-pulse`),children:[(0,X.jsx)(y,{className:`h-3 w-3`}),u&&(0,X.jsx)(`span`,{children:u}),!u&&l&&(0,X.jsx)(`span`,{children:`code`})]})})]})});Ft.displayName=`CodeAwareTextarea`;var It=a(`components:media-upload`),Lt=({images:e,onImagesChange:t,maxImages:n=5,sessionId:r,onDocumentUploaded:i,disabled:a=!1,className:o})=>{let{t:s}=q(),c=(0,Y.useRef)(null),[l,u]=(0,Y.useState)(!1),[d,f]=(0,Y.useState)(!1),[p,m]=(0,Y.useState)([]),h=async e=>{if(!(!e||a))for(let t=0;t<e.length;t++){let n=e[t];n.type.startsWith(`image/`)?await _(n):n.type.includes(`pdf`)||n.type.includes(`text`)?await v(n):T.error(`File type not supported: ${n.name}`)}},_=async r=>{if(n-e.length<=0){T.error(`Maximum ${n} images allowed`);return}if(r.size>10*1024*1024){T.error(`Image ${r.name} is too large (max 10MB)`);return}let i=new FileReader;i.onload=n=>{n.target?.result&&t([...e,n.target.result])},i.readAsDataURL(r)},v=async e=>{if(e.size>10*1024*1024){T.error(`File size must be less than 10MB`);return}f(!0);try{let t=await U.uploadDocument(e,r);if(t.success&&t.data){let n=t.data;m(e=>[...e,n]),i?.(n),T.success(`Document "${e.name}" uploaded`)}else T.error(t.error||`Failed to upload document`)}catch(e){It.error(`Document upload error:`,e),T.error(`Failed to upload document`)}finally{f(!1)}},y=e=>{e.preventDefault(),a||u(!0)},b=e=>{e.preventDefault(),u(!1)},x=e=>{e.preventDefault(),u(!1),a||h(e.dataTransfer.files)},S=n=>{t(e.filter((e,t)=>t!==n))},C=async e=>{try{let t=await U.deleteDocument(e);t.success?(m(t=>t.filter(t=>t.id!==e)),T.success(`Document removed`)):T.error(t.error||`Failed to remove document`)}catch(e){It.error(`Error removing document:`,e),T.error(`Failed to remove document`)}},w=e=>{if(e===0)return`0 B`;let t=1024,n=[`B`,`KB`,`MB`,`GB`],r=Math.floor(Math.log(e)/Math.log(t));return parseFloat((e/t**r).toFixed(1))+` `+n[r]},E=e.length>0||p.length>0;return(0,X.jsxs)(`div`,{className:W(`space-y-3`,o),children:[(0,X.jsxs)(`div`,{className:W(`border-2 border-dashed rounded-xl p-6 transition-all duration-200 cursor-pointer`,`border-gray-300 dark:border-gray-600`,`hover:border-primary-400 dark:hover:border-primary-500`,l&&`border-primary-500 dark:border-primary-400 bg-primary-50/50 dark:bg-primary-900/10`,a&&`opacity-50 cursor-not-allowed`),onDragOver:y,onDragLeave:b,onDrop:x,onClick:()=>!a&&c.current?.click(),children:[(0,X.jsx)(`input`,{ref:c,type:`file`,multiple:!0,accept:`image/*,.pdf,.txt`,onChange:e=>{h(e.target.files),e.target.value=``},className:`hidden`,disabled:a}),(0,X.jsxs)(`div`,{className:`flex flex-col items-center text-center`,children:[d?(0,X.jsx)(g,{className:`h-8 w-8 text-gray-400 dark:text-gray-500 mb-2 animate-spin`}):(0,X.jsx)(A,{className:`h-8 w-8 text-gray-400 dark:text-gray-500 mb-2`}),(0,X.jsxs)(`p`,{className:`text-sm text-gray-700 dark:text-gray-300`,children:[s(`chat.mediaUpload.dropImagesHere`),` `,(0,X.jsx)(`span`,{className:`text-primary-600 dark:text-primary-400 font-medium`,children:s(`chat.mediaUpload.browse`)})]}),(0,X.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 mt-1`,children:s(`chat.mediaUpload.supportedFormats`)})]})]}),E&&(0,X.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[e.map((e,t)=>(0,X.jsxs)(`div`,{className:`relative group w-16 h-16 rounded-lg overflow-hidden bg-gray-100 dark:bg-gray-800 border border-gray-200 dark:border-gray-700`,children:[(0,X.jsx)(`img`,{src:e,alt:`Upload ${t+1}`,className:`w-full h-full object-cover`}),(0,X.jsx)(`button`,{onClick:e=>{e.stopPropagation(),S(t)},className:`absolute top-0.5 right-0.5 p-0.5 rounded-full bg-black/60 hover:bg-black/80 text-white opacity-0 group-hover:opacity-100 transition-opacity`,children:(0,X.jsx)(L,{className:`h-3 w-3`})})]},`img-${t}`)),p.map(e=>(0,X.jsxs)(`div`,{className:`relative group flex items-center gap-2 px-3 py-2 rounded-lg bg-gray-100 dark:bg-gray-800 border border-gray-200 dark:border-gray-700`,children:[e.fileType===`pdf`?(0,X.jsx)(z,{className:`w-4 h-4 text-red-500 flex-shrink-0`}):(0,X.jsx)(N,{className:`w-4 h-4 text-blue-500 flex-shrink-0`}),(0,X.jsxs)(`div`,{className:`min-w-0`,children:[(0,X.jsx)(`p`,{className:`text-xs font-medium text-gray-900 dark:text-gray-100 truncate max-w-[100px]`,children:e.filename}),(0,X.jsx)(`p`,{className:`text-[10px] text-gray-500 dark:text-gray-400`,children:w(e.size)})]}),(0,X.jsx)(`button`,{onClick:t=>{t.stopPropagation(),C(e.id)},className:`p-0.5 rounded-full hover:bg-gray-200 dark:hover:bg-gray-700 text-gray-500 hover:text-red-500 transition-colors`,children:(0,X.jsx)(L,{className:`h-3 w-3`})})]},e.id))]})]})},Rt=a(`components:document-indicator`),zt=({sessionId:e,className:t=``})=>{let[n,r]=(0,Y.useState)([]);if((0,Y.useEffect)(()=>{e&&(async()=>{try{let t=await U.getDocuments(e);t.success&&t.data&&r(t.data)}catch(e){Rt.error(`Failed to load documents:`,e)}})()},[e]),!e||n.length===0)return null;let i=n.reduce((e,t)=>e+t.size,0);return(0,X.jsxs)(`div`,{className:`
|
|
4
4
|
inline-flex items-center space-x-1 px-2 py-1
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{d as t,f as n}from"./markdown-core-fkbHPd-g.js";import{t as r}from"./logger-BmpKNkls.js";import{Bt as i,Ot as a,V as o,Y as s,at as c,g as l,it as u,s as d,t as f,ut as p,vt as m,wt as h}from"./ui-vendor-njo77ljx.js";import{h as g}from"./api-D9FuobIF.js";import{P as _,n as v,t as y,x as b}from"../assets/index-pmlsmnQ4.js";var x=e(n(),1),S=t(),C=r(`components:first-time-setup`),w=({onComplete:e})=>{let{t}=_(),[n,r]=(0,x.useState)(`welcome`),[w,T]=(0,x.useState)(``),[E,D]=(0,x.useState)(``),[O,k]=(0,x.useState)(``),[A,j]=(0,x.useState)(!1),[M,N]=(0,x.useState)(!1),[P,F]=(0,x.useState)(!1),[I,L]=(0,x.useState)(null),[R,z]=(0,x.useState)(!1),[B,V]=(0,x.useState)(!1),[H,U]=(0,x.useState)(``),{login:W,systemInfo:G}=b(),K=G?.turnstile?.siteKey,q=!!(G?.turnstile?.enabled&&K),J=(0,x.useCallback)(e=>{U(e)},[]),Y=(0,x.useMemo)(()=>P||q&&!H,[P,q,H]);(0,x.useEffect)(()=>{n===`encryption-key`&&!I&&g.getEncryptionKey().then(e=>{e.success&&e.data&&L(e.data.encryptionKey)})},[n,I]);let X=async e=>{if(e.preventDefault(),!w.trim()||!E.trim()||!O.trim()){i.error(t(`setup.admin.fillAllFields`));return}if(E!==O){i.error(t(`auth.signup.passwordMismatch`));return}if(E.length<6){i.error(t(`auth.signup.passwordTooShort`));return}if(q&&!H){i.error(t(`auth.signup.tryAgain`));return}F(!0);try{let e=await g.signup({username:w,password:E,email:``,turnstileToken:H});e.success&&e.data?(W(e.data.user,e.data.token,e.data.systemInfo),i.success(t(`setup.admin.success`)),r(`encryption-key`)):i.error(e.message||t(`setup.admin.failed`))}catch(e){C.error(`Admin creation error:`,e),i.error(t(`setup.admin.failed`))}finally{U(``),F(!1)}},Z=async()=>{if(I)try{await navigator.clipboard.writeText(I),z(!0),i.success(t(`setup.encryptionKey.copied`)),setTimeout(()=>z(!1),3e3)}catch{i.error(t(`setup.encryptionKey.copyFailed`))}},Q=()=>{if(!B){i.error(t(`setup.encryptionKey.confirmRequired`));return}e?.()},$=e=>{if(e.key===`Enter`){let t=e.currentTarget.form;t&&t.requestSubmit()}};return n===`welcome`?(0,S.jsxs)(`div`,{className:`min-h-screen bg-gray-50 px-4 py-16 dark:bg-dark-50 sm:px-6 lg:flex lg:flex-col lg:justify-center lg:py-20`,children:[(0,S.jsx)(`div`,{className:`sm:mx-auto sm:w-full sm:max-w-md`,children:(0,S.jsx)(`div`,{className:`flex flex-col items-center`,children:(0,S.jsx)(v,{className:`text-gray-900 dark:text-gray-100`})})}),(0,S.jsx)(`div`,{className:`mt-10 sm:mx-auto sm:w-full sm:max-w-md`,children:(0,S.jsxs)(`div`,{className:`mx-auto w-full max-w-md rounded-2xl border border-gray-200/80 bg-white/80 p-6 shadow-sm backdrop-blur-xl dark:border-white/10 dark:bg-white/[0.04] sm:p-8`,children:[(0,S.jsxs)(`div`,{className:`mb-7 text-start`,children:[(0,S.jsx)(`h1`,{className:`mb-2 text-2xl font-normal tracking-[-0.03em] text-gray-950 dark:text-dark-950`,children:t(`setup.welcome.subtitle`)}),(0,S.jsx)(`p`,{className:`text-gray-600 dark:text-dark-500`,children:t(`setup.welcome.description`)})]}),(0,S.jsxs)(`div`,{className:`mb-7 divide-y divide-gray-200/70 border-y border-gray-200/70 dark:divide-white/[0.08] dark:border-white/[0.08]`,children:[(0,S.jsxs)(`div`,{className:`flex items-start gap-3 py-4`,children:[(0,S.jsx)(`div`,{className:`flex-shrink-0 mt-1`,children:(0,S.jsx)(l,{className:`h-5 w-5 text-primary-600 dark:text-primary-400`})}),(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`h3`,{className:`text-sm font-medium text-gray-900 dark:text-dark-950`,children:t(`setup.welcome.features.secure.title`)}),(0,S.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-dark-500`,children:t(`setup.welcome.features.secure.description`)})]})]}),(0,S.jsxs)(`div`,{className:`flex items-start gap-3 py-4`,children:[(0,S.jsx)(`div`,{className:`flex-shrink-0 mt-1`,children:(0,S.jsx)(f,{className:`h-5 w-5 text-primary-600 dark:text-primary-400`})}),(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`h3`,{className:`text-sm font-medium text-gray-900 dark:text-dark-950`,children:t(`setup.welcome.features.fast.title`)}),(0,S.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-dark-500`,children:t(`setup.welcome.features.fast.description`)})]})]}),(0,S.jsxs)(`div`,{className:`flex items-start gap-3 py-4`,children:[(0,S.jsx)(`div`,{className:`flex-shrink-0 mt-1`,children:(0,S.jsx)(s,{className:`h-5 w-5 text-primary-600 dark:text-primary-400`})}),(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`h3`,{className:`text-sm font-medium text-gray-900 dark:text-dark-950`,children:t(`setup.welcome.features.openSource.title`)}),(0,S.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-dark-500`,children:t(`setup.welcome.features.openSource.description`)})]})]})]}),(0,S.jsx)(`button`,{onClick:()=>r(`create-admin`),className:`flex min-h-11 w-full items-center justify-center rounded-xl border border-transparent bg-primary-600 px-4 py-2.5 text-sm font-medium text-white transition-colors duration-200 hover:bg-primary-700 focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-2`,children:(0,S.jsxs)(`div`,{className:`flex items-center`,children:[(0,S.jsx)(`span`,{children:t(`setup.welcome.createAdmin`)}),(0,S.jsx)(h,{size:16,className:`ms-2 rtl:rotate-180`})]})})]})})]}):n===`encryption-key`?(0,S.jsxs)(`div`,{className:`min-h-screen bg-gray-50 px-4 py-16 dark:bg-dark-50 sm:px-6 lg:flex lg:flex-col lg:justify-center lg:py-20`,children:[(0,S.jsxs)(`div`,{className:`sm:mx-auto sm:w-full sm:max-w-md`,children:[(0,S.jsx)(`div`,{className:`flex flex-col items-center`,children:(0,S.jsx)(v,{className:`text-gray-900 dark:text-gray-100`})}),(0,S.jsx)(`h2`,{className:`mt-8 text-center text-3xl font-light tracking-[-0.035em] text-gray-950 dark:text-dark-950`,children:t(`setup.encryptionKey.title`)})]}),(0,S.jsx)(`div`,{className:`mt-10 sm:mx-auto sm:w-full sm:max-w-lg`,children:(0,S.jsxs)(`div`,{className:`mx-auto w-full max-w-lg rounded-2xl border border-gray-200/80 bg-white/80 p-6 shadow-sm backdrop-blur-xl dark:border-white/10 dark:bg-white/[0.04] sm:p-8`,children:[(0,S.jsxs)(`div`,{className:`mb-7 text-start`,children:[(0,S.jsx)(`div`,{className:`flex justify-center mb-4`,children:(0,S.jsx)(`div`,{className:`rounded-xl border border-amber-200 bg-amber-50 p-3 dark:border-amber-800/60 dark:bg-amber-900/20`,children:(0,S.jsx)(o,{className:`h-8 w-8 text-amber-600 dark:text-amber-400`})})}),(0,S.jsx)(`h1`,{className:`mb-2 text-2xl font-normal tracking-[-0.03em] text-gray-950 dark:text-dark-950`,children:t(`setup.encryptionKey.subtitle`)}),(0,S.jsx)(`p`,{className:`text-gray-600 dark:text-dark-500`,children:t(`setup.encryptionKey.description`)})]}),(0,S.jsx)(`div`,{className:`mb-6 rounded-xl border border-amber-200 bg-amber-50/70 p-4 dark:border-amber-800/60 dark:bg-amber-900/15`,children:(0,S.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,S.jsx)(a,{className:`h-5 w-5 text-amber-600 dark:text-amber-400 flex-shrink-0 mt-0.5`}),(0,S.jsxs)(`div`,{className:`text-sm text-amber-800 dark:text-amber-200`,children:[(0,S.jsx)(`p`,{className:`font-medium mb-1`,children:t(`setup.encryptionKey.warning`)}),(0,S.jsx)(`p`,{children:t(`setup.encryptionKey.warningText`)})]})]})}),(0,S.jsxs)(`div`,{className:`mb-6`,children:[(0,S.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-dark-700 mb-2`,children:t(`setup.encryptionKey.label`)}),(0,S.jsxs)(`div`,{className:`relative`,children:[(0,S.jsx)(`div`,{className:`w-full break-all rounded-xl border border-gray-200 bg-gray-50 px-3 py-3 pe-12 font-mono text-sm text-gray-900 dark:border-white/10 dark:bg-white/[0.035] dark:text-dark-800`,children:I||t(`setup.encryptionKey.loading`)}),(0,S.jsx)(`button`,{type:`button`,onClick:Z,disabled:!I,className:`absolute end-2 top-1/2 -translate-y-1/2 p-2 text-gray-500 hover:text-gray-700 disabled:opacity-50 dark:text-dark-500 dark:hover:text-dark-700`,title:t(`setup.encryptionKey.copyToClipboard`),children:R?(0,S.jsx)(m,{className:`h-5 w-5 text-green-500`}):(0,S.jsx)(p,{className:`h-5 w-5`})})]}),(0,S.jsx)(`p`,{className:`mt-2 text-xs text-gray-500 dark:text-dark-500`,children:t(`setup.encryptionKey.envNote`)})]}),(0,S.jsx)(`div`,{className:`mb-6`,children:(0,S.jsxs)(`label`,{className:`flex cursor-pointer items-start gap-3`,children:[(0,S.jsx)(`input`,{type:`checkbox`,checked:B,onChange:e=>V(e.target.checked),className:`mt-1 h-4 w-4 text-primary-600 focus:ring-primary-500 border-gray-300 dark:border-dark-300 rounded`}),(0,S.jsx)(`span`,{className:`text-sm text-gray-700 dark:text-dark-700`,children:t(`setup.encryptionKey.acknowledgment`)})]})}),(0,S.jsx)(`button`,{onClick:Q,disabled:!B,className:`flex min-h-11 w-full items-center justify-center rounded-xl border border-transparent bg-primary-600 px-4 py-2.5 text-sm font-medium text-white transition-colors duration-200 hover:bg-primary-700 focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50`,children:(0,S.jsxs)(`div`,{className:`flex items-center`,children:[(0,S.jsx)(`span`,{children:t(`setup.encryptionKey.continue`)}),(0,S.jsx)(h,{size:16,className:`ms-2 rtl:rotate-180`})]})})]})})]}):(0,S.jsxs)(`div`,{className:`min-h-screen bg-gray-50 px-4 py-16 dark:bg-dark-50 sm:px-6 lg:flex lg:flex-col lg:justify-center lg:py-20`,children:[(0,S.jsxs)(`div`,{className:`sm:mx-auto sm:w-full sm:max-w-md`,children:[(0,S.jsx)(`div`,{className:`flex flex-col items-center`,children:(0,S.jsx)(v,{className:`text-gray-900 dark:text-gray-100`})}),(0,S.jsx)(`h2`,{className:`mt-8 text-center text-3xl font-light tracking-[-0.035em] text-gray-950 dark:text-dark-950`,children:t(`setup.admin.title`)})]}),(0,S.jsx)(`div`,{className:`mt-10 sm:mx-auto sm:w-full sm:max-w-md`,children:(0,S.jsxs)(`div`,{className:`mx-auto w-full max-w-md rounded-2xl border border-gray-200/80 bg-white/80 p-6 shadow-sm backdrop-blur-xl dark:border-white/10 dark:bg-white/[0.04] sm:p-8`,children:[(0,S.jsxs)(`div`,{className:`mb-7 text-start`,children:[(0,S.jsx)(`h1`,{className:`mb-2 text-2xl font-normal tracking-[-0.03em] text-gray-950 dark:text-dark-950`,children:t(`setup.admin.subtitle`)}),(0,S.jsx)(`p`,{className:`text-gray-600 dark:text-dark-500`,children:t(`setup.admin.description`)})]}),(0,S.jsxs)(`form`,{onSubmit:X,className:`space-y-4`,children:[(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`label`,{htmlFor:`username`,className:`block text-sm font-medium text-gray-700 dark:text-dark-700 mb-2`,children:t(`auth.login.username`)}),(0,S.jsx)(`input`,{id:`username`,type:`text`,value:w,onChange:e=>T(e.target.value),onKeyDown:$,className:`w-full rounded-xl border border-gray-200 bg-white/80 px-3 py-2.5 text-gray-900 transition-colors duration-200 focus:border-primary-500 focus:outline-none focus:ring-2 focus:ring-primary-500/20 dark:border-white/10 dark:bg-white/[0.04] dark:text-dark-800`,placeholder:t(`setup.admin.usernamePlaceholder`),required:!0,disabled:P})]}),(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`label`,{htmlFor:`password`,className:`block text-sm font-medium text-gray-700 dark:text-dark-700 mb-2`,children:t(`auth.login.password`)}),(0,S.jsxs)(`div`,{className:`relative`,children:[(0,S.jsx)(`input`,{id:`password`,type:A?`text`:`password`,value:E,onChange:e=>D(e.target.value),onKeyDown:$,className:`w-full rounded-xl border border-gray-200 bg-white/80 px-3 py-2.5 pe-10 text-gray-900 transition-colors duration-200 focus:border-primary-500 focus:outline-none focus:ring-2 focus:ring-primary-500/20 dark:border-white/10 dark:bg-white/[0.04] dark:text-dark-800`,placeholder:t(`setup.admin.passwordPlaceholder`),required:!0,disabled:P}),(0,S.jsx)(`button`,{type:`button`,onClick:()=>j(!A),className:`absolute inset-y-0 end-0 flex items-center pe-3 text-gray-400 hover:text-gray-600 dark:text-dark-500 dark:hover:text-dark-700`,disabled:P,children:A?(0,S.jsx)(u,{size:20}):(0,S.jsx)(c,{size:20})})]})]}),(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`label`,{htmlFor:`confirmPassword`,className:`block text-sm font-medium text-gray-700 dark:text-dark-700 mb-2`,children:t(`auth.signup.confirmPassword`)}),(0,S.jsxs)(`div`,{className:`relative`,children:[(0,S.jsx)(`input`,{id:`confirmPassword`,type:M?`text`:`password`,value:O,onChange:e=>k(e.target.value),onKeyDown:$,className:`w-full rounded-xl border border-gray-200 bg-white/80 px-3 py-2.5 pe-10 text-gray-900 transition-colors duration-200 focus:border-primary-500 focus:outline-none focus:ring-2 focus:ring-primary-500/20 dark:border-white/10 dark:bg-white/[0.04] dark:text-dark-800`,placeholder:t(`setup.admin.confirmPlaceholder`),required:!0,disabled:P}),(0,S.jsx)(`button`,{type:`button`,onClick:()=>N(!M),className:`absolute inset-y-0 end-0 flex items-center pe-3 text-gray-400 hover:text-gray-600 dark:text-dark-500 dark:hover:text-dark-700`,disabled:P,children:M?(0,S.jsx)(u,{size:20}):(0,S.jsx)(c,{size:20})})]})]}),q&&K&&(0,S.jsx)(y,{siteKey:K,disabled:P,errorMessage:t(`auth.signup.tryAgain`),onTokenChange:J}),(0,S.jsxs)(`div`,{className:`flex gap-3`,children:[(0,S.jsx)(`button`,{type:`button`,onClick:()=>r(`welcome`),disabled:P,className:`min-h-11 flex-1 rounded-xl border border-gray-200 bg-transparent px-4 py-2.5 text-sm font-medium text-gray-700 transition-colors duration-200 hover:bg-gray-100 focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 dark:border-white/10 dark:text-dark-700 dark:hover:bg-white/[0.06]`,children:t(`common.back`)}),(0,S.jsx)(`button`,{type:`submit`,disabled:Y,className:`flex min-h-11 flex-1 items-center justify-center rounded-xl border border-transparent bg-primary-600 px-4 py-2.5 text-sm font-medium text-white transition-colors duration-200 hover:bg-primary-700 focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50`,children:P?(0,S.jsxs)(`div`,{className:`flex items-center`,children:[(0,S.jsx)(`div`,{className:`me-2 h-4 w-4 animate-spin rounded-full border-b-2 border-white`}),t(`setup.admin.creating`)]}):(0,S.jsxs)(`div`,{className:`flex items-center`,children:[(0,S.jsx)(d,{size:16,className:`me-2`}),t(`setup.admin.createAdmin`)]})})]})]}),(0,S.jsx)(`div`,{className:`mt-6 text-center`,children:(0,S.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-dark-500`,children:t(`setup.admin.note`)})})]})})]})};export{w as FirstTimeSetup};
|
|
1
|
+
import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{d as t,f as n}from"./markdown-core-fkbHPd-g.js";import{t as r}from"./logger-BmpKNkls.js";import{Bt as i,Ot as a,V as o,Y as s,at as c,g as l,it as u,s as d,t as f,ut as p,vt as m,wt as h}from"./ui-vendor-njo77ljx.js";import{h as g}from"./api-Ddawdcbi.js";import{P as _,n as v,t as y,x as b}from"../assets/index-6X4Fay3z.js";var x=e(n(),1),S=t(),C=r(`components:first-time-setup`),w=({onComplete:e})=>{let{t}=_(),[n,r]=(0,x.useState)(`welcome`),[w,T]=(0,x.useState)(``),[E,D]=(0,x.useState)(``),[O,k]=(0,x.useState)(``),[A,j]=(0,x.useState)(!1),[M,N]=(0,x.useState)(!1),[P,F]=(0,x.useState)(!1),[I,L]=(0,x.useState)(null),[R,z]=(0,x.useState)(!1),[B,V]=(0,x.useState)(!1),[H,U]=(0,x.useState)(``),{login:W,systemInfo:G}=b(),K=G?.turnstile?.siteKey,q=!!(G?.turnstile?.enabled&&K),J=(0,x.useCallback)(e=>{U(e)},[]),Y=(0,x.useMemo)(()=>P||q&&!H,[P,q,H]);(0,x.useEffect)(()=>{n===`encryption-key`&&!I&&g.getEncryptionKey().then(e=>{e.success&&e.data&&L(e.data.encryptionKey)})},[n,I]);let X=async e=>{if(e.preventDefault(),!w.trim()||!E.trim()||!O.trim()){i.error(t(`setup.admin.fillAllFields`));return}if(E!==O){i.error(t(`auth.signup.passwordMismatch`));return}if(E.length<6){i.error(t(`auth.signup.passwordTooShort`));return}if(q&&!H){i.error(t(`auth.signup.tryAgain`));return}F(!0);try{let e=await g.signup({username:w,password:E,email:``,turnstileToken:H});e.success&&e.data?(W(e.data.user,e.data.token,e.data.systemInfo),i.success(t(`setup.admin.success`)),r(`encryption-key`)):i.error(e.message||t(`setup.admin.failed`))}catch(e){C.error(`Admin creation error:`,e),i.error(t(`setup.admin.failed`))}finally{U(``),F(!1)}},Z=async()=>{if(I)try{await navigator.clipboard.writeText(I),z(!0),i.success(t(`setup.encryptionKey.copied`)),setTimeout(()=>z(!1),3e3)}catch{i.error(t(`setup.encryptionKey.copyFailed`))}},Q=()=>{if(!B){i.error(t(`setup.encryptionKey.confirmRequired`));return}e?.()},$=e=>{if(e.key===`Enter`){let t=e.currentTarget.form;t&&t.requestSubmit()}};return n===`welcome`?(0,S.jsxs)(`div`,{className:`min-h-screen bg-gray-50 px-4 py-16 dark:bg-dark-50 sm:px-6 lg:flex lg:flex-col lg:justify-center lg:py-20`,children:[(0,S.jsx)(`div`,{className:`sm:mx-auto sm:w-full sm:max-w-md`,children:(0,S.jsx)(`div`,{className:`flex flex-col items-center`,children:(0,S.jsx)(v,{className:`text-gray-900 dark:text-gray-100`})})}),(0,S.jsx)(`div`,{className:`mt-10 sm:mx-auto sm:w-full sm:max-w-md`,children:(0,S.jsxs)(`div`,{className:`mx-auto w-full max-w-md rounded-2xl border border-gray-200/80 bg-white/80 p-6 shadow-sm backdrop-blur-xl dark:border-white/10 dark:bg-white/[0.04] sm:p-8`,children:[(0,S.jsxs)(`div`,{className:`mb-7 text-start`,children:[(0,S.jsx)(`h1`,{className:`mb-2 text-2xl font-normal tracking-[-0.03em] text-gray-950 dark:text-dark-950`,children:t(`setup.welcome.subtitle`)}),(0,S.jsx)(`p`,{className:`text-gray-600 dark:text-dark-500`,children:t(`setup.welcome.description`)})]}),(0,S.jsxs)(`div`,{className:`mb-7 divide-y divide-gray-200/70 border-y border-gray-200/70 dark:divide-white/[0.08] dark:border-white/[0.08]`,children:[(0,S.jsxs)(`div`,{className:`flex items-start gap-3 py-4`,children:[(0,S.jsx)(`div`,{className:`flex-shrink-0 mt-1`,children:(0,S.jsx)(l,{className:`h-5 w-5 text-primary-600 dark:text-primary-400`})}),(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`h3`,{className:`text-sm font-medium text-gray-900 dark:text-dark-950`,children:t(`setup.welcome.features.secure.title`)}),(0,S.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-dark-500`,children:t(`setup.welcome.features.secure.description`)})]})]}),(0,S.jsxs)(`div`,{className:`flex items-start gap-3 py-4`,children:[(0,S.jsx)(`div`,{className:`flex-shrink-0 mt-1`,children:(0,S.jsx)(f,{className:`h-5 w-5 text-primary-600 dark:text-primary-400`})}),(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`h3`,{className:`text-sm font-medium text-gray-900 dark:text-dark-950`,children:t(`setup.welcome.features.fast.title`)}),(0,S.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-dark-500`,children:t(`setup.welcome.features.fast.description`)})]})]}),(0,S.jsxs)(`div`,{className:`flex items-start gap-3 py-4`,children:[(0,S.jsx)(`div`,{className:`flex-shrink-0 mt-1`,children:(0,S.jsx)(s,{className:`h-5 w-5 text-primary-600 dark:text-primary-400`})}),(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`h3`,{className:`text-sm font-medium text-gray-900 dark:text-dark-950`,children:t(`setup.welcome.features.openSource.title`)}),(0,S.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-dark-500`,children:t(`setup.welcome.features.openSource.description`)})]})]})]}),(0,S.jsx)(`button`,{onClick:()=>r(`create-admin`),className:`flex min-h-11 w-full items-center justify-center rounded-xl border border-transparent bg-primary-600 px-4 py-2.5 text-sm font-medium text-white transition-colors duration-200 hover:bg-primary-700 focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-2`,children:(0,S.jsxs)(`div`,{className:`flex items-center`,children:[(0,S.jsx)(`span`,{children:t(`setup.welcome.createAdmin`)}),(0,S.jsx)(h,{size:16,className:`ms-2 rtl:rotate-180`})]})})]})})]}):n===`encryption-key`?(0,S.jsxs)(`div`,{className:`min-h-screen bg-gray-50 px-4 py-16 dark:bg-dark-50 sm:px-6 lg:flex lg:flex-col lg:justify-center lg:py-20`,children:[(0,S.jsxs)(`div`,{className:`sm:mx-auto sm:w-full sm:max-w-md`,children:[(0,S.jsx)(`div`,{className:`flex flex-col items-center`,children:(0,S.jsx)(v,{className:`text-gray-900 dark:text-gray-100`})}),(0,S.jsx)(`h2`,{className:`mt-8 text-center text-3xl font-light tracking-[-0.035em] text-gray-950 dark:text-dark-950`,children:t(`setup.encryptionKey.title`)})]}),(0,S.jsx)(`div`,{className:`mt-10 sm:mx-auto sm:w-full sm:max-w-lg`,children:(0,S.jsxs)(`div`,{className:`mx-auto w-full max-w-lg rounded-2xl border border-gray-200/80 bg-white/80 p-6 shadow-sm backdrop-blur-xl dark:border-white/10 dark:bg-white/[0.04] sm:p-8`,children:[(0,S.jsxs)(`div`,{className:`mb-7 text-start`,children:[(0,S.jsx)(`div`,{className:`flex justify-center mb-4`,children:(0,S.jsx)(`div`,{className:`rounded-xl border border-amber-200 bg-amber-50 p-3 dark:border-amber-800/60 dark:bg-amber-900/20`,children:(0,S.jsx)(o,{className:`h-8 w-8 text-amber-600 dark:text-amber-400`})})}),(0,S.jsx)(`h1`,{className:`mb-2 text-2xl font-normal tracking-[-0.03em] text-gray-950 dark:text-dark-950`,children:t(`setup.encryptionKey.subtitle`)}),(0,S.jsx)(`p`,{className:`text-gray-600 dark:text-dark-500`,children:t(`setup.encryptionKey.description`)})]}),(0,S.jsx)(`div`,{className:`mb-6 rounded-xl border border-amber-200 bg-amber-50/70 p-4 dark:border-amber-800/60 dark:bg-amber-900/15`,children:(0,S.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,S.jsx)(a,{className:`h-5 w-5 text-amber-600 dark:text-amber-400 flex-shrink-0 mt-0.5`}),(0,S.jsxs)(`div`,{className:`text-sm text-amber-800 dark:text-amber-200`,children:[(0,S.jsx)(`p`,{className:`font-medium mb-1`,children:t(`setup.encryptionKey.warning`)}),(0,S.jsx)(`p`,{children:t(`setup.encryptionKey.warningText`)})]})]})}),(0,S.jsxs)(`div`,{className:`mb-6`,children:[(0,S.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-dark-700 mb-2`,children:t(`setup.encryptionKey.label`)}),(0,S.jsxs)(`div`,{className:`relative`,children:[(0,S.jsx)(`div`,{className:`w-full break-all rounded-xl border border-gray-200 bg-gray-50 px-3 py-3 pe-12 font-mono text-sm text-gray-900 dark:border-white/10 dark:bg-white/[0.035] dark:text-dark-800`,children:I||t(`setup.encryptionKey.loading`)}),(0,S.jsx)(`button`,{type:`button`,onClick:Z,disabled:!I,className:`absolute end-2 top-1/2 -translate-y-1/2 p-2 text-gray-500 hover:text-gray-700 disabled:opacity-50 dark:text-dark-500 dark:hover:text-dark-700`,title:t(`setup.encryptionKey.copyToClipboard`),children:R?(0,S.jsx)(m,{className:`h-5 w-5 text-green-500`}):(0,S.jsx)(p,{className:`h-5 w-5`})})]}),(0,S.jsx)(`p`,{className:`mt-2 text-xs text-gray-500 dark:text-dark-500`,children:t(`setup.encryptionKey.envNote`)})]}),(0,S.jsx)(`div`,{className:`mb-6`,children:(0,S.jsxs)(`label`,{className:`flex cursor-pointer items-start gap-3`,children:[(0,S.jsx)(`input`,{type:`checkbox`,checked:B,onChange:e=>V(e.target.checked),className:`mt-1 h-4 w-4 text-primary-600 focus:ring-primary-500 border-gray-300 dark:border-dark-300 rounded`}),(0,S.jsx)(`span`,{className:`text-sm text-gray-700 dark:text-dark-700`,children:t(`setup.encryptionKey.acknowledgment`)})]})}),(0,S.jsx)(`button`,{onClick:Q,disabled:!B,className:`flex min-h-11 w-full items-center justify-center rounded-xl border border-transparent bg-primary-600 px-4 py-2.5 text-sm font-medium text-white transition-colors duration-200 hover:bg-primary-700 focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50`,children:(0,S.jsxs)(`div`,{className:`flex items-center`,children:[(0,S.jsx)(`span`,{children:t(`setup.encryptionKey.continue`)}),(0,S.jsx)(h,{size:16,className:`ms-2 rtl:rotate-180`})]})})]})})]}):(0,S.jsxs)(`div`,{className:`min-h-screen bg-gray-50 px-4 py-16 dark:bg-dark-50 sm:px-6 lg:flex lg:flex-col lg:justify-center lg:py-20`,children:[(0,S.jsxs)(`div`,{className:`sm:mx-auto sm:w-full sm:max-w-md`,children:[(0,S.jsx)(`div`,{className:`flex flex-col items-center`,children:(0,S.jsx)(v,{className:`text-gray-900 dark:text-gray-100`})}),(0,S.jsx)(`h2`,{className:`mt-8 text-center text-3xl font-light tracking-[-0.035em] text-gray-950 dark:text-dark-950`,children:t(`setup.admin.title`)})]}),(0,S.jsx)(`div`,{className:`mt-10 sm:mx-auto sm:w-full sm:max-w-md`,children:(0,S.jsxs)(`div`,{className:`mx-auto w-full max-w-md rounded-2xl border border-gray-200/80 bg-white/80 p-6 shadow-sm backdrop-blur-xl dark:border-white/10 dark:bg-white/[0.04] sm:p-8`,children:[(0,S.jsxs)(`div`,{className:`mb-7 text-start`,children:[(0,S.jsx)(`h1`,{className:`mb-2 text-2xl font-normal tracking-[-0.03em] text-gray-950 dark:text-dark-950`,children:t(`setup.admin.subtitle`)}),(0,S.jsx)(`p`,{className:`text-gray-600 dark:text-dark-500`,children:t(`setup.admin.description`)})]}),(0,S.jsxs)(`form`,{onSubmit:X,className:`space-y-4`,children:[(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`label`,{htmlFor:`username`,className:`block text-sm font-medium text-gray-700 dark:text-dark-700 mb-2`,children:t(`auth.login.username`)}),(0,S.jsx)(`input`,{id:`username`,type:`text`,value:w,onChange:e=>T(e.target.value),onKeyDown:$,className:`w-full rounded-xl border border-gray-200 bg-white/80 px-3 py-2.5 text-gray-900 transition-colors duration-200 focus:border-primary-500 focus:outline-none focus:ring-2 focus:ring-primary-500/20 dark:border-white/10 dark:bg-white/[0.04] dark:text-dark-800`,placeholder:t(`setup.admin.usernamePlaceholder`),required:!0,disabled:P})]}),(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`label`,{htmlFor:`password`,className:`block text-sm font-medium text-gray-700 dark:text-dark-700 mb-2`,children:t(`auth.login.password`)}),(0,S.jsxs)(`div`,{className:`relative`,children:[(0,S.jsx)(`input`,{id:`password`,type:A?`text`:`password`,value:E,onChange:e=>D(e.target.value),onKeyDown:$,className:`w-full rounded-xl border border-gray-200 bg-white/80 px-3 py-2.5 pe-10 text-gray-900 transition-colors duration-200 focus:border-primary-500 focus:outline-none focus:ring-2 focus:ring-primary-500/20 dark:border-white/10 dark:bg-white/[0.04] dark:text-dark-800`,placeholder:t(`setup.admin.passwordPlaceholder`),required:!0,disabled:P}),(0,S.jsx)(`button`,{type:`button`,onClick:()=>j(!A),className:`absolute inset-y-0 end-0 flex items-center pe-3 text-gray-400 hover:text-gray-600 dark:text-dark-500 dark:hover:text-dark-700`,disabled:P,children:A?(0,S.jsx)(u,{size:20}):(0,S.jsx)(c,{size:20})})]})]}),(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`label`,{htmlFor:`confirmPassword`,className:`block text-sm font-medium text-gray-700 dark:text-dark-700 mb-2`,children:t(`auth.signup.confirmPassword`)}),(0,S.jsxs)(`div`,{className:`relative`,children:[(0,S.jsx)(`input`,{id:`confirmPassword`,type:M?`text`:`password`,value:O,onChange:e=>k(e.target.value),onKeyDown:$,className:`w-full rounded-xl border border-gray-200 bg-white/80 px-3 py-2.5 pe-10 text-gray-900 transition-colors duration-200 focus:border-primary-500 focus:outline-none focus:ring-2 focus:ring-primary-500/20 dark:border-white/10 dark:bg-white/[0.04] dark:text-dark-800`,placeholder:t(`setup.admin.confirmPlaceholder`),required:!0,disabled:P}),(0,S.jsx)(`button`,{type:`button`,onClick:()=>N(!M),className:`absolute inset-y-0 end-0 flex items-center pe-3 text-gray-400 hover:text-gray-600 dark:text-dark-500 dark:hover:text-dark-700`,disabled:P,children:M?(0,S.jsx)(u,{size:20}):(0,S.jsx)(c,{size:20})})]})]}),q&&K&&(0,S.jsx)(y,{siteKey:K,disabled:P,errorMessage:t(`auth.signup.tryAgain`),onTokenChange:J}),(0,S.jsxs)(`div`,{className:`flex gap-3`,children:[(0,S.jsx)(`button`,{type:`button`,onClick:()=>r(`welcome`),disabled:P,className:`min-h-11 flex-1 rounded-xl border border-gray-200 bg-transparent px-4 py-2.5 text-sm font-medium text-gray-700 transition-colors duration-200 hover:bg-gray-100 focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 dark:border-white/10 dark:text-dark-700 dark:hover:bg-white/[0.06]`,children:t(`common.back`)}),(0,S.jsx)(`button`,{type:`submit`,disabled:Y,className:`flex min-h-11 flex-1 items-center justify-center rounded-xl border border-transparent bg-primary-600 px-4 py-2.5 text-sm font-medium text-white transition-colors duration-200 hover:bg-primary-700 focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50`,children:P?(0,S.jsxs)(`div`,{className:`flex items-center`,children:[(0,S.jsx)(`div`,{className:`me-2 h-4 w-4 animate-spin rounded-full border-b-2 border-white`}),t(`setup.admin.creating`)]}):(0,S.jsxs)(`div`,{className:`flex items-center`,children:[(0,S.jsx)(d,{size:16,className:`me-2`}),t(`setup.admin.createAdmin`)]})})]})]}),(0,S.jsx)(`div`,{className:`mt-6 text-center`,children:(0,S.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-dark-500`,children:t(`setup.admin.note`)})})]})})]})};export{w as FirstTimeSetup};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{d as t,f as n}from"./markdown-core-fkbHPd-g.js";import{n as r}from"./react-vendor-Co1u1rWb.js";import{n as i,t as a}from"./useBaseQuery-D0MMQYNQ.js";import{t as o}from"./logger-BmpKNkls.js";import{At as s,Bt as c,D as l,I as u,Nt as d,U as f,W as p,lt as m,n as h,pt as g,st as _,u as v}from"./ui-vendor-njo77ljx.js";import{u as y}from"./api-D9FuobIF.js";import{t as b}from"./utils-BaPYjs_z.js";import{t as x}from"./Button-Cgmt_2gR.js";import{P as S,X as C,Z as w,a as T,i as E,q as D}from"../assets/index-pmlsmnQ4.js";var O=class extends i{constructor(e,t){super(e,t)}bindMethods(){super.bindMethods(),this.fetchNextPage=this.fetchNextPage.bind(this),this.fetchPreviousPage=this.fetchPreviousPage.bind(this)}setOptions(e){e._type=`infinite`,super.setOptions(e)}getOptimisticResult(e){return e._type=`infinite`,super.getOptimisticResult(e)}fetchNextPage(e){return this.fetch({...e,meta:{fetchMore:{direction:`forward`}}})}fetchPreviousPage(e){return this.fetch({...e,meta:{fetchMore:{direction:`backward`}}})}createResult(e,t){let{state:n}=e,r=super.createResult(e,t),{isFetching:i,isRefetching:a,isError:o,isRefetchError:s}=r,c=n.fetchMeta?.fetchMore?.direction,l=o&&c===`forward`,u=i&&c===`forward`,d=o&&c===`backward`,f=i&&c===`backward`;return{...r,fetchNextPage:this.fetchNextPage,fetchPreviousPage:this.fetchPreviousPage,hasNextPage:C(t,n.data),hasPreviousPage:w(t,n.data),isFetchNextPageError:l,isFetchingNextPage:u,isFetchPreviousPageError:d,isFetchingPreviousPage:f,isRefetchError:s&&!l&&!d,isRefetching:a&&!u&&!f}}};function k(e,t){return a(e,O,t)}var A=e(n(),1),j=r(),M=t(),N=({image:e,onClose:t,onDelete:n,onDownload:r})=>{let{t:i}=S();return(0,A.useEffect)(()=>{let e=e=>{e.key===`Escape`&&t()};return document.addEventListener(`keydown`,e),document.body.style.overflow=`hidden`,()=>{document.removeEventListener(`keydown`,e),document.body.style.overflow=``}},[t]),(0,j.createPortal)((0,M.jsxs)(`div`,{className:`fixed inset-0 z-[99999] flex items-center justify-center`,onClick:t,children:[(0,M.jsx)(`div`,{className:`absolute inset-0 bg-black/90 backdrop-blur-sm`}),(0,M.jsxs)(`div`,{className:`relative flex flex-col lg:flex-row max-w-7xl max-h-[95vh] w-full mx-4 gap-4`,onClick:e=>e.stopPropagation(),children:[(0,M.jsx)(`button`,{onClick:t,className:b(`absolute -top-12 right-0 lg:top-0 lg:-right-12 z-10`,`p-2 rounded-full`,`bg-white/10 hover:bg-white/20`,`transition-colors`),children:(0,M.jsx)(h,{className:`h-6 w-6 text-white`})}),(0,M.jsx)(`div`,{className:`flex-1 flex items-center justify-center min-h-0`,children:(0,M.jsx)(`img`,{src:e.imageData,alt:e.prompt,className:`max-w-full max-h-[70vh] lg:max-h-[90vh] object-contain rounded-lg`})}),(0,M.jsxs)(`div`,{className:b(`w-full lg:w-80 flex-shrink-0`,`bg-white dark:bg-dark-100`,`rounded-xl p-4 lg:p-5`,`overflow-y-auto max-h-[25vh] lg:max-h-[90vh]`),children:[(0,M.jsxs)(`div`,{className:`mb-4`,children:[(0,M.jsx)(`h3`,{className:`text-sm font-medium text-gray-500 dark:text-gray-400 mb-1`,children:i(`gallery.prompt`)}),(0,M.jsx)(`p`,{className:`text-gray-900 dark:text-gray-100 text-sm leading-relaxed`,children:e.prompt})]}),(0,M.jsxs)(`div`,{className:`space-y-3 mb-4`,children:[(0,M.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,M.jsx)(m,{className:`h-4 w-4 text-gray-400 dark:text-gray-500`}),(0,M.jsxs)(`span`,{className:`text-gray-500 dark:text-gray-400`,children:[i(`gallery.model`),`:`]}),(0,M.jsx)(`span`,{className:`text-gray-900 dark:text-gray-100`,children:e.model})]}),e.size&&(0,M.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,M.jsx)(u,{className:`h-4 w-4 text-gray-400 dark:text-gray-500`}),(0,M.jsxs)(`span`,{className:`text-gray-500 dark:text-gray-400`,children:[i(`gallery.size`),`:`]}),(0,M.jsx)(`span`,{className:`text-gray-900 dark:text-gray-100`,children:e.size})]}),e.quality&&(0,M.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,M.jsx)(`span`,{className:`w-4 h-4 flex items-center justify-center text-gray-400 dark:text-gray-500 text-xs font-bold`,children:`Q`}),(0,M.jsxs)(`span`,{className:`text-gray-500 dark:text-gray-400`,children:[i(`gallery.quality`),`:`]}),(0,M.jsx)(`span`,{className:`text-gray-900 dark:text-gray-100 capitalize`,children:e.quality})]}),(0,M.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,M.jsx)(g,{className:`h-4 w-4 text-gray-400 dark:text-gray-500`}),(0,M.jsxs)(`span`,{className:`text-gray-500 dark:text-gray-400`,children:[i(`gallery.created`),`:`]}),(0,M.jsx)(`span`,{className:`text-gray-900 dark:text-gray-100`,children:(e=>new Date(e).toLocaleString(void 0,{year:`numeric`,month:`long`,day:`numeric`,hour:`2-digit`,minute:`2-digit`}))(e.createdAt)})]})]}),(0,M.jsxs)(`div`,{className:`flex gap-2 pt-4 border-t border-gray-200 dark:border-dark-300`,children:[(0,M.jsxs)(`button`,{onClick:()=>{if(r)r(e);else{let t=document.createElement(`a`);t.href=e.imageData,t.download=`generated-${e.id}.png`,document.body.appendChild(t),t.click(),document.body.removeChild(t)}},className:b(`flex-1 flex items-center justify-center gap-2 py-2.5 rounded-lg`,`bg-primary-600 dark:bg-primary-600`,`hover:bg-primary-700 dark:hover:bg-primary-500`,`text-white font-medium text-sm`,`transition-colors`),children:[(0,M.jsx)(_,{className:`h-4 w-4`}),i(`gallery.download`)]}),n&&(0,M.jsx)(`button`,{onClick:()=>n(e.id),className:b(`p-2.5 rounded-lg`,`bg-gray-100 dark:bg-dark-200`,`hover:bg-red-100 dark:hover:bg-red-900/30`,`text-gray-600 dark:text-gray-300`,`hover:text-red-600 dark:hover:text-red-400`,`transition-colors`),title:`Delete image`,children:(0,M.jsx)(v,{className:`h-4 w-4`})})]})]})]})]}),document.body)},P=o(`components:image-gallery`),F=({onImageCountChange:e})=>{let{t}=S(),n=D(),[r,i]=(0,A.useState)(null),[a,o]=(0,A.useState)(null),{data:s,fetchNextPage:l,hasNextPage:u,isFetchingNextPage:f,isLoading:m}=k({queryKey:[`image-gallery`],queryFn:async({pageParam:e})=>{let n=await y.getGallery({limit:20,offset:e});if(!n.success||!n.data)throw Error(t(`imageGallery.loadFailed`));return n.data},initialPageParam:0,getNextPageParam:(e,t)=>{let n=t.reduce((e,t)=>e+t.images.length,0);return n<e.total?n:void 0}}),h=(0,A.useMemo)(()=>s?.pages.flatMap(e=>e.images)??[],[s]),g=s?.pages[0]?.total??0,C=f;(0,A.useEffect)(()=>{e?.(g)},[g,e]);let w=()=>{l()},T=async(e,s)=>{if(s.stopPropagation(),!a){o(e);try{(await y.deleteGalleryImage(e)).success?(await n.invalidateQueries({queryKey:[`image-gallery`]}),c.success(t(`imageGallery.deleteSuccess`)),r?.id===e&&i(null)):c.error(t(`imageGallery.deleteFailed`))}catch(e){P.error(`Failed to delete image:`,e),c.error(t(`imageGallery.deleteFailed`))}finally{o(null)}}},E=(e,t)=>{t.stopPropagation();let n=document.createElement(`a`);n.href=e.imageData,n.download=`generated-${e.id}.png`,document.body.appendChild(n),n.click(),document.body.removeChild(n)},O=e=>new Date(e).toLocaleDateString(void 0,{year:`numeric`,month:`short`,day:`numeric`});return m?(0,M.jsx)(`div`,{className:`flex items-center justify-center py-20`,children:(0,M.jsx)(d,{className:`h-8 w-8 animate-spin text-gray-400 dark:text-gray-500`})}):h.length===0?(0,M.jsxs)(`div`,{className:`flex flex-col items-center justify-center rounded-2xl border border-dashed border-gray-300 bg-white/30 px-6 py-20 text-center dark:border-white/15 dark:bg-white/[0.02]`,children:[(0,M.jsx)(p,{className:`mb-4 h-10 w-10 text-gray-300 dark:text-gray-600`}),(0,M.jsx)(`h3`,{className:`text-lg font-medium text-gray-900 dark:text-gray-100 mb-2`,children:t(`imageGallery.noImages`)}),(0,M.jsx)(`p`,{className:`text-gray-500 dark:text-gray-400 max-w-sm`,children:t(`imageGallery.noImagesHint`)})]}):(0,M.jsxs)(M.Fragment,{children:[(0,M.jsx)(`div`,{className:b(`columns-1 sm:columns-2 lg:columns-3 xl:columns-4`,`gap-4 space-y-4`),children:h.map(e=>(0,M.jsxs)(`div`,{className:b(`group relative break-inside-avoid cursor-pointer overflow-hidden rounded-2xl`,`bg-gray-100 dark:bg-dark-200`,`border border-gray-200/80 dark:border-white/10`,`transition-[border-color,transform] duration-200`,`hover:border-gray-300 dark:hover:border-white/20`),children:[(0,M.jsx)(`img`,{src:e.imageData,alt:e.prompt,className:`w-full h-auto object-cover`,loading:`lazy`}),(0,M.jsx)(`button`,{type:`button`,className:`absolute inset-0 z-[1] rounded-2xl focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-primary-500`,onClick:()=>i(e),"aria-label":e.prompt}),(0,M.jsxs)(`div`,{className:b(`pointer-events-none absolute inset-0 z-[2] bg-gradient-to-t from-black/80 via-black/20 to-transparent`,`opacity-100 transition-opacity duration-200 sm:opacity-0 sm:group-hover:opacity-100 sm:group-focus-within:opacity-100`,`flex flex-col justify-end p-3`),children:[(0,M.jsx)(`p`,{className:`text-white text-sm line-clamp-2 mb-2`,children:e.prompt}),(0,M.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,M.jsx)(`span`,{className:`text-white/70 text-xs`,children:O(e.createdAt)}),(0,M.jsxs)(`div`,{className:`pointer-events-auto flex items-center gap-1`,children:[(0,M.jsx)(`button`,{onClick:t=>E(e,t),className:b(`p-1.5 rounded-lg`,`bg-white/20 hover:bg-white/30`,`transition-colors`),title:t(`imageGallery.download`),children:(0,M.jsx)(_,{className:`h-4 w-4 text-white`})}),(0,M.jsx)(`button`,{onClick:t=>T(e.id,t),disabled:a===e.id,className:b(`p-1.5 rounded-lg`,`bg-white/20 hover:bg-red-500/80`,`transition-colors`,a===e.id&&`opacity-50 cursor-not-allowed`),title:t(`imageGallery.delete`),children:a===e.id?(0,M.jsx)(d,{className:`h-4 w-4 text-white animate-spin`}):(0,M.jsx)(v,{className:`h-4 w-4 text-white`})})]})]})]})]},e.id))}),u&&(0,M.jsx)(`div`,{className:`flex justify-center mt-8`,children:(0,M.jsx)(x,{onClick:w,disabled:C,variant:`outline`,className:`px-6`,children:C?(0,M.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,M.jsx)(d,{className:`h-4 w-4 animate-spin`}),t(`common.loading`)]}):t(`imageGallery.loadMore`,{current:h.length,total:g})})}),r&&(0,M.jsx)(N,{image:r,onClose:()=>i(null),onDelete:e=>{T(e,{stopPropagation:()=>{}})},onDownload:e=>{E(e,{stopPropagation:()=>{}})}})]})},I=o(`components:image-generation-panel`),L=({isOpen:e,onClose:t,onImageGenerated:n})=>{let{t:r}=S(),[i,a]=(0,A.useState)([]),[o,l]=(0,A.useState)(``),[u,p]=(0,A.useState)(``),[m,g]=(0,A.useState)(``),[v,C]=(0,A.useState)(`1024x1024`),[w,T]=(0,A.useState)(`standard`),[E,D]=(0,A.useState)(!1),[O,k]=(0,A.useState)(null),[N,P]=(0,A.useState)([`512x512`,`768x768`,`1024x1024`]),[F,L]=(0,A.useState)([`standard`,`high`]),[R,z]=(0,A.useState)(null),B=A.useId();(0,A.useEffect)(()=>{e&&(async()=>{try{let e=await y.getPlugins();if(e.success&&e.data&&(a(e.data),e.data.length>0)){let t=e.data[0];l(t.id),t.models.length>0&&p(t.models[0]),t.config?.sizes&&(P(t.config.sizes),C(t.config.default_size||t.config.sizes[0]||`1024x1024`)),t.config?.qualities&&(L(t.config.qualities),T(t.config.default_quality||t.config.qualities[0]||`standard`)),z(t.config?.max_prompt_length??null)}}catch(e){I.error(`Failed to load image generation plugins:`,e)}})()},[e]),(0,A.useEffect)(()=>{if(!e)return;let n=document.body.style.overflow,r=e=>{e.key===`Escape`&&t()};return document.body.style.overflow=`hidden`,document.addEventListener(`keydown`,r),()=>{document.body.style.overflow=n,document.removeEventListener(`keydown`,r)}},[e,t]);let[V,H]=(0,A.useState)(o);if(o!==V){H(o);let e=i.find(e=>e.id===o);e&&(e.models.length>0&&!e.models.includes(u)&&p(e.models[0]),e.config?.sizes&&(P(e.config.sizes),e.config.sizes.includes(v)||C(e.config.default_size||e.config.sizes[0])),e.config?.qualities&&(L(e.config.qualities),e.config.qualities.includes(w)||T(e.config.default_quality||e.config.qualities[0])),z(e.config?.max_prompt_length??null))}let U=async()=>{if(!u||!m.trim()){c.error(r(`imageGeneration.enterPrompt`));return}if(R&&m.length>R){c.error(r(`imageGeneration.promptTooLong`,{max:R.toLocaleString()}));return}D(!0),k(null);try{let e=await y.generate({model:u,prompt:m.trim(),size:v,quality:w});if(e.success&&e.data?.images&&e.data.images.length>0){let i=e.data.images[0],a=null;i.b64_json?a=`data:image/png;base64,${i.b64_json}`:i.url&&(a=i.url),a&&(c.success(r(`imageGeneration.success`)),n?(n(a,m.trim(),u),g(``),k(null),t()):k(a))}else c.error(r(`imageGeneration.failed`))}catch(e){I.error(`Image generation failed:`,e);let t=e instanceof Error?e.message:r(`imageGeneration.failed`);c.error(t)}finally{D(!1)}},W=()=>{if(!O)return;let e=document.createElement(`a`);e.href=O,e.download=`generated-image-${Date.now()}.png`,document.body.appendChild(e),e.click(),document.body.removeChild(e)};if(!e)return null;let G=i.find(e=>e.id===o);return(0,j.createPortal)((0,M.jsxs)(`div`,{className:`fixed inset-0 z-[99999] flex items-center justify-center p-3 sm:p-6`,role:`dialog`,"aria-modal":`true`,"aria-labelledby":B,children:[(0,M.jsx)(`div`,{className:`absolute inset-0 bg-black/55 backdrop-blur-sm`,onClick:t}),(0,M.jsxs)(`div`,{className:b(`relative bg-white/95 dark:bg-dark-25/95`,`border border-gray-200/80 dark:border-white/10`,`rounded-3xl shadow-2xl backdrop-blur-xl`,`flex max-h-[92vh] w-full max-w-2xl flex-col overflow-hidden`),onClick:e=>e.stopPropagation(),children:[(0,M.jsxs)(`div`,{className:`flex items-center justify-between border-b border-gray-200/70 px-5 py-4 dark:border-white/[0.08] sm:px-6 sm:py-5`,children:[(0,M.jsx)(`div`,{children:(0,M.jsx)(`h2`,{id:B,className:`text-xl font-normal tracking-[-0.025em] text-gray-950 dark:text-dark-950`,children:r(`imageGeneration.title`)})}),(0,M.jsx)(`button`,{onClick:t,className:`rounded-xl p-2 text-gray-500 transition-colors hover:bg-gray-100 hover:text-gray-900 dark:text-dark-500 dark:hover:bg-white/[0.06] dark:hover:text-dark-900`,title:r(`common.close`,{defaultValue:`Close`}),children:(0,M.jsx)(h,{className:`h-5 w-5 text-gray-500 dark:text-gray-400`})})]}),(0,M.jsx)(`div`,{className:`flex-1 space-y-5 overflow-y-auto p-5 sm:p-6`,children:i.length===0?(0,M.jsxs)(`div`,{className:`text-center py-8`,children:[(0,M.jsx)(f,{className:`h-12 w-12 mx-auto mb-3 text-gray-300 dark:text-gray-600`}),(0,M.jsx)(`p`,{className:`text-gray-500 dark:text-gray-400`,children:r(`imageGeneration.noModels`)}),(0,M.jsx)(`p`,{className:`text-sm text-gray-400 dark:text-gray-500 mt-1`,children:r(`imageGeneration.configurePlugin`)})]}):(0,M.jsxs)(M.Fragment,{children:[(0,M.jsxs)(`div`,{className:`grid grid-cols-1 gap-4 sm:grid-cols-2`,children:[(0,M.jsxs)(`div`,{children:[(0,M.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1`,children:r(`settings.plugins.title`)}),(0,M.jsx)(`select`,{value:o,onChange:e=>l(e.target.value),className:b(`w-full rounded-xl px-3 py-2.5 text-sm`,`bg-white/70 dark:bg-white/[0.035]`,`border border-gray-200/80 dark:border-white/10`,`text-gray-900 dark:text-gray-100`,`focus:outline-none focus:ring-2 focus:ring-primary-500/20`),children:i.map(e=>(0,M.jsx)(`option`,{value:e.id,children:e.name},e.id))})]}),(0,M.jsxs)(`div`,{children:[(0,M.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1`,children:r(`imageGeneration.model`)}),(0,M.jsx)(`select`,{value:u,onChange:e=>p(e.target.value),className:b(`w-full rounded-xl px-3 py-2.5 text-sm`,`bg-white/70 dark:bg-white/[0.035]`,`border border-gray-200/80 dark:border-white/10`,`text-gray-900 dark:text-gray-100`,`focus:outline-none focus:ring-2 focus:ring-primary-500/20`),children:G?.models.map(e=>(0,M.jsx)(`option`,{value:e,children:e},e))})]})]}),(0,M.jsxs)(`div`,{className:`grid grid-cols-1 gap-4 sm:grid-cols-2`,children:[(0,M.jsxs)(`div`,{children:[(0,M.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1`,children:r(`imageGeneration.size`)}),(0,M.jsx)(`select`,{value:v,onChange:e=>C(e.target.value),className:b(`w-full rounded-xl px-3 py-2.5 text-sm`,`bg-white/70 dark:bg-white/[0.035]`,`border border-gray-200/80 dark:border-white/10`,`text-gray-900 dark:text-gray-100`,`focus:outline-none focus:ring-2 focus:ring-primary-500/20`),children:N.map(e=>(0,M.jsx)(`option`,{value:e,children:e},e))})]}),(0,M.jsxs)(`div`,{children:[(0,M.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1`,children:r(`imageGeneration.quality`)}),(0,M.jsx)(`select`,{value:w,onChange:e=>T(e.target.value),className:b(`w-full rounded-xl px-3 py-2.5 text-sm`,`bg-white/70 dark:bg-white/[0.035]`,`border border-gray-200/80 dark:border-white/10`,`text-gray-900 dark:text-gray-100`,`focus:outline-none focus:ring-2 focus:ring-primary-500/20`),children:F.map(e=>(0,M.jsx)(`option`,{value:e,children:e.charAt(0).toUpperCase()+e.slice(1)},e))})]})]}),(0,M.jsxs)(`div`,{children:[(0,M.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1`,children:r(`imageGeneration.prompt`)}),(0,M.jsx)(`textarea`,{value:m,onChange:e=>g(e.target.value),placeholder:r(`imageGeneration.promptPlaceholder`),rows:5,className:b(`w-full resize-none rounded-2xl px-4 py-3 text-sm leading-6`,`bg-white/70 dark:bg-white/[0.035]`,`border border-gray-200/80 dark:border-white/10`,`text-gray-900 dark:text-gray-100`,`placeholder-gray-500 dark:placeholder-gray-400`,`focus:outline-none focus:ring-2 focus:ring-primary-500/20`,R&&m.length>R&&`border-red-500 dark:border-red-500`)}),R&&(0,M.jsxs)(`div`,{className:b(`mt-1 text-end text-xs`,m.length>R?`text-red-500`:`text-gray-500 dark:text-gray-400`),children:[m.length.toLocaleString(),` /`,` `,R.toLocaleString()]})]}),O&&(0,M.jsxs)(`div`,{className:`relative overflow-hidden rounded-2xl border border-gray-200/80 dark:border-white/10`,children:[(0,M.jsx)(`img`,{src:O,alt:`Generated`,className:`w-full h-auto`}),(0,M.jsx)(`button`,{onClick:W,className:b(`absolute bottom-3 end-3 rounded-lg p-2`,`bg-white/90 dark:bg-dark-100/90`,`hover:bg-white dark:hover:bg-dark-100`,`border border-gray-200 dark:border-dark-300`,`transition-colors`),title:r(`imageGallery.download`),children:(0,M.jsx)(_,{className:`h-5 w-5 text-gray-700 dark:text-gray-200`})})]})]})}),i.length>0&&(0,M.jsx)(`div`,{className:`border-t border-gray-200/70 p-4 dark:border-white/[0.08] sm:px-6 sm:py-5`,children:(0,M.jsx)(x,{onClick:U,disabled:E||!m.trim()||!u,className:b(`w-full py-2.5 rounded-xl font-medium`,`bg-primary-600 dark:bg-primary-600`,`hover:bg-primary-700 dark:hover:bg-primary-500`,`text-white`,`disabled:opacity-50 disabled:cursor-not-allowed`,`transition-colors`),children:E?(0,M.jsxs)(`span`,{className:`flex items-center justify-center gap-2`,children:[(0,M.jsx)(d,{className:`h-4 w-4 animate-spin`}),r(`imageGeneration.generating`)]}):(0,M.jsxs)(`span`,{className:`flex items-center justify-center gap-2`,children:[(0,M.jsx)(s,{className:`h-4 w-4`}),r(`imageGeneration.generate`)]})})})]})]}),document.body)},R=()=>{let{t:e}=S(),[t,n]=(0,A.useState)(null),[r,i]=(0,A.useState)(!1),[a,o]=(0,A.useState)(0),s=(0,A.useCallback)(()=>{o(e=>e+1)},[]);return(0,M.jsxs)(T,{width:`wide`,children:[(0,M.jsx)(E,{title:e(`sidebar.navigation.imagine`),description:e(`gallery.subtitle`),meta:t!==null&&t>0?(0,M.jsx)(`span`,{className:`inline-flex rounded-full border border-gray-200/80 bg-white/60 px-2.5 py-1 text-xs text-gray-500 dark:border-white/10 dark:bg-white/[0.04] dark:text-dark-500`,children:e(`gallery.imageCount`,{count:t})}):null,actions:(0,M.jsxs)(x,{onClick:()=>i(!0),className:`gap-2 px-5`,children:[(0,M.jsx)(l,{className:`h-4 w-4`,"aria-hidden":`true`}),e(`gallery.generate`)]})}),(0,M.jsx)(F,{onImageCountChange:n},a),(0,M.jsx)(L,{isOpen:r,onClose:()=>i(!1),onImageGenerated:s})]})};export{R as GalleryPage,R as default};
|
|
1
|
+
import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{d as t,f as n}from"./markdown-core-fkbHPd-g.js";import{n as r}from"./react-vendor-Co1u1rWb.js";import{n as i,t as a}from"./useBaseQuery-5VtX6QMw.js";import{t as o}from"./logger-BmpKNkls.js";import{At as s,Bt as c,D as l,I as u,Nt as d,U as f,W as p,lt as m,n as h,pt as g,st as _,u as v}from"./ui-vendor-njo77ljx.js";import{u as y}from"./api-Ddawdcbi.js";import{t as b}from"./utils-BaPYjs_z.js";import{t as x}from"./Button-Cgmt_2gR.js";import{P as S,X as C,Z as w,a as T,i as E,q as D}from"../assets/index-6X4Fay3z.js";var O=class extends i{constructor(e,t){super(e,t)}bindMethods(){super.bindMethods(),this.fetchNextPage=this.fetchNextPage.bind(this),this.fetchPreviousPage=this.fetchPreviousPage.bind(this)}setOptions(e){e._type=`infinite`,super.setOptions(e)}getOptimisticResult(e){return e._type=`infinite`,super.getOptimisticResult(e)}fetchNextPage(e){return this.fetch({...e,meta:{fetchMore:{direction:`forward`}}})}fetchPreviousPage(e){return this.fetch({...e,meta:{fetchMore:{direction:`backward`}}})}createResult(e,t){let{state:n}=e,r=super.createResult(e,t),{isFetching:i,isRefetching:a,isError:o,isRefetchError:s}=r,c=n.fetchMeta?.fetchMore?.direction,l=o&&c===`forward`,u=i&&c===`forward`,d=o&&c===`backward`,f=i&&c===`backward`;return{...r,fetchNextPage:this.fetchNextPage,fetchPreviousPage:this.fetchPreviousPage,hasNextPage:C(t,n.data),hasPreviousPage:w(t,n.data),isFetchNextPageError:l,isFetchingNextPage:u,isFetchPreviousPageError:d,isFetchingPreviousPage:f,isRefetchError:s&&!l&&!d,isRefetching:a&&!u&&!f}}};function k(e,t){return a(e,O,t)}var A=e(n(),1),j=r(),M=t(),N=({image:e,onClose:t,onDelete:n,onDownload:r})=>{let{t:i}=S();return(0,A.useEffect)(()=>{let e=e=>{e.key===`Escape`&&t()};return document.addEventListener(`keydown`,e),document.body.style.overflow=`hidden`,()=>{document.removeEventListener(`keydown`,e),document.body.style.overflow=``}},[t]),(0,j.createPortal)((0,M.jsxs)(`div`,{className:`fixed inset-0 z-[99999] flex items-center justify-center`,onClick:t,children:[(0,M.jsx)(`div`,{className:`absolute inset-0 bg-black/90 backdrop-blur-sm`}),(0,M.jsxs)(`div`,{className:`relative flex flex-col lg:flex-row max-w-7xl max-h-[95vh] w-full mx-4 gap-4`,onClick:e=>e.stopPropagation(),children:[(0,M.jsx)(`button`,{onClick:t,className:b(`absolute -top-12 right-0 lg:top-0 lg:-right-12 z-10`,`p-2 rounded-full`,`bg-white/10 hover:bg-white/20`,`transition-colors`),children:(0,M.jsx)(h,{className:`h-6 w-6 text-white`})}),(0,M.jsx)(`div`,{className:`flex-1 flex items-center justify-center min-h-0`,children:(0,M.jsx)(`img`,{src:e.imageData,alt:e.prompt,className:`max-w-full max-h-[70vh] lg:max-h-[90vh] object-contain rounded-lg`})}),(0,M.jsxs)(`div`,{className:b(`w-full lg:w-80 flex-shrink-0`,`bg-white dark:bg-dark-100`,`rounded-xl p-4 lg:p-5`,`overflow-y-auto max-h-[25vh] lg:max-h-[90vh]`),children:[(0,M.jsxs)(`div`,{className:`mb-4`,children:[(0,M.jsx)(`h3`,{className:`text-sm font-medium text-gray-500 dark:text-gray-400 mb-1`,children:i(`gallery.prompt`)}),(0,M.jsx)(`p`,{className:`text-gray-900 dark:text-gray-100 text-sm leading-relaxed`,children:e.prompt})]}),(0,M.jsxs)(`div`,{className:`space-y-3 mb-4`,children:[(0,M.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,M.jsx)(m,{className:`h-4 w-4 text-gray-400 dark:text-gray-500`}),(0,M.jsxs)(`span`,{className:`text-gray-500 dark:text-gray-400`,children:[i(`gallery.model`),`:`]}),(0,M.jsx)(`span`,{className:`text-gray-900 dark:text-gray-100`,children:e.model})]}),e.size&&(0,M.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,M.jsx)(u,{className:`h-4 w-4 text-gray-400 dark:text-gray-500`}),(0,M.jsxs)(`span`,{className:`text-gray-500 dark:text-gray-400`,children:[i(`gallery.size`),`:`]}),(0,M.jsx)(`span`,{className:`text-gray-900 dark:text-gray-100`,children:e.size})]}),e.quality&&(0,M.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,M.jsx)(`span`,{className:`w-4 h-4 flex items-center justify-center text-gray-400 dark:text-gray-500 text-xs font-bold`,children:`Q`}),(0,M.jsxs)(`span`,{className:`text-gray-500 dark:text-gray-400`,children:[i(`gallery.quality`),`:`]}),(0,M.jsx)(`span`,{className:`text-gray-900 dark:text-gray-100 capitalize`,children:e.quality})]}),(0,M.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,M.jsx)(g,{className:`h-4 w-4 text-gray-400 dark:text-gray-500`}),(0,M.jsxs)(`span`,{className:`text-gray-500 dark:text-gray-400`,children:[i(`gallery.created`),`:`]}),(0,M.jsx)(`span`,{className:`text-gray-900 dark:text-gray-100`,children:(e=>new Date(e).toLocaleString(void 0,{year:`numeric`,month:`long`,day:`numeric`,hour:`2-digit`,minute:`2-digit`}))(e.createdAt)})]})]}),(0,M.jsxs)(`div`,{className:`flex gap-2 pt-4 border-t border-gray-200 dark:border-dark-300`,children:[(0,M.jsxs)(`button`,{onClick:()=>{if(r)r(e);else{let t=document.createElement(`a`);t.href=e.imageData,t.download=`generated-${e.id}.png`,document.body.appendChild(t),t.click(),document.body.removeChild(t)}},className:b(`flex-1 flex items-center justify-center gap-2 py-2.5 rounded-lg`,`bg-primary-600 dark:bg-primary-600`,`hover:bg-primary-700 dark:hover:bg-primary-500`,`text-white font-medium text-sm`,`transition-colors`),children:[(0,M.jsx)(_,{className:`h-4 w-4`}),i(`gallery.download`)]}),n&&(0,M.jsx)(`button`,{onClick:()=>n(e.id),className:b(`p-2.5 rounded-lg`,`bg-gray-100 dark:bg-dark-200`,`hover:bg-red-100 dark:hover:bg-red-900/30`,`text-gray-600 dark:text-gray-300`,`hover:text-red-600 dark:hover:text-red-400`,`transition-colors`),title:`Delete image`,children:(0,M.jsx)(v,{className:`h-4 w-4`})})]})]})]})]}),document.body)},P=o(`components:image-gallery`),F=({onImageCountChange:e})=>{let{t}=S(),n=D(),[r,i]=(0,A.useState)(null),[a,o]=(0,A.useState)(null),{data:s,fetchNextPage:l,hasNextPage:u,isFetchingNextPage:f,isLoading:m}=k({queryKey:[`image-gallery`],queryFn:async({pageParam:e})=>{let n=await y.getGallery({limit:20,offset:e});if(!n.success||!n.data)throw Error(t(`imageGallery.loadFailed`));return n.data},initialPageParam:0,getNextPageParam:(e,t)=>{let n=t.reduce((e,t)=>e+t.images.length,0);return n<e.total?n:void 0}}),h=(0,A.useMemo)(()=>s?.pages.flatMap(e=>e.images)??[],[s]),g=s?.pages[0]?.total??0,C=f;(0,A.useEffect)(()=>{e?.(g)},[g,e]);let w=()=>{l()},T=async(e,s)=>{if(s.stopPropagation(),!a){o(e);try{(await y.deleteGalleryImage(e)).success?(await n.invalidateQueries({queryKey:[`image-gallery`]}),c.success(t(`imageGallery.deleteSuccess`)),r?.id===e&&i(null)):c.error(t(`imageGallery.deleteFailed`))}catch(e){P.error(`Failed to delete image:`,e),c.error(t(`imageGallery.deleteFailed`))}finally{o(null)}}},E=(e,t)=>{t.stopPropagation();let n=document.createElement(`a`);n.href=e.imageData,n.download=`generated-${e.id}.png`,document.body.appendChild(n),n.click(),document.body.removeChild(n)},O=e=>new Date(e).toLocaleDateString(void 0,{year:`numeric`,month:`short`,day:`numeric`});return m?(0,M.jsx)(`div`,{className:`flex items-center justify-center py-20`,children:(0,M.jsx)(d,{className:`h-8 w-8 animate-spin text-gray-400 dark:text-gray-500`})}):h.length===0?(0,M.jsxs)(`div`,{className:`flex flex-col items-center justify-center rounded-2xl border border-dashed border-gray-300 bg-white/30 px-6 py-20 text-center dark:border-white/15 dark:bg-white/[0.02]`,children:[(0,M.jsx)(p,{className:`mb-4 h-10 w-10 text-gray-300 dark:text-gray-600`}),(0,M.jsx)(`h3`,{className:`text-lg font-medium text-gray-900 dark:text-gray-100 mb-2`,children:t(`imageGallery.noImages`)}),(0,M.jsx)(`p`,{className:`text-gray-500 dark:text-gray-400 max-w-sm`,children:t(`imageGallery.noImagesHint`)})]}):(0,M.jsxs)(M.Fragment,{children:[(0,M.jsx)(`div`,{className:b(`columns-1 sm:columns-2 lg:columns-3 xl:columns-4`,`gap-4 space-y-4`),children:h.map(e=>(0,M.jsxs)(`div`,{className:b(`group relative break-inside-avoid cursor-pointer overflow-hidden rounded-2xl`,`bg-gray-100 dark:bg-dark-200`,`border border-gray-200/80 dark:border-white/10`,`transition-[border-color,transform] duration-200`,`hover:border-gray-300 dark:hover:border-white/20`),children:[(0,M.jsx)(`img`,{src:e.imageData,alt:e.prompt,className:`w-full h-auto object-cover`,loading:`lazy`}),(0,M.jsx)(`button`,{type:`button`,className:`absolute inset-0 z-[1] rounded-2xl focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-primary-500`,onClick:()=>i(e),"aria-label":e.prompt}),(0,M.jsxs)(`div`,{className:b(`pointer-events-none absolute inset-0 z-[2] bg-gradient-to-t from-black/80 via-black/20 to-transparent`,`opacity-100 transition-opacity duration-200 sm:opacity-0 sm:group-hover:opacity-100 sm:group-focus-within:opacity-100`,`flex flex-col justify-end p-3`),children:[(0,M.jsx)(`p`,{className:`text-white text-sm line-clamp-2 mb-2`,children:e.prompt}),(0,M.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,M.jsx)(`span`,{className:`text-white/70 text-xs`,children:O(e.createdAt)}),(0,M.jsxs)(`div`,{className:`pointer-events-auto flex items-center gap-1`,children:[(0,M.jsx)(`button`,{onClick:t=>E(e,t),className:b(`p-1.5 rounded-lg`,`bg-white/20 hover:bg-white/30`,`transition-colors`),title:t(`imageGallery.download`),children:(0,M.jsx)(_,{className:`h-4 w-4 text-white`})}),(0,M.jsx)(`button`,{onClick:t=>T(e.id,t),disabled:a===e.id,className:b(`p-1.5 rounded-lg`,`bg-white/20 hover:bg-red-500/80`,`transition-colors`,a===e.id&&`opacity-50 cursor-not-allowed`),title:t(`imageGallery.delete`),children:a===e.id?(0,M.jsx)(d,{className:`h-4 w-4 text-white animate-spin`}):(0,M.jsx)(v,{className:`h-4 w-4 text-white`})})]})]})]})]},e.id))}),u&&(0,M.jsx)(`div`,{className:`flex justify-center mt-8`,children:(0,M.jsx)(x,{onClick:w,disabled:C,variant:`outline`,className:`px-6`,children:C?(0,M.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,M.jsx)(d,{className:`h-4 w-4 animate-spin`}),t(`common.loading`)]}):t(`imageGallery.loadMore`,{current:h.length,total:g})})}),r&&(0,M.jsx)(N,{image:r,onClose:()=>i(null),onDelete:e=>{T(e,{stopPropagation:()=>{}})},onDownload:e=>{E(e,{stopPropagation:()=>{}})}})]})},I=o(`components:image-generation-panel`),L=({isOpen:e,onClose:t,onImageGenerated:n})=>{let{t:r}=S(),[i,a]=(0,A.useState)([]),[o,l]=(0,A.useState)(``),[u,p]=(0,A.useState)(``),[m,g]=(0,A.useState)(``),[v,C]=(0,A.useState)(`1024x1024`),[w,T]=(0,A.useState)(`standard`),[E,D]=(0,A.useState)(!1),[O,k]=(0,A.useState)(null),[N,P]=(0,A.useState)([`512x512`,`768x768`,`1024x1024`]),[F,L]=(0,A.useState)([`standard`,`high`]),[R,z]=(0,A.useState)(null),B=A.useId();(0,A.useEffect)(()=>{e&&(async()=>{try{let e=await y.getPlugins();if(e.success&&e.data&&(a(e.data),e.data.length>0)){let t=e.data[0];l(t.id),t.models.length>0&&p(t.models[0]),t.config?.sizes&&(P(t.config.sizes),C(t.config.default_size||t.config.sizes[0]||`1024x1024`)),t.config?.qualities&&(L(t.config.qualities),T(t.config.default_quality||t.config.qualities[0]||`standard`)),z(t.config?.max_prompt_length??null)}}catch(e){I.error(`Failed to load image generation plugins:`,e)}})()},[e]),(0,A.useEffect)(()=>{if(!e)return;let n=document.body.style.overflow,r=e=>{e.key===`Escape`&&t()};return document.body.style.overflow=`hidden`,document.addEventListener(`keydown`,r),()=>{document.body.style.overflow=n,document.removeEventListener(`keydown`,r)}},[e,t]);let[V,H]=(0,A.useState)(o);if(o!==V){H(o);let e=i.find(e=>e.id===o);e&&(e.models.length>0&&!e.models.includes(u)&&p(e.models[0]),e.config?.sizes&&(P(e.config.sizes),e.config.sizes.includes(v)||C(e.config.default_size||e.config.sizes[0])),e.config?.qualities&&(L(e.config.qualities),e.config.qualities.includes(w)||T(e.config.default_quality||e.config.qualities[0])),z(e.config?.max_prompt_length??null))}let U=async()=>{if(!u||!m.trim()){c.error(r(`imageGeneration.enterPrompt`));return}if(R&&m.length>R){c.error(r(`imageGeneration.promptTooLong`,{max:R.toLocaleString()}));return}D(!0),k(null);try{let e=await y.generate({model:u,prompt:m.trim(),size:v,quality:w});if(e.success&&e.data?.images&&e.data.images.length>0){let i=e.data.images[0],a=null;i.b64_json?a=`data:image/png;base64,${i.b64_json}`:i.url&&(a=i.url),a&&(c.success(r(`imageGeneration.success`)),n?(n(a,m.trim(),u),g(``),k(null),t()):k(a))}else c.error(r(`imageGeneration.failed`))}catch(e){I.error(`Image generation failed:`,e);let t=e instanceof Error?e.message:r(`imageGeneration.failed`);c.error(t)}finally{D(!1)}},W=()=>{if(!O)return;let e=document.createElement(`a`);e.href=O,e.download=`generated-image-${Date.now()}.png`,document.body.appendChild(e),e.click(),document.body.removeChild(e)};if(!e)return null;let G=i.find(e=>e.id===o);return(0,j.createPortal)((0,M.jsxs)(`div`,{className:`fixed inset-0 z-[99999] flex items-center justify-center p-3 sm:p-6`,role:`dialog`,"aria-modal":`true`,"aria-labelledby":B,children:[(0,M.jsx)(`div`,{className:`absolute inset-0 bg-black/55 backdrop-blur-sm`,onClick:t}),(0,M.jsxs)(`div`,{className:b(`relative bg-white/95 dark:bg-dark-25/95`,`border border-gray-200/80 dark:border-white/10`,`rounded-3xl shadow-2xl backdrop-blur-xl`,`flex max-h-[92vh] w-full max-w-2xl flex-col overflow-hidden`),onClick:e=>e.stopPropagation(),children:[(0,M.jsxs)(`div`,{className:`flex items-center justify-between border-b border-gray-200/70 px-5 py-4 dark:border-white/[0.08] sm:px-6 sm:py-5`,children:[(0,M.jsx)(`div`,{children:(0,M.jsx)(`h2`,{id:B,className:`text-xl font-normal tracking-[-0.025em] text-gray-950 dark:text-dark-950`,children:r(`imageGeneration.title`)})}),(0,M.jsx)(`button`,{onClick:t,className:`rounded-xl p-2 text-gray-500 transition-colors hover:bg-gray-100 hover:text-gray-900 dark:text-dark-500 dark:hover:bg-white/[0.06] dark:hover:text-dark-900`,title:r(`common.close`,{defaultValue:`Close`}),children:(0,M.jsx)(h,{className:`h-5 w-5 text-gray-500 dark:text-gray-400`})})]}),(0,M.jsx)(`div`,{className:`flex-1 space-y-5 overflow-y-auto p-5 sm:p-6`,children:i.length===0?(0,M.jsxs)(`div`,{className:`text-center py-8`,children:[(0,M.jsx)(f,{className:`h-12 w-12 mx-auto mb-3 text-gray-300 dark:text-gray-600`}),(0,M.jsx)(`p`,{className:`text-gray-500 dark:text-gray-400`,children:r(`imageGeneration.noModels`)}),(0,M.jsx)(`p`,{className:`text-sm text-gray-400 dark:text-gray-500 mt-1`,children:r(`imageGeneration.configurePlugin`)})]}):(0,M.jsxs)(M.Fragment,{children:[(0,M.jsxs)(`div`,{className:`grid grid-cols-1 gap-4 sm:grid-cols-2`,children:[(0,M.jsxs)(`div`,{children:[(0,M.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1`,children:r(`settings.plugins.title`)}),(0,M.jsx)(`select`,{value:o,onChange:e=>l(e.target.value),className:b(`w-full rounded-xl px-3 py-2.5 text-sm`,`bg-white/70 dark:bg-white/[0.035]`,`border border-gray-200/80 dark:border-white/10`,`text-gray-900 dark:text-gray-100`,`focus:outline-none focus:ring-2 focus:ring-primary-500/20`),children:i.map(e=>(0,M.jsx)(`option`,{value:e.id,children:e.name},e.id))})]}),(0,M.jsxs)(`div`,{children:[(0,M.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1`,children:r(`imageGeneration.model`)}),(0,M.jsx)(`select`,{value:u,onChange:e=>p(e.target.value),className:b(`w-full rounded-xl px-3 py-2.5 text-sm`,`bg-white/70 dark:bg-white/[0.035]`,`border border-gray-200/80 dark:border-white/10`,`text-gray-900 dark:text-gray-100`,`focus:outline-none focus:ring-2 focus:ring-primary-500/20`),children:G?.models.map(e=>(0,M.jsx)(`option`,{value:e,children:e},e))})]})]}),(0,M.jsxs)(`div`,{className:`grid grid-cols-1 gap-4 sm:grid-cols-2`,children:[(0,M.jsxs)(`div`,{children:[(0,M.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1`,children:r(`imageGeneration.size`)}),(0,M.jsx)(`select`,{value:v,onChange:e=>C(e.target.value),className:b(`w-full rounded-xl px-3 py-2.5 text-sm`,`bg-white/70 dark:bg-white/[0.035]`,`border border-gray-200/80 dark:border-white/10`,`text-gray-900 dark:text-gray-100`,`focus:outline-none focus:ring-2 focus:ring-primary-500/20`),children:N.map(e=>(0,M.jsx)(`option`,{value:e,children:e},e))})]}),(0,M.jsxs)(`div`,{children:[(0,M.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1`,children:r(`imageGeneration.quality`)}),(0,M.jsx)(`select`,{value:w,onChange:e=>T(e.target.value),className:b(`w-full rounded-xl px-3 py-2.5 text-sm`,`bg-white/70 dark:bg-white/[0.035]`,`border border-gray-200/80 dark:border-white/10`,`text-gray-900 dark:text-gray-100`,`focus:outline-none focus:ring-2 focus:ring-primary-500/20`),children:F.map(e=>(0,M.jsx)(`option`,{value:e,children:e.charAt(0).toUpperCase()+e.slice(1)},e))})]})]}),(0,M.jsxs)(`div`,{children:[(0,M.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1`,children:r(`imageGeneration.prompt`)}),(0,M.jsx)(`textarea`,{value:m,onChange:e=>g(e.target.value),placeholder:r(`imageGeneration.promptPlaceholder`),rows:5,className:b(`w-full resize-none rounded-2xl px-4 py-3 text-sm leading-6`,`bg-white/70 dark:bg-white/[0.035]`,`border border-gray-200/80 dark:border-white/10`,`text-gray-900 dark:text-gray-100`,`placeholder-gray-500 dark:placeholder-gray-400`,`focus:outline-none focus:ring-2 focus:ring-primary-500/20`,R&&m.length>R&&`border-red-500 dark:border-red-500`)}),R&&(0,M.jsxs)(`div`,{className:b(`mt-1 text-end text-xs`,m.length>R?`text-red-500`:`text-gray-500 dark:text-gray-400`),children:[m.length.toLocaleString(),` /`,` `,R.toLocaleString()]})]}),O&&(0,M.jsxs)(`div`,{className:`relative overflow-hidden rounded-2xl border border-gray-200/80 dark:border-white/10`,children:[(0,M.jsx)(`img`,{src:O,alt:`Generated`,className:`w-full h-auto`}),(0,M.jsx)(`button`,{onClick:W,className:b(`absolute bottom-3 end-3 rounded-lg p-2`,`bg-white/90 dark:bg-dark-100/90`,`hover:bg-white dark:hover:bg-dark-100`,`border border-gray-200 dark:border-dark-300`,`transition-colors`),title:r(`imageGallery.download`),children:(0,M.jsx)(_,{className:`h-5 w-5 text-gray-700 dark:text-gray-200`})})]})]})}),i.length>0&&(0,M.jsx)(`div`,{className:`border-t border-gray-200/70 p-4 dark:border-white/[0.08] sm:px-6 sm:py-5`,children:(0,M.jsx)(x,{onClick:U,disabled:E||!m.trim()||!u,className:b(`w-full py-2.5 rounded-xl font-medium`,`bg-primary-600 dark:bg-primary-600`,`hover:bg-primary-700 dark:hover:bg-primary-500`,`text-white`,`disabled:opacity-50 disabled:cursor-not-allowed`,`transition-colors`),children:E?(0,M.jsxs)(`span`,{className:`flex items-center justify-center gap-2`,children:[(0,M.jsx)(d,{className:`h-4 w-4 animate-spin`}),r(`imageGeneration.generating`)]}):(0,M.jsxs)(`span`,{className:`flex items-center justify-center gap-2`,children:[(0,M.jsx)(s,{className:`h-4 w-4`}),r(`imageGeneration.generate`)]})})})]})]}),document.body)},R=()=>{let{t:e}=S(),[t,n]=(0,A.useState)(null),[r,i]=(0,A.useState)(!1),[a,o]=(0,A.useState)(0),s=(0,A.useCallback)(()=>{o(e=>e+1)},[]);return(0,M.jsxs)(T,{width:`wide`,children:[(0,M.jsx)(E,{title:e(`sidebar.navigation.imagine`),description:e(`gallery.subtitle`),meta:t!==null&&t>0?(0,M.jsx)(`span`,{className:`inline-flex rounded-full border border-gray-200/80 bg-white/60 px-2.5 py-1 text-xs text-gray-500 dark:border-white/10 dark:bg-white/[0.04] dark:text-dark-500`,children:e(`gallery.imageCount`,{count:t})}):null,actions:(0,M.jsxs)(x,{onClick:()=>i(!0),className:`gap-2 px-5`,children:[(0,M.jsx)(l,{className:`h-4 w-4`,"aria-hidden":`true`}),e(`gallery.generate`)]})}),(0,M.jsx)(F,{onImageCountChange:n},a),(0,M.jsx)(L,{isOpen:r,onClose:()=>i(!1),onImageGenerated:s})]})};export{R as GalleryPage,R as default};
|