jmpplbp's picture
Show held points in the owned balance
addbdcc verified
Raw History Blame Contribute Delete
41.9 kB
(()=>{var me=["cream","cream2","mllti","fella","moving"],pe={cream:"zamen1",cream2:"zamen2",mllti:"dynamic move",moving:"dynamic move2",fella:"fella"},Ze=["cream","cream2","mllti","moving","fella"],Le=()=>Object.fromEntries(me.map(t=>[t,0]));function Ee(t,e){let a=me.filter(u=>{let d=e[u];if(!Number.isFinite(d)||d<0||d>2)throw new Error("LoRA strength must be between 0 and 2: "+u);return d!==0});if(!a.length)return;let o=Object.entries(t).filter(([,u])=>u.class_type==="CheckpointLoaderSimple");if(o.length!==1)throw new Error("Expected one VIDEO checkpoint loader");let i=o[0][0],s=Object.values(t).flatMap(u=>Object.entries(u.inputs).filter(([,d])=>Array.isArray(d)&&d[0]===i&&d[1]===0).map(([d])=>({node:u,key:d})));if(!s.length)throw new Error("VIDEO checkpoint model has no consumers");let l=[i,0];for(let u of a){let d="video_user_lora_"+u;if(t[d])throw new Error("LoRA node already exists: "+d);t[d]={class_type:"LoraLoaderModelOnly",inputs:{model:l,lora_name:u+".safetensors",strength_model:e[u]},_meta:{title:u}},l=[d,0]}for(let{node:u,key:d}of s)u.inputs[d]=l}function Me(t){let e=document.createElement("fieldset");e.className="video-loras",e.id="video-loras";let a=document.createElement("legend");a.textContent="LoRA",e.append(a);let o=document.createElement("p");o.className="hint",o.textContent="0 = \u7121\u52B9 / 1 = \u6A19\u6E96\u306E\u5F37\u3055\u3002\u8907\u6570\u3092\u540C\u6642\u306B\u4F7F\u7528\u3067\u304D\u307E\u3059\u3002",e.append(o);for(let s of Ze){let l=document.createElement("div");l.className="video-lora-control";let u=document.createElement("label");u.htmlFor="lora-"+s,u.textContent=pe[s];let d=document.createElement("input");d.type="range",d.setAttribute("aria-label",pe[s]+" LoRA \u5F37\u3055"),d.dataset.loraSlider=s;let c=document.createElement("input");c.type="number",c.id="lora-"+s,c.name="lora_"+s,c.required=!0,c.setAttribute("aria-label",pe[s]+" LoRA \u5F37\u3055\uFF08\u6570\u5024\uFF09");for(let _ of[d,c])_.min="0",_.max="2",_.step="0.05",_.value=String(t[s]);d.addEventListener("input",()=>{t[s]=d.valueAsNumber,c.value=d.value}),c.addEventListener("input",()=>{c.validity.valid&&(t[s]=c.valueAsNumber,d.value=c.value)}),l.append(u,d,c),e.append(l)}let i=document.createElement("button");return i.type="button",i.textContent="\u3059\u3079\u3066\u7121\u52B9\u306B\u3059\u308B",i.addEventListener("click",()=>{for(let s of me)t[s]=0;for(let s of e.querySelectorAll("input"))s.value="0"}),e.append(i),e}function ke(t,e){return t==="video-flow"&&/^(i2v|t2v)/.test(e)?64:["video-flow","video-fusion","image-edit-super","image-studio"].includes(t)?32:t==="image-canvas"?64:16}function j(t,e){return t.startsWith("image-")||t==="media-enhance"&&e==="image"?1024:768}function Se(t,e,a=!1){return a?256:t==="video-flow"&&/^(i2v|t2v)/.test(e)?128:64}function Ce(t,e,a=768,o=64){if(!Number.isFinite(t.width)||!Number.isFinite(t.height)||t.width<=0||t.height<=0)throw Error("\u7D20\u6750\u306E\u30B5\u30A4\u30BA\u3092\u8AAD\u307F\u53D6\u308C\u307E\u305B\u3093\u3002");let i=Math.min(1,a/Math.max(t.width,t.height)),s=Math.round(t.width*i/e)*e,l=Math.round(t.height*i/e)*e;if(Math.min(s,l)<o)throw Error("\u3053\u306E\u7D20\u6750\u306F\u7E26\u6A2A\u6BD4\u3092\u4FDD\u3063\u3066\u8ABF\u6574\u3059\u308B\u3068\u77ED\u8FBA\u304C"+o+"px\u672A\u6E80\u306B\u306A\u308A\u307E\u3059\u3002\u9577\u8FBA"+a+"px\u4EE5\u5185\u30FB\u77ED\u8FBA"+o+"px\u4EE5\u4E0A\u306B\u306A\u308B\u753B\u50CF\u3084\u52D5\u753B\u3092\u9078\u3093\u3067\u304F\u3060\u3055\u3044\u3002");return{width:s,height:l}}function Fe(t){let e={width:0,height:0};for(let a of["width","height"])for(let o of Object.values(t)){let i=o._meta?.title||"";new RegExp("(?:^|\\s)"+a+"(?:$|\\s)","i").test(i)&&typeof o.inputs.value=="number"&&(e[a]=o.inputs.value);for(let s of[a,"resize_type."+a,"custom_"+a]){let l=o.inputs[s];typeof l=="number"&&l>0&&!e[a]&&(e[a]=l)}}return{width:e.width||768,height:e.height||768}}function K(t,e){for(let a of Object.values(t))for(let o of["width","height"]){for(let i of[o,"custom_"+o,"resize_type."+o])typeof a.inputs[i]=="number"&&(a.inputs[i]=e[o]);if(new RegExp("(?:^|\\s)"+o+"(?:$|\\s)","i").test(a._meta?.title||"")&&(/^Primitive(?:Int|Float)$/.test(a.class_type)&&typeof a.inputs.value=="number"&&(a.inputs.value=e[o]),a.class_type==="mxSlider"))for(let i of["Xi","Xf"])typeof a.inputs[i]=="number"&&(a.inputs[i]=e[o])}}function we(t,e,a){for(let o of new Set(e.map(i=>i[0]))){if(!/loadimage/i.test(t[o]?.class_type||""))continue;let i="input_size_"+o;for(;t[i];)i+="_";for(let s of Object.values(t))for(let[l,u]of Object.entries(s.inputs))Array.isArray(u)&&String(u[0])===o&&u[1]===0&&(s.inputs[l]=[i,0]);t[i]={class_type:"ImageScale",inputs:{image:[o,0],upscale_method:"lanczos",width:a.width,height:a.height,crop:"disabled"}}}}async function Ge(t,e,a){if(e==="audio")return null;let o=URL.createObjectURL(t);try{return await new Promise((i,s)=>{let l=document.createElement(e==="image"?"img":"video"),u=setTimeout(()=>d(new Error("\u7D20\u6750\u306E\u30B5\u30A4\u30BA\u78BA\u8A8D\u304C\u30BF\u30A4\u30E0\u30A2\u30A6\u30C8\u3057\u307E\u3057\u305F\u3002")),15e3);function d(c){clearTimeout(u),l.onerror=null,!c&&a!==void 0&&l instanceof HTMLVideoElement&&(!Number.isFinite(l.duration)||l.duration<=0?c=new Error("\u7D20\u6750\u52D5\u753B\u306E\u9577\u3055\u3092\u78BA\u8A8D\u3067\u304D\u307E\u305B\u3093\u3002"):l.duration>a&&(c=new Error("\u7D20\u6750\u52D5\u753B\u306F10\u79D2\u4EE5\u5185\u306B\u3057\u3066\u304F\u3060\u3055\u3044\u3002")));let _=l instanceof HTMLImageElement?l.naturalWidth:l.videoWidth,A=l instanceof HTMLImageElement?l.naturalHeight:l.videoHeight;l instanceof HTMLVideoElement?(l.onloadedmetadata=null,l.removeAttribute("src"),l.load()):l.onload=null,c?s(c):_&&A?i({width:_,height:A}):s(new Error("\u7D20\u6750\u306E\u30B5\u30A4\u30BA\u3092\u78BA\u8A8D\u3067\u304D\u307E\u305B\u3093\u3002"))}l.onerror=()=>d(new Error("\u3053\u306E\u7D20\u6750\u306E\u30B5\u30A4\u30BA\u3092\u30D6\u30E9\u30A6\u30B6\u3067\u78BA\u8A8D\u3067\u304D\u307E\u305B\u3093\u3002\u5225\u306E\u753B\u50CF\u30FB\u52D5\u753B\u5F62\u5F0F\u3067\u304A\u8A66\u3057\u304F\u3060\u3055\u3044\u3002")),l instanceof HTMLImageElement?l.onload=()=>d():(l.preload="metadata",l.onloadedmetadata=()=>d()),l.src=o})}finally{URL.revokeObjectURL(o)}}var _e=(t,e)=>{let a=Object.entries(t).filter(([,l])=>e[l.class_type]?.output_node===!0).map(([l])=>l);if(!a.length)return 0;let o=new Set,i=[...a];for(;i.length;){let l=i.pop();if(o.has(l))continue;let u=t[l];if(u){o.add(l);for(let d of Object.values(u.inputs))Array.isArray(d)&&d.length===2&&i.push(String(d[0]))}}let s=0;for(let l of Object.keys(t))o.has(l)||(delete t[l],s+=1);return s};var qe=t=>{let e=t.class_type.toLowerCase(),a=Object.keys(t.inputs).map(i=>i.toLowerCase()),o=(t._meta?.title??"").toLowerCase();return e.includes("lora")||/lora|turbo|4\s*steps?/.test(o)?"lora":e.includes("loadimage")||e.includes("loadvideo")?"input":e.includes("loader")||a.some(i=>["ckpt_name","unet_name","model_name","vae_name","clip_name"].includes(i))?"model":e.includes("textencode")||a.some(i=>["text","prompt","positive","negative"].includes(i))||typeof t.inputs.value=="string"&&(e.includes("primitivestring")||e.includes("stringmultiline")||e.includes("multilinestring")||/prompt|text \(multiline\)|プロンプト/.test(o))&&!/replace|regex|concatenate|combine/.test(e)?"prompt":e.includes("sampler")||/steps?|cfg|seed/.test(o)||a.some(i=>["steps","cfg","sampler_name","scheduler","seed","noise_seed"].includes(i))?"sampling":/fps|frame rate|frames?|duration|seconds?|width|height|size|length/.test(o)||a.some(i=>["width","target_width","output_width","height","target_height","output_height","length","duration","duration_seconds","seconds","num_frames","video_frames","frame_count","frames","fps","frame_rate"].includes(i))?"size":e.includes("save")||e.includes("preview")||e.includes("combine")?"output":"advanced"};var De=t=>{let e=t.toLowerCase().replace(/[^a-z0-9]+/g,"_");return/(?:^|_)negative(?:_|$)/.test(e)||e==="neg"?"negative":/(?:^|_)positive(?:_|$)/.test(e)||e==="pos"?"positive":null},Ve=t=>{let e={},a=(i,s)=>{let l=e[i];e[i]=l&&l!==s?"both":s},o=(i,s,l)=>{if(l.has(i))return;l.add(i);let u=t[i];if(!u)return;qe(u)==="prompt"&&a(i,s);let d=Object.entries(u.inputs).filter(([_,A])=>De(_)===s&&Array.isArray(A)&&A.length===2),c=d.length?d.map(([,_])=>_):Object.values(u.inputs);for(let _ of c)Array.isArray(_)&&_.length===2&&o(String(_[0]),s,l)};for(let i of Object.values(t))for(let[s,l]of Object.entries(i.inputs)){let u=De(s);!u||!Array.isArray(l)||l.length!==2||o(String(l[0]),u,new Set)}for(let[i,s]of Object.entries(t)){if(e[i]||qe(s)!=="prompt")continue;let l=(s._meta?.title??"").toLowerCase();/negative|ネガティブ|除外/.test(l)?a(i,"negative"):/positive|ポジティブ|肯定/.test(l)&&a(i,"positive")}return e};var Y=t=>typeof t=="number"&&Number.isFinite(t),H=(t,e)=>t[e.id]?.inputs[e.key],B=(t,e,a)=>{for(let o of e)t[o.id].inputs[o.key]=a},$e=t=>t._meta?.title||"";function Pe(t,e,a){let o=document.createElement("section");o.className="panel basic-controls";let i=document.createElement("div");i.className="basic-prompts";let s=document.createElement("div");s.className="fields",o.append(i,s);let l=Object.entries(t),u=()=>o.dispatchEvent(new CustomEvent("workflowchange",{bubbles:!0}));function d(n,m,r,p={}){let f=document.createElement("label");f.className="field";let h=document.createElement("span");h.textContent=n,f.append(h);let g=p.multiline?document.createElement("textarea"):document.createElement("input");return g instanceof HTMLTextAreaElement?g.rows=3:(g.type="number",p.min!==void 0&&(g.min=String(p.min)),p.max!==void 0&&(g.max=String(p.max)),g.step=String(p.step??1)),g.value=String(m),p.name&&(g.name=p.name),p.ref&&(g.dataset.node=p.ref.id,g.dataset.input=p.ref.key),g.addEventListener("input",()=>{if(g instanceof HTMLInputElement){if(g.value===""||!g.validity.valid)return;let L=Number(g.value);if(!Number.isFinite(L))return;r(L)}else r(g.value);u()}),f.append(g),(p.container||(p.multiline?i:s)).append(f),g}let c=Ve(t),_=new Map;for(let[n,m]of l)if(!(c[n]==="negative"||/negative|ネガティブ|除外/i.test($e(m))))for(let[r,p]of Object.entries(m.inputs)){if(typeof p!="string"||!(/^(text|prompt)$/.test(r)||r==="value"&&/PrimitiveString|StringMultiline|MultilineString/.test(m.class_type))||a.angleControls?.node===n&&a.angleControls.key===r||!p.trim()&&c[n]!=="positive")continue;let f=_.get(p)||{refs:[],value:p};f.refs.push({id:n,key:r}),_.set(p,f)}let R=0;for(let n of _.values()){if(e.id==="image-edit-super"&&a.id==="pose")continue;R++;let m=e.id==="sound-sync"?"\u97F3\u306E\u5185\u5BB9":e.id==="dialogue"?"\u52D5\u753B\u306E\u5185\u5BB9":_.size>1?"\u30D7\u30ED\u30F3\u30D7\u30C8 "+R:"\u30D7\u30ED\u30F3\u30D7\u30C8",r=e.id==="dialogue"&&n.value.match(/^; she says: [^\n]*\n*/)?.[0]||"",p=d(m,r?n.value.slice(r.length):n.value,f=>B(t,n.refs,r+f),{multiline:!0,ref:n.refs[0],name:"prompt"+(R>1?"_"+R:"")});e.id==="video-flow"&&(p.placeholder="\u5973\u6027\u304C\u30B3\u30C3\u30D7\u3092\u624B\u306B\u53D6\u3063\u3066\u98F2\u3080")}let v=(n,m,r)=>{let p=t[n]?.inputs[m];return Y(p)?p:r},M=(n,m,r)=>{Y(t[n]?.inputs[m])&&(t[n].inputs[m]=r)};function k(){return l.flatMap(([n,m])=>Object.entries(m.inputs).filter(([r,p])=>Y(p)&&(r==="length"&&/LatentVideo|ImageToVideo|BerniniConditioning/.test(m.class_type)||r==="frames_number"||r==="frame_load_cap"&&p>0)).map(([r])=>({id:n,key:r})))}let W;function P(n,m,r,p=.25,f,h={}){W=d(n,m,r,{name:"seconds",min:h.min??p,max:h.max??30,step:p,ref:f})}if(!a.continuation)if(e.id==="video-karma"){let n=k(),m=v("94","fps",16),r=n.length?Number(H(t,n[0])):81;P("\u79D2\u6570",Number(((r-1)/m).toFixed(2)),p=>{let f=Math.max(5,Math.round(p*m/4)*4+1);B(t,n,f)},.25,n[0])}else if(e.id==="video-flow"&&/^(i2v|t2v)/.test(a.id)){let n=v("300","value",24);P("\u79D2\u6570",v("301","value",5),m=>{M("301","value",m)},1,{id:"301",key:"value"})}else if(e.id==="video-flow"){let n=a.id==="crossview",m=n?v("616","value",24):v("133","frame_rate",24),r=k(),p=n?v("614","value",121):v("113","length",121);P("\u79D2\u6570",n?v("615","value",5):Number(((p-1)/m).toFixed(2)),f=>{let h=Math.max(9,Math.round(f*m/8)*8+1);B(t,r,h),n?(M("614","value",h),M("615","value",f)):(M("116","video_end_time",f),M("116","audio_end_time",f))},1,n?{id:"615",key:"value"}:{id:"113",key:"length"})}else if(e.id==="dialogue"){let n=v("542","value",24);P("\u52D5\u753B\u306E\u79D2\u6570",v("796","Xi",144)/n,m=>{let r=Math.max(8,Math.round(m*n/8)*8);M("796","Xi",r),M("796","Xf",r),M("535","frames_number",r+1)},1,{id:"796",key:"Xi"})}else if(e.id==="video-fusion")if(t[21]?.class_type==="MiniMaxH3Easy")P("\u79D2\u6570",v("21","seconds",5),n=>M("21","seconds",n),1,{id:"21",key:"seconds"},{min:1,max:20});else{let n=v("132","fps",24),m=v("133","length",124);P("\u79D2\u6570",Math.round(m/n*2)/2,r=>M("133","length",Math.max(5,Math.ceil((r*n-5)/17)*17+5)),.5,{id:"133",key:"length"})}else if(e.id==="video-extend"){let n=v("24","frame_rate",20),m=v("26","multiplier",2),r=n/m,p=k();P("\u79D2\u6570",Number(((v("20","length",53)-1)/r).toFixed(2)),f=>{let h=Math.max(5,Math.round(f*r/4)*4+1);B(t,p,h)},.1,{id:"20",key:"length"})}else e.id==="sound-sync"&&P("\u97F3\u58F0\u306E\u79D2\u6570",v("92","duration",5),n=>M("92","duration",n),.5,{id:"92",key:"duration"});if(e.id==="motion-smooth"){let n=l.find(([,m])=>m.class_type==="FrameInterpolate");if(n){let[m,r]=n,p=Number(r.inputs.multiplier)||2,f=l.find(([,g])=>g.class_type==="VHS_VideoCombine"),h=f&&Y(f[1].inputs.frame_rate)?f[1].inputs.frame_rate/p:void 0;d("\u306A\u3081\u3089\u304B\u3055\uFF08\u500D\uFF09",p,g=>{r.inputs.multiplier=g,f&&h!==void 0&&(f[1].inputs.frame_rate=h*g)},{name:"interpolation",ref:{id:m,key:"multiplier"},min:2,max:8,step:1})}}return o.hidden=!i.children.length&&!s.children.length,o}var Re={"CLIPSave":{"output_node":true},"CheckpointPerturbWeights":{"output_node":true},"CheckpointSave":{"output_node":true},"ConsoleDebug+":{"output_node":true},"CreateBoundingBoxes":{"output_node":true},"DebugTensorShape+":{"output_node":true},"DecodeAndSaveVideo":{"output_node":true},"Display Any (rgthree)":{"output_node":true},"Display Int (rgthree)":{"output_node":true},"DisplayAny":{"output_node":true},"DummyOut":{"output_node":true},"FastPreview":{"output_node":true},"FastPreviewBatch":{"output_node":true},"HDRPreviewKJ":{"output_node":true},"IPAdapterSaveEmbeds":{"output_node":true},"Image Comparer (rgthree)":{"output_node":true},"ImageAndMaskPreview":{"output_node":true},"ImageCompare":{"output_node":true},"ImageCompositor":{"output_node":true},"ImageOnlyCheckpointSave":{"output_node":true},"ImagePreviewFromLatent+":{"output_node":true},"LTXVGemmaEnhancePrompt":{"output_node":true},"LTXVHDRDecodePostprocess":{"output_node":true},"LTXVSaveConditioning":{"output_node":true},"LTXVSparseTrackEditor":{"output_node":true},"LoraExtractKJ":{"output_node":true},"LoraReduceRankKJ":{"output_node":true},"LoraSave":{"output_node":true},"LossGraphNode":{"output_node":true},"MaskPreview":{"output_node":true},"MaskPreview+":{"output_node":true},"ModelSave":{"output_node":true},"ModelSaveKJ":{"output_node":true},"PlaySoundKJ":{"output_node":true},"Preview3D":{"output_node":true},"Preview3DAdvanced":{"output_node":true},"PreviewAnimation":{"output_node":true},"PreviewAny":{"output_node":true},"PreviewAudio":{"output_node":true},"PreviewGaussianSplat":{"output_node":true},"PreviewImage":{"output_node":true},"PreviewImageOrMask":{"output_node":true},"PreviewPointCloud":{"output_node":true},"SAM3_TrackPreview":{"output_node":true},"Save3DAdvanced":{"output_node":true},"SaveAnimatedPNG":{"output_node":true},"SaveAnimatedWEBP":{"output_node":true},"SaveAudio":{"output_node":true},"SaveAudioAdvanced":{"output_node":true},"SaveAudioMP3":{"output_node":true},"SaveAudioOpus":{"output_node":true},"SaveCondition_EditUtils":{"output_node":true},"SaveGLB":{"output_node":true},"SaveGaussianSplat":{"output_node":true},"SaveImage":{"output_node":true},"SaveImageAdvanced":{"output_node":true},"SaveImageDataSetToFolder":{"output_node":true},"SaveImageKJ":{"output_node":true},"SaveImageTextDataSetToFolder":{"output_node":true},"SaveImageWebsocket":{"output_node":true},"SaveImageWithAlpha":{"output_node":true},"SaveLatent":{"output_node":true},"SaveLoRA":{"output_node":true},"SavePointCloud":{"output_node":true},"SavePoseKpsAsJsonFile":{"output_node":true},"SaveSVGNode":{"output_node":true},"SaveStringKJ":{"output_node":true},"SaveText":{"output_node":true},"SaveTrainingDataset":{"output_node":true},"SaveVideo":{"output_node":true},"SaveWEBM":{"output_node":true},"SeparateMasks":{"output_node":true},"VAESave":{"output_node":true},"VHS_PruneOutputs":{"output_node":true},"VHS_VideoCombine":{"output_node":true},"VisualizeCUDAMemoryHistory":{"output_node":true},"KSampler":{"input":{"required":{"sampler_name":[["euler","euler_cfg_pp","euler_ancestral","euler_ancestral_cfg_pp","heun","heunpp2","exp_heun_2_x0","exp_heun_2_x0_sde","dpm_2","dpm_2_ancestral","lms","dpm_fast","dpm_adaptive","dpmpp_2s_ancestral","dpmpp_2s_ancestral_cfg_pp","dpmpp_sde","dpmpp_sde_gpu","dpmpp_2m","dpmpp_2m_cfg_pp","dpmpp_2m_sde","dpmpp_2m_sde_gpu","dpmpp_2m_sde_heun","dpmpp_2m_sde_heun_gpu","dpmpp_3m_sde","dpmpp_3m_sde_gpu","ddpm","lcm","ipndm","ipndm_v","deis","res_multistep","res_multistep_cfg_pp","res_multistep_ancestral","res_multistep_ancestral_cfg_pp","gradient_estimation","gradient_estimation_cfg_pp","er_sde","seeds_2","seeds_3","sa_solver","sa_solver_pece","ddim","uni_pc","uni_pc_bh2"],{"tooltip":"The algorithm used when sampling, this can affect the quality, speed, and style of the generated output."}],"scheduler":[["simple","sgm_uniform","karras","exponential","ddim_uniform","beta","normal","linear_quadratic","kl_optimal"],{"tooltip":"The scheduler controls how noise is gradually removed to form the image."}]}}}};var I=JSON.parse(document.querySelector("#app-config").textContent),Be=Re,y=t=>document.querySelector(t),Z=t=>structuredClone(t),O=I.modes[0],F=Z(O?.workflow||{}),Ue=Le(),E=new Map,$=[],ce="",fe=1,ee=768;function We(){return j(I.id,O.id)===768?ee:1024}function xe(){let t=Fe(O.workflow),e=j(I.id,O.id)===768&&ee===1024?1024/Math.max(t.width,t.height):1;return Xe({width:t.width*e,height:t.height*e})}var b=(t,e,a)=>{let o=document.createElement(t);return o.textContent=e,a&&(o.className=a),o};function S(t,e=!1){y("#ui-status").textContent=t,y("#ui-status").classList.toggle("error",e)}function X(t,e,a,o={}){let i=document.createElement("label");i.className="field",i.append(b("span",t));let s;if(o.choices){s=document.createElement("select");for(let l of[...new Set([String(e),...o.choices])]){let u=document.createElement("option");u.value=l,u.textContent=l,s.append(u)}}else o.rows?(s=document.createElement("textarea"),s.rows=o.rows):(s=document.createElement("input"),s.type=typeof e=="boolean"?"checkbox":o.type||(typeof e=="number"?"number":"text"));return s instanceof HTMLInputElement&&s.type==="checkbox"?(s.checked=!!e,i.classList.add("check-field")):s.value=String(e),s instanceof HTMLInputElement&&(o.min!==void 0&&(s.min=String(o.min)),o.max!==void 0&&(s.max=String(o.max)),o.step!==void 0?s.step=String(o.step):typeof e=="number"&&(s.step="any")),s.addEventListener("input",()=>{let l=s instanceof HTMLInputElement&&s.type==="checkbox"?s.checked:typeof e=="number"?Number(s.value):s.value;a(l)}),i.append(s),o.help&&i.append(b("small",o.help)),{wrapper:i,field:s}}var tt=t=>"upload-"+crypto.randomUUID()+"."+(t.name.split(".").pop()?.toLowerCase().replace(/[^a-z0-9]/g,"").slice(0,8)||"bin"),he=t=>/loadaudio/i.test(t.class_type)?"audio":/loadvideo/i.test(t.class_type)?"video":/loadimage/i.test(t.class_type)?"image":null,ge=t=>Object.keys(t.inputs).find(e=>/^(image|video|audio|file|path|filename|audiofile|audiopath)$/i.test(e)&&typeof t.inputs[e]=="string");function te(t,e,a,o,i=!0,s=!1){let l=e==="video"&&(a==="continuation-source"||I.id==="video-flow"&&O?.id==="crossview"),u=document.createElement("div");u.className="media-card",u.append(b("strong",t));let d=document.createElement("input");d.type="file",d.accept=e+"/*",d.multiple=s,d.dataset.upload=a,d.setAttribute("aria-label",t);let c=document.createElement("div");c.className="media-preview";let _=b("small",i?"\u7D20\u6750\u3092\u9078\u629E\u3057\u3066\u304F\u3060\u3055\u3044\u3002":"\u4EFB\u610F\u306E\u53C2\u8003\u7D20\u6750");return l&&u.append(b("small","\u7D20\u6750\u52D5\u753B\u306F10\u79D2\u4EE5\u5185\u3002")),d.onchange=()=>{d.setCustomValidity("");for(let[x,G]of E)(x===a||x.startsWith(a+"::"))&&(URL.revokeObjectURL(G.url),E.delete(x));c.replaceChildren();let A=Array.from(d.files||[]);try{if(A.length>20)throw new Error("\u53C2\u8003\u7D20\u6750\u306F20\u4EF6\u4EE5\u5185\u306B\u3057\u3066\u304F\u3060\u3055\u3044\u3002");if(A.reduce((x,G)=>x+G.size,0)>2*1024*1024*1024)throw new Error("\u5165\u529B\u7D20\u6750\u306F\u5408\u8A082 GiB\u4EE5\u5185\u306B\u3057\u3066\u304F\u3060\u3055\u3044\u3002");A.forEach((x,G)=>{if(x.size>512*1024*1024)throw new Error("\u5165\u529B\u30D5\u30A1\u30A4\u30EB\u306F512 MiB\u4EE5\u5185\u306B\u3057\u3066\u304F\u3060\u3055\u3044\u3002");let R=URL.createObjectURL(x),v=tt(x),M=Ge(x,e,l?10:void 0);M.catch(C=>{l&&E.get(a)?.file===x&&d.isConnected&&(d.setCustomValidity(C.message),_.textContent=C.message,S(C.message,!0))}),E.set(s?a+"::"+G:a,{file:x,name:v,refs:o,url:R,kind:e,dimensions:M});let k=document.createElement(e==="image"?"img":e==="audio"?"audio":"video");k.src=R,k instanceof HTMLMediaElement?(k.controls=!0,k.preload="metadata",k instanceof HTMLVideoElement&&(k.playsInline=!0)):k.alt=x.name,c.append(k)}),_.textContent=A.length?A.map(x=>x.name+" \xB7 "+(x.size/1048576).toFixed(1)+" MiB").join(", "):i?"\u7D20\u6750\u3092\u9078\u629E\u3057\u3066\u304F\u3060\u3055\u3044\u3002":"\u4EFB\u610F\u306E\u53C2\u8003\u7D20\u6750",S(A.length?"\u7D20\u6750\u3092\u8AAD\u307F\u8FBC\u307F\u307E\u3057\u305F\u3002\u5B9F\u884C\u30DC\u30BF\u30F3\u3067\u958B\u59CB\u3067\u304D\u307E\u3059\u3002":"\u7D20\u6750\u3092\u89E3\u9664\u3057\u307E\u3057\u305F\u3002"),Te().catch(x=>S(x.message,!0))}catch(x){S(x.message,!0),d.value=""}},u.append(d,c,_),u}function at(){for(let t of E.values())URL.revokeObjectURL(t.url);E.clear()}function it(t){let e=I.modes.find(a=>a.id===t);e&&(O=e,F=Z(e.workflow),at(),He(),S("\u5165\u529B\u3092\u8A2D\u5B9A\u3057\u3001\u30B5\u30A4\u30C8\u4E0A\u306E\u300C\u751F\u6210\u3059\u308B\u300D\u3092\u62BC\u3057\u3066\u304F\u3060\u3055\u3044\u3002"))}function ze(t){return I.task==="dialogue"&&t==="dialogue-generated.wav"||O?.continuation&&t===O.continuation.last_frame_name}function Ke(t){return I.id!=="image-edit-super"||O.id!=="reference"?new Set:new Set(Object.values(t).filter(e=>e.class_type==="TextEncodeQwenImageEditPlus").flatMap(e=>{let a=e.inputs.image2;return Array.isArray(a)&&t[String(a[0])]?.class_type==="LoadImage"?[String(a[0])]:[]}))}function He(){y("#workflow-form").replaceChildren(),y("#upload-list").replaceChildren();let t=new Map,e={};for(let[i,s]of Object.entries(F)){let l=he(s),u=ge(s);if(l&&u&&!ze(s.inputs[u])){let d=l+":"+String(s.inputs[u]),c=t.get(d);if(!c){e[l]=(e[l]||0)+1;let _={image:"\u753B\u50CF",video:"\u52D5\u753B",audio:"\u97F3\u58F0"},A=s._meta?.title||"",x=/reference|参考|参照/i.test(A)?"\u53C2\u8003"+_[l]:/pose|姿勢/i.test(A)?"\u59FF\u52E2\u306E\u53C2\u8003\u753B\u50CF":_[l];c={kind:l,label:I.id==="image-edit-super"&&O.id==="pose"&&l==="image"&&e[l]===2?"\u30DD\u30FC\u30BA\u53C2\u7167\u753B\u50CF":x+(e[l]>1?" "+e[l]:""),refs:[]},t.set(d,c)}c.refs.push([i,u])}}let a=Ke(F);for(let[i,s]of t){let l=!s.refs.every(([u])=>a.has(u));y("#upload-list").append(te(s.label+(l?"":"\uFF08\u4EFB\u610F\uFF09"),s.kind,i,s.refs,l))}O?.continuation&&y("#upload-list").prepend(te("\u5EF6\u9577\u3059\u308B\u5143\u52D5\u753B","video","continuation-source",[])),st(),K(F,xe()),y("#workflow-form").append(Pe(F,I,O)),I.id==="video-flow"&&y("#workflow-form").append(Me(Ue));let o=b("p","\u30B5\u30A4\u30BA\u306F\u81EA\u52D5\u8ABF\u6574\uFF08\u9577\u8FBA\u6700\u5927"+We()+"px\uFF09\u3002\u7D20\u6750\u306E\u7E26\u6A2A\u6BD4\u3092\u57FA\u6E96\u306B\u3057\u307E\u3059\u3002","hint");o.id="output-size-hint",y("#workflow-form").append(o)}function ye(){let t=E.get("continuation-source");if(t)return t;let e=Array.from(document.querySelectorAll("[data-upload]")).flatMap(a=>{let o=E.get(a.dataset.upload);return o&&o.kind!=="audio"?[o]:[]});return e.find(a=>a.kind==="video")||e[0]}function Xe(t){return Ce(t,ke(I.id,O.id),We(),Se(I.id,O.id,!!O.continuation))}async function Te(){let t=ye();if(!t)return null;let e=await t.dimensions;if(t!==ye()||!e)return null;let a=Xe(e);K(F,a);let o=document.querySelector("#output-size-hint");return o&&(o.textContent="\u51FA\u529B\u30B5\u30A4\u30BA\uFF1A"+a.width+" \xD7 "+a.height+" px\uFF08\u7D20\u6750\u306E\u7E26\u6A2A\u6BD4\u306B\u5408\u308F\u305B\u3001\u5BFE\u5FDC\u3059\u308B\u30B5\u30A4\u30BA\u5358\u4F4D\u306B\u8ABF\u6574\uFF09"),a}function Ie(){let t=crypto.getRandomValues(new Uint32Array(2)),e=(t[0]&2097151)*4294967296+t[1];return e===fe&&(e=(e+1)%Number.MAX_SAFE_INTEGER),fe=e,e}async function Je(){let t=Array.from(E.values());if(t.length>20)throw new Error("\u5165\u529B\u7D20\u6750\u306F\u6700\u592720\u30D5\u30A1\u30A4\u30EB\u3067\u3059\u3002");if(t.some(e=>e.file.size>512*1024*1024))throw new Error("\u5165\u529B\u30D5\u30A1\u30A4\u30EB\u306F512 MiB\u4EE5\u5185\u306B\u3057\u3066\u304F\u3060\u3055\u3044\u3002");if(t.reduce((e,a)=>e+a.file.size,0)>2*1024*1024*1024)throw new Error("\u5165\u529B\u7D20\u6750\u306E\u5408\u8A08\u306F2 GiB\u4EE5\u5185\u306B\u3057\u3066\u304F\u3060\u3055\u3044\u3002");return t.map(e=>({name:e.name,mime_type:e.file.type||ot(e.file.name),blob:e.file}))}function ot(t){let e=t.split(".").pop()?.toLowerCase();return{png:"image/png",jpg:"image/jpeg",jpeg:"image/jpeg",webp:"image/webp",mp4:"video/mp4",webm:"video/webm",mov:"video/quicktime",wav:"audio/wav",mp3:"audio/mpeg",flac:"audio/flac",ogg:"audio/ogg"}[e||""]||"application/octet-stream"}async function je(){let t=await Te();if(!y("#app-form").reportValidity())throw new Error("\u5165\u529B\u5185\u5BB9\u3092\u78BA\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044\u3002");let e=Z(F);for(let d of Ke(e)){let c=e[d],_=ge(c);if(_&&!E.has("image:"+c.inputs[_]))for(let A of Object.values(e))A.class_type==="TextEncodeQwenImageEditPlus"&&Array.isArray(A.inputs.image2)&&String(A.inputs.image2[0])===d&&delete A.inputs.image2}I.id==="image-edit-super"&&O.id==="reference"&&_e(e,Be);let a=new Set;for(let d of Object.values(e)){let c=ge(d);he(d)&&c&&!ze(d.inputs[c])&&a.add(he(d)+":"+d.inputs[c])}for(let d of a)if(!E.has(d))throw new Error("\u5165\u529B\u7D20\u6750\u304C\u672A\u9078\u629E\u3067\u3059: "+d.split(":").slice(1).join(":"));for(let d of E.values())for(let[c,_]of d.refs)e[c]&&(e[c].inputs[_]=d.name);let o=Ie();for(let[d,c]of Object.entries(e))for(let _ of Object.keys(c.inputs))if(/^(seed|noise_seed)$/i.test(_)&&typeof c.inputs[_]=="number"){c.inputs[_]=o,F[d].inputs[_]=o;let A=document.querySelector(`[data-node="${CSS.escape(d)}"][data-input="${_}"]`);A&&(A.value=String(o))}let i=t||xe();K(e,i);let s=ye();s?.kind==="image"&&we(e,s.refs,i),I.id==="video-flow"&&Ee(e,Ue),_e(e,Be);let l=await Je();S("\u751F\u6210\u7528\u306E\u5165\u529B\u3092\u30B5\u30A4\u30C8\u3078\u6E21\u3057\u307E\u3057\u305F\u3002");let u;if(O?.continuation){let d=E.get("continuation-source");if(!d)throw new Error("\u5EF6\u9577\u3059\u308B\u5143\u52D5\u753B\u3092\u9078\u629E\u3057\u3066\u304F\u3060\u3055\u3044\u3002");u={...Z(O.continuation),source_video_name:d.name};let c=e[20]?.inputs,_=e[24]?.inputs;c&&(u.width=c.width,u.height=c.height),_&&(u.fps=_.frame_rate)}return{workflow:e,files:l,...u?{continuation:u}:{}}}function st(){let t=y("#quick-controls");t.replaceChildren();let e=O?.angleControls;if(j(I.id,O.id)===768){let a=X("\u52D5\u753B\u306E\u89E3\u50CF\u5EA6",String(ee),()=>{},{choices:["768","1024"],help:"\u6700\u59271024\u306F\u751F\u6210\u6642\u9593\u304C\u5897\u3048\u307E\u3059\u3002"}),o=a.field;o.name="video_max_edge";for(let i of Array.from(o.options))i.textContent="\u6700\u5927"+i.value+" px";o.onchange=()=>{ee=o.value==="1024"?1024:768,Te().then(i=>{if(!i){let s=xe();K(F,s);let l=document.querySelector("#output-size-hint");l&&(l.textContent="\u51FA\u529B\u30B5\u30A4\u30BA\uFF1A"+s.width+" \xD7 "+s.height+" px")}}).catch(i=>S(i.message,!0))},t.append(a.wrapper)}if(e){let a=document.createElement("div");a.className="panel";let o={};for(let[i,s]of[["azimuth","\u5DE6\u53F3\u306E\u30A2\u30F3\u30B0\u30EB"],["elevation","\u30AB\u30E1\u30E9\u306E\u9AD8\u3055"],["distance","\u30AB\u30E1\u30E9\u306E\u8DDD\u96E2"]]){let l=e[i]||[];o[i]=l.find(c=>String(F[e.node]?.inputs[e.key]||"").includes(c.prompt))?.prompt||l[0]?.prompt||"";let u=document.createElement("label");u.className="field",u.append(b("span",s));let d=document.createElement("select");d.name=i;for(let c of l){let _=document.createElement("option");_.value=c.prompt,_.textContent=c.label,d.append(_)}d.value=o[i],d.onchange=()=>{o[i]=d.value;let c=e.prefix+" "+Object.values(o).join(e.prefix.startsWith("crossview")?", ":" ");F[e.node].inputs[e.key]=c;let _=document.querySelector('[data-node="'+e.node+'"][data-input="'+e.key+'"]');_&&(_.value=c)},u.append(d),a.append(u)}t.append(a)}if(O?.continuation){let a=X("\u7D50\u5408\u5F8C\u306E\u76EE\u6A19\u79D2\u6570",Number(O.continuation.target_duration_seconds)||10,i=>{O.continuation.target_duration_seconds=i},{min:1,max:120,step:.1}),o=document.createElement("div");o.className="panel",o.append(a.wrapper),t.append(o)}}function nt(){let t=document.createElement("section");t.className="panel",t.id="dialogue-controls",t.append(b("h3","\u30BB\u30EA\u30D5\u3068\u58F0"));let e={text:"\u3053\u3093\u306B\u3061\u306F\u3002\u4ECA\u65E5\u306F\u3044\u3044\u5929\u6C17\u3067\u3059\u306D\u3002",caption:"A calm, natural Japanese voice.",num_steps:60,cfg_scale_text:3,cfg_scale_caption:3,cfg_scale_speaker:10,duration_scale:1,useCaptionWithReference:!1};for(let[a,o,i]of[["text","\u30BB\u30EA\u30D5",{rows:4}],["caption","\u58F0\u306E\u8AAC\u660E",{rows:3}],["duration_scale","\u767A\u8A71\u306E\u9577\u3055\u500D\u7387",{min:.5,max:2,step:.05}]]){let s=X(o,e[a],l=>e[a]=l,i);s.field.setAttribute("name","dialogue_"+a),t.append(s.wrapper)}return y("#quick-controls").after(t),y("#upload-list").append(te("\u58F0\u306E\u53C2\u8003\u97F3\u58F0\uFF08\u4EFB\u610F\uFF09","audio","dialogue-voice",[],!1,!0)),async()=>{if(!e.text.trim()||e.text.length>1e3)throw new Error("\u30BB\u30EA\u30D5\u306F1\u301C1000\u6587\u5B57\u306B\u3057\u3066\u304F\u3060\u3055\u3044\u3002");let a=await je(),o=Array.from(E.entries()).filter(([i])=>i.startsWith("dialogue-voice")).map(([,i])=>i);if(o.reduce((i,s)=>i+s.file.size,0)>20*1024*1024)throw new Error("\u53C2\u8003\u97F3\u58F0\u306F\u5408\u8A0820 MiB\u4EE5\u5185\u3067\u3059\u3002");return a.workflow[536]&&(a.workflow[536].inputs.text=String(a.workflow[536].inputs.text).replace(/^; she says: [^\n]*/,"; she says: "+String(e.text).trim().replace(/[\"']/g,"").replace(/\s+/g," ")+".")),{...a,task:"dialogue",irodori:{...e,caption:o.length&&!e.useCaptionWithReference?"":e.caption,cfg_scale_speaker:o.length?e.cfg_scale_speaker:0,seed:fe,reference_audios:o.map(i=>i.name)}}}}function lt(){let t=y("#workflow-form");t.replaceChildren();let e={text:"\u3053\u3093\u306B\u3061\u306F\u3002\u4ECA\u65E5\u3082\u826F\u3044\u4E00\u65E5\u3092\u3002",caption:"\u843D\u3061\u7740\u3044\u305F\u81EA\u7136\u306A\u58F0",num_steps:60,cfg_scale_text:3,cfg_scale_caption:3,cfg_scale_speaker:10,speed:1,seconds:0,useCaptionWithReference:!1};for(let[a,o,i]of[["text","\u8AAD\u307F\u4E0A\u3052\u308B\u6587\u7AE0",{rows:4}],["caption","\u58F0\u306E\u8AAC\u660E",{rows:3}],["speed","\u8A71\u3059\u901F\u5EA6",{min:.5,max:2,step:.05}],["seconds","\u9577\u3055\uFF080\u306F\u81EA\u52D5\uFF09",{min:0,max:45,step:.5}]]){let s=X(o,e[a],l=>e[a]=l,i);s.field.setAttribute("name",a),t.append(s.wrapper)}return y("#upload-list").append(te("\u53C2\u8003\u97F3\u58F0\uFF08\u4EFB\u610F\u30FB\u8907\u6570\u5BFE\u5FDC\uFF09","audio","voice",[],!1,!0)),async()=>{if(!String(e.text).trim()||String(e.text).length>1e3)throw new Error("\u8AAD\u307F\u4E0A\u3052\u308B\u6587\u7AE0\u306F1\u301C1000\u6587\u5B57\u306B\u3057\u3066\u304F\u3060\u3055\u3044\u3002");let a=Array.from(E.values());if(a.length>20||a.reduce((i,s)=>i+s.file.size,0)>20*1024*1024)throw new Error("\u53C2\u8003\u97F3\u58F0\u306F\u6700\u592720\u4EF6\u3001\u5408\u8A0820 MiB\u4EE5\u5185\u306B\u3057\u3066\u304F\u3060\u3055\u3044\u3002");let o=Ie();return{task:"irodori",text:e.text,caption:a.length&&!e.useCaptionWithReference?"":e.caption,num_steps:e.num_steps,cfg_scale_text:e.cfg_scale_text,cfg_scale_caption:e.cfg_scale_caption,cfg_scale_speaker:a.length?e.cfg_scale_speaker:0,duration_scale:1/e.speed,...e.seconds>0?{seconds:e.seconds}:{},seed:o,reference_audios:a.map(i=>i.name),files:await Je()}}}function dt(){let t={system:"\u65E5\u672C\u8A9E\u3067\u308F\u304B\u308A\u3084\u3059\u304F\u5FDC\u7B54\u3057\u3066\u304F\u3060\u3055\u3044\u3002",message:"",max_tokens:1024,temperature:.8,top_p:.95,repetition_penalty:1.1},e=y("#workflow-form");e.replaceChildren();for(let[o,i,s]of[["message","\u30E1\u30C3\u30BB\u30FC\u30B8",{rows:4}]]){let l=X(i,t[o],u=>t[o]=u,s);l.field.setAttribute("name",o),e.append(l.wrapper)}let a=b("button","\u4F1A\u8A71\u5C65\u6B74\u3092\u6D88\u53BB");return a.type="button",a.onclick=()=>{$=[],y("#chat-history").replaceChildren()},e.append(a,b("div","","chat-history")),e.lastElementChild.id="chat-history",async()=>{if(!t.message.trim())throw new Error("\u30E1\u30C3\u30BB\u30FC\u30B8\u3092\u5165\u529B\u3057\u3066\u304F\u3060\u3055\u3044\u3002");ce=t.message.trim();let o=Ie();return{task:"chat",messages:[{role:"system",content:t.system},...$.slice(-8),{role:"user",content:ce}],max_tokens:t.max_tokens,temperature:t.temperature,top_p:t.top_p,repetition_penalty:t.repetition_penalty,seed:o,files:[]}}}function ut(t){if(t.url){let e=new URL(t.url);if(e.protocol!=="https:")throw new Error("\u51FA\u529BURL\u304C\u4E0D\u6B63\u3067\u3059\u3002");return e.href}if(t.data&&/^(image|video|audio)\//.test(t.mime_type))return"data:"+t.mime_type+";base64,"+t.data;throw new Error("\u7D50\u679C\u306B\u30E1\u30C7\u30A3\u30A2URL\u304C\u3042\u308A\u307E\u305B\u3093\u3002")}function Q(t){y("#preview-loading").hidden=!t,y("#results").hidden=t,y(".output").setAttribute("aria-busy",String(t))}function rt({output:t,error:e}){Q(!1);let a=y("#results");if(a.replaceChildren(),e){a.append(b("p",e,"error")),S(e,!0);return}if(t?.text&&(a.append(b("pre",String(t.text),"text-result")),I.task==="chat")){$.push({role:"user",content:ce},{role:"assistant",content:String(t.text)});let i=y("#chat-history");i.replaceChildren();for(let s of $.slice(-8))i.append(b("p",(s.role==="user"?"\u3042\u306A\u305F: ":"AI: ")+s.content))}let o=Array.isArray(t?.files)?t.files:Array.isArray(t?.images)?t.images:[];for(let i of o)try{let s=ut(i),l=document.createElement("article");l.className="result-card",l.append(b("h3",i.filename||"\u751F\u6210\u7D50\u679C"));let u;i.mime_type?.startsWith("image/")?(u=document.createElement("img"),u.alt=i.filename):i.mime_type?.startsWith("video/")?(u=document.createElement("video"),u.controls=!0,u.playsInline=!0):i.mime_type?.startsWith("audio/")&&(u=document.createElement("audio"),u.controls=!0),u&&(u.src=s,l.append(u));let d=document.createElement("a");d.href=s,d.download=i.filename||"output",d.textContent="\u30C0\u30A6\u30F3\u30ED\u30FC\u30C9",d.rel="noreferrer",l.append(d),i.size&&l.append(b("small",(i.size/1048576).toFixed(2)+" MiB")),a.append(l)}catch(s){a.append(b("p",s.message,"error"))}!o.length&&!t?.text&&a.append(b("p","\u751F\u6210\u304C\u5B8C\u4E86\u3057\u307E\u3057\u305F\u3002")),S("\u751F\u6210\u7D50\u679C\u3092\u53D7\u3051\u53D6\u308A\u307E\u3057\u305F\u3002")}y("#title").textContent=I.title;y("#description").textContent=I.description;document.title=I.title+" \xB7 GPU App";var Ae=y("#mode");for(let t of I.modes){let e=document.createElement("option");e.value=t.id,e.textContent=t.label,Ae.append(e)}Ae.onchange=()=>it(Ae.value);y(".top-panel").hidden=I.modes.length<2;y("#app-form").onsubmit=t=>t.preventDefault();I.modes.length&&He();var pt=I.task==="irodori"?lt():I.task==="chat"?dt():I.task==="dialogue"?nt():je;if(window.appSdk){let t=window.appSdk,e=document.createElement("dialog");e.id="app-run-confirm",e.setAttribute("aria-labelledby","app-run-confirm-title"),e.setAttribute("aria-describedby","app-run-confirm-message"),e.append(b("h2","GPU\u3067\u5B9F\u884C\u3057\u307E\u3059\u304B\uFF1F")),e.firstElementChild.id="app-run-confirm-title";let a=b("p","\u5B9F\u884C\u4E2D\u306F\u753B\u9762\u9589\u3058\u305A\u306B\u304A\u5F85\u3061\u304F\u3060\u3055\u3044");a.id="app-run-confirm-message",e.append(a);let o=document.createElement("div");o.className="app-confirm-actions";let i=document.createElement("button");i.type="button",i.textContent="\u30AD\u30E3\u30F3\u30BB\u30EB",i.autofocus=!0,i.onclick=()=>e.close();let s=document.createElement("button");s.type="button",s.id="app-run-approve",s.textContent="\u5B9F\u884C\u3059\u308B",o.append(i,s),e.append(o),document.body.append(e);let l=document.createElement("style");l.textContent="#app-run-confirm{box-sizing:border-box;width:min(440px,calc(100% - 32px));padding:24px;border:1px solid #35455d;border-radius:16px;background:#141c29;color:#eef3ff}#app-run-confirm::backdrop{background:rgba(0,0,0,.65)}#app-run-confirm h2{font-size:20px;margin:0 0 16px}#app-run-confirm p{line-height:1.7}.app-confirm-actions{display:flex;justify-content:flex-end;gap:12px;margin-top:24px}.app-confirm-actions button{padding:12px 18px;border:1px solid #43526a;border-radius:10px;background:#263449;color:#fff;font-size:16px;cursor:pointer}#app-run-approve{background:#2865df}",document.head.append(l);let u,d=async()=>{try{if(!t.getTokenBalance)throw Error("SDK update required");let _=await t.getTokenBalance();y("#token-balance").textContent="保有: "+(_.balance+(Number(_.reservedTokens)||0))+" \u30C8\u30FC\u30AF\u30F3"+(_.reservedTokens?"\uFF08\u5B9F\u884C\u7528\u306B "+_.reservedTokens+" \u78BA\u4FDD\u4E2D\uFF09":"")}catch{y("#token-balance").textContent="\u30C8\u30FC\u30AF\u30F3\u6B8B\u9AD8\u3092\u53D6\u5F97\u3067\u304D\u307E\u305B\u3093"}},c=(_,A=0)=>{clearTimeout(u),_.status==="settled"?(y("#token-usage").textContent="\u4ECA\u56DE\u306E\u6D88\u8CBB: "+_.consumedTokens+" \u30C8\u30FC\u30AF\u30F3",d()):(y("#token-usage").textContent="\u6D88\u8CBB\u30C8\u30FC\u30AF\u30F3\u3092\u7CBE\u7B97\u4E2D\u2026",t.getUsage&&A<20&&(u=setTimeout(()=>{t.getUsage(_.jobId).then(x=>c(x,A+1)).catch(()=>{y("#token-usage").textContent="\u7CBE\u7B97\u7D50\u679C\u3092\u78BA\u8A8D\u3067\u304D\u307E\u305B\u3093\u3002\u518D\u8868\u793A\u3057\u3066\u78BA\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044\u3002"})},3e3)))};t.onUsage?.(_=>c(_)),d(),t.onGenerate(pt),t.onResult(rt),t.onStatus(_=>{Q(["collecting","preparing_input","uploading","starting","queued","running"].includes(_.phase)),y("#app-execute").disabled=!_.canRun,s.disabled=!_.canRun,!_.canRun&&e.open&&e.close(),S(_.message,_.phase==="failed");let A=y("#transfer-progress");A.hidden=!_.progress,_.progress&&(A.max=_.progress.totalBytes||1,A.value=_.progress.bytes||0)}),y("#app-execute").onclick=()=>{e.open||e.showModal()},s.onclick=()=>{s.disabled||!e.open||(e.close(),Q(!0),y("#token-usage").textContent="",t.run().catch(_=>S(_.message,!0)).finally(()=>{Q(!1),d()}))}}else S("\u3053\u306Eindex.html\u306FGPU App\u304B\u3089\u958B\u304F\u3068\u5B9F\u884C\u3067\u304D\u307E\u3059\u3002");})();
;/* media selection removal */
(()=>{var c=new WeakMap;function u(e){if(c.has(e))return;let n=document.createElement("div");n.className="media-clear-actions",e.insertAdjacentElement("afterend",n);let t=()=>{n.replaceChildren();let r=Array.from(e.files||[]);n.hidden=r.length===0,r.forEach((s,b)=>{let d=document.createElement("div");d.className="media-clear-row";let l=document.createElement("span");l.textContent=s.name;let a=document.createElement("button");a.type="button",a.className="media-clear-button",a.textContent="\xD7",a.title="\u7D20\u6750\u3092\u89E3\u9664",a.setAttribute("aria-label",s.name+"\u3092\u89E3\u9664"),a.disabled=e.disabled,a.addEventListener("click",()=>{if(e.disabled)return;let m=Array.from(e.files||[]).filter((i,o)=>o!==b);if(m.length){let i=new DataTransfer;m.forEach(o=>i.items.add(o)),e.files=i.files}else e.value="";e.setCustomValidity(""),e.dispatchEvent(new Event("change",{bubbles:!0})),t(),(n.querySelector("button")||e).focus()}),d.append(l,a),n.append(d)})};c.set(e,t),e.addEventListener("change",()=>queueMicrotask(t)),t()}function f(){if(document.getElementById("media-clear-style"))return;let e=document.createElement("style");e.id="media-clear-style",e.textContent=".media-clear-actions{display:grid;gap:6px;min-width:0;margin-top:6px}.media-clear-actions[hidden]{display:none!important}.media-clear-row{display:flex;align-items:center;gap:8px;min-width:0}.media-clear-row>span{flex:1;min-width:0;overflow-wrap:anywhere;font-size:12px;color:var(--muted,#63776a)}button.media-clear-button{flex:none;width:36px;min-width:36px;height:36px;min-height:36px;margin:0;padding:0;display:inline-flex;align-items:center;justify-content:center;border:1px solid #bed0c4;border-radius:8px;background:#fff;color:#245b43;font:24px/1 system-ui;cursor:pointer}button.media-clear-button:hover{background:#edf4ef}button.media-clear-button:disabled{opacity:.45;cursor:default}",document.head.append(e);let n=t=>{(t instanceof Element||t instanceof Document)&&(t instanceof HTMLInputElement&&t.type==="file"&&u(t),t.querySelectorAll('input[type="file"]').forEach(u))};n(document),new MutationObserver(t=>{for(let r of t)r.type==="attributes"?c.get(r.target)?.():r.addedNodes.forEach(n)}).observe(document.body,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["disabled"]})}document.readyState==="loading"?document.addEventListener("DOMContentLoaded",f,{once:!0}):f();})();