ima2-gen 3.6.0 → 3.7.0

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.
Files changed (26) hide show
  1. package/lib/generatePipeline.js +7 -0
  2. package/package.json +2 -2
  3. package/ui/dist/.vite/manifest.json +32 -32
  4. package/ui/dist/assets/{AgentWorkspace-Bfe9PqZy.js → AgentWorkspace-DU9efUdT.js} +1 -1
  5. package/ui/dist/assets/{AssetGenWorkspace-XbViHOY0.js → AssetGenWorkspace-ldEVBldg.js} +2 -2
  6. package/ui/dist/assets/{AssetsWorkspace-HemkY-0A.js → AssetsWorkspace-D_kJ7dP_.js} +1 -1
  7. package/ui/dist/assets/{CardNewsWorkspace-Cchcm8ts.js → CardNewsWorkspace-DIhk26qD.js} +1 -1
  8. package/ui/dist/assets/GenerationRequestLogPanel-BZZJh4w_.js +1 -0
  9. package/ui/dist/assets/{HomeWorkspace-Do6VnjWR.js → HomeWorkspace-DwRS4Cim.js} +1 -1
  10. package/ui/dist/assets/{KeyingPanel-D79TCHH_.js → KeyingPanel-YkL9305F.js} +1 -1
  11. package/ui/dist/assets/{NodeCanvas-BpNgtUxt.js → NodeCanvas-CaFDJn_9.js} +1 -1
  12. package/ui/dist/assets/{PromptBuilderPanel-DHB1sU7O.js → PromptBuilderPanel-Bl5-fDQs.js} +1 -1
  13. package/ui/dist/assets/{PromptImportDialog-qD_tVhN5.js → PromptImportDialog-5RbU95_Y.js} +2 -2
  14. package/ui/dist/assets/{PromptImportDiscoverySection-51FDzoLN.js → PromptImportDiscoverySection-uhS5xI0p.js} +1 -1
  15. package/ui/dist/assets/{PromptImportFolderSection-uQNX1sJ_.js → PromptImportFolderSection-COwFVcbE.js} +1 -1
  16. package/ui/dist/assets/{PromptLibraryPanel-BngHherb.js → PromptLibraryPanel-DCtxfzy1.js} +2 -2
  17. package/ui/dist/assets/{SettingsWorkspace-dpl5CLsg.js → SettingsWorkspace-aHoTeB4-.js} +1 -1
  18. package/ui/dist/assets/{SpriteRecipeWorkspace-IpS6TVAF.js → SpriteRecipeWorkspace-B0fR6yXF.js} +1 -1
  19. package/ui/dist/assets/{index-DoM1FoZ5.js → index-Bj2sxDP3.js} +6 -6
  20. package/ui/dist/assets/index-BnMUy9kc.css +1 -0
  21. package/ui/dist/assets/{index-BA51BzWd.js → index-DBh-jt0i.js} +3 -3
  22. package/ui/dist/assets/{pptxgen.es-DlpIDw00.js → pptxgen.es-AWrWIHuf.js} +1 -1
  23. package/ui/dist/assets/{useAgentDialogFocus-BOGEpRNF.js → useAgentDialogFocus-BB6ds9jo.js} +1 -1
  24. package/ui/dist/index.html +2 -2
  25. package/ui/dist/assets/GenerationRequestLogPanel-CKw9JLH8.js +0 -1
  26. package/ui/dist/assets/index-DUxkTj-7.css +0 -1
