@unsetsoft/ryunixjs 1.2.5-canary.6 → 1.2.5-canary.9

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,529 @@
1
+ /**
2
+ * Public typings for `@unsetsoft/ryunixjs`.
3
+ *
4
+ * Runtime remains JavaScript (Rollup bundles in `dist/`). These declarations
5
+ * cover the package entry, hooks, components, and SSR helpers exported from
6
+ * `src/main.js`.
7
+ */
8
+
9
+ // ---------------------------------------------------------------------------
10
+ // Virtual DOM
11
+ // ---------------------------------------------------------------------------
12
+
13
+ export type RyunixComponent<P = Record<string, unknown>> = (
14
+ props: P,
15
+ ) => RyunixNode
16
+
17
+ export type RyunixNode =
18
+ | RyunixElement
19
+ | string
20
+ | number
21
+ | boolean
22
+ | null
23
+ | undefined
24
+
25
+ export interface RyunixElement<
26
+ P extends Record<string, unknown> = Record<string, unknown>,
27
+ > {
28
+ type: string | symbol | RyunixComponent<P>
29
+ props: P & { children?: RyunixNode[] }
30
+ }
31
+
32
+ export type RyunixElementType =
33
+ | string
34
+ | symbol
35
+ | RyunixComponent
36
+ | { _contextId?: string }
37
+
38
+ export function createElement<P extends Record<string, unknown>>(
39
+ type: RyunixElementType,
40
+ props?: P | null,
41
+ ...children: RyunixNode[]
42
+ ): RyunixElement<P>
43
+
44
+ export function Fragment(props: {
45
+ children?: RyunixNode | RyunixNode[]
46
+ }): RyunixElement
47
+
48
+ export function cloneElement<P extends Record<string, unknown>>(
49
+ element: RyunixElement<P>,
50
+ props?: Partial<P> | null,
51
+ ...children: RyunixNode[]
52
+ ): RyunixElement<P>
53
+
54
+ export function isValidElement(object: unknown): object is RyunixElement
55
+
56
+ // ---------------------------------------------------------------------------
57
+ // Client rendering
58
+ // ---------------------------------------------------------------------------
59
+
60
+ export interface RyunixRoot {
61
+ dom: Element | DocumentFragment | null
62
+ props: { children?: RyunixNode[] }
63
+ alternate?: RyunixRoot | null
64
+ isHydrating?: boolean
65
+ hydrateCursor?: ChildNode | null
66
+ }
67
+
68
+ export function render(
69
+ element: RyunixNode,
70
+ container: Element | DocumentFragment,
71
+ ): RyunixRoot
72
+
73
+ export function hydrate(
74
+ element: RyunixNode,
75
+ container: Element | DocumentFragment,
76
+ ): RyunixRoot
77
+
78
+ export function init(
79
+ MainElement: RyunixNode,
80
+ root?: string,
81
+ components?: Record<string, RyunixComponent>,
82
+ ): RyunixRoot
83
+
84
+ export function safeRender<P extends Record<string, unknown>>(
85
+ component: RyunixComponent<P>,
86
+ props: P,
87
+ onError?: (error: unknown) => void,
88
+ ): RyunixNode
89
+
90
+ // ---------------------------------------------------------------------------
91
+ // Server rendering
92
+ // ---------------------------------------------------------------------------
93
+
94
+ export interface RyunixRenderToStringOptions {
95
+ nonce?: string
96
+ }
97
+
98
+ export function escapeHtml(unsafe: string): string
99
+
100
+ export function renderToString(
101
+ element: RyunixNode,
102
+ options?: RyunixRenderToStringOptions,
103
+ ): string
104
+
105
+ export function renderToStringAsync(
106
+ element: RyunixNode,
107
+ options?: RyunixRenderToStringOptions,
108
+ ): Promise<string>
109
+
110
+ export function renderToReadableStream(
111
+ element: RyunixNode,
112
+ options?: RyunixRenderToStringOptions,
113
+ ): ReadableStream<Uint8Array>
114
+
115
+ // ---------------------------------------------------------------------------
116
+ // Hooks — state
117
+ // ---------------------------------------------------------------------------
118
+
119
+ export type RyunixSetState<S> = (
120
+ value: S | ((prev: S) => S),
121
+ priority?: number,
122
+ ) => void
123
+
124
+ export type RyunixDispatch<A> = (action: A, priority?: number) => void
125
+
126
+ export type RyunixReducer<S, A> = (state: S, action: A) => S
127
+
128
+ export function useStore<S>(
129
+ initialState: S | (() => S),
130
+ priority?: number,
131
+ ): [S, RyunixSetState<S>]
132
+
133
+ export function useReducer<S, A>(
134
+ reducer: RyunixReducer<S, A>,
135
+ initialState: S,
136
+ init?: (initial: S) => S,
137
+ defaultPriority?: number,
138
+ ): [S, RyunixDispatch<A>]
139
+
140
+ export function useStorePriority<S>(
141
+ initialState: S | (() => S),
142
+ ): [S, RyunixSetState<S>]
143
+
144
+ export function usePersistentStore<S extends string>(
145
+ key: string,
146
+ initialState?: S,
147
+ ): [S, RyunixSetState<S>]
148
+
149
+ /** @deprecated Misspelled alias kept for backwards compatibility. */
150
+ export const usePersitentStore: typeof usePersistentStore
151
+
152
+ export function useSwitch(
153
+ initialState?: boolean,
154
+ ): [boolean, RyunixSetState<boolean>, () => void]
155
+
156
+ // ---------------------------------------------------------------------------
157
+ // Hooks — effects & memoization
158
+ // ---------------------------------------------------------------------------
159
+
160
+ export type RyunixEffectCallback = () => void | (() => void)
161
+
162
+ export function useEffect(
163
+ callback: RyunixEffectCallback,
164
+ deps?: readonly unknown[],
165
+ ): void
166
+
167
+ export function useLayoutEffect(
168
+ callback: RyunixEffectCallback,
169
+ deps?: readonly unknown[],
170
+ ): void
171
+
172
+ export function useRef<T>(initialValue: T): { current: T }
173
+
174
+ export function useMemo<T>(compute: () => T, deps?: readonly unknown[]): T
175
+
176
+ export function useCallback<T extends (...args: never[]) => unknown>(
177
+ callback: T,
178
+ deps?: readonly unknown[],
179
+ ): T
180
+
181
+ export function useDebounce<T>(value: T, delay?: number): T
182
+
183
+ export function useThrottle<T>(value: T, interval?: number): T
184
+
185
+ export function useTransition(): [
186
+ boolean,
187
+ (callback: () => void, priority?: number) => void,
188
+ ]
189
+
190
+ export function useDeferredValue<T>(value: T): T
191
+
192
+ export function useId(): string
193
+
194
+ export function resetIdCounter(): void
195
+
196
+ // ---------------------------------------------------------------------------
197
+ // Context
198
+ // ---------------------------------------------------------------------------
199
+
200
+ export interface RyunixContext<T> {
201
+ Provider: RyunixComponent<{ value: T; children?: RyunixNode }>
202
+ useContext: (ctxID?: string) => T
203
+ }
204
+
205
+ export function createContext<T>(
206
+ contextId?: string,
207
+ defaultValue?: T,
208
+ ): RyunixContext<T>
209
+
210
+ // ---------------------------------------------------------------------------
211
+ // Hooks — document / URL
212
+ // ---------------------------------------------------------------------------
213
+
214
+ export function useQuery(): Record<string, string>
215
+
216
+ export function useHash(): string
217
+
218
+ export interface RyunixMetadataTags {
219
+ title?: string
220
+ pageTitle?: string
221
+ canonical?: string
222
+ [key: string]: string | undefined
223
+ }
224
+
225
+ export interface RyunixMetadataOptions {
226
+ title?: {
227
+ template?: string
228
+ prefix?: string
229
+ }
230
+ }
231
+
232
+ export function useMetadata(
233
+ tags?: RyunixMetadataTags,
234
+ options?: RyunixMetadataOptions,
235
+ ): void
236
+
237
+ // ---------------------------------------------------------------------------
238
+ // Router
239
+ // ---------------------------------------------------------------------------
240
+
241
+ export interface RyunixRouteProps {
242
+ key?: string
243
+ params?: Record<string, string | string[]>
244
+ query?: Record<string, string>
245
+ hash?: string
246
+ location?: string
247
+ }
248
+
249
+ export interface RyunixRoute {
250
+ path?: string
251
+ component?: RyunixComponent<RyunixRouteProps>
252
+ subRoutes?: RyunixRoute[]
253
+ NotFound?: RyunixComponent
254
+ }
255
+
256
+ export interface RyunixRouterContext {
257
+ location: string
258
+ params: Record<string, string | string[]>
259
+ query: Record<string, string>
260
+ navigate: (path: string) => void
261
+ route: RyunixRoute | null
262
+ }
263
+
264
+ export function RouterProvider(props: {
265
+ routes: RyunixRoute[]
266
+ children?: RyunixNode
267
+ }): RyunixNode
268
+
269
+ export function useRouter(): RyunixRouterContext
270
+
271
+ export function Children(): RyunixNode
272
+
273
+ export function usePathname(): string
274
+
275
+ export function useSearchParams(): URLSearchParams
276
+
277
+ export interface RyunixLinkProps extends Record<string, unknown> {
278
+ to: string
279
+ prefetch?: boolean
280
+ className?: string
281
+ 'ryunix-class'?: string
282
+ }
283
+
284
+ export function Link(props: RyunixLinkProps): RyunixElement
285
+
286
+ export interface RyunixNavLinkProps extends RyunixLinkProps {
287
+ exact?: boolean
288
+ }
289
+
290
+ export function NavLink(props: RyunixNavLinkProps): RyunixElement
291
+
292
+ // ---------------------------------------------------------------------------
293
+ // Components & boundaries
294
+ // ---------------------------------------------------------------------------
295
+
296
+ export function memo<P extends Record<string, unknown>>(
297
+ Component: RyunixComponent<P>,
298
+ arePropsEqual?: (prev: P, next: P) => boolean,
299
+ ): RyunixComponent<P>
300
+
301
+ export function shallowEqual(
302
+ prevProps: Record<string, unknown>,
303
+ nextProps: Record<string, unknown>,
304
+ ): boolean
305
+
306
+ export function deepEqual(a: unknown, b: unknown): boolean
307
+
308
+ export type RyunixLazyImport<P = Record<string, unknown>> = () => Promise<
309
+ { default: RyunixComponent<P> } | RyunixComponent<P>
310
+ >
311
+
312
+ export function lazy<P extends Record<string, unknown>>(
313
+ importFn: RyunixLazyImport<P>,
314
+ ): RyunixComponent<P>
315
+
316
+ export function Suspense(props: {
317
+ fallback?: RyunixNode
318
+ children?: RyunixNode
319
+ }): RyunixNode
320
+
321
+ export function preload(
322
+ importFn: RyunixLazyImport,
323
+ ): Promise<{ default: RyunixComponent } | RyunixComponent>
324
+
325
+ export function forwardRef<P extends Record<string, unknown>>(
326
+ render: (props: P, ref: unknown) => RyunixNode,
327
+ ): RyunixComponent<P & { ref?: unknown }>
328
+
329
+ export function createPortal(
330
+ children: RyunixNode,
331
+ container: Element | DocumentFragment,
332
+ ): RyunixElement | null
333
+
334
+ export function ErrorBoundary(props: {
335
+ children?: RyunixNode
336
+ fallback?: RyunixNode | ((error: unknown) => RyunixNode)
337
+ }): RyunixNode
338
+
339
+ export function ServerBoundary(props: {
340
+ children?: RyunixNode
341
+ id?: string
342
+ }): RyunixNode
343
+
344
+ export function Image(
345
+ props: { src: string } & Record<string, unknown>,
346
+ ): RyunixElement
347
+
348
+ export type RyunixMDXComponents = Record<string, RyunixComponent>
349
+
350
+ export function MDXContent(props: {
351
+ children?: RyunixNode
352
+ components?: RyunixMDXComponents
353
+ }): RyunixElement
354
+
355
+ export const MDXProvider: RyunixComponent<{
356
+ value?: RyunixMDXComponents
357
+ children?: RyunixNode
358
+ }>
359
+
360
+ export function useMDXComponents(): RyunixMDXComponents
361
+
362
+ export function getMDXComponents(
363
+ components?: RyunixMDXComponents,
364
+ ): RyunixMDXComponents
365
+
366
+ export const defaultComponents: RyunixMDXComponents
367
+
368
+ export function RyunixDevOverlay(propsOrError?: unknown): RyunixNode
369
+
370
+ // ---------------------------------------------------------------------------
371
+ // Utilities
372
+ // ---------------------------------------------------------------------------
373
+
374
+ export const Priority: {
375
+ readonly IMMEDIATE: 1
376
+ readonly USER_BLOCKING: 2
377
+ readonly NORMAL: 3
378
+ readonly LOW: 4
379
+ readonly IDLE: 5
380
+ }
381
+
382
+ export function batchUpdates(callback: () => void): void
383
+
384
+ export interface RyunixProfilerStats {
385
+ total: number
386
+ avg: number
387
+ max: number
388
+ min: number
389
+ count: number
390
+ }
391
+
392
+ export interface RyunixProfilerComponentStats {
393
+ name: string
394
+ avg: number
395
+ max: number
396
+ count: number
397
+ }
398
+
399
+ export interface RyunixProfiler {
400
+ enabled: boolean
401
+ startMeasure(name: string): void
402
+ endMeasure(name: string): number | undefined
403
+ recordRender(componentName: string, duration: number): void
404
+ getStats(): RyunixProfilerStats | null
405
+ getSlowestComponents(limit?: number): RyunixProfilerComponentStats[]
406
+ logStats(): void
407
+ clear(): void
408
+ enable(): void
409
+ disable(): void
410
+ }
411
+
412
+ export const profiler: RyunixProfiler
413
+
414
+ export function useProfiler(componentName: string): () => void
415
+
416
+ export function withProfiler<P extends Record<string, unknown>>(
417
+ Component: RyunixComponent<P>,
418
+ name: string,
419
+ ): RyunixComponent<P>
420
+
421
+ export function createActionProxy(
422
+ actionId: string,
423
+ ): (...args: unknown[]) => Promise<unknown>
424
+
425
+ /** @internal Re-exported for advanced tooling; not part of the stable public API. */
426
+ export function getState(): Record<string, unknown>
427
+
428
+ // ---------------------------------------------------------------------------
429
+ // Hooks namespace (`export * as Hooks`)
430
+ // ---------------------------------------------------------------------------
431
+
432
+ export namespace Hooks {
433
+ export type SetState<S> = RyunixSetState<S>
434
+ export type Dispatch<A> = RyunixDispatch<A>
435
+ export type Reducer<S, A> = RyunixReducer<S, A>
436
+
437
+ export const useStore: typeof useStore
438
+ export const useReducer: typeof useReducer
439
+ export const useEffect: typeof useEffect
440
+ export const useLayoutEffect: typeof useLayoutEffect
441
+ export const useRef: typeof useRef
442
+ export const useMemo: typeof useMemo
443
+ export const useCallback: typeof useCallback
444
+ export const createContext: typeof createContext
445
+ export const useQuery: typeof useQuery
446
+ export const useHash: typeof useHash
447
+ export const useMetadata: typeof useMetadata
448
+ export const useId: typeof useId
449
+ export const resetIdCounter: typeof resetIdCounter
450
+ export const useDebounce: typeof useDebounce
451
+ export const useThrottle: typeof useThrottle
452
+ export const useStorePriority: typeof useStorePriority
453
+ export const useTransition: typeof useTransition
454
+ export const useDeferredValue: typeof useDeferredValue
455
+ export const usePersistentStore: typeof usePersistentStore
456
+ export const usePersitentStore: typeof usePersitentStore
457
+ export const useSwitch: typeof useSwitch
458
+ export const RouterProvider: typeof RouterProvider
459
+ export const useRouter: typeof useRouter
460
+ export const Children: typeof Children
461
+ export const NavLink: typeof NavLink
462
+ export const Link: typeof Link
463
+ export const usePathname: typeof usePathname
464
+ export const useSearchParams: typeof useSearchParams
465
+ }
466
+
467
+ declare const Ryunix: {
468
+ createElement: typeof createElement
469
+ Fragment: typeof Fragment
470
+ cloneElement: typeof cloneElement
471
+ isValidElement: typeof isValidElement
472
+ render: typeof render
473
+ init: typeof init
474
+ safeRender: typeof safeRender
475
+ hydrate: typeof hydrate
476
+ renderToString: typeof renderToString
477
+ renderToReadableStream: typeof renderToReadableStream
478
+ escapeHtml: typeof escapeHtml
479
+ renderToStringAsync: typeof renderToStringAsync
480
+ useStore: typeof useStore
481
+ useReducer: typeof useReducer
482
+ useEffect: typeof useEffect
483
+ useLayoutEffect: typeof useLayoutEffect
484
+ useRef: typeof useRef
485
+ useMemo: typeof useMemo
486
+ useCallback: typeof useCallback
487
+ createContext: typeof createContext
488
+ useQuery: typeof useQuery
489
+ useHash: typeof useHash
490
+ useMetadata: typeof useMetadata
491
+ useId: typeof useId
492
+ resetIdCounter: typeof resetIdCounter
493
+ useDebounce: typeof useDebounce
494
+ useThrottle: typeof useThrottle
495
+ useStorePriority: typeof useStorePriority
496
+ useTransition: typeof useTransition
497
+ useDeferredValue: typeof useDeferredValue
498
+ usePersistentStore: typeof usePersistentStore
499
+ usePersitentStore: typeof usePersitentStore
500
+ useSwitch: typeof useSwitch
501
+ RouterProvider: typeof RouterProvider
502
+ useRouter: typeof useRouter
503
+ Children: typeof Children
504
+ NavLink: typeof NavLink
505
+ Link: typeof Link
506
+ usePathname: typeof usePathname
507
+ useSearchParams: typeof useSearchParams
508
+ Hooks: typeof Hooks
509
+ memo: typeof memo
510
+ shallowEqual: typeof shallowEqual
511
+ deepEqual: typeof deepEqual
512
+ lazy: typeof lazy
513
+ Suspense: typeof Suspense
514
+ preload: typeof preload
515
+ batchUpdates: typeof batchUpdates
516
+ Priority: typeof Priority
517
+ profiler: typeof profiler
518
+ useProfiler: typeof useProfiler
519
+ withProfiler: typeof withProfiler
520
+ forwardRef: typeof forwardRef
521
+ createPortal: typeof createPortal
522
+ ServerBoundary: typeof ServerBoundary
523
+ ErrorBoundary: typeof ErrorBoundary
524
+ getState: typeof getState
525
+ createActionProxy: typeof createActionProxy
526
+ RyunixDevOverlay: typeof RyunixDevOverlay
527
+ }
528
+
529
+ export default Ryunix
@@ -0,0 +1,19 @@
1
+ import type { RyunixElement, RyunixRoute, useStore } from './index'
2
+
3
+ /** Compile-time smoke test for public core types (not executed). */
4
+ const _element: RyunixElement = {
5
+ type: 'motion.div',
6
+ props: { children: [] },
7
+ }
8
+
9
+ const _route: RyunixRoute = {
10
+ path: '/blog/:slug',
11
+ component: () => _element,
12
+ }
13
+
14
+ type _HookReturn = ReturnType<typeof useStore<number>>
15
+ const _state: _HookReturn = [0, () => {}]
16
+
17
+ void _element
18
+ void _route
19
+ void _state