{"version":3,"file":"DotGridSVG.D5mLIf3W.mjs","names":["useRef","useState","useMemo"],"sources":["https:/framerusercontent.com/modules/9oPONCOEzv6g8LTfe7CZ/iCOkqRVpoO4r7Cbep5s2/DotGridSVG.js"],"sourcesContent":["// Dot grid layout that recreates an SVG image using dots\nimport{jsx as _jsx,jsxs as _jsxs}from\"react/jsx-runtime\";import{useEffect,useRef,useState,useMemo,startTransition}from\"react\";import{addPropertyControls,ControlType}from\"framer\";/**\n * @framerSupportedLayoutWidth fixed\n * @framerSupportedLayoutHeight fixed\n * @framerIntrinsicWidth 640\n * @framerIntrinsicHeight 360\n */export default function DotGridSVG(props){const{svgFile=\"https://framerusercontent.com/images/GfGkADagM4KEibNcIiRUWlfrR0.jpg\",gridSize=50,dotSize=4,spacing=10,threshold=128,threshold2=200,animateThreshold=false,animationSpeed=30,dotColor=\"#000000\",backgroundColor=\"#FFFFFF\",invert=false,imageFit=\"fill\",style}=props;const canvasRef=useRef(null);const containerRef=useRef(null);const pixelDataRef=useRef(null);const[dots,setDots]=useState([]);const[imageDimensions,setImageDimensions]=useState({width:gridSize,height:gridSize});const[animatedThreshold,setAnimatedThreshold]=useState(threshold);// Threshold animation — unchanged\nuseEffect(()=>{if(typeof window===\"undefined\")return;if(!animateThreshold){startTransition(()=>setAnimatedThreshold(threshold));return;}const minT=Math.max(0,Math.min(255,Math.round(Math.min(threshold,threshold2))));const maxT=Math.max(0,Math.min(255,Math.round(Math.max(threshold,threshold2))));const speed=Math.max(1,Math.round(animationSpeed));let current=Math.max(minT,Math.min(maxT,Math.round(animatedThreshold)));let dir=current>=maxT?-1:1;const interval=window.setInterval(()=>{current+=dir;if(current>=maxT){current=maxT;dir=-1;}else if(current<=minT){current=minT;dir=1;}startTransition(()=>setAnimatedThreshold(current));},1e3/speed);return()=>window.clearInterval(interval);// eslint-disable-next-line react-hooks/exhaustive-deps\n},[animateThreshold,threshold,threshold2,animationSpeed]);const effectiveThreshold=animateThreshold?animatedThreshold:threshold;// Effect 1: Load image and extract pixel data\n// KEY FIX: effectiveThreshold removed from deps — image only reloads when source/grid/fit changes\nuseEffect(()=>{if(typeof window===\"undefined\")return;const canvas=canvasRef.current;const container=containerRef.current;if(!canvas||!container)return;const ctx=canvas.getContext(\"2d\",{willReadFrequently:true});if(!ctx)return;const img=new Image;img.crossOrigin=\"anonymous\";img.onload=()=>{const containerWidth=container.clientWidth;const containerHeight=container.clientHeight;const imageAspect=img.width/img.height;const containerAspect=containerWidth/containerHeight;let canvasWidth=gridSize;let canvasHeight=gridSize;if(imageFit===\"fill\"){canvasWidth=gridSize;canvasHeight=Math.round(gridSize/imageAspect);}else if(containerAspect>1){canvasWidth=gridSize;canvasHeight=Math.round(gridSize/containerAspect);}else{canvasHeight=gridSize;canvasWidth=Math.round(gridSize*containerAspect);}canvas.width=canvasWidth;canvas.height=canvasHeight;ctx.fillStyle=\"#FFFFFF\";ctx.fillRect(0,0,canvasWidth,canvasHeight);if(imageFit===\"tile\"){const tileSize=Math.min(gridSize/4,40);let tileWidth=tileSize;let tileHeight=tileSize/imageAspect;if(imageAspect<1){tileHeight=tileSize;tileWidth=tileSize*imageAspect;}for(let y=0;y<canvasHeight;y+=tileHeight){for(let x=0;x<canvasWidth;x+=tileWidth){ctx.drawImage(img,x,y,tileWidth,tileHeight);}}}else if(imageFit===\"fill\"){ctx.drawImage(img,0,0,img.width,img.height,0,0,canvasWidth,canvasHeight);}else if(imageFit===\"fit\"){let destWidth=canvasWidth,destHeight=canvasHeight,destX=0,destY=0;if(imageAspect>containerAspect){destWidth=canvasWidth;destHeight=canvasWidth/imageAspect;destY=(canvasHeight-destHeight)/2;}else{destHeight=canvasHeight;destWidth=canvasHeight*imageAspect;destX=(canvasWidth-destWidth)/2;}ctx.drawImage(img,0,0,img.width,img.height,destX,destY,destWidth,destHeight);}else if(imageFit===\"stretch\"){ctx.drawImage(img,0,0,img.width,img.height,0,0,canvasWidth,canvasHeight);}try{if(canvasWidth<=0||canvasHeight<=0||!isFinite(canvasWidth)||!isFinite(canvasHeight))return;const imageData=ctx.getImageData(0,0,canvasWidth,canvasHeight);// Cache pixel data — threshold changes will use this without reloading\npixelDataRef.current={data:imageData.data,width:canvasWidth,height:canvasHeight};startTransition(()=>setImageDimensions({width:canvasWidth,height:canvasHeight}));}catch(error){console.error(\"DotGridSVG - Error processing image:\",error);}};img.onerror=()=>console.error(\"DotGridSVG - Error loading image:\",svgFile);img.src=svgFile;},[svgFile,gridSize,imageFit])// No effectiveThreshold — this was the bug\n;// Effect 2: Compute dots from cached pixel data\n// Runs when threshold or invert changes — no image reload, no getImageData\nuseEffect(()=>{if(!pixelDataRef.current)return;const{data,width,height}=pixelDataRef.current;const newDots=[];for(let y=0;y<height;y++){const row=[];for(let x=0;x<width;x++){const index=(y*width+x)*4;const brightness=(data[index]+data[index+1]+data[index+2])/3;row.push(invert?brightness>effectiveThreshold:brightness<effectiveThreshold);}newDots.push(row);}startTransition(()=>setDots(newDots));},[effectiveThreshold,invert,imageDimensions]);const gridWidth=useMemo(()=>imageDimensions.width*spacing,[imageDimensions.width,spacing]);const gridHeight=useMemo(()=>imageDimensions.height*spacing,[imageDimensions.height,spacing]);const preserveAspectRatio=useMemo(()=>{switch(imageFit){case\"fill\":return\"xMidYMid slice\";case\"fit\":return\"xMidYMid meet\";case\"stretch\":return\"none\";default:return\"xMidYMid meet\";}},[imageFit]);return /*#__PURE__*/_jsxs(\"div\",{ref:containerRef,style:{...style,display:\"flex\",alignItems:\"center\",justifyContent:\"center\",backgroundColor,overflow:\"hidden\",position:\"relative\"},children:[/*#__PURE__*/_jsx(\"canvas\",{ref:canvasRef,style:{display:\"none\"}}),/*#__PURE__*/_jsx(\"svg\",{viewBox:`0 0 ${gridWidth} ${gridHeight}`,preserveAspectRatio:preserveAspectRatio,style:{width:\"100%\",height:\"100%\"},children:dots.map((row,y)=>row.map((shouldShow,x)=>shouldShow?/*#__PURE__*/_jsx(\"circle\",{cx:x*spacing+spacing/2,cy:y*spacing+spacing/2,r:dotSize/2,fill:dotColor},`${x}-${y}`):null))})]});}addPropertyControls(DotGridSVG,{svgFile:{type:ControlType.File,title:\"Image\",allowedFileTypes:[\"jpg\",\"jpeg\",\"png\",\"gif\",\"webp\",\"svg\"]},imageFit:{type:ControlType.Enum,title:\"Image Fit\",options:[\"fill\",\"fit\",\"stretch\",\"tile\"],optionTitles:[\"Fill\",\"Fit\",\"Stretch\",\"Tile\"],defaultValue:\"fill\",displaySegmentedControl:false},gridSize:{type:ControlType.Number,title:\"Grid Size\",defaultValue:50,min:10,max:200,step:1},dotSize:{type:ControlType.Number,title:\"Dot Size\",defaultValue:4,min:1,max:20,step:.5,unit:\"px\"},spacing:{type:ControlType.Number,title:\"Spacing\",defaultValue:10,min:2,max:50,step:1,unit:\"px\"},threshold:{type:ControlType.Number,title:\"Threshold 1\",defaultValue:128,min:0,max:255,step:1},threshold2:{type:ControlType.Number,title:\"Threshold 2\",defaultValue:200,min:0,max:255,step:1},animateThreshold:{type:ControlType.Boolean,title:\"Animate\",defaultValue:false,enabledTitle:\"On\",disabledTitle:\"Off\"},animationSpeed:{type:ControlType.Number,title:\"Anim Speed\",defaultValue:30,min:1,max:60,step:1,unit:\"fps\",hidden:({animateThreshold})=>!animateThreshold},invert:{type:ControlType.Boolean,title:\"Invert\",defaultValue:false,enabledTitle:\"On\",disabledTitle:\"Off\"},dotColor:{type:ControlType.Color,title:\"Dot Color\",defaultValue:\"#000000\"},backgroundColor:{type:ControlType.Color,title:\"Background\",defaultValue:\"#FFFFFF\"}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"DotGridSVG\",\"slots\":[],\"annotations\":{\"framerIntrinsicHeight\":\"360\",\"framerSupportedLayoutHeight\":\"fixed\",\"framerIntrinsicWidth\":\"640\",\"framerContractVersion\":\"1\",\"framerSupportedLayoutWidth\":\"fixed\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./DotGridSVG.map"],"mappings":"4NAMG,SA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