Skip to content

Commit

Permalink
react-lenis mjs
Browse files Browse the repository at this point in the history
  • Loading branch information
clementroche committed Dec 28, 2023
1 parent 5b2b879 commit 8bf3e03
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 42 deletions.
1 change: 0 additions & 1 deletion packages/react-lenis/dist/react-lenis.esm.js.map

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
import{useFrame as r}from"@studio-freight/hamo";import e from"@studio-freight/lenis";import t from"prop-types";import o,{createContext as a,useEffect as n,forwardRef as c,useRef as s,useState as l,useCallback as i,useImperativeHandle as f,useContext as u}from"react";import{create as m}from"zustand";import p from"clsx";function d(){return d=Object.assign?Object.assign.bind():function(r){for(var e=1;e<arguments.length;e++){var t=arguments[e];for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&(r[o]=t[o])}return r},d.apply(this,arguments)}const b=a(),y=m((()=>({})));function h(r,e=[],t=0){const{lenis:o,addCallback:a,removeCallback:c}=function(){const r=u(b),e=y();return r??e}();return n((()=>{if(r&&a&&c&&o)return a(r,t),r(o),()=>{c(r)}}),[o,a,c,t,...e]),o}const v=c((({children:t,root:a=!1,options:c={},autoRaf:u=!0,rafPriority:m=0,className:h,...v},g)=>{const N=s(),k=s(),[C,O]=l(),j=s([]),P=i(((r,e)=>{j.current.push({callback:r,priority:e}),j.current.sort(((r,e)=>r.priority-e.priority))}),[]),w=i((r=>{j.current=j.current.filter((e=>e.callback!==r))}),[]);f(g,(()=>C),[C]),n((()=>{const r=new e({...c,...!a&&{wrapper:N.current,content:k.current}});return O(r),()=>{r.destroy(),O(void 0)}}),[a,JSON.stringify(c)]),r((r=>{u&&C?.raf(r)}),m),n((()=>{a&&C&&y.setState({lenis:C,addCallback:P,removeCallback:w})}),[a,C,P,w]);const E=i((r=>{for(let e=0;e<j.current.length;e++)j.current[e].callback(r)}),[]);n((()=>(C?.on("scroll",E),()=>{C?.off("scroll",E)})),[C,E]);const R=i((()=>{N.current&&(N.current.className=p(C?.className,h))}),[C,h]);return n((()=>(R(),C?.on("className change",R),()=>{C?.off("className change",R)})),[C,R]),o.createElement(b.Provider,{value:{lenis:C,addCallback:P,removeCallback:w}},a?t:o.createElement("div",d({ref:N,className:p(C?.className,h)},v),o.createElement("div",{ref:k},t)))}));v.displayName="ReactLenis",v.propTypes={children:t.node,root:t.bool,options:t.object,autoRaf:t.bool,rafPriority:t.number,className:t.string};export{v as Lenis,b as LenisContext,v as ReactLenis,v as default,h as useLenis};
//# sourceMappingURL=react-lenis.esm.js.map
//# sourceMappingURL=react-lenis.mjs.map
Loading

2 comments on commit 8bf3e03

@vercel
Copy link

@vercel vercel bot commented on 8bf3e03 Dec 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"⚡️ Lighthouse report for the changes in this commit:

🔴 Performance: 31
🟠 Accessibility: 88
🟢 Best practices: 100
🟠 SEO: 67
🔴 PWA: 0

Lighthouse ran on https://gsap.com/requires-membership/?plugin=SplitText&source=trial"

Please sign in to comment.