@@ -1 +1 @@
1
- import{u as E,b as j,a as d,j as s,T as Q,X as H,m as ce,Y as ue,Z as me,_ as he,$ as fe,o as pe,a0 as ge,a1 as xe,a2 as be,a3 as ve,F as je,s as ye,p as _e,t as we,a4 as ke,a5 as Ne}from"./index-DoM1FoZ5.js";import{K as Ae,A as Se}from"./KeyingPanel-D79TCHH_.js";import"./useAgentDialogFocus-BOGEpRNF.js";function Ee({folder:e,depth:n}){const{t:r}=E(),a=j(t=>t.assetsFilters.folderId),m=j(t=>t.setAssetsFilters),g=j(t=>t.renameAssetFolder),f=j(t=>t.deleteAssetFolder),o=j(t=>t.showToast),[l,x]=d.useState(!1),[y,p]=d.useState(e.name),[b,v]=d.useState(!1),k=a===e.id;async function h(){const t=y.trim();if(!t||t===e.name){p(e.name),x(!1);return}await g(e.id,t)||o(r("assets.actionFailed"),!0),x(!1)}async function u(){if(!b){v(!0);return}await f(e.id)||o(r("assets.actionFailed"),!0),v(!1)}return s.jsxs("div",{className:"assets-folder-row",style:{"--folder-depth":n},children:[l?s.jsx("input",{className:"assets-folder-input",value:y,autoFocus:!0,"aria-label":r("assets.renameFolder"),onChange:t=>p(t.target.value),onBlur:()=>{h()},onKeyDown:t=>{t.key==="Enter"&&h(),t.key==="Escape"&&(p(e.name),x(!1))}}):s.jsx("button",{type:"button",className:`assets-folder-row__name${k?" is-active":""}`,"aria-current":k?"page":void 0,onClick:()=>m({folderId:e.id,kind:null}),children:e.name}),!l&&s.jsxs("span",{className:"assets-folder-row__actions",children:[s.jsx("button",{type:"button","aria-label":r("assets.renameFolder"),onClick:()=>x(!0),children:s.jsx(Q,{})}),s.jsx("button",{type:"button","aria-label":r(b?"assets.confirmDelete":"assets.deleteFolder"),className:b?"is-danger is-armed":"",onClick:()=>{u()},children:b?r("assets.confirmDelete"):"×"})]})]})}function Ie(){const{t:e}=E(),n=j(h=>h.assetsFolders),r=j(h=>h.assetsFilters.folderId),a=j(h=>h.assetsFilters.kind),m=j(h=>h.setAssetsFilters),g=j(h=>h.createAssetFolder),f=j(h=>h.showToast),[o,l]=d.useState(!1),[x,y]=d.useState(""),p=r===null&&a!=="element",b=r===null&&a==="element",v=d.useMemo(()=>{const h=[],u=(t,c)=>n.filter(_=>_.parentId===t).forEach(_=>{h.push({folder:_,depth:c}),u(_.id,c+1)});return u(null,0),h},[n]);async function k(){const h=x.trim();if(!h){l(!1);return}await g(h,r)||f(e("assets.actionFailed"),!0),y(""),l(!1)}return s.jsxs("aside",{className:"assets-folders","aria-label":e("assets.rootFolder"),children:[s.jsxs("div",{className:"assets-folders__heading",children:[s.jsx("span",{children:e("assets.rootFolder")}),s.jsx("button",{type:"button","aria-label":e("assets.newFolder"),onClick:()=>l(!0),children:"+"})]}),s.jsxs("div",{className:"assets-folders__rows",children:[s.jsx("button",{type:"button",className:`assets-folder-all${p?" is-active":""}`,"aria-current":p?"page":void 0,onClick:()=>m({folderId:null,kind:null}),children:e("assets.allAssets")}),s.jsxs("button",{type:"button",className:`assets-folder-all assets-folder-elements${b?" is-active":""}`,"aria-current":b?"page":void 0,onClick:()=>m({folderId:null,kind:"element"}),children:[s.jsx("span",{className:"assets-folder-elements__glyph","aria-hidden":"true",children:"@"}),e("assets.elementLibrary")]}),v.map(({folder:h,depth:u})=>s.jsx(Ee,{folder:h,depth:u},h.id)),o&&s.jsx("input",{className:"assets-folder-input assets-folder-input--new",value:x,autoFocus:!0,"aria-label":e("assets.newFolder"),placeholder:e("assets.newFolder"),onChange:h=>y(h.target.value),onBlur:()=>{x.trim()||l(!1)},onKeyDown:h=>{h.key==="Enter"&&k(),h.key==="Escape"&&(y(""),l(!1))}})]})]})}let C={status:"idle",elements:[]},P=null;const G=new Set;function R(e){C=e,G.forEach(n=>n())}function Te(e){return G.add(e),()=>G.delete(e)}function O(e=!1){return!e&&C.status==="ready"?Promise.resolve(!0):P||(R({...C,status:"loading"}),P=ce().then(n=>(R({status:"ready",elements:n}),!0)).catch(n=>(console.error("[ElementMembership] load failed",n),R({...C,status:"error"}),!1)).finally(()=>{P=null}),P)}function Ce(e){const n=[e,...C.elements.filter(r=>r.id!==e.id)];R({status:"ready",elements:n})}function X(e){R({status:"ready",elements:C.elements.filter(n=>n.id!==e)})}function Fe(e){e.stopPropagation()}function De(e){e.stopPropagation()}function Pe(e){(e.key==="Enter"||e.key===" ")&&e.stopPropagation()}async function Re(e,n){if(n){await ue(n.id),X(n.id);return}const{asset:r}=await me({result:{filePath:e.filePath??void 0},sourceAssetId:e.id,elementKind:"character",name:e.name,notes:e.notes??void 0,folderId:e.folderId,tags:[he(e.id)]});Ce(r)}function z({active:e,busy:n,label:r,onToggle:a}){return s.jsx("button",{type:"button",className:`asset-element-toggle${e?" is-active":""}`,title:r,"aria-label":r,"aria-pressed":e,"aria-busy":n||void 0,disabled:n,onPointerDown:Fe,onDoubleClick:De,onKeyDown:Pe,onClick:m=>{m.stopPropagation(),a()},children:s.jsx("span",{className:"asset-element-toggle__glyph","aria-hidden":"true",children:"@"})})}function Me({item:e}){const{t:n}=E(),r=j(v=>v.showToast),a=j(v=>v.deleteAssetItem),[m,g]=d.useState(!1),f=e.kind==="element",o=f||(e.kind==="image"||e.kind==="video")&&!!e.filePath,l=n("assets.elementLibrary"),x=d.useSyncExternalStore(Te,()=>C,()=>C),y=!f&&o?H(x.elements,e.id):null,p=m||x.status==="loading"||x.status==="idle";if(d.useEffect(()=>{o&&!f&&O()},[o,f]),f){const v=async()=>{if(!m){g(!0);try{await a(e.id)?X(e.id):r(n("assets.actionFailed"),!0)}finally{g(!1)}}};return s.jsx(z,{active:!0,busy:m,label:n("assets.removeFromElements"),onToggle:()=>{v()}})}if(!o)return null;async function b(){if(m||x.status==="loading")return;if(x.status!=="ready"&&!await O(!0)){r(n("assets.actionFailed"),!0);return}const v=H(C.elements,e.id);g(!0);try{await Re(e,v)}catch(k){console.error("[ElementMembership] toggle failed",k),r(n("assets.actionFailed"),!0)}finally{g(!1)}}return s.jsx(z,{active:!!y,busy:p,label:l,onToggle:()=>{b()}})}const B=12,V=180;function $e(e){return`/generated/${e.split("/").map(encodeURIComponent).join("/")}`}function Le({item:e,selected:n,onSelect:r,onPreview:a}){const{t:m}=E(),g=j(w=>w.deleteAssetItem),f=j(w=>w.updateAssetItem),o=j(w=>w.showToast),[l,x]=d.useState(!1),[y,p]=d.useState(!1),[b,v]=d.useState(!1),k=d.useRef(null);d.useEffect(()=>{const w=k.current;if(!w||e.kind!=="video"||typeof IntersectionObserver>"u"){v(!0);return}const M=new IntersectionObserver(([D])=>{D?.isIntersecting&&v(!0)},{rootMargin:"300px"});return M.observe(w),()=>M.disconnect()},[e.kind]);const h=e.kind==="element"&&!e.filePath?pe(e):e.filePath,u=h?$e(h):null,t=e.kind==="video",c=m(t?"assetGen.videoFallback":"assetGen.imageFallback"),_=m(t?"assetGen.previewVideo":"assetGen.previewImage",{prompt:e.name.trim()||c});async function A(){if(!l){x(!0);return}await g(e.id)||o(m("assets.actionFailed"),!0),x(!1)}const N=e.tags.includes("starred");async function S(){if(!y){p(!0);try{const w=xe(e.tags,N);await f(e.id,{tags:w})||o(m("assets.actionFailed"),!0)}finally{p(!1)}}}return s.jsxs("article",{ref:k,className:`assets-tile${n?" is-selected":""}`,tabIndex:0,"aria-selected":n,onClick:()=>r?.(e.id),onKeyDown:w=>{(w.key==="Enter"||w.key===" ")&&r&&(w.preventDefault(),r(e.id))},children:[s.jsxs("div",{className:"assets-tile__media",children:[u?s.jsxs("button",{type:"button",className:"assets-tile__preview","aria-label":_,onClick:w=>{w.stopPropagation(),r?.(e.id),a?.(e)},onKeyDown:w=>w.stopPropagation(),children:[t?b?s.jsx("video",{src:u,preload:"metadata",muted:!0,playsInline:!0,"aria-hidden":"true"}):null:s.jsx("img",{src:u,alt:"",loading:"lazy",decoding:"async"}),s.jsx("span",{className:"assets-tile__preview-hint","aria-hidden":"true",children:m(t?"assetGen.openHintVideo":"assetGen.openHintImage")})]}):s.jsx("span",{className:"assets-tile__glyph","aria-hidden":"true",children:e.kind.slice(0,1).toUpperCase()}),s.jsx(ge,{variant:"asset",active:N,busy:y,label:m(N?"assets.unstarAsset":"assets.starAsset"),onToggle:S}),s.jsx(Me,{item:e}),s.jsx("button",{type:"button",className:`assets-tile__delete${l?" is-danger":""}`,"aria-label":m(l?"assets.confirmDelete":"assets.deleteAsset"),onClick:w=>{w.stopPropagation(),A()},children:l?m("assets.confirmDelete"):"×"})]}),s.jsxs("div",{className:"assets-tile__meta",children:[s.jsxs("div",{className:"assets-tile__title",children:[s.jsx("strong",{title:e.name,children:e.name}),s.jsx("span",{children:e.kind})]}),e.tags.length>0&&s.jsxs("div",{className:"assets-tile__tags",children:[e.tags.slice(0,2).map(w=>s.jsx("span",{children:w},w)),e.tags.length>2&&s.jsxs("span",{children:["+",e.tags.length-2]})]})]})]})}function Be({onSelectAsset:e,onPreviewAsset:n,selectedId:r}){const{t:a}=E(),m=j(c=>c.assets),g=j(c=>c.assetsLoading),f=j(c=>c.assetsCursor),o=j(c=>c.loadMoreAssets),l=d.useRef(null),[x,y]=d.useState(960),p=Math.max(1,Math.floor((x+B)/(V+B))),b=d.useMemo(()=>Array.from({length:Math.ceil(m.length/p)},(c,_)=>m.slice(_*p,(_+1)*p)),[m,p]);d.useEffect(()=>{const c=l.current;if(!c)return;const _=()=>{const N=getComputedStyle(c),S=(parseFloat(N.paddingLeft)||0)+(parseFloat(N.paddingRight)||0);y(Math.max(0,c.clientWidth-S))};_();const A=new ResizeObserver(_);return A.observe(c),()=>A.disconnect()},[]);const v=Math.max(V,(x-B*(p-1))/p)+70+B,k=fe({count:b.length,getScrollElement:()=>l.current,estimateSize:()=>v,overscan:4}),h=k.getVirtualItems(),u=h.at(-1)?.index,t=d.useCallback(()=>{f&&!g&&o()},[f,g,o]);return d.useEffect(()=>{u===b.length-1&&t()},[u,t,b.length]),s.jsxs("div",{ref:l,className:"assets-grid-scroll",children:[s.jsx("div",{className:"assets-grid-virtual",style:{height:k.getTotalSize()},children:h.map(c=>s.jsx("div",{className:"assets-grid-row",style:{transform:`translateY(${c.start}px)`,gridTemplateColumns:`repeat(${p}, minmax(0, 1fr))`},children:b[c.index]?.map(_=>s.jsx(Le,{item:_,selected:_.id===r,onSelect:e,onPreview:n},_.id))},c.key))}),f&&s.jsx("button",{type:"button",className:"assets-load-more",disabled:g,onClick:t,children:a("assets.loadMore")})]})}const Ke=5e3;function Ue({refs:e,onChange:n,maxRefs:r=6}){const{t:a}=E(),[m,g]=d.useState(null),[f,o]=d.useState(null),[l,x]=d.useState(null),y=d.useRef(null);d.useEffect(()=>()=>{y.current&&window.clearTimeout(y.current)},[]);const p=(u,t)=>{if(t<0||t>=e.length||u===t)return;const c=[...e],[_]=c.splice(u,1);c.splice(t,0,_),n(c)},b=u=>{if(e.length<=1)return;const t=e[u];n(e.filter((c,_)=>_!==u)),x({ref:t,index:u}),y.current&&window.clearTimeout(y.current),y.current=window.setTimeout(()=>x(null),Ke)},v=()=>{if(!l||e.some(t=>t.path===l.ref.path))return;const u=[...e];u.splice(Math.min(l.index,u.length),0,l.ref),n(u.slice(0,r)),x(null)},k=(u,t)=>{u.preventDefault();const c=u.dataTransfer.getData("application/ima2-element-ref")||m,_=e.findIndex(S=>S.id===c);if(g(null),_<0||_===t)return;const A=e[_],N=e.find((S,w)=>w!==_&&S.path===A.path);if(N){o(N.id),window.setTimeout(()=>o(null),1200);return}p(_,t)},h=(u,t)=>n(e.map((c,_)=>_===u?{...c,alt:t}:c));return s.jsxs("section",{className:"element-ref-grid","aria-labelledby":"element-refs-title",children:[s.jsxs("div",{className:"element-detail__section-heading",children:[s.jsxs("div",{children:[s.jsx("h3",{id:"element-refs-title",children:a("element.refsTitle")}),s.jsx("p",{children:a("element.refsHelp")})]}),s.jsxs("span",{children:[e.length," / ",r]})]}),s.jsx("div",{className:"element-ref-grid__items",children:e.map((u,t)=>s.jsxs("div",{className:`element-ref-card${m===u.id?" is-dragging":""}${f===u.id?" is-duplicate":""}`,draggable:!0,onDragStart:c=>{g(u.id),c.dataTransfer.setData("application/ima2-element-ref",u.id),c.dataTransfer.effectAllowed="move"},onDragEnd:()=>g(null),onDragOver:c=>c.preventDefault(),onDrop:c=>k(c,t),children:[s.jsxs("div",{className:"element-ref-card__image",children:[s.jsx("img",{src:u.previewUrl||u.path,alt:u.alt||a("element.refAlt",{n:t+1})}),t===0?s.jsx("span",{children:a("element.refPrimary")}):null]}),s.jsxs("div",{className:"element-ref-card__controls",children:[s.jsxs("label",{children:[a("element.refLabel"),s.jsx("input",{value:u.alt,maxLength:80,placeholder:a("element.refLabelPlaceholder"),onChange:c=>h(t,c.target.value)})]}),s.jsxs("div",{children:[s.jsx("button",{type:"button",disabled:t===0,onClick:()=>p(t,t-1),"aria-label":a("element.refMoveUp",{n:t+1}),children:"↑"}),s.jsx("button",{type:"button",disabled:t===e.length-1,onClick:()=>p(t,t+1),"aria-label":a("element.refMoveDown",{n:t+1}),children:"↓"}),s.jsx("button",{type:"button",className:"is-danger",disabled:e.length<=1,onClick:()=>b(t),"aria-label":a("element.refRemove"),children:a("element.refRemove")})]})]})]},u.id))}),l?s.jsxs("div",{className:"element-ref-grid__undo",role:"status",children:[s.jsx("span",{children:a("element.refRemoved")}),s.jsx("button",{type:"button",onClick:v,children:a("element.refUndo")})]}):null]})}const Ge=/^[A-Za-z0-9_-]{1,32}$/;function qe({bindings:e,refs:n,onSave:r}){const{t:a}=E(),m=e.find(v=>v.provider==="runway"),g=e.find(v=>v.provider==="higgsfield"),[f,o]=d.useState(m?.tag??""),[l,x]=d.useState(!1),[y,p]=d.useState(null),b=async()=>{const v=f.trim();if(v&&!Ge.test(v)){p(a("assets.bindingTagInvalid"));return}p(null),x(!0);try{const k=[{provider:"runway",mode:"stateless-refs",...v?{tag:v}:{}},...g?[g]:[]];await r(k)||p(a("assets.actionFailed"))}finally{x(!1)}};return s.jsxs("section",{className:"element-detail__section","data-testid":"character-bindings-card",children:[s.jsx("div",{className:"element-detail__section-heading",children:s.jsxs("div",{children:[s.jsx("h3",{children:a("assets.bindingsTitle")}),s.jsx("p",{children:a("assets.bindingsHelp")})]})}),s.jsxs("div",{className:"character-binding-row",children:[s.jsx("span",{className:"character-binding-row__provider",children:"Runway"}),s.jsx("span",{className:"character-binding-row__mode",children:a("assets.bindingStateless")}),s.jsx("input",{value:f,maxLength:32,placeholder:a("assets.bindingTagPlaceholder"),"aria-label":a("assets.bindingTagPlaceholder"),onChange:v=>o(v.target.value)}),s.jsx("button",{type:"button",disabled:l,onClick:()=>{b()},children:a(l?"assets.bindingSaving":"assets.bindingSave")})]}),be(n)?s.jsx("p",{className:"element-detail__error",role:"alert",children:a("assets.bindingCapWarning",{count:n.length})}):null,s.jsxs("div",{className:"character-binding-row character-binding-row--locked",children:[s.jsx("span",{className:"character-binding-row__provider",children:"Higgsfield"}),g?.status?s.jsx("span",{className:"character-binding-row__status",children:g.status}):null,s.jsx("button",{type:"button",disabled:!0,title:a("assets.bindingTrainLockedHint"),children:a("assets.bindingTrain")}),s.jsx("span",{className:"character-binding-row__badge",children:a("assets.bindingPaidPlan")})]}),g&&ve(n,g)?s.jsx("p",{className:"element-detail__error",role:"alert",children:a("assets.bindingDriftWarning")}):null,y?s.jsx("p",{className:"element-detail__error",role:"alert",children:y}):null]})}const He=["character","product","style","scene"],W=e=>e[0].toUpperCase()+e.slice(1);function Y(e){return{id:e?.id,name:e?.name??"",kind:e?.kind??"character",refs:(e?.refs??[]).filter(n=>typeof n=="string"&&n.length>0).map((n,r)=>({id:`${e?.id??"new"}-${r}-${n}`,path:n,previewUrl:`/generated/${n.split("/").map(encodeURIComponent).join("/")}`,alt:""})),notes:e?.notes??"",defaultStrength:e?.defaultStrength??.75}}function Oe({element:e,saving:n,testing:r,onSave:a,onDelete:m,onRunTestSheet:g,onSaveBindings:f}){const{t:o}=E(),[l,x]=d.useState(()=>Y(e)),[y,p]=d.useState(null);d.useEffect(()=>{x(Y(e)),p(null)},[e]);const b=800-l.notes.length,v=d.useMemo(()=>l.notes.trim()?`[Element: ${l.name.trim()||"Untitled"}] ${l.notes.trim()}`:null,[l.name,l.notes]),k=(t,c)=>x(_=>({..._,[t]:c})),h=async()=>{if(!l.name.trim())return p(o("element.errorName"));if(!l.refs.length)return p(o("element.errorRefs"));p(null),await a({...l,name:l.name.trim(),notes:l.notes.trim()?l.notes:""})},u=He.map(t=>({value:t,label:o(`element.kind${W(t)}`)}));return s.jsxs("aside",{className:"element-detail","aria-label":o("element.ariaLabel"),children:[s.jsxs("header",{className:"element-detail__header",children:[s.jsxs("div",{children:[s.jsx("span",{children:o("element.title")}),s.jsx("h2",{children:o(e?"element.titleEdit":"element.titleNew")})]}),e?s.jsx("span",{className:"element-detail__status",children:o("element.saved")}):null]}),s.jsxs("label",{className:"element-detail__field",children:[o("element.name"),s.jsx("input",{value:l.name,maxLength:120,placeholder:o("element.namePlaceholder"),onChange:t=>k("name",t.target.value)})]}),s.jsx(je,{title:o("element.kind"),items:u,value:l.kind,onChange:t=>k("kind",t)}),s.jsx("p",{className:"element-detail__kind-help",children:o(`element.help${W(l.kind)}`)}),s.jsx(Ue,{refs:l.refs,onChange:t=>k("refs",t),maxRefs:6}),e&&l.kind==="character"&&f?s.jsx(qe,{bindings:e.characterBindings??[],refs:e.refs,onSave:t=>f(e.id,t)}):null,s.jsxs("section",{className:"element-detail__section",children:[s.jsxs("div",{className:"element-detail__section-heading",children:[s.jsxs("div",{children:[s.jsx("h3",{children:o("element.notes")}),s.jsx("p",{children:o("element.notesHelp")})]}),b<=100?s.jsx("span",{children:o("element.remaining",{n:b})}):null]}),s.jsx("textarea",{value:l.notes,maxLength:800,rows:6,placeholder:o("element.notesPlaceholder"),onChange:t=>k("notes",t.target.value)}),v?s.jsx("p",{className:"element-detail__note-preview",children:v}):null]}),s.jsxs("section",{className:"element-detail__section",children:[s.jsxs("div",{className:"element-detail__section-heading",children:[s.jsxs("div",{children:[s.jsx("h3",{children:o("element.strength")}),s.jsx("p",{children:o("element.strengthHelp")})]}),s.jsx("output",{children:l.defaultStrength.toFixed(2)})]}),s.jsx("input",{className:"element-detail__strength",type:"range",min:"0",max:"1",step:"0.05",value:l.defaultStrength,onChange:t=>k("defaultStrength",Number(t.target.value))}),s.jsx("button",{type:"button",className:"element-detail__reset",onClick:()=>k("defaultStrength",.75),children:o("element.resetDefault")})]}),y?s.jsx("p",{className:"element-detail__error",role:"alert",children:y}):null,s.jsxs("footer",{className:"element-detail__actions",children:[s.jsx("button",{type:"button",className:"element-detail__save",disabled:n,onClick:()=>{h()},children:o(n?"element.saving":"element.save")}),s.jsx("button",{type:"button",disabled:!e||r,onClick:()=>e&&void g(e.id),children:o(r?"element.testing":"element.runTest")}),e&&m?s.jsx("button",{type:"button",className:"is-danger",onClick:()=>{m(e.id)},children:o("element.delete")}):null]})]})}const ze=["image","video","element","preset","template"],Z='button, [href], input, textarea, select, [tabindex]:not([tabindex="-1"])';function Ve(e,n){const r=d.useRef(null),a=d.useRef(null);return d.useEffect(()=>{if(!e)return;a.current=document.activeElement;const m=window.setTimeout(()=>{r.current?.querySelector(Z)?.focus()},0),g=f=>{if(f.key==="Escape"){f.preventDefault(),n();return}if(f.key!=="Tab")return;const o=Array.from(r.current?.querySelectorAll(Z)??[]).filter(y=>!y.hasAttribute("disabled")&&y.getClientRects().length>0);if(o.length===0)return;const l=o[0],x=o[o.length-1];f.shiftKey&&document.activeElement===l?(f.preventDefault(),x.focus()):!f.shiftKey&&document.activeElement===x&&(f.preventDefault(),l.focus())};return document.addEventListener("keydown",g),()=>{window.clearTimeout(m),document.removeEventListener("keydown",g),a.current?.focus()}},[n,e]),r}function Je(){const{t:e}=E(),n=j(i=>i.assets),r=j(i=>i.assetsTags),a=j(i=>i.assetsFilters),m=j(i=>i.assetsLoading),g=j(i=>i.assetsLoadError),f=j(i=>i.loadAssets),o=j(i=>i.setUIMode),l=j(i=>i.setAssetsFilters),x=j(i=>i.updateAssetItem),y=j(i=>i.deleteAssetItem),p=j(i=>i.showToast),[b,v]=d.useState(a.q),[k,h]=d.useState(null),[u,t]=d.useState(null),[c,_]=d.useState(null),A=ye(),N=j(i=>i.keyingTarget),S=j(i=>i.pendingAssetDetailId);d.useEffect(()=>{if(!S)return;const i=S;j.setState({pendingAssetDetailId:null});const F=j.getState().assets.find(T=>T.id===i)??null;_(F),l({kind:null,folderId:null,tag:null,q:""}),v(""),h(i),F||_e(i).then(({asset:T})=>{j.setState(U=>({assets:[T,...U.assets.filter(L=>L.id!==T.id)]})),_(T)}).catch(()=>{})},[S,l]);const w=d.useRef(!1);d.useEffect(()=>{if(N){w.current=!0;return}w.current&&(w.current=!1,f(!0))},[N,f]);const M=d.useMemo(()=>[{value:"",label:e("assets.kindAll")},...ze.map(i=>({value:i,label:e(`assets.kind${i[0].toUpperCase()}${i.slice(1)}`)}))],[e]);d.useEffect(()=>{f(!0)},[f]),d.useEffect(()=>{const i=window.setTimeout(()=>l({q:b}),300);return()=>window.clearTimeout(i)},[b,l]);const D=!!(a.q||a.kind||a.tag),J=n.length===0&&!m,K=a.kind==="element"&&!a.folderId&&!a.q&&!a.tag,ee=K?"assets.emptyElementsTitle":a.folderId?"assets.emptyFolderTitle":D?"assets.emptySearchTitle":"assets.emptyTitle",se=K?"assets.emptyElementsBody":a.folderId?"assets.emptyFolderBody":D?"assets.emptySearchBody":"assets.emptyBody",I=n.find(i=>i.id===k)??(c?.id===k?c:null),q=I?.kind==="element"?Ye(I):null,$=d.useCallback(()=>h(null),[]),te=Ve(!!(I&&A),$),ne=d.useCallback(()=>t(null),[]),ae=async i=>{(!i.id||!await x(i.id,{name:i.name,notes:i.notes}))&&p(e("assets.actionFailed"),!0)},le=async(i,F)=>{const U={...n.find(de=>de.id===i)?.metadata??{},characterBindings:F},L=await x(i,{metadata:U});return L||p(e("assets.actionFailed"),!0),L},ie=async(i,F)=>{const T=await x(i,{name:F});return T||p(e("assets.actionFailed"),!0),T},re=async i=>{await y(i)?$():p(e("assets.actionFailed"),!0)},oe=async()=>p(e("assets.testSheetsUnavailable"),!0);return s.jsxs("section",{className:`assets-workspace${I?" assets-workspace--detail-open":""}`,"aria-labelledby":"assets-title",children:[s.jsx(Ie,{}),s.jsxs("main",{className:"assets-workspace__main",children:[s.jsxs("header",{className:"assets-toolbar",children:[s.jsxs("div",{className:"assets-toolbar__title",children:[s.jsx("h1",{id:"assets-title",children:e("assets.title")}),s.jsx("span",{children:e("assets.itemCount",{count:n.length})})]}),s.jsxs("div",{className:"assets-toolbar__controls",children:[s.jsx("input",{type:"search",value:b,placeholder:e("assets.searchPlaceholder"),"aria-label":e("assets.searchPlaceholder"),onChange:i=>v(i.target.value)}),s.jsx(we,{items:M,value:a.kind??"",onChange:i=>l({kind:i||null}),ariaLabel:e("assets.kindAll")}),n.length>0&&s.jsx("button",{type:"button",className:"assets-clear-btn",onClick:async()=>{confirm(e("assets.clearConfirm"))&&(await ke(),f(!0))},children:e("assets.clearAll")})]}),r.length>0&&s.jsx("div",{className:"assets-tag-filter",children:r.map(i=>s.jsx("button",{type:"button",className:a.tag===i?"is-active":"",onClick:()=>l({tag:a.tag===i?null:i}),children:i},i))})]}),g&&n.length===0?s.jsxs("div",{className:"assets-empty",role:"alert",children:[s.jsx("h2",{children:e("assets.loadErrorTitle")}),s.jsx("p",{children:e("assets.loadErrorBody")}),s.jsx("button",{type:"button",className:"assets-empty__cta",onClick:()=>{f(!0)},children:e("assets.retry")})]}):J?s.jsxs("div",{className:"assets-empty",children:[s.jsx("h2",{children:e(ee)}),s.jsx("p",{children:e(se)}),K||!D&&!a.folderId?s.jsx("button",{type:"button",className:"assets-empty__cta",onClick:()=>o("classic"),children:e("nav.create")}):null]}):s.jsx(Be,{selectedId:k??void 0,onSelectAsset:h,onPreviewAsset:i=>t(Ne(i))})]}),I&&A?s.jsx("button",{type:"button",className:"assets-workspace__detail-backdrop","aria-label":e("assets.detailClose"),onClick:$}):null,I&&s.jsxs("aside",{ref:te,className:"assets-workspace__detail",role:A?"dialog":void 0,"aria-modal":A?!0:void 0,"aria-label":e("assets.detailAria",{name:I.name}),children:[s.jsx("button",{type:"button",className:"assets-workspace__detail-close",onClick:$,"aria-label":e("assets.detailClose"),children:"×"}),q?s.jsx(Oe,{element:q,saving:!1,testing:!1,onSave:ae,onSaveBindings:le,onDelete:re,onRunTestSheet:oe}):s.jsx(We,{asset:I,onRename:i=>ie(I.id,i)})]}),s.jsx(Ae,{}),u?s.jsx(Se,{item:u,onClose:ne}):null]})}function We({asset:e,onRename:n}){const{t:r,locale:a}=E(),[m,g]=d.useState(!1),[f,o]=d.useState(e.name),l=d.useRef(!1),x=typeof e.metadata?.prompt=="string"?e.metadata.prompt:null,y=typeof e.metadata?.provider=="string"?e.metadata.provider:null;d.useEffect(()=>{o(e.name),g(!1)},[e.id,e.name]);async function p(){if(l.current)return;const b=f.trim();if(!b||b===e.name){o(e.name),g(!1);return}l.current=!0;try{await n(b)||o(e.name)}finally{l.current=!1,g(!1)}}return s.jsxs("div",{className:"assets-workspace__detail-meta",children:[s.jsx("div",{className:"assets-workspace__detail-title",children:m?s.jsx("input",{className:"assets-folder-input assets-workspace__detail-name-input",value:f,autoFocus:!0,"aria-label":r("assets.renameAsset"),onChange:b=>o(b.target.value),onBlur:()=>{p()},onKeyDown:b=>{b.key==="Enter"&&p(),b.key==="Escape"&&(o(e.name),g(!1))}}):s.jsxs(s.Fragment,{children:[s.jsx("h2",{children:e.name}),s.jsx("button",{type:"button",className:"assets-workspace__detail-rename","aria-label":r("assets.renameAsset"),title:r("assets.renameAsset"),onClick:()=>g(!0),children:s.jsx(Q,{})})]})}),s.jsxs("dl",{children:[s.jsx("dt",{children:r("assets.detailKind")}),s.jsx("dd",{children:r(`assets.kind${e.kind[0].toUpperCase()}${e.kind.slice(1)}`)}),s.jsx("dt",{children:r("assets.detailCreated")}),s.jsx("dd",{children:new Intl.DateTimeFormat(a,{dateStyle:"medium",timeStyle:"short"}).format(new Date(e.createdAt))}),y?s.jsxs(s.Fragment,{children:[s.jsx("dt",{children:r("assets.detailProvider")}),s.jsx("dd",{children:y})]}):null,x?s.jsxs(s.Fragment,{children:[s.jsx("dt",{children:r("assets.detailPrompt")}),s.jsx("dd",{className:"assets-workspace__detail-prompt",children:x})]}):null,e.tags.length>0?s.jsxs(s.Fragment,{children:[s.jsx("dt",{children:r("assets.detailTags")}),s.jsx("dd",{children:e.tags.join(", ")})]}):null]})]})}function Ye(e){const n=e.metadata??{},r=n.elementKind,a=n.refs,m=Array.isArray(n.characterBindings)?n.characterBindings:void 0;return{id:e.id,name:e.name,kind:r==="product"||r==="style"||r==="scene"?r:"character",refs:Array.isArray(a)?a.filter(g=>typeof g=="string"):e.filePath?[e.filePath]:[],notes:e.notes??void 0,defaultStrength:typeof n.defaultStrength=="number"?n.defaultStrength:void 0,characterBindings:m}}export{Je as AssetsWorkspace};
1
+ import{u as E,b as j,a as d,j as s,T as Q,X as H,m as ce,Y as ue,Z as me,_ as he,$ as fe,o as pe,a0 as ge,a1 as xe,a2 as be,a3 as ve,F as je,s as ye,p as _e,t as we,a4 as ke,a5 as Ne}from"./index-Bj2sxDP3.js";import{K as Ae,A as Se}from"./KeyingPanel-YkL9305F.js";import"./useAgentDialogFocus-BB6ds9jo.js";function Ee({folder:e,depth:n}){const{t:r}=E(),a=j(t=>t.assetsFilters.folderId),m=j(t=>t.setAssetsFilters),g=j(t=>t.renameAssetFolder),f=j(t=>t.deleteAssetFolder),o=j(t=>t.showToast),[l,x]=d.useState(!1),[y,p]=d.useState(e.name),[b,v]=d.useState(!1),k=a===e.id;async function h(){const t=y.trim();if(!t||t===e.name){p(e.name),x(!1);return}await g(e.id,t)||o(r("assets.actionFailed"),!0),x(!1)}async function u(){if(!b){v(!0);return}await f(e.id)||o(r("assets.actionFailed"),!0),v(!1)}return s.jsxs("div",{className:"assets-folder-row",style:{"--folder-depth":n},children:[l?s.jsx("input",{className:"assets-folder-input",value:y,autoFocus:!0,"aria-label":r("assets.renameFolder"),onChange:t=>p(t.target.value),onBlur:()=>{h()},onKeyDown:t=>{t.key==="Enter"&&h(),t.key==="Escape"&&(p(e.name),x(!1))}}):s.jsx("button",{type:"button",className:`assets-folder-row__name${k?" is-active":""}`,"aria-current":k?"page":void 0,onClick:()=>m({folderId:e.id,kind:null}),children:e.name}),!l&&s.jsxs("span",{className:"assets-folder-row__actions",children:[s.jsx("button",{type:"button","aria-label":r("assets.renameFolder"),onClick:()=>x(!0),children:s.jsx(Q,{})}),s.jsx("button",{type:"button","aria-label":r(b?"assets.confirmDelete":"assets.deleteFolder"),className:b?"is-danger is-armed":"",onClick:()=>{u()},children:b?r("assets.confirmDelete"):"×"})]})]})}function Ie(){const{t:e}=E(),n=j(h=>h.assetsFolders),r=j(h=>h.assetsFilters.folderId),a=j(h=>h.assetsFilters.kind),m=j(h=>h.setAssetsFilters),g=j(h=>h.createAssetFolder),f=j(h=>h.showToast),[o,l]=d.useState(!1),[x,y]=d.useState(""),p=r===null&&a!=="element",b=r===null&&a==="element",v=d.useMemo(()=>{const h=[],u=(t,c)=>n.filter(_=>_.parentId===t).forEach(_=>{h.push({folder:_,depth:c}),u(_.id,c+1)});return u(null,0),h},[n]);async function k(){const h=x.trim();if(!h){l(!1);return}await g(h,r)||f(e("assets.actionFailed"),!0),y(""),l(!1)}return s.jsxs("aside",{className:"assets-folders","aria-label":e("assets.rootFolder"),children:[s.jsxs("div",{className:"assets-folders__heading",children:[s.jsx("span",{children:e("assets.rootFolder")}),s.jsx("button",{type:"button","aria-label":e("assets.newFolder"),onClick:()=>l(!0),children:"+"})]}),s.jsxs("div",{className:"assets-folders__rows",children:[s.jsx("button",{type:"button",className:`assets-folder-all${p?" is-active":""}`,"aria-current":p?"page":void 0,onClick:()=>m({folderId:null,kind:null}),children:e("assets.allAssets")}),s.jsxs("button",{type:"button",className:`assets-folder-all assets-folder-elements${b?" is-active":""}`,"aria-current":b?"page":void 0,onClick:()=>m({folderId:null,kind:"element"}),children:[s.jsx("span",{className:"assets-folder-elements__glyph","aria-hidden":"true",children:"@"}),e("assets.elementLibrary")]}),v.map(({folder:h,depth:u})=>s.jsx(Ee,{folder:h,depth:u},h.id)),o&&s.jsx("input",{className:"assets-folder-input assets-folder-input--new",value:x,autoFocus:!0,"aria-label":e("assets.newFolder"),placeholder:e("assets.newFolder"),onChange:h=>y(h.target.value),onBlur:()=>{x.trim()||l(!1)},onKeyDown:h=>{h.key==="Enter"&&k(),h.key==="Escape"&&(y(""),l(!1))}})]})]})}let C={status:"idle",elements:[]},P=null;const G=new Set;function R(e){C=e,G.forEach(n=>n())}function Te(e){return G.add(e),()=>G.delete(e)}function O(e=!1){return!e&&C.status==="ready"?Promise.resolve(!0):P||(R({...C,status:"loading"}),P=ce().then(n=>(R({status:"ready",elements:n}),!0)).catch(n=>(console.error("[ElementMembership] load failed",n),R({...C,status:"error"}),!1)).finally(()=>{P=null}),P)}function Ce(e){const n=[e,...C.elements.filter(r=>r.id!==e.id)];R({status:"ready",elements:n})}function X(e){R({status:"ready",elements:C.elements.filter(n=>n.id!==e)})}function Fe(e){e.stopPropagation()}function De(e){e.stopPropagation()}function Pe(e){(e.key==="Enter"||e.key===" ")&&e.stopPropagation()}async function Re(e,n){if(n){await ue(n.id),X(n.id);return}const{asset:r}=await me({result:{filePath:e.filePath??void 0},sourceAssetId:e.id,elementKind:"character",name:e.name,notes:e.notes??void 0,folderId:e.folderId,tags:[he(e.id)]});Ce(r)}function z({active:e,busy:n,label:r,onToggle:a}){return s.jsx("button",{type:"button",className:`asset-element-toggle${e?" is-active":""}`,title:r,"aria-label":r,"aria-pressed":e,"aria-busy":n||void 0,disabled:n,onPointerDown:Fe,onDoubleClick:De,onKeyDown:Pe,onClick:m=>{m.stopPropagation(),a()},children:s.jsx("span",{className:"asset-element-toggle__glyph","aria-hidden":"true",children:"@"})})}function Me({item:e}){const{t:n}=E(),r=j(v=>v.showToast),a=j(v=>v.deleteAssetItem),[m,g]=d.useState(!1),f=e.kind==="element",o=f||(e.kind==="image"||e.kind==="video")&&!!e.filePath,l=n("assets.elementLibrary"),x=d.useSyncExternalStore(Te,()=>C,()=>C),y=!f&&o?H(x.elements,e.id):null,p=m||x.status==="loading"||x.status==="idle";if(d.useEffect(()=>{o&&!f&&O()},[o,f]),f){const v=async()=>{if(!m){g(!0);try{await a(e.id)?X(e.id):r(n("assets.actionFailed"),!0)}finally{g(!1)}}};return s.jsx(z,{active:!0,busy:m,label:n("assets.removeFromElements"),onToggle:()=>{v()}})}if(!o)return null;async function b(){if(m||x.status==="loading")return;if(x.status!=="ready"&&!await O(!0)){r(n("assets.actionFailed"),!0);return}const v=H(C.elements,e.id);g(!0);try{await Re(e,v)}catch(k){console.error("[ElementMembership] toggle failed",k),r(n("assets.actionFailed"),!0)}finally{g(!1)}}return s.jsx(z,{active:!!y,busy:p,label:l,onToggle:()=>{b()}})}const B=12,V=180;function $e(e){return`/generated/${e.split("/").map(encodeURIComponent).join("/")}`}function Le({item:e,selected:n,onSelect:r,onPreview:a}){const{t:m}=E(),g=j(w=>w.deleteAssetItem),f=j(w=>w.updateAssetItem),o=j(w=>w.showToast),[l,x]=d.useState(!1),[y,p]=d.useState(!1),[b,v]=d.useState(!1),k=d.useRef(null);d.useEffect(()=>{const w=k.current;if(!w||e.kind!=="video"||typeof IntersectionObserver>"u"){v(!0);return}const M=new IntersectionObserver(([D])=>{D?.isIntersecting&&v(!0)},{rootMargin:"300px"});return M.observe(w),()=>M.disconnect()},[e.kind]);const h=e.kind==="element"&&!e.filePath?pe(e):e.filePath,u=h?$e(h):null,t=e.kind==="video",c=m(t?"assetGen.videoFallback":"assetGen.imageFallback"),_=m(t?"assetGen.previewVideo":"assetGen.previewImage",{prompt:e.name.trim()||c});async function A(){if(!l){x(!0);return}await g(e.id)||o(m("assets.actionFailed"),!0),x(!1)}const N=e.tags.includes("starred");async function S(){if(!y){p(!0);try{const w=xe(e.tags,N);await f(e.id,{tags:w})||o(m("assets.actionFailed"),!0)}finally{p(!1)}}}return s.jsxs("article",{ref:k,className:`assets-tile${n?" is-selected":""}`,tabIndex:0,"aria-selected":n,onClick:()=>r?.(e.id),onKeyDown:w=>{(w.key==="Enter"||w.key===" ")&&r&&(w.preventDefault(),r(e.id))},children:[s.jsxs("div",{className:"assets-tile__media",children:[u?s.jsxs("button",{type:"button",className:"assets-tile__preview","aria-label":_,onClick:w=>{w.stopPropagation(),r?.(e.id),a?.(e)},onKeyDown:w=>w.stopPropagation(),children:[t?b?s.jsx("video",{src:u,preload:"metadata",muted:!0,playsInline:!0,"aria-hidden":"true"}):null:s.jsx("img",{src:u,alt:"",loading:"lazy",decoding:"async"}),s.jsx("span",{className:"assets-tile__preview-hint","aria-hidden":"true",children:m(t?"assetGen.openHintVideo":"assetGen.openHintImage")})]}):s.jsx("span",{className:"assets-tile__glyph","aria-hidden":"true",children:e.kind.slice(0,1).toUpperCase()}),s.jsx(ge,{variant:"asset",active:N,busy:y,label:m(N?"assets.unstarAsset":"assets.starAsset"),onToggle:S}),s.jsx(Me,{item:e}),s.jsx("button",{type:"button",className:`assets-tile__delete${l?" is-danger":""}`,"aria-label":m(l?"assets.confirmDelete":"assets.deleteAsset"),onClick:w=>{w.stopPropagation(),A()},children:l?m("assets.confirmDelete"):"×"})]}),s.jsxs("div",{className:"assets-tile__meta",children:[s.jsxs("div",{className:"assets-tile__title",children:[s.jsx("strong",{title:e.name,children:e.name}),s.jsx("span",{children:e.kind})]}),e.tags.length>0&&s.jsxs("div",{className:"assets-tile__tags",children:[e.tags.slice(0,2).map(w=>s.jsx("span",{children:w},w)),e.tags.length>2&&s.jsxs("span",{children:["+",e.tags.length-2]})]})]})]})}function Be({onSelectAsset:e,onPreviewAsset:n,selectedId:r}){const{t:a}=E(),m=j(c=>c.assets),g=j(c=>c.assetsLoading),f=j(c=>c.assetsCursor),o=j(c=>c.loadMoreAssets),l=d.useRef(null),[x,y]=d.useState(960),p=Math.max(1,Math.floor((x+B)/(V+B))),b=d.useMemo(()=>Array.from({length:Math.ceil(m.length/p)},(c,_)=>m.slice(_*p,(_+1)*p)),[m,p]);d.useEffect(()=>{const c=l.current;if(!c)return;const _=()=>{const N=getComputedStyle(c),S=(parseFloat(N.paddingLeft)||0)+(parseFloat(N.paddingRight)||0);y(Math.max(0,c.clientWidth-S))};_();const A=new ResizeObserver(_);return A.observe(c),()=>A.disconnect()},[]);const v=Math.max(V,(x-B*(p-1))/p)+70+B,k=fe({count:b.length,getScrollElement:()=>l.current,estimateSize:()=>v,overscan:4}),h=k.getVirtualItems(),u=h.at(-1)?.index,t=d.useCallback(()=>{f&&!g&&o()},[f,g,o]);return d.useEffect(()=>{u===b.length-1&&t()},[u,t,b.length]),s.jsxs("div",{ref:l,className:"assets-grid-scroll",children:[s.jsx("div",{className:"assets-grid-virtual",style:{height:k.getTotalSize()},children:h.map(c=>s.jsx("div",{className:"assets-grid-row",style:{transform:`translateY(${c.start}px)`,gridTemplateColumns:`repeat(${p}, minmax(0, 1fr))`},children:b[c.index]?.map(_=>s.jsx(Le,{item:_,selected:_.id===r,onSelect:e,onPreview:n},_.id))},c.key))}),f&&s.jsx("button",{type:"button",className:"assets-load-more",disabled:g,onClick:t,children:a("assets.loadMore")})]})}const Ke=5e3;function Ue({refs:e,onChange:n,maxRefs:r=6}){const{t:a}=E(),[m,g]=d.useState(null),[f,o]=d.useState(null),[l,x]=d.useState(null),y=d.useRef(null);d.useEffect(()=>()=>{y.current&&window.clearTimeout(y.current)},[]);const p=(u,t)=>{if(t<0||t>=e.length||u===t)return;const c=[...e],[_]=c.splice(u,1);c.splice(t,0,_),n(c)},b=u=>{if(e.length<=1)return;const t=e[u];n(e.filter((c,_)=>_!==u)),x({ref:t,index:u}),y.current&&window.clearTimeout(y.current),y.current=window.setTimeout(()=>x(null),Ke)},v=()=>{if(!l||e.some(t=>t.path===l.ref.path))return;const u=[...e];u.splice(Math.min(l.index,u.length),0,l.ref),n(u.slice(0,r)),x(null)},k=(u,t)=>{u.preventDefault();const c=u.dataTransfer.getData("application/ima2-element-ref")||m,_=e.findIndex(S=>S.id===c);if(g(null),_<0||_===t)return;const A=e[_],N=e.find((S,w)=>w!==_&&S.path===A.path);if(N){o(N.id),window.setTimeout(()=>o(null),1200);return}p(_,t)},h=(u,t)=>n(e.map((c,_)=>_===u?{...c,alt:t}:c));return s.jsxs("section",{className:"element-ref-grid","aria-labelledby":"element-refs-title",children:[s.jsxs("div",{className:"element-detail__section-heading",children:[s.jsxs("div",{children:[s.jsx("h3",{id:"element-refs-title",children:a("element.refsTitle")}),s.jsx("p",{children:a("element.refsHelp")})]}),s.jsxs("span",{children:[e.length," / ",r]})]}),s.jsx("div",{className:"element-ref-grid__items",children:e.map((u,t)=>s.jsxs("div",{className:`element-ref-card${m===u.id?" is-dragging":""}${f===u.id?" is-duplicate":""}`,draggable:!0,onDragStart:c=>{g(u.id),c.dataTransfer.setData("application/ima2-element-ref",u.id),c.dataTransfer.effectAllowed="move"},onDragEnd:()=>g(null),onDragOver:c=>c.preventDefault(),onDrop:c=>k(c,t),children:[s.jsxs("div",{className:"element-ref-card__image",children:[s.jsx("img",{src:u.previewUrl||u.path,alt:u.alt||a("element.refAlt",{n:t+1})}),t===0?s.jsx("span",{children:a("element.refPrimary")}):null]}),s.jsxs("div",{className:"element-ref-card__controls",children:[s.jsxs("label",{children:[a("element.refLabel"),s.jsx("input",{value:u.alt,maxLength:80,placeholder:a("element.refLabelPlaceholder"),onChange:c=>h(t,c.target.value)})]}),s.jsxs("div",{children:[s.jsx("button",{type:"button",disabled:t===0,onClick:()=>p(t,t-1),"aria-label":a("element.refMoveUp",{n:t+1}),children:"↑"}),s.jsx("button",{type:"button",disabled:t===e.length-1,onClick:()=>p(t,t+1),"aria-label":a("element.refMoveDown",{n:t+1}),children:"↓"}),s.jsx("button",{type:"button",className:"is-danger",disabled:e.length<=1,onClick:()=>b(t),"aria-label":a("element.refRemove"),children:a("element.refRemove")})]})]})]},u.id))}),l?s.jsxs("div",{className:"element-ref-grid__undo",role:"status",children:[s.jsx("span",{children:a("element.refRemoved")}),s.jsx("button",{type:"button",onClick:v,children:a("element.refUndo")})]}):null]})}const Ge=/^[A-Za-z0-9_-]{1,32}$/;function qe({bindings:e,refs:n,onSave:r}){const{t:a}=E(),m=e.find(v=>v.provider==="runway"),g=e.find(v=>v.provider==="higgsfield"),[f,o]=d.useState(m?.tag??""),[l,x]=d.useState(!1),[y,p]=d.useState(null),b=async()=>{const v=f.trim();if(v&&!Ge.test(v)){p(a("assets.bindingTagInvalid"));return}p(null),x(!0);try{const k=[{provider:"runway",mode:"stateless-refs",...v?{tag:v}:{}},...g?[g]:[]];await r(k)||p(a("assets.actionFailed"))}finally{x(!1)}};return s.jsxs("section",{className:"element-detail__section","data-testid":"character-bindings-card",children:[s.jsx("div",{className:"element-detail__section-heading",children:s.jsxs("div",{children:[s.jsx("h3",{children:a("assets.bindingsTitle")}),s.jsx("p",{children:a("assets.bindingsHelp")})]})}),s.jsxs("div",{className:"character-binding-row",children:[s.jsx("span",{className:"character-binding-row__provider",children:"Runway"}),s.jsx("span",{className:"character-binding-row__mode",children:a("assets.bindingStateless")}),s.jsx("input",{value:f,maxLength:32,placeholder:a("assets.bindingTagPlaceholder"),"aria-label":a("assets.bindingTagPlaceholder"),onChange:v=>o(v.target.value)}),s.jsx("button",{type:"button",disabled:l,onClick:()=>{b()},children:a(l?"assets.bindingSaving":"assets.bindingSave")})]}),be(n)?s.jsx("p",{className:"element-detail__error",role:"alert",children:a("assets.bindingCapWarning",{count:n.length})}):null,s.jsxs("div",{className:"character-binding-row character-binding-row--locked",children:[s.jsx("span",{className:"character-binding-row__provider",children:"Higgsfield"}),g?.status?s.jsx("span",{className:"character-binding-row__status",children:g.status}):null,s.jsx("button",{type:"button",disabled:!0,title:a("assets.bindingTrainLockedHint"),children:a("assets.bindingTrain")}),s.jsx("span",{className:"character-binding-row__badge",children:a("assets.bindingPaidPlan")})]}),g&&ve(n,g)?s.jsx("p",{className:"element-detail__error",role:"alert",children:a("assets.bindingDriftWarning")}):null,y?s.jsx("p",{className:"element-detail__error",role:"alert",children:y}):null]})}const He=["character","product","style","scene"],W=e=>e[0].toUpperCase()+e.slice(1);function Y(e){return{id:e?.id,name:e?.name??"",kind:e?.kind??"character",refs:(e?.refs??[]).filter(n=>typeof n=="string"&&n.length>0).map((n,r)=>({id:`${e?.id??"new"}-${r}-${n}`,path:n,previewUrl:`/generated/${n.split("/").map(encodeURIComponent).join("/")}`,alt:""})),notes:e?.notes??"",defaultStrength:e?.defaultStrength??.75}}function Oe({element:e,saving:n,testing:r,onSave:a,onDelete:m,onRunTestSheet:g,onSaveBindings:f}){const{t:o}=E(),[l,x]=d.useState(()=>Y(e)),[y,p]=d.useState(null);d.useEffect(()=>{x(Y(e)),p(null)},[e]);const b=800-l.notes.length,v=d.useMemo(()=>l.notes.trim()?`[Element: ${l.name.trim()||"Untitled"}] ${l.notes.trim()}`:null,[l.name,l.notes]),k=(t,c)=>x(_=>({..._,[t]:c})),h=async()=>{if(!l.name.trim())return p(o("element.errorName"));if(!l.refs.length)return p(o("element.errorRefs"));p(null),await a({...l,name:l.name.trim(),notes:l.notes.trim()?l.notes:""})},u=He.map(t=>({value:t,label:o(`element.kind${W(t)}`)}));return s.jsxs("aside",{className:"element-detail","aria-label":o("element.ariaLabel"),children:[s.jsxs("header",{className:"element-detail__header",children:[s.jsxs("div",{children:[s.jsx("span",{children:o("element.title")}),s.jsx("h2",{children:o(e?"element.titleEdit":"element.titleNew")})]}),e?s.jsx("span",{className:"element-detail__status",children:o("element.saved")}):null]}),s.jsxs("label",{className:"element-detail__field",children:[o("element.name"),s.jsx("input",{value:l.name,maxLength:120,placeholder:o("element.namePlaceholder"),onChange:t=>k("name",t.target.value)})]}),s.jsx(je,{title:o("element.kind"),items:u,value:l.kind,onChange:t=>k("kind",t)}),s.jsx("p",{className:"element-detail__kind-help",children:o(`element.help${W(l.kind)}`)}),s.jsx(Ue,{refs:l.refs,onChange:t=>k("refs",t),maxRefs:6}),e&&l.kind==="character"&&f?s.jsx(qe,{bindings:e.characterBindings??[],refs:e.refs,onSave:t=>f(e.id,t)}):null,s.jsxs("section",{className:"element-detail__section",children:[s.jsxs("div",{className:"element-detail__section-heading",children:[s.jsxs("div",{children:[s.jsx("h3",{children:o("element.notes")}),s.jsx("p",{children:o("element.notesHelp")})]}),b<=100?s.jsx("span",{children:o("element.remaining",{n:b})}):null]}),s.jsx("textarea",{value:l.notes,maxLength:800,rows:6,placeholder:o("element.notesPlaceholder"),onChange:t=>k("notes",t.target.value)}),v?s.jsx("p",{className:"element-detail__note-preview",children:v}):null]}),s.jsxs("section",{className:"element-detail__section",children:[s.jsxs("div",{className:"element-detail__section-heading",children:[s.jsxs("div",{children:[s.jsx("h3",{children:o("element.strength")}),s.jsx("p",{children:o("element.strengthHelp")})]}),s.jsx("output",{children:l.defaultStrength.toFixed(2)})]}),s.jsx("input",{className:"element-detail__strength",type:"range",min:"0",max:"1",step:"0.05",value:l.defaultStrength,onChange:t=>k("defaultStrength",Number(t.target.value))}),s.jsx("button",{type:"button",className:"element-detail__reset",onClick:()=>k("defaultStrength",.75),children:o("element.resetDefault")})]}),y?s.jsx("p",{className:"element-detail__error",role:"alert",children:y}):null,s.jsxs("footer",{className:"element-detail__actions",children:[s.jsx("button",{type:"button",className:"element-detail__save",disabled:n,onClick:()=>{h()},children:o(n?"element.saving":"element.save")}),s.jsx("button",{type:"button",disabled:!e||r,onClick:()=>e&&void g(e.id),children:o(r?"element.testing":"element.runTest")}),e&&m?s.jsx("button",{type:"button",className:"is-danger",onClick:()=>{m(e.id)},children:o("element.delete")}):null]})]})}const ze=["image","video","element","preset","template"],Z='button, [href], input, textarea, select, [tabindex]:not([tabindex="-1"])';function Ve(e,n){const r=d.useRef(null),a=d.useRef(null);return d.useEffect(()=>{if(!e)return;a.current=document.activeElement;const m=window.setTimeout(()=>{r.current?.querySelector(Z)?.focus()},0),g=f=>{if(f.key==="Escape"){f.preventDefault(),n();return}if(f.key!=="Tab")return;const o=Array.from(r.current?.querySelectorAll(Z)??[]).filter(y=>!y.hasAttribute("disabled")&&y.getClientRects().length>0);if(o.length===0)return;const l=o[0],x=o[o.length-1];f.shiftKey&&document.activeElement===l?(f.preventDefault(),x.focus()):!f.shiftKey&&document.activeElement===x&&(f.preventDefault(),l.focus())};return document.addEventListener("keydown",g),()=>{window.clearTimeout(m),document.removeEventListener("keydown",g),a.current?.focus()}},[n,e]),r}function Je(){const{t:e}=E(),n=j(i=>i.assets),r=j(i=>i.assetsTags),a=j(i=>i.assetsFilters),m=j(i=>i.assetsLoading),g=j(i=>i.assetsLoadError),f=j(i=>i.loadAssets),o=j(i=>i.setUIMode),l=j(i=>i.setAssetsFilters),x=j(i=>i.updateAssetItem),y=j(i=>i.deleteAssetItem),p=j(i=>i.showToast),[b,v]=d.useState(a.q),[k,h]=d.useState(null),[u,t]=d.useState(null),[c,_]=d.useState(null),A=ye(),N=j(i=>i.keyingTarget),S=j(i=>i.pendingAssetDetailId);d.useEffect(()=>{if(!S)return;const i=S;j.setState({pendingAssetDetailId:null});const F=j.getState().assets.find(T=>T.id===i)??null;_(F),l({kind:null,folderId:null,tag:null,q:""}),v(""),h(i),F||_e(i).then(({asset:T})=>{j.setState(U=>({assets:[T,...U.assets.filter(L=>L.id!==T.id)]})),_(T)}).catch(()=>{})},[S,l]);const w=d.useRef(!1);d.useEffect(()=>{if(N){w.current=!0;return}w.current&&(w.current=!1,f(!0))},[N,f]);const M=d.useMemo(()=>[{value:"",label:e("assets.kindAll")},...ze.map(i=>({value:i,label:e(`assets.kind${i[0].toUpperCase()}${i.slice(1)}`)}))],[e]);d.useEffect(()=>{f(!0)},[f]),d.useEffect(()=>{const i=window.setTimeout(()=>l({q:b}),300);return()=>window.clearTimeout(i)},[b,l]);const D=!!(a.q||a.kind||a.tag),J=n.length===0&&!m,K=a.kind==="element"&&!a.folderId&&!a.q&&!a.tag,ee=K?"assets.emptyElementsTitle":a.folderId?"assets.emptyFolderTitle":D?"assets.emptySearchTitle":"assets.emptyTitle",se=K?"assets.emptyElementsBody":a.folderId?"assets.emptyFolderBody":D?"assets.emptySearchBody":"assets.emptyBody",I=n.find(i=>i.id===k)??(c?.id===k?c:null),q=I?.kind==="element"?Ye(I):null,$=d.useCallback(()=>h(null),[]),te=Ve(!!(I&&A),$),ne=d.useCallback(()=>t(null),[]),ae=async i=>{(!i.id||!await x(i.id,{name:i.name,notes:i.notes}))&&p(e("assets.actionFailed"),!0)},le=async(i,F)=>{const U={...n.find(de=>de.id===i)?.metadata??{},characterBindings:F},L=await x(i,{metadata:U});return L||p(e("assets.actionFailed"),!0),L},ie=async(i,F)=>{const T=await x(i,{name:F});return T||p(e("assets.actionFailed"),!0),T},re=async i=>{await y(i)?$():p(e("assets.actionFailed"),!0)},oe=async()=>p(e("assets.testSheetsUnavailable"),!0);return s.jsxs("section",{className:`assets-workspace${I?" assets-workspace--detail-open":""}`,"aria-labelledby":"assets-title",children:[s.jsx(Ie,{}),s.jsxs("main",{className:"assets-workspace__main",children:[s.jsxs("header",{className:"assets-toolbar",children:[s.jsxs("div",{className:"assets-toolbar__title",children:[s.jsx("h1",{id:"assets-title",children:e("assets.title")}),s.jsx("span",{children:e("assets.itemCount",{count:n.length})})]}),s.jsxs("div",{className:"assets-toolbar__controls",children:[s.jsx("input",{type:"search",value:b,placeholder:e("assets.searchPlaceholder"),"aria-label":e("assets.searchPlaceholder"),onChange:i=>v(i.target.value)}),s.jsx(we,{items:M,value:a.kind??"",onChange:i=>l({kind:i||null}),ariaLabel:e("assets.kindAll")}),n.length>0&&s.jsx("button",{type:"button",className:"assets-clear-btn",onClick:async()=>{confirm(e("assets.clearConfirm"))&&(await ke(),f(!0))},children:e("assets.clearAll")})]}),r.length>0&&s.jsx("div",{className:"assets-tag-filter",children:r.map(i=>s.jsx("button",{type:"button",className:a.tag===i?"is-active":"",onClick:()=>l({tag:a.tag===i?null:i}),children:i},i))})]}),g&&n.length===0?s.jsxs("div",{className:"assets-empty",role:"alert",children:[s.jsx("h2",{children:e("assets.loadErrorTitle")}),s.jsx("p",{children:e("assets.loadErrorBody")}),s.jsx("button",{type:"button",className:"assets-empty__cta",onClick:()=>{f(!0)},children:e("assets.retry")})]}):J?s.jsxs("div",{className:"assets-empty",children:[s.jsx("h2",{children:e(ee)}),s.jsx("p",{children:e(se)}),K||!D&&!a.folderId?s.jsx("button",{type:"button",className:"assets-empty__cta",onClick:()=>o("classic"),children:e("nav.create")}):null]}):s.jsx(Be,{selectedId:k??void 0,onSelectAsset:h,onPreviewAsset:i=>t(Ne(i))})]}),I&&A?s.jsx("button",{type:"button",className:"assets-workspace__detail-backdrop","aria-label":e("assets.detailClose"),onClick:$}):null,I&&s.jsxs("aside",{ref:te,className:"assets-workspace__detail",role:A?"dialog":void 0,"aria-modal":A?!0:void 0,"aria-label":e("assets.detailAria",{name:I.name}),children:[s.jsx("button",{type:"button",className:"assets-workspace__detail-close",onClick:$,"aria-label":e("assets.detailClose"),children:"×"}),q?s.jsx(Oe,{element:q,saving:!1,testing:!1,onSave:ae,onSaveBindings:le,onDelete:re,onRunTestSheet:oe}):s.jsx(We,{asset:I,onRename:i=>ie(I.id,i)})]}),s.jsx(Ae,{}),u?s.jsx(Se,{item:u,onClose:ne}):null]})}function We({asset:e,onRename:n}){const{t:r,locale:a}=E(),[m,g]=d.useState(!1),[f,o]=d.useState(e.name),l=d.useRef(!1),x=typeof e.metadata?.prompt=="string"?e.metadata.prompt:null,y=typeof e.metadata?.provider=="string"?e.metadata.provider:null;d.useEffect(()=>{o(e.name),g(!1)},[e.id,e.name]);async function p(){if(l.current)return;const b=f.trim();if(!b||b===e.name){o(e.name),g(!1);return}l.current=!0;try{await n(b)||o(e.name)}finally{l.current=!1,g(!1)}}return s.jsxs("div",{className:"assets-workspace__detail-meta",children:[s.jsx("div",{className:"assets-workspace__detail-title",children:m?s.jsx("input",{className:"assets-folder-input assets-workspace__detail-name-input",value:f,autoFocus:!0,"aria-label":r("assets.renameAsset"),onChange:b=>o(b.target.value),onBlur:()=>{p()},onKeyDown:b=>{b.key==="Enter"&&p(),b.key==="Escape"&&(o(e.name),g(!1))}}):s.jsxs(s.Fragment,{children:[s.jsx("h2",{children:e.name}),s.jsx("button",{type:"button",className:"assets-workspace__detail-rename","aria-label":r("assets.renameAsset"),title:r("assets.renameAsset"),onClick:()=>g(!0),children:s.jsx(Q,{})})]})}),s.jsxs("dl",{children:[s.jsx("dt",{children:r("assets.detailKind")}),s.jsx("dd",{children:r(`assets.kind${e.kind[0].toUpperCase()}${e.kind.slice(1)}`)}),s.jsx("dt",{children:r("assets.detailCreated")}),s.jsx("dd",{children:new Intl.DateTimeFormat(a,{dateStyle:"medium",timeStyle:"short"}).format(new Date(e.createdAt))}),y?s.jsxs(s.Fragment,{children:[s.jsx("dt",{children:r("assets.detailProvider")}),s.jsx("dd",{children:y})]}):null,x?s.jsxs(s.Fragment,{children:[s.jsx("dt",{children:r("assets.detailPrompt")}),s.jsx("dd",{className:"assets-workspace__detail-prompt",children:x})]}):null,e.tags.length>0?s.jsxs(s.Fragment,{children:[s.jsx("dt",{children:r("assets.detailTags")}),s.jsx("dd",{children:e.tags.join(", ")})]}):null]})]})}function Ye(e){const n=e.metadata??{},r=n.elementKind,a=n.refs,m=Array.isArray(n.characterBindings)?n.characterBindings:void 0;return{id:e.id,name:e.name,kind:r==="product"||r==="style"||r==="scene"?r:"character",refs:Array.isArray(a)?a.filter(g=>typeof g=="string"):e.filePath?[e.filePath]:[],notes:e.notes??void 0,defaultStrength:typeof n.defaultStrength=="number"?n.defaultStrength:void 0,characterBindings:m}}export{Je as AssetsWorkspace};
@@ -1,2 +1,2 @@
1
- import{u,M as l,j as e,N as k,a as h,t as j,s as _}from"./index-DoM1FoZ5.js";function C(s){const r=s.slots.filter(n=>n.kind==="text"||n.textKind).length,c=s.slots.filter(n=>n.kind==="image").length;return`${r} text / ${c} image`}function T(){const{t:s}=u(),r=l(t=>t.templates),c=l(t=>t.imageTemplateId),n=l(t=>t.setImageTemplate);return e.jsxs("section",{className:"card-news-panel",children:[e.jsxs("div",{className:"card-news-panel__head",children:[e.jsx("span",{children:s("cardNews.imageTemplate")}),e.jsx("button",{type:"button",disabled:!0,title:s("cardNews.newTemplateLater"),children:"+"})]}),e.jsx("div",{className:"card-news-template-grid",children:r.map(t=>e.jsxs("button",{type:"button",className:`card-news-template${c===t.id?" selected":""}`,onClick:()=>n(t.id),children:[e.jsx("img",{src:t.previewUrl,alt:""}),e.jsxs("span",{className:"card-news-template__body",children:[e.jsx("span",{className:"card-news-template__name",children:t.name}),e.jsx("span",{className:"card-news-template__meta",children:C(t)}),e.jsx("span",{className:"card-news-template__sizes",children:t.recommendedOutputSizes.join(" · ")})]})]},t.id))})]})}function I(){const{t:s}=u(),r=l(t=>t.roleTemplates),c=l(t=>t.roleTemplateId),n=l(t=>t.setRoleTemplate);return e.jsxs("section",{className:"card-news-panel",children:[e.jsx("div",{className:"card-news-panel__head",children:e.jsx("span",{children:s("cardNews.roleTemplate")})}),e.jsx("div",{className:"card-news-role-row",children:r.map(t=>e.jsx("button",{type:"button",className:c===t.id?"selected":"",onClick:()=>n(t.id),children:t.name},t.id))})]})}function F({status:s,locked:r}){const{t:c}=u(),n=r?"locked":s,t=n==="queued"||n==="generating";return e.jsxs("span",{className:`card-news-status-badge card-news-status-badge--${n}`,children:[t?e.jsx("span",{className:"card-news-spinner","aria-hidden":"true"}):null,c(`cardNews.status.${n}`)]})}function M(s,r){const c=`cardNews.roles.${s}`,n=r(c);return n===c?s:n}function S(){const{t:s}=u(),r=l(t=>t.activePlan),c=l(t=>t.selectedCardId),n=l(t=>t.selectCard);return r?e.jsx("div",{className:"card-news-deck","aria-label":s("common.cardDeck"),onWheel:k,children:r.cards.map(t=>e.jsxs("button",{type:"button",className:`card-news-deck-card${c===t.id?" selected":""}`,onClick:()=>n(t.id),children:[e.jsx("span",{children:String(t.order).padStart(2,"0")}),t.url?e.jsx("img",{src:t.url,alt:"",className:"card-news-deck-card__thumb"}):null,e.jsx("strong",{children:M(t.role,s)}),e.jsx("small",{children:t.headline||t.textFields.find(p=>p.renderMode==="in-image")?.text}),e.jsx(F,{status:t.status,locked:t.locked})]},t.id))}):null}const $=[];function E(){const{t:s}=u(),r=l(t=>t.activePlan?.cards??$),c=l(t=>t.generating),n={total:r.length,done:r.filter(t=>t.status==="generated").length,queued:r.filter(t=>t.status==="queued").length,errors:r.filter(t=>t.status==="error").length,skipped:r.filter(t=>t.locked||t.status==="skipped").length};return n.total?e.jsxs("div",{className:"card-news-batch-bar","aria-live":"polite",children:[e.jsx("span",{children:c?s("cardNews.progress.generating",{done:n.done,total:n.total}):s("cardNews.progress.summary",{done:n.done,total:n.total})}),e.jsx("span",{children:s("cardNews.progress.detail",{queued:n.queued,errors:n.errors,skipped:n.skipped})})]}):null}function P({meta:s}){const{t:r}=u();if(!s)return null;const c=s.mode==="structured-output"?r("cardNews.planner.structured"):s.mode==="json-mode"?r("cardNews.planner.jsonMode"):r("cardNews.planner.fallback");return e.jsxs("span",{className:"card-news-planner-badge",children:[c," · ",s.model,s.repaired?` · ${r("cardNews.planner.repaired")}`:""]})}function L(s){const r=s.textFields.filter(c=>c.renderMode==="in-image"&&c.text).map(c=>`[${c.placement}] ${c.text}`);return[s.headline,...r].filter(Boolean).join(`
1
+ import{u,M as l,j as e,N as k,a as h,t as j,s as _}from"./index-Bj2sxDP3.js";function C(s){const r=s.slots.filter(n=>n.kind==="text"||n.textKind).length,c=s.slots.filter(n=>n.kind==="image").length;return`${r} text / ${c} image`}function T(){const{t:s}=u(),r=l(t=>t.templates),c=l(t=>t.imageTemplateId),n=l(t=>t.setImageTemplate);return e.jsxs("section",{className:"card-news-panel",children:[e.jsxs("div",{className:"card-news-panel__head",children:[e.jsx("span",{children:s("cardNews.imageTemplate")}),e.jsx("button",{type:"button",disabled:!0,title:s("cardNews.newTemplateLater"),children:"+"})]}),e.jsx("div",{className:"card-news-template-grid",children:r.map(t=>e.jsxs("button",{type:"button",className:`card-news-template${c===t.id?" selected":""}`,onClick:()=>n(t.id),children:[e.jsx("img",{src:t.previewUrl,alt:""}),e.jsxs("span",{className:"card-news-template__body",children:[e.jsx("span",{className:"card-news-template__name",children:t.name}),e.jsx("span",{className:"card-news-template__meta",children:C(t)}),e.jsx("span",{className:"card-news-template__sizes",children:t.recommendedOutputSizes.join(" · ")})]})]},t.id))})]})}function I(){const{t:s}=u(),r=l(t=>t.roleTemplates),c=l(t=>t.roleTemplateId),n=l(t=>t.setRoleTemplate);return e.jsxs("section",{className:"card-news-panel",children:[e.jsx("div",{className:"card-news-panel__head",children:e.jsx("span",{children:s("cardNews.roleTemplate")})}),e.jsx("div",{className:"card-news-role-row",children:r.map(t=>e.jsx("button",{type:"button",className:c===t.id?"selected":"",onClick:()=>n(t.id),children:t.name},t.id))})]})}function F({status:s,locked:r}){const{t:c}=u(),n=r?"locked":s,t=n==="queued"||n==="generating";return e.jsxs("span",{className:`card-news-status-badge card-news-status-badge--${n}`,children:[t?e.jsx("span",{className:"card-news-spinner","aria-hidden":"true"}):null,c(`cardNews.status.${n}`)]})}function M(s,r){const c=`cardNews.roles.${s}`,n=r(c);return n===c?s:n}function S(){const{t:s}=u(),r=l(t=>t.activePlan),c=l(t=>t.selectedCardId),n=l(t=>t.selectCard);return r?e.jsx("div",{className:"card-news-deck","aria-label":s("common.cardDeck"),onWheel:k,children:r.cards.map(t=>e.jsxs("button",{type:"button",className:`card-news-deck-card${c===t.id?" selected":""}`,onClick:()=>n(t.id),children:[e.jsx("span",{children:String(t.order).padStart(2,"0")}),t.url?e.jsx("img",{src:t.url,alt:"",className:"card-news-deck-card__thumb"}):null,e.jsx("strong",{children:M(t.role,s)}),e.jsx("small",{children:t.headline||t.textFields.find(p=>p.renderMode==="in-image")?.text}),e.jsx(F,{status:t.status,locked:t.locked})]},t.id))}):null}const $=[];function E(){const{t:s}=u(),r=l(t=>t.activePlan?.cards??$),c=l(t=>t.generating),n={total:r.length,done:r.filter(t=>t.status==="generated").length,queued:r.filter(t=>t.status==="queued").length,errors:r.filter(t=>t.status==="error").length,skipped:r.filter(t=>t.locked||t.status==="skipped").length};return n.total?e.jsxs("div",{className:"card-news-batch-bar","aria-live":"polite",children:[e.jsx("span",{children:c?s("cardNews.progress.generating",{done:n.done,total:n.total}):s("cardNews.progress.summary",{done:n.done,total:n.total})}),e.jsx("span",{children:s("cardNews.progress.detail",{queued:n.queued,errors:n.errors,skipped:n.skipped})})]}):null}function P({meta:s}){const{t:r}=u();if(!s)return null;const c=s.mode==="structured-output"?r("cardNews.planner.structured"):s.mode==="json-mode"?r("cardNews.planner.jsonMode"):r("cardNews.planner.fallback");return e.jsxs("span",{className:"card-news-planner-badge",children:[c," · ",s.model,s.repaired?` · ${r("cardNews.planner.repaired")}`:""]})}function L(s){const r=s.textFields.filter(c=>c.renderMode==="in-image"&&c.text).map(c=>`[${c.placement}] ${c.text}`);return[s.headline,...r].filter(Boolean).join(`
2
2
  `)}function R(s,r){const c=s.slotId?r?.slots.find(n=>n.id===s.slotId):null;return c?{left:`${c.x/20.48}%`,top:`${c.y/20.48}%`,width:`${c.w/20.48}%`,minHeight:`${c.h/20.48}%`}:B(s)}const b={"top-left":{left:"10%",top:"10%",width:"34%"},"top-center":{left:"50%",top:"10%",width:"42%",transform:"translateX(-50%)"},"top-right":{right:"10%",top:"10%",width:"34%"},"center-left":{left:"10%",top:"50%",width:"34%",transform:"translateY(-50%)"},center:{left:"50%",top:"50%",width:"44%",transform:"translate(-50%, -50%)"},"center-right":{right:"10%",top:"50%",width:"34%",transform:"translateY(-50%)"},"bottom-left":{left:"10%",bottom:"10%",width:"34%"},"bottom-center":{left:"50%",bottom:"10%",width:"42%",transform:"translateX(-50%)"},"bottom-right":{right:"10%",bottom:"10%",width:"34%"},free:{left:"50%",top:"50%",width:"44%",transform:"translate(-50%, -50%)"}};function B(s){return b[s.placement]||b.center}function D(){const{t:s}=u(),r=l(a=>a.activePlan),c=l(a=>a.selectedCardId),n=l(a=>a.selectedTextFieldId),t=l(a=>a.templates),p=l(a=>a.plannerMeta),m=l(a=>a.retryCard),x=l(a=>a.selectTextField),o=r?.cards.find(a=>a.id===c)||r?.cards[0],w=r?t.find(a=>a.id===r.imageTemplateId):void 0,d=o?.textFields.filter(a=>a.renderMode==="in-image")||[];return!r||!o?e.jsxs("section",{className:"card-news-empty",children:[e.jsxs("div",{className:"card-news-empty__deck","aria-hidden":"true",children:[e.jsx("div",{className:"card-news-empty__card card-news-empty__card--back"}),e.jsx("div",{className:"card-news-empty__card card-news-empty__card--mid"}),e.jsxs("div",{className:"card-news-empty__card",children:[e.jsx("span",{}),e.jsx("strong",{}),e.jsx("em",{})]})]}),e.jsxs("div",{className:"card-news-empty__copy",children:[e.jsx("span",{children:s("uiMode.cardNews")}),e.jsx("h2",{children:s("cardNews.emptyTitle")}),e.jsx("p",{children:s("cardNews.emptyBody")})]})]}):e.jsxs("section",{className:"card-news-stage",children:[e.jsxs("div",{className:"card-news-stage__header",children:[e.jsxs("div",{children:[e.jsx("h2",{children:r.title}),e.jsx("p",{children:r.generationStrategy}),e.jsx(P,{meta:p})]}),e.jsxs("span",{children:[o.order," / ",r.cards.length]})]}),e.jsx(E,{}),e.jsxs("div",{className:"card-news-preview",children:[o.status==="queued"||o.status==="generating"?e.jsx("div",{className:"card-news-preview__loading",children:s("cardNews.progress.cardGenerating")}):o.status==="error"?e.jsxs("div",{className:"card-news-preview__error",children:[e.jsx("span",{children:o.error||s("cardNews.error")}),o.locked?null:e.jsx("button",{type:"button",onClick:()=>{m(o.id)},children:s("cardNews.retryCard")})]}):o.url?e.jsx("img",{src:o.url,alt:o.headline}):e.jsx("div",{className:"card-news-preview__slot"}),d.length?e.jsx("div",{className:"card-news-stage-overlay",children:d.map(a=>e.jsx("button",{type:"button",className:`card-news-stage-overlay__field card-news-stage-overlay__field--${a.placement}${n===a.id?" selected":""}`,style:R(a,w),onClick:()=>x(a.id),"aria-label":s("cardNews.selectTextField",{text:a.text||a.kind}),children:e.jsx("span",{children:a.text||a.kind})},a.id))}):null]}),o.url?e.jsxs("div",{className:"card-news-result-actions",children:[e.jsx("button",{type:"button",onClick:()=>navigator.clipboard?.writeText(o.visualPrompt),children:s("cardNews.actions.copyPrompt")}),e.jsx("button",{type:"button",onClick:()=>navigator.clipboard?.writeText(L(o)),children:s("cardNews.actions.copyCopy")}),e.jsx("a",{href:o.url,target:"_blank",rel:"noreferrer",children:s("cardNews.actions.openImage")}),e.jsx("a",{href:o.url,download:!0,children:s("cardNews.actions.downloadCard")})]}):null]})}function y(s,r){const c=`cardNews.placements.${s}`,n=r(c);return n===c?s:n}function q({placement:s}){const{t:r}=u();return e.jsx("span",{className:"card-news-placement-chip",children:y(s,r)})}const K=["headline","body","caption","cta","badge","number"],A=["top-left","top-center","top-right","center-left","center","center-right","bottom-left","bottom-center","bottom-right","free"],H=["in-image","ui-only"],Y=["primary","secondary","supporting"];function N(s,r,c){const n=`cardNews.${s}.${r}`,t=c(n);return t===n?r:t}function z({field:s,locked:r,selected:c=!1,onSelect:n,onChange:t,onRemove:p}){const{t:m}=u(),x=s.text.length,o=typeof s.maxChars=="number"&&x>s.maxChars,w=s.maxChars===null||s.maxChars>80,d=h.useMemo(()=>K.map(i=>({value:i,label:N("textKinds",i,m)})),[m]),a=h.useMemo(()=>A.map(i=>({value:i,label:y(i,m)})),[m]),g=h.useMemo(()=>H.map(i=>({value:i,label:N("renderModes",i,m)})),[m]),f=h.useMemo(()=>Y.map(i=>({value:i,label:N("hierarchy",i,m)})),[m]);return e.jsxs("div",{className:`card-news-text-field-card${c?" selected":""}`,onClick:n,children:[e.jsxs("div",{className:"card-news-text-field-card__header",children:[e.jsx("span",{children:N("textKinds",s.kind,m)}),e.jsx(q,{placement:s.placement})]}),e.jsxs("label",{className:"card-news-field",children:[e.jsx("span",{children:m("cardNews.textFieldText")}),w?e.jsx("textarea",{value:s.text,disabled:r,onChange:i=>t({text:i.target.value,source:"user"})}):e.jsx("input",{value:s.text,disabled:r,onChange:i=>t({text:i.target.value,source:"user"})})]}),e.jsxs("div",{className:"card-news-text-field-card__grid",children:[e.jsxs("label",{className:"card-news-field",children:[e.jsx("span",{children:m("cardNews.textKind")}),e.jsx(j,{items:d,value:s.kind,disabled:r,onChange:i=>t({kind:i,source:"user"})})]}),e.jsxs("label",{className:"card-news-field",children:[e.jsx("span",{children:m("cardNews.placement")}),e.jsx(j,{items:a,value:s.placement,disabled:r,onChange:i=>t({placement:i,source:"user"})})]}),e.jsxs("label",{className:"card-news-field",children:[e.jsx("span",{children:m("cardNews.renderMode")}),e.jsx(j,{items:g,value:s.renderMode,disabled:r,onChange:i=>t({renderMode:i,source:"user"})})]}),e.jsxs("label",{className:"card-news-field",children:[e.jsx("span",{children:m("cardNews.hierarchyLabel")}),e.jsx(j,{items:f,value:s.hierarchy,disabled:r,onChange:i=>t({hierarchy:i,source:"user"})})]})]}),e.jsxs("div",{className:`card-news-text-field-card__meta${o?" over":""}`,children:[e.jsx("span",{children:s.maxChars===null?x:`${x}/${s.maxChars}`}),o?e.jsx("span",{children:m("cardNews.textTooLong")}):null,p?e.jsx("button",{type:"button",disabled:r,onClick:p,children:m("cardNews.removeTextField")}):null]})]})}function O(){return{id:`tf_${Date.now().toString(36)}`,kind:"body",text:"",renderMode:"in-image",placement:"center",slotId:null,hierarchy:"supporting",maxChars:null,language:null,source:"user"}}function W(){const{t:s}=u(),r=l(a=>a.activePlan),c=l(a=>a.selectedCardId),n=l(a=>a.selectedTextFieldId),t=l(a=>a.updateCard),p=l(a=>a.updateTextField),m=l(a=>a.addTextField),x=l(a=>a.removeTextField),o=l(a=>a.selectTextField),w=l(a=>a.retryCard),d=r?.cards.find(a=>a.id===c)||r?.cards[0];return d?e.jsxs("aside",{className:"card-news-inspector",children:[e.jsx("div",{className:"section-title",children:s("cardNews.inspector")}),e.jsxs("div",{className:"card-news-inspector-group",children:[e.jsx("span",{className:"card-news-inspector-label",children:s("cardNews.cardTitle")}),e.jsxs("label",{className:"card-news-field",children:[e.jsx("span",{children:s("cardNews.headline")}),e.jsx("input",{value:d.headline,disabled:d.locked,onChange:a=>t(d.id,{headline:a.target.value})})]})]}),e.jsxs("div",{className:"card-news-inspector-group",children:[e.jsxs("div",{className:"card-news-inspector-row",children:[e.jsx("span",{className:"card-news-inspector-label",children:s("cardNews.textFields")}),e.jsx("button",{type:"button",className:"secondary-btn",disabled:d.locked,onClick:()=>m(d.id,O()),children:s("cardNews.addTextField")})]}),d.textFields.length?d.textFields.map(a=>e.jsx(z,{field:a,locked:d.locked,selected:n===a.id,onSelect:()=>o(a.id),onChange:g=>p(d.id,a.id,g),onRemove:()=>x(d.id,a.id)},a.id)):e.jsx("p",{className:"card-news-muted",children:s("cardNews.noTextFields")})]}),e.jsxs("details",{className:"card-news-inspector-group card-news-advanced-prompt",children:[e.jsx("summary",{children:s("cardNews.designPrompt")}),e.jsxs("label",{className:"card-news-field",children:[e.jsx("span",{children:s("cardNews.visualPrompt")}),e.jsx("textarea",{value:d.visualPrompt,disabled:d.locked,onChange:a=>t(d.id,{visualPrompt:a.target.value})})]})]}),d.imageFilename?e.jsxs("div",{className:"card-news-generated-meta",children:[e.jsx("span",{children:s("cardNews.generatedMeta")}),e.jsx("code",{children:d.imageFilename}),e.jsx("span",{children:d.status})]}):null,d.locked?e.jsx("p",{className:"card-news-locked-help",children:s("cardNews.lockedHelp")}):null,e.jsx("button",{type:"button",className:`secondary-btn${d.locked?" active":""}`,onClick:()=>t(d.id,{locked:!d.locked}),children:d.locked?s("cardNews.locked"):s("cardNews.unlocked")}),e.jsx("button",{type:"button",className:"secondary-btn",disabled:d.locked||!["draft","error"].includes(d.status),onClick:()=>{w(d.id)},children:s("cardNews.retryCard")})]}):e.jsxs("aside",{className:"card-news-inspector card-news-inspector-empty",children:[e.jsx("div",{className:"section-title",children:s("cardNews.inspector")}),e.jsxs("div",{className:"card-news-inspector-empty__mock","aria-hidden":"true",children:[e.jsx("span",{}),e.jsx("strong",{}),e.jsx("i",{}),e.jsx("i",{})]}),e.jsx("p",{children:s("cardNews.noCard")})]})}const v="ima2:cardNewsMobileNoticeShown";function X(){const{t:s}=u(),r=_(),[c,n]=h.useState(()=>{if(typeof window>"u")return!0;try{return localStorage.getItem(v)==="1"}catch{return!1}});if(!r||c)return null;const t=()=>{try{localStorage.setItem(v,"1")}catch{}n(!0)};return e.jsxs("div",{className:"card-news-mobile-notice",role:"status",children:[e.jsx("span",{children:s("mobile.cardNewsBanner")}),e.jsx("button",{type:"button",onClick:t,children:s("mobile.dismiss")})]})}function U(){const{t:s}=u(),r=l(n=>n.hydrate),c=l(n=>n.error);return h.useEffect(()=>{r()},[r]),e.jsxs("main",{className:"card-news-workspace","aria-label":s("cardNews.workspace"),children:[e.jsx(X,{}),e.jsxs("div",{className:"card-news-setup",children:[e.jsx(T,{}),e.jsx(I,{})]}),e.jsxs("div",{className:"card-news-main",children:[c?e.jsx("div",{className:"card-news-error",role:"alert",children:c}):null,e.jsx(D,{}),e.jsx(S,{})]}),e.jsx(W,{})]})}export{U as CardNewsWorkspace};
@@ -0,0 +1 @@
1
+ import{q as j,u as _,aq as b,C as N,j as e,b as p,a as n}from"./index-Bj2sxDP3.js";async function f(){return j("/api/generation-requests")}async function v(a){if(navigator.clipboard?.writeText){await navigator.clipboard.writeText(a);return}const o=document.createElement("textarea");o.value=a,o.style.position="fixed",o.style.opacity="0",document.body.appendChild(o),o.select();try{document.execCommand("copy")}finally{document.body.removeChild(o)}}function y({entry:a,onClose:o,onCopyPrompt:i}){const{t:s}=_(),l=b(!0,o),r=a.succeeded===0;return N.createPortal(e.jsxs("div",{className:"generation-log-detail",role:"presentation",children:[e.jsx("div",{className:"generation-log-detail__backdrop",onClick:o}),e.jsxs("div",{ref:l,className:"generation-log-detail__content",role:"dialog","aria-modal":"true","aria-labelledby":"generation-log-detail-title",tabIndex:-1,children:[e.jsxs("div",{className:"generation-log-detail__header",children:[e.jsxs("h2",{id:"generation-log-detail-title",className:"generation-log-detail__title",children:[s("generationLog.detailTitle"),e.jsxs("span",{className:`generation-log-detail__badge${r?" is-error":" is-success"}`,children:[a.succeeded,"/",a.requested]})]}),e.jsx("button",{type:"button",className:"generation-log-detail__close",onClick:o,"aria-label":s("common.close"),children:"×"})]}),e.jsxs("div",{className:"generation-log-detail__grid",children:[e.jsx("span",{className:"generation-log-detail__label",children:s("generationLog.detailTime")}),e.jsx("span",{children:new Date(a.createdAt).toLocaleString()}),e.jsx("span",{className:"generation-log-detail__label",children:s("generationLog.detailRequestId")}),e.jsx("span",{className:"generation-log-detail__mono",children:a.requestId}),e.jsx("span",{className:"generation-log-detail__label",children:s("generationLog.detailCounts")}),e.jsxs("span",{children:[a.succeeded," / ",a.requested]}),a.error?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"generation-log-detail__label",children:s("generationLog.detailError")}),e.jsx("span",{className:"generation-log-detail__mono is-error",children:a.error})]}):null,a.errorMessage?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"generation-log-detail__label",children:s("generationLog.detailErrorMessage")}),e.jsx("span",{className:"generation-log-detail__reason",children:a.errorMessage})]}):null]}),e.jsxs("div",{className:"generation-log-detail__section",children:[e.jsx("div",{className:"generation-log-detail__label",children:s("generationLog.detailPrompt")}),e.jsx("div",{className:"generation-log-detail__prompt",children:a.prompt||s("generationLog.detailPromptEmpty")})]}),e.jsx("div",{className:"generation-log-detail__footer",children:e.jsx("button",{type:"button",className:"generation-log-detail__copy",onClick:()=>i(a),"data-modal-initial-focus":!0,children:s("generationLog.copy")})})]})]}),document.body)}function q(){const{t:a}=_(),o=p(t=>t.showToast),i=p(t=>t.activeGenerations),[s,l]=n.useState([]),[r,d]=n.useState(!0),[x,g]=n.useState(!1),[u,m]=n.useState(null),c=n.useCallback(async()=>{d(!0),g(!1);try{const t=await f();l(t.items)}catch{l([]),g(!0)}finally{d(!1)}},[]);n.useEffect(()=>{c()},[c,i]);const h=async t=>{try{await v(t.prompt),o(a("generationLog.copied"))}catch{o(a("toast.copyFailed"),!0)}};return r?e.jsx("div",{className:"generation-request-log__empty",children:a("common.loading")}):x?e.jsxs("div",{className:"generation-request-log__empty",role:"alert",children:[e.jsx("span",{children:a("generationLog.loadFailed")}),e.jsx("button",{type:"button",onClick:()=>{c()},children:a("generationLog.retry")})]}):e.jsxs("div",{className:"generation-request-log",role:"list",children:[s.length===0?e.jsx("div",{className:"generation-request-log__empty",children:a("generationLog.empty")}):s.map(t=>e.jsxs("button",{type:"button",role:"listitem",className:"generation-request-log__item",onClick:()=>m(t),title:a("generationLog.detailOpen"),children:[e.jsx("span",{className:"generation-request-log__prompt",children:t.prompt}),e.jsxs("span",{className:`generation-request-log__count${t.succeeded===0?" is-error":" is-success"}`,children:[t.succeeded,"/",t.requested]})]},t.id)),u?e.jsx(y,{entry:u,onClose:()=>m(null),onCopyPrompt:t=>{h(t)}}):null]})}export{q as GenerationRequestLogPanel};
@@ -1 +1 @@
1
- import{b as i,u as m,ae as I,j as e,af as k,ag as A,t as P,ah as E,a as x,ai as M,aj as R,ak as T,al as w,am as C,an as L,ao as O,ap as H}from"./index-DoM1FoZ5.js";const S={oauth:"GPT OAuth",api:"GPT API",grok:"Grok OAuth","grok-api":"Grok API",agy:"Antigravity","gemini-api":"Gemini API",atlascloud:"Atlas Cloud",minimax:"MiniMax"};function G(s){if(s.kind==="attachment")return s.source.dataUrl;if(s.source.thumbnailUrl)return s.source.thumbnailUrl;const t=s.source.referenceFilenames[0];if(t)return t.startsWith("/generated/")?t:`/generated/${t.split("/").map(encodeURIComponent).join("/")}`}function U({providerAvailability:s}){const t=i(o=>o.prompt),r=i(o=>o.setPrompt),n=i(o=>o.provider),a=i(o=>o.setProvider),c=i(o=>o.selectedPresetIds),p=i(o=>o.removePreset),d=i(o=>o.generate),j=i(o=>o.activeGenerations),h=i(o=>o.trayItems),{t:l}=m(),f=new Set(c),b=I().filter(o=>f.has(o.id)),v=j>0,y=Object.entries(S).map(([o,u])=>{const g=o,_=s[g];return{value:g,label:u,sub:_.ok?l("readiness.ready"):_.reason,disabled:!_.ok}});return e.jsxs("div",{className:"home-prompt",children:[b.length>0?e.jsx(k,{className:"home-prompt__chips",ariaLabel:l("home.selectedPresets"),children:b.map(o=>e.jsx(A,{selected:!0,onRemove:()=>p(o.id),removeLabel:l("common.removeNamed",{name:o.name}),title:o.category,children:o.name},o.id))}):null,h.length>0?e.jsxs("div",{className:"home-prompt__reference-strip",role:"group","aria-label":l("home.referenceTrayAria",{count:h.length}),children:[e.jsx("span",{className:"home-prompt__reference-thumbs","aria-hidden":"true",children:h.map(o=>{const u=G(o);return e.jsx("span",{className:"home-prompt__reference-thumb",children:u?e.jsx("img",{src:u,alt:"",loading:"lazy",decoding:"async"}):"@"},o.tokenId)})}),e.jsx("span",{className:"home-prompt__reference-count",children:l("home.referenceTrayCount",{count:h.length})})]}):null,e.jsx("label",{className:"home-prompt__label",htmlFor:"home-prompt-input",children:l("prompt.label")}),e.jsx("textarea",{id:"home-prompt-input",className:"home-prompt__textarea",rows:5,value:t,placeholder:l("prompt.placeholder"),onChange:o=>r(o.target.value)}),e.jsxs("div",{className:"home-prompt__footer",children:[e.jsx(P,{className:"home-prompt__provider",items:y,value:n,onChange:a,ariaLabel:l("readiness.provider")}),e.jsx("button",{type:"button",className:"home-prompt__generate",disabled:v||t.trim().length===0,onClick:()=>{d();const o=i.getState().setUIMode;o("classic")},children:v?l("generate.buttonLoading",{n:j}):l("generate.button")})]})]})}const N=/\.(mp4|webm|mov)(?:$|[?#])/i;function D(s){return s.mediaType==="video"||N.test(s.filename??"")||N.test(s.url??s.image)?s.thumb:s.thumb||s.url||s.image||void 0}function V({item:s,featured:t}){const{t:r}=m(),[n,a]=x.useState(!1),c=D(s),p=(s.userPrompt?.trim()||s.prompt?.trim()||r("home.untitledResult")).slice(0,60),d=r("home.recentResultAlt",{prompt:p});return!c||n?e.jsx("div",{className:"home-recent-card__fallback",role:"img","aria-label":d,children:r("home.mediaUnavailable")}):e.jsx("img",{src:c,alt:d,loading:t?"eager":"lazy",decoding:"async",onError:()=>a(!0)})}function B(){const s=i(n=>n.history),{t}=m(),r=s.slice(0,5);return r.length===0?e.jsx("p",{className:"home-recent-empty",role:"status",children:t("history.emptyRecent")}):e.jsx("div",{className:"home-recent-row",role:"list","aria-label":t("home.recentTitle"),children:r.map((n,a)=>{const c=a===0;return e.jsx("figure",{className:`home-recent-card${c?" is-featured":""}`,role:"listitem",children:e.jsx(V,{item:n,featured:c})},E(n))})})}function $(){return e.jsxs("svg",{className:"home-hero__mode-arrow",width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[e.jsx("path",{d:"M5 12h14"}),e.jsx("path",{d:"m12 5 7 7-7 7"})]})}function F(){const{t:s}=m(),t=M(),r=x.useMemo(()=>Object.values(t).filter(a=>a?.ok).length,[t]),n=x.useMemo(()=>Object.keys(t).length,[t]);return e.jsxs("div",{className:"home-hero",children:[e.jsx("div",{className:"home-hero__mark","aria-hidden":"true",children:"IMA2"}),e.jsxs("header",{className:"home-hero__intro",children:[e.jsx("h1",{className:"home-hero__title",children:s("home.heroTitle")}),e.jsx("p",{className:"home-hero__lede",children:s("home.heroLede")})]}),e.jsxs("p",{className:"home-hero__readiness",role:"status",children:[e.jsx("span",{className:`home-hero__dot${r>0?" is-ready":""}`,"aria-hidden":"true"}),r>0?s("home.lanesReady",{ready:r,total:n}):s("home.lanesNone")]}),e.jsx("div",{className:"home-workspace__composer",children:e.jsx(U,{providerAvailability:t})}),e.jsxs("section",{className:"home-workspace__recent","aria-labelledby":"home-recent-title",children:[e.jsx("h2",{id:"home-recent-title",children:s("home.recentTitle")}),e.jsx(B,{})]}),e.jsx(W,{})]})}function W(){const{t:s}=m(),t=i(a=>a.setUIMode),r=[{mode:"classic",label:s("nav.create"),hint:s("home.modeCreateHint"),enabled:!0,icon:R},{mode:"node",label:s("nav.node"),hint:s("home.modeNodeHint"),enabled:w,icon:T},{mode:"agent",label:s("nav.agent"),hint:s("home.modeAgentHint"),enabled:L,icon:C},{mode:"assets",label:s("nav.assets"),hint:s("home.modeAssetsHint"),enabled:!0,icon:O}];function n(a){t(a),history.replaceState(null,"",H[a]??"#create")}return e.jsxs("nav",{className:"home-modes","aria-label":s("home.modesTitle"),children:[e.jsx("h2",{className:"home-modes__title",children:s("home.modesTitle")}),r.filter(a=>a.enabled).map(a=>e.jsxs("button",{type:"button",className:"home-modes__item",onClick:()=>n(a.mode),children:[e.jsx("span",{className:"home-modes__icon",children:e.jsx(a.icon,{})}),e.jsx("span",{className:"home-modes__label",children:a.label}),e.jsx("span",{className:"home-modes__hint",children:a.hint}),e.jsx($,{})]},a.mode))]})}function K(){const{t:s}=m();return e.jsx("section",{className:"home-workspace","aria-label":s("nav.home"),children:e.jsx("div",{className:"home-workspace__inner",children:e.jsx(F,{})})})}export{K as HomeWorkspace};
1
+ import{b as i,u as m,ae as I,j as e,af as k,ag as A,t as P,ah as E,a as x,ai as M,aj as R,ak as T,al as w,am as C,an as L,ao as O,ap as H}from"./index-Bj2sxDP3.js";const S={oauth:"GPT OAuth",api:"GPT API",grok:"Grok OAuth","grok-api":"Grok API",agy:"Antigravity","gemini-api":"Gemini API",atlascloud:"Atlas Cloud",minimax:"MiniMax"};function G(s){if(s.kind==="attachment")return s.source.dataUrl;if(s.source.thumbnailUrl)return s.source.thumbnailUrl;const t=s.source.referenceFilenames[0];if(t)return t.startsWith("/generated/")?t:`/generated/${t.split("/").map(encodeURIComponent).join("/")}`}function U({providerAvailability:s}){const t=i(o=>o.prompt),r=i(o=>o.setPrompt),n=i(o=>o.provider),a=i(o=>o.setProvider),c=i(o=>o.selectedPresetIds),p=i(o=>o.removePreset),d=i(o=>o.generate),j=i(o=>o.activeGenerations),h=i(o=>o.trayItems),{t:l}=m(),f=new Set(c),b=I().filter(o=>f.has(o.id)),v=j>0,y=Object.entries(S).map(([o,u])=>{const g=o,_=s[g];return{value:g,label:u,sub:_.ok?l("readiness.ready"):_.reason,disabled:!_.ok}});return e.jsxs("div",{className:"home-prompt",children:[b.length>0?e.jsx(k,{className:"home-prompt__chips",ariaLabel:l("home.selectedPresets"),children:b.map(o=>e.jsx(A,{selected:!0,onRemove:()=>p(o.id),removeLabel:l("common.removeNamed",{name:o.name}),title:o.category,children:o.name},o.id))}):null,h.length>0?e.jsxs("div",{className:"home-prompt__reference-strip",role:"group","aria-label":l("home.referenceTrayAria",{count:h.length}),children:[e.jsx("span",{className:"home-prompt__reference-thumbs","aria-hidden":"true",children:h.map(o=>{const u=G(o);return e.jsx("span",{className:"home-prompt__reference-thumb",children:u?e.jsx("img",{src:u,alt:"",loading:"lazy",decoding:"async"}):"@"},o.tokenId)})}),e.jsx("span",{className:"home-prompt__reference-count",children:l("home.referenceTrayCount",{count:h.length})})]}):null,e.jsx("label",{className:"home-prompt__label",htmlFor:"home-prompt-input",children:l("prompt.label")}),e.jsx("textarea",{id:"home-prompt-input",className:"home-prompt__textarea",rows:5,value:t,placeholder:l("prompt.placeholder"),onChange:o=>r(o.target.value)}),e.jsxs("div",{className:"home-prompt__footer",children:[e.jsx(P,{className:"home-prompt__provider",items:y,value:n,onChange:a,ariaLabel:l("readiness.provider")}),e.jsx("button",{type:"button",className:"home-prompt__generate",disabled:v||t.trim().length===0,onClick:()=>{d();const o=i.getState().setUIMode;o("classic")},children:v?l("generate.buttonLoading",{n:j}):l("generate.button")})]})]})}const N=/\.(mp4|webm|mov)(?:$|[?#])/i;function D(s){return s.mediaType==="video"||N.test(s.filename??"")||N.test(s.url??s.image)?s.thumb:s.thumb||s.url||s.image||void 0}function V({item:s,featured:t}){const{t:r}=m(),[n,a]=x.useState(!1),c=D(s),p=(s.userPrompt?.trim()||s.prompt?.trim()||r("home.untitledResult")).slice(0,60),d=r("home.recentResultAlt",{prompt:p});return!c||n?e.jsx("div",{className:"home-recent-card__fallback",role:"img","aria-label":d,children:r("home.mediaUnavailable")}):e.jsx("img",{src:c,alt:d,loading:t?"eager":"lazy",decoding:"async",onError:()=>a(!0)})}function B(){const s=i(n=>n.history),{t}=m(),r=s.slice(0,5);return r.length===0?e.jsx("p",{className:"home-recent-empty",role:"status",children:t("history.emptyRecent")}):e.jsx("div",{className:"home-recent-row",role:"list","aria-label":t("home.recentTitle"),children:r.map((n,a)=>{const c=a===0;return e.jsx("figure",{className:`home-recent-card${c?" is-featured":""}`,role:"listitem",children:e.jsx(V,{item:n,featured:c})},E(n))})})}function $(){return e.jsxs("svg",{className:"home-hero__mode-arrow",width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[e.jsx("path",{d:"M5 12h14"}),e.jsx("path",{d:"m12 5 7 7-7 7"})]})}function F(){const{t:s}=m(),t=M(),r=x.useMemo(()=>Object.values(t).filter(a=>a?.ok).length,[t]),n=x.useMemo(()=>Object.keys(t).length,[t]);return e.jsxs("div",{className:"home-hero",children:[e.jsx("div",{className:"home-hero__mark","aria-hidden":"true",children:"IMA2"}),e.jsxs("header",{className:"home-hero__intro",children:[e.jsx("h1",{className:"home-hero__title",children:s("home.heroTitle")}),e.jsx("p",{className:"home-hero__lede",children:s("home.heroLede")})]}),e.jsxs("p",{className:"home-hero__readiness",role:"status",children:[e.jsx("span",{className:`home-hero__dot${r>0?" is-ready":""}`,"aria-hidden":"true"}),r>0?s("home.lanesReady",{ready:r,total:n}):s("home.lanesNone")]}),e.jsx("div",{className:"home-workspace__composer",children:e.jsx(U,{providerAvailability:t})}),e.jsxs("section",{className:"home-workspace__recent","aria-labelledby":"home-recent-title",children:[e.jsx("h2",{id:"home-recent-title",children:s("home.recentTitle")}),e.jsx(B,{})]}),e.jsx(W,{})]})}function W(){const{t:s}=m(),t=i(a=>a.setUIMode),r=[{mode:"classic",label:s("nav.create"),hint:s("home.modeCreateHint"),enabled:!0,icon:R},{mode:"node",label:s("nav.node"),hint:s("home.modeNodeHint"),enabled:w,icon:T},{mode:"agent",label:s("nav.agent"),hint:s("home.modeAgentHint"),enabled:L,icon:C},{mode:"assets",label:s("nav.assets"),hint:s("home.modeAssetsHint"),enabled:!0,icon:O}];function n(a){t(a),history.replaceState(null,"",H[a]??"#create")}return e.jsxs("nav",{className:"home-modes","aria-label":s("home.modesTitle"),children:[e.jsx("h2",{className:"home-modes__title",children:s("home.modesTitle")}),r.filter(a=>a.enabled).map(a=>e.jsxs("button",{type:"button",className:"home-modes__item",onClick:()=>n(a.mode),children:[e.jsx("span",{className:"home-modes__icon",children:e.jsx(a.icon,{})}),e.jsx("span",{className:"home-modes__label",children:a.label}),e.jsx("span",{className:"home-modes__hint",children:a.hint}),e.jsx($,{})]},a.mode))]})}function K(){const{t:s}=m();return e.jsx("section",{className:"home-workspace","aria-label":s("nav.home"),children:e.jsx("div",{className:"home-workspace__inner",children:e.jsx(F,{})})})}export{K as HomeWorkspace};
@@ -1 +1 @@
1
- import{u as se,a as M,b as q,p as he,j as s,ab as fe,ac as ge,ad as me}from"./index-DoM1FoZ5.js";import{u as pe}from"./useAgentDialogFocus-BOGEpRNF.js";function ye(){return s.jsx("svg",{viewBox:"0 0 24 24",width:"18",height:"18","aria-hidden":"true",children:s.jsx("path",{d:"M6 6l12 12M18 6 6 18",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round"})})}function xe({zoomed:e}){return s.jsxs("svg",{viewBox:"0 0 24 24",width:"18",height:"18","aria-hidden":"true",children:[s.jsx("circle",{cx:"10.5",cy:"10.5",r:"6.5",fill:"none",stroke:"currentColor",strokeWidth:"1.7"}),s.jsx("path",{d:"M15.5 15.5 21 21M7.5 10.5h6",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round"}),e?null:s.jsx("path",{d:"M10.5 7.5v6",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round"})]})}function Le({item:e,onClose:t}){const{t:n}=se(),[o,i]=M.useState(!1),l=e.metadata??null,[f,u]=M.useState(l),d=M.useId(),h=q(U=>U.setKeyingTarget),g=q(U=>U.setCuratorTarget),r=M.useCallback(()=>t(),[t]),v=pe(!0,r),a=e.mediaType==="video",m=e.kind!=="edit"&&!!e.filename,E=l??f,y=typeof E?.spriteRunId=="string"?E.spriteRunId:null,R=typeof E?.manifestPath=="string"?E.manifestPath:null,K=!!(y&&R&&e.filename),P=n(a?"assetGen.videoFallback":"assetGen.imageFallback"),x=e.prompt?.trim()||P,L=M.useCallback(()=>{h(e),t()},[e,t,h]),T=M.useCallback(()=>{!y||!R||!e.filename||(g({runId:y,atlasFile:e.filename,manifestFile:R}),t())},[e.filename,R,t,g,y]);return M.useEffect(()=>{u(l);const U=e.requestId?.startsWith("asset:")?e.requestId.slice(6):null;if(!U||l)return;let B=!0;return he(U).then(({asset:S})=>{B&&u(S.metadata)}).catch(()=>{B&&u(null)}),()=>{B=!1}},[l,e.requestId]),M.useEffect(()=>{const U=document.body.style.overflow,B=document.documentElement.style.overflow;return document.body.style.overflow="hidden",document.documentElement.style.overflow="hidden",()=>{document.body.style.overflow=U,document.documentElement.style.overflow=B}},[]),s.jsxs("div",{className:"assetgen-lightbox",role:"presentation",children:[s.jsx("button",{type:"button",className:"assetgen-lightbox__backdrop","aria-label":n("assetGen.closePreview"),onClick:r}),s.jsxs("section",{ref:v,className:"assetgen-lightbox__panel",role:"dialog","aria-modal":"true","aria-labelledby":d,children:[s.jsxs("header",{className:"assetgen-lightbox__header",children:[s.jsx("h2",{id:d,children:n("assetGen.previewDialogTitle",{prompt:x})}),s.jsx("button",{type:"button",className:"assetgen-lightbox__control","aria-label":n("assetGen.closePreview"),onClick:r,children:s.jsx(ye,{})})]}),s.jsx("div",{className:["assetgen-lightbox__stage",e.kind==="edit"?"is-keyed":"",o?"is-zoomed":""].filter(Boolean).join(" "),tabIndex:o?0:void 0,children:a?s.jsx("video",{src:e.url||e.image,poster:e.thumb||void 0,controls:!0,autoPlay:!0,muted:!0,playsInline:!0,preload:"metadata","aria-label":x}):s.jsx("img",{src:e.url||e.image,alt:x})}),!a||m||K?s.jsxs("footer",{className:"assetgen-lightbox__footer",children:[K?s.jsx("button",{type:"button",className:"assetgen-lightbox__zoom assetgen-lightbox__curate",onClick:T,children:n("spriteCurator.open")}):null,m?s.jsx("button",{type:"button",className:"assetgen-lightbox__zoom assetgen-lightbox__keybtn",onClick:L,children:n("keying.open")}):null,a?null:s.jsxs("button",{type:"button",className:"assetgen-lightbox__zoom","aria-pressed":o,"aria-label":n(o?"assetGen.zoomOut":"assetGen.zoomIn"),onClick:()=>i(U=>!U),children:[s.jsx(xe,{zoomed:o}),s.jsx("span",{children:n(o?"assetGen.zoomOut":"assetGen.zoomIn")})]})]}):null]})]})}const H={tolerance:40,softness:10,spill:50};function ee(e,t,n){const o=128-.168736*e-.331264*t+.5*n,i=128+.5*e-.418688*t-.081312*n;return[o,i]}function te(e,t,n){return .299*e+.587*t+.114*n}function ke(e,t,n,o){const i=t*n,l=new Uint8Array(i);for(let r=0;r<i;r++)e[r]<o&&(l[r]=1);const f=new Uint8Array(i),u=new Int32Array(i);let d=0,h=0;const g=r=>{l[r]&&!f[r]&&(f[r]=1,u[h++]=r)};for(let r=0;r<t;r++)g(r),g((n-1)*t+r);for(let r=0;r<n;r++)g(r*t),g(r*t+t-1);for(;d<h;){const r=u[d++],v=r%t,a=(r-v)/t;v>0&&g(r-1),v<t-1&&g(r+1),a>0&&g(r-t),a<n-1&&g(r+t)}for(let r=0;r<i;r++)l[r]&&!f[r]&&(e[r]=o)}function ne(e){const{width:t,height:n,data:o}=e;if(t<2||n<2||o.length<t*n*4)throw new Error("colorKey: image too small or malformed pixel buffer");const i=4,l=[0,Math.max(0,t-i)],f=[0,Math.max(0,n-i)],u=[],d=[],h=[];for(const r of l)for(const v of f)for(let a=v;a<Math.min(v+i,n);a++)for(let m=r;m<Math.min(r+i,t);m++){const E=(a*t+m)*4;u.push(o[E]),d.push(o[E+1]),h.push(o[E+2])}const g=r=>{const v=[...r].sort((a,m)=>a-m);return v[Math.floor(v.length/2)]};return{r:g(u),g:g(d),b:g(h)}}function be(e,t){const{width:n,height:o,data:i}=e;if(!n||!o||i.length!==n*o*4)throw new Error("colorKey: empty or malformed pixel buffer");const l=Math.max(0,Math.min(100,t.tolerance)),f=Math.max(0,Math.min(50,t.softness)),u=Math.max(0,Math.min(100,t.spill))/100,d=l/100*120,h=d+f/100*120,[g,r]=ee(t.keyColor.r,t.keyColor.g,t.keyColor.b),v=t.keyColor.r,a=t.keyColor.g,m=t.keyColor.b,E=a>v+20&&a>m+20&&a>60,R=Math.max(v,a,m)-Math.min(v,a,m)<40,K=te(v,a,m),P=10+l/100*15,x=400,L=n*o,T=new Float32Array(L);for(let b=0;b<L;b++){const k=b*4,_=i[k],A=i[k+1],I=i[k+2],[F,C]=ee(_,A,I),w=Math.hypot(F-g,C-r);if(R)if(w>P)T[b]=x;else{const N=Math.abs(te(_,A,I)-K)*.8;T[b]=Math.hypot(w,N)}else T[b]=w}const U=new Float32Array(L);for(let b=0;b<o;b++)for(let k=0;k<n;k++){const _=b*n+k;if(T[_]>=x){U[_]=x;continue}let A=0,I=0;for(let F=-1;F<=1;F++){const C=b+F;if(!(C<0||C>=o))for(let w=-1;w<=1;w++){const N=k+w;if(N<0||N>=n)continue;const G=T[C*n+N];G>=x||(A+=G,I++)}}U[_]=I>0?A/I:x}R&&ke(U,n,o,h);const B=h+u*120,S=new Uint8ClampedArray(i.length);for(let b=0;b<L;b++){const k=b*4,_=i[k],A=i[k+1],I=i[k+2],F=i[k+3],C=U[b];let w;C<=d?w=0:C<h?w=Math.pow((C-d)/(h-d),1.5)*255:w=255;let N=_,G=A,$=I;if(E&&u>0&&w>0){const W=B>d?Math.max(0,1-(C-d)/(B-d)):0;if(W>0){const X=(_+I)/2,p=Math.max(0,A-X)*W*u;G=Math.round(A-p);const j=p*.3;N=Math.min(255,Math.round(_+j)),$=Math.min(255,Math.round(I+j))}}S[k]=N,S[k+1]=G,S[k+2]=$,S[k+3]=Math.min(F,Math.round(w))}if(E&&u>0){let b=new Uint8Array(L);for(let k=0;k<o;k++)for(let _=0;_<n;_++){const A=k*n+_;if(S[A*4+3]===0)continue;let I=!1;e:for(let F=-1;F<=1;F++){const C=k+F;if(!(C<0||C>=o))for(let w=-1;w<=1;w++){const N=_+w;if(!(N<0||N>=n)&&S[(C*n+N)*4+3]===0){I=!0;break e}}}I&&(b[A]=1)}for(let k=0;k<3;k++){const _=new Uint8Array(L);for(let A=0;A<o;A++)for(let I=0;I<n;I++){const F=A*n+I;if(b[F]){_[F]=1;continue}if(S[F*4+3]===0)continue;let C=!1;for(let w=-1;w<=1&&!C;w++){const N=A+w;if(!(N<0||N>=o))for(let G=-1;G<=1&&!C;G++){const $=I+G;$<0||$>=n||b[N*n+$]&&(C=!0)}}C&&(_[F]=1)}b=_}for(let k=0;k<L;k++){if(!b[k])continue;const _=k*4,A=S[_],I=S[_+1],F=S[_+2],C=Math.max(A,F);if(I>C-8){const w=Math.max(0,C-4),N=Math.max(0,I-w);S[_+1]=Math.max(0,I-N),S[_]=Math.min(255,A+Math.round(N*.25)),S[_+2]=Math.min(255,F+Math.round(N*.25))}}}return{width:n,height:o,data:S}}function _e(e){return Math.round(Math.max(0,Math.min(100,e))*.7)}function oe(e,t,n){const o=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+o}function ve(e,t,n,o){for(const i of n)if(Math.max(Math.abs(e[t]-i.r),Math.abs(e[t+1]-i.g),Math.abs(e[t+2]-i.b))<=o)return!0;return!1}function Me(e,t,n){const{width:o,height:i,data:l}=e,f=o*i,u=new Uint8Array(f),d=new Uint8Array(f),h=new Int32Array(f),g=t.map(a=>{const m=oe(a,o,i)*4;return{r:l[m],g:l[m+1],b:l[m+2]}});let r=0;const v=a=>{d[a]||(d[a]=1,l[a*4+3]!==0&&ve(l,a*4,g,n)&&(h[r++]=a))};for(const a of t)v(oe(a,o,i));for(;r>0;){const a=h[--r];u[a]=1;const m=a%o;m>0&&v(a-1),m<o-1&&v(a+1),a>=o&&v(a-o),a<f-o&&v(a+o)}return u}function we(e,t,n,o){if(n.length===0)return;if(e.width!==t.width||e.height!==t.height||e.data.length!==t.data.length)throw new Error("wandErase: target/source buffer size mismatch");const i=Me(t,n,_e(o));for(let l=0;l<i.length;l++)i[l]&&(e.data[l*4+3]=0)}const je={reach:4,spillMaxFraction:.005},re=18,Ce=180,Ne=40,Ee=2,J=0,Se=1,ie=2,le=3;function Q(e){const t=[e.r,e.g,e.b],n=[],o=[];for(let i=0;i<3;i++)if(t[i]>=192)n.push(i);else if(t[i]<64)o.push(i);else return null;return n.length===0||o.length===0?null:{keyed:n,unkeyed:o}}function V(e,t,n,o){const i=[e,t,n];let l=0;for(const u of o.keyed)l+=i[u];let f=0;for(const u of o.unkeyed)f+=i[u];return l/o.keyed.length-f/o.unkeyed.length}function Ae(e,t,n,o){return Math.hypot(e-o.r,t-o.g,n-o.b)}function ce(e,t,n,o,i,l){const f=Math.min(l/i,1),u=1-f;if(u<=0)return[0,0,0,0];const d=(h,g)=>Math.min(255,Math.max(0,Math.round((h-f*g)/u)));return[u,d(e,o.r),d(t,o.g),d(n,o.b)]}function Ie(e,t,n,o){const i=t*n,l=255,f=new Uint8Array(i).fill(l);let u=[];for(let h=0;h<i;h++)e[h]&&(f[h]=0,u.push(h));let d=0;for(;u.length>0&&d<o;){d++;const h=[];for(const g of u){const r=g%t,v=(g-r)/t;for(let a=-1;a<=1;a++){const m=v+a;if(!(m<0||m>=n))for(let E=-1;E<=1;E++){const y=r+E;if(y<0||y>=t)continue;const R=m*t+y;f[R]===l&&(f[R]=d,h.push(R))}}}u=h}return f}function Re(e,t,n,o){const i=e.width*e.height,l=new Uint8Array(i),f=new Uint8Array(i);for(let u=0;u<i;u++){const d=u*4;if(t.data[d+3]===0){l[u]=J,f[u]=1;continue}const h=e.data[d],g=e.data[d+1],r=e.data[d+2];V(h,g,r,o)<re?l[u]=Se:Ae(h,g,r,n)<=Ce?l[u]=ie:l[u]=le}return{classes:l,keyedMask:f}}function Ue(e,t,n,o,i,l,f,u){const d=t.width*t.height,h=new Uint8Array(d);for(let g=0;g<d;g++){const r=l[g];if(!(r>0&&r<=u))continue;const v=f[g];if(v===ie){if(r>Ee)continue}else if(v!==le)continue;const a=g*4,m=t.data[a],E=t.data[a+1],y=t.data[a+2],R=V(m,E,y,o),[K,P,x,L]=ce(m,E,y,n,i,R),T=Math.round(t.data[a+3]*K);T<=0?(e.data[a]=0,e.data[a+1]=0,e.data[a+2]=0,e.data[a+3]=0):(e.data[a]=P,e.data[a+1]=x,e.data[a+2]=L,e.data[a+3]=T),h[g]=1}return h}function Te(e,t,n,o,i,l,f,u){const{width:d,height:h}=t,g=d*h;let r=0;for(let y=0;y<g;y++)l[y]!==J&&r++;const v=Math.max(32,Math.round(r*u)),a=new Float32Array(g).fill(-1);for(let y=0;y<g;y++){if(f[y]||l[y]===J)continue;const R=y*4;if(e.data[R+3]===0)continue;const K=V(t.data[R],t.data[R+1],t.data[R+2],o);K>=re&&(a[y]=K)}const m=new Uint8Array(g),E=[];for(let y=0;y<g;y++){if(a[y]<0||m[y])continue;m[y]=1,E.length=0,E.push(y);const R=[];let K=-1;for(;E.length>0;){const P=E.pop();R.push(P),a[P]>K&&(K=a[P]);const x=P%d,L=(P-x)/d;for(let T=-1;T<=1;T++){const U=L+T;if(!(U<0||U>=h))for(let B=-1;B<=1;B++){const S=x+B;if(S<0||S>=d)continue;const b=U*d+S;a[b]>=0&&!m[b]&&(m[b]=1,E.push(b))}}}if(!(R.length>v)&&!(K<=Ne))for(const P of R){const x=P*4,L=t.data[x],T=t.data[x+1],U=t.data[x+2],[B,S,b,k]=ce(L,T,U,n,i,a[P]);B<=0||(e.data[x]=S,e.data[x+1]=b,e.data[x+2]=k)}}}function De(e,t,n){if(!e.width||!e.height||e.width!==t.width||e.height!==t.height||e.data.length!==t.data.length||e.data.length!==e.width*e.height*4)throw new Error("softUnmix: empty or mismatched pixel buffers");const o=Q(n.keyColor);if(!o)return;const i=V(n.keyColor.r,n.keyColor.g,n.keyColor.b,o);if(i<=0)return;const l=Math.max(0,Math.min(254,Math.round(n.reach))),{classes:f,keyedMask:u}=Re(t,e,n.keyColor,o);let d;if(l>0){const h=Ie(u,t.width,t.height,l);d=Ue(e,t,n.keyColor,o,i,h,f,l)}else d=new Uint8Array(t.width*t.height);n.spillMaxFraction>0&&Te(e,t,n.keyColor,o,i,f,d,n.spillMaxFraction)}function ae(e,t,n){const o=`/generated/${encodeURIComponent(t)}`;return{...e,image:o,url:o,filename:t,mediaType:n,kind:"edit",requestId:`derived:${t}`,createdAt:Date.now(),providerUrl:null}}function Be(){const{t:e}=se(),t=q(c=>c.keyingTarget),n=q(c=>c.setKeyingTarget),o=q(c=>c.addAssetGenDerivedItem),i=q(c=>c.selectedProjectId),l=q(c=>c.showToast),[f,u]=M.useState("loading"),[d,h]=M.useState(!1),[g,r]=M.useState(null),[v,a]=M.useState(null),[m,E]=M.useState(H.tolerance),[y,R]=M.useState(H.softness),[K,P]=M.useState(H.spill),[x,L]=M.useState(null),[T,U]=M.useState("erase"),[B,S]=M.useState([]),[b,k]=M.useState(!0),_=M.useRef(null),A=M.useRef(null),I=M.useRef(0),F=M.useRef(null),C=M.useRef(null),w=M.useCallback(()=>{F.current?.(),F.current=null},[]),N=t?.mediaType==="video",G=t?N&&t.filename?`/api/video/frame?file=${encodeURIComponent(t.filename)}&position=0`:t.url||t.image:null;M.useEffect(()=>{if(!G)return;let c=!0;u("loading"),_.current=null,L(null),S([]),U("erase");const p=new Image;return p.onload=()=>{if(c)try{const j=document.createElement("canvas");j.width=p.naturalWidth,j.height=p.naturalHeight;const D=j.getContext("2d");if(!D)throw new Error("no 2d context");D.drawImage(p,0,0);const O=D.getImageData(0,0,j.width,j.height);_.current=O,L(ne(O)),u("ready")}catch{c&&u("error")}},p.onerror=()=>{c&&u("error")},p.src=G,()=>{c=!1,p.onload=null,p.onerror=null}},[G]),M.useEffect(()=>(C.current=t?.filename??null,w(),h(!1),a(null),r(null),w),[w,t?.filename]),M.useEffect(()=>{if(!(f!=="ready"||!x))return cancelAnimationFrame(I.current),I.current=requestAnimationFrame(()=>{const c=_.current,p=A.current;if(!(!c||!p))try{const j=be({width:c.width,height:c.height,data:c.data},{keyColor:x,tolerance:m,softness:y,spill:K});b&&Q(x)&&De(j,{width:c.width,height:c.height,data:c.data},{keyColor:x,...je}),B.length>0&&we(j,{width:c.width,height:c.height,data:c.data},B,m),p.width=j.width,p.height=j.height;const D=p.getContext("2d");if(!D)return;const O=D.createImageData(j.width,j.height);O.data.set(j.data),D.putImageData(O,0,0)}catch{u("error")}}),()=>cancelAnimationFrame(I.current)},[f,x,m,y,K,B,b]);const $=M.useCallback(c=>{const p=_.current,j=A.current;if(!p||!j)return;const D=j.getBoundingClientRect(),O=Math.max(0,Math.min(1,(c.clientX-D.left)/D.width)),Y=Math.max(0,Math.min(1,(c.clientY-D.top)/D.height));if(T==="erase"&&!N){S(de=>[...de,{x:O,y:Y}]);return}const z=Math.floor((c.clientX-D.left)/D.width*p.width),ue=Math.floor((c.clientY-D.top)/D.height*p.height),Z=(Math.max(0,Math.min(p.height-1,ue))*p.width+Math.max(0,Math.min(p.width-1,z)))*4;L({r:p.data[Z],g:p.data[Z+1],b:p.data[Z+2]})},[T,N]),W=M.useCallback(()=>{const c=A.current;c&&c.toBlob(p=>{if(!p)return;const j=URL.createObjectURL(p),D=document.createElement("a");D.href=j,D.download=`${(t?.filename||"asset").replace(/\.[a-z]+$/i,"")}-keyed.png`,D.click(),URL.revokeObjectURL(j)},"image/png")},[t]),X=M.useCallback(()=>{const c=A.current;if(!(!c||!t?.filename||d)){if(h(!0),r(null),N){fe({source:t.filename,keyParams:{tolerance:m,softness:y,keyColor:x??void 0},projectId:i,name:`${(t.prompt||"asset").trim().slice(0,60)} (keyed)`}).then(({requestId:p})=>{if(C.current!==t.filename)return;a(0),w();const j=ge(p,null,(D,O)=>{const Y=O&&typeof O=="object"?O:{};if(D==="keying-progress"){const z=Y.outTimeMs;a(typeof z=="number"&&Number.isFinite(z)?z:0)}else if(D==="keying-done"){w();const z=Y.filePath;if(typeof z=="string"&&z.trim()){o(ae(t,z.trim(),"video")),h(!1),a(null),l(e("keying.videoSaved")),n(null);return}h(!1),a(null),r(e("keying.saveError"))}else D==="keying-error"&&(w(),h(!1),a(null),r(typeof Y.error=="string"&&Y.error?Y.error:e("keying.saveError")))});F.current=j}).catch(p=>{C.current===t.filename&&(h(!1),r(p instanceof Error?p.message:e("keying.saveError")))});return}c.toBlob(p=>{if(C.current===t.filename){if(!p){h(!1),r(e("keying.saveError"));return}me(p,{source:t.filename,projectId:i,name:`${(t.prompt||"asset").trim().slice(0,60)} (keyed)`,meta:{keyParams:{tolerance:m,softness:y,spill:K},prompt:t.prompt}}).then(({filePath:j})=>{if(C.current===t.filename){if(typeof j!="string"||!j.trim())throw new Error(e("keying.saveError"));o(ae(t,j.trim(),"image")),l(e("keying.saved")),n(null)}}).catch(j=>{C.current===t.filename&&r(j instanceof Error?j.message:e("keying.saveError"))}).finally(()=>{C.current===t.filename&&h(!1)})}},"image/png")}},[t,d,N,x,i,m,y,K,w,o,l,n,e]);return M.useEffect(()=>{const c=p=>{p.key==="Escape"&&n(null)};return window.addEventListener("keydown",c),()=>window.removeEventListener("keydown",c)},[n]),t?s.jsx("div",{className:"assetgen-popup-backdrop",onClick:()=>n(null),children:s.jsxs("div",{className:"keying-panel",role:"dialog","aria-modal":"true","aria-label":e("keying.title"),onClick:c=>c.stopPropagation(),children:[s.jsxs("header",{className:"keying-panel__head",children:[s.jsx("h2",{children:e("keying.title")}),x?s.jsxs("span",{className:"keying-panel__key",title:e("keying.keyColor"),children:[N?null:s.jsxs("span",{className:"keying-panel__modes",role:"group","aria-label":e("keying.clickMode"),children:[s.jsx("button",{type:"button",className:T==="erase"?"is-active":"","aria-pressed":T==="erase",onClick:()=>U("erase"),children:e("keying.modeErase")}),s.jsx("button",{type:"button",className:T==="pick"?"is-active":"","aria-pressed":T==="pick",onClick:()=>U("pick"),children:e("keying.modePick")})]}),B.length>0?s.jsx("button",{type:"button",className:"keying-panel__undo",onClick:()=>S(c=>c.slice(0,-1)),children:e("keying.undoClick",{count:String(B.length)})}):null,s.jsx("span",{className:"assetgen-bg-picker__swatch",style:{background:`rgb(${x.r},${x.g},${x.b})`},"aria-hidden":"true"}),s.jsx("span",{className:"keying-panel__hint",children:e(T==="erase"&&!N?"keying.eraseHint":"keying.pickHint")})]}):null]}),s.jsx("div",{className:"keying-panel__compare","aria-busy":f==="loading",children:f==="error"?s.jsxs("div",{className:"keying-panel__error",role:"alert",children:[s.jsx("p",{children:e("keying.loadError")}),s.jsx("button",{type:"button",onClick:()=>n(null),children:e("project.close")})]}):s.jsxs(s.Fragment,{children:[s.jsxs("figure",{className:"keying-panel__preview",children:[s.jsx("figcaption",{className:"keying-panel__preview-label",children:e("keying.original")}),s.jsx("div",{className:"keying-panel__stage keying-panel__stage--original",children:s.jsx("img",{src:G??"",alt:e("keying.originalAlt")})})]}),s.jsxs("figure",{className:"keying-panel__preview",children:[s.jsx("figcaption",{className:"keying-panel__preview-label",children:e("keying.removed")}),s.jsxs("div",{className:"keying-panel__stage",children:[s.jsx("canvas",{ref:A,className:"keying-panel__canvas",onClick:$,"aria-label":e("keying.previewAlt")}),f==="loading"?s.jsx("span",{className:"keying-panel__loading",role:"status",children:e("keying.previewLoading")}):null]})]})]})}),s.jsxs("details",{className:"keying-panel__advanced",children:[s.jsx("summary",{children:e("keying.advanced")}),s.jsxs("div",{className:"keying-panel__controls",children:[s.jsxs("label",{children:[e("keying.tolerance")," ",s.jsx("output",{children:m}),s.jsx("input",{type:"range",min:0,max:100,value:m,onChange:c=>E(Number(c.target.value))})]}),s.jsxs("label",{children:[e("keying.softness")," ",s.jsx("output",{children:y}),s.jsx("input",{type:"range",min:0,max:50,value:y,onChange:c=>R(Number(c.target.value))})]}),s.jsxs("label",{children:[e("keying.spill")," ",s.jsx("output",{children:K}),s.jsx("input",{type:"range",min:0,max:100,value:K,onChange:c=>P(Number(c.target.value))})]}),s.jsxs("label",{className:"keying-panel__unmix",children:[s.jsx("input",{type:"checkbox",checked:b,disabled:!x||!Q(x),onChange:c=>k(c.target.checked)}),e("keying.unmix"),s.jsx("span",{className:"keying-panel__hint",children:e("keying.unmixHint")})]}),s.jsx("button",{type:"button",className:"keying-panel__reset",onClick:()=>{E(H.tolerance),R(H.softness),P(H.spill),S([]),k(!0),_.current&&L(ne(_.current))},children:e("keying.reset")})]})]}),s.jsxs("footer",{className:"keying-panel__actions",children:[g?s.jsx("span",{className:"keying-panel__save-error",role:"alert",children:g}):null,s.jsx("button",{type:"button",className:"assetgen-generate",disabled:f!=="ready"||d||!t.filename,onClick:X,children:d?v!==null?e("keying.videoKeying",{seconds:String(Math.round(v/1e3))}):e("keying.saving"):e(N?"keying.videoSave":"keying.save")}),N?null:s.jsx("button",{type:"button",className:"assetgen-popup__close",disabled:f!=="ready",onClick:W,children:e("keying.download")}),s.jsx("button",{type:"button",className:"assetgen-popup__close",onClick:()=>n(null),children:e("project.close")})]})]})}):null}export{Le as A,Be as K};
1
+ import{u as se,a as M,b as q,p as he,j as s,ab as fe,ac as ge,ad as me}from"./index-Bj2sxDP3.js";import{u as pe}from"./useAgentDialogFocus-BB6ds9jo.js";function ye(){return s.jsx("svg",{viewBox:"0 0 24 24",width:"18",height:"18","aria-hidden":"true",children:s.jsx("path",{d:"M6 6l12 12M18 6 6 18",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round"})})}function xe({zoomed:e}){return s.jsxs("svg",{viewBox:"0 0 24 24",width:"18",height:"18","aria-hidden":"true",children:[s.jsx("circle",{cx:"10.5",cy:"10.5",r:"6.5",fill:"none",stroke:"currentColor",strokeWidth:"1.7"}),s.jsx("path",{d:"M15.5 15.5 21 21M7.5 10.5h6",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round"}),e?null:s.jsx("path",{d:"M10.5 7.5v6",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round"})]})}function Le({item:e,onClose:t}){const{t:n}=se(),[o,i]=M.useState(!1),l=e.metadata??null,[f,u]=M.useState(l),d=M.useId(),h=q(U=>U.setKeyingTarget),g=q(U=>U.setCuratorTarget),r=M.useCallback(()=>t(),[t]),v=pe(!0,r),a=e.mediaType==="video",m=e.kind!=="edit"&&!!e.filename,E=l??f,y=typeof E?.spriteRunId=="string"?E.spriteRunId:null,R=typeof E?.manifestPath=="string"?E.manifestPath:null,K=!!(y&&R&&e.filename),P=n(a?"assetGen.videoFallback":"assetGen.imageFallback"),x=e.prompt?.trim()||P,L=M.useCallback(()=>{h(e),t()},[e,t,h]),T=M.useCallback(()=>{!y||!R||!e.filename||(g({runId:y,atlasFile:e.filename,manifestFile:R}),t())},[e.filename,R,t,g,y]);return M.useEffect(()=>{u(l);const U=e.requestId?.startsWith("asset:")?e.requestId.slice(6):null;if(!U||l)return;let B=!0;return he(U).then(({asset:S})=>{B&&u(S.metadata)}).catch(()=>{B&&u(null)}),()=>{B=!1}},[l,e.requestId]),M.useEffect(()=>{const U=document.body.style.overflow,B=document.documentElement.style.overflow;return document.body.style.overflow="hidden",document.documentElement.style.overflow="hidden",()=>{document.body.style.overflow=U,document.documentElement.style.overflow=B}},[]),s.jsxs("div",{className:"assetgen-lightbox",role:"presentation",children:[s.jsx("button",{type:"button",className:"assetgen-lightbox__backdrop","aria-label":n("assetGen.closePreview"),onClick:r}),s.jsxs("section",{ref:v,className:"assetgen-lightbox__panel",role:"dialog","aria-modal":"true","aria-labelledby":d,children:[s.jsxs("header",{className:"assetgen-lightbox__header",children:[s.jsx("h2",{id:d,children:n("assetGen.previewDialogTitle",{prompt:x})}),s.jsx("button",{type:"button",className:"assetgen-lightbox__control","aria-label":n("assetGen.closePreview"),onClick:r,children:s.jsx(ye,{})})]}),s.jsx("div",{className:["assetgen-lightbox__stage",e.kind==="edit"?"is-keyed":"",o?"is-zoomed":""].filter(Boolean).join(" "),tabIndex:o?0:void 0,children:a?s.jsx("video",{src:e.url||e.image,poster:e.thumb||void 0,controls:!0,autoPlay:!0,muted:!0,playsInline:!0,preload:"metadata","aria-label":x}):s.jsx("img",{src:e.url||e.image,alt:x})}),!a||m||K?s.jsxs("footer",{className:"assetgen-lightbox__footer",children:[K?s.jsx("button",{type:"button",className:"assetgen-lightbox__zoom assetgen-lightbox__curate",onClick:T,children:n("spriteCurator.open")}):null,m?s.jsx("button",{type:"button",className:"assetgen-lightbox__zoom assetgen-lightbox__keybtn",onClick:L,children:n("keying.open")}):null,a?null:s.jsxs("button",{type:"button",className:"assetgen-lightbox__zoom","aria-pressed":o,"aria-label":n(o?"assetGen.zoomOut":"assetGen.zoomIn"),onClick:()=>i(U=>!U),children:[s.jsx(xe,{zoomed:o}),s.jsx("span",{children:n(o?"assetGen.zoomOut":"assetGen.zoomIn")})]})]}):null]})]})}const H={tolerance:40,softness:10,spill:50};function ee(e,t,n){const o=128-.168736*e-.331264*t+.5*n,i=128+.5*e-.418688*t-.081312*n;return[o,i]}function te(e,t,n){return .299*e+.587*t+.114*n}function ke(e,t,n,o){const i=t*n,l=new Uint8Array(i);for(let r=0;r<i;r++)e[r]<o&&(l[r]=1);const f=new Uint8Array(i),u=new Int32Array(i);let d=0,h=0;const g=r=>{l[r]&&!f[r]&&(f[r]=1,u[h++]=r)};for(let r=0;r<t;r++)g(r),g((n-1)*t+r);for(let r=0;r<n;r++)g(r*t),g(r*t+t-1);for(;d<h;){const r=u[d++],v=r%t,a=(r-v)/t;v>0&&g(r-1),v<t-1&&g(r+1),a>0&&g(r-t),a<n-1&&g(r+t)}for(let r=0;r<i;r++)l[r]&&!f[r]&&(e[r]=o)}function ne(e){const{width:t,height:n,data:o}=e;if(t<2||n<2||o.length<t*n*4)throw new Error("colorKey: image too small or malformed pixel buffer");const i=4,l=[0,Math.max(0,t-i)],f=[0,Math.max(0,n-i)],u=[],d=[],h=[];for(const r of l)for(const v of f)for(let a=v;a<Math.min(v+i,n);a++)for(let m=r;m<Math.min(r+i,t);m++){const E=(a*t+m)*4;u.push(o[E]),d.push(o[E+1]),h.push(o[E+2])}const g=r=>{const v=[...r].sort((a,m)=>a-m);return v[Math.floor(v.length/2)]};return{r:g(u),g:g(d),b:g(h)}}function be(e,t){const{width:n,height:o,data:i}=e;if(!n||!o||i.length!==n*o*4)throw new Error("colorKey: empty or malformed pixel buffer");const l=Math.max(0,Math.min(100,t.tolerance)),f=Math.max(0,Math.min(50,t.softness)),u=Math.max(0,Math.min(100,t.spill))/100,d=l/100*120,h=d+f/100*120,[g,r]=ee(t.keyColor.r,t.keyColor.g,t.keyColor.b),v=t.keyColor.r,a=t.keyColor.g,m=t.keyColor.b,E=a>v+20&&a>m+20&&a>60,R=Math.max(v,a,m)-Math.min(v,a,m)<40,K=te(v,a,m),P=10+l/100*15,x=400,L=n*o,T=new Float32Array(L);for(let b=0;b<L;b++){const k=b*4,_=i[k],A=i[k+1],I=i[k+2],[F,C]=ee(_,A,I),w=Math.hypot(F-g,C-r);if(R)if(w>P)T[b]=x;else{const N=Math.abs(te(_,A,I)-K)*.8;T[b]=Math.hypot(w,N)}else T[b]=w}const U=new Float32Array(L);for(let b=0;b<o;b++)for(let k=0;k<n;k++){const _=b*n+k;if(T[_]>=x){U[_]=x;continue}let A=0,I=0;for(let F=-1;F<=1;F++){const C=b+F;if(!(C<0||C>=o))for(let w=-1;w<=1;w++){const N=k+w;if(N<0||N>=n)continue;const G=T[C*n+N];G>=x||(A+=G,I++)}}U[_]=I>0?A/I:x}R&&ke(U,n,o,h);const B=h+u*120,S=new Uint8ClampedArray(i.length);for(let b=0;b<L;b++){const k=b*4,_=i[k],A=i[k+1],I=i[k+2],F=i[k+3],C=U[b];let w;C<=d?w=0:C<h?w=Math.pow((C-d)/(h-d),1.5)*255:w=255;let N=_,G=A,$=I;if(E&&u>0&&w>0){const W=B>d?Math.max(0,1-(C-d)/(B-d)):0;if(W>0){const X=(_+I)/2,p=Math.max(0,A-X)*W*u;G=Math.round(A-p);const j=p*.3;N=Math.min(255,Math.round(_+j)),$=Math.min(255,Math.round(I+j))}}S[k]=N,S[k+1]=G,S[k+2]=$,S[k+3]=Math.min(F,Math.round(w))}if(E&&u>0){let b=new Uint8Array(L);for(let k=0;k<o;k++)for(let _=0;_<n;_++){const A=k*n+_;if(S[A*4+3]===0)continue;let I=!1;e:for(let F=-1;F<=1;F++){const C=k+F;if(!(C<0||C>=o))for(let w=-1;w<=1;w++){const N=_+w;if(!(N<0||N>=n)&&S[(C*n+N)*4+3]===0){I=!0;break e}}}I&&(b[A]=1)}for(let k=0;k<3;k++){const _=new Uint8Array(L);for(let A=0;A<o;A++)for(let I=0;I<n;I++){const F=A*n+I;if(b[F]){_[F]=1;continue}if(S[F*4+3]===0)continue;let C=!1;for(let w=-1;w<=1&&!C;w++){const N=A+w;if(!(N<0||N>=o))for(let G=-1;G<=1&&!C;G++){const $=I+G;$<0||$>=n||b[N*n+$]&&(C=!0)}}C&&(_[F]=1)}b=_}for(let k=0;k<L;k++){if(!b[k])continue;const _=k*4,A=S[_],I=S[_+1],F=S[_+2],C=Math.max(A,F);if(I>C-8){const w=Math.max(0,C-4),N=Math.max(0,I-w);S[_+1]=Math.max(0,I-N),S[_]=Math.min(255,A+Math.round(N*.25)),S[_+2]=Math.min(255,F+Math.round(N*.25))}}}return{width:n,height:o,data:S}}function _e(e){return Math.round(Math.max(0,Math.min(100,e))*.7)}function oe(e,t,n){const o=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+o}function ve(e,t,n,o){for(const i of n)if(Math.max(Math.abs(e[t]-i.r),Math.abs(e[t+1]-i.g),Math.abs(e[t+2]-i.b))<=o)return!0;return!1}function Me(e,t,n){const{width:o,height:i,data:l}=e,f=o*i,u=new Uint8Array(f),d=new Uint8Array(f),h=new Int32Array(f),g=t.map(a=>{const m=oe(a,o,i)*4;return{r:l[m],g:l[m+1],b:l[m+2]}});let r=0;const v=a=>{d[a]||(d[a]=1,l[a*4+3]!==0&&ve(l,a*4,g,n)&&(h[r++]=a))};for(const a of t)v(oe(a,o,i));for(;r>0;){const a=h[--r];u[a]=1;const m=a%o;m>0&&v(a-1),m<o-1&&v(a+1),a>=o&&v(a-o),a<f-o&&v(a+o)}return u}function we(e,t,n,o){if(n.length===0)return;if(e.width!==t.width||e.height!==t.height||e.data.length!==t.data.length)throw new Error("wandErase: target/source buffer size mismatch");const i=Me(t,n,_e(o));for(let l=0;l<i.length;l++)i[l]&&(e.data[l*4+3]=0)}const je={reach:4,spillMaxFraction:.005},re=18,Ce=180,Ne=40,Ee=2,J=0,Se=1,ie=2,le=3;function Q(e){const t=[e.r,e.g,e.b],n=[],o=[];for(let i=0;i<3;i++)if(t[i]>=192)n.push(i);else if(t[i]<64)o.push(i);else return null;return n.length===0||o.length===0?null:{keyed:n,unkeyed:o}}function V(e,t,n,o){const i=[e,t,n];let l=0;for(const u of o.keyed)l+=i[u];let f=0;for(const u of o.unkeyed)f+=i[u];return l/o.keyed.length-f/o.unkeyed.length}function Ae(e,t,n,o){return Math.hypot(e-o.r,t-o.g,n-o.b)}function ce(e,t,n,o,i,l){const f=Math.min(l/i,1),u=1-f;if(u<=0)return[0,0,0,0];const d=(h,g)=>Math.min(255,Math.max(0,Math.round((h-f*g)/u)));return[u,d(e,o.r),d(t,o.g),d(n,o.b)]}function Ie(e,t,n,o){const i=t*n,l=255,f=new Uint8Array(i).fill(l);let u=[];for(let h=0;h<i;h++)e[h]&&(f[h]=0,u.push(h));let d=0;for(;u.length>0&&d<o;){d++;const h=[];for(const g of u){const r=g%t,v=(g-r)/t;for(let a=-1;a<=1;a++){const m=v+a;if(!(m<0||m>=n))for(let E=-1;E<=1;E++){const y=r+E;if(y<0||y>=t)continue;const R=m*t+y;f[R]===l&&(f[R]=d,h.push(R))}}}u=h}return f}function Re(e,t,n,o){const i=e.width*e.height,l=new Uint8Array(i),f=new Uint8Array(i);for(let u=0;u<i;u++){const d=u*4;if(t.data[d+3]===0){l[u]=J,f[u]=1;continue}const h=e.data[d],g=e.data[d+1],r=e.data[d+2];V(h,g,r,o)<re?l[u]=Se:Ae(h,g,r,n)<=Ce?l[u]=ie:l[u]=le}return{classes:l,keyedMask:f}}function Ue(e,t,n,o,i,l,f,u){const d=t.width*t.height,h=new Uint8Array(d);for(let g=0;g<d;g++){const r=l[g];if(!(r>0&&r<=u))continue;const v=f[g];if(v===ie){if(r>Ee)continue}else if(v!==le)continue;const a=g*4,m=t.data[a],E=t.data[a+1],y=t.data[a+2],R=V(m,E,y,o),[K,P,x,L]=ce(m,E,y,n,i,R),T=Math.round(t.data[a+3]*K);T<=0?(e.data[a]=0,e.data[a+1]=0,e.data[a+2]=0,e.data[a+3]=0):(e.data[a]=P,e.data[a+1]=x,e.data[a+2]=L,e.data[a+3]=T),h[g]=1}return h}function Te(e,t,n,o,i,l,f,u){const{width:d,height:h}=t,g=d*h;let r=0;for(let y=0;y<g;y++)l[y]!==J&&r++;const v=Math.max(32,Math.round(r*u)),a=new Float32Array(g).fill(-1);for(let y=0;y<g;y++){if(f[y]||l[y]===J)continue;const R=y*4;if(e.data[R+3]===0)continue;const K=V(t.data[R],t.data[R+1],t.data[R+2],o);K>=re&&(a[y]=K)}const m=new Uint8Array(g),E=[];for(let y=0;y<g;y++){if(a[y]<0||m[y])continue;m[y]=1,E.length=0,E.push(y);const R=[];let K=-1;for(;E.length>0;){const P=E.pop();R.push(P),a[P]>K&&(K=a[P]);const x=P%d,L=(P-x)/d;for(let T=-1;T<=1;T++){const U=L+T;if(!(U<0||U>=h))for(let B=-1;B<=1;B++){const S=x+B;if(S<0||S>=d)continue;const b=U*d+S;a[b]>=0&&!m[b]&&(m[b]=1,E.push(b))}}}if(!(R.length>v)&&!(K<=Ne))for(const P of R){const x=P*4,L=t.data[x],T=t.data[x+1],U=t.data[x+2],[B,S,b,k]=ce(L,T,U,n,i,a[P]);B<=0||(e.data[x]=S,e.data[x+1]=b,e.data[x+2]=k)}}}function De(e,t,n){if(!e.width||!e.height||e.width!==t.width||e.height!==t.height||e.data.length!==t.data.length||e.data.length!==e.width*e.height*4)throw new Error("softUnmix: empty or mismatched pixel buffers");const o=Q(n.keyColor);if(!o)return;const i=V(n.keyColor.r,n.keyColor.g,n.keyColor.b,o);if(i<=0)return;const l=Math.max(0,Math.min(254,Math.round(n.reach))),{classes:f,keyedMask:u}=Re(t,e,n.keyColor,o);let d;if(l>0){const h=Ie(u,t.width,t.height,l);d=Ue(e,t,n.keyColor,o,i,h,f,l)}else d=new Uint8Array(t.width*t.height);n.spillMaxFraction>0&&Te(e,t,n.keyColor,o,i,f,d,n.spillMaxFraction)}function ae(e,t,n){const o=`/generated/${encodeURIComponent(t)}`;return{...e,image:o,url:o,filename:t,mediaType:n,kind:"edit",requestId:`derived:${t}`,createdAt:Date.now(),providerUrl:null}}function Be(){const{t:e}=se(),t=q(c=>c.keyingTarget),n=q(c=>c.setKeyingTarget),o=q(c=>c.addAssetGenDerivedItem),i=q(c=>c.selectedProjectId),l=q(c=>c.showToast),[f,u]=M.useState("loading"),[d,h]=M.useState(!1),[g,r]=M.useState(null),[v,a]=M.useState(null),[m,E]=M.useState(H.tolerance),[y,R]=M.useState(H.softness),[K,P]=M.useState(H.spill),[x,L]=M.useState(null),[T,U]=M.useState("erase"),[B,S]=M.useState([]),[b,k]=M.useState(!0),_=M.useRef(null),A=M.useRef(null),I=M.useRef(0),F=M.useRef(null),C=M.useRef(null),w=M.useCallback(()=>{F.current?.(),F.current=null},[]),N=t?.mediaType==="video",G=t?N&&t.filename?`/api/video/frame?file=${encodeURIComponent(t.filename)}&position=0`:t.url||t.image:null;M.useEffect(()=>{if(!G)return;let c=!0;u("loading"),_.current=null,L(null),S([]),U("erase");const p=new Image;return p.onload=()=>{if(c)try{const j=document.createElement("canvas");j.width=p.naturalWidth,j.height=p.naturalHeight;const D=j.getContext("2d");if(!D)throw new Error("no 2d context");D.drawImage(p,0,0);const O=D.getImageData(0,0,j.width,j.height);_.current=O,L(ne(O)),u("ready")}catch{c&&u("error")}},p.onerror=()=>{c&&u("error")},p.src=G,()=>{c=!1,p.onload=null,p.onerror=null}},[G]),M.useEffect(()=>(C.current=t?.filename??null,w(),h(!1),a(null),r(null),w),[w,t?.filename]),M.useEffect(()=>{if(!(f!=="ready"||!x))return cancelAnimationFrame(I.current),I.current=requestAnimationFrame(()=>{const c=_.current,p=A.current;if(!(!c||!p))try{const j=be({width:c.width,height:c.height,data:c.data},{keyColor:x,tolerance:m,softness:y,spill:K});b&&Q(x)&&De(j,{width:c.width,height:c.height,data:c.data},{keyColor:x,...je}),B.length>0&&we(j,{width:c.width,height:c.height,data:c.data},B,m),p.width=j.width,p.height=j.height;const D=p.getContext("2d");if(!D)return;const O=D.createImageData(j.width,j.height);O.data.set(j.data),D.putImageData(O,0,0)}catch{u("error")}}),()=>cancelAnimationFrame(I.current)},[f,x,m,y,K,B,b]);const $=M.useCallback(c=>{const p=_.current,j=A.current;if(!p||!j)return;const D=j.getBoundingClientRect(),O=Math.max(0,Math.min(1,(c.clientX-D.left)/D.width)),Y=Math.max(0,Math.min(1,(c.clientY-D.top)/D.height));if(T==="erase"&&!N){S(de=>[...de,{x:O,y:Y}]);return}const z=Math.floor((c.clientX-D.left)/D.width*p.width),ue=Math.floor((c.clientY-D.top)/D.height*p.height),Z=(Math.max(0,Math.min(p.height-1,ue))*p.width+Math.max(0,Math.min(p.width-1,z)))*4;L({r:p.data[Z],g:p.data[Z+1],b:p.data[Z+2]})},[T,N]),W=M.useCallback(()=>{const c=A.current;c&&c.toBlob(p=>{if(!p)return;const j=URL.createObjectURL(p),D=document.createElement("a");D.href=j,D.download=`${(t?.filename||"asset").replace(/\.[a-z]+$/i,"")}-keyed.png`,D.click(),URL.revokeObjectURL(j)},"image/png")},[t]),X=M.useCallback(()=>{const c=A.current;if(!(!c||!t?.filename||d)){if(h(!0),r(null),N){fe({source:t.filename,keyParams:{tolerance:m,softness:y,keyColor:x??void 0},projectId:i,name:`${(t.prompt||"asset").trim().slice(0,60)} (keyed)`}).then(({requestId:p})=>{if(C.current!==t.filename)return;a(0),w();const j=ge(p,null,(D,O)=>{const Y=O&&typeof O=="object"?O:{};if(D==="keying-progress"){const z=Y.outTimeMs;a(typeof z=="number"&&Number.isFinite(z)?z:0)}else if(D==="keying-done"){w();const z=Y.filePath;if(typeof z=="string"&&z.trim()){o(ae(t,z.trim(),"video")),h(!1),a(null),l(e("keying.videoSaved")),n(null);return}h(!1),a(null),r(e("keying.saveError"))}else D==="keying-error"&&(w(),h(!1),a(null),r(typeof Y.error=="string"&&Y.error?Y.error:e("keying.saveError")))});F.current=j}).catch(p=>{C.current===t.filename&&(h(!1),r(p instanceof Error?p.message:e("keying.saveError")))});return}c.toBlob(p=>{if(C.current===t.filename){if(!p){h(!1),r(e("keying.saveError"));return}me(p,{source:t.filename,projectId:i,name:`${(t.prompt||"asset").trim().slice(0,60)} (keyed)`,meta:{keyParams:{tolerance:m,softness:y,spill:K},prompt:t.prompt}}).then(({filePath:j})=>{if(C.current===t.filename){if(typeof j!="string"||!j.trim())throw new Error(e("keying.saveError"));o(ae(t,j.trim(),"image")),l(e("keying.saved")),n(null)}}).catch(j=>{C.current===t.filename&&r(j instanceof Error?j.message:e("keying.saveError"))}).finally(()=>{C.current===t.filename&&h(!1)})}},"image/png")}},[t,d,N,x,i,m,y,K,w,o,l,n,e]);return M.useEffect(()=>{const c=p=>{p.key==="Escape"&&n(null)};return window.addEventListener("keydown",c),()=>window.removeEventListener("keydown",c)},[n]),t?s.jsx("div",{className:"assetgen-popup-backdrop",onClick:()=>n(null),children:s.jsxs("div",{className:"keying-panel",role:"dialog","aria-modal":"true","aria-label":e("keying.title"),onClick:c=>c.stopPropagation(),children:[s.jsxs("header",{className:"keying-panel__head",children:[s.jsx("h2",{children:e("keying.title")}),x?s.jsxs("span",{className:"keying-panel__key",title:e("keying.keyColor"),children:[N?null:s.jsxs("span",{className:"keying-panel__modes",role:"group","aria-label":e("keying.clickMode"),children:[s.jsx("button",{type:"button",className:T==="erase"?"is-active":"","aria-pressed":T==="erase",onClick:()=>U("erase"),children:e("keying.modeErase")}),s.jsx("button",{type:"button",className:T==="pick"?"is-active":"","aria-pressed":T==="pick",onClick:()=>U("pick"),children:e("keying.modePick")})]}),B.length>0?s.jsx("button",{type:"button",className:"keying-panel__undo",onClick:()=>S(c=>c.slice(0,-1)),children:e("keying.undoClick",{count:String(B.length)})}):null,s.jsx("span",{className:"assetgen-bg-picker__swatch",style:{background:`rgb(${x.r},${x.g},${x.b})`},"aria-hidden":"true"}),s.jsx("span",{className:"keying-panel__hint",children:e(T==="erase"&&!N?"keying.eraseHint":"keying.pickHint")})]}):null]}),s.jsx("div",{className:"keying-panel__compare","aria-busy":f==="loading",children:f==="error"?s.jsxs("div",{className:"keying-panel__error",role:"alert",children:[s.jsx("p",{children:e("keying.loadError")}),s.jsx("button",{type:"button",onClick:()=>n(null),children:e("project.close")})]}):s.jsxs(s.Fragment,{children:[s.jsxs("figure",{className:"keying-panel__preview",children:[s.jsx("figcaption",{className:"keying-panel__preview-label",children:e("keying.original")}),s.jsx("div",{className:"keying-panel__stage keying-panel__stage--original",children:s.jsx("img",{src:G??"",alt:e("keying.originalAlt")})})]}),s.jsxs("figure",{className:"keying-panel__preview",children:[s.jsx("figcaption",{className:"keying-panel__preview-label",children:e("keying.removed")}),s.jsxs("div",{className:"keying-panel__stage",children:[s.jsx("canvas",{ref:A,className:"keying-panel__canvas",onClick:$,"aria-label":e("keying.previewAlt")}),f==="loading"?s.jsx("span",{className:"keying-panel__loading",role:"status",children:e("keying.previewLoading")}):null]})]})]})}),s.jsxs("details",{className:"keying-panel__advanced",children:[s.jsx("summary",{children:e("keying.advanced")}),s.jsxs("div",{className:"keying-panel__controls",children:[s.jsxs("label",{children:[e("keying.tolerance")," ",s.jsx("output",{children:m}),s.jsx("input",{type:"range",min:0,max:100,value:m,onChange:c=>E(Number(c.target.value))})]}),s.jsxs("label",{children:[e("keying.softness")," ",s.jsx("output",{children:y}),s.jsx("input",{type:"range",min:0,max:50,value:y,onChange:c=>R(Number(c.target.value))})]}),s.jsxs("label",{children:[e("keying.spill")," ",s.jsx("output",{children:K}),s.jsx("input",{type:"range",min:0,max:100,value:K,onChange:c=>P(Number(c.target.value))})]}),s.jsxs("label",{className:"keying-panel__unmix",children:[s.jsx("input",{type:"checkbox",checked:b,disabled:!x||!Q(x),onChange:c=>k(c.target.checked)}),e("keying.unmix"),s.jsx("span",{className:"keying-panel__hint",children:e("keying.unmixHint")})]}),s.jsx("button",{type:"button",className:"keying-panel__reset",onClick:()=>{E(H.tolerance),R(H.softness),P(H.spill),S([]),k(!0),_.current&&L(ne(_.current))},children:e("keying.reset")})]})]}),s.jsxs("footer",{className:"keying-panel__actions",children:[g?s.jsx("span",{className:"keying-panel__save-error",role:"alert",children:g}):null,s.jsx("button",{type:"button",className:"assetgen-generate",disabled:f!=="ready"||d||!t.filename,onClick:X,children:d?v!==null?e("keying.videoKeying",{seconds:String(Math.round(v/1e3))}):e("keying.saving"):e(N?"keying.videoSave":"keying.save")}),N?null:s.jsx("button",{type:"button",className:"assetgen-popup__close",disabled:f!=="ready",onClick:W,children:e("keying.download")}),s.jsx("button",{type:"button",className:"assetgen-popup__close",onClick:()=>n(null),children:e("project.close")})]})]})}):null}export{Le as A,Be as K};