ima2-gen 2.0.0 → 2.0.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/README.md +2 -11
- package/bin/commands/backfillThumbs.js +18 -0
- package/bin/commands/edit.js +7 -6
- package/bin/commands/gen.js +7 -6
- package/bin/commands/multimode.js +5 -4
- package/bin/commands/node.js +4 -4
- package/bin/ima2.js +7 -1
- package/bin/lib/config-store.js +1 -1
- package/docs/API.md +55 -4
- package/docs/CLI.md +9 -3
- package/docs/PROMPT_STUDIO.md +3 -1
- package/docs/migration/runtime-test-inventory.md +3 -1
- package/lib/agentRuntime.js +22 -16
- package/lib/agentSettings.js +1 -1
- package/lib/agyImageAdapter.js +232 -0
- package/lib/capabilities.js +2 -1
- package/lib/configKeys.js +1 -1
- package/lib/geminiApiImageAdapter.js +183 -0
- package/lib/grokImageAdapter.js +16 -9
- package/lib/grokMultimodeAdapter.js +2 -1
- package/lib/grokRuntime.js +3 -0
- package/lib/grokSizeMapper.js +13 -1
- package/lib/grokVideoAdapter.js +14 -7
- package/lib/historyList.js +18 -2
- package/lib/imageModels.js +15 -0
- package/lib/imageThumb.js +38 -0
- package/lib/providerOptions.js +36 -1
- package/lib/responsesFallback.js +52 -44
- package/lib/runtimeContext.js +27 -0
- package/lib/storageMigration.js +1 -1
- package/lib/thumbBackfill.js +59 -0
- package/lib/vertexAuth.js +44 -0
- package/lib/videoThumb.js +60 -0
- package/package.json +4 -2
- package/routes/auth.js +238 -0
- package/routes/edit.js +41 -7
- package/routes/generate.js +40 -12
- package/routes/history.js +13 -0
- package/routes/index.js +4 -0
- package/routes/keys.js +254 -0
- package/routes/multimode.js +39 -6
- package/routes/nodes.js +57 -35
- package/routes/quota.js +58 -7
- package/routes/video.js +7 -3
- package/server.js +123 -0
- package/ui/dist/.vite/manifest.json +12 -12
- package/ui/dist/assets/AgentWorkspace-CYv84Rus.js +3 -0
- package/ui/dist/assets/{CardNewsWorkspace-BN-ga1lG.js → CardNewsWorkspace-Dqyc1WZ1.js} +2 -2
- package/ui/dist/assets/{NodeCanvas-BbMa4IhI.js → NodeCanvas-ChEXzQbb.js} +2 -2
- package/ui/dist/assets/{PromptBuilderPanel-DRwBJRDQ.js → PromptBuilderPanel-B95ZufnR.js} +1 -1
- package/ui/dist/assets/{PromptImportDialog-Dp85kHCq.js → PromptImportDialog-DGOwFQET.js} +2 -2
- package/ui/dist/assets/{PromptImportDiscoverySection-BE8Q8MLD.js → PromptImportDiscoverySection-CgvdnR49.js} +1 -1
- package/ui/dist/assets/{PromptImportFolderSection-PtH5x0sc.js → PromptImportFolderSection-CfUye9J8.js} +1 -1
- package/ui/dist/assets/{PromptLibraryPanel-FnM9tHI9.js → PromptLibraryPanel-B9kndPw1.js} +2 -2
- package/ui/dist/assets/SettingsWorkspace-B3tgLrmF.js +1 -0
- package/ui/dist/assets/index-BhcvL0g-.js +1 -0
- package/ui/dist/assets/index-BtK3YhJc.js +39 -0
- package/ui/dist/assets/index-ClOLOjnA.css +1 -0
- package/ui/dist/index.html +2 -2
- package/ui/dist/assets/AgentWorkspace-C21zqdTZ.js +0 -3
- package/ui/dist/assets/SettingsWorkspace-MARPGyBL.js +0 -1
- package/ui/dist/assets/index-BAFI6htx.js +0 -42
- package/ui/dist/assets/index-BSXxr_Bt.js +0 -1
- package/ui/dist/assets/index-DS-ADE7U.css +0 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{J as I,K as S,b as u,u as f,j as t,a as _}from"./index-BtK3YhJc.js";function T(e){return e.filename??e.url??e.image}let M=0;function y(){return`pb_${Date.now()}_${++M}`}async function A(e){const n=y(),s=e.type.startsWith("image/")?"image":"file";if(s==="image"){const r=await new Promise(o=>{const l=new FileReader;l.onload=()=>o(l.result),l.readAsDataURL(e)});return{id:n,kind:s,name:e.name,mimeType:e.type,size:e.size,dataUrl:r}}return{id:n,kind:s,name:e.name,mimeType:e.type,size:e.size}}const p=I()((e,n)=>({messages:[],scope:{kind:"draft"},draft:"",model:"gpt-5.5",loading:!1,attachments:[],error:null,setDraft:s=>e({draft:s}),setModel:s=>e({model:s}),clearMessages:()=>e({messages:[],error:null}),clearImageScope:()=>e({scope:{kind:"draft"}}),setScopeFromImage:s=>{const r=T(s);e({scope:{kind:"image",imageKey:r}})},addAttachments:async s=>{const r=await Promise.all(s.map(A));e(o=>({attachments:[...o.attachments,...r]}))},removeAttachment:s=>{e(r=>({attachments:r.attachments.filter(o=>o.id!==s)}))},sendMessage:async s=>{const{draft:r,attachments:o,model:l,messages:i}=n(),d=r.trim()||(o.length>0?"Use the attached file as context and help with the prompt":"");if(!d&&o.length===0)return;const c={id:y(),role:"user",content:d,attachments:o.length>0?[...o]:void 0};e(m=>({messages:[...m.messages,c],draft:"",attachments:[],loading:!0,error:null}));try{const m=[...i,c].map(x=>({role:x.role,content:x.content,attachments:x.attachments?.map(h=>({kind:h.kind,name:h.name,mimeType:h.mimeType,size:h.size,dataUrl:h.dataUrl,text:h.text}))})),g=await S({model:l,messages:m,context:s}),j={id:y(),role:"assistant",content:g.message.content};e(x=>({messages:[...x.messages,j],loading:!1}))}catch(m){const g=m instanceof Error?m.message:"Prompt builder request failed";e({loading:!1,error:g})}}}));function P(e){return e?.filename??e?.url??e?.image??null}function C(e){const n=e.split(/[\\/]/).pop()??e;return n.length<=32?n:`${n.slice(0,14)}...${n.slice(-12)}`}function E(){const e=p(c=>c.scope),n=p(c=>c.clearImageScope),s=u(c=>c.currentImage),r=u(c=>c.history),{t:o}=f();if(e.kind==="draft")return t.jsx("span",{className:"prompt-builder__scope",children:o("promptBuilder.scopeDraft")});const i=P(s)===e.imageKey?s:r.find(c=>P(c)===e.imageKey)??null;if(!i)return t.jsx("span",{className:"prompt-builder__scope",children:o("promptBuilder.scopeDraft")});const d=o("promptBuilder.scopeImage",{name:C(e.imageKey)||o("promptBuilder.scopeImageFallback")});return t.jsxs("div",{className:"prompt-builder__scope-card",children:[t.jsx("img",{className:"prompt-builder__scope-thumb",src:i.thumb||i.url||i.image,alt:""}),t.jsx("span",{className:"prompt-builder__scope-name",children:d}),t.jsx("button",{type:"button",className:"prompt-builder__scope-remove",onClick:n,"aria-label":o("promptBuilder.removeScopeImage"),title:o("promptBuilder.removeScopeImage"),children:"×"})]})}const K=["gpt-5.5","gpt-5.4","gpt-5.4-mini"];function $(){const e=p(l=>l.model),n=p(l=>l.setModel),[s,r]=_.useState(!1),{t:o}=f();return t.jsxs("div",{className:"prompt-builder__model-picker",onBlur:l=>{const i=l.relatedTarget;i instanceof Node&&l.currentTarget.contains(i)||r(!1)},children:[t.jsx("button",{type:"button",className:"prompt-builder__model-trigger","aria-label":o("promptBuilder.model"),"aria-haspopup":"listbox","aria-expanded":s,onClick:()=>r(l=>!l),onKeyDown:l=>{l.key==="Escape"&&r(!1)},children:t.jsx("span",{children:e})}),s&&t.jsx("div",{className:"prompt-builder__model-menu",role:"listbox","aria-label":o("promptBuilder.model"),children:K.map(l=>t.jsx("button",{type:"button",role:"option","aria-selected":l===e,className:`prompt-builder__model-option${l===e?" active":""}`,onClick:()=>{n(l),r(!1)},children:l},l))})]})}const D={"Brief Intent Summary":"summary","Final Prompt - Korean":"ko","Final Prompt - English":"en",Notes:"notes"},F=/^(Brief Intent Summary|Final Prompt - Korean|Final Prompt - English|Notes):\s*(.*)$/gim;function w(e){const n=e.trim();return(n.match(/^```(?:[a-zA-Z0-9_-]+)?\s*([\s\S]*?)\s*```$/)?.[1]??n).trim()}function R(e){const n={},s=Array.from(e.matchAll(F));for(let r=0;r<s.length;r+=1){const o=s[r],l=o[1]??"",i=D[l];if(!i||typeof o.index!="number")continue;const d=o[2]?.trim()??"",c=o.index+o[0].length,m=s[r+1]?.index??e.length,g=w([d,e.slice(c,m)].filter(Boolean).join(`
|
|
2
2
|
`));g&&(n[i]=g)}return n}function z(e){const n=R(e),s=[];return n.ko&&s.push({language:"ko",heading:"Final Prompt - Korean",text:n.ko}),n.en&&s.push({language:"en",heading:"Final Prompt - English",text:n.en}),s.length===0?null:{summary:n.summary,prompts:s,notes:n.notes}}function U({messageId:e,prompt:n}){const s=u(m=>m.setPrompt),r=u(m=>m.insertPromptToComposer),o=u(m=>m.showToast),{t:l}=f(),i=n.language==="ko"?l("promptBuilder.finalKoreanPrompt"):l("promptBuilder.finalEnglishPrompt"),d=()=>{s(n.text),o(l("promptBuilder.applied"))},c=()=>{r({id:`builder_${e}_${n.language}`,name:i,text:n.text,placement:"after"}),o(l("promptBuilder.inserted"))};return t.jsxs("section",{className:"prompt-builder__structured-card","aria-label":i,children:[t.jsxs("div",{className:"prompt-builder__structured-card-header",children:[t.jsx("strong",{children:i}),t.jsx("span",{children:n.language.toUpperCase()})]}),t.jsx("p",{children:n.text}),t.jsxs("div",{className:"prompt-builder__structured-actions",children:[t.jsx("button",{type:"button",onClick:d,children:l("promptBuilder.applyToPrompt")}),t.jsx("button",{type:"button",onClick:c,children:l("promptBuilder.insertAsBlock")})]})]})}function L(e){return e.kind==="image"?"IMG":e.kind==="text"?"TXT":"FILE"}function O({message:e}){const{t:n}=f(),s=e.role==="assistant"?z(e.content):null;return t.jsxs("article",{className:`prompt-builder__message prompt-builder__message--${e.role}`,children:[t.jsx("div",{className:"prompt-builder__message-role",children:e.role==="user"?n("promptBuilder.user"):n("promptBuilder.assistant")}),s?t.jsxs("div",{className:"prompt-builder__structured-prompts",children:[s.summary?t.jsx("p",{className:"prompt-builder__structured-summary",children:s.summary}):null,s.prompts.map(r=>t.jsx(U,{messageId:e.id,prompt:r},`${e.id}-${r.language}`)),s.notes?t.jsx("p",{className:"prompt-builder__structured-notes",children:s.notes}):null]}):t.jsx("p",{children:e.content}),e.attachments&&e.attachments.length>0?t.jsx("div",{className:"prompt-builder__message-attachments",children:e.attachments.map(r=>t.jsxs("span",{className:"prompt-builder__message-attachment",children:[r.kind==="image"&&r.dataUrl?t.jsx("img",{src:r.dataUrl,alt:""}):t.jsx("span",{children:L(r)}),t.jsx("em",{children:r.name})]},r.id))}):null]})}function q(){const e=p(o=>o.messages),n=p(o=>o.loading),s=_.useRef(null),{t:r}=f();return _.useEffect(()=>{const o=s.current;o&&(o.scrollTop=o.scrollHeight)},[e.length,n]),t.jsxs("div",{ref:s,className:"prompt-builder__messages",children:[e.length===0&&t.jsx("div",{className:"prompt-builder__empty",children:r("promptBuilder.empty")}),e.map(o=>t.jsx(O,{message:o},o.id)),n&&t.jsxs("div",{className:"prompt-builder__thinking",role:"status","aria-live":"polite",children:[t.jsxs("span",{className:"prompt-builder__thinking-dots","aria-hidden":"true",children:[t.jsx("span",{}),t.jsx("span",{}),t.jsx("span",{})]}),t.jsx("span",{children:r("promptBuilder.thinking")})]})]})}function G(e){return e.kind==="image"?"IMG":e.kind==="text"?"TXT":"FILE"}function H(){const e=p(r=>r.attachments),n=p(r=>r.removeAttachment),{t:s}=f();return e.length===0?null:t.jsx("div",{className:"prompt-builder__attachments",children:e.map(r=>t.jsxs("span",{className:"prompt-builder__attachment",children:[r.kind==="image"&&r.dataUrl?t.jsx("img",{src:r.dataUrl,alt:""}):t.jsx("span",{children:G(r)}),t.jsx("em",{children:r.name}),t.jsx("button",{type:"button",onClick:()=>n(r.id),"aria-label":s("promptBuilder.removeAttachment",{name:r.name}),title:s("promptBuilder.removeAttachment",{name:r.name}),children:"×"})]},r.id))})}function X(){const e=p(a=>a.draft),n=p(a=>a.setDraft),s=p(a=>a.loading),r=p(a=>a.addAttachments),o=p(a=>a.sendMessage),l=p(a=>a.messages),i=p(a=>a.clearMessages),d=p(a=>a.attachments),c=u(a=>a.prompt),m=u(a=>a.insertedPrompts),g=u(a=>a.quality),j=u(a=>a.getResolvedSize),x=u(a=>a.currentImage),h=_.useRef(null),{t:b}=f(),B=()=>{!e.trim()&&d.length===0||s||o({currentPrompt:c,insertedPrompts:m.map(a=>({name:a.name,text:a.text})),settings:{quality:g,size:j()},currentResultPrompt:x?.prompt??null})},N=a=>{a.length!==0&&r(a)},v=a=>{const k=Array.from(a.clipboardData?.files??[]);k.length!==0&&(a.preventDefault(),N(k))};return t.jsxs("div",{className:"prompt-builder__composer",children:[t.jsx(H,{}),t.jsx("textarea",{value:e,placeholder:b("promptBuilder.placeholder"),onChange:a=>n(a.target.value),onPaste:v,onKeyDown:a=>{a.key==="Enter"&&(a.ctrlKey||a.metaKey)&&(a.preventDefault(),B())}}),t.jsx("input",{ref:h,type:"file",multiple:!0,hidden:!0,onChange:a=>{N(Array.from(a.target.files??[])),a.target.value=""}}),t.jsxs("div",{className:"prompt-builder__composer-actions",children:[t.jsx("button",{type:"button",className:"prompt-builder__attach",onClick:()=>h.current?.click(),disabled:s,"aria-label":b("promptBuilder.attach"),title:b("promptBuilder.attach"),children:"+"}),t.jsx("button",{type:"button",className:"prompt-builder__clear",onClick:i,disabled:l.length===0||s,children:b("promptBuilder.clear")}),t.jsx("button",{type:"button",className:"prompt-builder__send",onClick:B,disabled:!e.trim()&&d.length===0||s,children:b(s?"promptBuilder.sending":"promptBuilder.send")})]})]})}function W({variant:e="panel"}){const{t:n}=f();return t.jsxs("section",{className:`prompt-builder prompt-builder--${e}`,"aria-label":n("promptBuilder.title"),children:[t.jsxs("div",{className:"prompt-builder__header",children:[t.jsxs("div",{children:[t.jsx("span",{className:"section-title",children:n("promptBuilder.title")}),t.jsx(E,{})]}),t.jsx("div",{className:"prompt-builder__header-actions",children:t.jsx($,{})})]}),t.jsx(q,{}),t.jsx(X,{})]})}export{W as PromptBuilderPanel};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/PromptImportDiscoverySection-
|
|
2
|
-
import{u as V,j as e,b as ce,a as o,K as U,L as M,N as pe,O as de,P as me,_ as J}from"./index-BAFI6htx.js";function ue(i){const t=i.source;if(!t)return"";if(t.owner&&t.repo){const u=t.ref?`@${t.ref}`:"",s=t.path?`:${t.path}`:"";return`${t.owner}/${t.repo}${u}${s}`}return t.filename??t.sourceId??t.kind??""}function he(i,t){const u=i.tags.find(s=>s.toLowerCase().startsWith(t));return u?u.slice(t.length):null}function be(i){return i.tags.includes("attribution-required")||i.warnings?.some(t=>t.toLowerCase().includes("attribution"))===!0}function ge({candidate:i,selected:t,disabled:u=!1,onToggleSelected:s,onImportOne:g}){const{t:n}=V();if(!i)return e.jsx("aside",{className:"prompt-import-dialog__candidate-preview","aria-label":n("promptLibrary.previewPrompt"),children:e.jsx("div",{className:"prompt-import-dialog__empty",children:n("promptLibrary.importPreviewEmpty")})});const x=ue(i),v=he(i,"license:"),h=be(i);return e.jsxs("aside",{className:"prompt-import-dialog__candidate-preview","aria-label":n("promptLibrary.previewPrompt"),children:[e.jsxs("div",{className:"prompt-import-dialog__preview-header",children:[e.jsxs("div",{children:[e.jsx("span",{children:n("promptLibrary.previewPrompt")}),e.jsx("h4",{children:i.name})]}),e.jsx("button",{type:"button",onClick:()=>g(i),disabled:u,children:n("promptLibrary.importThisPrompt")})]}),e.jsxs("label",{className:"prompt-import-dialog__preview-select",children:[e.jsx("input",{type:"checkbox",checked:t,disabled:u,onChange:l=>s(i.id,l.target.checked)}),e.jsx("span",{children:n(t?"promptLibrary.selectedPrompt":"promptLibrary.selectPrompt")})]}),e.jsxs("div",{className:"prompt-import-dialog__preview-field",children:[e.jsx("strong",{children:n("promptLibrary.promptText")}),e.jsx("p",{children:i.text})]}),i.tags.length>0?e.jsxs("div",{className:"prompt-import-dialog__preview-field",children:[e.jsx("strong",{children:n("promptLibrary.tags")}),e.jsx("div",{className:"prompt-import-dialog__preview-chips",children:i.tags.map(l=>e.jsx("em",{children:l},l))})]}):null,i.warnings?.length?e.jsxs("div",{className:"prompt-import-dialog__preview-field",children:[e.jsx("strong",{children:n("promptLibrary.compatibilityWarnings")}),e.jsx("div",{className:"prompt-import-dialog__preview-chips",children:i.warnings.map(l=>e.jsx("b",{children:l},l))})]}):null,x||v||h?e.jsxs("div",{className:"prompt-import-dialog__preview-field",children:[e.jsx("strong",{children:n("promptLibrary.sourceDetails")}),x?e.jsx("small",{children:x}):null,v?e.jsxs("small",{children:[n("promptLibrary.license"),": ",v]}):null,h?e.jsx("small",{children:n("promptLibrary.attributionRequired")}):null]}):null]})}function fe(i){const t=i.source;if(!t)return"";if(t.owner&&t.repo){const u=t.path?` · ${t.path}`:"";return`github · ${t.owner}/${t.repo}${u}`}return t.filename?t.filename:t.sourceId?t.sourceId:t.kind??""}function ye(i){const t=i.replace(/\s+/g," ").trim();return t.length>220?`${t.slice(0,220)}...`:t}function xe({candidates:i,selectedIds:t,activeCandidateId:u,busy:s=!1,onSelectCandidate:g,onToggleSelected:n,onSelectAll:x,onClearSelection:v,onImportOne:h}){const{t:l}=V();if(i.length===0)return e.jsx("section",{className:"prompt-import-dialog__results","aria-label":l("promptLibrary.searchResults"),children:e.jsx("div",{className:"prompt-import-dialog__empty",children:l("promptLibrary.importPreviewEmpty")})});const f=i.every(p=>t.has(p.id));return e.jsxs("section",{className:"prompt-import-dialog__results","aria-label":l("promptLibrary.searchResults"),children:[e.jsxs("header",{className:"prompt-import-dialog__results-header",children:[e.jsx("strong",{children:l("promptLibrary.searchResultsHeader",{count:i.length})}),e.jsxs("div",{className:"prompt-import-dialog__results-header-actions",children:[e.jsx("button",{type:"button",onClick:x,disabled:f,children:l("promptLibrary.selectAllCandidates")}),e.jsx("button",{type:"button",onClick:v,disabled:t.size===0,children:l("promptLibrary.clearCandidateSelection")})]})]}),i.map(p=>{const y=t.has(p.id),S=u===p.id,j=fe(p);return e.jsxs("article",{className:`prompt-import-dialog__result-card${S?" active":""}`,children:[e.jsxs("button",{type:"button",className:"prompt-import-dialog__result-main",onClick:()=>g(p),children:[e.jsx("strong",{children:p.name}),e.jsx("span",{children:ye(p.text)}),j?e.jsx("small",{children:j}):null]}),e.jsxs("div",{className:"prompt-import-dialog__result-meta",children:[p.warnings?.slice(0,2).map(b=>e.jsx("b",{className:"prompt-import-dialog__hint-chip",children:b},b)),p.tags.slice(0,4).map(b=>e.jsx("em",{children:b},b))]}),e.jsxs("div",{className:"prompt-import-dialog__result-actions",children:[e.jsxs("label",{children:[e.jsx("input",{type:"checkbox",checked:y,onChange:b=>n(p.id,b.target.checked)}),e.jsx("span",{children:l(y?"promptLibrary.selectedPrompt":"promptLibrary.selectPrompt")})]}),e.jsx("button",{type:"button",onClick:()=>g(p),children:l("promptLibrary.previewPrompt")}),e.jsx("button",{type:"button",onClick:()=>h(p),disabled:s,children:l("promptLibrary.importThisPrompt")})]})]},p.id)})]})}const ve=o.lazy(()=>J(()=>import("./PromptImportDiscoverySection-BE8Q8MLD.js"),__vite__mapDeps([0,1,2])).then(i=>({default:i.PromptImportDiscoverySection}))),je=o.lazy(()=>J(()=>import("./PromptImportFolderSection-PtH5x0sc.js"),__vite__mapDeps([3,1,2])).then(i=>({default:i.PromptImportFolderSection}))),_e=/\.(txt|md|markdown)$/i;function Se({open:i,onClose:t,onImported:u}){const{t:s}=V(),g=ce(r=>r.showToast),n=o.useRef(null),x=o.useRef(null),v=o.useRef(null),[h,l]=o.useState(""),[f,p]=o.useState([]),[y,S]=o.useState(new Set),[j,b]=o.useState(null),[_,L]=o.useState(!1),[W,m]=o.useState(null),[X,N]=o.useState(!1),[Y,A]=o.useState([]),[$,Z]=o.useState(""),[P,z]=o.useState(new Set),[O,E]=o.useState(!1),[q,I]=o.useState([]),[C,B]=o.useState("curated"),[G,ee]=o.useState(!1),H=f.length>0,D=!H||G;o.useEffect(()=>{if(i)return v.current=document.activeElement,window.setTimeout(()=>x.current?.focus(),0),()=>v.current?.focus()},[i]);const re=o.useCallback(async()=>{const r=await U();A(r.sources),z(new Set)},[]);o.useEffect(()=>{if(!i)return;let r=!1;return U().then(a=>{r||(A(a.sources),z(new Set))}).catch(()=>{r||A([])}),()=>{r=!0}},[i]);const w=o.useCallback(r=>{p(a=>{const c=new Set(a.map(k=>k.id)),d=[...a];for(const k of r)c.has(k.id)||d.push(k);return b(k=>k??d[0]?.id??null),d})},[]),R=o.useCallback(async r=>{const a=r.filter(c=>_e.test(c.name));if(a.length===0){m(s("promptLibrary.importNoValidFiles"));return}L(!0),m(null);try{const c=[];for(const d of a)c.push(await M({source:{kind:"local",filename:d.name,text:await d.text()}}));w(c.flatMap(d=>d.candidates))}catch(c){m(c instanceof Error?c.message:s("promptLibrary.importFailed"))}finally{L(!1)}},[w,s]),te=o.useCallback(async()=>{if(h.trim()){L(!0),m(null);try{const r=await M({source:{kind:"github",input:h.trim()}});w(r.candidates)}catch(r){m(r instanceof Error?r.message:s("promptLibrary.importFailed"))}finally{L(!1)}}},[w,h,s]),se=o.useCallback(async()=>{E(!0),m(null),I([]);try{const r=await pe({q:$.trim(),sourceIds:[...P]});w(r.results),I(r.warnings),r.results.length===0&&m(s("promptLibrary.noCuratedResults"))}catch(r){m(r instanceof Error?r.message:s("promptLibrary.importFailed"))}finally{E(!1)}},[w,$,P,s]),ie=o.useCallback(async r=>{E(!0),m(null),I([]);try{const a=await de({sourceId:r});I(a.warnings),g(s("promptLibrary.curatedRefreshed",{count:a.candidateCount}))}catch(a){m(a instanceof Error?a.message:s("promptLibrary.importFailed"))}finally{E(!1)}},[g,s]),K=o.useCallback((r,a)=>{S(c=>{const d=new Set(c);return a?d.add(r):d.delete(r),d})},[]),oe=o.useCallback(()=>{S(new Set(f.map(r=>r.id)))},[f]),ae=o.useCallback(()=>{S(new Set)},[]),T=o.useCallback(async r=>{if(r.length===0){m(s("promptLibrary.importSelectAtLeastOne"));return}L(!0),m(null);try{const a=await me({candidates:r});await u(),g(s("promptLibrary.imported",{count:a.promptsImported})),t()}catch(a){m(a instanceof Error?a.message:s("promptLibrary.importFailed"))}finally{L(!1)}},[t,u,g,s]),le=o.useCallback(async()=>{const r=f.filter(a=>y.has(a.id));await T(r)},[f,T,y]),Q=o.useCallback(r=>{S(new Set([r.id])),T([r])},[T]),ne=o.useCallback(r=>{const a=Array.from(r.target.files??[]);a.length>0&&R(a),r.target.value=""},[R]),F=o.useCallback(r=>{r.preventDefault(),r.stopPropagation(),N(!1);const a=Array.from(r.dataTransfer?.files??[]);a.length>0&&R(a)},[R]);return o.useEffect(()=>{if(!i)return;const r=c=>{c.preventDefault(),N(!0)},a=c=>{c.relatedTarget===null&&N(!1)};return window.addEventListener("dragover",r),window.addEventListener("dragleave",a),window.addEventListener("drop",F),()=>{window.removeEventListener("dragover",r),window.removeEventListener("dragleave",a),window.removeEventListener("drop",F)}},[F,i]),i?e.jsxs("div",{className:"prompt-import-dialog",role:"presentation",children:[e.jsx("div",{className:"prompt-import-dialog__backdrop",onClick:t}),e.jsxs("div",{ref:x,className:"prompt-import-dialog__panel",role:"dialog","aria-modal":"true","aria-labelledby":"prompt-import-title",tabIndex:-1,onKeyDown:r=>{r.key==="Escape"&&t()},children:[e.jsxs("div",{className:"prompt-import-dialog__header",children:[e.jsx("h3",{id:"prompt-import-title",children:s("promptLibrary.importTitle")}),e.jsx("button",{type:"button",onClick:t,"aria-label":s("common.close"),children:"×"})]}),D&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:`prompt-import-dialog__dropzone${X?" active":""}`,onDragOver:r=>{r.preventDefault(),N(!0)},onDragLeave:()=>N(!1),onDrop:F,children:[e.jsx("strong",{children:s("promptLibrary.importDropTitle")}),e.jsx("span",{children:s("promptLibrary.importDropHint")}),e.jsx("button",{type:"button",onClick:()=>n.current?.click(),children:s("promptLibrary.importChooseFiles")}),e.jsx("input",{ref:n,className:"prompt-library-panel__file-input",type:"file",accept:".txt,.md,.markdown,text/plain,text/markdown",multiple:!0,onChange:ne})]}),e.jsxs("div",{className:"prompt-import-dialog__github",children:[e.jsx("label",{htmlFor:"prompt-import-github",children:s("promptLibrary.importGithubLabel")}),e.jsxs("div",{children:[e.jsx("input",{id:"prompt-import-github",type:"text",value:h,onChange:r=>l(r.target.value),placeholder:"owner/repo:path/to/prompts.md"}),e.jsx("button",{type:"button",onClick:()=>{te()},disabled:_||!h.trim(),children:s("promptLibrary.importPreview")})]})]}),e.jsx(o.Suspense,{fallback:null,children:e.jsx(je,{input:h,disabled:_,onCandidates:w,onError:m})}),e.jsxs("div",{className:"prompt-import-dialog__source-tabs",role:"tablist","aria-label":s("promptLibrary.curatedSources"),children:[e.jsx("button",{type:"button",className:C==="curated"?"active":"",onClick:()=>B("curated"),"aria-pressed":C==="curated",children:s("promptLibrary.curatedSources")}),e.jsx("button",{type:"button",className:C==="discovery"?"active":"",onClick:()=>B("discovery"),"aria-pressed":C==="discovery",children:s("promptLibrary.discovery")})]})]}),(D?C==="curated":!0)&&e.jsxs("div",{className:"prompt-import-dialog__curated",children:[D&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"prompt-import-dialog__section-title",children:[e.jsx("strong",{children:s("promptLibrary.curatedSources")}),e.jsx("span",{children:s("promptLibrary.curatedSourcesHint")})]}),e.jsx("div",{className:"prompt-import-dialog__source-list",children:Y.filter(r=>r.trustTier!=="manual-review").map(r=>e.jsxs("label",{className:"prompt-import-dialog__source",children:[e.jsx("input",{type:"checkbox",checked:P.has(r.id),onChange:a=>{z(c=>{const d=new Set(c);return a.target.checked?d.add(r.id):d.delete(r.id),d})}}),e.jsxs("span",{children:[e.jsx("strong",{children:r.displayName}),e.jsxs("small",{children:[r.licenseSpdx," · ",r.trustTier]})]}),e.jsx("button",{type:"button",onClick:()=>{ie(r.id)},disabled:O,children:s("promptLibrary.refreshSource")})]},r.id))})]}),e.jsxs("div",{className:"prompt-import-dialog__search-results",children:[e.jsx("input",{type:"text",value:$,onChange:r=>Z(r.target.value),placeholder:s("promptLibrary.curatedSearchPlaceholder"),"aria-label":s("promptLibrary.curatedSearch")}),e.jsx("button",{type:"button",onClick:()=>{se()},disabled:O||P.size===0,children:s(O?"common.loading":"promptLibrary.curatedSearch")})]}),q.length>0?e.jsx("div",{className:"prompt-import-dialog__warning",children:q.slice(0,3).join(" · ")}):null]}),D&&C==="discovery"&&e.jsx(o.Suspense,{fallback:e.jsx("div",{className:"prompt-import-dialog__empty",children:s("common.loading")}),children:e.jsx(ve,{disabled:_,onError:m,onSourcesChanged:re})}),H&&!G&&e.jsx("button",{type:"button",className:"prompt-import-dialog__add-source-toggle",onClick:()=>ee(!0),children:s("promptLibrary.addAnotherSource")}),W?e.jsx("div",{className:"prompt-import-dialog__error",role:"alert",children:W}):null,e.jsxs("div",{className:"prompt-import-dialog__workspace","aria-live":"polite",children:[e.jsx(xe,{candidates:f,selectedIds:y,activeCandidateId:j,busy:_,onSelectCandidate:r=>b(r.id),onToggleSelected:K,onSelectAll:oe,onClearSelection:ae,onImportOne:Q}),e.jsx(ge,{candidate:f.find(r=>r.id===j)??null,selected:j?y.has(j):!1,disabled:_,onToggleSelected:K,onImportOne:Q})]}),e.jsxs("div",{className:"prompt-import-dialog__footer",children:[e.jsx("button",{type:"button",onClick:t,children:s("common.cancel")}),e.jsx("button",{type:"button",onClick:()=>{le()},disabled:_||y.size===0,children:_?s("common.loading"):s("promptLibrary.importSelected",{count:y.size})})]})]})]}):null}export{Se as PromptImportDialog};
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/PromptImportDiscoverySection-CgvdnR49.js","assets/index-BtK3YhJc.js","assets/index-ClOLOjnA.css","assets/PromptImportFolderSection-CfUye9J8.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{u as V,j as e,b as ce,a as o,L as K,N as M,O as pe,P as de,Q as me,_ as J}from"./index-BtK3YhJc.js";function ue(i){const t=i.source;if(!t)return"";if(t.owner&&t.repo){const u=t.ref?`@${t.ref}`:"",s=t.path?`:${t.path}`:"";return`${t.owner}/${t.repo}${u}${s}`}return t.filename??t.sourceId??t.kind??""}function he(i,t){const u=i.tags.find(s=>s.toLowerCase().startsWith(t));return u?u.slice(t.length):null}function be(i){return i.tags.includes("attribution-required")||i.warnings?.some(t=>t.toLowerCase().includes("attribution"))===!0}function ge({candidate:i,selected:t,disabled:u=!1,onToggleSelected:s,onImportOne:g}){const{t:n}=V();if(!i)return e.jsx("aside",{className:"prompt-import-dialog__candidate-preview","aria-label":n("promptLibrary.previewPrompt"),children:e.jsx("div",{className:"prompt-import-dialog__empty",children:n("promptLibrary.importPreviewEmpty")})});const x=ue(i),v=he(i,"license:"),h=be(i);return e.jsxs("aside",{className:"prompt-import-dialog__candidate-preview","aria-label":n("promptLibrary.previewPrompt"),children:[e.jsxs("div",{className:"prompt-import-dialog__preview-header",children:[e.jsxs("div",{children:[e.jsx("span",{children:n("promptLibrary.previewPrompt")}),e.jsx("h4",{children:i.name})]}),e.jsx("button",{type:"button",onClick:()=>g(i),disabled:u,children:n("promptLibrary.importThisPrompt")})]}),e.jsxs("label",{className:"prompt-import-dialog__preview-select",children:[e.jsx("input",{type:"checkbox",checked:t,disabled:u,onChange:l=>s(i.id,l.target.checked)}),e.jsx("span",{children:n(t?"promptLibrary.selectedPrompt":"promptLibrary.selectPrompt")})]}),e.jsxs("div",{className:"prompt-import-dialog__preview-field",children:[e.jsx("strong",{children:n("promptLibrary.promptText")}),e.jsx("p",{children:i.text})]}),i.tags.length>0?e.jsxs("div",{className:"prompt-import-dialog__preview-field",children:[e.jsx("strong",{children:n("promptLibrary.tags")}),e.jsx("div",{className:"prompt-import-dialog__preview-chips",children:i.tags.map(l=>e.jsx("em",{children:l},l))})]}):null,i.warnings?.length?e.jsxs("div",{className:"prompt-import-dialog__preview-field",children:[e.jsx("strong",{children:n("promptLibrary.compatibilityWarnings")}),e.jsx("div",{className:"prompt-import-dialog__preview-chips",children:i.warnings.map(l=>e.jsx("b",{children:l},l))})]}):null,x||v||h?e.jsxs("div",{className:"prompt-import-dialog__preview-field",children:[e.jsx("strong",{children:n("promptLibrary.sourceDetails")}),x?e.jsx("small",{children:x}):null,v?e.jsxs("small",{children:[n("promptLibrary.license"),": ",v]}):null,h?e.jsx("small",{children:n("promptLibrary.attributionRequired")}):null]}):null]})}function fe(i){const t=i.source;if(!t)return"";if(t.owner&&t.repo){const u=t.path?` · ${t.path}`:"";return`github · ${t.owner}/${t.repo}${u}`}return t.filename?t.filename:t.sourceId?t.sourceId:t.kind??""}function ye(i){const t=i.replace(/\s+/g," ").trim();return t.length>220?`${t.slice(0,220)}...`:t}function xe({candidates:i,selectedIds:t,activeCandidateId:u,busy:s=!1,onSelectCandidate:g,onToggleSelected:n,onSelectAll:x,onClearSelection:v,onImportOne:h}){const{t:l}=V();if(i.length===0)return e.jsx("section",{className:"prompt-import-dialog__results","aria-label":l("promptLibrary.searchResults"),children:e.jsx("div",{className:"prompt-import-dialog__empty",children:l("promptLibrary.importPreviewEmpty")})});const f=i.every(p=>t.has(p.id));return e.jsxs("section",{className:"prompt-import-dialog__results","aria-label":l("promptLibrary.searchResults"),children:[e.jsxs("header",{className:"prompt-import-dialog__results-header",children:[e.jsx("strong",{children:l("promptLibrary.searchResultsHeader",{count:i.length})}),e.jsxs("div",{className:"prompt-import-dialog__results-header-actions",children:[e.jsx("button",{type:"button",onClick:x,disabled:f,children:l("promptLibrary.selectAllCandidates")}),e.jsx("button",{type:"button",onClick:v,disabled:t.size===0,children:l("promptLibrary.clearCandidateSelection")})]})]}),i.map(p=>{const y=t.has(p.id),S=u===p.id,j=fe(p);return e.jsxs("article",{className:`prompt-import-dialog__result-card${S?" active":""}`,children:[e.jsxs("button",{type:"button",className:"prompt-import-dialog__result-main",onClick:()=>g(p),children:[e.jsx("strong",{children:p.name}),e.jsx("span",{children:ye(p.text)}),j?e.jsx("small",{children:j}):null]}),e.jsxs("div",{className:"prompt-import-dialog__result-meta",children:[p.warnings?.slice(0,2).map(b=>e.jsx("b",{className:"prompt-import-dialog__hint-chip",children:b},b)),p.tags.slice(0,4).map(b=>e.jsx("em",{children:b},b))]}),e.jsxs("div",{className:"prompt-import-dialog__result-actions",children:[e.jsxs("label",{children:[e.jsx("input",{type:"checkbox",checked:y,onChange:b=>n(p.id,b.target.checked)}),e.jsx("span",{children:l(y?"promptLibrary.selectedPrompt":"promptLibrary.selectPrompt")})]}),e.jsx("button",{type:"button",onClick:()=>g(p),children:l("promptLibrary.previewPrompt")}),e.jsx("button",{type:"button",onClick:()=>h(p),disabled:s,children:l("promptLibrary.importThisPrompt")})]})]},p.id)})]})}const ve=o.lazy(()=>J(()=>import("./PromptImportDiscoverySection-CgvdnR49.js"),__vite__mapDeps([0,1,2])).then(i=>({default:i.PromptImportDiscoverySection}))),je=o.lazy(()=>J(()=>import("./PromptImportFolderSection-CfUye9J8.js"),__vite__mapDeps([3,1,2])).then(i=>({default:i.PromptImportFolderSection}))),_e=/\.(txt|md|markdown)$/i;function Se({open:i,onClose:t,onImported:u}){const{t:s}=V(),g=ce(r=>r.showToast),n=o.useRef(null),x=o.useRef(null),v=o.useRef(null),[h,l]=o.useState(""),[f,p]=o.useState([]),[y,S]=o.useState(new Set),[j,b]=o.useState(null),[_,L]=o.useState(!1),[W,m]=o.useState(null),[X,N]=o.useState(!1),[Y,A]=o.useState([]),[$,Z]=o.useState(""),[P,z]=o.useState(new Set),[O,E]=o.useState(!1),[q,I]=o.useState([]),[C,B]=o.useState("curated"),[G,ee]=o.useState(!1),H=f.length>0,D=!H||G;o.useEffect(()=>{if(i)return v.current=document.activeElement,window.setTimeout(()=>x.current?.focus(),0),()=>v.current?.focus()},[i]);const re=o.useCallback(async()=>{const r=await K();A(r.sources),z(new Set)},[]);o.useEffect(()=>{if(!i)return;let r=!1;return K().then(a=>{r||(A(a.sources),z(new Set))}).catch(()=>{r||A([])}),()=>{r=!0}},[i]);const w=o.useCallback(r=>{p(a=>{const c=new Set(a.map(k=>k.id)),d=[...a];for(const k of r)c.has(k.id)||d.push(k);return b(k=>k??d[0]?.id??null),d})},[]),R=o.useCallback(async r=>{const a=r.filter(c=>_e.test(c.name));if(a.length===0){m(s("promptLibrary.importNoValidFiles"));return}L(!0),m(null);try{const c=[];for(const d of a)c.push(await M({source:{kind:"local",filename:d.name,text:await d.text()}}));w(c.flatMap(d=>d.candidates))}catch(c){m(c instanceof Error?c.message:s("promptLibrary.importFailed"))}finally{L(!1)}},[w,s]),te=o.useCallback(async()=>{if(h.trim()){L(!0),m(null);try{const r=await M({source:{kind:"github",input:h.trim()}});w(r.candidates)}catch(r){m(r instanceof Error?r.message:s("promptLibrary.importFailed"))}finally{L(!1)}}},[w,h,s]),se=o.useCallback(async()=>{E(!0),m(null),I([]);try{const r=await pe({q:$.trim(),sourceIds:[...P]});w(r.results),I(r.warnings),r.results.length===0&&m(s("promptLibrary.noCuratedResults"))}catch(r){m(r instanceof Error?r.message:s("promptLibrary.importFailed"))}finally{E(!1)}},[w,$,P,s]),ie=o.useCallback(async r=>{E(!0),m(null),I([]);try{const a=await de({sourceId:r});I(a.warnings),g(s("promptLibrary.curatedRefreshed",{count:a.candidateCount}))}catch(a){m(a instanceof Error?a.message:s("promptLibrary.importFailed"))}finally{E(!1)}},[g,s]),Q=o.useCallback((r,a)=>{S(c=>{const d=new Set(c);return a?d.add(r):d.delete(r),d})},[]),oe=o.useCallback(()=>{S(new Set(f.map(r=>r.id)))},[f]),ae=o.useCallback(()=>{S(new Set)},[]),T=o.useCallback(async r=>{if(r.length===0){m(s("promptLibrary.importSelectAtLeastOne"));return}L(!0),m(null);try{const a=await me({candidates:r});await u(),g(s("promptLibrary.imported",{count:a.promptsImported})),t()}catch(a){m(a instanceof Error?a.message:s("promptLibrary.importFailed"))}finally{L(!1)}},[t,u,g,s]),le=o.useCallback(async()=>{const r=f.filter(a=>y.has(a.id));await T(r)},[f,T,y]),U=o.useCallback(r=>{S(new Set([r.id])),T([r])},[T]),ne=o.useCallback(r=>{const a=Array.from(r.target.files??[]);a.length>0&&R(a),r.target.value=""},[R]),F=o.useCallback(r=>{r.preventDefault(),r.stopPropagation(),N(!1);const a=Array.from(r.dataTransfer?.files??[]);a.length>0&&R(a)},[R]);return o.useEffect(()=>{if(!i)return;const r=c=>{c.preventDefault(),N(!0)},a=c=>{c.relatedTarget===null&&N(!1)};return window.addEventListener("dragover",r),window.addEventListener("dragleave",a),window.addEventListener("drop",F),()=>{window.removeEventListener("dragover",r),window.removeEventListener("dragleave",a),window.removeEventListener("drop",F)}},[F,i]),i?e.jsxs("div",{className:"prompt-import-dialog",role:"presentation",children:[e.jsx("div",{className:"prompt-import-dialog__backdrop",onClick:t}),e.jsxs("div",{ref:x,className:"prompt-import-dialog__panel",role:"dialog","aria-modal":"true","aria-labelledby":"prompt-import-title",tabIndex:-1,onKeyDown:r=>{r.key==="Escape"&&t()},children:[e.jsxs("div",{className:"prompt-import-dialog__header",children:[e.jsx("h3",{id:"prompt-import-title",children:s("promptLibrary.importTitle")}),e.jsx("button",{type:"button",onClick:t,"aria-label":s("common.close"),children:"×"})]}),D&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:`prompt-import-dialog__dropzone${X?" active":""}`,onDragOver:r=>{r.preventDefault(),N(!0)},onDragLeave:()=>N(!1),onDrop:F,children:[e.jsx("strong",{children:s("promptLibrary.importDropTitle")}),e.jsx("span",{children:s("promptLibrary.importDropHint")}),e.jsx("button",{type:"button",onClick:()=>n.current?.click(),children:s("promptLibrary.importChooseFiles")}),e.jsx("input",{ref:n,className:"prompt-library-panel__file-input",type:"file",accept:".txt,.md,.markdown,text/plain,text/markdown",multiple:!0,onChange:ne})]}),e.jsxs("div",{className:"prompt-import-dialog__github",children:[e.jsx("label",{htmlFor:"prompt-import-github",children:s("promptLibrary.importGithubLabel")}),e.jsxs("div",{children:[e.jsx("input",{id:"prompt-import-github",type:"text",value:h,onChange:r=>l(r.target.value),placeholder:"owner/repo:path/to/prompts.md"}),e.jsx("button",{type:"button",onClick:()=>{te()},disabled:_||!h.trim(),children:s("promptLibrary.importPreview")})]})]}),e.jsx(o.Suspense,{fallback:null,children:e.jsx(je,{input:h,disabled:_,onCandidates:w,onError:m})}),e.jsxs("div",{className:"prompt-import-dialog__source-tabs",role:"tablist","aria-label":s("promptLibrary.curatedSources"),children:[e.jsx("button",{type:"button",className:C==="curated"?"active":"",onClick:()=>B("curated"),"aria-pressed":C==="curated",children:s("promptLibrary.curatedSources")}),e.jsx("button",{type:"button",className:C==="discovery"?"active":"",onClick:()=>B("discovery"),"aria-pressed":C==="discovery",children:s("promptLibrary.discovery")})]})]}),(D?C==="curated":!0)&&e.jsxs("div",{className:"prompt-import-dialog__curated",children:[D&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"prompt-import-dialog__section-title",children:[e.jsx("strong",{children:s("promptLibrary.curatedSources")}),e.jsx("span",{children:s("promptLibrary.curatedSourcesHint")})]}),e.jsx("div",{className:"prompt-import-dialog__source-list",children:Y.filter(r=>r.trustTier!=="manual-review").map(r=>e.jsxs("label",{className:"prompt-import-dialog__source",children:[e.jsx("input",{type:"checkbox",checked:P.has(r.id),onChange:a=>{z(c=>{const d=new Set(c);return a.target.checked?d.add(r.id):d.delete(r.id),d})}}),e.jsxs("span",{children:[e.jsx("strong",{children:r.displayName}),e.jsxs("small",{children:[r.licenseSpdx," · ",r.trustTier]})]}),e.jsx("button",{type:"button",onClick:()=>{ie(r.id)},disabled:O,children:s("promptLibrary.refreshSource")})]},r.id))})]}),e.jsxs("div",{className:"prompt-import-dialog__search-results",children:[e.jsx("input",{type:"text",value:$,onChange:r=>Z(r.target.value),placeholder:s("promptLibrary.curatedSearchPlaceholder"),"aria-label":s("promptLibrary.curatedSearch")}),e.jsx("button",{type:"button",onClick:()=>{se()},disabled:O||P.size===0,children:s(O?"common.loading":"promptLibrary.curatedSearch")})]}),q.length>0?e.jsx("div",{className:"prompt-import-dialog__warning",children:q.slice(0,3).join(" · ")}):null]}),D&&C==="discovery"&&e.jsx(o.Suspense,{fallback:e.jsx("div",{className:"prompt-import-dialog__empty",children:s("common.loading")}),children:e.jsx(ve,{disabled:_,onError:m,onSourcesChanged:re})}),H&&!G&&e.jsx("button",{type:"button",className:"prompt-import-dialog__add-source-toggle",onClick:()=>ee(!0),children:s("promptLibrary.addAnotherSource")}),W?e.jsx("div",{className:"prompt-import-dialog__error",role:"alert",children:W}):null,e.jsxs("div",{className:"prompt-import-dialog__workspace","aria-live":"polite",children:[e.jsx(xe,{candidates:f,selectedIds:y,activeCandidateId:j,busy:_,onSelectCandidate:r=>b(r.id),onToggleSelected:Q,onSelectAll:oe,onClearSelection:ae,onImportOne:U}),e.jsx(ge,{candidate:f.find(r=>r.id===j)??null,selected:j?y.has(j):!1,disabled:_,onToggleSelected:Q,onImportOne:U})]}),e.jsxs("div",{className:"prompt-import-dialog__footer",children:[e.jsx("button",{type:"button",onClick:t,children:s("common.cancel")}),e.jsx("button",{type:"button",onClick:()=>{le()},disabled:_||y.size===0,children:_?s("common.loading"):s("promptLibrary.importSelected",{count:y.size})})]})]})]}):null}export{Se as PromptImportDialog};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{u as L,a as t,
|
|
1
|
+
import{u as L,a as t,V as S,X as C,Y as P,j as r}from"./index-BtK3YhJc.js";const R=["gpt-image-2 prompt","nano banana prompts","typography image prompt"];function k({disabled:d=!1,onError:a,onSourcesChanged:y}){const{t:s}=L(),[l,N]=t.useState("gpt-image-2 prompt"),[v,p]=t.useState([]),[n,c]=t.useState(!1),[g,m]=t.useState([]),[h,_]=t.useState({});t.useEffect(()=>{let e=!1;return S().then(i=>{e||p(i.candidates)}).catch(()=>{e||p([])}),()=>{e=!0}},[]);const w=t.useCallback(async()=>{c(!0),m([]),a(null);try{const e=await C({q:l.trim(),seeds:R});p(e.candidates),m([...e.warnings,...e.rateLimit?.remaining===0?["github-rate-limit-exhausted"]:[]]),e.candidates.length===0&&a(s("promptLibrary.discoveryNoResults"))}catch(e){a(e instanceof Error?e.message:s("promptLibrary.importFailed"))}finally{c(!1)}},[a,l,s]),x=t.useCallback(async(e,i)=>{c(!0),m([]),a(null);try{const j=(h[e.fullName]||"").split(/\r?\n|,/).map(u=>u.trim()).filter(Boolean),b=await P({repo:e.fullName,status:i,allowedPaths:i==="approved"?j:[],defaultSearch:i==="approved"&&j.length>0});m(b.warnings),p(u=>u.map(f=>f.fullName===e.fullName?b.candidate:f)),await y()}catch(o){a(o instanceof Error?o.message:s("promptLibrary.importFailed"))}finally{c(!1)}},[h,a,y,s]);return r.jsxs("div",{className:"prompt-import-dialog__discovery",children:[r.jsxs("div",{className:"prompt-import-dialog__section-title",children:[r.jsx("strong",{children:s("promptLibrary.discovery")}),r.jsx("span",{children:s("promptLibrary.discoveryReviewQueue")})]}),r.jsxs("div",{className:"prompt-import-dialog__discovery-actions",children:[r.jsx("input",{type:"text",value:l,onChange:e=>N(e.target.value),placeholder:s("promptLibrary.discoverySearchPlaceholder"),"aria-label":s("promptLibrary.discoverySearch")}),r.jsx("button",{type:"button",onClick:()=>{w()},disabled:d||n||!l.trim(),children:s(n?"common.loading":"promptLibrary.discoverySearch")})]}),g.length>0?r.jsx("div",{className:"prompt-import-dialog__discovery-warning",children:g.slice(0,3).join(" · ")}):null,v.length===0?r.jsx("div",{className:"prompt-import-dialog__empty",children:s("promptLibrary.discoveryNoResults")}):r.jsx("div",{className:"prompt-import-dialog__discovery-list",children:v.map(e=>r.jsxs("article",{className:"prompt-import-dialog__discovery-candidate",children:[r.jsxs("div",{children:[r.jsx("strong",{children:e.fullName}),r.jsx("small",{children:e.description||e.htmlUrl})]}),r.jsxs("div",{className:"prompt-import-dialog__score",children:[r.jsxs("span",{children:[s("promptLibrary.discoveryScore"),": ",e.score]}),r.jsx("span",{children:e.licenseSpdx}),r.jsx("span",{children:e.status})]}),e.scoreReasons.length>0?r.jsx("em",{children:e.scoreReasons.slice(0,3).join(" · ")}):null,e.warnings.length>0?r.jsx("b",{children:e.warnings.slice(0,2).join(" · ")}):null,r.jsx("textarea",{value:h[e.fullName]||"",onChange:i=>_(o=>({...o,[e.fullName]:i.target.value})),placeholder:"README.md, prompts/example.md","aria-label":s("promptLibrary.discoveryRequiresPaths")}),r.jsxs("div",{className:"prompt-import-dialog__review-actions",children:[r.jsx("button",{type:"button",onClick:()=>{x(e,"approved")},disabled:d||n,children:s("promptLibrary.discoveryApprove")}),r.jsx("button",{type:"button",onClick:()=>{x(e,"rejected")},disabled:d||n,children:s("promptLibrary.discoveryReject")})]})]},e.fullName))})]})}export{k as PromptImportDiscoverySection};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{u as w,a,
|
|
1
|
+
import{u as w,a,Z as S,$ as _,j as t}from"./index-BtK3YhJc.js";function F({input:i,disabled:h=!1,onCandidates:u,onError:l}){const{t:s}=w(),[f,g]=a.useState([]),[o,p]=a.useState(new Set),[d,n]=a.useState(!1),[x,c]=a.useState([]),y=a.useCallback(async()=>{if(i.trim()){n(!0),c([]),l(null);try{const e=await S({source:{kind:"github-folder",input:i.trim()}});g(e.files),p(new Set(e.files.slice(0,5).map(r=>r.path))),c(e.warnings),e.files.length===0&&l(s("promptLibrary.folderFilesEmpty"))}catch(e){g([]),p(new Set),l(e instanceof Error?e.message:s("promptLibrary.folderUnsupported"))}finally{n(!1)}}},[i,l,s]),b=a.useCallback(async()=>{const e=[...o];if(e.length===0){l(s("promptLibrary.folderNoSelection"));return}n(!0),c([]),l(null);try{const r=await _({source:{kind:"github-folder",input:i.trim()},paths:e});c(r.warnings),u(r.candidates)}catch(r){l(r instanceof Error?r.message:s("promptLibrary.importFailed"))}finally{n(!1)}},[i,u,l,o,s]);return t.jsxs("div",{className:"prompt-import-dialog__folder",children:[t.jsxs("div",{className:"prompt-import-dialog__section-title",children:[t.jsx("strong",{children:s("promptLibrary.folderFiles")}),t.jsx("span",{children:s("promptLibrary.folderBrowseHint")})]}),t.jsxs("div",{className:"prompt-import-dialog__folder-actions",children:[t.jsx("button",{type:"button",onClick:()=>{y()},disabled:h||d||!i.trim(),children:s(d?"common.loading":"promptLibrary.folderBrowse")}),t.jsx("button",{type:"button",onClick:()=>{b()},disabled:h||d||o.size===0,children:s("promptLibrary.folderPreviewSelected")}),t.jsx("span",{children:s("promptLibrary.folderSelectedCount",{count:o.size})})]}),f.length>0?t.jsx("div",{className:"prompt-import-dialog__folder-list",children:f.map(e=>t.jsxs("label",{className:"prompt-import-dialog__folder-file",children:[t.jsx("input",{type:"checkbox",checked:o.has(e.path),onChange:r=>{p(j=>{const m=new Set(j);return r.target.checked?m.add(e.path):m.delete(e.path),m})}}),t.jsxs("span",{children:[t.jsx("strong",{children:e.name}),t.jsx("small",{children:e.path})]}),t.jsxs("em",{children:[Math.ceil(e.sizeBytes/1024)," KB"]})]},e.path))}):null,x.length>0?t.jsx("div",{className:"prompt-import-dialog__folder-warning",children:x.slice(0,3).join(" · ")}):null]})}export{F as PromptImportFolderSection};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/PromptImportDialog-
|
|
2
|
-
import{u,j as r,a as n,b as s,S as E,_ as $}from"./index-
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/PromptImportDialog-DGOwFQET.js","assets/index-BtK3YhJc.js","assets/index-ClOLOjnA.css"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{u,j as r,a as n,b as s,S as E,_ as $}from"./index-BtK3YhJc.js";function A({prompt:a,onClose:c,onLoad:d,onInsert:t,onDelete:m,onToggleFavorite:l}){const{t:o}=u(),p=async()=>{try{await navigator.clipboard.writeText(a.text)}catch{}};return r.jsxs("div",{className:"prompt-detail-modal",onClick:c,children:[r.jsx("div",{className:"prompt-detail-modal__backdrop"}),r.jsxs("div",{className:"prompt-detail-modal__content",onClick:i=>i.stopPropagation(),children:[r.jsxs("div",{className:"prompt-detail-modal__header",children:[r.jsx("h4",{children:a.name||o("promptLibrary.untitled")}),r.jsx("button",{className:"prompt-detail-modal__close",onClick:c,"aria-label":o("common.close"),children:"×"})]}),r.jsxs("div",{className:"prompt-detail-modal__body",children:[r.jsx("div",{className:"prompt-detail-modal__label",children:o("promptLibrary.content")}),r.jsx("div",{className:"prompt-detail-modal__prompt",children:a.text}),a.tags.length>0&&r.jsxs("div",{className:"prompt-detail-modal__tags",children:[r.jsx("div",{className:"prompt-detail-modal__label",children:o("promptLibrary.tags")}),r.jsx("div",{className:"prompt-detail-modal__tag-list",children:a.tags.map(i=>r.jsxs("span",{className:"prompt-detail-modal__tag",children:["#",i]},i))})]})]}),r.jsxs("div",{className:"prompt-detail-modal__footer",children:[r.jsx("button",{className:"prompt-detail-modal__load",onClick:d,children:o("promptLibrary.load")}),r.jsx("button",{className:"prompt-detail-modal__copy",onClick:p,children:o("promptLibrary.copy")}),r.jsxs("button",{className:"prompt-detail-modal__insert",onClick:t,children:["+ ",o("promptLibrary.insert")]}),r.jsx("button",{className:`prompt-detail-modal__favorite${a.isFavorite?" prompt-detail-modal__favorite--on":""}`,onClick:l,children:a.isFavorite?"★ "+o("promptLibrary.unfavorite"):"☆ "+o("promptLibrary.favorite")}),r.jsx("button",{className:"prompt-detail-modal__delete",onClick:m,children:o("common.delete")})]})]})]})}function R({prompt:a,onLoad:c,onInsert:d,onDelete:t,onToggleFavorite:m}){const{t:l}=u(),[o,p]=n.useState(!1),i=a.text.length>45?a.text.slice(0,45)+"...":a.text;return r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"prompt-library-row",onClick:()=>p(!0),children:[r.jsxs("div",{className:"prompt-library-row__main",children:[r.jsx("div",{className:"prompt-library-row__title",children:a.name||l("promptLibrary.untitled")}),r.jsx("div",{className:"prompt-library-row__preview",children:i})]}),r.jsxs("div",{className:"prompt-library-row__actions",children:[r.jsx("button",{className:"prompt-library-row__insert",onClick:b=>{b.stopPropagation(),d()},title:l("promptLibrary.insert"),"aria-label":l("promptLibrary.insert"),children:"+"}),r.jsx("button",{className:`prompt-library-row__star${a.isFavorite?" prompt-library-row__star--on":""}`,onClick:b=>{b.stopPropagation(),m()},"aria-label":a.isFavorite?l("promptLibrary.unfavorite"):l("promptLibrary.favorite"),children:a.isFavorite?"★":"☆"}),r.jsx("span",{className:"prompt-library-row__chevron",children:"›"})]})]}),o&&r.jsx(A,{prompt:a,onClose:()=>p(!1),onLoad:()=>{c(),p(!1)},onInsert:()=>{d(),p(!1)},onDelete:t,onToggleFavorite:m})]})}const z=n.lazy(()=>$(()=>import("./PromptImportDialog-DGOwFQET.js"),__vite__mapDeps([0,1,2])).then(a=>({default:a.PromptImportDialog})));function V({variant:a="overlay",forceOpen:c=!1,onRequestClose:d}){const{t}=u(),m=s(e=>e.promptLibraryOpen),l=s(e=>e.togglePromptLibrary),o=s(e=>e.promptLibrary),p=s(e=>e.promptLibraryLoading),i=s(e=>e.loadPromptLibrary),b=s(e=>e.deletePromptFromLibrary),P=s(e=>e.togglePromptFavorite),w=s(e=>e.setPrompt),j=s(e=>e.insertPromptToComposer),k=s(e=>e.clearInsertedPrompts),L=s(e=>e.showToast),[y,F]=n.useState(""),[x,O]=n.useState(!1),[S,N]=n.useState(!1),[f,g]=n.useState(!1),h=c||m,_=d??l;n.useEffect(()=>{h&&i()},[h,i]);const I=n.useCallback(e=>{j({id:e.id,name:e.name||t("promptLibrary.untitled"),text:e.text}),L(t("promptLibrary.inserted")),_()},[_,j,L,t]);if(!h)return null;const C=o.prompts.filter(e=>{if(x&&!e.isFavorite)return!1;if(!y.trim())return!0;const v=y.toLowerCase();return e.name.toLowerCase().includes(v)||e.text.toLowerCase().includes(v)||e.tags.some(T=>T.toLowerCase().includes(v))}),D=r.jsxs("div",{className:"prompt-library-panel__drawer",children:[r.jsxs("div",{className:"prompt-library-panel__header",children:[r.jsx("h3",{children:t("promptLibrary.title")}),r.jsxs("div",{className:"prompt-library-panel__actions",children:[r.jsx("button",{className:"prompt-library-panel__add",onClick:()=>N(e=>!e),title:t("promptLibrary.addNew"),"aria-label":t("promptLibrary.addNew"),children:"+"}),r.jsx("button",{className:"prompt-library-panel__import",onClick:()=>g(!0),title:t("promptLibrary.importFiles"),"aria-label":t("promptLibrary.importFiles"),children:t("promptLibrary.import")}),r.jsx("button",{onClick:_,"aria-label":t("common.close"),children:"×"})]}),S&&r.jsx(E,{text:"",onClose:()=>N(!1)})]}),r.jsxs("div",{className:"prompt-library-panel__search",children:[r.jsx("input",{type:"text",placeholder:t("promptLibrary.search"),value:y,onChange:e=>F(e.target.value)}),r.jsxs("button",{type:"button",className:`prompt-library-panel__filter-toggle${x?" active":""}`,"aria-pressed":x,title:t("promptLibrary.favorites"),onClick:()=>O(e=>!e),children:[r.jsx("span",{"aria-hidden":"true",children:"★"}),r.jsx("span",{children:t("promptLibrary.favorites")})]})]}),p?r.jsx("div",{className:"prompt-library-panel__loading",children:t("common.loading")}):r.jsx("div",{className:"prompt-library-panel__list",children:C.length===0?r.jsx("div",{className:"prompt-library-panel__empty",children:t("promptLibrary.empty")}):C.map(e=>r.jsx(R,{prompt:e,onLoad:()=>{k(),w(e.text),l()},onInsert:()=>I(e),onDelete:()=>b(e.id),onToggleFavorite:()=>P(e.id)},e.id))}),f?r.jsx(n.Suspense,{fallback:null,children:r.jsx(z,{open:f,onClose:()=>g(!1),onImported:i})}):null]});return r.jsxs("div",{className:`prompt-library-panel prompt-library-panel--${a}`,children:[a==="overlay"?r.jsx("div",{className:"prompt-library-panel__backdrop",onClick:_}):null,D]})}export{V as PromptLibraryPanel};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{u as j,a as c,j as e,h as I,k as P,l as F,m as B,b as y,o as M,p as D,T as z,I as G,W as U}from"./index-BtK3YhJc.js";function L({provider:s,label:a,placeholder:r,maskedKey:t,source:i,configured:o,onSaved:u}){const{t:d}=j(),[h,n]=c.useState(""),[m,p]=c.useState(!1),[g,b]=c.useState(!1),[l,x]=c.useState(null),[f,_]=c.useState(!1),N=i==="env",v=h.trim().length>0,k=o&&!m&&!v,E=c.useCallback(async()=>{if(v){b(!0),x(null),_(!1);try{const $=await(await fetch(`/api/keys/${s}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({apiKey:h.trim()})})).json();$.ok?(n(""),p(!1),_(!0),u(),setTimeout(()=>_(!1),3e3)):x($.error||"Failed to save")}catch(w){x(w.message||"Network error")}finally{b(!1)}}},[h,s,v,u]),S=c.useCallback(async()=>{try{if(!(await fetch(`/api/keys/${s}`,{method:"DELETE"})).ok){x("Failed to remove key");return}n(""),p(!1),u()}catch(w){x(w.message||"Failed to remove key")}},[s,u]),T=c.useCallback(()=>{o&&p(!0)},[o]),O=c.useCallback(()=>{v||p(!1)},[v]);return e.jsxs("article",{className:"settings-row",children:[e.jsxs("div",{className:"settings-row__copy",children:[e.jsx("p",{className:"settings-eyebrow",children:d(N?"settings.apiKeys.envSource":"settings.apiKeys.configSource")}),e.jsx("h4",{children:a}),e.jsxs("div",{className:"api-key-input-group",children:[k?e.jsx("input",{type:"text",className:"api-key-input is-masked",value:t||"●●●●●●",readOnly:!0,onFocus:T,onClick:T}):e.jsx("input",{type:"password",className:`api-key-input${l?" is-invalid":""}`,placeholder:r,value:h,onChange:w=>{n(w.target.value),x(null)},onBlur:O,readOnly:!1,autoComplete:"off",autoFocus:m,spellCheck:!1,"data-1p-ignore":!0,"data-lpignore":"true","data-form-type":"other"}),e.jsxs("div",{className:"api-key-actions",children:[e.jsx("button",{type:"button",className:"settings-action-btn",onClick:E,disabled:!v||g,children:d(g?"settings.apiKeys.saving":f?"settings.apiKeys.saved":"settings.apiKeys.save")}),o&&!N&&e.jsx("button",{type:"button",className:"settings-action-btn settings-action-btn--danger",onClick:S,children:d("settings.apiKeys.remove")})]})]}),l&&e.jsx("p",{className:"api-key-error",children:l})]}),e.jsxs("div",{className:`settings-status${o?" is-ok":""}`,children:[e.jsx("span",{"aria-hidden":"true"}),d(o?"settings.apiKeys.status.valid":"settings.apiKeys.status.notConfigured")]})]})}function W({configured:s,maskedKey:a,source:r,onSaved:t}){const{t:i}=j(),[o,u]=c.useState(""),[d,h]=c.useState(!1),[n,m]=c.useState(!1),[p,g]=c.useState(null),[b,l]=c.useState(!1),x=r==="env",f=o.trim().length>0,_=s&&!d&&!f,N=c.useCallback(async()=>{if(f){m(!0),g(null),l(!1);try{const T=await(await fetch("/api/keys/vertex",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({serviceAccountJson:o.trim()})})).json();T.ok?(u(""),h(!1),l(!0),t(),setTimeout(()=>l(!1),3e3)):g(T.error||"Failed to save")}catch(S){g(S.message||"Network error")}finally{m(!1)}}},[o,f,t]),v=c.useCallback(async()=>{try{await fetch("/api/keys/vertex",{method:"DELETE"}),u(""),h(!1),t()}catch{}},[t]),k=c.useCallback(()=>{s&&!x&&h(!0)},[s,x]),E=c.useCallback(()=>{f||h(!1)},[f]);return e.jsxs("div",{className:"vertex-json-section",children:[e.jsx("p",{className:"settings-eyebrow",children:i(x?"settings.apiKeys.envSource":"settings.apiKeys.configSource")}),s&&a&&e.jsx("p",{className:"vertex-project-id",children:a}),_?e.jsx("textarea",{className:"vertex-json-textarea is-masked",value:"●●● (configured — click to replace)",readOnly:!0,onFocus:k,onClick:k}):e.jsx("textarea",{className:`vertex-json-textarea${p?" is-invalid":""}`,placeholder:i("settings.apiKeys.vertex.placeholder"),value:o,onChange:S=>{u(S.target.value),g(null)},onBlur:E,readOnly:x,autoFocus:d,spellCheck:!1,"data-1p-ignore":!0,"data-lpignore":"true","data-form-type":"other"}),e.jsxs("div",{className:"api-key-actions",style:{marginTop:8},children:[!x&&e.jsx("button",{type:"button",className:"settings-action-btn",onClick:N,disabled:!f||n,children:i(n?"settings.apiKeys.saving":b?"settings.apiKeys.saved":"settings.apiKeys.save")}),s&&!x&&e.jsx("button",{type:"button",className:"settings-action-btn settings-action-btn--danger",onClick:v,children:i("settings.apiKeys.remove")})]}),p&&e.jsx("p",{className:"api-key-error",children:p}),e.jsxs("div",{className:`settings-status${s?" is-ok":""}`,style:{marginTop:8},children:[e.jsx("span",{"aria-hidden":"true"}),i(s?"settings.apiKeys.status.valid":"settings.apiKeys.status.notConfigured")]})]})}function J({keyStatus:s,onSaved:a}){const{t:r}=j(),t=s.vertex?.configured??!1,i=s.gemini?.configured??!1,[o,u]=c.useState(t&&!i?"vertex":"apikey"),[d,h]=c.useState(!1);return c.useEffect(()=>{d||u(t&&!i?"vertex":"apikey")},[t,i,d]),e.jsxs("div",{className:"gemini-key-section",children:[e.jsxs("div",{className:"gemini-key-section__header",children:[e.jsx("h5",{children:r("settings.apiKeys.gemini.label")}),e.jsxs("select",{value:o,onChange:n=>{h(!0),u(n.target.value)},className:"gemini-auth-mode-select",children:[e.jsx("option",{value:"apikey",children:r("settings.apiKeys.vertex.authModeApiKey")}),e.jsx("option",{value:"vertex",children:r("settings.apiKeys.vertex.authModeVertex")})]})]}),o==="apikey"?e.jsx(L,{provider:"gemini",label:"",placeholder:r("settings.apiKeys.gemini.placeholder"),maskedKey:s.gemini?.maskedKey??null,source:s.gemini?.source??"none",configured:i,onSaved:a}):e.jsx(W,{configured:t,maskedKey:s.vertex?.maskedKey??null,source:s.vertex?.source??"none",onSaved:a})]})}function R(s,a){return s(a==="ready"?"settings.account.status.ready":a==="auth_required"?"settings.account.status.authRequired":a==="starting"?"settings.account.status.starting":a==="offline"?"settings.account.status.offline":a==="no_image_model"?"settings.account.status.noImageModel":a==="error"?"settings.account.status.error":"settings.account.status.checking")}function V(){const{t:s}=j(),a=I(),r=P(),{data:t,error:i}=F(),{data:o,mutate:u}=B(),[d,h]=c.useState(!1),n=t?.apiKeySource==="env"||t?.apiKeySource==="config"||t?.apiKeyValid===!0,m=a?.status==="ready",p=t?.apiKeySource==="config"?s("settings.account.apiSourceConfig"):s("settings.account.apiSourceEnv"),g=t?.apiKeyValid===!0,b=r?.status==="ready";return e.jsxs(e.Fragment,{children:[e.jsxs("article",{className:"settings-row",children:[e.jsxs("div",{className:"settings-row__copy",children:[e.jsx("p",{className:"settings-eyebrow",children:s("settings.account.primaryEyebrow")}),e.jsx("h4",{children:s("settings.account.oauthTitle")}),e.jsx("p",{children:s("settings.account.oauthBody")})]}),e.jsxs("div",{className:`settings-status${m?" is-ok":""}`,children:[e.jsx("span",{"aria-hidden":"true"}),R(s,a?.status)]})]}),n?e.jsxs("article",{className:"settings-row",children:[e.jsxs("div",{className:"settings-row__copy",children:[e.jsx("p",{className:"settings-eyebrow",children:p}),e.jsx("h4",{children:s("settings.account.apiTitle")}),e.jsx("p",{children:s("settings.account.apiBody")})]}),e.jsxs("div",{className:`settings-status${g?" is-ok":" is-muted"}`,children:[e.jsx("span",{"aria-hidden":"true"}),s(i?"settings.account.apiUnknown":g?"settings.account.apiReady":"settings.account.apiUnavailable")]})]}):null,e.jsxs("article",{className:"settings-row",children:[e.jsxs("div",{className:"settings-row__copy",children:[e.jsx("p",{className:"settings-eyebrow",children:s("settings.account.grokEyebrow")}),e.jsx("h4",{children:s("settings.account.grokTitle")}),e.jsx("p",{children:s("settings.account.grokBody")})]}),e.jsxs("div",{className:`settings-status${b?" is-ok":" is-muted"}`,children:[e.jsx("span",{"aria-hidden":"true"}),R(s,r?.status)]})]}),o&&e.jsxs("article",{className:"settings-row settings-accordion",children:[e.jsxs("button",{type:"button",className:"settings-accordion__trigger",onClick:()=>h(!d),children:[e.jsx("h4",{children:s("settings.apiKeys.accordionTitle")}),e.jsx("span",{className:`settings-accordion__arrow${d?" is-open":""}`,children:"▼"})]}),d&&e.jsxs("div",{className:"settings-accordion__body",children:[e.jsx(L,{provider:"openai",label:s("settings.apiKeys.openai.label"),placeholder:s("settings.apiKeys.openai.placeholder"),maskedKey:o.openai?.maskedKey??null,source:o.openai?.source??"none",configured:o.openai?.configured??!1,onSaved:u}),e.jsx(L,{provider:"xai",label:s("settings.apiKeys.xai.label"),placeholder:s("settings.apiKeys.xai.placeholder"),maskedKey:o.xai?.maskedKey??null,source:o.xai?.source??"none",configured:o.xai?.configured??!1,onSaved:u}),e.jsx(J,{keyStatus:o,onSaved:u})]})]})]})}function H(){const{t:s}=j(),a=y(i=>i.reasoningEffort),r=y(i=>i.setReasoningEffort),t=i=>{r(i.target.value)};return e.jsx("div",{className:"image-model-select image-model-select--settings",children:e.jsx("select",{id:"settings-reasoning-effort",value:a,onChange:t,children:M.map(i=>e.jsx("option",{value:i.value,children:s(i.fullLabelKey)},i.value))})})}const Q={ko:"KO",en:"EN"};function X(){const{t:s,locale:a}=j(),r=y(t=>t.setLocale);return e.jsx("div",{className:"lang-toggle",role:"group","aria-label":s("language.label"),children:D.map(t=>e.jsx("button",{type:"button",className:`lang-toggle__btn ${a===t?"is-active":""}`,onClick:()=>r(t),"aria-pressed":a===t,title:s(`language.${t}`),children:e.jsx("span",{className:"lang-toggle__label",children:Q[t]})},t))})}const Y=["system","dark","light"];function Z(){const{t:s}=j(),a=y(n=>n.theme),r=y(n=>n.setTheme),t=y(n=>n.themeFamily),i=y(n=>n.setThemeFamily),[o,u]=c.useState(!1),d=c.useRef(null);c.useEffect(()=>{if(!o)return;const n=p=>{d.current&&(d.current.contains(p.target)||u(!1))},m=p=>{p.key==="Escape"&&u(!1)};return document.addEventListener("mousedown",n),document.addEventListener("keydown",m),()=>{document.removeEventListener("mousedown",n),document.removeEventListener("keydown",m)}},[o]);const h=n=>s(`theme.family.${n}`);return e.jsxs("div",{className:"theme-toggle","aria-label":s("theme.label"),children:[e.jsxs("div",{className:"theme-toggle__row",children:[e.jsx("span",{className:"theme-toggle__label",id:"theme-style-label",children:s("theme.styleLabel")}),e.jsxs("div",{className:"theme-toggle__family",ref:d,children:[e.jsxs("button",{type:"button",className:"theme-toggle__family-trigger","aria-haspopup":"listbox","aria-expanded":o,"aria-labelledby":"theme-style-label",onClick:()=>u(n=>!n),children:[e.jsx("span",{className:`theme-toggle__family-dot theme-toggle__family-dot--${t}`,"aria-hidden":"true"}),e.jsx("span",{className:"theme-toggle__family-name",children:h(t)}),e.jsx("span",{className:"theme-toggle__family-caret","aria-hidden":"true",children:"▾"})]}),o?e.jsx("ul",{className:"theme-toggle__family-menu",role:"listbox","aria-labelledby":"theme-style-label",children:z.map(n=>e.jsx("li",{role:"none",children:e.jsxs("button",{type:"button",role:"option","aria-selected":t===n,className:`theme-toggle__family-option ${t===n?"is-active":""}`,onClick:()=>{i(n),u(!1)},children:[e.jsx("span",{className:`theme-toggle__family-dot theme-toggle__family-dot--${n}`,"aria-hidden":"true"}),e.jsx("span",{className:"theme-toggle__family-name",children:h(n)})]})},n))}):null]})]}),e.jsxs("div",{className:"theme-toggle__row",children:[e.jsx("span",{className:"theme-toggle__label",id:"theme-mode-label",children:s("theme.modeLabel")}),e.jsx("div",{className:"theme-toggle__mode",role:"group","aria-labelledby":"theme-mode-label",children:Y.map(n=>e.jsx("button",{type:"button",className:`theme-toggle__btn ${a===n?"is-active":""}`,onClick:()=>r(n),"aria-pressed":a===n,title:s(`theme.${n}`),children:s(`theme.${n}`)},n))})]})]})}const ee=["rail","horizontal","sidebar"];function se(){const{t:s}=j(),a=y(t=>t.historyStripLayout),r=y(t=>t.setHistoryStripLayout);return e.jsx("div",{className:"history-layout-toggle",role:"group","aria-label":s("settings.appearance.historyStripLayoutTitle"),children:ee.map(t=>e.jsx("button",{type:"button",className:`history-layout-toggle__btn ${a===t?"is-active":""}`,onClick:()=>r(t),"aria-pressed":a===t,title:s(`settings.appearance.historyStripLayout.${t}`),children:s(`settings.appearance.historyStripLayout.${t}`)},t))})}const te=[{value:"default",labelKey:"workspace.defaultLabel",descKey:"workspace.defaultDesc"},{value:"prompt-studio",labelKey:"workspace.promptStudioLabel",descKey:"workspace.promptStudioDesc"}];function ae(){const s=y(t=>t.workspaceProfile),a=y(t=>t.setWorkspaceProfile),{t:r}=j();return e.jsx("div",{className:"settings-field",children:e.jsx("select",{id:"workspace-profile-select",className:"settings-field__select",value:s,onChange:t=>a(t.target.value),"aria-label":r("workspace.profileLabel"),children:te.map(t=>e.jsx("option",{value:t.value,children:r(t.labelKey)},t.value))})})}function ne(s){return s>80?"var(--error, #e53935)":s>50?"var(--warning, #f59e0b)":"var(--info, #3b82f6)"}function ie(s){if(!s)return"";const a=new Date(s);return`${a.getMonth()+1}/${a.getDate()} ${String(a.getHours()).padStart(2,"0")}:${String(a.getMinutes()).padStart(2,"0")}`}function re(){return e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true",children:e.jsx("path",{d:"M22.282 9.821a5.985 5.985 0 0 0-.516-4.91 6.046 6.046 0 0 0-6.51-2.9A6.065 6.065 0 0 0 4.981 4.18a5.998 5.998 0 0 0-3.998 2.9 6.049 6.049 0 0 0 .743 7.097 5.98 5.98 0 0 0 .51 4.911 6.051 6.051 0 0 0 6.515 2.9A5.985 5.985 0 0 0 13.26 24a6.056 6.056 0 0 0 5.772-4.206 5.99 5.99 0 0 0 3.997-2.9 6.056 6.056 0 0 0-.747-7.073zM13.26 22.43a4.476 4.476 0 0 1-2.876-1.04l.141-.081 4.779-2.758a.795.795 0 0 0 .392-.681v-6.737l2.02 1.168a.071.071 0 0 1 .038.052v5.583a4.504 4.504 0 0 1-4.494 4.494zM3.6 18.304a4.47 4.47 0 0 1-.535-3.014l.142.085 4.783 2.759a.771.771 0 0 0 .78 0l5.843-3.369v2.332a.08.08 0 0 1-.033.062L9.74 19.95a4.5 4.5 0 0 1-6.14-1.646zM2.34 7.896a4.485 4.485 0 0 1 2.366-1.973V11.6a.766.766 0 0 0 .388.676l5.815 3.355-2.02 1.168a.076.076 0 0 1-.071 0l-4.83-2.786A4.504 4.504 0 0 1 2.34 7.872zm16.597 3.855l-5.833-3.387L15.119 7.2a.076.076 0 0 1 .071 0l4.83 2.791a4.494 4.494 0 0 1-.676 8.105v-5.678a.79.79 0 0 0-.407-.667zm2.01-3.023l-.141-.085-4.774-2.782a.776.776 0 0 0-.785 0L9.409 9.23V6.897a.066.066 0 0 1 .028-.061l4.83-2.787a4.5 4.5 0 0 1 6.68 4.66zm-12.64 4.135l-2.02-1.164a.08.08 0 0 1-.038-.057V6.075a4.5 4.5 0 0 1 7.375-3.453l-.142.08L8.704 5.46a.795.795 0 0 0-.393.681zm1.097-2.365l2.602-1.5 2.607 1.5v2.999l-2.597 1.5-2.612-1.5z"})})}function le(){return e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"currentColor",fillRule:"evenodd","aria-hidden":"true",children:e.jsx("path",{d:"M9.27 15.29l7.978-5.897c.391-.29.95-.177 1.137.272.98 2.369.542 5.215-1.41 7.169-1.951 1.954-4.667 2.382-7.149 1.406l-2.711 1.257c3.889 2.661 8.611 2.003 11.562-.953 2.341-2.344 3.066-5.539 2.388-8.42l.006.007c-.983-4.232.242-5.924 2.75-9.383.06-.082.12-.164.179-.248l-3.301 3.305v-.01L9.267 15.292M7.623 16.723c-2.792-2.67-2.31-6.801.071-9.184 1.761-1.763 4.647-2.483 7.166-1.425l2.705-1.25a7.808 7.808 0 00-1.829-1A8.975 8.975 0 005.984 5.83c-2.533 2.536-3.33 6.436-1.962 9.764 1.022 2.487-.653 4.246-2.34 6.022-.599.63-1.199 1.259-1.682 1.925l7.62-6.815"})})}function A({window:s}){const a=ie(s.resetsAt);return e.jsxs("div",{className:"quota-bar",children:[e.jsx("span",{className:"quota-bar__label",children:s.label}),e.jsx("div",{className:"quota-bar__track",children:e.jsx("div",{className:"quota-bar__fill",style:{width:`${Math.min(s.percent,100)}%`,background:ne(s.percent)}})}),e.jsxs("span",{className:"quota-bar__pct",children:[s.percent,"%"]}),a&&e.jsx("span",{className:"quota-bar__reset",children:a})]})}function q({provider:s,onComplete:a}){const[r,t]=c.useState({phase:"idle"}),[i,o]=c.useState(!1),u=c.useRef(!1),d=c.useCallback(async()=>{if(!u.current){u.current=!0,t({phase:"starting"});try{const h=await fetch("/api/auth/switch",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:s})});if(!h.ok){const m=await h.json().catch(()=>({error:"Request failed"}));t({phase:"error",error:m.error||`HTTP ${h.status}`});return}const n=await h.json();t({phase:"waiting",...n}),window.open(n.verificationUrl,"_blank")}catch(h){u.current=!1,t({phase:"error",error:h.message})}}},[s]);return c.useEffect(()=>{if(r.phase!=="waiting"||!r.sessionId)return;let h=!1;const n=async()=>{try{const g=await(await fetch(`/api/auth/switch/${r.sessionId}`)).json();if(h)return;if(g.status==="complete"){t({phase:"complete"}),setTimeout(a,1e3);return}if(g.status==="error"||g.status==="expired"){t({phase:"error",error:g.error||g.status});return}}catch{}h||setTimeout(n,3e3)},m=setTimeout(n,3e3);return()=>{h=!0,clearTimeout(m)}},[r.phase,r.sessionId,a]),r.phase==="idle"?e.jsxs("button",{type:"button",className:"settings-action-btn",style:{width:"100%",marginTop:"6px"},onClick:d,children:["Switch ",s==="grok"?"Grok":"Codex"," Account"]}):r.phase==="starting"?e.jsx("div",{className:"quota-card__hint",style:{textAlign:"center",marginTop:"6px"},children:"Starting login..."}):r.phase==="waiting"?e.jsxs("div",{style:{marginTop:"6px",padding:"8px",background:"var(--surface, #f5f5f5)",borderRadius:"6px",fontSize:"12px"},children:[e.jsx("div",{style:{textAlign:"center",marginBottom:"4px"},children:"Enter this code in the opened tab:"}),e.jsx("div",{style:{textAlign:"center",fontSize:"18px",fontWeight:700,fontFamily:"monospace",letterSpacing:"2px",margin:"6px 0"},children:r.userCode}),r.verificationUrl&&e.jsxs("div",{style:{display:"flex",gap:"4px",margin:"6px 0"},children:[e.jsx("button",{type:"button",className:"settings-action-btn",style:{flex:1,fontSize:"11px"},onClick:()=>window.open(r.verificationUrl,"_blank"),children:"Open tab again"}),e.jsx("button",{type:"button",className:"settings-action-btn",style:{flex:1,fontSize:"11px"},onClick:()=>{navigator.clipboard?.writeText(r.verificationUrl).then(()=>{o(!0),setTimeout(()=>o(!1),2e3)})},children:i?"Copied!":"Copy link"})]}),e.jsx("div",{style:{textAlign:"center",color:"var(--text-dim, #888)",fontSize:"11px"},children:"Waiting for approval..."})]}):r.phase==="complete"?e.jsx("div",{className:"quota-card__hint",style:{textAlign:"center",marginTop:"6px",color:"var(--success, #22c55e)"},children:"Account switched! Refreshing..."}):e.jsxs("div",{style:{marginTop:"6px"},children:[e.jsx("div",{className:"quota-card__hint",style:{color:"var(--error, #e53935)",marginBottom:"4px"},children:r.error||"Switch failed"}),e.jsx("button",{type:"button",className:"settings-action-btn",style:{width:"100%",fontSize:"11px"},onClick:()=>{u.current=!1,t({phase:"idle"})},children:"Try again"})]})}function ce(){const{t:s}=j(),[a,r]=c.useState(null),[t,i]=c.useState(!0),o=c.useCallback(()=>{i(!0),fetch("/api/quota").then(g=>g.json()).then(r).catch(()=>r(null)).finally(()=>i(!1))},[]);c.useEffect(()=>{const g=setTimeout(o,1500);return()=>clearTimeout(g)},[o]);const u=a?.codex,d=a?.grok,h=u?.windows&&u.windows.length>0,n=d?.windows&&d.windows.length>0,m=u?.account?[u.account.email,u.account.plan].filter(Boolean).join(" · "):null,p=d?.account?[d.account.email,d.account.plan].filter(Boolean).join(" · "):null;return e.jsxs("article",{className:"settings-row",children:[e.jsxs("div",{className:"settings-row__copy",children:[e.jsx("p",{className:"settings-eyebrow",children:s("settings.quota.eyebrow")}),e.jsx("h4",{children:s("settings.quota.title")})]}),e.jsxs("div",{className:"settings-row__control quota-cards",children:[e.jsxs("div",{className:"quota-card",children:[e.jsxs("div",{className:"quota-card__header",children:[e.jsx(re,{}),e.jsx("strong",{children:"Codex"}),m&&e.jsx("span",{className:"quota-card__account",children:m})]}),t?e.jsx("span",{className:"quota-card__loading",children:s("common.loading")}):h?u.windows.map(g=>e.jsx(A,{window:g},g.label)):u?.authenticated===!1?e.jsx("span",{className:"quota-card__hint",children:s("settings.quota.codexNotLoggedIn")}):u?.error?e.jsx("span",{className:"quota-card__hint",children:s("settings.quota.fetchError")}):e.jsx("span",{className:"quota-card__hint",children:s("settings.quota.noData")}),e.jsx(q,{provider:"codex",onComplete:o})]}),e.jsxs("div",{className:"quota-card",children:[e.jsxs("div",{className:"quota-card__header",style:{display:"flex",alignItems:"center"},children:[e.jsx(le,{}),e.jsx("strong",{children:"Grok"}),p&&e.jsx("span",{className:"quota-card__account",children:p}),d?.billing&&e.jsxs("span",{style:{marginLeft:"auto",fontSize:"11px",color:"var(--text-dim, #888)",whiteSpace:"nowrap"},children:["$",d.billing.usedUsd.toFixed(1),"/$",d.billing.limitUsd]})]}),t?e.jsx("span",{className:"quota-card__loading",children:s("common.loading")}):n?d.windows.map(g=>e.jsx(A,{window:g},g.label)):d?.authenticated===!1?e.jsx("span",{className:"quota-card__hint",children:"Not logged in"}):e.jsx("a",{href:"https://grok.com/?_s=usage",target:"_blank",rel:"noopener noreferrer",className:"settings-action-btn",children:s("settings.quota.grokUsageLink")}),e.jsx(q,{provider:"grok",onComplete:o})]})]})]})}function oe(){const{t:s}=j(),[a,r]=c.useState(null);c.useEffect(()=>{fetch("/api/config/grok-planner").then(i=>i.json()).then(r).catch(()=>{})},[]);const t=async i=>{try{await fetch("/api/config/grok-planner",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({model:i})}),r(o=>o?{...o,model:i}:null)}catch{}};return a?e.jsxs("article",{className:"settings-row",children:[e.jsxs("div",{className:"settings-row__copy",children:[e.jsx("h4",{children:s("settings.grokPlanner.title")}),e.jsx("p",{children:s("settings.grokPlanner.body")})]}),e.jsx("div",{className:"settings-row__control",children:e.jsx("select",{value:a.model,onChange:i=>{t(i.target.value)},"aria-label":s("settings.grokPlanner.title"),children:a.options.map(i=>e.jsx("option",{value:i,children:i},i))})})]}):null}const K=["account","generation","appearance","workspace","language","future"];function C({id:s,setRef:a,children:r}){const{t}=j();return e.jsxs("section",{id:s,ref:i=>a(s,i),className:"settings-section","aria-labelledby":`settings-section-${s}`,children:[e.jsx("header",{className:"settings-section__header",children:e.jsxs("div",{children:[e.jsx("h3",{id:`settings-section-${s}`,children:t(`settings.sections.${s}.title`)}),e.jsx("p",{children:t(`settings.sections.${s}.hint`)})]})}),e.jsx("div",{className:"settings-section__body",children:r})]})}function ue(){const{t:s}=j(),a=y(l=>l.activeSettingsSection),r=y(l=>l.setActiveSettingsSection),t=y(l=>l.closeSettings),i=y(l=>l.openReadinessPopup),o=y(l=>l.galleryDefaultScope),u=y(l=>l.setGalleryDefaultScope),d=y(l=>l.provider),h=c.useRef(null),n=c.useRef(null),m=c.useRef(!1),p=c.useRef({account:null,generation:null,appearance:null,workspace:null,language:null,future:null}),g=(l,x)=>{p.current[l]=x},b=l=>{r(l),m.current=!0,p.current[l]?.scrollIntoView({behavior:"auto",block:"start"}),n.current!==null&&window.clearTimeout(n.current),n.current=window.setTimeout(()=>{m.current=!1,n.current=null},120)};return c.useEffect(()=>{const l=x=>{x.key==="Escape"&&t()};return window.addEventListener("keydown",l),()=>window.removeEventListener("keydown",l)},[t]),c.useEffect(()=>{const l=h.current;if(!l||typeof IntersectionObserver!="function")return;const x=new IntersectionObserver(f=>{if(m.current)return;const N=f.filter(v=>v.isIntersecting).sort((v,k)=>k.intersectionRatio-v.intersectionRatio)[0]?.target.id;N&&K.includes(N)&&r(N)},{root:l,threshold:[.35,.6]});for(const f of K){const _=p.current[f];_&&x.observe(_)}return()=>x.disconnect()},[r]),c.useEffect(()=>()=>{n.current!==null&&window.clearTimeout(n.current)},[]),e.jsx("main",{ref:h,className:"settings-workspace","aria-labelledby":"settings-title",children:e.jsxs("div",{className:"settings-shell",children:[e.jsxs("header",{className:"settings-header",children:[e.jsxs("div",{children:[e.jsx("p",{className:"settings-eyebrow",children:s("settings.eyebrow")}),e.jsx("h2",{id:"settings-title",children:s("settings.title")}),e.jsx("p",{children:s("settings.subtitle")})]}),e.jsx("button",{type:"button",className:"settings-close",onClick:t,"aria-label":s("settings.closeAria"),title:s("settings.closeTitle"),children:"X"})]}),e.jsxs("div",{className:"settings-layout",children:[e.jsx("nav",{className:"settings-nav settings-nav--mobile","aria-label":s("settings.navAria"),children:e.jsx("div",{className:"settings-mobile-nav",role:"list",children:K.map(l=>e.jsxs("button",{type:"button",className:`settings-mobile-nav__item${a===l?" is-active":""}`,onClick:()=>b(l),"aria-current":a===l?"true":void 0,children:[e.jsx("span",{children:s(`settings.sections.${l}.title`)}),e.jsx("small",{children:s(`settings.sections.${l}.hint`)})]},l))})}),e.jsx("nav",{className:"settings-nav","aria-label":s("settings.navAria"),children:K.map(l=>e.jsxs("button",{type:"button",className:`settings-nav__item${a===l?" is-active":""}`,onClick:()=>b(l),"aria-label":s("settings.jumpTo",{section:s(`settings.sections.${l}.title`)}),children:[e.jsx("span",{children:s(`settings.sections.${l}.title`)}),e.jsx("small",{children:s(`settings.sections.${l}.hint`)})]},l))}),e.jsxs("section",{className:"settings-content","aria-label":s("settings.contentAria"),children:[e.jsxs(C,{id:"account",setRef:g,children:[e.jsx(V,{}),e.jsx(ce,{}),e.jsxs("article",{className:"settings-row",children:[e.jsxs("div",{className:"settings-row__copy",children:[e.jsx("h4",{children:s("readiness.settingsTitle")}),e.jsx("p",{children:s("readiness.settingsBody")})]}),e.jsx("div",{className:"settings-row__control",children:e.jsx("button",{type:"button",className:"settings-action-btn",onClick:i,children:s("readiness.open")})})]})]}),e.jsxs(C,{id:"generation",setRef:g,children:[e.jsxs("article",{className:"settings-row",children:[e.jsxs("div",{className:"settings-row__copy",children:[e.jsx("h4",{children:s("settings.imageModel.title")}),e.jsx("p",{children:s("settings.imageModel.body")}),e.jsx("p",{className:"settings-row__microcopy",children:s("settings.imageModel.unsupportedHelp")})]}),e.jsx("div",{className:"settings-row__control",children:e.jsx(G,{variant:"settings"})})]}),d==="grok"?e.jsxs(e.Fragment,{children:[e.jsx("article",{className:"settings-row",children:e.jsxs("div",{className:"settings-row__copy",children:[e.jsx("h4",{children:s("settings.grokCompatibility.title")}),e.jsx("p",{children:s("settings.grokCompatibility.body")})]})}),e.jsx(oe,{})]}):d==="agy"||d==="gemini-api"?e.jsx("article",{className:"settings-row",children:e.jsxs("div",{className:"settings-row__copy",children:[e.jsx("h4",{children:d==="gemini-api"?"Gemini API":s("provider.agyCompatTitle")}),e.jsx("p",{children:d==="gemini-api"?"Google Gemini API direct. Supports nano-banana-2 (Flash) and nano-banana-pro (Pro). 1024x1024 default, JPEG output.":s("provider.agyCompatBodyLong")})]})}):e.jsxs(e.Fragment,{children:[e.jsxs("article",{className:"settings-row",children:[e.jsxs("div",{className:"settings-row__copy",children:[e.jsx("h4",{children:s("settings.reasoning.title")}),e.jsx("p",{children:s("settings.reasoning.body")})]}),e.jsx("div",{className:"settings-row__control",children:e.jsx(H,{})})]}),e.jsxs("article",{className:"settings-row",children:[e.jsxs("div",{className:"settings-row__copy",children:[e.jsx("h4",{children:s("settings.webSearch.title")}),e.jsx("p",{children:s("settings.webSearch.body")})]}),e.jsx("div",{className:"settings-row__control",children:e.jsx(U,{})})]})]}),e.jsxs("article",{className:"settings-row",children:[e.jsxs("div",{className:"settings-row__copy",children:[e.jsx("h4",{children:s("settings.gallery.defaultScopeTitle")}),e.jsx("p",{children:s("settings.gallery.defaultScopeBody")})]}),e.jsx("div",{className:"settings-row__control",children:e.jsxs("select",{value:o,onChange:l=>u(l.target.value),"aria-label":s("settings.gallery.defaultScopeTitle"),children:[e.jsx("option",{value:"current-session",children:s("gallery.scope.current")}),e.jsx("option",{value:"all",children:s("gallery.scope.all")})]})})]})]}),e.jsxs(C,{id:"appearance",setRef:g,children:[e.jsxs("article",{className:"settings-row",children:[e.jsxs("div",{className:"settings-row__copy",children:[e.jsx("h4",{children:s("settings.appearance.themeTitle")}),e.jsx("p",{children:s("settings.appearance.themeBody")})]}),e.jsx("div",{className:"settings-row__control",children:e.jsx(Z,{})})]}),e.jsxs("article",{className:"settings-row",children:[e.jsxs("div",{className:"settings-row__copy",children:[e.jsx("h4",{children:s("settings.appearance.historyStripLayoutTitle")}),e.jsx("p",{children:s("settings.appearance.historyStripLayoutBody")})]}),e.jsx("div",{className:"settings-row__control",children:e.jsx(se,{})})]})]}),e.jsx(C,{id:"workspace",setRef:g,children:e.jsxs("article",{className:"settings-row",children:[e.jsxs("div",{className:"settings-row__copy",children:[e.jsx("h4",{children:s("workspace.sectionTitle")}),e.jsx("p",{children:s("workspace.sectionBody")})]}),e.jsx("div",{className:"settings-row__control",children:e.jsx(ae,{})})]})}),e.jsx(C,{id:"language",setRef:g,children:e.jsxs("article",{className:"settings-row",children:[e.jsxs("div",{className:"settings-row__copy",children:[e.jsx("h4",{children:s("settings.language.title")}),e.jsx("p",{children:s("settings.language.body")})]}),e.jsx("div",{className:"settings-row__control",children:e.jsx(X,{})})]})}),e.jsx(C,{id:"future",setRef:g,children:e.jsxs("article",{className:"settings-note",children:[e.jsx("h4",{children:s("settings.future.title")}),e.jsx("p",{children:s("settings.future.body")})]})})]})]})]})})}export{ue as SettingsWorkspace};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as c,j as o,u as ke,f as an,w as rn,x as on,y as sn,z as St,A as me,B as ln,C as Bt,E as cn,b as j,F as un,c as dn,G as hn,H as fn,M as pn}from"./index-BtK3YhJc.js";const Ae=2,Oe=1e-6;function mn({paths:e,points:t,radius:n,makeId:a=()=>crypto.randomUUID()}){if(e.length===0||t.length===0||n<=0)return{paths:e,changed:!1};let r=!1;const l=[];for(const s of e){const d=vn(s,t,n,a);(d.length!==1||d[0]!==s)&&(r=!0),l.push(...d)}return{paths:l,changed:r}}function vn(e,t,n,a=()=>crypto.randomUUID()){if(e.points.length<Ae||t.length===0||n<=0)return[e];const r=[];let l=Te(e.points[0],t,n)?[]:[e.points[0]];for(let d=1;d<e.points.length;d+=1){const u=e.points[d-1],i=e.points[d],b=Te(i,t,n),f=bn(u,i,t,n);if(f){l.length===0&&!Te(u,t,n)&&(l=[u]),l.length>0&&f.leftT>Oe&&ft(l,Pe(u,i,f.leftT)),l.length>=Ae&&r.push(l),l=[],f.rightT<1-Oe&&!b&&(l=[Pe(u,i,f.rightT),i]);continue}if(b){l.length>=Ae&&r.push(l),l=[];continue}l.length===0&&!Te(u,t,n)&&(l=[u]),ft(l,i)}if(l.length>=Ae&&r.push(l),r.length===0)return[];if(r.length===1&&r[0].length===e.points.length)return[e];const s=e.tool==="arrow"?r.length-1:-1;return r.map((d,u)=>({...e,id:u===0?e.id:a(),tool:e.tool==="arrow"&&u!==s?"pen":e.tool,points:d}))}function Te(e,t,n){if(t.length===1)return ye(e,t[0])<=n;for(let a=1;a<t.length;a+=1)if(gn(e,t[a-1],t[a])<=n)return!0;return!1}function ye(e,t){const n=e.x-t.x,a=e.y-t.y;return Math.sqrt(n*n+a*a)}function bn(e,t,n,a){const r=ye(e,t);if(r<=Oe)return Te(e,n,a)?{leftT:0,rightT:1}:null;let l=null,s=Number.POSITIVE_INFINITY;for(const u of n){const i=ht(u,e,t),b=Pe(e,t,i),f=ye(u,b);f<s&&(s=f,l=i)}for(let u=1;u<n.length;u+=1){const i=[0,.25,.5,.75,1];for(const b of i){const f=Pe(n[u-1],n[u],b),_=ht(f,e,t),B=Pe(e,t,_),A=ye(f,B);A<s&&(s=A,l=_)}}if(l===null||s>a)return null;const d=Math.max(a/r,.01);return{leftT:Math.max(0,l-d),rightT:Math.min(1,l+d)}}function ht(e,t,n){const a=n.x-t.x,r=n.y-t.y,l=e.x-t.x,s=e.y-t.y,d=a*a+r*r;return d===0?0:Math.max(0,Math.min(1,(l*a+s*r)/d))}function Pe(e,t,n){return{x:e.x+(t.x-e.x)*n,y:e.y+(t.y-e.y)*n}}function ft(e,t){const n=e.at(-1);(!n||ye(n,t)>Oe)&&e.push(t)}function gn(e,t,n){const a=n.x-t.x,r=n.y-t.y,l=e.x-t.x,s=e.y-t.y,d=a*a+r*r;if(d===0)return ye(e,t);const u=Math.max(0,Math.min(1,(l*a+s*r)/d));return ye(e,{x:t.x+u*a,y:t.y+u*r})}function st(e,t){return`${e}:${t}`}function lt(e){const t=e.indexOf(":");if(t<=0)return null;const n=e.slice(0,t),a=e.slice(t+1);return!a||n!=="path"&&n!=="box"&&n!=="memo"?null:{kind:n,id:a}}function jt(e){return st("path",e.id)}function Tt(e){return st("box",e.id)}function Pt(e){return st("memo",e.id)}function pe(e,t,n){const a=lt(e);return a?.kind===t&&a.id===n}const Dt="ima2.canvas.annotationStyle.v1",At=["#ef4444","#f97316","#eab308","#22c55e","#38bdf8","#6366f1","#a855f7","#111827","#ffffff"],It=[2,3,5,8],Se={color:"#ef4444",strokeWidth:3};function xn(){if(typeof window>"u")return Se;try{const e=window.localStorage.getItem(Dt);if(!e)return Se;const t=JSON.parse(e),n=typeof t.color=="string"&&At.includes(t.color)?t.color:Se.color,a=typeof t.strokeWidth=="number"&&It.includes(t.strokeWidth)?t.strokeWidth:Se.strokeWidth;return{color:n,strokeWidth:a}}catch{return Se}}function yn(e){if(!(typeof window>"u"))try{window.localStorage.setItem(Dt,JSON.stringify(e))}catch{}}const pt=xn(),tt={activeTool:"select",toolColor:pt.color,strokeWidth:pt.strokeWidth,paths:[],boxes:[],memos:[],activeMemoId:null,activePath:null,activeBox:null,eraserMode:"object",activeEraserStroke:null,eraserBaseline:null,selectionBox:null,selectedIds:[],past:[],future:[],memoBaseline:null,moveBaseline:null,isDirty:!1};function xe(e){return{paths:e.paths,boxes:e.boxes,memos:e.memos}}function ge(e){return{...e,past:[...e.past.slice(-49),xe(e)],future:[]}}function Ge(e,t){return{...e,past:[...e.past.slice(-49),t],future:[]}}function kn(e,t){return JSON.stringify(e)===JSON.stringify(t)}function mt(e,t){return{...e,...t,activeMemoId:null,activePath:null,activeBox:null,selectionBox:null,selectedIds:[],isDirty:!0}}function Cn(e,t,n){const{start:a,current:r}=e,l=Math.min(a.x,r.x),s=Math.min(a.y,r.y),d=Math.abs(r.x-a.x),u=Math.abs(r.y-a.y);return d<.01||u<.01?null:{id:crypto.randomUUID(),x:l,y:s,width:d,height:u,color:t,strokeWidth:n}}function wn(e,t){return{...e,x:Math.min(1-e.width,Math.max(0,e.x+t.x)),y:Math.min(1-e.height,Math.max(0,e.y+t.y))}}function Ze(e,t){return{x:Math.min(1,Math.max(0,e.x+t.x)),y:Math.min(1,Math.max(0,e.y+t.y))}}function _n(e,t){switch(t.type){case"SET_TOOL":return{...e,activeTool:t.tool};case"SET_ERASER_MODE":return{...e,eraserMode:t.mode};case"SET_STYLE":return{...e,toolColor:t.style.color,strokeWidth:t.style.strokeWidth};case"START_PATH":return{...e,isDirty:!0,activePath:{id:crypto.randomUUID(),tool:e.activeTool,points:[t.point],color:e.toolColor,strokeWidth:e.strokeWidth}};case"ADD_POINT":return e.activePath?{...e,activePath:{...e.activePath,points:[...e.activePath.points,t.point]}}:e;case"END_PATH":return!e.activePath||e.activePath.points.length<2?{...e,activePath:null}:{...ge(e),isDirty:!0,paths:[...e.paths,e.activePath],activePath:null};case"START_BOX":return{...e,isDirty:!0,activeBox:{start:t.point,current:t.point}};case"UPDATE_BOX":return e.activeBox?{...e,activeBox:{...e.activeBox,current:t.point}}:e;case"END_BOX":{if(!e.activeBox)return e;const n=Cn(e.activeBox,e.toolColor,e.strokeWidth);return n?{...ge(e),isDirty:!0,boxes:[...e.boxes,n],activeBox:null}:{...e,activeBox:null}}case"CREATE_MEMO":{const n=crypto.randomUUID(),a={id:n,x:t.point.x,y:t.point.y,text:"",color:e.toolColor};return{...ge(e),isDirty:!0,memos:[...e.memos,a],activeMemoId:n}}case"UPDATE_MEMO":return{...e,isDirty:!0,memos:e.memos.map(n=>n.id===t.id?{...n,text:t.text}:n)};case"COMMIT_MEMO_EDIT":return e.memoBaseline?kn(e.memoBaseline,xe(e))?{...e,memoBaseline:null,activeMemoId:null}:{...Ge(e,e.memoBaseline),memoBaseline:null,activeMemoId:null,isDirty:!0}:{...e,activeMemoId:null};case"DELETE_MEMO":return{...ge(e),isDirty:!0,memos:e.memos.filter(n=>n.id!==t.id),activeMemoId:e.activeMemoId===t.id?null:e.activeMemoId,selectedIds:e.selectedIds.filter(n=>!pe(n,"memo",t.id))};case"FOCUS_MEMO":return{...e,activeMemoId:t.id,memoBaseline:t.id&&e.activeMemoId!==t.id&&!e.memoBaseline?xe(e):e.memoBaseline};case"CLEAR":return{...ge(e),isDirty:!0,paths:[],boxes:[],memos:[],activeMemoId:null,activePath:null,activeBox:null,selectionBox:null,selectedIds:[]};case"LOAD":return{...tt,activeTool:e.activeTool,eraserMode:e.eraserMode,toolColor:e.toolColor,strokeWidth:e.strokeWidth,...t.payload};case"MARK_SAVED":return{...e,isDirty:!1};case"RESET_LOCAL":return{...tt,activeTool:e.activeTool,eraserMode:e.eraserMode,toolColor:e.toolColor,strokeWidth:e.strokeWidth};case"UNDO":{const n=e.past.at(-1);return n?{...mt(e,n),past:e.past.slice(0,-1),future:[xe(e),...e.future]}:e}case"REDO":{const n=e.future[0];return n?{...mt(e,n),past:[...e.past.slice(-49),xe(e)],future:e.future.slice(1)}:e}case"SELECT_ONE":return{...e,selectedIds:[t.id],selectionBox:null};case"TOGGLE_SELECTED":return{...e,selectedIds:e.selectedIds.includes(t.id)?e.selectedIds.filter(n=>n!==t.id):[...e.selectedIds,t.id],selectionBox:null};case"CLEAR_SELECTION":return{...e,selectedIds:[],selectionBox:null};case"DELETE_SELECTED":return e.selectedIds.length===0?e:{...ge(e),isDirty:!0,paths:e.paths.filter(n=>!e.selectedIds.some(a=>pe(a,"path",n.id))),boxes:e.boxes.filter(n=>!e.selectedIds.some(a=>pe(a,"box",n.id))),memos:e.memos.filter(n=>!e.selectedIds.some(a=>pe(a,"memo",n.id))),selectedIds:[]};case"MOVE_SELECTED":return e.selectedIds.length===0?e:{...e,isDirty:!0,paths:e.paths.map(n=>e.selectedIds.some(a=>pe(a,"path",n.id))?{...n,points:n.points.map(a=>Ze(a,t.delta))}:n),boxes:e.boxes.map(n=>e.selectedIds.some(a=>pe(a,"box",n.id))?wn(n,t.delta):n),memos:e.memos.map(n=>e.selectedIds.some(a=>pe(a,"memo",n.id))?{...n,x:Ze(n,t.delta).x,y:Ze(n,t.delta).y}:n)};case"START_SELECTED_MOVE":return{...e,moveBaseline:xe(e)};case"COMMIT_SELECTED_MOVE":return e.moveBaseline?{...Ge(e,e.moveBaseline),moveBaseline:null,isDirty:!0}:e;case"START_SELECTION_BOX":return{...e,selectionBox:{start:t.point,current:t.point},selectedIds:[]};case"UPDATE_SELECTION_BOX":return e.selectionBox?{...e,selectionBox:{...e.selectionBox,current:t.point}}:e;case"END_SELECTION_BOX":return{...e,selectionBox:null,selectedIds:t.ids};case"ERASE_OBJECT":{const n=lt(t.id);return!n||!(n.kind==="path"?e.paths.some(r=>r.id===n.id):n.kind==="box"?e.boxes.some(r=>r.id===n.id):e.memos.some(r=>r.id===n.id))?e:{...ge(e),isDirty:!0,paths:n.kind==="path"?e.paths.filter(r=>r.id!==n.id):e.paths,boxes:n.kind==="box"?e.boxes.filter(r=>r.id!==n.id):e.boxes,memos:n.kind==="memo"?e.memos.filter(r=>r.id!==n.id):e.memos,selectedIds:e.selectedIds.filter(r=>r!==t.id)}}case"START_ERASER_STROKE":return{...e,activeEraserStroke:{points:[t.point],radius:.018},eraserBaseline:xe(e)};case"UPDATE_ERASER_STROKE":return e.activeEraserStroke?{...e,activeEraserStroke:{...e.activeEraserStroke,points:[...e.activeEraserStroke.points,t.point]}}:e;case"END_ERASER_STROKE":{if(!e.activeEraserStroke||!e.eraserBaseline)return{...e,activeEraserStroke:null,eraserBaseline:null};const n=mn({paths:e.paths,points:e.activeEraserStroke.points,radius:e.activeEraserStroke.radius});return n.changed?{...Ge(e,e.eraserBaseline),paths:n.paths,activeEraserStroke:null,eraserBaseline:null,selectedIds:[],isDirty:!0}:{...e,activeEraserStroke:null,eraserBaseline:null}}default:return e}}function Mn(){const[e,t]=c.useReducer(_n,tt),n=c.useMemo(()=>e.paths.length>0||e.boxes.length>0||e.memos.length>0,[e.paths.length,e.boxes.length,e.memos.length]),a=e.past.length>0,r=e.future.length>0,l=c.useCallback(g=>t({type:"SET_TOOL",tool:g}),[]),s=c.useCallback(g=>{yn(g),t({type:"SET_STYLE",style:g})},[]),d=c.useCallback(()=>t({type:"CLEAR"}),[]),u=c.useCallback(g=>t({type:"LOAD",payload:g}),[]),i=c.useCallback(()=>t({type:"MARK_SAVED"}),[]),b=c.useCallback(()=>t({type:"RESET_LOCAL"}),[]),f=c.useCallback(()=>t({type:"UNDO"}),[]),_=c.useCallback(()=>t({type:"REDO"}),[]),B=c.useCallback(()=>t({type:"COMMIT_MEMO_EDIT"}),[]),A=c.useCallback(()=>t({type:"START_SELECTED_MOVE"}),[]),O=c.useCallback(()=>t({type:"COMMIT_SELECTED_MOVE"}),[]),T=c.useCallback(g=>{e.activeTool==="pen"||e.activeTool==="arrow"?t({type:"START_PATH",point:g}):e.activeTool==="box"&&t({type:"START_BOX",point:g})},[e.activeTool]),N=c.useCallback(g=>{e.activePath?t({type:"ADD_POINT",point:g}):e.activeBox&&t({type:"UPDATE_BOX",point:g})},[e.activePath,e.activeBox]),p=c.useCallback(()=>{e.activePath?t({type:"END_PATH"}):e.activeBox&&t({type:"END_BOX"})},[e.activePath,e.activeBox]),C=c.useCallback(g=>t({type:"CREATE_MEMO",point:g}),[]),M=c.useCallback((g,D)=>t({type:"UPDATE_MEMO",id:g,text:D}),[]),y=c.useCallback(g=>t({type:"DELETE_MEMO",id:g}),[]),v=c.useCallback(g=>t({type:"FOCUS_MEMO",id:g}),[]),X=c.useCallback(g=>t({type:"SET_ERASER_MODE",mode:g}),[]),R=c.useCallback(g=>t({type:"SELECT_ONE",id:g}),[]),$=c.useCallback(g=>t({type:"TOGGLE_SELECTED",id:g}),[]),x=c.useCallback(()=>t({type:"CLEAR_SELECTION"}),[]),E=c.useCallback(()=>t({type:"DELETE_SELECTED"}),[]),S=c.useCallback(g=>t({type:"MOVE_SELECTED",delta:g}),[]),P=c.useCallback(g=>t({type:"START_SELECTION_BOX",point:g}),[]),Y=c.useCallback(g=>t({type:"UPDATE_SELECTION_BOX",point:g}),[]),ne=c.useCallback(g=>t({type:"END_SELECTION_BOX",ids:g}),[]),ae=c.useCallback(g=>t({type:"ERASE_OBJECT",id:g}),[]),re=c.useCallback(g=>t({type:"START_ERASER_STROKE",point:g}),[]),le=c.useCallback(g=>t({type:"UPDATE_ERASER_STROKE",point:g}),[]),I=c.useCallback(()=>t({type:"END_ERASER_STROKE"}),[]),F=c.useCallback(()=>({paths:e.paths,boxes:e.boxes,memos:e.memos}),[e.paths,e.boxes,e.memos]);return{...e,canUndo:a,canRedo:r,hasAnnotations:n,setTool:l,setStyle:s,setEraserMode:X,startDrawing:T,moveDrawing:N,endDrawing:p,createMemo:C,updateMemo:M,commitMemoEdit:B,deleteMemo:y,focusMemo:v,clear:d,load:u,toPayload:F,markSaved:i,resetLocal:b,undo:f,redo:_,selectOne:R,toggleSelected:$,clearSelection:x,deleteSelected:E,moveSelected:S,startSelectedMove:A,commitSelectedMove:O,startSelectionBox:P,updateSelectionBox:Y,endSelectionBox:ne,eraseObjectAtPoint:ae,startEraserStroke:re,updateEraserStroke:le,endEraserStroke:I}}function Ie(e,t){return{x:e.x*t.width,y:e.y*t.height}}function nt(e,t,n){if(t.points.length<2)return;const a=Ie(t.points[0],n);e.save(),e.beginPath(),e.strokeStyle=t.color,e.lineWidth=t.strokeWidth,e.lineCap="round",e.lineJoin="round",e.moveTo(a.x,a.y);for(const r of t.points.slice(1)){const l=Ie(r,n);e.lineTo(l.x,l.y)}if(e.stroke(),t.tool==="arrow"){const r=Ie(t.points[t.points.length-1],n),l=Ie(t.points[t.points.length-2],n);Bn(e,l,r,t.color,t.strokeWidth)}e.restore()}function at(e,t,n,a){const r="start"in t?{x:Math.min(t.start.x,t.current.x),y:Math.min(t.start.y,t.current.y),width:Math.abs(t.current.x-t.start.x),height:Math.abs(t.current.y-t.start.y),color:"#64c8ff",strokeWidth:2}:t;e.save(),e.strokeStyle=r.color,e.lineWidth=a==="active"?Math.max(2,r.strokeWidth):r.strokeWidth,a==="active"&&e.setLineDash([8,6]),e.strokeRect(r.x*n.width,r.y*n.height,r.width*n.width,r.height*n.height),e.restore()}function En(e,t,n){const a=t.x*n.width,r=t.y*n.height,l=Math.min(260,Math.max(150,n.width*.22)),s=12,d=18;e.save(),e.font="14px sans-serif";const u=jn(e,t.text.trim()||" ",l-s*2),i=Math.max(52,s*2+u.length*d);e.fillStyle="rgba(255, 246, 179, 0.96)",e.strokeStyle="rgba(44, 37, 12, 0.28)",e.lineWidth=1,Tn(e,a,r,l,i,8),e.fill(),e.stroke(),e.fillStyle="#2f2a13",e.textBaseline="top",u.forEach((b,f)=>{e.fillText(b,a+s,r+s+f*d)}),e.restore()}function Sn(e,t){const n=lt(e);if(!n)return null;if(n.kind==="box")return t.boxes.find(i=>i.id===n.id)??null;const a=n.kind==="memo"?t.memos.find(i=>i.id===n.id):null;if(a)return{id:a.id,x:a.x,y:a.y,width:.18,height:.12,color:a.color,strokeWidth:1};if(n.kind!=="path")return null;const r=t.paths.find(i=>i.id===n.id);if(!r||r.points.length===0)return null;const l=r.points.map(i=>i.x),s=r.points.map(i=>i.y),d=Math.min(...l),u=Math.min(...s);return{id:r.id,x:d,y:u,width:Math.max(.01,Math.max(...l)-d),height:Math.max(.01,Math.max(...s)-u),color:r.color,strokeWidth:r.strokeWidth}}function vt(e,t,n){const a="start"in t?{x:Math.min(t.start.x,t.current.x),y:Math.min(t.start.y,t.current.y),width:Math.abs(t.current.x-t.start.x),height:Math.abs(t.current.y-t.start.y)}:t;e.save(),e.strokeStyle="#64c8ff",e.lineWidth=2,e.setLineDash([5,5]),e.strokeRect(a.x*n.width,a.y*n.height,a.width*n.width,a.height*n.height),e.restore()}function Bn(e,t,n,a,r){const l=Math.atan2(n.y-t.y,n.x-t.x),s=Math.max(12,r*4),d=Math.PI/7;e.save(),e.fillStyle=a,e.beginPath(),e.moveTo(n.x,n.y),e.lineTo(n.x-s*Math.cos(l-d),n.y-s*Math.sin(l-d)),e.lineTo(n.x-s*Math.cos(l+d),n.y-s*Math.sin(l+d)),e.closePath(),e.fill(),e.restore()}function jn(e,t,n){const a=t.split(/\s+/).filter(Boolean);if(a.length===0)return[""];const r=[];let l="";for(const s of a){const d=l?`${l} ${s}`:s;if(e.measureText(d).width<=n||l===""){l=d;continue}r.push(l),l=s}return l&&r.push(l),r}function Tn(e,t,n,a,r,l){const s=Math.min(l,a/2,r/2);e.beginPath(),e.moveTo(t+s,n),e.lineTo(t+a-s,n),e.quadraticCurveTo(t+a,n,t+a,n+s),e.lineTo(t+a,n+r-s),e.quadraticCurveTo(t+a,n+r,t+a-s,n+r),e.lineTo(t+s,n+r),e.quadraticCurveTo(t,n+r,t,n+r-s),e.lineTo(t,n+s),e.quadraticCurveTo(t,n,t+s,n),e.closePath()}function Pn({paths:e,boxes:t,memos:n=[],selectedIds:a=[],selectionBox:r=null,activePath:l,activeBox:s}){const d=c.useRef(null);return c.useEffect(()=>{const u=d.current;if(!u)return;const i=u.getBoundingClientRect(),b=window.devicePixelRatio||1;u.width=Math.max(1,Math.round(i.width*b)),u.height=Math.max(1,Math.round(i.height*b));const f=u.getContext("2d");if(!f)return;f.setTransform(b,0,0,b,0,0),f.clearRect(0,0,i.width,i.height);const _={width:i.width,height:i.height};for(const B of e)nt(f,B,_);for(const B of t)at(f,B,_,"committed");for(const B of a){const A=Sn(B,{paths:e,boxes:t,memos:n});A&&vt(f,A,_)}r&&vt(f,r,_),l&&nt(f,l,_),s&&at(f,s,_,"active")},[e,t,n,a,r,l,s]),o.jsx("canvas",{ref:d,className:"canvas-annotation-layer","aria-hidden":"true"})}function Ne(e){e.stopPropagation()}function Dn({memos:e,activeMemoId:t,onUpdate:n,onDelete:a,onFocus:r,onCommit:l}){return o.jsx("div",{className:"canvas-memo-overlay",children:e.map(s=>o.jsx("textarea",{className:`canvas-memo${t===s.id?" canvas-memo--active":""}`,value:s.text,style:{left:`${s.x*100}%`,top:`${s.y*100}%`},autoFocus:t===s.id,onFocus:()=>r(s.id),onPointerDown:Ne,onPointerMove:Ne,onPointerUp:Ne,onPointerCancel:Ne,onChange:d=>n(s.id,d.currentTarget.value),onBlur:()=>{l?.(),s.text.trim()===""&&a(s.id)},"aria-label":"Canvas memo"},s.id))})}function An({annotationFrameRef:e,imageElementRef:t,frameClassName:n,frameStyle:a,imageKey:r,imageSrc:l,fallbackImage:s,alt:d,canvasOpen:u,maskOverlayUrl:i,cleanupLayer:b,annotations:f,onOpenCanvas:_,onPointerDown:B,onPointerMove:A,onPointerUp:O,onPointerLeave:T}){return o.jsxs("div",{ref:e,className:n,onPointerDown:B,onPointerMove:A,onPointerUp:O,onPointerCancel:O,onPointerLeave:T,style:a,children:[o.jsx("img",{ref:t,className:"result-img",src:l??s,alt:d,decoding:"async",onDoubleClick:N=>{N.stopPropagation(),_()}},r),u&&i?o.jsx("img",{className:"canvas-background-cleanup-mask",src:i,alt:"","aria-hidden":"true",decoding:"async"}):null,u?b:null,u&&o.jsxs(o.Fragment,{children:[o.jsx(Pn,{paths:f.paths,boxes:f.boxes,memos:f.memos,selectedIds:f.selectedIds,selectionBox:f.selectionBox,activePath:f.activePath,activeBox:f.activeBox}),o.jsx(Dn,{memos:f.memos,activeMemoId:f.activeMemoId,onUpdate:f.updateMemo,onDelete:f.deleteMemo,onFocus:f.focusMemo,onCommit:f.commitMemoEdit})]})]})}function In(e){return`${e.x*100} ${e.y*100}`}function Nn(e){return e.map(In).join(" ")}function Rn({seeds:e,brushStrokes:t,brushCursor:n,brushRadius:a,active:r}){if(!r&&e.length===0&&t.length===0)return null;const l=a*100;return o.jsxs("svg",{className:"canvas-cleanup-overlay",viewBox:"0 0 100 100",preserveAspectRatio:"none","aria-hidden":"true",children:[t.map(s=>o.jsx("polyline",{className:`canvas-cleanup-overlay__stroke canvas-cleanup-overlay__stroke--${s.intent}`,points:Nn(s.points),strokeWidth:Math.max(.3,s.radius*200),vectorEffect:"non-scaling-stroke"},s.id)),r&&n?o.jsx("circle",{className:"canvas-cleanup-cursor",cx:n.x*100,cy:n.y*100,r:Math.max(.6,l),vectorEffect:"non-scaling-stroke"}):null]})}function Ln({mode:e,matteColor:t,onModeChange:n,onMatteColorChange:a}){const{t:r}=ke();return o.jsxs("div",{className:"canvas-toolbar__bg",role:"group","aria-label":r("canvas.toolbar.bgGroup"),children:[o.jsx("button",{type:"button",className:`canvas-toolbar__bg-tab${e==="alpha"?" active":""}`,onClick:()=>n("alpha"),children:r("canvas.toolbar.bgAlpha")}),o.jsx("button",{type:"button",className:`canvas-toolbar__bg-tab${e==="matte"?" active":""}`,onClick:()=>n("matte"),children:r("canvas.toolbar.bgMatte")}),e==="matte"?o.jsx("input",{type:"color","aria-label":r("canvas.toolbar.bgMatteColor"),value:t,onChange:l=>a(l.target.value)}):null]})}function bt({label:e,value:t,options:n,onChange:a}){return o.jsxs("div",{className:"canvas-toolbar__segmented-row",children:[o.jsx("span",{className:"canvas-toolbar__segmented-label",children:e}),o.jsx("div",{className:"canvas-toolbar__segmented",role:"group","aria-label":e,children:n.map(r=>o.jsx("button",{type:"button",className:"canvas-toolbar__segmented-button","data-value":r.value,"aria-pressed":t===r.value,onClick:()=>a(r.value),children:r.label},r.value))})]})}function On({seedCount:e,tolerance:t,stats:n,hasPreview:a,isPickingSeed:r,intent:l,tool:s,brushRadius:d,isPreviewing:u,isApplying:i,keepOpen:b,disabled:f,onAutoSample:_,onPickSeed:B,onIntentChange:A,onToolChange:O,onBrushRadiusChange:T,onToleranceChange:N,onPreview:p,onApply:C,onReset:M}){const{t:y}=ke(),[v,X]=c.useState(!1),R=c.useRef(null),$=n?Math.round(n.removedPercent*1e3)/10:0,x=r||s==="brush";return c.useEffect(()=>{if(!v)return;const E=S=>{b||R.current?.contains(S.target)||X(!1)};return window.addEventListener("pointerdown",E),()=>window.removeEventListener("pointerdown",E)},[b,v]),o.jsxs("div",{className:"canvas-toolbar__cleanup",ref:R,children:[o.jsx("button",{type:"button",className:`canvas-toolbar__button${v||a?" canvas-toolbar__button--active":""}`,onClick:()=>X(E=>!E),disabled:f,"aria-expanded":v,"aria-label":y("canvas.toolbar.cleanup"),title:y("canvas.toolbar.cleanup"),children:o.jsx($n,{})}),v?o.jsxs("div",{className:"canvas-toolbar__cleanup-panel",role:"group","aria-label":y("canvas.toolbar.cleanup"),children:[o.jsxs("div",{className:"canvas-toolbar__cleanup-row",children:[o.jsx("span",{className:"canvas-toolbar__cleanup-title",children:y("canvas.toolbar.cleanup")}),o.jsx("span",{className:"canvas-toolbar__cleanup-meta",children:y("canvas.toolbar.cleanupSeedCount",{n:e})})]}),o.jsx(bt,{label:y("canvas.toolbar.cleanupMark"),value:l,options:[{value:"remove",label:y("canvas.toolbar.cleanupRemove")},{value:"preserve",label:y("canvas.toolbar.cleanupPreserve")}],onChange:A}),o.jsx(bt,{label:y("canvas.toolbar.cleanupInput"),value:s,options:[{value:"click",label:y("canvas.toolbar.cleanupClick")},{value:"brush",label:y("canvas.toolbar.cleanupBrush")}],onChange:O}),o.jsxs("label",{className:"canvas-toolbar__cleanup-slider",children:[o.jsx("span",{children:y("canvas.toolbar.cleanupTolerance")}),o.jsx("input",{type:"range",min:"0",max:"96",value:t,onChange:E=>N(Number(E.target.value))}),o.jsx("output",{children:t})]}),s==="brush"?o.jsxs("label",{className:"canvas-toolbar__cleanup-slider",children:[o.jsx("span",{children:y("canvas.toolbar.cleanupBrushSize")}),o.jsx("input",{type:"range",min:"0.006",max:"0.06",step:"0.002",value:d,onChange:E=>T(Number(E.target.value))}),o.jsx("output",{children:Math.round(d*1e3)})]}):null,o.jsxs("div",{className:"canvas-toolbar__cleanup-actions",children:[o.jsx("button",{type:"button",onClick:_,children:y("canvas.toolbar.cleanupAutoSample")}),o.jsx("button",{type:"button",className:r?"active":"",onClick:B,children:y(x?"canvas.toolbar.cleanupActive":"canvas.toolbar.cleanupPickSeed")})]}),o.jsxs("div",{className:"canvas-toolbar__cleanup-actions",children:[o.jsx("button",{type:"button",onClick:p,disabled:u||e===0,children:y(u?"canvas.toolbar.cleanupPreviewing":"canvas.toolbar.cleanupPreview")}),o.jsx("button",{type:"button",onClick:C,disabled:i||!a&&e===0,children:y(i?"canvas.toolbar.cleanupApplying":"canvas.toolbar.cleanupApply")}),o.jsx("button",{type:"button",onClick:M,disabled:!a&&e===0,children:y("canvas.toolbar.cleanupReset")})]}),x?o.jsx("div",{className:"canvas-toolbar__cleanup-status canvas-toolbar__cleanup-status--active",children:y(s==="brush"?"canvas.toolbar.cleanupBrushHint":"canvas.toolbar.cleanupPickHint")}):n&&!a?o.jsx("div",{className:"canvas-toolbar__cleanup-status canvas-toolbar__cleanup-status--active",children:y("canvas.toolbar.cleanupMaskHint")}):null,n?o.jsx("div",{className:"canvas-toolbar__cleanup-status",children:y("canvas.toolbar.cleanupRemoved",{n:$})}):null]}):null]})}function $n(){return o.jsxs("svg",{className:"canvas-toolbar__icon",viewBox:"0 0 24 24","aria-hidden":"true",children:[o.jsx("path",{d:"M5 7.5h14"}),o.jsx("path",{d:"M7 12h10"}),o.jsx("path",{d:"M10 16.5h4"}),o.jsx("path",{d:"M7.5 5.5 9 4l1.5 1.5L9 7 7.5 5.5Z"}),o.jsx("path",{d:"M13.5 11 15 9.5l1.5 1.5L15 12.5 13.5 11Z"}),o.jsx("path",{d:"M4.5 15.5 6 14l1.5 1.5L6 17 4.5 15.5Z"})]})}function Un({style:e,onStyleChange:t}){const{t:n}=ke(),[a,r]=c.useState(!1),l=c.useRef(null);return c.useEffect(()=>{if(!a)return;const s=d=>{l.current?.contains(d.target)||r(!1)};return window.addEventListener("pointerdown",s),()=>window.removeEventListener("pointerdown",s)},[a]),o.jsxs("div",{ref:l,className:`canvas-toolbar__split-button${a?" canvas-toolbar__split-button--active":""}`,onKeyDown:s=>{s.key==="Escape"&&a&&(s.preventDefault(),s.stopPropagation(),r(!1))},children:[o.jsxs("button",{type:"button",className:"canvas-toolbar__button canvas-toolbar__style-trigger",onClick:()=>r(s=>!s),"aria-haspopup":"dialog","aria-expanded":a,"aria-label":n("canvas.toolbar.style"),title:n("canvas.toolbar.style"),children:[o.jsx("span",{className:"canvas-style-trigger__swatch",style:{background:e.color},"aria-hidden":"true"}),o.jsx("span",{className:"canvas-style-trigger__width",style:{height:`${Math.min(8,Math.max(2,e.strokeWidth))}px`},"aria-hidden":"true"})]}),a?o.jsxs("div",{className:"canvas-style-popover",role:"dialog","aria-label":n("canvas.toolbar.style"),children:[o.jsx("div",{className:"canvas-style-popover__row",role:"group","aria-label":n("canvas.toolbar.color"),children:At.map(s=>o.jsx("button",{type:"button",className:`canvas-style-swatch${e.color===s?" canvas-style-swatch--active":""}`,style:{background:s},onClick:()=>t({...e,color:s}),"aria-pressed":e.color===s,"aria-label":s,title:s},s))}),o.jsx("div",{className:"canvas-style-popover__row",role:"group","aria-label":n("canvas.toolbar.strokeWidth"),children:It.map(s=>o.jsx("button",{type:"button",className:`canvas-style-width${e.strokeWidth===s?" canvas-style-width--active":""}`,onClick:()=>t({...e,strokeWidth:s}),"aria-pressed":e.strokeWidth===s,"aria-label":`${s}px`,title:`${s}px`,children:o.jsx("span",{style:{height:`${s}px`,background:e.color}})},s))})]}):null]})}function Wn({tools:e,activeTool:t,onToolChange:n}){const[a,r]=c.useState(!1),l=c.useRef(null),s=e.find(u=>u.id===t)??e[0],d=s.icon;return c.useEffect(()=>{if(!a)return;const u=i=>{l.current?.contains(i.target)||r(!1)};return window.addEventListener("pointerdown",u),()=>window.removeEventListener("pointerdown",u)},[a]),o.jsxs("div",{ref:l,className:"canvas-tool-picker",children:[o.jsxs("button",{type:"button",className:`canvas-toolbar__button canvas-tool-picker__trigger${t!=="eraser"?" canvas-toolbar__button--active":""}`,onClick:()=>r(u=>!u),"aria-label":`${s.label} (${s.shortcut})`,"aria-pressed":t===s.id,"aria-haspopup":"menu","aria-expanded":a,title:`${s.label} (${s.shortcut})`,children:[o.jsx(d,{}),o.jsx("span",{className:"canvas-toolbar__shortcut","aria-hidden":"true",children:s.shortcut})]}),a?o.jsx("div",{className:"canvas-tool-picker__menu",role:"menu",children:e.map(u=>{const i=u.icon,b=t===u.id;return o.jsxs("button",{type:"button",className:`canvas-tool-picker__item${b?" active":""}`,role:"menuitemradio","aria-checked":b,onClick:()=>{n(u.id),r(!1)},children:[o.jsx(i,{}),o.jsx("span",{children:u.label}),o.jsx("kbd",{children:u.shortcut})]},u.id)})}):null]})}function Hn({activeTool:e,hasAnnotations:t,hasExportableContent:n,onToolChange:a,eraserMode:r="object",onEraserModeChange:l,style:s,onStyleChange:d,onClear:u,onApply:i,onExport:b,onUndo:f,onRedo:_,canUndo:B,canRedo:A,onDeleteSelected:O,selectedCount:T=0,onEditWithMask:N,canEditWithMask:p,isEditingWithMask:C,isApplying:M,isExporting:y,exportBackground:v="alpha",exportMatteColor:X="#ffffff",onExportBackgroundChange:R,onExportMatteColorChange:$,cleanupTolerance:x=28,cleanupSeedCount:E=0,cleanupStats:S=null,cleanupHasPreview:P=!1,isCleanupPickingSeed:Y=!1,isCleanupActive:ne=!1,cleanupIntent:ae="remove",cleanupTool:re="click",cleanupBrushRadius:le=.018,isCleanupPreviewing:I=!1,isCleanupApplying:F=!1,onCleanupAutoSample:g,onCleanupPickSeed:D,onCleanupIntentChange:J,onCleanupToolChange:de,onCleanupBrushRadiusChange:ce,onCleanupToleranceChange:G,onCleanupPreview:Q,onCleanupApply:Z,onCleanupReset:K}){const{t:k}=ke(),[H,ee]=c.useState(!1),U=c.useRef(null),te=n??t??!1,z=k(r==="object"?"canvas.toolbar.objectEraser":"canvas.toolbar.brushEraser"),V=[{id:"select",shortcut:"1",label:k("canvas.toolbar.select"),icon:Fn},{id:"pen",shortcut:"2",label:k("canvas.toolbar.pen"),icon:Vn},{id:"box",shortcut:"3",label:k("canvas.toolbar.box"),icon:Kn},{id:"arrow",shortcut:"4",label:k("canvas.toolbar.arrow"),icon:zn},{id:"memo",shortcut:"5",label:k("canvas.toolbar.memo"),icon:Xn}];c.useEffect(()=>{if(!H)return;const oe=we=>{U.current?.contains(we.target)||ee(!1)};return window.addEventListener("pointerdown",oe),()=>window.removeEventListener("pointerdown",oe)},[H]);const he=oe=>{l?.(oe),a("eraser"),ee(!1)};return o.jsxs("div",{className:"canvas-toolbar","aria-label":k("canvas.toolbar.label"),children:[o.jsx(Wn,{tools:V,activeTool:e,onToolChange:a}),o.jsx(Un,{style:s,onStyleChange:d}),o.jsxs("div",{ref:U,className:`canvas-toolbar__split-button${e==="eraser"?" canvas-toolbar__split-button--active":""}`,onKeyDown:oe=>{oe.key==="Escape"&&H&&(oe.preventDefault(),ee(!1))},children:[o.jsxs("button",{type:"button",className:`canvas-toolbar__button canvas-toolbar__button--split-main${e==="eraser"?" canvas-toolbar__button--active":""}`,onClick:()=>a("eraser"),"aria-label":`${z} (6)`,"aria-pressed":e==="eraser",title:`${z} (6)`,children:[o.jsx(qn,{}),o.jsx("span",{className:"canvas-toolbar__shortcut","aria-hidden":"true",children:"6"})]}),o.jsx("button",{type:"button",className:"canvas-toolbar__button canvas-toolbar__button--split-menu",onClick:()=>ee(oe=>!oe),"aria-label":k("canvas.toolbar.eraserMenu"),"aria-haspopup":"menu","aria-expanded":H,"aria-controls":"canvas-eraser-menu",title:k("canvas.toolbar.eraserMenu"),children:o.jsx(Yn,{})}),H?o.jsxs("div",{id:"canvas-eraser-menu",className:"canvas-toolbar__eraser-menu",role:"menu",children:[o.jsx("button",{type:"button",className:`canvas-toolbar__eraser-menu-item${r==="object"?" canvas-toolbar__eraser-menu-item--active":""}`,role:"menuitemradio","aria-checked":r==="object",onClick:()=>he("object"),children:k("canvas.toolbar.objectEraser")}),o.jsx("button",{type:"button",className:`canvas-toolbar__eraser-menu-item${r==="brush"?" canvas-toolbar__eraser-menu-item--active":""}`,role:"menuitemradio","aria-checked":r==="brush",onClick:()=>he("brush"),children:k("canvas.toolbar.brushEraser")})]}):null]}),o.jsx("span",{className:"canvas-toolbar__divider","aria-hidden":"true"}),i?o.jsx("button",{type:"button",className:`canvas-toolbar__button canvas-toolbar__button--primary${M?" canvas-toolbar__button--busy":""}`,onClick:i,disabled:!te||M,"aria-label":k("canvas.toolbar.apply"),title:k("canvas.toolbar.apply"),children:o.jsx(Gn,{})}):null,N?o.jsx("button",{type:"button",className:`canvas-toolbar__button canvas-toolbar__button--primary canvas-toolbar__button--mask${C?" canvas-toolbar__button--busy":""}`,onClick:N,disabled:!p||C,"aria-label":k(p?"canvas.toolbar.editMask":"canvas.toolbar.editMaskDisabled"),title:k(p?"canvas.toolbar.editMask":"canvas.toolbar.editMaskDisabled"),children:o.jsx(ea,{})}):null,f?o.jsx("button",{type:"button",className:"canvas-toolbar__button",onClick:f,disabled:!B,"aria-label":k("canvas.toolbar.undo"),title:k("canvas.toolbar.undo"),children:o.jsx(Jn,{})}):null,_?o.jsx("button",{type:"button",className:"canvas-toolbar__button",onClick:_,disabled:!A,"aria-label":k("canvas.toolbar.redo"),title:k("canvas.toolbar.redo"),children:o.jsx(Qn,{})}):null,O?o.jsx("button",{type:"button",className:"canvas-toolbar__button canvas-toolbar__button--danger",onClick:O,disabled:T===0,"aria-label":k("canvas.toolbar.deleteSelected"),title:k("canvas.toolbar.deleteSelected"),children:o.jsx(gt,{})}):null,b&&R&&$?o.jsx(Ln,{mode:v,matteColor:X,onModeChange:R,onMatteColorChange:$}):null,g&&D&&J&&de&&ce&&G&&Q&&Z&&K?o.jsx(On,{seedCount:E,tolerance:x,stats:S,hasPreview:P,isPickingSeed:Y,intent:ae,tool:re,brushRadius:le,isPreviewing:I,isApplying:F,keepOpen:ne,disabled:M||y,onAutoSample:g,onPickSeed:D,onIntentChange:J,onToolChange:de,onBrushRadiusChange:ce,onToleranceChange:G,onPreview:Q,onApply:Z,onReset:K}):null,b?o.jsx("button",{type:"button",className:`canvas-toolbar__button${y?" canvas-toolbar__button--busy":""}`,onClick:b,disabled:!te||y,"aria-label":k("canvas.toolbar.export"),title:k("canvas.toolbar.export"),children:o.jsx(Zn,{})}):null,o.jsx("button",{type:"button",className:"canvas-toolbar__button canvas-toolbar__button--danger",onClick:u,disabled:!te,"aria-label":k("canvas.toolbar.clear"),title:k("canvas.toolbar.clear"),children:o.jsx(gt,{})})]})}function Fn(){return o.jsxs("svg",{className:"canvas-toolbar__icon",viewBox:"0 0 24 24","aria-hidden":"true",children:[o.jsx("path",{d:"M8 12.5V7a2 2 0 0 1 4 0v4"}),o.jsx("path",{d:"M12 11V5a2 2 0 0 1 4 0v7"}),o.jsx("path",{d:"M16 12V8a2 2 0 0 1 4 0v5.5A6.5 6.5 0 0 1 13.5 20H12a6 6 0 0 1-4.24-1.76L4.7 15.18a1.7 1.7 0 0 1 2.4-2.4L9 14.68"})]})}function Vn(){return o.jsxs("svg",{className:"canvas-toolbar__icon",viewBox:"0 0 24 24","aria-hidden":"true",children:[o.jsx("path",{d:"m4 20 4.2-1.1L19.5 7.6a2.2 2.2 0 0 0-3.1-3.1L5.1 15.8 4 20Z"}),o.jsx("path",{d:"m14.5 6.5 3 3"})]})}function Kn(){return o.jsx("svg",{className:"canvas-toolbar__icon",viewBox:"0 0 24 24","aria-hidden":"true",children:o.jsx("rect",{x:"5",y:"5",width:"14",height:"14",rx:"2"})})}function zn(){return o.jsxs("svg",{className:"canvas-toolbar__icon",viewBox:"0 0 24 24","aria-hidden":"true",children:[o.jsx("path",{d:"M5 19 19 5"}),o.jsx("path",{d:"M10 5h9v9"})]})}function Xn(){return o.jsxs("svg",{className:"canvas-toolbar__icon",viewBox:"0 0 24 24","aria-hidden":"true",children:[o.jsx("path",{d:"M6 4h12v16H6z"}),o.jsx("path",{d:"M9 8h6"}),o.jsx("path",{d:"M9 12h5"}),o.jsx("path",{d:"M9 16h3"})]})}function qn(){return o.jsxs("svg",{className:"canvas-toolbar__icon",viewBox:"0 0 24 24","aria-hidden":"true",children:[o.jsx("path",{d:"m4 15 8.5-8.5a2.1 2.1 0 0 1 3 0l2 2a2.1 2.1 0 0 1 0 3L10 19H6.5L4 16.5V15Z"}),o.jsx("path",{d:"M10 19h10"}),o.jsx("path",{d:"m8.5 10.5 5 5"})]})}function Yn(){return o.jsx("svg",{className:"canvas-toolbar__icon canvas-toolbar__icon--small",viewBox:"0 0 24 24","aria-hidden":"true",children:o.jsx("path",{d:"m7 14 5-5 5 5"})})}function Gn(){return o.jsx("svg",{className:"canvas-toolbar__icon",viewBox:"0 0 24 24","aria-hidden":"true",children:o.jsx("path",{d:"M5 12.5 10 17 19 7"})})}function Zn(){return o.jsxs("svg",{className:"canvas-toolbar__icon",viewBox:"0 0 24 24","aria-hidden":"true",children:[o.jsx("path",{d:"M12 4v11"}),o.jsx("path",{d:"m8 11 4 4 4-4"}),o.jsx("path",{d:"M5 20h14"})]})}function gt(){return o.jsxs("svg",{className:"canvas-toolbar__icon",viewBox:"0 0 24 24","aria-hidden":"true",children:[o.jsx("path",{d:"M4 7h16"}),o.jsx("path",{d:"M9 7V5h6v2"}),o.jsx("path",{d:"M7 7l1 13h8l1-13"}),o.jsx("path",{d:"M10 11v5"}),o.jsx("path",{d:"M14 11v5"})]})}function Jn(){return o.jsxs("svg",{className:"canvas-toolbar__icon",viewBox:"0 0 24 24","aria-hidden":"true",children:[o.jsx("path",{d:"M9 7 5 11l4 4"}),o.jsx("path",{d:"M5 11h9a5 5 0 0 1 0 10h-2"})]})}function Qn(){return o.jsxs("svg",{className:"canvas-toolbar__icon",viewBox:"0 0 24 24","aria-hidden":"true",children:[o.jsx("path",{d:"m15 7 4 4-4 4"}),o.jsx("path",{d:"M19 11h-9a5 5 0 0 0 0 10h2"})]})}function ea(){return o.jsxs("svg",{className:"canvas-toolbar__icon",viewBox:"0 0 24 24","aria-hidden":"true",children:[o.jsx("rect",{x:"5",y:"5",width:"14",height:"14",rx:"2"}),o.jsx("path",{d:"M9 9h6v6H9z"})]})}function ta({annotations:e,backgroundCleanup:t,backgroundCleanupPreview:n,canvasState:a,actions:r}){return o.jsx(Hn,{activeTool:e.activeTool,eraserMode:e.eraserMode,onEraserModeChange:e.setEraserMode,style:{color:e.toolColor,strokeWidth:e.strokeWidth},onStyleChange:e.setStyle,hasExportableContent:e.hasAnnotations,onToolChange:e.setTool,onClear:e.clear,onApply:()=>{r.handleApplyCanvas()},onExport:()=>{r.handleExportCanvas()},onUndo:e.undo,onRedo:e.redo,canUndo:e.canUndo,canRedo:e.canRedo,onDeleteSelected:e.deleteSelected,selectedCount:e.selectedIds.length,onEditWithMask:()=>{r.handleEditWithMask()},canEditWithMask:e.boxes.length>0,isEditingWithMask:a.isEditingWithMask,isApplying:a.isApplying,isExporting:a.isExporting,exportBackground:a.exportBackground,exportMatteColor:a.exportMatteColor,onExportBackgroundChange:r.setExportBackground,onExportMatteColorChange:r.setExportMatteColor,cleanupTolerance:t.backgroundCleanupTolerance,cleanupSeedCount:t.backgroundCleanupSeeds.length,cleanupStats:t.backgroundCleanupStats,cleanupHasPreview:!!n,isCleanupPickingSeed:t.isBackgroundCleanupPickingSeed,isCleanupActive:t.isBackgroundCleanupActive,cleanupIntent:t.cleanupIntent,cleanupTool:t.cleanupTool,cleanupBrushRadius:t.cleanupBrushRadius,isCleanupPreviewing:t.isBackgroundCleanupPreviewing,isCleanupApplying:t.isBackgroundCleanupApplying,onCleanupAutoSample:t.handleBackgroundCleanupAutoSample,onCleanupPickSeed:t.handleBackgroundCleanupPickSeed,onCleanupIntentChange:t.setCleanupIntent,onCleanupToolChange:l=>{t.setCleanupTool(l),t.setIsBackgroundCleanupActive(!0)},onCleanupBrushRadiusChange:t.setCleanupBrushRadius,onCleanupToleranceChange:t.handleBackgroundCleanupToleranceChange,onCleanupPreview:()=>{t.runBackgroundCleanupPreview()},onCleanupApply:()=>{t.handleBackgroundCleanupApply()},onCleanupReset:t.handleBackgroundCleanupReset})}function na({currentImage:e,canvasDisplayImage:t,canvasOpen:n,displayQuality:a,displaySize:r,displayModel:l,onAfterDeleteFocus:s,onCopyPrompt:d}){const{t:u}=ke(),i=[e.elapsed!=null?`${e.elapsed}s`:null,e.usage?u("canvas.tokens",{n:e.usage.total_tokens??"?"}):null,an(e.reasoningEffort),a,r,l].filter(b=>!!b).join(" · ");return o.jsxs(o.Fragment,{children:[o.jsx("div",{className:"result-meta",children:i}),o.jsx(rn,{imageOverride:n?t:null,onAfterDeleteFocus:s}),e.prompt?o.jsx(on,{prompt:e.prompt,onCopy:d}):null]})}function aa({zoom:e,onZoomIn:t,onZoomOut:n,onZoomReset:a}){const{t:r}=ke(),l=Math.round(e*100);return o.jsxs("div",{className:"canvas-toolbar__zoom",role:"group","aria-label":r("canvas.toolbar.zoomGroup"),children:[o.jsx("button",{type:"button",className:"canvas-toolbar__zoom-button",onClick:n,"aria-label":r("canvas.toolbar.zoomOut"),title:r("canvas.toolbar.zoomOut"),children:o.jsx(ra,{})}),o.jsxs("button",{type:"button",className:"canvas-toolbar__zoom-value",onClick:a,"aria-label":r("canvas.toolbar.zoomReset"),title:r("canvas.toolbar.zoomReset"),children:[l,"%"]}),o.jsx("button",{type:"button",className:"canvas-toolbar__zoom-button",onClick:t,"aria-label":r("canvas.toolbar.zoomIn"),title:r("canvas.toolbar.zoomIn"),children:o.jsx(oa,{})})]})}function ra(){return o.jsx("svg",{className:"canvas-toolbar__icon canvas-toolbar__icon--small",viewBox:"0 0 24 24","aria-hidden":"true",children:o.jsx("path",{d:"M5 12h14"})})}function oa(){return o.jsxs("svg",{className:"canvas-toolbar__icon canvas-toolbar__icon--small",viewBox:"0 0 24 24","aria-hidden":"true",children:[o.jsx("path",{d:"M12 5v14"}),o.jsx("path",{d:"M5 12h14"})]})}function sa({zoom:e,closeLabel:t,blankCanvasLabel:n,blankCanvasAriaLabel:a,blankCanvasShortcut:r,blankCanvasBusy:l,shortcutHint:s,onZoomIn:d,onZoomOut:u,onZoomReset:i,onCreateBlankCanvas:b,onClose:f}){return o.jsxs("div",{className:"canvas-mode-topbar",children:[o.jsxs("div",{className:"canvas-mode-topbar__stack",children:[o.jsx("span",{className:"canvas-mode-topbar__label",children:"Canvas Mode"}),o.jsx(aa,{zoom:e,onZoomIn:d,onZoomOut:u,onZoomReset:i}),o.jsx("span",{className:"canvas-mode-topbar__shortcuts",children:s})]}),o.jsx("div",{className:"canvas-mode-topbar__center",children:o.jsxs("button",{type:"button",className:"canvas-mode-blank",onClick:b,disabled:l,"aria-label":a,title:a,children:[o.jsx("span",{"aria-hidden":"true",children:"+"}),o.jsx("span",{children:n}),o.jsx("kbd",{children:r})]})}),o.jsxs("button",{type:"button",className:"canvas-mode-close",onClick:f,"aria-label":t,children:[o.jsx("kbd",{children:"ESC"}),o.jsx("span",{children:t})]})]})}function Je(e,t,n){return Math.max(t,Math.min(n,e))}function la({zoom:e,panX:t,panY:n}){const a=Je(100/Math.max(1,e),18,100),r=a/2,l=Je(50-t/40,r,100-r),s=Je(50-n/40,r,100-r);return{width:`${a}%`,height:`${a}%`,left:`${l}%`,top:`${s}%`}}function ca({imageSrc:e,zoom:t,panX:n,panY:a,resetLabel:r,onReset:l}){return o.jsxs("button",{type:"button",className:"canvas-viewport-minimap",onClick:l,"aria-label":r,title:r,children:[o.jsx("img",{src:e,alt:"","aria-hidden":"true"}),o.jsx("span",{className:"canvas-viewport-minimap__window",style:la({zoom:t,panX:n,panY:a}),"aria-hidden":"true"})]})}const ia=`url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='28' height='28' viewBox='0 0 28 28'%3E%3Ccircle cx='14' cy='14' r='8' fill='white' fill-opacity='0.16' stroke='black' stroke-width='3'/%3E%3Ccircle cx='14' cy='14' r='8' fill='none' stroke='white' stroke-width='1.5'/%3E%3Ccircle cx='14' cy='14' r='2' fill='white' stroke='black' stroke-width='1'/%3E%3C/svg%3E") 14 14, auto`,ua=`url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='28' height='28' viewBox='0 0 28 28'%3E%3Ccircle cx='14' cy='14' r='8' fill='white' fill-opacity='0.18' stroke='black' stroke-width='3'/%3E%3Ccircle cx='14' cy='14' r='8' fill='none' stroke='white' stroke-width='1.5'/%3E%3C/svg%3E") 14 14, auto`;function da(e){return e==="low"?"l":e==="medium"?"m":e==="high"?"h":e??null}function ha(e){if(!e)return null;const t=e.match(/^(\d+)x\1$/);return t?`${t[1]}²`:e.replace("x","×")}function fa(e){const t=e.url??e.image;if(!e.canvasVersion||!e.canvasMergedAt||t.startsWith("data:"))return t;const n=t.includes("?")?"&":"?";return`${t}${n}canvasMergedAt=${e.canvasMergedAt}`}function ct(e,t){return!e.canvasVersion||e.prompt||!t?.prompt?e:{...e,prompt:t.prompt}}function pa(e,t){if(!t?.filename)return null;const n=e.find(a=>a.canvasVersion&&(a.canvasSourceFilename===t.filename||a.canvasEditableFilename===t.filename))??null;return n?ct(n,t):null}function ma(e,t){if(sn(e)){const n=e.images[0];if(!n)throw new Error("edit_empty_response");return{...n,prompt:t,reasoningEffort:e.reasoningEffort,provider:e.provider,quality:e.quality,size:e.size,moderation:e.moderation,model:e.model,usage:e.usage,kind:"edit",createdAt:Date.now()}}return{image:e.image,url:e.filename?`/generated/${e.filename}`:e.image,thumb:e.image,filename:e.filename,prompt:t,elapsed:e.elapsed,reasoningEffort:e.reasoningEffort,provider:e.provider,quality:e.quality,size:e.size,moderation:e.moderation,model:e.model,usage:e.usage,revisedPrompt:e.revisedPrompt??null,promptMode:e.promptMode??null,kind:"edit",createdAt:Date.now()}}const Qe=new WeakMap;function va(e){if(!e.complete||!e.naturalWidth||!e.naturalHeight)return!1;const t=Qe.get(e);if(t&&t.src===e.currentSrc&&t.width===e.naturalWidth&&t.height===e.naturalHeight)return t.result;const n=64,a=Math.min(n,e.naturalWidth),r=Math.min(n,e.naturalHeight),l=document.createElement("canvas");l.width=a,l.height=r;const s=l.getContext("2d",{willReadFrequently:!0});if(!s)return!1;try{s.drawImage(e,0,0,a,r);const d=s.getImageData(0,0,a,r).data;for(let u=3;u<d.length;u+=4)if(d[u]<250)return Qe.set(e,{src:e.currentSrc,width:e.naturalWidth,height:e.naturalHeight,result:!0}),!0;return Qe.set(e,{src:e.currentSrc,width:e.naturalWidth,height:e.naturalHeight,result:!1}),!1}catch{return!1}}function ba(e,t){if(e.width!==t.width||e.height!==t.height||e.data.length!==t.data.length)throw new Error("cleanup_mask_size_mismatch")}function xt(e,t){return{width:e,height:t,data:new Uint8Array(e*t)}}function rt(e){return{width:e.width,height:e.height,data:new Uint8Array(e.data)}}function ga(e,t){ba(e,t);for(let n=0;n<e.data.length;n+=1)(t.data[n]??0)>0&&(e.data[n]=0)}function Be(e,t){if(!e)return null;const n=rt(e);return t&&ga(n,t),n}function xa(e,t){if(e.width!==t.width||e.height!==t.height)throw new Error("cleanup_mask_size_mismatch");const n=new ImageData(new Uint8ClampedArray(e.data),e.width,e.height);for(let a=0;a<t.data.length;a+=1)(t.data[a]??0)>0&&(n.data[a*4+3]=0);return n}function Re(e){return Math.min(1,Math.max(0,e))}function ya(e){return new Promise((t,n)=>{e.toBlob(a=>{a?t(a):n(new Error("mask_blob_unavailable"))},"image/png")})}async function ka(e){const t=e.imageElement.naturalWidth,n=e.imageElement.naturalHeight;if(!t||!n)throw new Error("mask_source_size_unavailable");if(e.boxes.length===0)throw new Error("mask_boxes_required");const a=document.createElement("canvas");a.width=t,a.height=n;const r=a.getContext("2d");if(!r)throw new Error("mask_context_unavailable");r.fillStyle="rgba(0, 0, 0, 1)",r.fillRect(0,0,t,n),r.globalCompositeOperation="destination-out";for(const l of e.boxes){const s=Re(l.x)*t,d=Re(l.y)*n,u=Re(l.width)*t,i=Re(l.height)*n;u>0&&i>0&&r.fillRect(s,d,u,i)}return ya(a)}async function Ca(e){const t=e.naturalWidth,n=e.naturalHeight;if(!t||!n)throw new Error("image_source_size_unavailable");const a=document.createElement("canvas");a.width=t,a.height=n;const r=a.getContext("2d");if(!r)throw new Error("image_context_unavailable");return r.drawImage(e,0,0,t,n),a.toDataURL("image/png")}function it(e){return new Promise((t,n)=>{const a=new FileReader;a.onerror=()=>n(new Error("mask_blob_read_failed")),a.onload=()=>t(String(a.result)),a.readAsDataURL(e)})}const ut=[{x:0,y:0},{x:1,y:0},{x:0,y:1},{x:1,y:1}],wa=1024;function _a(e){return Math.max(0,Math.min(255,Math.round(e)))}function Nt(e,t,n){const a=Math.max(0,Math.min(t-1,Math.round(e.x*(t-1))));return Math.max(0,Math.min(n-1,Math.round(e.y*(n-1))))*t+a}function Ma(e,t){return(t.length>0?t:ut).map(a=>{const r=Nt(a,e.width,e.height)*4;return{r:e.data[r]??0,g:e.data[r+1]??0,b:e.data[r+2]??0}})}function Ea(e,t,n,a){for(const r of n)if(Math.max(Math.abs((e[t]??0)-r.r),Math.abs((e[t+1]??0)-r.g),Math.abs((e[t+2]??0)-r.b))<=a)return!0;return!1}function je(e,t,n,a,r,l,s){if(e<0||e>=a.length||a[e])return r;const d=e*4;return(t.data[d+3]??0)===0?(a[e]=1,r):Ea(t.data,d,l,s)?(a[e]=1,n[r]=e,r+1):r}function et(){return ut.map(e=>({...e}))}function yt(e,t,n,a){if(e.width!==t.width||e.height!==t.height)throw new Error("cleanup_mask_size_mismatch");const{width:r,height:l}=t,s=r*l,d=new Uint8Array(s),u=new Int32Array(s),i=Ma(t,n),b=_a(a);let f=0;for(const _ of n.length>0?n:ut)f=je(Nt(_,r,l),t,u,d,f,i,b);for(;f>0;){const _=u[--f];e.data[_]=255;const B=_%r;B>0&&(f=je(_-1,t,u,d,f,i,b)),B<r-1&&(f=je(_+1,t,u,d,f,i,b)),_>=r&&(f=je(_-r,t,u,d,f,i,b)),_<s-r&&(f=je(_+r,t,u,d,f,i,b))}}function Sa(e,t){const n=new ImageData(new Uint8ClampedArray(e.data),e.width,e.height),a=xa(n,t),r=t.data.reduce((l,s)=>l+(s>0?1:0),0);return{imageData:{width:e.width,height:e.height,data:a.data},stats:{width:e.width,height:e.height,removedPixels:r,removedPercent:t.data.length>0?r/t.data.length:0}}}function Rt(e){return new Promise((t,n)=>{e.toBlob(a=>{a?t(a):n(new Error("background_cleanup_blob_failed"))},"image/png")})}function Lt(e,t){const n=e.naturalWidth,a=e.naturalHeight;if(n<=0||a<=0)throw new Error("background_cleanup_image_not_ready");const r=t&&t>0?Math.min(1,t/Math.max(n,a)):1,l=Math.max(1,Math.round(n*r)),s=Math.max(1,Math.round(a*r)),d=document.createElement("canvas");d.width=l,d.height=s;const u=d.getContext("2d",{willReadFrequently:!0});if(!u)throw new Error("background_cleanup_context_failed");return u.drawImage(e,0,0,l,s),{canvas:d,context:u,width:l,height:s}}async function kt({imageElement:e,mask:t}){try{const{canvas:n,context:a,width:r,height:l}=Lt(e),s=a.getImageData(0,0,r,l),d=Sa({width:r,height:l,data:s.data},t),u=a.createImageData(r,l);u.data.set(d.imageData.data),a.putImageData(u,0,0);const i=await Rt(n);return{blob:i,dataUrl:await it(i),stats:d.stats}}catch(n){throw n instanceof Error?n:new Error("background_cleanup_failed")}}async function Ba({imageElement:e,mask:t}){try{const{width:n,height:a}=Lt(e,wa),r=document.createElement("canvas");r.width=n,r.height=a;const l=r.getContext("2d");if(!l)throw new Error("background_cleanup_context_failed");const s=l.createImageData(n,a);let d=0;for(let i=0;i<a;i+=1)for(let b=0;b<n;b+=1){const f=Math.min(t.width-1,Math.floor(b/n*t.width)),_=Math.min(t.height-1,Math.floor(i/a*t.height));if((t.data[_*t.width+f]??0)===0)continue;const B=(i*n+b)*4;s.data[B]=168,s.data[B+1]=85,s.data[B+2]=247,s.data[B+3]=150,d+=1}l.putImageData(s,0,0);const u=await Rt(r);return{dataUrl:await it(u),stats:{width:t.width,height:t.height,removedPixels:t.data.reduce((i,b)=>i+(b>0?1:0),0),removedPercent:t.data.length>0?d/(n*a):0}}}catch(n){throw n instanceof Error?n:new Error("background_cleanup_failed")}}function Ct(e){return{...e,seeds:e.seeds.map(t=>({intent:t.intent,point:{...t.point}})),brushStrokes:e.brushStrokes.map(t=>({...t,points:t.points.map(n=>({...n}))})),brushCursor:e.brushCursor?{...e.brushCursor}:null,removeMask:e.removeMask?rt(e.removeMask):null,preserveMask:e.preserveMask?rt(e.preserveMask):null}}function ja(){return`cleanup_${Date.now().toString(36)}_${Math.random().toString(36).slice(2,8)}`}function Le(e){return Math.max(0,Math.min(1,e))}function Ta(e){const t=[],n=Math.max(0,e.radius*.55);for(const a of e.points)t.push({...a}),!(n<=0)&&t.push({x:Le(a.x-n),y:a.y},{x:Le(a.x+n),y:a.y},{x:a.x,y:Le(a.y-n)},{x:a.x,y:Le(a.y+n)});return t}function Pa(e){const t=e.naturalWidth,n=e.naturalHeight;if(t<=0||n<=0)throw new Error("background_cleanup_image_not_ready");const a=document.createElement("canvas");a.width=t,a.height=n;const r=a.getContext("2d",{willReadFrequently:!0});if(!r)throw new Error("background_cleanup_context_failed");r.drawImage(e,0,0,t,n);const l=r.getImageData(0,0,t,n);return{width:t,height:n,data:l.data}}function Da({canvasOpen:e,currentImage:t,canvasDisplayImage:n,imageElementRef:a,canvasSourceImageRef:r,lastMergedDataUrlRef:l,setCanvasSaveState:s,setCanvasVersionItem:d,applyMergedCanvasImage:u,attachCanvasVersionReference:i,showToast:b,t:f}){const[_,B]=c.useState(!1),[A,O]=c.useState("remove"),[T,N]=c.useState("click"),[p,C]=c.useState("flat-flood-fill"),[M,y]=c.useState([]),[v,X]=c.useState([]),[R,$]=c.useState(28),[x,E]=c.useState(null),[S,P]=c.useState(null),[Y,ne]=c.useState(null),[ae,re]=c.useState(!1),[le,I]=c.useState(.018),[F,g]=c.useState(null),[D,J]=c.useState(!1),[de,ce]=c.useState(!1),G=c.useRef(null),Q=c.useRef(null),Z=c.useRef(null),K=c.useRef({past:[],future:[]}),k=c.useRef(0),H=c.useRef(null),ee=c.useCallback(()=>Ct({intent:A,tool:T,engine:p,seeds:M,brushStrokes:v,brushRadius:le,tolerance:R,removeMask:G.current,preserveMask:Q.current,preview:x,maskOverlay:S,stats:Y,active:ae,brushCursor:F}),[v,S,x,M,Y,R,F,le,p,A,T,ae]),U=c.useCallback(()=>{K.current={past:[...K.current.past.slice(-19),ee()],future:[]}},[ee]),te=c.useCallback(w=>{const m=Ct(w);G.current=m.removeMask,Q.current=m.preserveMask,Z.current=null,O(m.intent),N(m.tool),C(m.engine),y(m.seeds),X(m.brushStrokes),I(m.brushRadius),$(m.tolerance),E(m.preview),P(m.maskOverlay),ne(m.stats),re(m.active),g(m.brushCursor),J(!1),ce(!1)},[]),z=c.useCallback(async()=>{if(!a.current||!t)return;const w=Be(G.current,Q.current);if(!w){P(null),ne(null);return}const m=k.current+1;k.current=m,J(!0);try{const L=await Ba({imageElement:a.current,mask:w});if(k.current!==m)return;P(L),ne(L.stats)}catch{if(k.current!==m)return;b(f("canvas.toolbar.cleanupFailed"),!0)}finally{k.current===m&&J(!1)}},[t,a,b,f]),V=c.useCallback(async(w,m,L)=>{if(!a.current)return;const q=Pa(a.current),ie=xt(q.width,q.height),Ce=xt(q.width,q.height);for(const be of w){const _e=be.intent==="remove"?ie:Ce;yt(_e,q,[be.point],L)}for(const be of m){const _e=be.intent==="remove"?ie:Ce;yt(_e,q,Ta(be),L)}G.current=ie,Q.current=Ce},[a]),he=c.useCallback(()=>{k.current+=1,H.current!=null&&(window.clearTimeout(H.current),H.current=null),G.current=null,Q.current=null,Z.current=null,K.current={past:[],future:[]},y([]),X([]),E(null),P(null),ne(null),re(!1),g(null),J(!1),ce(!1)},[]),oe=c.useCallback(()=>{const w=K.current.past.pop();return w?(K.current.future=[ee(),...K.current.future.slice(0,19)],te(w),!0):!1},[ee,te]),we=c.useCallback(()=>{const w=K.current.future.shift();return w?(K.current.past=[...K.current.past.slice(-19),ee()],te(w),!0):!1},[ee,te]),De=c.useCallback(w=>{U();const m=[...M,{point:w,intent:A}];y(m),E(null),V(m,v,R).then(z)},[v,M,R,A,U,V,z]),$e=c.useCallback(()=>{U();const w=et().map(m=>({point:m,intent:"remove"}));y(w),E(null),re(!1),V(w,v,R).then(z)},[v,R,U,V,z]),Ue=c.useCallback(()=>{U(),N("click"),re(w=>!w)},[U]),W=c.useCallback(w=>{U(),H.current!=null&&window.clearTimeout(H.current),$(w),E(null),H.current=window.setTimeout(()=>{H.current=null,V(M,v,w).then(z)},180)},[v,M,U,V,z]),We=c.useCallback(async()=>{if(!a.current||!t)return null;let w=Be(G.current,Q.current);if(!w){const L=et().map(q=>({point:q,intent:"remove"}));y(L),await V(L,v,R),w=Be(G.current,Q.current)}if(!w)return null;U();const m=k.current+1;k.current=m,J(!0);try{const L=await kt({imageElement:a.current,mask:w});return k.current!==m?null:(E(L),P(null),ne(L.stats),L)}catch{return k.current!==m||b(f("canvas.toolbar.cleanupFailed"),!0),null}finally{k.current===m&&J(!1)}},[v,R,t,a,U,V,b,f]),He=c.useCallback(()=>{U(),he()},[U,he]),Fe=c.useCallback(w=>{U();const m={id:ja(),intent:A,points:[{...w}],radius:le};Z.current=m,g(w),X(L=>[...L,m])},[le,A,U]),Ve=c.useCallback(w=>{const m=Z.current;if(!m){g(w);return}m.points=[...m.points,{...w}],g(w),X(L=>L.map(q=>q.id===m.id?{...m,points:m.points.map(ie=>({...ie}))}:q)),V(M,v.map(L=>L.id===m.id?m:L),R).then(z)},[v,M,R,V,z]),ve=c.useCallback(()=>{Z.current=null,V(M,v,R).then(z)},[v,M,R,V,z]),fe=c.useCallback(async()=>{if(!t||!a.current)return;const w=r.current??t;if(!w?.filename){b(f("canvas.toolbar.cleanupFailed"),!0);return}let m=Be(G.current,Q.current);if(!m){const L=et().map(q=>({point:q,intent:"remove"}));y(L),await V(L,v,R),m=Be(G.current,Q.current)}if(m){ce(!0),s("saving");try{U();const L=await kt({imageElement:a.current,mask:m}),q=await St({sourceFilename:w.canvasSourceFilename??w.filename,image:L.blob,prompt:w.prompt}),ie=ct(q.item,w);l.current=L.dataUrl,d(ie),u(ie),await i(ie),s("saved"),E(null),P(null),ne(L.stats),re(!1),b(f("canvas.toolbar.cleanupApplied"))}catch{s("error"),b(f("canvas.toolbar.cleanupFailed"),!0)}finally{ce(!1)}}},[u,i,v,R,r,t,a,l,U,V,s,d,b,f]),ue=c.useCallback(()=>ae?(Z.current=null,re(!1),g(null),!0):!1,[ae]);return c.useEffect(()=>{const w=a.current;if(!w||!e){B(!1);return}const m=()=>B(va(w));if(w.complete)m();else return w.addEventListener("load",m),()=>w.removeEventListener("load",m)},[e,n?.canvasMergedAt,n?.filename,n?.image,n?.url,x?.dataUrl,a]),{imageHasAlpha:_,backgroundCleanupSeeds:M,backgroundCleanupBrushStrokes:v,backgroundCleanupTolerance:R,backgroundCleanupPreview:x,backgroundCleanupMaskOverlay:S,backgroundCleanupStats:Y,cleanupIntent:A,setCleanupIntent:O,cleanupTool:T,setCleanupTool:N,cleanupClickEngine:p,setCleanupClickEngine:C,cleanupBrushRadius:le,setCleanupBrushRadius:I,cleanupBrushCursor:F,setCleanupBrushCursor:g,isBackgroundCleanupActive:ae,setIsBackgroundCleanupActive:re,isBackgroundCleanupPickingSeed:ae&&T==="click",isBackgroundCleanupPreviewing:D,isBackgroundCleanupApplying:de,hasActiveCleanupStroke:!!Z.current,canUndoBackgroundCleanup:K.current.past.length>0,canRedoBackgroundCleanup:K.current.future.length>0,resetBackgroundCleanup:he,undoBackgroundCleanup:oe,redoBackgroundCleanup:we,addBackgroundCleanupClick:De,addBackgroundCleanupSeed:De,runBackgroundCleanupPreview:We,handleBackgroundCleanupAutoSample:$e,handleBackgroundCleanupPickSeed:Ue,handleBackgroundCleanupToleranceChange:W,handleBackgroundCleanupReset:He,handleBackgroundCleanupApply:fe,handleBackgroundCleanupEscape:ue,startBackgroundCleanupBrushStroke:Fe,updateBackgroundCleanupBrushStroke:Ve,endBackgroundCleanupBrushStroke:ve}}function wt(e){return Math.min(1,Math.max(0,e))}function _t(e,t){const n=t.getBoundingClientRect();return{x:wt((e.clientX-n.left)/n.width),y:wt((e.clientY-n.top)/n.height)}}const Aa=.18,Ia=.12;function Na(e){return{id:"selection-box",x:Math.min(e.start.x,e.current.x),y:Math.min(e.start.y,e.current.y),width:Math.abs(e.current.x-e.start.x),height:Math.abs(e.current.y-e.start.y),color:"#64c8ff",strokeWidth:2}}function ot(e,t,n=0){return e.x>=t.x-n&&e.x<=t.x+t.width+n&&e.y>=t.y-n&&e.y<=t.y+t.height+n}function Ot(e){return{id:e.id,x:e.x,y:e.y,width:Aa,height:Ia,color:e.color,strokeWidth:1}}function Ra(e,t,n){const a=n.x-t.x,r=n.y-t.y,l=e.x-t.x,s=e.y-t.y,d=a*a+r*r;if(d===0)return Math.hypot(e.x-t.x,e.y-t.y);const u=Math.max(0,Math.min(1,(l*a+s*r)/d));return Math.hypot(e.x-(t.x+u*a),e.y-(t.y+u*r))}function La(e,t,n){for(let a=1;a<t.points.length;a+=1)if(Ra(e,t.points[a-1],t.points[a])<=n)return!0;return!1}function Mt(e,t){return e.x<=t.x+t.width&&e.x+e.width>=t.x&&e.y<=t.y+t.height&&e.y+e.height>=t.y}function Oa(e,t){return e.points.some(n=>ot(n,t))}function Et(e){const t=e.tolerance??.015;for(const n of[...e.memos].reverse())if(ot(e.point,Ot(n),t))return Pt(n);for(const n of[...e.boxes].reverse())if(ot(e.point,n,t))return Tt(n);for(const n of[...e.paths].reverse())if(La(e.point,n,t))return jt(n);return null}function $a(e){const t=[];for(const n of e.annotations.paths)Oa(n,e.box)&&t.push(jt(n));for(const n of e.annotations.boxes)Mt(n,e.box)&&t.push(Tt(n));for(const n of e.annotations.memos)Mt(Ot(n),e.box)&&t.push(Pt(n));return t}function Ua({canvasOpen:e,canvasZoom:t,canvasPanX:n,canvasPanY:a,spaceHeld:r,canDragViewportWithSelect:l,isBackgroundCleanupActive:s,cleanupTool:d,annotationFrameRef:u,annotations:i,setCanvasPan:b,addBackgroundCleanupClick:f,startBackgroundCleanupBrushStroke:_,updateBackgroundCleanupBrushStroke:B,endBackgroundCleanupBrushStroke:A,setCleanupBrushCursor:O}){const T=c.useRef({mode:null,lastPoint:null,didMove:!1}),N=c.useRef({active:!1,startX:0,startY:0,basePanX:0,basePanY:0,pointerId:null}),[p,C]=c.useState(!1),M=x=>{x.currentTarget.setPointerCapture(x.pointerId),N.current={active:!0,startX:x.clientX,startY:x.clientY,basePanX:n,basePanY:a,pointerId:x.pointerId},C(!0)};return{viewportPanActive:p,resetPointerSession:()=>{T.current={mode:null,lastPoint:null,didMove:!1},N.current={active:!1,startX:0,startY:0,basePanX:0,basePanY:0,pointerId:null},C(!1)},handleAnnotationPointerDown:x=>{if(!e||me(x.target)||!u.current)return;const E=x.button===1;if(r||E){x.preventDefault(),M(x);return}x.preventDefault();const S=_t(x,u.current);if(s){d==="click"?f(S):(x.currentTarget.setPointerCapture(x.pointerId),_(S));return}if(i.activeTool==="select"){const P=Et({point:S,paths:i.paths,boxes:i.boxes,memos:i.memos});if(P)x.shiftKey?i.toggleSelected(P):i.selectOne(P),i.startSelectedMove(),T.current={mode:"move",lastPoint:S,didMove:!1};else if(l&&t>1.01){M(x);return}else i.clearSelection(),i.startSelectionBox(S),T.current={mode:"box",lastPoint:S,didMove:!1};x.currentTarget.setPointerCapture(x.pointerId);return}if(i.activeTool==="memo"){i.createMemo(S),requestAnimationFrame(()=>{u.current?.querySelector(".canvas-memo--active")?.focus()});return}if(i.activeTool==="eraser"){if(i.eraserMode==="object"){const P=Et({point:S,paths:i.paths,boxes:i.boxes,memos:i.memos});P&&i.eraseObjectAtPoint(P);return}x.currentTarget.setPointerCapture(x.pointerId),i.startEraserStroke(S);return}x.currentTarget.setPointerCapture(x.pointerId),i.startDrawing(S)},handleAnnotationPointerMove:x=>{if(!e||me(x.target)||!u.current)return;if(N.current.active){const S=x.clientX-N.current.startX,P=x.clientY-N.current.startY;b(N.current.basePanX+S,N.current.basePanY+P);return}const E=_t(x,u.current);if(s){d==="brush"?B(E):O(E);return}if(i.activeTool==="select"){if(T.current.mode==="move"&&T.current.lastPoint){const S={x:E.x-T.current.lastPoint.x,y:E.y-T.current.lastPoint.y};(Math.abs(S.x)>5e-4||Math.abs(S.y)>5e-4)&&(i.moveSelected(S),T.current.didMove=!0),T.current.lastPoint=E}else T.current.mode==="box"&&i.updateSelectionBox(E);return}if(i.activeTool!=="memo"){if(i.activeTool==="eraser"){i.eraserMode==="brush"&&i.updateEraserStroke(E);return}i.moveDrawing(E)}},handleAnnotationPointerUp:x=>{if(e&&!me(x.target)){if(N.current.active&&N.current.pointerId===x.pointerId){x.currentTarget.hasPointerCapture(x.pointerId)&&x.currentTarget.releasePointerCapture(x.pointerId),N.current={active:!1,startX:0,startY:0,basePanX:0,basePanY:0,pointerId:null},C(!1);return}if(x.currentTarget.hasPointerCapture(x.pointerId)&&x.currentTarget.releasePointerCapture(x.pointerId),s){d==="brush"&&A();return}if(i.activeTool==="select"){T.current.mode==="move"&&T.current.didMove&&i.commitSelectedMove(),T.current.mode==="box"&&i.selectionBox&&i.endSelectionBox($a({box:Na(i.selectionBox),annotations:i.toPayload()})),T.current={mode:null,lastPoint:null,didMove:!1};return}if(i.activeTool!=="memo"){if(i.activeTool==="eraser"){i.eraserMode==="brush"&&i.endEraserStroke();return}i.endDrawing()}}},handleAnnotationPointerLeave:()=>{s&&O(null)}}}function Wa({canvasOpen:e,canvasZoom:t,currentImage:n,annotations:a,undoBackgroundCleanup:r,redoBackgroundCleanup:l,handleBackgroundCleanupEscape:s,handleCloseCanvas:d,selectHistoryShortcutTarget:u,trashHistoryItem:i,permanentlyDeleteHistoryItemByShortcut:b,setCanvasZoom:f,resetCanvasZoom:_,onCreateBlankCanvas:B,isCreatingBlankCanvas:A}){const[O,T]=c.useState(!1);return c.useEffect(()=>{if(!e)return;const p=v=>{v.preventDefault()},C=v=>{v.ctrlKey&&v.preventDefault()},M={passive:!1,capture:!0},y={passive:!1};return window.addEventListener("wheel",C,M),window.addEventListener("gesturestart",p,y),window.addEventListener("gesturechange",p,y),window.addEventListener("gestureend",p,y),()=>{window.removeEventListener("wheel",C,M),window.removeEventListener("gesturestart",p,y),window.removeEventListener("gesturechange",p,y),window.removeEventListener("gestureend",p,y)}},[e]),c.useEffect(()=>{if(!e)return;const p=M=>{M.code==="Space"&&(me(M.target)||(O||T(!0),M.preventDefault()))},C=M=>{M.code==="Space"&&T(!1)};return window.addEventListener("keydown",p),window.addEventListener("keyup",C),()=>{window.removeEventListener("keydown",p),window.removeEventListener("keyup",C)}},[e,O]),c.useEffect(()=>{if(!e)return;const p=C=>{if(!C.defaultPrevented){if(me(C.target)){C.key==="Escape"&&(C.preventDefault(),C.target.blur(),a.focusMemo(null));return}if(C.key==="Escape"){if(C.preventDefault(),s())return;d();return}if(C.shiftKey&&!C.metaKey&&!C.ctrlKey&&!C.altKey&&C.key.toLowerCase()==="b"){C.preventDefault(),!A&&!C.repeat&&B();return}if((C.metaKey||C.ctrlKey)&&C.key.toLowerCase()==="z"){if(C.preventDefault(),C.shiftKey){if(l())return;a.redo();return}if(r())return;a.undo()}}};return window.addEventListener("keydown",p),()=>window.removeEventListener("keydown",p)},[a,a.focusMemo,a.redo,a.undo,e,d,s,A,B,l,r]),{spaceHeld:O,handleViewerKeyDown:p=>{if(me(p.target)){p.key==="Escape"&&(p.preventDefault(),p.target.blur(),a.focusMemo(null));return}if(e&&["1","2","3","4","5","6"].includes(p.key)){p.preventDefault();const C=["select","pen","box","arrow","memo","eraser"];a.setTool(C[Number(p.key)-1]);return}if(e&&p.key==="Escape"){if(p.preventDefault(),p.stopPropagation(),s())return;d();return}if(e&&p.key==="]"){p.preventDefault(),f(t+.1);return}if(e&&p.key==="["){p.preventDefault(),f(t-.1);return}if(e&&p.key==="0"){p.preventDefault(),_();return}if(p.key==="Delete"||p.key==="Backspace"){if(!n||p.target!==p.currentTarget)return;if(p.preventDefault(),p.shiftKey){b(n);return}i(n);return}p.key!=="ArrowLeft"&&p.key!=="ArrowRight"&&p.key!=="Home"&&p.key!=="End"||p.target===p.currentTarget&&(me(p.target)||(p.preventDefault(),p.key==="ArrowLeft"?u("previous"):p.key==="ArrowRight"?u("next"):p.key==="Home"?u("first"):p.key==="End"&&u("last")))}}}function Ha(e,t){return new Promise((n,a)=>{e.toBlob(r=>{if(r){n(r);return}a(new Error("canvas_blob_unavailable"))},t)})}async function $t(e){const t=document.createElement("canvas");t.width=e.imageElement.naturalWidth,t.height=e.imageElement.naturalHeight;const n=t.getContext("2d");if(!n)throw new Error("canvas_context_unavailable");e.background?.mode==="matte"&&(n.fillStyle=e.background.color,n.fillRect(0,0,t.width,t.height)),n.drawImage(e.imageElement,0,0,t.width,t.height);const a={width:t.width,height:t.height};for(const l of e.paths)nt(n,l,a);for(const l of e.boxes)at(n,l,a,"committed");for(const l of e.memos)En(n,l,a);return{blob:await Ha(t,"image/png"),dataUrl:t.toDataURL("image/png")}}async function Fa(e){return(await $t(e)).blob}function Va(e={},t=new Date){const n=t.toISOString().slice(0,19).replace(/[-:T]/g,""),a=e.matte?"-flat":"";return`canvas-export-${n}${a}.png`}function Ka(e,t){const n=URL.createObjectURL(e);try{const a=document.createElement("a");a.href=n,a.download=t,a.click()}finally{URL.revokeObjectURL(n)}}function za({imageElementRef:e,currentImage:t,canvasDisplayImage:n,canvasSourceImageRef:a,lastMergedDataUrlRef:r,canvasVersionItem:l,annotations:s,exportBackground:d,exportMatteColor:u,quality:i,format:b,moderation:f,provider:_,imageModel:B,reasoningEffort:A,promptMode:O,webSearchEnabled:T,getResolvedSize:N,setCanvasVersionItem:p,setCanvasSaveState:C,setIsApplying:M,setIsExporting:y,setIsEditingWithMask:v,applyMergedCanvasImage:X,addGeneratedHistoryItem:R,attachCanvasVersionReference:$,closeCanvas:x,resetCanvasSession:E,showToast:S,t:P}){const Y=c.useCallback(async()=>{if(!e.current||!t)return null;const I=a.current??t;if(!I?.filename)return S(P("canvas.version.failed"),!0),null;M(!0),C("saving");try{const F=await $t({imageElement:e.current,paths:s.paths,boxes:s.boxes,memos:s.memos});r.current=F.dataUrl;const g=l?.filename?await ln(l.filename,{image:F.blob,sourceFilename:I.canvasSourceFilename??I.filename,prompt:I.prompt}):await St({sourceFilename:I.filename,image:F.blob,prompt:I.prompt}),D=ct(g.item,I);return p(D),X(D),await $(D),await Bt(I.filename).catch(()=>{}),s.resetLocal(),s.markSaved(),C("saved"),S(P("canvas.version.saved")),D}catch{return C("error"),S(P("canvas.version.failed"),!0),null}finally{M(!1)}},[s,X,$,a,l?.filename,t,e,r,C,p,M,S,P]);return{saveCanvasVersionAndUseReference:Y,handleApplyCanvas:async()=>{await Y()},handleCloseCanvas:async()=>{(s.hasAnnotations||s.isDirty)&&!await Y()||(x(),E())},handleExportCanvas:async()=>{if(!(!e.current||!t)){y(!0);try{const I=d==="matte",F=await Fa({imageElement:e.current,paths:s.paths,boxes:s.boxes,memos:s.memos,background:I?{mode:"matte",color:u}:{mode:"alpha"}});Ka(F,Va({matte:I}))}catch{S(P("canvas.toolbar.exportFailed"),!0)}finally{y(!1)}}},handleEditWithMask:async()=>{if(!(!e.current||!n||s.boxes.length===0)){v(!0);try{let I=r.current;if(s.isDirty||s.hasAnnotations){if(!await Y())return;I=r.current}I||(I=await Ca(e.current));const F=s.boxes.filter(de=>s.selectedIds.some(ce=>pe(ce,"box",de.id))),g=await ka({imageElement:e.current,boxes:F.length>0?F:s.boxes}),D=n.prompt??t?.prompt??"";if(!D.trim()){S(P("toast.noPromptToFork"),!0);return}const J=await cn({image:I,mask:await it(g),prompt:D,quality:i,size:n.size??t?.size??N(),format:b,moderation:f,provider:_,n:1,model:B,reasoningEffort:A,mode:O,webSearchEnabled:T});await R(ma(J,D))}catch(I){const F=I.code;S(P(F==="EDIT_MASK_NOT_SUPPORTED"?"canvas.toolbar.editMaskUnsupported":"canvas.toolbar.editMaskFailed"),!0)}finally{v(!1)}}}}}function qa(e){const t=j(h=>h.currentImage),n=j(h=>h.history),a=j(h=>h.importLocalImageToHistory),[r,l]=c.useState(!1),s=j(h=>{const se=h.multimodePreviewFlightId;return se?h.multimodeSequences[se]??null:null}),d=j(h=>h.selectHistoryShortcutTarget),u=j(h=>h.trashHistoryItem),i=j(h=>h.permanentlyDeleteHistoryItemByShortcut),b=j(h=>h.markGeneratedResultsSeen),f=j(h=>h.activeGenerations),_=j(h=>h.quality),B=j(h=>h.format),A=j(h=>h.moderation),O=j(h=>h.provider),T=j(h=>h.imageModel),N=j(h=>h.reasoningEffort),p=j(h=>h.promptMode),C=j(h=>h.webSearchEnabled),M=j(h=>h.getResolvedSize),y=j(h=>h.showToast),v=j(h=>h.canvasOpen),X=j(h=>h.openCanvas),R=j(h=>h.closeCanvas),$=j(h=>h.canvasZoom),x=j(h=>h.canvasPanX),E=j(h=>h.canvasPanY),S=j(h=>h.setCanvasPan),P=j(h=>h.setCanvasZoom),Y=j(h=>h.resetCanvasZoom),ne=j(h=>h.canvasExportBackground),ae=j(h=>h.canvasExportMatteColor),re=j(h=>h.setCanvasExportBackground),le=j(h=>h.setCanvasExportMatteColor),I=j(h=>h.applyMergedCanvasImage),F=j(h=>h.addGeneratedHistoryItem),g=j(h=>h.attachCanvasVersionReference),{t:D}=ke(),{creatingBlankCanvas:J,createBlankCanvas:de}=un(),ce=c.useRef(null),G=c.useRef(null),Q=c.useRef(null),Z=c.useRef(null),K=c.useRef(null),k=c.useRef(null),H=c.useRef(null),ee=c.useRef(null),[U,te]=c.useState(null),[z,V]=c.useState("idle"),[he,oe]=c.useState(!1),[we,De]=c.useState(!1),[$e,Ue]=c.useState(!1),W=Mn(),We=()=>{t?.prompt&&(navigator.clipboard.writeText(t.prompt),y(D("toast.promptCopied")))},He=da(t?.quality??_),Fe=ha(t?.size??M()),Ve=dn(t?.model),ve=t?.filename??t?.url??t?.image??null,fe=pa(n,t),ue=v?U??fe??t:t,w=ue?fa(ue):null,m=Da({canvasOpen:v,currentImage:t,canvasDisplayImage:ue,imageElementRef:G,canvasSourceImageRef:H,lastMergedDataUrlRef:ee,setCanvasSaveState:V,setCanvasVersionItem:te,applyMergedCanvasImage:I,attachCanvasVersionReference:g,showToast:y,t:D}),{imageHasAlpha:L,backgroundCleanupSeeds:q,backgroundCleanupPreview:ie,backgroundCleanupMaskOverlay:Ce,backgroundCleanupBrushStrokes:be,cleanupTool:_e,cleanupBrushRadius:Ut,cleanupBrushCursor:Wt,isBackgroundCleanupActive:Me}=m,Ke=m.backgroundCleanupPreview?.dataUrl??w,ze=()=>{H.current=null,K.current=null,k.current!=null&&(window.clearTimeout(k.current),k.current=null),te(null),V("idle"),m.resetBackgroundCleanup(),ee.current=null,Jt()};c.useEffect(()=>{if(!v){Z.current=ve,ze();return}if(Z.current===null){Z.current=ve,H.current=t,te(fe);return}Z.current!==ve&&(W.resetLocal(),ze(),H.current=t,te(fe),Z.current=ve)},[W.resetLocal,v,t,ve,fe]),c.useEffect(()=>{!v||!t||H.current||(H.current=t,te(fe))},[v,t,fe]),c.useEffect(()=>{if(!v||!t?.filename||t.canvasVersion)return;const h=t.filename;if(K.current===h)return;K.current=h;let se=!1;return hn(h).then(Ee=>{!se&&Ee.annotations&&W.load(Ee.annotations)}).catch(()=>{}),()=>{se=!0}},[W.load,v,t?.canvasVersion,t?.filename]),c.useEffect(()=>{if(!v||!t?.filename||t.canvasVersion||!W.isDirty)return;const h=t.filename;return k.current!=null&&window.clearTimeout(k.current),k.current=window.setTimeout(()=>{const se=W.toPayload();(W.hasAnnotations?fn(h,se):Bt(h)).then(()=>W.markSaved()).catch(()=>{})},500),()=>{k.current!=null&&(window.clearTimeout(k.current),k.current=null)}},[W,W.hasAnnotations,W.isDirty,v,t?.canvasVersion,t?.filename]);const Ht=h=>{me(h.target)||(b(),h.currentTarget.focus())},Ft=c.useCallback(()=>{window.requestAnimationFrame(()=>Q.current?.focus())},[]),Vt=h=>{if(v){if(h.preventDefault(),h.ctrlKey){P($-h.deltaY*.01);return}S(x-h.deltaX,E-h.deltaY)}},Kt=c.useCallback(h=>{Array.from(h.dataTransfer.types).includes("Files")&&(h.preventDefault(),l(se=>se||!0))},[]),zt=c.useCallback(h=>{h.currentTarget.contains(h.relatedTarget)||l(!1)},[]),Xt=c.useCallback(async h=>{if(!Array.from(h.dataTransfer.types).includes("Files"))return;h.preventDefault(),l(!1);const se=Array.from(h.dataTransfer.files).filter(Ee=>/^image\/(png|jpeg|webp)$/.test(Ee.type));se.length!==0&&await a(se[0])},[a]),{handleApplyCanvas:qt,handleCloseCanvas:dt,handleExportCanvas:Yt,handleEditWithMask:Gt}=za({imageElementRef:G,currentImage:t,canvasDisplayImage:ue,canvasSourceImageRef:H,lastMergedDataUrlRef:ee,canvasVersionItem:U,annotations:W,exportBackground:ne,exportMatteColor:ae,quality:_,format:B,moderation:A,provider:O,imageModel:T,reasoningEffort:N,promptMode:p,webSearchEnabled:C,getResolvedSize:M,setCanvasVersionItem:te,setCanvasSaveState:V,setIsApplying:oe,setIsExporting:De,setIsEditingWithMask:Ue,applyMergedCanvasImage:I,addGeneratedHistoryItem:F,attachCanvasVersionReference:g,closeCanvas:R,resetCanvasSession:ze,showToast:y,t:D}),{spaceHeld:Xe,handleViewerKeyDown:Zt}=Wa({canvasOpen:v,canvasZoom:$,currentImage:t,annotations:W,undoBackgroundCleanup:m.undoBackgroundCleanup,redoBackgroundCleanup:m.redoBackgroundCleanup,handleBackgroundCleanupEscape:m.handleBackgroundCleanupEscape,handleCloseCanvas:dt,selectHistoryShortcutTarget:d,trashHistoryItem:u,permanentlyDeleteHistoryItemByShortcut:i,setCanvasZoom:P,resetCanvasZoom:Y,onCreateBlankCanvas:de,isCreatingBlankCanvas:J}),qe=v&&$>1.01&&W.activeTool==="select"&&!Me,{viewportPanActive:Ye,resetPointerSession:Jt,handleAnnotationPointerDown:Qt,handleAnnotationPointerMove:en,handleAnnotationPointerUp:tn,handleAnnotationPointerLeave:nn}=Ua({canvasOpen:v,canvasZoom:$,canvasPanX:x,canvasPanY:E,spaceHeld:Xe,canDragViewportWithSelect:qe,isBackgroundCleanupActive:Me,cleanupTool:_e,annotationFrameRef:ce,annotations:W,setCanvasPan:S,addBackgroundCleanupClick:m.addBackgroundCleanupClick,startBackgroundCleanupBrushStroke:m.startBackgroundCleanupBrushStroke,updateBackgroundCleanupBrushStroke:m.updateBackgroundCleanupBrushStroke,endBackgroundCleanupBrushStroke:m.endBackgroundCleanupBrushStroke,setCleanupBrushCursor:m.setCleanupBrushCursor});return o.jsxs("main",{className:`canvas${v?" canvas--mode-open":""}${r?" canvas--drop-active":""}${Xe?" canvas--space-held":""}${Ye?" canvas--pan-active":""}${qe?" canvas--zoom-hand":""}`,onDragOver:Kt,onDragLeave:zt,onDrop:Xt,children:[r?o.jsx("div",{className:"canvas__drop-overlay","aria-hidden":!0,children:o.jsx("span",{className:"canvas__drop-hint",children:D("canvas.drop.hint")})}):null,v&&o.jsx(sa,{zoom:$,closeLabel:D("canvas.close"),blankCanvasLabel:D("canvas.blank.title"),blankCanvasAriaLabel:`${D(J?"canvas.blank.creating":"canvas.blank.create")} (Shift+B)`,blankCanvasShortcut:"Shift+B",blankCanvasBusy:J,shortcutHint:D("canvas.toolbar.zoomShortcutHint"),onZoomIn:()=>P($+.1),onZoomOut:()=>P($-.1),onZoomReset:Y,onCreateBlankCanvas:()=>{de()},onClose:()=>{dt()}}),o.jsx("div",{className:`progress-bar${f>0?" active":""}`}),s?o.jsx(pn,{}):t?o.jsxs("div",{ref:Q,className:"result-container visible",tabIndex:0,onMouseDown:Ht,onWheel:Vt,onKeyDown:Zt,"aria-label":D("canvas.imageViewerAria"),children:[o.jsx(An,{annotationFrameRef:ce,imageElementRef:G,frameClassName:`canvas-annotation-frame${(L||ie)&&v?" canvas-annotation-frame--alpha":""}${Me&&v?" canvas-annotation-frame--cleanup-picking":""}${Ce&&v?" canvas-annotation-frame--cleanup-mask":""}`,frameStyle:{cursor:Ye?"grabbing":Xe||qe?"grab":v?Me?"crosshair":W.activeTool==="select"?"default":W.activeTool==="eraser"?W.eraserMode==="object"?ia:ua:"crosshair":"zoom-in",transform:v?`translate(${x}px, ${E}px) scale(${$})`:void 0,transition:v&&!Ye?"transform 0.2s ease":void 0},imageKey:`${ue?.filename??ue?.url??ue?.image}:${ue?.canvasMergedAt??""}`,imageSrc:Ke??t.image,fallbackImage:t.image,alt:D("canvas.resultAlt"),canvasOpen:v,maskOverlayUrl:Ce?.dataUrl??null,cleanupLayer:o.jsx(Rn,{seeds:q,brushStrokes:be,brushCursor:Wt,brushRadius:Ut,active:Me}),annotations:W,onOpenCanvas:X,onPointerDown:Qt,onPointerMove:en,onPointerUp:tn,onPointerLeave:nn}),v&&Ke?o.jsx(ca,{imageSrc:Ke,zoom:$,panX:x,panY:E,resetLabel:D("canvas.toolbar.zoomReset"),onReset:Y}):null,v&&o.jsx(ta,{annotations:W,backgroundCleanup:m,backgroundCleanupPreview:ie,canvasState:{exportBackground:ne,exportMatteColor:ae,isApplying:he,isExporting:we,isEditingWithMask:$e},actions:{handleApplyCanvas:qt,handleExportCanvas:Yt,handleEditWithMask:Gt,setExportBackground:re,setExportMatteColor:le}}),v&&z!=="idle"?o.jsx("div",{className:`canvas-save-state canvas-save-state--${z}`,children:D(z==="saving"?"canvas.version.saving":z==="saved"?"canvas.version.saved":"canvas.version.failed")}):null,o.jsx(na,{currentImage:t,canvasDisplayImage:ue,canvasOpen:v,displayQuality:He,displaySize:Fe,displayModel:Ve,onAfterDeleteFocus:Ft,onCopyPrompt:We})]}):null]})}export{qa as CanvasModeWorkspace};
|