1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[3178],{62720:function(e,t,r){r.d(t,{Z:function(){return a}});let a=(0,r(79205).Z)("Tag",[["path",{d:"M12.586 2.586A2 2 0 0 0 11.172 2H4a2 2 0 0 0-2 2v7.172a2 2 0 0 0 .586 1.414l8.704 8.704a2.426 2.426 0 0 0 3.42 0l6.58-6.58a2.426 2.426 0 0 0 0-3.42z",key:"vktsd0"}],["circle",{cx:"7.5",cy:"7.5",r:".5",fill:"currentColor",key:"kqv944"}]])},33178:function(e,t,r){r.r(t),r.d(t,{default:function(){return D}});var a=r(57437),l=r(2265),n=r(78960),s=r(79205);let o=(0,s.Z)("SpellCheck",[["path",{d:"m6 16 6-12 6 12",key:"1b4byz"}],["path",{d:"M8 12h8",key:"1wcyev"}],["path",{d:"m16 20 2 2 4-4",key:"13tcca"}]]);var i=r(75277),d=r(53113);let c=(0,s.Z)("Sticker",[["path",{d:"M15.5 3H5a2 2 0 0 0-2 2v14c0 1.1.9 2 2 2h14a2 2 0 0 0 2-2V8.5L15.5 3Z",key:"1wis1t"}],["path",{d:"M14 3v4a2 2 0 0 0 2 2h4",key:"36rjfy"}],["path",{d:"M8 13h.01",key:"1sbv64"}],["path",{d:"M16 13h.01",key:"wip0gl"}],["path",{d:"M10 16s.8 1 2 1c1.3 0 2-1 2-1",key:"1vvgv3"}]]);var u=r(62720),x=r(12805),b=r(18930),g=r(88893),m=r(30401),h=r(14064),p=r(62883),y=r(51817),f=r(76865),k=r(81328),v=r(19680);let w=(0,s.Z)("SunMedium",[["circle",{cx:"12",cy:"12",r:"4",key:"4exip2"}],["path",{d:"M12 3v1",key:"1asbbs"}],["path",{d:"M12 20v1",key:"1wcdkc"}],["path",{d:"M3 12h1",key:"lp3yf2"}],["path",{d:"M20 12h1",key:"1vloll"}],["path",{d:"m18.364 5.636-.707.707",key:"1hakh0"}],["path",{d:"m6.343 17.657-.707.707",key:"18m9nf"}],["path",{d:"m5.636 5.636.707.707",key:"1xv1c5"}],["path",{d:"m17.657 17.657.707.707",key:"vl76zb"}]]);var j=r(73520);let N=(0,s.Z)("Droplets",[["path",{d:"M7 16.3c2.2 0 4-1.83 4-4.05 0-1.16-.57-2.26-1.71-3.19S7.29 6.75 7 5.3c-.29 1.45-1.14 2.84-2.29 3.76S3 11.1 3 12.25c0 2.22 1.8 4.05 4 4.05z",key:"1ptgy4"}],["path",{d:"M12.56 6.6A10.97 10.97 0 0 0 14 3.02c.5 2.5 2 4.9 4 6.5s3 3.5 3 5.5a6.98 6.98 0 0 1-11.91 4.97",key:"1sl1rz"}]]);var C=r(92451),S=r(69064),F=r(36600);let A=["Georgia","Arial","Helvetica","Times New Roman","Courier New","Verdana","Impact","Trebuchet MS","Palatino","Garamond"],T=["#FFFFFF","#000000","#FFD700","#FF4444","#44BBFF","#44FF44","#FF8800","#CC44FF","#FF69B4","#00CED1","#1a1a2e","#2d3436","#6c5ce7","#e17055","#00b894"];function M(e){let{selectedObj:t,activeTool:r,colorFilters:n,grabbed:s,detectedLayers:M,grabbing:D,onGrabText:I,onUndoGrab:O,onAddText:P,onResetTool:z,onDelete:R,onExport:G,onCancel:X,onPropertyChange:B,onApplyFilters:W,onSwapBackground:_,onAddSticker:Y,onFixTextApply:L,onSelectLayer:J,getCanvasSnapshot:U,getTextLayers:H}=e,[V,q]=(0,l.useState)(null),K=(null==t?void 0:t.type)==="i-text"||(null==t?void 0:t.type)==="text";(0,l.useEffect)(()=>{K&&"textStyle"!==V?q("textStyle"):t||"textStyle"!==V||q(null)},[t,K]);let[Q,$]=(0,l.useState)(!1),[ee,et]=(0,l.useState)([]),[er,ea]=(0,l.useState)(""),[el,en]=(0,l.useState)(!1),[es,eo]=(0,l.useState)(""),[ei,ed]=(0,l.useState)(!1),[ec,eu]=(0,l.useState)(""),[ex,eb]=(0,l.useState)(n),eg=e=>{q(t=>t===e?null:e)},em=async()=>{$(!0),et([]),ea("");try{let e=U(),t=H();if(!e)throw Error("Could not capture cover");let r=await fetch("/api/coauthor/ai/story/cover/fix-text",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({coverImage:e,textLayers:t})});if(!r.ok)throw Error("Scan failed");let a=await r.json();et(a.errors||[]),ea(a.summary||"")}catch(e){S.Am.error("Failed to scan cover text")}finally{$(!1)}},eh=async()=>{if(es.trim()){en(!0);try{var e;let t=await fetch("/api/coauthor/ai/story/cover/layers",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({title:"cover",authorName:"author",genre:"general",size:"6x9",vision:es.trim(),characterMode:"no-characters"})});if(!t.ok)throw Error("Generation failed");let r=null===(e=t.body)||void 0===e?void 0:e.getReader();if(!r)throw Error("No stream");let a=new TextDecoder,l="";for(;;){let{done:e,value:t}=await r.read();if(e)break;for(let e of a.decode(t).split("\n").filter(Boolean))try{let t=JSON.parse(e);"result"===t.type&&t.background&&(l=t.background)}catch(e){}}if(l)await _(l),eo(""),q(null);else throw Error("No background returned")}catch(e){S.Am.error("Failed to generate new illustration")}finally{en(!1)}}},ep=async()=>
1{if(ec.trim()){ed(!0);try{var e;let t=await fetch("/api/coauthor/ai/story/cover/standalone",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({bookTitle:ec.trim(),bookDescription:"A small decorative sticker/badge element: ".concat(ec.trim(),". Flat illustration style, clean edges, suitable as an overlay on a book cover. White or transparent background."),genre:"design",size:"1x1",style:"bold-graphic",characterMode:"no-characters",authorName:"",authorDisplay:"name-only"})});if(!t.ok)throw Error("Generation failed");let r=null===(e=t.body)||void 0===e?void 0:e.getReader();if(!r)throw Error("No stream");let a=new TextDecoder,l="";for(;;){let{done:e,value:t}=await r.read();if(e)break;for(let e of a.decode(t).split("\n").filter(Boolean))try{let t=JSON.parse(e);"result"===t.type&&t.coverImage&&(l=t.coverImage)}catch(e){}}if(l)await Y(l),eu(""),q(null);else throw Error("No sticker returned")}catch(e){S.Am.error("Failed to generate sticker")}finally{ed(!1)}}},ey=(e,t)=>{let r={...ex,[e]:t};eb(r),W(r)},ef=[{id:"fixText",label:"Fix Text Errors",icon:(0,a.jsx)(o,{className:"w-4 h-4"}),aiPowered:!0},{id:"textStyle",label:"Change Text Style",icon:(0,a.jsx)(i.Z,{className:"w-4 h-4"}),needsSelection:!0},{id:"changeIllustration",label:"Change Illustration",icon:(0,a.jsx)(d.Z,{className:"w-4 h-4"}),aiPowered:!0},{id:"addSticker",label:"Add Sticker",icon:(0,a.jsx)(c,{className:"w-4 h-4"}),aiPowered:!0},{id:"addTagline",label:"Add Tagline",icon:(0,a.jsx)(u.Z,{className:"w-4 h-4"})},{id:"adjustColors",label:"Adjust Colors",icon:(0,a.jsx)(x.Z,{className:"w-4 h-4"})},{id:"removeElement",label:"Remove Element",icon:(0,a.jsx)(b.Z,{className:"w-4 h-4"}),needsSelection:!0},{id:"freeEdit",label:"Free Edit",icon:(0,a.jsx)(g.Z,{className:"w-4 h-4"})}],ek=e=>{if(e)switch(e){case"grabText":eg(e);return;case"removeElement":R();return;case"freeEdit":z(),eg(e);return;default:"addTagline"!==e&&z(),eg(e)}};return(0,a.jsxs)("div",{className:"w-full flex flex-col h-full",children:[(0,a.jsxs)("button",{onClick:G,className:"w-full py-2.5 px-4 text-sm font-semibold text-white bg-emerald-600 hover:bg-emerald-700 rounded-lg transition-colors mb-4 flex items-center justify-center gap-2",children:[(0,a.jsx)(m.Z,{className:"w-4 h-4"}),"Finalize Cover"]}),s&&(0,a.jsxs)("div",{className:"mb-3 p-2.5 bg-blue-50 dark:bg-blue-900/20 rounded-lg border border-blue-200 dark:border-blue-800",children:[(0,a.jsx)("p",{className:"text-[11px] text-blue-700 dark:text-blue-300 font-medium mb-1",children:"Elements detected â cover is editable"}),(0,a.jsx)("p",{className:"text-[10px] text-blue-600/70 dark:text-blue-400/70 mb-2",children:"Click any element to select. Drag to move. Double-click text to edit."}),(0,a.jsxs)("button",{onClick:O,className:"flex items-center gap-1.5 text-[10px] font-medium text-blue-600 hover:text-blue-800 dark:text-blue-400 dark:hover:text-blue-200 transition-colors",children:[(0,a.jsx)(h.Z,{className:"w-3 h-3"}),"Undo Detection"]})]}),(0,a.jsx)("div",{className:"text-[10px] font-semibold text-gray-500 dark:text-gray-400 uppercase tracking-wider mb-2 px-1",children:"Editing Tools"}),(0,a.jsx)("div",{className:"space-y-0.5",children:ef.map(e=>{let l=e.needsSelection&&!t,n=V===e.id;return(0,a.jsxs)("div",{children:[(0,a.jsxs)("button",{onClick:()=>ek(e.id),disabled:l,className:"w-full flex items-center gap-2.5 px-3 py-2 text-[13px] rounded-lg transition-colors text-left ".concat(n?"bg-blue-50 dark:bg-blue-900/30 text-blue-700 dark:text-blue-300":l?"text-gray-300 dark:text-gray-600 cursor-not-allowed":"text-gray-700 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-800"),children:[e.icon,(0,a.jsx)("span",{className:"flex-1",children:e.label}),e.aiPowered&&(0,a.jsx)("span",{className:"text-[9px] font-medium text-blue-500 dark:text-blue-400 bg-blue-50 dark:bg-blue-900/40 px-1.5 py-0.5 rounded",children:"AI"})]}),n&&"grabText"===e.id&&(0,a.jsxs)(E,{children:[!D&&!s&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("p",{className:"text-xs text-gray-500 dark:text-gray-400 mb-2",children:"Scans the cover and detects all text and graphic elements, making each one selectable, movable, and editable."}),(0,a.jsxs)("button",{onClick:I,className:"w-full py-2 text-xs font-medium text-white bg-blue-600 hover:bg-blue-700 rounded-md transition-colors flex items-center justify-center gap-2",children:[(0,a.jsx)(p.Z,{className:"w-3.5 h-3.5"}),"Make Editable"]})]}),D&&(0,a.jsxs)("div",{className:"flex items-center gap-2 text-xs text-gray-500",children:[(0,a.jsx)(y.Z,{className:"w-3.5 h-3.5 animate-spin"}),(0,a.jsx)("span",{children:"Detecting elements..."})]}),s&&!D&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("div",{className:"flex items-center gap-2 text-xs text-emerald-600 dark:text-emerald-400 mb-2",children:[(0,a.jsx)(m.Z,{className:"w-3.5 h-3.5"}),(0,a.jsxs)("span",{children:[(null==M?void 0:M.length)||0," element",1!==((null==M?void 0:M.length)||0)?"s":""," detected"]})]}),M&&M.length>0&&(0,a.jsx)("div",{className:"space-y-1 max-h-40 overflow-y-auto",children:M.map(e=>(0,a.jsxs)("button",{onClick:()=>J(e.id),className:"w-full flex items-center gap-2 px-2 py-1.5 bg-white dark:bg-gray-800 rounded-md border border-gray-200 dark:border-stroke-dark hover:border-blue-400 hover:bg-blue-50 dark:hover:bg-blue-900/20 transition-colors cursor-pointer text-left",children:[(0,a.jsx)("span",{className:"text-[9px] font-semibold uppercase px-1.5 py-0.5 rounded ".concat("text"===e.type?"bg-purple-100 dar
1k:bg-purple-900/40 text-purple-600 dark:text-purple-400":"bg-amber-100 dark:bg-amber-900/40 text-amber-600 dark:text-amber-400"),children:"text"===e.type?"T":"G"}),(0,a.jsx)("span",{className:"text-[11px] text-gray-700 dark:text-gray-300 truncate flex-1",children:e.label})]},e.id))}),(0,a.jsxs)("button",{onClick:O,className:"w-full py-1.5 text-[11px] font-medium text-gray-500 hover:text-gray-700 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-800 rounded-md transition-colors flex items-center justify-center gap-1.5 mt-1",children:[(0,a.jsx)(h.Z,{className:"w-3 h-3"}),"Undo Detection"]})]})]}),n&&"fixText"===e.id&&(0,a.jsxs)(E,{children:[!Q&&0===ee.length&&!er&&(0,a.jsx)("button",{onClick:em,className:"w-full py-2 text-xs font-medium text-white bg-blue-600 hover:bg-blue-700 rounded-md transition-colors",children:"Scan Cover for Errors"}),Q&&(0,a.jsxs)("div",{className:"flex items-center gap-2 text-xs text-gray-500",children:[(0,a.jsx)(y.Z,{className:"w-3.5 h-3.5 animate-spin"}),(0,a.jsx)("span",{children:"Analyzing cover text..."})]}),er&&(0,a.jsx)("p",{className:"text-xs text-gray-600 dark:text-gray-400 mb-2",children:er}),ee.length>0&&(0,a.jsxs)("div",{className:"space-y-2",children:[ee.map((e,t)=>(0,a.jsxs)("div",{className:"p-2 bg-amber-50 dark:bg-amber-900/20 rounded-md border border-amber-200 dark:border-amber-800",children:[(0,a.jsxs)("div",{className:"flex items-start gap-1.5 mb-1",children:[(0,a.jsx)(f.Z,{className:"w-3 h-3 text-amber-500 mt-0.5 shrink-0"}),(0,a.jsx)("span",{className:"text-[10px] text-amber-700 dark:text-amber-300",children:e.issue})]}),(0,a.jsx)("div",{className:"text-[10px] text-gray-500 line-through mb-0.5",children:e.original}),(0,a.jsx)("div",{className:"text-xs font-medium text-emerald-700 dark:text-emerald-400",children:e.corrected}),(0,a.jsx)("button",{onClick:()=>L([{layerId:e.layerId,corrected:e.corrected}]),className:"mt-1.5 text-[10px] font-medium text-blue-600 hover:text-blue-800 dark:text-blue-400",children:"Apply fix"})]},t)),(0,a.jsx)("button",{onClick:()=>L(ee.map(e=>({layerId:e.layerId,corrected:e.corrected}))),className:"w-full py-1.5 text-[11px] font-medium text-white bg-emerald-600 hover:bg-emerald-700 rounded-md",children:"Apply all fixes"})]}),er&&0===ee.length&&!Q&&(0,a.jsxs)("div",{className:"flex items-center gap-2 text-xs text-emerald-600 dark:text-emerald-400",children:[(0,a.jsx)(m.Z,{className:"w-3.5 h-3.5"}),(0,a.jsx)("span",{children:"No errors found!"})]})]}),n&&"textStyle"===e.id&&K&&(0,a.jsxs)(E,{children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("label",{className:"text-[10px] font-medium text-gray-500 dark:text-gray-400 uppercase mb-1 block",children:"Font"}),(0,a.jsx)(F.Z,{value:(null==t?void 0:t.fontFamily)||"Georgia",onValueChange:e=>B("fontFamily",e),className:"h-8 min-h-8 rounded-md border-gray-200 bg-white px-2 text-xs text-gray-800 dark:border-stroke-dark dark:bg-gray-800 dark:text-white",options:A.map(e=>({value:e,label:e}))})]}),(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsxs)("div",{className:"flex-1",children:[(0,a.jsx)("label",{className:"text-[10px] font-medium text-gray-500 dark:text-gray-400 uppercase mb-1 block",children:"Size"}),(0,a.jsx)("input",{type:"number",value:Math.round((null==t?void 0:t.fontSize)||28),onChange:e=>B("fontSize",parseInt(e.target.value)||28),className:"w-full h-8 text-xs text-center border border-gray-200 dark:border-stroke-dark rounded-md bg-white dark:bg-gray-800 text-gray-800 dark:text-white",min:8,max:200})]}),(0,a.jsxs)("div",{className:"flex gap-1 pt-4",children:[(0,a.jsx)("button",{onClick:()=>B("fontWeight",(null==t?void 0:t.fontWeight)==="bold"?"normal":"bold"),className:"p-1.5 rounded-md transition-colors ".concat((null==t?void 0:t.fontWeight)==="bold"?"bg-blue-100 dark:bg-blue-900/40 text-blue-700":"text-gray-500 hover:bg-gray-200 dark:hover:bg-gray-700"),children:(0,a.jsx)(k.Z,{className:"w-3.5 h-3.5"})}),(0,a.jsx)("button",{onClick:()=>B("fontStyle",(null==t?void 0:t.fontStyle)==="italic"?"normal":"italic"),className:"p-1.5 rounded-md transition-colors ".concat((null==t?void 0:t.fontStyle)==="italic"?"bg-blue-100 dar
1k:bg-blue-900/40 text-blue-700":"text-gray-500 hover:bg-gray-200 dark:hover:bg-gray-700"),children:(0,a.jsx)(v.Z,{className:"w-3.5 h-3.5"})})]})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)("label",{className:"text-[10px] font-medium text-gray-500 dark:text-gray-400 uppercase mb-1.5 block",children:"Color"}),(0,a.jsx)("div",{className:"grid grid-cols-5 gap-1.5",children:T.map(e=>(0,a.jsx)("button",{onClick:()=>B("fill",e),className:"w-6 h-6 rounded-md border-2 transition-all ".concat((null==t?void 0:t.fill)===e?"border-blue-500 scale-110 ring-1 ring-blue-300":"border-gray-200 dark:border-stroke-dark hover:scale-105"),style:{backgroundColor:e}},e))})]})]}),n&&"changeIllustration"===e.id&&(0,a.jsxs)(E,{children:[(0,a.jsx)("label",{className:"text-[10px] font-medium text-gray-500 dark:text-gray-400 uppercase mb-1 block",children:"Describe the new illustration"}),(0,a.jsx)("textarea",{value:es,onChange:e=>eo(e.target.value),placeholder:"e.g. A serene mountain landscape at sunset with warm golden tones...",className:"w-full text-xs border border-gray-200 dark:border-stroke-dark rounded-md bg-white dark:bg-gray-800 text-gray-800 dark:text-white px-2 py-1.5 resize-none",rows:3,disabled:el}),(0,a.jsx)("button",{onClick:eh,disabled:el||!es.trim(),className:"w-full py-2 text-xs font-medium text-white bg-blue-600 hover:bg-blue-700 disabled:bg-gray-400 rounded-md transition-colors flex items-center justify-center gap-2",children:el?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(y.Z,{className:"w-3.5 h-3.5 animate-spin"}),"Generating..."]}):"Generate New Background"}),(0,a.jsx)("p",{className:"text-[10px] text-gray-400",children:"Text layers will be preserved"})]}),n&&"addSticker"===e.id&&(0,a.jsxs)(E,{children:[(0,a.jsx)("label",{className:"text-[10px] font-medium text-gray-500 dark:text-gray-400 uppercase mb-1 block",children:"Describe the sticker"}),(0,a.jsx)("textarea",{value:ec,onChange:e=>eu(e.target.value),placeholder:"e.g. Gold bestseller badge, butterfly, award ribbon...",className:"w-full text-xs border border-gray-200 dark:border-stroke-dark rounded-md bg-white dark:bg-gray-800 text-gray-800 dark:text-white px-2 py-1.5 resize-none",rows:2,disabled:ei}),(0,a.jsx)("button",{onClick:ep,disabled:ei||!ec.trim(),className:"w-full py-2 text-xs font-medium text-white bg-blue-600 hover:bg-blue-700 disabled:bg-gray-400 rounded-md transition-colors flex items-center justify-center gap-2",children:ei?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(y.Z,{className:"w-3.5 h-3.5 animate-spin"}),"Generating..."]}):"Generate Sticker"})]}),n&&"addTagline"===e.id&&(0,a.jsxs)(E,{children:["text"===r?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("p",{className:"text-xs text-blue-600 dark:text-blue-400 font-medium",children:"Click anywhere on the cover to place your tagline."}),(0,a.jsx)("button",{onClick:()=>z(),className:"w-full py-1.5 text-[11px] font-medium text-gray-500 hover:text-gray-700 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-800 rounded-md transition-colors",children:"Cancel placement"})]}):(0,a.jsx)("button",{onClick:P,className:"w-full py-2 text-xs font-medium text-white bg-blue-600 hover:bg-blue-700 rounded-md transition-colors",children:"Place Tagline on Cover"}),(0,a.jsx)("p",{className:"text-[10px] text-gray-400",children:"After placing, double-click to edit the text. Drag to reposition."})]}),n&&"adjustColors"===e.id&&(0,a.jsxs)(E,{children:[(0,a.jsx)(Z,{icon:(0,a.jsx)(w,{className:"w-3.5 h-3.5"}),label:"Brightness",value:ex.brightness,min:-.5,max:.5,step:.05,onChange:e=>ey("brightness",e)}),(0,a.jsx)(Z,{icon:(0,a.jsx)(j.Z,{className:"w-3.5 h-3.5"}),label:"Contrast",value:ex.contrast,min:-.5,max:.5,step:.05,onChange:e=>ey("contrast",e)}),(0,a.jsx)(Z,{icon:(0,a.jsx)(N,{className:"w-3.5 h-3.5"}),label:"Saturation",value:ex.saturation,min:-1,max:1,step:.1,onChange:e=>ey("saturation",e)}),(0,a.jsx)("button",{onClick:()=>{let e={brightness:0,contrast:0,saturation:0};eb(e),W(e)},className:"w-full py-1.5 text-[10px] font-medium text-gray-500 hover:text-gray-700 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-800 rounded-md transition-colors",children:"Reset to default"})]}),n&&"freeEdit"===e.id&&(0,a.jsx)(E,{children:(0,a.jsx)("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:"Click any element on the cover to select it. Drag to reposition. Double-click text to edit it inline."})})]},e.id)})}),(0,a.jsx)("div",{className:"mt-auto pt-4",children:(0,a.jsxs)("button",{onClick:X,className:"w-full flex items-center justify-center gap-2 py-2 text-sm text-gray-500 dark:text-gray-400 hover:text-gray-700 dark:hover:text-gray-200 hover:bg-gray-100 dark:hover:bg-gray-800 rounded-lg transition-colors",children:[(0,a.jsx)(C.Z,{className:"w-4 h-4"}),"Back to Cover"]})})]})}function E(e){let{children:t}=e;return(0,a.jsx)("div",{className:"ml-3 mt-1 mb-2 p-3 bg-gray-50 dark:bg-gray-800/50 rounded-lg space-y-2.5 border border-gray-200 dark:border-stroke-dark",children:t})}function Z(e){let{icon:t,label:r,value:l,min:n,max:s,step:o,onChange:i}=e;return(0,a.jsxs)("div",{children:[(0,a.jsxs)("div",{className:"flex items-center gap-1.5 mb-1",children:[t,(0,a.jsx)("span",{className:"text-[10px] font-medium text-gray-500 dark:text-gray-400 uppercase flex-1",children:r}),(0,a.jsxs)("span",{className:"text-[10px] text-gray-400 tabular-nums",children:[l>0?"+":"",l.toFixed(2)]})]}),(0,a.jsx)("input",{type:"range",min:n,max:s,step:o,value:l,onCh
1ange:e=>i(parseFloat(e.target.value)),className:"w-full h-1.5 bg-gray-200 dark:bg-gray-700 rounded-lg appearance-none cursor-pointer accent-blue-600"})]})}function D(e){let{background:t,layers:r,canvasWidth:s,canvasHeight:o,onSave:i,onCancel:d}=e,c=(0,l.useRef)(null),u=(0,l.useRef)(null),x=(0,l.useRef)(null),b=(0,l.useRef)(null),g=(0,l.useRef)(null),[m,h]=(0,l.useState)(null),[p,y]=(0,l.useState)("select"),[f,k]=(0,l.useState)({brightness:0,contrast:0,saturation:0}),[v,w]=(0,l.useState)(!1),[j,N]=(0,l.useState)(!1),[C,F]=(0,l.useState)([]),A=(0,l.useCallback)(async(e,t)=>{var r,a,l;let i=null!==(a=e.width)&&void 0!==a?a:s,d=null!==(l=e.height)&&void 0!==l?l:o,c=new Image;c.crossOrigin="anonymous",await new Promise((e,r)=>{c.onload=()=>e(),c.onerror=r,c.src=t});let u=document.createElement("canvas");u.width=i,u.height=d,null===(r=u.getContext("2d"))||void 0===r||r.drawImage(c,0,0,i,d),b.current&&e.remove(b.current);let x=new n.I(u,{left:0,top:0,originX:"left",originY:"top",selectable:!1,evented:!1,objectCaching:!1});b.current=x,e.add(x),e.sendObjectToBack(x),e.renderAll()},[s,o]);(0,l.useEffect)(()=>{var e;if(!c.current)return;x.current&&(x.current.dispose(),x.current=null);let a=c.current,l=(null===(e=u.current)||void 0===e?void 0:e.clientWidth)||s,i=s>l?l/s:1,d=Math.round(s*i),b=Math.round(o*i);return(async()=>{let e=new n.Xz(a,{width:d,height:b,backgroundColor:"#1a1a2e",selection:!0,enableRetinaScaling:!1});if(x.current=e,await A(e,t),r&&r.length>0){let t=[],a=d/s,l=b/o;for(let s of r){let r="title"===s.id,o=new n.jX(r?{color:"rgba(0,0,0,0.8)",blur:8,offsetX:2,offsetY:3}:{color:"rgba(0,0,0,0.6)",blur:4,offsetX:1,offsetY:1}),i=new n.aW(s.content,{left:s.x*a,top:s.y*l,originX:s.originX||"center",originY:s.originY||"center",fontSize:Math.round(s.fontSize*Math.min(a,l)),fontFamily:s.fontFamily||"Georgia",fontWeight:s.fontWeight||"bold",fill:s.fill||"#FFFFFF",textAlign:s.textAlign||"center",editable:!0,selectable:!0,evented:!0,padding:4,shadow:o});i._layerId=s.id,i._grabbed=!0,i._regionType="text",e.add(i),t.push({id:s.id,label:s.content,type:"text"})}F(t),N(!0)}e.on("selection:created",e=>{var t;h((null===(t=e.selected)||void 0===t?void 0:t[0])||null)}),e.on("selection:updated",e=>{var t;h((null===(t=e.selected)||void 0===t?void 0:t[0])||null)}),e.on("selection:cleared",()=>{h(null)}),e.on("mouse:dblclick",t=>{t.target&&"i-text"===t.target.type&&(t.target.enterEditing(),e.renderAll())}),e.renderAll()})(),()=>{x.current&&(x.current.dispose(),x.current=null)}},[]);let T=(0,l.useCallback)(async()=>{var e,t;if(!x.current)return;let r=x.current,a=null!==(e=r.width)&&void 0!==e?e:s,l=null!==(t=r.height)&&void 0!==t?t:o;w(!0);try{r.discardActiveObject(),r.renderAll();let e=r.toDataURL({format:"png",multiplier:1});g.current||(g.current=e);let t=await fetch("/api/coauthor/ai/story/cover/grab-text",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({coverImage:e})});if(!t.ok){let e=await t.json().catch(()=>({}));throw Error(e.error||"Detection failed (".concat(t.status,")"))}let s=await t.json(),o=s.textRegions||[],i=s.imageWidth||a,d=s.imageHeight||l,c=a/i,u=l/d;if(0===o.length){(0,S.Am)("No elements detected on this cover.",{icon:"â¹ï¸"});return}s.cleanBackground&&await A(r,s.cleanBackground);let x=[];for(let e of o){let t=void 0!==e.bbox.xPx,s=t?Math.round(e.bbox.xPx*c):Math.round((e.bbox.xPct||0)/100*a),o=t?Math.round(e.bbox.yPx*u):Math.round((e.bbox.yPct||0)/100*l),i=t?Math.round(e.bbox.wPx*c):Math.round((e.bbox.wPct||0)/100*a),d=t?Math.round(e.bbox.hPx*u):Math.round((e.bbox.hPct||0)/100*l);if(i<5||d<5)continue;let b=e.style||{},g=e.content||e.id,m=Math.max(14,Math.round(.75*d)),h=s+i/2,p=o+d/2,y=new n.aW(g,{left:h,top:p,originX:"center",originY:"center",fontSize:m,fontFamily:"Georgia",fontWeight:b.fontWeight||"bold",fontStyle:b.fontStyle||"normal",fill:b.color||"#FFFFFF",textAlign:b.textAlign||"center",editable:!0,selectable:!0,evented:!0,padding:4,shadow:new n.jX({color:"rgba(0,0,0,0.6)",blur:4,offsetX:1,offsetY:1})});y._layerId=e.id,y._grabbed=!0,y._regionType="text",r.add(y),x.push({id:e.id,label:g,type:"text"})}r.renderAll(),F(x),N(!0),S.Am.success("".concat(o.length," text element").concat(o.length>
11?"s":""," detected â click to select, drag to move, double-click to edit!"))}catch(e){console.error("[CoverEditor] Detection failed:",e),S.Am.error(e instanceof Error?e.message:"Detection failed")}finally{w(!1)}},[s,o,A]),E=(0,l.useCallback)(async()=>{if(!x.current||!g.current)return;let e=x.current;for(let t of e.getObjects().filter(e=>e._grabbed))e.remove(t);await A(e,g.current),g.current=null,N(!1),F([]),S.Am.success("Detection reverted")},[A]),Z=(0,l.useCallback)(e=>{var t,r,a;if("text"!==p||!x.current)return;let l=x.current,i=null===(t=c.current)||void 0===t?void 0:t.getBoundingClientRect();if(!i)return;let d=null!==(r=l.width)&&void 0!==r?r:s,u=null!==(a=l.height)&&void 0!==a?a:o,b=d/i.width,g=u/i.height,m=(e.clientX-i.left)*b,h=(e.clientY-i.top)*g,f=new n.aW("New Tagline",{left:m,top:h,fontSize:24,fontFamily:"Georgia",fontWeight:"normal",fill:"#FFFFFF",textAlign:"center",originX:"center",originY:"center",editable:!0,padding:4,shadow:new n.jX({color:"rgba(0,0,0,0.7)",blur:4,offsetX:2,offsetY:2})});l.add(f),l.setActiveObject(f),l.renderAll(),y("select")},[p,s,o]),D=(0,l.useCallback)(()=>{if(!x.current)return;let e=x.current;e.discardActiveObject(),e.renderAll(),i(e.toDataURL({format:"png",multiplier:2}))},[i]),I=(0,l.useCallback)(()=>{x.current&&m&&(x.current.remove(m),x.current.renderAll(),h(null))},[m]),O=(0,l.useCallback)((e,t)=>{x.current&&m&&(m.set(e,t),x.current.renderAll())},[m]),P=(0,l.useCallback)(()=>{y(e=>"text"===e?"select":"text")},[]),z=(0,l.useCallback)(()=>{y("select")},[]),R=(0,l.useCallback)(e=>{if(k(e),!x.current||!b.current)return;let t=b.current;t.filters=[new n.u8.Brightness({brightness:e.brightness}),new n.u8.Contrast({contrast:e.contrast}),new n.u8.Saturation({saturation:e.saturation})],t.applyFilters(),x.current.renderAll()},[]),G=(0,l.useCallback)(async e=>
1{x.current&&(await A(x.current,e),S.Am.success("Background updated!"))},[A]),X=(0,l.useCallback)(async e=>{var t,r;if(!x.current)return;let a=x.current,l=new Image;l.crossOrigin="anonymous",await new Promise((t,r)=>{l.onload=()=>t(),l.onerror=r,l.src=e});let i=new n.I(l,{left:(null!==(t=a.width)&&void 0!==t?t:s)/2,top:(null!==(r=a.height)&&void 0!==r?r:o)/2,originX:"center",originY:"center",scaleX:.3,scaleY:.3});a.add(i),a.setActiveObject(i),a.renderAll(),S.Am.success("Sticker added! Drag to reposition.")},[s,o]),B=(0,l.useCallback)(e=>{if(!x.current)return 0;let t=x.current,r=t.getObjects(),a=0;for(let t of e){let e=r.find(e=>e._layerId===t.layerId);e&&e.set&&(e.set("text",t.corrected),a++)}return a>0&&(t.renderAll(),S.Am.success("".concat(a," text correction").concat(a>1?"s":""," applied!"))),a},[]),W=(0,l.useCallback)(()=>x.current?x.current.toDataURL({format:"png",multiplier:1}):null,[]),_=(0,l.useCallback)(()=>x.current?x.current.getObjects().filter(e=>"i-text"===e.type).map(e=>({id:e._layerId||"",text:e.text||""})):[],[]),Y=(0,l.useCallback)(e=>{if(!x.current)return;let t=x.current,r=t.getObjects().find(t=>t._layerId===e);r&&(t.setActiveObject(r),t.renderAll())},[]);return(0,a.jsxs)("div",{className:"flex gap-6 w-full items-start max-w-5xl mx-auto",children:[(0,a.jsx)("div",{className:"flex-1 min-w-0",ref:u,children:(0,a.jsxs)("div",{className:"relative rounded-xl overflow-hidden shadow-xl bg-gray-100 dark:bg-gray-900",onClick:"text"===p?Z:void 0,children:[(0,a.jsx)("canvas",{ref:c}),"text"===p&&(0,a.jsx)("div",{className:"absolute inset-0 z-10 cursor-crosshair bg-blue-500/5 border-2 border-dashed border-blue-400 rounded-xl flex items-center justify-center pointer-events-none",children:(0,a.jsx)("span",{className:"bg-blue-600 text-white text-xs px-3 py-1.5 rounded-full shadow-lg",children:"Click anywhere on the cover to place tagline"})}),v&&(0,a.jsxs)("div",{className:"absolute inset-0 z-20 bg-black/40 backdrop-blur-sm rounded-xl flex flex-col items-center justify-center gap-3",children:[(0,a.jsx)("div",{className:"w-8 h-8 border-3 border-white/30 border-t-white rounded-full animate-spin"}),(0,a.jsx)("span",{className:"text-white text-sm font-medium px-4 text-center",children:"Scanning cover for all elements (v2)..."})]})]})}),(0,a.jsx)("div",{className:"w-64 shrink-0 flex flex-col bg-white dark:bg-gray-900 border border-gray-200 dark:border-stroke-dark rounded-xl p-4 shadow-sm sticky top-4 max-h-[85vh] overflow-y-auto",children:(0,a.jsx)(M,{selectedObj:m,activeTool:p,colorFilters:f,grabbed:j,detectedLayers:C,onGrabText:T,onUndoGrab:E,grabbing:v,onAddText:P,onResetTool:z,onDelete:I,onExport:D,onCancel:d,onPropertyChange:O,onApplyFilters:R,onSwapBackground:G,onAddSticker:X,onFixTextApply:B,onSelectLayer:Y,getCanvasSnapshot:W,getTextLayers:_})})]})}}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.