@unsetsoft/ryunixjs 1.2.5-canary.1 → 1.2.5-canary.11

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,540 @@
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 HydrationBoundary(props: {
345
+ children?: RyunixNode
346
+ id?: string
347
+ }): RyunixNode
348
+
349
+ export function logHydrationInfo(message: string): void
350
+ export function logHydrationRecoverable(detail: string): void
351
+ export function logHydrationBoundaryMismatch(detail: string): void
352
+ export function logHydrationBoundaryRecovery(): void
353
+ export function logHydrationFatal(reason: string): void
354
+
355
+ export function Image(
356
+ props: { src: string } & Record<string, unknown>,
357
+ ): RyunixElement
358
+
359
+ export type RyunixMDXComponents = Record<string, RyunixComponent>
360
+
361
+ export function MDXContent(props: {
362
+ children?: RyunixNode
363
+ components?: RyunixMDXComponents
364
+ }): RyunixElement
365
+
366
+ export const MDXProvider: RyunixComponent<{
367
+ value?: RyunixMDXComponents
368
+ children?: RyunixNode
369
+ }>
370
+
371
+ export function useMDXComponents(): RyunixMDXComponents
372
+
373
+ export function getMDXComponents(
374
+ components?: RyunixMDXComponents,
375
+ ): RyunixMDXComponents
376
+
377
+ export const defaultComponents: RyunixMDXComponents
378
+
379
+ export function RyunixDevOverlay(propsOrError?: unknown): RyunixNode
380
+
381
+ // ---------------------------------------------------------------------------
382
+ // Utilities
383
+ // ---------------------------------------------------------------------------
384
+
385
+ export const Priority: {
386
+ readonly IMMEDIATE: 1
387
+ readonly USER_BLOCKING: 2
388
+ readonly NORMAL: 3
389
+ readonly LOW: 4
390
+ readonly IDLE: 5
391
+ }
392
+
393
+ export function batchUpdates(callback: () => void): void
394
+
395
+ export interface RyunixProfilerStats {
396
+ total: number
397
+ avg: number
398
+ max: number
399
+ min: number
400
+ count: number
401
+ }
402
+
403
+ export interface RyunixProfilerComponentStats {
404
+ name: string
405
+ avg: number
406
+ max: number
407
+ count: number
408
+ }
409
+
410
+ export interface RyunixProfiler {
411
+ enabled: boolean
412
+ startMeasure(name: string): void
413
+ endMeasure(name: string): number | undefined
414
+ recordRender(componentName: string, duration: number): void
415
+ getStats(): RyunixProfilerStats | null
416
+ getSlowestComponents(limit?: number): RyunixProfilerComponentStats[]
417
+ logStats(): void
418
+ clear(): void
419
+ enable(): void
420
+ disable(): void
421
+ }
422
+
423
+ export const profiler: RyunixProfiler
424
+
425
+ export function useProfiler(componentName: string): () => void
426
+
427
+ export function withProfiler<P extends Record<string, unknown>>(
428
+ Component: RyunixComponent<P>,
429
+ name: string,
430
+ ): RyunixComponent<P>
431
+
432
+ export function createActionProxy(
433
+ actionId: string,
434
+ ): (...args: unknown[]) => Promise<unknown>
435
+
436
+ /** @internal Re-exported for advanced tooling; not part of the stable public API. */
437
+ export function getState(): Record<string, unknown>
438
+
439
+ // ---------------------------------------------------------------------------
440
+ // Hooks namespace (`export * as Hooks`)
441
+ // ---------------------------------------------------------------------------
442
+
443
+ export namespace Hooks {
444
+ export type SetState<S> = RyunixSetState<S>
445
+ export type Dispatch<A> = RyunixDispatch<A>
446
+ export type Reducer<S, A> = RyunixReducer<S, A>
447
+
448
+ export const useStore: typeof useStore
449
+ export const useReducer: typeof useReducer
450
+ export const useEffect: typeof useEffect
451
+ export const useLayoutEffect: typeof useLayoutEffect
452
+ export const useRef: typeof useRef
453
+ export const useMemo: typeof useMemo
454
+ export const useCallback: typeof useCallback
455
+ export const createContext: typeof createContext
456
+ export const useQuery: typeof useQuery
457
+ export const useHash: typeof useHash
458
+ export const useMetadata: typeof useMetadata
459
+ export const useId: typeof useId
460
+ export const resetIdCounter: typeof resetIdCounter
461
+ export const useDebounce: typeof useDebounce
462
+ export const useThrottle: typeof useThrottle
463
+ export const useStorePriority: typeof useStorePriority
464
+ export const useTransition: typeof useTransition
465
+ export const useDeferredValue: typeof useDeferredValue
466
+ export const usePersistentStore: typeof usePersistentStore
467
+ export const usePersitentStore: typeof usePersitentStore
468
+ export const useSwitch: typeof useSwitch
469
+ export const RouterProvider: typeof RouterProvider
470
+ export const useRouter: typeof useRouter
471
+ export const Children: typeof Children
472
+ export const NavLink: typeof NavLink
473
+ export const Link: typeof Link
474
+ export const usePathname: typeof usePathname
475
+ export const useSearchParams: typeof useSearchParams
476
+ }
477
+
478
+ declare const Ryunix: {
479
+ createElement: typeof createElement
480
+ Fragment: typeof Fragment
481
+ cloneElement: typeof cloneElement
482
+ isValidElement: typeof isValidElement
483
+ render: typeof render
484
+ init: typeof init
485
+ safeRender: typeof safeRender
486
+ hydrate: typeof hydrate
487
+ renderToString: typeof renderToString
488
+ renderToReadableStream: typeof renderToReadableStream
489
+ escapeHtml: typeof escapeHtml
490
+ renderToStringAsync: typeof renderToStringAsync
491
+ useStore: typeof useStore
492
+ useReducer: typeof useReducer
493
+ useEffect: typeof useEffect
494
+ useLayoutEffect: typeof useLayoutEffect
495
+ useRef: typeof useRef
496
+ useMemo: typeof useMemo
497
+ useCallback: typeof useCallback
498
+ createContext: typeof createContext
499
+ useQuery: typeof useQuery
500
+ useHash: typeof useHash
501
+ useMetadata: typeof useMetadata
502
+ useId: typeof useId
503
+ resetIdCounter: typeof resetIdCounter
504
+ useDebounce: typeof useDebounce
505
+ useThrottle: typeof useThrottle
506
+ useStorePriority: typeof useStorePriority
507
+ useTransition: typeof useTransition
508
+ useDeferredValue: typeof useDeferredValue
509
+ usePersistentStore: typeof usePersistentStore
510
+ usePersitentStore: typeof usePersitentStore
511
+ useSwitch: typeof useSwitch
512
+ RouterProvider: typeof RouterProvider
513
+ useRouter: typeof useRouter
514
+ Children: typeof Children
515
+ NavLink: typeof NavLink
516
+ Link: typeof Link
517
+ usePathname: typeof usePathname
518
+ useSearchParams: typeof useSearchParams
519
+ Hooks: typeof Hooks
520
+ memo: typeof memo
521
+ shallowEqual: typeof shallowEqual
522
+ deepEqual: typeof deepEqual
523
+ lazy: typeof lazy
524
+ Suspense: typeof Suspense
525
+ preload: typeof preload
526
+ batchUpdates: typeof batchUpdates
527
+ Priority: typeof Priority
528
+ profiler: typeof profiler
529
+ useProfiler: typeof useProfiler
530
+ withProfiler: typeof withProfiler
531
+ forwardRef: typeof forwardRef
532
+ createPortal: typeof createPortal
533
+ ServerBoundary: typeof ServerBoundary
534
+ ErrorBoundary: typeof ErrorBoundary
535
+ getState: typeof getState
536
+ createActionProxy: typeof createActionProxy
537
+ RyunixDevOverlay: typeof RyunixDevOverlay
538
+ }
539
+
540
+ 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