1 line
34 KiB
JavaScript
1 line
34 KiB
JavaScript
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<r&&(r=t,n=i)}return n}function te(e){let t=[],n=new Map;for(let r=0;r<e.length;r+=4){if(e[r+3]<c){t.push(null);continue}let i=e[r],a=e[r+1],o=e[r+2],s=i>>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<i.length;r++){let a=y(e.lab,i[r].lab);a<n&&(n=a,t=r)}if(t>=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);a<n&&(n=a,t=i)}),a.set(e.key,t)}return{pixelKeys:t,clusters:i,binClusters:a}}function ne(e,t){let n=new Map;for(let t of e){let e=S(t.lab,x),r=y(t.lab,e.lab),i=Math.hypot(t.lab[1],t.lab[2]),a=1+Math.min(.65,i*2.2)+(t.lab[0]<.28?.35:0),o=n.get(e.code)??{color:e,count:0,error:0,score:0};o.count+=t.count,o.error+=r*t.count,o.score+=t.count*a/(1+r*5),n.set(e.code,o)}let r=[],i=[...n.values()].sort((e,t)=>t.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;e<t.length;e+=4)o.push(t[e+3]<c?null:v([t[e],t[e+1],t[e+2]]));let s=new Uint8Array(n*r),l=[[-1,0],[1,0],[0,-1],[0,1]];for(let e=1;e<r-1;e++)for(let t=1;t<n-1;t++){let r=e*n+t,i=o[r];if(!i)continue;let a=0;for(let[r,s]of l){let c=o[(e+r)*n+t+s];if(!c){a=1/0;break}a=Math.max(a,y(i,c))}a<=.018&&(s[r]=1)}let u=new Set;for(let e=2;e<r-2;e++)for(let t=2;t<n-2;t++){let r=e*n+t;if(!s[r])continue;let i=0;for(let r=-1;r<=1;r++)for(let a=-1;a<=1;a++)s[(e+r)*n+t+a]&&(i+=1);if(i<7)continue;let c=o[r],l=S(c,Math.hypot(c[1],c[2])<.035?x.filter(e=>e.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;o<n;o++)for(let s=0;s<t;s++){let c=o*t+s,l=e[c];if(!l||(r.get(l.code)??0)>2)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<f||(i[c]=d.color,a+=1)}return{colors:i,changed:a}}function oe(e,t,n,r,i){let a=[[1,1,1],[1,2,1],[1,1,1]],o=document.createElement(`canvas`);o.width=t*3,o.height=n*3;let s=o.getContext(`2d`,{willReadFrequently:!0});s.clearRect(0,0,o.width,o.height),s.imageSmoothingEnabled=!1,C(s,e,o.width,o.height,r,i);let l=s.getImageData(0,0,o.width,o.height).data,u=new Uint8ClampedArray(t*n*4),d=new Float32Array(t*n);for(let e=0;e<n;e++)for(let n=0;n<t;n++){let r=[],i=0;for(let t=0;t<3;t++)for(let s=0;s<3;s++){let u=((e*3+t)*o.width+n*3+s)*4,d=a[t][s];if(l[u+3]<c){i+=d;continue}let f=[l[u],l[u+1],l[u+2]],p=v(f),m=s===1&&t===1,h,g=1/0;for(let e of r){let t=y(p,e.lab);t<g&&(h=e,g=t)}if(h&&g<=.04){let e=h.weight+d;h.lab=h.lab.map((t,n)=>(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;n<r.length;n++)for(let i=n+1;i<r.length;i++)r[n]===e||r[i]===e||r[n].weight+r[i].weight<e.weight||b(e.lab,r[n].lab,r[i].lab)&&(t=0);return{group:e,effectiveWeight:t}}).sort((e,t)=>t.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)<y(e.lab,f.lab)?t:e);u[s]=p.rgb[0],u[s+1]=p.rgb[1],u[s+2]=p.rgb[2],u[s+3]=255,d[e*t+n]=f.weight/Math.max(1,10-i)}return{data:u,confidence:d}}function se(e,t,n){let r=[...e],i=0;for(let a=0;a<n;a++)for(let o=0;o<t;o++){let s=a*t+o,c=e[s];if(!c)continue;let l=new Map,u=0;for(let r=-1;r<=1;r++)for(let i=-1;i<=1;i++){if(r===0&&i===0)continue;let s=a+r,d=o+i;if(s<0||d<0||s>=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.length;e++)for(let t=e+1;t<d.length;t++){if(d[e].count+d[t].count<4||!b(c.lab,d[e].color.lab,d[t].color.lab))continue;let n=d[e].count>=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<r;s++)for(let c=0;c<n;c++){let l=s*n+c,u=e[l];if(!u||t[l]>=.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<g||h.confidentCount<Math.min(3,h.count)||y(u.lab,h.color.lab)>.075||(i[l]=h.color,a+=1)}return{colors:i,changed:a}}function C(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<d?(p=r,f=r*u):(f=n,p=n/u);let m=(n-f)/2,h=(r-p)/2;e.drawImage(t,o,s,c,l,m,h,f,p)}function w(){let e=document.createElement(`canvas`);e.width=640,e.height=640;let t=e.getContext(`2d`),n=t.createLinearGradient(0,0,0,640);return n.addColorStop(0,`#bfe8f1`),n.addColorStop(.65,`#fff2ce`),n.addColorStop(1,`#f6c783`),t.fillStyle=n,t.fillRect(0,0,640,640),t.fillStyle=`#f6c742`,t.beginPath(),t.arc(488,134,70,0,Math.PI*2),t.fill(),t.fillStyle=`#58a95b`,t.beginPath(),t.moveTo(0,455),t.quadraticCurveTo(135,310,300,455),t.quadraticCurveTo(480,285,640,435),t.lineTo(640,640),t.lineTo(0,640),t.fill(),t.fillStyle=`#27865a`,t.beginPath(),t.moveTo(0,535),t.quadraticCurveTo(180,390,350,520),t.quadraticCurveTo(505,410,640,505),t.lineTo(640,640),t.lineTo(0,640),t.fill(),t.fillStyle=`#f7f5ed`,t.fillRect(245,390,152,126),t.fillStyle=`#d9383a`,t.beginPath(),t.moveTo(218,405),t.lineTo(321,323),t.lineTo(424,405),t.closePath(),t.fill(),t.fillStyle=`#754a32`,t.fillRect(300,447,43,69),t.fillStyle=`#79cbe1`,t.fillRect(258,415,39,37),t.fillRect(350,415,34,37),e.toDataURL(`image/png`)}function T(){let[e,t]=(0,r.useState)(``),[n,i]=(0,r.useState)(`示例:田野小屋`),[c,d]=(0,r.useState)(100),[f,m]=(0,r.useState)(100),[_,v]=(0,r.useState)(100),[y,b]=(0,r.useState)(100),[S,T]=(0,r.useState)(64),[E,le]=(0,r.useState)(`contain`),[D,ue]=(0,r.useState)(`dominant`),[O,de]=(0,r.useState)(o),[k,A]=(0,r.useState)(o),[j,M]=(0,r.useState)(!1),[N,fe]=(0,r.useState)([]),[P,F]=(0,r.useState)(new Set),[I,pe]=(0,r.useState)(!1),[L,R]=(0,r.useState)(8),[z,me]=(0,r.useState)(!0),[B,he]=(0,r.useState)(!0),[V,ge]=(0,r.useState)(``),[H,U]=(0,r.useState)(null),[W,_e]=(0,r.useState)([]),[ve,ye]=(0,r.useState)(``),[be,G]=(0,r.useState)(`示例图已准备好,可以直接转换`),K=(0,r.useRef)(null),xe=(0,r.useRef)(null),Se=(0,r.useRef)(null),Ce=(0,r.useRef)(null),q=(0,r.useRef)(null),J=(0,r.useRef)(null),we=(0,r.useRef)(L),Te=(0,r.useRef)(null),Ee=(0,r.useRef)(null),Y=(0,r.useRef)(null),X=(0,r.useRef)(null),Z=(0,r.useRef)(!1);(0,r.useEffect)(()=>{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||_e(t.slice(0,l))}catch{e||G(`历史记录读取失败,请检查浏览器是否允许本地存储`)}})(),()=>{e=!0}},[]);let De=(e=K.current,t=O,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(D===`dominant`){let n=oe(e,r,i,E,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),C(o,e,r,i,E,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),fe(y),F(new Set);let ee=D===`dominant`?`区域主色 · 清理 ${_} 个低可信孤立格`:`平滑取色`,w=new Set(g.filter(e=>e!==null).map(e=>e.code)).size,T=g.filter(e=>e!==null).length;n&&s({event:`conversion`,width:r,height:i,sampling_strategy:D,color_limit:S,actual_colors:w,bead_count:T,transparent_cells:r*i-T}),G(`已转换为 ${r} × ${i} · ${T} 颗拼豆 · ${ee} · ${w} 种差异色`)};(0,r.useEffect)(()=>{let e=w(),n=new Image;n.onload=()=>{K.current=n,t(e),De(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),C(a,t,r,i,E,O)},[e,c,f,E,O]),(0,r.useEffect)(()=>{if(!j)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)},[j,e]),(0,r.useEffect)(()=>{if(!j)return;let e=document.body.style.overflow;document.body.style.overflow=`hidden`;let t=e=>{e.key===`Escape`&&M(!1)};return window.addEventListener(`keydown`,t),()=>{document.body.style.overflow=e,window.removeEventListener(`keydown`,t)}},[j]);let Q=(0,r.useMemo)(()=>{let e=new Map;return N.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)},[N]),Oe=(0,r.useMemo)(()=>N.reduce((e,t)=>e+ +!!t.color,0),[N]),ke=(0,r.useMemo)(()=>{let e=V.trim().toLowerCase();return Q.filter(t=>!e||t.code.toLowerCase().includes(e)||t.name.includes(e)||t.hex.toLowerCase().includes(e))},[V,Q]);(0,r.useEffect)(()=>{let e=q.current;if(!e||N.length===0)return;let t=L,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<y;e++){let r=n+e*t;i.strokeRect(.3,r+.3,n-.6,t-.6),(e===0||(e+1)%a===0)&&i.fillText(String(e+1),n/2,r+t/2)}if(N.forEach(({color:e},r)=>{let a=n+r%_*t,o=n+Math.floor(r/_)*t;if(!e){i.clearRect(a,o,t,t),z&&(i.strokeStyle=`rgba(32,38,36,.12)`,i.lineWidth=.6,i.strokeRect(a+.3,o+.3,t-.6,t-.6));return}let s=P.size>0,c=P.has(e.code);if(I&&s&&!c?i.fillStyle=`#ffffff`:(i.fillStyle=e.hex,i.globalAlpha=s&&!c?.12:1,i.fillRect(a,o,t,t),i.globalAlpha=1),z&&(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)),B&&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)}}),z){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<y;e+=5){let r=n+e*t;i.beginPath(),i.moveTo(n,r),i.lineTo(n+_*t,r),i.stroke()}}},[N,_,y,L,P,I,z,B]),(0,r.useEffect)(()=>{we.current=L;let e=Te.current;if(!e)return;Te.current=null;let t=window.requestAnimationFrame(()=>{let{stage:t}=e,n=q.current;if(!n)return;let r=t.getBoundingClientRect(),i=n.getBoundingClientRect(),a=i.left+i.width*e.canvasX,o=i.top+i.height*e.canvasY;t.scrollLeft+=a-(r.left+e.cursorX),t.scrollTop+=o-(r.top+e.cursorY)});return()=>window.cancelAnimationFrame(t)},[L]),(0,r.useEffect)(()=>{let e=J.current;if(!e)return;let t=t=>{if(N.length===0||t.deltaY===0)return;t.preventDefault();let n=we.current,r=Math.max(3,Math.min(42,n+(t.deltaY<0?1:-1)));if(r===n)return;let i=e.getBoundingClientRect(),a=q.current?.getBoundingClientRect();Te.current={stage:e,cursorX:t.clientX-i.left,cursorY:t.clientY-i.top,canvasX:a?(t.clientX-a.left)/Math.max(1,a.width):.5,canvasY:a?(t.clientY-a.top)/Math.max(1,a.height):.5},we.current=r,R(r)};return e.addEventListener(`wheel`,t,{passive:!1}),()=>e.removeEventListener(`wheel`,t)},[N.length]);let Ae=n=>{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),de(o),A(o),G(`图片已载入,点击“重新转换”生成图纸`),De(s,o)},s.src=a},je=()=>{A(O),M(!0)},Me=e=>{let t=Ee.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)))}},Ne=(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,A({x:s>0?e:e-u,y:l>0?t:t-d,width:Math.max(.01,u),height:Math.max(.01,d)})},Pe=e=>{if(e.button!==0)return;let t=Me(e);e.currentTarget.setPointerCapture(e.pointerId),Y.current={pointerId:e.pointerId,startX:t.x,startY:t.y},A({x:t.x,y:t.y,width:.01,height:.01})},Fe=e=>{let t=Y.current;if(!t||t.pointerId!==e.pointerId)return;let n=Me(e);Ne(t.startX,t.startY,n.x,n.y)},Ie=e=>{Y.current?.pointerId===e.pointerId&&(Y.current=null),e.currentTarget.hasPointerCapture(e.pointerId)&&e.currentTarget.releasePointerCapture(e.pointerId)},Le=()=>{if(k.width<.03||k.height<.03){G(`框选区域太小,请在大图上拖出更大的选框`);return}de(k),M(!1),G(`取景区域已更新,点击“重新转换”生成图纸`)},$=e=>{F(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},Re=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})},ze=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,U(null))},Be=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))},Ve=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))},He=e=>{X.current?.pointerId===e.pointerId&&(X.current=null,Z.current=!1,J.current?.classList.remove(`is-dragging`))},Ue=e=>{if(Z.current){Z.current=!1;return}let t=q.current;if(!t)return;let n=t.getBoundingClientRect(),r=Math.max(22,L),i=Math.floor((e.clientX-n.left-r)/L),a=Math.floor((e.clientY-n.top-r)/L),o=N[a*_+i];i>=0&&a>=0&&i<_&&a<y&&o?.color&&$(o.color.code)},We=e=>{if(X.current?.moved){U(null);return}let t=q.current;if(!t)return;let n=t.getBoundingClientRect(),r=Math.max(22,L),i=Math.floor((e.clientX-n.left-r)/L),a=Math.floor((e.clientY-n.top-r)/L),o=N[a*_+i];if(i<0||a<0||i>=_||a>=y||!o?.color){U(null);return}U({row:a+1,column:i+1,color:o.color,left:e.clientX-n.left+14,top:e.clientY-n.top+14})},Ge=async e=>{await g(e),_e(e)},Ke=async()=>{if(N.length)try{await Ge([{id:p(),name:n.replace(/\.[^.]+$/,``)||`未命名图纸`,savedAt:new Date().toISOString(),width:_,height:y,colorLimit:S,codes:N.map(e=>e.color?.code??null)},...W].slice(0,l)),ye(``),G(`图纸已保存到本机历史记录`),requestAnimationFrame(()=>document.getElementById(`history-title`)?.scrollIntoView({behavior:`smooth`,block:`start`}))}catch{G(`保存历史失败,请检查浏览器是否允许本地存储或剩余空间是否充足`)}},qe=e=>{let t=new Map(x.map(e=>[e.code,e]));fe(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),T(e.colorLimit),i(e.name),F(new Set),G(`已恢复历史图纸:${e.name}`),document.getElementById(`pattern-preview`)?.scrollIntoView({behavior:`smooth`})},Je=async e=>{try{await Ge(W.filter(t=>t.id!==e))}catch{G(`删除历史失败,请稍后重试`)}},Ye=(0,r.useMemo)(()=>{let e=ve.trim().toLowerCase();return W.filter(t=>!e||t.name.toLowerCase().includes(e)||`${t.width}x${t.height}`.includes(e))},[W,ve]);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:Ae})]}),(0,a.jsx)(`p`,{className:`file-name`,title:n,children:n}),(0,a.jsx)(`button`,{className:`crop-select-button`,onClick:je,children:`选择取景区域`}),(0,a.jsx)(`button`,{className:`reset-crop`,onClick:()=>{de(o),A(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=>T(Number(e.target.value))})]}),(0,a.jsxs)(`label`,{className:`field`,children:[(0,a.jsx)(`span`,{children:`取色策略`}),(0,a.jsxs)(`select`,{value:D,onChange:e=>ue(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:E,onChange:e=>le(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:()=>De(),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:()=>R(e=>Math.max(3,e-1)),"aria-label":`缩小`,children:`−`}),(0,a.jsx)(`input`,{"aria-label":`缩放比例`,type:`range`,min:`3`,max:`42`,step:`1`,value:L,onChange:e=>R(Number(e.target.value))}),(0,a.jsx)(`button`,{onClick:()=>R(e=>Math.min(42,e+1)),"aria-label":`放大`,children:`+`}),(0,a.jsxs)(`output`,{children:[L,`px`]})]})]}),(0,a.jsx)(`div`,{className:`canvas-viewport`,children:(0,a.jsx)(`div`,{className:`canvas-stage`,ref:J,title:`鼠标位于预览区时,可滚动滚轮缩放图纸`,children:(0,a.jsxs)(`div`,{className:`canvas-wrap`,children:[(0,a.jsx)(`canvas`,{ref:q,onPointerDown:Re,onPointerMove:ze,onPointerUp:Be,onPointerCancel:Ve,onLostPointerCapture:He,onContextMenu:e=>e.preventDefault(),onClick:Ue,onMouseMove:We,onMouseLeave:()=>U(null),"aria-label":`转换后的拼豆像素图,可拖动查看,轻点格子选择颜色`}),H&&(0,a.jsxs)(`div`,{className:`pixel-tooltip`,style:{left:H.left,top:H.top},children:[(0,a.jsx)(`span`,{className:`tooltip-swatch`,style:{backgroundColor:H.color.hex}}),(0,a.jsxs)(`strong`,{children:[`第 `,H.row,` 行 · 第 `,H.column,` 列`]}),(0,a.jsxs)(`small`,{children:[H.color.code,` · `,H.color.name,` · `,H.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:z,onChange:e=>me(e.target.checked)}),` 网格`]}),(0,a.jsxs)(`label`,{children:[(0,a.jsx)(`input`,{type:`checkbox`,checked:B,onChange:e=>he(e.target.checked)}),` 格内编号`]}),(0,a.jsx)(`button`,{className:`save-button`,onClick:Ke,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:[`按数量从多到少,共 `,Q.length,` 色`]})]}),(0,a.jsx)(`div`,{className:`legend-list`,children:Q.map(e=>(0,a.jsxs)(`button`,{className:P.has(e.code)?`active`:``,onClick:()=>$(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:[Q.length,` 种颜色 · `,Oe,` 颗`]})]})]}),(0,a.jsxs)(`div`,{className:`search-box`,children:[(0,a.jsx)(`span`,{children:`⌕`}),(0,a.jsx)(`input`,{value:V,onChange:e=>ge(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:I,onChange:e=>pe(e.target.checked)}),(0,a.jsx)(`span`,{className:`switch`}),(0,a.jsx)(`span`,{children:`只显示选中颜色`})]}),P.size>0&&(0,a.jsxs)(`button`,{onClick:()=>F(new Set),children:[`清除 `,P.size,` 项`]})]}),(0,a.jsx)(`div`,{className:`color-list`,children:ke.map(e=>{let t=P.has(e.code);return(0,a.jsxs)(`button`,{className:`color-item ${t?`active`:``}`,onClick:()=>$(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 九个系列。屏幕色值仅用于近似匹配,实体豆颜色会受批次、光线和屏幕影响。`]})]})]}),j&&(0,a.jsx)(`div`,{className:`crop-dialog-backdrop`,role:`presentation`,onMouseDown:e=>{e.target===e.currentTarget&&M(!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:()=>M(!1),children:`×`})]}),(0,a.jsx)(`div`,{className:`crop-dialog-scroll`,children:(0,a.jsxs)(`div`,{className:`crop-dialog-stage`,ref:Ee,onPointerDown:Pe,onPointerMove:Fe,onPointerUp:Ie,onPointerCancel:Ie,children:[(0,a.jsx)(`canvas`,{ref:Ce,"aria-label":`可框选的原始大图`}),(0,a.jsx)(`div`,{className:`crop-selection-mask crop-selection-top`,style:{height:`${k.y*100}%`}}),(0,a.jsx)(`div`,{className:`crop-selection-mask crop-selection-left`,style:{top:`${k.y*100}%`,width:`${k.x*100}%`,height:`${k.height*100}%`}}),(0,a.jsx)(`div`,{className:`crop-selection-mask crop-selection-right`,style:{top:`${k.y*100}%`,left:`${(k.x+k.width)*100}%`,right:0,height:`${k.height*100}%`}}),(0,a.jsx)(`div`,{className:`crop-selection-mask crop-selection-bottom`,style:{top:`${(k.y+k.height)*100}%`}}),(0,a.jsx)(`div`,{className:`crop-selection-box`,style:{left:`${k.x*100}%`,top:`${k.y*100}%`,width:`${k.width*100}%`,height:`${k.height*100}%`}})]})}),(0,a.jsxs)(`div`,{className:`crop-dialog-actions`,children:[(0,a.jsx)(`button`,{onClick:()=>A(o),children:`选择整张图`}),(0,a.jsx)(`span`,{children:`从左上角拖向右下角即可重新框选`}),(0,a.jsx)(`button`,{onClick:()=>M(!1),children:`取消`}),(0,a.jsx)(`button`,{className:`confirm`,disabled:k.width<.03||k.height<.03,onClick:Le,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:ve,onChange:e=>ye(e.target.value),placeholder:`按名称或 32x32 查询`})]})]}),Ye.length?(0,a.jsx)(`div`,{className:`history-grid`,children:Ye.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:()=>qe(e),children:`打开`}),(0,a.jsx)(`button`,{onClick:()=>Je(e.id),children:`删除`})]})]},e.id)})}):(0,a.jsx)(`div`,{className:`history-empty`,children:`还没有符合条件的历史图纸。转换完成后点击“保存历史”即可在这里查询。`})]})]})}export{T as default}; |