Skip to content

Commit

Permalink
remove zustand
Browse files Browse the repository at this point in the history
  • Loading branch information
clementroche committed Apr 27, 2024
1 parent 253c3ba commit acbfaf3
Show file tree
Hide file tree
Showing 34 changed files with 1,504 additions and 394 deletions.
12 changes: 7 additions & 5 deletions dist/lenis-react.d.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import * as react from 'react';
import { ForwardRefExoticComponent, PropsWithoutRef, RefAttributes, ReactNode } from 'react';
import Lenis, { LenisOptions } from 'lenis';
import { ForwardRefExoticComponent, PropsWithoutRef, ReactNode, RefAttributes } from 'react';

type LenisEventHandler = (lenis: Lenis) => void;
interface LenisContextValue {
lenis: Lenis;
addCallback: (handler: LenisEventHandler, priority: number) => void;
removeCallback: (handler: LenisEventHandler) => void;
}
export declare const LenisContext: import("react").Context<LenisContextValue | null>;
export declare function useLenis(callback?: (lenis: Lenis) => void, deps?: Array<any>, priority?: number): Lenis | undefined;
declare const LenisContext: react.Context<LenisContextValue | null>;
declare function useLenis(callback?: (lenis: Lenis) => void, deps?: Array<any>, priority?: number): Lenis | undefined;
type ForwardRefComponent<P, T> = ForwardRefExoticComponent<PropsWithoutRef<P> & RefAttributes<T>>;
type Props = {
root?: boolean;
Expand All @@ -24,5 +26,5 @@ type LenisRef = {
lenis?: Lenis;
};
declare const ReactLenis: ForwardRefComponent<Props, LenisRef>;
export { ReactLenis as Lenis, ReactLenis };
export default ReactLenis;

export { ReactLenis as Lenis, LenisContext, ReactLenis, ReactLenis as default, useLenis };
2 changes: 1 addition & 1 deletion dist/lenis-react.mjs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
import{jsx as r}from"react/jsx-runtime";import e from"@darkroom.engineering/tempus";import n from"clsx";import t from"lenis";import{createContext as o,forwardRef as l,useRef as a,useState as c,useCallback as s,useImperativeHandle as i,useEffect as u,useContext as f}from"react";import{create as p}from"zustand";"function"==typeof SuppressedError&&SuppressedError;const m=o(null),d=p((()=>({})));function b(r,e=[],n=0){const{lenis:t,addCallback:o,removeCallback:l}=function(){const r=f(m),e=d();return null!=r?r:e}();return u((()=>{if(r&&o&&l&&t)return o(r,n),r(t),()=>{l(r)}}),[t,o,l,n,...e]),t}const y=l(((o,l)=>{var{children:f,root:p=!1,options:b={},autoRaf:y=!0,rafPriority:v=0,className:O}=o,g=function(r,e){var n={};for(var t in r)Object.prototype.hasOwnProperty.call(r,t)&&e.indexOf(t)<0&&(n[t]=r[t]);if(null!=r&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(t=Object.getOwnPropertySymbols(r);o<t.length;o++)e.indexOf(t[o])<0&&Object.prototype.propertyIsEnumerable.call(r,t[o])&&(n[t[o]]=r[t[o]])}return n}(o,["children","root","options","autoRaf","rafPriority","className"]);const h=a(null),k=a(null),[N,j]=c(void 0),w=a([]),C=s(((r,e)=>{w.current.push({callback:r,priority:e}),w.current.sort(((r,e)=>r.priority-e.priority))}),[]),P=s((r=>{w.current=w.current.filter((e=>e.callback!==r))}),[]);i(l,(()=>({wrapper:h.current,content:k.current,lenis:N})),[N]),u((()=>{const r=new t(Object.assign(Object.assign({},b),!p&&{wrapper:h.current,content:k.current}));return j(r),()=>{r.destroy(),j(void 0)}}),[p,JSON.stringify(b)]),u((()=>{if(!N||!y)return;const r=e.add((r=>{null==N||N.raf(r)}),v);return()=>{r()}}),[N,y,v]),u((()=>{p&&N&&d.setState({lenis:N,addCallback:C,removeCallback:P})}),[p,N,C,P]);const S=s((r=>{for(let e=0;e<w.current.length;e++)w.current[e].callback(r)}),[]);u((()=>(null==N||N.on("scroll",S),()=>{null==N||N.off("scroll",S)})),[N,S]);const x=s((()=>{h.current&&(h.current.className=n(null==N?void 0:N.className,O))}),[N,O]);return u((()=>(x(),null==N||N.on("className change",x),()=>{null==N||N.off("className change",x)})),[N,x]),r(m.Provider,{value:{lenis:N,addCallback:C,removeCallback:P},children:p?f:r("div",Object.assign({ref:h,className:n(null==N?void 0:N.className,O)},g,{children:r("div",{ref:k,children:f})}))})}));export{y as Lenis,m as LenisContext,y as ReactLenis,y as default,b as useLenis};
import{jsx as r}from"react/jsx-runtime";import e from"@darkroom.engineering/tempus";import t from"clsx";import n from"lenis";import{useState as s,useEffect as l,createContext as o,forwardRef as i,useRef as c,useCallback as a,useImperativeHandle as u,useContext as f}from"react";"function"==typeof SuppressedError&&SuppressedError;const p=o(null),d=new class Store{constructor(r){this.listeners=[],this.state=r}set(r){this.state=r;for(let r of this.listeners)r(this.state)}subscribe(r){return this.listeners=[...this.listeners,r],()=>{this.listeners=this.listeners.filter((e=>e!==r))}}get(){return this.state}}({});function m(){const r=f(p),e=function(r){const[e,t]=s(r.get());return l((()=>r.subscribe((r=>t(r)))),[r]),e}(d);return null!=r?r:e}function b(r,e=[],t=0){const{lenis:n,addCallback:s,removeCallback:o}=m();return l((()=>{if(r&&s&&o&&n)return s(r,t),r(n),()=>{o(r)}}),[n,s,o,t,...e]),n}const h=i(((o,i)=>{var{children:f,root:m=!1,options:b={},autoRaf:h=!0,rafPriority:y=0,className:v}=o,g=function(r,e){var t={};for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&e.indexOf(n)<0&&(t[n]=r[n]);if(null!=r&&"function"==typeof Object.getOwnPropertySymbols){var s=0;for(n=Object.getOwnPropertySymbols(r);s<n.length;s++)e.indexOf(n[s])<0&&Object.prototype.propertyIsEnumerable.call(r,n[s])&&(t[n[s]]=r[n[s]])}return t}(o,["children","root","options","autoRaf","rafPriority","className"]);const O=c(null),k=c(null),[N,j]=s(void 0),w=c([]),C=a(((r,e)=>{w.current.push({callback:r,priority:e}),w.current.sort(((r,e)=>r.priority-e.priority))}),[]),P=a((r=>{w.current=w.current.filter((e=>e.callback!==r))}),[]);u(i,(()=>({wrapper:O.current,content:k.current,lenis:N})),[N]),l((()=>{const r=new n(Object.assign(Object.assign({},b),!m&&{wrapper:O.current,content:k.current}));return j(r),()=>{r.destroy(),j(void 0)}}),[m,JSON.stringify(b)]),l((()=>{if(N&&h)return e.add((r=>{null==N||N.raf(r)}),y)}),[N,h,y]),l((()=>{if(m&&N)return d.set({lenis:N,addCallback:C,removeCallback:P}),()=>d.set({})}),[m,N,C,P]);const S=a((r=>{for(let e=0;e<w.current.length;e++)w.current[e].callback(r)}),[]);l((()=>(null==N||N.on("scroll",S),()=>{null==N||N.off("scroll",S)})),[N,S]);const x=a((()=>{O.current&&(O.current.className=t(null==N?void 0:N.className,v))}),[N,v]);return l((()=>(x(),null==N||N.on("className change",x),()=>{null==N||N.off("className change",x)})),[N,x]),r(p.Provider,{value:{lenis:N,addCallback:C,removeCallback:P},children:m?f:r("div",Object.assign({ref:O,className:t(null==N?void 0:N.className,v)},g,{children:r("div",{ref:k,children:f})}))})}));export{h as Lenis,p as LenisContext,h as ReactLenis,h as default,b as useLenis};
//# sourceMappingURL=lenis-react.mjs.map
2 changes: 1 addition & 1 deletion dist/lenis-react.mjs.map

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions dist/lenis.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
type EasingFunction = (t: number) => number;
type Orientation = 'vertical' | 'horizontal';
type GestureOrientation = 'vertical' | 'horizontal' | 'both';
export type LenisOptions = {
type LenisOptions = {
wrapper?: Window | HTMLElement;
content?: HTMLElement;
wheelEventsTarget?: Window | HTMLElement;
Expand All @@ -21,7 +21,7 @@ export type LenisOptions = {
autoResize?: boolean;
__experimental__naiveDimensions?: boolean;
};
export default class Lenis {
declare class Lenis {
__isSmooth: boolean;
__isScrolling: boolean;
__isStopped: boolean;
Expand Down Expand Up @@ -72,4 +72,5 @@ export default class Lenis {
get className(): string;
private toggleClassName;
}
export {};

export { type LenisOptions, Lenis as default };
Loading

1 comment on commit acbfaf3

@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: 53
🟢 Accessibility: 96
🟢 Best practices: 100
🟠 SEO: 67
🟠 PWA: 56

Lighthouse ran on https://lenis-emslefewp-studio-freight.vercel.app/"

Please sign in to comment.