@fluixi/core 1.0.0-alpha.100

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 (253) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +334 -0
  3. package/dist/cdn/core.global.js +2 -0
  4. package/dist/cli/generate.cjs +5639 -0
  5. package/dist/cli/generate.d.ts +7 -0
  6. package/dist/cli/generate.d.ts.map +1 -0
  7. package/dist/cli/generate.js +2580 -0
  8. package/dist/cli/generate.mjs +5644 -0
  9. package/dist/cli/index.cjs +5639 -0
  10. package/dist/cli/index.d.ts +7 -0
  11. package/dist/cli/index.d.ts.map +1 -0
  12. package/dist/cli/index.js +2580 -0
  13. package/dist/cli/index.mjs +5644 -0
  14. package/dist/cli/run.cjs +64 -0
  15. package/dist/cli/run.d.ts +3 -0
  16. package/dist/cli/run.d.ts.map +1 -0
  17. package/dist/cli/run.js +62 -0
  18. package/dist/cli/run.mjs +40 -0
  19. package/dist/fluixi.d.ts +5 -0
  20. package/dist/src/cdn/chunk-RKBFEFZP.mjs +987 -0
  21. package/dist/src/cdn/core.cjs +1592 -0
  22. package/dist/src/cdn/core.d.ts +16 -0
  23. package/dist/src/cdn/core.d.ts.map +1 -0
  24. package/dist/src/cdn/core.js +15 -0
  25. package/dist/src/cdn/core.mjs +714 -0
  26. package/dist/src/cdn/router-V2THK27H.mjs +74 -0
  27. package/dist/src/index.cjs +1711 -0
  28. package/dist/src/index.d.ts +4 -0
  29. package/dist/src/index.d.ts.map +1 -0
  30. package/dist/src/index.js +11 -0
  31. package/dist/src/index.mjs +1833 -0
  32. package/dist/src/jsx-dev-runtime.cjs +26 -0
  33. package/dist/src/jsx-dev-runtime.d.ts +2 -0
  34. package/dist/src/jsx-dev-runtime.d.ts.map +1 -0
  35. package/dist/src/jsx-dev-runtime.js +1 -0
  36. package/dist/src/jsx-dev-runtime.mjs +24 -0
  37. package/dist/src/jsx-runtime.cjs +26 -0
  38. package/dist/src/jsx-runtime.d.ts +7 -0
  39. package/dist/src/jsx-runtime.d.ts.map +1 -0
  40. package/dist/src/jsx-runtime.js +8 -0
  41. package/dist/src/jsx-runtime.mjs +24 -0
  42. package/dist/src/lib/client/chunk-FDOPDB6Z.mjs +53 -0
  43. package/dist/src/lib/client/index.cjs +1210 -0
  44. package/dist/src/lib/client/index.d.ts +51 -0
  45. package/dist/src/lib/client/index.d.ts.map +1 -0
  46. package/dist/src/lib/client/index.js +174 -0
  47. package/dist/src/lib/client/index.mjs +293 -0
  48. package/dist/src/lib/client/router-4PTBPZLQ.mjs +891 -0
  49. package/dist/src/lib/context/context.cjs +81 -0
  50. package/dist/src/lib/context/context.d.ts +73 -0
  51. package/dist/src/lib/context/context.d.ts.map +1 -0
  52. package/dist/src/lib/context/context.js +93 -0
  53. package/dist/src/lib/context/context.mjs +64 -0
  54. package/dist/src/lib/context/index.cjs +83 -0
  55. package/dist/src/lib/context/index.d.ts +3 -0
  56. package/dist/src/lib/context/index.d.ts.map +1 -0
  57. package/dist/src/lib/context/index.js +1 -0
  58. package/dist/src/lib/context/index.mjs +64 -0
  59. package/dist/src/lib/control-flow.cjs +35 -0
  60. package/dist/src/lib/control-flow.d.ts +4 -0
  61. package/dist/src/lib/control-flow.d.ts.map +1 -0
  62. package/dist/src/lib/control-flow.js +1 -0
  63. package/dist/src/lib/control-flow.mjs +25 -0
  64. package/dist/src/lib/core.cjs +1710 -0
  65. package/dist/src/lib/core.d.ts +91 -0
  66. package/dist/src/lib/core.d.ts.map +1 -0
  67. package/dist/src/lib/core.js +158 -0
  68. package/dist/src/lib/core.mjs +1833 -0
  69. package/dist/src/lib/env/index.cjs +44 -0
  70. package/dist/src/lib/env/index.d.ts +26 -0
  71. package/dist/src/lib/env/index.d.ts.map +1 -0
  72. package/dist/src/lib/env/index.js +31 -0
  73. package/dist/src/lib/env/index.mjs +23 -0
  74. package/dist/src/lib/i18n/index.cjs +123 -0
  75. package/dist/src/lib/i18n/index.d.ts +110 -0
  76. package/dist/src/lib/i18n/index.d.ts.map +1 -0
  77. package/dist/src/lib/i18n/index.js +164 -0
  78. package/dist/src/lib/i18n/index.mjs +103 -0
  79. package/dist/src/lib/index.cjs +598 -0
  80. package/dist/src/lib/index.d.ts +81 -0
  81. package/dist/src/lib/index.d.ts.map +1 -0
  82. package/dist/src/lib/index.js +130 -0
  83. package/dist/src/lib/index.mjs +688 -0
  84. package/dist/src/lib/isomorphic.cjs +90 -0
  85. package/dist/src/lib/isomorphic.d.ts +114 -0
  86. package/dist/src/lib/isomorphic.d.ts.map +1 -0
  87. package/dist/src/lib/isomorphic.js +132 -0
  88. package/dist/src/lib/isomorphic.mjs +69 -0
  89. package/dist/src/lib/jsx-runtime/index.cjs +21 -0
  90. package/dist/src/lib/jsx-runtime/index.d.ts +13 -0
  91. package/dist/src/lib/jsx-runtime/index.d.ts.map +1 -0
  92. package/dist/src/lib/jsx-runtime/index.js +13 -0
  93. package/dist/src/lib/jsx-runtime/index.mjs +4 -0
  94. package/dist/src/lib/jsx-runtime/jsx-dev-runtime.cjs +21 -0
  95. package/dist/src/lib/jsx-runtime/jsx-dev-runtime.d.ts +2 -0
  96. package/dist/src/lib/jsx-runtime/jsx-dev-runtime.d.ts.map +1 -0
  97. package/dist/src/lib/jsx-runtime/jsx-dev-runtime.js +1 -0
  98. package/dist/src/lib/jsx-runtime/jsx-dev-runtime.mjs +4 -0
  99. package/dist/src/lib/plugins/fluixi-routes-plugin.cjs +302 -0
  100. package/dist/src/lib/plugins/fluixi-routes-plugin.d.ts +35 -0
  101. package/dist/src/lib/plugins/fluixi-routes-plugin.d.ts.map +1 -0
  102. package/dist/src/lib/plugins/fluixi-routes-plugin.js +118 -0
  103. package/dist/src/lib/plugins/fluixi-routes-plugin.mjs +271 -0
  104. package/dist/src/lib/plugins/index.cjs +311 -0
  105. package/dist/src/lib/plugins/index.d.ts +6 -0
  106. package/dist/src/lib/plugins/index.d.ts.map +1 -0
  107. package/dist/src/lib/plugins/index.js +7 -0
  108. package/dist/src/lib/plugins/index.mjs +279 -0
  109. package/dist/src/lib/plugins/route-codegen.cjs +73 -0
  110. package/dist/src/lib/plugins/route-codegen.d.ts +12 -0
  111. package/dist/src/lib/plugins/route-codegen.d.ts.map +1 -0
  112. package/dist/src/lib/plugins/route-codegen.js +80 -0
  113. package/dist/src/lib/plugins/route-codegen.mjs +52 -0
  114. package/dist/src/lib/plugins/route-scanner.cjs +189 -0
  115. package/dist/src/lib/plugins/route-scanner.d.ts +38 -0
  116. package/dist/src/lib/plugins/route-scanner.d.ts.map +1 -0
  117. package/dist/src/lib/plugins/route-scanner.js +215 -0
  118. package/dist/src/lib/plugins/route-scanner.mjs +158 -0
  119. package/dist/src/lib/plugins/vite.cjs +27 -0
  120. package/dist/src/lib/plugins/vite.d.ts +3 -0
  121. package/dist/src/lib/plugins/vite.d.ts.map +1 -0
  122. package/dist/src/lib/plugins/vite.js +1 -0
  123. package/dist/src/lib/plugins/vite.mjs +6 -0
  124. package/dist/src/lib/render/await.cjs +38 -0
  125. package/dist/src/lib/render/await.d.ts +26 -0
  126. package/dist/src/lib/render/await.d.ts.map +1 -0
  127. package/dist/src/lib/render/await.js +45 -0
  128. package/dist/src/lib/render/await.mjs +17 -0
  129. package/dist/src/lib/render/component.cjs +221 -0
  130. package/dist/src/lib/render/component.d.ts +296 -0
  131. package/dist/src/lib/render/component.d.ts.map +1 -0
  132. package/dist/src/lib/render/component.js +514 -0
  133. package/dist/src/lib/render/component.mjs +214 -0
  134. package/dist/src/lib/render/deferred.cjs +175 -0
  135. package/dist/src/lib/render/deferred.d.ts +36 -0
  136. package/dist/src/lib/render/deferred.d.ts.map +1 -0
  137. package/dist/src/lib/render/deferred.js +141 -0
  138. package/dist/src/lib/render/deferred.mjs +158 -0
  139. package/dist/src/lib/render/index.cjs +573 -0
  140. package/dist/src/lib/render/index.d.ts +98 -0
  141. package/dist/src/lib/render/index.d.ts.map +1 -0
  142. package/dist/src/lib/render/index.js +180 -0
  143. package/dist/src/lib/render/index.mjs +590 -0
  144. package/dist/src/lib/render/lazy.cjs +67 -0
  145. package/dist/src/lib/render/lazy.d.ts +49 -0
  146. package/dist/src/lib/render/lazy.d.ts.map +1 -0
  147. package/dist/src/lib/render/lazy.js +105 -0
  148. package/dist/src/lib/render/lazy.mjs +50 -0
  149. package/dist/src/lib/render/suspense.cjs +141 -0
  150. package/dist/src/lib/render/suspense.d.ts +65 -0
  151. package/dist/src/lib/render/suspense.d.ts.map +1 -0
  152. package/dist/src/lib/render/suspense.js +196 -0
  153. package/dist/src/lib/render/suspense.mjs +136 -0
  154. package/dist/src/lib/render/versions.cjs +35 -0
  155. package/dist/src/lib/render/versions.d.ts +2 -0
  156. package/dist/src/lib/render/versions.d.ts.map +1 -0
  157. package/dist/src/lib/render/versions.js +21 -0
  158. package/dist/src/lib/render/versions.mjs +14 -0
  159. package/dist/src/lib/router/data.cjs +228 -0
  160. package/dist/src/lib/router/data.d.ts +142 -0
  161. package/dist/src/lib/router/data.d.ts.map +1 -0
  162. package/dist/src/lib/router/data.js +258 -0
  163. package/dist/src/lib/router/data.mjs +214 -0
  164. package/dist/src/lib/router/index.cjs +921 -0
  165. package/dist/src/lib/router/index.d.ts +274 -0
  166. package/dist/src/lib/router/index.d.ts.map +1 -0
  167. package/dist/src/lib/router/index.js +904 -0
  168. package/dist/src/lib/router/index.mjs +938 -0
  169. package/dist/src/lib/router/scroll.cjs +79 -0
  170. package/dist/src/lib/router/scroll.d.ts +19 -0
  171. package/dist/src/lib/router/scroll.d.ts.map +1 -0
  172. package/dist/src/lib/router/scroll.js +68 -0
  173. package/dist/src/lib/router/scroll.mjs +58 -0
  174. package/dist/src/lib/router/transition.cjs +75 -0
  175. package/dist/src/lib/router/transition.d.ts +81 -0
  176. package/dist/src/lib/router/transition.d.ts.map +1 -0
  177. package/dist/src/lib/router/transition.js +136 -0
  178. package/dist/src/lib/router/transition.mjs +54 -0
  179. package/dist/src/lib/server/hydration.cjs +169 -0
  180. package/dist/src/lib/server/hydration.d.ts +198 -0
  181. package/dist/src/lib/server/hydration.d.ts.map +1 -0
  182. package/dist/src/lib/server/hydration.js +345 -0
  183. package/dist/src/lib/server/hydration.mjs +148 -0
  184. package/dist/src/lib/server/index.cjs +406 -0
  185. package/dist/src/lib/server/index.d.ts +115 -0
  186. package/dist/src/lib/server/index.d.ts.map +1 -0
  187. package/dist/src/lib/server/index.js +164 -0
  188. package/dist/src/lib/server/index.mjs +384 -0
  189. package/dist/src/lib/server/reactive.cjs +197 -0
  190. package/dist/src/lib/server/reactive.d.ts +239 -0
  191. package/dist/src/lib/server/reactive.d.ts.map +1 -0
  192. package/dist/src/lib/server/reactive.js +413 -0
  193. package/dist/src/lib/server/reactive.mjs +176 -0
  194. package/dist/src/lib/storage/cache.cjs +51 -0
  195. package/dist/src/lib/storage/cache.d.ts +18 -0
  196. package/dist/src/lib/storage/cache.d.ts.map +1 -0
  197. package/dist/src/lib/storage/cache.js +42 -0
  198. package/dist/src/lib/storage/cache.mjs +30 -0
  199. package/dist/src/lib/storage/index.cjs +246 -0
  200. package/dist/src/lib/storage/index.d.ts +83 -0
  201. package/dist/src/lib/storage/index.d.ts.map +1 -0
  202. package/dist/src/lib/storage/index.js +179 -0
  203. package/dist/src/lib/storage/index.mjs +231 -0
  204. package/dist/src/lib/storage/persisted.cjs +91 -0
  205. package/dist/src/lib/storage/persisted.d.ts +53 -0
  206. package/dist/src/lib/storage/persisted.d.ts.map +1 -0
  207. package/dist/src/lib/storage/persisted.js +75 -0
  208. package/dist/src/lib/storage/persisted.mjs +70 -0
  209. package/dist/src/lib/theme/color-scheme.cjs +281 -0
  210. package/dist/src/lib/theme/color-scheme.d.ts +61 -0
  211. package/dist/src/lib/theme/color-scheme.d.ts.map +1 -0
  212. package/dist/src/lib/theme/color-scheme.js +120 -0
  213. package/dist/src/lib/theme/color-scheme.mjs +265 -0
  214. package/dist/src/lib/theme/index.cjs +267 -0
  215. package/dist/src/lib/theme/index.d.ts +78 -0
  216. package/dist/src/lib/theme/index.d.ts.map +1 -0
  217. package/dist/src/lib/theme/index.js +135 -0
  218. package/dist/src/lib/theme/index.mjs +251 -0
  219. package/dist/src/lib/theme/provider.cjs +346 -0
  220. package/dist/src/lib/theme/provider.d.ts +34 -0
  221. package/dist/src/lib/theme/provider.d.ts.map +1 -0
  222. package/dist/src/lib/theme/provider.js +60 -0
  223. package/dist/src/lib/theme/provider.mjs +332 -0
  224. package/dist/src/lib/utils/index.cjs +209 -0
  225. package/dist/src/lib/utils/index.d.ts +286 -0
  226. package/dist/src/lib/utils/index.d.ts.map +1 -0
  227. package/dist/src/lib/utils/index.js +434 -0
  228. package/dist/src/lib/utils/index.mjs +188 -0
  229. package/dist/src/routes.cjs +37 -0
  230. package/dist/src/routes.d.ts +22 -0
  231. package/dist/src/routes.d.ts.map +1 -0
  232. package/dist/src/routes.js +20 -0
  233. package/dist/src/routes.mjs +17 -0
  234. package/dist/src/server.cjs +405 -0
  235. package/dist/src/server.d.ts +63 -0
  236. package/dist/src/server.d.ts.map +1 -0
  237. package/dist/src/server.js +62 -0
  238. package/dist/src/server.mjs +382 -0
  239. package/dist/src/utils.cjs +21 -0
  240. package/dist/src/utils.d.ts +10 -0
  241. package/dist/src/utils.d.ts.map +1 -0
  242. package/dist/src/utils.js +9 -0
  243. package/dist/src/utils.mjs +4 -0
  244. package/dist/src/version.generated.cjs +26 -0
  245. package/dist/src/version.generated.d.ts +3 -0
  246. package/dist/src/version.generated.d.ts.map +1 -0
  247. package/dist/src/version.generated.js +3 -0
  248. package/dist/src/version.generated.mjs +5 -0
  249. package/dist/tsconfig.lib.tsbuildinfo +1 -0
  250. package/package.json +164 -0
  251. package/src/index.ts +19 -0
  252. package/types/fluixi.d.ts +5 -0
  253. package/types/vinxi.d.ts +50 -0
