@neveranyart/weaver 1.0.15 → 1.0.17

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.
@@ -0,0 +1,31 @@
1
+ name: Publish Package
2
+
3
+ on:
4
+ push:
5
+ tags:
6
+ - "v*"
7
+
8
+ permissions:
9
+ id-token: write # Required for OIDC
10
+ contents: read
11
+
12
+ jobs:
13
+ publish:
14
+ runs-on: ubuntu-latest
15
+ steps:
16
+ - uses: actions/checkout@v6
17
+
18
+ - name: Corepack enable
19
+ run: corepack enable
20
+
21
+ - uses: actions/setup-node@v6
22
+ with:
23
+ node-version: "24"
24
+ registry-url: "https://registry.npmjs.org"
25
+ cache: "yarn"
26
+
27
+ - name: Install dependencies
28
+ run: yarn install --immutable
29
+
30
+ - name: Publish package
31
+ run: npm publish
package/README.md CHANGED
@@ -1,9 +1,11 @@
1
- # `@neveranyart/weaver`
1
+ # Weaver
2
2
 
3
3
  **WIP DOCS**
4
4
 
5
5
  An in-house core package by neveranyart for making performant, interactive React CSR.
6
6
 
7
+ <sub>Almost feels like a framework, but it's not.</sub>
8
+
7
9
  ![neverany branding](https://github.com/user-attachments/assets/8c09234f-d592-4adc-8ab1-284b1fca3f7c)
8
10
 
9
11
  ## Introduction
@@ -11,6 +13,21 @@ This package is published as an in-depth on `neverany` technicals. It is not int
11
13
 
12
14
  But, most components and tools are built with flexibility in mind, providing a balance between abstraction and verbose.
13
15
 
16
+ > [!INFO]
17
+ > `React v19+` is required.
18
+
19
+ ## Installation
20
+ NPM:
21
+ ```
22
+ npm i @neveranyart/weaver
23
+ ```
24
+
25
+ Yarn:
26
+ ```
27
+ yarn add @neveranyart/weaver
28
+ ```
29
+
30
+
14
31
  ## Documentations
15
32
  1. [Routing](https://github.com/neveranyart/weaver/blob/main/docs/ROUTING.md)
16
33
  2. Hooks
package/dist/hooks.d.mts CHANGED
@@ -1,9 +1,42 @@
1
1
  import { RefObject } from 'react';
2
2
  import { OrthographicCamera, PerspectiveCamera } from 'three';
3
3
 
4
- declare function useBreakpoints(breakpoints?: number[] | null): number;
4
+ /**
5
+ * A screen size hook to change components when media-query isn't viable. For example, swap out
6
+ * components when screen gets too small, changing layout of a 3D scene to match the size.
7
+ *
8
+ * The value passed in must be sorted in ascending order.
9
+ *
10
+ * The hooks return where the screen size belong inbetween, for example:
11
+ *
12
+ * ```
13
+ * Input: " 640 768 1024 1280 1536 "
14
+ * | | | | | |
15
+ * Returns: 0 1 2 3 4 5
16
+ * ```
17
+ *
18
+ * @param breakpoints Default value is TailwindCSS's screen sizes:
19
+ * `[640, 768, 1024, 1280, 1536]`
20
+ *
21
+ * @returns A number from `0` to `breakpoints.length + 1` depends on screen sizes.
22
+ */
23
+ declare function useBreakpoints(breakpoints?: number[]): number;
5
24
 
25
+ /**
26
+ * Effect to run once on mount/unmount, ignore all cautions.
27
+ *
28
+ * Strict mode still make this effect runs twice, but never by a state change.
29
+ *
30
+ * Used for initialization, clean up.
31
+ */
6
32
  declare function useEffectOnce(callback: React.EffectCallback): void;
33
+ /**
34
+ * Effect to run once on mount/unmount, ignore all cautions.
35
+ *
36
+ * Strict mode still make this effect runs twice, but never by a state change.
37
+ *
38
+ * Used for initialization, clean up.
39
+ */
7
40
  declare function useLayoutEffectOnce(callback: React.EffectCallback): void;
8
41
 
9
42
  interface HookOptions$1 {
@@ -16,32 +49,61 @@ interface HookOptions$1 {
16
49
  */
17
50
  intersectOn?: RefObject<HTMLOrSVGElement | null>;
18
51
  }
19
- declare const scrollCallbackReason: {
20
- readonly Resize: "resize";
21
- readonly Scroll: "scroll";
22
- readonly Initialize: "initialize";
23
- };
24
- type ScrollCallbackReason = (typeof scrollCallbackReason)[keyof typeof scrollCallbackReason];
25
- type Callback$2 = (latest: number, reason: ScrollCallbackReason) => void;
26
- declare function useLenisCallback(callback: Callback$2, options?: HookOptions$1): void;
52
+ type ScrollCallbackReason$1 = 'resize' | 'scroll' | 'initialize';
53
+ /**
54
+ * A lenis scroll hook.
55
+ *
56
+ * This hook calls many time and repeated. Update states inside this hook carefully to avoid performance issues.
57
+ */
58
+ declare function useLenisCallback(callback: (latest: number, reason: ScrollCallbackReason$1) => void, options?: HookOptions$1): void;
27
59
 
28
- interface MousePositionValues {
29
- x: number;
30
- y: number;
31
- }
32
60
  interface HookOptions {
33
- normalized?: boolean;
61
+ /**
62
+ * Hook will report when first initialized without waiting for scroll event to actually happens.
63
+ */
64
+ initialCall?: boolean;
65
+ /**
66
+ * Set an element to only call when the element is actually entering the viewport (with 25% `rootMargin`).
67
+ */
68
+ intersectOn?: RefObject<HTMLOrSVGElement | null>;
34
69
  }
35
- type Callback$1 = (latest: MousePositionValues) => void;
36
- declare function useMouseCallback(callback: Callback$1, options?: HookOptions): void;
70
+ type ScrollCallbackReason = 'resize' | 'scroll' | 'initialize';
71
+ /**
72
+ * A DOM scroll hook.
73
+ *
74
+ * This hook calls many time and repeated. Update states inside this hook carefully to avoid performance issues.
75
+ *
76
+ * For manipulating elements matches closely with the actual scroll offet, consider use `lenis` and utilize `useLenisCallback`.
77
+ */
78
+ declare function useMouseCallback(callback: (latest: number, reason: ScrollCallbackReason) => void, options?: HookOptions): void;
37
79
 
38
- declare function useNavigateAnchor(onNavigate?: () => void): (event: React.MouseEvent<HTMLAnchorElement, MouseEvent>) => void;
80
+ /**
81
+ * A hook to replace `<Link>` from `react-router`, attach the function to
82
+ * `onClick` event of an anchor tag to overwrites its behavior.
83
+ *
84
+ * Example usage:
85
+ * ```tsx
86
+ * const navigator = useNavigateAnchor();
87
+ *
88
+ * return (
89
+ * <a href="/" onClick={navigator}>
90
+ * Navigate
91
+ * </a>
92
+ * );
93
+ * ```
94
+ *
95
+ * @param onNavigate Calls when a navigation event happens.
96
+ * @param onSameRoute Calls when user is on the same route, no navigation happens.
97
+ * @returns
98
+ */
99
+ declare function useNavigateAnchor(onNavigate?: () => void, onSameRoute?: () => void): (event: React.MouseEvent<HTMLAnchorElement, MouseEvent>) => void;
39
100
 
40
101
  /**
41
- * A simple Orbit hook.
102
+ * A simple Orbit hook for ResizeObserver and IntersectionObserver.
42
103
  *
43
104
  * @param target HTML element ref to attach to.
44
105
  * @param events Specify which events should the orbit tracks.
106
+ * @param rootMargin Adjust `rootMargin` option for `IntersectionObserver`.
45
107
  */
46
108
  declare function useOrbit(options: {
47
109
  target?: RefObject<HTMLElement | null>;
@@ -52,15 +114,16 @@ declare function useOrbit(options: {
52
114
  rootMargin?: string;
53
115
  }): void;
54
116
 
55
- declare function useRawParams(prefix: string, limit?: number): (string | undefined)[];
56
-
57
- declare function useRouteNormalizer(options: {
58
- autoReplace: boolean;
59
- }): {
60
- pathname: string;
61
- normalizer: (input: string) => string;
62
- };
117
+ /**
118
+ * Routing hook. This hook updates and splits pathname on location change.
119
+ *
120
+ * Great for creating custom routes on the fly under the same parent `Pipeline`.
121
+ */
122
+ declare function useRawParams(): (string | undefined)[];
63
123
 
124
+ /**
125
+ * A state-based screen hook. It will change its state on resize.
126
+ */
64
127
  declare function useScreen(): {
65
128
  width: number;
66
129
  height: number;
@@ -71,13 +134,19 @@ interface ScreenCallbackValues {
71
134
  height: number;
72
135
  }
73
136
  type Callback = (props: ScreenCallbackValues) => void;
137
+ /**
138
+ * A callback-based screen hook. Recommended.
139
+ */
74
140
  declare function useScreenCallback(callback: Callback, options?: {
75
141
  initialCall?: boolean;
76
142
  }): void;
77
143
 
144
+ /**
145
+ * Get current threejs viewport with the actual current.
146
+ */
78
147
  declare function useViewport(customCamera?: OrthographicCamera | PerspectiveCamera): {
79
148
  width: number;
80
149
  height: number;
81
150
  };
82
151
 
83
- export { useBreakpoints, useEffectOnce, useLayoutEffectOnce, useLenisCallback, useMouseCallback, useNavigateAnchor, useOrbit, useRawParams, useRouteNormalizer, useScreen, useScreenCallback, useViewport };
152
+ export { useBreakpoints, useEffectOnce, useLayoutEffectOnce, useLenisCallback, useMouseCallback, useNavigateAnchor, useOrbit, useRawParams, useScreen, useScreenCallback, useViewport };
package/dist/hooks.d.ts CHANGED
@@ -1,9 +1,42 @@
1
1
  import { RefObject } from 'react';
2
2
  import { OrthographicCamera, PerspectiveCamera } from 'three';
3
3
 
4
- declare function useBreakpoints(breakpoints?: number[] | null): number;
4
+ /**
5
+ * A screen size hook to change components when media-query isn't viable. For example, swap out
6
+ * components when screen gets too small, changing layout of a 3D scene to match the size.
7
+ *
8
+ * The value passed in must be sorted in ascending order.
9
+ *
10
+ * The hooks return where the screen size belong inbetween, for example:
11
+ *
12
+ * ```
13
+ * Input: " 640 768 1024 1280 1536 "
14
+ * | | | | | |
15
+ * Returns: 0 1 2 3 4 5
16
+ * ```
17
+ *
18
+ * @param breakpoints Default value is TailwindCSS's screen sizes:
19
+ * `[640, 768, 1024, 1280, 1536]`
20
+ *
21
+ * @returns A number from `0` to `breakpoints.length + 1` depends on screen sizes.
22
+ */
23
+ declare function useBreakpoints(breakpoints?: number[]): number;
5
24
 
25
+ /**
26
+ * Effect to run once on mount/unmount, ignore all cautions.
27
+ *
28
+ * Strict mode still make this effect runs twice, but never by a state change.
29
+ *
30
+ * Used for initialization, clean up.
31
+ */
6
32
  declare function useEffectOnce(callback: React.EffectCallback): void;
33
+ /**
34
+ * Effect to run once on mount/unmount, ignore all cautions.
35
+ *
36
+ * Strict mode still make this effect runs twice, but never by a state change.
37
+ *
38
+ * Used for initialization, clean up.
39
+ */
7
40
  declare function useLayoutEffectOnce(callback: React.EffectCallback): void;
8
41
 
9
42
  interface HookOptions$1 {
@@ -16,32 +49,61 @@ interface HookOptions$1 {
16
49
  */
17
50
  intersectOn?: RefObject<HTMLOrSVGElement | null>;
18
51
  }
19
- declare const scrollCallbackReason: {
20
- readonly Resize: "resize";
21
- readonly Scroll: "scroll";
22
- readonly Initialize: "initialize";
23
- };
24
- type ScrollCallbackReason = (typeof scrollCallbackReason)[keyof typeof scrollCallbackReason];
25
- type Callback$2 = (latest: number, reason: ScrollCallbackReason) => void;
26
- declare function useLenisCallback(callback: Callback$2, options?: HookOptions$1): void;
52
+ type ScrollCallbackReason$1 = 'resize' | 'scroll' | 'initialize';
53
+ /**
54
+ * A lenis scroll hook.
55
+ *
56
+ * This hook calls many time and repeated. Update states inside this hook carefully to avoid performance issues.
57
+ */
58
+ declare function useLenisCallback(callback: (latest: number, reason: ScrollCallbackReason$1) => void, options?: HookOptions$1): void;
27
59
 
28
- interface MousePositionValues {
29
- x: number;
30
- y: number;
31
- }
32
60
  interface HookOptions {
33
- normalized?: boolean;
61
+ /**
62
+ * Hook will report when first initialized without waiting for scroll event to actually happens.
63
+ */
64
+ initialCall?: boolean;
65
+ /**
66
+ * Set an element to only call when the element is actually entering the viewport (with 25% `rootMargin`).
67
+ */
68
+ intersectOn?: RefObject<HTMLOrSVGElement | null>;
34
69
  }
35
- type Callback$1 = (latest: MousePositionValues) => void;
36
- declare function useMouseCallback(callback: Callback$1, options?: HookOptions): void;
70
+ type ScrollCallbackReason = 'resize' | 'scroll' | 'initialize';
71
+ /**
72
+ * A DOM scroll hook.
73
+ *
74
+ * This hook calls many time and repeated. Update states inside this hook carefully to avoid performance issues.
75
+ *
76
+ * For manipulating elements matches closely with the actual scroll offet, consider use `lenis` and utilize `useLenisCallback`.
77
+ */
78
+ declare function useMouseCallback(callback: (latest: number, reason: ScrollCallbackReason) => void, options?: HookOptions): void;
37
79
 
38
- declare function useNavigateAnchor(onNavigate?: () => void): (event: React.MouseEvent<HTMLAnchorElement, MouseEvent>) => void;
80
+ /**
81
+ * A hook to replace `<Link>` from `react-router`, attach the function to
82
+ * `onClick` event of an anchor tag to overwrites its behavior.
83
+ *
84
+ * Example usage:
85
+ * ```tsx
86
+ * const navigator = useNavigateAnchor();
87
+ *
88
+ * return (
89
+ * <a href="/" onClick={navigator}>
90
+ * Navigate
91
+ * </a>
92
+ * );
93
+ * ```
94
+ *
95
+ * @param onNavigate Calls when a navigation event happens.
96
+ * @param onSameRoute Calls when user is on the same route, no navigation happens.
97
+ * @returns
98
+ */
99
+ declare function useNavigateAnchor(onNavigate?: () => void, onSameRoute?: () => void): (event: React.MouseEvent<HTMLAnchorElement, MouseEvent>) => void;
39
100
 
40
101
  /**
41
- * A simple Orbit hook.
102
+ * A simple Orbit hook for ResizeObserver and IntersectionObserver.
42
103
  *
43
104
  * @param target HTML element ref to attach to.
44
105
  * @param events Specify which events should the orbit tracks.
106
+ * @param rootMargin Adjust `rootMargin` option for `IntersectionObserver`.
45
107
  */
46
108
  declare function useOrbit(options: {
47
109
  target?: RefObject<HTMLElement | null>;
@@ -52,15 +114,16 @@ declare function useOrbit(options: {
52
114
  rootMargin?: string;
53
115
  }): void;
54
116
 
55
- declare function useRawParams(prefix: string, limit?: number): (string | undefined)[];
56
-
57
- declare function useRouteNormalizer(options: {
58
- autoReplace: boolean;
59
- }): {
60
- pathname: string;
61
- normalizer: (input: string) => string;
62
- };
117
+ /**
118
+ * Routing hook. This hook updates and splits pathname on location change.
119
+ *
120
+ * Great for creating custom routes on the fly under the same parent `Pipeline`.
121
+ */
122
+ declare function useRawParams(): (string | undefined)[];
63
123
 
124
+ /**
125
+ * A state-based screen hook. It will change its state on resize.
126
+ */
64
127
  declare function useScreen(): {
65
128
  width: number;
66
129
  height: number;
@@ -71,13 +134,19 @@ interface ScreenCallbackValues {
71
134
  height: number;
72
135
  }
73
136
  type Callback = (props: ScreenCallbackValues) => void;
137
+ /**
138
+ * A callback-based screen hook. Recommended.
139
+ */
74
140
  declare function useScreenCallback(callback: Callback, options?: {
75
141
  initialCall?: boolean;
76
142
  }): void;
77
143
 
144
+ /**
145
+ * Get current threejs viewport with the actual current.
146
+ */
78
147
  declare function useViewport(customCamera?: OrthographicCamera | PerspectiveCamera): {
79
148
  width: number;
80
149
  height: number;
81
150
  };
82
151
 
83
- export { useBreakpoints, useEffectOnce, useLayoutEffectOnce, useLenisCallback, useMouseCallback, useNavigateAnchor, useOrbit, useRawParams, useRouteNormalizer, useScreen, useScreenCallback, useViewport };
152
+ export { useBreakpoints, useEffectOnce, useLayoutEffectOnce, useLenisCallback, useMouseCallback, useNavigateAnchor, useOrbit, useRawParams, useScreen, useScreenCallback, useViewport };