ima2-gen 3.13.0 → 3.13.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/docs/migration/runtime-test-inventory.md +2 -1
- package/package.json +5 -2
- package/ui/dist/.vite/manifest.json +39 -39
- package/ui/dist/assets/{AgentWorkspace-CBwn1WUC.js → AgentWorkspace-PbBytTeV.js} +1 -1
- package/ui/dist/assets/{AssetGenWorkspace-CleWSwPz.js → AssetGenWorkspace-B-TGlvVb.js} +2 -2
- package/ui/dist/assets/{AssetsWorkspace-DdjXb45L.js → AssetsWorkspace-LnGaW151.js} +1 -1
- package/ui/dist/assets/{CardNewsWorkspace-BaNpBvJw.js → CardNewsWorkspace-BS3jKOja.js} +1 -1
- package/ui/dist/assets/{GenerationRequestLogPanel-Cd2ArsWr.js → GenerationRequestLogPanel-DuDWD_ic.js} +1 -1
- package/ui/dist/assets/{HomeWorkspace-nKDhivwR.js → HomeWorkspace-DVP7UG6O.js} +1 -1
- package/ui/dist/assets/{KeyingPanel-DT8zsqpi.js → KeyingPanel-5bRUFQaq.js} +1 -1
- package/ui/dist/assets/{NodeCanvas-DcKs0w36.js → NodeCanvas-BBEpERTb.js} +1 -1
- package/ui/dist/assets/{PromptBuilderPanel-e6BSRAdj.js → PromptBuilderPanel-D97A4pwB.js} +1 -1
- package/ui/dist/assets/{PromptImportDialog-CLkjHz7L.js → PromptImportDialog-C89MN5JY.js} +2 -2
- package/ui/dist/assets/{PromptImportDiscoverySection-DoQw4zcd.js → PromptImportDiscoverySection-BgRfDOs2.js} +1 -1
- package/ui/dist/assets/{PromptImportFolderSection-CcLiliAZ.js → PromptImportFolderSection-zTMyriT1.js} +1 -1
- package/ui/dist/assets/{PromptLibraryPanel-BjxzL7t5.js → PromptLibraryPanel-BD96qZu_.js} +2 -2
- package/ui/dist/assets/{SettingsWorkspace-Ctu_usKk.js → SettingsWorkspace-BAOk3X_8.js} +1 -1
- package/ui/dist/assets/{SpriteRecipeWorkspace-DZjsabce.js → SpriteRecipeWorkspace-ClIM5QRo.js} +1 -1
- package/ui/dist/assets/{index-ICf98ZcU.js → index-BFciPGTn.js} +3 -3
- package/ui/dist/assets/{index-DueH_AmZ.js → index-BbykeXR9.js} +17 -17
- package/ui/dist/assets/{pptxgen.es-C--aL3JM.js → pptxgen.es-D4pedbwM.js} +1 -1
- package/ui/dist/assets/{promptBuilderStore-CkwnWMbR.js → promptBuilderStore-Do7M8g7J.js} +1 -1
- package/ui/dist/assets/useAgentDialogFocus-B6-QgEVI.js +1 -0
- package/ui/dist/index.html +1 -1
- package/ui/dist/assets/useAgentDialogFocus-DPB8JITN.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{u as I,b as v,a as d,j as s,a1 as Q,a2 as q,m as de,a3 as ce,a4 as ue,a5 as me,a6 as he,o as pe,a7 as fe,a8 as ge,a9 as xe,aa as be,J as ve,t as je,q as ye,v as _e,ab as we,ac as ke,ad as Ne,p as Ae}from"./index-DueH_AmZ.js";import{K as Se,A as Ie}from"./KeyingPanel-DT8zsqpi.js";import"./useAgentDialogFocus-DPB8JITN.js";function Ce({folder:e,depth:a}){const{t:r}=I(),l=v(t=>t.assetsFilters.folderId),p=v(t=>t.setAssetsFilters),f=v(t=>t.renameAssetFolder),j=v(t=>t.deleteAssetFolder),o=v(t=>t.showToast),[i,g]=d.useState(!1),[_,h]=d.useState(e.name),[x,b]=d.useState(!1),k=l===e.id;async function m(){const t=_.trim();if(!t||t===e.name){h(e.name),g(!1);return}await f(e.id,t)||o(r("assets.actionFailed"),!0),g(!1)}async function u(){if(!x){b(!0);return}await j(e.id)||o(r("assets.actionFailed"),!0),b(!1)}return s.jsxs("div",{className:"assets-folder-row",style:{"--folder-depth":a},children:[i?s.jsx("input",{className:"assets-folder-input",value:_,autoFocus:!0,"aria-label":r("assets.renameFolder"),onChange:t=>h(t.target.value),onBlur:()=>{m()},onKeyDown:t=>{t.key==="Enter"&&m(),t.key==="Escape"&&(h(e.name),g(!1))}}):s.jsx("button",{type:"button",className:`assets-folder-row__name${k?" is-active":""}`,"aria-current":k?"page":void 0,onClick:()=>p({folderId:e.id,kind:null}),children:e.name}),!i&&s.jsxs("span",{className:"assets-folder-row__actions",children:[s.jsx("button",{type:"button","aria-label":r("assets.renameFolder"),onClick:()=>g(!0),children:s.jsx(Q,{})}),s.jsx("button",{type:"button","aria-label":r(x?"assets.confirmDelete":"assets.deleteFolder"),className:x?"is-danger is-armed":"",onClick:()=>{u()},children:x?r("assets.confirmDelete"):"×"})]})]})}function Fe(){const{t:e}=I(),a=v(m=>m.assetsFolders),r=v(m=>m.assetsFilters.folderId),l=v(m=>m.assetsFilters.kind),p=v(m=>m.setAssetsFilters),f=v(m=>m.createAssetFolder),j=v(m=>m.showToast),[o,i]=d.useState(!1),[g,_]=d.useState(""),h=r===null&&l!=="element",x=r===null&&l==="element",b=d.useMemo(()=>{const m=[],u=(t,c)=>a.filter(y=>y.parentId===t).forEach(y=>{m.push({folder:y,depth:c}),u(y.id,c+1)});return u(null,0),m},[a]);async function k(){const m=g.trim();if(!m){i(!1);return}await f(m,r)||j(e("assets.actionFailed"),!0),_(""),i(!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:()=>i(!0),children:"+"})]}),s.jsxs("div",{className:"assets-folders__rows",children:[s.jsx("button",{type:"button",className:`assets-folder-all${h?" is-active":""}`,"aria-current":h?"page":void 0,onClick:()=>p({folderId:null,kind:null}),children:e("assets.allAssets")}),s.jsxs("button",{type:"button",className:`assets-folder-all assets-folder-elements${x?" is-active":""}`,"aria-current":x?"page":void 0,onClick:()=>p({folderId:null,kind:"element"}),children:[s.jsx("span",{className:"assets-folder-elements__glyph","aria-hidden":"true",children:"@"}),e("assets.elementLibrary")]}),b.map(({folder:m,depth:u})=>s.jsx(Ce,{folder:m,depth:u},m.id)),o&&s.jsx("input",{className:"assets-folder-input assets-folder-input--new",value:g,autoFocus:!0,"aria-label":e("assets.newFolder"),placeholder:e("assets.newFolder"),onChange:m=>_(m.target.value),onBlur:()=>{g.trim()||i(!1)},onKeyDown:m=>{m.key==="Enter"&&k(),m.key==="Escape"&&(_(""),i(!1))}})]})]})}let T={status:"idle",elements:[]},D=null;const G=new Set;function M(e){T=e,G.forEach(a=>a())}function Te(e){return G.add(e),()=>G.delete(e)}function z(e=!1){return!e&&T.status==="ready"?Promise.resolve(!0):D||(M({...T,status:"loading"}),D=de().then(a=>(M({status:"ready",elements:a}),!0)).catch(a=>(console.error("[ElementMembership] load failed",a),M({...T,status:"error"}),!1)).finally(()=>{D=null}),D)}function Ee(e){const a=[e,...T.elements.filter(r=>r.id!==e.id)];M({status:"ready",elements:a})}function Y(e){M({status:"ready",elements:T.elements.filter(a=>a.id!==e)})}function Pe(e){e.stopPropagation()}function De(e){e.stopPropagation()}function Me(e){(e.key==="Enter"||e.key===" ")&&e.stopPropagation()}async function Re(e,a){if(a){await ce(a.id),Y(a.id);return}const{asset:r}=await ue({result:{filePath:e.filePath??void 0},sourceAssetId:e.id,elementKind:"character",name:e.name,notes:e.notes??void 0,folderId:e.folderId,tags:[me(e.id)]});Ee(r)}function O({active:e,busy:a,label:r,onToggle:l}){return s.jsx("button",{type:"button",className:`asset-element-toggle${e?" is-active":""}`,title:r,"aria-label":r,"aria-pressed":e,"aria-busy":a||void 0,disabled:a,onPointerDown:Pe,onDoubleClick:De,onKeyDown:Me,onClick:p=>{p.stopPropagation(),l()},children:s.jsx("span",{className:"asset-element-toggle__glyph","aria-hidden":"true",children:"@"})})}function $e({item:e}){const{t:a}=I(),r=v(b=>b.showToast),l=v(b=>b.deleteAssetItem),[p,f]=d.useState(!1),j=e.kind==="element",o=j||(e.kind==="image"||e.kind==="video")&&!!e.filePath,i=a("assets.elementLibrary"),g=d.useSyncExternalStore(Te,()=>T,()=>T),_=!j&&o?q(g.elements,e.id):null,h=p||g.status==="loading"||g.status==="idle";if(d.useEffect(()=>{o&&!j&&z()},[o,j]),j){const b=async()=>{if(!p){f(!0);try{await l(e.id)?Y(e.id):r(a("assets.actionFailed"),!0)}finally{f(!1)}}};return s.jsx(O,{active:!0,busy:p,label:a("assets.removeFromElements"),onToggle:()=>{b()}})}if(!o)return null;async function x(){if(p||g.status==="loading")return;if(g.status!=="ready"&&!await z(!0)){r(a("assets.actionFailed"),!0);return}const b=q(T.elements,e.id);f(!0);try{await Re(e,b)}catch(k){console.error("[ElementMembership] toggle failed",k),r(a("assets.actionFailed"),!0)}finally{f(!1)}}return s.jsx(O,{active:!!_,busy:h,label:i,onToggle:()=>{x()}})}const L=12,V=180;function Be(e){return`/generated/${e.split("/").map(encodeURIComponent).join("/")}`}function Le({item:e,selected:a,onSelect:r,onPreview:l}){const{t:p}=I(),f=v(w=>w.deleteAssetItem),j=v(w=>w.updateAssetItem),o=v(w=>w.showToast),[i,g]=d.useState(!1),[_,h]=d.useState(!1),[x,b]=d.useState(!1),k=d.useRef(null);d.useEffect(()=>{const w=k.current;if(!w||e.kind!=="video"||typeof IntersectionObserver>"u"){b(!0);return}const R=new IntersectionObserver(([P])=>{P?.isIntersecting&&b(!0)},{rootMargin:"300px"});return R.observe(w),()=>R.disconnect()},[e.kind]);const m=e.kind==="element"&&!e.filePath?pe(e):e.filePath,u=m?Be(m):null,t=e.kind==="video",c=p(t?"assetGen.videoFallback":"assetGen.imageFallback"),y=p(t?"assetGen.previewVideo":"assetGen.previewImage",{prompt:e.name.trim()||c});async function A(){if(!i){g(!0);return}await f(e.id)||o(p("assets.actionFailed"),!0),g(!1)}const N=e.tags.includes("starred");async function S(){if(!_){h(!0);try{const w=ge(e.tags,N);await j(e.id,{tags:w})||o(p("assets.actionFailed"),!0)}finally{h(!1)}}}return s.jsxs("article",{ref:k,className:`assets-tile${a?" is-selected":""}`,tabIndex:0,"aria-selected":a,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":y,onClick:w=>{w.stopPropagation(),r?.(e.id),l?.(e)},onKeyDown:w=>w.stopPropagation(),children:[t?x?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:p(t?"assetGen.openHintVideo":"assetGen.openHintImage")})]}):s.jsx("span",{className:"assets-tile__glyph","aria-hidden":"true",children:e.kind.slice(0,1).toUpperCase()}),s.jsx(fe,{variant:"asset",active:N,busy:_,label:p(N?"assets.unstarAsset":"assets.starAsset"),onToggle:S}),s.jsx($e,{item:e}),s.jsx("button",{type:"button",className:`assets-tile__delete${i?" is-danger":""}`,"aria-label":p(i?"assets.confirmDelete":"assets.deleteAsset"),onClick:w=>{w.stopPropagation(),A()},children:i?p("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 Ue({onSelectAsset:e,onPreviewAsset:a,selectedId:r}){const{t:l}=I(),p=v(c=>c.assets),f=v(c=>c.assetsLoading),j=v(c=>c.assetsCursor),o=v(c=>c.loadMoreAssets),i=d.useRef(null),[g,_]=d.useState(960),h=Math.max(1,Math.floor((g+L)/(V+L))),x=d.useMemo(()=>Array.from({length:Math.ceil(p.length/h)},(c,y)=>p.slice(y*h,(y+1)*h)),[p,h]);d.useEffect(()=>{const c=i.current;if(!c)return;const y=()=>{const N=getComputedStyle(c),S=(parseFloat(N.paddingLeft)||0)+(parseFloat(N.paddingRight)||0);_(Math.max(0,c.clientWidth-S))};y();const A=new ResizeObserver(y);return A.observe(c),()=>A.disconnect()},[]);const b=Math.max(V,(g-L*(h-1))/h)+70+L,k=he({count:x.length,getScrollElement:()=>i.current,estimateSize:()=>b,overscan:4}),m=k.getVirtualItems(),u=m.at(-1)?.index,t=d.useCallback(()=>{j&&!f&&o()},[j,f,o]);return d.useEffect(()=>{u===x.length-1&&t()},[u,t,x.length]),s.jsxs("div",{ref:i,className:"assets-grid-scroll",children:[s.jsx("div",{className:"assets-grid-virtual",style:{height:k.getTotalSize()},children:m.map(c=>s.jsx("div",{className:"assets-grid-row",style:{transform:`translateY(${c.start}px)`,gridTemplateColumns:`repeat(${h}, minmax(0, 1fr))`},children:x[c.index]?.map(y=>s.jsx(Le,{item:y,selected:y.id===r,onSelect:e,onPreview:a},y.id))},c.key))}),j&&s.jsx("button",{type:"button",className:"assets-load-more",disabled:f,onClick:t,children:l("assets.loadMore")})]})}const Ke=5e3;function Ge({refs:e,onChange:a,maxRefs:r=6}){const{t:l}=I(),[p,f]=d.useState(null),[j,o]=d.useState(null),[i,g]=d.useState(null),_=d.useRef(null);d.useEffect(()=>()=>{_.current&&window.clearTimeout(_.current)},[]);const h=(u,t)=>{if(t<0||t>=e.length||u===t)return;const c=[...e],[y]=c.splice(u,1);c.splice(t,0,y),a(c)},x=u=>{if(e.length<=1)return;const t=e[u];a(e.filter((c,y)=>y!==u)),g({ref:t,index:u}),_.current&&window.clearTimeout(_.current),_.current=window.setTimeout(()=>g(null),Ke)},b=()=>{if(!i||e.some(t=>t.path===i.ref.path))return;const u=[...e];u.splice(Math.min(i.index,u.length),0,i.ref),a(u.slice(0,r)),g(null)},k=(u,t)=>{u.preventDefault();const c=u.dataTransfer.getData("application/ima2-element-ref")||p,y=e.findIndex(S=>S.id===c);if(f(null),y<0||y===t)return;const A=e[y],N=e.find((S,w)=>w!==y&&S.path===A.path);if(N){o(N.id),window.setTimeout(()=>o(null),1200);return}h(y,t)},m=(u,t)=>a(e.map((c,y)=>y===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:l("element.refsTitle")}),s.jsx("p",{children:l("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${p===u.id?" is-dragging":""}${j===u.id?" is-duplicate":""}`,draggable:!0,onDragStart:c=>{f(u.id),c.dataTransfer.setData("application/ima2-element-ref",u.id),c.dataTransfer.effectAllowed="move"},onDragEnd:()=>f(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||l("element.refAlt",{n:t+1})}),t===0?s.jsx("span",{children:l("element.refPrimary")}):null]}),s.jsxs("div",{className:"element-ref-card__controls",children:[s.jsxs("label",{children:[l("element.refLabel"),s.jsx("input",{value:u.alt,maxLength:80,placeholder:l("element.refLabelPlaceholder"),onChange:c=>m(t,c.target.value)})]}),s.jsxs("div",{children:[s.jsx("button",{type:"button",disabled:t===0,onClick:()=>h(t,t-1),"aria-label":l("element.refMoveUp",{n:t+1}),children:"↑"}),s.jsx("button",{type:"button",disabled:t===e.length-1,onClick:()=>h(t,t+1),"aria-label":l("element.refMoveDown",{n:t+1}),children:"↓"}),s.jsx("button",{type:"button",className:"is-danger",disabled:e.length<=1,onClick:()=>x(t),"aria-label":l("element.refRemove"),children:l("element.refRemove")})]})]})]},u.id))}),i?s.jsxs("div",{className:"element-ref-grid__undo",role:"status",children:[s.jsx("span",{children:l("element.refRemoved")}),s.jsx("button",{type:"button",onClick:b,children:l("element.refUndo")})]}):null]})}const He=/^[A-Za-z0-9_-]{1,32}$/;function qe({bindings:e,refs:a,onSave:r}){const{t:l}=I(),p=e.find(b=>b.provider==="runway"),f=e.find(b=>b.provider==="higgsfield"),[j,o]=d.useState(p?.tag??""),[i,g]=d.useState(!1),[_,h]=d.useState(null),x=async()=>{const b=j.trim();if(b&&!He.test(b)){h(l("assets.bindingTagInvalid"));return}h(null),g(!0);try{const k=[{provider:"runway",mode:"stateless-refs",...b?{tag:b}:{}},...f?[f]:[]];await r(k)||h(l("assets.actionFailed"))}finally{g(!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:l("assets.bindingsTitle")}),s.jsx("p",{children:l("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:l("assets.bindingStateless")}),s.jsx("input",{value:j,maxLength:32,placeholder:l("assets.bindingTagPlaceholder"),"aria-label":l("assets.bindingTagPlaceholder"),onChange:b=>o(b.target.value)}),s.jsx("button",{type:"button",disabled:i,onClick:()=>{x()},children:l(i?"assets.bindingSaving":"assets.bindingSave")})]}),xe(a)?s.jsx("p",{className:"element-detail__error",role:"alert",children:l("assets.bindingCapWarning",{count:a.length})}):null,s.jsxs("div",{className:"character-binding-row character-binding-row--locked",children:[s.jsx("span",{className:"character-binding-row__provider",children:"Higgsfield"}),f?.status?s.jsx("span",{className:"character-binding-row__status",children:f.status}):null,s.jsx("button",{type:"button",disabled:!0,title:l("assets.bindingTrainLockedHint"),children:l("assets.bindingTrain")}),s.jsx("span",{className:"character-binding-row__badge",children:l("assets.bindingPaidPlan")})]}),f&&be(a,f)?s.jsx("p",{className:"element-detail__error",role:"alert",children:l("assets.bindingDriftWarning")}):null,_?s.jsx("p",{className:"element-detail__error",role:"alert",children:_}):null]})}const ze=["character","product","style","scene"],W=e=>e[0].toUpperCase()+e.slice(1);function J(e){return{id:e?.id,name:e?.name??"",kind:e?.kind??"character",refs:(e?.refs??[]).filter(a=>typeof a=="string"&&a.length>0).map((a,r)=>({id:`${e?.id??"new"}-${r}-${a}`,path:a,previewUrl:`/generated/${a.split("/").map(encodeURIComponent).join("/")}`,alt:""})),notes:e?.notes??"",defaultStrength:e?.defaultStrength??.75}}function Oe({element:e,saving:a,testing:r,onSave:l,onDelete:p,onRunTestSheet:f,onSaveBindings:j}){const{t:o}=I(),[i,g]=d.useState(()=>J(e)),[_,h]=d.useState(null);d.useEffect(()=>{g(J(e)),h(null)},[e]);const x=800-i.notes.length,b=d.useMemo(()=>i.notes.trim()?`[Element: ${i.name.trim()||"Untitled"}] ${i.notes.trim()}`:null,[i.name,i.notes]),k=(t,c)=>g(y=>({...y,[t]:c})),m=async()=>{if(!i.name.trim())return h(o("element.errorName"));if(!i.refs.length)return h(o("element.errorRefs"));h(null),await l({...i,name:i.name.trim(),notes:i.notes.trim()?i.notes:""})},u=ze.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:i.name,maxLength:120,placeholder:o("element.namePlaceholder"),onChange:t=>k("name",t.target.value)})]}),s.jsx(ve,{title:o("element.kind"),items:u,value:i.kind,onChange:t=>k("kind",t)}),s.jsx("p",{className:"element-detail__kind-help",children:o(`element.help${W(i.kind)}`)}),s.jsx(Ge,{refs:i.refs,onChange:t=>k("refs",t),maxRefs:6}),e&&i.kind==="character"&&j?s.jsx(qe,{bindings:e.characterBindings??[],refs:e.refs,onSave:t=>j(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")})]}),x<=100?s.jsx("span",{children:o("element.remaining",{n:x})}):null]}),s.jsx("textarea",{value:i.notes,maxLength:800,rows:6,placeholder:o("element.notesPlaceholder"),onChange:t=>k("notes",t.target.value)}),b?s.jsx("p",{className:"element-detail__note-preview",children:b}):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:i.defaultStrength.toFixed(2)})]}),s.jsx("input",{className:"element-detail__strength",type:"range",min:"0",max:"1",step:"0.05",value:i.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")})]}),_?s.jsx("p",{className:"element-detail__error",role:"alert",children:_}):null,s.jsxs("footer",{className:"element-detail__actions",children:[s.jsx("button",{type:"button",className:"element-detail__save",disabled:a,onClick:()=>{m()},children:o(a?"element.saving":"element.save")}),s.jsx("button",{type:"button",disabled:!e||r,onClick:()=>e&&void f(e.id),children:o(r?"element.testing":"element.runTest")}),e&&p?s.jsx("button",{type:"button",className:"is-danger",onClick:()=>{p(e.id)},children:o("element.delete")}):null]})]})}const Ve=["image","video","element","preset","template"];function We(e,a){return Ae(e,a)}function es(){const{t:e}=I(),a=v(n=>n.assets),r=v(n=>n.assetsTags),l=v(n=>n.assetsFilters),p=v(n=>n.assetsLoading),f=v(n=>n.assetsLoadError),j=v(n=>n.loadAssets),o=v(n=>n.setUIMode),i=v(n=>n.setAssetsFilters),g=v(n=>n.updateAssetItem),_=v(n=>n.deleteAssetItem),h=v(n=>n.showToast),[x,b]=d.useState(l.q),[k,m]=d.useState(null),[u,t]=d.useState(null),[c,y]=d.useState(null),A=je(),N=v(n=>n.keyingTarget),S=v(n=>n.pendingAssetDetailId);d.useEffect(()=>{if(!S)return;const n=S;v.setState({pendingAssetDetailId:null});const E=v.getState().assets.find(F=>F.id===n)??null;y(E),i({kind:null,folderId:null,tag:null,q:""}),b(""),m(n),E||ye(n).then(({asset:F})=>{v.setState(K=>({assets:[F,...K.assets.filter(B=>B.id!==F.id)]})),y(F)}).catch(()=>{})},[S,i]);const w=d.useRef(!1);d.useEffect(()=>{if(N){w.current=!0;return}w.current&&(w.current=!1,j(!0))},[N,j]);const R=d.useMemo(()=>[{value:"",label:e("assets.kindAll")},...Ve.map(n=>({value:n,label:e(`assets.kind${n[0].toUpperCase()}${n.slice(1)}`)}))],[e]);d.useEffect(()=>{j(!0)},[j]),d.useEffect(()=>{const n=window.setTimeout(()=>i({q:x}),300);return()=>window.clearTimeout(n)},[x,i]);const P=!!(l.q||l.kind||l.tag),Z=a.length===0&&!p,U=l.kind==="element"&&!l.folderId&&!l.q&&!l.tag,X=U?"assets.emptyElementsTitle":l.folderId?"assets.emptyFolderTitle":P?"assets.emptySearchTitle":"assets.emptyTitle",ee=U?"assets.emptyElementsBody":l.folderId?"assets.emptyFolderBody":P?"assets.emptySearchBody":"assets.emptyBody",C=a.find(n=>n.id===k)??(c?.id===k?c:null),H=C?.kind==="element"?Qe(C):null,$=d.useCallback(()=>m(null),[]),se=We(!!(C&&A),$),te=d.useCallback(()=>t(null),[]),ae=async n=>{(!n.id||!await g(n.id,{name:n.name,notes:n.notes}))&&h(e("assets.actionFailed"),!0)},ne=async(n,E)=>{const K={...a.find(oe=>oe.id===n)?.metadata??{},characterBindings:E},B=await g(n,{metadata:K});return B||h(e("assets.actionFailed"),!0),B},le=async(n,E)=>{const F=await g(n,{name:E});return F||h(e("assets.actionFailed"),!0),F},ie=async n=>{await _(n)?$():h(e("assets.actionFailed"),!0)},re=async()=>h(e("assets.testSheetsUnavailable"),!0);return s.jsxs("section",{className:`assets-workspace${C?" assets-workspace--detail-open":""}`,"aria-labelledby":"assets-title",children:[s.jsx(Fe,{}),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:a.length})})]}),s.jsxs("div",{className:"assets-toolbar__controls",children:[s.jsx("input",{type:"search",value:x,placeholder:e("assets.searchPlaceholder"),"aria-label":e("assets.searchPlaceholder"),onChange:n=>b(n.target.value)}),s.jsx(_e,{items:R,value:l.kind??"",onChange:n=>i({kind:n||null}),ariaLabel:e("assets.kindAll")}),a.length>0&&s.jsx("button",{type:"button",className:"assets-clear-btn",onClick:async()=>{confirm(e("assets.clearConfirm"))&&(await we(),j(!0))},children:e("assets.clearAll")})]}),r.length>0&&s.jsx("div",{className:"assets-tag-filter",children:r.map(n=>s.jsx("button",{type:"button",className:l.tag===n?"is-active":"",onClick:()=>i({tag:l.tag===n?null:n}),children:n},n))})]}),f&&a.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:()=>{j(!0)},children:e("assets.retry")})]}):Z?s.jsxs("div",{className:"assets-empty",children:[s.jsx("h2",{children:e(X)}),s.jsx("p",{children:e(ee)}),U||!P&&!l.folderId?s.jsx("button",{type:"button",className:"assets-empty__cta",onClick:()=>o("classic"),children:e("nav.create")}):null]}):s.jsx(Ue,{selectedId:k??void 0,onSelectAsset:m,onPreviewAsset:n=>t(ke(n))})]}),C&&A?s.jsx("button",{type:"button",className:"assets-workspace__detail-backdrop","aria-label":e("assets.detailClose"),onClick:$}):null,C&&s.jsxs("aside",{ref:se,className:"assets-workspace__detail",role:A?"dialog":void 0,"aria-modal":A?!0:void 0,"aria-label":e("assets.detailAria",{name:C.name}),children:[s.jsx("button",{type:"button",className:"assets-workspace__detail-close",onClick:$,"aria-label":e("assets.detailClose"),children:"×"}),H?s.jsx(Oe,{element:H,saving:!1,testing:!1,onSave:ae,onSaveBindings:ne,onDelete:ie,onRunTestSheet:re}):s.jsx(Je,{asset:C,onRename:n=>le(C.id,n)})]}),s.jsx(Se,{}),s.jsx(Ne,{}),u?s.jsx(Ie,{item:u,onClose:te}):null]})}function Je({asset:e,onRename:a}){const{t:r,locale:l}=I(),[p,f]=d.useState(!1),[j,o]=d.useState(e.name),i=d.useRef(!1),g=typeof e.metadata?.prompt=="string"?e.metadata.prompt:null,_=typeof e.metadata?.provider=="string"?e.metadata.provider:null;d.useEffect(()=>{o(e.name),f(!1)},[e.id,e.name]);async function h(){if(i.current)return;const x=j.trim();if(!x||x===e.name){o(e.name),f(!1);return}i.current=!0;try{await a(x)||o(e.name)}finally{i.current=!1,f(!1)}}return s.jsxs("div",{className:"assets-workspace__detail-meta",children:[s.jsx("div",{className:"assets-workspace__detail-title",children:p?s.jsx("input",{className:"assets-folder-input assets-workspace__detail-name-input",value:j,autoFocus:!0,"aria-label":r("assets.renameAsset"),onChange:x=>o(x.target.value),onBlur:()=>{h()},onKeyDown:x=>{x.key==="Enter"&&h(),x.key==="Escape"&&(o(e.name),f(!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:()=>f(!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(l,{dateStyle:"medium",timeStyle:"short"}).format(new Date(e.createdAt))}),_?s.jsxs(s.Fragment,{children:[s.jsx("dt",{children:r("assets.detailProvider")}),s.jsx("dd",{children:_})]}):null,g?s.jsxs(s.Fragment,{children:[s.jsx("dt",{children:r("assets.detailPrompt")}),s.jsx("dd",{className:"assets-workspace__detail-prompt",children:g})]}):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 Qe(e){const a=e.metadata??{},r=a.elementKind,l=a.refs,p=Array.isArray(a.characterBindings)?a.characterBindings:void 0;return{id:e.id,name:e.name,kind:r==="product"||r==="style"||r==="scene"?r:"character",refs:Array.isArray(l)?l.filter(f=>typeof f=="string"):e.filePath?[e.filePath]:[],notes:e.notes??void 0,defaultStrength:typeof a.defaultStrength=="number"?a.defaultStrength:void 0,characterBindings:p}}export{es as AssetsWorkspace};
|
|
1
|
+
import{u as I,b as v,a as d,j as s,a1 as Q,a2 as q,m as de,a3 as ce,a4 as ue,a5 as me,a6 as he,o as pe,a7 as fe,a8 as ge,a9 as xe,aa as be,J as ve,t as je,q as ye,v as _e,ab as we,ac as ke,ad as Ne,p as Ae}from"./index-BbykeXR9.js";import{K as Se,A as Ie}from"./KeyingPanel-5bRUFQaq.js";import"./useAgentDialogFocus-B6-QgEVI.js";function Ce({folder:e,depth:a}){const{t:r}=I(),l=v(t=>t.assetsFilters.folderId),p=v(t=>t.setAssetsFilters),f=v(t=>t.renameAssetFolder),j=v(t=>t.deleteAssetFolder),o=v(t=>t.showToast),[i,g]=d.useState(!1),[_,h]=d.useState(e.name),[x,b]=d.useState(!1),k=l===e.id;async function m(){const t=_.trim();if(!t||t===e.name){h(e.name),g(!1);return}await f(e.id,t)||o(r("assets.actionFailed"),!0),g(!1)}async function u(){if(!x){b(!0);return}await j(e.id)||o(r("assets.actionFailed"),!0),b(!1)}return s.jsxs("div",{className:"assets-folder-row",style:{"--folder-depth":a},children:[i?s.jsx("input",{className:"assets-folder-input",value:_,autoFocus:!0,"aria-label":r("assets.renameFolder"),onChange:t=>h(t.target.value),onBlur:()=>{m()},onKeyDown:t=>{t.key==="Enter"&&m(),t.key==="Escape"&&(h(e.name),g(!1))}}):s.jsx("button",{type:"button",className:`assets-folder-row__name${k?" is-active":""}`,"aria-current":k?"page":void 0,onClick:()=>p({folderId:e.id,kind:null}),children:e.name}),!i&&s.jsxs("span",{className:"assets-folder-row__actions",children:[s.jsx("button",{type:"button","aria-label":r("assets.renameFolder"),onClick:()=>g(!0),children:s.jsx(Q,{})}),s.jsx("button",{type:"button","aria-label":r(x?"assets.confirmDelete":"assets.deleteFolder"),className:x?"is-danger is-armed":"",onClick:()=>{u()},children:x?r("assets.confirmDelete"):"×"})]})]})}function Fe(){const{t:e}=I(),a=v(m=>m.assetsFolders),r=v(m=>m.assetsFilters.folderId),l=v(m=>m.assetsFilters.kind),p=v(m=>m.setAssetsFilters),f=v(m=>m.createAssetFolder),j=v(m=>m.showToast),[o,i]=d.useState(!1),[g,_]=d.useState(""),h=r===null&&l!=="element",x=r===null&&l==="element",b=d.useMemo(()=>{const m=[],u=(t,c)=>a.filter(y=>y.parentId===t).forEach(y=>{m.push({folder:y,depth:c}),u(y.id,c+1)});return u(null,0),m},[a]);async function k(){const m=g.trim();if(!m){i(!1);return}await f(m,r)||j(e("assets.actionFailed"),!0),_(""),i(!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:()=>i(!0),children:"+"})]}),s.jsxs("div",{className:"assets-folders__rows",children:[s.jsx("button",{type:"button",className:`assets-folder-all${h?" is-active":""}`,"aria-current":h?"page":void 0,onClick:()=>p({folderId:null,kind:null}),children:e("assets.allAssets")}),s.jsxs("button",{type:"button",className:`assets-folder-all assets-folder-elements${x?" is-active":""}`,"aria-current":x?"page":void 0,onClick:()=>p({folderId:null,kind:"element"}),children:[s.jsx("span",{className:"assets-folder-elements__glyph","aria-hidden":"true",children:"@"}),e("assets.elementLibrary")]}),b.map(({folder:m,depth:u})=>s.jsx(Ce,{folder:m,depth:u},m.id)),o&&s.jsx("input",{className:"assets-folder-input assets-folder-input--new",value:g,autoFocus:!0,"aria-label":e("assets.newFolder"),placeholder:e("assets.newFolder"),onChange:m=>_(m.target.value),onBlur:()=>{g.trim()||i(!1)},onKeyDown:m=>{m.key==="Enter"&&k(),m.key==="Escape"&&(_(""),i(!1))}})]})]})}let T={status:"idle",elements:[]},D=null;const G=new Set;function M(e){T=e,G.forEach(a=>a())}function Te(e){return G.add(e),()=>G.delete(e)}function z(e=!1){return!e&&T.status==="ready"?Promise.resolve(!0):D||(M({...T,status:"loading"}),D=de().then(a=>(M({status:"ready",elements:a}),!0)).catch(a=>(console.error("[ElementMembership] load failed",a),M({...T,status:"error"}),!1)).finally(()=>{D=null}),D)}function Ee(e){const a=[e,...T.elements.filter(r=>r.id!==e.id)];M({status:"ready",elements:a})}function Y(e){M({status:"ready",elements:T.elements.filter(a=>a.id!==e)})}function Pe(e){e.stopPropagation()}function De(e){e.stopPropagation()}function Me(e){(e.key==="Enter"||e.key===" ")&&e.stopPropagation()}async function Re(e,a){if(a){await ce(a.id),Y(a.id);return}const{asset:r}=await ue({result:{filePath:e.filePath??void 0},sourceAssetId:e.id,elementKind:"character",name:e.name,notes:e.notes??void 0,folderId:e.folderId,tags:[me(e.id)]});Ee(r)}function O({active:e,busy:a,label:r,onToggle:l}){return s.jsx("button",{type:"button",className:`asset-element-toggle${e?" is-active":""}`,title:r,"aria-label":r,"aria-pressed":e,"aria-busy":a||void 0,disabled:a,onPointerDown:Pe,onDoubleClick:De,onKeyDown:Me,onClick:p=>{p.stopPropagation(),l()},children:s.jsx("span",{className:"asset-element-toggle__glyph","aria-hidden":"true",children:"@"})})}function $e({item:e}){const{t:a}=I(),r=v(b=>b.showToast),l=v(b=>b.deleteAssetItem),[p,f]=d.useState(!1),j=e.kind==="element",o=j||(e.kind==="image"||e.kind==="video")&&!!e.filePath,i=a("assets.elementLibrary"),g=d.useSyncExternalStore(Te,()=>T,()=>T),_=!j&&o?q(g.elements,e.id):null,h=p||g.status==="loading"||g.status==="idle";if(d.useEffect(()=>{o&&!j&&z()},[o,j]),j){const b=async()=>{if(!p){f(!0);try{await l(e.id)?Y(e.id):r(a("assets.actionFailed"),!0)}finally{f(!1)}}};return s.jsx(O,{active:!0,busy:p,label:a("assets.removeFromElements"),onToggle:()=>{b()}})}if(!o)return null;async function x(){if(p||g.status==="loading")return;if(g.status!=="ready"&&!await z(!0)){r(a("assets.actionFailed"),!0);return}const b=q(T.elements,e.id);f(!0);try{await Re(e,b)}catch(k){console.error("[ElementMembership] toggle failed",k),r(a("assets.actionFailed"),!0)}finally{f(!1)}}return s.jsx(O,{active:!!_,busy:h,label:i,onToggle:()=>{x()}})}const L=12,V=180;function Be(e){return`/generated/${e.split("/").map(encodeURIComponent).join("/")}`}function Le({item:e,selected:a,onSelect:r,onPreview:l}){const{t:p}=I(),f=v(w=>w.deleteAssetItem),j=v(w=>w.updateAssetItem),o=v(w=>w.showToast),[i,g]=d.useState(!1),[_,h]=d.useState(!1),[x,b]=d.useState(!1),k=d.useRef(null);d.useEffect(()=>{const w=k.current;if(!w||e.kind!=="video"||typeof IntersectionObserver>"u"){b(!0);return}const R=new IntersectionObserver(([P])=>{P?.isIntersecting&&b(!0)},{rootMargin:"300px"});return R.observe(w),()=>R.disconnect()},[e.kind]);const m=e.kind==="element"&&!e.filePath?pe(e):e.filePath,u=m?Be(m):null,t=e.kind==="video",c=p(t?"assetGen.videoFallback":"assetGen.imageFallback"),y=p(t?"assetGen.previewVideo":"assetGen.previewImage",{prompt:e.name.trim()||c});async function A(){if(!i){g(!0);return}await f(e.id)||o(p("assets.actionFailed"),!0),g(!1)}const N=e.tags.includes("starred");async function S(){if(!_){h(!0);try{const w=ge(e.tags,N);await j(e.id,{tags:w})||o(p("assets.actionFailed"),!0)}finally{h(!1)}}}return s.jsxs("article",{ref:k,className:`assets-tile${a?" is-selected":""}`,tabIndex:0,"aria-selected":a,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":y,onClick:w=>{w.stopPropagation(),r?.(e.id),l?.(e)},onKeyDown:w=>w.stopPropagation(),children:[t?x?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:p(t?"assetGen.openHintVideo":"assetGen.openHintImage")})]}):s.jsx("span",{className:"assets-tile__glyph","aria-hidden":"true",children:e.kind.slice(0,1).toUpperCase()}),s.jsx(fe,{variant:"asset",active:N,busy:_,label:p(N?"assets.unstarAsset":"assets.starAsset"),onToggle:S}),s.jsx($e,{item:e}),s.jsx("button",{type:"button",className:`assets-tile__delete${i?" is-danger":""}`,"aria-label":p(i?"assets.confirmDelete":"assets.deleteAsset"),onClick:w=>{w.stopPropagation(),A()},children:i?p("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 Ue({onSelectAsset:e,onPreviewAsset:a,selectedId:r}){const{t:l}=I(),p=v(c=>c.assets),f=v(c=>c.assetsLoading),j=v(c=>c.assetsCursor),o=v(c=>c.loadMoreAssets),i=d.useRef(null),[g,_]=d.useState(960),h=Math.max(1,Math.floor((g+L)/(V+L))),x=d.useMemo(()=>Array.from({length:Math.ceil(p.length/h)},(c,y)=>p.slice(y*h,(y+1)*h)),[p,h]);d.useEffect(()=>{const c=i.current;if(!c)return;const y=()=>{const N=getComputedStyle(c),S=(parseFloat(N.paddingLeft)||0)+(parseFloat(N.paddingRight)||0);_(Math.max(0,c.clientWidth-S))};y();const A=new ResizeObserver(y);return A.observe(c),()=>A.disconnect()},[]);const b=Math.max(V,(g-L*(h-1))/h)+70+L,k=he({count:x.length,getScrollElement:()=>i.current,estimateSize:()=>b,overscan:4}),m=k.getVirtualItems(),u=m.at(-1)?.index,t=d.useCallback(()=>{j&&!f&&o()},[j,f,o]);return d.useEffect(()=>{u===x.length-1&&t()},[u,t,x.length]),s.jsxs("div",{ref:i,className:"assets-grid-scroll",children:[s.jsx("div",{className:"assets-grid-virtual",style:{height:k.getTotalSize()},children:m.map(c=>s.jsx("div",{className:"assets-grid-row",style:{transform:`translateY(${c.start}px)`,gridTemplateColumns:`repeat(${h}, minmax(0, 1fr))`},children:x[c.index]?.map(y=>s.jsx(Le,{item:y,selected:y.id===r,onSelect:e,onPreview:a},y.id))},c.key))}),j&&s.jsx("button",{type:"button",className:"assets-load-more",disabled:f,onClick:t,children:l("assets.loadMore")})]})}const Ke=5e3;function Ge({refs:e,onChange:a,maxRefs:r=6}){const{t:l}=I(),[p,f]=d.useState(null),[j,o]=d.useState(null),[i,g]=d.useState(null),_=d.useRef(null);d.useEffect(()=>()=>{_.current&&window.clearTimeout(_.current)},[]);const h=(u,t)=>{if(t<0||t>=e.length||u===t)return;const c=[...e],[y]=c.splice(u,1);c.splice(t,0,y),a(c)},x=u=>{if(e.length<=1)return;const t=e[u];a(e.filter((c,y)=>y!==u)),g({ref:t,index:u}),_.current&&window.clearTimeout(_.current),_.current=window.setTimeout(()=>g(null),Ke)},b=()=>{if(!i||e.some(t=>t.path===i.ref.path))return;const u=[...e];u.splice(Math.min(i.index,u.length),0,i.ref),a(u.slice(0,r)),g(null)},k=(u,t)=>{u.preventDefault();const c=u.dataTransfer.getData("application/ima2-element-ref")||p,y=e.findIndex(S=>S.id===c);if(f(null),y<0||y===t)return;const A=e[y],N=e.find((S,w)=>w!==y&&S.path===A.path);if(N){o(N.id),window.setTimeout(()=>o(null),1200);return}h(y,t)},m=(u,t)=>a(e.map((c,y)=>y===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:l("element.refsTitle")}),s.jsx("p",{children:l("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${p===u.id?" is-dragging":""}${j===u.id?" is-duplicate":""}`,draggable:!0,onDragStart:c=>{f(u.id),c.dataTransfer.setData("application/ima2-element-ref",u.id),c.dataTransfer.effectAllowed="move"},onDragEnd:()=>f(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||l("element.refAlt",{n:t+1})}),t===0?s.jsx("span",{children:l("element.refPrimary")}):null]}),s.jsxs("div",{className:"element-ref-card__controls",children:[s.jsxs("label",{children:[l("element.refLabel"),s.jsx("input",{value:u.alt,maxLength:80,placeholder:l("element.refLabelPlaceholder"),onChange:c=>m(t,c.target.value)})]}),s.jsxs("div",{children:[s.jsx("button",{type:"button",disabled:t===0,onClick:()=>h(t,t-1),"aria-label":l("element.refMoveUp",{n:t+1}),children:"↑"}),s.jsx("button",{type:"button",disabled:t===e.length-1,onClick:()=>h(t,t+1),"aria-label":l("element.refMoveDown",{n:t+1}),children:"↓"}),s.jsx("button",{type:"button",className:"is-danger",disabled:e.length<=1,onClick:()=>x(t),"aria-label":l("element.refRemove"),children:l("element.refRemove")})]})]})]},u.id))}),i?s.jsxs("div",{className:"element-ref-grid__undo",role:"status",children:[s.jsx("span",{children:l("element.refRemoved")}),s.jsx("button",{type:"button",onClick:b,children:l("element.refUndo")})]}):null]})}const He=/^[A-Za-z0-9_-]{1,32}$/;function qe({bindings:e,refs:a,onSave:r}){const{t:l}=I(),p=e.find(b=>b.provider==="runway"),f=e.find(b=>b.provider==="higgsfield"),[j,o]=d.useState(p?.tag??""),[i,g]=d.useState(!1),[_,h]=d.useState(null),x=async()=>{const b=j.trim();if(b&&!He.test(b)){h(l("assets.bindingTagInvalid"));return}h(null),g(!0);try{const k=[{provider:"runway",mode:"stateless-refs",...b?{tag:b}:{}},...f?[f]:[]];await r(k)||h(l("assets.actionFailed"))}finally{g(!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:l("assets.bindingsTitle")}),s.jsx("p",{children:l("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:l("assets.bindingStateless")}),s.jsx("input",{value:j,maxLength:32,placeholder:l("assets.bindingTagPlaceholder"),"aria-label":l("assets.bindingTagPlaceholder"),onChange:b=>o(b.target.value)}),s.jsx("button",{type:"button",disabled:i,onClick:()=>{x()},children:l(i?"assets.bindingSaving":"assets.bindingSave")})]}),xe(a)?s.jsx("p",{className:"element-detail__error",role:"alert",children:l("assets.bindingCapWarning",{count:a.length})}):null,s.jsxs("div",{className:"character-binding-row character-binding-row--locked",children:[s.jsx("span",{className:"character-binding-row__provider",children:"Higgsfield"}),f?.status?s.jsx("span",{className:"character-binding-row__status",children:f.status}):null,s.jsx("button",{type:"button",disabled:!0,title:l("assets.bindingTrainLockedHint"),children:l("assets.bindingTrain")}),s.jsx("span",{className:"character-binding-row__badge",children:l("assets.bindingPaidPlan")})]}),f&&be(a,f)?s.jsx("p",{className:"element-detail__error",role:"alert",children:l("assets.bindingDriftWarning")}):null,_?s.jsx("p",{className:"element-detail__error",role:"alert",children:_}):null]})}const ze=["character","product","style","scene"],W=e=>e[0].toUpperCase()+e.slice(1);function J(e){return{id:e?.id,name:e?.name??"",kind:e?.kind??"character",refs:(e?.refs??[]).filter(a=>typeof a=="string"&&a.length>0).map((a,r)=>({id:`${e?.id??"new"}-${r}-${a}`,path:a,previewUrl:`/generated/${a.split("/").map(encodeURIComponent).join("/")}`,alt:""})),notes:e?.notes??"",defaultStrength:e?.defaultStrength??.75}}function Oe({element:e,saving:a,testing:r,onSave:l,onDelete:p,onRunTestSheet:f,onSaveBindings:j}){const{t:o}=I(),[i,g]=d.useState(()=>J(e)),[_,h]=d.useState(null);d.useEffect(()=>{g(J(e)),h(null)},[e]);const x=800-i.notes.length,b=d.useMemo(()=>i.notes.trim()?`[Element: ${i.name.trim()||"Untitled"}] ${i.notes.trim()}`:null,[i.name,i.notes]),k=(t,c)=>g(y=>({...y,[t]:c})),m=async()=>{if(!i.name.trim())return h(o("element.errorName"));if(!i.refs.length)return h(o("element.errorRefs"));h(null),await l({...i,name:i.name.trim(),notes:i.notes.trim()?i.notes:""})},u=ze.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:i.name,maxLength:120,placeholder:o("element.namePlaceholder"),onChange:t=>k("name",t.target.value)})]}),s.jsx(ve,{title:o("element.kind"),items:u,value:i.kind,onChange:t=>k("kind",t)}),s.jsx("p",{className:"element-detail__kind-help",children:o(`element.help${W(i.kind)}`)}),s.jsx(Ge,{refs:i.refs,onChange:t=>k("refs",t),maxRefs:6}),e&&i.kind==="character"&&j?s.jsx(qe,{bindings:e.characterBindings??[],refs:e.refs,onSave:t=>j(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")})]}),x<=100?s.jsx("span",{children:o("element.remaining",{n:x})}):null]}),s.jsx("textarea",{value:i.notes,maxLength:800,rows:6,placeholder:o("element.notesPlaceholder"),onChange:t=>k("notes",t.target.value)}),b?s.jsx("p",{className:"element-detail__note-preview",children:b}):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:i.defaultStrength.toFixed(2)})]}),s.jsx("input",{className:"element-detail__strength",type:"range",min:"0",max:"1",step:"0.05",value:i.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")})]}),_?s.jsx("p",{className:"element-detail__error",role:"alert",children:_}):null,s.jsxs("footer",{className:"element-detail__actions",children:[s.jsx("button",{type:"button",className:"element-detail__save",disabled:a,onClick:()=>{m()},children:o(a?"element.saving":"element.save")}),s.jsx("button",{type:"button",disabled:!e||r,onClick:()=>e&&void f(e.id),children:o(r?"element.testing":"element.runTest")}),e&&p?s.jsx("button",{type:"button",className:"is-danger",onClick:()=>{p(e.id)},children:o("element.delete")}):null]})]})}const Ve=["image","video","element","preset","template"];function We(e,a){return Ae(e,a)}function es(){const{t:e}=I(),a=v(n=>n.assets),r=v(n=>n.assetsTags),l=v(n=>n.assetsFilters),p=v(n=>n.assetsLoading),f=v(n=>n.assetsLoadError),j=v(n=>n.loadAssets),o=v(n=>n.setUIMode),i=v(n=>n.setAssetsFilters),g=v(n=>n.updateAssetItem),_=v(n=>n.deleteAssetItem),h=v(n=>n.showToast),[x,b]=d.useState(l.q),[k,m]=d.useState(null),[u,t]=d.useState(null),[c,y]=d.useState(null),A=je(),N=v(n=>n.keyingTarget),S=v(n=>n.pendingAssetDetailId);d.useEffect(()=>{if(!S)return;const n=S;v.setState({pendingAssetDetailId:null});const E=v.getState().assets.find(F=>F.id===n)??null;y(E),i({kind:null,folderId:null,tag:null,q:""}),b(""),m(n),E||ye(n).then(({asset:F})=>{v.setState(K=>({assets:[F,...K.assets.filter(B=>B.id!==F.id)]})),y(F)}).catch(()=>{})},[S,i]);const w=d.useRef(!1);d.useEffect(()=>{if(N){w.current=!0;return}w.current&&(w.current=!1,j(!0))},[N,j]);const R=d.useMemo(()=>[{value:"",label:e("assets.kindAll")},...Ve.map(n=>({value:n,label:e(`assets.kind${n[0].toUpperCase()}${n.slice(1)}`)}))],[e]);d.useEffect(()=>{j(!0)},[j]),d.useEffect(()=>{const n=window.setTimeout(()=>i({q:x}),300);return()=>window.clearTimeout(n)},[x,i]);const P=!!(l.q||l.kind||l.tag),Z=a.length===0&&!p,U=l.kind==="element"&&!l.folderId&&!l.q&&!l.tag,X=U?"assets.emptyElementsTitle":l.folderId?"assets.emptyFolderTitle":P?"assets.emptySearchTitle":"assets.emptyTitle",ee=U?"assets.emptyElementsBody":l.folderId?"assets.emptyFolderBody":P?"assets.emptySearchBody":"assets.emptyBody",C=a.find(n=>n.id===k)??(c?.id===k?c:null),H=C?.kind==="element"?Qe(C):null,$=d.useCallback(()=>m(null),[]),se=We(!!(C&&A),$),te=d.useCallback(()=>t(null),[]),ae=async n=>{(!n.id||!await g(n.id,{name:n.name,notes:n.notes}))&&h(e("assets.actionFailed"),!0)},ne=async(n,E)=>{const K={...a.find(oe=>oe.id===n)?.metadata??{},characterBindings:E},B=await g(n,{metadata:K});return B||h(e("assets.actionFailed"),!0),B},le=async(n,E)=>{const F=await g(n,{name:E});return F||h(e("assets.actionFailed"),!0),F},ie=async n=>{await _(n)?$():h(e("assets.actionFailed"),!0)},re=async()=>h(e("assets.testSheetsUnavailable"),!0);return s.jsxs("section",{className:`assets-workspace${C?" assets-workspace--detail-open":""}`,"aria-labelledby":"assets-title",children:[s.jsx(Fe,{}),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:a.length})})]}),s.jsxs("div",{className:"assets-toolbar__controls",children:[s.jsx("input",{type:"search",value:x,placeholder:e("assets.searchPlaceholder"),"aria-label":e("assets.searchPlaceholder"),onChange:n=>b(n.target.value)}),s.jsx(_e,{items:R,value:l.kind??"",onChange:n=>i({kind:n||null}),ariaLabel:e("assets.kindAll")}),a.length>0&&s.jsx("button",{type:"button",className:"assets-clear-btn",onClick:async()=>{confirm(e("assets.clearConfirm"))&&(await we(),j(!0))},children:e("assets.clearAll")})]}),r.length>0&&s.jsx("div",{className:"assets-tag-filter",children:r.map(n=>s.jsx("button",{type:"button",className:l.tag===n?"is-active":"",onClick:()=>i({tag:l.tag===n?null:n}),children:n},n))})]}),f&&a.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:()=>{j(!0)},children:e("assets.retry")})]}):Z?s.jsxs("div",{className:"assets-empty",children:[s.jsx("h2",{children:e(X)}),s.jsx("p",{children:e(ee)}),U||!P&&!l.folderId?s.jsx("button",{type:"button",className:"assets-empty__cta",onClick:()=>o("classic"),children:e("nav.create")}):null]}):s.jsx(Ue,{selectedId:k??void 0,onSelectAsset:m,onPreviewAsset:n=>t(ke(n))})]}),C&&A?s.jsx("button",{type:"button",className:"assets-workspace__detail-backdrop","aria-label":e("assets.detailClose"),onClick:$}):null,C&&s.jsxs("aside",{ref:se,className:"assets-workspace__detail",role:A?"dialog":void 0,"aria-modal":A?!0:void 0,"aria-label":e("assets.detailAria",{name:C.name}),children:[s.jsx("button",{type:"button",className:"assets-workspace__detail-close",onClick:$,"aria-label":e("assets.detailClose"),children:"×"}),H?s.jsx(Oe,{element:H,saving:!1,testing:!1,onSave:ae,onSaveBindings:ne,onDelete:ie,onRunTestSheet:re}):s.jsx(Je,{asset:C,onRename:n=>le(C.id,n)})]}),s.jsx(Se,{}),s.jsx(Ne,{}),u?s.jsx(Ie,{item:u,onClose:te}):null]})}function Je({asset:e,onRename:a}){const{t:r,locale:l}=I(),[p,f]=d.useState(!1),[j,o]=d.useState(e.name),i=d.useRef(!1),g=typeof e.metadata?.prompt=="string"?e.metadata.prompt:null,_=typeof e.metadata?.provider=="string"?e.metadata.provider:null;d.useEffect(()=>{o(e.name),f(!1)},[e.id,e.name]);async function h(){if(i.current)return;const x=j.trim();if(!x||x===e.name){o(e.name),f(!1);return}i.current=!0;try{await a(x)||o(e.name)}finally{i.current=!1,f(!1)}}return s.jsxs("div",{className:"assets-workspace__detail-meta",children:[s.jsx("div",{className:"assets-workspace__detail-title",children:p?s.jsx("input",{className:"assets-folder-input assets-workspace__detail-name-input",value:j,autoFocus:!0,"aria-label":r("assets.renameAsset"),onChange:x=>o(x.target.value),onBlur:()=>{h()},onKeyDown:x=>{x.key==="Enter"&&h(),x.key==="Escape"&&(o(e.name),f(!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:()=>f(!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(l,{dateStyle:"medium",timeStyle:"short"}).format(new Date(e.createdAt))}),_?s.jsxs(s.Fragment,{children:[s.jsx("dt",{children:r("assets.detailProvider")}),s.jsx("dd",{children:_})]}):null,g?s.jsxs(s.Fragment,{children:[s.jsx("dt",{children:r("assets.detailPrompt")}),s.jsx("dd",{className:"assets-workspace__detail-prompt",children:g})]}):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 Qe(e){const a=e.metadata??{},r=a.elementKind,l=a.refs,p=Array.isArray(a.characterBindings)?a.characterBindings:void 0;return{id:e.id,name:e.name,kind:r==="product"||r==="style"||r==="scene"?r:"character",refs:Array.isArray(l)?l.filter(f=>typeof f=="string"):e.filePath?[e.filePath]:[],notes:e.notes??void 0,defaultStrength:typeof a.defaultStrength=="number"?a.defaultStrength:void 0,characterBindings:p}}export{es as AssetsWorkspace};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{u,Z as l,j as e,_,a as h,v as j,t as k}from"./index-
|
|
1
|
+
import{u,Z as l,j as e,_,a as h,v as j,t as k}from"./index-BbykeXR9.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:_,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=k(),[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};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{s as j,u as _,p as b,D as N,j as e,b as p,a as n}from"./index-
|
|
1
|
+
import{s as j,u as _,p as b,D as N,j as e,b as p,a as n}from"./index-BbykeXR9.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 l,u as m,am as P,j as e,an as k,ao as E,ap as w,v as M,aq as R,a as j,ar as T,as as C,at as L,au as O,av as H,aw as S,ax as G,ay as U}from"./index-
|
|
1
|
+
import{b as l,u as m,am as P,j as e,an as k,ao as E,ap as w,v as M,aq as R,a as j,ar as T,as as C,at as L,au as O,av as H,aw as S,ax as G,ay as U}from"./index-BbykeXR9.js";const D={oauth:"GPT OAuth",api:"GPT API",grok:"Grok OAuth","grok-api":"Grok API",agy:"Antigravity","gemini-api":"Gemini API",atlascloud:"Atlas Cloud",minimax:"MiniMax",nai:"NovelAI",comfy:"ComfyUI"};function V(o){if(o.kind==="attachment")return o.source.dataUrl;if(o.source.thumbnailUrl)return o.source.thumbnailUrl;const s=o.source.referenceFilenames[0];if(s)return s.startsWith("/generated/")?s:`/generated/${s.split("/").map(encodeURIComponent).join("/")}`}function $({providerAvailability:o}){const s=l(t=>t.prompt),r=l(t=>t.setPrompt),n=l(t=>t.provider),a=l(t=>t.setProvider),c=l(t=>t.selectedPresetIds),_=l(t=>t.removePreset),h=l(t=>t.generate),g=l(t=>t.activeGenerations),p=l(t=>t.trayItems),{t:i}=m(),I=new Set(c),N=P().filter(t=>I.has(t.id)),x=g>0,d=n==="nai",v=()=>{x||s.trim().length===0||(h(),l.getState().setUIMode("classic"))},A=Object.entries(D).map(([t,u])=>{const f=t,b=o[f];return{value:f,label:u,sub:b.ok?i("readiness.ready"):b.reason,disabled:!b.ok}});return e.jsxs("div",{className:"home-prompt",children:[N.length>0?e.jsx(k,{className:"home-prompt__chips",ariaLabel:i("home.selectedPresets"),children:N.map(t=>e.jsx(E,{selected:!0,onRemove:()=>_(t.id),removeLabel:i("common.removeNamed",{name:t.name}),title:t.category,children:t.name},t.id))}):null,p.length>0?e.jsxs("div",{className:"home-prompt__reference-strip",role:"group","aria-label":i("home.referenceTrayAria",{count:p.length}),children:[e.jsx("span",{className:"home-prompt__reference-thumbs","aria-hidden":"true",children:p.map(t=>{const u=V(t);return e.jsx("span",{className:"home-prompt__reference-thumb",children:u?e.jsx("img",{src:u,alt:"",loading:"lazy",decoding:"async"}):"@"},t.tokenId)})}),e.jsx("span",{className:"home-prompt__reference-count",children:i("home.referenceTrayCount",{count:p.length})})]}):null,e.jsxs("div",{className:`home-prompt__panes${d?" home-prompt__panes--dual":""}`,children:[e.jsxs("div",{className:"home-prompt__pane",children:[e.jsx("label",{className:"home-prompt__label",htmlFor:"home-prompt-input",children:i(d?"nai.positivePrompt.label":"prompt.label")}),e.jsx("textarea",{id:"home-prompt-input",className:"home-prompt__textarea",rows:5,value:s,placeholder:i(d?"nai.positivePrompt.placeholder":"prompt.placeholder"),"aria-describedby":d?"home-prompt-hint":void 0,onChange:t=>r(t.target.value),onKeyDown:t=>{t.key!=="Enter"||!(t.metaKey||t.ctrlKey)||(t.preventDefault(),v())}}),d?e.jsx("p",{id:"home-prompt-hint",className:"home-prompt__hint",children:i("nai.positivePrompt.hint",{count:s.length})}):null]}),e.jsx(w,{variant:"home",onSubmit:v})]}),e.jsxs("div",{className:"home-prompt__footer",children:[e.jsx(M,{className:"home-prompt__provider",items:A,value:n,onChange:a,ariaLabel:i("readiness.provider")}),e.jsx("button",{type:"button",className:"home-prompt__generate",disabled:x||s.trim().length===0,onClick:v,children:x?i("generate.buttonLoading",{n:g}):i("generate.button")})]})]})}const y=/\.(mp4|webm|mov)(?:$|[?#])/i;function B(o){return o.mediaType==="video"||y.test(o.filename??"")||y.test(o.url??o.image)?o.thumb:o.thumb||o.url||o.image||void 0}function F({item:o,featured:s}){const{t:r}=m(),[n,a]=j.useState(!1),c=B(o),_=(o.userPrompt?.trim()||o.prompt?.trim()||r("home.untitledResult")).slice(0,60),h=r("home.recentResultAlt",{prompt:_});return!c||n?e.jsx("div",{className:"home-recent-card__fallback",role:"img","aria-label":h,children:r("home.mediaUnavailable")}):e.jsx("img",{src:c,alt:h,loading:s?"eager":"lazy",decoding:"async",onError:()=>a(!0)})}function K(){const o=l(n=>n.history),{t:s}=m(),r=o.slice(0,5);return r.length===0?e.jsx("p",{className:"home-recent-empty",role:"status",children:s("history.emptyRecent")}):e.jsx("div",{className:"home-recent-row",role:"list","aria-label":s("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(F,{item:n,featured:c})},R(n))})})}function W(){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 z(){const{t:o}=m(),s=T(),r=j.useMemo(()=>Object.values(s).filter(a=>a?.ok).length,[s]),n=j.useMemo(()=>Object.keys(s).length,[s]);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:o("home.heroTitle")}),e.jsx("p",{className:"home-hero__lede",children:o("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?o("home.lanesReady",{ready:r,total:n}):o("home.lanesNone")]}),e.jsx("div",{className:"home-workspace__composer",children:e.jsx($,{providerAvailability:s})}),e.jsxs("section",{className:"home-workspace__recent","aria-labelledby":"home-recent-title",children:[e.jsx("h2",{id:"home-recent-title",children:o("home.recentTitle")}),e.jsx(K,{})]}),e.jsx(q,{})]})}function q(){const{t:o}=m(),s=l(a=>a.setUIMode),r=[{mode:"classic",label:o("nav.create"),hint:o("home.modeCreateHint"),enabled:!0,icon:C},{mode:"node",label:o("nav.node"),hint:o("home.modeNodeHint"),enabled:O,icon:L},{mode:"agent",label:o("nav.agent"),hint:o("home.modeAgentHint"),enabled:S,icon:H},{mode:"assets",label:o("nav.assets"),hint:o("home.modeAssetsHint"),enabled:!0,icon:G}];function n(a){s(a),history.replaceState(null,"",U[a]??"#create")}return e.jsxs("nav",{className:"home-modes","aria-label":o("home.modesTitle"),children:[e.jsx("h2",{className:"home-modes__title",children:o("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(W,{})]},a.mode))]})}function J(){const{t:o}=m();return e.jsx("section",{className:"home-workspace","aria-label":o("nav.home"),children:e.jsx("div",{className:"home-workspace__inner",children:e.jsx(z,{})})})}export{J as HomeWorkspace};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{u as re,a as _,b as q,q as fe,j as a,p as ge,aj as me,ak as pe,al as ye}from"./index-DueH_AmZ.js";import{u as xe}from"./useAgentDialogFocus-DPB8JITN.js";function ke(){return a.jsx("svg",{viewBox:"0 0 24 24",width:"18",height:"18","aria-hidden":"true",children:a.jsx("path",{d:"M6 6l12 12M18 6 6 18",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round"})})}function be({zoomed:e}){return a.jsxs("svg",{viewBox:"0 0 24 24",width:"18",height:"18","aria-hidden":"true",children:[a.jsx("circle",{cx:"10.5",cy:"10.5",r:"6.5",fill:"none",stroke:"currentColor",strokeWidth:"1.7"}),a.jsx("path",{d:"M15.5 15.5 21 21M7.5 10.5h6",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round"}),e?null:a.jsx("path",{d:"M10.5 7.5v6",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round"})]})}function Pe({item:e,onClose:t}){const{t:n}=re(),[o,s]=_.useState(!1),l=e.metadata??null,[y,c]=_.useState(l),u=_.useId(),g=q(f=>f.setKeyingTarget),h=q(f=>f.setVectorizeTarget),i=q(f=>f.setCuratorTarget),x=_.useCallback(()=>t(),[t]),r=xe(!0,x),m=e.mediaType==="video",v=e.kind!=="edit"&&!!e.filename&&e.backgroundPreset!=="transparent",b=l??y,j=typeof b?.spriteRunId=="string"?b.spriteRunId:null,P=typeof b?.manifestPath=="string"?b.manifestPath:null,D=!!(j&&P&&e.filename),K=!m&&!!e.filename&&!/\.svg$/i.test(e.filename??""),C=n(m?"assetGen.videoFallback":"assetGen.imageFallback"),U=e.prompt?.trim()||C,B=_.useCallback(()=>{g(e),t()},[e,t,g]),z=_.useCallback(()=>{h(e),t()},[e,t,h]),N=_.useCallback(()=>{!j||!P||!e.filename||(i({runId:j,atlasFile:e.filename,manifestFile:P}),t())},[e.filename,P,t,i,j]);return _.useEffect(()=>{c(l);const f=e.requestId?.startsWith("asset:")?e.requestId.slice(6):null;if(!f||l)return;let p=!0;return fe(f).then(({asset:M})=>{p&&c(M.metadata)}).catch(()=>{p&&c(null)}),()=>{p=!1}},[l,e.requestId]),_.useEffect(()=>{const f=document.body.style.overflow,p=document.documentElement.style.overflow;return document.body.style.overflow="hidden",document.documentElement.style.overflow="hidden",()=>{document.body.style.overflow=f,document.documentElement.style.overflow=p}},[]),a.jsxs("div",{className:"assetgen-lightbox",role:"presentation",children:[a.jsx("button",{type:"button",className:"assetgen-lightbox__backdrop","aria-label":n("assetGen.closePreview"),onClick:x}),a.jsxs("section",{ref:r,className:"assetgen-lightbox__panel",role:"dialog","aria-modal":"true","aria-labelledby":u,children:[a.jsxs("header",{className:"assetgen-lightbox__header",children:[a.jsx("h2",{id:u,children:n("assetGen.previewDialogTitle",{prompt:U})}),a.jsx("button",{type:"button",className:"assetgen-lightbox__control","aria-label":n("assetGen.closePreview"),onClick:x,children:a.jsx(ke,{})})]}),a.jsx("div",{className:["assetgen-lightbox__stage",e.kind==="edit"?"is-keyed":"",o?"is-zoomed":""].filter(Boolean).join(" "),tabIndex:o?0:void 0,children:m?a.jsx("video",{src:e.url||e.image,poster:e.thumb||void 0,controls:!0,autoPlay:!0,muted:!0,playsInline:!0,preload:"metadata","aria-label":U}):a.jsx("img",{src:e.url||e.image,alt:U})}),!m||v||D?a.jsxs("footer",{className:"assetgen-lightbox__footer",children:[D?a.jsx("button",{type:"button",className:"assetgen-lightbox__zoom assetgen-lightbox__curate",onClick:N,children:n("spriteCurator.open")}):null,v?a.jsx("button",{type:"button",className:"assetgen-lightbox__zoom assetgen-lightbox__keybtn",onClick:B,children:n("keying.open")}):null,K?a.jsx("button",{type:"button",className:"assetgen-lightbox__zoom assetgen-lightbox__vectorbtn",onClick:z,children:n("vectorize.open")}):null,m?null:a.jsxs("button",{type:"button",className:"assetgen-lightbox__zoom","aria-pressed":o,"aria-label":n(o?"assetGen.zoomOut":"assetGen.zoomIn"),onClick:()=>s(f=>!f),children:[a.jsx(be,{zoomed:o}),a.jsx("span",{children:n(o?"assetGen.zoomOut":"assetGen.zoomIn")})]})]}):null]})]})}const Y={tolerance:40,softness:10,spill:50};function te(e,t,n){const o=128-.168736*e-.331264*t+.5*n,s=128+.5*e-.418688*t-.081312*n;return[o,s]}function ne(e,t,n){return .299*e+.587*t+.114*n}function _e(e,t,n,o){const s=t*n,l=new Uint8Array(s);for(let i=0;i<s;i++)e[i]<o&&(l[i]=1);const y=new Uint8Array(s),c=new Int32Array(s);let u=0,g=0;const h=i=>{l[i]&&!y[i]&&(y[i]=1,c[g++]=i)};for(let i=0;i<t;i++)h(i),h((n-1)*t+i);for(let i=0;i<n;i++)h(i*t),h(i*t+t-1);for(;u<g;){const i=c[u++],x=i%t,r=(i-x)/t;x>0&&h(i-1),x<t-1&&h(i+1),r>0&&h(i-t),r<n-1&&h(i+t)}for(let i=0;i<s;i++)l[i]&&!y[i]&&(e[i]=o)}function oe(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 s=4,l=[0,Math.max(0,t-s)],y=[0,Math.max(0,n-s)],c=[],u=[],g=[];for(const i of l)for(const x of y)for(let r=x;r<Math.min(x+s,n);r++)for(let m=i;m<Math.min(i+s,t);m++){const v=(r*t+m)*4;c.push(o[v]),u.push(o[v+1]),g.push(o[v+2])}const h=i=>{const x=[...i].sort((r,m)=>r-m);return x[Math.floor(x.length/2)]};return{r:h(c),g:h(u),b:h(g)}}function ve(e,t){const{width:n,height:o,data:s}=e;if(!n||!o||s.length!==n*o*4)throw new Error("colorKey: empty or malformed pixel buffer");const l=Math.max(0,Math.min(100,t.tolerance)),y=Math.max(0,Math.min(50,t.softness)),c=Math.max(0,Math.min(100,t.spill))/100,u=l/100*120,g=u+y/100*120,[h,i]=te(t.keyColor.r,t.keyColor.g,t.keyColor.b),x=t.keyColor.r,r=t.keyColor.g,m=t.keyColor.b,v=r>x+20&&r>m+20&&r>60,j=Math.max(x,r,m)-Math.min(x,r,m)<40,P=ne(x,r,m),D=10+l/100*15,K=400,C=n*o,U=new Float32Array(C);for(let f=0;f<C;f++){const p=f*4,M=s[p],I=s[p+1],S=s[p+2],[F,R]=te(M,I,S),w=Math.hypot(F-h,R-i);if(j)if(w>D)U[f]=K;else{const E=Math.abs(ne(M,I,S)-P)*.8;U[f]=Math.hypot(w,E)}else U[f]=w}const B=new Float32Array(C);for(let f=0;f<o;f++)for(let p=0;p<n;p++){const M=f*n+p;if(U[M]>=K){B[M]=K;continue}let I=0,S=0;for(let F=-1;F<=1;F++){const R=f+F;if(!(R<0||R>=o))for(let w=-1;w<=1;w++){const E=p+w;if(E<0||E>=n)continue;const L=U[R*n+E];L>=K||(I+=L,S++)}}B[M]=S>0?I/S:K}j&&_e(B,n,o,g);const z=g+c*120,N=new Uint8ClampedArray(s.length);for(let f=0;f<C;f++){const p=f*4,M=s[p],I=s[p+1],S=s[p+2],F=s[p+3],R=B[f];let w;R<=u?w=0:R<g?w=Math.pow((R-u)/(g-u),1.5)*255:w=255;let E=M,L=I,G=S;if(v&&c>0&&w>0){const H=z>u?Math.max(0,1-(R-u)/(z-u)):0;if(H>0){const X=(M+S)/2,d=Math.max(0,I-X)*H*c;L=Math.round(I-d);const k=d*.3;E=Math.min(255,Math.round(M+k)),G=Math.min(255,Math.round(S+k))}}N[p]=E,N[p+1]=L,N[p+2]=G,N[p+3]=Math.min(F,Math.round(w))}if(v&&c>0){let f=new Uint8Array(C);for(let p=0;p<o;p++)for(let M=0;M<n;M++){const I=p*n+M;if(N[I*4+3]===0)continue;let S=!1;e:for(let F=-1;F<=1;F++){const R=p+F;if(!(R<0||R>=o))for(let w=-1;w<=1;w++){const E=M+w;if(!(E<0||E>=n)&&N[(R*n+E)*4+3]===0){S=!0;break e}}}S&&(f[I]=1)}for(let p=0;p<3;p++){const M=new Uint8Array(C);for(let I=0;I<o;I++)for(let S=0;S<n;S++){const F=I*n+S;if(f[F]){M[F]=1;continue}if(N[F*4+3]===0)continue;let R=!1;for(let w=-1;w<=1&&!R;w++){const E=I+w;if(!(E<0||E>=o))for(let L=-1;L<=1&&!R;L++){const G=S+L;G<0||G>=n||f[E*n+G]&&(R=!0)}}R&&(M[F]=1)}f=M}for(let p=0;p<C;p++){if(!f[p])continue;const M=p*4,I=N[M],S=N[M+1],F=N[M+2],R=Math.max(I,F);if(S>R-8){const w=Math.max(0,R-4),E=Math.max(0,S-w);N[M+1]=Math.max(0,S-E),N[M]=Math.min(255,I+Math.round(E*.25)),N[M+2]=Math.min(255,F+Math.round(E*.25))}}}return{width:n,height:o,data:N}}function Me(e){return Math.round(Math.max(0,Math.min(100,e))*.7)}function ae(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 we(e,t,n,o){for(const s of n)if(Math.max(Math.abs(e[t]-s.r),Math.abs(e[t+1]-s.g),Math.abs(e[t+2]-s.b))<=o)return!0;return!1}function je(e,t,n){const{width:o,height:s,data:l}=e,y=o*s,c=new Uint8Array(y),u=new Uint8Array(y),g=new Int32Array(y),h=t.map(r=>{const m=ae(r,o,s)*4;return{r:l[m],g:l[m+1],b:l[m+2]}});let i=0;const x=r=>{u[r]||(u[r]=1,l[r*4+3]!==0&&we(l,r*4,h,n)&&(g[i++]=r))};for(const r of t)x(ae(r,o,s));for(;i>0;){const r=g[--i];c[r]=1;const m=r%o;m>0&&x(r-1),m<o-1&&x(r+1),r>=o&&x(r-o),r<y-o&&x(r+o)}return c}function Ce(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 s=je(t,n,Me(o));for(let l=0;l<s.length;l++)s[l]&&(e.data[l*4+3]=0)}const Ne={reach:4,spillMaxFraction:.005},ie=18,Se=180,Ee=40,Ae=2,J=0,Ie=1,le=2,ce=3;function Q(e){const t=[e.r,e.g,e.b],n=[],o=[];for(let s=0;s<3;s++)if(t[s]>=192)n.push(s);else if(t[s]<64)o.push(s);else return null;return n.length===0||o.length===0?null:{keyed:n,unkeyed:o}}function W(e,t,n,o){const s=[e,t,n];let l=0;for(const c of o.keyed)l+=s[c];let y=0;for(const c of o.unkeyed)y+=s[c];return l/o.keyed.length-y/o.unkeyed.length}function Re(e,t,n,o){return Math.hypot(e-o.r,t-o.g,n-o.b)}function ue(e,t,n,o,s,l){const y=Math.min(l/s,1),c=1-y;if(c<=0)return[0,0,0,0];const u=(g,h)=>Math.min(255,Math.max(0,Math.round((g-y*h)/c)));return[c,u(e,o.r),u(t,o.g),u(n,o.b)]}function Te(e,t,n,o){const s=t*n,l=255,y=new Uint8Array(s).fill(l);let c=[];for(let g=0;g<s;g++)e[g]&&(y[g]=0,c.push(g));let u=0;for(;c.length>0&&u<o;){u++;const g=[];for(const h of c){const i=h%t,x=(h-i)/t;for(let r=-1;r<=1;r++){const m=x+r;if(!(m<0||m>=n))for(let v=-1;v<=1;v++){const b=i+v;if(b<0||b>=t)continue;const j=m*t+b;y[j]===l&&(y[j]=u,g.push(j))}}}c=g}return y}function Ue(e,t,n,o){const s=e.width*e.height,l=new Uint8Array(s),y=new Uint8Array(s);for(let c=0;c<s;c++){const u=c*4;if(t.data[u+3]===0){l[c]=J,y[c]=1;continue}const g=e.data[u],h=e.data[u+1],i=e.data[u+2];W(g,h,i,o)<ie?l[c]=Ie:Re(g,h,i,n)<=Se?l[c]=le:l[c]=ce}return{classes:l,keyedMask:y}}function Fe(e,t,n,o,s,l,y,c){const u=t.width*t.height,g=new Uint8Array(u);for(let h=0;h<u;h++){const i=l[h];if(!(i>0&&i<=c))continue;const x=y[h];if(x===le){if(i>Ae)continue}else if(x!==ce)continue;const r=h*4,m=t.data[r],v=t.data[r+1],b=t.data[r+2],j=W(m,v,b,o),[P,D,K,C]=ue(m,v,b,n,s,j),U=Math.round(t.data[r+3]*P);U<=0?(e.data[r]=0,e.data[r+1]=0,e.data[r+2]=0,e.data[r+3]=0):(e.data[r]=D,e.data[r+1]=K,e.data[r+2]=C,e.data[r+3]=U),g[h]=1}return g}function De(e,t,n,o,s,l,y,c){const{width:u,height:g}=t,h=u*g;let i=0;for(let b=0;b<h;b++)l[b]!==J&&i++;const x=Math.max(32,Math.round(i*c)),r=new Float32Array(h).fill(-1);for(let b=0;b<h;b++){if(y[b]||l[b]===J)continue;const j=b*4;if(e.data[j+3]===0)continue;const P=W(t.data[j],t.data[j+1],t.data[j+2],o);P>=ie&&(r[b]=P)}const m=new Uint8Array(h),v=[];for(let b=0;b<h;b++){if(r[b]<0||m[b])continue;m[b]=1,v.length=0,v.push(b);const j=[];let P=-1;for(;v.length>0;){const D=v.pop();j.push(D),r[D]>P&&(P=r[D]);const K=D%u,C=(D-K)/u;for(let U=-1;U<=1;U++){const B=C+U;if(!(B<0||B>=g))for(let z=-1;z<=1;z++){const N=K+z;if(N<0||N>=u)continue;const f=B*u+N;r[f]>=0&&!m[f]&&(m[f]=1,v.push(f))}}}if(!(j.length>x)&&!(P<=Ee))for(const D of j){const K=D*4,C=t.data[K],U=t.data[K+1],B=t.data[K+2],[z,N,f,p]=ue(C,U,B,n,s,r[D]);z<=0||(e.data[K]=N,e.data[K+1]=f,e.data[K+2]=p)}}}function Ke(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 s=W(n.keyColor.r,n.keyColor.g,n.keyColor.b,o);if(s<=0)return;const l=Math.max(0,Math.min(254,Math.round(n.reach))),{classes:y,keyedMask:c}=Ue(t,e,n.keyColor,o);let u;if(l>0){const g=Te(c,t.width,t.height,l);u=Fe(e,t,n.keyColor,o,s,g,y,l)}else u=new Uint8Array(t.width*t.height);n.spillMaxFraction>0&&De(e,t,n.keyColor,o,s,y,u,n.spillMaxFraction)}function se(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 ze(){const{t:e}=re(),t=q(d=>d.keyingTarget),n=q(d=>d.setKeyingTarget),o=ge(!!t,()=>n(null)),s=q(d=>d.addAssetGenDerivedItem),l=q(d=>d.selectedProjectId),y=q(d=>d.showToast),[c,u]=_.useState("loading"),[g,h]=_.useState(!1),[i,x]=_.useState(null),[r,m]=_.useState(null),[v,b]=_.useState(Y.tolerance),[j,P]=_.useState(Y.softness),[D,K]=_.useState(Y.spill),[C,U]=_.useState(null),[B,z]=_.useState("erase"),[N,f]=_.useState([]),[p,M]=_.useState(!0),I=_.useRef(null),S=_.useRef(null),F=_.useRef(0),R=_.useRef(null),w=_.useRef(null),E=_.useCallback(()=>{R.current?.(),R.current=null},[]),L=t?.mediaType==="video",G=t?L&&t.filename?`/api/video/frame?file=${encodeURIComponent(t.filename)}&position=0`:t.url||t.image:null;_.useEffect(()=>{if(!G)return;let d=!0;u("loading"),I.current=null,U(null),f([]),z("erase");const k=new Image;return k.onload=()=>{if(d)try{const A=document.createElement("canvas");A.width=k.naturalWidth,A.height=k.naturalHeight;const T=A.getContext("2d");if(!T)throw new Error("no 2d context");T.drawImage(k,0,0);const O=T.getImageData(0,0,A.width,A.height);I.current=O,U(oe(O)),u("ready")}catch{d&&u("error")}},k.onerror=()=>{d&&u("error")},k.src=G,()=>{d=!1,k.onload=null,k.onerror=null}},[G]),_.useEffect(()=>(w.current=t?.filename??null,E(),h(!1),m(null),x(null),E),[E,t?.filename]),_.useEffect(()=>{if(!(c!=="ready"||!C))return cancelAnimationFrame(F.current),F.current=requestAnimationFrame(()=>{const d=I.current,k=S.current;if(!(!d||!k))try{const A=ve({width:d.width,height:d.height,data:d.data},{keyColor:C,tolerance:v,softness:j,spill:D});p&&Q(C)&&Ke(A,{width:d.width,height:d.height,data:d.data},{keyColor:C,...Ne}),N.length>0&&Ce(A,{width:d.width,height:d.height,data:d.data},N,v),k.width=A.width,k.height=A.height;const T=k.getContext("2d");if(!T)return;const O=T.createImageData(A.width,A.height);O.data.set(A.data),T.putImageData(O,0,0)}catch{u("error")}}),()=>cancelAnimationFrame(F.current)},[c,C,v,j,D,N,p]);const H=_.useCallback(d=>{const k=I.current,A=S.current;if(!k||!A)return;const T=A.getBoundingClientRect(),O=Math.max(0,Math.min(1,(d.clientX-T.left)/T.width)),V=Math.max(0,Math.min(1,(d.clientY-T.top)/T.height));if(B==="erase"&&!L){f(he=>[...he,{x:O,y:V}]);return}const $=Math.floor((d.clientX-T.left)/T.width*k.width),de=Math.floor((d.clientY-T.top)/T.height*k.height),Z=(Math.max(0,Math.min(k.height-1,de))*k.width+Math.max(0,Math.min(k.width-1,$)))*4;U({r:k.data[Z],g:k.data[Z+1],b:k.data[Z+2]})},[B,L]),X=_.useCallback(()=>{const d=S.current;d&&d.toBlob(k=>{if(!k)return;const A=URL.createObjectURL(k),T=document.createElement("a");T.href=A,T.download=`${(t?.filename||"asset").replace(/\.[a-z]+$/i,"")}-keyed.png`,T.click(),URL.revokeObjectURL(A)},"image/png")},[t]),ee=_.useCallback(()=>{const d=S.current;if(!(!d||!t?.filename||g)){if(h(!0),x(null),L){me({source:t.filename,keyParams:{tolerance:v,softness:j,keyColor:C??void 0},projectId:l,name:`${(t.prompt||"asset").trim().slice(0,60)} (keyed)`}).then(({requestId:k})=>{if(w.current!==t.filename)return;m(0),E();const A=pe(k,null,(T,O)=>{const V=O&&typeof O=="object"?O:{};if(T==="keying-progress"){const $=V.outTimeMs;m(typeof $=="number"&&Number.isFinite($)?$:0)}else if(T==="keying-done"){E();const $=V.filePath;if(typeof $=="string"&&$.trim()){s(se(t,$.trim(),"video")),h(!1),m(null),y(e("keying.videoSaved")),n(null);return}h(!1),m(null),x(e("keying.saveError"))}else T==="keying-error"&&(E(),h(!1),m(null),x(typeof V.error=="string"&&V.error?V.error:e("keying.saveError")))});R.current=A}).catch(k=>{w.current===t.filename&&(h(!1),x(k instanceof Error?k.message:e("keying.saveError")))});return}d.toBlob(k=>{if(w.current===t.filename){if(!k){h(!1),x(e("keying.saveError"));return}ye(k,{source:t.filename,projectId:l,name:`${(t.prompt||"asset").trim().slice(0,60)} (keyed)`,meta:{keyParams:{tolerance:v,softness:j,spill:D},prompt:t.prompt}}).then(({filePath:A})=>{if(w.current===t.filename){if(typeof A!="string"||!A.trim())throw new Error(e("keying.saveError"));s(se(t,A.trim(),"image")),y(e("keying.saved")),n(null)}}).catch(A=>{w.current===t.filename&&x(A instanceof Error?A.message:e("keying.saveError"))}).finally(()=>{w.current===t.filename&&h(!1)})}},"image/png")}},[t,g,L,C,l,v,j,D,E,s,y,n,e]);return t?a.jsx("div",{className:"assetgen-popup-backdrop",onClick:()=>n(null),children:a.jsxs("div",{ref:o,className:"keying-panel",role:"dialog","aria-modal":"true","aria-label":e("keying.title"),onClick:d=>d.stopPropagation(),children:[a.jsxs("header",{className:"keying-panel__head",children:[a.jsx("h2",{children:e("keying.title")}),C?a.jsxs("span",{className:"keying-panel__key",title:e("keying.keyColor"),children:[L?null:a.jsxs("span",{className:"keying-panel__modes",role:"group","aria-label":e("keying.clickMode"),children:[a.jsx("button",{type:"button",className:B==="erase"?"is-active":"","aria-pressed":B==="erase",onClick:()=>z("erase"),children:e("keying.modeErase")}),a.jsx("button",{type:"button",className:B==="pick"?"is-active":"","aria-pressed":B==="pick",onClick:()=>z("pick"),children:e("keying.modePick")})]}),N.length>0?a.jsx("button",{type:"button",className:"keying-panel__undo",onClick:()=>f(d=>d.slice(0,-1)),children:e("keying.undoClick",{count:String(N.length)})}):null,a.jsx("span",{className:"assetgen-bg-picker__swatch",style:{background:`rgb(${C.r},${C.g},${C.b})`},"aria-hidden":"true"}),a.jsx("span",{className:"keying-panel__hint",children:e(B==="erase"&&!L?"keying.eraseHint":"keying.pickHint")})]}):null]}),a.jsx("div",{className:"keying-panel__compare","aria-busy":c==="loading",children:c==="error"?a.jsxs("div",{className:"keying-panel__error",role:"alert",children:[a.jsx("p",{children:e("keying.loadError")}),a.jsx("button",{type:"button",onClick:()=>n(null),children:e("project.close")})]}):a.jsxs(a.Fragment,{children:[a.jsxs("figure",{className:"keying-panel__preview",children:[a.jsx("figcaption",{className:"keying-panel__preview-label",children:e("keying.original")}),a.jsx("div",{className:"keying-panel__stage keying-panel__stage--original",children:a.jsx("img",{src:G??"",alt:e("keying.originalAlt")})})]}),a.jsxs("figure",{className:"keying-panel__preview",children:[a.jsx("figcaption",{className:"keying-panel__preview-label",children:e("keying.removed")}),a.jsxs("div",{className:"keying-panel__stage",children:[a.jsx("canvas",{ref:S,className:"keying-panel__canvas",onClick:H,"aria-label":e("keying.previewAlt")}),c==="loading"?a.jsx("span",{className:"keying-panel__loading",role:"status",children:e("keying.previewLoading")}):null]})]})]})}),a.jsxs("details",{className:"keying-panel__advanced",children:[a.jsx("summary",{children:e("keying.advanced")}),a.jsxs("div",{className:"keying-panel__controls",children:[a.jsxs("label",{children:[e("keying.tolerance")," ",a.jsx("output",{children:v}),a.jsx("input",{type:"range",min:0,max:100,value:v,onChange:d=>b(Number(d.target.value))})]}),a.jsxs("label",{children:[e("keying.softness")," ",a.jsx("output",{children:j}),a.jsx("input",{type:"range",min:0,max:50,value:j,onChange:d=>P(Number(d.target.value))})]}),a.jsxs("label",{children:[e("keying.spill")," ",a.jsx("output",{children:D}),a.jsx("input",{type:"range",min:0,max:100,value:D,onChange:d=>K(Number(d.target.value))})]}),a.jsxs("label",{className:"keying-panel__unmix",children:[a.jsx("input",{type:"checkbox",checked:p,disabled:!C||!Q(C),onChange:d=>M(d.target.checked)}),e("keying.unmix"),a.jsx("span",{className:"keying-panel__hint",children:e("keying.unmixHint")})]}),a.jsx("button",{type:"button",className:"keying-panel__reset",onClick:()=>{b(Y.tolerance),P(Y.softness),K(Y.spill),f([]),M(!0),I.current&&U(oe(I.current))},children:e("keying.reset")})]})]}),a.jsxs("footer",{className:"keying-panel__actions",children:[i?a.jsx("span",{className:"keying-panel__save-error",role:"alert",children:i}):null,a.jsx("button",{type:"button",className:"assetgen-generate",disabled:c!=="ready"||g||!t.filename,onClick:ee,children:g?r!==null?e("keying.videoKeying",{seconds:String(Math.round(r/1e3))}):e("keying.saving"):e(L?"keying.videoSave":"keying.save")}),L?null:a.jsx("button",{type:"button",className:"assetgen-popup__close",disabled:c!=="ready",onClick:X,children:e("keying.download")}),a.jsx("button",{type:"button",className:"assetgen-popup__close",onClick:()=>n(null),children:e("project.close")})]})]})}):null}export{Pe as A,ze as K};
|
|
1
|
+
import{u as re,a as _,b as q,q as fe,j as a,p as ge,aj as me,ak as pe,al as ye}from"./index-BbykeXR9.js";import{u as xe}from"./useAgentDialogFocus-B6-QgEVI.js";function ke(){return a.jsx("svg",{viewBox:"0 0 24 24",width:"18",height:"18","aria-hidden":"true",children:a.jsx("path",{d:"M6 6l12 12M18 6 6 18",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round"})})}function be({zoomed:e}){return a.jsxs("svg",{viewBox:"0 0 24 24",width:"18",height:"18","aria-hidden":"true",children:[a.jsx("circle",{cx:"10.5",cy:"10.5",r:"6.5",fill:"none",stroke:"currentColor",strokeWidth:"1.7"}),a.jsx("path",{d:"M15.5 15.5 21 21M7.5 10.5h6",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round"}),e?null:a.jsx("path",{d:"M10.5 7.5v6",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round"})]})}function Pe({item:e,onClose:t}){const{t:n}=re(),[o,s]=_.useState(!1),l=e.metadata??null,[y,c]=_.useState(l),u=_.useId(),g=q(f=>f.setKeyingTarget),h=q(f=>f.setVectorizeTarget),i=q(f=>f.setCuratorTarget),x=_.useCallback(()=>t(),[t]),r=xe(!0,x),m=e.mediaType==="video",v=e.kind!=="edit"&&!!e.filename&&e.backgroundPreset!=="transparent",b=l??y,j=typeof b?.spriteRunId=="string"?b.spriteRunId:null,P=typeof b?.manifestPath=="string"?b.manifestPath:null,D=!!(j&&P&&e.filename),K=!m&&!!e.filename&&!/\.svg$/i.test(e.filename??""),C=n(m?"assetGen.videoFallback":"assetGen.imageFallback"),U=e.prompt?.trim()||C,B=_.useCallback(()=>{g(e),t()},[e,t,g]),z=_.useCallback(()=>{h(e),t()},[e,t,h]),N=_.useCallback(()=>{!j||!P||!e.filename||(i({runId:j,atlasFile:e.filename,manifestFile:P}),t())},[e.filename,P,t,i,j]);return _.useEffect(()=>{c(l);const f=e.requestId?.startsWith("asset:")?e.requestId.slice(6):null;if(!f||l)return;let p=!0;return fe(f).then(({asset:M})=>{p&&c(M.metadata)}).catch(()=>{p&&c(null)}),()=>{p=!1}},[l,e.requestId]),_.useEffect(()=>{const f=document.body.style.overflow,p=document.documentElement.style.overflow;return document.body.style.overflow="hidden",document.documentElement.style.overflow="hidden",()=>{document.body.style.overflow=f,document.documentElement.style.overflow=p}},[]),a.jsxs("div",{className:"assetgen-lightbox",role:"presentation",children:[a.jsx("button",{type:"button",className:"assetgen-lightbox__backdrop","aria-label":n("assetGen.closePreview"),onClick:x}),a.jsxs("section",{ref:r,className:"assetgen-lightbox__panel",role:"dialog","aria-modal":"true","aria-labelledby":u,children:[a.jsxs("header",{className:"assetgen-lightbox__header",children:[a.jsx("h2",{id:u,children:n("assetGen.previewDialogTitle",{prompt:U})}),a.jsx("button",{type:"button",className:"assetgen-lightbox__control","aria-label":n("assetGen.closePreview"),onClick:x,children:a.jsx(ke,{})})]}),a.jsx("div",{className:["assetgen-lightbox__stage",e.kind==="edit"?"is-keyed":"",o?"is-zoomed":""].filter(Boolean).join(" "),tabIndex:o?0:void 0,children:m?a.jsx("video",{src:e.url||e.image,poster:e.thumb||void 0,controls:!0,autoPlay:!0,muted:!0,playsInline:!0,preload:"metadata","aria-label":U}):a.jsx("img",{src:e.url||e.image,alt:U})}),!m||v||D?a.jsxs("footer",{className:"assetgen-lightbox__footer",children:[D?a.jsx("button",{type:"button",className:"assetgen-lightbox__zoom assetgen-lightbox__curate",onClick:N,children:n("spriteCurator.open")}):null,v?a.jsx("button",{type:"button",className:"assetgen-lightbox__zoom assetgen-lightbox__keybtn",onClick:B,children:n("keying.open")}):null,K?a.jsx("button",{type:"button",className:"assetgen-lightbox__zoom assetgen-lightbox__vectorbtn",onClick:z,children:n("vectorize.open")}):null,m?null:a.jsxs("button",{type:"button",className:"assetgen-lightbox__zoom","aria-pressed":o,"aria-label":n(o?"assetGen.zoomOut":"assetGen.zoomIn"),onClick:()=>s(f=>!f),children:[a.jsx(be,{zoomed:o}),a.jsx("span",{children:n(o?"assetGen.zoomOut":"assetGen.zoomIn")})]})]}):null]})]})}const Y={tolerance:40,softness:10,spill:50};function te(e,t,n){const o=128-.168736*e-.331264*t+.5*n,s=128+.5*e-.418688*t-.081312*n;return[o,s]}function ne(e,t,n){return .299*e+.587*t+.114*n}function _e(e,t,n,o){const s=t*n,l=new Uint8Array(s);for(let i=0;i<s;i++)e[i]<o&&(l[i]=1);const y=new Uint8Array(s),c=new Int32Array(s);let u=0,g=0;const h=i=>{l[i]&&!y[i]&&(y[i]=1,c[g++]=i)};for(let i=0;i<t;i++)h(i),h((n-1)*t+i);for(let i=0;i<n;i++)h(i*t),h(i*t+t-1);for(;u<g;){const i=c[u++],x=i%t,r=(i-x)/t;x>0&&h(i-1),x<t-1&&h(i+1),r>0&&h(i-t),r<n-1&&h(i+t)}for(let i=0;i<s;i++)l[i]&&!y[i]&&(e[i]=o)}function oe(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 s=4,l=[0,Math.max(0,t-s)],y=[0,Math.max(0,n-s)],c=[],u=[],g=[];for(const i of l)for(const x of y)for(let r=x;r<Math.min(x+s,n);r++)for(let m=i;m<Math.min(i+s,t);m++){const v=(r*t+m)*4;c.push(o[v]),u.push(o[v+1]),g.push(o[v+2])}const h=i=>{const x=[...i].sort((r,m)=>r-m);return x[Math.floor(x.length/2)]};return{r:h(c),g:h(u),b:h(g)}}function ve(e,t){const{width:n,height:o,data:s}=e;if(!n||!o||s.length!==n*o*4)throw new Error("colorKey: empty or malformed pixel buffer");const l=Math.max(0,Math.min(100,t.tolerance)),y=Math.max(0,Math.min(50,t.softness)),c=Math.max(0,Math.min(100,t.spill))/100,u=l/100*120,g=u+y/100*120,[h,i]=te(t.keyColor.r,t.keyColor.g,t.keyColor.b),x=t.keyColor.r,r=t.keyColor.g,m=t.keyColor.b,v=r>x+20&&r>m+20&&r>60,j=Math.max(x,r,m)-Math.min(x,r,m)<40,P=ne(x,r,m),D=10+l/100*15,K=400,C=n*o,U=new Float32Array(C);for(let f=0;f<C;f++){const p=f*4,M=s[p],I=s[p+1],S=s[p+2],[F,R]=te(M,I,S),w=Math.hypot(F-h,R-i);if(j)if(w>D)U[f]=K;else{const E=Math.abs(ne(M,I,S)-P)*.8;U[f]=Math.hypot(w,E)}else U[f]=w}const B=new Float32Array(C);for(let f=0;f<o;f++)for(let p=0;p<n;p++){const M=f*n+p;if(U[M]>=K){B[M]=K;continue}let I=0,S=0;for(let F=-1;F<=1;F++){const R=f+F;if(!(R<0||R>=o))for(let w=-1;w<=1;w++){const E=p+w;if(E<0||E>=n)continue;const L=U[R*n+E];L>=K||(I+=L,S++)}}B[M]=S>0?I/S:K}j&&_e(B,n,o,g);const z=g+c*120,N=new Uint8ClampedArray(s.length);for(let f=0;f<C;f++){const p=f*4,M=s[p],I=s[p+1],S=s[p+2],F=s[p+3],R=B[f];let w;R<=u?w=0:R<g?w=Math.pow((R-u)/(g-u),1.5)*255:w=255;let E=M,L=I,G=S;if(v&&c>0&&w>0){const H=z>u?Math.max(0,1-(R-u)/(z-u)):0;if(H>0){const X=(M+S)/2,d=Math.max(0,I-X)*H*c;L=Math.round(I-d);const k=d*.3;E=Math.min(255,Math.round(M+k)),G=Math.min(255,Math.round(S+k))}}N[p]=E,N[p+1]=L,N[p+2]=G,N[p+3]=Math.min(F,Math.round(w))}if(v&&c>0){let f=new Uint8Array(C);for(let p=0;p<o;p++)for(let M=0;M<n;M++){const I=p*n+M;if(N[I*4+3]===0)continue;let S=!1;e:for(let F=-1;F<=1;F++){const R=p+F;if(!(R<0||R>=o))for(let w=-1;w<=1;w++){const E=M+w;if(!(E<0||E>=n)&&N[(R*n+E)*4+3]===0){S=!0;break e}}}S&&(f[I]=1)}for(let p=0;p<3;p++){const M=new Uint8Array(C);for(let I=0;I<o;I++)for(let S=0;S<n;S++){const F=I*n+S;if(f[F]){M[F]=1;continue}if(N[F*4+3]===0)continue;let R=!1;for(let w=-1;w<=1&&!R;w++){const E=I+w;if(!(E<0||E>=o))for(let L=-1;L<=1&&!R;L++){const G=S+L;G<0||G>=n||f[E*n+G]&&(R=!0)}}R&&(M[F]=1)}f=M}for(let p=0;p<C;p++){if(!f[p])continue;const M=p*4,I=N[M],S=N[M+1],F=N[M+2],R=Math.max(I,F);if(S>R-8){const w=Math.max(0,R-4),E=Math.max(0,S-w);N[M+1]=Math.max(0,S-E),N[M]=Math.min(255,I+Math.round(E*.25)),N[M+2]=Math.min(255,F+Math.round(E*.25))}}}return{width:n,height:o,data:N}}function Me(e){return Math.round(Math.max(0,Math.min(100,e))*.7)}function ae(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 we(e,t,n,o){for(const s of n)if(Math.max(Math.abs(e[t]-s.r),Math.abs(e[t+1]-s.g),Math.abs(e[t+2]-s.b))<=o)return!0;return!1}function je(e,t,n){const{width:o,height:s,data:l}=e,y=o*s,c=new Uint8Array(y),u=new Uint8Array(y),g=new Int32Array(y),h=t.map(r=>{const m=ae(r,o,s)*4;return{r:l[m],g:l[m+1],b:l[m+2]}});let i=0;const x=r=>{u[r]||(u[r]=1,l[r*4+3]!==0&&we(l,r*4,h,n)&&(g[i++]=r))};for(const r of t)x(ae(r,o,s));for(;i>0;){const r=g[--i];c[r]=1;const m=r%o;m>0&&x(r-1),m<o-1&&x(r+1),r>=o&&x(r-o),r<y-o&&x(r+o)}return c}function Ce(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 s=je(t,n,Me(o));for(let l=0;l<s.length;l++)s[l]&&(e.data[l*4+3]=0)}const Ne={reach:4,spillMaxFraction:.005},ie=18,Se=180,Ee=40,Ae=2,J=0,Ie=1,le=2,ce=3;function Q(e){const t=[e.r,e.g,e.b],n=[],o=[];for(let s=0;s<3;s++)if(t[s]>=192)n.push(s);else if(t[s]<64)o.push(s);else return null;return n.length===0||o.length===0?null:{keyed:n,unkeyed:o}}function W(e,t,n,o){const s=[e,t,n];let l=0;for(const c of o.keyed)l+=s[c];let y=0;for(const c of o.unkeyed)y+=s[c];return l/o.keyed.length-y/o.unkeyed.length}function Re(e,t,n,o){return Math.hypot(e-o.r,t-o.g,n-o.b)}function ue(e,t,n,o,s,l){const y=Math.min(l/s,1),c=1-y;if(c<=0)return[0,0,0,0];const u=(g,h)=>Math.min(255,Math.max(0,Math.round((g-y*h)/c)));return[c,u(e,o.r),u(t,o.g),u(n,o.b)]}function Te(e,t,n,o){const s=t*n,l=255,y=new Uint8Array(s).fill(l);let c=[];for(let g=0;g<s;g++)e[g]&&(y[g]=0,c.push(g));let u=0;for(;c.length>0&&u<o;){u++;const g=[];for(const h of c){const i=h%t,x=(h-i)/t;for(let r=-1;r<=1;r++){const m=x+r;if(!(m<0||m>=n))for(let v=-1;v<=1;v++){const b=i+v;if(b<0||b>=t)continue;const j=m*t+b;y[j]===l&&(y[j]=u,g.push(j))}}}c=g}return y}function Ue(e,t,n,o){const s=e.width*e.height,l=new Uint8Array(s),y=new Uint8Array(s);for(let c=0;c<s;c++){const u=c*4;if(t.data[u+3]===0){l[c]=J,y[c]=1;continue}const g=e.data[u],h=e.data[u+1],i=e.data[u+2];W(g,h,i,o)<ie?l[c]=Ie:Re(g,h,i,n)<=Se?l[c]=le:l[c]=ce}return{classes:l,keyedMask:y}}function Fe(e,t,n,o,s,l,y,c){const u=t.width*t.height,g=new Uint8Array(u);for(let h=0;h<u;h++){const i=l[h];if(!(i>0&&i<=c))continue;const x=y[h];if(x===le){if(i>Ae)continue}else if(x!==ce)continue;const r=h*4,m=t.data[r],v=t.data[r+1],b=t.data[r+2],j=W(m,v,b,o),[P,D,K,C]=ue(m,v,b,n,s,j),U=Math.round(t.data[r+3]*P);U<=0?(e.data[r]=0,e.data[r+1]=0,e.data[r+2]=0,e.data[r+3]=0):(e.data[r]=D,e.data[r+1]=K,e.data[r+2]=C,e.data[r+3]=U),g[h]=1}return g}function De(e,t,n,o,s,l,y,c){const{width:u,height:g}=t,h=u*g;let i=0;for(let b=0;b<h;b++)l[b]!==J&&i++;const x=Math.max(32,Math.round(i*c)),r=new Float32Array(h).fill(-1);for(let b=0;b<h;b++){if(y[b]||l[b]===J)continue;const j=b*4;if(e.data[j+3]===0)continue;const P=W(t.data[j],t.data[j+1],t.data[j+2],o);P>=ie&&(r[b]=P)}const m=new Uint8Array(h),v=[];for(let b=0;b<h;b++){if(r[b]<0||m[b])continue;m[b]=1,v.length=0,v.push(b);const j=[];let P=-1;for(;v.length>0;){const D=v.pop();j.push(D),r[D]>P&&(P=r[D]);const K=D%u,C=(D-K)/u;for(let U=-1;U<=1;U++){const B=C+U;if(!(B<0||B>=g))for(let z=-1;z<=1;z++){const N=K+z;if(N<0||N>=u)continue;const f=B*u+N;r[f]>=0&&!m[f]&&(m[f]=1,v.push(f))}}}if(!(j.length>x)&&!(P<=Ee))for(const D of j){const K=D*4,C=t.data[K],U=t.data[K+1],B=t.data[K+2],[z,N,f,p]=ue(C,U,B,n,s,r[D]);z<=0||(e.data[K]=N,e.data[K+1]=f,e.data[K+2]=p)}}}function Ke(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 s=W(n.keyColor.r,n.keyColor.g,n.keyColor.b,o);if(s<=0)return;const l=Math.max(0,Math.min(254,Math.round(n.reach))),{classes:y,keyedMask:c}=Ue(t,e,n.keyColor,o);let u;if(l>0){const g=Te(c,t.width,t.height,l);u=Fe(e,t,n.keyColor,o,s,g,y,l)}else u=new Uint8Array(t.width*t.height);n.spillMaxFraction>0&&De(e,t,n.keyColor,o,s,y,u,n.spillMaxFraction)}function se(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 ze(){const{t:e}=re(),t=q(d=>d.keyingTarget),n=q(d=>d.setKeyingTarget),o=ge(!!t,()=>n(null)),s=q(d=>d.addAssetGenDerivedItem),l=q(d=>d.selectedProjectId),y=q(d=>d.showToast),[c,u]=_.useState("loading"),[g,h]=_.useState(!1),[i,x]=_.useState(null),[r,m]=_.useState(null),[v,b]=_.useState(Y.tolerance),[j,P]=_.useState(Y.softness),[D,K]=_.useState(Y.spill),[C,U]=_.useState(null),[B,z]=_.useState("erase"),[N,f]=_.useState([]),[p,M]=_.useState(!0),I=_.useRef(null),S=_.useRef(null),F=_.useRef(0),R=_.useRef(null),w=_.useRef(null),E=_.useCallback(()=>{R.current?.(),R.current=null},[]),L=t?.mediaType==="video",G=t?L&&t.filename?`/api/video/frame?file=${encodeURIComponent(t.filename)}&position=0`:t.url||t.image:null;_.useEffect(()=>{if(!G)return;let d=!0;u("loading"),I.current=null,U(null),f([]),z("erase");const k=new Image;return k.onload=()=>{if(d)try{const A=document.createElement("canvas");A.width=k.naturalWidth,A.height=k.naturalHeight;const T=A.getContext("2d");if(!T)throw new Error("no 2d context");T.drawImage(k,0,0);const O=T.getImageData(0,0,A.width,A.height);I.current=O,U(oe(O)),u("ready")}catch{d&&u("error")}},k.onerror=()=>{d&&u("error")},k.src=G,()=>{d=!1,k.onload=null,k.onerror=null}},[G]),_.useEffect(()=>(w.current=t?.filename??null,E(),h(!1),m(null),x(null),E),[E,t?.filename]),_.useEffect(()=>{if(!(c!=="ready"||!C))return cancelAnimationFrame(F.current),F.current=requestAnimationFrame(()=>{const d=I.current,k=S.current;if(!(!d||!k))try{const A=ve({width:d.width,height:d.height,data:d.data},{keyColor:C,tolerance:v,softness:j,spill:D});p&&Q(C)&&Ke(A,{width:d.width,height:d.height,data:d.data},{keyColor:C,...Ne}),N.length>0&&Ce(A,{width:d.width,height:d.height,data:d.data},N,v),k.width=A.width,k.height=A.height;const T=k.getContext("2d");if(!T)return;const O=T.createImageData(A.width,A.height);O.data.set(A.data),T.putImageData(O,0,0)}catch{u("error")}}),()=>cancelAnimationFrame(F.current)},[c,C,v,j,D,N,p]);const H=_.useCallback(d=>{const k=I.current,A=S.current;if(!k||!A)return;const T=A.getBoundingClientRect(),O=Math.max(0,Math.min(1,(d.clientX-T.left)/T.width)),V=Math.max(0,Math.min(1,(d.clientY-T.top)/T.height));if(B==="erase"&&!L){f(he=>[...he,{x:O,y:V}]);return}const $=Math.floor((d.clientX-T.left)/T.width*k.width),de=Math.floor((d.clientY-T.top)/T.height*k.height),Z=(Math.max(0,Math.min(k.height-1,de))*k.width+Math.max(0,Math.min(k.width-1,$)))*4;U({r:k.data[Z],g:k.data[Z+1],b:k.data[Z+2]})},[B,L]),X=_.useCallback(()=>{const d=S.current;d&&d.toBlob(k=>{if(!k)return;const A=URL.createObjectURL(k),T=document.createElement("a");T.href=A,T.download=`${(t?.filename||"asset").replace(/\.[a-z]+$/i,"")}-keyed.png`,T.click(),URL.revokeObjectURL(A)},"image/png")},[t]),ee=_.useCallback(()=>{const d=S.current;if(!(!d||!t?.filename||g)){if(h(!0),x(null),L){me({source:t.filename,keyParams:{tolerance:v,softness:j,keyColor:C??void 0},projectId:l,name:`${(t.prompt||"asset").trim().slice(0,60)} (keyed)`}).then(({requestId:k})=>{if(w.current!==t.filename)return;m(0),E();const A=pe(k,null,(T,O)=>{const V=O&&typeof O=="object"?O:{};if(T==="keying-progress"){const $=V.outTimeMs;m(typeof $=="number"&&Number.isFinite($)?$:0)}else if(T==="keying-done"){E();const $=V.filePath;if(typeof $=="string"&&$.trim()){s(se(t,$.trim(),"video")),h(!1),m(null),y(e("keying.videoSaved")),n(null);return}h(!1),m(null),x(e("keying.saveError"))}else T==="keying-error"&&(E(),h(!1),m(null),x(typeof V.error=="string"&&V.error?V.error:e("keying.saveError")))});R.current=A}).catch(k=>{w.current===t.filename&&(h(!1),x(k instanceof Error?k.message:e("keying.saveError")))});return}d.toBlob(k=>{if(w.current===t.filename){if(!k){h(!1),x(e("keying.saveError"));return}ye(k,{source:t.filename,projectId:l,name:`${(t.prompt||"asset").trim().slice(0,60)} (keyed)`,meta:{keyParams:{tolerance:v,softness:j,spill:D},prompt:t.prompt}}).then(({filePath:A})=>{if(w.current===t.filename){if(typeof A!="string"||!A.trim())throw new Error(e("keying.saveError"));s(se(t,A.trim(),"image")),y(e("keying.saved")),n(null)}}).catch(A=>{w.current===t.filename&&x(A instanceof Error?A.message:e("keying.saveError"))}).finally(()=>{w.current===t.filename&&h(!1)})}},"image/png")}},[t,g,L,C,l,v,j,D,E,s,y,n,e]);return t?a.jsx("div",{className:"assetgen-popup-backdrop",onClick:()=>n(null),children:a.jsxs("div",{ref:o,className:"keying-panel",role:"dialog","aria-modal":"true","aria-label":e("keying.title"),onClick:d=>d.stopPropagation(),children:[a.jsxs("header",{className:"keying-panel__head",children:[a.jsx("h2",{children:e("keying.title")}),C?a.jsxs("span",{className:"keying-panel__key",title:e("keying.keyColor"),children:[L?null:a.jsxs("span",{className:"keying-panel__modes",role:"group","aria-label":e("keying.clickMode"),children:[a.jsx("button",{type:"button",className:B==="erase"?"is-active":"","aria-pressed":B==="erase",onClick:()=>z("erase"),children:e("keying.modeErase")}),a.jsx("button",{type:"button",className:B==="pick"?"is-active":"","aria-pressed":B==="pick",onClick:()=>z("pick"),children:e("keying.modePick")})]}),N.length>0?a.jsx("button",{type:"button",className:"keying-panel__undo",onClick:()=>f(d=>d.slice(0,-1)),children:e("keying.undoClick",{count:String(N.length)})}):null,a.jsx("span",{className:"assetgen-bg-picker__swatch",style:{background:`rgb(${C.r},${C.g},${C.b})`},"aria-hidden":"true"}),a.jsx("span",{className:"keying-panel__hint",children:e(B==="erase"&&!L?"keying.eraseHint":"keying.pickHint")})]}):null]}),a.jsx("div",{className:"keying-panel__compare","aria-busy":c==="loading",children:c==="error"?a.jsxs("div",{className:"keying-panel__error",role:"alert",children:[a.jsx("p",{children:e("keying.loadError")}),a.jsx("button",{type:"button",onClick:()=>n(null),children:e("project.close")})]}):a.jsxs(a.Fragment,{children:[a.jsxs("figure",{className:"keying-panel__preview",children:[a.jsx("figcaption",{className:"keying-panel__preview-label",children:e("keying.original")}),a.jsx("div",{className:"keying-panel__stage keying-panel__stage--original",children:a.jsx("img",{src:G??"",alt:e("keying.originalAlt")})})]}),a.jsxs("figure",{className:"keying-panel__preview",children:[a.jsx("figcaption",{className:"keying-panel__preview-label",children:e("keying.removed")}),a.jsxs("div",{className:"keying-panel__stage",children:[a.jsx("canvas",{ref:S,className:"keying-panel__canvas",onClick:H,"aria-label":e("keying.previewAlt")}),c==="loading"?a.jsx("span",{className:"keying-panel__loading",role:"status",children:e("keying.previewLoading")}):null]})]})]})}),a.jsxs("details",{className:"keying-panel__advanced",children:[a.jsx("summary",{children:e("keying.advanced")}),a.jsxs("div",{className:"keying-panel__controls",children:[a.jsxs("label",{children:[e("keying.tolerance")," ",a.jsx("output",{children:v}),a.jsx("input",{type:"range",min:0,max:100,value:v,onChange:d=>b(Number(d.target.value))})]}),a.jsxs("label",{children:[e("keying.softness")," ",a.jsx("output",{children:j}),a.jsx("input",{type:"range",min:0,max:50,value:j,onChange:d=>P(Number(d.target.value))})]}),a.jsxs("label",{children:[e("keying.spill")," ",a.jsx("output",{children:D}),a.jsx("input",{type:"range",min:0,max:100,value:D,onChange:d=>K(Number(d.target.value))})]}),a.jsxs("label",{className:"keying-panel__unmix",children:[a.jsx("input",{type:"checkbox",checked:p,disabled:!C||!Q(C),onChange:d=>M(d.target.checked)}),e("keying.unmix"),a.jsx("span",{className:"keying-panel__hint",children:e("keying.unmixHint")})]}),a.jsx("button",{type:"button",className:"keying-panel__reset",onClick:()=>{b(Y.tolerance),P(Y.softness),K(Y.spill),f([]),M(!0),I.current&&U(oe(I.current))},children:e("keying.reset")})]})]}),a.jsxs("footer",{className:"keying-panel__actions",children:[i?a.jsx("span",{className:"keying-panel__save-error",role:"alert",children:i}):null,a.jsx("button",{type:"button",className:"assetgen-generate",disabled:c!=="ready"||g||!t.filename,onClick:ee,children:g?r!==null?e("keying.videoKeying",{seconds:String(Math.round(r/1e3))}):e("keying.saving"):e(L?"keying.videoSave":"keying.save")}),L?null:a.jsx("button",{type:"button",className:"assetgen-popup__close",disabled:c!=="ready",onClick:X,children:e("keying.download")}),a.jsx("button",{type:"button",className:"assetgen-popup__close",onClick:()=>n(null),children:e("project.close")})]})]})}):null}export{Pe as A,ze as K};
|