Skip to content

Commit

Permalink
1.0.45-dev.0
Browse files Browse the repository at this point in the history
  • Loading branch information
clementroche committed Apr 26, 2024
1 parent c2e3b3a commit 253c3ba
Show file tree
Hide file tree
Showing 11 changed files with 909 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import Lenis from 'lenis'
using scripts:

```html
<script src="https://unpkg.com/lenis@1.0.44/dist/lenis.min.js"></script>
<script src="https://unpkg.com/lenis@1.0.45-dev.0/dist/lenis.min.js"></script>
```


Expand Down
28 changes: 28 additions & 0 deletions dist/lenis-react.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
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;
type ForwardRefComponent<P, T> = ForwardRefExoticComponent<PropsWithoutRef<P> & RefAttributes<T>>;
type Props = {
root?: boolean;
options?: LenisOptions;
autoRaf?: boolean;
rafPriority?: number;
className?: string;
children?: ReactNode;
props?: any;
};
type LenisRef = {
wrapper?: HTMLElement;
content?: HTMLElement;
lenis?: Lenis;
};
declare const ReactLenis: ForwardRefComponent<Props, LenisRef>;
export { ReactLenis as Lenis, ReactLenis };
export default ReactLenis;
2 changes: 2 additions & 0 deletions dist/lenis-react.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +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};
//# sourceMappingURL=lenis-react.mjs.map
1 change: 1 addition & 0 deletions dist/lenis-react.mjs.map

Large diffs are not rendered by default.

75 changes: 75 additions & 0 deletions dist/lenis.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
type EasingFunction = (t: number) => number;
type Orientation = 'vertical' | 'horizontal';
type GestureOrientation = 'vertical' | 'horizontal' | 'both';
export type LenisOptions = {
wrapper?: Window | HTMLElement;
content?: HTMLElement;
wheelEventsTarget?: Window | HTMLElement;
eventsTarget?: Window | HTMLElement;
smoothWheel?: boolean;
syncTouch?: boolean;
syncTouchLerp?: number;
touchInertiaMultiplier?: number;
duration?: number;
easing?: EasingFunction;
lerp?: number;
infinite?: boolean;
orientation?: Orientation;
gestureOrientation?: GestureOrientation;
touchMultiplier?: number;
wheelMultiplier?: number;
autoResize?: boolean;
__experimental__naiveDimensions?: boolean;
};
export default class Lenis {
__isSmooth: boolean;
__isScrolling: boolean;
__isStopped: boolean;
__isLocked: boolean;
constructor({ wrapper, content, wheelEventsTarget, // deprecated
eventsTarget, smoothWheel, syncTouch, syncTouchLerp, touchInertiaMultiplier, duration, // in seconds
easing, lerp, infinite, orientation, // vertical, horizontal
gestureOrientation, // vertical, horizontal, both
touchMultiplier, wheelMultiplier, autoResize, __experimental__naiveDimensions, }?: LenisOptions);
destroy(): void;
on(event: string, callback: Function): any;
off(event: string, callback: Function): any;
private setScroll;
private onVirtualScroll;
resize(): void;
private emit;
private onNativeScroll;
private reset;
start(): void;
stop(): void;
raf(time: number): void;
scrollTo(target: number | string | HTMLElement, { offset, immediate, lock, duration, easing, lerp, onComplete, force, // scroll even if stopped
programmatic, }?: {
offset?: number;
immediate?: boolean;
lock?: boolean;
duration?: number;
easing?: EasingFunction;
lerp?: number;
onComplete?: (lenis: Lenis) => void;
force?: boolean;
programmatic?: boolean;
}): void;
get rootElement(): any;
get limit(): any;
get isHorizontal(): boolean;
get actualScroll(): any;
get scroll(): any;
get progress(): number;
get isSmooth(): boolean;
private set isSmooth(value);
get isScrolling(): boolean;
private set isScrolling(value);
get isStopped(): boolean;
private set isStopped(value);
get isLocked(): boolean;
private set isLocked(value);
get className(): string;
private toggleClassName;
}
export {};
Loading

1 comment on commit 253c3ba

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

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

Please sign in to comment.