lazy-react 3.6.2 → 3.6.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2022 Jonathan Obino
3
+ Copyright (c) 2026 Jonathan Obino
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- var e,t=require("react/jsx-runtime"),n=require("react");function r(e,t,n,r){Object.defineProperty(e,t,{get:n,set:r,enumerable:!0,configurable:!0})}function l(e){const[r,l,s]=u(e),[i,o]=(0,n.useState)({backgroundImage:`url(${l})`,...e.style});return(0,n.useEffect)((()=>{s&&o({backgroundImage:`url(${l})`,...e.style})}),[l,s,e.style]),(0,t.jsx)("div",{className:e.className,style:i,ref:e=>{r(e)},children:e.children})}function s(e){const[n,r]=u(e);return(0,t.jsx)("div",{ref:e=>{n(e)},children:(0,t.jsx)("img",{src:r,alt:e.alt,style:e.style,className:e.className})})}function i(e){const[n,r]=u(e);return(0,t.jsx)("iframe",{src:r,ref:e=>{n(e)},...e,height:e.height||"500",allowFullScreen:e.allowFullScreen||!0})}function o(e){const[n,r,l]=u(e);return l?(0,t.jsx)("div",{children:e.children}):(0,t.jsx)("div",{ref:e=>{n(e)},style:{height:"300px",width:"300px",...e.style}})}e=module.exports,Object.defineProperty(e,"__esModule",{value:!0,configurable:!0}),r(module.exports,"default",(()=>u)),r(module.exports,"LazyBackgroundImage",(()=>l)),r(module.exports,"LazyImage",(()=>s)),r(module.exports,"LazyFrame",(()=>i)),r(module.exports,"LazyComponent",(()=>o));const a=new Set,c={isInViewPort:({offset:e,top:t,left:n})=>t<window.innerHeight+e&&n<window.innerWidth+e,calculateNewPosition:e=>{const{top:t,left:n}=e.element?.getBoundingClientRect()||{top:0,left:0};return{...e,top:t,left:n}},addElement:e=>{a.add(e),0===c.isListenerAttached&&(c.isListenerAttached=window.requestAnimationFrame(c.eventHandler))},eventHandler:()=>{0===a.size?c.removeScrollHandler():(a.forEach((e=>{c.isInViewPort(c.calculateNewPosition(e))&&(e.makeItVisible(),c.removeElementFromList(e))})),c.isListenerAttached=window.requestAnimationFrame(c.eventHandler))},removeScrollHandler:()=>{window.cancelAnimationFrame(c.isListenerAttached),c.isListenerAttached=0},removeElementFromList:e=>{a.delete(e)},isListenerAttached:0};function u(e){const[t,r]=(0,n.useState)(""),[l,s]=(0,n.useState)(!1),[i,o]=(0,n.useState)(null),a=(0,n.useCallback)((()=>{e.link&&r((()=>e.link)),s((()=>!0))}),[e.link]),u=(0,n.useMemo)((()=>({element:i,makeItVisible:a,offset:e.offset||100})),[i,e.offset,a]),d=(0,n.useCallback)((e=>{null!==e&&o(e)}),[]);return(0,n.useEffect)((()=>(null!==i&&c.addElement(u),()=>c.removeElementFromList(u))),[i,u]),[d,t,l]}
1
+ var $9w1Q4$reactjsxruntime=require("react/jsx-runtime"),$9w1Q4$react=require("react");function $parcel$defineInteropFlag(e){Object.defineProperty(e,"__esModule",{value:!0,configurable:!0})}function $parcel$export(e,t,r,$){Object.defineProperty(e,t,{get:r,set:$,enumerable:!0,configurable:!0})}function $6e38eea936045ca0$export$2e2bcd8739ae039(e){let[t,r,$]=$03b515f3f8c77d8f$export$2e2bcd8739ae039(e),[f,c]=(0,$9w1Q4$react.useState)({backgroundImage:`url(${r})`,...e.style});return(0,$9w1Q4$react.useEffect)(()=>{$&&c({backgroundImage:`url(${r})`,...e.style})},[r,$,e.style]),(0,$9w1Q4$reactjsxruntime.jsx)("div",{className:e.className,style:f,ref:e=>{t(e)},children:e.children})}function $f6f596272f209e0c$export$2e2bcd8739ae039(e){let[t,r]=$03b515f3f8c77d8f$export$2e2bcd8739ae039(e);return(0,$9w1Q4$reactjsxruntime.jsx)("div",{ref:e=>{t(e)},children:(0,$9w1Q4$reactjsxruntime.jsx)("img",{src:r,alt:e.alt,style:e.style,className:e.className,title:e.title})})}function $8e3d626f2d1eebd8$export$2e2bcd8739ae039(e){let[t,r]=$03b515f3f8c77d8f$export$2e2bcd8739ae039(e);return(0,$9w1Q4$reactjsxruntime.jsx)("iframe",{src:r,ref:e=>{t(e)},...e,height:e.height||"500",allowFullScreen:e.allowFullScreen||!0})}function $c17687259f8b5ddf$export$2e2bcd8739ae039(e){let[t,r,$]=$03b515f3f8c77d8f$export$2e2bcd8739ae039(e);return $?(0,$9w1Q4$reactjsxruntime.jsx)("div",{children:e.children}):(0,$9w1Q4$reactjsxruntime.jsx)("div",{ref:e=>{t(e)},style:{height:"300px",width:"300px",...e.style}})}$parcel$defineInteropFlag(module.exports),$parcel$export(module.exports,"default",()=>$03b515f3f8c77d8f$export$2e2bcd8739ae039),$parcel$export(module.exports,"LazyBackgroundImage",()=>$6e38eea936045ca0$export$2e2bcd8739ae039),$parcel$export(module.exports,"LazyImage",()=>$f6f596272f209e0c$export$2e2bcd8739ae039),$parcel$export(module.exports,"LazyFrame",()=>$8e3d626f2d1eebd8$export$2e2bcd8739ae039),$parcel$export(module.exports,"LazyComponent",()=>$c17687259f8b5ddf$export$2e2bcd8739ae039);const $03b515f3f8c77d8f$var$elements=new Set,$03b515f3f8c77d8f$var$CheckIfRender={isInViewPort:({offset:e,top:t,left:r})=>t<window.innerHeight+e&&r<window.innerWidth+e,calculateNewPosition:e=>{let{top:t,left:r}=e.element?.getBoundingClientRect()||{top:0,left:0};return{...e,top:t,left:r}},addElement:e=>{$03b515f3f8c77d8f$var$elements.add(e),0===$03b515f3f8c77d8f$var$CheckIfRender.isListenerAttached&&($03b515f3f8c77d8f$var$CheckIfRender.isListenerAttached=window.requestAnimationFrame($03b515f3f8c77d8f$var$CheckIfRender.eventHandler))},eventHandler:()=>{0===$03b515f3f8c77d8f$var$elements.size?$03b515f3f8c77d8f$var$CheckIfRender.removeScrollHandler():($03b515f3f8c77d8f$var$elements.forEach(e=>{$03b515f3f8c77d8f$var$CheckIfRender.isInViewPort($03b515f3f8c77d8f$var$CheckIfRender.calculateNewPosition(e))&&(e.makeItVisible(),$03b515f3f8c77d8f$var$CheckIfRender.removeElementFromList(e))}),$03b515f3f8c77d8f$var$CheckIfRender.isListenerAttached=window.requestAnimationFrame($03b515f3f8c77d8f$var$CheckIfRender.eventHandler))},removeScrollHandler:()=>{window.cancelAnimationFrame($03b515f3f8c77d8f$var$CheckIfRender.isListenerAttached),$03b515f3f8c77d8f$var$CheckIfRender.isListenerAttached=0},removeElementFromList:e=>{$03b515f3f8c77d8f$var$elements.delete(e)},isListenerAttached:0};function $03b515f3f8c77d8f$export$2e2bcd8739ae039(e){let[t,r]=(0,$9w1Q4$react.useState)(""),[$,f]=(0,$9w1Q4$react.useState)(!1),[c,a]=(0,$9w1Q4$react.useState)(null),n=(0,$9w1Q4$react.useCallback)(()=>{e.link&&r(()=>e.link),f(()=>!0)},[e.link]),d=(0,$9w1Q4$react.useMemo)(()=>({element:c,makeItVisible:n,offset:e.offset||100}),[c,e.offset,n]),l=(0,$9w1Q4$react.useCallback)(e=>{null!==e&&a(e)},[]);return(0,$9w1Q4$react.useEffect)(()=>(null!==c&&$03b515f3f8c77d8f$var$CheckIfRender.addElement(d),()=>$03b515f3f8c77d8f$var$CheckIfRender.removeElementFromList(d)),[c,d]),[l,t,$]}
2
2
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"mappings":"mJAWe,SAAAA,EAA6BC,GAC3C,MAAOC,EAAQC,EAAMC,GAAcC,EAAgBJ,IAE5CK,EAAOC,IAAY,EAAAC,EAAAC,UAAS,CAClCC,gBAAiB,OAAOP,QACrBF,EAAMK,QAYV,OATA,EAAAE,EAAAG,YAAU,KACTP,GACGG,EAAS,CACTG,gBAAiB,OAAOP,QACrBF,EAAMK,OACR,GAEF,CAACH,EAAMC,EAAYH,EAAMK,SAG3B,EAAAM,EAAAC,KAAC,MAAG,CACHC,UAAWb,EAAMa,UACjBR,MAAOA,EACPS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ACZjB,EAAckB,uBAEdpB,EAASqB,SAASV,IACET,EAAcC,aAChCD,EAAcQ,qBAAqBC,MAGnCA,EAAKW,gBAELpB,EAAcqB,sBAAsBZ,G,IAGtCT,EAAcc,mBAAqBT,OAAOU,sBACzCf,EAAcgB,c,EAKjBE,oBAAqB,KACpBb,OAAOiB,qBAAqBtB,EAAcc,oBAC1Cd,EAAcc,mBAAqB,CAAC,EAGrCO,sBAAwBE,IACvBzB,EAAS0B,OAAOD,EAAS,EAE1BT,mBAAoB,GAGN,SAAAvC,EAA+BJ,GAI7C,MAAOE,EAAMoD,IAAW,EAAA/C,EAAAC,UAAS,KAC1B+C,EAASC,IAAc,EAAAjD,EAAAC,WAAS,IAEhCM,EAAKb,IAAU,EAAAM,EAAAC,UAAgC,MAEhDyC,GAAgB,EAAA1C,EAAAkD,cAAY,KAC7BzD,EAAME,MAAMoD,GAAQ,IAAMtD,EAAME,OACpCsD,GAAW,KAAM,GAAK,GACpB,CAACxD,EAAME,OAEJwD,GAAe,EAAAnD,EAAAoD,UAAQ,KACrB,CACNpB,QAASzB,E,cACTmC,EACAlB,OAAQ/B,EAAM+B,QAAU,OAEvB,CAACjB,EAAKd,EAAM+B,OAAQkB,IAEjBW,GAAS,EAAArD,EAAAkD,cAAa1C,IACd,OAATA,GAAed,EAAOc,EAAK,GAC7B,IAWH,OATA,EAAAR,EAAAG,YAAU,KACG,OAARI,GAEHe,EAAcY,WAAWiB,GACnB,IAEN7B,EAAcqB,sBAAsBQ,KACnC,CAAC5C,EAAK4C,IAEF,CAACE,EAAQ1D,EAAMqD,E","sources":["src/lazyLoadBackgroundImage.tsx","src/lazyLoadImage.tsx","src/lazyLoadFrame.tsx","src/lazyLoadComponent.tsx","src/useIsInViewport.tsx"],"sourcesContent":["import { useState, useEffect, type ReactNode } from 'react'\nimport useIsInViewPort from './index'\n\ninterface LazyBackgroundImageProps {\n\tlink: string\n\toffset: number\n\tstyle: object\n\tclassName: string\n\tchildren: ReactNode,\n}\n\nexport default function LazyBackgroundImage(props: LazyBackgroundImageProps) {\n\tconst [setRef, link, isViewable] = useIsInViewPort(props)\n\n\tconst [style, setStyle] = useState({\n\t\tbackgroundImage: `url(${link})`,\n\t\t...props.style,\n\t})\n\n\tuseEffect(() => {\n\t\tisViewable\n\t\t\t? setStyle({\n\t\t\t\t\tbackgroundImage: `url(${link})`,\n\t\t\t\t\t...props.style,\n\t\t\t\t})\n\t\t\t: null\n\t}, [link, isViewable, props.style])\n\n\treturn (\n\t\t<div\n\t\t\tclassName={props.className}\n\t\t\tstyle={style}\n\t\t\tref={(node) => {\n\t\t\t\tsetRef(node)\n\t\t\t}}\n\t\t>\n\t\t\t{props.children}\n\t\t</div>\n\t)\n}\n","import useIsInViewPort from './index'\n\ninterface LazyImageProps {\n link: string,\n offset: number,\n alt: string,\n style: object,\n className: string\n}\n\nexport default function LazyImage(props: LazyImageProps) {\n\tconst [setRef, link] = useIsInViewPort(props)\n\n\treturn (\n\t\t<div\n\t\t\tref={(node) => {\n\t\t\t\tsetRef(node)\n\t\t\t}}\n\t\t>\n\t\t\t<img\n\t\t\t\tsrc={link}\n\t\t\t\talt={props.alt}\n\t\t\t\tstyle={props.style}\n\t\t\t\tclassName={props.className}\n\t\t\t/>\n\t\t</div>\n\t)\n}\n","import useIsInViewPort from './index'\n\ninterface LazyFrameProps {\n\theight: number\n\tlink: string\n\toffset: number\n\tallowFullScreen: boolean,\n}\n\nexport default function LazyFrame(props: LazyFrameProps) {\n\tconst [setRef, link] = useIsInViewPort(props)\n\n\treturn (\n\t\t<iframe\n\t\t\t// scrolling={props.scrolling || 'no'}\n\t\t\tsrc={link}\n\t\t\t// frameBorder={props.frameBorder || 'no'}\n\t\t\t// style={props.style || {border: props.frameBorder}}\n\t\t\tref={(node) => {\n\t\t\t\tsetRef(node)\n\t\t\t}}\n\t\t\t{...props}\n\t\t\theight={props.height || '500'}\n\t\t\tallowFullScreen={props.allowFullScreen || true}\n\t\t/>\n\t)\n}\n","import type { ReactNode } from 'react'\nimport useIsInViewport from './index'\n\ninterface LazyComponentProps {\n link: string,\n offset: number,\n style: object,\n children: ReactNode\n}\n\nexport default function LazyComponent(props: LazyComponentProps) {\n\tconst [setRef, _, isVisible] = useIsInViewport(props)\n\n\tif (!isVisible)\n\t\treturn (\n\t\t\t<div\n\t\t\t\tref={(node) => {\n\t\t\t\t\tsetRef(node)\n\t\t\t\t}}\n\t\t\t\tstyle={{\n\t\t\t\t\theight: '300px',\n\t\t\t\t\twidth: '300px',\n\t\t\t\t\t...props.style,\n\t\t\t\t}}\n\t\t\t></div>\n\t\t)\n\n\treturn <div>{props.children}</div>\n}\n","import { useState, useEffect, useMemo, useCallback } from 'react'\n\ninterface InstanceElement {\n\tmakeItVisible: () => void\n\telement: HTMLElement | null\n\toffset: number\n}\n\n// array with all the elements that are waiting to be shown in the viewport\nconst elements = new Set<InstanceElement>()\n\nconst CheckIfRender = {\n\t// top: the position of the element in relation with the top of the browser\n\t// left: the position of the element in relation with the left of the browser\n\t// offset: the desired offset of the element in relation of the viewport\n\tisInViewPort: ({\n\t\toffset,\n\t\ttop,\n\t\tleft,\n\t}: {\n\t\toffset: number\n\t\ttop: number\n\t\tleft: number\n\t}) => top < window.innerHeight + offset && left < window.innerWidth + offset,\n\n\tcalculateNewPosition: (elem: InstanceElement) => {\n\t\tconst { top, left } = elem.element?.getBoundingClientRect() || {\n\t\t\ttop: 0,\n\t\t\tleft: 0,\n\t\t}\n\n\t\treturn {\n\t\t\t...elem,\n\t\t\ttop,\n\t\t\tleft,\n\t\t}\n\t},\n\taddElement: (element: InstanceElement) => {\n\t\t//the distance from the pixel 0,0 and the top of the element\n\t\telements.add(element)\n\t\t//check if has already been started the rAF cycle\n\t\tif (CheckIfRender.isListenerAttached === 0) {\n\t\t\tCheckIfRender.isListenerAttached = window.requestAnimationFrame(\n\t\t\t\tCheckIfRender.eventHandler,\n\t\t\t)\n\t\t}\n\t},\n\teventHandler: () => {\n\t\t//if there is no more element to lazy load remove the listener/rAF\n\t\tif (elements.size === 0) {\n\t\t\tCheckIfRender.removeScrollHandler()\n\t\t} else {\n\t\t\telements.forEach((elem) => {\n\t\t\t\tconst haveToShow = CheckIfRender.isInViewPort(\n\t\t\t\t\tCheckIfRender.calculateNewPosition(elem),\n\t\t\t\t)\n\t\t\t\tif (haveToShow) {\n\t\t\t\t\telem.makeItVisible()\n\t\t\t\t\t// remove element from the list of elements to lazy load\n\t\t\t\t\tCheckIfRender.removeElementFromList(elem)\n\t\t\t\t}\n\t\t\t})\n\t\t\tCheckIfRender.isListenerAttached = window.requestAnimationFrame(\n\t\t\t\tCheckIfRender.eventHandler,\n\t\t\t)\n\t\t}\n\t},\n\n\tremoveScrollHandler: () => {\n\t\twindow.cancelAnimationFrame(CheckIfRender.isListenerAttached)\n\t\tCheckIfRender.isListenerAttached = 0\n\t},\n\t//When an element is unloaded remove it from the list of elements that are waiting to be lazy-loaded\n\tremoveElementFromList: (toRemove: InstanceElement) => {\n\t\telements.delete(toRemove)\n\t},\n\tisListenerAttached: 0, // intended as not set\n}\n\nexport default function useRenderIfInViewPort(props: {\n\tlink: string\n\toffset: number\n}): [(node: HTMLDivElement | null) => void, string, boolean] {\n\tconst [link, setLink] = useState('')\n\tconst [visible, setVisible] = useState(false)\n\n\tconst [ref, setRef] = useState<HTMLDivElement | null>(null)\n\n\tconst makeItVisible = useCallback(() => {\n\t\tif (props.link) setLink(() => props.link)\n\t\tsetVisible(() => true)\n\t}, [props.link])\n\n\tconst thisInstance = useMemo(() => {\n\t\treturn {\n\t\t\telement: ref,\n\t\t\tmakeItVisible,\n\t\t\toffset: props.offset || 100,\n\t\t}\n\t}, [ref, props.offset, makeItVisible])\n\n\tconst getRef = useCallback((node: HTMLDivElement | null) => {\n\t\tif (node !== null) setRef(node)\n\t}, [])\n\n\tuseEffect(() => {\n\t\tif (ref !== null)\n\t\t\t// add the element to the array of elements that are waiting to be lazy loaded\n\t\t\tCheckIfRender.addElement(thisInstance)\n\t\treturn () =>\n\t\t\t// if the element is unloaded remove the element from the list of elements that needs to be lazy loader\n\t\t\tCheckIfRender.removeElementFromList(thisInstance)\n\t}, [ref, thisInstance])\n\n\treturn [getRef, link, visible]\n}\n\n"],"names":["$6e38eea936045ca0$export$2e2bcd8739ae039","props","setRef","link","isViewable","$03b515f3f8c77d8f$export$2e2bcd8739ae039","style","setStyle","$9w1Q4$react","useState","backgroundImage","useEffect","$9w1Q4$reactjsxruntime","jsx","className","ref","node","children","$f6f596272f209e0c$export$2e2bcd8739ae039","src","alt","$8e3d626f2d1eebd8$export$2e2bcd8739ae039","height","allowFullScreen","$c17687259f8b5ddf$export$2e2bcd8739ae039","_","isVisible","width","$03b515f3f8c77d8f$var$elements","Set","$03b515f3f8c77d8f$var$CheckIfRender","isInViewPort","offset","top","left","window","innerHeight","innerWidth","calculateNewPosition","elem","element","getBoundingClientRect","addElement","add","isListenerAttached","requestAnimationFrame","eventHandler","size","removeScrollHandler","forEach","makeItVisible","removeElementFromList","cancelAnimationFrame","toRemove","delete","setLink","visible","setVisible","useCallback","thisInstance","useMemo","getRef"],"version":3,"file":"index.js.map"}
1
+ {"mappings":"A,I,uB,Q,qB,a,Q,S,S,0B,C,E,O,c,C,E,a,C,M,C,E,a,C,C,E,C,S,e,C,C,C,C,C,C,C,E,O,c,C,E,E,C,I,E,I,E,W,C,E,a,C,C,E,CEWe,SAAA,yCAA6B,CAA+B,EAC1E,GAAM,CAAC,EAAQ,EAAM,EAAW,CAAG,AAAA,yCAAgB,GAE7C,CAAC,EAAO,EAAS,CAAG,AAAA,CAAA,EAAA,aAAA,QAAO,AAAP,EAAS,CAClC,gBAAiB,CAAC,IAAI,EAAE,EAAK,CAAC,CAAC,CAC/B,GAAG,EAAM,KAAK,AACf,GAWA,MATA,AAAA,CAAA,EAAA,aAAA,SAAQ,AAAR,EAAU,KACT,GACG,EAAS,CACT,gBAAiB,CAAC,IAAI,EAAE,EAAK,CAAC,CAAC,CAC/B,GAAG,EAAM,KAAK,AACf,EAEH,EAAG,CAAC,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A,EAAA,aAAA,QAAO,AAAP,EAAgC,MAEhD,EAAgB,AAAA,CAAA,EAAA,aAAA,WAAU,AAAV,EAAY,KAC7B,EAAM,IAAI,EAAE,EAAQ,IAAM,EAAM,IAAI,EACxC,EAAW,IAAM,CAAA,EAClB,EAAG,CAAC,EAAM,IAAI,CAAC,EAET,EAAe,AAAA,CAAA,EAAA,aAAA,OAAM,AAAN,EAAQ,IACrB,CAAA,CACN,QAAS,EACT,cAAA,EACA,OAAQ,EAAM,MAAM,EAAI,GACzB,CAAA,EACE,CAAC,EAAK,EAAM,MAAM,CAAE,EAAc,EAE/B,EAAS,AAAA,CAAA,EAAA,aAAA,WAAU,AAAV,EAAY,AAAC,IACvB,AAAS,OAAT,GAAe,EAAO,EAC3B,EAAG,EAAE,EAWL,MATA,AAAA,CAAA,EAAA,aAAA,SAAQ,AAAR,EAAU,KACL,AAAQ,OAAR,GAEH,oCAAc,UAAU,CAAC,GACnB,IAEN,oCAAc,qBAAqB,CAAC,IACnC,CAAC,EAAK,EAAa,EAEf,CAAC,EAAQ,EAAM,EAAQ,AAC/B","sources":["<anon>","src/index.tsx","src/lazyLoadBackgroundImage.tsx","src/lazyLoadImage.tsx","src/lazyLoadFrame.tsx","src/lazyLoadComponent.tsx","src/useIsInViewport.tsx"],"sourcesContent":["var $9w1Q4$reactjsxruntime = require(\"react/jsx-runtime\");\nvar $9w1Q4$react = require(\"react\");\n\n\nfunction $parcel$defineInteropFlag(a) {\n Object.defineProperty(a, '__esModule', {value: true, configurable: true});\n}\n\nfunction $parcel$export(e, n, v, s) {\n Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});\n}\n\n$parcel$defineInteropFlag(module.exports);\n\n$parcel$export(module.exports, \"default\", () => $03b515f3f8c77d8f$export$2e2bcd8739ae039);\n$parcel$export(module.exports, \"LazyBackgroundImage\", () => $6e38eea936045ca0$export$2e2bcd8739ae039);\n$parcel$export(module.exports, \"LazyImage\", () => $f6f596272f209e0c$export$2e2bcd8739ae039);\n$parcel$export(module.exports, \"LazyFrame\", () => $8e3d626f2d1eebd8$export$2e2bcd8739ae039);\n$parcel$export(module.exports, \"LazyComponent\", () => $c17687259f8b5ddf$export$2e2bcd8739ae039);\n\n\n\nfunction $6e38eea936045ca0$export$2e2bcd8739ae039(props) {\n const [setRef, link, isViewable] = (0, $03b515f3f8c77d8f$export$2e2bcd8739ae039)(props);\n const [style, setStyle] = (0, $9w1Q4$react.useState)({\n backgroundImage: `url(${link})`,\n ...props.style\n });\n (0, $9w1Q4$react.useEffect)(()=>{\n isViewable && setStyle({\n backgroundImage: `url(${link})`,\n ...props.style\n });\n }, [\n link,\n isViewable,\n props.style\n ]);\n return /*#__PURE__*/ (0, $9w1Q4$reactjsxruntime.jsx)(\"div\", {\n className: props.className,\n style: style,\n ref: (node)=>{\n setRef(node);\n },\n children: props.children\n });\n}\n\n\n\n\nfunction $f6f596272f209e0c$export$2e2bcd8739ae039(props) {\n const [setRef, link] = (0, $03b515f3f8c77d8f$export$2e2bcd8739ae039)(props);\n return /*#__PURE__*/ (0, $9w1Q4$reactjsxruntime.jsx)(\"div\", {\n ref: (node)=>{\n setRef(node);\n },\n children: /*#__PURE__*/ (0, $9w1Q4$reactjsxruntime.jsx)(\"img\", {\n src: link,\n alt: props.alt,\n style: props.style,\n className: props.className,\n title: props.title\n })\n });\n}\n\n\n\n\nfunction $8e3d626f2d1eebd8$export$2e2bcd8739ae039(props) {\n const [setRef, link] = (0, $03b515f3f8c77d8f$export$2e2bcd8739ae039)(props);\n return /*#__PURE__*/ (0, $9w1Q4$reactjsxruntime.jsx)(\"iframe\", {\n // scrolling={props.scrolling || 'no'}\n src: link,\n // frameBorder={props.frameBorder || 'no'}\n // style={props.style || {border: props.frameBorder}}\n ref: (node)=>{\n setRef(node);\n },\n ...props,\n height: props.height || '500',\n allowFullScreen: props.allowFullScreen || true\n });\n}\n\n\n\n\nfunction $c17687259f8b5ddf$export$2e2bcd8739ae039(props) {\n const [setRef, _, isVisible] = (0, $03b515f3f8c77d8f$export$2e2bcd8739ae039)(props);\n if (!isVisible) return /*#__PURE__*/ (0, $9w1Q4$reactjsxruntime.jsx)(\"div\", {\n ref: (node)=>{\n setRef(node);\n },\n style: {\n height: '300px',\n width: '300px',\n ...props.style\n }\n });\n return /*#__PURE__*/ (0, $9w1Q4$reactjsxruntime.jsx)(\"div\", {\n children: props.children\n });\n}\n\n\n\n// array with all the elements that are waiting to be shown in the viewport\nconst $03b515f3f8c77d8f$var$elements = new Set();\nconst $03b515f3f8c77d8f$var$CheckIfRender = {\n // top: the position of the element in relation with the top of the browser\n // left: the position of the element in relation with the left of the browser\n // offset: the desired offset of the element in relation of the viewport\n isInViewPort: ({ offset: offset, top: top, left: left })=>top < window.innerHeight + offset && left < window.innerWidth + offset,\n calculateNewPosition: (elem)=>{\n const { top: top, left: left } = elem.element?.getBoundingClientRect() || {\n top: 0,\n left: 0\n };\n return {\n ...elem,\n top: top,\n left: left\n };\n },\n addElement: (element)=>{\n //the distance from the pixel 0,0 and the top of the element\n $03b515f3f8c77d8f$var$elements.add(element);\n //check if has already been started the rAF cycle\n if ($03b515f3f8c77d8f$var$CheckIfRender.isListenerAttached === 0) $03b515f3f8c77d8f$var$CheckIfRender.isListenerAttached = window.requestAnimationFrame($03b515f3f8c77d8f$var$CheckIfRender.eventHandler);\n },\n eventHandler: ()=>{\n //if there is no more element to lazy load remove the listener/rAF\n if ($03b515f3f8c77d8f$var$elements.size === 0) $03b515f3f8c77d8f$var$CheckIfRender.removeScrollHandler();\n else {\n $03b515f3f8c77d8f$var$elements.forEach((elem)=>{\n const haveToShow = $03b515f3f8c77d8f$var$CheckIfRender.isInViewPort($03b515f3f8c77d8f$var$CheckIfRender.calculateNewPosition(elem));\n if (haveToShow) {\n elem.makeItVisible();\n // remove element from the list of elements to lazy load\n $03b515f3f8c77d8f$var$CheckIfRender.removeElementFromList(elem);\n }\n });\n $03b515f3f8c77d8f$var$CheckIfRender.isListenerAttached = window.requestAnimationFrame($03b515f3f8c77d8f$var$CheckIfRender.eventHandler);\n }\n },\n removeScrollHandler: ()=>{\n window.cancelAnimationFrame($03b515f3f8c77d8f$var$CheckIfRender.isListenerAttached);\n $03b515f3f8c77d8f$var$CheckIfRender.isListenerAttached = 0;\n },\n //When an element is unloaded remove it from the list of elements that are waiting to be lazy-loaded\n removeElementFromList: (toRemove)=>{\n $03b515f3f8c77d8f$var$elements.delete(toRemove);\n },\n isListenerAttached: 0\n};\nfunction $03b515f3f8c77d8f$export$2e2bcd8739ae039(props) {\n const [link, setLink] = (0, $9w1Q4$react.useState)('');\n const [visible, setVisible] = (0, $9w1Q4$react.useState)(false);\n const [ref, setRef] = (0, $9w1Q4$react.useState)(null);\n const makeItVisible = (0, $9w1Q4$react.useCallback)(()=>{\n if (props.link) setLink(()=>props.link);\n setVisible(()=>true);\n }, [\n props.link\n ]);\n const thisInstance = (0, $9w1Q4$react.useMemo)(()=>{\n return {\n element: ref,\n makeItVisible: makeItVisible,\n offset: props.offset || 100\n };\n }, [\n ref,\n props.offset,\n makeItVisible\n ]);\n const getRef = (0, $9w1Q4$react.useCallback)((node)=>{\n if (node !== null) setRef(node);\n }, []);\n (0, $9w1Q4$react.useEffect)(()=>{\n if (ref !== null) // add the element to the array of elements that are waiting to be lazy loaded\n $03b515f3f8c77d8f$var$CheckIfRender.addElement(thisInstance);\n return ()=>// if the element is unloaded remove the element from the list of elements that needs to be lazy loader\n $03b515f3f8c77d8f$var$CheckIfRender.removeElementFromList(thisInstance);\n }, [\n ref,\n thisInstance\n ]);\n return [\n getRef,\n link,\n visible\n ];\n}\n\n\n\n\n//# sourceMappingURL=index.js.map\n","import LazyBackgroundImage from './lazyLoadBackgroundImage'\nimport LazyImage from './lazyLoadImage'\nimport LazyFrame from './lazyLoadFrame'\nimport LazyComponent from './lazyLoadComponent'\n\nexport { default } from './useIsInViewport'\nexport { LazyBackgroundImage, LazyImage, LazyFrame, LazyComponent }\n","import { useState, useEffect, type ReactNode } from 'react'\nimport useIsInViewPort from './index'\n\ninterface LazyBackgroundImageProps {\n\tlink: string\n\toffset: number\n\tstyle: object\n\tclassName: string\n\tchildren: ReactNode,\n}\n\nexport default function LazyBackgroundImage(props: LazyBackgroundImageProps) {\n\tconst [setRef, link, isViewable] = useIsInViewPort(props)\n\n\tconst [style, setStyle] = useState({\n\t\tbackgroundImage: `url(${link})`,\n\t\t...props.style,\n\t})\n\n\tuseEffect(() => {\n\t\tisViewable\n\t\t\t? setStyle({\n\t\t\t\t\tbackgroundImage: `url(${link})`,\n\t\t\t\t\t...props.style,\n\t\t\t\t})\n\t\t\t: null\n\t}, [link, isViewable, props.style])\n\n\treturn (\n\t\t<div\n\t\t\tclassName={props.className}\n\t\t\tstyle={style}\n\t\t\tref={(node) => {\n\t\t\t\tsetRef(node)\n\t\t\t}}\n\t\t>\n\t\t\t{props.children}\n\t\t</div>\n\t)\n}\n","import useIsInViewPort from './index'\n\ninterface LazyImageProps {\n link: string,\n offset: number,\n alt: string,\n style: object,\n className: string,\n\ttitle: string\n}\n\nexport default function LazyImage(props: LazyImageProps) {\n\tconst [setRef, link] = useIsInViewPort(props)\n\n\treturn (\n\t\t<div\n\t\t\tref={(node) => {\n\t\t\t\tsetRef(node)\n\t\t\t}}\n\t\t>\n\t\t\t<img\n\t\t\t\tsrc={link}\n\t\t\t\talt={props.alt}\n\t\t\t\tstyle={props.style}\n\t\t\t\tclassName={props.className}\n\t\t\t\ttitle={props.title}\n\t\t\t/>\n\t\t</div>\n\t)\n}\n","import useIsInViewPort from './index'\n\ninterface LazyFrameProps {\n\theight: number\n\tlink: string\n\toffset: number\n\tallowFullScreen: boolean,\n}\n\nexport default function LazyFrame(props: LazyFrameProps) {\n\tconst [setRef, link] = useIsInViewPort(props)\n\n\treturn (\n\t\t<iframe\n\t\t\t// scrolling={props.scrolling || 'no'}\n\t\t\tsrc={link}\n\t\t\t// frameBorder={props.frameBorder || 'no'}\n\t\t\t// style={props.style || {border: props.frameBorder}}\n\t\t\tref={(node) => {\n\t\t\t\tsetRef(node)\n\t\t\t}}\n\t\t\t{...props}\n\t\t\theight={props.height || '500'}\n\t\t\tallowFullScreen={props.allowFullScreen || true}\n\t\t/>\n\t)\n}\n","import type { ReactNode } from 'react'\nimport useIsInViewport from './index'\n\ninterface LazyComponentProps {\n link: string,\n offset: number,\n style: object,\n children: ReactNode\n}\n\nexport default function LazyComponent(props: LazyComponentProps) {\n\tconst [setRef, _, isVisible] = useIsInViewport(props)\n\n\tif (!isVisible)\n\t\treturn (\n\t\t\t<div\n\t\t\t\tref={(node) => {\n\t\t\t\t\tsetRef(node)\n\t\t\t\t}}\n\t\t\t\tstyle={{\n\t\t\t\t\theight: '300px',\n\t\t\t\t\twidth: '300px',\n\t\t\t\t\t...props.style,\n\t\t\t\t}}\n\t\t\t></div>\n\t\t)\n\n\treturn <div>{props.children}</div>\n}\n","import { useState, useEffect, useMemo, useCallback } from 'react'\n\ninterface InstanceElement {\n\tmakeItVisible: () => void\n\telement: HTMLElement | null\n\toffset: number\n}\n\n// array with all the elements that are waiting to be shown in the viewport\nconst elements = new Set<InstanceElement>()\n\nconst CheckIfRender = {\n\t// top: the position of the element in relation with the top of the browser\n\t// left: the position of the element in relation with the left of the browser\n\t// offset: the desired offset of the element in relation of the viewport\n\tisInViewPort: ({\n\t\toffset,\n\t\ttop,\n\t\tleft,\n\t}: {\n\t\toffset: number\n\t\ttop: number\n\t\tleft: number\n\t}) => top < window.innerHeight + offset && left < window.innerWidth + offset,\n\n\tcalculateNewPosition: (elem: InstanceElement) => {\n\t\tconst { top, left } = elem.element?.getBoundingClientRect() || {\n\t\t\ttop: 0,\n\t\t\tleft: 0,\n\t\t}\n\n\t\treturn {\n\t\t\t...elem,\n\t\t\ttop,\n\t\t\tleft,\n\t\t}\n\t},\n\taddElement: (element: InstanceElement) => {\n\t\t//the distance from the pixel 0,0 and the top of the element\n\t\telements.add(element)\n\t\t//check if has already been started the rAF cycle\n\t\tif (CheckIfRender.isListenerAttached === 0) {\n\t\t\tCheckIfRender.isListenerAttached = window.requestAnimationFrame(\n\t\t\t\tCheckIfRender.eventHandler,\n\t\t\t)\n\t\t}\n\t},\n\teventHandler: () => {\n\t\t//if there is no more element to lazy load remove the listener/rAF\n\t\tif (elements.size === 0) {\n\t\t\tCheckIfRender.removeScrollHandler()\n\t\t} else {\n\t\t\telements.forEach((elem) => {\n\t\t\t\tconst haveToShow = CheckIfRender.isInViewPort(\n\t\t\t\t\tCheckIfRender.calculateNewPosition(elem),\n\t\t\t\t)\n\t\t\t\tif (haveToShow) {\n\t\t\t\t\telem.makeItVisible()\n\t\t\t\t\t// remove element from the list of elements to lazy load\n\t\t\t\t\tCheckIfRender.removeElementFromList(elem)\n\t\t\t\t}\n\t\t\t})\n\t\t\tCheckIfRender.isListenerAttached = window.requestAnimationFrame(\n\t\t\t\tCheckIfRender.eventHandler,\n\t\t\t)\n\t\t}\n\t},\n\n\tremoveScrollHandler: () => {\n\t\twindow.cancelAnimationFrame(CheckIfRender.isListenerAttached)\n\t\tCheckIfRender.isListenerAttached = 0\n\t},\n\t//When an element is unloaded remove it from the list of elements that are waiting to be lazy-loaded\n\tremoveElementFromList: (toRemove: InstanceElement) => {\n\t\telements.delete(toRemove)\n\t},\n\tisListenerAttached: 0, // intended as not set\n}\n\nexport default function useRenderIfInViewPort(props: {\n\tlink: string\n\toffset: number\n}): [(node: HTMLDivElement | null) => void, string, boolean] {\n\tconst [link, setLink] = useState('')\n\tconst [visible, setVisible] = useState(false)\n\n\tconst [ref, setRef] = useState<HTMLDivElement | null>(null)\n\n\tconst makeItVisible = useCallback(() => {\n\t\tif (props.link) setLink(() => props.link)\n\t\tsetVisible(() => true)\n\t}, [props.link])\n\n\tconst thisInstance = useMemo(() => {\n\t\treturn {\n\t\t\telement: ref,\n\t\t\tmakeItVisible,\n\t\t\toffset: props.offset || 100,\n\t\t}\n\t}, [ref, props.offset, makeItVisible])\n\n\tconst getRef = useCallback((node: HTMLDivElement | null) => {\n\t\tif (node !== null) setRef(node)\n\t}, [])\n\n\tuseEffect(() => {\n\t\tif (ref !== null)\n\t\t\t// add the element to the array of elements that are waiting to be lazy loaded\n\t\t\tCheckIfRender.addElement(thisInstance)\n\t\treturn () =>\n\t\t\t// if the element is unloaded remove the element from the list of elements that needs to be lazy loader\n\t\t\tCheckIfRender.removeElementFromList(thisInstance)\n\t}, [ref, thisInstance])\n\n\treturn [getRef, link, visible]\n}\n\n"],"names":["$9w1Q4$reactjsxruntime","require","$9w1Q4$react","$parcel$defineInteropFlag","a","Object","defineProperty","value","configurable","$parcel$export","e","n","v","s","get","set","enumerable","$6e38eea936045ca0$export$2e2bcd8739ae039","props","setRef","link","isViewable","$03b515f3f8c77d8f$export$2e2bcd8739ae039","style","setStyle","useState","backgroundImage","useEffect","jsx","className","ref","node","children","$f6f596272f209e0c$export$2e2bcd8739ae039","src","alt","title","$8e3d626f2d1eebd8$export$2e2bcd8739ae039","height","allowFullScreen","$c17687259f8b5ddf$export$2e2bcd8739ae039","_","isVisible","width","module","exports","$03b515f3f8c77d8f$var$elements","Set","$03b515f3f8c77d8f$var$CheckIfRender","isInViewPort","offset","top","left","window","innerHeight","innerWidth","calculateNewPosition","elem","element","getBoundingClientRect","addElement","add","isListenerAttached","requestAnimationFrame","eventHandler","size","removeScrollHandler","forEach","makeItVisible","removeElementFromList","cancelAnimationFrame","toRemove","delete","setLink","visible","setVisible","useCallback","thisInstance","useMemo","getRef"],"version":3,"file":"index.js.map"}
package/dist/module.js ADDED
@@ -0,0 +1,186 @@
1
+ import {jsx as $4MPRY$jsx} from "react/jsx-runtime";
2
+ import {useState as $4MPRY$useState, useEffect as $4MPRY$useEffect, useCallback as $4MPRY$useCallback, useMemo as $4MPRY$useMemo} from "react";
3
+
4
+
5
+
6
+
7
+ function $d53282a0f683afba$export$2e2bcd8739ae039(props) {
8
+ const [setRef, link, isViewable] = (0, $cf52ec504e3068a6$export$2e2bcd8739ae039)(props);
9
+ const [style, setStyle] = (0, $4MPRY$useState)({
10
+ backgroundImage: `url(${link})`,
11
+ ...props.style
12
+ });
13
+ (0, $4MPRY$useEffect)(()=>{
14
+ isViewable && setStyle({
15
+ backgroundImage: `url(${link})`,
16
+ ...props.style
17
+ });
18
+ }, [
19
+ link,
20
+ isViewable,
21
+ props.style
22
+ ]);
23
+ return /*#__PURE__*/ (0, $4MPRY$jsx)("div", {
24
+ className: props.className,
25
+ style: style,
26
+ ref: (node)=>{
27
+ setRef(node);
28
+ },
29
+ children: props.children
30
+ });
31
+ }
32
+
33
+
34
+
35
+
36
+ function $c76f9bf8c035eea9$export$2e2bcd8739ae039(props) {
37
+ const [setRef, link] = (0, $cf52ec504e3068a6$export$2e2bcd8739ae039)(props);
38
+ return /*#__PURE__*/ (0, $4MPRY$jsx)("div", {
39
+ ref: (node)=>{
40
+ setRef(node);
41
+ },
42
+ children: /*#__PURE__*/ (0, $4MPRY$jsx)("img", {
43
+ src: link,
44
+ alt: props.alt,
45
+ style: props.style,
46
+ className: props.className,
47
+ title: props.title
48
+ })
49
+ });
50
+ }
51
+
52
+
53
+
54
+
55
+ function $6154e4cf378cce38$export$2e2bcd8739ae039(props) {
56
+ const [setRef, link] = (0, $cf52ec504e3068a6$export$2e2bcd8739ae039)(props);
57
+ return /*#__PURE__*/ (0, $4MPRY$jsx)("iframe", {
58
+ // scrolling={props.scrolling || 'no'}
59
+ src: link,
60
+ // frameBorder={props.frameBorder || 'no'}
61
+ // style={props.style || {border: props.frameBorder}}
62
+ ref: (node)=>{
63
+ setRef(node);
64
+ },
65
+ ...props,
66
+ height: props.height || '500',
67
+ allowFullScreen: props.allowFullScreen || true
68
+ });
69
+ }
70
+
71
+
72
+
73
+
74
+ function $bff95282d9e2e246$export$2e2bcd8739ae039(props) {
75
+ const [setRef, _, isVisible] = (0, $cf52ec504e3068a6$export$2e2bcd8739ae039)(props);
76
+ if (!isVisible) return /*#__PURE__*/ (0, $4MPRY$jsx)("div", {
77
+ ref: (node)=>{
78
+ setRef(node);
79
+ },
80
+ style: {
81
+ height: '300px',
82
+ width: '300px',
83
+ ...props.style
84
+ }
85
+ });
86
+ return /*#__PURE__*/ (0, $4MPRY$jsx)("div", {
87
+ children: props.children
88
+ });
89
+ }
90
+
91
+
92
+
93
+ // array with all the elements that are waiting to be shown in the viewport
94
+ const $cf52ec504e3068a6$var$elements = new Set();
95
+ const $cf52ec504e3068a6$var$CheckIfRender = {
96
+ // top: the position of the element in relation with the top of the browser
97
+ // left: the position of the element in relation with the left of the browser
98
+ // offset: the desired offset of the element in relation of the viewport
99
+ isInViewPort: ({ offset: offset, top: top, left: left })=>top < window.innerHeight + offset && left < window.innerWidth + offset,
100
+ calculateNewPosition: (elem)=>{
101
+ const { top: top, left: left } = elem.element?.getBoundingClientRect() || {
102
+ top: 0,
103
+ left: 0
104
+ };
105
+ return {
106
+ ...elem,
107
+ top: top,
108
+ left: left
109
+ };
110
+ },
111
+ addElement: (element)=>{
112
+ //the distance from the pixel 0,0 and the top of the element
113
+ $cf52ec504e3068a6$var$elements.add(element);
114
+ //check if has already been started the rAF cycle
115
+ if ($cf52ec504e3068a6$var$CheckIfRender.isListenerAttached === 0) $cf52ec504e3068a6$var$CheckIfRender.isListenerAttached = window.requestAnimationFrame($cf52ec504e3068a6$var$CheckIfRender.eventHandler);
116
+ },
117
+ eventHandler: ()=>{
118
+ //if there is no more element to lazy load remove the listener/rAF
119
+ if ($cf52ec504e3068a6$var$elements.size === 0) $cf52ec504e3068a6$var$CheckIfRender.removeScrollHandler();
120
+ else {
121
+ $cf52ec504e3068a6$var$elements.forEach((elem)=>{
122
+ const haveToShow = $cf52ec504e3068a6$var$CheckIfRender.isInViewPort($cf52ec504e3068a6$var$CheckIfRender.calculateNewPosition(elem));
123
+ if (haveToShow) {
124
+ elem.makeItVisible();
125
+ // remove element from the list of elements to lazy load
126
+ $cf52ec504e3068a6$var$CheckIfRender.removeElementFromList(elem);
127
+ }
128
+ });
129
+ $cf52ec504e3068a6$var$CheckIfRender.isListenerAttached = window.requestAnimationFrame($cf52ec504e3068a6$var$CheckIfRender.eventHandler);
130
+ }
131
+ },
132
+ removeScrollHandler: ()=>{
133
+ window.cancelAnimationFrame($cf52ec504e3068a6$var$CheckIfRender.isListenerAttached);
134
+ $cf52ec504e3068a6$var$CheckIfRender.isListenerAttached = 0;
135
+ },
136
+ //When an element is unloaded remove it from the list of elements that are waiting to be lazy-loaded
137
+ removeElementFromList: (toRemove)=>{
138
+ $cf52ec504e3068a6$var$elements.delete(toRemove);
139
+ },
140
+ isListenerAttached: 0
141
+ };
142
+ function $cf52ec504e3068a6$export$2e2bcd8739ae039(props) {
143
+ const [link, setLink] = (0, $4MPRY$useState)('');
144
+ const [visible, setVisible] = (0, $4MPRY$useState)(false);
145
+ const [ref, setRef] = (0, $4MPRY$useState)(null);
146
+ const makeItVisible = (0, $4MPRY$useCallback)(()=>{
147
+ if (props.link) setLink(()=>props.link);
148
+ setVisible(()=>true);
149
+ }, [
150
+ props.link
151
+ ]);
152
+ const thisInstance = (0, $4MPRY$useMemo)(()=>{
153
+ return {
154
+ element: ref,
155
+ makeItVisible: makeItVisible,
156
+ offset: props.offset || 100
157
+ };
158
+ }, [
159
+ ref,
160
+ props.offset,
161
+ makeItVisible
162
+ ]);
163
+ const getRef = (0, $4MPRY$useCallback)((node)=>{
164
+ if (node !== null) setRef(node);
165
+ }, []);
166
+ (0, $4MPRY$useEffect)(()=>{
167
+ if (ref !== null) // add the element to the array of elements that are waiting to be lazy loaded
168
+ $cf52ec504e3068a6$var$CheckIfRender.addElement(thisInstance);
169
+ return ()=>// if the element is unloaded remove the element from the list of elements that needs to be lazy loader
170
+ $cf52ec504e3068a6$var$CheckIfRender.removeElementFromList(thisInstance);
171
+ }, [
172
+ ref,
173
+ thisInstance
174
+ ]);
175
+ return [
176
+ getRef,
177
+ link,
178
+ visible
179
+ ];
180
+ }
181
+
182
+
183
+
184
+
185
+ export {$cf52ec504e3068a6$export$2e2bcd8739ae039 as default, $d53282a0f683afba$export$2e2bcd8739ae039 as LazyBackgroundImage, $c76f9bf8c035eea9$export$2e2bcd8739ae039 as LazyImage, $6154e4cf378cce38$export$2e2bcd8739ae039 as LazyFrame, $bff95282d9e2e246$export$2e2bcd8739ae039 as LazyComponent};
186
+ //# sourceMappingURL=module.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;;;ACWe,kDAA6B,KAA+B;IAC1E,MAAM,CAAC,QAAQ,MAAM,WAAW,GAAG,CAAA,GAAA,wCAAc,EAAE;IAEnD,MAAM,CAAC,OAAO,SAAS,GAAG,CAAA,GAAA,eAAO,EAAE;QAClC,iBAAiB,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;QAC/B,GAAG,MAAM,KAAK;IACf;IAEA,CAAA,GAAA,gBAAQ,EAAE;QACT,cACG,SAAS;YACT,iBAAiB,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;YAC/B,GAAG,MAAM,KAAK;QACf;IAEH,GAAG;QAAC;QAAM;QAAY,MAAM,KAAK;KAAC;IAElC,qBACC,gBAAC;QACA,WAAW,MAAM,SAAS;QAC1B,OAAO;QACP,KAAK,CAAC;YACL,OAAO;QACR;kBAEC,MAAM,QAAQ;;AAGlB;;;;;AC5Be,kDAAmB,KAAqB;IACtD,MAAM,CAAC,QAAQ,KAAK,GAAG,CAAA,GAAA,wCAAc,EAAE;IAEvC,qBACC,gBAAC;QACA,KAAK,CAAC;YACL,OAAO;QACR;kBAEA,cAAA,gBAAC;YACA,KAAK;YACL,KAAK,MAAM,GAAG;YACd,OAAO,MAAM,KAAK;YAClB,WAAW,MAAM,SAAS;YAC1B,OAAO,MAAM,KAAK;;;AAItB;;;;;ACpBe,kDAAmB,KAAqB;IACtD,MAAM,CAAC,QAAQ,KAAK,GAAG,CAAA,GAAA,wCAAc,EAAE;IAEvC,qBACC,gBAAC;QACA,sCAAsC;QACtC,KAAK;QACL,0CAA0C;QAC1C,qDAAqD;QACrD,KAAK,CAAC;YACL,OAAO;QACR;QACC,GAAG,KAAK;QACT,QAAQ,MAAM,MAAM,IAAI;QACxB,iBAAiB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AEA,qBAAqB;QACpB,OAAO,oBAAoB,CAAC,oCAAc,kBAAkB;QAC5D,oCAAc,kBAAkB,GAAG;IACpC;IACA,oGAAoG;IACpG,uBAAuB,CAAC;QACvB,+BAAS,MAAM,CAAC;IACjB;IACA,oBAAoB;AACrB;AAEe,kDAA+B,KAG7C;IACA,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAA,GAAA,eAAO,EAAE;IACjC,MAAM,CAAC,SAAS,WAAW,GAAG,CAAA,GAAA,eAAO,EAAE;IAEvC,MAAM,CAAC,KAAK,OAAO,GAAG,CAAA,GAAA,eAAO,EAAyB;IAEtD,MAAM,gBAAgB,CAAA,GAAA,kBAAU,EAAE;QACjC,IAAI,MAAM,IAAI,EAAE,QAAQ,IAAM,MAAM,IAAI;QACxC,WAAW,IAAM;IAClB,GAAG;QAAC,MAAM,IAAI;KAAC;IAEf,MAAM,eAAe,CAAA,GAAA,cAAM,EAAE;QAC5B,OAAO;YACN,SAAS;2BACT;YACA,QAAQ,MAAM,MAAM,IAAI;QACzB;IACD,GAAG;QAAC;QAAK,MAAM,MAAM;QAAE;KAAc;IAErC,MAAM,SAAS,CAAA,GAAA,kBAAU,EAAE,CAAC;QAC3B,IAAI,SAAS,MAAM,OAAO;IAC3B,GAAG,EAAE;IAEL,CAAA,GAAA,gBAAQ,EAAE;QACT,IAAI,QAAQ,MACX,8EAA8E;QAC9E,oCAAc,UAAU,CAAC;QAC1B,OAAO,IACN,uGAAuG;YACvG,oCAAc,qBAAqB,CAAC;IACtC,GAAG;QAAC;QAAK;KAAa;IAEtB,OAAO;QAAC;QAAQ;QAAM;KAAQ;AAC/B;","sources":["src/index.tsx","src/lazyLoadBackgroundImage.tsx","src/lazyLoadImage.tsx","src/lazyLoadFrame.tsx","src/lazyLoadComponent.tsx","src/useIsInViewport.tsx"],"sourcesContent":["import LazyBackgroundImage from './lazyLoadBackgroundImage'\nimport LazyImage from './lazyLoadImage'\nimport LazyFrame from './lazyLoadFrame'\nimport LazyComponent from './lazyLoadComponent'\n\nexport { default } from './useIsInViewport'\nexport { LazyBackgroundImage, LazyImage, LazyFrame, LazyComponent }\n","import { useState, useEffect, type ReactNode } from 'react'\nimport useIsInViewPort from './index'\n\ninterface LazyBackgroundImageProps {\n\tlink: string\n\toffset: number\n\tstyle: object\n\tclassName: string\n\tchildren: ReactNode,\n}\n\nexport default function LazyBackgroundImage(props: LazyBackgroundImageProps) {\n\tconst [setRef, link, isViewable] = useIsInViewPort(props)\n\n\tconst [style, setStyle] = useState({\n\t\tbackgroundImage: `url(${link})`,\n\t\t...props.style,\n\t})\n\n\tuseEffect(() => {\n\t\tisViewable\n\t\t\t? setStyle({\n\t\t\t\t\tbackgroundImage: `url(${link})`,\n\t\t\t\t\t...props.style,\n\t\t\t\t})\n\t\t\t: null\n\t}, [link, isViewable, props.style])\n\n\treturn (\n\t\t<div\n\t\t\tclassName={props.className}\n\t\t\tstyle={style}\n\t\t\tref={(node) => {\n\t\t\t\tsetRef(node)\n\t\t\t}}\n\t\t>\n\t\t\t{props.children}\n\t\t</div>\n\t)\n}\n","import useIsInViewPort from './index'\n\ninterface LazyImageProps {\n link: string,\n offset: number,\n alt: string,\n style: object,\n className: string,\n\ttitle: string\n}\n\nexport default function LazyImage(props: LazyImageProps) {\n\tconst [setRef, link] = useIsInViewPort(props)\n\n\treturn (\n\t\t<div\n\t\t\tref={(node) => {\n\t\t\t\tsetRef(node)\n\t\t\t}}\n\t\t>\n\t\t\t<img\n\t\t\t\tsrc={link}\n\t\t\t\talt={props.alt}\n\t\t\t\tstyle={props.style}\n\t\t\t\tclassName={props.className}\n\t\t\t\ttitle={props.title}\n\t\t\t/>\n\t\t</div>\n\t)\n}\n","import useIsInViewPort from './index'\n\ninterface LazyFrameProps {\n\theight: number\n\tlink: string\n\toffset: number\n\tallowFullScreen: boolean,\n}\n\nexport default function LazyFrame(props: LazyFrameProps) {\n\tconst [setRef, link] = useIsInViewPort(props)\n\n\treturn (\n\t\t<iframe\n\t\t\t// scrolling={props.scrolling || 'no'}\n\t\t\tsrc={link}\n\t\t\t// frameBorder={props.frameBorder || 'no'}\n\t\t\t// style={props.style || {border: props.frameBorder}}\n\t\t\tref={(node) => {\n\t\t\t\tsetRef(node)\n\t\t\t}}\n\t\t\t{...props}\n\t\t\theight={props.height || '500'}\n\t\t\tallowFullScreen={props.allowFullScreen || true}\n\t\t/>\n\t)\n}\n","import type { ReactNode } from 'react'\nimport useIsInViewport from './index'\n\ninterface LazyComponentProps {\n link: string,\n offset: number,\n style: object,\n children: ReactNode\n}\n\nexport default function LazyComponent(props: LazyComponentProps) {\n\tconst [setRef, _, isVisible] = useIsInViewport(props)\n\n\tif (!isVisible)\n\t\treturn (\n\t\t\t<div\n\t\t\t\tref={(node) => {\n\t\t\t\t\tsetRef(node)\n\t\t\t\t}}\n\t\t\t\tstyle={{\n\t\t\t\t\theight: '300px',\n\t\t\t\t\twidth: '300px',\n\t\t\t\t\t...props.style,\n\t\t\t\t}}\n\t\t\t></div>\n\t\t)\n\n\treturn <div>{props.children}</div>\n}\n","import { useState, useEffect, useMemo, useCallback } from 'react'\n\ninterface InstanceElement {\n\tmakeItVisible: () => void\n\telement: HTMLElement | null\n\toffset: number\n}\n\n// array with all the elements that are waiting to be shown in the viewport\nconst elements = new Set<InstanceElement>()\n\nconst CheckIfRender = {\n\t// top: the position of the element in relation with the top of the browser\n\t// left: the position of the element in relation with the left of the browser\n\t// offset: the desired offset of the element in relation of the viewport\n\tisInViewPort: ({\n\t\toffset,\n\t\ttop,\n\t\tleft,\n\t}: {\n\t\toffset: number\n\t\ttop: number\n\t\tleft: number\n\t}) => top < window.innerHeight + offset && left < window.innerWidth + offset,\n\n\tcalculateNewPosition: (elem: InstanceElement) => {\n\t\tconst { top, left } = elem.element?.getBoundingClientRect() || {\n\t\t\ttop: 0,\n\t\t\tleft: 0,\n\t\t}\n\n\t\treturn {\n\t\t\t...elem,\n\t\t\ttop,\n\t\t\tleft,\n\t\t}\n\t},\n\taddElement: (element: InstanceElement) => {\n\t\t//the distance from the pixel 0,0 and the top of the element\n\t\telements.add(element)\n\t\t//check if has already been started the rAF cycle\n\t\tif (CheckIfRender.isListenerAttached === 0) {\n\t\t\tCheckIfRender.isListenerAttached = window.requestAnimationFrame(\n\t\t\t\tCheckIfRender.eventHandler,\n\t\t\t)\n\t\t}\n\t},\n\teventHandler: () => {\n\t\t//if there is no more element to lazy load remove the listener/rAF\n\t\tif (elements.size === 0) {\n\t\t\tCheckIfRender.removeScrollHandler()\n\t\t} else {\n\t\t\telements.forEach((elem) => {\n\t\t\t\tconst haveToShow = CheckIfRender.isInViewPort(\n\t\t\t\t\tCheckIfRender.calculateNewPosition(elem),\n\t\t\t\t)\n\t\t\t\tif (haveToShow) {\n\t\t\t\t\telem.makeItVisible()\n\t\t\t\t\t// remove element from the list of elements to lazy load\n\t\t\t\t\tCheckIfRender.removeElementFromList(elem)\n\t\t\t\t}\n\t\t\t})\n\t\t\tCheckIfRender.isListenerAttached = window.requestAnimationFrame(\n\t\t\t\tCheckIfRender.eventHandler,\n\t\t\t)\n\t\t}\n\t},\n\n\tremoveScrollHandler: () => {\n\t\twindow.cancelAnimationFrame(CheckIfRender.isListenerAttached)\n\t\tCheckIfRender.isListenerAttached = 0\n\t},\n\t//When an element is unloaded remove it from the list of elements that are waiting to be lazy-loaded\n\tremoveElementFromList: (toRemove: InstanceElement) => {\n\t\telements.delete(toRemove)\n\t},\n\tisListenerAttached: 0, // intended as not set\n}\n\nexport default function useRenderIfInViewPort(props: {\n\tlink: string\n\toffset: number\n}): [(node: HTMLDivElement | null) => void, string, boolean] {\n\tconst [link, setLink] = useState('')\n\tconst [visible, setVisible] = useState(false)\n\n\tconst [ref, setRef] = useState<HTMLDivElement | null>(null)\n\n\tconst makeItVisible = useCallback(() => {\n\t\tif (props.link) setLink(() => props.link)\n\t\tsetVisible(() => true)\n\t}, [props.link])\n\n\tconst thisInstance = useMemo(() => {\n\t\treturn {\n\t\t\telement: ref,\n\t\t\tmakeItVisible,\n\t\t\toffset: props.offset || 100,\n\t\t}\n\t}, [ref, props.offset, makeItVisible])\n\n\tconst getRef = useCallback((node: HTMLDivElement | null) => {\n\t\tif (node !== null) setRef(node)\n\t}, [])\n\n\tuseEffect(() => {\n\t\tif (ref !== null)\n\t\t\t// add the element to the array of elements that are waiting to be lazy loaded\n\t\t\tCheckIfRender.addElement(thisInstance)\n\t\treturn () =>\n\t\t\t// if the element is unloaded remove the element from the list of elements that needs to be lazy loader\n\t\t\tCheckIfRender.removeElementFromList(thisInstance)\n\t}, [ref, thisInstance])\n\n\treturn [getRef, link, visible]\n}\n\n"],"names":[],"version":3,"file":"module.js.map"}
@@ -0,0 +1,38 @@
1
+ import { ReactNode, JSX } from "react";
2
+ interface LazyBackgroundImageProps {
3
+ link: string;
4
+ offset: number;
5
+ style: object;
6
+ className: string;
7
+ children: ReactNode;
8
+ }
9
+ export function LazyBackgroundImage(props: LazyBackgroundImageProps): JSX.Element;
10
+ interface LazyImageProps {
11
+ link: string;
12
+ offset: number;
13
+ alt: string;
14
+ style: object;
15
+ className: string;
16
+ title: string;
17
+ }
18
+ export function LazyImage(props: LazyImageProps): JSX.Element;
19
+ interface LazyFrameProps {
20
+ height: number;
21
+ link: string;
22
+ offset: number;
23
+ allowFullScreen: boolean;
24
+ }
25
+ export function LazyFrame(props: LazyFrameProps): JSX.Element;
26
+ interface LazyComponentProps {
27
+ link: string;
28
+ offset: number;
29
+ style: object;
30
+ children: ReactNode;
31
+ }
32
+ export function LazyComponent(props: LazyComponentProps): JSX.Element;
33
+ export default function useRenderIfInViewPort(props: {
34
+ link: string;
35
+ offset: number;
36
+ }): [(node: HTMLDivElement | null) => void, string, boolean];
37
+
38
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"mappings":";AAGA;IACC,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,MAAM,CAAA;IACd,KAAK,EAAE,MAAM,CAAA;IACb,SAAS,EAAE,MAAM,CAAA;IACjB,QAAQ,EAAE,SAAS,CAAC;CACpB;AAED,oCAA4C,KAAK,EAAE,wBAAwB,eA4B1E;ACrCD;IACE,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,MAAM,CAAA;CACb;AAED,0BAAkC,KAAK,EAAE,cAAc,eAkBtD;AC3BD;IACC,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,MAAM,CAAA;IACd,eAAe,EAAE,OAAO,CAAC;CACzB;AAED,0BAAkC,KAAK,EAAE,cAAc,eAiBtD;ACvBD;IACE,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,SAAS,CAAA;CACpB;AAED,8BAAsC,KAAK,EAAE,kBAAkB,eAkB9D;ACmDD,8CAA8C,KAAK,EAAE;IACpD,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,MAAM,CAAA;CACd,GAAG,CAAC,CAAC,IAAI,EAAE,cAAc,GAAG,IAAI,KAAK,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,CAiC3D","sources":["src/src/lazyLoadBackgroundImage.tsx","src/src/lazyLoadImage.tsx","src/src/lazyLoadFrame.tsx","src/src/lazyLoadComponent.tsx","src/src/useIsInViewport.tsx","src/src/index.tsx","src/index.tsx"],"sourcesContent":[null,null,null,null,null,null,"import LazyBackgroundImage from './lazyLoadBackgroundImage'\nimport LazyImage from './lazyLoadImage'\nimport LazyFrame from './lazyLoadFrame'\nimport LazyComponent from './lazyLoadComponent'\n\nexport { default } from './useIsInViewport'\nexport { LazyBackgroundImage, LazyImage, LazyFrame, LazyComponent }\n"],"names":[],"version":3,"file":"types.d.ts.map"}
package/package.json CHANGED
@@ -1,9 +1,28 @@
1
1
  {
2
2
  "name": "lazy-react",
3
- "version": "3.6.2",
4
- "description": "components to lazy load iframes, images and images as backgrounds",
3
+ "version": "3.6.3",
4
+ "description": "React utility for lazy resource loading and lazy component execution. Engineered with requestAnimationFrame to ensure 60fps scrolling, it minimizes both network payload and CPU overhead by deferring resource fetching and component mounting until the viewport entry.",
5
+ "author": "Jonathan Obino",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/jonathanobino/react-lazy"
10
+ },
11
+ "keywords": [
12
+ "react",
13
+ "lazy-loading",
14
+ "typescript",
15
+ "javascript",
16
+ "performance",
17
+ "react-component",
18
+ "web-performance",
19
+ "frontend",
20
+ "library"
21
+ ],
5
22
  "source": "./src/index.tsx",
