(()=>{"use strict";const initEkoParking=()=>{const section=document.querySelector("[data-eko-park]");if (!section){return}const scrollArea=section.querySelector(".eko-park__scroll");const plane=section.querySelector("[data-eko-park-plane]");const canvas=section.querySelector("[data-eko-park-lines]");const car=section.querySelector("[data-eko-park-car]");if (!scrollArea || !plane || !canvas || !car){return}const reduceMotion=window.matchMedia("(prefers-reduced-motion: reduce)");const clamp=(value,min,max)=>Math.min(Math.max(value,min),max);const mix=(a,b,amount)=>a + ((b - a) * amount);const ease=(t)=>t < .5 ? 4 * t * t * t :1 - Math.pow(-2 * t + 2,3) / 2;let assetsLoaded=false;const loadAssets=()=>{if (assetsLoaded){return}assetsLoaded=true;const carSource=car.dataset.src;if (carSource){car.src=carSource}const linesSource=canvas.dataset.src;if (!linesSource){return}const sourceImage=new Image();sourceImage.decoding="async";sourceImage.onload=()=>{const ctx=canvas.getContext("2d",{willReadFrequently:true});if (!ctx){return}canvas.width=sourceImage.naturalWidth;canvas.height=sourceImage.naturalHeight;ctx.clearRect(0,0,canvas.width,canvas.height);ctx.drawImage(sourceImage,0,0);const imageData=ctx.getImageData(0,0,canvas.width,canvas.height);const data=imageData.data;const width=canvas.width;const height=canvas.height;const pixelCount=width * height;const mask=new Uint8Array(pixelCount);for (let i=0,px=0;i < data.length;i +=4,px++){const r=data[i];const g=data[i + 1];const b=data[i + 2];const a=data[i + 3];const maxChannel=Math.max(r,g,b);const minChannel=Math.min(r,g,b);const neutral=(maxChannel - minChannel) < 20;const bright=r>232 && g>232 && b>225;if (a>=8 && neutral && bright){mask[px]=1}}const visited=new Uint8Array(pixelCount);const keep=new Uint8Array(pixelCount);const minComponentSize=220;const neighborOffsets=[-width - 1,-width,-width + 1,-1,1,width - 1,width,width + 1];for (let i=0;i < pixelCount;i++){if (!mask[i] || visited[i]){continue}const stack=[i];const component=[];visited[i]=1;while (stack.length){const current=stack.pop();component.push(current);const x=current % width;const y=Math.floor(current / width);for (let n=0;n < neighborOffsets.length;n++){const next=current + neighborOffsets[n];if (next < 0 || next>=pixelCount){continue}const nx=next % width;const ny=Math.floor(next / width);if (Math.abs(nx - x)>1 || Math.abs(ny - y)>1){continue}if (!mask[next] || visited[next]){continue}visited[next]=1;stack.push(next)}}if (component.length>=minComponentSize){for (let c=0;c < component.length;c++){keep[component[c]]=1}}}for (let i=0,px=0;i < data.length;i +=4,px++){if (!keep[px]){data[i + 3]=0;continue}data[i]=244;data[i + 1]=242;data[i + 2]=235;data[i + 3]=255}ctx.clearRect(0,0,canvas.width,canvas.height);ctx.putImageData(imageData,0,0)};sourceImage.src=linesSource};if ("IntersectionObserver" in window){const assetObserver=new IntersectionObserver((entries)=>{entries.forEach((entry)=>{if (!entry.isIntersecting){return}loadAssets();assetObserver.disconnect()})},{rootMargin:"900px 0px"});assetObserver.observe(section)}else{loadAssets()}const start={x:-42,y:36,r:-14};const approach={x:-30.5,y:18,r:-7.5};const finalPosition={x:-19.8724,y:-4.6631,r:-.65};const setCarPosition=(x,y,rotation)=>{section.style.setProperty("--park-car-x",`${x}%`);section.style.setProperty("--park-car-y",`${y}%`);section.style.setProperty("--park-car-r",`${rotation}deg`)};const parkedPosition=()=>{setCarPosition(finalPosition.x,finalPosition.y,finalPosition.r)};let ticking=false;const update=()=>{ticking=false;if (reduceMotion.matches){parkedPosition();return}const rect=scrollArea.getBoundingClientRect();const travel=Math.max(scrollArea.offsetHeight - window.innerHeight,1);const rawProgress=clamp(-rect.top / travel,0,1);const driveProgress=clamp(rawProgress / .76,0,1);if (driveProgress < .56){const local=ease(driveProgress / .56);setCarPosition(mix(start.x,approach.x,local),mix(start.y,approach.y,local),mix(start.r,approach.r,local));return}const local=ease((driveProgress - .56) / .44);setCarPosition(mix(approach.x,finalPosition.x,local),mix(approach.y,finalPosition.y,local),mix(approach.r,finalPosition.r,local))};const requestUpdate=()=>{if (ticking){return}ticking=true;window.requestAnimationFrame(update)};window.addEventListener("scroll",requestUpdate,{passive:true});window.addEventListener("resize",requestUpdate,{passive:true});if (typeof reduceMotion.addEventListener==="function"){reduceMotion.addEventListener("change",requestUpdate)}requestUpdate()};if (document.readyState==="loading"){document.addEventListener("DOMContentLoaded",initEkoParking,{once:true})}else{initEkoParking()}})();