@float.js/core 2.0.1

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,400 @@
1
+ import { FloatRoute as Route } from './router/index.js';
2
+ export { FloatRouterOptions, matchRoute, scanRoutes } from './router/index.js';
3
+ export { DevServer, DevServerOptions, PageProps, ProdServerOptions, RenderOptions, createDevServer, renderPage, renderPageStream, startProductionServer } from './server/index.js';
4
+ import * as esbuild from 'esbuild';
5
+ export { ComponentType, FC, ReactElement, ReactNode } from 'react';
6
+ export { AIProvider, AIResponse, AnthropicProvider, ChatOptions, Message, OpenAIProvider, ai, aiAction, sseResponse, streamResponse } from './ai/index.js';
7
+ export { FloatValidationError, Infer, error, f, json, redirect, typedRoute } from './api/index.js';
8
+ export { FloatRealtime, PresenceState, RealtimeClient, RealtimeMessage, RealtimeOptions, RealtimeRoom, createRealtimeClient, getRealtimeServer, realtime } from './realtime/index.js';
9
+ export { BuildInfo, DevDashboardOptions, PerformanceMetrics, RequestLog, RouteInfo, createDevDashboard, createRequestLogger, dashboardState, devtools } from './devtools/index.js';
10
+ export { ImageConfig, ImageProps, OptimizedImage, StaticImageData, configureImages, createImageHandler, floatImageLoader, generateSrcSet, getImageConfig, getImageProps, image, renderImageToString } from './image/index.js';
11
+ export { GeoData, MiddlewareConfig, MiddlewareHandler, MiddlewareRequest, NextResponse, NextURL, clearMiddleware, createMiddlewareHandler, middleware, middlewareHelpers, registerMiddleware } from './middleware/index.js';
12
+ export { CachedPage, GenerateResult, GetStaticPathsResult, GetStaticPropsContext, GetStaticPropsResult, SSGConfig, SSGEngine, StaticPath, configureSSG, createRevalidateHandler, createSSGHandler, defineStaticPaths, defineStaticProps, getSSGEngine, default as ssg } from './ssg/index.js';
13
+ export { AnalyticsConfig, AnalyticsData, AnalyticsEngine, AnalyticsSummary, CustomEvent, PageView, WebVitals, default as analytics, analyticsClientScript, configureAnalytics, createAnalyticsHandler, createAnalyticsMiddleware, getAnalytics } from './analytics/index.js';
14
+ import 'ws';
15
+ import 'http';
16
+ import 'events';
17
+
18
+ declare const VERSION = "2.0.1";
19
+
20
+ /**
21
+ * Float.js Build System
22
+ * Fast builds with esbuild
23
+ */
24
+
25
+ interface BuildOptions {
26
+ analyze?: boolean;
27
+ minify?: boolean;
28
+ sourcemap?: boolean;
29
+ }
30
+ interface BuildResult {
31
+ routes: Route[];
32
+ duration: number;
33
+ outputDir: string;
34
+ pages: string[];
35
+ assets: string[];
36
+ }
37
+ declare function build(options?: BuildOptions): Promise<BuildResult>;
38
+
39
+ /**
40
+ * Float.js Transform
41
+ * On-the-fly TypeScript/JSX transformation
42
+ */
43
+
44
+ /**
45
+ * Transform and import a file
46
+ * Handles .ts, .tsx, .js, .jsx files
47
+ */
48
+ declare function transformFile(filePath: string): Promise<any>;
49
+ /**
50
+ * Clear module cache (for HMR)
51
+ */
52
+ declare function clearModuleCache(filePath?: string): void;
53
+ /**
54
+ * Transform source code without file operations
55
+ */
56
+ declare function transformSource(source: string, options?: {
57
+ filename?: string;
58
+ loader?: esbuild.Loader;
59
+ }): Promise<string>;
60
+
61
+ /**
62
+ * Float.js Router Hook
63
+ * Modern client-side routing utilities
64
+ */
65
+ interface FloatRouterState {
66
+ pathname: string;
67
+ search: string;
68
+ hash: string;
69
+ params: Record<string, string>;
70
+ query: Record<string, string>;
71
+ }
72
+ interface FloatRouter extends FloatRouterState {
73
+ push: (url: string, options?: NavigateOptions) => void;
74
+ replace: (url: string, options?: NavigateOptions) => void;
75
+ back: () => void;
76
+ forward: () => void;
77
+ prefetch: (url: string) => void;
78
+ refresh: () => void;
79
+ }
80
+ interface NavigateOptions {
81
+ scroll?: boolean;
82
+ shallow?: boolean;
83
+ }
84
+ /**
85
+ * Access Float.js router for client-side navigation
86
+ * @example
87
+ * const router = useFloatRouter();
88
+ * router.push('/dashboard');
89
+ */
90
+ declare function useFloatRouter(): FloatRouter;
91
+
92
+ /**
93
+ * Float.js Data Hook
94
+ * SWR-like data fetching with caching
95
+ */
96
+ interface FloatDataOptions<T> {
97
+ /** Initial data before fetching */
98
+ fallbackData?: T;
99
+ /** Revalidate on window focus */
100
+ revalidateOnFocus?: boolean;
101
+ /** Revalidate on network reconnect */
102
+ revalidateOnReconnect?: boolean;
103
+ /** Refresh interval in milliseconds */
104
+ refreshInterval?: number;
105
+ /** Dedupe requests within this time window (ms) */
106
+ dedupingInterval?: number;
107
+ /** Keep previous data when revalidating */
108
+ keepPreviousData?: boolean;
109
+ /** Custom fetcher function */
110
+ fetcher?: (url: string) => Promise<T>;
111
+ }
112
+ interface FloatDataResult<T> {
113
+ data: T | undefined;
114
+ error: Error | undefined;
115
+ isLoading: boolean;
116
+ isValidating: boolean;
117
+ mutate: (data?: T | Promise<T> | ((current?: T) => T | Promise<T>)) => Promise<T | undefined>;
118
+ refresh: () => Promise<void>;
119
+ }
120
+ /**
121
+ * Fetch and cache data with automatic revalidation
122
+ * @example
123
+ * const { data, error, isLoading } = useFloatData('/api/users');
124
+ */
125
+ declare function useFloatData<T = any>(key: string | null, options?: FloatDataOptions<T>): FloatDataResult<T>;
126
+
127
+ /**
128
+ * Float.js Form Hook
129
+ * Modern form handling with validation
130
+ */
131
+ type ValidationRule<T> = (value: T, formData: Record<string, any>) => string | undefined | Promise<string | undefined>;
132
+ interface FieldState<T = any> {
133
+ value: T;
134
+ error: string | undefined;
135
+ touched: boolean;
136
+ dirty: boolean;
137
+ }
138
+ interface FloatFormOptions<T extends Record<string, any>> {
139
+ initialValues?: Partial<T>;
140
+ onSubmit: (values: T) => void | Promise<void>;
141
+ onError?: (errors: Record<keyof T, string | undefined>) => void;
142
+ validateOnChange?: boolean;
143
+ validateOnBlur?: boolean;
144
+ }
145
+ interface FloatFormResult<T extends Record<string, any>> {
146
+ values: T;
147
+ errors: Partial<Record<keyof T, string>>;
148
+ touched: Partial<Record<keyof T, boolean>>;
149
+ isSubmitting: boolean;
150
+ isValid: boolean;
151
+ isDirty: boolean;
152
+ register: (name: keyof T) => {
153
+ value: any;
154
+ onChange: (e: React.ChangeEvent<any>) => void;
155
+ onBlur: (e: React.FocusEvent<any>) => void;
156
+ name: string;
157
+ };
158
+ setValue: (name: keyof T, value: any) => void;
159
+ setError: (name: keyof T, error: string | undefined) => void;
160
+ setTouched: (name: keyof T, touched?: boolean) => void;
161
+ reset: (values?: Partial<T>) => void;
162
+ handleSubmit: (e?: React.FormEvent) => Promise<void>;
163
+ validate: () => Promise<boolean>;
164
+ getFieldProps: (name: keyof T) => FieldState;
165
+ }
166
+ /**
167
+ * Powerful form handling with validation
168
+ * @example
169
+ * const form = useFloatForm({
170
+ * initialValues: { email: '', password: '' },
171
+ * onSubmit: async (values) => await login(values)
172
+ * });
173
+ */
174
+ declare function useFloatForm<T extends Record<string, any>>(options: FloatFormOptions<T>): FloatFormResult<T>;
175
+ declare const validators: {
176
+ required: (message?: string) => ValidationRule<any>;
177
+ email: (message?: string) => ValidationRule<string>;
178
+ minLength: (min: number, message?: string) => ValidationRule<string>;
179
+ maxLength: (max: number, message?: string) => ValidationRule<string>;
180
+ pattern: (regex: RegExp, message?: string) => ValidationRule<string>;
181
+ match: (field: string, message?: string) => ValidationRule<any>;
182
+ };
183
+
184
+ /**
185
+ * Float.js Async Hook
186
+ * Handle async operations with loading and error states
187
+ */
188
+ interface AsyncState<T> {
189
+ data: T | undefined;
190
+ error: Error | undefined;
191
+ isLoading: boolean;
192
+ isSuccess: boolean;
193
+ isError: boolean;
194
+ isIdle: boolean;
195
+ }
196
+ interface FloatAsyncResult<T, Args extends any[]> extends AsyncState<T> {
197
+ execute: (...args: Args) => Promise<T | undefined>;
198
+ reset: () => void;
199
+ setData: (data: T) => void;
200
+ }
201
+ interface FloatAsyncOptions<T> {
202
+ /** Initial data */
203
+ initialData?: T;
204
+ /** Execute immediately on mount */
205
+ immediate?: boolean;
206
+ /** Retry count on error */
207
+ retryCount?: number;
208
+ /** Delay between retries (ms) */
209
+ retryDelay?: number;
210
+ /** Callback on success */
211
+ onSuccess?: (data: T) => void;
212
+ /** Callback on error */
213
+ onError?: (error: Error) => void;
214
+ /** Callback on settle (success or error) */
215
+ onSettled?: (data: T | undefined, error: Error | undefined) => void;
216
+ }
217
+ /**
218
+ * Execute async functions with loading/error states
219
+ * @example
220
+ * const { data, isLoading, execute } = useFloatAsync(
221
+ * async (id) => await fetchUser(id),
222
+ * { immediate: false }
223
+ * );
224
+ */
225
+ declare function useFloatAsync<T, Args extends any[] = []>(asyncFn: (...args: Args) => Promise<T>, options?: FloatAsyncOptions<T>): FloatAsyncResult<T, Args>;
226
+ /**
227
+ * Debounced async execution
228
+ */
229
+ declare function useFloatDebounce<T, Args extends any[]>(asyncFn: (...args: Args) => Promise<T>, delay?: number, options?: FloatAsyncOptions<T>): FloatAsyncResult<T, Args>;
230
+ /**
231
+ * Throttled async execution
232
+ */
233
+ declare function useFloatThrottle<T, Args extends any[]>(asyncFn: (...args: Args) => Promise<T>, limit?: number, options?: FloatAsyncOptions<T>): FloatAsyncResult<T, Args>;
234
+
235
+ /**
236
+ * Float.js Store Hook
237
+ * Lightweight global state management (like Zustand but simpler)
238
+ */
239
+ type SetState<T> = (partial: Partial<T> | ((state: T) => Partial<T>)) => void;
240
+ type GetState<T> = () => T;
241
+ type Subscribe = (listener: () => void) => () => void;
242
+ type Selector<T, U> = (state: T) => U;
243
+ interface FloatStore<T> {
244
+ getState: GetState<T>;
245
+ setState: SetState<T>;
246
+ subscribe: Subscribe;
247
+ reset: () => void;
248
+ }
249
+ interface FloatStoreOptions<T> {
250
+ /** Persist state to localStorage */
251
+ persist?: string;
252
+ /** Custom equality function */
253
+ equals?: (a: any, b: any) => boolean;
254
+ /** Middleware */
255
+ middleware?: (set: SetState<T>, get: GetState<T>) => SetState<T>;
256
+ }
257
+ /**
258
+ * Create a global store
259
+ * @example
260
+ * const useStore = createFloatStore({ count: 0 });
261
+ *
262
+ * // In component
263
+ * const count = useStore(state => state.count);
264
+ */
265
+ declare function createFloatStore<T extends object>(initialState: T | (() => T), options?: FloatStoreOptions<T>): {
266
+ (): T;
267
+ <U>(selector: Selector<T, U>): U;
268
+ getState: GetState<T>;
269
+ setState: SetState<T>;
270
+ subscribe: Subscribe;
271
+ reset: () => void;
272
+ };
273
+ /**
274
+ * Use a selector on an existing store
275
+ */
276
+ declare function useFloatStore<T, U>(store: FloatStore<T>, selector: Selector<T, U>): U;
277
+ declare const floatMiddleware: {
278
+ /**
279
+ * Log all state changes
280
+ */
281
+ logger: <T>(name?: string) => (set: SetState<T>, get: GetState<T>) => SetState<T>;
282
+ /**
283
+ * Add undo/redo capability
284
+ */
285
+ undoable: <T>(maxHistory?: number) => (set: SetState<T>, get: GetState<T>) => SetState<T>;
286
+ /**
287
+ * Debounce state updates
288
+ */
289
+ debounce: <T>(delay: number) => (set: SetState<T>, _get: GetState<T>) => SetState<T>;
290
+ };
291
+ /**
292
+ * Combine multiple stores
293
+ */
294
+ declare function combineFloatStores<T extends Record<string, FloatStore<any>>>(stores: T): FloatStore<{
295
+ [K in keyof T]: ReturnType<T[K]['getState']>;
296
+ }>;
297
+
298
+ /**
299
+ * Float.js Welcome Page
300
+ * Shown when users first install the framework
301
+ */
302
+ declare function generateWelcomePage(): string;
303
+
304
+ /**
305
+ * Float.js - Ultra Modern Web Framework
306
+ *
307
+ * @packageDocumentation
308
+ */
309
+
310
+ interface FloatConfig {
311
+ /** App directory (default: 'app') */
312
+ appDir?: string;
313
+ /** Base path for all routes */
314
+ basePath?: string;
315
+ /** Enable React strict mode */
316
+ reactStrictMode?: boolean;
317
+ /** Internationalization config */
318
+ i18n?: {
319
+ locales: string[];
320
+ defaultLocale: string;
321
+ };
322
+ /** Custom headers */
323
+ headers?: () => Promise<Array<{
324
+ source: string;
325
+ headers: Array<{
326
+ key: string;
327
+ value: string;
328
+ }>;
329
+ }>>;
330
+ /** Redirects */
331
+ redirects?: () => Promise<Array<{
332
+ source: string;
333
+ destination: string;
334
+ permanent: boolean;
335
+ }>>;
336
+ /** Environment variables to expose to client */
337
+ env?: Record<string, string>;
338
+ /** Experimental features */
339
+ experimental?: {
340
+ serverActions?: boolean;
341
+ ppr?: boolean;
342
+ };
343
+ }
344
+ interface Metadata {
345
+ title?: string | {
346
+ default: string;
347
+ template?: string;
348
+ };
349
+ description?: string;
350
+ keywords?: string[];
351
+ authors?: Array<{
352
+ name: string;
353
+ url?: string;
354
+ }>;
355
+ creator?: string;
356
+ publisher?: string;
357
+ robots?: string | {
358
+ index?: boolean;
359
+ follow?: boolean;
360
+ googleBot?: {
361
+ index?: boolean;
362
+ follow?: boolean;
363
+ };
364
+ };
365
+ openGraph?: {
366
+ title?: string;
367
+ description?: string;
368
+ url?: string;
369
+ siteName?: string;
370
+ images?: Array<{
371
+ url: string;
372
+ width?: number;
373
+ height?: number;
374
+ alt?: string;
375
+ }>;
376
+ locale?: string;
377
+ type?: 'website' | 'article' | 'book' | 'profile';
378
+ };
379
+ twitter?: {
380
+ card?: 'summary' | 'summary_large_image' | 'app' | 'player';
381
+ title?: string;
382
+ description?: string;
383
+ images?: string[];
384
+ creator?: string;
385
+ };
386
+ icons?: {
387
+ icon?: string | Array<{
388
+ url: string;
389
+ sizes?: string;
390
+ }>;
391
+ apple?: string | Array<{
392
+ url: string;
393
+ sizes?: string;
394
+ }>;
395
+ };
396
+ manifest?: string;
397
+ canonical?: string;
398
+ }
399
+
400
+ export { type BuildOptions, type BuildResult, type FloatConfig, Route as FloatRoute, type Metadata, VERSION, build, clearModuleCache, combineFloatStores, createFloatStore, floatMiddleware, generateWelcomePage, transformFile, transformSource, useFloatAsync, useFloatData, useFloatDebounce, useFloatForm, useFloatRouter, useFloatStore, useFloatThrottle, validators };