@seip/bluebird-js 0.1.7 → 0.2.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.
Files changed (151) hide show
  1. package/AGENTS.md +727 -620
  2. package/README.md +670 -607
  3. package/app/models/user.js +19 -0
  4. package/app/resources/html/home.html +137 -0
  5. package/app/resources/html/layouts/main.html +55 -0
  6. package/app/resources/html/notFound.html +14 -0
  7. package/app/resources/html/table.html +15 -0
  8. package/app/resources/html/terms.html +46 -0
  9. package/app/resources/index.html +27 -0
  10. package/app/resources/layouts/AppLayout.jsx +92 -0
  11. package/app/resources/main.jsx +18 -0
  12. package/app/resources/pages/Dashboard.jsx +93 -0
  13. package/app/resources/pages/Home.jsx +140 -0
  14. package/app/resources/pages/Login.jsx +35 -0
  15. package/app/resources/pages/NotFound.jsx +16 -0
  16. package/app/resources/pages/Register.jsx +55 -0
  17. package/app/resources/pages/TableDemo.jsx +85 -0
  18. package/app/resources/routes.jsx +59 -0
  19. package/app/resources/spa.js +73 -0
  20. package/app/resources/styles.css +9 -0
  21. package/app/routes/api.js +129 -50
  22. package/app/routes/auth.js +209 -0
  23. package/app/routes/web.js +89 -47
  24. package/core/ai.js +30 -10
  25. package/core/app.d.ts +2 -18
  26. package/core/app.js +987 -801
  27. package/core/auth.d.ts +2 -13
  28. package/core/auth.js +444 -326
  29. package/core/cli/build.js +37 -0
  30. package/core/cli/dev.js +155 -0
  31. package/core/cli/doctor.js +37 -2
  32. package/core/cli/export.js +191 -0
  33. package/core/cli/init.js +91 -322
  34. package/core/cli/nginx.js +1 -1
  35. package/core/cli/templates.js +139 -0
  36. package/core/cli/view.js +98 -161
  37. package/core/config.js +44 -2
  38. package/core/csrf.js +156 -24
  39. package/core/database.js +1184 -1131
  40. package/core/debug.js +1 -1
  41. package/core/html.js +8 -1
  42. package/core/index.d.ts +126 -310
  43. package/core/paths.js +55 -0
  44. package/core/ratelimit.js +10 -1
  45. package/core/react/client/api.js +239 -0
  46. package/core/react/client/auth.js +236 -0
  47. package/core/react/client/components.js +1321 -0
  48. package/core/react/client/datatable.js +595 -0
  49. package/core/react/client/i18n.js +440 -0
  50. package/core/react/client/index.d.ts +314 -0
  51. package/core/react/client/index.js +50 -0
  52. package/core/react/client/router.js +26 -0
  53. package/core/react/client/theme.css +512 -0
  54. package/core/render-cache.js +250 -212
  55. package/core/render.d.ts +25 -21
  56. package/core/render.js +738 -736
  57. package/core/router.d.ts +2 -3
  58. package/core/router.js +171 -171
  59. package/core/seo.js +10 -0
  60. package/core/spa.js +599 -0
  61. package/core/view-loader.js +155 -613
  62. package/core/vite-plugin.d.ts +18 -0
  63. package/core/vite-plugin.js +162 -0
  64. package/core/vite.js +250 -145
  65. package/index.js +22 -18
  66. package/jsconfig.json +5 -3
  67. package/package.json +114 -92
  68. package/production.md +8 -3
  69. package/public/js/bluebird.js +1886 -0
  70. package/templates/_auth/app/database.js +19 -0
  71. package/templates/_auth/app/models/user.js +22 -0
  72. package/templates/_auth/app/routes/auth-router.js +304 -0
  73. package/templates/_base/app/resources/html/layouts/main.html +55 -0
  74. package/templates/_base/app/resources/html/notFound.html +14 -0
  75. package/templates/_base/app/resources/index.html +27 -0
  76. package/templates/_base/app/resources/styles.css +9 -0
  77. package/templates/api/app/models/note.js +18 -0
  78. package/templates/api/app/routes/api.js +82 -0
  79. package/templates/api/app/routes/auth.js +11 -0
  80. package/templates/api/index.js +19 -0
  81. package/templates/api/template.json +13 -0
  82. package/templates/auth/app/mail.js +11 -0
  83. package/templates/auth/app/models/password_reset.js +18 -0
  84. package/templates/auth/app/resources/html/home.html +21 -0
  85. package/templates/auth/app/resources/html/partials/nav.html +2 -0
  86. package/templates/auth/app/resources/layouts/AppLayout.jsx +60 -0
  87. package/templates/auth/app/resources/main.jsx +18 -0
  88. package/templates/auth/app/resources/pages/Dashboard.jsx +51 -0
  89. package/templates/auth/app/resources/pages/ForgotPassword.jsx +34 -0
  90. package/templates/auth/app/resources/pages/Login.jsx +36 -0
  91. package/templates/auth/app/resources/pages/NotFound.jsx +16 -0
  92. package/templates/auth/app/resources/pages/Profile.jsx +99 -0
  93. package/templates/auth/app/resources/pages/Register.jsx +50 -0
  94. package/templates/auth/app/resources/pages/ResetPassword.jsx +50 -0
  95. package/templates/auth/app/resources/routes.jsx +54 -0
  96. package/templates/auth/app/resources/spa.js +29 -0
  97. package/templates/auth/app/routes/api.js +17 -0
  98. package/templates/auth/app/routes/auth.js +13 -0
  99. package/templates/auth/app/routes/web.js +21 -0
  100. package/templates/auth/index.js +19 -0
  101. package/templates/auth/template.json +15 -0
  102. package/templates/blank/app/models/.gitkeep +0 -0
  103. package/templates/blank/app/resources/html/home.html +27 -0
  104. package/templates/blank/app/resources/html/partials/nav.html +1 -0
  105. package/templates/blank/app/resources/main.jsx +16 -0
  106. package/templates/blank/app/resources/pages/Home.jsx +42 -0
  107. package/templates/blank/app/resources/pages/NotFound.jsx +27 -0
  108. package/templates/blank/app/resources/routes.jsx +15 -0
  109. package/templates/blank/app/resources/spa.js +24 -0
  110. package/templates/blank/app/routes/api.js +11 -0
  111. package/templates/blank/app/routes/web.js +21 -0
  112. package/templates/blank/index.js +13 -0
  113. package/templates/blank/template.json +12 -0
  114. package/templates/blog/app/lib/blog.js +149 -0
  115. package/templates/blog/app/models/post.js +22 -0
  116. package/templates/blog/app/resources/html/home.html +28 -0
  117. package/templates/blog/app/resources/html/not-found.html +5 -0
  118. package/templates/blog/app/resources/html/partials/nav.html +2 -0
  119. package/templates/blog/app/resources/html/partials/post-card.html +9 -0
  120. package/templates/blog/app/resources/html/post.html +8 -0
  121. package/templates/blog/app/resources/layouts/AdminLayout.jsx +54 -0
  122. package/templates/blog/app/resources/main.jsx +18 -0
  123. package/templates/blog/app/resources/pages/Login.jsx +31 -0
  124. package/templates/blog/app/resources/pages/NotFound.jsx +16 -0
  125. package/templates/blog/app/resources/pages/PostEditor.jsx +51 -0
  126. package/templates/blog/app/resources/pages/Posts.jsx +83 -0
  127. package/templates/blog/app/resources/pages/Register.jsx +43 -0
  128. package/templates/blog/app/resources/routes.jsx +51 -0
  129. package/templates/blog/app/resources/spa.js +25 -0
  130. package/templates/blog/app/resources/styles.css +40 -0
  131. package/templates/blog/app/routes/api.js +77 -0
  132. package/templates/blog/app/routes/auth.js +10 -0
  133. package/templates/blog/app/routes/web.js +114 -0
  134. package/templates/blog/index.js +21 -0
  135. package/templates/blog/template.json +14 -0
  136. package/vite.config.js +11 -0
  137. package/app/views/components/Header.jsx +0 -42
  138. package/app/views/components/LiveCounter.jsx +0 -67
  139. package/app/views/layouts/main/view.jsx +0 -201
  140. package/app/views/legal/terms.html +0 -29
  141. package/app/views/pages/about.jsx +0 -98
  142. package/app/views/pages/dashboard.jsx +0 -278
  143. package/app/views/pages/index.jsx +0 -123
  144. package/app/views/pages/login.jsx +0 -141
  145. package/core/actions.d.ts +0 -4
  146. package/core/actions.js +0 -355
  147. package/core/jsx.d.ts +0 -38
  148. package/core/jsx.js +0 -1597
  149. package/core/vite.d.ts +0 -3
  150. package/public/js/bluebird-client.js +0 -3265
  151. package/public/js/tailwind.js +0 -8
