import{r as e}from"./rolldown-runtime-C60lm6uB.js";import{i as t,r as n}from"./framework-BgSIrAUN.js";var r=e(n(),1),i=Object.entries({A:`#FAF4C8 #FFFFD5 #FEFF8B #FBED56 #F4D738 #FEAC4C #FE8B4C #FFDA45 #FF995B #F77C31 #FFDD99 #FE9F72 #FFC365 #FD543D #FFF365 #FFFF9F #FFE36E #FEBE7D #FD7C72 #FFD568 #FFE395 #F4F57D #E6C9B7 #F7F8A2 #FFD67D #FFC830`,B:`#E6EE31 #63F347 #9EF780 #5DE035 #35E352 #65E2A6 #3DAF80 #1C9C4F #27523A #95D3C2 #5D722A #166F41 #CAEB7B #ADE946 #2E5132 #C5ED9C #9BB13A #E6EE49 #24B88C #C2F0CC #156A6B #0B3C43 #303A21 #EEFCA5 #4E846D #8D7A35 #CCE1AF #9EE5B9 #C5E254 #E2FCB1 #B0E792 #9CAB5A`,C:`#E8FFE7 #A9F9FC #A0E2FB #41CCFF #01ACEB #50AAF0 #3677D2 #0F54C0 #324BCA #3EBCE2 #28DDDE #1C334D #CDE8FF #D5FDFF #22C4C6 #1557A8 #04D1F6 #1D3344 #1887A2 #176DAF #BEDDFF #67B4BE #C8E2FF #7CC4FF #A9E5E5 #3CAED8 #D3DFFA #BBCFED #34488E`,D:`#AEB4F2 #858EDD #2F54AF #182A84 #B843C5 #AC7BDE #8854B3 #E2D3FF #D5B9F8 #361851 #B9BAE1 #DE9AD4 #B90095 #8B279B #2F1F90 #E3E1EE #C4D4F6 #A45EC7 #D8C3D7 #9C32B2 #9A009B #333A95 #EBDAFC #7786E5 #494FC7 #DFC2F8`,E:`#FDD3CC #FEC0DF #FFB7E7 #E8649E #F551A2 #F13D74 #C63478 #FFDBE9 #E970CC #D33793 #FCDDD2 #F78FC3 #B5006D #FFD1BA #F8C7C9 #FFF3EB #FFE2EA #FFC7DB #FEBAD5 #D8C7D1 #BD9DA1 #B785A1 #937A8D #E1BCE8`,F:`#FD957B #FC3D46 #F74941 #FC283C #E7002F #943630 #971937 #BC0028 #E2677A #8A4526 #5A2121 #FD4E6A #F35744 #FFA9AD #D30022 #FEC2A6 #E69C79 #D37C46 #C1444A #CD9391 #F7B4C6 #FDC0D0 #F67E66 #E698AA #E54B4F`,G:`#FFE2CE #FFC4AA #F4C3A5 #E1B383 #EDB045 #E99C17 #9D5B3E #753832 #E6B483 #D98C39 #E0C593 #FFC890 #B7714A #8D614C #FCF9E0 #F2D9BA #78524B #FFE4CC #E07935 #A94023 #B88558`,H:`#FDFBFF #FEFFFF #B6B1BA #89858C #48464E #2F2B2F #000000 #E7D6DB #EDEDED #EEE9EA #CECDD5 #FFF5ED #F5ECD2 #CFD7D3 #98A6A8 #1D1414 #F1EDED #FFFDF0 #F6EFE2 #949FA3 #FFFBE1 #CACAD4 #9A9D94`,M:`#BCC6B8 #8AA386 #697D80 #E3D2BC #D0CCAA #B0A782 #B4A497 #B38281 #A58767 #C5B2BC #9F7594 #644749 #D19066 #C77362 #757D78`}).flatMap(([e,t])=>t.split(` `).map((t,n)=>[e+(n+1),t])),a=t(),o={x:0,y:0,width:1,height:1};function s(e){fetch(`/api/usage`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(e),keepalive:!0}).catch(()=>void 0)}var c=128,l=30,u=`bead-pattern-history`,d=`pixel-bead-pattern-history`,f=`patterns`;function p(){return typeof globalThis.crypto?.randomUUID==`function`?globalThis.crypto.randomUUID():`${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function m(){return new Promise((e,t)=>{let n=indexedDB.open(d,1);n.onupgradeneeded=()=>{n.result.objectStoreNames.contains(f)||n.result.createObjectStore(f)},n.onsuccess=()=>e(n.result),n.onerror=()=>t(n.error)})}async function h(){let e=await m();return new Promise((t,n)=>{let r=e.transaction(f,`readonly`),i=r.objectStore(f).get(u);i.onsuccess=()=>t(Array.isArray(i.result)?i.result:[]),i.onerror=()=>n(i.error),r.oncomplete=()=>e.close()})}async function g(e){let t=await m();return new Promise((n,r)=>{let i=t.transaction(f,`readwrite`);i.objectStore(f).put(e,u),i.oncomplete=()=>{t.close(),n()},i.onerror=()=>{t.close(),r(i.error)},i.onabort=()=>{t.close(),r(i.error)}})}var _={A:`黄橙系`,B:`绿色系`,C:`蓝青系`,D:`紫蓝系`,E:`粉红系`,F:`红色系`,G:`肤棕系`,H:`黑白灰系`,M:`莫兰迪系`};function v([e,t,n]){let r=e=>{let t=e/255;return t<=.04045?t/12.92:((t+.055)/1.055)**2.4},i=r(e),a=r(t),o=r(n),s=Math.cbrt(.4122214708*i+.5363325363*a+.0514459929*o),c=Math.cbrt(.2119034982*i+.6806995451*a+.1073969566*o),l=Math.cbrt(.0883024619*i+.2817188376*a+.6299787005*o);return[.2104542553*s+.793617785*c-.0040720468*l,1.9779984951*s-2.428592205*c+.4505937099*l,.0259040371*s+.7827717662*c-.808675766*l]}function y(e,t){return Math.hypot(e[0]-t[0],e[1]-t[1],e[2]-t[2])}function b(e,t,n){let r=[n[0]-t[0],n[1]-t[1],n[2]-t[2]],i=r[0]**2+r[1]**2+r[2]**2;if(i<.07**2)return!1;let a=[e[0]-t[0],e[1]-t[1],e[2]-t[2]],o=(a[0]*r[0]+a[1]*r[1]+a[2]*r[2])/i;return o<.12||o>.88?!1:y(e,[t[0]+r[0]*o,t[1]+r[1]*o,t[2]+r[2]*o])<=.025}var x=i.map(([e,t])=>{let n=[parseInt(t.slice(1,3),16),parseInt(t.slice(3,5),16),parseInt(t.slice(5,7),16)];return{code:e,name:`MARD ${_[e[0]]}`,hex:t,rgb:n,lab:v(n)}}),ee=e=>[parseInt(e.slice(1,3),16),parseInt(e.slice(3,5),16),parseInt(e.slice(5,7),16)];function S(e,t){let n=t[0],r=1/0;for(let i of t){let t=y(e,i.lab);t>3<<10|a>>3<<5|o>>3;t.push(s);let l=n.get(s);l?(l.count+=1,l.red+=i,l.green+=a,l.blue+=o):n.set(s,{count:1,red:i,green:a,blue:o})}let r=[...n.entries()].map(([e,t])=>{let n=[t.red/t.count,t.green/t.count,t.blue/t.count];return{key:e,count:t.count,rgb:n,lab:v(n)}}).sort((e,t)=>t.count-e.count),i=[];for(let e of r){let t=-1,n=1/0;for(let r=0;r=0&&n<=.015){let n=i[t],r=n.count+e.count;n.rgb=n.rgb.map((t,i)=>(t*n.count+e.rgb[i]*e.count)/r),n.lab=n.lab.map((t,i)=>(t*n.count+e.lab[i]*e.count)/r),n.count=r}else i.push({count:e.count,rgb:[...e.rgb],lab:[...e.lab]})}let a=new Map;for(let e of r){let t=0,n=1/0;i.forEach((r,i)=>{let a=y(e.lab,r.lab);at.score-e.score||e.error/e.count-t.error/t.count);for(let e of i)r.every(t=>y(e.color.lab,t.lab)>=.035)&&r.push(e.color);return r.slice(0,Math.max(0,Math.min(t,r.length)))}function re(e,t,n){let r=e.map(e=>S(e.lab,t));if(n<12)return r;let i=e.reduce((e,t)=>e+t.count,0),a=Math.max(24,i*.012),o=Math.min(8,Math.max(0,n-t.length)),s=[],c=e.map((e,t)=>({cluster:e,index:t,exact:S(e.lab,x)})).filter(({cluster:e,exact:t,index:n})=>e.count>=a&&t.code!==r[n].code).sort((e,t)=>t.cluster.count-e.cluster.count);for(let e of c){if(s.length>=o)break;if(s.some(t=>t.code===e.exact.code)){r[e.index]=e.exact;continue}Math.min(...t.map(t=>y(t.lab,e.exact.lab)))<.018||(s.push(e.exact),r[e.index]=e.exact)}return r}function ie(e,t,n,r,i){if(i<12)return e;let a=[...e],o=[];for(let e=0;ee.code.startsWith(`H`)):x);!u.has(l.code)&&u.size>=8||(u.add(l.code),a[r]=l)}return a}function ae(e,t,n){let r=new Map;e.forEach(e=>{e&&r.set(e.code,(r.get(e.code)??0)+1)});let i=[...e],a=0;for(let o=0;o2)continue;let u=new Map;for(let r=-1;r<=1;r++)for(let i=-1;i<=1;i++){if(r===0&&i===0)continue;let a=o+r,c=s+i;if(a<0||c<0||a>=n||c>=t)continue;let d=e[a*t+c];if(!d||d.code===l.code)continue;let f=u.get(d.code)??{color:d,count:0};f.count+=1,u.set(d.code,f)}let d=[...u.values()].sort((e,t)=>t.count-e.count)[0];if(!d)continue;let f=(r.get(l.code)??0)===1?3:5;d.count(t*h.weight+p[n]*d)/e),h.weight=e,h.count+=1,h.samples.push({rgb:f,lab:p}),h.containsCenter||=m}else r.push({count:1,weight:d,lab:[...p],samples:[{rgb:f,lab:p}],containsCenter:m})}let s=(e*t+n)*4;if(i>=10/2||r.length===0){u[s+3]=0,d[e*t+n]=i/10;continue}let f=r.map(e=>{let t=e.weight;if(e.count<=2)for(let n=0;nt.effectiveWeight-e.effectiveWeight||t.group.weight-e.group.weight||Number(t.group.containsCenter)-Number(e.group.containsCenter))[0].group,p=f.samples.reduce((e,t)=>y(t.lab,f.lab)=n||d>=t)continue;let f=e[s*t+d];if(!f)continue;if(f.code===c.code){u+=1;continue}let p=l.get(f.code)??{color:f,count:0};p.count+=1,l.set(f.code,p)}if(u>2)continue;let d=[...l.values()].sort((e,t)=>t.count-e.count).slice(0,3),f=null,p=0;for(let e=0;e=d[t].count?d[e]:d[t];n.count>p&&(f=n.color,p=n.count)}f&&(r[s]=f,i+=1)}return{colors:r,changed:i}}function ce(e,t,n,r){let i=[...e],a=0,o=[-1,0,1];for(let s=0;s=.625)continue;let d=Math.hypot(u.lab[1],u.lab[2]);if(u.lab[0]<.32||u.lab[0]>.96||d>.14)continue;let f=new Map,p=0,m=0;for(let i of o)for(let a of o){if(i===0&&a===0)continue;let o=s+i,l=c+a;if(o<0||l<0||o>=r||l>=n)continue;let d=o*n+l,h=e[d];if(!h)continue;h.code===u.code&&(m+=1);let g=f.get(h.code)??{color:h,count:0,confidentCount:0};g.count+=1,t[d]>=.625&&(g.confidentCount+=1),f.set(h.code,g),p+=1}if(m>0)continue;let h=[...f.values()].sort((e,t)=>t.count-e.count)[0];if(!h||h.color.code===u.code)continue;let g=p>=7?5:Math.max(2,Math.ceil(p*.67));h.count.075||(i[l]=h.color,a+=1)}return{colors:i,changed:a}}function le(e,t,n,r,i,a){let o=a.x*t.naturalWidth,s=a.y*t.naturalHeight,c=a.width*t.naturalWidth,l=a.height*t.naturalHeight,u=c/l,d=n/r,f=n,p=r;i===`cover`&&u>d||i===`contain`&&u{s({event:`page_view`});let e=!1;return(async()=>{try{let t=await h(),n=localStorage.getItem(u);if(t.length===0&&n){let e=JSON.parse(n);Array.isArray(e)&&(t=e.slice(0,l),await g(t)),localStorage.removeItem(u)}e||ve(t.slice(0,l))}catch{e||G(`历史记录读取失败,请检查浏览器是否允许本地存储`)}})(),()=>{e=!0}},[]);let Q=(e=K.current,t=E,n=!0)=>{if(!e)return;let r=Math.max(8,Math.min(256,c)),i=Math.max(8,Math.min(256,f)),a,o=null;if(T===`dominant`){let n=oe(e,r,i,w,t);a=n.data,o=n.confidence}else{let n=document.createElement(`canvas`);n.width=r,n.height=i;let o=n.getContext(`2d`,{willReadFrequently:!0});o.clearRect(0,0,r,i),le(o,e,r,i,w,t),a=o.getImageData(0,0,r,i).data}let{pixelKeys:l,clusters:u,binClusters:p}=te(a),h=re(u,ne(u,Math.max(2,Math.min(S,x.length))),S),g=l.map(e=>e===null?null:h[p.get(e)??0]),_=0;if(o){let e=ce(g,o,r,i);g=e.colors,_=e.changed;let t=se(g,r,i);g=t.colors,_+=t.changed,g=ie(g,a,r,i,S);let n=ae(g,r,i);g=n.colors,_+=n.changed}let y=g.map(e=>({color:e}));v(r),b(i),d(r),m(i),pe(y),P(new Set);let ee=T===`dominant`?`区域主色 · 清理 ${_} 个低可信孤立格`:`平滑取色`,ue=new Set(g.filter(e=>e!==null).map(e=>e.code)).size,C=g.filter(e=>e!==null).length;n&&s({event:`conversion`,width:r,height:i,sampling_strategy:T,color_limit:S,actual_colors:ue,bead_count:C,transparent_cells:r*i-C}),G(`已转换为 ${r} × ${i} · ${C} 颗拼豆 · ${ee} · ${ue} 种差异色`)};(0,r.useEffect)(()=>{let e=ue(),n=new Image;n.onload=()=>{K.current=n,t(e),Q(n,o,!1)},n.src=e},[]),(0,r.useEffect)(()=>{let e=Se.current,t=K.current;if(!e||!t)return;let n=Math.max(8,Math.min(256,c||8))/Math.max(8,Math.min(256,f||8)),r=n>=1?600:Math.max(120,Math.round(600*n)),i=n>=1?Math.max(120,Math.round(600/n)):600;e.width=r,e.height=i;let a=e.getContext(`2d`);a.fillStyle=`#f7f5ed`,a.fillRect(0,0,r,i),le(a,t,r,i,w,E)},[e,c,f,w,E]),(0,r.useEffect)(()=>{if(!A)return;let e=Ce.current,t=K.current;if(!e||!t)return;let n=Math.min(1200/t.naturalWidth,760/t.naturalHeight,1);e.width=Math.max(1,Math.round(t.naturalWidth*n)),e.height=Math.max(1,Math.round(t.naturalHeight*n));let r=e.getContext(`2d`);r.clearRect(0,0,e.width,e.height),r.drawImage(t,0,0,e.width,e.height)},[A,e]),(0,r.useEffect)(()=>{if(!A)return;let e=document.body.style.overflow;document.body.style.overflow=`hidden`;let t=e=>{e.key===`Escape`&&j(!1)};return window.addEventListener(`keydown`,t),()=>{document.body.style.overflow=e,window.removeEventListener(`keydown`,t)}},[A]);let $=(0,r.useMemo)(()=>{let e=new Map;return M.forEach(({color:t})=>{t&&e.set(t.code,(e.get(t.code)??0)+1)}),x.filter(t=>e.has(t.code)).map(t=>({...t,count:e.get(t.code)})).sort((e,t)=>t.count-e.count)},[M]),Te=(0,r.useMemo)(()=>M.reduce((e,t)=>e+ +!!t.color,0),[M]),Ee=(0,r.useMemo)(()=>{let e=B.trim().toLowerCase();return $.filter(t=>!e||t.code.toLowerCase().includes(e)||t.name.includes(e)||t.hex.toLowerCase().includes(e))},[B,$]);(0,r.useEffect)(()=>{let e=q.current;if(!e||M.length===0)return;let t=I,n=Math.max(22,t),r=Math.min(window.devicePixelRatio||1,2);e.width=(_*t+n)*r,e.height=(y*t+n)*r,e.style.width=`${_*t+n}px`,e.style.height=`${y*t+n}px`;let i=e.getContext(`2d`);i.scale(r,r),i.fillStyle=`#ffffff`,i.fillRect(0,0,_*t+n,y*t+n),i.fillStyle=`#f0eee7`,i.fillRect(n,0,_*t,n),i.fillRect(0,n,n,y*t),i.strokeStyle=`rgba(32,38,36,.25)`,i.lineWidth=.6,i.font=`600 ${Math.max(7,Math.min(10,t*.35))}px Arial`,i.fillStyle=`#56605b`,i.textAlign=`center`,i.textBaseline=`middle`;let a=t<10?10:t<16?5:1;for(let e=0;e<_;e++){let r=n+e*t;i.strokeRect(r+.3,.3,t-.6,n-.6),(e===0||(e+1)%a===0)&&i.fillText(String(e+1),r+t/2,n/2)}for(let e=0;e{let a=n+r%_*t,o=n+Math.floor(r/_)*t;if(!e){i.clearRect(a,o,t,t),R&&(i.strokeStyle=`rgba(32,38,36,.12)`,i.lineWidth=.6,i.strokeRect(a+.3,o+.3,t-.6,t-.6));return}let s=N.size>0,c=N.has(e.code);if(F&&s&&!c?i.fillStyle=`#ffffff`:(i.fillStyle=e.hex,i.globalAlpha=s&&!c?.12:1,i.fillRect(a,o,t,t),i.globalAlpha=1),R&&(i.strokeStyle=s&&!c?`rgba(32,38,36,.07)`:`rgba(32,38,36,.22)`,i.lineWidth=.6,i.strokeRect(a+.3,o+.3,t-.6,t-.6)),z&&t>=22&&(!s||c)){let[n,r,s]=ee(e.hex);i.fillStyle=n*.299+r*.587+s*.114>160?`#1f2925`:`#ffffff`,i.font=`600 ${Math.max(7,t*.28)}px Arial`,i.textAlign=`center`,i.textBaseline=`middle`,i.fillText(e.code,a+t/2,o+t/2)}}),R){i.strokeStyle=`rgba(32,38,36,.48)`,i.lineWidth=1.5;for(let e=5;e<_;e+=5){let r=n+e*t;i.beginPath(),i.moveTo(r,n),i.lineTo(r,n+y*t),i.stroke()}for(let e=5;e{let r=n.target.files?.[0];if(!r)return;if(!r.type.startsWith(`image/`)){G(`请选择 JPG、PNG 或 WebP 图片`);return}let a=URL.createObjectURL(r),s=new Image;s.onload=()=>{e.startsWith(`blob:`)&&URL.revokeObjectURL(e),K.current=s,t(a),i(r.name),D(o),k(o),G(`图片已载入,点击“重新转换”生成图纸`),Q(s,o)},s.src=a},Oe=()=>{k(E),j(!0)},ke=e=>{let t=we.current;if(!t)return{x:0,y:0};let n=t.getBoundingClientRect();return{x:Math.max(0,Math.min(1,(e.clientX-n.left)/Math.max(1,n.width))),y:Math.max(0,Math.min(1,(e.clientY-n.top)/Math.max(1,n.height)))}},Ae=(e,t,n,r)=>{let i=Math.max(8,c||8)/Math.max(8,f||8),a=K.current;if(!a)return;let o=i*a.naturalHeight/a.naturalWidth,s=n>=e?1:-1,l=r>=t?1:-1,u=Math.abs(n-e),d=Math.abs(r-t);u/Math.max(d,1e-4)>o?u=d*o:d=u/Math.max(o,1e-4);let p=s>0?1-e:e,m=l>0?1-t:t,h=Math.min(1,p/Math.max(u,1e-4),m/Math.max(d,1e-4));u*=h,d*=h,k({x:s>0?e:e-u,y:l>0?t:t-d,width:Math.max(.01,u),height:Math.max(.01,d)})},je=e=>{if(e.button!==0)return;let t=ke(e);e.currentTarget.setPointerCapture(e.pointerId),Y.current={pointerId:e.pointerId,startX:t.x,startY:t.y},k({x:t.x,y:t.y,width:.01,height:.01})},Me=e=>{let t=Y.current;if(!t||t.pointerId!==e.pointerId)return;let n=ke(e);Ae(t.startX,t.startY,n.x,n.y)},Ne=e=>{Y.current?.pointerId===e.pointerId&&(Y.current=null),e.currentTarget.hasPointerCapture(e.pointerId)&&e.currentTarget.releasePointerCapture(e.pointerId)},Pe=()=>{if(O.width<.03||O.height<.03){G(`框选区域太小,请在大图上拖出更大的选框`);return}D(O),j(!1),G(`取景区域已更新,点击“重新转换”生成图纸`)},Fe=e=>{P(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},Ie=e=>{if(e.button!==0)return;let t=J.current;t&&(Z.current=!1,e.currentTarget.setPointerCapture(e.pointerId),X.current={pointerId:e.pointerId,x:e.clientX,y:e.clientY,scrollLeft:t.scrollLeft,scrollTop:t.scrollTop,moved:!1})},Le=e=>{let t=J.current,n=X.current;if(!t||!n||n.pointerId!==e.pointerId)return;let r=e.clientX-n.x,i=e.clientY-n.y;!n.moved&&Math.hypot(r,i)<5||(n.moved=!0,t.classList.add(`is-dragging`),t.scrollLeft=n.scrollLeft-r,t.scrollTop=n.scrollTop-i,H(null))},Re=e=>{let t=J.current,n=X.current;!n||n.pointerId!==e.pointerId||(Z.current=n.moved,X.current=null,t?.classList.remove(`is-dragging`),e.currentTarget.hasPointerCapture(e.pointerId)&&e.currentTarget.releasePointerCapture(e.pointerId))},ze=e=>{X.current?.pointerId===e.pointerId&&(X.current=null,Z.current=!1,J.current?.classList.remove(`is-dragging`),e.currentTarget.hasPointerCapture(e.pointerId)&&e.currentTarget.releasePointerCapture(e.pointerId))},Be=e=>{X.current?.pointerId===e.pointerId&&(X.current=null,Z.current=!1,J.current?.classList.remove(`is-dragging`))},Ve=e=>{if(Z.current){Z.current=!1;return}let t=q.current;if(!t)return;let n=t.getBoundingClientRect(),r=Math.max(22,I),i=Math.floor((e.clientX-n.left-r)/I),a=Math.floor((e.clientY-n.top-r)/I),o=M[a*_+i];i>=0&&a>=0&&i<_&&a{if(X.current?.moved){H(null);return}let t=q.current;if(!t)return;let n=t.getBoundingClientRect(),r=Math.max(22,I),i=Math.floor((e.clientX-n.left-r)/I),a=Math.floor((e.clientY-n.top-r)/I),o=M[a*_+i];if(i<0||a<0||i>=_||a>=y||!o?.color){H(null);return}H({row:a+1,column:i+1,color:o.color,left:e.clientX-n.left+14,top:e.clientY-n.top+14})},Ue=async e=>{await g(e),ve(e)},We=async()=>{if(M.length)try{await Ue([{id:p(),name:n.replace(/\.[^.]+$/,``)||`未命名图纸`,savedAt:new Date().toISOString(),width:_,height:y,colorLimit:S,codes:M.map(e=>e.color?.code??null)},...U].slice(0,l)),ye(``),G(`图纸已保存到本机历史记录`),requestAnimationFrame(()=>document.getElementById(`history-title`)?.scrollIntoView({behavior:`smooth`,block:`start`}))}catch{G(`保存历史失败,请检查浏览器是否允许本地存储或剩余空间是否充足`)}},Ge=e=>{let t=new Map(x.map(e=>[e.code,e]));pe(e.codes.map(e=>({color:e===null?null:t.get(e)??x[0]}))),v(e.width),b(e.height),d(e.width),m(e.height),C(e.colorLimit),i(e.name),P(new Set),G(`已恢复历史图纸:${e.name}`),document.getElementById(`pattern-preview`)?.scrollIntoView({behavior:`smooth`})},Ke=async e=>{try{await Ue(U.filter(t=>t.id!==e))}catch{G(`删除历史失败,请稍后重试`)}},qe=(0,r.useMemo)(()=>{let e=W.trim().toLowerCase();return U.filter(t=>!e||t.name.toLowerCase().includes(e)||`${t.width}x${t.height}`.includes(e))},[U,W]);return(0,a.jsxs)(`main`,{children:[(0,a.jsxs)(`header`,{className:`topbar`,children:[(0,a.jsxs)(`a`,{className:`brand`,href:`#top`,"aria-label":`豆格工坊首页`,children:[(0,a.jsxs)(`span`,{className:`brand-mark`,"aria-hidden":`true`,children:[(0,a.jsx)(`i`,{}),(0,a.jsx)(`i`,{}),(0,a.jsx)(`i`,{}),(0,a.jsx)(`i`,{})]}),(0,a.jsx)(`span`,{children:`豆格工坊`})]}),(0,a.jsx)(`span`,{className:`top-note`,children:`图片转拼豆图纸 · 本地处理`})]}),(0,a.jsxs)(`section`,{className:`hero`,id:`top`,children:[(0,a.jsxs)(`div`,{children:[(0,a.jsx)(`p`,{className:`eyebrow`,children:`PIXEL BEAD STUDIO`}),(0,a.jsxs)(`h1`,{children:[`把喜欢的图片,`,(0,a.jsx)(`br`,{}),(0,a.jsx)(`em`,{children:`变成一格一格的快乐。`})]}),(0,a.jsx)(`p`,{className:`hero-copy`,children:`上传图片,选择图纸大小和颜色数量;点击任意像素格,就能单独查看该颜色需要摆放的区域。`})]}),(0,a.jsxs)(`div`,{className:`hero-badge`,children:[(0,a.jsxs)(`strong`,{children:[_,` × `,y]}),(0,a.jsx)(`span`,{children:`当前图纸格数`})]})]}),(0,a.jsxs)(`section`,{className:`workspace`,"aria-label":`拼豆图纸转换工具`,children:[(0,a.jsxs)(`aside`,{className:`control-panel`,children:[(0,a.jsxs)(`div`,{className:`panel-heading`,children:[(0,a.jsx)(`span`,{children:`01`}),(0,a.jsxs)(`div`,{children:[(0,a.jsx)(`h2`,{children:`图片与规格`}),(0,a.jsx)(`p`,{children:`先决定图纸需要多少格`})]})]}),(0,a.jsxs)(`div`,{className:`upload-card crop-preview`,style:{aspectRatio:`${Math.max(8,c||8)} / ${Math.max(8,f||8)}`},children:[(0,a.jsx)(`canvas`,{ref:Se,"aria-label":`当前取景区域预览`}),(0,a.jsx)(`button`,{type:`button`,className:`upload-overlay`,onClick:()=>xe.current?.click(),children:`更换图片`}),(0,a.jsx)(`input`,{ref:xe,className:`file-input`,type:`file`,accept:`image/png,image/jpeg,image/webp`,onChange:De})]}),(0,a.jsx)(`p`,{className:`file-name`,title:n,children:n}),(0,a.jsx)(`button`,{className:`crop-select-button`,onClick:Oe,children:`选择取景区域`}),(0,a.jsx)(`button`,{className:`reset-crop`,onClick:()=>{D(o),k(o),G(`已恢复使用整张图片`)},children:`使用整张图片`}),(0,a.jsxs)(`div`,{className:`field-row`,children:[(0,a.jsxs)(`label`,{children:[(0,a.jsx)(`span`,{children:`横向格数`}),(0,a.jsx)(`input`,{type:`number`,min:`8`,max:`256`,value:c,onChange:e=>d(Number(e.target.value))})]}),(0,a.jsx)(`span`,{className:`times`,children:`×`}),(0,a.jsxs)(`label`,{children:[(0,a.jsx)(`span`,{children:`纵向格数`}),(0,a.jsx)(`input`,{type:`number`,min:`8`,max:`256`,value:f,onChange:e=>m(Number(e.target.value))})]})]}),(0,a.jsxs)(`label`,{className:`field`,children:[(0,a.jsxs)(`span`,{children:[`最多使用颜色 `,(0,a.jsx)(`b`,{children:S})]}),(0,a.jsx)(`input`,{type:`range`,min:`2`,max:`64`,value:S,onChange:e=>C(Number(e.target.value))})]}),(0,a.jsxs)(`label`,{className:`field`,children:[(0,a.jsx)(`span`,{children:`取色策略`}),(0,a.jsxs)(`select`,{value:T,onChange:e=>fe(e.target.value),children:[(0,a.jsx)(`option`,{value:`dominant`,children:`区域主色(减少杂色)`}),(0,a.jsx)(`option`,{value:`smooth`,children:`平滑取色(细节丰富)`})]})]}),(0,a.jsxs)(`label`,{className:`field`,children:[(0,a.jsx)(`span`,{children:`图片适应方式`}),(0,a.jsxs)(`select`,{value:w,onChange:e=>de(e.target.value),children:[(0,a.jsx)(`option`,{value:`contain`,children:`完整显示`}),(0,a.jsx)(`option`,{value:`cover`,children:`裁剪铺满`})]})]}),(0,a.jsx)(`button`,{className:`primary-button`,onClick:()=>Q(),children:`重新转换`}),(0,a.jsx)(`p`,{className:`privacy-note`,children:`图片只在当前浏览器中处理,不会上传到服务器。`})]}),(0,a.jsxs)(`section`,{className:`pattern-panel`,id:`pattern-preview`,children:[(0,a.jsxs)(`div`,{className:`pattern-toolbar`,children:[(0,a.jsxs)(`div`,{children:[(0,a.jsx)(`p`,{className:`section-kicker`,children:`02 / 图纸预览`}),(0,a.jsx)(`h2`,{children:`点击格子,筛选颜色`})]}),(0,a.jsxs)(`div`,{className:`zoom-control`,"aria-label":`图纸缩放`,children:[(0,a.jsx)(`button`,{onClick:()=>L(e=>Math.max(3,e-1)),"aria-label":`缩小`,children:`−`}),(0,a.jsx)(`input`,{"aria-label":`缩放比例`,type:`range`,min:`3`,max:`42`,step:`1`,value:I,onChange:e=>L(Number(e.target.value))}),(0,a.jsx)(`button`,{onClick:()=>L(e=>Math.min(42,e+1)),"aria-label":`放大`,children:`+`}),(0,a.jsxs)(`output`,{children:[I,`px`]})]})]}),(0,a.jsx)(`div`,{className:`canvas-viewport`,children:(0,a.jsx)(`div`,{className:`canvas-stage`,ref:J,children:(0,a.jsxs)(`div`,{className:`canvas-wrap`,children:[(0,a.jsx)(`canvas`,{ref:q,onPointerDown:Ie,onPointerMove:Le,onPointerUp:Re,onPointerCancel:ze,onLostPointerCapture:Be,onContextMenu:e=>e.preventDefault(),onClick:Ve,onMouseMove:He,onMouseLeave:()=>H(null),"aria-label":`转换后的拼豆像素图,可拖动查看,轻点格子选择颜色`}),V&&(0,a.jsxs)(`div`,{className:`pixel-tooltip`,style:{left:V.left,top:V.top},children:[(0,a.jsx)(`span`,{className:`tooltip-swatch`,style:{backgroundColor:V.color.hex}}),(0,a.jsxs)(`strong`,{children:[`第 `,V.row,` 行 · 第 `,V.column,` 列`]}),(0,a.jsxs)(`small`,{children:[V.color.code,` · `,V.color.name,` · `,V.color.hex]})]})]})})}),(0,a.jsxs)(`div`,{className:`pattern-footer`,children:[(0,a.jsx)(`span`,{className:`status-dot`}),` `,(0,a.jsx)(`span`,{children:be}),(0,a.jsxs)(`div`,{className:`view-options`,children:[(0,a.jsxs)(`label`,{children:[(0,a.jsx)(`input`,{type:`checkbox`,checked:R,onChange:e=>he(e.target.checked)}),` 网格`]}),(0,a.jsxs)(`label`,{children:[(0,a.jsx)(`input`,{type:`checkbox`,checked:z,onChange:e=>ge(e.target.checked)}),` 格内编号`]}),(0,a.jsx)(`button`,{className:`save-button`,onClick:We,children:`保存历史`}),(0,a.jsx)(`button`,{onClick:()=>{let e=q.current;if(!e)return;let t=document.createElement(`a`);t.download=`拼豆图纸-${_}x${y}.png`,t.href=e.toDataURL(`image/png`),t.click()},children:`下载 PNG`})]})]}),(0,a.jsxs)(`div`,{className:`pattern-legend`,children:[(0,a.jsxs)(`div`,{className:`legend-heading`,children:[(0,a.jsx)(`strong`,{children:`本图所需颜色与用量`}),(0,a.jsxs)(`span`,{children:[`按数量从多到少,共 `,$.length,` 色`]})]}),(0,a.jsx)(`div`,{className:`legend-list`,children:$.map(e=>(0,a.jsxs)(`button`,{className:N.has(e.code)?`active`:``,onClick:()=>Fe(e.code),children:[(0,a.jsx)(`i`,{style:{backgroundColor:e.hex}}),(0,a.jsx)(`strong`,{children:e.code}),(0,a.jsx)(`span`,{children:e.name}),(0,a.jsxs)(`b`,{children:[e.count,` 颗`]})]},e.code))})]})]}),(0,a.jsxs)(`aside`,{className:`color-panel`,children:[(0,a.jsxs)(`div`,{className:`panel-heading`,children:[(0,a.jsx)(`span`,{children:`03`}),(0,a.jsxs)(`div`,{children:[(0,a.jsx)(`h2`,{children:`分色查看`}),(0,a.jsxs)(`p`,{children:[$.length,` 种颜色 · `,Te,` 颗`]})]})]}),(0,a.jsxs)(`div`,{className:`search-box`,children:[(0,a.jsx)(`span`,{children:`⌕`}),(0,a.jsx)(`input`,{value:B,onChange:e=>_e(e.target.value),placeholder:`输入 A6、MARD A 或 #FEAC4C`})]}),(0,a.jsxs)(`div`,{className:`selection-tools`,children:[(0,a.jsxs)(`label`,{className:`switch-row`,children:[(0,a.jsx)(`input`,{type:`checkbox`,checked:F,onChange:e=>me(e.target.checked)}),(0,a.jsx)(`span`,{className:`switch`}),(0,a.jsx)(`span`,{children:`只显示选中颜色`})]}),N.size>0&&(0,a.jsxs)(`button`,{onClick:()=>P(new Set),children:[`清除 `,N.size,` 项`]})]}),(0,a.jsx)(`div`,{className:`color-list`,children:Ee.map(e=>{let t=N.has(e.code);return(0,a.jsxs)(`button`,{className:`color-item ${t?`active`:``}`,onClick:()=>Fe(e.code),"aria-pressed":t,children:[(0,a.jsx)(`span`,{className:`swatch`,style:{backgroundColor:e.hex}}),(0,a.jsxs)(`span`,{className:`color-meta`,children:[(0,a.jsxs)(`strong`,{children:[e.code,` · `,e.name]}),(0,a.jsx)(`small`,{children:e.hex})]}),(0,a.jsxs)(`b`,{children:[e.count,(0,a.jsx)(`small`,{children:`颗`})]})]},e.code)})}),(0,a.jsxs)(`p`,{className:`palette-note`,children:[(0,a.jsx)(`strong`,{children:`MARD 221 基础色卡`}),`:默认使用 A/B/C/D/E/F/G/H/M 九个系列。屏幕色值仅用于近似匹配,实体豆颜色会受批次、光线和屏幕影响。`]})]})]}),A&&(0,a.jsx)(`div`,{className:`crop-dialog-backdrop`,role:`presentation`,onMouseDown:e=>{e.target===e.currentTarget&&j(!1)},children:(0,a.jsxs)(`section`,{className:`crop-dialog`,role:`dialog`,"aria-modal":`true`,"aria-labelledby":`crop-dialog-title`,children:[(0,a.jsxs)(`div`,{className:`crop-dialog-header`,children:[(0,a.jsxs)(`div`,{children:[(0,a.jsx)(`p`,{className:`section-kicker`,children:`IMAGE CROP`}),(0,a.jsx)(`h2`,{id:`crop-dialog-title`,children:`框选需要转换的区域`}),(0,a.jsxs)(`p`,{children:[`在大图上按住并拖动。选框比例为 `,Math.max(8,c||8),` : `,Math.max(8,f||8),`。`]})]}),(0,a.jsx)(`button`,{"aria-label":`关闭取景窗口`,onClick:()=>j(!1),children:`×`})]}),(0,a.jsx)(`div`,{className:`crop-dialog-scroll`,children:(0,a.jsxs)(`div`,{className:`crop-dialog-stage`,ref:we,onPointerDown:je,onPointerMove:Me,onPointerUp:Ne,onPointerCancel:Ne,children:[(0,a.jsx)(`canvas`,{ref:Ce,"aria-label":`可框选的原始大图`}),(0,a.jsx)(`div`,{className:`crop-selection-mask crop-selection-top`,style:{height:`${O.y*100}%`}}),(0,a.jsx)(`div`,{className:`crop-selection-mask crop-selection-left`,style:{top:`${O.y*100}%`,width:`${O.x*100}%`,height:`${O.height*100}%`}}),(0,a.jsx)(`div`,{className:`crop-selection-mask crop-selection-right`,style:{top:`${O.y*100}%`,left:`${(O.x+O.width)*100}%`,right:0,height:`${O.height*100}%`}}),(0,a.jsx)(`div`,{className:`crop-selection-mask crop-selection-bottom`,style:{top:`${(O.y+O.height)*100}%`}}),(0,a.jsx)(`div`,{className:`crop-selection-box`,style:{left:`${O.x*100}%`,top:`${O.y*100}%`,width:`${O.width*100}%`,height:`${O.height*100}%`}})]})}),(0,a.jsxs)(`div`,{className:`crop-dialog-actions`,children:[(0,a.jsx)(`button`,{onClick:()=>k(o),children:`选择整张图`}),(0,a.jsx)(`span`,{children:`从左上角拖向右下角即可重新框选`}),(0,a.jsx)(`button`,{onClick:()=>j(!1),children:`取消`}),(0,a.jsx)(`button`,{className:`confirm`,disabled:O.width<.03||O.height<.03,onClick:Pe,children:`使用此区域`})]})]})}),(0,a.jsxs)(`section`,{className:`history-section`,"aria-labelledby":`history-title`,children:[(0,a.jsxs)(`div`,{className:`history-heading`,children:[(0,a.jsxs)(`div`,{children:[(0,a.jsx)(`p`,{className:`section-kicker`,children:`LOCAL PATTERN ARCHIVE`}),(0,a.jsx)(`h2`,{id:`history-title`,children:`历史图纸`}),(0,a.jsx)(`p`,{children:`历史保存在当前浏览器,最多保留 30 份。`})]}),(0,a.jsxs)(`div`,{className:`search-box`,children:[(0,a.jsx)(`span`,{children:`⌕`}),(0,a.jsx)(`input`,{value:W,onChange:e=>ye(e.target.value),placeholder:`按名称或 32x32 查询`})]})]}),qe.length?(0,a.jsx)(`div`,{className:`history-grid`,children:qe.map(e=>{let t=new Map;return e.codes.forEach(e=>{e&&t.set(e,(t.get(e)??0)+1)}),(0,a.jsxs)(`article`,{className:`history-card`,children:[(0,a.jsx)(`div`,{className:`history-swatches`,children:[...t.entries()].sort((e,t)=>t[1]-e[1]).slice(0,6).map(([e,t])=>(0,a.jsx)(`i`,{style:{backgroundColor:x.find(t=>t.code===e)?.hex,flexGrow:t}},e))}),(0,a.jsxs)(`div`,{children:[(0,a.jsx)(`h3`,{children:e.name}),(0,a.jsxs)(`p`,{children:[e.width,` × `,e.height,` · `,new Date(e.savedAt).toLocaleString(`zh-CN`,{hour12:!1})]})]}),(0,a.jsxs)(`div`,{className:`history-actions`,children:[(0,a.jsx)(`button`,{onClick:()=>Ge(e),children:`打开`}),(0,a.jsx)(`button`,{onClick:()=>Ke(e.id),children:`删除`})]})]},e.id)})}):(0,a.jsx)(`div`,{className:`history-empty`,children:`还没有符合条件的历史图纸。转换完成后点击“保存历史”即可在这里查询。`})]})]})}export{C as default};