{"version":3,"file":"ExternalHTMLReader.B4fCiZwC.mjs","names":["useState","useMemo","useCallback"],"sources":["https:/framerusercontent.com/modules/sMBnIeGrhZZvyMbAl71O/Z1hQu1FHFmwU9y9b7Fct/ExternalHTMLReader.js"],"sourcesContent":["import{jsx as _jsx,jsxs as _jsxs}from\"react/jsx-runtime\";import{useCallback,useEffect,useMemo,useState,startTransition}from\"react\";import{addPropertyControls,ControlType,useIsStaticRenderer}from\"framer\";const CACHE_PREFIX=\"external-html-reader::\";function getCacheKey(fragmentUrl){return`${CACHE_PREFIX}${fragmentUrl}`;}function sanitizeAndResolveHtml(rawHtml,fragmentUrl){if(typeof window===\"undefined\")return\"\";const parser=new window.DOMParser;const parsed=parser.parseFromString(rawHtml,\"text/html\");const forbiddenSelectors=\"script, style, iframe, object, embed\";parsed.querySelectorAll(forbiddenSelectors).forEach(node=>node.remove());const allElements=parsed.querySelectorAll(\"*\");allElements.forEach(element=>{const attrs=Array.from(element.attributes);attrs.forEach(attr=>{const name=attr.name.toLowerCase();const value=attr.value.trim();if(name.startsWith(\"on\")){element.removeAttribute(attr.name);return;}if(name===\"href\"||name===\"src\"||name===\"xlink:href\"){if(/^\\s*javascript:/i.test(value)){element.removeAttribute(attr.name);return;}try{const resolved=new URL(value,fragmentUrl).toString();element.setAttribute(attr.name,resolved);}catch(_error){// Keep original safe-looking value if resolution fails.\n}}});});return parsed.body.innerHTML;}/**\n * @framerSupportedLayoutWidth any-prefer-fixed\n * @framerSupportedLayoutHeight auto\n */export default function ExternalHTMLReader(props){const{fragmentUrl,pdfUrl,loadingText,errorText,refreshMinutes}=props;const isStatic=useIsStaticRenderer();const[content,setContent]=useState(\"\");const[isLoading,setIsLoading]=useState(true);const[isRefreshing,setIsRefreshing]=useState(false);const[error,setError]=useState(\"\");const refreshMs=useMemo(()=>Math.max(1,refreshMinutes)*60*1e3,[refreshMinutes]);const readCache=useCallback(()=>{if(typeof window===\"undefined\"||!fragmentUrl)return null;try{const raw=window.sessionStorage.getItem(getCacheKey(fragmentUrl));if(!raw)return null;const parsed=JSON.parse(raw);if(typeof parsed?.html!==\"string\"||typeof parsed?.timestamp!==\"number\"){return null;}return parsed;}catch(_error){return null;}},[fragmentUrl]);const writeCache=useCallback(html=>{if(typeof window===\"undefined\"||!fragmentUrl)return;try{const payload={html,timestamp:Date.now()};window.sessionStorage.setItem(getCacheKey(fragmentUrl),JSON.stringify(payload));}catch(_error){// Ignore storage quota and privacy-mode failures.\n}},[fragmentUrl]);const fetchAndSanitize=useCallback(async()=>{const response=await fetch(fragmentUrl,{method:\"GET\",credentials:\"omit\"});if(!response.ok){throw new Error(`Request failed with status ${response.status}`);}const htmlText=await response.text();return sanitizeAndResolveHtml(htmlText,fragmentUrl);},[fragmentUrl]);useEffect(()=>{if(!fragmentUrl){startTransition(()=>{setIsLoading(false);setIsRefreshing(false);setError(errorText);});return;}if(typeof window===\"undefined\"||isStatic){startTransition(()=>{setIsLoading(false);setIsRefreshing(false);setError(errorText);setContent(\"\");});return;}let active=true;const cached=readCache();const hasCached=Boolean(cached?.html);const cacheAge=cached?Date.now()-cached.timestamp:Number.POSITIVE_INFINITY;const isFresh=cacheAge<=refreshMs;if(hasCached&&cached){startTransition(()=>{setContent(cached.html);setError(\"\");setIsLoading(false);});}else{startTransition(()=>{setIsLoading(true);setError(\"\");});}const shouldFetch=!hasCached||!isFresh;if(!shouldFetch)return;startTransition(()=>{setIsRefreshing(hasCached);if(!hasCached)setIsLoading(true);});fetchAndSanitize().then(safeHtml=>{if(!active)return;writeCache(safeHtml);startTransition(()=>{setContent(safeHtml);setError(\"\");setIsLoading(false);setIsRefreshing(false);});}).catch(()=>{if(!active)return;startTransition(()=>{if(!hasCached)setError(errorText);setIsLoading(false);setIsRefreshing(false);});});return()=>{active=false;};},[errorText,fetchAndSanitize,fragmentUrl,isStatic,readCache,refreshMs,writeCache]);const showErrorOnly=!isLoading&&!!error&&!content;return /*#__PURE__*/_jsxs(\"section\",{style:{position:\"relative\",width:\"100%\",maxWidth:900,margin:\"0 auto\",boxSizing:\"border-box\",background:\"#FFFFFF\",color:\"#2C3643\",padding:\"16px\"},role:\"region\",\"aria-live\":\"polite\",children:[/*#__PURE__*/_jsx(\"style\",{children:`\n                .ehr-content {\n                    color: #2C3643;\n                    line-height: 1.7;\n                    font-size: 18px;\n                    word-break: normal;\n                    overflow-wrap: anywhere;\n                }\n                .ehr-content h1, .ehr-content h2, .ehr-content h3, .ehr-content h4, .ehr-content h5, .ehr-content h6 {\n                    color: #0D2A56;\n                    line-height: 1.25;\n                    margin-top: 1.4em;\n                    margin-bottom: 0.5em;\n                }\n                .ehr-content p, .ehr-content ul, .ehr-content ol, .ehr-content blockquote {\n                    margin-top: 0.75em;\n                    margin-bottom: 0.75em;\n                }\n                .ehr-content a {\n                    color: #008080;\n                    text-decoration: underline;\n                    text-underline-offset: 2px;\n                }\n                .ehr-content img {\n                    max-width: 100%;\n                    height: auto;\n                }\n                .ehr-content table {\n                    width: 100%;\n                    border-collapse: collapse;\n                    display: block;\n                    overflow-x: auto;\n                    -webkit-overflow-scrolling: touch;\n                    white-space: nowrap;\n                }\n                .ehr-content th, .ehr-content td {\n                    border: 1px solid #EEEEEE;\n                    padding: 8px 10px;\n                    text-align: left;\n                }\n                .ehr-content code, .ehr-content pre {\n                    max-width: 100%;\n                    overflow-x: auto;\n                }\n                .ehr-status {\n                    color: #2C3643;\n                    font-size: 15px;\n                    line-height: 1.4;\n                    margin-bottom: 12px;\n                }\n            `}),isLoading&&!content?/*#__PURE__*/_jsx(\"p\",{className:\"ehr-status\",children:loadingText}):null,isRefreshing&&content?/*#__PURE__*/_jsx(\"p\",{className:\"ehr-status\",children:loadingText}):null,showErrorOnly?/*#__PURE__*/_jsxs(\"div\",{role:\"status\",className:\"ehr-status\",children:[/*#__PURE__*/_jsx(\"p\",{style:{margin:0},children:errorText}),pdfUrl?/*#__PURE__*/_jsx(\"p\",{style:{marginTop:10,marginBottom:0},children:/*#__PURE__*/_jsx(\"a\",{href:pdfUrl,target:\"_blank\",rel:\"noreferrer\",children:\"Open the original PDF\"})}):null]}):null,content?/*#__PURE__*/_jsx(\"article\",{className:\"ehr-content\",dangerouslySetInnerHTML:{__html:content}}):null]});}addPropertyControls(ExternalHTMLReader,{fragmentUrl:{type:ControlType.String,title:\"Fragment URL\",defaultValue:\"https://example.com/reading-fragment.html\"},pdfUrl:{type:ControlType.String,title:\"PDF URL\",defaultValue:\"https://example.com/original-document.pdf\"},loadingText:{type:ControlType.String,title:\"Loading Text\",defaultValue:\"Loading document…\"},errorText:{type:ControlType.String,title:\"Error Text\",defaultValue:\"The HTML reading version is currently unavailable.\"},refreshMinutes:{type:ControlType.Number,title:\"Refresh (min)\",defaultValue:15,min:1,max:120,step:1}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"ExternalHTMLReader\",\"slots\":[],\"annotations\":{\"framerSupportedLayoutHeight\":\"auto\",\"framerContractVersion\":\"1\",\"framerSupportedLayoutWidth\":\"any-prefer-fixed\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./ExternalHTMLReader.map"],"mappings":"8NAAuP,SAAS,EAAY,EAAY,CAAC,MAAM,GAAG,IAAe,GAAc,CAAC,SAAS,EAAuB,EAAQ,EAAY,CAAC,GAAU,IAAS,OAAY,MAAM,GAAqC,IAAM,EAAO,IAA9B,EAAO,UAA4B,CAAC,CAAC,gBAAgB,EAAQ,WAAW,EAC9e,OADgjB,EAAO,iBAAiB,sCAAkB,CAAC,CAAC,QAAQ,GAAM,EAAK,OAAO,CAAC,EAAiD,EAAtB,iBAAiB,GAAe,CAAC,CAAC,QAAQ,GAAS,CAA4C,MAAzB,KAAK,EAAQ,UAAgB,CAAC,CAAC,QAAQ,GAAM,CAAC,IAAM,EAAK,EAAK,KAAK,YAAY,EAAQ,EAAM,EAAK,MAAM,KAAK,EAAE,GAAG,EAAK,WAAW,IAAI,EAAE,CAAC,EAAQ,gBAAgB,EAAK,IAAI,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