@pyreon/hooks 0.0.2 → 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.
Files changed (2) hide show
  1. package/package.json +12 -7
  2. package/lib/index2.d.ts +0 -312
package/package.json CHANGED
@@ -1,6 +1,11 @@
1
1
  {
2
2
  "name": "@pyreon/hooks",
3
- "version": "0.0.2",
3
+ "version": "0.1.0",
4
+ "repository": {
5
+ "type": "git",
6
+ "url": "https://github.com/pyreon/ui-system",
7
+ "directory": "packages/hooks"
8
+ },
4
9
  "description": "Signal-based reactive utilities for Pyreon",
5
10
  "license": "MIT",
6
11
  "type": "module",
@@ -36,13 +41,13 @@
36
41
  "typecheck": "tsc --noEmit"
37
42
  },
38
43
  "peerDependencies": {
39
- "@pyreon/core": ">=0.3.0",
40
- "@pyreon/reactivity": ">=0.3.0",
41
- "@pyreon/styler": "^0.0.2",
42
- "@pyreon/ui-core": "^0.0.2"
44
+ "@pyreon/core": ">=0.4.0 <1.0.0",
45
+ "@pyreon/reactivity": ">=0.4.0 <1.0.0",
46
+ "@pyreon/styler": "^0.1.0",
47
+ "@pyreon/ui-core": "^0.1.0"
43
48
  },
44
49
  "devDependencies": {
45
- "@vitus-labs/tools-rolldown": "^1.15.0",
46
- "@vitus-labs/tools-typescript": "^1.15.0"
50
+ "@vitus-labs/tools-rolldown": "^1.15.3",
51
+ "@vitus-labs/tools-typescript": "^1.15.3"
47
52
  }
48
53
  }
