Files
behind_glass/dist/assets/CutoutPreparation-9rCu4swh.js
T
horoli e358e24436 Replace project with current server release and Windows setup
Import the 2026-10-09 source release, Fastify/SQLite backend, restored source
assets, and analytics-enabled server build. Replace files from the previous
release while retaining the existing repository history.

Make builds portable across Windows and Linux, configure local startup,
normalize Windows static asset paths, and fix test fixture cleanup and file
URL handling. Exclude local environment settings, databases, dependencies,
validation output, and TypeScript build cache from version control.

Validation: npm ci, static and server builds, 106 arrival tests, and actual
local HTTP checks passed. The full suite passed 467 of 470 tests; three tests
still require QA fixtures omitted from the supplied release, documented in
README-서버실행.md.
2026-10-09 16:43:35 +09:00

1 line
5.9 KiB
JavaScript

import{t as e}from"./index-BYcEjj7E.js";function t(e,t,n){if(!Number.isInteger(t)||!Number.isInteger(n)||t<1||n<1||e.length!==t*n)throw Error(`누끼 크기를 읽지 못했어요. 다른 사진으로 다시 시도해 주세요.`);let r=t,i=n,a=0,o=0,s=0,c=0;for(let n=0;n<e.length;n++)if(e[n]===255&&c++,e[n]>=13){let e=n%t,c=Math.floor(n/t);r=Math.min(r,e),i=Math.min(i,c),a=Math.max(a,e+1),o=Math.max(o,c+1),s++}if(!s||c===e.length)throw Error(`강아지와 배경을 구분하지 못했어요. 다른 사진으로 다시 시도해 주세요.`);let l=new Uint8Array(e.length),u=new Int32Array(s),d=[];for(let r=0;r<e.length;r++){if(l[r]||e[r]<13)continue;let i=0,a=1;for(u[0]=r,l[r]=1;i<a;){let r=u[i++],o=r%t,s=Math.floor(r/t);for(let r=-1;r<=1;r++)for(let i=-1;i<=1;i++){let c=o+i,d=s+r;if(c<0||c>=t||d<0||d>=n)continue;let f=d*t+c;!l[f]&&e[f]>=13&&(l[f]=1,u[a++]=f)}}d.push(a)}let f=d.filter(e=>e>=s*.05).length,p=[];f>1&&p.push(`multiple-foreground`),s<16&&p.push(`tiny-foreground`);let m=Math.ceil(Math.max(t,n)*.01);return{bounds:{x0:Math.max(0,r-m),y0:Math.max(0,i-m),x1:Math.min(t,a+m),y1:Math.min(n,o+m)},largeComponentCount:f,warnings:p}}var n=class{worker=null;disposed=!1;pending=null;onStatus;constructor(e=()=>{}){this.onStatus=e}run(e,t){return this.disposed?Promise.reject(Error(`누끼 준비가 종료됐어요.`)):(this.cancel(),t.throwIfAborted(),new Promise((n,r)=>{let i=()=>this.cancel(),a={snapshot:e,signal:t,abort:i,fallback:!1,resolve:n,reject:r};this.pending=a,t.addEventListener(`abort`,i,{once:!0}),this.send(a).catch(e=>{this.pending===a&&this.fail(e)})}))}cancel(){let e=this.pending;this.pending=null,this.worker?.terminate(),this.worker=null,e&&(e.signal.removeEventListener(`abort`,e.abort),e.reject(new DOMException(`사진 준비를 취소했어요.`,`AbortError`)))}dispose(){this.disposed=!0,this.cancel()}fail(e){let t=this.pending;t&&(this.pending=null,this.worker?.terminate(),this.worker=null,t.signal.removeEventListener(`abort`,t.abort),t.reject(e instanceof Error?e:Error(`누끼를 준비하지 못했어요.`)))}async send(e){let n=await createImageBitmap(e.snapshot.bitmap);if(this.pending!==e||e.signal.aborted){n.close();return}let r;try{r=new Worker(new URL(`/assets/cutout.worker-D417j0Nw.js`,``+import.meta.url),{type:`module`})}catch(e){throw n.close(),e}this.worker=r,r.onmessage=n=>{if(this.worker!==r||this.pending!==e||n.data.id!==e.snapshot.requestId)return;let i=n.data;if(i.type===`status`){this.onStatus(i.id,i.message);return}if(r.terminate(),this.worker=null,i.type===`fallback`){if(e.fallback){this.fail(Error(`이 기기에서 누끼를 계산하지 못했어요.`));return}e.fallback=!0,this.send(e).catch(t=>{this.pending===e&&this.fail(t)});return}if(i.type===`error`){this.fail(Error(i.message));return}try{if(i.width!==e.snapshot.width||i.height!==e.snapshot.height)throw Error(`누끼 좌표가 사진과 맞지 않아요.`);let n=new Uint8Array(i.alpha),r=t(n,i.width,i.height);this.pending=null,e.signal.removeEventListener(`abort`,e.abort),e.resolve({requestId:i.id,width:i.width,height:i.height,alpha:n,...r,run:i.run})}catch(e){this.fail(e)}},r.onerror=t=>{this.worker===r&&this.pending===e&&this.fail(Error(t.message||`누끼 작업이 중단됐어요.`))},r.onmessageerror=()=>{this.worker===r&&this.pending===e&&this.fail(Error(`누끼 결과를 읽지 못했어요.`))};try{r.postMessage({type:`infer`,id:e.snapshot.requestId,image:n,forceWasm:e.fallback},[n])}catch(e){throw n.close(),e}}},r=class{nextId=0;pending=null;disposed=!1;results=new Set;provider=new n((e,t)=>{this.pending?.id===e&&!this.pending.controller.signal.aborted&&this.pending.onProgress(t)});async prepare(n,r=()=>{},o){if(this.disposed)throw Error(`누끼 준비가 종료됐어요.`);this.cancel(),o?.throwIfAborted();let s=new AbortController,c={id:++this.nextId,controller:s,onProgress:r};this.pending=c;let l=()=>s.abort(o?.reason);o?.addEventListener(`abort`,l,{once:!0});let u=null,d=``,f=``,p=new Image,m=new Image,h=!1,g=null,_=()=>{if(!h){h=!0;for(let e of[p,m])e.onload=e.onerror=null,e.removeAttribute(`src`);d&&URL.revokeObjectURL(d),f&&URL.revokeObjectURL(f),g&&this.results.delete(g)}},v=document.createElement(`canvas`);try{r(`사진 크기와 방향을 준비하는 중…`),u=await e(n,c.id,s.signal),s.signal.throwIfAborted();let o=await this.provider.run(u,s.signal);s.signal.throwIfAborted(),v.width=u.width,v.height=u.height;let l=v.getContext(`2d`);if(!l)throw Error(`사진 미리보기를 준비할 수 없어요.`);l.drawImage(u.bitmap,0,0);let h=await i(v);s.signal.throwIfAborted();let y=l.getImageData(0,0,v.width,v.height),b=new Uint8Array(o.alpha.length);for(let e=0;e<b.length;e++)b[e]=Math.round(y.data[e*4+3]*o.alpha[e]/255),y.data[e*4+3]=b[e];let x=t(b,u.width,u.height);l.putImageData(y,0,0);let S=await i(v);return s.signal.throwIfAborted(),d=URL.createObjectURL(h),f=URL.createObjectURL(S),await a(p,d,s.signal),await a(m,f,s.signal),s.signal.throwIfAborted(),g={...o,alpha:b,...x,requiresReview:!0,originalBlob:h,cutoutBlob:S,originalUrl:d,cutoutUrl:f,originalImage:p,cutoutImage:m,dispose:_},this.results.add(g),g}catch(e){throw _(),e}finally{u?.bitmap.close(),v.width=v.height=1,o?.removeEventListener(`abort`,l),this.pending===c&&(this.pending=null)}}cancel(){let e=this.pending;this.pending=null,e?.controller.abort(),this.provider.cancel()}dispose(){if(!this.disposed){this.disposed=!0,this.cancel(),this.provider.dispose();for(let e of this.results)e.dispose()}}};function i(e){return new Promise((t,n)=>e.toBlob(e=>{!e||e.type!==`image/png`?n(Error(`PNG 사진 미리보기를 만들지 못했어요.`)):t(e)},`image/png`))}function a(e,t,n){return new Promise((r,i)=>{let a=()=>{e.onload=e.onerror=null,n.removeEventListener(`abort`,o)},o=()=>{a(),i(new DOMException(`사진 준비를 취소했어요.`,`AbortError`))};e.onload=()=>{a(),r()},e.onerror=()=>{a(),i(Error(`PNG 사진 미리보기를 읽지 못했어요.`))},n.addEventListener(`abort`,o,{once:!0}),n.aborted?o():e.src=t})}export{r as CutoutPreparation};