UNPKG

eff-anim

Version:
1 lines 3.18 kB
{"version":3,"file":"index.mjs","sources":["../node_modules/style-inject/dist/style-inject.es.js","../src/components/ContainerViews.tsx"],"sourcesContent":["function styleInject(css, ref) {\n if ( ref === void 0 ) ref = {};\n var insertAt = ref.insertAt;\n\n if (!css || typeof document === 'undefined') { return; }\n\n var head = document.head || document.getElementsByTagName('head')[0];\n var style = document.createElement('style');\n style.type = 'text/css';\n\n if (insertAt === 'top') {\n if (head.firstChild) {\n head.insertBefore(style, head.firstChild);\n } else {\n head.appendChild(style);\n }\n } else {\n head.appendChild(style);\n }\n\n if (style.styleSheet) {\n style.styleSheet.cssText = css;\n } else {\n style.appendChild(document.createTextNode(css));\n }\n}\n\nexport default styleInject;\n","import { useEffect, useRef, useState } from \"react\";\r\nimport \"../styles/containerViews.css\";\r\nimport { ContainerViewsProps } from \"../types\";\r\n\r\nexport const ContainerViews = ({\r\n children,\r\n threshold = 0.9,\r\n effect = \"\",\r\n}: ContainerViewsProps) => {\r\n const elementRef = useRef(null);\r\n const [isVisible, setIsVisible] = useState(false);\r\n\r\n useEffect(() => {\r\n const element = elementRef.current;\r\n if (!element) return;\r\n\r\n const observer = new IntersectionObserver(\r\n ([entry]) => {\r\n setIsVisible(entry.isIntersecting);\r\n },\r\n { threshold }\r\n );\r\n\r\n observer.observe(element);\r\n\r\n return () => {\r\n observer.disconnect();\r\n };\r\n }, [threshold]);\r\n\r\n return (\r\n <section ref={elementRef} className={`content ${effect} ${isVisible ? \"animation\" : \"\"}`}>\r\n {children}\r\n </section>\r\n );\r\n};\r\n"],"names":["css","ref","insertAt","document","head","getElementsByTagName","style","createElement","type","firstChild","insertBefore","appendChild","styleSheet","cssText","createTextNode","ContainerViews","_a","children","_b","threshold","_c","effect","elementRef","useRef","_d","useState","isVisible","setIsVisible","useEffect","element","current","observer","IntersectionObserver","entry","isIntersecting","observe","disconnect","_jsx","className","concat"],"mappings":"qGAAA,SAAqBA,EAAKC,QACX,IAARA,IAAiBA,EAAM,CAAE,GAC9B,IAAIC,EAAWD,EAAIC,SAEnB,GAAgC,oBAAbC,SAAnB,CAEA,IAAIC,EAAOD,SAASC,MAAQD,SAASE,qBAAqB,QAAQ,GAC9DC,EAAQH,SAASI,cAAc,SACnCD,EAAME,KAAO,WAEI,QAAbN,GACEE,EAAKK,WACPL,EAAKM,aAAaJ,EAAOF,EAAKK,YAKhCL,EAAKO,YAAYL,GAGfA,EAAMM,WACRN,EAAMM,WAAWC,QAAUb,EAE3BM,EAAMK,YAAYR,SAASW,eAAed,GAnBU,CAqBxD,guJCrBO,IAAMe,EAAiB,SAACC,GAC7B,IAAAC,EAAQD,EAAAC,SACRC,EAAeF,EAAAG,UAAfA,OAAY,IAAAD,EAAA,GAAGA,EACfE,EAAWJ,EAAAK,OAAXA,OAAM,IAAAD,EAAG,GAAEA,EAELE,EAAaC,EAAO,MACpBC,EAA4BC,GAAS,GAApCC,EAASF,EAAA,GAAEG,EAAYH,EAAA,GAoB9B,OAlBAI,GAAU,WACR,IAAMC,EAAUP,EAAWQ,QAC3B,GAAKD,EAAL,CAEA,IAAME,EAAW,IAAIC,sBACnB,SAAChB,GAAC,IAAAiB,EAAKjB,EAAA,GACLW,EAAaM,EAAMC,eACrB,GACA,CAAEf,UAASA,IAKb,OAFAY,EAASI,QAAQN,GAEV,WACLE,EAASK,YACV,CAba,CAchB,GAAG,CAACjB,IAGFkB,EAAS,UAAA,CAAApC,IAAKqB,EAAYgB,UAAW,WAAWC,OAAAlB,EAAU,KAAAkB,OAAAb,EAAY,YAAc,IACjFT,SAAAA,GAGP","x_google_ignoreList":[0]}