@neveranyart/weaver 1.0.12 → 1.0.14

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/README.md CHANGED
@@ -6,146 +6,15 @@ An in-house core package by neveranyart for making performant, interactive React
6
6
 
7
7
  ![neverany branding](https://github.com/user-attachments/assets/8c09234f-d592-4adc-8ab1-284b1fca3f7c)
8
8
 
9
-
10
9
  ## Introduction
11
- This package is published as an in-depth on `neverany` technicals. This package is not intended for broad usage so it has a strict choice of dependencies and a specific way of use.
12
-
13
- ## Usage
14
-
15
- ### Routing
16
- The package wraps around `react-router` as a base for working with routing because it provides us a way to postpone parent components mounting.
17
-
18
- There are 2 components for composing delayed routing for animations: `DelayedOutlet`, `Pipeline`.
19
-
20
- - `DelayedOutlet`:
21
- - Drop-in replacement for `Outlet` component from `react-router`.
22
- - `Pipeline`:
23
- - Declare parent for an endpoint, handle route changes and communicates with `DelayedOutlet`.
24
- - As long as it's the ONLY instance on the route endpoint, it should works just fine.
25
- - Can be placed anywhere, but please put it as a parent for all of your endpoint's components.
26
- - It can't nest itself.
27
-
28
- > [!CAUTION]
29
- > There can only be ONE `DelayedOutlet` per app and ONE `Pipeline` per parent path.
30
-
31
- Other than that, just use `react-router` like intended. `weaver/routing` has especially tested against going back and forth rapidly and works flawlessly in strict mode, so you don't have to think about the logic behind it!
32
-
33
- While the route is delayed, the previous route is still displayed to ensure a smooth tranition to your likings.
34
-
35
- Example usage with 2 endpoints, router delayed for `500ms`:
36
-
37
- ```tsx
38
- import { DelayedOutlet, Pipeline } from '@neveranyart/weaver/routing';
39
- import { StrictMode, Suspense } from 'react';
40
- import { createRoot } from 'react-dom/client';
41
- import { createBrowserRouter, Link, RouterProvider } from 'react-router';
42
-
43
- function Root() {
44
- return (
45
- <main>
46
- <DelayedOutlet delay={500} />
47
- </main>
48
- );
49
- }
50
-
51
- function Home() {
52
- return (
53
- <Pipeline title={'Home'} debugName={'Home'}>
54
- <p>Home</p>
55
- <Link to="/projects">Navigate</Link>
56
- </Pipeline>
57
- );
58
- }
59
-
60
- const router = createBrowserRouter([
61
- {
62
- path: '/',
63
- element: <Root />,
64
- children: [
65
- {
66
- index: true,
67
- element: (
68
- <Suspense>
69
- <Home />
70
- </Suspense>
71
- ),
72
- },
73
- {
74
- path: '/projects/*',
75
- element: (
76
- <Suspense>
77
- <Pipeline title={'Projects'} debugName={'Projects'}>
78
- <p>Projects</p>
79
- <Link to="/">Navigate</Link>
80
- </Pipeline>
81
- </Suspense>
82
- ),
83
- },
84
- ],
85
- },
86
- ]);
87
-
88
- createRoot(document.getElementById('root')!).render(
89
- <StrictMode>
90
- <RouterProvider router={router} />
91
- </StrictMode>
92
- );
93
- ```
94
-
95
- `weaver/routing` also provides a quick way to react to state changes with a cool hook called `useWeaverState`. Containing 4 states for you to play with:
96
-
97
- ```ts
98
- const pageRendered = useWeaverState('pageRendered');
99
- const activePipeline = useWeaverState('activePipeline');
100
- const activeParent = useWeaverState('activeParent');
101
- const navigating = useWeaverState('navigating');
102
- ```
103
-
104
- When a route change happens, this is how states in `weaver/routing` changes when a route change is successful:
105
-
106
- `+`: Other events/information.
107
- `!`: State changes.
108
-
109
- ```
110
- + Current `Pipeline` path: "/""
111
- ! pageRendered -> false, navigating -> true.
112
- + Receives new parent.
113
- + Delay route change.
114
- + Set new `Pipeline`.
115
- + `Pipeline` path "/" start unmounting process.
116
- + New `Pipeline` path: "/projects".
117
- ! activePipeline -> "/projects".
118
- ! navigating -> false.
119
- + New `Pipeline` start mounting process.
120
- ! pageRendered -> true, activeParent -> "/projects".
121
- ```
122
-
123
- When a route change is cancelled by user going back mid delay:
124
-
125
- ```
126
- + Current `Pipeline` path: "/""
127
- ! pageRendered -> false, navigating -> true.
128
- + Receives new parent.
129
- + Delay route change.
130
- + User cancelled.
131
- ! pageRendered -> true, navigating -> false.
132
- ```
133
-
134
- Overall:
135
- - `pageRendered` covers the whole routing process. It is the recommended way of knowing if the content is ready to be displayed or not.
136
- - `activePipeline` is for knowing which Pipeline has taken over previous one.
137
- - `activeParent` tells which Pipeline has delivered its components on screen.
138
- - `navigating` tells when `DelayedOutlet` handles routing.
139
-
140
- ### Hooks
141
- `weaver` provides a reasonable amount of DOM hooks, intensive hooks will only allow callbacks usage to avoid React re-render.
10
+ This package is published as an in-depth on `neverany` technicals. It is not intended for broad usage so it has a strict choice of dependencies and a specific way of use.
142
11
 
143
- ### Scene
12
+ But, most components and tools are built with flexibility in mind, providing a balance between abstraction and verbose.
144
13
 
14
+ ## Documentations
15
+ 1. [Routing](/docs/ROUTING.md)
16
+ 2. Hooks
17
+ 3. Scene
145
18
 
146
- The package comes packed with:
147
- - `Pipeline`, `DelayedOutlet`: CSR router handler built for transition animation, hiding initialization lags behind a wall while allowing SEO to work.
148
- - `BakeScene`: Wait and notify when a 3D scene has finished rendering and ready to be shown, usually paired with `Pipeline`.
149
- - `Orbit`: ResizeObserver & IntersectionObserver simplified.
150
- - `SceneSync`: Sync `@react-three/fiber` scene with DOM element.
151
- - And a big directory of DOM hooks.
19
+ ## About copyleft license
20
+ This project is relatively new, we'll consider switching to a more permissive license when the project is mature enough.
@@ -51,6 +51,12 @@ interface PipelineProps {
51
51
  * Title for the page.
52
52
  */
53
53
  title: string;
54
+ /**
55
+ * This is crucial for different `Pipeline`s to differentiate each other and avoiding conflict.
56
+ *
57
+ * Example for parent path: `/`, `/about`, `/projects`,...
58
+ */
59
+ parentPath: string;
54
60
  /**
55
61
  * If provided, `Pipeline` will log the current phase to console.
56
62
  */
package/dist/routing.d.ts CHANGED
@@ -51,6 +51,12 @@ interface PipelineProps {
51
51
  * Title for the page.
52
52
  */
53
53
  title: string;
54
+ /**
55
+ * This is crucial for different `Pipeline`s to differentiate each other and avoiding conflict.
56
+ *
57
+ * Example for parent path: `/`, `/about`, `/projects`,...
58
+ */
59
+ parentPath: string;
54
60
  /**
55
61
  * If provided, `Pipeline` will log the current phase to console.
56
62
  */
package/dist/routing.js CHANGED
@@ -169,11 +169,7 @@ var weaverSetup = new WeaverSetup();
169
169
  // src/routing/Pipeline.tsx
170
170
  function Pipeline(props) {
171
171
  const { children, ...restOfProps } = props;
172
- const parentPath = (0, import_react5.useMemo)(
173
- () => getParentRoute(window.location.pathname),
174
- []
175
- );
176
- return /* @__PURE__ */ import_react5.default.createElement(import_react5.default.Fragment, null, /* @__PURE__ */ import_react5.default.createElement(RouteHandler, { ...restOfProps, parentPath }), children);
172
+ return /* @__PURE__ */ import_react5.default.createElement(import_react5.default.Fragment, null, /* @__PURE__ */ import_react5.default.createElement(RouteHandler, { ...restOfProps }), children);
177
173
  }
178
174
  function RouteHandler(props) {
179
175
  const navigating = useWeaverContext((state) => state.navigating);
@@ -184,7 +180,14 @@ function RouteHandler(props) {
184
180
  );
185
181
  const setPageRendered = useWeaverContext((state) => state.setPageRendered);
186
182
  const setActiveParent = useWeaverContext((state) => state.setActiveParent);
187
- const loopWatcher = (0, import_react5.useCallback)(() => {
183
+ (0, import_react5.useLayoutEffect)(() => {
184
+ document.title = props.title;
185
+ setActivePipeline(props.parentPath);
186
+ if (props.contentReady !== void 0 && !props.contentReady) {
187
+ if (props.debugName)
188
+ console.log(`[${props.debugName}] Renderer status: Loading scene`);
189
+ return;
190
+ }
188
191
  if (!navigating && (!pageRendered || activeParent !== props.parentPath)) {
189
192
  if (props.lenisUsage === void 0 || props.lenisUsage) {
190
193
  weaverSetup._lenisInstance?.start();
@@ -196,33 +199,16 @@ function RouteHandler(props) {
196
199
  }
197
200
  }, [
198
201
  activeParent,
202
+ setActivePipeline,
199
203
  navigating,
200
204
  pageRendered,
201
205
  props.lenisUsage,
202
- props.debugName,
203
- props.parentPath,
204
- setActiveParent,
205
- setPageRendered
206
- ]);
207
- (0, import_react5.useLayoutEffect)(() => {
208
- document.title = props.title;
209
- setActivePipeline(props.parentPath);
210
- if (props.contentReady !== void 0 && !props.contentReady) {
211
- if (props.debugName)
212
- console.log(`[${props.debugName}] Renderer status: Loading scene`);
213
- return;
214
- }
215
- const loopWatcherTask = setInterval(loopWatcher, 32);
216
- return () => {
217
- clearInterval(loopWatcherTask);
218
- };
219
- }, [
220
- setActivePipeline,
221
206
  props.contentReady,
222
207
  props.debugName,
223
208
  props.parentPath,
224
209
  props.title,
225
- loopWatcher
210
+ setActiveParent,
211
+ setPageRendered
226
212
  ]);
227
213
  useLayoutEffectOnce(() => {
228
214
  return () => {
@@ -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/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, {\n useCallback,\n useLayoutEffect,\n useMemo,\n type ReactNode,\n} from 'react';\nimport { useLayoutEffectOnce } from '../hooks/effectOnce';\nimport { weaverSetup } from '../setup';\nimport { getParentRoute } from '../utils/getParentRoute';\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 * If provided, `Pipeline` will log the current phase to console.\n */\n debugName?: string;\n\n /**\n * This is the only feature where weaver will use lenis to directly manipulate scrolling behaviour.\n *\n * By default, this value is `true` when a lenis instance is provided.\n *\n * `Pipeline` will stop and start lenis automatically when this variable is `true`.\n *\n * Disable this feature to gains complete control over lenis when mounting/unmounting to handle however you want.\n */\n lenisUsage?: 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 const parentPath = useMemo(\n () => getParentRoute(window.location.pathname),\n []\n );\n\n return (\n <>\n <RouteHandler {...restOfProps} parentPath={parentPath} />\n {children}\n </>\n );\n}\n\nfunction RouteHandler(\n props: Omit<PipelineProps, 'children'> & { parentPath: string }\n) {\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 const loopWatcher = useCallback(() => {\n if (!navigating && (!pageRendered || activeParent !== props.parentPath)) {\n if (props.lenisUsage === undefined || props.lenisUsage) {\n weaverSetup._lenisInstance?.start();\n }\n\n setPageRendered(true);\n setActiveParent(props.parentPath);\n\n if (props.debugName)\n console.log(`[${props.debugName}] Renderer status: Mounted`);\n }\n }, [\n activeParent,\n navigating,\n pageRendered,\n props.lenisUsage,\n props.debugName,\n props.parentPath,\n setActiveParent,\n setPageRendered,\n ]);\n\n useLayoutEffect(() => {\n document.title = props.title;\n setActivePipeline(props.parentPath);\n\n if (props.contentReady !== undefined && !props.contentReady) {\n if (props.debugName)\n console.log(`[${props.debugName}] Renderer status: Loading scene`);\n return;\n }\n\n const loopWatcherTask = setInterval(loopWatcher, 32);\n\n return () => {\n clearInterval(loopWatcherTask);\n };\n }, [\n setActivePipeline,\n props.contentReady,\n props.debugName,\n props.parentPath,\n props.title,\n loopWatcher,\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 if (props.lenisUsage === undefined || props.lenisUsage) {\n weaverSetup._lenisInstance?.stop();\n weaverSetup._lenisInstance?.scrollTo(0, {\n immediate: true,\n force: true,\n });\n }\n\n if (props.debugName)\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 type BasicTunnelIn = ({ children }: { children: ReactNode }) => null;\n\nclass WeaverSetup {\n /**\n * This variable is handled internally by weaver. **Do not use**.\n */\n get _lenisInstance(): Lenis | undefined {\n return (globalThis as any).__weaverLenis;\n }\n set _lenisInstance(val: Lenis | undefined) {\n (globalThis as any).__weaverLenis = val;\n }\n\n /**\n * This variable is handled internally by weaver. **Do not use**.\n */\n get _Default3DTunnelIn(): BasicTunnelIn | undefined {\n return (globalThis as any).__weaver3DTunnel;\n }\n set _Default3DTunnelIn(val: BasicTunnelIn | undefined) {\n (globalThis as any).__weaver3DTunnel = val;\n }\n\n setLenisInstance(instance: Lenis) {\n this._lenisInstance = instance;\n }\n set3DTunnel(tunnelIn: BasicTunnelIn) {\n this._Default3DTunnelIn = tunnelIn;\n }\n}\n\nexport const weaverSetup = new WeaverSetup();\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,gB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AAI,MAAM,SAAS,kCAAkC;AACnE;AAAA,IACF;AAEA,UAAM,kBAAkB,YAAY,aAAa,EAAE;AAEnD,WAAO,MAAM;AACX,oBAAc,eAAe;AAAA,IAC/B;AAAA,EACF,GAAG;AAAA,IACD;AAAA,IACA,MAAM;AAAA,IACN,MAAM;AAAA,IACN,MAAM;AAAA,IACN,MAAM;AAAA,IACN;AAAA,EACF,CAAC;AAED,sBAAoB,MAAM;AACxB,WAAO,MAAM;AAOX,UAAI,MAAM,eAAe,UAAa,MAAM,YAAY;AACtD,oBAAY,gBAAgB,KAAK;AACjC,oBAAY,gBAAgB,SAAS,GAAG;AAAA,UACtC,WAAW;AAAA,UACX,OAAO;AAAA,QACT,CAAC;AAAA,MACH;AAEA,UAAI,MAAM;AACR,gBAAQ,IAAI,IAAI,MAAM,SAAS,8BAA8B;AAAA,IACjE;AAAA,EACF,CAAC;AAED,SAAO;AACT;;;ALnJO,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 { weaverSetup } 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 * 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 * If provided, `Pipeline` will log the current phase to console.\n */\n debugName?: string;\n\n /**\n * This is the only feature where weaver will use lenis to directly manipulate scrolling behaviour.\n *\n * By default, this value is `true` when a lenis instance is provided.\n *\n * `Pipeline` will stop and start lenis automatically when this variable is `true`.\n *\n * Disable this feature to gains complete control over lenis when mounting/unmounting to handle however you want.\n */\n lenisUsage?: 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\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 if (props.debugName)\n console.log(`[${props.debugName}] Renderer status: Loading scene`);\n return;\n }\n\n if (!navigating && (!pageRendered || activeParent !== props.parentPath)) {\n if (props.lenisUsage === undefined || props.lenisUsage) {\n weaverSetup._lenisInstance?.start();\n }\n\n setPageRendered(true);\n setActiveParent(props.parentPath);\n\n if (props.debugName)\n console.log(`[${props.debugName}] Renderer status: Mounted`);\n }\n }, [\n activeParent,\n setActivePipeline,\n navigating,\n pageRendered,\n props.lenisUsage,\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 if (props.lenisUsage === undefined || props.lenisUsage) {\n weaverSetup._lenisInstance?.stop();\n weaverSetup._lenisInstance?.scrollTo(0, {\n immediate: true,\n force: true,\n });\n }\n\n if (props.debugName)\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 type BasicTunnelIn = ({ children }: { children: ReactNode }) => null;\n\nclass WeaverSetup {\n /**\n * This variable is handled internally by weaver. **Do not use**.\n */\n get _lenisInstance(): Lenis | undefined {\n return (globalThis as any).__weaverLenis;\n }\n set _lenisInstance(val: Lenis | undefined) {\n (globalThis as any).__weaverLenis = val;\n }\n\n /**\n * This variable is handled internally by weaver. **Do not use**.\n */\n get _Default3DTunnelIn(): BasicTunnelIn | undefined {\n return (globalThis as any).__weaver3DTunnel;\n }\n set _Default3DTunnelIn(val: BasicTunnelIn | undefined) {\n (globalThis as any).__weaver3DTunnel = val;\n }\n\n setLenisInstance(instance: Lenis) {\n this._lenisInstance = instance;\n }\n set3DTunnel(tunnelIn: BasicTunnelIn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,MAAM,UAAU;AAEhC,UAAI,MAAM;AACR,gBAAQ,IAAI,IAAI,MAAM,SAAS,4BAA4B;AAAA,IAC/D;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,UAAI,MAAM,eAAe,UAAa,MAAM,YAAY;AACtD,oBAAY,gBAAgB,KAAK;AACjC,oBAAY,gBAAgB,SAAS,GAAG;AAAA,UACtC,WAAW;AAAA,UACX,OAAO;AAAA,QACT,CAAC;AAAA,MACH;AAEA,UAAI,MAAM;AACR,gBAAQ,IAAI,IAAI,MAAM,SAAS,8BAA8B;AAAA,IACjE;AAAA,EACF,CAAC;AAED,SAAO;AACT;;;ALlIO,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
@@ -91,11 +91,7 @@ function DelayedOutlet(props) {
91
91
  }
92
92
 
93
93
  // src/routing/Pipeline.tsx
94
- import React, {
95
- useCallback as useCallback2,
96
- useLayoutEffect as useLayoutEffect4,
97
- useMemo
98
- } from "react";
94
+ import React, { useLayoutEffect as useLayoutEffect4 } from "react";
99
95
 
100
96
  // src/hooks/effectOnce.ts
101
97
  import { useEffect, useLayoutEffect as useLayoutEffect3 } from "react";
@@ -135,11 +131,7 @@ var weaverSetup = new WeaverSetup();
135
131
  // src/routing/Pipeline.tsx
136
132
  function Pipeline(props) {
137
133
  const { children, ...restOfProps } = props;
138
- const parentPath = useMemo(
139
- () => getParentRoute(window.location.pathname),
140
- []
141
- );
142
- return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(RouteHandler, { ...restOfProps, parentPath }), children);
134
+ return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(RouteHandler, { ...restOfProps }), children);
143
135
  }
144
136
  function RouteHandler(props) {
145
137
  const navigating = useWeaverContext((state) => state.navigating);
@@ -150,7 +142,14 @@ function RouteHandler(props) {
150
142
  );
151
143
  const setPageRendered = useWeaverContext((state) => state.setPageRendered);
152
144
  const setActiveParent = useWeaverContext((state) => state.setActiveParent);
153
- const loopWatcher = useCallback2(() => {
145
+ useLayoutEffect4(() => {
146
+ document.title = props.title;
147
+ setActivePipeline(props.parentPath);
148
+ if (props.contentReady !== void 0 && !props.contentReady) {
149
+ if (props.debugName)
150
+ console.log(`[${props.debugName}] Renderer status: Loading scene`);
151
+ return;
152
+ }
154
153
  if (!navigating && (!pageRendered || activeParent !== props.parentPath)) {
155
154
  if (props.lenisUsage === void 0 || props.lenisUsage) {
156
155
  weaverSetup._lenisInstance?.start();
@@ -162,33 +161,16 @@ function RouteHandler(props) {
162
161
  }
163
162
  }, [
164
163
  activeParent,
164
+ setActivePipeline,
165
165
  navigating,
166
166
  pageRendered,
167
167
  props.lenisUsage,
168
- props.debugName,
169
- props.parentPath,
170
- setActiveParent,
171
- setPageRendered
172
- ]);
173
- useLayoutEffect4(() => {
174
- document.title = props.title;
175
- setActivePipeline(props.parentPath);
176
- if (props.contentReady !== void 0 && !props.contentReady) {
177
- if (props.debugName)
178
- console.log(`[${props.debugName}] Renderer status: Loading scene`);
179
- return;
180
- }
181
- const loopWatcherTask = setInterval(loopWatcher, 32);
182
- return () => {
183
- clearInterval(loopWatcherTask);
184
- };
185
- }, [
186
- setActivePipeline,
187
168
  props.contentReady,
188
169
  props.debugName,
189
170
  props.parentPath,
190
171
  props.title,
191
- loopWatcher
172
+ setActiveParent,
173
+ setPageRendered
192
174
  ]);
193
175
  useLayoutEffectOnce(() => {
194
176
  return () => {
@@ -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/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, {\n useCallback,\n useLayoutEffect,\n useMemo,\n type ReactNode,\n} from 'react';\nimport { useLayoutEffectOnce } from '../hooks/effectOnce';\nimport { weaverSetup } from '../setup';\nimport { getParentRoute } from '../utils/getParentRoute';\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 * If provided, `Pipeline` will log the current phase to console.\n */\n debugName?: string;\n\n /**\n * This is the only feature where weaver will use lenis to directly manipulate scrolling behaviour.\n *\n * By default, this value is `true` when a lenis instance is provided.\n *\n * `Pipeline` will stop and start lenis automatically when this variable is `true`.\n *\n * Disable this feature to gains complete control over lenis when mounting/unmounting to handle however you want.\n */\n lenisUsage?: 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 const parentPath = useMemo(\n () => getParentRoute(window.location.pathname),\n []\n );\n\n return (\n <>\n <RouteHandler {...restOfProps} parentPath={parentPath} />\n {children}\n </>\n );\n}\n\nfunction RouteHandler(\n props: Omit<PipelineProps, 'children'> & { parentPath: string }\n) {\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 const loopWatcher = useCallback(() => {\n if (!navigating && (!pageRendered || activeParent !== props.parentPath)) {\n if (props.lenisUsage === undefined || props.lenisUsage) {\n weaverSetup._lenisInstance?.start();\n }\n\n setPageRendered(true);\n setActiveParent(props.parentPath);\n\n if (props.debugName)\n console.log(`[${props.debugName}] Renderer status: Mounted`);\n }\n }, [\n activeParent,\n navigating,\n pageRendered,\n props.lenisUsage,\n props.debugName,\n props.parentPath,\n setActiveParent,\n setPageRendered,\n ]);\n\n useLayoutEffect(() => {\n document.title = props.title;\n setActivePipeline(props.parentPath);\n\n if (props.contentReady !== undefined && !props.contentReady) {\n if (props.debugName)\n console.log(`[${props.debugName}] Renderer status: Loading scene`);\n return;\n }\n\n const loopWatcherTask = setInterval(loopWatcher, 32);\n\n return () => {\n clearInterval(loopWatcherTask);\n };\n }, [\n setActivePipeline,\n props.contentReady,\n props.debugName,\n props.parentPath,\n props.title,\n loopWatcher,\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 if (props.lenisUsage === undefined || props.lenisUsage) {\n weaverSetup._lenisInstance?.stop();\n weaverSetup._lenisInstance?.scrollTo(0, {\n immediate: true,\n force: true,\n });\n }\n\n if (props.debugName)\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 type BasicTunnelIn = ({ children }: { children: ReactNode }) => null;\n\nclass WeaverSetup {\n /**\n * This variable is handled internally by weaver. **Do not use**.\n */\n get _lenisInstance(): Lenis | undefined {\n return (globalThis as any).__weaverLenis;\n }\n set _lenisInstance(val: Lenis | undefined) {\n (globalThis as any).__weaverLenis = val;\n }\n\n /**\n * This variable is handled internally by weaver. **Do not use**.\n */\n get _Default3DTunnelIn(): BasicTunnelIn | undefined {\n return (globalThis as any).__weaver3DTunnel;\n }\n set _Default3DTunnelIn(val: BasicTunnelIn | undefined) {\n (globalThis as any).__weaver3DTunnel = val;\n }\n\n setLenisInstance(instance: Lenis) {\n this._lenisInstance = instance;\n }\n set3DTunnel(tunnelIn: BasicTunnelIn) {\n this._Default3DTunnelIn = tunnelIn;\n }\n}\n\nexport const weaverSetup = new WeaverSetup();\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,SAA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B,MAAM;AACxB,WAAO,MAAM;AAOX,UAAI,MAAM,eAAe,UAAa,MAAM,YAAY;AACtD,oBAAY,gBAAgB,KAAK;AACjC,oBAAY,gBAAgB,SAAS,GAAG;AAAA,UACtC,WAAW;AAAA,UACX,OAAO;AAAA,QACT,CAAC;AAAA,MACH;AAEA,UAAI,MAAM;AACR,gBAAQ,IAAI,IAAI,MAAM,SAAS,8BAA8B;AAAA,IACjE;AAAA,EACF,CAAC;AAED,SAAO;AACT;;;AGnJO,IAAM,iBAAiB,CAAC,eAA0C;AACvE,QAAM,QAAQ,iBAAiB,CAACC,WAAUA,OAAM,UAAU,CAAC;AAC3D,SAAO;AACT;","names":["useLayoutEffect","useLayoutEffect","useCallback","useLayoutEffect","useLayoutEffect","useLayoutEffect","useCallback","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 { weaverSetup } 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 * 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 * If provided, `Pipeline` will log the current phase to console.\n */\n debugName?: string;\n\n /**\n * This is the only feature where weaver will use lenis to directly manipulate scrolling behaviour.\n *\n * By default, this value is `true` when a lenis instance is provided.\n *\n * `Pipeline` will stop and start lenis automatically when this variable is `true`.\n *\n * Disable this feature to gains complete control over lenis when mounting/unmounting to handle however you want.\n */\n lenisUsage?: 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\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 if (props.debugName)\n console.log(`[${props.debugName}] Renderer status: Loading scene`);\n return;\n }\n\n if (!navigating && (!pageRendered || activeParent !== props.parentPath)) {\n if (props.lenisUsage === undefined || props.lenisUsage) {\n weaverSetup._lenisInstance?.start();\n }\n\n setPageRendered(true);\n setActiveParent(props.parentPath);\n\n if (props.debugName)\n console.log(`[${props.debugName}] Renderer status: Mounted`);\n }\n }, [\n activeParent,\n setActivePipeline,\n navigating,\n pageRendered,\n props.lenisUsage,\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 if (props.lenisUsage === undefined || props.lenisUsage) {\n weaverSetup._lenisInstance?.stop();\n weaverSetup._lenisInstance?.scrollTo(0, {\n immediate: true,\n force: true,\n });\n }\n\n if (props.debugName)\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 type BasicTunnelIn = ({ children }: { children: ReactNode }) => null;\n\nclass WeaverSetup {\n /**\n * This variable is handled internally by weaver. **Do not use**.\n */\n get _lenisInstance(): Lenis | undefined {\n return (globalThis as any).__weaverLenis;\n }\n set _lenisInstance(val: Lenis | undefined) {\n (globalThis as any).__weaverLenis = val;\n }\n\n /**\n * This variable is handled internally by weaver. **Do not use**.\n */\n get _Default3DTunnelIn(): BasicTunnelIn | undefined {\n return (globalThis as any).__weaver3DTunnel;\n }\n set _Default3DTunnelIn(val: BasicTunnelIn | undefined) {\n (globalThis as any).__weaver3DTunnel = val;\n }\n\n setLenisInstance(instance: Lenis) {\n this._lenisInstance = instance;\n }\n set3DTunnel(tunnelIn: BasicTunnelIn) {\n this._Default3DTunnelIn = tunnelIn;\n }\n}\n\nexport const weaverSetup = new WeaverSetup();\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;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;AAAA,EACF,CAAC;AAED,sBAAoB,MAAM;AACxB,WAAO,MAAM;AAOX,UAAI,MAAM,eAAe,UAAa,MAAM,YAAY;AACtD,oBAAY,gBAAgB,KAAK;AACjC,oBAAY,gBAAgB,SAAS,GAAG;AAAA,UACtC,WAAW;AAAA,UACX,OAAO;AAAA,QACT,CAAC;AAAA,MACH;AAEA,UAAI,MAAM;AACR,gBAAQ,IAAI,IAAI,MAAM,SAAS,8BAA8B;AAAA,IACjE;AAAA,EACF,CAAC;AAED,SAAO;AACT;;;AGlIO,IAAM,iBAAiB,CAAC,eAA0C;AACvE,QAAM,QAAQ,iBAAiB,CAACC,WAAUA,OAAM,UAAU,CAAC;AAC3D,SAAO;AACT;","names":["useLayoutEffect","useLayoutEffect","useLayoutEffect","useLayoutEffect","useLayoutEffect","useLayoutEffect","state"]}
@@ -0,0 +1,128 @@
1
+ # Routing
2
+ The package wraps around `react-router` as a base for working with routing because it provides us a way to postpone parent components mounting.
3
+
4
+ ## `DelayedOutlet`, `Pipeline`
5
+ - `DelayedOutlet`:
6
+ - Drop-in replacement for `Outlet`.
7
+ - `Pipeline`:
8
+ - Declares parent for a route, handle route changes and communicates with `DelayedOutlet`.
9
+ - Recommended place to put the component is the parent for a route's components, see example below.
10
+ - It can't nest itself.
11
+
12
+ > [!CAUTION]
13
+ > The only officially supported router is `BrowserRouter`, we don't test with other methods.
14
+ >
15
+ > There can only be ONE `DelayedOutlet` per app and ONE `Pipeline` per parent path.
16
+
17
+ Other than that, use `react-router` like intended. `weaver/routing` has especially tested against going back and forth rapidly and works flawlessly in strict mode, even with throttle the CPU to a good x20 slowdown, so you don't have to suffer like we did developing the package!
18
+
19
+ While the route is delayed, the previous route is still displayed to ensure a smooth tranition to your likings.
20
+
21
+ Example usage with 2 endpoints, router delayed for `500ms`:
22
+
23
+ ```tsx
24
+ import { DelayedOutlet, Pipeline } from '@neveranyart/weaver/routing';
25
+ import { StrictMode, Suspense } from 'react';
26
+ import { createRoot } from 'react-dom/client';
27
+ import { createBrowserRouter, Link, RouterProvider } from 'react-router';
28
+
29
+ function Root() {
30
+ return (
31
+ <main>
32
+ <DelayedOutlet delay={500} />
33
+ </main>
34
+ );
35
+ }
36
+
37
+ function Home() {
38
+ return (
39
+ <Pipeline title='Home' debugName='Home' parentPath='/'>
40
+ <p>Home</p>
41
+ <Link to="/projects">Navigate</Link>
42
+ </Pipeline>
43
+ );
44
+ }
45
+
46
+ const router = createBrowserRouter([
47
+ {
48
+ path: '/',
49
+ element: <Root />,
50
+ children: [
51
+ {
52
+ index: true,
53
+ element: (
54
+ <Suspense>
55
+ <Home />
56
+ </Suspense>
57
+ ),
58
+ },
59
+ {
60
+ path: '/projects/*',
61
+ element: (
62
+ <Suspense>
63
+ <Pipeline title='Projects' debugName='Projects' parentPath='/projects/*'>
64
+ <p>Projects</p>
65
+ <Link to="/">Navigate</Link>
66
+ </Pipeline>
67
+ </Suspense>
68
+ ),
69
+ },
70
+ ],
71
+ },
72
+ ]);
73
+
74
+ createRoot(document.getElementById('root')!).render(
75
+ <StrictMode>
76
+ <RouterProvider router={router} />
77
+ </StrictMode>
78
+ );
79
+ ```
80
+
81
+ Routing also provides a quick way to react to state changes with a cool hook called `useWeaverState`. Containing 4 states for you to play with:
82
+
83
+ ```ts
84
+ // Covers the whole routing process. It is the recommended way of knowing if the content is ready to be displayed or not
85
+ const pageRendered = useWeaverState('pageRendered');
86
+
87
+ // Knowing which Pipeline has taken over previous one.
88
+ const activePipeline = useWeaverState('activePipeline');
89
+
90
+ // Which Pipeline has delivered its components on screen.
91
+ const activeParent = useWeaverState('activeParent');
92
+
93
+ // Tells when `DelayedOutlet` handles routing.
94
+ const navigating = useWeaverState('navigating');
95
+ ```
96
+
97
+ When a route change happens, this is how states in `weaver/routing` changes when a route change is successful:
98
+
99
+ - `+`: Other events/information.
100
+ - `!`: State changes.
101
+
102
+ ```
103
+ + Current `Pipeline` path: "/"
104
+ + User navigates.
105
+ ! pageRendered -> false, navigating -> true.
106
+ + Receives new parent.
107
+ + Delay route change.
108
+ + Set new `Pipeline`.
109
+ + `Pipeline` path "/" start unmounting process.
110
+ + New `Pipeline` path: "/projects".
111
+ ! activePipeline -> "/projects".
112
+ ! navigating -> false.
113
+ + New `Pipeline` start mounting process.
114
+ ! pageRendered -> true, activeParent -> "/projects".
115
+ ```
116
+
117
+ When a route change is cancelled by user:
118
+
119
+ ```
120
+ + Current `Pipeline` path: "/"
121
+ + User navigates.
122
+ ! pageRendered -> false, navigating -> true.
123
+ + Receives new parent.
124
+ + Delay route change.
125
+ + User cancelled.
126
+ + `Pipeline` path "/" detects cancel.
127
+ ! pageRendered -> true, navigating -> false.
128
+ ```
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.12",
5
+ "version": "1.0.14",
6
6
  "description": "An in-house package by neverany for making interactive React CSR.",
7
7
  "packageManager": "yarn@4.10.3",
8
8
  "publishConfig": {