{"version":3,"file":"ReadingTime.DB53IGAb.mjs","names":["useRef","useCallback","useState"],"sources":["https:/framerusercontent.com/modules/BBGoGChQZPQA6NjCYvSh/27iBqnbssl3c2NtBz93E/ReadingTime.js"],"sourcesContent":["import{jsx as _jsx}from\"react/jsx-runtime\";import{forwardRef,useCallback,useEffect,useState,useRef}from\"react\";import{useIsStaticRenderer}from\"framer\";// User request: Create a new code file ReadingTime.tsx that exports a code override named withReadingTime for a RichText layer, computes client-side reading time from article body content, outputs `${minutes} min read`, avoids styling changes, supports delayed CMS mounts with observation/retries, and exports WORDS_PER_MINUTE.\nexport const WORDS_PER_MINUTE=220;const MAX_RETRIES=20;const RETRY_INTERVAL_MS=250;const EXCLUDED_SELECTOR=\"nav,footer,aside,button,input,select,textarea,form,script,style,noscript,svg,canvas\";const BODY_TOP_SELECTOR='[data-framer-name=\"Body Top\"]';const BODY_BOTTOM_SELECTOR='[data-framer-name=\"Body Bottom\"]';const ARTICLE_BODY_TOP_SELECTOR='[data-framer-name=\"Article Body Top\"]';const ARTICLE_BODY_BOTTOM_SELECTOR='[data-framer-name=\"Article Body Bottom\"]';function setForwardedRef(ref,node){if(typeof ref===\"function\"){ref(node);}else if(ref&&typeof ref===\"object\"){ref.current=node;}}function countWordsFromText(text){const trimmed=text.trim();if(!trimmed)return 0;return trimmed.split(/\\s+/).filter(Boolean).length;}function getMinutesFromWords(words){return Math.max(1,Math.round(words/WORDS_PER_MINUTE));}function getDeepestTextElement(hostElement){if(!hostElement)return null;const candidates=hostElement.querySelectorAll(\"*\");for(let i=candidates.length-1;i>=0;i-=1){const element=candidates[i];const hasDirectText=Array.from(element.childNodes).some(node=>{return node.nodeType===Node.TEXT_NODE&&Boolean(node.textContent&&node.textContent.trim());});if(hasDirectText)return element;}return hostElement;}export function withReadingTime(Component){return /*#__PURE__*/forwardRef((props,ref)=>{const localRef=useRef(null);const observerRef=useRef(null);const lastWrittenTextRef=useRef(\"\");const resolvedRef=useCallback(node=>{localRef.current=node;setForwardedRef(ref,node);},[ref]);const isStatic=useIsStaticRenderer();const getArticleRoot=useCallback(hostElement=>{if(typeof document===\"undefined\")return null;const articleContent=document.querySelector('[data-framer-name=\"ArticleContent\"]');if(articleContent)return articleContent;const closestPostContent=(hostElement?.closest('[data-framer-name=\"Post Content\"]'))??document.querySelector('[data-framer-name=\"Post Content\"]');if(closestPostContent)return closestPostContent;return document.querySelector(\"main\");},[]);const countWords=useCallback((root,hostElement)=>{if(typeof document===\"undefined\")return 0;const walker=document.createTreeWalker(root,NodeFilter.SHOW_TEXT,{acceptNode(node){const text=node.textContent?.trim();if(!text)return NodeFilter.FILTER_REJECT;const parent=node.parentElement;if(!parent)return NodeFilter.FILTER_REJECT;if(hostElement&&hostElement.contains(parent)){return NodeFilter.FILTER_REJECT;}if(parent.closest(EXCLUDED_SELECTOR)){return NodeFilter.FILTER_REJECT;}return NodeFilter.FILTER_ACCEPT;}});let words=0;let currentNode=walker.nextNode();while(currentNode){const content=currentNode.textContent?.trim()??\"\";if(content){words+=content.split(/\\s+/).filter(Boolean).length;}currentNode=walker.nextNode();}return words;},[]);const getArticleBodyFieldWords=useCallback(()=>{if(typeof document===\"undefined\"){return{hasAnyLayer:false,words:0};}const bodyTop=document.querySelector(ARTICLE_BODY_TOP_SELECTOR);const bodyBottom=document.querySelector(ARTICLE_BODY_BOTTOM_SELECTOR);const hasAnyLayer=Boolean(bodyTop||bodyBottom);const combinedText=`${bodyTop?.textContent?.trim()??\"\"} ${bodyBottom?.textContent?.trim()??\"\"}`.trim();return{hasAnyLayer,words:countWordsFromText(combinedText)};},[]);const writeText=useCallback(value=>{const hostElement=localRef.current;const target=getDeepestTextElement(hostElement);if(!target)return;if(lastWrittenTextRef.current===value)return;// Bail out on repeated values so observer callbacks caused by this write do not loop.\ntarget.textContent=value;lastWrittenTextRef.current=value;},[]);useEffect(()=>{if(isStatic)return;if(typeof window===\"undefined\"||typeof document===\"undefined\")return;let retries=0;let observer=null;let intervalId=null;let stopped=false;let lastWordCount=0;let stableHits=0;const stop=()=>{if(stopped)return;stopped=true;if(observer)observer.disconnect();if(intervalId!==null)window.clearInterval(intervalId);};const updateReadingTime=()=>{const hostElement=localRef.current;const fieldWordResult=getArticleBodyFieldWords();let words=0;if(fieldWordResult.hasAnyLayer){words=fieldWordResult.words;}else{const root=getArticleRoot(hostElement);if(!root){retries+=1;if(retries>=MAX_RETRIES)stop();return;}words=countWords(root,hostElement);}if(words<=0){retries+=1;if(retries>=MAX_RETRIES)stop();return;}if(words===lastWordCount){stableHits+=1;}else{lastWordCount=words;stableHits=1;}const minutes=getMinutesFromWords(words);const nextText=`${minutes} min read`;writeText(nextText);if(stableHits>=2){stop();}};// Keep the layer empty until an estimate is available.\nwriteText(\"\");updateReadingTime();observer=new MutationObserver(()=>{updateReadingTime();});observerRef.current=observer;observer.observe(document.body,{childList:true,subtree:true,characterData:true});intervalId=window.setInterval(()=>{updateReadingTime();if(retries>=MAX_RETRIES)stop();},RETRY_INTERVAL_MS);return()=>{stop();observerRef.current=null;};},[countWords,getArticleBodyFieldWords,getArticleRoot,isStatic,writeText]);return /*#__PURE__*/_jsx(Component,{ref:resolvedRef,...props});});}function isValidDate(value){const date=value instanceof Date?value:new Date(value);return date instanceof Date;}function isToday(str){const d=new Date(str);const now=new Date;return d.getFullYear()===now.getFullYear()&&d.getMonth()===now.getMonth()&&d.getDate()===now.getDate();}export function withCardReadingTime(Component){return /*#__PURE__*/forwardRef((props,ref)=>{const localRef=useRef(null);const observerRef=useRef(null);const originalLabelRef=useRef(null);const lastWrittenTextRef=useRef(\"\");const isStatic=useIsStaticRenderer();const[isTodaysDate,setIsTodaysDate]=useState(false);const resolvedRef=useCallback(node=>{localRef.current=node;setForwardedRef(ref,node);},[ref]);const findScopedCardRoot=useCallback(hostElement=>{let current=hostElement?.parentElement??null;while(current){const hasBodySource=Boolean(current.querySelector(BODY_TOP_SELECTOR)||current.querySelector(BODY_BOTTOM_SELECTOR));if(hasBodySource)return current;current=current.parentElement;}return null;},[]);const getCombinedWordCount=useCallback(scopeRoot=>{const bodyTop=scopeRoot.querySelector(BODY_TOP_SELECTOR);const bodyBottom=scopeRoot.querySelector(BODY_BOTTOM_SELECTOR);const topText=bodyTop?.textContent?.trim()??\"\";const bottomText=bodyBottom?.textContent?.trim()??\"\";const combined=`${topText} ${bottomText}`.trim();if(!combined)return 0;return countWordsFromText(combined);},[]);const getCurrentLabelFromDom=useCallback(hostElement=>{const text=getDeepestTextElement(hostElement)?.textContent?.trim()??\"\";return text;},[]);const stripExistingMinSuffix=useCallback(value=>{return value.replace(/\\s*·\\s*\\d+\\s+min$/i,\"\").trim();},[]);const writeText=useCallback(value=>{const hostElement=localRef.current;const target=getDeepestTextElement(hostElement);if(!target)return;if(lastWrittenTextRef.current===value)return;// Avoid feedback loops by skipping identical writes.\ntarget.textContent=value;lastWrittenTextRef.current=value;},[]);useEffect(()=>{if(isStatic)return;if(typeof window===\"undefined\"||typeof document===\"undefined\"){return;}let retries=0;let observer=null;let intervalId=null;let stopped=false;let lastWordCount=0;let stableHits=0;const stop=()=>{if(stopped)return;stopped=true;if(observer)observer.disconnect();if(intervalId!==null)window.clearInterval(intervalId);};const update=()=>{const hostElement=localRef.current;if(!hostElement){retries+=1;if(retries>=MAX_RETRIES)stop();return;}const scopeRoot=findScopedCardRoot(hostElement);if(!scopeRoot){retries+=1;if(retries>=MAX_RETRIES)stop();return;}const words=getCombinedWordCount(scopeRoot);if(words<=0){retries+=1;if(retries>=MAX_RETRIES)stop();return;}if(originalLabelRef.current===null){const fromProps=typeof props.children===\"string\"?props.children.trim():\"\";const fromDom=getCurrentLabelFromDom(hostElement);const candidate=fromProps||fromDom;originalLabelRef.current=stripExistingMinSuffix(candidate);}if(words===lastWordCount){stableHits+=1;}else{lastWordCount=words;stableHits=1;}const minutes=getMinutesFromWords(words);const originalLabel=originalLabelRef.current??\"\";const nextLabel=originalLabel?`${originalLabel} \\xb7 ${minutes} min`:`${minutes} min`;writeText(nextLabel);if(!observer){observer=new MutationObserver(()=>{update();});observerRef.current=observer;observer.observe(scopeRoot,{childList:true,subtree:true,characterData:true});}if(stableHits>=2){stop();}};update();intervalId=window.setInterval(()=>{update();if(retries>=MAX_RETRIES)stop();},RETRY_INTERVAL_MS);return()=>{stop();};},[findScopedCardRoot,getCombinedWordCount,getCurrentLabelFromDom,isStatic,props.children,stripExistingMinSuffix,writeText]);useEffect(()=>{const date=props.text?new Date(props.text):null;setIsTodaysDate(isToday(date));},[props.text]);if(isTodaysDate){return null;}return /*#__PURE__*/_jsx(Component,{ref:resolvedRef,...props});});}\nexport const __FramerMetadata__ = {\"exports\":{\"withReadingTime\":{\"type\":\"reactHoc\",\"name\":\"withReadingTime\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"WORDS_PER_MINUTE\":{\"type\":\"variable\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withCardReadingTime\":{\"type\":\"reactHoc\",\"name\":\"withCardReadingTime\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./ReadingTime.map"],"mappings":"0MAC6c,SAAS,EAAgB,EAAI,EAAK,CAAI,OAAO,GAAM,WAAY,EAAI,CAAI,EAAW,GAAK,OAAO,GAAM,WAAU,EAAI,QAAQ,EAAM,CAAC,SAAS,EAAmB,EAAK,CAAC,IAAM,EAAQ,EAAK,KAAK,EAAuB,OAAjB,EAAwB,EAAQ,MAAM,KAAK,CAAC,CAAC,OAAO,OAAO,CAAC,CAAC,OAA9C,CAAqD,CAAC,SAAS,EAAoB,EAAM,CAAC,OAAO,KAAK,IAAI,EAAE,KAAK,MAAM,EAAA,GAAsB,CAAC,CAAE,CAAC,SAAS,EAAsB,EAAY,CAAC,GAAG,CAAC,EAAY,OAAO,KAAK,IAAM,EAAW,EAAY,iBAAiB,GAAG,EAAE,IAAI,IAAI,EAAE,EAAW,OAAO,EAAE,GAAG,EAAE,IAAK,CAAC,IAAM,EAAQ,EAAW,GAA+J,GAAxI,MAA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