@@ -0,0 +1,302 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/lib/plugins/fluixi-routes-plugin.ts
31
+ var fluixi_routes_plugin_exports = {};
32
+ __export(fluixi_routes_plugin_exports, {
33
+ fluixiRoutesPlugin: () => fluixiRoutesPlugin
34
+ });
35
+ module.exports = __toCommonJS(fluixi_routes_plugin_exports);
36
+ var path2 = __toESM(require("path"), 1);
37
+ var import_vite_plugin_node_polyfills = require("vite-plugin-node-polyfills");
38
+
39
+ // src/lib/plugins/route-scanner.ts
40
+ var fs = __toESM(require("fs"), 1);
41
+ var path = __toESM(require("path"), 1);
42
+ var DEFAULT_EXTENSIONS = [".tsx", ".ts", ".jsx", ".js"];
43
+ function scanRoutes(routesDir, options = {}) {
44
+ const extensions = options.extensions ?? DEFAULT_EXTENSIONS;
45
+ const absDir = path.resolve(routesDir);
46
+ if (!fs.existsSync(absDir)) {
47
+ return [];
48
+ }
49
+ return scanDirectory(absDir, absDir, "", extensions);
50
+ }
51
+ function scanDirectory(dir, rootDir, parentUrlPath, extensions) {
52
+ const entries = fs.readdirSync(dir, { withFileTypes: true });
53
+ const routes = [];
54
+ const layoutRoute = null;
55
+ const files = [];
56
+ const dirs = [];
57
+ for (const entry of entries) {
58
+ if (entry.isDirectory()) {
59
+ dirs.push(entry);
60
+ } else if (entry.isFile() && hasValidExtension(entry.name, extensions)) {
61
+ files.push(entry);
62
+ }
63
+ }
64
+ let layout;
65
+ const nonLayoutFiles = [];
66
+ for (const file of files) {
67
+ const baseName = stripExtension(file.name);
68
+ if (baseName === "layout") {
69
+ layout = buildFileRoute(file.name, dir, rootDir, parentUrlPath, true);
70
+ } else {
71
+ nonLayoutFiles.push(file);
72
+ }
73
+ }
74
+ const fileRoutes = [];
75
+ for (const file of nonLayoutFiles) {
76
+ fileRoutes.push(
77
+ buildFileRoute(file.name, dir, rootDir, parentUrlPath, false)
78
+ );
79
+ }
80
+ const dirRoutes = [];
81
+ for (const d of dirs) {
82
+ const dirName = d.name;
83
+ const isGroup = isRouteGroup(dirName);
84
+ const segment = isGroup ? "" : dirNameToSegment(dirName);
85
+ const childUrlPath = segment ? joinUrlPath(parentUrlPath, segment) : parentUrlPath;
86
+ const children = scanDirectory(
87
+ path.join(dir, dirName),
88
+ rootDir,
89
+ childUrlPath,
90
+ extensions
91
+ );
92
+ if (isGroup) {
93
+ dirRoutes.push(...children);
94
+ } else {
95
+ const childLayout = children.find((c) => c.isLayout && c.urlPath === childUrlPath);
96
+ const childNonLayout = children.filter((c) => !c.isLayout || c.urlPath !== childUrlPath);
97
+ if (childLayout) {
98
+ childLayout.children = [...childLayout.children, ...childNonLayout];
99
+ dirRoutes.push(childLayout);
100
+ } else if (childNonLayout.length > 0) {
101
+ dirRoutes.push(...childNonLayout);
102
+ }
103
+ }
104
+ }
105
+ if (layout) {
106
+ layout.children = [...fileRoutes, ...dirRoutes];
107
+ routes.push(layout);
108
+ } else {
109
+ routes.push(...fileRoutes, ...dirRoutes);
110
+ }
111
+ return sortRoutes(routes);
112
+ }
113
+ function buildFileRoute(fileName, dir, rootDir, parentUrlPath, isLayout) {
114
+ const baseName = stripExtension(fileName);
115
+ const filePath = path.relative(rootDir, path.join(dir, fileName));
116
+ const isIndex = baseName === "index";
117
+ const isCatchAll = baseName.startsWith("[...");
118
+ const isDynamic = !isCatchAll && baseName.startsWith("[") && baseName.endsWith("]");
119
+ let urlSegment;
120
+ if (isLayout) {
121
+ urlSegment = "";
122
+ } else if (isIndex) {
123
+ urlSegment = "/";
124
+ } else if (isCatchAll) {
125
+ const paramName = baseName.slice(4, -1);
126
+ urlSegment = `*${paramName}`;
127
+ } else if (isDynamic) {
128
+ const paramName = baseName.slice(1, -1);
129
+ urlSegment = `:${paramName}`;
130
+ } else {
131
+ urlSegment = baseName;
132
+ }
133
+ const urlPath = isLayout ? parentUrlPath || "/" : isIndex ? parentUrlPath || "/" : joinUrlPath(parentUrlPath, urlSegment);
134
+ const absoluteFilePath = path.join(dir, fileName);
135
+ let hasRouteData = false;
136
+ try {
137
+ const content = fs.readFileSync(absoluteFilePath, "utf-8");
138
+ hasRouteData = /export\s+(const|function|async\s+function)\s+routeData\b/.test(content);
139
+ } catch {
140
+ }
141
+ return {
142
+ filePath: filePath.replace(/\\/g, "/"),
143
+ // normalize to forward slashes
144
+ urlSegment,
145
+ urlPath,
146
+ isLayout,
147
+ isIndex,
148
+ isDynamic,
149
+ isCatchAll,
150
+ isGroup: false,
151
+ children: [],
152
+ parentUrlPath,
153
+ hasRouteData,
154
+ rootDir,
155
+ dir
156
+ };
157
+ }
158
+ function hasValidExtension(fileName, extensions) {
159
+ return extensions.some((ext) => fileName.endsWith(ext));
160
+ }
161
+ function stripExtension(fileName) {
162
+ const lastDot = fileName.lastIndexOf(".");
163
+ return lastDot > 0 ? fileName.slice(0, lastDot) : fileName;
164
+ }
165
+ function isRouteGroup(dirName) {
166
+ return dirName.startsWith("(") && dirName.endsWith(")");
167
+ }
168
+ function dirNameToSegment(dirName) {
169
+ if (dirName.startsWith("[...") && dirName.endsWith("]")) {
170
+ return "*" + dirName.slice(4, -1);
171
+ }
172
+ if (dirName.startsWith("[") && dirName.endsWith("]")) {
173
+ return ":" + dirName.slice(1, -1);
174
+ }
175
+ return dirName;
176
+ }
177
+ function joinUrlPath(parent, segment) {
178
+ const base = parent.endsWith("/") ? parent : parent + "/";
179
+ return base + segment;
180
+ }
181
+ function sortRoutes(routes) {
182
+ return routes.sort((a, b) => {
183
+ if (a.isLayout && !b.isLayout) return -1;
184
+ if (!a.isLayout && b.isLayout) return 1;
185
+ if (a.isIndex && !b.isIndex) return -1;
186
+ if (!a.isIndex && b.isIndex) return 1;
187
+ if (!a.isDynamic && !a.isCatchAll && (b.isDynamic || b.isCatchAll)) return -1;
188
+ if ((a.isDynamic || a.isCatchAll) && !b.isDynamic && !b.isCatchAll) return 1;
189
+ if (a.isDynamic && b.isCatchAll) return -1;
190
+ if (a.isCatchAll && b.isDynamic) return 1;
191
+ return a.urlSegment.localeCompare(b.urlSegment);
192
+ });
193
+ }
194
+
195
+ // src/lib/plugins/route-codegen.ts
196
+ function generateRouteModule(routes, routesDir) {
197
+ const lines = [];
198
+ lines.push(`// Auto-generated by fluixi route plugin`);
199
+ lines.push(`// Do not edit manually`);
200
+ lines.push(``);
201
+ lines.push(`import { lazy } from '@fluixi/core/router';`);
202
+ lines.push(``);
203
+ lines.push(`export const routes = ${generateRouteArray(routes, routesDir, 0)};`);
204
+ lines.push(``);
205
+ return lines.join("\n");
206
+ }
207
+ function generateRouteArray(routes, routesDir, depth) {
208
+ if (routes.length === 0) return "[]";
209
+ const indent = " ".repeat(depth);
210
+ const items = routes.map((route) => generateRouteObject(route, routesDir, depth + 1));
211
+ return `[
212
+ ${items.join(",\n")}
213
+ ${indent}]`;
214
+ }
215
+ function generateRouteObject(route, routesDir, depth) {
216
+ const indent = " ".repeat(depth);
217
+ const props = [];
218
+ const importPath = buildImportPath(route.filePath, routesDir);
219
+ const routePath = computeRoutePath(route);
220
+ props.push(`${indent} path: ${JSON.stringify(routePath)}`);
221
+ props.push(`${indent} component: lazy(() => import(${JSON.stringify(importPath)}))`);
222
+ if (route.hasRouteData) {
223
+ props.push(
224
+ `${indent} data: (args, __owner, __isCancelled, __deps) => import(${JSON.stringify(
225
+ importPath
226
+ )}).then(m => { if (typeof __isCancelled === 'function' && __isCancelled()) return undefined; if (!m.routeData) return undefined; if (typeof m.routeDeps === 'function') { if (typeof __deps === 'function') __deps(m.routeDeps); args = { ...args, deps: m.routeDeps() }; } return m.routeData(args); })`
227
+ );
228
+ }
229
+ if (route.children.length > 0) {
230
+ const childArray = generateRouteArray(route.children, routesDir, depth + 1);
231
+ props.push(`${indent} children: ${childArray}`);
232
+ }
233
+ return `${indent}{
234
+ ${props.join(",\n")}
235
+ ${indent}}`;
236
+ }
237
+ function computeRoutePath(route) {
238
+ return route.urlPath;
239
+ }
240
+ function buildImportPath(filePath, routesDir) {
241
+ const base = routesDir.replace(/\\/g, "/").replace(/\/$/, "");
242
+ return `${base}/${filePath}`;
243
+ }
244
+
245
+ // src/lib/plugins/fluixi-routes-plugin.ts
246
+ var VIRTUAL_MODULE_ID = "virtual:fluixi-routes";
247
+ var RESOLVED_VIRTUAL_ID = "\0" + VIRTUAL_MODULE_ID;
248
+ var PUBLIC_MODULE_ID = "@fluixi/core/routes";
249
+ function fluixiRoutesPlugin(options = {}) {
250
+ const routesDir = options.routesDir ?? "src/routes";
251
+ const extensions = options.extensions ?? [".tsx", ".ts", ".jsx", ".js"];
252
+ let projectRoot = "";
253
+ let lastGenerated = null;
254
+ function generateModule(root) {
255
+ const absRoutesDir = path2.resolve(root, routesDir);
256
+ const scanOpts = { extensions };
257
+ const routes = scanRoutes(absRoutesDir, scanOpts);
258
+ return generateRouteModule(routes, "./" + routesDir);
259
+ }
260
+ const usePolyfills = options.polyfills !== false;
261
+ const polyfillsPlugin = usePolyfills ? Object.assign({}, (0, import_vite_plugin_node_polyfills.nodePolyfills)({ include: ["fs", "path"] }), { apply: "serve" }) : null;
262
+ const routesPlugin = {
263
+ name: "fluixi-routes",
264
+ enforce: "pre",
265
+ configResolved(config) {
266
+ projectRoot = config.root || process.cwd();
267
+ },
268
+ resolveId(id) {
269
+ if (id === VIRTUAL_MODULE_ID || id === PUBLIC_MODULE_ID) {
270
+ return RESOLVED_VIRTUAL_ID;
271
+ }
272
+ return null;
273
+ },
274
+ load(id) {
275
+ if (id !== RESOLVED_VIRTUAL_ID) return null;
276
+ lastGenerated = generateModule(projectRoot || process.cwd());
277
+ return lastGenerated;
278
+ },
279
+ // Vite dev server: watch routes directory for changes
280
+ configureServer(server) {
281
+ const root = projectRoot || process.cwd();
282
+ const absRoutesDir = path2.resolve(root, routesDir);
283
+ server.watcher.add(absRoutesDir);
284
+ server.watcher.on("all", (event, filePath) => {
285
+ if (!filePath.startsWith(absRoutesDir)) return;
286
+ if (!["add", "unlink", "addDir", "unlinkDir", "change"].includes(event)) return;
287
+ if (event !== "addDir" && event !== "unlinkDir" && !extensions.some((ext) => filePath.endsWith(ext))) {
288
+ return;
289
+ }
290
+ const next = generateModule(root);
291
+ if (next === lastGenerated) return;
292
+ lastGenerated = next;
293
+ const mod = server.moduleGraph.getModuleById(RESOLVED_VIRTUAL_ID);
294
+ if (mod) {
295
+ server.moduleGraph.invalidateModule(mod);
296
+ server.ws.send({ type: "full-reload" });
297
+ }
298
+ });
299
+ }
300
+ };
301
+ return polyfillsPlugin ? [polyfillsPlugin, routesPlugin] : [routesPlugin];
302
+ }
@@ -0,0 +1,35 @@
1
+ /**
2
+ * @module @fluixi/core/plugins/fluixi-routes-plugin
3
+ *
4
+ * Scans a routes directory at build time and generates a virtual module
5
+ * (virtual:fluixi-routes) containing the route tree. Replaces import.meta.glob.
6
+ */
7
+ export interface FluixiRoutesPluginOptions {
8
+ /** Path to routes directory, relative to project root. Default: 'src/routes' */
9
+ routesDir?: string;
10
+ /** File extensions to scan. Default: ['.tsx', '.ts', '.jsx', '.js'] */
11
+ extensions?: string[];
12
+ /**
13
+ * Inject browser polyfills for Node built-ins (Buffer/process/global/fs/path) via
14
+ * vite-plugin-node-polyfills. Default `true` (back-compat). Set `false` for SSR
15
+ * (the injected shims break server rendering); `@fluixi/start` passes `false`.
16
+ */
17
+ polyfills?: boolean;
18
+ }
19
+ /**
20
+ * The Vite plugin that turns a routes directory into a route tree.
21
+ *
22
+ * Scans `routesDir` and serves the result as `@fluixi/core/routes`, so an app imports a
23
+ * real module from this package and needs no generated `declare module` of its own. The
24
+ * shipped file is a typed empty array, which is what the plugin replaces.
25
+ *
26
+ * Without it that import resolves to the empty array and an app has no routes, which is
27
+ * the error `routes.ts` raises rather than rendering a blank page.
28
+ *
29
+ * @example
30
+ * ```ts
31
+ * export default defineConfig({ plugins: [fluixiRoutesPlugin({ routesDir: 'src/routes' })] });
32
+ * ```
33
+ */
34
+ export declare function fluixiRoutesPlugin(options?: FluixiRoutesPluginOptions): any[];
35
+ //# sourceMappingURL=fluixi-routes-plugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fluixi-routes-plugin.d.ts","sourceRoot":"","sources":["../../../../src/lib/plugins/fluixi-routes-plugin.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAQH,MAAM,WAAW,yBAAyB;IACxC,gFAAgF;IAChF,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,uEAAuE;IACvE,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB;;;;OAIG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAcD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,GAAE,yBAA8B,GACtC,GAAG,EAAE,CA+FP"}
@@ -0,0 +1,118 @@
1
+ /**
2
+ * @module @fluixi/core/plugins/fluixi-routes-plugin
3
+ *
4
+ * Scans a routes directory at build time and generates a virtual module
5
+ * (virtual:fluixi-routes) containing the route tree. Replaces import.meta.glob.
6
+ */
7
+ import * as path from 'path';
8
+ import { nodePolyfills } from 'vite-plugin-node-polyfills';
9
+ import { scanRoutes } from './route-scanner.js';
10
+ import { generateRouteModule } from './route-codegen.js';
11
+ const VIRTUAL_MODULE_ID = 'virtual:fluixi-routes';
12
+ const RESOLVED_VIRTUAL_ID = '\0' + VIRTUAL_MODULE_ID;
13
+ /**
14
+ * The public specifier. A real module in this package, so its types come from here and an
15
+ * app needs no generated `declare module` in its own `src/`. The plugin swaps in the
16
+ * scanned tree; the shipped file is a typed empty array.
17
+ *
18
+ * `virtual:fluixi-routes` stays resolvable so existing apps keep working.
19
+ */
20
+ const PUBLIC_MODULE_ID = '@fluixi/core/routes';
21
+ /**
22
+ * The Vite plugin that turns a routes directory into a route tree.
23
+ *
24
+ * Scans `routesDir` and serves the result as `@fluixi/core/routes`, so an app imports a
25
+ * real module from this package and needs no generated `declare module` of its own. The
26
+ * shipped file is a typed empty array, which is what the plugin replaces.
27
+ *
28
+ * Without it that import resolves to the empty array and an app has no routes, which is
29
+ * the error `routes.ts` raises rather than rendering a blank page.
30
+ *
31
+ * @example
32
+ * ```ts
33
+ * export default defineConfig({ plugins: [fluixiRoutesPlugin({ routesDir: 'src/routes' })] });
34
+ * ```
35
+ */
36
+ export function fluixiRoutesPlugin(options = {}) {
37
+ const routesDir = options.routesDir ?? 'src/routes';
38
+ const extensions = options.extensions ?? ['.tsx', '.ts', '.jsx', '.js'];
39
+ let projectRoot = '';
40
+ /** The module body most recently served, so the watcher can tell a real change from a save. */
41
+ let lastGenerated = null;
42
+ function generateModule(root) {
43
+ const absRoutesDir = path.resolve(root, routesDir);
44
+ const scanOpts = { extensions };
45
+ const routes = scanRoutes(absRoutesDir, scanOpts);
46
+ // Import paths are relative to project root, prefixed with ./
47
+ return generateRouteModule(routes, './' + routesDir);
48
+ }
49
+ // nodePolyfills injects `vite-plugin-node-polyfills/shims/*` (browser polyfills for
50
+ // Buffer/process/global/fs/path) into transformed modules. It's needed by some apps
51
+ // for the BROWSER, but it BREAKS SSR. Node already has those globals, and the
52
+ // injected CJS shim can't be ESM-evaluated (and often can't be resolved at all:
53
+ // "Cannot find module .../shims/buffer"). So it's opt-out: on by default for
54
+ // back-compat, but SSR-first setups (e.g. @fluixi/start) pass `polyfills: false`.
55
+ const usePolyfills = options.polyfills !== false;
56
+ const polyfillsPlugin = usePolyfills
57
+ ? Object.assign({}, nodePolyfills({ include: ['fs', 'path'] }), { apply: 'serve' })
58
+ : null;
59
+ const routesPlugin = {
60
+ name: 'fluixi-routes',
61
+ enforce: 'pre',
62
+ configResolved(config) {
63
+ projectRoot = config.root || process.cwd();
64
+ },
65
+ resolveId(id) {
66
+ if (id === VIRTUAL_MODULE_ID || id === PUBLIC_MODULE_ID) {
67
+ return RESOLVED_VIRTUAL_ID;
68
+ }
69
+ return null;
70
+ },
71
+ load(id) {
72
+ if (id !== RESOLVED_VIRTUAL_ID)
73
+ return null;
74
+ lastGenerated = generateModule(projectRoot || process.cwd());
75
+ return lastGenerated;
76
+ },
77
+ // Vite dev server: watch routes directory for changes
78
+ configureServer(server) {
79
+ const root = projectRoot || process.cwd();
80
+ const absRoutesDir = path.resolve(root, routesDir);
81
+ // Watch the routes directory
82
+ server.watcher.add(absRoutesDir);
83
+ server.watcher.on('all', (event, filePath) => {
84
+ if (!filePath.startsWith(absRoutesDir))
85
+ return;
86
+ // `change` matters as much as add/unlink. The route tree is not only a list of
87
+ // files: `routeData` is detected by reading each file at scan time, so EDITING a
88
+ // route, adding a `routeData` export, or changing one, changes the generated
89
+ // module even though no file appeared or vanished. Leaving `change` out meant
90
+ // those edits needed a dev-server restart to take effect.
91
+ if (!['add', 'unlink', 'addDir', 'unlinkDir', 'change'].includes(event))
92
+ return;
93
+ // Check if the file has a valid extension
94
+ if (event !== 'addDir' &&
95
+ event !== 'unlinkDir' &&
96
+ !extensions.some((ext) => filePath.endsWith(ext))) {
97
+ return;
98
+ }
99
+ // Regenerate and compare before invalidating. Every save of a route component now
100
+ // reaches this handler, and most change nothing about the tree: reloading the
101
+ // page on each of them would undo the point of HMR. A full reload is only correct
102
+ // when the generated module actually differs.
103
+ const next = generateModule(root);
104
+ if (next === lastGenerated)
105
+ return;
106
+ lastGenerated = next;
107
+ const mod = server.moduleGraph.getModuleById(RESOLVED_VIRTUAL_ID);
108
+ if (mod) {
109
+ server.moduleGraph.invalidateModule(mod);
110
+ server.ws.send({ type: 'full-reload' });
111
+ }
112
+ });
113
+ },
114
+ };
115
+ // Vite flattens plugin arrays automatically: consumers just use:
116
+ // plugins: [fluixiRoutesPlugin({ routesDir: 'src/routes' })]
117
+ return polyfillsPlugin ? [polyfillsPlugin, routesPlugin] : [routesPlugin];
118
+ }