{"version":3,"file":"BeforeAfterSlider.Eb2sQS-e.mjs","names":["useRef","useState","useCallback","p","useMemo"],"sources":["https:/framerusercontent.com/modules/DbZVkOPVl9calND1vkEY/iS5DiQka1B3R65f8wces/BeforeAfterSlider.js"],"sourcesContent":["// User wants: \"need a before and after image slider\"\nimport{jsx as _jsx,jsxs as _jsxs}from\"react/jsx-runtime\";import{addPropertyControls,ControlType,useIsStaticRenderer}from\"framer\";import{useCallback,useEffect,useMemo,useRef,useState,startTransition}from\"react\";/**\n * @framerIntrinsicWidth 600\n * @framerIntrinsicHeight 360\n *\n * @framerSupportedLayoutWidth fixed\n * @framerSupportedLayoutHeight fixed\n */export default function BeforeAfterSlider(props){const{beforeImage={src:\"https://framerusercontent.com/images/f9RiWoNpmlCMqVRIHz8l8wYfeI.jpg\",alt:\"Before image\"},afterImage={src:\"https://framerusercontent.com/images/aNsAT3jCvt4zglbWCUoFe33Q.jpg\",alt:\"After image\"},orientation,initialPosition,dividerColor,dividerWidth,dividerShadow,showHandle,handleColor,handleSize,handleIconColor,cornerRadius,backgroundColor,style}=props;const isStatic=useIsStaticRenderer();const containerRef=useRef(null);const pointerIdRef=useRef(null);const[position,setPosition]=useState(()=>clamp01To100(initialPosition));useEffect(()=>{startTransition(()=>setPosition(clamp01To100(initialPosition)));// eslint-disable-next-line react-hooks/exhaustive-deps\n},[initialPosition]);const isHorizontal=orientation===\"horizontal\";const updateFromClientPoint=useCallback((clientX,clientY)=>{const el=containerRef.current;if(!el)return;const rect=el.getBoundingClientRect();const next=isHorizontal?(clientX-rect.left)/Math.max(1,rect.width)*100:(clientY-rect.top)/Math.max(1,rect.height)*100;const clamped=clamp01To100(next);startTransition(()=>setPosition(clamped));},[isHorizontal]);const onPointerDown=useCallback(e=>{if(isStatic)return;pointerIdRef.current=e.pointerId;e.currentTarget.setPointerCapture(e.pointerId);updateFromClientPoint(e.clientX,e.clientY);},[isStatic,updateFromClientPoint]);const onPointerMove=useCallback(e=>{if(isStatic)return;if(pointerIdRef.current===null)return;if(e.pointerId!==pointerIdRef.current)return;updateFromClientPoint(e.clientX,e.clientY);},[isStatic,updateFromClientPoint]);const endPointer=useCallback(e=>{if(pointerIdRef.current===null)return;if(e.pointerId!==pointerIdRef.current)return;pointerIdRef.current=null;try{e.currentTarget.releasePointerCapture(e.pointerId);}catch{// ignore\n}},[]);const onKeyDown=useCallback(e=>{if(isStatic)return;const step=e.shiftKey?10:2;if(e.key===\"Home\"){e.preventDefault();startTransition(()=>setPosition(0));return;}if(e.key===\"End\"){e.preventDefault();startTransition(()=>setPosition(100));return;}if(isHorizontal){if(e.key===\"ArrowLeft\"){e.preventDefault();startTransition(()=>setPosition(p=>clamp01To100(p-step)));}else if(e.key===\"ArrowRight\"){e.preventDefault();startTransition(()=>setPosition(p=>clamp01To100(p+step)));}}else{if(e.key===\"ArrowUp\"){e.preventDefault();startTransition(()=>setPosition(p=>clamp01To100(p-step)));}else if(e.key===\"ArrowDown\"){e.preventDefault();startTransition(()=>setPosition(p=>clamp01To100(p+step)));}}},[isStatic,isHorizontal]);const clipPath=useMemo(()=>{const p=clamp01To100(position);return isHorizontal?`inset(0 ${100-p}% 0 0)`:`inset(0 0 ${100-p}% 0)`;},[position,isHorizontal]);const dividerStyle=useMemo(()=>{const p=clamp01To100(position);const translate=isHorizontal?`translateX(-${dividerWidth/2}px)`:`translateY(-${dividerWidth/2}px)`;return{position:\"absolute\",top:isHorizontal?0:`${p}%`,left:isHorizontal?`${p}%`:0,width:isHorizontal?`${dividerWidth}px`:\"100%\",height:isHorizontal?\"100%\":`${dividerWidth}px`,backgroundColor:dividerColor,boxShadow:dividerShadow?\"0 8px 24px rgba(0,0,0,0.18)\":\"none\",transform:translate,zIndex:3,pointerEvents:\"none\"};},[position,isHorizontal,dividerWidth,dividerColor,dividerShadow]);const handleStyle=useMemo(()=>{const p=clamp01To100(position);const translate=isHorizontal?`translate(-${handleSize/2}px, -50%)`:`translate(-50%, -${handleSize/2}px)`;return{position:\"absolute\",top:isHorizontal?\"50%\":`${p}%`,left:isHorizontal?`${p}%`:\"50%\",width:`${handleSize}px`,height:`${handleSize}px`,borderRadius:999,backgroundColor:handleColor,boxShadow:\"0 10px 30px rgba(0,0,0,0.22)\",display:\"flex\",alignItems:\"center\",justifyContent:\"center\",transform:translate,zIndex:4,pointerEvents:\"none\"};},[position,isHorizontal,handleSize,handleColor]);return /*#__PURE__*/_jsxs(\"div\",{ref:containerRef,style:{position:\"relative\",width:\"100%\",height:\"100%\",overflow:\"hidden\",backgroundColor,borderRadius:cornerRadius,touchAction:\"none\",userSelect:\"none\",WebkitUserSelect:\"none\",cursor:isStatic?\"default\":isHorizontal?\"ew-resize\":\"ns-resize\",...style},role:\"slider\",\"aria-label\":\"Before and after image comparison\",\"aria-valuemin\":0,\"aria-valuemax\":100,\"aria-valuenow\":Math.round(clamp01To100(position)),\"aria-orientation\":orientation,tabIndex:0,onPointerDown:onPointerDown,onPointerMove:onPointerMove,onPointerUp:endPointer,onPointerCancel:endPointer,onLostPointerCapture:()=>{if(pointerIdRef.current!==null)pointerIdRef.current=null;},onKeyDown:onKeyDown,children:[/*#__PURE__*/_jsx(\"img\",{src:afterImage.src,srcSet:afterImage.srcSet,alt:afterImage.alt??\"After\",draggable:false,style:{position:\"absolute\",inset:0,width:\"100%\",height:\"100%\",objectFit:\"cover\"}}),/*#__PURE__*/_jsx(\"div\",{style:{position:\"absolute\",inset:0,clipPath,WebkitClipPath:clipPath,zIndex:2},\"aria-hidden\":\"true\",children:/*#__PURE__*/_jsx(\"img\",{src:beforeImage.src,srcSet:beforeImage.srcSet,alt:beforeImage.alt??\"Before\",draggable:false,style:{position:\"absolute\",inset:0,width:\"100%\",height:\"100%\",objectFit:\"cover\"}})}),/*#__PURE__*/_jsx(\"div\",{style:dividerStyle,\"aria-hidden\":\"true\"}),showHandle&&/*#__PURE__*/_jsx(\"div\",{style:handleStyle,\"aria-hidden\":\"true\",children:/*#__PURE__*/_jsx(HandleIcon,{orientation:orientation,color:handleIconColor,size:Math.max(14,Math.round(handleSize*.55))})})]});}function clamp01To100(v){if(!Number.isFinite(v))return 50;return Math.max(0,Math.min(100,v));}function HandleIcon(props){const{orientation,color,size}=props;const isHorizontal=orientation===\"horizontal\";return /*#__PURE__*/_jsx(\"svg\",{width:size,height:size,viewBox:\"0 0 24 24\",fill:\"none\",\"aria-hidden\":\"true\",children:/*#__PURE__*/_jsx(\"path\",{d:isHorizontal?\"M8.5 7.5L4.5 12L8.5 16.5M15.5 7.5L19.5 12L15.5 16.5\":\"M7.5 8.5L12 4.5L16.5 8.5M7.5 15.5L12 19.5L16.5 15.5\",stroke:color,strokeWidth:\"2\",strokeLinecap:\"round\",strokeLinejoin:\"round\"})});}addPropertyControls(BeforeAfterSlider,{beforeImage:{type:ControlType.ResponsiveImage,title:\"Before\"},afterImage:{type:ControlType.ResponsiveImage,title:\"After\"},orientation:{type:ControlType.Enum,title:\"Orientation\",options:[\"horizontal\",\"vertical\"],optionTitles:[\"Horizontal\",\"Vertical\"],defaultValue:\"horizontal\",displaySegmentedControl:true},initialPosition:{type:ControlType.Number,title:\"Start\",defaultValue:50,min:0,max:100,step:1,unit:\"%\"},dividerColor:{type:ControlType.Color,title:\"Divider\",defaultValue:\"#FFFFFF\"},dividerWidth:{type:ControlType.Number,title:\"Divider W\",defaultValue:2,min:1,max:20,step:1,unit:\"px\"},dividerShadow:{type:ControlType.Boolean,title:\"Divider Shadow\",defaultValue:true,enabledTitle:\"On\",disabledTitle:\"Off\"},showHandle:{type:ControlType.Boolean,title:\"Handle\",defaultValue:true,enabledTitle:\"Show\",disabledTitle:\"Hide\"},handleColor:{type:ControlType.Color,title:\"Handle Fill\",defaultValue:\"#FFFFFF\",hidden:p=>!p.showHandle},handleIconColor:{type:ControlType.Color,title:\"Handle Icon\",defaultValue:\"#000000\",hidden:p=>!p.showHandle},handleSize:{type:ControlType.Number,title:\"Handle Size\",defaultValue:44,min:20,max:90,step:1,unit:\"px\",hidden:p=>!p.showHandle},cornerRadius:{type:ControlType.BorderRadius,title:\"Radius\",defaultValue:\"16px\"},backgroundColor:{type:ControlType.Color,title:\"Background\",defaultValue:\"#FFFFFF\"}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"BeforeAfterSlider\",\"slots\":[],\"annotations\":{\"framerIntrinsicWidth\":\"600\",\"framerSupportedLayoutHeight\":\"fixed\",\"framerContractVersion\":\"1\",\"framerIntrinsicHeight\":\"360\",\"framerSupportedLayoutWidth\":\"fixed\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./BeforeAfterSlider.map"],"mappings":"uNAOG,SAAwB,EAAkB,EAAM,CAAC,GAAK,CAAC,cAAY,CAAC,IAAI,sEAAsE,IAAI,eAAe,CAAC,aAAW,CAAC,IAAI,oEAAoE,IAAI,cAAc,CAAC,cAAY,kBAAgB,eAAa,eAAa,gBAAc,aAAW,cAAY,aAAW,kBAAgB,eAAa,kBAAgB,SAAO,EAAY,EAAS,GAAqB,CAAO,EAAaA,EAAO,KAAK,CAAO,EAAaA,EAAO,KAAK,CAAM,CAAC,EAAS,GAAaC,MAAa,EAAa,EAAgB,CAAC,CAAC,MAAc,CAAC,MAAoB,EAAY,EAAa,EAAgB,CAAC,CAAC,EACrqB,CAAC,EAAgB,CAAC,CAAC,IAAM,EAAa,IAAc,aAAmB,EAAsBC,GAAa,EAAQ,IAAU,CAAC,IAAM,EAAG,EAAa,QAAQ,GAAG,CAAC,EAAG,OAAO,IAAM,EAAK,EAAG,uBAAuB,CAA6H,EAAQ,EAAzH,GAAc,EAAQ,EAAK,MAAM,KAAK,IAAI,EAAE,EAAK,MAAM,CAAC,KAAK,EAAQ,EAAK,KAAK,KAAK,IAAI,EAAE,EAAK,OAAO,CAAC,IAAoC,CAAC,MAAoB,EAAY,EAAQ,CAAC,EAAG,CAAC,EAAa,CAAC,CAAO,EAAcA,EAAY,GAAG,CAAI,IAAgB,EAAa,QAAQ,EAAE,UAAU,EAAE,cAAc,k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