@neveranyart/weaver 1.0.1 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/hooks.js CHANGED
@@ -103,7 +103,7 @@ function useLayoutEffectOnce(callback) {
103
103
  // src/hooks/lenisCallback.ts
104
104
  var import_react5 = require("react");
105
105
 
106
- // src/index.ts
106
+ // src/setup.ts
107
107
  var lenisInstance = void 0;
108
108
 
109
109
  // src/hooks/orbit.ts
package/dist/hooks.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/hooks/index.ts","../src/hooks/breakpoints.ts","../src/hooks/screenCallback.ts","../src/hooks/effectOnce.ts","../src/hooks/lenisCallback.ts","../src/index.ts","../src/hooks/orbit.ts","../src/hooks/mouseCallback.ts","../src/hooks/navigateAnchor.ts","../src/hooks/rawParams.ts","../src/hooks/routeNormalizer.ts","../src/hooks/screen.ts","../src/hooks/viewport.ts"],"sourcesContent":["import { useBreakpoints } from './breakpoints';\nimport { useEffectOnce, useLayoutEffectOnce } from './effectOnce';\nimport { useLenisCallback } from './lenisCallback';\nimport { useMouseCallback } from './mouseCallback';\nimport { useNavigateAnchor } from './navigateAnchor';\nimport { useOrbit } from './orbit';\nimport { useRawParams } from './rawParams';\nimport { useRouteNormalizer } from './routeNormalizer';\nimport { useScreen } from './screen';\nimport { useScreenCallback } from './screenCallback';\nimport { useViewport } from './viewport';\n\nexport {\n useBreakpoints,\n useEffectOnce,\n useLayoutEffectOnce,\n useLenisCallback,\n useMouseCallback,\n useNavigateAnchor,\n useOrbit,\n useRawParams,\n useRouteNormalizer,\n useScreen,\n useScreenCallback,\n useViewport,\n};\n","import { useCallback, useState } from 'react';\nimport { useScreenCallback } from './screenCallback';\n\nexport function useBreakpoints(breakpoints?: number[] | null) {\n const getBreakpoint = useCallback(\n (width: number) => {\n const processingBreakpoints = !breakpoints\n ? [640, 768, 1024, 1280, 1536]\n : breakpoints;\n\n if (!processingBreakpoints) {\n throw Error(\"Uhhh... so you don't want a breakpoint? Just say it.\");\n }\n\n let result = processingBreakpoints!.length;\n for (let index = 0; index < processingBreakpoints!.length; index++) {\n if (width < processingBreakpoints![index]) {\n result = index;\n break;\n }\n }\n\n return result;\n },\n [breakpoints]\n );\n\n const [breakAt, setBreakAt] = useState<number>(\n getBreakpoint(document.body.clientWidth)\n );\n\n const breakpointCheck = useCallback(\n (latest: { width: number; height: number }) => {\n const result = getBreakpoint(latest.width);\n if (result !== breakAt) {\n setBreakAt(result);\n }\n },\n [breakAt, getBreakpoint]\n );\n useScreenCallback(breakpointCheck);\n\n return breakAt;\n}\n","import { useLayoutEffect } from 'react';\n\nexport interface ScreenCallbackValues {\n width: number;\n height: number;\n}\n\ntype Callback = (props: ScreenCallbackValues) => void;\n\nexport function useScreenCallback(\n callback: Callback,\n options?: { initialCall?: boolean }\n) {\n useLayoutEffect(() => {\n const reportScreen = () =>\n callback({\n width: document.body.clientWidth,\n height: document.documentElement.clientHeight,\n });\n\n // Call it first time when the hook was initialized.\n if (options?.initialCall) {\n reportScreen();\n }\n\n window.addEventListener('resize', reportScreen, { passive: true });\n\n return () => {\n window.removeEventListener('resize', reportScreen);\n };\n }, [callback, options?.initialCall]);\n}\n","import { useEffect, useLayoutEffect } from 'react';\n\nexport function useEffectOnce(callback: React.EffectCallback) {\n // eslint-disable-next-line react-hooks/exhaustive-deps\n useEffect(callback, []);\n}\n\nexport function useLayoutEffectOnce(callback: React.EffectCallback) {\n // eslint-disable-next-line react-hooks/exhaustive-deps\n useLayoutEffect(callback, []);\n}\n","import { type RefObject, useCallback, useLayoutEffect, useMemo } from 'react';\nimport { lenisInstance } from '..';\nimport { useOrbit } from './orbit';\n\ninterface HookOptions {\n /**\n * Hook will report when first initialized without waiting for scroll event to actually happens.\n */\n initialCall?: boolean;\n /**\n * Set an element to only call when the element is actually entering the viewport (with 25% `rootMargin`).\n */\n intersectOn?: RefObject<HTMLOrSVGElement | null>;\n}\n\nexport const scrollCallbackReason = {\n Resize: 'resize',\n Scroll: 'scroll',\n Initialize: 'initialize',\n} as const;\nexport type ScrollCallbackReason =\n (typeof scrollCallbackReason)[keyof typeof scrollCallbackReason];\n\ntype Callback = (latest: number, reason: ScrollCallbackReason) => void;\n\nexport function useLenisCallback(callback: Callback, options?: HookOptions) {\n const callbackWrapScroll = useCallback(\n () => callback(lenisInstance!.actualScroll, scrollCallbackReason.Scroll),\n [callback]\n );\n const callbackWrapResize = useCallback(\n () => callback(lenisInstance!.actualScroll, scrollCallbackReason.Resize),\n [callback]\n );\n\n const intersectOn = useMemo(\n () => options?.intersectOn,\n [options?.intersectOn]\n );\n const initialCall = useMemo(\n () => options?.initialCall,\n [options?.initialCall]\n );\n\n useOrbit({\n target: intersectOn as RefObject<HTMLElement | null> | undefined,\n events: {\n onIntersect(entry) {\n if (entry.isIntersecting) {\n lenisInstance!.on('scroll', callbackWrapScroll);\n window.addEventListener('resize', callbackWrapResize);\n } else {\n lenisInstance!.off('scroll', callbackWrapScroll);\n window.removeEventListener('resize', callbackWrapResize);\n }\n },\n },\n rootMargin: '50% 0px 50% 0px',\n });\n\n useLayoutEffect(() => {\n if (!intersectOn) {\n lenisInstance!.on('scroll', callbackWrapScroll);\n window.addEventListener('resize', callbackWrapResize);\n }\n\n if (initialCall) {\n callback(lenisInstance!.actualScroll, scrollCallbackReason.Initialize);\n }\n\n return () => {\n lenisInstance!.off('scroll', callbackWrapScroll);\n window.removeEventListener('resize', callbackWrapResize);\n };\n }, [\n callback,\n callbackWrapResize,\n callbackWrapScroll,\n initialCall,\n intersectOn,\n ]);\n}\n","import Lenis from 'lenis';\nimport { ReactNode } from 'react';\n\nexport let lenisInstance: Lenis | undefined = undefined;\n\nexport type BasicTunnelIn = ({ children }: { children: ReactNode }) => null;\nexport let Default3DTunnelIn: BasicTunnelIn | undefined = undefined;\n\nexport const weaverSetup = {\n setLenisInstance(instance: Lenis) {\n lenisInstance = instance;\n },\n set3DTunnel(tunnelIn: BasicTunnelIn) {\n Default3DTunnelIn = tunnelIn;\n },\n};\n","import { type RefObject, useLayoutEffect } from 'react';\n\n/**\n * A simple Orbit hook.\n *\n * @param target HTML element ref to attach to.\n * @param events Specify which events should the orbit tracks.\n */\nexport function useOrbit(options: {\n target?: RefObject<HTMLElement | null>;\n events: {\n onResize?: (entry: ResizeObserverEntry) => void;\n onIntersect?: (entry: IntersectionObserverEntry) => void;\n };\n rootMargin?: string;\n}) {\n const { onResize, onIntersect } = options.events;\n const { rootMargin = '25% 0px 25% 0px' } = options;\n\n useLayoutEffect(() => {\n if (!options.target) return;\n if (!options.target.current) return;\n\n let orbitResize = undefined;\n if (onResize) {\n orbitResize = new ResizeObserver((entries) => onResize(entries[0]));\n orbitResize.observe(options.target.current);\n }\n let orbitIntersect = undefined;\n if (onIntersect) {\n orbitIntersect = new IntersectionObserver(\n (entries) => onIntersect(entries[0]),\n { rootMargin }\n );\n orbitIntersect.observe(options.target.current);\n }\n\n return () => {\n orbitResize?.disconnect();\n orbitIntersect?.disconnect();\n };\n }, [onIntersect, onResize, rootMargin, options.target]);\n}\n","import { useId, useLayoutEffect } from 'react';\n\nexport interface MousePositionValues {\n x: number;\n y: number;\n}\n\ninterface MouseCallback {\n callback: (latest: MousePositionValues) => void;\n options: HookOptions;\n}\n\ninterface HookOptions {\n normalized?: boolean;\n}\n\ntype Callback = (latest: MousePositionValues) => void;\n\nclass MouseEventDistributor {\n private callbacks = new Map<string, MouseCallback>();\n private eventRegistered = false;\n\n constructor() {\n if (this.eventRegistered) return;\n\n window.addEventListener('pointermove', this.callbackLoop.bind(this), {\n passive: true,\n });\n\n this.eventRegistered = true;\n }\n\n addCallbackLoop(\n id: string,\n callback: (latest: MousePositionValues) => void,\n options: HookOptions\n ) {\n this.callbacks.set(id, { callback, options });\n }\n\n removeCallbackLoop(id: string) {\n this.callbacks.delete(id);\n }\n\n private processEvent(event: PointerEvent) {\n const mouse = {\n x: event.clientX,\n y: event.clientY,\n };\n const mouseNormalized = {\n x: mouse.x / (document.body.clientWidth / 2) - 1,\n y: mouse.y / (document.documentElement.clientHeight / 2) - 1,\n };\n\n return [mouse, mouseNormalized];\n }\n\n private callbackLoop(event: PointerEvent) {\n if (event.pointerType !== 'mouse') return;\n\n const callbacks = this.callbacks.entries();\n const [mouse, mouseNormalized] = this.processEvent(event);\n\n let inspecting = callbacks.next().value;\n while (inspecting) {\n if (inspecting[1].options.normalized) {\n inspecting[1].callback(mouseNormalized);\n } else {\n inspecting[1].callback(mouse);\n }\n\n inspecting = callbacks.next().value;\n }\n }\n}\n\nconst distributor = new MouseEventDistributor();\n\nexport function useMouseCallback(\n callback: Callback,\n options: HookOptions = {\n normalized: true,\n }\n) {\n const id = useId();\n\n useLayoutEffect(() => {\n distributor.addCallbackLoop(id, callback, options);\n\n return () => {\n distributor.removeCallbackLoop(id);\n };\n }, [callback, id, options]);\n}\n","import { useCallback } from 'react';\nimport { useNavigate } from 'react-router';\nimport { lenisInstance } from '..';\n\nexport function useNavigateAnchor(onNavigate?: () => void) {\n const navigate = useNavigate();\n\n return useCallback(\n (event: React.MouseEvent<HTMLAnchorElement, MouseEvent>) => {\n event.preventDefault();\n const href = event.currentTarget.getAttribute('href');\n if (href) {\n if (onNavigate) {\n onNavigate();\n }\n\n if (href !== window.location.pathname) {\n navigate(event.currentTarget.getAttribute('href') ?? '');\n } else {\n lenisInstance!.scrollTo(0, { duration: 2 });\n }\n }\n },\n [onNavigate, navigate]\n );\n}\n","import { useLocation } from 'react-router';\n\nexport function useRawParams(\n prefix: string,\n limit?: number\n): (string | undefined)[] {\n const { pathname } = useLocation();\n\n const prefixedPath = pathname.replace(new RegExp(prefix), '');\n if (prefixedPath === pathname) {\n return [];\n }\n\n return prefixedPath\n .split('/')\n .filter((param) => param !== '')\n .slice(limit);\n}\n","import { useCallback, useLayoutEffect } from 'react';\nimport { useLocation, useNavigate } from 'react-router';\n\nexport function useRouteNormalizer(options: { autoReplace: boolean }) {\n const { pathname } = useLocation();\n const navigate = useNavigate();\n\n const normalizer = useCallback(\n (input: string) => input.replace(/\\/+\\//g, () => '/'),\n []\n );\n\n useLayoutEffect(() => {\n const result = normalizer(pathname);\n if (options.autoReplace && result !== pathname) {\n window.location.replace(result);\n }\n }, [options.autoReplace, pathname, navigate, normalizer]);\n\n return {\n pathname,\n normalizer,\n };\n}\n","import { useCallback, useLayoutEffect, useState } from 'react';\n\nexport function useScreen() {\n const [width, setWidth] = useState(document.body.clientWidth);\n const [height, setHeight] = useState(document.documentElement.clientHeight);\n\n const setScreen = useCallback(() => {\n setWidth(document.body.clientWidth);\n setHeight(document.documentElement.clientHeight);\n }, []);\n\n useLayoutEffect(() => {\n window.addEventListener('resize', setScreen, { passive: true });\n\n return () => {\n window.removeEventListener('resize', setScreen);\n };\n }, [setScreen]);\n\n return { width: width, height: height };\n}\n","import { useThree } from '@react-three/fiber';\nimport { useCallback, useState } from 'react';\nimport { OrthographicCamera, PerspectiveCamera } from 'three';\nimport { useScreenCallback } from './screenCallback';\n\nexport function useViewport(\n customCamera?: OrthographicCamera | PerspectiveCamera\n) {\n const { viewport, camera } = useThree();\n\n const [width, setWidth] = useState(viewport.getCurrentViewport().width);\n const [height, setHeight] = useState(viewport.getCurrentViewport().height);\n\n const viewportUpdate = useCallback(() => {\n const actualViewport = viewport.getCurrentViewport(customCamera ?? camera);\n setWidth(actualViewport.width);\n setHeight(actualViewport.height);\n }, [camera, customCamera, viewport]);\n useScreenCallback(viewportUpdate);\n\n return { width: width, height: height };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,IAAAA,gBAAsC;;;ACAtC,mBAAgC;AASzB,SAAS,kBACd,UACA,SACA;AACA,oCAAgB,MAAM;AACpB,UAAM,eAAe,MACnB,SAAS;AAAA,MACP,OAAO,SAAS,KAAK;AAAA,MACrB,QAAQ,SAAS,gBAAgB;AAAA,IACnC,CAA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AW,EAAE,SAAS,KAAK,CAAC;AAE9D,WAAO,MAAM;AACX,aAAO,oBAAoB,UAAU,SAAS;AAAA,IAChD;AAAA,EACF,GAAG,CAAC,SAAS,CAAC;AAEd,SAAO,EAAE,OAAc,OAAe;AACxC;;;ACpBA,mBAAyB;AACzB,IAAAC,iBAAsC;AAI/B,SAAS,YACd,cACA;AACA,QAAM,EAAE,UAAU,OAAO,QAAI,uBAAS;AAEtC,QAAM,CAAC,OAAO,QAAQ,QAAI,yBAAS,SAAS,mBAAmB,EAAE,KAAK;AACtE,QAAM,CAAC,QAAQ,SAAS,QAAI,yBAAS,SAAS,mBAAmB,EAAE,MAAM;AAEzE,QAAM,qBAAiB,4BAAY,MAAM;AACvC,UAAM,iBAAiB,SAAS,mBAAmB,gBAAgB,MAAM;AACzE,aAAS,eAAe,KAAK;AAC7B,cAAU,eAAe,MAAM;AAAA,EACjC,GAAG,CAAC,QAAQ,cAAc,QAAQ,CAAC;AACnC,oBAAkB,cAAc;AAEhC,SAAO,EAAE,OAAc,OAAe;AACxC;","names":["import_react","import_react","import_react","import_react","import_react","import_react","import_react_router","import_react","import_react_router","import_react","import_react"]}
1
+ {"version":3,"sources":["../src/hooks/index.ts","../src/hooks/breakpoints.ts","../src/hooks/screenCallback.ts","../src/hooks/effectOnce.ts","../src/hooks/lenisCallback.ts","../src/setup.ts","../src/hooks/orbit.ts","../src/hooks/mouseCallback.ts","../src/hooks/navigateAnchor.ts","../src/hooks/rawParams.ts","../src/hooks/routeNormalizer.ts","../src/hooks/screen.ts","../src/hooks/viewport.ts"],"sourcesContent":["import { useBreakpoints } from './breakpoints';\nimport { useEffectOnce, useLayoutEffectOnce } from './effectOnce';\nimport { useLenisCallback } from './lenisCallback';\nimport { useMouseCallback } from './mouseCallback';\nimport { useNavigateAnchor } from './navigateAnchor';\nimport { useOrbit } from './orbit';\nimport { useRawParams } from './rawParams';\nimport { useRouteNormalizer } from './routeNormalizer';\nimport { useScreen } from './screen';\nimport { useScreenCallback } from './screenCallback';\nimport { useViewport } from './viewport';\n\nexport {\n useBreakpoints,\n useEffectOnce,\n useLayoutEffectOnce,\n useLenisCallback,\n useMouseCallback,\n useNavigateAnchor,\n useOrbit,\n useRawParams,\n useRouteNormalizer,\n useScreen,\n useScreenCallback,\n useViewport,\n};\n","import { useCallback, useState } from 'react';\nimport { useScreenCallback } from './screenCallback';\n\nexport function useBreakpoints(breakpoints?: number[] | null) {\n const getBreakpoint = useCallback(\n (width: number) => {\n const processingBreakpoints = !breakpoints\n ? [640, 768, 1024, 1280, 1536]\n : breakpoints;\n\n if (!processingBreakpoints) {\n throw Error(\"Uhhh... so you don't want a breakpoint? Just say it.\");\n }\n\n let result = processingBreakpoints!.length;\n for (let index = 0; index < processingBreakpoints!.length; index++) {\n if (width < processingBreakpoints![index]) {\n result = index;\n break;\n }\n }\n\n return result;\n },\n [breakpoints]\n );\n\n const [breakAt, setBreakAt] = useState<number>(\n getBreakpoint(document.body.clientWidth)\n );\n\n const breakpointCheck = useCallback(\n (latest: { width: number; height: number }) => {\n const result = getBreakpoint(latest.width);\n if (result !== breakAt) {\n setBreakAt(result);\n }\n },\n [breakAt, getBreakpoint]\n );\n useScreenCallback(breakpointCheck);\n\n return breakAt;\n}\n","import { useLayoutEffect } from 'react';\n\nexport interface ScreenCallbackValues {\n width: number;\n height: number;\n}\n\ntype Callback = (props: ScreenCallbackValues) => void;\n\nexport function useScreenCallback(\n callback: Callback,\n options?: { initialCall?: boolean }\n) {\n useLayoutEffect(() => {\n const reportScreen = () =>\n callback({\n width: document.body.clientWidth,\n height: document.documentElement.clientHeight,\n });\n\n // Call it first time when the hook was initialized.\n if (options?.initialCall) {\n reportScreen();\n }\n\n window.addEventListener('resize', reportScreen, { passive: true });\n\n return () => {\n window.removeEventListener('resize', reportScreen);\n };\n }, [callback, options?.initialCall]);\n}\n","import { useEffect, useLayoutEffect } from 'react';\n\nexport function useEffectOnce(callback: React.EffectCallback) {\n // eslint-disable-next-line react-hooks/exhaustive-deps\n useEffect(callback, []);\n}\n\nexport function useLayoutEffectOnce(callback: React.EffectCallback) {\n // eslint-disable-next-line react-hooks/exhaustive-deps\n useLayoutEffect(callback, []);\n}\n","import { type RefObject, useCallback, useLayoutEffect, useMemo } from 'react';\nimport { lenisInstance } from '../setup';\nimport { useOrbit } from './orbit';\n\ninterface HookOptions {\n /**\n * Hook will report when first initialized without waiting for scroll event to actually happens.\n */\n initialCall?: boolean;\n /**\n * Set an element to only call when the element is actually entering the viewport (with 25% `rootMargin`).\n */\n intersectOn?: RefObject<HTMLOrSVGElement | null>;\n}\n\nexport const scrollCallbackReason = {\n Resize: 'resize',\n Scroll: 'scroll',\n Initialize: 'initialize',\n} as const;\nexport type ScrollCallbackReason =\n (typeof scrollCallbackReason)[keyof typeof scrollCallbackReason];\n\ntype Callback = (latest: number, reason: ScrollCallbackReason) => void;\n\nexport function useLenisCallback(callback: Callback, options?: HookOptions) {\n const callbackWrapScroll = useCallback(\n () => callback(lenisInstance!.actualScroll, scrollCallbackReason.Scroll),\n [callback]\n );\n const callbackWrapResize = useCallback(\n () => callback(lenisInstance!.actualScroll, scrollCallbackReason.Resize),\n [callback]\n );\n\n const intersectOn = useMemo(\n () => options?.intersectOn,\n [options?.intersectOn]\n );\n const initialCall = useMemo(\n () => options?.initialCall,\n [options?.initialCall]\n );\n\n useOrbit({\n target: intersectOn as RefObject<HTMLElement | null> | undefined,\n events: {\n onIntersect(entry) {\n if (entry.isIntersecting) {\n lenisInstance!.on('scroll', callbackWrapScroll);\n window.addEventListener('resize', callbackWrapResize);\n } else {\n lenisInstance!.off('scroll', callbackWrapScroll);\n window.removeEventListener('resize', callbackWrapResize);\n }\n },\n },\n rootMargin: '50% 0px 50% 0px',\n });\n\n useLayoutEffect(() => {\n if (!intersectOn) {\n lenisInstance!.on('scroll', callbackWrapScroll);\n window.addEventListener('resize', callbackWrapResize);\n }\n\n if (initialCall) {\n callback(lenisInstance!.actualScroll, scrollCallbackReason.Initialize);\n }\n\n return () => {\n lenisInstance!.off('scroll', callbackWrapScroll);\n window.removeEventListener('resize', callbackWrapResize);\n };\n }, [\n callback,\n callbackWrapResize,\n callbackWrapScroll,\n initialCall,\n intersectOn,\n ]);\n}\n","import Lenis from 'lenis';\nimport { ReactNode } from 'react';\n\nexport let lenisInstance: Lenis | undefined = undefined;\n\nexport type BasicTunnelIn = ({ children }: { children: ReactNode }) => null;\nexport let Default3DTunnelIn: BasicTunnelIn | undefined = undefined;\n\nexport const weaverSetup = {\n setLenisInstance(instance: Lenis) {\n lenisInstance = instance;\n },\n set3DTunnel(tunnelIn: BasicTunnelIn) {\n Default3DTunnelIn = tunnelIn;\n },\n};\n","import { type RefObject, useLayoutEffect } from 'react';\n\n/**\n * A simple Orbit hook.\n *\n * @param target HTML element ref to attach to.\n * @param events Specify which events should the orbit tracks.\n */\nexport function useOrbit(options: {\n target?: RefObject<HTMLElement | null>;\n events: {\n onResize?: (entry: ResizeObserverEntry) => void;\n onIntersect?: (entry: IntersectionObserverEntry) => void;\n };\n rootMargin?: string;\n}) {\n const { onResize, onIntersect } = options.events;\n const { rootMargin = '25% 0px 25% 0px' } = options;\n\n useLayoutEffect(() => {\n if (!options.target) return;\n if (!options.target.current) return;\n\n let orbitResize = undefined;\n if (onResize) {\n orbitResize = new ResizeObserver((entries) => onResize(entries[0]));\n orbitResize.observe(options.target.current);\n }\n let orbitIntersect = undefined;\n if (onIntersect) {\n orbitIntersect = new IntersectionObserver(\n (entries) => onIntersect(entries[0]),\n { rootMargin }\n );\n orbitIntersect.observe(options.target.current);\n }\n\n return () => {\n orbitResize?.disconnect();\n orbitIntersect?.disconnect();\n };\n }, [onIntersect, onResize, rootMargin, options.target]);\n}\n","import { useId, useLayoutEffect } from 'react';\n\nexport interface MousePositionValues {\n x: number;\n y: number;\n}\n\ninterface MouseCallback {\n callback: (latest: MousePositionValues) => void;\n options: HookOptions;\n}\n\ninterface HookOptions {\n normalized?: boolean;\n}\n\ntype Callback = (latest: MousePositionValues) => void;\n\nclass MouseEventDistributor {\n private callbacks = new Map<string, MouseCallback>();\n private eventRegistered = false;\n\n constructor() {\n if (this.eventRegistered) return;\n\n window.addEventListener('pointermove', this.callbackLoop.bind(this), {\n passive: true,\n });\n\n this.eventRegistered = true;\n }\n\n addCallbackLoop(\n id: string,\n callback: (latest: MousePositionValues) => void,\n options: HookOptions\n ) {\n this.callbacks.set(id, { callback, options });\n }\n\n removeCallbackLoop(id: string) {\n this.callbacks.delete(id);\n }\n\n private processEvent(event: PointerEvent) {\n const mouse = {\n x: event.clientX,\n y: event.clientY,\n };\n const mouseNormalized = {\n x: mouse.x / (document.body.clientWidth / 2) - 1,\n y: mouse.y / (document.documentElement.clientHeight / 2) - 1,\n };\n\n return [mouse, mouseNormalized];\n }\n\n private callbackLoop(event: PointerEvent) {\n if (event.pointerType !== 'mouse') return;\n\n const callbacks = this.callbacks.entries();\n const [mouse, mouseNormalized] = this.processEvent(event);\n\n let inspecting = callbacks.next().value;\n while (inspecting) {\n if (inspecting[1].options.normalized) {\n inspecting[1].callback(mouseNormalized);\n } else {\n inspecting[1].callback(mouse);\n }\n\n inspecting = callbacks.next().value;\n }\n }\n}\n\nconst distributor = new MouseEventDistributor();\n\nexport function useMouseCallback(\n callback: Callback,\n options: HookOptions = {\n normalized: true,\n }\n) {\n const id = useId();\n\n useLayoutEffect(() => {\n distributor.addCallbackLoop(id, callback, options);\n\n return () => {\n distributor.removeCallbackLoop(id);\n };\n }, [callback, id, options]);\n}\n","import { useCallback } from 'react';\nimport { useNavigate } from 'react-router';\nimport { lenisInstance } from '../setup';\n\nexport function useNavigateAnchor(onNavigate?: () => void) {\n const navigate = useNavigate();\n\n return useCallback(\n (event: React.MouseEvent<HTMLAnchorElement, MouseEvent>) => {\n event.preventDefault();\n const href = event.currentTarget.getAttribute('href');\n if (href) {\n if (onNavigate) {\n onNavigate();\n }\n\n if (href !== window.location.pathname) {\n navigate(event.currentTarget.getAttribute('href') ?? '');\n } else {\n lenisInstance!.scrollTo(0, { duration: 2 });\n }\n }\n },\n [onNavigate, navigate]\n );\n}\n","import { useLocation } from 'react-router';\n\nexport function useRawParams(\n prefix: string,\n limit?: number\n): (string | undefined)[] {\n const { pathname } = useLocation();\n\n const prefixedPath = pathname.replace(new RegExp(prefix), '');\n if (prefixedPath === pathname) {\n return [];\n }\n\n return prefixedPath\n .split('/')\n .filter((param) => param !== '')\n .slice(limit);\n}\n","import { useCallback, useLayoutEffect } from 'react';\nimport { useLocation, useNavigate } from 'react-router';\n\nexport function useRouteNormalizer(options: { autoReplace: boolean }) {\n const { pathname } = useLocation();\n const navigate = useNavigate();\n\n const normalizer = useCallback(\n (input: string) => input.replace(/\\/+\\//g, () => '/'),\n []\n );\n\n useLayoutEffect(() => {\n const result = normalizer(pathname);\n if (options.autoReplace && result !== pathname) {\n window.location.replace(result);\n }\n }, [options.autoReplace, pathname, navigate, normalizer]);\n\n return {\n pathname,\n normalizer,\n };\n}\n","import { useCallback, useLayoutEffect, useState } from 'react';\n\nexport function useScreen() {\n const [width, setWidth] = useState(document.body.clientWidth);\n const [height, setHeight] = useState(document.documentElement.clientHeight);\n\n const setScreen = useCallback(() => {\n setWidth(document.body.clientWidth);\n setHeight(document.documentElement.clientHeight);\n }, []);\n\n useLayoutEffect(() => {\n window.addEventListener('resize', setScreen, { passive: true });\n\n return () => {\n window.removeEventListener('resize', setScreen);\n };\n }, [setScreen]);\n\n return { width: width, height: height };\n}\n","import { useThree } from '@react-three/fiber';\nimport { useCallback, useState } from 'react';\nimport { OrthographicCamera, PerspectiveCamera } from 'three';\nimport { useScreenCallback } from './screenCallback';\n\nexport function useViewport(\n customCamera?: OrthographicCamera | PerspectiveCamera\n) {\n const { viewport, camera } = useThree();\n\n const [width, setWidth] = useState(viewport.getCurrentViewport().width);\n const [height, setHeight] = useState(viewport.getCurrentViewport().height);\n\n const viewportUpdate = useCallback(() => {\n const actualViewport = viewport.getCurrentViewport(customCamera ?? camera);\n setWidth(actualViewport.width);\n setHeight(actualViewport.height);\n }, [camera, customC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ACL;AAAA,IACA;AAAA,EACF;AACF;;;ACvBA,IAAAC,gBAAuD;AAEhD,SAAS,YAAY;AAC1B,QAAM,CAAC,OAAO,QAAQ,QAAI,wBAAS,SAAS,KAAK,WAAW;AAC5D,QAAM,CAAC,QAAQ,SAAS,QAAI,wBAAS,SAAS,gBAAgB,YAAY;AAE1E,QAAM,gBAAY,2BAAY,MAAM;AAClC,aAAS,SAAS,KAAK,WAAW;AAClC,cAAU,SAAS,gBAAgB,YAAY;AAAA,EACjD,GAAG,CAAC,CAAC;AAEL,qCAAgB,MAAM;AACpB,WAAO,iBAAiB,UAAU,WAAW,EAAE,SAAS,KAAK,CAAC;AAE9D,WAAO,MAAM;AACX,aAAO,oBAAoB,UAAU,SAAS;AAAA,IAChD;AAAA,EACF,GAAG,CAAC,SAAS,CAAC;AAEd,SAAO,EAAE,OAAc,OAAe;AACxC;;;ACpBA,mBAAyB;AACzB,IAAAC,iBAAsC;AAI/B,SAAS,YACd,cACA;AACA,QAAM,EAAE,UAAU,OAAO,QAAI,uBAAS;AAEtC,QAAM,CAAC,OAAO,QAAQ,QAAI,yBAAS,SAAS,mBAAmB,EAAE,KAAK;AACtE,QAAM,CAAC,QAAQ,SAAS,QAAI,yBAAS,SAAS,mBAAmB,EAAE,MAAM;AAEzE,QAAM,qBAAiB,4BAAY,MAAM;AACvC,UAAM,iBAAiB,SAAS,mBAAmB,gBAAgB,MAAM;AACzE,aAAS,eAAe,KAAK;AAC7B,cAAU,eAAe,MAAM;AAAA,EACjC,GAAG,CAAC,QAAQ,cAAc,QAAQ,CAAC;AACnC,oBAAkB,cAAc;AAEhC,SAAO,EAAE,OAAc,OAAe;AACxC;","names":["import_react","import_react","import_react","import_react","import_react","import_react","import_react_router","import_react","import_react_router","import_react","import_react"]}
package/dist/hooks.mjs CHANGED
@@ -66,7 +66,7 @@ function useLayoutEffectOnce(callback) {
66
66
  // src/hooks/lenisCallback.ts
67
67
  import { useCallback as useCallback2, useLayoutEffect as useLayoutEffect4, useMemo } from "react";
68
68
 
69
- // src/index.ts
69
+ // src/setup.ts
70
70
  var lenisInstance = void 0;
71
71
 
72
72
  // src/hooks/orbit.ts
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/hooks/breakpoints.ts","../src/hooks/screenCallback.ts","../src/hooks/effectOnce.ts","../src/hooks/lenisCallback.ts","../src/index.ts","../src/hooks/orbit.ts","../src/hooks/mouseCallback.ts","../src/hooks/navigateAnchor.ts","../src/hooks/rawParams.ts","../src/hooks/routeNormalizer.ts","../src/hooks/screen.ts","../src/hooks/viewport.ts"],"sourcesContent":["import { useCallback, useState } from 'react';\nimport { useScreenCallback } from './screenCallback';\n\nexport function useBreakpoints(breakpoints?: number[] | null) {\n const getBreakpoint = useCallback(\n (width: number) => {\n const processingBreakpoints = !breakpoints\n ? [640, 768, 1024, 1280, 1536]\n : breakpoints;\n\n if (!processingBreakpoints) {\n throw Error(\"Uhhh... so you don't want a breakpoint? Just say it.\");\n }\n\n let result = processingBreakpoints!.length;\n for (let index = 0; index < processingBreakpoints!.length; index++) {\n if (width < processingBreakpoints![index]) {\n result = index;\n break;\n }\n }\n\n return result;\n },\n [breakpoints]\n );\n\n const [breakAt, setBreakAt] = useState<number>(\n getBreakpoint(document.body.clientWidth)\n );\n\n const breakpointCheck = useCallback(\n (latest: { width: number; height: number }) => {\n const result = getBreakpoint(latest.width);\n if (result !== breakAt) {\n setBreakAt(result);\n }\n },\n [breakAt, getBreakpoint]\n );\n useScreenCallback(breakpointCheck);\n\n return breakAt;\n}\n","import { useLayoutEffect } from 'react';\n\nexport interface ScreenCallbackValues {\n width: number;\n height: number;\n}\n\ntype Callback = (props: ScreenCallbackValues) => void;\n\nexport function useScreenCallback(\n callback: Callback,\n options?: { initialCall?: boolean }\n) {\n useLayoutEffect(() => {\n const reportScreen = () =>\n callback({\n width: document.body.clientWidth,\n height: document.documentElement.clientHeight,\n });\n\n // Call it first time when the hook was initialized.\n if (options?.initialCall) {\n reportScreen();\n }\n\n window.addEventListener('resize', reportScreen, { passive: true });\n\n return () => {\n window.removeEventListener('resize', reportScreen);\n };\n }, [callback, options?.initialCall]);\n}\n","import { useEffect, useLayoutEffect } from 'react';\n\nexport function useEffectOnce(callback: React.EffectCallback) {\n // eslint-disable-next-line react-hooks/exhaustive-deps\n useEffect(callback, []);\n}\n\nexport function useLayoutEffectOnce(callback: React.EffectCallback) {\n // eslint-disable-next-line react-hooks/exhaustive-deps\n useLayoutEffect(callback, []);\n}\n","import { type RefObject, useCallback, useLayoutEffect, useMemo } from 'react';\nimport { lenisInstance } from '..';\nimport { useOrbit } from './orbit';\n\ninterface HookOptions {\n /**\n * Hook will report when first initialized without waiting for scroll event to actually happens.\n */\n initialCall?: boolean;\n /**\n * Set an element to only call when the element is actually entering the viewport (with 25% `rootMargin`).\n */\n intersectOn?: RefObject<HTMLOrSVGElement | null>;\n}\n\nexport const scrollCallbackReason = {\n Resize: 'resize',\n Scroll: 'scroll',\n Initialize: 'initialize',\n} as const;\nexport type ScrollCallbackReason =\n (typeof scrollCallbackReason)[keyof typeof scrollCallbackReason];\n\ntype Callback = (latest: number, reason: ScrollCallbackReason) => void;\n\nexport function useLenisCallback(callback: Callback, options?: HookOptions) {\n const callbackWrapScroll = useCallback(\n () => callback(lenisInstance!.actualScroll, scrollCallbackReason.Scroll),\n [callback]\n );\n const callbackWrapResize = useCallback(\n () => callback(lenisInstance!.actualScroll, scrollCallbackReason.Resize),\n [callback]\n );\n\n const intersectOn = useMemo(\n () => options?.intersectOn,\n [options?.intersectOn]\n );\n const initialCall = useMemo(\n () => options?.initialCall,\n [options?.initialCall]\n );\n\n useOrbit({\n target: intersectOn as RefObject<HTMLElement | null> | undefined,\n events: {\n onIntersect(entry) {\n if (entry.isIntersecting) {\n lenisInstance!.on('scroll', callbackWrapScroll);\n window.addEventListener('resize', callbackWrapResize);\n } else {\n lenisInstance!.off('scroll', callbackWrapScroll);\n window.removeEventListener('resize', callbackWrapResize);\n }\n },\n },\n rootMargin: '50% 0px 50% 0px',\n });\n\n useLayoutEffect(() => {\n if (!intersectOn) {\n lenisInstance!.on('scroll', callbackWrapScroll);\n window.addEventListener('resize', callbackWrapResize);\n }\n\n if (initialCall) {\n callback(lenisInstance!.actualScroll, scrollCallbackReason.Initialize);\n }\n\n return () => {\n lenisInstance!.off('scroll', callbackWrapScroll);\n window.removeEventListener('resize', callbackWrapResize);\n };\n }, [\n callback,\n callbackWrapResize,\n callbackWrapScroll,\n initialCall,\n intersectOn,\n ]);\n}\n","import Lenis from 'lenis';\nimport { ReactNode } from 'react';\n\nexport let lenisInstance: Lenis | undefined = undefined;\n\nexport type BasicTunnelIn = ({ children }: { children: ReactNode }) => null;\nexport let Default3DTunnelIn: BasicTunnelIn | undefined = undefined;\n\nexport const weaverSetup = {\n setLenisInstance(instance: Lenis) {\n lenisInstance = instance;\n },\n set3DTunnel(tunnelIn: BasicTunnelIn) {\n Default3DTunnelIn = tunnelIn;\n },\n};\n","import { type RefObject, useLayoutEffect } from 'react';\n\n/**\n * A simple Orbit hook.\n *\n * @param target HTML element ref to attach to.\n * @param events Specify which events should the orbit tracks.\n */\nexport function useOrbit(options: {\n target?: RefObject<HTMLElement | null>;\n events: {\n onResize?: (entry: ResizeObserverEntry) => void;\n onIntersect?: (entry: IntersectionObserverEntry) => void;\n };\n rootMargin?: string;\n}) {\n const { onResize, onIntersect } = options.events;\n const { rootMargin = '25% 0px 25% 0px' } = options;\n\n useLayoutEffect(() => {\n if (!options.target) return;\n if (!options.target.current) return;\n\n let orbitResize = undefined;\n if (onResize) {\n orbitResize = new ResizeObserver((entries) => onResize(entries[0]));\n orbitResize.observe(options.target.current);\n }\n let orbitIntersect = undefined;\n if (onIntersect) {\n orbitIntersect = new IntersectionObserver(\n (entries) => onIntersect(entries[0]),\n { rootMargin }\n );\n orbitIntersect.observe(options.target.current);\n }\n\n return () => {\n orbitResize?.disconnect();\n orbitIntersect?.disconnect();\n };\n }, [onIntersect, onResize, rootMargin, options.target]);\n}\n","import { useId, useLayoutEffect } from 'react';\n\nexport interface MousePositionValues {\n x: number;\n y: number;\n}\n\ninterface MouseCallback {\n callback: (latest: MousePositionValues) => void;\n options: HookOptions;\n}\n\ninterface HookOptions {\n normalized?: boolean;\n}\n\ntype Callback = (latest: MousePositionValues) => void;\n\nclass MouseEventDistributor {\n private callbacks = new Map<string, MouseCallback>();\n private eventRegistered = false;\n\n constructor() {\n if (this.eventRegistered) return;\n\n window.addEventListener('pointermove', this.callbackLoop.bind(this), {\n passive: true,\n });\n\n this.eventRegistered = true;\n }\n\n addCallbackLoop(\n id: string,\n callback: (latest: MousePositionValues) => void,\n options: HookOptions\n ) {\n this.callbacks.set(id, { callback, options });\n }\n\n removeCallbackLoop(id: string) {\n this.callbacks.delete(id);\n }\n\n private processEvent(event: PointerEvent) {\n const mouse = {\n x: event.clientX,\n y: event.clientY,\n };\n const mouseNormalized = {\n x: mouse.x / (document.body.clientWidth / 2) - 1,\n y: mouse.y / (document.documentElement.clientHeight / 2) - 1,\n };\n\n return [mouse, mouseNormalized];\n }\n\n private callbackLoop(event: PointerEvent) {\n if (event.pointerType !== 'mouse') return;\n\n const callbacks = this.callbacks.entries();\n const [mouse, mouseNormalized] = this.processEvent(event);\n\n let inspecting = callbacks.next().value;\n while (inspecting) {\n if (inspecting[1].options.normalized) {\n inspecting[1].callback(mouseNormalized);\n } else {\n inspecting[1].callback(mouse);\n }\n\n inspecting = callbacks.next().value;\n }\n }\n}\n\nconst distributor = new MouseEventDistributor();\n\nexport function useMouseCallback(\n callback: Callback,\n options: HookOptions = {\n normalized: true,\n }\n) {\n const id = useId();\n\n useLayoutEffect(() => {\n distributor.addCallbackLoop(id, callback, options);\n\n return () => {\n distributor.removeCallbackLoop(id);\n };\n }, [callback, id, options]);\n}\n","import { useCallback } from 'react';\nimport { useNavigate } from 'react-router';\nimport { lenisInstance } from '..';\n\nexport function useNavigateAnchor(onNavigate?: () => void) {\n const navigate = useNavigate();\n\n return useCallback(\n (event: React.MouseEvent<HTMLAnchorElement, MouseEvent>) => {\n event.preventDefault();\n const href = event.currentTarget.getAttribute('href');\n if (href) {\n if (onNavigate) {\n onNavigate();\n }\n\n if (href !== window.location.pathname) {\n navigate(event.currentTarget.getAttribute('href') ?? '');\n } else {\n lenisInstance!.scrollTo(0, { duration: 2 });\n }\n }\n },\n [onNavigate, navigate]\n );\n}\n","import { useLocation } from 'react-router';\n\nexport function useRawParams(\n prefix: string,\n limit?: number\n): (string | undefined)[] {\n const { pathname } = useLocation();\n\n const prefixedPath = pathname.replace(new RegExp(prefix), '');\n if (prefixedPath === pathname) {\n return [];\n }\n\n return prefixedPath\n .split('/')\n .filter((param) => param !== '')\n .slice(limit);\n}\n","import { useCallback, useLayoutEffect } from 'react';\nimport { useLocation, useNavigate } from 'react-router';\n\nexport function useRouteNormalizer(options: { autoReplace: boolean }) {\n const { pathname } = useLocation();\n const navigate = useNavigate();\n\n const normalizer = useCallback(\n (input: string) => input.replace(/\\/+\\//g, () => '/'),\n []\n );\n\n useLayoutEffect(() => {\n const result = normalizer(pathname);\n if (options.autoReplace && result !== pathname) {\n window.location.replace(result);\n }\n }, [options.autoReplace, pathname, navigate, normalizer]);\n\n return {\n pathname,\n normalizer,\n };\n}\n","import { useCallback, useLayoutEffect, useState } from 'react';\n\nexport function useScreen() {\n const [width, setWidth] = useState(document.body.clientWidth);\n const [height, setHeight] = useState(document.documentElement.clientHeight);\n\n const setScreen = useCallback(() => {\n setWidth(document.body.clientWidth);\n setHeight(document.documentElement.clientHeight);\n }, []);\n\n useLayoutEffect(() => {\n window.addEventListener('resize', setScreen, { passive: true });\n\n return () => {\n window.removeEventListener('resize', setScreen);\n };\n }, [setScreen]);\n\n return { width: width, height: height };\n}\n","import { useThree } from '@react-three/fiber';\nimport { useCallback, useState } from 'react';\nimport { OrthographicCamera, PerspectiveCamera } from 'three';\nimport { useScreenCallback } from './screenCallback';\n\nexport function useViewport(\n customCamera?: OrthographicCamera | PerspectiveCamera\n) {\n const { viewport, camera } = useThree();\n\n const [width, setWidth] = useState(viewport.getCurrentViewport().width);\n const [height, setHeight] = useState(viewport.getCurrentViewport().height);\n\n const viewportUpdate = useCallback(() => {\n const actualViewport = viewport.getCurrentViewport(customCamera ?? camera);\n setWidth(actualViewport.width);\n setHeight(actualViewport.height);\n }, [camera, customCamera, viewport]);\n useScreenCallback(viewportUpdate);\n\n return { width: width, height: height };\n}\n"],"mappings":";AAAA,SAAS,aAAa,gBAAgB;;;ACAtC,SAAS,uBAAuB;AASzB,SAAS,kBACd,UACA,SACA;AACA,kBAAgB,MAAM;AACpB,UAAM,eAAe,MACnB,SAAS;AAAA,MACP,OAAO,SAAS,KAAK;AAAA,MACrB,QAAQ,SAAS,gBAAgB;AAAA,IACnC,CAAC;AAGH,QAAI,SAAS,aAAa;AACxB,mBAAa;AAAA,IACf;AAEA,WAAO,iBAAiB,UAAU,cAAc,EAAE,SAAS,KAAK,CAAC;AAEjE,WAAO,MAAM;AACX,aAAO,oBAAoB,UAAU,YAAY;AAAA,IACnD;AAAA,EACF,GAAG,CAAC,UAAU,SAAS,WAAW,CAAC;AACrC;;;AD5BO,SAAS,eAAe,aAA+B;AAC5D,QAAM,gBAAgB;AAAA,IACpB,CAAC,UAAkB;AACjB,YAAM,wBAAwB,CAAC,cAC3B,CAAC,KAAK,KAAK,MAAM,MAAM,IAAI,IAC3B;AAEJ,UAAI,CAAC,uBAAuB;AAC1B,cAAM,MAAM,sDAAsD;AAAA,MACpE;AAEA,UAAI,SAAS,sBAAuB;AACpC,eAAS,QAAQ,GAAG,QAAQ,sBAAuB,QAAQ,SAAS;AAClE,YAAI,QAAQ,sBAAuB,KAAK,GAAG;AACzC,mBAAS;AACT;AAAA,QACF;AAAA,MACF;AAEA,aAAO;AAAA,IACT;AAAA,IACA,CAAC,WAAW;AAAA,EACd;AAEA,QAAM,CAAC,SAAS,UAAU,IAAI;AAAA,IAC5B,cAAc,SAAS,KAAK,WAAW;AAAA,EACzC;AAEA,QAAM,kBAAkB;AAAA,IACtB,CAAC,WAA8C;AA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AQ,CAAC;AACnC,oBAAkB,cAAc;AAEhC,SAAO,EAAE,OAAc,OAAe;AACxC;","names":["useLayoutEffect","useCallback","useLayoutEffect","useLayoutEffect","useCallback","useLayoutEffect","useLayoutEffect","useCallback","useCallback","useCallback","useLayoutEffect","useLocation","useNavigate","useCallback","useLayoutEffect","useState","useCallback","useState","useState","useCallback"]}
1
+ {"version":3,"sources":["../src/hooks/breakpoints.ts","../src/hooks/screenCallback.ts","../src/hooks/effectOnce.ts","../src/hooks/lenisCallback.ts","../src/setup.ts","../src/hooks/orbit.ts","../src/hooks/mouseCallback.ts","../src/hooks/navigateAnchor.ts","../src/hooks/rawParams.ts","../src/hooks/routeNormalizer.ts","../src/hooks/screen.ts","../src/hooks/viewport.ts"],"sourcesContent":["import { useCallback, useState } from 'react';\nimport { useScreenCallback } from './screenCallback';\n\nexport function useBreakpoints(breakpoints?: number[] | null) {\n const getBreakpoint = useCallback(\n (width: number) => {\n const processingBreakpoints = !breakpoints\n ? [640, 768, 1024, 1280, 1536]\n : breakpoints;\n\n if (!processingBreakpoints) {\n throw Error(\"Uhhh... so you don't want a breakpoint? Just say it.\");\n }\n\n let result = processingBreakpoints!.length;\n for (let index = 0; index < processingBreakpoints!.length; index++) {\n if (width < processingBreakpoints![index]) {\n result = index;\n break;\n }\n }\n\n return result;\n },\n [breakpoints]\n );\n\n const [breakAt, setBreakAt] = useState<number>(\n getBreakpoint(document.body.clientWidth)\n );\n\n const breakpointCheck = useCallback(\n (latest: { width: number; height: number }) => {\n const result = getBreakpoint(latest.width);\n if (result !== breakAt) {\n setBreakAt(result);\n }\n },\n [breakAt, getBreakpoint]\n );\n useScreenCallback(breakpointCheck);\n\n return breakAt;\n}\n","import { useLayoutEffect } from 'react';\n\nexport interface ScreenCallbackValues {\n width: number;\n height: number;\n}\n\ntype Callback = (props: ScreenCallbackValues) => void;\n\nexport function useScreenCallback(\n callback: Callback,\n options?: { initialCall?: boolean }\n) {\n useLayoutEffect(() => {\n const reportScreen = () =>\n callback({\n width: document.body.clientWidth,\n height: document.documentElement.clientHeight,\n });\n\n // Call it first time when the hook was initialized.\n if (options?.initialCall) {\n reportScreen();\n }\n\n window.addEventListener('resize', reportScreen, { passive: true });\n\n return () => {\n window.removeEventListener('resize', reportScreen);\n };\n }, [callback, options?.initialCall]);\n}\n","import { useEffect, useLayoutEffect } from 'react';\n\nexport function useEffectOnce(callback: React.EffectCallback) {\n // eslint-disable-next-line react-hooks/exhaustive-deps\n useEffect(callback, []);\n}\n\nexport function useLayoutEffectOnce(callback: React.EffectCallback) {\n // eslint-disable-next-line react-hooks/exhaustive-deps\n useLayoutEffect(callback, []);\n}\n","import { type RefObject, useCallback, useLayoutEffect, useMemo } from 'react';\nimport { lenisInstance } from '../setup';\nimport { useOrbit } from './orbit';\n\ninterface HookOptions {\n /**\n * Hook will report when first initialized without waiting for scroll event to actually happens.\n */\n initialCall?: boolean;\n /**\n * Set an element to only call when the element is actually entering the viewport (with 25% `rootMargin`).\n */\n intersectOn?: RefObject<HTMLOrSVGElement | null>;\n}\n\nexport const scrollCallbackReason = {\n Resize: 'resize',\n Scroll: 'scroll',\n Initialize: 'initialize',\n} as const;\nexport type ScrollCallbackReason =\n (typeof scrollCallbackReason)[keyof typeof scrollCallbackReason];\n\ntype Callback = (latest: number, reason: ScrollCallbackReason) => void;\n\nexport function useLenisCallback(callback: Callback, options?: HookOptions) {\n const callbackWrapScroll = useCallback(\n () => callback(lenisInstance!.actualScroll, scrollCallbackReason.Scroll),\n [callback]\n );\n const callbackWrapResize = useCallback(\n () => callback(lenisInstance!.actualScroll, scrollCallbackReason.Resize),\n [callback]\n );\n\n const intersectOn = useMemo(\n () => options?.intersectOn,\n [options?.intersectOn]\n );\n const initialCall = useMemo(\n () => options?.initialCall,\n [options?.initialCall]\n );\n\n useOrbit({\n target: intersectOn as RefObject<HTMLElement | null> | undefined,\n events: {\n onIntersect(entry) {\n if (entry.isIntersecting) {\n lenisInstance!.on('scroll', callbackWrapScroll);\n window.addEventListener('resize', callbackWrapResize);\n } else {\n lenisInstance!.off('scroll', callbackWrapScroll);\n window.removeEventListener('resize', callbackWrapResize);\n }\n },\n },\n rootMargin: '50% 0px 50% 0px',\n });\n\n useLayoutEffect(() => {\n if (!intersectOn) {\n lenisInstance!.on('scroll', callbackWrapScroll);\n window.addEventListener('resize', callbackWrapResize);\n }\n\n if (initialCall) {\n callback(lenisInstance!.actualScroll, scrollCallbackReason.Initialize);\n }\n\n return () => {\n lenisInstance!.off('scroll', callbackWrapScroll);\n window.removeEventListener('resize', callbackWrapResize);\n };\n }, [\n callback,\n callbackWrapResize,\n callbackWrapScroll,\n initialCall,\n intersectOn,\n ]);\n}\n","import Lenis from 'lenis';\nimport { ReactNode } from 'react';\n\nexport let lenisInstance: Lenis | undefined = undefined;\n\nexport type BasicTunnelIn = ({ children }: { children: ReactNode }) => null;\nexport let Default3DTunnelIn: BasicTunnelIn | undefined = undefined;\n\nexport const weaverSetup = {\n setLenisInstance(instance: Lenis) {\n lenisInstance = instance;\n },\n set3DTunnel(tunnelIn: BasicTunnelIn) {\n Default3DTunnelIn = tunnelIn;\n },\n};\n","import { type RefObject, useLayoutEffect } from 'react';\n\n/**\n * A simple Orbit hook.\n *\n * @param target HTML element ref to attach to.\n * @param events Specify which events should the orbit tracks.\n */\nexport function useOrbit(options: {\n target?: RefObject<HTMLElement | null>;\n events: {\n onResize?: (entry: ResizeObserverEntry) => void;\n onIntersect?: (entry: IntersectionObserverEntry) => void;\n };\n rootMargin?: string;\n}) {\n const { onResize, onIntersect } = options.events;\n const { rootMargin = '25% 0px 25% 0px' } = options;\n\n useLayoutEffect(() => {\n if (!options.target) return;\n if (!options.target.current) return;\n\n let orbitResize = undefined;\n if (onResize) {\n orbitResize = new ResizeObserver((entries) => onResize(entries[0]));\n orbitResize.observe(options.target.current);\n }\n let orbitIntersect = undefined;\n if (onIntersect) {\n orbitIntersect = new IntersectionObserver(\n (entries) => onIntersect(entries[0]),\n { rootMargin }\n );\n orbitIntersect.observe(options.target.current);\n }\n\n return () => {\n orbitResize?.disconnect();\n orbitIntersect?.disconnect();\n };\n }, [onIntersect, onResize, rootMargin, options.target]);\n}\n","import { useId, useLayoutEffect } from 'react';\n\nexport interface MousePositionValues {\n x: number;\n y: number;\n}\n\ninterface MouseCallback {\n callback: (latest: MousePositionValues) => void;\n options: HookOptions;\n}\n\ninterface HookOptions {\n normalized?: boolean;\n}\n\ntype Callback = (latest: MousePositionValues) => void;\n\nclass MouseEventDistributor {\n private callbacks = new Map<string, MouseCallback>();\n private eventRegistered = false;\n\n constructor() {\n if (this.eventRegistered) return;\n\n window.addEventListener('pointermove', this.callbackLoop.bind(this), {\n passive: true,\n });\n\n this.eventRegistered = true;\n }\n\n addCallbackLoop(\n id: string,\n callback: (latest: MousePositionValues) => void,\n options: HookOptions\n ) {\n this.callbacks.set(id, { callback, options });\n }\n\n removeCallbackLoop(id: string) {\n this.callbacks.delete(id);\n }\n\n private processEvent(event: PointerEvent) {\n const mouse = {\n x: event.clientX,\n y: event.clientY,\n };\n const mouseNormalized = {\n x: mouse.x / (document.body.clientWidth / 2) - 1,\n y: mouse.y / (document.documentElement.clientHeight / 2) - 1,\n };\n\n return [mouse, mouseNormalized];\n }\n\n private callbackLoop(event: PointerEvent) {\n if (event.pointerType !== 'mouse') return;\n\n const callbacks = this.callbacks.entries();\n const [mouse, mouseNormalized] = this.processEvent(event);\n\n let inspecting = callbacks.next().value;\n while (inspecting) {\n if (inspecting[1].options.normalized) {\n inspecting[1].callback(mouseNormalized);\n } else {\n inspecting[1].callback(mouse);\n }\n\n inspecting = callbacks.next().value;\n }\n }\n}\n\nconst distributor = new MouseEventDistributor();\n\nexport function useMouseCallback(\n callback: Callback,\n options: HookOptions = {\n normalized: true,\n }\n) {\n const id = useId();\n\n useLayoutEffect(() => {\n distributor.addCallbackLoop(id, callback, options);\n\n return () => {\n distributor.removeCallbackLoop(id);\n };\n }, [callback, id, options]);\n}\n","import { useCallback } from 'react';\nimport { useNavigate } from 'react-router';\nimport { lenisInstance } from '../setup';\n\nexport function useNavigateAnchor(onNavigate?: () => void) {\n const navigate = useNavigate();\n\n return useCallback(\n (event: React.MouseEvent<HTMLAnchorElement, MouseEvent>) => {\n event.preventDefault();\n const href = event.currentTarget.getAttribute('href');\n if (href) {\n if (onNavigate) {\n onNavigate();\n }\n\n if (href !== window.location.pathname) {\n navigate(event.currentTarget.getAttribute('href') ?? '');\n } else {\n lenisInstance!.scrollTo(0, { duration: 2 });\n }\n }\n },\n [onNavigate, navigate]\n );\n}\n","import { useLocation } from 'react-router';\n\nexport function useRawParams(\n prefix: string,\n limit?: number\n): (string | undefined)[] {\n const { pathname } = useLocation();\n\n const prefixedPath = pathname.replace(new RegExp(prefix), '');\n if (prefixedPath === pathname) {\n return [];\n }\n\n return prefixedPath\n .split('/')\n .filter((param) => param !== '')\n .slice(limit);\n}\n","import { useCallback, useLayoutEffect } from 'react';\nimport { useLocation, useNavigate } from 'react-router';\n\nexport function useRouteNormalizer(options: { autoReplace: boolean }) {\n const { pathname } = useLocation();\n const navigate = useNavigate();\n\n const normalizer = useCallback(\n (input: string) => input.replace(/\\/+\\//g, () => '/'),\n []\n );\n\n useLayoutEffect(() => {\n const result = normalizer(pathname);\n if (options.autoReplace && result !== pathname) {\n window.location.replace(result);\n }\n }, [options.autoReplace, pathname, navigate, normalizer]);\n\n return {\n pathname,\n normalizer,\n };\n}\n","import { useCallback, useLayoutEffect, useState } from 'react';\n\nexport function useScreen() {\n const [width, setWidth] = useState(document.body.clientWidth);\n const [height, setHeight] = useState(document.documentElement.clientHeight);\n\n const setScreen = useCallback(() => {\n setWidth(document.body.clientWidth);\n setHeight(document.documentElement.clientHeight);\n }, []);\n\n useLayoutEffect(() => {\n window.addEventListener('resize', setScreen, { passive: true });\n\n return () => {\n window.removeEventListener('resize', setScreen);\n };\n }, [setScreen]);\n\n return { width: width, height: height };\n}\n","import { useThree } from '@react-three/fiber';\nimport { useCallback, useState } from 'react';\nimport { OrthographicCamera, PerspectiveCamera } from 'three';\nimport { useScreenCallback } from './screenCallback';\n\nexport function useViewport(\n customCamera?: OrthographicCamera | PerspectiveCamera\n) {\n const { viewport, camera } = useThree();\n\n const [width, setWidth] = useState(viewport.getCurrentViewport().width);\n const [height, setHeight] = useState(viewport.getCurrentViewport().height);\n\n const viewportUpdate = useCallback(() => {\n const actualViewport = viewport.getCurrentViewport(customCamera ?? camera);\n setWidth(actualViewport.width);\n setHeight(actualViewport.height);\n }, [camera, customCamera, viewport]);\n useScreenCallback(viewportUpdate);\n\n return { width: width, height: height };\n}\n"],"mappings":";AAAA,SAAS,aAAa,gBAAgB;;;ACAtC,SAAS,uBAAuB;AASzB,SAAS,kBACd,UACA,SACA;AACA,kBAAgB,MAAM;AACpB,UAAM,eAAe,MACnB,SAAS;AAAA,MACP,OAAO,SAAS,KAAK;AAAA,MACrB,QAAQ,SAAS,gBAAgB;AAAA,IACnC,CAAC;AAGH,QAAI,SAAS,aAAa;AACxB,mBAAa;AAAA,IACf;AAEA,WAAO,iBAAiB,UAAU,cAAc,EAAE,SAAS,KAAK,CAAC;AAEjE,WAAO,MAAM;AACX,aAAO,oBAAoB,UAAU,YAAY;AAAA,IACnD;AAAA,EACF,GAAG,CAAC,UAAU,SAAS,WAAW,CAAC;AACrC;;;AD5BO,SAAS,eAAe,aAA+B;AAC5D,QAAM,gBAAgB;AAAA,IACpB,CAAC,UAAkB;AACjB,YAAM,wBAAwB,CAAC,cAC3B,CAAC,KAAK,KAAK,MAAM,MAAM,IAAI,IAC3B;AAEJ,UAAI,CAAC,uBAAuB;AAC1B,cAAM,MAAM,sDAAsD;AAAA,MACpE;AAEA,UAAI,SAAS,sBAAuB;AACpC,eAAS,QAAQ,GAAG,QAAQ,sBAAuB,QAAQ,SAAS;AAClE,YAAI,QAAQ,sBAAuB,KAAK,GAAG;AACzC,mBAAS;AACT;AAAA,QACF;AAAA,MACF;AAEA,aAAO;AAAA,IACT;AAAA,IACA,CAAC,WAAW;AAAA,EACd;AAEA,QAAM,CA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,SAAS,mBAAmB,gBAAgB,MAAM;AACzE,aAAS,eAAe,KAAK;AAC7B,cAAU,eAAe,MAAM;AAAA,EACjC,GAAG,CAAC,QAAQ,cAAc,QAAQ,CAAC;AACnC,oBAAkB,cAAc;AAEhC,SAAO,EAAE,OAAc,OAAe;AACxC;","names":["useLayoutEffect","useCallback","useLayoutEffect","useLayoutEffect","useCallback","useLayoutEffect","useLayoutEffect","useCallback","useCallback","useCallback","useLayoutEffect","useLocation","useNavigate","useCallback","useLayoutEffect","useState","useCallback","useState","useState","useCallback"]}
@@ -0,0 +1,12 @@
1
+ import Lenis from 'lenis';
2
+ import { ReactNode } from 'react';
3
+
4
+ type BasicTunnelIn = ({ children }: {
5
+ children: ReactNode;
6
+ }) => null;
7
+ declare const weaverSetup: {
8
+ setLenisInstance(instance: Lenis): void;
9
+ set3DTunnel(tunnelIn: BasicTunnelIn): void;
10
+ };
11
+
12
+ export { type BasicTunnelIn as B, weaverSetup as w };
@@ -0,0 +1,12 @@
1
+ import Lenis from 'lenis';
2
+ import { ReactNode } from 'react';
3
+
4
+ type BasicTunnelIn = ({ children }: {
5
+ children: ReactNode;
6
+ }) => null;
7
+ declare const weaverSetup: {
8
+ setLenisInstance(instance: Lenis): void;
9
+ set3DTunnel(tunnelIn: BasicTunnelIn): void;
10
+ };
11
+
12
+ export { type BasicTunnelIn as B, weaverSetup as w };
package/dist/index.d.mts CHANGED
@@ -1,14 +1,3 @@
1
- import Lenis from 'lenis';
2
- import { ReactNode } from 'react';
3
-
4
- declare let lenisInstance: Lenis | undefined;
5
- type BasicTunnelIn = ({ children }: {
6
- children: ReactNode;
7
- }) => null;
8
- declare let Default3DTunnelIn: BasicTunnelIn | undefined;
9
- declare const weaverSetup: {
10
- setLenisInstance(instance: Lenis): void;
11
- set3DTunnel(tunnelIn: BasicTunnelIn): void;
12
- };
13
-
14
- export { type BasicTunnelIn, Default3DTunnelIn, lenisInstance, weaverSetup };
1
+ export { w as weaverSetup } from './index-BRbPCByN.mjs';
2
+ import 'lenis';
3
+ import 'react';
package/dist/index.d.ts CHANGED
@@ -1,14 +1,3 @@
1
- import Lenis from 'lenis';
2
- import { ReactNode } from 'react';
3
-
4
- declare let lenisInstance: Lenis | undefined;
5
- type BasicTunnelIn = ({ children }: {
6
- children: ReactNode;
7
- }) => null;
8
- declare let Default3DTunnelIn: BasicTunnelIn | undefined;
9
- declare const weaverSetup: {
10
- setLenisInstance(instance: Lenis): void;
11
- set3DTunnel(tunnelIn: BasicTunnelIn): void;
12
- };
13
-
14
- export { type BasicTunnelIn, Default3DTunnelIn, lenisInstance, weaverSetup };
1
+ export { w as weaverSetup } from './index-BRbPCByN.js';
2
+ import 'lenis';
3
+ import 'react';
package/dist/index.js CHANGED
@@ -20,11 +20,11 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/index.ts
21
21
  var src_exports = {};
22
22
  __export(src_exports, {
23
- Default3DTunnelIn: () => Default3DTunnelIn,
24
- lenisInstance: () => lenisInstance,
25
23
  weaverSetup: () => weaverSetup
26
24
  });
27
25
  module.exports = __toCommonJS(src_exports);
26
+
27
+ // src/setup.ts
28
28
  var lenisInstance = void 0;
29
29
  var Default3DTunnelIn = void 0;
30
30
  var weaverSetup = {
@@ -37,8 +37,6 @@ var weaverSetup = {
37
37
  };
38
38
  // Annotate the CommonJS export names for ESM import in node:
39
39
  0 && (module.exports = {
40
- Default3DTunnelIn,
41
- lenisInstance,
42
40
  weaverSetup
43
41
  });
44
42
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import Lenis from 'lenis';\nimport { ReactNode } from 'react';\n\nexport let lenisInstance: Lenis | undefined = undefined;\n\nexport type BasicTunnelIn = ({ children }: { children: ReactNode }) => null;\nexport let Default3DTunnelIn: BasicTunnelIn | undefined = undefined;\n\nexport const weaverSetup = {\n setLenisInstance(instance: Lenis) {\n lenisInstance = instance;\n },\n set3DTunnel(tunnelIn: BasicTunnelIn) {\n Default3DTunnelIn = tunnelIn;\n },\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGO,IAAI,gBAAmC;AAGvC,IAAI,oBAA+C;AAEnD,IAAM,cAAc;AAAA,EACzB,iBAAiB,UAAiB;AAChC,oBAAgB;AAAA,EAClB;AAAA,EACA,YAAY,UAAyB;AACnC,wBAAoB;AAAA,EACtB;AACF;","names":[]}
1
+ {"version":3,"sources":["../src/index.ts","../src/setup.ts"],"sourcesContent":["import { weaverSetup } from './setup';\nexport { weaverSetup };\n","import Lenis from 'lenis';\nimport { ReactNode } from 'react';\n\nexport let lenisInstance: Lenis | undefined = undefined;\n\nexport type BasicTunnelIn = ({ children }: { children: ReactNode }) => null;\nexport let Default3DTunnelIn: BasicTunnelIn | undefined = undefined;\n\nexport const weaverSetup = {\n setLenisInstance(instance: Lenis) {\n lenisInstance = instance;\n },\n set3DTunnel(tunnelIn: BasicTunnelIn) {\n Default3DTunnelIn = tunnelIn;\n },\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACGO,IAAI,gBAAmC;AAGvC,IAAI,oBAA+C;AAEnD,IAAM,cAAc;AAAA,EACzB,iBAAiB,UAAiB;AAChC,oBAAgB;AAAA,EAClB;AAAA,EACA,YAAY,UAAyB;AACnC,wBAAoB;AAAA,EACtB;AACF;","names":[]}
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- // src/index.ts
1
+ // src/setup.ts
2
2
  var lenisInstance = void 0;
3
3
  var Default3DTunnelIn = void 0;
4
4
  var weaverSetup = {
@@ -10,8 +10,6 @@ var weaverSetup = {
10
10
  }
11
11
  };
12
12
  export {
13
- Default3DTunnelIn,
14
- lenisInstance,
15
13
  weaverSetup
16
14
  };
17
15
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import Lenis from 'lenis';\nimport { ReactNode } from 'react';\n\nexport let lenisInstance: Lenis | undefined = undefined;\n\nexport type BasicTunnelIn = ({ children }: { children: ReactNode }) => null;\nexport let Default3DTunnelIn: BasicTunnelIn | undefined = undefined;\n\nexport const weaverSetup = {\n setLenisInstance(instance: Lenis) {\n lenisInstance = instance;\n },\n set3DTunnel(tunnelIn: BasicTunnelIn) {\n Default3DTunnelIn = tunnelIn;\n },\n};\n"],"mappings":";AAGO,IAAI,gBAAmC;AAGvC,IAAI,oBAA+C;AAEnD,IAAM,cAAc;AAAA,EACzB,iBAAiB,UAAiB;AAChC,oBAAgB;AAAA,EAClB;AAAA,EACA,YAAY,UAAyB;AACnC,wBAAoB;AAAA,EACtB;AACF;","names":[]}
1
+ {"version":3,"sources":["../src/setup.ts"],"sourcesContent":["import Lenis from 'lenis';\nimport { ReactNode } from 'react';\n\nexport let lenisInstance: Lenis | undefined = undefined;\n\nexport type BasicTunnelIn = ({ children }: { children: ReactNode }) => null;\nexport let Default3DTunnelIn: BasicTunnelIn | undefined = undefined;\n\nexport const weaverSetup = {\n setLenisInstance(instance: Lenis) {\n lenisInstance = instance;\n },\n set3DTunnel(tunnelIn: BasicTunnelIn) {\n Default3DTunnelIn = tunnelIn;\n },\n};\n"],"mappings":";AAGO,IAAI,gBAAmC;AAGvC,IAAI,oBAA+C;AAEnD,IAAM,cAAc;AAAA,EACzB,iBAAiB,UAAiB;AAChC,oBAAgB;AAAA,EAClB;AAAA,EACA,YAAY,UAAyB;AACnC,wBAAoB;AAAA,EACtB;AACF;","names":[]}
package/dist/routing.js CHANGED
@@ -131,15 +131,15 @@ function DelayedOutlet(props) {
131
131
  // src/routing/Pipeline.tsx
132
132
  var import_react5 = __toESM(require("react"));
133
133
 
134
- // src/index.ts
135
- var lenisInstance = void 0;
136
-
137
134
  // src/hooks/effectOnce.ts
138
135
  var import_react4 = require("react");
139
136
  function useLayoutEffectOnce(callback) {
140
137
  (0, import_react4.useLayoutEffect)(callback, []);
141
138
  }
142
139
 
140
+ // src/setup.ts
141
+ var lenisInstance = void 0;
142
+
143
143
  // src/routing/Pipeline.tsx
144
144
  function Pipeline(props) {
145
145
  const { children, ...restOfProps } = props;
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/routing/index.ts","../src/routing/context.ts","../src/routing/DelayedOutlet.tsx","../src/hooks/routeNormalizer.ts","../src/utils/getParentRoute.ts","../src/routing/Pipeline.tsx","../src/index.ts","../src/hooks/effectOnce.ts"],"sourcesContent":["import { useWeaverContext, WeaverContextGetter } from './context';\nimport DelayedOutlet from './DelayedOutlet';\nimport Pipeline from './Pipeline';\n\n/// A read-only state for reacting with changes reflected by weaver.\nexport const useWeaverState = (givenState: keyof WeaverContextGetter) => {\n const state = useWeaverContext((state) => state[givenState]);\n return state;\n};\n\nexport { DelayedOutlet, Pipeline };\n","import { create } from 'zustand/react';\n\nexport interface WeaverContextGetter {\n /**\n * Current active parent, **AFTER** Pipeline has finished rendering, so the `activeParent`\n * will be delayed. Example: \"/\", \"/works\",...\n */\n activeParent: string;\n\n /**\n * Current active Pipeline. Example: \"/\", \"/works\",...\n *\n * This is **not based on URL**, it's based on which `Pipeline` has access to the the site.\n */\n activePipeline: string;\n\n /**\n * `DelayedOutlet` special variable, indicating if the route is current transitioning to a new route or not.\n */\n navigating: boolean;\n\n /**\n * When the page is rendered, it will turns this to true,\n * any parent page navigation will causes this to goes false, set to false in `DelayedOulet`.\n *\n * It's set to `false` right after `navigating` is set to `true`. `true` statement will be handled by `Pipeline`.\n */\n pageRendered: boolean;\n}\n\ninterface WeaverContextSetter {\n setActiveParent: (activeParent: string) => void;\n setActivePipeline: (activePipeline: string) => void;\n setNavigating: (navigating: boolean) => void;\n setPageRendered: (pageRendered: boolean) => void;\n}\n\nexport const useWeaverContext = create<\n WeaverContextSetter & WeaverContextGetter\n>()((set) => ({\n activeParent: '',\n setActiveParent: (activeParent) => set({ activeParent }),\n\n activePipeline: '',\n setActivePipeline: (activePipeline) => set({ activePipeline }),\n\n navigating: true,\n setNavigating: (navigating) => set({ navigating }),\n\n pageRendered: false,\n setPageRendered: (pageRendered) => set({ pageRendered }),\n}));\n","import { type ReactNode, useLayoutEffect, useRef, useState } from 'react';\nimport { useOutlet } from 'react-router';\nimport { useRouteNormalizer } from '../hooks/routeNormalizer';\nimport { getParentRoute } from '../utils/getParentRoute';\nimport { useWeaverContext } from './context';\n\n/**\n * A core part of an in-house tool called `weaver`.\n *\n * Delaying the routing process from `react-router`, handles gracefully between `Pipeline`s\n * while allowing any loading fallback component to listen and react with event changes.\n */\nexport default function DelayedOutlet(props: { delay: number }) {\n // Middleware to detect and replace invalid url.\n useRouteNormalizer({ autoReplace: true });\n\n const activePipeline = useWeaverContext((state) => state.activePipeline);\n const setNavigating = useWeaverContext((state) => state.setNavigating);\n const setPageRendered = useWeaverContext((state) => state.setPageRendered);\n\n const renderPageTask = useRef(setTimeout(() => {}));\n const routerOutlet = useOutlet();\n\n const [renderer, setRenderer] = useState<ReactNode>(null);\n\n // Handle and update new parent page.\n useLayoutEffect(() => {\n /**\n * `pageRendered` should be outside of `renderPageTask`,\n * we alrady have `Pipeline` to correct errors.\n */\n if ('scrollRestoration' in history) {\n history.scrollRestoration = 'manual';\n }\n\n if (getParentRoute(window.location.pathname) === activePipeline) {\n // Avoid while changing page, cancelling before new page pushed in\n // cause `activePipeline` to not change, making `navigating` softlock.\n setNavigating(false);\n return;\n }\n\n setNavigating(true);\n setPageRendered(false);\n\n clearTimeout(renderPageTask.current);\n renderPageTask.current = setTimeout(() => {\n setRenderer(routerOutlet!);\n setNavigating(false);\n }, props.delay);\n\n return () => {\n /**\n * Clear invalid task that were scheduled last effect.\n */\n clearInterval(renderPageTask.current);\n };\n }, [\n activePipeline,\n props.delay,\n routerOutlet,\n setNavigating,\n setPageRendered,\n ]);\n\n return renderer;\n}\n","import { useCallback, useLayoutEffect } from 'react';\nimport { useLocation, useNavigate } from 'react-router';\n\nexport function useRouteNormalizer(options: { autoReplace: boolean }) {\n const { pathname } = useLocation();\n const navigate = useNavigate();\n\n const normalizer = useCallback(\n (input: string) => input.replace(/\\/+\\//g, () => '/'),\n []\n );\n\n useLayoutEffect(() => {\n const result = normalizer(pathname);\n if (options.autoReplace && result !== pathname) {\n window.location.replace(result);\n }\n }, [options.autoReplace, pathname, navigate, normalizer]);\n\n return {\n pathname,\n normalizer,\n };\n}\n","export function getParentRoute(pathname: string) {\n let slashes = 0;\n let sliceAt = 0;\n for (sliceAt; sliceAt < pathname.length; sliceAt++) {\n if (pathname[sliceAt] == '/') {\n slashes++;\n }\n if (slashes === 2) {\n break;\n }\n }\n\n return pathname.slice(0, sliceAt);\n}\n","import React, { useLayoutEffect, type ReactNode } from 'react';\nimport { lenisInstance } from '..';\nimport { useLayoutEffectOnce } from '../hooks/effectOnce';\nimport { useWeaverContext } from './context';\n\ninterface PipelineProps {\n children?: ReactNode;\n\n /**\n * A state switch to notifies `Pipeline` that the content and elements of the page is ready to be displayed.\n *\n * Usually, you will need to preload some other external sources, or initialize 3D scene, this state\n * make sure that the loading fallback doesn't mess up and show initializing stuff.\n *\n * Using `BakeScene`, you can ensure that the scene is loaded via its callback, you can then pass the state value that\n * `BakeScene` changes to this variable to hide all the lags behind loading screen.\n */\n contentReady?: boolean;\n\n /**\n * Title for the page.\n */\n title: string;\n\n /**\n * By default, `Pipeline` will log the current phase to console.\n */\n debugName: string;\n\n /**\n * This is crucial for different `Pipeline`s to differentiate each other and avoiding conflict.\n *\n * Example for parent path: `/`, `/about`, `/projects`,...\n */\n parentPath: string;\n\n /**\n * By default, this value is `true`\n *\n * When navigating off of a previous `Pipeline`. It will stop lenis as a clean up.\n *\n * So when a new `Pipeline` takes in, it will enable lenis immediately when `contentReady` is switched to `true`.\n *\n * Set to `false` to gain manual control over when lenis will start. This does not affect to stop mechanism,\n * you don't have to clean up yourself.\n */\n autoStartLenis?: boolean;\n}\n\n/**\n * A core part of an in-house tool called `weaver`.\n *\n * `Pipeline`: Notifies & reflect changes to/from `LoadingFallback`\n * and `DelayedOutlet` about its page loading status.\n *\n * All parent routes must have `Pipeline` in order to work and sync with `DelayedOutlet`.\n */\nexport default function Pipeline(props: PipelineProps) {\n const { children, ...restOfProps } = props;\n return (\n <>\n <RouteHandler {...restOfProps} />\n {children}\n </>\n );\n}\n\nfunction RouteHandler(props: Omit<PipelineProps, 'children'>) {\n const navigating = useWeaverContext((state) => state.navigating);\n const pageRendered = useWeaverContext((state) => state.pageRendered);\n const activeParent = useWeaverContext((state) => state.activeParent);\n\n const setActivePipeline = useWeaverContext(\n (state) => state.setActivePipeline\n );\n const setPageRendered = useWeaverContext((state) => state.setPageRendered);\n const setActiveParent = useWeaverContext((state) => state.setActiveParent);\n\n useLayoutEffect(() => {\n document.title = props.title;\n setActivePipeline(props.parentPath);\n\n if (props.contentReady !== undefined && !props.contentReady) {\n console.log(`[${props.debugName}] Renderer status: Loading scene`);\n return;\n }\n\n if (!navigating && (!pageRendered || activeParent !== props.parentPath)) {\n if (props.autoStartLenis === undefined || props.autoStartLenis) {\n lenisInstance!.start();\n }\n\n setPageRendered(true);\n setActiveParent(props.parentPath);\n\n console.log(`[${props.debugName}] Renderer status: Mounted`);\n }\n }, [\n activeParent,\n setActivePipeline,\n navigating,\n pageRendered,\n props.autoStartLenis,\n props.contentReady,\n props.debugName,\n props.parentPath,\n props.title,\n setActiveParent,\n setPageRendered,\n ]);\n\n useLayoutEffectOnce(() => {\n return () => {\n /**\n * When unmounted, stop lenis to pass control to another Pipline instance.\n *\n * The unmount process only happens when the `<LoadingFallback />` kicks in,\n * so any visual glitches can happen in here, we can now set the scroll position to 0.\n */\n lenisInstance!.stop();\n lenisInstance!.scrollTo(0, { immediate: true, force: true });\n\n console.log(`[${props.debugName}] Renderer status: Unmounted`);\n };\n });\n\n return null;\n}\n","import Lenis from 'lenis';\nimport { ReactNode } from 'react';\n\nexport let lenisInstance: Lenis | undefined = undefined;\n\nexport type BasicTunnelIn = ({ children }: { children: ReactNode }) => null;\nexport let Default3DTunnelIn: BasicTunnelIn | undefined = undefined;\n\nexport const weaverSetup = {\n setLenisInstance(instance: Lenis) {\n lenisInstance = instance;\n },\n set3DTunnel(tunnelIn: BasicTunnelIn) {\n Default3DTunnelIn = tunnelIn;\n },\n};\n","import { useEffect, useLayoutEffect } from 'react';\n\nexport function useEffectOnce(callback: React.EffectCallback) {\n // eslint-disable-next-line react-hooks/exhaustive-deps\n useEffect(callback, []);\n}\n\nexport function useLayoutEffectOnce(callback: React.EffectCallback) {\n // eslint-disable-next-line react-hooks/exhaustive-deps\n useLayoutEffect(callback, []);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAAuB;AAqChB,IAAM,uBAAmB,qBAE9B,EAAE,CAAC,SAAS;AAAA,EACZ,cAAc;AAAA,EACd,iBAAiB,CAAC,iBAAiB,IAAI,EAAE,aAAa,CAAC;AAAA,EAEvD,gBAAgB;AAAA,EAChB,mBAAmB,CAAC,mBAAmB,IAAI,EAAE,eAAe,CAAC;AAAA,EAE7D,YAAY;AAAA,EACZ,eAAe,CAAC,eAAe,IAAI,EAAE,WAAW,CAAC;AAAA,EAEjD,cAAc;AAAA,EACd,iBAAiB,CAAC,iBAAiB,IAAI,EAAE,aAAa,CAAC;AACzD,EAAE;;;ACnDF,IAAAA,gBAAkE;AAClE,IAAAC,uBAA0B;;;ACD1B,IAAAC,gBAA6C;AAC7C,0BAAyC;AAElC,SAAS,mBAAmB,SAAmC;AACpE,QAAM,EAAE,SAAS,QAAI,iCAAY;AACjC,QAAM,eAAW,iCAAY;AAE7B,QAAM,iBAAa;AAAA,IACjB,CAAC,UAAkB,MAAM,QAAQ,UAAU,MAAM,GAAG;AAAA,IACpD,CAAC;AAAA,EACH;AAEA,qCAAgB,MAAM;AACpB,UAAM,SAAS,WAAW,QAAQ;AAClC,QAAI,QAAQ,eAAe,WAAW,UAAU;AAC9C,aAAO,S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AAA,IACN,MAAM;AAAA,IACN,MAAM;AAAA,IACN,MAAM;AAAA,IACN;AAAA,IACA;AAAA,EACF,CAAC;AAED,sBAAoB,MAAM;AACxB,WAAO,MAAM;AAOX,oBAAe,KAAK;AACpB,oBAAe,SAAS,GAAG,EAAE,WAAW,MAAM,OAAO,KAAK,CAAC;AAE3D,cAAQ,IAAI,IAAI,MAAM,SAAS,8BAA8B;AAAA,IAC/D;AAAA,EACF,CAAC;AAED,SAAO;AACT;;;AL1HO,IAAM,iBAAiB,CAAC,eAA0C;AACvE,QAAM,QAAQ,iBAAiB,CAACC,WAAUA,OAAM,UAAU,CAAC;AAC3D,SAAO;AACT;","names":["import_react","import_react_router","import_react","import_react","import_react","React","state"]}
1
+ {"version":3,"sources":["../src/routing/index.ts","../src/routing/context.ts","../src/routing/DelayedOutlet.tsx","../src/hooks/routeNormalizer.ts","../src/utils/getParentRoute.ts","../src/routing/Pipeline.tsx","../src/hooks/effectOnce.ts","../src/setup.ts"],"sourcesContent":["import { useWeaverContext, WeaverContextGetter } from './context';\nimport DelayedOutlet from './DelayedOutlet';\nimport Pipeline from './Pipeline';\n\n/// A read-only state for reacting with changes reflected by weaver.\nexport const useWeaverState = (givenState: keyof WeaverContextGetter) => {\n const state = useWeaverContext((state) => state[givenState]);\n return state;\n};\n\nexport { DelayedOutlet, Pipeline };\n","import { create } from 'zustand/react';\n\nexport interface WeaverContextGetter {\n /**\n * Current active parent, **AFTER** Pipeline has finished rendering, so the `activeParent`\n * will be delayed. Example: \"/\", \"/works\",...\n */\n activeParent: string;\n\n /**\n * Current active Pipeline. Example: \"/\", \"/works\",...\n *\n * This is **not based on URL**, it's based on which `Pipeline` has access to the the site.\n */\n activePipeline: string;\n\n /**\n * `DelayedOutlet` special variable, indicating if the route is current transitioning to a new route or not.\n */\n navigating: boolean;\n\n /**\n * When the page is rendered, it will turns this to true,\n * any parent page navigation will causes this to goes false, set to false in `DelayedOulet`.\n *\n * It's set to `false` right after `navigating` is set to `true`. `true` statement will be handled by `Pipeline`.\n */\n pageRendered: boolean;\n}\n\ninterface WeaverContextSetter {\n setActiveParent: (activeParent: string) => void;\n setActivePipeline: (activePipeline: string) => void;\n setNavigating: (navigating: boolean) => void;\n setPageRendered: (pageRendered: boolean) => void;\n}\n\nexport const useWeaverContext = create<\n WeaverContextSetter & WeaverContextGetter\n>()((set) => ({\n activeParent: '',\n setActiveParent: (activeParent) => set({ activeParent }),\n\n activePipeline: '',\n setActivePipeline: (activePipeline) => set({ activePipeline }),\n\n navigating: true,\n setNavigating: (navigating) => set({ navigating }),\n\n pageRendered: false,\n setPageRendered: (pageRendered) => set({ pageRendered }),\n}));\n","import { type ReactNode, useLayoutEffect, useRef, useState } from 'react';\nimport { useOutlet } from 'react-router';\nimport { useRouteNormalizer } from '../hooks/routeNormalizer';\nimport { getParentRoute } from '../utils/getParentRoute';\nimport { useWeaverContext } from './context';\n\n/**\n * A core part of an in-house tool called `weaver`.\n *\n * Delaying the routing process from `react-router`, handles gracefully between `Pipeline`s\n * while allowing any loading fallback component to listen and react with event changes.\n */\nexport default function DelayedOutlet(props: { delay: number }) {\n // Middleware to detect and replace invalid url.\n useRouteNormalizer({ autoReplace: true });\n\n const activePipeline = useWeaverContext((state) => state.activePipeline);\n const setNavigating = useWeaverContext((state) => state.setNavigating);\n const setPageRendered = useWeaverContext((state) => state.setPageRendered);\n\n const renderPageTask = useRef(setTimeout(() => {}));\n const routerOutlet = useOutlet();\n\n const [renderer, setRenderer] = useState<ReactNode>(null);\n\n // Handle and update new parent page.\n useLayoutEffect(() => {\n /**\n * `pageRendered` should be outside of `renderPageTask`,\n * we alrady have `Pipeline` to correct errors.\n */\n if ('scrollRestoration' in history) {\n history.scrollRestoration = 'manual';\n }\n\n if (getParentRoute(window.location.pathname) === activePipeline) {\n // Avoid while changing page, cancelling before new page pushed in\n // cause `activePipeline` to not change, making `navigating` softlock.\n setNavigating(false);\n return;\n }\n\n setNavigating(true);\n setPageRendered(false);\n\n clearTimeout(renderPageTask.current);\n renderPageTask.current = setTimeout(() => {\n setRenderer(routerOutlet!);\n setNavigating(false);\n }, props.delay);\n\n return () => {\n /**\n * Clear invalid task that were scheduled last effect.\n */\n clearInterval(renderPageTask.current);\n };\n }, [\n activePipeline,\n props.delay,\n routerOutlet,\n setNavigating,\n setPageRendered,\n ]);\n\n return renderer;\n}\n","import { useCallback, useLayoutEffect } from 'react';\nimport { useLocation, useNavigate } from 'react-router';\n\nexport function useRouteNormalizer(options: { autoReplace: boolean }) {\n const { pathname } = useLocation();\n const navigate = useNavigate();\n\n const normalizer = useCallback(\n (input: string) => input.replace(/\\/+\\//g, () => '/'),\n []\n );\n\n useLayoutEffect(() => {\n const result = normalizer(pathname);\n if (options.autoReplace && result !== pathname) {\n window.location.replace(result);\n }\n }, [options.autoReplace, pathname, navigate, normalizer]);\n\n return {\n pathname,\n normalizer,\n };\n}\n","export function getParentRoute(pathname: string) {\n let slashes = 0;\n let sliceAt = 0;\n for (sliceAt; sliceAt < pathname.length; sliceAt++) {\n if (pathname[sliceAt] == '/') {\n slashes++;\n }\n if (slashes === 2) {\n break;\n }\n }\n\n return pathname.slice(0, sliceAt);\n}\n","import React, { useLayoutEffect, type ReactNode } from 'react';\nimport { useLayoutEffectOnce } from '../hooks/effectOnce';\nimport { lenisInstance } from '../setup';\nimport { useWeaverContext } from './context';\n\ninterface PipelineProps {\n children?: ReactNode;\n\n /**\n * A state switch to notifies `Pipeline` that the content and elements of the page is ready to be displayed.\n *\n * Usually, you will need to preload some other external sources, or initialize 3D scene, this state\n * make sure that the loading fallback doesn't mess up and show initializing stuff.\n *\n * Using `BakeScene`, you can ensure that the scene is loaded via its callback, you can then pass the state value that\n * `BakeScene` changes to this variable to hide all the lags behind loading screen.\n */\n contentReady?: boolean;\n\n /**\n * Title for the page.\n */\n title: string;\n\n /**\n * By default, `Pipeline` will log the current phase to console.\n */\n debugName: string;\n\n /**\n * This is crucial for different `Pipeline`s to differentiate each other and avoiding conflict.\n *\n * Example for parent path: `/`, `/about`, `/projects`,...\n */\n parentPath: string;\n\n /**\n * By default, this value is `true`\n *\n * When navigating off of a previous `Pipeline`. It will stop lenis as a clean up.\n *\n * So when a new `Pipeline` takes in, it will enable lenis immediately when `contentReady` is switched to `true`.\n *\n * Set to `false` to gain manual control over when lenis will start. This does not affect to stop mechanism,\n * you don't have to clean up yourself.\n */\n autoStartLenis?: boolean;\n}\n\n/**\n * A core part of an in-house tool called `weaver`.\n *\n * `Pipeline`: Notifies & reflect changes to/from `LoadingFallback`\n * and `DelayedOutlet` about its page loading status.\n *\n * All parent routes must have `Pipeline` in order to work and sync with `DelayedOutlet`.\n */\nexport default function Pipeline(props: PipelineProps) {\n const { children, ...restOfProps } = props;\n return (\n <>\n <RouteHandler {...restOfProps} />\n {children}\n </>\n );\n}\n\nfunction RouteHandler(props: Omit<PipelineProps, 'children'>) {\n const navigating = useWeaverContext((state) => state.navigating);\n const pageRendered = useWeaverContext((state) => state.pageRendered);\n const activeParent = useWeaverContext((state) => state.activeParent);\n\n const setActivePipeline = useWeaverContext(\n (state) => state.setActivePipeline\n );\n const setPageRendered = useWeaverContext((state) => state.setPageRendered);\n const setActiveParent = useWeaverContext((state) => state.setActiveParent);\n\n useLayoutEffect(() => {\n document.title = props.title;\n setActivePipeline(props.parentPath);\n\n if (props.contentReady !== undefined && !props.contentReady) {\n console.log(`[${props.debugName}] Renderer status: Loading scene`);\n return;\n }\n\n if (!navigating && (!pageRendered || activeParent !== props.parentPath)) {\n if (props.autoStartLenis === undefined || props.autoStartLenis) {\n lenisInstance!.start();\n }\n\n setPageRendered(true);\n setActiveParent(props.parentPath);\n\n console.log(`[${props.debugName}] Renderer status: Mounted`);\n }\n }, [\n activeParent,\n setActivePipeline,\n navigating,\n pageRendered,\n props.autoStartLenis,\n props.contentReady,\n props.debugName,\n props.parentPath,\n props.title,\n setActiveParent,\n setPageRendered,\n ]);\n\n useLayoutEffectOnce(() => {\n return () => {\n /**\n * When unmounted, stop lenis to pass control to another Pipline instance.\n *\n * The unmount process only happens when the `<LoadingFallback />` kicks in,\n * so any visual glitches can happen in here, we can now set the scroll position to 0.\n */\n lenisInstance!.stop();\n lenisInstance!.scrollTo(0, { immediate: true, force: true });\n\n console.log(`[${props.debugName}] Renderer status: Unmounted`);\n };\n });\n\n return null;\n}\n","import { useEffect, useLayoutEffect } from 'react';\n\nexport function useEffectOnce(callback: React.EffectCallback) {\n // eslint-disable-next-line react-hooks/exhaustive-deps\n useEffect(callback, []);\n}\n\nexport function useLayoutEffectOnce(callback: React.EffectCallback) {\n // eslint-disable-next-line react-hooks/exhaustive-deps\n useLayoutEffect(callback, []);\n}\n","import Lenis from 'lenis';\nimport { ReactNode } from 'react';\n\nexport let lenisInstance: Lenis | undefined = undefined;\n\nexport type BasicTunnelIn = ({ children }: { children: ReactNode }) => null;\nexport let Default3DTunnelIn: BasicTunnelIn | undefined = undefined;\n\nexport const weaverSetup = {\n setLenisInstance(instance: Lenis) {\n lenisInstance = instance;\n },\n set3DTunnel(tunnelIn: BasicTunnelIn) {\n Default3DTunnelIn = tunnelIn;\n },\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAAuB;AAqChB,IAAM,uBAAmB,qBAE9B,EAAE,CAAC,SAAS;AAAA,EACZ,cAAc;AAAA,EACd,iBAAiB,CAAC,iBAAiB,IAAI,EAAE,aAAa,CAAC;AAAA,EAEvD,gBAAgB;AAAA,EAChB,mBAAmB,CAAC,mBAAmB,IAAI,EAAE,eAAe,CAAC;AAAA,EAE7D,YAAY;AAAA,EACZ,eAAe,CAAC,eAAe,IAAI,EAAE,WAAW,CAAC;AAAA,EAEjD,cAAc;AAAA,EACd,iBAAiB,CAAC,iBAAiB,IAAI,EAAE,aAAa,CAAC;AACzD,EAAE;;;ACnDF,IAAAA,gBAAkE;AAClE,IAAAC,uBAA0B;;;ACD1B,IAAAC,gBAA6C;AAC7C,0BAAyC;AAElC,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AAM,aAAa;AACvE,UAAI,MAAM,mBAAmB,UAAa,MAAM,gBAAgB;AAC9D,sBAAe,MAAM;AAAA,MACvB;AAEA,sBAAgB,IAAI;AACpB,sBAAgB,MAAM,UAAU;AAEhC,cAAQ,IAAI,IAAI,MAAM,SAAS,4BAA4B;AAAA,IAC7D;AAAA,EACF,GAAG;AAAA,IACD;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,MAAM;AAAA,IACN,MAAM;AAAA,IACN,MAAM;AAAA,IACN,MAAM;AAAA,IACN,MAAM;AAAA,IACN;AAAA,IACA;AAAA,EACF,CAAC;AAED,sBAAoB,MAAM;AACxB,WAAO,MAAM;AAOX,oBAAe,KAAK;AACpB,oBAAe,SAAS,GAAG,EAAE,WAAW,MAAM,OAAO,KAAK,CAAC;AAE3D,cAAQ,IAAI,IAAI,MAAM,SAAS,8BAA8B;AAAA,IAC/D;AAAA,EACF,CAAC;AAED,SAAO;AACT;;;AL1HO,IAAM,iBAAiB,CAAC,eAA0C;AACvE,QAAM,QAAQ,iBAAiB,CAACC,WAAUA,OAAM,UAAU,CAAC;AAC3D,SAAO;AACT;","names":["import_react","import_react_router","import_react","import_react","import_react","React","state"]}
package/dist/routing.mjs CHANGED
@@ -93,15 +93,15 @@ function DelayedOutlet(props) {
93
93
  // src/routing/Pipeline.tsx
94
94
  import React, { useLayoutEffect as useLayoutEffect4 } from "react";
95
95
 
96
- // src/index.ts
97
- var lenisInstance = void 0;
98
-
99
96
  // src/hooks/effectOnce.ts
100
97
  import { useEffect, useLayoutEffect as useLayoutEffect3 } from "react";
101
98
  function useLayoutEffectOnce(callback) {
102
99
  useLayoutEffect3(callback, []);
103
100
  }
104
101
 
102
+ // src/setup.ts
103
+ var lenisInstance = void 0;
104
+
105
105
  // src/routing/Pipeline.tsx
106
106
  function Pipeline(props) {
107
107
  const { children, ...restOfProps } = props;
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/routing/context.ts","../src/routing/DelayedOutlet.tsx","../src/hooks/routeNormalizer.ts","../src/utils/getParentRoute.ts","../src/routing/Pipeline.tsx","../src/index.ts","../src/hooks/effectOnce.ts","../src/routing/index.ts"],"sourcesContent":["import { create } from 'zustand/react';\n\nexport interface WeaverContextGetter {\n /**\n * Current active parent, **AFTER** Pipeline has finished rendering, so the `activeParent`\n * will be delayed. Example: \"/\", \"/works\",...\n */\n activeParent: string;\n\n /**\n * Current active Pipeline. Example: \"/\", \"/works\",...\n *\n * This is **not based on URL**, it's based on which `Pipeline` has access to the the site.\n */\n activePipeline: string;\n\n /**\n * `DelayedOutlet` special variable, indicating if the route is current transitioning to a new route or not.\n */\n navigating: boolean;\n\n /**\n * When the page is rendered, it will turns this to true,\n * any parent page navigation will causes this to goes false, set to false in `DelayedOulet`.\n *\n * It's set to `false` right after `navigating` is set to `true`. `true` statement will be handled by `Pipeline`.\n */\n pageRendered: boolean;\n}\n\ninterface WeaverContextSetter {\n setActiveParent: (activeParent: string) => void;\n setActivePipeline: (activePipeline: string) => void;\n setNavigating: (navigating: boolean) => void;\n setPageRendered: (pageRendered: boolean) => void;\n}\n\nexport const useWeaverContext = create<\n WeaverContextSetter & WeaverContextGetter\n>()((set) => ({\n activeParent: '',\n setActiveParent: (activeParent) => set({ activeParent }),\n\n activePipeline: '',\n setActivePipeline: (activePipeline) => set({ activePipeline }),\n\n navigating: true,\n setNavigating: (navigating) => set({ navigating }),\n\n pageRendered: false,\n setPageRendered: (pageRendered) => set({ pageRendered }),\n}));\n","import { type ReactNode, useLayoutEffect, useRef, useState } from 'react';\nimport { useOutlet } from 'react-router';\nimport { useRouteNormalizer } from '../hooks/routeNormalizer';\nimport { getParentRoute } from '../utils/getParentRoute';\nimport { useWeaverContext } from './context';\n\n/**\n * A core part of an in-house tool called `weaver`.\n *\n * Delaying the routing process from `react-router`, handles gracefully between `Pipeline`s\n * while allowing any loading fallback component to listen and react with event changes.\n */\nexport default function DelayedOutlet(props: { delay: number }) {\n // Middleware to detect and replace invalid url.\n useRouteNormalizer({ autoReplace: true });\n\n const activePipeline = useWeaverContext((state) => state.activePipeline);\n const setNavigating = useWeaverContext((state) => state.setNavigating);\n const setPageRendered = useWeaverContext((state) => state.setPageRendered);\n\n const renderPageTask = useRef(setTimeout(() => {}));\n const routerOutlet = useOutlet();\n\n const [renderer, setRenderer] = useState<ReactNode>(null);\n\n // Handle and update new parent page.\n useLayoutEffect(() => {\n /**\n * `pageRendered` should be outside of `renderPageTask`,\n * we alrady have `Pipeline` to correct errors.\n */\n if ('scrollRestoration' in history) {\n history.scrollRestoration = 'manual';\n }\n\n if (getParentRoute(window.location.pathname) === activePipeline) {\n // Avoid while changing page, cancelling before new page pushed in\n // cause `activePipeline` to not change, making `navigating` softlock.\n setNavigating(false);\n return;\n }\n\n setNavigating(true);\n setPageRendered(false);\n\n clearTimeout(renderPageTask.current);\n renderPageTask.current = setTimeout(() => {\n setRenderer(routerOutlet!);\n setNavigating(false);\n }, props.delay);\n\n return () => {\n /**\n * Clear invalid task that were scheduled last effect.\n */\n clearInterval(renderPageTask.current);\n };\n }, [\n activePipeline,\n props.delay,\n routerOutlet,\n setNavigating,\n setPageRendered,\n ]);\n\n return renderer;\n}\n","import { useCallback, useLayoutEffect } from 'react';\nimport { useLocation, useNavigate } from 'react-router';\n\nexport function useRouteNormalizer(options: { autoReplace: boolean }) {\n const { pathname } = useLocation();\n const navigate = useNavigate();\n\n const normalizer = useCallback(\n (input: string) => input.replace(/\\/+\\//g, () => '/'),\n []\n );\n\n useLayoutEffect(() => {\n const result = normalizer(pathname);\n if (options.autoReplace && result !== pathname) {\n window.location.replace(result);\n }\n }, [options.autoReplace, pathname, navigate, normalizer]);\n\n return {\n pathname,\n normalizer,\n };\n}\n","export function getParentRoute(pathname: string) {\n let slashes = 0;\n let sliceAt = 0;\n for (sliceAt; sliceAt < pathname.length; sliceAt++) {\n if (pathname[sliceAt] == '/') {\n slashes++;\n }\n if (slashes === 2) {\n break;\n }\n }\n\n return pathname.slice(0, sliceAt);\n}\n","import React, { useLayoutEffect, type ReactNode } from 'react';\nimport { lenisInstance } from '..';\nimport { useLayoutEffectOnce } from '../hooks/effectOnce';\nimport { useWeaverContext } from './context';\n\ninterface PipelineProps {\n children?: ReactNode;\n\n /**\n * A state switch to notifies `Pipeline` that the content and elements of the page is ready to be displayed.\n *\n * Usually, you will need to preload some other external sources, or initialize 3D scene, this state\n * make sure that the loading fallback doesn't mess up and show initializing stuff.\n *\n * Using `BakeScene`, you can ensure that the scene is loaded via its callback, you can then pass the state value that\n * `BakeScene` changes to this variable to hide all the lags behind loading screen.\n */\n contentReady?: boolean;\n\n /**\n * Title for the page.\n */\n title: string;\n\n /**\n * By default, `Pipeline` will log the current phase to console.\n */\n debugName: string;\n\n /**\n * This is crucial for different `Pipeline`s to differentiate each other and avoiding conflict.\n *\n * Example for parent path: `/`, `/about`, `/projects`,...\n */\n parentPath: string;\n\n /**\n * By default, this value is `true`\n *\n * When navigating off of a previous `Pipeline`. It will stop lenis as a clean up.\n *\n * So when a new `Pipeline` takes in, it will enable lenis immediately when `contentReady` is switched to `true`.\n *\n * Set to `false` to gain manual control over when lenis will start. This does not affect to stop mechanism,\n * you don't have to clean up yourself.\n */\n autoStartLenis?: boolean;\n}\n\n/**\n * A core part of an in-house tool called `weaver`.\n *\n * `Pipeline`: Notifies & reflect changes to/from `LoadingFallback`\n * and `DelayedOutlet` about its page loading status.\n *\n * All parent routes must have `Pipeline` in order to work and sync with `DelayedOutlet`.\n */\nexport default function Pipeline(props: PipelineProps) {\n const { children, ...restOfProps } = props;\n return (\n <>\n <RouteHandler {...restOfProps} />\n {children}\n </>\n );\n}\n\nfunction RouteHandler(props: Omit<PipelineProps, 'children'>) {\n const navigating = useWeaverContext((state) => state.navigating);\n const pageRendered = useWeaverContext((state) => state.pageRendered);\n const activeParent = useWeaverContext((state) => state.activeParent);\n\n const setActivePipeline = useWeaverContext(\n (state) => state.setActivePipeline\n );\n const setPageRendered = useWeaverContext((state) => state.setPageRendered);\n const setActiveParent = useWeaverContext((state) => state.setActiveParent);\n\n useLayoutEffect(() => {\n document.title = props.title;\n setActivePipeline(props.parentPath);\n\n if (props.contentReady !== undefined && !props.contentReady) {\n console.log(`[${props.debugName}] Renderer status: Loading scene`);\n return;\n }\n\n if (!navigating && (!pageRendered || activeParent !== props.parentPath)) {\n if (props.autoStartLenis === undefined || props.autoStartLenis) {\n lenisInstance!.start();\n }\n\n setPageRendered(true);\n setActiveParent(props.parentPath);\n\n console.log(`[${props.debugName}] Renderer status: Mounted`);\n }\n }, [\n activeParent,\n setActivePipeline,\n navigating,\n pageRendered,\n props.autoStartLenis,\n props.contentReady,\n props.debugName,\n props.parentPath,\n props.title,\n setActiveParent,\n setPageRendered,\n ]);\n\n useLayoutEffectOnce(() => {\n return () => {\n /**\n * When unmounted, stop lenis to pass control to another Pipline instance.\n *\n * The unmount process only happens when the `<LoadingFallback />` kicks in,\n * so any visual glitches can happen in here, we can now set the scroll position to 0.\n */\n lenisInstance!.stop();\n lenisInstance!.scrollTo(0, { immediate: true, force: true });\n\n console.log(`[${props.debugName}] Renderer status: Unmounted`);\n };\n });\n\n return null;\n}\n","import Lenis from 'lenis';\nimport { ReactNode } from 'react';\n\nexport let lenisInstance: Lenis | undefined = undefined;\n\nexport type BasicTunnelIn = ({ children }: { children: ReactNode }) => null;\nexport let Default3DTunnelIn: BasicTunnelIn | undefined = undefined;\n\nexport const weaverSetup = {\n setLenisInstance(instance: Lenis) {\n lenisInstance = instance;\n },\n set3DTunnel(tunnelIn: BasicTunnelIn) {\n Default3DTunnelIn = tunnelIn;\n },\n};\n","import { useEffect, useLayoutEffect } from 'react';\n\nexport function useEffectOnce(callback: React.EffectCallback) {\n // eslint-disable-next-line react-hooks/exhaustive-deps\n useEffect(callback, []);\n}\n\nexport function useLayoutEffectOnce(callback: React.EffectCallback) {\n // eslint-disable-next-line react-hooks/exhaustive-deps\n useLayoutEffect(callback, []);\n}\n","import { useWeaverContext, WeaverContextGetter } from './context';\nimport DelayedOutlet from './DelayedOutlet';\nimport Pipeline from './Pipeline';\n\n/// A read-only state for reacting with changes reflected by weaver.\nexport const useWeaverState = (givenState: keyof WeaverContextGetter) => {\n const state = useWeaverContext((state) => state[givenState]);\n return state;\n};\n\nexport { DelayedOutlet, Pipeline };\n"],"mappings":";AAAA,SAAS,cAAc;AAqChB,IAAM,mBAAmB,OAE9B,EAAE,CAAC,SAAS;AAAA,EACZ,cAAc;AAAA,EACd,iBAAiB,CAAC,iBAAiB,IAAI,EAAE,aAAa,CAAC;AAAA,EAEvD,gBAAgB;AAAA,EAChB,mBAAmB,CAAC,mBAAmB,IAAI,EAAE,eAAe,CAAC;AAAA,EAE7D,YAAY;AAAA,EACZ,eAAe,CAAC,eAAe,IAAI,EAAE,WAAW,CAAC;AAAA,EAEjD,cAAc;AAAA,EACd,iBAAiB,CAAC,iBAAiB,IAAI,EAAE,aAAa,CAAC;AACzD,EAAE;;;ACnDF,SAAyB,mBAAAA,kBAAiB,QAAQ,gBAAgB;AAClE,SAAS,iBAAiB;;;ACD1B,SAAS,aAAa,uBAAuB;AAC7C,SAAS,aAAa,mBAAmB;AAElC,SAAS,mBAAmB,SAAmC;AACpE,QAAM,EAAE,SAAS,IAAI,YAAY;AACjC,QAAM,WAAW,YAAY;AAE7B,QAAM,aAAa;AAAA,IACjB,CAAC,UAAkB,MAAM,QAAQ,UAAU,MAAM,GAAG;AAAA,IACpD,CAAC;AAAA,EACH;AAEA,kBAAgB,MAAM;AACpB,UAAM,SAAS,WAAW,QAAQ;AAClC,QAAI,QAAQ,eAAe,WAAW,UAAU;AAC9C,aAAO,SAAS,QAAQ,MAAM;AAAA,IAChC;AAAA,EACF,GAAG,CAAC,QAAQ,aAAa,UAAU,UAAU,UAAU,CAAC;AAExD,SAAO;AAAA,IACL;AAAA,IACA;AAAA,EACF;AACF;;;ACvBO,SAAS,eAAe,UAAkB;AAC/C,MAAI,UAAU;AACd,MAAI,UAAU;AACd,OAAK,SAAS,UAAU,SAAS,QAAQ,WAAW;AAClD,QAAI,SA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AC/D;AAAA,EACF,CAAC;AAED,SAAO;AACT;;;AG1HO,IAAM,iBAAiB,CAAC,eAA0C;AACvE,QAAM,QAAQ,iBAAiB,CAACC,WAAUA,OAAM,UAAU,CAAC;AAC3D,SAAO;AACT;","names":["useLayoutEffect","useLayoutEffect","useLayoutEffect","useLayoutEffect","useLayoutEffect","useLayoutEffect","state"]}
1
+ {"version":3,"sources":["../src/routing/context.ts","../src/routing/DelayedOutlet.tsx","../src/hooks/routeNormalizer.ts","../src/utils/getParentRoute.ts","../src/routing/Pipeline.tsx","../src/hooks/effectOnce.ts","../src/setup.ts","../src/routing/index.ts"],"sourcesContent":["import { create } from 'zustand/react';\n\nexport interface WeaverContextGetter {\n /**\n * Current active parent, **AFTER** Pipeline has finished rendering, so the `activeParent`\n * will be delayed. Example: \"/\", \"/works\",...\n */\n activeParent: string;\n\n /**\n * Current active Pipeline. Example: \"/\", \"/works\",...\n *\n * This is **not based on URL**, it's based on which `Pipeline` has access to the the site.\n */\n activePipeline: string;\n\n /**\n * `DelayedOutlet` special variable, indicating if the route is current transitioning to a new route or not.\n */\n navigating: boolean;\n\n /**\n * When the page is rendered, it will turns this to true,\n * any parent page navigation will causes this to goes false, set to false in `DelayedOulet`.\n *\n * It's set to `false` right after `navigating` is set to `true`. `true` statement will be handled by `Pipeline`.\n */\n pageRendered: boolean;\n}\n\ninterface WeaverContextSetter {\n setActiveParent: (activeParent: string) => void;\n setActivePipeline: (activePipeline: string) => void;\n setNavigating: (navigating: boolean) => void;\n setPageRendered: (pageRendered: boolean) => void;\n}\n\nexport const useWeaverContext = create<\n WeaverContextSetter & WeaverContextGetter\n>()((set) => ({\n activeParent: '',\n setActiveParent: (activeParent) => set({ activeParent }),\n\n activePipeline: '',\n setActivePipeline: (activePipeline) => set({ activePipeline }),\n\n navigating: true,\n setNavigating: (navigating) => set({ navigating }),\n\n pageRendered: false,\n setPageRendered: (pageRendered) => set({ pageRendered }),\n}));\n","import { type ReactNode, useLayoutEffect, useRef, useState } from 'react';\nimport { useOutlet } from 'react-router';\nimport { useRouteNormalizer } from '../hooks/routeNormalizer';\nimport { getParentRoute } from '../utils/getParentRoute';\nimport { useWeaverContext } from './context';\n\n/**\n * A core part of an in-house tool called `weaver`.\n *\n * Delaying the routing process from `react-router`, handles gracefully between `Pipeline`s\n * while allowing any loading fallback component to listen and react with event changes.\n */\nexport default function DelayedOutlet(props: { delay: number }) {\n // Middleware to detect and replace invalid url.\n useRouteNormalizer({ autoReplace: true });\n\n const activePipeline = useWeaverContext((state) => state.activePipeline);\n const setNavigating = useWeaverContext((state) => state.setNavigating);\n const setPageRendered = useWeaverContext((state) => state.setPageRendered);\n\n const renderPageTask = useRef(setTimeout(() => {}));\n const routerOutlet = useOutlet();\n\n const [renderer, setRenderer] = useState<ReactNode>(null);\n\n // Handle and update new parent page.\n useLayoutEffect(() => {\n /**\n * `pageRendered` should be outside of `renderPageTask`,\n * we alrady have `Pipeline` to correct errors.\n */\n if ('scrollRestoration' in history) {\n history.scrollRestoration = 'manual';\n }\n\n if (getParentRoute(window.location.pathname) === activePipeline) {\n // Avoid while changing page, cancelling before new page pushed in\n // cause `activePipeline` to not change, making `navigating` softlock.\n setNavigating(false);\n return;\n }\n\n setNavigating(true);\n setPageRendered(false);\n\n clearTimeout(renderPageTask.current);\n renderPageTask.current = setTimeout(() => {\n setRenderer(routerOutlet!);\n setNavigating(false);\n }, props.delay);\n\n return () => {\n /**\n * Clear invalid task that were scheduled last effect.\n */\n clearInterval(renderPageTask.current);\n };\n }, [\n activePipeline,\n props.delay,\n routerOutlet,\n setNavigating,\n setPageRendered,\n ]);\n\n return renderer;\n}\n","import { useCallback, useLayoutEffect } from 'react';\nimport { useLocation, useNavigate } from 'react-router';\n\nexport function useRouteNormalizer(options: { autoReplace: boolean }) {\n const { pathname } = useLocation();\n const navigate = useNavigate();\n\n const normalizer = useCallback(\n (input: string) => input.replace(/\\/+\\//g, () => '/'),\n []\n );\n\n useLayoutEffect(() => {\n const result = normalizer(pathname);\n if (options.autoReplace && result !== pathname) {\n window.location.replace(result);\n }\n }, [options.autoReplace, pathname, navigate, normalizer]);\n\n return {\n pathname,\n normalizer,\n };\n}\n","export function getParentRoute(pathname: string) {\n let slashes = 0;\n let sliceAt = 0;\n for (sliceAt; sliceAt < pathname.length; sliceAt++) {\n if (pathname[sliceAt] == '/') {\n slashes++;\n }\n if (slashes === 2) {\n break;\n }\n }\n\n return pathname.slice(0, sliceAt);\n}\n","import React, { useLayoutEffect, type ReactNode } from 'react';\nimport { useLayoutEffectOnce } from '../hooks/effectOnce';\nimport { lenisInstance } from '../setup';\nimport { useWeaverContext } from './context';\n\ninterface PipelineProps {\n children?: ReactNode;\n\n /**\n * A state switch to notifies `Pipeline` that the content and elements of the page is ready to be displayed.\n *\n * Usually, you will need to preload some other external sources, or initialize 3D scene, this state\n * make sure that the loading fallback doesn't mess up and show initializing stuff.\n *\n * Using `BakeScene`, you can ensure that the scene is loaded via its callback, you can then pass the state value that\n * `BakeScene` changes to this variable to hide all the lags behind loading screen.\n */\n contentReady?: boolean;\n\n /**\n * Title for the page.\n */\n title: string;\n\n /**\n * By default, `Pipeline` will log the current phase to console.\n */\n debugName: string;\n\n /**\n * This is crucial for different `Pipeline`s to differentiate each other and avoiding conflict.\n *\n * Example for parent path: `/`, `/about`, `/projects`,...\n */\n parentPath: string;\n\n /**\n * By default, this value is `true`\n *\n * When navigating off of a previous `Pipeline`. It will stop lenis as a clean up.\n *\n * So when a new `Pipeline` takes in, it will enable lenis immediately when `contentReady` is switched to `true`.\n *\n * Set to `false` to gain manual control over when lenis will start. This does not affect to stop mechanism,\n * you don't have to clean up yourself.\n */\n autoStartLenis?: boolean;\n}\n\n/**\n * A core part of an in-house tool called `weaver`.\n *\n * `Pipeline`: Notifies & reflect changes to/from `LoadingFallback`\n * and `DelayedOutlet` about its page loading status.\n *\n * All parent routes must have `Pipeline` in order to work and sync with `DelayedOutlet`.\n */\nexport default function Pipeline(props: PipelineProps) {\n const { children, ...restOfProps } = props;\n return (\n <>\n <RouteHandler {...restOfProps} />\n {children}\n </>\n );\n}\n\nfunction RouteHandler(props: Omit<PipelineProps, 'children'>) {\n const navigating = useWeaverContext((state) => state.navigating);\n const pageRendered = useWeaverContext((state) => state.pageRendered);\n const activeParent = useWeaverContext((state) => state.activeParent);\n\n const setActivePipeline = useWeaverContext(\n (state) => state.setActivePipeline\n );\n const setPageRendered = useWeaverContext((state) => state.setPageRendered);\n const setActiveParent = useWeaverContext((state) => state.setActiveParent);\n\n useLayoutEffect(() => {\n document.title = props.title;\n setActivePipeline(props.parentPath);\n\n if (props.contentReady !== undefined && !props.contentReady) {\n console.log(`[${props.debugName}] Renderer status: Loading scene`);\n return;\n }\n\n if (!navigating && (!pageRendered || activeParent !== props.parentPath)) {\n if (props.autoStartLenis === undefined || props.autoStartLenis) {\n lenisInstance!.start();\n }\n\n setPageRendered(true);\n setActiveParent(props.parentPath);\n\n console.log(`[${props.debugName}] Renderer status: Mounted`);\n }\n }, [\n activeParent,\n setActivePipeline,\n navigating,\n pageRendered,\n props.autoStartLenis,\n props.contentReady,\n props.debugName,\n props.parentPath,\n props.title,\n setActiveParent,\n setPageRendered,\n ]);\n\n useLayoutEffectOnce(() => {\n return () => {\n /**\n * When unmounted, stop lenis to pass control to another Pipline instance.\n *\n * The unmount process only happens when the `<LoadingFallback />` kicks in,\n * so any visual glitches can happen in here, we can now set the scroll position to 0.\n */\n lenisInstance!.stop();\n lenisInstance!.scrollTo(0, { immediate: true, force: true });\n\n console.log(`[${props.debugName}] Renderer status: Unmounted`);\n };\n });\n\n return null;\n}\n","import { useEffect, useLayoutEffect } from 'react';\n\nexport function useEffectOnce(callback: React.EffectCallback) {\n // eslint-disable-next-line react-hooks/exhaustive-deps\n useEffect(callback, []);\n}\n\nexport function useLayoutEffectOnce(callback: React.EffectCallback) {\n // eslint-disable-next-line react-hooks/exhaustive-deps\n useLayoutEffect(callback, []);\n}\n","import Lenis from 'lenis';\nimport { ReactNode } from 'react';\n\nexport let lenisInstance: Lenis | undefined = undefined;\n\nexport type BasicTunnelIn = ({ children }: { children: ReactNode }) => null;\nexport let Default3DTunnelIn: BasicTunnelIn | undefined = undefined;\n\nexport const weaverSetup = {\n setLenisInstance(instance: Lenis) {\n lenisInstance = instance;\n },\n set3DTunnel(tunnelIn: BasicTunnelIn) {\n Default3DTunnelIn = tunnelIn;\n },\n};\n","import { useWeaverContext, WeaverContextGetter } from './context';\nimport DelayedOutlet from './DelayedOutlet';\nimport Pipeline from './Pipeline';\n\n/// A read-only state for reacting with changes reflected by weaver.\nexport const useWeaverState = (givenState: keyof WeaverContextGetter) => {\n const state = useWeaverContext((state) => state[givenState]);\n return state;\n};\n\nexport { DelayedOutlet, Pipeline };\n"],"mappings":";AAAA,SAAS,cAAc;AAqChB,IAAM,mBAAmB,OAE9B,EAAE,CAAC,SAAS;AAAA,EACZ,cAAc;AAAA,EACd,iBAAiB,CAAC,iBAAiB,IAAI,EAAE,aAAa,CAAC;AAAA,EAEvD,gBAAgB;AAAA,EAChB,mBAAmB,CAAC,mBAAmB,IAAI,EAAE,eAAe,CAAC;AAAA,EAE7D,YAAY;AAAA,EACZ,eAAe,CAAC,eAAe,IAAI,EAAE,WAAW,CAAC;AAAA,EAEjD,cAAc;AAAA,EACd,iBAAiB,CAAC,iBAAiB,IAAI,EAAE,aAAa,CAAC;AACzD,EAAE;;;ACnDF,SAAyB,mBAAAA,kBAAiB,QAAQ,gBAAgB;AAClE,SAAS,iBAAiB;;;ACD1B,SAAS,aAAa,uBAAuB;AAC7C,SAAS,aAAa,mBAAmB;AAElC,SAAS,mBAAmB,SAAmC;AACpE,QAAM,EAAE,SAAS,IAAI,YAAY;AACjC,QAAM,WAAW,YAAY;AAE7B,QAAM,aAAa;AAAA,IACjB,CAAC,UAAkB,MAAM,QAAQ,UAAU,MAAM,GAAG;AAAA,IACpD,CAAC;AAAA,EACH;AAEA,kBAAgB,MAAM;AACpB,UAAM,SAAS,WAAW,QAAQ;AAClC,QAAI,QAAQ,eAA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IACA,MAAM;AAAA,IACN,MAAM;AAAA,IACN,MAAM;AAAA,IACN,MAAM;AAAA,IACN,MAAM;AAAA,IACN;AAAA,IACA;AAAA,EACF,CAAC;AAED,sBAAoB,MAAM;AACxB,WAAO,MAAM;AAOX,oBAAe,KAAK;AACpB,oBAAe,SAAS,GAAG,EAAE,WAAW,MAAM,OAAO,KAAK,CAAC;AAE3D,cAAQ,IAAI,IAAI,MAAM,SAAS,8BAA8B;AAAA,IAC/D;AAAA,EACF,CAAC;AAED,SAAO;AACT;;;AG1HO,IAAM,iBAAiB,CAAC,eAA0C;AACvE,QAAM,QAAQ,iBAAiB,CAACC,WAAUA,OAAM,UAAU,CAAC;AAC3D,SAAO;AACT;","names":["useLayoutEffect","useLayoutEffect","useLayoutEffect","useLayoutEffect","useLayoutEffect","useLayoutEffect","state"]}
package/dist/scene.d.mts CHANGED
@@ -1,5 +1,5 @@
1
1
  import React, { ReactNode, Dispatch, SetStateAction, RefObject } from 'react';
2
- import { BasicTunnelIn } from './index.mjs';
2
+ import { B as BasicTunnelIn } from './index-BRbPCByN.mjs';
3
3
  import 'lenis';
4
4
 
5
5
  /**
package/dist/scene.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import React, { ReactNode, Dispatch, SetStateAction, RefObject } from 'react';
2
- import { BasicTunnelIn } from './index.js';
2
+ import { B as BasicTunnelIn } from './index-BRbPCByN.js';
3
3
  import 'lenis';
4
4
 
5
5
  /**
package/dist/scene.js CHANGED
@@ -39,7 +39,7 @@ module.exports = __toCommonJS(scene_exports);
39
39
  var import_fiber = require("@react-three/fiber");
40
40
  var import_react = __toESM(require("react"));
41
41
 
42
- // src/index.ts
42
+ // src/setup.ts
43
43
  var lenisInstance = void 0;
44
44
  var Default3DTunnelIn = void 0;
45
45
 
package/dist/scene.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/scene/index.ts","../src/scene/BakeScene.tsx","../src/index.ts","../src/scene/SceneSync.tsx","../src/hooks/effectOnce.ts","../src/hooks/lenisCallback.ts","../src/hooks/orbit.ts"],"sourcesContent":["import BakeScene from './BakeScene';\nimport SceneSync from './SceneSync';\n\nexport { BakeScene, SceneSync };\n","import { useFrame } from '@react-three/fiber';\nimport React, {\n type Dispatch,\n Fragment,\n type ReactNode,\n type SetStateAction,\n useId,\n useRef,\n} from 'react';\nimport { BasicTunnelIn, Default3DTunnelIn } from '../';\n\n/**\n * A core part of an in-house tool called `weaver`.\n *\n * `BakeScene`: This component will notifiy when the global 3D scene is ready.\n *\n * It works by tune in the `useFrame` from `@react-three/fiber`. When the scene is loaded, `useFreame` will fire\n * with ease, the component takes advantage of that, and because `useLoader` is unreliable.\n *\n * This component also accepts 3D elements `children` to be rendered directly to the canvas with some camera options.\n * But you don't have to put every 3D components inside the baker, for example, `SceneSync`s in the page are also\n * being watched by this component.\n *\n * The route renderer **CAN'T** detect if the page has 3D elements or not, so if a page uses any sort of 3D rendering,\n * this component **MUST** be a children iniside `Pipeline` (`index.tsx`), then pass the state value that bake changes\n * to `Pipeline`'s `contentReady` in order for the `BakeScene` to work behind loading fallback screen.\n */\nexport default function BakeScene(props: {\n children?: ReactNode;\n sceneReady: boolean;\n tunnelIn: BasicTunnelIn;\n loadTaskDelay?: number;\n setSceneReady: Dispatch<SetStateAction<boolean>>;\n onReady?: () => void;\n}) {\n const unique = useId();\n const pipeObjects = useId();\n\n const TunnelIn = props.tunnelIn ?? Default3DTunnelIn;\n\n if (!TunnelIn) {\n throw Error(\n 'Failed to find a tunnel to use. Consider setting a default tunnel.'\n );\n }\n\n return (\n <TunnelIn>\n <Fragment key={pipeObjects}>{props.children}</Fragment>\n <NotificationHandler\n key={unique}\n callback={props.onReady}\n sceneReady={props.sceneReady}\n setSceneReady={props.setSceneReady}\n />\n </TunnelIn>\n );\n}\n\nfunction NotificationHandler(props: {\n callback?: (isSceneReady: boolean) => void;\n sceneReady: boolean;\n setSceneReady: (value: boolean) => void;\n}) {\n /**\n * `useFrame` is expensive for something that only triggers once, so yea,\n * we'll remove the notification as soon as the job is done.\n */\n return !props.sceneReady && <RenderNotification {...props} />;\n}\n\nfunction RenderNotification(props: {\n callback?: (isSceneReady: boolean) => void;\n sceneReady: boolean;\n loadTaskDelay?: number;\n setSceneReady: (value: boolean) => void;\n}) {\n const scheduledForCallback = useRef(false);\n\n useFrame(() => {\n if (!props.sceneReady && !scheduledForCallback.current) {\n scheduledForCallback.current = true;\n setTimeout(() => {\n if (props.callback) {\n props.callback(true);\n }\n props.setSceneReady(true);\n }, props.loadTaskDelay ?? 50);\n }\n });\n\n return null;\n}\n","import Lenis from 'lenis';\nimport { ReactNode } from 'react';\n\nexport let lenisInstance: Lenis | undefined = undefined;\n\nexport type BasicTunnelIn = ({ children }: { children: ReactNode }) => null;\nexport let Default3DTunnelIn: BasicTunnelIn | undefined = undefined;\n\nexport const weaverSetup = {\n setLenisInstance(instance: Lenis) {\n lenisInstance = instance;\n },\n set3DTunnel(tunnelIn: BasicTunnelIn) {\n Default3DTunnelIn = tunnelIn;\n },\n};\n","import { Hud } from '@react-three/drei';\nimport { useThree, type Viewport } from '@react-three/fiber';\nimport { cancelFrame, frame } from 'motion/react';\nimport React, {\n type ReactNode,\n type RefObject,\n useCallback,\n useId,\n useLayoutEffect,\n useRef,\n useState,\n} from 'react';\nimport { Group } from 'three';\nimport { BasicTunnelIn, Default3DTunnelIn, lenisInstance } from '../';\nimport { useLayoutEffectOnce } from '../hooks/effectOnce';\nimport { useLenisCallback } from '../hooks/lenisCallback';\nimport { useOrbit } from '../hooks/orbit';\n\nexport type Basic3DTransforms = {\n scale: {\n set: (x: number, y: number, z: number) => void;\n };\n position: {\n x: number;\n y: number;\n };\n};\n\ninterface SyncProps {\n /**\n * HTML element ref that `<SceneSync />` will use to sync with the scene.\n *\n * ```tsx\n * <div ref={container} />\n * <SceneSync attach={container}>\n * <group />\n * </SceneSync>\n * ```\n */\n attach: RefObject<HTMLElement | null>;\n\n /**\n * This variable allows fine-grain control over your scene when passed to `<SceneSync />`.\n *\n * `<SceneSync />` will use its own ref and group when creating your scene to control its scale and position.\n * Setting this variable will disable the internal ref, and you can decide on which object gets controlled.\n *\n * This variable is needed for `hud` if you wanted to add a custom camera.\n *\n * For listening to change details, use `onLayoutChange` instead.\n */\n control?: RefObject<Basic3DTransforms | null>;\n\n /**\n * When this variable is set, `<SceneSync />` will send updates when the scene update its positions.\n *\n * The function return the calculated DOM rect, with dimension and position in 3D measurements.\n */\n onLayoutUpdate?: (\n rect: DOMRect,\n dimension: { w: number; h: number },\n position: { x: number; y: number }\n ) => void;\n\n /**\n * Use `Hud` for this scene or not.\n *\n * This is useful when you want to apply custom camera for this scene, or renders multiple scenes on each other.\n *\n * NOTE: When setting a custom camera, the `control` variable must also be set and mount to your scene, not related to the camera\n * to avoid unwanted behavior.\n *\n * `<SceneSync />` groups children passed to it by default, so the camera is also in the group, when syncer updates the group,\n * the camera is also change, ruining the effect.\n */\n hud?: boolean;\n\n /**\n * Control the scene's scaling when positioning.\n */\n scaleFactor?: number;\n\n /**\n * `<SceneSync />` avoid stretching the object by default by using the smallest dimension of the DOM element.\n *\n * This variable will tell `<SceneSync />` to stretch it anyways.\n */\n stretch?: boolean;\n\n /**\n * Disable automatic scaling on the object.\n *\n * This variable will also disable any scaling settings like `stretch` and `scaleFactor`.\n */\n disableScaling?: boolean;\n\n /**\n * `<SceneSync />` will depend on this variable to adjust how it should update.\n *\n * There are 3 modes: `relaxed`, `balanced` and `aggressive`.\n *\n * For each mode, there will be some very distinct trade-offs\n *\n * - `relaxed`: Uses IntersectionObserver paired with a scroll hook, together with ResizeObserver.\n * - (+): Minimal update calls, best performance.\n * - (-): The scene get desynced the moment DOM element moves without changing its sizes.\n * When the scene bleeds out of the DOM element too much, if IntersectionObserver reported that the DOM element\n * is out of view, the scene that did not fully moved out of view will stay there, as scroll hook will be disabled.\n * - `balanced`: Uses IntersectionObserver paired with frame-based update, together with ResizeObserver.\n * - (+): Just enough update calls to allow the DOM element to move freely while maintain aceptable performance.\n * - (-): It will update on every frame when the object gets into view as reported by IntersectionObserver. And the same\n * problem with `relaxed` mode when the scene bleeds out too much.\n * - `aggressive`: Frame-based update only. This mode is like how `<View />` from `@react-three/drei` kepts track of DOM elements.\n * - (+): Designed for precise element <-> scene updates. Can't be desynced, if desynced, that's a bug.\n * - (-): This is frame-based. It will fire updates as long as the scene is still mounted. Too many scenes with this\n * mode enabled is not a good idea. Acceptable amount would be 3 scenes with this mode.\n *\n * Best of both worlds is `balanced` mode, for simpler scenes that doesn't change its position, `relaxed` should be used.\n */\n trackingMode: 'relaxed' | 'balanced' | 'aggressive';\n\n /**\n * Set a custom tunnel for `<SceneSync />` send the components to for this scene only.\n *\n * Which is useful for example, put the objects inside a container in the scene.\n *\n * To set a default tunnel, pass it to `setDefaulTunnel` before use.\n */\n tunnelIn?: BasicTunnelIn;\n\n children: ReactNode;\n}\n\ninterface HudProps extends SyncProps {\n hud: true;\n /**\n * Set the `renderPriority` to render things for `Hud`.\n *\n * This variable is ignored when `hud` is not `true`.\n */\n hudRenderPriority: number;\n}\n\ninterface NormalProps extends SyncProps {\n hud?: false;\n}\n\n/**\n * A core part of an in-house tool called `weaver`.\n *\n * A component to allow three objects to track and sync with DOM element.\n *\n * The component uses `<Hud />` under the \"hud\", so if you want to use more than one `<SceneSync />`,\n * you must set `renderPriority`. If not, the component will render the last scene pushed through React.\n */\nexport default function SceneSync(props: NormalProps | HudProps) {\n const unique = useId();\n\n const TunnelIn = props.tunnelIn ?? Default3DTunnelIn;\n\n if (!TunnelIn) {\n throw Error(\n 'Failed to find a tunnel to use. Consider setting a default tunnel.'\n );\n }\n\n if (props.hud) {\n return (\n <TunnelIn>\n <Hud key={unique} renderPriority={props.hudRenderPriority}>\n <SyncInternal {...props} />\n </Hud>\n </TunnelIn>\n );\n }\n\n return (\n <TunnelIn>\n <SyncInternal key={unique} {...props} />\n </TunnelIn>\n );\n}\n\nfunction SyncInternal(props: SyncProps) {\n const { viewport, camera } = useThree();\n\n const defaultControl = useRef<Group>(null);\n const {\n attach,\n control,\n scaleFactor,\n stretch,\n disableScaling,\n onLayoutUpdate,\n } = props;\n\n const properties: RefObject<{\n viewport?: Omit<Viewport, 'dpr' | 'initialDpr'>;\n }> = useRef({\n viewport: undefined,\n });\n\n const updatePosition = useCallback(() => {\n const activeControl = control ?? defaultControl;\n\n const vp = properties.current.viewport;\n if (!vp) return;\n\n const domRect = attach.current!.getBoundingClientRect();\n const screenH = document.documentElement.clientHeight;\n const screenW = document.body.clientWidth;\n\n const vpWidthRatio = vp.width / screenW;\n const vpHeightRatio = vp.height / screenH;\n\n const scrollOffset = (lenisInstance!.actualScroll / screenH) * vp.height;\n\n const w = domRect.width * vpWidthRatio;\n const h = domRect.height * vpHeightRatio;\n\n const x = domRect.x * vpWidthRatio + w * 0.5 - vp.width * 0.5;\n const y =\n vp.height * 0.5 -\n (domRect.y + lenisInstance!.actualScroll) * vpHeightRatio -\n h * 0.5 +\n scrollOffset;\n\n if (onLayoutUpdate) {\n onLayoutUpdate(domRect, { w, h }, { x, y });\n }\n\n const unwrapedScaleFactor = scaleFactor ?? 1;\n\n if (!disableScaling) {\n if (!stretch) {\n const minScale = Math.min(w, h) * unwrapedScaleFactor;\n activeControl.current!.scale.set(minScale, minScale, minScale);\n } else {\n activeControl.current!.scale.set(\n w * unwrapedScaleFactor,\n h * unwrapedScaleFactor,\n Math.min(w, h) * unwrapedScaleFactor\n );\n }\n }\n\n // eslint-disable-next-line react-hooks/immutability\n activeControl.current!.position.x = x;\n activeControl.current!.position.y = y;\n }, [attach, onLayoutUpdate, control, scaleFactor, disableScaling, stretch]);\n\n /**\n * Update position when `camera` changes.\n */\n useLayoutEffect(() => {\n properties.current.viewport = viewport.getCurrentViewport(camera);\n updatePosition();\n }, [camera, updatePosition, viewport]);\n\n const graceUpdate = useCallback(() => {\n try {\n updatePosition();\n } catch {\n /* empty */\n }\n }, [updatePosition]);\n\n const mode = {\n relaxed: (\n <RelaxedUpdate attach={props.attach} updatePosition={graceUpdate} />\n ),\n balanced: (\n <BalancedUpdate attach={props.attach} updatePosition={graceUpdate} />\n ),\n aggressive: <AggressiveUpdate updatePosition={graceUpdate} />,\n };\n\n if (props.control) {\n return (\n <>\n {props.children}\n {mode[props.trackingMode]}\n </>\n );\n }\n\n return (\n <group ref={defaultControl}>\n {props.children}\n {mode[props.trackingMode]}\n </group>\n );\n}\n\nfunction RelaxedUpdate(props: {\n attach: RefObject<HTMLElement | null>;\n updatePosition: () => void;\n}) {\n const { updatePosition } = props;\n\n /**\n * Scroll hook to update object correctly to the current HTML scroll position.\n */\n useLenisCallback(updatePosition, {\n initialCall: true,\n intersectOn: props.attach,\n });\n\n /**\n * Allows the element to resize too.\n */\n useOrbit({\n target: props.attach,\n events: {\n onIntersect: updatePosition,\n onResize: updatePosition,\n },\n });\n\n useLayoutEffectOnce(updatePosition);\n return null;\n}\n\nfunction BalancedUpdate(props: {\n attach: RefObject<HTMLElement | null>;\n updatePosition: () => void;\n}) {\n const { updatePosition } = props;\n\n const [shouldUpdate, setShouldUpdate] = useState(false);\n\n useOrbit({\n target: props.attach,\n events: {\n onIntersect(entry) {\n setShouldUpdate(entry.isIntersecting);\n },\n onResize: updatePosition,\n },\n rootMargin: '50% 0px 50% 0px',\n });\n\n useLayoutEffect(() => {\n if (shouldUpdate) {\n frame.read(updatePosition, true);\n } else {\n cancelFrame(updatePosition);\n }\n\n return () => {\n cancelFrame(updatePosition);\n };\n }, [updatePosition, shouldUpdate]);\n\n useLayoutEffectOnce(updatePosition);\n return null;\n}\n\nfunction AggressiveUpdate(props: { updatePosition: () => void }) {\n const { updatePosition } = props;\n\n useLayoutEffect(() => {\n frame.read(updatePosition, true);\n\n return () => {\n cancelFrame(updatePosition);\n };\n }, [updatePosition]);\n\n return null;\n}\n","import { useEffect, useLayoutEffect } from 'react';\n\nexport function useEffectOnce(callback: React.EffectCallback) {\n // eslint-disable-next-line react-hooks/exhaustive-deps\n useEffect(callback, []);\n}\n\nexport function useLayoutEffectOnce(callback: React.EffectCallback) {\n // eslint-disable-next-line react-hooks/exhaustive-deps\n useLayoutEffect(callback, []);\n}\n","import { type RefObject, useCallback, useLayoutEffect, useMemo } from 'react';\nimport { lenisInstance } from '..';\nimport { useOrbit } from './orbit';\n\ninterface HookOptions {\n /**\n * Hook will report when first initialized without waiting for scroll event to actually happens.\n */\n initialCall?: boolean;\n /**\n * Set an element to only call when the element is actually entering the viewport (with 25% `rootMargin`).\n */\n intersectOn?: RefObject<HTMLOrSVGElement | null>;\n}\n\nexport const scrollCallbackReason = {\n Resize: 'resize',\n Scroll: 'scroll',\n Initialize: 'initialize',\n} as const;\nexport type ScrollCallbackReason =\n (typeof scrollCallbackReason)[keyof typeof scrollCallbackReason];\n\ntype Callback = (latest: number, reason: ScrollCallbackReason) => void;\n\nexport function useLenisCallback(callback: Callback, options?: HookOptions) {\n const callbackWrapScroll = useCallback(\n () => callback(lenisInstance!.actualScroll, scrollCallbackReason.Scroll),\n [callback]\n );\n const callbackWrapResize = useCallback(\n () => callback(lenisInstance!.actualScroll, scrollCallbackReason.Resize),\n [callback]\n );\n\n const intersectOn = useMemo(\n () => options?.intersectOn,\n [options?.intersectOn]\n );\n const initialCall = useMemo(\n () => options?.initialCall,\n [options?.initialCall]\n );\n\n useOrbit({\n target: intersectOn as RefObject<HTMLElement | null> | undefined,\n events: {\n onIntersect(entry) {\n if (entry.isIntersecting) {\n lenisInstance!.on('scroll', callbackWrapScroll);\n window.addEventListener('resize', callbackWrapResize);\n } else {\n lenisInstance!.off('scroll', callbackWrapScroll);\n window.removeEventListener('resize', callbackWrapResize);\n }\n },\n },\n rootMargin: '50% 0px 50% 0px',\n });\n\n useLayoutEffect(() => {\n if (!intersectOn) {\n lenisInstance!.on('scroll', callbackWrapScroll);\n window.addEventListener('resize', callbackWrapResize);\n }\n\n if (initialCall) {\n callback(lenisInstance!.actualScroll, scrollCallbackReason.Initialize);\n }\n\n return () => {\n lenisInstance!.off('scroll', callbackWrapScroll);\n window.removeEventListener('resize', callbackWrapResize);\n };\n }, [\n callback,\n callbackWrapResize,\n callbackWrapScroll,\n initialCall,\n intersectOn,\n ]);\n}\n","import { type RefObject, useLayoutEffect } from 'react';\n\n/**\n * A simple Orbit hook.\n *\n * @param target HTML element ref to attach to.\n * @param events Specify which events should the orbit tracks.\n */\nexport function useOrbit(options: {\n target?: RefObject<HTMLElement | null>;\n events: {\n onResize?: (entry: ResizeObserverEntry) => void;\n onIntersect?: (entry: IntersectionObserverEntry) => void;\n };\n rootMargin?: string;\n}) {\n const { onResize, onIntersect } = options.events;\n const { rootMargin = '25% 0px 25% 0px' } = options;\n\n useLayoutEffect(() => {\n if (!options.target) return;\n if (!options.target.current) return;\n\n let orbitResize = undefined;\n if (onResize) {\n orbitResize = new ResizeObserver((entries) => onResize(entries[0]));\n orbitResize.observe(options.target.current);\n }\n let orbitIntersect = undefined;\n if (onIntersect) {\n orbitIntersect = new IntersectionObserver(\n (entries) => onIntersect(entries[0]),\n { rootMargin }\n );\n orbitIntersect.observe(options.target.current);\n }\n\n return () => {\n orbitResize?.disconnect();\n orbitIntersect?.disconnect();\n };\n }, [onIntersect, onResize, rootMargin, options.target]);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAAyB;AACzB,mBAOO;;;ACLA,IAAI,gBAAmC;AAGvC,IAAI,oBAA+C;;;ADqB3C,SAAR,UAA2B,OAO/B;AACD,QAAM,aAAS,oBAAM;AACrB,QAAM,kBAAc,oBAAM;AAE1B,QAAM,WAAW,MAAM,YAAY;AAEnC,MAAI,CAAC,UAAU;AACb,UAAM;AAAA,MACJ;AAAA,IACF;AAAA,EACF;AAEA,SACE,6BAAAA,QAAA,cAAC,gBACC,6BAAAA,QAAA,cAAC,yBAAS,KAAK,eAAc,MAAM,QAAS,GAC5C,6BAAAA,QAAA;AAAA,IAAC;AAAA;AAAA,MACC,KAAK;AAAA,MACL,UAAU,MAAM;AAAA,MAChB,YAAY,M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AG,CAAC,cAAc,CAAC;AAEnB,SAAO;AACT;","names":["React","import_fiber","import_react","import_react","import_react","import_react","React"]}
1
+ {"version":3,"sources":["../src/scene/index.ts","../src/scene/BakeScene.tsx","../src/setup.ts","../src/scene/SceneSync.tsx","../src/hooks/effectOnce.ts","../src/hooks/lenisCallback.ts","../src/hooks/orbit.ts"],"sourcesContent":["import BakeScene from './BakeScene';\nimport SceneSync from './SceneSync';\n\nexport { BakeScene, SceneSync };\n","import { useFrame } from '@react-three/fiber';\nimport React, {\n type Dispatch,\n Fragment,\n type ReactNode,\n type SetStateAction,\n useId,\n useRef,\n} from 'react';\nimport { BasicTunnelIn, Default3DTunnelIn } from '../setup';\n\n/**\n * A core part of an in-house tool called `weaver`.\n *\n * `BakeScene`: This component will notifiy when the global 3D scene is ready.\n *\n * It works by tune in the `useFrame` from `@react-three/fiber`. When the scene is loaded, `useFreame` will fire\n * with ease, the component takes advantage of that, and because `useLoader` is unreliable.\n *\n * This component also accepts 3D elements `children` to be rendered directly to the canvas with some camera options.\n * But you don't have to put every 3D components inside the baker, for example, `SceneSync`s in the page are also\n * being watched by this component.\n *\n * The route renderer **CAN'T** detect if the page has 3D elements or not, so if a page uses any sort of 3D rendering,\n * this component **MUST** be a children iniside `Pipeline` (`index.tsx`), then pass the state value that bake changes\n * to `Pipeline`'s `contentReady` in order for the `BakeScene` to work behind loading fallback screen.\n */\nexport default function BakeScene(props: {\n children?: ReactNode;\n sceneReady: boolean;\n tunnelIn: BasicTunnelIn;\n loadTaskDelay?: number;\n setSceneReady: Dispatch<SetStateAction<boolean>>;\n onReady?: () => void;\n}) {\n const unique = useId();\n const pipeObjects = useId();\n\n const TunnelIn = props.tunnelIn ?? Default3DTunnelIn;\n\n if (!TunnelIn) {\n throw Error(\n 'Failed to find a tunnel to use. Consider setting a default tunnel.'\n );\n }\n\n return (\n <TunnelIn>\n <Fragment key={pipeObjects}>{props.children}</Fragment>\n <NotificationHandler\n key={unique}\n callback={props.onReady}\n sceneReady={props.sceneReady}\n setSceneReady={props.setSceneReady}\n />\n </TunnelIn>\n );\n}\n\nfunction NotificationHandler(props: {\n callback?: (isSceneReady: boolean) => void;\n sceneReady: boolean;\n setSceneReady: (value: boolean) => void;\n}) {\n /**\n * `useFrame` is expensive for something that only triggers once, so yea,\n * we'll remove the notification as soon as the job is done.\n */\n return !props.sceneReady && <RenderNotification {...props} />;\n}\n\nfunction RenderNotification(props: {\n callback?: (isSceneReady: boolean) => void;\n sceneReady: boolean;\n loadTaskDelay?: number;\n setSceneReady: (value: boolean) => void;\n}) {\n const scheduledForCallback = useRef(false);\n\n useFrame(() => {\n if (!props.sceneReady && !scheduledForCallback.current) {\n scheduledForCallback.current = true;\n setTimeout(() => {\n if (props.callback) {\n props.callback(true);\n }\n props.setSceneReady(true);\n }, props.loadTaskDelay ?? 50);\n }\n });\n\n return null;\n}\n","import Lenis from 'lenis';\nimport { ReactNode } from 'react';\n\nexport let lenisInstance: Lenis | undefined = undefined;\n\nexport type BasicTunnelIn = ({ children }: { children: ReactNode }) => null;\nexport let Default3DTunnelIn: BasicTunnelIn | undefined = undefined;\n\nexport const weaverSetup = {\n setLenisInstance(instance: Lenis) {\n lenisInstance = instance;\n },\n set3DTunnel(tunnelIn: BasicTunnelIn) {\n Default3DTunnelIn = tunnelIn;\n },\n};\n","import { Hud } from '@react-three/drei';\nimport { useThree, type Viewport } from '@react-three/fiber';\nimport { cancelFrame, frame } from 'motion/react';\nimport React, {\n type ReactNode,\n type RefObject,\n useCallback,\n useId,\n useLayoutEffect,\n useRef,\n useState,\n} from 'react';\nimport { Group } from 'three';\nimport { useLayoutEffectOnce } from '../hooks/effectOnce';\nimport { useLenisCallback } from '../hooks/lenisCallback';\nimport { useOrbit } from '../hooks/orbit';\nimport { BasicTunnelIn, Default3DTunnelIn, lenisInstance } from '../setup';\n\nexport type Basic3DTransforms = {\n scale: {\n set: (x: number, y: number, z: number) => void;\n };\n position: {\n x: number;\n y: number;\n };\n};\n\ninterface SyncProps {\n /**\n * HTML element ref that `<SceneSync />` will use to sync with the scene.\n *\n * ```tsx\n * <div ref={container} />\n * <SceneSync attach={container}>\n * <group />\n * </SceneSync>\n * ```\n */\n attach: RefObject<HTMLElement | null>;\n\n /**\n * This variable allows fine-grain control over your scene when passed to `<SceneSync />`.\n *\n * `<SceneSync />` will use its own ref and group when creating your scene to control its scale and position.\n * Setting this variable will disable the internal ref, and you can decide on which object gets controlled.\n *\n * This variable is needed for `hud` if you wanted to add a custom camera.\n *\n * For listening to change details, use `onLayoutChange` instead.\n */\n control?: RefObject<Basic3DTransforms | null>;\n\n /**\n * When this variable is set, `<SceneSync />` will send updates when the scene update its positions.\n *\n * The function return the calculated DOM rect, with dimension and position in 3D measurements.\n */\n onLayoutUpdate?: (\n rect: DOMRect,\n dimension: { w: number; h: number },\n position: { x: number; y: number }\n ) => void;\n\n /**\n * Use `Hud` for this scene or not.\n *\n * This is useful when you want to apply custom camera for this scene, or renders multiple scenes on each other.\n *\n * NOTE: When setting a custom camera, the `control` variable must also be set and mount to your scene, not related to the camera\n * to avoid unwanted behavior.\n *\n * `<SceneSync />` groups children passed to it by default, so the camera is also in the group, when syncer updates the group,\n * the camera is also change, ruining the effect.\n */\n hud?: boolean;\n\n /**\n * Control the scene's scaling when positioning.\n */\n scaleFactor?: number;\n\n /**\n * `<SceneSync />` avoid stretching the object by default by using the smallest dimension of the DOM element.\n *\n * This variable will tell `<SceneSync />` to stretch it anyways.\n */\n stretch?: boolean;\n\n /**\n * Disable automatic scaling on the object.\n *\n * This variable will also disable any scaling settings like `stretch` and `scaleFactor`.\n */\n disableScaling?: boolean;\n\n /**\n * `<SceneSync />` will depend on this variable to adjust how it should update.\n *\n * There are 3 modes: `relaxed`, `balanced` and `aggressive`.\n *\n * For each mode, there will be some very distinct trade-offs\n *\n * - `relaxed`: Uses IntersectionObserver paired with a scroll hook, together with ResizeObserver.\n * - (+): Minimal update calls, best performance.\n * - (-): The scene get desynced the moment DOM element moves without changing its sizes.\n * When the scene bleeds out of the DOM element too much, if IntersectionObserver reported that the DOM element\n * is out of view, the scene that did not fully moved out of view will stay there, as scroll hook will be disabled.\n * - `balanced`: Uses IntersectionObserver paired with frame-based update, together with ResizeObserver.\n * - (+): Just enough update calls to allow the DOM element to move freely while maintain aceptable performance.\n * - (-): It will update on every frame when the object gets into view as reported by IntersectionObserver. And the same\n * problem with `relaxed` mode when the scene bleeds out too much.\n * - `aggressive`: Frame-based update only. This mode is like how `<View />` from `@react-three/drei` kepts track of DOM elements.\n * - (+): Designed for precise element <-> scene updates. Can't be desynced, if desynced, that's a bug.\n * - (-): This is frame-based. It will fire updates as long as the scene is still mounted. Too many scenes with this\n * mode enabled is not a good idea. Acceptable amount would be 3 scenes with this mode.\n *\n * Best of both worlds is `balanced` mode, for simpler scenes that doesn't change its position, `relaxed` should be used.\n */\n trackingMode: 'relaxed' | 'balanced' | 'aggressive';\n\n /**\n * Set a custom tunnel for `<SceneSync />` send the components to for this scene only.\n *\n * Which is useful for example, put the objects inside a container in the scene.\n *\n * To set a default tunnel, pass it to `setDefaulTunnel` before use.\n */\n tunnelIn?: BasicTunnelIn;\n\n children: ReactNode;\n}\n\ninterface HudProps extends SyncProps {\n hud: true;\n /**\n * Set the `renderPriority` to render things for `Hud`.\n *\n * This variable is ignored when `hud` is not `true`.\n */\n hudRenderPriority: number;\n}\n\ninterface NormalProps extends SyncProps {\n hud?: false;\n}\n\n/**\n * A core part of an in-house tool called `weaver`.\n *\n * A component to allow three objects to track and sync with DOM element.\n *\n * The component uses `<Hud />` under the \"hud\", so if you want to use more than one `<SceneSync />`,\n * you must set `renderPriority`. If not, the component will render the last scene pushed through React.\n */\nexport default function SceneSync(props: NormalProps | HudProps) {\n const unique = useId();\n\n const TunnelIn = props.tunnelIn ?? Default3DTunnelIn;\n\n if (!TunnelIn) {\n throw Error(\n 'Failed to find a tunnel to use. Consider setting a default tunnel.'\n );\n }\n\n if (props.hud) {\n return (\n <TunnelIn>\n <Hud key={unique} renderPriority={props.hudRenderPriority}>\n <SyncInternal {...props} />\n </Hud>\n </TunnelIn>\n );\n }\n\n return (\n <TunnelIn>\n <SyncInternal key={unique} {...props} />\n </TunnelIn>\n );\n}\n\nfunction SyncInternal(props: SyncProps) {\n const { viewport, camera } = useThree();\n\n const defaultControl = useRef<Group>(null);\n const {\n attach,\n control,\n scaleFactor,\n stretch,\n disableScaling,\n onLayoutUpdate,\n } = props;\n\n const properties: RefObject<{\n viewport?: Omit<Viewport, 'dpr' | 'initialDpr'>;\n }> = useRef({\n viewport: undefined,\n });\n\n const updatePosition = useCallback(() => {\n const activeControl = control ?? defaultControl;\n\n const vp = properties.current.viewport;\n if (!vp) return;\n\n const domRect = attach.current!.getBoundingClientRect();\n const screenH = document.documentElement.clientHeight;\n const screenW = document.body.clientWidth;\n\n const vpWidthRatio = vp.width / screenW;\n const vpHeightRatio = vp.height / screenH;\n\n const scrollOffset = (lenisInstance!.actualScroll / screenH) * vp.height;\n\n const w = domRect.width * vpWidthRatio;\n const h = domRect.height * vpHeightRatio;\n\n const x = domRect.x * vpWidthRatio + w * 0.5 - vp.width * 0.5;\n const y =\n vp.height * 0.5 -\n (domRect.y + lenisInstance!.actualScroll) * vpHeightRatio -\n h * 0.5 +\n scrollOffset;\n\n if (onLayoutUpdate) {\n onLayoutUpdate(domRect, { w, h }, { x, y });\n }\n\n const unwrapedScaleFactor = scaleFactor ?? 1;\n\n if (!disableScaling) {\n if (!stretch) {\n const minScale = Math.min(w, h) * unwrapedScaleFactor;\n activeControl.current!.scale.set(minScale, minScale, minScale);\n } else {\n activeControl.current!.scale.set(\n w * unwrapedScaleFactor,\n h * unwrapedScaleFactor,\n Math.min(w, h) * unwrapedScaleFactor\n );\n }\n }\n\n // eslint-disable-next-line react-hooks/immutability\n activeControl.current!.position.x = x;\n activeControl.current!.position.y = y;\n }, [attach, onLayoutUpdate, control, scaleFactor, disableScaling, stretch]);\n\n /**\n * Update position when `camera` changes.\n */\n useLayoutEffect(() => {\n properties.current.viewport = viewport.getCurrentViewport(camera);\n updatePosition();\n }, [camera, updatePosition, viewport]);\n\n const graceUpdate = useCallback(() => {\n try {\n updatePosition();\n } catch {\n /* empty */\n }\n }, [updatePosition]);\n\n const mode = {\n relaxed: (\n <RelaxedUpdate attach={props.attach} updatePosition={graceUpdate} />\n ),\n balanced: (\n <BalancedUpdate attach={props.attach} updatePosition={graceUpdate} />\n ),\n aggressive: <AggressiveUpdate updatePosition={graceUpdate} />,\n };\n\n if (props.control) {\n return (\n <>\n {props.children}\n {mode[props.trackingMode]}\n </>\n );\n }\n\n return (\n <group ref={defaultControl}>\n {props.children}\n {mode[props.trackingMode]}\n </group>\n );\n}\n\nfunction RelaxedUpdate(props: {\n attach: RefObject<HTMLElement | null>;\n updatePosition: () => void;\n}) {\n const { updatePosition } = props;\n\n /**\n * Scroll hook to update object correctly to the current HTML scroll position.\n */\n useLenisCallback(updatePosition, {\n initialCall: true,\n intersectOn: props.attach,\n });\n\n /**\n * Allows the element to resize too.\n */\n useOrbit({\n target: props.attach,\n events: {\n onIntersect: updatePosition,\n onResize: updatePosition,\n },\n });\n\n useLayoutEffectOnce(updatePosition);\n return null;\n}\n\nfunction BalancedUpdate(props: {\n attach: RefObject<HTMLElement | null>;\n updatePosition: () => void;\n}) {\n const { updatePosition } = props;\n\n const [shouldUpdate, setShouldUpdate] = useState(false);\n\n useOrbit({\n target: props.attach,\n events: {\n onIntersect(entry) {\n setShouldUpdate(entry.isIntersecting);\n },\n onResize: updatePosition,\n },\n rootMargin: '50% 0px 50% 0px',\n });\n\n useLayoutEffect(() => {\n if (shouldUpdate) {\n frame.read(updatePosition, true);\n } else {\n cancelFrame(updatePosition);\n }\n\n return () => {\n cancelFrame(updatePosition);\n };\n }, [updatePosition, shouldUpdate]);\n\n useLayoutEffectOnce(updatePosition);\n return null;\n}\n\nfunction AggressiveUpdate(props: { updatePosition: () => void }) {\n const { updatePosition } = props;\n\n useLayoutEffect(() => {\n frame.read(updatePosition, true);\n\n return () => {\n cancelFrame(updatePosition);\n };\n }, [updatePosition]);\n\n return null;\n}\n","import { useEffect, useLayoutEffect } from 'react';\n\nexport function useEffectOnce(callback: React.EffectCallback) {\n // eslint-disable-next-line react-hooks/exhaustive-deps\n useEffect(callback, []);\n}\n\nexport function useLayoutEffectOnce(callback: React.EffectCallback) {\n // eslint-disable-next-line react-hooks/exhaustive-deps\n useLayoutEffect(callback, []);\n}\n","import { type RefObject, useCallback, useLayoutEffect, useMemo } from 'react';\nimport { lenisInstance } from '../setup';\nimport { useOrbit } from './orbit';\n\ninterface HookOptions {\n /**\n * Hook will report when first initialized without waiting for scroll event to actually happens.\n */\n initialCall?: boolean;\n /**\n * Set an element to only call when the element is actually entering the viewport (with 25% `rootMargin`).\n */\n intersectOn?: RefObject<HTMLOrSVGElement | null>;\n}\n\nexport const scrollCallbackReason = {\n Resize: 'resize',\n Scroll: 'scroll',\n Initialize: 'initialize',\n} as const;\nexport type ScrollCallbackReason =\n (typeof scrollCallbackReason)[keyof typeof scrollCallbackReason];\n\ntype Callback = (latest: number, reason: ScrollCallbackReason) => void;\n\nexport function useLenisCallback(callback: Callback, options?: HookOptions) {\n const callbackWrapScroll = useCallback(\n () => callback(lenisInstance!.actualScroll, scrollCallbackReason.Scroll),\n [callback]\n );\n const callbackWrapResize = useCallback(\n () => callback(lenisInstance!.actualScroll, scrollCallbackReason.Resize),\n [callback]\n );\n\n const intersectOn = useMemo(\n () => options?.intersectOn,\n [options?.intersectOn]\n );\n const initialCall = useMemo(\n () => options?.initialCall,\n [options?.initialCall]\n );\n\n useOrbit({\n target: intersectOn as RefObject<HTMLElement | null> | undefined,\n events: {\n onIntersect(entry) {\n if (entry.isIntersecting) {\n lenisInstance!.on('scroll', callbackWrapScroll);\n window.addEventListener('resize', callbackWrapResize);\n } else {\n lenisInstance!.off('scroll', callbackWrapScroll);\n window.removeEventListener('resize', callbackWrapResize);\n }\n },\n },\n rootMargin: '50% 0px 50% 0px',\n });\n\n useLayoutEffect(() => {\n if (!intersectOn) {\n lenisInstance!.on('scroll', callbackWrapScroll);\n window.addEventListener('resize', callbackWrapResize);\n }\n\n if (initialCall) {\n callback(lenisInstance!.actualScroll, scrollCallbackReason.Initialize);\n }\n\n return () => {\n lenisInstance!.off('scroll', callbackWrapScroll);\n window.removeEventListener('resize', callbackWrapResize);\n };\n }, [\n callback,\n callbackWrapResize,\n callbackWrapScroll,\n initialCall,\n intersectOn,\n ]);\n}\n","import { type RefObject, useLayoutEffect } from 'react';\n\n/**\n * A simple Orbit hook.\n *\n * @param target HTML element ref to attach to.\n * @param events Specify which events should the orbit tracks.\n */\nexport function useOrbit(options: {\n target?: RefObject<HTMLElement | null>;\n events: {\n onResize?: (entry: ResizeObserverEntry) => void;\n onIntersect?: (entry: IntersectionObserverEntry) => void;\n };\n rootMargin?: string;\n}) {\n const { onResize, onIntersect } = options.events;\n const { rootMargin = '25% 0px 25% 0px' } = options;\n\n useLayoutEffect(() => {\n if (!options.target) return;\n if (!options.target.current) return;\n\n let orbitResize = undefined;\n if (onResize) {\n orbitResize = new ResizeObserver((entries) => onResize(entries[0]));\n orbitResize.observe(options.target.current);\n }\n let orbitIntersect = undefined;\n if (onIntersect) {\n orbitIntersect = new IntersectionObserver(\n (entries) => onIntersect(entries[0]),\n { rootMargin }\n );\n orbitIntersect.observe(options.target.current);\n }\n\n return () => {\n orbitResize?.disconnect();\n orbitIntersect?.disconnect();\n };\n }, [onIntersect, onResize, rootMargin, options.target]);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAAyB;AACzB,mBAOO;;;ACLA,IAAI,gBAAmC;AAGvC,IAAI,oBAA+C;;;ADqB3C,SAAR,UAA2B,OAO/B;AACD,QAAM,aAAS,oBAAM;AACrB,QAAM,kBAAc,oBAAM;AAE1B,QAAM,WAAW,MAAM,YAAY;AAEnC,MAAI,CAAC,UAAU;AACb,UAAM;AAAA,MACJ;AAAA,IACF;AAAA,EACF;AAE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;AACT;AAEA,SAAS,iBAAiB,OAAuC;AAC/D,QAAM,EAAE,eAAe,IAAI;AAE3B,qCAAgB,MAAM;AACpB,wBAAM,KAAK,gBAAgB,IAAI;AAE/B,WAAO,MAAM;AACX,qCAAY,cAAc;AAAA,IAC5B;AAAA,EACF,GAAG,CAAC,cAAc,CAAC;AAEnB,SAAO;AACT;","names":["React","import_fiber","import_react","import_react","import_react","import_react","React"]}
package/dist/scene.mjs CHANGED
@@ -6,7 +6,7 @@ import React, {
6
6
  useRef
7
7
  } from "react";
8
8
 
9
- // src/index.ts
9
+ // src/setup.ts
10
10
  var lenisInstance = void 0;
11
11
  var Default3DTunnelIn = void 0;
12
12
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/scene/BakeScene.tsx","../src/index.ts","../src/scene/SceneSync.tsx","../src/hooks/effectOnce.ts","../src/hooks/lenisCallback.ts","../src/hooks/orbit.ts"],"sourcesContent":["import { useFrame } from '@react-three/fiber';\nimport React, {\n type Dispatch,\n Fragment,\n type ReactNode,\n type SetStateAction,\n useId,\n useRef,\n} from 'react';\nimport { BasicTunnelIn, Default3DTunnelIn } from '../';\n\n/**\n * A core part of an in-house tool called `weaver`.\n *\n * `BakeScene`: This component will notifiy when the global 3D scene is ready.\n *\n * It works by tune in the `useFrame` from `@react-three/fiber`. When the scene is loaded, `useFreame` will fire\n * with ease, the component takes advantage of that, and because `useLoader` is unreliable.\n *\n * This component also accepts 3D elements `children` to be rendered directly to the canvas with some camera options.\n * But you don't have to put every 3D components inside the baker, for example, `SceneSync`s in the page are also\n * being watched by this component.\n *\n * The route renderer **CAN'T** detect if the page has 3D elements or not, so if a page uses any sort of 3D rendering,\n * this component **MUST** be a children iniside `Pipeline` (`index.tsx`), then pass the state value that bake changes\n * to `Pipeline`'s `contentReady` in order for the `BakeScene` to work behind loading fallback screen.\n */\nexport default function BakeScene(props: {\n children?: ReactNode;\n sceneReady: boolean;\n tunnelIn: BasicTunnelIn;\n loadTaskDelay?: number;\n setSceneReady: Dispatch<SetStateAction<boolean>>;\n onReady?: () => void;\n}) {\n const unique = useId();\n const pipeObjects = useId();\n\n const TunnelIn = props.tunnelIn ?? Default3DTunnelIn;\n\n if (!TunnelIn) {\n throw Error(\n 'Failed to find a tunnel to use. Consider setting a default tunnel.'\n );\n }\n\n return (\n <TunnelIn>\n <Fragment key={pipeObjects}>{props.children}</Fragment>\n <NotificationHandler\n key={unique}\n callback={props.onReady}\n sceneReady={props.sceneReady}\n setSceneReady={props.setSceneReady}\n />\n </TunnelIn>\n );\n}\n\nfunction NotificationHandler(props: {\n callback?: (isSceneReady: boolean) => void;\n sceneReady: boolean;\n setSceneReady: (value: boolean) => void;\n}) {\n /**\n * `useFrame` is expensive for something that only triggers once, so yea,\n * we'll remove the notification as soon as the job is done.\n */\n return !props.sceneReady && <RenderNotification {...props} />;\n}\n\nfunction RenderNotification(props: {\n callback?: (isSceneReady: boolean) => void;\n sceneReady: boolean;\n loadTaskDelay?: number;\n setSceneReady: (value: boolean) => void;\n}) {\n const scheduledForCallback = useRef(false);\n\n useFrame(() => {\n if (!props.sceneReady && !scheduledForCallback.current) {\n scheduledForCallback.current = true;\n setTimeout(() => {\n if (props.callback) {\n props.callback(true);\n }\n props.setSceneReady(true);\n }, props.loadTaskDelay ?? 50);\n }\n });\n\n return null;\n}\n","import Lenis from 'lenis';\nimport { ReactNode } from 'react';\n\nexport let lenisInstance: Lenis | undefined = undefined;\n\nexport type BasicTunnelIn = ({ children }: { children: ReactNode }) => null;\nexport let Default3DTunnelIn: BasicTunnelIn | undefined = undefined;\n\nexport const weaverSetup = {\n setLenisInstance(instance: Lenis) {\n lenisInstance = instance;\n },\n set3DTunnel(tunnelIn: BasicTunnelIn) {\n Default3DTunnelIn = tunnelIn;\n },\n};\n","import { Hud } from '@react-three/drei';\nimport { useThree, type Viewport } from '@react-three/fiber';\nimport { cancelFrame, frame } from 'motion/react';\nimport React, {\n type ReactNode,\n type RefObject,\n useCallback,\n useId,\n useLayoutEffect,\n useRef,\n useState,\n} from 'react';\nimport { Group } from 'three';\nimport { BasicTunnelIn, Default3DTunnelIn, lenisInstance } from '../';\nimport { useLayoutEffectOnce } from '../hooks/effectOnce';\nimport { useLenisCallback } from '../hooks/lenisCallback';\nimport { useOrbit } from '../hooks/orbit';\n\nexport type Basic3DTransforms = {\n scale: {\n set: (x: number, y: number, z: number) => void;\n };\n position: {\n x: number;\n y: number;\n };\n};\n\ninterface SyncProps {\n /**\n * HTML element ref that `<SceneSync />` will use to sync with the scene.\n *\n * ```tsx\n * <div ref={container} />\n * <SceneSync attach={container}>\n * <group />\n * </SceneSync>\n * ```\n */\n attach: RefObject<HTMLElement | null>;\n\n /**\n * This variable allows fine-grain control over your scene when passed to `<SceneSync />`.\n *\n * `<SceneSync />` will use its own ref and group when creating your scene to control its scale and position.\n * Setting this variable will disable the internal ref, and you can decide on which object gets controlled.\n *\n * This variable is needed for `hud` if you wanted to add a custom camera.\n *\n * For listening to change details, use `onLayoutChange` instead.\n */\n control?: RefObject<Basic3DTransforms | null>;\n\n /**\n * When this variable is set, `<SceneSync />` will send updates when the scene update its positions.\n *\n * The function return the calculated DOM rect, with dimension and position in 3D measurements.\n */\n onLayoutUpdate?: (\n rect: DOMRect,\n dimension: { w: number; h: number },\n position: { x: number; y: number }\n ) => void;\n\n /**\n * Use `Hud` for this scene or not.\n *\n * This is useful when you want to apply custom camera for this scene, or renders multiple scenes on each other.\n *\n * NOTE: When setting a custom camera, the `control` variable must also be set and mount to your scene, not related to the camera\n * to avoid unwanted behavior.\n *\n * `<SceneSync />` groups children passed to it by default, so the camera is also in the group, when syncer updates the group,\n * the camera is also change, ruining the effect.\n */\n hud?: boolean;\n\n /**\n * Control the scene's scaling when positioning.\n */\n scaleFactor?: number;\n\n /**\n * `<SceneSync />` avoid stretching the object by default by using the smallest dimension of the DOM element.\n *\n * This variable will tell `<SceneSync />` to stretch it anyways.\n */\n stretch?: boolean;\n\n /**\n * Disable automatic scaling on the object.\n *\n * This variable will also disable any scaling settings like `stretch` and `scaleFactor`.\n */\n disableScaling?: boolean;\n\n /**\n * `<SceneSync />` will depend on this variable to adjust how it should update.\n *\n * There are 3 modes: `relaxed`, `balanced` and `aggressive`.\n *\n * For each mode, there will be some very distinct trade-offs\n *\n * - `relaxed`: Uses IntersectionObserver paired with a scroll hook, together with ResizeObserver.\n * - (+): Minimal update calls, best performance.\n * - (-): The scene get desynced the moment DOM element moves without changing its sizes.\n * When the scene bleeds out of the DOM element too much, if IntersectionObserver reported that the DOM element\n * is out of view, the scene that did not fully moved out of view will stay there, as scroll hook will be disabled.\n * - `balanced`: Uses IntersectionObserver paired with frame-based update, together with ResizeObserver.\n * - (+): Just enough update calls to allow the DOM element to move freely while maintain aceptable performance.\n * - (-): It will update on every frame when the object gets into view as reported by IntersectionObserver. And the same\n * problem with `relaxed` mode when the scene bleeds out too much.\n * - `aggressive`: Frame-based update only. This mode is like how `<View />` from `@react-three/drei` kepts track of DOM elements.\n * - (+): Designed for precise element <-> scene updates. Can't be desynced, if desynced, that's a bug.\n * - (-): This is frame-based. It will fire updates as long as the scene is still mounted. Too many scenes with this\n * mode enabled is not a good idea. Acceptable amount would be 3 scenes with this mode.\n *\n * Best of both worlds is `balanced` mode, for simpler scenes that doesn't change its position, `relaxed` should be used.\n */\n trackingMode: 'relaxed' | 'balanced' | 'aggressive';\n\n /**\n * Set a custom tunnel for `<SceneSync />` send the components to for this scene only.\n *\n * Which is useful for example, put the objects inside a container in the scene.\n *\n * To set a default tunnel, pass it to `setDefaulTunnel` before use.\n */\n tunnelIn?: BasicTunnelIn;\n\n children: ReactNode;\n}\n\ninterface HudProps extends SyncProps {\n hud: true;\n /**\n * Set the `renderPriority` to render things for `Hud`.\n *\n * This variable is ignored when `hud` is not `true`.\n */\n hudRenderPriority: number;\n}\n\ninterface NormalProps extends SyncProps {\n hud?: false;\n}\n\n/**\n * A core part of an in-house tool called `weaver`.\n *\n * A component to allow three objects to track and sync with DOM element.\n *\n * The component uses `<Hud />` under the \"hud\", so if you want to use more than one `<SceneSync />`,\n * you must set `renderPriority`. If not, the component will render the last scene pushed through React.\n */\nexport default function SceneSync(props: NormalProps | HudProps) {\n const unique = useId();\n\n const TunnelIn = props.tunnelIn ?? Default3DTunnelIn;\n\n if (!TunnelIn) {\n throw Error(\n 'Failed to find a tunnel to use. Consider setting a default tunnel.'\n );\n }\n\n if (props.hud) {\n return (\n <TunnelIn>\n <Hud key={unique} renderPriority={props.hudRenderPriority}>\n <SyncInternal {...props} />\n </Hud>\n </TunnelIn>\n );\n }\n\n return (\n <TunnelIn>\n <SyncInternal key={unique} {...props} />\n </TunnelIn>\n );\n}\n\nfunction SyncInternal(props: SyncProps) {\n const { viewport, camera } = useThree();\n\n const defaultControl = useRef<Group>(null);\n const {\n attach,\n control,\n scaleFactor,\n stretch,\n disableScaling,\n onLayoutUpdate,\n } = props;\n\n const properties: RefObject<{\n viewport?: Omit<Viewport, 'dpr' | 'initialDpr'>;\n }> = useRef({\n viewport: undefined,\n });\n\n const updatePosition = useCallback(() => {\n const activeControl = control ?? defaultControl;\n\n const vp = properties.current.viewport;\n if (!vp) return;\n\n const domRect = attach.current!.getBoundingClientRect();\n const screenH = document.documentElement.clientHeight;\n const screenW = document.body.clientWidth;\n\n const vpWidthRatio = vp.width / screenW;\n const vpHeightRatio = vp.height / screenH;\n\n const scrollOffset = (lenisInstance!.actualScroll / screenH) * vp.height;\n\n const w = domRect.width * vpWidthRatio;\n const h = domRect.height * vpHeightRatio;\n\n const x = domRect.x * vpWidthRatio + w * 0.5 - vp.width * 0.5;\n const y =\n vp.height * 0.5 -\n (domRect.y + lenisInstance!.actualScroll) * vpHeightRatio -\n h * 0.5 +\n scrollOffset;\n\n if (onLayoutUpdate) {\n onLayoutUpdate(domRect, { w, h }, { x, y });\n }\n\n const unwrapedScaleFactor = scaleFactor ?? 1;\n\n if (!disableScaling) {\n if (!stretch) {\n const minScale = Math.min(w, h) * unwrapedScaleFactor;\n activeControl.current!.scale.set(minScale, minScale, minScale);\n } else {\n activeControl.current!.scale.set(\n w * unwrapedScaleFactor,\n h * unwrapedScaleFactor,\n Math.min(w, h) * unwrapedScaleFactor\n );\n }\n }\n\n // eslint-disable-next-line react-hooks/immutability\n activeControl.current!.position.x = x;\n activeControl.current!.position.y = y;\n }, [attach, onLayoutUpdate, control, scaleFactor, disableScaling, stretch]);\n\n /**\n * Update position when `camera` changes.\n */\n useLayoutEffect(() => {\n properties.current.viewport = viewport.getCurrentViewport(camera);\n updatePosition();\n }, [camera, updatePosition, viewport]);\n\n const graceUpdate = useCallback(() => {\n try {\n updatePosition();\n } catch {\n /* empty */\n }\n }, [updatePosition]);\n\n const mode = {\n relaxed: (\n <RelaxedUpdate attach={props.attach} updatePosition={graceUpdate} />\n ),\n balanced: (\n <BalancedUpdate attach={props.attach} updatePosition={graceUpdate} />\n ),\n aggressive: <AggressiveUpdate updatePosition={graceUpdate} />,\n };\n\n if (props.control) {\n return (\n <>\n {props.children}\n {mode[props.trackingMode]}\n </>\n );\n }\n\n return (\n <group ref={defaultControl}>\n {props.children}\n {mode[props.trackingMode]}\n </group>\n );\n}\n\nfunction RelaxedUpdate(props: {\n attach: RefObject<HTMLElement | null>;\n updatePosition: () => void;\n}) {\n const { updatePosition } = props;\n\n /**\n * Scroll hook to update object correctly to the current HTML scroll position.\n */\n useLenisCallback(updatePosition, {\n initialCall: true,\n intersectOn: props.attach,\n });\n\n /**\n * Allows the element to resize too.\n */\n useOrbit({\n target: props.attach,\n events: {\n onIntersect: updatePosition,\n onResize: updatePosition,\n },\n });\n\n useLayoutEffectOnce(updatePosition);\n return null;\n}\n\nfunction BalancedUpdate(props: {\n attach: RefObject<HTMLElement | null>;\n updatePosition: () => void;\n}) {\n const { updatePosition } = props;\n\n const [shouldUpdate, setShouldUpdate] = useState(false);\n\n useOrbit({\n target: props.attach,\n events: {\n onIntersect(entry) {\n setShouldUpdate(entry.isIntersecting);\n },\n onResize: updatePosition,\n },\n rootMargin: '50% 0px 50% 0px',\n });\n\n useLayoutEffect(() => {\n if (shouldUpdate) {\n frame.read(updatePosition, true);\n } else {\n cancelFrame(updatePosition);\n }\n\n return () => {\n cancelFrame(updatePosition);\n };\n }, [updatePosition, shouldUpdate]);\n\n useLayoutEffectOnce(updatePosition);\n return null;\n}\n\nfunction AggressiveUpdate(props: { updatePosition: () => void }) {\n const { updatePosition } = props;\n\n useLayoutEffect(() => {\n frame.read(updatePosition, true);\n\n return () => {\n cancelFrame(updatePosition);\n };\n }, [updatePosition]);\n\n return null;\n}\n","import { useEffect, useLayoutEffect } from 'react';\n\nexport function useEffectOnce(callback: React.EffectCallback) {\n // eslint-disable-next-line react-hooks/exhaustive-deps\n useEffect(callback, []);\n}\n\nexport function useLayoutEffectOnce(callback: React.EffectCallback) {\n // eslint-disable-next-line react-hooks/exhaustive-deps\n useLayoutEffect(callback, []);\n}\n","import { type RefObject, useCallback, useLayoutEffect, useMemo } from 'react';\nimport { lenisInstance } from '..';\nimport { useOrbit } from './orbit';\n\ninterface HookOptions {\n /**\n * Hook will report when first initialized without waiting for scroll event to actually happens.\n */\n initialCall?: boolean;\n /**\n * Set an element to only call when the element is actually entering the viewport (with 25% `rootMargin`).\n */\n intersectOn?: RefObject<HTMLOrSVGElement | null>;\n}\n\nexport const scrollCallbackReason = {\n Resize: 'resize',\n Scroll: 'scroll',\n Initialize: 'initialize',\n} as const;\nexport type ScrollCallbackReason =\n (typeof scrollCallbackReason)[keyof typeof scrollCallbackReason];\n\ntype Callback = (latest: number, reason: ScrollCallbackReason) => void;\n\nexport function useLenisCallback(callback: Callback, options?: HookOptions) {\n const callbackWrapScroll = useCallback(\n () => callback(lenisInstance!.actualScroll, scrollCallbackReason.Scroll),\n [callback]\n );\n const callbackWrapResize = useCallback(\n () => callback(lenisInstance!.actualScroll, scrollCallbackReason.Resize),\n [callback]\n );\n\n const intersectOn = useMemo(\n () => options?.intersectOn,\n [options?.intersectOn]\n );\n const initialCall = useMemo(\n () => options?.initialCall,\n [options?.initialCall]\n );\n\n useOrbit({\n target: intersectOn as RefObject<HTMLElement | null> | undefined,\n events: {\n onIntersect(entry) {\n if (entry.isIntersecting) {\n lenisInstance!.on('scroll', callbackWrapScroll);\n window.addEventListener('resize', callbackWrapResize);\n } else {\n lenisInstance!.off('scroll', callbackWrapScroll);\n window.removeEventListener('resize', callbackWrapResize);\n }\n },\n },\n rootMargin: '50% 0px 50% 0px',\n });\n\n useLayoutEffect(() => {\n if (!intersectOn) {\n lenisInstance!.on('scroll', callbackWrapScroll);\n window.addEventListener('resize', callbackWrapResize);\n }\n\n if (initialCall) {\n callback(lenisInstance!.actualScroll, scrollCallbackReason.Initialize);\n }\n\n return () => {\n lenisInstance!.off('scroll', callbackWrapScroll);\n window.removeEventListener('resize', callbackWrapResize);\n };\n }, [\n callback,\n callbackWrapResize,\n callbackWrapScroll,\n initialCall,\n intersectOn,\n ]);\n}\n","import { type RefObject, useLayoutEffect } from 'react';\n\n/**\n * A simple Orbit hook.\n *\n * @param target HTML element ref to attach to.\n * @param events Specify which events should the orbit tracks.\n */\nexport function useOrbit(options: {\n target?: RefObject<HTMLElement | null>;\n events: {\n onResize?: (entry: ResizeObserverEntry) => void;\n onIntersect?: (entry: IntersectionObserverEntry) => void;\n };\n rootMargin?: string;\n}) {\n const { onResize, onIntersect } = options.events;\n const { rootMargin = '25% 0px 25% 0px' } = options;\n\n useLayoutEffect(() => {\n if (!options.target) return;\n if (!options.target.current) return;\n\n let orbitResize = undefined;\n if (onResize) {\n orbitResize = new ResizeObserver((entries) => onResize(entries[0]));\n orbitResize.observe(options.target.current);\n }\n let orbitIntersect = undefined;\n if (onIntersect) {\n orbitIntersect = new IntersectionObserver(\n (entries) => onIntersect(entries[0]),\n { rootMargin }\n );\n orbitIntersect.observe(options.target.current);\n }\n\n return () => {\n orbitResize?.disconnect();\n orbitIntersect?.disconnect();\n };\n }, [onIntersect, onResize, rootMargin, options.target]);\n}\n"],"mappings":";AAAA,SAAS,gBAAgB;AACzB,OAAO;AAAA,EAEL;AAAA,EAGA;AA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M,cAAc;AAAA,MACtC;AAAA,MACA,UAAU;AAAA,IACZ;AAAA,IACA,YAAY;AAAA,EACd,CAAC;AAED,EAAAG,iBAAgB,MAAM;AACpB,QAAI,cAAc;AAChB,YAAM,KAAK,gBAAgB,IAAI;AAAA,IACjC,OAAO;AACL,kBAAY,cAAc;AAAA,IAC5B;AAEA,WAAO,MAAM;AACX,kBAAY,cAAc;AAAA,IAC5B;AAAA,EACF,GAAG,CAAC,gBAAgB,YAAY,CAAC;AAEjC,sBAAoB,cAAc;AAClC,SAAO;AACT;AAEA,SAAS,iBAAiB,OAAuC;AAC/D,QAAM,EAAE,eAAe,IAAI;AAE3B,EAAAA,iBAAgB,MAAM;AACpB,UAAM,KAAK,gBAAgB,IAAI;AAE/B,WAAO,MAAM;AACX,kBAAY,cAAc;AAAA,IAC5B;AAAA,EACF,GAAG,CAAC,cAAc,CAAC;AAEnB,SAAO;AACT;","names":["React","useCallback","useId","useLayoutEffect","useRef","useLayoutEffect","useLayoutEffect","useLayoutEffect","useId","React","useRef","useCallback","useLayoutEffect"]}
1
+ {"version":3,"sources":["../src/scene/BakeScene.tsx","../src/setup.ts","../src/scene/SceneSync.tsx","../src/hooks/effectOnce.ts","../src/hooks/lenisCallback.ts","../src/hooks/orbit.ts"],"sourcesContent":["import { useFrame } from '@react-three/fiber';\nimport React, {\n type Dispatch,\n Fragment,\n type ReactNode,\n type SetStateAction,\n useId,\n useRef,\n} from 'react';\nimport { BasicTunnelIn, Default3DTunnelIn } from '../setup';\n\n/**\n * A core part of an in-house tool called `weaver`.\n *\n * `BakeScene`: This component will notifiy when the global 3D scene is ready.\n *\n * It works by tune in the `useFrame` from `@react-three/fiber`. When the scene is loaded, `useFreame` will fire\n * with ease, the component takes advantage of that, and because `useLoader` is unreliable.\n *\n * This component also accepts 3D elements `children` to be rendered directly to the canvas with some camera options.\n * But you don't have to put every 3D components inside the baker, for example, `SceneSync`s in the page are also\n * being watched by this component.\n *\n * The route renderer **CAN'T** detect if the page has 3D elements or not, so if a page uses any sort of 3D rendering,\n * this component **MUST** be a children iniside `Pipeline` (`index.tsx`), then pass the state value that bake changes\n * to `Pipeline`'s `contentReady` in order for the `BakeScene` to work behind loading fallback screen.\n */\nexport default function BakeScene(props: {\n children?: ReactNode;\n sceneReady: boolean;\n tunnelIn: BasicTunnelIn;\n loadTaskDelay?: number;\n setSceneReady: Dispatch<SetStateAction<boolean>>;\n onReady?: () => void;\n}) {\n const unique = useId();\n const pipeObjects = useId();\n\n const TunnelIn = props.tunnelIn ?? Default3DTunnelIn;\n\n if (!TunnelIn) {\n throw Error(\n 'Failed to find a tunnel to use. Consider setting a default tunnel.'\n );\n }\n\n return (\n <TunnelIn>\n <Fragment key={pipeObjects}>{props.children}</Fragment>\n <NotificationHandler\n key={unique}\n callback={props.onReady}\n sceneReady={props.sceneReady}\n setSceneReady={props.setSceneReady}\n />\n </TunnelIn>\n );\n}\n\nfunction NotificationHandler(props: {\n callback?: (isSceneReady: boolean) => void;\n sceneReady: boolean;\n setSceneReady: (value: boolean) => void;\n}) {\n /**\n * `useFrame` is expensive for something that only triggers once, so yea,\n * we'll remove the notification as soon as the job is done.\n */\n return !props.sceneReady && <RenderNotification {...props} />;\n}\n\nfunction RenderNotification(props: {\n callback?: (isSceneReady: boolean) => void;\n sceneReady: boolean;\n loadTaskDelay?: number;\n setSceneReady: (value: boolean) => void;\n}) {\n const scheduledForCallback = useRef(false);\n\n useFrame(() => {\n if (!props.sceneReady && !scheduledForCallback.current) {\n scheduledForCallback.current = true;\n setTimeout(() => {\n if (props.callback) {\n props.callback(true);\n }\n props.setSceneReady(true);\n }, props.loadTaskDelay ?? 50);\n }\n });\n\n return null;\n}\n","import Lenis from 'lenis';\nimport { ReactNode } from 'react';\n\nexport let lenisInstance: Lenis | undefined = undefined;\n\nexport type BasicTunnelIn = ({ children }: { children: ReactNode }) => null;\nexport let Default3DTunnelIn: BasicTunnelIn | undefined = undefined;\n\nexport const weaverSetup = {\n setLenisInstance(instance: Lenis) {\n lenisInstance = instance;\n },\n set3DTunnel(tunnelIn: BasicTunnelIn) {\n Default3DTunnelIn = tunnelIn;\n },\n};\n","import { Hud } from '@react-three/drei';\nimport { useThree, type Viewport } from '@react-three/fiber';\nimport { cancelFrame, frame } from 'motion/react';\nimport React, {\n type ReactNode,\n type RefObject,\n useCallback,\n useId,\n useLayoutEffect,\n useRef,\n useState,\n} from 'react';\nimport { Group } from 'three';\nimport { useLayoutEffectOnce } from '../hooks/effectOnce';\nimport { useLenisCallback } from '../hooks/lenisCallback';\nimport { useOrbit } from '../hooks/orbit';\nimport { BasicTunnelIn, Default3DTunnelIn, lenisInstance } from '../setup';\n\nexport type Basic3DTransforms = {\n scale: {\n set: (x: number, y: number, z: number) => void;\n };\n position: {\n x: number;\n y: number;\n };\n};\n\ninterface SyncProps {\n /**\n * HTML element ref that `<SceneSync />` will use to sync with the scene.\n *\n * ```tsx\n * <div ref={container} />\n * <SceneSync attach={container}>\n * <group />\n * </SceneSync>\n * ```\n */\n attach: RefObject<HTMLElement | null>;\n\n /**\n * This variable allows fine-grain control over your scene when passed to `<SceneSync />`.\n *\n * `<SceneSync />` will use its own ref and group when creating your scene to control its scale and position.\n * Setting this variable will disable the internal ref, and you can decide on which object gets controlled.\n *\n * This variable is needed for `hud` if you wanted to add a custom camera.\n *\n * For listening to change details, use `onLayoutChange` instead.\n */\n control?: RefObject<Basic3DTransforms | null>;\n\n /**\n * When this variable is set, `<SceneSync />` will send updates when the scene update its positions.\n *\n * The function return the calculated DOM rect, with dimension and position in 3D measurements.\n */\n onLayoutUpdate?: (\n rect: DOMRect,\n dimension: { w: number; h: number },\n position: { x: number; y: number }\n ) => void;\n\n /**\n * Use `Hud` for this scene or not.\n *\n * This is useful when you want to apply custom camera for this scene, or renders multiple scenes on each other.\n *\n * NOTE: When setting a custom camera, the `control` variable must also be set and mount to your scene, not related to the camera\n * to avoid unwanted behavior.\n *\n * `<SceneSync />` groups children passed to it by default, so the camera is also in the group, when syncer updates the group,\n * the camera is also change, ruining the effect.\n */\n hud?: boolean;\n\n /**\n * Control the scene's scaling when positioning.\n */\n scaleFactor?: number;\n\n /**\n * `<SceneSync />` avoid stretching the object by default by using the smallest dimension of the DOM element.\n *\n * This variable will tell `<SceneSync />` to stretch it anyways.\n */\n stretch?: boolean;\n\n /**\n * Disable automatic scaling on the object.\n *\n * This variable will also disable any scaling settings like `stretch` and `scaleFactor`.\n */\n disableScaling?: boolean;\n\n /**\n * `<SceneSync />` will depend on this variable to adjust how it should update.\n *\n * There are 3 modes: `relaxed`, `balanced` and `aggressive`.\n *\n * For each mode, there will be some very distinct trade-offs\n *\n * - `relaxed`: Uses IntersectionObserver paired with a scroll hook, together with ResizeObserver.\n * - (+): Minimal update calls, best performance.\n * - (-): The scene get desynced the moment DOM element moves without changing its sizes.\n * When the scene bleeds out of the DOM element too much, if IntersectionObserver reported that the DOM element\n * is out of view, the scene that did not fully moved out of view will stay there, as scroll hook will be disabled.\n * - `balanced`: Uses IntersectionObserver paired with frame-based update, together with ResizeObserver.\n * - (+): Just enough update calls to allow the DOM element to move freely while maintain aceptable performance.\n * - (-): It will update on every frame when the object gets into view as reported by IntersectionObserver. And the same\n * problem with `relaxed` mode when the scene bleeds out too much.\n * - `aggressive`: Frame-based update only. This mode is like how `<View />` from `@react-three/drei` kepts track of DOM elements.\n * - (+): Designed for precise element <-> scene updates. Can't be desynced, if desynced, that's a bug.\n * - (-): This is frame-based. It will fire updates as long as the scene is still mounted. Too many scenes with this\n * mode enabled is not a good idea. Acceptable amount would be 3 scenes with this mode.\n *\n * Best of both worlds is `balanced` mode, for simpler scenes that doesn't change its position, `relaxed` should be used.\n */\n trackingMode: 'relaxed' | 'balanced' | 'aggressive';\n\n /**\n * Set a custom tunnel for `<SceneSync />` send the components to for this scene only.\n *\n * Which is useful for example, put the objects inside a container in the scene.\n *\n * To set a default tunnel, pass it to `setDefaulTunnel` before use.\n */\n tunnelIn?: BasicTunnelIn;\n\n children: ReactNode;\n}\n\ninterface HudProps extends SyncProps {\n hud: true;\n /**\n * Set the `renderPriority` to render things for `Hud`.\n *\n * This variable is ignored when `hud` is not `true`.\n */\n hudRenderPriority: number;\n}\n\ninterface NormalProps extends SyncProps {\n hud?: false;\n}\n\n/**\n * A core part of an in-house tool called `weaver`.\n *\n * A component to allow three objects to track and sync with DOM element.\n *\n * The component uses `<Hud />` under the \"hud\", so if you want to use more than one `<SceneSync />`,\n * you must set `renderPriority`. If not, the component will render the last scene pushed through React.\n */\nexport default function SceneSync(props: NormalProps | HudProps) {\n const unique = useId();\n\n const TunnelIn = props.tunnelIn ?? Default3DTunnelIn;\n\n if (!TunnelIn) {\n throw Error(\n 'Failed to find a tunnel to use. Consider setting a default tunnel.'\n );\n }\n\n if (props.hud) {\n return (\n <TunnelIn>\n <Hud key={unique} renderPriority={props.hudRenderPriority}>\n <SyncInternal {...props} />\n </Hud>\n </TunnelIn>\n );\n }\n\n return (\n <TunnelIn>\n <SyncInternal key={unique} {...props} />\n </TunnelIn>\n );\n}\n\nfunction SyncInternal(props: SyncProps) {\n const { viewport, camera } = useThree();\n\n const defaultControl = useRef<Group>(null);\n const {\n attach,\n control,\n scaleFactor,\n stretch,\n disableScaling,\n onLayoutUpdate,\n } = props;\n\n const properties: RefObject<{\n viewport?: Omit<Viewport, 'dpr' | 'initialDpr'>;\n }> = useRef({\n viewport: undefined,\n });\n\n const updatePosition = useCallback(() => {\n const activeControl = control ?? defaultControl;\n\n const vp = properties.current.viewport;\n if (!vp) return;\n\n const domRect = attach.current!.getBoundingClientRect();\n const screenH = document.documentElement.clientHeight;\n const screenW = document.body.clientWidth;\n\n const vpWidthRatio = vp.width / screenW;\n const vpHeightRatio = vp.height / screenH;\n\n const scrollOffset = (lenisInstance!.actualScroll / screenH) * vp.height;\n\n const w = domRect.width * vpWidthRatio;\n const h = domRect.height * vpHeightRatio;\n\n const x = domRect.x * vpWidthRatio + w * 0.5 - vp.width * 0.5;\n const y =\n vp.height * 0.5 -\n (domRect.y + lenisInstance!.actualScroll) * vpHeightRatio -\n h * 0.5 +\n scrollOffset;\n\n if (onLayoutUpdate) {\n onLayoutUpdate(domRect, { w, h }, { x, y });\n }\n\n const unwrapedScaleFactor = scaleFactor ?? 1;\n\n if (!disableScaling) {\n if (!stretch) {\n const minScale = Math.min(w, h) * unwrapedScaleFactor;\n activeControl.current!.scale.set(minScale, minScale, minScale);\n } else {\n activeControl.current!.scale.set(\n w * unwrapedScaleFactor,\n h * unwrapedScaleFactor,\n Math.min(w, h) * unwrapedScaleFactor\n );\n }\n }\n\n // eslint-disable-next-line react-hooks/immutability\n activeControl.current!.position.x = x;\n activeControl.current!.position.y = y;\n }, [attach, onLayoutUpdate, control, scaleFactor, disableScaling, stretch]);\n\n /**\n * Update position when `camera` changes.\n */\n useLayoutEffect(() => {\n properties.current.viewport = viewport.getCurrentViewport(camera);\n updatePosition();\n }, [camera, updatePosition, viewport]);\n\n const graceUpdate = useCallback(() => {\n try {\n updatePosition();\n } catch {\n /* empty */\n }\n }, [updatePosition]);\n\n const mode = {\n relaxed: (\n <RelaxedUpdate attach={props.attach} updatePosition={graceUpdate} />\n ),\n balanced: (\n <BalancedUpdate attach={props.attach} updatePosition={graceUpdate} />\n ),\n aggressive: <AggressiveUpdate updatePosition={graceUpdate} />,\n };\n\n if (props.control) {\n return (\n <>\n {props.children}\n {mode[props.trackingMode]}\n </>\n );\n }\n\n return (\n <group ref={defaultControl}>\n {props.children}\n {mode[props.trackingMode]}\n </group>\n );\n}\n\nfunction RelaxedUpdate(props: {\n attach: RefObject<HTMLElement | null>;\n updatePosition: () => void;\n}) {\n const { updatePosition } = props;\n\n /**\n * Scroll hook to update object correctly to the current HTML scroll position.\n */\n useLenisCallback(updatePosition, {\n initialCall: true,\n intersectOn: props.attach,\n });\n\n /**\n * Allows the element to resize too.\n */\n useOrbit({\n target: props.attach,\n events: {\n onIntersect: updatePosition,\n onResize: updatePosition,\n },\n });\n\n useLayoutEffectOnce(updatePosition);\n return null;\n}\n\nfunction BalancedUpdate(props: {\n attach: RefObject<HTMLElement | null>;\n updatePosition: () => void;\n}) {\n const { updatePosition } = props;\n\n const [shouldUpdate, setShouldUpdate] = useState(false);\n\n useOrbit({\n target: props.attach,\n events: {\n onIntersect(entry) {\n setShouldUpdate(entry.isIntersecting);\n },\n onResize: updatePosition,\n },\n rootMargin: '50% 0px 50% 0px',\n });\n\n useLayoutEffect(() => {\n if (shouldUpdate) {\n frame.read(updatePosition, true);\n } else {\n cancelFrame(updatePosition);\n }\n\n return () => {\n cancelFrame(updatePosition);\n };\n }, [updatePosition, shouldUpdate]);\n\n useLayoutEffectOnce(updatePosition);\n return null;\n}\n\nfunction AggressiveUpdate(props: { updatePosition: () => void }) {\n const { updatePosition } = props;\n\n useLayoutEffect(() => {\n frame.read(updatePosition, true);\n\n return () => {\n cancelFrame(updatePosition);\n };\n }, [updatePosition]);\n\n return null;\n}\n","import { useEffect, useLayoutEffect } from 'react';\n\nexport function useEffectOnce(callback: React.EffectCallback) {\n // eslint-disable-next-line react-hooks/exhaustive-deps\n useEffect(callback, []);\n}\n\nexport function useLayoutEffectOnce(callback: React.EffectCallback) {\n // eslint-disable-next-line react-hooks/exhaustive-deps\n useLayoutEffect(callback, []);\n}\n","import { type RefObject, useCallback, useLayoutEffect, useMemo } from 'react';\nimport { lenisInstance } from '../setup';\nimport { useOrbit } from './orbit';\n\ninterface HookOptions {\n /**\n * Hook will report when first initialized without waiting for scroll event to actually happens.\n */\n initialCall?: boolean;\n /**\n * Set an element to only call when the element is actually entering the viewport (with 25% `rootMargin`).\n */\n intersectOn?: RefObject<HTMLOrSVGElement | null>;\n}\n\nexport const scrollCallbackReason = {\n Resize: 'resize',\n Scroll: 'scroll',\n Initialize: 'initialize',\n} as const;\nexport type ScrollCallbackReason =\n (typeof scrollCallbackReason)[keyof typeof scrollCallbackReason];\n\ntype Callback = (latest: number, reason: ScrollCallbackReason) => void;\n\nexport function useLenisCallback(callback: Callback, options?: HookOptions) {\n const callbackWrapScroll = useCallback(\n () => callback(lenisInstance!.actualScroll, scrollCallbackReason.Scroll),\n [callback]\n );\n const callbackWrapResize = useCallback(\n () => callback(lenisInstance!.actualScroll, scrollCallbackReason.Resize),\n [callback]\n );\n\n const intersectOn = useMemo(\n () => options?.intersectOn,\n [options?.intersectOn]\n );\n const initialCall = useMemo(\n () => options?.initialCall,\n [options?.initialCall]\n );\n\n useOrbit({\n target: intersectOn as RefObject<HTMLElement | null> | undefined,\n events: {\n onIntersect(entry) {\n if (entry.isIntersecting) {\n lenisInstance!.on('scroll', callbackWrapScroll);\n window.addEventListener('resize', callbackWrapResize);\n } else {\n lenisInstance!.off('scroll', callbackWrapScroll);\n window.removeEventListener('resize', callbackWrapResize);\n }\n },\n },\n rootMargin: '50% 0px 50% 0px',\n });\n\n useLayoutEffect(() => {\n if (!intersectOn) {\n lenisInstance!.on('scroll', callbackWrapScroll);\n window.addEventListener('resize', callbackWrapResize);\n }\n\n if (initialCall) {\n callback(lenisInstance!.actualScroll, scrollCallbackReason.Initialize);\n }\n\n return () => {\n lenisInstance!.off('scroll', callbackWrapScroll);\n window.removeEventListener('resize', callbackWrapResize);\n };\n }, [\n callback,\n callbackWrapResize,\n callbackWrapScroll,\n initialCall,\n intersectOn,\n ]);\n}\n","import { type RefObject, useLayoutEffect } from 'react';\n\n/**\n * A simple Orbit hook.\n *\n * @param target HTML element ref to attach to.\n * @param events Specify which events should the orbit tracks.\n */\nexport function useOrbit(options: {\n target?: RefObject<HTMLElement | null>;\n events: {\n onResize?: (entry: ResizeObserverEntry) => void;\n onIntersect?: (entry: IntersectionObserverEntry) => void;\n };\n rootMargin?: string;\n}) {\n const { onResize, onIntersect } = options.events;\n const { rootMargin = '25% 0px 25% 0px' } = options;\n\n useLayoutEffect(() => {\n if (!options.target) return;\n if (!options.target.current) return;\n\n let orbitResize = undefined;\n if (onResize) {\n orbitResize = new ResizeObserver((entries) => onResize(entries[0]));\n orbitResize.observe(options.target.current);\n }\n let orbitIntersect = undefined;\n if (onIntersect) {\n orbitIntersect = new IntersectionObserver(\n (entries) => onIntersect(entries[0]),\n { rootMargin }\n );\n orbitIntersect.observe(options.target.current);\n }\n\n return () => {\n orbitResize?.disconnect();\n orbitIntersect?.disconnect();\n };\n }, [onIntersect, onResize, rootMargin, options.target]);\n}\n"],"mappings":";AAAA,SAAS,gBAAgB;AACzB,OAAO;AAAA,EAEL;AAAA,EAGA;AAAA,EACA;AAAA,OACK;;;ACLA,IAAI,gBAAmC;AAGvC,IAAI,oBAA+C;;;ADqB3C,SAAR,UAA2B,OAO/B;AACD,QAAM,SAAS,MAAM;AACrB,QAAM,cAAc,MAAM;AAE1B,QAAM,WAAW,MAAM,YAAY;AAEnC,MAAI,CAAC,UAAU;AACb,UAAM;AAAA,MACJ;AAAA,IACF;AAAA,EACF;AAEA,SACE,oCAAC,gBACC,oCAAC,YAAS,KAAK,eAAc,MAAM,QAAS,GAC5C;AAAA,IAAC;AAAA;AAAA,MACC,KAAK;AAAA,MACL,UAAU,MAAM;AAAA,MAChB,YAAY,MAAM;AAAA,MAClB,eAAe,MAAM;AAAA;AAAA,EACvB,CACF;AAEJ;AAEA,SAAS,oBAAoB,OAI1B;AAKD,SAAO,CAAC,MAAM,cAAc,oCAAC,sBAAoB,GAAG,OAAO;AAC7D;AAEA,SAAS,mBAAmB,OAKzB;AACD,QAAM,uBAAuB,OAAO,KAAK;AAEzC,WAAS,MAAM;AACb,QAAI,CAAC,MAAM,cAAc,CAAC,qBAAqB,SAAS;AACtD,2BAAqB,UAAU;AAC/B,iBAAW,MAAM;AACf,YAAI,MAAM,UAAU;AAClB,gBAAM,SAAS,IAAI;AAAA,QACrB;AACA,cAAM,cAAc,IAAI;AAAA,MAC1B,GAAG,MAAM,iBAAiB,EAAE;AAAA,IAC9B;AAAA,EACF,CAAC;AAED,SAAO;AACT;;;AE5FA,SAAS,WAAW;AACpB,SAAS,gBAA+B;AACxC,SAAS,aAAa,aAAa;AACnC,OAAOA;AAAA,EAGL,eAAAC;AAAA,EACA,SAAAC;AAAA,E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sBAAoB,cAAc;AAClC,SAAO;AACT;AAEA,SAAS,eAAe,OAGrB;AACD,QAAM,EAAE,eAAe,IAAI;AAE3B,QAAM,CAAC,cAAc,eAAe,IAAI,SAAS,KAAK;AAEtD,WAAS;AAAA,IACP,QAAQ,MAAM;AAAA,IACd,QAAQ;AAAA,MACN,YAAY,OAAO;AACjB,wBAAgB,MAAM,cAAc;AAAA,MACtC;AAAA,MACA,UAAU;AAAA,IACZ;AAAA,IACA,YAAY;AAAA,EACd,CAAC;AAED,EAAAG,iBAAgB,MAAM;AACpB,QAAI,cAAc;AAChB,YAAM,KAAK,gBAAgB,IAAI;AAAA,IACjC,OAAO;AACL,kBAAY,cAAc;AAAA,IAC5B;AAEA,WAAO,MAAM;AACX,kBAAY,cAAc;AAAA,IAC5B;AAAA,EACF,GAAG,CAAC,gBAAgB,YAAY,CAAC;AAEjC,sBAAoB,cAAc;AAClC,SAAO;AACT;AAEA,SAAS,iBAAiB,OAAuC;AAC/D,QAAM,EAAE,eAAe,IAAI;AAE3B,EAAAA,iBAAgB,MAAM;AACpB,UAAM,KAAK,gBAAgB,IAAI;AAE/B,WAAO,MAAM;AACX,kBAAY,cAAc;AAAA,IAC5B;AAAA,EACF,GAAG,CAAC,cAAc,CAAC;AAEnB,SAAO;AACT;","names":["React","useCallback","useId","useLayoutEffect","useRef","useLayoutEffect","useLayoutEffect","useLayoutEffect","useId","React","useRef","useCallback","useLayoutEffect"]}
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "author": "neveranyart",
3
3
  "license": "GPL-3.0-or-later",
4
4
  "name": "@neveranyart/weaver",
5
- "version": "1.0.1",
5
+ "version": "1.0.3",
6
6
  "description": "An in-house package by neverany for making interactive React CSR.",
7
7
  "packageManager": "yarn@4.10.3",
8
8
  "publishConfig": {