PageSourceSearch

https://raphael.app/_next/static/chunks/3037-71242ea66a8a102a.js

js raphael.app collected 2026-09-25 05:15:05 UTC 262,217 bytes, 1 lines download raw bytes

1!function(){try{var e="u">typeof window?window:"u">typeof global?global:"u">typeof globalThis?globalThis:"u">typeof self?self:{},t=(new e.Error).stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="2caf5275-ecd0-49ad-a923-68500d7b4163",e._sentryDebugIdIdentifier="sentry-dbid-2caf5275-ecd0-49ad-a923-68500d7b4163")}catch(e){}}();"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[1819,3037],{3549:(e,t,r)=>{r.d(t,{g:()=>n});let n="raphael:show-annual-pricing"},23037:(e,t,r)=>{r.r(t),r.d(t,{AiVideoGeneratorPageClient:()=>rz});var n,a=r(4364),i=r(9277),o=r(62093);function l(e,t,r){return"unlimited"===e&&(0,o.$2)(t,r)?"unlimited":"credits"}var s=r(87423),d=r(10567),u=r(37885),c=r(50288),m=r(360),g=r(24985),p=r(69751),f=r(81714),h=r(44032),x=r(8184),b=r(91760),v=r(23955),y=r(27995),w=r(69571);function I(e){let{hero:t}=e;return t?(0,a.jsx)("div",{"data-critical-hero":!0,className:"relative flex flex-col items-center justify-center text-center py-8 sm:py-16",children:(0,a.jsxs)("div",{className:"w-full max-w-5xl mx-auto px-4",children:[(0,a.jsxs)("div",{className:"flex items-center justify-center gap-3 sm:gap-4",children:[(0,a.jsx)(w.default,{src:"/logo.webp",alt:"Raphael Logo",width:48,height:48,className:"hidden sm:block w-10 h-10 sm:w-12 sm:h-12",priority:!0,placeholder:"empty"}),(0,a.jsx)("h1",{className:"text-3xl sm:text-5xl font-bold tracking-tight [text-rendering:optimizeLegibility] [font-smooth:always] [-webkit-font-smoothing:antialiased] [-moz-osx-font-smoothing:grayscale]",children:(0,a.jsx)("span",{className:"relative inline-block",children:(0,a.jsx)("span",{className:"bg-gradient-to-r from-amber-500 via-amber-400 to-amber-500 [background-clip:text] [-webkit-background-clip:text] text-transparent",children:t.title})})})]}),(0,a.jsx)("p",{className:"hero-lead mt-4 sm:mt-6 text-xl sm:text-2xl font-medium text-foreground/90 max-w-2xl mx-auto",children:t.subtitle}),(0,a.jsxs)("div",{className:"flex items-center justify-center gap-2 mt-2 sm:mt-3",children:[(0,a.jsx)(y.A,{className:"w-4 h-4 text-amber-400"}),(0,a.jsx)("p",{className:"text-base sm:text-lg text-foreground/70",children:t.tag}),(0,a.jsx)(y.A,{className:"w-4 h-4 text-amber-400"})]})]})}):null}var j=r(64648),F=r(14423),N=r(10932),C=r(76066),R=r(30869),k=r(96254),A=r(17646),S=r(5886),M=r(56760);function _(e){let{currentCredits:t,originalCredits:r}=e;if("number"!=typeof r||!Number.isFinite(r)||r<=0||!Number.isFinite(t)||t<0||t>=r)return;let n=Math.round((1-t/r)*100);return n>0?`-${n}%`:void 0}var E=r(21298),T=r(40764),L=r(60300),V=r(92106),P=r(72734),D=r(7755);function U(e){let{embedded:t=!1,primary:r,secondary:n,right:i}=e;return(0,a.jsx)("div",{className:"sm:hidden",children:(0,a.jsx)(P.B,{embedded:t,leftClassName:"grid grid-cols-1 gap-2",rightClassName:"flex w-full items-center gap-2",left:(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(D.L,{className:"w-full flex-wrap",children:r}),n?(0,a.jsx)(D.x,{className:"w-full flex-wrap",children:n}):null]}),right:i})})}function O(e){let{prompt:t,mobileRail:r,sticky:n=!1,mobileRailClassName:i}=e;return(0,a.jsxs)(a.Fragment,{children:[t,r?(0,a.jsx)("div",{className:(0,F.cn)("mt-3 sm:hidden",n&&"mt-2",i),children:r}):null]})}var $=r(8272),W=r(22583),q=r(20958);function H(e){let{cost:t,originalCost:r,mode:n="inline"}=e;return(0,a.jsx)(q.i,{label:`${t}`,originalLabel:null!=r?`${r}`:null,mode:n})}function B(e){let{durations:t,value:r,onChange:n,label:i,className:o}=e,l=t.length>0?t:[r||5],s=l.indexOf(r),d=s>=0?s:l.reduce((e,t,n)=>{let a=Math.abs(l[e]-r);return Math.abs(t-r)<a?n:e},0),u=Math.max(0,l.length-1),c=0===u?100:d/u*100;return(0,a.jsxs)("div",{className:(0,F.cn)("space-y-2.5",o),children:[(0,a.jsxs)("div",{className:"flex items-center justify-between gap-3",children:[i?(0,a.jsx)("span",{className:"text-xs font-medium text-foreground/54",children:i}):null,(0,a.jsxs)("span",{className:"rounded-full bg-primary/14 px-2 py-0.5 text-xs font-semibold text-primary",children:[l[d],"s"]})]}),(0,a.jsx)("input",{type:"range",min:0,max:u,step:1,value:d,onChange:e=>{n(l[Number(e.currentTarget.value)]??l[0])},className:"h-2 w-full cursor-pointer appearance-none rounded-full bg-transparent outline-none [&::-moz-range-thumb]:h-4 [&::-moz-range-thumb]:w-4 [&::-moz-range-thumb]:cursor-pointer [&::-moz-range-thumb]:rounded-full [&::-moz-range-thumb]:border-0 [&::-moz-range-thumb]:bg-primary [&::-webkit-slider-thumb]:h-4 [&::-webkit-slider-thumb]:w-4 [&::-webkit-slider-thumb]:appearance-none [&::-webkit-slider-thumb]:cursor-pointer [&::-webkit-slider-thumb]:rounded-full [&::-webkit-slider-thumb]:bg-primary",style:{background:`linear-gradient(90deg, hsl(var(--primary)) 0%, hsl(var(--primary)) ${c}%, rgba(255,255,255,0.12) ${c}%, rgba(255,255,255,0.12) 100%)`},"aria-label":i||"Duration"}),l.length>1?(0,a.jsxs)("div",{className:"flex items-center justify-between text-[10px] font-medium text-foreground
1/38",children:[(0,a.jsxs)("span",{children:[l[0],"s"]}),(0,a.jsxs)("span",{children:[l[l.length-1],"s"]})]}):null]})}var z=r(39490),G=r(19303),X=r(9629),Y=r(7298),Q=r(31819),J=r(25640),K=r(80215);let Z={raphael:{label:"Seedance",logoSrc:"/images/logos/video-models/seedance.svg",logoClassName:"object-contain",accentClassName:"from-cyan-500/18 via-blue-500/8 to-transparent"},seedance:{label:"Seedance",logoSrc:"/images/logos/video-models/seedance.svg",logoClassName:"object-contain",accentClassName:"from-cyan-500/18 via-blue-500/8 to-transparent"},minimax:{label:"MiniMax",logoSrc:"/images/logos/video-models/minimax-h3-icon.png",logoClassName:"object-contain",accentClassName:"from-fuchsia-500/18 via-orange-500/8 to-transparent"},kling:{label:"Kling",logoSrc:"/images/logos/video-models/kling-official.png",logoClassName:"object-contain",accentClassName:"from-sky-500/18 via-lime-500/8 to-transparent"},veo:{label:"Veo",logoSrc:"/images/logos/video-models/google-g.svg",logoClassName:"object-contain",accentClassName:"from-emerald-500/16 via-sky-500/8 to-transparent"},gemini:{label:"Gemini",logoSrc:"/images/logos/video-models/gemini-omni-flash-aurora.svg",logoClassName:"h-[19px] w-[19px] object-contain",accentClassName:"from-blue-500/18 via-violet-500/8 to-transparent"}};function ee(e){let{unlimitedPlan:t="free",selectedModelId:r,models:n,onModelSelect:i,modelDescriptions:l,className:s,triggerClassName:d,panelAlign:u="start",panelContainerClassName:c}=e,m=(0,v.c)("imageGenerator"),[g,p]=(0,h.useState)(!1),[f,x]=(0,h.useState)(null),b=(0,h.useMemo)(()=>n.find(e=>e.id===r)??n[0]??null,[n,r]),y=(0,h.useMemo)(()=>(0,K.jN)(n).map(e=>{var t;let r=e.models[0],n=Z[e.id]??Z.raphael;return{id:e.id,label:r?.providerLabel||n.label,description:(t=e.id,m(`videoProviderDesc.${t}`)),logoSrc:n.logoSrc,logoClassName:n.logoClassName,models:e.models}}),[m,n]),I=b?(0,K.fX)(b):y[0]?.id??"raphael",j=y.find(e=>e.id===f)??y.find(e=>e.id===I)??y[0]??null;if(!b)return null;let C=Z[I]??Z.raphael;return(0,a.jsx)(L.s,{open:g,onOpenChange:p,className:(0,F.cn)("w-full md:w-auto",s),panelAlign:u,panelContainerClassName:(0,F.cn)("w-[min(90vw,584px)]",c),panelSurfaceClassName:"overflow-hidden rounded-[22px] p-2",trigger:(0,a.jsxs)("button",{type:"button",onClick:()=>p(e=>!e),className:(0,F.cn)("flex w-full max-w-full min-w-0 items-center justify-between border-transparent bg-[rgba(94,96,104,0.30)] text-foreground/92 outline-none hover:bg-[rgba(109,112,121,0.36)] focus:outline-none focus-visible:outline-none focus-visible:ring-0 sm:w-auto",T.DJ,d),"aria-expanded":g,"aria-haspopup":"dialog","aria-label":`Model: ${b.label}`,children:[(0,a.jsxs)("span",{className:"flex min-w-0 items-center gap-2",children:[(0,a.jsx)("span",{className:"flex h-6 w-6 shrink-0 items-center justify-center overflow-hidden rounded-full border border-white/10 bg-black/30",children:(0,a.jsx)(w.default,{src:C.logoSrc,alt:b.label,width:20,height:20,className:(0,F.cn)("h-4 w-4",C.logoClassName)})}),(0,a.jsx)("span",{className:"min-w-0 truncate",children:b.label})]}),(0,a.jsx)(S.A,{className:(0,F.cn)("h-3.5 w-3.5 shrink-0 opacity-60 transition-transform duration-200",g&&"rotate-180")})]}),children:(0,a.jsxs)("div",{children:[(0,a.jsx)("div",{className:"px-2 pb-2 pt-1 text-[10px] font-semibold uppercase tracking-[0.16em] text-foreground/35",children:m("selectors.models")}),(0,a.jsxs)("div",{className:"grid h-[300px] grid-cols-[156px_minmax(0,1fr)] gap-2 md:grid-cols-[196px_minmax(0,1fr)]",children:[(0,a.jsx)("div",{className:(0,F.cn)(W.af,"flex h-full min-h-0 flex-col p-1"),children:(0,a.jsx)("div",{className:"scrollbar-ui-thin min-h-0 flex-1 space-y-1.5 overflow-y-auto",children:y.map(e=>{let r=e.models.some(e=>(0,o.t9)(t,e.id)),n=e.id===j?.id;return(0,a.jsx)("button",{type:"button",onClick:()=>x(e.id),className:(0,F.cn)("group flex w-full items-center rounded-[13px] border px-2 py-1.5 text-left outline-none transition-all duration-200 focus:outline-none focus-visible:outline-none focus-visible:ring-0",n?W.B5:W.ik),children:(0,a.jsxs)("span",{className:"flex min-w-0 flex-1 items-center gap-2.5",children:[(0,a.jsx)("span",{className:"flex h-7 w-7 shrink-0 items-center justify-center overflow-hidden rounded-[10px] border border-white/10 bg-black/35",children:(0,a.jsx)(w.default,{src:e.logoSrc,alt:"",width:18,height:18,className:(0,F.cn)("h-[15px] w-[15px]",e.logoClassName)})}),(0,a.jsxs)("span",{className:"min-w-0 flex-1 pr-1",children:[(0,a.jsxs)("span",{className:"flex items-center gap-1.5 leading-tight",children:[(0,a.jsx)("span",{className:"shrink-0 text-[12.5px] font-semibold text-foreground",children:e.label}),(0,K.GG)(e.id)?(0,a.jsx)(X.l,{}):null,r?(0,a.jsx)(N.y,{eligible:!0}):(0,K.n8)(e.id)?(0,a.jsx)("span",{className:(0,F.cn)("inline-flex shrink-0 items-center px-1.5 py-0.5 text-[8px] font-bold tracking-[0.04em]",W.Sc),children:(0,K.n8)(e.id)}
1):null,"seedance"===e.id&&(0,a.jsx)("span",{className:"inline-flex shrink-0 items-center rounded-[3px] bg-primary/20 px-1 py-[1px] text-[9px] font-bold tracking-[0.06em] text-primary",children:Y.yb})]}),(0,a.jsx)("span",{className:"mt-0.5 block whitespace-normal break-words text-[10.5px] leading-[1.25] text-foreground/45",children:e.description})]})]})},e.id)})})}),(0,a.jsx)("div",{className:(0,F.cn)(W.af,"flex min-h-0 h-full flex-col overflow-hidden p-1"),children:(0,a.jsx)("div",{className:"scrollbar-ui-thin max-h-[inherit] min-h-0 space-y-1 overflow-y-auto pr-1","data-video-generator-floating-content":"true",children:j?.models.map(e=>{let n,s=e.id===r,d=(0,Q.getModelMinimumVideoCreditDisplayOffer)(e),u=(0,K.MT)(e.id).filter(r=>!(0,o.t9)(t,e.id)||"deal"!==r.tone),c=Z[(0,K.fX)(e)]??Z.raphael;return(0,a.jsxs)("button",{type:"button",onClick:()=>{i(e.id),p(!1)},className:(0,F.cn)("relative w-full overflow-hidden rounded-[13px] border px-2 py-1.5 text-left outline-none transition-all duration-200 focus:outline-none focus-visible:outline-none focus-visible:ring-0",s?W.B5:W.ik),children:[(0,a.jsx)("div",{className:(0,F.cn)("pointer-events-none absolute inset-0 bg-gradient-to-br opacity-100",c.accentClassName||"from-amber-500/16 via-orange-500/8 to-transparent")}),(0,a.jsxs)("div",{className:"relative flex items-start gap-2",children:[(0,a.jsx)("span",{className:"flex h-7 w-7 shrink-0 items-center justify-center overflow-hidden rounded-[10px] border border-white/10 bg-black/40",children:(0,a.jsx)(w.default,{src:c.logoSrc,alt:e.label,width:18,height:18,className:(0,F.cn)("h-[15px] w-[15px]",c.logoClassName)})}),(0,a.jsxs)("span",{className:"min-w-0 flex-1",children:[(0,a.jsxs)("span",{className:"flex min-w-0 items-start gap-1.5",children:[(0,a.jsxs)("span",{className:"flex min-w-0 flex-1 flex-wrap items-center gap-1.5",children:[(0,a.jsx)("span",{className:"min-w-0 whitespace-normal break-words text-[12.5px] font-semibold leading-tight text-foreground",children:e.label}),(0,K.Cw)(e.id)?(0,a.jsx)(X.l,{}):null,u.map(e=>(0,a.jsx)("span",{className:(0,F.cn)("inline-flex shrink-0 items-center px-1.5 py-0.5 text-[8px] font-bold tracking-[0.04em]","deal"===e.tone?W.Sc:W.V$),children:e.label},e.label)),("minimax-h3"===e.id||"minimax-h3-turbo"===e.id)&&(0,a.jsx)("span",{className:"inline-flex h-5 w-5 shrink-0 items-center justify-center",children:(0,a.jsx)(N.y,{eligible:(0,o.t9)(t,e.id)})})]}),s?(0,a.jsx)("span",{className:"mt-[-1px] flex h-4 w-4 shrink-0 items-center justify-center text-primary/90",children:(0,a.jsx)("svg",{viewBox:"0 0 16 16",className:"h-4 w-4",fill:"none","aria-hidden":"true",children:(0,a.jsx)("path",{d:"M3.5 8.25 6.5 11l6-6",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round"})})}):null]}),(0,a.jsx)("span",{className:"mt-0.5 block whitespace-normal break-words text-[10.5px] leading-[1.25] text-foreground/45",children:l?.[e.id]??e.label}),(0,a.jsxs)("span",{className:"mt-1 flex flex-wrap items-center gap-x-1.5 gap-y-0.5 text-[10px] text-foreground/48",children:[(0,a.jsxs)("span",{className:"inline-flex items-center gap-1 whitespace-nowrap",children:[(0,a.jsx)(z.A,{className:"h-2.5 w-2.5 text-primary/85"}),null!==d.originalCredits?(0,a.jsx)("span",{className:"text-foreground/35 line-through decoration-foreground/50",children:d.originalCredits}):null,(0,a.jsxs)("span",{children:[d.credits,"+ ",m("selectors.credits")]})]}),(0,a.jsxs)("span",{className:"inline-flex items-center gap-1 whitespace-nowrap",children:[(0,a.jsx)(G.A,{className:"h-2.5 w-2.5 text-foreground/42"}),(0,a.jsx)("span",{children:(0,J.u8)(e)})]}),(0,a.jsxs)("span",{className:"inline-flex items-center gap-1 whitespace-nowrap",children:[(0,a.jsx)(A.A,{className:"h-2.5 w-2.5 text-foreground/42"}),(0,a.jsx)("span",{children:(n=(0,Q.getModelDurations)(e)).length<=1?`${n[0]??""}s`:`${Math.min(...n)}-${Math.max(...n)}s`})]}),(0,a.jsxs)("span",{className:"inline-flex items-center gap-1 whitespace-nowrap",children:[(0,a.jsx)(k.A,{className:"h-2.5 w-2.5 text-foreground/42"}),(0,a.jsx)("span",{children:e.estimatedTimeLabel})]})]})]})]})]},e.id)})})})]})]})})}function et(e){let{modelId:t,onModelChange:r,onGenerate:n,isGenerating:i,isLoggedIn:o,credits:l,originalCredits:s,isReady:d=!0,models:u,modelDescriptions:c,onClear:m,isEndFrameMissing:g,endFrameWarning:p,generateLabel:f="Generate",generatingLabel:h="Generating...",clearLabel:x="Clear",embedded:b=!1,supportsAudio:y=!1,generateAudio:w=!1,onGenerateAudioChange:I,audioLabel:j="Audio"}=e,F=(0,v.c)("videoGenerator.reference")("sound");return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("div",{className:["flex flex-col md:flex-row md:items-center justify-between gap-4 md:gap-6",b?"mt-4":"mt-6"].join(" "),children:[(0,a.jsxs)("div",{className:"flex flex-col md:flex-row items-stretch md:items-center gap-3 w-full md:w-auto",children:[(0,a.jsx)(ee,{selectedModelId:t,models:u,onModelSelect:r,modelDescriptions:c,className:"w-full md:w-auto",triggerClassName:"w-full md:w-auto md:max-w-[184px] text-secondary-foreground
1/88",panelAlign:"start",panelContainerClassName:"w-[min(90vw,584px)]"}),y&&I?(0,a.jsxs)("label",{className:"inline-flex h-8 cursor-pointer select-none items-center gap-1.5 rounded-lg border border-white/8 bg-white/[0.04] px-2 text-[12px] font-medium text-secondary-foreground/82 transition-colors hover:bg-white/[0.06]",children:[(0,a.jsx)("span",{children:F}),(0,a.jsx)($.Switch,{checked:w,onCheckedChange:I,"aria-label":j,className:"h-3.5 w-6 [&>span]:h-2.5 [&>span]:w-2.5 [&>span]:data-[state=checked]:translate-x-2.5"})]}):null]}),(0,a.jsxs)("div",{className:"flex flex-wrap items-center gap-2 w-full md:w-auto md:gap-3",children:[m&&(0,a.jsx)("button",{type:"button",onClick:m,className:["hidden md:block px-4 h-10 text-sm font-medium rounded-full transition-colors",b?"bg-[rgba(41,29,23,0.78)] text-muted-foreground hover:text-foreground hover:bg-[rgba(48,34,27,0.86)]":"text-muted-foreground hover:text-foreground hover:bg-secondary/50"].join(" "),children:x}),(0,a.jsx)("div",{className:"flex-1 md:flex-none",children:(0,a.jsx)(M.M,{onClick:n,label:f,loadingLabel:h,isLoading:i,softDisabled:!d,className:"md:w-auto",cornerBadgeLabel:_({currentCredits:l,originalCredits:s}),children:(0,a.jsx)(H,{cost:l,originalCost:s,mode:"inline"})})})]})]}),o&&g&&p&&(0,a.jsx)("p",{className:"text-xs text-destructive text-center mt-2 animate-in fade-in slide-in-from-top-1",children:p})]})}var er=r(40810),en=r(36820),ea=r(67850),ei=r(63631),eo=r(38406),el=r(74862),es=r(22537);function ed(e){let t=(0,h.useMemo)(()=>e?"string"==typeof e?e:URL.createObjectURL(e):null,[e]);return(0,h.useEffect)(()=>()=>{t&&e instanceof File&&URL.revokeObjectURL(t)},[t,e]),t}var eu=r(90794),ec=r(89798),em=r(89540),eg=r(43722);function ep(e){return e.imageCount+e.videoCount+e.audioCount>0}let ef=["prompt","model","aspect","resolution","length","reference"];function eh(e){if("reference"===e.inputMode)return"referenceToVideo";if("startEndFrame"===e.inputMode)return"imageToVideo";let t="string"==typeof e.inputMode,r=ep({imageCount:e.referenceImages?.length??0,videoCount:e.referenceVideos?.length??0,audioCount:e.referenceAudios?.length??0});return!t&&("referenceToVideo"===e.mode||r)?"referenceToVideo":e.startFrameImage||e.endFrameImage||e.addEndFrame||!t&&"imageToVideo"===e.mode?"imageToVideo":r?"referenceToVideo":"textToVideo"}function ex(e,t){return"referenceToVideo"===t?e.referenceImages.length:"imageToVideo"!==t?0:Number(!!e.startFrameImage)+Number(!!(e.addEndFrame&&e.endFrameImage))}var eb=r(38052);function ev(e){let{locale:t,target:r,addEndFrame:n,startLabel:a,endLabel:i,labels:o}=e,l=t.startsWith("zh"),s=a||(l?"开始":"Start"),d=i||(l?"结束":"End"),u=o?.reference??(l?"参考图":"Reference"),c=o?.optional??(l?"可选":"Optional"),m=o?.frame??(l?"帧":"Frame"),g="end"===r?d:s,p="end"===r?d:n?s:u,f="end"===r||n?m:c;return{previewLabel:g,overlayLabel:n?g:void 0,emptyLabel:p,emptySubtitle:f,tileLabel:n||"end"===r?`${g}${l?"帧":" Frame"}`:u,tileHelper:f,buttonAriaLabel:o?.select(p)??(l?`选择${p}`:`Select ${p}`),removeAriaLabel:o?.remove(p)??(l?`移除${p}`:`Remove ${p}`)}}var ey=r(77992),ew=r(40894),eI=r(55188),ej=r(36292),eF=r(50165),eN=r(45607),eC=r(36776),eR=r(23992);function ek(e){let{item:t}=e,r=ed(t.source),n=function(e,t){if(e instanceof File&&e.name)return e.name;if("string"==typeof e)try{return new URL(e).pathname.split("/").pop()||t}catch{}return t}(t.source,t.kind);return r?"image"===t.kind?(0,a.jsx)("img",{src:r,alt:"",className:"max-h-[72vh] max-w-full object-contain"}):"video"===t.kind?(0,a.jsx)("video",{src:r,controls:!0,playsInline:!0,className:"max-h-[72vh] max-w-full rounded-xl bg-black"}):(0,a.jsxs)("div",{className:"flex min-h-[240px] w-full max-w-lg flex-col items-center justify-center gap-5 rounded-[20px] border border-white/10 bg-black/24 px-6 text-center",children:[(0,a.jsx)("div",{className:"flex h-16 w-16 items-center justify-center rounded-full border border-primary/25 bg-primary/10 text-primary",children:(0,a.jsx)(ey.A,{className:"h-8 w-8"})}),(0,a.jsx)("div",{className:"max-w-sm truncate text-sm font-medium text-foreground/88",children:n}),(0,a.jsx)("audio",{src:r,controls:!0,className:"w-full max-w-sm"})]}):null}
1function eA(e){let{items:t,previewIndex:r,title:n,previousLabel:i,nextLabel:o,onPreviewIndexChange:l}=e,s=null!==r&&r>=0&&r<t.length?t[r]:null;return(0,a.jsx)(eR.lG,{open:null!==r&&!!s,onOpenChange:e=>{e||l(null)},children:(0,a.jsxs)(eR.Cf,{className:"max-w-[calc(100vw-1.5rem)] border-white/10 bg-popover/95 p-3 text-foreground shadow-2xl backdrop-blur-2xl sm:max-w-4xl sm:p-5",children:[(0,a.jsxs)("div",{className:"flex items-center justify-between gap-3",children:[(0,a.jsx)(eR.L3,{className:"text-sm font-medium text-foreground/88",children:n}),(0,a.jsx)(eR.HM,{className:"flex h-8 w-8 items-center justify-center rounded-full border border-white/10 bg-white/[0.04] text-foreground/70 transition-colors hover:bg-white/[0.08] hover:text-foreground",children:(0,a.jsx)(eI.A,{className:"h-4 w-4"})})]}),s?(0,a.jsxs)("div",{className:"relative flex min-h-[260px] items-center justify-center overflow-hidden rounded-[20px] border border-white/8 bg-black/20 p-3 sm:min-h-[320px] sm:p-4",children:[(0,a.jsx)(ek,{item:s}),t.length>1?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("button",{type:"button",onClick:()=>l(null===r?0:(r-1+t.length)%t.length),className:"absolute bottom-0 left-2 top-0 my-auto flex h-10 w-10 items-center justify-center rounded-full border border-white/12 bg-black/55 text-white/92 backdrop-blur-md transition-colors hover:bg-black/70 sm:left-3","aria-label":i,children:(0,a.jsx)(eN.A,{className:"h-5 w-5"})}),(0,a.jsx)("button",{type:"button",onClick:()=>l(null===r?0:(r+1)%t.length),className:"absolute bottom-0 right-2 top-0 my-auto flex h-10 w-10 items-center justify-center rounded-full border border-white/12 bg-black/55 text-white/92 backdrop-blur-md transition-colors hover:bg-black/70 sm:right-3","aria-label":o,children:(0,a.jsx)(eC.A,{className:"h-5 w-5"})})]}):null]}):null]})})}function eS(e){return e instanceof File?`${e.name}-${e.size}-${e.lastModified}`:e}function eM(e){let{item:t,raised:r,showRemove:n,removeLabel:i,previewLabel:o,onClick:l,onRemove:s,onMouseEnter:d,onMouseLeave:u,className:c,style:m}=e,g=ed(t.source),p=function(e,t){if(e instanceof File&&e.name)return e.name;if("string"==typeof e)try{return new URL(e).pathname.split("/").pop()||t}catch{}return t}(t.source,o),[f,x]=(0,h.useState)("");return(0,h.useEffect)(()=>{if("video"!==t.kind||!g)return void x("");let e=document.createElement("video"),r=window.setTimeout(()=>{x(""),n()},8e3),n=()=>{window.clearTimeout(r),e.removeAttribute("src"),e.load()};return e.preload="metadata",e.muted=!0,e.playsInline=!0,e.onloadedmetadata=()=>{x(function(e){if(!Number.isFinite(e)||e<=0)return"";let t=Math.max(0,Math.round(e)),r=Math.floor(t/3600),n=Math.floor(t%3600/60),a=t%60;return r>0?`${r}:${String(n).padStart(2,"0")}:${String(a).padStart(2,"0")}`:`${String(n).padStart(2,"0")}:${String(a).padStart(2,"0")}`}(e.duration)),n()},e.onerror=()=>{x(""),n()},e.src=g,n},[t.kind,g]),(0,a.jsxs)("div",{className:(0,F.cn)(em.tD,r?"border-primary/60 shadow-[0_24px_56px_-34px_rgba(255,166,76,0.82)]":"border-white/10","group/card hover:border-primary/40",c),style:m,onMouseEnter:d,onMouseLeave:u,children:[(0,a.jsxs)("button",{type:"button",onClick:l,className:"h-full w-full overflow-hidden rounded-none focus:outline-none","aria-label":o,children:["image"===t.kind&&g?(0,a.jsx)("img",{src:g,alt:"",className:"h-full w-full object-cover"}):null,"video"===t.kind&&g?(0,a.jsx)("video",{src:g,muted:!0,playsInline:!0,preload:"metadata",className:"h-full w-full object-cover"}):null,"audio"===t.kind?(0,a.jsxs)("div",{className:"flex h-full w-full flex-col items-center justify-center gap-2 bg-[linear-gradient(145deg,#3a2c46,#211927)] px-2 text-center",children:[(0,a.jsx)("div",{className:"flex h-10 w-10 items-center justify-center rounded-full border border-white/14 bg-[#4a3859] text-primary shadow-[0_16px_32px_-24px_rgba(0,0,0,0.95)]",children:(0,a.jsx)(ey.A,{className:"h-5 w-5"})}),(0,a.jsx)("span",{className:"line-clamp-2 max-w-full break-all text-[9px] font-medium leading-tight text-white/82",children:p})]}):null,"image"!==t.kind?(0,a.jsx)("div",{className:"absolute inset-0 bg-gradient-to-t from-black/72 via-black/8 to-transparent"}):null,"video"===t.kind?(0,a.jsx)("span",{className:"pointer-events-none absolute inset-0 flex items-center justify-center",children:(0,a.jsx)("span",{className:"flex h-7 w-7 items-center justify-center rounded-full bg-black/45 backdrop-blur-sm ring-1 ring-white/20",children:(0,a.jsx)(ew.A,{className:"h-3.5 w-3.5 translate-x-[1px] fill-white text-white"})})}):null,"video"===t.kind&&f?(0,a.jsx)("span",{className:"absolute bottom-1.5 right-1.5 rounded-full bg-black/58 px-1.5 py-0.5 text-[9px] font-medium leading-none text-white/90 shadow-[0_8px_18px_-12px_rgba(0,0,0,0.9)]",children:f}):null]}),(0,a.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),s()},className:(0,F.cn)("absolute -right-2.5 -top-2.5 z-20 flex h-7 w-7 items-center justify-center rounded-full border border-primary/35 bg-[rgba(98,72,52,0.92)] text-primary/90 shadow-[0_12px_28px_-18px_rgba(0,0,0,0.95)] backdrop-blur-md transition-all duration-200 hover:border-primary/45 hover:bg-[rgba(112,82,58,0.96)] hover:text-primary",n?"opacity-0 group-hover/card:opacity-100":"opacity-0"),"aria-label":i,children:(0,a.jsx)(eI.A,{className:"h-3.5 w-3.5"})})]})}function e_(e){let{label:t,className:r,style:n}=e;return(0,a.jsxs)("div",{className:(0,F.cn)(em.tD,"overflow-hidden border-primary/30 bg-[rgba(38,28,22,0.96)]",r),style:n,role:"status","aria-label":t,children:[(0,a.jsx)("div",{className:"flex h-full w-full items-center justify-center",children:(0,a.jsx)("div",{className:"h-8 w-8 rounded-full border-2 border-primary/20 border-t-primary animate-spin"})}),(0,a.jsx)("div",{className:"absolute inset-x-3 bottom-3 h-1 overflow-hidden rounded-full bg-white/10",children:(0,a.jsx)("div",{className:"h-full w-full animate-pulse rounded-full bg-primary"})})]})}function eE(e){let{locale:t,referenceImages:r,referenceVideos:n,referenceAudios:i,imageLimit:o,videoLimit:l,audioLimit:s,videoTotalSeconds:d,audioTotalSeconds:u,label:c,helper:m,isProcessing:g=!1,processingLabel:p,onAdd:f,onRemoveImage:x,onRemoveVideo:b,onRemoveAudio:y}=e,w=(0,h.useRef)(null),[I,j]=(0,h.useState)(!1),[N,C]=(0,h.useState)(null),[R,k]=(0,h.useState)(null),A=(0,h.useRef)(null),S=(0,v.c)("videoGenerator.reference"),M=(0,h.useMemo)(()=>[...r.map((e,t)=>({kind:"image",source:e,index:t,key:`image-${t}-${eS(e)}`})),...n.map((e,t)=>({kind:"video",source:e,index:t,key:`video-${t}-${eS(e)}`})),...i.map((e,t)=>({kind:"audio",source:e,index:t,key:`audio-${t}-${eS(e)}`}))],[i,r,n]),_=()=>{null!==A.current&&(window.clearTimeout(A.current),A.current=null)},E=()=>{_(),j(!0)},T=()=>{_(),A.current=window.setTimeout(()=>{C(null),j(!1),A.current=null},60)};(0,h.useEffect)(()=>()=>_(),[]),(0,h.useEffect)(()=>{null===R||R<M.length||k(M.length>0?M.length-1:null)},[M.length,R]);let L=(0,eF.t4)(M.length),V=I?M:M.slice(L),P=I?0:L,D=r.length<o||n.length<l||i.length<s,U=Math.max(0,V.length-1),O=(0,eF.pZ)(U,V.length,I),{left:$,top:W}=(0,eF.yW)(O,V.length),q=I?(0,eF.lZ)(V.length):null,H=I?(0,eF.lZ)(V.length):{left:20,top:10,rotation:7},B=(0,eF.W3)(V.length,D&&I),z=S("add"),G=p??S("processing"),X=S("remove"),Y=S("preview"),Q=l>0||s>0,J=Q?(0,a.jsxs)("span",{className:"flex flex-col items-center gap-0.5 text-[9px] leading-[1.05]",children:[(0,a.jsx)("span",{children:S("helperImageCompact",{imageCount:o})}),s>0&&u?(0,a.jsx)("span",{children:S("helperAudioSeconds",{seconds:u})}):null,l>0&&d?(0,a.jsx)("span",{children:S("helperVideoSeconds",{seconds:d})}):null]}):m,K=e=>{e.stopPropagation(),f()};return 0===M.length?(0,a.jsx)("div",{className:"relative z-10 flex h-[112px] w-[88px] flex-col overflow-visible",children:g?(0,a.jsx)(e_,{label:G,className:"left-[6px] top-[4px]",style:{transform:"rotate(-4deg)"}}):(0,a.jsx)(em.Ut,{compact:!0,emptyState:"text",emptyLabel:Q?void 0:c,emptySubtitle:J,onClick:f})}):(0,a.jsxs)("div",{ref:w,className:"relative z-10 flex w-[88px] flex-col overflow-visible",children:[(0,a.jsxs)("div",{className:"group relative h-[112px] overflow-visible",onMouseEnter:E,onMouseLeave:T,children:[(0,a.jsx)("div",{className:"pointer-events-none absolute left-0 top-0 h-full overflow-visible",style:{width:I?B:eF.tF},children:(0,a.jsxs)("div",{className:"pointer-events-none absolute inset-0 overflow-visible",children:[V.map((e,t)=>{let r=P+t,{left:n,top:i,rotation:o}=(0,eF.pZ)(t,V.length,I),l=N===r;return(0,a.jsx)("div",{className:"pointer-events-auto absolute overflow-visible",style:{left:n,top:i,zIndex:l?V.length+40:t+1},children:(0,a.jsx)(eM,{item:e,raised:l,showRemove:!0,removeLabel:X,previewLabel:Y,onClick:()=>k(r),onRemove:()=>{"image"===e.kind&&x(e.index),"video"===e.kind&&b(e.index),"audio"===e.kind&&y(e.index)},onMouseEnter:()=>{E(),C(r)},onMouseLeave:()=>
1{T(),C(e=>e===r?null:e)},style:{transform:`translateY(${l?-12:0}px) rotate(${o}deg)`}})},e.key)}),g?(0,a.jsx)(e_,{label:G,className:"pointer-events-auto",style:{left:H.left,top:H.top,zIndex:V.length+30,transform:`rotate(${H.rotation}deg)`}}):null]})}),D&&I&&q&&!g?(0,a.jsx)("button",{type:"button",onClick:K,onMouseEnter:E,onMouseLeave:T,className:(0,F.cn)(em.mf,"hover:-translate-y-1 hover:border-primary/35 hover:bg-[rgba(24,17,14,0.82)]"),style:{left:q.left,top:q.top,transform:`rotate(${q.rotation}deg)`},"aria-label":z,children:(0,a.jsx)(ej.A,{className:"h-6 w-6"})}):null,!D||I||g?null:(0,a.jsx)("button",{type:"button",onClick:K,onMouseEnter:E,onMouseLeave:T,className:"absolute z-20 flex h-7 w-7 items-center justify-center rounded-full border border-white/10 bg-[rgba(78,56,38,0.92)] text-primary shadow-[0_18px_40px_-28px_rgba(0,0,0,0.96)] backdrop-blur-md transition-all duration-200 hover:scale-105 hover:bg-[rgba(92,66,44,0.95)]",style:{left:$,top:W},"aria-label":z,children:(0,a.jsx)(ej.A,{className:"h-3.5 w-3.5"})})]}),(0,a.jsx)(eA,{items:M,previewIndex:R,title:Y,previousLabel:S("previous"),nextLabel:S("next"),onPreviewIndexChange:k})]})}var eT=r(30900),eL=r(3715);function eV(e){let{value:t,onPromptChange:r,label:n,placeholder:i,examples:o,imageExamples:l,actions:s,controls:d,hints:u,labels:c,state:m,modelConfig:g,onStateChange:f,onImageFileSelected:x,onImageClick:y,isStartFrameLoading:w=!1,embedded:I=!1,stickyExpanded:j=!1,hideInlineControls:N=!1,embeddedFooter:C,sharedLayoutVariant:S,embeddedFooterClassName:M,activeMediaMode:_,onMediaModeChange:T,enhancePrompt:V,onEnhancePromptChange:P,enhancePromptLabel:D="AI Enhance"}=e,U=(0,b.Ym)(),O=(0,v.c)("videoGenerator.reference"),$=(0,v.c)("uploadErrors"),q=(0,h.useId)(),H=(0,h.useId)(),[B,z]=(0,h.useState)(null),[X,Y]=(0,h.useState)(!1),K=(0,h.useRef)(null),Z=(0,h.useRef)(null),ee=d?.singleFrame??"First Frame",et=d?.startEnd??"Start & End",ep=c?.start??"Start",ef=c?.end??"End",ex=c?.clip??"Clip",ey=c?.clips??"Clips",ew=O("loading"),eI=ed(m.startFrameImage),ej=ed(m.endFrameImage),eF=eh(m),eN=(0,J.P3)(g,eF,m.resolution),eC={auto:O("auto"),adaptive:O("adaptive")},eR=(0,J.Yo)(g,m.resolution,eF),ek=m.durationAuto?"auto":m.length,eA=(g?.maxImageCount??1)>0,eS=(0,J.US)(g),eM=(0,Q.supportsVideoReferenceMode)(g,m.resolution),e_=g?.provider==="veo"||!!g?.id.startsWith("veo-3.1-"),eV=(0,J.JX)(g),{imageCount:eP,videoCount:eD,audioCount:eU,totalCount:eO,imageFormats:e$,videoFormats:eW,audioFormats:eq,videoMinSeconds:eH,videoMaxSeconds:eB,videoTotalSeconds:ez,audioMinSeconds:eG,audioMaxSeconds:eX,audioTotalSeconds:eY}=eV,eQ=(0,J.if)(eV,{imagesDetailed:O.has("helperImagesDetailed")?String(O.raw("helperImagesDetailed")):u?.referenceHelperImagesDetailed,multiDetailed:O.has("helperMultiDetailed")?String(O.raw("helperMultiDetailed")):u?.referenceHelperMultiDetailed,multiDetailedWithTotal:O.has("helperMultiDetailedWithTotal")?String(O.raw("helperMultiDetailedWithTotal")):u?.referenceHelperMultiDetailedWithTotal,imagesFallback:O("helperImages",{imageCount:eP}),multiFallback:O("helperMulti",{imageCount:eP,videoCount:eD,audioCount:eU})}),eJ=eD>0||eU>0?eQ:O("helperImages",{imageCount:eP}),eK=O.has("allInOneLabel")?O("allInOneLabel"):d?.allInOneReference??d?.reference??"Reference",eZ=O.has("multiImageLabel")?O("multiImageLabel"):d?.multiImageReference??d?.reference??"Reference",e0=(0,J.ke)(g,m.resolution,d?.reference??"Reference",eK,eZ),e1=(0,J.rj)(eF,{text:i,image:i,reference:eQ}),e2=eT.JK,e5=[...e2,...eD>0?["video/mp4","video/quicktime"]:[],...eU>0?["audio/mpeg","audio/wav","audio/x-wav"]:[]].join(","),e3=e2.join(","),e4=eS&&("startEndFrame"===m.inputMode||m.addEndFrame),e8=e=>
1(0,F.cn)("h-8 sm:h-9 px-3 sm:px-4 rounded-full border text-xs sm:text-sm font-medium transition-all flex items-center gap-2 shadow-sm active:scale-95",e?"border-transparent bg-primary/10 text-primary":"border-white/5 bg-secondary/40 text-foreground/80 hover:bg-secondary/60 hover:border-white/10 hover:text-foreground"),e6=(e,t)=>{let r=(0,eb.U3)(e);return r>1.05?(0,a.jsx)(en.A,{className:t}):r<.95?(0,a.jsx)(ea.A,{className:t}):(0,a.jsx)(ei.A,{className:t})},e9=e=>{let{target:t,image:r,previewUrl:n}=e,i=ev({locale:U,target:t,addEndFrame:m.addEndFrame,startLabel:ep,endLabel:ef,labels:{reference:O("label"),optional:O("optional"),frame:O("frame"),select:e=>O("selectLabel",{label:e}),remove:e=>O("removeLabel",{label:e})}});return(0,a.jsx)(em.Ut,{compact:!0,previewUrl:n,imageAlt:i.previewLabel,buttonAriaLabel:i.buttonAriaLabel,removeAriaLabel:i.removeAriaLabel,previewFit:"cover",loading:"start"===t&&w,loadingLabel:ew,emptyState:"text",emptyLabel:i.emptyLabel,emptySubtitle:i.emptySubtitle,imageOverlayLabel:i.overlayLabel,onClick:()=>{r&&y?y(t):(K.current?.setAttribute("data-target",t),K.current?.click())},onRemove:r?()=>f("start"===t?{startFrameImage:null,originalStartFrameImage:null}:{endFrameImage:null,originalEndFrameImage:null}):void 0})},e7=async e=>{let t,r=e.currentTarget,n=Array.from(r.files??[]);if(r.value="",0===n.length)return;let a=n.some(e=>e.type.startsWith("video/")&&e.size>0x1400000)?R.oR.loading(O("checkingVideo")):void 0;try{Y(!0),t=await (0,p.wI)({files:n,resolution:m.resolution,existingImages:m.referenceImages,existingVideos:m.referenceVideos,existingAudios:m.referenceAudios,imageLimit:eP,videoLimit:eD,audioLimit:eU,totalLimit:g?.maxReferenceTotalCount,imageMaxBytes:e_?p.Lx:void 0,modelId:g?.id})}catch{R.oR.error((0,eg.A)({code:"upload_failed",mediaType:"media"},U,$));return}finally{Y(!1),void 0!==a&&R.oR.dismiss(a)}t.errors.forEach(e=>{R.oR.error((0,eg.A)(e,U,$))}),(t.images.length>0||t.videos.length>0||t.audios.length>0)&&f({referenceImages:[...m.referenceImages,...t.images],referenceVideos:[...m.referenceVideos,...t.videos],referenceAudios:[...m.referenceAudios,...t.audios]})};return(0,a.jsx)(a.Fragment,{children:(0,a.jsxs)(eu.i,{variant:S,containerClassName:(0,F.cn)("rounded-xl px-2",I?"py-0.5 rounded-2xl sm:rounded-xl shadow-[0_24px_64px_-40px_rgba(0,0,0,0.68)]":"mb-2 sm:mb-3 py-0.5 border border-border/60"),contentClassName:ec.D_,footerClassName:(0,F.cn)(ec.Nz,M),footer:C,header:(0,a.jsx)(eL.R,{activeMode:_,onModeChange:T,enhancePrompt:V,onEnhancePromptChange:P,enhancePromptLabel:D}),children:[(0,a.jsxs)("div",{className:(0,F.cn)("flex items-stretch",ec.D9.compact),children:[(eA||eM)&&(0,a.jsxs)("div",{className:"flex-shrink-0 flex items-start self-start gap-3 pt-1 sm:pt-2",children:[(0,a.jsx)("input",{id:q,name:"videoFrameUpload",type:"file",ref:K,onChange:e=>{let t=e.currentTarget.files?.[0];t&&(x("end"===e.currentTarget.dataset.target?"end":"start",t),e.currentTarget.value="")},className:"hidden",accept:e3,"aria-label":O("selectLabel",{label:e0})}),"reference"===m.inputMode&&eM?(0,a.jsxs)("div",{className:"shrink-0 overflow-visible",children:[(0,a.jsx)("input",{id:H,name:"videoReferenceMediaUpload",type:"file",ref:Z,onChange:e7,className:"hidden",accept:e5,"aria-label":O("add"),multiple:!0}),(0,a.jsx)(eE,{locale:U,referenceImages:m.referenceImages,referenceVideos:m.referenceVideos,referenceAudios:m.referenceAudios,imageLimit:eP,videoLimit:eD,audioLimit:eU,videoTotalSeconds:ez,audioTotalSeconds:eY,label:e0,helper:eJ,isProcessing:X,processingLabel:O("processing"),onAdd:()=>{Z.current?.click()},onRemoveImage:e=>f({referenceImages:m.referenceImages.filter((t,r)=>r!==e)}),onRemoveVideo:e=>f({referenceVideos:m.referenceVideos.filter((t,r)=>r!==e)}),onRemoveAudio:e=>f({referenceAudios:m.referenceAudios.filter((t,r)=>r!==e)})})]}):eA?(0,a.jsxs)(a.Fragment,{children:[e9({target:"start",image:m.startFrameImage,previewUrl:eI}),e4&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("div",{className:"flex w-4 shrink-0 items-center justify-center self-stretch text-muted-foreground/16",children:(0,a.jsx)(eo.A,{className:"h-3 w-3"})}),e9({target:"end",image:m.endFrameImage,previewUrl:ej})]})]}):null]}),(0,a.jsx)("div",{className:"flex-1 min-w-0 flex flex-col justify-start pt-0",children:(0,a.jsx)("div",{className:"relative flex-1 flex flex-col",children:(0,a.jsx)(er.T,{value:t,onChange:e=>
1r(e.target.value),placeholder:e1,"data-prompt-input":"video",className:(0,F.cn)(ec.PL,ec.T9,ec.B9.compact,"flex-1 pt-0")})})})]}),!N&&(0,a.jsxs)("div",{className:"flex flex-wrap gap-1.5 sm:gap-2 mt-0 sm:mt-2 px-2 pb-2",children:[(0,a.jsx)("div",{className:"relative",children:(0,a.jsx)(L.s,{open:"aspect"===B,onOpenChange:e=>z(e?"aspect":null),panelAlign:"start",panelContainerClassName:"w-[160px] sm:w-[200px]",panelSurfaceClassName:"p-1.5 sm:p-2",trigger:(0,a.jsxs)("button",{type:"button",className:e8("aspect"===B),children:[e6(m.aspectRatio,"w-4 h-4"),(0,a.jsx)("span",{children:(0,J.Qp)(m.aspectRatio,U,eC)})]}),children:(0,a.jsx)("div",{className:(0,F.cn)("grid gap-1.5 sm:gap-2",eN.length<=1?"grid-cols-1":"grid-cols-2"),children:eN.map(e=>(0,a.jsxs)("button",{type:"button",onClick:()=>{f({aspectRatio:e}),z(null)},className:(0,F.cn)("flex flex-col items-center justify-center gap-1 sm:gap-2 rounded-[10px] border p-2 sm:p-3 text-xs sm:text-sm transition-all duration-200",m.aspectRatio===e?W.ws:W.xu),children:[e6(e,"w-4 h-4 sm:w-5 sm:h-5"),(0,a.jsx)("span",{children:(0,J.Qp)(e,U,eC)})]},e))})})}),(0,a.jsx)("div",{className:"relative",children:(0,a.jsx)(L.s,{open:"length"===B,onOpenChange:e=>z(e?"length":null),panelAlign:"start",panelContainerClassName:"w-[120px]",panelSurfaceClassName:"p-1",trigger:(0,a.jsxs)("button",{type:"button",className:e8("length"===B),children:[(0,a.jsx)(k.A,{className:"w-4 h-4"}),(0,a.jsx)("span",{children:(0,J.t4)(m.length,m.durationAuto,O("auto"))})]}),children:(0,a.jsx)("div",{className:"p-1",children:(0,a.jsx)(E.Nj,{className:"gap-0.5",itemClassName:"px-1 text-[12px]",options:eR.map(e=>({value:e,label:"auto"===e?O("auto"):`${e}s`})),selected:ek,onSelect:e=>{f((0,J.AT)(g,e)),z(null)}})})})}),(0,a.jsx)("div",{className:"relative",children:(0,a.jsx)(L.s,{open:"resolution"===B,onOpenChange:e=>z(e?"resolution":null),panelAlign:"start",panelContainerClassName:"w-[140px]",panelSurfaceClassName:"p-1",trigger:(0,a.jsxs)("button",{type:"button",className:e8("resolution"===B),children:[(0,a.jsx)(G.A,{className:"w-4 h-4"}),(0,a.jsx)("span",{children:(0,Q.getVideoOutputLabel)(g,m.resolution)})]}),children:(0,a.jsx)("div",{className:(0,F.cn)(W.d2,"flex-col"),children:(0,Q.getModelResolutions)(g).map(e=>(0,a.jsx)("button",{type:"button",onClick:()=>{f({resolution:e}),z(null)},className:(0,F.cn)("flex h-8 w-full items-center rounded-[9px] px-3 text-left text-sm transition-all duration-200",m.resolution===e&&W.ws,m.resolution!==e&&W.xu),children:(0,Q.getVideoOutputLabel)(g,e)},e))})})}),(0,a.jsx)("div",{className:"relative",children:(0,a.jsx)(L.s,{open:"output"===B,onOpenChange:e=>z(e?"output":null),panelAlign:"start",panelContainerClassName:"w-[180px]",panelSurfaceClassName:"p-2",trigger:(0,a.jsxs)("button",{type:"button",className:e8("output"===B),children:[(0,a.jsx)(el.A,{className:"w-4 h-4"}),(0,a.jsxs)("span",{children:[m.outputCount," ",m.outputCount>1?ey:ex]})]}),children:(0,a.jsx)("div",{className:(0,F.cn)(W.d2,"gap-1 p-1"),children:[1,2,3,4].map(e=>(0,a.jsx)("button",{type:"button",onClick:()=>{f({outputCount:e}),z(null)},className:(0,F.cn)("flex h-8 flex-1 items-center justify-center rounded-[9px] border text-sm font-medium transition-all duration-200",m.outputCount===e?W.ws:W.xu),children:e},e))})})}),((g?.maxImageCount??1)>1||eM)&&(0,a.jsx)("div",{className:"relative",children:(0,a.jsx)(L.s,{open:"frames"===B,onOpenChange:e=>z(e?"frames":null),panelAlign:"start",panelContainerClassName:"w-[160px]",panelSurfaceClassName:"p-1",trigger:(0,a.jsxs)("button",{type:"button",className:e8(m.addEndFrame),children:[(0,a.jsx)(A.A,{className:"w-4 h-4"}),(0,a.jsx)("span",{children:"reference"===m.inputMode?e0:"startEndFrame"===m.inputMode||m.addEndFrame?et:ee})]}),children:(0,a.jsxs)("div",{className:(0,F.cn)(W.d2,"flex-col"),children:[(0,a.jsxs)("button",{type:"button",onClick:()=>{f({inputMode:"singleFrame",addEndFrame:!1}),z(null)},className:(0,F.cn)("flex h-8 w-full items-center gap-2 rounded-[9px] px-3 text-left text-sm transition-all duration-200","singleFrame"===m.inputMode&&W.ws,"singleFrame"!==m.inputMode&&W.xu),children:[(0,a.jsx)(es.A,{className:"w-4 h-4"}),(0,a.jsx)("span",{children:ee})]}),eS?(0,a.jsxs)("button",{type:"button",onClick:()=>{let e="string"==typeof m.startFrameImage&&l?.some(e=>e.image===m.startFrameImage);m.endFrameImage||!e?f({inputMode:"startEndFrame",addEndFrame:!0}):f({inputMode:"startEndFrame",addEndFrame:!0,endFrameImage:m.startFrameImage,originalEndFrameImage:m.originalStartFrameImage??m.startFrameImage,endFrameDimensions:m.startFrameDimensions}),z(null)},className:(0,F.cn)("flex h-8 w-full items-center gap-2 rounded-[9px] px-3 text-left text-sm transition-all duration-200","startEndFrame"===m.inputMode&&W.ws,"startEndFrame"!==m.inputMode&&W.xu),children:[(0,a.jsx)(eo.A,{className:"h-3.5 w-3.5"}),(0,a.jsx)("span",{children:et})]}):null,eM?(0,a.jsxs)("button",{type:"button",onClick:()=>{f({inputMode:"reference"}),z(null)},className:(0,F.cn)("flex h-8 w-full items-center gap-2 rounded-[9px] px-3 text-left text-sm transition-all duration-200","reference"===m.inputMode&&W.ws,"reference"!==m.inputMode&&W.xu),children:[(0,a.jsx)(A.A,{className:"h-3.5 w-3.5"}),(0,a.jsx)("span",{children:e0})]}):null]})})})]})]})})}var eP=r(69248),eD=r(18767);function eU(e){let{label:t,help:r}=e;return(0,a.jsxs)("span",{className:"inline-flex items-center gap-1",children:[(0,a.jsx)("span",{children:t}),(0,a.jsxs)(eD.AM,{children:[(0,a.jsx)(eD.Wv,{asChild:!0,children:(0,a.jsx)("button",{type:"button","aria-label":r,className:"inline-flex h-5 w-5 shrink-0 items-center justify-center rounded-full text-foreground
1/45 transition-colors hover:bg-white/[0.06] hover:text-foreground/75 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-primary/60",children:(0,a.jsx)(eP.A,{className:"h-3.5 w-3.5","aria-hidden":"true"})})}),(0,a.jsx)(eD.hl,{align:"start",side:"top",className:"z-[1200] w-64 border-white/10 bg-[rgba(41,30,23,0.99)] p-3 text-xs leading-relaxed text-foreground/78 shadow-xl",children:r})]})]})}function eO(e){let{unlimitedAvailable:t,unlimitedPlan:r="free",state:n,onChange:i,onImageFileSelected:l,onImageClick:s,onGenerate:d,isGenerating:u,isLoggedIn:c,isStartFrameLoading:m=!1,models:g,activeModel:p,embedded:f=!1,stickyExpanded:x=!1,activeMediaMode:y,onMediaModeChange:w,generator:I,credits:j,originalCredits:P,resolvedMode:D,isReadyToGenerate:q,isEndFrameMissing:z,clearState:G,showFrameToggle:X,singleFrameLabel:Y,startEndLabel:Z,referenceLabel:er,audioOnLabel:en,audioOffLabel:ea}=e,ei=(0,b.Ym)(),eo=(0,v.c)("videoGenerator.reference"),el=(0,v.c)("imageGenerator.controls"),es=(0,v.c)("imageGenerator.switches"),[ed,eu]=(0,h.useState)(!1),[ec,em]=(0,h.useState)(!1),[eg,ep]=(0,h.useState)(!1),[ef,eh]=(0,h.useState)(!1),ex=(0,F.cn)(T.jB,T.c1),eb=(0,F.cn)("flex items-center gap-1 text-secondary-foreground/88",T.DJ,ex),ev=(0,J.P3)(p,D,n.resolution),ey=(0,J._g)(p,n.resolution,D),ew=(0,J.Yo)(p,n.resolution,D),eI=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:n.resolution,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:n.length;return(0,o.$2)(r,{kind:"video",modelId:n.modelId,resolution:e,durationSeconds:t,outputCount:1})},ej=n.durationAuto?"auto":n.length,eF=(0,Q.getVideoPhysicalResolutions)(p),eN=(0,Q.getVideoOutputResolution)(p,n.resolution),eC=(0,Q.getVideoQualityOptions)(p,eN),eR=(0,Q.getVideoOutputQuality)(p,n.resolution),ek=e=>{let t=(0,J._S)(p,n.resolution,e);if(t.blocked){let e=eN.toUpperCase();R.oR.info(eo.has("audioRequired")?eo("audioRequired",{resolution:e}):(0,J.Gk)(I.hints.audioRequired,e,en));return}i({generateAudio:t.generateAudio})},eA=(0,Q.supportsVideoReferenceMode)(p,n.resolution),eS=(0,J.US)(p),eM=eo.has("allInOneLabel")?eo("allInOneLabel"):I.controls?.allInOneReference??er,e_=eo.has("multiImageLabel")?eo("multiImageLabel"):I.controls?.multiImageReference??er,eE=(0,J.ke)(p,n.resolution,er,eM,e_),eT={auto:eo("auto"),adaptive:eo("adaptive")},eL=eo.has("relaxedContent")?eo("relaxedContent"):(0,J.H5)(ei),eP=eo.has("relaxedContentHelp")?eo("relaxedContentHelp"):(0,J.Is)(ei),eD=()=>(0,a.jsxs)("div",{className:W.m2,"data-video-generator-floating-content":"true",children:[(0,a.jsx)(E.SX,{label:I.labels?.aspect||"Aspect Ratio",children:(0,a.jsx)(E.pq,{items:ev,selected:n.aspectRatio,onSelect:e=>i({aspectRatio:e}),renderItem:e=>(0,a.jsxs)(a.Fragment,{children:[(0,J.s3)(e,"h-5 w-5"),(0,a.jsx)("span",{className:"text-[10px] font-medium leading-none",children:(0,J.Qp)(e,ei,eT)})]})})}),(0,a.jsx)(E.SX,{label:I.labels?.length||"Duration",children:ey.length>12&&!p.supportsAutoDuration?(0,a.jsx)(B,{durations:ey,value:n.length,onChange:e=>i({length:e,durationAuto:!1}),className:"space-y-1"}):(0,a.jsx)(E.Nj,{className:"gap-0.5",itemClassName:"px-1 text-[12px]",options:ew.map(e=>({value:e,label:"auto"===e?eo("auto"):`${e}s`,endAdornment:(0,a.jsx)(N.y,{eligible:"auto"!==e&&eI(n.resolution,e),placement:"corner"})})),selected:ej,onSelect:e=>i((0,J.AT)(p,e))})}),(0,a.jsx)(E.SX,{label:I.labels?.resolution||"Resolution",children:(0,a.jsx)(E.Nj,{options:eF.map(e=>({value:e,label:e.toUpperCase(),endAdornment:(0,a.jsx)(N.y,{eligible:eI((0,Q.resolveVideoOutputId)(p,e,eR)??"")}),cornerBadge:eI((0,Q.resolveVideoOutputId)(p,e,eR)??"")?void 0:(0,K.me)(p.id,e)})),selected:eN,onSelect:e=>{let t=(0,Q.resolveVideoOutputId)(p,e,eR);t&&i({resolution:t})}})}),(0,J.wY)(p,eC)?(0,a.jsx)(E.SX,{label:el("quality"),children:(0,a.jsx)(E.Nj,{options:eC.map(e=>({value:e,label:el("low"===e?"qualityLow":"medium"===e?"qualityMedium":"qualityHigh"),endAdornment:(0,a.jsx)(N.y,{eligible:eI((0,Q.resolveVideoOutputId)(p,eN,e)??"")})})),selected:eR??eC[0],onSelect:e=>{let t=(0,Q.resolveVideoOutputId)(p,eN,e);t&&i({resolution:t})}})}
1):null,(0,a.jsx)(E.SX,{label:I.labels?.output||"Output Count",children:(0,a.jsx)(E.Nj,{options:[1,2,3,4].map(e=>({value:e,label:String(e),endAdornment:(0,a.jsx)(N.y,{eligible:1===e&&eI()})})),selected:n.outputCount,onSelect:e=>i({outputCount:e})})}),p.outputFormats?.length?(0,a.jsx)(E.SX,{label:eo.has("outputFormat")?eo("outputFormat"):"Format",children:(0,a.jsx)(E.Nj,{options:p.outputFormats.map(e=>({value:e,label:e.toUpperCase()})),selected:n.outputFormat,onSelect:e=>i({outputFormat:e})})}):null,p.supportsContentFilter?(0,a.jsx)("section",{className:"p-0.5",children:(0,a.jsx)(E.f1,{label:(0,a.jsx)(eU,{label:eL,help:eP}),checked:!n.contentFilter,onCheckedChange:e=>i({contentFilter:!e}),ariaLabel:eL})}):null]}),eO=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(!(0,J.jo)(p,n.resolution))return null;let t=eo("sound"),r=n.generateAudio?en:ea;return(0,a.jsxs)("label",{"aria-label":r,title:r,className:(0,F.cn)("flex select-none items-center gap-1.5 text-secondary-foreground/82","cursor-pointer",e.mobile?"w-full justify-between":"w-auto",T.DJ,ex),children:[(0,a.jsx)("span",{children:t}),(0,a.jsx)($.Switch,{checked:n.generateAudio,onCheckedChange:ek,"aria-label":r,className:"h-3.5 w-6 [&>span]:h-2.5 [&>span]:w-2.5 [&>span]:data-[state=checked]:translate-x-2.5"})]})},e$=()=>(0,a.jsx)("div",{className:"flex items-center gap-1.5 sm:gap-2",children:(0,a.jsx)("div",{className:"shrink-0",children:(0,a.jsx)(M.M,{onClick:d,label:I.actions.generate,loadingLabel:I.actions.generating,isLoading:u,softDisabled:!q,size:"compact",cornerBadgeLabel:_({currentCredits:j,originalCredits:P}),children:(0,a.jsx)(H,{cost:j,originalCost:P,mode:"inline"})})})}),eW=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return(0,a.jsx)(V.o,{embedded:e.embedded,primary:(0,a.jsx)(a.Fragment,{children:(0,a.jsx)(ee,{unlimitedPlan:r,selectedModelId:n.modelId,models:g,onModelSelect:e=>i({modelId:e}),modelDescriptions:I.modelDescriptions,className:"w-auto",triggerClassName:(0,F.cn)("md:w-auto max-w-[184px] text-secondary-foreground/88",eb),panelAlign:"start",panelContainerClassName:"w-[min(90vw,584px)]"})}),secondary:(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(L.s,{open:ed,onOpenChange:eu,panelAlign:"start",panelContainerClassName:"w-[min(calc(100vw-2rem),392px)]",panelSurfaceClassName:W.Zn,trigger:(0,a.jsxs)("button",{type:"button",onClick:()=>eu(e=>!e),className:(0,F.cn)("group",eb),children:[(0,a.jsxs)("span",{className:"flex items-center gap-0.5",children:[(0,J.s3)(n.aspectRatio,"h-3 w-3 opacity-75"),(0,a.jsx)("span",{className:"font-medium",children:(0,J.Qp)(n.aspectRatio,ei,eT)})]}
1),(0,a.jsx)("span",{className:"mx-0.5 h-4 w-px bg-foreground/10"}),(0,a.jsxs)("span",{className:"flex items-center gap-0.5 text-foreground/88",children:[(0,a.jsx)(k.A,{className:"h-3 w-3 opacity-75"}),(0,a.jsx)("span",{className:"font-medium",children:(0,J.t4)(n.length,n.durationAuto,eo("auto"))})]}),(0,a.jsx)("span",{className:"mx-0.5 h-4 w-px bg-foreground/10"}),(0,a.jsx)("span",{className:"font-medium text-foreground/90",children:eN.toUpperCase()}),(0,a.jsx)("span",{className:"mx-0.5 h-4 w-px bg-foreground/10"}),(0,a.jsxs)("span",{className:"flex items-center gap-0.5 text-foreground/88",children:[(0,a.jsx)(A.A,{className:"h-3 w-3 opacity-75"}),(0,a.jsx)("span",{className:"font-medium",children:n.outputCount})]}),(0,a.jsx)(S.A,{className:(0,F.cn)("ml-0.5 h-3.5 w-3.5 opacity-60 transition-transform duration-200",ed&&"rotate-180")})]}),children:eD()}),X?(0,a.jsx)(L.s,{open:ec,onOpenChange:em,panelAlign:"start",panelContainerClassName:"w-[180px]",panelSurfaceClassName:"p-2",trigger:(0,a.jsxs)("button",{type:"button",onClick:()=>em(e=>!e),className:(0,F.cn)("w-auto shrink-0",eb),children:[(0,a.jsx)("span",{className:"font-medium",children:"reference"===n.inputMode?eE:"startEndFrame"===n.inputMode||n.addEndFrame?Z:Y}),(0,a.jsx)(S.A,{className:(0,F.cn)("h-3.5 w-3.5 shrink-0 opacity-50 transition-transform duration-200",ec&&"rotate-180")})]}),children:(0,a.jsxs)("div",{"data-video-generator-floating-content":"true",children:[(0,a.jsx)("button",{type:"button",onClick:()=>{i({inputMode:"singleFrame",addEndFrame:!1,endFrameImage:null,originalEndFrameImage:null}),em(!1)},className:(0,F.cn)("flex w-full cursor-pointer select-none items-center rounded-[13px] border border-transparent px-2 py-1.5 text-left text-sm outline-none transition-all duration-200","singleFrame"===n.inputMode?W.B5:W.ik),children:(0,a.jsx)("span",{className:"font-medium text-foreground",children:Y})}),eS?(0,a.jsx)("button",{type:"button",onClick:()=>{i({inputMode:"startEndFrame",addEndFrame:!0}),em(!1)},className:(0,F.cn)("mt-1 flex w-full cursor-pointer select-none items-center rounded-[13px] border border-transparent px-2 py-1.5 text-left text-sm outline-none transition-all duration-200","startEndFrame"===n.inputMode?W.B5:W.ik),children:(0,a.jsx)("span",{className:"font-medium text-foreground",children:Z})}):null,eA?(0,a.jsx)("button",{type:"button",onClick:()=>{i({inputMode:"reference"}),em(!1)},className:(0,F.cn)("mt-1 flex w-full cursor-pointer select-none items-center rounded-[13px] border border-transparent px-2 py-1.5 text-left text-sm outline-none transition-all duration-200","reference"===n.inputMode?W.B5:W.ik),children:(0,a.jsx)("span",{className:"font-medium text-foreground",children:eE})}):null]})}):null,eO(),p.supportsWebSearch&&"textToVideo"===D?(0,a.jsxs)("label",{className:(0,F.cn)("flex cursor-pointer select-none items-center gap-1.5 text-secondary-foreground/82",T.DJ,eb),children:[(0,a.jsx)("span",{children:es("webSearch")}),(0,a.jsx)($.Switch,{checked:n.webSearch,onCheckedChange:e=>i({webSearch:e}),"aria-label":es("webSearch"),className:"h-4 w-7 [&>span]:h-3 [&>span]:w-3 [&>span]:data-[state=checked]:translate-x-3"})]}):null,t&&(0,a.jsx)(C.S,{presentation:"single",value:"unlimited"===n.billingMode&&1===n.outputCount?"unlimited":"credits",onChange:e=>i({billingMode:e,..."unlimited"===e?{outputCount:1}:{}}),disabled:u})]}),right:e$()})}({embedded:!0}),eq=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return(0,a.jsx)(U,{embedded:e.embedded,primary:(0,a.jsx)(a.Fragment,{children:(0,a.jsx)(ee,{unlimitedPlan:r,selectedModelId:n.modelId,models:g,onModelSelect:e=>i({modelId:e}),modelDescriptions:I.modelDescriptions,className:"w-full",triggerClassName:(0,F.cn)("w-full text-secondary-foreground/88",eb),panelAlign:"stretch",panelContainerClassName:"w-full"})}),secondary:(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(L.s,{open:eg,onOpenChange:ep,className:"w-full",panelAlign:"stretch",panelSurfaceClassName:"p-2.5",trigger:(0,a.jsxs)("button",{type:"button",onClick:()=>ep(e=>!e),className:(0,F.cn)("group flex h-8 w-full items-center rounded-lg border px-1.5 text-[12px] text-secondary-foreground
1/88 transition-all duration-200 backdrop-blur-xl sm:px-2",eb),children:[(0,a.jsxs)("span",{className:"flex items-center gap-0.5",children:[(0,J.s3)(n.aspectRatio,"h-3 w-3 opacity-75"),(0,a.jsx)("span",{className:"font-medium",children:(0,J.Qp)(n.aspectRatio,ei,eT)})]}),(0,a.jsx)("span",{className:"mx-0.5 h-4 w-px bg-foreground/10"}),(0,a.jsxs)("span",{className:"flex items-center gap-0.5 text-foreground/88",children:[(0,a.jsx)(k.A,{className:"h-3 w-3 opacity-75"}),(0,a.jsx)("span",{className:"font-medium",children:(0,J.t4)(n.length,n.durationAuto,eo("auto"))})]}),(0,a.jsx)("span",{className:"mx-0.5 h-4 w-px bg-foreground/10"}),(0,a.jsx)("span",{className:"font-medium text-foreground/90",children:eN.toUpperCase()}),(0,a.jsx)("span",{className:"mx-0.5 h-4 w-px bg-foreground/10"}),(0,a.jsxs)("span",{className:"flex items-center gap-0.5 text-foreground/88",children:[(0,a.jsx)(A.A,{className:"h-3 w-3 opacity-75"}),(0,a.jsx)("span",{className:"font-medium",children:n.outputCount})]}),(0,a.jsx)(S.A,{className:(0,F.cn)("ml-0.5 h-3.5 w-3.5 opacity-60 transition-transform duration-200",eg&&"rotate-180")})]}),children:eD()}),eO({mobile:!0}),X?(0,a.jsx)(L.s,{open:ef,onOpenChange:eh,className:"w-full",panelAlign:"stretch",panelSurfaceClassName:"p-2.5",trigger:(0,a.jsxs)("button",{type:"button",onClick:()=>eh(e=>!e),className:(0,F.cn)("flex h-8 w-full items-center justify-between rounded-lg border px-2.5 text-sm font-medium transition-all duration-200 backdrop-blur-xl",`${ex} text-secondary-foreground/85`),children:[(0,a.jsx)("span",{children:I.labels?.advanced||"Advanced"}),(0,a.jsx)(S.A,{className:(0,F.cn)("h-4 w-4 opacity-60 transition-transform duration-200",ef&&"rotate-180")})]}),children:(0,a.jsx)("div",{className:"space-y-2",children:X?(0,a.jsxs)("div",{className:W.d2,children:[(0,a.jsx)("button",{type:"button",onClick:()=>i({inputMode:"singleFrame",addEndFrame:!1,endFrameImage:null,originalEndFrameImage:null}),className:(0,F.cn)("flex h-8 flex-1 items-center justify-center gap-1.5 rounded-[14px] px-3 text-sm font-medium transition-all duration-200","singleFrame"===n.inputMode?W.ws:W.xu),children:Y}),eS?(0,a.jsx)("button",{type:"button",onClick:()=>i({inputMode:"startEndFrame",addEndFrame:!0}),className:(0,F.cn)("flex h-8 flex-1 items-center justify-center gap-1.5 rounded-[14px] px-3 text-sm font-medium transition-all duration-200","startEndFrame"===n.inputMode?W.ws:W.xu),children:Z}):null,eA?(0,a.jsx)("button",{type:"button",onClick:()=>i({inputMode:"reference"}),className:(0,F.cn)("flex h-8 flex-1 items-center justify-center gap-1.5 rounded-[14px] px-3 text-sm font-medium transition-all duration-200","reference"===n.inputMode?W.ws:W.xu),children:eE}):null]}):null})}):null]}),right:e$()})}({embedded:!0});return f?(0,a.jsxs)("div",{className:"mx-auto w-full",children:[(0,a.jsx)(O,{sticky:x,prompt:(0,a.jsx)(eV,{activeMediaMode:y,onMediaModeChange:w,label:I.labels.prompt,labels:I.labels,value:n.prompt,onPromptChange:e=>i({prompt:e}),placeholder:"imageToVideo"===D?I.placeholders.promptImage:I.placeholders.promptText,examples:I.examples||[],imageExamples:I.imageExamples,actions:I.actions,controls:I.controls,hints:I.hints,state:n,modelConfig:p,onStateChange:i,onImageFileSelected:l,onImageClick:s,isStartFrameLoading:m,enhancePrompt:n.enhancePrompt,onEnhancePromptChange:e=>i({enhancePrompt:e}),enhancePromptLabel:I.actions.enhancePrompt||"AI Enhance",embedded:!0,stickyExpanded:x,hideInlineControls:!0,embeddedFooter:eW,sharedLayoutVariant:x?"sticky-expanded":"embedded"}),mobileRail:eq}),c&&z&&I.hints.endFrameRequired?(0,a.jsx)("p",{className:"mt-2 animate-in slide-in-from-top-1 fade-in text-center text-xs text-destructive",children:I.hints.endFrameRequired}):null]}):(0,a.jsx)("div",{className:"mx-auto w-full px-0 pb-16",children:(0,a.jsx)("div",{className:"space-y-8 rounded-xl border border-border/40 bg-card/40 px-4 py-8 sm:px-8",children:(0,a.jsxs)("div",{className:"w-full space-y-6",children:[(0,a.jsx)(eV,{activeMediaMode:y,onMediaModeChange:w,label:I.labels.prompt,labels:I.labels,value:n.prompt,onPromptChange:e=>i({prompt:e}),placeholder:"imageToVideo"===D?I.placeholders.promptImage:I.placeholders.promptText,examples:I.examples||[],imageExamples:I.imageExamples,actions:I.actions,controls:I.controls,hints:I.hints,state:n,modelConfig:p,onStateChange:i,onImageFileSelected:l,onImageClick:s,isStartFrameLoading:m,enhancePrompt:n.enhancePrompt,onEnhancePromptChange:e=>i({enhancePrompt:e}),enhancePromptLabel:I.actions.enhancePrompt||"AI Enhance"}),(0,a.jsx)(et,{modelId:n.modelId,onModelChange:e=>i({modelId:e}),onGenerate:d,isGenerating:u,isLoggedIn:c,credits:j,originalCredits:P,isReady:q,models:g,onClear:G,isEndFrameMissing:z,endFrameWarning:I.hints.endFrameRequired,generateLabel:I.actions.generate,generatingLabel:I.actions.generating,clearLabel:I.actions.clear,modelDescriptions:I.modelDescriptions,supportsAudio:(0,J.jo)(p,n.resolution),generateAudio:n.generateAudio,onGenerateAudioChange:ek,audioLabel:n.generateAudio?en:ea})]})})})}var e$=r(78027),eW=r(55601),eq=r(49405),eH=r(98633),eB=r(36428),ez=r(2325);function eG(e){let{label:t,placeholder:r,value:n,onPromptChange:i,showEnhancePrompt:o=!0,enhancePrompt:l,onEnhancePromptChange:s,enhancePromptLabel:d="AI Enhance",maxLength:u=2e3}=e,c=(0,h.useId)();return(0,a.jsx)(eW.kL,{label:t,inputId:c,value:n,onChange:i,placeholder:r,maxLength:u,textareaClassName:"min-h-[88px] border-0 px-0 py-0 shadow-none focus-visible:ring-0 focus-visible:ring-offset-0",footerRight:o?(0,a.jsx)(ez.f,{checked:l,onCheckedChange:s,label:d,size:"mobile"}):null,textareaProps:{name:"videoPrompt"}})}function eX(e){let{unlimitedPlan:t="free",models:r,selectedModelId:n,onModelSelect:i,panelLabel:l,modelDescriptions:s}=e,d=(0,v.c)("imageGenerator"),u=(0,K.jN)(r).map(e=>{let r=e.models[0],n=e.models.some(e=>(0,o.t9)(t,e.id));return{id:e.id,label:(0,a.jsxs)("span",{className:"inline-flex items-center gap-1.5",children:[r?.providerLabel??e.id,(0,a.jsx)(N.y,{eligible:n})]}),description:r?.providerDescription,commercial:(0,K.GG)(e.id),badges:!n&&(0,K.n8)(e.id)?[{label:(0,K.n8)(e.id),tone:"deal"}]:[],items:e.models.map(e=>{let r=(0,Q.getModelMinimumVideoCreditDisplayOffer)(e);return{id:e.id,title:e.label,titleEndAdornment:"minimax-h3"===e.id||"minimax-h3-turbo"===e.id?(0,a.jsx)("span",{className:"inline-flex h-5 w-5 shrink-0 items-center justify-center",children:(0,a.jsx)(N.y,{eligible:(0,o.t9)(t,e.id)})}):void 0,description:s?.[e.id]??e.label,media:(0,a.jsx)(w.default,{src:e.logoSrc,alt:e.label,width:20,height:20,className:"h-5 w-5 object-contain"}),badges:(0,K.MT)(e.id).filter(r=>!(0,o.t9)(t,e.id)||"deal"!==r.tone),commercial:(0,K.Cw)(e.id),metas:[{icon:(0,a.jsx)(z.A,{className:"h-3 w-3"}),label:(0,a.jsxs)("span",{className:"inline-flex items-center gap-1",children:[null!==r.originalCredits?(0,a.jsx)("span",{className:"text-muted-foreground
1/55 line-through",children:r.originalCredits}):null,(0,a.jsxs)("span",{children:[r.credits,"+"," ",d("selectors.credits")]})]})},{icon:(0,a.jsx)(G.A,{className:"h-3 w-3"}),label:(0,J.u8)(e)},{icon:(0,a.jsx)(A.A,{className:"h-3 w-3"}),label:(0,J.mZ)(e)}]}})}});return(0,a.jsx)(eW.Xm,{value:n,groups:u,onValueChange:i,panelLabel:l})}function eY(e){let{image:t,index:r,label:n,onClick:i,onRemove:o}=e,l=ed(t);return(0,a.jsx)(eW.b9,{previewUrl:l,imageAlt:`${n} ${r+1}`,onClick:i,onRemove:o,buttonAriaLabel:n,removeAriaLabel:"Remove reference image",label:n,imageOverlayLabel:`${r+1}`,className:"shrink-0"})}function eQ(e){let{video:t,index:r,label:n,onClick:i,onRemove:o}=e,l=ed(t),s=t instanceof File?t.name:n;return(0,a.jsxs)("div",{className:"relative h-[72px] w-[72px] shrink-0",children:[(0,a.jsxs)("button",{type:"button",onClick:i,"aria-label":`${n} ${r+1}`,className:(0,F.cn)("relative flex h-full w-full items-center justify-center overflow-hidden border border-white/10 bg-black/12 transition-all duration-200",em.OL),children:[l?(0,a.jsx)("video",{src:l,muted:!0,playsInline:!0,preload:"metadata",className:"h-full w-full object-cover"}):null,(0,a.jsx)("div",{className:"absolute inset-0 bg-gradient-to-t from-black/75 via-black/10 to-transparent"}),(0,a.jsxs)("div",{className:"absolute inset-x-0 bottom-0 px-1.5 pb-1.5 text-center",children:[(0,a.jsx)(A.A,{className:"mx-auto mb-0.5 h-3.5 w-3.5 text-white/82"}),(0,a.jsx)("div",{className:"truncate text-[8px] font-medium text-white/88",children:s})]})]}),(0,a.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),o()},"aria-label":"Remove reference video",className:"absolute -right-1.5 -top-1.5 z-20 flex h-6 w-6 items-center justify-center rounded-full border border-primary/35 bg-[rgba(24,18,15,0.9)] text-primary shadow-[0_12px_28px_-18px_rgba(0,0,0,0.95)]",children:(0,a.jsx)(eI.A,{className:"h-3.5 w-3.5"})})]})}function eJ(e){let{audio:t,index:r,label:n,onClick:i,onRemove:o}=e,l=t instanceof File?t.name:n;return(0,a.jsxs)("div",{className:"relative h-[72px] w-[72px] shrink-0",children:[(0,a.jsxs)("button",{type:"button",onClick:i,"aria-label":`${n} ${r+1}`,className:(0,F.cn)("relative flex h-full w-full flex-col items-center justify-center gap-1 overflow-hidden border border-white/10 bg-white/[0.04] px-2 text-center transition-all duration-200",em.OL),children:[(0,a.jsx)(ey.A,{className:"h-5 w-5 text-primary/84"}),(0,a.jsx)("div",{className:"line-clamp-2 text-[8px] font-medium leading-tight text-white/78",children:l})]}),(0,a.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),o()},"aria-label":"Remove reference audio",className:"absolute -right-1.5 -top-1.5 z-20 flex h-6 w-6 items-center justify-center rounded-full border border-primary/35 bg-[rgba(24,18,15,0.9)] text-primary shadow-[0_12px_28px_-18px_rgba(0,0,0,0.95)]",children:(0,a.jsx)(eI.A,{className:"h-3.5 w-3.5"})})]})}function eK(e){let t,r,n,{unlimitedAvailable:i,unlimitedPlan:l="free",state:s,onChange:d,onImageFileSelected:u,onImageClick:c,onGenerate:m,isGenerating:g,isLoggedIn:f,isStartFrameLoading:x=!1,models:y,activeModel:w,embedded:I=!1,stickyExpanded:j=!1,activeMediaMode:k,onMediaModeChange:A,hideModeSwitcherOnMobile:S=!1,generator:E,credits:T,originalCredits:L,resolvedMode:V,isReadyToGenerate:P,isEndFrameMissing:D,showFrameToggle:U,singleFrameLabel:O,startEndLabel:$,audioOnLabel:q,audioOffLabel:z,embeddedMobileHeader:G}=e,X=(0,b.Ym)(),Y=(0,v.c)("videoGenerator.reference"),Z=(0,v.c)("videoGenerator.actions"),ee=(0,v.c)("uploadErrors"),et=(0,v.c)("imageGenerator.controls"),er=(0,v.c)("imageGenerator.switches");(0,v.c)("imageGenerator");let en=Y.has("relaxedContent")?Y("relaxedContent"):(0,J.H5)(X),ea=Y.has("relaxedContentHelp")?Y("relaxedContentHelp"):(0,J.Is)(X),ei=(0,h.useId)(),el=(0,h.useRef)(null),es=(0,h.useRef)(null),[eu,ec]=(0,h.useState)(null),em=ed(s.startFrameImage),ep=ed(s.endFrameImage),ef=(w.maxImageCount??1)>0,eh=(0,J.US)(w),ex=(0,Q.supportsVideoReferenceMode)(w,s.resolution),eb="veo"===w.provider||w.id.startsWith("veo-3.1-"),ey=Y.has("allInOneLabel")?Y("allInOneLabel"):E.controls?.allInOneReference??E.controls?.reference??Y("label"),ew=Y.has("multiImageLabel")?Y("multiImageLabel"):E.controls?.multiImageReference??E.controls?.reference??Y("label"),eI=(0,J.ke)(w,s.resolution,E.controls?.reference||Y("label"),ey,ew),ej=(0,J.JX)(w),{imageCount:eF,videoCount:eN,audioCount:eC,totalCount:eR,imageFormats:ek,videoFormats:eS,audioFormats:eM,videoMinSeconds:e_,videoMaxSeconds:eE,videoTotalSeconds:eL,audioMinSeconds:eV,audioMaxSeconds:eP,audioTotalSeconds:eD}=ej,eO=(0,J.if)(ej,{imagesDetailed:Y.has("helperImagesDetailed")?String(Y.raw("helperImagesDetailed")):E.hints.referenceHelperImagesDetailed,multiDetailed:Y.has("helperMultiDetailed")?String(Y.raw("helperMultiDetailed")):E.hints.referenceHelperMultiDetailed,multiDetailedWithTotal:Y.has("helperMultiDetailedWithTotal")?String(Y.raw("helperMultiDetailedWithTotal")):E.hints.referenceHelperMultiDetailedWithTotal,imagesFallback:Y("helperImages",{imageCount:eF}),multiFallback:Y("helperMulti",{imageCount:eF,videoCount:eN,audioCount:eC})}),ez=eN>0||eC>0?(0,a.jsxs)("span",{className:"flex flex-col items-center gap-0.5",children:[(0,a.jsx)("span",{children:Y("helperImageCompact",{imageCount:eF})}),eC>0?(0,a.jsx)("span",{children:Y("helperAudioSeconds",{seconds:eD})}):null,eN>0?(0,a.jsx)("span",{children:Y("helperVideoSeconds",{seconds:eL})}):null]}):Y("helperImages",{imageCount:eF}),eK=eT.JK,eZ=[...eK,...eN>0?["video/mp4","video/quicktime"]:[],...eC>0?["audio/mpeg","audio/wav","audio/x-wav"]:[]].join(","),e0=eK.join(","),e1=eh&&("startEndFrame"===s.inputMode||s.addEndFrame),e2=E.labels.start||Y("start"),e5=E.labels.end||Y("end"),e3=Y("loading"),e4=(0,J.P3)(w,V,s.resolution),e8=(0,J._g)(w,s.resolution,V),e6=(0,J.Yo)(w,s.resolution,V),e9=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:s.resolution,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:s.length;return(0,o.$2)(l,{kind:"video",modelId:s.modelId,resolution:e,durationSeconds:t,outputCount:1})},e7=s.durationAuto?"auto":s.length,te=(0,Q.getVideoPhysicalResolutions)(w),tt=(0,Q.getVideoOutputResolution)(w,s.resolution),tr=(0,Q.getVideoQualityOptions)(w,tt),tn=(0,Q.getVideoOutputQuality)(w,s.resolution),ta={auto:Y("auto"),adaptive:Y("adaptive")},ti=(0,h.useMemo)(()=>[...s.referenceImages.map(e=>({kind:"image",source:e})),...s.referenceVideos.map(e=>({kind:"video",source:e})),...s.referenceAudios.map(e=>({kind:"audio",source:e}))],[s.referenceAudios,s.referenceImages,s.referenceVideos]);(0,h.useEffect)(()=>{null===eu||eu<ti.length||ec(ti.length>0?ti.length-1:null)},[eu,ti.length]);let to=async e=>{let t,r=e.currentTarget,n=Array.from(r.files??[]);if(r.value="",0===n.length)return;let a=n.some(e=>e.type.startsWith("video/")&&e.size>0x1400000)?R.oR.loading(Y("checkingVideo")):void 0;try{t=await (0,p.wI)({files:n,resolution:s.resolution,existingImages:s.referenceImages,existingVideos:s.referenceVideos,existingAudios:s.referenceAudios,imageLimit:eF,videoLimit:eN,audioLimit:eC,totalLimit:w.maxReferenceTotalCount,imageMaxBytes:eb?p.Lx:void 0,modelId:w.id})}catch{R.oR.error((0,eg.A)({code:"upload_failed",mediaType:"media"},X,ee));return}finally{void 0!==a&&R.oR.dismiss(a)}
1t.errors.forEach(e=>{R.oR.error((0,eg.A)(e,X,ee))}),(t.images.length>0||t.videos.length>0||t.audios.length>0)&&d({referenceImages:[...s.referenceImages,...t.images],referenceVideos:[...s.referenceVideos,...t.videos],referenceAudios:[...s.referenceAudios,...t.audios]})},tl=e=>{let{target:t,image:r,previewUrl:n}=e,i=ev({locale:X,target:t,addEndFrame:s.addEndFrame,startLabel:e2,endLabel:e5,labels:{reference:Y("label"),optional:Y("optional"),frame:Y("frame"),select:e=>Y("selectLabel",{label:e}),remove:e=>Y("removeLabel",{label:e})}}),o="start"===t&&!s.addEndFrame&&!n;return(0,a.jsx)(eW.b9,{previewUrl:n,imageAlt:i.previewLabel,onClick:()=>((e,t)=>{let r;t&&c?c(e):(r=el.current)&&(r.setAttribute("data-target",e),r.click())})(t,r),onRemove:r?()=>d("start"===t?{startFrameImage:null,originalStartFrameImage:null}:{endFrameImage:null,originalEndFrameImage:null}):void 0,buttonAriaLabel:i.buttonAriaLabel,removeAriaLabel:i.removeAriaLabel,loading:"start"===t&&x,loadingLabel:e3,label:o?i.tileHelper:i.emptyLabel,helper:o||n?void 0:i.tileHelper,imageOverlayLabel:i.overlayLabel,className:"shrink-0"})},ts=e=>{let{value:t,options:r,onSelect:n,renderLabel:i,renderEndAdornment:o,renderCornerBadge:l,className:s}=e,d=1===r.length?"grid-cols-1":2===r.length?"grid-cols-2":3===r.length?"grid-cols-3":"grid-cols-4";return(0,a.jsx)("div",{className:(0,F.cn)("grid gap-1.5",s??d),children:r.map(e=>{let r=e===t;return(0,a.jsxs)(eW.RO,{onClick:()=>n(e),selected:r,className:(0,F.cn)("relative flex h-9 items-center justify-center overflow-visible rounded-[10px] border px-3 text-sm font-medium transition-all duration-200"),children:[l?.(e)?(0,a.jsx)("span",{className:(0,F.cn)("pointer-events-none absolute -right-1 -top-2 z-20 inline-flex h-4 min-w-[2.8rem] items-center justify-center whitespace-nowrap px-1.5 text-[9px] font-black leading-none",W.Sc),children:l(e)}):null,(0,a.jsx)(e$.i,{endAdornment:o?.(e),children:i?i(e):String(e)})]},String(e))})})},td=k&&A&&!S?(0,a.jsx)(eW.Ah,{activeMode:k,onModeChange:A}):null,tu=(0,a.jsxs)("div",{className:"space-y-2.5",children:[ef||ex?(0,a.jsx)(eW.LU,{label:E.labels.referenceImage||Y("label"),children:"reference"===s.inputMode&&ex?(t=s.referenceImages.length+s.referenceVideos.length+s.referenceAudios.length<(w.maxReferenceTotalCount??1/0)&&(s.referenceImages.length<eF||s.referenceVideos.length<eN||s.referenceAudios.length<eC),r=s.referenceImages.length,n=s.referenceImages.length+s.referenceVideos.length,(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("input",{ref:es,type:"file",name:"videoReferenceMediaUpload",accept:eZ,onChange:to,className:"hidden",multiple:!0}),(0,a.jsxs)("div",{className:"flex items-center gap-2.5 overflow-x-auto pb-1",children:[s.referenceImages.map((e,t)=>(0,a.jsx)(eY,{image:e,index:t,label:eI,onClick:()=>ec(t),onRemove:()=>d({referenceImages:s.referenceImages.filter((e,r)=>r!==t)})},`reference-image-${t}`)),s.referenceVideos.map((e,t)=>(0,a.jsx)(eQ,{video:e,index:t,label:eI,onClick:()=>ec(r+t),onRemove:()=>d({referenceVideos:s.referenceVideos.filter((e,r)=>r!==t)})},`reference-video-${t}`)),s.referenceAudios.map((e,t)=>(0,a.jsx)(eJ,{audio:e,index:t,label:eI,onClick:()=>ec(n+t),onRemove:()=>d({referenceAudios:s.referenceAudios.filter((e,r)=>r!==t)})},`reference-audio-${t}`)),t?(0,a.jsx)(eW.b9,{previewUrl:null,onClick:()=>{es.current?.click()},buttonAriaLabel:eI,label:eN>0||eC>0?null:eI,helper:ez,className:"shrink-0"}):null]}),(0,a.jsx)(eA,{items:ti,previewIndex:eu,title:Y("preview"),previousLabel:Y("previous"),nextLabel:Y("next"),onPreviewIndexChange:ec})]})):ef?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("input",{id:ei,ref:el,type:"file",name:"videoReferenceUpload",accept:e0,"aria-label":Y("selectLabel",{label:E.labels.referenceImage||Y("label")}),onChange:e=>{let t=e.currentTarget.files?.[0];t&&(u("end"===e.currentTarget.dataset.target?"end":"start",t),e.currentTarget.value="")},className:"hidden"}),(0,a.jsxs)("div",{className:"flex items-center gap-2.5 overflow-x-auto pb-1",children:[tl({target:"start",image:s.startFrameImage,previewUrl:em}),e1?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("div",{className:"flex h-full w-4 shrink-0 items-center justify-center text-muted-foreground
1/24",children:(0,a.jsx)(eo.A,{className:"h-3 w-3"})}),tl({target:"end",image:s.endFrameImage,previewUrl:ep})]}):null]})]}):null}):null,(0,a.jsx)(eG,{showEnhancePrompt:!0,label:E.labels.prompt||"Prompt",placeholder:(0,J.rj)(V,{text:E.placeholders.promptText,image:E.placeholders.promptImage,reference:eO}),value:s.prompt,onPromptChange:e=>d({prompt:e}),maxLength:(0,Q.getVideoPromptMaxLength)(w),enhancePrompt:s.enhancePrompt,onEnhancePromptChange:e=>d({enhancePrompt:e}),enhancePromptLabel:Z("enhancePrompt")}),(0,a.jsx)(eW.om,{label:E.labels.model||"Model",children:(0,a.jsx)(eX,{unlimitedPlan:l,models:y,selectedModelId:s.modelId,onModelSelect:e=>d({modelId:e}),panelLabel:E.labels.model||"Model",modelDescriptions:E.modelDescriptions})}),(0,a.jsx)(eW.LU,{label:E.labels.aspect||"Aspect Ratio",children:(0,a.jsx)("div",{className:(0,F.cn)("grid gap-1.5",e4.length<=1?"grid-cols-1":"grid-cols-5"),children:e4.map(e=>{let[t,r]=e.split(":").map(Number),n=t&&r?t/r:1,i=s.aspectRatio===e;return(0,a.jsxs)(eW.RO,{onClick:()=>d({aspectRatio:e}),selected:i,className:(0,F.cn)("flex h-11 flex-col items-center justify-center gap-0.5 rounded-[10px] border px-1 transition-all duration-200"),children:[(0,a.jsx)("div",{className:(0,F.cn)("rounded-sm border-2 transition-all duration-200",i?"border-foreground":"border-foreground
1/35"),style:{width:n>=1?18:18*n,height:n>=1?18/n:18}}),(0,a.jsx)("span",{className:"text-[10px]",children:(0,J.Qp)(e,X,ta)})]},e)})})}),(0,a.jsx)(eW.LU,{label:E.labels.length||"Duration",children:e8.length>12&&!w.supportsAutoDuration?(0,a.jsx)(B,{durations:e8,value:s.length,onChange:e=>d({length:e,durationAuto:!1})}):ts({value:e7,options:e6,onSelect:e=>d((0,J.AT)(w,e)),renderEndAdornment:e=>(0,a.jsx)(N.y,{eligible:"auto"!==e&&e9(s.resolution,e),placement:"corner"}),renderLabel:e=>"auto"===e?Y("auto"):`${e}s`})}),(0,a.jsx)(eW.LU,{label:E.labels.resolution||"Resolution",children:ts({value:tt,options:te,onSelect:e=>{let t=(0,Q.resolveVideoOutputId)(w,e,tn);t&&d({resolution:t})},renderLabel:e=>e.toUpperCase(),renderEndAdornment:e=>(0,a.jsx)(N.y,{eligible:e9((0,Q.resolveVideoOutputId)(w,e,tn)??"")}),renderCornerBadge:e=>e9((0,Q.resolveVideoOutputId)(w,e,tn)??"")?void 0:(0,K.me)(w.id,e)})}),(0,J.wY)(w,tr)?(0,a.jsx)(eW.LU,{label:et("quality"),children:ts({value:tn??tr[0],options:tr,onSelect:e=>{let t=(0,Q.resolveVideoOutputId)(w,tt,e);t&&d({resolution:t})},renderLabel:e=>et("low"===e?"qualityLow":"medium"===e?"qualityMedium":"qualityHigh"),renderEndAdornment:e=>(0,a.jsx)(N.y,{eligible:e9((0,Q.resolveVideoOutputId)(w,tt,e)??"")})})}
1):null,(0,a.jsx)(eW.LU,{label:E.labels.output||"Output Count",children:ts({value:s.outputCount,options:[1,2,3,4],onSelect:e=>d({outputCount:e}),renderEndAdornment:e=>(0,a.jsx)(N.y,{eligible:1===e&&e9()})})}),w.outputFormats?.length?(0,a.jsx)(eW.LU,{label:Y.has("outputFormat")?Y("outputFormat"):"Format",children:ts({value:s.outputFormat,options:[...w.outputFormats],onSelect:e=>d({outputFormat:e}),renderLabel:e=>e.toUpperCase()})}):null,U?(0,a.jsx)(eW.LU,{label:Y("frameMode"),children:(0,a.jsxs)("div",{className:(0,F.cn)("grid gap-1.5",eh&&ex?"grid-cols-3":eh||ex?"grid-cols-2":"grid-cols-1"),children:[(0,a.jsx)(eW.RO,{type:"button",selected:"singleFrame"===s.inputMode,onClick:()=>d({inputMode:"singleFrame",addEndFrame:!1,endFrameImage:null,originalEndFrameImage:null}),className:(0,F.cn)("flex h-9 items-center justify-center rounded-[10px] border px-3 text-sm font-medium transition-all duration-200"),children:O}),eh?(0,a.jsx)(eW.RO,{type:"button",selected:"startEndFrame"===s.inputMode,onClick:()=>d({inputMode:"startEndFrame",addEndFrame:!0}),className:(0,F.cn)("flex h-9 items-center justify-center rounded-[10px] border px-3 text-sm font-medium transition-all duration-200"),children:$}):null,ex?(0,a.jsx)(eW.RO,{type:"button",selected:"reference"===s.inputMode,onClick:()=>d({inputMode:"reference"}),className:(0,F.cn)("flex h-9 items-center justify-center rounded-[10px] border px-3 text-sm font-medium transition-all duration-200"),children:eI}):null]})}):null,(0,J.jo)(w,s.resolution)?(0,a.jsx)(eW.WY,{icon:eq.A,label:s.generateAudio?q:z,checked:s.generateAudio,onCheckedChange:e=>{let t=(0,J._S)(w,s.resolution,e);if(t.blocked){let e=tt.toUpperCase();R.oR.info(Y.has("audioRequired")?Y("audioRequired",{resolution:e}):(0,J.Gk)(E.hints.audioRequired,e,q));return}d({generateAudio:t.generateAudio})}}):null,w.supportsWebSearch&&"textToVideo"===V?(0,a.jsx)(eW.WY,{icon:eH.A,label:er("webSearch"),checked:s.webSearch,onCheckedChange:e=>d({webSearch:e})}):null,w.supportsContentFilter?(0,a.jsx)(eW.WY,{icon:eB.A,label:(0,a.jsx)(eU,{label:en,help:ea}),ariaLabel:en,checked:!s.contentFilter,onCheckedChange:e=>d({contentFilter:!e})}):null,i&&(0,a.jsx)(C.S,{presentation:"single",value:"unlimited"===s.billingMode&&1===s.outputCount?"unlimited":"credits",onChange:e=>d({billingMode:e,..."unlimited"===e?{outputCount:1}:{}}),disabled:g}),(0,a.jsx)(M.M,{size:"mobile",onClick:m,label:E.actions.generate,loadingLabel:E.actions.generating,isLoading:g,softDisabled:!P,cornerBadgeLabel:_({currentCredits:T,originalCredits:L}),children:(0,a.jsx)(H,{cost:T,originalCost:L,mode:"inline"})}),f&&D&&E.hints.endFrameRequired?(0,a.jsx)("p",{className:"animate-in slide-in-from-top-1 fade-in text-center text-xs text-destructive",children:E.hints.endFrameRequired}):null]});return I?(0,a.jsxs)("div",{className:"space-y-2.5",children:[td,(0,a.jsxs)(eW.e3,{embedded:!0,className:"rounded-xl border border-white/10 bg-[rgba(38,30,24,0.82)] p-3 shadow-[0_28px_72px_-42px_rgba(0,0,0,0.5)]",children:[G?(0,a.jsx)("div",{className:"mb-3 border-b border-white/6 pb-3",children:G}):null,tu]})]}):(0,a.jsxs)("div",{className:"space-y-2.5",children:[td,(0,a.jsx)(eW.e3,{children:tu})]})}function eZ(e){let{pageData:t,unlimitedPlan:r="free",state:n,onChange:i,onImageFileSelected:l,onImageClick:s,onGenerate:d,isGenerating:u,isLoggedIn:c,showEndFrameWarning:m=!1,isStartFrameLoading:g=!1,models:f,activeModel:h,embedded:x=!1,stickyExpanded:b=!1,activeMediaMode:v,onMediaModeChange:y,hideModeSwitcherOnMobile:w=!1,modeSwitcherPlacement:I="tabs",embeddedMobileHeader:N}=e,C=(0,j.U)("(max-width: 639px)"),R=t.generator;if(!R)return null;if(!h)return(0,a.jsx)("div",{className:(0,F.cn)("mx-auto w-full",x?"":"px-0 pb-16"),children:(0,a.jsx)("div",{className:(0,F.cn)("rounded-xl px-4 py-8 sm:px-8",x?"bg-secondary/50":"border border-border/40 bg-card/40"),children:(0,a.jsx)("div",{className:"flex h-40 items-center justify-center",children:(0,a.jsx)("div",{className:"text-muted-foreground",children:"Loading models..."})})})});let k=eh(n),A="referenceToVideo"===k&&n.referenceVideos.length>0,S=(0,p.dZ)(n.referenceVideos),M=(0,Q.getVideoCreditDisplayOffer)(h,n.resolution,n.length,n.generateAudio,{hasReferenceVideoInput:A,referenceVideoInputSeconds:S,referenceImageInputCount:"referenceToVideo"===k?n.referenceImages.length:0,inputImageCount:ex(n,k),relaxedContent:h.supportsContentFilter&&!1===n.contentFilter,webSearch:h.supportsWebSearch&&"textToVideo"===k&&n.webSearch}),_=(0,o.$2)(r,{kind:"video",modelId:n.modelId,resolution:n.resolution,durationSeconds:n.length,outputCount:1}),E=_&&1===n.outputCount&&"unlimited"===n.billingMode,T=E?0:(M?.credits??0)*n.outputCount,L=!E&&M?.originalCredits?M.originalCredits*n.outputCount:null,V=!!n.prompt.trim()&&("imageToVideo"!==k||!!n.startFrameImage)&&(!n.addEndFrame||!!n.endFrameImage)&&("referenceToVideo"!==k||(0,Q.supportsVideoReferenceMode)(h,n.resolution)&&ep({imageCount:n.referenceImages.length,videoCount:n.referenceVideos.length,audioCount:n.referenceAudios.length})&&(!h.referenceRequiresVisual||n.referenceImages.length>0||n.referenceVideos.length>0)),P=m&&"imageToVideo"===k&&n.addEndFrame&&!n.endFrameImage,D={unlimitedAvailable:_,unlimitedPlan:r,state:n,onChange:i,onImageFileSelected:l,onImageClick:s,onGenerate:d,isGenerating:u,isLoggedIn:c,showEndFrameWarning:m,isStartFrameLoading:g,models:f,activeModel:h,embedded:x,stickyExpanded:b,activeMediaMode:v,onMediaModeChange:y,hideModeSwitcherOnMobile:w,modeSwitcherPlacement:I,embeddedMobileHeader:N,generator:R,credits:T,originalCredits:L,resolvedMode:k,isReadyToGenerate:V,isEndFrameMissing:P,clearState:()=>{i({prompt:"",startFrameImage:null,endFrameImage:null,originalStartFrameImage:null,originalEndFrameImage:null,referenceImages:[],referenceVideos:[],referenceAudios:[]})},showFrameToggle:(h.maxImageCount??1)>1||!!h.supportsReferenceMode,singleFrameLabel:R.controls?.singleFrame??"First Frame",startEndLabel:R.controls?.startEnd??"Start & End",referenceLabel:R.controls?.reference??"Reference",audioOnLabel:R.controls?.audioOn??"Audio On",audioOffLabel:R.controls?.audioOff??"Audio Off"};return C?(0,a.jsx)(eK,{...D}):(0,a.jsx)(eO,{...D})}var e0=r(80188),e1=r(25247),e2=r(41166),e5=r(67864),e3=((n={}).None="none",n.TopLeft="topLeft",n.TopRight="topRight",n.BottomLeft="bottomLeft",n.BottomRight="bottomRight",n);let e4=(e,t,r)=>r.isVisible?8>=Math.abs(e-r.x)&&8>=Math.abs(t-r.y)?"topLeft":8>=Math.abs(e-(r.x+r.width))&&8>=Math.abs(t-r.y)?"topRight":8>=Math.abs(e-r.x)&&8>=Math.abs(t-(r.y+r.height))?"bottomLeft":8>=Math.abs(e-(r.x+r.width))&&8>=Math.abs(t-(r.y+r.height))?"bottomRight":"none":"none",e8=e=>{switch(e){case"topLeft":case"bottomRight":return"nwse-resize";case"topRight":case"bottomLeft":return"nesw-resize";default:return"default"}},e6="#A67042",e9=new WeakMap,e7=function(e,t){let r,n,a,i,o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1,l=arguments.length>3&&void 0!==arguments[3]?arguments[3]:e,s=arguments.length>4&&void 0!==arguments[4]?arguments[4]:t,d=Math.min(.05*l,.05*s);return o>(l-d)/(s-d)?(i=(a=l-2*d)/o,r=d,n=(s-i)/2):(a=(i=s-2*d)*o,n=d,r=(l-a)/2),{x:r,y:n,width:a,height:i}},te=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:e.canvasWidth/e.canvasHeight,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:e.canvasWidth,n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:e.canvasHeight,a=arguments.length>4?arguments[4]:void 0,{canvasWidth:i,canvasHeight:o}=e,l=a||e7(i,o,t,r,n),s=l.width/i,d=l.height/o,u=e.canvasImgWidth*s,c=e.canvasImgHeight*d,m=e.canvasImgPosX*s+l.x,g=e.canvasImgPosY*d+l.y;return{...e,canvasImgWidth:u,canvasImgHeight:c,canvasImgPosX:m,canvasImgPosY:g}},tt=function(e,t){let r=arguments.length>2&&void 0!==arguments[2]&&arguments[2],n=e.getContext("2d");
1n&&(r||n.clearRect(0,0,e.width,e.height),n.drawImage(t,0,0))},tr=(e,t)=>{let r=t.getBoundingClientRect();if("touches"in e){let t=e.touches[0]||e.changedTouches[0];return{x:t.clientX-r.left,y:t.clientY-r.top}}return{x:e.clientX-r.left,y:e.clientY-r.top}},tn=(e,t,r)=>r<t?r:Math.min(Math.max(e,t),r),ta=(e,t)=>e.x>=t.x&&e.x<=t.x+t.width&&e.y>=t.y&&e.y<=t.y+t.height,ti=e=>({x:e.imgPosX,y:e.imgPosY,width:e.imgWidth,height:e.imgHeight}),to=(e,t,r,n,a,i,o)=>{let l=((e,t)=>{switch(t){case e3.TopLeft:return{x:e.x+e.width,y:e.y+e.height};case e3.TopRight:return{x:e.x,y:e.y+e.height};case e3.BottomLeft:return{x:e.x+e.width,y:e.y};case e3.BottomRight:default:return{x:e.x,y:e.y}}})(e,r),{dx:s,dy:d}=((e,t,r)=>{switch(r){case e3.TopLeft:return{dx:t.x-e.x,dy:t.y-e.y};case e3.TopRight:return{dx:e.x-t.x,dy:t.y-e.y};case e3.BottomLeft:return{dx:t.x-e.x,dy:e.y-t.y};case e3.BottomRight:return{dx:e.x-t.x,dy:e.y-t.y};default:return{dx:0,dy:0}}})(t,l,r);if(s<=0||d<=0)return e;let u=tn(Math.min(s,d*a),i,Math.min(((e,t,r,n)=>{let a=t.x+t.width,i=t.y+t.height,o=0,l=0;switch(r){case e3.TopLeft:o=e.x-t.x,l=e.y-t.y;break;case e3.TopRight:o=a-e.x,l=e.y-t.y;break;case e3.BottomLeft:o=e.x-t.x,l=i-e.y;break;case e3.BottomRight:o=a-e.x,l=i-e.y}return Math.min(Math.max(0,o),Math.max(0,l)*n)})(l,n,r,a),o)),c=u/a;switch(r){case e3.TopLeft:return{x:l.x-u,y:l.y-c,width:u,height:c};case e3.TopRight:return{x:l.x,y:l.y-c,width:u,height:c};case e3.BottomLeft:return{x:l.x-u,y:l.y,width:u,height:c};case e3.BottomRight:return{x:l.x,y:l.y,width:u,height:c};default:return e}},tl=(e,t)=>{if(e.width/e.height>t){let r=e.height,n=r*t;return{x:e.x+(e.width-n)/2,y:e.y,width:n,height:r}}let r=e.width,n=r/t;return{x:e.x,y:e.y+(e.height-n)/2,width:r,height:n}},ts=(e,t,r)=>{let n=tl(t,r).width,a=Math.min(n,Math.max(40,40*r)),i=tn(e.width,a,n),o=i/r,l=t.x,s=t.x+t.width-i,d=t.y,u=t.y+t.height-o;return{x:tn(e.x,l,s),y:tn(e.y,d,u),width:i,height:o}},td=(e,t,r,n)=>({x:(e.x-t.x)*r,y:(e.y-t.y)*n}),tu=(e,t,r,n)=>({x:t.x+e.x/r,y:t.y+e.y/n,width:e.width/r,height:e.height/n}),tc=e=>{let{divWidth:t,divHeight:r,image:n,targetWidth:i,targetHeight:o,mode:l="extend",imgPosX:s,imgPosY:d,imgScaleRatio:u,cropRatio:c,onTargetCoordinatesChange:m,onGenerateSuccess:g,generatedImageUrl:p}=e,f=(0,h.useRef)(null),x=(0,h.useRef)(null),b=(0,h.useRef)(null),v=(0,h.useRef)(n),y=(0,h.useRef)(null),w=(0,h.useRef)(null),I=(0,h.useRef)(null),j=(0,h.useRef)(0),F=(0,h.useRef)({targetCoordinates:null,canvasCoordinates:null,adjustedCanvasCoordinates:null,innerArea:null,scaleX:null,scaleY:null,targetRatio:null,imageBoundsTarget:null,imageBoundsCanvas:null,containScale:null,minExtendScale:null});(0,h.useEffect)(()=>{v.current=n},[n]);let N=(0,h.useCallback)((e,t)=>{if(!m)return;let r={x:e.imgPosX,y:e.imgPosY,width:e.imgWidth,height:e.imgHeight};m({...e,mode:l,imageBounds:r,cropRect:"crop"===l&&t?t:void 0})},[l,m]),C=(0,h.useCallback)((e,n)=>{var a;let s,d,u,m,g,p,h,b,I,j,C,R=f.current;if(!R)return;let k=x.current;k||(x.current=k=document.createElement("canvas"));let A=v.current,S=i/o,M=(t/r<i/o?(s=t/i,d=t,u=o*s):(s=r/o,u=r,d=i*s),m=e.imgWidth*s,g=e.imgHeight*s,p=e.imgPosX*s,h=e.imgPosY*s,{canvasScale:s,canvasWidth:d,canvasHeight:u,canvasImgWidth:m,canvasImgHeight:g,canvasImgPosX:p,canvasImgPosY:h});a=k,R.width=t,R.height=r,a.width=t,a.height=r;let _=k.width,E=k.height,T=e7(M.canvasWidth,M.canvasHeight,S,_,E),L=te(M,S,_,E,T),{scaleX:V,scaleY:P}={scaleX:i/T.width,scaleY:o/T.height},D=ti(e),U=tu(D,T,V,P),O=Math.min(i/A.width,o/A.height),$=Math.max(40/A.width,40/A.height,.2*O),W=n?.nextCropRect??y.current;if("crop"===l){let e=c??S,t=`${A.width}x${A.height}-${i}x${o}-${l}-${e}`;W=n?.shouldResetCropRect||w.current!==t||!W?tl(D,e):ts(W,D,e),w.current=t,y.current=W}else y.current=null,w.current=null;F.current={targetCoordinates:e,canvasCoordinates:M,adjustedCanvasCoordinates:L,innerArea:T,scaleX:V,scaleY:P,targetRatio:S,imageBoundsTarget:D,imageBoundsCanvas:U,containScale:O,minExtendScale:$},R.dataset.targetImgScaleRatio=e.imgScaleRatio.toString(),R.dataset.targetImgWidth=e.imgWidth.toString(),R.dataset.targetImgHeight=e.imgHeight.toString(),R.dataset.targetImgPosX=e.imgPosX.toString(),R.dataset.targetImgPosY=e.imgPosY.toString(),R.dataset.canvasScale=M.canvasScale.toString(),R.dataset.canvasImgWidth=M.canvasImgWidth.toString(),R.dataset.canvasImgHeight=M.canvasImgHeight.toString(),R.dataset.canvasImgPosX=M.canvasImgPosX.toString(),R.dataset.canvasImgPosY=M.canvasImgPosY.toString(),n?.log&&(b=i/o,M.canvasWidth,M.canvasHeight,I=_||M.canvasWidth,j=E||M.canvasHeight,C=T||e7(M.canvasWidth,M.canvasHeight,b,I,j),te(M,b,I,j,C)),n?.emit&&N(e,y.current)},[t,r,i,o,l,s,d,u,c,N]),R=(0,h.useCallback)(()=>{let{targetCoordinates:e,imageBoundsTarget:t,targetRatio:r}=F.current;if(!e||!t||!r)return null;if("crop"===l){let e=c??r,n=y.current;if(!n){let r=tl(t,e);return y.current=r,r}let a=ts(n,t,e);return y.current=a,a}return ti(e)},[l,c]),k=(0,h.useCallback)(()=>{let{innerArea:e,scaleX:t,scaleY:r}=F.current;if(!e||!t||!r)return null;let n=R();return n?tu(n,e,t,r):null},[R]),A=(0,h.useCallback)(()=>{let e=f.current;if(!e){b.current=requestAnimationFrame(A);return}let t=x.current;t||(x.current=t=document.createElement("canvas"));let{canvasCoordinates:r,innerArea:n,scaleX:a,scaleY:i,targetRatio:o,imageBoundsCanvas:s,imageBoundsTarget:d}=F.current;if(!r||!n||!a||!i||!o||!s||!d){b.current=requestAnimationFrame(A);return}let u=v.current,c=R(),m="crop"===l&&c?tu(c,n,a,i):void 0,g="extend"===l?s:m||s;((e,t,r,n)=>{let a=e.getContext("2d");if(!a)return;let{canvasWidth:i,canvasHeight:o}
1=r,l=e.width,s=e.height,d=n?.mode??"extend",u=n?.targetRatio??r.canvasWidth/r.canvasHeight,c=n?.innerArea||e7(i,o,u,l,s);if(a.clearRect(0,0,l,s),"extend"===d){let e=(e=>{let t,r,n=e9.get(e);if(n)return n;let a=((t=document.createElement("canvas")).width=24,t.height=24,(r=t.getContext("2d"))?(r.fillStyle="#3a3a3a",r.fillRect(0,0,12,12),r.fillRect(12,12,12,12),r.fillStyle="#2a2a2a",r.fillRect(12,0,12,12),r.fillRect(0,12,12,12),e.createPattern(t,"repeat")):null);return a&&e9.set(e,a),a})(a);e?a.fillStyle=e:a.fillStyle="#333333",a.fillRect(c.x,c.y,c.width,c.height),a.strokeStyle="rgba(166, 112, 66, 0.25)",a.lineWidth=1.5,a.strokeRect(c.x,c.y,c.width,c.height)}let m=te(r,u,l,s,c),g={x:m.canvasImgPosX,y:m.canvasImgPosY,width:m.canvasImgWidth,height:m.canvasImgHeight},p=n?.imageBoundsCanvas??g;if(a.save(),"extend"===d&&(a.beginPath(),a.rect(c.x,c.y,c.width,c.height),a.clip()),a.drawImage(t,g.x,g.y,g.width,g.height),a.restore(),"crop"===d&&n?.cropRectCanvas){let e=n.cropRectCanvas;a.save(),a.beginPath(),a.rect(p.x,p.y,p.width,p.height),a.clip(),a.fillStyle="rgba(0, 0, 0, 0.6)",a.fillRect(p.x,p.y,p.width,p.height),a.globalCompositeOperation="destination-out",a.fillRect(e.x,e.y,e.width,e.height),a.globalCompositeOperation="source-over",a.restore(
1),a.save(),a.beginPath(),a.rect(e.x,e.y,e.width,e.height),a.clip(),a.drawImage(t,g.x,g.y,g.width,g.height),a.restore()}n?.selectionBox&&n.selectionBox.isVisible&&((e,t,r)=>{if(!t.isVisible)return;let n=r?.strokeColor??"#FFFFFF",a=r?.handleColor??n,i=r?.lineWidth??2,o=r?.handleRadius??6;e.strokeStyle=n,e.lineWidth=i,e.strokeRect(t.x,t.y,t.width,t.height),e.fillStyle=a,e.beginPath(),e.arc(t.x,t.y,o,0,2*Math.PI),e.fill(),e.beginPath(),e.arc(t.x+t.width,t.y,o,0,2*Math.PI),e.fill(),e.beginPath(),e.arc(t.x,t.y+t.height,o,0,2*Math.PI),e.fill(),e.beginPath(),e.arc(t.x+t.width,t.y+t.height,o,0,2*Math.PI),e.fill()})(a,n.selectionBox,{strokeColor:e6,handleColor:e6,lineWidth:2,handleRadius:6})})(t,u,r,{mode:l,targetRatio:o,innerArea:n,selectionBox:{x:g.x,y:g.y,width:g.width,height:g.height,isVisible:!0,isDragging:!1},cropRectCanvas:m,imageBoundsCanvas:s}),tt(e,t,!1),b.current=requestAnimationFrame(A)},[R,l]),S=(0,h.useCallback)(()=>{let e=!!I.current;I.current=null;let t=f.current,{targetCoordinates:r,canvasCoordinates:n,adjustedCanvasCoordinates:a,innerArea:i}=F.current;e&&t&&r&&n&&a&&i&&x.current,t&&(t.style.cursor="default")},[i,o]),M=(0,h.useCallback)((e,t)=>{let r=f.current;if(!r)return;let n=k();if(!n){r.style.cursor="default";return}let a=e4(e,t,{x:n.x,y:n.y,width:n.width,height:n.height,isVisible:!0,isDragging:!1});if(a!==e3.None){r.style.cursor=e8(a);return}if(ta({x:e,y:t},n)){r.style.cursor="pointer";return}r.style.cursor="default"},[k]),_=(0,h.useCallback)(e=>{let t=I.current;if(!t||"drag-image"!==t.kind)return;let r=v.current,n=ti(t.startTarget),a=e.x-t.dragOffsetTarget.x,l=e.y-t.dragOffsetTarget.y,s=Math.min(40,.1*n.width,.1*n.height),d=-n.width+s,u=i-s,c=-n.height+s,m=o-s,g=tn(a,d,u),p=tn(l,c,m);C({...t.startTarget,imgPosX:g,imgPosY:p,imgWidth:n.width,imgHeight:n.height,imgScaleRatio:n.width/r.width,targetWidth:i,targetHeight:o},{emit:!0})},[i,o,C]),E=(0,h.useCallback)(e=>{let t=I.current;if(!t||"resize-image"!==t.kind)return;let r=v.current,n=r.width/r.height,a=F.current.containScale??Math.min(i/r.width,o/r.height),l=Math.max(i/r.width,o/r.height),s=F.current.minExtendScale??.2*a,d=r.width*s,u=r.width*l*2,c=to(ti(t.startTarget),e,t.controlPoint,{x:0,y:0,width:i,height:o},n,d,u);C({...t.startTarget,imgPosX:c.x,imgPosY:c.y,imgWidth:c.width,imgHeight:c.height,imgScaleRatio:c.width/r.width,targetWidth:i,targetHeight:o},{emit:!0})},[i,o,C]),T=(0,h.useCallback)(e=>{let t=I.current;if(!t||"drag-crop"!==t.kind)return;let{imageBoundsTarget:r,targetRatio:n}=F.current;if(!r||!n)return;let a=c??n,i=e.x-t.dragOffsetTarget.x,o=e.y-t.dragOffsetTarget.y,l=ts({...t.startCropRect,x:i,y:o},r,a);y.current=l,C(t.startTarget,{nextCropRect:l,emit:!0})},[c,C]),L=(0,h.useCallback)(e=>{let t=I.current;if(!t||"resize-crop"!==t.kind)return;let{imageBoundsTarget:r,targetRatio:n}=F.current;if(!r||!n)return;let a=c??n,i=tl(r,a).width,o=Math.min(i,Math.max(40,40*a)),l=ts(to(t.startCropRect,e,t.controlPoint,r,a,o,i),r,a);y.current=l,C(t.startTarget,{nextCropRect:l,emit:!0})},[c,C]),V=(0,h.useCallback)((e,t)=>{let{innerArea:r,scaleX:n,scaleY:a}=F.current;if(!r||!n||!a)return;let l=td({x:e,y:t},r,n,a),s=I.current,d=s?.kind==="drag-image"||s?.kind==="resize-image"?l:{x:tn(l.x,0,i),y:tn(l.y,0,o)};if(!s)return void M(e,t);switch(s.kind){case"drag-image":_(d);break;case"resize-image":E(d);break;case"drag-crop":T(d);break;case"resize-crop":L(d)}},[i,o,M,_,E,T,L]),P=(0,h.useCallback)((e,t)=>{let r=f.current,{targetCoordinates:n,innerArea:a,scaleX:s,scaleY:d,imageBoundsTarget:u,targetRatio:c}=F.current;if(!r||!n||!a||!s||!d||!u||!c)return;let m=k(),g=R();if(!m||!g)return;let p=td({x:e,y:t},a,s,d),h="extend"===l?p:{x:tn(p.x,0,i),y:tn(p.y,0,o)}
1,x=e4(e,t,{x:m.x,y:m.y,width:m.width,height:m.height,isVisible:!0,isDragging:!1});if(x!==e3.None){I.current="crop"===l?{kind:"resize-crop",startTarget:n,startCropRect:g,controlPoint:x}:{kind:"resize-image",startTarget:n,controlPoint:x},r.style.cursor=e8(x);return}if(!ta({x:e,y:t},m)){r.style.cursor="default";return}if("crop"===l)I.current={kind:"drag-crop",startTarget:n,startCropRect:g,dragOffsetTarget:{x:h.x-g.x,y:h.y-g.y}};else{let e=ti(n);I.current={kind:"drag-image",startTarget:n,dragOffsetTarget:{x:h.x-e.x,y:h.y-e.y}}}r.style.cursor="pointer"},[l,i,o,k,R]);return(0,h.useEffect)(()=>{let e=()=>S(),t=()=>S(),r=e=>{let t=I.current;if(!t||"drag-image"!==t.kind&&"resize-image"!==t.kind)return;let r=f.current;if(!r)return;let n=r.getBoundingClientRect();V(e.clientX-n.left,e.clientY-n.top)};return window.addEventListener("mouseup",e),window.addEventListener("touchend",t),window.addEventListener("mousemove",r),()=>{window.removeEventListener("mouseup",e),window.removeEventListener("touchend",t),window.removeEventListener("mousemove",r)}},[S,V]),(0,h.useEffect)(()=>(b.current=requestAnimationFrame(A),()=>{null!==b.current&&cancelAnimationFrame(b.current)}),[A]),(0,h.useEffect)(()=>{let e,t,r,a,c,m;if(!f.current)return;let g=x.current;g||(x.current=g=document.createElement("canvas")),v.current=n;let p=v.current,h=Math.min(i/p.width,o/p.height),b=(m=p.width/p.height,void 0!==s&&void 0!==d&&void 0!==u?(e=u,t=p.width*e,r=p.height*e,a=s,c=d):m>i/o?(e=i/p.width,t=i,r=p.height*e,a=0,c=(o-r)/2):(e=o/p.height,t=p.width*e,r=o,a=(i-t)/2,c=0),{imgScaleRatio:e,imgWidth:t,imgHeight:r,imgPosX:a,imgPosY:c,targetWidth:i,targetHeight:o});if("crop"===l){let e=p.width*h,t=p.height*h;b={imgScaleRatio:h,imgWidth:e,imgHeight:t,imgPosX:(i-e)/2,imgPosY:(o-t)/2,targetWidth:i,targetHeight:o}}else{let e=Math.max(40/p.width,40/p.height,.2*h),t=Math.max(i/p.width,o/p.height),r=tn(b.imgScaleRatio,e,2*t),n=p.width*r,a=p.height*r,l=Math.min(40,.1*n,.1*a),s=i-l,d=o-l;b={imgScaleRatio:r,imgWidth:n,imgHeight:a,imgPosX:tn(b.imgPosX,-n+l,s),imgPosY:tn(b.imgPosY,-a+l,d),targetWidth:i,targetHeight:o}}C(b,{shouldResetCropRect:!0,emit:!0,log:!0})},[t,r,n,i,o,s,d,u,l,C]),(0,h.useEffect)(()=>{if(!p)return;let e=++j.current,t=new Image;t.crossOrigin="anonymous",t.src=p,t.onload=()=>{if(e!==j.current)return;v.current=t;let r=Math.min(i/t.width,o/t.height),n=t.width*r,a=t.height*r;C({imgScaleRatio:r,imgWidth:n,imgHeight:a,imgPosX:(i-n)/2,imgPosY:(o-a)/2,targetWidth:i,targetHeight:o},{shouldResetCropRect:"crop"===l,emit:!0}),g&&g(t)},t.onerror=t=>{e===j.current&&console.error("生成的图片加载失败:",t)}},[p,l,g,i,o,C]),(0,a.jsx)("canvas",{ref:f,className:"max-w-full max-h-full",style:{touchAction:"none"},onMouseMove:e=>{let t=f.current;if(!t)return;let{x:r,y:n}=tr(e,t);V(r,n)},onMouseDown:e=>{let t=f.current;if(!t)return;let{x:r,y:n}=tr(e,t);P(r,n)},onMouseUp:()=>{S()},onMouseLeave:()=>{let e=I.current;e?.kind!=="drag-image"&&e?.kind!=="resize-image"&&S()},onTouchStart:e=>{e.preventDefault(),e.stopPropagation();let t=f.current;if(!t)return;let{x:r,y:n}=tr(e,t);P(r,n)},onTouchMove:e=>{e.preventDefault(),e.stopPropagation();let t=f.current;if(!t)return;let{x:r,y:n}=tr(e,t);V(r,n)},onTouchEnd:e=>{e.preventDefault(),e.stopPropagation(),S()}})};var tm=r(27068);function tg(e){if(!e)return null;if("object"==typeof e)return e;if("string"!=typeof e)return null;try{return JSON.parse(e)}catch{return null}}function tp(e){return"string"==typeof e?e.toLowerCase():"processing"}async function tf(e){let t=await e.text();try{let r=JSON.parse(t),n=r.error?.message||r.message||t||`HTTP error: ${e.status}`;if(n.includes("Turnstile verification failed"))return Error("TURNSTILE_VERIFICATION_FAILED");return Error(n)}catch{return Error(t||`HTTP error: ${e.status}`)}}async function th(e,t,r,n,a){let i=Number.isFinite(t)&&t>0?t:2e3;for(let t=0;t<90;t+=1){var o;t>0&&await function(e,t){return new Promise((r,n)=>{if(t.aborted)return void n(new DOMException("Aborted","AbortError"));let a=window.setTimeout(r,e);t.addEventListener("abort",()=>{window.clearTimeout(a),n(new DOMException("Aborted","AbortError"))},{once:!0})})}(i,r.signal);let l=await fetch(`/api/history/${encodeURIComponent(e)}`,{cache:"no-store",signal:r.signal});if(!l.ok)throw await tf(l);let s=await l.json().catch(()=>({})),d=s?.data?.item;if(0!==s.code||!d)throw Error(s.message||"Polling failed");let u=tp(d.status),c=Array.isArray(o=d.images)?o:tg(o)??[],m=c.find(e=>"output"===e.role&&"string"==typeof e.url&&e.url.length>0&&"failed"!==tp(e.status));if(m?.url){let t={url:m.url,uuid:m.taskId||e,width:"number"==typeof m.width?m.width:n.width,height:"number"==typeof m.height?m.height:n.height};return a?.(t),t}if("complete"===u||"partial"===u||"failed"===u||"error"===u)throw Error(function(e,t){let r=tg(e.params);return t.find(e=>e.error)?.error||r?.history?.error||"Failed to generate image"}(d,c))}throw Error("Generation timed out")}let tx=async(e,t)=>new Promise((r,n)=>{try{if(!e||"string"!=typeof e||!e.startsWith("data:image"))return void r({image:e,scale:t});let n=document.createElement("img");n.src=e,n.onload=()=>{try{let a=document.createElement("canvas"),i=Math.round(n.width*t),o=Math.round(n.height*t);a.width=i,a.height=o;let l=a.getContext("2d");if(!l){console.error("获取 canvas 上下文失败"),r({image:e,scale:t});return}
1l.drawImage(n,0,0,i,o);let s=a.toDataURL("image/webp",.9),d=e.length;s.length<d?r({image:s,scale:1}):r({image:e,scale:t})}catch(n){console.error("图片处理过程中出错:",n),r({image:e,scale:t})}},n.onerror=n=>{console.error("图片加载失败:",n),r({image:e,scale:t})}}catch(n){console.error("优化图片失败:",n),r({image:e,scale:t})}}),tb=async(e,t)=>{let r=new AbortController;try{let{image:n,scale:a}=await tx(e.extend_images.image,e.extend_images.scale),i=await (0,tm.I)("/api/extend/task",{input_image:n,width:e.width,height:e.height,scale:a,pos_x:e.extend_images.pos_x,pos_y:e.extend_images.pos_y,client_request_id:"u">typeof crypto&&"randomUUID"in crypto?crypto.randomUUID():`${Date.now()}-${Math.random().toString(36).slice(2)}`},{signal:r.signal,analytics:{toolType:"expand-image",mediaType:"image"}});if(!i.ok){if(429===i.status)throw Error("RATE_LIMIT_EXCEEDED");let e=await tf(i);throw console.error(`API 错误 (${i.status}):`,e.message),e}let o=await i.json().catch(()=>({}));if(0!==o.code||!o.data?.historyId)throw Error(o.error?.message||o.message||"Failed to create task");let l=await th(o.data.historyId,o.data.pollIntervalMs||2e3,r,{width:e.width,height:e.height},t);return{controller:r,result:l}}catch(e){throw console.error("图片扩展调用失败:",e),e}},tv=new WeakMap,ty=async e=>{if(e instanceof File){let t=tv.get(e);if(t)return t;let r=await (0,eT.Q1)(e);return tv.set(e,r),r}if(e.startsWith("data:")||e.startsWith("blob:"))return new Promise((t,r)=>{let n=new Image;e.startsWith("data:")||e.startsWith("blob:")||(n.crossOrigin="anonymous"),n.onload=()=>t(n),n.onerror=e=>r(e),n.src=e});let t=await (0,eb.Cn)(e);return(0,eT.Q1)(t)},tw=async(e,t,r,n)=>{let a=await new Promise(t=>{e.toBlob(e=>t(e),r,n)});if(!a)throw Error("Canvas export failed");return new File([a],t,{type:r})};function tI(e){let{open:t,onOpenChange:r,source:n,targetRatio:i,availableRatios:o,onRatioChange:l,title:s,ratioLabel:d,defaultMode:u="crop",onConfirm:c,onCancel:m}=e,g=(0,v.c)("studio.imageActions"),p=(0,v.c)("quickI2I.modal"),f=(0,v.c)("extend.editor"),x=(0,v.c)("fluxKontext.errors"),b=(0,h.useRef)(null),y=(0,h.useRef)(null),w=(0,h.useRef)(null),I=(0,h.useRef)(null),j=(0,h.useRef)(null),N=(0,h.useRef)(null),[C,k]=(0,h.useState)(u),[A,S]=(0,h.useState)(null),[M,_]=(0,h.useState)({width:0,height:0}),[E,T]=(0,h.useState)(null),[L,V]=(0,h.useState)(!1),[P,D]=(0,h.useState)(!1),[U,O]=(0,h.useState)(null),[$,W]=(0,h.useState)(0),[q,H]=(0,h.useState)(null),[B,z]=(0,h.useState)(null),G=(0,h.useRef)(null),X=(0,h.useCallback)(function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:b.current;if(!e)return;let t=e.clientWidth,r=e.clientHeight;t<=0||r<=0||_(e=>e.width===t&&e.height===r?e:{width:t,height:r})},[]),Y=(0,h.useCallback)(e=>{b.current=e,X(e)},[X]);(0,h.useEffect)(()=>{t?k(u):I.current=null},[t,u]),(0,h.useEffect)(()=>{let e;if(!t){S(null),T(null),G.current=null,D(!1),O(null),w.current=null,q?.url&&URL.revokeObjectURL(q.url),H(null),B?.url&&URL.revokeObjectURL(B.url),z(null),y.current&&(y.current.abort(),y.current=null);return}if(!n)return void S(null);if(j.current?.source===n)return void S(j.current.image);N.current?.source===n?e=N.current.promise:(e=ty(n),N.current={source:n,promise:e});let r=!0;return e.then(e=>{r&&(j.current={source:n,image:e},S(e))}).catch(e=>{console.error("Failed to load image",e),r&&S(null)}).finally(()=>{N.current?.source===n&&(N.current=null)}),()=>{r=!1}},[t,n]),(0,h.useEffect)(()=>{if(!t||!b.current)return;let e=0,r=0,n=()=>{X(),(r+=1)<12&&b.current&&(0===b.current.clientWidth||0===b.current.clientHeight)&&(e=requestAnimationFrame(n))};e=requestAnimationFrame(n);let a=new ResizeObserver(()=>X());return a.observe(b.current),()=>{cancelAnimationFrame(e),a.disconnect()}},[t,X]),(0,h.useEffect)(()=>{t&&X()},[t,A,C,i,X]);let Q=(0,h.useMemo)(()=>{if(!A)return null;if("crop"===C){let e=Math.min(1,eb.ry/Math.max(A.width,A.height));return{targetWidth:Math.round(A.width*e),targetHeight:Math.round(A.height*e)}}return(0,eb.Ll)(A.width,A.height,i,C,eb.ry)},[A,C,i]),J=(0,h.useMemo)(()=>A&&Q?(0,eb.yj)(A.width,A.height,Q.targetWidth,Q.targetHeight,"contain"):null,[A,Q,C]),K=(0,h.useMemo)(()=>
1{if("extend"!==C||!Q)return null;let e=E??I.current;return!e||e.mode&&"extend"!==e.mode||e.targetWidth!==Q.targetWidth||e.targetHeight!==Q.targetHeight?null:{posX:e.imgPosX,posY:e.imgPosY,scale:e.imgScaleRatio}},[C,E,Q]),Z=(0,h.useCallback)(e=>{let t=G.current;t&&t.imgPosX===e.imgPosX&&t.imgPosY===e.imgPosY&&t.imgScaleRatio===e.imgScaleRatio&&t.imgWidth===e.imgWidth&&t.imgHeight===e.imgHeight&&t.targetWidth===e.targetWidth&&t.targetHeight===e.targetHeight&&t.mode===e.mode&&t.cropRect?.x===e.cropRect?.x&&t.cropRect?.y===e.cropRect?.y&&t.cropRect?.width===e.cropRect?.width&&t.cropRect?.height===e.cropRect?.height||(G.current=e,T(e),"extend"===e.mode&&(I.current=e))},[]),ee=(0,h.useCallback)(e=>{e&&(w.current=e),O(null),D(!0),W(e=>e+1)},[]),et=!!(A&&Q&&J)&&M.width>0&&M.height>0,er=()=>{m(),r(!1)},en=async()=>{if(!n||!A||!E)return void R.oR.error(f("errors.adjustPosition"));V(!0);try{let e=(0,eb.fR)(n),t=((e,t,r)=>{let n="image/png"===t?"png":"image/webp"===t?"webp":"jpg";if(e instanceof File&&e.name){let t=e.name.replace(/\.[^.]+$/,"");return`${t}-${r}.${n}`}return`image-${r}-${Date.now()}.${n}`})(n,e,"crop"),r=document.createElement("canvas"),a=E.cropRect;if(a){let e=a.width/a.height;e>=1?(r.width=Math.min(eb.ry,Math.round(a.width)),r.height=Math.round(r.width/e)):(r.height=Math.min(eb.ry,Math.round(a.height)),r.width=Math.round(r.height*e));let t=r.getContext("2d");if(!t)throw Error("Failed to create canvas context");let n=E.imgScaleRatio,i=(a.x-E.imgPosX)/n,o=(a.y-E.imgPosY)/n,l=a.width/n,s=a.height/n,d=Math.min(Math.max(0,i),A.width),u=Math.min(Math.max(0,o),A.height),c=Math.min(l,A.width-d),m=Math.min(s,A.height-u);t.drawImage(A,d,u,c,m,0,0,r.width,r.height)}else{r.width=E.targetWidth,r.height=E.targetHeight;let e=r.getContext("2d");if(!e)throw Error("Failed to create canvas context");e.drawImage(A,E.imgPosX,E.imgPosY,E.imgWidth,E.imgHeight)}let i=(0,eb.Ag)(e),o=await tw(r,t,e,i),l=URL.createObjectURL(o);z({file:o,url:l})}catch(e){console.error("Crop failed",e),R.oR.error(f("errors.incompleteData"))}finally{V(!1)}},ea=async(e,t)=>{let r;V(!0);try{let{controller:n,result:a}=await tb({...e,turnstileToken:t},e=>{r=e});y.current=n;let i=a??r;if(!i)throw Error("No response");let o=await (0,eb.Cn)(i.url),l=(0,eb.fR)(o),s=await (0,eb.CD)(o,eb.ry,l),d=URL.createObjectURL(s);H({file:s,url:d}),w.current=null}catch(t){if(t instanceof Error&&"TURNSTILE_VERIFICATION_FAILED"===t.message)return void ee(e);w.current=null,console.error("Extend failed",t),R.oR.error(f("errors.generationFailed",{message:x("failedToGenerateImage")}))}finally{V(!1),y.current=null}},ei=async()=>{if(!n||!A||!E)return void R.oR.error(f("errors.adjustPosition"));try{let e=await (0,eb.ou)(n),t={prompt:"",width:Math.round(E.targetWidth),height:Math.round(E.targetHeight),upload_to_s3:!1,extend_images:{image:e,scale:E.imgScaleRatio,pos_x:Math.round(E.imgPosX),pos_y:Math.round(E.imgPosY)},turnstileToken:U||""};if(!U)return void ee(t);await ea(t,U)}catch(e){console.error("Extend setup failed",e),R.oR.error(f("errors.incompleteData"))}},eo=async()=>{"extend"===C?await ei():await en()},el=async e=>{O(e),D(!1);let t=w.current;t&&await ea(t,e)};return(0,a.jsx)(eR.lG,{open:t,onOpenChange:e=>{e?r(e):er()},children:(0,a.jsxs)(eR.Cf,{"aria-describedby":void 0,className:"w-[min(96vw,1200px)] max-h-[calc(100dvh-1rem)] max-w-6xl overflow-hidden border-border/60 bg-background p-0 shadow-2xl max-sm:inset-0 max-sm:left-0 max-sm:top-0 max-sm:h-[100dvh] max-sm:max-h-[100dvh] max-sm:w-screen max-sm:max-w-none max-sm:translate-x-0 max-sm:translate-y-0 max-sm:rounded-none max-sm:border-0",children:[(0,a.jsxs)("div",{className:"flex h-[80dvh] min-h-0 flex-col max-sm:h-[100dvh]",children:[(0,a.jsxs)("div",{className:"grid min-h-14 shrink-0 grid-cols-[minmax(0,1fr)_auto] items-center gap-x-2 gap-y-1 px-3 py-2 sm:flex sm:h-14 sm:gap-3 sm:px-4 sm:py-0",children:[(0,a.jsx)(eR.L3,{className:"min-w-0 truncate text-[13px] font-semibold tracking-[-0.01em]",children:s}),(0,a.jsxs)("div",{className:"order-3 col-span-2 flex h-8 items-center justify-self-center rounded-full bg-foreground
1/[0.06] p-0.5 sm:order-none sm:col-span-1 sm:ml-auto sm:justify-self-auto",children:[(0,a.jsx)("button",{type:"button",onClick:()=>k("extend"),className:(0,F.cn)("h-7 rounded-full px-3 text-[11px] font-medium transition-colors","extend"===C?"bg-foreground/[0.08] text-foreground":"text-muted-foreground hover:text-foreground"),children:g("extend.label")}),(0,a.jsx)("button",{type:"button",onClick:()=>k("crop"),className:(0,F.cn)("h-7 rounded-full px-3 text-[11px] font-medium transition-colors","crop"===C?"bg-foreground/[0.08] text-foreground":"text-muted-foreground hover:text-foreground"),children:g("crop.label")})]}),(0,a.jsx)(eR.HM,{asChild:!0,children:(0,a.jsxs)(e5.$,{variant:"ghost",size:"icon",className:"h-8 w-8 shrink-0 rounded-full",children:[(0,a.jsx)(eI.A,{className:"h-4 w-4"}),(0,a.jsx)("span",{className:"sr-only",children:p("cancel")})]})})]}),(0,a.jsx)("div",{className:"min-h-0 flex-1 overflow-y-auto overscroll-contain bg-black",children:(0,a.jsx)("div",{ref:Y,className:"h-full min-h-[12rem] w-full bg-muted/20 flex items-center justify-center relative",children:q||B?(0,a.jsx)("div",{className:"absolute inset-0 z-10 flex items-center justify-center bg-background/95",children:(0,a.jsx)("img",{src:q?.url||B?.url,alt:"Preview",className:"max-h-full max-w-full object-contain"})}):(0,a.jsxs)(a.Fragment,{children:[L&&(0,a.jsxs)("div",{className:"absolute inset-0 z-10 flex flex-col items-center justify-center bg-background/80 backdrop-blur-sm",children:[(0,a.jsx)(e2.A,{className:"h-10 w-10 animate-spin text-primary mb-4"}),(0,a.jsx)("p",{className:"text-foreground font-medium",children:f("messages.generatingImage")||"Generating"}),(0,a.jsx)("p",{className:"text-muted-foreground text-sm mt-1",children:f("messages.estimatedTime")||"Estimated time: 20s"})]}),et&&A&&Q&&J?(0,a.jsx)(tc,{divWidth:M.width,divHeight:M.height,image:A,targetWidth:Q.targetWidth,targetHeight:Q.targetHeight,imgPosX:K?.posX??J.posX,imgPosY:K?.posY??J.posY,imgScaleRatio:K?.scale??J.scale,mode:C,cropRatio:"crop"===C?(0,eb.U3)(i):void 0,onTargetCoordinatesChange:Z}):(0,a.jsx)(e2.A,{className:"h-5 w-5 animate-spin text-muted-foreground"})]})})}
1),(0,a.jsx)("div",{className:"shrink-0 bg-foreground/[0.025] px-3 pb-[max(0.75rem,env(safe-area-inset-bottom))] pt-2.5",children:(0,a.jsxs)("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-end sm:justify-between",children:[!(q||B)&&(0,a.jsxs)("div",{className:"flex min-w-0 items-center gap-2 sm:flex-1",children:[(0,a.jsx)("span",{className:"shrink-0 whitespace-nowrap text-[10px] font-semibold uppercase tracking-[0.12em] text-muted-foreground",children:d||"Aspect Ratio"}),o&&o.length>1&&l?(0,a.jsx)("div",{className:"flex min-w-0 flex-1 items-center gap-1.5 overflow-x-auto overscroll-x-contain",children:o.map(e=>(0,a.jsx)("button",{type:"button",onClick:()=>l(e),disabled:L,className:(0,F.cn)("h-8 shrink-0 rounded-lg px-3 text-[11px] font-semibold transition-colors",i===e?"bg-primary/15 text-primary":"text-muted-foreground hover:bg-foreground/[0.05] hover:text-foreground"),children:e},e))}):(0,a.jsx)("span",{className:"inline-flex h-8 items-center rounded-lg bg-primary/15 px-3 text-[11px] font-semibold text-primary",children:i})]}),(q||B)&&(0,a.jsx)("div",{className:"flex min-h-8 items-center text-[11px] text-muted-foreground sm:flex-1",children:(0,a.jsx)("span",{children:f("previewHint")||"Preview the result"})}),(0,a.jsx)("div",{className:"grid grid-cols-[0.72fr_1.28fr] gap-2 sm:w-[280px] sm:shrink-0",children:q||B?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(e5.$,{variant:"ghost",className:"h-10 rounded-[10px] bg-foreground
1/[0.045] text-[12px] font-medium text-muted-foreground hover:bg-foreground/[0.075] hover:text-foreground",onClick:q?()=>{q?.url&&URL.revokeObjectURL(q.url),H(null),O(null)}:()=>{B?.url&&URL.revokeObjectURL(B.url),z(null)},children:f("retry")||"Retry"}),(0,a.jsx)(e5.$,{className:"h-10 rounded-[10px] text-[13px] font-semibold",onClick:q?()=>{q&&(c(q.file,"extend"),URL.revokeObjectURL(q.url),H(null),r(!1))}:()=>{B&&(c(B.file,"crop"),URL.revokeObjectURL(B.url),z(null),r(!1))},children:f("useThis")||"Use This"})]}):(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(e5.$,{variant:"ghost",className:"h-10 rounded-[10px] bg-foreground/[0.045] text-[12px] font-medium text-muted-foreground hover:bg-foreground/[0.075] hover:text-foreground",onClick:er,disabled:L,children:p("cancel")}),(0,a.jsxs)(e5.$,{className:"h-10 rounded-[10px] text-[13px] font-semibold",onClick:eo,disabled:L||!n,children:[L&&(0,a.jsx)(e2.A,{className:"mr-2 h-4 w-4 animate-spin"}),"crop"===C?g("crop.label"):p("generate")]})]})})]})})]}),P&&(0,a.jsx)(e0.W,{className:"flex items-center justify-center bg-black/50",children:(0,a.jsx)("div",{className:"rounded-lg bg-background p-6",children:(0,a.jsx)(e1.Xs,{siteKey:"0x4AAAAAAA5Sq0S5dntDaacq",onSuccess:el,onError:()=>{O(null),D(!1)},onExpire:()=>{O(null),D(!1)}},$)})})]})})}var tj=r(94160),tF=r(2530);function tN(e){return"textToVideo"===e?"text_to_video":"imageToVideo"===e?"image_to_video":"referenceToVideo"===e?"reference_to_video":void 0}function tC(e){let t=tN(e.mode);return{...t?{generation_mode:t}:{},..."boolean"==typeof e.durationAuto?{duration_mode:e.durationAuto?"auto":"fixed"}:{}}}var tR=r(65732),tk=r(65340),tA=r(83385),tS=r(33578);let tM="raphael_ai_video_generator_draft_v1";function t_(e,t){let r=e.sourceHistoryId?.trim();if(r)for(let n of[e.startFrameImageUrl,e.endFrameImageUrl,...e.referenceImageUrls??[],...e.referenceVideoUrls??[],...e.referenceAudioUrls??[]]){let e=n?.trim();!e||e.startsWith("data:")||e.startsWith("blob:")||t.set(e,r)}}function tE(e){(0,tS._q)("session",tM,e)}function tT(){let e=(0,tS.uU)("session",tM);return e&&"object"==typeof e?e:null}function tL(){(0,tS.xZ)("session",tM)}var tV=r(98121),tP=r(23823),tD=r(13523),tU=r(44973),tO=r(45431),t$=r(53694),tW=r(34751),tq=r(90938);function tH(e){let t,r,n,{isGenerating:i,videoUrls:o,thumbnailUrls:l=[],prompt:s,modelId:d,modelLabel:u,modelLogoSrc:c,mode:m="imageToVideo",duration:g,durationAuto:p=!1,startFrameImage:x,aspectRatio:b,resolution:I,outputCount:j=1,enhancePrompt:F=!1,enhancedPrompt:N,isZh:C=!1,billingMode:R,unlimitedState:k,estimatedTimeLabel:A,progress:S,labels:M}=e,_=(0,v.c)("unlimitedGeneration"),E=(0,v.c)("videoGenerator.result"),T=(0,v.c)("imageGenerator.controls"),L=(0,v.c)("imageGenerator.results"),V=(0,v.c)("settings.assets"),P=(0,v.c)("videoGenerator.reference"),[D,U]=(0,h.useState)(0),[O,$]=(0,h.useState)({}),W=Math.max(1,j,o.length);(0,h.useEffect)(()=>{$({})},[o]),(0,h.useEffect)(()=>{U(e=>Math.min(e,W-1))},[W]);let q=Number.isFinite(S)?Math.min(Math.max(S,0),100):0,H=(0,h.useMemo)(()=>x?"string"==typeof x?x:URL.createObjectURL(x):null,[x]),B=(0,h.useMemo)(()=>{let[e,t]=b.split(":").map(Number);return{ratio:e>0&&t>0?e/t:16/9,css:e>0&&t>0?`${e}/${t}`:"16/9"}},[b]),z=(0,h.useMemo)(()=>{let{ratio:e}=B;return e>1.2?"max-w-3xl lg:max-w-4xl":e>.8?"max-w-md sm:max-w-lg md:max-w-xl lg:max-w-2xl":"max-w-[280px] sm:max-w-xs md:max-w-sm"},[B]),G=(0,h.useMemo)(()=>({aspectRatio:B.css,maxHeight:"var(--video-max-h)",width:`min(100%, calc(var(--video-max-h) * ${B.ratio}))`}),[B]);if((0,h.useEffect)(()=>()=>{H&&URL.revokeObjectURL(H)},[H]),!i&&0===o.length)return null;let X=o[D]??o[0],Y=O[D]??!1,Q=s.length>20?`${s.slice(0,20)}...`:s,J=q<30?M?.queueing||"Queueing":q<70?M?.rendering||"Rendering":M?.finalizing||"Finalizing",K=M?.clips||"Clips";M?.details;let Z=M?.untitledVideo||"Untitled Video",ee=W>1?M?.clips_plural||"clips":M?.clip||"clip",et=M?.estimated||"Est.",er=E("referenceToVideo"===m?"referenceToVideo":"imageToVideo"===m?"imageToVideo":"textToVideo"),en=tq.i6.find(e=>e.id===d),ea=(0,tq.Xd)(en,I).toUpperCase(),ei=(0,tq.sf)(en,I),eo=ei&&!(0,f.fe)(d)?T("low"===ei?"qualityLow":"medium"===ei?"qualityMedium":"qualityHigh"):void 0,el=[b,p?P("auto"):`${g}s`,ea,eo,`\xd7${W}
1`].filter(Boolean).join(" \xb7 "),es=M?.generationTimeHint?M.generationTimeHint.replace("{time}",A||"~2 min"):`Video generation typically takes ${A||"~2 min"}. Please wait patiently.`;return(0,a.jsxs)("div",{className:"w-full max-w-6xl mx-auto animate-in fade-in slide-in-from-bottom-4 duration-500",children:[(0,a.jsxs)("div",{className:"mb-3 space-y-2 px-1",children:[(0,a.jsx)("div",{className:"text-sm font-medium text-foreground",children:Q||Z}),(0,a.jsxs)("div",{className:"flex flex-wrap items-center gap-1.5 text-[11px] font-medium text-foreground/70",children:[(0,a.jsx)("span",{className:"inline-flex items-center rounded-md border border-amber-500/20 bg-amber-500/10 px-1.5 py-0.5 leading-none text-amber-300",children:er}),(0,a.jsxs)("span",{className:"inline-flex items-center gap-1 rounded-md bg-white/[0.06] px-1.5 py-0.5",children:[(0,a.jsx)(w.default,{src:c||"/logo.webp",alt:"",width:14,height:14,className:"h-3.5 w-3.5 rounded-sm"}),u||d]}),N?(0,a.jsx)(t$.G,{prompt:N,isZh:C}):F?(0,a.jsxs)("span",{className:"inline-flex items-center gap-1 rounded-md bg-white/[0.06] px-1.5 py-0.5",children:[(0,a.jsx)(y.A,{className:"h-3 w-3 text-amber-300/75"}),E("aiEnhanced")]}):null,(0,a.jsx)("span",{className:"inline-flex items-center rounded-md bg-white/[0.06] px-1.5 py-0.5",children:el}),(0,a.jsxs)("span",{className:"inline-flex items-center rounded-md bg-white/[0.06] px-1.5 py-0.5 text-foreground/50",children:[W," ",ee]})]})]}),(0,a.jsxs)("div",{className:"flex flex-col md:flex-row gap-4",children:[(0,a.jsxs)("div",{className:"order-first md:order-none md:w-28",children:[(0,a.jsxs)("div",{className:"flex items-center justify-between px-1 text-[11px] font-semibold uppercase tracking-wide text-muted-foreground/80 mb-2",children:[(0,a.jsx)("span",{children:K}),(0,a.jsxs)("span",{className:"md:hidden text-[10px] font-medium normal-case tracking-normal text-muted-foreground/60",children:[D+1,"/",W]})]}),(0,a.jsx)("div",{className:"flex md:flex-col gap-3 overflow-x-auto md:overflow-y-auto md:max-h-[560px] pr-1 pb-1 md:pb-0 [&::-webkit-scrollbar]:w-1.5 [&::-webkit-scrollbar]:h-1.5 [&::-webkit-scrollbar-track]:bg-transparent [&::-webkit-scrollbar-thumb]:rounded-full [&::-webkit-scrollbar-thumb]:bg-white/10 hover:[&::-webkit-scrollbar-thumb]:bg-white/20",children:Array.from({length:W}).map((e,t)=>{let r=D===t,n=o[t],s=l[t],d="imageToVideo"===m||"referenceToVideo"===m?H:s;return(0,a.jsxs)("button",{type:"button",onClick:()=>U(t),className:["relative h-20 w-20 md:h-24 md:w-24 overflow-hidden border transition-all bg-secondary/40",r?"border-primary ring-2 ring-primary/40 shadow-lg shadow-primary/10":"border-border/40 hover:border-primary/40"].join(" "),children:[d?(0,a.jsx)("img",{src:d,alt:`Clip ${t+1}`,className:"h-full w-full object-cover",onError:e=>{e.target.style.display="none"}}):!i&&n?(0,a.jsx)("video",{src:n,muted:!0,playsInline:!0,className:"h-full w-full object-cover",onError:e=>{e.target.style.display="none"}},n):(0,a.jsx)("div",{className:"h-full w-full bg-gradient-to-br from-muted/40 via-muted/20 to-background/40 animate-pulse"}),(0,a.jsx)("div",{className:"absolute bottom-1.5 right-1.5 rounded-md bg-black/70 px-1.5 py-0.5 text-[11px] font-semibold text-white",children:t+1})]},`clip-${t}`)})})]}),(0,a.jsxs)("div",{className:"flex-1 flex flex-col items-center justify-center",children:[(0,a.jsxs)("div",{className:`relative bg-black/40 overflow-hidden border border-border/30 shadow-2xl w-full ${z} [--video-max-h:55vh] md:[--video-max-h:60vh] lg:[--video-max-h:65vh]`,style:G,children:[(t=o[D],r=O[D]??!1,n=!!t&&!r,i&&n?(0,a.jsxs)("div",{className:"absolute inset-0 z-10 bg-black",children:[(0,a.jsx)("video",{src:t,controls:!0,autoPlay:!0,loop:!0,playsInline:!0,preload:"auto",className:"w-full h-full object-contain",onError:e=>{let r=e.currentTarget.error;console.error(`[Video Player] Failed to load video: ${t}`),console.error(`[Video Player] Error code: ${r?.code}, message: ${r?.message}`),$(e=>({...e,[D]:!0}))}},t),(0,a.jsxs)("div",{className:"absolute top-3 right-3 z-20 flex items-center gap-2 bg-black/70 backdrop-blur-sm rounded-full px-3 py-1.5",children:[(0,a.jsx)("div",{className:"w-2 h-2 rounded-full bg-primary animate-pulse"}),(0,a.jsxs)("span",{className:"text-xs text-white/80",children:[o.length,"/",W," ",M?.clips_plural||"clips"]})]})]}):null),i&&!o[D]&&(0,a.jsxs)("div",{className:"absolute inset-0 z-20 flex flex-col justify-end p-5 sm:p-6",children:[H&&(0,a.jsx)("div",{className:"absolute inset-0 bg-cover bg-center opacity-25",style:{backgroundImage:`url(${H})`}}
1),!H&&(0,a.jsx)("div",{className:"absolute inset-0 bg-gradient-to-br from-primary/10 via-background to-secondary/10"}),(0,a.jsxs)("div",{className:"relative z-10 w-full space-y-3",children:["unlimited"!==R&&A&&(0,a.jsx)("div",{className:"text-center text-xs sm:text-sm text-muted-foreground/80",children:(0,a.jsxs)("span",{className:"inline-flex items-center gap-1.5",children:[(0,a.jsx)("svg",{className:"w-4 h-4 animate-pulse",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:(0,a.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"})}),es]})}),(0,a.jsxs)("div",{className:"flex items-center justify-between text-xs sm:text-sm text-muted-foreground",children:[(0,a.jsx)("span",{children:"unlimited"===R?_((0,tD.C)(k)):`${J}...`}),"unlimited"!==R&&A&&(0,a.jsxs)("span",{children:[et," ",A]})]}),"unlimited"!==R&&(0,a.jsx)(tU.Progress,{value:q,className:"h-1.5"})]})]}),!i&&o.length>0&&(0,a.jsx)("div",{className:"absolute inset-0 z-10 bg-black",children:o.map((e,t)=>{let r=D===t;return O[t]?null:(0,a.jsx)("video",{src:e,controls:r,autoPlay:r,loop:!0,muted:!r,playsInline:!0,preload:"auto",className:["absolute inset-0 w-full h-full object-contain transition-opacity duration-200",r?"opacity-100 z-10":"opacity-0 z-0 pointer-events-none"].join(" "),onError:r=>{let n=r.currentTarget,a=n.error;console.error(`[Video Player] Failed to load video: ${e}`),console.error(`[Video Player] Error code: ${a?.code}, message: ${a?.message}`),console.error(`[Video Player] Network state: ${n.networkState}, Ready state: ${n.readyState}`),$(e=>({...e,[t]:!0}))}},e)})}),!i&&X&&Y&&(0,a.jsxs)("div",{className:"absolute inset-0 z-10 bg-black/80 flex flex-col items-center justify-center gap-3 p-4",children:[(0,a.jsx)(tO.A,{className:"w-10 h-10 text-destructive/70"}),(0,a.jsx)("p",{className:"text-sm text-muted-foreground text-center",children:"Video failed to load. The file may still be processing."}),(0,a.jsx)("button",{type:"button",onClick:()=>$(e=>({...e,[D]:!1})),className:"text-xs text-primary hover:underline",children:"Try again"})]})]}),X&&!Y?(0,a.jsx)("div",{className:`mt-2 flex w-full justify-start md:hidden ${z}`,children:(0,a.jsx)(tW.b,{videoUrl:X,fileName:`raphael-video-${D+1}.mp4`,label:L.has("videoDownloadTitle")?L("videoDownloadTitle"):"Download",errorLabel:V.has("downloadFailed")?V("downloadFailed"):"Download failed. Please try again later."})}):null]})]})]})}var tB=r(62778),tz=r(64894),tG=r(51939),tX=r(13080),tY=r(27157);function tQ(e,t){return!(0,f.bq)(e?.id)&&e?.imageRatioPolicy!=="provider-pad"&&(e?.imageRatioPolicy!=="adaptive"||"adaptive"!==t.toLowerCase())}var tJ=r(32807),tK=r(68022),tZ=r(24489),t0=r(68566),t1=r(54651),t2=r(61639),t5=r(55112),t3=r(54079),t4=r(54e3),t8=r(63831),t6=r(71838),t9=r(98386),t7=r(65716),re=r(85178),rt=r(73974),rr=r(82999);let rn=[2e3,5e3,1e4,1e4,1e4,1e4,1e4,1e4,1e4,1e4];class ra extends Error{constructor(){super("Video submission was not found"),this.name="VideoSubmissionNotFoundError"}}class ri extends Error{constructor(e){super("Video submission could not be confirmed",e),this.name="VideoSubmissionUnconfirmedError"}}class ro extends Error{constructor(e){super(e.message||"Video submission failed"),this.response=e,this.name="VideoSubmissionBusinessError"}}async function rl(e){try{return await (0,d.UG)({clientRequestId:e.clientRequestId,attempt:e.attempt,timeoutMs:e.timeoutMs,reconcileTimeoutMs:e.reconcileTimeoutMs,reconcileIntervalMs:e.reconcileIntervalMs,onPhaseChange:e.onPhaseChange,isTerminalError:e=>e instanceof ro,reconcile:async(t,r)=>{let n=await e.reconcile(t,r);return"not_found"===n.kind?n:{kind:"found",value:{...n,source:"reconcile"}}}})}catch(e){if(e instanceof d.S0)throw new ra;if(e instanceof d.jM)throw new ri({cause:e.cause});throw e}}let rs="video-generation-pending-submission";function rd(e){return(0,tS._q)("session",rs,e)}function ru(){let e=(0,tS.uU)("session",rs);if(!e?.clientRequestId||!e.createdAt)return null;let t=Date.parse(e.createdAt);return!Number.isFinite(t)||t>Date.now()+6e4||Date.now()-t>18e5?((0,tS.xZ)("session",rs),null):e}function rc(e){if(e){let t=ru();if(t&&t.clientRequestId!==e)return}(0,tS.xZ)("session",rs)}var rm=r(57339);let rg="REFERENCE_IMAGE_UNAVAILABLE",rp="video-draft-images",rf="draft-id",rh="created-at";
1class rx extends Error{constructor(e="VIDEO_DRAFT_IMAGE_STORAGE_FAILED"){super(e),this.name="VideoDraftImageStorageError"}}function rb(e){return new Promise((t,r)=>{e.onsuccess=()=>t(e.result),e.onerror=()=>r(e.error??new rx)})}function rv(e){return new Promise((t,r)=>{e.oncomplete=()=>t(),e.onerror=()=>r(e.error??new rx),e.onabort=()=>r(e.error??new rx)})}function ry(){return"u"<typeof indexedDB?Promise.reject(new rx):new Promise((e,t)=>{let r=indexedDB.open("raphael-generator-drafts",1);r.onupgradeneeded=()=>{let e=r.result;if(e.objectStoreNames.contains(rp))return;let t=e.createObjectStore(rp,{keyPath:"key"});t.createIndex(rf,"draftId",{unique:!1}),t.createIndex(rh,"createdAt",{unique:!1})},r.onsuccess=()=>e(r.result),r.onerror=()=>t(r.error??new rx),r.onblocked=()=>t(new rx)})}function rw(e,t,r,n){return{key:`${e}:${t}`,draftId:e,slot:t,blob:r,name:r.name,type:r.type,lastModified:r.lastModified,createdAt:n}}async function rI(e,t){let r=await ry();try{let n=r.transaction(rp,"readwrite"),a=rv(n),i=n.objectStore(rp);(await rb(i.index(rf).getAllKeys(IDBKeyRange.only(e)))).forEach(e=>i.delete(e)),t.forEach(e=>i.put(e)),await a}finally{r.close()}}async function rj(e){let t=async e=>{if("string"!=typeof e||!e.startsWith("blob:"))return e;try{let t=await fetch(e);if(!t.ok)throw new rx;let r=await t.blob();return new File([r],"draft-image",{type:r.type})}catch{throw new rx}},[r,n,a]=await Promise.all([t(e.startFrameImage),t(e.endFrameImage),Promise.all(e.referenceImages.map(async e=>await t(e)))]);e={...e,startFrameImage:r,endFrameImage:n,referenceImages:a};let i=Date.now(),o=[],l={draftId:e.draftId},s=(t,r)=>{if(t){if("string"==typeof t)return t;o.push(rw(e.draftId,r,t,i))}},d=s(e.startFrameImage,"start");e.startFrameImage instanceof File&&(l.startFrameSlot="start");let u=s(e.endFrameImage,"end");e.endFrameImage instanceof File&&(l.endFrameSlot="end");let c=e.referenceImages.map((t,r)=>{if("string"==typeof t)return{kind:"url",url:t};let n=`reference-${r}`;return o.push(rw(e.draftId,n,t,i)),{kind:"local",slot:n}});c.length>0&&(l.referenceEntries=c),o.length>0&&(await rI(e.draftId,o).catch(e=>{throw e instanceof rx?e:new rx}),rC().catch(()=>void 0));let m=c.filter(e=>"url"===e.kind).map(e=>e.url);return{startFrameImageUrl:d,endFrameImageUrl:u,referenceImageUrls:m.length>0?m:void 0,localImageDraft:o.length>0?l:void 0}}async function rF(e){if(!e)return{referenceImages:[],missingLocalImages:!1};let t=await ry();try{let r=t.transaction(rp,"readonly"),n=rv(r),a=await rb(r.objectStore(rp).index(rf).getAll(IDBKeyRange.only(e.draftId)));await n;let i=a.filter(e=>Date.now()-e.createdAt<=36e5),o=new Map(i.map(e=>[e.slot,e])),l=i.length!==a.length,s=e=>{if(!e)return;let t=o.get(e);if(!t){l=!0;return}return new File([t.blob],t.name||"draft-image",{type:t.type||t.blob.type,lastModified:t.lastModified})},d=(e.referenceEntries||[]).reduce((e,t)=>{if("url"===t.kind)return e.push(t.url),e;let r=s(t.slot);return r&&e.push(r),e},[]);return{startFrameImage:s(e.startFrameSlot),endFrameImage:s(e.endFrameSlot),referenceImages:d,missingLocalImages:l}}finally{t.close()}}async function rN(e){let t,r,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},a=Math.max(1,n.attempts??3),i=Math.max(0,n.retryDelayMs??150);for(let n=1;n<=a;n+=1){try{let r=await rF(e);if(t=r,!r.missingLocalImages)return r}catch(e){r=e}n<a&&i>0&&await new Promise(e=>setTimeout(e,i))}if(t)return t;throw r instanceof Error?r:new rx}async function rC(){if("u"<typeof indexedDB)return;let e=await ry();try{let t=e.transaction(rp,"readwrite"),r=rv(t),n=t.objectStore(rp);(await rb(n.index(rh).getAllKeys(IDBKeyRange.upperBound(Date.now()-36e5)))).forEach(e=>n.delete(e)),await r}finally{e.close()}}function rR(e){let t=(e||"").toLowerCase();return t.includes("insufficient")||t.includes("credits")?"insufficient_credits":t.includes("login")?"login_required":t.includes("concurrent")||t.includes("too many")?"too_many_concurrent_jobs":t.includes("nsfw")?"nsfw":t.includes("dispatch")?"dispatch_failed":t.includes("payment")?"payment_failed":t.includes("timeout")?"timeout":t.includes("metadata")?"metadata_read_failed":t.includes("upload")?"upload_failed":"unknown"}function rk(e,t){return{model_id:e.modelId,workspace_mode:"textToVideo"===t?"video-text":"video-image",...tC({mode:t,durationAuto:e.durationAuto}),video_duration:e.length,output_count:e.outputCount,has_reference_media:!!e.startFrameImage||e.referenceImages.length>0||e.referenceVideos.length>0,generate_audio:!!e.generateAudio}}let rA="16:9";function rS(e,t){if(0!==e.code)throw new ro(e);let r="string"==typeof e.data?.sessionId?e.data.sessionId:"";if(!r)throw Error("Video task response missing sessionId");return{kind:"acknowledged",billingMode:e.data?.billingMode,unlimited:e.data?.unlimited,sessionId:r,pollIntervalMs:"number"==typeof e.data?.pollIntervalMs?e.data.pollIntervalMs:2e3,requiredCredits:"number"==typeof e.data?.requiredCredits?e.data.requiredCredits:void 0,taskCount:"number"==typeof e.data?.taskCount?e.data.taskCount:void 0,source:t}}async function rM(e){let t=await e.text(),r=null;try{r=t?JSON.parse(t):null}catch{r=null}
1if(!r)throw Error(`Invalid video generation response (${e.status})`);return r}async function r_(e,t){let r=async t=>{let r=await fetch(`/api/video/submission/${encodeURIComponent(e)}`,{cache:"no-store",signal:t});if(404===r.status)return{kind:"not_found"};if(r.status>=400&&r.status<500&&![408,429].includes(r.status))throw new d.HA(r.status);if(!r.ok)throw Error(`Video submission lookup failed (${r.status})`);return rS(await rM(r),"reconcile")};return t?r(t):(0,d.EN)(r,8e3)}function rE(e){let t=(0,tK.SC)();t?.kind==="video"&&t.clientRequestId===e&&!1!==t.autoSubmit&&(0,tK.lP)({...t,autoSubmit:!1})}function rT(e){return e instanceof Error?e.message:"string"==typeof e?e:void 0}function rL(e,t){let r=e instanceof Error?e:Error("string"==typeof e?e:"Video input preparation failed");return Object.assign(r,{videoTaskCreateFailureStep:t}),r}function rV(e){return e instanceof File?"file":"url"}function rP(e){let t=e.filter(e=>e instanceof File);return{total:e.length,files:t.length,urls:e.length-t.length,totalBytes:t.reduce((e,t)=>e+t.size,0),mimeTypes:Array.from(new Set(t.map(e=>e.type||"unknown")))}}function rD(e){var t,r,n,a,i;console.error("[Video Task Create] Submission failed:",{message:rT(e.error)||"Video task creation failed",...(t=e.snapshot,r=e.snapshotMode,n=e.step,a=e.clientRequestId,i=e.sessionId,{stage:n.stage,mediaType:n.mediaType,slotName:n.slotName,sourceKind:n.sourceKind,fileSize:n.fileSize,fileType:n.fileType,httpStatus:n.httpStatus,responseMessage:n.responseMessage,hasSessionId:!!i,sessionId:i??void 0,clientRequestId:a,mode:r,modelId:t.modelId,aspectRatio:t.aspectRatio,duration:t.length,durationAuto:t.durationAuto,resolution:t.resolution,outputCount:t.outputCount,generateAudio:t.generateAudio,addEndFrame:t.addEndFrame,inputs:{startFrame:t.startFrameImage?{sourceKind:rV(t.startFrameImage)}:null,endFrame:t.endFrameImage?{sourceKind:rV(t.endFrameImage)}:null,referenceImages:rP(t.referenceImages),referenceVideos:rP(t.referenceVideos),referenceAudios:rP(t.referenceAudios)},client:{userAgent:window.navigator.userAgent,platform:window.navigator.platform,language:window.navigator.language,viewport:`${window.innerWidth}x${window.innerHeight}`,online:window.navigator.onLine,isMobile:/Android|iPhone|iPad|iPod|Mobile/i.test(window.navigator.userAgent)}})})}function rU(e){var t;let r,n=(r="string"==typeof(t=e.reason)?t.trim():"")?new Set(["Generation failed","Generation failed. Please try again.","Internal server error","Failed to create video generation task"]).has(r)?null:r:null;return n?(e.copy?.taskCreateFailedWithReason||"Video task was not created: {reason}").replace("{reason}",n):"read_video_metadata"===e.step.stage?e.copy?.taskCreateMetadataFailed||"Video task was not created because the browser could not read the video metadata.":"upload_input"===e.step.stage?e.copy?.taskCreateUploadFailed||"Video task was not created because the input upload failed.":"create_task_request"===e.step.stage||"parse_create_response"===e.step.stage?e.copy?.taskCreateSubmissionUncertain||"Task confirmation in progress. Please check your history later.":e.copy?.taskCreateFailed||"Video task was not created. Please check your connection or input media and try again."}function rO(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"720p";if("string"!=typeof e)return t;let r=e.trim().toLowerCase();return r?/^\d+p-(?:low|medium|high)$/.test(r)?r:/^\d+-(?:low|medium|high)$/.test(r)?r.replace(/^(\d+)-/,"$1p-"):/^\d+p$/.test(r)?r:/^\d+$/.test(r)?`${r}p`:r:t}function r$(e){return e?.provider==="veo"||!!e?.id.startsWith("veo-3.1-")}function rW(e,t){let r=(0,Q.getModelResolutions)(e??void 0);return t&&r.includes(t)?t:r[0]||"720p"}function rq(e,t){if(!r$(t)||"referenceToVideo"!==eh(e))return!1;let r=!1;return e.durationAuto&&(e.durationAuto=!1,r=!0),t?.ratios.includes(rA)&&e.aspectRatio!==rA&&(e.aspectRatio=rA,r=!0),(0,Q.getDurationsForResolution)(t??void 0,e.resolution).includes(8)&&8!==e.length&&(e.length=8,r=!0),e.referenceVideos.length>0&&(e.referenceVideos=[],r=!0),e.referenceAudios.length>0&&(e.referenceAudios=[],r=!0),r}function rH(e,t){let r=Number(e),n=Number(t);return!Number.isFinite(r)||!Number.isFinite(n)||r<=0||n<=0?null:{width:r,height:n}}function rB(e){let t=e.supportedRatios??[],r=e.fallback||t[0]||"16:9";if(e.explicitAspectRatio&&t.includes(e.explicitAspectRatio))return e.explicitAspectRatio;if(e.dimensions&&t.length>0){let{width:r,height:n}=e.dimensions,a=t.find(e=>(0,eb.c9)(r,n,e));return a||(0,eb.sp)(r,n,t)}return r}function rz(e){let{pageData:t,embedded:r=!1,stickyExpanded:n=!1,enableStickyComposer:o=!1,activeMediaMode:d,onMediaModeChange:y,hideModeSwitcherOnMobile:w=!1,modeSwitcherPlacement:F="tabs",sharedStickyComposerState:N,onStickyComposerStateChange:C,hideInternalResult:k=!1,redirectLoggedInGenerationsToApp:A=!1,externallyBusy:S=!1,initialModelId:M,modelSelectionRequest:_,lockedModelId:E,onSessionBatchesChange:T,onGenerationStarted:L,onComposerDraftChange:V,onLoginDraftBuilderReady:P,loginRestoreDraft:D,loginRestoreOmittedLocalReferences:U=!1,onLoginRestoreDraftConsumed:O,onUseAsVideoReferenceReady:$,embeddedMobileHeader:W}=e,{user:q,refreshUserCredits:H,setShowSignModal:B,setSignModalCallbackUrl:z,showInsufficientCreditsPrompt:G}=(0,tj.U)(),{trackEvent:X}=(0,tF.s)(),Y=(0,rr.Q)(),K=(0,x.useSearchParams)(),Z=(0,x.useRouter)(),ee=(0,x.usePathname)(),et=(0,tJ.rd)(),er=(0,b.Ym)(),en=(0,v.c)("uploadErrors"),ea=(0,v.c)("videoGenerator.validation"),ei=(0,v.c)("appWorkspace.videoBatch"),eo=(0,v.c)("promptEnhancement"),el=(0,v.c)("imageGenerator.mobilePanel"),es=(0,v.c)("imageGenerator"),eu=t.generator,ec=eu?.errors,em=eu?.hints,ev=er.startsWith("zh"),ey=em?.resumingGeneration||"Resuming your video generation in progress...",ew=em?.loadingModels||"Loading video models...",eI=em?.loadingFailed||"Failed to load video models. Please refresh the page.",ej=ec?.imageDataLoadFailed||"Failed to load image data.",eF=ec?.fileTypeNotSupported||"Unsupported file type. Please upload PNG/JPG/JP
1EG/WEBP.",eN=(0,h.useCallback)(()=>{q?.id&&H()},[H,q?.id]),eC=ec?.imageProcessingFailed||"Failed to process image.",eR=(0,h.useCallback)((e,r)=>{let n=e.trim(),a=(0,Q.getVideoPromptMaxLength)(r);return n?(0,t4.zl)(n)?!(n.length>a)||(R.oR.error(ea("promptTooLong",{max:a})),!1):(R.oR.error(ea("promptTooShort")),!1):(R.oR.error(t.generator?.errors?.promptRequired||"Prompt is required"),!1)},[t.generator?.errors?.promptRequired,ea]),{config:ek,isLoading:eA,error:eS}=(0,Q.useVideoCreditsConfig)(),eM=E??M,[e_,eE]=(0,h.useState)(()=>{let e=ek&&eM&&(0,Q.getModelById)(ek,eM)||ek&&(0,Q.getModelById)(ek,ek.defaultModelId)||ek?.models[0],t=(0,Q.getModelDurations)(e);return{mode:"textToVideo",modelId:e?.id||"",prompt:"",inputMode:"singleFrame",aspectRatio:e?.ratios[0]||"16:9",length:e?.defaultDurationSeconds??t[0]??5,durationAuto:!1,resolution:rW(e,ek?.defaultResolution),outputCount:1,generateAudio:e?.defaultGenerateAudio??!1,webSearch:!1,contentFilter:!0,outputFormat:e?.defaultOutputFormat??"mp4",enhancePrompt:!1,addEndFrame:!1,startFrameImage:null,endFrameImage:null,originalStartFrameImage:null,originalEndFrameImage:null,startFrameDimensions:null,endFrameDimensions:null,referenceImages:[],referenceVideos:[],referenceAudios:[]}}),eT=(0,h.useRef)(null),eL=(0,h.useRef)({}),eV=(0,h.useRef)({});(0,h.useEffect)(()=>{let e=e=>{let t=e.detail,r=(0,Q.getVideoPromptMaxLength)(ek?(0,Q.getModelById)(ek,e_.modelId):void 0),n="string"==typeof t?.prompt?t.prompt.slice(0,r):"";n.trim()&&("number"==typeof t?.exampleId&&"number"==typeof t?.index&&(eT.current=(0,tA.d5)({exampleId:t.exampleId,index:t.index,prompt:n,mediaMode:"video"})),ry.current+=1,eE(e=>({...e,mode:"textToVideo",inputMode:"singleFrame",prompt:n,addEndFrame:!1,startFrameImage:null,endFrameImage:null,originalStartFrameImage:null,originalEndFrameImage:null,startFrameDimensions:null,endFrameDimensions:null,referenceImages:[],referenceVideos:[],referenceAudios:[]})))};return window.addEventListener("raphael:video-example-prompt",e),()=>{window.removeEventListener("raphael:video-example-prompt",e)}},[ek,e_.modelId]),(0,h.useEffect)(()=>{eT.current&&!(0,tA.is)(eT.current,e_.prompt)&&(eT.current=null)},[e_.prompt]);let eP=(0,i.j)(q?.id),eD=(0,h.useRef)(d);(0,h.useEffect)(()=>{eD.current!==d&&(eD.current=d,eE(e=>"unlimited"===e.billingMode?{...e,billingMode:"credits"}:e))},[d]);let eU=l(e_.billingMode,eP,{kind:"video",modelId:e_.modelId,resolution:e_.resolution,durationSeconds:e_.length,outputCount:e_.outputCount});(0,h.useEffect)(()=>{"unlimited"===e_.billingMode&&"unlimited"!==eU&&eE(e=>({...e,billingMode:"credits"}))},[e_.billingMode,eU]);let[eO,e$]=(0,h.useState)(!1),[eW,eq]=(0,h.useState)(!1),[eH,eB]=(0,h.useState)(!1),[ez,eG]=(0,h.useState)(null),[eX,eY]=(0,h.useState)([]),[eQ,eJ]=(0,h.useState)([]),[eK,e0]=(0,h.useState)(!1),[e1,e5]=(0,h.useState)(0),[e3,e4]=(0,h.useState)(!0),[e8,e6]=(0,h.useState)(null),e9=(0,h.useRef)(null),e7=(0,h.useRef)(null),te=(0,h.useRef)(!1),[tt,tr]=(0,h.useState)(!1),[tn,ta]=(0,h.useState)(0),ti=(0,h.useRef)(new Map),[to,tl]=(0,h.useState)(null),[ts,td]=(0,h.useState)(!1),[tu,tc]=(0,h.useState)(null),[tm,tg]=(0,h.useState)(null),[tp,tf]=(0,h.useState)(null),[th,tx]=(0,h.useState)("crop"),[tb,tv]=(0,h.useState)(null),[ty,tw]=(0,h.useState)(!1),[tS,tM]=(0,h.useState)(void 0),[tD,tU]=(0,h.useState)(void 0),[tO,t$]=(0,h.useState)([]),tW=(0,h.useRef)(0),tq=(0,h.useRef)(null),rs=(0,h.useRef)("generate"),rp=(0,h.useRef)(null),rf=(0,h.useRef)(null),rh=(0,h.useRef)(null),rb=(0,h.useRef)(null),rv=(0,h.useRef)(null),ry=(0,h.useRef)(0),rw=(0,h.useRef)(new WeakMap),rI=(0,h.useRef)("u">typeof crypto&&"randomUUID"in crypto?crypto.randomUUID():`video-draft-${Date.now()}-${Math.random().toString(36).slice(2,10)}`),rF=(0,h.useRef)(function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:function(){for(var e=arguments.length,t=Array(e),r=0;r<e;r++)t[r]=arguments[r];return fetch(...t)},t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0x3200000,r=new Map;return{retain(e){let t=new Set(e);for(let e of r.keys())t.has(e)||r.delete(e)},get(n){let a=r.get(n);if(a)return a;let i=(async()=>{let a=new AbortController,i=setTimeout(()=>a.abort(),3e4);try{let r=await e(n,{signal:a.signal}),i=r.headers.get("content-type")?.split(";")[0]??"";if(!r.ok||!i.startsWith("image/")||Number(r.headers.get("content-length"))>t)throw await r.body?.cancel(),Error(rg);let o=r.body?.getReader();if(!o)throw Error(rg);let l=[],s=0;try{for(;;){let{done:e,value:r}=await o.read();if(e)break;if((s+=r.length)>t)throw Error(rg);l.push(new Uint8Array(r))}}finally{await o.cancel()}if(!s)throw Error(rg);let d="image/jpeg"===i?"jpg":i.split("/")[1].replace(/[^a-z0-9]/gi,"");return new File(l,`reference.${d}`,{type:i})}catch{throw r.delete(n),Error(rg)}finally{clearTimeout(i)}})();return r.set(n,i),i}}}()),rC=(0,h.useRef)(function(){let e,t,r=arguments.length>
10&&void 0!==arguments[0]?arguments[0]:rj,n=0,a=Promise.resolve();return i=>{if(e&&t&&Date.now()-n<18e5&&e.draftId===i.draftId&&e.startFrameImage===i.startFrameImage&&e.endFrameImage===i.endFrameImage&&e.referenceImages.length===i.referenceImages.length&&e.referenceImages.every((e,t)=>e===i.referenceImages[t]))return t;let o={...i,referenceImages:[...i.referenceImages]};e=o,n=Date.now();let l=a.catch(()=>void 0).then(()=>r(o));return a=l,t=l,l.catch(()=>{t===l&&(e=void 0,t=void 0)}),l}}()),rP=(0,h.useRef)(null),rz=(0,h.useRef)(null),rG=(0,h.useRef)(!1),rX=(0,h.useRef)(!1),rY=(0,h.useRef)(null),rQ=(0,h.useRef)(null),rJ=(0,h.useRef)(null),rK=(0,h.useRef)(!1),rZ=(0,h.useRef)(new Set),r0=(0,h.useRef)(!1),r1=(0,h.useRef)(!1),r2=(0,h.useRef)(void 0),r5=(0,h.useRef)(!1),r3=(0,h.useRef)(null),r4=(0,j.U)("(max-width: 639px)"),r8=(0,h.useCallback)(()=>{rK.current=!1,eq(!1),eB(!1)},[]),r6=(0,h.useMemo)(()=>eH&&t.generator?{...t,generator:{...t.generator,actions:{...t.generator.actions,generating:el("uploading")}}}:t,[eH,t,el]),r9=k||A&&!!q,r7=r&&o&&!r4,{panelRootRef:ne,floatingComposerRef:nt,showStickyComposer:nr,stickyComposerExpanded:nn,setStickyComposerExpanded:na}=(0,tz.N)({enabled:r7,activeMediaMode:d,expandOnMode:"video",initialState:N,onStateChange:C}),ni=ed(e_.startFrameImage),no=ed(e_.endFrameImage),nl=(0,h.useCallback)(function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[],n=arguments.length>3&&void 0!==arguments[3]&&arguments[3],a=arguments.length>4?arguments[4]:void 0,i=arguments.length>5?arguments[5]:void 0;return(0,rm.W)({outputCount:e,videoUrls:t,thumbnailUrls:r,isLoading:n,tasks:a,failure:i})},[]),ns=(0,h.useCallback)((e,t,r)=>["processing","pending_dispatch","pending_payment"].includes(e)?"processing":"partial"===e?"partial":"failed"===e||"dispatch_failed"===e||"payment_failed"===e||"credits_deduction_failed"===e?"failed":t.length>0&&t.length<r?"partial":"complete",[]),nd=(0,h.useCallback)((e,t)=>{t$(r=>r.map(r=>r.id===e?t(r):r))},[]),nu=(0,h.useCallback)(e=>{t$(t=>t.filter(t=>t.id!==e))},[]);(0,h.useEffect)(()=>{T?.(tO)},[T,tO]),(0,h.useEffect)(()=>()=>{e9.current&&clearTimeout(e9.current)},[]);let nc=(0,Q.getModelById)(ek,e_.modelId),nm=eh(e_),ng=r7?nn:n,np=e_.prompt.trim(),nf="imageToVideo"===nm?eu?.placeholders.promptImage:eu?.placeholders.promptText,nh=(0,h.useCallback)(e=>{tc(e.target),tg(e.source),tf(e.originalSource??null),tx(e.defaultMode??"crop"),tv(e.targetRatio??null),tw(e.lockRatio??!1),e.pendingGenerateId&&(tq.current=e.pendingGenerateId,rs.current=e.pendingAction??"generate"),td(!0)},[]),nx=(0,h.useCallback)(()=>{td(!1),tc(null),tg(null),tf(null),tx("crop"),tv(null),tw(!1),tq.current=null,rs.current="generate"},[]),nb=(0,h.useCallback)(async function(e,t){let r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;try{let r=await fetch(`/api/video/task/${e}`),n=await r.json();if(0!==n.code)throw Error(n.message||"Failed to get task status");let{status:a,tasks:i,hasNsfwError:o,refundedCredits:l,progress:s,errorCode:d,errorMessage:u}=n.data;"unlimited"===n.data.billingMode&&tl(e=>e?{...e,billingMode:"unlimited",unlimitedState:n.data.unlimited?.state}:e);let c="VIDEO_ASSET_NOT_READY"===d?ec?.assetNotReadyReason||"The generated video file could not be downloaded.":("string"==typeof u?u.trim():"")||void 0;if(rZ.current.has(e))return;if("number"==typeof s){e5(s);let t=r3.current;t&&t.sessionId===e?s>t.progress?r3.current={...t,progress:s,updatedAt:Date.now()}:!t.stalledTracked&&Date.now()-t.updatedAt>=3e4&&(r3.current={...t,stalledTracked:!0},X("video_gen_progress_stalled",{model_id:to?.modelId??"unknown",...tC({mode:to?.mode,durationAuto:to?.durationAuto}),progress_pct:s})):r3.current={sessionId:e,progress:s,updatedAt:Date.now(),stalledTracked:!1}}let m=i.filter(e=>"success"===e.meta.status&&e.assets.videoUrl),g=m.map(e=>e.assets.videoUrl),p=m.map(e=>e.assets.thumbnailUrl||"");g.length>0&&(eY(g),eJ(p));let f=rJ.current;if(f&&nd(f,e=>({...e,billingMode:n.data.billingMode??e.billingMode,unlimitedState:n.data.unlimited?.state??e.unlimitedState,progress:"number"==typeof s?s:e.progress,status:ns(a,g,e.outputCount),errorMessage:c??e.errorMessage,refundedCredits:"number"==typeof l&&l>0?l:e.refundedCredits,items:nl(e.outputCount,g,p,["processing","pending_dispatch","pen
1ding_payment"].includes(a),i)})),["processing","pending_dispatch","pending_payment"].includes(a)){let r=n.data.nextPollMs||t;e9.current=setTimeout(()=>{nb(e,r,0)},r)}else{rZ.current.add(e),e9.current&&(clearTimeout(e9.current),e9.current=null),eN(),r8(),e$(!1),e5(100),r3.current=null;let t={model_id:to?.modelId??"unknown",...tC({mode:to?.mode,durationAuto:to?.durationAuto}),output_count:g.length,task_status:a};if(g.length>0?(X("video_gen_task_success",t),(0,tk.S)(X,"milestone_first_video_generated",{model_id:to?.modelId??"unknown"})):X("video_gen_task_failure",{...t,failure_reason:rR(d||u||a)}),rJ.current&&(nd(rJ.current,e=>({...e,progress:100,status:ns(a,g,e.outputCount),items:nl(e.outputCount,g,p,!1,i)})),rJ.current=null),"dispatch_failed"===a)R.oR.error(ec?.dispatchFailedRefunded||ei("failure.taskLost.title"));else if("payment_failed"===a||"credits_deduction_failed"===a)R.oR.error(ec?.paymentFailed||ei("failure.unknown.title"));else if(o)R.oR.error(ec?.nsfwRefunded||ei("failure.nsfw.title"));else if("failed"===a)"VIDEO_ASSET_NOT_READY"===d?R.oR.error(ec?.assetNotReadyRefunded||ei("failure.outputSaveFailed.title")):R.oR.error(ec?.generationFailedRefunded||ei("failure.unknown.title"));else if("partial"===a){let e=ec?.partialFailedRefunded?ec.partialFailedRefunded.replace("{credits}",String(l||0)):ei("failure.unknown.title");R.oR.warning(e)}else R.oR.success(eu?.actions?.success||"Video generated successfully!")}}catch(i){let n=r+1,a=!Number.isInteger(n)||n<1?null:rn[n-1]??null;if(null!==a){console.warn("Polling error, retrying:",{sessionId:e,retryAttempt:n,retryDelayMs:a,error:i}),e9.current=setTimeout(()=>{nb(e,t,n)},a);return}console.error("Polling error after retries:",i),X("video_gen_status_check_failure",{model_id:to?.modelId??"unknown",...tC({mode:to?.mode,durationAuto:to?.durationAuto}),retry_attempts:r}),r3.current=null,r8(),e$(!1),rJ.current=null,R.oR.error(ec?.statusCheckFailed||"Failed to check generation status. Please refresh the page.")}},[nl,ec,eu?.actions?.success,to?.modelId,to?.mode,to?.durationAuto,ns,eN,r8,ei,ea,X,nd]);(0,h.useEffect)(()=>{let e=e=>{if(!(e instanceof CustomEvent))return;let t=e.detail,r=rJ.current;!(!eO||!r||"video"!==t.kind||t.historyId!==r||!t.status||!(0,t0.kn)(t.status)||rZ.current.has(r))&&(e9.current&&(clearTimeout(e9.current),e9.current=null),nb(r,2e3,0))};return window.addEventListener(tZ.KD,e),()=>{window.removeEventListener(tZ.KD,e)}},[eO,nb]),(0,h.useEffect)(()=>{if(!q)return;let e=ru();if(!e||rb.current===e.clientRequestId)return;rb.current=e.clientRequestId;let t=!1,r=null,n=Symbol(e.clientRequestId),a=function(){let e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];rv.current===n&&(rv.current=null,r8(),e||e$(!1))},i=async e=>{rK.current=!0,eq(!0),e$(!0),rv.current=n;let r=e.clientRequestId,i=(0,tK.SC)(),o=i?.kind==="video"&&i.clientRequestId===r?i:void 0,l=o?.autoSubmit===!0&&!o.confirmedHistoryId,s=o?.inputMode==="reference"?"referenceToVideo":o?.mode==="video-image"?"imageToVideo":o?.mode==="video-text"?"textToVideo":to?.mode,d={model_id:o?.modelId??to?.modelId??"unknown",workspace_mode:"mount_recovery",...tC({mode:s,durationAuto:o?.durationAuto??to?.durationAuto})};eG("reconciling"),rd({...e,attempt:2,phase:"reconciling",phaseStartedAt:new Date().toISOString()}),X("video_gen_submission_reconcile_started",{...d}),nd(r,e=>({...e,submissionPhase:"reconciling",hasServerSession:!1}));try{let n=await r_(r);if(t)return;if("not_found"===n.kind){if("unconfirmed"===e.phase)throw new ri;X("video_gen_submission_not_found",{...d}),l?(rf.current=r,eG("submitting"),rd({...e,attempt:1,phase:"submitting",phaseStartedAt:new Date().toISOString()}),nd(r,e=>({...e,submissionPhase:"submitting",hasServerSession:!1}))):(rc(r),rE(r),nu(r),rf.current=null,eG(null),R.oR.error(ec?.taskCreateFailed||"Video task was not created. Please check your connection or input media and try again.")),a();return}rc(r),rf.current=null,eG(null),a(!0),e$(!0),e5(0),rJ.current=n.sessionId,nd(r,e=>({...e,id:n.sessionId,submissionPhase:void 0,hasServerSession:!0})),X("video_gen_submission_recovered",{...d}),X("video_gen_submission_acknowledged",{...d,submission_source:"reconcile"}),e9.current&&clearTimeout(e9.current),e9.current=setTimeout(()=>{nb(n.sessionId,n.pollIntervalMs)},n.pollIntervalMs)}catch{if(t)return;rE(r),nu(r),rf.current=o?.confirmedHistoryId?null:r,eG("unconfirmed"),rd({...e,attempt:2,phase:"unconfirmed",phaseStartedAt:new Date().toISOString()}),a(),R.oR.error(ec?.taskCreateSubmissionUncertain||"Task confirmation in progress. Please check your history later."),X("video_gen_submission_unconfirmed",{...d})}},o=()=>
1{if(t)return;let l=ru();if(!l||l.clientRequestId!==e.clientRequestId){rb.current=null,eG(null),a();return}let s=function(e){if(e.activeClientRequestId===e.pending.clientRequestId)return{kind:"skip"};if("unconfirmed"===e.pending.phase)return{kind:"recover"};let t=Date.parse(e.pending.phaseStartedAt??e.pending.createdAt);if(!Number.isFinite(t))return{kind:"recover"};let r=t+("reconciling"===e.pending.phase?8e3:3e4)-e.nowMs;return r>0?{kind:"defer",delayMs:r}:{kind:"recover"}}({pending:l,activeClientRequestId:rh.current,nowMs:Date.now()});if("skip"===s.kind){rb.current=null;return}if("defer"===s.kind){rK.current=!0,eq(!0),e$(!0),rv.current=n,eG(l.phase),nd(l.clientRequestId,e=>({...e,submissionPhase:l.phase,hasServerSession:!1})),r=setTimeout(o,Math.min(s.delayMs,500));return}i(l)};return o(),()=>{t=!0,r&&clearTimeout(r),rv.current===n&&(rv.current=null,rb.current=null,r8(),e$(!1))}},[q?.id]);let nv="imageToVideo"===nm&&e_.addEndFrame&&!e_.endFrameImage;(0,h.useEffect)(()=>{let e=nc?.id,t=!!e&&!0===eV.current[e],r=(0,J.kt)({currentInputMode:e_.inputMode,preferredInputMode:e?eL.current[e]??e_.inputMode:e_.inputMode,supportsReferenceMode:(0,Q.supportsVideoReferenceMode)(nc,e_.resolution),isAutoFallbackActive:t});e&&(r.isAutoFallbackActive?(eL.current[e]="reference",eV.current[e]=!0):t&&(eV.current[e]=!1)),eE(e=>{let t=(nc?.maxImageCount??1)>0,n=nc?.maxReferenceImageCount??0,a=nc?.maxReferenceVideoCount??0,i=(nc?.maxReferenceAudioCount??0)>0,o=!1,l={...e};l.inputMode===e_.inputMode&&l.inputMode!==r.inputMode&&(l.inputMode=r.inputMode,o=!0),(0,Q.supportsVideoReferenceMode)(nc,l.resolution);let s=(0,Q.getVideoAudioPolicy)(nc,l.resolution);nc?.audioSelectable===!1&&l.generateAudio?(l.generateAudio=!1,o=!0):"always"!==s||l.generateAudio?"unsupported"===s&&l.generateAudio&&(l.generateAudio=!1,o=!0):(l.generateAudio=!0,o=!0),!nc?.supportsWebSearch&&l.webSearch&&(l.webSearch=!1,o=!0),!nc?.supportsAutoDuration&&l.durationAuto&&(l.durationAuto=!1,o=!0),nc?.supportsContentFilter||l.contentFilter||(l.contentFilter=!0,o=!0),nc?.outputFormats?.length&&!nc.outputFormats.includes(l.outputFormat)&&(l.outputFormat=nc.defaultOutputFormat??"mp4",o=!0),!i&&l.referenceAudios.length>0&&(l.referenceAudios=[],o=!0),l.referenceImages.length>n&&(l.referenceImages=l.referenceImages.slice(0,n),o=!0),l.referenceVideos.length>a&&(l.referenceVideos=l.referenceVideos.slice(0,a),o=!0),rq(l,nc)&&(o=!0),!t&&(l.startFrameImage||l.originalStartFrameImage)&&(l.startFrameImage=null,l.originalStartFrameImage=null,o=!0),!t&&(l.endFrameImage||l.originalEndFrameImage||l.addEndFrame)&&(l.endFrameImage=null,l.originalEndFrameImage=null,l.addEndFrame=!1,o=!0),!l.startFrameImage&&!l.addEndFrame&&(l.endFrameImage||l.originalEndFrameImage)&&(l.endFrameImage=null,l.originalEndFrameImage=null,o=!0);let d=(0,J.Y)(l,nc);(l.inputMode!==d.inputMode||l.addEndFrame!==d.addEndFrame||l.endFrameImage!==d.endFrameImage||l.originalEndFrameImage!==d.originalEndFrameImage||l.endFrameDimensions!==d.endFrameDimensions)&&(Object.assign(l,d),o=!0);let u=eh(l),c=(0,J.Gf)(nc,u,l.aspectRatio,l.resolution);return l.aspectRatio!==c&&(l.aspectRatio=c,o=!0),l.mode!==u&&(l.mode=u,o=!0),o?l:e})},[nc?.maxImageCount,nc?.maxReferenceImageCount,nc?.maxReferenceAudioCount,nc?.maxReferenceVideoCount,nc?.id,nc?.provider,nc?.supportsReferenceMode,nc?.supportsAutoDuration,nc?.audioSelectable,nc?.supportsWebSearch,nc?.supportsContentFilter,nc?.outputFormats,e_.startFrameImage,e_.originalStartFrameImage,e_.endFrameImage,e_.originalEndFrameImage,e_.addEndFrame,e_.aspectRatio,e_.inputMode,e_.length,e_.mode,e_.resolution,e_.referenceAudios.length,e_.referenceImages.length,e_.referenceVideos.length]),(0,h.useEffect)(()=>{if(!ek||0===ek.models.length)return;let e=eM&&(0,Q.getModelById)(ek,eM)||(0,Q.getModelById)(ek,ek.defaultModelId)||ek.models[0];if(!e)return;let t=eM||ek.defaultModelId||e.id,r=E?e_.modelId!==e.id:!e_.modelId||rY.current!==t,n=rW(e,ek.defaultResolution),a=!r&&!r1.current&&e_.modelId===e.id&&e_.resolution!==n;if(!r&&!a)return;rY.current=t;let i=(0,Q.getModelDurations)(e),o=(0,Q.getDurationsForResolution)(e,n);eE(t=>({...t,modelId:e.id,aspectRatio:r?e.ratios[0]||"16:9":t.aspectRatio,resolution:n,length:r?e.defaultDurationSeconds??i[0]??5:o.includes(t.length)?t.length:o[0]||i[0]||5,durationAuto:!r&&!!e.supportsAutoDuration&&t.durationAuto,generateAudio:r?e.defaultGenerateAudio??!1:t.generateAudio,webSearch:!r&&t.webSearch,contentFilter:!!r||t.contentFilter,outputFormat:r?e.defaultOutputFormat??"mp4":t.outputFormat}))},[ek,E,eM,e_.modelId,e_.resolution]),(0,h.useEffect)(()=>{!nv&&eK&&e0(!1)},[nv,eK]),(0,h.useEffect)(()=>
1{if(!ek||0===ek.models.length)return;let e=k?(0,tK.SC)():null;if(D||e?.kind==="video"&&!(0,t2.qt)(e)&&!(0,t5.jz)(e))return;let t=tT();if(!t)return;let r=!1;return(async()=>{let e=ry.current;try{let n=t.localImageDraft?await rN(t.localImageDraft):void 0;if(r||e!==ry.current)return;if(n?.missingLocalImages)return void R.oR.error(es("referenceLimits.restoreFailed"));ry.current+=1,t.localImageDraft&&(rI.current=t.localImageDraft.draftId),t_(t,ti.current);let a=(0,Q.getModelById)(ek,eM||t.modelId);if(!a)return;r0.current="boolean"==typeof t.enhancePrompt;let i=(0,Q.getModelResolutions)(a),o=(0,Q.getModelDurations)(a);"string"==typeof t.resolution&&i.includes(t.resolution)&&(r1.current=!0);let l=rH(t.startFrameWidth,t.startFrameHeight),s=rH(t.endFrameWidth,t.endFrameHeight);eE(e=>{let r=!!(n?.startFrameImage||t.startFrameImageUrl),d="reference"===t.inputMode||"referenceToVideo"===t.mode,u="number"==typeof t.outputCount&&Number.isFinite(t.outputCount)?t.outputCount:1,c=Math.min(4,Math.max(1,Math.floor(u))),m=!0===a.supportsAutoDuration&&!0===t.durationAuto,g=m?a.autoDurationReservationSeconds??10:o.includes(t.lengthSeconds)?t.lengthSeconds:o[0],p=i.includes(t.resolution)?t.resolution:i[0],f=rB({supportedRatios:a.ratios,explicitAspectRatio:t.aspect,dimensions:r?l:null,fallback:a.ratios[0]}),h=!!a.supportsAudio&&!1!==a.audioSelectable&&!!t.generateAudio,x=a.maxImageCount>1&&!!t.enableEndFrame;return{...e,mode:d?"referenceToVideo":r?"imageToVideo":"textToVideo",inputMode:d?"reference":x?"startEndFrame":"singleFrame",modelId:a.id,prompt:"string"==typeof t.prompt?t.prompt:"",aspectRatio:f,length:g,durationAuto:m,resolution:p,outputCount:c,generateAudio:h,enhancePrompt:t.enhancePrompt??!1,addEndFrame:x,startFrameImage:n?.startFrameImage??t.startFrameImageUrl??null,endFrameImage:n?.endFrameImage??t.endFrameImageUrl??null,originalStartFrameImage:null,originalEndFrameImage:null,startFrameDimensions:l,endFrameDimensions:s,referenceImages:n?.referenceImages??(Array.isArray(t.referenceImageUrls)?t.referenceImageUrls.filter(Boolean):[]),referenceAudios:Array.isArray(t.referenceAudioUrls)?t.referenceAudioUrls.filter(Boolean):[],referenceVideos:[]}})}catch{return}})(),()=>{r=!0}},[ek,eM,es,k,D]);let[ny,nw]=(0,h.useState)(0);(0,h.useEffect)(()=>{let e=()=>{ry.current+=1,r5.current=!1,rP.current=null,nw(e=>e+1)};return window.addEventListener(tZ.Eb,e),()=>{window.removeEventListener(tZ.Eb,e)}},[]),(0,h.useEffect)(()=>{if(!k)return;let e=(0,tK.SC)();if(!e||"video"!==e.kind||!e.localImageDraft||(0,t2.qt)(e)||(0,t5.jz)(e)||rP.current?.draftId===e.localImageDraft.draftId&&rP.current.revision===ry.current&&rP.current.draftIdentity===JSON.stringify(e))return;let t=!1;return(async()=>{let r=++ry.current,n=JSON.stringify(e),a=()=>!t&&r===ry.current&&JSON.stringify((0,tK.SC)())===n,i=e.localImageDraft;if(i)try{let t=await rN(i);if(!a())return;if(t.missingLocalImages){(0,tK.lP)({...e,autoSubmit:!1}),R.oR.error(es("referenceLimits.restoreFailed"));return}rP.current={draftId:i.draftId,images:t,revision:r,draftIdentity:n},ta(e=>e+1)}catch(t){if(!a())return;console.warn("Failed to restore workspace video draft images:",t),(0,tK.lP)({...e,autoSubmit:!1}),R.oR.error(es("referenceLimits.restoreFailed"))}})(),()=>{t=!0}},[k,es,ny]),(0,h.useEffect)(()=>{if(!k||!ek||0===ek.models.length||r5.current)return;let e=(0,tK.SC)();if(!e||"video"!==e.kind||(0,t2.qt)(e)||(0,t5.jz)(e))return;let t=e.localImageDraft&&rP.current?.draftId===e.localImageDraft.draftId&&rP.current.revision===ry.current&&rP.current.draftIdentity===JSON.stringify(e)?rP.current.images:void 0;if(e.localImageDraft&&!t)return;ry.current+=1;let r=!!e.confirmedHistoryId;rf.current=r?null:e.clientRequestId??null,t_(e,ti.current);let n=(0,Q.getModelById)(ek,e.modelId||"")||(0,Q.getModelById)(ek,ek.defaultModelId)||ek.models[0];if(!n)return;let a=(0,Q.getModelResolutions)(n),i=(0,Q.getModelDurations)(n),o="string"==typeof e.resolution&&a.includes(e.resolution),l=rH(e.startFrameWidth,e.startFrameHeight),s=rH(e.endFrameWidth,e.endFrameHeight),d=rB({supportedRatios:n.ratios,explicitAspectRatio:e.aspectRatio,dimensions:"video-image"===e.mode?l:null,fallback:n.ratios[0]||"16:9"}),u=e.resolution&&a.includes(e.resolution)?e.resolution:a[0]||ek.defaultResolution||"720p",c=!0===n.supportsAutoDuration&&!0===e.durationAuto,m=c?n.autoDurationReservationSeconds??10:"number"==typeof e.duration&&i.includes(e.duration)?e.duration:n.defaultDurationSeconds??i[0]??5,g="number"==typeof e.outputCount&&Number.isFinite(e.outputCount)?Math.min(4,Math.max(1,Math.floor(e.outputCount))):1,f=!r&&(e.autoSubmit??!0),h="reference"===e.inputMode,x=h?"referenceToVideo":"video-image"===e.mode?"imageToVideo":"textToVideo",b=Array.isArray(e.referenceVideoUrls)?e.referenceVideoUrls.filter(
1Boolean):[];Array.isArray(e.referenceVideoDurations)&&(0,p.HX)(b,e.referenceVideoDurations),r5.current=!0,rY.current=eM||ek.defaultModelId||n.id,r0.current="boolean"==typeof e.enhancePrompt,o&&(r1.current=!0),e.localImageDraft?(rI.current=e.localImageDraft.draftId,rz.current=e.localImageDraft.draftId):(0,tK.HZ)(),rG.current=!!e.skipRatioCheck;let v={mode:x,inputMode:h?"reference":e.addEndFrame?"startEndFrame":"singleFrame",modelId:n.id,prompt:e.prompt||"",aspectRatio:d,length:m,durationAuto:c,resolution:u,outputCount:g,generateAudio:!!n.supportsAudio&&!1!==n.audioSelectable&&!!e.generateAudio,webSearch:!!n.supportsWebSearch&&!!e.webSearch,contentFilter:!n.supportsContentFilter||!1!==e.contentFilter,outputFormat:e.outputFormat&&n.outputFormats?.includes(e.outputFormat)?e.outputFormat:n.defaultOutputFormat??"mp4",enhancePrompt:e.enhancePrompt??!1,addEndFrame:n.maxImageCount>1&&!!e.addEndFrame,startFrameImage:t?.startFrameImage??e.startFrameImageUrl??null,endFrameImage:t?.endFrameImage??e.endFrameImageUrl??null,originalStartFrameImage:null,originalEndFrameImage:null,startFrameDimensions:l,endFrameDimensions:s,referenceImages:t?t.referenceImages:Array.isArray(e.referenceImageUrls)?e.referenceImageUrls.filter(Boolean):[],referenceVideos:b,referenceAudios:Array.isArray(e.referenceAudioUrls)?e.referenceAudioUrls.filter(Boolean):[]};rp.current=f?v:null,eE({...v,billingMode:"credits"}),tr(f)},[ek,k,tn,ny]),(0,h.useEffect)(()=>{!r9&&q&&ek&&0!==ek.models.length?te.current||(te.current=!0,(async()=>{try{let e=await fetch("/api/video/processing"),t=await e.json();if(0!==t.code||!t.data?.task)return void e4(!1);let{task:r}=t.data;e6(r.sessionId),e$(!0),e5(r.progress||0);let n=r.params&&"object"==typeof r.params?r.params:{},a=Array.isArray(r.inputImages)?r.inputImages:[],i=Array.isArray(n.imageUrls)?n.imageUrls.filter(e=>"string"==typeof e):[],o=Array.isArray(n.videoUrls)?n.videoUrls.filter(e=>"string"==typeof e):[],l=Array.isArray(n.audioUrls)?n.audioUrls.filter(e=>"string"==typeof e):[],s=a.find(e=>"start"===e.type)?.url||null,d=a.find(e=>"end"===e.type)?.url||null,u=[s,d].filter(e=>!!e),c="referenceToVideo"===n.mode?"referenceToVideo":a.length>0?"imageToVideo":n.mode||"textToVideo";if(tl({billingMode:n.billingMode,unlimitedState:n.unlimited?.state,prompt:r.prompt||"",modelId:r.modelId||"",mode:c,duration:n.durationSeconds||5,durationAuto:!0===n.durationAuto,aspectRatio:n.aspect||"16:9",resolution:rO(n.resolution),outputCount:n.outputCount||(Array.isArray(r.tasks)?r.tasks.length:1),enhancePrompt:!!n.enhancedPrompt,enhancedPrompt:"string"==typeof n.enhancedPrompt?n.enhancedPrompt:void 0,startFrameImage:s}),r.prompt&&eE(e=>({...e,prompt:r.prompt,modelId:r.modelId||e.modelId,length:n.durationSeconds||e.length,durationAuto:!0===n.durationAuto})),r.tasks&&Array.isArray(r.tasks)){let e=r.tasks.filter(e=>"success"===e.meta.status&&e.assets.videoUrl),t=e.map(e=>e.assets.videoUrl),a=e.map(e=>e.assets.thumbnailUrl||"");t.length>0&&(eY(t),eJ(a));let d=`video-resumed-${r.sessionId}`;rJ.current=d,t$(e=>{let m=(0,Q.getModelById)(ek,r.modelId||""),g=n.durationSeconds||5,p=rO(n.resolution),f=n.outputCount||(Array.isArray(r.tasks)?r.tasks.length:1),h=(0,Q.calculateCredits)(m,p,g,!!n.generateAudio,{hasReferenceVideoInput:"referenceToVideo"===c&&Array.isArray(n.referenceVideoDurations)&&n.referenceVideoDurations.length>0,referenceVideoInputSeconds:Array.isArray(n.referenceVideoDurations)?n.referenceVideoDurations.reduce((e,t)=>e+("number"==typeof t?t:0),0):0,referenceImageInputCount:"referenceToVideo"===c&&"number"==typeof n.referenceImageCount?n.referenceImageCount:0,inputImageCount:"number"==typeof n.inputImageCount?n.inputImageCount:Array.isArray(n.imageUrls)?n.imageUrls.length:0}),x={id:d,kind:"video",mode:"textToVideo"===c?"video-text":"video-image",status:"processing",hasServerSession:!0,prompt:r.prompt||"",modelId:r.modelId||"",modelLabel:m?.label||r.modelId||"",duration:g,durationAuto:!0===n.durationAuto,aspectRatio:n.aspect||"16:9",outputCount:f,resolution:p,billingMode:n.billingMode,unlimitedState:n.unlimited?.state,credit
1Cost:"unlimited"===n.billingMode?0:null!=h?h*f:void 0,progress:r.progress||0,inputThumbnailUrl:("referenceToVideo"===c?i[0]:s)||void 0,inputImageUrls:u.length>0?u:void 0,inputMode:"referenceToVideo"===c?"reference":u.length>1?"startEndFrame":"singleFrame",referenceImageUrls:i.length>0?i:void 0,referenceVideoUrls:o.length>0?o:void 0,referenceAudioUrls:l.length>0?l:void 0,referenceVideoDurations:Array.isArray(n.referenceVideoDurations)?n.referenceVideoDurations.filter(e=>"number"==typeof e&&Number.isFinite(e)):void 0,generateAudio:!!n.generateAudio,webSearch:!!n.webSearch,contentFilter:"boolean"==typeof n.contentFilter?n.contentFilter:void 0,outputFormat:"mov"===n.outputFormat||"mp4"===n.outputFormat?n.outputFormat:void 0,enhancePrompt:!!n.enhancedPrompt,createdAt:new Date(r.createdAt||Date.now()).toISOString(),items:nl(f,t,a,!0,r.tasks)};return[...e.filter(e=>e.id!==d),x]})}let m=r.pollIntervalMs||2e3;e9.current=setTimeout(()=>{nb(r.sessionId,m)},m),R.oR.info(ey)}catch(e){console.error("Failed to check processing task:",e)}finally{e4(!1)}})()):e4(!1)},[ek,nl,r9,nb,ey,q]),(0,h.useEffect)(()=>{let e=async()=>{let e=K.get("ref");if(!e)return;let t=`ai-video-generator-image-${e}`,r=localStorage.getItem(t);if(!r)return void console.warn("No image data found for ref token:",e);try{let e,t=JSON.parse(r);t.width&&t.height&&nc?.ratios?.length&&(e=(0,eb.sp)(t.width,t.height,nc.ratios)),eE(r=>({...r,startFrameImage:t.url,originalStartFrameImage:null,startFrameDimensions:rH(t.width,t.height),prompt:"string"==typeof t.prompt?t.prompt:"",...e&&{aspectRatio:e}}));let n=window.location.pathname;Z.replace(n,{scroll:!1})}catch(e){console.error("Failed to load image data from localStorage:",e),R.oR.error(ej)}};K.get("ref")&&nc&&e()},[ej,K,Z,nc]),(0,h.useEffect)(()=>{if(!ek||rX.current||!ef.some(e=>!!K.get(e)?.trim()))return;let e=K.get("prompt"),t=K.get("model"),r=K.get("aspect"),n=K.get("resolution"),a=K.get("length"),i=K.get("reference"),o=eM&&(0,Q.getModelById)(ek,eM)||(0,Q.getModelById)(ek,t||"")||(0,Q.getModelById)(ek,ek.defaultModelId);if(!o)return;let l=eM?o:t&&(0,Q.getModelById)(ek,t)||o,s=r&&l.ratios.includes(r)?r:l.ratios[0]||"16:9",d=n?rO(n):void 0,u=d&&(0,Q.getModelResolutions)(l).includes(d)?d:(0,Q.getModelResolutions)(l)[0]||ek.defaultResolution||"720p",c=(0,Q.getDurationsForResolution)(l,u),m=!0===l.supportsAutoDuration&&"auto"===a,g=Number(a),p=m?l.autoDurationReservationSeconds??10:Number.isFinite(g)&&c.includes(g)?g:l.defaultDurationSeconds??c[0]??(0,Q.getModelDurations)(l)[0]??5,f=e?e.slice(0,(0,Q.getVideoPromptMaxLength)(l)):"",h=i||null;ry.current+=1,eE(e=>{let t={...e,modelId:l.id,prompt:f||e.prompt,aspectRatio:s,resolution:u,length:p,durationAuto:m};return h&&l.maxImageCount>0&&(t.startFrameImage=h,t.originalStartFrameImage=null,t.startFrameDimensions=null),t.mode=eh(t),t}),rX.current=!0},[ek,eM,K]);let nI=e=>{if(ry.current+=1,"unlimited"===e.billingMode&&(e.outputCount=1),"enhancePrompt"in e&&(r0.current=!0),e.inputMode&&nc?.id&&(eL.current[nc.id]=e.inputMode,eV.current[nc.id]=!1),e.aspectRatio&&e.aspectRatio!==e_.aspectRatio&&!(e.modelId&&e.modelId!==e_.modelId)&&(r2.current=e.aspectRatio),e.resolution&&e.resolution!==e_.resolution){r1.current=!0;let t=e.modelId&&ek?(0,Q.getModelById)(ek,e.modelId)??nc:nc,r=(0,Q.getDurationsForResolution)(t,e.resolution);r.includes(e_.length)||(e.length=t?.defaultDurationSeconds??r[0]??5)}eE(t=>{let r={...t,...e};if(e.modelId&&e.modelId!==t.modelId&&ek){let n=(0,Q.getModelById)(ek,e.modelId);if(n){"aspectRatio"in e||(r.aspectRatio=(0,re.G8)({currentAspect:t.aspectRatio,currentAspectSource:r2.current?"user":"system",preferredUserAspect:r2.current,nextAspectOptions:n.ratios,fallbackDimensions:r.startFrameDimensions??void 0}));let a=(0,Q.getModelResolutions)(n),i=(0,Q.getModelDurations)(n);i.includes(r.length)||(r.length=n.defaultDurationSeconds??i[0]??5),a.includes(r.resolution)||(r.resolution=a[0]||"720p"),n.supportsAutoDuration||(r.durationAuto=!1),n.supportsAudio&&!1!==n.audioSelectable?r.generateAudio=n.defaultGenerateAudio??r.generateAudio:r.generateAudio=!1,n.maxImageCount<=0?(r.startFrameImage=null,r.originalStartFrameImage=null,r.endFrameImage=null,r.originalEndFrameImage=null,r.startFrameDimensions=null,r.endFrameDimensions=null,r.addEndFrame=!1):n.maxImageCount<=1&&r.addEndFrame&&(r.addEndFrame=!1,r.endFrameImage=null,r.originalEndFrameImage=null,r.endFrameDimensions=null),n.supportsReferenceMode||(r.referenceImages=[],r.referenceVideos=[],r.referenceAudios=[],"reference"===r.inputMode&&(r.inputMode="singleFrame")),(n.maxReferenceAudioCount??0)<=0&&(r.referenceAudios=[]),(n.maxReferenceVideoCount??0)<=0&&(r.referenceVideos=[]);let o=n.maxReferenceImageCount??0;r.referenceImages.length>o&&(r.referenceImages=r.referenceImages.slice(0,o))}}"inputMode"in e&&("singleFrame"===e.inputMode?(r.addEndFrame=!1,r.endFrameImage=null,r.originalEndFrameImage=null,r.endFrameDimensions=null,r.referenceImages=[],r.referenceVideos=[],r.referenceAudios=[]):"startEndFrame"===e.inputMode?(r.addEndFrame=!0,r.referenceImages=[],r.referenceVideos=[],r.referenceAudios=[]):"reference"===e.inputMode&&(r.addEndFrame=!1,r.startFrameImage=null,r.endFrameImage=null,r.originalStartFrameImage=null,r.originalEndFrameImage=null,r.startFrameDimensions=null,r.endFrameDimensions=null)),"addEndFrame"in e&&!1===e.addEndFrame?(r.endFrameImage=null,r.originalEndFrameImage=null,r.endFrameDimensions=null,"inputMode"in e||(r.inputMode="singleFrame")):"addEndFrame"in e&&!0===e.addEndFrame&&!("inputMode"in e)&&(r.inputMode="startEndFrame"),"startFrameImage"in e&&(e.startFrameImage?"startFrameDimensions"in e||(r.startFrameDimensions=e.startFrameImage===t.startFrameImage?t.startFrameDimensions:null):r.startFrameDimensions=null),"endFrameImage"in e&&(e.endFrameImage?"endFrameDimensions"in e||(r.endFrameDimensions=e.endFrameImage===t.endFrameImage?t.endFrameDimensions:null):r.endFrameDimensions=null);let n=ek?(0,Q.getModelById)(ek,r.modelId):nc;return rq(r,n),Object.assign(r,(0,J.Y)(r,n)),r.mode=eh(r),r})};(0,h.useEffect)(()=>
1{if(!ek||E||!_||rQ.current===_.requestId)return;let e=(0,Q.getModelById)(ek,_.modelId);if(!e)return;let t="unlimited"===_.billingMode?"minimax-h3-turbo"===e.id?"480p-low":"480p-medium":rW(e,ek.defaultResolution),r=(0,Q.getDurationsForResolution)(e,t);rQ.current=_.requestId,nI({modelId:e.id,aspectRatio:e.ratios[0]||"16:9",resolution:t,length:r[0]||5,..._.billingMode?{billingMode:_.billingMode,outputCount:1}:{},durationAuto:!1})},[ek,nI,E,_]);let nj=(0,h.useCallback)(async e=>{if(!e.imageUrl)return;ry.current+=1;let t=(0,tK.WI)(e);t.sourceHistoryId&&ti.current.set(e.imageUrl,t.sourceHistoryId);let r=ek?.models.find(e=>e.id===e_.modelId&&e.maxImageCount>0)??ek?.models.find(e=>e.maxImageCount>0)??nc;r2.current=void 0,e0(!1),eE(t=>{let n=(0,Q.getModelResolutions)(r),a=n.includes(t.resolution)?t.resolution:n[0]||t.resolution,i=(0,Q.getDurationsForResolution)(r,a),o=i.includes(t.length)?t.length:r?.defaultDurationSeconds??i[0]??(0,Q.getModelDurations)(r)[0]??t.length,l=rH(e.imageWidth,e.imageHeight),s=rB({supportedRatios:r?.ratios,dimensions:l,fallback:r?.ratios.includes(t.aspectRatio)?t.aspectRatio:r?.ratios[0]||t.aspectRatio}),d={...t,mode:"imageToVideo",modelId:r?.id||t.modelId,prompt:"string"==typeof e.prompt?e.prompt.trim():"",aspectRatio:s,length:o,durationAuto:r?.supportsAutoDuration===!0&&t.durationAuto,resolution:a,generateAudio:!!r?.supportsAudio&&!1!==r.audioSelectable&&t.generateAudio,addEndFrame:!1,startFrameImage:e.imageUrl,endFrameImage:null,originalStartFrameImage:null,originalEndFrameImage:null,startFrameDimensions:l,endFrameDimensions:null,inputMode:"singleFrame",referenceImages:[],referenceVideos:[],referenceAudios:[]};return d.mode=eh(d),d})},[nc,ek,e_.modelId]);(0,h.useEffect)(()=>($?.(nj),()=>{$?.(null)}),[nj,$]);let nF=(0,h.useCallback)(async e=>new Promise((t,r)=>{let n=new FileReader;n.onload=()=>t(n.result),n.onerror=r,n.readAsDataURL(e)}),[]),nN=(0,h.useCallback)(async e=>{let t=[],r=0;for(let n of e){if("string"==typeof n){t.push(n);continue}if(!(r+n.size>2097152))try{t.push(await nF(n)),r+=n.size}catch(e){console.error("Failed to convert audio draft source:",e)}}return t},[nF]),nC=(0,h.useCallback)(async function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:e_,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},[r,n]=await Promise.all([rC.current({draftId:rI.current,startFrameImage:e.startFrameImage,endFrameImage:e.endFrameImage,referenceImages:e.referenceImages}),nN(e.referenceAudios)]),a=function(e,t){let r=e.filter(e=>!!e&&!e?.startsWith("data:")&&!e?.startsWith("blob:"));if(0===r.length||r.some(e=>!t.has(e)))return;let n=new Set(r.map(e=>t.get(e)));return 1===n.size?n.values().next().value:void 0}([r.startFrameImageUrl,r.endFrameImageUrl,...r.referenceImageUrls??[],...e.referenceVideos.filter(e=>"string"==typeof e),...n],ti.current);return{mode:eh(e),inputMode:e.inputMode,prompt:e.prompt,modelId:e.modelId,clientRequestId:t.clientRequestId,sourceHistoryId:a,aspect:e.aspectRatio,lengthSeconds:e.length,durationAuto:e.durationAuto,resolution:e.resolution,outputCount:e.outputCount,generateAudio:e.generateAudio,webSearch:e.webSearch,contentFilter:e.contentFilter,outputFormat:e.outputFormat,enhancePrompt:e.enhancePrompt,enableEndFrame:e.addEndFrame,startFrameImageUrl:r.startFrameImageUrl,endFrameImageUrl:r.endFrameImageUrl,referenceImageUrls:r.referenceImageUrls,referenceAudioUrls:n.length>0?n:void 0,localImageDraft:r.localImageDraft,startFrameWidth:e.startFrameDimensions?.width,startFrameHeight:e.startFrameDimensions?.height,endFrameWidth:e.endFrameDimensions?.width,endFrameHeight:e.endFrameDimensions?.height}},[nN,e_]),nR=(0,h.useCallback)(async(e,t)=>{let r=await nC(e,{clientRequestId:t.clientRequestId}),n="textToVideo"===r.mode?"video-text":"video-image",a=e.referenceVideos.filter(e=>"string"==typeof e);return{kind:"video",mode:n,inputMode:r.inputMode,prompt:r.prompt,autoSubmit:t.autoSubmit,sourceHistoryId:r.sourceHistoryId,preferredHistoryScope:"all",modelId:r.modelId,clientRequestId:r.clientRequestId,aspectRatio:r.aspect,resolution:r.resolution,duration:r.lengthSeconds,durationAuto:r.durationAuto,outputCount:r.outputCount,generateAudio:r.generateAudio,webSearch:r.webSearch,contentFilter:r.contentFilter,outputFormat:r.outputFormat,enhancePrompt:r.enhancePrompt,addEndFrame:r.enableEndFrame,startFrameImageUrl:r.startFrameImageUrl,endFrameImageUrl:r.endFrameImageUrl,referenceImageUrls:r.referenceImageUrls,referenceVideoUrls:a.length>0?a:void 0,referenceAudioUrls:r.referenceAudioUrls,localImageDraft:r.localImageDraft,startFrameWidth:r.startFrameWidth,startFrameHeight:r.startFrameHeight,endFrameWidth:r.endFrameWidth,endFrameHeight:r.endFrameHeight,skipRatioCheck:t.skipRatioCheck}},[nC]),nk=(0,h.useCallback)(async()=>nR(e_,{autoSubmit:!1}),[nR,e_]);(0,h.useEffect)(()=>(P?.(nk),()=>{P?.(null)}),[nk,P]);let nA=(0,h.useCallback)((e,t)=>{if(!ek||0===ek.models.length)return!1;t_(e,ti.current);let r=(0,Q.getModelById)(ek,E||e.modelId||"")||(0,Q.getModelById)(ek,ek.defaultModelId)||ek.models[0];if(!r)return!1;ry.current+=1;let n=(0,Q.getModelResolutions)(r),a=(0,Q.getModelDurations)(r),i="string"==typeof e.resolution&&n.includes(e.resolution),o=rH(e.startFrameWidth,e.startFrameHeight),l=rH(e.endFrameWidth,e.endFrameHeight),s="reference"===e.inputMode,d=t?.startFrameImage??e.startFrameImageUrl??null,u=t?.endFrameImage??e.endFrameImageUrl??null,c=t?t.referenceImages:Array.isArray(e.referenceImageUrls)?e.referenceImageUrls.filter(
1Boolean):[],m=s?"referenceToVideo":"video-image"===e.mode||d?"imageToVideo":"textToVideo",g=Array.isArray(e.referenceVideoUrls)?e.referenceVideoUrls.filter(Boolean):[];Array.isArray(e.referenceVideoDurations)&&(0,p.HX)(g,e.referenceVideoDurations);let f=rB({supportedRatios:r.ratios,explicitAspectRatio:e.aspectRatio,dimensions:"imageToVideo"===m?o:null,fallback:r.ratios[0]||"16:9"}),h=e.resolution&&n.includes(e.resolution)?e.resolution:n[0]||ek.defaultResolution||"720p",x=!0===r.supportsAutoDuration&&!0===e.durationAuto,b=x?r.autoDurationReservationSeconds??10:"number"==typeof e.duration&&a.includes(e.duration)?e.duration:r.defaultDurationSeconds??a[0]??5,v="number"==typeof e.outputCount&&Number.isFinite(e.outputCount)?Math.min(4,Math.max(1,Math.floor(e.outputCount))):1;return rY.current=eM||ek.defaultModelId||r.id,r0.current="boolean"==typeof e.enhancePrompt,i&&(r1.current=!0),eE(t=>({...t,mode:m,inputMode:s?"reference":e.addEndFrame?"startEndFrame":"singleFrame",modelId:r.id,prompt:e.prompt||"",aspectRatio:f,length:b,durationAuto:x,resolution:h,outputCount:v,generateAudio:!!r.supportsAudio&&!1!==r.audioSelectable&&!!e.generateAudio,webSearch:!!r.supportsWebSearch&&!!e.webSearch,contentFilter:!r.supportsContentFilter||!1!==e.contentFilter,outputFormat:e.outputFormat&&r.outputFormats?.includes(e.outputFormat)?e.outputFormat:r.defaultOutputFormat??"mp4",enhancePrompt:e.enhancePrompt??!1,addEndFrame:r.maxImageCount>1&&!!e.addEndFrame,billingMode:"credits",startFrameImage:d,endFrameImage:u,originalStartFrameImage:null,originalEndFrameImage:null,startFrameDimensions:o,endFrameDimensions:l,referenceImages:c,referenceVideos:g,referenceAudios:Array.isArray(e.referenceAudioUrls)?e.referenceAudioUrls.filter(Boolean):[]})),!0},[ek,E,eM]),nS=(0,h.useCallback)(async(e,t,r)=>{if(!r)return;let n=(0,p.dZ)(e.referenceVideos);if("referenceToVideo"===t&&e.referenceVideos.length>0&&n<=0)try{n=(await Promise.all(e.referenceVideos.map(e=>(0,p.QX)(e)))).reduce((e,t)=>e+t,0)}catch{return}let a=(0,Q.calculateCredits)(r,e.resolution,e.length,e.generateAudio,{hasReferenceVideoInput:"referenceToVideo"===t&&e.referenceVideos.length>0,referenceVideoInputSeconds:n,referenceImageInputCount:"referenceToVideo"===t?e.referenceImages.length:0,inputImageCount:ex(e,t),webSearch:r.supportsWebSearch&&"textToVideo"===t&&e.webSearch,relaxedContent:r.supportsContentFilter&&!1===e.contentFilter});return null!=a?a*e.outputCount:void 0},[]);(0,h.useEffect)(()=>{let e,t=!1;return(async()=>{e_.startFrameImage?"string"==typeof e_.startFrameImage?tM(e_.startFrameImage):(e=URL.createObjectURL(e_.startFrameImage),t||tM(e)):tM(void 0)})(),()=>{t=!0,e&&URL.revokeObjectURL(e)}},[e_.startFrameImage]),(0,h.useEffect)(()=>{let e,t=!1;return(async()=>{e_.addEndFrame&&e_.endFrameImage?"string"==typeof e_.endFrameImage?tU(e_.endFrameImage):(e=URL.createObjectURL(e_.endFrameImage),t||tU(e)):tU(void 0)})(),()=>{t=!0,e&&URL.revokeObjectURL(e)}},[e_.addEndFrame,e_.endFrameImage]),(0,h.useEffect)(()=>{if(!V)return;let e=!1,t=e=>{if(!e)return Promise.resolve(void 0);if("string"==typeof e)return e.startsWith("blob:")?fetch(e).then(e=>e.blob()).then(e=>nF(new File([e],"preview",{type:e.type}))):Promise.resolve(e);let t=rw.current.get(e);return t||(t=nF(e),rw.current.set(e,t),t.catch(()=>rw.current.delete(e))),t};return Promise.all([nR(e_,{autoSubmit:!1}),t(e_.startFrameImage),t(e_.addEndFrame?e_.endFrameImage:null),Promise.all(e_.referenceImages.map(t))]).then(t=>{let[r,n,a,i]=t;e||V({...r,startFrameImageUrl:n,endFrameImageUrl:a,referenceImageUrls:i.filter(e=>!!e)})}).catch(()=>{}),()=>{e=!0}},[nR,nF,V,e_]),(0,h.useEffect)(()=>{if(q||!e_.startFrameImage&&!e_.endFrameImage&&0===e_.referenceImages.length&&0===e_.referenceAudios.length||!ek||0===ek.models.length)return;let e=!1,t=ry.current;return(async()=>{try{let r=await nC();e||t!==ry.current||tE(r)}catch(e){console.warn("Failed to persist video login draft images:",e)}})(),()=>{e=!0}},[nC,ek,e_.endFrameImage,e_.referenceAudios.length,e_.referenceImages.length,e_.startFrameImage,q]);let nM=(0,h.useCallback)(async e=>{if(e.startsWith("data:"))return e;if(e.startsWith("http://")||e.startsWith("https://")){let t=new URL(e);if(!t.hostname.includes("localhost")&&!t.hostname.includes("127.0.0.1"))return e}try{let t=await fetch(e);if(!t.ok)throw Error(`Failed to fetch image: ${t.status}`);let r=await t.blob();return new Promise((e,t)=>
1{let n=new FileReader;n.onload=()=>e(n.result),n.onerror=t,n.readAsDataURL(r)})}catch(e){throw console.error("Failed to convert URL to base64:",e),e}},[]),n_=(0,h.useCallback)((e,t)=>{let r="start"===t?e.startFrameDimensions:e.endFrameDimensions;return rH(r?.width,r?.height)},[]),nE=(0,h.useCallback)(e=>!!r$(nc)&&!(e.size<=p.Lx)&&(R.oR.error((0,eg.A)({code:"file_too_large",mediaType:"image",fileName:e.name,maxSize:"10MB"},er,en)),!0),[nc,er,en]),nT=(0,h.useCallback)(async(e,t)=>{ry.current+=1;let r=(0,eb.Wl)(t,nc?.id,e_.resolution);if(!r.ok)return void R.oR.error("type"===r.error?eF:(0,eg.A)({code:"file_too_large",mediaType:"image",maxSize:`${((0,c.LQ)(nc?.id,e_.resolution).maxBytes??0)/1048576}MB`},er,en));try{let{width:r,height:n}=await (0,eb.vX)(t),a=nc?.id;if((0,f.fe)(a)){let e=(0,c.LQ)(a,e_.resolution),i=e.minAspectRatio,o=e.maxAspectRatio;if(!(0,f.Fl)(r,n,i,o))return void R.oR.error((0,eg.A)({code:"aspect_ratio_invalid",mediaType:"image",fileName:t.name,minAspectRatio:i,maxAspectRatio:o},er,en))}let i=nc?.ratios||[];if(!tQ(nc,e_.aspectRatio)||0===i.length){let r=(await (0,m.n)(t,(0,c.LQ)(nc?.id,e_.resolution))).file;if(nE(r))return;let n=await (0,eb.vX)(r);eE(a=>"end"===e?{...a,endFrameImage:r,originalEndFrameImage:t,endFrameDimensions:n}:{...a,startFrameImage:r,originalStartFrameImage:t,startFrameDimensions:n});return}for(let a of i)if((0,eb.c9)(r,n,a)){let r=(await (0,m.n)(t,(0,c.LQ)(nc?.id,e_.resolution))).file;if(nE(r))return;let n=await (0,eb.vX)(r);eE(i=>"end"===e?{...i,aspectRatio:a,endFrameImage:r,originalEndFrameImage:t,endFrameDimensions:n}:{...i,aspectRatio:a,startFrameImage:r,originalStartFrameImage:t,startFrameDimensions:n});return}let o=(0,eb.sp)(r,n,i);eE(e=>({...e,aspectRatio:o})),nh({target:e,source:t,originalSource:t,defaultMode:"crop"})}catch(e){console.error("Failed to process image:",e),R.oR.error(e instanceof g.Qv?(0,eg.A)(e.detail,er,en):eC)}},[nc?.ratios,nc,er,en,eF,eC,nE,nh,e_.aspectRatio,e_.resolution]),nL=(0,h.useCallback)(e=>{let t="start"===e?e_.startFrameImage:e_.endFrameImage,r="start"===e?e_.originalStartFrameImage:e_.originalEndFrameImage;if(!t)return;let n=r||t;nh({target:e,source:n,originalSource:r?null:n,defaultMode:"crop"})},[e_.startFrameImage,e_.endFrameImage,e_.originalStartFrameImage,e_.originalEndFrameImage,nh]),nV=(0,h.useCallback)(async function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:e_,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"generate";if("imageToVideo"!==eh(t))return!0;let n=t.aspectRatio,a=(0,Q.getModelById)(ek,t.modelId)||nc;if(t.addEndFrame&&t.startFrameImage&&t.endFrameImage)try{let i=n_(t,"start")??await (0,eb.vX)(t.startFrameImage),o=n_(t,"end")??await (0,eb.vX)(t.endFrameImage),l=function(e,t,r,n){if("adaptive"!==e||"adaptive"!==t.toLowerCase()||!r||!n||r.width<=0||r.height<=0||n.width<=0||n.height<=0)return null;let a=(0,eb.$f)(r.width,r.height);return(0,eb.c9)(n.width,n.height,a)?null:a}(a?.imageRatioPolicy,n,i,o);if(l){let n=t.originalEndFrameImage||t.endFrameImage;return nh({target:"end",source:n,originalSource:t.originalEndFrameImage?null:n,defaultMode:"crop",targetRatio:l,lockRatio:!0,pendingGenerateId:e,pendingAction:r}),!1}}catch(e){return console.error("Failed to compare frame dimensions:",e),R.oR.error(e instanceof g.Qv?(0,eg.A)(e.detail,er,en):eC),!1}if(!tQ(a,n))return!0;let i=async(t,a,i,o)=>{if(!t)return!0;try{let{width:e,height:r}="string"==typeof t&&i?i:await (0,eb.vX)(t);if((0,eb.c9)(e,r,n))return!0}catch(e){return console.error("Failed to read image dimensions:",e),R.oR.error(e instanceof g.Qv?(0,eg.A)(e.detail,er,en):eC),!1}let l=a||t;return nh({target:o,source:l,originalSource:a?null:l,defaultMode:"crop",pendingGenerateId:e,pendingAction:r}),!1};return!!await i(t.startFrameImage,t.originalStartFrameImage,n_(t,"start"),"start")&&(!t.addEndFrame||!!await i(t.endFrameImage,t.originalEndFrameImage,n_(t,"end"),"end"))},[n_,nc,ek,eC,er,nh,e_,en]),nP=(0,h.useCallback)(()=>{r8(),nx()},[r8,nx]),nD=(0,h.useCallback)(()=>{setTimeout(()=>{let e=e7.current;if(!e)return;let t=e.getBoundingClientRect(),r=window.scrollY+t.top-100;window.scrollTo({top:Math.max(0,r),behavior:"smooth"})},100)},[]),nU=(0,h.useCallback)(e=>{let t=A?"public":"app",r=(0,t1.$I)(e,t),n=ee||window.location.pathname;if(!n)return r;let a=`/${er}`,i=n===a?"/":n.startsWith(`${a}/`)?n.slice(a.length):n;if("/app"===i)return r;let o=(0,t1.YB)(i),l=o?(0,t1.Un)(o):null;return o&&!l?.startsWith("video")?r:"/"===i?`${n}?mode=video`:n},[er,ee,A]),nO=(0,h.useCallback)(async function(e,t){var r,n;let a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"generate";if(t!==tW.current)return void r8();let i=eh(e),o="redirect"===a,l=ru(),s=rf.current??("u">typeof crypto&&"randomUUID"in crypto?crypto.randomUUID():`video-${Date.now()}-${Math.random().toString(36).slice(2,10)}`),d=l?.clientRequestId===s?l:null;rf.current=null;let f=o?null:s,h="textToVideo"===i?"video-text":"video-image",x=e.referenceImages.find(e=>"string"==typeof e)??null,b="string"==typeof e.startFrameImage?e.startFrameImage:tS,v=e.addEndFrame&&"string"==typeof e.endFrameImage?e.endFrameImage:e.addEndFrame?tD:void 0;f&&(rJ.current=f),o||tl({billingMode:e.billingMode,unlimitedState:"unlimited"===e.billingMode?"waiting":void 0,prompt:e.prompt,modelId:e.modelId,mode:i,duration:e.length,durationAuto:e.durationAuto,aspectRatio:e.aspectRatio,resolution:e.resolution,outputCount:e.outputCount,enhancePrompt:e.enhancePrompt,startFrameImage:"referenceToVideo"===i?e.referenceImages[0]??null:e.startFrameImage});let y=(0,Q.getModelById)(ek,e.modelId),w=r$(y),I="referenceToVideo"===i&&e.referenceVideos.length>0,j=(0,p.dZ)(e.referenceVideos),F=(0,Q.calculateCredits)(y,e.resolution,e.length,e.generateAudio,{hasReferenceVideoInput:I,referenceVideoInputSeconds:j,referenceImageInputCount:"referenceToVideo"===i?e.referenceImages.length:0,inputImageCount:ex(e,i)}),N="unlimited"===e.billingMode?0:null!=F?F*e.outputCount:void 0,C=rk(e,i);o&&X("video_gen_start",C);let k={stage:"prepare_input"},A=null,S=f;if(!o){let t=[b,v].filter(e=>!!e),r="referenceToVideo"===i&&x?[x]:void 0;eq(!1),t$(n=>[...n.filter(e=>e.id!==s),{id:s,kind:"video",mode:h,status:"processing",prompt:e.prompt,modelId:e.modelId,clientRequestId:s,submissionPhase:"submitting",hasServerSession:!1,modelLabel:y?.label||e.modelId,duration:e.length,durationAuto:e.durationAuto,aspectRatio:e.aspectRatio,outputCount:e.outputCount,resolution:e.resolution,billingMode:e.billingMode,unlimitedState:"unlimited"===e.billingMode?"waiting":void 0,creditCost:N,progress:0,inputThumbnailUrl:x??b,inputImageUrls:"referenceToVideo"!==i&&t.length>0?t:void 0,inputMode:e.inputMode,referenceImageUrls:r,generateAudio:e.generateAudio,webSearch:e.webSearch,contentFilter:e.contentFilter,outputFormat:e.outputFormat,enhancePrompt:e.enhancePrompt,createdAt:new Date().toISOString(),items:nl(e.outputCount,[],[],!0)}]),X("video_gen_start",C),r3.current={sessionId:f||s,progress:0,updatedAt:Date.now(),stalledTracked:!1},e$(!0),e5(0),eY([]),eJ([])}try{let t;if("referenceToVideo"===i){let t=(0,Q.getModelById)(ek,e.modelId),r
1=await (0,p.TI)({images:e.referenceImages,videos:e.referenceVideos,audios:e.referenceAudios,modelId:e.modelId,resolution:e.resolution,imageLimit:t?.maxReferenceImageCount??0,videoLimit:t?.maxReferenceVideoCount??0,audioLimit:t?.maxReferenceAudioCount??0,totalLimit:t?.maxReferenceTotalCount});e={...e,referenceImages:r.images,referenceVideos:r.videos,referenceAudios:r.audios}}let a=new Map,l=[],g=[],x=[],I=[],j=[e.startFrameImage,e.endFrameImage,...e.referenceImages,...e.referenceVideos,...e.referenceAudios].some(e=>e instanceof File);eB(j);let F=async(t,r,n)=>{let o={stage:"upload_input",mediaType:r,slotName:n,sourceKind:"file",fileSize:t.size,fileType:t.type||"unknown"};try{let o,l="image"===r?(await (0,m.n)(t,(0,c.LQ)(e.modelId,e.resolution))).file:t,d=await (0,p.px)({file:l,modelId:e.modelId,resolution:e.resolution,clientRequestId:s,mediaType:r,slotName:n,toolType:"textToVideo"===i?"text-to-video":"image-to-video",surfaceType:(0,tY.qA)(ee)?"home":void 0,onAuthorization:e=>{o=e}});return o&&a.set(d,o),d}catch(e){throw rL(e,{...o,httpStatus:function(e){if("object"!=typeof e||null===e)return;let t=e.status;return"number"==typeof t&&Number.isFinite(t)?t:void 0}(e),responseMessage:rT(e)})}},M=async(e,t,r)=>{try{let n=await nM(e);if("image"===t&&!/^https?:\/\//i.test(n)){let e=await rF.current.get(n);return await F(e,"image",r)}return n}catch(e){throw rL(e,{...{stage:"read_input_url",mediaType:t,slotName:r,sourceKind:"url"},responseMessage:rT(e)})}},_=async(e,t)=>{let r={stage:"read_video_metadata",mediaType:"video",slotName:t,sourceKind:rV(e),fileSize:e instanceof File?e.size:void 0,fileType:e instanceof File?e.type||"unknown":void 0};try{return await (0,p.QX)(e)}catch(e){throw rL(e,{...r,responseMessage:rT(e)})}};if("referenceToVideo"===i){let[t,r,n]=await Promise.all([Promise.all(e.referenceImages.map((e,t)=>{let r=`reference-image-${t+1}`;return e instanceof File?F(e,"image",r):M(e,"image",r)})),w?Promise.resolve([]):Promise.all(e.referenceVideos.map(async(e,t)=>{let r=`reference-video-${t+1}`,[n,a]=await Promise.all([_(e,r),e instanceof File?F(e,"video",r):M(e,"video",r)]);return{duration:n,url:a}})),w?Promise.resolve([]):Promise.all(e.referenceAudios.map((e,t)=>{let r=`reference-audio-${t+1}`;return e instanceof File?F(e,"audio",r):M(e,"audio",r)}))]);l.push(...t),g.push(...r.map(e=>{let{url:t}=e;return t})),I.push(...r.map(e=>{let{duration:t}=e;return t})),x.push(...n)}else if("imageToVideo"===i&&e.startFrameImage){if(e.startFrameImage instanceof File)l.push(await F(e.startFrameImage,"image","input-start"));else{let t=await M(e.startFrameImage,"image","input-start");l.push(t)}if(e.addEndFrame&&e.endFrameImage)if(e.endFrameImage instanceof File)l.push(await F(e.endFrameImage,"image","input-end"));else{let t=await M(e.endFrameImage,"image","input-end");l.push(t)}}eB(!1),f&&nd(f,e=>({...e,inputImageUrls:"referenceToVideo"!==i&&l.length>0?l:e.inputImageUrls,referenceImageUrls:"referenceToVideo"===i&&l.length>0?l:e.referenceImageUrls,referenceVideoUrls:"referenceToVideo"===i&&g.length>0?g:e.referenceVideoUrls,referenceAudioUrls:"referenceToVideo"===i&&x.length>0?x:e.referenceAudioUrls,referenceVideoDurations:I.length>0?I:e.referenceVideoDurations}));let E=e.prompt,T=r0.current?"manual":"automatic",V=(0,t8.t8)({enabled:e.enhancePrompt,prompt:E});if(e.enhancePrompt&&!V&&(0,tR.sX)({mediaType:"video",promptMode:T,modelId:e.modelId,trackEvent:X}),V){let e=await (0,tR.St)({prompt:E,mediaType:"video",promptMode:T,maxAcceptedEnhancedPromptLength:(0,Q.getVideoPromptMaxLength)(y),trackEvent:X});E=e.enhancedPrompt,(0,tR.r7)(e)&&R.oR.warning(eo("fallbackNotice"),{duration:5e3})}E!==e.prompt&&f&&nd(f,e=>({...e,enhancedPrompt:E})),o||E===e.prompt||tl(e=>e?{...e,enhancedPrompt:E}:e);let P={media_sources:[["image",l],["video",g],["audio",x]].flatMap(e=>{let[t,r]=e;return r.map((e,r)=>a.has(e)?{mediaType:t,index:r,authorization:a.get(e)}:(0,u.o)(e,t,r,ti.current.get(e)))}),billing_mode:e.billingMode??"credits",prompt:e.prompt,...E!==e.prompt?{enhanced_prompt:E}:{},model_id:e.modelId,aspect:e.aspectRatio,duration_seconds:e.length,duration_auto:e.durationAuto,resolution:e.resolution.replace("p",""),output_count:e.outputCount,mode:i,image_urls:l.length>0?l:void 0,video_urls:g.length>
10?g:void 0,reference_video_durations:I.length>0?I:void 0,audio_urls:x.length>0?x:void 0,generate_audio:e.generateAudio,model_params:"textToVideo"===i&&e.webSearch?{web_search:!0}:void 0,content_filter:e.contentFilter,output_format:(0,Q.resolveVideoOutputFormatForRequest)(y,e.outputFormat),client_request_id:s},D=o?await nR(e,{autoSubmit:!1,clientRequestId:s}):void 0;rh.current=s;try{let e=await rl({clientRequestId:s,timeoutMs:3e4,onPhaseChange:e=>{eG(e),"retrying"===e?X("video_gen_submission_retry",{...C}):"reconciling"===e&&X("video_gen_submission_reconcile_started",{...C}),f&&nd(f,t=>({...t,submissionPhase:e,hasServerSession:!1})),rd({clientRequestId:s,createdAt:d?.createdAt??new Date().toISOString(),phaseStartedAt:new Date().toISOString(),attempt:"submitting"===e?1:2,phase:e})},attempt:async e=>{var t;let r,{signal:n}=e;k={stage:"create_task_request"};let a=await fetch("/api/video/generate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(P),signal:n});k={stage:"parse_create_response",httpStatus:a.status};let i=await rM(a);if(k={stage:"create_task_response",httpStatus:a.status,responseMessage:i.message},t=a.status,r=i.data?.sessionId,t>=500&&t<=599&&("string"!=typeof r||!r.trim()))throw Error(`Retryable video generation response (${a.status})`);return rS(i,"attempt")},reconcile:r_});eE(e=>({...e,billingMode:"credits"})),t={code:0,message:"ok",data:{billingMode:e.billingMode,unlimited:e.unlimited,sessionId:e.sessionId,pollIntervalMs:e.pollIntervalMs,requiredCredits:e.requiredCredits,taskCount:e.taskCount}},"reconcile"===e.source&&X("video_gen_submission_recovered",{...C}),X("video_gen_submission_acknowledged",{...C,submission_source:e.source}),rc(s),eG(null)}catch(e){if(e instanceof ro)rc(s),eG(null),t=e.response;else throw e}finally{rh.current===s&&(rh.current=null)}if(0!==t.code){let a,l;rE(s);let d="string"==typeof t.data?.sessionId?t.data.sessionId:null;if(f&&d){let e="REFERENCE_MEDIA_REQUIRED"===t.message?ec?.referenceMediaRequired:ec?.failed;A=d,S=d,nd(f,t=>({...t,id:d,status:"failed",errorMessage:e||ec?.failed||void 0,items:nl(t.outputCount,[],[],!1,void 0,{errorCode:"GENERATION_FAILED",errorMessage:e||ec?.failed||void 0})})),rJ.current===f&&(rJ.current=null)}else f&&(nu(f),rJ.current===f&&(rJ.current=null));let u=(0,t6.t8)(t,{locale:er,copy:{detailed:ec?.insufficientCreditsDetailed}}),c=(r=t.message,"PAID_MODEL_REQUIRED"===r||"PAID_MODEL_CREDITS_REQUIRED"===r?"paid_model_required":null),m=!!d||!u&&!c&&(a=(n=t).message,l=n.code,"LOGIN_REQUIRED"!==a&&"TOO_MANY_CONCURRENT_JOBS"!==a&&"INSUFFICIENT_CREDITS"!==a&&"PAID_MODEL_REQUIRED"!==a&&"PAID_MODEL_CREDITS_REQUIRED"!==a&&402!==l);d&&eN(),m&&rD({error:Error(t.message||"Video task create request failed"),snapshot:e,snapshotMode:i,step:k,clientRequestId:s,sessionId:d}),c?(X("video_gen_task_failure",{...rk(e,i),failure_reason:c}),X("credits_insufficient_shown",{...rk(e,i),required_credits:N}),G({...(0,t9.yx)(t,{requiredCredits:N,analytics:{toolType:"video-generator",modelId:e.modelId,generationType:i,generationMode:tN(i),durationMode:e.durationAuto?"auto":"fixed",surfaceType:"video_generator",triggerStage:"api_response"}}),reason:c})):u?(X("video_gen_task_failure",{...rk(e,i),failure_reason:"insufficient_credits"}),X("credits_insufficient_shown",{...rk(e,i),required_credits:N}),G((0,t9.yx)(t,{requiredCredits:N,analytics:{toolType:"video-generator",modelId:e.modelId,generationType:i,generationMode:tN(i),durationMode:e.durationAuto?"auto":"fixed",surfaceType:"video_generator",triggerStage:"api_response"}}))):t.message===rg?R.oR.error(es("referenceLimits.restoreFailed")):"REFERENCE_MEDIA_REQUIRED"===t.message?(X("video_gen_task_failure",{...rk(e,i),failure_reason:"reference_media_required"}),R.oR.error(ec?.referenceMediaRequired||ec?.failed)):"TOO_MANY_CONCURRENT_JOBS"===t.message?(X("video_gen_task_failure",{...rk(e,i),failure_reason:"too_many_concurrent_jobs"}),R.oR.error(ec?.tooManyConcurrentJobs||"You have too many videos generating. Please wait for them to complete.")):"LOGIN_REQUIRED"===t.message?(X("video_gen_task_failure",{...rk(e,i),failure_reason:"login_required"}),z(nU(h)),B(!0,"video_generation")):d?(X("video_gen_task_failure",{...rk(e,i),failure_reason:"dispatch_failed"}),R.oR.error(ec?.dispatchFailedRefunded||ei("failure.taskLost.title"))):(X("video_gen_task_failure",{...rk(e,i),failure_reason:rR(t.message)}),R.oR.error(rU({step:k,reason:t.message,copy:ec}))),r8(),o||e$(!1);return}let U="string"==typeof t.data?.sessionId?t.data.sessionId:"",O="number"==typeof t.data?.pollIntervalMs?t.data.pollIntervalMs:2e3;if(!U)throw Error("Video task response missing sessionId");if(A=U,(0,tK.HZ)(),eN(),f&&(S=U,nd(f,e=>({...e,id:U,submissionPhase:void 0,hasServerSession:!0,progress:"number"==typeof e.progress?Math.max(e.progress,5):5})),rJ.current===f&&(rJ.current=U),L?.(),nD()),tL(),o){let t="imageToVideo"===i?l[0]??b:void 0,r="imageToVideo"===i&&e.addEndFrame?l[1]??v:void 0,n="referenceToVideo"===i&&l.length>0?l:void 0,a="referenceToVideo"===i&&g.length>
10?g:void 0,o="referenceToVideo"===i&&x.length>0?x:void 0;(0,tK.lP)({kind:"video",mode:h,inputMode:e.inputMode,prompt:e.prompt,autoSubmit:!1,confirmedHistoryId:U,preferredHistoryScope:"all",modelId:e.modelId,clientRequestId:s,aspectRatio:e.aspectRatio,resolution:e.resolution,duration:e.length,durationAuto:e.durationAuto,outputCount:e.outputCount,generateAudio:e.generateAudio,webSearch:e.webSearch,contentFilter:e.contentFilter,outputFormat:e.outputFormat,enhancePrompt:e.enhancePrompt,addEndFrame:e.addEndFrame,startFrameImageUrl:D?.startFrameImageUrl??t,endFrameImageUrl:D?.endFrameImageUrl??r,referenceImageUrls:D?.referenceImageUrls??n,localImageDraft:D?.localImageDraft,referenceVideoUrls:a,referenceAudioUrls:o,referenceVideoDurations:I.length>0?I:void 0,startFrameWidth:e.startFrameDimensions?.width,startFrameHeight:e.startFrameDimensions?.height,endFrameWidth:e.endFrameDimensions?.width,endFrameHeight:e.endFrameDimensions?.height}),(0,t3.tG)("latest"),et.push((0,t1.s6)(h,U),{scroll:!1});return}e9.current=setTimeout(()=>{nb(U,O)},O)}catch(l){let t=l instanceof ra,r=l instanceof ri;if(t)X("video_gen_submission_not_found",{model_id:e.modelId,workspace_mode:h}),rc(s),eG(null),rE(s);else if(r){rE(s),X("video_gen_submission_unconfirmed",{model_id:e.modelId,workspace_mode:h}),rf.current=s,eG("unconfirmed");let t=ru();rd({clientRequestId:s,createdAt:t?.createdAt??new Date().toISOString(),phaseStartedAt:new Date().toISOString(),attempt:2,phase:"unconfirmed"})}let n=function(e){if("object"==typeof e&&null!==e)return e.videoTaskCreateFailureStep}(l);n&&(k=n),rD({error:l,snapshot:e,snapshotMode:i,step:k,clientRequestId:s,sessionId:A}),r||X("video_gen_task_failure",{...rk(e,i),failure_reason:rR(rT(l))});let a=l instanceof Error&&l.message===rg?es("referenceLimits.restoreFailed"):l instanceof g.Qv?(0,eg.A)(l.detail,er,en):t?ec?.taskCreateFailed||"Video task was not created. Please check your connection or input media and try again.":r?ec?.taskCreateSubmissionUncertain||"Task confirmation in progress. Please check your history later.":rU({step:k,reason:rT(l),copy:ec});A||rE(s),f&&!A?(r?nd(f,e=>({...e,submissionPhase:"unconfirmed",hasServerSession:!1})):nd(f,e=>({...e,status:"failed",submissionPhase:void 0,hasServerSession:!1,errorMessage:a,items:nl(e.outputCount,[],[],!1,void 0,{errorCode:"VIDEO_TASK_CREATE_FAILED",errorMessage:a})})),rJ.current===f&&(rJ.current=null)):S&&(nu(S),rJ.current===S&&(rJ.current=null)),R.oR.error(a),r8(),o||e$(!1)}},[ek,nl,ec,er,et,L,nb,tD,tS,eN,r8,nu,nU,nD,z,B,tK.lP,ei,X,nd,en,nM]),n$=(0,h.useCallback)(async(e,t)=>{if(tu){ry.current+=1;try{let r=(await (0,m.n)(e,(0,c.LQ)(nc?.id,e_.resolution))).file;if(nE(r))return;let n=await (0,eb.vX)(r),a=tq.current,i=rs.current,o="extend"===t?r:tp,l=null;eE(e=>{let t={...e};return"end"===tu?(t.endFrameImage=r,t.endFrameDimensions=n,null!=o&&(t.originalEndFrameImage=o)):(t.startFrameImage=r,t.startFrameDimensions=n,null!=o&&(t.originalStartFrameImage=o)),l=t,t}),nx(),tq.current=null,a&&l&&a===tW.current&&(rK.current=!0,eq(!0),await nV(a,l,i)?await nO(l,a,i):r8())}catch(e){console.error("Failed to apply crop:",e),r8(),R.oR.error(e instanceof g.Qv?(0,eg.A)(e.detail,er,en):eC)}}},[nc?.id,e_.resolution,er,en,nO,tp,tu,nV,eC,nE,r8,nx]),nW=async e=>{if(!rK.current&&!eW&&!eO&&!S){rK.current=!0,eq(!0);try{let r=++tW.current,n=e??e_,a={...n,billingMode:l(e?"credits":n.billingMode,eP,{kind:"video",modelId:n.modelId,resolution:n.resolution,durationSeconds:n.length,outputCount:n.outputCount})},i=eh(a),o=(0,Q.getModelById)(ek,a.modelId),s=A&&q?"redirect":"generate";if(!eR(a.prompt,o))return void r8();if("imageToVideo"===i){if(!a.startFrameImage){R.oR.error(t.generator?.errors?.startFrameRequired||"Start frame is required"),r8();return}if(a.addEndFrame&&!a.endFrameImage){e0(!0),r8();return}}if("referenceToVideo"===i){if(!o?.supportsReferenceMode){R.oR.error(ea("unsupportedReferenceMode")),r8();return}if(!ep({imageCount:a.referenceImages.length,videoCount:a.referenceVideos.length,audioCount:a.referenceAudios.length})){R.oR.error(ea("referenceMediaRequired")),r8();return}if(r$(o)){if(0===a.referenceImages.length){R.oR.error(ea("veoReferenceImageRequired")),r8();return}if(a.aspectRatio!==rA||8!==a.length){R.oR.error(ea("veoReferenceConstraints")),r8();return}}}let d=eT.current;if(d&&(0,tA.is)(d,a.prompt)&&(X("home_inspiration_generate_clicked",{surface_type:"home",inspiration_surface:"get_inspired_gallery",inspiration_id:d.inspiration_id,inspiration_index:d.inspiration_index,media_mode:d.media_mode,prompt_source:tA.vS},tA.u8),eT.current=null),X("video_gen_intent",rk(a,i)),!q){let e=await nC(a),t="textToVideo"===i?"video-text":"video-image",r=nU(t);if(tE(e),!(0,tK.lP)({kind:"video",mode:t,inputMode:e.inputMode,prompt:e.prompt,autoSubmit:!1,preferredHistoryScope:"all",modelId:e.modelId,clientRequestId:e.clientRequestId,sourceHistoryId:e.sourceHistoryId,aspectRatio:e.aspect,resolution:e.resolution,duration:e.lengthSeconds,durationAuto:e.durationAuto,outputCount:e.outputCount,generateAudio:e.generateAudio,enhancePrompt:e.enhancePrompt,addEndFrame:e.enableEndFrame,startFrameImageUrl:e.startFrameImageUrl,endFrameImageUrl:e.endFrameImageUrl,referenceImageUrls:e.referenceImageUrls,referenceAudioUrls:e.referenceAudioUrls,localImageDraft:e.localImageDraft,startFrameWidth:e.startFrameWidth,startFrameHeight:e.startFrameHeight,endFrameWidth:e.endFrameWidth,endFrameHeight:e.endFrameHeight}))throw new rx("VIDEO_DRAFT_METADATA_STORAGE_FAILED");z(r),B(!0,"video_generation"),r8();return}let u=await nS(a,i,o);if("unlimited"!==a.billingMode&&"number"==typeof u&&!(await Y({requiredCredits:u,...(0,t7.$)({isExternalPaidModel:(0,rt.VV)(a.modelId,a.resolution)}),analytics:{toolType:"video-generator",modelId:a.modelId,generationType:i,generationMode:tN(i),durationMode:a.durationAuto?"auto":"fixed",surfaceType:"video_generator",triggerStage:"client_precheck"},onBlocked:e=>{X("video_gen_task_failure",{...rk(a,i),failure_reason:"insufficient_credits"}),X("credits_insufficient_shown",{...rk(a,i),required_credits:e.requiredCredits,current_credits:e.currentCredits}),r8()}})).ok)return;if(rG.current){rG.current=!1,await nO(a,r,s);return}if(!await nV(r,a,s))return void r8();await nO(a,r,s)}catch(e){console.error("Failed to start video generation:",e),r8(),R.oR.error(e instanceof rx?en("processFailed"):t.generator?.errors?.failed||"Generation failed. Please try again.")}}},nq=()=>{nW()};(0,h.useEffect)(()=>
1{if(!q||!D)return;let e=!1;return(async()=>{let t,r=++ry.current;try{t=await rN(D.localImageDraft)}catch(e){console.warn("Failed to restore video login draft images:",e),t={referenceImages:[],missingLocalImages:!!D.localImageDraft}}if(e||r!==ry.current||!nA(D,t))return;let n=U||t.missingLocalImages;(D.localImageDraft&&(0,tK.lP)({...D,autoSubmit:!1}),n)?R.oR.error(es("referenceLimits.restoreFailed")):(D.localImageDraft&&(rI.current=D.localImageDraft.draftId,rz.current=D.localImageDraft.draftId),tL(),O?.())})(),()=>{e=!0}},[D,U,O,nA,es,q]),(0,h.useEffect)(()=>{if(!r||!ek?.models.length)return;let e=()=>{let e=(0,s.ws)();e&&nA(e.draft)&&(eT.current=(0,tA.d5)(e.selection),X("home_inspiration_prompt_applied",(0,tA.q9)(e.selection),tA.u8),tr(!1),(0,s.xM)(e))};return window.addEventListener(s.Yl,e),e(),()=>window.removeEventListener(s.Yl,e)},[r,ek,nA,X]),(0,h.useEffect)(()=>{if(!q||!ek||0===ek.models.length||D||r5.current)return;let e=k?(0,tK.SC)():null;if(D||e?.kind==="video"&&!(0,t2.qt)(e)&&!(0,t5.jz)(e))return;let t=tT();if(!t)return;let r=!1;return(async()=>{let e=++ry.current;try{let n=await rN(t.localImageDraft);if(r||e!==ry.current||!nA({kind:"video",mode:"textToVideo"===t.mode?"video-text":"video-image",inputMode:t.inputMode,prompt:t.prompt,modelId:t.modelId,clientRequestId:t.clientRequestId,sourceHistoryId:t.sourceHistoryId,aspectRatio:t.aspect,duration:t.lengthSeconds,durationAuto:t.durationAuto,resolution:t.resolution,outputCount:t.outputCount,generateAudio:t.generateAudio,webSearch:t.webSearch,contentFilter:t.contentFilter,outputFormat:t.outputFormat,enhancePrompt:t.enhancePrompt,addEndFrame:t.enableEndFrame,startFrameImageUrl:t.startFrameImageUrl,endFrameImageUrl:t.endFrameImageUrl,referenceImageUrls:t.referenceImageUrls,referenceAudioUrls:t.referenceAudioUrls,localImageDraft:t.localImageDraft,startFrameWidth:t.startFrameWidth,startFrameHeight:t.startFrameHeight,endFrameWidth:t.endFrameWidth,endFrameHeight:t.endFrameHeight},n))return;if(n.missingLocalImages)return void R.oR.error(es("referenceLimits.restoreFailed"));t.localImageDraft&&(rI.current=t.localImageDraft.draftId,rz.current=t.localImageDraft.draftId),tL()}catch(t){console.error("Failed to restore draft after login:",t),r||e!==ry.current||R.oR.error(es("referenceLimits.restoreFailed"))}})(),()=>{r=!0}},[ek,k,D,nA,es,q]),(0,h.useEffect)(()=>{let e=rp.current??e_;tt&&e.prompt&&!eO&&!S&&(rp.current=null,tr(!1),nW(e))},[tt,e_,eO,S]);let nH="end"===tu?eu?.labels?.endFrameImage||eu?.labels?.end||"":eu?.labels?.startFrame||eu?.labels?.start||"",nB=t.faq?{name:"faq",label:"FAQ",title:t.faq.title,description:t.faq.description,items:t.faq.items}:null,nz=t.features??null,nG=(0,h.useMemo)(()=>{if(to?.modelId&&ek)return(0,Q.getModelById)(ek,to.modelId)},[to?.modelId,ek]);if(eA)return(0,a.jsxs)("div",{className:r?"w-full py-12":"min-h-screen bg-background text-foreground",children:[!r&&(0,a.jsx)(I,{hero:t.hero}),(0,a.jsx)("div",{className:r?"w-full":"container mx-auto px-4 py-20",children:(0,a.jsxs)("div",{className:"flex flex-col items-center justify-center space-y-4",children:[(0,a.jsx)(e2.A,{className:"h-8 w-8 animate-spin text-primary"}),(0,a.jsx)("p",{className:"text-muted-foreground",children:ew})]})})]});if(eS||!ek||0===ek.models.length)return(0,a.jsxs)("div",{className:r?"w-full py-12":"min-h-screen bg-background text-foreground",children:[!r&&(0,a.jsx)(I,{hero:t.hero}),(0,a.jsx)("div",{className:r?"w-full":"container mx-auto px-4 py-20",children:(0,a.jsx)("div",{className:"flex flex-col items-center justify-center space-y-4",children:(0,a.jsx)("p",{className:"text-destructive",children:eI})})})]});let nX=eO||eW||S,nY=y??(r?void 0:e=>{if("video"===e)return;let t=ee===`/${er}`||ee.startsWith(`/${er}/`);Z.push(t?`/${er}`:"/")}),nQ={pageData:r6,state:e_,unlimitedPlan:eP,onChange:nI,onImageFileSelected:nT,onImageClick:nL,onGenerate:nq,isGenerating:nX,isLoggedIn:!!q,showEndFrameWarning:eK,isStartFrameLoading:!1,models:ek.models,activeModel:nc,embedded:r,activeMediaMode:d??(r?void 0:"video"),onMediaModeChange:nY,hideModeSwitcherOnMobile:w,modeSwitcherPlacement:F};
1return(0,a.jsxs)("div",{"data-video-generator-root":!0,"data-app-update-busy":nX?"true":void 0,className:r?"w-full text-foreground":"min-h-screen bg-background text-foreground",children:[!r&&(0,a.jsx)(I,{hero:t.hero}),(0,a.jsxs)("div",{className:r?"w-full":"container mx-auto px-4 space-y-8 pb-20",children:[(0,a.jsx)(tX.Y,{panelRootRef:ne,body:(0,a.jsx)(eZ,{...nQ,stickyExpanded:!1,embeddedMobileHeader:W}),stickyCollapsed:r7&&nr&&!nn?(0,a.jsx)(tG.J5,{floatingRef:nt,prompt:np,placeholder:nf??"",leading:ni||"imageToVideo"===nm&&e_.addEndFrame?(0,a.jsx)(tG.QT,{startFrameUrl:ni,endFrameUrl:no,showEndFrame:"imageToVideo"===nm&&e_.addEndFrame}):(0,a.jsx)(tG.kV,{}),isGenerating:nX,generateDisabled:nX,generateLabel:eu?.actions.generate??"Generate",onExpand:()=>na(!0),onGenerate:nq}):null,stickyExpanded:r7&&nn?(0,a.jsx)(tG.mz,{floatingRef:nt,children:(0,a.jsx)(eZ,{...nQ,stickyExpanded:!0,embeddedMobileHeader:W})}):null}),(0,a.jsx)(tI,{open:ts,onOpenChange:td,source:tm,targetRatio:tb??e_.aspectRatio,availableRatios:ty&&tb?[tb]:nc?.ratios,onRatioChange:ty?void 0:e=>{r2.current=e,nI({aspectRatio:e})},title:nH,ratioLabel:eu?.labels?.aspect||"Aspect Ratio",defaultMode:th,onConfirm:n$,onCancel:nP}),!r9&&!ng&&(eO||eX.length>0)&&to&&(0,a.jsx)("div",{ref:e7,className:"w-full pb-10",children:(0,a.jsx)(tH,{billingMode:to.billingMode,unlimitedState:to.unlimitedState,isGenerating:eO,videoUrls:eX,thumbnailUrls:eQ,prompt:to.prompt,modelId:to.modelId,modelLabel:nG?.label,modelLogoSrc:nG?.logoSrc,mode:to.mode,duration:to.duration,durationAuto:to.durationAuto,startFrameImage:to.startFrameImage,aspectRatio:to.aspectRatio,resolution:to.resolution,outputCount:to.outputCount,enhancePrompt:to.enhancePrompt,enhancedPrompt:to.enhancedPrompt,isZh:ev,progress:e1,estimatedTimeLabel:nG?.estimatedTimeLabel||"~2 min",labels:t.generator?.result})})]}),!r&&nz&&(0,a.jsx)(tB.VideoFeaturesSection,{section:nz}),!r&&(0,a.jsx)(tP.EmbeddedPricingSection,{}),!r&&nB&&(0,a.jsx)(tV.A,{section:nB})]})}},23823:(e,t,r)=>{r.r(t),r.d(t,{EmbeddedPricingSection:()=>l});var n=r(4364),a=r(23955),i=r(94160),o=r(89917);function l(){let e=(0,a.c)("pricing"),{user:t}=(0,i.U)();return(0,n.jsx)("section",{className:"py-12 md:py-20",children:(0,n.jsxs)("div",{className:"container px-4 sm:px-6 lg:px-8",children:[(0,n.jsxs)("div",{id:"plans",className:"mx-auto mb-12 text-center scroll-mt-24",children:[(0,n.jsx)("h2",{className:"mb-4 text-3xl font-semibold lg:text-4xl",children:e("title")}),(0,n.jsx)("p",{className:"text-muted-foreground lg:text-lg",children:e("subtitle")})]}),(0,n.jsx)(o.PricingClient,{user:t??null,analyticsSurface:"embedded_pricing_section"})]})})}},25640:(e,t,r)=>{r.d(t,{AT:()=>I,Gf:()=>v,Gk:()=>p,H5:()=>f,Is:()=>h,JX:()=>M,P3:()=>b,Qp:()=>N,US:()=>c,Y:()=>m,Yo:()=>w,_S:()=>g,_g:()=>y,if:()=>_,jo:()=>u,ke:()=>A,kt:()=>S,mZ:()=>k,rj:()=>E,s3:()=>F,t4:()=>j,u8:()=>C,wY:()=>R});var n=r(4364),a=r(63631),i=r(36820),o=r(67850),l=r(81714),s=r(31819),d=r(69751);function u(e,t){return!!e?.supportsAudio&&!1!==e.audioSelectable&&"unsupported"!==(t?(0,s.getVideoAudioPolicy)(e,t):e.audioPolicy??"optional")}function c(e){return(e?.maxImageCount??1)>1}function m(e,t){return c(t)?"startEndFrame"===e.inputMode?{...e,addEndFrame:!0}:"singleFrame"===e.inputMode?{...e,addEndFrame:!1,endFrameImage:null,originalEndFrameImage:null,endFrameDimensions:null}:e:{...e,inputMode:"startEndFrame"===e.inputMode?"singleFrame":e.inputMode,addEndFrame:!1,endFrameImage:null,originalEndFrameImage:null,endFrameDimensions:null}}function g(e,t,r){if(!e?.supportsAudio)return{generateAudio:!1,blocked:!1};let n=t?(0,s.getVideoAudioPolicy)(e,t):e.audioPolicy??"optional";return"always"===n?{generateAudio:!0,blocked:!r}:"unsupported"===n?{generateAudio:!1,blocked:!1}:{generateAudio:r,blocked:!1}}function p(e,t,r){return e&&"videoGenerator.reference.audioRequired"!==e?e.replaceAll("{resolution}",t):`${t} \xb7 ${r}`}function f(e){return"zh-Hant"===e?"寬鬆內容":e.startsWith("zh")?"宽松内容":"Relaxed Content"}function h(e){return"zh-Hant"===e?"開啟後使用更寬鬆的內容過濾設定,影片生成點數增加 10%。仍需遵守平台å…
1§å®¹è¦ç¯„。":e.startsWith("zh")?"开启后使用更宽松的内容过滤设置,视频生成积分增加 10%。仍需遵守平台内容规范。":"Uses a more relaxed content-filter setting. Video generation credits increase by 10%. Platform content rules still apply."}function x(e,t){return"referenceToVideo"===t&&(e?.provider==="veo"||!!e?.id.startsWith("veo-3.1-"))}function b(e,t,r){var n;if(n=e,"imageToVideo"===t&&(n?.id==="seedance-2.5"||(0,l.bq)(n?.id)))return["adaptive"];let a=(0,l.fe)(e?.id)&&!!r&&"2k"===(0,s.getVideoOutputResolution)(e,r);return a&&"imageToVideo"===t?["adaptive"]:a&&"referenceToVideo"===t?["adaptive",...e?.ratios??[]]:x(e,t)?["16:9"]:[...e?.ratios??[]]}function v(e,t,r,n){let a=b(e,t,n);return a.includes(r)?r:a[0]||r}function y(e,t,r){return x(e,r)?[8]:(0,s.getDurationsForResolution)(e,t)}function w(e,t,r){let n=y(e,t,r);return e?.supportsAutoDuration?["auto",...n]:n}function I(e,t){if("auto"!==t)return{length:t,durationAuto:!1};let r=(0,s.getModelDurations)(e);return{length:e?.autoDurationReservationSeconds??e?.defaultDurationSeconds??r[r.length-1]??5,durationAuto:!0}}function j(e,t,r){return t?r:`${e}s`}function F(e,t){if("adaptive"===e||"auto"===e)return(0,n.jsx)(a.A,{className:t});let[r,l]=e.split(":").map(Number);if(!r||!l)return(0,n.jsx)(i.A,{className:t});let s=r/l;return s>1.05?(0,n.jsx)(i.A,{className:t}):s<.95?(0,n.jsx)(o.A,{className:t}):(0,n.jsx)(a.A,{className:t})}function N(e,t,r){return"auto"===e?r?.auto??(t?.startsWith("zh")?"自动":"Auto"):"adaptive"!==e?e:r?.adaptive??(t?.startsWith("zh")?"自适应":"Adaptive")}function C(e){let t=(0,s.getVideoPhysicalResolutions)(e).map(e=>e.toUpperCase());return t.length<=1?t[0]??"":t.join(" / ")}function R(e,t){return!(0,l.fe)(e?.id)&&t.length>1}function k(e){let t=(0,s.getModelDurations)(e);return t.length<=1?`${t[0]??""}s`:`${Math.min(...t)}-${Math.max(...t)}s`}function A(e,t,r,n){let a=arguments.length>4&&void 0!==arguments[4]?arguments[4]:r,i=M(e),o=[i.imageCount,i.videoCount,i.audioCount].filter(e=>e>0).length;return(0,s.supportsVideoReferenceMode)(e,t)?o>1?n:i.imageCount>1?a:r:r}function S(e){return e.supportsReferenceMode||"reference"!==e.currentInputMode&&"reference"!==e.preferredInputMode?e.supportsReferenceMode&&e.isAutoFallbackActive&&"singleFrame"===e.currentInputMode&&"reference"===e.preferredInputMode?{inputMode:"reference",isAutoFallbackActive:!1}:{inputMode:e.currentInputMode,isAutoFallbackActive:e.isAutoFallbackActive}:{inputMode:"singleFrame",isAutoFallbackActive:!0}}function M(e){let t=(0,l.Vu)(e?.id);return{imageCount:e?.maxReferenceImageCount??0,videoCount:e?.maxReferenceVideoCount??0,audioCount:e?.maxReferenceAudioCount??0,totalCount:e?.maxReferenceTotalCount,imageFormats:t.image.formatsLabel,videoFormats:t.video.formatsLabel,audioFormats:d.v5,videoMinSeconds:e?.referenceVideoMinDurationSeconds??t.video.durationSeconds[0],videoMaxSeconds:e?.referenceVideoMaxDurationSeconds??t.video.durationSeconds[1],videoTotalSeconds:e?.referenceVideoTotalMaxDurationSeconds??d.Sk,audioMinSeconds:e?.referenceAudioMinDurationSeconds??d.E0,audioMaxSeconds:e?.referenceAudioMaxDurationSeconds??d.wD,audioTotalSeconds:e?.referenceAudioTotalMaxDurationSeconds??d.Xd}}function _(e,t){let r=e.videoCount>0||e.audioCount>0,n=r?e.totalCount?t.multiDetailedWithTotal:t.multiDetailed:t.imagesDetailed;return n?Object.entries({...e,totalCount:e.totalCount??0}).reduce((e,t)=>{let[r,n]=t;return e.replaceAll(`{${r}}`,String(n))},n):r?t.multiFallback:t.imagesFallback}function E(e,t){return"referenceToVideo"===e?t.reference:"imageToVideo"===e?t.image:t.text}},27068:(e,t,r)=>{r.d(t,{I:()=>o});var n=r(44099),a=r(13886),i=r(77232);let o=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=function(){for(var t=arguments.length,r=Array(t),n=0;n<t;n++)r[n]=arguments[n];return(e.fetcher??fetch)(...r)},r=e.wait??(e=>new Promise(t=>setTimeout(t,e)));return async function(o,l){let s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},d=l.input_image;if(!s.file&&("string"!=typeof d||!d.startsWith("data:")))return t(o,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(l),signal:s.signal});let u=s.file;if(!u){if("string"!=typeof d)throw Error("INVALID_INPUT_IMAGE");u=(0,n.f)(d,"input-image","INVALID_INPUT_IMAGE")}let c=l.client_request_id,m=`${o}${o.includes("?")?"&":"?"}raphael_direct_tool=1`,g=(0,i.E)({endpoint:m,body:{upload_action:"fail",client_request_id:c},fetcher:t});async function p(e){let n=!(arguments.length>1)||void 0===arguments[1]||arguments[1];for(let a=1;;a++){if(n&&s.signal?.aborted)throw new DOMException("Aborted","AbortError");let i=new AbortController,l=()=>i.abort();n&&s.signal?.addEventListener("abort",l,{once:!0});let d=setTimeout(l,3e4);try{let r=await t(o,{method:"POST",headers:{"Content-Type":"application/json","x-raphael-direct-tool":"1"},body:JSON.stringify(e),signal:i.signal});if(r.status<500||a>=3)return r}catch(e){if(n&&s.signal?.aborted||a>=3)throw e}finally{clearTimeout(d),s.signal?.removeEventListener("abort",l)}await r(800*a)}}{let t,{input_image:r,...n}=l;try{t=await p({...n,client_request_id:c,upload_action:"initialize",input_file:{size:u.size,type:u.type}})}catch(e){throw await g.cancel().catch(()=>void 0),e}let i=await t.clone().json().catch(()=>({}));if(!t.ok||0!==i.code)return g.disarm(),t;let d=t;if(i.data?.uploadRequired){let r=i.data.historyId;g.update({body:{upload_action:"fail",history_id:r}});let n="";
1try{if(!await (e.upload??a.ad)({file:u,endpoint:o,context:{upload_action:"upload",history_id:r},analytics:s.analytics??{toolType:o.includes("/extend/")||o.includes("uncrop")?"expand-image":o.includes("/remove")?"remove-background":"expand-image",mediaType:"image"},controlHeaders:{"x-raphael-direct-tool":"1"},timeoutMs:115e3,maxAttempts:3,signal:s.signal,onAuthorization:e=>{n=e,g.update({body:{upload_action:"interrupt",history_id:r,authorization:e}})}})||!n)throw Error("UPLOAD_SERVICE_UNAVAILABLE");if(!(d=await p({upload_action:"complete",history_id:r,authorization:n})).ok)throw Error("UPLOAD_COMPLETION_FAILED");g.disarm()}catch{try{g.disarm();let e=await p({upload_action:"fail",history_id:r},!1),n=await e.clone().json();d=e.ok&&0===n.code?e:t}catch{d=t}}}else g.disarm();return d}}}()},31819:(e,t,r)=>{r.r(t),r.d(t,{calculateCredits:()=>a.hL,getDurationsForResolution:()=>a.Jg,getModelById:()=>a.UT,getModelDurations:()=>a.xW,getModelMinimumVideoCreditDisplayOffer:()=>a.qd,getModelResolutions:()=>a.td,getReferenceVideoOutputId:()=>a.p1,getVideoAudioPolicy:()=>a.q3,getVideoCreditDisplayOffer:()=>a.vc,getVideoOutputLabel:()=>a.$w,getVideoOutputQuality:()=>a.sf,getVideoOutputResolution:()=>a.Xd,getVideoPhysicalResolutions:()=>a.QA,getVideoPromptMaxLength:()=>a.Ch,getVideoQualityOptions:()=>a.Zb,preloadVideoCreditsConfig:()=>u,resolveVideoOutputFormatForRequest:()=>a.Ul,resolveVideoOutputId:()=>a.Yc,supportsVideoReferenceMode:()=>a.UG,useVideoCreditsConfig:()=>c});var n=r(44032),a=r(90938);let i=(0,a.UD)(),o=i,l=null,s=!1;async function d(){let e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];if(!e&&s&&o)return o;if(!e&&l)return l;l=(async()=>{let e=await fetch("/api/video/credits"),t=await e.json();if(!e.ok||!t.success)throw Error(t.error||"Failed to fetch video credits config");return o=t.data,s=!0,t.data})();try{return await l}finally{l=null}}async function u(){try{await d()}catch(e){console.warn("[useVideoCreditsConfig] Silent preload failed:",e instanceof Error?e.message:e)}}function c(){let[e,t]=(0,n.useState)(o),[r,a]=(0,n.useState)(!1),[l,u]=(0,n.useState)(null),c=async function(){let e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];try{if(!e&&s&&o){t(o),u(null),a(!1);return}a(!o),u(null);let r=await d(e);t(r)}catch(r){console.warn("[useVideoCreditsConfig] Failed to load config, using fallback:",r instanceof Error?r.message:r);let e=o||i;t(e),u(e?null:r instanceof Error?r.message:"Unknown error")}finally{a(!1)}};return(0,n.useEffect)(()=>{if(s&&o){t(o),a(!1);return}c()},[]),{config:e,isLoading:r,error:l,refetch:()=>c(!0)}}},34751:(e,t,r)=>{r.d(t,{b:()=>g,r:()=>m});var n=r(4364),a=r(44032),i=r(41166),o=r(75152),l=r(69285),s=r(30869),d=r(14423),u=r(2530);async function c(e,t){let r=await fetch(e,{cache:"no-store",credentials:"omit"});if(!r.ok)throw Error(`Failed to download video: ${r.status}`);let n=await r.blob();if(!n.size)throw Error("Empty video blob");(0,l.saveAs)(n,t)}async function m(e,t){let r=`/api/download?url=${encodeURIComponent(e)}&name=${encodeURIComponent(t)}`;try{await c(r,t)}catch(r){console.warn("Video proxy download failed, falling back to direct download:",r),await c(e,t)}}function g(e){let{videoUrl:t,fileName:r,label:l,errorLabel:c="Download failed. Please try again later.",className:g,analyticsProps:p,disabled:f=!1,iconOnly:h=!1,style:x}=e,[b,v]=(0,a.useState)(!1),{trackEvent:y}=(0,u.s)(),w=async e=>{if(e.stopPropagation(),!f&&!b&&t){v(!0);try{await m(t,r),y("video_gen_downloaded",{download_surface:"result",...p})}catch(e){console.error("Failed to download generated video:",e),s.oR.error(c)}finally{v(!1)}}};return(0,n.jsxs)("button",{type:"button",onClick:w,disabled:f||b,style:x,className:(0,d.cn)("inline-flex h-8 max-w-full items-center gap-1.5 rounded-lg border border-white/10 bg-white/[0.06] px-2.5 text-xs font-medium text-foreground/80 shadow-sm transition-colors hover:bg-white/[0.10] hover:text-foreground disabled:pointer-events-none disabled:opacity-60",g),"aria-label":l,children:[b?(0,n.jsx)(i.A,{className:h?"h-5 w-5 animate-spin":"h-3.5 w-3.5 animate-spin"}):(0,n.jsx)(o.A,{className:h?"h-5 w-5":"h-3.5 w-3.5"}),h?null:(0,n.jsx)("span",{className:"min-w-0 truncate",children:l})]})}},38052:(e,t,r)=>{r.d(t,{$f:()=>f,Ag:()=>v,CD:()=>w,Cn:()=>I,Ll:()=>C,U3:()=>p,Wl:()=>b,c9:()=>x,fR:()=>R,ou:()=>F,ry:()=>i,sp:()=>h,vX:()=>y,yj:()=>N});var n=r(50288),a=r(30900);let i=Number.MAX_SAFE_INTEGER,o=e=>{if(e.startsWith("data:")||!/^https?:\/\//i.test(e))return e;try{return e}catch{return e}},l=async e=>{if(/^https?:\/\//i.test(e))try{return await fetch(e,{cache:"no-store"})}catch{let t=`/api/download?url=${encodeURIComponent(e)}`;return await fetch(t,{cache:"no-store"})}let t=o(e);return await fetch(t,{cache:"no-store"})},s=e=>new Promise((t,r)=>{let n=new Image;n.onload=()=>t(n),n.onerror=e=>r(e),n.src=e}),d=e=>{try{return new URL(e,window.location.origin).searchParams.get("url")||e}catch{return e}},u=e=>{let t=d(e),r=(t.split("?")[0]||t).toLowerCase();return r.endsWith(".png")?"image/png":r.endsWith(".webp")?"image/webp":r.endsWith(".jpg")||r.endsWith(".jpeg")?"image/jpeg":null},c=(e,t,r)=>{let n="image/png"===t?"png":"image/webp"===t?"webp":"jpg";if(e instanceof File&&e.name)return`${e.name.replace(/\.[^.]+$/,"")}.${n}`;if("string"==typeof e&&!e.startsWith("data:"))try{let t=new URL(d(e),window.location.origin).pathname.split("/").pop();if(t)return`${t.replace(/\.[^.]+$/,"")}.${n}`}catch{}return`${r}-${Date.now()}.${n}`},m=async(e,t,r,n)=>{let a=await new Promise(t=>{e.toBlob(e=>t(e),r,n)});if(!a)throw Error("Canvas export failed");return new File([a],t,{type:r})},g=(e,t)=>0===t?e:g(t,e%t);function p(e){let[t,r]=e.split(":").map(e=>Number(e));return t&&r?t/r:1}function f(e,t){let r=g(e,t);return`${Math.round(e/r)}:${Math.round(t/r)}`}function h(e,t,r){if(!r.length)return f(e,t);let n=e/t,a=r[0],i=Math.abs(n-p(a));for(let e of r.slice(1)){let t=Math.abs(n-p(e));t<i&&(i=t,a=e)}return a}function x(e,t,r){let n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:.05;return"adaptive"===r||Math.abs(e/t-p(r))<=n}function b(e,t,r){if(!(0,a.uX)(e))return{ok:!1,error:"type"};let i=(0,n.LQ)(t,r);return void 0!==i.maxBytes&&e.size>i.maxBytes?{ok:!1,error:"size"}:{ok:!0}
1}function v(e){if("image/webp"===e)return .86}async function y(e){if(e instanceof File){let t=await (0,a.Q1)(e);return{width:t.width,height:t.height}}if(/^https?:\/\//i.test(e))try{let t=await s(e);return{width:t.width,height:t.height}}catch{}let t=o(e),r=await s(t);return{width:r.width,height:r.height}}async function w(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:i,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:e.type||"image/jpeg",n=await (0,a.Q1)(e),o=n.width,l=n.height;if(o<=t&&l<=t&&r===e.type)return e;(o>t||l>t)&&(o>l?(l=Math.round(l*t/o),o=t):(o=Math.round(o*t/l),l=t));let s=document.createElement("canvas");s.width=o,s.height=l;let d=s.getContext("2d");if(!d)throw Error("Failed to create canvas context");d.drawImage(n,0,0,o,l);let u=c(e,r,"image"),g=v(r);return m(s,u,r,g)}async function I(e){let t=await l(e);if(!t.ok)throw Error(`Failed to fetch image: ${t.status}`);let r=await t.blob(),n=u(e),a=((e,t)=>{if(!e)return!0;let r=e.toLowerCase();return!r.startsWith("image/")&&!!t&&("application/octet-stream"===r||"binary/octet-stream"===r||r.startsWith("text/plain"))})(r.type,n)?n||"image/jpeg":r.type;return new File([r],c(e,a,"image"),{type:a})}async function j(e){return new Promise((t,r)=>{let n=new FileReader;n.onload=()=>t(n.result),n.onerror=()=>r(n.error),n.readAsDataURL(e)})}async function F(e){if(e instanceof File)return j(e);if(e.startsWith("data:"))return e;let t=await l(e);if(!t.ok)throw Error(`Failed to fetch image: ${t.status}`);let r=await t.blob();return new Promise((e,t)=>{let n=new FileReader;n.onload=()=>e(n.result),n.onerror=()=>t(n.error),n.readAsDataURL(r)})}function N(e,t,r,n,a){let i="cover"===a?Math.max(r/e,n/t):Math.min(r/e,n/t),o=e*i,l=t*i,s=Math.round((r-o)/2),d=Math.round((n-l)/2);return{scale:i,scaledWidth:o,scaledHeight:l,posX:s,posY:d}}function C(e,t,r,n){let a=arguments.length>4&&void 0!==arguments[4]?arguments[4]:i,o=p(r),l=e/t,s=e,d=t;"crop"===n?l>o?(s=Math.round(t*o),d=t):l<o&&(s=e,d=Math.round(e/o)):l>o?(s=e,d=Math.round(e/o)):l<o&&(s=Math.round(t*o),d=t);let u=Math.min(1,a/Math.max(s,d));return{targetWidth:Math.round(s*u),targetHeight:Math.round(d*u)}}function R(e){var t;return["image/jpeg","image/png","image/webp"].includes(t=(e=>{if(e instanceof File)return e.type||"image/jpeg";if(e.startsWith("data:")){let t=e.match(/^data:([^;]+);/);return t?.[1]||"image/jpeg"}return u(e)||"image/jpeg"})(e))?t:"image/png"}},40810:(e,t,r)=>{r.d(t,{T:()=>o});var n=r(4364),a=r(44032),i=r(14423);let o=a.forwardRef((e,t)=>{let{className:r,...a}=e;return(0,n.jsx)("textarea",{className:(0,i.cn)("flex min-h-[80px] w-full rounded-md border border-input bg-background px-3 py-2 text-sm r
1ing-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",r),ref:t,...a})});o.displayName="Textarea"},44973:(e,t,r)=>{r.d(t,{Progress:()=>u});var n=r(4364),a=r(44032),i=r(3398),o=r(20720),l=r(14423);let s=(0,o.F)("relative w-full overflow-hidden rounded-full bg-[var(--ui-progress-track)]",{variants:{size:{sm:"h-2",default:"h-2.5",lg:"h-3"}},defaultVariants:{size:"default"}}),d=(0,o.F)("h-full w-full flex-1 rounded-full transition-transform duration-300 ease-out",{variants:{intent:{default:"bg-[var(--ui-progress-fill)]",success:"bg-[var(--ui-progress-success)]",warning:"bg-[var(--ui-progress-warning)]",danger:"bg-[var(--ui-progress-danger)]"}},defaultVariants:{intent:"default"}}),u=a.forwardRef((e,t)=>{let{className:r,value:a=0,label:o,valueLabel:u,size:c,intent:m,indicatorClassName:g,...p}=e,f=Number.isFinite(a)?Math.min(Math.max(a??0,0),100):0;return(0,n.jsxs)("div",{className:"space-y-2",children:[o||u?(0,n.jsxs)("div",{className:"flex items-center justify-between gap-3 text-xs font-medium text-muted-foreground",children:[(0,n.jsx)("span",{children:o}),(0,n.jsx)("span",{children:u})]}):null,(0,n.jsx)(i.bL,{ref:t,className:(0,l.cn)(s({size:c}),r),value:f,...p,children:(0,n.jsx)(i.C1,{className:(0,l.cn)(d({intent:m}),g),style:{transform:`translateX(-${100-f}%)`}})})]})});u.displayName=i.bL.displayName},50278:(e,t,r)=>{r.d(t,{K:()=>d,x:()=>u});var n=r(4364),a=r(61810),i=r(68494),o=r(99909),l=r(77886),s=r(14423);function d(e){let{children:t,className:r}=e;return(0,n.jsx)("div",{className:(0,s.cn)("mx-auto grid max-w-[1180px] gap-4 md:grid-cols-3",r),children:t})}function u(e){let{planType:t,planName:r,billingInterval:d,monthlyPrice:u,yearlyMonthlyPrice:c,badgeLabel:m,isRecommended:g=!1,action:p}=e;return(0,n.jsxs)("section",{className:(0,s.cn)("relative rounded-xl p-5 transition-all duration-300 hover:-translate-y-1 hover:shadow-xl",g?"order-1 border-2 border-primary/80 bg-primary/[0.08] shadow-2xl shadow-primary/25 ring-2 ring-primary/20 md:order-none":"order-2 border border-primary/20 bg-card/95 shadow-lg shadow-black/10 ring-1 ring-primary/10 md:order-none"),children:[m?(0,n.jsx)(i.X,{className:"absolute right-0 top-0 rounded-bl-md rounded-br-none rounded-tl-none rounded-tr-[11px]",children:m}):null,(0,n.jsx)("div",{className:"flex h-full flex-col justify-between gap-4",children:(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{className:"mb-3 flex min-h-7 flex-wrap items-center gap-1.5",children:[(0,n.jsx)("h3",{className:"text-lg font-semibold",children:r}),"yearly"===d?(0,n.jsx)(o.u,{className:"h-[18px] px-2 text-[11px]"}):null]}),(0,n.jsx)("div",{className:"mb-3 min-h-[76px]",children:(0,n.jsx)(l.Z,{billingInterval:d,monthlyPrice:u,yearlyMonthlyPrice:c,compact:!0})}),p?(0,n.jsx)("div",{className:"mb-4",children:p}):null,(0,n.jsx)(a.PricingPlanFeatures,{planType:t,compact:!0})]})})]})}},55112:(e,t,r)=>{function n(e){let{prompt:t,sourceHistoryId:r,clientRequestId:n,referenceVideoUrls:a}=e,i=a?.map(e=>e.trim()).filter(e=>/^https?:\/\//i.test(e));return{kind:"video",mode:"video-edit",modelId:"video-editor",prompt:t,autoSubmit:!1,preferredHistoryScope:"tool",sourceHistoryId:r?.trim()||void 0,clientRequestId:n?.trim()||void 0,...i&&i.length>0?{referenceVideoUrls:i.slice(0,1)}:{}}}function a(e){let{videoUrl:t,sourceHistoryId:r}=e,a=n({prompt:"",sourceHistoryId:r,referenceVideoUrls:[t]});return a.referenceVideoUrls?.length?a:null}function i(e){return!!(e&&"video"===e.kind&&"video-edit"===e.mode&&"video-editor"===e.modelId)}r.d(t,{jz:()=>i,lq:()=>a,zk:()=>n})},57339:(e,t,r)=>{r.d(t,{W:()=>s});var n=r(78182);function a(e){return"object"==typeof e&&null!==e}function i(e){return"string"==typeof e?e.trim().toLowerCase():""}function o(e){if("string"==typeof e)return e.trim()||void 0}function l(e){return"number"==typeof e&&Number.isFinite(e)&&e>=0?e:void 0}function s(e){let{outputCount:t=1,tasks:r,videoUrls:s,thumbnailUrls:d,isLoading:u=!1,batchId:c="video-item",failure:m}=e,g=Array.isArray(r)?r.filter(a):[],p=Math.max(1,t,g.length,s?.length??0),f={isLoading:u,batchId:c,videoUrls:s,thumbnailUrls:d,failure:m};return Array.from({length:p},(e,t)=>{let r,s,d,u,c,m,p,h,x,b,v,y,w,I,j,F,N,C,R,k,A,S,M,_=g[t];return _?(r=a(_.meta)?_.meta:{},s=a(_.assets)?_.assets:{},d=a(_.result)?_.result:{},u=a(r.upstream)?r.upstream:{},c=a(u.result)?u.result:{},m=f.videoUrls?.[t],p=f.thumbnailUrls?.[t],h=o(_.url)||o(_.video_url),x=o(s.videoUrl)||o(d.url)||o(d.video_url)||h||m,b=o(s.thumbnailUrl)||o(s.coverUrl)||o(s.cover_image_url)||o(s.imageUrl)||o(d.cover_image_url)||o(d.thumbnail_url)||p,v="mov"===s.videoFormat||"mp4"===s.videoFormat?s.videoFormat:void 0,y=o(r.status),w=l(_.index),I=l(r.progress),j=l(r.actualDurationSeconds),F=o(r.errorCode),N=o(r.errorMessage)||o(c.error_message),C=o(c.error_code),R=o(c.upstream_status),A=(k="failed"===i(y))||F||N||C?(0,n.Ur)({errorCode:F,errorMessage:N,upstreamErrorCode:C,upstreamStatus:R}):void 0,{id:o(r.taskId)||o(_.task_id)||o(_.id)||`${f.batchId}-${t}`,slotIndex:w,fileName:o(_.fileName),fileSizeBytes:l(_.fileSizeBytes),durationSeconds:j??l(_.durationSeconds),width:l(_.width),height:l(_.height),requiredCredits:l(_.requiredCredits),refundedCredits:l(_.refundedCredits),progress:I,inputVideoUrl:o(_.inputVideoUrl),url:x,thumbnailUrl:b,videoFormat:v,isLoading:!x&&!k&&(f.isLoading||["awaiting_upload","uploading","pending","processing"].includes(i(y))),status:y,errorCode:F,errorMessage:N,failureKey:A}):(S=f.videoUrls?.[t],M=f.failure?(0,n.Ur)({errorCode:f.failure.errorCode,errorMessage:f.failure.errorMessage}):void 0,{id:`${f.batchId}-${t}`,url:S,thumbnailUrl:f.thumbnailUrls?.[t],isLoading:!f.failure&&f.isLoading&&!S,status:f.failure?"failed":S?"success":f.isLoading?"processing":void 0,errorCode:f.failure?.errorCode,errorMessage:f.failure?.errorMessage,failureKey:M})})}},61639:(e,t,r)=>{r.d(t,{D3:()=>s,Og:()=>i,pl:()=>l,qt:()=>a,uW:()=>o});var n=r(22198);function a(e){return!!(e&&"video"===e.kind&&(e.modelId===n.xA||e.videoUpscale))}function i(e){return{kind:"video",mode:"video-text",prompt:"",autoSubmit:!1,preferredHistoryScope:"all",modelId:n.xA,clientRequestId:e.sessionId,duration:e.durationSeconds,videoUpscale:{sourceKind:"url",inputVideoUrl:e.inputVideoUrl,factor:e.factor,fileSizeBytes:e.fileSizeBytes,width:e.width,height:e.height,fileName:e.fileName}}}function o(e){let t,r=e.sourceHistoryId.trim(),a=e.itemId.trim(),i=e.factor??1;if(!r||!a||!Number.isInteger(e.slotIndex)||e.slotIndex<0||1!==i&&2!==i&&4!==i)return null;try{let r=new URL(e.previewUrl);if("http:"!==r.protocol&&"https:"!==r.protocol)return null;t=r.toString()}catch{return null}return{kind:"video",mode:"video-text",prompt:"",autoSubmit:!1,preferredHistoryScope:"all",modelId:n.xA,sourceHistoryId:r,videoUpscale:{sourceKind:"history",itemId:a,slotIndex:e.slotIndex,previewUrl:t,factor:i}}}function l(e){if(!a(e)||!e.videoUpscale)return null;let t=e.videoUpscale;if("history"===t.sourceKind||!("inputVideoUrl"in t)||"string"!=typeof t.inputVideoUrl||1!==t.factor&&2!==t.factor&&4!==t.factor||!Number.isFinite(t.fileSizeBytes)||t.fileSizeBytes<0||!Number.isFinite(t.width)||t.width<=0||!Number.isFinite(t.height)||t.height<=0)return null;try{let e=new URL(t.inputVideoUrl);if("http:"!==e.protocol&&"https:"!==e.protocol)return null}catch{return null}let r="number"==typeof e.duration&&Number.isFinite(e.duration)&&e.duration>0?e.duration:null;return r?{inputVideoUrl:t.inputVideoUrl,factor:t.factor,fileSizeBytes:t.fileSizeBytes,width:t.width,height:t.height,durationSeconds:r,fileName:t.fileName,sessionId:"string"==typeof e.clientRequestId?e.clientRequestId:void 0}:null}function s(e){if(!a(e)||!e.videoUpscale||"history"!==e.videoUpscale.sourceKind)return null;
1let t=e.sourceHistoryId?.trim(),r=e.videoUpscale.itemId.trim(),{slotIndex:n,factor:i}=e.videoUpscale;if(!t||!r||!Number.isInteger(n)||n<0||1!==i&&2!==i&&4!==i)return null;try{let a=new URL(e.videoUpscale.previewUrl);if("http:"!==a.protocol&&"https:"!==a.protocol)return null;return{sourceHistoryId:t,itemId:r,slotIndex:n,previewUrl:a.toString(),factor:i}}catch{return null}}},61810:(e,t,r)=>{r.d(t,{PricingPlanFeatures:()=>b});var n=r(4364),a=r(38536),i=r(55188),o=r(21208),l=r(69248),s=r(23955),d=r(98244),u=r(14423);let c=[{modelId:"minimax-h3",name:"MiniMax H3",src:"/images/logos/video-models/minimax-h3-icon.png"},{modelId:"gemini-omni",name:"Gemini",src:"/images/logos/video-models/gemini-omni-flash-aurora.svg"},{name:"Nano Banana",src:"/images/logos/video-models/google-g.svg"},{modelId:"gpt-image-2-5",name:"GPT",src:"/images/logos/image-models/openai.svg"},{modelId:"seedream-5-pro",name:"Seedream",src:"/images/logos/image-models/seedream.svg"},{name:"Veo",src:"/images/logos/video-models/google-g.svg"},{modelId:"seedance-2.5",name:"Seedance 2.5",src:"/images/logos/video-models/seedance.svg"},{name:"Kling",src:"/images/logos/video-models/kling-color.svg"}];function m(e){let{label:t,className:r,tone:a="default"}=e,i="inverse"===a;return(0,n.jsxs)("div",{className:(0,u.cn)("min-w-0",r),children:[(0,n.jsx)("div",{className:(0,u.cn)("font-medium",i?"text-white":"text-foreground"),children:t}),(0,n.jsx)("div",{className:"mt-2.5 grid grid-cols-8 gap-x-0.5",children:c.map(e=>(0,n.jsxs)("span",{className:"flex min-w-0 flex-col items-center gap-1 text-center",children:[(0,n.jsx)("span",{className:(0,u.cn)("inline-flex size-6 shrink-0 items-center justify-center overflow-hidden rounded-full border shadow-sm",i?"border-white/15 bg-black":"border-border/60 bg-background"),children:(0,n.jsx)("img",{src:e.src,alt:"",className:"size-4 object-contain",loading:"lazy"})}),(0,n.jsx)("span",{className:(0,u.cn)("min-w-0 text-[8px] leading-[10px] sm:text-[9px]",i?"text-white/65":"text-muted-foreground"),children:e.name}),(0,n.jsx)(d.s,{modelId:e.modelId})]},e.modelId??e.name))})]})}var g=r(57257),p=r(60226),f=r(90938);function h(e,t,r){return[e,t,r].filter(Boolean).join(" ")}function x(e){let{text:t,emphasis:r}=e;if(!r)return t;let a=t.indexOf(r);return -1===a?t:(0,n.jsxs)(n.Fragment,{children:[t.slice(0,a),(0,n.jsx)("span",{className:"font-semibold text-primary",children:r}),t.slice(a+r.length)]})}function b(e){let{planType:t,compact:r=!1}=e,d=(0,s.c)("pricing"),c=(0,s.c)("upgradeModal.insufficientCredits"),b=(0,p.YB)("pro")?.amount||2e3,v=(0,p.YB)("ultimate")?.amount||5e3,y=(0,p.YB)("max")?.amount||1e4,w=(0,f.Dr)(),I=(0,f.QH)(b),j=(0,f.QH)(v),F=(0,f.QH)(y),N=c("models.title"),C=b.toLocaleString(),R=v.toLocaleString(),k=y.toLocaleString(),A=I.toLocaleString(),S=j.toLocaleString(),M=F.toLocaleString(),_=h(c("benefits.maxImagesPrefix"),C,c("benefits.maxImagesSuffix")),E=h(c("benefits.maxImagesPrefix"),R,c("benefits.maxImagesSuffix")),T=h(c("benefits.maxImagesPrefix"),k,c("benefits.maxImagesSuffix")),L=h(c("benefits.maxVideosPrefix"),A,c("benefits.maxVideosSuffix")),V=h(c("benefits.maxVideosPrefix"),S,c("benefits.maxVideosSuffix")),P=h(c("benef
1its.maxVideosPrefix"),M,c("benefits.maxVideosSuffix")),D=c("benefits.imageEstimateHint"),U=c("benefits.videoEstimateHint",{model:w.modelLabel,resolution:w.resolution,duration:w.durationSeconds,credits:w.creditsPerVideo}),O={[d("features.priorityQueue.title")]:d("features.priorityQueue.tooltip"),[d("features.highestPriority.title")]:d("features.highestPriority.tooltip"),[d("features.refineSpeed.title")]:d("features.refineSpeed.tooltip"),[d("features.privateGen.title")]:d("features.privateGen.tooltip"),[d("features.fullPrivacy.title")]:d("features.fullPrivacy.tooltip"),[d("features.hdImages.title")]:d("features.hdImages.tooltip"),[d("features.aiPhotoEditorSlow.title")]:d("features.aiPhotoEditorSlow.tooltip"),[_]:D,[E]:D,[T]:D,[L]:U,[V]:U,[P]:U,[d("features.noVideoGeneration.title")]:d("features.noVideoGeneration.tooltip")},$={pro:[N,{text:d("features.credits.monthly",{amount:C}),emphasis:C},{text:_,emphasis:C,hasTooltip:!0},{text:L,emphasis:A,hasTooltip:!0},[d("features.priorityQueue.title"),!0],d("features.noWatermarks"),c("benefits.batchImageUpscaling"),[d("features.fullPrivacy.title"),!0]],ultimate:[N,{text:d("features.credits.monthly",{amount:R}),emphasis:R},{text:E,emphasis:R,hasTooltip:!0},{text:V,emphasis:S,hasTooltip:!0},[d("features.highestPriority.title"),!0],d("features.noWatermarks"),c("benefits.batchImageUpscaling"),[d("features.fullPrivacy.title"),!0]],max:[N,{text:d("features.credits.monthly",{amount:k}),emphasis:k},{text:T,emphasis:k,hasTooltip:!0},{text:P,emphasis:M,hasTooltip:!0},[d("features.highestPriority.title"),!0],d("features.noWatermarks"),c("benefits.batchImageUpscaling"),[d("features.fullPrivacy.title"),!0]]},W="pro"===t||"ultimate"===t||"max"===t?$[t]:null;return W?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(a.Jm,{planType:t}),(0,n.jsx)("ul",{className:(0,u.cn)("flex flex-col",r?"gap-2 text-sm leading-5":"gap-3"),children:W.map((e,a)=>{let{text:s,hasTooltip:c,emphasis:p}=Array.isArray(e)?{text:e[0],hasTooltip:e[1],emphasis:void 0}:"string"==typeof e?{text:e,hasTooltip:!1,emphasis:void 0}:{text:e.text,hasTooltip:e.hasTooltip??!1,emphasis:e.emphasis},f=s===d("features.noHdImages")||s===d("features.noVideoGeneration.title")||"pro"===t&&s===d("features.fullPrivacy.title"),h=s===N;return(0,n.jsxs)("li",{className:(0,u.cn)("flex items-start",r?"gap-1.5":"gap-2",h&&"border-t border-border/60 pt-3"),children:[h?null:f?(0,n.jsx)(i.A,{className:(0,u.cn)("shrink-0 text-muted-foreground/70",r?"mt-0.5 size-3.5":"mt-1 size-4")}):(0,n.jsx)(o.A,{className:(0,u.cn)("shrink-0 text-primary",r?"mt-0.5 size-3.5":"mt-1 size-4")}),(0,n.jsxs)("div",{className:f?"flex items-center gap-1 text-muted-foreground":h?"min-w-0 flex-1":"flex items-center gap-1",children:[h?(0,n.jsx)(m,{label:s}):(0,n.jsx)(x,{text:s,emphasis:p}),c&&O[s]?(0,n.jsx)(g.Bc,{children:(0,n.jsxs)(g.m_,{children:[(0,n.jsx)(g.k$,{asChild:!0,children:(0,n.jsx)(l.A,{className:(0,u.cn)("cursor-pointer text-muted-foreground",r?"h-3.5 w-3.5":"h-4 w-4")})}),(0,n.jsx)(g.ZI,{side:"right",children:(0,n.jsx)("p",{className:"w-[200px]",children:O[s]})})]})}):null]})]},a)})})]}):null}},62778:(e,t,r)=>{r.d(t,{VideoFeaturesSection:()=>h});var n=r(4364),a=r(44032),i=r(10731),o=r(51213),l=r(94072),s=r(64648),d=r(14423),u=r(40894);let c=["/video/VideoShowcase/extend-image-1.mp4","/video/VideoShowcase/extend-image-2.mp4","/video/VideoShowcase/extend-image-3.mp4","/video/VideoShowcase/extend-image-4.mp4","/video/VideoShowcase/extend-image-5.mp4"];function m(e){let{src:t,className:r,priority:i=!1}=e,o=(0,a.useRef)(null),l=(0,a.useRef)(null),[s,c]=(0,a.useState)(!1),[m,g]=(0,a.useState)(!1),[p,f]=(0,a.useState)(!1),[h,x]=(0,a.useState)(!1),b=(0,a.useCallback)(()=>{let e=o.current,t=l.current;if(!e||!t)return;let r=t.getContext("2d");r&&(t.width=e.videoWidth,t.height=e.videoHeight,r.drawImage(e,0,0,t.width,t.height),f(!0))},[]),v=(0,a.useCallback)(()=>{let e=o.current;e&&(e.pause(),e.currentTime=0,c(!1),g(!0))},[]),y=(0,a.useCallback)(()=>{let e=o.current;if(e&&h)if(s)e.pause(),c(!1);else{let t=e.play();t&&t.then(()=>c(!0)).catch(()=>{})}},[s,h]);return(0,a.useEffect)(()=>{let e=o.current;if(!e)return;let r=()=>{"true"!==e.dataset.loaded&&(e.src=t,e.dataset.loaded="true",e.load())},n=()=>{x(!0),b();let t=e.play();t&&t.then(()=>c(!0)).catch(()=>{})};if(e.addEventListener("loadeddata",n),e.addEventListener("ended",v),i)r();else{let t=new IntersectionObserver(e=>
1{e.forEach(e=>{e.isIntersecting&&(r(),t.unobserve(e.target))})},{threshold:.2});return t.observe(e),()=>{t.disconnect(),e.removeEventListener("loadeddata",n),e.removeEventListener("ended",v)}}return()=>{e.removeEventListener("loadeddata",n),e.removeEventListener("ended",v)}},[i,t,b,v]),(0,n.jsxs)("div",{className:(0,d.cn)("relative h-full w-full cursor-pointer group",r),onClick:y,children:[(0,n.jsx)("canvas",{ref:l,className:(0,d.cn)("absolute inset-0 h-full w-full object-cover transition-opacity duration-300",s||!p?"opacity-0":"opacity-100")}),(0,n.jsx)("video",{ref:o,className:(0,d.cn)("h-full w-full object-cover transition-opacity duration-300",h?"opacity-100":"opacity-0"),muted:!0,playsInline:!0,preload:"none"}),m&&!s&&(0,n.jsx)("div",{className:"absolute inset-0 flex items-center justify-center transition-opacity duration-200",children:(0,n.jsx)("div",{className:"flex h-14 w-14 items-center justify-center rounded-full bg-black/40 backdrop-blur-sm transition-all duration-200 group-hover:scale-110 group-hover:bg-black/50",children:(0,n.jsx)(u.A,{className:"h-6 w-6 text-white/90 ml-1",fill:"currentColor"})})}),!h&&!p&&(0,n.jsx)("div",{className:"absolute inset-0 bg-card/80 animate-pulse"})]})}function g(e){let{src:t,className:r,priority:a=!1}=e;return(0,n.jsxs)("div",{className:(0,d.cn)("relative overflow-hidden rounded-[10px] lg:rounded-[16px]","border border-border/50 bg-card/50","shadow-[0_20px_60px_rgba(0,0,0,0.25)]",r),children:[(0,n.jsx)(m,{src:t,priority:a,className:"absolute inset-0"}),(0,n.jsx)("div",{className:"absolute inset-0 pointer-events-none bg-gradient-to-tr from-background/70 via-transparent to-foreground/10"})]})}function p(e){let{index:t}=e,r=c[t%c.length];return(0,n.jsx)("div",{className:"w-full flex justify-center",children:(0,n.jsx)(g,{src:r,priority:0===t,className:"w-full max-w-[600px] aspect-[16/9]"})})}function f(e){let{item:t,index:r,total:a,scrollYProgress:l,isDesktop:s}=e,u=r/a,c=(r+1)/a,m=Math.min(1,.88+.03*r),g=(0,i.G)(l,[u,c],[1,m]),f=(0,i.G)(l,[u,c],[0,-10+1.5*r]),h=(0,i.G)(l,[u,c],[1,.72]),x=(0,i.G)(l,[u,c],[0,.6]);return(0,n.jsxs)(o.P.article,{className:(0,d.cn)("relative origin-top bg-card/70 rounded-[16px] lg:rounded-[32px] overflow-hidden","border border-border/40 shadow-[0_-30px_90px_rgba(0,0,0,0.35)]","lg:sticky lg:top-[60px]"),style:{transformOrigin:"center top",transformStyle:"preserve-3d",zIndex:20+10*r,...s?{scale:g,rotateX:f,opacity:h}:{scale:1,rotateX:0,opacity:1}},children:[(0,n.jsxs)("div",{className:"flex flex-col gap-10 p-6 lg:flex-row lg:items-center lg:p-[120px] lg:gap-24 max-w-[1400px] mx-auto",children:[(0,n.jsxs)("div",{className:"flex flex-col items-start lg:flex-[2]",children:[t.tag&&(0,n.jsx)("span",{className:"text-xs uppercase tracking-[0.28em] text-muted-foreground/80",children:t.tag}),(0,n.jsx)("h3",{className:"flex flex-col text-2xl mt-4 lg:text-3xl 2xl:text-4xl font-semibold text-foreground",children:t.title}),(0,n.jsx)("p",{className:"text-lg text-muted-foreground mt-4 leading-relaxed",children:t.description}),t.highlights?.length?(0,n.jsx)("div",{className:"flex flex-wrap gap-2 mt-6",children:t.highlights.map(e=>(0,n.jsx)("span",{className:"text-xs text-foreground/80 bg-secondary/60 border border-border/50 px-3 py-1 rounded-full",children:e},e))}):null]}),(0,n.jsx)("div",{className:"lg:flex-[3] overflow-hidden",children:(0,n.jsx)(p,{index:r})})]}),(0,n.jsx)(o.P.div,{className:"absolute inset-0 bg-background pointer-events-none",style:{opacity:s?x:0}})]})}function h(e){let{section:t}=e;if(!t?.items?.length)return null;let r=(0,a.useRef)(null),{scrollYProgress:i}=(0,l.L)({target:r,offset:["start start","end start"]}),o=(0,s.U)("(min-width: 1024px)");return(0,n.jsxs)("section",{ref:r,className:"w-full py-16 lg:py-24",style:{perspective:"800px"},children:[(0,n.jsx)("div",{className:"mx-auto max-w-[1400px] px-4 lg:px-20",children:(0,n.jsxs)("div",{className:"text-center",children:[(0,n.jsx)("h2",{className:"text-3xl lg:text-4xl font-semibold text-foreground",children:t.title}),t.description?(0,n.jsx)("p",{className:"mt-4 text-lg text-muted-foreground max-w-2xl mx-auto",children:t.description}):null]})}),(0,n.jsxs)("div",{className:"mt-12 flex flex-col gap-8 px-4 lg:px-20",children:[t.items.map((e,r)=>(0,n.jsx)(f,{item:e,index:r,total:t.items.length,scrollYProgress:i,isDesktop:o},e.title)),(0,n.jsx)("div",{className:"h-[12vh]"})]})]})}},69751:(e,t,r)=>{r.d(t,{E0:()=>c,HX:()=>I,Lx:()=>d,QX:()=>N,Sk:()=>u,TI:()=>L,Xd:()=>g,dZ:()=>F,px:()=>T,v5:()=>p,wD:()=>m,wI:()=>E,yn:()=>C});var n=r(46247),a=r(360),i=r(24985),o=r(13886),l=r(81714),s=r(38052);let d=0xa00000,u=15,c=2,m=15,g=15,p="MP3 / WAV",f="__raphaelReferenceVideoDurationSeconds",h=new Set(["audio/mpeg","audio/mp3","audio/wav","audio/wave","audio/x-wav","audio/vnd.wav"]);function x(e){return`${(e/1048576).toFixed(e>=0xa00000?0:1)}MB`}function b(e){return e.name||"file"}function v(e,t,r){let n=new Int16Array(r);for(let a=0;a<r;
1a+=1){let r=Math.max(-1,Math.min(1,e[t+a]??0));n[a]=r<0?32768*r:32767*r}return n}async function y(e){let t=await e.arrayBuffer(),n=new AudioContext;try{let a,i=await n.decodeAudioData(t.slice(0)),o=Math.min(2,Math.max(1,i.numberOfChannels)),l=i.sampleRate,s=i.getChannelData(0),d=o>1?i.getChannelData(1):void 0,{Mp3Encoder:u}=await r.e(5377).then(r.t.bind(r,35377,19)),c=new u(o,l,96),m=[];for(let e=0;e<i.length;e+=1152){let t=Math.min(1152,i.length-e),r=v(s,e,t),n=d&&o>1?v(d,e,t):void 0,a=n?c.encodeBuffer(r,n):c.encodeBuffer(r);a.length>0&&m.push(a)}let g=c.flush();return g.length>0&&m.push(g),new File(m,(a=b(e).replace(/\.[^.]+$/,""),`${a||"audio"}.mp3`),{type:"audio/mpeg"})}finally{await n.close().catch(()=>void 0)}}let w=new Map;function I(e,t){e.forEach((e,r)=>{let n=t[r];e&&"number"==typeof n&&Number.isFinite(n)&&n>0&&w.set(e,n)})}function j(e){if("string"==typeof e)return w.get(e)??0;let t=e[f];return"number"==typeof t&&Number.isFinite(t)?t:0}function F(e){return e.reduce((e,t)=>e+j(t),0)}async function N(e){let t=j(e);if(t>0)return t;let r=await C(e);return Number.isFinite(r.duration)?r.duration:0}function C(e){return new Promise((t,r)=>{let n=document.createElement("video"),a=e instanceof File?URL.createObjectURL(e):null,i=window.setTimeout(()=>{o(),r(Error("Video metadata timeout"))},12e3),o=()=>{window.clearTimeout(i),n.removeAttribute("src"),n.load(),a&&URL.revokeObjectURL(a)};n.preload="metadata",n.muted=!0,n.playsInline=!0,n.onloadedmetadata=()=>{let e=Number.isFinite(n.duration)?n.duration:0,r=n.videoWidth||0,a=n.videoHeight||0;o(),t({duration:e,width:r,height:a})},n.onerror=()=>{o(),r(Error("Failed to load video metadata"))},n.src=a??("string"==typeof e?e:"")})}function R(e){return new Promise((t,r)=>{let n=document.createElement("audio"),a=e instanceof File?URL.createObjectURL(e):null,i=window.setTimeout(()=>{o(),r(Error("Audio metadata timeout"))},12e3),o=()=>{window.clearTimeout(i),n.removeAttribute("src"),n.load(),a&&URL.revokeObjectURL(a)};n.preload="metadata",n.onloadedmetadata=()=>{let e=Number.isFinite(n.duration)?n.duration:0;o(),t(e)},n.onerror=()=>{o(),r(Error("Failed to load audio metadata"))},n.src=a??("string"==typeof e?e:"")})}async function k(e,t){let{policy:r}=t,n=t.imageMaxBytes??r.image.maxBytes;if(!["image/jpeg","image/png","image/webp"].includes(e.type.toLowerCase()))return{error:{code:"unsupported_file_type",mediaType:"image",fileName:b(e),formats:r.image.formatsLabel}};try{let{file:t}=await (0,a.n)(e,{...r.image,provider:"evolink",maxBytes:n});if(t.size>n)return{error:{code:"file_too_large",mediaType:"image",fileName:b(e),maxSize:x(n)}};let{width:i,height:o}=await (0,s.vX)(t);if(!(0,l.SZ)(i,o,r.image.minEdge,r.image.maxEdge))return{error:{code:"image_dimensions_invalid",mediaType:"image",fileName:b(e),minEdge:r.image.minEdge,maxEdge:r.image.maxEdge}};if(!(0,l.Fl)(i,o,r.image.minAspectRatio,r.image.maxAspectRatio))return{error:{code:"aspect_ratio_invalid",mediaType:"image",fileName:b(e),minAspectRatio:r.image.minAspectRatio,maxAspectRatio:r.image.maxAspectRatio}};return{file:t}}catch(t){if(t instanceof i.Qv)return{error:t.detail};return{error:{code:"read_failed",mediaType:"image",fileName:b(e)}}}}async function A(e,t){let r;if(!t.video.mimeTypes.has(e.type.toLowerCase()))return{error:{code:"unsupported_file_type",mediaType:"video",fileName:b(e),formats:t.video.formatsLabel}};try{r=await C(e)}catch{return{error:{code:"read_failed",mediaType:"video",fileName:b(e)}}}if(r.duration<t.video.durationSeconds[0]||r.duration>t.video.durationSeconds[1])return{error:{code:"duration_invalid",mediaType:"video",fileName:b(e),minDurationSeconds:t.video.durationSeconds[0],maxDurationSeconds:t.video.durationSeconds[1]}};if(void 0!==t.video.minAspectRatio&&void 0!==t.video.maxAspectRatio&&!(0,l.Fl)(r.width,r.height,t.video.minAspectRatio,t.video.maxAspectRatio))return{error:{code:"aspect_ratio_invalid",mediaType:"video",fileName:b(e),minAspectRatio:t.video.minAspectRatio,maxAspectRatio:t.video.maxAspectRatio}};if(e.size>t.video.maxBytes)return{error:{code:"file_too_large",mediaType:"video",fileName:b(e),maxSize:x(t.video.maxBytes)}};let n=r.width*r.height,a=void 0!==t.video.minEdge&&void 0!==t.video.maxEdge&&!(0,l.SZ)(r.width,r.height,t.video.minEdge,t.video.maxEdge),i=void 0!==t.video.minPixels&&n<t.video.minPixels||void 0!==t.video.maxPixels&&n>t.video.maxPixels;
1return a||i?{error:{code:"video_resolution_invalid",mediaType:"video",fileName:b(e),resolutionHint:t.video.resolutionHint}}:{file:function(e,t){if(!Number.isFinite(t)||t<=0)return e;try{Object.defineProperty(e,f,{value:t,configurable:!0})}catch{e[f]=t}return e}(e,r.duration),metadata:r}}async function S(e,t){let r;if(!h.has(e.type))return{error:{code:"unsupported_file_type",mediaType:"audio",fileName:b(e),formats:p}};let n="audio/wav"===(r=e.type.toLowerCase())||"audio/wave"===r||"audio/x-wav"===r||"audio/vnd.wav"===r||e.name.toLowerCase().endsWith(".wav"),a=n?0x3200000:0xf00000;if(e.size>a)return{error:{code:"file_too_large",mediaType:"audio",fileName:b(e),maxSize:x(a)}};try{let r=await R(e);if(r<t.minSeconds||r>t.maxSeconds)return{error:{code:"duration_invalid",mediaType:"audio",fileName:b(e),minDurationSeconds:t.minSeconds,maxDurationSeconds:t.maxSeconds}};let a=n?await y(e):e;if(a.size>0xf00000)return{error:{code:"file_too_large",mediaType:"audio",fileName:b(e),maxSize:x(0xf00000)}};return{file:a,duration:r}}catch{return{error:{code:"read_failed",mediaType:"audio",fileName:b(e)}}}}async function M(e){try{let t=await C(e);return Number.isFinite(t.duration)?t.duration:0}catch{return 0}}async function _(e){try{return await R(e)}catch{return 0}}async function E(e){let{files:t,existingImages:r,existingVideos:n,existingAudios:a,imageLimit:i,videoLimit:o,audioLimit:s,totalLimit:d,imageMaxBytes:p,modelId:f}=e,h=(0,l.Vu)(f,e.resolution),x="seedance-2.5"===f||f?.startsWith("seedance-2.5-"),v=x?30:u,y=x?30:m,w=x?30:g,I=[],j=[],F=[],N=[],C=0,R=0;for(let e of n)C+=await M(e);for(let e of a)R+=await _(e);for(let e of t){let t=function(e){let t=[...e.imageLimit>0?[e.policy.image.formatsLabel]:[],...e.videoLimit>0?[e.policy.video.formatsLabel]:[],...e.audioLimit>0?["MP3","WAV"]:[]];return t.length>0?t.join(" / "):"JPG / PNG / WebP"}({imageLimit:i,videoLimit:o,audioLimit:s,policy:h}),l=r.length+n.length+a.length;if(void 0!==d&&l+I.length+j.length+F.length>=d){N.push({code:"count_limit_exceeded",mediaType:"media",maxCount:d});continue}if(e.type.startsWith("image/")){if(i<=0){N.push({code:"unsupported_file_type",mediaType:"image",fileName:b(e),formats:t});continue}if(r.length+I.length>=i){N.push({code:"count_limit_exceeded",mediaType:"image",maxCount:i});continue}let n=await k(e,{imageMaxBytes:p,policy:h});n.file?I.push(n.file):n.error&&N.push(n.error);continue}if(e.type.startsWith("video/")){if(o<=0){N.push({code:"unsupported_file_type",mediaType:"video",fileName:b(e),formats:t});continue}if(n.length+j.length>=o){N.push({code:"count_limit_exceeded",mediaType:"video",maxCount:o});continue}let r=await A(e,h);if(!r.file||!r.metadata){r.error&&N.push(r.error);continue}if(C+r.metadata.duration>v){N.push({code:"total_duration_exceeded",mediaType:"video",maxTotalDurationSeconds:v});continue}C+=r.metadata.duration,j.push(r.file);continue}if(e.type.startsWith("audio/")){if(s<=0){N.push({code:"unsupported_file_type",mediaType:"audio",fileName:b(e),formats:t});continue}if(a.length+F.length>=s){N.push({code:"count_limit_exceeded",mediaType:"audio",maxCount:s});continue}let r=await S(e,{minSeconds:c,maxSeconds:y});if(!r.file||"number"!=typeof r.duration){r.error&&N.push(r.error);continue}if(R+r.duration>w){N.push({code:"total_duration_exceeded",mediaType:"audio",maxTotalDurationSeconds:w});continue}R+=r.duration,F.push(r.file);continue}N.push({code:"unsupported_file_type",mediaType:"media",fileName:b(e),formats:t})}return{images:I,videos:j,audios:F,errors:Array.from(new Map(N.map(e=>[JSON.stringify(e),e])).values())}}async function T(e){let t=e.maxAttempts??3,r=e.timeoutMs??24e4;return await (0,o.ad)({file:e.file,endpoint:"/api/video/upload-input",context:{model_id:e.modelId,resolution:e.resolution??"",client_request_id:e.clientRequestId,media_type:e.mediaType,slot_name:e.slotName},analytics:{toolType:e.toolType,modelId:e.modelId,mediaType:e.mediaType,surfaceType:e.surfaceType},timeoutMs:r,maxAttempts:t,signal:e.signal,onProgress:e.onProgress,onAuthorization:e.onAuthorization})}async function L(e){let t,r=[...e.images,...e.videos,...e.audios],a=new AbortController;try{t=await Promise.all(r.map(async e=>{if(e instanceof File)return e;let t=await (0,n.H3)(e,{signal:a.signal});return new File([t],"retained-input",{type:t.type})}))}catch(e){throw a.abort(),Object.assign(new i.Qv({code:"read_failed",mediaType:"media"}),{cause:e})}let o=[...e.images.map(()=>"image"),...e.videos.map(()=>"video"),...e.audios.map(()=>"audio")];t.forEach((e,t)=>{if(!e.type.startsWith(`${o[t]}/`))throw new i.Qv({code:"unsupported_file_type",mediaType:"media",fileName:e.name})});let l=await E({...e,files:t,existingImages:[],existingVideos:[],existingAudios:[]});if(l.errors.length)throw new i.Qv(l.errors[0]);let s=(e,n)=>e.map((e,a)=>e===t[n+a]?r[n+a]:e);return{images:s(l.images,0),videos:s(l.videos,e.images.length),audios:s(l.audios,e.images.length+e.videos.length)}}},77232:(e,t,r)=>{r.d(t,{E:()=>n});function n(e){let t=e.windowObject??window,r=e.navigatorObject??("u"<typeof navigator?void 0:navigator),n=e.fetcher??fetch,a=!0,i=e.endpoint,o=e.body,l=()=>{if(o instanceof FormData)return{beacon:o,fetch:o};let e=JSON.stringify(o);return{beacon:new Blob([e],{type:"application/json"}),fetch:e,headers:{"Content-Type":"application/json"}}},s=()=>{let e=l();return n(i,{method:"POST",...e.headers?{headers:e.headers}:{},body:e.fetch,keepalive:!0}).then(()=>void 0)},d=()=>t?.removeEventListener("pagehide",c),u=()=>{a&&(a=!1,d())},c=()=>
1{if(!a)return;a=!1,d();let e=l();if(r?.sendBeacon)try{r.sendBeacon(i,e.beacon)}catch{}s().catch(()=>void 0)};return t?.addEventListener("pagehide",c),{disarm:u,update:e=>{a&&(e.endpoint&&(i=e.endpoint),e.body&&(o=e.body))},cancel:async()=>{a&&(u(),await s())}}}},81714:(e,t,r)=>{r.d(t,{Fl:()=>c,SZ:()=>u,Vu:()=>d,bq:()=>s,fe:()=>l});var n=r(50288);let a={image:{maxBytes:0x1e00000,mimeTypes:new Set(["image/jpeg","image/png","image/webp"]),formatsLabel:"JPG / PNG / WebP",minEdge:300,maxEdge:6e3,minAspectRatio:.4,maxAspectRatio:2.5},video:{maxBytes:n._z,mimeTypes:new Set(["video/mp4","video/quicktime"]),formatsLabel:"MP4 / MOV",durationSeconds:[2,15],minAspectRatio:.4,maxAspectRatio:2.5,minPixels:409600,maxPixels:2086876,resolutionHint:"480p / 720p / 1080p"}},i={image:{maxBytes:0x1e00000,mimeTypes:new Set(["image/jpeg","image/png","image/webp"]),formatsLabel:"JPG / PNG / WebP",minEdge:256,maxEdge:5760,minAspectRatio:.4,maxAspectRatio:2.5},video:{maxBytes:n._z,mimeTypes:new Set(["video/mp4","video/quicktime"]),formatsLabel:"MP4 / MOV",durationSeconds:[2,15],minAspectRatio:.4,maxAspectRatio:2.5,minEdge:256,maxEdge:5760,resolutionHint:"宽高各 256-5760px"}},o={image:{maxBytes:0x1e00000,mimeTypes:new Set(["image/jpeg","image/png","image/webp"]),formatsLabel:"JPG / PNG / WebP",minEdge:300,maxEdge:6e3,minAspectRatio:.4,maxAspectRatio:2.5},video:{maxBytes:n._z,mimeTypes:new Set(["video/mp4","video/quicktime"]),formatsLabel:"MP4 / MOV",durationSeconds:[2,30]}};function l(e){return!!e&&("minimax-h3"===e||"hailuo-3"===e||e.startsWith("minimax-h3-"))}function s(e){return!!e&&("minimax-h3-max"===e||e.startsWith("minimax-h3-max-"))}function d(e,t){let r="seedance-2.5"===e||e?.startsWith("seedance-2.5-")?o:l(e)?i:a,s=(0,n.LQ)(e,t),d=e?.startsWith("veo-")||e?.startsWith("gemini-");return{...r,image:{...r.image,...s,maxBytes:s.maxBytes??n._z,minEdge:s.minEdge??(d?r.image.minEdge:1),maxEdge:s.maxEdge??(d?r.image.maxEdge:Number.MAX_SAFE_INTEGER),minAspectRatio:s.minAspectRatio??(d?r.image.minAspectRatio:0),maxAspectRatio:s.maxAspectRatio??(d?r.image.maxAspectRatio:Number.MAX_SAFE_INTEGER)}}}function u(e,t,r,n){return e>=r&&t>=r&&e<=n&&t<=n}function c(e,t,r,n){if(!t)return!1;let a=e/t;return a>=r&&a<=n}},87423:(e,t,r)=>{r.d(t,{Yl:()=>n,ko:()=>i,ws:()=>o,xM:()=>l});let n="raphael:home-video-example",a=null;function i(e,t){a={draft:{...e,autoSubmit:!1},selection:t},window.dispatchEvent(new Event("raphael:activate-video-generator")),window.dispatchEvent(new Event(n)),window.scrollTo({top:0,behavior:matchMedia("(prefers-reduced-motion: reduce)").matches?"auto":"smooth"})}function o(){return a}function l(e){a===e&&(a=null)}},89917:(e,t,r)=>{r.r(t),r.d(t,{PricingClient:()=>k});var n=r(4364),a=r(44032),i=r(67864),o=r(41166),l=r(23955),s=r(91760),d=r(30869),u=r(94160),c=r(9115),m=r(89113),g=r(2530),p=r(48041),f=r(63035),h=r(69893),x=r(72755),b=r(80668),v=r(45001),y=r(99909),w=r(50278),I=r(14423),j=r(61564),F=r(10785),N=r(3549);let C="raphael_subscription_checkout_started";function R(){try{window.localStorage.removeItem(C)}catch{}}function k(e){let{user:t,analyticsSurface:r}=e,k=(0,l.c)("pricing"),A=(0,s.Ym)(),{setShowSignModal:S}=(0,u.U)(),{trackEvent:M}=(0,g.s)(),[_,E]=(0,a.useState)("yearly"),[T,L]=(0,a.useState)("yearly");(0,a.useEffect)(()=>{if("pricing_page"!==r)return;let e=()=>{E("yearly"),L("yearly")};return window.addEventListener(N.g,e),()=>window.removeEventListener(N.g,e)},[r]);let[V,P]=(0,a.useState)(null),D=(0,a.useRef)(null),U=(0,a.useRef)(!1),O=k("creditPacks.tab"),$=(0,m.e)(t?.membership?.paymentGateway),W=!!(t?.plan&&"free"!==t.plan),q=t?.membership?.paymentGateway==="admin";(0,j.Z)(()=>{P(null),R()}),(0,a.useEffect)(()=>{M("pricing_page_viewed",{billing_type:"credit_packs"===_?"credit_packs":T},p.E)},[_,T,M]),(0,a.useEffect)(()=>{let e=D.current;if(!e||U.current)return;let t=null,n=()=>{null!==t&&(window.clearTimeout(t),t=null)},a=()=>{U.current||(U.current=!0,M("pricing_component_view_qualified",{surface_type:r,engagement_ms:1e3,visible_ratio:.25},p.E))};if(!("IntersectionObserver"in window))return void a();let i=new IntersectionObserver(e=>{let[r]=e;!r?.isIntersecting||r.intersectionRatio<.25?n():null===t&&(t=window.setTimeout(()=>{t=null,a(),i.disconnect()},1e3))},{threshold:[0,.25]});return i.observe(e),()=>{n(),i.disconnect()}},[r,M]),(0,a.useEffect)(()=>{("credit_packs"===new URLSearchParams(window.location.search).get("tab")||"#credit-packs"===window.location.hash)&&E("credit_packs")},[]);let H=[{name:k("plans.pro.name"),type:"pro",price:{monthly:"--",yearly:"--"},button:{text:k("plans.pro.button")}},{name:k("plans.ultimate.name"),type:"ultimate",price:{monthly:"--",yearly:"--"},button:{text:k("plans.ultimate.button")}},{name:k("plans.max.name"),type:"max",price:{monthly:"--",yearly:"--"},button:{text:k("plans.max.button")}},{name:"Enterprise",type:"enterprise",price:{monthly:k("plans.enterprise.price"),yearly:k("plans.enterprise.price")},button:{text:k("plans.enterprise.button")}}].filter(e=>"enterprise"!==e.type).map(e=>{let t=(0,c.fm)(e.type)?(0,c.RQ)(e.type,"monthly"):null,r=(0,c.fm)(e.type)?(0,c.RQ)(e.type,"yearly"):null,n="Enterprise"===e.name||!!("monthly"===T?t:r);return{...e,price:{monthly:t??e.price.monthly,yearly:r??e.price.yearly},hasValidPrice:n}}),B=async e=>{let n=(0,c.fm)(e)?(0,c.RQ)(e,T):null,a=n?Number(n):null,i=null!==a&&Number.isFinite(a)?"yearly"===T?12*a:a:null,o={plan_type:e,billing_type:T,payment_provider:"configured",checkout_entry:"pricing",checkout_surface:r,...null!==i?{currency:"USD",value:i}:{}};if(M("plan_selected",o),!t){M("paywall_shown",{...o,paywall_reason:"login_required"}),S(!0,"pricing");return}if(W&&(0,c.fm)(e)){if(M("upgrade_cta_clicked",{...o,cta_location:"pricing_existing_subscription"}),$)return void window.open($,"_blank","noopener,noreferrer");if(!q)return void d.oR.error(k("errors.processingFailed"),{duration:3e3})}if(!(0,c.fm)(e))return;let l=`${e}:${T}`;P(l);let s=(0,h.VU)(),u=(0,h.zz)(s);try{window.localStorage.setItem(C,JSON.stringify({checkoutKey:l,at:Date.now()}))}catch{}M("checkout_intent",{...o,redirect_method:s});let m=!1;try{let t=await fetch("/api/billing/subscription-checkouts",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({plan_type:e,billing_interval:T,return_to:(0,x.D)(),language:A,analytics_context:{...(0,f.SK)("pricing"),checkout_surface:r,redirect_method:s}})}),n=await t.json();if(0===n.code&&n.data.checkout_url){let e=(0,h.oU)(s,u);M("checkout_link_created",{...o,payment_provider:n.data.payment_provider??"configured",redirect_method:e}),M("checkout_redirected",{...o,payment_provider:n.data.payment_provider??"configured",redirect_method:e}),(0,h.jP)(n.data.checkout_url,u,e),m=(0,h.iq)(e)}else M("checkout_link_failed",{...o,failure_reason:"api_error"}),u?.close(),R(),console.error("Subscription request failed:",n?.message),d.oR.error(k("errors.processingFailed"),{duration:3e3})}catch(e){M("checkout_link_failed",{...o,failure_reason:"network_error"}),u?.close(),R(),d.oR.error(k("errors.processingFailed"),{duration:3e3}),console.error("Subscription request error:",e)}finally{m||P(null)}},z=e=>
1{("monthly"===e||"yearly"===e||"credit_packs"===e)&&(E(e),("monthly"===e||"yearly"===e)&&L(e))},G=function(e,t){let r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},a=_===e;return(0,n.jsxs)("button",{type:"button",onClick:()=>z(e),className:(0,I.cn)("flex h-9 items-center gap-2 rounded-full px-4 text-sm font-medium transition sm:px-5",a?"bg-primary text-primary-foreground shadow-sm":"text-muted-foreground hover:text-foreground"),children:[t,r.showDiscount?(0,n.jsx)(y.u,{className:"h-4 px-1.5 text-[10px]"}):null]})},X=()=>(0,n.jsx)(w.K,{children:H.map(e=>{if(!(0,c.fm)(e.type))return null;let t=(0,F.l)(e.type,T),r=W&&!!$,a=`${e.type}:${T}`,l=W&&!$&&!q;return(0,n.jsx)(w.x,{planType:e.type,planName:e.name,billingInterval:T,monthlyPrice:e.price.monthly,yearlyMonthlyPrice:e.price.yearly,badgeLabel:t?k("recommended"):void 0,isRecommended:t,action:l?null:(0,n.jsx)(i.$,{className:"h-9 w-full shadow-lg shadow-primary/30 hover:shadow-xl",disabled:!e.hasValidPrice||V===a,style:e.hasValidPrice?void 0:{pointerEvents:"none",opacity:.6},onClick:()=>B(e.type),children:V===a?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(o.A,{className:"mr-2 h-4 w-4 animate-spin"}),k("checkout.preparing")]}):r?k("manageSubscription"):e.button.text})},e.type)})});return(0,n.jsx)("div",{ref:D,children:(0,n.jsxs)(b.Tabs,{value:_,onValueChange:z,className:"w-full",children:[(0,n.jsx)("div",{className:"mb-8 flex justify-center",children:(0,n.jsxs)("div",{className:"flex max-w-full flex-wrap items-center gap-1 rounded-full border border-border/40 bg-muted/30 p-1 shadow-sm",children:[G("monthly",k("billing.monthly")),G("yearly",k("billing.yearly"),{showDiscount:!0}),G("credit_packs",O)]})}),(0,n.jsx)(b.TabsContent,{value:"monthly",className:"mt-0",children:X()}),(0,n.jsx)(b.TabsContent,{value:"yearly",className:"mt-0",children:X()}),(0,n.jsx)(b.TabsContent,{value:"credit_packs",className:"mt-0",children:(0,n.jsx)(v.Y,{user:t,surface:r,variant:"pricing"})})]})})}},98121:(e,t,r)=>{r.d(t,{A:()=>u});var n=r(4364),a=r(70121),i=r(44032);let o="[email protected]",l=`<!--email_off-->${o}<!--/email_off-->`;function s(e){let{className:t}=e;return(0,n.jsx)("span",{className:t,dangerouslySetInnerHTML:{__html:l}})}function d(e){let{text:t,emailClassName:r}=e;if(!t)return null;let a=t.split(o);return 1===a.length?(0,n.jsx)(n.Fragment,{children:t}):(0,n.jsx)(n.Fragment,{children:a.map((e,t)=>(0,n.jsxs)(i.Fragment,{children:[e,t<a.length-1?(0,n.jsx)(s,{className:r}):null]},`${e}-${t}`))})}function u(e){let{section:t}=e;return t.disabled?null:(0,n.jsx)("section",{id:t.name,className:"py-16",children:(0,n.jsxs)("div",{className:"container",children:[(0,n.jsxs)("div",{className:"text-center",children:[t.label&&(0,n.jsx)(a.E,{className:"text-xs font-medium",children:t.label}),(0,n.jsx)("h2",{className:"mt-4 text-3xl sm:text-4xl font-bold text-foreground tracking-tight",children:t.title}),(0,n.jsx)("p",{className:"mt-6 text-base font-medium text-foreground/70",children:(0,n.jsx)(d,{text:t.description})})]}),(0,n.jsx)("div",{className:"mx-auto mt-14 grid gap-8 md:grid-cols-2 md:gap-12",children:t.items?.map((e,t)=>(0,n.jsxs)("div",{className:"flex gap-4",children:[(0,n.jsx)("span",{className:"flex size-6 shrink-0 items-center justify-center rounded-sm border border-primary font-mono text-xs text-primary",children:t+1}),(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{className:"mb-2 flex items-center justify-between",children:(0,n.jsx)("h3",{className:"text-xl font-bold text-foreground",children:e.title})}),(0,n.jsx)("p",{className:"text-base text-foreground/70 leading-relaxed",children:(0,n.jsx)(d,{text:e.description})})]})]},t))})]})})}}}]);

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.