import{r,j as e,a as E,v as Sr}from"./framework-flIpXurr.js";import{q as ls,o as cs,L as xa,M as wn,N as Cn,A as ds,U as Yt,Q as Wa,z as yt,c as Xt,d as Ba,e as La,f as Zt,g as qt,h as us,V as kr,t as ms,W as Fr,s as ps,v as hs,Y as Ar,Z as fs,S as Dr,E as Pr,a as Rr,X as vt,_ as Nn,$ as jn,C as Sn,a0 as Tr,n as _r,G as Ir,a1 as Mr,a2 as Ha,k as xs,a3 as Br,a4 as Lr,a5 as kn,a6 as Or,a7 as Fn,F as Gr,a8 as zr,a9 as Ur,w as Wr,B as Hr,x as $r,aa as Vr}from"./image-upload-DvZZvEi_.js";import{d as gs,L as Yr,P as Xr,I as Vt,k as An,l as Zr,m as qr,e as Kr,U as Qr,R as Jr,u as eo,c as to,n as ao,b as Dn,a as no,o as so,s as ro,S as Pn,h as Rn,F as gt,f as Tn,i as oo,j as io}from"./pattern-export-source-DAXqKyAF.js";import{b as ga,n as de,F as Oa,H as lo,D as _n,P as bs,I as ys,B as ke,w as $a,r as ha,L as co,c as ne,a as uo,y as mo,J as po,Z as ho,l as In,t as fo,v as xo}from"./rectangle-selection-overlay-Bblq5p9_.js";import{BeadGridCanvas as go}from"./bead-grid-canvas-BiNMzuMo.js";import{d as Je,e as et,f as vs,S as tt,b as at}from"./sheet-T4tIXgn9.js";import{c as Es,d as Ut,a as bo,u as yo,s as vo}from"./use-media-query-1yxTUMF5.js";import{ImageCropper as Eo}from"./image-cropper-D4xq9yaF.js";import{b as wo,c as Co,d as No,e as jo}from"./index-j6j51b9x.js";import{a as So}from"./saved-pattern-BLI9vXUR.js";const ws=ga("ExternalLink",[["path",{d:"M15 3h6v6",key:"1q9fwt"}],["path",{d:"M10 14 21 3",key:"gplh6r"}],["path",{d:"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6",key:"a6xqqp"}]]);const ko=ga("FlipHorizontal2",[["path",{d:"m3 7 5 5-5 5V7",key:"couhi7"}],["path",{d:"m21 7-5 5 5 5V7",key:"6ouia7"}],["path",{d:"M12 20v2",key:"1lh1kg"}],["path",{d:"M12 14v2",key:"8jcxud"}],["path",{d:"M12 8v2",key:"1woqiv"}],["path",{d:"M12 2v2",key:"tus03m"}]]);const Fo=ga("Settings",[["path",{d:"M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.08a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z",key:"1qme2f"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}]]);const Ga=ga("Share2",[["circle",{cx:"18",cy:"5",r:"3",key:"gq8acd"}],["circle",{cx:"6",cy:"12",r:"3",key:"w7nqdw"}],["circle",{cx:"18",cy:"19",r:"3",key:"1xt0gg"}],["line",{x1:"8.59",x2:"15.42",y1:"13.51",y2:"17.49",key:"47mynk"}],["line",{x1:"15.41",x2:"8.59",y1:"6.51",y2:"10.49",key:"1n3mei"}]]),Ao={id:"simplified",maxColors:8,analysisPixelsPerCell:4,minimumForegroundCoverage:.28,outlineDarkLuminance:.34,outlineDarkRatio:.22,outlineContrast:.18,outlineWeight:3,backgroundSeedDeltaE:8,backgroundFillDeltaE:13,backgroundMinimumConfidence:.85,cleanupMinimumNeighbors:4,cellSamplingMode:"dominant-bucket",colorBucketBits:4,paletteSelectionMode:"fixed-palette-greedy",colorDistanceMode:"oklab",ditheringMode:"none",spatialRegularizationIterations:2,spatialSmoothness:3,spatialEdgeSigma:8},Do={id:"standard",maxColors:10,analysisPixelsPerCell:4,minimumForegroundCoverage:.2,outlineDarkLuminance:.32,outlineDarkRatio:.2,outlineContrast:.16,outlineWeight:2.5,backgroundSeedDeltaE:8,backgroundFillDeltaE:14,backgroundMinimumConfidence:.85,cleanupMinimumNeighbors:5,cellSamplingMode:"dominant-bucket",colorBucketBits:4,paletteSelectionMode:"fixed-palette-greedy",colorDistanceMode:"oklab",ditheringMode:"none",spatialRegularizationIterations:2,spatialSmoothness:2,spatialEdgeSigma:10},Po={id:"detailed",maxColors:16,analysisPixelsPerCell:4,minimumForegroundCoverage:.12,outlineDarkLuminance:.28,outlineDarkRatio:.3,outlineContrast:.22,outlineWeight:1.5,backgroundSeedDeltaE:8,backgroundFillDeltaE:13,backgroundMinimumConfidence:.88,cleanupMinimumNeighbors:7,cellSamplingMode:"dominant-bucket",colorBucketBits:5,paletteSelectionMode:"fixed-palette-greedy",colorDistanceMode:"ciede2000",ditheringMode:"floyd-steinberg",spatialRegularizationIterations:1,spatialSmoothness:1,spatialEdgeSigma:12},Ro={id:"legacy",maxColors:null,analysisPixelsPerCell:1,minimumForegroundCoverage:0,outlineDarkLuminance:0,outlineDarkRatio:1,outlineContrast:1,outlineWeight:1,backgroundSeedDeltaE:0,backgroundFillDeltaE:0,backgroundMinimumConfidence:1,cleanupMinimumNeighbors:null,cellSamplingMode:"average",colorBucketBits:null,paletteSelectionMode:"cluster-then-snap",colorDistanceMode:"oklab",ditheringMode:"none",spatialRegularizationIterations:0,spatialSmoothness:0,spatialEdgeSigma:1},To={id:"zippland",maxColors:null,analysisPixelsPerCell:1,minimumForegroundCoverage:0,outlineDarkLuminance:0,outlineDarkRatio:1,outlineContrast:1,outlineWeight:1,backgroundSeedDeltaE:0,backgroundFillDeltaE:0,backgroundMinimumConfidence:1,cleanupMinimumNeighbors:null,cellSamplingMode:"average",colorBucketBits:null,paletteSelectionMode:"cluster-then-snap",colorDistanceMode:"oklab",ditheringMode:"none",spatialRegularizationIterations:0,spatialSmoothness:0,spatialEdgeSigma:1},_o={zippland:To,simplified:Ao,standard:Do,detailed:Po,legacy:Ro},Wt=200,Mn=10,Io="EMPTY_PATTERN";function Bn(){const t=new Error("Image processing was replaced by a newer task");return t.name="AbortError",t}function Mo(t,a,n){if(n)return{width:n.columns,height:n.rows};const o=t.naturalWidth||t.width,l=t.naturalHeight||t.height,i=Math.max(Mn,Math.min(Wt,a)),c=l/Math.max(o,1),h=Math.max(1,Math.round(i*c));if(h<=Wt)return{width:i,height:h};const u=Math.max(Mn,Math.round(i*(Wt/h)));return{width:Math.min(Wt,u),height:Wt}}function Bo(t,a,n,o,l){if(l)return{width:t.naturalWidth||t.width,height:t.naturalHeight||t.height};if(o.preset==="legacy")return{width:a,height:n};const i=t.naturalWidth||t.width,c=t.naturalHeight||t.height;if(o.preset==="zippland")return{width:i,height:c};const h=_o[o.preset].analysisPixelsPerCell,u=Math.max(a*h/Math.max(1,i),n*h/Math.max(1,c)),m=Math.min(1,u,1024/Math.max(1,i),1024/Math.max(1,c));return{width:Math.max(1,Math.round(i*m)),height:Math.max(1,Math.round(c*m))}}function Lo(){const[t,a]=r.useState(null),[n,o]=r.useState(!1),l=r.useRef(null),i=r.useRef(0),c=r.useCallback(()=>{const u=l.current;u&&(l.current=null,u.worker.terminate(),u.reject(Bn()),o(!1))},[]);r.useEffect(()=>()=>{const u=l.current;u&&(l.current=null,u.worker.terminate(),u.reject(Bn()))},[]);const h=r.useCallback((u,m,y,F,A)=>(c(),o(!0),new Promise((d,k)=>{try{const v=document.createElement("canvas"),N=v.getContext("2d");if(!N){o(!1),k(new Error("Failed to get canvas context"));return}const{width:O,height:f}=Mo(u,m,A),x=Bo(u,O,f,F,A);v.width=x.width,v.height=x.height,N.imageSmoothingEnabled=!0,N.imageSmoothingQuality="high",N.drawImage(u,0,0,x.width,x.height);const M=N.getImageData(0,0,x.width,x.height),D=new Worker(new URL("/assets/processing.worker-DWPC8ic2.js",import.meta.url),{type:"module"}),_=++i.current;l.current={id:_,worker:D,reject:k},D.onmessage=$=>{if(l.current?.id!==_)return;if(l.current=null,D.terminate(),o(!1),$.data.error){k(new Error($.data.error));return}const L=$.data;d({matrix:L.matrix,width:O,height:f,diagnostics:L.diagnostics})},D.onerror=$=>{l.current?.id===_&&(l.current=null,D.terminate(),o(!1),k($))},D.postMessage({imageData:M.data,imageWidth:x.width,imageHeight:x.height,targetWidth:O,targetHeight:f,activePalette:y.map(({id:$,hex:L})=>({id:$,hex:L})),options:F,sourceGrid:A},[M.data.buffer])}catch(v){o(!1),k(v)}})),[c]);return{image:t,setImage:a,isProcessing:n,processImage:h}}const za=96,Oo=25.4,Ln=10,On=200,Gn=[52,104];function zn(t,a,n){return Number.isFinite(t)?Math.max(a,Math.min(n,Math.round(t))):a}function Go({label:t,value:a,onChange:n}){return e.jsxs("label",{className:"flex min-h-9 items-center justify-between gap-2 text-[10px] font-bold text-[#6F5C4D]",children:[e.jsx("span",{children:t}),e.jsxs("span",{className:"flex h-8 items-center gap-1.5 rounded-lg border border-[#D8CBB9] bg-white px-1.5",children:[e.jsx("input",{type:"color",value:a,onChange:o=>n(o.target.value),className:"h-6 w-7 cursor-pointer border-0 bg-transparent p-0","aria-label":t}),e.jsx("span",{className:"font-mono text-[9px] uppercase text-[#8A7768]",children:a})]})]})}function Un(t,a=za){return t*a/Oo}function zo(t){return Un(t==="5mm"?5:2.6,za)}function Uo({gridWidth:t,onGridWidthChange:a,cellSizeUnit:n,onCellSizeUnitChange:o,selectedPalette:l,onPaletteChange:i,selectedMardCategory:c,onMardCategoryChange:h,generationPreset:u,onGenerationPresetChange:m,showReferenceGrid:y,showGridNumbers:F,onToggleReferenceGrid:A,onToggleGridNumbers:d,gridGuideSettings:k,onGridGuideSettingsChange:v,onResetGridGuideSettings:N,showHeading:O=!0}){const f=de("Generator"),x=Gn.some(p=>p===t),[M,D]=r.useState(!x),[_,$]=r.useState(!1);r.useEffect(()=>{x||D(!0)},[x]);const L=p=>{D(!1),a(p)};return e.jsxs("div",{className:"space-y-0.5",children:[O&&e.jsx("div",{className:"text-[10px] font-black uppercase tracking-[0.2em] text-[#8F7E6F]",children:f("settings")}),e.jsxs("div",{className:"space-y-0.5",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx("label",{htmlFor:"generation-preset",className:"text-[10px] font-bold uppercase leading-3 text-[#5A4738]",children:f("patternMode")}),e.jsxs("select",{id:"generation-preset",value:u,onChange:p=>m(p.target.value),className:"w-full rounded-lg border-none bg-[#F7F1E1] px-2.5 py-1.5 text-xs text-[#3E2A1E] focus:ring-1 focus:ring-[#3E2A1E]",children:[e.jsx("option",{value:"zippland",children:f("patternModeZippland")}),e.jsx("option",{value:"simplified",children:f("patternModeSimplified")}),e.jsx("option",{value:"standard",children:f("patternModeStandard")}),e.jsx("option",{value:"detailed",children:f("patternModeDetailed")}),e.jsx("option",{value:"legacy",children:f("patternModeLegacy")})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex justify-between text-[10px] font-bold uppercase text-[#5A4738]",children:[e.jsx("span",{children:f("width")}),e.jsxs("span",{children:[t," ",f("units")]})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-1.5",role:"group","aria-label":f("width"),children:[Gn.map(p=>{const g=!M&&t===p;return e.jsxs("button",{type:"button",onClick:()=>L(p),"aria-pressed":g,className:`min-h-10 rounded-lg px-1.5 text-[10px] font-bold transition-all focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#3E2A1E] focus-visible:ring-offset-2 lg:min-h-9 ${g?"bg-[#3E2A1E] text-white shadow-md":"bg-[#F7F1E1] text-[#5A4738] hover:bg-[#F0EEE8] hover:text-[#3E2A1E]"}`,children:[p," ",f("units")]},p)}),e.jsx("button",{type:"button",onClick:()=>D(!0),"aria-expanded":M,"aria-controls":"custom-grid-width-controls","aria-pressed":M,className:`min-h-10 rounded-lg px-1.5 text-[10px] font-bold transition-all focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#3E2A1E] focus-visible:ring-offset-2 lg:min-h-9 ${M?"bg-[#3E2A1E] text-white shadow-md":"bg-[#F7F1E1] text-[#5A4738] hover:bg-[#F0EEE8] hover:text-[#3E2A1E]"}`,children:f("widthCustom")})]}),M&&e.jsxs("div",{id:"custom-grid-width-controls",className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>a(Math.max(Ln,t-1)),className:"w-10 h-10 shrink-0 flex items-center justify-center bg-[#F7F1E1] hover:bg-[#F0EEE8] text-[#3E2A1E] rounded-lg font-bold text-sm transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#3E2A1E] focus-visible:ring-offset-2 lg:h-9 lg:w-9","aria-label":f("decreaseWidth"),children:"−"}),e.jsx("input",{type:"range",min:Ln,max:On,value:t,onChange:p=>a(parseInt(p.target.value,10)),className:"flex-1 h-1 bg-[#F0EEE8] appearance-none cursor-pointer accent-[#3E2A1E]","aria-label":f("width")}),e.jsx("button",{type:"button",onClick:()=>a(Math.min(On,t+1)),className:"w-10 h-10 shrink-0 flex items-center justify-center bg-[#F7F1E1] hover:bg-[#F0EEE8] text-[#3E2A1E] rounded-lg font-bold text-sm transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#3E2A1E] focus-visible:ring-offset-2 lg:h-9 lg:w-9","aria-label":f("increaseWidth"),children:"+"})]}),e.jsx("p",{className:"text-[9px] font-semibold leading-3 text-[#8F7E6F]",children:f("heightAutoHint")})]}),e.jsxs("div",{className:"space-y-0.5",children:[e.jsx("span",{className:"text-[10px] font-bold uppercase leading-3 text-[#5A4738]",children:f("cellSize")}),e.jsx("div",{className:"grid grid-cols-2 gap-2",children:["5mm","2.6mm"].map(p=>{const g=n===p;return e.jsx("button",{onClick:()=>o(p),className:`min-h-9 px-3 py-1 rounded-lg text-[10px] font-bold uppercase tracking-wider transition-all lg:min-h-8 ${g?"bg-[#3E2A1E] text-white shadow-lg":"bg-[#F7F1E1] text-[#5A4738] hover:bg-[#F0EEE8] hover:text-[#3E2A1E]"}`,children:f(p==="5mm"?"cellSizeUnit5mm":"cellSizeUnit26mm")},p)})})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"text-[10px] font-bold uppercase leading-3 text-[#5A4738]",children:f("referenceGrid")}),e.jsxs("button",{type:"button",onClick:()=>$(p=>!p),"aria-expanded":_,"aria-controls":"generator-grid-settings",className:"flex min-h-8 items-center gap-1 rounded-lg px-2 text-[10px] font-bold text-[#6F5C4D] transition hover:bg-[#F7F1E1] hover:text-[#3E2A1E] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#3E2A1E]",children:[f("gridSettings"),e.jsx(ls,{className:`h-3.5 w-3.5 transition-transform ${_?"rotate-180":""}`,"aria-hidden":"true"})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",role:"group","aria-label":f("referenceGridControls"),children:[e.jsx("button",{type:"button","aria-pressed":y,onClick:A,className:`min-h-10 rounded-lg border px-2 text-[10px] font-bold transition focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#437EC8] focus-visible:ring-offset-2 lg:min-h-9 ${y?"border-[#9FC3ED] bg-[#E9F2FF] text-[#315F9D]":"border-transparent bg-[#F7F1E1] text-[#5A4738] hover:bg-[#F0EEE8]"}`,children:f("referenceGrid")}),e.jsx("button",{type:"button",disabled:!y,"aria-pressed":y&&F,onClick:d,className:`min-h-10 rounded-lg border px-2 text-[10px] font-bold transition focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#437EC8] focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-45 lg:min-h-9 ${y&&F?"border-[#9FC3ED] bg-[#E9F2FF] text-[#315F9D]":"border-transparent bg-[#F7F1E1] text-[#5A4738] hover:bg-[#F0EEE8]"}`,children:f("gridCoordinates")})]}),e.jsx("p",{className:"text-[9px] font-semibold leading-3 text-[#8F7E6F]",children:f("referenceGridHint",{reference:k.referenceGridInterval,major:k.majorGridInterval})}),_&&e.jsxs("div",{id:"generator-grid-settings",className:"space-y-2 rounded-xl border border-[#E1D6C7] bg-[#F7F1E7] p-2.5",children:[e.jsx(Go,{label:f("minorGrid"),value:k.minorColor,onChange:p=>v({minorColor:p})}),e.jsx("div",{className:"rounded-lg border border-[#E1D6C7] bg-white p-2",children:e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"min-w-0 flex-1 text-[10px] font-black text-[#5A4738]",children:f("referenceGrid")}),e.jsx("span",{className:"text-[9px] font-bold text-[#756253]",children:f("lineEvery")}),e.jsx("input",{type:"number","aria-label":`${f("referenceGrid")} ${f("lineEvery")}`,min:"2",max:"50",value:k.referenceGridInterval,onChange:p=>v({referenceGridInterval:zn(Number(p.target.value),2,50)}),className:"h-8 w-12 rounded-lg border border-[#D8CBB9] px-1 text-center text-xs font-black outline-none focus:border-[#437EC8]"}),e.jsx("input",{type:"color","aria-label":f("referenceGridColor"),value:k.referenceGridColor,onChange:p=>v({referenceGridColor:p.target.value}),className:"h-8 w-10 cursor-pointer rounded-lg border border-[#D8CBB9] bg-white p-1"})]})}),e.jsxs("div",{className:"flex items-center gap-1.5 rounded-lg border border-[#E1D6C7] bg-white p-2",children:[e.jsx("span",{className:"min-w-0 flex-1 text-[10px] font-black text-[#5A4738]",children:f("majorGrid")}),e.jsx("span",{className:"text-[9px] font-bold text-[#756253]",children:f("lineEvery")}),e.jsx("input",{type:"number","aria-label":`${f("majorGrid")} ${f("lineEvery")}`,min:"2",max:"100",value:k.majorGridInterval,onChange:p=>v({majorGridInterval:zn(Number(p.target.value),2,100)}),className:"h-8 w-12 rounded-lg border border-[#D8CBB9] px-1 text-center text-xs font-black outline-none focus:border-[#437EC8]"}),e.jsx("input",{type:"color","aria-label":f("majorGridColor"),value:k.majorGridColor,onChange:p=>v({majorGridColor:p.target.value}),className:"h-8 w-10 cursor-pointer rounded-lg border border-[#D8CBB9] bg-white p-1"})]}),e.jsxs("button",{type:"button",onClick:N,className:"flex min-h-9 w-full items-center justify-center gap-1.5 rounded-lg border border-[#D8CBB9] bg-white px-2 text-[10px] font-black text-[#6F5C4D] transition hover:border-[#437EC8] hover:text-[#315F9D] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#437EC8]",children:[e.jsx(cs,{className:"h-3.5 w-3.5","aria-hidden":"true"}),f("resetGrid")]})]})]}),e.jsxs("div",{className:"space-y-0.5",children:[e.jsx("span",{className:"text-[10px] font-bold uppercase leading-3 text-[#5A4738]",children:f("beadBrand")}),e.jsx("select",{value:l,onChange:p=>i(p.target.value),className:"w-full bg-[#F7F1E1] px-2.5 py-1.5 text-xs text-[#3E2A1E] border-none focus:ring-1 focus:ring-[#3E2A1E] rounded-lg",children:Object.keys(Oa).map(p=>e.jsx("option",{value:p,children:Oa[p]},p))})]}),l==="MARD"&&e.jsxs("div",{className:"space-y-0.5",children:[e.jsx("span",{className:"text-[10px] font-bold uppercase leading-3 text-[#5A4738]",children:f("mardCategory")}),e.jsxs("select",{value:c,onChange:p=>h(p.target.value),className:"w-full bg-[#F7F1E1] px-2.5 py-1.5 text-xs text-[#3E2A1E] border-none focus:ring-1 focus:ring-[#3E2A1E] rounded-lg",children:[lo.map(p=>e.jsxs("option",{value:p,children:[p," ",f("colors")]},p)),e.jsxs("option",{value:"all",children:[f("allColors")," (291)"]})]})]})]})]})}const Wo={easy:{gridWidth:30,cellSize:15},medium:{gridWidth:52,cellSize:17},hard:{gridWidth:80,cellSize:8},custom:{gridWidth:65,cellSize:8}},se=xa((t,a)=>({matrix:[],gridWidth:52,cellSize:10,cellSizeUnit:"2.6mm",beadStyle:"square",gridSpacing:"small",selectedDifficulty:"medium",selectedPalette:"MARD",selectedMardCategory:"221",generationPreset:"zippland",backgroundMode:"auto",drawingLayer:{...wn},boardLayer:{...wn},showBeadCodes:!1,showReferenceGrid:!0,showGridNumbers:!0,gridGuideSettings:{..._n},setMatrix:n=>t({matrix:n}),setCell:(n,o,l)=>{const{matrix:i}=a();if(!i[n]||i[n][o]===void 0)return;const c=i.map(h=>[...h]);c[n][o]=l,t({matrix:c})},clearCell:(n,o)=>{const{matrix:l}=a();if(!l[n]||l[n][o]===void 0)return;const i=l.map(c=>[...c]);i[n][o]="",t({matrix:i})},setGridWidth:n=>t({gridWidth:Math.max(10,Math.min(200,n))}),setCellSize:n=>t({cellSize:n}),setCellSizeUnit:n=>t({cellSizeUnit:n}),setBeadStyle:n=>t({beadStyle:n}),setGridSpacing:n=>t({gridSpacing:n}),setSelectedDifficulty:n=>t({selectedDifficulty:n}),setSelectedPalette:n=>t({selectedPalette:n}),setSelectedMardCategory:n=>t({selectedMardCategory:n}),setGenerationPreset:n=>t({generationPreset:n}),setBackgroundMode:n=>t({backgroundMode:n}),updateDrawingLayer:n=>t(o=>({drawingLayer:Cn(o.drawingLayer,n)})),updateBoardLayer:n=>t(o=>({boardLayer:Cn(o.boardLayer,n)})),toggleBeadCodes:()=>t(n=>({showBeadCodes:!n.showBeadCodes})),toggleReferenceGrid:()=>t(n=>({showReferenceGrid:!n.showReferenceGrid})),toggleGridNumbers:()=>t(n=>({showGridNumbers:!n.showGridNumbers})),updateGridGuideSettings:n=>t(o=>({gridGuideSettings:{...o.gridGuideSettings,...n}})),resetGridGuideSettings:()=>t({showReferenceGrid:!0,showGridNumbers:!0,gridGuideSettings:{..._n}}),applyDifficulty:n=>{const o=Wo[n];t({selectedDifficulty:n,gridWidth:o.gridWidth,cellSize:o.cellSize})},getActivePalette:()=>{const{selectedPalette:n,selectedMardCategory:o}=a(),l=bs[n]??[];if(n!=="MARD")return l;const i=ys[o];if(!i)return l;const c=new Set(i.keys);return l.filter(h=>!!h.code&&c.has(h.code))}}));function Cs({handleImageUpload:t,inputId:a,showHeading:n=!0,uploadError:o}){const l=de("Generator");return e.jsxs("section",{className:"space-y-1",children:[n&&e.jsxs("div",{className:"flex items-center gap-2 text-[10px] font-black uppercase tracking-[0.2em] text-[#8F7E6F]",children:[e.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-[#3E2A1E]"}),l("imageSource")]}),e.jsx("input",{type:"file",id:a,hidden:!0,onChange:t,accept:ds}),e.jsxs("label",{htmlFor:a,className:"group flex w-full cursor-pointer items-center justify-center gap-2 rounded-xl border-2 border-dashed border-[#D8CBB9] py-2.5 text-[10px] font-bold uppercase tracking-widest text-[#8F7E6F] transition-all hover:border-[#3E2A1E] hover:bg-[#F7F1E1]/50 hover:text-[#3E2A1E]",children:[e.jsx(Yt,{size:14,className:"transition-transform group-hover:scale-110","aria-hidden":"true"}),l("replaceImage")]}),e.jsx("p",{className:`min-h-4 text-[10px] font-semibold leading-4 ${o?"text-[#B74343]":"text-[#8F7E6F]"}`,role:o?"alert":void 0,"aria-live":"polite",children:o||l("uploadRequirements",{size:Wa})})]})}function Ns({hasManualEdits:t=!1,hasPattern:a=!1,onGridWidthApplied:n,showHeading:o=!0}){const l=de("Generator"),{gridWidth:i,setGridWidth:c,setCellSize:h,cellSizeUnit:u,setCellSizeUnit:m,selectedPalette:y,setSelectedPalette:F,selectedMardCategory:A,setSelectedMardCategory:d,generationPreset:k,setGenerationPreset:v,showReferenceGrid:N,showGridNumbers:O,toggleReferenceGrid:f,toggleGridNumbers:x,gridGuideSettings:M,updateGridGuideSettings:D,resetGridGuideSettings:_}=se(yt(T=>({gridWidth:T.gridWidth,setGridWidth:T.setGridWidth,setCellSize:T.setCellSize,cellSizeUnit:T.cellSizeUnit,setCellSizeUnit:T.setCellSizeUnit,selectedPalette:T.selectedPalette,setSelectedPalette:T.setSelectedPalette,selectedMardCategory:T.selectedMardCategory,setSelectedMardCategory:T.setSelectedMardCategory,generationPreset:T.generationPreset,setGenerationPreset:T.setGenerationPreset,showReferenceGrid:T.showReferenceGrid,showGridNumbers:T.showGridNumbers,toggleReferenceGrid:T.toggleReferenceGrid,toggleGridNumbers:T.toggleGridNumbers,gridGuideSettings:T.gridGuideSettings,updateGridGuideSettings:T.updateGridGuideSettings,resetGridGuideSettings:T.resetGridGuideSettings}))),[$,L]=r.useState(!1),[p,g]=r.useState(()=>({generationPreset:k,gridWidth:i,selectedMardCategory:A,selectedPalette:y})),j=r.useCallback(T=>{const w=zo(T);h(Math.round(w)),m(T)},[h,m]);r.useEffect(()=>{g({generationPreset:k,gridWidth:i,selectedMardCategory:A,selectedPalette:y})},[k,i,A,y]);const V=r.useMemo(()=>p.generationPreset!==k||p.gridWidth!==i||p.selectedMardCategory!==A||p.selectedPalette!==y,[p.generationPreset,p.gridWidth,p.selectedMardCategory,p.selectedPalette,k,i,A,y]),K=r.useCallback(()=>{n?.(p.gridWidth),c(p.gridWidth),F(p.selectedPalette),d(p.selectedMardCategory),v(p.generationPreset),L(!1)},[p.generationPreset,p.gridWidth,p.selectedMardCategory,p.selectedPalette,n,v,c,d,F]),te=()=>{if(V){if(a&&t){L(!0);return}K()}};return e.jsxs(e.Fragment,{children:[e.jsx(Uo,{gridWidth:p.gridWidth,onGridWidthChange:T=>g(w=>({...w,gridWidth:T})),cellSizeUnit:u,onCellSizeUnitChange:j,selectedPalette:p.selectedPalette,onPaletteChange:T=>g(w=>({...w,selectedPalette:T})),selectedMardCategory:p.selectedMardCategory,onMardCategoryChange:T=>g(w=>({...w,selectedMardCategory:T})),generationPreset:p.generationPreset,onGenerationPresetChange:T=>g(w=>({...w,generationPreset:T})),showReferenceGrid:N,showGridNumbers:O,onToggleReferenceGrid:f,onToggleGridNumbers:x,gridGuideSettings:M,onGridGuideSettingsChange:D,onResetGridGuideSettings:_,showHeading:o}),e.jsxs("div",{className:"mt-3 border-t border-[#E7DDCF] pt-3",children:[e.jsx(ke,{type:"button",onClick:te,disabled:!V,className:"min-h-11 w-full bg-[#168B7D] font-black text-white hover:bg-[#117568]",children:l(a?"regeneratePattern":"applyGenerationSettings")}),e.jsx("p",{className:"mt-1.5 text-[10px] font-semibold leading-4 text-[#8A7768]",children:l(V?"generationSettingsPending":"generationSettingsApplied")})]}),e.jsx(Xt,{open:$,onOpenChange:L,children:e.jsxs(Ba,{closeLabel:l("cancel"),className:"max-w-md border-[#D8CBB9] bg-[#FFFDF8]",children:[e.jsxs(La,{children:[e.jsx(Zt,{children:l("regenerateConfirmTitle")}),e.jsx(qt,{children:l("regenerateConfirmDescription")})]}),e.jsxs(us,{className:"gap-2 sm:gap-0",children:[e.jsx(ke,{type:"button",variant:"outline",onClick:()=>L(!1),children:l("cancel")}),e.jsx(ke,{type:"button",className:"bg-[#B74736] text-white hover:bg-[#963A2C]",onClick:K,children:l("regenerateAndReplaceEdits")})]})]})})]})}function Ho({handleImageUpload:t,hasManualEdits:a=!1,hasPattern:n=!1,inputId:o,onGridWidthApplied:l,uploadError:i}){return e.jsxs("div",{className:"flex flex-col space-y-1 px-4 pb-2 pt-2.5",children:[e.jsx(Cs,{handleImageUpload:t,inputId:o,uploadError:i}),e.jsx("div",{className:"w-full h-px bg-[#F0EEE8]"}),e.jsx(Ns,{hasManualEdits:a,hasPattern:n,onGridWidthApplied:l})]})}const $o={source:"generator-source-panel",tools:"generator-tools-panel",layers:"generator-layers-panel",settings:"generator-settings-panel",symmetry:"generator-symmetry-panel",palette:"generator-palette-panel",export:"generator-export-panel"};function Vo({exportDisabled:t=!1,onToggle:a,openPanels:n,paletteDisabled:o=!1,symmetryDisabled:l=!1}){const i=de("Generator"),c=de("PerlerBeadArt"),h=[{id:"source",label:i("sourcePanel"),icon:kr,activeClass:"bg-[#FFF0E4] text-[#C96535]",disabled:!1},{id:"tools",label:i("editTools"),icon:ms,activeClass:"bg-[#DDF5F1] text-[#168B7D]",disabled:!1},{id:"layers",label:i("layers"),icon:gs,activeClass:"bg-[#F1EAFB] text-[#7552A3]",disabled:!1},{id:"settings",label:i("generatePanel"),icon:Fr,activeClass:"bg-[#E9F2FF] text-[#437EC8]",disabled:!1},{id:"symmetry",label:c("symmetryTitle"),icon:ps,activeClass:"bg-[#FCEAF1] text-[#B93568]",disabled:l},{id:"palette",label:i("materialsPanel"),icon:hs,activeClass:"bg-[#F1EAFB] text-[#7552A3]",disabled:o},{id:"export",label:i("export"),icon:$a,activeClass:"bg-[#E8F4E8] text-[#397A46]",disabled:t}];return e.jsx("aside",{className:"hidden w-20 shrink-0 flex-col items-center gap-2 overflow-y-auto border-r border-[#D8CBB9] bg-[#FFFDF8] py-4 lg:flex","aria-label":i("workspacePanels"),children:h.map((u,m)=>{const y=u.icon,F=n[u.id],A=u.id==="symmetry"?i("uploadToUseSymmetry"):u.id==="palette"?i("uploadToUsePalette"):u.id==="export"?i("uploadToUseExport"):void 0;return e.jsxs("div",{className:"contents",children:[m===4&&e.jsx("div",{className:"my-1 h-px w-10 bg-[#E7DDCF]","aria-hidden":"true"}),e.jsxs("button",{type:"button",className:`flex w-16 flex-col items-center gap-1 rounded-xl px-2 py-2 text-[10px] font-black transition focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#32B8A6] focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-35 ${F?u.activeClass:"text-[#756253] hover:bg-[#F4EEE4]"}`,onClick:()=>a(u.id),disabled:u.disabled,"aria-expanded":F,"aria-controls":$o[u.id],title:u.disabled?A:u.label,children:[e.jsx(y,{className:"h-5 w-5","aria-hidden":"true"}),e.jsx("span",{children:u.label})]})]},u.id)})})}function Wn(){const t=de("Generator"),{drawingLayer:a,boardLayer:n,updateDrawingLayer:o,updateBoardLayer:l}=se(yt(m=>({drawingLayer:m.drawingLayer,boardLayer:m.boardLayer,updateDrawingLayer:m.updateDrawingLayer,updateBoardLayer:m.updateBoardLayer}))),i=m=>({showLabel:t("showLayer",{layer:m}),hideLabel:t("hideLayer",{layer:m}),opacityLabel:t("layerOpacity",{layer:m})}),c=t("drawingLayer"),h=t("boardLayer"),u=[{id:"generator-drawing",label:c,visible:a.visible,opacity:a.opacity,...i(c),onVisibilityChange:m=>o({visible:m}),onOpacityChange:m=>o({opacity:m})},{id:"generator-board",label:h,visible:n.visible,opacity:n.opacity,...i(h),onVisibilityChange:m=>l({visible:m}),onOpacityChange:m=>l({opacity:m})}];return e.jsx(Yr,{items:u})}function Yo({activeTab:t,onTabChange:a,paletteDisabled:n=!1,exportDisabled:o=!1,symmetryDisabled:l=!1}){const i=de("Generator"),c=de("PerlerBeadArt"),h=[{id:"tools",label:i("editTools"),icon:ms,disabled:n},{id:"settings",label:i("generatePanel"),icon:Fo,disabled:!1},{id:"layers",label:i("layers"),icon:gs,disabled:!1},{id:"symmetry",label:c("symmetryTitle"),icon:ps,disabled:l},{id:"palette",label:i("paletteTool"),icon:hs,disabled:n},{id:"export",label:i("export"),icon:$a,disabled:o}];return e.jsx("div",{className:"lg:hidden fixed bottom-0 left-0 right-0 bg-white border-t border-[#D8CBB9] pb-safe z-40",children:e.jsx("div",{className:"flex justify-around items-center h-16",children:h.map(u=>{const m=t===u.id;return e.jsxs("button",{type:"button",disabled:u.disabled,onClick:()=>a(m?null:u.id),"aria-expanded":m,"aria-label":u.label,className:`flex flex-col items-center justify-center gap-1 w-full h-full transition-colors disabled:cursor-not-allowed disabled:opacity-40 ${m?"text-[#3E2A1E]":"text-[#8F7E6F] hover:text-[#5A4738]"}`,children:[e.jsx(u.icon,{size:20,className:m?"stroke-[2.5px]":"stroke-2"}),e.jsx("span",{className:`text-[10px] uppercase font-bold tracking-wider ${m?"opacity-100":"opacity-70"}`,children:u.label})]},u.id)})})})}function Xo({onUpload:t,isProcessing:a=!1,isCropPending:n=!1,error:o}){const l=de("Generator"),i=h=>{t(h)},c=n||a;return e.jsxs("div",{className:`flex flex-col items-center justify-center p-8 min-[375px]:p-12 bg-white/50 backdrop-blur-sm border border-white shadow-2xl rounded-[32px] text-center animate-in fade-in zoom-in slide-in-from-bottom-8 duration-700 ease-out max-w-lg mx-auto ${c?"cursor-wait":"cursor-pointer hover:scale-[1.02] transition-transform duration-300"}`,children:[e.jsxs("div",{className:"relative group",children:[e.jsx("div",{className:"absolute -inset-4 bg-[#3E2A1E]/5 rounded-full blur-xl group-hover:bg-[#3E2A1E]/10 transition-all duration-500"}),e.jsx("div",{className:"relative inline-flex p-10 bg-white border border-[#D8CBB9] rounded-full shadow-lg mb-8 transition-transform duration-500 group-hover:scale-110",children:e.jsx(Yt,{size:48,className:"text-[#3E2A1E]"})})]}),e.jsx("h1",{className:"text-2xl min-[375px]:text-3xl font-black text-[#3E2A1E] mb-4 tracking-tighter uppercase",children:l("title")}),e.jsx("p",{className:"text-[#5A4738] text-base leading-relaxed mb-10 max-w-[320px] font-medium",children:l("description")}),e.jsxs("div",{className:"flex w-full max-w-[360px] flex-col items-stretch justify-center gap-3 min-[440px]:flex-row",children:[e.jsxs("label",{htmlFor:"upload",className:`relative inline-flex min-h-14 flex-1 items-center justify-center gap-3 overflow-hidden rounded-2xl bg-[#32B8A6] px-7 py-4 text-[12px] font-black uppercase tracking-[0.16em] text-white shadow-[0_16px_32px_rgba(50,184,166,0.28)] transition-all duration-300 focus-within:ring-2 focus-within:ring-[#3E2A1E] focus-within:ring-offset-2 ${c?"cursor-wait opacity-75":"cursor-pointer hover:-translate-y-0.5 hover:bg-[#28A997] hover:shadow-[0_20px_38px_rgba(50,184,166,0.36)] active:translate-y-0"}`,children:[e.jsx("span",{className:"relative z-10 flex items-center gap-3",children:c?e.jsxs(e.Fragment,{children:[e.jsx(ha,{size:16,className:"animate-spin"}),l(n?"loadingImage":"processing")]}):e.jsxs(e.Fragment,{children:[e.jsx(Yt,{size:16}),l("getStarted")]})}),e.jsx("input",{type:"file",id:"upload",className:"absolute inset-0 opacity-0 cursor-pointer",onChange:i,accept:ds,disabled:c})]}),e.jsxs(co,{href:"/perler-bead-art",className:"inline-flex min-h-14 flex-1 items-center justify-center gap-3 rounded-2xl border-2 border-[#3E2A1E] bg-white/55 px-7 py-4 text-[12px] font-black uppercase tracking-[0.16em] text-[#3E2A1E] shadow-[0_10px_24px_rgba(62,42,30,0.08)] transition-all duration-300 hover:-translate-y-0.5 hover:bg-[#3E2A1E] hover:text-[#F7F1E1] hover:shadow-[0_16px_32px_rgba(62,42,30,0.18)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#32B8A6] focus-visible:ring-offset-2 active:translate-y-0",children:[e.jsx(Xr,{size:16,"aria-hidden":"true"}),l("drawManually")]})]}),e.jsx("p",{className:`mt-4 min-h-5 max-w-[320px] text-sm font-semibold ${o?"text-[#B74343]":"text-[#8F7E6F]"}`,role:o?"alert":void 0,"aria-live":"polite",children:o||l("uploadRequirements",{size:Wa})}),e.jsxs("div",{className:"mt-8 flex items-center gap-4 opacity-30 text-[#3E2A1E] min-[375px]:gap-6",children:[e.jsx("div",{className:"text-[10px] font-black uppercase tracking-widest",children:"JPG / JPEG"}),e.jsx("div",{className:"w-1 h-1 bg-[#3E2A1E] rounded-full"}),e.jsx("div",{className:"text-[10px] font-black uppercase tracking-widest",children:"PNG"}),e.jsx("div",{className:"w-1 h-1 bg-[#3E2A1E] rounded-full"}),e.jsx("div",{className:"text-[10px] font-black uppercase tracking-widest",children:"WEBP"})]})]})}var Zo=t=>{switch(t){case"success":return Qo;case"info":return ei;case"warning":return Jo;case"error":return ti;default:return null}},qo=Array(12).fill(0),Ko=({visible:t,className:a})=>E.createElement("div",{className:["sonner-loading-wrapper",a].filter(Boolean).join(" "),"data-visible":t},E.createElement("div",{className:"sonner-spinner"},qo.map((n,o)=>E.createElement("div",{className:"sonner-loading-bar",key:`spinner-bar-${o}`})))),Qo=E.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor",height:"20",width:"20"},E.createElement("path",{fillRule:"evenodd",d:"M10 18a8 8 0 100-16 8 8 0 000 16zm3.857-9.809a.75.75 0 00-1.214-.882l-3.483 4.79-1.88-1.88a.75.75 0 10-1.06 1.061l2.5 2.5a.75.75 0 001.137-.089l4-5.5z",clipRule:"evenodd"})),Jo=E.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",height:"20",width:"20"},E.createElement("path",{fillRule:"evenodd",d:"M9.401 3.003c1.155-2 4.043-2 5.197 0l7.355 12.748c1.154 2-.29 4.5-2.599 4.5H4.645c-2.309 0-3.752-2.5-2.598-4.5L9.4 3.003zM12 8.25a.75.75 0 01.75.75v3.75a.75.75 0 01-1.5 0V9a.75.75 0 01.75-.75zm0 8.25a.75.75 0 100-1.5.75.75 0 000 1.5z",clipRule:"evenodd"})),ei=E.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor",height:"20",width:"20"},E.createElement("path",{fillRule:"evenodd",d:"M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a.75.75 0 000 1.5h.253a.25.25 0 01.244.304l-.459 2.066A1.75 1.75 0 0010.747 15H11a.75.75 0 000-1.5h-.253a.25.25 0 01-.244-.304l.459-2.066A1.75 1.75 0 009.253 9H9z",clipRule:"evenodd"})),ti=E.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor",height:"20",width:"20"},E.createElement("path",{fillRule:"evenodd",d:"M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-8-5a.75.75 0 01.75.75v4.5a.75.75 0 01-1.5 0v-4.5A.75.75 0 0110 5zm0 10a1 1 0 100-2 1 1 0 000 2z",clipRule:"evenodd"})),ai=E.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"},E.createElement("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),E.createElement("line",{x1:"6",y1:"6",x2:"18",y2:"18"})),ni=()=>{let[t,a]=E.useState(document.hidden);return E.useEffect(()=>{let n=()=>{a(document.hidden)};return document.addEventListener("visibilitychange",n),()=>window.removeEventListener("visibilitychange",n)},[]),t},Ua=1,si=class{constructor(){this.subscribe=t=>(this.subscribers.push(t),()=>{let a=this.subscribers.indexOf(t);this.subscribers.splice(a,1)}),this.publish=t=>{this.subscribers.forEach(a=>a(t))},this.addToast=t=>{this.publish(t),this.toasts=[...this.toasts,t]},this.create=t=>{var a;let{message:n,...o}=t,l=typeof t?.id=="number"||((a=t.id)==null?void 0:a.length)>0?t.id:Ua++,i=this.toasts.find(h=>h.id===l),c=t.dismissible===void 0?!0:t.dismissible;return this.dismissedToasts.has(l)&&this.dismissedToasts.delete(l),i?this.toasts=this.toasts.map(h=>h.id===l?(this.publish({...h,...t,id:l,title:n}),{...h,...t,id:l,dismissible:c,title:n}):h):this.addToast({title:n,...o,dismissible:c,id:l}),l},this.dismiss=t=>(this.dismissedToasts.add(t),t||this.toasts.forEach(a=>{this.subscribers.forEach(n=>n({id:a.id,dismiss:!0}))}),this.subscribers.forEach(a=>a({id:t,dismiss:!0})),t),this.message=(t,a)=>this.create({...a,message:t}),this.error=(t,a)=>this.create({...a,message:t,type:"error"}),this.success=(t,a)=>this.create({...a,type:"success",message:t}),this.info=(t,a)=>this.create({...a,type:"info",message:t}),this.warning=(t,a)=>this.create({...a,type:"warning",message:t}),this.loading=(t,a)=>this.create({...a,type:"loading",message:t}),this.promise=(t,a)=>{if(!a)return;let n;a.loading!==void 0&&(n=this.create({...a,promise:t,type:"loading",message:a.loading,description:typeof a.description!="function"?a.description:void 0}));let o=t instanceof Promise?t:t(),l=n!==void 0,i,c=o.then(async u=>{if(i=["resolve",u],E.isValidElement(u))l=!1,this.create({id:n,type:"default",message:u});else if(oi(u)&&!u.ok){l=!1;let m=typeof a.error=="function"?await a.error(`HTTP error! status: ${u.status}`):a.error,y=typeof a.description=="function"?await a.description(`HTTP error! status: ${u.status}`):a.description;this.create({id:n,type:"error",message:m,description:y})}else if(a.success!==void 0){l=!1;let m=typeof a.success=="function"?await a.success(u):a.success,y=typeof a.description=="function"?await a.description(u):a.description;this.create({id:n,type:"success",message:m,description:y})}}).catch(async u=>{if(i=["reject",u],a.error!==void 0){l=!1;let m=typeof a.error=="function"?await a.error(u):a.error,y=typeof a.description=="function"?await a.description(u):a.description;this.create({id:n,type:"error",message:m,description:y})}}).finally(()=>{var u;l&&(this.dismiss(n),n=void 0),(u=a.finally)==null||u.call(a)}),h=()=>new Promise((u,m)=>c.then(()=>i[0]==="reject"?m(i[1]):u(i[1])).catch(m));return typeof n!="string"&&typeof n!="number"?{unwrap:h}:Object.assign(n,{unwrap:h})},this.custom=(t,a)=>{let n=a?.id||Ua++;return this.create({jsx:t(n),id:n,...a}),n},this.getActiveToasts=()=>this.toasts.filter(t=>!this.dismissedToasts.has(t.id)),this.subscribers=[],this.toasts=[],this.dismissedToasts=new Set}},Fe=new si,ri=(t,a)=>{let n=a?.id||Ua++;return Fe.addToast({title:t,...a,id:n}),n},oi=t=>t&&typeof t=="object"&&"ok"in t&&typeof t.ok=="boolean"&&"status"in t&&typeof t.status=="number",ii=ri,li=()=>Fe.toasts,ci=()=>Fe.getActiveToasts(),bt=Object.assign(ii,{success:Fe.success,info:Fe.info,warning:Fe.warning,error:Fe.error,custom:Fe.custom,message:Fe.message,promise:Fe.promise,dismiss:Fe.dismiss,loading:Fe.loading},{getHistory:li,getToasts:ci});function di(t,{insertAt:a}={}){if(typeof document>"u")return;let n=document.head||document.getElementsByTagName("head")[0],o=document.createElement("style");o.type="text/css",a==="top"&&n.firstChild?n.insertBefore(o,n.firstChild):n.appendChild(o),o.styleSheet?o.styleSheet.cssText=t:o.appendChild(document.createTextNode(t))}di(`:where(html[dir="ltr"]),:where([data-sonner-toaster][dir="ltr"]){--toast-icon-margin-start: -3px;--toast-icon-margin-end: 4px;--toast-svg-margin-start: -1px;--toast-svg-margin-end: 0px;--toast-button-margin-start: auto;--toast-button-margin-end: 0;--toast-close-button-start: 0;--toast-close-button-end: unset;--toast-close-button-transform: translate(-35%, -35%)}:where(html[dir="rtl"]),:where([data-sonner-toaster][dir="rtl"]){--toast-icon-margin-start: 4px;--toast-icon-margin-end: -3px;--toast-svg-margin-start: 0px;--toast-svg-margin-end: -1px;--toast-button-margin-start: 0;--toast-button-margin-end: auto;--toast-close-button-start: unset;--toast-close-button-end: 0;--toast-close-button-transform: translate(35%, -35%)}:where([data-sonner-toaster]){position:fixed;width:var(--width);font-family:ui-sans-serif,system-ui,-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,Arial,Noto Sans,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol,Noto Color Emoji;--gray1: hsl(0, 0%, 99%);--gray2: hsl(0, 0%, 97.3%);--gray3: hsl(0, 0%, 95.1%);--gray4: hsl(0, 0%, 93%);--gray5: hsl(0, 0%, 90.9%);--gray6: hsl(0, 0%, 88.7%);--gray7: hsl(0, 0%, 85.8%);--gray8: hsl(0, 0%, 78%);--gray9: hsl(0, 0%, 56.1%);--gray10: hsl(0, 0%, 52.3%);--gray11: hsl(0, 0%, 43.5%);--gray12: hsl(0, 0%, 9%);--border-radius: 8px;box-sizing:border-box;padding:0;margin:0;list-style:none;outline:none;z-index:999999999;transition:transform .4s ease}:where([data-sonner-toaster][data-lifted="true"]){transform:translateY(-10px)}@media (hover: none) and (pointer: coarse){:where([data-sonner-toaster][data-lifted="true"]){transform:none}}:where([data-sonner-toaster][data-x-position="right"]){right:var(--offset-right)}:where([data-sonner-toaster][data-x-position="left"]){left:var(--offset-left)}:where([data-sonner-toaster][data-x-position="center"]){left:50%;transform:translate(-50%)}:where([data-sonner-toaster][data-y-position="top"]){top:var(--offset-top)}:where([data-sonner-toaster][data-y-position="bottom"]){bottom:var(--offset-bottom)}:where([data-sonner-toast]){--y: translateY(100%);--lift-amount: calc(var(--lift) * var(--gap));z-index:var(--z-index);position:absolute;opacity:0;transform:var(--y);filter:blur(0);touch-action:none;transition:transform .4s,opacity .4s,height .4s,box-shadow .2s;box-sizing:border-box;outline:none;overflow-wrap:anywhere}:where([data-sonner-toast][data-styled="true"]){padding:16px;background:var(--normal-bg);border:1px solid var(--normal-border);color:var(--normal-text);border-radius:var(--border-radius);box-shadow:0 4px 12px #0000001a;width:var(--width);font-size:13px;display:flex;align-items:center;gap:6px}:where([data-sonner-toast]:focus-visible){box-shadow:0 4px 12px #0000001a,0 0 0 2px #0003}:where([data-sonner-toast][data-y-position="top"]){top:0;--y: translateY(-100%);--lift: 1;--lift-amount: calc(1 * var(--gap))}:where([data-sonner-toast][data-y-position="bottom"]){bottom:0;--y: translateY(100%);--lift: -1;--lift-amount: calc(var(--lift) * var(--gap))}:where([data-sonner-toast]) :where([data-description]){font-weight:400;line-height:1.4;color:inherit}:where([data-sonner-toast]) :where([data-title]){font-weight:500;line-height:1.5;color:inherit}:where([data-sonner-toast]) :where([data-icon]){display:flex;height:16px;width:16px;position:relative;justify-content:flex-start;align-items:center;flex-shrink:0;margin-left:var(--toast-icon-margin-start);margin-right:var(--toast-icon-margin-end)}:where([data-sonner-toast][data-promise="true"]) :where([data-icon])>svg{opacity:0;transform:scale(.8);transform-origin:center;animation:sonner-fade-in .3s ease forwards}:where([data-sonner-toast]) :where([data-icon])>*{flex-shrink:0}:where([data-sonner-toast]) :where([data-icon]) svg{margin-left:var(--toast-svg-margin-start);margin-right:var(--toast-svg-margin-end)}:where([data-sonner-toast]) :where([data-content]){display:flex;flex-direction:column;gap:2px}[data-sonner-toast][data-styled=true] [data-button]{border-radius:4px;padding-left:8px;padding-right:8px;height:24px;font-size:12px;color:var(--normal-bg);background:var(--normal-text);margin-left:var(--toast-button-margin-start);margin-right:var(--toast-button-margin-end);border:none;cursor:pointer;outline:none;display:flex;align-items:center;flex-shrink:0;transition:opacity .4s,box-shadow .2s}:where([data-sonner-toast]) :where([data-button]):focus-visible{box-shadow:0 0 0 2px #0006}:where([data-sonner-toast]) :where([data-button]):first-of-type{margin-left:var(--toast-button-margin-start);margin-right:var(--toast-button-margin-end)}:where([data-sonner-toast]) :where([data-cancel]){color:var(--normal-text);background:rgba(0,0,0,.08)}:where([data-sonner-toast][data-theme="dark"]) :where([data-cancel]){background:rgba(255,255,255,.3)}:where([data-sonner-toast]) :where([data-close-button]){position:absolute;left:var(--toast-close-button-start);right:var(--toast-close-button-end);top:0;height:20px;width:20px;display:flex;justify-content:center;align-items:center;padding:0;color:var(--gray12);border:1px solid var(--gray4);transform:var(--toast-close-button-transform);border-radius:50%;cursor:pointer;z-index:1;transition:opacity .1s,background .2s,border-color .2s}[data-sonner-toast] [data-close-button]{background:var(--gray1)}:where([data-sonner-toast]) :where([data-close-button]):focus-visible{box-shadow:0 4px 12px #0000001a,0 0 0 2px #0003}:where([data-sonner-toast]) :where([data-disabled="true"]){cursor:not-allowed}:where([data-sonner-toast]):hover :where([data-close-button]):hover{background:var(--gray2);border-color:var(--gray5)}:where([data-sonner-toast][data-swiping="true"]):before{content:"";position:absolute;left:-50%;right:-50%;height:100%;z-index:-1}:where([data-sonner-toast][data-y-position="top"][data-swiping="true"]):before{bottom:50%;transform:scaleY(3) translateY(50%)}:where([data-sonner-toast][data-y-position="bottom"][data-swiping="true"]):before{top:50%;transform:scaleY(3) translateY(-50%)}:where([data-sonner-toast][data-swiping="false"][data-removed="true"]):before{content:"";position:absolute;inset:0;transform:scaleY(2)}:where([data-sonner-toast]):after{content:"";position:absolute;left:0;height:calc(var(--gap) + 1px);bottom:100%;width:100%}:where([data-sonner-toast][data-mounted="true"]){--y: translateY(0);opacity:1}:where([data-sonner-toast][data-expanded="false"][data-front="false"]){--scale: var(--toasts-before) * .05 + 1;--y: translateY(calc(var(--lift-amount) * var(--toasts-before))) scale(calc(-1 * var(--scale)));height:var(--front-toast-height)}:where([data-sonner-toast])>*{transition:opacity .4s}:where([data-sonner-toast][data-expanded="false"][data-front="false"][data-styled="true"])>*{opacity:0}:where([data-sonner-toast][data-visible="false"]){opacity:0;pointer-events:none}:where([data-sonner-toast][data-mounted="true"][data-expanded="true"]){--y: translateY(calc(var(--lift) * var(--offset)));height:var(--initial-height)}:where([data-sonner-toast][data-removed="true"][data-front="true"][data-swipe-out="false"]){--y: translateY(calc(var(--lift) * -100%));opacity:0}:where([data-sonner-toast][data-removed="true"][data-front="false"][data-swipe-out="false"][data-expanded="true"]){--y: translateY(calc(var(--lift) * var(--offset) + var(--lift) * -100%));opacity:0}:where([data-sonner-toast][data-removed="true"][data-front="false"][data-swipe-out="false"][data-expanded="false"]){--y: translateY(40%);opacity:0;transition:transform .5s,opacity .2s}:where([data-sonner-toast][data-removed="true"][data-front="false"]):before{height:calc(var(--initial-height) + 20%)}[data-sonner-toast][data-swiping=true]{transform:var(--y) translateY(var(--swipe-amount-y, 0px)) translate(var(--swipe-amount-x, 0px));transition:none}[data-sonner-toast][data-swiped=true]{user-select:none}[data-sonner-toast][data-swipe-out=true][data-y-position=bottom],[data-sonner-toast][data-swipe-out=true][data-y-position=top]{animation-duration:.2s;animation-timing-function:ease-out;animation-fill-mode:forwards}[data-sonner-toast][data-swipe-out=true][data-swipe-direction=left]{animation-name:swipe-out-left}[data-sonner-toast][data-swipe-out=true][data-swipe-direction=right]{animation-name:swipe-out-right}[data-sonner-toast][data-swipe-out=true][data-swipe-direction=up]{animation-name:swipe-out-up}[data-sonner-toast][data-swipe-out=true][data-swipe-direction=down]{animation-name:swipe-out-down}@keyframes swipe-out-left{0%{transform:var(--y) translate(var(--swipe-amount-x));opacity:1}to{transform:var(--y) translate(calc(var(--swipe-amount-x) - 100%));opacity:0}}@keyframes swipe-out-right{0%{transform:var(--y) translate(var(--swipe-amount-x));opacity:1}to{transform:var(--y) translate(calc(var(--swipe-amount-x) + 100%));opacity:0}}@keyframes swipe-out-up{0%{transform:var(--y) translateY(var(--swipe-amount-y));opacity:1}to{transform:var(--y) translateY(calc(var(--swipe-amount-y) - 100%));opacity:0}}@keyframes swipe-out-down{0%{transform:var(--y) translateY(var(--swipe-amount-y));opacity:1}to{transform:var(--y) translateY(calc(var(--swipe-amount-y) + 100%));opacity:0}}@media (max-width: 600px){[data-sonner-toaster]{position:fixed;right:var(--mobile-offset-right);left:var(--mobile-offset-left);width:100%}[data-sonner-toaster][dir=rtl]{left:calc(var(--mobile-offset-left) * -1)}[data-sonner-toaster] [data-sonner-toast]{left:0;right:0;width:calc(100% - var(--mobile-offset-left) * 2)}[data-sonner-toaster][data-x-position=left]{left:var(--mobile-offset-left)}[data-sonner-toaster][data-y-position=bottom]{bottom:var(--mobile-offset-bottom)}[data-sonner-toaster][data-y-position=top]{top:var(--mobile-offset-top)}[data-sonner-toaster][data-x-position=center]{left:var(--mobile-offset-left);right:var(--mobile-offset-right);transform:none}}[data-sonner-toaster][data-theme=light]{--normal-bg: #fff;--normal-border: var(--gray4);--normal-text: var(--gray12);--success-bg: hsl(143, 85%, 96%);--success-border: hsl(145, 92%, 91%);--success-text: hsl(140, 100%, 27%);--info-bg: hsl(208, 100%, 97%);--info-border: hsl(221, 91%, 91%);--info-text: hsl(210, 92%, 45%);--warning-bg: hsl(49, 100%, 97%);--warning-border: hsl(49, 91%, 91%);--warning-text: hsl(31, 92%, 45%);--error-bg: hsl(359, 100%, 97%);--error-border: hsl(359, 100%, 94%);--error-text: hsl(360, 100%, 45%)}[data-sonner-toaster][data-theme=light] [data-sonner-toast][data-invert=true]{--normal-bg: #000;--normal-border: hsl(0, 0%, 20%);--normal-text: var(--gray1)}[data-sonner-toaster][data-theme=dark] [data-sonner-toast][data-invert=true]{--normal-bg: #fff;--normal-border: var(--gray3);--normal-text: var(--gray12)}[data-sonner-toaster][data-theme=dark]{--normal-bg: #000;--normal-bg-hover: hsl(0, 0%, 12%);--normal-border: hsl(0, 0%, 20%);--normal-border-hover: hsl(0, 0%, 25%);--normal-text: var(--gray1);--success-bg: hsl(150, 100%, 6%);--success-border: hsl(147, 100%, 12%);--success-text: hsl(150, 86%, 65%);--info-bg: hsl(215, 100%, 6%);--info-border: hsl(223, 100%, 12%);--info-text: hsl(216, 87%, 65%);--warning-bg: hsl(64, 100%, 6%);--warning-border: hsl(60, 100%, 12%);--warning-text: hsl(46, 87%, 65%);--error-bg: hsl(358, 76%, 10%);--error-border: hsl(357, 89%, 16%);--error-text: hsl(358, 100%, 81%)}[data-sonner-toaster][data-theme=dark] [data-sonner-toast] [data-close-button]{background:var(--normal-bg);border-color:var(--normal-border);color:var(--normal-text)}[data-sonner-toaster][data-theme=dark] [data-sonner-toast] [data-close-button]:hover{background:var(--normal-bg-hover);border-color:var(--normal-border-hover)}[data-rich-colors=true][data-sonner-toast][data-type=success],[data-rich-colors=true][data-sonner-toast][data-type=success] [data-close-button]{background:var(--success-bg);border-color:var(--success-border);color:var(--success-text)}[data-rich-colors=true][data-sonner-toast][data-type=info],[data-rich-colors=true][data-sonner-toast][data-type=info] [data-close-button]{background:var(--info-bg);border-color:var(--info-border);color:var(--info-text)}[data-rich-colors=true][data-sonner-toast][data-type=warning],[data-rich-colors=true][data-sonner-toast][data-type=warning] [data-close-button]{background:var(--warning-bg);border-color:var(--warning-border);color:var(--warning-text)}[data-rich-colors=true][data-sonner-toast][data-type=error],[data-rich-colors=true][data-sonner-toast][data-type=error] [data-close-button]{background:var(--error-bg);border-color:var(--error-border);color:var(--error-text)}.sonner-loading-wrapper{--size: 16px;height:var(--size);width:var(--size);position:absolute;inset:0;z-index:10}.sonner-loading-wrapper[data-visible=false]{transform-origin:center;animation:sonner-fade-out .2s ease forwards}.sonner-spinner{position:relative;top:50%;left:50%;height:var(--size);width:var(--size)}.sonner-loading-bar{animation:sonner-spin 1.2s linear infinite;background:var(--gray11);border-radius:6px;height:8%;left:-10%;position:absolute;top:-3.9%;width:24%}.sonner-loading-bar:nth-child(1){animation-delay:-1.2s;transform:rotate(.0001deg) translate(146%)}.sonner-loading-bar:nth-child(2){animation-delay:-1.1s;transform:rotate(30deg) translate(146%)}.sonner-loading-bar:nth-child(3){animation-delay:-1s;transform:rotate(60deg) translate(146%)}.sonner-loading-bar:nth-child(4){animation-delay:-.9s;transform:rotate(90deg) translate(146%)}.sonner-loading-bar:nth-child(5){animation-delay:-.8s;transform:rotate(120deg) translate(146%)}.sonner-loading-bar:nth-child(6){animation-delay:-.7s;transform:rotate(150deg) translate(146%)}.sonner-loading-bar:nth-child(7){animation-delay:-.6s;transform:rotate(180deg) translate(146%)}.sonner-loading-bar:nth-child(8){animation-delay:-.5s;transform:rotate(210deg) translate(146%)}.sonner-loading-bar:nth-child(9){animation-delay:-.4s;transform:rotate(240deg) translate(146%)}.sonner-loading-bar:nth-child(10){animation-delay:-.3s;transform:rotate(270deg) translate(146%)}.sonner-loading-bar:nth-child(11){animation-delay:-.2s;transform:rotate(300deg) translate(146%)}.sonner-loading-bar:nth-child(12){animation-delay:-.1s;transform:rotate(330deg) translate(146%)}@keyframes sonner-fade-in{0%{opacity:0;transform:scale(.8)}to{opacity:1;transform:scale(1)}}@keyframes sonner-fade-out{0%{opacity:1;transform:scale(1)}to{opacity:0;transform:scale(.8)}}@keyframes sonner-spin{0%{opacity:1}to{opacity:.15}}@media (prefers-reduced-motion){[data-sonner-toast],[data-sonner-toast]>*,.sonner-loading-bar{transition:none!important;animation:none!important}}.sonner-loader{position:absolute;top:50%;left:50%;transform:translate(-50%,-50%);transform-origin:center;transition:opacity .2s,transform .2s}.sonner-loader[data-visible=false]{opacity:0;transform:scale(.8) translate(-50%,-50%)} `);function da(t){return t.label!==void 0}var ui=3,mi="32px",pi="16px",Hn=4e3,hi=356,fi=14,xi=20,gi=200;function We(...t){return t.filter(Boolean).join(" ")}function bi(t){let[a,n]=t.split("-"),o=[];return a&&o.push(a),n&&o.push(n),o}var yi=t=>{var a,n,o,l,i,c,h,u,m,y,F;let{invert:A,toast:d,unstyled:k,interacting:v,setHeights:N,visibleToasts:O,heights:f,index:x,toasts:M,expanded:D,removeToast:_,defaultRichColors:$,closeButton:L,style:p,cancelButtonStyle:g,actionButtonStyle:j,className:V="",descriptionClassName:K="",duration:te,position:T,gap:w,loadingIcon:I,expandByDefault:Z,classNames:S,icons:ae,closeButtonAriaLabel:re="Close toast",pauseWhenPageIsHidden:G}=t,[q,Y]=E.useState(null),[J,me]=E.useState(null),[X,be]=E.useState(!1),[Ae,Ie]=E.useState(!1),[ce,De]=E.useState(!1),[rt,Le]=E.useState(!1),[Pe,Re]=E.useState(!1),[Te,Ye]=E.useState(0),[_e,Xe]=E.useState(0),ye=E.useRef(d.duration||te||Hn),P=E.useRef(null),z=E.useRef(null),ve=x===0,Ee=x+1<=O,pe=d.type,ue=d.dismissible!==!1,Rt=d.className||"",U=d.descriptionClassName||"",we=E.useMemo(()=>f.findIndex(B=>B.toastId===d.id)||0,[f,d.id]),Et=E.useMemo(()=>{var B;return(B=d.closeButton)!=null?B:L},[d.closeButton,L]),Tt=E.useMemo(()=>d.duration||te||Hn,[d.duration,te]),_t=E.useRef(0),Ce=E.useRef(0),It=E.useRef(0),ot=E.useRef(null),[Mt,ie]=T.split("-"),wt=E.useMemo(()=>f.reduce((B,W,ee)=>ee>=we?B:B+W.height,0),[f,we]),mt=ni(),it=d.invert||A,Bt=pe==="loading";Ce.current=E.useMemo(()=>we*w+wt,[we,wt]),E.useEffect(()=>{ye.current=Tt},[Tt]),E.useEffect(()=>{be(!0)},[]),E.useEffect(()=>{let B=z.current;if(B){let W=B.getBoundingClientRect().height;return Xe(W),N(ee=>[{toastId:d.id,height:W,position:d.position},...ee]),()=>N(ee=>ee.filter(oe=>oe.toastId!==d.id))}},[N,d.id]),E.useLayoutEffect(()=>{if(!X)return;let B=z.current,W=B.style.height;B.style.height="auto";let ee=B.getBoundingClientRect().height;B.style.height=W,Xe(ee),N(oe=>oe.find(Ne=>Ne.toastId===d.id)?oe.map(Ne=>Ne.toastId===d.id?{...Ne,height:ee}:Ne):[{toastId:d.id,height:ee,position:d.position},...oe])},[X,d.title,d.description,N,d.id]);let Oe=E.useCallback(()=>{Ie(!0),Ye(Ce.current),N(B=>B.filter(W=>W.toastId!==d.id)),setTimeout(()=>{_(d)},gi)},[d,_,N,Ce]);E.useEffect(()=>{if(d.promise&&pe==="loading"||d.duration===1/0||d.type==="loading")return;let B;return D||v||G&&mt?(()=>{if(It.current<_t.current){let W=new Date().getTime()-_t.current;ye.current=ye.current-W}It.current=new Date().getTime()})():ye.current!==1/0&&(_t.current=new Date().getTime(),B=setTimeout(()=>{var W;(W=d.onAutoClose)==null||W.call(d,d),Oe()},ye.current)),()=>clearTimeout(B)},[D,v,d,pe,G,mt,Oe]),E.useEffect(()=>{d.delete&&Oe()},[Oe,d.delete]);function Ct(){var B,W,ee;return ae!=null&&ae.loading?E.createElement("div",{className:We(S?.loader,(B=d?.classNames)==null?void 0:B.loader,"sonner-loader"),"data-visible":pe==="loading"},ae.loading):I?E.createElement("div",{className:We(S?.loader,(W=d?.classNames)==null?void 0:W.loader,"sonner-loader"),"data-visible":pe==="loading"},I):E.createElement(Ko,{className:We(S?.loader,(ee=d?.classNames)==null?void 0:ee.loader),visible:pe==="loading"})}return E.createElement("li",{tabIndex:0,ref:z,className:We(V,Rt,S?.toast,(a=d?.classNames)==null?void 0:a.toast,S?.default,S?.[pe],(n=d?.classNames)==null?void 0:n[pe]),"data-sonner-toast":"","data-rich-colors":(o=d.richColors)!=null?o:$,"data-styled":!(d.jsx||d.unstyled||k),"data-mounted":X,"data-promise":!!d.promise,"data-swiped":Pe,"data-removed":Ae,"data-visible":Ee,"data-y-position":Mt,"data-x-position":ie,"data-index":x,"data-front":ve,"data-swiping":ce,"data-dismissible":ue,"data-type":pe,"data-invert":it,"data-swipe-out":rt,"data-swipe-direction":J,"data-expanded":!!(D||Z&&X),style:{"--index":x,"--toasts-before":x,"--z-index":M.length-x,"--offset":`${Ae?Te:Ce.current}px`,"--initial-height":Z?"auto":`${_e}px`,...p,...d.style},onDragEnd:()=>{De(!1),Y(null),ot.current=null},onPointerDown:B=>{Bt||!ue||(P.current=new Date,Ye(Ce.current),B.target.setPointerCapture(B.pointerId),B.target.tagName!=="BUTTON"&&(De(!0),ot.current={x:B.clientX,y:B.clientY}))},onPointerUp:()=>{var B,W,ee,oe;if(rt||!ue)return;ot.current=null;let Ne=Number(((B=z.current)==null?void 0:B.style.getPropertyValue("--swipe-amount-x").replace("px",""))||0),Ge=Number(((W=z.current)==null?void 0:W.style.getPropertyValue("--swipe-amount-y").replace("px",""))||0),ze=new Date().getTime()-((ee=P.current)==null?void 0:ee.getTime()),he=q==="x"?Ne:Ge,Me=Math.abs(he)/ze;if(Math.abs(he)>=xi||Me>.11){Ye(Ce.current),(oe=d.onDismiss)==null||oe.call(d,d),me(q==="x"?Ne>0?"right":"left":Ge>0?"down":"up"),Oe(),Le(!0),Re(!1);return}De(!1),Y(null)},onPointerMove:B=>{var W,ee,oe,Ne;if(!ot.current||!ue||((W=window.getSelection())==null?void 0:W.toString().length)>0)return;let Ge=B.clientY-ot.current.y,ze=B.clientX-ot.current.x,he=(ee=t.swipeDirections)!=null?ee:bi(T);!q&&(Math.abs(ze)>1||Math.abs(Ge)>1)&&Y(Math.abs(ze)>Math.abs(Ge)?"x":"y");let Me={x:0,y:0};q==="y"?(he.includes("top")||he.includes("bottom"))&&(he.includes("top")&&Ge<0||he.includes("bottom")&&Ge>0)&&(Me.y=Ge):q==="x"&&(he.includes("left")||he.includes("right"))&&(he.includes("left")&&ze<0||he.includes("right")&&ze>0)&&(Me.x=ze),(Math.abs(Me.x)>0||Math.abs(Me.y)>0)&&Re(!0),(oe=z.current)==null||oe.style.setProperty("--swipe-amount-x",`${Me.x}px`),(Ne=z.current)==null||Ne.style.setProperty("--swipe-amount-y",`${Me.y}px`)}},Et&&!d.jsx?E.createElement("button",{"aria-label":re,"data-disabled":Bt,"data-close-button":!0,onClick:Bt||!ue?()=>{}:()=>{var B;Oe(),(B=d.onDismiss)==null||B.call(d,d)},className:We(S?.closeButton,(l=d?.classNames)==null?void 0:l.closeButton)},(i=ae?.close)!=null?i:ai):null,d.jsx||r.isValidElement(d.title)?d.jsx?d.jsx:typeof d.title=="function"?d.title():d.title:E.createElement(E.Fragment,null,pe||d.icon||d.promise?E.createElement("div",{"data-icon":"",className:We(S?.icon,(c=d?.classNames)==null?void 0:c.icon)},d.promise||d.type==="loading"&&!d.icon?d.icon||Ct():null,d.type!=="loading"?d.icon||ae?.[pe]||Zo(pe):null):null,E.createElement("div",{"data-content":"",className:We(S?.content,(h=d?.classNames)==null?void 0:h.content)},E.createElement("div",{"data-title":"",className:We(S?.title,(u=d?.classNames)==null?void 0:u.title)},typeof d.title=="function"?d.title():d.title),d.description?E.createElement("div",{"data-description":"",className:We(K,U,S?.description,(m=d?.classNames)==null?void 0:m.description)},typeof d.description=="function"?d.description():d.description):null),r.isValidElement(d.cancel)?d.cancel:d.cancel&&da(d.cancel)?E.createElement("button",{"data-button":!0,"data-cancel":!0,style:d.cancelButtonStyle||g,onClick:B=>{var W,ee;da(d.cancel)&&ue&&((ee=(W=d.cancel).onClick)==null||ee.call(W,B),Oe())},className:We(S?.cancelButton,(y=d?.classNames)==null?void 0:y.cancelButton)},d.cancel.label):null,r.isValidElement(d.action)?d.action:d.action&&da(d.action)?E.createElement("button",{"data-button":!0,"data-action":!0,style:d.actionButtonStyle||j,onClick:B=>{var W,ee;da(d.action)&&((ee=(W=d.action).onClick)==null||ee.call(W,B),!B.defaultPrevented&&Oe())},className:We(S?.actionButton,(F=d?.classNames)==null?void 0:F.actionButton)},d.action.label):null))};function $n(){if(typeof window>"u"||typeof document>"u")return"ltr";let t=document.documentElement.getAttribute("dir");return t==="auto"||!t?window.getComputedStyle(document.documentElement).direction:t}function vi(t,a){let n={};return[t,a].forEach((o,l)=>{let i=l===1,c=i?"--mobile-offset":"--offset",h=i?pi:mi;function u(m){["top","right","bottom","left"].forEach(y=>{n[`${c}-${y}`]=typeof m=="number"?`${m}px`:m})}typeof o=="number"||typeof o=="string"?u(o):typeof o=="object"?["top","right","bottom","left"].forEach(m=>{o[m]===void 0?n[`${c}-${m}`]=h:n[`${c}-${m}`]=typeof o[m]=="number"?`${o[m]}px`:o[m]}):u(h)}),n}r.forwardRef(function(t,a){let{invert:n,position:o="bottom-right",hotkey:l=["altKey","KeyT"],expand:i,closeButton:c,className:h,offset:u,mobileOffset:m,theme:y="light",richColors:F,duration:A,style:d,visibleToasts:k=ui,toastOptions:v,dir:N=$n(),gap:O=fi,loadingIcon:f,icons:x,containerAriaLabel:M="Notifications",pauseWhenPageIsHidden:D}=t,[_,$]=E.useState([]),L=E.useMemo(()=>Array.from(new Set([o].concat(_.filter(G=>G.position).map(G=>G.position)))),[_,o]),[p,g]=E.useState([]),[j,V]=E.useState(!1),[K,te]=E.useState(!1),[T,w]=E.useState(y!=="system"?y:typeof window<"u"&&window.matchMedia&&window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"),I=E.useRef(null),Z=l.join("+").replace(/Key/g,"").replace(/Digit/g,""),S=E.useRef(null),ae=E.useRef(!1),re=E.useCallback(G=>{$(q=>{var Y;return(Y=q.find(J=>J.id===G.id))!=null&&Y.delete||Fe.dismiss(G.id),q.filter(({id:J})=>J!==G.id)})},[]);return E.useEffect(()=>Fe.subscribe(G=>{if(G.dismiss){$(q=>q.map(Y=>Y.id===G.id?{...Y,delete:!0}:Y));return}setTimeout(()=>{Sr.flushSync(()=>{$(q=>{let Y=q.findIndex(J=>J.id===G.id);return Y!==-1?[...q.slice(0,Y),{...q[Y],...G},...q.slice(Y+1)]:[G,...q]})})})}),[]),E.useEffect(()=>{if(y!=="system"){w(y);return}if(y==="system"&&(window.matchMedia&&window.matchMedia("(prefers-color-scheme: dark)").matches?w("dark"):w("light")),typeof window>"u")return;let G=window.matchMedia("(prefers-color-scheme: dark)");try{G.addEventListener("change",({matches:q})=>{w(q?"dark":"light")})}catch{G.addListener(({matches:Y})=>{try{w(Y?"dark":"light")}catch(J){console.error(J)}})}},[y]),E.useEffect(()=>{_.length<=1&&V(!1)},[_]),E.useEffect(()=>{let G=q=>{var Y,J;l.every(me=>q[me]||q.code===me)&&(V(!0),(Y=I.current)==null||Y.focus()),q.code==="Escape"&&(document.activeElement===I.current||(J=I.current)!=null&&J.contains(document.activeElement))&&V(!1)};return document.addEventListener("keydown",G),()=>document.removeEventListener("keydown",G)},[l]),E.useEffect(()=>{if(I.current)return()=>{S.current&&(S.current.focus({preventScroll:!0}),S.current=null,ae.current=!1)}},[I.current]),E.createElement("section",{ref:a,"aria-label":`${M} ${Z}`,tabIndex:-1,"aria-live":"polite","aria-relevant":"additions text","aria-atomic":"false",suppressHydrationWarning:!0},L.map((G,q)=>{var Y;let[J,me]=G.split("-");return _.length?E.createElement("ol",{key:G,dir:N==="auto"?$n():N,tabIndex:-1,ref:I,className:h,"data-sonner-toaster":!0,"data-theme":T,"data-y-position":J,"data-lifted":j&&_.length>1&&!i,"data-x-position":me,style:{"--front-toast-height":`${((Y=p[0])==null?void 0:Y.height)||0}px`,"--width":`${hi}px`,"--gap":`${O}px`,...d,...vi(u,m)},onBlur:X=>{ae.current&&!X.currentTarget.contains(X.relatedTarget)&&(ae.current=!1,S.current&&(S.current.focus({preventScroll:!0}),S.current=null))},onFocus:X=>{X.target instanceof HTMLElement&&X.target.dataset.dismissible==="false"||ae.current||(ae.current=!0,S.current=X.relatedTarget)},onMouseEnter:()=>V(!0),onMouseMove:()=>V(!0),onMouseLeave:()=>{K||V(!1)},onDragEnd:()=>V(!1),onPointerDown:X=>{X.target instanceof HTMLElement&&X.target.dataset.dismissible==="false"||te(!0)},onPointerUp:()=>te(!1)},_.filter(X=>!X.position&&q===0||X.position===G).map((X,be)=>{var Ae,Ie;return E.createElement(yi,{key:X.id,icons:x,index:be,toast:X,defaultRichColors:F,duration:(Ae=v?.duration)!=null?Ae:A,className:v?.className,descriptionClassName:v?.descriptionClassName,invert:n,visibleToasts:k,closeButton:(Ie=v?.closeButton)!=null?Ie:c,interacting:K,position:G,style:v?.style,unstyled:v?.unstyled,classNames:v?.classNames,cancelButtonStyle:v?.cancelButtonStyle,actionButtonStyle:v?.actionButtonStyle,removeToast:re,toasts:_.filter(ce=>ce.position==X.position),heights:p.filter(ce=>ce.position==X.position),setHeights:g,expandByDefault:i,gap:O,loadingIcon:f,expanded:j,pauseWhenPageIsHidden:D,swipeDirections:t.swipeDirections})})):null}))});var Ei="Label",js=r.forwardRef((t,a)=>e.jsx(Ar.label,{...t,ref:a,onMouseDown:n=>{n.target.closest("button, input, select, textarea")||(t.onMouseDown?.(n),!n.defaultPrevented&&n.detail>1&&n.preventDefault())}}));js.displayName=Ei;var Ss=js;const wi=uo("text-sm font-medium leading-none text-[#18181B] peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),$t=r.forwardRef(({className:t,...a},n)=>e.jsx(Ss,{ref:n,className:ne(wi(),t),...a}));$t.displayName=Ss.displayName;const ks=r.forwardRef(({className:t,...a},n)=>e.jsx("textarea",{className:ne("flex min-h-[80px] w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",t),ref:n,...a}));ks.displayName="Textarea";const Ci=Array.from({length:12},(t,a)=>a);function Vn(t){return t==="pdf"?"PDF":t==="image"?"PNG":t==="svg"?"SVG":"JSON"}function Da(t=!1){return ne("h-12 rounded-[12px] border border-[#DED3C1] bg-[#F4F0E7] px-4 text-sm text-[#1E1C12] shadow-none placeholder:text-[#8A8377] focus-visible:border-[#006B5F]/45 focus-visible:bg-white focus-visible:ring-2 focus-visible:ring-[#006B5F]/15 focus-visible:ring-offset-0 sm:h-14 sm:rounded-[14px] sm:px-5 sm:text-base",t&&"border-[#C84D4D] focus-visible:border-[#C84D4D] focus-visible:ring-[#C84D4D]/20")}function Ni({open:t,onOpenChange:a,onConfirmExport:n,author:o,onAuthorChange:l,watermark:i,onWatermarkChange:c,onSaveAndExport:h,exportFormat:u,loading:m=!1,statusLabel:y,error:F,usesLargePdfPage:A=!1,previewPixels:d,previewWidth:k,previewHeight:v,exportSettings:N,mode:O="export"}){const f=de("Generator.exportDialog"),x=Es("(max-width: 1023px)"),[M,D]=r.useState(""),[_,$]=r.useState(""),[L,p]=r.useState(!1),[g,j]=r.useState(!1),[V,K]=r.useState(null),[te,T]=r.useState(!1),[w,I]=r.useState(!1),Z=r.useRef(null),S=r.useRef(null),ae=m?V:null,re=O==="publish",G=d.length>0&&k>0&&v>0,q=G?Math.min(4/3,Math.max(1,k/v)):1,Y=!i.text||i.text===Ut(o),J=u==="image"?f("descriptionImage"):f("descriptionPdf").replace("PDF",Vn(u)),me=f("directDownloadFormat",{format:Vn(u)}),X=U=>{!U&&m||(U||(K(null),j(!1),T(!1),I(!1)),a(U))},be=()=>{j(!0),requestAnimationFrame(()=>{S.current?.focus(),S.current?.scrollIntoView({block:"center"})})},Ae=()=>!i.enabled||i.text.trim()?(I(!1),!0):(I(!0),be(),!1),Ie=U=>{const we=Ut(o),Et=!i.text||i.text===we;l(U),Et&&(c({...i,text:Ut(U)}),I(!1))},ce=()=>{if(m)return;const U=!i.enabled,we=i.text||Ut(o);c({enabled:U,text:we}),I(!1),U&&!we&&be()},De=U=>{c({...i,text:U}),U.trim()&&I(!1)},rt=()=>{const U=Ut(o);c({...i,text:U}),I(!U),U||be()},Le=()=>{m||!Ae()||(K("download"),n())},Pe=U=>{if(U?.preventDefault(),m)return;const we=M.trim();if(!we){T(!0),requestAnimationFrame(()=>{Z.current?.focus(),Z.current?.scrollIntoView({block:"center"})});return}Ae()&&(K("share"),h({name:we,author:o.trim()||void 0,public:!0,message:_.trim()||void 0,isOriginal:L}))},Re=e.jsxs("div",{className:ne("relative mx-auto w-full",x?"max-w-[210px] md:max-w-[240px]":re?"max-w-[300px]":"max-w-[360px]"),children:[e.jsxs("div",{className:ne("relative overflow-hidden rounded-[16px] border border-[#D8CBB9] bg-white shadow-[0_16px_34px_rgba(62,42,30,0.06)]",(x||!re)&&"aspect-square"),style:!x&&re?{aspectRatio:q}:void 0,children:[e.jsx("div",{className:"flex h-full items-center justify-center p-3 sm:p-4",children:G?e.jsx(mo,{pixels:d,width:k,height:v,maxSize:x?182:re?264:396}):e.jsx("div",{className:"flex h-full w-full items-center justify-center rounded-[12px] bg-[#F4F0E7] text-sm font-semibold text-[#8F7E6F]",children:f("previewUnavailable")})}),i.enabled&&i.text.trim()?e.jsx("div",{"aria-hidden":"true",className:"pointer-events-none absolute inset-0 overflow-hidden",children:e.jsx("div",{className:"absolute -inset-16 grid -rotate-[28deg] grid-cols-3 content-around gap-x-8 gap-y-7 text-center text-[10px] font-black leading-tight text-[#1E1C12]/20 sm:text-xs",children:Ci.map(U=>e.jsx("span",{className:"whitespace-nowrap",children:i.text.trim()},U))})}):null]}),i.enabled&&i.text.trim()?e.jsx("div",{role:"status",className:"absolute bottom-3 left-3 rounded-full bg-white/92 px-3 py-1 text-[10px] font-black text-[#006B5F] shadow-sm backdrop-blur-sm",children:f("watermarkEnabled")}):null]}),Te=F?e.jsx("p",{role:"alert",className:"mt-3 rounded-[14px] bg-[#FFF0F0] px-4 py-3 text-sm font-semibold leading-5 text-[#B74343]",children:F}):m&&y?e.jsx("p",{role:"status","aria-live":"polite",className:"mt-3 text-center text-sm font-semibold text-[#006B5F]",children:y}):null,Ye=u==="pdf"&&A?e.jsxs("div",{role:"note",className:"mt-4 flex items-start gap-3 rounded-[16px] bg-[#FFF0C7] px-4 py-3 text-[#694D16]",children:[e.jsx(fs,{"aria-hidden":"true",className:"mt-0.5 h-5 w-5 shrink-0"}),e.jsx("p",{className:"text-sm font-semibold leading-5",children:f("largePdfNotice")})]}):null,_e=e.jsxs("section",{className:"overflow-hidden rounded-[16px] border border-[#DDCFBA] bg-white/70 shadow-[0_10px_22px_rgba(62,42,30,0.035)]",children:[e.jsxs("button",{type:"button",onClick:()=>j(U=>!U),"aria-expanded":g,"aria-controls":"download-watermark-settings",className:ne("flex w-full touch-manipulation items-center gap-3 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-[#006B5F]",x?"min-h-[62px] px-3 py-2":"min-h-[60px] px-3.5 py-2"),children:[e.jsx("span",{className:ne("flex shrink-0 items-center justify-center rounded-full bg-[#E6F5F2] text-[#006B5F]","h-9 w-9"),children:e.jsx(Dr,{"aria-hidden":"true",className:"h-[18px] w-[18px]"})}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:ne("block font-black text-[#1E1C12]",x?"text-[13px]":"text-sm"),children:f("downloadProtectionTitle")}),e.jsx("span",{className:ne("block text-[#766D5F]",x?"mt-0.5 text-[11px] leading-4":"mt-1 text-xs leading-4"),children:f("downloadProtectionDescription")})]}),e.jsx("span",{className:ne("shrink-0 rounded-full px-2.5 py-1 text-[10px] font-black",i.enabled?"bg-[#DDF3EE] text-[#006B5F]":"bg-[#EEE8D8] text-[#6C5D48]"),children:i.enabled?f("watermarkEnabled"):f("optionalBadge")}),e.jsx(ls,{"aria-hidden":"true",className:ne("h-4 w-4 shrink-0 text-[#8E8679] transition-transform",g&&"rotate-180")})]}),g?e.jsxs("div",{id:"download-watermark-settings",className:ne("border-t border-[#E8DDC8]",x?"space-y-3 px-3 py-3":"space-y-4 px-4 py-4"),children:[e.jsxs("button",{type:"button",role:"switch","aria-checked":i.enabled,onClick:ce,disabled:m,className:ne("flex w-full touch-manipulation items-center justify-between bg-[#F1F8F6] text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#006B5F] focus-visible:ring-offset-2 disabled:opacity-60",x?"min-h-11 gap-3 rounded-[12px] px-3 py-2.5":"min-h-12 gap-4 rounded-[16px] px-4 py-3"),children:[e.jsxs("span",{children:[e.jsx("span",{className:ne("block font-black text-[#1E1C12]",x?"text-[13px]":"text-sm"),children:f("watermarkToggle")}),e.jsx("span",{className:ne("block text-[#5F736E]",x?"mt-0.5 text-[11px] leading-4":"mt-1 text-xs leading-5"),children:f("watermarkContentHelp")})]}),e.jsx("span",{className:ne("relative h-7 w-12 shrink-0 rounded-full transition-colors",i.enabled?"bg-[#006B5F]":"bg-[#CFC8B8]"),children:e.jsx("span",{className:ne("absolute left-0 top-1 h-5 w-5 rounded-full bg-white shadow-sm transition-transform",i.enabled?"translate-x-6":"translate-x-1")})})]}),i.enabled?e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs($t,{htmlFor:"watermark-content",className:"flex items-center gap-2 text-xs font-black tracking-[0.08em] text-[#4E4638]",children:[f("watermarkContent"),e.jsx("span",{className:"rounded-full bg-[#006B5F]/10 px-2 py-0.5 text-[10px] tracking-normal text-[#006B5F]",children:f("requiredBadge")})]}),!Y&&o.trim()?e.jsxs("button",{type:"button",onClick:rt,className:"inline-flex min-h-9 touch-manipulation items-center gap-1.5 rounded-full px-2.5 text-xs font-bold text-[#006B5F] hover:bg-[#E6F5F2] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#006B5F]",children:[e.jsx(cs,{"aria-hidden":"true",className:"h-3.5 w-3.5"}),f("restoreAuthorWatermark")]}):null]}),e.jsx(Vt,{ref:S,id:"watermark-content",name:"watermarkContent",type:"text",autoComplete:"off",maxLength:60,required:!0,"aria-required":"true","aria-invalid":w,"aria-describedby":"watermark-content-help",value:i.text,onChange:U=>De(U.target.value),placeholder:f("watermarkContentPlaceholder"),className:Da(w)}),e.jsx("p",{id:"watermark-content-help","aria-live":"polite",className:ne("text-sm leading-6",w?"text-[#B74343]":"text-[#766D5F]"),children:f(w?"watermarkRequired":"watermarkContentHelp")})]}):null]}):null]}),Xe=e.jsxs("form",{id:"export-share-form",noValidate:!0,onSubmit:Pe,className:x?"space-y-4":"space-y-5",children:[e.jsxs("div",{className:ne("grid gap-4",!x&&"lg:grid-cols-[1.15fr_0.85fr] lg:gap-5"),children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs($t,{htmlFor:"pattern-name",className:"flex items-center gap-2 text-[13px] font-black text-[#3E2A1E] sm:text-sm",children:[f("patternName"),e.jsx("span",{className:"rounded-full bg-[#DDF3EE] px-2.5 py-0.5 text-[10px] font-black text-[#006B5F]",children:f("requiredBadge")})]}),e.jsx(Vt,{ref:Z,id:"pattern-name",name:"patternName",type:"text",autoComplete:"off",required:!0,"aria-required":"true","aria-describedby":"pattern-name-help",placeholder:f("patternNamePlaceholder"),value:M,onChange:U=>{D(U.target.value),te&&U.target.value.trim()&&T(!1)},"aria-invalid":te,className:Da(te)}),e.jsx("p",{id:"pattern-name-help","aria-live":"polite",className:ne("text-xs leading-5 sm:text-sm sm:leading-5",te?"text-[#B74343]":"text-[#766D5F]"),children:f(te?"nameRequired":"patternNameHelp")})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs($t,{htmlFor:"author-name",className:"flex items-center gap-2 text-[13px] font-black text-[#3E2A1E] sm:text-sm",children:[f("authorName"),e.jsx("span",{className:"rounded-full bg-[#F2EDE4] px-2.5 py-0.5 text-[10px] font-black text-[#6C5D48]",children:f("optionalBadge")})]}),e.jsx(Vt,{id:"author-name",name:"authorName",type:"text",autoComplete:"off",maxLength:30,value:o,onChange:U=>Ie(U.target.value),placeholder:f("authorNamePlaceholder"),className:Da()}),e.jsx("p",{className:"text-xs leading-5 text-[#766D5F] sm:text-sm",children:f("authorPublicHelp")})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs($t,{htmlFor:"author-message",className:"flex items-center gap-2 text-[13px] font-black text-[#3E2A1E] sm:text-sm",children:[f("message"),e.jsx("span",{className:"rounded-full bg-[#F2EDE4] px-2.5 py-0.5 text-[10px] font-black text-[#6C5D48]",children:f("optionalBadge")})]}),e.jsx(ks,{id:"author-message",name:"authorMessage",autoComplete:"off",maxLength:100,value:_,onChange:U=>$(U.target.value),placeholder:f("messagePlaceholder"),className:"min-h-[88px] rounded-[12px] border border-[#DED3C1] bg-[#F4F0E7] px-4 py-3 text-sm text-[#1E1C12] shadow-none placeholder:text-[#8A8377] focus-visible:border-[#006B5F]/45 focus-visible:bg-white focus-visible:ring-2 focus-visible:ring-[#006B5F]/15 focus-visible:ring-offset-0 sm:min-h-[96px] sm:rounded-[14px] sm:px-5 sm:py-3 sm:text-base"}),e.jsxs("div",{className:"flex items-start justify-between gap-3 text-xs leading-5 text-[#766D5F] sm:gap-4 sm:text-sm sm:leading-6",children:[e.jsx("p",{children:f("messageHelp")}),e.jsxs("span",{className:"shrink-0 tabular-nums","aria-label":f("messageCharacterCount",{count:_.length}),children:[_.length,"/100"]})]})]}),e.jsxs("div",{className:ne("space-y-1",!x&&"flex items-center gap-3 space-y-0"),children:[e.jsxs("label",{className:"flex min-h-11 touch-manipulation items-center gap-2.5 text-sm font-black text-[#1E1C12] sm:gap-3 sm:text-base",children:[e.jsx(Pr,{checked:L,onCheckedChange:U=>p(U===!0),className:"h-5 w-5 rounded-[5px] border-[#948B7D] data-[state=checked]:border-[#006B5F] data-[state=checked]:bg-[#006B5F] data-[state=checked]:text-white focus-visible:ring-[#006B5F]/25 sm:h-6 sm:w-6 sm:rounded-md"}),f("isOriginal")]}),e.jsx("p",{className:ne("text-xs leading-5 text-[#766D5F] sm:text-sm",x&&"pl-[30px] sm:pl-9 sm:leading-6"),children:f("originalHelp")})]}),x?e.jsxs("div",{role:"note",className:"flex items-center gap-2.5 rounded-[12px] bg-[#EEF8F6] px-4 py-3 text-[#185E57] sm:gap-3 sm:rounded-[14px]",children:[e.jsx(Ga,{"aria-hidden":"true",className:"h-[18px] w-[18px] shrink-0 sm:h-5 sm:w-5"}),e.jsx("p",{className:"text-xs font-semibold leading-5 sm:text-sm sm:leading-6",children:f("moderationNotice")})]}):null]}),ye=e.jsx(ke,{id:"download-hd-btn",type:"button",onClick:Le,disabled:m,className:"h-[52px] w-full rounded-[14px] bg-[#087B70] px-5 text-base font-black text-white shadow-[0_12px_24px_rgba(0,107,95,0.14)] hover:bg-[#006B5F]",children:m&&ae==="download"?e.jsxs(e.Fragment,{children:[e.jsx("span",{"aria-hidden":"true",className:"mr-2 h-5 w-5 animate-spin rounded-full border-2 border-white border-t-transparent motion-reduce:animate-none"}),f("processing")]}):e.jsxs(e.Fragment,{children:[e.jsx($a,{"aria-hidden":"true",className:"mr-2 h-5 w-5"}),me]})}),P=e.jsx(ke,{type:"submit",form:"export-share-form",disabled:m,className:ne("min-w-0 flex-1 rounded-[16px] bg-[linear-gradient(100deg,#087B70_0%,#25B6A7_100%)] px-6 text-base font-black text-white shadow-[0_18px_34px_rgba(0,107,95,0.18)] hover:brightness-95 sm:min-w-[320px]",x?"h-[52px]":"h-14"),children:m&&ae==="share"?e.jsxs(e.Fragment,{children:[e.jsx("span",{"aria-hidden":"true",className:"mr-2 h-5 w-5 animate-spin rounded-full border-2 border-white border-t-transparent motion-reduce:animate-none"}),f("processing")]}):e.jsxs(e.Fragment,{children:[e.jsx(Yt,{"aria-hidden":"true",className:"mr-2 h-5 w-5"}),f("publishAndDownloadPng")]})}),z=e.jsx(Rr,{disabled:m,"aria-label":f("close"),className:"absolute right-4 top-3 z-10 flex h-10 w-10 touch-manipulation items-center justify-center rounded-full text-[#7F7668] transition-colors hover:bg-[#F3EEDF] hover:text-[#1E1C12] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#006B5F] focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 lg:right-5 lg:top-4",children:e.jsx(vt,{"aria-hidden":"true",className:"h-6 w-6"})}),ve=e.jsx(Xt,{open:t,onOpenChange:X,children:e.jsxs(Nn,{children:[e.jsx(jn,{className:"bg-[#1E1C12]/28 backdrop-blur-[6px]"}),e.jsx(Sn,{className:"pointer-events-none fixed inset-0 z-50 flex items-center justify-center overflow-hidden overscroll-contain p-4 lg:p-8",children:e.jsxs("div",{className:"pointer-events-auto relative flex h-[min(780px,calc(100dvh-3rem))] w-full max-w-[68rem] flex-col overflow-hidden rounded-[30px] bg-white shadow-[0_32px_84px_rgba(30,28,18,0.22)]",children:[z,e.jsxs("header",{className:"shrink-0 border-b border-[#E9E0D3] bg-white px-8 py-4 pr-20 lg:px-10 lg:py-5 lg:pr-24",children:[e.jsx(Zt,{className:"text-pretty text-[1.75rem] font-black leading-tight tracking-tight text-[#251E18] lg:text-[2rem]",children:f("publishTitle")}),e.jsx(qt,{className:"mt-1 max-w-3xl text-sm leading-5 text-[#6C6255] lg:text-[15px]",children:f("publishDescription")})]}),e.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto overscroll-contain",children:e.jsxs("div",{className:"grid min-h-full grid-cols-[40%_60%]",children:[e.jsx("section",{className:"bg-[#FBF5E7] px-8 py-5 lg:px-10",children:e.jsxs("div",{className:"mx-auto max-w-[420px] lg:sticky lg:top-5",children:[e.jsx("h3",{className:"mb-2 text-lg font-black text-[#2E261F]",children:f("previewTitle")}),Re,N?e.jsx("div",{className:"mt-3",children:N}):null,e.jsx("div",{className:"mt-3",children:_e})]})}),e.jsx("section",{className:"bg-white px-8 py-5 lg:px-10",children:e.jsxs("div",{className:"mx-auto max-w-[44rem]",children:[e.jsxs("div",{className:"mb-4",children:[e.jsx("h3",{className:"text-lg font-black text-[#2E261F]",children:f("shareFormStepTitle")}),e.jsx("p",{className:"mt-1 text-sm leading-5 text-[#766D5F]",children:f("shareFormDescription")})]}),Xe]})})]})}),e.jsxs("footer",{className:"shrink-0 border-t border-[#E2D8C9] bg-white px-8 py-4 lg:px-10",children:[e.jsxs("div",{className:"flex items-center gap-6",children:[e.jsxs("div",{role:"note",className:"flex min-w-0 flex-1 items-center gap-2.5 text-[#185E57]",children:[e.jsx(Ga,{"aria-hidden":"true",className:"h-[18px] w-[18px] shrink-0"}),e.jsx("p",{className:"text-xs font-semibold leading-5 lg:text-sm",children:f("moderationNotice")})]}),e.jsxs("div",{className:"flex shrink-0 items-center justify-end gap-3",children:[e.jsx("button",{type:"button",onClick:()=>X(!1),disabled:m,className:"h-12 min-w-[96px] rounded-[14px] px-4 text-base font-black text-[#655A4D] transition-colors hover:bg-[#F5F0E6] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#006B5F] disabled:opacity-50",children:f("cancel")}),P]})]}),Te]})]})})]})}),Ee=e.jsx(Xt,{open:t,onOpenChange:X,children:e.jsxs(Nn,{children:[e.jsx(jn,{className:"bg-[#1E1C12]/24 backdrop-blur-[6px]"}),e.jsx(Sn,{className:"pointer-events-none fixed inset-0 z-50 flex items-center justify-center overflow-hidden overscroll-contain px-5 py-5",children:e.jsxs("div",{className:"pointer-events-auto relative max-h-[calc(100dvh-2rem)] w-full max-w-[48rem] overflow-y-auto rounded-[24px] bg-[#FBF5E7] px-6 py-6 shadow-[0_28px_72px_rgba(30,28,18,0.2)] lg:px-7 lg:py-7",children:[z,e.jsx(Zt,{className:"pr-12 text-[1.75rem] font-black leading-tight tracking-tight text-[#251E18]",children:f("title")}),e.jsx(qt,{className:"mt-1 max-w-xl text-sm leading-5 text-[#6C6255]",children:J}),e.jsxs("div",{className:"mt-5 grid grid-cols-[minmax(0,0.92fr)_minmax(0,1.08fr)] gap-5",children:[e.jsx("div",{children:Re}),e.jsxs("div",{className:"space-y-3",children:[N,_e,e.jsxs("div",{className:"rounded-[16px] bg-white/75 p-4",children:[e.jsx("h3",{className:"text-base font-black text-[#251E18]",children:f("quickExportTitle")}),Ye,e.jsx("div",{className:"mt-4",children:ye}),Te]})]})]})]})})]})}),pe=e.jsxs("div",{className:"flex shrink-0 items-start justify-between gap-2.5 border-b border-[#E4DACB] bg-[#FBF5E7] px-4 pb-3 pt-[max(0.75rem,env(safe-area-inset-top))]",children:[e.jsxs("div",{className:"min-w-0 pr-2",children:[e.jsx(Je,{className:"text-pretty text-[1.45rem] font-black leading-tight tracking-tight text-[#251E18]",children:f(re?"publishTitle":"title")}),e.jsx(et,{className:"mt-1 text-xs leading-4 text-[#6C6255]",children:re?f("publishDescription"):J})]}),e.jsx(vs,{disabled:m,"aria-label":f("close"),className:"flex h-11 w-11 shrink-0 touch-manipulation items-center justify-center rounded-full text-[#7F7668] transition-colors hover:bg-[#F3EEDF] hover:text-[#1E1C12] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#006B5F] focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50",children:e.jsx(vt,{"aria-hidden":"true",className:"h-5 w-5"})})]}),ue=e.jsxs("div",{className:"flex h-full min-h-0 flex-col overflow-hidden bg-white text-[#1E1C12]",children:[pe,e.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto overscroll-contain",children:e.jsxs("div",{className:"md:grid md:min-h-full md:grid-cols-[minmax(0,0.82fr)_minmax(0,1.18fr)]",children:[e.jsxs("section",{className:"bg-[#FBF5E7] px-4 py-4 md:px-6 md:py-6",children:[e.jsx("h3",{className:"mb-3 text-sm font-black text-[#2E261F] md:text-base",children:f("previewTitle")}),Re,N?e.jsx("div",{className:"mt-4",children:N}):null]}),e.jsxs("section",{className:"bg-white px-4 py-4 md:px-6 md:py-6",children:[e.jsxs("div",{className:"mb-4 hidden md:block",children:[e.jsx("h3",{className:"text-base font-black text-[#2E261F]",children:f("shareFormStepTitle")}),e.jsx("p",{className:"mt-1 text-xs leading-5 text-[#766D5F]",children:f("shareFormDescription")})]}),Xe,e.jsx("div",{className:"mt-4",children:_e})]})]})}),e.jsxs("div",{className:"shrink-0 border-t border-[#E2D8C9] bg-white px-3 pb-[max(0.75rem,env(safe-area-inset-bottom))] pt-2.5 shadow-[0_-12px_28px_rgba(30,28,18,0.07)]",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>X(!1),disabled:m,className:"h-[52px] shrink-0 rounded-[14px] px-3 text-sm font-black text-[#655A4D] hover:bg-[#F5F0E6] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#006B5F] disabled:opacity-50",children:f("cancel")}),P]}),Te]})]}),Rt=e.jsxs("div",{className:"flex h-full min-h-0 flex-col overflow-hidden bg-[#FBF5E7] text-[#1E1C12]",children:[pe,e.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto overscroll-contain px-4 pb-[max(1.25rem,env(safe-area-inset-bottom))] pt-4",children:[Re,N?e.jsx("div",{className:"mt-4",children:N}):null,e.jsx("div",{className:"mt-4",children:_e}),e.jsxs("div",{className:"mt-4 rounded-[16px] bg-white/80 p-4",children:[e.jsx("h3",{className:"text-lg font-black tracking-tight text-[#251E18]",children:f("quickExportTitle")}),Ye,e.jsx("div",{className:"mt-4",children:ye}),Te]})]})]});return x?e.jsx(tt,{open:t,onOpenChange:X,children:e.jsx(at,{side:"bottom",className:"h-dvh overflow-hidden overscroll-contain rounded-none border-none bg-transparent p-0 shadow-none motion-reduce:transition-none motion-reduce:data-[state=closed]:animate-none motion-reduce:data-[state=open]:animate-none sm:h-[94dvh] sm:rounded-t-[28px] [&>button]:hidden",children:re?ue:Rt})}):re?ve:Ee}const ua=20,Yn=12;function ji({open:t,onOpenChange:a}){const n=de("AndroidTesterSignup"),o=de("Generator"),l=Es("(max-width: 1023px)"),i=r.useRef(null),c=r.useRef(!1),h=r.useRef(null),u=r.useRef(null),m=r.useRef(null),y=r.useRef(null),[F,A]=r.useState(null),[d,k]=r.useState(!1),v=r.useCallback(p=>{const g=h.current;return g?An(p,{width:window.innerWidth,height:window.innerHeight},{width:g.offsetWidth,height:g.offsetHeight},ua):p},[]),N=r.useCallback(p=>{h.current&&(h.current.style.transform=`translate3d(${p.x}px, ${p.y}px, 0)`)},[]),O=r.useCallback(()=>{const p=h.current;p&&A(g=>{const j=g?An(g,{width:window.innerWidth,height:window.innerHeight},{width:p.offsetWidth,height:p.offsetHeight},ua):Zr("top-right",{width:window.innerWidth,height:window.innerHeight},{width:p.offsetWidth,height:p.offsetHeight},ua,ua);return N(j),j})},[N]);r.useEffect(()=>{t&&!c.current&&(i.current=document.activeElement instanceof HTMLElement?document.activeElement:null),!t&&c.current&&i.current?.focus(),c.current=t},[t]),r.useEffect(()=>{if(!t||l)return;const p=g=>{g.key==="Escape"&&(g.preventDefault(),a(!1))};return document.addEventListener("keydown",p),()=>document.removeEventListener("keydown",p)},[l,a,t]),r.useLayoutEffect(()=>{!t||l||O()},[l,t,O]),r.useEffect(()=>{if(!t||l)return;const p=()=>{A(j=>{if(!j)return j;const V=v(j);return N(V),V})};window.addEventListener("resize",p);const g=new ResizeObserver(p);return h.current&&g.observe(h.current),()=>{window.removeEventListener("resize",p),g.disconnect()}},[N,v,l,t]),r.useEffect(()=>()=>{y.current!==null&&window.cancelAnimationFrame(y.current)},[]);const f=p=>{m.current=p,y.current===null&&(y.current=window.requestAnimationFrame(()=>{y.current=null,m.current&&N(m.current)}))},x=p=>{p.button!==0||!F||p.target instanceof Element&&p.target.closest("[data-panel-drag-exclude]")||(p.preventDefault(),p.currentTarget.setPointerCapture(p.pointerId),u.current={pointerId:p.pointerId,pointerX:p.clientX,pointerY:p.clientY,position:F},m.current=F,k(!0))},M=p=>{const g=u.current;!g||g.pointerId!==p.pointerId||f(v({x:g.position.x+p.clientX-g.pointerX,y:g.position.y+p.clientY-g.pointerY}))},D=p=>{const g=u.current;if(!(!g||g.pointerId!==p.pointerId)&&(p.currentTarget.hasPointerCapture(p.pointerId)&&p.currentTarget.releasePointerCapture(p.pointerId),u.current=null,k(!1),m.current)){const j=m.current;N(j),A(j)}},_=p=>{const g={ArrowDown:{x:0,y:1},ArrowLeft:{x:-1,y:0},ArrowRight:{x:1,y:0},ArrowUp:{x:0,y:-1}}[p.key];g&&(p.preventDefault(),A(j=>{if(!j)return j;const V=p.shiftKey?Yn*3:Yn,K=v({x:j.x+g.x*V,y:j.y+g.y*V});return N(K),K}))},$=e.jsx(Tr,{source:"generator-export-panel",variant:"compact",autoFocus:!0});if(l)return e.jsx(tt,{open:t,onOpenChange:a,children:e.jsxs(at,{side:"bottom",className:"inset-x-3 bottom-3 h-auto max-h-[calc(100dvh-1.5rem)] overflow-y-auto rounded-[22px] border border-[#D8CBB9] bg-[#FFFDF8] px-4 pb-[max(1rem,env(safe-area-inset-bottom))] pt-4 shadow-[0_20px_56px_rgba(30,28,18,0.22)] [&>button:last-child]:hidden",children:[e.jsxs("div",{className:"mb-4 flex items-start gap-2.5 pr-11",children:[e.jsx("span",{"aria-hidden":"true",className:"flex h-8 w-8 shrink-0 items-center justify-center rounded-full bg-[#E3F5F1] text-sm font-black text-[#087B70]",children:"?"}),e.jsxs("div",{children:[e.jsx("p",{className:"mb-1 text-[10px] font-black uppercase tracking-[0.18em] text-[#087B70]",children:n("eyebrow")}),e.jsx(Je,{className:"text-left text-lg font-black leading-tight tracking-tight text-[#251E18]",children:n("panelTitle")}),e.jsx(et,{className:"mt-1.5 text-left text-[13px] leading-5 text-[#6C6255]",children:n("panelDescription")})]})]}),e.jsx("button",{type:"button",onClick:()=>a(!1),"aria-label":n("close"),className:"absolute right-3 top-3 flex h-11 w-11 touch-manipulation items-center justify-center rounded-full text-[#7F7668] hover:bg-[#F3EEDF] hover:text-[#1E1C12] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#168B7D] focus-visible:ring-offset-2",children:e.jsx(vt,{"aria-hidden":"true",className:"h-5 w-5"})}),$]})});if(!t)return null;const L=o("dragPanel",{panel:n("panelTitle")});return e.jsxs("aside",{ref:h,role:"dialog","aria-modal":"false","aria-labelledby":"android-tester-panel-title","aria-describedby":"android-tester-panel-description",className:`fixed left-0 top-0 z-[80] w-[min(380px,calc(100vw-2.5rem))] max-h-[calc(100dvh-2.5rem)] overflow-y-auto rounded-[22px] border bg-[#FFFDF8] p-5 shadow-[0_24px_64px_rgba(30,28,18,0.22)] motion-safe:animate-in motion-safe:fade-in motion-safe:duration-150 ${d?"border-[#168B7D] shadow-[0_28px_72px_rgba(30,28,18,0.28)]":"border-[#D8CBB9]"}`,style:{transform:F?`translate3d(${F.x}px, ${F.y}px, 0)`:"translate3d(-9999px, -9999px, 0)",visibility:F?"visible":"hidden"},children:[e.jsx("button",{type:"button",onClick:()=>a(!1),"aria-label":n("close"),"data-panel-drag-exclude":!0,className:"absolute right-3 top-3 flex h-11 w-11 touch-manipulation items-center justify-center rounded-full text-[#7F7668] hover:bg-[#F3EEDF] hover:text-[#1E1C12] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#168B7D] focus-visible:ring-offset-2",children:e.jsx(vt,{"aria-hidden":"true",className:"h-5 w-5"})}),e.jsxs("header",{className:`mb-5 flex touch-none select-none items-start gap-2.5 pr-10 ${d?"cursor-grabbing":"cursor-grab"}`,onPointerDown:x,onPointerMove:M,onPointerUp:D,onPointerCancel:D,children:[e.jsx("button",{type:"button","aria-label":L,title:L,onKeyDown:_,className:`flex h-9 w-9 shrink-0 items-center justify-center rounded-full bg-[#E3F5F1] text-[#087B70] transition hover:bg-[#CDEDE7] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#168B7D] focus-visible:ring-offset-2 ${d?"bg-[#CDEDE7]":""}`,children:e.jsx(qr,{"aria-hidden":"true",className:"h-5 w-5"})}),e.jsxs("div",{children:[e.jsx("p",{className:"mb-1 text-[10px] font-black uppercase tracking-[0.18em] text-[#087B70]",children:n("eyebrow")}),e.jsx("h2",{id:"android-tester-panel-title",className:"text-lg font-black leading-tight tracking-tight text-[#251E18]",children:n("panelTitle")}),e.jsx("p",{id:"android-tester-panel-description",className:"mt-1.5 text-[13px] leading-5 text-[#6C6255]",children:n("panelDescription")})]})]}),$]})}const Xn=new Intl.Collator(void 0,{numeric:!0,sensitivity:"base"});function He(t){return t.code||t.name}function Zn(t,a){const n=a.trim().toLocaleLowerCase();return n?[t.code,t.name,t.id].some(o=>o?.toLocaleLowerCase().includes(n)??!1):!0}function qn({colors:t,selectedIds:a,onSelect:n,beadCountLabel:o,unusedLabel:l,disabled:i=!1,emptyMessage:c}){return t.length===0?e.jsx("div",{className:"flex min-h-32 items-center justify-center rounded-lg bg-[#FBF9F6] px-4 py-8 text-center text-sm text-[#8F7E6F]",children:c}):e.jsx("div",{className:"grid grid-cols-[repeat(auto-fit,minmax(52px,1fr))] content-start gap-x-2 gap-y-2 rounded-lg bg-[#FBF9F6] p-2 sm:grid-cols-8 sm:gap-x-2.5 sm:gap-y-3 sm:p-3",children:t.map(h=>{const u=a.has(h.id),m=He(h),y=h.name===m?m:`${h.name} ${m}`,F=h.count>0?`${h.count} ${o}`:l;return e.jsxs("button",{type:"button",onClick:()=>n(h.id),"aria-pressed":u,"aria-label":`${y},${F}`,title:`${y} · ${F}`,disabled:i,className:`group flex min-h-16 min-w-0 touch-manipulation flex-col items-center justify-center gap-1 rounded-lg px-1 py-1.5 transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#3E2A1E] focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 ${u?"bg-[#E6F5F2] text-[#19796C]":"text-[#5A4738] hover:bg-white"}`,children:[e.jsxs("span",{className:"relative",children:[e.jsx("span",{className:`block h-7 w-7 rounded-md border-2 shadow-sm transition-transform group-hover:scale-105 ${u?"border-white ring-2 ring-[#32B8A6] ring-offset-1":h.count>0?"border-[#8F7E6F]":"border-[#D8CBB9]"}`,style:{backgroundColor:h.hex},"aria-hidden":"true"}),u&&e.jsx("span",{className:"absolute inset-0 flex items-center justify-center","aria-hidden":"true",children:e.jsx("span",{className:"flex h-4 w-4 items-center justify-center rounded-full bg-[#19796C] text-white",children:e.jsx(_r,{className:"h-3 w-3",strokeWidth:3})})}),h.count>0&&e.jsx("span",{className:"absolute -right-2 -top-1.5 min-w-5 rounded-full bg-[#3E2A1E] px-1 py-0.5 text-center text-[8px] font-black leading-none text-white shadow-sm","aria-hidden":"true",children:h.count>99?"99+":h.count})]}),e.jsx("span",{className:"max-w-full truncate text-[10px] font-black tracking-wide",children:m})]},h.id)})})}function Si({open:t,onOpenChange:a,beadStats:n,activePalette:o,onDeleteColors:l,onReplaceColor:i}){const c=de("Generator"),h=bo(),[u,m]=r.useState("delete"),[y,F]=r.useState("source"),[A,d]=r.useState([]),[k,v]=r.useState(null),[N,O]=r.useState("used"),[f,x]=r.useState(""),[M,D]=r.useState(""),[_,$]=r.useState("least"),[L,p]=r.useState(!1),[g,j]=r.useState(!1),[V,K]=r.useState(null),te=r.useMemo(()=>new Set(A),[A]),T=r.useMemo(()=>n.filter(P=>te.has(P.id)),[n,te]),w=u==="replace"&&A.length===1&&T[0]||null,I=r.useMemo(()=>T.reduce((P,z)=>P+z.count,0),[T]),Z=r.useMemo(()=>T.map(He).join("、"),[T]),S=r.useMemo(()=>new Map(n.map(P=>[P.id,P.count])),[n]),ae=r.useMemo(()=>{const P=n.filter(z=>Zn(z,f)).slice();return P.sort((z,ve)=>_==="least"&&z.count!==ve.count?z.count-ve.count:Xn.compare(He(z),He(ve))),P},[n,_,f]),re=r.useMemo(()=>(N==="used"?n:o.map(z=>({...z,count:S.get(z.id)||0}))).filter(z=>z.id!==w?.id).filter(z=>Zn(z,M)).slice().sort((z,ve)=>Xn.compare(He(z),He(ve))),[o,n,N,S,w,M]),G=r.useMemo(()=>k&&re.find(P=>P.id===k)||null,[k,re]),q=r.useMemo(()=>k?new Set([k]):new Set,[k]),Y=()=>{m("delete"),F("source"),d([]),v(null),O("used"),x(""),D(""),$("least"),p(!1),j(!1),K(null)},J=P=>{!P&&g||(P||Y(),a(P))},me=P=>{g||P===u||(m(P),F("source"),d([]),v(null),x(""),D(""),K(null))},X=P=>{if(!g){if(K(null),u==="replace"){d([P]),v(null);return}d(z=>z.includes(P)?z.filter(ve=>ve!==P):[...z,P])}},be=P=>{g||(v(P),K(null))},Ae=P=>{g||P===N||(O(P),v(null),D(""))},Ie=async()=>{if(!(A.length===0||g)){j(!0),K(null);try{await l(A),Y(),a(!1)}catch{K(c("colorAdjustmentError")),j(!1)}}},ce=async()=>{if(!(!w||!G||g)){j(!0),K(null);try{await i(w.id,G.id),Y(),a(!1)}catch{K(c("colorAdjustmentError")),j(!1)}}},De=P=>{!P&&g||(p(P),P||K(null))},rt=()=>e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row",children:[e.jsxs("label",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"sr-only",children:c("searchColorPlaceholder")}),e.jsx(Vt,{type:"search",value:f,onChange:P=>x(P.target.value),placeholder:c("searchColorPlaceholder"),disabled:g,className:"h-11 border-[#D8CBB9] bg-white text-[#3E2A1E] focus-visible:ring-[#3E2A1E]"})]}),e.jsxs("label",{className:"sm:w-44",children:[e.jsx("span",{className:"sr-only",children:c("colorSortLabel")}),e.jsxs("select",{value:_,onChange:P=>$(P.target.value),disabled:g,"aria-label":c("colorSortLabel"),className:"h-11 w-full rounded-md border border-[#D8CBB9] bg-white px-3 text-sm font-medium text-[#5A4738] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#3E2A1E] focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",children:[e.jsx("option",{value:"least",children:c("sortLeastUsed")}),e.jsx("option",{value:"code",children:c("sortByCode")})]})]})]}),Le=P=>e.jsxs("section",{className:"min-w-0 space-y-3","aria-labelledby":"cleanup-source-heading",children:[e.jsxs("div",{className:"flex flex-wrap items-end justify-between gap-2",children:[e.jsx("h3",{id:"cleanup-source-heading",className:"text-sm font-black text-[#5A4738]",children:P}),A.length>0&&e.jsx("button",{type:"button",onClick:()=>{d([]),v(null),K(null)},disabled:g,className:"min-h-9 rounded-md px-2 text-xs font-bold text-[#19796C] underline-offset-4 hover:bg-[#E6F5F2] hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#19796C] disabled:opacity-50",children:c("clearSelection")})]}),rt(),e.jsx(qn,{colors:ae,selectedIds:te,onSelect:X,beadCountLabel:c("beadsCount"),unusedLabel:c("unusedColor"),disabled:g,emptyMessage:c("noMatchingColors")})]}),Pe=()=>e.jsxs("section",{className:"min-w-0 space-y-3","aria-labelledby":"cleanup-target-heading",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsx("h3",{id:"cleanup-target-heading",className:"text-sm font-black text-[#5A4738]",children:c("selectTargetColor")}),w&&e.jsxs("div",{className:"flex min-w-0 items-center gap-2 text-xs font-bold text-[#8F7E6F]",children:[e.jsx("span",{className:"h-5 w-5 shrink-0 rounded border border-[#D8CBB9]",style:{backgroundColor:w.hex},"aria-hidden":"true"}),e.jsxs("span",{className:"truncate",children:[He(w)," →"]})]})]}),w?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-2 rounded-lg bg-[#F7F1E1] p-1",role:"tablist","aria-label":c("targetColorSource"),children:[e.jsx("button",{type:"button",role:"tab","aria-selected":N==="used",onClick:()=>Ae("used"),disabled:g,className:`min-h-10 rounded-md px-2 text-xs font-black transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#3E2A1E] ${N==="used"?"bg-white text-[#3E2A1E] shadow-sm":"text-[#8F7E6F] hover:text-[#5A4738]"}`,children:c("colorFromUsed")}),e.jsx("button",{type:"button",role:"tab","aria-selected":N==="palette",onClick:()=>Ae("palette"),disabled:g,className:`min-h-10 rounded-md px-2 text-xs font-black transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#3E2A1E] ${N==="palette"?"bg-white text-[#3E2A1E] shadow-sm":"text-[#8F7E6F] hover:text-[#5A4738]"}`,children:c("colorFromPalette")})]}),e.jsxs("label",{children:[e.jsx("span",{className:"sr-only",children:c("searchTargetColorPlaceholder")}),e.jsx(Vt,{type:"search",value:M,onChange:P=>D(P.target.value),placeholder:c("searchTargetColorPlaceholder"),disabled:g,className:"h-11 border-[#D8CBB9] bg-white text-[#3E2A1E] focus-visible:ring-[#3E2A1E]"})]}),e.jsx(qn,{colors:re,selectedIds:q,onSelect:be,beadCountLabel:c("beadsCount"),unusedLabel:c("unusedColor"),disabled:g,emptyMessage:c("noMatchingColors")})]}):e.jsx("div",{className:"flex min-h-32 items-center justify-center rounded-lg bg-[#F7F1E1] px-4 py-8 text-center text-sm text-[#8F7E6F]",children:c("selectSourceFirst")})]}),Re=()=>n.length===0?e.jsxs("div",{className:"flex min-h-56 flex-col items-center justify-center px-4 py-10 text-center",children:[e.jsx("div",{className:"mb-4 flex h-12 w-12 items-center justify-center rounded-full bg-[#F7F1E1]",children:e.jsx(vt,{className:"h-6 w-6 text-[#8F7E6F]","aria-hidden":"true"})}),e.jsx("p",{className:"text-sm font-bold text-[#5A4738]",children:c("noColorsUsed")}),e.jsx("p",{className:"mt-2 max-w-sm text-xs leading-5 text-[#8F7E6F]",children:c("noColorsUsedDesc")})]}):u==="delete"?Le(c("selectColorToDelete")):h?y==="source"?Le(c("selectSourceColor")):Pe():e.jsxs("div",{className:"grid min-w-0 grid-cols-2 gap-6",children:[Le(c("selectSourceColor")),Pe()]}),Te=()=>e.jsxs("div",{className:"mt-4 grid grid-cols-2 rounded-lg bg-[#F7F1E1] p-1",role:"tablist","aria-label":c("adjustmentMode"),children:[e.jsx("button",{type:"button",role:"tab","aria-selected":u==="delete",onClick:()=>me("delete"),disabled:g||n.length===0,className:`min-h-11 rounded-md px-3 text-sm font-black transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#3E2A1E] disabled:cursor-not-allowed disabled:opacity-50 ${u==="delete"?"bg-white text-[#3E2A1E] shadow-sm":"text-[#8F7E6F] hover:text-[#5A4738]"}`,children:c("deleteColor")}),e.jsx("button",{type:"button",role:"tab","aria-selected":u==="replace",onClick:()=>me("replace"),disabled:g||n.length===0,className:`min-h-11 rounded-md px-3 text-sm font-black transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#3E2A1E] disabled:cursor-not-allowed disabled:opacity-50 ${u==="replace"?"bg-white text-[#3E2A1E] shadow-sm":"text-[#8F7E6F] hover:text-[#5A4738]"}`,children:c("replaceColor")})]}),Ye=()=>u==="delete"?A.length>0?c("selectedColorsSummary",{count:A.length,beadCount:I}):c("selectColorsHint"):w?G?c("replaceSummary",{sourceCode:He(w),targetCode:He(G)}):c("selectTargetNext",{colorCode:He(w)}):c("selectSourceFirst"),_e=()=>n.length===0?e.jsx(ke,{type:"button",onClick:()=>J(!1),className:"h-11 w-full bg-[#3E2A1E] text-white hover:bg-[#2E1F17] sm:w-auto sm:min-w-28",children:c("closeColorAdjustment")}):u==="delete"?e.jsxs(e.Fragment,{children:[e.jsx(ke,{type:"button",variant:"outline",onClick:()=>J(!1),disabled:g,className:"h-11 border-[#D8CBB9] text-[#5A4738] hover:bg-[#F7F1E1] sm:min-w-28",children:c("cancel")}),e.jsx(ke,{type:"button",variant:"destructive",onClick:()=>p(!0),disabled:A.length===0||g,className:"h-11 sm:min-w-36",children:c("deleteSelectedColors",{count:A.length})})]}):h&&y==="source"?e.jsxs(e.Fragment,{children:[e.jsx(ke,{type:"button",variant:"outline",onClick:()=>J(!1),disabled:g,className:"h-12 border-[#D8CBB9] text-[#5A4738] hover:bg-[#F7F1E1]",children:c("cancel")}),e.jsx(ke,{type:"button",onClick:()=>F("target"),disabled:!w||g,className:"h-12 bg-[#3E2A1E] text-white hover:bg-[#2E1F17]",children:c("nextSelectTarget")})]}):e.jsxs(e.Fragment,{children:[e.jsx(ke,{type:"button",variant:"outline",onClick:()=>{if(h){F("source"),v(null),K(null);return}J(!1)},disabled:g,className:"h-11 border-[#D8CBB9] text-[#5A4738] hover:bg-[#F7F1E1] sm:min-w-28",children:c(h?"backToSourceColor":"cancel")}),e.jsxs(ke,{type:"button",onClick:ce,disabled:!w||!G||g,className:"h-11 bg-[#3E2A1E] text-white hover:bg-[#2E1F17] sm:min-w-36",children:[g&&e.jsx(ha,{className:"mr-2 h-4 w-4 animate-spin","aria-hidden":"true"}),c(g?"replacingColor":"confirmReplace")]})]}),Xe=e.jsx("div",{className:"shrink-0 border-t border-[#E7DED2] bg-white px-4 py-3 pb-[max(0.75rem,env(safe-area-inset-bottom))] sm:px-6 sm:py-4",children:e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{className:"min-w-0 text-xs font-bold leading-5 text-[#6F5B4B]",role:"status","aria-live":"polite",children:[e.jsx("p",{className:"break-words",children:Ye()}),V&&e.jsx("p",{className:"mt-1 text-[#B42318]",role:"alert",children:V})]}),e.jsx("div",{className:"grid shrink-0 grid-cols-2 gap-2 sm:flex sm:justify-end",children:_e()})]})}),ye=L?e.jsx(Xt,{open:L,onOpenChange:De,children:e.jsxs(Ba,{closeLabel:c("closeColorAdjustment"),closeDisabled:g,className:"w-[min(92vw,440px)] gap-0 overflow-hidden rounded-xl border-[#D8CBB9] p-0 [&>button]:hidden",children:[e.jsxs(La,{className:"space-y-2 px-5 pb-4 pt-5 text-left sm:px-6 sm:pt-6",children:[e.jsx(Zt,{className:"text-lg font-black text-[#3E2A1E]",children:c("confirmDelete")}),e.jsx(qt,{className:"leading-6 text-[#6F5B4B]",children:c("deleteColorsConfirm",{colorCodes:Z,beadCount:I})})]}),e.jsx("div",{className:"flex max-h-28 flex-wrap gap-1.5 overflow-y-auto px-5 pb-2 sm:px-6","aria-label":Z,children:T.map(P=>e.jsx("span",{className:"rounded-full border border-[#D8CBB9] bg-[#F7F1E1] px-2.5 py-1 text-xs font-black text-[#3E2A1E]",children:He(P)},P.id))}),V&&e.jsx("p",{className:"px-5 pt-2 text-sm font-medium text-[#B42318] sm:px-6",role:"alert",children:V}),e.jsxs(us,{className:"mt-4 grid grid-cols-2 gap-2 border-t border-[#E7DED2] bg-[#FBF9F6] px-5 py-4 sm:grid-cols-2 sm:space-x-0 sm:px-6",children:[e.jsx(ke,{type:"button",variant:"outline",onClick:()=>De(!1),disabled:g,className:"h-11 border-[#D8CBB9] text-[#5A4738] hover:bg-white",children:c("cancel")}),e.jsxs(ke,{type:"button",variant:"destructive",onClick:Ie,disabled:g,className:"h-11",children:[g&&e.jsx(ha,{className:"mr-2 h-4 w-4 animate-spin","aria-hidden":"true"}),g?c("deletingColors"):c("deleteSelectedColors",{count:T.length})]})]})]})}):null;return h?e.jsxs(e.Fragment,{children:[e.jsx(tt,{open:t,onOpenChange:J,children:e.jsxs(at,{side:"bottom",className:"flex h-dvh w-full flex-col gap-0 overflow-hidden border-0 bg-white p-0 [&>button]:hidden",children:[e.jsxs("div",{className:"shrink-0 border-b border-[#E7DED2] bg-white px-4 pb-4 pt-[max(1rem,env(safe-area-inset-top))]",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx(Je,{className:"text-left text-xl font-black text-[#3E2A1E]",children:c("cleanupDialogTitle")}),e.jsx(et,{className:"mt-1 text-left leading-5 text-[#8F7E6F]",children:c("cleanupDialogDescription")})]}),e.jsx(vs,{asChild:!0,children:e.jsx("button",{type:"button",disabled:g,"aria-label":c("closeColorAdjustment"),className:"flex h-11 w-11 shrink-0 touch-manipulation items-center justify-center rounded-full text-[#6F5B4B] hover:bg-[#F7F1E1] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#3E2A1E] disabled:opacity-50",children:e.jsx(vt,{className:"h-5 w-5","aria-hidden":"true"})})})]}),Te()]}),e.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto overscroll-contain px-4 py-4",children:Re()}),Xe]})}),ye]}):e.jsxs(e.Fragment,{children:[e.jsx(Xt,{open:t,onOpenChange:J,children:e.jsxs(Ba,{closeLabel:c("closeColorAdjustment"),closeDisabled:g,className:"flex h-[min(86dvh,820px)] w-[min(92vw,880px)] max-w-[880px] flex-col gap-0 overflow-hidden border-[#D8CBB9] p-0",children:[e.jsxs("div",{className:"shrink-0 border-b border-[#E7DED2] bg-white px-6 pb-4 pt-6",children:[e.jsxs(La,{className:"space-y-1.5 pr-12 text-left",children:[e.jsx(Zt,{className:"text-xl font-black text-[#3E2A1E]",children:c("cleanupDialogTitle")}),e.jsx(qt,{className:"leading-5 text-[#8F7E6F]",children:c("cleanupDialogDescription")})]}),Te()]}),e.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto overscroll-contain px-6 py-5",children:Re()}),Xe]})}),ye]})}const ki={UNSUPPORTED_PAGE:"sourceUnavailable",IMAGE_NOT_FOUND:"sourceUnavailable",IMAGE_NOT_VISIBLE:"sourceUnavailable",DIRECT_FETCH_FAILED:"captureFailed",CAPTURE_FAILED:"captureFailed",EMPTY_CAPTURE:"captureFailed",UNSUPPORTED_IMAGE:"imageInvalid",IMAGE_TOO_LARGE:"imageInvalid",IMAGE_DECODE_FAILED:"imageInvalid",TRANSFER_EXPIRED:"transferUnavailable",TRANSFER_MISSING:"transferUnavailable",TRANSFER_CORRUPTED:"validationFailed",BRIDGE_UNAVAILABLE:"bridgeUnavailable",IMPORT_TIMEOUT:"bridgeUnavailable",SITE_VALIDATION_FAILED:"validationFailed"};function Fi({state:t,manualUploadInputId:a,onReturnToSource:n}){const o=de("Generator.extensionImport");if(t.status==="idle"||t.status==="opening-crop")return null;const l=t.status==="error";let i=o("waiting");t.status==="receiving"?i=o("receiving",{received:t.receivedChunks,total:t.totalChunks}):t.status==="validating"?i=o("validating"):t.status==="error"&&(i=o(`errors.${ki[t.code]}`));const c=()=>{const h=document.getElementById(a);h instanceof HTMLInputElement&&h.click()};return e.jsxs("section",{role:l?"alert":"status","aria-live":l?"assertive":"polite",className:`mx-auto mb-4 w-full max-w-lg rounded-2xl border px-4 py-3 shadow-sm ${l?"border-[#E2A39C] bg-[#FDECEA] text-[#7F2929]":"border-[#C8BCA9] bg-white/90 text-[#3E2A1E]"}`,children:[e.jsxs("div",{className:"flex items-start gap-3",children:[l?e.jsx(Ir,{size:20,className:"mt-0.5 shrink-0","aria-hidden":"true"}):e.jsx(ha,{size:20,className:"mt-0.5 shrink-0 animate-spin motion-reduce:animate-none","aria-hidden":"true"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("h2",{className:"text-sm font-black uppercase tracking-wide",children:o(l?"errorTitle":"statusTitle")}),e.jsx("p",{className:"mt-1 text-sm leading-5",children:i})]})]}),l?e.jsxs("div",{className:"mt-3 flex flex-col gap-2 min-[420px]:flex-row",children:[e.jsxs("button",{type:"button",onClick:c,className:"inline-flex min-h-11 cursor-pointer items-center justify-center gap-2 rounded-xl bg-[#238F82] px-4 py-2 text-sm font-bold text-white hover:bg-[#1E786F] focus-within:ring-2 focus-within:ring-[#238F82] focus-within:ring-offset-2",children:[e.jsx(Yt,{size:16,"aria-hidden":"true"}),o("manualUpload")]}),t.canReturnToSource?e.jsxs("button",{type:"button",onClick:n,className:"inline-flex min-h-11 items-center justify-center gap-2 rounded-xl border border-[#B77A72] bg-white px-4 py-2 text-sm font-bold text-[#7F2929] hover:bg-[#FFF7F5] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#B74343] focus-visible:ring-offset-2",children:[e.jsx(ws,{size:16,"aria-hidden":"true"}),o("returnToSource")]}):null]}):null]})}function Ai({manifest:t}){const a=de("Generator.extensionImport"),n=t.capture.method==="visible-screenshot";return e.jsxs("aside",{className:"mt-3 rounded-xl border border-[#D6C7B3] bg-[#FFF9EC] px-3 py-2.5 text-sm text-[#5A4738]",children:[e.jsx("p",{className:"font-bold",children:a("cropSource",{domain:t.source.domain})}),n?e.jsx("p",{className:"mt-1 leading-5",children:t.capture.partialCapture?a("partialCaptureWarning"):a("screenshotWarning")}):null,e.jsxs("a",{href:t.source.pageUrl,target:"_blank",rel:"noopener noreferrer",className:"mt-2 inline-flex min-h-9 items-center gap-1.5 rounded-md font-bold text-[#1E786F] underline underline-offset-2 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#238F82]",children:[a("viewSource"),e.jsx(ws,{size:14,"aria-hidden":"true"})]})]})}const Di="_beadSlot_1knze_1",Pi="_bead_1knze_1",Ri="_beadSide_1knze_17",Ti="_beadTop_1knze_40",_i="_count_1knze_59",Ht={beadSlot:Di,bead:Pi,beadSide:Ri,beadTop:Ti,count:_i};function Ii(t){const a=t.replace("#","");if(!/^[\da-f]{6}$/i.test(a))return"#FFFFFF";const n=Number.parseInt(a.slice(0,2),16),o=Number.parseInt(a.slice(2,4),16),l=Number.parseInt(a.slice(4,6),16);return n*.299+o*.587+l*.114>165?"#3E2A1E":"#FFFFFF"}function Mi({color:t,count:a}){const n={"--bead-color":t,"--bead-count-color":Ii(t)};return e.jsx("span",{className:Ht.beadSlot,"aria-hidden":"true",children:e.jsxs("span",{className:Ht.bead,style:n,children:[e.jsx("span",{className:Ht.beadSide,children:e.jsx("span",{className:Ht.count,children:a})}),e.jsx("span",{className:Ht.beadTop})]})})}function Kn({activePalette:t,beadStats:a,selectedColorId:n,onColorSelect:o,onColorClear:l,children:i,className:c}){const h=de("Generator"),[u,m]=r.useState("used"),y=r.useMemo(()=>new Map(a.map(x=>[x.id,x.count])),[a]),F=r.useMemo(()=>new Map(t.map(x=>[x.id,x])),[t]),A=r.useMemo(()=>[...t].sort((x,M)=>{const D=x.code||x.name,_=M.code||M.name;return D.localeCompare(_,void 0,{numeric:!0})}),[t]),d=r.useMemo(()=>a.map(x=>F.get(x.id)).filter(x=>x!==void 0),[a,F]),k=u==="used"?d:A,v=n&&F.get(n)||null,N=d.length,O=a.reduce((x,M)=>x+M.count,0),f=v&&y.get(v.id)||0;return e.jsxs("aside",{className:`relative z-20 flex h-full w-full shrink-0 flex-col overflow-hidden border-l border-[#D8CBB9] bg-white shadow-[-1px_0_20px_rgba(62,42,30,0.05)] ${c||"hidden xl:flex"}`,children:[i&&e.jsx("div",{className:"sticky top-0 z-10 space-y-3 border-b border-[#D8CBB9] bg-white p-4",children:i}),e.jsxs("div",{className:"z-10 shrink-0 space-y-3 border-b border-[#D8CBB9] bg-white p-3",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-black text-[#3E2A1E]",children:h("colorStatisticsSummary",{count:N})}),e.jsx("p",{className:"mt-0.5 text-[9px] font-bold text-[#8F7E6F]",children:h("totalBeadCount",{count:O})})]}),v&&e.jsxs("div",{className:"flex min-h-16 items-center gap-3 rounded-xl border border-[#32B8A6]/50 bg-[#E8F7F4] p-2.5 shadow-[0_0_0_2px_rgba(50,184,166,0.08)]",children:[e.jsx("span",{className:"h-10 w-10 shrink-0 rounded-lg border-2 border-white shadow-[0_0_0_1px_#D8CBB9]",style:{backgroundColor:v.hex},"aria-hidden":"true"}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block text-[9px] font-bold uppercase tracking-wide text-[#168B7D]",children:h("highlightedColor")}),e.jsx("span",{className:"block truncate text-xs font-black text-[#3E2A1E]",children:v.code||v.name}),v.code&&v.name!==v.code&&e.jsx("span",{className:"block truncate text-[9px] font-medium text-[#6F5B4B]",children:v.name})]}),e.jsx("span",{className:`shrink-0 rounded-full px-2 py-1 text-[9px] font-black ${f>0?"bg-[#D5F1EC] text-[#19796C]":"bg-[#F0EEE8] text-[#8F7E6F]"}`,children:f>0?h("usedBeads",{count:f}):h("unusedColor")}),e.jsx("button",{type:"button",onClick:l,className:"flex h-8 w-8 shrink-0 items-center justify-center rounded-lg text-[#5B756F] transition hover:bg-white hover:text-[#3E2A1E] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#32B8A6]",title:h("clearColorHighlight"),"aria-label":h("clearColorHighlight"),children:e.jsx(vt,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-1 rounded-lg bg-[#F0EEE8] p-1",role:"group","aria-label":h("paletteFilters"),children:[e.jsxs("button",{type:"button","aria-pressed":u==="used",onClick:()=>m("used"),className:`min-h-10 rounded-md px-2 text-[10px] font-black transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#3E2A1E] focus-visible:ring-offset-1 ${u==="used"?"bg-white text-[#3E2A1E] shadow-sm":"text-[#6F5B4B] hover:bg-white/60"}`,children:[h("usedColors")," ",e.jsx("span",{className:"tabular-nums text-[#8F7E6F]",children:N})]}),e.jsxs("button",{type:"button","aria-pressed":u==="all",onClick:()=>m("all"),className:`min-h-10 rounded-md px-2 text-[10px] font-black transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#3E2A1E] focus-visible:ring-offset-1 ${u==="all"?"bg-white text-[#3E2A1E] shadow-sm":"text-[#6F5B4B] hover:bg-white/60"}`,children:[h("allPaletteColors")," ",e.jsx("span",{className:"tabular-nums text-[#8F7E6F]",children:t.length})]})]}),e.jsxs("p",{className:"flex items-start gap-1.5 text-[9px] font-medium leading-relaxed text-[#6F5B4B]",children:[e.jsx(fs,{size:11,className:"mt-0.5 shrink-0 text-[#8F7E6F]","aria-hidden":"true"}),e.jsx("span",{children:h("colorHighlightHint")})]})]}),e.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto overscroll-contain bg-[#FBF9F6] p-2",children:k.length===0?e.jsxs("div",{className:"flex h-full min-h-48 flex-col items-center justify-center px-6 text-center",role:"status",children:[e.jsx("div",{className:"mb-3 grid grid-cols-3 gap-1","aria-hidden":"true",children:["#F2C94C","#32B8A6","#D8CBB9"].map(x=>e.jsx("span",{className:"h-5 w-5 rounded-md border border-[#D8CBB9]",style:{backgroundColor:x}},x))}),e.jsx("p",{className:"text-xs font-black text-[#3E2A1E]",children:h("noUsedColors")}),e.jsx("p",{className:"mt-1 max-w-48 text-[10px] leading-relaxed text-[#8F7E6F]",children:h("noUsedColorsDescription")})]}):e.jsx("div",{className:"grid grid-cols-5 gap-x-2 gap-y-3",children:k.map(x=>{const M=y.get(x.id)||0,D=n===x.id,_=x.code||x.name,$=x.name===_?_:`${x.name} ${_}`,L=M>0?h("usedBeads",{count:M}):h("unusedColor");return e.jsx("div",{className:"relative min-w-0",children:e.jsxs("button",{type:"button",onClick:()=>o(x.id),"aria-pressed":D,"aria-label":`${$}. ${L}`,title:`${x.name} · ${L}`,className:`w-full min-w-0 rounded-xl px-1 py-1.5 text-center transition hover:-translate-y-0.5 hover:bg-white hover:shadow-md focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#32B8A6] ${D?"bg-[#E8F7F4] ring-2 ring-[#32B8A6]/45 shadow-sm":""}`,children:[e.jsx("span",{className:`block truncate text-xs font-black ${D?"text-[#168B7D]":"text-[#3E2A1E]"}`,children:_}),e.jsx(Mi,{color:x.hex,count:M})]})},x.id)})})})]})}const $e=xa(t=>({editTool:"brush",fillMode:"single",selectedColorId:null,setEditTool:a=>t({editTool:a}),setFillMode:a=>t({fillMode:a}),setSelectedColorId:a=>t(n=>({selectedColorId:a,editTool:a?"brush":n.editTool}))}));function Qn({actionsDisabled:t=!1,activePalette:a,onOpenPalette:n,onOpenSourceColorSampler:o,selectedColorId:l,sourceColorSamplerDisabled:i=!1}){const{editTool:c,fillMode:h,setEditTool:u,setFillMode:m}=$e(yt(y=>({editTool:y.editTool,fillMode:y.fillMode,setEditTool:y.setEditTool,setFillMode:y.setFillMode})));return e.jsx(Kr,{actionsDisabled:t,activePalette:a,editTool:c==="symmetry"?null:c,fillMode:h,onEditToolChange:u,onFillModeChange:m,onOpenPalette:n,onOpenSourceColorSampler:o,selectedColorId:l,sourceColorSamplerDisabled:i})}function Jn({onMirror:t,onCleanupClick:a,onUndo:n,onRedo:o,canUndo:l,canRedo:i,actionsDisabled:c=!1,historyActionsDisabled:h=!1,showHeading:u=!0}){const m=de("Generator"),y="group relative flex h-11 flex-col items-center justify-center rounded-xl border border-[#D8CBB9] bg-[#FBF9F6] text-[#5A4738] transition-all duration-300 hover:border-[#3E2A1E] hover:bg-white hover:text-[#3E2A1E] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#3E2A1E] focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-35 disabled:hover:border-[#D8CBB9] disabled:hover:bg-[#FBF9F6] lg:h-10";return e.jsxs("div",{className:"space-y-1",children:[u&&e.jsx("h2",{className:"text-[10px] font-black uppercase tracking-[0.2em] text-[#8F7E6F]",children:m("tools")}),e.jsxs("div",{className:"grid grid-cols-4 gap-1.5",children:[e.jsxs("button",{type:"button",onClick:n,disabled:!l||h,className:y,title:m("undo"),"aria-label":m("undo"),children:[e.jsx(Qr,{size:16,"aria-hidden":"true"}),e.jsx("span",{className:"mt-0.5 text-[8px] font-black uppercase tracking-wide",children:m("undo")})]}),e.jsxs("button",{type:"button",onClick:o,disabled:!i||h,className:y,title:m("redo"),"aria-label":m("redo"),children:[e.jsx(Jr,{size:16,"aria-hidden":"true"}),e.jsx("span",{className:"mt-0.5 text-[8px] font-black uppercase tracking-wide",children:m("redo")})]}),e.jsxs("button",{type:"button",onClick:t,disabled:c,className:y,title:m("toggleMirrorMode"),children:[e.jsx(ko,{size:16,className:"transition-transform group-hover:scale-x-[-1]","aria-hidden":"true"}),e.jsx("span",{className:"mt-0.5 text-[8px] font-black uppercase tracking-wide",children:m("mirror")})]}),e.jsxs("button",{type:"button",onClick:a,disabled:c,className:y,title:m("cleanupTooltip"),children:[e.jsx(Mr,{size:16,className:"transition-transform group-hover:scale-110","aria-hidden":"true"}),e.jsx("span",{className:"mt-0.5 text-[8px] font-black uppercase tracking-wide",children:m("cleanupTool")})]})]})]})}function Bi(t,a){const[n,o]=r.useState(t);return r.useEffect(()=>{const l=setTimeout(()=>{o(t)},a);return()=>{clearTimeout(l)}},[t,a]),n}const Li=640,Oi=.82,Gi=new Set(["","transparent","#00000000"]);async function zi({pixels:t,width:a,height:n,size:o=Li}){if(!t.length||a<=0||n<=0||typeof document>"u")return null;const l=document.createElement("canvas"),i=l.getContext("2d");if(!i)return null;const c=Math.max(1,Math.floor((o-48)/Math.max(a,n))),h=a*c,u=n*c,m=Math.floor((o-h)/2),y=Math.floor((o-u)/2),F=new Map;l.width=o,l.height=o,i.imageSmoothingEnabled=!1,i.fillStyle="#f8fafc",i.fillRect(0,0,o,o);for(let A=0;Ao&&(o=h),il&&(l=i))}return o<0||l<0?null:{x:a,y:n,width:o-a+1,height:l-n+1}}function Wi(t){const a=Ui(t);if(!a)return{matrix:[],width:0,height:0,bounds:null};const n=[],o=a.y+a.height,l=a.x+a.width;for(let i=a.y;i{const w=h.current;if(!w)return;const I=new ResizeObserver(Z=>{const S=Z[0];S&&d({width:S.contentRect.width,height:S.contentRect.height})});return I.observe(w),()=>I.disconnect()},[]);const f=r.useMemo(()=>!t||A.width===0||A.height===0?1:wo({viewportWidth:A.width,viewportHeight:A.height,gridWidth:n,gridHeight:o,cellSize:l,gapSize:i,extraWidth:c*2+2,extraHeight:c*2+2}),[l,c,t,i,o,n,A]),x=r.useCallback((w,I,Z,S=I,ae=Z)=>{const re=es(w);if(!(Math.abs(re-y.current)>=1e-4)){const J=S-I,me=ae-Z;(Math.abs(J)>=.01||Math.abs(me)>=.01)&&v(X=>({x:X.x+J,y:X.y+me}));return}const q=u.current?.querySelector("canvas")||u.current,Y=q?Co(q.getBoundingClientRect(),I,Z):null;m.current=Y?{...Y,clientX:S,clientY:ae}:null,y.current=re,O(re)},[]),M=r.useCallback(w=>{const I=h.current;if(!I){const S=es(w);y.current=S,O(S);return}const Z=I.getBoundingClientRect();x(w,Z.left+Z.width/2,Z.top+Z.height/2)},[x]),D=r.useCallback(w=>{if(!t)return;w.preventDefault();const I=w.currentTarget.getBoundingClientRect().height,Z=No(y.current,w.deltaY,w.deltaMode,I,{minZoom:Fs,maxZoom:As});x(Z,w.clientX,w.clientY)},[t,x]);r.useLayoutEffect(()=>{const w=m.current,I=u.current?.querySelector("canvas")||u.current;if(m.current=null,!w||!I)return;const Z=jo(w,I.getBoundingClientRect());Math.abs(Z.x)<.01&&Math.abs(Z.y)<.01||v(S=>({x:S.x+Z.x,y:S.y+Z.y}))},[N]);const _=r.useCallback(()=>{m.current=null,F.current=null,y.current=1,O(1),v({x:0,y:0})},[]);r.useEffect(()=>{_()},[n,a,_]);const $=r.useCallback(w=>{w.target!==w.currentTarget||!t||_()},[t,_]),L=r.useCallback((w,I)=>{v({x:w,y:I})},[]),{isPanning:p,handlePointerDown:g,handlePointerMove:j,handlePointerUp:V}=eo({x:k.x,y:k.y,onPan:L,enabled:t}),K=r.useCallback(w=>{!t||w.distance<=0||(F.current={distance:w.distance,userZoom:y.current,lastCenterX:w.centerX,lastCenterY:w.centerY})},[t]),te=r.useCallback(w=>{const I=F.current;!t||!I||I.distance<=0||(x(I.userZoom*w.distance/I.distance,I.lastCenterX,I.lastCenterY,w.centerX,w.centerY),I.lastCenterX=w.centerX,I.lastCenterY=w.centerY)},[t,x]),T=r.useCallback(()=>{F.current=null},[]);return{viewportRef:h,boardRef:u,pan:k,userZoom:N,zoom:f*N,isPanning:p,setZoomAtViewportCenter:M,handleWheel:D,handleDoubleClick:$,handlePointerDown:g,handlePointerMove:j,handlePointerUp:V,handlePinchStart:K,handlePinchMove:te,handlePinchEnd:T,resetView:_}}const Ds="pixel-beads.extension-import",Va=1,ba="extensionImport",st=256*1024,Ps=Math.ceil(Ha/st),$i=["UNSUPPORTED_PAGE","IMAGE_NOT_FOUND","IMAGE_NOT_VISIBLE","DIRECT_FETCH_FAILED","CAPTURE_FAILED","EMPTY_CAPTURE","UNSUPPORTED_IMAGE","IMAGE_TOO_LARGE","IMAGE_DECODE_FAILED","TRANSFER_EXPIRED","TRANSFER_MISSING","TRANSFER_CORRUPTED","BRIDGE_UNAVAILABLE","IMPORT_TIMEOUT","SITE_VALIDATION_FAILED"],Vi=/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i,Rs=/^[0-9a-f]{64}$/i,Yi=/^(?:0|[1-9]\d{0,4})(?:\.(?:0|[1-9]\d{0,4})){0,3}$/,Ts=80,Xi=/[\p{Cc}\p{Cf}]/gu,Zi=/[<>:"/\\|?*]/g,ts=/^[.\s]+|[.\s]+$/g,qi=Math.ceil(st/3)*4,Ki=new Set(["en","zh","zh-tw","ja","vi","ko","de"]),Qi=new Set(["image/jpeg","image/png","image/webp"]),Ji={"image/jpeg":"jpg","image/png":"png","image/webp":"webp"};function nt(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function ut(t,a,n=[]){const o=new Set([...a,...n]),l=Object.keys(t);return a.every(i=>Object.hasOwn(t,i))&&l.every(i=>o.has(i))}function Pa(t){return Number.isSafeInteger(t)&&Number(t)>0}function as(t){if(typeof t!="string")return!1;const a=Date.parse(t);return Number.isFinite(a)&&new Date(a).toISOString()===t}function el(t){return typeof t!="string"||!Yi.test(t)?!1:t.split(".").every(a=>Number(a)<=65535)}function ns(t){if(typeof t!="string")return!1;try{const a=new URL(t);return(a.protocol==="http:"||a.protocol==="https:")&&a.username===""&&a.password===""}catch{return!1}}function tl(t){const a=t.normalize("NFC").replace(Xi,"").trim().replace(Zi,"-").replace(/\s+/g," ").replace(/-+/g,"-").replace(ts,"").trim();return Array.from(a).slice(0,Ts).join("").replace(ts,"")}function al(t,a){if(typeof t!="string"||t==="")return!1;const n=`.${Ji[a]}`;if(!t.toLowerCase().endsWith(n))return!1;const o=t.slice(0,-n.length);return o!==""&&Array.from(o).length<=Ts&&o===tl(o)}function nl(t){return nt(t)&&Object.keys(t).length===0}function sl(t){const a=t.endsWith("==")?2:t.endsWith("=")?1:0,n=t.length-a;for(let o=0;o=65&&l<=90,c=l>=97&&l<=122,h=l>=48&&l<=57;if(!i&&!c&&!h&&!(l===43||l===47))return!1}return!t.slice(0,n).includes("=")}function _s(t){if(t.length===0||t.length%4!==0||!sl(t))return null;try{const a=atob(t),n=new Uint8Array(a.length);for(let o=0;oa===t)}function Is(t){if(!nt(t)||!ut(t,["protocolVersion","transferId","createdAt","expiresAt","extensionVersion","locale","file","source","capture"])||t.protocolVersion!==Va||!fa(t.transferId)||!as(t.createdAt)||!as(t.expiresAt)||Date.parse(t.expiresAt)<=Date.parse(t.createdAt)||!el(t.extensionVersion)||typeof t.locale!="string"||!Ki.has(t.locale)||!nt(t.file)||!nt(t.source)||!nt(t.capture))return!1;const a=t.file,n=t.source,o=t.capture;if(!ut(a,["name","mimeType","size","sha256","width","height"])||!Qi.has(a.mimeType))return!1;const l=a.mimeType;return!al(a.name,l)||!Pa(a.size)||Number(a.size)>Ha||typeof a.sha256!="string"||!Rs.test(a.sha256)||!Pa(a.width)||!Pa(a.height)||!ut(n,["pageUrl","pageTitle","domain"],["imageUrl"])||!ns(n.pageUrl)||n.pageUrl.length>16384||typeof n.pageTitle!="string"||n.pageTitle.length>2048||typeof n.domain!="string"||n.domain.length===0||n.domain.length>255||new URL(n.pageUrl).hostname!==n.domain||n.imageUrl!==void 0&&!ns(n.imageUrl)?!1:ut(o,["method","partialCapture"])&&(o.method==="direct"||o.method==="visible-screenshot")&&typeof o.partialCapture=="boolean"}function Ms(t){if(!nt(t)||!ut(t,["index","totalChunks","base64"])||!Number.isSafeInteger(t.index)||!Number.isSafeInteger(t.totalChunks))return!1;const a=Number(t.index),n=Number(t.totalChunks);if(a<0||n<1||n>Ps||a>=n||typeof t.base64!="string"||t.base64.length>qi)return!1;const o=_s(t.base64);return!o||o.byteLength===0||o.byteLength>st?!1:a===n-1||o.byteLength===st}function Bs(t){if(!nt(t)||!ut(t,["totalChunks","totalBytes","sha256"])||!Number.isSafeInteger(t.totalChunks)||!Number.isSafeInteger(t.totalBytes))return!1;const a=Number(t.totalChunks),n=Number(t.totalBytes);return a>=1&&a<=Ps&&n>=1&&n<=Ha&&Math.ceil(n/st)===a&&typeof t.sha256=="string"&&Rs.test(t.sha256)}function ol(t){if(!nt(t)||!ut(t,["channel","protocolVersion","direction","type","transferId","sessionNonce","payload"])||t.channel!==Ds||t.protocolVersion!==Va||t.direction!=="extension-to-site"||!fa(t.transferId)||!fa(t.sessionNonce))return!1;switch(t.type){case"PIXEL_BEADS_IMPORT_BRIDGE_READY":return nl(t.payload);case"PIXEL_BEADS_IMPORT_MANIFEST":return Is(t.payload)&&t.payload.transferId===t.transferId;case"PIXEL_BEADS_IMPORT_CHUNK":return Ms(t.payload);case"PIXEL_BEADS_IMPORT_COMPLETE":return Bs(t.payload);case"PIXEL_BEADS_IMPORT_ERROR":return nt(t.payload)&&ut(t.payload,["code"])&&rl(t.payload.code);default:return!1}}function Ra(t,a,n,o){return{channel:Ds,protocolVersion:Va,direction:"site-to-extension",type:t,transferId:a,sessionNonce:n,payload:t==="PIXEL_BEADS_IMPORT_REJECTED"?{code:o??"SITE_VALIDATION_FAILED"}:{}}}function il(t){try{const a=new URL(t).searchParams.get(ba);return fa(a)?a:null}catch{return null}}function ll(t){const a=new URL(t);return a.searchParams.delete(ba),`${a.pathname}${a.search}${a.hash}`}async function cl(t){const a=new ArrayBuffer(t.byteLength);new Uint8Array(a).set(t);const n=await crypto.subtle.digest("SHA-256",a);return[...new Uint8Array(n)].map(o=>o.toString(16).padStart(2,"0")).join("")}class Ve extends Error{constructor(a){super(a),this.code=a,this.name="ExtensionImportAssemblyError"}}class dl{#e;#t=new Map;#a;#n=0;constructor(a){if(!Is(a))throw new Ve("TRANSFER_CORRUPTED");this.#e=a}addChunk(a){if(!Ms(a))throw new Ve("TRANSFER_CORRUPTED");const n=Math.ceil(this.#e.file.size/st);if(a.totalChunks!==n||this.#a!==void 0&&a.totalChunks!==this.#a||this.#t.has(a.index))throw new Ve("TRANSFER_CORRUPTED");const o=_s(a.base64);if(!o)throw new Ve("TRANSFER_CORRUPTED");const l=a.index===a.totalChunks-1?this.#e.file.size-(a.totalChunks-1)*st:st;if(o.byteLength!==l)throw new Ve("TRANSFER_CORRUPTED");if(this.#a=a.totalChunks,this.#n+=o.byteLength,this.#n>this.#e.file.size)throw new Ve("IMAGE_TOO_LARGE");return this.#t.set(a.index,o),{receivedChunks:this.#t.size,totalChunks:a.totalChunks}}async complete(a){if(!Bs(a)||a.totalBytes!==this.#e.file.size||a.sha256!==this.#e.file.sha256||a.totalChunks!==this.#a||this.#t.size!==a.totalChunks||this.#n!==a.totalBytes)throw new Ve("TRANSFER_CORRUPTED");const n=new ArrayBuffer(a.totalBytes),o=new Uint8Array(n);let l=0;for(let i=0;iObject.hasOwn(t,o))}function Ta(t){return t==="direct"||t==="visible-screenshot"}function fl(t){return t==="unknown"?!0:typeof t!="string"||!ul.test(t)?!1:t.split(".").every(a=>Number(a)<=65535)}function xl(t,a){if(!hl(a))return!1;switch(t){case"extension_import_opened":return Dt(a,["status","locale","extension_version"])&&(a.status==="waiting"||a.status==="ready"||a.status==="error")&&typeof a.locale=="string"&&ml.has(a.locale)&&fl(a.extension_version);case"extension_import_received":return Dt(a,["capture_method","partial_capture","file_type","size_bucket"])&&Ta(a.capture_method)&&typeof a.partial_capture=="boolean"&&(a.file_type==="jpeg"||a.file_type==="png"||a.file_type==="webp")&&(a.size_bucket==="under_1_mb"||a.size_bucket==="1_to_5_mb"||a.size_bucket==="5_to_10_mb");case"extension_import_failed":return Dt(a,["error_code","capture_method"])&&typeof a.error_code=="string"&&pl.has(a.error_code)&&(Ta(a.capture_method)||a.capture_method==="unknown");case"extension_crop_confirmed":return Dt(a,["capture_method"])&&Ta(a.capture_method);case"pattern_generated":return Dt(a,["entry_source"])&&a.entry_source==="chrome_extension";case"extension_export_completed":return Dt(a,["export_type"])&&(a.export_type==="pdf"||a.export_type==="image"||a.export_type==="svg"||a.export_type==="json")}}function gl(){if(!(typeof window>"u"))return window.gtag}function bl(t){return t==="image/jpeg"?"jpeg":t==="image/png"?"png":"webp"}function yl(t){return t<1024*1024?"under_1_mb":t<=5*1024*1024?"1_to_5_mb":"5_to_10_mb"}function vl(t){const a=new Set;return{track(n,o){if(!xl(n,o)||ss.has(n)&&a.has(n))return!1;const l=gl();if(!l)return!1;try{l("event",n,o)}catch{return!1}return ss.has(n)&&a.add(n),!0}}}const El=750,wl=1e4,Cl=new Set(["en","zh","zh-tw","ja","vi","ko","de"]);function Nl(t){return Cl.has(t)?t:"en"}function jl(t){return t.reason==="too-large"?"IMAGE_TOO_LARGE":t.reason==="unsupported-type"?"UNSUPPORTED_IMAGE":t.reason==="read-error"?"IMAGE_DECODE_FAILED":"SITE_VALIDATION_FAILED"}function _a(t){window.postMessage(t,window.location.origin)}function ma(){const t=new URL(window.location.href);t.searchParams.has(ba)&&window.history.replaceState(window.history.state,"",ll(t.href))}function Sl({locale:t,onFileReady:a}){const[n,o]=r.useState({status:"idle"}),l=r.useRef(void 0),i=r.useRef(a),c=Nl(t);r.useEffect(()=>{i.current=a},[a]),r.useEffect(()=>{const y=new URL(window.location.href);if(!y.searchParams.has(ba))return;const F=il(y.href);if(!F){ma(),o({status:"idle"});return}const A=crypto.randomUUID(),d=vl();let k=!0,v=Promise.resolve(),N,O;const f=()=>{N!==void 0&&clearInterval(N),O!==void 0&&clearTimeout(O),N=void 0,O=void 0},x={transferId:F,sessionNonce:A,analytics:d,stopTimers:f,bridgeReady:!1,failed:!1,finished:!1};l.current=x,o({status:"waiting",transferId:F});const M=(p,g)=>{k&&_a(Ra(p,F,A,g))},D=(p,g)=>{!k||x.failed||x.finished||(x.failed=!0,f(),g&&M("PIXEL_BEADS_IMPORT_REJECTED",p),x.analytics.track("extension_import_opened",{status:"error",locale:c,extension_version:x.manifest?.extensionVersion??"unknown"}),x.analytics.track("extension_import_failed",{error_code:p,capture_method:x.manifest?.capture.method??"unknown"}),o({status:"error",code:p,canReturnToSource:x.bridgeReady}))},_=async p=>{if(!k||p.source!==window||p.origin!==window.location.origin||!ol(p.data)||p.data.transferId!==F||p.data.sessionNonce!==A||x.failed||x.finished)return;const g=p.data;switch(g.type){case"PIXEL_BEADS_IMPORT_BRIDGE_READY":x.bridgeReady=!0,N!==void 0&&(clearInterval(N),N=void 0),ma();return;case"PIXEL_BEADS_IMPORT_MANIFEST":{if(x.manifest||Date.parse(g.payload.expiresAt)<=Date.now()){D(x.manifest?"TRANSFER_CORRUPTED":"TRANSFER_EXPIRED",!0);return}x.manifest=g.payload,x.assembler=new dl(g.payload),x.analytics.track("extension_import_opened",{status:"ready",locale:c,extension_version:g.payload.extensionVersion}),o({status:"receiving",receivedChunks:0,totalChunks:Math.ceil(g.payload.file.size/st)});return}case"PIXEL_BEADS_IMPORT_CHUNK":{if(!x.assembler){D("TRANSFER_CORRUPTED",!0);return}try{const j=x.assembler.addChunk(g.payload);o({status:"receiving",...j})}catch(j){D(j instanceof Ve?j.code:"TRANSFER_CORRUPTED",!0)}return}case"PIXEL_BEADS_IMPORT_COMPLETE":{if(!x.assembler||!x.manifest){D("TRANSFER_CORRUPTED",!0);return}o({status:"validating"});try{const j=await x.assembler.complete(g.payload);if(!k||l.current!==x)return;const V=await i.current(j);if(!k||l.current!==x||x.finished)return;if(!V.ok){D(jl(V),!0);return}x.analytics.track("extension_import_received",{capture_method:x.manifest.capture.method,partial_capture:x.manifest.capture.partialCapture,file_type:bl(x.manifest.file.mimeType),size_bucket:yl(x.manifest.file.size)}),M("PIXEL_BEADS_IMPORT_ACK"),f(),x.finished=!0,o({status:"opening-crop",manifest:x.manifest})}catch(j){D(j instanceof Ve?j.code:"SITE_VALIDATION_FAILED",!0)}return}case"PIXEL_BEADS_IMPORT_ERROR":ma(),D(g.payload.code,!1);return}},$=p=>{v=v.then(()=>_(p)).catch(()=>{D("SITE_VALIDATION_FAILED",!0)})};window.addEventListener("message",$);const L=()=>{M("PIXEL_BEADS_IMPORT_READY")};return L(),N=setInterval(L,El),O=setTimeout(()=>{D("IMPORT_TIMEOUT",!0)},wl),()=>{k=!1,f(),window.removeEventListener("message",$)}},[c]);const h=r.useCallback(()=>{const y=l.current;y&&(y.stopTimers(),y.finished||_a(Ra("PIXEL_BEADS_IMPORT_REJECTED",y.transferId,y.sessionNonce,"SITE_VALIDATION_FAILED")),y.finished=!0,ma(),l.current=void 0,o({status:"idle"}))},[]),u=r.useCallback(()=>{const y=l.current;y&&_a(Ra("PIXEL_BEADS_IMPORT_RETURN_TO_SOURCE",y.transferId,y.sessionNonce))},[]),m=r.useCallback((y,F)=>l.current?.analytics.track(y,F)??!1,[]);return{state:n,manifest:n.status==="opening-crop"?n.manifest:l.current?.manifest,isExtensionEntry:n.status==="opening-crop",cancelImport:h,returnToSource:u,track:m}}const kl={Perler:"Perler",Hama:"Hama","Artkal-S":"Artkal",MARD:"MARD","Hama-Midi":"Hama","Artkal-Midi":"Artkal","Artkal-M-2.6mm":"Artkal","Perler-Midi":"Perler","Ikea-Pyssla":"Ikea",Nabbi:"Nabbi"};function Ls(t){return kl[t]||t}function rs(t=new Date,a=globalThis.crypto.randomUUID()){return{patternId:`pt_${a.replace(/-/g,"")}`,timestamp:t.getTime(),createdAt:t.toISOString()}}function Fl(t){const a=t.patternId||`pt_${t.timestamp}`,n=t.format==="pdf"?"pdf":"png",o=Ls(t.paletteId),l=t.formData?.socialHandle?{platform:t.formData.socialPlatform,handle:t.formData.socialHandle}:void 0,i={id:a,name:t.formData?.name,author:t.formData?.author,public:t.formData?.public??!0,message:t.formData?.message,isOriginal:t.formData?.isOriginal,themes:t.formData?.themes??[],social:l,createdAt:t.createdAt,format:n,materials:{brand:o,totalBeads:t.totalBeads,colors:t.colors.map(h=>({colorCode:h.code||"",colorName:h.name,hex:h.hex,count:h.count}))},source:"pattern-generator"},c=xs({origin:"image-generator",id:a,name:t.formData?.name,createdAt:t.createdAt,grid:{width:t.gridWidth,height:t.gridHeight,cells:t.matrix},palette:{brand:o,...t.paletteCollection?{collection:t.paletteCollection}:{}},...t.beadStyle?{bead:{style:t.beadStyle}}:{}},{maxDimension:Br});return So(c,i)}function Al(t){return t.name.replace(/[\u4e00-\u9fa5]/g,"").trim()||t.id.split(":").pop()||t.id}function Dl(t){return t.map(a=>({...a,name:Al(a)}))}function Pl(t){if(!t.matrix.length)return null;const a=xs({origin:"image-generator",grid:{width:t.gridWidth,height:t.matrix.length,cells:t.matrix},palette:{brand:Ls(t.paletteId),...t.paletteCollection?{collection:t.paletteCollection}:{}},...t.beadStyle?{bead:{style:t.beadStyle}}:{}});try{return to(a,Dl(t.colors),{statisticsOrder:"count-desc-catalog"})}catch(n){if(n instanceof ao&&n.code==="missing-color")return null;throw n}}const Rl={dominant:"zippland",average:"standard",fast:"legacy",soft:"simplified","pixel-detail":"detailed",precise:"detailed"};function Ia(t){return Rl[t]}const os=50,qe=xa((t,a)=>({past:[],present:[],future:[],canUndo:!1,canRedo:!1,push:n=>{const{present:o,past:l}=a(),i=o.length>0?[...l,o]:l,c=i.length>os?i.slice(i.length-os):i;t({past:c,present:n,future:[],canUndo:c.length>0,canRedo:!1})},undo:()=>{const{past:n,present:o,future:l}=a();if(n.length===0)return null;const i=n[n.length-1],c=n.slice(0,-1);return t({past:c,present:i,future:[o,...l],canUndo:c.length>0,canRedo:!0}),i},redo:()=>{const{past:n,present:o,future:l}=a();if(l.length===0)return null;const i=l[0],c=l.slice(1);return t({past:[...n,o],present:i,future:c,canUndo:!0,canRedo:c.length>0}),i},reset:n=>{t({past:[],present:n,future:[],canUndo:!1,canRedo:!1})}}));function is(t,a){if(typeof window>"u")return a;try{const n=localStorage.getItem(t);return n!==null?n==="true":a}catch{return a}}function pa(t,a){try{localStorage.setItem(t,String(a))}catch{}}const Pt=xa((t,a)=>({leftSidebarOpen:!0,rightSidebarOpen:!0,activeMobileTab:null,isProcessing:!1,isSaving:!1,isExporting:!1,isStyleChanging:!1,toggleLeftSidebar:()=>{const n=!a().leftSidebarOpen;pa("pbg-left-sidebar",n),t({leftSidebarOpen:n})},toggleRightSidebar:()=>{const n=!a().rightSidebarOpen;pa("pbg-right-sidebar",n),t({rightSidebarOpen:n})},setLeftSidebarOpen:n=>{pa("pbg-left-sidebar",n),t({leftSidebarOpen:n})},setRightSidebarOpen:n=>{pa("pbg-right-sidebar",n),t({rightSidebarOpen:n})},setActiveMobileTab:n=>t({activeMobileTab:n}),setIsProcessing:n=>t({isProcessing:n}),setIsSaving:n=>t({isSaving:n}),setIsExporting:n=>t({isExporting:n}),setIsStyleChanging:n=>t({isStyleChanging:n}),hydrate:()=>{t({leftSidebarOpen:is("pbg-left-sidebar",!0),rightSidebarOpen:is("pbg-right-sidebar",!0)})}})),Tl={matrix:[],gridWidth:0,gridHeight:0,colorById:new Map,beadStats:[],totalBeads:0};function Ma(t,a,n,o){if(!a.enabled)return t;const l=[],i=new Set;return t.forEach(c=>{const h=[c],u=Vr(c.y,c.x,a,n,o);u&&h.push({x:u.column,y:u.row}),h.forEach(m=>{const y=`${m.x}:${m.y}`;i.has(y)||(i.add(y),l.push(m))})}),l}function _l(t){return new Promise((a,n)=>{const o=new Image;o.onload=()=>a(o),o.onerror=()=>n(new Error("Failed to load cropped image")),o.src=t})}function Il(){const t=de("Generator"),a=de("PerlerBeadArt"),n=ho(),[,o]=r.useTransition(),{editTool:l,selectedColorId:i,setEditTool:c,setSelectedColorId:h}=$e(yt(s=>({editTool:s.editTool,selectedColorId:s.selectedColorId,setEditTool:s.setEditTool,setSelectedColorId:s.setSelectedColorId}))),{matrix:u,gridWidth:m,cellSize:y,cellSizeUnit:F,drawingLayer:A,boardLayer:d,showReferenceGrid:k,showGridNumbers:v,gridGuideSettings:N,beadStyle:O,gridSpacing:f,selectedPalette:x,selectedMardCategory:M,generationPreset:D,backgroundMode:_,setBeadStyle:$}=se(yt(s=>({matrix:s.matrix,gridWidth:s.gridWidth,cellSize:s.cellSize,cellSizeUnit:s.cellSizeUnit,drawingLayer:s.drawingLayer,boardLayer:s.boardLayer,showReferenceGrid:s.showReferenceGrid,showGridNumbers:s.showGridNumbers,gridGuideSettings:s.gridGuideSettings,beadStyle:s.beadStyle,gridSpacing:s.gridSpacing,selectedPalette:s.selectedPalette,selectedMardCategory:s.selectedMardCategory,generationPreset:s.generationPreset,backgroundMode:s.backgroundMode,setBeadStyle:s.setBeadStyle}))),{activeMobileTab:L,isSaving:p,isStyleChanging:g,setActiveMobileTab:j,setIsSaving:V,setIsStyleChanging:K}=Pt(yt(s=>({activeMobileTab:s.activeMobileTab,isSaving:s.isSaving,isStyleChanging:s.isStyleChanging,setActiveMobileTab:s.setActiveMobileTab,setIsSaving:s.setIsSaving,setIsStyleChanging:s.setIsStyleChanging}))),{canUndo:te,canRedo:T}=qe(yt(s=>({canUndo:s.canUndo,canRedo:s.canRedo}))),w=Bi(m,300),[I,Z]=r.useState(!1),[S,ae]=r.useState(null),[re,G]=r.useState("export"),[q,Y]=r.useState(!1),[J,me]=r.useState(!1),[X,be]=r.useState(!1),[Ae,Ie]=r.useState(!1),[ce,De]=r.useState(null),[rt,Le]=r.useState(null),[Pe,Re]=r.useState(()=>Lr(m)),Te=r.useRef(!1),[Ye,_e]=r.useState(!1),[Xe,ye]=r.useState(null),[P,z]=r.useState(!1),[ve,Ee]=r.useState(null),[pe,ue]=r.useState(null),[Rt,U]=r.useState(""),[we,Et]=r.useState([]),[Tt,_t]=r.useState({enabled:!1,text:""}),[Ce,It]=r.useState({source:!1,tools:!1,layers:!1,settings:!0,symmetry:!1,palette:!1,export:!1}),[ot,Mt]=r.useState({format:"image",beadStyle:"square",gridSpacing:"small",showCodes:!0,showStats:!0}),[ie,wt]=r.useState(null),[mt,it]=r.useState(!1),[Bt,Oe]=r.useState(null),[Ct,B]=r.useState(null),W=r.useRef(null),ee=r.useRef(30),oe=r.useRef(null),Ne=r.useRef(0),Ge=r.useRef(async()=>({ok:!1,reason:"aborted"})),ze=r.useRef(!1),he=r.useRef(null),Me=r.useRef("single"),ya=r.useRef(null),Kt=r.useRef(null),Qt=r.useRef(new Set),Nt=r.useRef(!1),Lt=r.useRef(null),Ot=r.useRef(Pe),va=r.useRef(null),{image:xe,setImage:Jt,isProcessing:Be,processImage:Ya}=Lo(),Ea=mt?ie?.grid:void 0,Xa=Ea?.columns??(ie?m:w),Za=Ct?.maximumColors,qa=Ct?.generationMethod&&Ia(Ct.generationMethod)===D?Ct.generationMethod:void 0,Os=r.useCallback(s=>Ge.current(s),[]),{state:Gs,manifest:Gt,isExtensionEntry:Ke,cancelImport:ea,returnToSource:zs,track:lt}=Sl({locale:n,onFileReady:Os}),zt=r.useRef({translate:t,isExtensionEntry:Ke,trackExtensionImport:lt});zt.current={translate:t,isExtensionEntry:Ke,trackExtensionImport:lt};const wa=r.useMemo(()=>Wi(u),[u]),Us=wa.bounds,pt=wa.matrix,jt=wa.width,ta=pt.length,je=!!(xe&&Us),aa=!je||Be||g,Ka=Be||g,Ws=f==="none"?0:f==="small"?1:3,Hs=k&&v?Math.max(In(m),In(u.length)):0,{viewportRef:Qa,boardRef:$s,pan:Ja,userZoom:Ca,zoom:en,isPanning:Vs,setZoomAtViewportCenter:Na,handleWheel:Ys,handleDoubleClick:Xs,handlePointerDown:Zs,handlePointerMove:qs,handlePointerUp:tn,handlePinchStart:Ks,handlePinchMove:Qs,handlePinchEnd:Js}=Hi({enabled:!!(xe&&u.length),resetKey:xe,gridWidth:m,gridHeight:u.length,cellSize:y,gapSize:Ws,coordinateGutter:Hs}),St=r.useCallback(s=>{Re(b=>kn({...b,...s},m,Math.max(1,u.length)))},[m,u.length]),er=r.useCallback(s=>{St({enabled:!0,position:s})},[St]),tr=r.useCallback(()=>{St({enabled:!0}),c("symmetry")},[c,St]);r.useEffect(()=>{Ot.current=Pe},[Pe]),r.useEffect(()=>{Re(s=>kn(s,m,Math.max(1,u.length)))},[m,u.length]),r.useEffect(()=>{u.length>0||l!=="symmetry"||c("brush")},[l,u.length,c]);const ht=r.useCallback(()=>(ee.current+=1,ee.current),[]),ar=r.useCallback(s=>{It(b=>({...b,[s]:!b[s]}))},[]),ft=r.useCallback(s=>{It(b=>({...b,[s]:!1}))},[]),an=r.useCallback(()=>{const s=L==="settings";Te.current=s,s&&j(null),Y(!0)},[L,j]),nr=r.useCallback(s=>{Y(s),!s&&Te.current&&(Te.current=!1,j("settings"))},[j]);r.useEffect(()=>{Pt.getState().hydrate()},[]),r.useEffect(()=>{const s=window.matchMedia("(min-width: 768px)"),b=()=>{s.matches&&j(null)};return b(),s.addEventListener("change",b),()=>s.removeEventListener("change",b)},[j]),r.useEffect(()=>()=>oe.current?.abort(),[]),r.useEffect(()=>{Mt(s=>({...s,beadStyle:O,gridSpacing:f}))},[O,f]);const Q=r.useMemo(()=>{const s=bs[x]??[];if(x!=="MARD")return s;const b=ys[M];if(!b)return s;const C=new Set(b.keys);return s.filter(R=>!!R.code&&C.has(R.code))},[x,M]),Qe=r.useMemo(()=>new Map(Q.map(s=>[s.id,s])),[Q]),Se=r.useMemo(()=>Pl({matrix:pt,gridWidth:jt,paletteId:x,paletteCollection:x==="MARD"?M:x,beadStyle:O,colors:Q}),[Q,O,jt,pt,M,x]),ct=Se||Tl,Ue=r.useMemo(()=>{if(!u.length)return[];const s={};return u.flat().forEach(b=>{b&&(s[b]=(s[b]||0)+1)}),Q.filter(b=>s[b.id]).map(b=>({...b,name:b.name.replace(/[\u4e00-\u9fa5]/g,"").trim()||b.id.split(":").pop()||b.id,count:s[b.id]})).sort((b,C)=>C.count-b.count)},[u,Q]),nn=r.useMemo(()=>Ue.reduce((s,b)=>s+b.count,0),[Ue]),sr=r.useMemo(()=>ce&&Ue.some(s=>s.id===ce)?ce:null,[Ue,ce]),sn=r.useMemo(()=>Dn(we,Ue.map(s=>s.id),Q.map(s=>s.id)),[Q,Ue,we]),ja=r.useMemo(()=>sn.map(s=>Qe.get(s)).filter(s=>s!==void 0),[Qe,sn]),rr=x==="MARD"?`MARD · ${M}`:Oa[x]||x,or=r.useCallback(s=>{h(s),c("brush")},[c,h]);r.useEffect(()=>{Ke||(ze.current=!1)},[Ke]),r.useEffect(()=>{B(s=>{const b=s?.generationMethod;return!b||Ia(b)===D?s:{maximumColors:s.maximumColors}})},[D]),r.useEffect(()=>{!xe||Q.length===0||Ya(xe,Xa,Q,{preset:D,backgroundMode:_,maximumColors:Za,generationMethod:qa},Ea).then(({matrix:s,width:b})=>{Ee(null);const C=se.getState();C.gridWidth!==b&&C.setGridWidth(b),C.setMatrix(s),qe.getState().reset(s);const R=$e.getState().selectedColorId;(!R||!Q.some(H=>H.id===R))&&Q.length>0&&$e.getState().setSelectedColorId(Q[0].id),zt.current.isExtensionEntry&&!ze.current&&(ze.current=!0,zt.current.trackExtensionImport("pattern_generated",{entry_source:"chrome_extension"}))}).catch(s=>{if(!(s instanceof Error&&s.name==="AbortError")){if(s instanceof Error&&s.message===Io){Ee(zt.current.translate("emptyPatternError")),se.getState().setMatrix([]),qe.getState().reset([]),wt(null),it(!1),Oe(null),Jt(null);return}console.error("Failed to process image:",s),Ee(zt.current.translate("processingFailed"))}})},[xe,Xa,Ea,Q,D,_,Za,qa,Ya,Jt]),r.useEffect(()=>{Q.length>0&&i&&!Q.some(s=>s.id===i)&&h(Q[0].id)},[Q,i,h]),r.useEffect(()=>{const s=Q.map(b=>b.id);Et(b=>Dn(b,[],s))},[Q]),r.useEffect(()=>{!i||!Qe.has(i)||Et(s=>no(s,i))},[Qe,i]),r.useEffect(()=>{!ce||Qe.has(ce)||De(null)},[Qe,ce]);const na=r.useMemo(()=>i&&Q.find(s=>s.id===i)||null,[Q,i]),rn=r.useCallback(s=>{h(s),De(b=>b===s?null:s)},[h]),sa=r.useCallback(s=>{const b=he.current;if(b===null||s.length===0)return;const C=se.getState(),R=C.matrix;let H=R;const fe=new Map;Ma(s,Ot.current,R[0]?.length||m,R.length).forEach(({x:ge,y:Ze})=>{const dt=`${ge}:${Ze}`;if(Qt.current.has(dt))return;Qt.current.add(dt);const At=fe.get(Ze)||R[Ze];if(!At||At[ge]===void 0||At[ge]===b)return;H===R&&(H=[...R]);const xt=fe.get(Ze)||[...At];xt[ge]=b,fe.set(Ze,xt),H[Ze]=xt,Nt.current=!0}),H!==R&&C.setMatrix(H)},[m]),ra=r.useCallback(s=>{const b=he.current,C=ya.current,R=Lt.current;if(b===null||!C||!R)return;let H=Or(R,C.x,C.y,s.x,s.y,b);if(Ot.current.enabled){const fe=[],le=Math.min(C.x,s.x),ge=Math.max(C.x,s.x),Ze=Math.min(C.y,s.y),dt=Math.max(C.y,s.y);for(let xt=Ze;xt<=dt;xt+=1)for(let Aa=le;Aa<=ge;Aa+=1)fe.push({x:Aa,y:xt});const At=Ma(fe,Ot.current,R[0]?.length||m,R.length);H=Fn(H,At,b)}Nt.current=H!==R,se.getState().setMatrix(H)},[m]),oa=r.useCallback(()=>{he.current=null,Me.current="single",ya.current=null,Kt.current=null,Qt.current.clear(),Nt.current=!1,Lt.current=null,Le(null)},[]),ir=r.useCallback(()=>{Nt.current&&qe.getState().push(se.getState().matrix),oa()},[oa]),lr=r.useCallback(()=>{Nt.current&&Lt.current&&se.getState().setMatrix(Lt.current),oa()},[oa]),ia=r.useCallback((s,b)=>{const C=se.getState().matrix[b]?.[s];C&&$e.getState().setSelectedColorId(C)},[]),cr=r.useCallback((s,b)=>{if(Pt.getState().isStyleChanging)return;const C=$e.getState();if(C.editTool==="eyedropper"){ia(s,b);return}if(C.editTool==="symmetry")return;const R=C.editTool==="eraser"?"":C.selectedColorId;if(R!==null){if(Lt.current=se.getState().matrix,he.current=R,Me.current=C.fillMode,ya.current={x:s,y:b},Kt.current={x:s,y:b},Qt.current.clear(),Nt.current=!1,C.fillMode==="rectangle"){Le({start:{x:s,y:b},end:{x:s,y:b},action:C.editTool==="eraser"?"erase":"fill",color:R?Qe.get(R)?.hex:null}),ra({x:s,y:b});return}sa([{x:s,y:b}])}},[Qe,sa,ra,ia]),dr=r.useCallback((s,b)=>{if(he.current===null)return;const C={x:s,y:b};if(Me.current==="rectangle"){Le(H=>H&&{...H,end:C}),ra(C);return}const R=Kt.current;sa(R?Gr(R,C):[C]),Kt.current=C},[sa,ra]),ur=r.useCallback((s,b)=>{if(Pt.getState().isStyleChanging)return;const C=$e.getState();if(C.editTool==="eyedropper"){ia(s,b);return}if(C.editTool==="symmetry")return;const R=C.editTool==="eraser"?"":C.selectedColorId,H=se.getState();if(R===null||!H.matrix[b])return;const fe=Ma([{x:s,y:b}],Ot.current,H.matrix[0]?.length||m,H.matrix.length),le=Fn(H.matrix,fe,R);le!==H.matrix&&(H.setMatrix(le),qe.getState().push(le))},[m,ia]),on=r.useCallback(()=>{const s=qe.getState().undo();s&&se.getState().setMatrix(s)},[]),ln=r.useCallback(()=>{const s=qe.getState().redo();s&&se.getState().setMatrix(s)},[]),cn=r.useCallback(()=>{const s=se.getState().matrix;if(!s.length)return;const b=s.map(C=>[...C].reverse());se.getState().setMatrix(b),qe.getState().push(b)},[]),dn=r.useCallback((s,b)=>{const C=se.getState().matrix;if(!C.length)return;const R=zr(C,s);if(R===C)return;se.getState().setMatrix(R),qe.getState().push(R);const H=$e.getState().selectedColorId;if(!b&&H&&s.includes(H)){const fe=new Set(R.flat().filter(Boolean)),le=Q.find(ge=>fe.has(ge.id));$e.getState().setSelectedColorId(le?.id??null)}bt.success(t("colorDeleted")||"Color deleted")},[Q,t]),mr=r.useCallback(s=>{dn(s,!1)},[dn]),pr=r.useCallback((s,b)=>{const C=se.getState().matrix;if(!C.length||s===b)return;const R=Ur(C,s,b);R!==C&&(se.getState().setMatrix(R),qe.getState().push(R),$e.getState().selectedColorId===s&&$e.getState().setSelectedColorId(b),bt.success(t("colorReplaced")||"Color replaced"))},[t]),la=r.useCallback(()=>{_e(!1),ye(null),z(!1)},[]),hr=r.useCallback(async(s,b,C,R)=>{try{const[H,fe]=await Promise.all([_l(s),b==="pixel-grid"?Wr(s):Promise.resolve(null)]),le=fe?.analysis?so(fe.analysis):null,ge=ro(R?.subjectScale);b==="pixel-grid"&&le&&ge?(wt({grid:le,photoGridWidth:m}),it(!0)):(wt(null),it(!1)),B(C||null),C&&se.getState().setGenerationPreset(Ia(C.generationMethod)),Oe(b),Ee(null),Jt(H),Gt&<("extension_crop_confirmed",{capture_method:Gt.capture.method}),la()}catch(H){throw console.error(H),Ee(t("uploadReadError")),H}},[la,Gt,m,lt,Jt,t]),un=r.useCallback(s=>{ie&&s!==ie.grid.columns&&it(!1)},[ie]),fr=r.useCallback(()=>{ie&&(it(!1),se.getState().setGridWidth(ie.photoGridWidth))},[ie]),xr=r.useCallback(()=>{ie&&(it(!0),se.getState().setGridWidth(ie.grid.columns))},[ie]),Sa=r.useCallback((s,b)=>{b==="manual"&&ea();let C=null,R=null;if(typeof s=="string"?R=s:s instanceof File?C=s:"target"in s&&s.target.files&&(C=s.target.files[0],s.target.value=""),!C&&!R)return Promise.resolve({ok:!1,reason:"aborted"});const H=Ne.current+1;if(Ne.current=H,oe.current?.abort(),R)return oe.current=null,Ee(null),Pt.getState().setActiveMobileTab(null),z(!0),ye(R),_e(!0),Promise.resolve({ok:!0});if(C){const fe=Hr(C);if(fe==="too-large")return z(!1),Ee(t("uploadTooLarge",{size:Wa})),Promise.resolve({ok:!1,reason:"too-large"});if(fe==="unsupported-type")return z(!1),Ee(t("uploadUnsupportedType")),Promise.resolve({ok:!1,reason:"unsupported-type"});Ee(null),Pt.getState().setActiveMobileTab(null),z(!0);const le=new FileReader;return oe.current=le,new Promise(ge=>{le.onload=Ze=>{if(oe.current!==le||Ne.current!==H){ge({ok:!1,reason:"aborted"});return}oe.current=null;const dt=Ze.target?.result;if(typeof dt=="string"&&dt!==""){ye(dt),_e(!0),ge({ok:!0});return}z(!1),Ee(t("uploadReadError")),ge({ok:!1,reason:"read-error"})},le.onerror=()=>{oe.current===le&&(oe.current=null,z(!1),Ee(t("uploadReadError"))),ge({ok:!1,reason:"read-error"})},le.onabort=()=>{oe.current===le&&(oe.current=null,z(!1)),ge({ok:!1,reason:"aborted"})},le.readAsDataURL(C)})}return Promise.resolve({ok:!1,reason:"aborted"})},[ea,t]);Ge.current=s=>Sa(s,"extension");const ka=r.useCallback(s=>{Sa(s,"manual")},[Sa]),mn=r.useCallback(()=>{la(),ea()},[ea,la]),gr=r.useMemo(()=>{const s=n==="zh"||n.startsWith("zh-");return{patternTitle:t("patternTitle"),generatedFor:t("generatedFor"),gridSize:t("gridSize"),colorShoppingList:t("colorShoppingList"),beadsCount:t("beadsCount"),total:t("total"),rowsLabel:t("rowsLabel"),colsLabel:t("colsLabel"),pdfZoomHint:t("pdfZoomHint"),savingPattern:t("savingPattern"),generatingImage:t("generatingImage"),generatingPdf:t("generatingPdf"),downloading:t("downloading"),statsTitle:t("statsTitle"),brandName:n==="zh-tw"?"拼豆藝術":s?"拼豆艺术":"PixelBeads"}},[n,t]),pn=r.useCallback((s,b,C)=>Fl({format:s,formData:b,matrix:pt,gridWidth:jt,gridHeight:ta,paletteId:x,paletteCollection:x==="MARD"?M:x,beadStyle:O,totalBeads:nn,colors:Ue,patternId:C.patternId,timestamp:C.timestamp,createdAt:C.createdAt}),[Ue,O,ta,jt,pt,M,x,nn]),{exportToPDF:hn,exportToImage:fn,exportToSVG:xn,exportToJSON:gn,activeExportFormat:bn,exportStatusLabel:br,isExporting:kt,usesLargePdfPage:yr}=yo({matrix:ct.matrix,gridWidth:ct.gridWidth,selectedPalette:x,colorById:ct.colorById,beadStats:ct.beadStats,totalBeads:ct.totalBeads,cellSizeUnit:F,cellSize:y,exportConfig:ot,watermark:Tt,translations:gr}),yn=r.useCallback(s=>{Se&&(ue(null),G("export"),ae(s),Mt(b=>({...b,format:s,showCodes:s==="pdf"?!0:b.showCodes})),Z(!0))},[Se]),vr=r.useCallback(()=>{Se&&(va.current=rs(),ue(null),ae("image"),G("publish"),Mt(s=>({...s,format:"image"})),Z(!0))},[Se]),Er=r.useCallback(()=>{j(null),me(!0)},[j]),ca=r.useCallback(async s=>{s==="pdf"&&await hn(),s==="image"&&await fn(),s==="svg"&&await xn(),s==="json"&&await gn()},[fn,gn,hn,xn]),Ft=r.useCallback(()=>{Z(!1),ae(null),G("export"),ue(null)},[]),wr=r.useCallback(s=>{if(s){Z(!0);return}Ft()},[Ft]),Cr=r.useCallback(async s=>{if(!S||!Se)return;const b=S,C=va.current||rs();va.current=C,ue(null),V(!0);try{const R=pn(b,s,C),H=await zi({pixels:pt,width:jt,height:ta});if(!await vo(R,H)){bt.error(t("failedToSave")),ue(t("failedToSave"));return}bt.success(t("savedToLibrary"))}catch(R){console.error("Failed to save:",R),bt.error(t("failedToSave")),ue(t("failedToSave"));return}finally{V(!1)}try{await ca(b),Ke&<("extension_export_completed",{export_type:b}),bt.success(t("downloadStarted")),Ft()}catch(R){console.error("Failed to export pattern:",R),ue(t("exportFailed"))}},[S,Se,ta,jt,pt,pn,t,ca,Ft,V,Ke,lt]),Nr=r.useCallback(async()=>{if(!S||!Se)return;const s=S;ue(null);try{await ca(s),Ke&<("extension_export_completed",{export_type:s}),bt.success(t("downloadStarted")),Ft()}catch(b){console.error("Failed to export pattern:",b),ue(t("exportFailed"))}},[S,Se,ca,Ft,t,Ke,lt]),vn=r.useCallback(s=>{K(!0),o(()=>{$(s),setTimeout(()=>K(!1),300)})},[$,K]),jr=r.useCallback(s=>{j(L===s?null:s)},[L,j]),Fa=r.useCallback((s="compact")=>e.jsxs("div",{className:s==="dialog"?"space-y-2":"space-y-1.5",children:[e.jsx("span",{className:s==="dialog"?"block text-xs font-black text-[#2E261F] sm:text-sm":"text-[10px] font-bold uppercase text-[#5A4738]",children:t("beadStyle")}),e.jsx("div",{className:s==="dialog"?"flex min-w-0 flex-1 overflow-hidden rounded-full border border-[#D8CBB9] bg-white":"flex gap-1.5",children:["square","round","hollow"].map(b=>e.jsx("button",{type:"button",onClick:()=>vn(b),"aria-pressed":O===b,className:ne("transition-all focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-[#006B5F]",s==="dialog"?"min-h-11 flex-auto whitespace-nowrap px-2 text-xs font-black lg:min-h-10":"flex-auto whitespace-nowrap rounded-lg px-1 py-1.5 text-[9px] font-bold uppercase tracking-wider",O===b?s==="dialog"?"bg-[#087B70] text-white shadow-[0_8px_18px_rgba(0,107,95,0.18)]":"bg-[#3E2A1E] text-white shadow-lg":s==="dialog"?"bg-white text-[#5A4738] hover:bg-[#F7F1E1] hover:text-[#3E2A1E]":"bg-[#F7F1E1] text-[#5A4738] hover:bg-[#F0EEE8] hover:text-[#3E2A1E]"),children:t(`beadStyle${b.charAt(0).toUpperCase()+b.slice(1)}`)},b))})]}),[O,vn,t]),En=s=>e.jsxs("div",{className:"flex w-full items-start gap-2",children:[e.jsxs("button",{type:"button",disabled:!je||!Se||kt,onClick:()=>{s==="mobile"&&j(null),vr()},className:ne("flex min-w-0 flex-1 items-center justify-center gap-1.5 rounded-xl border border-[#79CFC2] bg-[#F0FBF9] px-2 text-[clamp(0.72rem,2vw,0.8rem)] font-black leading-tight text-[#176E64] transition hover:border-[#32B8A6] hover:bg-[#E1F7F3] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#168B7D] focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 sm:gap-2 sm:px-3",s==="mobile"?"min-h-12":"min-h-11"),children:[e.jsx(Ga,{className:"h-4 w-4 shrink-0","aria-hidden":"true"}),e.jsx("span",{className:"min-w-0 text-balance",children:t("publishToGallery")})]}),e.jsx("div",{className:"flex min-w-[34%] max-w-[48%] shrink-0 justify-end",children:e.jsx("button",{type:"button",onClick:Er,"aria-label":t("joinAndroidBeta"),className:"group flex min-h-11 max-w-full touch-manipulation items-start justify-end rounded-full px-0.5 py-1 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#168B7D] focus-visible:ring-offset-2",children:e.jsxs("span",{className:"flex max-w-full items-center gap-1 rounded-full border border-[#CFC4B2] bg-white/80 px-[clamp(0.45rem,1.2vw,0.7rem)] py-2 text-[clamp(0.68rem,1.5vw,0.78rem)] font-bold leading-none text-[#655A4D] shadow-[0_6px_14px_rgba(62,42,30,0.06)] transition group-hover:border-[#79CFC2] group-hover:bg-[#F0FBF9] group-hover:text-[#176E64]",children:[e.jsx("span",{"aria-hidden":"true",className:"shrink-0 font-black text-[#168B7D]",children:"?"}),e.jsx("span",{className:"min-w-0 whitespace-nowrap",children:t("joinAndroidBeta")})]})})})]});return e.jsxs("div",{className:"flex h-[calc(100dvh-65px)] flex-col overflow-hidden bg-[#F7F1E1] pb-16 font-sans text-[#3E2A1E] selection:bg-[#3E2A1E] selection:text-white lg:flex-row lg:pb-0",children:[e.jsx(tt,{open:L==="tools",onOpenChange:s=>!s&&j(null),children:e.jsxs(at,{side:"bottom",className:"max-h-[82dvh] overflow-y-auto border-[#D8CBB9] bg-[#FFFDF8] p-0","aria-describedby":"tools-description",children:[e.jsxs("div",{className:"border-b border-[#E7DDCF] px-5 py-4 pr-14",children:[e.jsx(Je,{className:"text-left text-lg font-black text-[#3E2A1E]",children:t("editTools")}),e.jsx(et,{id:"tools-description",className:"mt-1 text-left text-xs font-semibold leading-5 text-[#8A7768]",children:t("editToolsDescription")})]}),e.jsxs("div",{className:"space-y-5 p-4",children:[e.jsx(Qn,{activePalette:Q,selectedColorId:i,onOpenPalette:()=>{j(null),be(!0)},onOpenSourceColorSampler:()=>{j(null),Ie(!0)},sourceColorSamplerDisabled:!xe,actionsDisabled:aa}),e.jsxs("section",{className:"border-t border-[#E7DDCF] pt-4","aria-labelledby":"generator-mobile-commands-heading",children:[e.jsx("h3",{id:"generator-mobile-commands-heading",className:"mb-2 text-[10px] font-black uppercase tracking-[0.16em] text-[#8F7E6F]",children:t("commands")}),e.jsx(Jn,{onMirror:cn,onCleanupClick:an,onUndo:on,onRedo:ln,canUndo:te,canRedo:T,actionsDisabled:aa,historyActionsDisabled:Ka,showHeading:!1})]})]})]})}),e.jsx(tt,{open:L==="settings",onOpenChange:s=>!s&&j(null),children:e.jsxs(at,{side:"left",className:"w-[85vw] sm:w-[350px] p-0 bg-white","aria-describedby":"settings-description",children:[e.jsx(Je,{className:"sr-only",children:t("generatePanel")}),e.jsx(et,{id:"settings-description",className:"sr-only",children:t("settingsDescription")}),e.jsx(Ho,{handleImageUpload:ka,hasManualEdits:te,hasPattern:je,inputId:"mobile-upload",onGridWidthApplied:un,uploadError:xe?ve:null})]})}),e.jsx(tt,{open:L==="layers",onOpenChange:s=>!s&&j(null),children:e.jsxs(at,{side:"left",className:"w-[85vw] max-w-[380px] overflow-y-auto border-[#D8CBB9] bg-[#FFFDF8] p-0","aria-describedby":"layers-description",children:[e.jsxs("div",{className:"border-b border-[#E7DDCF] px-5 py-4 pr-14",children:[e.jsx(Je,{className:"text-left text-lg font-black text-[#3E2A1E]",children:t("layers")}),e.jsx(et,{id:"layers-description",className:"mt-1 text-left text-xs font-semibold leading-5 text-[#8A7768]",children:t("layersDescription")})]}),e.jsx("div",{className:"p-4",children:e.jsx(Wn,{})})]})}),e.jsx(tt,{open:L==="symmetry",onOpenChange:s=>!s&&j(null),children:e.jsxs(at,{side:"bottom",className:"max-h-[78dvh] overflow-y-auto border-[#D8CBB9] bg-[#FFFDF8] p-0","aria-describedby":"symmetry-description",children:[e.jsxs("div",{className:"border-b border-[#E7DDCF] px-5 py-4 pr-14",children:[e.jsx(Je,{className:"text-left text-lg font-black text-[#3E2A1E]",children:a("symmetryTitle")}),e.jsx(et,{id:"symmetry-description",className:"mt-1 text-left text-xs font-semibold leading-5 text-[#8A7768]",children:a("symmetryDescription")})]}),e.jsx("div",{className:"p-4",children:e.jsx(Pn,{gridWidth:m,gridHeight:Math.max(1,u.length),symmetry:Pe,placementActive:l==="symmetry",onSymmetryChange:St,onPlacementActiveChange:s=>c(s?"symmetry":"brush")})})]})}),e.jsx(tt,{open:L==="palette",onOpenChange:s=>!s&&j(null),children:e.jsxs(at,{side:"bottom",className:"h-[82dvh] overflow-hidden bg-white p-0","aria-describedby":"palette-description",children:[e.jsx(Je,{className:"sr-only",children:t("colorStatistics")}),e.jsx(et,{id:"palette-description",className:"sr-only",children:t("colorStatisticsDescription")}),e.jsx(Kn,{activePalette:Q,beadStats:Ue,selectedColorId:ce,onColorSelect:rn,onColorClear:()=>De(null),className:"flex w-full border-0 shadow-none"})]})}),e.jsx(tt,{open:L==="export",onOpenChange:s=>!s&&j(null),children:e.jsxs(at,{side:"bottom",className:"max-h-[72dvh] overflow-y-auto border-[#D8CBB9] bg-[#FFFDF8] p-0","aria-describedby":"mobile-export-description",children:[e.jsxs("div",{className:"border-b border-[#E7DDCF] px-5 py-4 pr-14",children:[e.jsx(Je,{className:"text-left text-lg font-black text-[#3E2A1E]",children:t("export")}),e.jsx(et,{id:"mobile-export-description",className:"mt-1 text-left text-xs font-semibold leading-5 text-[#8A7768]",children:t("exportFormatDescription")})]}),e.jsxs("div",{className:"space-y-5 p-4",children:[Fa(),e.jsx(Rn,{ariaLabel:t("export"),activeFormat:bn,disabled:!je||!Se||kt,formatLabels:{image:t("downloadFormat",{format:"PNG"}),pdf:t("downloadFormat",{format:"PDF"})},onSelect:s=>{j(null),yn(s)}}),e.jsx("div",{className:"border-t border-[#E7DDCF] pt-4",children:En("mobile")})]})]})}),e.jsx(Vo,{openPanels:Ce,onToggle:ar,paletteDisabled:!je||Be,symmetryDisabled:!je||Be,exportDisabled:!je||!Se||kt}),e.jsxs("main",{ref:W,className:"relative flex min-w-0 flex-1 flex-col overflow-hidden bg-[#F7F1E1]",children:[e.jsx(gt,{id:"generator-source-panel",open:Ce.source,title:t("sourcePanel"),dragLabel:t("dragPanel",{panel:t("sourcePanel")}),minimizeLabel:t("minimizePanel",{panel:t("sourcePanel")}),initialPlacement:"top-left",containerRef:W,getNextZIndex:ht,onMinimize:()=>ft("source"),className:"w-[340px]",children:e.jsx("div",{className:"p-4",children:e.jsx(Cs,{handleImageUpload:ka,inputId:"desktop-floating-upload",showHeading:!1,uploadError:xe?ve:null})})}),e.jsx(gt,{id:"generator-layers-panel",open:Ce.layers,title:t("layers"),dragLabel:t("dragPanel",{panel:t("layers")}),minimizeLabel:t("minimizePanel",{panel:t("layers")}),initialPlacement:"top-left",initialOffsetY:170,containerRef:W,getNextZIndex:ht,onMinimize:()=>ft("layers"),className:"w-[340px]",children:e.jsx("div",{className:"p-3",children:e.jsx(Wn,{})})}),e.jsx(gt,{id:"generator-tools-panel",open:Ce.tools,title:t("editTools"),dragLabel:t("dragPanel",{panel:t("editTools")}),minimizeLabel:t("minimizePanel",{panel:t("editTools")}),initialPlacement:"top-left",initialOffsetX:450,initialOffsetY:64,containerRef:W,getNextZIndex:ht,onMinimize:()=>ft("tools"),className:"w-[400px]",children:e.jsx("div",{className:"p-3",children:e.jsx(Qn,{activePalette:Q,selectedColorId:i,onOpenPalette:()=>be(!0),onOpenSourceColorSampler:()=>Ie(!0),sourceColorSamplerDisabled:!xe,actionsDisabled:aa})})}),e.jsx(gt,{id:"generator-settings-panel",open:Ce.settings,title:t("generatePanel"),dragLabel:t("dragPanel",{panel:t("generatePanel")}),minimizeLabel:t("minimizePanel",{panel:t("generatePanel")}),initialPlacement:"top-left",initialOffsetY:64,containerRef:W,getNextZIndex:ht,onMinimize:()=>ft("settings"),className:"w-[380px]",children:e.jsx("div",{className:"p-4",children:e.jsx(Ns,{hasManualEdits:te,hasPattern:je,onGridWidthApplied:un,showHeading:!1})})}),e.jsx(gt,{id:"generator-symmetry-panel",open:Ce.symmetry,title:a("symmetryTitle"),dragLabel:t("dragPanel",{panel:a("symmetryTitle")}),minimizeLabel:t("minimizePanel",{panel:a("symmetryTitle")}),initialPlacement:"top-left",initialOffsetX:360,initialOffsetY:260,containerRef:W,getNextZIndex:ht,onMinimize:()=>ft("symmetry"),className:"w-[360px]",children:e.jsx("div",{className:"p-4",children:e.jsx(Pn,{gridWidth:m,gridHeight:Math.max(1,u.length),symmetry:Pe,placementActive:l==="symmetry",onSymmetryChange:St,onPlacementActiveChange:s=>c(s?"symmetry":"brush")})})}),e.jsx(gt,{id:"generator-palette-panel",open:Ce.palette,title:t("materialsPanel"),dragLabel:t("dragPanel",{panel:t("materialsPanel")}),minimizeLabel:t("minimizePanel",{panel:t("materialsPanel")}),initialPlacement:"top-right",initialOffsetY:260,containerRef:W,getNextZIndex:ht,onMinimize:()=>ft("palette"),className:"h-[calc(100%_-_1.5rem)] w-[430px] max-h-[760px]",children:e.jsx(Kn,{activePalette:Q,beadStats:Ue,selectedColorId:ce,onColorSelect:rn,onColorClear:()=>De(null),className:"flex min-h-0 w-full flex-1 border-0 shadow-none"})}),e.jsx(gt,{id:"generator-export-panel",open:Ce.export,title:t("export"),dragLabel:t("dragPanel",{panel:t("export")}),minimizeLabel:t("minimizePanel",{panel:t("export")}),initialPlacement:"top-left",initialOffsetX:450,initialOffsetY:440,containerRef:W,getNextZIndex:ht,onMinimize:()=>ft("export"),className:"w-[340px]",children:e.jsxs("div",{className:"space-y-4 p-4",children:[Fa(),e.jsx(Rn,{ariaLabel:t("export"),activeFormat:bn,disabled:!je||!Se||kt,formatLabels:{image:t("downloadFormat",{format:"PNG"}),pdf:t("downloadFormat",{format:"PDF"})},onSelect:yn}),e.jsx("div",{className:"border-t border-[#E7DDCF] pt-4",children:En("desktop")})]})}),je&&e.jsx("div",{className:"absolute left-1/2 top-3 z-20 hidden w-[320px] -translate-x-1/2 rounded-2xl border border-[#D8CBB9]/80 bg-white/95 p-2 shadow-lg backdrop-blur lg:block",children:e.jsx(Jn,{onMirror:cn,onCleanupClick:an,onUndo:on,onRedo:ln,canUndo:te,canRedo:T,actionsDisabled:aa,historyActionsDisabled:Ka,showHeading:!1})}),je&&na&&e.jsxs("div",{className:"absolute left-4 top-4 z-20 flex min-h-11 items-center gap-2 rounded-xl border border-[#D8CBB9]/70 bg-white/95 px-3 py-2 shadow-lg backdrop-blur-sm",role:"status","aria-live":"polite",children:[e.jsx("span",{className:"h-7 w-7 rounded-lg border-2 border-white shadow-[0_0_0_1px_#D8CBB9]",style:{backgroundColor:na.hex},"aria-hidden":"true"}),e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block text-[9px] font-bold uppercase tracking-wide text-[#8F7E6F]",children:t("selectedColor")}),e.jsx("span",{className:"block max-w-28 truncate text-xs font-black text-[#3E2A1E]",children:na.code||na.name})]})]}),je&&ja.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"absolute bottom-3 left-1/2 z-20 hidden max-w-[calc(100%_-_1.5rem)] -translate-x-1/2 lg:block",children:e.jsx(Tn,{colors:ja,selectedColorId:i,onColorSelect:s=>h(s),onOpenPalette:()=>be(!0),disabled:Be||g,variant:"desktop"})}),e.jsx("div",{className:"absolute inset-x-3 bottom-3 z-20 flex justify-center lg:hidden",children:e.jsx(Tn,{colors:ja,selectedColorId:i,onColorSelect:s=>h(s),onOpenPalette:()=>be(!0),disabled:Be||g,variant:"mobile"})})]}),je&&l==="symmetry"&&e.jsx("div",{className:"pointer-events-none absolute left-1/2 top-20 z-20 -translate-x-1/2 rounded-full border border-[#EAB4C8] bg-[#FFF5F8]/95 px-4 py-2 text-center text-[11px] font-black text-[#A9305E] shadow-lg backdrop-blur-sm",role:"status","aria-live":"polite",children:a("positionSymmetryHint")}),xe&&ie&&e.jsxs("div",{className:"absolute left-1/2 top-20 z-30 flex max-w-[calc(100%_-_2rem)] -translate-x-1/2 items-center gap-2 rounded-xl border border-[#79CFC2] bg-[#F0FBF9]/95 px-3 py-2 text-[#176E64] shadow-lg backdrop-blur-sm",role:"status","aria-live":"polite",children:[e.jsx($r,{className:"h-4 w-4 shrink-0","aria-hidden":"true"}),e.jsx("span",{className:"min-w-0 text-[11px] font-black leading-4",children:mt?t("pixelGridAligned",{columns:ie.grid.columns,rows:ie.grid.rows,confidence:Math.round(ie.grid.confidence*100)}):t("pixelGridAvailable",{columns:ie.grid.columns,rows:ie.grid.rows})}),e.jsx("button",{type:"button",disabled:Be,onClick:mt?fr:xr,className:"min-h-8 shrink-0 rounded-lg border border-[#79CFC2] bg-white px-2 text-[10px] font-black text-[#176E64] transition hover:bg-[#E1F7F3] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#168B7D] disabled:cursor-not-allowed disabled:opacity-50",children:t(mt?"pixelGridUsePhoto":"pixelGridUseDetected")})]}),xe&&u.length>0&&e.jsxs("div",{className:"absolute right-4 top-4 z-20 flex items-center gap-2 rounded-lg border border-[#D8CBB9]/50 bg-white/90 p-2 shadow-lg backdrop-blur-sm",children:[e.jsx("span",{className:"text-[10px] font-medium text-[#8F7E6F]",children:t("zoom")}),e.jsx("button",{type:"button",onClick:()=>Na(Math.round((Ca-.1)*10)/10),className:"p-1 hover:bg-[#F7F1E1] rounded text-[#8F7E6F] hover:text-[#3E2A1E] transition-colors","aria-label":t("zoomOut"),children:e.jsx(fo,{size:14})}),e.jsx("input",{type:"range",min:"0.5",max:"3",step:"0.1",value:Ca,onChange:s=>Na(parseFloat(s.target.value)),className:"w-20 h-1.5 bg-[#F0EEE8] rounded-lg appearance-none cursor-pointer accent-[#3E2A1E]"}),e.jsx("button",{type:"button",onClick:()=>Na(Math.round((Ca+.1)*10)/10),className:"p-1 hover:bg-[#F7F1E1] rounded text-[#8F7E6F] hover:text-[#3E2A1E] transition-colors","aria-label":t("zoomIn"),children:e.jsx(xo,{size:14})}),e.jsxs("span",{className:"text-[10px] w-8 text-right font-mono text-[#5A4738]",children:[Math.round(en*100),"%"]})]}),e.jsxs("div",{ref:Qa,className:"relative flex flex-1 overflow-auto overscroll-contain p-6 lg:p-12",onWheel:Ys,children:[xe&&u.length>0&&e.jsx("div",{className:`absolute inset-0 z-0 touch-none ${Vs?"cursor-grabbing":"cursor-grab"}`,onPointerDown:Zs,onPointerMove:qs,onPointerUp:tn,onPointerCancel:tn,onDoubleClick:Xs,"aria-hidden":"true"}),xe?e.jsxs("div",{ref:$s,className:"relative z-10 m-auto inline-block shrink-0 cursor-auto will-change-transform",style:{transform:`translate3d(${Ja.x}px, ${Ja.y}px, 0)`},children:[u.length>0&&e.jsx("div",{children:e.jsx(go,{matrix:u,gridWidth:m,cellSize:y,showGrid:d.visible,showBeadCodes:!1,showReferenceGrid:k,showGridNumbers:v,gridGuideSettings:N,colorById:Qe,onCellClick:ur,onCellDrawStart:cr,onCellDrawMove:dr,onCellDrawEnd:ir,onCellDrawCancel:lr,onPinchStart:Ks,onPinchMove:Qs,onPinchEnd:Js,viewportRef:Qa,gridAriaLabel:t("patternGridAria"),canvasAriaLabel:t("patternCanvasAria"),zoom:en,beadStyle:O,gridSpacing:f,drawingOpacity:A.visible?A.opacity:0,boardOpacity:d.opacity,highlightedColorId:sr,symmetry:Pe,symmetryPlacementActive:l==="symmetry",symmetryHandleAriaLabel:a("placeSymmetryAxis"),onSymmetryPlacementStart:tr,onSymmetryPositionChange:er,rectangleSelection:rt})}),(Be||g)&&e.jsx("div",{className:"absolute inset-0 bg-white/90 backdrop-blur-md flex items-center justify-center z-50 transition-opacity",role:"status",children:e.jsx("div",{className:"flex flex-col items-center gap-6 w-72 p-8 bg-white shadow-2xl rounded-2xl border border-[#D8CBB9]",children:Be?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"relative w-12 h-12","aria-hidden":"true",children:[e.jsx("div",{className:"absolute inset-0 border-4 border-[#F7F1E1] rounded-full"}),e.jsx("div",{className:"absolute inset-0 border-4 border-t-[#3E2A1E] rounded-full animate-spin"})]}),e.jsx("span",{className:"text-[10px] font-black uppercase tracking-[0.2em] text-[#3E2A1E]",children:t("processing")})]}):g?e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-4 h-4 border-2 border-[#3E2A1E] border-t-transparent rounded-full animate-spin"}),e.jsx("span",{className:"text-xs font-bold uppercase tracking-wider text-[#3E2A1E]",children:t("styleChanging")})]}):null})})]}):e.jsxs("div",{className:"relative z-10 m-auto w-full cursor-auto",children:[e.jsx(Fi,{state:Gs,manualUploadInputId:"upload",onReturnToSource:zs}),e.jsx(Xo,{onUpload:ka,isProcessing:Be,isCropPending:P,error:ve})]})]})]}),S&&e.jsx(Ni,{open:I,onOpenChange:wr,onConfirmExport:Nr,onSaveAndExport:Cr,author:Rt,onAuthorChange:U,watermark:Tt,onWatermarkChange:_t,exportFormat:S,loading:p||kt,statusLabel:p?t("savingPattern"):br,error:pe,usesLargePdfPage:S==="pdf"&&yr,previewPixels:ct.matrix,previewWidth:ct.gridWidth,previewHeight:ct.gridHeight,exportSettings:Fa("dialog"),mode:re}),e.jsx(ji,{open:J,onOpenChange:me}),e.jsx(Si,{open:q,onOpenChange:nr,beadStats:Ue,activePalette:Q,onDeleteColors:mr,onReplaceColor:pr}),e.jsx(oo,{open:X,onOpenChange:be,activePalette:Q,selectedColorId:i,onColorSelect:h}),e.jsx(io,{open:Ae,onOpenChange:Ie,sourceSrc:xe?.src||null,sourceKind:Bt||"photo",sourceGrid:ie?.grid,palette:Q,activePaletteLabel:rr,onApplyColor:or}),e.jsx(Eo,{imageSrc:Xe,open:Ye,gridWidth:m,showGenerationSettings:!0,onOpenChange:s=>{if(s){_e(!0);return}mn()},onCropComplete:hr,onCancel:mn,notice:Ke&&Gt?e.jsx(Ai,{manifest:Gt}):void 0}),e.jsx(Yo,{activeTab:L,onTabChange:jr,paletteDisabled:!je||Be,symmetryDisabled:!je||Be,exportDisabled:!xe||!Se||kt})]})}const Vl={PixelBeadGenerator:Il};export{Vl as export_512223e363fe};