@@ -0,0 +1,314 @@
1
+ import type {
2
+ AnchorHTMLAttributes,
3
+ ButtonHTMLAttributes,
4
+ ComponentType,
5
+ FormHTMLAttributes,
6
+ InputHTMLAttributes,
7
+ ReactNode,
8
+ SelectHTMLAttributes,
9
+ TextareaHTMLAttributes,
10
+ } from "react";
11
+
12
+ export function setApiBaseUrl(baseUrl: string): void;
13
+ export function getApiBaseUrl(): string;
14
+ export function getCsrfToken(): string;
15
+
16
+ export interface BluebirdExportConfig {
17
+ apiUrl?: string;
18
+ router?: "hash" | "browser" | "memory";
19
+ basename?: string;
20
+ auth?: "token" | "cookie";
21
+ }
22
+
23
+ export function getExportConfig(): BluebirdExportConfig | null;
24
+ export function isExported(): boolean;
25
+ export function configureApi(options?: { baseUrl?: string; auth?: "cookie" | "token" }): void;
26
+ export function getAuthMode(): "cookie" | "token";
27
+ export function getAuthToken(): string;
28
+ export function setAuthToken(token: string | null): void;
29
+
30
+ export function createRouter(
31
+ routes: import("react-router").RouteObject[],
32
+ options?: { basename?: string; mode?: "browser" | "hash" | "memory"; [key: string]: any }
33
+ ): ReturnType<typeof import("react-router").createBrowserRouter>;
34
+
35
+ export class ApiError extends Error {
36
+ status: number;
37
+ data: any;
38
+ errors: Record<string, string | string[]> | null;
39
+ }
40
+
41
+ export interface ApiRequestOptions {
42
+ method?: string;
43
+ body?: any;
44
+ headers?: Record<string, string>;
45
+ credentials?: RequestCredentials;
46
+ signal?: AbortSignal;
47
+ /** Return the whole JSON body (e.g. `{ data, pagination }` from `res.paginate`) instead of only `data`. */
48
+ raw?: boolean;
49
+ }
50
+
51
+ export interface ApiClient {
52
+ <T = any>(url: string, options?: ApiRequestOptions): Promise<T>;
53
+ get<T = any>(url: string, options?: Omit<ApiRequestOptions, "method" | "body">): Promise<T>;
54
+ post<T = any>(url: string, body?: any, options?: Omit<ApiRequestOptions, "method" | "body">): Promise<T>;
55
+ put<T = any>(url: string, body?: any, options?: Omit<ApiRequestOptions, "method" | "body">): Promise<T>;
56
+ patch<T = any>(url: string, body?: any, options?: Omit<ApiRequestOptions, "method" | "body">): Promise<T>;
57
+ delete<T = any>(url: string, options?: Omit<ApiRequestOptions, "method" | "body">): Promise<T>;
58
+ }
59
+
60
+ export const api: ApiClient;
61
+ export const request: ApiClient;
62
+
63
+ export interface AuthUser {
64
+ id: number | string;
65
+ name: string;
66
+ email: string;
67
+ role?: string;
68
+ roles?: string[];
69
+ [key: string]: any;
70
+ }
71
+
72
+ export interface AuthEndpoints {
73
+ me?: string;
74
+ login?: string;
75
+ register?: string;
76
+ logout?: string;
77
+ }
78
+
79
+ export interface AuthContextValue {
80
+ user: AuthUser | null;
81
+ loading: boolean;
82
+ authenticated: boolean;
83
+ registerEnabled: boolean;
84
+ login: (credentials: Record<string, any>) => Promise<AuthUser | null>;
85
+ register: (payload: Record<string, any>) => Promise<AuthUser | null>;
86
+ logout: () => Promise<void>;
87
+ refresh: (signal?: AbortSignal) => Promise<AuthUser | null>;
88
+ setUser: (user: AuthUser | null) => void;
89
+ hasRole: (roles?: string | string[] | null) => boolean;
90
+ }
91
+
92
+ export function matchUserRole(user: AuthUser | null | undefined, roles?: string | string[] | null): boolean;
93
+ export function AuthProvider(props: {
94
+ endpoints?: AuthEndpoints;
95
+ initialUser?: AuthUser | null;
96
+ children?: ReactNode;
97
+ }): ReactNode;
98
+ export function useAuth(): AuthContextValue;
99
+ export function RequireAuth(props?: {
100
+ roles?: string | string[];
101
+ redirectTo?: string;
102
+ forbiddenRedirect?: string;
103
+ fallback?: ReactNode;
104
+ forbidden?: ReactNode;
105
+ children?: ReactNode;
106
+ }): ReactNode;
107
+ export function GuestOnly(props?: {
108
+ redirectTo?: string;
109
+ fallback?: ReactNode;
110
+ children?: ReactNode;
111
+ }): ReactNode;
112
+
113
+ /** Built-in UI strings by language (`en`, `es`, `pt`, `fr`, `de`, `it`). */
114
+ export const MESSAGES: Record<string, Record<string, string>>;
115
+ /** Active UI locale: `setLocale()` override, then `<html lang>`, then the browser language. */
116
+ export function getLocale(): string;
117
+ /** Forces the UI locale for all components (`null` returns to `<html lang>` detection). */
118
+ export function setLocale(locale: string | null): void;
119
+ /** Adds or overrides UI strings for a language, e.g. `addMessages("es", { "toast.warning": "Atención" })`. */
120
+ export function addMessages(locale: string, messages: Record<string, string>): void;
121
+ /** Translates a UI string key, replacing `{name}` placeholders. */
122
+ export function t(key: string, params?: Record<string, string | number>, locale?: string): string;
123
+ /** Hook that re-renders when the locale or messages change. */
124
+ export function useLocale(): {
125
+ locale: string;
126
+ t: (key: string, params?: Record<string, string | number>) => string;
127
+ setLocale: (locale: string | null) => void;
128
+ };
129
+
130
+ export function cn(...parts: any[]): string;
131
+ export function useTheme(): {
132
+ theme: "dark" | "light";
133
+ isDark: boolean;
134
+ setTheme: (mode: "dark" | "light") => void;
135
+ toggleTheme: () => void;
136
+ };
137
+ export function ThemeToggle(props?: { className?: string }): ReactNode;
138
+
139
+ export interface LinkProps extends Omit<AnchorHTMLAttributes<HTMLAnchorElement>, "href"> {
140
+ href?: string;
141
+ to?: string;
142
+ activeClassName?: string;
143
+ inactiveClassName?: string;
144
+ exact?: boolean;
145
+ replace?: boolean;
146
+ }
147
+ export const Link: ComponentType<LinkProps>;
148
+
149
+ export type ButtonVariant = "primary" | "secondary" | "outline" | "ghost" | "danger" | "link";
150
+ export type ButtonSize = "sm" | "md" | "lg" | "icon";
151
+ /** Button classes (`btn btn-<variant> btn-<size>`) to style links or other elements like a Button. */
152
+ export function buttonVariants(options?: { variant?: ButtonVariant; size?: ButtonSize; className?: string }): string;
153
+
154
+ export interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
155
+ variant?: ButtonVariant;
156
+ size?: ButtonSize;
157
+ loading?: boolean;
158
+ loadingText?: ReactNode;
159
+ url?: string;
160
+ method?: string;
161
+ payload?: Record<string, any>;
162
+ confirm?: string;
163
+ onSuccess?: (data: any) => void;
164
+ onError?: (error: ApiError) => void;
165
+ }
166
+ export const Button: ComponentType<ButtonProps>;
167
+ export function SubmitButton(props: ButtonProps): ReactNode;
168
+ export function useFormState(): { errors: Record<string, string | string[]>; pending: boolean };
169
+
170
+ export interface FormProps extends Omit<FormHTMLAttributes<HTMLFormElement>, "action" | "onError"> {
171
+ url?: string;
172
+ method?: string;
173
+ data?: Record<string, any> | ((values: Record<string, any>) => Record<string, any>);
174
+ onSubmitRequest?: (values: Record<string, any> | FormData) => Promise<any>;
175
+ onBefore?: (values: Record<string, any>) => boolean | void;
176
+ onSuccess?: (data: any, values: Record<string, any>) => void;
177
+ onError?: (error: ApiError) => void;
178
+ resetOnSuccess?: boolean;
179
+ successMessage?: string;
180
+ }
181
+ export function Form(props: FormProps): ReactNode;
182
+
183
+ interface FieldProps {
184
+ label?: ReactNode;
185
+ hint?: ReactNode;
186
+ error?: string;
187
+ wrapperClassName?: string;
188
+ }
189
+ export const Input: ComponentType<InputHTMLAttributes<HTMLInputElement> & FieldProps>;
190
+ export const Textarea: ComponentType<TextareaHTMLAttributes<HTMLTextAreaElement> & FieldProps>;
191
+ export const Select: ComponentType<SelectHTMLAttributes<HTMLSelectElement> & FieldProps>;
192
+
193
+ export function Card(props: {
194
+ title?: ReactNode;
195
+ description?: ReactNode;
196
+ footer?: ReactNode;
197
+ variant?: "default" | "glass";
198
+ className?: string;
199
+ children?: ReactNode;
200
+ }): ReactNode;
201
+ export function Badge(props: {
202
+ tone?: "default" | "info" | "success" | "warning" | "danger" | "error";
203
+ soft?: boolean;
204
+ className?: string;
205
+ children?: ReactNode;
206
+ }): ReactNode;
207
+ export function Carousel(props: {
208
+ slides: Array<{ title?: ReactNode; description?: ReactNode; badge?: ReactNode; content?: ReactNode }>;
209
+ autoPlayMs?: number;
210
+ loop?: boolean;
211
+ label?: string;
212
+ className?: string;
213
+ }): ReactNode;
214
+ export function Modal(props: {
215
+ open: boolean;
216
+ onClose: () => void;
217
+ title?: ReactNode;
218
+ description?: ReactNode;
219
+ footer?: ReactNode;
220
+ size?: "sm" | "md" | "lg" | "xl";
221
+ className?: string;
222
+ children?: ReactNode;
223
+ }): ReactNode;
224
+ export function Drawer(props: {
225
+ open: boolean;
226
+ onClose: () => void;
227
+ side?: "left" | "right" | "top" | "bottom";
228
+ title?: ReactNode;
229
+ className?: string;
230
+ children?: ReactNode;
231
+ }): ReactNode;
232
+ export interface DataTableColumn<T = any> {
233
+ key: string;
234
+ label: ReactNode;
235
+ sortable?: boolean;
236
+ /** Include in the search (default true). */
237
+ searchable?: boolean;
238
+ /** Card title on narrow screens (defaults to the first column). */
239
+ primary?: boolean;
240
+ /** `false` hides it on cards, `"details"` moves it behind "Show details". */
241
+ mobile?: boolean | "details";
242
+ align?: "left" | "right" | "center";
243
+ /** Right-aligned monospace tabular numbers. */
244
+ numeric?: boolean;
245
+ render?: (row: T, index: number) => ReactNode;
246
+ /** Raw value for search and sorting when it differs from `row[key]`. */
247
+ value?: (row: T) => any;
248
+ className?: string;
249
+ }
250
+
251
+ export interface DataTableAction<T = any> {
252
+ key?: string;
253
+ label: string;
254
+ /** Icon-only button when set; text button otherwise. */
255
+ icon?: ReactNode;
256
+ onClick?: (row: T) => any;
257
+ /** Link pattern (`"/users/:id"`) or builder. */
258
+ href?: string | ((row: T) => string);
259
+ variant?: "default" | "danger";
260
+ /** Ask in a dialog first (`true` or custom text). */
261
+ confirm?: boolean | string;
262
+ hidden?: (row: T) => boolean;
263
+ }
264
+
265
+ export interface DataTableProps<T = any> {
266
+ rows?: T[];
267
+ /** Server endpoint returning `res.paginate()` or `Model.paginate()` results; receives `?page&limit&search&sort&order`. */
268
+ url?: string;
269
+ params?: Record<string, any>;
270
+ columns: DataTableColumn<T>[];
271
+ searchable?: boolean;
272
+ searchPlaceholder?: string;
273
+ pageSize?: number;
274
+ pageSizes?: number[];
275
+ defaultSort?: { key: string; dir?: "asc" | "desc" };
276
+ onView?: ((row: T) => any) | string;
277
+ onEdit?: ((row: T) => any) | string;
278
+ onDelete?: (row: T) => any;
279
+ deleteConfirm?: boolean | string;
280
+ actions?: DataTableAction<T>[];
281
+ onRowClick?: (row: T) => void;
282
+ rowKey?: (row: T, index: number) => string | number;
283
+ loading?: boolean;
284
+ empty?: ReactNode;
285
+ toolbar?: ReactNode;
286
+ caption?: string;
287
+ className?: string;
288
+ ref?: import("react").Ref<{ reload: () => void }>;
289
+ }
290
+
291
+ /** Responsive data table: search, sort, pagination, row actions with delete confirmation, cards on narrow screens, local or server data. */
292
+ export function DataTable<T = any>(props: DataTableProps<T>): ReactNode;
293
+ export function normalizeTableResponse(body: any): { rows: any[]; total: number };
294
+
295
+ export function Skeleton(props?: { className?: string; style?: Record<string, any> }): ReactNode;
296
+ export function PageSkeleton(): ReactNode;
297
+ export function ProgressBar(props?: { active?: boolean }): ReactNode;
298
+ export function Spinner(props?: { className?: string }): ReactNode;
299
+ export function Toaster(): ReactNode;
300
+
301
+ export interface ToastOptions {
302
+ title?: string;
303
+ description?: string;
304
+ badge?: string;
305
+ type?: "info" | "success" | "error" | "warning";
306
+ duration?: number;
307
+ }
308
+ export const toast: ((input: string | ToastOptions) => number) & {
309
+ success(title: string, description?: string): number;
310
+ error(title: string, description?: string): number;
311
+ info(title: string, description?: string): number;
312
+ warning(title: string, description?: string): number;
313
+ };
314
+ export function dismissToast(id: number): void;
@@ -0,0 +1,50 @@
1
+ export {
2
+ ApiError,
3
+ api,
4
+ configureApi,
5
+ getApiBaseUrl,
6
+ getAuthMode,
7
+ getAuthToken,
8
+ getCsrfToken,
9
+ getExportConfig,
10
+ isExported,
11
+ request,
12
+ setApiBaseUrl,
13
+ setAuthToken,
14
+ } from "./api.js";
15
+ export { createRouter } from "./router.js";
16
+ export { DataTable, normalizeTableResponse } from "./datatable.js";
17
+ export { MESSAGES, addMessages, getLocale, setLocale, t, useLocale } from "./i18n.js";
18
+ export {
19
+ AuthProvider,
20
+ GuestOnly,
21
+ RequireAuth,
22
+ matchUserRole,
23
+ useAuth,
24
+ } from "./auth.js";
25
+ export {
26
+ Badge,
27
+ Button,
28
+ buttonVariants,
29
+ Card,
30
+ Carousel,
31
+ Drawer,
32
+ Form,
33
+ Input,
34
+ Link,
35
+ Modal,
36
+ PageSkeleton,
37
+ ProgressBar,
38
+ Select,
39
+ Skeleton,
40
+ Spinner,
41
+ SubmitButton,
42
+ Textarea,
43
+ ThemeToggle,
44
+ Toaster,
45
+ cn,
46
+ dismissToast,
47
+ toast,
48
+ useFormState,
49
+ useTheme,
50
+ } from "./components.js";
@@ -0,0 +1,26 @@
1
+ import { createBrowserRouter, createHashRouter, createMemoryRouter } from "react-router";
2
+ import { getExportConfig } from "./api.js";
3
+
4
+ /**
5
+ * Creates a React Router data router that works on the Bluebird server and in static exports.
6
+ * - Served by `router.spa()`: `createBrowserRouter` with `basename` (e.g. `"/app"`).
7
+ * - Static export (`npx bluebird-js export`) or `file://` (Electron `loadFile`): `createHashRouter`.
8
+ * - `mode` forces `"browser"`, `"hash"`, or `"memory"`.
9
+ * @param {import('react-router').RouteObject[]} routes
10
+ * @param {Object} [options={}]
11
+ * @param {string} [options.basename] - Mount path on the server (ignored by hash and memory routers).
12
+ * @param {"browser"|"hash"|"memory"} [options.mode]
13
+ * @returns {ReturnType<typeof createBrowserRouter>}
14
+ */
15
+ export function createRouter(routes, options = {}) {
16
+ const { mode: requested, basename, ...rest } = options;
17
+ const exported = getExportConfig();
18
+ const isFileProtocol = typeof window !== "undefined" && window.location?.protocol === "file:";
19
+ const mode = requested || exported?.router || (isFileProtocol ? "hash" : "browser");
20
+
21
+ if (mode === "hash") return createHashRouter(routes, rest);
22
+ if (mode === "memory") return createMemoryRouter(routes, rest);
23
+
24
+ const base = exported ? exported.basename || "/" : basename;
25
+ return createBrowserRouter(routes, base && base !== "/" ? { ...rest, basename: base } : rest);
26
+ }