{"version":3,"file":"SmartMap.DFne9GxO.mjs","names":["React.useState","React.useRef","React.useCallback"],"sources":["https:/framerusercontent.com/modules/rrnSYH7qvAW4vncD8imv/fUFtslNgfEf93J5sRRdc/SmartMap.js"],"sourcesContent":["import{jsx as _jsx,jsxs as _jsxs}from\"react/jsx-runtime\";import*as React from\"react\";import{addPropertyControls,ControlType}from\"framer\";// --- 1. SHARED BRAIN ---\nconst store={state:{visible:false,x:0,y:0,title:\"\",area:\"\",buildingRight:\"\"},listeners:new Set,subscribe(callback){this.listeners.add(callback);return()=>this.listeners.delete(callback);},update(newState){this.state={...this.state,...newState};this.listeners.forEach(cb=>cb(this.state));}};// --- 2. TOOLTIP COMPONENT ---\nexport function MapTooltip(props){const[data,setData]=React.useState(store.state);const[position,setPosition]=React.useState({left:0,top:0});const tooltipRef=React.useRef(null);const isPhoneMapMeaningfullyVisible=React.useCallback(()=>{if(typeof window===\"undefined\"||typeof document===\"undefined\"){return true;}const mapElement=document.getElementById(\"phone-plot-map\");if(!mapElement)return true;const rect=mapElement.getBoundingClientRect();const viewportHeight=window.innerHeight||0;const verticalOverlap=Math.min(rect.bottom,viewportHeight)-Math.max(rect.top,0);return verticalOverlap>=80;},[]);const clearTooltipIfMapIsOutOfView=React.useCallback(()=>{if(!isPhoneMapMeaningfullyVisible()&&store.state.visible){store.update({visible:false});}},[isPhoneMapMeaningfullyVisible]);React.useEffect(()=>{return store.subscribe(setData);},[]);React.useEffect(()=>{if(typeof window===\"undefined\"||typeof document===\"undefined\"){return;}let animationFrame=0;let observer;const scheduleVisibilityCheck=()=>{if(animationFrame){window.cancelAnimationFrame(animationFrame);}animationFrame=window.requestAnimationFrame(()=>{animationFrame=0;clearTooltipIfMapIsOutOfView();});};const mapElement=document.getElementById(\"phone-plot-map\");if(typeof IntersectionObserver!==\"undefined\"&&mapElement){observer=new IntersectionObserver(()=>{scheduleVisibilityCheck();});observer.observe(mapElement);}const handleScroll=()=>{if(store.state.visible){store.update({visible:false});}scheduleVisibilityCheck();};window.addEventListener(\"scroll\",handleScroll,{passive:true});window.addEventListener(\"resize\",scheduleVisibilityCheck);scheduleVisibilityCheck();return()=>{window.removeEventListener(\"scroll\",handleScroll);window.removeEventListener(\"resize\",scheduleVisibilityCheck);if(observer)observer.disconnect();if(animationFrame){window.cancelAnimationFrame(animationFrame);}};},[clearTooltipIfMapIsOutOfView]);React.useLayoutEffect(()=>{if(!data.visible||!tooltipRef.current)return;if(typeof window===\"undefined\")return;const viewportWidth=window.innerWidth;const viewportHeight=window.innerHeight;const rect=tooltipRef.current.getBoundingClientRect();const tooltipWidth=rect.width||320;const tooltipHeight=rect.height||140;const margin=12;const isNarrow=viewportWidth<=480;const preferredLeft=isNarrow?(viewportWidth-tooltipWidth)/2:data.x+20;const preferredTop=isNarrow?data.y+18:data.y-40;const safeLeft=Math.min(Math.max(preferredLeft,margin),viewportWidth-tooltipWidth-margin);const safeTop=Math.min(Math.max(preferredTop,margin),viewportHeight-tooltipHeight-margin);setPosition({left:safeLeft,top:safeTop});},[data.visible,data.x,data.y,data.title,data.area,data.buildingRight]);if(!data.visible)return null;return /*#__PURE__*/_jsxs(\"div\",{ref:tooltipRef,style:{position:\"fixed\",left:position.left,top:position.top,background:\"white\",padding:\"20px 24px\",borderRadius:\"12px\",boxShadow:\"0 8px 24px rgba(0,0,0,0.15)\",zIndex:99999,pointerEvents:\"none\",fontFamily:\"Inter, sans-serif\",// Wide enough for \"Rakennusoikeus\"\nminWidth:\"320px\"},children:[/*#__PURE__*/_jsx(\"div\",{style:{fontWeight:\"bold\",marginBottom:\"12px\",color:\"#333\",fontSize:\"18px\",borderBottom:\"1px solid #eee\",paddingBottom:\"8px\"},children:data.title}),/*#__PURE__*/_jsxs(\"div\",{style:{fontSize:\"15px\",color:\"#666\",marginBottom:\"8px\",display:\"flex\",justifyContent:\"space-between\"},children:[/*#__PURE__*/_jsx(\"span\",{children:\"Pinta-ala:\"}),/*#__PURE__*/_jsx(\"span\",{style:{fontWeight:\"500\",color:\"#333\"},children:data.area})]}),/*#__PURE__*/_jsxs(\"div\",{style:{fontSize:\"15px\",color:\"#666\",display:\"flex\",justifyContent:\"space-between\"},children:[/*#__PURE__*/_jsx(\"span\",{children:\"Rakennusoikeus:\"}),/*#__PURE__*/_jsx(\"span\",{style:{fontWeight:\"600\",color:\"#0099FF\"},children:data.buildingRight})]})]});}// --- 3. PLOT COMPONENT ---\nexport function SmartPlot(props){const{pathData,normalColor,hoverColor,title,area,buildingRight,borderColor,borderWidth}=props;const[isHovered,setHovered]=React.useState(false);const[viewBox,setViewBox]=React.useState(\"0 0 100 100\");const ref=React.useRef(null);const svgRef=React.useRef(null);const pathRef=React.useRef(null);React.useLayoutEffect(()=>{if(ref.current&&ref.current.parentElement){ref.current.parentElement.style.pointerEvents=\"none\";if(ref.current.parentElement.parentElement){ref.current.parentElement.parentElement.style.pointerEvents=\"none\";}}},[]);React.useLayoutEffect(()=>{if(typeof window===\"undefined\")return;if(!svgRef.current||!pathRef.current)return;try{const bounds=pathRef.current.getBBox();const strokePadding=Math.max(borderWidth||0,0);const minSize=1;const x=bounds.x-strokePadding;const y=bounds.y-strokePadding;const width=Math.max(bounds.width+strokePadding*2,minSize);const height=Math.max(bounds.height+strokePadding*2,minSize);React.startTransition(()=>{setViewBox(`${x} ${y} ${width} ${height}`);});}catch(_error){React.startTransition(()=>{setViewBox(\"0 0 100 100\");});}},[pathData,borderWidth]);const updateTooltipPosition=e=>{if(!e)return;const hasCoords=typeof e.clientX===\"number\"&&typeof e.clientY===\"number\";if(!hasCoords)return;store.update({x:e.clientX,y:e.clientY});};const handleEnter=e=>{React.startTransition(()=>{setHovered(true);});updateTooltipPosition(e);store.update({visible:true,title:title,area:area,buildingRight:buildingRight});};const handleMove=e=>{updateTooltipPosition(e);};const handleLeave=()=>{React.startTransition(()=>{setHovered(false);});store.update({visible:false});};return /*#__PURE__*/_jsx(\"div\",{ref:ref,style:{width:\"100%\",height:\"100%\",position:\"relative\",overflow:\"hidden\",pointerEvents:\"none\"},children:/*#__PURE__*/_jsx(\"svg\",{ref:svgRef,width:\"100%\",height:\"100%\",viewBox:viewBox,preserveAspectRatio:\"xMidYMid meet\",style:{display:\"block\",width:\"100%\",height:\"100%\",overflow:\"hidden\"},children:/*#__PURE__*/_jsx(\"path\",{ref:pathRef,d:pathData,fill:isHovered?hoverColor:normalColor,// UPDATED: Add stroke properties\nstroke:borderColor,strokeWidth:borderWidth,// UPDATED: This ensures the border doesn't stretch/distort\nvectorEffect:\"non-scaling-stroke\",style:{pointerEvents:\"auto\",cursor:\"pointer\",transition:\"fill 0.2s ease\"},onMouseEnter:handleEnter,onMouseMove:handleMove,onClick:handleEnter,onMouseLeave:handleLeave})})});}// --- 4. CONTROLS ---\naddPropertyControls(SmartPlot,{title:{type:ControlType.String,title:\"Title\",defaultValue:\"Tontti 101\"},area:{type:ControlType.String,title:\"Pinta-ala\",defaultValue:\"1,200 m\\xb2\"},buildingRight:{type:ControlType.String,title:\"Rakennusoikeus\",defaultValue:\"450 k-m\\xb2\"},normalColor:{type:ControlType.Color,title:\"Color\",defaultValue:\"rgba(255, 0, 0, 0.3)\"},hoverColor:{type:ControlType.Color,title:\"Hover\",defaultValue:\"rgba(0, 255, 0, 0.8)\"},borderColor:{type:ControlType.Color,title:\"Border Color\",defaultValue:\"#000000\"},borderWidth:{type:ControlType.Number,title:\"Border Width\",defaultValue:2,min:0,max:10,step:.5},pathData:{type:ControlType.String,title:\"SVG Path\",placeholder:\"Paste d='...' here\",displayTextArea:true,defaultValue:\"M 10 10 L 90 10 L 90 90 L 10 90 Z\"}});\nexport const __FramerMetadata__ = {\"exports\":{\"SmartPlot\":{\"type\":\"reactComponent\",\"name\":\"SmartPlot\",\"slots\":[],\"annotations\":{\"framerContractVersion\":\"1\"}},\"MapTooltip\":{\"type\":\"reactComponent\",\"name\":\"MapTooltip\",\"slots\":[],\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./S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