6
23
  "main": "./dist/index.js",
24
+ "module": "dist/module.js",
25
+ "types": "./dist/types.d.ts",
7
26
  "scripts": {
8
27
  "start": "parcel serve ./src/demo/index.html --dist-dir ./demo",
9
28
  "build": "parcel build",
@@ -23,26 +42,19 @@
23
42
  "git add"
24
43
  ]
25
44
  },
26
- "keywords": [
27
- "react",
28
- "lazy-load"
29
- ],
30
- "author": "Jonathan Obino",
31
- "license": "ISC",
32
- "repository": {
33
- "type": "git",
34
- "url": "https://github.com/jonathanobino/react-lazy"
35
- },
36
45
  "devDependencies": {
37
46
  "@biomejs/biome": "2.3.11",
38
- "@types/node": "^17.0.21",
39
- "@types/react": "^18.3.0",
40
- "@types/react-dom": "^18.3.0",
47
+ "@parcel/packager-ts": "^2.16.3",
48
+ "@parcel/transformer-typescript-types": "^2.9.0",
49
+ "@types/node": "^25.0.0",
50
+ "@types/react": "^19.2.0",
51
+ "@types/react-dom": "^19.2.0",
41
52
  "husky": "^4.3.0",
42
53
  "jest": "^27.5.1",
43
54
  "lint-staged": "^10.4.0",
44
- "parcel": "^2.7.0",
45
- "process": "^0.11.10"
55
+ "parcel": "^2.9.0",
56
+ "process": "^0.11.10",
57
+ "typescript": "^5.9.3"
46
58
  },
47
59
  "peerDependencies": {
48
60
  "react": "^18.3.0",
@@ -5,7 +5,8 @@ interface LazyImageProps {
5
5
  offset: number,
6
6
  alt: string,
7
7
  style: object,
8
- className: string
8
+ className: string,
9
+ title: string
9
10
  }
10
11
 
11
12
  export default function LazyImage(props: LazyImageProps) {
@@ -22,6 +23,7 @@ export default function LazyImage(props: LazyImageProps) {
22
23
  alt={props.alt}
23
24
  style={props.style}
24
25
  className={props.className}
26
+ title={props.title}
25
27
  />
26
28
  </div>
27
29
  )