{"version":3,"file":"WithEvent.OS9y6KA5.mjs","names":["useRef"],"sources":["https:/framerusercontent.com/modules/d55PZ9zMiqZCmf772GUe/KCvSpaDZd64jXGuc3MOg/WithEvent.js"],"sourcesContent":["import{jsx as _jsx}from\"react/jsx-runtime\";import{useScroll}from\"framer-motion\";import{useEffect,useRef}from\"react\";function throttled(fn,delay){let timer;let starttime=Date.now();return function(){let curTime=Date.now();let remaining=delay-(curTime-starttime);let context=this;let args=arguments;clearTimeout(timer);if(remaining<=0){fn.apply(context,args);starttime=Date.now();}else{timer=setTimeout(fn,remaining);}};}export function pageEvent(Component){return props=>{const componentRef=useRef();const{scrollY}=useScroll();let startTime=0;const documentVisibilityChange=()=>{if(document.visibilityState===\"hidden\"){window?.collectEvent?.(\"lark_website_get_focus_server\",{duration:Date.now()-startTime});}else if(document.visibilityState===\"visible\"){startTime=Date.now();}};const scrollRateChange=throttled(()=>{const{height}=componentRef.current?.getBoundingClientRect?.();const totalHeight=window.innerHeight||document.documentElement.clientHeight;window?.collectEvent?.(\"lark_website_rate_show_view\",{rate:Math.round(scrollY.get()/(height-totalHeight)*100)/100,height:totalHeight});},500);const scrollChange=()=>{scrollRateChange();};useEffect(()=>{scrollY.onChange(scrollChange);startTime=Date.now();document.addEventListener(\"visibilitychange\",documentVisibilityChange);return()=>{document.removeEventListener(\"visibilitychange\",documentVisibilityChange);};},[]);return /*#__PURE__*/_jsx(Component,{ref:componentRef,...props});};}export function withScroll(Component){const mainPageViewEventName=\"lark_website_mainpage_story_view\";function getModuleIndex({module_name,moduleClassName}){console.log(moduleClassName,module_name,99);if(!moduleClassName){return 0;}const moduleList=document.querySelectorAll(`[data-framer-name=\"${module_name}\"]`);const target=document.querySelector(`.${moduleClassName}`);return Array.from(moduleList).findIndex(item=>item===target);}return props=>{const componentRef=useRef();const{scrollY}=useScroll();function debounce(fn,delay){let timer;return function(...args){if(timer)clearTimeout(timer);timer=setTimeout(()=>fn.apply(this,args),delay);};}let moduleViewStartTime;const module_name=props[\"data-framer-name\"]||props.name;const moduleClassName=props.className||\"\";console.log(props,33);const eventReport=()=>{// height: 此元素的高度  top: 距离浏览器顶部的高度\nconst{height,top}=componentRef?.current?.getBoundingClientRect?.();// 浏览器高度\nconst totalHeight=window.innerHeight||document.documentElement.clientHeight;if(top>=0&&top-totalHeight<0||top<0&&top+height>0){if(!moduleViewStartTime){moduleViewStartTime=Date.now();}const module_index=getModuleIndex({module_name,moduleClassName});const params={module_name,module_index};console.log(params,\"上报\");window?.collectEvent?.(mainPageViewEventName,params);}else{if(moduleViewStartTime){window?.collectEvent?.(\"lark_website_mainpage_story_click\",{module_name,click:\"page_active\",duration:Date.now()-moduleViewStartTime});moduleViewStartTime=0;}}};const scrollModuleChange=debounce(eventReport,300);const scrollChange=()=>{scrollModuleChange();};const documentVisibilityChange=()=>{if(!moduleViewStartTime){return;}if(document.visibilityState===\"hidden\"){window?.collectEvent?.(\"lark_website_mainpage_story_click\",{module_name,click:\"page_active\",duration:Date.now()-moduleViewStartTime});}else if(document.visibilityState===\"visible\"){moduleViewStartTime=Date.now();}};useEffect(()=>{scrollY.onChange(scrollChange);eventReport();document.addEventListener(\"visibilitychange\",documentVisibilityChange);return()=>{document.removeEventListener(\"visibilitychange\",documentVisibilityChange);};},[]);return /*#__PURE__*/_jsx(Component,{ref:componentRef,...props});};}\nexport const __FramerMetadata__ = {\"exports\":{\"withScroll\":{\"type\":\"reactHoc\",\"name\":\"withScroll\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"pageEvent\":{\"type\":\"reactHoc\",\"name\":\"pageEvent\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./WithEvent.map"],"mappings":"wLAAoH,SAAS,EAAU,EAAG,EAAM,CAAC,IAAI,EAAU,EAAU,KAAK,KAAK,CAAC,OAAO,UAAU,CAAwB,IAAI,EAAU,GAAzB,KAAK,KAAK,CAA8B,GAAe,EAAQ,KAAS,EAAK,UAA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