diff --git a/packages/react-lenis/README.md b/packages/react-lenis/README.md index 3781e2da..8f474ce9 100644 --- a/packages/react-lenis/README.md +++ b/packages/react-lenis/README.md @@ -6,24 +6,17 @@ react-lenis provides a `` component that creates a [Lenis](https://github.com/darkroomengineering/lenis) instance and provides it to its children via context. This allows you to use Lenis in your React app without worrying about passing the instance down through props. It also provides a `useLenis` hook that allows you to access the Lenis instance from any component in your app. -
- ## Installation -For npm users: -``` +```bash npm i @studio-freight/react-lenis ``` -For yarn users: -``` -yarn add @studio-freight/react-lenis -``` - - ## Usage -```js +### Basic + +```jsx import { ReactLenis, useLenis } from '@studio-freight/react-lenis' function Layout() { @@ -38,15 +31,28 @@ function Layout() { ) } ``` -
+ +### RSC +```jsx +// libs/react-lenis.js + +'use client' + +export * from '@studio-freight/react-lenis' +``` + +```jsx +import { ReactLenis, useLenis } from 'libs/react-lenis' +``` ## Props - `options`: [Lenis options](https://github.com/darkroomengineering/lenis#instance-settings). - `root`: Lenis will be instanciate using `` scroll. Default: `false`. - `autoRaf`: if `false`, `lenis.raf` needs to be called manually. Default: `true`. -- `rAFpriority`: [Tempus](https://github.com/studio-freight/tempus#readme) execution priority. Default: `0`. +- `rafPriority`: [Tempus](https://github.com/studio-freight/tempus#readme) execution priority. Default: `0`. +- `className`: Class name for the wrapper div. Default: `''`. + -
## Hooks Once the Lenis context is set (components mounted inside ``) you can use these handy hooks: @@ -62,7 +68,7 @@ The hook takes three argument: GSAP integration -```js +```jsx function Component() { const lenisRef = useRef() @@ -87,7 +93,6 @@ function Component() { ``` -
## @studio-freight/react-lenis in use diff --git a/packages/react-lenis/dist/react-lenis.cjs.js b/packages/react-lenis/dist/react-lenis.cjs.js index 435aa3ae..b0285fb7 100644 --- a/packages/react-lenis/dist/react-lenis.cjs.js +++ b/packages/react-lenis/dist/react-lenis.cjs.js @@ -1,2 +1,2 @@ -"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@studio-freight/hamo"),r=require("@studio-freight/lenis"),t=require("clsx"),n=require("react"),s=require("zustand");"function"==typeof SuppressedError&&SuppressedError;"undefined"!=typeof window&&(window.reactLenisVersion="0.0.46");const a=n.createContext(),l=s.create((()=>({})));const c=n.forwardRef(((s,c)=>{var{children:o,root:u=!1,options:i={},autoRaf:f=!0,rafPriority:p=0,className:d}=s,b=function(e,r){var t={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&r.indexOf(n)<0&&(t[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var s=0;for(n=Object.getOwnPropertySymbols(e);s{k.current.push({callback:e,priority:r}),k.current.sort(((e,r)=>e.priority-r.priority))}),[]),g=n.useCallback((e=>{k.current=k.current.filter((r=>r.callback!==e))}),[]);n.useImperativeHandle(c,(()=>({wrapper:m.current,content:y.current,lenis:v})),[v]),n.useEffect((()=>{const e=new r(Object.assign(Object.assign({},i),!u&&{wrapper:m.current,content:y.current}));return O(e),()=>{e.destroy(),O(void 0)}}),[u,JSON.stringify(i)]),e.useFrame((e=>{f&&(null==v||v.raf(e))}),p),n.useEffect((()=>{u&&v&&l.setState({lenis:v,addCallback:C,removeCallback:g})}),[u,v,C,g]);const x=n.useCallback((e=>{for(let r=0;r(null==v||v.on("scroll",x),()=>{null==v||v.off("scroll",x)})),[v,x]);const h=n.useCallback((()=>{m.current&&(m.current.className=t(null==v?void 0:v.className,d))}),[v,d]);return n.useEffect((()=>(h(),null==v||v.on("className change",h),()=>{null==v||v.off("className change",h)})),[v,h]),n.createElement(a.Provider,{value:{lenis:v,addCallback:C,removeCallback:g}},u?o:n.createElement("div",Object.assign({ref:m,className:t(null==v?void 0:v.className,d)},b),n.createElement("div",{ref:y},o)))}));exports.Lenis=c,exports.LenisContext=a,exports.ReactLenis=c,exports.default=c,exports.useLenis=function(e,r=[],t=0){const{lenis:s,addCallback:c,removeCallback:o}=function(){const e=n.useContext(a),r=l();return null!=e?e:r}();return n.useEffect((()=>{if(e&&c&&o&&s)return c(e,t),e(s),()=>{o(e)}}),[s,c,o,t,...r]),s}; +"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@studio-freight/hamo"),r=require("@studio-freight/lenis"),t=require("clsx"),n=require("react"),l=require("zustand");"function"==typeof SuppressedError&&SuppressedError;"undefined"!=typeof window&&(window.reactLenisVersion="0.0.46");const s=n.createContext(null),a=l.create((()=>({})));const c=n.forwardRef(((l,c)=>{var{children:o,root:u=!1,options:i={},autoRaf:f=!0,rafPriority:p=0,className:d}=l,b=function(e,r){var t={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&r.indexOf(n)<0&&(t[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var l=0;for(n=Object.getOwnPropertySymbols(e);l{k.current.push({callback:e,priority:r}),k.current.sort(((e,r)=>e.priority-r.priority))}),[]),g=n.useCallback((e=>{k.current=k.current.filter((r=>r.callback!==e))}),[]);n.useImperativeHandle(c,(()=>({wrapper:m.current,content:y.current,lenis:v})),[v]),n.useEffect((()=>{const e=new r(Object.assign(Object.assign({},i),!u&&{wrapper:m.current,content:y.current}));return O(e),()=>{e.destroy(),O(void 0)}}),[u,JSON.stringify(i)]),e.useFrame((e=>{f&&(null==v||v.raf(e))}),p),n.useEffect((()=>{u&&v&&a.setState({lenis:v,addCallback:C,removeCallback:g})}),[u,v,C,g]);const x=n.useCallback((e=>{for(let r=0;r(null==v||v.on("scroll",x),()=>{null==v||v.off("scroll",x)})),[v,x]);const h=n.useCallback((()=>{m.current&&(m.current.className=t(null==v?void 0:v.className,d))}),[v,d]);return n.useEffect((()=>(h(),null==v||v.on("className change",h),()=>{null==v||v.off("className change",h)})),[v,h]),n.createElement(s.Provider,{value:{lenis:v,addCallback:C,removeCallback:g}},u?o:n.createElement("div",Object.assign({ref:m,className:t(null==v?void 0:v.className,d)},b),n.createElement("div",{ref:y},o)))}));exports.Lenis=c,exports.LenisContext=s,exports.ReactLenis=c,exports.default=c,exports.useLenis=function(e,r=[],t=0){const{lenis:l,addCallback:c,removeCallback:o}=function(){const e=n.useContext(s),r=a();return null!=e?e:r}();return n.useEffect((()=>{if(e&&c&&o&&l)return c(e,t),e(l),()=>{o(e)}}),[l,c,o,t,...r]),l}; //# sourceMappingURL=react-lenis.cjs.js.map diff --git a/packages/react-lenis/dist/react-lenis.cjs.js.map b/packages/react-lenis/dist/react-lenis.cjs.js.map index 54f896ad..16b30ef4 100644 --- a/packages/react-lenis/dist/react-lenis.cjs.js.map +++ b/packages/react-lenis/dist/react-lenis.cjs.js.map @@ -1 +1 @@ -{"version":3,"file":"react-lenis.cjs.js","sources":["../../../node_modules/tslib/tslib.es6.js","../../src/index.tsx"],"sourcesContent":["/******************************************************************************\r\nCopyright (c) Microsoft Corporation.\r\n\r\nPermission to use, copy, modify, and/or distribute this software for any\r\npurpose with or without fee is hereby granted.\r\n\r\nTHE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\r\nREGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\r\nAND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\r\nINDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\r\nLOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\r\nOTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\r\nPERFORMANCE OF THIS SOFTWARE.\r\n***************************************************************************** */\r\n/* global Reflect, Promise, SuppressedError, Symbol */\r\n\r\nvar extendStatics = function(d, b) {\r\n extendStatics = Object.setPrototypeOf ||\r\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\r\n function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };\r\n return extendStatics(d, b);\r\n};\r\n\r\nexport function __extends(d, b) {\r\n if (typeof b !== \"function\" && b !== null)\r\n throw new TypeError(\"Class extends value \" + String(b) + \" is not a constructor or null\");\r\n extendStatics(d, b);\r\n function __() { this.constructor = d; }\r\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\r\n}\r\n\r\nexport var __assign = function() {\r\n __assign = Object.assign || function __assign(t) {\r\n for (var s, i = 1, n = arguments.length; i < n; i++) {\r\n s = arguments[i];\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];\r\n }\r\n return t;\r\n }\r\n return __assign.apply(this, arguments);\r\n}\r\n\r\nexport function __rest(s, e) {\r\n var t = {};\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)\r\n t[p] = s[p];\r\n if (s != null && typeof Object.getOwnPropertySymbols === \"function\")\r\n for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {\r\n if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))\r\n t[p[i]] = s[p[i]];\r\n }\r\n return t;\r\n}\r\n\r\nexport function __decorate(decorators, target, key, desc) {\r\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\r\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\r\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\r\n return c > 3 && r && Object.defineProperty(target, key, r), r;\r\n}\r\n\r\nexport function __param(paramIndex, decorator) {\r\n return function (target, key) { decorator(target, key, paramIndex); }\r\n}\r\n\r\nexport function __esDecorate(ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {\r\n function accept(f) { if (f !== void 0 && typeof f !== \"function\") throw new TypeError(\"Function expected\"); return f; }\r\n var kind = contextIn.kind, key = kind === \"getter\" ? \"get\" : kind === \"setter\" ? \"set\" : \"value\";\r\n var target = !descriptorIn && ctor ? contextIn[\"static\"] ? ctor : ctor.prototype : null;\r\n var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});\r\n var _, done = false;\r\n for (var i = decorators.length - 1; i >= 0; i--) {\r\n var context = {};\r\n for (var p in contextIn) context[p] = p === \"access\" ? {} : contextIn[p];\r\n for (var p in contextIn.access) context.access[p] = contextIn.access[p];\r\n context.addInitializer = function (f) { if (done) throw new TypeError(\"Cannot add initializers after decoration has completed\"); extraInitializers.push(accept(f || null)); };\r\n var result = (0, decorators[i])(kind === \"accessor\" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);\r\n if (kind === \"accessor\") {\r\n if (result === void 0) continue;\r\n if (result === null || typeof result !== \"object\") throw new TypeError(\"Object expected\");\r\n if (_ = accept(result.get)) descriptor.get = _;\r\n if (_ = accept(result.set)) descriptor.set = _;\r\n if (_ = accept(result.init)) initializers.unshift(_);\r\n }\r\n else if (_ = accept(result)) {\r\n if (kind === \"field\") initializers.unshift(_);\r\n else descriptor[key] = _;\r\n }\r\n }\r\n if (target) Object.defineProperty(target, contextIn.name, descriptor);\r\n done = true;\r\n};\r\n\r\nexport function __runInitializers(thisArg, initializers, value) {\r\n var useValue = arguments.length > 2;\r\n for (var i = 0; i < initializers.length; i++) {\r\n value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);\r\n }\r\n return useValue ? value : void 0;\r\n};\r\n\r\nexport function __propKey(x) {\r\n return typeof x === \"symbol\" ? x : \"\".concat(x);\r\n};\r\n\r\nexport function __setFunctionName(f, name, prefix) {\r\n if (typeof name === \"symbol\") name = name.description ? \"[\".concat(name.description, \"]\") : \"\";\r\n return Object.defineProperty(f, \"name\", { configurable: true, value: prefix ? \"\".concat(prefix, \" \", name) : name });\r\n};\r\n\r\nexport function __metadata(metadataKey, metadataValue) {\r\n if (typeof Reflect === \"object\" && typeof Reflect.metadata === \"function\") return Reflect.metadata(metadataKey, metadataValue);\r\n}\r\n\r\nexport function __awaiter(thisArg, _arguments, P, generator) {\r\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\r\n return new (P || (P = Promise))(function (resolve, reject) {\r\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\r\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\r\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\r\n step((generator = generator.apply(thisArg, _arguments || [])).next());\r\n });\r\n}\r\n\r\nexport function __generator(thisArg, body) {\r\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\r\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\r\n function verb(n) { return function (v) { return step([n, v]); }; }\r\n function step(op) {\r\n if (f) throw new TypeError(\"Generator is already executing.\");\r\n while (g && (g = 0, op[0] && (_ = 0)), _) try {\r\n if (f = 1, y && (t = op[0] & 2 ? y[\"return\"] : op[0] ? y[\"throw\"] || ((t = y[\"return\"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;\r\n if (y = 0, t) op = [op[0] & 2, t.value];\r\n switch (op[0]) {\r\n case 0: case 1: t = op; break;\r\n case 4: _.label++; return { value: op[1], done: false };\r\n case 5: _.label++; y = op[1]; op = [0]; continue;\r\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\r\n default:\r\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\r\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\r\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\r\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\r\n if (t[2]) _.ops.pop();\r\n _.trys.pop(); continue;\r\n }\r\n op = body.call(thisArg, _);\r\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\r\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\r\n }\r\n}\r\n\r\nexport var __createBinding = Object.create ? (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n var desc = Object.getOwnPropertyDescriptor(m, k);\r\n if (!desc || (\"get\" in desc ? !m.__esModule : desc.writable || desc.configurable)) {\r\n desc = { enumerable: true, get: function() { return m[k]; } };\r\n }\r\n Object.defineProperty(o, k2, desc);\r\n}) : (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n o[k2] = m[k];\r\n});\r\n\r\nexport function __exportStar(m, o) {\r\n for (var p in m) if (p !== \"default\" && !Object.prototype.hasOwnProperty.call(o, p)) __createBinding(o, m, p);\r\n}\r\n\r\nexport function __values(o) {\r\n var s = typeof Symbol === \"function\" && Symbol.iterator, m = s && o[s], i = 0;\r\n if (m) return m.call(o);\r\n if (o && typeof o.length === \"number\") return {\r\n next: function () {\r\n if (o && i >= o.length) o = void 0;\r\n return { value: o && o[i++], done: !o };\r\n }\r\n };\r\n throw new TypeError(s ? \"Object is not iterable.\" : \"Symbol.iterator is not defined.\");\r\n}\r\n\r\nexport function __read(o, n) {\r\n var m = typeof Symbol === \"function\" && o[Symbol.iterator];\r\n if (!m) return o;\r\n var i = m.call(o), r, ar = [], e;\r\n try {\r\n while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);\r\n }\r\n catch (error) { e = { error: error }; }\r\n finally {\r\n try {\r\n if (r && !r.done && (m = i[\"return\"])) m.call(i);\r\n }\r\n finally { if (e) throw e.error; }\r\n }\r\n return ar;\r\n}\r\n\r\n/** @deprecated */\r\nexport function __spread() {\r\n for (var ar = [], i = 0; i < arguments.length; i++)\r\n ar = ar.concat(__read(arguments[i]));\r\n return ar;\r\n}\r\n\r\n/** @deprecated */\r\nexport function __spreadArrays() {\r\n for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;\r\n for (var r = Array(s), k = 0, i = 0; i < il; i++)\r\n for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)\r\n r[k] = a[j];\r\n return r;\r\n}\r\n\r\nexport function __spreadArray(to, from, pack) {\r\n if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {\r\n if (ar || !(i in from)) {\r\n if (!ar) ar = Array.prototype.slice.call(from, 0, i);\r\n ar[i] = from[i];\r\n }\r\n }\r\n return to.concat(ar || Array.prototype.slice.call(from));\r\n}\r\n\r\nexport function __await(v) {\r\n return this instanceof __await ? (this.v = v, this) : new __await(v);\r\n}\r\n\r\nexport function __asyncGenerator(thisArg, _arguments, generator) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var g = generator.apply(thisArg, _arguments || []), i, q = [];\r\n return i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i;\r\n function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }\r\n function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }\r\n function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }\r\n function fulfill(value) { resume(\"next\", value); }\r\n function reject(value) { resume(\"throw\", value); }\r\n function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }\r\n}\r\n\r\nexport function __asyncDelegator(o) {\r\n var i, p;\r\n return i = {}, verb(\"next\"), verb(\"throw\", function (e) { throw e; }), verb(\"return\"), i[Symbol.iterator] = function () { return this; }, i;\r\n function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: false } : f ? f(v) : v; } : f; }\r\n}\r\n\r\nexport function __asyncValues(o) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var m = o[Symbol.asyncIterator], i;\r\n return m ? m.call(o) : (o = typeof __values === \"function\" ? __values(o) : o[Symbol.iterator](), i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i);\r\n function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }\r\n function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }\r\n}\r\n\r\nexport function __makeTemplateObject(cooked, raw) {\r\n if (Object.defineProperty) { Object.defineProperty(cooked, \"raw\", { value: raw }); } else { cooked.raw = raw; }\r\n return cooked;\r\n};\r\n\r\nvar __setModuleDefault = Object.create ? (function(o, v) {\r\n Object.defineProperty(o, \"default\", { enumerable: true, value: v });\r\n}) : function(o, v) {\r\n o[\"default\"] = v;\r\n};\r\n\r\nexport function __importStar(mod) {\r\n if (mod && mod.__esModule) return mod;\r\n var result = {};\r\n if (mod != null) for (var k in mod) if (k !== \"default\" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);\r\n __setModuleDefault(result, mod);\r\n return result;\r\n}\r\n\r\nexport function __importDefault(mod) {\r\n return (mod && mod.__esModule) ? mod : { default: mod };\r\n}\r\n\r\nexport function __classPrivateFieldGet(receiver, state, kind, f) {\r\n if (kind === \"a\" && !f) throw new TypeError(\"Private accessor was defined without a getter\");\r\n if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError(\"Cannot read private member from an object whose class did not declare it\");\r\n return kind === \"m\" ? f : kind === \"a\" ? f.call(receiver) : f ? f.value : state.get(receiver);\r\n}\r\n\r\nexport function __classPrivateFieldSet(receiver, state, value, kind, f) {\r\n if (kind === \"m\") throw new TypeError(\"Private method is not writable\");\r\n if (kind === \"a\" && !f) throw new TypeError(\"Private accessor was defined without a setter\");\r\n if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError(\"Cannot write private member to an object whose class did not declare it\");\r\n return (kind === \"a\" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;\r\n}\r\n\r\nexport function __classPrivateFieldIn(state, receiver) {\r\n if (receiver === null || (typeof receiver !== \"object\" && typeof receiver !== \"function\")) throw new TypeError(\"Cannot use 'in' operator on non-object\");\r\n return typeof state === \"function\" ? receiver === state : state.has(receiver);\r\n}\r\n\r\nexport function __addDisposableResource(env, value, async) {\r\n if (value !== null && value !== void 0) {\r\n if (typeof value !== \"object\" && typeof value !== \"function\") throw new TypeError(\"Object expected.\");\r\n var dispose;\r\n if (async) {\r\n if (!Symbol.asyncDispose) throw new TypeError(\"Symbol.asyncDispose is not defined.\");\r\n dispose = value[Symbol.asyncDispose];\r\n }\r\n if (dispose === void 0) {\r\n if (!Symbol.dispose) throw new TypeError(\"Symbol.dispose is not defined.\");\r\n dispose = value[Symbol.dispose];\r\n }\r\n if (typeof dispose !== \"function\") throw new TypeError(\"Object not disposable.\");\r\n env.stack.push({ value: value, dispose: dispose, async: async });\r\n }\r\n else if (async) {\r\n env.stack.push({ async: true });\r\n }\r\n return value;\r\n}\r\n\r\nvar _SuppressedError = typeof SuppressedError === \"function\" ? SuppressedError : function (error, suppressed, message) {\r\n var e = new Error(message);\r\n return e.name = \"SuppressedError\", e.error = error, e.suppressed = suppressed, e;\r\n};\r\n\r\nexport function __disposeResources(env) {\r\n function fail(e) {\r\n env.error = env.hasError ? new _SuppressedError(e, env.error, \"An error was suppressed during disposal.\") : e;\r\n env.hasError = true;\r\n }\r\n function next() {\r\n while (env.stack.length) {\r\n var rec = env.stack.pop();\r\n try {\r\n var result = rec.dispose && rec.dispose.call(rec.value);\r\n if (rec.async) return Promise.resolve(result).then(next, function(e) { fail(e); return next(); });\r\n }\r\n catch (e) {\r\n fail(e);\r\n }\r\n }\r\n if (env.hasError) throw env.error;\r\n }\r\n return next();\r\n}\r\n\r\nexport default {\r\n __extends: __extends,\r\n __assign: __assign,\r\n __rest: __rest,\r\n __decorate: __decorate,\r\n __param: __param,\r\n __metadata: __metadata,\r\n __awaiter: __awaiter,\r\n __generator: __generator,\r\n __createBinding: __createBinding,\r\n __exportStar: __exportStar,\r\n __values: __values,\r\n __read: __read,\r\n __spread: __spread,\r\n __spreadArrays: __spreadArrays,\r\n __spreadArray: __spreadArray,\r\n __await: __await,\r\n __asyncGenerator: __asyncGenerator,\r\n __asyncDelegator: __asyncDelegator,\r\n __asyncValues: __asyncValues,\r\n __makeTemplateObject: __makeTemplateObject,\r\n __importStar: __importStar,\r\n __importDefault: __importDefault,\r\n __classPrivateFieldGet: __classPrivateFieldGet,\r\n __classPrivateFieldSet: __classPrivateFieldSet,\r\n __classPrivateFieldIn: __classPrivateFieldIn,\r\n __addDisposableResource: __addDisposableResource,\r\n __disposeResources: __disposeResources,\r\n};\r\n","'use client'\n\nimport { useFrame } from '@studio-freight/hamo'\nimport Lenis, { LenisOptions } from '@studio-freight/lenis'\nimport cn from 'clsx'\nimport React, {\n ForwardRefExoticComponent,\n PropsWithoutRef,\n ReactNode,\n RefAttributes,\n createContext,\n forwardRef,\n useCallback,\n useContext,\n useEffect,\n useImperativeHandle,\n useRef,\n useState,\n} from 'react'\nimport { create } from 'zustand'\nimport { version } from '../package.json'\n\nif (typeof window !== 'undefined') window.reactLenisVersion = version\n\nexport const LenisContext = createContext() as Lenis | null\n\nconst useRoot = create(() => ({}))\n\nfunction useCurrentLenis() {\n const local = useContext(LenisContext)\n const root = useRoot()\n\n return local ?? root\n}\n\nexport function useLenis(\n callback?: (lenis: Lenis) => void,\n deps?: Array = [],\n priority = 0\n): Lenis | undefined {\n const { lenis, addCallback, removeCallback } = useCurrentLenis()\n\n useEffect(() => {\n if (!callback || !addCallback || !removeCallback || !lenis) return\n\n addCallback(callback, priority)\n callback(lenis)\n\n return () => {\n removeCallback(callback)\n }\n }, [lenis, addCallback, removeCallback, priority, ...deps])\n\n return lenis\n}\n\ntype ForwardRefComponent = ForwardRefExoticComponent<\n PropsWithoutRef

& RefAttributes\n>\n\ntype Props = {\n root?: boolean\n options?: LenisOptions\n autoRaf?: boolean\n rafPriority?: number\n className?: string\n children?: ReactNode\n props?: any\n}\n\ntype LenisRef = {\n wrapper?: HTMLElement\n content?: HTMLElement\n lenis?: Lenis\n}\n\nconst ReactLenis: ForwardRefComponent = forwardRef<\n LenisRef,\n Props\n>(\n (\n {\n children,\n root = false,\n options = {},\n autoRaf = true,\n rafPriority = 0,\n className,\n ...props\n }: Props,\n ref\n ) => {\n const wrapperRef = useRef()\n const contentRef = useRef()\n\n const [lenis, setLenis] = useState()\n\n const callbacksRefs = useRef([])\n\n const addCallback = useCallback((callback, priority) => {\n callbacksRefs.current.push({ callback, priority })\n callbacksRefs.current.sort((a, b) => a.priority - b.priority)\n }, [])\n\n const removeCallback = useCallback((callback) => {\n callbacksRefs.current = callbacksRefs.current.filter(\n (cb) => cb.callback !== callback\n )\n }, [])\n\n useImperativeHandle(\n ref,\n () => ({\n wrapper: wrapperRef.current,\n content: contentRef.current,\n lenis,\n }),\n [lenis]\n )\n\n useEffect(() => {\n const lenis = new Lenis({\n ...options,\n ...(!root && {\n wrapper: wrapperRef.current,\n content: contentRef.current,\n }),\n })\n\n setLenis(lenis)\n\n return () => {\n lenis.destroy()\n setLenis(undefined)\n }\n }, [root, JSON.stringify(options)])\n\n useFrame((time) => {\n if (autoRaf) {\n lenis?.raf(time)\n }\n }, rafPriority)\n\n useEffect(() => {\n if (root && lenis) {\n useRoot.setState({ lenis, addCallback, removeCallback })\n }\n }, [root, lenis, addCallback, removeCallback])\n\n const onScroll = useCallback((e) => {\n for (let i = 0; i < callbacksRefs.current.length; i++) {\n callbacksRefs.current[i].callback(e)\n }\n }, [])\n\n useEffect(() => {\n lenis?.on('scroll', onScroll)\n\n return () => {\n lenis?.off('scroll', onScroll)\n }\n }, [lenis, onScroll])\n\n const onClassNameChange = useCallback(() => {\n if (wrapperRef.current) {\n wrapperRef.current.className = cn(lenis?.className, className)\n }\n }, [lenis, className])\n\n useEffect(() => {\n onClassNameChange()\n\n lenis?.on('className change', onClassNameChange)\n\n return () => {\n lenis?.off('className change', onClassNameChange)\n }\n }, [lenis, onClassNameChange])\n\n return (\n \n {root ? (\n children\n ) : (\n \n

{children}
\n \n )}\n \n )\n }\n)\n\nexport { ReactLenis as Lenis, ReactLenis }\nexport default ReactLenis\n"],"names":["SuppressedError","window","reactLenisVersion","LenisContext","createContext","useRoot","create","ReactLenis","forwardRef","_a","ref","children","root","options","autoRaf","rafPriority","className","props","s","e","t","p","Object","prototype","hasOwnProperty","call","indexOf","getOwnPropertySymbols","i","length","propertyIsEnumerable","__rest","wrapperRef","useRef","contentRef","lenis","setLenis","useState","callbacksRefs","addCallback","useCallback","callback","priority","current","push","sort","a","b","removeCallback","filter","cb","useImperativeHandle","wrapper","content","useEffect","Lenis","assign","destroy","undefined","JSON","stringify","useFrame","time","raf","setState","onScroll","on","off","onClassNameChange","cn","React","Provider","value","createElement","deps","local","useContext","useCurrentLenis"],"mappings":"uMA2TkD,mBAApBA,iBAAiCA,gBCrSzC,oBAAXC,SAAwBA,OAAOC,4BAE7BC,MAAAA,EAAeC,EAAAA,gBAEtBC,EAAUC,EAAMA,QAAC,MAAS,KAkD1BC,MAAAA,EAAmDC,EAAUA,YAIjE,CACEC,EASAC,SATAC,SACEA,EAAQC,KACRA,GAAO,EAAKC,QACZA,EAAU,CAAE,EAAAC,QACZA,GAAU,EAAIC,YACdA,EAAc,EAACC,UACfA,KACGC,ED9CF,SAAgBC,EAAGC,GACtB,IAAIC,EAAI,CAAA,EACR,IAAK,IAAIC,KAAKH,EAAOI,OAAOC,UAAUC,eAAeC,KAAKP,EAAGG,IAAMF,EAAEO,QAAQL,GAAK,IAC9ED,EAAEC,GAAKH,EAAEG,IACb,GAAS,MAALH,GAAqD,mBAAjCI,OAAOK,sBACtB,KAAIC,EAAI,EAAb,IAAgBP,EAAIC,OAAOK,sBAAsBT,GAAIU,EAAIP,EAAEQ,OAAQD,IAC3DT,EAAEO,QAAQL,EAA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AChDU,EAAcK,QAAQf,GAAGa,SAAStB,EACpC,GACC,IAEHmC,EAAAA,WAAU,KACRnB,SAAAA,EAAO+B,GAAG,SAAUD,GAEb,KACL9B,SAAAA,EAAOgC,IAAI,SAAUF,EAAS,IAE/B,CAAC9B,EAAO8B,IAEX,MAAMG,EAAoB5B,EAAAA,aAAY,KAChCR,EAAWW,UACbX,EAAWW,QAAQ3B,UAAYqD,EAAGlC,eAAAA,EAAOnB,UAAWA,GACtD,GACC,CAACmB,EAAOnB,IAYX,OAVAsC,EAAAA,WAAU,KACRc,IAEAjC,SAAAA,EAAO+B,GAAG,mBAAoBE,GAEvB,KACLjC,SAAAA,EAAOgC,IAAI,mBAAoBC,EAAkB,IAElD,CAACjC,EAAOiC,IAGTE,gBAACnE,EAAaoE,SAAS,CAAAC,MAAO,CAAErC,QAAOI,cAAaS,mBACjDpC,EACCD,EAEA2D,EACEG,cAAA,MAAAnD,OAAAkC,OAAA,CAAA9C,IAAKsB,EACLhB,UAAWqD,EAAGlC,eAAAA,EAAOnB,UAAWA,IAC5BC,GAEJqD,EAAKG,cAAA,MAAA,CAAA/D,IAAKwB,GAAavB,IAGL,mGA7JxB,SACJ8B,EACAiC,EAAoB,GACpBhC,EAAW,GAEX,MAAMP,MAAEA,EAAKI,YAAEA,EAAWS,eAAEA,GAZ9B,WACE,MAAM2B,EAAQC,aAAWzE,GACnBS,EAAOP,IAEb,OAAOsE,QAAAA,EAAS/D,CAClB,CAOiDiE,GAa/C,OAXAvB,EAAAA,WAAU,KACR,GAAKb,GAAaF,GAAgBS,GAAmBb,EAKrD,OAHAI,EAAYE,EAAUC,GACtBD,EAASN,GAEF,KACLa,EAAeP,EAAS,CACzB,GACA,CAACN,EAAOI,EAAaS,EAAgBN,KAAagC,IAE9CvC,CACT","x_google_ignoreList":[0]} \ No newline at end of file +{"version":3,"file":"react-lenis.cjs.js","sources":["../../../node_modules/tslib/tslib.es6.js","../../src/index.tsx"],"sourcesContent":["/******************************************************************************\r\nCopyright (c) Microsoft Corporation.\r\n\r\nPermission to use, copy, modify, and/or distribute this software for any\r\npurpose with or without fee is hereby granted.\r\n\r\nTHE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\r\nREGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\r\nAND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\r\nINDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\r\nLOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\r\nOTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\r\nPERFORMANCE OF THIS SOFTWARE.\r\n***************************************************************************** */\r\n/* global Reflect, Promise, SuppressedError, Symbol */\r\n\r\nvar extendStatics = function(d, b) {\r\n extendStatics = Object.setPrototypeOf ||\r\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\r\n function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };\r\n return extendStatics(d, b);\r\n};\r\n\r\nexport function __extends(d, b) {\r\n if (typeof b !== \"function\" && b !== null)\r\n throw new TypeError(\"Class extends value \" + String(b) + \" is not a constructor or null\");\r\n extendStatics(d, b);\r\n function __() { this.constructor = d; }\r\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\r\n}\r\n\r\nexport var __assign = function() {\r\n __assign = Object.assign || function __assign(t) {\r\n for (var s, i = 1, n = arguments.length; i < n; i++) {\r\n s = arguments[i];\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];\r\n }\r\n return t;\r\n }\r\n return __assign.apply(this, arguments);\r\n}\r\n\r\nexport function __rest(s, e) {\r\n var t = {};\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)\r\n t[p] = s[p];\r\n if (s != null && typeof Object.getOwnPropertySymbols === \"function\")\r\n for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {\r\n if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))\r\n t[p[i]] = s[p[i]];\r\n }\r\n return t;\r\n}\r\n\r\nexport function __decorate(decorators, target, key, desc) {\r\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\r\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\r\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\r\n return c > 3 && r && Object.defineProperty(target, key, r), r;\r\n}\r\n\r\nexport function __param(paramIndex, decorator) {\r\n return function (target, key) { decorator(target, key, paramIndex); }\r\n}\r\n\r\nexport function __esDecorate(ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {\r\n function accept(f) { if (f !== void 0 && typeof f !== \"function\") throw new TypeError(\"Function expected\"); return f; }\r\n var kind = contextIn.kind, key = kind === \"getter\" ? \"get\" : kind === \"setter\" ? \"set\" : \"value\";\r\n var target = !descriptorIn && ctor ? contextIn[\"static\"] ? ctor : ctor.prototype : null;\r\n var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});\r\n var _, done = false;\r\n for (var i = decorators.length - 1; i >= 0; i--) {\r\n var context = {};\r\n for (var p in contextIn) context[p] = p === \"access\" ? {} : contextIn[p];\r\n for (var p in contextIn.access) context.access[p] = contextIn.access[p];\r\n context.addInitializer = function (f) { if (done) throw new TypeError(\"Cannot add initializers after decoration has completed\"); extraInitializers.push(accept(f || null)); };\r\n var result = (0, decorators[i])(kind === \"accessor\" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);\r\n if (kind === \"accessor\") {\r\n if (result === void 0) continue;\r\n if (result === null || typeof result !== \"object\") throw new TypeError(\"Object expected\");\r\n if (_ = accept(result.get)) descriptor.get = _;\r\n if (_ = accept(result.set)) descriptor.set = _;\r\n if (_ = accept(result.init)) initializers.unshift(_);\r\n }\r\n else if (_ = accept(result)) {\r\n if (kind === \"field\") initializers.unshift(_);\r\n else descriptor[key] = _;\r\n }\r\n }\r\n if (target) Object.defineProperty(target, contextIn.name, descriptor);\r\n done = true;\r\n};\r\n\r\nexport function __runInitializers(thisArg, initializers, value) {\r\n var useValue = arguments.length > 2;\r\n for (var i = 0; i < initializers.length; i++) {\r\n value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);\r\n }\r\n return useValue ? value : void 0;\r\n};\r\n\r\nexport function __propKey(x) {\r\n return typeof x === \"symbol\" ? x : \"\".concat(x);\r\n};\r\n\r\nexport function __setFunctionName(f, name, prefix) {\r\n if (typeof name === \"symbol\") name = name.description ? \"[\".concat(name.description, \"]\") : \"\";\r\n return Object.defineProperty(f, \"name\", { configurable: true, value: prefix ? \"\".concat(prefix, \" \", name) : name });\r\n};\r\n\r\nexport function __metadata(metadataKey, metadataValue) {\r\n if (typeof Reflect === \"object\" && typeof Reflect.metadata === \"function\") return Reflect.metadata(metadataKey, metadataValue);\r\n}\r\n\r\nexport function __awaiter(thisArg, _arguments, P, generator) {\r\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\r\n return new (P || (P = Promise))(function (resolve, reject) {\r\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\r\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\r\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\r\n step((generator = generator.apply(thisArg, _arguments || [])).next());\r\n });\r\n}\r\n\r\nexport function __generator(thisArg, body) {\r\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\r\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\r\n function verb(n) { return function (v) { return step([n, v]); }; }\r\n function step(op) {\r\n if (f) throw new TypeError(\"Generator is already executing.\");\r\n while (g && (g = 0, op[0] && (_ = 0)), _) try {\r\n if (f = 1, y && (t = op[0] & 2 ? y[\"return\"] : op[0] ? y[\"throw\"] || ((t = y[\"return\"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;\r\n if (y = 0, t) op = [op[0] & 2, t.value];\r\n switch (op[0]) {\r\n case 0: case 1: t = op; break;\r\n case 4: _.label++; return { value: op[1], done: false };\r\n case 5: _.label++; y = op[1]; op = [0]; continue;\r\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\r\n default:\r\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\r\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\r\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\r\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\r\n if (t[2]) _.ops.pop();\r\n _.trys.pop(); continue;\r\n }\r\n op = body.call(thisArg, _);\r\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\r\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\r\n }\r\n}\r\n\r\nexport var __createBinding = Object.create ? (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n var desc = Object.getOwnPropertyDescriptor(m, k);\r\n if (!desc || (\"get\" in desc ? !m.__esModule : desc.writable || desc.configurable)) {\r\n desc = { enumerable: true, get: function() { return m[k]; } };\r\n }\r\n Object.defineProperty(o, k2, desc);\r\n}) : (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n o[k2] = m[k];\r\n});\r\n\r\nexport function __exportStar(m, o) {\r\n for (var p in m) if (p !== \"default\" && !Object.prototype.hasOwnProperty.call(o, p)) __createBinding(o, m, p);\r\n}\r\n\r\nexport function __values(o) {\r\n var s = typeof Symbol === \"function\" && Symbol.iterator, m = s && o[s], i = 0;\r\n if (m) return m.call(o);\r\n if (o && typeof o.length === \"number\") return {\r\n next: function () {\r\n if (o && i >= o.length) o = void 0;\r\n return { value: o && o[i++], done: !o };\r\n }\r\n };\r\n throw new TypeError(s ? \"Object is not iterable.\" : \"Symbol.iterator is not defined.\");\r\n}\r\n\r\nexport function __read(o, n) {\r\n var m = typeof Symbol === \"function\" && o[Symbol.iterator];\r\n if (!m) return o;\r\n var i = m.call(o), r, ar = [], e;\r\n try {\r\n while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);\r\n }\r\n catch (error) { e = { error: error }; }\r\n finally {\r\n try {\r\n if (r && !r.done && (m = i[\"return\"])) m.call(i);\r\n }\r\n finally { if (e) throw e.error; }\r\n }\r\n return ar;\r\n}\r\n\r\n/** @deprecated */\r\nexport function __spread() {\r\n for (var ar = [], i = 0; i < arguments.length; i++)\r\n ar = ar.concat(__read(arguments[i]));\r\n return ar;\r\n}\r\n\r\n/** @deprecated */\r\nexport function __spreadArrays() {\r\n for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;\r\n for (var r = Array(s), k = 0, i = 0; i < il; i++)\r\n for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)\r\n r[k] = a[j];\r\n return r;\r\n}\r\n\r\nexport function __spreadArray(to, from, pack) {\r\n if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {\r\n if (ar || !(i in from)) {\r\n if (!ar) ar = Array.prototype.slice.call(from, 0, i);\r\n ar[i] = from[i];\r\n }\r\n }\r\n return to.concat(ar || Array.prototype.slice.call(from));\r\n}\r\n\r\nexport function __await(v) {\r\n return this instanceof __await ? (this.v = v, this) : new __await(v);\r\n}\r\n\r\nexport function __asyncGenerator(thisArg, _arguments, generator) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var g = generator.apply(thisArg, _arguments || []), i, q = [];\r\n return i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i;\r\n function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }\r\n function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }\r\n function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }\r\n function fulfill(value) { resume(\"next\", value); }\r\n function reject(value) { resume(\"throw\", value); }\r\n function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }\r\n}\r\n\r\nexport function __asyncDelegator(o) {\r\n var i, p;\r\n return i = {}, verb(\"next\"), verb(\"throw\", function (e) { throw e; }), verb(\"return\"), i[Symbol.iterator] = function () { return this; }, i;\r\n function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: false } : f ? f(v) : v; } : f; }\r\n}\r\n\r\nexport function __asyncValues(o) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var m = o[Symbol.asyncIterator], i;\r\n return m ? m.call(o) : (o = typeof __values === \"function\" ? __values(o) : o[Symbol.iterator](), i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i);\r\n function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }\r\n function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }\r\n}\r\n\r\nexport function __makeTemplateObject(cooked, raw) {\r\n if (Object.defineProperty) { Object.defineProperty(cooked, \"raw\", { value: raw }); } else { cooked.raw = raw; }\r\n return cooked;\r\n};\r\n\r\nvar __setModuleDefault = Object.create ? (function(o, v) {\r\n Object.defineProperty(o, \"default\", { enumerable: true, value: v });\r\n}) : function(o, v) {\r\n o[\"default\"] = v;\r\n};\r\n\r\nexport function __importStar(mod) {\r\n if (mod && mod.__esModule) return mod;\r\n var result = {};\r\n if (mod != null) for (var k in mod) if (k !== \"default\" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);\r\n __setModuleDefault(result, mod);\r\n return result;\r\n}\r\n\r\nexport function __importDefault(mod) {\r\n return (mod && mod.__esModule) ? mod : { default: mod };\r\n}\r\n\r\nexport function __classPrivateFieldGet(receiver, state, kind, f) {\r\n if (kind === \"a\" && !f) throw new TypeError(\"Private accessor was defined without a getter\");\r\n if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError(\"Cannot read private member from an object whose class did not declare it\");\r\n return kind === \"m\" ? f : kind === \"a\" ? f.call(receiver) : f ? f.value : state.get(receiver);\r\n}\r\n\r\nexport function __classPrivateFieldSet(receiver, state, value, kind, f) {\r\n if (kind === \"m\") throw new TypeError(\"Private method is not writable\");\r\n if (kind === \"a\" && !f) throw new TypeError(\"Private accessor was defined without a setter\");\r\n if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError(\"Cannot write private member to an object whose class did not declare it\");\r\n return (kind === \"a\" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;\r\n}\r\n\r\nexport function __classPrivateFieldIn(state, receiver) {\r\n if (receiver === null || (typeof receiver !== \"object\" && typeof receiver !== \"function\")) throw new TypeError(\"Cannot use 'in' operator on non-object\");\r\n return typeof state === \"function\" ? receiver === state : state.has(receiver);\r\n}\r\n\r\nexport function __addDisposableResource(env, value, async) {\r\n if (value !== null && value !== void 0) {\r\n if (typeof value !== \"object\" && typeof value !== \"function\") throw new TypeError(\"Object expected.\");\r\n var dispose;\r\n if (async) {\r\n if (!Symbol.asyncDispose) throw new TypeError(\"Symbol.asyncDispose is not defined.\");\r\n dispose = value[Symbol.asyncDispose];\r\n }\r\n if (dispose === void 0) {\r\n if (!Symbol.dispose) throw new TypeError(\"Symbol.dispose is not defined.\");\r\n dispose = value[Symbol.dispose];\r\n }\r\n if (typeof dispose !== \"function\") throw new TypeError(\"Object not disposable.\");\r\n env.stack.push({ value: value, dispose: dispose, async: async });\r\n }\r\n else if (async) {\r\n env.stack.push({ async: true });\r\n }\r\n return value;\r\n}\r\n\r\nvar _SuppressedError = typeof SuppressedError === \"function\" ? SuppressedError : function (error, suppressed, message) {\r\n var e = new Error(message);\r\n return e.name = \"SuppressedError\", e.error = error, e.suppressed = suppressed, e;\r\n};\r\n\r\nexport function __disposeResources(env) {\r\n function fail(e) {\r\n env.error = env.hasError ? new _SuppressedError(e, env.error, \"An error was suppressed during disposal.\") : e;\r\n env.hasError = true;\r\n }\r\n function next() {\r\n while (env.stack.length) {\r\n var rec = env.stack.pop();\r\n try {\r\n var result = rec.dispose && rec.dispose.call(rec.value);\r\n if (rec.async) return Promise.resolve(result).then(next, function(e) { fail(e); return next(); });\r\n }\r\n catch (e) {\r\n fail(e);\r\n }\r\n }\r\n if (env.hasError) throw env.error;\r\n }\r\n return next();\r\n}\r\n\r\nexport default {\r\n __extends: __extends,\r\n __assign: __assign,\r\n __rest: __rest,\r\n __decorate: __decorate,\r\n __param: __param,\r\n __metadata: __metadata,\r\n __awaiter: __awaiter,\r\n __generator: __generator,\r\n __createBinding: __createBinding,\r\n __exportStar: __exportStar,\r\n __values: __values,\r\n __read: __read,\r\n __spread: __spread,\r\n __spreadArrays: __spreadArrays,\r\n __spreadArray: __spreadArray,\r\n __await: __await,\r\n __asyncGenerator: __asyncGenerator,\r\n __asyncDelegator: __asyncDelegator,\r\n __asyncValues: __asyncValues,\r\n __makeTemplateObject: __makeTemplateObject,\r\n __importStar: __importStar,\r\n __importDefault: __importDefault,\r\n __classPrivateFieldGet: __classPrivateFieldGet,\r\n __classPrivateFieldSet: __classPrivateFieldSet,\r\n __classPrivateFieldIn: __classPrivateFieldIn,\r\n __addDisposableResource: __addDisposableResource,\r\n __disposeResources: __disposeResources,\r\n};\r\n","'use client'\r\n\r\nimport { useFrame } from '@studio-freight/hamo'\r\nimport Lenis, { LenisOptions } from '@studio-freight/lenis'\r\nimport cn from 'clsx'\r\nimport React, {\r\n ForwardRefExoticComponent,\r\n PropsWithoutRef,\r\n ReactNode,\r\n RefAttributes,\r\n createContext,\r\n forwardRef,\r\n useCallback,\r\n useContext,\r\n useEffect,\r\n useImperativeHandle,\r\n useRef,\r\n useState,\r\n} from 'react'\r\nimport { create } from 'zustand'\r\nimport { version } from '../package.json'\r\n\r\ntype LenisEventHandler = (lenis: Lenis) => void\r\ninterface LenisContextValue {\r\n lenis: Lenis\r\n addCallback: (handler: LenisEventHandler, priority: number) => void\r\n removeCallback: (handler: LenisEventHandler) => void\r\n}\r\n\r\ndeclare global {\r\n interface Window {\r\n reactLenisVersion: string\r\n }\r\n}\r\nif (typeof window !== 'undefined') {\r\n window.reactLenisVersion = version\r\n}\r\n\r\nexport const LenisContext = createContext(null)\r\n\r\nconst useRoot = create>(() => ({}))\r\n\r\nfunction useCurrentLenis() {\r\n const local = useContext(LenisContext)\r\n const root = useRoot()\r\n\r\n return local ?? root\r\n}\r\n\r\nexport function useLenis(\r\n callback?: (lenis: Lenis) => void,\r\n deps: Array = [],\r\n priority = 0\r\n): Lenis | undefined {\r\n const { lenis, addCallback, removeCallback } = useCurrentLenis()\r\n\r\n useEffect(() => {\r\n if (!callback || !addCallback || !removeCallback || !lenis) return\r\n\r\n addCallback(callback, priority)\r\n callback(lenis)\r\n\r\n return () => {\r\n removeCallback(callback)\r\n }\r\n }, [lenis, addCallback, removeCallback, priority, ...deps])\r\n\r\n return lenis\r\n}\r\n\r\ntype ForwardRefComponent = ForwardRefExoticComponent<\r\n PropsWithoutRef

& RefAttributes\r\n>\r\n\r\ntype Props = {\r\n root?: boolean\r\n options?: LenisOptions\r\n autoRaf?: boolean\r\n rafPriority?: number\r\n className?: string\r\n children?: ReactNode\r\n props?: any\r\n}\r\n\r\ntype LenisRef = {\r\n wrapper?: HTMLElement\r\n content?: HTMLElement\r\n lenis?: Lenis\r\n}\r\n\r\nconst ReactLenis: ForwardRefComponent = forwardRef<\r\n LenisRef,\r\n Props\r\n>(\r\n (\r\n {\r\n children,\r\n root = false,\r\n options = {},\r\n autoRaf = true,\r\n rafPriority = 0,\r\n className,\r\n ...props\r\n }: Props,\r\n ref\r\n ) => {\r\n const wrapperRef = useRef(null)\r\n const contentRef = useRef(null)\r\n\r\n const [lenis, setLenis] = useState(undefined)\r\n\r\n const callbacksRefs = useRef<\r\n {\r\n callback: LenisEventHandler\r\n priority: number\r\n }[]\r\n >([])\r\n\r\n const addCallback: LenisContextValue['addCallback'] = useCallback(\r\n (callback, priority) => {\r\n callbacksRefs.current.push({ callback, priority })\r\n callbacksRefs.current.sort((a, b) => a.priority - b.priority)\r\n },\r\n []\r\n )\r\n\r\n const removeCallback: LenisContextValue['removeCallback'] = useCallback(\r\n (callback) => {\r\n callbacksRefs.current = callbacksRefs.current.filter(\r\n (cb) => cb.callback !== callback\r\n )\r\n },\r\n []\r\n )\r\n\r\n useImperativeHandle(\r\n ref,\r\n () => ({\r\n wrapper: wrapperRef.current!,\r\n content: contentRef.current!,\r\n lenis,\r\n }),\r\n [lenis]\r\n )\r\n\r\n useEffect(() => {\r\n const lenis = new Lenis({\r\n ...options,\r\n ...(!root && {\r\n wrapper: wrapperRef.current!,\r\n content: contentRef.current!,\r\n }),\r\n })\r\n\r\n setLenis(lenis)\r\n\r\n return () => {\r\n lenis.destroy()\r\n setLenis(undefined)\r\n }\r\n }, [root, JSON.stringify(options)])\r\n\r\n useFrame((time: number) => {\r\n if (autoRaf) {\r\n lenis?.raf(time)\r\n }\r\n }, rafPriority)\r\n\r\n useEffect(() => {\r\n if (root && lenis) {\r\n useRoot.setState({ lenis, addCallback, removeCallback })\r\n }\r\n }, [root, lenis, addCallback, removeCallback])\r\n\r\n const onScroll = useCallback((lenisInstance: Lenis) => {\r\n for (let i = 0; i < callbacksRefs.current.length; i++) {\r\n callbacksRefs.current[i].callback(lenisInstance)\r\n }\r\n }, [])\r\n\r\n useEffect(() => {\r\n lenis?.on('scroll', onScroll)\r\n\r\n return () => {\r\n lenis?.off('scroll', onScroll)\r\n }\r\n }, [lenis, onScroll])\r\n\r\n const onClassNameChange = useCallback(() => {\r\n if (wrapperRef.current) {\r\n wrapperRef.current.className = cn(lenis?.className, className)\r\n }\r\n }, [lenis, className])\r\n\r\n useEffect(() => {\r\n onClassNameChange()\r\n\r\n lenis?.on('className change', onClassNameChange)\r\n\r\n return () => {\r\n lenis?.off('className change', onClassNameChange)\r\n }\r\n }, [lenis, onClassNameChange])\r\n\r\n return (\r\n \r\n {root ? (\r\n children\r\n ) : (\r\n \r\n

{children}
\r\n \r\n )}\r\n \r\n )\r\n }\r\n)\r\n\r\nexport { ReactLenis as Lenis, ReactLenis }\r\nexport default ReactLenis\r\n"],"names":["SuppressedError","window","reactLenisVersion","LenisContext","createContext","useRoot","create","ReactLenis","forwardRef","_a","ref","children","root","options","autoRaf","rafPriority","className","props","s","e","t","p","Object","prototype","hasOwnProperty","call","indexOf","getOwnPropertySymbols","i","length","propertyIsEnumerable","__rest","wrapperRef","useRef","contentRef","lenis","setLenis","useState","undefined","callbacksRefs","addCallback","useCallback","callback","priority","current","push","sort","a","b","removeCallback","filter","cb","useImperativeHandle","wrapper","content","useEffect","Lenis","assign","destroy","JSON","stringify","useFrame","time","raf","setState","onScroll","lenisInstance","on","off","onClassNameChange","cn","React","Provider","value","createElement","deps","local","useContext","useCurrentLenis"],"mappings":"uMA2TkD,mBAApBA,iBAAiCA,gBCzRzC,oBAAXC,SACTA,OAAOC,kCAGIC,EAAeC,EAAaA,cAA2B,MAE9DC,EAAUC,EAAMA,QAA6B,MAAS,KAkDtDC,MAAAA,EAAmDC,EAAUA,YAIjE,CACEC,EASAC,SATAC,SACEA,EAAQC,KACRA,GAAO,EAAKC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EAAWS,eAAEA,GAZ9B,WACE,MAAM2B,EAAQC,aAAW1E,GACnBS,EAAOP,IAEb,OAAOuE,QAAAA,EAAShE,CAClB,CAOiDkE,GAa/C,OAXAvB,EAAAA,WAAU,KACR,GAAKb,GAAaF,GAAgBS,GAAmBd,EAKrD,OAHAK,EAAYE,EAAUC,GACtBD,EAASP,GAEF,KACLc,EAAeP,EAAS,CACzB,GACA,CAACP,EAAOK,EAAaS,EAAgBN,KAAagC,IAE9CxC,CACT","x_google_ignoreList":[0]} \ No newline at end of file diff --git a/packages/react-lenis/dist/react-lenis.mjs b/packages/react-lenis/dist/react-lenis.mjs index ff9a7f43..329d125f 100644 --- a/packages/react-lenis/dist/react-lenis.mjs +++ b/packages/react-lenis/dist/react-lenis.mjs @@ -1,2 +1,2 @@ -import{useFrame as r}from"@studio-freight/hamo";import e from"@studio-freight/lenis";import t from"clsx";import n,{createContext as o,useEffect as l,forwardRef as a,useRef as c,useState as s,useCallback as i,useImperativeHandle as u,useContext as f}from"react";import{create as p}from"zustand";"function"==typeof SuppressedError&&SuppressedError;"undefined"!=typeof window&&(window.reactLenisVersion="0.0.46");const m=o(),d=p((()=>({})));function b(r,e=[],t=0){const{lenis:n,addCallback:o,removeCallback:a}=function(){const r=f(m),e=d();return null!=r?r:e}();return l((()=>{if(r&&o&&a&&n)return o(r,t),r(n),()=>{a(r)}}),[n,o,a,t,...e]),n}const y=a(((o,a)=>{var{children:f,root:p=!1,options:b={},autoRaf:y=!0,rafPriority:v=0,className:O}=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 o=0;for(n=Object.getOwnPropertySymbols(r);o{j.current.push({callback:r,priority:e}),j.current.sort(((r,e)=>r.priority-e.priority))}),[]),E=i((r=>{j.current=j.current.filter((e=>e.callback!==r))}),[]);u(a,(()=>({wrapper:h.current,content:w.current,lenis:k})),[k]),l((()=>{const r=new e(Object.assign(Object.assign({},b),!p&&{wrapper:h.current,content:w.current}));return N(r),()=>{r.destroy(),N(void 0)}}),[p,JSON.stringify(b)]),r((r=>{y&&(null==k||k.raf(r))}),v),l((()=>{p&&k&&d.setState({lenis:k,addCallback:C,removeCallback:E})}),[p,k,C,E]);const P=i((r=>{for(let e=0;e(null==k||k.on("scroll",P),()=>{null==k||k.off("scroll",P)})),[k,P]);const S=i((()=>{h.current&&(h.current.className=t(null==k?void 0:k.className,O))}),[k,O]);return l((()=>(S(),null==k||k.on("className change",S),()=>{null==k||k.off("className change",S)})),[k,S]),n.createElement(m.Provider,{value:{lenis:k,addCallback:C,removeCallback:E}},p?f:n.createElement("div",Object.assign({ref:h,className:t(null==k?void 0:k.className,O)},g),n.createElement("div",{ref:w},f)))}));export{y as Lenis,m as LenisContext,y as ReactLenis,y as default,b as useLenis}; +import{useFrame as r}from"@studio-freight/hamo";import e from"@studio-freight/lenis";import t from"clsx";import n,{createContext as o,useEffect as l,forwardRef as a,useRef as c,useState as s,useCallback as i,useImperativeHandle as u,useContext as f}from"react";import{create as p}from"zustand";"function"==typeof SuppressedError&&SuppressedError;"undefined"!=typeof window&&(window.reactLenisVersion="0.0.46");const d=o(null),m=p((()=>({})));function b(r,e=[],t=0){const{lenis:n,addCallback:o,removeCallback:a}=function(){const r=f(d),e=m();return null!=r?r:e}();return l((()=>{if(r&&o&&a&&n)return o(r,t),r(n),()=>{a(r)}}),[n,o,a,t,...e]),n}const y=a(((o,a)=>{var{children:f,root:p=!1,options:b={},autoRaf:y=!0,rafPriority:v=0,className:O}=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 o=0;for(n=Object.getOwnPropertySymbols(r);o{j.current.push({callback:r,priority:e}),j.current.sort(((r,e)=>r.priority-e.priority))}),[]),E=i((r=>{j.current=j.current.filter((e=>e.callback!==r))}),[]);u(a,(()=>({wrapper:h.current,content:w.current,lenis:k})),[k]),l((()=>{const r=new e(Object.assign(Object.assign({},b),!p&&{wrapper:h.current,content:w.current}));return N(r),()=>{r.destroy(),N(void 0)}}),[p,JSON.stringify(b)]),r((r=>{y&&(null==k||k.raf(r))}),v),l((()=>{p&&k&&m.setState({lenis:k,addCallback:C,removeCallback:E})}),[p,k,C,E]);const P=i((r=>{for(let e=0;e(null==k||k.on("scroll",P),()=>{null==k||k.off("scroll",P)})),[k,P]);const S=i((()=>{h.current&&(h.current.className=t(null==k?void 0:k.className,O))}),[k,O]);return l((()=>(S(),null==k||k.on("className change",S),()=>{null==k||k.off("className change",S)})),[k,S]),n.createElement(d.Provider,{value:{lenis:k,addCallback:C,removeCallback:E}},p?f:n.createElement("div",Object.assign({ref:h,className:t(null==k?void 0:k.className,O)},g),n.createElement("div",{ref:w},f)))}));export{y as Lenis,d as LenisContext,y as ReactLenis,y as default,b as useLenis}; //# sourceMappingURL=react-lenis.mjs.map diff --git a/packages/react-lenis/dist/react-lenis.mjs.map b/packages/react-lenis/dist/react-lenis.mjs.map index 49c51b07..45ca0861 100644 --- a/packages/react-lenis/dist/react-lenis.mjs.map +++ b/packages/react-lenis/dist/react-lenis.mjs.map @@ -1 +1 @@ -{"version":3,"file":"react-lenis.mjs","sources":["../../../node_modules/tslib/tslib.es6.js","../../src/index.tsx"],"sourcesContent":["/******************************************************************************\r\nCopyright (c) Microsoft Corporation.\r\n\r\nPermission to use, copy, modify, and/or distribute this software for any\r\npurpose with or without fee is hereby granted.\r\n\r\nTHE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\r\nREGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\r\nAND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\r\nINDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\r\nLOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\r\nOTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\r\nPERFORMANCE OF THIS SOFTWARE.\r\n***************************************************************************** */\r\n/* global Reflect, Promise, SuppressedError, Symbol */\r\n\r\nvar extendStatics = function(d, b) {\r\n extendStatics = Object.setPrototypeOf ||\r\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\r\n function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };\r\n return extendStatics(d, b);\r\n};\r\n\r\nexport function __extends(d, b) {\r\n if (typeof b !== \"function\" && b !== null)\r\n throw new TypeError(\"Class extends value \" + String(b) + \" is not a constructor or null\");\r\n extendStatics(d, b);\r\n function __() { this.constructor = d; }\r\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\r\n}\r\n\r\nexport var __assign = function() {\r\n __assign = Object.assign || function __assign(t) {\r\n for (var s, i = 1, n = arguments.length; i < n; i++) {\r\n s = arguments[i];\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];\r\n }\r\n return t;\r\n }\r\n return __assign.apply(this, arguments);\r\n}\r\n\r\nexport function __rest(s, e) {\r\n var t = {};\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)\r\n t[p] = s[p];\r\n if (s != null && typeof Object.getOwnPropertySymbols === \"function\")\r\n for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {\r\n if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))\r\n t[p[i]] = s[p[i]];\r\n }\r\n return t;\r\n}\r\n\r\nexport function __decorate(decorators, target, key, desc) {\r\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\r\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\r\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\r\n return c > 3 && r && Object.defineProperty(target, key, r), r;\r\n}\r\n\r\nexport function __param(paramIndex, decorator) {\r\n return function (target, key) { decorator(target, key, paramIndex); }\r\n}\r\n\r\nexport function __esDecorate(ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {\r\n function accept(f) { if (f !== void 0 && typeof f !== \"function\") throw new TypeError(\"Function expected\"); return f; }\r\n var kind = contextIn.kind, key = kind === \"getter\" ? \"get\" : kind === \"setter\" ? \"set\" : \"value\";\r\n var target = !descriptorIn && ctor ? contextIn[\"static\"] ? ctor : ctor.prototype : null;\r\n var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});\r\n var _, done = false;\r\n for (var i = decorators.length - 1; i >= 0; i--) {\r\n var context = {};\r\n for (var p in contextIn) context[p] = p === \"access\" ? {} : contextIn[p];\r\n for (var p in contextIn.access) context.access[p] = contextIn.access[p];\r\n context.addInitializer = function (f) { if (done) throw new TypeError(\"Cannot add initializers after decoration has completed\"); extraInitializers.push(accept(f || null)); };\r\n var result = (0, decorators[i])(kind === \"accessor\" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);\r\n if (kind === \"accessor\") {\r\n if (result === void 0) continue;\r\n if (result === null || typeof result !== \"object\") throw new TypeError(\"Object expected\");\r\n if (_ = accept(result.get)) descriptor.get = _;\r\n if (_ = accept(result.set)) descriptor.set = _;\r\n if (_ = accept(result.init)) initializers.unshift(_);\r\n }\r\n else if (_ = accept(result)) {\r\n if (kind === \"field\") initializers.unshift(_);\r\n else descriptor[key] = _;\r\n }\r\n }\r\n if (target) Object.defineProperty(target, contextIn.name, descriptor);\r\n done = true;\r\n};\r\n\r\nexport function __runInitializers(thisArg, initializers, value) {\r\n var useValue = arguments.length > 2;\r\n for (var i = 0; i < initializers.length; i++) {\r\n value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);\r\n }\r\n return useValue ? value : void 0;\r\n};\r\n\r\nexport function __propKey(x) {\r\n return typeof x === \"symbol\" ? x : \"\".concat(x);\r\n};\r\n\r\nexport function __setFunctionName(f, name, prefix) {\r\n if (typeof name === \"symbol\") name = name.description ? \"[\".concat(name.description, \"]\") : \"\";\r\n return Object.defineProperty(f, \"name\", { configurable: true, value: prefix ? \"\".concat(prefix, \" \", name) : name });\r\n};\r\n\r\nexport function __metadata(metadataKey, metadataValue) {\r\n if (typeof Reflect === \"object\" && typeof Reflect.metadata === \"function\") return Reflect.metadata(metadataKey, metadataValue);\r\n}\r\n\r\nexport function __awaiter(thisArg, _arguments, P, generator) {\r\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\r\n return new (P || (P = Promise))(function (resolve, reject) {\r\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\r\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\r\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\r\n step((generator = generator.apply(thisArg, _arguments || [])).next());\r\n });\r\n}\r\n\r\nexport function __generator(thisArg, body) {\r\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\r\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\r\n function verb(n) { return function (v) { return step([n, v]); }; }\r\n function step(op) {\r\n if (f) throw new TypeError(\"Generator is already executing.\");\r\n while (g && (g = 0, op[0] && (_ = 0)), _) try {\r\n if (f = 1, y && (t = op[0] & 2 ? y[\"return\"] : op[0] ? y[\"throw\"] || ((t = y[\"return\"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;\r\n if (y = 0, t) op = [op[0] & 2, t.value];\r\n switch (op[0]) {\r\n case 0: case 1: t = op; break;\r\n case 4: _.label++; return { value: op[1], done: false };\r\n case 5: _.label++; y = op[1]; op = [0]; continue;\r\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\r\n default:\r\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\r\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\r\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\r\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\r\n if (t[2]) _.ops.pop();\r\n _.trys.pop(); continue;\r\n }\r\n op = body.call(thisArg, _);\r\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\r\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\r\n }\r\n}\r\n\r\nexport var __createBinding = Object.create ? (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n var desc = Object.getOwnPropertyDescriptor(m, k);\r\n if (!desc || (\"get\" in desc ? !m.__esModule : desc.writable || desc.configurable)) {\r\n desc = { enumerable: true, get: function() { return m[k]; } };\r\n }\r\n Object.defineProperty(o, k2, desc);\r\n}) : (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n o[k2] = m[k];\r\n});\r\n\r\nexport function __exportStar(m, o) {\r\n for (var p in m) if (p !== \"default\" && !Object.prototype.hasOwnProperty.call(o, p)) __createBinding(o, m, p);\r\n}\r\n\r\nexport function __values(o) {\r\n var s = typeof Symbol === \"function\" && Symbol.iterator, m = s && o[s], i = 0;\r\n if (m) return m.call(o);\r\n if (o && typeof o.length === \"number\") return {\r\n next: function () {\r\n if (o && i >= o.length) o = void 0;\r\n return { value: o && o[i++], done: !o };\r\n }\r\n };\r\n throw new TypeError(s ? \"Object is not iterable.\" : \"Symbol.iterator is not defined.\");\r\n}\r\n\r\nexport function __read(o, n) {\r\n var m = typeof Symbol === \"function\" && o[Symbol.iterator];\r\n if (!m) return o;\r\n var i = m.call(o), r, ar = [], e;\r\n try {\r\n while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);\r\n }\r\n catch (error) { e = { error: error }; }\r\n finally {\r\n try {\r\n if (r && !r.done && (m = i[\"return\"])) m.call(i);\r\n }\r\n finally { if (e) throw e.error; }\r\n }\r\n return ar;\r\n}\r\n\r\n/** @deprecated */\r\nexport function __spread() {\r\n for (var ar = [], i = 0; i < arguments.length; i++)\r\n ar = ar.concat(__read(arguments[i]));\r\n return ar;\r\n}\r\n\r\n/** @deprecated */\r\nexport function __spreadArrays() {\r\n for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;\r\n for (var r = Array(s), k = 0, i = 0; i < il; i++)\r\n for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)\r\n r[k] = a[j];\r\n return r;\r\n}\r\n\r\nexport function __spreadArray(to, from, pack) {\r\n if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {\r\n if (ar || !(i in from)) {\r\n if (!ar) ar = Array.prototype.slice.call(from, 0, i);\r\n ar[i] = from[i];\r\n }\r\n }\r\n return to.concat(ar || Array.prototype.slice.call(from));\r\n}\r\n\r\nexport function __await(v) {\r\n return this instanceof __await ? (this.v = v, this) : new __await(v);\r\n}\r\n\r\nexport function __asyncGenerator(thisArg, _arguments, generator) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var g = generator.apply(thisArg, _arguments || []), i, q = [];\r\n return i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i;\r\n function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }\r\n function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }\r\n function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }\r\n function fulfill(value) { resume(\"next\", value); }\r\n function reject(value) { resume(\"throw\", value); }\r\n function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }\r\n}\r\n\r\nexport function __asyncDelegator(o) {\r\n var i, p;\r\n return i = {}, verb(\"next\"), verb(\"throw\", function (e) { throw e; }), verb(\"return\"), i[Symbol.iterator] = function () { return this; }, i;\r\n function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: false } : f ? f(v) : v; } : f; }\r\n}\r\n\r\nexport function __asyncValues(o) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var m = o[Symbol.asyncIterator], i;\r\n return m ? m.call(o) : (o = typeof __values === \"function\" ? __values(o) : o[Symbol.iterator](), i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i);\r\n function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }\r\n function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }\r\n}\r\n\r\nexport function __makeTemplateObject(cooked, raw) {\r\n if (Object.defineProperty) { Object.defineProperty(cooked, \"raw\", { value: raw }); } else { cooked.raw = raw; }\r\n return cooked;\r\n};\r\n\r\nvar __setModuleDefault = Object.create ? (function(o, v) {\r\n Object.defineProperty(o, \"default\", { enumerable: true, value: v });\r\n}) : function(o, v) {\r\n o[\"default\"] = v;\r\n};\r\n\r\nexport function __importStar(mod) {\r\n if (mod && mod.__esModule) return mod;\r\n var result = {};\r\n if (mod != null) for (var k in mod) if (k !== \"default\" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);\r\n __setModuleDefault(result, mod);\r\n return result;\r\n}\r\n\r\nexport function __importDefault(mod) {\r\n return (mod && mod.__esModule) ? mod : { default: mod };\r\n}\r\n\r\nexport function __classPrivateFieldGet(receiver, state, kind, f) {\r\n if (kind === \"a\" && !f) throw new TypeError(\"Private accessor was defined without a getter\");\r\n if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError(\"Cannot read private member from an object whose class did not declare it\");\r\n return kind === \"m\" ? f : kind === \"a\" ? f.call(receiver) : f ? f.value : state.get(receiver);\r\n}\r\n\r\nexport function __classPrivateFieldSet(receiver, state, value, kind, f) {\r\n if (kind === \"m\") throw new TypeError(\"Private method is not writable\");\r\n if (kind === \"a\" && !f) throw new TypeError(\"Private accessor was defined without a setter\");\r\n if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError(\"Cannot write private member to an object whose class did not declare it\");\r\n return (kind === \"a\" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;\r\n}\r\n\r\nexport function __classPrivateFieldIn(state, receiver) {\r\n if (receiver === null || (typeof receiver !== \"object\" && typeof receiver !== \"function\")) throw new TypeError(\"Cannot use 'in' operator on non-object\");\r\n return typeof state === \"function\" ? receiver === state : state.has(receiver);\r\n}\r\n\r\nexport function __addDisposableResource(env, value, async) {\r\n if (value !== null && value !== void 0) {\r\n if (typeof value !== \"object\" && typeof value !== \"function\") throw new TypeError(\"Object expected.\");\r\n var dispose;\r\n if (async) {\r\n if (!Symbol.asyncDispose) throw new TypeError(\"Symbol.asyncDispose is not defined.\");\r\n dispose = value[Symbol.asyncDispose];\r\n }\r\n if (dispose === void 0) {\r\n if (!Symbol.dispose) throw new TypeError(\"Symbol.dispose is not defined.\");\r\n dispose = value[Symbol.dispose];\r\n }\r\n if (typeof dispose !== \"function\") throw new TypeError(\"Object not disposable.\");\r\n env.stack.push({ value: value, dispose: dispose, async: async });\r\n }\r\n else if (async) {\r\n env.stack.push({ async: true });\r\n }\r\n return value;\r\n}\r\n\r\nvar _SuppressedError = typeof SuppressedError === \"function\" ? SuppressedError : function (error, suppressed, message) {\r\n var e = new Error(message);\r\n return e.name = \"SuppressedError\", e.error = error, e.suppressed = suppressed, e;\r\n};\r\n\r\nexport function __disposeResources(env) {\r\n function fail(e) {\r\n env.error = env.hasError ? new _SuppressedError(e, env.error, \"An error was suppressed during disposal.\") : e;\r\n env.hasError = true;\r\n }\r\n function next() {\r\n while (env.stack.length) {\r\n var rec = env.stack.pop();\r\n try {\r\n var result = rec.dispose && rec.dispose.call(rec.value);\r\n if (rec.async) return Promise.resolve(result).then(next, function(e) { fail(e); return next(); });\r\n }\r\n catch (e) {\r\n fail(e);\r\n }\r\n }\r\n if (env.hasError) throw env.error;\r\n }\r\n return next();\r\n}\r\n\r\nexport default {\r\n __extends: __extends,\r\n __assign: __assign,\r\n __rest: __rest,\r\n __decorate: __decorate,\r\n __param: __param,\r\n __metadata: __metadata,\r\n __awaiter: __awaiter,\r\n __generator: __generator,\r\n __createBinding: __createBinding,\r\n __exportStar: __exportStar,\r\n __values: __values,\r\n __read: __read,\r\n __spread: __spread,\r\n __spreadArrays: __spreadArrays,\r\n __spreadArray: __spreadArray,\r\n __await: __await,\r\n __asyncGenerator: __asyncGenerator,\r\n __asyncDelegator: __asyncDelegator,\r\n __asyncValues: __asyncValues,\r\n __makeTemplateObject: __makeTemplateObject,\r\n __importStar: __importStar,\r\n __importDefault: __importDefault,\r\n __classPrivateFieldGet: __classPrivateFieldGet,\r\n __classPrivateFieldSet: __classPrivateFieldSet,\r\n __classPrivateFieldIn: __classPrivateFieldIn,\r\n __addDisposableResource: __addDisposableResource,\r\n __disposeResources: __disposeResources,\r\n};\r\n","'use client'\n\nimport { useFrame } from '@studio-freight/hamo'\nimport Lenis, { LenisOptions } from '@studio-freight/lenis'\nimport cn from 'clsx'\nimport React, {\n ForwardRefExoticComponent,\n PropsWithoutRef,\n ReactNode,\n RefAttributes,\n createContext,\n forwardRef,\n useCallback,\n useContext,\n useEffect,\n useImperativeHandle,\n useRef,\n useState,\n} from 'react'\nimport { create } from 'zustand'\nimport { version } from '../package.json'\n\nif (typeof window !== 'undefined') window.reactLenisVersion = version\n\nexport const LenisContext = createContext() as Lenis | null\n\nconst useRoot = create(() => ({}))\n\nfunction useCurrentLenis() {\n const local = useContext(LenisContext)\n const root = useRoot()\n\n return local ?? root\n}\n\nexport function useLenis(\n callback?: (lenis: Lenis) => void,\n deps?: Array = [],\n priority = 0\n): Lenis | undefined {\n const { lenis, addCallback, removeCallback } = useCurrentLenis()\n\n useEffect(() => {\n if (!callback || !addCallback || !removeCallback || !lenis) return\n\n addCallback(callback, priority)\n callback(lenis)\n\n return () => {\n removeCallback(callback)\n }\n }, [lenis, addCallback, removeCallback, priority, ...deps])\n\n return lenis\n}\n\ntype ForwardRefComponent = ForwardRefExoticComponent<\n PropsWithoutRef

& RefAttributes\n>\n\ntype Props = {\n root?: boolean\n options?: LenisOptions\n autoRaf?: boolean\n rafPriority?: number\n className?: string\n children?: ReactNode\n props?: any\n}\n\ntype LenisRef = {\n wrapper?: HTMLElement\n content?: HTMLElement\n lenis?: Lenis\n}\n\nconst ReactLenis: ForwardRefComponent = forwardRef<\n LenisRef,\n Props\n>(\n (\n {\n children,\n root = false,\n options = {},\n autoRaf = true,\n rafPriority = 0,\n className,\n ...props\n }: Props,\n ref\n ) => {\n const wrapperRef = useRef()\n const contentRef = useRef()\n\n const [lenis, setLenis] = useState()\n\n const callbacksRefs = useRef([])\n\n const addCallback = useCallback((callback, priority) => {\n callbacksRefs.current.push({ callback, priority })\n callbacksRefs.current.sort((a, b) => a.priority - b.priority)\n }, [])\n\n const removeCallback = useCallback((callback) => {\n callbacksRefs.current = callbacksRefs.current.filter(\n (cb) => cb.callback !== callback\n )\n }, [])\n\n useImperativeHandle(\n ref,\n () => ({\n wrapper: wrapperRef.current,\n content: contentRef.current,\n lenis,\n }),\n [lenis]\n )\n\n useEffect(() => {\n const lenis = new Lenis({\n ...options,\n ...(!root && {\n wrapper: wrapperRef.current,\n content: contentRef.current,\n }),\n })\n\n setLenis(lenis)\n\n return () => {\n lenis.destroy()\n setLenis(undefined)\n }\n }, [root, JSON.stringify(options)])\n\n useFrame((time) => {\n if (autoRaf) {\n lenis?.raf(time)\n }\n }, rafPriority)\n\n useEffect(() => {\n if (root && lenis) {\n useRoot.setState({ lenis, addCallback, removeCallback })\n }\n }, [root, lenis, addCallback, removeCallback])\n\n const onScroll = useCallback((e) => {\n for (let i = 0; i < callbacksRefs.current.length; i++) {\n callbacksRefs.current[i].callback(e)\n }\n }, [])\n\n useEffect(() => {\n lenis?.on('scroll', onScroll)\n\n return () => {\n lenis?.off('scroll', onScroll)\n }\n }, [lenis, onScroll])\n\n const onClassNameChange = useCallback(() => {\n if (wrapperRef.current) {\n wrapperRef.current.className = cn(lenis?.className, className)\n }\n }, [lenis, className])\n\n useEffect(() => {\n onClassNameChange()\n\n lenis?.on('className change', onClassNameChange)\n\n return () => {\n lenis?.off('className change', onClassNameChange)\n }\n }, [lenis, onClassNameChange])\n\n return (\n \n {root ? (\n children\n ) : (\n \n

{children}
\n \n )}\n \n )\n }\n)\n\nexport { ReactLenis as Lenis, ReactLenis }\nexport default ReactLenis\n"],"names":["SuppressedError","window","reactLenisVersion","LenisContext","createContext","useRoot","create","useLenis","callback","deps","priority","lenis","addCallback","removeCallback","local","useContext","root","useCurrentLenis","useEffect","ReactLenis","forwardRef","_a","ref","children","options","autoRaf","rafPriority","className","props","s","e","t","p","Object","prototype","hasOwnProperty","call","indexOf","getOwnPropertySymbols","i","length","propertyIsEnumerable","__rest","wrapperRef","useRef","contentRef","setLenis","useState","callbacksRefs","useCallback","current","push","sort","a","b","filter","cb","useImperativeHandle","wrapper","content","Lenis","assign","destroy","undefined","JSON","stringify","useFrame","time","raf","setState","onScroll","on","off","onClassNameChange","cn","React","Provider","value","createElement"],"mappings":"sSA2TkD,mBAApBA,iBAAiCA,gBCrSzC,oBAAXC,SAAwBA,OAAOC,4BAE7BC,MAAAA,EAAeC,IAEtBC,EAAUC,GAAO,MAAS,KAS1B,SAAUC,EACdC,EACAC,EAAoB,GACpBC,EA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E,QAAOC,cAAaC,mBACjDG,EACCO,EAEAoD,EACEG,cAAA,MAAA7C,OAAA4B,OAAA,CAAAvC,IAAKqB,EACLhB,UAAW+C,EAAG/D,eAAAA,EAAOgB,UAAWA,IAC5BC,GAEJ+C,EAAKG,cAAA,MAAA,CAAAxD,IAAKuB,GAAatB,IAGL","x_google_ignoreList":[0]} \ No newline at end of file +{"version":3,"file":"react-lenis.mjs","sources":["../../../node_modules/tslib/tslib.es6.js","../../src/index.tsx"],"sourcesContent":["/******************************************************************************\r\nCopyright (c) Microsoft Corporation.\r\n\r\nPermission to use, copy, modify, and/or distribute this software for any\r\npurpose with or without fee is hereby granted.\r\n\r\nTHE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\r\nREGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\r\nAND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\r\nINDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\r\nLOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\r\nOTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\r\nPERFORMANCE OF THIS SOFTWARE.\r\n***************************************************************************** */\r\n/* global Reflect, Promise, SuppressedError, Symbol */\r\n\r\nvar extendStatics = function(d, b) {\r\n extendStatics = Object.setPrototypeOf ||\r\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\r\n function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };\r\n return extendStatics(d, b);\r\n};\r\n\r\nexport function __extends(d, b) {\r\n if (typeof b !== \"function\" && b !== null)\r\n throw new TypeError(\"Class extends value \" + String(b) + \" is not a constructor or null\");\r\n extendStatics(d, b);\r\n function __() { this.constructor = d; }\r\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\r\n}\r\n\r\nexport var __assign = function() {\r\n __assign = Object.assign || function __assign(t) {\r\n for (var s, i = 1, n = arguments.length; i < n; i++) {\r\n s = arguments[i];\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];\r\n }\r\n return t;\r\n }\r\n return __assign.apply(this, arguments);\r\n}\r\n\r\nexport function __rest(s, e) {\r\n var t = {};\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)\r\n t[p] = s[p];\r\n if (s != null && typeof Object.getOwnPropertySymbols === \"function\")\r\n for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {\r\n if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))\r\n t[p[i]] = s[p[i]];\r\n }\r\n return t;\r\n}\r\n\r\nexport function __decorate(decorators, target, key, desc) {\r\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\r\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\r\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\r\n return c > 3 && r && Object.defineProperty(target, key, r), r;\r\n}\r\n\r\nexport function __param(paramIndex, decorator) {\r\n return function (target, key) { decorator(target, key, paramIndex); }\r\n}\r\n\r\nexport function __esDecorate(ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {\r\n function accept(f) { if (f !== void 0 && typeof f !== \"function\") throw new TypeError(\"Function expected\"); return f; }\r\n var kind = contextIn.kind, key = kind === \"getter\" ? \"get\" : kind === \"setter\" ? \"set\" : \"value\";\r\n var target = !descriptorIn && ctor ? contextIn[\"static\"] ? ctor : ctor.prototype : null;\r\n var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});\r\n var _, done = false;\r\n for (var i = decorators.length - 1; i >= 0; i--) {\r\n var context = {};\r\n for (var p in contextIn) context[p] = p === \"access\" ? {} : contextIn[p];\r\n for (var p in contextIn.access) context.access[p] = contextIn.access[p];\r\n context.addInitializer = function (f) { if (done) throw new TypeError(\"Cannot add initializers after decoration has completed\"); extraInitializers.push(accept(f || null)); };\r\n var result = (0, decorators[i])(kind === \"accessor\" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);\r\n if (kind === \"accessor\") {\r\n if (result === void 0) continue;\r\n if (result === null || typeof result !== \"object\") throw new TypeError(\"Object expected\");\r\n if (_ = accept(result.get)) descriptor.get = _;\r\n if (_ = accept(result.set)) descriptor.set = _;\r\n if (_ = accept(result.init)) initializers.unshift(_);\r\n }\r\n else if (_ = accept(result)) {\r\n if (kind === \"field\") initializers.unshift(_);\r\n else descriptor[key] = _;\r\n }\r\n }\r\n if (target) Object.defineProperty(target, contextIn.name, descriptor);\r\n done = true;\r\n};\r\n\r\nexport function __runInitializers(thisArg, initializers, value) {\r\n var useValue = arguments.length > 2;\r\n for (var i = 0; i < initializers.length; i++) {\r\n value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);\r\n }\r\n return useValue ? value : void 0;\r\n};\r\n\r\nexport function __propKey(x) {\r\n return typeof x === \"symbol\" ? x : \"\".concat(x);\r\n};\r\n\r\nexport function __setFunctionName(f, name, prefix) {\r\n if (typeof name === \"symbol\") name = name.description ? \"[\".concat(name.description, \"]\") : \"\";\r\n return Object.defineProperty(f, \"name\", { configurable: true, value: prefix ? \"\".concat(prefix, \" \", name) : name });\r\n};\r\n\r\nexport function __metadata(metadataKey, metadataValue) {\r\n if (typeof Reflect === \"object\" && typeof Reflect.metadata === \"function\") return Reflect.metadata(metadataKey, metadataValue);\r\n}\r\n\r\nexport function __awaiter(thisArg, _arguments, P, generator) {\r\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\r\n return new (P || (P = Promise))(function (resolve, reject) {\r\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\r\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\r\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\r\n step((generator = generator.apply(thisArg, _arguments || [])).next());\r\n });\r\n}\r\n\r\nexport function __generator(thisArg, body) {\r\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\r\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\r\n function verb(n) { return function (v) { return step([n, v]); }; }\r\n function step(op) {\r\n if (f) throw new TypeError(\"Generator is already executing.\");\r\n while (g && (g = 0, op[0] && (_ = 0)), _) try {\r\n if (f = 1, y && (t = op[0] & 2 ? y[\"return\"] : op[0] ? y[\"throw\"] || ((t = y[\"return\"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;\r\n if (y = 0, t) op = [op[0] & 2, t.value];\r\n switch (op[0]) {\r\n case 0: case 1: t = op; break;\r\n case 4: _.label++; return { value: op[1], done: false };\r\n case 5: _.label++; y = op[1]; op = [0]; continue;\r\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\r\n default:\r\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\r\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\r\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\r\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\r\n if (t[2]) _.ops.pop();\r\n _.trys.pop(); continue;\r\n }\r\n op = body.call(thisArg, _);\r\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\r\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\r\n }\r\n}\r\n\r\nexport var __createBinding = Object.create ? (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n var desc = Object.getOwnPropertyDescriptor(m, k);\r\n if (!desc || (\"get\" in desc ? !m.__esModule : desc.writable || desc.configurable)) {\r\n desc = { enumerable: true, get: function() { return m[k]; } };\r\n }\r\n Object.defineProperty(o, k2, desc);\r\n}) : (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n o[k2] = m[k];\r\n});\r\n\r\nexport function __exportStar(m, o) {\r\n for (var p in m) if (p !== \"default\" && !Object.prototype.hasOwnProperty.call(o, p)) __createBinding(o, m, p);\r\n}\r\n\r\nexport function __values(o) {\r\n var s = typeof Symbol === \"function\" && Symbol.iterator, m = s && o[s], i = 0;\r\n if (m) return m.call(o);\r\n if (o && typeof o.length === \"number\") return {\r\n next: function () {\r\n if (o && i >= o.length) o = void 0;\r\n return { value: o && o[i++], done: !o };\r\n }\r\n };\r\n throw new TypeError(s ? \"Object is not iterable.\" : \"Symbol.iterator is not defined.\");\r\n}\r\n\r\nexport function __read(o, n) {\r\n var m = typeof Symbol === \"function\" && o[Symbol.iterator];\r\n if (!m) return o;\r\n var i = m.call(o), r, ar = [], e;\r\n try {\r\n while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);\r\n }\r\n catch (error) { e = { error: error }; }\r\n finally {\r\n try {\r\n if (r && !r.done && (m = i[\"return\"])) m.call(i);\r\n }\r\n finally { if (e) throw e.error; }\r\n }\r\n return ar;\r\n}\r\n\r\n/** @deprecated */\r\nexport function __spread() {\r\n for (var ar = [], i = 0; i < arguments.length; i++)\r\n ar = ar.concat(__read(arguments[i]));\r\n return ar;\r\n}\r\n\r\n/** @deprecated */\r\nexport function __spreadArrays() {\r\n for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;\r\n for (var r = Array(s), k = 0, i = 0; i < il; i++)\r\n for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)\r\n r[k] = a[j];\r\n return r;\r\n}\r\n\r\nexport function __spreadArray(to, from, pack) {\r\n if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {\r\n if (ar || !(i in from)) {\r\n if (!ar) ar = Array.prototype.slice.call(from, 0, i);\r\n ar[i] = from[i];\r\n }\r\n }\r\n return to.concat(ar || Array.prototype.slice.call(from));\r\n}\r\n\r\nexport function __await(v) {\r\n return this instanceof __await ? (this.v = v, this) : new __await(v);\r\n}\r\n\r\nexport function __asyncGenerator(thisArg, _arguments, generator) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var g = generator.apply(thisArg, _arguments || []), i, q = [];\r\n return i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i;\r\n function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }\r\n function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }\r\n function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }\r\n function fulfill(value) { resume(\"next\", value); }\r\n function reject(value) { resume(\"throw\", value); }\r\n function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }\r\n}\r\n\r\nexport function __asyncDelegator(o) {\r\n var i, p;\r\n return i = {}, verb(\"next\"), verb(\"throw\", function (e) { throw e; }), verb(\"return\"), i[Symbol.iterator] = function () { return this; }, i;\r\n function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: false } : f ? f(v) : v; } : f; }\r\n}\r\n\r\nexport function __asyncValues(o) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var m = o[Symbol.asyncIterator], i;\r\n return m ? m.call(o) : (o = typeof __values === \"function\" ? __values(o) : o[Symbol.iterator](), i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i);\r\n function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }\r\n function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }\r\n}\r\n\r\nexport function __makeTemplateObject(cooked, raw) {\r\n if (Object.defineProperty) { Object.defineProperty(cooked, \"raw\", { value: raw }); } else { cooked.raw = raw; }\r\n return cooked;\r\n};\r\n\r\nvar __setModuleDefault = Object.create ? (function(o, v) {\r\n Object.defineProperty(o, \"default\", { enumerable: true, value: v });\r\n}) : function(o, v) {\r\n o[\"default\"] = v;\r\n};\r\n\r\nexport function __importStar(mod) {\r\n if (mod && mod.__esModule) return mod;\r\n var result = {};\r\n if (mod != null) for (var k in mod) if (k !== \"default\" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);\r\n __setModuleDefault(result, mod);\r\n return result;\r\n}\r\n\r\nexport function __importDefault(mod) {\r\n return (mod && mod.__esModule) ? mod : { default: mod };\r\n}\r\n\r\nexport function __classPrivateFieldGet(receiver, state, kind, f) {\r\n if (kind === \"a\" && !f) throw new TypeError(\"Private accessor was defined without a getter\");\r\n if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError(\"Cannot read private member from an object whose class did not declare it\");\r\n return kind === \"m\" ? f : kind === \"a\" ? f.call(receiver) : f ? f.value : state.get(receiver);\r\n}\r\n\r\nexport function __classPrivateFieldSet(receiver, state, value, kind, f) {\r\n if (kind === \"m\") throw new TypeError(\"Private method is not writable\");\r\n if (kind === \"a\" && !f) throw new TypeError(\"Private accessor was defined without a setter\");\r\n if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError(\"Cannot write private member to an object whose class did not declare it\");\r\n return (kind === \"a\" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;\r\n}\r\n\r\nexport function __classPrivateFieldIn(state, receiver) {\r\n if (receiver === null || (typeof receiver !== \"object\" && typeof receiver !== \"function\")) throw new TypeError(\"Cannot use 'in' operator on non-object\");\r\n return typeof state === \"function\" ? receiver === state : state.has(receiver);\r\n}\r\n\r\nexport function __addDisposableResource(env, value, async) {\r\n if (value !== null && value !== void 0) {\r\n if (typeof value !== \"object\" && typeof value !== \"function\") throw new TypeError(\"Object expected.\");\r\n var dispose;\r\n if (async) {\r\n if (!Symbol.asyncDispose) throw new TypeError(\"Symbol.asyncDispose is not defined.\");\r\n dispose = value[Symbol.asyncDispose];\r\n }\r\n if (dispose === void 0) {\r\n if (!Symbol.dispose) throw new TypeError(\"Symbol.dispose is not defined.\");\r\n dispose = value[Symbol.dispose];\r\n }\r\n if (typeof dispose !== \"function\") throw new TypeError(\"Object not disposable.\");\r\n env.stack.push({ value: value, dispose: dispose, async: async });\r\n }\r\n else if (async) {\r\n env.stack.push({ async: true });\r\n }\r\n return value;\r\n}\r\n\r\nvar _SuppressedError = typeof SuppressedError === \"function\" ? SuppressedError : function (error, suppressed, message) {\r\n var e = new Error(message);\r\n return e.name = \"SuppressedError\", e.error = error, e.suppressed = suppressed, e;\r\n};\r\n\r\nexport function __disposeResources(env) {\r\n function fail(e) {\r\n env.error = env.hasError ? new _SuppressedError(e, env.error, \"An error was suppressed during disposal.\") : e;\r\n env.hasError = true;\r\n }\r\n function next() {\r\n while (env.stack.length) {\r\n var rec = env.stack.pop();\r\n try {\r\n var result = rec.dispose && rec.dispose.call(rec.value);\r\n if (rec.async) return Promise.resolve(result).then(next, function(e) { fail(e); return next(); });\r\n }\r\n catch (e) {\r\n fail(e);\r\n }\r\n }\r\n if (env.hasError) throw env.error;\r\n }\r\n return next();\r\n}\r\n\r\nexport default {\r\n __extends: __extends,\r\n __assign: __assign,\r\n __rest: __rest,\r\n __decorate: __decorate,\r\n __param: __param,\r\n __metadata: __metadata,\r\n __awaiter: __awaiter,\r\n __generator: __generator,\r\n __createBinding: __createBinding,\r\n __exportStar: __exportStar,\r\n __values: __values,\r\n __read: __read,\r\n __spread: __spread,\r\n __spreadArrays: __spreadArrays,\r\n __spreadArray: __spreadArray,\r\n __await: __await,\r\n __asyncGenerator: __asyncGenerator,\r\n __asyncDelegator: __asyncDelegator,\r\n __asyncValues: __asyncValues,\r\n __makeTemplateObject: __makeTemplateObject,\r\n __importStar: __importStar,\r\n __importDefault: __importDefault,\r\n __classPrivateFieldGet: __classPrivateFieldGet,\r\n __classPrivateFieldSet: __classPrivateFieldSet,\r\n __classPrivateFieldIn: __classPrivateFieldIn,\r\n __addDisposableResource: __addDisposableResource,\r\n __disposeResources: __disposeResources,\r\n};\r\n","'use client'\r\n\r\nimport { useFrame } from '@studio-freight/hamo'\r\nimport Lenis, { LenisOptions } from '@studio-freight/lenis'\r\nimport cn from 'clsx'\r\nimport React, {\r\n ForwardRefExoticComponent,\r\n PropsWithoutRef,\r\n ReactNode,\r\n RefAttributes,\r\n createContext,\r\n forwardRef,\r\n useCallback,\r\n useContext,\r\n useEffect,\r\n useImperativeHandle,\r\n useRef,\r\n useState,\r\n} from 'react'\r\nimport { create } from 'zustand'\r\nimport { version } from '../package.json'\r\n\r\ntype LenisEventHandler = (lenis: Lenis) => void\r\ninterface LenisContextValue {\r\n lenis: Lenis\r\n addCallback: (handler: LenisEventHandler, priority: number) => void\r\n removeCallback: (handler: LenisEventHandler) => void\r\n}\r\n\r\ndeclare global {\r\n interface Window {\r\n reactLenisVersion: string\r\n }\r\n}\r\nif (typeof window !== 'undefined') {\r\n window.reactLenisVersion = version\r\n}\r\n\r\nexport const LenisContext = createContext(null)\r\n\r\nconst useRoot = create>(() => ({}))\r\n\r\nfunction useCurrentLenis() {\r\n const local = useContext(LenisContext)\r\n const root = useRoot()\r\n\r\n return local ?? root\r\n}\r\n\r\nexport function useLenis(\r\n callback?: (lenis: Lenis) => void,\r\n deps: Array = [],\r\n priority = 0\r\n): Lenis | undefined {\r\n const { lenis, addCallback, removeCallback } = useCurrentLenis()\r\n\r\n useEffect(() => {\r\n if (!callback || !addCallback || !removeCallback || !lenis) return\r\n\r\n addCallback(callback, priority)\r\n callback(lenis)\r\n\r\n return () => {\r\n removeCallback(callback)\r\n }\r\n }, [lenis, addCallback, removeCallback, priority, ...deps])\r\n\r\n return lenis\r\n}\r\n\r\ntype ForwardRefComponent = ForwardRefExoticComponent<\r\n PropsWithoutRef

& RefAttributes\r\n>\r\n\r\ntype Props = {\r\n root?: boolean\r\n options?: LenisOptions\r\n autoRaf?: boolean\r\n rafPriority?: number\r\n className?: string\r\n children?: ReactNode\r\n props?: any\r\n}\r\n\r\ntype LenisRef = {\r\n wrapper?: HTMLElement\r\n content?: HTMLElement\r\n lenis?: Lenis\r\n}\r\n\r\nconst ReactLenis: ForwardRefComponent = forwardRef<\r\n LenisRef,\r\n Props\r\n>(\r\n (\r\n {\r\n children,\r\n root = false,\r\n options = {},\r\n autoRaf = true,\r\n rafPriority = 0,\r\n className,\r\n ...props\r\n }: Props,\r\n ref\r\n ) => {\r\n const wrapperRef = useRef(null)\r\n const contentRef = useRef(null)\r\n\r\n const [lenis, setLenis] = useState(undefined)\r\n\r\n const callbacksRefs = useRef<\r\n {\r\n callback: LenisEventHandler\r\n priority: number\r\n }[]\r\n >([])\r\n\r\n const addCallback: LenisContextValue['addCallback'] = useCallback(\r\n (callback, priority) => {\r\n callbacksRefs.current.push({ callback, priority })\r\n callbacksRefs.current.sort((a, b) => a.priority - b.priority)\r\n },\r\n []\r\n )\r\n\r\n const removeCallback: LenisContextValue['removeCallback'] = useCallback(\r\n (callback) => {\r\n callbacksRefs.current = callbacksRefs.current.filter(\r\n (cb) => cb.callback !== callback\r\n )\r\n },\r\n []\r\n )\r\n\r\n useImperativeHandle(\r\n ref,\r\n () => ({\r\n wrapper: wrapperRef.current!,\r\n content: contentRef.current!,\r\n lenis,\r\n }),\r\n [lenis]\r\n )\r\n\r\n useEffect(() => {\r\n const lenis = new Lenis({\r\n ...options,\r\n ...(!root && {\r\n wrapper: wrapperRef.current!,\r\n content: contentRef.current!,\r\n }),\r\n })\r\n\r\n setLenis(lenis)\r\n\r\n return () => {\r\n lenis.destroy()\r\n setLenis(undefined)\r\n }\r\n }, [root, JSON.stringify(options)])\r\n\r\n useFrame((time: number) => {\r\n if (autoRaf) {\r\n lenis?.raf(time)\r\n }\r\n }, rafPriority)\r\n\r\n useEffect(() => {\r\n if (root && lenis) {\r\n useRoot.setState({ lenis, addCallback, removeCallback })\r\n }\r\n }, [root, lenis, addCallback, removeCallback])\r\n\r\n const onScroll = useCallback((lenisInstance: Lenis) => {\r\n for (let i = 0; i < callbacksRefs.current.length; i++) {\r\n callbacksRefs.current[i].callback(lenisInstance)\r\n }\r\n }, [])\r\n\r\n useEffect(() => {\r\n lenis?.on('scroll', onScroll)\r\n\r\n return () => {\r\n lenis?.off('scroll', onScroll)\r\n }\r\n }, [lenis, onScroll])\r\n\r\n const onClassNameChange = useCallback(() => {\r\n if (wrapperRef.current) {\r\n wrapperRef.current.className = cn(lenis?.className, className)\r\n }\r\n }, [lenis, className])\r\n\r\n useEffect(() => {\r\n onClassNameChange()\r\n\r\n lenis?.on('className change', onClassNameChange)\r\n\r\n return () => {\r\n lenis?.off('className change', onClassNameChange)\r\n }\r\n }, [lenis, onClassNameChange])\r\n\r\n return (\r\n \r\n {root ? (\r\n children\r\n ) : (\r\n \r\n

{children}
\r\n \r\n )}\r\n \r\n )\r\n }\r\n)\r\n\r\nexport { ReactLenis as Lenis, ReactLenis }\r\nexport default ReactLenis\r\n"],"names":["SuppressedError","window","reactLenisVersion","LenisContext","createContext","useRoot","create","useLenis","callback","deps","priority","lenis","addCallback","removeCallback","local","useContext","root","useCurrentLenis","useEffect","ReactLenis","forwardRef","_a","ref","children","options","autoRaf","rafPriority","className","props","s","e","t","p","Object","prototype","hasOwnProperty","call","indexOf","getOwnPropertySymbols","i","length","propertyIsEnumerable","__rest","wrapperRef","useRef","contentRef","setLenis","useState","undefined","callbacksRefs","useCallback","current","push","sort","a","b","filter","cb","useImperativeHandle","wrapper","content","Lenis","assign","destroy","JSON","stringify","useFrame","time","raf","setState","onScroll","lenisInstance","on","off","onClassNameChange","cn","React","Provider","value","createElement"],"mappings":"sSA2TkD,mBAApBA,iBAAiCA,gBCzRzC,oBAAXC,SACTA,OAAOC,kCAGIC,EAAeC,EAAwC,MAE9DC,EAAUC,GAAmC,MAAS,KAStD,SAAUC,EACdC,EACAC,EAAmB,GACnBC,EAAW,GAEX,MAAMC,MAAEA,EAAKC,YAAEA,EAAWC,eAAEA,GAZ9B,WACE,MAAMC,EAAQC,EAAWZ,GACnBa,EAAOX,IAEb,OAAOS,QAAAA,EAASE,CAClB,CAOiDC,GAa/C,OAXAC,GAAU,KACR,GAAKV,GAAaI,GAAgBC,GAAmBF,EAKrD,OAHAC,EAAYJ,EAAUE,GACtBF,EAASG,GAEF,KACLE,EAAeL,EAAS,CACzB,GACA,CAACG,EAAOC,EAAaC,EAAgBH,KAAaD,IAE9CE,CACT,CAsBMQ,MAAAA,EAAmDC,GAIvD,CACEC,EASAC,SATAC,SACEA,EAAQP,KACRA,GAAO,EAAKQ,QACZA,EAAU,CAAE,EAAAC,QACZA,GAAU,EAAIC,YACdA,EAAc,EAACC,UACfA,KACGC,ED5DF,SAAgBC,EAAGC,GACtB,IAAIC,EAAI,CAAA,EACR,IAAK,IAAIC,KAAKH,EAAOI,OAAOC,UAAUC,eAAeC,KAAKP,EAAGG,IAAMF,EAAEO,QAAQL,GAAK,IAC9ED,EAAEC,GAAKH,EAAEG,IACb,GAAS,MAALH,GAAqD,mBAAjCI,OAAOK,sBACtB,KAAIC,EAAI,EAAb,IAAgBP,EAAIC,OAAOK,sBAAsBT,GAAIU,EAAIP,EAAEQ,OAAQD,IAC3DT,EAAEO,QAAQL,EAAEO,IAAM,GAAKN,OAAOC,UAAUO,qBAAqBL,KAAKP,EAAGG,EAAEO,MACvER,EAAEC,EAAEO,IAAMV,EAAEG,EAAEO,IAF4B,CAItD,OAAOR,CACX,CC2CIW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I,EAAoBxB,GAAY,KAChCP,EAAWQ,UACbR,EAAWQ,QAAQxB,UAAYgD,EAAGhE,eAAAA,EAAOgB,UAAWA,GACtD,GACC,CAAChB,EAAOgB,IAYX,OAVAT,GAAU,KACRwD,IAEA/D,SAAAA,EAAO6D,GAAG,mBAAoBE,GAEvB,KACL/D,SAAAA,EAAO8D,IAAI,mBAAoBC,EAAkB,IAElD,CAAC/D,EAAO+D,IAGTE,gBAACzE,EAAa0E,SACZ,CAAAC,MAAO,CAAEnE,MAAOA,EAAQC,cAAaC,mBAEpCG,EACCO,EAEAqD,EAAAG,cAAA,MAAA9C,OAAA6B,OAAA,CACExC,IAAKqB,EACLhB,UAAWgD,EAAGhE,aAAK,EAALA,EAAOgB,UAAWA,IAC5BC,GAEJgD,EAAKG,cAAA,MAAA,CAAAzD,IAAKuB,GAAatB,IAGL","x_google_ignoreList":[0]} \ No newline at end of file diff --git a/packages/react-lenis/dist/react-lenis.umd.js b/packages/react-lenis/dist/react-lenis.umd.js index 5320fcaa..878595ce 100644 --- a/packages/react-lenis/dist/react-lenis.umd.js +++ b/packages/react-lenis/dist/react-lenis.umd.js @@ -1,2 +1,2 @@ -!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@studio-freight/hamo"),require("@studio-freight/lenis"),require("clsx"),require("react"),require("zustand")):"function"==typeof define&&define.amd?define(["exports","@studio-freight/hamo","@studio-freight/lenis","clsx","react","zustand"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).ReactLenis={},e.hamo,e.Lenis,e.cn,e.React,e.zustand)}(this,(function(e,t,r,n,s,a){"use strict";"function"==typeof SuppressedError&&SuppressedError;"undefined"!=typeof window&&(window.reactLenisVersion="0.0.46");const o=s.createContext(),c=a.create((()=>({})));const l=s.forwardRef(((e,a)=>{var{children:l,root:i=!1,options:u={},autoRaf:f=!0,rafPriority:d=0,className:p}=e,b=function(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var s=0;for(n=Object.getOwnPropertySymbols(e);s{v.current.push({callback:e,priority:t}),v.current.sort(((e,t)=>e.priority-t.priority))}),[]),k=s.useCallback((e=>{v.current=v.current.filter((t=>t.callback!==e))}),[]);s.useImperativeHandle(a,(()=>({wrapper:m.current,content:y.current,lenis:h})),[h]),s.useEffect((()=>{const e=new r(Object.assign(Object.assign({},u),!i&&{wrapper:m.current,content:y.current}));return g(e),()=>{e.destroy(),g(void 0)}}),[i,JSON.stringify(u)]),t.useFrame((e=>{f&&(null==h||h.raf(e))}),d),s.useEffect((()=>{i&&h&&c.setState({lenis:h,addCallback:O,removeCallback:k})}),[i,h,O,k]);const C=s.useCallback((e=>{for(let t=0;t(null==h||h.on("scroll",C),()=>{null==h||h.off("scroll",C)})),[h,C]);const w=s.useCallback((()=>{m.current&&(m.current.className=n(null==h?void 0:h.className,p))}),[h,p]);return s.useEffect((()=>(w(),null==h||h.on("className change",w),()=>{null==h||h.off("className change",w)})),[h,w]),s.createElement(o.Provider,{value:{lenis:h,addCallback:O,removeCallback:k}},i?l:s.createElement("div",Object.assign({ref:m,className:n(null==h?void 0:h.className,p)},b),s.createElement("div",{ref:y},l)))}));e.Lenis=l,e.LenisContext=o,e.ReactLenis=l,e.default=l,e.useLenis=function(e,t=[],r=0){const{lenis:n,addCallback:a,removeCallback:l}=function(){const e=s.useContext(o),t=c();return null!=e?e:t}();return s.useEffect((()=>{if(e&&a&&l&&n)return a(e,r),e(n),()=>{l(e)}}),[n,a,l,r,...t]),n},Object.defineProperty(e,"__esModule",{value:!0})})); +!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@studio-freight/hamo"),require("@studio-freight/lenis"),require("clsx"),require("react"),require("zustand")):"function"==typeof define&&define.amd?define(["exports","@studio-freight/hamo","@studio-freight/lenis","clsx","react","zustand"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).ReactLenis={},e.hamo,e.Lenis,e.cn,e.React,e.zustand)}(this,(function(e,t,r,n,l,s){"use strict";"function"==typeof SuppressedError&&SuppressedError;"undefined"!=typeof window&&(window.reactLenisVersion="0.0.46");const a=l.createContext(null),o=s.create((()=>({})));const c=l.forwardRef(((e,s)=>{var{children:c,root:u=!1,options:i={},autoRaf:f=!0,rafPriority:d=0,className:p}=e,b=function(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var l=0;for(n=Object.getOwnPropertySymbols(e);l{g.current.push({callback:e,priority:t}),g.current.sort(((e,t)=>e.priority-t.priority))}),[]),k=l.useCallback((e=>{g.current=g.current.filter((t=>t.callback!==e))}),[]);l.useImperativeHandle(s,(()=>({wrapper:m.current,content:y.current,lenis:h})),[h]),l.useEffect((()=>{const e=new r(Object.assign(Object.assign({},i),!u&&{wrapper:m.current,content:y.current}));return v(e),()=>{e.destroy(),v(void 0)}}),[u,JSON.stringify(i)]),t.useFrame((e=>{f&&(null==h||h.raf(e))}),d),l.useEffect((()=>{u&&h&&o.setState({lenis:h,addCallback:O,removeCallback:k})}),[u,h,O,k]);const C=l.useCallback((e=>{for(let t=0;t(null==h||h.on("scroll",C),()=>{null==h||h.off("scroll",C)})),[h,C]);const w=l.useCallback((()=>{m.current&&(m.current.className=n(null==h?void 0:h.className,p))}),[h,p]);return l.useEffect((()=>(w(),null==h||h.on("className change",w),()=>{null==h||h.off("className change",w)})),[h,w]),l.createElement(a.Provider,{value:{lenis:h,addCallback:O,removeCallback:k}},u?c:l.createElement("div",Object.assign({ref:m,className:n(null==h?void 0:h.className,p)},b),l.createElement("div",{ref:y},c)))}));e.Lenis=c,e.LenisContext=a,e.ReactLenis=c,e.default=c,e.useLenis=function(e,t=[],r=0){const{lenis:n,addCallback:s,removeCallback:c}=function(){const e=l.useContext(a),t=o();return null!=e?e:t}();return l.useEffect((()=>{if(e&&s&&c&&n)return s(e,r),e(n),()=>{c(e)}}),[n,s,c,r,...t]),n},Object.defineProperty(e,"__esModule",{value:!0})})); //# sourceMappingURL=react-lenis.umd.js.map diff --git a/packages/react-lenis/dist/react-lenis.umd.js.map b/packages/react-lenis/dist/react-lenis.umd.js.map index 20f7c0e0..6b694aab 100644 --- a/packages/react-lenis/dist/react-lenis.umd.js.map +++ b/packages/react-lenis/dist/react-lenis.umd.js.map @@ -1 +1 @@ -{"version":3,"file":"react-lenis.umd.js","sources":["../../../node_modules/tslib/tslib.es6.js","../../src/index.tsx"],"sourcesContent":["/******************************************************************************\r\nCopyright (c) Microsoft Corporation.\r\n\r\nPermission to use, copy, modify, and/or distribute this software for any\r\npurpose with or without fee is hereby granted.\r\n\r\nTHE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\r\nREGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\r\nAND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\r\nINDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\r\nLOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\r\nOTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\r\nPERFORMANCE OF THIS SOFTWARE.\r\n***************************************************************************** */\r\n/* global Reflect, Promise, SuppressedError, Symbol */\r\n\r\nvar extendStatics = function(d, b) {\r\n extendStatics = Object.setPrototypeOf ||\r\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\r\n function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };\r\n return extendStatics(d, b);\r\n};\r\n\r\nexport function __extends(d, b) {\r\n if (typeof b !== \"function\" && b !== null)\r\n throw new TypeError(\"Class extends value \" + String(b) + \" is not a constructor or null\");\r\n extendStatics(d, b);\r\n function __() { this.constructor = d; }\r\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\r\n}\r\n\r\nexport var __assign = function() {\r\n __assign = Object.assign || function __assign(t) {\r\n for (var s, i = 1, n = arguments.length; i < n; i++) {\r\n s = arguments[i];\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];\r\n }\r\n return t;\r\n }\r\n return __assign.apply(this, arguments);\r\n}\r\n\r\nexport function __rest(s, e) {\r\n var t = {};\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)\r\n t[p] = s[p];\r\n if (s != null && typeof Object.getOwnPropertySymbols === \"function\")\r\n for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {\r\n if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))\r\n t[p[i]] = s[p[i]];\r\n }\r\n return t;\r\n}\r\n\r\nexport function __decorate(decorators, target, key, desc) {\r\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\r\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\r\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\r\n return c > 3 && r && Object.defineProperty(target, key, r), r;\r\n}\r\n\r\nexport function __param(paramIndex, decorator) {\r\n return function (target, key) { decorator(target, key, paramIndex); }\r\n}\r\n\r\nexport function __esDecorate(ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {\r\n function accept(f) { if (f !== void 0 && typeof f !== \"function\") throw new TypeError(\"Function expected\"); return f; }\r\n var kind = contextIn.kind, key = kind === \"getter\" ? \"get\" : kind === \"setter\" ? \"set\" : \"value\";\r\n var target = !descriptorIn && ctor ? contextIn[\"static\"] ? ctor : ctor.prototype : null;\r\n var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});\r\n var _, done = false;\r\n for (var i = decorators.length - 1; i >= 0; i--) {\r\n var context = {};\r\n for (var p in contextIn) context[p] = p === \"access\" ? {} : contextIn[p];\r\n for (var p in contextIn.access) context.access[p] = contextIn.access[p];\r\n context.addInitializer = function (f) { if (done) throw new TypeError(\"Cannot add initializers after decoration has completed\"); extraInitializers.push(accept(f || null)); };\r\n var result = (0, decorators[i])(kind === \"accessor\" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);\r\n if (kind === \"accessor\") {\r\n if (result === void 0) continue;\r\n if (result === null || typeof result !== \"object\") throw new TypeError(\"Object expected\");\r\n if (_ = accept(result.get)) descriptor.get = _;\r\n if (_ = accept(result.set)) descriptor.set = _;\r\n if (_ = accept(result.init)) initializers.unshift(_);\r\n }\r\n else if (_ = accept(result)) {\r\n if (kind === \"field\") initializers.unshift(_);\r\n else descriptor[key] = _;\r\n }\r\n }\r\n if (target) Object.defineProperty(target, contextIn.name, descriptor);\r\n done = true;\r\n};\r\n\r\nexport function __runInitializers(thisArg, initializers, value) {\r\n var useValue = arguments.length > 2;\r\n for (var i = 0; i < initializers.length; i++) {\r\n value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);\r\n }\r\n return useValue ? value : void 0;\r\n};\r\n\r\nexport function __propKey(x) {\r\n return typeof x === \"symbol\" ? x : \"\".concat(x);\r\n};\r\n\r\nexport function __setFunctionName(f, name, prefix) {\r\n if (typeof name === \"symbol\") name = name.description ? \"[\".concat(name.description, \"]\") : \"\";\r\n return Object.defineProperty(f, \"name\", { configurable: true, value: prefix ? \"\".concat(prefix, \" \", name) : name });\r\n};\r\n\r\nexport function __metadata(metadataKey, metadataValue) {\r\n if (typeof Reflect === \"object\" && typeof Reflect.metadata === \"function\") return Reflect.metadata(metadataKey, metadataValue);\r\n}\r\n\r\nexport function __awaiter(thisArg, _arguments, P, generator) {\r\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\r\n return new (P || (P = Promise))(function (resolve, reject) {\r\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\r\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\r\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\r\n step((generator = generator.apply(thisArg, _arguments || [])).next());\r\n });\r\n}\r\n\r\nexport function __generator(thisArg, body) {\r\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\r\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\r\n function verb(n) { return function (v) { return step([n, v]); }; }\r\n function step(op) {\r\n if (f) throw new TypeError(\"Generator is already executing.\");\r\n while (g && (g = 0, op[0] && (_ = 0)), _) try {\r\n if (f = 1, y && (t = op[0] & 2 ? y[\"return\"] : op[0] ? y[\"throw\"] || ((t = y[\"return\"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;\r\n if (y = 0, t) op = [op[0] & 2, t.value];\r\n switch (op[0]) {\r\n case 0: case 1: t = op; break;\r\n case 4: _.label++; return { value: op[1], done: false };\r\n case 5: _.label++; y = op[1]; op = [0]; continue;\r\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\r\n default:\r\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\r\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\r\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\r\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\r\n if (t[2]) _.ops.pop();\r\n _.trys.pop(); continue;\r\n }\r\n op = body.call(thisArg, _);\r\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\r\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\r\n }\r\n}\r\n\r\nexport var __createBinding = Object.create ? (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n var desc = Object.getOwnPropertyDescriptor(m, k);\r\n if (!desc || (\"get\" in desc ? !m.__esModule : desc.writable || desc.configurable)) {\r\n desc = { enumerable: true, get: function() { return m[k]; } };\r\n }\r\n Object.defineProperty(o, k2, desc);\r\n}) : (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n o[k2] = m[k];\r\n});\r\n\r\nexport function __exportStar(m, o) {\r\n for (var p in m) if (p !== \"default\" && !Object.prototype.hasOwnProperty.call(o, p)) __createBinding(o, m, p);\r\n}\r\n\r\nexport function __values(o) {\r\n var s = typeof Symbol === \"function\" && Symbol.iterator, m = s && o[s], i = 0;\r\n if (m) return m.call(o);\r\n if (o && typeof o.length === \"number\") return {\r\n next: function () {\r\n if (o && i >= o.length) o = void 0;\r\n return { value: o && o[i++], done: !o };\r\n }\r\n };\r\n throw new TypeError(s ? \"Object is not iterable.\" : \"Symbol.iterator is not defined.\");\r\n}\r\n\r\nexport function __read(o, n) {\r\n var m = typeof Symbol === \"function\" && o[Symbol.iterator];\r\n if (!m) return o;\r\n var i = m.call(o), r, ar = [], e;\r\n try {\r\n while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);\r\n }\r\n catch (error) { e = { error: error }; }\r\n finally {\r\n try {\r\n if (r && !r.done && (m = i[\"return\"])) m.call(i);\r\n }\r\n finally { if (e) throw e.error; }\r\n }\r\n return ar;\r\n}\r\n\r\n/** @deprecated */\r\nexport function __spread() {\r\n for (var ar = [], i = 0; i < arguments.length; i++)\r\n ar = ar.concat(__read(arguments[i]));\r\n return ar;\r\n}\r\n\r\n/** @deprecated */\r\nexport function __spreadArrays() {\r\n for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;\r\n for (var r = Array(s), k = 0, i = 0; i < il; i++)\r\n for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)\r\n r[k] = a[j];\r\n return r;\r\n}\r\n\r\nexport function __spreadArray(to, from, pack) {\r\n if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {\r\n if (ar || !(i in from)) {\r\n if (!ar) ar = Array.prototype.slice.call(from, 0, i);\r\n ar[i] = from[i];\r\n }\r\n }\r\n return to.concat(ar || Array.prototype.slice.call(from));\r\n}\r\n\r\nexport function __await(v) {\r\n return this instanceof __await ? (this.v = v, this) : new __await(v);\r\n}\r\n\r\nexport function __asyncGenerator(thisArg, _arguments, generator) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var g = generator.apply(thisArg, _arguments || []), i, q = [];\r\n return i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i;\r\n function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }\r\n function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }\r\n function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }\r\n function fulfill(value) { resume(\"next\", value); }\r\n function reject(value) { resume(\"throw\", value); }\r\n function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }\r\n}\r\n\r\nexport function __asyncDelegator(o) {\r\n var i, p;\r\n return i = {}, verb(\"next\"), verb(\"throw\", function (e) { throw e; }), verb(\"return\"), i[Symbol.iterator] = function () { return this; }, i;\r\n function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: false } : f ? f(v) : v; } : f; }\r\n}\r\n\r\nexport function __asyncValues(o) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var m = o[Symbol.asyncIterator], i;\r\n return m ? m.call(o) : (o = typeof __values === \"function\" ? __values(o) : o[Symbol.iterator](), i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i);\r\n function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }\r\n function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }\r\n}\r\n\r\nexport function __makeTemplateObject(cooked, raw) {\r\n if (Object.defineProperty) { Object.defineProperty(cooked, \"raw\", { value: raw }); } else { cooked.raw = raw; }\r\n return cooked;\r\n};\r\n\r\nvar __setModuleDefault = Object.create ? (function(o, v) {\r\n Object.defineProperty(o, \"default\", { enumerable: true, value: v });\r\n}) : function(o, v) {\r\n o[\"default\"] = v;\r\n};\r\n\r\nexport function __importStar(mod) {\r\n if (mod && mod.__esModule) return mod;\r\n var result = {};\r\n if (mod != null) for (var k in mod) if (k !== \"default\" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);\r\n __setModuleDefault(result, mod);\r\n return result;\r\n}\r\n\r\nexport function __importDefault(mod) {\r\n return (mod && mod.__esModule) ? mod : { default: mod };\r\n}\r\n\r\nexport function __classPrivateFieldGet(receiver, state, kind, f) {\r\n if (kind === \"a\" && !f) throw new TypeError(\"Private accessor was defined without a getter\");\r\n if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError(\"Cannot read private member from an object whose class did not declare it\");\r\n return kind === \"m\" ? f : kind === \"a\" ? f.call(receiver) : f ? f.value : state.get(receiver);\r\n}\r\n\r\nexport function __classPrivateFieldSet(receiver, state, value, kind, f) {\r\n if (kind === \"m\") throw new TypeError(\"Private method is not writable\");\r\n if (kind === \"a\" && !f) throw new TypeError(\"Private accessor was defined without a setter\");\r\n if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError(\"Cannot write private member to an object whose class did not declare it\");\r\n return (kind === \"a\" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;\r\n}\r\n\r\nexport function __classPrivateFieldIn(state, receiver) {\r\n if (receiver === null || (typeof receiver !== \"object\" && typeof receiver !== \"function\")) throw new TypeError(\"Cannot use 'in' operator on non-object\");\r\n return typeof state === \"function\" ? receiver === state : state.has(receiver);\r\n}\r\n\r\nexport function __addDisposableResource(env, value, async) {\r\n if (value !== null && value !== void 0) {\r\n if (typeof value !== \"object\" && typeof value !== \"function\") throw new TypeError(\"Object expected.\");\r\n var dispose;\r\n if (async) {\r\n if (!Symbol.asyncDispose) throw new TypeError(\"Symbol.asyncDispose is not defined.\");\r\n dispose = value[Symbol.asyncDispose];\r\n }\r\n if (dispose === void 0) {\r\n if (!Symbol.dispose) throw new TypeError(\"Symbol.dispose is not defined.\");\r\n dispose = value[Symbol.dispose];\r\n }\r\n if (typeof dispose !== \"function\") throw new TypeError(\"Object not disposable.\");\r\n env.stack.push({ value: value, dispose: dispose, async: async });\r\n }\r\n else if (async) {\r\n env.stack.push({ async: true });\r\n }\r\n return value;\r\n}\r\n\r\nvar _SuppressedError = typeof SuppressedError === \"function\" ? SuppressedError : function (error, suppressed, message) {\r\n var e = new Error(message);\r\n return e.name = \"SuppressedError\", e.error = error, e.suppressed = suppressed, e;\r\n};\r\n\r\nexport function __disposeResources(env) {\r\n function fail(e) {\r\n env.error = env.hasError ? new _SuppressedError(e, env.error, \"An error was suppressed during disposal.\") : e;\r\n env.hasError = true;\r\n }\r\n function next() {\r\n while (env.stack.length) {\r\n var rec = env.stack.pop();\r\n try {\r\n var result = rec.dispose && rec.dispose.call(rec.value);\r\n if (rec.async) return Promise.resolve(result).then(next, function(e) { fail(e); return next(); });\r\n }\r\n catch (e) {\r\n fail(e);\r\n }\r\n }\r\n if (env.hasError) throw env.error;\r\n }\r\n return next();\r\n}\r\n\r\nexport default {\r\n __extends: __extends,\r\n __assign: __assign,\r\n __rest: __rest,\r\n __decorate: __decorate,\r\n __param: __param,\r\n __metadata: __metadata,\r\n __awaiter: __awaiter,\r\n __generator: __generator,\r\n __createBinding: __createBinding,\r\n __exportStar: __exportStar,\r\n __values: __values,\r\n __read: __read,\r\n __spread: __spread,\r\n __spreadArrays: __spreadArrays,\r\n __spreadArray: __spreadArray,\r\n __await: __await,\r\n __asyncGenerator: __asyncGenerator,\r\n __asyncDelegator: __asyncDelegator,\r\n __asyncValues: __asyncValues,\r\n __makeTemplateObject: __makeTemplateObject,\r\n __importStar: __importStar,\r\n __importDefault: __importDefault,\r\n __classPrivateFieldGet: __classPrivateFieldGet,\r\n __classPrivateFieldSet: __classPrivateFieldSet,\r\n __classPrivateFieldIn: __classPrivateFieldIn,\r\n __addDisposableResource: __addDisposableResource,\r\n __disposeResources: __disposeResources,\r\n};\r\n","'use client'\n\nimport { useFrame } from '@studio-freight/hamo'\nimport Lenis, { LenisOptions } from '@studio-freight/lenis'\nimport cn from 'clsx'\nimport React, {\n ForwardRefExoticComponent,\n PropsWithoutRef,\n ReactNode,\n RefAttributes,\n createContext,\n forwardRef,\n useCallback,\n useContext,\n useEffect,\n useImperativeHandle,\n useRef,\n useState,\n} from 'react'\nimport { create } from 'zustand'\nimport { version } from '../package.json'\n\nif (typeof window !== 'undefined') window.reactLenisVersion = version\n\nexport const LenisContext = createContext() as Lenis | null\n\nconst useRoot = create(() => ({}))\n\nfunction useCurrentLenis() {\n const local = useContext(LenisContext)\n const root = useRoot()\n\n return local ?? root\n}\n\nexport function useLenis(\n callback?: (lenis: Lenis) => void,\n deps?: Array = [],\n priority = 0\n): Lenis | undefined {\n const { lenis, addCallback, removeCallback } = useCurrentLenis()\n\n useEffect(() => {\n if (!callback || !addCallback || !removeCallback || !lenis) return\n\n addCallback(callback, priority)\n callback(lenis)\n\n return () => {\n removeCallback(callback)\n }\n }, [lenis, addCallback, removeCallback, priority, ...deps])\n\n return lenis\n}\n\ntype ForwardRefComponent = ForwardRefExoticComponent<\n PropsWithoutRef

& RefAttributes\n>\n\ntype Props = {\n root?: boolean\n options?: LenisOptions\n autoRaf?: boolean\n rafPriority?: number\n className?: string\n children?: ReactNode\n props?: any\n}\n\ntype LenisRef = {\n wrapper?: HTMLElement\n content?: HTMLElement\n lenis?: Lenis\n}\n\nconst ReactLenis: ForwardRefComponent = forwardRef<\n LenisRef,\n Props\n>(\n (\n {\n children,\n root = false,\n options = {},\n autoRaf = true,\n rafPriority = 0,\n className,\n ...props\n }: Props,\n ref\n ) => {\n const wrapperRef = useRef()\n const contentRef = useRef()\n\n const [lenis, setLenis] = useState()\n\n const callbacksRefs = useRef([])\n\n const addCallback = useCallback((callback, priority) => {\n callbacksRefs.current.push({ callback, priority })\n callbacksRefs.current.sort((a, b) => a.priority - b.priority)\n }, [])\n\n const removeCallback = useCallback((callback) => {\n callbacksRefs.current = callbacksRefs.current.filter(\n (cb) => cb.callback !== callback\n )\n }, [])\n\n useImperativeHandle(\n ref,\n () => ({\n wrapper: wrapperRef.current,\n content: contentRef.current,\n lenis,\n }),\n [lenis]\n )\n\n useEffect(() => {\n const lenis = new Lenis({\n ...options,\n ...(!root && {\n wrapper: wrapperRef.current,\n content: contentRef.current,\n }),\n })\n\n setLenis(lenis)\n\n return () => {\n lenis.destroy()\n setLenis(undefined)\n }\n }, [root, JSON.stringify(options)])\n\n useFrame((time) => {\n if (autoRaf) {\n lenis?.raf(time)\n }\n }, rafPriority)\n\n useEffect(() => {\n if (root && lenis) {\n useRoot.setState({ lenis, addCallback, removeCallback })\n }\n }, [root, lenis, addCallback, removeCallback])\n\n const onScroll = useCallback((e) => {\n for (let i = 0; i < callbacksRefs.current.length; i++) {\n callbacksRefs.current[i].callback(e)\n }\n }, [])\n\n useEffect(() => {\n lenis?.on('scroll', onScroll)\n\n return () => {\n lenis?.off('scroll', onScroll)\n }\n }, [lenis, onScroll])\n\n const onClassNameChange = useCallback(() => {\n if (wrapperRef.current) {\n wrapperRef.current.className = cn(lenis?.className, className)\n }\n }, [lenis, className])\n\n useEffect(() => {\n onClassNameChange()\n\n lenis?.on('className change', onClassNameChange)\n\n return () => {\n lenis?.off('className change', onClassNameChange)\n }\n }, [lenis, onClassNameChange])\n\n return (\n \n {root ? (\n children\n ) : (\n \n

{children}
\n \n )}\n \n )\n }\n)\n\nexport { ReactLenis as Lenis, ReactLenis }\nexport default ReactLenis\n"],"names":["SuppressedError","window","reactLenisVersion","LenisContext","createContext","useRoot","create","ReactLenis","forwardRef","_a","ref","children","root","options","autoRaf","rafPriority","className","props","s","e","t","p","Object","prototype","hasOwnProperty","call","indexOf","getOwnPropertySymbols","i","length","propertyIsEnumerable","__rest","wrapperRef","useRef","contentRef","lenis","setLenis","useState","callbacksRefs","addCallback","useCallback","callback","priority","current","push","sort","a","b","removeCallback","filter","cb","useImperativeHandle","wrapper","content","useEffect","Lenis","assign","destroy","undefined","JSON","stringify","useFrame","time","raf","setState","onScroll","on","off","onClassNameChange","cn","React","Provider","value","createElement","deps","local","useContext","useCurrentLenis"],"mappings":"+dA2TkD,mBAApBA,iBAAiCA,gBCrSzC,oBAAXC,SAAwBA,OAAOC,4BAE7BC,MAAAA,EAAeC,EAAAA,gBAEtBC,EAAUC,EAAMA,QAAC,MAAS,KAkD1BC,MAAAA,EAAmDC,EAAUA,YAIjE,CACEC,EASAC,SATAC,SACEA,EAAQC,KACRA,GAAO,EAAKC,QACZA,EAAU,CAAE,EAAAC,QACZA,GAAU,EAAIC,YACdA,EAAc,EAACC,UACfA,KACGC,ED9CF,SAAgBC,EAAGC,GACtB,IAAIC,EAAI,CAAA,EACR,IAAK,IAAIC,KAAKH,EAAOI,OAAOC,UAAUC,eAAeC,KAAKP,EAAGG,IAAMF,EAAEO,QAAQL,GAAK,IAC9ED,EAAEC,GAAKH,EAAEG,IACb,GAAS,MAALH,GAAqD,mBAAjCI,OAAOK,sBACtB,KAAIC,EAAI,EAAb,IAAgBP,EAAIC,OAAOK,sBAAsBT,GAAIU,EAAIP,EAAEQ,OAAQD,IAC3DT,EAAEO,QAAQL,EAAEO,IAAM,GAAKN,OAAOC,UAAUO,qBAAqBL,KAAKP,EAAG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,EAAAA,WAAU,KACRnB,SAAAA,EAAO+B,GAAG,SAAUD,GAEb,KACL9B,SAAAA,EAAOgC,IAAI,SAAUF,EAAS,IAE/B,CAAC9B,EAAO8B,IAEX,MAAMG,EAAoB5B,EAAAA,aAAY,KAChCR,EAAWW,UACbX,EAAWW,QAAQ3B,UAAYqD,EAAGlC,eAAAA,EAAOnB,UAAWA,GACtD,GACC,CAACmB,EAAOnB,IAYX,OAVAsC,EAAAA,WAAU,KACRc,IAEAjC,SAAAA,EAAO+B,GAAG,mBAAoBE,GAEvB,KACLjC,SAAAA,EAAOgC,IAAI,mBAAoBC,EAAkB,IAElD,CAACjC,EAAOiC,IAGTE,gBAACnE,EAAaoE,SAAS,CAAAC,MAAO,CAAErC,QAAOI,cAAaS,mBACjDpC,EACCD,EAEA2D,EACEG,cAAA,MAAAnD,OAAAkC,OAAA,CAAA9C,IAAKsB,EACLhB,UAAWqD,EAAGlC,eAAAA,EAAOnB,UAAWA,IAC5BC,GAEJqD,EAAKG,cAAA,MAAA,CAAA/D,IAAKwB,GAAavB,IAGL,qEA7JxB,SACJ8B,EACAiC,EAAoB,GACpBhC,EAAW,GAEX,MAAMP,MAAEA,EAAKI,YAAEA,EAAWS,eAAEA,GAZ9B,WACE,MAAM2B,EAAQC,aAAWzE,GACnBS,EAAOP,IAEb,OAAOsE,QAAAA,EAAS/D,CAClB,CAOiDiE,GAa/C,OAXAvB,EAAAA,WAAU,KACR,GAAKb,GAAaF,GAAgBS,GAAmBb,EAKrD,OAHAI,EAAYE,EAAUC,GACtBD,EAASN,GAEF,KACLa,EAAeP,EAAS,CACzB,GACA,CAACN,EAAOI,EAAaS,EAAgBN,KAAagC,IAE9CvC,CACT","x_google_ignoreList":[0]} \ No newline at end of file +{"version":3,"file":"react-lenis.umd.js","sources":["../../../node_modules/tslib/tslib.es6.js","../../src/index.tsx"],"sourcesContent":["/******************************************************************************\r\nCopyright (c) Microsoft Corporation.\r\n\r\nPermission to use, copy, modify, and/or distribute this software for any\r\npurpose with or without fee is hereby granted.\r\n\r\nTHE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\r\nREGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\r\nAND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\r\nINDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\r\nLOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\r\nOTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\r\nPERFORMANCE OF THIS SOFTWARE.\r\n***************************************************************************** */\r\n/* global Reflect, Promise, SuppressedError, Symbol */\r\n\r\nvar extendStatics = function(d, b) {\r\n extendStatics = Object.setPrototypeOf ||\r\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\r\n function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };\r\n return extendStatics(d, b);\r\n};\r\n\r\nexport function __extends(d, b) {\r\n if (typeof b !== \"function\" && b !== null)\r\n throw new TypeError(\"Class extends value \" + String(b) + \" is not a constructor or null\");\r\n extendStatics(d, b);\r\n function __() { this.constructor = d; }\r\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\r\n}\r\n\r\nexport var __assign = function() {\r\n __assign = Object.assign || function __assign(t) {\r\n for (var s, i = 1, n = arguments.length; i < n; i++) {\r\n s = arguments[i];\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];\r\n }\r\n return t;\r\n }\r\n return __assign.apply(this, arguments);\r\n}\r\n\r\nexport function __rest(s, e) {\r\n var t = {};\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)\r\n t[p] = s[p];\r\n if (s != null && typeof Object.getOwnPropertySymbols === \"function\")\r\n for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {\r\n if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))\r\n t[p[i]] = s[p[i]];\r\n }\r\n return t;\r\n}\r\n\r\nexport function __decorate(decorators, target, key, desc) {\r\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\r\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\r\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\r\n return c > 3 && r && Object.defineProperty(target, key, r), r;\r\n}\r\n\r\nexport function __param(paramIndex, decorator) {\r\n return function (target, key) { decorator(target, key, paramIndex); }\r\n}\r\n\r\nexport function __esDecorate(ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {\r\n function accept(f) { if (f !== void 0 && typeof f !== \"function\") throw new TypeError(\"Function expected\"); return f; }\r\n var kind = contextIn.kind, key = kind === \"getter\" ? \"get\" : kind === \"setter\" ? \"set\" : \"value\";\r\n var target = !descriptorIn && ctor ? contextIn[\"static\"] ? ctor : ctor.prototype : null;\r\n var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});\r\n var _, done = false;\r\n for (var i = decorators.length - 1; i >= 0; i--) {\r\n var context = {};\r\n for (var p in contextIn) context[p] = p === \"access\" ? {} : contextIn[p];\r\n for (var p in contextIn.access) context.access[p] = contextIn.access[p];\r\n context.addInitializer = function (f) { if (done) throw new TypeError(\"Cannot add initializers after decoration has completed\"); extraInitializers.push(accept(f || null)); };\r\n var result = (0, decorators[i])(kind === \"accessor\" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);\r\n if (kind === \"accessor\") {\r\n if (result === void 0) continue;\r\n if (result === null || typeof result !== \"object\") throw new TypeError(\"Object expected\");\r\n if (_ = accept(result.get)) descriptor.get = _;\r\n if (_ = accept(result.set)) descriptor.set = _;\r\n if (_ = accept(result.init)) initializers.unshift(_);\r\n }\r\n else if (_ = accept(result)) {\r\n if (kind === \"field\") initializers.unshift(_);\r\n else descriptor[key] = _;\r\n }\r\n }\r\n if (target) Object.defineProperty(target, contextIn.name, descriptor);\r\n done = true;\r\n};\r\n\r\nexport function __runInitializers(thisArg, initializers, value) {\r\n var useValue = arguments.length > 2;\r\n for (var i = 0; i < initializers.length; i++) {\r\n value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);\r\n }\r\n return useValue ? value : void 0;\r\n};\r\n\r\nexport function __propKey(x) {\r\n return typeof x === \"symbol\" ? x : \"\".concat(x);\r\n};\r\n\r\nexport function __setFunctionName(f, name, prefix) {\r\n if (typeof name === \"symbol\") name = name.description ? \"[\".concat(name.description, \"]\") : \"\";\r\n return Object.defineProperty(f, \"name\", { configurable: true, value: prefix ? \"\".concat(prefix, \" \", name) : name });\r\n};\r\n\r\nexport function __metadata(metadataKey, metadataValue) {\r\n if (typeof Reflect === \"object\" && typeof Reflect.metadata === \"function\") return Reflect.metadata(metadataKey, metadataValue);\r\n}\r\n\r\nexport function __awaiter(thisArg, _arguments, P, generator) {\r\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\r\n return new (P || (P = Promise))(function (resolve, reject) {\r\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\r\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\r\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\r\n step((generator = generator.apply(thisArg, _arguments || [])).next());\r\n });\r\n}\r\n\r\nexport function __generator(thisArg, body) {\r\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\r\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\r\n function verb(n) { return function (v) { return step([n, v]); }; }\r\n function step(op) {\r\n if (f) throw new TypeError(\"Generator is already executing.\");\r\n while (g && (g = 0, op[0] && (_ = 0)), _) try {\r\n if (f = 1, y && (t = op[0] & 2 ? y[\"return\"] : op[0] ? y[\"throw\"] || ((t = y[\"return\"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;\r\n if (y = 0, t) op = [op[0] & 2, t.value];\r\n switch (op[0]) {\r\n case 0: case 1: t = op; break;\r\n case 4: _.label++; return { value: op[1], done: false };\r\n case 5: _.label++; y = op[1]; op = [0]; continue;\r\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\r\n default:\r\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\r\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\r\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\r\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\r\n if (t[2]) _.ops.pop();\r\n _.trys.pop(); continue;\r\n }\r\n op = body.call(thisArg, _);\r\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\r\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\r\n }\r\n}\r\n\r\nexport var __createBinding = Object.create ? (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n var desc = Object.getOwnPropertyDescriptor(m, k);\r\n if (!desc || (\"get\" in desc ? !m.__esModule : desc.writable || desc.configurable)) {\r\n desc = { enumerable: true, get: function() { return m[k]; } };\r\n }\r\n Object.defineProperty(o, k2, desc);\r\n}) : (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n o[k2] = m[k];\r\n});\r\n\r\nexport function __exportStar(m, o) {\r\n for (var p in m) if (p !== \"default\" && !Object.prototype.hasOwnProperty.call(o, p)) __createBinding(o, m, p);\r\n}\r\n\r\nexport function __values(o) {\r\n var s = typeof Symbol === \"function\" && Symbol.iterator, m = s && o[s], i = 0;\r\n if (m) return m.call(o);\r\n if (o && typeof o.length === \"number\") return {\r\n next: function () {\r\n if (o && i >= o.length) o = void 0;\r\n return { value: o && o[i++], done: !o };\r\n }\r\n };\r\n throw new TypeError(s ? \"Object is not iterable.\" : \"Symbol.iterator is not defined.\");\r\n}\r\n\r\nexport function __read(o, n) {\r\n var m = typeof Symbol === \"function\" && o[Symbol.iterator];\r\n if (!m) return o;\r\n var i = m.call(o), r, ar = [], e;\r\n try {\r\n while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);\r\n }\r\n catch (error) { e = { error: error }; }\r\n finally {\r\n try {\r\n if (r && !r.done && (m = i[\"return\"])) m.call(i);\r\n }\r\n finally { if (e) throw e.error; }\r\n }\r\n return ar;\r\n}\r\n\r\n/** @deprecated */\r\nexport function __spread() {\r\n for (var ar = [], i = 0; i < arguments.length; i++)\r\n ar = ar.concat(__read(arguments[i]));\r\n return ar;\r\n}\r\n\r\n/** @deprecated */\r\nexport function __spreadArrays() {\r\n for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;\r\n for (var r = Array(s), k = 0, i = 0; i < il; i++)\r\n for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)\r\n r[k] = a[j];\r\n return r;\r\n}\r\n\r\nexport function __spreadArray(to, from, pack) {\r\n if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {\r\n if (ar || !(i in from)) {\r\n if (!ar) ar = Array.prototype.slice.call(from, 0, i);\r\n ar[i] = from[i];\r\n }\r\n }\r\n return to.concat(ar || Array.prototype.slice.call(from));\r\n}\r\n\r\nexport function __await(v) {\r\n return this instanceof __await ? (this.v = v, this) : new __await(v);\r\n}\r\n\r\nexport function __asyncGenerator(thisArg, _arguments, generator) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var g = generator.apply(thisArg, _arguments || []), i, q = [];\r\n return i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i;\r\n function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }\r\n function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }\r\n function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }\r\n function fulfill(value) { resume(\"next\", value); }\r\n function reject(value) { resume(\"throw\", value); }\r\n function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }\r\n}\r\n\r\nexport function __asyncDelegator(o) {\r\n var i, p;\r\n return i = {}, verb(\"next\"), verb(\"throw\", function (e) { throw e; }), verb(\"return\"), i[Symbol.iterator] = function () { return this; }, i;\r\n function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: false } : f ? f(v) : v; } : f; }\r\n}\r\n\r\nexport function __asyncValues(o) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var m = o[Symbol.asyncIterator], i;\r\n return m ? m.call(o) : (o = typeof __values === \"function\" ? __values(o) : o[Symbol.iterator](), i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i);\r\n function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }\r\n function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }\r\n}\r\n\r\nexport function __makeTemplateObject(cooked, raw) {\r\n if (Object.defineProperty) { Object.defineProperty(cooked, \"raw\", { value: raw }); } else { cooked.raw = raw; }\r\n return cooked;\r\n};\r\n\r\nvar __setModuleDefault = Object.create ? (function(o, v) {\r\n Object.defineProperty(o, \"default\", { enumerable: true, value: v });\r\n}) : function(o, v) {\r\n o[\"default\"] = v;\r\n};\r\n\r\nexport function __importStar(mod) {\r\n if (mod && mod.__esModule) return mod;\r\n var result = {};\r\n if (mod != null) for (var k in mod) if (k !== \"default\" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);\r\n __setModuleDefault(result, mod);\r\n return result;\r\n}\r\n\r\nexport function __importDefault(mod) {\r\n return (mod && mod.__esModule) ? mod : { default: mod };\r\n}\r\n\r\nexport function __classPrivateFieldGet(receiver, state, kind, f) {\r\n if (kind === \"a\" && !f) throw new TypeError(\"Private accessor was defined without a getter\");\r\n if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError(\"Cannot read private member from an object whose class did not declare it\");\r\n return kind === \"m\" ? f : kind === \"a\" ? f.call(receiver) : f ? f.value : state.get(receiver);\r\n}\r\n\r\nexport function __classPrivateFieldSet(receiver, state, value, kind, f) {\r\n if (kind === \"m\") throw new TypeError(\"Private method is not writable\");\r\n if (kind === \"a\" && !f) throw new TypeError(\"Private accessor was defined without a setter\");\r\n if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError(\"Cannot write private member to an object whose class did not declare it\");\r\n return (kind === \"a\" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;\r\n}\r\n\r\nexport function __classPrivateFieldIn(state, receiver) {\r\n if (receiver === null || (typeof receiver !== \"object\" && typeof receiver !== \"function\")) throw new TypeError(\"Cannot use 'in' operator on non-object\");\r\n return typeof state === \"function\" ? receiver === state : state.has(receiver);\r\n}\r\n\r\nexport function __addDisposableResource(env, value, async) {\r\n if (value !== null && value !== void 0) {\r\n if (typeof value !== \"object\" && typeof value !== \"function\") throw new TypeError(\"Object expected.\");\r\n var dispose;\r\n if (async) {\r\n if (!Symbol.asyncDispose) throw new TypeError(\"Symbol.asyncDispose is not defined.\");\r\n dispose = value[Symbol.asyncDispose];\r\n }\r\n if (dispose === void 0) {\r\n if (!Symbol.dispose) throw new TypeError(\"Symbol.dispose is not defined.\");\r\n dispose = value[Symbol.dispose];\r\n }\r\n if (typeof dispose !== \"function\") throw new TypeError(\"Object not disposable.\");\r\n env.stack.push({ value: value, dispose: dispose, async: async });\r\n }\r\n else if (async) {\r\n env.stack.push({ async: true });\r\n }\r\n return value;\r\n}\r\n\r\nvar _SuppressedError = typeof SuppressedError === \"function\" ? SuppressedError : function (error, suppressed, message) {\r\n var e = new Error(message);\r\n return e.name = \"SuppressedError\", e.error = error, e.suppressed = suppressed, e;\r\n};\r\n\r\nexport function __disposeResources(env) {\r\n function fail(e) {\r\n env.error = env.hasError ? new _SuppressedError(e, env.error, \"An error was suppressed during disposal.\") : e;\r\n env.hasError = true;\r\n }\r\n function next() {\r\n while (env.stack.length) {\r\n var rec = env.stack.pop();\r\n try {\r\n var result = rec.dispose && rec.dispose.call(rec.value);\r\n if (rec.async) return Promise.resolve(result).then(next, function(e) { fail(e); return next(); });\r\n }\r\n catch (e) {\r\n fail(e);\r\n }\r\n }\r\n if (env.hasError) throw env.error;\r\n }\r\n return next();\r\n}\r\n\r\nexport default {\r\n __extends: __extends,\r\n __assign: __assign,\r\n __rest: __rest,\r\n __decorate: __decorate,\r\n __param: __param,\r\n __metadata: __metadata,\r\n __awaiter: __awaiter,\r\n __generator: __generator,\r\n __createBinding: __createBinding,\r\n __exportStar: __exportStar,\r\n __values: __values,\r\n __read: __read,\r\n __spread: __spread,\r\n __spreadArrays: __spreadArrays,\r\n __spreadArray: __spreadArray,\r\n __await: __await,\r\n __asyncGenerator: __asyncGenerator,\r\n __asyncDelegator: __asyncDelegator,\r\n __asyncValues: __asyncValues,\r\n __makeTemplateObject: __makeTemplateObject,\r\n __importStar: __importStar,\r\n __importDefault: __importDefault,\r\n __classPrivateFieldGet: __classPrivateFieldGet,\r\n __classPrivateFieldSet: __classPrivateFieldSet,\r\n __classPrivateFieldIn: __classPrivateFieldIn,\r\n __addDisposableResource: __addDisposableResource,\r\n __disposeResources: __disposeResources,\r\n};\r\n","'use client'\r\n\r\nimport { useFrame } from '@studio-freight/hamo'\r\nimport Lenis, { LenisOptions } from '@studio-freight/lenis'\r\nimport cn from 'clsx'\r\nimport React, {\r\n ForwardRefExoticComponent,\r\n PropsWithoutRef,\r\n ReactNode,\r\n RefAttributes,\r\n createContext,\r\n forwardRef,\r\n useCallback,\r\n useContext,\r\n useEffect,\r\n useImperativeHandle,\r\n useRef,\r\n useState,\r\n} from 'react'\r\nimport { create } from 'zustand'\r\nimport { version } from '../package.json'\r\n\r\ntype LenisEventHandler = (lenis: Lenis) => void\r\ninterface LenisContextValue {\r\n lenis: Lenis\r\n addCallback: (handler: LenisEventHandler, priority: number) => void\r\n removeCallback: (handler: LenisEventHandler) => void\r\n}\r\n\r\ndeclare global {\r\n interface Window {\r\n reactLenisVersion: string\r\n }\r\n}\r\nif (typeof window !== 'undefined') {\r\n window.reactLenisVersion = version\r\n}\r\n\r\nexport const LenisContext = createContext(null)\r\n\r\nconst useRoot = create>(() => ({}))\r\n\r\nfunction useCurrentLenis() {\r\n const local = useContext(LenisContext)\r\n const root = useRoot()\r\n\r\n return local ?? root\r\n}\r\n\r\nexport function useLenis(\r\n callback?: (lenis: Lenis) => void,\r\n deps: Array = [],\r\n priority = 0\r\n): Lenis | undefined {\r\n const { lenis, addCallback, removeCallback } = useCurrentLenis()\r\n\r\n useEffect(() => {\r\n if (!callback || !addCallback || !removeCallback || !lenis) return\r\n\r\n addCallback(callback, priority)\r\n callback(lenis)\r\n\r\n return () => {\r\n removeCallback(callback)\r\n }\r\n }, [lenis, addCallback, removeCallback, priority, ...deps])\r\n\r\n return lenis\r\n}\r\n\r\ntype ForwardRefComponent = ForwardRefExoticComponent<\r\n PropsWithoutRef

& RefAttributes\r\n>\r\n\r\ntype Props = {\r\n root?: boolean\r\n options?: LenisOptions\r\n autoRaf?: boolean\r\n rafPriority?: number\r\n className?: string\r\n children?: ReactNode\r\n props?: any\r\n}\r\n\r\ntype LenisRef = {\r\n wrapper?: HTMLElement\r\n content?: HTMLElement\r\n lenis?: Lenis\r\n}\r\n\r\nconst ReactLenis: ForwardRefComponent = forwardRef<\r\n LenisRef,\r\n Props\r\n>(\r\n (\r\n {\r\n children,\r\n root = false,\r\n options = {},\r\n autoRaf = true,\r\n rafPriority = 0,\r\n className,\r\n ...props\r\n }: Props,\r\n ref\r\n ) => {\r\n const wrapperRef = useRef(null)\r\n const contentRef = useRef(null)\r\n\r\n const [lenis, setLenis] = useState(undefined)\r\n\r\n const callbacksRefs = useRef<\r\n {\r\n callback: LenisEventHandler\r\n priority: number\r\n }[]\r\n >([])\r\n\r\n const addCallback: LenisContextValue['addCallback'] = useCallback(\r\n (callback, priority) => {\r\n callbacksRefs.current.push({ callback, priority })\r\n callbacksRefs.current.sort((a, b) => a.priority - b.priority)\r\n },\r\n []\r\n )\r\n\r\n const removeCallback: LenisContextValue['removeCallback'] = useCallback(\r\n (callback) => {\r\n callbacksRefs.current = callbacksRefs.current.filter(\r\n (cb) => cb.callback !== callback\r\n )\r\n },\r\n []\r\n )\r\n\r\n useImperativeHandle(\r\n ref,\r\n () => ({\r\n wrapper: wrapperRef.current!,\r\n content: contentRef.current!,\r\n lenis,\r\n }),\r\n [lenis]\r\n )\r\n\r\n useEffect(() => {\r\n const lenis = new Lenis({\r\n ...options,\r\n ...(!root && {\r\n wrapper: wrapperRef.current!,\r\n content: contentRef.current!,\r\n }),\r\n })\r\n\r\n setLenis(lenis)\r\n\r\n return () => {\r\n lenis.destroy()\r\n setLenis(undefined)\r\n }\r\n }, [root, JSON.stringify(options)])\r\n\r\n useFrame((time: number) => {\r\n if (autoRaf) {\r\n lenis?.raf(time)\r\n }\r\n }, rafPriority)\r\n\r\n useEffect(() => {\r\n if (root && lenis) {\r\n useRoot.setState({ lenis, addCallback, removeCallback })\r\n }\r\n }, [root, lenis, addCallback, removeCallback])\r\n\r\n const onScroll = useCallback((lenisInstance: Lenis) => {\r\n for (let i = 0; i < callbacksRefs.current.length; i++) {\r\n callbacksRefs.current[i].callback(lenisInstance)\r\n }\r\n }, [])\r\n\r\n useEffect(() => {\r\n lenis?.on('scroll', onScroll)\r\n\r\n return () => {\r\n lenis?.off('scroll', onScroll)\r\n }\r\n }, [lenis, onScroll])\r\n\r\n const onClassNameChange = useCallback(() => {\r\n if (wrapperRef.current) {\r\n wrapperRef.current.className = cn(lenis?.className, className)\r\n }\r\n }, [lenis, className])\r\n\r\n useEffect(() => {\r\n onClassNameChange()\r\n\r\n lenis?.on('className change', onClassNameChange)\r\n\r\n return () => {\r\n lenis?.off('className change', onClassNameChange)\r\n }\r\n }, [lenis, onClassNameChange])\r\n\r\n return (\r\n \r\n {root ? (\r\n children\r\n ) : (\r\n \r\n

{children}
\r\n \r\n )}\r\n \r\n )\r\n }\r\n)\r\n\r\nexport { ReactLenis as Lenis, ReactLenis }\r\nexport default ReactLenis\r\n"],"names":["SuppressedError","window","reactLenisVersion","LenisContext","createContext","useRoot","create","ReactLenis","forwardRef","_a","ref","children","root","options","autoRaf","rafPriority","className","props","s","e","t","p","Object","prototype","hasOwnProperty","call","indexOf","getOwnPropertySymbols","i","length","propertyIsEnumerable","__rest","wrapperRef","useRef","contentRef","lenis","setLenis","useState","undefined","callbacksRefs","addCallback","useCallback","callback","priority","current","push","sort","a","b","removeCallback","filter","cb","useImperativeHandle","wrapper","content","useEffect","Lenis","assign","destroy","JSON","stringify","useFrame","time","raf","setState","onScroll","lenisInstance","on","off","onClassNameChange","cn","React","Provider","value","createElement","deps","local","useContext","useCurrentLenis"],"mappings":"+dA2TkD,mBAApBA,iBAAiCA,gBCzRzC,oBAAXC,SACTA,OAAOC,kCAGIC,EAAeC,EAAaA,cAA2B,MAE9DC,EAAUC,EAAMA,QAA6B,MAAS,KAkDtDC,MAAAA,EAAmDC,EAAUA,YAIjE,CACEC,EASAC,SATAC,SACEA,EAAQC,KACRA,GAAO,EAAKC,QACZA,EAAU,CAAE,EAAAC,QACZA,GAAU,EAAIC,YACdA,EA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nBS,EAAOP,IAEb,OAAOuE,QAAAA,EAAShE,CAClB,CAOiDkE,GAa/C,OAXAvB,EAAAA,WAAU,KACR,GAAKb,GAAaF,GAAgBS,GAAmBd,EAKrD,OAHAK,EAAYE,EAAUC,GACtBD,EAASP,GAEF,KACLc,EAAeP,EAAS,CACzB,GACA,CAACP,EAAOK,EAAaS,EAAgBN,KAAagC,IAE9CxC,CACT","x_google_ignoreList":[0]} \ No newline at end of file diff --git a/packages/react-lenis/dist/types/index.d.ts b/packages/react-lenis/dist/types/index.d.ts index f92b3b44..b003c98b 100644 --- a/packages/react-lenis/dist/types/index.d.ts +++ b/packages/react-lenis/dist/types/index.d.ts @@ -1,6 +1,17 @@ import Lenis, { LenisOptions } from '@studio-freight/lenis'; -import { ForwardRefExoticComponent, PropsWithoutRef, ReactNode, RefAttributes } from 'react'; -export declare const LenisContext: Lenis | null; +import React, { 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; +} +declare global { + interface Window { + reactLenisVersion: string; + } +} +export declare const LenisContext: React.Context; export declare function useLenis(callback?: (lenis: Lenis) => void, deps?: Array, priority?: number): Lenis | undefined; type ForwardRefComponent = ForwardRefExoticComponent & RefAttributes>; type Props = { diff --git a/packages/react-lenis/dist/types/src/index.d.ts b/packages/react-lenis/dist/types/src/index.d.ts new file mode 100644 index 00000000..b003c98b --- /dev/null +++ b/packages/react-lenis/dist/types/src/index.d.ts @@ -0,0 +1,33 @@ +import Lenis, { LenisOptions } from '@studio-freight/lenis'; +import React, { 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; +} +declare global { + interface Window { + reactLenisVersion: string; + } +} +export declare const LenisContext: React.Context; +export declare function useLenis(callback?: (lenis: Lenis) => void, deps?: Array, priority?: number): Lenis | undefined; +type ForwardRefComponent = ForwardRefExoticComponent & RefAttributes>; +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; +export { ReactLenis as Lenis, ReactLenis }; +export default ReactLenis; diff --git a/packages/react-lenis/package.json b/packages/react-lenis/package.json index 609f85bf..4145ff7b 100644 --- a/packages/react-lenis/package.json +++ b/packages/react-lenis/package.json @@ -14,12 +14,8 @@ "scripts": { "dev": "npm-run-all --parallel watch playground", "playground": "npm run dev --prefix ./playground", - "build": "npm-run-all --parallel build:dist", - "build:dist": "rollup --bundleConfigAsCjs -c", - "build:types": "tsc --target esnext --allowJs -d --emitDeclarationOnly --declarationDir ./dist/types --removeComments ./src/index.jsx", - "watch:dist": "rollup --bundleConfigAsCjs -c -w", - "watch:types": "tsc --target esnext --allowJs -d --emitDeclarationOnly --declarationDir ./dist/types --removeComments --watch ./src/index.jsx --jsx react", - "watch": "npm-run-all --parallel watch:dist", + "build": "rollup --bundleConfigAsCjs -c", + "watch": "rollup --bundleConfigAsCjs -c -w", "git:commit": "git add -A && cross-var git commit -m \"$npm_package_name@$npm_package_version\"", "git:tag": "cross-var git tag -a $npm_package_name@$npm_package_version -m \"$npm_package_name@$npm_package_version\"", "git:push": "git push && git push --tags", diff --git a/packages/react-lenis/src/index.tsx b/packages/react-lenis/src/index.tsx index d9dd4462..61314169 100644 --- a/packages/react-lenis/src/index.tsx +++ b/packages/react-lenis/src/index.tsx @@ -20,19 +20,23 @@ import React, { import { create } from 'zustand' import { version } from '../package.json' -type LenisEventHandler = (lenis: Lenis) => void; +type LenisEventHandler = (lenis: Lenis) => void interface LenisContextValue { - lenis: Lenis; - addCallback: (handler: LenisEventHandler, priority: number) => void; - removeCallback: (handler: LenisEventHandler) => void; + lenis: Lenis + addCallback: (handler: LenisEventHandler, priority: number) => void + removeCallback: (handler: LenisEventHandler) => void } declare global { - interface Window { reactLenisVersion: string; } + interface Window { + reactLenisVersion: string + } +} +if (typeof window !== 'undefined') { + window.reactLenisVersion = version } -if (typeof window !== 'undefined') window.reactLenisVersion = version -export const LenisContext = createContext(null); +export const LenisContext = createContext(null) const useRoot = create>(() => ({})) @@ -103,23 +107,31 @@ const ReactLenis: ForwardRefComponent = forwardRef< const wrapperRef = useRef(null) const contentRef = useRef(null) - const [lenis, setLenis] = useState(undefined); - - const callbacksRefs = useRef<{ - callback: LenisEventHandler, - priority: number, - }[]>([]) - - const addCallback: LenisContextValue["addCallback"] = useCallback((callback, priority) => { - callbacksRefs.current.push({ callback, priority }) - callbacksRefs.current.sort((a, b) => a.priority - b.priority) - }, []) + const [lenis, setLenis] = useState(undefined) + + const callbacksRefs = useRef< + { + callback: LenisEventHandler + priority: number + }[] + >([]) + + const addCallback: LenisContextValue['addCallback'] = useCallback( + (callback, priority) => { + callbacksRefs.current.push({ callback, priority }) + callbacksRefs.current.sort((a, b) => a.priority - b.priority) + }, + [] + ) - const removeCallback: LenisContextValue["removeCallback"] = useCallback((callback) => { - callbacksRefs.current = callbacksRefs.current.filter( - (cb) => cb.callback !== callback - ) - }, []) + const removeCallback: LenisContextValue['removeCallback'] = useCallback( + (callback) => { + callbacksRefs.current = callbacksRefs.current.filter( + (cb) => cb.callback !== callback + ) + }, + [] + ) useImperativeHandle( ref, @@ -191,7 +203,9 @@ const ReactLenis: ForwardRefComponent = forwardRef< }, [lenis, onClassNameChange]) return ( - + {root ? ( children ) : ( diff --git a/packages/react-lenis/tsconfig.json b/packages/react-lenis/tsconfig.json index b95f8dcb..5afcad9c 100644 --- a/packages/react-lenis/tsconfig.json +++ b/packages/react-lenis/tsconfig.json @@ -11,7 +11,7 @@ "noEmit": true, "allowJs": true, "removeComments": true, - "resolveJsonModule": true, + // "resolveJsonModule": true, "outDir": "./dist/types", "jsx": "react" }, diff --git a/yarn.lock b/yarn.lock index c8c93faf..1457adc6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2616,3 +2616,10 @@ zustand@^4.4.7: integrity sha512-XlauQmH64xXSC1qGYNv00ODaQ3B+tNPoy22jv2diYiP4eoDKr9LA+Bh5Bc3gplTrFdb6JVI+N4kc1DZ/tbtfPg== dependencies: use-sync-external-store "1.2.0" + +zustand@^4.5.1: + version "4.5.2" + resolved "https://registry.yarnpkg.com/zustand/-/zustand-4.5.2.tgz#fddbe7cac1e71d45413b3682cdb47b48034c3848" + integrity sha512-2cN1tPkDVkwCy5ickKrI7vijSjPksFRfqS6237NzT0vqSsztTNnQdHw9mmN7uBdk3gceVXU0a+21jFzFzAc9+g== + dependencies: + use-sync-external-store "1.2.0"