@fictjs/hooks 0.1.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Fict
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,153 @@
1
+ # @fictjs/hooks
2
+
3
+ [![Node CI](https://github.com/fictjs/hooks/actions/workflows/nodejs.yml/badge.svg)](https://github.com/fictjs/hooks/actions/workflows/nodejs.yml)
4
+ [![npm](https://img.shields.io/npm/v/@fictjs/hooks.svg)](https://www.npmjs.com/package/@fictjs/hooks)
5
+ ![license](https://img.shields.io/npm/l/@fictjs/hooks)
6
+
7
+ Official hooks package for Fict.
8
+
9
+ `@fictjs/hooks` provides official, production-ready hooks built for Fict signal/lifecycle semantics.
10
+
11
+ ## Install
12
+
13
+ For application usage:
14
+
15
+ ```bash
16
+ pnpm add @fictjs/hooks @fictjs/runtime
17
+ ```
18
+
19
+ For repository development:
20
+
21
+ ```bash
22
+ pnpm install
23
+ ```
24
+
25
+ ## Requirements
26
+
27
+ - Node.js >= 18
28
+ - Peer dependency: `@fictjs/runtime@^0.8.0`
29
+
30
+ ## Quick Start
31
+
32
+ ```ts
33
+ import { useCounter, useMount } from '@fictjs/hooks';
34
+
35
+ export function CounterExample() {
36
+ const { count, inc, dec, reset } = useCounter(0);
37
+
38
+ useMount(() => {
39
+ inc();
40
+ });
41
+
42
+ return { count, inc, dec, reset };
43
+ }
44
+ ```
45
+
46
+ In plain TypeScript/JavaScript usage (without Fict compile transforms), read reactive values via accessors, for example `count()`.
47
+
48
+ ## Import Policy
49
+
50
+ - Only import from `@fictjs/hooks`; deep imports are unsupported
51
+ - Tree shaking is supported through ESM exports and `"sideEffects": false`
52
+
53
+ ## Runtime Semantics
54
+
55
+ - Hooks follow Fict top-level hook rules (`useX` in component/hook top-level scope)
56
+ - Effects/listeners/timers are auto-cleaned on root dispose
57
+ - Browser hooks are SSR-safe and provide unsupported fallbacks
58
+ - Browser globals can be injected with options like `window`, `document`, or `navigator` when needed
59
+
60
+ ## Hook Docs
61
+
62
+ - Lifecycle
63
+ - `useMount` -> `docs/hooks/useMount.md`
64
+ - `useUnmount` -> `docs/hooks/useUnmount.md`
65
+ - Event
66
+ - `useEventListener` -> `docs/hooks/useEventListener.md`
67
+ - `useClickOutside` -> `docs/hooks/useClickOutside.md`
68
+ - `useHover` -> `docs/hooks/useHover.md`
69
+ - `useFocusWithin` -> `docs/hooks/useFocusWithin.md`
70
+ - `useKeyPress` -> `docs/hooks/useKeyPress.md`
71
+ - Timing
72
+ - `useDebounceFn` -> `docs/hooks/useDebounceFn.md`
73
+ - `useThrottleFn` -> `docs/hooks/useThrottleFn.md`
74
+ - `useTimeoutFn` -> `docs/hooks/useTimeoutFn.md`
75
+ - `useIntervalFn` -> `docs/hooks/useIntervalFn.md`
76
+ - `useRafFn` -> `docs/hooks/useRafFn.md`
77
+ - State
78
+ - `useToggle` -> `docs/hooks/useToggle.md`
79
+ - `useCounter` -> `docs/hooks/useCounter.md`
80
+ - `usePrevious` -> `docs/hooks/usePrevious.md`
81
+ - `useVirtualList` -> `docs/hooks/useVirtualList.md`
82
+ - Browser
83
+ - `useScroll` -> `docs/hooks/useScroll.md`
84
+ - `useWindowScroll` -> `docs/hooks/useWindowScroll.md`
85
+ - `useWindowSize` -> `docs/hooks/useWindowSize.md`
86
+ - `useTitle` -> `docs/hooks/useTitle.md`
87
+ - `useFullscreen` -> `docs/hooks/useFullscreen.md`
88
+ - `usePermission` -> `docs/hooks/usePermission.md`
89
+ - `useGeolocation` -> `docs/hooks/useGeolocation.md`
90
+ - `useIdle` -> `docs/hooks/useIdle.md`
91
+ - `useSize` -> `docs/hooks/useSize.md`
92
+ - `useWebSocket` -> `docs/hooks/useWebSocket.md`
93
+ - `useMediaQuery` -> `docs/hooks/useMediaQuery.md`
94
+ - `useDocumentVisibility` -> `docs/hooks/useDocumentVisibility.md`
95
+ - `useNetwork` -> `docs/hooks/useNetwork.md`
96
+ - Storage
97
+ - `useStorage` -> `docs/hooks/useStorage.md`
98
+ - `useLocalStorage` -> `docs/hooks/useLocalStorage.md`
99
+ - `useSessionStorage` -> `docs/hooks/useSessionStorage.md`
100
+ - Observer
101
+ - `useIntersectionObserver` -> `docs/hooks/useIntersectionObserver.md`
102
+ - `useResizeObserver` -> `docs/hooks/useResizeObserver.md`
103
+ - `useMutationObserver` -> `docs/hooks/useMutationObserver.md`
104
+ - Async
105
+ - `useAsyncState` -> `docs/hooks/useAsyncState.md`
106
+ - `useFetch` -> `docs/hooks/useFetch.md`
107
+ - `useRequest` -> `docs/hooks/useRequest.md`
108
+ - Clipboard
109
+ - `useClipboard` -> `docs/hooks/useClipboard.md`
110
+
111
+ ## Demo Website
112
+
113
+ Run interactive hook demos:
114
+
115
+ ```bash
116
+ pnpm demo:dev
117
+ ```
118
+
119
+ Build static demo site:
120
+
121
+ ```bash
122
+ pnpm demo:build
123
+ ```
124
+
125
+ ## Quality Gates
126
+
127
+ Before publish, these checks must pass:
128
+
129
+ 1. `pnpm lint`
130
+ 2. `pnpm typecheck`
131
+ 3. `pnpm test:types`
132
+ 4. `pnpm test`
133
+ 5. `pnpm build`
134
+
135
+ `prepublishOnly` already enforces this pipeline.
136
+
137
+ ## Scripts
138
+
139
+ - `pnpm dev`: watch mode build with tsup
140
+ - `pnpm build`: build ESM + CJS + d.ts to `dist`
141
+ - `pnpm demo:dev`: run Vite demo website (`playground/`)
142
+ - `pnpm demo:build`: build Vite demo website
143
+ - `pnpm demo:preview`: preview built demo website
144
+ - `pnpm typecheck`: TypeScript type checking
145
+ - `pnpm test:types`: API type assertion tests
146
+ - `pnpm lint`: ESLint check
147
+ - `pnpm test`: run unit tests with Vitest
148
+ - `pnpm test:coverage`: run tests with coverage threshold checks
149
+ - `pnpm format`: format files with Prettier
150
+
151
+ ## Package Entry
152
+
153
+ Package entry is `src/index.ts`.