package/lib/index2.d.ts DELETED
@@ -1,312 +0,0 @@
1
- import { onMount } from "@pyreon/core";
2
-
3
- //#region src/useBreakpoint.d.ts
4
- type BreakpointMap = Record<string, number>;
5
- /**
6
- * Return the currently active breakpoint name as a reactive signal.
7
- */
8
- declare function useBreakpoint(breakpoints?: BreakpointMap): () => string;
9
- //#endregion
10
- //#region src/useClickOutside.d.ts
11
- /**
12
- * Call handler when a click occurs outside the target element.
13
- */
14
- declare function useClickOutside(getEl: () => HTMLElement | null, handler: () => void): void;
15
- //#endregion
16
- //#region src/useColorScheme.d.ts
17
- /**
18
- * Returns the OS color scheme preference as 'light' or 'dark'.
19
- */
20
- declare function useColorScheme(): () => "light" | "dark";
21
- //#endregion
22
- //#region src/useControllableState.d.ts
23
- type UseControllableStateOptions<T> = {
24
- value?: T | undefined;
25
- defaultValue: T;
26
- onChange?: ((value: T) => void) | undefined;
27
- };
28
- type UseControllableState = <T>(options: UseControllableStateOptions<T>) => [() => T, (next: T | ((prev: T) => T)) => void];
29
- /**
30
- * Unified controlled/uncontrolled state pattern.
31
- * When `value` is provided the component is controlled; otherwise
32
- * internal state is used with `defaultValue` as the initial value.
33
- * The `onChange` callback fires in both modes.
34
- *
35
- * Returns [getter, setter] where getter is a reactive function.
36
- */
37
- declare const useControllableState: UseControllableState;
38
- //#endregion
39
- //#region src/useDebouncedCallback.d.ts
40
- type DebouncedFn<T extends (...args: any[]) => any> = {
41
- (...args: Parameters<T>): void;
42
- cancel: () => void;
43
- flush: () => void;
44
- };
45
- type UseDebouncedCallback = <T extends (...args: any[]) => any>(callback: T, delay: number) => DebouncedFn<T>;
46
- /**
47
- * Returns a debounced version of the callback.
48
- * The returned function has `.cancel()` and `.flush()` methods.
49
- * Always calls the latest callback (no stale closures).
50
- * Cleans up on unmount.
51
- */
52
- declare const useDebouncedCallback: UseDebouncedCallback;
53
- //#endregion
54
- //#region src/useDebouncedValue.d.ts
55
- /**
56
- * Return a debounced version of a reactive value.
57
- */
58
- declare function useDebouncedValue<T>(getter: () => T, delayMs: number): () => T;
59
- //#endregion
60
- //#region src/useElementSize.d.ts
61
- interface Size {
62
- width: number;
63
- height: number;
64
- }
65
- /**
66
- * Observe element dimensions reactively via ResizeObserver.
67
- */
68
- declare function useElementSize(getEl: () => HTMLElement | null): () => Size;
69
- //#endregion
70
- //#region src/useFocus.d.ts
71
- interface UseFocusResult {
72
- focused: () => boolean;
73
- props: {
74
- onFocus: () => void;
75
- onBlur: () => void;
76
- };
77
- }
78
- /**
79
- * Track focus state reactively.
80
- */
81
- declare function useFocus(): UseFocusResult;
82
- //#endregion
83
- //#region src/useFocusTrap.d.ts
84
- /**
85
- * Trap Tab/Shift+Tab focus within a container element.
86
- */
87
- declare function useFocusTrap(getEl: () => HTMLElement | null): void;
88
- //#endregion
89
- //#region src/useHover.d.ts
90
- interface UseHoverResult {
91
- /** Reactive boolean — true when element is hovered */
92
- hovered: () => boolean;
93
- /** Props to spread onto the element */
94
- props: {
95
- onMouseEnter: () => void;
96
- onMouseLeave: () => void;
97
- };
98
- }
99
- /**
100
- * Track hover state reactively.
101
- *
102
- * @example
103
- * const { hovered, props } = useHover()
104
- * h('div', { ...props, class: () => hovered() ? 'active' : '' })
105
- */
106
- declare function useHover(): UseHoverResult;
107
- //#endregion
108
- //#region src/useIntersection.d.ts
109
- /**
110
- * Observe element intersection reactively.
111
- */
112
- declare function useIntersection(getEl: () => HTMLElement | null, options?: IntersectionObserverInit): () => IntersectionObserverEntry | null;
113
- //#endregion
114
- //#region src/useInterval.d.ts
115
- type UseInterval = (callback: () => void, delay: number | null) => void;
116
- /**
117
- * Declarative `setInterval` with auto-cleanup.
118
- * Pass `null` as `delay` to pause the interval.
119
- * Always calls the latest callback (no stale closures).
120
- */
121
- declare const useInterval: UseInterval;
122
- //#endregion
123
- //#region src/useIsomorphicLayoutEffect.d.ts
124
- /**
125
- * In Pyreon there is no SSR warning distinction between effect and
126
- * layout-effect as there is in React.
127
- *
128
- * On the client `onMount` fires synchronously after the component is
129
- * mounted (similar to useLayoutEffect). On the server `effect` is a
130
- * no-op. This export provides the appropriate primitive for each env.
131
- *
132
- * Consumers that need layout-timing should use `onMount` directly.
133
- * This hook is provided for API parity with the original library.
134
- */
135
- type UseIsomorphicLayoutEffect = typeof onMount;
136
- declare const useIsomorphicLayoutEffect: UseIsomorphicLayoutEffect;
137
- //#endregion
138
- //#region src/useKeyboard.d.ts
139
- /**
140
- * Listen for a specific key press.
141
- */
142
- declare function useKeyboard(key: string, handler: (event: KeyboardEvent) => void, options?: {
143
- event?: "keydown" | "keyup";
144
- target?: EventTarget;
145
- }): void;
146
- //#endregion
147
- //#region src/useLatest.d.ts
148
- type UseLatest = <T>(value: T) => {
149
- readonly current: T;
150
- };
151
- /**
152
- * Returns a ref-like object that always holds the latest value.
153
- * Useful to avoid stale closures in callbacks and effects.
154
- *
155
- * In Pyreon, since the component body runs once, this simply wraps
156
- * the value in a mutable object. The caller is expected to call this
157
- * once and update `.current` manually if needed, or pass a reactive
158
- * getter to read the latest value.
159
- */
160
- declare const useLatest: UseLatest;
161
- //#endregion
162
- //#region src/useMediaQuery.d.ts
163
- /**
164
- * Subscribe to a CSS media query, returns a reactive boolean.
165
- */
166
- declare function useMediaQuery(query: string): () => boolean;
167
- //#endregion
168
- //#region src/useMergedRef.d.ts
169
- type RefCallback<T> = (node: T | null) => void;
170
- type RefObject<T> = {
171
- current: T | null;
172
- };
173
- type Ref<T> = RefCallback<T> | RefObject<T>;
174
- type UseMergedRef = <T>(...refs: (Ref<T> | undefined)[]) => (node: T | null) => void;
175
- /**
176
- * Merges multiple refs (callback or object) into a single callback ref.
177
- * Handles undefined, callback refs, and object refs with `.current`.
178
- */
179
- declare const useMergedRef: <T>(...refs: (Ref<T> | undefined)[]) => ((node: T | null) => void);
180
- //#endregion
181
- //#region src/usePrevious.d.ts
182
- /**
183
- * Track the previous value of a reactive getter.
184
- * Returns undefined on first access.
185
- */
186
- declare function usePrevious<T>(getter: () => T): () => T | undefined;
187
- //#endregion
188
- //#region src/useReducedMotion.d.ts
189
- /**
190
- * Returns true when the user prefers reduced motion.
191
- */
192
- declare function useReducedMotion(): () => boolean;
193
- //#endregion
194
- //#region src/useRootSize.d.ts
195
- type RootSizeResult = {
196
- rootSize: number;
197
- pxToRem: (px: number) => string;
198
- remToPx: (rem: number) => number;
199
- };
200
- type UseRootSize = () => RootSizeResult;
201
- /**
202
- * Returns `rootSize` from the theme context along with
203
- * `pxToRem` and `remToPx` conversion utilities.
204
- *
205
- * Defaults to `16` when no rootSize is set in the theme.
206
- */
207
- declare const useRootSize: UseRootSize;
208
- //#endregion
209
- //#region src/useScrollLock.d.ts
210
- /**
211
- * Lock page scroll. Uses reference counting for concurrent locks.
212
- * Returns an unlock function.
213
- */
214
- declare function useScrollLock(): {
215
- lock: () => void;
216
- unlock: () => void;
217
- };
218
- //#endregion
219
- //#region src/useSpacing.d.ts
220
- type UseSpacing = (base?: number | undefined) => (multiplier: number) => string;
221
- /**
222
- * Returns a `spacing(n)` function that computes spacing values
223
- * based on `rootSize` from the theme.
224
- *
225
- * @param base - Base spacing unit in px (defaults to `rootSize / 2`, i.e. 8px)
226
- *
227
- * @example
228
- * ```ts
229
- * const spacing = useSpacing()
230
- * spacing(1) // "8px"
231
- * spacing(2) // "16px"
232
- * spacing(0.5) // "4px"
233
- * ```
234
- */
235
- declare const useSpacing: UseSpacing;
236
- //#endregion
237
- //#region src/useThemeValue.d.ts
238
- type UseThemeValue = <T = unknown>(path: string) => T | undefined;
239
- /**
240
- * Deep-reads a value from the current theme by dot-separated path.
241
- *
242
- * @example
243
- * ```ts
244
- * const primary = useThemeValue<string>('colors.primary')
245
- * const columns = useThemeValue<number>('grid.columns')
246
- * ```
247
- */
248
- declare const useThemeValue: UseThemeValue;
249
- //#endregion
250
- //#region src/useThrottledCallback.d.ts
251
- type ThrottledFn<T extends (...args: any[]) => any> = {
252
- (...args: Parameters<T>): void;
253
- cancel: () => void;
254
- };
255
- type UseThrottledCallback = <T extends (...args: any[]) => any>(callback: T, delay: number) => ThrottledFn<T>;
256
- /**
257
- * Returns a throttled version of the callback.
258
- * Uses `throttle` from `@pyreon/ui-core`.
259
- * Always calls the latest callback (no stale closures).
260
- * Cleans up on unmount.
261
- */
262
- declare const useThrottledCallback: UseThrottledCallback;
263
- //#endregion
264
- //#region src/useTimeout.d.ts
265
- type UseTimeout = (callback: () => void, delay: number | null) => {
266
- reset: () => void;
267
- clear: () => void;
268
- };
269
- /**
270
- * Declarative `setTimeout` with auto-cleanup.
271
- * Pass `null` as `delay` to disable. Returns `reset` and `clear` controls.
272
- * Always calls the latest callback (no stale closures).
273
- */
274
- declare const useTimeout: UseTimeout;
275
- //#endregion
276
- //#region src/useToggle.d.ts
277
- interface UseToggleResult {
278
- value: () => boolean;
279
- toggle: () => void;
280
- setTrue: () => void;
281
- setFalse: () => void;
282
- }
283
- /**
284
- * Simple boolean toggle.
285
- */
286
- declare function useToggle(initial?: boolean): UseToggleResult;
287
- //#endregion
288
- //#region src/useUpdateEffect.d.ts
289
- type UseUpdateEffect = <T>(source: () => T, callback: (newVal: T, oldVal: T | undefined) => undefined | (() => void)) => void;
290
- /**
291
- * Like `effect` but skips the initial value — only fires on updates.
292
- *
293
- * In Pyreon, this is implemented using `watch()` which already skips
294
- * the initial value by default (immediate defaults to false).
295
- *
296
- * @param source - A reactive getter to watch
297
- * @param callback - Called when source changes, receives (newVal, oldVal)
298
- */
299
- declare const useUpdateEffect: UseUpdateEffect;
300
- //#endregion
301
- //#region src/useWindowResize.d.ts
302
- interface WindowSize {
303
- width: number;
304
- height: number;
305
- }
306
- /**
307
- * Track window dimensions reactively with throttling.
308
- */
309
- declare function useWindowResize(throttleMs?: number): () => WindowSize;
310
- //#endregion
311
- export { type BreakpointMap, type Size, type UseControllableState, type UseDebouncedCallback, type UseFocusResult, type UseHoverResult, type UseInterval, type UseIsomorphicLayoutEffect, type UseLatest, type UseMergedRef, type UseRootSize, type UseSpacing, type UseThemeValue, type UseThrottledCallback, type UseTimeout, type UseToggleResult, type UseUpdateEffect, type WindowSize, useBreakpoint, useClickOutside, useColorScheme, useControllableState, useDebouncedCallback, useDebouncedValue, useElementSize, useFocus, useFocusTrap, useHover, useIntersection, useInterval, useIsomorphicLayoutEffect, useKeyboard, useLatest, useMediaQuery, useMergedRef, usePrevious, useReducedMotion, useRootSize, useScrollLock, useSpacing, useThemeValue, useThrottledCallback, useTimeout, useToggle, useUpdateEffect, useWindowResize };
312
- //# sourceMappingURL=index2.d.ts.map